@openchamber/web 1.11.0 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{JsonTreeView-CUIfrcFf.js → JsonTreeView-9F0tH9yA.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Bma9y3dD.js → MarkdownRendererImpl-C3QofAGm.js} +2 -2
- package/dist/assets/{MultiRunWindow-Cwc0x7fs.js → MultiRunWindow-wnUGv0Dl.js} +1 -1
- package/dist/assets/{OnboardingScreen-BhozUlcE.js → OnboardingScreen-17dAs0NH.js} +2 -2
- package/dist/assets/{SettingsWindow-B4B2bn0C.js → SettingsWindow-BgyVY5gz.js} +1 -1
- package/dist/assets/{TerminalView-BpoHWJj6.js → TerminalView-D11XIZuz.js} +1 -1
- package/dist/assets/{ToolOutputDialog-7U42lN20.js → ToolOutputDialog-DFG7ANVw.js} +6 -6
- package/dist/assets/es-Chl2Hu6K.js +15 -0
- package/dist/assets/index-0bVkxg-Z.css +1 -0
- package/dist/assets/{index-B2ztI3pp.js → index-BV2XTsJJ.js} +1 -1
- package/dist/assets/ko-BSrH3F9n.js +15 -0
- package/dist/assets/{main-rHOaDqOy.js → main-BHkNwOz1.js} +2 -2
- package/dist/assets/main-Bqf4fXgq.js +225 -0
- package/dist/assets/miniChat-BmB-E5xo.js +2 -0
- package/dist/assets/{modelPrefsAutoSave-D5z_F_WP.js → modelPrefsAutoSave-2uwW8uD9.js} +104 -96
- package/dist/assets/pl-YlGvPmFg.js +15 -0
- package/dist/assets/pt-BR-BonIMDN_.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-B_qrXCU2.js +2 -0
- package/dist/assets/uk-lPqA3MHn.js +15 -0
- package/dist/assets/{vendor-.bun-BFTPeDgG.js → vendor-.bun-Boz6Tqcq.js} +20 -20
- package/dist/assets/zh-CN-C5nQQsUL.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/package.json +1 -1
- package/server/lib/git/DOCUMENTATION.md +1 -0
- package/server/lib/git/routes.js +26 -0
- package/server/lib/git/service.js +96 -10
- package/server/lib/git/service.test.js +39 -0
- package/server/lib/opencode/settings-helpers.js +10 -1
- package/server/lib/opencode/settings-helpers.test.js +35 -0
- package/server/lib/opencode/skill-routes.js +43 -49
- package/server/lib/opencode/skills.js +78 -10
- package/server/lib/preview/proxy-runtime.js +43 -3
- package/dist/assets/es-DLzL0vVb.js +0 -15
- package/dist/assets/index-D5TVqnib.css +0 -1
- package/dist/assets/ko-apnbnEuD.js +0 -15
- package/dist/assets/main-ClS4RVxe.js +0 -217
- package/dist/assets/miniChat-Cx8YK32Y.js +0 -2
- package/dist/assets/pl-DUKUujvh.js +0 -15
- package/dist/assets/pt-BR-D0UPeIZC.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-zbukf-1g.js +0 -2
- package/dist/assets/uk-CaTe2At9.js +0 -15
- package/dist/assets/zh-CN-D-oQmPdK.js +0 -15
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-BFTPeDgG.js","assets/vendor--V65Sl9C2.css","assets/modelPrefsAutoSave-D5z_F_WP.js","assets/index-B2ztI3pp.js","assets/index-D5TVqnib.css","assets/TerminalView-BpoHWJj6.js","assets/JsonTreeView-CUIfrcFf.js","assets/SettingsWindow-B4B2bn0C.js","assets/MultiRunWindow-Cwc0x7fs.js","assets/OnboardingScreen-BhozUlcE.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as rt,R as l,u as qo,a as Fi,j as s,b as xd,C as bd,P as Jo,S as Ec,d as Cg,D as Qo,e as Yo,f as Xo,g as ur,i as xi,r as $e,k as Ig,l as Pg,p as Xi,m as xl,n as Ag,o as Dg,q as Tg,_ as wr,s as Li,t as Ea,v as Mg,w as mr,W as Eg,x as Rg,V as Fg,F as Lg,y as Og,E as $g,z as Jn,A as Bg,B as bi,G as Gd,H as _g,I as Vg,J as Ll,K as zg,L as Ug,M as Wg,N as qd,O as Jd,Q as Kg,T as hh,U as fh,X as Hg,Y as Qd,Z as Gg,$ as qg,a0 as Jg,a1 as Qg,a2 as Yg,a3 as Xg,a4 as Zg,a5 as gh,a6 as ex,a7 as Rc,a8 as xh,a9 as bh,aa as Za,ab as Di,ac as Fc,ad as ot,ae as yh,af as vh,ag as tx,ah as sx,ai as nx,aj as rx,ak as ax,al as ix,am as ox,an as lx,ao as cx,ap as Yd,aq as dx,ar as ux,as as Xd,at as Zd,au as Ol,av as mx}from"./vendor-.bun-BFTPeDgG.js";import{a as px,b as hx,f as fx}from"./index-B2ztI3pp.js";import{u as mt,a as Me,b as rn,c as pe,I as C,d as Ps,i as pn,g as lr,e as Zr,s as $l,r as Bl,f as _l,h as Es,o as In,j as Ws,T as Ct,k as It,l as Pt,m as ka,n as Ur,p as eu,D as zt,q as gx,t as Zo,v as Rn,w as q,x as Os,y as An,z as $s,A as Bs,B as wh,C as tu,E as xx,F as bx,G as su,H as yx,J as vx,K as wx,L as jx,M as _n,N as wn,O as Qn,P as Lc,Q as Mn,R as Oi,S as Nx,U as yt,V as Ht,W as Sx,X as jh,Y as $i,Z as Nh,_ as Kn,$ as yd,a0 as bl,a1 as kx,a2 as nu,a3 as Cx,a4 as Ix,a5 as Sh,a6 as Px,a7 as Ax,a8 as kh,a9 as vd,aa as el,ab as Ch,ac as yl,ad as Vr,ae as wd,af as Fo,ag as Dx,ah as Ys,ai as Ih,aj as Ph,ak as Ut,al as As,am as Dr,an as li,ao as Tx,ap as Ah,aq as Ss,ar as js,as as ve,at as vs,au as ws,av as Ca,aw as Mx,ax as Ex,ay as ho,az as En,aA as Dh,aB as Th,aC as vl,aD as Rx,aE as Fx,aF as ru,aG as vn,aH as bs,aI as Lx,aJ as Ox,aK as $x,aL as Bx,aM as _x,aN as Vx,aO as zx,aP as Ks,aQ as Ux,aR as Wx,aS as Rs,aT as Kx,aU as Hx,aV as Gx,aW as qx,aX as yr,aY as Zi,aZ as Jx,a_ as Gs,a$ as ps,b0 as hs,b1 as ys,b2 as fs,b3 as Ft,b4 as Qx,b5 as Ia,b6 as Yx,b7 as Or,b8 as Mh,b9 as wl,ba as Xx,bb as jd,bc as Zx,bd as eb,be as Eh,bf as tb,bg as on,bh as eo,bi as vr,bj as sb,bk as nb,bl as Vl,bm as jl,bn as Nd,bo as Sd,bp as Nl,bq as $n,br as kd,bs as Pa,bt as Sl,bu as ei,bv as ci,bw as di,bx as au,by as tl,bz as sl,bA as Ui,bB as ui,bC as Rh,bD as rb,bE as Nr,bF as ab,bG as iu,bH as nl,bI as to,bJ as Fh,bK as ib,bL as ob,bM as so,bN as lb,bO as Cd,bP as cb,bQ as ti,bR as Wi,bS as Lh,bT as mi,bU as Oh,bV as db,bW as ub,bX as Id,bY as ea,bZ as si,b_ as wa,b$ as kl,c0 as no,c1 as ro,c2 as Oc,c3 as $h,c4 as Pd,c5 as Bh,c6 as Ki,c7 as mb,c8 as pb,c9 as hb,ca as fb,cb as gb,cc as ni,cd as zl,ce as ou,cf as xb,cg as bb,ch as yb,ci as vb,cj as Qa,ck as Ul,cl as wb,cm as lu,cn as sa,co as jb,cp as cu,cq as du,cr as uu,cs as mu,ct as Lo,cu as pu,cv as Nb,cw as Wl,cx as Sb,cy as kb,cz as Cb,cA as Ib,cB as Pb,cC as Ab,cD as Db,cE as Kl,cF as hu,cG as Tb,cH as Mb,cI as Eb,cJ as Rb,cK as Fb,cL as Hl,cM as Lb,cN as fu,cO as Ti,cP as Ob,cQ as $b,cR as _h,cS as Bb,cT as Ya,cU as _b,cV as gu,cW as Vb,cX as Vh,cY as fo,cZ as Oo,c_ as zb,c$ as zh,d0 as Ub,d1 as Wb,d2 as xu,d3 as bu,d4 as Uh,d5 as Wh,d6 as Gl,d7 as go,d8 as Kb,d9 as Hb,da as Gb,db as qb,dc as Kh,dd as Hh,de as $c,df as Ad,dg as Jb,dh as Ns,di as Hi,dj as pi,dk as ri,dl as yu,dm as Hn,dn as Qb,dp as Bi,dq as Yb,dr as Gh,ds as Xb,dt as Zb,du as ey,dv as qh,dw as Jh,dx as ty,dy as sy,dz as ny,dA as ry,dB as vu,dC as ay,dD as iy,dE as oy,dF as ly,dG as cy,dH as Qh,dI as dy,dJ as uy,dK as my,dL as py,dM as hy,dN as fy,dO as gy,dP as xy,dQ as by,dR as yy,dS as vy,dT as wy,dU as jy,dV as Ny,dW as Bc,dX as wu,dY as Sy,dZ as Yh,d_ as ky,d$ as Cy,e0 as Iy,e1 as Py,e2 as Kr,e3 as Ay,e4 as ju,e5 as Dy,e6 as $o,e7 as Bo,e8 as Ty,e9 as My,ea as Ey,eb as Ry,ec as Nu,ed as Fy,ee as Su,ef as Ly,eg as ku,eh as Oy,ei as $y,ej as By,ek as Cu,el as Iu,em as Pu,en as Au,eo as Du,ep as _y,eq as Vy,er as zy,es as Uy,et as Wy,eu as Ky,ev as Hy,ew as Gy,ex as qy,ey as Jy,ez as Qy,eA as Yy}from"./modelPrefsAutoSave-D5z_F_WP.js";import{J as Xy}from"./JsonTreeView-CUIfrcFf.js";const Zy=({transform:t})=>({...t,y:0}),ev=t=>{const e=rt.c(18),{id:n,children:r,className:i}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:o,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=xd(a);let f;e[2]!==p?(f=bd.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let b;e[4]!==f||e[5]!==m?(b={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=b):b=e[6];const h=u&&"opacity-50";let v;e[7]!==i||e[8]!==h?(v=pe("h-full rounded-md",i,h),e[7]=i,e[8]=h,e[9]=v):v=e[9];let x;return e[10]!==o||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==b||e[16]!==v?(x=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:b,className:v,...o,...c,children:r}),e[10]=o,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=b,e[16]=v,e[17]=x):x=e[17],x},tv=t=>{const e=rt.c(6),{id:n,children:r,className:i}=t;let a;e[0]!==i?(a=pe("h-full",i),e[0]=i,e[1]=a):a=e[1];let o;return e[2]!==r||e[3]!==n||e[4]!==a?(o=s.jsx("div",{className:a,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=a,e[5]=o):o=e[5],o},Tr=t=>{const e=rt.c(121),{items:n,activeId:r,onSelect:i,onClose:a,onReorder:o,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:f,animateActivePill:b,activePillLowercase:h,className:v}=t,x=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,y=f===void 0?!1:f,S=h===void 0?!0:h,{t:D}=mt(),j=Me(sv),{isTablet:I}=rn(),A=j||I,E=l.useRef(null);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P={left:!1,right:!1},e[0]=P):P=e[0];const[k,N]=l.useState(P);let T;e[1]!==n?(T=n.map(nv),e[1]=n,e[2]=T):T=e[2];const M=T,R=x==="scrollable",L=g==="default",O=g==="active-pill",V=g==="animated",$=O||V,B=L,H=$||B,_=O&&R,se=$,oe=b??V,ae=typeof o=="function",ne=ae?ev:tv;let xe;e[3]===Symbol.for("react.memo_cache_sentinel")?(xe=new Map,e[3]=xe):xe=e[3];const te=l.useRef(xe),[F,z]=l.useState(null);let Q;e[4]===Symbol.for("react.memo_cache_sentinel")?(Q={activationConstraint:{distance:8}},e[4]=Q):Q=e[4];const re=qo(Fi(Jo,Q)),K=rv;let le;e[5]===Symbol.for("react.memo_cache_sentinel")?(le=(lt,ye)=>{if(ye){te.current.set(lt,ye);return}te.current.delete(lt)},e[5]=le):le=e[5];const Se=le;let ue;e[6]!==r||e[7]!==H?(ue=()=>{if(!H||!r){z(av);return}const lt=E.current,ye=te.current.get(r);if(!lt||!ye){z(iv);return}let Je=0,Be=0,ze=ye;for(;ze&&ze!==lt;)Je=Je+ze.offsetLeft,Be=Be+ze.offsetTop,ze=ze.offsetParent;const nt={left:Je,top:Be,width:ye.offsetWidth,height:ye.offsetHeight};z(Ye=>K(Ye,nt)?Ye:nt)},e[6]=r,e[7]=H,e[8]=ue):ue=e[8];const je=ue;let W;e[9]!==R?(W=()=>{if(!R){N({left:!1,right:!1});return}const lt=E.current;if(!lt){N({left:!1,right:!1});return}N({left:lt.scrollLeft>2,right:lt.scrollLeft+lt.clientWidth<lt.scrollWidth-2})},e[9]=R,e[10]=W):W=e[10];const me=W;let X;e[11]!==R||e[12]!==me?(X=()=>{if(!R){N({left:!1,right:!1});return}const lt=E.current;if(!lt)return;me(),lt.addEventListener("scroll",me,{passive:!0});const ye=new ResizeObserver(me);return ye.observe(lt),()=>{lt.removeEventListener("scroll",me),ye.disconnect()}},e[11]=R,e[12]=me,e[13]=X):X=e[13];let ce;e[14]!==R||e[15]!==n.length||e[16]!==me?(ce=[R,n.length,me],e[14]=R,e[15]=n.length,e[16]=me,e[17]=ce):ce=e[17],l.useEffect(X,ce);let ee;e[18]!==r||e[19]!==je||e[20]!==H?(ee=()=>{if(!H){z(null);return}je();const lt=E.current;if(!lt)return;const ye=new ResizeObserver(je);if(ye.observe(lt),r){const Je=te.current.get(r);Je&&ye.observe(Je)}return()=>{ye.disconnect()}},e[18]=r,e[19]=je,e[20]=H,e[21]=ee):ee=e[21];let Pe;e[22]!==r||e[23]!==n.length||e[24]!==je||e[25]!==H?(Pe=[r,n.length,je,H],e[22]=r,e[23]=n.length,e[24]=je,e[25]=H,e[26]=Pe):Pe=e[26],l.useEffect(ee,Pe);let Ne;e[27]!==je?(Ne=()=>{je()},e[27]=je,e[28]=Ne):Ne=e[28],l.useLayoutEffect(Ne);let Y;e[29]!==r||e[30]!==R||e[31]!==me?(Y=()=>{if(!R||!r)return;const lt=E.current;if(!lt)return;const ye=window.requestAnimationFrame(()=>{const Je=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),Be=lt.querySelector(`[data-sortable-tab-id="${Je}"]`);Be&&(Be.scrollIntoView({block:"nearest",inline:"nearest"}),me())});return()=>{window.cancelAnimationFrame(ye)}},e[29]=r,e[30]=R,e[31]=me,e[32]=Y):Y=e[32];let he;e[33]!==r||e[34]!==R||e[35]!==n.length||e[36]!==me?(he=[r,R,n.length,me],e[33]=r,e[34]=R,e[35]=n.length,e[36]=me,e[37]=he):he=e[37],l.useEffect(Y,he);let ke;e[38]!==o?(ke=lt=>{if(!o)return;const{active:ye,over:Je}=lt;!Je||ye.id===Je.id||o(String(ye.id),String(Je.id))},e[38]=o,e[39]=ke):ke=e[39];const be=ke;let fe;e[40]!==v?(fe=pe("relative flex h-full min-w-0 flex-1",v),e[40]=v,e[41]=fe):fe=e[41];let Te;e[42]!==R||e[43]!==k||e[44]!==$?(Te=R&&k.left?s.jsx("div",{className:pe("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=R,e[43]=k,e[44]=$,e[45]=Te):Te=e[45];let Ve;e[46]!==R||e[47]!==k||e[48]!==$?(Ve=R&&k.right?s.jsx("div",{className:pe("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=R,e[47]=k,e[48]=$,e[49]=Ve):Ve=e[49];const G=$?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Ie=$&&"@container/pill-tabs",Oe=$&&"pill-tabs__track",De=$&&(p??"gap-0.5 py-0.5"),ge=B&&"items-center overflow-y-hidden",U=se&&"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=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Ee;e[50]!==G||e[51]!==Ie||e[52]!==Oe||e[53]!==De||e[54]!==ge||e[55]!==U||e[56]!==de?(Ee=pe("relative flex h-full min-w-0 flex-1",G,Ie,Oe,De,ge,U,de),e[50]=G,e[51]=Ie,e[52]=Oe,e[53]=De,e[54]=ge,e[55]=U,e[56]=de,e[57]=Ee):Ee=e[57];let _e;e[58]!==R?(_e=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=_e):_e=e[59];let Z;e[60]!==D?(Z=D("sortableTabsStrip.aria.tabs"),e[60]=D,e[61]=Z):Z=e[61];let ie;e[62]!==F||e[63]!==oe||e[64]!==$?(ie=$&&F?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(${F.left}px, ${F.top}px, 0)`,width:`${F.width}px`,height:`${F.height}px`,transition:oe?"transform 300ms cubic-bezier(0.65, 0, 0.35, 1), width 300ms cubic-bezier(0.65, 0, 0.35, 1), height 300ms cubic-bezier(0.65, 0, 0.35, 1)":void 0}}):null,e[62]=F,e[63]=oe,e[64]=$,e[65]=ie):ie=e[65];let Ce;e[66]!==F||e[67]!==B?(Ce=B&&F?s.jsx("div",{className:"pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",style:{transform:`translate3d(${F.left}px, 0, 0)`,width:`${F.width}px`},"aria-hidden":!0}):null,e[66]=F,e[67]=B,e[68]=Ce):Ce=e[68];let He;if(e[69]!==ne||e[70]!==r||e[71]!==m||e[72]!==S||e[73]!==A||e[74]!==y||e[75]!==w||e[76]!==O||e[77]!==j||e[78]!==R||e[79]!==n||e[80]!==a||e[81]!==i||e[82]!==_||e[83]!==$){let lt;e[85]!==ne||e[86]!==r||e[87]!==m||e[88]!==S||e[89]!==A||e[90]!==y||e[91]!==w||e[92]!==O||e[93]!==j||e[94]!==R||e[95]!==a||e[96]!==i||e[97]!==_||e[98]!==$?(lt=ye=>{const Je=ye.id===r,Be=w&&$&&!Je&&!!ye.icon,ze=!Be,nt=!!ye.icon&&(!y||Je),Ye=w&&$&&Je&&!R&&!_,Ue=ye.closable!==!1&&!!a,vt=Ue&&!!ye.icon,Et=R||_?void 0:$?Ye?"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(ne,{id:ye.id,className:Et,children:s.jsxs("div",{ref:Gt=>Se(ye.id,Gt),className:pe("group flex h-full min-w-0 flex-nowrap items-center",R||_?"shrink-0":$?"w-full":"w-full min-w-0",$?"relative z-10 bg-transparent":Je?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":Je,"aria-label":Be?ye.title??ye.label:void 0,onClick:()=>i(ye.id),className:pe($?"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",$&&S?"lowercase":null,$&&(Be?"gap-0":"gap-1.5"),$?_?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":Be?"px-2 !min-w-0 text-center":Ye?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":R?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",$?m??(O?j?"h-[38px]":"h-[31px]":"h-7"):null,$?Je?"text-foreground":"text-muted-foreground hover:text-foreground":null,$?"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:$?s.jsxs(s.Fragment,{children:[nt?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",vt&&(A?"opacity-0":"group-hover:opacity-0")),children:ye.icon}),vt?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",A?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:ov,onClick:Gt=>{Gt.stopPropagation(),a?.(ye.id)},"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,ze?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",!R&&"justify-center"),children:[nt?s.jsxs("span",{className:pe("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Je?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:pe("flex items-center justify-center transition-opacity",vt&&(A?"opacity-0":"group-hover:opacity-0")),children:ye.icon}),vt?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",A?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:lv,onClick:Gt=>{Gt.stopPropagation(),a?.(ye.id)},"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:ye.label})]})}),Ue&&!vt?s.jsx("button",{type:"button",onPointerDown:cv,onClick:Gt=>{Gt.stopPropagation(),a?.(ye.id)},className:pe("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",$?"-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",$?Je?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Je?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(C,{name:"close",className:"h-3 w-3"})}):null]})},ye.id)},e[85]=ne,e[86]=r,e[87]=m,e[88]=S,e[89]=A,e[90]=y,e[91]=w,e[92]=O,e[93]=j,e[94]=R,e[95]=a,e[96]=i,e[97]=_,e[98]=$,e[99]=lt):lt=e[99],He=n.map(lt),e[69]=ne,e[70]=r,e[71]=m,e[72]=S,e[73]=A,e[74]=y,e[75]=w,e[76]=O,e[77]=j,e[78]=R,e[79]=n,e[80]=a,e[81]=i,e[82]=_,e[83]=$,e[84]=He}else He=e[84];let Ge;e[100]!==Ee||e[101]!==_e||e[102]!==Z||e[103]!==ie||e[104]!==Ce||e[105]!==He?(Ge=s.jsxs("div",{ref:E,className:Ee,style:_e,role:"tablist","aria-label":Z,children:[ie,Ce,He]}),e[100]=Ee,e[101]=_e,e[102]=Z,e[103]=ie,e[104]=Ce,e[105]=He,e[106]=Ge):Ge=e[106];let Xe;e[107]!==fe||e[108]!==Te||e[109]!==Ve||e[110]!==Ge?(Xe=s.jsxs("div",{className:fe,children:[Te,Ve,Ge]}),e[107]=fe,e[108]=Te,e[109]=Ve,e[110]=Ge,e[111]=Xe):Xe=e[111];const we=Xe;if(!ae)return we;let tt;e[112]===Symbol.for("react.memo_cache_sentinel")?(tt=[Zy],e[112]=tt):tt=e[112];let st;e[113]!==M||e[114]!==we?(st=s.jsx(Ec,{items:M,strategy:Cg,children:we}),e[113]=M,e[114]=we,e[115]=st):st=e[115];let qe;e[116]===Symbol.for("react.memo_cache_sentinel")?(qe=s.jsx(Qo,{dropAnimation:null}),e[116]=qe):qe=e[116];let it;return e[117]!==be||e[118]!==re||e[119]!==st?(it=s.jsxs(Yo,{sensors:re,collisionDetection:Xo,onDragEnd:be,modifiers:tt,children:[st,qe]}),e[117]=be,e[118]=re,e[119]=st,e[120]=it):it=e[120],it};function sv(t){return t.isMobile}function nv(t){return t.id}function rv(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 av(t){return t===null?t:null}function iv(t){return t===null?t:null}function ov(t){t.stopPropagation()}function lv(t){t.stopPropagation()}function cv(t){t.stopPropagation()}function Tu(t){const e=rt.c(14);let n,r,i,a;e[0]!==t?({size:i,className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(n=e[1],r=e[2],i=e[3],a=e[4]);const o=typeof i=="number"?`${i}px`:i,c=typeof i=="number"?`${i}px`:i;let d;e[5]!==a||e[6]!==o||e[7]!==c?(d={width:o,height:c,...a},e[5]=a,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 Lr=[{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"}];Lr.reduce((t,e)=>(t[e.id]=e,t),{});const dv=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),uv=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,Gi=(t,e)=>t??uv(e),Xh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",Dd=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,mv=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},qi=(t,e,n,r)=>{let i=n;if(i===null&&r&&(i=mv(r)),t===null||e===null||i===null||i<=0)return null;const a=Date.now(),o=Math.max(0,(e-a)/1e3),c=Math.max(0,Math.min(i,i-o)),d=Math.max(0,Math.min(1,c/i)),p=t/100,m=t>=100&&o>0;let u;d>.01?u=Math.min(999,p/d*100):u=t;let f;m?f="exhausted":p<=d?f="on-track":u<=130?f="slightly-fast":f="too-fast";const b=i>=120*3600,h=b?86400:3600,v=b?"d":"h",x=i/h,g=Math.max(c/h,x*.01),w=t/g,y=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${v}`:"-",S=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let D=null;const j=i/86400;return j>=7&&(D=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:o,isExhausted:m,elapsedSeconds:c,totalSeconds:i,status:f,paceRateText:y,predictText:S,dailyAllocationPercent:D}},pv=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)"}},Mu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),i=Math.floor(r/24),a=r%24,o=n%60;return i>0?`${i}d ${a}h`:r>0?`${r}h`:n===0?"<1m":`${o}m`},zr=t=>Math.min(100,Math.max(0,t*100));function rl(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 hv=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],Zh={google:hv};function ef(t,e){const n=Zh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function tf(t){return Zh[t]??[]}function sf(t){return[...t].sort((e,n)=>e.order-n.order)}function fv(t,e){const n=new Map;for(const r of Object.keys(t)){const a=ef(r,e)?.id??null;n.has(a)||n.set(a,[]),n.get(a).push(r)}return n}function gv(t,e,n){const r=new Map;for(const i of t){const a=e(i),c=ef(a,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(i)}return r}function xv(t,e){return e.filter(n=>{const r=n.toLowerCase(),i=r.includes("/")?r.split("/")[1]:r;return!!(i.startsWith("gemini-3-")||i.startsWith("claude-"))})}const Td=6e4,Eu=t=>{const e=Lr.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))):Td,i=t?.usageDisplayMode==="remaining"?"remaining":"usage",a=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,o=a?a.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[u,f]of Object.entries(d))Array.isArray(f)&&(c[u]=f.filter(b=>typeof b=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,f]of Object.entries(m))Array.isArray(f)&&(p[u]=f.filter(b=>typeof b=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:i,dropdownProviderIds:o,selectedModels:c,expandedFamilies:p}},bv=async()=>{const t=lr()?.settings;if(t)try{const n=(await t.load())?.settings;return Eu(n??null)}catch{}if(!pn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Eu(n)}}return{autoRefresh:!1,refreshIntervalMs:Td,displayMode:"usage",dropdownProviderIds:Lr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ls=ur()(xi((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Td,displayMode:"usage",dropdownProviderIds:Lr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await bv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Lr.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const i=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:i})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),i=await r.json().catch(()=>null);if(!r.ok)throw new Error(i?.error||"Failed to fetch quota");const a=i;t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(a),{results:c,error:null}})}catch(r){const i=r instanceof Error?r.message:"Failed to fetch quota",a={providerId:n,providerName:n,ok:!1,configured:!1,error:i,usage:null,fetchedAt:Date.now()};t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(a),{results:c,error:i}})}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(i=>({selectedModels:{...i.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(i=>{const a=i.selectedModels[n]??[],c=a.includes(r)?a.filter(d=>d!==r):[...a,r];return{selectedModels:{...i.selectedModels,[n]:c}}})},setExpandedFamilies:(n,r)=>{t(i=>({expandedFamilies:{...i.expandedFamilies,[n]:r}})),Ps({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(i=>{const a=i.expandedFamilies[n]??[],c=a.includes(r)?a.filter(d=>d!==r):[...a,r];return{expandedFamilies:{...i.expandedFamilies,[n]:c}}}),Ps({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const a=xv(n,r);a.length!==0&&(t(o=>({selectedModels:{...o.selectedModels,[n]:a}})),Ps({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),nf=()=>{const t=rt.c(5),e=Ls(yv),n=Ls(vv),r=Ls(wv);let i,a;t[0]!==e||t[1]!==r||t[2]!==n?(i=()=>{if(!e)return;const o=window.setInterval(()=>{r()},n);return()=>window.clearInterval(o)},a=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=a):(i=t[3],a=t[4]),l.useEffect(i,a)};function yv(t){return t.autoRefresh}function vv(t){return t.refreshIntervalMs}function wv(t){return t.fetchAllQuotas}const al=$e.forwardRef((t,e)=>{const n=rt.c(11);let r,i;n[0]!==t?({className:r,...i}=t,n[0]=t,n[1]=r,n[2]=i):(r=n[1],i=n[2]);let a;n[3]!==r?(a=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]=a):a=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(Ig,{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]!==i||n[8]!==e||n[9]!==a?(d=s.jsx(Pg,{className:a,style:o,...i,ref:e,children:c}),n[7]=i,n[8]=e,n[9]=a,n[10]=d):d=n[10],d});al.displayName="Switch";const xo=()=>{try{const e=Es.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=In.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},Ru=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],Fu=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},bo=t=>typeof t!="string"?void 0:t.trim()||void 0,ql=800,jv=5e3,Nv="__default__",_c=new Map,Jl=new Map,rf=t=>t?.trim()||Nv,Ql=t=>{_c.delete(rf(t))},Ji=ur()(xi(Xi((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=xo(),i=rf(r),a=Date.now(),o=_c.get(i)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&a-o<jv)return!0;const d=Jl.get(i);if(!n?.force&&d)return d;const p=(async()=>{t({isLoading:!0});try{const m=r?`?directory=${encodeURIComponent(r)}`:"",u=await fetch(`/api/config/mcp${m}`,{headers:r?{"x-opencode-directory":r}:void 0});if(!u.ok)throw new Error("Failed to load MCP configs");const f=await u.json();return t({mcpServers:f,isLoading:!1}),_c.set(i,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();Jl.set(i,p);try{return await p}finally{Jl.delete(i)}},createMcp:async n=>{$l("Creating MCP server configuration…");let r=!1;try{const i=Lu(n),a=xo(),o=a?`?directory=${encodeURIComponent(a)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-opencode-directory":a}:{}},body:JSON.stringify(i)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return Ql(a),d?.requiresReload?(r=!0,await Bl({message:d.message,delayMs:d.reloadDelayMs??ql,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(i){return console.error("[McpConfigStore] Failed to create MCP:",i),{ok:!1}}finally{r||_l()}},updateMcp:async(n,r)=>{$l("Updating MCP server configuration…");let i=!1;try{const a=Lu(r),o=xo(),c=o?`?directory=${encodeURIComponent(o)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(a)}),p=await d.json().catch(()=>null);if(!d.ok)throw new Error(p?.error||"Failed to update MCP server");return Ql(o),p?.requiresReload?(i=!0,await Bl({message:p.message,delayMs:p.reloadDelayMs??ql,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(a){throw console.error("[McpConfigStore] Failed to update MCP:",a),a}finally{i||_l()}},deleteMcp:async n=>{$l("Deleting MCP server configuration…");let r=!1;try{const i=xo(),a=i?`?directory=${encodeURIComponent(i)}`:"",o=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${a}`,{method:"DELETE",headers:i?{"x-opencode-directory":i}:void 0}),c=await o.json().catch(()=>null);if(!o.ok)throw new Error(c?.error||"Failed to delete MCP server");return Ql(i),c?.requiresReload&&(r=!0,await Bl({message:c.message,delayMs:c.reloadDelayMs??ql,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(i){return console.error("[McpConfigStore] Failed to delete MCP:",i),{ok:!1}}finally{r||_l()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:xl(()=>Zr()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function Lu(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=Fu(t.environment)??{}),t.headers!==void 0&&(e.headers=Fu(t.headers)??{}),t.oauthEnabled!==void 0||t.oauthClientId!==void 0||t.oauthClientSecret!==void 0||t.oauthScope!==void 0||t.oauthRedirectUri!==void 0)if(t.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:bo(t.oauthClientId),clientSecret:bo(t.oauthClientSecret),scope:bo(t.oauthScope),redirectUri:bo(t.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:t.oauthEnabled?e.oauth={}:e.oauth=!1}if(t.timeout!==void 0){const n=Number(t.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return t.enabled!==void 0&&(e.enabled=t.enabled),e}const Sv={},kv={},_r=t=>{if(typeof t!="string")return null;const e=t.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},Ha=t=>_r(t)??"__global__",ca=t=>{const e=_r(t);return e?In.getScopedApiClient(e):In.getApiClient()},Cn=ur()(xi((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Ha(n??Ws.getState().currentDirectory);return e().byDirectory[r]??Sv},getDiagnosticForDirectory:n=>{const r=Ha(n??Ws.getState().currentDirectory);return e().diagnosticsByDirectory[r]??kv},getErrorForDirectory:n=>{const r=Ha(n??Ws.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=_r(n?.directory??Ws.getState().currentDirectory),i=Ha(r);n?.silent||t(a=>({loadingKeys:{...a.loadingKeys,[i]:!0},lastErrorKeys:{...a.lastErrorKeys,[i]:null}}));try{const c=(await ca(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[i]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[i]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[i]??{}).filter(([p])=>!c[p]))},loadingKeys:{...d.loadingKeys,[i]:!1},lastErrorKeys:{...d.lastErrorKeys,[i]:null}}))}catch(a){const o=a instanceof Error?a.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[i]:!1},lastErrorKeys:{...c.lastErrorKeys,[i]:o}}))}},connect:async(n,r)=>{const i=_r(r??Ws.getState().currentDirectory),a=Ha(i),o=ca(i);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,[a]:{...p.diagnosticsByDirectory[a]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:i,silent:!0})},disconnect:async(n,r)=>{const i=_r(r??Ws.getState().currentDirectory);await ca(i).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},startAuth:async(n,r)=>{const i=_r(r??Ws.getState().currentDirectory),c=(await ca(i).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,i)=>{const a=_r(i??Ws.getState().currentDirectory);await ca(a).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},clearAuth:async(n,r)=>{const i=_r(r??Ws.getState().currentDirectory);await ca(i).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},testConnection:async(n,r)=>{const i=_r(r??Ws.getState().currentDirectory),a=Ha(i),o=ca(i),d=e().getStatusForDirectory(i)[n]?.status==="connected";let p,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(b){p=b instanceof Error?b.message:"Connection failed",t(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[a]:{...h.diagnosticsByDirectory[a]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:i,silent:!0});const u=e().getStatusForDirectory(i)[n],f=u;if(!d&&u?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(b){m=`Connection test succeeded, but cleanup disconnect failed: ${b instanceof Error?b.message:"Disconnect failed"}`}await e().refresh({directory:i,silent:!0})}return{status:f??e().getStatusForDirectory(i)[n],error:p,warning:m}}})));function Cv(t){const e=rt.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 i;return e[2]!==t?(i=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]=i):i=e[3],i}const Iv=(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}},Pv=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},af=({active:t,className:e})=>{const{t:n}=mt(),i=Ws(g=>g.currentDirectory)??null,a=Cn(g=>g.getStatusForDirectory(i)),o=Cn(g=>g.refresh),c=Cn(g=>g.connect),d=Cn(g=>g.disconnect),p=Ji(g=>g.mcpServers),m=Ji(g=>g.loadMcpConfigs),[u,f]=l.useState(!1),[b,h]=l.useState(null);l.useEffect(()=>{o({directory:i,silent:!0})},[o,i]),l.useEffect(()=>{m({force:!0})},[m]),l.useEffect(()=>{t&&Promise.all([o({directory:i,silent:!0}),m({force:!0})])},[t,o,i,m]);const v=l.useMemo(()=>{const g=new Set(Object.keys(a));for(const w of p)w?.name&&g.add(w.name);return Array.from(g).sort((w,y)=>w.localeCompare(y))},[p,a]),x=l.useCallback(g=>{if(g?.preventDefault(),u)return;f(!0);const w=new Promise(y=>setTimeout(y,500));Promise.all([o({directory:i}),w]).finally(()=>{f(!1)})},[u,o,i]);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")}),i&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:i.split("/").pop()||i})]}),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(C,{name:"refresh",className:pe("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[v.map(g=>{const w=a[g],y=Pv(w),S=w?.status==="connected",D=b===g,j=Iv(w,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:pe("h-2 w-2 rounded-full flex-shrink-0",y==="success"&&"bg-status-success",y==="error"&&"bg-status-error",y==="warning"&&"bg-status-warning",y==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(Pt,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(al,{checked:S,disabled:D,className:"data-[checked]:bg-status-info",onCheckedChange:async I=>{h(g);try{I?await c(g,i):await d(g,i)}finally{h(null)}}})]},g)}),v.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},Qi=t=>{const e=rt.c(20),{percent:n,tonePercent:r,className:i,expectedMarkerPercent:a}=t;let o;e[0]!==n?(o=dv(n)??0,e[0]=n,e[1]=o):o=e[1];const c=o,d=r??n;let p;e[2]!==d?(p=Xh(d),e[2]=d,e[3]=p):p=e[3];const m=p,u=a!=null?Math.max(0,Math.min(100,a)):null;let f;e[4]!==m?(f=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=f):f=e[5];const b=f;let h;e[6]!==i?(h=pe("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=h):h=e[7];const v=`${c}%`;let x;e[8]!==b||e[9]!==v?(x={...b,width:v},e[8]=b,e[9]=v,e[10]=x):x=e[10];let g;e[11]!==c||e[12]!==x?(g=s.jsx("div",{className:"h-full transition-all duration-300",style:x,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=x,e[13]=g):g=e[13];let w;e[14]!==u?(w=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=w):w=e[15];let y;return e[16]!==h||e[17]!==g||e[18]!==w?(y=s.jsxs("div",{className:h,children:[g,w]}),e[16]=h,e[17]=g,e[18]=w,e[19]=y):y=e[19],y},Yi=t=>{const e=rt.c(67),{paceInfo:n,className:r,compact:i}=t,a=i===void 0?!1:i,{t:o}=mt();let c;e[0]!==n.status?(c=pv(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 I;e[2]!==o?(I=o("settings.usage.pace.status.onTrack"),e[2]=o,e[3]=I):I=e[3],p=I;break e}case"slightly-fast":{let I;e[4]!==o?(I=o("settings.usage.pace.status.slightlyFast"),e[4]=o,e[5]=I):I=e[5],p=I;break e}case"too-fast":{let I;e[6]!==o?(I=o("settings.usage.pace.status.tooFast"),e[6]=o,e[7]=I):I=e[7],p=I;break e}case"exhausted":{let I;e[8]!==o?(I=o("settings.usage.pace.status.usedUp"),e[8]=o,e[9]=I):I=e[9],p=I;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==o?(u=o("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=o,e[12]=u):u=e[12];const f=u;if(a){let I;e[13]!==r?(I=pe("flex items-center gap-1.5",r),e[13]=r,e[14]=I):I=e[14];let A;e[15]!==d?(A={backgroundColor:d},e[15]=d,e[16]=A):A=e[16];let E;e[17]!==m||e[18]!==A?(E=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:A,title:m}),e[17]=m,e[18]=A,e[19]=E):E=e[19];let P;e[20]!==d?(P={color:d},e[20]=d,e[21]=P):P=e[21];const k=n.isExhausted?void 0:f;let N;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==o?(N=n.isExhausted?s.jsx(s.Fragment,{children:o("settings.usage.pace.wait",{duration:Mu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:o("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=o,e[26]=N):N=e[26];let T;e[27]!==N||e[28]!==P||e[29]!==k?(T=s.jsx("span",{className:"typography-micro tabular-nums",style:P,title:k,children:N}),e[27]=N,e[28]=P,e[29]=k,e[30]=T):T=e[30];let M;return e[31]!==T||e[32]!==I||e[33]!==E?(M=s.jsxs("div",{className:I,children:[E,T]}),e[31]=T,e[32]=I,e[33]=E,e[34]=M):M=e[34],M}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 h;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==o?(h=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=o,e[40]=h):h=e[40];let v;e[41]!==h?(v=s.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[41]=h,e[42]=v):v=e[42];let x;e[43]!==d?(x={color:d},e[43]=d,e[44]=x):x=e[44];let g;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==f||e[49]!==m||e[50]!==o?(g=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:Mu(n.remainingSeconds)})]}):s.jsxs("span",{title:f,children:[s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=f,e[49]=m,e[50]=o,e[51]=g):g=e[51];let w;e[52]!==x||e[53]!==g?(w=s.jsx("span",{className:"typography-micro tabular-nums",style:x,children:g}),e[52]=x,e[53]=g,e[54]=w):w=e[54];let y;e[55]!==d?(y={backgroundColor:d},e[55]=d,e[56]=y):y=e[56];let S;e[57]!==m||e[58]!==y?(S=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:y,title:m}),e[57]=m,e[58]=y,e[59]=S):S=e[59];let D;e[60]!==w||e[61]!==S?(D=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,S]}),e[60]=w,e[61]=S,e[62]=D):D=e[62];let j;return e[63]!==D||e[64]!==b||e[65]!==v?(j=s.jsxs("div",{className:b,children:[v,D]}),e[63]=D,e[64]=b,e[65]=v,e[66]=j):j=e[66],j},cr=Ag,jr=t=>{const e=rt.c(14);let n,r,i,a;e[0]!==t?({className:i,asChild:n,children:r,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(n=e[1],r=e[2],i=e[3],a=e[4]);let o;e[5]!==n||e[6]!==r?(o=n&&$e.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=o):o=e[7];const c=o;let d;e[8]!==i?(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",i),e[8]=i,e[9]=d):d=e[9];let p;return e[10]!==a||e[11]!==c||e[12]!==d?(p=s.jsx(Dg,{className:d,...a,...c}),e[10]=a,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},dr=t=>{const e=rt.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 i;e[3]!==n?(i=pe("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Tg,{className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a},ta=[{id:"finder",label:"Finder",appName:"Finder"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm"},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"xcode",label:"Xcode",appName:"Xcode"},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"zed",label:"Zed",appName:"Zed"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"kiro",label:"Kiro",appName:"Kiro"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],Vc="finder",zc=new Set(["finder","terminal"]),Uc=t=>t?ta.find(e=>e.id===t)??null:null,Yl=()=>ta.filter(t=>zc.has(t.id)).map(t=>({...t})),Av=()=>{if(typeof window>"u")return Vc;const t=window.localStorage.getItem("openInAppId");return t&&Uc(t)?t:Vc};let Xl=!1,Ga=!1,Jr=!1,Qr=0,_i=null;const Ou=()=>{_i&&(clearTimeout(_i),_i=null)},Pr=ur()((t,e)=>({selectedAppId:Av(),availableApps:Yl(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Xl||typeof window>"u")return;Xl=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:Yl(),hasLoadedApps:p});return}const m=new Set(d.map(h=>h.name)),u=new Map(d.map(h=>[h.name,h.iconDataUrl??void 0])),b=ta.filter(h=>m.has(h.appName)||zc.has(h.id)).map(h=>({...h,iconDataUrl:u.get(h.appName)}));t({availableApps:b,hasLoadedApps:!0})},r=async d=>{if(!ka()||!Ur()||Ga||e().hasLoadedApps&&!d)return;const m=ta.map(u=>u.appName);Ou(),Ga=!0,Jr=!1,t({isScanning:!0});try{const{apps:u,success:f,hasCache:b,isCacheStale:h}=await eu(m,d),v=f&&!b&&u.length===0&&Qr<3;if(t({isCacheStale:b?h:!1}),n(u,f?!v:!1),f){if(v){const g=[800,1600,3200][Qr]??3200;Qr+=1,Jr=!0,_i=setTimeout(()=>{r()},g);return}Qr=0,Jr=!1;return}if(Qr<3){const g=[1e3,3e3,7e3][Qr]??7e3;Qr+=1,Jr=!0,_i=setTimeout(()=>{r()},g)}}finally{Ga=!1,Jr||t({isScanning:!1})}};r();const i=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&Uc(p.openInAppId)?p.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},a=()=>{r()},o=d=>{const p=d.detail;Array.isArray(p)&&(Qr=3,Jr=!1,t({isScanning:!1,isCacheStale:!1}),n(p))};window.addEventListener("openchamber:settings-synced",i),window.addEventListener("openchamber:app-ready",a),window.addEventListener("openchamber:installed-apps-updated",o),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Xl||e().initialize(),!ka()||!Ur()||Ga||e().hasLoadedApps&&!n)return;const i=ta.map(a=>a.appName);Ou(),n&&t({hasLoadedApps:!1}),Ga=!0,Jr=!1,t({isScanning:!0});try{const{apps:a,hasCache:o,isCacheStale:c}=await eu(i,n),d=new Set(a.map(f=>f.name)),p=new Map(a.map(f=>[f.name,f.iconDataUrl??void 0])),u=ta.filter(f=>d.has(f.appName)||zc.has(f.id)).map(f=>({...f,iconDataUrl:p.get(f.appName)}));t({availableApps:u.length>0?u:Yl(),hasLoadedApps:u.length>0,isCacheStale:o?c:!1})}finally{Ga=!1,Jr||t({isScanning:!1})}},selectApp:async n=>{Uc(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Ps({openInAppId:n}))}})),Dv="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",Tv="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",Zl=t=>({...t,fallbackIconDataUrl:t.id==="finder"?Dv:t.id==="terminal"?Tv:void 0}),$u=t=>{const e=rt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:i}=t,[a,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||i;if(p&&!a){let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=()=>o(!0),e[2]=f):f=e[2];let b;return e[3]!==p?(b=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:f}),e[3]=p,e[4]=b):b=e[4],b}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=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},Mv=t=>{const e=rt.c(82),{directory:n,className:r}=t,{t:i}=mt(),a=Pr(Ev),o=Pr(Rv),c=Pr(Fv),d=Pr(Lv),p=Pr(Ov),m=Pr($v),u=Pr(Bv);let f,b;e[0]!==p?(f=()=>{p()},b=[p],e[0]=p,e[1]=f,e[2]=b):(f=e[1],b=e[2]),l.useEffect(f,b);const h=ka()&&Ur();let v;e:{let K;e[3]!==o||e[4]!==a?(K=o.find(ue=>ue.id===a)??o.find(_v)??o[0]??ta[0],e[3]=o,e[4]=a,e[5]=K):K=e[5];const le=K;if(le){let ue;e[6]!==le?(ue=Zl(le),e[6]=le,e[7]=ue):ue=e[7],v=ue;break e}let Se;e[8]===Symbol.for("react.memo_cache_sentinel")?(Se=Zl(ta[0]),e[8]=Se):Se=e[8],v=Se}const x=v;if(!h||!n||o.length===0)return null;let g;e[9]!==n?(g=async K=>{await gx(n,K.id,K.appName)||await Zo(n,K.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let y;e[11]!==w||e[12]!==u?(y=async K=>{await u(K.id),await w(K)},e[11]=w,e[12]=u,e[13]=y):y=e[13];const S=y;let D;e[14]!==n||e[15]!==i?(D=async()=>{(await Rn(n)).ok&&q.success(i("openInApp.toast.pathCopied"))},e[14]=n,e[15]=i,e[16]=D):D=e[16];const j=D;let I;e[17]!==r?(I=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]=I):I=e[18];let A;e[19]!==w||e[20]!==x?(A=()=>{w(x)},e[19]=w,e[20]=x,e[21]=A):A=e[21];let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=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]=E):E=e[22];let P;e[23]!==x.label||e[24]!==i?(P=i("openInApp.actions.openInAria",{app:x.label}),e[23]=x.label,e[24]=i,e[25]=P):P=e[25];let k;e[26]!==x.fallbackIconDataUrl||e[27]!==x.iconDataUrl||e[28]!==x.label?(k=s.jsx($u,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[26]=x.fallbackIconDataUrl,e[27]=x.iconDataUrl,e[28]=x.label,e[29]=k):k=e[29];const N=d?"animate-pulse text-muted-foreground":void 0;let T;e[30]!==N?(T=pe("header-open-label",N),e[30]=N,e[31]=T):T=e[31];let M;e[32]!==i?(M=i("openInApp.actions.open"),e[32]=i,e[33]=M):M=e[33];let R;e[34]!==T||e[35]!==M?(R=s.jsx("span",{className:T,children:M}),e[34]=T,e[35]=M,e[36]=R):R=e[36];let L;e[37]!==P||e[38]!==k||e[39]!==R||e[40]!==A?(L=s.jsxs("button",{type:"button",onClick:A,className:E,"aria-label":P,children:[k,R]}),e[37]=P,e[38]=k,e[39]=R,e[40]=A,e[41]=L):L=e[41];let O;e[42]===Symbol.for("react.memo_cache_sentinel")?(O=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]=O):O=e[42];let V;e[43]!==i?(V=i("openInApp.actions.chooseAppAria"),e[43]=i,e[44]=V):V=e[44];let $;e[45]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4"}),e[45]=$):$=e[45];let B;e[46]!==V?(B=s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:O,"aria-label":V,children:$})}),e[46]=V,e[47]=B):B=e[47];let H;e[48]===Symbol.for("react.memo_cache_sentinel")?(H={translate:"-30px 0"},e[48]=H):H=e[48];let _;e[49]!==j?(_=()=>{j()},e[49]=j,e[50]=_):_=e[50];let se;e[51]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(C,{name:"file-copy",className:"h-4 w-4"}),e[51]=se):se=e[51];let oe;e[52]!==i?(oe=i("openInApp.actions.copyPath"),e[52]=i,e[53]=oe):oe=e[53];let ae;e[54]!==oe?(ae=s.jsx("span",{className:"typography-ui-label text-foreground",children:oe}),e[54]=oe,e[55]=ae):ae=e[55];let ne;e[56]!==_||e[57]!==ae?(ne=s.jsxs(zt,{className:"flex items-center gap-2",onClick:_,children:[se,ae]}),e[56]=_,e[57]=ae,e[58]=ne):ne=e[58];let xe;e[59]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx(An,{}),e[59]=xe):xe=e[59];let te;if(e[60]!==o||e[61]!==S||e[62]!==x.id){let K;e[64]!==S||e[65]!==x.id?(K=le=>{const Se=Zl(le);return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{S(le)},children:[s.jsx($u,{label:le.label,iconDataUrl:le.iconDataUrl,fallbackIconDataUrl:Se.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:le.label}),x.id===le.id?s.jsx(C,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},le.id)},e[64]=S,e[65]=x.id,e[66]=K):K=e[66],te=o.map(K),e[60]=o,e[61]=S,e[62]=x.id,e[63]=te}else te=e[63];let F;e[67]!==c||e[68]!==m||e[69]!==i?(F=c?s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(C,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("openInApp.actions.refreshApps")})]}):null,e[67]=c,e[68]=m,e[69]=i,e[70]=F):F=e[70];let z;e[71]!==ne||e[72]!==te||e[73]!==F?(z=s.jsxs($s,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:H,children:[ne,xe,te,F]}),e[71]=ne,e[72]=te,e[73]=F,e[74]=z):z=e[74];let Q;e[75]!==B||e[76]!==z?(Q=s.jsxs(Bs,{children:[B,z]}),e[75]=B,e[76]=z,e[77]=Q):Q=e[77];let re;return e[78]!==L||e[79]!==Q||e[80]!==I?(re=s.jsxs("div",{className:I,children:[L,Q]}),e[78]=L,e[79]=Q,e[80]=I,e[81]=re):re=e[81],re};function Ev(t){return t.selectedAppId}function Rv(t){return t.availableApps}function Fv(t){return t.isCacheStale}function Lv(t){return t.isScanning}function Ov(t){return t.initialize}function $v(t){return t.loadInstalledApps}function Bv(t){return t.selectApp}function _v(t){return t.id===Vc}const Vv=1e6,zv="terminal-store";let Bu=!1;const ec=t=>typeof t=="object"&&t!==null,Uv=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function Un(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const tc=(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}),of=/\x1b\[[0-9;]*m/g,Wv=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,Kv=new Set([".",",",";",":","!","?"]),Hv=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",i=e.slice(0,-1),a=(i.match(new RegExp(`\\${r}`,"g"))||[]).length,o=(i.match(new RegExp(`\\${n}`,"g"))||[]).length;if(a>o)break;e=i;continue}if(Kv.has(n)){e=e.slice(0,-1);continue}break}return e},Gv=t=>{if(!t)return null;const n=t.replace(of,"").match(Wv);if(!n?.[1])return null;let r=Hv(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},qv=t=>{if(!t)return null;const n=t.replace(of,"").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}/`},sc=t=>({tabs:[t],activeTabId:t.id}),Cr=(t,e)=>t.tabs.findIndex(n=>n.id===e),dn=ur()(xi(Xi((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=Un(n);r&&t(i=>{if(i.sessions.has(r))return i;const a=new Map(i.sessions),o=`tab-${i.nextTabId}`,c=tc(o,"Terminal");return a.set(r,sc(c)),{sessions:a,nextTabId:i.nextTabId+1}})},getDirectoryState:n=>{const r=Un(n);return e().sessions.get(r)},getActiveTab:n=>{const r=Un(n),i=e().sessions.get(r);if(!i)return;const a=i.activeTabId;return a?i.tabs.find(o=>o.id===a)??i.tabs[0]:i.tabs[0]},createTab:n=>{const r=Un(n);if(!r)return"tab-invalid";const i=`tab-${e().nextTabId}`;return t(a=>{const o=new Map(a.sessions),c=o.get(r),d=a.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=tc(i,m);return c?o.set(r,{...c,tabs:[...c.tabs,u]}):o.set(r,sc(u)),{sessions:o,nextTabId:d}}),i},setActiveTab:(n,r)=>{const i=Un(n);t(a=>{const o=new Map(a.sessions),c=o.get(i);return!c||c.activeTabId===r||Cr(c,r)<0?a:(o.set(i,{...c,activeTabId:r}),{sessions:o})})},setTabLabel:(n,r,i)=>{const a=Un(n),o=i.trim();o&&t(c=>{const d=new Map(c.sessions),p=d.get(a);if(!p)return c;const m=Cr(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(a,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,i)=>{const a=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(a);if(!d)return o;const p=Cr(d,r);if(p<0)return o;const m=i?.trim()||null;if(d.tabs[p]?.iconKey===m)return o;const u=[...d.tabs];return u[p]={...u[p],iconKey:m},c.set(a,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const i=Un(n),c=e().sessions.get(i)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await px(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(i);if(!m)return d;const u=Cr(m,r);if(u<0)return d;const f=m.tabs.filter(x=>x.id!==r),b=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,x])=>!(x.directory===i&&x.tabId===r))),h=Object.keys(b).length!==Object.keys(d.projectActionRuns).length;if(f.length===0){const x=`tab-${d.nextTabId}`,g=tc(x,"Terminal");return p.set(i,sc(g)),{sessions:p,nextTabId:d.nextTabId+1,...h?{projectActionRuns:b}:{}}}let v=m.activeTabId;return m.activeTabId===r&&(v=f[Math.min(u,f.length-1)]?.id??f[0]?.id??null),p.set(i,{...m,tabs:f,activeTabId:v}),{sessions:p,...h?{projectActionRuns:b}:{}}})},setTabSessionId:(n,r,i)=>{const a=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(a);if(!d)return o;const p=Cr(d,r);if(p<0)return o;const m=d.tabs[p],u=i!==null&&m.terminalSessionId!==i,f=i?"running":m.terminalSessionId?"exited":m.lifecycle,b={...m,terminalSessionId:i,lifecycle:f,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},h=[...d.tabs];return h[p]=b,c.set(a,{...d,tabs:h}),{sessions:c}})},setTabLifecycle:(n,r,i)=>{const a=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(a);if(!d)return o;const p=Cr(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],lifecycle:i,isConnecting:!1},c.set(a,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,i)=>{const a=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(a);if(!d)return o;const p=Cr(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],isConnecting:i},c.set(a,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,i)=>{if(!i)return;const a=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(a);if(!d)return o;const p=Cr(d,r);if(p<0)return o;const m=d.tabs[p],u=o.nextChunkId,f={id:u,data:i},b=[...m.bufferChunks,f];let h=m.bufferLength+i.length;for(;h>Vv&&b.length>1;){const w=b.shift();if(!w)break;h-=w.data.length}const v=m.previewUrlLocked?null:Gv(i)??qv(i),x=!!(v&&v!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:b,bufferLength:h,...x?{previewUrl:v,previewAutoOpened:!1}:null},c.set(a,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,i,a={})=>{const o=Un(n);t(c=>{const d=new Map(c.sessions),p=d.get(o);if(!p)return c;const m=Cr(p,r);if(m<0)return c;const u=p.tabs[m],f=a.autoOpened??u.previewAutoOpened,b=a.locked??u.previewUrlLocked;if(u.previewUrl===i&&u.previewAutoOpened===f&&u.previewUrlLocked===b)return c;const h=[...p.tabs];return h[m]={...u,previewUrl:i,previewAutoOpened:f,previewUrlLocked:b},d.set(o,{...p,tabs:h}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const i=Un(n);t(a=>{const o=new Map(a.sessions),c=o.get(i);if(!c)return a;const d=Cr(c,r);if(d<0)return a;const p=c.tabs[d];if(!p.previewUrl||p.previewAutoOpened)return a;const m=[...c.tabs];return m[d]={...p,previewAutoOpened:!0},o.set(i,{...c,tabs:m}),{sessions:o}})},setProjectActionRun:n=>{t(r=>{const i=r.projectActionRuns[n.key];return i&&i.directory===n.directory&&i.actionId===n.actionId&&i.tabId===n.tabId&&i.sessionId===n.sessionId&&i.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(i=>{const a=i.projectActionRuns[n];return!a||a.status===r?i:{projectActionRuns:{...i.projectActionRuns,[n]:{...a,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const i={...r.projectActionRuns};return delete i[n],{projectActionRuns:i}})},clearBuffer:(n,r)=>{const i=Un(n);t(a=>{const o=new Map(a.sessions),c=o.get(i);if(!c)return a;const d=Cr(c,r);if(d<0)return a;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},o.set(i,{...c,tabs:p}),{sessions:o}})},removeDirectory:n=>{const r=Un(n);t(i=>{const a=new Map(i.sessions);a.delete(r);const o=Object.fromEntries(Object.entries(i.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:a,projectActionRuns:o}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:zv,storage:xl(()=>wh()),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(!ec(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let i=0;for(const c of n){if(!Array.isArray(c)||c.length!==2)continue;const[d,p]=c;if(typeof d!="string"||!ec(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const h of m){if(!ec(h))continue;const v=typeof h.id=="string"?h.id:null;if(!v)continue;const x=Uv(v);x!==null&&(i=Math.max(i,x));const g=typeof h.terminalSessionId=="string"||h.terminalSessionId===null?h.terminalSessionId:null,w=h.lifecycle,y=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:v,label:typeof h.label=="string"?h.label:"Terminal",iconKey:typeof h.iconKey=="string"?h.iconKey:null,terminalSessionId:g,lifecycle:y,createdAt:typeof h.createdAt=="number"?h.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const f=typeof p.activeTabId=="string"?p.activeTabId:null,b=f?u.some(h=>h.id===f):!1;r.set(d,{tabs:u,activeTabId:b?f:u[0].id})}const a=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,o=Math.max(e.nextTabId,a,i+1);return{...e,sessions:r,nextChunkId:1,nextTabId:o,hasHydrated:!0}}})));if(typeof window<"u"&&!Bu){Bu=!0;const t=dn.persist,e=()=>{dn.getState().hasHydrated||dn.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const _u=(t,e)=>e.updatedAtMs-t.updatedAtMs,Qs=ur((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([vx(),su()]),i={};for(const a of r.sort(_u))i[a.id]=a;e().listenerReady||await wx(a=>{t(o=>({statusesById:{...o.statusesById,[a.id]:a}}))}),t({instances:n.instances,statusesById:i,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 yx();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await su(),r={};for(const i of n.sort(_u))r[i.id]=i;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await bx({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,i=r.some(a=>a.id===n.id)?r.map(a=>a.id===n.id?n:a):[n,...r];await e().setInstances(i)},createFromCommand:async(n,r,i)=>{const a=jx(n,r);i&&i.trim()&&(a.nickname=i.trim()),await e().upsertInstance(a)},removeInstance:async n=>{await tu(n).catch(()=>{});const r=e().instances.filter(i=>i.id!==n);await e().setInstances(r),t(i=>{const a={...i.statusesById};return delete a[n],{statusesById:a}})},connect:async n=>{t({error:null});try{await xx(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 tu(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})})),lf=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],_o=Object.fromEntries(lf.map(t=>[t.key,t.Icon])),Wc="openchamber:project-actions-updated",cf=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},Yr=(t,e)=>`${cf(t)}::${e}`,Jv=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Vu=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},Qv=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=Vu(e.localPort),r=Vu(e.remotePort);if(!n||!r)return null;const i=Jv(e.localHost||t.localForward.bindHost||"127.0.0.1"),a=(e.remoteHost||"127.0.0.1").trim(),o=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${o} - ${i}:${n} -> ${a}:${r}`,url:`http://${i}:${n}`}},df=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const i=Qv(n,r);i&&e.push(i)}return e},Yv=(t,e)=>{const n=(t||"").trim();return n&&df(e).find(a=>a.id===n)?.url||null},Xv=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Zv=["dev","start","preview","serve"];async function e1(t,e,n){if(!t)return null;const r=n1(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const i=r1(n);if(i){const a=await a1(t);return{command:`${a==="npm"?"npm run":a==="yarn"?"yarn":a==="pnpm"?"pnpm":a==="bun"?"bun run --shell=bun":"npm run"} ${i}`,label:`Start (${i})`}}}if(await t1(t)){const i=await s1(),a=typeof i=="number"&&Number.isFinite(i)&&i>0?i:8e3;return{command:`python3 -m http.server ${a}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${a}/`}}return null}async function t1(t){const e=`${t}/index.html`,n=await il(e);return typeof n=="string"&&n.trim().length>0}async function s1(){try{const t=await fetch("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function n1(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Zv.some(i=>n.includes(i)))return e}return t.length===1?t[0]:null}function r1(t){for(const{pattern:e}of Xv)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function a1(t){const e=await il(`${t}/package.json`);if(e)try{const r=JSON.parse(e),i=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(i.startsWith("bun@"))return"bun";if(i.startsWith("pnpm@"))return"pnpm";if(i.startsWith("yarn@"))return"yarn";if(i.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,i]of n){const a=await il(`${t}/${r}`);if(typeof a=="string"&&a.trim().length>0)return i}return"npm"}async function il(t){const e=lr()?.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 i1(t){try{const e=await il(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const o1=t=>new Promise(e=>{window.setTimeout(e,t)}),l1="\x1B",c1=new RegExp(`${l1}\\[[0-9;?]*[ -/]*[@-~]`,"g"),d1=/https?:\/\/[^\s<>'"`]+/gi,sr="__openchamber_auto_discover_preview__",u1=15e3,m1=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},p1=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}},h1=t=>{const n=t.replace(c1,"").match(d1);if(!n||n.length===0)return null;const r=n.map(a=>a.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const i=[];for(const a of r)try{const o=new URL(a);o.port&&o.port.length>0&&i.push({raw:a,parsed:o})}catch{}if(i.length>0){const a=o=>{const{parsed:c}=o,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,f=m==="/"||m==="",b=!!(c.search||c.hash);let h=0;return p&&(h+=50),f&&(h+=30),h-=Math.min(u*5,20),b&&(h-=10),h};return i.sort((o,c)=>a(c)-a(o)),i[0]?.parsed.origin??i[0]?.raw??null}return r[0]??null},f1=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const i=r[0],a=r[1].slice(0,3),o=`${i} ${a}`.trim();return r.length>2||o.length<n.length?`${o}...`:o}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},zu=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:i=!1})=>{const{t:a}=mt(),{terminal:o,runtime:c}=_n(),{isMobile:d}=rn(),p=l.useMemo(()=>wn(),[]),m=Qs(G=>G.instances),u=Qs(G=>G.load),f=Me(G=>G.setBottomTerminalOpen),b=Me(G=>G.setActiveMainTab),h=Me(G=>G.setSettingsPage),v=Me(G=>G.setSettingsDialogOpen),x=Me(G=>G.setSettingsProjectsSelectedId),g=Me(G=>G.openContextPreview),w=dn(G=>G.sessions),y=dn(G=>G.ensureDirectory),S=dn(G=>G.setTabLabel),D=dn(G=>G.setTabIconKey),j=dn(G=>G.setActiveTab),I=dn(G=>G.setConnecting),A=dn(G=>G.setTabSessionId),E=dn(G=>G.setTabPreviewUrl),P=dn(G=>G.projectActionRuns),k=dn(G=>G.setProjectActionRun),N=dn(G=>G.updateProjectActionRunStatus),T=dn(G=>G.removeProjectActionRun),[M,R]=l.useState([]),[L,O]=l.useState(null),[V,$]=l.useState(!1),B=l.useRef({}),H=l.useRef({}),_=l.useRef({}),se=l.useRef({}),oe=l.useRef(0),ae=t?.id??null,ne=t?.path??"",xe=l.useMemo(()=>ae?{id:ae,path:ne}:null,[ae,ne]);l.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const te=l.useCallback(async G=>{await Qn(G)},[]),F=l.useCallback(async()=>{if(!xe)return;const G=oe.current+1;oe.current=G,$(!0);try{const Ie=await Lc(xe);if(oe.current!==G)return;const Oe=Ie.actions;R(Oe),O(De=>De===sr||De&&Oe.some(ge=>ge.id===De)?De:null)}catch{if(oe.current!==G)return}finally{oe.current===G&&$(!1)}},[xe]),z=l.useMemo(()=>cf(e||xe?.path||""),[e,xe?.path]),Q=l.useMemo(()=>L?M.find(G=>G.id===L)??null:null,[M,L]),re=l.useMemo(()=>({id:sr,name:a("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[a]),K=!d,le=l.useMemo(()=>K?[re,...M]:M,[M,re,K]);l.useEffect(()=>{F()},[F]),l.useEffect(()=>{if(typeof window>"u")return;const G=Ie=>{const Oe=Ie.detail;ae&&(Oe?.projectId&&Oe.projectId!==ae||F())};return window.addEventListener(Wc,G),()=>{window.removeEventListener(Wc,G)}},[F,ae]),l.useEffect(()=>{L&&(L===sr&&K||M.some(G=>G.id===L)||O(null))},[M,K,L]),l.useEffect(()=>{for(const[G,Ie]of Object.entries(P)){const De=w.get(Ie.directory)?.tabs.find(ge=>ge.id===Ie.tabId);(!De||De.terminalSessionId!==Ie.sessionId)&&T(G)}},[P,T,w]),l.useEffect(()=>{for(const[G,Ie]of Object.entries(P)){const Oe=H.current[G]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};H.current[G]=Oe;const De=le.find(Ce=>Ce.id===Ie.actionId);if(!De)continue;const U=w.get(Ie.directory)?.tabs.find(Ce=>Ce.id===Ie.tabId);if(!U||!Array.isArray(U.bufferChunks)||U.bufferChunks.length===0)continue;const de=U.bufferChunks.filter(Ce=>Oe.lastSeenChunkId===null?!0:Ce.id>Oe.lastSeenChunkId);if(de.length===0)continue;const Ee=de.map(Ce=>Ce.data).join(""),_e=`${Oe.tail}${Ee}`,Z=!Oe.openedUrl&&De.autoOpenUrl===!0?h1(_e):null,ie=de[de.length-1]?.id??Oe.lastSeenChunkId;if(Oe.lastSeenChunkId=ie,Oe.tail=_e.slice(-512),Z)if(Oe.openedUrl=!0,Oe.openInPreview){const Ce=P[G];Ce&&(E(Ce.directory,Ce.tabId,Z,{locked:!1,autoOpened:!1}),Ce.status==="waiting-for-preview"&&N(G,"running"),window.clearTimeout(se.current[G]),delete se.current[G],g(Ce.directory,Z))}else te(Z),q.success(a("projectActions.toast.openedUrlFromOutput"));H.current[G]=Oe}for(const G of Object.keys(H.current))P[G]||(delete H.current[G],window.clearTimeout(se.current[G]),delete se.current[G])},[le,g,te,P,E,a,w,N]);const Se=l.useCallback(async(G,Ie={})=>{if(!z)throw new Error(a("projectActions.error.noActiveDirectory"));const Oe=Yr(z,G.id);y(z);const De=dn.getState(),ge=De.getDirectoryState(z);let U=B.current[Oe]||null;const de=U?!!ge?.tabs.some(Z=>Z.id===U):!1;(!U||!de)&&(U=De.createTab(z),B.current[Oe]=U),S(z,U,`Action: ${G.name}`),D(z,U,G.icon||"play"),Ie.revealTerminal!==!1&&(j(z,U),f(!0),b("terminal"));const _e=dn.getState().getDirectoryState(z)?.tabs.find(Z=>Z.id===U);return{key:Oe,tabId:U,sessionId:_e?.terminalSessionId??null}},[y,z,b,j,f,D,S,a]),ue=l.useCallback(async G=>{if(c.isVSCode||!i&&d)return;if(!z){q.error(a("projectActions.error.noActiveDirectoryForAction"));return}const Ie=Yr(z,G.id),Oe=P[Ie];if(!(Oe&&Oe.status==="running"))try{const De=G.id===sr?await(async()=>{const[Xe,we]=await Promise.all([Lc({id:xe?.id??"",path:z}),i1(z)]),tt=await e1(z,Xe.actions,we);if(!tt)throw new Error(a("contextPanel.preview.noDevServer"));return{id:sr,name:a("projectActions.actions.autoDiscover"),command:tt.command,icon:"search",autoOpenUrl:!0,openUrl:tt.previewUrlHint||""}})():G,ge=De.autoOpenUrl===!0&&(De.openUrl||"").trim().length>0,{key:U,tabId:de,sessionId:Ee}=await Se(De,{revealTerminal:!ge&&G.id!==sr});let _e=Ee,Z=!1;if(!_e){I(z,de,!0);try{_e=(await o.createSession({cwd:z})).sessionId,Z=!0,A(z,de,_e)}finally{I(z,de,!1)}}if(!_e)throw new Error(a("projectActions.error.failedToCreateTerminalSession"));Z&&await o1(350),De.id===sr&&(_.current[U]?.(),I(z,de,!0),_.current[U]=hx(_e,Xe=>{Xe.type==="data"&&typeof Xe.data=="string"&&Xe.data.length>0&&dn.getState().appendToBuffer(z,de,Xe.data),Xe.type==="exit"&&(dn.getState().setTabLifecycle(z,de,"exited"),dn.getState().setConnecting(z,de,!1),dn.getState().removeProjectActionRun(U),delete H.current[U],_.current[U]?.(),delete _.current[U],window.clearTimeout(se.current[U]),delete se.current[U])},()=>{dn.getState().setConnecting(z,de,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const ie=De.autoOpenUrl===!0&&p&&(De.desktopOpenSshForward||"").trim().length>0,Ce=De.autoOpenUrl?p1(De.openUrl):null,He=De.autoOpenUrl&&p?Yv(De.desktopOpenSshForward,m):null;k({key:U,directory:z,actionId:De.id,tabId:de,sessionId:_e,status:De.id===sr&&!Ce?"waiting-for-preview":"running"}),window.clearTimeout(se.current[U]),delete se.current[U],De.id===sr&&!Ce&&(se.current[U]=window.setTimeout(()=>{dn.getState().updateProjectActionRunStatus(U,"running"),delete se.current[U]},u1)),He?(E(z,de,null,{locked:!0}),te(He),q.success(a("projectActions.toast.openedForwardedUrl"))):Ce?(E(z,de,Ce,{locked:!0,autoOpened:!0}),g(z,Ce),q.success(a("projectActions.toast.openedActionUrl"))):ge?(E(z,de,null,{locked:!0}),q.error(a("projectActions.error.invalidCustomUrlFormat"))):ie?(E(z,de,null,{locked:!0}),q.error(a("projectActions.error.selectedDesktopSshForwardUnavailable"))):E(z,de,null,{locked:!1,autoOpened:!1}),H.current[U]={lastSeenChunkId:null,openedUrl:!!He||!!Ce||ge,tail:"",openInPreview:De.id===sr};const Ge=m1(De.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
-
`));await o.sendInput(_e,`${Ge}\r`)}catch(De){T(Ie),delete H.current[Ie],_.current[Ie]?.(),delete _.current[Ie],window.clearTimeout(se.current[Ie]),delete se.current[Ie],q.error(De instanceof Error?De.message:a("projectActions.error.failedToRunAction"))}},[m,Se,i,d,p,z,te,g,P,c.isVSCode,T,I,k,E,A,xe?.id,a,o]),je=l.useCallback(async G=>{const Ie=Yr(z,G.id),Oe=P[Ie];if(!Oe)return;N(Ie,"stopping");try{await o.sendInput(Oe.sessionId,"")}catch{}if(await new Promise(U=>{window.setTimeout(U,1e3)}),dn.getState().getDirectoryState(Oe.directory)?.tabs.find(U=>U.id===Oe.tabId)?.terminalSessionId===Oe.sessionId){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:Oe.sessionId})}catch{}else try{await o.close(Oe.sessionId)}catch{}A(Oe.directory,Oe.tabId,null)}T(Ie),delete H.current[Ie],_.current[Ie]?.(),delete _.current[Ie],window.clearTimeout(se.current[Ie]),delete se.current[Ie]},[z,P,T,A,o,N]),W=l.useCallback(()=>{const G=Q??le[0];if(!G)return;const Ie=Yr(z,G.id),Oe=P[Ie];if(Oe?.status!=="stopping"){if(Oe){je(G);return}ue(G)}},[le,z,ue,P,Q,je]),me=l.useCallback((G,Ie=!1)=>{if(O(G.id),!Ie){ue(G);return}const Oe=Yr(z,G.id),De=P[Oe];if(De?.status!=="stopping"){if(De){je(G);return}ue(G)}},[z,ue,P,je]),X=l.useCallback(()=>{xe?.id&&(x(xe.id),h("projects"),v(!0))},[v,h,x,xe?.id]);if(c.isVSCode||!i&&d||!xe||!z)return null;const ce=Q??le[0]??null;if(!ce)return null;const ee=ce.icon||"play",Pe=ce.id===sr?"search":_o[ee]||"play",Ne=f1(ce.name,a("projectActions.label.fallbackAction")),Y=Yr(z,ce.id),he=P[Y],ke=he?.status==="stopping",be=he?.status==="waiting-for-preview",fe=he?w.get(he.directory)?.tabs.find(G=>G.id===he.tabId)?.previewUrl??null:null,Te=!!(he&&fe),Ve=()=>{!he||!fe||g(he.directory,fe)};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:W,"aria-label":he?a("projectActions.actions.stopNamedAria",{name:ce.name}):a("projectActions.actions.runNamedAria",{name:ce.name}),children:ke||be?s.jsx(C,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):he?s.jsx(C,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(C,{name:Pe,className:"h-5 w-5"})}),Te?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":a("projectActions.actions.openPreview"),onClick:Ve,children:s.jsx(C,{name:"global",className:"h-4 w-4"})})}),s.jsx(Pt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":a("projectActions.actions.chooseActionAria"),children:s.jsx(C,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs($s,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:X,children:[s.jsx(C,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx(An,{}),le.map(G=>{const Ie=G.icon||"play",Oe=G.id===sr?"search":_o[Ie]||"play",De=Yr(z,G.id),ge=P[De],U=!!ge,de=ge?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{me(G,!0)},children:[s.jsx(C,{name:Oe,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:G.name}),de||ge?.status==="waiting-for-preview"?s.jsx(C,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):U?s.jsx(C,{name:"stop",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:W,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":he?a("projectActions.actions.stopNamedAria",{name:ce.name}):a("projectActions.actions.runNamedAria",{name:ce.name}),children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ke||be?s.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):he?s.jsx(C,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(C,{name:Pe,className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:Ne})]}),Te?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ve,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":a("projectActions.actions.openPreview"),children:s.jsx(C,{name:"global",className:"h-4 w-4"})})}),s.jsx(Pt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(Bs,{children:[s.jsx(Os,{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":a("projectActions.actions.chooseActionAria"),children:s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs($s,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:X,children:[s.jsx(C,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx(An,{}),le.map(G=>{const Ie=G.icon||"play",Oe=G.id===sr?"search":_o[Ie]||"play",De=Yr(z,G.id),ge=P[De],U=!!ge,de=ge?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{me(G)},children:[s.jsx(C,{name:Oe,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:G.name}),de||ge?.status==="waiting-for-preview"?s.jsx(C,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):U?s.jsx(C,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},G.id)})]})]})]})},Cl="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",g1="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",ji=l.memo(function(e){const n=rt.c(13),{visible:r,title:i,ariaLabel:a,onClick:o,className:c,Icon:d,iconClassName:p}=e;if(!(r===void 0?!0:r))return null;const u=c??Cl,f=p??"h-[18px] w-[18px]";let b;n[0]!==d||n[1]!==f?(b=s.jsx(C,{name:d,className:f}),n[0]=d,n[1]=f,n[2]=b):b=n[2];let h;n[3]!==a||n[4]!==o||n[5]!==u||n[6]!==b?(h=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,"aria-label":a,className:u,children:b})}),n[3]=a,n[4]=o,n[5]=u,n[6]=b,n[7]=h):h=n[7];let v;n[8]!==i?(v=s.jsx(Pt,{children:s.jsx("p",{children:i})}),n[8]=i,n[9]=v):v=n[9];let x;return n[10]!==h||n[11]!==v?(x=s.jsxs(Ct,{children:[h,v]}),n[10]=h,n[11]=v,n[12]=x):x=n[12],x}),x1=l.memo(function(e){const n=rt.c(42),{isMobile:r,githubAuthStatus:i,githubAccounts:a,githubAvatarUrl:o,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=mt();if(!i?.connected||r)return null;if(a.length>1){let h;n[0]===Symbol.for("react.memo_cache_sentinel")?(h=pe(Cl,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=h):h=n[0];let v;n[1]!==c||n[2]!==m?(v=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=v):v=n[3];let x;n[4]!==o||n[5]!==c||n[6]!==m?(x=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(C,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=o,n[5]=c,n[6]=m,n[7]=x):x=n[7];let g;n[8]!==d||n[9]!==v||n[10]!==x?(g=s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:h,title:v,disabled:d,children:x})}),n[8]=d,n[9]=v,n[10]=x,n[11]=g):g=n[11];let w;n[12]!==m?(w=m("header.github.accountsTitle"),n[12]=m,n[13]=w):w=n[13];let y;n[14]!==w?(y=s.jsx(Oi,{className:"typography-ui-header font-semibold text-foreground",children:w}),n[14]=w,n[15]=y):y=n[15];let S;n[16]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(An,{}),n[16]=S):S=n[16];let D;if(n[17]!==a||n[18]!==p||n[19]!==d||n[20]!==m){let A;n[22]!==p||n[23]!==d||n[24]!==m?(A=E=>{const P=E.user,k=!!E.current;return s.jsxs(zt,{className:"gap-2",disabled:k||d,onSelect:()=>{k||p(E.id)},children:[P?.avatarUrl?s.jsx("img",{src:P.avatarUrl,alt:P.login?m("header.github.avatarWithLogin",{login:P.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(C,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:P?.name?.trim()||P?.login||"GitHub"}),P?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:P.login}):null]}),k?s.jsx(C,{name:"check",className:"h-4 w-4 text-primary"}):null]},E.id)},n[22]=p,n[23]=d,n[24]=m,n[25]=A):A=n[25],D=a.map(A),n[17]=a,n[18]=p,n[19]=d,n[20]=m,n[21]=D}else D=n[21];let j;n[26]!==y||n[27]!==D?(j=s.jsxs($s,{align:"end",className:"w-64",children:[y,S,D]}),n[26]=y,n[27]=D,n[28]=j):j=n[28];let I;return n[29]!==g||n[30]!==j?(I=s.jsxs(Bs,{children:[g,j]}),n[29]=g,n[30]=j,n[31]=I):I=n[31],I}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let f;n[35]!==o||n[36]!==c||n[37]!==m?(f=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(C,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=o,n[36]=c,n[37]=m,n[38]=f):f=n[38];let b;return n[39]!==u||n[40]!==f?(b=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:u,children:f}),n[39]=u,n[40]=f,n[41]=b):b=n[41],b}),b1=l.memo(function(e){const n=rt.c(76),{isDesktopApp:r,currentInstanceLabel:i,compactCurrentInstanceLabel:a,isDesktopServicesOpen:o,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:f,servicesTabItems:b,quotaLastUpdated:h,quotaDisplayMode:v,quotaDisplayTabItems:x,handleDisplayModeChange:g,handleUsageRefresh:w,isQuotaLoading:y,isUsageRefreshSpinning:S,hasRateLimits:D,rateLimitGroups:j,expandedFamilies:I,toggleFamilyExpanded:A,shortcutLabel:E,showDevShutdown:P,isDevShutdownInFlight:k,onDevShutdown:N}=e,{t:T}=mt();let M;n[0]!==p||n[1]!==f||n[2]!==u||n[3]!==d||n[4]!==c?(M=re=>{c(re),re&&(d(),p==="usage"&&u===0&&f())},n[0]=p,n[1]=f,n[2]=u,n[3]=d,n[4]=c,n[5]=M):M=n[5];let R;n[6]!==i||n[7]!==r||n[8]!==T?(R=r?T("header.services.openWithCurrent",{current:i}):T("header.services.open"),n[6]=i,n[7]=r,n[8]=T,n[9]=R):R=n[9];const L=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let O;n[10]!==L?(O=pe(Cl,L),n[10]=L,n[11]=O):O=n[11];let V;n[12]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(C,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=V):V=n[12];let $;n[13]!==a||n[14]!==r?($=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:a}):null,n[13]=a,n[14]=r,n[15]=$):$=n[15];let B;n[16]!==R||n[17]!==O||n[18]!==$?(B=s.jsx(It,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":R,className:O,children:[V,$]})})}),n[16]=R,n[17]=O,n[18]=$,n[19]=B):B=n[19];let H;n[20]!==i||n[21]!==r||n[22]!==E||n[23]!==T?(H=r?T("header.services.tooltip.currentInstanceWithShortcuts",{current:i,toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}):T("header.services.tooltip.servicesWithShortcuts",{toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}),n[20]=i,n[21]=r,n[22]=E,n[23]=T,n[24]=H):H=n[24];let _;n[25]!==H?(_=s.jsx(Pt,{children:s.jsx("p",{children:H})}),n[25]=H,n[26]=_):_=n[26];let se;n[27]!==B||n[28]!==_?(se=s.jsxs(Ct,{children:[B,_]}),n[27]=B,n[28]=_,n[29]=se):se=n[29];let oe;n[30]!==f||n[31]!==u||n[32]!==m?(oe=re=>{const K=re;m(K),K==="usage"&&u===0&&f()},n[30]=f,n[31]=u,n[32]=m,n[33]=oe):oe=n[33];let ae;n[34]!==p||n[35]!==b||n[36]!==oe?(ae=s.jsx("div",{className:"sticky top-0 z-20 px-2 pt-1.5 pb-px",children:s.jsx("div",{className:"h-9",children:s.jsx(Tr,{items:b,activeId:p,onSelect:oe,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]=oe,n[37]=ae):ae=n[37];let ne;n[38]!==p||n[39]!==r||n[40]!==o||n[41]!==c?(ne=r&&p==="instance"?s.jsx(Nx,{embedded:!0,open:o&&p==="instance",onOpenChange:w1,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=o,n[41]=c,n[42]=ne):ne=n[42];let xe;n[43]!==p||n[44]!==o?(xe=p==="mcp"?s.jsx(af,{active:o&&p==="mcp"}):null,n[43]=p,n[44]=o,n[45]=xe):xe=n[45];let te;n[46]!==p||n[47]!==I||n[48]!==g||n[49]!==w||n[50]!==D||n[51]!==y||n[52]!==S||n[53]!==v||n[54]!==x||n[55]!==h||n[56]!==j||n[57]!==T||n[58]!==A?(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:T("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:uf(h)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Tr,{items:x,activeId:v,onSelect:re=>{g(re)},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:y||S,"aria-label":T("header.services.refreshRateLimitsAria"),children:s.jsx(C,{name:"refresh",className:pe("h-4 w-4",S&&"animate-spin")})})]})]}),D?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:T("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:j.map((re,K)=>{const le=I[re.providerId]??[];return s.jsxs(l.Fragment,{children:[K>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(Mn,{providerId:re.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:re.providerName})]}),re.entries.length===0&&(!re.modelFamilies||re.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:re.error??T("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[re.entries.map(Se=>{const[ue,je]=Se,W=v==="remaining"?je.remainingPercent:je.usedPercent,me=qi(je.usedPercent,je.resetAt,je.windowSeconds,ue),X=me?.dailyAllocationPercent!=null?v==="remaining"?100-zr(me.elapsedRatio):zr(me.elapsedRatio):null,ce=Gi(je.valueLabel,W);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:Dd(ue)}),je.resetAfterFormatted??je.resetAtFormatted?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:je.resetAfterFormatted??je.resetAtFormatted}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ce==="-"?"":ce})]}),s.jsx(Qi,{percent:W,tonePercent:je.usedPercent,className:"h-1.5",expectedMarkerPercent:X}),me?s.jsx(Yi,{paceInfo:me,compact:!0}):null]},`${re.providerId}-${ue}`)}),re.modelFamilies&&re.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:re.modelFamilies.map(Se=>{const ue=Se.familyId??"other",je=le.includes(ue);return s.jsxs(cr,{open:je,onOpenChange:()=>A(re.providerId,ue),children:[s.jsxs(jr,{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:Se.familyLabel}),je?s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(C,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(dr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Se.models.map(W=>{const[me,X]=W,ce=v==="remaining"?X.remainingPercent:X.usedPercent,ee=qi(X.usedPercent,X.resetAt,X.windowSeconds),Pe=ee?.dailyAllocationPercent!=null?v==="remaining"?100-zr(ee.elapsedRatio):zr(ee.elapsedRatio):null,Ne=Gi(X.valueLabel,ce);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:rl(me)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ne==="-"?"":Ne})]}),s.jsx(Qi,{percent:ce,tonePercent:X.usedPercent,className:"h-1.5",expectedMarkerPercent:Pe}),ee?s.jsx(Yi,{paceInfo:ee,compact:!0}):null]},`${re.providerId}-${me}`)})})})]},ue)})}):null]})]},re.providerId)})})]}):null,n[46]=p,n[47]=I,n[48]=g,n[49]=w,n[50]=D,n[51]=y,n[52]=S,n[53]=v,n[54]=x,n[55]=h,n[56]=j,n[57]=T,n[58]=A,n[59]=te):te=n[59];let F;n[60]!==k||n[61]!==N||n[62]!==P||n[63]!==T?(F=P?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx(zt,{disabled:k,onSelect:()=>{N()},children:T("header.services.shutdownDev")})})]}):null,n[60]=k,n[61]=N,n[62]=P,n[63]=T,n[64]=F):F=n[64];let z;n[65]!==ae||n[66]!==ne||n[67]!==xe||n[68]!==te||n[69]!==F?(z=s.jsxs($s,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[ae,ne,xe,te,F]}),n[65]=ae,n[66]=ne,n[67]=xe,n[68]=te,n[69]=F,n[70]=z):z=n[70];let Q;return n[71]!==o||n[72]!==M||n[73]!==se||n[74]!==z?(Q=s.jsxs(Bs,{open:o,onOpenChange:M,children:[se,z]}),n[71]=o,n[72]=M,n[73]=se,n[74]=z,n[75]=Q):Q=n[75],Q}),y1=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),v1=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],i=n[1].slice(0,3),a=`${r} ${i}`.trim();return n.length>2||a.length<e.length?`${a}...`:a}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},uf=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},nr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},yo=t=>!t?.isOpen||!Array.isArray(t.tabs)||t.tabs.length===0?null:(t.tabs.find(n=>n.id===t.activeTabId)??t.tabs[t.tabs.length-1])?.mode??null,Uu=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:i=null})=>{const{t:a}=mt(),o=Me(Fe=>Fe.setSessionSwitcherOpen),c=Me(Fe=>Fe.toggleSidebar),d=Me(Fe=>Fe.isSidebarOpen),p=Me(Fe=>Fe.isRightSidebarOpen),m=Me(Fe=>Fe.toggleBottomTerminal),u=Me(Fe=>Fe.toggleRightSidebar),f=Me(Fe=>Fe.openContextOverview),b=Me(Fe=>Fe.openContextPlan),h=Me(Fe=>Fe.openContextBrowser),v=Me(Fe=>Fe.closeContextPanel),x=Me(Fe=>Fe.contextPanelByDirectory),g=Me(Fe=>Fe.activeMainTab),w=Me(Fe=>Fe.setActiveMainTab),y=Me(Fe=>Fe.shortcutOverrides),S=yt(Fe=>Fe.getCurrentModel),D=_n(),[j,I]=l.useState(!1),A=Ht(Fe=>Fe.getContextUsage),E=Ht(Fe=>Fe.openNewSessionDraft),P=Ht(Fe=>!!Fe.newSessionDraft?.open),k=Ht(Fe=>Fe.currentSessionId),N=Sx(k??""),T=jh(k??null),M=$i(Fe=>Fe.activeSessions),R=Nh(),L=Es(Fe=>Fe.activeProjectId?Fe.projects.find(Mt=>Mt.id===Fe.activeProjectId)??null:null),O=l.useMemo(()=>{if(!L)return null;const Fe=L.label?.trim();if(Fe)return Fe;const Mt=L.path.split(/[\\/]/).filter(Boolean);return Mt[Mt.length-1]??null},[L]),V=Ls(Fe=>Fe.results),$=Ls(Fe=>Fe.fetchAllQuotas),B=Ls(Fe=>Fe.isLoading),H=Ls(Fe=>Fe.lastUpdated),_=Ls(Fe=>Fe.displayMode),se=Ls(Fe=>Fe.dropdownProviderIds),oe=Ls(Fe=>Fe.loadSettings),ae=Ls(Fe=>Fe.setDisplayMode),{isMobile:ne}=rn(),xe=Kn(Fe=>Fe.status),te=Kn(Fe=>Fe.setStatus),F=l.useRef(null),[z,Q]=l.useState(()=>typeof window>"u"?!1:wn()),re=l.useMemo(()=>yd(),[]),K=bl(),[le,Se]=l.useState(!1),ue=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),je=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 Mt=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Mt)return null;const is=Number.parseInt(Mt[1],10),ms=Number.parseInt(Mt[2],10);return Number.isNaN(is)?null:is===10?ms:is},[]);$e.useEffect(()=>{typeof window>"u"||Q(wn())},[]);const W=S(),me=W&&typeof W.limit=="object"&&W.limit!==null?W.limit:null,X=me&&typeof me.context=="number"?me.context:0,ce=me&&typeof me.output=="number"?me.output:0,ee=A(X,ce),[Pe,Ne]=l.useState(null),Y=!k||N;$e.useEffect(()=>{if(!k){Ne(Fe=>Fe===null?Fe:null);return}if(ee&&ee.totalTokens>0){Ne(Fe=>y1(Fe,ee)?Fe:ee);return}Y&&Ne(Fe=>Fe===null?Fe:null)},[ee,k,Y]);const he=Me(Fe=>Fe.isSessionSwitcherOpen),ke=xe?.connected?xe.user?.avatarUrl??null:null,be=xe?.connected?xe.user?.login??null:null,fe=xe?.accounts??[],[Te,Ve]=l.useState(!1),[G,Ie]=l.useState(!1),[Oe,De]=l.useState(!1),[ge,U]=l.useState(!1),[de,Ee]=l.useState("Local"),_e=l.useMemo(()=>v1(de),[de]),[Z,ie]=l.useState(z?"instance":"usage"),[Ce,He]=l.useState("usage");$e.useEffect(()=>{!z&&Z==="instance"&&ie("usage")},[Z,z]);const Ge=l.useMemo(()=>pn(),[]),Xe=l.useMemo(()=>ne?typeof t=="function"?!!n:he:d,[ne,he,d,n,t]),we=!Ge&&g==="chat"&&!!Pe&&Pe.totalTokens>0,tt=Pe&&Pe.contextLimit>0?Math.min(999,Pe.totalTokens/Pe.contextLimit*100):0,st=l.useCallback(async()=>{if(!(typeof window>"u"||!z))try{const Fe=await kx(),Mt=window.location.href,is=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(nu(Mt,is)){Ee("Local");return}const ms=Fe.hosts.find(qs=>nu(Mt,qs.url));if(ms?.label?.trim()){Ee(Cx(ms.label.trim()));return}Ee("Instance")}catch{Ee("Local")}},[z]);$e.useEffect(()=>{st()},[st]),nf();const qe=Ls(Fe=>Fe.selectedModels),it=Ls(Fe=>Fe.expandedFamilies),lt=Ls(Fe=>Fe.toggleFamilyExpanded),ye=l.useMemo(()=>{const Fe=[];for(const Mt of Lr){if(!se.includes(Mt.id))continue;const is=V.find(Xs=>Xs.providerId===Mt.id),ms=is?.usage?.windows??{},qs=is?.usage?.models,Vs=Object.entries(ms),Ds={providerId:Mt.id,providerName:Mt.name,entries:Vs,error:is&&!is.ok&&is.configured?is.error:void 0};if(qs&&Object.keys(qs).length>0){const Xs=qe[Mt.id]??[],hn=Xs.length>0,tr=fv(qs,Mt.id),Sn=tf(Mt.id),Mr=sf(Sn);Ds.modelFamilies=[];for(const Zs of Mr){const Yn=tr.get(Zs.id)??[];if(Yn.length===0)continue;const kn=hn?Yn.filter(hr=>Xs.includes(hr)):Yn;if(kn.length===0)continue;const Xn=[];for(const hr of kn){const Er=qs[hr];if(Er?.windows){const fr=Object.entries(Er.windows);fr.length>0&&Xn.push([hr,fr[0][1]])}}Xn.length>0&&Ds.modelFamilies.push({familyId:Zs.id,familyLabel:Zs.label,models:Xn})}const Sr=tr.get(null)??[],kr=hn?Sr.filter(Zs=>Xs.includes(Zs)):Sr;if(kr.length>0){const Zs=[];for(const Yn of kr){const kn=qs[Yn];if(kn?.windows){const Xn=Object.entries(kn.windows);Xn.length>0&&Zs.push([Yn,Xn[0][1]])}}Zs.length>0&&Ds.modelFamilies.push({familyId:null,familyLabel:a("header.services.modelFamily.other"),models:Zs})}}(Vs.length>0||Ds.modelFamilies&&Ds.modelFamilies.length>0||Ds.error)&&Fe.push(Ds)}return Fe},[se,V,qe,a]),Je=ye.length>0;l.useEffect(()=>{oe()},[oe]);const Be=l.useCallback(async Fe=>{ae(Fe);try{await Ps({usageDisplayMode:Fe})}catch(Mt){console.warn("Failed to update usage display mode:",Mt)}},[ae]),ze=l.useCallback(()=>{if(ge)return;U(!0);const Fe=new Promise(Mt=>setTimeout(Mt,500));Promise.all([$(),Fe]).finally(()=>{U(!1)})},[$,ge]),nt=l.useMemo(()=>k?R.find(Fe=>Fe.id===k)??M.find(Fe=>Fe.id===k)??T??Ix().find(Fe=>Fe.id===k)??null:null,[k,T,M,R]),Ye=l.useRef(null),[Ue,vt]=l.useState(0);l.useEffect(()=>{if(!k){Ye.current&&(Ye.current=null,vt(ms=>ms+1));return}if(nt){Ye.current={sessionId:k,session:nt,expiresAt:Date.now()+2e3};return}const Fe=Ye.current;if(!Fe||Fe.sessionId!==k)return;const Mt=Fe.expiresAt-Date.now();if(Mt<=0){Ye.current=null,vt(ms=>ms+1);return}const is=window.setTimeout(()=>{Ye.current?.sessionId===k&&(Ye.current=null),vt(ms=>ms+1)},Mt);return()=>{window.clearTimeout(is)}},[k,nt]);const Et=(()=>{if(nt)return nt;if(!k)return null;const Fe=Ye.current;return Fe&&Fe.sessionId===k&&Fe.expiresAt>Date.now()?Fe.session:null})(),Gt=Ht(Fe=>k?Fe.worktreeMetadata.get(k)?.path??"":""),ts=Ht(Fe=>k?Fe.worktreeMetadata.get(k)?.branch?.trim()??null:null),Nt=Sh(Fe=>k?Fe.getAttachment(k):void 0),St=l.useMemo(()=>Nt?Px(Nt):null,[Nt]),Zt=l.useMemo(()=>Nt?Nt.legacy?"legacy":Nt.degraded?"degraded":Nt.worktreeStatus==="missing"?"missing":Nt.worktreeStatus==="invalid"?"invalid":Nt.attentionReason?"attention":null:null,[Nt]),ut=l.useMemo(()=>nr(Gt||""),[Gt]),Xt=l.useMemo(()=>{const Fe=typeof Et?.directory=="string"?Et.directory:"";return nr(Fe||"")},[Et?.directory]),as=Ht(Fe=>Fe.newSessionDraft?.open?nr(Fe.newSessionDraft.bootstrapPendingDirectory??Fe.newSessionDraft.directoryOverride??""):""),Bt=l.useMemo(()=>ut||Xt||as,[as,Xt,ut]),ls=Ht(Fe=>{const Mt=nr(ut||Xt||"");if(!Mt)return null;for(const is of Fe.availableWorktreesByProject.values()){const qs=is.find(Vs=>nr(Vs.path)===Mt)?.branch?.trim();if(qs)return qs}return null}),us=Ax(Bt||null)||ts||ls,xs=l.useMemo(()=>{if(!k)return O??"OpenChamber";const Fe=Et?.title?.trim();return Fe&&Fe.length>0?Fe:"Untitled Session"},[O,Et?.title,k]),At=l.useMemo(()=>kh(Et?.summary),[Et?.summary]),We=l.useMemo(()=>At||{additions:0,deletions:0},[At]),Rt=We.additions>0||We.deletions>0,Dt=l.useMemo(()=>nr(Bt||L?.path||""),[L?.path,Bt]),wt=l.useMemo(()=>L?{id:L.id,path:L.path}:null,[L]),Jt=l.useRef(null);l.useEffect(()=>{!wt||!Dt||(Jt.current={projectRef:wt,directory:Dt})},[Dt,wt]);const _t=l.useMemo(()=>wt&&Dt?{projectRef:wt,directory:Dt}:Jt.current,[Dt,wt]),Fs=vd(Fe=>Fe.planModeEnabled),ft=Ht(Fe=>Fe.isSessionPlanAvailable),ds=Fs&&k?ft(k):!1,Qt=ds,ks=l.useRef("");l.useEffect(()=>{if(!Fs){Me.getState().activeMainTab==="plan"&&Me.getState().setActiveMainTab("chat");return}if(!k)return;const Fe=`${k||"none"}:${Xt||"none"}:${Et?.time?.created||0}:${Et?.slug||"none"}`;ks.current!==Fe&&(ks.current=Fe),!ds&&Me.getState().activeMainTab==="plan"&&Me.getState().setActiveMainTab("chat")},[Fs,ds,Et?.slug,Et?.time?.created,k,Xt]);const _s=l.useCallback(async Fe=>{if(!(!Fe||Te)){Ve(!0);try{const Mt=D.github?await D.github.authActivate(Fe):await(async()=>{const is=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Fe})}),ms=await is.json().catch(()=>null);if(!is.ok||!ms)throw new Error(ms?.error||is.statusText);return ms})();te(Mt)}catch(Mt){console.error("Failed to switch GitHub account:",Mt)}finally{Ve(!1)}}},[Te,D.github,te]),J=l.useCallback(()=>{if(typeof document>"u")return;const Fe=document.activeElement;if(!Fe)return;const Mt=Fe.tagName;(Mt==="INPUT"||Mt==="TEXTAREA"||Mt==="SELECT"||Fe.isContentEditable)&&Fe.blur()},[]),pt=l.useCallback(()=>{if(ne){J(),o(!he);return}c()},[J,ne,he,o,c]),jt=l.useCallback(()=>{w("chat"),o(!1),E()},[E,w,o]),Wt=l.useCallback(()=>{el("desktop_open_draft_mini_chat_window",{directory:nr(Bt||L?.path||""),projectId:L?.id??null}).catch(Fe=>{console.warn("[header] failed to open draft mini chat window",Fe)})},[L?.id,L?.path,Bt]),es=l.useCallback(()=>{if(P){Wt();return}k&&el("desktop_open_session_mini_chat_window",{sessionId:k,directory:nr(Bt||L?.path||"")}).catch(Fe=>{console.warn("[header] failed to open session mini chat window",Fe)})},[L?.path,k,Wt,P,Bt]),ns=l.useCallback(()=>{const Fe=nr(Bt||"");if(!Fe)return;const Mt=x[Fe];if(yo(Mt)==="context"){v(Fe);return}f(Fe)},[v,x,f,Bt]),Cs=l.useMemo(()=>{const Fe=nr(Bt||"");if(!Fe)return!1;const Mt=x[Fe];return yo(Mt)==="context"},[x,Bt]),Is=l.useCallback(()=>{const Fe=nr(Bt||"");if(!Fe)return;const Mt=x[Fe];if(yo(Mt)==="plan"){v(Fe);return}b(Fe)},[v,x,b,Bt]),Ke=l.useCallback(()=>{const Fe=nr(Bt||"");Fe&&h(Fe)},[h,Bt]),xt=l.useMemo(()=>{const Fe=nr(Bt||"");if(!Fe)return!1;const Mt=x[Fe];return yo(Mt)==="plan"},[x,Bt]),kt=Cl,Tt=g1,ss=l.useMemo(()=>!d&&(z&&ue&&!le||K)?"pl-[5.5rem]":"pl-3",[z,le,ue,d,K]);$e.useEffect(()=>{if(!z||!ue){Se(!1);return}let Fe=!1,Mt=null;const is=async()=>{try{const{getCurrentWindow:qs}=await wr(async()=>{const{getCurrentWindow:Xs}=await import("./vendor-.bun-BFTPeDgG.js").then(hn=>hn.bK);return{getCurrentWindow:Xs}},__vite__mapDeps([0,1])),Ds=await qs().isFullscreen();Fe||Se(Ds)}catch{Fe||Se(!1)}},ms=async()=>{try{const{getCurrentWindow:qs}=await wr(async()=>{const{getCurrentWindow:Ds}=await import("./vendor-.bun-BFTPeDgG.js").then(Xs=>Xs.bK);return{getCurrentWindow:Ds}},__vite__mapDeps([0,1]));Mt=await qs().onResized(()=>{is()})}catch{}};return is(),ms(),()=>{Fe=!0,Mt&&Mt()}},[z,ue]);const at=l.useMemo(()=>!z||!ue||je===null?"":je>=26?"h-12":je<=15?"h-14":"",[z,ue,je]),Lt=l.useMemo(()=>{if(!(z||Ge))return{paddingLeft:K&&!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))"}},[z,d,K,Ge]),os=l.useCallback(()=>{if(typeof document>"u")return;const Fe=F.current?.getBoundingClientRect().height;Fe&&document.documentElement.style.setProperty("--oc-header-height",`${Fe}px`)},[]);$e.useEffect(()=>{if(typeof window>"u")return;os();const Fe=F.current;if(!Fe||typeof ResizeObserver>"u")return()=>{};let Mt=0;const is=()=>{Mt||(Mt=requestAnimationFrame(()=>{Mt=0,os()}))},ms=new ResizeObserver(is);return ms.observe(Fe),window.addEventListener("resize",is),window.addEventListener("orientationchange",is),()=>{Mt&&cancelAnimationFrame(Mt),ms.disconnect(),window.removeEventListener("resize",is),window.removeEventListener("orientationchange",is)}},[os]),$e.useEffect(()=>{os()},[os,ne,at]);const rs=l.useCallback(async Fe=>{const Mt=Fe.target;Mt.closest(".app-region-no-drag")||Mt.closest("button, a, input, select, textarea")||Fe.button===0&&z&&await Ch()},[z]),Vt=l.useMemo(()=>{if(ne){const Fe=[{id:"chat",label:a("layout.mainTab.chat"),icon:"chat-4"}];return Qt&&Fe.push({id:"plan",label:a("layout.mainTab.plan"),icon:"file-text"}),Fe.push({id:"diff",label:a("layout.mainTab.diff"),icon:"diff"},{id:"files",label:a("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:a("layout.mainTab.terminal"),icon:"terminal-box"}),Fe}return[]},[ne,Qt,a]),cs=l.useCallback(Fe=>yl(Vr(Fe,y)),[y]);$e.useEffect(()=>{!ne&&(g==="git"||g==="terminal"||g==="diff"||g==="files")&&w("chat")},[g,ne,w]);const sn=l.useMemo(()=>{const Fe=[];return z&&Fe.push({value:"instance",label:a("layout.services.instance"),icon:"server"}),Fe.push({value:"usage",label:a("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:Cv}),Fe},[z,a]),Js=l.useMemo(()=>sn.map(Fe=>({id:Fe.value,label:Fe.label,icon:s.jsx(C,{name:Fe.icon,className:"h-3.5 w-3.5"})})),[sn]),Us=l.useMemo(()=>{if(typeof window>"u"||z||Ge)return!1;const Fe=window.location.hostname;return Fe==="localhost"||Fe==="127.0.0.1"||Fe==="::1"},[z,Ge]),ln=l.useCallback(async()=>{if(j)return;I(!0),De(!1);const Fe=[];let Mt=!1;try{try{for(const[,is]of dn.getState().sessions.entries())for(const ms of is.tabs)ms.previewUrl&&Fe.push(ms.previewUrl)}catch{}try{await fx({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Fe})})).ok?Mt=!0:Mt=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Mt||I(!1)}},[j,De]),nn=l.useMemo(()=>[{value:"usage",label:a("header.services.used")},{value:"remaining",label:a("header.services.remaining")}],[a]),cn=l.useMemo(()=>nn.map(Fe=>({id:Fe.value,label:Fe.label})),[nn]),un=l.useMemo(()=>[{id:"usage",label:a("layout.services.usage"),icon:s.jsx(C,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(C,{name:"command",className:"h-3.5 w-3.5"})}],[a]);$e.useEffect(()=>{const Fe=Mt=>{if(wd(Mt)&&!Mt.shiftKey&&!Mt.altKey){const is=parseInt(Mt.key,10);is>=1&&is<=Vt.length&&(Mt.preventDefault(),w(Vt[is-1].id))}};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[Vt,w]),$e.useEffect(()=>{const Fe=Mt=>{const is=Vr("toggle_services_menu",y);if(Fo(Mt,is)){Mt.preventDefault(),Oe?De(!1):(De(!0),st(),Z==="usage"&&V.length===0&&$());return}const ms=Vr("cycle_services_tab",y);if(Fo(Mt,ms)){Mt.preventDefault();const Vs=sn.map(tr=>tr.value);if(Vs.length===0)return;const Ds=Vs.indexOf(Z),Xs=Ds===-1?0:(Ds+1)%Vs.length,hn=Vs[Xs];ie(hn),De(!0),st(),hn==="usage"&&V.length===0&&$();return}const qs=Vr("toggle_context_plan",y);Fo(Mt,qs)&&(Mt.preventDefault(),Is())};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[y,Oe,Z,sn,V.length,$,st,Is]);const jn=Fe=>{const Mt=g===Fe.id,is=Fe.icon==="diff",ms=is?null:Fe.icon,qs=Fe.id==="chat",Vs=Xs=>is?s.jsx(Tu,{size:Xs}):ms?s.jsx(C,{name:ms,className:`h-${Xs/4} w-${Xs/4}`}):null,Ds=s.jsxs("button",{type:"button",onClick:()=>w(Fe.id),className:pe("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Mt?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",qs&&!ne&&"min-w-[100px] justify-center"),"aria-label":Fe.label,"aria-selected":Mt,role:"tab",children:[ne?Vs(20):s.jsxs(s.Fragment,{children:[Vs(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:Ds},Fe.id)},an=s.jsxs(s.Fragment,{children:[Qt&&s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.openPlanAria"),onClick:Is,className:pe(kt,xt&&"bg-[var(--interactive-hover)]"),children:s.jsx(C,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(Pt,{children:s.jsx("p",{children:a("header.actions.planWithShortcut",{shortcut:cs("toggle_context_plan")})})})]}),s.jsx(Mv,{directory:Dt,className:"mr-1"}),s.jsx(b1,{isDesktopApp:z,currentInstanceLabel:de,compactCurrentInstanceLabel:_e,isDesktopServicesOpen:Oe,setIsDesktopServicesOpen:De,refreshCurrentInstanceLabel:st,desktopServicesTab:Z,setDesktopServicesTab:ie,quotaResultsLength:V.length,fetchAllQuotas:$,servicesTabItems:Js,quotaLastUpdated:H,quotaDisplayMode:_,quotaDisplayTabItems:cn,handleDisplayModeChange:Be,handleUsageRefresh:ze,isQuotaLoading:B,isUsageRefreshSpinning:ge,hasRateLimits:Je,rateLimitGroups:ye,expandedFamilies:it,toggleFamilyExpanded:lt,shortcutLabel:cs,showDevShutdown:Us,isDevShutdownInFlight:j,onDevShutdown:ln}),s.jsx(ji,{title:a("header.actions.terminalPanelWithShortcut",{shortcut:cs("toggle_terminal")}),ariaLabel:a("header.actions.toggleTerminalPanelAria"),onClick:m,Icon:"terminal-box"}),re?s.jsx(ji,{title:a("contextPanel.browser.open"),ariaLabel:a("contextPanel.browser.open"),onClick:Ke,Icon:"global"}):null,s.jsx(ji,{title:a("header.actions.rightSidebarWithShortcut",{shortcut:cs("toggle_right_sidebar")}),ariaLabel:a("header.actions.toggleRightSidebarAria"),onClick:u,Icon:"layout-right"}),s.jsx(x1,{isMobile:ne,githubAuthStatus:xe,githubAccounts:fe,githubAvatarUrl:ke,githubLogin:be,isSwitchingGitHubAccount:Te,handleGitHubAccountSwitch:_s})]}),gn=!p||!i,pr=re&&(P||!!k),Fn=()=>s.jsxs("div",{onMouseDown:rs,className:pe("app-region-drag relative flex h-12 select-none items-center pr-3",ss,at),style:Lt,role:"tablist","aria-label":a("header.navigation.mainAria"),children:[s.jsx(ji,{visible:!d,title:a("header.actions.openSessionsWithShortcut",{shortcut:cs("toggle_sidebar")}),ariaLabel:a("header.actions.openSessionsAria"),onClick:pt,className:`${kt} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:pe("flex min-w-0 flex-1 items-center",!d&&"pl-3"),children:[Xe?null:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.newSessionAria"),onClick:jt,className:pe(kt,"mr-6 shrink-0"),children:s.jsx(C,{name:"chat-new",className:"h-[18px] w-[18px]"})})}),s.jsx(Pt,{children:s.jsx("p",{children:a("header.actions.newSessionWithShortcut",{shortcut:cs("new_chat")})})})]}),_t&&s.jsx(zu,{projectRef:_t.projectRef,directory:_t.directory,className:"mr-2"}),P?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:xs}),O||us||Rt?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:[O?s.jsx("span",{className:"truncate",children:O}):null,us?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(C,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:us})]}):null,Rt?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:["+",We.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",We.deletions]})]}):null,Zt?s.jsxs("span",{className:pe("inline-flex min-w-0 items-center gap-0.5",Zt==="attention"||Zt==="invalid"||Zt==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(C,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:St})]}):null]}):null]}),Vt.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Vt.map(Fe=>jn(Fe))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[we&&Pe?s.jsx(Dx,{totalTokens:Pe.totalTokens,percentage:tt,colorPercentage:Pe.percentage,contextLimit:Pe.contextLimit,outputLimit:Pe.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:ns,pressed:Cs,className:gn&&!pr?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(ji,{visible:pr,title:a(P?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:a(P?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:es,className:pe(kt,gn&&we?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),gn?an:null,!gn&&i?Li.createPortal(an,i):null]})]})]}),Dn=()=>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(Tt,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":a(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(C,{name:"layout-left",className:"h-5 w-5"})}):he?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":a("header.actions.backAria"),children:s.jsx(C,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:pt,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":a("header.actions.openSessionsAria"),children:s.jsx(C,{name:"play-list-add",className:"h-5 w-5"})}),he&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:a("header.sessions.title")})]}),!he&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":a("header.navigation.mainAria"),children:Vt.map(Fe=>{const Mt=g===Fe.id,is=Fe.icon==="diff",ms=is?null:Fe.icon;return s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{ne&&J(),w(Fe.id)},"aria-label":Fe.label,"aria-selected":Mt,role:"tab",className:pe(Tt,"relative rounded-lg",Mt&&"bg-interactive-selection text-interactive-selection-foreground"),children:[is?s.jsx(Tu,{className:"h-5 w-5"}):ms?s.jsx(C,{name:ms,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":a("header.changes.availableAria")})]})}),s.jsx(Pt,{children:s.jsx("p",{children:Fe.label})})]},Fe.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[_t&&s.jsx(zu,{projectRef:_t.projectRef,directory:_t.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(Bs,{open:G,onOpenChange:Fe=>{Ie(Fe),Fe&&V.length===0&&$()},children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.services.viewAria"),className:Tt,children:s.jsx(C,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Pt,{children:s.jsx("p",{children:a("header.services.title")})})]}),s.jsx($s,{align:"end",sideOffset:0,className:"h-dvh w-[100vw] max-h-none rounded-none border-0 p-0 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(Tr,{items:un,activeId:Ce,onSelect:Fe=>{const Mt=Fe;He(Mt),Mt==="usage"&&V.length===0&&$()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>Ie(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":a("header.services.closeAria"),children:s.jsx(C,{name:"close",className:"h-5 w-5"})})]})}),Ce==="mcp"&&s.jsx(af,{active:G&&Ce==="mcp"}),Ce==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:a("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:uf(H)})]}),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:()=>Be("usage"),className:pe("typography-ui-label px-1 pb-0.5 transition-colors",_==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>Be("remaining"),className:pe("typography-ui-label px-1 pb-0.5 transition-colors",_==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.remaining")})]}),s.jsx("button",{type:"button",className: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:ze,disabled:B||ge,"aria-label":a("header.services.refreshRateLimitsAria"),children:s.jsx(C,{name:"refresh",className:pe("h-4 w-4",ge&&"animate-spin")})})]})]})}),!Je&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:a("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:ye.map((Fe,Mt)=>s.jsxs(l.Fragment,{children:[Mt>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(Mn,{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??a("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Fe.entries.map(([is,ms])=>{const qs=_==="remaining"?ms.remainingPercent:ms.usedPercent,Vs=qi(ms.usedPercent,ms.resetAt,ms.windowSeconds,is),Ds=Vs?.dailyAllocationPercent!=null?_==="remaining"?100-zr(Vs.elapsedRatio):zr(Vs.elapsedRatio):null,Xs=Gi(ms.valueLabel,qs);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:Dd(is)}),ms.resetAfterFormatted??ms.resetAtFormatted?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:ms.resetAfterFormatted??ms.resetAtFormatted}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Xs==="-"?"":Xs})]}),s.jsx(Qi,{percent:qs,tonePercent:ms.usedPercent,className:"h-1.5",expectedMarkerPercent:Ds}),Vs?s.jsx(Yi,{paceInfo:Vs,compact:!0}):null]},`${Fe.providerId}-${is}`)}),Fe.modelFamilies&&Fe.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Fe.modelFamilies.map(is=>{const qs=(it[Fe.providerId]??[]).includes(is.familyId??"other");return s.jsxs(cr,{open:qs,onOpenChange:()=>lt(Fe.providerId,is.familyId??"other"),children:[s.jsxs(jr,{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:is.familyLabel}),qs?s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(C,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(dr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:is.models.map(([Vs,Ds])=>{const Xs=_==="remaining"?Ds.remainingPercent:Ds.usedPercent,hn=qi(Ds.usedPercent,Ds.resetAt,Ds.windowSeconds),tr=hn?.dailyAllocationPercent!=null?_==="remaining"?100-zr(hn.elapsedRatio):zr(hn.elapsedRatio):null,Sn=Gi(Ds.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.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:rl(Vs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Sn==="-"?"":Sn})]}),s.jsx(Qi,{percent:Xs,tonePercent:Ds.usedPercent,className:"h-1.5",expectedMarkerPercent:tr}),hn?s.jsx(Yi,{paceInfo:hn,compact:!0}):null]},`${Fe.providerId}-${Vs}`)})})})]},is.familyId??"other")})})]})]},Fe.providerId))})]})]})})]}),e?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:pe(Tt,"relative",r&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(C,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Pt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Tn=pe("header-safe-area relative z-10",ne&&"border-b border-border/50","bg-background");return s.jsx("header",{ref:F,className:Tn,style:{"--padding-scale":"1"},children:ne?Dn():Fn()})};function w1(){}const Wu=180,Ku=640,j1=110,N1=t=>{const e=rt.c(44),{isOpen:n,isMobile:r,children:i}=t,{t:a}=mt(),o=Me(S1),c=Me(k1),d=Me(C1),p=Me(I1),[m,u]=l.useState(null),[f,b]=l.useState(!1),h=l.useRef(null),v=l.useRef(0),x=l.useRef(o||300),g=Math.min(Ku,Math.max(Wu,o||300));let w,y;e[0]!==n?(w=()=>{n||(u(null),b(!1))},y=[n],e[0]=n,e[1]=w,e[2]=y):(w=e[1],y=e[2]),l.useEffect(w,y);let S,D;e[3]!==c||e[4]!==r||e[5]!==n?(S=()=>{if(r||!n||!c)return;const oe=()=>{const xe=h.current?.parentElement?.getBoundingClientRect().height;if(!xe||xe<=0)return;const te=Math.max(0,Math.round(xe));u(F=>F===te?F:te)};oe();const ae=h.current?.parentElement;if(!ae)return;const ne=new ResizeObserver(oe);return ne.observe(ae),()=>{ne.disconnect()}},D=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=S,e[7]=D):(S=e[6],D=e[7]),l.useEffect(S,D);let j,I;if(e[8]!==c||e[9]!==r||e[10]!==f||e[11]!==d||e[12]!==p?(j=()=>{if(r||!f||c)return;const oe=ne=>{const xe=v.current-ne.clientY,te=Math.min(Ku,Math.max(Wu,x.current+xe));d(te)},ae=()=>{b(!1),Me.getState().bottomTerminalHeight<=j1&&p(!1)};return window.addEventListener("pointermove",oe),window.addEventListener("pointerup",ae,{once:!0}),()=>{window.removeEventListener("pointermove",oe),window.removeEventListener("pointerup",ae)}},I=[c,r,f,d,p],e[8]=c,e[9]=r,e[10]=f,e[11]=d,e[12]=p,e[13]=j,e[14]=I):(j=e[13],I=e[14]),l.useEffect(j,I),r)return null;const A=n?c?Math.max(0,m??g):g:0,E=n&&c;let P;e[15]!==A||e[16]!==c||e[17]!==n?(P=oe=>{!n||c||(b(!0),v.current=oe.clientY,x.current=A,oe.preventDefault())},e[15]=A,e[16]=c,e[17]=n,e[18]=P):P=e[18];const k=P,N=E?"absolute inset-x-0 bottom-0 z-40":"relative",T=f?"transition-none":"transition-[height] duration-300 ease-in-out",M=!n&&"border-t-0";let R;e[19]!==M||e[20]!==N||e[21]!==T?(R=pe("flex overflow-hidden border-t border-border bg-sidebar",N,T,M),e[19]=M,e[20]=N,e[21]=T,e[22]=R):R=e[22];let L;e[23]!==A||e[24]!==E?(L=E?{top:"var(--oc-header-height, 48px)"}:{height:`${A}px`,minHeight:`${A}px`,maxHeight:`${A}px`},e[23]=A,e[24]=E,e[25]=L):L=e[25];const O=!n||!c&&A===0;let V;e[26]!==k||e[27]!==c||e[28]!==n||e[29]!==f||e[30]!==a?(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",f&&"bg-[var(--interactive-border)]"),onPointerDown:k,role:"separator","aria-orientation":"horizontal","aria-label":a("terminalView.bottomDock.resizeAria")}),e[26]=k,e[27]=c,e[28]=n,e[29]=f,e[30]=a,e[31]=V):V=e[31];const $=!n&&"pointer-events-none select-none opacity-0";let B;e[32]!==$?(B=pe("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",$),e[32]=$,e[33]=B):B=e[33];const H=!n;let _;e[34]!==i||e[35]!==B||e[36]!==H?(_=s.jsx("div",{className:B,"aria-hidden":H,children:i}),e[34]=i,e[35]=B,e[36]=H,e[37]=_):_=e[37];let se;return e[38]!==R||e[39]!==L||e[40]!==O||e[41]!==V||e[42]!==_?(se=s.jsxs("section",{ref:h,className:R,style:L,"aria-hidden":O,children:[V,_]}),e[38]=R,e[39]=L,e[40]=O,e[41]=V,e[42]=_,e[43]=se):se=e[43],se};function S1(t){return t.bottomTerminalHeight}function k1(t){return t.isBottomTerminalExpanded}function C1(t){return t.setBottomTerminalHeight}function I1(t){return t.setBottomTerminalOpen}const Kc=280,Hu=280,Gu=500,P1=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:i}=mt(),a=Me(S=>S.sidebarWidth),o=Me(S=>S.setSidebarWidth),[c,d]=l.useState(!1),p=l.useRef(0),m=l.useRef(a||Kc),u=l.useRef(null),f=l.useRef(null),b=l.useRef(null),h=l.useCallback(S=>Math.min(Gu,Math.max(Hu,S)),[]),v=l.useCallback(S=>{const D=b.current;D&&D.style.setProperty("--oc-left-sidebar-width",`${S}px`)},[]);if(l.useEffect(()=>{e&&c&&d(!1)},[e,c]),l.useEffect(()=>{c||(u.current=null,f.current=null)},[c]),e)return null;const x=t?Math.min(Gu,Math.max(Hu,a||Kc)):0,g=S=>{if(t){try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}f.current=S.pointerId,d(!0),p.current=S.clientX,m.current=x,u.current=x,v(x),S.preventDefault()}},w=S=>{if(e||!c||f.current!==S.pointerId)return;const D=S.clientX-p.current,j=h(m.current+D);u.current!==j&&(u.current=j,v(j))},y=S=>{if(f.current!==S.pointerId||e)return;try{S.currentTarget.releasePointerCapture(S.pointerId)}catch{}const D=h(u.current??x);f.current=null,u.current=null,d(!1),o(D)};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:y,onPointerCancel:y,role:"separator","aria-orientation":"vertical","aria-label":i("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(Ys,{children:n})})})]})},mf=420,qu=400,Ju=860,A1=({isOpen:t,children:e,className:n,onTopActionsHostChange:r})=>{const{t:i}=mt(),a=Me(E=>E.rightSidebarWidth),o=Me(E=>E.setRightSidebarWidth),c=l.useMemo(()=>wn(),[]),d=l.useMemo(()=>pn(),[]),p=bl(),[m,u]=l.useState(!1),f=l.useRef(0),b=l.useRef(a||420),h=l.useRef(null),v=l.useRef(null),x=l.useRef(null),g=l.useCallback(E=>Math.min(Ju,Math.max(qu,E)),[]),w=l.useCallback(E=>{const P=x.current;P&&P.style.setProperty("--oc-right-sidebar-width",`${E}px`)},[]),y=t?Math.min(Ju,Math.max(qu,a||mf)):0,S=E=>{if(t){try{E.currentTarget.setPointerCapture(E.pointerId)}catch{}v.current=E.pointerId,u(!0),f.current=E.clientX,b.current=y,h.current=y,w(y),E.preventDefault()}},D=E=>{if(!m||v.current!==E.pointerId)return;const P=f.current-E.clientX,k=g(b.current+P);h.current!==k&&(h.current=k,w(k))},j=E=>{if(v.current!==E.pointerId)return;try{E.currentTarget.releasePointerCapture(E.pointerId)}catch{}const P=g(h.current??y);v.current=null,h.current=null,u(!1),o(P)};l.useEffect(()=>{m||(h.current=null,v.current=null)},[m]),l.useEffect(()=>{t||r?.(null)},[t,r]);const I=l.useCallback(async E=>{const P=E.target;P.closest(".app-region-no-drag")||P.closest("button, a, input, select, textarea")||E.button===0&&c&&await Ch()},[c]),A=l.useMemo(()=>{if(!(c||d))return{paddingLeft:"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",...p?{paddingTop:"var(--oc-safe-area-top, 0px)"}:null}},[c,p,d]);return s.jsxs("aside",{ref:x,className: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?h.current??y:y}px`,overflowX:"clip"},"aria-hidden":!t||y===0,children:[t?s.jsx("div",{onMouseDown:I,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:A,"aria-hidden":!0,children:s.jsx("div",{ref:r,className:"app-region-no-drag flex items-center gap-1"})}):null,t&&s.jsx("div",{className: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:D,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":i("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})]})},D1=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),T1=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=D1.format(t);return e.endsWith(".0")?e.slice(0,-2):e},ao=({providerId:t,modelId:e,onChange:n,className:r,allowedProviderIds:i,placeholder:a})=>{const{t:o}=mt(),{isReady:c,isUnavailable:d}=Ih(),p=yt(F=>F.providers),m=yt(F=>F.modelsMetadata),u=Me(F=>F.isMobile),f=Me(F=>F.hiddenModels),b=Me(F=>F.toggleFavoriteModel),h=Me(F=>F.isFavoriteModel),v=Me(F=>F.addRecentModel),{favoriteModelsList:x,recentModelsList:g}=Ph(),{isMobile:w}=rn(),y=u||w,[S,D]=l.useState(!1),[j,I]=l.useState(new Set),[A,E]=l.useState(!1),[P,k]=l.useState(""),[N,T]=l.useState(0),M=l.useRef([]),R=l.useMemo(()=>!Array.isArray(i)||i.length===0?null:new Set(i),[i]),L=l.useMemo(()=>(R?p.filter(z=>R.has(String(z.id))):p).map(z=>{const re=(Array.isArray(z.models)?z.models:[]).filter(K=>{const le=typeof K?.id=="string"?K.id:"";return!f.some(Se=>Se.providerID===String(z.id)&&Se.modelID===le)});return{...z,models:re}}).filter(z=>z.models.length>0),[p,R,f]),O=()=>D(!1),V=F=>{I(z=>{const Q=new Set(z);return Q.has(F)?Q.delete(F):Q.add(F),Q})};l.useEffect(()=>{A||(k(""),T(0))},[A]),l.useEffect(()=>{T(0)},[P]);const $=F=>{const z=F?.name||F?.id||"",Q=String(z);return Q.length>40?Q.substring(0,37)+"...":Q},B=(F,z)=>{const Q=`${F}/${z}`;return m.get(Q)},H=(F,z)=>{n(F,z),F&&z&&v(F,z),E(!1)},_=(F,z)=>{if(!P.trim())return!0;const Q=P.toLowerCase();return F.toLowerCase().includes(Q)||z.toLowerCase().includes(Q)},se=(F,z,Q,re,K,le)=>{const Se=B(z,Q),ue=T1(Se?.limit?.context),je=t===z&&e===Q,W=h(z,Q),me=re==="fav"||re==="recent";return s.jsxs(zt,{ref:X=>{M.current[K]=X},className:pe("group flex items-center gap-2",le&&"bg-interactive-selection"),onSelect:()=>H(z,Q),onMouseEnter:()=>T(K),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[me&&s.jsx(Mn,{providerId:z,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(F)}),ue?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:ue}):null]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[je&&s.jsx(C,{name:"check",className:"h-4 w-4 text-primary"}),s.jsx("button",{onClick:X=>{X.preventDefault(),X.stopPropagation(),b(z,Q)},className:pe("model-favorite-button flex h-4 w-4 items-center justify-center hover:text-primary/80",W?"text-primary":"text-muted-foreground"),"aria-label":o(W?"settings.agents.modelSelector.actions.unfavorite":"settings.agents.modelSelector.actions.favorite"),title:o(W?"settings.agents.modelSelector.actions.removeFromFavorites":"settings.agents.modelSelector.actions.addToFavorites"),children:W?s.jsx(C,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"star",className:"h-3.5 w-3.5"})})]})]},`${re}-${z}-${Q}`)},oe=x.filter(({model:F,providerID:z})=>{if(R&&!R.has(z))return!1;const re=p.find(le=>le.id===z)?.name||z,K=$(F);return _(K,re)}),ae=g.filter(({model:F,providerID:z})=>{if(R&&!R.has(z))return!1;const re=p.find(le=>le.id===z)?.name||z,K=$(F);return _(K,re)}),ne=L.map(F=>{const Q=(Array.isArray(F.models)?F.models:[]).filter(re=>{const K=$(re);return _(K,F.name||F.id||"")});return{...F,models:Q}}).filter(F=>F.models.length>0),xe=oe.length>0||ae.length>0||ne.length>0,te=()=>y?s.jsx(Dr,{open:S,onClose:O,title:o("settings.agents.modelSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[x.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.favorites")}),s.jsx("div",{className:"border-t border-border/20",children:x.map(({model:F,providerID:z,modelID:Q})=>{const re=z===t&&Q===e;return s.jsxs("div",{className:pe("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",re?"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:()=>{H(z,Q),O()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Mn,{providerId:z,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(F)})]})}),s.jsx("button",{onClick:K=>{K.preventDefault(),K.stopPropagation(),b(z,Q)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-primary hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.unfavorite"),children:s.jsx(C,{name:"star-fill",className:"h-4 w-4"})})]},`fav-mobile-${z}-${Q}`)})})]}),g.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.recents")}),s.jsx("div",{className:"border-t border-border/20",children:g.map(({model:F,providerID:z,modelID:Q})=>{const re=z===t&&Q===e;return s.jsxs("div",{className:pe("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",re?"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:()=>{H(z,Q),O()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Mn,{providerId:z,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(F)})]})}),s.jsx("button",{onClick:K=>{K.preventDefault(),K.stopPropagation(),b(z,Q)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-muted-foreground/50 hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.favorite"),children:s.jsx(C,{name:"star",className:"h-4 w-4"})})]},`recent-mobile-${z}-${Q}`)})})]}),L.map(F=>{const z=Array.isArray(F.models)?F.models:[];if(z.length===0)return null;const Q=F.id===t,re=j.has(F.id);return s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)]",children:[s.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-1.5 px-2 py-1.5 text-left",onClick:()=>V(F.id),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Mn,{providerId:F.id,className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:F.name}),Q&&s.jsx("span",{className:"typography-micro text-primary/80",children:o("settings.agents.modelSelector.badge.current")})]}),re?s.jsx(C,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"}):s.jsx(C,{name:"arrow-right-s",className:"h-3 w-3 text-muted-foreground"})]}),re&&s.jsx("div",{className:"border-t border-border/20",children:z.map(K=>{const le=F.id===t&&K.id===e;return s.jsxs("div",{className:pe("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",le?"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:()=>{H(F.id,K.id),O()},children:s.jsx("span",{className:"font-medium truncate",children:$(K)})}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx("button",{onClick:Se=>{Se.preventDefault(),Se.stopPropagation(),b(F.id,K.id)},className:pe("flex h-8 w-8 items-center justify-center active:scale-95 touch-manipulation hover:text-primary/80",h(F.id,K.id)?"text-primary":"text-muted-foreground/50"),"aria-label":h(F.id,K.id)?o("settings.agents.modelSelector.actions.unfavorite"):o("settings.agents.modelSelector.actions.favorite"),children:h(F.id,K.id)?s.jsx(C,{name:"star-fill",className:"h-4 w-4"}):s.jsx(C,{name:"star",className:"h-4 w-4"})}),le&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]})]},K.id)})})]},F.id)}),s.jsx("button",{type:"button",className:"flex w-full items-center justify-between rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",onClick:()=>{H("",""),O()},children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:a||o("settings.agents.modelSelector.noModelOptional")})})]})}):null;return s.jsxs(s.Fragment,{children:[y?s.jsxs("button",{type:"button",onClick:c?()=>D(!0):void 0,disabled:!c,className: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(Mn,{providerId:t,className:"h-3.5 w-3.5"}):s.jsx(C,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),c&&s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t&&e?`${t}/${e}`:a||o("settings.agents.modelSelector.selectPlaceholder")})]}),s.jsx(C,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):s.jsxs(Bs,{open:c&&A,onOpenChange:c?E:void 0,children:[s.jsx(Os,{asChild:!0,children:s.jsxs("div",{className: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(Mn,{providerId:t,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx(C,{name:"pencil-ai",className:"h-3 w-3 text-primary/60 hidden"})]}):s.jsx(C,{name:"pencil-ai",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-foreground",children:t&&e?`${t}/${e}`:a||o("settings.agents.modelSelector.notSelected")})]}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsx($s,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:(()=>{const F=[];oe.forEach(({model:K,providerID:le,modelID:Se})=>{F.push({model:K,providerID:le,modelID:Se,section:"fav"})}),ae.forEach(({model:K,providerID:le,modelID:Se})=>{F.push({model:K,providerID:le,modelID:Se,section:"recent"})}),ne.forEach(K=>{K.models.forEach(le=>{F.push({model:le,providerID:K.id,modelID:le.id,section:"provider"})})});const z=F.length,Q=K=>{if(K.stopPropagation(),K.key==="ArrowDown"){K.preventDefault();const le=(N+1)%Math.max(1,z);T(le),setTimeout(()=>{M.current[le]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(K.key==="ArrowUp"){K.preventDefault();const le=(N-1+Math.max(1,z))%Math.max(1,z);T(le),setTimeout(()=>{M.current[le]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(K.key==="Enter"){K.preventDefault();const le=F[N];le&&H(le.providerID,le.modelID)}else K.key==="Escape"&&(K.preventDefault(),E(!1))};let re=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(C,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Ut,{type:"text",placeholder:o("settings.agents.modelSelector.searchPlaceholder"),value:P,onChange:K=>k(K.target.value),onKeyDown:Q,className:"pl-8 h-8 typography-meta",autoFocus:!0})]})}),s.jsx(As,{outerClassName:"max-h-[min(400px,calc(100dvh-12rem))] flex-1",children:s.jsxs("div",{className:"p-1",children:[s.jsxs(zt,{className:pe("flex items-center gap-2"),onSelect:()=>H("",""),children:[s.jsx(C,{name:"close",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-muted-foreground",children:a||o("settings.agents.modelSelector.notSelected")}),!t&&!e&&s.jsx(C,{name:"check",className:"h-4 w-4 text-primary ml-auto"})]}),s.jsx(An,{}),!xe&&P&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("settings.agents.modelSelector.state.noModelsFound")}),oe.length>0&&s.jsxs("div",{children:[s.jsxs(Oi,{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(C,{name:"star-fill",className:"h-4 w-4 text-primary"}),o("settings.agents.modelSelector.section.favorites")]}),oe.map(({model:K,providerID:le,modelID:Se})=>{const ue=re++;return se(K,le,Se,"fav",ue,N===ue)})]}),ae.length>0&&s.jsxs("div",{children:[oe.length>0&&s.jsx(An,{}),s.jsxs(Oi,{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(C,{name:"time",className:"h-4 w-4"}),o("settings.agents.modelSelector.section.recent")]}),ae.map(({model:K,providerID:le,modelID:Se})=>{const ue=re++;return se(K,le,Se,"recent",ue,N===ue)})]}),(oe.length>0||ae.length>0)&&ne.length>0&&s.jsx(An,{}),ne.map((K,le)=>s.jsxs("div",{children:[le>0&&s.jsx(An,{}),s.jsxs(Oi,{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(Mn,{providerId:K.id,className:"h-4 w-4 flex-shrink-0"}),K.name]}),K.models.map(Se=>{const ue=re++;return se(Se,K.id,Se.id,"provider",ue,N===ue)})]},K.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()]})},Il=t=>{const e=rt.c(34),{agentName:n,onChange:r,className:i,filter:a}=t,{t:o}=mt(),{isReady:c,isUnavailable:d}=Ih(),p=yt(M1),m=li(E1),u=li(R1),f=yt(F1);let b;e:{if(Array.isArray(p)&&p.length>0){b=p;break e}let O;e[0]!==m?(O=Array.isArray(m)?m:[],e[0]=m,e[1]=O):O=e[1],b=O}const h=b;let v;if(e[2]!==a||e[3]!==h){const O=Tx(h);v=a?O.filter(a):O,e[2]=a,e[3]=h,e[4]=v}else v=e[4];const x=v,g=Me(L1),{isMobile:w}=rn(),y=g||w,[S,D]=l.useState(!1);let j,I;e[5]!==u||e[6]!==f||e[7]!==h.length?(j=()=>{h.length>0||(f(),u())},I=[h.length,f,u],e[5]=u,e[6]=f,e[7]=h.length,e[8]=j,e[9]=I):(j=e[8],I=e[9]),l.useEffect(j,I);let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=()=>D(!1),e[10]=A):A=e[10];const E=A;let P;e[11]!==r?(P=O=>{r(O)},e[11]=r,e[12]=P):P=e[12];const k=P;let N;e[13]!==n||e[14]!==x||e[15]!==k||e[16]!==y||e[17]!==S||e[18]!==o?(N=()=>y?s.jsx(Dr,{open:S,onClose:E,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:()=>{k(""),E()},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(O=>{const V=O.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:()=>{k(O.name),E()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:O.name}),O.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:O.description})]}),V&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},O.name)})]})}):null,e[13]=n,e[14]=x,e[15]=k,e[16]=y,e[17]=S,e[18]=o,e[19]=N):N=e[19];const T=N;let M;e[20]!==n||e[21]!==x||e[22]!==i||e[23]!==k||e[24]!==y||e[25]!==c||e[26]!==d||e[27]!==o?(M=y?s.jsxs("button",{type:"button",onClick:c?()=>D(!0):void 0,disabled:!c,className: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",i),children:[s.jsx("div",{className:"flex items-center gap-2",children:c?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"robot-2",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:n||o("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]})}),s.jsx(C,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsxs("div",{className: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",i),children:[s.jsx(C,{name:"robot-2",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap",children:n||o("settings.commands.agentSelector.notSelected")}),s.jsx(C,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs($s,{className:"max-w-[300px]",children:[s.jsx(zt,{className:"typography-meta",onSelect:()=>k(""),children:s.jsx("span",{className:"text-muted-foreground",children:o("settings.commands.agentSelector.notSelected")})}),x.map(O=>s.jsx(zt,{className:"typography-meta",onSelect:()=>k(O.name),children:s.jsx("span",{className:"font-medium",children:O.name})},O.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",i),children:[s.jsx(C,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=x,e[22]=i,e[23]=k,e[24]=y,e[25]=c,e[26]=d,e[27]=o,e[28]=M):M=e[28];let R;e[29]!==T?(R=T(),e[29]=T,e[30]=R):R=e[30];let L;return e[31]!==M||e[32]!==R?(L=s.jsxs(s.Fragment,{children:[M,R]}),e[31]=M,e[32]=R,e[33]=L):L=e[33],L};function M1(t){return t.agents}function E1(t){return t.agents}function R1(t){return t.loadAgents}function F1(t){return t.loadAgents}function L1(t){return t.isMobile}const Qu=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),O1=t=>{const e=rt.c(38),{value:n,options:r,disabled:i,onChange:a}=t,{t:o}=mt();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=i?"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 f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(C,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=f):f=e[7];let b;e[8]!==m||e[9]!==u?(b=s.jsxs("div",{className:m,children:[u,f]}),e[8]=m,e[9]=u,e[10]=b):b=e[10];const h=b;if(i)return h;let v;e[11]!==h?(v=s.jsx(Os,{asChild:!0,children:h}),e[11]=h,e[12]=v):v=e[12];let x;e[13]!==a?(x=()=>a(""),e[13]=a,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 y;e[17]!==o?(y=o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=o,e[18]=y):y=e[18];let S;e[19]!==w||e[20]!==y?(S=s.jsx("span",{className:w,children:y}),e[19]=w,e[20]=y,e[21]=S):S=e[21];let D;e[22]!==S||e[23]!==x?(D=s.jsx(zt,{className:"typography-meta",onSelect:x,children:S}),e[22]=S,e[23]=x,e[24]=D):D=e[24];let j;if(e[25]!==a||e[26]!==r||e[27]!==n){let E;e[29]!==a||e[30]!==n?(E=P=>s.jsx(zt,{className:"typography-meta",onSelect:()=>a(P),children:s.jsx("span",{className:pe("font-medium capitalize",n===P&&"text-primary"),children:P})},P),e[29]=a,e[30]=n,e[31]=E):E=e[31],j=r.map(E),e[25]=a,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let I;e[32]!==D||e[33]!==j?(I=s.jsxs($s,{align:"start",className:"max-w-[220px]",children:[D,j]}),e[32]=D,e[33]=j,e[34]=I):I=e[34];let A;return e[35]!==I||e[36]!==v?(A=s.jsxs(Bs,{children:[v,I]}),e[35]=I,e[36]=v,e[37]=A):A=e[37],A};function pf(t){const e=rt.c(99),{t:n}=mt(),{open:r,onOpenChange:i,target:a,projectDirectory:o,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=yt(G1),u=yt(H1),f=li(K1),b=yt(W1),h=yt(U1),v=yt(z1),x=yt(V1),g=yt(_1);let w;e[0]!==g||e[1]!==v||e[2]!==h||e[3]!==x?(w=()=>Qu({providerID:h,modelID:v,variant:x,agent:g}),e[0]=g,e[1]=v,e[2]=h,e[3]=x,e[4]=w):w=e[4];const[y,S]=l.useState(w);let D,j;e[5]!==f||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==o?(D=()=>{r&&(m({directory:o}),u({directory:o}),f())},j=[r,m,u,f,o],e[5]=f,e[6]=u,e[7]=m,e[8]=r,e[9]=o,e[10]=D,e[11]=j):(D=e[10],j=e[11]),l.useEffect(D,j);let I,A;e[12]!==g||e[13]!==v||e[14]!==h||e[15]!==x||e[16]!==r?(I=()=>{r&&S(Qu({providerID:h,modelID:v,variant:x,agent:g}))},A=[r,h,v,x,g],e[12]=g,e[13]=v,e[14]=h,e[15]=x,e[16]=r,e[17]=I,e[18]=A):(I=e[17],A=e[18]),l.useEffect(I,A);let E,P;e[19]!==y.modelID||e[20]!==y.providerID||e[21]!==r||e[22]!==b?(E=()=>{if(!r||b.length===0)return;const he=b.find(Te=>Te.id===y.providerID)??b[0],ke=Array.isArray(he?.models)?he.models:[],be=ke.some(Te=>Te.id===y.modelID),fe=ke[0]?.id??"";he?.id===y.providerID&&be||S(Te=>({...Te,providerID:he?.id??"",modelID:be?Te.modelID:fe,variant:""}))},P=[r,b,y.providerID,y.modelID],e[19]=y.modelID,e[20]=y.providerID,e[21]=r,e[22]=b,e[23]=E,e[24]=P):(E=e[23],P=e[24]),l.useEffect(E,P);const k=B1;let N;if(e[25]!==y.modelID||e[26]!==y.providerID||e[27]!==b){let he;e[29]!==y.providerID?(he=be=>be.id===y.providerID,e[29]=y.providerID,e[30]=he):he=e[30],N=b.find(he)?.models?.find(be=>be.id===y.modelID),e[25]=y.modelID,e[26]=y.providerID,e[27]=b,e[28]=N}else N=e[28];const T=N;let M;e[31]!==T?(M=T?.variants?Object.keys(T.variants):[],e[31]=T,e[32]=M):M=e[32];const R=M,L=R.length>0;let O,V;e[33]!==y.variant||e[34]!==L?(O=()=>{L||!y.variant||S($1)},V=[L,y.variant],e[33]=y.variant,e[34]=L,e[35]=O,e[36]=V):(O=e[35],V=e[36]),l.useEffect(O,V);let $;e[37]!==y.modelID||e[38]!==y.providerID?($=y.providerID.trim().length>0&&y.modelID.trim().length>0,e[37]=y.modelID,e[38]=y.providerID,e[39]=$):$=e[39];const B=$;let H;e[40]!==B||e[41]!==y||e[42]!==d||e[43]!==p?(H=()=>{!B||p||d(y)},e[40]=B,e[41]=y,e[42]=d,e[43]=p,e[44]=H):H=e[44];const _=H;let se,oe;e[45]!==_||e[46]!==r?(se=()=>{if(!r)return;const he=ke=>{(ke.metaKey||ke.ctrlKey)&&ke.key==="Enter"&&(ke.preventDefault(),_())};return window.addEventListener("keydown",he),()=>window.removeEventListener("keydown",he)},oe=[r,_],e[45]=_,e[46]=r,e[47]=se,e[48]=oe):(se=e[47],oe=e[48]),l.useEffect(se,oe);let ae;e[49]!==n||e[50]!==a?(ae=n(a==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=a,e[51]=ae):ae=e[51];const ne=ae;let xe;e[52]!==i||e[53]!==p?(xe=he=>{p||i(he)},e[52]=i,e[53]=p,e[54]=xe):xe=e[54];let te;e[55]!==ne?(te=s.jsx(Ss,{children:s.jsx(js,{children:ne})}),e[55]=ne,e[56]=te):te=e[56];let F;e[57]===Symbol.for("react.memo_cache_sentinel")?(F=(he,ke)=>{S(be=>({...be,providerID:he,modelID:ke,variant:""}))},e[57]=F):F=e[57];let z;e[58]!==y.modelID||e[59]!==y.providerID?(z=s.jsx(ao,{providerId:y.providerID,modelId:y.modelID,onChange:F}),e[58]=y.modelID,e[59]=y.providerID,e[60]=z):z=e[60];const Q=!L;let re;e[61]===Symbol.for("react.memo_cache_sentinel")?(re=he=>S(ke=>({...ke,variant:he})),e[61]=re):re=e[61];let K;e[62]!==y.variant||e[63]!==Q||e[64]!==R?(K=s.jsx(O1,{value:y.variant,options:R,disabled:Q,onChange:re}),e[62]=y.variant,e[63]=Q,e[64]=R,e[65]=K):K=e[65];let le;e[66]===Symbol.for("react.memo_cache_sentinel")?(le=he=>S(ke=>({...ke,agent:he})),e[66]=le):le=e[66];let Se;e[67]!==y.agent?(Se=s.jsx(Il,{agentName:y.agent,filter:k,onChange:le}),e[67]=y.agent,e[68]=Se):Se=e[68];let ue;e[69]!==z||e[70]!==K||e[71]!==Se?(ue=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[z,K,Se]}),e[69]=z,e[70]=K,e[71]=Se,e[72]=ue):ue=e[72];let je;e[73]!==i?(je=()=>i(!1),e[73]=i,e[74]=je):je=e[74];let W;e[75]!==n?(W=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=W):W=e[76];let me;e[77]!==p||e[78]!==je||e[79]!==W?(me=s.jsx(ve,{variant:"ghost",size:"sm",onClick:je,disabled:p,children:W}),e[77]=p,e[78]=je,e[79]=W,e[80]=me):me=e[80];const X=!B||p;let ce;e[81]!==p||e[82]!==n?(ce=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=ce):ce=e[83];let ee;e[84]!==_||e[85]!==X||e[86]!==ce?(ee=s.jsx(ve,{size:"sm",onClick:_,disabled:X,children:ce}),e[84]=_,e[85]=X,e[86]=ce,e[87]=ee):ee=e[87];let Pe;e[88]!==me||e[89]!==ee?(Pe=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[me,ee]}),e[88]=me,e[89]=ee,e[90]=Pe):Pe=e[90];let Ne;e[91]!==te||e[92]!==ue||e[93]!==Pe?(Ne=s.jsxs(vs,{className:"max-w-lg",children:[te,ue,Pe]}),e[91]=te,e[92]=ue,e[93]=Pe,e[94]=Ne):Ne=e[94];let Y;return e[95]!==r||e[96]!==xe||e[97]!==Ne?(Y=s.jsx(ws,{open:r,onOpenChange:xe,children:Ne}),e[95]=r,e[96]=xe,e[97]=Ne,e[98]=Y):Y=e[98],Y}function $1(t){return{...t,variant:""}}function B1(t){return Ah(t.mode)}function _1(t){return t.currentAgentName||""}function V1(t){return t.currentVariant||""}function z1(t){return t.currentModelId}function U1(t){return t.currentProviderId}function W1(t){return t.providers}function K1(t){return t.loadAgents}function H1(t){return t.loadAgents}function G1(t){return t.loadProviders}const q1=async(t,e)=>{const n=await Lx(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},J1=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Q1=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:i})=>{const{t:a}=mt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),[m,u]=l.useState([]),[f,b]=l.useState(""),[h,v]=l.useState(null),[x,g]=l.useState(()=>new Set),[w,y]=l.useState([]),[S,D]=l.useState(null),[j,I]=l.useState(!1),[A,E]=l.useState(0),P=l.useRef(!1),k=l.useRef(""),N=Ht(Y=>Y.currentSessionId),T=Ht(Y=>Y.createSession),M=Ht(Y=>Y.initializeNewOpenChamberSession),R=Ht(Y=>Y.sendMessage),L=Ht(Y=>Y.setCurrentSession),O=Ca(Y=>Y.setPendingInputText),V=Ws(Y=>Y.currentDirectory),$=Me(Y=>Y.openContextPanelTab),B=Me(Y=>Y.setActiveMainTab),H=Me(Y=>Y.setSessionSwitcherOpen),_=l.useCallback(async(Y,he)=>{if(!t)return!1;const ke=await Mx(t,{notes:Y,todos:he});return ke||q.error(a("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),ke},[t,a]);l.useEffect(()=>{if(!t){p(""),u([]),y([]),b(""),g(new Set);return}let Y=!1;return c(!0),(async()=>{try{const he=await Ex(t),ke=await Promise.all(he.plans.map(be=>q1(be,a("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(Y)return;p(he.notes),u(he.todos),y(ke),k.current=he.notes,P.current=!0,b(""),g(new Set)}catch{Y||(q.error(a("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),y([]),k.current="",P.current=!0)}finally{Y||c(!1)}})(),()=>{Y=!0}},[A,t,a]),l.useEffect(()=>{if(!t)return;const Y=he=>{const ke=he.detail;ke?.projectId&&ke.projectId!==t.id||E(be=>be+1)};return window.addEventListener("openchamber:project-plan-saved",Y),window.addEventListener("openchamber:project-notes-updated",Y),()=>{window.removeEventListener("openchamber:project-plan-saved",Y),window.removeEventListener("openchamber:project-notes-updated",Y)}},[t]);const se=l.useCallback(()=>{k.current=d,_(d,m)},[d,_,m]);l.useEffect(()=>{if(!t||!P.current||d===k.current)return;const Y=window.setTimeout(()=>{k.current=d,_(d,m)},400);return()=>{window.clearTimeout(Y)}},[d,_,t,m]);const oe=l.useCallback(()=>{const Y=f.trim();if(!Y)return;const he=[...m,{id:J1(),text:Y.slice(0,ho),completed:!1,createdAt:Date.now()}];u(he),b(""),_(d,he)},[f,d,_,m]),ae=l.useCallback(Y=>{g(he=>{const ke=new Set(he);return ke.has(Y)?ke.delete(Y):ke.add(Y),ke})},[]),ne=l.useCallback((Y,he)=>{const ke=m.map(be=>be.id===Y?{...be,completed:he}:be);u(ke),_(d,ke)},[d,_,m]),xe=l.useCallback(Y=>{const he=m.filter(ke=>ke.id!==Y);u(he),_(d,he)},[d,_,m]),te=l.useCallback(()=>{const Y=m.filter(he=>!he.completed);Y.length!==m.length&&(u(Y),_(d,Y))},[d,_,m]),F=f.slice(0,ho),z=m.reduce((Y,he)=>Y+(he.completed?1:0),0),Q=l.useCallback(()=>{B("chat"),H(!1)},[B,H]),re=l.useCallback((Y,he)=>{!t||h||D({kind:"session",todoId:Y,todoText:he})},[t,h]),K=l.useCallback(Y=>{if(!N){q.error(a("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Q();const he=`\`\`\`md
|
|
4
|
-
${Y}
|
|
5
|
-
\`\`\``;O(he,"append"),q.success(a("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[N,r,Q,O,a]),le=l.useCallback((Y,he)=>{if(!(!t||h)){if(!n){q.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}D({kind:"worktree",todoId:Y,todoText:he})}},[n,t,h,a]),Se=l.useCallback(async Y=>{if(!t||!S)return;const he=await En("plan.todo.visible",{todo_text:S.todoText}),be=[{synthetic:!0,text:await En("plan.todo.instructions",{todo_text:S.todoText})}];I(!0),v(S.todoId);try{Q();let fe=null,Te=t.path;if(S.kind==="worktree"){if(!n){q.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const G=await Dh(t.path,Th());if(!G?.id)return;fe=G.id,Te=null}else{const G=await T(void 0,t.path,null);if(!G?.id){q.error(a("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}fe=G.id,Te=G.directory??t.path,M(G.id,yt.getState().agents??[])}if(!fe)return;const Ve=vl.getState();Ve.saveSessionModelSelection(fe,Y.providerID,Y.modelID),Y.agent.trim()&&(Ve.saveSessionAgentSelection(fe,Y.agent),Ve.saveAgentModelForSession(fe,Y.agent,Y.providerID,Y.modelID),Ve.saveAgentModelVariantForSession(fe,Y.agent,Y.providerID,Y.modelID,Y.variant||void 0)),L(fe,Te),await R(he,Y.providerID,Y.modelID,Y.agent.trim()||void 0,void 0,void 0,be,Y.variant||void 0),q.success(S.kind==="worktree"?a("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):a("rightSidebar.contextNotesTodo.toast.sentToNewSession")),D(null),r?.()}catch(fe){const Te=fe instanceof Error?fe.message:void 0;q.error(a("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Te?{description:Te}:void 0)}finally{I(!1),v(null)}},[n,T,M,r,S,t,Q,R,L,a]),ue=l.useRef(null),[je,W]=l.useState(!1),[me,X]=l.useState(null),ce=l.useCallback(async Y=>{if(!(!t||me)){X(Y);try{if(!await Rx(t,Y)){q.error(a("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}y(ke=>ke.filter(be=>be.id!==Y)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{X(null)}}},[me,t,a]),ee=l.useCallback(()=>{!t||je||ue.current?.click()},[je,t]),Pe=l.useCallback(async Y=>{if(!(!t||!Y)){W(!0);try{const he=await Y.text();if(!he.trim()){q.error(a("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const ke=Y.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await Fx(t,he,ke)){q.error(a("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),q.success(a("rightSidebar.contextNotesTodo.toast.planImported"))}catch(he){const ke=he instanceof Error?he.message:void 0;q.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),ke?{description:ke}:void 0)}finally{W(!1)}}},[t,a]),Ne=l.useCallback(Y=>{const he=t?.path?.trim(),ke=V?.trim()||he;ke&&$(ke,{mode:"plan",targetPath:Y.path,dedupeKey:Y.path,label:Y.title})},[V,$,t]);return t?s.jsxs("div",{className:pe("w-full min-w-0 space-y-3 p-3",i),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:a("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,"/",ru]})]}),s.jsx(vn,{value:d,onChange:Y=>p(Y.target.value.slice(0,ru)),onBlur:se,placeholder:a("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:a("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?a("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):a("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:a("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[F.length,"/",ho]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ut,{value:F,onChange:Y=>b(Y.target.value.slice(0,ho)),onKeyDown:Y=>{Y.key==="Enter"&&(Y.preventDefault(),oe())},placeholder:a("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:o,className:"h-8"}),s.jsx("button",{type:"button",onClick:oe,disabled:o||F.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":a("rightSidebar.contextNotesTodo.todo.addAria"),title:a("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(C,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(Y=>{const he=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=>ne(Y.id,ke),ariaLabel:a("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:Y.text})})}),s.jsx("button",{type:"button",onClick:()=>ae(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",he?"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:he?void 0:Y.text,"aria-label":he?a("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:Y.text}):a("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:()=>xe(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":a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:Y.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:Y.text}),children:s.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",disabled:h===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":a("rightSidebar.contextNotesTodo.todo.actions.send",{text:Y.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.send",{text:Y.text}),children:s.jsx(C,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs($s,{align:"end",className:"w-56",children:[s.jsx(zt,{onClick:()=>K(Y.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(zt,{onClick:()=>re(Y.id,Y.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(zt,{onClick:()=>{le(Y.id,Y.text)},disabled:!n,children:a("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:a("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:w.length===1?a("rightSidebar.contextNotesTodo.plans.filesSingle",{count:w.length}):a("rightSidebar.contextNotesTodo.plans.filesPlural",{count:w.length})})]}),s.jsx("input",{ref:ue,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:Y=>{const he=Y.target.files?.[0]??null;Pe(he),Y.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:ee,disabled:!t||je,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":a("rightSidebar.contextNotesTodo.plans.importFromFile"),title:a("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(C,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:w.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:w.map(Y=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>Ne(Y),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:Y.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(Y.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{ce(Y.id)},disabled:me===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:a("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":a("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:Y.title}),children:s.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},Y.id))})})]}),s.jsx(pf,{open:S!==null,onOpenChange:Y=>{!Y&&!j&&D(null)},target:S?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:Se})]}):s.jsx("div",{className:pe("w-full min-w-0 p-3",i),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.empty.selectProject")})})},hf=12,Y1=[{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"}],X1=t=>{const e=rt.c(18),{isActive:n,burstKey:r,className:i,durationMs:a,bursts:o,onComplete:c}=t,d=r===void 0?0:r,p=a===void 0?900:a,m=o===void 0?Y1:o,u=$e.useRef(!1);let f,b;e[0]!==n||e[1]!==c?(f=()=>{!n&&u.current&&c?.(),n&&(u.current=!0)},b=[n,c],e[0]=n,e[1]=c,e[2]=f,e[3]=b):(f=e[2],b=e[3]),$e.useEffect(f,b);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=Array.from({length:hf},Z1),e[4]=h):h=e[4];const v=h;if(!n)return null;let x;e[5]!==i?(x=pe("fireworks-overlay pointer-events-none",i),e[5]=i,e[6]=x):x=e[6];let g;if(e[7]!==d||e[8]!==m||e[9]!==p){let y;e[11]!==d||e[12]!==p?(y=S=>{const D={"--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:D,children:v.map((j,I)=>{const A=j.x*S.radius,E=j.y*S.radius,P={"--translate-x":`${A}px`,"--translate-y":`${E}px`,"--particle-delay":`${j.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${S.id}-${I}-${d}`)})},`${S.id}-${d}`)},e[11]=d,e[12]=p,e[13]=y):y=e[13],g=m.map(y),e[7]=d,e[8]=m,e[9]=p,e[10]=g}else g=e[10];let w;return e[14]!==d||e[15]!==x||e[16]!==g?(w=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":d,children:g}),e[14]=d,e[15]=x,e[16]=g,e[17]=w):w=e[17],w};function Z1(t,e){const n=Math.PI*2*e/hf;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const ew=t=>{const e=rt.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,i=r===void 0?3400:r;let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={isActive:!1,cycle:0},e[2]=a):a=e[2];const[o,c]=$e.useState(a),d=$e.useRef(null);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=p):p=e[3];const m=p;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),c(tw)},e[4]=u):u=e[4];const f=u;let b;e[5]!==i?(b=()=>{m(),c(sw),d.current=window.setTimeout(()=>{c(nw),d.current=null},i)},e[5]=i,e[6]=b):b=e[6];const h=b;let v,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>m(),x=[m],e[7]=v,e[8]=x):(v=e[7],x=e[8]),$e.useEffect(v,x);let g;return e[9]!==o.cycle||e[10]!==o.isActive||e[11]!==h?(g={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:h,dismissFireworks:f},e[9]=o.cycle,e[10]=o.isActive,e[11]=h,e[12]=g):g=e[12],g};function tw(t){return t.isActive?{...t,isActive:!1}:t}function sw(t){return{isActive:!0,cycle:t.cycle+1}}function nw(t){return t.isActive?{...t,isActive:!1}:t}const ff=l.createContext(void 0),rw=t=>{const e=rt.c(10),{children:n}=t,{isActive:r,burstKey:i,triggerFireworks:a,dismissFireworks:o}=ew();let c;e[0]!==o||e[1]!==a?(c={triggerFireworks:a,dismissFireworks:o},e[0]=o,e[1]=a,e[2]=c):c=e[2];const d=c;let p;e[3]!==i||e[4]!==r?(p=s.jsx(X1,{isActive:r,burstKey:i}),e[3]=i,e[4]=r,e[5]=p):p=e[5];let m;return e[6]!==n||e[7]!==p||e[8]!==d?(m=s.jsxs(ff.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},aw=()=>{const t=l.useContext(ff);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Gn=ur()(xi(Xi((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 zx();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 Vx();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 _x();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 i=r.trim();return i.length>0?i:null};try{let r=null;if(r===null){const i=lr()?.settings;if(i)try{const o=(await i.load())?.settings||{};r=n(o.defaultGitIdentityId)}catch{}}if(r===null)try{const i=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(i.ok){const a=await i.json().catch(()=>null);r=n(a?.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():"",i=r.length>0?r:"";return await Ps({defaultGitIdentityId:i}),t({defaultGitIdentityId:i.length>0?i: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 Bx(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const i=e().profiles.find(o=>o.id===n);if(!i)throw new Error("Profile not found");const a={...i,...r};return await $x(n,a),await e().loadProfiles(),!0}catch(i){return console.error("Failed to update git identity profile:",i),!1}},deleteProfile:async n=>{try{return await Ox(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:i}=e();return n==="global"?i||void 0:r.find(a=>a.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=e();return r.filter(i=>!n.some(a=>a.authType==="token"&&a.host===i.host))}}),{name:"git-identities-store",storage:xl(()=>Zr()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Gn);function Aa(t){const e=rt.c(12);let n,r,i;e[0]!==t?({className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i):(n=e[1],r=e[2],i=e[3]);let a;e[4]!==i?(a={color:"var(--surface-elevated-foreground)",...i},e[4]=i,e[5]=a):a=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]!==a||e[10]!==o?(c=s.jsx(Ea,{"data-slot":"command",style:a,className:o,...r}),e[8]=r,e[9]=a,e[10]=o,e[11]=c):c=e[11],c}const ra=$e.forwardRef((t,e)=>{const n=rt.c(10);let r,i;n[0]!==t?({className:r,...i}=t,n[0]=t,n[1]=r,n[2]=i):(r=n[1],i=n[2]);let a;n[3]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(C,{name:"search",className:"size-4 shrink-0 opacity-50"}),n[3]=a):a=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]!==i||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:[a,s.jsx(Ea.Input,{ref:e,"data-slot":"command-input",className:o,...i})]}),n[6]=i,n[7]=e,n[8]=o,n[9]=c):c=n[9],c});ra.displayName="CommandInput";function Da(t){const e=rt.c(14);let n,r,i,a,o;e[0]!==t?({className:r,children:n,scrollbarClassName:o,disableHorizontal:i,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a,e[5]=o):(n=e[1],r=e[2],i=e[3],a=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=i??!0;let m;return e[8]!==n||e[9]!==a||e[10]!==c||e[11]!==d||e[12]!==p?(m=s.jsx(As,{as:Ea.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,...a,children:n}),e[8]=n,e[9]=a,e[10]=c,e[11]=d,e[12]=p,e[13]=m):m=e[13],m}function Ta(t){const e=rt.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(Ea.Empty,{"data-slot":"command-empty",className:"py-6 text-center typography-ui-label",...n}),e[2]=n,e[3]=r):r=e[3],r}function Bn(t){const e=rt.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 i;e[3]!==n?(i=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]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Ea.Group,{"data-slot":"command-group",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function ya(t){const e=rt.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 i;e[3]!==n?(i=pe("bg-border -mx-1 h-px",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Ea.Separator,{"data-slot":"command-separator",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function Pn(t){const e=rt.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 i;e[3]!==n?(i=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]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Ea.Item,{"data-slot":"command-item",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function iw(t){const e=rt.c(12);let n,r,i,a;if(e[0]!==t){const{className:c,...d}=t,p=lw,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(ow).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],i=d,a=u.length>0?u.map((f,b)=>s.jsxs($e.Fragment,{children:[b>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),p(f)]},`${f}-${b}`)):d.children,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a}else n=e[1],r=e[2],i=e[3],a=e[4];let o;return e[7]!==n||e[8]!==r||e[9]!==i||e[10]!==a?(o=s.jsx("span",{"data-slot":n,className:r,...i,children:a}),e[7]=n,e[8]=r,e[9]=i,e[10]=a,e[11]=o):o=e[11],o}function ow(t){return t.trim()}function lw(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(C,{name:"command",className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(C,{name:"arrow-up",className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const Hc=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},cw=t=>{const e=Hc(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function dw(t,e,n){const r=rt.c(5),[i,a]=l.useState();let o,c;return r[0]!==n||r[1]!==t||r[2]!==e?(o=()=>{if(e){a(void 0);return}if(!t){a(void 0);return}a(void 0);let d=!1;return(async()=>{const[p,m]=await Promise.all([Ks("git rev-parse --absolute-git-dir",t),Ks("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=Hc((p.stdout||"").trim()),f=cw(u);if(!f)return;const b=Hc((m.stdout||"").trim());if(!b||b===f)return;const h=n||"",v=b.split("/").filter(Boolean).pop()||b;a({source:"sdk",path:b,projectDirectory:f,branch:h,label:h||v,name:v,worktreeRoot:b,worktreeStatus:"ready",headState:h?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},c=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=o,r[4]=c):(o=r[3],c=r[4]),l.useEffect(o,c),e??i}const qn=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},hi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),Wr=t=>!!t.success,Pl=t=>(t.stdout||"").trim(),ja=t=>(t.stderr||"").trim();async function uw(t){const n=((await Ks("git worktree list --porcelain",t)).stdout||"").split(/\r?\n/),r=[];let i=null;for(const a of n){if(a.startsWith("worktree ")){i&&r.push(i),i={path:a.slice(9).trim(),branchRef:null};continue}i&&a.startsWith("branch ")&&(i.branchRef=a.slice(7).trim())}return i&&r.push(i),r.filter(a=>!!a.path)}async function mw(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),i=(await uw(t.repoRoot)).filter(o=>o.branchRef===e).map(o=>o.path).filter(o=>o&&!n.has(o)),a=[];for(const o of i){const c=await Ks("git status --porcelain",o);Pl(c)||a.push(o)}return a}async function gf(t,e){for(const n of e)await Ks("git reset --hard",n).catch(()=>{})}async function pw(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Ks(`git show-ref --verify --quiet ${qn(`refs/heads/${n}`)}`,t);if(Wr(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 Ks(`git branch --track ${qn(d)} ${qn(`${c}/${d}`)}`,t),d}const i=await Ks(`git show-ref --verify --quiet ${qn(`refs/remotes/origin/${n}`)}`,t);return Wr(i)&&await Ks(`git branch --track ${qn(n)} ${qn(`origin/${n}`)}`,t),n}async function Ni(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 i=await pw(e,r),a=await Ks(`git cherry ${qn(i)} ${qn(n)}`,e),o=hi(a.stdout),c=new Set;for(const u of o){const f=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);f&&c.add(f[1])}const d=await Ks(`git rev-list --reverse ${qn(`${i}..${n}`)}`,e),m=hi(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:i,commits:m}}async function hw(t,e){const n=await Ks('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!Wr(n))throw new Error(ja(n)||"Failed to create temp directory parent");const r=await Ks('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),i=Pl(r);if(!i)throw new Error(ja(r)||"Failed to create temp directory");const a=await Ks(`git worktree add --force ${qn(i)} ${qn(e)}`,t);if(!Wr(a))throw new Error(ja(a)||"Failed to create temp worktree");return i}async function ol(t,e){await Ks(`git worktree remove --force ${qn(e)}`,t).catch(()=>{}),await Ks("git worktree prune",t).catch(()=>{})}async function fw(t){const e=await Ks("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Pl(e);if(!n)return;await Ks("git fetch",t);const r=await Ks(`git merge --ff-only ${qn(n)}`,t);if(!Wr(r))throw new Error(ja(r)||"Fast-forward failed")}async function ll(t){const e=await Ks("git status --porcelain",t),n=await Ks("git diff --name-only --diff-filter=U",t),r=await Ks("git diff",t),i=await Ks("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),a=await Ks("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:hi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:i.stdout||i.stderr||"",currentPatch:a.stdout||a.stderr||""}}async function gw(t){return ll(t)}async function xw(t){const e=await Ks("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return Wr(e)}async function bw(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await hw(t.repoRoot,t.targetBranch);let n=[];try{await fw(e);const r=await Ks("git status --porcelain",e);if(Pl(r))throw new Error("Target branch has local changes; abort integration and retry");const i=await mw({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const a=n[0],o=await Ks(`git cherry-pick ${qn(a)}`,e);if(Wr(o)){n.shift();continue}const c=await Ks("git diff --name-only --diff-filter=U",e);if(hi(c.stdout).length>0){const p=await ll(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:i,remainingCommits:n,currentCommit:a},details:p}}throw new Error(ja(o)||"Cherry-pick failed")}return await ol(t.repoRoot,e),await gf(t.repoRoot,i).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await ol(t.repoRoot,e).catch(()=>{}),r}}async function yw(t){await Ks("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await ol(t.repoRoot,t.tempWorktreePath)}async function vw(t){const e=await Ks("git cherry-pick --continue",t.tempWorktreePath);if(!Wr(e)){const a=await Ks("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(hi(a.stdout).length>0){const c=await ll(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 i=[...r];for(;i.length>0;){const a=i[0],o=await Ks(`git cherry-pick ${qn(a)}`,n);if(Wr(o)){i.shift();continue}const c=await Ks("git diff --name-only --diff-filter=U",n);if(hi(c.stdout).length>0){const p=await ll(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:i,currentCommit:a},details:p}}throw new Error(ja(o)||"Cherry-pick failed")}return await ol(t.repoRoot,t.tempWorktreePath),await gf(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const ww=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:i,refreshKey:a,onRefresh:o})=>{const{t:c}=mt(),d=Ht($=>$.currentSessionId),p=Me($=>$.setActiveMainTab),[m,u]=$e.useState(!1),f=$e.useRef(null),[b,h]=$e.useState(i);$e.useEffect(()=>{h(i)},[i]),$e.useEffect(()=>{if(m){const $=setTimeout(()=>{f.current?.focus()},0);return()=>clearTimeout($)}},[m]);const v=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[x,g]=$e.useState({kind:"idle"}),[w,y]=$e.useState(!1),[S,D]=$e.useState([]),j=$e.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);$e.useEffect(()=>{if(!j||typeof window>"u")return;const $=window.localStorage.getItem(j);if(!$)return;let B=!1;try{const H=JSON.parse($);if(!H?.tempWorktreePath||H.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const _=await xw(H.tempWorktreePath).catch(()=>!1);if(B)return;if(!_){window.localStorage.removeItem(j);return}const se=await gw(H.tempWorktreePath).catch(()=>null);B||se&&g({kind:"conflict",state:H,details:se})})()}catch{window.localStorage.removeItem(j)}return()=>{B=!0}},[j,t]),$e.useEffect(()=>{if(!v){g({kind:"idle"});return}let $=!1;return g({kind:"loading"}),(async()=>{try{const B=await Ni({repoRoot:t,sourceBranch:e,targetBranch:b});if($)return;if(g({kind:"ready",plan:B}),B.commits.length>0){const se=B.commits.slice(-50).reverse().map(xe=>JSON.stringify(xe)).join(" "),ae=((await Ks(`git show -s --format=%H%x09%h%x09%s ${se}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),ne=[];for(const xe of ae){const[te,F,z]=xe.split(" ");!te||!F||ne.push({sha:te,short:F,subject:z||""})}$||(D(ne),y(!1))}else $||(D([]),y(!1))}catch{$||g({kind:"idle"})}})(),()=>{$=!0}},[v,t,e,b,a]);const I=$e.useCallback($=>{d&&Ht.getState().setWorktreeMetadata(d,{...n,createdFromBranch:$})},[d,n]),A=Ht($=>$.openNewSessionDraft),E=$e.useCallback(async $=>{const B=await En("git.integrate.cherrypick.resolve.visible",{current_commit:$.state.currentCommit,target_branch:$.state.targetBranch}),H=await En("git.integrate.cherrypick.resolve.instructions",{repo_root:$.state.repoRoot,temp_worktree_path:$.state.tempWorktreePath,source_branch:$.state.sourceBranch,target_branch:$.state.targetBranch,current_commit:$.state.currentCommit}),_=`Cherry-pick conflict context (JSON)
|
|
6
|
-
${JSON.stringify({repoRoot:$.state.repoRoot,tempWorktreePath:$.state.tempWorktreePath,sourceBranch:$.state.sourceBranch,targetBranch:$.state.targetBranch,currentCommit:$.state.currentCommit,remainingCommits:$.state.remainingCommits,statusPorcelain:$.details.statusPorcelain,unmergedFiles:$.details.unmergedFiles,currentPatchMeta:$.details.currentPatchMeta,currentPatch:$.details.currentPatch,diff:$.details.diff},null,2)}`;return{visibleText:B,instructionsText:H,payloadText:_}},[]),P=Ca($=>$.setPendingInputText),k=Ca($=>$.setPendingSyntheticParts),N=$e.useCallback(async($,B)=>{const H=await E($);if(B){A({directoryOverride:$.state.tempWorktreePath,initialPrompt:H.visibleText,syntheticParts:[{text:H.instructionsText,synthetic:!0},{text:H.payloadText,synthetic:!0}]}),p("chat");return}if(!d){q.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}P(H.visibleText,"replace"),k([{text:H.instructionsText,synthetic:!0},{text:H.payloadText,synthetic:!0}]),p("chat")},[d,p,E,A,P,k,c]),T=$e.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 $=await bw(x.plan);if($.kind==="success"){q.success(c("gitView.integrate.commitsMovedToast"),{description:$.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:$.moved,branch:x.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:$.moved,branch:x.plan.targetBranch})});const B=await Ni(x.plan);g({kind:"ready",plan:B}),o?.();return}$.kind==="conflict"&&(q.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),g({kind:"conflict",state:$.state,details:$.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify($.state)))}catch($){const B=$ instanceof Error?$.message:String($);q.error(c("gitView.integrate.failedToMoveToast"),{description:B});const H=await Ni({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(H?{kind:"ready",plan:H}:{kind:"idle"})}}},[x,o,t,e,b,j,c]),M=$e.useCallback(async()=>{if(x.kind==="conflict")try{await yw(x.state),q.message(c("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const $=await Ni({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g($?{kind:"ready",plan:$}:{kind:"idle"})}},[x,t,e,b,j,c]),R=$e.useCallback(async()=>{if(x.kind==="conflict")try{const $=await vw(x.state);if($.kind==="success"){q.success(c("gitView.integrate.cherryPickFinishedToast"));const B=await Ni({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(B?{kind:"ready",plan:B}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),o?.();return}$.kind==="conflict"&&(g({kind:"conflict",state:$.state,details:$.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify($.state)))}catch($){const B=$ instanceof Error?$.message:String($);q.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:B})}},[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(C,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.integrate.title")}),x.kind==="ready"&&x.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:c("gitView.integrate.toMoveCount",{count:x.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:x.kind==="loading"||x.kind==="running"?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",b]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(Bs,{open:m,onOpenChange:u,children:[s.jsx(Os,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"gap-1.5",children:[c("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:b}),s.jsx(C,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx($s,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(Aa,{className:"h-full min-h-0",children:[s.jsx(ra,{ref:f,placeholder:c("gitView.branch.searchPlaceholder")}),s.jsxs(Da,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Ta,{children:c("gitView.branch.empty")}),s.jsx(Bn,{heading:c("gitView.branch.localBranches"),children:r.map($=>s.jsx(Pn,{value:$,onSelect:()=>{h($),I($),u(!1)},children:$},$))})]})]})})]}),x.kind==="ready"?s.jsx(ve,{size:"sm",onClick:()=>{T()},disabled:!v||x.plan.commits.length===0,children:c("gitView.integrate.move")}):x.kind==="loading"?s.jsx(ve,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):x.kind==="running"?s.jsx(ve,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.moving")}):null]}),x.kind==="ready"&&x.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.noCommitsToMove")}),x.kind==="ready"&&x.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[c("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",x.plan.commits.length,")"]})]}),S.length>0&&x.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>y($=>!$),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($=>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:$.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:$.subject||$.sha})]},$.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($=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:$},$)),x.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:c("gitView.integrate.moreFiles",{count:x.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ve,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{M()},children:c("gitView.operation.abort")}),s.jsxs(ve,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{N({state:x.state,details:x.details},!1)},children:[s.jsx(C,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(ve,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{N({state:x.state,details:x.details},!0)},children:[s.jsx(C,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(ve,{size:"sm",className:"typography-meta",onClick:()=>{R()},children:c("gitView.operation.continue")})]})]})]})]})},jw=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Nw=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:i,onCreate:a,remotes:o=[],disabled:c=!1})=>{const{t:d}=mt(),[p,m]=l.useState(!1),[u,f]=l.useState(""),[b,h]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(""),[y,S]=l.useState(!1),D=l.useRef(null),j=l.useCallback(O=>{O.stopPropagation()},[]),I=o.length>1,A=l.useMemo(()=>jw(g),[g]),E=l.useMemo(()=>{const O=u.toLowerCase();return O?e.filter(V=>V.toLowerCase().includes(O)):e},[u,e]),P=l.useMemo(()=>{const O=u.toLowerCase();return O?n.filter(V=>V.toLowerCase().includes(O)):n},[u,n]),k=O=>{if(O===t){m(!1);return}i(O),m(!1),f("")},N=()=>{h(!0),setTimeout(()=>D.current?.focus(),50)},T=async()=>{if(!(!A||y)){if(I){x(!0);return}S(!0);try{await a(A,o[0]),w(""),h(!1),m(!1)}finally{S(!1)}}},M=async O=>{if(!(!A||y)){S(!0);try{await a(A,O),w(""),h(!1),x(!1),m(!1)}finally{S(!1)}}},R=()=>{x(!1)},L=()=>{w(""),h(!1),x(!1)};return l.useEffect(()=>{p||(f(""),h(!1),x(!1),w(""))},[p]),s.jsxs(Bs,{open:p,onOpenChange:m,children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsxs(ve,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:c,children:[s.jsx(C,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:t||d("gitView.branch.detachedHead")}),s.jsx(C,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),s.jsx(Pt,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx($s,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(Aa,{className:"h-full min-h-0",children:[s.jsx(ra,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:f}),s.jsxs(Da,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Ta,{children:d("gitView.branch.empty")}),s.jsx(Bn,{children:v?s.jsxs("div",{className:"px-2 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("button",{type:"button",onClick:R,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(C,{name:"arrow-left",className:"size-4"})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d("gitView.branch.pushToPrefix")," ",s.jsx("span",{className:"text-foreground font-medium",children:A})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:o.map(O=>s.jsxs("button",{type:"button",onClick:()=>M(O),disabled:y,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[y?s.jsx(C,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,O.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:O.pushUrl})]},O.name))})]}):b?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:D,placeholder:d("gitView.branch.newBranchPlaceholder"),value:g,onChange:O=>w(O.target.value),onClick:O=>O.stopPropagation(),onKeyDown:O=>{j(O),O.key==="Enter"?(O.preventDefault(),T()):O.key==="Escape"&&(O.preventDefault(),L())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:T,disabled:!A||y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:y?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:L,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(C,{name:"close",className:"size-4"})})]}):s.jsxs(Pn,{onSelect:N,children:[s.jsx(C,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(ya,{}),s.jsxs(Bn,{heading:d("gitView.branch.localBranches"),children:[E.map(O=>s.jsxs(Pn,{onSelect:()=>k(O),children:[s.jsxs("span",{className:"flex flex-1 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:O}),(r?.[O]?.ahead||r?.[O]?.behind)&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[O].ahead||0," ahead ·"," ",r[O].behind||0," behind"]})]}),t===O&&s.jsx("span",{className:"typography-micro text-primary",children:d("gitView.branch.currentBadge")})]},`local-${O}`)),E.length===0&&s.jsx(Pn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(ya,{}),s.jsxs(Bn,{heading:d("gitView.branch.remoteBranches"),children:[P.map(O=>s.jsx(Pn,{onSelect:()=>k(O),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:O})},`remote-${O}`)),P.length===0&&s.jsx(Pn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},Sw=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),kw=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=mt(),[i,a]=l.useState(!1),[o,c]=l.useState(t||""),[d,p]=l.useState(!1),m=l.useRef(null),u=()=>{!t||!e||(c(t),a(!0),setTimeout(()=>m.current?.focus(),0))},f=async()=>{if(!t||!e||!o.trim())return;const v=Sw(o);if(v===t){a(!1);return}p(!0);try{await e(t,v),a(!1),c("")}finally{p(!1)}},b=()=>{a(!1),c("")},h=v=>{v.key==="Enter"?(v.preventDefault(),f()):v.key==="Escape"&&(v.preventDefault(),b())};return i?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:v=>{v.preventDefault(),f()},children:[s.jsx(C,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:o,onChange:v=>c(v.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:h,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,"aria-label":r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:b,disabled:d,"aria-label":r("gitView.branch.renameCancel"),title:r("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(C,{name:"close",className:"size-4"})})]})}):s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[s.jsx(C,{name:"git-branch",className:"size-4 text-primary shrink-0"}),s.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:t||r("gitView.branch.detachedHead")}),n&&e&&t&&s.jsx(ve,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(C,{name:"edit",className:"size-4"})})]})]})},Cw=t=>{const e=rt.c(41),{syncAction:n,remotes:r,onFetch:i,onSync:a,onRemoveRemote:o,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:f}=t,b=r===void 0?[]:r,h=d===void 0?null:d,v=p===void 0?0:p,x=m===void 0?0:m,g=f===void 0?!1:f,{t:w}=mt(),y=l.useRef(!1),S=!!h,D=b.find(W=>W.name===u)??b[0],j=x>0&&g,I=c||n!==null||S||!D||j,A=c||n!==null||S||b.length===0,E=v>0||x>0;let P;e[0]!==w?(P=w("gitView.sync.sync"),e[0]=w,e[1]=P):P=e[1];const k=x>0?`↓${x}`:null,N=v>0?`↑${v}`:null;let T;e[2]!==P||e[3]!==k||e[4]!==N?(T=[P,k,N].filter(Boolean),e[2]=P,e[3]=k,e[4]=N,e[5]=T):T=e[5];const M=T.join(" "),R=j?w("gitView.sync.commitOrStashTooltip"):D?E?w("gitView.sync.syncChangesTooltip",{ahead:v,behind:x}):w("gitView.sync.syncChanges"):w("gitView.sync.noRemoteTooltip"),L=()=>{D&&a(D)},O="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 $;e[7]!==w?($=w("gitView.sync.syncChanges"),e[7]=w,e[8]=$):$=e[8];let B;e[9]!==n?(B=n==="sync"?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=B):B=e[10];let H;e[11]!==M?(H=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:M}),e[11]=M,e[12]=H):H=e[12];let _;e[13]!==L||e[14]!==I||e[15]!==$||e[16]!==B||e[17]!==H?(_=s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:L,disabled:I,className:V,"aria-label":$,children:[B,H]})}),e[13]=L,e[14]=I,e[15]=$,e[16]=B,e[17]=H,e[18]=_):_=e[18];let se;e[19]!==R?(se=s.jsx(Pt,{sideOffset:8,children:R}),e[19]=R,e[20]=se):se=e[20];let oe;e[21]!==_||e[22]!==se?(oe=s.jsxs(Ct,{children:[_,se]}),e[21]=_,e[22]=se,e[23]=oe):oe=e[23];const ae=Bs;let ne;e[24]===Symbol.for("react.memo_cache_sentinel")?(ne=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]=ne):ne=e[24];let xe;e[25]!==w?(xe=w("gitView.sync.moreActionsAria"),e[25]=w,e[26]=xe):xe=e[26];let te;e[27]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(C,{name:"arrow-down-s",className:"size-4"}),e[27]=te):te=e[27];let F;e[28]!==A||e[29]!==xe?(F=s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:ne,disabled:A,"aria-label":xe,children:te})}),e[28]=A,e[29]=xe,e[30]=F):F=e[30];const z=$s,Q="start",re=-40,K="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",le=b.map(W=>s.jsx(zt,{onSelect:me=>{if(y.current){me.preventDefault(),y.current=!1;return}i(W)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(C,{name:"refresh",className:"size-4 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:w("gitView.sync.fetchFromRemote",{name:W.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:W.fetchUrl})]})}),o&&W.name!==u?s.jsx(ve,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||S,onPointerDown:me=>{y.current=!0,me.preventDefault(),me.stopPropagation()},onClick:me=>{y.current=!0,me.preventDefault(),me.stopPropagation(),o(W)},"aria-label":w("gitView.header.removeRemoteAria",{name:W.name}),title:w("gitView.header.removeRemoteTitle",{name:W.name}),children:h===W.name?s.jsx(C,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(C,{name:"close",className:"size-3.5"})}):null]})},W.name));let Se;e[31]!==z||e[32]!==le?(Se=s.jsx(z,{align:Q,alignOffset:re,className:K,children:le}),e[31]=z,e[32]=le,e[33]=Se):Se=e[33];let ue;e[34]!==ae||e[35]!==F||e[36]!==Se?(ue=s.jsxs(ae,{children:[F,Se]}),e[34]=ae,e[35]=F,e[36]=Se,e[37]=ue):ue=e[37];let je;return e[38]!==oe||e[39]!==ue?(je=s.jsxs("div",{className:O,children:[oe,ue]}),e[38]=oe,e[39]=ue,e[40]=je):je=e[40],je},Iw={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},Pw={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 xf(t){return t&&Pw[t]||"var(--primary)"}const Yu=t=>{const e=rt.c(8),{icon:n,className:r,colorToken:i}=t,a=Iw[n??"branch"]??"user-3";let o;e[0]!==i?(o=xf(i),e[0]=i,e[1]=o):o=e[1];let c;e[2]!==o?(c={color:o},e[2]=o,e[3]=c):c=e[3];let d;return e[4]!==r||e[5]!==a||e[6]!==c?(d=s.jsx(C,{name:a,className:r,style:c}),e[4]=r,e[5]=a,e[6]=c,e[7]=d):d=e[7],d},bf=t=>{const e=rt.c(35),{activeProfile:n,identities:r,onSelect:i,isApplying:a,iconOnly:o}=t,c=o===void 0?!1:o,{t:d}=mt(),p=a||r.length===0,m=n?.color;let u;e[0]!==m?(u=xf(m),e[0]=m,e[1]=u):u=e[1];let f;e[2]!==u?(f={color:u},e[2]=u,e[3]=f):f=e[3];let b;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==a?(b=a?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(Yu,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=a,e[7]=b):b=e[7];let h;e[8]!==n?.name||e[9]!==c||e[10]!==d?(h=!c&&s.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||d("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=c,e[10]=d,e[11]=h):h=e[11];let v;e[12]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(C,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=v):v=e[12];let x;e[13]!==p||e[14]!==f||e[15]!==b||e[16]!==h?(x=s.jsx(It,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsxs(ve,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:f,disabled:p,children:[b,h,v]})})}),e[13]=p,e[14]=f,e[15]=b,e[16]=h,e[17]=x):x=e[17];let g;e[18]!==d?(g=d("gitView.header.identityTooltip"),e[18]=d,e[19]=g):g=e[19];let w;e[20]!==g?(w=s.jsx(Pt,{sideOffset:8,children:g}),e[20]=g,e[21]=w):w=e[21];let y;e[22]!==w||e[23]!==x?(y=s.jsxs(Ct,{children:[x,w]}),e[22]=w,e[23]=x,e[24]=y):y=e[24];let S;e[25]!==n?.id||e[26]!==r||e[27]!==i||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(I=>{const A=n?.id===I.id;return s.jsx(zt,{onSelect:()=>i(I),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(Yu,{icon:I.icon,colorToken:I.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:I.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:I.userEmail})]}),A?s.jsx(C,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},I.id)}),e[25]=n?.id,e[26]=r,e[27]=i,e[28]=d,e[29]=S):S=e[29];let D;e[30]!==S?(D=s.jsx($s,{align:"end",className:"w-64",children:S}),e[30]=S,e[31]=D):D=e[31];let j;return e[32]!==y||e[33]!==D?(j=s.jsxs(Bs,{children:[y,D]}),e[32]=y,e[33]=D,e[34]=j):j=e[34],j},Aw=t=>{const e=rt.c(48),{status:n,localBranches:r,remoteBranches:i,branchInfo:a,syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:f,onCreateBranch:b,onRenameBranch:h,activeIdentityProfile:v,availableIdentities:x,onSelectIdentity:g,isApplyingIdentity:w,isWorktreeMode:y,onOpenHistory:S,actionTabItems:D,activeActionTab:j,onSelectActionTab:I}=t,{t:A}=mt();if(!n)return null;let E;e[0]!==S||e[1]!==A?(E=S?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:S,children:s.jsx(C,{name:"history",className:"size-4"})})}),s.jsx(Pt,{sideOffset:8,children:A("gitView.history.title")})]}):null,e[0]=S,e[1]=A,e[2]=E):E=e[2];let P;e[3]!==E?(P=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:E}),e[3]=E,e[4]=P):P=e[4];const k=P,N=!n;let T;e[5]!==n.tracking?(T=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=T):T=e[6];const M=(n.files?.length??0)>0;let R;e[7]!==d||e[8]!==m||e[9]!==p||e[10]!==c||e[11]!==u||e[12]!==n.ahead||e[13]!==n.behind||e[14]!==o||e[15]!==N||e[16]!==T||e[17]!==M?(R=s.jsx(Cw,{syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:N,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:T,hasUncommittedChanges:M}),e[7]=d,e[8]=m,e[9]=p,e[10]=c,e[11]=u,e[12]=n.ahead,e[13]=n.behind,e[14]=o,e[15]=N,e[16]=T,e[17]=M,e[18]=R):R=e[18];const L=R;let O;e[19]!==v||e[20]!==x||e[21]!==w||e[22]!==g?(O=s.jsx(bf,{activeProfile:v,identities:x,onSelect:g,isApplying:w,iconOnly:!0}),e[19]=v,e[20]=x,e[21]=w,e[22]=g,e[23]=O):O=e[23];const V=O;let $;e[24]!==a||e[25]!==y||e[26]!==r||e[27]!==f||e[28]!==b||e[29]!==h||e[30]!==i||e[31]!==c||e[32]!==n.current?($=s.jsx("div",{className:"min-w-0 flex-1",children:y?s.jsx(kw,{currentBranch:n.current,onRename:h}):s.jsx(Nw,{currentBranch:n.current,localBranches:r,remoteBranches:i,branchInfo:a,onCheckout:f,onCreate:b,remotes:c})}),e[24]=a,e[25]=y,e[26]=r,e[27]=f,e[28]=b,e[29]=h,e[30]=i,e[31]=c,e[32]=n.current,e[33]=$):$=e[33];let B;e[34]!==V||e[35]!==k?(B=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[k,V]}),e[34]=V,e[35]=k,e[36]=B):B=e[36];let H;e[37]!==$||e[38]!==B?(H=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[$,B]}),e[37]=$,e[38]=B,e[39]=H):H=e[39];let _;e[40]!==D||e[41]!==j||e[42]!==I||e[43]!==L?(_=D&&j&&I?s.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(Tr,{items:D,activeId:j,onSelect:I,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:L})]}):null,e[40]=D,e[41]=j,e[42]=I,e[43]=L,e[44]=_):_=e[44];let se;return e[45]!==H||e[46]!==_?(se=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[H,_]}),e[45]=H,e[46]=_,e[47]=se):se=e[47],se},Dw=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,uncommittedFileCount:i,onChanged:a})=>{const{t:o}=mt(),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(""),[b,h]=l.useState(""),[v,x]=l.useState(null),[g,w]=l.useState({}),y=l.useCallback(async()=>{if(n){m(!0);try{const E=await Ux(n);d(E.stashes),w({})}catch(E){q.error(E instanceof Error?E.message:o("gitView.stashes.toast.loadFailed"))}finally{m(!1)}}},[n,o]);l.useEffect(()=>{t&&y()},[y,t]),l.useEffect(()=>{if(!t||!n||c.length===0)return;let E=!1;const P=c.map(k=>k.ref);return Wx(n,P).then(k=>{E||w(k.counts)}).catch(()=>{}),()=>{E=!0}},[n,t,c]);const S=l.useMemo(()=>{const E=u.trim().toLowerCase();return E?c.filter(P=>`${P.ref} ${P.message} ${P.relativeTime}`.toLowerCase().includes(E)):c},[u,c]),D=l.useCallback(async()=>{await y(),await a?.()},[y,a]),j=async()=>{if(!(!n||v)){x("create");try{(await Kx(n,{message:b.trim()||void 0})).created?(q.success(o("gitView.stashes.toast.created")),h("")):q.info(o("gitView.stashes.toast.noChanges")),await D()}catch(E){q.error(E instanceof Error?E.message:o("gitView.stashes.toast.createFailed"))}finally{x(null)}}},I=async(E,P)=>{if(!(!n||v)&&!(P==="drop"&&!window.confirm(o("gitView.stashes.confirm.drop",{ref:E.ref})))){x(`${P}:${E.ref}`);try{P==="apply"&&await Hx(n,{ref:E.ref}),P==="pop"&&await Gx(n,{ref:E.ref}),P==="drop"&&await qx(n,{ref:E.ref});const k=P==="apply"?"gitView.stashes.toast.applySuccess":P==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";q.success(o(k)),await D()}catch(k){const N=P==="apply"?"gitView.stashes.toast.applyFailed":P==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";q.error(k instanceof Error?k.message:o(N)),await D()}finally{x(null)}}},A=v!==null;return s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(Ss,{children:[s.jsxs(js,{className:"flex items-center gap-2",children:[s.jsx(C,{name:"archive-stack",className:"h-5 w-5"}),o("gitView.stashes.title")]}),s.jsx(Rs,{children:o("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(Ut,{value:b,onChange:E=>h(E.target.value),placeholder:o("gitView.stashes.messagePlaceholder"),disabled:A||!r,className:"flex-1"}),s.jsxs(ve,{onClick:j,disabled:!r||A||!n,children:[v==="create"?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"inbox-archive",className:"size-4"}),o("gitView.stashes.actions.stashCurrentWithCount",{count:i})]})]}),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(C,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(Ut,{value:u,onChange:E=>f(E.target.value),placeholder:o("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:p?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(C,{name:"loader-4",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((E,P)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:E.message||o("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{children:P===0&&!u.trim()?o("gitView.stashes.latestLabel"):o("gitView.stashes.itemNumber",{number:P+1})})}),s.jsx(Pt,{sideOffset:6,children:E.ref})]})," · ",E.relativeTime," · ",typeof g[E.ref]=="number"?o("gitView.stashes.fileCount",{count:g[E.ref]}):o("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(nc,{label:o("gitView.stashes.actions.apply"),loading:v===`apply:${E.ref}`,onClick:()=>I(E,"apply"),disabled:A,children:s.jsx(C,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(nc,{label:o("gitView.stashes.actions.pop"),loading:v===`pop:${E.ref}`,onClick:()=>I(E,"pop"),disabled:A,children:s.jsx(C,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(nc,{label:o("gitView.stashes.actions.drop"),loading:v===`drop:${E.ref}`,onClick:()=>I(E,"drop"),disabled:A,destructive:!0,children:s.jsx(C,{name:"delete-bin",className:"size-4"})})]})]},E.ref))})]})})},nc=t=>{const e=rt.c(17),{label:n,loading:r,disabled:i,destructive:a,onClick:o,children:c}=t,d=r||void 0,p=a?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let m;e[0]!==p?(m=pe("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",p),e[0]=p,e[1]=m):m=e[1];let u;e[2]!==c||e[3]!==r?(u=r?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):c,e[2]=c,e[3]=r,e[4]=u):u=e[4];let f;e[5]!==i||e[6]!==n||e[7]!==o||e[8]!==d||e[9]!==m||e[10]!==u?(f=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:o,disabled:i,children:u})}),e[5]=i,e[6]=n,e[7]=o,e[8]=d,e[9]=m,e[10]=u,e[11]=f):f=e[11];let b;e[12]!==n?(b=s.jsx(Pt,{sideOffset:6,children:n}),e[12]=n,e[13]=b):b=e[13];let h;return e[14]!==f||e[15]!==b?(h=s.jsxs(Ct,{children:[f,b]}),e[14]=f,e[15]=b,e[16]=h):h=e[16],h},yf={"?":{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"}},Tw=yf.M;function Mw(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 Ew(t){const e=Mw(t);return yf[e]??Tw}const Xu=l.memo(function(e){const n=rt.c(71),{file:r,checked:i,onToggle:a,onViewDiff:o,onRevert:c,isReverting:d,stats:p,rowPaddingClassName:m,indentPx:u}=e,f=u===void 0?0:u;let b;n[0]!==r?(b=Ew(r),n[0]=r,n[1]=b):b=n[1];const h=b,{t:v}=mt(),x=h.description,g=p?.insertions??0,w=p?.deletions??0;let y;n[2]!==a||n[3]!==o?(y=F=>{F.key===" "?(F.preventDefault(),a()):F.key==="Enter"&&(F.preventDefault(),o())},n[2]=a,n[3]=o,n[4]=y):y=n[4];const S=y;let D;n[5]!==c?(D=F=>{F.preventDefault(),F.stopPropagation(),c()},n[5]=c,n[6]=D):D=n[6];const j=D,I=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${m??"px-3"}`;let A;n[7]!==f?(A=f>0?{paddingLeft:`${f}px`}:void 0,n[7]=f,n[8]=A):A=n[8];let E;n[9]!==a?(E=()=>a(),n[9]=a,n[10]=E):E=n[10];let P;n[11]!==r.path||n[12]!==v?(P=v("gitView.changes.selectFileAria",{path:r.path}),n[11]=r.path,n[12]=v,n[13]=P):P=n[13];let k;n[14]!==i||n[15]!==E||n[16]!==P?(k=s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",onClick:Rw,children:s.jsx(bs,{size:"sm",checked:i,onChange:E,ariaLabel:P})}),n[14]=i,n[15]=E,n[16]=P,n[17]=k):k=n[17];let N;n[18]!==h.color?(N={color:h.color},n[18]=h.color,n[19]=N):N=n[19];let T;n[20]!==h.code||n[21]!==x||n[22]!==N?(T=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:N,title:x,"aria-label":x,children:h.code}),n[20]=h.code,n[21]=x,n[22]=N,n[23]=T):T=n[23];let M;n[24]!==r.path?(M=s.jsx(yr,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[24]=r.path,n[25]=M):M=n[25];let R;if(n[26]!==r.path){e:{const F=r.path.lastIndexOf("/");if(F===-1){let ue;n[28]===Symbol.for("react.memo_cache_sentinel")?(ue={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[28]=ue):ue=n[28],R=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:ue,title:r.path,children:r.path});break e}const z=r.path.slice(0,F),Q=r.path.slice(F);let re;n[29]===Symbol.for("react.memo_cache_sentinel")?(re={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[29]=re):re=n[29];let K;n[30]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[30]=K):K=n[30];const le=s.jsx("span",{className:"text-foreground",children:Q.slice(1)});let Se;n[31]!==le?(Se=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[K,le]}),n[31]=le,n[32]=Se):Se=n[32],R=s.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:r.path,children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:re,children:z}),Se]})}n[26]=r.path,n[27]=R}else R=n[27];let L;n[33]===Symbol.for("react.memo_cache_sentinel")?(L={color:"var(--status-success)"},n[33]=L):L=n[33];let O;n[34]!==g?(O=s.jsxs("span",{style:L,children:["+",g]}),n[34]=g,n[35]=O):O=n[35];let V,$;n[36]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),$={color:"var(--status-error)"},n[36]=V,n[37]=$):(V=n[36],$=n[37]);let B;n[38]!==w?(B=s.jsxs("span",{style:$,children:["-",w]}),n[38]=w,n[39]=B):B=n[39];let H;n[40]!==O||n[41]!==B?(H=s.jsxs("span",{className:"shrink-0 typography-micro",children:[O,V,B]}),n[40]=O,n[41]=B,n[42]=H):H=n[42];let _;n[43]!==r.path||n[44]!==v?(_=v("gitView.changes.revertFileAria",{path:r.path}),n[43]=r.path,n[44]=v,n[45]=_):_=n[45];let se;n[46]!==d?(se=d?s.jsx(C,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(C,{name:"arrow-go-back",className:"size-3.5"}),n[46]=d,n[47]=se):se=n[47];let oe;n[48]!==j||n[49]!==d||n[50]!==_||n[51]!==se?(oe=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,disabled:d,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":_,children:se})}),n[48]=j,n[49]=d,n[50]=_,n[51]=se,n[52]=oe):oe=n[52];let ae;n[53]!==v?(ae=v("gitView.changes.revertFileTooltip"),n[53]=v,n[54]=ae):ae=n[54];let ne;n[55]!==ae?(ne=s.jsx(Pt,{sideOffset:8,children:ae}),n[55]=ae,n[56]=ne):ne=n[56];let xe;n[57]!==oe||n[58]!==ne?(xe=s.jsxs(Ct,{children:[oe,ne]}),n[57]=oe,n[58]=ne,n[59]=xe):xe=n[59];let te;return n[60]!==S||n[61]!==o||n[62]!==T||n[63]!==M||n[64]!==R||n[65]!==H||n[66]!==xe||n[67]!==I||n[68]!==A||n[69]!==k?(te=s.jsxs("div",{className:I,role:"button",tabIndex:0,onClick:o,onKeyDown:S,style:A,children:[k,T,M,R,H,xe]}),n[60]=S,n[61]=o,n[62]=T,n[63]=M,n[64]=R,n[65]=H,n[66]=xe,n[67]=I,n[68]=A,n[69]=k,n[70]=te):te=n[70],te});function Rw(t){t.stopPropagation()}const Fw=120,Lw=34,Zu=14,vf=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),em=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),Ow=t=>{const e=em("","");for(const n of t){const r=vf(n.path);if(!r)continue;const a=r.split("/").filter(Boolean).slice(0,-1);let o=e;if(o.files.push(n),a.length>0){let c="";for(const d of a){c=c?`${c}/${d}`:d;const p=o.children.get(d);if(p){p.files.push(n),o=p;continue}const m=em(c,d);m.files.push(n),o.children.set(d,m),o=m}}o.directFiles.push(n)}return e},$w=(t,e)=>{const n=[],r=(i,a)=>{const o=Array.from(i.children.values()).sort((d,p)=>d.path.localeCompare(p.path));for(const d of o)n.push({key:d.id,kind:"directory",depth:a,directory:d}),e.has(d.path)&&r(d,a+1);const c=[...i.directFiles].sort((d,p)=>d.path.localeCompare(p.path));for(const d of c)n.push({key:`file:${vf(d.path)}`,kind:"file",depth:a,file:d})};return r(t,0),n},tm=(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"},Bw=({changeEntries:t,selectedPaths:e,diffStats:n,revertingPaths:r,onToggleFile:i,onSelectAll:a,onClearSelection:o,onRevertAll:c,onViewDiff:d,onRevertFile:p,isRevertingAll:m=!1,maxListHeightClassName:u,onVisiblePathsChange:f,onOpenStashes:b})=>{const{t:h}=mt(),v=l.useRef(null),g=Me(te=>te.gitChangesViewMode)==="tree",w=e.size,y=t.length,[S,D]=l.useState(!1),j=l.useMemo(()=>Ow(t),[t]),[I,A]=l.useState(new Set),E=l.useMemo(()=>Array.from(j.children.values()).map(te=>te.path),[j]);l.useEffect(()=>{g&&A(te=>{const F=new Set,z=new Set(E);return te.forEach(Q=>{if(Q.includes("/")){F.add(Q);return}z.has(Q)&&F.add(Q)}),E.forEach(Q=>F.add(Q)),F})},[g,E]);const P=l.useMemo(()=>$w(j,I),[I,j]),k=l.useMemo(()=>g?P:t,[t,g,P]),N=k.length,T=N>=Fw,M=w>0,R=y>0&&w===y,L=M&&!R,O=Mg({count:N,getScrollElement:()=>v.current,estimateSize:()=>Lw,overscan:10,enabled:T});l.useEffect(()=>{if(!T)return;const te=v.current;if(!te)return;const F=new ResizeObserver(()=>{O.measure()});return F.observe(te),()=>F.disconnect()},[T,O]);const V=O.getTotalSize(),$=l.useMemo(()=>T&&V>=0?O.getVirtualItems():[],[T,O,V]);l.useEffect(()=>{if(!f)return;if(N===0){f([]);return}const te=F=>{if(!g)return F.path;const z=F;return z.kind==="file"?z.file.path:null};if(!T){f(k.slice(0,Math.min(30,N)).map(F=>te(F)).filter(F=>!!F));return}f($.map(F=>k[F.index]).map(F=>F?te(F):null).filter(F=>!!F))},[g,f,N,k,T,$]);const B="flex flex-col flex-1 min-h-0",H="flex items-center justify-between gap-2 px-0 py-3 border-b border-border/40",_=`flex-1 min-h-0 pr-0 ${u??""}`.trim(),se="pl-0 pr-2",oe=l.useCallback(te=>{A(F=>{const z=new Set(F);return z.has(te)?z.delete(te):z.add(te),z})},[]),ae=l.useCallback(te=>{const z=tm(te,e)!=="all";for(const Q of te.files){const re=e.has(Q.path);(z&&!re||!z&&re)&&i(Q.path)}},[i,e]),ne=l.useCallback(te=>{if(!g){const K=te;return s.jsx(Xu,{file:K,checked:e.has(K.path),stats:n?.[K.path],onToggle:()=>i(K.path),onViewDiff:()=>d(K.path),onRevert:()=>p(K.path),isReverting:r.has(K.path)||m,rowPaddingClassName:se})}const F=te;if(F.kind==="file"){const K=F.file;return s.jsx(Xu,{file:K,checked:e.has(K.path),stats:n?.[K.path],onToggle:()=>i(K.path),onViewDiff:()=>d(K.path),onRevert:()=>p(K.path),isReverting:r.has(K.path)||m,rowPaddingClassName:se,indentPx:F.depth*Zu})}const z=F.directory,Q=I.has(z.path),re=tm(z,e);return s.jsxs("div",{className:pe("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",se),style:{paddingLeft:`${F.depth*Zu}px`},children:[s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",children:s.jsx(bs,{size:"sm",checked:re==="all",indeterminate:re==="partial",onChange:()=>ae(z),ariaLabel:h("gitView.changes.toggleDirectorySelectionAria",{path:z.path})})}),s.jsxs("button",{type:"button",onClick:()=>oe(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":Q?h("gitView.changes.collapseDirectoryAria",{path:z.path}):h("gitView.changes.expandDirectoryAria",{path:z.path}),children:[Q?s.jsx(C,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(C,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:z.path,children:z.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:z.files.length})]})]})},[n,I,m,g,p,i,d,r,se,e,h,oe,ae]),xe=l.useCallback(async()=>{!c||m||t.length===0||(await c(t.map(te=>te.path)),D(!1))},[t,m,c]);return s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:B,children:[s.jsxs("header",{className:H,children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:h("gitView.changes.title")}),y>0?s.jsxs("div",{className: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:M,indeterminate:L,disabled:m,onChange:()=>R?o():a(),ariaLabel:h(R?"gitView.changes.clearSelectionAria":"gitView.changes.selectAllAria")}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[w,"/",y]})]}):null,b?s.jsx(ve,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-1.5",onClick:b,"aria-label":h("gitView.stashes.title"),title:h("gitView.stashes.title"),children:s.jsx(C,{name:"archive-stack",className:"size-4"})}):null]}),s.jsx("div",{className:"flex items-center gap-2 pr-1",children:y>0&&c?s.jsx(ve,{variant:"destructive",size:"xs",onClick:()=>D(!0),disabled:m,children:h("gitView.changes.revertAll")}):null})]}),s.jsxs("div",{className:pe("relative flex flex-col min-h-0 w-full overflow-hidden",_),children:[s.jsx(Zi,{ref:v,className:"overlay-scrollbar-target overlay-scrollbar-container flex-1 min-h-0 w-full overflow-y-auto overflow-x-hidden",children:T?s.jsx("div",{className:"relative w-full",style:{height:`${O.getTotalSize()}px`},children:$.map(te=>{const F=k[te.index];if(!F)return null;const z=g?F.key:`file:${F.path}`;return s.jsx("div",{ref:O.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:ne(F)},z)})}):s.jsx("div",{role:"list","aria-label":h("gitView.changes.changedFilesAria"),children:k.map((te,F)=>s.jsx("div",{className:pe("relative",F>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:ne(te)},g?te.key:`file:${te.path}`))})}),s.jsx(Jx,{containerRef:v,disableHorizontal:!0})]})]}),s.jsx(ws,{open:S,onOpenChange:te=>{m||D(te)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:h("gitView.changes.revertAllDialogTitle")}),s.jsx(Rs,{children:y===1?h("gitView.changes.revertAllDescriptionSingle",{count:y}):h("gitView.changes.revertAllDescriptionPlural",{count:y})})]}),s.jsxs(Gs,{children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>D(!1),disabled:m,children:h("gitView.common.cancel")}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:()=>{xe()},disabled:m,children:h(m?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},rc=38,vo=200,_w=t=>{const e=rt.c(20),{value:n,onChange:r,placeholder:i,disabled:a,hasTouchInput:o,isMobile:c}=t,d=a===void 0?!1:a,p=o===void 0?!1:o,m=c===void 0?!1:c,{t:u}=mt(),f=l.useRef(null),b=Me(Vw);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const E=f.current;if(!E)return;const P=document.activeElement===E,k=()=>{E.style.height=`${rc}px`;const T=E.scrollHeight,M=Math.min(Math.max(T,rc),vo);E.style.height=`${M}px`,E.style.overflowY=T>vo?"auto":"hidden",T>vo&&!P&&(E.scrollTop=E.scrollHeight)};k();const N=window.requestAnimationFrame(k);return()=>{window.cancelAnimationFrame(N)}},e[0]=h):h=e[0];let v;e[1]!==n?(v=[n],e[1]=n,e[2]=v):v=e[2],l.useLayoutEffect(h,v);let x;e[3]!==r?(x=E=>r(E.target.value),e[3]=r,e[4]=x):x=e[4];let g;e[5]!==i||e[6]!==u?(g=i??u("gitView.commit.messagePlaceholder"),e[5]=i,e[6]=u,e[7]=g):g=e[7];const w=p?"on":"off",y=p?"sentences":"off",S=m||b,D=d&&"opacity-50";let j;e[8]!==D?(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)]",D),e[8]=D,e[9]=j):j=e[9];let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I={minHeight:rc,maxHeight:vo},e[10]=I):I=e[10];let A;return e[11]!==d||e[12]!==S||e[13]!==j||e[14]!==x||e[15]!==g||e[16]!==w||e[17]!==y||e[18]!==n?(A=s.jsx("textarea",{ref:f,value:n,onChange:x,placeholder:g,rows:1,disabled:d,autoCorrect:w,autoCapitalize:y,spellCheck:S,className:j,style:I}),e[11]=d,e[12]=S,e[13]=j,e[14]=x,e[15]=g,e[16]=w,e[17]=y,e[18]=n,e[19]=A):A=e[19],A};function Vw(t){return t.inputSpellcheckEnabled}const zw=t=>{const e=rt.c(30),{highlights:n,onInsert:r}=t,{t:i}=mt();if(n.length===0)return null;let a;e[0]!==n||e[1]!==r?(a=()=>{r(n)},e[0]=n,e[1]=r,e[2]=a):a=e[2];const o=a;let c;e[3]!==i?(c=i("gitView.commit.aiHighlights.title"),e[3]=i,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]!==i?(p=i("gitView.commit.aiHighlights.insertAria"),e[7]=i,e[8]=p):p=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(C,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==o||e[11]!==p?(u=s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"size-6",onClick:o,"aria-label":p,children:m})}),e[10]=o,e[11]=p,e[12]=u):u=e[12];let f;e[13]!==i?(f=i("gitView.commit.aiHighlights.insertTooltip"),e[13]=i,e[14]=f):f=e[14];let b;e[15]!==f?(b=s.jsx(Pt,{sideOffset:8,children:f}),e[15]=f,e[16]=b):b=e[16];let h;e[17]!==u||e[18]!==b?(h=s.jsxs(Ct,{children:[u,b]}),e[17]=u,e[18]=b,e[19]=h):h=e[19];let v;e[20]!==d||e[21]!==h?(v=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,h]}),e[20]=d,e[21]=h,e[22]=v):v=e[22];let x;e[23]!==n?(x=n.map(Uw),e[23]=n,e[24]=x):x=e[24];let g;e[25]!==x?(g=s.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=g):g=e[26];let w;return e[27]!==v||e[28]!==g?(w=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[v,g]}),e[27]=v,e[28]=g,e[29]=w):w=e[29],w};function Uw(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const Ww=t=>{const e=rt.c(72),{selectedCount:n,commitMessage:r,onCommitMessageChange:i,generatedHighlights:a,onInsertHighlights:o,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,gitmojiEnabled:f,onOpenGitmojiPicker:b}=t,{t:h}=mt(),v=n>0;let x;e[0]!==u||e[1]!==r||e[2]!==v?(x=r.trim()&&v&&u===null,e[0]=u,e[1]=r,e[2]=v,e[3]=x):x=e[3];const g=x,{isMobile:w,hasTouchInput:y}=rn();let S;e[4]!==h?(S=h("gitView.commit.title"),e[4]=h,e[5]=S):S=e[5];let D;e[6]!==S?(D=s.jsx("div",{className:"flex w-full items-center justify-between px-0 pt-2 pb-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:S})}),e[6]=S,e[7]=D):D=e[7];let j;e[8]!==v||e[9]!==h?(j=v?null:s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.commit.selectFilesHint")}),e[8]=v,e[9]=h,e[10]=j):j=e[10];let I;e[11]!==a||e[12]!==o?(I=s.jsx(zw,{highlights:a,onInsert:o}),e[11]=a,e[12]=o,e[13]=I):I=e[13];let A;e[14]!==h?(A=h("gitView.commit.messagePlaceholder"),e[14]=h,e[15]=A):A=e[15];const E=u!==null;let P;e[16]!==r||e[17]!==y||e[18]!==w||e[19]!==i||e[20]!==A||e[21]!==E?(P=s.jsx(_w,{value:r,onChange:i,placeholder:A,disabled:E,hasTouchInput:y,isMobile:w}),e[16]=r,e[17]=y,e[18]=w,e[19]=i,e[20]=A,e[21]=E,e[22]=P):P=e[22];let k;e[23]!==f||e[24]!==b||e[25]!==h?(k=f&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:b,className:"w-fit",type:"button",children:[s.jsx(C,{name:"emotion-happy",className:"size-4"}),h("gitView.commit.addGitmoji")]}),e[23]=f,e[24]=b,e[25]=h,e[26]=k):k=e[26];const N=d||u!==null||n===0;let T;e[27]!==h?(T=h("gitView.commit.generateAria"),e[27]=h,e[28]=T):T=e[28];let M;e[29]!==d?(M=d?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"ai-generate-2",className:"size-4 text-primary"}),e[29]=d,e[30]=M):M=e[30];let R;e[31]!==h?(R=h("gitView.commit.generate"),e[31]=h,e[32]=R):R=e[32];let L;e[33]!==R?(L=s.jsx("span",{className:"commit-actions__label",children:R}),e[33]=R,e[34]=L):L=e[34];let O;e[35]!==c||e[36]!==N||e[37]!==T||e[38]!==M||e[39]!==L?(O=s.jsxs(ve,{variant:"outline",size:"sm",onClick:c,disabled:N,type:"button","aria-label":T,className:"commit-actions__btn",children:[M,L]}),e[35]=c,e[36]=N,e[37]=T,e[38]=M,e[39]=L,e[40]=O):O=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 $=!g||d;let B;e[42]!==h?(B=h("gitView.commit.commitAria"),e[42]=h,e[43]=B):B=e[43];let H;e[44]!==u||e[45]!==h?(H=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.commit")})]}),e[44]=u,e[45]=h,e[46]=H):H=e[46];let _;e[47]!==p||e[48]!==$||e[49]!==B||e[50]!==H?(_=s.jsx(ve,{size:"sm",variant:"outline",onClick:p,disabled:$,className:"commit-actions__btn whitespace-nowrap","aria-label":B,children:H}),e[47]=p,e[48]=$,e[49]=B,e[50]=H,e[51]=_):_=e[51];let se;e[52]!==g||e[53]!==u||e[54]!==d||e[55]!==w||e[56]!==m||e[57]!==h?(se=w?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"default",size:"sm",onClick:()=>m(),disabled:!g||d,className:"h-7 w-7 p-0","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(Pt,{side:"top",children:s.jsx("p",{children:h("gitView.commit.push")})})]}):s.jsx(ve,{size:"sm",variant:"default",onClick:()=>m(),disabled:!g||d,className:"commit-actions__btn","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.push")})]})}),e[52]=g,e[53]=u,e[54]=d,e[55]=w,e[56]=m,e[57]=h,e[58]=se):se=e[58];let oe;e[59]!==O||e[60]!==_||e[61]!==se?(oe=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[O,V,_,se]}),e[59]=O,e[60]=_,e[61]=se,e[62]=oe):oe=e[62];let ae;e[63]!==oe||e[64]!==j||e[65]!==I||e[66]!==P||e[67]!==k?(ae=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[j,I,P,k,oe]}),e[63]=oe,e[64]=j,e[65]=I,e[66]=P,e[67]=k,e[68]=ae):ae=e[68];let ne;return e[69]!==ae||e[70]!==D?(ne=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[D,ae]}),e[69]=ae,e[70]=D,e[71]=ne):ne=e[71],ne},Kw=t=>{const e=rt.c(16),{onOpenStashes:n}=t,{t:r}=mt();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(C,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=i):i=e[0];let a;e[1]!==r?(a=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=a):a=e[2];let o;e[3]!==a?(o=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:a}),e[3]=a,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(ve,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(C,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=p):p=e[11];let m;return e[12]!==o||e[13]!==d||e[14]!==p?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[i,o,d,p]}),e[12]=o,e[13]=d,e[14]=p,e[15]=m):m=e[15],m};function sm(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 Hw(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 Gw=l.memo(t=>{const e=rt.c(55),{entry:n,isExpanded:r,onToggle:i,files:a,isLoadingFiles:o,onCopyHash:c}=t,{t:d}=mt(),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 f;e[3]!==n.message?(f=s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:n.message}),e[3]=n.message,e[4]=f):f=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 h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx("span",{className:"shrink-0",children:"·"}),e[7]=h):h=e[7];let v;e[8]!==n.date?(v=sm(n.date),e[8]=n.date,e[9]=v):v=e[9];let x;e[10]!==n.date?(x=sm(n.date),e[10]=n.date,e[11]=x):x=e[11];let g;e[12]!==v||e[13]!==x?(g=s.jsx("span",{className:"truncate min-w-0",title:v,children:x}),e[12]=v,e[13]=x,e[14]=g):g=e[14];let w;e[15]!==b||e[16]!==g?(w=s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[b,h,g]}),e[15]=b,e[16]=g,e[17]=w):w=e[17];let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("span",{className:"shrink-0",children:"·"}),e[18]=y):y=e[18];let S;e[19]!==n.hash?(S=n.hash.slice(0,8),e[19]=n.hash,e[20]=S):S=e[20];let D;e[21]!==S?(D=s.jsx("code",{className:"shrink-0 font-mono",children:S}),e[21]=S,e[22]=D):D=e[22];let j;e[23]!==n.hash||e[24]!==c?(j=O=>{O.stopPropagation(),c(n.hash)},e[23]=n.hash,e[24]=c,e[25]=j):j=e[25];let I;e[26]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(C,{name:"file-copy",className:"size-3"}),e[26]=I):I=e[26];let A;e[27]!==j?(A=s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:j,children:I})}),e[27]=j,e[28]=A):A=e[28];let E;e[29]!==d?(E=d("gitView.history.copySha"),e[29]=d,e[30]=E):E=e[30];let P;e[31]!==E?(P=s.jsx(Pt,{sideOffset:8,children:E}),e[31]=E,e[32]=P):P=e[32];let k;e[33]!==A||e[34]!==P?(k=s.jsxs(Ct,{children:[A,P]}),e[33]=A,e[34]=P,e[35]=k):k=e[35];let N;e[36]!==w||e[37]!==D||e[38]!==k?(N=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[w,y,D,k]}),e[36]=w,e[37]=D,e[38]=k,e[39]=N):N=e[39];let T;e[40]!==N||e[41]!==f?(T=s.jsxs("div",{className:"min-w-0 flex-1",children:[f,N]}),e[40]=N,e[41]=f,e[42]=T):T=e[42];let M;e[43]!==i||e[44]!==m||e[45]!==T?(M=s.jsxs("button",{type:"button",onClick:i,className:m,children:[u,T]}),e[43]=i,e[44]=m,e[45]=T,e[46]=M):M=e[46];let R;e[47]!==a||e[48]!==r||e[49]!==o||e[50]!==d?(R=r&&s.jsx("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:o?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(C,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:d("gitView.history.loadingFiles")})]}):a.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:a.map(O=>s.jsxs("li",{className:"flex items-center gap-2 typography-micro",children:[s.jsx("span",{className:pe("font-semibold w-3 text-center",Hw(O.changeType)),children:O.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:O.path,children:O.path}),!O.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",O.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",O.deletions]})]}),O.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:d("gitView.history.binary")})]},O.path))})}),e[47]=a,e[48]=r,e[49]=o,e[50]=d,e[51]=R):R=e[51];let L;return e[52]!==M||e[53]!==R?(L=s.jsxs("li",{children:[M,R]}),e[52]=M,e[53]=R,e[54]=L):L=e[54],L}),qw=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],Jw=t=>{const e=rt.c(54),{log:n,isLogLoading:r,logMaxCount:i,onLogMaxCountChange:a,expandedCommitHashes:o,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,showHeader:u,contentMaxHeightClassName:f,branchDivider:b}=t,h=u===void 0?!0:u,v=f===void 0?"max-h-[50vh]":f,x=b===void 0?null:b,{t:g}=mt(),[w,y]=l.useState(!0);if(!n)return null;const S=x!==null&&x.insertBeforeIndex>0&&x.insertBeforeIndex<n.all.length,D=x!==null&&x.insertBeforeIndex===n.all.length,j=S||D;let I;e[0]!==x||e[1]!==S||e[2]!==D||e[3]!==n.all?(I=S?n.all.slice(0,x.insertBeforeIndex):D?n.all:[],e[0]=x,e[1]=S,e[2]=D,e[3]=n.all,e[4]=I):I=e[4];const A=I;let E;if(e[5]!==x||e[6]!==d||e[7]!==v||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]!==A){const $=S?n.all.slice(x.insertBeforeIndex):[];let B;e[18]!==x?.direction?(B=x?.direction==="down"?s.jsx(C,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(C,{name:"arrow-up",className:"size-3.5"}),e[18]=x?.direction,e[19]=B):B=e[19];const H=B;let _;e[20]!==d||e[21]!==o||e[22]!==p||e[23]!==m||e[24]!==c?(_=oe=>s.jsx("ul",{className:"divide-y divide-border/60",children:oe.map(ae=>s.jsx(Gw,{entry:ae,isExpanded:o.has(ae.hash),onToggle:()=>c(ae.hash),files:d.get(ae.hash)??[],isLoadingFiles:p.has(ae.hash),onCopyHash:m},ae.hash))}),e[20]=d,e[21]=o,e[22]=p,e[23]=m,e[24]=c,e[25]=_):_=e[25];const se=_;E=s.jsx(As,{outerClassName:`min-h-0 ${v}`,className:"h-full w-full",children:n.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:g("gitView.history.noCommits")})}):j&&x?s.jsxs("div",{className:"flex flex-col gap-0",children:[A.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:se(A)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:x.branchName,children:x.branchName}),H]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),$.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:se($)}):null]}):se(n.all)}),e[5]=x,e[6]=d,e[7]=v,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]=A,e[17]=E}else E=e[17];const P=E;if(!h){if(j){let B;return e[26]!==P?(B=s.jsx("section",{className:"h-full min-h-0",children:P}),e[26]=P,e[27]=B):B=e[27],B}let $;return e[28]!==P?($=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:P}),e[28]=P,e[29]=$):$=e[29],$}let k;e[30]!==g?(k=g("gitView.history.title"),e[30]=g,e[31]=k):k=e[31];let N;e[32]!==k?(N=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:k}),e[32]=k,e[33]=N):N=e[33];let T;e[34]!==r||e[35]!==w||e[36]!==i||e[37]!==a||e[38]!==g?(T=w&&s.jsx("div",{onClick:Qw,onPointerDown:Yw,children:s.jsxs(ps,{value:String(i),onValueChange:$=>a(Number($)),disabled:r,children:[s.jsx(hs,{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(fs,{children:qw.map($=>s.jsx(Ft,{value:String($.value),children:g($.labelKey)},$.value))})]})}),e[34]=r,e[35]=w,e[36]=i,e[37]=a,e[38]=g,e[39]=T):T=e[39];let M;e[40]!==w?(M=w?s.jsx(C,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(C,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[40]=w,e[41]=M):M=e[41];let R;e[42]!==T||e[43]!==M?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[T,M]}),e[42]=T,e[43]=M,e[44]=R):R=e[44];let L;e[45]!==R||e[46]!==N?(L=s.jsxs(jr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[N,R]}),e[45]=R,e[46]=N,e[47]=L):L=e[47];let O;e[48]!==P?(O=s.jsx(dr,{children:P}),e[48]=P,e[49]=O):O=e[49];let V;return e[50]!==w||e[51]!==L||e[52]!==O?(V=s.jsxs(cr,{open:w,onOpenChange:y,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[L,O]}),e[50]=w,e[51]=L,e[52]=O,e[53]=V):V=e[53],V};function Qw(t){return t.stopPropagation()}function Yw(t){return t.stopPropagation()}const Xw=9e4,Zw=15e3,ej=5*6e4,tj=[2e3,5e3],sj=6e4,nj=2*6e4,rj=5*6e4,aj=720*6e4,ij="openchamber.github-pr-status",oj=t=>t==="closed"||t==="merged",lj=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Vi=(t,e,n)=>`${t}::${e}`,wo=new Map,jo=new Map,Si=new Set,nm=new Map,Mi=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),cl=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,Md=t=>{const e=cl(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},wf=(t,e)=>Object.entries(t).filter(([,n])=>Md(n)===e).map(([n])=>n),cj=(t,e)=>{const n=e.remoteName??t.params?.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null;return{...t,params:t.params?{...t.params,...e,remoteName:n}:{...e,remoteName:n},identity:{directory:e.directory,branch:e.branch,remoteName:n}}},No=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},dj=(t,e,n)=>{const r=wf(t,e),i=r.map(d=>No(t[d])).filter(d=>!!d);if(i.length===0)return null;const a=No(t[n]);if(a&&Md(t[n])===e)return a;const o=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&No(d)));if(o)return No(o);const c=i.find(d=>!!d.remoteName);return c||(i[0]??null)},uj=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:cl(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),mj=t=>({...Mi(),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}),or=ur()(Xi((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:Mi()}})},setParams:(n,r)=>{t(i=>{const a=i.entries[n]??Mi();return{entries:{...i.entries,[n]:cj(a,r)}}})},startWatching:n=>{if(t(a=>{const o=a.entries[n]??Mi();return{entries:{...a.entries,[n]:{...o,watchers:o.watchers+1}}}}),wo.has(n))return;const r=a=>{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})},a),c=jo.get(n)??[];c.push(o),jo.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),tj.forEach(a=>r(a));const i=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const a=e().entries[n];if(!a||a.watchers<=0)return;if(!!!a.status?.pr){const p=Date.now();if(p-a.lastDiscoveryPollAt<ej)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(oj(a.status?.pr?.state))return;const c=Date.now()-a.lastRefreshAt,d=lj(a.status)?sj:a.status?.checks&&a.status.checks.state!=="pending"?rj:nj;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},Zw);wo.set(n,i)},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 i=wo.get(n);typeof i=="number"&&window.clearInterval(i),wo.delete(n);const a=jo.get(n);a&&a.length>0&&a.forEach(o=>{window.clearTimeout(o)}),jo.delete(n)},refresh:async(n,r)=>{const i=e(),a=i.entries[n],o=Md(a);if(!a||!o)return;const c=wf(i.entries,o),d=c.some(u=>!!i.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const p=nm.get(o)??0;if(!r?.force&&Date.now()-p<Xw||Si.has(o))return;const m=dj(i.entries,o,n);if(m){if(Si.add(o),nm.set(o,Date.now()),t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,lastRefreshAt:Date.now(),isLoading:r?.silent?h.isLoading:!0,error:null})}),{entries:f}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,status:{connected:!1},error:null,isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),Si.delete(o);return}if(!m.github?.prStatus){t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),Si.delete(o);return}try{t(f=>({...f,activeRequestCount:f.activeRequestCount+1,totalRequestCount:f.totalRequestCount+1}));const u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(f=>{const b={...f.entries};return c.forEach(h=>{const v=b[h];if(!v)return;const x=v.status?.pr,g=u.pr,y=!!(g&&x&&g.number===x.number&&(!g.body||!g.body.trim())&&typeof x.body=="string"&&x.body.trim().length>0)&&g&&x?.body?{...u,pr:{...g,body:x.body}}:u,S=y.resolvedRemoteName??v.resolvedRemoteName??m.remoteName??null,D=cl(v)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};b[h]={...v,status:y,error:null,isLoading:r?.silent?v.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?v.isInitialStatusResolved:!0,resolvedRemoteName:S,identity:{...D,remoteName:S??D.remoteName??null}}}),{entries:b}})}catch(u){const f=u instanceof Error?u.message:String(u);t(b=>{const h={...b.entries};return c.forEach(v=>{const x=h[v];x&&(h[v]={...x,error:f||"Failed to load PR status",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:h}})}finally{Si.delete(o),t(u=>({...u,activeRequestCount:Math.max(0,u.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const i=Array.from(new Set(n.map(a=>{const o=a.directory.trim(),c=a.branch.trim();return!o||!c?null:Vi(o,c,a.remoteName??null)}).filter(a=>!!a)));await Promise.all(i.map(a=>e().refresh(a,r)))},updateStatus:(n,r)=>{t(i=>{const a=i.entries[n]??Mi();return{entries:{...i.entries,[n]:{...a,status:r(a.status)}}}})}}),{name:ij,storage:xl(()=>Zr()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=cl(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<aj}).map(([e,n])=>[e,uj(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([i,a])=>[i,mj(a)]))}}})),pj=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:"",i=e.mergeable===!1||r==="blocked"||r==="dirty";return n||i?"blocked":"open"},hj=t=>{const e=pj(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}},fj=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 ac=new Map,rm=new Map;const gj=t=>{const e=rt.c(2);let n;return e[0]!==t?(n=r=>{const i=new Map,a=new Map;for(const o of t){const c=r.entries[o];if(!c)continue;const d=hj(c);if(!d)continue;const p=fj(d);i.set(o,p),a.set(o,d)}if(i.size===ac.size){let o=!0;for(const[c,d]of i)if(ac.get(c)!==d){o=!1;break}if(o)return rm}return ac=i,rm=a,a},e[0]=t,e[1]=n):n=e[1],or(n)},xj=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"}},bj=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:"",i=e.mergeable===!1||r==="blocked"||r==="dirty";return n||i?"blocked":"open"},yj=[2e3,5e3],am=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),Xr=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},vj=(t,e)=>{const n=Xr(t);if(!n||n.includes("->"))return"";if(e){const i=`${e}/`;return n.startsWith(i)?n.slice(i.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},wj=(t,e)=>`${t}::${e}`,Ed=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},ic=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const a=t.find(o=>o.name===n);if(a)return a}const r=Ed(e.trackingBranch);if(r){const a=r==="origin"?t.find(c=>c.name==="upstream"):null;if(a)return a;const o=t.find(c=>c.name===r);if(o)return o}const i=t.find(a=>a.name==="origin");return i||(t[0]??null)},jj=t=>t.startsWith("pr-"),Nj=(t,e)=>{const n=Ed(e),r=new Map(t.map(o=>[o.name,o])),i=[],a=o=>{o&&(i.some(c=>c.name===o.name)||i.push(o))};return n&&a(r.get(n)),a(r.get("upstream")),a(r.get("origin")),t.filter(o=>!jj(o.name)).forEach(o=>a(o)),t.forEach(o=>a(o)),i},oc=new Map,lc=Qn;function Sj(t,e){const[n,r]=l.useState(null),[i,a]=l.useState([]),o=l.useRef(null);return l.useEffect(()=>{r(null),a([])},[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||a(p)}catch{}}catch{}})(),()=>{c=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:i}}const kj=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:i=[],remoteBranches:a=[],onGeneratedDescription:o})=>{const{t:c}=mt(),{github:d}=_n(),p=Kn(Ke=>Ke.status),m=Kn(Ke=>Ke.hasChecked),u=Me(Ke=>Ke.setSettingsDialogOpen),f=Me(Ke=>Ke.setSettingsPage),b=Me(Ke=>Ke.setActiveMainTab),h=Ht(Ke=>Ke.currentSessionId),{isMobile:v,hasTouchInput:x}=rn(),g=l.useCallback(()=>{f("github"),u(!0)},[u,f]),w=l.useMemo(()=>wj(t,e),[t,e]),y=l.useMemo(()=>oc.get(w)??null,[w]),S=or(Ke=>Ke.ensureEntry),D=or(Ke=>Ke.setParams),j=or(Ke=>Ke.startWatching),I=or(Ke=>Ke.stopWatching),A=or(Ke=>Ke.refresh),E=or(Ke=>Ke.updateStatus),[P,k]=l.useState(()=>y?.title??am(e)),[N,T]=l.useState(()=>y?.body??""),[M,R]=l.useState(()=>y?.draft??!1),[L,O]=l.useState(()=>y?.additionalContext??""),[V,$]=l.useState(()=>{const Ke=typeof y?.targetBaseBranch=="string"?Xr(y.targetBaseBranch):"";return Ke||Xr(n)}),[B,H]=l.useState("squash"),[_,se]=l.useState(!1),[oe,ae]=l.useState(!1),[ne,xe]=l.useState(!1),[te,F]=l.useState(!1),[z,Q]=l.useState(!1),[re,K]=l.useState(!1),[le,Se]=l.useState(null),[ue,je]=l.useState(""),[W,me]=l.useState(""),[X,ce]=l.useState(!1),[ee,Pe]=l.useState(!1),[Ne,Y]=l.useState(()=>ic(i,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r})),[he,ke]=l.useState(!1),{detectedUpstream:be,upstreamBranches:fe}=Sj(t,d);l.useEffect(()=>{ke(!1)},[t]);const Te=i.some(Ke=>Ke.name==="upstream"),G=!!(t&&e&&n&&(e!==n||(Te||be!==null))),Ie=l.useMemo(()=>Vi(t,e),[t,e]),Oe=or(Ke=>Ke.entries[Ie]),De=Oe?.isLoading??!1,ge=Oe?.status??null,U=Oe?.error??null,de=Oe?.isInitialStatusResolved??!1,Ee=l.useMemo(()=>{const Ke=he?null:Ne?.name?.trim()||null,xt=new Set;for(const ss of a){const at=vj(ss,Ke);!at||at==="HEAD"||xt.add(at)}if(he)for(const ss of fe)ss&&ss!=="HEAD"&&xt.add(ss);const kt=Xr(n);kt&&kt!=="HEAD"&&xt.add(kt);const Tt=Xr(V);return Tt&&Tt!=="HEAD"&&xt.add(Tt),Array.from(xt).sort((ss,at)=>ss.localeCompare(at))},[n,a,Ne?.name,V,fe,he]);l.useEffect(()=>{if(i.length===0){Ne&&Y(null);return}(!Ne||!i.some(Ke=>Ke.name===Ne.name))&&Y(ic(i,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r}))},[y?.selectedRemoteName,i,Ne,r]),l.useEffect(()=>{const Ke=Xr(n);if(!V&&Ke){$(Ke);return}if(Ee.length!==0&&!Ee.includes(V)){const xt=Ee.includes(Ke)?Ke:Ee[0];xt&&$(xt)}},[Ee,n,V]);const[_e,Z]=l.useState(!1),[ie,Ce]=l.useState(null),[He,Ge]=l.useState(!1),[Xe,we]=l.useState(new Set),[tt,st]=l.useState(!1),[qe,it]=l.useState(null),[lt,ye]=l.useState(!1),Je=l.useRef(new Set),Be=l.useRef(null),ze=l.useRef(!1),nt=l.useRef(new Set),Ye=l.useRef([]);l.useEffect(()=>{be&&!Te&&ke(!0)},[be,Te]),l.useEffect(()=>{he&&be?.defaultBranch&&$(be.defaultBranch)},[he,be?.defaultBranch]);const Ue=ge?.pr??null,vt=Ue?`${t}#${Ue.number}`:null,Et=!!(vt&&le===vt);l.useEffect(()=>{if(!d?.prContext||!Ue||typeof Ue.body=="string"&&Ue.body.length>0)return;const Ke=`${t}#${Ue.number}`;if(Je.current.has(Ke))return;Je.current.add(Ke),Se(Ke);let xt=!1;return d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!1}).then(kt=>{if(xt)return;const Tt=kt?.pr;Tt&&E(Ie,ss=>!ss?.pr||ss.pr.number!==Ue.number?ss:{...ss,pr:{...ss.pr,body:Tt.body||""}})}).catch(()=>{}).finally(()=>{xt||Se(kt=>kt===Ke?null:kt)}),()=>{xt=!0}},[t,d,Ue,Ie,E]),l.useEffect(()=>{if(!Ue){K(!1),je(""),me(""),Be.current=null;return}const Ke=Be.current!==null&&Be.current!==Ue.number;Ke&&K(!1),(!re||Ke)&&(je(Ue.title||""),me(Ue.body||"")),Be.current=Ue.number},[re,Ue]);const Gt=l.useCallback(async()=>{if(!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(Ue){Z(!0),we(new Set),Ge(!0);try{const Ke=await d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!0});Ce(Ke)}catch(Ke){const xt=Ke instanceof Error?Ke.message:String(Ke);q.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:xt})}finally{Ge(!1)}}},[t,d,Ue,c]),ts=l.useCallback(async()=>{if(!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(Ue){st(!0),ye(!0);try{const Ke=await d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!1});it(Ke)}catch(Ke){const xt=Ke instanceof Error?Ke.message:String(Ke);q.error(c("gitView.pr.toast.loadCommentsFailed"),{description:xt})}finally{ye(!1)}}},[t,d,Ue,c]),Nt=l.useCallback(Ke=>{if(!Ke)return"";const xt=Date.parse(Ke);return Number.isFinite(xt)?new Date(xt).toLocaleString():Ke},[]),St=l.useMemo(()=>{const Ke=p?.user?.login;return typeof Ke=="string"?Ke.trim():""},[p]),Zt=l.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),ut=l.useCallback(Ke=>{const xt=St.toLowerCase(),kt=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return Ke.replace(kt,(Tt,ss,at)=>{const Lt=`@${at}`,os=at.toLowerCase();return`${ss}[${Lt}](https://github.com/${os}${xt&&os===xt?"?oc-self-mention=1":""})`})},[St]),Xt=l.useMemo(()=>{const Ke=(qe?.issueComments??[]).map(Tt=>({id:`issue-${Tt.id}`,body:Tt.body||"",authorName:Tt.author?.name||Tt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Tt.author?.login||null,avatarUrl:Tt.author?.avatarUrl||null,createdAt:Tt.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),xt=(qe?.reviewComments??[]).map(Tt=>({id:`review-${Tt.id}`,body:Tt.body||"",authorName:Tt.author?.name||Tt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Tt.author?.login||null,avatarUrl:Tt.author?.avatarUrl||null,createdAt:Tt.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Tt.path||null,line:Tt.line??null})),kt=[...Ke,...xt];return kt.sort((Tt,ss)=>{const at=Tt.createdAt?Date.parse(Tt.createdAt):0,Lt=ss.createdAt?Date.parse(ss.createdAt):0,os=Number.isFinite(at)?at:0,rs=Number.isFinite(Lt)?Lt:0;return os-rs}),kt},[qe,c]),as=l.useCallback(()=>{if(!h)return q.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:Ke,currentModelId:xt,currentAgentName:kt,currentVariant:Tt}=yt.getState(),ss=vl.getState().lastUsedProvider,at=Ke||ss?.providerID,Lt=xt||ss?.modelID;return!at||!Lt?(q.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:h,providerID:at,modelID:Lt,currentAgentName:kt??null,currentVariant:Tt??null}},[h,c]),Bt=l.useCallback((Ke,xt,kt,Tt)=>{Ht.getState().sendMessage(xt,Ke.providerID,Ke.modelID,Ke.currentAgentName??void 0,void 0,void 0,[{text:kt,synthetic:!0},{text:Tt,synthetic:!0}],Ke.currentVariant??void 0).catch(ss=>{const at=ss instanceof Error?ss.message:String(ss);q.error(c("gitView.pr.toast.sendMessageFailed"),{description:at})})},[c]),ls=l.useCallback(Ke=>{const xt=Ke.status||"unknown",kt=Ke.conclusion??void 0,Tt=kt?`${xt} / ${kt}`:xt,ss=Ke.app?.name||Ke.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:Ke.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:ss?`${ss} · ${Tt}`:Tt})]}),Ke.detailsUrl?s.jsx(ve,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:Ke.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(C,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),Ke.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:Ke.output.title}):null,Ke.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:Ke.output.summary}):null,Ke.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:Ke.output.text}):null,Array.isArray(Ke.annotations)&&Ke.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",Ke.annotations.length>20?` (showing 20/${Ke.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:Ke.annotations.slice(0,20).map((at,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:[at.title||at.level||"Issue",at.path?` · ${at.path}`:"",typeof at.startLine=="number"?`:${at.startLine}`:"",typeof at.endLine=="number"&&at.endLine!==at.startLine?`-${at.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:at.message}),at.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:at.rawDetails}):null]},`${at.path||"file"}:${at.startLine||Lt}:${Lt}`))})]}):null,Ke.job?.steps&&Ke.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:Ke.job.steps.map((at,Lt)=>{const os=(at.conclusion||"").toLowerCase(),rs=os&&!["success","neutral","skipped"].includes(os),Vt=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${at.number??Lt}:${at.name}`,cs=Xe.has(Vt);return rs?s.jsxs(cr,{open:cs,children:[s.jsxs("button",{type:"button",onClick:()=>{we(sn=>{const Js=new Set(sn);return Js.has(Vt)?Js.delete(Vt):Js.add(Vt),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:[cs?s.jsx(C,{name:"arrow-down-s",className:"size-4"}):s.jsx(C,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:at.name}),at.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:at.conclusion}):null]}),s.jsx(dr,{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 at.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",at.number]}):null,at.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",at.status]}):null,at.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",at.conclusion]}):null,at.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",Nt(at.startedAt)]}):null,at.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",Nt(at.completedAt)]}):null]})})]},Vt):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:at.name}),at.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:at.conclusion}):null]},Vt)})})]}):null]})},[Xe,Nt,c]),gs=l.useCallback(async()=>{if(b("chat"),!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ue)return;const Ke=as();if(Ke)try{const xt=await d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!0}),Tt=(xt.checkRuns??[]).filter(rs=>{const Vt=typeof rs.conclusion=="string"?rs.conclusion.toLowerCase():"";return Vt?!["success","neutral","skipped"].includes(Vt):!1});if(Tt.length===0){q.message(c("gitView.pr.toast.noFailedChecks"));return}const ss=await En("github.pr.checks.review.visible"),at=await En("github.pr.checks.review.instructions"),Lt=Tt.flatMap(rs=>(Array.isArray(rs.annotations)?rs.annotations:[]).map(cs=>({run:rs.name,level:cs.level,title:cs.title,path:cs.path,startLine:cs.startLine,endLine:cs.endLine,message:cs.message,rawDetails:cs.rawDetails}))),os=`GitHub PR failed checks (JSON)
|
|
7
|
-
${JSON.stringify({repo:xt.repo??null,pr:xt.pr??null,failedChecks:Tt,failedAnnotations:Lt},null,2)}`;Bt(Ke,ss,at,os)}catch(xt){const kt=xt instanceof Error?xt.message:String(xt);q.error(c("gitView.pr.toast.loadChecksFailed"),{description:kt})}},[t,Bt,d,Ue,as,b,c]),us=l.useCallback(async()=>{if(b("chat"),!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ue)return;const Ke=as();if(Ke)try{const xt=await d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!1}),kt=xt.issueComments??[],Tt=xt.reviewComments??[];if(kt.length+Tt.length===0){q.message(c("gitView.pr.toast.noPrComments"));return}const at=await En("github.pr.comments.review.visible"),Lt=await En("github.pr.comments.review.instructions"),os=`GitHub PR comments (JSON)
|
|
8
|
-
${JSON.stringify({repo:xt.repo??null,pr:xt.pr??null,issueComments:kt,reviewComments:Tt},null,2)}`;Bt(Ke,at,Lt,os)}catch(xt){const kt=xt instanceof Error?xt.message:String(xt);q.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:kt})}},[t,Bt,d,Ue,as,b,c]),xs=l.useCallback(async Ke=>{st(!1),b("chat");const xt=as();if(!xt)return;const kt=await En("github.pr.comment.single.visible"),Tt=await En("github.pr.comment.single.instructions"),ss=`GitHub PR comment (JSON)
|
|
9
|
-
${JSON.stringify({repo:qe?.repo??null,pr:qe?.pr??Ue??null,comment:Ke},null,2)}`;Bt(xt,kt,Tt,ss)},[qe,Bt,Ue,as,b]),At=l.useCallback(async Ke=>{await A(Ie,Ke)},[Ie,A]),We=l.useCallback(()=>{Ye.current.forEach(Ke=>{window.clearTimeout(Ke)}),Ye.current=yj.map(Ke=>window.setTimeout(()=>{At({force:!0,silent:!0,markInitialResolved:!0})},Ke))},[At]);l.useEffect(()=>{if(!d?.prStatus||!G||i.length<=1||ze.current||ge?.pr)return;const Ke=`${w}::${Ne?.name??""}`;if(nt.current.has(Ke))return;nt.current.add(Ke);const xt=Nj(i,r).filter(ss=>ss.name!==Ne?.name);if(xt.length===0)return;let kt=!1;return(async()=>{for(const ss of xt){if(kt)return;try{if(!(await d.prStatus(t,e,ss.name))?.pr)continue;if(kt)return;Y(Lt=>Lt?.name===ss.name?Lt:ss);return}catch{}}})(),()=>{kt=!0}},[e,G,t,d,i,Ne?.name,w,ge?.pr,r]),l.useEffect(()=>{S(Ie),D(Ie,{directory:t,branch:e,remoteName:Ne?.name??null,canShow:G,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,G,t,S,d,m,p?.connected,Ie,Ne?.name,D]),l.useEffect(()=>(j(Ie),()=>{I(Ie)}),[Ie,j,I]),l.useEffect(()=>{const Ke=oc.get(w)??null;k(Ke?.title??am(e)),T(Ke?.body??""),R(Ke?.draft??!1),$(Ke?.targetBaseBranch?Xr(Ke.targetBaseBranch):Xr(n));const xt=ic(i,{selectedRemoteName:Ke?.selectedRemoteName,trackingBranch:r});Y(kt=>kt?.name===xt?.name?kt:xt)},[n,e,i,w,r]),l.useEffect(()=>{At({markInitialResolved:!0})},[Ie,At]),l.useEffect(()=>{!G||!Ne?.name||At({force:!0,silent:!0,markInitialResolved:!0})},[G,At,Ne?.name]),l.useEffect(()=>{const Ke=ge?.resolvedRemoteName?.trim();if(!Ke||ze.current)return;const xt=i.find(kt=>kt.name===Ke);xt&&Y(kt=>kt?.name===xt.name?kt:xt)},[i,ge?.resolvedRemoteName]),l.useEffect(()=>{const Ke=ge?.pr?.state==="closed"||ge?.pr?.state==="merged",xt=Oe?.lastRefreshAt??0,kt=Date.now()-xt>6e4,Tt=!Ke&&kt,ss=()=>{Tt&&At({force:!0,silent:!0})},at=()=>{document.visibilityState==="visible"&&Tt&&At({force:!0,silent:!0})};return window.addEventListener("focus",ss),document.addEventListener("visibilitychange",at),()=>{window.removeEventListener("focus",ss),document.removeEventListener("visibilitychange",at)}},[At,ge?.pr?.state,Oe?.lastRefreshAt]),l.useEffect(()=>{m&&p?.connected===!1&&At({force:!0,silent:!0,markInitialResolved:!0})},[m,p,At]),l.useEffect(()=>{!t||!e||oc.set(w,{title:P,body:N,draft:M,additionalContext:L,targetBaseBranch:V,selectedRemoteName:Ne?.name})},[w,P,N,M,L,V,Ne?.name,t,e]),l.useEffect(()=>{const Ke=Ye.current;return()=>{Ke.forEach(xt=>{window.clearTimeout(xt)}),Ye.current=[]}},[]);const Rt=l.useCallback(async()=>{if(!_&&t){se(!0);try{const xt={base:he&&be?.defaultBranchSha?be.defaultBranchSha:V,head:e};L&&(xt.context=L);const kt=await Qx(t,xt);kt.title?.trim()&&k(kt.title.trim()),kt.body?.trim()&&T(kt.body.trim()),o?.()}catch(Ke){const xt=Ke instanceof Error?Ke.message:String(Ke);q.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:xt})}finally{se(!1)}}},[L,e,be?.defaultBranchSha,t,_,o,V,c,he]),Dt=l.useCallback(async()=>{if(!d?.prCreate){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}const Ke=P.trim();if(!Ke){q.error(c("gitView.pr.toast.titleRequired"));return}const xt=V.trim();if(!xt){q.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!he&&xt===e){q.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}ae(!0);try{const kt=Ed(r),Tt=he&&be,ss=await d.prCreate({directory:t,title:Ke,head:e,base:xt,...N.trim()?{body:N}:{},draft:M,...Tt?{targetRepo:{owner:be.owner,repo:be.repo},headRemote:"origin"}:{...Ne?{remote:Ne.name}:{},...kt&&kt!==Ne?.name?{headRemote:kt}:{}}});q.success(c("gitView.pr.toast.prCreated")),E(Ie,at=>at&&{...at,pr:ss}),await At({force:!0}),We()}catch(kt){const Tt=kt instanceof Error?kt.message:String(kt);q.error(c("gitView.pr.toast.createPrFailed"),{description:Tt})}finally{ae(!1)}},[N,e,be,t,M,d,Ie,At,We,Ne,V,P,r,E,he,c]),wt=l.useCallback(async Ke=>{if(!d?.prMerge){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}F(!0);try{const xt=await d.prMerge({directory:t,number:Ke.number,method:B});xt.merged?q.success(c("gitView.pr.toast.prMerged")):q.message(c("gitView.pr.toast.prNotMerged"),{description:xt.message||c("gitView.pr.notMergeable")}),await At({force:!0}),We()}catch(xt){const kt=xt instanceof Error?xt.message:String(xt);q.error(c("gitView.pr.toast.mergeFailed"),{description:kt}),Ke.url&&lc(Ke.url)}finally{F(!1)}},[t,d,B,At,We,c]),Jt=l.useCallback(async Ke=>{if(!d?.prReady){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}Q(!0);try{await d.prReady({directory:t,number:Ke.number}),q.success(c("gitView.pr.toast.markedReady")),await At({force:!0}),We()}catch(xt){const kt=xt instanceof Error?xt.message:String(xt);q.error(c("gitView.pr.toast.markReadyFailed"),{description:kt}),Ke.url&&lc(Ke.url)}finally{Q(!1)}},[t,d,At,We,c]),_t=l.useCallback(async Ke=>{if(!d?.prUpdate){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}const xt=ue.trim();if(!xt){q.error(c("gitView.pr.toast.titleRequired"));return}xe(!0);try{const kt=await d.prUpdate({directory:t,number:Ke.number,title:xt,body:W});E(Ie,Tt=>Tt&&{...Tt,pr:{...Tt.pr??Ke,...kt}}),K(!1),q.success(c("gitView.pr.toast.prUpdated")),await At({force:!0}),We()}catch(kt){const Tt=kt instanceof Error?kt.message:String(kt);q.error(c("gitView.pr.toast.updatePrFailed"),{description:Tt})}finally{xe(!1)}},[t,W,ue,d,Ie,At,We,E,c]);if(!G)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pullRequest.availableOnFeatureBranches")})]})});const Fs=ge?.repo?.url||null,ft=he&&be?.url?be.url:Fs,ds=ge?.checks??null,Qt=!!ge?.canMerge,ks=!!ge?.connected,_s=m&&ge?.connected===!1,J=bj(ge),pt=J?`var(--pr-${J})`:"var(--status-info)",jt=J==="draft"?"git-pr-draft":J==="merged"?"git-merge":J==="closed"?"git-close-pull-request":"git-pull-request",Wt=Ue?[`${Ue.state}${Ue.draft?" (draft)":""}`,Ue.mergeable===!1?c("gitView.pr.notMergeable"):null,Ue.state==="open"&&typeof Ue.mergeableState=="string"&&Ue.mergeableState&&Ue.mergeableState!=="unknown"?Ue.mergeableState:null].filter(Boolean).join(" · "):"",es=ds?ds.total>0?`${ds.success}/${ds.total} ${c("gitView.pr.checks.label")}`:`${ds.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:[Ue?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{lc(Ue.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(C,{name:jt,className:"size-4 shrink-0",style:{color:pt}})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(C,{name:jt,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")}),Ue?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",Ue.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[De?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:De,onClick:()=>{At({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(C,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.refresh")})})]})]})]}),Ue?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:Wt}),ds?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${xj(ds.state)}`}),es]}):null,r&&Ne&&r.split("/")[0]!==Ne.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",Ne.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[_s?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(ve,{variant:"outline",size:"sm",onClick: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(ve,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:ft,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(C,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!Ue&&!de&&!U&&!_s?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}),c("gitView.pr.checkingStatus")]}):Ue?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:[re?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ut,{value:ue,onChange:Ke=>je(Ke.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x}),s.jsx(vn,{value:W,onChange:Ke=>me(Ke.target.value),className:"min-h-[120px] bg-background/80",placeholder:c("gitView.pr.placeholder.description"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:Ue.title}),Ue.body?.trim()?s.jsx(Ia,{content:Ue.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(Et?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),Qt&&Ue.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,Qt?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:[Ue.state==="open"?re?s.jsxs(s.Fragment,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{K(!1),je(Ue.title||""),me(Ue.body||"")},disabled:ne,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(C,{name:"close",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>_t(Ue),disabled:ne||!ue.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:ne?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"check",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.savePr")})})]})]}):s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>K(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(C,{name:"edit",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,ds?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Gt,disabled:He,"aria-label":c("gitView.pr.actions.openChecksAria"),children:He?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"information",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,ds?.failure?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:gs,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(C,{name:"error-warning",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:ts,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(C,{name:"chat-4",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.openComments")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:us,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(C,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),Qt&&Ue.draft&&Ue.state==="open"?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Jt(Ue),disabled:z||te||ne||re,"aria-label":c("gitView.pr.actions.markReadyAria"),children:z?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:Qt?s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:B,onValueChange:Ke=>H(Ke),disabled:te||Ue.state!=="open",children:[s.jsx(hs,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(ys,{})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"squash",children:c("gitView.pr.mergeMethod.squash")}),s.jsx(Ft,{value:"merge",children:c("gitView.pr.mergeMethod.merge")}),s.jsx(Ft,{value:"rebase",children:c("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>wt(Ue),disabled:te||z||Ue.state!=="open"||Ue.draft||ne||re,"aria-label":c("gitView.pr.actions.mergePrAria"),children:te?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"git-merge",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.mergePr")})})]})]}):null})]})]})}):s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",V," ",s.jsxs("span",{className:"opacity-60",children:["(",he&&be?"upstream":"remote",")"]})]})]}),ft?s.jsx(ve,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:ft,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(C,{name:"external-link",className:"size-4"}),c("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.title")}),s.jsx(Ut,{value:P,onChange:Ke=>k(Ke.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.baseBranch")}),Ee.length>0?s.jsxs(ps,{value:V,onValueChange:$,children:[s.jsx(hs,{className:"h-9",children:s.jsx(ys,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(fs,{children:Ee.map(Ke=>s.jsx(Ft,{value:Ke,children:Ke},Ke))})]}):s.jsx(Ut,{value:V,onChange:Ke=>$(Ke.target.value),placeholder:c("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.description")}),s.jsx(vn,{value:N,onChange:Ke=>T(Ke.target.value),className:"min-h-[110px]",placeholder:c("gitView.pr.placeholder.whatChanged"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":M,onClick:()=>R(Ke=>!Ke),onKeyDown:Ke=>{(Ke.key===" "||Ke.key==="Enter")&&(Ke.preventDefault(),R(xt=>!xt))},children:[s.jsx(bs,{size:"sm",checked:M,onChange:Ke=>R(Ke),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),v?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>Pe(!0),children:L.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),L.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:c("gitView.pr.additionalContext.added")})})]}):s.jsxs(cr,{open:X,onOpenChange:ce,children:[s.jsxs(jr,{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:X?c("gitView.pr.actions.hide"):L.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(dr,{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(vn,{value:L,onChange:Ke=>O(Ke.target.value),className:"min-h-[100px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(Dr,{open:ee,onClose:()=>Pe(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(ve,{size:"sm",onClick:()=>Pe(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(vn,{value:L,onChange:Ke=>O(Ke.target.value),className:"min-h-[200px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ve,{variant:"outline",size:"sm",onClick:Rt,disabled:_||oe,children:[_?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"ai-generate-2",className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(ve,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Dt,disabled:oe||!ks||!V.trim()||!he&&V.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:oe?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(ws,{open:_e,onOpenChange:Z,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(Ss,{children:[s.jsxs(js,{className:"flex items-center gap-2",children:[s.jsx(C,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.checkDetails.title")]}),s.jsx(Rs,{children:Ue?c("gitView.pr.numberLabel",{number:Ue.number}):c("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[He?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,He?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(ie?.checkRuns)&&ie?.checkRuns.length>0?ie.checkRuns.map((Ke,xt)=>{const kt=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${Ke.name}:${xt}`;return s.jsx("div",{className:"p-1",children:ls(Ke)},kt)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(ws,{open:tt,onOpenChange:st,children:s.jsxs(vs,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(Ss,{children:s.jsxs(js,{className:"flex items-center gap-2",children:[s.jsx(C,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.comments.title"),Ue?s.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.numberLabel",{number:Ue.number})}):null]})}),s.jsxs(Zi,{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(C,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,lt?null:s.jsx("div",{className:"space-y-4",children:Xt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Xt.map((Ke,xt)=>{const kt=(Ke.authorName||"?").charAt(0).toUpperCase(),Tt=xt===Xt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Tt?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:Ke.avatarUrl?s.jsx("img",{src:Ke.avatarUrl,alt:Ke.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:kt})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[Ke.authorName,Ke.authorLogin&&Ke.authorLogin!==Ke.authorName?` · @${Ke.authorLogin}`:""]}),Ke.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:Nt(Ke.createdAt)}):null,s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs(ve,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{xs(Ke)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(C,{name:"ai-generate-2",className:"size-3.5"}),c("gitView.pr.actions.sendToAgent")]})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Ke.context,Ke.path?` · ${Ke.path}`:"",Ke.line?`:${Ke.line}`:""]}),s.jsx(Ia,{content:ut(Ke.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Zt].filter(Boolean).join(" ")})]})]},Ke.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},Cj=t=>{const e=rt.c(150),{open:n,onOpenChange:r,conflictFiles:i,directory:a,operation:o,onAbort:c,onClearState:d}=t;let p;e[0]!==i?(p=i===void 0?[]:i,e[0]=i,e[1]=p):p=e[1];const m=p,{t:u}=mt(),f=Ht(Ij),b=Ht(Pj),h=Ca(Aj),v=Ca(Dj),x=Me(Tj),[g,w]=l.useState(!1),[y,S]=l.useState(null),[D,j]=l.useState(null);let I,A;e[2]!==a||e[3]!==n||e[4]!==u?(I=()=>{!n||!a||(w(!0),j(null),S(null),Yx(a).then(ke=>{S(ke)}).catch(ke=>{const be=ke instanceof Error?ke.message:u("gitView.conflict.loadFailed");j(be)}).finally(()=>{w(!1)}))},A=[n,a,u],e[2]=a,e[3]=n,e[4]=u,e[5]=I,e[6]=A):(I=e[5],A=e[6]),l.useEffect(I,A);let E;e[7]!==y||e[8]!==a||e[9]!==o?(E=async()=>{if(!y)return null;const ke=o==="merge"?"merge":"rebase",be=y.headInfo||(o==="merge"?"MERGE_HEAD":"REBASE_HEAD"),fe=o==="merge"?"git commit --no-edit":"git rebase --continue",Te=await En("git.conflict.resolve.visible",{operation_label:ke,head_ref:be}),Ve=await En("git.conflict.resolve.instructions",{operation_label:ke,directory:a,operation:o,head_info:y.headInfo||"N/A",continue_cmd:fe}),G=`${ke} conflict context (JSON)
|
|
10
|
-
${JSON.stringify({directory:a,operation:y.operation,headInfo:y.headInfo,statusPorcelain:y.statusPorcelain,unmergedFiles:y.unmergedFiles,diff:y.diff},null,2)}`;return{visibleText:Te,instructionsText:Ve,payloadText:G}},e[7]=y,e[8]=a,e[9]=o,e[10]=E):E=e[10];const P=E;let k;e[11]!==c||e[12]!==r?(k=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=k):k=e[13];const N=k;let T;e[14]!==d||e[15]!==r?(T=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=T):T=e[16];const M=T;let R;e[17]!==P||e[18]!==b||e[19]!==d||e[20]!==r||e[21]!==x||e[22]!==h||e[23]!==v||e[24]!==u?(R=async()=>{const ke=await P();if(!ke){q.error(u("gitView.conflict.noDetailsAvailable"));return}if(!b){q.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}h(ke.visibleText,"replace"),v([{text:ke.instructionsText,synthetic:!0},{text:ke.payloadText,synthetic:!0}]),x("chat"),d?.(),r(!1)},e[17]=P,e[18]=b,e[19]=d,e[20]=r,e[21]=x,e[22]=h,e[23]=v,e[24]=u,e[25]=R):R=e[25];const L=R;let O;e[26]!==P||e[27]!==a||e[28]!==d||e[29]!==r||e[30]!==f||e[31]!==x||e[32]!==u?(O=async()=>{const ke=await P();if(!ke){q.error(u("gitView.conflict.noDetailsAvailable"));return}f({directoryOverride:a,initialPrompt:ke.visibleText,syntheticParts:[{text:ke.instructionsText,synthetic:!0},{text:ke.payloadText,synthetic:!0}]}),x("chat"),d?.(),r(!1)},e[26]=P,e[27]=a,e[28]=d,e[29]=r,e[30]=f,e[31]=x,e[32]=u,e[33]=O):O=e[33];const V=O;let $,B,H,_,se,oe,ae,ne,xe,te,F,z,Q,re,K,le,Se,ue,je,W,me,X;if(e[34]!==y||e[35]!==m||e[36]!==b||e[37]!==N||e[38]!==M||e[39]!==L||e[40]!==V||e[41]!==g||e[42]!==D||e[43]!==r||e[44]!==n||e[45]!==o||e[46]!==u){const ke=u(o==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),be=y?.unmergedFiles||m;H=ws,me=n,X=r,B=vs,W="max-w-md w-[calc(100vw-2rem)]",re="flex flex-col gap-4 overflow-hidden";let fe;e[69]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(C,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=fe):fe=e[69];const Te=s.jsxs("div",{className:"flex items-center gap-2",children:[fe,s.jsx(js,{children:u("gitView.conflict.detectedTitle",{operation:ke})})]});let Ve;e[70]!==o||e[71]!==u?(Ve=u("gitView.conflict.detectedDescription",{operation:o}),e[70]=o,e[71]=u,e[72]=Ve):Ve=e[72];let G;e[73]!==Ve?(G=s.jsx(Rs,{children:Ve}),e[73]=Ve,e[74]=G):G=e[74],e[75]!==Te||e[76]!==G?(K=s.jsxs(Ss,{children:[Te,G]}),e[75]=Te,e[76]=G,e[77]=K):K=e[77],e[78]!==g||e[79]!==u?(le=g&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:u("gitView.conflict.loading")})]}),e[78]=g,e[79]=u,e[80]=le):le=e[80],e[81]!==D||e[82]!==u?(Se=D&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:u("gitView.conflict.errorLoadingDetails",{message:D})}),e[81]=D,e[82]=u,e[83]=Se):Se=e[83],e[84]!==be||e[85]!==u?(ue=be.length>0&&s.jsxs("div",{className:"space-y-2 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:be.length})]}),s.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:s.jsx("ul",{className:"space-y-1",children:be.map(Mj)})})]}),e[84]=be,e[85]=u,e[86]=ue):ue=e[86],e[87]!==y||e[88]!==u?(je=y?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:y.headInfo})]}),e[87]=y,e[88]=u,e[89]=je):je=e[89],F="flex flex-col gap-2 pt-2";let Ie;e[90]!==V?(Ie=()=>{V()},e[90]=V,e[91]=Ie):Ie=e[91];const Oe=g||!y;let De;e[92]!==g?(De=g?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"add",className:"size-4"}),e[92]=g,e[93]=De):De=e[93];let ge;e[94]!==u?(ge=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=ge):ge=e[95],e[96]!==Ie||e[97]!==Oe||e[98]!==De||e[99]!==ge?(z=s.jsxs(ve,{variant:"default",onClick:Ie,disabled:Oe,className:"w-full gap-2",children:[De,ge]}),e[96]=Ie,e[97]=Oe,e[98]=De,e[99]=ge,e[100]=z):z=e[100];let U;e[101]!==L?(U=()=>{L()},e[101]=L,e[102]=U):U=e[102];const de=g||!y||!b;let Ee;e[103]!==g?(Ee=g?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"chat-1",className:"size-4"}),e[103]=g,e[104]=Ee):Ee=e[104];let _e;e[105]!==u?(_e=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=_e):_e=e[106],e[107]!==U||e[108]!==de||e[109]!==Ee||e[110]!==_e?(Q=s.jsxs(ve,{variant:"outline",onClick:U,disabled:de,className:"w-full gap-2",children:[Ee,_e]}),e[107]=U,e[108]=de,e[109]=Ee,e[110]=_e,e[111]=Q):Q=e[111],xe="flex gap-2 pt-1";let Z;e[112]!==u?(Z=u("gitView.conflict.continueLater"),e[112]=u,e[113]=Z):Z=e[113],e[114]!==M||e[115]!==Z?(te=s.jsx(ve,{variant:"ghost",size:"sm",onClick:M,className:"flex-1",children:Z}),e[114]=M,e[115]=Z,e[116]=te):te=e[116],$=ve,_="destructive",se="sm",oe=N,ae="flex-1",ne=u("gitView.conflict.abortOperation",{operation:ke}),e[34]=y,e[35]=m,e[36]=b,e[37]=N,e[38]=M,e[39]=L,e[40]=V,e[41]=g,e[42]=D,e[43]=r,e[44]=n,e[45]=o,e[46]=u,e[47]=$,e[48]=B,e[49]=H,e[50]=_,e[51]=se,e[52]=oe,e[53]=ae,e[54]=ne,e[55]=xe,e[56]=te,e[57]=F,e[58]=z,e[59]=Q,e[60]=re,e[61]=K,e[62]=le,e[63]=Se,e[64]=ue,e[65]=je,e[66]=W,e[67]=me,e[68]=X}else $=e[47],B=e[48],H=e[49],_=e[50],se=e[51],oe=e[52],ae=e[53],ne=e[54],xe=e[55],te=e[56],F=e[57],z=e[58],Q=e[59],re=e[60],K=e[61],le=e[62],Se=e[63],ue=e[64],je=e[65],W=e[66],me=e[67],X=e[68];let ce;e[117]!==$||e[118]!==_||e[119]!==se||e[120]!==oe||e[121]!==ae||e[122]!==ne?(ce=s.jsx($,{variant:_,size:se,onClick:oe,className:ae,children:ne}),e[117]=$,e[118]=_,e[119]=se,e[120]=oe,e[121]=ae,e[122]=ne,e[123]=ce):ce=e[123];let ee;e[124]!==xe||e[125]!==te||e[126]!==ce?(ee=s.jsxs("div",{className:xe,children:[te,ce]}),e[124]=xe,e[125]=te,e[126]=ce,e[127]=ee):ee=e[127];let Pe;e[128]!==F||e[129]!==z||e[130]!==Q||e[131]!==ee?(Pe=s.jsxs("div",{className:F,children:[z,Q,ee]}),e[128]=F,e[129]=z,e[130]=Q,e[131]=ee,e[132]=Pe):Pe=e[132];let Ne;e[133]!==re||e[134]!==K||e[135]!==le||e[136]!==Se||e[137]!==ue||e[138]!==je||e[139]!==Pe?(Ne=s.jsxs("div",{className:re,children:[K,le,Se,ue,je,Pe]}),e[133]=re,e[134]=K,e[135]=le,e[136]=Se,e[137]=ue,e[138]=je,e[139]=Pe,e[140]=Ne):Ne=e[140];let Y;e[141]!==B||e[142]!==W||e[143]!==Ne?(Y=s.jsx(B,{className:W,children:Ne}),e[141]=B,e[142]=W,e[143]=Ne,e[144]=Y):Y=e[144];let he;return e[145]!==H||e[146]!==me||e[147]!==X||e[148]!==Y?(he=s.jsx(H,{open:me,onOpenChange:X,children:Y}),e[145]=H,e[146]=me,e[147]=X,e[148]=Y,e[149]=he):he=e[149],he};function Ij(t){return t.openNewSessionDraft}function Pj(t){return t.currentSessionId}function Aj(t){return t.setPendingInputText}function Dj(t){return t.setPendingSyntheticParts}function Tj(t){return t.setActiveMainTab}function Mj(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const Ej=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:i})=>{const{t:a}=mt(),[o,c]=l.useState(!0),[d,p]=l.useState(!1),m=a(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{p(!0);try{await i(o),e(!1)}catch(b){const h=b instanceof Error?b.message:`Failed to ${n}`;q.error(h)}finally{p(!1)}},f=()=>{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(Ss,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(js,{children:a("gitView.stash.title")})]}),s.jsx(Rs,{children:a("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:a("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:a("gitView.stash.stepStash")}),s.jsxs("li",{children:[a(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",a(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),o&&s.jsx("li",{children:a("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:a("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&c(!o),children:a("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(Gs,{className:"gap-2",children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:f,disabled:d,children:a("gitView.common.cancel")}),s.jsx(ve,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.common.processing")]}):a("gitView.stash.confirmButton",{operation:m})})]})]})})},Rj=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:i,hasUnresolvedConflicts:a=!1,isLoading:o=!1})=>{const{t:c}=mt(),[d,p]=l.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),f=m?"merge":u?"rebase":null;if(!f)return null;const b=async()=>{p("continue");try{await n()}finally{p(null)}},h=async()=>{p("abort");try{await r()}finally{p(null)}},v=d!==null,x=c(f==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),g=f==="merge"?"git-merge":"git-branch";let w="";return t?w=t.message?c("gitView.operation.mergingMessage",{message:t.message}):c("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(w=e.headName?c("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):c("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(C,{name:g,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:c("gitView.operation.inProgressTitle",{operation:x})}),w&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:w})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a&&i&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:i,disabled:v||o,className:"gap-1.5",children:[s.jsx(C,{name:"sparkling",className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(ve,{variant:"ghost",size:"sm",onClick:h,disabled:v||o,className:"gap-1.5",children:[d==="abort"?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"close",className:"size-4"}),c("gitView.operation.abort")]}),!a&&s.jsxs(ve,{variant:"default",size:"sm",onClick:b,disabled:v||o,className:"gap-1.5",children:[d==="continue"?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"check",className:"size-4"}),c("gitView.operation.continue")]})]}),a&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:c("gitView.operation.resolveConflictsHint")})]})})},Fj=t=>{const e=rt.c(104),{currentBranch:n,localBranches:r,remoteBranches:i,onMerge:a,onRebase:o,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:f}=t,b=c===void 0?!1:c,h=d===void 0?!1:d,v=p===void 0?[]:p,x=u===void 0?"dialog":u,{t:g}=mt(),[w,y]=l.useState(!1),[S,D]=l.useState("merge"),[j,I]=l.useState(null),[A,E]=l.useState(!1),[P,k]=l.useState(""),N=l.useRef(null),T=l.useRef(null),M=b||h,R=n||g("gitView.branch.currentBranchFallback"),L=v.length>0&&v.every(Lj),O=v.some(Oj);let V;e[0]===Symbol.for("react.memo_cache_sentinel")?(V=()=>{T.current&&(T.current.scrollTop=T.current.scrollHeight)},e[0]=V):V=e[0],l.useEffect(V,[v]);let $;if(e[1]!==P||e[2]!==n||e[3]!==r||e[4]!==i){e:{const U=P.toLowerCase();let de;e[6]!==i?(de=new Set(i.map($j).filter(Boolean)),e[6]=i,e[7]=de):de=e[7];const Ee=de;let _e;e[8]!==n||e[9]!==Ee?(_e=ie=>ie!==n&&!Ee.has(ie),e[8]=n,e[9]=Ee,e[10]=_e):_e=e[10];const Z=r.filter(_e);if(!U){$=Z;break e}$=Z.filter(ie=>ie.toLowerCase().includes(U))}e[1]=P,e[2]=n,e[3]=r,e[4]=i,e[5]=$}else $=e[5];const B=$;let H;if(e[11]!==P||e[12]!==i){e:{const U=P.toLowerCase();if(!U){H=i;break e}H=i.filter(de=>de.toLowerCase().includes(U))}e[11]=P,e[12]=i,e[13]=H}else H=e[13];const _=H;let se;e[14]!==f||e[15]!==r||e[16]!==i?(se=()=>f&&(i.includes(f)||r.includes(f))?f:null,e[14]=f,e[15]=r,e[16]=i,e[17]=se):se=e[17];const oe=se;let ae;e[18]!==oe||e[19]!==y?(ae=()=>{y(!0),I(oe()),D("merge"),k("")},e[18]=oe,e[19]=y,e[20]=ae):ae=e[20];const ne=ae;let xe;e[21]===Symbol.for("react.memo_cache_sentinel")?(xe=U=>{I(U),E(!1),k("")},e[21]=xe):xe=e[21];const te=xe;let F;e[22]!==a||e[23]!==o||e[24]!==S||e[25]!==j?(F=()=>{j&&(S==="merge"?a(j):o(j))},e[22]=a,e[23]=o,e[24]=S,e[25]=j,e[26]=F):F=e[26];const z=F;let Q;e[27]!==h||e[28]!==y?(Q=()=>{h||(I(null),D("merge"),k(""),y(!1))},e[27]=h,e[28]=y,e[29]=Q):Q=e[29];const re=Q,K=()=>{h&&!L||(L&&m?.(),I(null),D("merge"),k(""),y(!1))};let le,Se;e[30]!==A?(le=()=>{A||k("")},Se=[A],e[30]=A,e[31]=le,e[32]=Se):(le=e[31],Se=e[32]),l.useEffect(le,Se);let ue,je;e[33]!==x||e[34]!==oe||e[35]!==j?(ue=()=>{x!=="inline"||j||I(oe())},je=[x,oe,j],e[33]=x,e[34]=oe,e[35]=j,e[36]=ue,e[37]=je):(ue=e[36],je=e[37]),l.useEffect(ue,je);const X=h?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:T,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:v.map(Bj)})}),L?x==="dialog"?s.jsx(Gs,{children:s.jsx(ve,{variant:"default",size:"sm",onClick:K,children:g(O?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(ve,{variant:"default",size:"sm",onClick:K,children:g(O?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:g("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>D("merge"),className: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(C,{name:"git-merge",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:()=>D("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(C,{name:"git-branch",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:R}):g("gitView.branch.branchToRebaseOnto")}),s.jsxs(Bs,{open:A,onOpenChange:E,modal:!1,children:[s.jsx(Os,{asChild:!0,children:s.jsxs(ve,{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(C,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx($s,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(Aa,{className:"h-full min-h-0",children:[s.jsx(ra,{ref:N,placeholder:g("gitView.branch.searchPlaceholder"),value:P,onValueChange:k,onKeyDown:_j}),s.jsxs(Da,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(Ta,{children:g("gitView.branch.empty")}),B.length>0&&s.jsx(Bn,{heading:g("gitView.branch.localBranches"),children:B.map(U=>s.jsx(Pn,{onSelect:()=>te(U),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:U})},`local-${U}`))}),B.length>0&&_.length>0?s.jsx(ya,{}):null,_.length>0&&s.jsx(Bn,{heading:g("gitView.branch.remoteBranches"),children:_.map(U=>s.jsx(Pn,{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:R})]}):s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})," ",g("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})]})})}):null,x==="dialog"?s.jsxs(Gs,{className:"gap-2 pt-1",children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:re,children:g("gitView.common.cancel")}),s.jsx(ve,{variant:"default",size:"sm",onClick:z,disabled:!j,className:"gap-1.5",children:S==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"git-merge",className:"size-4"}),g("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"git-branch",className:"size-4"}),g("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ve,{variant:"destructive",size:"sm",onClick:re,disabled:M,children:g("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(ve,{variant:"default",size:"sm",onClick:z,disabled:M||!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 Ee;e[42]!==g?(Ee=g("gitView.branch.updateDescriptionPrefix"),e[42]=g,e[43]=Ee):Ee=e[43];let _e;e[44]!==R?(_e=s.jsx("span",{className:"font-mono text-foreground",children:R}),e[44]=R,e[45]=_e):_e=e[45];let Z;e[46]!==Ee||e[47]!==_e?(Z=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Ee," ",_e,"."]}),e[46]=Ee,e[47]=_e,e[48]=Z):Z=e[48];let ie;e[49]!==de||e[50]!==Z?(ie=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[de,Z]})}),e[49]=de,e[50]=Z,e[51]=ie):ie=e[51];let Ce;e[52]!==X?(Ce=s.jsx("div",{className:"pt-3",children:X}),e[52]=X,e[53]=Ce):Ce=e[53];let He;return e[54]!==ie||e[55]!==Ce?(He=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[ie,Ce]}),e[54]=ie,e[55]=Ce,e[56]=He):He=e[56],He}let ce;e[57]!==h?(ce=h?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"git-merge",className:"size-4"}),e[57]=h,e[58]=ce):ce=e[58];let ee;e[59]!==g?(ee=g("gitView.branch.mergeRebase"),e[59]=g,e[60]=ee):ee=e[60];let Pe;e[61]!==ee?(Pe=s.jsx("span",{children:ee}),e[61]=ee,e[62]=Pe):Pe=e[62];let Ne;e[63]!==ne||e[64]!==M||e[65]!==ce||e[66]!==Pe?(Ne=s.jsx(It,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ne,disabled:M,children:[ce,Pe]})}),e[63]=ne,e[64]=M,e[65]=ce,e[66]=Pe,e[67]=Ne):Ne=e[67];let Y;e[68]!==g?(Y=g("gitView.branch.mergeRebaseTooltip"),e[68]=g,e[69]=Y):Y=e[69];let he;e[70]!==Y?(he=s.jsx(Pt,{sideOffset:8,children:Y}),e[70]=Y,e[71]=he):he=e[71];let ke;e[72]!==Ne||e[73]!==he?(ke=s.jsxs(Ct,{children:[Ne,he]}),e[72]=Ne,e[73]=he,e[74]=ke):ke=e[74];let be;e[75]!==K||e[76]!==y?(be=U=>{U?y(!0):K()},e[75]=K,e[76]=y,e[77]=be):be=e[77];let fe;e[78]!==g?(fe=g("gitView.branch.updateTitle"),e[78]=g,e[79]=fe):fe=e[79];let Te;e[80]!==fe?(Te=s.jsx(js,{children:fe}),e[80]=fe,e[81]=Te):Te=e[81];let Ve;e[82]!==O||e[83]!==h||e[84]!==S||e[85]!==L||e[86]!==g||e[87]!==R?(Ve=h?g(L?O?"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:R}),"."]}),e[82]=O,e[83]=h,e[84]=S,e[85]=L,e[86]=g,e[87]=R,e[88]=Ve):Ve=e[88];let G;e[89]!==Ve?(G=s.jsx(Rs,{children:Ve}),e[89]=Ve,e[90]=G):G=e[90];let Ie;e[91]!==Te||e[92]!==G?(Ie=s.jsxs(Ss,{children:[Te,G]}),e[91]=Te,e[92]=G,e[93]=Ie):Ie=e[93];let Oe;e[94]!==X||e[95]!==Ie?(Oe=s.jsxs(vs,{className:"max-w-md",children:[Ie,X]}),e[94]=X,e[95]=Ie,e[96]=Oe):Oe=e[96];let De;e[97]!==w||e[98]!==be||e[99]!==Oe?(De=s.jsx(ws,{open:w,onOpenChange:be,children:Oe}),e[97]=w,e[98]=be,e[99]=Oe,e[100]=De):De=e[100];let ge;return e[101]!==ke||e[102]!==De?(ge=s.jsxs(s.Fragment,{children:[ke,De]}),e[101]=ke,e[102]=De,e[103]=ge):ge=e[103],ge};function Lj(t){return t.status==="done"||t.status==="error"}function Oj(t){return t.status==="error"}function $j(t){return t.slice(t.indexOf("/")+1)}function Bj(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(C,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(C,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(C,{name:"close",className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className: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 _j(t){return t.stopPropagation()}const im="oc.git.actionTab",Vj=t=>t==="commit"||t==="branch"||t==="pr",jf="gitmojiCache",zj=1e3*60*60*24*7,Nf="1",Uj=40,Wj=20,Kj="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",om={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Sf=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Hj=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(jf);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==Nf||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Sf),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Gj=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:Nf};localStorage.setItem(jf,JSON.stringify(e))}catch{return}},qj=t=>Date.now()-t.fetchedAt<zj,Jj=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,i=n.match(r);if(i){const c=i[1],d=om[c];if(d)return e.find(p=>p.code===d)||null}const a=n.split(" ")[0],o=om[a];return o&&e.find(c=>c.code===o)||null},lm=new Map,da=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),kf=()=>{const{t}=mt(),{git:e}=_n(),n=Or(),[r,i]=l.useState(null),[a,o]=l.useState(!1),c=Ht(Le=>Le.currentSessionId),d=Ht(Le=>Le.newSessionDraft),p=Ht(Le=>Le.setDraftBootstrapPendingDirectory),m=Ht(Le=>Le.worktreeMetadata),u=Ht(Le=>Le.availableWorktrees),f=da(n),b=l.useMemo(()=>{if(!f)return;const Le=u.find(Ze=>da(Ze.path)===f);if(Le)return Le;for(const Ze of m.values())if(da(Ze.path)===f)return Ze},[u,f,m]),h=l.useMemo(()=>{if(c)return m.get(c)??b;if(d?.open)return b},[c,b,d?.open,m]),{profiles:v,globalIdentity:x,defaultGitIdentityId:g,loadProfiles:w,loadGlobalIdentity:y,loadDefaultGitIdentityId:S}=Gn(mr(Le=>({profiles:Le.profiles,globalIdentity:Le.globalIdentity,defaultGitIdentityId:Le.defaultGitIdentityId,loadProfiles:Le.loadProfiles,loadGlobalIdentity:Le.loadGlobalIdentity,loadDefaultGitIdentityId:Le.loadDefaultGitIdentityId}))),D=Mh(n??null),j=wl(n??null),I=Sh(Le=>c?Le.getAttachment(c):void 0),A=I?Xx(I):[],E=I&&!I.degraded&&!I.legacy?I.worktreeRoot??void 0:void 0,P=dw(n,h,j?.current??void 0),k=jd(n??null),N=Zx(n??null),T=eb(n??null),M=Eh(n??null),R=tb(n??null),L=on(Le=>Le.setActiveDirectory),O=on(Le=>Le.fetchAll),V=on(Le=>Le.ensureAll),$=on(Le=>Le.fetchStatus),B=on(Le=>Le.fetchBranches),H=on(Le=>Le.fetchLog),_=on(Le=>Le.fetchIdentity),se=on(Le=>Le.prefetchDiffs),oe=on(Le=>Le.setLogMaxCount),ae=Me(Le=>Le.isMobile),ne=Me(Le=>Le.openContextDiff),xe=Me(Le=>Le.navigateToDiff),te=Me(Le=>Le.setRightSidebarOpen),F=l.useRef(null);l.useEffect(()=>{if(!n){i(null),o(!1);return}let Le=!1,Ze=null;const et=async()=>{try{const ct=await nb(n);if(Le)return;i(ct.status),ct.status==="pending"&&(Ze=window.setTimeout(()=>{et()},500))}catch{Le||i(null)}};return et(),()=>{Le=!0,Ze!==null&&window.clearTimeout(Ze)}},[n]),l.useEffect(()=>{const Le=F.current;F.current=r,!(!n||!e)&&(Le==="pending"&&r==="ready"&&(o(!0),O(n,e).finally(()=>{window.setTimeout(()=>{o(!1)},1200)})),r==="failed"&&(p(null),o(!1)))},[n,O,e,p,r]);const z=da(d?.bootstrapPendingDirectory??null),Q=!!(n&&z&&z===da(n)),K=!!(n&&(r==="pending"||Q))||a,le=l.useMemo(()=>n?lm.get(n)??null:null,[n]),Se=yt(Le=>Le.settingsGitmojiEnabled),[ue,je]=l.useState(null);l.useEffect(()=>{const Le=E||P?.projectDirectory;if(!Le){je(null);return}let Ze=!1;return eo(Le).then(et=>{if(Ze)return;const ct=et.trim();je(ct&&ct!=="HEAD"?ct:null)}).catch(()=>{Ze||je(null)}),()=>{Ze=!0}},[E,P?.projectDirectory]);const[W,me]=l.useState(le?.commitMessage??""),[X,ce]=l.useState([]),[ee,Pe]=l.useState(!1),Ne=l.useRef(null),[Y,he]=l.useState(null),[ke,be]=l.useState(!1),[fe,Te]=l.useState(null),[Ve,G]=l.useState(25),[Ie,Oe]=l.useState(!1),{triggerFireworks:De}=aw(),ge=l.useRef(new Map),U=l.useRef(0),de=l.useCallback(()=>{U.current+=1,Oe(!0)},[]),Ee=l.useCallback(()=>{U.current=Math.max(0,U.current-1),U.current===0&&Oe(!1)},[]),[_e,Z]=l.useState(()=>new Set(le?.selectedPaths??[])),[ie,Ce]=l.useState(!1),[He,Ge]=l.useState(new Set),[Xe,we]=l.useState(!1),[tt,st]=l.useState(0),[qe,it]=l.useState(!1),[lt,ye]=l.useState(le?.generatedHighlights??[]),Je=l.useCallback(()=>{const Le=Ne.current;Le&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Le.scrollTo({top:Le.scrollHeight,behavior:"smooth"})})})},[]),Be=E||P?.projectDirectory||null,ze=j?.current||null,nt=l.useMemo(()=>{const Le=j?.tracking;return Le?Le.startsWith("origin/"):!0},[j?.tracking]),Ye=l.useMemo(()=>{const Le=P?.createdFromBranch,Ze=typeof Le=="string"?Le.trim():"",et=typeof j?.current=="string"?j.current.trim():"",ct=typeof ue=="string"?ue.trim():"";return Ze?Ze===et&&Ze.startsWith("opencode/")&&ct.length>0&&ct!==Ze?ct:Ze:ct||et||"HEAD"},[P?.createdFromBranch,j,ue]),Ue=l.useCallback(()=>{ye([])},[]),[vt,Et]=l.useState(new Set),[Gt,ts]=l.useState(new Map),[Nt,St]=l.useState(new Set),[Zt,ut]=l.useState(null),[Xt,as]=l.useState(null),[Bt,ls]=l.useState([]),[gs,us]=l.useState(""),[xs,At]=l.useState(!1),We=l.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(C,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(C,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(C,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[Rt,Dt]=l.useState(()=>{if(typeof window>"u")return"commit";const Le=window.localStorage.getItem(im);return Le==="worktree"?"branch":Vj(Le)?Le:"commit"}),[wt,Jt]=l.useState([]),[_t,Fs]=l.useState(null),[ft,ds]=l.useState(null),[Qt,ks]=l.useState([]),[_s,J]=l.useState(!1),[pt,jt]=l.useState([]),[Wt,es]=l.useState("merge"),ns=l.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Cs=l.useCallback((Le,Ze,et)=>{if(!ns||typeof window>"u")return;const ct={directory:Le,conflictFiles:Ze,operation:et};window.localStorage.setItem(ns,JSON.stringify(ct))},[ns]),Is=l.useCallback(()=>{!ns||typeof window>"u"||window.localStorage.removeItem(ns)},[ns]);l.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(im,Rt)},[Rt]),l.useEffect(()=>{if(!ns||typeof window>"u"||!n)return;const Le=window.localStorage.getItem(ns);if(Le)try{const Ze=JSON.parse(Le);if(Ze.directory!==n){window.localStorage.removeItem(ns);return}jt(Ze.conflictFiles??[]),es(Ze.operation??"merge"),J(!0)}catch{window.localStorage.removeItem(ns)}},[ns,n]);const[Ke,xt]=l.useState(!1),[kt,Tt]=l.useState("merge"),[ss,at]=l.useState(""),Lt=l.useCallback(Le=>{Rn(Le).then(Ze=>{if(Ze.ok){q.success(t("gitView.toast.commitHashCopied"));return}q.error(t("gitView.toast.copyFailed"))})},[t]),os=l.useCallback(Le=>{Et(Ze=>{const et=new Set(Ze);return et.has(Le)?et.delete(Le):et.add(Le),et})},[]);l.useEffect(()=>{if(!n||!e)return;const Le=Array.from(vt).filter(Ze=>!Gt.has(Ze)&&!Nt.has(Ze));if(Le.length!==0){St(Ze=>{const et=new Set(Ze);for(const ct of Le)et.add(ct);return et});for(const Ze of Le)e.getCommitFiles(n,Ze).then(et=>{ts(ct=>new Map(ct).set(Ze,et.files))}).catch(et=>{console.error("Failed to fetch commit files:",et),ts(ct=>new Map(ct).set(Ze,[]))}).finally(()=>{St(et=>{const ct=new Set(et);return ct.delete(Ze),ct})})}},[vt,n,e,Gt,Nt]),l.useEffect(()=>{n&&lm.set(n,{directory:n,selectedPaths:Array.from(_e),commitMessage:W,generatedHighlights:lt})},[W,n,_e,lt]),l.useEffect(()=>{w(),y(),S()},[w,y,S]),l.useEffect(()=>{if(!n||!e?.getRemoteUrl){as(null);return}e.getRemoteUrl(n).then(as).catch(()=>as(null))},[n,e]);const rs=l.useCallback(async()=>{if(!n||!e?.getRemotes){Jt([]);return}try{const Le=await e.getRemotes(n);Jt(Le)}catch{Jt([])}},[n,e]);l.useEffect(()=>{rs()},[rs]),l.useEffect(()=>{if(!Se){ls([]);return}let Le=!1;const Ze=Hj();return Ze&&(ls(Ze.gitmojis),qj(Ze))?()=>{Le=!0}:((async()=>{try{const ct=await fetch(Kj);if(!ct.ok)throw new Error(`Failed to load gitmojis: ${ct.statusText}`);const Ot=await ct.json(),Kt=Array.isArray(Ot.gitmojis)?Ot.gitmojis.filter(Sf):[];Le||(ls(Kt),Gj(Kt))}catch(ct){Le||console.warn("Failed to load gitmoji list:",ct)}})(),()=>{Le=!0})},[Se]),l.useEffect(()=>{n&&(L(n),V(n,e))},[n,L,V,e]),l.useEffect(()=>{if(n)return vr.onGitRefreshHint(Le=>{da(Le.directory)===da(n)&&$(n,e)})},[n,$,e]);const Vt=l.useCallback(async(Le=!0)=>{if(n)try{await Promise.all([$(n,e),B(n,e)])}catch(Ze){if(Le){const et=Ze instanceof Error?Ze.message:t("gitView.toast.refreshRepositoryFailed");q.error(et)}}},[n,e,$,B,t]),cs=l.useCallback(async()=>{n&&await H(n,e,Ve)},[n,e,H,Ve]),sn=l.useCallback(async()=>{n&&await _(n,e)},[n,e,_]);l.useEffect(()=>{if(!n||!e?.hasLocalIdentity||D!==!0)return;const Le=typeof g=="string"?g.trim():"";if(!Le||Le==="global"||ge.current.get(n)===Le)return;let et=!1;return(async()=>{try{const Ot=await e.hasLocalIdentity?.(n);if(et||Ot===!0)return;de(),await e.setGitIdentity(n,Le),ge.current.set(n,Le),await sn()}catch(Ot){console.warn("Failed to auto-apply default git identity:",Ot)}finally{et||Ee()}})(),()=>{et=!0}},[de,n,g,Ee,e,D,sn]);const Js=l.useMemo(()=>{if(!j)return[];const Le=j.files??[],Ze=new Map;for(const et of Le)Ze.set(et.path,et);return Array.from(Ze.values()).sort((et,ct)=>et.path.localeCompare(ct.path))},[j]);l.useEffect(()=>{if(!n||Js.length===0)return;const Le=[],Ze=new Set,et=Ot=>{!Ot||Ze.has(Ot)||(Ze.add(Ot),Le.push(Ot))};if(Array.from(_e).forEach(et),X.forEach(et),Js.slice(0,Wj).forEach(Ot=>et(Ot.path)),Le.length===0)return;const ct=window.setTimeout(()=>{se(n,e,Le,{maxFiles:Uj})},120);return()=>{window.clearTimeout(ct)}},[Js,n,e,se,_e,X]),l.useEffect(()=>{if(!j||Js.length===0){Z(new Set),Ce(!1);return}Z(Le=>{const Ze=new Set,et=Le??new Set;for(const ct of Js)et.has(ct.path)?Ze.add(ct.path):ie||Ze.add(ct.path);return Ze})},[j,Js,ie]);const Us=async(Le,Ze)=>{if(n){he(Le);try{const et=ct=>{const Ot=`${ct.name}/`,Kt=j?.tracking?.startsWith(Ot)?j.tracking.slice(Ot.length):void 0;return{remote:ct.name,branch:Kt,rebase:!0}};if(Le==="fetch"){if(!Ze)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:Ze.name}),q.success(t("gitView.toast.fetchedFromRemote",{name:Ze.name}))}else if(Le==="pull"){if(!Ze)throw new Error("No remote available for pull");const ct=await e.gitPull(n,et(Ze));q.success(ct.files.length===1?t("gitView.toast.pulledFilesSingle",{count:ct.files.length,name:Ze.name}):t("gitView.toast.pulledFilesPlural",{count:ct.files.length,name:Ze.name}))}else if(Le==="push")await e.gitPush(n),q.success(t("gitView.toast.pushedToUpstream"));else if(Le==="sync"){if(!Ze)throw new Error("No remote available for sync");let ct=0,Ot=!1;await e.gitFetch(n,{remote:Ze.name});const Kt=await e.getGitStatus(n);if((Kt.behind??0)>0){if((Kt.files?.length??0)>0){q.error(t("gitView.toast.commitOrStashBeforeSync"));return}ct=(await e.gitPull(n,et(Ze))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Ot=!0),ct>0&&Ot?q.success(ct===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:ct,name:Ze.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:ct,name:Ze.name})):ct>0?q.success(ct===1?t("gitView.toast.pulledFilesSingle",{count:ct,name:Ze.name}):t("gitView.toast.pulledFilesPlural",{count:ct,name:Ze.name})):Ot?q.success(t("gitView.toast.pushedToUpstream")):q.success(t("gitView.toast.alreadyUpToDate"))}await Vt(!1),await cs()}catch(et){const ct=et instanceof Error?et.message:t("gitView.toast.syncActionFailed",{action:Le==="sync"?t("gitView.sync.syncChanges"):Le==="pull"?t("gitView.sync.pull"):Le});q.error(ct)}finally{he(null)}}},ln=l.useCallback(async Le=>{if(!n)return;const Ze=Le.name.trim();if(!Ze){q.error(t("gitView.toast.remoteNameRequired"));return}if(Ze==="origin"){q.error(t("gitView.toast.cannotRemoveOriginRemote"));return}Fs(Ze);try{await e.removeRemote(n,{remote:Ze}),q.success(t("gitView.toast.removedRemote",{name:Ze})),await Promise.all([Vt(!1),rs()])}catch(et){const ct=et instanceof Error?et.message:`Failed to remove ${Ze}`;q.error(ct)}finally{Fs(null)}},[n,e,rs,Vt,t]),nn=async(Le={})=>{if(!n)return;if(!W.trim()){q.error(t("gitView.toast.enterCommitMessage"));return}const Ze=Array.from(_e).sort();if(Ze.length===0){q.error(t("gitView.toast.selectFileToCommit"));return}const et=Le.pushAfter?"commitAndPush":"commit";Te(et);try{if(await e.createGitCommit(n,W.trim(),{files:Ze}),q.success(t("gitView.toast.commitCreated")),me(""),Z(new Set),Ce(!1),Ue(),await Vt(),Le.pushAfter){he("sync");const ct=j?.tracking?.split("/")[0],Ot=Tn.find(_a=>_a.name===ct)??Tn[0];if(!Ot)throw new Error("No remote available for sync");const Kt=`${Ot.name}/`,zs=j?.tracking?.startsWith(Kt)?j.tracking.slice(Kt.length):void 0;let mn=0,Zn=!1;await e.gitFetch(n,{remote:Ot.name}),((await e.getGitStatus(n)).behind??0)>0&&(mn=(await e.gitPull(n,{remote:Ot.name,branch:zs,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Zn=!0),mn>0&&Zn?q.success(mn===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:mn,name:Ot.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:mn,name:Ot.name})):mn>0?q.success(mn===1?t("gitView.toast.pulledFilesSingle",{count:mn,name:Ot.name}):t("gitView.toast.pulledFilesPlural",{count:mn,name:Ot.name})):Zn?q.success(t("gitView.toast.pushedToUpstream")):q.success(t("gitView.toast.alreadyUpToDate")),De(),await Vt(!1)}else await Vt(!1);await cs(),st(ct=>ct+1)}catch(ct){const Ot=ct instanceof Error?ct.message:t("gitView.toast.createCommitFailed");q.error(Ot)}finally{Te(null),Le.pushAfter&&he(null)}},cn=l.useCallback(async()=>{if(n){if(_e.size===0){q.error(t("gitView.toast.selectFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:_e.size}),it(!0);try{const{message:Le}=await sb(n,Array.from(_e)),Ze=Le.subject?.trim()??"",et=Array.isArray(Le.highlights)?Le.highlights:[];if(Ze){let ct=Ze;if(Se&&Bt.length>0){const Ot=Jj(Ze,Bt);if(Ot){const{code:Kt,emoji:zs}=Ot;!Ze.startsWith(Kt)&&!Ze.startsWith(zs)&&(ct=`${Kt} ${Ze}`)}}me(ct)}ye(et),Je()}catch(Le){console.error("[git-generation][browser] GitView generate handler failed",{message:Le instanceof Error?Le.message:String(Le),error:Le});const Ze=Le instanceof Error?Le.message:t("gitView.toast.generateCommitMessageFailed");q.error(Ze)}finally{it(!1)}}},[n,_e,Se,Bt,Je,t]),un=Le=>Le.reason==="attention"?`${Le.attentionReason} in progress`:Le.reason==="missing"?"worktree is missing":"worktree is invalid",jn=async(Le,Ze)=>{if(!n||!j)return;const et=Vl(I);if(et.length>0){q.error(t("gitView.toast.cannotCreateBranch",{reason:un(et[0])}));return}const ct=j.current??null,Ot=Ze?.name??"origin";try{await e.createBranch(n,Le,ct??"HEAD"),q.success(t("gitView.toast.createdBranch",{name:Le})),await e.checkoutBranch(n,Le);let Kt=!1;try{await e.gitPush(n,{remote:Ot,branch:Le,options:["--set-upstream"]}),Kt=!0}catch(zs){const mn=zs instanceof Error?zs.message:`Unable to push new branch to ${Ot}.`;q.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",mn]})})}await Vt(),await cs(),Kt&&q.success(t("gitView.toast.upstreamSet",{branch:Le,remote:Ot}))}catch(Kt){const zs=Kt instanceof Error?Kt.message:t("gitView.toast.createBranchFailed");throw q.error(zs),Kt}},an=async(Le,Ze)=>{if(!n)return;const et=Vl(I);if(et.length>0){q.error(t("gitView.toast.cannotRenameBranch",{reason:un(et[0])}));return}try{await e.renameBranch(n,Le,Ze),q.success(t("gitView.toast.renamedBranch",{oldName:Le,newName:Ze})),await Vt(),await cs()}catch(ct){const Ot=ct instanceof Error?ct.message:t("gitView.toast.renameBranchFailed",{oldName:Le,newName:Ze});q.error(Ot)}},gn=async Le=>{if(!n)return;const Ze=Vl(I);if(Ze.length>0){q.error(t("gitView.toast.cannotCheckout",{reason:un(Ze[0])}));return}const et=Le.replace(/^remotes\//,"");if(j?.current!==et)try{await e.checkoutBranch(n,et),q.success(t("gitView.toast.checkedOut",{name:et})),await Vt(),await cs()}catch(ct){const Ot=ct instanceof Error?ct.message:t("gitView.toast.checkoutFailed",{name:et});q.error(Ot)}},pr=async Le=>{if(n){de();try{await e.setGitIdentity(n,Le.id),q.success(t("gitView.toast.appliedIdentity",{name:Le.name})),await sn()}catch(Ze){const et=Ze instanceof Error?Ze.message:t("gitView.toast.applyIdentityFailed");q.error(et)}finally{Ee()}}},Fn=l.useMemo(()=>k?.all?k.all.filter(Le=>!Le.startsWith("remotes/")).sort():[],[k]),Dn=l.useMemo(()=>k?.all?k.all.filter(Le=>Le.startsWith("remotes/")).map(Le=>Le.replace(/^remotes\//,"")).sort():[],[k]),Tn=l.useMemo(()=>{if(wt.length>0)return wt;const Le=new Set,Ze=j?.tracking?.trim();Ze&&Ze.includes("/")&&Le.add(Ze.split("/")[0]);for(const et of Dn){const ct=et.indexOf("/");ct>0&&Le.add(et.slice(0,ct))}return Le.size===0&&Xt&&Le.add("origin"),Array.from(Le).map(et=>({name:et,fetchUrl:Xt??"",pushUrl:Xt??""}))},[wt,Dn,Xt,j?.tracking]),Fe=l.useMemo(()=>{const Le=new Set(Tn.map(Ot=>Ot.name)),Ze=Ot=>{if(!Ot)return"";let Kt=Ot.trim();if(!Kt||Kt==="HEAD")return"";if(Fn.includes(Kt))return Kt;Kt.startsWith("refs/heads/")&&(Kt=Kt.slice(11)),Kt.startsWith("heads/")&&(Kt=Kt.slice(6)),Kt.startsWith("remotes/")&&(Kt=Kt.slice(8));const zs=Kt.indexOf("/");if(zs>0){const mn=Kt.slice(0,zs);if(Le.has(mn)){const Zn=Kt.slice(zs+1).trim();Zn&&(Kt=Zn)}}return Kt},et=Ze(typeof P?.createdFromBranch=="string"?P.createdFromBranch:"");if(et)return et;const ct=Ze(typeof ue=="string"?ue:"");return ct||(Fn.includes("main")?"main":Fn.includes("master")?"master":Fn.includes("develop")?"develop":"main")},[Tn,Fn,ue,P?.createdFromBranch]),Mt=l.useMemo(()=>Tn.map(et=>et.name).map(et=>`${et}/${Fe}`).find(et=>Dn.includes(et))??Fe,[Fe,Tn,Dn]),is=l.useMemo(()=>{const Le=new Map;x&&Le.set(x.id,x);let Ze=null;if(Xt)try{let et=Xt.trim();et.startsWith("git@")&&(et=`https://${et.slice(4).replace(":","/")}`),et.endsWith(".git")&&(et=et.slice(0,-4));const ct=new URL(et);Ze=ct.hostname+ct.pathname}catch{}for(const et of v){if(et.authType!=="token"){Le.set(et.id,et);continue}const ct=et.host;if(!ct){Le.set(et.id,et);continue}if(!ct.includes("/")){Le.set(et.id,et);continue}Ze&&Ze===ct&&Le.set(et.id,et)}return Array.from(Le.values())},[v,x,Xt]),ms=l.useMemo(()=>{if(T?.userName&&T?.userEmail){const Le=v.find(Ze=>Ze.userName===T.userName&&Ze.userEmail===T.userEmail);return Le||(x&&x.userName===T.userName&&x.userEmail===T.userEmail?x:{id:"local-config",name:T.userName,userName:T.userName,userEmail:T.userEmail,sshKey:T.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return x??null},[T,v,x]),qs=_e.size,Vs=M||Y!==null||fe!==null,Ds=j?.current??null,Xs=!!(P&&Be&&ze&&nt),hn=!!(n&&Ds),tr=!!Ds,Sn=Xs&&Be&&ze&&P?{repoRoot:Be,sourceBranch:ze,worktreeMetadata:P}:null,Mr=l.useMemo(()=>!hn||!n||!Ds?null:{directory:n,branch:Ds},[hn,Ds,n]);l.useEffect(()=>{if(!n||!e||!N?.all?.length||!Ds||!Fe||Ds===Fe){ut(null);return}let Le=!1;return(async()=>{try{const et=await e.getGitLog(n,{from:Fe,to:"HEAD",maxCount:Ve});if(Le)return;const ct=new Set((et?.all??[]).map(Kt=>Kt.hash).filter(Kt=>typeof Kt=="string"&&Kt.length>0));if(ct.size===0){ut(null);return}const Ot=N.all.findIndex(Kt=>!ct.has(Kt.hash));if(Ot===0){ut(null);return}if(Ot===-1){ut({insertBeforeIndex:N.all.length,branchName:Ds,direction:"up"});return}ut({insertBeforeIndex:Ot,branchName:Ds,direction:"up"})}catch{Le||ut(null)}})(),()=>{Le=!0}},[Fe,Ds,n,e,N,Ve]);const Sr=Le=>{Z(Ze=>{const et=new Set(Ze);return et.has(Le)?et.delete(Le):et.add(Le),et}),Ce(!0)},kr=()=>{const Le=new Set(Js.map(Ze=>Ze.path));Z(Le),Ce(!0)},Zs=()=>{Z(new Set),Ce(!0)},Yn=l.useCallback(async Le=>{if(n){Ge(Ze=>{const et=new Set(Ze);return et.add(Le),et});try{await e.revertGitFile(n,Le),q.success(t("gitView.toast.revertedFile",{path:Le})),await Vt(!1)}catch(Ze){const et=Ze instanceof Error?Ze.message:t("gitView.toast.revertFailed");q.error(et)}finally{Ge(Ze=>{const et=new Set(Ze);return et.delete(Le),et})}}},[n,Vt,e,t]),kn=l.useCallback(async Le=>{if(!n||Le.length===0||Xe)return;const Ze=Array.from(new Set(Le));we(!0),Ge(ct=>{const Ot=new Set(ct);return Ze.forEach(Kt=>Ot.add(Kt)),Ot});const et=[];try{if(await Promise.all(Ze.map(async ct=>{try{await e.revertGitFile(n,ct)}catch(Ot){et.push({path:ct,message:Ot instanceof Error?Ot.message:t("gitView.toast.revertFailed")})}})),await Vt(!1),et.length===0)q.success(Ze.length===1?t("gitView.toast.revertedFilesSingle",{count:Ze.length}):t("gitView.toast.revertedFilesPlural",{count:Ze.length}));else if(et.length===Ze.length)q.error(et[0]?.message||t("gitView.toast.revertFailed"));else{const ct=Ze.length-et.length;q.warning(ct===1?t("gitView.toast.revertedSomeSingle",{success:ct,failed:et.length}):t("gitView.toast.revertedSomePlural",{success:ct,failed:et.length}))}}finally{Ge(ct=>{const Ot=new Set(ct);return Ze.forEach(Kt=>Ot.delete(Kt)),Ot}),we(!1)}},[n,e,Xe,Vt,t]),Xn=l.useCallback(Le=>{if(Le.length===0)return;const Ze=Le.map(et=>et.trim()).filter(Boolean);if(Ze.length===0){Ue();return}me(et=>{const ct=et.trim(),Ot=ct.length>0?`
|
|
11
|
-
|
|
12
|
-
`:"";return`${ct}${Ot}${Ze.join(`
|
|
13
|
-
`)}`.trim()}),Ue()},[Ue]),hr=l.useCallback((Le,Ze)=>{const et=Ze||Le;me(ct=>{const Ot=ct.trimStart();return Ot.startsWith(Le)||Ze&&Ot.startsWith(Ze)?ct:`${et.endsWith(" ")?et:`${et} `}${ct}`.trimStart()}),us(""),Pe(!1)},[]),Er=l.useCallback(Le=>{G(Le),n&&(oe(n,Le),H(n,e,Le))},[n,oe,H,e]),fr=l.useCallback(Le=>{const Ze=Le instanceof Error?Le.message.toLowerCase():"";return Ze.includes("uncommitted changes")||Ze.includes("local changes")||Ze.includes("your local changes would be overwritten")||Ze.includes("please commit your changes or stash them")||Ze.includes("cannot rebase: you have unstaged changes")||Ze.includes("error: cannot pull with rebase")},[]),Ln=l.useCallback((Le,Ze)=>{ks(et=>[...et,{message:Le,status:Ze,timestamp:Date.now()}])},[]),fn=l.useCallback((Le,Ze)=>{ks(et=>{if(et.length===0)return et;const ct=[...et];return ct[ct.length-1]={...ct[ct.length-1],status:Le,...Ze?{message:Ze}:{}},ct})},[]),en=l.useCallback(()=>{ks([])},[]),gr=l.useCallback(()=>{ks([]),ds(null)},[]),Rr=l.useCallback(Le=>{const Ze=Le.trim(),et=new Set(Tn.map(Ot=>Ot.name)),ct=Ze.indexOf("/");if(ct>0){const Ot=Ze.slice(0,ct),Kt=Ze.slice(ct+1);if(et.has(Ot)&&Kt)return{branch:Ze,remote:Ot,remoteBranch:Kt}}for(const Ot of Tn){const Kt=`${Ot.name}/${Ze}`;if(Dn.includes(Kt))return{branch:Kt,remote:Ot.name,remoteBranch:Ze}}return{branch:Ze,remote:null,remoteBranch:null}},[Tn,Dn]),Ra=l.useCallback(async Le=>{if(!n)return;ds("merge"),en();const Ze=j?.current,et=Rr(Le);try{et.remote&&et.remoteBranch&&(Ln(`Fetching ${et.remote}/${et.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:et.remote,branch:et.remoteBranch}),fn("done",`Fetched ${et.remote}/${et.remoteBranch}`)),Ln(`Merging ${et.branch} into ${Ze}...`,"running");const ct=await e.merge(n,{branch:et.branch});ct.conflict?(fn("error","Merge conflicts detected"),jt(ct.conflictFiles??[]),es("merge"),J(!0),Cs(n,ct.conflictFiles??[],"merge")):(fn("done",`Merged ${et.branch} into ${Ze}`),Is(),Ln("Refreshing repository status...","running"),await Vt(),await cs(),fn("done","Repository status updated"))}catch(ct){if(fr(ct))fn("error","Uncommitted changes detected"),Tt("merge"),at(et.branch),xt(!0);else{const Ot=ct instanceof Error?ct.message:`Failed to merge ${et.branch}`;fn("error",Ot)}}},[n,e,j,Rr,Vt,cs,fr,Cs,Is,Ln,fn,en]),Hr=l.useCallback(async Le=>{if(!n)return;ds("rebase"),en();const Ze=j?.current,et=Rr(Le);try{et.remote&&et.remoteBranch&&(Ln(`Fetching ${et.remote}/${et.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:et.remote,branch:et.remoteBranch}),fn("done",`Fetched ${et.remote}/${et.remoteBranch}`)),Ln(`Rebasing ${Ze} onto ${et.branch}...`,"running");const ct=await e.rebase(n,{onto:et.branch});ct.conflict?(fn("error","Rebase conflicts detected"),jt(ct.conflictFiles??[]),es("rebase"),J(!0),Cs(n,ct.conflictFiles??[],"rebase")):(fn("done",`Rebased ${Ze} onto ${et.branch}`),Is(),Ln("Refreshing repository status...","running"),await Vt(),await cs(),fn("done","Repository status updated"))}catch(ct){if(fr(ct))fn("error","Uncommitted changes detected"),Tt("rebase"),at(et.branch),xt(!0);else{const Ot=ct instanceof Error?ct.message:`Failed to rebase onto ${et.branch}`;fn("error",Ot)}}},[n,e,j,Rr,Vt,cs,fr,Cs,Is,Ln,fn,en]),Fa=l.useCallback(async()=>{if(n)try{Wt==="merge"?(await e.abortMerge(n),q.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),q.success(t("gitView.toast.rebaseAborted"))),Is(),await Vt(),await cs()}catch(Le){const Ze=Le instanceof Error?Le.message:`Failed to abort ${Wt}`;q.error(Ze)}},[n,e,Wt,Vt,cs,Is,t]),Nn=l.useMemo(()=>j?.files?j.files.some(Le=>Le.index==="U"||Le.working_dir==="U"||Le.index==="A"&&Le.working_dir==="A"||Le.index==="D"&&Le.working_dir==="D"):!1,[j?.files]),La=l.useCallback(async()=>{if(n)try{const Le=!!j?.mergeInProgress?.head,Ze=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(Le){const et=await e.continueMerge(n);et.conflict?(jt(et.conflictFiles??[]),es("merge"),J(!0),Cs(n,et.conflictFiles??[],"merge"),q.error(t("gitView.toast.mergeConflictsDetected"))):(Is(),q.success(t("gitView.toast.mergeCompleted")),await Vt(),await cs())}else if(Ze){const et=await e.continueRebase(n);et.conflict?(jt(et.conflictFiles??[]),es("rebase"),J(!0),Cs(n,et.conflictFiles??[],"rebase"),q.error(t("gitView.toast.rebaseConflictsDetected"))):(Is(),q.success(t("gitView.toast.rebaseStepCompleted")),await Vt(),await cs())}}catch(Le){const Ze=Le instanceof Error?Le.message:t("gitView.toast.continueOperationFailed");q.error(Ze)}},[n,e,j,Vt,cs,Cs,Is,t]),Oa=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"))),Is(),await Vt(),await cs()}catch(Le){const Ze=Le instanceof Error?Le.message:t("gitView.toast.abortOperationFailed");q.error(Ze)}},[n,e,j,Vt,cs,Is,t]),$a=l.useCallback(()=>{if(!n)return;const Ze=!!j?.mergeInProgress?.head?"merge":"rebase",et=j?.files?.filter(ct=>ct.index==="U"||ct.working_dir==="U").map(ct=>ct.path)??[];et.length>0&&jt(et),es(Ze),J(!0)},[n,j]),Vn=l.useCallback(async Le=>{if(!n)return;const Ze=j?.current,et=kt,ct=ss;try{await e.stash(n,{message:`Auto-stash before ${et} with ${ct}`,includeUntracked:!0})}catch(zs){const mn=zs instanceof Error?zs.message:"Failed to stash changes";q.error(mn);return}let Ot=!1,Kt=!1;try{if(et==="merge"){const zs=await e.merge(n,{branch:ct});zs.conflict?(Kt=!0,jt(zs.conflictFiles??[]),es("merge"),J(!0)):(Ot=!0,q.success(t("gitView.toast.mergedIntoBranch",{branch:ct,currentBranch:Ze||""})))}else{const zs=await e.rebase(n,{onto:ct});zs.conflict?(Kt=!0,jt(zs.conflictFiles??[]),es("rebase"),J(!0)):(Ot=!0,q.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:Ze||"",branch:ct})))}if(Le&&Ot)try{await e.stashPop(n),q.success(t("gitView.toast.stashedRestored"))}catch(zs){const mn=zs instanceof Error?zs.message:t("gitView.toast.restoreStashFailed");q.error(mn)}else Le&&Kt&&q.info(t("gitView.toast.restoreStashManually"));await Vt(),await cs()}catch(zs){if(Le)try{await e.stashPop(n)}catch{}throw zs}},[n,e,j,kt,ss,Vt,cs,t]);return n?M&&D===null?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):D===!1?K?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(C,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(C,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.notGitRepositoryDescription")}),A.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:t("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:pe("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(Aw,{status:j,localBranches:Fn,remoteBranches:Dn,branchInfo:k?.branches,syncAction:Y,remotes:Tn,onFetch:Le=>Us("fetch",Le),onSync:Le=>Us("sync",Le),onRemoveRemote:ln,removingRemoteName:_t,onCheckoutBranch:gn,onCreateBranch:jn,onRenameBranch:an,activeIdentityProfile:ms,availableIdentities:is,onSelectIdentity:pr,isApplyingIdentity:Ie,isWorktreeMode:!!P,onOpenHistory:()=>At(!0),actionTabItems:We,activeActionTab:Rt,onSelectActionTab:Le=>Dt(Le)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(Rj,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:La,onAbort:Oa,onResolveWithAI:$a,hasUnresolvedConflicts:Nn,isLoading:M}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:pe("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(As,{as:Zi,ref:Ne,outerClassName:"flex-1 min-h-0",className:pe("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[Rt==="commit"?s.jsx("div",{className:"space-y-4",children:(Js?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx(Bw,{maxListHeightClassName:"max-h-[40vh]",changeEntries:Js,onVisiblePathsChange:ce,selectedPaths:_e,diffStats:j?.diffStats,revertingPaths:He,onToggleFile:Sr,onSelectAll:kr,onClearSelection:Zs,onRevertAll:kn,onViewDiff:Le=>{if(n&&!ae){ne(n,Le);return}xe(Le),ae&&te(!1)},onRevertFile:Yn,isRevertingAll:Xe,onOpenStashes:()=>be(!0)}),s.jsx(Ww,{selectedCount:qs,commitMessage:W,onCommitMessageChange:me,generatedHighlights:lt,onInsertHighlights:Xn,onGenerateMessage:cn,isGeneratingMessage:qe,onCommit:()=>nn({pushAfter:!1}),onCommitAndPush:()=>nn({pushAfter:!0}),commitAction:fe,gitmojiEnabled:Se,onOpenGitmojiPicker:()=>Pe(!0)})]}):s.jsx(Kw,{onOpenStashes:()=>be(!0)})}):null,Rt==="branch"?s.jsx("div",{className:"space-y-4",children:tr?s.jsxs(s.Fragment,{children:[s.jsx(Fj,{mode:"inline",currentBranch:j?.current,localBranches:Fn,remoteBranches:Dn,defaultTargetBranch:Mt,onMerge:Ra,onRebase:Hr,disabled:Vs,isOperating:ft!==null,operationLogs:Qt,onOperationComplete:gr}),Sn?s.jsx(ww,{repoRoot:Sn.repoRoot,sourceBranch:Sn.sourceBranch,worktreeMetadata:Sn.worktreeMetadata,localBranches:Fn,defaultTargetBranch:Ye,refreshKey:tt,onRefresh:()=>{n&&($(n,e),B(n,e),H(n,e,Ve))}},Sn.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,Rt==="pr"?s.jsx("div",{className:"space-y-4",children:Mr?s.jsx(kj,{directory:Mr.directory,branch:Mr.branch,baseBranch:Fe,trackingBranch:j?.tracking??void 0,remotes:wt,remoteBranches:Dn,onGeneratedDescription:Je}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:t("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(ws,{open:xs,onOpenChange:At,children:s.jsxs(vs,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:t("gitView.history.title")}),s.jsx(Rs,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(Jw,{log:N,isLogLoading:R,logMaxCount:Ve,onLogMaxCountChange:Er,expandedCommitHashes:vt,onToggleCommit:os,commitFilesMap:Gt,loadingCommitHashes:Nt,onCopyHash:Lt,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Zt})})]})}),s.jsx(Dw,{open:ke,onOpenChange:be,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,uncommittedFileCount:j?.files?.length??0,onChanged:async()=>{await Vt(!1),await cs()}}),s.jsx(ws,{open:ee,onOpenChange:Pe,children:s.jsxs(vs,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(Ss,{className:"px-4 pt-4",children:s.jsx(js,{children:t("gitView.gitmoji.title")})}),s.jsxs(Aa,{className:"h-[420px]",children:[s.jsx(ra,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:gs,onValueChange:us}),s.jsxs(Da,{children:[s.jsx(Ta,{children:t("gitView.gitmoji.empty")}),s.jsx(Bn,{children:(Bt.length===0?[]:Bt.filter(Le=>{const Ze=gs.trim().toLowerCase();return Ze?Le.emoji.includes(Ze)||Le.code.toLowerCase().includes(Ze)||Le.description.toLowerCase().includes(Ze):!0})).map(Le=>s.jsxs(Pn,{onSelect:()=>hr(Le.emoji,Le.code),children:[s.jsx("span",{className:"text-lg",children:Le.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Le.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Le.description})]},Le.code))})]})]})]})}),n&&s.jsx(Cj,{open:_s,onOpenChange:J,conflictFiles:pt,directory:n,operation:Wt,onAbort:Fa,onClearState:Is}),s.jsx(Ej,{open:Ke,onOpenChange:xt,operation:kt,targetBranch:ss,onConfirm:Vn})]}):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")})})},Qj=Object.freeze(Object.defineProperty({__proto__:null,GitView:kf},Symbol.toStringTag,{value:"Module"})),Gc=5e3,Yj=(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},Xj=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"},Zj=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 i=await r.json().catch(()=>({error:r.statusText}));throw new Error(i.error||"Failed to read file")}return r.text()},Rd=async(t,e)=>{try{const n=await Zj(t,e);return Yj(n,Gc)>Gc?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:Xj(n)}}},Fd=t=>t==="too-large"?`File is too large to open (>${Gc.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",e0=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Wn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Cf=(t,e)=>{const n=Wn(e),r=Wn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},t0=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),s0=new Set(["node_modules"]),n0=t=>s0.has(t),r0=t=>{const e=Wn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},If=(t,e)=>s.jsx(yr,{filePath:t,extension:e}),a0=t=>{const e=rt.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 i=r[n];let a;return e[1]!==i?(a=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:i}}),e[1]=i,e[2]=a):a=e[2],a},i0=t=>{const e=rt.c(63),{node:n,root:r,isExpanded:i,isActive:a,status:o,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:f,onToggle:b,onRevealPath:h,onOpenDialog:v}=t,{t:x}=mt(),g=n.type==="directory",{canRename:w,canCreateFile:y,canCreateFolder:S,canDelete:D,canReveal:j}=d;let I;e[0]!==y||e[1]!==S||e[2]!==D||e[3]!==w||e[4]!==j||e[5]!==n.path||e[6]!==u?(I=oe=>{!w&&!y&&!S&&!D&&!j||(oe?.preventDefault(),u(n.path))},e[0]=y,e[1]=S,e[2]=D,e[3]=w,e[4]=j,e[5]=n.path,e[6]=u,e[7]=I):I=e[7];const A=I;let E;e[8]!==g||e[9]!==n||e[10]!==f||e[11]!==b?(E=()=>{g?b(n.path):f(n)},e[8]=g,e[9]=n,e[10]=f,e[11]=b,e[12]=E):E=e[12];const P=E;let k;e[13]!==n.path||e[14]!==u?(k=oe=>{oe.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=k):k=e[15];const N=k;let T;e[16]!==n.path||e[17]!==r?(T=oe=>{const ae=Cf(r,n.path);!ae||ae==="."||(oe.dataTransfer.setData("application/x-openchamber-file-path",ae),oe.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=T):T=e[18];const M=T,R=a?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let L;e[19]!==R?(L=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",R,"cursor-grab active:cursor-grabbing"),e[19]=R,e[20]=L):L=e[20];let O;e[21]!==g||e[22]!==i||e[23]!==n.extension||e[24]!==n.path?(O=g?i?s.jsx(C,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(C,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):If(n.path,n.extension),e[21]=g,e[22]=i,e[23]=n.extension,e[24]=n.path,e[25]=O):O=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 $;e[29]!==g||e[30]!==o?($=!g&&o&&s.jsx(a0,{status:o}),e[29]=g,e[30]=o,e[31]=$):$=e[31];let B;e[32]!==c||e[33]!==g?(B=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]=B):B=e[34];let H;e[35]!==A||e[36]!==M||e[37]!==P||e[38]!==B||e[39]!==L||e[40]!==O||e[41]!==V||e[42]!==$?(H=s.jsxs("button",{type:"button",onClick:P,onContextMenu:A,draggable:!0,onDragStart:M,className:L,children:[O,V,$,B]}),e[35]=A,e[36]=M,e[37]=P,e[38]=B,e[39]=L,e[40]=O,e[41]=V,e[42]=$,e[43]=H):H=e[43];let _;e[44]!==y||e[45]!==S||e[46]!==D||e[47]!==w||e[48]!==j||e[49]!==m||e[50]!==p||e[51]!==N||e[52]!==g||e[53]!==n||e[54]!==v||e[55]!==h||e[56]!==u||e[57]!==x?(_=(w||y||S||D||j)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(Bs,{open:m===n.path,onOpenChange:oe=>u(oe?n.path:null),children:[s.jsx(Os,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:N,children:s.jsx(C,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsxs($s,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[w&&s.jsxs(zt,{onClick:oe=>{oe.stopPropagation(),v("rename",n)},children:[s.jsx(C,{name:"edit",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.rename")]}),s.jsxs(zt,{onClick:oe=>{oe.stopPropagation(),Rn(n.path).then(ae=>{if(ae.ok){q.success(x("sidebarFilesTree.toast.pathCopied"));return}q.error(x("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(C,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.copyPath")]}),!g&&p&&s.jsxs(zt,{onClick:oe=>{oe.stopPropagation(),p(n.path)},children:[s.jsx(C,{name:"download",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.save")]}),j&&s.jsxs(zt,{onClick:oe=>{oe.stopPropagation(),h(n.path)},children:[s.jsx(C,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",x(kd())]}),g&&(y||S)&&s.jsxs(s.Fragment,{children:[s.jsx(An,{}),y&&s.jsxs(zt,{onClick:oe=>{oe.stopPropagation(),v("createFile",n)},children:[s.jsx(C,{name:"file-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFile")]}),S&&s.jsxs(zt,{onClick:oe=>{oe.stopPropagation(),v("createFolder",n)},children:[s.jsx(C,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFolder")]})]}),D&&s.jsxs(s.Fragment,{children:[s.jsx(An,{}),s.jsxs(zt,{onClick:oe=>{oe.stopPropagation(),v("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=y,e[45]=S,e[46]=D,e[47]=w,e[48]=j,e[49]=m,e[50]=p,e[51]=N,e[52]=g,e[53]=n,e[54]=v,e[55]=h,e[56]=u,e[57]=x,e[58]=_):_=e[58];let se;return e[59]!==A||e[60]!==H||e[61]!==_?(se=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:A,children:[H,_]}),e[59]=A,e[60]=H,e[61]=_,e[62]=se):se=e[62],se},o0=()=>{const t=rt.c(240),{t:e}=mt(),{files:n,runtime:r}=_n(),i=Or()??"";let a;t[0]!==i?(a=Wn(i.trim()),t[0]=i,t[1]=a):a=t[1];const o=a,c=jl(),d=Nd(),p=Sd(l0),m=Me(c0),u=wl(i),[f,b]=l.useState(""),h=Nl(f,200),v=l.useRef(null);let x;t[2]===Symbol.for("react.memo_cache_sentinel")?(x=[],t[2]=x):x=t[2];const[g,w]=l.useState(x),[y,S]=l.useState(!1);let D;t[3]===Symbol.for("react.memo_cache_sentinel")?(D={},t[3]=D):D=t[3];const[j,I]=l.useState(D);let A;t[4]===Symbol.for("react.memo_cache_sentinel")?(A=new Set,t[4]=A):A=t[4];const E=l.useRef(A);let P;t[5]===Symbol.for("react.memo_cache_sentinel")?(P=new Set,t[5]=P):P=t[5];const k=l.useRef(P);let N;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=[],t[6]=N):N=t[6];const T=N;let M;t[7]===Symbol.for("react.memo_cache_sentinel")?(M=[],t[7]=M):M=t[7];const R=M;let L;t[8]!==o?(L=J=>o?J.byRoot[o]?.expandedPaths??T:T,t[8]=o,t[9]=L):L=t[9];const O=$n(L);let V;t[10]!==o?(V=J=>o?J.byRoot[o]?.selectedPath??null:null,t[10]=o,t[11]=V):V=t[11];const $=$n(V),B=$n(d0),H=$n(u0),_=$n(m0),se=$n(p0);let oe;t[12]!==o?(oe=J=>o?J.contextPanelByDirectory[o]?.tabs??R:R,t[12]=o,t[13]=oe):oe=t[13];const ae=Me(oe);let ne;t[14]!==ae?(ne=new Set(ae.map(h0).filter(f0).map(g0)),t[14]=ae,t[15]=ne):ne=t[15];const xe=ne,[te,F]=l.useState(null),[z,Q]=l.useState(null),[re,K]=l.useState(null),[le,Se]=l.useState(""),[ue,je]=l.useState(!1),W=!!n.writeFile,me=!!n.createDirectory,X=!!n.rename,ce=!!n.delete,ee=!!n.revealPath;let Pe;t[16]!==W||t[17]!==me||t[18]!==ce||t[19]!==X||t[20]!==ee?(Pe={canRename:X,canCreateFile:W,canCreateFolder:me,canDelete:ce,canReveal:ee},t[16]=W,t[17]=me,t[18]=ce,t[19]=X,t[20]=ee,t[21]=Pe):Pe=t[21];const Ne=Pe;let Y;t[22]!==n||t[23]!==e?(Y=J=>{n.revealPath&&n.revealPath(J).catch(()=>{q.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=Y):Y=t[24];const he=Y;let ke;t[25]===Symbol.for("react.memo_cache_sentinel")?(ke=(J,pt)=>{Q(J),K(pt),Se(J==="rename"&&pt.name||""),je(!1)},t[25]=ke):ke=t[25];const be=ke;let fe;t[26]!==d||t[27]!==c?(fe=(J,pt)=>{const jt=pt.filter(x0).filter(Wt=>c||!Wt.name.startsWith(".")).filter(Wt=>d||!n0(Wt.name)).map(Wt=>{const es=Wt.name,ns=Wn(Wt.path||""),Cs=ns?t0(ns)?ns:Wn(`${J}/${ns}`):Wn(`${J}/${es}`),Is=Wt.isDirectory?"directory":"file",Ke=Is==="file"&&es.includes(".")?es.split(".").pop()?.toLowerCase():void 0;return{name:es,path:Cs,type:Is,extension:Ke}});return e0(jt)},t[26]=d,t[27]=c,t[28]=fe):fe=t[28];const Te=fe;let Ve;t[29]!==n||t[30]!==Te||t[31]!==r.isDesktop||t[32]!==d?(Ve=async J=>{const pt=Wn(J.trim());if(!pt||E.current.has(pt)||k.current.has(pt))return;k.current=new Set(k.current),k.current.add(pt);const jt=!d;await(r.isDesktop?n.listDirectory(pt,{respectGitignore:jt}).then(y0):In.listLocalDirectory(pt,{respectGitignore:jt}).then(w0)).then(es=>{const ns=Te(pt,es);E.current=new Set(E.current),E.current.add(pt),I(Cs=>({...Cs,[pt]:ns}))}).catch(()=>{I(es=>({...es,[pt]:es[pt]??[]}))}).finally(()=>{k.current=new Set(k.current),k.current.delete(pt)})},t[29]=n,t[30]=Te,t[31]=r.isDesktop,t[32]=d,t[33]=Ve):Ve=t[33];const G=Ve;let Ie;t[34]!==G||t[35]!==o?(Ie=async()=>{o&&(E.current=new Set,k.current=new Set,I(j0),await G(o))},t[34]=G,t[35]=o,t[36]=Ie):Ie=t[36];const Oe=Ie;let De;t[37]!==G||t[38]!==Oe?(De=async J=>{if(!J){await Oe();return}const pt=Wn(J);E.current=new Set(E.current),E.current.delete(pt),k.current=new Set(k.current),k.current.delete(pt),await G(pt)},t[37]=G,t[38]=Oe,t[39]=De):De=t[39];const ge=De;let U;t[40]!==G||t[41]!==o?(U=()=>{o&&(E.current=new Set,k.current=new Set,I(N0),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 Ee,_e;t[48]!==O||t[49]!==G||t[50]!==o?(Ee=()=>{if(!o||O.length===0)return;const J=O.map(S0).filter(jt=>!!jt&&jt!==o&&jt.startsWith(`${o}/`)&&!E.current.has(jt)&&!k.current.has(jt)).sort(k0);if(J.length===0)return;let pt=!1;return(async()=>{for(let jt=0;jt<J.length&&!pt;jt=jt+3,jt){const Wt=J.slice(jt,jt+3);await Promise.all(Wt.map(es=>G(es)))}})(),()=>{pt=!0}},_e=[O,G,o],t[48]=O,t[49]=G,t[50]=o,t[51]=Ee,t[52]=_e):(Ee=t[51],_e=t[52]),l.useEffect(Ee,_e);let Z,ie;t[53]!==i||t[54]!==h||t[55]!==p||t[56]!==d||t[57]!==c?(Z=()=>{if(!i){w([]),S(!1);return}const J=h.trim();if(!J){w([]),S(!1);return}let pt=!1;return S(!0),p(i,J,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(jt=>{if(pt)return;const es=jt.filter(ns=>d||!r0(ns.path)).map(C0);w(es)}).catch(()=>{pt||w([])}).finally(()=>{pt||S(!1)}),()=>{pt=!0}},ie=[i,h,p,c,d],t[53]=i,t[54]=h,t[55]=p,t[56]=d,t[57]=c,t[58]=Z,t[59]=ie):(Z=t[58],ie=t[59]),l.useEffect(Z,ie);let Ce;t[60]!==u||t[61]!==xe||t[62]!==o?(Ce=J=>{if(xe.has(J))return"open";if(u?.files){const pt=J.startsWith(o+"/")?J.slice(o.length+1):J,jt=u.files.find(Wt=>Wt.path===pt);if(jt){if(jt.index==="A"||jt.working_dir==="?")return"git-added";if(jt.index==="D")return"git-deleted";if(jt.index==="M"||jt.working_dir==="M")return"git-modified"}}return null},t[60]=u,t[61]=xe,t[62]=o,t[63]=Ce):Ce=t[63];const He=Ce;let Ge;t[64]!==u||t[65]!==o?(Ge=J=>{if(!u?.files)return null;const pt=J.startsWith(o+"/")?J.slice(o.length+1):J,jt=pt?`${pt}/`:"";let Wt=0,es=0;for(const ns of u.files)ns.path.startsWith(jt)&&((ns.index==="M"||ns.working_dir==="M")&&Wt++,(ns.index==="A"||ns.working_dir==="?")&&es++);return Wt+es>0?{modified:Wt,added:es}:null},t[64]=u,t[65]=o,t[66]=Ge):Ge=t[66];const Xe=Ge;let we;t[67]!==H||t[68]!==n||t[69]!==m||t[70]!==o||t[71]!==B?(we=async J=>{if(!o)return;const pt=await Rd(n,J.path);if(!pt.ok){q.error(Fd(pt.reason));return}B(o,J.path),H(o,J.path),m(o,J.path)},t[67]=H,t[68]=n,t[69]=m,t[70]=o,t[71]=B,t[72]=we):we=t[72];const tt=we;let st;t[73]!==G||t[74]!==o||t[75]!==se?(st=async J=>{const pt=Wn(J);o&&(se(o,pt),E.current.has(pt)||await G(pt))},t[73]=G,t[74]=o,t[75]=se,t[76]=st):st=t[76];const qe=st;let it;t[77]!==z||t[78]!==re||t[79]!==le||t[80]!==n||t[81]!==ge||t[82]!==_||t[83]!==o||t[84]!==$||t[85]!==B||t[86]!==e?(it=async J=>{if(J?.preventDefault(),!re||!z)return;je(!0);const pt=()=>je(!1),jt=()=>Q(null);if(z==="createFile"){if(!le.trim()){q.error(e("sidebarFilesTree.toast.filenameRequired")),pt();return}if(!n.writeFile){q.error(e("sidebarFilesTree.toast.writeNotSupported")),pt();return}const Wt=re.path,es=Wt?`${Wt}/`:"",ns=Wn(`${es}${le.trim()}`);await n.writeFile(ns,"").then(async Cs=>{Cs.success&&(q.success(e("sidebarFilesTree.toast.fileCreated")),await ge(Wt)),jt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(pt);return}if(z==="createFolder"){if(!le.trim()){q.error(e("sidebarFilesTree.toast.folderNameRequired")),pt();return}const Wt=re.path,es=Wt?`${Wt}/`:"",ns=Wn(`${es}${le.trim()}`);await n.createDirectory(ns).then(async Cs=>{Cs.success&&(q.success(e("sidebarFilesTree.toast.folderCreated")),await ge(Wt)),jt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(pt);return}if(z==="rename"){if(!le.trim()){q.error(e("sidebarFilesTree.toast.nameRequired")),pt();return}if(!n.rename){q.error(e("sidebarFilesTree.toast.renameNotSupported")),pt();return}const Wt=re.path,es=Wt.split("/").slice(0,-1).join("/"),ns=es?`${es}/`:"",Cs=Wn(`${ns}${le.trim()}`);await n.rename(Wt,Cs).then(async Is=>{Is.success&&(q.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await ge(es),o&&_(o,Wt),($===Wt||$&&$.startsWith(`${Wt}/`))&&B(o,null)),jt()}).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 Wt=re.path,es=Wt.split("/").slice(0,-1).join("/");await n.delete(Wt).then(async ns=>{ns.success&&(q.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await ge(es),o&&_(o,Wt),($===Wt||$&&$.startsWith(Wt+"/"))&&B(o,null)),jt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(pt);return}pt()},t[77]=z,t[78]=re,t[79]=le,t[80]=n,t[81]=ge,t[82]=_,t[83]=o,t[84]=$,t[85]=B,t[86]=e,t[87]=it):it=t[87];const lt=it;let ye,Je,Be,ze,nt,Ye,Ue;if(t[88]!==W||t[89]!==me||t[90]!==j||t[91]!==te||t[92]!==i||t[93]!==O||t[94]!==Ne||t[95]!==n.downloadFile||t[96]!==He||t[97]!==Xe||t[98]!==tt||t[99]!==he||t[100]!==Oe||t[101]!==o||t[102]!==f||t[103]!==g||t[104]!==y||t[105]!==$||t[106]!==e||t[107]!==qe){let J=function(Lt,os){const rs=j[Lt]??[];return rs.map((Vt,cs)=>{const sn=Vt.type==="directory",Js=sn&&O.includes(Vt.path),Us=$===Vt.path,ln=cs===rs.length-1;return s.jsxs("li",{className:"relative",children:[os>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),ln&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(i0,{node:Vt,root:o,isExpanded:Js,isActive:Us,status:sn?void 0:He(Vt.path),badge:sn?Xe(Vt.path):void 0,permissions:Ne,downloadFile:n.downloadFile,contextMenuPath:te,setContextMenuPath:F,onSelect:tt,onToggle:qe,onRevealPath:he,onOpenDialog:be}),sn&&Js&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:J(Vt.path,os+1)})]},Vt.path)})};const pt=!!(o&&j[o]);Ye="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let jt;t[115]===Symbol.for("react.memo_cache_sentinel")?(jt=s.jsx(C,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[115]=jt):jt=t[115];let Wt;t[116]===Symbol.for("react.memo_cache_sentinel")?(Wt=Lt=>b(Lt.target.value),t[116]=Wt):Wt=t[116];let es;t[117]!==e?(es=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=es):es=t[118];let ns;t[119]!==f||t[120]!==es?(ns=s.jsx(Ut,{ref:v,value:f,onChange:Wt,placeholder:es,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=f,t[120]=es,t[121]=ns):ns=t[121];let Cs;t[122]!==f||t[123]!==e?(Cs=f.trim().length>0?s.jsx("button",{type:"button","aria-label":e("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{b(""),v.current?.focus()},children:s.jsx(C,{name:"close",className:"h-4 w-4"})}):null,t[122]=f,t[123]=e,t[124]=Cs):Cs=t[124];let Is;t[125]!==ns||t[126]!==Cs?(Is=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[jt,ns,Cs]}),t[125]=ns,t[126]=Cs,t[127]=Is):Is=t[127];let Ke;t[128]!==W||t[129]!==i||t[130]!==e?(Ke=W&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>be("createFile",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(C,{name:"file-add",className:"h-4 w-4"})}),t[128]=W,t[129]=i,t[130]=e,t[131]=Ke):Ke=t[131];let xt;t[132]!==me||t[133]!==i||t[134]!==e?(xt=me&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>be("createFolder",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(C,{name:"folder-add",className:"h-4 w-4"})}),t[132]=me,t[133]=i,t[134]=e,t[135]=xt):xt=t[135];let kt;t[136]!==Oe?(kt=()=>{Oe()},t[136]=Oe,t[137]=kt):kt=t[137];let Tt;t[138]!==e?(Tt=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Tt):Tt=t[139];let ss;t[140]===Symbol.for("react.memo_cache_sentinel")?(ss=s.jsx(C,{name:"refresh",className:"h-4 w-4"}),t[140]=ss):ss=t[140];let at;t[141]!==kt||t[142]!==Tt?(at=s.jsx(ve,{variant:"ghost",size:"sm",onClick:kt,className:"h-8 w-8 p-0 flex-shrink-0",title:Tt,children:ss}),t[141]=kt,t[142]=Tt,t[143]=at):at=t[143],t[144]!==Is||t[145]!==Ke||t[146]!==xt||t[147]!==at?(Ue=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[Is,Ke,xt,at]}),t[144]=Is,t[145]=Ke,t[146]=xt,t[147]=at,t[148]=Ue):Ue=t[148],ye=As,ze="flex-1 min-h-0",nt="p-2",Je="flex flex-col",Be=y?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):g.length>0?g.map(Lt=>{const os=$===Lt.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>tt(Lt),draggable:!0,onDragStart:rs=>{const Vt=Lt.relativePath||Cf(o??"",Lt.path);!Vt||Vt==="."||(rs.dataTransfer.setData("application/x-openchamber-file-path",Vt),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",os?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:Lt.path,children:[If(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?J(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=W,t[89]=me,t[90]=j,t[91]=te,t[92]=i,t[93]=O,t[94]=Ne,t[95]=n.downloadFile,t[96]=He,t[97]=Xe,t[98]=tt,t[99]=he,t[100]=Oe,t[101]=o,t[102]=f,t[103]=g,t[104]=y,t[105]=$,t[106]=e,t[107]=qe,t[108]=ye,t[109]=Je,t[110]=Be,t[111]=ze,t[112]=nt,t[113]=Ye,t[114]=Ue}else ye=t[108],Je=t[109],Be=t[110],ze=t[111],nt=t[112],Ye=t[113],Ue=t[114];let vt;t[149]!==Je||t[150]!==Be?(vt=s.jsx("ul",{className:Je,children:Be}),t[149]=Je,t[150]=Be,t[151]=vt):vt=t[151];let Et;t[152]!==ye||t[153]!==ze||t[154]!==nt||t[155]!==vt?(Et=s.jsx(ye,{outerClassName:ze,className:nt,children:vt}),t[152]=ye,t[153]=ze,t[154]=nt,t[155]=vt,t[156]=Et):Et=t[156];const Gt=!!z;let ts;t[157]===Symbol.for("react.memo_cache_sentinel")?(ts=J=>!J&&Q(null),t[157]=ts):ts=t[157];let Nt;t[158]!==z||t[159]!==e?(Nt=z==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[158]=z,t[159]=e,t[160]=Nt):Nt=t[160];let St;t[161]!==z||t[162]!==e?(St=z==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[161]=z,t[162]=e,t[163]=St):St=t[163];let Zt;t[164]!==z||t[165]!==e?(Zt=z==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[164]=z,t[165]=e,t[166]=Zt):Zt=t[166];let ut;t[167]!==z||t[168]!==e?(ut=z==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[167]=z,t[168]=e,t[169]=ut):ut=t[169];let Xt;t[170]!==Nt||t[171]!==St||t[172]!==Zt||t[173]!==ut?(Xt=s.jsxs(js,{children:[Nt,St,Zt,ut]}),t[170]=Nt,t[171]=St,t[172]=Zt,t[173]=ut,t[174]=Xt):Xt=t[174];let as;t[175]!==z||t[176]!==re?.path||t[177]!==e?(as=z==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:re?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[175]=z,t[176]=re?.path,t[177]=e,t[178]=as):as=t[178];let Bt;t[179]!==z||t[180]!==re?.path||t[181]!==e?(Bt=z==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:re?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[179]=z,t[180]=re?.path,t[181]=e,t[182]=Bt):Bt=t[182];let ls;t[183]!==z||t[184]!==re?.name||t[185]!==e?(ls=z==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:re?.name??""}),t[183]=z,t[184]=re?.name,t[185]=e,t[186]=ls):ls=t[186];let gs;t[187]!==z||t[188]!==re?.name||t[189]!==e?(gs=z==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:re?.name??""}),t[187]=z,t[188]=re?.name,t[189]=e,t[190]=gs):gs=t[190];let us;t[191]!==as||t[192]!==Bt||t[193]!==ls||t[194]!==gs?(us=s.jsxs(Rs,{children:[as,Bt,ls,gs]}),t[191]=as,t[192]=Bt,t[193]=ls,t[194]=gs,t[195]=us):us=t[195];let xs;t[196]!==Xt||t[197]!==us?(xs=s.jsxs(Ss,{children:[Xt,us]}),t[196]=Xt,t[197]=us,t[198]=xs):xs=t[198];let At;t[199]!==z||t[200]!==le||t[201]!==lt||t[202]!==e?(At=z!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Ut,{value:le,onChange:J=>Se(J.target.value),placeholder:e(z==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:J=>{J.key==="Enter"&<()},autoFocus:!0})}),t[199]=z,t[200]=le,t[201]=lt,t[202]=e,t[203]=At):At=t[203];let We;t[204]===Symbol.for("react.memo_cache_sentinel")?(We=()=>Q(null),t[204]=We):We=t[204];let Rt;t[205]!==e?(Rt=e("sidebarFilesTree.dialog.cancel"),t[205]=e,t[206]=Rt):Rt=t[206];let Dt;t[207]!==ue||t[208]!==Rt?(Dt=s.jsx(ve,{variant:"outline",onClick:We,disabled:ue,children:Rt}),t[207]=ue,t[208]=Rt,t[209]=Dt):Dt=t[209];const wt=z==="delete"?"destructive":"default";let Jt;t[210]!==lt?(Jt=()=>{lt()},t[210]=lt,t[211]=Jt):Jt=t[211];let _t;t[212]!==z||t[213]!==le||t[214]!==ue?(_t=ue||z!=="delete"&&!le.trim(),t[212]=z,t[213]=le,t[214]=ue,t[215]=_t):_t=t[215];let Fs;t[216]!==z||t[217]!==ue||t[218]!==e?(Fs=ue?s.jsx(C,{name:"loader-4",className:"animate-spin"}):e(z==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[216]=z,t[217]=ue,t[218]=e,t[219]=Fs):Fs=t[219];let ft;t[220]!==wt||t[221]!==Jt||t[222]!==_t||t[223]!==Fs?(ft=s.jsx(ve,{variant:wt,onClick:Jt,disabled:_t,children:Fs}),t[220]=wt,t[221]=Jt,t[222]=_t,t[223]=Fs,t[224]=ft):ft=t[224];let ds;t[225]!==Dt||t[226]!==ft?(ds=s.jsxs(Gs,{children:[Dt,ft]}),t[225]=Dt,t[226]=ft,t[227]=ds):ds=t[227];let Qt;t[228]!==xs||t[229]!==At||t[230]!==ds?(Qt=s.jsxs(vs,{children:[xs,At,ds]}),t[228]=xs,t[229]=At,t[230]=ds,t[231]=Qt):Qt=t[231];let ks;t[232]!==Gt||t[233]!==Qt?(ks=s.jsx(ws,{open:Gt,onOpenChange:ts,children:Qt}),t[232]=Gt,t[233]=Qt,t[234]=ks):ks=t[234];let _s;return t[235]!==Ye||t[236]!==Ue||t[237]!==Et||t[238]!==ks?(_s=s.jsxs("section",{className:Ye,children:[Ue,Et,ks]}),t[235]=Ye,t[236]=Ue,t[237]=Et,t[238]=ks,t[239]=_s):_s=t[239],_s};function l0(t){return t.searchFiles}function c0(t){return t.openContextFile}function d0(t){return t.setSelectedPath}function u0(t){return t.addOpenPath}function m0(t){return t.removeOpenPathsByPrefix}function p0(t){return t.toggleExpandedPath}function h0(t){return t.mode==="file"?t.targetPath:null}function f0(t){return typeof t=="string"&&t.length>0}function g0(t){return Wn(t)}function x0(t){return t&&typeof t.name=="string"&&t.name.length>0}function b0(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function y0(t){return t.entries.map(b0)}function v0(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function w0(t){return t.map(v0)}function j0(t){return Object.keys(t).length===0?t:{}}function N0(t){return Object.keys(t).length===0?t:{}}function S0(t){return Wn(t)}function k0(t,e){return t.split("/").length-e.split("/").length}function C0(t){return{name:t.name,path:Wn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function I0(t,e){const n=rt.c(6),{git:r}=_n(),i=on(P0);let a,o;n[0]!==t||n[1]!==i||n[2]!==r||n[3]!==e?(a=()=>{if(!t||!r||!e)return;i(t,r);const c=setInterval(()=>{typeof document<"u"&&document.hidden||i(t,r)},1e4);return()=>clearInterval(c)},o=[t,r,e,i],n[0]=t,n[1]=i,n[2]=r,n[3]=e,n[4]=a,n[5]=o):(a=n[4],o=n[5]),l.useEffect(a,o)}function P0(t){return t.ensureStatus}const A0=()=>{const t=rt.c(17),e=Es(T0),n=Es(M0),r=Ws(E0),i=on(R0);let a;e:{if(e){let h;t[0]!==e||t[1]!==n?(h=n.find(v=>v.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=h):h=t[2],a=h;break e}a=n[0]??null}const o=a;let c;e:{if(!o){c=null;break e}let h;t[3]!==o.id||t[4]!==o.path?(h={id:o.id,path:o.path},t[3]=o.id,t[4]=o.path,t[5]=h):h=t[5],c=h}const d=c;let p;e:{if(!o){p=null;break e}let h;t[6]!==o.label||t[7]!==o.path||t[8]!==r?(h=o.label?.trim()||Pa(o.path,r)||o.path,t[6]=o.label,t[7]=o.path,t[8]=r,t[9]=h):h=t[9],p=h}const m=p;let u;e:{if(!o){u=!1;break e}let h;t[10]!==o.path||t[11]!==i?(h=i.get(o.path)?.isGitRepo,t[10]=o.path,t[11]=i,t[12]=h):h=t[12],u=h===!0}const f=u;let b;return t[13]!==f||t[14]!==m||t[15]!==d?(b=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(Q1,{projectRef:d,projectLabel:m,canCreateWorktree:f})}),t[13]=f,t[14]=m,t[15]=d,t[16]=b):b=t[16],b},D0=()=>{const t=rt.c(38),{t:e}=mt(),n=Me(F0),r=Me(L0),i=Me(O0),a=Or();I0(a,i);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(C,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=c):c=t[2];let d;t[3]!==o?(d={id:"git",label:o,icon:c},t[3]=o,t[4]=d):d=t[4];let p;t[5]!==e?(p=e("layout.rightSidebar.files"),t[5]=e,t[6]=p):p=t[6];let m;t[7]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(C,{name:"folder-3",className:"h-3.5 w-3.5"}),t[7]=m):m=t[7];let u;t[8]!==p?(u={id:"files",label:p,icon:m},t[8]=p,t[9]=u):u=t[9];let f;t[10]!==e?(f=e("layout.rightSidebar.context"),t[10]=e,t[11]=f):f=t[11];let b;t[12]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(C,{name:"booklet",className:"h-3.5 w-3.5"}),t[12]=b):b=t[12];let h;t[13]!==f?(h={id:"context",label:f,icon:b},t[13]=f,t[14]=h):h=t[14];let v;t[15]!==d||t[16]!==u||t[17]!==h?(v=[d,u,h],t[15]=d,t[16]=u,t[17]=h,t[18]=v):v=t[18];const x=v;let g;t[19]!==r?(g=A=>r(A),t[19]=r,t[20]=g):g=t[20];let w;t[21]!==n||t[22]!==g||t[23]!==x?(w=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Tr,{items:x,activeId:n,onSelect:g,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=g,t[23]=x,t[24]=w):w=t[24];let y;t[25]!==n?(y=n==="git"&&s.jsx(kf,{}),t[25]=n,t[26]=y):y=t[26];let S;t[27]!==n?(S=n==="files"&&s.jsx(o0,{}),t[27]=n,t[28]=S):S=t[28];let D;t[29]!==n?(D=n==="context"&&s.jsx(A0,{}),t[29]=n,t[30]=D):D=t[30];let j;t[31]!==y||t[32]!==S||t[33]!==D?(j=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[y,S,D]}),t[31]=y,t[32]=S,t[33]=D,t[34]=j):j=t[34];let I;return t[35]!==w||t[36]!==j?(I=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]=I):I=t[37],I};function T0(t){return t.activeProjectId}function M0(t){return t.projects}function E0(t){return t.homeDirectory}function R0(t){return t.directories}function F0(t){return t.rightSidebarTab}function L0(t){return t.setRightSidebarTab}function O0(t){return t.isRightSidebarOpen}function Pf(t){const e=rt.c(63),{draft:n,onEdit:r,onDelete:i,className:a,maxWidth:o}=t,{t:c}=mt(),p=Sl()?.currentTheme,[m,u]=$e.useState(!1),f=typeof n.text=="string"?n.text:"";let b;e[0]!==f?(b=f.length>150||f.split(`
|
|
14
|
-
`).length>3,e[0]=f,e[1]=b):b=e[1];const h=b;let v;e[2]!==a?(v=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",a),e[2]=a,e[3]=v):v=e[3];const x=p?.colors?.surface?.elevated,g=p?.colors?.interactive?.border,w=o?`${Math.max(200,Math.floor(o))}px`:void 0;let y;e[4]!==x||e[5]!==g||e[6]!==w?(y={backgroundColor:x,borderColor:g,maxWidth:w},e[4]=x,e[5]=g,e[6]=w,e[7]=y):y=e[7];let 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 D;e[10]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx("span",{children:"•"}),e[10]=D):D=e[10];let j;e[11]!==n.endLine||e[12]!==n.startLine||e[13]!==c?(j=c("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[11]=n.endLine,e[12]=n.startLine,e[13]=c,e[14]=j):j=e[14];let I;e[15]!==j?(I=s.jsx("span",{children:j}),e[15]=j,e[16]=I):I=e[16];let A;e[17]!==n.side?(A=n.side&&s.jsxs("span",{children:["(",n.side,")"]}),e[17]=n.side,e[18]=A):A=e[18];let E;e[19]!==I||e[20]!==A||e[21]!==S?(E=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[S,D,I,A]}),e[19]=I,e[20]=A,e[21]=S,e[22]=E):E=e[22];const P=m||!h,k=!m&&h&&"line-clamp-3";let N;e[23]!==k?(N=pe("text-sm whitespace-pre-wrap break-words leading-relaxed",k),e[23]=k,e[24]=N):N=e[24];let T;e[25]!==f||e[26]!==N?(T=s.jsx("div",{className:N,children:f}),e[25]=f,e[26]=N,e[27]=T):T=e[27];let M;e[28]!==h||e[29]!==m||e[30]!==c?(M=h&&s.jsx(jr,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"arrow-up-s",className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"arrow-down-s",className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=h,e[29]=m,e[30]=c,e[31]=M):M=e[31];let R;e[32]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(dr,{}),e[32]=R):R=e[32];let L;e[33]!==P||e[34]!==T||e[35]!==M?(L=s.jsxs(cr,{open:P,onOpenChange:u,children:[T,M,R]}),e[33]=P,e[34]=T,e[35]=M,e[36]=L):L=e[36];let O;e[37]!==E||e[38]!==L?(O=s.jsxs("div",{className:"flex-1 min-w-0",children:[E,L]}),e[37]=E,e[38]=L,e[39]=O):O=e[39];let V;e[40]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(Os,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(C,{name:"more",className:"size-4"})})}),e[40]=V):V=e[40];let $;e[41]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(C,{name:"edit",className:"size-4 mr-2"}),e[41]=$):$=e[41];let B;e[42]!==c?(B=c("inlineComment.actions.editComment"),e[42]=c,e[43]=B):B=e[43];let H;e[44]!==r||e[45]!==B?(H=s.jsxs(zt,{onClick:r,children:[$,B]}),e[44]=r,e[45]=B,e[46]=H):H=e[46];let _;e[47]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(C,{name:"delete-bin",className:"size-4 mr-2"}),e[47]=_):_=e[47];let se;e[48]!==c?(se=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=se):se=e[49];let oe;e[50]!==i||e[51]!==se?(oe=s.jsxs(zt,{onClick:i,className:"text-destructive",children:[_,se]}),e[50]=i,e[51]=se,e[52]=oe):oe=e[52];let ae;e[53]!==H||e[54]!==oe?(ae=s.jsxs(Bs,{children:[V,s.jsxs($s,{align:"end",children:[H,oe]})]}),e[53]=H,e[54]=oe,e[55]=ae):ae=e[55];let ne;e[56]!==O||e[57]!==ae?(ne=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[O,ae]}),e[56]=O,e[57]=ae,e[58]=ne):ne=e[58];let xe;return e[59]!==v||e[60]!==ne||e[61]!==y?(xe=s.jsx("div",{className:v,style:y,"data-comment-card":"true",children:ne}),e[59]=v,e[60]=ne,e[61]=y,e[62]=xe):xe=e[62],xe}function dl(t){const e=rt.c(57),{initialText:n,onSave:r,onCancel:i,fileLabel:a,lineRange:o,isEditing:c,className:d,maxWidth:p}=t,m=n===void 0?"":n,u=c===void 0?!1:c,{t:f}=mt(),h=Sl()?.currentTheme,{isMobile:v}=rn(),[x,g]=l.useState(m),w=$e.useRef(null),y=$e.useRef(o);let S,D;e[0]!==o?(S=()=>{o&&(y.current=o)},D=[o],e[0]=o,e[1]=S,e[2]=D):(S=e[1],D=e[2]),$e.useEffect(S,D);const j=W0,I=j(o);let A,E;e[3]!==v?(A=()=>{const me=w.current;if(!me)return;const X=me.closest(".overlay-scrollbar-container"),ce=X?.scrollTop??window.scrollY,ee=X?.scrollLeft??window.scrollX;if(v){me.scrollIntoView({behavior:"auto",block:"nearest"});try{me.focus({preventScroll:!0})}catch{me.focus()}return}try{me.focus({preventScroll:!0})}catch{me.focus()}const Pe=me.value.length;try{me.setSelectionRange(Pe,Pe)}catch{}requestAnimationFrame(()=>{X?(X.scrollTop=ce,X.scrollLeft=ee):window.scrollTo({top:ce,left:ee})})},E=[v],e[3]=v,e[4]=A,e[5]=E):(A=e[4],E=e[5]),$e.useEffect(A,E);let P;e[6]!==i||e[7]!==r||e[8]!==x?(P=me=>{(me.metaKey||me.ctrlKey)&&me.key==="Enter"?(me.preventDefault(),x.trim()&&r(x,j(y.current))):me.key==="Escape"&&(me.preventDefault(),i())},e[6]=i,e[7]=r,e[8]=x,e[9]=P):P=e[9];const k=P;let N;e[10]!==r||e[11]!==x?(N=me=>{me.stopPropagation(),x.trim()&&r(x,j(y.current))},e[10]=r,e[11]=x,e[12]=N):N=e[12];const T=N;let M;e[13]!==d?(M=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]=M):M=e[14];const R=h?.colors?.surface?.elevated,L=h?.colors?.interactive?.border,O=p?`${Math.max(200,Math.floor(p))}px`:void 0;let V;e[15]!==R||e[16]!==L||e[17]!==O?(V={backgroundColor:R,borderColor:L,maxWidth:O},e[15]=R,e[16]=L,e[17]=O,e[18]=V):V=e[18];const $="true",B=U0,H=z0,_="p-3",se=(a||o)&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[a&&s.jsx("span",{className:"truncate max-w-[200px]",children:a}),a&&o&&s.jsx("span",{children:"•"}),I&&s.jsx("span",{children:f("inlineComment.range.lines",{start:I.start,end:I.end})})]});let oe;e[19]===Symbol.for("react.memo_cache_sentinel")?(oe=me=>g(me.target.value),e[19]=oe):oe=e[19];let ae;e[20]!==f?(ae=f("inlineComment.input.placeholder"),e[20]=f,e[21]=ae):ae=e[21];let ne;e[22]!==k||e[23]!==ae||e[24]!==x?(ne=s.jsx(vn,{simple:!0,ref:w,value:x,onChange:oe,onKeyDown:k,placeholder:ae,outerClassName:"rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]",className:"min-h-[80px] px-3 py-2.5 text-sm resize-y"}),e[22]=k,e[23]=ae,e[24]=x,e[25]=ne):ne=e[25];let xe;e[26]!==f?(xe=f("inlineComment.actions.cancel"),e[26]=f,e[27]=xe):xe=e[27];let te;e[28]!==i||e[29]!==xe?(te=s.jsx(ve,{variant:"ghost",size:"sm",onClick:i,onPointerDown:V0,onTouchStart:_0,className:"h-8 text-muted-foreground hover:text-foreground",children:xe}),e[28]=i,e[29]=xe,e[30]=te):te=e[30];let F;e[31]!==x?(F=x.trim(),e[31]=x,e[32]=F):F=e[32];const z=!F,Q=h?.colors?.status?.success,re=h?.colors?.status?.successForeground;let K;e[33]!==Q||e[34]!==re?(K={backgroundColor:Q,color:re},e[33]=Q,e[34]=re,e[35]=K):K=e[35];let le;e[36]!==u||e[37]!==f?(le=f(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=f,e[38]=le):le=e[38];let Se;e[39]!==T||e[40]!==z||e[41]!==K||e[42]!==le?(Se=s.jsx(ve,{size:"sm",onClick:T,onPointerDown:B0,onTouchStart:$0,disabled:z,className:"h-8 min-w-[80px]",style:K,children:le}),e[39]=T,e[40]=z,e[41]=K,e[42]=le,e[43]=Se):Se=e[43];let ue;e[44]!==te||e[45]!==Se?(ue=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[te,Se]}),e[44]=te,e[45]=Se,e[46]=ue):ue=e[46];let je;e[47]!==se||e[48]!==ne||e[49]!==ue?(je=s.jsxs("div",{className:_,children:[se,ne,ue]}),e[47]=se,e[48]=ne,e[49]=ue,e[50]=je):je=e[50];let W;return e[51]!==V||e[52]!==B||e[53]!==H||e[54]!==je||e[55]!==M?(W=s.jsx("div",{className:M,style:V,"data-comment-input":$,onPointerDown:B,onTouchStart:H,children:je}),e[51]=V,e[52]=B,e[53]=H,e[54]=je,e[55]=M,e[56]=W):W=e[56],W}function $0(t){return t.stopPropagation()}function B0(t){return t.stopPropagation()}function _0(t){return t.stopPropagation()}function V0(t){return t.stopPropagation()}function z0(t){return t.stopPropagation()}function U0(t){return t.stopPropagation()}function W0(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 K0=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},ul=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function Ld(t){const e=rt.c(40),{t:n}=mt(),{source:r,fileLabel:i,language:a,getCodeForRange:o,toStoreRange:c,fromDraftRange:d}=t,p=Ht(Y0),m=Ht(Q0),u=ei(J0),f=ei(q0),b=ei(G0),h=ei(H0),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,S]=l.useState(null),D=p??(m?"draft":null);let j;e:{if(!D||!i){let _;e[0]===Symbol.for("react.memo_cache_sentinel")?(_=[],e[0]=_):_=e[0],j=_;break e}let $;e[1]!==h||e[2]!==D?($=h[D]??[],e[1]=h,e[2]=D,e[3]=$):$=e[3];const B=$;let H;if(e[4]!==i||e[5]!==B||e[6]!==r){let _;e[8]!==i||e[9]!==r?(_=se=>se.source===r&&se.fileLabel===i,e[8]=i,e[9]=r,e[10]=_):_=e[10],H=B.filter(_),e[4]=i,e[5]=B,e[6]=r,e[7]=H}else H=e[7];j=H}const I=j;let A;e[11]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{x(null),w(""),S(null)},e[11]=A):A=e[11];const E=A;let P;e[12]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{E()},e[12]=P):P=e[12];const k=P;let N;e[13]!==d?(N=$=>{const B=ul(d($));x(B),w($.text),S($.id)},e[13]=d,e[14]=N):N=e[14];const T=N;let M;e[15]!==y||e[16]!==b?(M=$=>{b($.sessionKey,$.id),y===$.id&&E()},e[15]=y,e[16]=b,e[17]=M):M=e[17];const R=M;let L;e[18]!==u||e[19]!==y||e[20]!==i||e[21]!==o||e[22]!==a||e[23]!==v||e[24]!==D||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==f?(L=($,B)=>{const H=B??v,_=$.trim();if(!H||!_||!i)return;if(!D){q.error(n("inlineComment.toast.selectSessionToSave"));return}const se=ul(H),oe=K0(c(se)),ae=o(se);y?f(D,y,{fileLabel:i,startLine:oe.startLine,endLine:oe.endLine,side:oe.side,code:ae,language:a,text:_}):u({sessionKey:D,source:r,fileLabel:i,startLine:oe.startLine,endLine:oe.endLine,side:oe.side,code:ae,language:a,text:_}),E()},e[18]=u,e[19]=y,e[20]=i,e[21]=o,e[22]=a,e[23]=v,e[24]=D,e[25]=r,e[26]=n,e[27]=c,e[28]=f,e[29]=L):L=e[29];const O=L;let V;return e[30]!==g||e[31]!==R||e[32]!==I||e[33]!==y||e[34]!==d||e[35]!==O||e[36]!==v||e[37]!==D||e[38]!==T?(V={sessionKey:D,drafts:I,selection:v,setSelection:x,commentText:g,setCommentText:w,editingDraftId:y,setEditingDraftId:S,reset:E,cancel:k,startEdit:T,deleteDraft:R,saveComment:O,fromDraftRange:d},e[30]=g,e[31]=R,e[32]=I,e[33]=y,e[34]=d,e[35]=O,e[36]=v,e[37]=D,e[38]=T,e[39]=V):V=e[39],V}function H0(t){return t.drafts}function G0(t){return t.removeDraft}function q0(t){return t.updateDraft}function J0(t){return t.addDraft}function Q0(t){return t.newSessionDraft?.open}function Y0(t){return t.currentSessionId}function Af(t){const{drafts:e,editingDraftId:n,commentText:r,selection:i,isDragging:a,fileLabel:o,newWidgetId:c,mapDraftToRange:d,onSave:p,onCancel:m,onEdit:u,onDelete:f}=t,b=[];for(const h of e){const v=d(h);if(h.id===n){b.push({afterLine:v.end,id:`edit-${h.id}`,content:s.jsx(dl,{initialText:r,fileLabel:o,lineRange:v,isEditing:!0,onSave:p,onCancel:m},`edit-${h.id}`)});continue}b.push({afterLine:v.end,id:`card-${h.id}`,content:s.jsx(Pf,{draft:h,onEdit:()=>u(h),onDelete:()=>f(h)},`card-${h.id}`)})}if(i&&!n&&!a){const h={...i,start:Math.min(i.start,i.end),end:Math.max(i.start,i.end)};b.push({afterLine:h.end,id:c,content:s.jsx(dl,{initialText:r,fileLabel:o,lineRange:h,isEditing:!1,onSave:p,onCancel:m},c)})}return b}const Vo=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}`},X0=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,i=[];for(const a of e){if(!Number.isFinite(a.endLine))continue;const o=Math.max(1,Math.floor(a.endLine)),c=a.side==="original"?"deletions":"additions";i.push({lineNumber:o,side:c,metadata:{type:a.id===n?"edit":"saved",draft:a}})}return r&&!n&&i.push({lineNumber:Math.max(r.start,r.end),side:r.side??"additions",metadata:{type:"new",selection:r}}),i};function Z0(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 cm(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function eN(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:i,commentText:a,fileLabel:o,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,f]=l.useState(0),[b,h]=l.useState(null),v=l.useMemo(()=>!r||i?null:Vo({type:"new",selection:r}),[i,r]),x=l.useMemo(()=>{const y=n.map(S=>Vo({type:S.id===i?"edit":"saved",draft:S}));return v&&y.push(v),y},[n,i,v]),g=l.useCallback(y=>{const S=e.current;if(!S)return null;const D=S.querySelector("diffs-container");if(!(D instanceof HTMLElement))return null;const j=D.querySelector(`[data-annotation-id="${y}"]`);if(j instanceof HTMLElement)return j;const I=D.shadowRoot;return I?I.querySelector(`[data-annotation-id="${y}"]`):null},[e]);l.useEffect(()=>{if(x.length===0)return;let y=!1,S=0;const D=12,j=()=>{y||x.every(A=>!!g(A))||S>=D||(S+=1,requestAnimationFrame(()=>{y||(f(A=>A+1),j())}))};return j(),()=>{y=!0}},[x,g]),l.useEffect(()=>{const y=e.current;if(!y)return;const S=()=>{const j=getComputedStyle(y),I=Z0(j.getPropertyValue("--oc-context-panel-width")),A=y.getBoundingClientRect(),E=I??A.width;h(E>0?E:null)};S();const D=new ResizeObserver(()=>{S()});return D.observe(y),window.addEventListener("resize",S),()=>{D.disconnect(),window.removeEventListener("resize",S)}},[e]);const w=l.useCallback(y=>{const D=e.current?.getBoundingClientRect(),j=y.closest("[data-annotation-content]"),I=j instanceof HTMLElement?j.getBoundingClientRect():y.getBoundingClientRect(),A=[I.width];D&&A.push(D.right-I.left);const E=A.filter(P=>Number.isFinite(P)&&P>0);return E.length>0?cm(Math.min(...E)):cm(b)},[e,b]);return s.jsxs(s.Fragment,{children:[n.map(y=>{const S=Vo({type:y.id===i?"edit":"saved",draft:y}),D=g(S);if(!D)return null;const j=w(D);return y.id===i?Li.createPortal(s.jsx(dl,{initialText:a,fileLabel:o,lineRange:{start:y.startLine,end:y.endLine,side:y.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:j}),D,`draft-edit-${y.id}`):Li.createPortal(s.jsx(Pf,{draft:y,onEdit:()=>p(y),onDelete:()=>m(y),maxWidth:j}),D,`draft-card-${y.id}`)}),r&&!i&&v&&(()=>{const y=g(v);if(!y)return null;const S=w(y);return Li.createPortal(s.jsx(dl,{initialText:a,fileLabel:o,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:S}),y,v)})()]})}function tN(){return new Worker(Eg,{type:"module"})}const sN=["typescript","javascript","tsx","jsx","json","markdown"],qc={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let dm,um;const mm=t=>{const e=qc[t],n=new Rg({workerFactory:tN,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:sN,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},nN=t=>{if(!(typeof window>"u"))return t==="split"?(um??=mm("split"),um):(dm??=mm("unified"),dm)},rN=t=>{const e=rt.c(7),{children:n,renderTheme:r}=t,i=Jc("unified"),a=Jc("split");let o,c;e[0]!==r||e[1]!==a||e[2]!==i?(o=()=>{i&&i.setRenderOptions({theme:r,lineDiffType:qc.unified.lineDiffType}),a&&a.setRenderOptions({theme:r,lineDiffType:qc.split.lineDiffType})},c=[r,a,i],e[0]=r,e[1]=a,e[2]=i,e[3]=o,e[4]=c):(o=e[3],c=e[4]),$e.useEffect(o,c);let d;return e[5]!==n?(d=s.jsx(s.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},aN=t=>{const e=rt.c(11),{children:n}=t,r=Sl();let i,a;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=ci(!1),m=ci(!0),u=r?.lightThemeId??p.metadata.id,f=r?.darkThemeId??m.metadata.id;a=r?.availableThemes.find(b=>b.metadata.id===u)??p,i=r?.availableThemes.find(b=>b.metadata.id===f)??m,di(a),di(i),e[0]=r?.availableThemes,e[1]=r?.darkThemeId,e[2]=r?.lightThemeId,e[3]=i,e[4]=a}else i=e[3],a=e[4];let o;e[5]!==i.metadata.id||e[6]!==a.metadata.id?(o={light:a.metadata.id,dark:i.metadata.id},e[5]=i.metadata.id,e[6]=a.metadata.id,e[7]=o):o=e[7];const c=o;let d;return e[8]!==n||e[9]!==c?(d=s.jsx(rN,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},Jc=t=>{const e=rt.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=nN(n),e[0]=n,e[1]=r):r=e[1],r},iN=5e5,oN=`
|
|
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 lN(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 pm(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${lN(e)}`}const cN=(t,e,n)=>{const a=(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(a.length,c);return d>p?"":a.slice(d-1,p).join(`
|
|
45
|
-
`)},dN=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,So=new WeakMap,uN={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function mN(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 pN(t){if(typeof document>"u")return null;const e=mN(t);let n=So.get(e.key);if(!n){const i=new Og;i.setup(e.root,e.content),n={virtualizer:i,refs:0},So.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const i=So.get(e.key);i&&(i.refs-=1,!(i.refs>0)&&(i.virtualizer.cleanUp(),So.delete(e.key)))}}}const Df=({original:t,modified:e,language:n,fileName:r,renderSideBySide:i,wrapLines:a,layout:o="fill"})=>{const c=Sl(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(Q=>Q.metadata.id===c.lightThemeId)??ci(!1),m=c?.availableThemes.find(Q=>Q.metadata.id===c.darkThemeId)??ci(!0),{isMobile:u}=rn(),f=Ld({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:Q=>cN(t,e,Q),toStoreRange:Q=>({startLine:Q.start,endLine:Q.end,side:Q.side==="deletions"?"original":"modified"}),fromDraftRange:Q=>({start:Q.startLine,end:Q.endLine,side:Q.side==="original"?"deletions":"additions"})}),{drafts:b,selection:h,setSelection:v,commentText:x,setCommentText:g,editingDraftId:w,saveComment:y,cancel:S,startEdit:D,deleteDraft:j}=f,I=$e.useRef(null),A=$e.useRef(null),E=$e.useRef(!1),P=$e.useRef(null);$e.useEffect(()=>{I.current=h},[h]),$e.useEffect(()=>{A.current=w},[w]);const k=$e.useCallback(Q=>{if(E.current)return;const re=I.current;if(u&&re&&Q&&Q.side===re.side){const K=Math.min(re.start,Q.start),le=Math.max(re.end,Q.end);v({...Q,start:K,end:le})}else v(Q);Q&&(A.current||g(""))},[u,g,v]),N=$e.useCallback(()=>{S()},[S]),T=$e.useCallback(Q=>{const re=document.createElement("div");re.style.position="relative";const K=Vo(Q.metadata);return re.dataset.annotationId=K,re.dataset.annotationSide=Q.side,re.dataset.annotationLine=String(Q.lineNumber),re},[]),M=$e.useCallback((Q,re)=>{y(Q,re??h??void 0)},[y,h]),R=$e.useCallback(Q=>{v(Q);const re=B.current;if(re)try{E.current=!0,re.setSelectedLines(Q),P.current=Q}catch{}finally{E.current=!1}},[v]),L=$e.useCallback(Q=>{const re=Q.closest("[data-line-type]")?.getAttribute("data-line-type")??Q.getAttribute("data-line-type");if(re==="change-deletion")return"deletions";if(re==="change-addition")return"additions";const K=Q.getAttribute("data-column-side")??Q.getAttribute("data-side")??Q.closest("[data-column-side]")?.getAttribute("data-column-side");if(K==="deletions"||K==="left"||K==="original")return"deletions";if(K==="additions"||K==="right"||K==="modified")return"additions";const le=Q.closest("[data-line-type]");if(le instanceof HTMLElement){const Se=le.getBoundingClientRect(),ue=Q.getBoundingClientRect(),je=Se.left+Se.width/2;return ue.left+ue.width/2<je?"deletions":"additions"}return"additions"},[]);di(p),di(m);const O=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,V=$e.useRef(null),$=$e.useRef(null),B=$e.useRef(null),H=$e.useRef(null),[,_]=l.useReducer(Q=>Q+1,0),se=Jc(i?"split":"unified"),oe=$e.useMemo(()=>au(p),[p]),ae=$e.useMemo(()=>au(m),[m]);l.useLayoutEffect(()=>{const Q=V.current;if(!Q)return;const re=Q.querySelector("diffs-container");if(!re)return;const K=d?ae:oe,le=(Y,he)=>Y.colors?.[he],Se=le(oe,"terminal.ansiGreen"),ue=le(oe,"terminal.ansiRed"),je=le(oe,"terminal.ansiBlue"),W=le(ae,"terminal.ansiGreen"),me=le(ae,"terminal.ansiRed"),X=le(ae,"terminal.ansiBlue");re.style.setProperty("--shiki-light",oe.fg),re.style.setProperty("--shiki-light-bg",oe.bg),Se&&re.style.setProperty("--shiki-light-addition-color",Se),ue&&re.style.setProperty("--shiki-light-deletion-color",ue),je&&re.style.setProperty("--shiki-light-modified-color",je),re.style.setProperty("--shiki-dark",ae.fg),re.style.setProperty("--shiki-dark-bg",ae.bg),W&&re.style.setProperty("--shiki-dark-addition-color",W),me&&re.style.setProperty("--shiki-dark-deletion-color",me),X&&re.style.setProperty("--shiki-dark-modified-color",X),re.style.setProperty("--diffs-bg",K.bg),re.style.setProperty("--diffs-fg",K.fg);const ce=d?W:Se,ee=d?me:ue,Pe=d?X:je;ce&&re.style.setProperty("--diffs-addition-color-override",ce),ee&&re.style.setProperty("--diffs-deletion-color-override",ee),Pe&&re.style.setProperty("--diffs-modified-color-override",Pe);const Ne=re.shadowRoot?.querySelector("pre");Ne&&(Ne.style.setProperty("--shiki-light",oe.fg),Ne.style.setProperty("--shiki-light-bg",oe.bg),Se&&Ne.style.setProperty("--shiki-light-addition-color",Se),ue&&Ne.style.setProperty("--shiki-light-deletion-color",ue),je&&Ne.style.setProperty("--shiki-light-modified-color",je),Ne.style.setProperty("--shiki-dark",ae.fg),Ne.style.setProperty("--shiki-dark-bg",ae.bg),W&&Ne.style.setProperty("--shiki-dark-addition-color",W),me&&Ne.style.setProperty("--shiki-dark-deletion-color",me),X&&Ne.style.setProperty("--shiki-dark-modified-color",X),Ne.style.setProperty("--diffs-bg",K.bg),Ne.style.setProperty("--diffs-fg",K.fg),ce&&Ne.style.setProperty("--diffs-addition-color-override",ce),ee&&Ne.style.setProperty("--diffs-deletion-color-override",ee),Pe&&Ne.style.setProperty("--diffs-modified-color-override",Pe))},[ae,O,d,oe]);const ne=$e.useMemo(()=>Math.max(t.length,e.length)>iN,[t.length,e.length]),xe=$e.useMemo(()=>({theme:{dark:m.metadata.id,light:p.metadata.id},themeType:d?"dark":"light",diffStyle:i?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:ne?0:1e3,maxLineLengthForHighlighting:ne?1:1e3,expansionLineCount:20,overflow:a?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:k,unsafeCSS:oN,renderAnnotation:T}),[m.metadata.id,d,ne,p.metadata.id,i,a,k,T]),te=$e.useMemo(()=>X0({drafts:b,editingDraftId:w,selection:h}),[w,b,h]),F=$e.useRef(te);if($e.useEffect(()=>{F.current=te},[te]),$e.useEffect(()=>{if(typeof window>"u")return;const Q=$.current;if(!Q||!se)return;B.current?.cleanUp(),B.current=null,H.current?.release(),H.current=null,Q.innerHTML="";const re=pN(Q);H.current=re;const K=re?new Fg(xe,re.virtualizer,uN,se):new Lg(xe,se);B.current=K,P.current=null;const le={name:r||"",contents:t,lang:n,cacheKey:`old:${O}:${r}:${pm(t)}`},Se={name:r||"",contents:e,lang:n,cacheKey:`new:${O}:${r}:${pm(e)}`};return K.render({oldFile:le,newFile:Se,lineAnnotations:F.current,containerWrapper:Q}),requestAnimationFrame(()=>{_()}),()=>{K.cleanUp(),B.current===K&&(B.current=null),re?.release(),re&&H.current===re&&(H.current=null),Q.innerHTML=""}},[O,r,n,e,xe,t,se]),$e.useEffect(()=>{const Q=B.current;if(Q){try{Q.setLineAnnotations(te)}catch(re){console.error("Failed to apply diff line annotations",re);try{Q.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(B.current===Q){try{Q.rerender()}catch{}_()}})}},[te]),$e.useEffect(()=>{const Q=B.current;if(!Q||h!==null)return;const re=P.current;if(!dN(h,re))try{E.current=!0,Q.setSelectedLines(h),P.current=h}catch{}finally{E.current=!1}},[h]),$e.useEffect(()=>{const Q=$.current;if(!Q)return;let re=null,K=()=>{};const le=()=>{const ue=Q.querySelector("diffs-container")?.shadowRoot;if(!ue){re=requestAnimationFrame(le);return}const je=W=>{if(!(W instanceof MouseEvent)||W.button!==0||!(W.target instanceof Element))return;const me=W.target.closest("[data-column-number]");if(!(me instanceof HTMLElement))return;const X=me.getAttribute("data-column-number"),ce=X?parseInt(X,10):NaN;if(Number.isNaN(ce))return;const ee=L(me);k({start:ce,end:ce,side:ee}),W.preventDefault(),W.stopPropagation()};ue.addEventListener("click",je,!0),K=()=>{ue.removeEventListener("click",je,!0)}};return le(),()=>{re!==null&&cancelAnimationFrame(re),K()}},[O,r,k,L]),$e.useEffect(()=>{const Q=$.current;if(!Q)return;let re=null,K=null;const Se=setTimeout(()=>{const ue=Q.querySelector("diffs-container");if(!(ue instanceof HTMLElement))return;const je=ue.shadowRoot;re=new MutationObserver(()=>{K&&cancelAnimationFrame(K),K=requestAnimationFrame(()=>{_(),K=null})}),re.observe(ue,{childList:!0,subtree:!0}),je&&re.observe(je,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(Se),K&&cancelAnimationFrame(K),re?.disconnect()}},[O,r]),typeof window>"u")return null;const z=s.jsx(eN,{diffRootRef:V,drafts:b,selection:h,editingDraftId:w,commentText:x,fileLabel:r?.split("/").pop()??"",onSave:M,onCancel:N,onEdit:Q=>{R({start:Q.startLine,end:Q.endLine,side:Q.side==="original"?"deletions":"additions"}),D(Q)},onDelete:j});return o==="fill"?s.jsx("div",{className: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(As,{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:$,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:$,className:"w-full"})}),z]})},hN=1100,Qc=15e3,hm=500,fN=t=>t<=6?t:t<=12?6:t<=25?4:2,Tf=l.memo(()=>{const t=rt.c(4),{t:e}=mt();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}),Mf={"?":{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"}},gN=Mf.M,zo=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],xN=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"},Ef=t=>{const e=xN(t);return Mf[e]??gN},bN=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},yN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),vN=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(yN(r))return r;const i=r.replace(/^\/+/,"");return n?`${n}/${i}`:i},fm=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),gm=(t,e)=>{const n=t.split(`
|
|
46
|
-
`),r=e.split(`
|
|
47
|
-
`),i=Math.min(n.length,r.length);for(let a=0;a<i;a+=1)if(n[a]!==r[a])return a+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},wN=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},ml=(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]})},jN=l.memo(t=>{const e=rt.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:i,onSelectFile:a,isMobile:o,showModeSelector:c,mode:d,onModeChange:p}=t,m=c===void 0?!1:c,{t:u}=mt();let f;e[0]!==o?(f=I=>{if(!o)return I;const A=I.lastIndexOf("/");return A>=0?I.slice(A+1):I},e[0]=o,e[1]=f):f=e[1];const b=f;if(n.length===0)return null;let h;e[2]!==b||e[3]!==i||e[4]!==u?(h=i?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(yr,{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)}),ml(i.insertions,i.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:u("diffView.selector.selectFile")}),e[2]=b,e[3]=i,e[4]=u,e[5]=h):h=e[5];let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(C,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=v):v=e[6];let x;e[7]!==h?(x=s.jsx(Os,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[h,v]})}),e[7]=h,e[8]=x):x=e[8];let g;e[9]!==d||e[10]!==p||e[11]!==m||e[12]!==u?(g=m&&d&&p?s.jsxs(s.Fragment,{children:[s.jsx(Oi,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(tl,{value:d,onValueChange:I=>p(I),children:zo.map(I=>s.jsx(sl,{value:I.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(I.labelKey)})},I.value))}),s.jsx(An,{})]}):null,e[9]=d,e[10]=p,e[11]=m,e[12]=u,e[13]=g):g=e[13];const w=r??"";let y;if(e[14]!==n||e[15]!==b){let I;e[17]!==b?(I=A=>s.jsx(sl,{value:A.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(yr,{filePath:A.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(A.path)}),s.jsx("span",{className:"ml-auto",children:ml(A.insertions,A.deletions)})]})},A.path),e[17]=b,e[18]=I):I=e[18],y=n.map(I),e[14]=n,e[15]=b,e[16]=y}else y=e[16];let S;e[19]!==a||e[20]!==w||e[21]!==y?(S=s.jsx(tl,{value:w,onValueChange:a,children:y}),e[19]=a,e[20]=w,e[21]=y,e[22]=S):S=e[22];let D;e[23]!==g||e[24]!==S?(D=s.jsxs($s,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[g,S]}),e[23]=g,e[24]=S,e[25]=D):D=e[25];let j;return e[26]!==D||e[27]!==x?(j=s.jsxs(Bs,{children:[x,D]}),e[26]=D,e[27]=x,e[28]=j):j=e[28],j}),NN=l.memo(t=>{const e=rt.c(31),{mode:n,onModeChange:r}=t,{t:i}=mt();let a,o,c,d,p,m;if(e[0]!==n||e[1]!==i){const y=zo.find(S=>S.value===n)??zo[0];o=Bs,a=Os,m=!0,p="flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",c="min-w-0 truncate typography-meta",d=i(y.labelKey),e[0]=n,e[1]=i,e[2]=a,e[3]=o,e[4]=c,e[5]=d,e[6]=p,e[7]=m}else a=e[2],o=e[3],c=e[4],d=e[5],p=e[6],m=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsx("span",{className:c,children:d}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let f;e[11]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(C,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=f):f=e[11];let b;e[12]!==p||e[13]!==u?(b=s.jsxs("button",{className:p,children:[u,f]}),e[12]=p,e[13]=u,e[14]=b):b=e[14];let h;e[15]!==a||e[16]!==m||e[17]!==b?(h=s.jsx(a,{asChild:m,children:b}),e[15]=a,e[16]=m,e[17]=b,e[18]=h):h=e[18];let v;e[19]!==r?(v=y=>r(y),e[19]=r,e[20]=v):v=e[20];let x;e[21]!==i?(x=zo.map(y=>s.jsx(sl,{value:y.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:i(y.labelKey)})},y.value)),e[21]=i,e[22]=x):x=e[22];let g;e[23]!==n||e[24]!==x||e[25]!==v?(g=s.jsx($s,{className:"min-w-[140px]",children:s.jsx(tl,{value:n,onValueChange:v,children:x})}),e[23]=n,e[24]=x,e[25]=v,e[26]=g):g=e[26];let w;return e[27]!==o||e[28]!==g||e[29]!==h?(w=s.jsxs(o,{children:[h,g]}),e[27]=o,e[28]=g,e[29]=h,e[30]=w):w=e[30],w}),SN=l.memo(t=>{const e=rt.c(11),{changedFiles:n,selectedFile:r,onSelectFile:i}=t,{t:a}=mt();if(n.length===0)return null;let o;if(e[0]!==n||e[1]!==i||e[2]!==r||e[3]!==a){let d;e[5]!==i||e[6]!==r||e[7]!==a?(d=p=>{const m=Ef(p),u=r===p.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>i(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(yr,{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:a(m.descriptionKey),"aria-label":a(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}),ml(p.insertions,p.deletions)]})},p.path)},e[5]=i,e[6]=r,e[7]=a,e[8]=d):d=e[8],o=n.map(d),e[0]=n,e[1]=i,e[2]=r,e[3]=a,e[4]=o}else o=e[4];let c;return e[9]!==o?(c=s.jsx(As,{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}),kN=l.memo(t=>{const e=rt.c(21),{filePath:n,diff:r,isVisible:i,renderSideBySide:a}=t,{t:o}=mt(),c=r.original.length>0,d=r.modified.length>0;if(!i){let v;return e[0]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=v):v=e[0],v}const p=a?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=a?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"size layout"},e[1]=u):u=e[1];let f;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==a||e[7]!==o?(f=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o("diffView.image.original")}),s.jsx("img",{src:r.original,alt:o("diffView.image.originalAlt",{path:n}),className:a?"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]=a,e[7]=o,e[8]=f):f=e[8];let b;e[9]!==r.modified||e[10]!==n||e[11]!==d||e[12]!==c||e[13]!==m||e[14]!==a||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:a?"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]=a,e[15]=o,e[16]=b):b=e[16];let h;return e[17]!==p||e[18]!==f||e[19]!==b?(h=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:u,children:s.jsxs("div",{className:p,children:[f,b]})}),e[17]=p,e[18]=f,e[19]=b,e[20]=h):h=e[20],h}),CN=l.memo(t=>{const e=rt.c(20),{filePath:n,diff:r,renderSideBySide:i}=t,{t:a}=mt(),o=r.original.length>0,c=r.modified.length>0,d=i?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",p=i?"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]!==i||e[6]!==a?(u=o&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a("diffView.image.original")}),s.jsx("img",{src:r.original,alt:a("diffView.image.originalAlt",{path:n}),className:i?"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]=i,e[6]=a,e[7]=u):u=e[7];let f;e[8]!==r.modified||e[9]!==n||e[10]!==c||e[11]!==o||e[12]!==p||e[13]!==i||e[14]!==a?(f=c&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a(o?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:a("diffView.image.modifiedAlt",{path:n}),className:i?"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]=i,e[14]=a,e[15]=f):f=e[15];let b;return e[16]!==d||e[17]!==u||e[18]!==f?(b=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,f]})}),e[16]=d,e[17]=u,e[18]=f,e[19]=b):b=e[19],b}),IN=l.memo(t=>{const e=rt.c(15),{filePath:n,diff:r,renderSideBySide:i,wrapLines:a}=t;let o;e[0]!==n?(o=Ui(n)||"text",e[0]=n,e[1]=o):o=e[1];const c=o;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Tf,{}),e[2]=m):m=e[2],m}if(ui(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==i?(m=s.jsx(CN,{filePath:n,diff:r,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=i,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]!==i||e[13]!==a?(p=s.jsx("div",{className:"w-full",style:d,children:s.jsx(Df,{original:r.original,modified:r.modified,language:c,fileName:n,renderSideBySide:i,wrapLines:a,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=c,e[12]=i,e[13]=a,e[14]=p):p=e[14],p}),PN=l.memo(t=>{const e=rt.c(15),{filePath:n,diff:r,isVisible:i,renderSideBySide:a,wrapLines:o}=t;let c;e[0]!==n?(c=Ui(n)||"text",e[0]=n,e[1]=c):c=e[1];const d=c;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Tf,{}),e[2]=m):m=e[2],m}if(!i)return null;if(ui(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==i||e[6]!==a?(m=s.jsx(kN,{filePath:n,diff:r,isVisible:i,renderSideBySide:a}),e[3]=r,e[4]=n,e[5]=i,e[6]=a,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]!==a||e[13]!==o?(p=s.jsx(As,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Df,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:a,wrapLines:o,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=a,e[13]=o,e[14]=p):p=e[14],p}),AN=l.memo(t=>{const e=rt.c(122),{directory:n,file:r,layout:i,wrapLines:a,scrollRootRef:o,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:f,showOpenInEditorAction:b,isOpeningInEditor:h,onOpenInEditor:v}=t,x=m===void 0?!1:m,g=u===void 0?null:u,w=f===void 0?0:f,y=b===void 0?!1:b,S=h===void 0?!1:h,{t:D}=mt(),{git:j}=_n();let I;e[0]!==n||e[1]!==r.path?(I=tt=>tt.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=I):I=e[2];const A=on(I),E=on(TN),P=Me(MN),[k,N]=l.useState(!x),[T,M]=l.useState(!1),[R,L]=l.useState(0),[O,V]=l.useState(null),[$,B]=l.useState(!1),[H,_]=l.useState(!1),se=l.useRef(null),oe=l.useRef(null);let ae;e[3]!==r?(ae=Ef(r),e[3]=r,e[4]=ae):ae=e[4];const ne=ae,xe=i==="side-by-side";let te;e:{if(!A){te=null;break e}let tt;e[5]!==A.isBinary||e[6]!==A.modified||e[7]!==A.original?(tt={original:A.original,modified:A.modified,isBinary:A.isBinary},e[5]=A.isBinary,e[6]=A.modified,e[7]=A.original,e[8]=tt):tt=e[8],te=tt}const F=te;let z;e[9]!==r.path||e[10]!==p?(z=tt=>{oe.current=tt,p(r.path,tt)},e[9]=r.path,e[10]=p,e[11]=z):z=e[11];const Q=z;let re;e[12]===Symbol.for("react.memo_cache_sentinel")?(re=tt=>{N(tt),tt&&M(!0)},e[12]=re):re=e[12];const K=re;let le;e[13]!==r.path||e[14]!==d?(le=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=le):le=e[15];const Se=le;let ue,je;e[16]!==T||e[17]!==k||e[18]!==o?(ue=()=>{if(!k||T)return;const tt=oe.current;if(!tt)return;if(!o.current||typeof IntersectionObserver>"u"){M(!0);return}const st=new IntersectionObserver(qe=>{qe.some(EN)&&(M(!0),st.disconnect())},{root:o.current,rootMargin:"200px 0px",threshold:.1});return st.observe(tt),()=>st.disconnect()},je=[T,k,o],e[16]=T,e[17]=k,e[18]=o,e[19]=ue,e[20]=je):(ue=e[19],je=e[20]),l.useEffect(ue,je);let W,me;e[21]!==w||e[22]!==g||e[23]!==r.path?(W=()=>{w<=0||g!==r.path||(N(!0),M(!0))},me=[w,g,r.path],e[21]=w,e[22]=g,e[23]=r.path,e[24]=W,e[25]=me):(W=e[24],me=e[25]),l.useEffect(W,me);let X,ce;e[26]!==F||e[27]!==R||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==T||e[32]!==k||e[33]!==E?(X=()=>{if(!k||!T)return;if(!n||F){se.current=null,B(!1);return}const tt=`${n}::${r.path}::${R}`;if(se.current===tt)return;se.current=tt,V(null),B(!0);let st=!1;const qe=j.getGitFileDiff(n,{path:r.path}),it=new Promise(RN);return Promise.race([qe,it]).then(lt=>{st||(E(n,r.path,{original:lt.original??"",modified:lt.modified??"",isBinary:lt.isBinary}),B(!1))}).catch(lt=>{if(st)return;const ye=lt instanceof Error?lt.message:String(lt);V(ye),B(!1)}),()=>{st=!0,se.current===tt&&(se.current=null)}},ce=[n,F,R,r.path,j,T,k,E],e[26]=F,e[27]=R,e[28]=n,e[29]=r.path,e[30]=j,e[31]=T,e[32]=k,e[33]=E,e[34]=X,e[35]=ce):(X=e[34],ce=e[35]),l.useEffect(X,ce);let ee;e[36]!==Se||e[37]!==k?(ee=()=>{K(!k),Se()},e[36]=Se,e[37]=k,e[38]=ee):ee=e[38];const Pe=ee,Ne=k?"rounded-b-none":"rounded-b-xl",Y=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let he;e[39]!==Ne||e[40]!==Y?(he=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",Ne,"text-muted-foreground hover:text-foreground",Y),e[39]=Ne,e[40]=Y,e[41]=he):he=e[41];let ke;e[42]===Symbol.for("react.memo_cache_sentinel")?(ke=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[42]=ke):ke=e[42];let be;e[43]!==k?(be=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:k?s.jsx(C,{name:"arrow-down-s",className:"size-4"}):s.jsx(C,{name:"arrow-right-s",className:"size-4"})}),e[43]=k,e[44]=be):be=e[44];let fe;e[45]!==ne.color?(fe={color:ne.color},e[45]=ne.color,e[46]=fe):fe=e[46];let Te;e[47]!==ne.descriptionKey||e[48]!==D?(Te=D(ne.descriptionKey),e[47]=ne.descriptionKey,e[48]=D,e[49]=Te):Te=e[49];let Ve;e[50]!==ne.descriptionKey||e[51]!==D?(Ve=D(ne.descriptionKey),e[50]=ne.descriptionKey,e[51]=D,e[52]=Ve):Ve=e[52];let G;e[53]!==ne.code||e[54]!==fe||e[55]!==Te||e[56]!==Ve?(G=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:fe,title:Te,"aria-label":Ve,children:ne.code}),e[53]=ne.code,e[54]=fe,e[55]=Te,e[56]=Ve,e[57]=G):G=e[57];const Ie=r.path;let Oe;e[58]!==r.path?(Oe=s.jsx(yr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=Oe):Oe=e[59];let De;if(e[60]!==r.path){e:{const tt=r.path.lastIndexOf("/");if(tt===-1){let ze;e[62]===Symbol.for("react.memo_cache_sentinel")?(ze={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[62]=ze):ze=e[62],De=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:ze,children:r.path});break e}const st=r.path.slice(0,tt),qe=r.path.slice(tt+1);let it;e[63]===Symbol.for("react.memo_cache_sentinel")?(it={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=it):it=e[63];let lt;e[64]!==st?(lt=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:it,children:st}),e[64]=st,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 Je;e[67]!==qe?(Je=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[ye,s.jsx("span",{className:"text-foreground",children:qe})]}),e[67]=qe,e[68]=Je):Je=e[68];let Be;e[69]!==lt||e[70]!==Je?(Be=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[lt,Je]}),e[69]=lt,e[70]=Je,e[71]=Be):Be=e[71],De=Be}e[60]=r.path,e[61]=De}else De=e[61];let ge;e[72]!==Oe||e[73]!==De?(ge=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[Oe,De]}),e[72]=Oe,e[73]=De,e[74]=ge):ge=e[74];let U;e[75]!==r.path||e[76]!==ge?(U=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Ie,children:ge}),e[75]=r.path,e[76]=ge,e[77]=U):U=e[77];let de;e[78]!==be||e[79]!==G||e[80]!==U?(de=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[be,G,U]}),e[78]=be,e[79]=G,e[80]=U,e[81]=de):de=e[81];let Ee;e[82]!==r.deletions||e[83]!==r.insertions?(Ee=ml(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=Ee):Ee=e[84];let _e;e[85]!==F||e[86]!==r.path||e[87]!==S||e[88]!==v||e[89]!==y||e[90]!==D?(_e=y&&v?s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:D("diffView.actions.openFileInEditorAtChange"),onClick:tt=>{tt.stopPropagation(),v(r.path,F)},disabled:S,children:S?s.jsx(C,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(C,{name:"edit",className:"size-3.5"})}):null,e[85]=F,e[86]=r.path,e[87]=S,e[88]=v,e[89]=y,e[90]=D,e[91]=_e):_e=e[91];const Z=xe?"side-by-side":"unified";let ie;e[92]!==r.path||e[93]!==P?(ie=tt=>{const st=tt==="side-by-side"?"side-by-side":"inline";P(r.path,st)},e[92]=r.path,e[93]=P,e[94]=ie):ie=e[94];let Ce;e[95]!==Z||e[96]!==ie?(Ce=s.jsx(Rh,{mode:Z,onModeChange:ie,className:"opacity-70"}),e[95]=Z,e[96]=ie,e[97]=Ce):Ce=e[97];let He;e[98]!==Ee||e[99]!==_e||e[100]!==Ce?(He=s.jsxs("div",{className:"relative flex items-center gap-2",children:[Ee,_e,Ce]}),e[98]=Ee,e[99]=_e,e[100]=Ce,e[101]=He):He=e[101];let Ge;e[102]!==Pe||e[103]!==he||e[104]!==de||e[105]!==He?(Ge=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:Pe,className:he,children:[ke,de,He]})}),e[102]=Pe,e[103]=he,e[104]=de,e[105]=He,e[106]=Ge):Ge=e[106];let Xe;e[107]!==F||e[108]!==O||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==H||e[113]!==k||e[114]!==$||e[115]!==xe||e[116]!==a?(Xe=k&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[O?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:O}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>L(FN),children:"Retry"})]}):null,$&&!F&&!O?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"animate-spin"}),"Loading diff…"]}):null,F&&!H&&r.insertions+r.deletions>hm?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:()=>_(!0),children:"Render anyway"})]}):null,F&&(H||r.insertions+r.deletions<=hm)?s.jsx(IN,{filePath:r.path,diff:F,renderSideBySide:xe,wrapLines:a}):null]}),e[107]=F,e[108]=O,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=H,e[113]=k,e[114]=$,e[115]=xe,e[116]=a,e[117]=Xe):Xe=e[117];let we;return e[118]!==Q||e[119]!==Ge||e[120]!==Xe?(we=s.jsxs("div",{ref:Q,className:"scroll-mt-4",children:[Ge,Xe]}),e[118]=Q,e[119]=Ge,e[120]=Xe,e[121]=we):we=e[121],we}),Rf=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:i=!1})=>{const{t:a}=mt(),{git:o,files:c}=_n(),d=Or(),{screenWidth:p,isMobile:m}=rn(),u=Mh(d??null),f=wl(d??null),b=Eh(d??null),h=on(de=>de.setActiveDirectory),v=on(de=>de.ensureStatus),x=on(de=>de.fetchStatus),g=on(de=>de.setDiff),[w,y]=l.useState(null),[S,D]=l.useState(null),[j,I]=l.useState(0),[A,E]=l.useState(null),[P,k]=l.useState(0),[N,T]=l.useState(null),M=l.useRef(null),R=Me(de=>de.pendingDiffFile),L=Me(de=>de.setPendingDiffFile),O=Me(de=>de.diffLayoutPreference),V=Me(de=>de.diffFileLayout),$=Me(de=>de.setDiffFileLayout),B=Me(de=>de.diffWrapLines),H=Me(de=>de.setDiffWrapLines),_=Me(de=>de.diffViewMode),se=Me(de=>de.setDiffViewMode),oe=Me(de=>de.openContextFileAtLine),ae=B,ne=_==="stacked",xe=m||p<=768,te=!t&&!xe&&p>=1024,F=l.useRef(null),z=l.useRef(new Map),Q=l.useRef(null),re=l.useRef(null),K=l.useRef(!1);l.useEffect(()=>{if(!r||!ne||!A)return;const de=F.current;if(!de)return;let Ee=null,_e=!1,Z=0;const ie=Date.now()+1200;let Ce=0;const He=()=>{_e||(_e=!0,E(null))},Ge=()=>{He()},Xe=()=>{if(Ce>0){Ce-=1;return}He()};window.addEventListener("wheel",Ge,{passive:!0,capture:!0}),window.addEventListener("touchstart",Ge,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Ge,{capture:!0}),window.addEventListener("keydown",Ge,{capture:!0}),de.addEventListener("scroll",Xe,{passive:!0});const we=()=>{if(_e||Date.now()>ie){He();return}const tt=F.current,st=z.current.get(A);if(!tt||!st){He();return}const qe=tt.getBoundingClientRect(),lt=st.getBoundingClientRect().top-qe.top;if(Math.abs(lt)<=1){if(Z+=1,Z>=2){He();return}}else{Z=0;const ye=Math.max(0,tt.scrollHeight-tt.clientHeight),Je=Math.min(ye,Math.max(0,tt.scrollTop+lt));if(Math.abs(Je-tt.scrollTop)<=.5){He();return}Ce+=1,tt.scrollTop=Je}Ee=window.requestAnimationFrame(we)};return Ee=window.requestAnimationFrame(we),()=>{_e=!0,Ee!==null&&window.cancelAnimationFrame(Ee),window.removeEventListener("wheel",Ge,!0),window.removeEventListener("touchstart",Ge,!0),window.removeEventListener("pointerdown",Ge,!0),window.removeEventListener("keydown",Ge,!0),de.removeEventListener("scroll",Xe)}},[ne,r,A]);const le=l.useMemo(()=>{if(!f?.files)return[];const de=f.diffStats??{};return f.files.map(Ee=>({...Ee,insertions:de[Ee.path]?.insertions??0,deletions:de[Ee.path]?.deletions??0,isNew:bN(Ee)})).sort((Ee,_e)=>Ee.path.localeCompare(_e.path))},[f]),Se=l.useMemo(()=>w?le.find(de=>de.path===w)??null:null,[le,w]),ue=l.useCallback(de=>{const Ee=V[de.path];if(Ee)return Ee;if(O==="inline")return"inline";if(O==="side-by-side")return"side-by-side";const _e=p<hN;return de.isNew||_e?"inline":"side-by-side"},[V,O,p]),je=l.useMemo(()=>Se?ue(Se):null,[ue,Se]);l.useEffect(()=>{d&&(h(d),v(d,o))},[d,h,v,o]),l.useEffect(()=>{if(d)return vr.onGitRefreshHint(de=>{fm(de.directory)===fm(d)&&x(d,o)})},[d,x,o]),l.useEffect(()=>{R&&(y(R),L(null),ne&&(K.current=!0,Q.current=R,D(R),I(de=>de+1)))},[ne,R,L]),l.useEffect(()=>{!w&&!R&&le.length>0&&y(le[0].path)},[le,w,R]),l.useEffect(()=>{w&&le.length>0&&(le.some(Ee=>Ee.path===w)||y(le[0]?.path??null))},[le,w]);const W=l.useCallback((de,Ee)=>{const _e=z.current;Ee?_e.set(de,Ee):_e.delete(de)},[]),me=l.useCallback(de=>{const Ee=z.current.get(de),_e=F.current;if(!Ee||!_e)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const Z=_e.getBoundingClientRect(),Ce=Ee.getBoundingClientRect().top-Z.top,He=Math.max(0,_e.scrollHeight-_e.clientHeight),Ge=_e.scrollTop+Ce,Xe=Math.min(He,Math.max(0,Ge)),we=Math.abs(Xe-_e.scrollTop)>.5;_e.scrollTop=Xe;const tt=Math.abs(Ce)<=1,st=Xe<=.5||Xe>=He-.5;return{ok:!0,aligned:tt,didMove:we,atScrollLimit:st,delta:Ce}},[]);l.useEffect(()=>{if(!ne){Q.current=null,K.current=!1,re.current!==null&&(window.cancelAnimationFrame(re.current),re.current=null);return}if(!Q.current)return;let Ee=0;const _e=120;let Z=!1,ie=0,Ce=!1,He=0;const Ge=Date.now()+2e3,Xe=()=>{Ce||(Ce=!0,window.removeEventListener("wheel",tt,!0),window.removeEventListener("touchstart",tt,!0),window.removeEventListener("pointerdown",tt,!0),window.removeEventListener("keydown",tt,!0),qe?.removeEventListener("scroll",st))},we=()=>{Z||(Z=!0,Xe(),Q.current=null,K.current=!1,re.current!==null&&(window.cancelAnimationFrame(re.current),re.current=null))},tt=()=>{we()},st=()=>{if(ie>0){ie-=1;return}we()},qe=F.current;window.addEventListener("wheel",tt,{passive:!0,capture:!0}),window.addEventListener("touchstart",tt,{passive:!0,capture:!0}),window.addEventListener("pointerdown",tt,{capture:!0}),window.addEventListener("keydown",tt,{capture:!0}),qe?.addEventListener("scroll",st,{passive:!0});const it=()=>{if(Date.now()>Ge){we(),re.current=null;return}if(Z){re.current=null;return}const lt=Q.current;if(!lt){we(),re.current=null;return}ie+=1;const ye=me(lt);if(!ye.ok){ie=Math.max(0,ie-1),Ee+=1,Ee<_e?re.current=window.requestAnimationFrame(it):(we(),re.current=null);return}if(!ye.aligned){if(Ee+=1,ye.didMove){if(He=0,Ee<_e){re.current=window.requestAnimationFrame(it);return}}else if(He+=1,He<6&&(ye.atScrollLimit||Math.abs(ye.delta)>1)){re.current=window.requestAnimationFrame(it);return}}r&&K.current&&E(lt),we()};return re.current=window.requestAnimationFrame(it),()=>{Z=!0,Xe(),re.current!==null&&(window.cancelAnimationFrame(re.current),re.current=null)}},[ne,r,me,w,j]);const X=l.useCallback(de=>{y(de)},[]),ce=l.useCallback(de=>{if(re.current!==null&&(window.cancelAnimationFrame(re.current),re.current=null),Q.current=null,y(de),!ne){K.current=!1;return}K.current=!0,Q.current=de,me(de)},[ne,me]),ee=l.useCallback(de=>{se(de),de==="stacked"&&w&&(me(w).aligned||(Q.current=w))},[me,w,se]),Pe=l.useCallback(de=>{const Ee=de==="side-by-side"?"side-by-side":"inline";if(ne){le.forEach(_e=>{$(_e.path,Ee)});return}Se&&$(Se.path,Ee)},[le,ne,Se,$]),Ne=(je??"side-by-side")==="side-by-side",Y=!n&&(!ne||!te),he=on(l.useCallback(de=>!d||!w?null:de.directories.get(d)?.diffCache.get(w)??null,[d,w])),ke=l.useMemo(()=>he?{original:he.original,modified:he.modified,isBinary:he.isBinary}:null,[he]),[be,fe]=l.useState(null),Te=l.useCallback(async(de,Ee)=>{if(!(!d||!de)){fe(de);try{let _e=null;if(Ee&&!Ee.isBinary&&!ui(de)&&(_e=gm(Ee.original,Ee.modified)),_e===null)try{const Ge=await o.getGitDiff(d,{path:de,contextLines:3});_e=wN(Ge.diff)}catch{_e=null}let Z=Ee;if(_e===null||!Z){const Ge=await o.getGitFileDiff(d,{path:de});Z={original:Ge.original??"",modified:Ge.modified??"",isBinary:Ge.isBinary},g(d,de,Z)}const ie=_e??(Z.isBinary||ui(de)?1:gm(Z.original,Z.modified)),Ce=vN(d,de),He=await Rd(c,Ce);if(!He.ok){q.error(Fd(He.reason));return}oe(d,Ce,ie,1)}finally{fe(_e=>_e===de?null:_e)}}},[d,c,o,oe,g]),Ve=l.useCallback(async()=>{w&&await Te(w,ke)},[Te,ke,w]),G=!!(w&&be===w),Ie=!!he,Oe=!ne&&!!w&&!Ie;l.useEffect(()=>{if(ne)return;if(T(null),!d||!w){M.current=null;return}if(he){M.current=null;return}const de=`${d}::${w}::${P}`;if(M.current===de)return;M.current=de;let Ee=!1;const _e=o.getGitFileDiff(d,{path:w}),Z=Qc,ie=new Promise((Ce,He)=>{setTimeout(()=>He(new Error(`Timed out after ${Z}ms`)),Z)});return Promise.race([_e,ie]).then(Ce=>{Ee||g(d,w,{original:Ce.original??"",modified:Ce.modified??"",isBinary:Ce.isBinary})}).catch(Ce=>{if(Ee)return;const He=Ce instanceof Error?Ce.message:String(Ce);T(He)}),()=>{Ee=!0,M.current===de&&(M.current=null)}},[d,ne,w,he,o,g,P]);const De=()=>!d||!w||!ke?null:s.jsx(PN,{filePath:w,diff:ke,isVisible:!0,renderSideBySide:Ne,wrapLines:ae},w),ge=()=>{if(!d)return null;const de=fN(le.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:a("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:le.length})]}),s.jsx(SN,{changedFiles:le,selectedFile:w,onSelectFile:ce})]}),s.jsx(As,{ref:F,outerClassName:"flex-1 min-h-0 h-full",className:"pr-2",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx("div",{className:"flex flex-col gap-3",children:le.map((Ee,_e)=>s.jsx(AN,{directory:d,file:Ee,layout:ue(Ee),wrapLines:ae,scrollRootRef:F,isSelected:Ee.path===w,onSelect:X,registerSectionRef:W,defaultCollapsed:e?!0:_e>=de,expandRequestPath:S,expandRequestNonce:j,showOpenInEditorAction:i,isOpeningInEditor:be===Ee.path,onOpenInEditor:(Z,ie)=>{Te(Z,ie)}},Ee.path))})})]})},U=()=>d?b&&!f?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"animate-spin"}),a("diffView.state.loadingRepositoryStatus")]}):u===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:a("diffView.state.notGitRepository")}):le.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:a("diffView.state.cleanWorkingTree")}):ne?ge():s.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden px-3 py-3 relative","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[De(),Oe&&!Ie&&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:a("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:N}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{T(null),k(de=>de+1)},children:a("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"loader-4",className:"animate-spin"}),a("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:a("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(C,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:b&&!f?a("diffView.state.loadingChanges"):le.length===1?a("diffView.summary.changedFilesSingle",{count:le.length}):a("diffView.summary.changedFilesPlural",{count:le.length})})]}),!xe&&s.jsx(NN,{mode:_,onModeChange:ee}),Y&&s.jsx(jN,{changedFiles:le,selectedFile:w,selectedFileEntry:Se,onSelectFile:ce,isMobile:xe,showModeSelector:xe,mode:_,onModeChange:ee}),s.jsx("div",{className:"flex-1"}),Se&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>H(!B),className:pe("h-5 w-5 p-0 transition-opacity",ae?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:a(ae?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(C,{name:"text-wrap",className:"size-4"})}),i&&Se&&!ne&&s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Ve()},disabled:G,title:a("diffView.actions.openFileAtFirstChangedLine"),children:G?s.jsx(C,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(C,{name:"edit",className:"size-3.5"})}),Se&&je&&s.jsx(Rh,{mode:je==="side-by-side"?"side-by-side":"unified",onModeChange:Pe})]}),U()]})},DN=()=>{const t=rt.c(6),{git:e}=_n(),n=Or(),r=on(LN),i=on(ON),a=rb(n??null);let o,c;return t[0]!==n||t[1]!==i||t[2]!==e||t[3]!==r?(o=()=>{n&&(r(n),i(n,e))},c=[n,r,i,e],t[0]=n,t[1]=i,t[2]=e,t[3]=r,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c),a};function TN(t){return t.setDiff}function MN(t){return t.setDiffFileLayout}function EN(t){return t.isIntersecting}function RN(t,e){setTimeout(()=>e(new Error(`Timed out after ${Qc}ms`)),Qc)}function FN(t){return t+1}function LN(t){return t.setActiveDirectory}function ON(t){return t.ensureStatus}const $N=Object.freeze(Object.defineProperty({__proto__:null,DiffView:Rf,useDiffFileCount:DN},Symbol.toStringTag,{value:"Module"})),BN={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},_N={case:"Match case",re:"Regular expression",word:"Match whole word"};function VN(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(BN)){const i=e.querySelector(`button[name="${n}"]`);i&&!i.title&&(i.title=r)}for(const[n,r]of Object.entries(_N)){const a=e.querySelector(`input[name="${n}"]`)?.parentElement;a&&!a.title&&(a.title=r)}}}const xm=new bi,bm=new bi,ym=new bi,vm=new bi,wm=new bi,jm=new bi,Nm=t=>t,cc=Gg,zN=qg,UN=Jg;class WN extends Qg{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 Sm=(t,e)=>!t||t.length===0?[]:Hg.define({create(n){const r=new hh,i=[...t].sort((a,o)=>a.afterLine-o.afterLine);for(const a of i){const o=n.doc.lines;if(a.afterLine>o)continue;const c=n.doc.line(a.afterLine);r.add(c.to,c.to,fh.widget({widget:new WN(a.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>Jn.decorations.from(n)}),km=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return Kg.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 i=new hh;for(let a=e;a<=n&&a<=r.state.doc.lines;a+=1){const o=r.state.doc.line(a);i.add(o.from,o.from,fh.line({class:"oc-cm-selected-line"}))}return i.finish()}},{decorations:r=>r.decorations})};function Yc({value:t,onChange:e,extensions:n,className:r,readOnly:i,lineNumbersConfig:a,highlightLines:o,onViewReady:c,onViewDestroy:d,blockWidgets:p,enableSearch:m,searchOpen:u,onSearchOpenChange:f}){const b=l.useRef(null),h=l.useRef(null),v=l.useRef(t),x=l.useRef(e),g=l.useRef(c),w=l.useRef(d),y=l.useRef(f),S=l.useRef(p),D=l.useRef(new Map),[j,I]=l.useState([]),A=l.useCallback(P=>{const k=(P??[]).map(N=>{const T=D.current.get(N.id);return T?{id:N.id,content:N.content,container:T}:null}).filter(N=>N!==null);I(N=>N.length===k.length&&N.every((T,M)=>{const R=k[M];return T.id===R.id&&T.content===R.content&&T.container===R.container})?N:k)},[]),E=l.useCallback(P=>{const k=b.current,N=P??h.current;if(!k||!N)return;const T=N.dom.querySelector(".cm-gutters"),M=T instanceof HTMLElement?T.getBoundingClientRect().width:0;k.style.setProperty("--oc-editor-gutter-width",`${M}px`)},[]);return l.useEffect(()=>{v.current=t},[t]),l.useEffect(()=>{x.current=e},[e]),l.useEffect(()=>{g.current=c,w.current=d},[c,d]),l.useEffect(()=>{y.current=f},[f]),l.useEffect(()=>{S.current=p,A(p)},[p,A]),l.useEffect(()=>{if(!b.current)return;const P=(()=>{if(typeof document>"u")return null;const N=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(N)return N;const T=window.__OPENCHAMBER_CSP_NONCE__;return typeof T=="string"&&T.length>0?T:null})(),k=$g.create({doc:v.current,extensions:[...P?[Jn.cspNonce.of(P)]:[],Bg({fixed:!0}),xm.of(Gd(a)),_g(),Vg.of(" "),Ll.of([zg,...Ug,...Wg]),Jn.updateListener.of(N=>{E(N.view),(N.viewportChanged||N.geometryChanged)&&A(S.current);const T=qd(N.startState),M=qd(N.state);if(T!==M&&y.current?.(M),!N.docChanged)return;const R=N.state.doc.toString();v.current=R,x.current(R),A(S.current)}),bm.of(Jn.editable.of(!i)),ym.of(n??[]),vm.of(km(o)),wm.of(Sm(p,D.current)),jm.of(m?[Jd({top:!0}),Ll.of(Nm(Qd))]:[])]});return h.current=new Jn({state:k,parent:b.current}),cc(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{E(h.current),A(S.current)}),h.current&&g.current?.(h.current),()=>{w.current?.(),h.current?.destroy(),h.current=null,I([])}},[S,E,A]),l.useEffect(()=>{const P=h.current;P&&(P.dispatch({effects:[xm.reconfigure(Gd(a)),bm.reconfigure(Jn.editable.of(!i)),ym.reconfigure(n??[]),vm.reconfigure(km(o)),wm.reconfigure(Sm(p,D.current)),jm.reconfigure(m?[Jd({top:!0}),Ll.of(Nm(Qd))]:[])]}),cc(P,P.state.doc.length,200),P.requestMeasure(),requestAnimationFrame(()=>{E(P),A(S.current)}))},[n,o,a,i,p,m,E,A]),l.useEffect(()=>{const P=h.current;!P||m===!1||(u?(zN(P),requestAnimationFrame(()=>{VN(P.dom)})):UN(P))},[u,m]),l.useEffect(()=>{const P=h.current;if(!P)return;const k=P.state.doc.toString();k!==t&&(P.dispatch({changes:{from:0,to:k.length,insert:t}}),cc(P,P.state.doc.length,300),P.requestMeasure(),requestAnimationFrame(()=>E(P)))},[t,E]),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(P=>Li.createPortal(P.content,P.container,P.id))]})}const KN=(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)},Cm=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Im=(t,e,n)=>{const r=t.state.doc.line(e),i=Math.max(1,Math.min(n,r.length+1)),a=r.from+i-1;t.dispatch({selection:Yg.cursor(a),effects:Jn.scrollIntoView(a,{y:"center"})})};function HN({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:i}=mt(),[a,o]=l.useState(""),c=l.useRef(null),d=l.useRef(!1),p=l.useRef(null),m=l.useRef(null),u=l.useMemo(()=>KN(a,n),[a,n]);l.useEffect(()=>{!t||!n||(d.current=!1,c.current=Cm(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:Jn.scrollIntoView(x.main.from,{y:"center"})});return}Im(n,u,c.current.character)}},[u,t,n]);const f=l.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:x}=c.current;n.dispatch({selection:x,effects:Jn.scrollIntoView(x.main.from,{y:"center"})})},[n]),b=l.useCallback(x=>{x||f(),e(x)},[e,f]),h=l.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,Im(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);l.useEffect(()=>{if(!t)return;const x=w=>{const y=p.current,S=w.target;!y||!(S instanceof Node)||y.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 v=l.useMemo(()=>{if(!n)return i("goToLineDialog.helper.editorUnavailable");if(u===null){const x=c.current??Cm(n,n.state.selection);return i("goToLineDialog.helper.currentLineRange",{current:x.lineNumber,max:n.state.doc.lines})}return i("goToLineDialog.helper.goToLine",{line:u})},[u,i,n]);return r==="inline"?t?s.jsxs("div",{ref:p,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Ut,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:a,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:i("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(ve,{variant:"outline",size:"xs",onClick:h,disabled:!n||u===null,className:"h-6 px-2",children:i("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(Ut,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:a,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:i("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:v})]})})}const Xc=t=>{const e=rt.c(11),{currentMode:n,onToggle:r}=t,i=n==="preview",a=i?"Switch to edit mode":"Switch to preview mode",o=i?"Edit":"Preview";let c;e[0]!==i?(c=i?s.jsx(C,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(C,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=i,e[1]=c):c=e[1];let d;e[2]!==a||e[3]!==r||e[4]!==c?(d=s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:r,"aria-label":a,className:"h-5 w-5 p-0",children:c})}),e[2]=a,e[3]=r,e[4]=c,e[5]=d):d=e[5];let p;e[6]!==o?(p=s.jsx(Pt,{sideOffset:8,children:o}),e[6]=o,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs(Ct,{children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},Zc=Xg.define(Zg);function GN(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return Zc;case"json":case"jsonc":case"json5":return bh().language;case"js":case"javascript":return Za().language;case"jsx":return Za({jsx:!0}).language;case"ts":case"typescript":return Za({typescript:!0}).language;case"tsx":return Za({typescript:!0,jsx:!0}).language;case"html":return Rc().language;case"css":return xh().language;case"py":case"python":return gh().language;case"heex":case"eex":case"leex":return Rc().language;default:return yh.matchLanguageName(vh,e,!0)}}const Ff=t=>t.split("/").pop()?.toLowerCase()??"",qN=t=>{const e=Ff(t);return e?yh.matchFilename(vh,e):null},JN=()=>Di(Fc.define([{tag:[ot.heading1,ot.heading2,ot.heading3,ot.heading4,ot.heading5,ot.heading6],fontWeight:"600"},{tag:ot.strong,fontWeight:"600"},{tag:ot.emphasis,fontStyle:"italic"},{tag:ot.strikethrough,textDecoration:"line-through"},{tag:[ot.link,ot.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:ot.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:ot.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:ot.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:ot.heading,color:"var(--markdown-heading1, currentColor)"}]));function Lf(t){const e=t.toLowerCase();switch(Ff(e)){case"makefile":case"gnumakefile":return Zc}const r=e.lastIndexOf("."),i=r>=0?e.slice(r+1):"";switch(i){case"ts":case"tsx":case"mts":case"cts":return Za({typescript:!0,jsx:i==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return Za({typescript:!1,jsx:i==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return bh();case"css":case"scss":case"sass":case"less":return xh();case"html":case"htm":return Rc();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[ex({codeLanguages:GN}),JN()];case"sh":case"bash":case"zsh":case"fish":case"env":return Zc;case"py":case"pyw":case"pyi":return gh();default:return null}}async function QN(t){const e=qN(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function ed(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},i=t.colors.syntax.tokens||{},a=Jn.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:i.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:i.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:i.boolean||t.colors.syntax.base.number},".cm-builtin":{color:i.functionCall||t.colors.syntax.base.function},".cm-def":{color:i.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:i.variableOther||i.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:i.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:i.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:i.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:i.tag||t.colors.syntax.base.keyword},".cm-link":{color:i.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=Fc.define([{tag:[ot.comment,ot.docComment,ot.meta,ot.documentMeta],class:"cm-comment"},{tag:[ot.keyword,ot.controlKeyword,ot.moduleKeyword,ot.definitionKeyword,ot.modifier],class:"cm-keyword"},{tag:[ot.operatorKeyword,ot.operator,ot.derefOperator,ot.updateOperator,ot.definitionOperator,ot.typeOperator,ot.controlOperator,ot.logicOperator,ot.bitwiseOperator,ot.arithmeticOperator,ot.compareOperator],class:"cm-operator"},{tag:[ot.punctuation,ot.separator,ot.bracket,ot.paren,ot.brace,ot.squareBracket,ot.angleBracket],class:"cm-punctuation"},{tag:[ot.string,ot.regexp,ot.attributeValue,ot.special(ot.string),ot.monospace],class:"cm-string"},{tag:ot.escape,class:"cm-string-2"},{tag:[ot.number,ot.bool,ot.atom,ot.null,ot.self],class:"cm-number"},{tag:[ot.function(ot.variableName),ot.function(ot.definition(ot.variableName)),ot.function(ot.propertyName),ot.standard(ot.variableName),ot.special(ot.variableName)],class:"cm-builtin"},{tag:ot.definition(ot.variableName),class:"cm-def"},{tag:[ot.variableName,ot.local(ot.variableName),ot.constant(ot.variableName),ot.literal],class:"cm-variable"},{tag:ot.propertyName,class:"cm-property"},{tag:ot.attributeName,class:"cm-attribute"},{tag:[ot.className,ot.typeName,ot.namespace],class:"cm-variable-3"},{tag:[ot.tagName,ot.labelName,ot.annotation,ot.macroName],class:"cm-tag"},{tag:ot.link,class:"cm-link"},{tag:[ot.heading,ot.heading1,ot.heading2,ot.heading3,ot.heading4,ot.heading5,ot.heading6],class:"cm-keyword"}]),c=Fc.define([{tag:[ot.comment,ot.docComment,ot.meta,ot.documentMeta],color:t.colors.syntax.base.comment},{tag:[ot.keyword,ot.controlKeyword,ot.moduleKeyword,ot.definitionKeyword,ot.modifier],color:t.colors.syntax.base.keyword},{tag:[ot.operatorKeyword,ot.operator,ot.derefOperator,ot.updateOperator,ot.definitionOperator,ot.typeOperator,ot.controlOperator,ot.logicOperator,ot.bitwiseOperator,ot.arithmeticOperator,ot.compareOperator],color:t.colors.syntax.base.operator},{tag:[ot.string,ot.regexp,ot.attributeValue,ot.special(ot.string),ot.monospace],color:t.colors.syntax.base.string},{tag:ot.escape,color:i.stringEscape||t.colors.syntax.base.string},{tag:[ot.number,ot.bool,ot.atom,ot.null,ot.self],color:t.colors.syntax.base.number},{tag:[ot.function(ot.variableName),ot.function(ot.definition(ot.variableName)),ot.function(ot.propertyName),ot.standard(ot.variableName),ot.special(ot.variableName)],color:t.colors.syntax.base.function},{tag:ot.definition(ot.variableName),color:i.variableGlobal||t.colors.syntax.base.variable},{tag:[ot.variableName,ot.local(ot.variableName),ot.constant(ot.variableName),ot.literal],color:t.colors.syntax.base.variable},{tag:ot.propertyName,color:i.variableProperty||t.colors.syntax.base.variable},{tag:ot.attributeName,color:i.variableOther||t.colors.syntax.base.variable},{tag:[ot.className,ot.typeName,ot.namespace],color:t.colors.syntax.base.type},{tag:[ot.tagName,ot.labelName,ot.annotation,ot.macroName],color:i.tag||t.colors.syntax.base.keyword},{tag:ot.link,color:i.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[ot.punctuation,ot.separator,ot.bracket,ot.paren,ot.brace,ot.squareBracket,ot.angleBracket],color:i.punctuation||t.colors.syntax.base.comment}]);return[a,Di(tx,{fallback:!0}),Di(sx),Di(o),Di(c)]}const YN=t=>{const e=bn(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},XN=t=>{const e=rt.c(8),{label:n,iconDataUrl:r}=t,[i,a]=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&&!i){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>a(!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},ZN=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),bn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const i=r==="/",a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,"")),r},e2=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Pm=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,pl=(t,e)=>{const n=bn(e),r=bn(t);if(!n||!r)return!1;const i=Pm(n),a=Pm(r);return a===i||a.startsWith(`${i}/`)},Am=(t,e)=>{const n=bn(e),r=bn(t);if(!pl(r,n))return[];const a=r.slice(n.length).replace(/^\//,"").split("/"),o=[];let c=n;for(let d=0;d<a.length-1;d++)c=c?`${c}/${a[d]}`:a[d],o.push(c);return o},td=(t,e)=>{if(!e)return"";const n=bn(e);if(!t||!pl(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},t2=new Set(["node_modules"]),s2=t=>{const e=rt.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 i=r[n];let a;return e[1]!==i?(a=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:i}}),e[1]=i,e[2]=a):a=e[2],a},n2=t=>t2.has(t),r2=t=>{const e=bn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},a2=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},ki=2e5,Of="openchamber:files:auto-save-enabled",i2=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Of)!=="false"}catch{return!0}},$f=(t,e)=>s.jsx(yr,{filePath:t,extension:e}),o2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},l2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},dc=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},c2=t=>{const e=rt.c(62),{node:n,root:r,isExpanded:i,isActive:a,isMobile:o,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:f,setContextMenuPath:b,onSelect:h,onToggle:v,onRevealPath:x,onOpenDialog:g}=t,{t:w}=mt(),y=n.type==="directory",{canRename:S,canCreateFile:D,canCreateFolder:j,canDelete:I,canReveal:A}=m;let E;e[0]!==D||e[1]!==j||e[2]!==I||e[3]!==S||e[4]!==A||e[5]!==n.path||e[6]!==b?(E=ne=>{!S&&!D&&!j&&!I&&!A||(ne?.preventDefault(),b(n.path))},e[0]=D,e[1]=j,e[2]=I,e[3]=S,e[4]=A,e[5]=n.path,e[6]=b,e[7]=E):E=e[7];const P=E;let k;e[8]!==y||e[9]!==n||e[10]!==h||e[11]!==v?(k=()=>{y?v(n.path):h(n)},e[8]=y,e[9]=n,e[10]=h,e[11]=v,e[12]=k):k=e[12];const N=k;let T;e[13]!==n.path||e[14]!==b?(T=ne=>{ne.stopPropagation(),b(n.path)},e[13]=n.path,e[14]=b,e[15]=T):T=e[15];const M=T,R=o?void 0:P,L=o?void 0:P,O=a?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[16]!==O?(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",O),e[16]=O,e[17]=V):V=e[17];let $;e[18]!==y||e[19]!==i||e[20]!==n.extension||e[21]!==n.path?($=y?i?s.jsx(C,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(C,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):$f(n.path,n.extension),e[18]=y,e[19]=i,e[20]=n.extension,e[21]=n.path,e[22]=$):$=e[22];let B;e[23]!==n.name||e[24]!==n.path?(B=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]=B):B=e[25];let H;e[26]!==y||e[27]!==d?(H=!y&&d&&s.jsx(s2,{status:d}),e[26]=y,e[27]=d,e[28]=H):H=e[28];let _;e[29]!==p||e[30]!==y?(_=y&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[29]=p,e[30]=y,e[31]=_):_=e[31];let se;e[32]!==N||e[33]!==H||e[34]!==_||e[35]!==L||e[36]!==V||e[37]!==$||e[38]!==B?(se=s.jsxs("button",{type:"button",onClick:N,onContextMenu:L,className:V,children:[$,B,H,_]}),e[32]=N,e[33]=H,e[34]=_,e[35]=L,e[36]=V,e[37]=$,e[38]=B,e[39]=se):se=e[39];let oe;e[40]!==c||e[41]!==D||e[42]!==j||e[43]!==I||e[44]!==S||e[45]!==A||e[46]!==f||e[47]!==u||e[48]!==M||e[49]!==y||e[50]!==o||e[51]!==n||e[52]!==g||e[53]!==x||e[54]!==r||e[55]!==b||e[56]!==w?(oe=(S||D||j||I||A)&&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(Bs,{open:f===n.path,onOpenChange:ne=>b(ne?n.path:null),children:[s.jsx(Os,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:M,children:s.jsx(C,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsxs($s,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:[S&&s.jsxs(zt,{onClick:ne=>{ne.stopPropagation(),g("rename",n)},children:[s.jsx(C,{name:"edit",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.rename")]}),s.jsxs(zt,{onClick:ne=>{ne.stopPropagation(),Rn(n.path).then(xe=>{if(xe.ok){q.success(w("sidebarFilesTree.toast.pathCopied"));return}q.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(C,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.copyPath")]}),s.jsxs(zt,{onClick:ne=>{ne.stopPropagation();const xe=td(r,n.path)||n.path;Rn(xe).then(te=>{if(te.ok){q.success(w("filesView.toast.relativePathCopied"));return}q.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(C,{name:"file-copy-2",className:"mr-2 h-4 w-4"})," ",w("filesView.tree.menu.copyRelativePath")]}),!y&&u&&s.jsxs(zt,{onClick:ne=>{ne.stopPropagation(),u(n.path)},children:[s.jsx(C,{name:"download",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.save")]}),A&&s.jsxs(zt,{onClick:ne=>{ne.stopPropagation(),x(n.path)},children:[s.jsx(C,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",w(kd())]}),y&&(D||j)&&s.jsxs(s.Fragment,{children:[s.jsx(An,{}),D&&s.jsxs(zt,{onClick:ne=>{ne.stopPropagation(),g("createFile",n)},children:[s.jsx(C,{name:"file-add",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs(zt,{onClick:ne=>{ne.stopPropagation(),g("createFolder",n)},children:[s.jsx(C,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFolder")]})]}),I&&s.jsxs(s.Fragment,{children:[s.jsx(An,{}),s.jsxs(zt,{onClick:ne=>{ne.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=D,e[42]=j,e[43]=I,e[44]=S,e[45]=A,e[46]=f,e[47]=u,e[48]=M,e[49]=y,e[50]=o,e[51]=n,e[52]=g,e[53]=x,e[54]=r,e[55]=b,e[56]=w,e[57]=oe):oe=e[57];let ae;return e[58]!==se||e[59]!==oe||e[60]!==R?(ae=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:R,children:[se,oe]}),e[58]=se,e[59]=oe,e[60]=R,e[61]=ae):ae=e[61],ae},Bf=({mode:t="full"})=>{const{t:e}=mt(),{files:n,runtime:r}=_n(),{currentTheme:i,availableThemes:a,lightThemeId:o,darkThemeId:c}=Nr(),{isMobile:d,isTablet:p,screenWidth:m}=rn(),u=d||p,f=jl(),b=Nd(),h=Or()??"",v=bn(h.trim()),x=d||t!=="editor-only",g=t==="editor-only"&&!d,w=Sd(Ae=>Ae.searchFiles),y=wl(h),[S,D]=l.useState(""),j=Nl(S,200),I=l.useRef(null),[A,E]=l.useState(!1),[P,k]=l.useState(!0),[N,T]=l.useState(!1),[M,R]=l.useState(!1),[L,O]=l.useState(!1),V=l.useRef(null),$=l.useRef(0),B=l.useCallback(Ae=>{$.current=Math.max(0,$.current+(Ae?1:-1))},[]),H=l.useCallback(Ae=>Ae instanceof Element?Ae.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);l.useEffect(()=>{if(!L)return;const Ae=Qe=>{$.current>0||H(Qe.target)||V.current&&!V.current.contains(Qe.target)&&O(!1)};return document.addEventListener("mousedown",Ae),()=>document.removeEventListener("mousedown",Ae)},[H,L]);const[_,se]=l.useState("edit"),[oe,ae]=l.useState("edit"),[ne,xe]=l.useState("tree"),[te,F]=l.useState("edit"),z=l.useRef({}),Q=l.useRef({}),re=l.useRef({}),K=l.useMemo(()=>a.find(Ae=>Ae.metadata.id===o)??ci(!1),[a,o]),le=l.useMemo(()=>a.find(Ae=>Ae.metadata.id===c)??ci(!0),[a,c]);l.useEffect(()=>{di(K),di(le)},[K,le]);const Se=l.useMemo(()=>[],[]),ue=$n(Ae=>v?Ae.byRoot[v]?.openPaths??Se:Se),je=$n(Ae=>v?Ae.byRoot[v]?.selectedPath??null:null),W=$n(Ae=>v?Ae.byRoot[v]?.expandedPaths??Se:Se),me=$n(Ae=>Ae.addOpenPath),X=$n(Ae=>Ae.removeOpenPath),ce=$n(Ae=>Ae.removeOpenPathsByPrefix),ee=$n(Ae=>Ae.setSelectedPath),Pe=$n(Ae=>Ae.toggleExpandedPath),Ne=$n(Ae=>Ae.expandPaths),Y=l.useCallback(Ae=>{const Qe=bn(Ae),ht=Qe.split("/"),gt=ht[ht.length-1]||Qe,$t=gt.includes(".")?gt.split(".").pop()?.toLowerCase():void 0;return{name:gt,path:Qe,type:"file",extension:$t}},[]),he=l.useMemo(()=>ue.map(Y),[ue,Y]),ke=l.useMemo(()=>je??ue[0]??null,[ue,je]),be=l.useMemo(()=>ke?Y(ke):null,[ke,Y]),fe=be?.path??"",Te=!!(v&&fe&&!pl(fe,v)),Ve=l.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Te}),[t,Te]),G=l.useRef(null),[Ie,Oe]=l.useState({left:!1,right:!1}),De=l.useCallback(()=>{const Ae=G.current;Ae&&Oe({left:Ae.scrollLeft>2,right:Ae.scrollLeft+Ae.clientWidth<Ae.scrollWidth-2})},[]);l.useEffect(()=>{const Ae=G.current;if(!Ae)return;De(),Ae.addEventListener("scroll",De,{passive:!0});const Qe=new ResizeObserver(De);return Qe.observe(Ae),()=>{Ae.removeEventListener("scroll",De),Qe.disconnect()}},[De,he.length]);const[ge,U]=l.useState({}),de=l.useRef(new Set),Ee=l.useRef(new Set),_e=l.useRef(new Map),Z=l.useRef(0),[ie,Ce]=l.useState([]),[He,Ge]=l.useState(!1),[Xe,we]=l.useState(""),[tt,st]=l.useState(!1),[qe,it]=l.useState(null),[lt,ye]=l.useState(""),[Je,Be]=l.useState(null),[ze,nt]=l.useState(""),[Ye,Ue]=l.useState(!1),vt=l.useRef(null),Et=l.useRef(null),Gt=l.useRef(0),[ts,Nt]=l.useState("idle"),[St,Zt]=l.useState(i2),[ut,Xt]=l.useState(!1),as=l.useRef(null),Bt=l.useRef(null),ls=l.useRef(null),gs=l.useRef(!1),us=l.useRef(null),xs=l.useRef(null),At=l.useRef(null),We=l.useRef(null),[Rt,Dt]=l.useState(0),wt=l.useRef(null),Jt=l.useRef({key:"",attempts:0});l.useEffect(()=>()=>{wt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(wt.current),wt.current=null)},[]);const[_t,Fs]=l.useState(null),[ft,ds]=l.useState(null),[Qt,ks]=l.useState(""),[_s,J]=l.useState(!1),[pt,jt]=l.useState(null),[Wt,es]=l.useState(!1),[ns,Cs]=l.useState(!1),[Is,Ke]=l.useState(!1),xt=!!n.writeFile,kt=!!n.createDirectory,Tt=!!n.rename,ss=!!n.delete,at=!!n.revealPath,Lt=Pr(Ae=>Ae.availableApps),os=Pr(Ae=>Ae.isCacheStale),rs=Pr(Ae=>Ae.initialize),Vt=Pr(Ae=>Ae.loadInstalledApps);l.useEffect(()=>{rs()},[rs]);const cs=l.useCallback(Ae=>{n.revealPath&&n.revealPath(Ae).catch(()=>{q.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),sn=l.useCallback(async Ae=>{if(!be?.path||await ab(be.path,Ae.id,Ae.appName)||await Zo(be.path,Ae.appName))return;const gt=YN(be.path)||v;gt&&await Zo(gt,Ae.appName)||q.error(e("filesView.toast.openInAppFailed",{app:Ae.appName}))},[v,be?.path,e]),Js=l.useCallback((Ae,Qe)=>{Fs(Ae),ds(Qe),ks(Ae==="rename"&&Qe.name||""),J(!1)},[]),[Us,ln]=l.useState(null),nn=l.useRef(!1),cn=l.useRef(null),[un,jn]=l.useState(!1),an=Me(Ae=>Ae.setMainTabGuard),gn=Me(Ae=>Ae.pendingFileNavigation),pr=Me(Ae=>Ae.setPendingFileNavigation),Fn=Me(Ae=>Ae.pendingFileFocusPath),Dn=Me(Ae=>Ae.setPendingFileFocusPath),Tn=Me(Ae=>Ae.shortcutOverrides),Fe=yt(Ae=>Ae.settingsDefaultFileViewerPreview);l.useEffect(()=>{const Ae=()=>{nn.current=!1,cn.current=null,jn(!1)};return document.addEventListener("mouseup",Ae),()=>document.removeEventListener("mouseup",Ae)},[]),l.useEffect(()=>()=>{us.current!==null&&window.clearTimeout(us.current),xs.current!==null&&window.clearTimeout(xs.current)},[]);const Mt=l.useCallback((Ae,Qe)=>{const ht=Ae.split(`
|
|
48
|
-
`),gt=Math.max(1,Qe.start),$t=Math.min(ht.length,Qe.end);return gt>$t?"":ht.slice(gt-1,$t).join(`
|
|
49
|
-
`)},[]),is=Ld({source:"file",fileLabel:be?.path??null,language:be?.path&&Ui(be.path)||"text",getCodeForRange:Ae=>Mt(Xe,ul(Ae)),toStoreRange:Ae=>({startLine:Ae.start,endLine:Ae.end}),fromDraftRange:Ae=>({start:Ae.startLine,end:Ae.endLine})}),{drafts:ms,commentText:qs,editingDraftId:Vs,setSelection:Ds,saveComment:Xs,cancel:hn,reset:tr,startEdit:Sn,deleteDraft:Mr}=is;l.useEffect(()=>{ln(null),tr(),an(null),nt(""),Ue(!1)},[be?.path,tr,an]),l.useEffect(()=>{Ds(Us)},[Us,Ds]),l.useEffect(()=>{if(!Us&&!Vs)return;const Ae=ht=>{const gt=ht.target;gt.closest('[data-comment-input="true"]')||gt.closest('[data-comment-card="true"]')||gt.closest(".cm-gutterElement")||gt.closest("[data-sonner-toast]")||gt.closest("[data-sonner-toaster]")||(ln(null),hn())},Qe=setTimeout(()=>{document.addEventListener("click",Ae)},100);return()=>{clearTimeout(Qe),document.removeEventListener("click",Ae)}},[hn,Vs,Us]);const Sr=l.useCallback((Ae,Qe)=>{const ht=Qe??Us??void 0;Qe&&ln(Qe),Xs(Ae,ht),ln(null)},[Us,Xs]),kr=l.useCallback((Ae,Qe)=>{const ht=Qe.filter(gt=>gt&&typeof gt.name=="string"&>.name.length>0).filter(gt=>f||!gt.name.startsWith(".")).filter(gt=>b||!n2(gt.name)).map(gt=>{const $t=gt.name,qt=bn(gt.path||""),Ms=qt?e2(qt)?qt:bn(`${Ae}/${qt}`):bn(`${Ae}/${$t}`),Hs=gt.isDirectory?"directory":"file",zn=Hs==="file"&&$t.includes(".")?$t.split(".").pop()?.toLowerCase():void 0;return{name:$t,path:Ms,type:Hs,extension:zn}});return ZN(ht)},[b,f]),Zs=l.useCallback(async Ae=>{const Qe=bn(Ae.trim());if(!Qe||de.current.has(Qe)||Ee.current.has(Qe))return;Ee.current=new Set(Ee.current),Ee.current.add(Qe);const ht=Z.current+1;Z.current=ht,_e.current=new Map(_e.current),_e.current.set(Qe,ht);const gt=()=>_e.current.get(Qe)===ht,$t=!b;await(r.isDesktop?n.listDirectory(Qe,{respectGitignore:$t}).then(Ms=>Ms.entries.map(Hs=>({name:Hs.name,path:Hs.path,isDirectory:Hs.isDirectory}))):In.listLocalDirectory(Qe,{respectGitignore:$t}).then(Ms=>Ms.map(Hs=>({name:Hs.name,path:Hs.path,isDirectory:Hs.isDirectory})))).then(Ms=>{if(!gt())return;const Hs=kr(Qe,Ms);de.current=new Set(de.current),de.current.add(Qe),U(zn=>({...zn,[Qe]:Hs}))}).catch(()=>{gt()&&U(Ms=>({...Ms,[Qe]:Ms[Qe]??[]}))}).finally(()=>{gt()&&(_e.current=new Map(_e.current),_e.current.delete(Qe),Ee.current=new Set(Ee.current),Ee.current.delete(Qe))})},[n,kr,r.isDesktop,b]),Yn=l.useCallback(async()=>{v&&(de.current=new Set,Ee.current=new Set,_e.current=new Map,U(Ae=>Object.keys(Ae).length===0?Ae:{}),await Zs(v))},[Zs,v]),kn=l.useCallback(async Ae=>{if(!Ae){await Yn();return}const Qe=bn(Ae);de.current=new Set(de.current),de.current.delete(Qe),Ee.current=new Set(Ee.current),Ee.current.delete(Qe),await Zs(Qe)},[Zs,Yn]),Xn=l.useRef(""),hr=l.useRef("");l.useEffect(()=>{if(!v)return;const Ae=`${v}|h${f?"1":"0"}|g${b?"1":"0"}`,Qe=Xn.current!==v,ht=hr.current!==Ae;!Qe&&!ht||(Qe&&(Xn.current=v,we(""),it(null),ye(""),Be(null),E(!1)),ht&&(hr.current=Ae,de.current=new Set,Ee.current=new Set,_e.current=new Map,U(gt=>Object.keys(gt).length===0?gt:{}),Zs(v)))},[Zs,v,b,f]),l.useEffect(()=>{if(!n.listDirectory)return;const Ae=()=>{if(!document.hidden&&W.length>0)for(const Qe of W)kn(Qe)};return document.addEventListener("visibilitychange",Ae),()=>document.removeEventListener("visibilitychange",Ae)},[W,n.listDirectory,kn]),l.useEffect(()=>{if(!n.listDirectory||W.length===0)return;const Ae=setInterval(()=>{if(!document.hidden)for(const Qe of W)kn(Qe)},8e3);return()=>clearInterval(Ae)},[W,n.listDirectory,kn]);const Er=l.useCallback(async Ae=>{if(Ae?.preventDefault(),!ft||!_t)return;J(!0);const Qe=()=>{Fs(null)},ht=$t=>{q.error($t)},gt=()=>{J(!1)};if(_t==="createFile"){if(!Qt.trim()){ht(e("sidebarFilesTree.toast.filenameRequired")),gt();return}if(!n.writeFile){ht(e("sidebarFilesTree.toast.writeNotSupported")),gt();return}const $t=ft.path,qt=$t?`${$t}/`:"",Ms=bn(`${qt}${Qt.trim()}`);await n.writeFile(Ms,"").then(async Hs=>{Hs.success&&(q.success(e("sidebarFilesTree.toast.fileCreated")),await kn($t)),Qe()}).catch(()=>ht(e("sidebarFilesTree.toast.operationFailed"))).finally(gt);return}if(_t==="createFolder"){if(!Qt.trim()){ht(e("sidebarFilesTree.toast.folderNameRequired")),gt();return}const $t=ft.path,qt=$t?`${$t}/`:"",Ms=bn(`${qt}${Qt.trim()}`);await n.createDirectory(Ms).then(async Hs=>{Hs.success&&(q.success(e("sidebarFilesTree.toast.folderCreated")),await kn($t)),Qe()}).catch(()=>ht(e("sidebarFilesTree.toast.operationFailed"))).finally(gt);return}if(_t==="rename"){if(!Qt.trim()){ht(e("sidebarFilesTree.toast.nameRequired")),gt();return}if(!n.rename){ht(e("sidebarFilesTree.toast.renameNotSupported")),gt();return}const $t=ft.path,qt=$t.split("/").slice(0,-1).join("/"),Ms=qt?`${qt}/`:"",Hs=bn(`${Ms}${Qt.trim()}`);await n.rename($t,Hs).then(async zn=>{zn.success&&(q.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await kn(qt),v&&ce(v,$t),(be?.path===$t||be?.path.startsWith(`${$t}/`))&&(v&&ee(v,null),we(""),it(null),ye(""),Be(null),d&&E(!1))),Qe()}).catch(()=>ht(e("sidebarFilesTree.toast.operationFailed"))).finally(gt);return}if(_t==="delete"){if(!n.delete){ht(e("sidebarFilesTree.toast.deleteNotSupported")),gt();return}const $t=ft.path,qt=$t.split("/").slice(0,-1).join("/");await n.delete($t).then(async Ms=>{Ms.success&&(q.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await kn(qt),v&&ce(v,$t),(be?.path===$t||be?.path.startsWith(`${$t}/`))&&(v&&ee(v,null),we(""),it(null),ye(""),Be(null),d&&E(!1))),Qe()}).catch(()=>ht(e("sidebarFilesTree.toast.operationFailed"))).finally(gt);return}gt()},[_t,ft,Qt,n,kn,d,ce,v,be?.path,ee,e]);l.useEffect(()=>{if(!h){Ce([]),Ge(!1);return}const Ae=j.trim();if(!Ae){Ce([]),Ge(!1);return}let Qe=!1;return Ge(!0),w(h,Ae,150,{includeHidden:f,respectGitignore:!b,type:"file"}).then(ht=>{if(Qe)return;const $t=ht.filter(qt=>b||!r2(qt.path)).map(qt=>({name:qt.name,path:bn(qt.path),type:"file",extension:qt.extension,relativePath:qt.relativePath}));Ce($t)}).catch(()=>{Qe||Ce([])}).finally(()=>{Qe||Ge(!1)}),()=>{Qe=!0}},[h,j,w,f,b]);const fr=l.useCallback(async(Ae,Qe)=>{if(n.readFile)return(await n.readFile(Ae,Qe)).content??"";const ht=new URLSearchParams({path:Ae});Qe?.allowOutsideWorkspace&&ht.set("allowOutsideWorkspace","true"),Qe?.optional&&ht.set("optional","true");const gt=await fetch(`/api/fs/read?${ht.toString()}`,{cache:Qe?.optional?"no-store":"default"});if(!gt.ok){const $t=await gt.json().catch(()=>({error:gt.statusText}));throw new Error($t.error||e("filesView.error.readFileFailed"))}return gt.text()},[n,e]),Ln=l.useCallback(async(Ae,Qe)=>{if(n.statFile){const ht=await n.statFile(Ae,Qe);return{path:ht.path,size:ht.size,mtimeMs:ht.mtimeMs}}return null},[n]),fn=l.useMemo(()=>Xe.length>ki?`${Xe.slice(0,ki)}
|
|
50
|
-
|
|
51
|
-
… truncated …`:Xe,[Xe]),en=l.useMemo(()=>ze!==fn,[ze,fn]),gr=l.useCallback(async()=>{if(!be||!n.writeFile)return q.error(e("filesView.toast.savingNotSupported")),!1;if(!en)return!0;Ue(!0);try{return(await n.writeFile(be.path,ze))?.success?(we(ze),Ln(be.path).then(Qe=>{Qe&&(Et.current=Qe)}).catch(()=>{}),!0):(q.error(e("filesView.toast.writeFileFailed")),!1)}catch(Ae){return q.error(Ae instanceof Error?Ae.message:e("filesView.toast.saveFailed")),!1}finally{Ue(!1)}},[ze,n,en,Ln,be,e]);l.useEffect(()=>{if(!en){an(null);return}const Ae=Qe=>gs.current?(gs.current=!1,!0):(Xt(!0),Bt.current=Qe,!1);return an(Ae),()=>{Me.getState().mainTabGuard===Ae&&an(null)}},[en,an]),l.useEffect(()=>{try{window.localStorage.setItem(Of,St?"true":"false")}catch{}},[St]),l.useEffect(()=>{St||(Nt("idle"),vt.current&&(clearTimeout(vt.current),vt.current=null))},[St]);const Rr=1500;l.useEffect(()=>{const Ae=!!(be&&n.writeFile);if(!(!St||!en||!Ae||Ye))return vt.current=setTimeout(()=>{gr().then(Qe=>{Qe&&(Nt("saved"),setTimeout(()=>Nt("idle"),2e3))})},Rr),()=>{vt.current&&(clearTimeout(vt.current),vt.current=null)}},[St,ze,en,be,n.writeFile,Ye,gr]),l.useEffect(()=>{Nt("idle")},[be?.path]),l.useEffect(()=>{const Ae=Qe=>{wd(Qe)&&(Qe.key.toLowerCase()==="s"?(Qe.preventDefault(),vt.current&&(clearTimeout(vt.current),vt.current=null),Ye||gr().then(ht=>{ht&&(Nt("saved"),setTimeout(()=>Nt("idle"),2e3))})):Qe.key.toLowerCase()==="f"&&(Qe.preventDefault(),R(!0)))};return window.addEventListener("keydown",Ae),()=>window.removeEventListener("keydown",Ae)},[Ye,gr]);const Ra=l.useCallback(async Ae=>{const Qe=Gt.current+1;Gt.current=Qe;const ht=()=>{if(!v)return!1;const Ms=$n.getState().byRoot[v],Hs=Ms?.selectedPath??Ms?.openPaths[0]??null;return Gt.current===Qe&&Hs===Ae.path};it(null),ye(""),Be(null);const gt=ui(Ae.path),$t=Ae.path.toLowerCase().endsWith(".svg");if(d&&E(!0),r.isDesktop&>&&!$t){we(""),nt(""),st(!0);return}if(!r.isDesktop&>&&!$t){we(""),nt(""),Be(Ae.path),st(!1);return}st(!0);const qt={allowOutsideWorkspace:t==="editor-only"&&!!v&&!pl(Ae.path,v)};await fr(Ae.path,qt).then(Ms=>{ht()&&(we(Ms),nt(Ms.length>ki?`${Ms.slice(0,ki)}
|
|
52
|
-
|
|
53
|
-
… truncated …`:Ms),Be(Ae.path),Ln(Ae.path,qt).then(Hs=>{Hs&&ht()&&(Et.current=Hs)}).catch(()=>{}))}).catch(Ms=>{if(ht()){if(a2(Ms)){if(st(!1),v&&ee(v,null),it(null),we(""),nt(""),Be(null),Et.current=null,S.trim().length>0&&D(""),d&&E(!1),v){const zn=[...Am(Ae.path,v),Ae.path];zn.length>0&&Ne(v,zn);for(const po of zn)de.current.has(po)||Zs(po)}return}we(""),nt(""),it(Ms instanceof Error?Ms.message:e("filesView.error.readFileFailed")),Et.current=null}}).finally(()=>{ht()&&st(!1)})},[Ne,d,Zs,t,fr,Ln,v,r.isDesktop,S,ee,e]),Hr=l.useCallback(async(Ae,Qe)=>{if(!v)return;const ht=Am(Ae,v),gt=Qe?[...ht,Ae]:ht;gt.length>0&&Ne(v,gt);for(const $t of gt)de.current.has($t)||await Zs($t)},[Ne,Zs,v]),Fa=l.useCallback((Ae,Qe)=>{const ht=Qe.findIndex(gt=>gt.path===Ae);return ht===-1||Qe.length<=1?null:Qe[ht+1]??Qe[ht-1]??null},[]),Nn=l.useCallback(async Ae=>{if(gs.current)gs.current=!1;else if(en){Xt(!0),as.current=Ae;return}v&&(ee(v,Ae.path),me(v,Ae.path),Hr(Ae.path,!1)),it(null),ye(""),we(""),nt(""),Be(null),d&&E(!0)},[me,Hr,en,d,v,ee]);l.useEffect(()=>{be?.path&&Hr(be.path,!1)},[Hr,be?.path]),l.useEffect(()=>{if(!be){Gt.current+=1,st(!1);return}Je!==be.path&&Ra(be)},[Ra,Je,be]);const La=l.useRef(en);La.current=en,l.useEffect(()=>{if(!be?.path||Je!==be.path)return;let Ae=!1;const Qe=window.setInterval(()=>{document.hidden||Ln(be.path,Ve).then(ht=>{if(Ae||!ht)return;const gt=Et.current;if(!gt||gt.path!==be.path){Et.current=ht;return}const $t=ht.mtimeMs!==void 0&>.mtimeMs!==void 0&&ht.mtimeMs!==gt.mtimeMs,qt=ht.size!==gt.size;!$t&&!qt||La.current||(Et.current=ht,Be(null))}).catch(()=>{})},2e3);return()=>{Ae=!0,window.clearInterval(Qe)}},[Je,Ln,be?.path,Ve]);const Oa=l.useCallback(()=>{const Ae=as.current,Qe=Bt.current,ht=ls.current;if(as.current=null,Bt.current=null,ls.current=null,gs.current=!0,Xt(!1),nt(fn),ht){v&&X(v,ht),be?.path===ht&&(Ae?Nn(Ae):(v&&ee(v,null),we(""),it(null),ye(""),Be(null),d&&E(!1)));return}if(Ae){Nn(Ae);return}Qe&&(an(null),Me.getState().setActiveMainTab(Qe))},[fn,Nn,d,X,v,be?.path,an,ee]),$a=l.useCallback(async()=>{const Ae=as.current,Qe=Bt.current,ht=ls.current;if(!await gr()){gs.current=!1;return}if(as.current=null,Bt.current=null,ls.current=null,gs.current=!0,Xt(!1),ht){v&&X(v,ht),be?.path===ht&&(Ae?await Nn(Ae):(v&&ee(v,null),we(""),it(null),ye(""),Be(null),d&&E(!1)));return}if(Ae){await Nn(Ae);return}Qe&&(an(null),Me.getState().setActiveMainTab(Qe))},[Nn,d,X,v,gr,be?.path,an,ee]),Vn=l.useCallback(Ae=>{const Qe=be?.path===Ae,ht=Fa(Ae,he);if(Qe&&en){Xt(!0),as.current=ht,ls.current=Ae;return}if(v&&X(v,Ae),!!Qe){if(ht){Nn(ht);return}v&&ee(v,null),we(""),it(null),ye(""),Be(null),d&&E(!1)}},[Fa,Nn,en,d,he,X,v,be?.path,ee]),Le=l.useCallback(Ae=>{if(ue.includes(Ae))return"open";if(y?.files){const Qe=Ae.startsWith(v+"/")?Ae.slice(v.length+1):Ae,ht=y.files.find(gt=>gt.path===Qe);if(ht){if(ht.index==="A"||ht.working_dir==="?")return"git-added";if(ht.index==="D")return"git-deleted";if(ht.index==="M"||ht.working_dir==="M")return"git-modified"}}return null},[ue,y,v]),Ze=l.useCallback(Ae=>{if(!y?.files)return null;const Qe=Ae.startsWith(v+"/")?Ae.slice(v.length+1):Ae,ht=Qe?`${Qe}/`:"";let gt=0,$t=0;for(const qt of y.files)qt.path.startsWith(ht)&&((qt.index==="M"||qt.working_dir==="M")&>++,(qt.index==="A"||qt.working_dir==="?")&&$t++);return gt+$t>0?{modified:gt,added:$t}:null},[y,v]),et=l.useCallback(async Ae=>{const Qe=bn(Ae);v&&(Pe(v,Qe),de.current.has(Qe)||await Zs(Qe))},[Zs,v,Pe]),ct=l.useMemo(()=>({canRename:Tt,canCreateFile:xt,canCreateFolder:kt,canDelete:ss,canReveal:at}),[Tt,xt,kt,ss,at]);function Ot(Ae,Qe){const ht=ge[Ae]??[];return ht.map((gt,$t)=>{const qt=gt.type==="directory",Ms=qt&&W.includes(gt.path),Hs=be?.path===gt.path,zn=$t===ht.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"}),zn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(c2,{node:gt,root:v,isExpanded:Ms,isActive:Hs,isMobile:d,alwaysShowActions:u,status:qt?void 0:Le(gt.path),badge:qt?Ze(gt.path):void 0,permissions:ct,downloadFile:n.downloadFile,contextMenuPath:pt,setContextMenuPath:jt,onSelect:Nn,onToggle:et,onRevealPath:cs,onOpenDialog:Js}),qt&&Ms&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Ot(gt.path,Qe+1)})]},gt.path)})}const Kt=!!(be?.path&&ui(be.path)),zs=!!(be?.path&&be.path.toLowerCase().endsWith(".svg")),mn=l.useMemo(()=>bn(gn?.path??""),[gn?.path]),Zn=!!(gn&&mn&&fe&&fe===mn&&!tt&&!qe&&!Kt),Ba=l.useMemo(()=>td(v,fe),[fe,v]),oo=!!(be&&(!Kt||zs)&&Xe.length>0),_a=!!(be&&Ba.length>0),er=!!(be&&!Te&&!Kt&&n.writeFile&&Xe.length<=ki),Fr=!!(be?.path&&o2(be.path)),Va=!!(be?.path&&l2(be.path)),za=!!(be?.path&&dc(be.path)),vi=!!(be&&!Kt)&&!Fr&&!(za&&te==="preview"),Gr=l.useMemo(()=>fe?Lf(fe):null,[fe]),[aa,tn]=l.useState(null);l.useEffect(()=>{let Ae=!1;const Qe=be?.path;if(!Qe||Gr){tn(null);return}return tn(null),QN(Qe).then(ht=>{Ae||tn(ht)}),()=>{Ae=!0}},[be?.path,Gr]),l.useEffect(()=>{!er&&_==="edit"&&se("view")},[er,_]);const Ua="openchamber:files:md-viewer-mode",Wa="openchamber:files:html-viewer-mode",lo="openchamber:files:json-viewer-mode";l.useEffect(()=>{const Ae=be?.path;if(!Ae)return;const Qe=Fe?"view":"edit";se(z.current[Ae]??Qe);let ht=Fe?"preview":"edit";try{const qt=localStorage.getItem(Ua);(qt==="preview"||qt==="edit")&&(ht=qt)}catch{}ae(Q.current[Ae]??ht);let gt=Fe?"preview":"edit";try{const qt=localStorage.getItem(Wa);(qt==="preview"||qt==="edit")&&(gt=qt)}catch{}F(re.current[Ae]??gt);let $t=Fe?"tree":"text";try{const qt=localStorage.getItem(lo);(qt==="tree"||qt==="text")&&($t=qt)}catch{}xe($t)},[be?.path,Fe]);const Dl=l.useCallback(Ae=>{const Qe=be?.path;Qe&&(z.current[Qe]=Ae),se(Ae)},[be?.path]),ia=l.useCallback(Ae=>{const Qe=be?.path;Qe&&(Q.current[Qe]=Ae),ae(Ae);try{localStorage.setItem(Ua,Ae)}catch{}},[be?.path]),xn=l.useCallback(()=>oe,[oe]),Tl=l.useCallback(Ae=>{xe(Ae);try{localStorage.setItem(lo,Ae)}catch{}},[]),Ml=l.useCallback(Ae=>{const Qe=be?.path;Qe&&(re.current[Qe]=Ae),F(Ae);try{localStorage.setItem(Wa,Ae)}catch{}},[be?.path]),co=l.useCallback(()=>te,[te]);l.useEffect(()=>{if(!gn||!v)return;const Ae=()=>{typeof window>"u"||wt.current===null&&(wt.current=window.requestAnimationFrame(()=>{wt.current=null,Dt($r=>$r+1)}))},Qe=($r,la)=>{if($r.state.doc.length!==la.length)return!1;if(la.length===0)return!0;const Fl=Math.min(128,la.length);if($r.state.sliceDoc(0,Fl)!==la.slice(0,Fl))return!1;const Hd=Math.max(0,la.length-Fl);return $r.state.sliceDoc(Hd,la.length)===la.slice(Hd)},ht=bn(gn.path);if(!ht){pr(null),Jt.current={key:"",attempts:0};return}const gt=`${ht}:${gn.line}:${gn.column??1}`;if(Jt.current.key!==gt&&(Jt.current={key:gt,attempts:0}),be?.path!==ht){if(ut)return;Nn(Y(ht));return}if(tt||Je!==ht)return;if(qe||Kt){pr(null),Jt.current={key:"",attempts:0};return}if(!er)return;if(_!=="edit"){se("edit");return}const $t=At.current;if(!$t){Ae();return}if(!Qe($t,ze)){Ae();return}const qt=Math.max(1,Math.min(gn.line,$t.state.doc.lines)),Ms=$t.state.doc.line(qt),Hs=Math.max(1,gn.column||1),zn=Math.max(0,Ms.to-Ms.from),po=Math.min(zn,Hs-1),wi=Ms.from+po;if(!($t.state.selection.main.head===wi)||Jt.current.attempts===0){Jt.current.attempts+=1,$t.dispatch({selection:{anchor:wi},effects:Jn.scrollIntoView(wi,{y:"center"})}),$t.focus(),Ae();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const $r=At.current;$r&&($r.dispatch({selection:{anchor:wi},effects:Jn.scrollIntoView(wi,{y:"center"})}),$r.focus())}),pr(null),Jt.current={key:"",attempts:0}},[er,ut,ze,Rt,qe,tt,Kt,Je,Nn,gn,v,be?.path,pr,_,Y]),l.useEffect(()=>{if(!Fn||!v)return;const Ae=bn(Fn);if(!Ae){Dn(null);return}if(be?.path!==Ae){if(ut)return;Nn(Y(Ae));return}if(!(tt||Je!==Ae||qe||Kt)){if(er&&_==="edit"){const Qe=At.current;if(!Qe)return;Qe.focus()}Dn(null)}},[er,ut,qe,tt,Nn,Kt,Je,Fn,v,be?.path,Dn,_,Y]);const qr=l.useCallback(Ae=>{if(!d||!Ae||!Ae.hasFocus||typeof window>"u")return;const Qe=window.visualViewport;if(!Qe)return;const ht=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,ht-(Qe.offsetTop+Qe.height))<=0)return;const $t=Ae.state.selection.main.head,qt=Ae.coordsAtPos($t);if(!qt)return;const Ms=Math.round(Qe.offsetTop+Qe.height),zn=qt.bottom+20-Ms;zn<=0||(Ae.scrollDOM.scrollTop+=zn)},[d]);l.useEffect(()=>{if(!d||typeof window>"u")return;const Ae=()=>{window.requestAnimationFrame(()=>{qr(At.current)})},Qe=window.visualViewport;return Qe?.addEventListener("resize",Ae),Qe?.addEventListener("scroll",Ae),document.addEventListener("selectionchange",Ae),()=>{Qe?.removeEventListener("resize",Ae),Qe?.removeEventListener("scroll",Ae),document.removeEventListener("selectionchange",Ae)}},[d,qr]),l.useEffect(()=>{if(!er||_!=="edit"||d)return;const Ae=Vr("open_go_to_line",Tn),Qe=ht=>{const gt=ht.target;if(gt?.closest('[role="dialog"]'))return;const $t=!!gt?.closest(".cm-editor");gt?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!$t||!document.activeElement?.closest(".cm-editor")||Fo(ht,Ae)&&(ht.preventDefault(),Ke(!0))};return window.addEventListener("keydown",Qe),()=>window.removeEventListener("keydown",Qe)},[er,d,Tn,_]);const uo=l.useMemo(()=>{if(!be?.path)return[ed(i)];const Ae=[ed(i)],Qe=Gr??aa;return Qe&&Ae.push(Qe),P&&Ae.push(Jn.lineWrapping),d&&Ae.push(Jn.updateListener.of(ht=>{ht.view.hasFocus&&(ht.selectionSet||ht.focusChanged||ht.viewportChanged||ht.geometryChanged)&&window.requestAnimationFrame(()=>{qr(ht.view)})})),Ae},[i,be?.path,Gr,aa,P,d,qr]),oa=l.useMemo(()=>({light:K.metadata.id,dark:le.metadata.id}),[K.metadata.id,le.metadata.id]),Ka=be?.path&&Kt?r.isDesktop?zs?`data:${iu(be.path)};utf8,${encodeURIComponent(Xe)}`:lt:zs?`data:${iu(be.path)};utf8,${encodeURIComponent(Xe)}`:`/api/fs/raw?${new URLSearchParams({path:be.path,...Ve.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";l.useEffect(()=>{let Ae=!1;return(async()=>{if(!r.isDesktop||!be?.path||!Kt||zs){ye("");return}it(null),await(n.readFileBinary?n.readFileBinary(be.path,Ve).then(gt=>gt.dataUrl):Promise.resolve(rx(be.path,"asset"))).then(gt=>{Ae||(ye(gt),Be(be.path))}).catch(gt=>{Ae||(ye(""),it(gt instanceof Error?gt.message:e("filesView.error.readFileFailed")),Be(null))}).finally(()=>{Ae||st(!1)})})(),()=>{Ae=!0}},[n,Kt,zs,r.isDesktop,be?.path,Ve,e]);const El=()=>s.jsx(ws,{open:!!_t,onOpenChange:Ae=>!Ae&&Fs(null),children:s.jsxs(vs,{children:[s.jsxs(Ss,{children:[s.jsxs(js,{children:[_t==="createFile"&&e("filesView.dialog.createFile.title"),_t==="createFolder"&&e("filesView.dialog.createFolder.title"),_t==="rename"&&e("filesView.dialog.rename.title"),_t==="delete"&&e("filesView.dialog.delete.title")]}),s.jsxs(Rs,{children:[_t==="createFile"&&e("filesView.dialog.createFile.description",{path:ft?.path??e("filesView.dialog.rootFallback")}),_t==="createFolder"&&e("filesView.dialog.createFolder.description",{path:ft?.path??e("filesView.dialog.rootFallback")}),_t==="rename"&&e("filesView.dialog.rename.description",{name:ft?.name??""}),_t==="delete"&&e("filesView.dialog.delete.description",{name:ft?.name??""})]})]}),_t!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Ut,{value:Qt,onChange:Ae=>ks(Ae.target.value),placeholder:e(_t==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:Ae=>{Ae.key==="Enter"&&Er()},autoFocus:!0})}),s.jsxs(Gs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>Fs(null),disabled:_s,children:e("filesView.dialog.cancel")}),s.jsx(ve,{variant:_t==="delete"?"destructive":"default",onClick:()=>{Er()},disabled:_s||_t!=="delete"&&!Qt.trim(),children:_s?s.jsx(C,{name:"loader-4",className:"animate-spin"}):e(_t==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm")})]})]})}),Rl=l.useMemo(()=>Af({drafts:ms,editingDraftId:Vs,commentText:qs,selection:Us,isDragging:un,fileLabel:be?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Ae=>({start:Ae.startLine,end:Ae.endLine}),onSave:Sr,onCancel:()=>{ln(null),hn()},onEdit:Ae=>{Sn(Ae),ln({start:Ae.startLine,end:Ae.endLine})},onDelete:Mr}),[hn,qs,Mr,Vs,ms,Sr,un,Us,be?.path,Sn]),mo=l.useCallback((Ae,Qe)=>s.jsx("div",{className:"h-full",children:s.jsx(nx,{file:{name:Ae.name,contents:Qe,lang:Ui(Ae.path)||void 0},options:{disableFileHeader:!0,overflow:P?"wrap":"scroll",theme:oa,themeType:i.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[i.metadata.variant,oa,P]),Re=({exitFullscreenOnly:Ae=!1}={})=>be?s.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",children:[er&&_==="edit"&&s.jsxs(s.Fragment,{children:[Ye?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(C,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),e("filesView.editor.saving")]}):St&&ts==="saved"&&!en?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(C,{name:"check",className:"h-3.5 w-3.5"}),e("filesView.editor.saved")]}):en?s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{gr()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(St?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${nl()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${nl()}+S`}),children:s.jsx(C,{name:"save-3",className:"h-4 w-4"})}):null,s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>Zt(Qe=>!Qe),className:pe("h-6 w-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",St?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(St?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(St?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:St?s.jsx(C,{name:"file-check-fill",className:"size-4"}):s.jsx(C,{name:"file-check",className:"size-4"})})]}),s.jsxs(Bs,{onOpenChange:B,children:[s.jsx(Os,{asChild:!0,children:s.jsx(ve,{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(C,{name:"file-transfer",className:"h-4 w-4"})})}),s.jsxs($s,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Lt.map(Qe=>s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{sn(Qe)},children:[s.jsx(XN,{label:Qe.label,iconDataUrl:Qe.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Qe.label})]},Qe.id)),os?s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{Vt(!0)},children:[s.jsx(C,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Kt&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>k(!P),className:pe("h-6 w-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",P?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(P?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(C,{name:"text-wrap",className:"size-4"})}),_==="edit"&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:Qe=>{R(!M),Qe.currentTarget.blur()},className:"h-6 w-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(C,{name:"search",className:"size-4"})}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:Qe=>{Ke(ht=>!ht),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(C,{name:"menu-fold-2",className:"size-4"})}),s.jsx(HN,{open:Is,onOpenChange:Ke,view:At.current,variant:"inline"})]})]}),vi&&er&&!Va&&!za&&s.jsx(Xc,{currentMode:_==="view"?"preview":"edit",onToggle:()=>{Dl(_==="view"?"edit":"view")}}),(Fr||dc(be?.path??""))&&s.jsx(Xc,{currentMode:Fr?xn():co(),onToggle:()=>{dc(be?.path??"")?Ml(co()==="preview"?"edit":"preview"):ia(xn()==="preview"?"edit":"preview")}}),Va&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>Tl(ne==="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(ne==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ne==="tree"?s.jsx(C,{name:"code-sslash",className:"size-4"}):s.jsx(C,{name:"node-tree",className:"size-4"})}),oo&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(Xe)).ok?(es(!0),us.current!==null&&window.clearTimeout(us.current),us.current=window.setTimeout(()=>{es(!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(C,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(C,{name:"clipboard",className:"h-4 w-4"})}),_a&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(Ba)).ok?(Cs(!0),xs.current!==null&&window.clearTimeout(xs.current),xs.current=window.setTimeout(()=>{Cs(!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:Ba}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:Ba}),children:ns?s.jsx(C,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(C,{name:"file-copy-2",className:"h-4 w-4"})}),n.downloadFile&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{const Qe=n.downloadFile;Qe&&Qe(be.path)},className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(C,{name:"download",className:"h-4 w-4"})}),Ae?s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>T(!1),className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(C,{name:"fullscreen-exit",className:"h-4 w-4"})}):!d&&t==="full"&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>T(!N),className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:N?s.jsx(C,{name:"fullscreen-exit",className:"h-4 w-4"}):s.jsx(C,{name:"fullscreen",className:"h-4 w-4"})})]}):null,bt=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(ws,{open:ut,onOpenChange:Ae=>{Ae||Xt(!0)},children:s.jsxs(vs,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:e("filesView.unsaved.title")}),s.jsx(Rs,{children:e("filesView.unsaved.description")})]}),s.jsxs(Gs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>{$a()},disabled:Ye,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(ve,{variant:"destructive",onClick:Oa,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&&A&&s.jsx("button",{type:"button",onClick:()=>E(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex h-7 w-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(C,{name:"arrow-left-s",className:"h-5 w-5"})}),d?be?s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(yr,{filePath:be.path,extension:be.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:be.name}),s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx($s,{align:"start",className:"min-w-[16rem]",children:he.map(Ae=>{const Qe=be?.path===Ae.path;return s.jsxs(zt,{onSelect:ht=>{if(ht.target.closest("[data-close-open-file]")){ht.preventDefault();return}Qe||Nn(Ae)},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(yr,{filePath:Ae.path,extension:Ae.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ae.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:ht=>{ht.preventDefault(),ht.stopPropagation()},onClick:ht=>{ht.preventDefault(),ht.stopPropagation(),Vn(Ae.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:Ae.name}),children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]},Ae.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):he.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Ie.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"}),Ie.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:he.map(Ae=>{const Qe=be?.path===Ae.path;return s.jsxs("div",{title:td(v,Ae.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(yr,{filePath:Ae.path,extension:Ae.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{Qe||Nn(Ae)},className:"max-w-[12rem] truncate text-left",children:Ae.name}),s.jsx("button",{type:"button",onClick:ht=>{ht.stopPropagation(),Vn(Ae.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:Ae.name}),children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]},Ae.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[be&&!M&&s.jsx("div",{ref:V,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>O(!0),onMouseLeave:()=>{$.current>0||O(!1)},children:L?Re():s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>O(!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(C,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsx(As,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:be?tt?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(C,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("filesView.state.loading")]}):qe?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:qe}):Kt?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:Ka,alt:be?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):be&&Va&&ne==="tree"?s.jsx(Ys,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Xy,{jsonString:Xe,maxHeight:"100%",initiallyExpandedDepth:2})})}):be&&Fr&&xn()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Xe.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(Xe.length/1024)})}),s.jsx(Ys,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Ia,{content:Xe,className:"typography-markdown-body",stripFrontmatter:!0})})]}):be&&za&&te==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Ae=be.path.substring(0,be.path.lastIndexOf("/")+1);if(!Ae)return Xe;const Qe=`<base href="${r.isDesktop,Ae}">`;return Xe.replace(/<head([^>]*)>/i,`<head$1>${Qe}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):be&&vi&&_==="view"?mo(be,ze):s.jsxs("div",{className:pe("relative h-full",Zn&&"overflow-hidden"),ref:We,children:[s.jsx("div",{className:pe("h-full",Zn&&"invisible"),children:s.jsx(Yc,{value:ze,onChange:nt,readOnly:!er,extensions:uo,className:"h-full",blockWidgets:Rl,onViewReady:Ae=>{At.current=Ae,Dt(Qe=>Qe+1),window.requestAnimationFrame(()=>{qr(Ae)})},onViewDestroy:()=>{At.current&&(At.current=null),Dt(Ae=>Ae+1)},enableSearch:!0,searchOpen:M,onSearchOpenChange:R,highlightLines:Us?{start:Math.min(Us.start,Us.end),end:Math.max(Us.start,Us.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Ae,Qe,ht)=>{if(!(ht instanceof MouseEvent)||ht.button!==0)return!1;ht.preventDefault();const gt=Ae.state.doc.lineAt(Qe.from).number;if(d&&Us&&!ht.shiftKey){const $t=Math.min(Us.start,Us.end,gt),qt=Math.max(Us.start,Us.end,gt);return ln({start:$t,end:qt}),nn.current=!1,cn.current=null,jn(!1),!0}if(nn.current=!0,cn.current=gt,jn(!0),Us&&ht.shiftKey){const $t=Math.min(Us.start,gt),qt=Math.max(Us.end,gt);ln({start:$t,end:qt})}else ln({start:gt,end:gt});return!0},mouseover:(Ae,Qe,ht)=>{if(!(ht instanceof MouseEvent)||ht.buttons!==1||!nn.current||cn.current===null)return!1;const gt=Ae.state.doc.lineAt(Qe.from).number,$t=Math.min(cn.current,gt),qt=Math.max(cn.current,gt);return ln({start:$t,end:qt}),jn(!0),!1},mouseup:()=>(nn.current=!1,cn.current=null,jn(!1),!1)}}})}),Zn&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),dt=!!(v&&ge[v]),Yt=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(C,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Ut,{ref:I,value:S,onChange:Ae=>D(Ae.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:()=>{D(""),I.current?.focus()},children:s.jsx(C,{name:"close",className:"h-4 w-4"})})]}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>Js("createFile",{path:h,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),children:s.jsx(C,{name:"file-add",className:"h-4 w-4"})}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>Js("createFolder",{path:h,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),children:s.jsx(C,{name:"folder-add",className:"h-4 w-4"})}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{Yn()},className:"h-8 w-8 p-0 flex-shrink-0",children:s.jsx(C,{name:"refresh",className:"h-4 w-4"})})]})}),s.jsx(As,{outerClassName:"flex-1 min-h-0",className:pe("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:He?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("filesView.tree.search.searching")]}):ie.length>0?ie.map(Ae=>{const Qe=be?.path===Ae.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{Nn(Ae)},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:[$f(Ae.path,Ae.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:Ae.path,children:Ae.relativePath??Ae.path})]})},Ae.path)}):dt?Ot(v,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Ts=t==="full"&&N&&be&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:Re({exitFullscreenOnly:!0})}),s.jsx(As,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:tt?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(C,{name:"loader-4",className:"h-4 w-4 animate-spin"}),"Loading…"]}):qe?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:qe}):Kt?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:Ka,alt:be.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):Fr&&xn()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Xe.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(Xe.length/1024)})}),s.jsx(Ys,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Ia,{content:Xe,className:"typography-markdown-body",stripFrontmatter:!0})})]}):vi&&_==="view"?mo(be,ze):s.jsxs("div",{className:pe("relative h-full",Zn&&"overflow-hidden"),children:[s.jsx("div",{className:pe("h-full",Zn&&"invisible"),children:s.jsx(Yc,{value:ze,onChange:nt,readOnly:!er,extensions:uo,className:"h-full",onViewReady:Ae=>{At.current=Ae,window.requestAnimationFrame(()=>{qr(Ae)})},onViewDestroy:()=>{At.current&&(At.current=null)}})}),Zn&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[El(),Ts,d?A?bt:Yt: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:bt})}):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:Yt}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:bt})]})]})},d2=Object.freeze(Object.defineProperty({__proto__:null,FilesView:Bf},Symbol.toStringTag,{value:"Module"})),Ar=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},uc=(t,e)=>{const n=Ar(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},u2=(t,e,n)=>uc(uc(uc(t,".opencode"),"plans"),`${e}-${n}.md`),m2=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,p2=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},h2=(t,e)=>{const n=Ar(e.currentDirectory),r=Ar(e.homeDirectory),i=Ar(t);return n&&i.startsWith(n+"/")?i.slice(n.length+1):r&&i===r?"~":r&&i.startsWith(r+"/")?`~${i.slice(r.length)}`:i},f2=(t,e,n)=>{const r=Ar(t.trim());if(!r)return null;const i=n?e.find(o=>o.id===n)??null:null;if(i?.path){const o=Ar(i.path);if(r===o||r.startsWith(`${o}/`))return{id:i.id,path:i.path}}const a=e.filter(o=>{const c=Ar(o.path);return r===c||r.startsWith(`${c}/`)}).sort((o,c)=>Ar(c.path).length-Ar(o.path).length)[0];return a?{id:a.id,path:a.path}:null},_f=({targetPath:t=null})=>{const{t:e}=mt(),n=Ht(ge=>ge.currentSessionId),r=Ht(ge=>ge.createSession),i=Ht(ge=>ge.initializeNewOpenChamberSession),a=Ht(ge=>ge.sendMessage),o=Ht(ge=>ge.setCurrentSession),c=to(),d=Ws(ge=>ge.homeDirectory),p=vd(ge=>ge.planModeEnabled),m=Es(ge=>ge.projects),u=Es(ge=>ge.activeProjectId),f=on(ge=>ge.directories),b=Or()??"",h=Me(ge=>ge.setActiveMainTab),v=Me(ge=>ge.setSessionSwitcherOpen),x=_n(),{isMobile:g}=rn(),{currentTheme:w}=Nr();l.useMemo(()=>Fh(w),[w]);const y=l.useMemo(()=>n?c.find(ge=>ge.id===n)??null:null,[n,c]),S=l.useMemo(()=>{const ge=typeof y?.directory=="string"?y.directory:"";return Ar(ge||"")},[y?.directory]),D=l.useMemo(()=>Ar(b||S),[b,S]),j=l.useMemo(()=>f2(D,m,u),[u,D,m]),I=l.useMemo(()=>j?f.get(j.path)?.isGitRepo===!0:!1,[j,f]),[A,E]=l.useState(null),[P,k]=l.useState(!1),[N,T]=l.useState(null),M=l.useMemo(()=>!N||!S||!d?N:h2(N,{currentDirectory:S,homeDirectory:d}),[N,S,d]),[R,L]=l.useState(""),[O,V]=l.useState(null),$=l.useMemo(()=>M&&M.split("/").pop()||e("planView.file.defaultName"),[M,e]),B=l.useMemo(()=>R.trim()&&ib(R).title||e("planView.title.default"),[R,e]),H=l.useMemo(()=>B.trim()||e("planView.title.default"),[B,e]),[_,se]=l.useState(!1),[oe,ae]=l.useState(!1),[ne,xe]=l.useState("edit"),te=l.useRef(null),[F,z]=l.useState(null),Q=l.useRef(null),re=l.useRef(null),K="openchamber:plan:md-viewer-mode";l.useEffect(()=>{try{const ge=localStorage.getItem(K);if(!ge)return;const U=JSON.parse(ge);(U==="preview"||U==="edit")&&xe(U)}catch{}},[]);const le=l.useCallback(ge=>{xe(ge);try{localStorage.setItem(K,JSON.stringify(ge))}catch{}},[]),Se=l.useRef(!1),ue=l.useRef(null),[je,W]=l.useState(!1);l.useEffect(()=>{const ge=()=>{Se.current=!1,ue.current=null,W(!1)};return document.addEventListener("mouseup",ge),()=>document.removeEventListener("mouseup",ge)},[]);const me=l.useCallback((ge,U)=>{const de=ge.split(`
|
|
54
|
-
`),Ee=Math.max(1,U.start),_e=Math.min(de.length,U.end);return Ee>_e?"":de.slice(Ee-1,_e).join(`
|
|
55
|
-
`)},[]),X=Ld({source:"plan",fileLabel:$,language:N&&Ui(N)||"markdown",getCodeForRange:ge=>me(R,ul(ge)),toStoreRange:ge=>({startLine:ge.start,endLine:ge.end}),fromDraftRange:ge=>({start:ge.startLine,end:ge.endLine})}),{drafts:ce,commentText:ee,editingDraftId:Pe,setSelection:Ne,saveComment:Y,cancel:he,reset:ke,startEdit:be,deleteDraft:fe}=X;l.useEffect(()=>{z(null),ke()},[R,ke]),l.useEffect(()=>{Ne(F)},[F,Ne]);const Te=l.useCallback(()=>{z(null),he()},[he]),Ve=l.useCallback((ge,U)=>{U&&z(U),Y(ge,U??F??void 0),z(null)},[F,Y]);l.useEffect(()=>{if(!F)return;const ge=de=>{const Ee=de.target;Ee.closest('[data-comment-card="true"]')||Ee.closest('[data-comment-input="true"]')||Ee.closest(".oc-block-widget")||Ee.closest(".cm-gutterElement")||Ee.closest("[data-sonner-toast]")||Ee.closest("[data-sonner-toaster]")||(z(null),he())},U=window.setTimeout(()=>{document.addEventListener("click",ge)},100);return()=>{window.clearTimeout(U),document.removeEventListener("click",ge)}},[he,Pe,g,F]);const G=l.useMemo(()=>{const ge=[ed(w)],U=Lf(N||"plan.md");return U&&ge.push(U),ge.push(Jn.lineWrapping),ge},[w,N]);l.useEffect(()=>{if(!p&&!t){T(null),L(""),se(!1);return}let ge=!1;const U=async Ee=>{if(x.files?.readFile)return(await x.files.readFile(Ee))?.content??"";const _e=lr()?.files;if(_e?.readFile)return(await _e.readFile(Ee,{optional:!0}))?.content??"";const Z=await fetch(`/api/fs/read?path=${encodeURIComponent(Ee)}&optional=true`,{cache:"no-store"});if(!Z.ok)throw new Error(`Failed to read plan file (${Z.status})`);return Z.text()};return(async()=>{if(T(null),L(""),V(null),t){se(!0);try{const Ee=await U(t);if(ge)return;T(t),L(Ee)}catch{if(ge)return;T(null),L("")}finally{ge||se(!1)}return}if(!y?.slug||!y?.time?.created||!S){T(null),L("");return}se(!0);try{const Ee=u2(S,y.time.created,y.slug),_e=p2(m2(y.time.created,y.slug),d||null);let Z=null,ie=null;try{ie=await U(Ee),Z=Ee}catch{}if(!Z)try{ie=await U(_e),Z=_e}catch{}if(ge)return;if(!Z||ie===null){T(null),L("");return}T(Z),L(ie)}catch{if(ge)return;T(null),L("")}finally{ge||se(!1)}})(),()=>{ge=!0}},[d,p,x.files,S,y?.slug,y?.time?.created,t]),l.useEffect(()=>{if(!N){V(null);return}const ge=window.setTimeout(async()=>{V(null);try{if(x.files?.writeFile){if(!(await x.files.writeFile(N,R))?.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:R})});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(ge)}},[R,N,x.files,e]),l.useEffect(()=>()=>{te.current!==null&&window.clearTimeout(te.current)},[]);const Ie=l.useCallback(()=>{h("chat"),v(!1)},[h,v]),Oe=l.useCallback(async ge=>{if(!j||!A)return;const U=await En(A.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:H}),Ee=[{synthetic:!0,text:await En(A.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:H,plan_path:N??""})}];k(!0);try{Ie();let _e=null,Z=j.path;if(A.target==="worktree"){if(!I)return;const Ce=await Dh(j.path,Th());if(!Ce?.id)return;_e=Ce.id,Z=null}else{const Ce=await r(void 0,j.path,null);if(!Ce?.id)return;_e=Ce.id,Z=Ce.directory??j.path,i(Ce.id,yt.getState().agents??[])}if(!_e)return;const ie=vl.getState();ie.saveSessionModelSelection(_e,ge.providerID,ge.modelID),ge.agent.trim()&&(ie.saveSessionAgentSelection(_e,ge.agent),ie.saveAgentModelForSession(_e,ge.agent,ge.providerID,ge.modelID),ie.saveAgentModelVariantForSession(_e,ge.agent,ge.providerID,ge.modelID,ge.variant||void 0)),o(_e,Z),await a(U,ge.providerID,ge.modelID,ge.agent.trim()||void 0,void 0,void 0,Ee,ge.variant||void 0),E(null)}finally{k(!1)}},[I,r,j,i,A,N,Ie,a,H,o]),De=l.useMemo(()=>Af({drafts:ce,editingDraftId:Pe,commentText:ee,selection:F,isDragging:je,fileLabel:$,newWidgetId:"plan-new-comment-input",mapDraftToRange:ge=>({start:ge.startLine,end:ge.endLine}),onSave:Ve,onCancel:Te,onEdit:ge=>{be(ge),z({start:ge.startLine,end:ge.endLine})},onDelete:fe}),[ee,fe,Pe,Te,Ve,je,F,ce,$,be]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:B}),O?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:O,children:e("planView.error.saveFailed")}):null]}),N?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(Bs,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!R.trim(),children:s.jsx(C,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(Pt,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs($s,{align:"end",children:[s.jsx(zt,{onClick:()=>E({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(zt,{onClick:()=>E({action:"improve",target:"worktree"}),disabled:!I,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(Bs,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!R.trim(),children:s.jsx(C,{name:"code-ai",className:"size-4"})})})}),s.jsx(Pt,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs($s,{align:"end",children:[s.jsx(zt,{onClick:()=>E({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(zt,{onClick:()=>E({action:"implement",target:"worktree"}),disabled:!I,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(Xc,{currentMode:ne,onToggle:()=>le(ne==="preview"?"edit":"preview")}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(R)).ok&&(ae(!0),te.current!==null&&window.clearTimeout(te.current),te.current=window.setTimeout(()=>{ae(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:oe?s.jsx(C,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(C,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(pf,{open:A!==null,onOpenChange:ge=>{!ge&&!P&&E(null)},target:A?.target??"session",projectDirectory:j?.path??null,submitting:P,onConfirm:Oe}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(As,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:_?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("planView.state.loading")}):s.jsx("div",{className:"relative h-full",children:s.jsx("div",{className:"h-full",children:ne==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(Ys,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("planView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("planView.error.switchToEditMode")})]}),children:s.jsx(Ia,{content:R,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:re,children:s.jsx(Yc,{value:R,onChange:L,readOnly:!1,className:"h-full",extensions:G,onViewReady:ge=>{Q.current=ge},onViewDestroy:()=>{Q.current=null},blockWidgets:De,highlightLines:F?{start:Math.min(F.start,F.end),end:Math.max(F.start,F.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(ge,U,de)=>{if(!(de instanceof MouseEvent)||de.button!==0)return!1;de.preventDefault();const Ee=ge.state.doc.lineAt(U.from).number;if(g&&F&&!de.shiftKey){const _e=Math.min(F.start,F.end,Ee),Z=Math.max(F.start,F.end,Ee);return z({start:_e,end:Z}),Se.current=!1,ue.current=null,W(!1),!0}if(Se.current=!0,ue.current=Ee,W(!0),F&&de.shiftKey){const _e=Math.min(F.start,Ee),Z=Math.max(F.end,Ee);z({start:_e,end:Z})}else z({start:Ee,end:Ee});return!0},mouseover:(ge,U,de)=>{if(!(de instanceof MouseEvent)||de.buttons!==1||!Se.current||ue.current===null)return!1;const Ee=ge.state.doc.lineAt(U.from).number,_e=Math.min(ue.current,Ee),Z=Math.max(ue.current,Ee);return z({start:_e,end:Z}),W(!0),!1},mouseup:()=>(Se.current=!1,ue.current=null,W(!1),!1)}}})})})})})})]})},g2=Object.freeze(Object.defineProperty({__proto__:null,PlanView:_f},Symbol.toStringTag,{value:"Module"})),sd={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Uo={user:0,assistant:0,tool:0,other:0},fa=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Dm=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{...sd,total:fa(n)};if(!n||typeof n!="object")return sd;const r=n,i=fa(r.input),a=fa(r.output),o=fa(r.reasoning),c=fa(r.cache?.read),d=fa(r.cache?.write);return{input:i,output:a,reasoning:o,cacheRead:c,cacheWrite:d,total:i+a+o+c+d}},x2=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},rr=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+rr(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+rr(n),0):0,b2=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...Uo,assistant:rr(n.text)+rr(n.content)};const i=x2(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:rr(n.input)+rr(n.output)+rr(n.error)+rr(n.call?.input)+rr(n.call?.output)+rr(n.call?.error)+rr(n.raw)+Math.round(rr(n.metadata)*.25)+Math.round(rr(n.state)*.1),other:0}:e==="user"?{user:i.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:i.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:i.length}},Tm=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),y2=t=>{const e=so(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},v2=(t,e)=>{if(t.length===0)return{...Uo};const n=t.reduce((r,i)=>{const a=y2(i);let o={...Uo};for(const c of i.parts)o=Tm(o,b2(c,a));return Tm(r,o)},{...Uo});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)}},Xa=t=>t.toLocaleString(),w2=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,j2=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),N2=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),S2=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,k2=(t,e,n)=>{const r=t.find(a=>a.id===e),i=r?.models?.find(a=>a.id===n);return{providerName:r?.name||e||"-",modelName:i?.name||n||"-",contextLimit:typeof i?.limit?.context=="number"?i.limit.context:null}},C2=()=>{const t=rt.c(199),{t:e}=mt(),{currentTheme:n}=Nr();let r;t[0]!==n?(r=Fh(n),t[0]=n,t[1]=r):r=t[1];const i=r;let a;t[2]===Symbol.for("react.memo_cache_sentinel")?(a={},t[2]=a):a=t[2];const[o,c]=l.useState(a),[d,p]=l.useState(null),m=l.useRef(null),u=Ht(I2),f=to(),b=ob(u??""),h=yt(P2);let v;t[3]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(A2),p(null)},t[3]=v):v=t[3];let x;t[4]!==u?(x=[u],t[4]=u,t[5]=x):x=t[5],l.useEffect(v,x);let g,w;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},w=[],t[6]=g,t[7]=w):(g=t[6],w=t[7]),l.useEffect(g,w);let y;t[8]===Symbol.for("react.memo_cache_sentinel")?(y=async(Nt,St)=>{(await Rn(St)).ok?(p(Nt),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(ut=>ut===Nt?null:ut),m.current=null},2e3)):p(null)},t[8]=y):y=t[8];const S=y;let D;t[9]!==u||t[10]!==f?(D=u?f.find(Nt=>Nt.id===u)??null:null,t[9]=u,t[10]=f,t[11]=D):D=t[11];const j=D;let I,A,E,P,k;if(t[12]!==h||t[13]!==b){I=b.filter(D2);let Nt;t[19]!==b?(Nt=b.filter(T2),t[19]=b,t[20]=Nt):Nt=t[20],k=Nt;let St=null;for(let ut=I.length-1;ut>=0;ut=ut-1,ut){const Xt=I[ut];if(Dm(Xt).total>0){St=Xt;break}}E=St?Dm(St):sd,P=I.reduce(M2,0);const Zt=St?.info??null;A=k2(h,Zt?.providerID||"",Zt?.modelID||""),t[12]=h,t[13]=b,t[14]=I,t[15]=A,t[16]=E,t[17]=P,t[18]=k}else I=t[14],A=t[15],E=t[16],P=t[17],k=t[18];const N=A,T=N.contextLimit,M=T&&T>0?Math.min(999,E.total/T*100):0;let R;if(t[21]!==b){const Nt=[...b].reverse().find(E2)?.info?.system||"";R=v2(b,Nt),t[21]=b,t[22]=R}else R=t[22];const L=R,O=L.user,V=L.assistant,$=L.tool,B=Math.max(0,E.input-O-V-$),H=O+V+$+B,_=b[0]?.info?.time?.created,se=b.length>0?b[b.length-1]?.info?.time?.created:null;let oe;t[23]!==j?.title||t[24]!==e?(oe=j?.title||e("contextSidebar.session.untitled"),t[23]=j?.title,t[24]=e,t[25]=oe):oe=t[25];const ae=j?.time?.created??_??null,ne=se??j?.time?.created??null;let xe;t[26]!==V||t[27]!==B||t[28]!==$||t[29]!==O?(xe={user:O,assistant:V,tool:$,other:B},t[26]=V,t[27]=B,t[28]=$,t[29]=O,t[30]=xe):xe=t[30];let te;t[31]!==I.length||t[32]!==H||t[33]!==T||t[34]!==N||t[35]!==b.length||t[36]!==oe||t[37]!==ae||t[38]!==ne||t[39]!==xe||t[40]!==E||t[41]!==P||t[42]!==M||t[43]!==k.length?(te={sessionTitle:oe,messagesCount:b.length,userMessagesCount:k.length,assistantMessagesCount:I.length,createdAt:ae,lastActivityAt:ne,providerModel:N,tokenBreakdown:E,usagePercent:M,totalAssistantCost:P,contextLimit:T,breakdown:xe,breakdownTotal:H},t[31]=I.length,t[32]=H,t[33]=T,t[34]=N,t[35]=b.length,t[36]=oe,t[37]=ae,t[38]=ne,t[39]=xe,t[40]=E,t[41]=P,t[42]=M,t[43]=k.length,t[44]=te):te=t[44];const F=te;if(!u){let Nt;t[45]!==e?(Nt=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=Nt):Nt=t[46];let St;return t[47]!==Nt?(St=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:Nt}),t[47]=Nt,t[48]=St):St=t[48],St}let z;t[49]!==e?(z=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=z):z=t[50];let Q;t[51]!==z||t[52]!==F.breakdown.user?(Q={key:"user",label:z,value:F.breakdown.user,color:"var(--status-success)"},t[51]=z,t[52]=F.breakdown.user,t[53]=Q):Q=t[53];let re;t[54]!==e?(re=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=re):re=t[55];let K;t[56]!==re||t[57]!==F.breakdown.assistant?(K={key:"assistant",label:re,value:F.breakdown.assistant,color:"var(--primary-base)"},t[56]=re,t[57]=F.breakdown.assistant,t[58]=K):K=t[58];let le;t[59]!==e?(le=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=le):le=t[60];let Se;t[61]!==le||t[62]!==F.breakdown.tool?(Se={key:"tool",label:le,value:F.breakdown.tool,color:"var(--status-warning)"},t[61]=le,t[62]=F.breakdown.tool,t[63]=Se):Se=t[63];let ue;t[64]!==e?(ue=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=ue):ue=t[65];let je;t[66]!==ue||t[67]!==F.breakdown.other?(je={key:"other",label:ue,value:F.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=ue,t[67]=F.breakdown.other,t[68]=je):je=t[68];let W;t[69]!==Q||t[70]!==K||t[71]!==Se||t[72]!==je?(W=[Q,K,Se,je],t[69]=Q,t[70]=K,t[71]=Se,t[72]=je,t[73]=W):W=t[73];const me=W;let X;t[74]!==F.sessionTitle?(X=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:F.sessionTitle}),t[74]=F.sessionTitle,t[75]=X):X=t[75];let ce;t[76]!==F.providerModel.modelName||t[77]!==F.providerModel.providerName?(ce=s.jsxs("span",{children:[F.providerModel.providerName," / ",F.providerModel.modelName]}),t[76]=F.providerModel.modelName,t[77]=F.providerModel.providerName,t[78]=ce):ce=t[78];let ee;t[79]!==F.createdAt?(ee=F.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:j2(F.createdAt)})]}),t[79]=F.createdAt,t[80]=ee):ee=t[80];let Pe;t[81]!==ce||t[82]!==ee?(Pe=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:[ce,ee]}),t[81]=ce,t[82]=ee,t[83]=Pe):Pe=t[83];let Ne;t[84]!==X||t[85]!==Pe?(Ne=s.jsxs("div",{className:"mb-6",children:[X,Pe]}),t[84]=X,t[85]=Pe,t[86]=Ne):Ne=t[86];let Y;t[87]!==e?(Y=e("contextSidebar.section.context"),t[87]=e,t[88]=Y):Y=t[88];let he;t[89]!==Y?(he=s.jsx("span",{className:"typography-micro text-muted-foreground",children:Y}),t[89]=Y,t[90]=he):he=t[90];let ke;t[91]!==F.tokenBreakdown.total?(ke=Xa(F.tokenBreakdown.total),t[91]=F.tokenBreakdown.total,t[92]=ke):ke=t[92];let be;t[93]!==F.contextLimit?(be=F.contextLimit?` / ${Xa(F.contextLimit)}`:"",t[93]=F.contextLimit,t[94]=be):be=t[94];let fe;t[95]!==ke||t[96]!==be?(fe=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[ke,be]}),t[95]=ke,t[96]=be,t[97]=fe):fe=t[97];let Te;t[98]!==he||t[99]!==fe?(Te=s.jsxs("div",{className:"flex items-baseline justify-between",children:[he,fe]}),t[98]=he,t[99]=fe,t[100]=Te):Te=t[100];let Ve;t[101]!==F.usagePercent?(Ve=F.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,F.usagePercent)}%`,backgroundColor:F.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=F.usagePercent,t[102]=Ve):Ve=t[102];let G;t[103]!==Ve?(G=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Ve}),t[103]=Ve,t[104]=G):G=t[104];let Ie;t[105]!==e||t[106]!==F.usagePercent?(Ie=e("contextSidebar.context.percentUsed",{percent:F.usagePercent.toFixed(1)}),t[105]=e,t[106]=F.usagePercent,t[107]=Ie):Ie=t[107];let Oe;t[108]!==Ie?(Oe=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Ie}),t[108]=Ie,t[109]=Oe):Oe=t[109];let De;t[110]!==Te||t[111]!==G||t[112]!==Oe?(De=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Te,G,Oe]}),t[110]=Te,t[111]=G,t[112]=Oe,t[113]=De):De=t[113];let ge;t[114]!==e?(ge=e("contextSidebar.stats.messages"),t[114]=e,t[115]=ge):ge=t[115];let U;t[116]!==F.messagesCount?(U=Xa(F.messagesCount),t[116]=F.messagesCount,t[117]=U):U=t[117];let de;t[118]!==ge||t[119]!==U?(de={label:ge,value:U},t[118]=ge,t[119]=U,t[120]=de):de=t[120];let Ee;t[121]!==e?(Ee=e("contextSidebar.stats.user"),t[121]=e,t[122]=Ee):Ee=t[122];let _e;t[123]!==F.userMessagesCount?(_e=Xa(F.userMessagesCount),t[123]=F.userMessagesCount,t[124]=_e):_e=t[124];let Z;t[125]!==Ee||t[126]!==_e?(Z={label:Ee,value:_e},t[125]=Ee,t[126]=_e,t[127]=Z):Z=t[127];let ie;t[128]!==e?(ie=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=ie):ie=t[129];let Ce;t[130]!==F.assistantMessagesCount?(Ce=Xa(F.assistantMessagesCount),t[130]=F.assistantMessagesCount,t[131]=Ce):Ce=t[131];let He;t[132]!==ie||t[133]!==Ce?(He={label:ie,value:Ce},t[132]=ie,t[133]=Ce,t[134]=He):He=t[134];let Ge;t[135]!==e?(Ge=e("contextSidebar.stats.cost"),t[135]=e,t[136]=Ge):Ge=t[136];let Xe;t[137]!==F.totalAssistantCost?(Xe=w2(F.totalAssistantCost),t[137]=F.totalAssistantCost,t[138]=Xe):Xe=t[138];let we;t[139]!==Ge||t[140]!==Xe?(we={label:Ge,value:Xe},t[139]=Ge,t[140]=Xe,t[141]=we):we=t[141];let tt;t[142]!==de||t[143]!==Z||t[144]!==He||t[145]!==we?(tt=[de,Z,He,we],t[142]=de,t[143]=Z,t[144]=He,t[145]=we,t[146]=tt):tt=t[146];const st=tt;let qe;t[147]!==st?(qe=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:st.map(R2)}),t[147]=st,t[148]=qe):qe=t[148];let it;t[149]!==e?(it=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=it):it=t[150];let lt;t[151]!==it?(lt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:it}),t[151]=it,t[152]=lt):lt=t[152];let ye;t[153]!==e||t[154]!==F.tokenBreakdown.cacheRead||t[155]!==F.tokenBreakdown.cacheWrite||t[156]!==F.tokenBreakdown.input||t[157]!==F.tokenBreakdown.output||t[158]!==F.tokenBreakdown.reasoning?(ye=s.jsx("div",{className:"mt-2.5 grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:F.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:F.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:F.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:F.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:F.tokenBreakdown.cacheWrite}].map(F2)}),t[153]=e,t[154]=F.tokenBreakdown.cacheRead,t[155]=F.tokenBreakdown.cacheWrite,t[156]=F.tokenBreakdown.input,t[157]=F.tokenBreakdown.output,t[158]=F.tokenBreakdown.reasoning,t[159]=ye):ye=t[159];let Je;t[160]!==lt||t[161]!==ye?(Je=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]=Je):Je=t[162];let Be;t[163]!==me||t[164]!==F.breakdownTotal?(Be=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:me.map(Nt=>Nt.value<=0||F.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${Nt.value/F.breakdownTotal*100}%`,backgroundColor:Nt.color}},Nt.key))}),t[163]=me,t[164]=F.breakdownTotal,t[165]=Be):Be=t[165];let ze;t[166]!==me||t[167]!==F.breakdownTotal?(ze=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:me.map(Nt=>{const St=F.breakdownTotal>0?Nt.value/F.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:Nt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[Nt.label," ",s.jsxs("span",{className:"tabular-nums",children:[St.toFixed(0),"%"]})]})]},Nt.key)})}),t[166]=me,t[167]=F.breakdownTotal,t[168]=ze):ze=t[168];let nt;t[169]!==Be||t[170]!==ze?(nt=s.jsxs("div",{className:"mb-6",children:[Be,ze]}),t[169]=Be,t[170]=ze,t[171]=nt):nt=t[171];let Ye;t[172]!==e?(Ye=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=Ye):Ye=t[173];let Ue;t[174]!==Ye?(Ue=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ye}),t[174]=Ye,t[175]=Ue):Ue=t[175];let vt;if(t[176]!==d||t[177]!==o||t[178]!==b||t[179]!==i||t[180]!==e){let Nt;t[182]!==d||t[183]!==o||t[184]!==i||t[185]!==e?(Nt=St=>{const Zt=so(St.info).role,ut=o[St.info.id]===!0,Xt=d===St.info.id,as=St.info.time?.created??null,Bt=ut?JSON.stringify({info:St.info,parts:St.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":ut,onClick:()=>{c(ls=>({...ls,[St.info.id]:ls[St.info.id]!==!0}))},children:s.jsxs("div",{className:"flex items-center justify-between gap-2 whitespace-nowrap overflow-hidden",children:[s.jsxs("span",{className:"min-w-0 inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:S2(Zt)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:St.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:N2(as)})]})}),ut&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:ls=>{ls.stopPropagation(),S(St.info.id,Bt)},"aria-label":e(Xt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Xt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Xt?s.jsx(C,{name:"check",className:"size-3.5"}):s.jsx(C,{name:"file-copy",className:"size-3.5"})})}),s.jsx(ax,{language:"json",style:i,PreTag:"div",customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},codeTagProps:{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"break-word"}},wrapLongLines:!0,children:Bt})]})})]},St.info.id)},t[182]=d,t[183]=o,t[184]=i,t[185]=e,t[186]=Nt):Nt=t[186],vt=[...b].reverse().map(Nt),t[176]=d,t[177]=o,t[178]=b,t[179]=i,t[180]=e,t[181]=vt}else vt=t[181];let Et;t[187]!==vt?(Et=s.jsx("div",{className:"mt-2.5 space-y-1",children:vt}),t[187]=vt,t[188]=Et):Et=t[188];let Gt;t[189]!==Ue||t[190]!==Et?(Gt=s.jsxs("div",{children:[Ue,Et]}),t[189]=Ue,t[190]=Et,t[191]=Gt):Gt=t[191];let ts;return t[192]!==Ne||t[193]!==De||t[194]!==qe||t[195]!==Je||t[196]!==nt||t[197]!==Gt?(ts=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[Ne,De,qe,Je,nt,Gt]})}),t[192]=Ne,t[193]=De,t[194]=qe,t[195]=Je,t[196]=nt,t[197]=Gt,t[198]=ts):ts=t[198],ts};function I2(t){return t.currentSessionId}function P2(t){return t.providers}function A2(t){return Object.keys(t).length>0?{}:t}function D2(t){return so(t.info).role==="assistant"}function T2(t){return so(t.info).isUser}function M2(t,e){const n=fa(e.info.cost);return t+n}function E2(t){return so(t.info).isUser&&typeof t.info.system=="string"}function R2(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 F2(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:Xa(t.value)})]},t.label)}const L2=360,O2=1400,Vf=600,$2=24,Mm=200,B2=(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",nd=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"},zf=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:i,intro:a})=>{const o=r.text.trim(),c=Object.entries(r.attributes).map(([b,h])=>`${b}="${h}"`).join(" "),d=r.computedStyle,p=r.bounds,m=r.center,u=a.replace(/[.:]+$/g,""),f=r.ancestry.map(b=>b.selectorPart).join(" > ");return[`${u}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${i?"attached":"not attached"}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,c?`- Attributes: ${c}`:null,`- Bounds: x=${Math.round(p.x)}, y=${Math.round(p.y)}, width=${Math.round(p.width)}, height=${Math.round(p.height)}`,`- Center: x=${Math.round(m.x)}, y=${Math.round(m.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(b=>typeof b=="string").join(`
|
|
56
|
-
`)},_2=async(t,e)=>{const n=typeof window<"u"?window.__TAURI__:void 0;if(typeof n?.core?.invoke=="function")try{const r=t.getBoundingClientRect(),i=await n.core.invoke("desktop_capture_page_rect",{x:r.left,y:r.top,width:r.width,height:r.height}),a=new Image;await new Promise((v,x)=>{a.onload=()=>v(),a.onerror=()=>x(new Error("Failed to load desktop preview screenshot")),a.src=`data:${i.mime};base64,${i.base64}`});const o=Math.max(1,a.naturalWidth||i.width||Math.floor(r.width)),c=Math.max(1,a.naturalHeight||i.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(a,0,0,o,c);const f=o/Math.max(1,r.width),b=c/Math.max(1,r.height);u.fillStyle="rgba(37, 99, 235, 0.28)",u.strokeStyle="rgb(37, 99, 235)",u.lineWidth=Math.max(2,2*f),u.fillRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b),u.strokeRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b);const h=await new Promise(v=>m.toBlob(v,"image/jpeg",.82));return h?new File([h],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},V2=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},Em=t=>Number.isFinite(t)?Math.min(O2,Math.max(L2,Math.round(t))):Vf,z2=(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},U2=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":t==="browser"?"contextPanel.mode.browser":"contextPanel.mode.context"),W2=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},K2=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return W2(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 U2(t.mode,e)},H2=t=>{if(t.mode==="file")return t.targetPath?s.jsx(yr,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(C,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(C,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(C,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(C,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(C,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(C,{name:"global",className:"h-3.5 w-3.5"})},G2=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,q2=`new Promise((resolve) => {
|
|
57
|
-
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
58
|
-
if (existing) existing.remove();
|
|
59
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
60
|
-
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
61
|
-
}
|
|
62
|
-
const overlay = document.createElement('div');
|
|
63
|
-
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
64
|
-
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
65
|
-
document.documentElement.appendChild(overlay);
|
|
66
|
-
const cssEscape = (value) => {
|
|
67
|
-
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
68
|
-
};
|
|
69
|
-
const selectorPart = (element) => {
|
|
70
|
-
const tag = element.tagName.toLowerCase();
|
|
71
|
-
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
72
|
-
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
73
|
-
return tag + className;
|
|
74
|
-
};
|
|
75
|
-
const metadata = (element) => {
|
|
76
|
-
const rect = element.getBoundingClientRect();
|
|
77
|
-
const style = getComputedStyle(element);
|
|
78
|
-
const ancestry = [];
|
|
79
|
-
let current = element;
|
|
80
|
-
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
81
|
-
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
82
|
-
current = current.parentElement;
|
|
83
|
-
}
|
|
84
|
-
const attrs = {};
|
|
85
|
-
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
86
|
-
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
87
|
-
return {
|
|
88
|
-
frame: 'top',
|
|
89
|
-
tag: element.tagName.toLowerCase(),
|
|
90
|
-
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
91
|
-
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
92
|
-
path,
|
|
93
|
-
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
94
|
-
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
95
|
-
attributes: attrs,
|
|
96
|
-
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
97
|
-
ancestry,
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
const move = (event) => {
|
|
101
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
102
|
-
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
103
|
-
const rect = element.getBoundingClientRect();
|
|
104
|
-
overlay.style.display = 'block';
|
|
105
|
-
overlay.style.left = rect.left + 'px';
|
|
106
|
-
overlay.style.top = rect.top + 'px';
|
|
107
|
-
overlay.style.width = rect.width + 'px';
|
|
108
|
-
overlay.style.height = rect.height + 'px';
|
|
109
|
-
};
|
|
110
|
-
const cleanup = () => {
|
|
111
|
-
window.removeEventListener('mousemove', move, true);
|
|
112
|
-
window.removeEventListener('click', click, true);
|
|
113
|
-
window.removeEventListener('keydown', keydown, true);
|
|
114
|
-
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
115
|
-
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
const cancel = () => {
|
|
119
|
-
cleanup();
|
|
120
|
-
overlay.remove();
|
|
121
|
-
resolve(null);
|
|
122
|
-
};
|
|
123
|
-
const click = (event) => {
|
|
124
|
-
event.preventDefault();
|
|
125
|
-
event.stopPropagation();
|
|
126
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
127
|
-
const result = element ? metadata(element) : null;
|
|
128
|
-
cleanup();
|
|
129
|
-
overlay.remove();
|
|
130
|
-
resolve(result);
|
|
131
|
-
};
|
|
132
|
-
const keydown = (event) => {
|
|
133
|
-
if (event.key !== 'Escape') return;
|
|
134
|
-
cancel();
|
|
135
|
-
};
|
|
136
|
-
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
137
|
-
window.addEventListener('mousemove', move, true);
|
|
138
|
-
window.addEventListener('click', click, true);
|
|
139
|
-
window.addEventListener('keydown', keydown, true);
|
|
140
|
-
});`,mc=`(() => {
|
|
141
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
142
|
-
window.__openchamberDesktopBrowserCancelInspect();
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
146
|
-
if (overlay) overlay.remove();
|
|
147
|
-
})()`,pc=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},J2=async(t,e,n,r,i,a)=>{if(!t)return null;try{const o=new Image;await new Promise((x,g)=>{o.onload=()=>x(),o.onerror=()=>g(new Error("Failed to load desktop browser screenshot")),o.src=`data:image/jpeg;base64,${t}`});const c=Math.max(1,o.naturalWidth||e),d=Math.max(1,o.naturalHeight||n),m=Math.min(1,1200/c),u=document.createElement("canvas");u.width=Math.floor(c*m),u.height=Math.floor(d*m);const f=u.getContext("2d");if(!f)return null;f.scale(m,m),f.drawImage(o,0,0,c,d);const b=c/Math.max(1,r||c),h=d/Math.max(1,i||d);f.fillStyle="rgba(37, 99, 235, 0.14)",f.strokeStyle="rgb(37, 99, 235)",f.lineWidth=Math.max(2,2*b),f.fillRect(a.bounds.x*b,a.bounds.y*h,a.bounds.width*b,a.bounds.height*h),f.strokeRect(a.bounds.x*b,a.bounds.y*h,a.bounds.width*b,a.bounds.height*h);const v=await new Promise(x=>u.toBlob(x,"image/jpeg",.82));return v?new File([v],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Q2=(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()},Y2=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,xa=new Map,X2=3e4,Z2=t=>{const e=xa.get(t);return e?e.expiresAt-Date.now()<=X2?(xa.delete(t),null):e:null},eS=({rawUrl:t,onNavigate:e})=>{const{t:n}=mt(),{currentTheme:r}=Nr(),[i,a]=l.useReducer(ue=>ue+1,0),[o,c]=l.useReducer(ue=>ue+1,0),[d,p]=l.useState({status:"idle"}),m=l.useRef(null),u=l.useRef(1),[f,b]=l.useState(!1),[h,v]=l.useState(!1),[x,g]=l.useState("all"),[w,y]=l.useState([]),[S,D]=l.useState(!1),[j,I]=l.useState(null),A=Ht(ue=>ue.currentSessionId),E=Ht(ue=>ue.newSessionDraft?.open),P=ei(ue=>ue.addDraft),k=Ca(ue=>ue.addAttachedFile);let N=null;try{N=t?new URL(t):null}catch{N=null}const T=N?N.hostname==="localhost"||N.hostname==="127.0.0.1"||N.hostname==="::1"||N.hostname==="[::1]"||N.hostname==="0.0.0.0":!1,M=N?N.hostname==="0.0.0.0"?new URL(N.toString().replace("0.0.0.0","127.0.0.1")):N:null,R=M?M.toString():"",L=r.metadata.variant;l.useEffect(()=>{if(!R||!T){p({status:"idle"});return}const ue=Z2(R);if(ue){p({status:"ready",proxyBasePath:ue.proxyBasePath,expiresAt:ue.expiresAt});return}let je=!1;return p({status:"loading"}),(async()=>{try{const W=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:R})});if(!W.ok){xa.delete(R);const ee=await W.json().catch(()=>({})),Pe=typeof ee?.error=="string"?ee.error:`HTTP ${W.status}`;je||p({status:"error",message:Pe});return}const me=await W.json(),X=typeof me.proxyBasePath=="string"?me.proxyBasePath:"",ce=typeof me.expiresAt=="number"?me.expiresAt:0;if(!X){xa.delete(R),je||p({status:"error",message:n("contextPanel.preview.proxyError")});return}xa.set(R,{proxyBasePath:X,expiresAt:ce}),je||p({status:"ready",proxyBasePath:X,expiresAt:ce})}catch(W){if(xa.delete(R),!je){const me=W instanceof Error?W.message:String(W);p({status:"error",message:me})}}})(),()=>{je=!0}},[T,o,n,R]);const O=M&&(M.protocol==="http:"||M.protocol==="https:")?M.toString():"",V=T&&d.status==="ready"&&M?(()=>{const ue=M.pathname||"/",je=new URLSearchParams(M.search);je.set("ocPreview",String(i));const W=je.toString(),me=M.hash||"";return`${d.proxyBasePath}${ue}${W?`?${W}`:""}${me}`})():"",$=T?V:O,B=$||O,H=T&&(d.status==="loading"||d.status==="idle"),_=T&&d.status==="error",se=l.useCallback(ue=>{const je=A??(E?"draft":null);if(!je){q.error(n("contextPanel.preview.inspect.attachNoSession"));return}const W=t||$||"",me=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},X=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let ce=!1;try{const ee=m.current,Pe=ee?await _2(ee,ue):null;Pe&&(await k(Pe),ce=!0)}catch{ce=!1}P({sessionKey:je,source:"preview-annotation",fileLabel:W||"preview",startLine:1,endLine:1,code:zf({pageUrl:W,viewport:me,devicePixelRatio:X,target:ue,screenshotAttached:ce,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),q.success(n("contextPanel.preview.inspect.attached"))})()},[k,P,A,$,E,t,n]);l.useEffect(()=>{b(!1),y([]),v(!1),g("all"),D(!1),I(null),u.current=1},[$]),l.useEffect(()=>{const ue=m.current?.contentWindow;!f||!ue||ue.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:S},window.location.origin)},[f,S]),l.useEffect(()=>{const ue=m.current?.contentWindow;!f||!ue||ue.postMessage({source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:L},window.location.origin)},[f,L]),l.useEffect(()=>{if(!S||typeof window>"u")return;const ue=je=>{je.key==="Escape"&&(je.preventDefault(),je.stopImmediatePropagation(),D(!1))};return window.addEventListener("keydown",ue,!0),()=>window.removeEventListener("keydown",ue,!0)},[S]),l.useEffect(()=>{if(!T||typeof window>"u")return;const ue=me=>{if(typeof me=="string")return me;if(me==null)return"";try{return JSON.stringify(me)}catch{return String(me)}},je=me=>{const X=u.current;u.current+=1,y(ce=>{const ee=[...ce,{...me,id:X}];return ee.length>Mm?ee.slice(ee.length-Mm):ee})},W=me=>{if(me.source!==m.current?.contentWindow)return;const X=me.data;if(!(!X||X.source!=="openchamber-preview-bridge"||X.version!==1)){if(X.type==="ready"){b(!0);return}if(X.type==="console"){const ce=X.level==="error"||X.level==="warn"||X.level==="info"||X.level==="debug"?X.level:"log",ee=Array.isArray(X.args)?X.args.map(ue).filter(Boolean):[];je({level:ce,message:ee.join(" "),ts:typeof X.ts=="number"?X.ts:Date.now()});return}if(X.type==="runtime-error"){const ce=ue(X.filename),ee=typeof X.line=="number"?X.line:null,Pe=typeof X.column=="number"?X.column:null,Ne=ce?`${ce}${ee!==null?`:${ee}${Pe!==null?`:${Pe}`:""}`:""}`:"",Y=ue(X.stack);je({level:"runtime",message:ue(X.message)||n("contextPanel.preview.console.runtimeError"),details:[Ne,Y].filter(Boolean).join(`
|
|
148
|
-
`),ts:typeof X.ts=="number"?X.ts:Date.now()});return}if(X.type==="resource-error"){const ce=ue(X.tag)||"resource",ee=ue(X.url);je({level:"resource",message:ee?`${ce}: ${ee}`:ce,details:ue(X.outerHTML),ts:typeof X.ts=="number"?X.ts:Date.now()});return}if(X.type==="hover"){I(nd(X.target)?X.target:null);return}if(X.type==="select"&&nd(X.target)){I(X.target),D(!1),se(X.target);return}if(X.type==="navigate-preview"){const ce=typeof X.url=="string"?X.url:"",ee=X.navigation==="external"?"external":"proxy";if(ce&&ee==="external"){Qn(ce);return}ce&&e(ce)}}};return window.addEventListener("message",W),()=>{window.removeEventListener("message",W)}},[se,T,e,n]);const oe=w.filter(ue=>ue.level==="error"||ue.level==="runtime"||ue.level==="resource").length,ae=w.filter(ue=>B2(ue,x)),ne=l.useCallback(()=>{const ue=[`Preview URL: ${t||$||""}`,`Events: ${w.length}`,""].join(`
|
|
149
|
-
`),je=w.map(W=>{const me=new Date(W.ts).toISOString(),X=W.details?`
|
|
150
|
-
${W.details}`:"";return`[${me}] [${W.level}] ${W.message}${X}`}).join(`
|
|
151
|
-
`);Rn(`${ue}${je}`).then(W=>{W.ok?q.success(n("contextPanel.preview.console.copied")):q.error(n("contextPanel.preview.console.copyFailed"))})},[w,$,t,n]),xe=l.useCallback(()=>{const ue=A??(E?"draft":null);if(!ue){q.error(n("contextPanel.preview.console.attachNoSession"));return}const je=[`Preview URL: ${t||$||""}`,`Events: ${w.length}`,""].join(`
|
|
152
|
-
`),W=w.map(me=>{const X=new Date(me.ts).toISOString(),ce=me.details?`
|
|
153
|
-
${me.details}`:"";return`[${X}] [${me.level}] ${me.message}${ce}`}).join(`
|
|
154
|
-
`);P({sessionKey:ue,source:"preview-console",fileLabel:t||$||"preview",startLine:1,endLine:Math.max(1,w.length),code:`${je}${W}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),q.success(n("contextPanel.preview.console.attached"))},[P,w,A,$,E,t,n]),[te,F]=l.useState("unknown"),z=l.useRef(0),Q=l.useRef(0),re=15e3;l.useEffect(()=>{if(!V){F("unknown"),z.current=0,Q.current=0;return}let ue=!1;return z.current||(z.current=Date.now(),Q.current=0),F("unknown"),(async()=>{const W=await(async()=>{try{return await fetch(V,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(ue)return;if(!W){F("unreachable");return}if(W.status===403||W.status===404){xa.delete(R),p({status:"loading"}),c();return}if(W.status!==502){F("reachable");return}const me=z.current||Date.now();if(Date.now()-me<re){F("starting"),Q.current+=1;const ce=Q.current,ee=Math.min(2e3,250*Math.pow(2,Math.min(4,ce)));setTimeout(()=>{ue||a()},ee).unref?.();return}F("unreachable")})(),()=>{ue=!0}},[V,i,R]);const K=T&&d.status==="ready"&&(te==="unknown"||te==="starting"),le=T&&d.status==="ready"&&te==="unreachable",Se=l.useCallback(ue=>{if(!T||d.status!=="ready"||typeof window>"u")return;const je=ue.currentTarget.contentWindow;if(je)try{const W=je.location;if(W.origin!==window.location.origin||W.pathname.startsWith(d.proxyBasePath))return;const me=`${d.proxyBasePath}${W.pathname}${W.search}${W.hash}`;je.location.replace(me)}catch{}},[T,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:B||t,children:B||t||n("contextPanel.preview.empty")}),s.jsx(ve,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>a(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!$,children:s.jsx(C,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{O&&Qn(O)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!O,children:s.jsx(C,{name:"external-link",className:"h-3.5 w-3.5"})}),T?s.jsx(ve,{type:"button",size:"sm",variant:S?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>D(ue=>!ue),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!f,children:s.jsx(C,{name:"cursor",className:"h-3.5 w-3.5"})}):null,T?s.jsxs(ve,{type:"button",size:"sm",variant:h?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(ue=>!ue),title:n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!f&&w.length===0,children:[s.jsx(C,{name:"terminal-box",className:"h-3.5 w-3.5"}),oe>0?s.jsx("span",{className:"typography-micro text-status-error",children:oe}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[K?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")})]}):le?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(ve,{type:"button",size:"sm",variant:"outline",onClick:()=>a(),children:n("contextPanel.preview.actions.retry")})]}):$&&(!T||te==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:$,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:L},onLoad:Se,sandbox:T?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${$}:${i}`),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]}):H?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):_?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),h?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:xe,disabled:w.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:ne,disabled:w.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:()=>y([]),disabled:w.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(ue=>s.jsx(ve,{type:"button",size:"xs",variant:x===ue?"secondary":"ghost",onClick:()=>g(ue),children:n(ue==="all"?"contextPanel.preview.console.filter.all":ue==="errors"?"contextPanel.preview.console.filter.errors":ue==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},ue))}),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")}):ae.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ae.map(ue=>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",ue.level==="error"||ue.level==="runtime"||ue.level==="resource"?"text-status-error":ue.level==="warn"?"text-status-warning":"text-muted-foreground"),children:ue.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:ue.message})]})},ue.id))})]}):null]})]})},tS=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=mt(),i=l.useRef(null),a=Me(E=>E.setContextPanelTabTargetPath),o=pc(t),c=o!=="about:blank"?o:"",[d,p]=l.useState(c),[m,u]=l.useState(c),[f,b]=l.useState(!1),[h,v]=l.useState(!0),x=l.useRef(null),g=h,w=l.useCallback(E=>{!E||E==="about:blank"||!e||!n||a(e,n,E)},[e,n,a]),y=Ht(E=>E.currentSessionId),S=Ht(E=>E.newSessionDraft?.open),D=ei(E=>E.addDraft),j=Ca(E=>E.addAttachedFile);l.useEffect(()=>{const E=i.current;if(!E)return;const P=()=>{try{const R=E.getURL();R&&R!=="about:blank"&&(u(R),p(R),w(R))}catch{}},k=R=>{const L=R.detail;typeof L?.url=="string"&&L.url&&(u(L.url),p(L.url),w(L.url))},N=()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>v(!0),200)},T=()=>{x.current&&clearTimeout(x.current),v(!1),P()},M=R=>{const L=R.detail;if(L?.disposition==="new-window"||L?.disposition==="foreground-tab"||L?.disposition==="background-tab"){R.preventDefault();const O=i.current;typeof O?.loadURL=="function"&&L.url&&O.loadURL(L.url)}};E.addEventListener("did-navigate",k),E.addEventListener("did-navigate-in-page",k),E.addEventListener("did-start-loading",N),E.addEventListener("did-stop-loading",T),E.addEventListener("new-window",M);try{E.isLoading()||(v(!1),P())}catch{}return()=>{x.current&&clearTimeout(x.current),E.removeEventListener("did-navigate",k),E.removeEventListener("did-navigate-in-page",k),E.removeEventListener("did-start-loading",N),E.removeEventListener("did-stop-loading",T),E.removeEventListener("new-window",M)}},[w]),l.useEffect(()=>{const E=setTimeout(()=>v(!1),3e4);return()=>clearTimeout(E)},[]),l.useEffect(()=>{if(!f)return;const E=P=>{if(P.key!=="Escape")return;P.preventDefault(),P.stopImmediatePropagation(),b(!1);const k=i.current;try{k?.executeJavaScript?.(mc).catch(()=>{})}catch{}};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[f]),l.useEffect(()=>{const E=i.current;return()=>{try{const P=E?.getURL?.();P&&P!=="about:blank"&&a(e,n,P)}catch{}try{E?.executeJavaScript?.(mc).catch(()=>{})}catch{}}},[e,n,a]);const I=l.useCallback(E=>{const P=i.current;if(typeof P?.loadURL!="function")return;const k=pc(E);try{P.loadURL(k)}catch{}},[]),A=l.useCallback(()=>{const E=i.current;if(E){if(f){b(!1);try{E.executeJavaScript?.(mc).catch(()=>{})}catch{}return}b(!0),E.executeJavaScript?.(q2,!0).then(async P=>{if(b(!1),!P||!nd(P))return;const k=y??(S?"draft":null);if(!k){q.error(r("contextPanel.preview.inspect.attachNoSession"));return}const N=typeof E.getWebContentsId=="function"?E.getWebContentsId():null;if(N==null)return;const T=await lb("desktop_browser_capture_page",{webContentsId:N}),M=await E.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),R=Number.isFinite(M?.width)?M.width:T.width,L=Number.isFinite(M?.height)?M.height:T.height,O=await J2(T.base64,T.width,T.height,R,L,P),V=!!O;O&&await j(O),D({sessionKey:k,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:zf({pageUrl:m,viewport:{width:R,height:L},devicePixelRatio:window.devicePixelRatio||1,target:P,screenshotAttached:V,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),q.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[j,D,y,m,f,S,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(ve,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{i.current?.goBack?.()}catch{}},children:s.jsx(C,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{i.current?.goForward?.()}catch{}},children:s.jsx(C,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{i.current?.reload?.()}catch{}},children:s.jsx(C,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:E=>{E.preventDefault(),I(d)},children:s.jsx("input",{value:d,onChange:E=>p(E.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(ve,{type:"button",variant:f?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:A,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(C,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{Qn(m)},children:s.jsx(C,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:i,src:pc(t),partition:"persist:openchamber-browser",style:{width:"100%",height:"100%",border:"none"}}),(!m||m==="about:blank")&&!h?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Cd,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,g?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},sS=()=>{const{t}=mt(),e=Or()??"",n=l.useMemo(()=>V2(e),[e]),r=Me(K=>n?K.contextPanelByDirectory[n]:void 0),i=Me(K=>K.closeContextPanel),a=Me(K=>K.closeContextPanelTab),o=Me(K=>K.toggleContextPanelExpanded),c=Me(K=>K.setContextPanelWidth),d=Me(K=>K.setActiveContextPanelTab),p=Me(K=>K.reorderContextPanelTabs),m=Me(K=>K.setPendingDiffFile),u=$n(K=>K.setSelectedPath),f=Me(K=>K.openContextPreview),{themeMode:b,lightThemeId:h,darkThemeId:v,currentTheme:x}=Nr(),g=l.useMemo(()=>r?.tabs??[],[r?.tabs]),w=g.find(K=>K.id===r?.activeTabId)??g[g.length-1]??null,y=!!(r?.isOpen&&w),S=!!(y&&r?.expanded),D=Em(r?.width??Vf),[j,I]=l.useState(!1),A=l.useRef(0),E=l.useRef(D),P=l.useRef(null),k=l.useRef(null),N=l.useRef(null),T=l.useRef(new Map),M=l.useRef(!1);l.useEffect(()=>{if(!y||M.current){M.current=y;return}const K=window.requestAnimationFrame(()=>{N.current?.focus({preventScroll:!0})});return M.current=!0,()=>window.cancelAnimationFrame(K)},[y]);const R=l.useCallback(K=>{const le=N.current;le&&le.style.setProperty("--oc-context-panel-width",`${K}px`)},[]),L=l.useCallback(K=>{if(!(!y||S||!n)){try{K.currentTarget.setPointerCapture(K.pointerId)}catch{}k.current=K.pointerId,I(!0),A.current=K.clientX,E.current=D,P.current=D,R(D),K.preventDefault()}},[R,n,S,y,D]),O=l.useCallback(K=>{if(!j||k.current!==K.pointerId)return;const le=A.current-K.clientX,Se=Em(E.current+le);P.current!==Se&&(P.current=Se,R(Se))},[R,j]),V=l.useCallback(K=>{if(k.current!==K.pointerId||!n)return;try{K.currentTarget.releasePointerCapture(K.pointerId)}catch{}const le=P.current??D;I(!1),k.current=null,P.current=null,c(n,le)},[n,c,D]);l.useEffect(()=>{j||(P.current=null)},[j]);const $=l.useCallback(()=>{n&&i(n)},[i,n]),B=l.useCallback(()=>{n&&o(n)},[n,o]),H=l.useCallback(K=>{K.key==="Escape"&&(K.preventDefault(),K.stopPropagation(),$())},[$]);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 _=w?.mode==="chat"?w.id:null,se=l.useCallback(()=>{if(typeof window>"u")return;const K={themeMode:b,lightThemeId:h,darkThemeId:v,currentTheme:x};for(const le of T.current.values()){const Se=le.contentWindow;if(!Se)continue;const ue=Se.__openchamberApplyThemeSync;if(typeof ue=="function")try{ue(K);continue}catch{}Se.postMessage({type:"openchamber:theme-sync",payload:K},window.location.origin)}},[x,v,h,b]),oe=l.useCallback(()=>{if(!(typeof window>"u"))for(const[K,le]of T.current.entries()){const Se=le.contentWindow;if(!Se)continue;const ue={visible:_===K},je=Se.__openchamberSetEmbeddedVisibility;if(typeof je=="function")try{je(ue);continue}catch{}Se.postMessage({type:"openchamber:embedded-visibility",payload:ue},window.location.origin)}},[_]);l.useLayoutEffect(()=>{g.some(le=>le.mode==="chat")&&(se(),oe())},[v,h,oe,se,g,b]);const ae=l.useMemo(()=>g.map(K=>{const le=K2(K,t),Se=Y2(le,$2),ue=z2(K.targetPath,e);return{id:K.id,label:Se,icon:H2(K),title:ue?`${le}: ${ue}`:le,closeLabel:t("contextPanel.tab.closeTabAria",{label:Se})}}),[e,t,g]),ne=w?.mode==="diff"?s.jsx(Rf,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0}):w?.mode==="context"?s.jsx(C2,{}):w?.mode==="plan"?s.jsx(_f,{targetPath:w.targetPath}):w?.mode==="preview"?s.jsx(eS,{rawUrl:w.targetPath??"",onNavigate:K=>f(e,K)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(C,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),xe=l.useMemo(()=>g.filter(K=>K.mode==="chat"),[g]),te=l.useMemo(()=>g.filter(K=>K.mode==="browser"),[g]),F=l.useMemo(()=>g.some(K=>K.mode==="file"),[g]),z=w?.mode==="file",Q=s.jsxs("header",{className:"flex h-8 items-stretch border-b border-transparent",children:[s.jsx(Tr,{items:ae,activeId:w?.id??null,onSelect:K=>{n&&d(n,K)},onClose:K=>{n&&a(n,K)},onReorder:(K,le)=>{n&&p(n,K,le)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:B,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(C,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:$,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]})]});if(!y)return null;const re=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?P.current??D:D}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:H,style:re,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:L,onPointerMove:O,onPointerUp:V,onPointerCancel:V,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),Q,s.jsxs("div",{className:pe("relative min-h-0 flex-1 overflow-hidden",j&&"pointer-events-none"),children:[F?s.jsx("div",{className:pe("absolute inset-0",z?"block":"hidden"),children:s.jsx(Bf,{mode:"editor-only"})}):null,xe.map(K=>{const le=G2(K.dedupeKey);if(!le)return null;const Se=Q2(le,n||null);return Se?s.jsx("iframe",{ref:ue=>{if(!ue){T.current.delete(K.id);return}T.current.set(K.id,ue)},src:Se,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:le}),className:pe("absolute inset-0 h-full w-full border-0 bg-background",_===K.id?"block":"hidden"),onLoad:()=>{se(),oe()}},K.id):null}),te.map(K=>s.jsx("div",{className:pe("absolute inset-0",w?.mode!=="browser"&&"hidden"),children:s.jsx(tS,{initialUrl:K.targetPath??"",directory:n,tabID:K.id})},K.id)),w?.mode!=="chat"&&!z&&w?.mode!=="browser"?ne:null]})]})},Od=[{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}],nS={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function Ei(t){const e=t.trim().toLowerCase();return Od.find(n=>n.slug===e)??null}function Uf(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=nS[e];if(n)return n;const r=Ei(e);return r?r.slug:"home"}const Wf=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),io=t=>{const e=rt.c(39),{className:n}=t,{t:r}=mt(),i=Es(rS),a=Es(aS),o=Es(iS),c=pn();let d;e[0]!==i?(d=[...i].sort(oS),e[0]=i,e[1]=d):d=e[1];const p=d;let m;e:{if(p.length===0){m=null;break e}let M;e[2]!==a||e[3]!==p?(M=p.find(R=>R.id===a)??p[0],e[2]=a,e[3]=p,e[4]=M):M=e[4],m=M}const u=m;if(c||p.length===0)return null;let f;e[5]!==u||e[6]!==r?(f=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||r("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=r,e[7]=f):f=e[7];const b=f;let h;e[8]!==b?(h=Wf(b),e[8]=b,e[9]=h):h=e[9];const v=h;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 y,S;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=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(C,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=y,e[17]=S):(y=e[16],S=e[17]);let D;e[18]!==v?(D=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:v}),e[18]=v,e[19]=D):D=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(C,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let I;e[21]!==D||e[22]!==g||e[23]!==w?(I=s.jsx(Os,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":g,title:w,className:y,children:[S,D,j]})}),e[21]=D,e[22]=g,e[23]=w,e[24]=I):I=e[24];const A=u?.id??"";let E;e[25]!==o?(E=M=>{M&&o(M)},e[25]=o,e[26]=E):E=e[26];let P;e[27]!==p?(P=p.map(lS),e[27]=p,e[28]=P):P=e[28];let k;e[29]!==A||e[30]!==E||e[31]!==P?(k=s.jsx($s,{align:"start",className:"w-auto",children:s.jsx(tl,{value:A,onValueChange:E,children:P})}),e[29]=A,e[30]=E,e[31]=P,e[32]=k):k=e[32];let N;e[33]!==I||e[34]!==k?(N=s.jsxs(Bs,{children:[I,k]}),e[33]=I,e[34]=k,e[35]=N):N=e[35];let T;return e[36]!==N||e[37]!==x?(T=s.jsx("div",{className:x,children:N}),e[36]=N,e[37]=x,e[38]=T):T=e[38],T};function rS(t){return t.projects}function aS(t){return t.activeProjectId}function iS(t){return t.setActiveProject}function oS(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function lS(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=Wf(e);return s.jsx(sl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function cS(t,e){return`opencode:sidebar-group:${t}:${e}`}const rd=t=>{const e=rt.c(33),{label:n,count:r,storageKey:i,defaultExpanded:a,children:o}=t,c=a===void 0?!0:a;let d;e[0]!==n||e[1]!==i?(d=cS(i,n),e[0]=n,e[1]=i,e[2]=d):d=e[2];const p=d,m=l.useId();let u;e[3]!==c||e[4]!==p?(u=()=>{try{const k=localStorage.getItem(p);if(k!==null)return k==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=u):u=e[5];const[f,b]=$e.useState(u);let h,v;e[6]!==f||e[7]!==p?(h=()=>{try{localStorage.setItem(p,String(f))}catch{}},v=[p,f],e[6]=f,e[7]=p,e[8]=h,e[9]=v):(h=e[8],v=e[9]),$e.useEffect(h,v);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>b(dS),e[10]=x):x=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=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[11]=g):g=e[11];const w=!f&&"-rotate-90";let y;e[12]!==w?(y=pe("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",w),e[12]=w,e[13]=y):y=e[13];let S;e[14]!==y?(S=s.jsx(C,{name:"arrow-down-s",className:y}),e[14]=y,e[15]=S):S=e[15];let D;e[16]!==n?(D=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=D):D=e[17];let j;e[18]!==r?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:r}),e[18]=r,e[19]=j):j=e[19];let I;e[20]!==m||e[21]!==f||e[22]!==S||e[23]!==D||e[24]!==j?(I=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":f,"aria-controls":m,className:g,children:[S,D,j]}),e[20]=m,e[21]=f,e[22]=S,e[23]=D,e[24]=j,e[25]=I):I=e[25];const A=!f;let E;e[26]!==o||e[27]!==m||e[28]!==A?(E=s.jsx("div",{id:m,hidden:A,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[26]=o,e[27]=m,e[28]=A,e[29]=E):E=e[29];let P;return e[30]!==I||e[31]!==E?(P=s.jsxs("div",{children:[I,E]}),e[30]=I,e[31]=E,e[32]=P):P=e[32],P};function dS(t){return!t}const uS=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},mS=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())},Rm=t=>{const e=mS(uS(t));if(e.length===0)return;const n={};for(const i of e)i.permission&&((n[i.permission]||={})[i.pattern]=i.action);const r={};for(const[i,a]of Object.entries(n)){const o=Object.keys(a);if(o.length===1&&o[0]==="*"){r[i]=a["*"];continue}r[i]=a}return Object.keys(r).length>0?r:void 0},pS=({onItemSelect:t})=>{const{t:e}=mt(),[n,r]=l.useState(null),[i,a]=l.useState(""),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedAgentName:h,agents:v,setSelectedAgent:x,setAgentDraft:g,createAgent:w,deleteAgent:y,loadAgents:S}=li(mr(B=>({selectedAgentName:B.selectedAgentName,agents:B.agents,setSelectedAgent:B.setSelectedAgent,setAgentDraft:B.setAgentDraft,createAgent:B.createAgent,deleteAgent:B.deleteAgent,loadAgents:B.loadAgents})));l.useEffect(()=>{S()},[S]);const D="bg-background",j=()=>{const B="new-agent";let H=B,_=1;for(;v.some(se=>se.name===H);)H=`${B}-${_}`,_++;g({name:H,scope:"user"}),x(H),t?.()},I=async B=>{if(ti(B)){q.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(B),p("delete")},A=async B=>{ti(B)&&(c(B),p("reset"))},E=()=>{c(null),p(null)},P=async()=>{if(!o||!d)return;u(!0),await y(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})),E()):d==="delete"?q.error(e("settings.agents.sidebar.toast.deleteFailed")):q.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},k=B=>{const H=B.name;let _=1,se=`${H}-copy`;for(;v.some(xe=>xe.name===se);)_++,se=`${H}-copy-${_}`;const oe=B,ae=B.model?.providerID&&B.model?.modelID?`${B.model.providerID}/${B.model.modelID}`:null,ne=B;g({name:se,scope:oe.scope||"user",description:B.description,model:ae,temperature:B.temperature,top_p:B.topP,prompt:B.prompt,mode:B.mode,permission:Rm(B.permission),disable:ne.disable}),x(se)},N=B=>{a(B.name),r(B)},T=async()=>{if(!n)return;const B=i.trim().replace(/\s+/g,"-");if(!B){q.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(B===n.name){r(null);return}if(v.some(oe=>oe.name===B)){q.error(e("settings.agents.sidebar.toast.agentExists"));return}const H=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,_=n;await w({name:B,description:n.description,model:H,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Rm(n.permission),disable:_.disable,scope:_.scope})?await y(n.name)?(q.success(`Agent renamed to "${B}"`),x(B)):q.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):q.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},M=B=>{switch(B){case"primary":return s.jsx(C,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(C,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(C,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},R=v.filter(B=>!cb(B)),L=R.filter(ti),O=R.filter(B=>!ti(B)),{groupedCustomAgents:V,ungroupedCustomAgents:$}=$e.useMemo(()=>{const B={},H=[];for(const se of O){const oe=se;oe.group?(B[oe.group]||(B[oe.group]=[]),B[oe.group].push(se)):H.push(se)}return{groupedCustomAgents:Object.keys(B).sort((se,oe)=>se.localeCompare(oe)).map(se=>({name:se,agents:B[se]})),ungroupedCustomAgents:H}},[O]);return s.jsxs("div",{className:pe("flex h-full flex-col",D),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),s.jsx(io,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:R.length})}),s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:s.jsx(C,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(As,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:R.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(C,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[L.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),L.map(B=>s.jsx(hc,{agent:B,isSelected:h===B.name,onSelect:()=>{x(B.name),t?.()},onReset:()=>A(B),onDuplicate:()=>k(B),getAgentModeIcon:M,isMenuOpen:f===B.name,onMenuOpenChange:H=>b(H?B.name:null)},B.name))]}),O.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:B,agents:H})=>s.jsx(rd,{label:B,count:H.length,storageKey:"agents",children:H.map(_=>s.jsx(hc,{agent:_,isSelected:h===_.name,onSelect:()=>{x(_.name),t?.()},onRename:()=>N(_),onDelete:()=>I(_),onDuplicate:()=>k(_),getAgentModeIcon:M,isMenuOpen:f===_.name,onMenuOpenChange:se=>b(se?_.name:null)},_.name))},B)),$.map(B=>s.jsx(hc,{agent:B,isSelected:h===B.name,onSelect:()=>{x(B.name),t?.()},onRename:()=>N(B),onDelete:()=>I(B),onDuplicate:()=>k(B),getAgentModeIcon:M,isMenuOpen:f===B.name,onMenuOpenChange:H=>b(H?B.name:null)},B.name))]})]})}),s.jsx(ws,{open:o!==null&&d!==null,onOpenChange:B=>{!B&&!m&&E()},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Rs,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),s.jsxs(Gs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:E,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:P,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(ws,{open:n!==null,onOpenChange:B=>!B&&r(null),children:s.jsxs(vs,{children:[s.jsxs(Ss,{children:[s.jsx(js,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Rs,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Ut,{value:i,onChange:B=>a(B.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:B=>{B.key==="Enter"&&T()}}),s.jsxs(Gs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:T,children:e("settings.common.actions.rename")})]})]})})]})},hc=t=>{const e=rt.c(58),{agent:n,isSelected:r,onSelect:i,onDelete:a,onReset:o,onRename:c,onDuplicate:d,getAgentModeIcon:p,isMenuOpen:m,onMenuOpenChange:u}=t,{t:f}=mt(),b=n;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Wi(),e[0]=h):h=e[0];const v=h,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=v?void 0:H=>{H.preventDefault(),u(!0)},e[3]=u,e[4]=w):w=e[4];let y;e[5]!==n.name?(y=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=y):y=e[6];let 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 D;e[10]!==n||e[11]!==b.scope||e[12]!==f?(D=(b.scope||ti(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:ti(n)?f("settings.agents.sidebar.badge.system"):b.scope}),e[10]=n,e[11]=b.scope,e[12]=f,e[13]=D):D=e[13];let j;e[14]!==y||e[15]!==S||e[16]!==D?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,S,D]}),e[14]=y,e[15]=S,e[16]=D,e[17]=j):j=e[17];let I;e[18]!==n.description?(I=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=I):I=e[19];let A;e[20]!==i||e[21]!==j||e[22]!==I?(A=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:[j,I]}),e[20]=i,e[21]=j,e[22]=I,e[23]=A):A=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Os,{asChild:!0,children:s.jsx(ve,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(C,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=E):E=e[24];let P;e[25]!==c||e[26]!==f?(P=c&&s.jsxs(zt,{onClick:H=>{H.stopPropagation(),c()},children:[s.jsx(C,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),e[25]=c,e[26]=f,e[27]=P):P=e[27];let k;e[28]!==d?(k=H=>{H.stopPropagation(),d()},e[28]=d,e[29]=k):k=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(C,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=N):N=e[30];let T;e[31]!==f?(T=f("settings.common.actions.duplicate"),e[31]=f,e[32]=T):T=e[32];let M;e[33]!==k||e[34]!==T?(M=s.jsxs(zt,{onClick:k,children:[N,T]}),e[33]=k,e[34]=T,e[35]=M):M=e[35];let R;e[36]!==o||e[37]!==f?(R=o&&s.jsxs(zt,{onClick:H=>{H.stopPropagation(),o()},children:[s.jsx(C,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),e[36]=o,e[37]=f,e[38]=R):R=e[38];let L;e[39]!==a||e[40]!==f?(L=a&&s.jsxs(zt,{onClick:H=>{H.stopPropagation(),a()},className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]}),e[39]=a,e[40]=f,e[41]=L):L=e[41];let O;e[42]!==P||e[43]!==M||e[44]!==R||e[45]!==L?(O=s.jsxs($s,{align:"end",className:"w-fit min-w-20",children:[P,M,R,L]}),e[42]=P,e[43]=M,e[44]=R,e[45]=L,e[46]=O):O=e[46];let V;e[47]!==m||e[48]!==u||e[49]!==O?(V=s.jsxs(Bs,{open:m,onOpenChange:u,children:[E,O]}),e[47]=m,e[48]=u,e[49]=O,e[50]=V):V=e[50];let $;e[51]!==A||e[52]!==V?($=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,V]}),e[51]=A,e[52]=V,e[53]=$):$=e[53];let B;return e[54]!==$||e[55]!==g||e[56]!==w?(B=s.jsx("div",{className:g,onContextMenu:w,children:$}),e[54]=$,e[55]=g,e[56]=w,e[57]=B):B=e[57],B};function Fm(t,e,n){return Math.min(n,Math.max(e,t))}function hS(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 Lm(t,e){const n=hS(e);return n<=0?t:Number(t.toFixed(n))}const yn=$e.forwardRef((t,e)=>{const n=rt.c(125);let r,i,a,o,c,d,p,m,u,f,b,h,v;n[0]!==t?({value:v,onValueChange:p,min:u,max:f,step:b,className:r,containerClassName:i,onBlur:c,disabled:a,fallbackValue:o,onClear:d,emptyLabel:h,...m}=t,n[0]=t,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=c,n[6]=d,n[7]=p,n[8]=m,n[9]=u,n[10]=f,n[11]=b,n[12]=h,n[13]=v):(r=n[1],i=n[2],a=n[3],o=n[4],c=n[5],d=n[6],p=n[7],m=n[8],u=n[9],f=n[10],b=n[11],h=n[12],v=n[13]);const x=u===void 0?-1/0:u,g=f===void 0?1/0:f,w=b===void 0?1:b,y=h===void 0?"—":h,{t:S}=mt();let D;n[14]!==v?(D=()=>v===void 0?"":String(v),n[14]=v,n[15]=D):D=n[15];const[j,I]=$e.useState(D),{isMobile:A}=rn(),E=$e.useRef(!1),P=$e.useRef(null);let k;n[16]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{if(typeof document>"u"||typeof window>"u")return;P.current?.();const ke=Te=>{Te.preventDefault(),Te.stopPropagation(),Te.stopImmediatePropagation?.(),P.current?.()},be=window.setTimeout(()=>{P.current?.()},700),fe=()=>{window.clearTimeout(be),document.removeEventListener("click",ke,!0),P.current=null};P.current=fe,document.addEventListener("click",ke,!0)},n[16]=k):k=n[16];const N=k;let T,M;n[17]===Symbol.for("react.memo_cache_sentinel")?(T=()=>()=>{P.current?.()},M=[],n[17]=T,n[18]=M):(T=n[17],M=n[18]),$e.useEffect(T,M);let R,L;n[19]!==v?(L=()=>{I(v===void 0?"":String(v))},R=[v],n[19]=v,n[20]=R,n[21]=L):(R=n[20],L=n[21]),$e.useEffect(L,R);let O;e:{if(v!==void 0){O=v;break e}if(o!==void 0){O=o;break e}if(Number.isFinite(x)){O=x;break e}O=0}const V=O;let $;n[22]!==g||n[23]!==x||n[24]!==p||n[25]!==w?($=ke=>{const be=Fm(ke,x,g);p(Lm(be,w))},n[22]=g,n[23]=x,n[24]=p,n[25]=w,n[26]=$):$=n[26];const B=$;let H;n[27]!==B||n[28]!==d?(H=ke=>{const be=ke.target.value;if(I(be),be.trim()===""){d?.();return}const fe=Number(be);Number.isFinite(fe)&&B(fe)},n[27]=B,n[28]=d,n[29]=H):H=n[29];const _=H;let se;n[30]!==j||n[31]!==g||n[32]!==x||n[33]!==c||n[34]!==d||n[35]!==p||n[36]!==w||n[37]!==v?(se=ke=>{if(j.trim()===""){d||I(v===void 0?"":String(v)),c?.(ke);return}const be=Number(j);if(!Number.isFinite(be))I(v===void 0?"":String(v));else{const fe=Fm(be,x,g),Te=Lm(fe,w);Te!==v&&p(Te),I(String(Te))}c?.(ke)},n[30]=j,n[31]=g,n[32]=x,n[33]=c,n[34]=d,n[35]=p,n[36]=w,n[37]=v,n[38]=se):se=n[38];const oe=se,ae=!!(a||V>=g),ne=!!(a||V<=x);let xe;n[39]!==V||n[40]!==B||n[41]!==ne||n[42]!==w?(xe=()=>{ne||B(V-w)},n[39]=V,n[40]=B,n[41]=ne,n[42]=w,n[43]=xe):xe=n[43];const te=xe;let F;n[44]!==V||n[45]!==B||n[46]!==ae||n[47]!==w?(F=()=>{ae||B(V+w)},n[44]=V,n[45]=B,n[46]=ae,n[47]=w,n[48]=F):F=n[48];const z=F;let Q;if(n[49]!==r||n[50]!==i||n[51]!==ne||n[52]!==j||n[53]!==y||n[54]!==te||n[55]!==z||n[56]!==ae||n[57]!==A||n[58]!==S||n[59]!==v){Q=Symbol.for("react.early_return_sentinel");e:{const ke=fe=>Te=>{Te.preventDefault(),Te.stopPropagation(),E.current=!0,N(),fe()},be=fe=>Te=>{if(E.current){E.current=!1,Te.preventDefault(),Te.stopPropagation();return}fe()};if(A){let fe;n[61]!==i?(fe=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",i),n[61]=i,n[62]=fe):fe=n[62];let Te;n[63]!==S?(Te=S("numberInput.actions.decreaseAria"),n[63]=S,n[64]=Te):Te=n[64];const Ve=ke(te),G=be(te),Ie=!ne&&"active:bg-interactive-hover";let Oe;n[65]!==Ie?(Oe=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",Ie),n[65]=Ie,n[66]=Oe):Oe=n[66];let De;n[67]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx(C,{name:"subtract",className:"block h-4 w-4"}),n[67]=De):De=n[67];const ge=s.jsx("button",{type:"button","aria-label":Te,disabled:ne,onTouchStart:Ve,onClick:G,className:Oe,children:De});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=v===void 0?y:j;let Ee;n[70]!==U||n[71]!==de?(Ee=s.jsx("div",{className:U,"aria-live":"polite",children:de}),n[70]=U,n[71]=de,n[72]=Ee):Ee=n[72];let _e;n[73]!==S?(_e=S("numberInput.actions.increaseAria"),n[73]=S,n[74]=_e):_e=n[74];const Z=ke(z),ie=be(z),Ce=!ae&&"active:bg-interactive-hover";let He;n[75]!==Ce?(He=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",Ce),n[75]=Ce,n[76]=He):He=n[76];let Ge;n[77]===Symbol.for("react.memo_cache_sentinel")?(Ge=s.jsx(C,{name:"add",className:"block h-4 w-4"}),n[77]=Ge):Ge=n[77];const Xe=s.jsx("button",{type:"button","aria-label":_e,disabled:ae,onTouchStart:Z,onClick:ie,className:He,children:Ge});let we;n[78]!==fe||n[79]!==ge||n[80]!==Ee||n[81]!==Xe?(we=s.jsxs("div",{className:fe,children:[ge,Ee,Xe]}),n[78]=fe,n[79]=ge,n[80]=Ee,n[81]=Xe,n[82]=we):we=n[82],Q=we;break e}}n[49]=r,n[50]=i,n[51]=ne,n[52]=j,n[53]=y,n[54]=te,n[55]=z,n[56]=ae,n[57]=A,n[58]=S,n[59]=v,n[60]=Q}else Q=n[60];if(Q!==Symbol.for("react.early_return_sentinel"))return Q;let re;n[83]!==i?(re=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",i),n[83]=i,n[84]=re):re=n[84];let K;n[85]!==S?(K=S("numberInput.actions.decreaseAria"),n[85]=S,n[86]=K):K=n[86];let le;n[87]!==V||n[88]!==B||n[89]!==w?(le=()=>B(V-w),n[87]=V,n[88]=B,n[89]=w,n[90]=le):le=n[90];let Se,ue;n[91]===Symbol.for("react.memo_cache_sentinel")?(Se=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"),ue=s.jsx(C,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=Se,n[92]=ue):(Se=n[91],ue=n[92]);let je;n[93]!==ne||n[94]!==K||n[95]!==le?(je=s.jsx("button",{type:"button","aria-label":K,disabled:ne,onClick:le,className:Se,children:ue}),n[93]=ne,n[94]=K,n[95]=le,n[96]=je):je=n[96];const W=m.inputMode??"numeric";let me;n[97]!==r?(me=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]=me):me=n[98];let X;n[99]!==a||n[100]!==j||n[101]!==oe||n[102]!==_||n[103]!==m||n[104]!==e||n[105]!==W||n[106]!==me?(X=s.jsx("input",{...m,ref:e,type:"text",inputMode:W,value:j,onChange:_,onBlur:oe,disabled:a,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:me}),n[99]=a,n[100]=j,n[101]=oe,n[102]=_,n[103]=m,n[104]=e,n[105]=W,n[106]=me,n[107]=X):X=n[107];let ce;n[108]!==S?(ce=S("numberInput.actions.increaseAria"),n[108]=S,n[109]=ce):ce=n[109];let ee;n[110]!==V||n[111]!==B||n[112]!==w?(ee=()=>B(V+w),n[110]=V,n[111]=B,n[112]=w,n[113]=ee):ee=n[113];let Pe,Ne;n[114]===Symbol.for("react.memo_cache_sentinel")?(Pe=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"),Ne=s.jsx(C,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=Pe,n[115]=Ne):(Pe=n[114],Ne=n[115]);let Y;n[116]!==ae||n[117]!==ce||n[118]!==ee?(Y=s.jsx("button",{type:"button","aria-label":ce,disabled:ae,onClick:ee,className:Pe,children:Ne}),n[116]=ae,n[117]=ce,n[118]=ee,n[119]=Y):Y=n[119];let he;return n[120]!==re||n[121]!==je||n[122]!==X||n[123]!==Y?(he=s.jsxs("div",{className:re,children:[je,X,Y]}),n[120]=re,n[121]=je,n[122]=X,n[123]=Y,n[124]=he):he=n[124],he});yn.displayName="NumberInput";const Om=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Wo=t=>t==="allow"||t==="ask"||t==="deny",ba=(t,e)=>`${t}::${e}`,Ma=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&Wo(n.action)&&e.set(ba(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},ko=t=>{const e=new Map;for(const n of Ma(t))e.set(ba(n.permission,n.pattern),n);return e},$m=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),fS=(t,e)=>{const n=$m(Ma(t)),r=$m(Ma(e));return n.length!==r.length?!1:n.every((i,a)=>{const o=r[a];return i.permission===o.permission&&i.pattern===o.pattern&&i.action===o.action})},gS=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",xS=(t,e)=>Ma(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),bS=t=>{if(Wo(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(Wo(r)){e.push({permission:n,pattern:"*",action:r});continue}if(r&&typeof r=="object"&&!Array.isArray(r))for(const[i,a]of Object.entries(r))Wo(a)&&e.push({permission:n,pattern:i,action:a})}return e},yS=(t,e)=>{const n=Ma(e),r={};for(const a of n)(r[a.permission]||={})[a.pattern]=a.action;const i={"*":t};for(const[a,o]of Object.entries(r))if(a!=="*"){if(Object.keys(o).length===1&&o["*"]){i[a]=o["*"];continue}i[a]=o}return i},vS=()=>{const{t}=mt(),{isMobile:e}=rn(),{selectedAgentName:n,getAgentByName:r,createAgent:i,updateAgent:a,agents:o,agentDraft:c,setAgentDraft:d}=li(mr(fe=>({selectedAgentName:fe.selectedAgentName,getAgentByName:fe.getAgentByName,createAgent:fe.createAgent,updateAgent:fe.updateAgent,agents:fe.agents,agentDraft:fe.agentDraft,setAgentDraft:fe.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,f]=l.useState(""),[b,h]=l.useState("user"),[v,x]=l.useState(""),[g,w]=l.useState("subagent"),[y,S]=l.useState(""),[D,j]=l.useState(void 0),[I,A]=l.useState(void 0),[E,P]=l.useState(""),[k,N]=l.useState("allow"),[T,M]=l.useState([]),[R,L]=l.useState([]),[O,V]=l.useState(""),[$,B]=l.useState("*"),[H,_]=l.useState(!1),[se,oe]=l.useState(!1),ae=l.useRef(null),ne=Ws(fe=>fe.currentDirectory??null),[xe,te]=l.useState([]),F=Lh(fe=>fe.permission);l.useEffect(()=>{let fe=!1;return(async()=>{const Ve=await In.listToolIds({directory:ne});if(fe)return;const G=new Set(["write","patch","multiedit"]),Ie=Ve.map(Oe=>typeof Oe=="string"?Oe.trim():"").filter(Boolean).filter(Oe=>Oe!=="*").filter(Oe=>Oe!=="invalid").filter(Oe=>!G.has(Oe));te(Array.from(new Set(Ie)).sort((Oe,De)=>Oe.localeCompare(De)))})(),()=>{fe=!0}},[ne]);const z=l.useMemo(()=>{const fe=new Set;for(const Te of o){const Ve=Ma(Array.isArray(Te.permission)?Te.permission:[]);for(const G of Ve)G.permission&&G.permission!=="*"&&G.permission!=="invalid"&&fe.add(G.permission)}for(const Te of Object.values(F))for(const Ve of Te){const G=Ve.permission?.trim();G&&G!=="invalid"&&fe.add(G)}for(const Te of xe)fe.add(Te);return Array.from(fe).sort((Te,Ve)=>Te.localeCompare(Ve))},[o,F,xe]),Q=l.useMemo(()=>ko(T),[T]),re=l.useMemo(()=>ko(R),[R]),K=l.useCallback(fe=>re.get(ba(fe,"*"))?.action,[re]),le=l.useCallback(fe=>R.filter(Te=>Te.permission===fe&&Te.pattern!=="*").sort((Te,Ve)=>Te.pattern.localeCompare(Ve.pattern)),[R]),Se=l.useMemo(()=>{const fe=new Set;for(const Te of Om)fe.add(Te);for(const Te of z)fe.add(Te);return Array.from(fe).sort((Te,Ve)=>Te.localeCompare(Ve))},[z]),ue=l.useCallback(fe=>{const Te=fe==="*"?k:K(fe)??k,Ve=le(fe),G=!1,Ie=Ve.reduce((De,ge)=>(De[ge.action]=(De[ge.action]??0)+1,De),{allow:0,ask:0,deny:0}),Oe=["allow","ask","deny"].filter(De=>Ie[De]>0).map(De=>`${Ie[De]} ${De}`).join(", ");return{defaultAction:Te,patternRulesCount:Ve.length,patternSummary:Oe,hasDefaultHint:G}},[le,K,k]),je=l.useCallback(fe=>t(fe==="allow"?"settings.common.permission.allow":fe==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),W=l.useCallback(fe=>fe==="global"?t("settings.common.scope.global"):je(fe),[je,t]),me=l.useMemo(()=>{const fe=new Set;for(const Te of Om)fe.add(Te);for(const Te of z)fe.add(Te);return Array.from(fe).sort((Te,Ve)=>Te.localeCompare(Ve))},[z]),X=l.useCallback((fe,Te,Ve)=>{L(G=>{const Ie=ko(G);return Ie.set(ba(fe,Te),{permission:fe,pattern:Te,action:Ve}),Array.from(Ie.values())})},[]),ce=l.useCallback((fe,Te)=>{L(Ve=>{const G=ko(Ve);return G.delete(ba(fe,Te)),Array.from(G.values())})},[]),ee=l.useCallback((fe,Te)=>{const Ve=Q.get(ba(fe,Te));if(Ve){X(fe,Te,Ve.action);return}ce(fe,Te)},[Q,ce,X]),Pe=l.useCallback((fe,Te,Ve)=>{X(fe,Te,Ve)},[X]),Ne=l.useCallback(fe=>{N(fe),L(Te=>Te.filter(Ve=>!(Ve.pattern==="*"&&Ve.action===fe)))},[]),Y=l.useCallback(fe=>{const Te=O.trim();if(!Te){q.error(t("settings.agents.page.toast.permissionNameRequired"));return}const Ve=$.trim()||"*";if(Te==="*"&&Ve==="*"){Ne(fe),V(""),B("*");return}Ve==="*"&&Te!=="*"&&fe===k?ce(Te,"*"):X(Te,Ve,fe),V(""),B("*")},[k,O,$,ce,Ne,t,X]),he=l.useCallback(fe=>fe==="*"?t("settings.agents.page.permissions.defaultLabel"):fe==="webfetch"?"WebFetch":fe==="websearch"?"WebSearch":fe==="codesearch"?"CodeSearch":fe==="doom_loop"?"Doom Loop":fe==="external_directory"?"External Directory":fe==="todowrite"?"TodoWrite":fe==="todoread"?"TodoRead":fe.split(/[_-]+/g).filter(Boolean).map(Te=>Te.charAt(0).toUpperCase()+Te.slice(1)).join(" "),[t]);l.useEffect(()=>{V(""),B("*");const fe=Te=>{const Ve=Ma(Te),G=gS(Ve),Ie=xS(Ve,G);return N(G),M(Ie),L(Ie),{global:G,rules:Ie}};if(m&&c){const Te=c.name||"",Ve=c.scope||"user",G=c.description||"",Ie=c.mode||"subagent",Oe=c.model||"",De=c.temperature,ge=c.top_p,U=c.prompt||"";f(Te),h(Ve),x(G),w(Ie),S(Oe),j(De),A(ge),P(U);const de=bS(c.permission),Ee=fe(de);ae.current={draftName:Te,draftScope:Ve,description:G,mode:Ie,model:Oe,temperature:De,topP:ge,prompt:U,globalPermission:Ee.global,permissionRules:Ee.rules};return}if(p&&n===p.name){const Te=p.description||"",Ve=p.mode||"subagent",G=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",Ie=p.temperature,Oe=p.topP,De=p.prompt||"";x(Te),w(Ve),S(G),j(Ie),A(Oe),P(De);const ge=fe(Array.isArray(p.permission)?p.permission:[]);ae.current={draftName:"",draftScope:"user",description:Te,mode:Ve,model:G,temperature:Ie,topP:Oe,prompt:De,globalPermission:ge.global,permissionRules:ge.rules}}},[c,m,p,n]);const ke=l.useMemo(()=>{const fe=ae.current;return fe?!!(m&&(u!==fe.draftName||b!==fe.draftScope)||v!==fe.description||g!==fe.mode||y!==fe.model||D!==fe.temperature||I!==fe.topP||E!==fe.prompt||k!==fe.globalPermission||!fS(R,fe.permissionRules)):!1},[v,u,b,k,m,g,y,R,E,D,I]),be=async()=>{const fe=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!fe){q.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(Te=>Te.name===fe)){q.error(t("settings.agents.sidebar.toast.agentExists"));return}oe(!0);try{const Te=y.trim(),Ve=yS(k,R),G={name:fe,description:v.trim()||void 0,mode:g,model:Te===""?null:Te,temperature:D,top_p:I,prompt:E.trim()||void 0,permission:Ve,scope:m?b:void 0};let Ie;m?(Ie=await i(G),Ie&&d(null)):Ie=await a(fe,G),Ie?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(Te){console.error("Error saving agent:",Te);const Ve=Te instanceof Error&&Te.message?Te.message:t("settings.agents.page.toast.saveUnexpectedError");q.error(Ve)}finally{oe(!1)}};return n?s.jsx(As,{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(Ut,{value:u,onChange:fe=>f(fe.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ps,{value:b,onValueChange:fe=>h(fe),children:[s.jsx(hs,{className:"w-fit min-w-[100px]",children:s.jsx(ys,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(fs,{align:"end",children:[s.jsx(Ft,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ft,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(vn,{value:v,onChange:fe=>x(fe.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.mode")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.modeTooltip")})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":g==="primary",onClick:()=>w("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":g==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":g==="all",onClick:()=>w("all"),className:"!font-normal",children:t("settings.agents.page.mode.all")})]})]})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.modelParameters")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(ao,{providerId:mi(y)?.providerId??"",modelId:mi(y)?.modelId??"",onChange:(fe,Te)=>{S(fe&&Te?`${fe}/${Te}`:"")}})})]}),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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.temperatureTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.temperatureRange")})]}),s.jsxs("div",{className:pe("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(yn,{value:D,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),D!==void 0&&s.jsx(ve,{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(C,{name:"close",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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.topPTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.topPRange")})]}),s.jsxs("div",{className:pe("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(yn,{value:I,fallbackValue:.9,onValueChange:A,onClear:()=>A(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),I!==void 0&&s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>A(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.systemPrompt")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(vn,{value:E,onChange:fe=>P(fe.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.toolPermissions")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>_(fe=>!fe),children:t(H?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),H?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:k,onValueChange:fe=>Ne(fe),children:[s.jsx(hs,{className:"w-[100px]",children:s.jsx(ys,{children:je(k)})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Ft,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Ft,{value:"deny",children:t("settings.common.permission.deny")})]})]})]}),s.jsx("div",{className:"space-y-4",children:Se.filter(fe=>fe!=="*").map(fe=>{const Te=he(fe),{defaultAction:Ve,patternRulesCount:G}=ue(fe),Ie=K(fe),Oe=Ie??"global",De=le(fe),ge=["allow","ask","deny"].filter(U=>U!==k);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:Te}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:fe})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:G>0?t("settings.agents.page.permissions.globalSummary",{summary:Ve}):Ve})]}),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:"*"}),Ie&&s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>ee(fe,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(C,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ps,{value:Oe,onValueChange:U=>{if(U==="global"){ce(fe,"*");return}X(fe,"*",U)},children:[s.jsx(hs,{className:"w-[90px]",children:s.jsx(ys,{children:W(Oe)})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"global",children:t("settings.common.scope.global")}),ge.map(U=>s.jsx(Ft,{value:U,className:"capitalize",children:je(U)},U))]})]})]}),De.map(U=>{const de=ba(U.permission,U.pattern),Ee=Q.get(de),_e=!Ee,Z=!!(Ee&&Ee.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}),_e&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),Z&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(_e||Z)&&s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>_e?ce(U.permission,U.pattern):ee(U.permission,U.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(C,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ps,{value:U.action,onValueChange:ie=>Pe(U.permission,U.pattern,ie),children:[s.jsx(hs,{className:"w-[90px]",children:s.jsx(ys,{children:je(U.action)})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Ft,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Ft,{value:"deny",children:t("settings.common.permission.deny")})]})]})]},de)})]})]},fe)})}),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:O,onValueChange:V,children:[s.jsx(hs,{className:"w-full sm:w-[160px]",children:O?s.jsx("span",{className:"truncate",children:he(O)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(fs,{children:me.map(fe=>s.jsx(Ft,{value:fe,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:he(fe)})})},fe))})]}),s.jsx(Ut,{value:$,onChange:fe=>B(fe.target.value),placeholder:t("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),s.jsxs("div",{className:"flex gap-1",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Y("allow"),children:t("settings.common.permission.allow")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Y("ask"),children:t("settings.common.permission.ask")}),s.jsx(ve,{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:Se.map((fe,Te)=>{const{defaultAction:Ve,patternRulesCount:G,patternSummary:Ie,hasDefaultHint:Oe}=ue(fe),De=he(fe),ge=Oe?`${Ve} (env blocked)`:Ve;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",Te>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:De}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:fe})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[G>0?s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.globalSummary",{summary:ge})}):s.jsx("span",{className:pe("typography-micro capitalize px-1.5 py-0.5 rounded",ge==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":ge==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:ge}),G>0&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.rulesSummary",{summary:Ie})})]})]},fe)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ve,{onClick:be,disabled:se||!ke,size:"xs",className:"!font-normal",children:t(se?"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(C,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},wS="~/.config/opencode/AGENTS.md",Kf=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},jS=t=>t.length>0&&!t.endsWith(`
|
|
155
|
-
`)?`${t}
|
|
156
|
-
`:t,Co={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},NS=(t,e)=>t==="custom"?e:ub(t),SS=t=>t==="custom"?"custom":Oh(t)?t:"concise",Bm={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"},_m=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 Kf(n,e))},kS=()=>{const{t}=mt(),[e,n]=l.useState(""),[r,i]=l.useState(Co.responseStyleEnabled),[a,o]=l.useState(Co.responseStylePreset),[c,d]=l.useState(Co.responseStyleCustomInstructions),[p,m]=l.useState(!0),[u,f]=l.useState(!1),[b,h]=l.useState(""),v=l.useRef(null);l.useEffect(()=>{const y=new AbortController;return(async()=>{try{const[D,j]=await Promise.all([fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:y.signal}),fetch("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:y.signal})]);let I=Co;if(D.ok){const A=await D.json();I={...I,responseStyleEnabled:A.responseStyleEnabled===!0,responseStylePreset:SS(A.responseStylePreset),responseStyleCustomInstructions:typeof A.responseStyleCustomInstructions=="string"?A.responseStyleCustomInstructions:""},typeof A.globalBehaviorPrompt=="string"&&(I={...I,prompt:A.globalBehaviorPrompt})}if(!I.prompt.trim()&&j.ok){const A=await j.json();typeof A.content=="string"&&(I={...I,prompt:A.content})}n(I.prompt),i(I.responseStyleEnabled),o(I.responseStylePreset),d(I.responseStyleCustomInstructions),h(I.prompt),v.current={enabled:I.responseStyleEnabled,preset:I.responseStylePreset,custom:I.responseStyleCustomInstructions}}catch(D){D.name!=="AbortError"&&console.warn("Failed to load behavior settings:",D)}finally{m(!1)}})(),()=>y.abort()},[]),l.useEffect(()=>{if(p)return;const y=v.current;if(y&&y.enabled===r&&y.preset===a&&y.custom===c)return;const S={enabled:r,preset:a,custom:c},D=setTimeout(async()=>{try{await _m({responseStyleEnabled:S.enabled,responseStylePreset:S.preset,responseStyleCustomInstructions:S.custom},t("settings.behavior.page.toast.saveFailed")),v.current=S}catch(j){const I=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");q.error(I)}},400);return()=>clearTimeout(D)},[r,a,c,p,t]);const x=NS(a,c),g=e!==b,w=async()=>{f(!0);try{const y=jS(e),S=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:y})});if(!S.ok)throw new Error(await Kf(S,t("settings.behavior.page.toast.saveFailed")));await _m({globalBehaviorPrompt:y},t("settings.behavior.page.toast.saveFailed")),n(y),h(y),q.success(t("settings.behavior.page.toast.saved"))}catch(y){console.error("Failed to save behavior:",y);const S=y instanceof Error?y.message:t("settings.behavior.page.toast.saveFailed");q.error(S)}finally{f(!1)}};return s.jsx(As,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8 space-y-6",children:[s.jsx("div",{className:"space-y-1",children:s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.behavior.page.title")})}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.systemPrompt")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:wS})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(vn,{value:e,onChange:y=>n(y.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(ve,{onClick:w,disabled:u||!g||p,size:"xs",className:"!font-normal",children:t(u?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.responseStyle")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.behavior.page.responseStyle.tooltip")})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[s.jsx(bs,{checked:r,onChange:i,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(ps,{value:a,onValueChange:y=>o(y),disabled:p||!r,children:[s.jsx(hs,{className:"w-full sm:w-56",size:"lg",children:s.jsx(ys,{children:y=>y==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Oh(y)?t(Bm[y]):null})}),s.jsxs(fs,{children:[db.map(y=>s.jsx(Ft,{value:y,children:t(Bm[y])},y)),s.jsx(Ft,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(vn,{value:x,onChange:y=>d(y.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!r||a!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},CS=t=>{const e=rt.c(169),{onItemSelect:n}=t,{t:r}=mt(),[i,a]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(!1),[h,v]=l.useState(null),{selectedCommandName:x,commands:g,setSelectedCommand:w,setCommandDraft:y,createCommand:S,deleteCommand:D,loadCommands:j}=Id(mr(IS)),I=ea(PS),A=ea(AS);let E,P;e[0]!==j||e[1]!==A?(E=()=>{j(),A()},P=[j,A],e[0]=j,e[1]=A,e[2]=E,e[3]=P):(E=e[2],P=e[3]),l.useEffect(E,P);let k;e[4]!==I?(k=new Set(I.map(DS)),e[4]=I,e[5]=k):k=e[5];const N=k;let T;if(e[6]!==g||e[7]!==N){let Be;e[9]!==N?(Be=ze=>!N.has(ze.name),e[9]=N,e[10]=Be):Be=e[10],T=g.filter(Be),e[6]=g,e[7]=N,e[8]=T}else T=e[8];const M=T;let R,L;e[11]!==x||e[12]!==w||e[13]!==N?(R=()=>{x&&N.has(x)&&w(null)},L=[x,w,N],e[11]=x,e[12]=w,e[13]=N,e[14]=R,e[15]=L):(R=e[14],L=e[15]),l.useEffect(R,L);let O;e[16]!==g||e[17]!==n||e[18]!==y||e[19]!==w?(O=()=>{let Be="new-command",ze=1;for(;g.some(nt=>nt.name===Be);)Be=`new-command-${ze}`,ze++;y({name:Be,scope:"user"}),w(Be),n?.()},e[16]=g,e[17]=n,e[18]=y,e[19]=w,e[20]=O):O=e[20];const V=O;let $;e[21]!==r?($=async Be=>{if(si(Be)){q.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p(Be),u("delete")},e[21]=r,e[22]=$):$=e[22];const B=$;let H;e[23]===Symbol.for("react.memo_cache_sentinel")?(H=async Be=>{si(Be)&&(p(Be),u("reset"))},e[23]=H):H=e[23];const _=H;let se;e[24]===Symbol.for("react.memo_cache_sentinel")?(se=()=>{p(null),u(null)},e[24]=se):se=e[24];const oe=se;let ae;e[25]!==d||e[26]!==m||e[27]!==D||e[28]!==r?(ae=async()=>{if(!d||!m)return;b(!0),await D(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})),oe()):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]=D,e[28]=r,e[29]=ae):ae=e[29];const ne=ae;let xe;e[30]!==g||e[31]!==y||e[32]!==w?(xe=Be=>{const ze=Be.name;let nt=1,Ye=`${ze}-copy`;for(;g.some(Ue=>Ue.name===Ye);)nt++,Ye=`${ze}-copy-${nt}`;y({name:Ye,scope:Be.scope||"user",description:Be.description,template:Be.template,agent:Be.agent,model:Be.model}),w(Ye)},e[30]=g,e[31]=y,e[32]=w,e[33]=xe):xe=e[33];const te=xe;let F;e[34]===Symbol.for("react.memo_cache_sentinel")?(F=Be=>{c(Be.name),a(Be)},e[34]=F):F=e[34];const z=F;let Q;e[35]!==g||e[36]!==S||e[37]!==D||e[38]!==i||e[39]!==o||e[40]!==w||e[41]!==r?(Q=async()=>{if(!i)return;const Be=o.trim().replace(/\s+/g,"-");if(!Be){q.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if(Be===i.name){a(null);return}if(g.some(nt=>nt.name===Be)){q.error(r("settings.commands.sidebar.toast.commandExists"));return}await S({name:Be,description:i.description,template:i.template,agent:i.agent,model:i.model})?await D(i.name)?(q.success(`Command renamed to "${Be}"`),w(Be)):q.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):q.error(r("settings.commands.sidebar.toast.renameFailed")),a(null)},e[35]=g,e[36]=S,e[37]=D,e[38]=i,e[39]=o,e[40]=w,e[41]=r,e[42]=Q):Q=e[42];const re=Q;let K,le,Se,ue,je,W;if(e[43]!==M||e[44]!==V||e[45]!==B||e[46]!==te||e[47]!==n||e[48]!==h||e[49]!==x||e[50]!==w||e[51]!==r){const Be=M.filter(si),ze=M.filter(TS);e[58]===Symbol.for("react.memo_cache_sentinel")?(je=pe("flex h-full flex-col","bg-background"),e[58]=je):je=e[58];let nt;e[59]!==r?(nt=r("settings.commands.sidebar.title"),e[59]=r,e[60]=nt):nt=e[60];let Ye;e[61]!==nt?(Ye=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:nt}),e[61]=nt,e[62]=Ye):Ye=e[62];let Ue;e[63]===Symbol.for("react.memo_cache_sentinel")?(Ue=s.jsx(io,{className:"mb-3"}),e[63]=Ue):Ue=e[63];let vt;e[64]!==M.length||e[65]!==r?(vt=r("settings.commands.sidebar.total",{count:M.length}),e[64]=M.length,e[65]=r,e[66]=vt):vt=e[66];let Et;e[67]!==vt?(Et=s.jsx("span",{className:"typography-meta text-muted-foreground",children:vt}),e[67]=vt,e[68]=Et):Et=e[68];let Gt;e[69]===Symbol.for("react.memo_cache_sentinel")?(Gt=s.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),e[69]=Gt):Gt=e[69];let ts;e[70]!==V?(ts=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:V,children:Gt}),e[70]=V,e[71]=ts):ts=e[71];let Nt;e[72]!==Et||e[73]!==ts?(Nt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Et,ts]}),e[72]=Et,e[73]=ts,e[74]=Nt):Nt=e[74],e[75]!==Ye||e[76]!==Nt?(W=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Ye,Ue,Nt]}),e[75]=Ye,e[76]=Nt,e[77]=W):W=e[77],K=As,le="flex-1 min-h-0",Se="space-y-1 px-3 py-2",ue=M.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(C,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[Be.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")}),[...Be].sort(MS).map(St=>s.jsx(Vm,{command:St,isSelected:x===St.name,onSelect:()=>{w(St.name),n?.()},onReset:()=>_(St),onDuplicate:()=>te(St),isMenuOpen:h===St.name,onMenuOpenChange:Zt=>v(Zt?St.name:null)},St.name))]}),ze.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")}),[...ze].sort(ES).map(St=>s.jsx(Vm,{command:St,isSelected:x===St.name,onSelect:()=>{w(St.name),n?.()},onRename:()=>z(St),onDelete:()=>B(St),onDuplicate:()=>te(St),isMenuOpen:h===St.name,onMenuOpenChange:Zt=>v(Zt?St.name:null)},St.name))]})]}),e[43]=M,e[44]=V,e[45]=B,e[46]=te,e[47]=n,e[48]=h,e[49]=x,e[50]=w,e[51]=r,e[52]=K,e[53]=le,e[54]=Se,e[55]=ue,e[56]=je,e[57]=W}else K=e[52],le=e[53],Se=e[54],ue=e[55],je=e[56],W=e[57];let me;e[78]!==K||e[79]!==le||e[80]!==Se||e[81]!==ue?(me=s.jsx(K,{outerClassName:le,className:Se,children:ue}),e[78]=K,e[79]=le,e[80]=Se,e[81]=ue,e[82]=me):me=e[82];const X=d!==null&&m!==null;let ce;e[83]!==f?(ce=Be=>{!Be&&!f&&oe()},e[83]=f,e[84]=ce):ce=e[84];let ee;e[85]!==m||e[86]!==r?(ee=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=ee):ee=e[87];let Pe;e[88]!==ee?(Pe=s.jsx(js,{children:ee}),e[88]=ee,e[89]=Pe):Pe=e[89];let Ne;e[90]!==d?.name||e[91]!==m||e[92]!==r?(Ne=m==="delete"?r("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):r("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[90]=d?.name,e[91]=m,e[92]=r,e[93]=Ne):Ne=e[93];let Y;e[94]!==Ne?(Y=s.jsx(Rs,{children:Ne}),e[94]=Ne,e[95]=Y):Y=e[95];let he;e[96]!==Pe||e[97]!==Y?(he=s.jsxs(Ss,{children:[Pe,Y]}),e[96]=Pe,e[97]=Y,e[98]=he):he=e[98];let ke;e[99]!==r?(ke=r("settings.common.actions.cancel"),e[99]=r,e[100]=ke):ke=e[100];let be;e[101]!==f||e[102]!==ke?(be=s.jsx(ve,{size:"sm",variant:"ghost",onClick:oe,disabled:f,children:ke}),e[101]=f,e[102]=ke,e[103]=be):be=e[103];let fe;e[104]!==m||e[105]!==r?(fe=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=fe):fe=e[106];let Te;e[107]!==ne||e[108]!==f||e[109]!==fe?(Te=s.jsx(ve,{size:"sm",onClick:ne,disabled:f,children:fe}),e[107]=ne,e[108]=f,e[109]=fe,e[110]=Te):Te=e[110];let Ve;e[111]!==be||e[112]!==Te?(Ve=s.jsxs(Gs,{children:[be,Te]}),e[111]=be,e[112]=Te,e[113]=Ve):Ve=e[113];let G;e[114]!==he||e[115]!==Ve?(G=s.jsxs(vs,{className:"max-w-md",children:[he,Ve]}),e[114]=he,e[115]=Ve,e[116]=G):G=e[116];let Ie;e[117]!==X||e[118]!==ce||e[119]!==G?(Ie=s.jsx(ws,{open:X,onOpenChange:ce,children:G}),e[117]=X,e[118]=ce,e[119]=G,e[120]=Ie):Ie=e[120];const Oe=i!==null;let De;e[121]===Symbol.for("react.memo_cache_sentinel")?(De=Be=>!Be&&a(null),e[121]=De):De=e[121];let ge;e[122]!==r?(ge=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=ge):ge=e[123];let U;e[124]!==ge?(U=s.jsx(js,{children:ge}),e[124]=ge,e[125]=U):U=e[125];const de=i?.name??"";let Ee;e[126]!==r||e[127]!==de?(Ee=r("settings.commands.sidebar.renameDialog.description",{name:de}),e[126]=r,e[127]=de,e[128]=Ee):Ee=e[128];let _e;e[129]!==Ee?(_e=s.jsx(Rs,{children:Ee}),e[129]=Ee,e[130]=_e):_e=e[130];let Z;e[131]!==U||e[132]!==_e?(Z=s.jsxs(Ss,{children:[U,_e]}),e[131]=U,e[132]=_e,e[133]=Z):Z=e[133];let ie;e[134]===Symbol.for("react.memo_cache_sentinel")?(ie=Be=>c(Be.target.value),e[134]=ie):ie=e[134];let Ce;e[135]!==r?(Ce=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=Ce):Ce=e[136];let He;e[137]!==re?(He=Be=>{Be.key==="Enter"&&re()},e[137]=re,e[138]=He):He=e[138];let Ge;e[139]!==o||e[140]!==Ce||e[141]!==He?(Ge=s.jsx(Ut,{value:o,onChange:ie,placeholder:Ce,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:He}),e[139]=o,e[140]=Ce,e[141]=He,e[142]=Ge):Ge=e[142];let Xe;e[143]===Symbol.for("react.memo_cache_sentinel")?(Xe=()=>a(null),e[143]=Xe):Xe=e[143];let we;e[144]!==r?(we=r("settings.common.actions.cancel"),e[144]=r,e[145]=we):we=e[145];let tt;e[146]!==we?(tt=s.jsx(ve,{size:"sm",variant:"ghost",onClick:Xe,children:we}),e[146]=we,e[147]=tt):tt=e[147];let st;e[148]!==r?(st=r("settings.common.actions.rename"),e[148]=r,e[149]=st):st=e[149];let qe;e[150]!==re||e[151]!==st?(qe=s.jsx(ve,{size:"sm",onClick:re,children:st}),e[150]=re,e[151]=st,e[152]=qe):qe=e[152];let it;e[153]!==tt||e[154]!==qe?(it=s.jsxs(Gs,{children:[tt,qe]}),e[153]=tt,e[154]=qe,e[155]=it):it=e[155];let lt;e[156]!==Z||e[157]!==Ge||e[158]!==it?(lt=s.jsxs(vs,{children:[Z,Ge,it]}),e[156]=Z,e[157]=Ge,e[158]=it,e[159]=lt):lt=e[159];let ye;e[160]!==Oe||e[161]!==lt?(ye=s.jsx(ws,{open:Oe,onOpenChange:De,children:lt}),e[160]=Oe,e[161]=lt,e[162]=ye):ye=e[162];let Je;return e[163]!==je||e[164]!==W||e[165]!==me||e[166]!==Ie||e[167]!==ye?(Je=s.jsxs("div",{className:je,children:[W,me,Ie,ye]}),e[163]=je,e[164]=W,e[165]=me,e[166]=Ie,e[167]=ye,e[168]=Je):Je=e[168],Je},Vm=t=>{const e=rt.c(53),{command:n,isSelected:r,onSelect:i,onDelete:a,onReset:o,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=mt();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Wi(),e[0]=f):f=e[0];const b=f,h=r?"bg-interactive-selection":"hover:bg-interactive-hover";let v;e[1]!==h?(v=pe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",h),e[1]=h,e[2]=v):v=e[2];let x;e[3]!==m?(x=b?void 0: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||si(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:si(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=w):w=e[9];let y;e[10]!==g||e[11]!==w?(y=s.jsxs("div",{className:"flex items-center gap-2",children:[g,w]}),e[10]=g,e[11]=w,e[12]=y):y=e[12];let 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 D;e[15]!==i||e[16]!==y||e[17]!==S?(D=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:[y,S]}),e[15]=i,e[16]=y,e[17]=S,e[18]=D):D=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Os,{asChild:!0,children:s.jsx(ve,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(C,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[19]=j):j=e[19];let I;e[20]!==c||e[21]!==u?(I=c&&s.jsxs(zt,{onClick:V=>{V.stopPropagation(),c()},children:[s.jsx(C,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=I):I=e[22];let A;e[23]!==d?(A=V=>{V.stopPropagation(),d()},e[23]=d,e[24]=A):A=e[24];let E;e[25]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(C,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[25]=E):E=e[25];let P;e[26]!==u?(P=u("settings.common.actions.duplicate"),e[26]=u,e[27]=P):P=e[27];let k;e[28]!==A||e[29]!==P?(k=s.jsxs(zt,{onClick:A,children:[E,P]}),e[28]=A,e[29]=P,e[30]=k):k=e[30];let N;e[31]!==o||e[32]!==u?(N=o&&s.jsxs(zt,{onClick:V=>{V.stopPropagation(),o()},children:[s.jsx(C,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=o,e[32]=u,e[33]=N):N=e[33];let T;e[34]!==a||e[35]!==u?(T=a&&s.jsxs(zt,{onClick:V=>{V.stopPropagation(),a()},className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=a,e[35]=u,e[36]=T):T=e[36];let M;e[37]!==I||e[38]!==k||e[39]!==N||e[40]!==T?(M=s.jsxs($s,{align:"end",className:"w-fit min-w-20",children:[I,k,N,T]}),e[37]=I,e[38]=k,e[39]=N,e[40]=T,e[41]=M):M=e[41];let R;e[42]!==p||e[43]!==m||e[44]!==M?(R=s.jsxs(Bs,{open:p,onOpenChange:m,children:[j,M]}),e[42]=p,e[43]=m,e[44]=M,e[45]=R):R=e[45];let L;e[46]!==R||e[47]!==D?(L=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[D,R]}),e[46]=R,e[47]=D,e[48]=L):L=e[48];let O;return e[49]!==L||e[50]!==v||e[51]!==x?(O=s.jsx("div",{className:v,onContextMenu:x,children:L}),e[49]=L,e[50]=v,e[51]=x,e[52]=O):O=e[52],O};function IS(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function PS(t){return t.skills}function AS(t){return t.loadSkills}function DS(t){return t.name}function TS(t){return!si(t)}function MS(t,e){return t.name.localeCompare(e.name)}function ES(t,e){return t.name.localeCompare(e.name)}const RS=()=>{const{t}=mt(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:i,commands:a,commandDraft:o,setCommandDraft:c}=Id(mr(k=>({selectedCommandName:k.selectedCommandName,getCommandByName:k.getCommandByName,createCommand:k.createCommand,updateCommand:k.updateCommand,commands:k.commands,commandDraft:k.commandDraft,setCommandDraft:k.setCommandDraft}))),d=e?n(e):null,p=!!(o&&o.name===e&&!d),[m,u]=l.useState(""),[f,b]=l.useState("user"),[h,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState(""),[S,D]=l.useState(""),[j,I]=l.useState(!1),A=l.useRef(null);l.useEffect(()=>{if(p&&o){const k=o.name||"",N=o.scope||"user",T=o.description||"",M=o.agent||"",R=o.model||"",L=o.template||"";u(k),b(N),v(T),g(M),y(R),D(L),A.current={draftName:k,draftScope:N,description:T,agent:M,model:R,template:L}}else if(d){const k=d.description||"",N=d.agent||"",T=d.model||"",M=d.template||"";v(k),g(N),y(T),D(M),A.current={draftName:"",draftScope:"user",description:k,agent:N,model:T,template:M}}},[d,p,e,a,o]);const E=l.useMemo(()=>{const k=A.current;return k?!!(p&&(m!==k.draftName||f!==k.draftScope)||h!==k.description||x!==k.agent||w!==k.model||S!==k.template):!1},[x,h,m,f,p,w,S]),P=async()=>{const k=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!k){q.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!S.trim()){q.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&a.some(N=>N.name===k)){q.error(t("settings.commands.sidebar.toast.commandExists"));return}I(!0);try{const N=x.trim(),T=w.trim(),M=S.trim(),R={name:k,description:h.trim()||void 0,agent:N===""?null:N,model:T===""?null:T,template:M,scope:p?f:void 0};let L;p?(L=await r(R),L&&c(null)):L=await i(k,R),L?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{I(!1)}};return e?s.jsx(As,{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(Ut,{value:m,onChange:k=>u(k.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ps,{value:f,onValueChange:k=>b(k),children:[s.jsx(hs,{className:"w-fit min-w-[100px]",children:s.jsx(ys,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(fs,{align:"end",children:[s.jsx(Ft,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ft,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(vn,{value:h,onChange:k=>v(k.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(Il,{agentName:x,onChange:k=>g(k)})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(ao,{providerId:mi(w)?.providerId??"",modelId:mi(w)?.modelId??"",onChange:(k,N)=>{y(k&&N?`${k}/${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(vn,{value:S,onChange:k=>D(k.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ve,{onClick:P,disabled:j||!E,size:"xs",className:"!font-normal",children:t(j?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(C,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},zm=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Um=t=>{const e=rt.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 i;e[1]!==n?(i=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]=i):i=e[2];let a;return e[3]!==i?(a=s.jsx("span",{className:i}),e[3]=i,e[4]=a):a=e[4],a},FS=t=>{const e=rt.c(116),{onItemSelect:n}=t,{t:r}=mt(),{mcpServers:i,selectedMcpName:a,setSelectedMcp:o,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=Ji(mr(LS)),m=Ws(OS);let u;e[0]!==m?(u=ge=>ge.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const f=Cn(u),b=Cn($S),h=Cn(BS),[v,x]=l.useState(null),[g,w]=l.useState(!1),[y,S]=l.useState(null),[D,j]=l.useState(!1);let I;e[2]!==i?(I=i.filter(_S),e[2]=i,e[3]=I):I=e[3];const A=I;let E;e[4]!==i?(E=i.filter(VS),e[4]=i,e[5]=E):E=e[5];const P=E;let k,N;e[6]!==d?(k=()=>{d()},N=[d],e[6]=d,e[7]=k,e[8]=N):(k=e[7],N=e[8]),l.useEffect(k,N);let T;e[9]!==m||e[10]!==h||e[11]!==D||e[12]!==b?(T=()=>{if(D)return;j(!0);const ge=new Promise(zS);Promise.all([b({directory:m,silent:!0}),ge]).then(()=>{const U=h(m);U&&q.error(U)}).finally(()=>{j(!1)})},e[9]=m,e[10]=h,e[11]=D,e[12]=b,e[13]=T):T=e[13];const M=T;let R;e[14]!==i||e[15]!==n||e[16]!==c||e[17]!==o?(R=()=>{let ge="new-mcp-server",U=1;for(;i.some(Ee=>Ee.name===ge);)ge=`new-mcp-server-${U}`,U++;c({name:ge,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(ge),n?.()},e[14]=i,e[15]=n,e[16]=c,e[17]=o,e[18]=R):R=e[18];const L=R;let O;e[19]!==p||e[20]!==v||e[21]!==r?(O=async()=>{if(!v)return;w(!0);const ge=await p(v.name);ge.ok?ge.reloadFailed?q.warning(ge.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:ge.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):q.success(ge.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:v.name})):q.error(r("settings.mcp.sidebar.toast.deleteFailed")),x(null),w(!1)},e[19]=p,e[20]=v,e[21]=r,e[22]=O):O=e[22];const V=O;let $;e[23]===Symbol.for("react.memo_cache_sentinel")?($=pe("flex h-full flex-col","bg-background"),e[23]=$):$=e[23];let B;e[24]!==r?(B=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=B):B=e[25];let H;e[26]!==B?(H=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:B}),e[26]=B,e[27]=H):H=e[27];let _;e[28]!==r?(_=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=_):_=e[29];let se;e[30]!==r?(se=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=se):se=e[31];const oe=D&&"animate-spin";let ae;e[32]!==oe?(ae=pe("h-4 w-4",oe),e[32]=oe,e[33]=ae):ae=e[33];let ne;e[34]!==ae?(ne=s.jsx(C,{name:"refresh",className:ae}),e[34]=ae,e[35]=ne):ne=e[35];let xe;e[36]!==M||e[37]!==D||e[38]!==_||e[39]!==se||e[40]!==ne?(xe=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:D,onClick:M,"aria-label":_,title:se,children:ne}),e[36]=M,e[37]=D,e[38]=_,e[39]=se,e[40]=ne,e[41]=xe):xe=e[41];let te;e[42]!==H||e[43]!==xe?(te=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[H,xe]}),e[42]=H,e[43]=xe,e[44]=te):te=e[44];let F;e[45]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(io,{className:"mb-3"}),e[45]=F):F=e[45];let z;e[46]!==i.length||e[47]!==r?(z=r("settings.mcp.sidebar.total",{count:i.length}),e[46]=i.length,e[47]=r,e[48]=z):z=e[48];let Q;e[49]!==z?(Q=s.jsx("span",{className:"typography-meta text-muted-foreground",children:z}),e[49]=z,e[50]=Q):Q=e[50];let re;e[51]!==r?(re=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=re):re=e[52];let K;e[53]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),e[53]=K):K=e[53];let le;e[54]!==L||e[55]!==re?(le=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:L,title:re,children:K}),e[54]=L,e[55]=re,e[56]=le):le=e[56];let Se;e[57]!==Q||e[58]!==le?(Se=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Q,le]}),e[57]=Q,e[58]=le,e[59]=Se):Se=e[59];let ue;e[60]!==te||e[61]!==Se?(ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[te,F,Se]}),e[60]=te,e[61]=Se,e[62]=ue):ue=e[62];let je;e[63]!==i.length||e[64]!==f||e[65]!==n||e[66]!==y||e[67]!==A||e[68]!==a||e[69]!==c||e[70]!==o||e[71]!==r||e[72]!==P?(je=s.jsx(As,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:i.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(C,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[A.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.projectServers")}),A.map(ge=>{const U=f[ge.name],de=zm(U?.status),Ee=a===ge.name,_e=Wi();return s.jsxs("div",{className:pe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ee?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:_e?void 0:Z=>{Z.preventDefault(),S(ge.name)},children:[s.jsxs("button",{onClick:()=>{o(ge.name),c(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Um,{tone:de,enabled:ge.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ge.name}),s.jsx("span",{title:ge.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ge.type==="local"?s.jsx(C,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(C,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ge.type==="local"?ge.command?.join(" ")??"":ge.url??""})]}),s.jsxs(Bs,{open:y===ge.name,onOpenChange:Z=>S(Z?ge.name:null),children:[s.jsx(Os,{asChild:!0,children:s.jsx(ve,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(C,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx($s,{align:"end",className:"w-fit min-w-20",children:s.jsxs(zt,{onClick:Z=>{Z.stopPropagation(),x(ge)},className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ge.name)})]}),P.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.userServers")}),P.map(ge=>{const U=f[ge.name],de=zm(U?.status),Ee=a===ge.name,_e=Wi();return s.jsxs("div",{className:pe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ee?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:_e?void 0:Z=>{Z.preventDefault(),S(ge.name)},children:[s.jsxs("button",{onClick:()=>{o(ge.name),c(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Um,{tone:de,enabled:ge.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ge.name}),s.jsx("span",{title:ge.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ge.type==="local"?s.jsx(C,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(C,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ge.type==="local"?ge.command?.join(" ")??"":ge.url??""})]}),s.jsxs(Bs,{open:y===ge.name,onOpenChange:Z=>S(Z?ge.name:null),children:[s.jsx(Os,{asChild:!0,children:s.jsx(ve,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(C,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx($s,{align:"end",className:"w-fit min-w-20",children:s.jsxs(zt,{onClick:Z=>{Z.stopPropagation(),x(ge)},className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ge.name)})]})]})}),e[63]=i.length,e[64]=f,e[65]=n,e[66]=y,e[67]=A,e[68]=a,e[69]=c,e[70]=o,e[71]=r,e[72]=P,e[73]=je):je=e[73];const W=v!==null;let me;e[74]!==g?(me=ge=>{!ge&&!g&&x(null)},e[74]=g,e[75]=me):me=e[75];let X;e[76]!==r?(X=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=X):X=e[77];let ce;e[78]!==X?(ce=s.jsx(js,{children:X}),e[78]=X,e[79]=ce):ce=e[79];const ee=v?.name||"";let Pe;e[80]!==r||e[81]!==ee?(Pe=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:ee}),e[80]=r,e[81]=ee,e[82]=Pe):Pe=e[82];let Ne;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=Ne):Ne=e[83];let Y;e[84]!==Pe?(Y=s.jsxs(Rs,{children:[Pe," ",Ne,"."]}),e[84]=Pe,e[85]=Y):Y=e[85];let he;e[86]!==ce||e[87]!==Y?(he=s.jsxs(Ss,{children:[ce,Y]}),e[86]=ce,e[87]=Y,e[88]=he):he=e[88];let ke;e[89]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>x(null),e[89]=ke):ke=e[89];let be;e[90]!==r?(be=r("settings.common.actions.cancel"),e[90]=r,e[91]=be):be=e[91];let fe;e[92]!==g||e[93]!==be?(fe=s.jsx(ve,{size:"sm",variant:"ghost",onClick:ke,disabled:g,children:be}),e[92]=g,e[93]=be,e[94]=fe):fe=e[94];let Te;e[95]!==g||e[96]!==r?(Te=r(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=g,e[96]=r,e[97]=Te):Te=e[97];let Ve;e[98]!==V||e[99]!==g||e[100]!==Te?(Ve=s.jsx(ve,{size:"sm",onClick:V,disabled:g,children:Te}),e[98]=V,e[99]=g,e[100]=Te,e[101]=Ve):Ve=e[101];let G;e[102]!==fe||e[103]!==Ve?(G=s.jsxs(Gs,{children:[fe,Ve]}),e[102]=fe,e[103]=Ve,e[104]=G):G=e[104];let Ie;e[105]!==he||e[106]!==G?(Ie=s.jsxs(vs,{className:"max-w-md",children:[he,G]}),e[105]=he,e[106]=G,e[107]=Ie):Ie=e[107];let Oe;e[108]!==W||e[109]!==me||e[110]!==Ie?(Oe=s.jsx(ws,{open:W,onOpenChange:me,children:Ie}),e[108]=W,e[109]=me,e[110]=Ie,e[111]=Oe):Oe=e[111];let De;return e[112]!==ue||e[113]!==je||e[114]!==Oe?(De=s.jsxs("div",{className:$,children:[ue,je,Oe]}),e[112]=ue,e[113]=je,e[114]=Oe,e[115]=De):De=e[115],De};function LS(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function OS(t){return t.currentDirectory}function $S(t){return t.refresh}function BS(t){return t.getErrorForDirectory}function _S(t){return t.scope==="project"}function VS(t){return t.scope!=="project"}function zS(t){return setTimeout(t,500)}function na(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Ci(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function ua(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function fc(t,e,n){const r=US(n),i=typeof n.url=="string"?n.url.trim():"",a=Wm(n,"env","environment"),o=Wm(n,"headers"),c=WS(n),d=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",m=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",u=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",f=KS(n),b=HS(n);return{ok:!0,name:t,type:e,command:r,url:i,environment:a,headers:o,oauthEnabled:c,oauthClientId:d,oauthClientSecret:p,oauthScope:m,oauthRedirectUri:u,timeout:f,enabled:b}}function US(t){const e=t.command,n=t.args;if(Ci(e)&&Ci(n))return[...e,...n];if(Ci(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return Ci(n)?[...r,...n]:r}return Ci(n)?n:[]}function Wm(t,...e){for(const n of e){const r=t[n];if(!na(r))continue;const i=Object.entries(r).filter(([a,o])=>a&&typeof o=="string");if(i.length>0)return i.map(([a,o])=>({key:a,value:String(o)}))}return[]}function WS(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 KS(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 HS(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function GS(t){const e=t.mcpServers;if(na(e)){const r=Object.keys(e);if(r.length===1){const i=r[0],a=e[i];if(na(a))return{name:i,entry:a}}if(r.length>1)return null}const n=Object.keys(t).filter(r=>{const i=t[r];return r!=="mcpServers"&&na(i)});if(n.length===1){const r=n[0],i=t[r];if(Hf(i))return{name:r,entry:i}}return null}function Hf(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function qS(t,e){let n;try{const o=t.trim();if(!o)return ua("No JSON content provided");n=JSON.parse(o)}catch(o){return ua(o instanceof Error?`Invalid JSON: ${o.message}`:"Invalid JSON")}if(!na(n))return ua("Expected a JSON object, not an array or primitive");const r=n,i=r.mcpServers;if(na(i)){const o=Object.keys(i);if(o.length===0)return ua("mcpServers object is empty",n);if(o.length>1)return ua("Paste one server at a time. Found "+o.length+" servers in mcpServers",n);const c=o[0],d=i[c];return na(d)?fc(c,gc(d),d):ua("Server entry is not a valid object",n)}const a=GS(r);if(a)return fc(a.name,gc(a.entry),a.entry);if(Hf(r)){const o=gc(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return fc(c,o,r)}return ua("No recognizable MCP server configuration found in JSON",n)}function gc(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 JS(t,e,n){const r=n?.isNewServer??!1,i=t.name,a=r&&i?i:e.name??"";return{...e,name:a,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 Gf="/mcp/oauth/callback",QS=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),i=Uint8Array.from(r,a=>a.charCodeAt(0));return new TextDecoder().decode(i)}catch{return null}},qf=t=>{const e=YS(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}},$d=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},YS=t=>{if(typeof t!="string"||!t.trim())return null;const e=QS(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 XS(t){const e=[];let n="",r=!1,i=!1;for(let a=0;a<t.length;a++){const o=t[a];if(o==="'"&&!i){r=!r;continue}if(o==='"'&&!r){i=!i;continue}if((o===" "||o===" ")&&!r&&!i){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function ZS(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:qf(n.searchParams),stateKey:$d(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const ek=({value:t,onChange:e,pasteCommandTitle:n,pasteCommandLabel:r,pasteSuccess:i,clipboardReadFailed:a,preview:o})=>{const[c,d]=l.useState(()=>t.join(`
|
|
157
|
-
`)),p=l.useRef(t);l.useEffect(()=>{JSON.stringify(p.current)!==JSON.stringify(t)&&(p.current=t,d(t.join(`
|
|
158
|
-
`)))},[t]);const m=f=>{const b=f.split(`
|
|
159
|
-
`).filter(h=>h.trim().length>0);e(b)},u=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),h=b.includes(`
|
|
160
|
-
`)?b.split(`
|
|
161
|
-
`).filter(v=>v.trim()):XS(b);d(h.join(`
|
|
162
|
-
`)),e(h),q.success(i(h.length))}catch{q.error(a)}};return s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[s.jsx("div",{className:"flex items-center justify-end gap-2",children:s.jsxs(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(C,{name:"clipboard",className:"h-3 w-3"}),r]})}),s.jsx(vn,{value:c,onChange:f=>{d(f.target.value),m(f.target.value)},onBlur:()=>{const f=c.split(`
|
|
163
|
-
`).map(b=>b.trimEnd()).join(`
|
|
164
|
-
`);d(f),m(f)},placeholder:`npx
|
|
165
|
-
-y
|
|
166
|
-
@modelcontextprotocol/server-postgres
|
|
167
|
-
postgresql://user:pass@host/db`,rows:Math.max(4,t.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),t.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:o(t.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:t.map((f,b)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),f]},b))})})]})]})},tk=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Km=({value:t,onChange:e,keyTransform:n=tk,keyPlaceholder:r="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:a="Paste .env",pasteTitle:o="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:p,keyLabel:m,valueLabel:u,valuePlaceholder:f,hideValueTitle:b,showValueTitle:h,addVariable:v,plainTextWarning:x,removeVariableAria:g})=>{const[w,y]=l.useState(new Set),S=()=>e([...t,{key:"",value:""}]),D=P=>{e(t.filter((k,N)=>N!==P)),y(k=>{const N=new Set(k);return N.delete(P),N})},j=(P,k,N)=>{const T=[...t];T[P]={...T[P],[k]:N},e(T)},I=P=>{y(k=>{const N=new Set(k);return N.has(P)?N.delete(P):N.add(P),N})},A=async()=>{try{const P=await navigator.clipboard.readText(),k=[];for(const T of P.split(`
|
|
168
|
-
`)){const M=T.trim();if(!M||M.startsWith("#"))continue;const R=M.indexOf("=");if(R===-1)continue;const L=M.slice(0,R).trim();let O=M.slice(R+1).trim();(O.startsWith('"')&&O.endsWith('"')||O.startsWith("'")&&O.endsWith("'"))&&(O=O.slice(1,-1)),L&&k.push({key:L,value:O})}if(k.length===0){q.error(c);return}const N=[...t];for(const T of k){const M=N.findIndex(R=>R.key===T.key);M!==-1?N[M]=T:N.push(T)}e(N),q.success(d(k.length))}catch{q.error(p)}},E=t.some(P=>P.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:u})]}),s.jsxs(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:A,type:"button",title:o,children:[s.jsx(C,{name:"clipboard",className:"h-3 w-3"}),a]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((P,k)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ut,{value:P.key,onChange:N=>j(k,"key",n(N.target.value)),placeholder:r,className:i,"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(Ut,{type:w.has(k)?"text":"password",value:P.value,onChange:N=>j(k,"value",N.target.value),placeholder:f,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>I(k),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:w.has(k)?b:h,children:w.has(k)?s.jsx(C,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>D(k),"aria-label":g,children:s.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},k))}),s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:S,type:"button",children:[s.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),v]}),E&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},Hm=t=>{const e=rt.c(14),{status:n,enabled:r,getStatusLabel:i,variant:a}=t,o=a===void 0?"compact":a;if(!r||!n)return null;let c,d;if(e[0]!==i||e[1]!==n||e[2]!==o){d=Symbol.for("react.early_return_sentinel");e:{const f={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[n]??{text:"text-muted-foreground",bg:""};if(o==="pill"){const b=pe("typography-micro font-medium rounded-full px-2 py-0.5",f.text,f.bg);let h;e[5]!==i||e[6]!==n?(h=i(n),e[5]=i,e[6]=n,e[7]=h):h=e[7],d=s.jsxs("span",{className:b,children:["● ",h]});break e}c=pe("typography-micro font-medium",f.text)}e[0]=i,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]!==i||e[9]!==n?(p=i(n),e[8]=i,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},sk=(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")}},nk=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)]"}},rk=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),Gm=(t,e)=>{if(typeof window>"u")return null;const n=new URL(Gf,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()},ak=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")}},ik=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},Ii=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},xc=(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},ok=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},lk=()=>{const{t}=mt(),e=l.useCallback((We,Rt)=>t(We,Rt),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:i,setMcpDraft:a,setSelectedMcp:o,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=Ji(mr(We=>({selectedMcpName:We.selectedMcpName,mcpServers:We.mcpServers,mcpDraft:We.mcpDraft,setMcpDraft:We.setMcpDraft,setSelectedMcp:We.setSelectedMcp,getMcpByName:We.getMcpByName,createMcp:We.createMcp,updateMcp:We.updateMcp,deleteMcp:We.deleteMcp}))),u=Ws(We=>We.currentDirectory),f=l.useMemo(()=>pn(),[]),b=Cn(We=>We.getStatusForDirectory(u??null)),h=Cn(We=>We.getDiagnosticForDirectory(u??null)),v=Cn(We=>We.refresh),x=Cn(We=>We.connect),g=Cn(We=>We.disconnect),w=Cn(We=>We.startAuth),y=Cn(We=>We.completeAuth),S=Cn(We=>We.clearAuth),D=Cn(We=>We.testConnection),j=n?c(n):null,I=!!(i&&i.name===n&&!j),[A,E]=l.useState(""),[P,k]=l.useState("user"),[N,T]=l.useState("local"),[M,R]=l.useState([]),[L,O]=l.useState(""),[V,$]=l.useState([]),[B,H]=l.useState([]),[_,se]=l.useState(!0),[oe,ae]=l.useState(""),[ne,xe]=l.useState(""),[te,F]=l.useState(""),[z,Q]=l.useState(""),[re,K]=l.useState(""),[le,Se]=l.useState(!0),[ue,je]=l.useState(!1),[W,me]=l.useState(!1),[X,ce]=l.useState(!1),[ee,Pe]=l.useState(!1),[Ne,Y]=l.useState(!1),[he,ke]=l.useState(!1),[be,fe]=l.useState(!1),[Te,Ve]=l.useState(!1),[G,Ie]=l.useState(null),[Oe,De]=l.useState(null),[ge,U]=l.useState(""),[de,Ee]=l.useState(!1),_e=l.useRef(0),Z=l.useRef(!1),[ie,Ce]=l.useState(!1),[He,Ge]=l.useState(!1),[Xe,we]=l.useState(""),[tt,st]=l.useState(null),qe=l.useMemo(()=>ok(n,u),[u,n]),it=l.useRef(qe),lt=l.useRef(null),ye=l.useCallback(()=>{Ie(null),De(null),U(""),Ee(!1),_e.current=0,Ve(!1),Y(!1),ke(!1),Z.current=!1},[]),Je=l.useCallback(()=>{we(""),st(null),Ge(!0)},[]),Be=l.useCallback(async()=>{try{const We=await navigator.clipboard.readText();we(We),st(null)}catch{q.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),ze=l.useCallback(()=>{const We=qS(Xe,{fallbackName:A});if(!We.ok){st(We.error);return}const Dt=JS(We,{name:A,scope:P,type:N,command:M,url:L,environment:V,headers:B,oauthEnabled:_,oauthClientId:oe,oauthClientSecret:ne,oauthScope:te,oauthRedirectUri:z,timeout:re,enabled:le},{isNewServer:I});E(Dt.name),T(Dt.type),R(Dt.command??[]),O(Dt.url??""),$(Dt.environment??[]),H(Dt.headers??[]),se(Dt.oauthEnabled??!1),ae(Dt.oauthClientId??""),xe(Dt.oauthClientSecret??""),F(Dt.oauthScope??""),Q(Dt.oauthRedirectUri??""),K(Dt.timeout??""),Se(Dt.enabled??!0),Ge(!1),we(""),st(null),q.success(t("settings.mcp.page.toast.configImported"))},[Xe,A,P,N,M,L,V,B,_,oe,ne,te,z,re,le,I,t]);l.useEffect(()=>{if(I&&i){E(i.name),k(i.scope||"user"),T(i.type),R(i.command),O(i.url),$(i.environment),H(i.headers),se(i.oauthEnabled),ae(i.oauthClientId),xe(i.oauthClientSecret),F(i.oauthScope),Q(i.oauthRedirectUri),K(i.timeout),Se(i.enabled),Ce(!1),lt.current={mcpType:i.type,command:i.command,url:i.url,envEntries:i.environment,headerEntries:i.headers,oauthEnabled:i.oauthEnabled,oauthClientId:i.oauthClientId,oauthClientSecret:i.oauthClientSecret,oauthScope:i.oauthScope,oauthRedirectUri:i.oauthRedirectUri,timeout:i.timeout,enabled:i.enabled};return}if(j){k(j.scope==="project"?"project":"user");const We=Ru(j.environment),Rt=j.type==="remote"?j:null,Dt=Ru(Rt?.headers),wt=Rt?.oauth,Jt=wt&&typeof wt=="object"?wt:null,_t=wt!==!1,Fs=j.type,ft=Fs==="local"?j.command??[]:[],ds=Fs==="remote"?j.url??"":"",Qt=typeof Rt?.timeout=="number"&&Number.isFinite(Rt.timeout)?String(Rt.timeout):"";T(Fs),R(ft),O(ds),$(We),H(Dt),se(_t),ae(_t?Jt?.clientId??"":""),xe(_t?Jt?.clientSecret??"":""),F(_t?Jt?.scope??"":""),Q(_t?Jt?.redirectUri??"":""),K(Qt),Se(j.enabled),Ce(!1),lt.current={mcpType:Fs,command:ft,url:ds,envEntries:We,headerEntries:Dt,oauthEnabled:_t,oauthClientId:_t?Jt?.clientId??"":"",oauthClientSecret:_t?Jt?.clientSecret??"":"",oauthScope:_t?Jt?.scope??"":"",oauthRedirectUri:_t?Jt?.redirectUri??"":"",timeout:Qt,enabled:j.enabled}}},[j,I,i]);const nt=l.useMemo(()=>{const We=lt.current;return We?N!==We.mcpType||le!==We.enabled||JSON.stringify(M)!==JSON.stringify(We.command)||L!==We.url||JSON.stringify(V)!==JSON.stringify(We.envEntries)||JSON.stringify(B)!==JSON.stringify(We.headerEntries)||_!==We.oauthEnabled||oe!==We.oauthClientId||ne!==We.oauthClientSecret||te!==We.oauthScope||z!==We.oauthRedirectUri||re!==We.timeout:!1},[N,M,L,V,B,_,oe,ne,te,z,re,le]),Ye=async()=>{const We=I?A.trim():n??"";if(!We){q.error(t("settings.mcp.page.toast.nameRequired"));return}if(I&&r.some(Dt=>Dt.name===We)){q.error(t("settings.mcp.page.toast.serverNameExists"));return}if(N==="local"&&M.filter(Boolean).length===0){q.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(N==="remote"&&!L.trim()){q.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const Rt={name:We,scope:P,type:N,command:M,url:L,environment:V,headers:B,oauthEnabled:_,oauthClientId:oe,oauthClientSecret:ne,oauthScope:te,oauthRedirectUri:z,timeout:re,enabled:le};je(!0);try{const Dt=I?await d(Rt):await p(We,Rt);Dt.ok?(await Ii(Oe),ye(),I&&(a(null),o(We)),await v({directory:u,silent:!0}),Dt.reloadFailed?q.warning(Dt.message||t(I?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Dt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):q.success(Dt.message||t(I?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):q.error(t("settings.mcp.page.toast.saveFailed"))}catch(Dt){q.error(Dt instanceof Error?Dt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{je(!1)}},Ue=async()=>{if(!n)return;ce(!0);const We=await m(n);We.ok?(await Ii(Oe),ye(),We.reloadFailed?q.warning(We.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:We.warning||t("settings.mcp.page.toast.refreshListIfStale")}):q.success(We.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),me(!1)):q.error(t("settings.mcp.page.toast.deleteFailed")),ce(!1)},vt=async()=>{if(n){Pe(!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 v({directory:u,silent:!0});const Rt=Cn.getState().getStatusForDirectory(u??null)[n];Rt?.status==="connected"?q.success(t("settings.mcp.page.toast.connected")):Rt?.status==="needs_auth"?q.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Rt?.status==="needs_client_registration"?q.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Rt?.status==="failed"?q.error(Rt.error||t("settings.mcp.page.toast.connectionFailed")):q.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await v({directory:u,silent:!0})}catch(We){q.error(We instanceof Error?We.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Pe(!1)}}},Et=l.useCallback(()=>I?(q.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):nt?(q.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[nt,I,t]),Gt=l.useCallback(async(We=!1)=>{try{await v({directory:u,silent:We})}catch(Rt){We||q.error(Rt instanceof Error?Rt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,v,t]);l.useEffect(()=>{Gt(!0)},[Gt]),l.useEffect(()=>{it.current=qe,Pe(!1),fe(!1),ye()},[ye,qe]);const ts=l.useCallback(async()=>{if(!n||N!=="remote"||!Et())return;Y(!0);const We=qe;let Rt=null;try{const Dt=Cn.getState().getStatusForDirectory(u??null)[n]?.status;Z.current=Dt==="needs_auth"||Dt==="needs_client_registration";const wt=Gm(n,u);if(!wt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!z.trim()&&!f){const ft=await p(n,{oauthEnabled:_,oauthClientId:oe,oauthClientSecret:ne,oauthScope:te,oauthRedirectUri:wt});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(it.current!==We)return;Q(wt),lt.current=lt.current?{...lt.current,oauthRedirectUri:wt}:lt.current}const Jt=await w(n,u),_t=$d(new URL(Jt).searchParams);if(_t&&(Rt=_t,await ak({state:_t,name:n,directory:u})),it.current!==We)return;Ie(Jt),De(_t??null),Ee(!0),_e.current=0;const Fs=await Qn(Jt);if(it.current!==We)return;Fs?q.message(t(f?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):q.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Dt){await Ii(Rt),it.current===We&&q.error(xc(Dt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{it.current===We&&Y(!1)}},[u,f,N,oe,ne,_,z,te,Et,qe,n,w,t,e,p]),Nt=l.useCallback(async()=>{if(!n||!Et())return;ke(!0);const We=qe;try{if(await S(n,u),it.current!==We)return;Ie(null),De(null),U(""),Ee(!1),_e.current=0,await Ii(Oe),q.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(Rt){it.current===We&&q.error(xc(Rt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{it.current===We&&ke(!1)}},[Oe,S,u,Et,qe,n,t,e]),St=l.useCallback(async()=>{if(!G)return;if((await Rn(G)).ok){q.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}q.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[G,t]),Zt=l.useCallback(async()=>{const We=ZS(ge);if(!We.code){q.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const Rt=We.stateKey?await ik(We.stateKey):null,Dt=We.context??Rt,wt=Dt?.name??n,Jt=Dt?.directory??u;if(!wt){q.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Dt&&!Et())return;Ve(!0);const _t=qe;try{if(await y(wt,We.code,Jt),await Ii(We.stateKey??Oe),it.current!==_t)return;U(""),Ie(null),De(null),Ee(!1),_e.current=0,q.success(wt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:wt}))}catch(Fs){it.current===_t&&q.error(xc(Fs,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{it.current===_t&&Ve(!1)}},[ge,Oe,y,u,Et,qe,n,t,e]),ut=l.useCallback(async()=>{if(!(!n||!Et())){if(!le){q.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}fe(!0);try{const We=await D(n,u),Rt=We.status?.status;We.warning?q.warning(We.warning):Rt==="connected"?q.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Rt==="needs_auth"?q.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Rt==="needs_client_registration"?q.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Rt==="failed"?q.error(We.status?.error||We.error||t("settings.mcp.page.toast.connectionTestFailed")):We.error?q.error(We.error):q.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(We){q.error(We instanceof Error?We.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{fe(!1)}}},[u,le,Et,n,t,D]);if(l.useEffect(()=>{if(!de||!n)return;const We=window.setInterval(()=>{(async()=>{_e.current+=1,await v({directory:u,silent:!0});const Rt=Cn.getState().getStatusForDirectory(u??null)[n];if(Rt){if(Z.current&&Rt.status!=="needs_auth"&&Rt.status!=="needs_client_registration"){Ee(!1),_e.current=0,Z.current=!1,Ie(null),U(""),Rt.status==="connected"&&q.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!Z.current&&Rt.status==="failed"){Ee(!1),_e.current=0,Z.current=!1,q.error(Rt.error||t("settings.mcp.page.toast.authorizationFailed"));return}_e.current>=30&&(Ee(!1),_e.current=0,Z.current=!1,q.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(We)}},[u,de,v,n,t]),!n)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(C,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Xt=b[n],as=n?h[n]:void 0,Bt=Xt??as,ls=Xt?.status==="connected",gs=Xt?.status==="needs_auth"||Xt?.status==="needs_client_registration",us=f?null:Gm(n,u),xs=sk(Bt?.status,e,Bt&&"error"in Bt?Bt.error:void 0),At=We=>{switch(We){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");default:return We}};return s.jsxs(As,{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:[I?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(Hm,{status:Bt?.status,enabled:le,getStatusLabel:At,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:I?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")})}),!I&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:ls?"outline":"default",size:"xs",className:"!font-normal",onClick:vt,disabled:ee||!le,children:t(ee?"settings.mcp.page.actions.working":ls?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),N==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:gs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{ts()},disabled:Ne||!le,children:t(Ne?"settings.mcp.page.actions.starting":gs?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{Nt()},disabled:he||!le,children:t(he?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),ls&&s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ut()},disabled:be||!le,children:t(be?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!I&&rk(Bt?.status,G,gs,de)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:pe("rounded-lg border p-3",nk(Bt?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Hm,{status:Bt?.status,enabled:le,getStatusLabel:At})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:xs}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:P==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:u??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!ls&&s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ut()},disabled:be||!le,children:t(be?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),G&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:G}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Qn(G)},children:[s.jsx(C,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{St()},children:[s.jsx(C,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),N==="remote"&&(gs||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(vn,{value:ge,onChange:We=>U(We.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Zt()},disabled:Te,children:t(Te?"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:[I&&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(Ut,{value:A,onChange:We=>E(We.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 font-mono px-2",autoFocus:!0}),s.jsxs(ps,{value:P,onValueChange:We=>k(We),children:[s.jsx(hs,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:t(P==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:P==="user"?s.jsx(C,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"folder",className:"h-3.5 w-3.5"})}),s.jsxs(fs,{align:"end",children:[s.jsx(Ft,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ft,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),I&&s.jsx("div",{className:"py-1.5",children:s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:Je,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(C,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]})}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":le,onClick:()=>Se(!le),onKeyDown:We=>{(We.key===" "||We.key==="Enter")&&(We.preventDefault(),Se(!le))},children:[s.jsx(bs,{checked:le,onChange:Se,ariaLabel:t("settings.mcp.page.server.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.enable")})]}),s.jsx("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:s.jsxs("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.transportMode")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":N==="local",onClick:()=>T("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":N==="remote",onClick:()=>T("remote"),className:"!font-normal",children:t("settings.mcp.page.transport.remote")})]})]})})]})]}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t(N==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:N==="local"?s.jsx(ek,{value:M,onChange:R,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:We=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:We}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:We=>t("settings.mcp.page.connection.previewArgs",{count:We})}):s.jsx(Ut,{value:L,onChange:We=>O(We.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),N==="remote"&&s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.advanced.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs(cr,{open:ie,onOpenChange:Ce,children:[s.jsxs(jr,{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(_?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",B.length," ",t("settings.mcp.page.advanced.headers"),re?` · ${re}ms`:"",")"]})]}),ie?s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(C,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(dr,{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(Ut,{type:"number",min:"1",step:"1",value:re,onChange:We=>K(We.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground sm:pl-64",children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-2 typography-ui-label text-foreground",children:[t("settings.mcp.page.advanced.requestHeaders"),B.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",B.length,")"]})]}),s.jsx(Km,{value:B,onChange:H,keyTransform:We=>We.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:We=>t("settings.mcp.page.toast.importedVariablesCount",{count:We}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":_,onClick:()=>se(!_),onKeyDown:We=>{(We.key===" "||We.key==="Enter")&&(We.preventDefault(),se(!_))},children:[s.jsx(bs,{checked:_,onChange:se,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(Ut,{value:oe,onChange:We=>ae(We.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!_,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Ut,{value:ne,onChange:We=>xe(We.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!_,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Ut,{value:te,onChange:We=>F(We.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!_,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Ut,{value:z,onChange:We=>Q(We.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!_,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),us&&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:us})]})]})]})})]})})]}),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(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>$([{key:"",value:""}]),children:[s.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Km,{value:V,onChange:$,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:We=>t("settings.mcp.page.toast.importedVariablesCount",{count:We}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})})]}),s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[s.jsx(ve,{onClick:Ye,disabled:ue||!nt&&!I,size:"xs",className:"!font-normal",children:t(ue?"settings.common.actions.saving":I?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!I&&s.jsx(ve,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>me(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(ws,{open:He,onOpenChange:We=>{We||(Ge(!1),we(""),st(null))},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Rs,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(vn,{value:Xe,onChange:We=>{we(We.target.value),st(null)},placeholder:`{
|
|
169
|
-
"mcpServers": {
|
|
170
|
-
"postgres": {
|
|
171
|
-
"command": "npx",
|
|
172
|
-
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),tt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:tt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Be,type:"button",children:[s.jsx(C,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Gs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>{Ge(!1),we(""),st(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(ve,{onClick:ze,disabled:!Xe.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(ws,{open:W,onOpenChange:We=>{!We&&!X&&me(!1)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Rs,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Gs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>me(!1),disabled:X,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:Ue,disabled:X,children:t(X?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},ck=t=>{const e=rt.c(150),{onItemSelect:n}=t,{t:r}=mt(),[i,a]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedSkillName:h,skills:v,setSelectedSkill:x,setSkillDraft:g,createSkill:w,deleteSkill:y,getSkillDetail:S}=ea(mr(dk));let D;e[0]!==n||e[1]!==x||e[2]!==g||e[3]!==v?(D=()=>{let Be="new-skill",ze=1;for(;v.some(nt=>nt.name===Be);)Be=`new-skill-${ze}`,ze++;g({name:Be,scope:"user",source:"opencode",description:""}),x(Be),n?.()},e[0]=n,e[1]=x,e[2]=g,e[3]=v,e[4]=D):D=e[4];const j=D;let I;e[5]===Symbol.for("react.memo_cache_sentinel")?(I=async Be=>{p(Be)},e[5]=I):I=e[5];const A=I;let E;e[6]!==d||e[7]!==y||e[8]!==r?(E=async()=>{if(!d)return;u(!0),await y(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]=y,e[8]=r,e[9]=E):E=e[9];const P=E;let k;e[10]!==S||e[11]!==x||e[12]!==g||e[13]!==v||e[14]!==r?(k=async Be=>{const ze=Be.name;let nt=1,Ye=`${ze}-copy`;for(;v.some(vt=>vt.name===Ye);)nt++,Ye=`${ze}-copy-${nt}`;const Ue=await S(Be.name);if(!Ue){q.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}g({name:Ye,scope:Be.scope||"user",source:Be.source||"opencode",description:(Ue.sources.md.fields.includes("description"),""),instructions:""}),x(Ye)},e[10]=S,e[11]=x,e[12]=g,e[13]=v,e[14]=r,e[15]=k):k=e[15];const N=k;let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=Be=>{c(Be.name),a(Be)},e[16]=T):T=e[16];const M=T;let R;e[17]!==w||e[18]!==y||e[19]!==S||e[20]!==i||e[21]!==o||e[22]!==x||e[23]!==v||e[24]!==r?(R=async()=>{if(!i)return;const Be=o.trim().replace(/\s+/g,"-").toLowerCase();if(!Be){q.error(r("settings.skills.page.toast.skillNameRequired"));return}if(Be===i.name){a(null);return}if(v.some(Ye=>Ye.name===Be)){q.error(r("settings.skills.page.toast.skillExists"));return}if(!await S(i.name)){q.error(r("settings.skills.sidebar.toast.renameLoadFailed")),a(null);return}await w({name:Be,description:"Renamed skill",scope:i.scope,source:i.source})?await y(i.name)?(q.success(`Skill renamed to "${Be}"`),x(Be)):q.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):q.error(r("settings.skills.sidebar.toast.renameFailed")),a(null)},e[17]=w,e[18]=y,e[19]=S,e[20]=i,e[21]=o,e[22]=x,e[23]=v,e[24]=r,e[25]=R):R=e[25];const L=R;let O;e[26]!==v?(O=v.filter(uk),e[26]=v,e[27]=O):O=e[27];const V=O;let $;e[28]!==v?($=v.filter(mk),e[28]=v,e[29]=$):$=e[29];const B=$;let H;e[30]===Symbol.for("react.memo_cache_sentinel")?(H=function(ze){const nt={},Ye=[];for(const vt of ze)vt.group?(nt[vt.group]||(nt[vt.group]=[]),nt[vt.group].push(vt)):Ye.push(vt);const Ue=Object.keys(nt).sort(pk).map(vt=>({name:vt,skills:[...nt[vt]].sort(hk)}));return Ye.sort(fk),{sortedGroups:Ue,ungrouped:Ye}},e[30]=H):H=e[30];const _=H;let se;e[31]!==V?(se=_(V),e[31]=V,e[32]=se):se=e[32];const oe=se;let ae;e[33]!==B?(ae=_(B),e[33]=B,e[34]=ae):ae=e[34];const ne=ae;let xe;e[35]===Symbol.for("react.memo_cache_sentinel")?(xe=pe("flex h-full flex-col","bg-background"),e[35]=xe):xe=e[35];let te;e[36]!==r?(te=r("settings.skills.sidebar.title"),e[36]=r,e[37]=te):te=e[37];let F;e[38]!==te?(F=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:te}),e[38]=te,e[39]=F):F=e[39];let z;e[40]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(io,{className:"mb-3"}),e[40]=z):z=e[40];let Q;e[41]!==v.length||e[42]!==r?(Q=r("settings.skills.sidebar.total",{count:v.length}),e[41]=v.length,e[42]=r,e[43]=Q):Q=e[43];let re;e[44]!==Q?(re=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Q}),e[44]=Q,e[45]=re):re=e[45];let K;e[46]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),e[46]=K):K=e[46];let le;e[47]!==j?(le=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:K}),e[47]=j,e[48]=le):le=e[48];let Se;e[49]!==re||e[50]!==le?(Se=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[re,le]}),e[49]=re,e[50]=le,e[51]=Se):Se=e[51];let ue;e[52]!==F||e[53]!==Se?(ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[F,z,Se]}),e[52]=F,e[53]=Se,e[54]=ue):ue=e[54];let je;e[55]!==oe||e[56]!==ne||e[57]!==N||e[58]!==n||e[59]!==f||e[60]!==V||e[61]!==h||e[62]!==x||e[63]!==v.length||e[64]!==r||e[65]!==B?(je=s.jsx(As,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(C,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[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")}),oe.sortedGroups.map(Be=>{const{name:ze,skills:nt}=Be;return s.jsx(rd,{label:ze,count:nt.length,storageKey:"project-skills",children:nt.map(Ye=>s.jsx(Io,{skill:Ye,isSelected:h===Ye.name,onSelect:()=>{x(Ye.name),n?.()},onRename:()=>M(Ye),onDelete:()=>A(Ye),onDuplicate:()=>N(Ye),isMenuOpen:f===Ye.name,onMenuOpenChange:Ue=>b(Ue?Ye.name:null)},Ye.name))},ze)}),oe.ungrouped.map(Be=>s.jsx(Io,{skill:Be,isSelected:h===Be.name,onSelect:()=>{x(Be.name),n?.()},onRename:()=>M(Be),onDelete:()=>A(Be),onDuplicate:()=>N(Be),isMenuOpen:f===Be.name,onMenuOpenChange:ze=>b(ze?Be.name:null)},Be.name))]}),B.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.user")}),ne.sortedGroups.map(Be=>{const{name:ze,skills:nt}=Be;return s.jsx(rd,{label:ze,count:nt.length,storageKey:"user-skills",children:nt.map(Ye=>s.jsx(Io,{skill:Ye,isSelected:h===Ye.name,onSelect:()=>{x(Ye.name),n?.()},onRename:()=>M(Ye),onDelete:()=>A(Ye),onDuplicate:()=>N(Ye),isMenuOpen:f===Ye.name,onMenuOpenChange:Ue=>b(Ue?Ye.name:null)},Ye.name))},ze)}),ne.ungrouped.map(Be=>s.jsx(Io,{skill:Be,isSelected:h===Be.name,onSelect:()=>{x(Be.name),n?.()},onRename:()=>M(Be),onDelete:()=>A(Be),onDuplicate:()=>N(Be),isMenuOpen:f===Be.name,onMenuOpenChange:ze=>b(ze?Be.name:null)},Be.name))]})]})}),e[55]=oe,e[56]=ne,e[57]=N,e[58]=n,e[59]=f,e[60]=V,e[61]=h,e[62]=x,e[63]=v.length,e[64]=r,e[65]=B,e[66]=je):je=e[66];const W=d!==null;let me;e[67]!==m?(me=Be=>{!Be&&!m&&p(null)},e[67]=m,e[68]=me):me=e[68];let X;e[69]!==r?(X=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=X):X=e[70];let ce;e[71]!==X?(ce=s.jsx(js,{children:X}),e[71]=X,e[72]=ce):ce=e[72];const ee=d?.name??"";let Pe;e[73]!==r||e[74]!==ee?(Pe=r("settings.skills.sidebar.deleteDialog.description",{name:ee}),e[73]=r,e[74]=ee,e[75]=Pe):Pe=e[75];let Ne;e[76]!==Pe?(Ne=s.jsx(Rs,{children:Pe}),e[76]=Pe,e[77]=Ne):Ne=e[77];let Y;e[78]!==ce||e[79]!==Ne?(Y=s.jsxs(Ss,{children:[ce,Ne]}),e[78]=ce,e[79]=Ne,e[80]=Y):Y=e[80];let he;e[81]===Symbol.for("react.memo_cache_sentinel")?(he=()=>p(null),e[81]=he):he=e[81];let ke;e[82]!==r?(ke=r("settings.common.actions.cancel"),e[82]=r,e[83]=ke):ke=e[83];let be;e[84]!==m||e[85]!==ke?(be=s.jsx(ve,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:he,disabled:m,children:ke}),e[84]=m,e[85]=ke,e[86]=be):be=e[86];let fe;e[87]!==r?(fe=r("settings.common.actions.delete"),e[87]=r,e[88]=fe):fe=e[88];let Te;e[89]!==P||e[90]!==m||e[91]!==fe?(Te=s.jsx(ve,{size:"sm",onClick:P,disabled:m,children:fe}),e[89]=P,e[90]=m,e[91]=fe,e[92]=Te):Te=e[92];let Ve;e[93]!==be||e[94]!==Te?(Ve=s.jsxs(Gs,{children:[be,Te]}),e[93]=be,e[94]=Te,e[95]=Ve):Ve=e[95];let G;e[96]!==Y||e[97]!==Ve?(G=s.jsxs(vs,{className:"max-w-md",children:[Y,Ve]}),e[96]=Y,e[97]=Ve,e[98]=G):G=e[98];let Ie;e[99]!==W||e[100]!==me||e[101]!==G?(Ie=s.jsx(ws,{open:W,onOpenChange:me,children:G}),e[99]=W,e[100]=me,e[101]=G,e[102]=Ie):Ie=e[102];const Oe=i!==null;let De;e[103]===Symbol.for("react.memo_cache_sentinel")?(De=Be=>!Be&&a(null),e[103]=De):De=e[103];let ge;e[104]!==r?(ge=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=ge):ge=e[105];let U;e[106]!==ge?(U=s.jsx(js,{children:ge}),e[106]=ge,e[107]=U):U=e[107];const de=i?.name??"";let Ee;e[108]!==r||e[109]!==de?(Ee=r("settings.skills.sidebar.renameDialog.description",{name:de}),e[108]=r,e[109]=de,e[110]=Ee):Ee=e[110];let _e;e[111]!==Ee?(_e=s.jsx(Rs,{children:Ee}),e[111]=Ee,e[112]=_e):_e=e[112];let Z;e[113]!==U||e[114]!==_e?(Z=s.jsxs(Ss,{children:[U,_e]}),e[113]=U,e[114]=_e,e[115]=Z):Z=e[115];let ie;e[116]===Symbol.for("react.memo_cache_sentinel")?(ie=Be=>c(Be.target.value),e[116]=ie):ie=e[116];let Ce;e[117]!==r?(Ce=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=Ce):Ce=e[118];let He;e[119]!==L?(He=Be=>{Be.key==="Enter"&&L()},e[119]=L,e[120]=He):He=e[120];let Ge;e[121]!==o||e[122]!==Ce||e[123]!==He?(Ge=s.jsx(Ut,{value:o,onChange:ie,placeholder:Ce,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:He}),e[121]=o,e[122]=Ce,e[123]=He,e[124]=Ge):Ge=e[124];let Xe;e[125]===Symbol.for("react.memo_cache_sentinel")?(Xe=()=>a(null),e[125]=Xe):Xe=e[125];let we;e[126]!==r?(we=r("settings.common.actions.cancel"),e[126]=r,e[127]=we):we=e[127];let tt;e[128]!==we?(tt=s.jsx(ve,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Xe,children:we}),e[128]=we,e[129]=tt):tt=e[129];let st;e[130]!==r?(st=r("settings.common.actions.rename"),e[130]=r,e[131]=st):st=e[131];let qe;e[132]!==L||e[133]!==st?(qe=s.jsx(ve,{size:"sm",onClick:L,children:st}),e[132]=L,e[133]=st,e[134]=qe):qe=e[134];let it;e[135]!==tt||e[136]!==qe?(it=s.jsxs(Gs,{children:[tt,qe]}),e[135]=tt,e[136]=qe,e[137]=it):it=e[137];let lt;e[138]!==Z||e[139]!==Ge||e[140]!==it?(lt=s.jsxs(vs,{children:[Z,Ge,it]}),e[138]=Z,e[139]=Ge,e[140]=it,e[141]=lt):lt=e[141];let ye;e[142]!==Oe||e[143]!==lt?(ye=s.jsx(ws,{open:Oe,onOpenChange:De,children:lt}),e[142]=Oe,e[143]=lt,e[144]=ye):ye=e[144];let Je;return e[145]!==ue||e[146]!==je||e[147]!==Ie||e[148]!==ye?(Je=s.jsxs("div",{className:xe,children:[ue,je,Ie,ye]}),e[145]=ue,e[146]=je,e[147]=Ie,e[148]=ye,e[149]=Je):Je=e[149],Je},Io=t=>{const e=rt.c(63),{skill:n,isSelected:r,onSelect:i,onDelete:a,onRename:o,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=mt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Wi(),e[0]=u):u=e[0];const f=u,b=r?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[1]!==b?(h=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]=h):h=e[2];let v;e[3]!==p?(v=f?void 0:se=>{se.preventDefault(),p(!0)},e[3]=p,e[4]=v):v=e[4];let x;e[5]!==n.name?(x=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=x):x=e[6];let g;e[7]!==n.scope?(g=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:n.scope}),e[7]=n.scope,e[8]=g):g=e[8];let w;e[9]!==n.source||e[10]!==m?(w=n.source==="claude"&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:m("settings.skills.sidebar.badge.claude")}),e[9]=n.source,e[10]=m,e[11]=w):w=e[11];let y;e[12]!==n.source||e[13]!==m?(y=n.source==="agents"&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:m("settings.skills.sidebar.badge.agents")}),e[12]=n.source,e[13]=m,e[14]=y):y=e[14];let S;e[15]!==x||e[16]!==g||e[17]!==w||e[18]!==y?(S=s.jsxs("div",{className:"flex items-center gap-1.5",children:[x,g,w,y]}),e[15]=x,e[16]=g,e[17]=w,e[18]=y,e[19]=S):S=e[19];let D;e[20]!==i||e[21]!==S?(D=s.jsx("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:S}),e[20]=i,e[21]=S,e[22]=D):D=e[22];let j;e[23]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Os,{asChild:!0,children:s.jsx(ve,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(C,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[23]=j):j=e[23];let I;e[24]!==o?(I=se=>{se.stopPropagation(),o()},e[24]=o,e[25]=I):I=e[25];let A;e[26]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(C,{name:"edit",className:"h-4 w-4 mr-px"}),e[26]=A):A=e[26];let E;e[27]!==m?(E=m("settings.common.actions.rename"),e[27]=m,e[28]=E):E=e[28];let P;e[29]!==I||e[30]!==E?(P=s.jsxs(zt,{onClick:I,children:[A,E]}),e[29]=I,e[30]=E,e[31]=P):P=e[31];let k;e[32]!==c?(k=se=>{se.stopPropagation(),c()},e[32]=c,e[33]=k):k=e[33];let N;e[34]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(C,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[34]=N):N=e[34];let T;e[35]!==m?(T=m("settings.common.actions.duplicate"),e[35]=m,e[36]=T):T=e[36];let M;e[37]!==k||e[38]!==T?(M=s.jsxs(zt,{onClick:k,children:[N,T]}),e[37]=k,e[38]=T,e[39]=M):M=e[39];let R;e[40]!==a?(R=se=>{se.stopPropagation(),a()},e[40]=a,e[41]=R):R=e[41];let L;e[42]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(C,{name:"delete-bin",className:"h-4 w-4 mr-px"}),e[42]=L):L=e[42];let O;e[43]!==m?(O=m("settings.common.actions.delete"),e[43]=m,e[44]=O):O=e[44];let V;e[45]!==R||e[46]!==O?(V=s.jsxs(zt,{onClick:R,className:"text-destructive focus:text-destructive",children:[L,O]}),e[45]=R,e[46]=O,e[47]=V):V=e[47];let $;e[48]!==P||e[49]!==M||e[50]!==V?($=s.jsxs($s,{align:"end",className:"w-fit min-w-20",children:[P,M,V]}),e[48]=P,e[49]=M,e[50]=V,e[51]=$):$=e[51];let B;e[52]!==d||e[53]!==p||e[54]!==$?(B=s.jsxs(Bs,{open:d,onOpenChange:p,children:[j,$]}),e[52]=d,e[53]=p,e[54]=$,e[55]=B):B=e[55];let H;e[56]!==D||e[57]!==B?(H=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[D,B]}),e[56]=D,e[57]=B,e[58]=H):H=e[58];let _;return e[59]!==H||e[60]!==h||e[61]!==v?(_=s.jsx("div",{className:h,onContextMenu:v,children:H}),e[59]=H,e[60]=h,e[61]=v,e[62]=_):_=e[62],_};function dk(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function uk(t){return t.scope==="project"}function mk(t){return t.scope==="user"}function pk(t,e){return t.localeCompare(e)}function hk(t,e){return t.name.localeCompare(e.name)}function fk(t,e){return t.name.localeCompare(e.name)}const gk=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,xk=t=>{const e=t.trim(),n=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(n==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(n==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const r=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return r?`${r[1]}/${r[2].replace(/\.git$/i,"")}`:e},bk=async()=>{try{const t=lr()?.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}},yk=t=>{const e=rt.c(158),{open:n,onOpenChange:r}=t,{t:i}=mt(),a=wa(vk),o=wa(wk),c=wa(jk),d=Gn(Nk),p=Gn(Sk),[m,u]=l.useState(""),[f,b]=l.useState(""),[h,v]=l.useState("");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=[],e[0]=x):x=e[0];const[g,w]=l.useState(x),[y,S]=l.useState(null),[D,j]=l.useState(!1);let I;e[1]===Symbol.for("react.memo_cache_sentinel")?(I=[],e[1]=I):I=e[1];const[A,E]=l.useState(I),[P,k]=l.useState(null),N=l.useRef(0);let T;e[2]===Symbol.for("react.memo_cache_sentinel")?(T=ye=>{N.current=N.current+1,j(!1),S(null),ye?.clearIdentity&&(E([]),k(null))},e[2]=T):T=e[2];const M=T;let R,L;e[3]!==p||e[4]!==n?(R=()=>{n&&(N.current=N.current+1,u(""),b(""),v(""),S(null),j(!1),E([]),k(null),p(),(async()=>{const ye=await bk(),Je=Array.isArray(ye?.skillCatalogs)?ye?.skillCatalogs:[];w(Je||[])})())},L=[n,p],e[3]=p,e[4]=n,e[5]=R,e[6]=L):(R=e[5],L=e[6]),l.useEffect(R,L);let O;e[7]!==f?(O=f.trim(),e[7]=f,e[8]=O):O=e[8];const V=O;let $;e[9]!==h?($=h.trim(),e[9]=h,e[10]=$):$=e[10];const B=$;let H;if(e[11]!==g||e[12]!==V||e[13]!==B){let ye;e[15]!==V||e[16]!==B?(ye=Je=>{const Be=(Je.source||"").trim(),ze=(Je.subpath||"").trim();return Be===V&&ze===B},e[15]=V,e[16]=B,e[17]=ye):ye=e[17],H=g.some(ye),e[11]=g,e[12]=V,e[13]=B,e[14]=H}else H=e[14];const _=H;let se;e[18]!==d||e[19]!==P||e[20]!==m||e[21]!==a||e[22]!==f||e[23]!==h||e[24]!==i?(se=async()=>{const ye=f.trim();if(!ye){q.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(xk(ye)),j(!1),S(null);const Je=N.current+1;N.current=Je;const Be=await a({source:ye,subpath:h.trim()||void 0,gitIdentityId:P||void 0});if(N.current!==Je)return;if(!Be.ok){if(Be.error?.kind==="authRequired"){if(pn()){q.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const nt=Be.error.identities||[];if(E(nt),!P&&nt.length>0){const Ye=d&&d!=="global"&&nt.some(Ue=>Ue.id===d)?d:nt[0].id;k(Ye)}q.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}q.error(Be.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const ze=Be.items?.length||0;if(S(ze),ze===0){q.error(i("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}E([]),j(!0),q.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:ze}))},e[18]=d,e[19]=P,e[20]=m,e[21]=a,e[22]=f,e[23]=h,e[24]=i,e[25]=se):se=e[25];const oe=se;let ae;e[26]!==g||e[27]!==P||e[28]!==_||e[29]!==m||e[30]!==o||e[31]!==r||e[32]!==D||e[33]!==f||e[34]!==h||e[35]!==i?(ae=async()=>{const ye=m.trim(),Je=f.trim(),Be=h.trim();if(!ye){q.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!Je){q.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!D){q.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(_){q.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const ze={id:gk(),label:ye,source:Je,...Be?{subpath:Be}:{},...P?{gitIdentityId:P}:{}},nt=[...g,ze];try{await Ps({skillCatalogs:nt}),w(nt),q.success(i("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),r(!1)}catch(Ye){const Ue=Ye;q.error(Ue instanceof Error?Ue.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=g,e[27]=P,e[28]=_,e[29]=m,e[30]=o,e[31]=r,e[32]=D,e[33]=f,e[34]=h,e[35]=i,e[36]=ae):ae=e[36];const ne=ae;let xe;e[37]!==i?(xe=i("settings.skills.catalog.add.title"),e[37]=i,e[38]=xe):xe=e[38];let te;e[39]!==xe?(te=s.jsx(js,{children:xe}),e[39]=xe,e[40]=te):te=e[40];let F;e[41]!==i?(F=i("settings.skills.catalog.add.descriptionPrefix"),e[41]=i,e[42]=F):F=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 Q;e[44]!==i?(Q=i("settings.skills.catalog.add.descriptionSuffix"),e[44]=i,e[45]=Q):Q=e[45];let re;e[46]!==F||e[47]!==Q?(re=s.jsxs(Rs,{children:[F," ",z,Q]}),e[46]=F,e[47]=Q,e[48]=re):re=e[48];let K;e[49]!==te||e[50]!==re?(K=s.jsxs(Ss,{children:[te,re]}),e[49]=te,e[50]=re,e[51]=K):K=e[51];let le;e[52]!==i?(le=i("settings.skills.catalog.add.field.catalogName"),e[52]=i,e[53]=le):le=e[53];let Se;e[54]!==le?(Se=s.jsx("label",{className:"typography-ui-label text-foreground",children:le}),e[54]=le,e[55]=Se):Se=e[55];let ue;e[56]===Symbol.for("react.memo_cache_sentinel")?(ue=ye=>u(ye.target.value),e[56]=ue):ue=e[56];let je;e[57]!==i?(je=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=i,e[58]=je):je=e[58];let W;e[59]!==m||e[60]!==je?(W=s.jsx(Ut,{value:m,onChange:ue,placeholder:je}),e[59]=m,e[60]=je,e[61]=W):W=e[61];let me;e[62]!==Se||e[63]!==W?(me=s.jsxs("div",{className:"space-y-2",children:[Se,W]}),e[62]=Se,e[63]=W,e[64]=me):me=e[64];let X;e[65]!==i?(X=i("settings.skills.catalog.add.field.repository"),e[65]=i,e[66]=X):X=e[66];let ce;e[67]!==X?(ce=s.jsx("label",{className:"typography-ui-label text-foreground",children:X}),e[67]=X,e[68]=ce):ce=e[68];let ee;e[69]===Symbol.for("react.memo_cache_sentinel")?(ee=ye=>{b(ye.target.value),M({clearIdentity:!0})},e[69]=ee):ee=e[69];let Pe;e[70]!==i?(Pe=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[70]=i,e[71]=Pe):Pe=e[71];let Ne;e[72]!==f||e[73]!==Pe?(Ne=s.jsx(Ut,{value:f,onChange:ee,placeholder:Pe}),e[72]=f,e[73]=Pe,e[74]=Ne):Ne=e[74];let Y;e[75]!==i?(Y=i("settings.skills.catalog.add.field.repositoryHint"),e[75]=i,e[76]=Y):Y=e[76];let he;e[77]!==Y?(he=s.jsx("p",{className:"typography-micro text-muted-foreground",children:Y}),e[77]=Y,e[78]=he):he=e[78];let ke;e[79]!==ce||e[80]!==Ne||e[81]!==he?(ke=s.jsxs("div",{className:"space-y-2",children:[ce,Ne,he]}),e[79]=ce,e[80]=Ne,e[81]=he,e[82]=ke):ke=e[82];let be;e[83]!==i?(be=i("settings.skills.catalog.add.field.optionalSubpath"),e[83]=i,e[84]=be):be=e[84];let fe;e[85]!==be?(fe=s.jsx("label",{className:"typography-ui-label text-foreground",children:be}),e[85]=be,e[86]=fe):fe=e[86];let Te;e[87]===Symbol.for("react.memo_cache_sentinel")?(Te=ye=>{v(ye.target.value),M({clearIdentity:!0})},e[87]=Te):Te=e[87];let Ve;e[88]!==i?(Ve=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=i,e[89]=Ve):Ve=e[89];let G;e[90]!==h||e[91]!==Ve?(G=s.jsx(Ut,{value:h,onChange:Te,placeholder:Ve}),e[90]=h,e[91]=Ve,e[92]=G):G=e[92];let Ie;e[93]!==fe||e[94]!==G?(Ie=s.jsxs("div",{className:"space-y-2",children:[fe,G]}),e[93]=fe,e[94]=G,e[95]=Ie):Ie=e[95];let Oe;e[96]!==P||e[97]!==A||e[98]!==i?(Oe=A.length>0&&!pn()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:i("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:i("settings.skills.catalog.shared.auth.description")})]}),s.jsxs(ps,{value:P||"",onValueChange:ye=>{k(ye),M()},children:[s.jsx(hs,{className:"w-fit",children:s.jsx("span",{children:A.find(ye=>ye.id===P)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(fs,{align:"start",children:A.map(kk)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:i("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=P,e[97]=A,e[98]=i,e[99]=Oe):Oe=e[99];let De;e[100]!==y||e[101]!==i?(De=y!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:y})}):null,e[100]=y,e[101]=i,e[102]=De):De=e[102];let ge;e[103]!==_||e[104]!==i?(ge=_?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=_,e[104]=i,e[105]=ge):ge=e[105];let U;e[106]!==me||e[107]!==ke||e[108]!==Ie||e[109]!==Oe||e[110]!==De||e[111]!==ge?(U=s.jsxs("div",{className:"space-y-4",children:[me,ke,Ie,Oe,De,ge]}),e[106]=me,e[107]=ke,e[108]=Ie,e[109]=Oe,e[110]=De,e[111]=ge,e[112]=U):U=e[112];let de;e[113]!==r?(de=()=>r(!1),e[113]=r,e[114]=de):de=e[114];let Ee;e[115]!==i?(Ee=i("settings.common.actions.cancel"),e[115]=i,e[116]=Ee):Ee=e[116];let _e;e[117]!==de||e[118]!==Ee?(_e=s.jsx(ve,{size:"sm",variant:"ghost",onClick:de,children:Ee}),e[117]=de,e[118]=Ee,e[119]=_e):_e=e[119];let Z;e[120]!==oe?(Z=()=>{oe()},e[120]=oe,e[121]=Z):Z=e[121];let ie;e[122]!==c||e[123]!==f?(ie=c||!f.trim(),e[122]=c,e[123]=f,e[124]=ie):ie=e[124];let Ce;e[125]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(C,{name:"git-repository",className:"h-4 w-4"}),e[125]=Ce):Ce=e[125];let He;e[126]!==c||e[127]!==i?(He=i(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=i,e[128]=He):He=e[128];let Ge;e[129]!==Z||e[130]!==ie||e[131]!==He?(Ge=s.jsxs(ve,{size:"sm",className:"gap-2",variant:"ghost",onClick:Z,disabled:ie,children:[Ce,He]}),e[129]=Z,e[130]=ie,e[131]=He,e[132]=Ge):Ge=e[132];let Xe;e[133]!==ne?(Xe=()=>{ne()},e[133]=ne,e[134]=Xe):Xe=e[134];let we;e[135]!==_||e[136]!==m||e[137]!==D||e[138]!==f?(we=!D||_||!m.trim()||!f.trim(),e[135]=_,e[136]=m,e[137]=D,e[138]=f,e[139]=we):we=e[139];let tt;e[140]!==i?(tt=i("settings.skills.catalog.add.actions.addCatalog"),e[140]=i,e[141]=tt):tt=e[141];let st;e[142]!==Xe||e[143]!==we||e[144]!==tt?(st=s.jsx(ve,{size:"sm",onClick:Xe,disabled:we,children:tt}),e[142]=Xe,e[143]=we,e[144]=tt,e[145]=st):st=e[145];let qe;e[146]!==_e||e[147]!==Ge||e[148]!==st?(qe=s.jsxs(Gs,{children:[_e,Ge,st]}),e[146]=_e,e[147]=Ge,e[148]=st,e[149]=qe):qe=e[149];let it;e[150]!==K||e[151]!==U||e[152]!==qe?(it=s.jsxs(vs,{className:"max-w-xl",children:[K,U,qe]}),e[150]=K,e[151]=U,e[152]=qe,e[153]=it):it=e[153];let lt;return e[154]!==r||e[155]!==n||e[156]!==it?(lt=s.jsx(ws,{open:n,onOpenChange:r,children:it}),e[154]=r,e[155]=n,e[156]=it,e[157]=lt):lt=e[157],lt};function vk(t){return t.scanRepo}function wk(t){return t.loadCatalog}function jk(t){return t.isScanning}function Nk(t){return t.defaultGitIdentityId}function Sk(t){return t.loadDefaultGitIdentityId}function kk(t){return s.jsx(Ft,{value:t.id,children:t.name},t.id)}const Ck=t=>{const e=rt.c(85),{open:n,onOpenChange:r,conflicts:i,onConfirm:a}=t,{t:o}=mt();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]!==i||e[2]!==n?(m=()=>{if(!n)return;const te={};for(const F of i)te[F.skillName]="skip";p(te)},u=[n,i],e[1]=i,e[2]=n,e[3]=m,e[4]=u):(m=e[3],u=e[4]),l.useEffect(m,u);let f;e[5]!==i?(f=te=>{const F={};for(const z of i)F[z.skillName]=te;p(F)},e[5]=i,e[6]=f):f=e[6];const b=f;let h;e[7]!==i||e[8]!==d?(h=i.length>0&&i.every(te=>d[te.skillName]),e[7]=i,e[8]=d,e[9]=h):h=e[9];const v=h;let x;e[10]!==o?(x=o("settings.skills.catalog.conflicts.title"),e[10]=o,e[11]=x):x=e[11];let g;e[12]!==x?(g=s.jsx(js,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==o?(w=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=w):w=e[15];let y;e[16]!==w?(y=s.jsx(Rs,{children:w}),e[16]=w,e[17]=y):y=e[17];let S;e[18]!==g||e[19]!==y?(S=s.jsxs(Ss,{children:[g,y]}),e[18]=g,e[19]=y,e[20]=S):S=e[20];let D;e[21]!==i.length||e[22]!==o?(D=o("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=o,e[23]=D):D=e[23];let j;e[24]!==D?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:D}),e[24]=D,e[25]=j):j=e[25];let I;e[26]!==b?(I=()=>b("skip"),e[26]=b,e[27]=I):I=e[27];let A;e[28]!==o?(A=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=A):A=e[29];let E;e[30]!==I||e[31]!==A?(E=s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:I,children:A}),e[30]=I,e[31]=A,e[32]=E):E=e[32];let P;e[33]!==b?(P=()=>b("overwrite"),e[33]=b,e[34]=P):P=e[34];let k;e[35]!==o?(k=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=k):k=e[36];let N;e[37]!==P||e[38]!==k?(N=s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:P,children:k}),e[37]=P,e[38]=k,e[39]=N):N=e[39];let T;e[40]!==E||e[41]!==N?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[E,N]}),e[40]=E,e[41]=N,e[42]=T):T=e[42];let M;e[43]!==j||e[44]!==T?(M=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,T]}),e[43]=j,e[44]=T,e[45]=M):M=e[45];let R;if(e[46]!==i||e[47]!==d||e[48]!==o){let te;e[50]!==d||e[51]!==o?(te=F=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:F.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:F.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:F.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(ps,{value:d[F.skillName]||"skip",onValueChange:z=>p(Q=>({...Q,[F.skillName]:z})),children:[s.jsx(hs,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[F.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(fs,{align:"end",children:[s.jsx(Ft,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Ft,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},F.skillName),e[50]=d,e[51]=o,e[52]=te):te=e[52],R=i.map(te),e[46]=i,e[47]=d,e[48]=o,e[49]=R}else R=e[49];let L;e[53]!==R?(L=s.jsx("div",{className:"space-y-2",children:R}),e[53]=R,e[54]=L):L=e[54];let O;e[55]!==M||e[56]!==L?(O=s.jsxs("div",{className:"space-y-3",children:[M,L]}),e[55]=M,e[56]=L,e[57]=O):O=e[57];let V;e[58]!==r?(V=()=>r(!1),e[58]=r,e[59]=V):V=e[59];let $;e[60]!==o?($=o("settings.common.actions.cancel"),e[60]=o,e[61]=$):$=e[61];let B;e[62]!==V||e[63]!==$?(B=s.jsx(ve,{size:"sm",variant:"ghost",onClick:V,children:$}),e[62]=V,e[63]=$,e[64]=B):B=e[64];let H;e[65]!==d||e[66]!==a?(H=()=>a(d),e[65]=d,e[66]=a,e[67]=H):H=e[67];const _=!v;let se;e[68]!==o?(se=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=se):se=e[69];let oe;e[70]!==H||e[71]!==_||e[72]!==se?(oe=s.jsx(ve,{size:"sm",onClick:H,disabled:_,children:se}),e[70]=H,e[71]=_,e[72]=se,e[73]=oe):oe=e[73];let ae;e[74]!==B||e[75]!==oe?(ae=s.jsxs(Gs,{children:[B,oe]}),e[74]=B,e[75]=oe,e[76]=ae):ae=e[76];let ne;e[77]!==S||e[78]!==O||e[79]!==ae?(ne=s.jsxs(vs,{className:"max-w-2xl",children:[S,O,ae]}),e[77]=S,e[78]=O,e[79]=ae,e[80]=ne):ne=e[80];let xe;return e[81]!==r||e[82]!==n||e[83]!==ne?(xe=s.jsx(ws,{open:n,onOpenChange:r,children:ne}),e[81]=r,e[82]=n,e[83]=ne,e[84]=xe):xe=e[84],xe},Bd=[{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 zi(t,e){return t==="project"&&e==="agents"?"project-agents":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Jf(t){const e=Bd.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const Ik=t=>{const e=rt.c(124),{open:n,onOpenChange:r,item:i}=t,{t:a}=mt(),o=wa(Pk),c=wa(Ak),[d,p]=l.useState("user"),[m,u]=l.useState("opencode"),f=Es(Dk),b=Es(Tk),[h,v]=l.useState(null),[x,g]=l.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=[],e[0]=w):w=e[0];const[y,S]=l.useState(w),[D,j]=l.useState(null);let I,A;e[1]!==b||e[2]!==n?(I=()=>{n&&(p("user"),u("opencode"),v(b),g(!1),S([]),j(null))},A=[n,b],e[1]=b,e[2]=n,e[3]=I,e[4]=A):(I=e[3],A=e[4]),l.useEffect(I,A);let E;e[5]!==a?(E=De=>{switch(De){case"project-opencode":return a("settings.skills.location.option.projectOpencode.label");case"user-agents":return a("settings.skills.location.option.userAgents.label");case"project-agents":return a("settings.skills.location.option.projectAgents.label");default:return a("settings.skills.location.option.userOpencode.label")}},e[5]=a,e[6]=E):E=e[6];const P=E;let k;e[7]!==a?(k=De=>{switch(De){case"project-opencode":return a("settings.skills.location.option.projectOpencode.description");case"user-agents":return a("settings.skills.location.option.userAgents.description");case"project-agents":return a("settings.skills.location.option.projectAgents.description");default:return a("settings.skills.location.option.userOpencode.description")}},e[7]=a,e[8]=k):k=e[8];const N=k;let T;e:{if(f.length===0){T=null;break e}if(h&&f.some(De=>De.id===h)){T=h;break e}if(b&&f.some(De=>De.id===b)){T=b;break e}T=f[0]?.id??null}const M=T;let R;e:{if(d!=="project"){R=null;break e}const De=M;if(!De){R=null;break e}let ge;if(e[9]!==De||e[10]!==f){let de;e[12]!==De?(de=Ee=>Ee.id===De,e[12]=De,e[13]=de):de=e[13],ge=f.find(de),e[9]=De,e[10]=f,e[11]=ge}else ge=e[11];R=ge?.path??null}const L=R;let O;e[14]!==o||e[15]!==i||e[16]!==r||e[17]!==a?(O=async De=>{const ge={skillDir:De.skillDir};i?.clawdhub&&(ge.clawdhub={slug:i.clawdhub.slug,version:i.clawdhub.version});const U=await o({source:De.source,subpath:De.subpath,gitIdentityId:i?.gitIdentityId,scope:De.scope,targetSource:De.targetSource,selections:[ge],conflictPolicy:"prompt",conflictDecisions:De.conflictDecisions},{directory:De.directoryOverride??null});if(U.ok){q.success(a("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(U.error?.kind==="conflicts"){j({source:De.source,subpath:De.subpath,scope:De.scope,targetSource:De.targetSource,skillDir:De.skillDir,directoryOverride:De.directoryOverride??null}),S(U.error.conflicts),g(!0);return}if(U.error?.kind==="authRequired"){q.error(U.error.message||a("settings.skills.catalog.installSkill.toast.authRequired"));return}q.error(U.error?.message||a("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=o,e[15]=i,e[16]=r,e[17]=a,e[18]=O):O=e[18];const V=O;if(!i)return null;let $;e[19]!==a?($=a("settings.skills.catalog.installSkill.title"),e[19]=a,e[20]=$):$=e[20];let B;e[21]!==$?(B=s.jsx(js,{children:$}),e[21]=$,e[22]=B):B=e[22];let H;e[23]!==a?(H=a("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=a,e[24]=H):H=e[24];let _;e[25]!==i.skillName?(_=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=_):_=e[26];let se;e[27]!==a?(se=a("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=a,e[28]=se):se=e[28];let oe;e[29]!==H||e[30]!==_||e[31]!==se?(oe=s.jsxs(Rs,{children:[H," ",_," ",se]}),e[29]=H,e[30]=_,e[31]=se,e[32]=oe):oe=e[32];let ae;e[33]!==B||e[34]!==oe?(ae=s.jsxs(Ss,{children:[B,oe]}),e[33]=B,e[34]=oe,e[35]=ae):ae=e[35];let ne;e[36]!==a?(ne=a("settings.skills.catalog.installSkill.field.destination"),e[36]=a,e[37]=ne):ne=e[37];let xe;e[38]!==ne?(xe=s.jsx("span",{className:"typography-ui-label text-foreground",children:ne}),e[38]=ne,e[39]=xe):xe=e[39];let te;e[40]!==d||e[41]!==m?(te=zi(d,m),e[40]=d,e[41]=m,e[42]=te):te=e[42];let F;e[43]===Symbol.for("react.memo_cache_sentinel")?(F=De=>{const ge=Jf(De);p(ge.scope),u(ge.source==="agents"?"agents":"opencode")},e[43]=F):F=e[43];let z;e[44]!==d?(z=d==="user"?s.jsx(C,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=z):z=e[45];let Q;e[46]!==m?(Q=m==="agents"?s.jsx(C,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=Q):Q=e[47];let re;e[48]!==P||e[49]!==d||e[50]!==m?(re=P(zi(d,m)),e[48]=P,e[49]=d,e[50]=m,e[51]=re):re=e[51];let K;e[52]!==re?(K=s.jsx("span",{children:re}),e[52]=re,e[53]=K):K=e[53];let le;e[54]!==z||e[55]!==Q||e[56]!==K?(le=s.jsxs(hs,{className:"w-fit gap-1.5",children:[z,Q,K]}),e[54]=z,e[55]=Q,e[56]=K,e[57]=le):le=e[57];let Se;e[58]!==N||e[59]!==P?(Se=Bd.map(De=>s.jsx(Ft,{value:De.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[De.scope==="user"?s.jsx(C,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"folder",className:"h-3.5 w-3.5"}),De.source==="agents"?s.jsx(C,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:P(De.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:N(De.value)})]})},De.value)),e[58]=N,e[59]=P,e[60]=Se):Se=e[60];let ue;e[61]!==Se?(ue=s.jsx(fs,{align:"start",children:Se}),e[61]=Se,e[62]=ue):ue=e[62];let je;e[63]!==te||e[64]!==le||e[65]!==ue?(je=s.jsxs(ps,{value:te,onValueChange:F,children:[le,ue]}),e[63]=te,e[64]=le,e[65]=ue,e[66]=je):je=e[66];let W;e[67]!==xe||e[68]!==je?(W=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[xe,je]}),e[67]=xe,e[68]=je,e[69]=W):W=e[69];let me;e[70]!==f||e[71]!==M||e[72]!==d||e[73]!==a?(me=d==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.installSkill.field.project")}),f.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(ps,{value:M??"",onValueChange:De=>v(De),disabled:f.length===1,children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:a("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(fs,{align:"start",children:f.map(Mk)})]})]}),e[70]=f,e[71]=M,e[72]=d,e[73]=a,e[74]=me):me=e[74];let X;e[75]!==i.warnings?(X=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=X):X=e[76];let ce;e[77]!==W||e[78]!==me||e[79]!==X?(ce=s.jsxs("div",{className:"mt-2 space-y-3",children:[W,me,X]}),e[77]=W,e[78]=me,e[79]=X,e[80]=ce):ce=e[80];let ee;e[81]!==r?(ee=()=>r(!1),e[81]=r,e[82]=ee):ee=e[82];let Pe;e[83]!==a?(Pe=a("settings.common.actions.cancel"),e[83]=a,e[84]=Pe):Pe=e[84];let Ne;e[85]!==ee||e[86]!==Pe?(Ne=s.jsx(ve,{size:"sm",variant:"ghost",onClick:ee,children:Pe}),e[85]=ee,e[86]=Pe,e[87]=Ne):Ne=e[87];const Y=c||!i.installable||d==="project"&&!L;let he;e[88]!==L||e[89]!==V||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==d||e[94]!==m?(he=()=>{V({source:i.repoSource,subpath:i.repoSubpath,scope:d,targetSource:m,skillDir:i.skillDir,directoryOverride:L})},e[88]=L,e[89]=V,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=d,e[94]=m,e[95]=he):he=e[95];let ke;e[96]!==c||e[97]!==a?(ke=a(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=a,e[98]=ke):ke=e[98];let be;e[99]!==Y||e[100]!==he||e[101]!==ke?(be=s.jsx(ve,{size:"sm",disabled:Y,onClick:he,children:ke}),e[99]=Y,e[100]=he,e[101]=ke,e[102]=be):be=e[102];let fe;e[103]!==Ne||e[104]!==be?(fe=s.jsxs(Gs,{children:[Ne,be]}),e[103]=Ne,e[104]=be,e[105]=fe):fe=e[105];let Te;e[106]!==ae||e[107]!==ce||e[108]!==fe?(Te=s.jsxs(vs,{className:"max-w-md",children:[ae,ce,fe]}),e[106]=ae,e[107]=ce,e[108]=fe,e[109]=Te):Te=e[109];let Ve;e[110]!==r||e[111]!==n||e[112]!==Te?(Ve=s.jsx(ws,{open:n,onOpenChange:r,children:Te}),e[110]=r,e[111]=n,e[112]=Te,e[113]=Ve):Ve=e[113];let G;e[114]!==D||e[115]!==V?(G=De=>{D&&(V({source:D.source,subpath:D.subpath,scope:D.scope,targetSource:D.targetSource,skillDir:D.skillDir,conflictDecisions:De,directoryOverride:D.directoryOverride??null}),g(!1))},e[114]=D,e[115]=V,e[116]=G):G=e[116];let Ie;e[117]!==y||e[118]!==x||e[119]!==G?(Ie=s.jsx(Ck,{open:x,onOpenChange:g,conflicts:y,onConfirm:G}),e[117]=y,e[118]=x,e[119]=G,e[120]=Ie):Ie=e[120];let Oe;return e[121]!==Ve||e[122]!==Ie?(Oe=s.jsxs(s.Fragment,{children:[Ve,Ie]}),e[121]=Ve,e[122]=Ie,e[123]=Oe):Oe=e[123],Oe};function Pk(t){return t.installSkills}function Ak(t){return t.isInstalling}function Dk(t){return t.projects}function Tk(t){return t.activeProjectId}function Mk(t){return s.jsx(Ft,{value:t.id,children:t.label||t.path},t.id)}const Ek=async()=>{try{const t=lr()?.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}},Rk=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=mt(),{sources:i,itemsBySource:a,selectedSourceId:o,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:f,isLoadingMore:b,loadedSourceIds:h,clawdhubHasMoreBySource:v,lastCatalogError:x}=wa(mr(B=>({sources:B.sources,itemsBySource:B.itemsBySource,selectedSourceId:B.selectedSourceId,setSelectedSource:B.setSelectedSource,loadCatalog:B.loadCatalog,loadSource:B.loadSource,loadMoreClawdHub:B.loadMoreClawdHub,isLoadingCatalog:B.isLoadingCatalog,isLoadingSource:B.isLoadingSource,isLoadingMore:B.isLoadingMore,loadedSourceIds:B.loadedSourceIds,clawdhubHasMoreBySource:B.clawdhubHasMoreBySource,lastCatalogError:B.lastCatalogError}))),[g,w]=l.useState(""),[y,S]=l.useState(!1),[D,j]=l.useState(!1),[I,A]=l.useState(null),[E,P]=l.useState(!1),[k,N]=l.useState(!1);l.useEffect(()=>{d()},[d]),l.useEffect(()=>{o&&(h[o]||p(o))},[o,h,p]);const T=l.useMemo(()=>o?a[o]||[]:[],[a,o]),M=l.useMemo(()=>{const B=g.trim().toLowerCase();return B?T.filter(H=>{const _=H.skillName.toLowerCase(),se=(H.description||"").toLowerCase(),oe=(H.frontmatterName||"").toLowerCase();return _.includes(B)||se.includes(B)||oe.includes(B)}):T},[T,g]),R=l.useMemo(()=>i.find(B=>B.id===o)||null,[i,o]),L=!!(o&&o.startsWith("custom:")),O=R?.source==="clawdhub:registry"||R?.sourceType==="clawdhub",V=!!(o&&(v[o]??!0)),$=async()=>{if(!(!o||!L)){P(!0);try{const B=await Ek(),_=(Array.isArray(B?.skillCatalogs)?B?.skillCatalogs:[]).filter(se=>se.id!==o);await Ps({skillCatalogs:_}),await d({refresh:!0}),N(!1)}finally{P(!1)}}};return s.jsx(As,{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(Tr,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:B=>e(B),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:B=>c(B),children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder")})}),s.jsx(fs,{align:"start",children:i.map(B=>s.jsx(Ft,{value:B.id,children:B.label},B.id))})]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{o?p(o,{refresh:!0}):d({refresh:!0})},disabled:u||f,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(C,{name:"refresh",className:pe("h-3.5 w-3.5",(u||f)&&"animate-spin")})}),L&&s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>N(!0),disabled:E,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(ve,{size:"xs",className:"!font-normal gap-1",onClick:()=>S(!0),children:[s.jsx(C,{name:"add",className:"h-3.5 w-3.5"})," ",r("settings.skills.catalog.page.actions.addCatalog")]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"relative",children:[s.jsx(C,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Ut,{value:g,onChange:B=>w(B.target.value),placeholder:r("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:u?r("settings.skills.catalog.page.loading.catalog"):r("settings.skills.catalog.page.foundCount",{count:M.length})})]})]})]}),x&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:r("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x.message})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("section",{className:"px-2 pb-2 pt-0",children:M.length===0&&!f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:r("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.catalog.page.empty.noSkillsDescription")})]}):f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(C,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:r("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:M.map(B=>{const H=B.installed?.isInstalled,_=B.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:B.skillName}),H&&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:_||r("settings.skills.catalog.page.badge.unknown")})}),!B.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")})]}),B.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:B.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),B.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[B.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:B.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(C,{name:"download",className:"h-3 w-3"}),B.clawdhub.downloads?.toLocaleString()??0]}),(B.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(C,{name:"star",className:"h-3 w-3"}),B.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",B.clawdhub.version]})]}),B.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:B.warnings.join(" · ")}):null]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!B.installable,onClick:()=>{A(B),j(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${B.sourceId}:${B.skillDir}`)})})}),O&&V&&!f&&M.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:b,children:r(b?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),s.jsx(yk,{open:y,onOpenChange:S}),s.jsx(Ik,{open:D,onOpenChange:j,item:I}),s.jsx(ws,{open:k,onOpenChange:B=>{E||N(B)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Rs,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Gs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>N(!1),disabled:E,children:r("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:E,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},Fk=()=>{const t=rt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Rk,{mode:"external",onModeChange:Ok,showModeTabs:!1}),t[0]=e):e=t[0],e},Lk=()=>{const{t}=mt(),{selectedSkillName:e,getSkillByName:n,getSkillDetail:r,createSkill:i,updateSkill:a,skills:o,skillDraft:c,setSkillDraft:d,setSelectedSkill:p}=ea(mr(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),f=!!(e&&!m&&!c);l.useEffect(()=>{f&&p(null)},[f,p]);const[b,h]=l.useState(""),[v,x]=l.useState("user"),[g,w]=l.useState("opencode"),[y,S]=l.useState(""),[D,j]=l.useState(""),[I,A]=l.useState([]),[E,P]=l.useState([]),[k,N]=l.useState(!1),[T,M]=l.useState(!1),[R,L]=l.useState(""),[O,V]=l.useState(""),[$,B]=l.useState(!1),[H,_]=l.useState(""),[se,oe]=l.useState(""),[ae,ne]=l.useState(null),[xe,te]=l.useState(!1),[F,z]=l.useState(""),[Q,re]=l.useState(null),[K,le]=l.useState(!1),Se=u?b.trim()!==""||y.trim()!==""||D.trim()!==""||E.length>0:y!==R||D!==O,ue=ae?se!==F:H.trim()!=="",je=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]),W=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)h(c.name||""),x(c.scope||"user"),w(c.source==="agents"?"agents":"opencode"),S(c.description||""),j(c.instructions||""),L(""),V(""),A([]),P(c.pendingFiles||[]);else if(e&&m){M(!0);try{const he=await r(e);if(he){const ke=he.sources.md;S(ke.description||""),j(ke.instructions||""),L(ke.description||""),V(ke.instructions||""),A(ke.supportingFiles||[])}}catch(he){console.error("Failed to load skill details:",he)}finally{M(!1)}}})()},[m,u,e,o,c,r]);const me=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(!y.trim()){q.error(t("settings.skills.page.toast.descriptionRequired"));return}if(u&&o.some(he=>he.name===Y)){q.error(t("settings.skills.page.toast.skillExists"));return}N(!0);try{const he={name:Y,description:y.trim(),instructions:D.trim()||void 0,scope:u?v:void 0,source:u?g:void 0,supportingFiles:u&&E.length>0?E:void 0};let ke;u?(ke=await i(he),ke&&(d(null),P([]),p(Y))):(ke=await a(Y,he),ke&&(L(y.trim()),V(D.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(he){console.error("Error saving skill:",he),q.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{N(!1)}},X=()=>{ne(null),_(""),oe(""),z(""),B(!0)},ce=async Y=>{if(ne(Y),_(Y),u){const ke=E.find(be=>be.path===Y)?.content||"";oe(ke),z(ke),B(!0);return}if(e){te(!0),B(!0);try{const{readSupportingFile:he}=ea.getState(),ke=await he(e,Y);oe(ke||""),z(ke||"")}catch{q.error(t("settings.skills.page.toast.loadFileContentFailed")),oe(""),z("")}finally{te(!1)}}},ee=async()=>{if(!H.trim()){q.error(t("settings.skills.page.toast.fileNameRequired"));return}const Y=H.trim(),he=ae!==null;if(u){if(he)P(fe=>fe.map(Te=>Te.path===ae?{path:Y,content:se}:Te)),q.success(t("settings.skills.page.toast.fileUpdated",{path:Y}));else{if(E.some(fe=>fe.path===Y)){q.error(t("settings.skills.page.toast.fileExists"));return}P(fe=>[...fe,{path:Y,content:se}]),q.success(t("settings.skills.page.toast.fileAdded",{path:Y}))}B(!1),ne(null);return}if(!e){q.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:ke}=ea.getState();if(await ke(e,Y,se)){q.success(he?t("settings.skills.page.toast.fileUpdated",{path:Y}):t("settings.skills.page.toast.fileCreated",{path:Y})),B(!1),ne(null);const fe=await r(e);fe&&A(fe.sources.md.supportingFiles||[])}else q.error(t(he?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Pe=Y=>{if(u){P(he=>he.filter(ke=>ke.path!==Y)),q.success(t("settings.skills.page.toast.fileRemoved",{path:Y}));return}e&&re(Y)},Ne=async()=>{if(!Q||!e)return;le(!0);const{deleteSupportingFile:Y}=ea.getState();if(await Y(e,Q)){q.success(t("settings.skills.page.toast.fileDeleted",{path:Q}));const ke=await r(e);ke&&A(ke.sources.md.supportingFiles||[]),re(null)}else q.error(t("settings.skills.page.toast.deleteFileFailed"));le(!1)};return!e&&!c||f?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(C,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):T?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(As,{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:je(zi(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(Ut,{value:b,onChange:Y=>h(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:zi(v,g),onValueChange:Y=>{const he=Jf(Y);x(he.scope),w(he.source==="agents"?"agents":"opencode")},children:[s.jsxs(hs,{className:"w-fit gap-1.5",children:[v==="user"?s.jsx(C,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"folder",className:"h-3.5 w-3.5"}),g==="agents"?s.jsx(C,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:je(zi(v,g))})]}),s.jsx(fs,{align:"start",children:Bd.map(Y=>s.jsx(Ft,{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(C,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"folder",className:"h-3.5 w-3.5"}),Y.source==="agents"?s.jsx(C,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:je(Y.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:W(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(vn,{value:y,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(vn,{value:D,onChange:Y=>j(Y.target.value),placeholder:t("settings.skills.page.field.instructionsPlaceholder"),className:"min-h-[220px] max-h-[60vh] font-mono typography-meta"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.supportingFiles")}),s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:X,children:[s.jsx(C,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:(()=>{const Y=u?E:I;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(he=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>ce(he.path),children:[s.jsx(C,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:he.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(ve,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:ke=>{ke.stopPropagation(),Pe(he.path)},children:s.jsx(C,{name:"delete-bin",className:"h-3 w-3"})})]},he.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ve,{onClick:me,disabled:k||!Se,size:"xs",className:"!font-normal",children:t(k?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(ws,{open:Q!==null,onOpenChange:Y=>{!Y&&!K&&re(null)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Rs,{children:t("settings.skills.page.deleteFileDialog.description",{path:Q??""})})]}),s.jsxs(Gs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>re(null),disabled:K,children:t("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",variant:"destructive",onClick:Ne,disabled:K,children:t("settings.common.actions.delete")})]})]})}),s.jsx(ws,{open:$,onOpenChange:Y=>{B(Y),Y||ne(null)},children:s.jsxs(vs,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Ss,{className:"flex-shrink-0",children:[s.jsx(js,{children:t(ae?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Rs,{children:t(ae?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),xe?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(Ut,{value:H,onChange:Y=>_(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:ae!==null}),!ae&&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(vn,{value:se,onChange:Y=>oe(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(Gs,{className:"mt-4",children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>{B(!1),ne(null)},children:t("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:ee,disabled:xe||!ue,children:t(ae?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},qm=t=>{const e=rt.c(2),{view:n}=t,r=n===void 0?"installed":n;let i;return e[0]!==r?(i=r==="catalog"?s.jsx(Fk,{}):s.jsx(Lk,{}),e[0]=r,e[1]=i):i=e[1],i};function Ok(){}const Qf=t=>{const e=rt.c(26),{header:n,footer:r,children:i,className:a,variant:o}=t,c=o===void 0?"sidebar":o,d=pn(),p=l.useRef(null),[m,u]=l.useState(!1),[f,b]=l.useState(!1),h=c==="background"||d?"bg-background":"bg-sidebar",v=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const N=p.current;if(!N){u(!1),b(!1);return}if(!(N.scrollHeight>N.clientHeight+1)){u(!1),b(!1);return}u(N.scrollTop>1),b(N.scrollTop+N.clientHeight<N.scrollHeight-1)},e[0]=x):x=e[0];const g=x;let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{g()},e[1]=w):w=e[1];let y;e[2]!==i?(y=[i,g],e[2]=i,e[3]=y):y=e[3],l.useEffect(w,y);let S,D;e[4]===Symbol.for("react.memo_cache_sentinel")?(S=()=>{const N=p.current;if(!N)return;const T=()=>g();return N.addEventListener("scroll",T,{passive:!0}),()=>N.removeEventListener("scroll",T)},D=[g],e[4]=S,e[5]=D):(S=e[4],D=e[5]),l.useEffect(S,D);let j;e[6]!==h||e[7]!==a?(j=pe("flex h-full flex-col",h,a),e[6]=h,e[7]=a,e[8]=j):j=e[8];let I;e[9]!==i?(I=s.jsx(As,{ref:p,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=I):I=e[10];let A;e[11]!==v||e[12]!==m?(A=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${v} 0%, transparent 100%)`}}),e[11]=v,e[12]=m,e[13]=A):A=e[13];let E;e[14]!==v||e[15]!==f?(E=f&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${v} 0%, transparent 100%)`}}),e[14]=v,e[15]=f,e[16]=E):E=e[16];let P;e[17]!==E||e[18]!==I||e[19]!==A?(P=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[I,A,E]}),e[17]=E,e[18]=I,e[19]=A,e[20]=P):P=e[20];let k;return e[21]!==r||e[22]!==n||e[23]!==P||e[24]!==j?(k=s.jsxs("div",{className:j,children:[n,P,r]}),e[21]=r,e[22]=n,e[23]=P,e[24]=j,e[25]=k):k=e[25],k},Yf=t=>{const e=rt.c(23),{title:n,metadata:r,selected:i,onSelect:a,icon:o,actions:c,className:d}=t,p=i===void 0?!1:i,m=c&&c.length>0,u=p?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==d||e[1]!==u?(f=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]=f):f=e[2];let b;e[3]!==n?(b=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=b):b=e[4];let h;e[5]!==o||e[6]!==b?(h=s.jsxs("div",{className:"flex items-center gap-1.5",children:[o,b]}),e[5]=o,e[6]=b,e[7]=h):h=e[7];let v;e[8]!==r?(v=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=v):v=e[9];let x;e[10]!==a||e[11]!==h||e[12]!==v?(x=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:[h,v]}),e[10]=a,e[11]=h,e[12]=v,e[13]=x):x=e[13];let g;e[14]!==c||e[15]!==m?(g=m&&s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(C,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx($s,{align:"end",className:"w-fit min-w-20",children:c.map($k)})]}),e[14]=c,e[15]=m,e[16]=g):g=e[16];let w;e[17]!==x||e[18]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,g]}),e[17]=x,e[18]=g,e[19]=w):w=e[19];let y;return e[20]!==f||e[21]!==w?(y=s.jsx("div",{className:f,children:w}),e[20]=f,e[21]=w,e[22]=y):y=e[22],y};function $k(t){const e=t.icon;return s.jsxs(zt,{onClick:n=>{n.stopPropagation(),t.onClick()},className:pe(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(C,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Bk=t=>{const e=rt.c(41),{onItemSelect:n}=t,{t:r}=mt(),i=Es(_k),a=Me(Vk),o=Me(zk),{currentTheme:c}=Nr();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=pn(),e[1]=u):u=e[1];const f=u,b=Uk;let h,v;e[2]!==i||e[3]!==a||e[4]!==o?(h=()=>{if(i.length===0){a!==null&&o(null);return}a&&i.some(P=>P.id===a)||o(i[0].id)},v=[i,a,o],e[2]=i,e[3]=a,e[4]=o,e[5]=h,e[6]=v):(h=e[5],v=e[6]),l.useEffect(h,v);let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=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 y;e[12]!==i.length||e[13]!==r?(y=r("settings.projects.sidebar.total",{count:i.length}),e[12]=i.length,e[13]=r,e[14]=y):y=e[14];let S;e[15]!==y?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:y}),e[15]=y,e[16]=S):S=e[16];let D;e[17]!==r?(D=!f&&s.jsx(ve,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:b,"aria-label":r("settings.projects.sidebar.actions.addProject"),children:s.jsx(C,{name:"add",className:"size-4"})}),e[17]=r,e[18]=D):D=e[18];let j;e[19]!==D||e[20]!==S?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,D]}),e[19]=D,e[20]=S,e[21]=j):j=e[21];let I;e[22]!==j||e[23]!==w?(I=s.jsxs("div",{className:x,children:[w,j]}),e[22]=j,e[23]=w,e[24]=I):I=e[24];let A;if(e[25]!==p||e[26]!==c||e[27]!==n||e[28]!==i||e[29]!==a||e[30]!==o){let P;e[32]!==p||e[33]!==c||e[34]!==n||e[35]!==a||e[36]!==o?(P=k=>{const N=k.id===a,T=k.icon?kl[k.icon]:null,M=`${k.id}:${k.iconImage?.updatedAt??0}`,R=p.has(M)?null:no(k,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),L=k.color?ro[k.color]??null:null,O=R?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:k.iconBackground?{backgroundColor:k.iconBackground}:void 0,children:s.jsx("img",{src:R,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m(V=>{if(V.has(M))return V;const $=new Set(V);return $.add(M),$})}})}):T?s.jsx(C,{name:T,className:pe("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:L?{color:L}:void 0}):s.jsx(C,{name:"folder",className:pe("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:L?{color:L}:void 0});return s.jsx(Yf,{title:k.label||k.path,icon:O,selected:N,onSelect:()=>{o(k.id),n?.()}},k.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=a,e[36]=o,e[37]=P):P=e[37],A=i.map(P),e[25]=p,e[26]=c,e[27]=n,e[28]=i,e[29]=a,e[30]=o,e[31]=A}else A=e[31];let E;return e[38]!==I||e[39]!==A?(E=s.jsx(Qf,{variant:"background",header:I,children:A}),e[38]=I,e[39]=A,e[40]=E):E=e[40],E};function _k(t){return t.projects}function Vk(t){return t.settingsProjectsSelectedId}function zk(t){return t.setSettingsProjectsSelectedId}function Uk(){vr.requestDirectoryDialog()}const Wk=({projectRef:t=null})=>{const{t:e}=mt(),{isMobile:n,isTablet:r}=rn(),i=n||r,a=Es(T=>T.getActiveProject()),o=t?.path??a?.path??null,c=Ht(T=>T.getWorktreeMetadata),d=to(),p=Ws(T=>T.homeDirectory),[m,u]=l.useState([]),[f,b]=l.useState(!1),[h,v]=l.useState(null),[x,g]=l.useState([]),[w,y]=l.useState(!1),S=l.useMemo(()=>t?.id&&t?.path?{id:t.id,path:t.path}:!a?.id||!o?null:{id:a.id,path:o},[a?.id,o,t?.id,t?.path]),D=l.useCallback(async()=>{if(!(!S||h===!1))try{const T=await Oc(S);g(T)}catch{}},[S,h]);l.useEffect(()=>{if(!o)return;let T=!1;return v(null),(async()=>{try{const M=await $h(o);if(T)return;v(M)}catch{}})(),()=>{T=!0}},[o]),l.useEffect(()=>{if(!S){g([]),y(!1);return}if(h===!1){g([]),y(!1);return}let T=!1;return y(!0),g([]),(async()=>{try{const M=await Oc(S);if(T)return;g(M)}catch{}finally{T||y(!1)}})(),()=>{T=!0}},[S,h]),l.useEffect(()=>{if(!S)return;let T=!1;return b(!0),(async()=>{try{const M=await Pd(S);T||u(M.length>0?M:[""])}catch{T||u([""])}finally{T||b(!1)}})(),()=>{T=!0}},[S]);const j=l.useCallback((T,M)=>{u(R=>{const L=[...R];return L[T]=M,L})},[]),I=l.useCallback(()=>{u(T=>[...T,""])},[]),A=l.useCallback(async T=>{if(!S)return;const M=T.filter(R=>R.trim().length>0);await Bh(S,M)},[S]),E=l.useCallback(T=>{u(M=>{const R=M.filter((L,O)=>O!==T);return A(R),R.length>0?R:[""]})},[A]),P=l.useCallback(()=>{A(m)},[A,m]),k=l.useCallback(T=>{const M=_=>_.replace(/\\/g,"/").replace(/\/+$/,""),R=M(T.path),L=d.filter(_=>{const se=c(_.id);if(se?.path&&M(se.path)===R)return!0;const oe=_.directory;return!!(oe&&M(oe)===R)}),O=new Set(L.map(_=>_.id)),V=_=>{const se=d.filter(ae=>{const ne=ae.parentID;return ne&&_.has(ne)});if(se.length===0)return[];const oe=new Set(se.map(ae=>ae.id));return[...se,...V(oe)]},$=V(O),B=new Set,H=[...L,...$].filter(_=>B.has(_.id)?!1:(B.add(_.id),!0));vr.requestDelete({sessions:H,mode:"worktree",worktree:T})},[d,c]),N=l.useMemo(()=>d.map(T=>T.id).join(","),[d]);return l.useEffect(()=>{h&&o&&D()},[N,h,o,D]),o?h===!1?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")}):s.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.setup.title")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Pt,{sideOffset:8,className:"max-w-xs",children:[e("settings.openchamber.worktrees.setup.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs bg-sidebar-accent/50 px-1 rounded",children:"$ROOT_PROJECT_PATH"})," ",e("settings.openchamber.worktrees.setup.tooltipSuffix")]})]})]})}),f?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.setup.loading")}):s.jsxs("div",{className:"space-y-2 px-1",children:[m.map((T,M)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Ut,{value:T,onChange:R=>j(M,R.target.value),onBlur:P,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 w-[30rem] max-w-full font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{E(M)},className:"flex-shrink-0 flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:s.jsx(C,{name:"close",className:"h-4 w-4"})})]},M)),s.jsxs(ve,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:I,children:[s.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),e("settings.openchamber.worktrees.setup.addCommand")]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-border/40 pt-4",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.list.title")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]})]})}),w?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.list.loading")}):x.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.openchamber.worktrees.list.empty")}):s.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:x.map(T=>s.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("p",{className:"typography-meta text-foreground truncate min-w-0",children:T.label||T.branch||e("settings.openchamber.worktrees.list.detachedHead")}),s.jsx("span",{className:"typography-micro text-muted-foreground/60 px-1.5 py-[1px] rounded bg-sidebar-accent/40 flex-shrink-0 self-center leading-none",children:"OpenCode"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground/60 truncate",children:Ki(T.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>k(T),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",i?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:T.branch||T.label||T.path}),children:s.jsx(C,{name:"delete-bin",className:"h-4 w-4"})})]},T.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},Kk=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,Hk=()=>({id:Kk(),name:"",command:"",icon:"play"}),Gk=({projectRef:t})=>{const{t:e}=mt(),n=l.useMemo(()=>wn(),[]),r=Qs(I=>I.instances),i=Qs(I=>I.load),[a,o]=l.useState([]),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState({});l.useEffect(()=>{n&&i().catch(()=>{})},[n,i]),l.useEffect(()=>{let I=!1;return d(!0),(async()=>{try{const A=await Lc(t);if(I)return;o(A.actions),f(JSON.stringify({actions:A.actions}))}catch{if(I)return;o([]),f(JSON.stringify({actions:[]}))}finally{I||d(!1)}})(),()=>{I=!0}},[t]);const v=l.useMemo(()=>n?df(r):[],[r,n]),x=l.useMemo(()=>a.some(A=>A.name.trim().length===0||A.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[a,e]),g=l.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:a}),[a,u]),w=l.useCallback(()=>{const I=Hk();o(A=>[...A,I]),h(A=>({...A,[I.id]:!0}))},[]),y=l.useCallback(I=>{o(A=>A.filter(E=>E.id!==I)),h(A=>{const E={...A};return delete E[I],E})},[]),S=l.useCallback((I,A)=>{o(E=>E.map(P=>P.id===I?A(P):P))},[]),D=l.useCallback(async()=>{if(x){q.error(x);return}m(!0);try{if(!await mb(t,{actions:a,primaryActionId:null})){q.error(e("settings.projects.actions.toast.saveFailed"));return}f(JSON.stringify({actions:a})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Wc,{detail:{projectId:t.id}})),q.success(e("settings.projects.actions.toast.saved"))}catch{q.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[a,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(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:w,children:[s.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]})]}),s.jsxs("section",{className:"pb-2 pt-0 space-y-2",children:[c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):a.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:a.map(I=>{const A=I.icon||"play",E=_o[A]||"play",P=b[I.id]??!1,k=I.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(cr,{open:P,onOpenChange:N=>{h(T=>({...T,[I.id]:N}))},className:pe("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(jr,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[P?s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(C,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx(C,{name:E,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k})})})]}),s.jsx(ve,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>y(I.id),children:s.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(dr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-2 pb-6 pl-3 pr-3",children:[s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":e("settings.projects.actions.field.selectIconAria"),children:s.jsx(C,{name:E,className:"h-4 w-4"})})}),s.jsx($s,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:lf.map(N=>{const T=N.Icon,M=(I.icon||"play")===N.key;return s.jsx("button",{type:"button",onClick:()=>S(I.id,R=>({...R,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)]",M&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:N.label}),children:s.jsx(C,{name:T,className:"h-4 w-4"})},N.key)})})})]}),s.jsx(Ut,{value:I.name,onChange:N=>S(I.id,T=>({...T,name:N.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),s.jsxs("div",{className:"py-1",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),s.jsx(vn,{value:I.command,onChange:N=>S(I.id,T=>({...T,command:N.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] font-mono text-xs"})]}),s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":I.autoOpenUrl===!0,onClick:()=>S(I.id,N=>({...N,...N.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),S(I.id,T=>({...T,...T.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(bs,{checked:I.autoOpenUrl===!0,onChange:N=>S(I.id,T=>({...T,...N?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:k})}),s.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),I.autoOpenUrl===!0?s.jsxs("div",{className:"mt-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ut,{value:I.openUrl||"",onChange:N=>S(I.id,T=>({...T,openUrl:N.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]})]}),n?s.jsxs("div",{className:"mt-2",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),v.length>0?s.jsxs(ps,{value:I.desktopOpenSshForward&&v.some(N=>N.id===I.desktopOpenSshForward)?I.desktopOpenSshForward:"__none__",onValueChange:N=>{S(I.id,T=>({...T,...N==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:N}}))},children:[s.jsx(hs,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(ys,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),v.map(N=>s.jsx(Ft,{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]})]})})]},I.id)})}),s.jsxs("div",{className:"pt-3",children:[x?s.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:x}):null,s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",onClick:D,disabled:!j,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},qk=()=>{const t=rt.c(201),{t:e}=mt(),n=Es(Jk),r=Es(Qk),i=Es(Yk),a=Es(Xk),o=Es(Zk),c=Me(e3),d=Me(t3),{currentTheme:p}=Nr();let m;e:{if(!c){m=null;break e}let wt;t[0]!==n||t[1]!==c?(wt=n.find(Jt=>Jt.id===c)??null,t[0]=n,t[1]=c,t[2]=wt):wt=t[2],m=wt}const u=m;let f,b;t[3]!==n||t[4]!==c||t[5]!==d?(f=()=>{if(n.length===0){d(null);return}c&&n.some(wt=>wt.id===c)||d(n[0].id)},b=[n,c,d],t[3]=n,t[4]=c,t[5]=d,t[6]=f,t[7]=b):(f=t[6],b=t[7]),l.useEffect(f,b);const[h,v]=l.useState(""),[x,g]=l.useState(null),[w,y]=l.useState(null),[S,D]=l.useState(null),[j,I]=l.useState(!1),[A,E]=l.useState(!1),[P,k]=l.useState(!1),[N,T]=l.useState(!1),[M,R]=l.useState(null),[L,O]=l.useState(null),[V,$]=l.useState(!1),B=l.useRef(null);let H;t[8]===Symbol.for("react.memo_cache_sentinel")?(H=()=>{R(null),O(s3)},t[8]=H):H=t[8];const _=H;let se;e:{if(!u){se=null;break e}let wt;t[9]!==u.id||t[10]!==u.path?(wt={id:u.id,path:u.path},t[9]=u.id,t[10]=u.path,t[11]=wt):wt=t[11],se=wt}const oe=se;let ae,ne;t[12]!==u?(ae=()=>{if(!u){v(""),g(null),y(null),D(null);return}v(u.label??""),g(u.icon??null),y(u.color??null),D(u.iconBackground??null),T(!1),_(),$(!1)},ne=[u,_],t[12]=u,t[13]=ae,t[14]=ne):(ae=t[13],ne=t[14]),l.useEffect(ae,ne);let xe,te;t[15]===Symbol.for("react.memo_cache_sentinel")?(xe=()=>()=>{_()},te=[_],t[15]=xe,t[16]=te):(xe=t[15],te=t[16]),l.useEffect(xe,te);let F;t[17]!==w||t[18]!==x||t[19]!==S||t[20]!==h||t[21]!==N||t[22]!==M||t[23]!==u?(F=!!u&&(h.trim()!==(u?.label??"").trim()||x!==(u?.icon??null)||w!==(u?.color??null)||S!==(u?.iconBackground??null)||N||!!M),t[17]=w,t[18]=x,t[19]=S,t[20]=h,t[21]=N,t[22]=M,t[23]=u,t[24]=F):F=t[24];const z=F;let Q;t[25]!==w||t[26]!==x||t[27]!==S||t[28]!==h||t[29]!==N||t[30]!==M||t[31]!==a||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==i?(Q=async()=>{if(!u)return;if(M){I(!0);const Jt=await i(u.id,M);if(I(!1),!Jt.ok){q.error(Jt.error||e("settings.projects.page.toast.uploadIconFailed"));return}q.success(e("settings.projects.page.toast.iconUpdated")),_(),T(!1)}const wt=N&&!!u.iconImage;if(wt){E(!0);const Jt=await a(u.id);if(E(!1),!Jt.ok){q.error(Jt.error||e("settings.projects.page.toast.removeIconFailed"));return}q.success(e("settings.projects.page.toast.iconRemoved")),T(!1),D(null)}r(u.id,{label:h.trim(),icon:x,color:w,iconBackground:wt?null:S})},t[25]=w,t[26]=x,t[27]=S,t[28]=h,t[29]=N,t[30]=M,t[31]=a,t[32]=u,t[33]=e,t[34]=r,t[35]=i,t[36]=Q):Q=t[36];const re=Q,K=w?ro[w]??null:null,le=!!u?.iconImage,Se=!!(M&&L),ue=u?.iconImage?.source==="custom",je=le&&!N||Se,W=je;let me;t[37]!==p||t[38]!==Se||t[39]!==le||t[40]!==N||t[41]!==L||t[42]!==V||t[43]!==u?(me=V?null:Se?L:u&&le&&!N?no(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=Se,t[39]=le,t[40]=N,t[41]=L,t[42]=V,t[43]=u,t[44]=me):me=t[44];const X=me;let ce;t[45]!==j||t[46]!==u?(ce=wt=>{!u||!wt||j||(T(!1),$(!1),R(wt),O(Jt=>(Jt&&URL.revokeObjectURL(Jt),URL.createObjectURL(wt))))},t[45]=j,t[46]=u,t[47]=ce):ce=t[47];const ee=ce;let Pe;t[48]!==Se||t[49]!==W||t[50]!==le||t[51]!==A||t[52]!==u?(Pe=()=>{!u||!W||A||(Se&&_(),T(!!le),$(!1))},t[48]=Se,t[49]=W,t[50]=le,t[51]=A,t[52]=u,t[53]=Pe):Pe=t[53];const Ne=Pe;let Y;t[54]!==o||t[55]!==P||t[56]!==u||t[57]!==e?(Y=async()=>{!u||P||(_(),T(!1),$(!1),k(!0),o(u.id).then(wt=>{if(!wt.ok){q.error(wt.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(wt.skipped){q.success(e("settings.projects.page.toast.customIconAlreadySet"));return}q.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{k(!1)}))},t[54]=o,t[55]=P,t[56]=u,t[57]=e,t[58]=Y):Y=t[58];const he=Y;if(!u){let wt;t[59]!==e?(wt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=wt):wt=t[60];let Jt;return t[61]!==wt?(Jt=s.jsx(As,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:wt})})}),t[61]=wt,t[62]=Jt):Jt=t[62],Jt}let ke;t[63]!==u.label||t[64]!==e?(ke=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=ke):ke=t[65];let be;t[66]!==ke?(be=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ke}),t[66]=ke,t[67]=be):be=t[67];let fe;t[68]!==u.path?(fe=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=fe):fe=t[69];let Te;t[70]!==be||t[71]!==fe?(Te=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[be,fe]})}),t[70]=be,t[71]=fe,t[72]=Te):Te=t[72];let Ve;t[73]!==e?(Ve=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=Ve):Ve=t[74];let G;t[75]!==Ve?(G=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Ve})}),t[75]=Ve,t[76]=G):G=t[76];let Ie;t[77]===Symbol.for("react.memo_cache_sentinel")?(Ie=wt=>v(wt.target.value),t[77]=Ie):Ie=t[77];let Oe;t[78]!==e?(Oe=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=Oe):Oe=t[79];let De;t[80]!==h||t[81]!==Oe?(De=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Ut,{value:h,onChange:Ie,placeholder:Oe,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=h,t[81]=Oe,t[82]=De):De=t[82];let ge;t[83]!==G||t[84]!==De?(ge=s.jsxs("div",{className:"py-1.5",children:[G,De]}),t[83]=G,t[84]=De,t[85]=ge):ge=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 Ee;t[90]===Symbol.for("react.memo_cache_sentinel")?(Ee=()=>y(null),t[90]=Ee):Ee=t[90];const _e=w===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let Z;t[91]!==_e?(Z=pe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",_e),t[91]=_e,t[92]=Z):Z=t[92];let ie;t[93]!==e?(ie=e("settings.projects.page.field.none"),t[93]=e,t[94]=ie):ie=t[94];let Ce;t[95]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(C,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[95]=Ce):Ce=t[95];let He;t[96]!==Z||t[97]!==ie?(He=s.jsx("button",{type:"button",onClick:Ee,className:Z,title:ie,children:Ce}),t[96]=Z,t[97]=ie,t[98]=He):He=t[98];let Ge;t[99]!==w?(Ge=pb.map(wt=>s.jsx("button",{type:"button",onClick:()=>y(wt.key),className:pe("h-7 w-7 rounded-md border transition-colors",w===wt.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:wt.cssVar},title:wt.label},wt.key)),t[99]=w,t[100]=Ge):Ge=t[100];let Xe;t[101]!==He||t[102]!==Ge?(Xe=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[He,Ge]}),t[101]=He,t[102]=Ge,t[103]=Xe):Xe=t[103];let we;t[104]!==de||t[105]!==Xe?(we=s.jsxs("div",{className:"py-1.5",children:[de,Xe]}),t[104]=de,t[105]=Xe,t[106]=we):we=t[106];let tt;t[107]!==e?(tt=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=tt):tt=t[108];let st;t[109]!==tt?(st=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:tt})}),t[109]=tt,t[110]=st):st=t[110];let qe;t[111]!==ee?(qe=s.jsx("input",{ref:B,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:wt=>{const Jt=wt.target.files?.[0]??null;ee(Jt),wt.currentTarget.value=""}}),t[111]=ee,t[112]=qe):qe=t[112];let it;t[113]===Symbol.for("react.memo_cache_sentinel")?(it=()=>g(null),t[113]=it):it=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 Je;t[116]!==e?(Je=e("settings.projects.page.field.none"),t[116]=e,t[117]=Je):Je=t[117];let Be;t[118]===Symbol.for("react.memo_cache_sentinel")?(Be=s.jsx(C,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[118]=Be):Be=t[118];let ze;t[119]!==ye||t[120]!==Je?(ze=s.jsx("button",{type:"button",onClick:it,className:ye,title:Je,children:Be}),t[119]=ye,t[120]=Je,t[121]=ze):ze=t[121];let nt;t[122]!==K||t[123]!==x?(nt=hb.map(wt=>{const Jt=wt.Icon;return s.jsx("button",{type:"button",onClick:()=>g(wt.key),className:pe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",x===wt.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:wt.label,children:s.jsx(C,{name:Jt,className:"w-4 h-4",style:K&&x===wt.key?{color:K}:void 0})},wt.key)}),t[122]=K,t[123]=x,t[124]=nt):nt=t[124];let Ye;t[125]!==ze||t[126]!==nt?(Ye=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[ze,nt]}),t[125]=ze,t[126]=nt,t[127]=Ye):Ye=t[127];let Ue;t[128]!==je||t[129]!==S||t[130]!==X||t[131]!==e?(Ue=je&&X&&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:X,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>$(!0)})})})]}),t[128]=je,t[129]=S,t[130]=X,t[131]=e,t[132]=Ue):Ue=t[132];let vt;t[133]!==je||t[134]!==S||t[135]!==e?(vt=je&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:S??"#000000",onChange:wt=>D(wt.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":e("settings.projects.page.field.projectIconBackgroundAria")}),s.jsx(Ut,{value:S??"",onChange:wt=>D(wt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(ve,{type:"button",size:"xs",variant:"outline",onClick:()=>D(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!S,children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]}),t[133]=je,t[134]=S,t[135]=e,t[136]=vt):vt=t[136];let Et;t[137]!==he||t[138]!==ue||t[139]!==P||t[140]!==j||t[141]!==e?(Et=!ue&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{size:"xs",className:"h-6 !font-normal",onClick:()=>B.current?.click(),disabled:j,children:e(j?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(ve,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{he()},disabled:P,children:e(P?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=he,t[138]=ue,t[139]=P,t[140]=j,t[141]=e,t[142]=Et):Et=t[142];let Gt;t[143]!==Ne||t[144]!==W||t[145]!==A||t[146]!==e?(Gt=W&&s.jsx(ve,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Ne()},disabled:A,children:e(A?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=Ne,t[144]=W,t[145]=A,t[146]=e,t[147]=Gt):Gt=t[147];let ts;t[148]!==A||t[149]!==N||t[150]!==e?(ts=N&&s.jsx(ve,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>T(!1),disabled:A,children:e("settings.projects.page.actions.undoRemove")}),t[148]=A,t[149]=N,t[150]=e,t[151]=ts):ts=t[151];let Nt;t[152]!==Et||t[153]!==Gt||t[154]!==ts?(Nt=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Et,Gt,ts]}),t[152]=Et,t[153]=Gt,t[154]=ts,t[155]=Nt):Nt=t[155];let St;t[156]!==st||t[157]!==qe||t[158]!==Ye||t[159]!==Ue||t[160]!==vt||t[161]!==Nt?(St=s.jsxs("div",{className:"py-1.5",children:[st,qe,Ye,Ue,vt,Nt]}),t[156]=st,t[157]=qe,t[158]=Ye,t[159]=Ue,t[160]=vt,t[161]=Nt,t[162]=St):St=t[162];let Zt;t[163]!==ge||t[164]!==we||t[165]!==St?(Zt=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[ge,we,St]}),t[163]=ge,t[164]=we,t[165]=St,t[166]=Zt):Zt=t[166];let ut;t[167]!==z||t[168]!==A||t[169]!==j||t[170]!==h?(ut=!z||h.trim().length===0||j||A,t[167]=z,t[168]=A,t[169]=j,t[170]=h,t[171]=ut):ut=t[171];let Xt;t[172]!==e?(Xt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=Xt):Xt=t[173];let as;t[174]!==re||t[175]!==ut||t[176]!==Xt?(as=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(ve,{onClick:re,disabled:ut,size:"xs",className:"!font-normal",children:Xt})}),t[174]=re,t[175]=ut,t[176]=Xt,t[177]=as):as=t[177];let Bt;t[178]!==Zt||t[179]!==as?(Bt=s.jsxs("div",{className:"mb-8",children:[Zt,as]}),t[178]=Zt,t[179]=as,t[180]=Bt):Bt=t[180];let ls;t[181]!==oe?(ls=oe&&s.jsx(Gk,{projectRef:oe}),t[181]=oe,t[182]=ls):ls=t[182];let gs;t[183]!==ls?(gs=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:ls})}),t[183]=ls,t[184]=gs):gs=t[184];let us;t[185]!==e?(us=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=us):us=t[186];let xs;t[187]!==us?(xs=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:us})}),t[187]=us,t[188]=xs):xs=t[188];let At;t[189]!==oe?(At=oe&&s.jsx(Wk,{projectRef:oe}),t[189]=oe,t[190]=At):At=t[190];let We;t[191]!==At?(We=s.jsx("section",{className:"px-2 pb-2 pt-0",children:At}),t[191]=At,t[192]=We):We=t[192];let Rt;t[193]!==xs||t[194]!==We?(Rt=s.jsxs("div",{className:"mb-8",children:[xs,We]}),t[193]=xs,t[194]=We,t[195]=Rt):Rt=t[195];let Dt;return t[196]!==Te||t[197]!==Bt||t[198]!==gs||t[199]!==Rt?(Dt=s.jsx(As,{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:[Te,Bt,gs,Rt]})}),t[196]=Te,t[197]=Bt,t[198]=gs,t[199]=Rt,t[200]=Dt):Dt=t[200],Dt};function Jk(t){return t.projects}function Qk(t){return t.updateProjectMeta}function Yk(t){return t.uploadProjectIcon}function Xk(t){return t.removeProjectIcon}function Zk(t){return t.discoverProjectIcon}function e3(t){return t.settingsProjectsSelectedId}function t3(t){return t.setSettingsProjectsSelectedId}function s3(t){return t&&URL.revokeObjectURL(t),null}const n3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,r3=()=>Math.floor(2e4+Math.random()*3e4),a3=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")},i3=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"}},o3=({onItemSelect:t})=>{const{t:e}=mt(),n=Qs(g=>g.instances),r=Qs(g=>g.statusesById),i=Qs(g=>g.isLoading),a=Qs(g=>g.load),o=Qs(g=>g.loadImports),c=Qs(g=>g.createFromCommand),d=Qs(g=>g.connect),p=Qs(g=>g.disconnect),m=Qs(g=>g.retry),u=Qs(g=>g.removeInstance),f=Qs(g=>g.upsertInstance),b=Me(g=>g.settingsRemoteInstancesSelectedId),h=Me(g=>g.setSettingsRemoteInstancesSelectedId);l.useEffect(()=>{a(),o()},[a,o]),l.useEffect(()=>{if(!i){if(n.length===0){b!==null&&h(null);return}b&&n.some(g=>g.id===b)||h(n[0].id)}},[n,i,b,h]);const v=l.useCallback(async()=>{const g=n3();try{await c(g,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),h(g),t?.()}catch(w){q.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:w instanceof Error?w.message:String(w)})}},[c,t,h,e]),x=l.useCallback(async g=>{try{await d(g.id);return}catch(w){if(!a3(w)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw w;const S={...g,localForward:{...g.localForward,preferredLocalPort:r3()}};await f(S),await d(S.id),q.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,f]);return s.jsx(Qf,{variant:"background",header:s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.remoteInstances.sidebar.title")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.remoteInstances.sidebar.total",{count:n.length})}),s.jsx(ve,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{v()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(C,{name:"add",className:"size-4"})})]})]}),children:n.map(g=>{const w=r[g.id],y=g.id===b,S=g.nickname?.trim()||g.sshParsed?.destination||g.id,D=`${e(i3(w?.phase))}${w?.localUrl?` · ${w.localUrl}`:""}`,j=w?.phase==="ready",I=w?.phase==="error"||w?.phase==="degraded";return s.jsx(Yf,{title:S,metadata:D,selected:y,onSelect:()=>{h(g.id),t?.()},actions:[{label:e(j?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:j?"stop":"plug-2",onClick:()=>{(j?p(g.id):x(g)).catch(E=>{q.error(e(j?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:E instanceof Error?E.message:String(E)})})}},{label:e("settings.remoteInstances.sidebar.actions.retry"),icon:"refresh",onClick:()=>{I&&m(g.id).catch(A=>{q.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:A instanceof Error?A.message:String(A)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:"delete-bin",destructive:!0,onClick:()=>{u(g.id).then(()=>{if(b===g.id){const A=n.find(E=>E.id!==g.id);h(A?.id||null)}}).catch(A=>{q.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:A instanceof Error?A.message:String(A)})})}}]},g.id)})})},Jm=t=>{const e=rt.c(10),{children:n,className:r,outerClassName:i}=t;let a;e[0]!==i?(a=pe("h-full",i),e[0]=i,e[1]=a):a=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]!==a||e[8]!==c?(d=s.jsx(As,{outerClassName:a,className:"w-full",children:c}),e[7]=a,e[8]=c,e[9]=d):d=e[9],d},ad=()=>Math.floor(2e4+Math.random()*3e4),l3=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")},c3=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"}},d3=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Xf=t=>!!(t&&d3.has(t)),u3=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Xf(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",m3=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}`,p3=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:ad(),remoteHost:"127.0.0.1",remotePort:80}),h3=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Br=t=>{const e=rt.c(8),{label:n,hint:r}=t;let i;e[0]!==n?(i=s.jsx("span",{children:n}),e[0]=n,e[1]=i):i=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=a):a=e[2];let o;e[3]!==r?(o=s.jsxs(Ct,{children:[a,s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:s.jsx("div",{className:"typography-meta text-foreground",children:r})})]}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==i||e[6]!==o?(c=s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[i,o]}),e[5]=i,e[6]=o,e[7]=c):c=e[7],c},f3=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"}},Qm=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},g3=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},x3=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],i=(e[2]||"INFO").toUpperCase(),a=e[3]||"";return`[${r}] [${i}] ${a}`},b3=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},y3=t=>{const e=t.sshCommand.trim(),n=t.nickname?.trim(),r=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.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}},v3=()=>{const{t}=mt(),e=Qs(U=>U.instances),n=Qs(U=>U.statusesById),r=Qs(U=>U.importCandidates),i=Qs(U=>U.isImportsLoading),a=Qs(U=>U.isSaving),o=Qs(U=>U.error),c=Qs(U=>U.load),d=Qs(U=>U.loadImports),p=Qs(U=>U.refreshStatuses),m=Qs(U=>U.upsertInstance),u=Qs(U=>U.createFromCommand),f=Qs(U=>U.removeInstance),b=Qs(U=>U.connect),h=Qs(U=>U.disconnect),v=Qs(U=>U.retry),x=Me(U=>U.settingsRemoteInstancesSelectedId),g=Me(U=>U.setSettingsRemoteInstancesSelectedId),w=l.useMemo(()=>x&&e.find(U=>U.id===x)||null,[e,x]),[y,S]=l.useState(null),[D,j]=l.useState(!1),[I,A]=l.useState(!1),[E,P]=l.useState(null),[k,N]=l.useState([]),[T,M]=l.useState(null),[R,L]=l.useState(""),[O,V]=l.useState(!1),[$,B]=l.useState({}),[H,_]=l.useState(!1),[se,oe]=l.useState(!1),[ae,ne]=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 Ee=()=>{const Z=Date.now();Z-de>=1e3&&(ne(Z),de=Z),U=requestAnimationFrame(Ee)};(typeof document>"u"||document.visibilityState==="visible")&&(U=requestAnimationFrame(Ee));const _e=()=>{document.visibilityState==="visible"&&U===null?U=requestAnimationFrame(Ee):document.visibilityState!=="visible"&&U!==null&&(cancelAnimationFrame(U),U=null)};return document.addEventListener("visibilitychange",_e),()=>{document.removeEventListener("visibilitychange",_e),U!==null&&cancelAnimationFrame(U)}},[]);const xe=x?n[x]:null,te=xe?.phase,F=te==="ready",z=te==="degraded",Q=Xf(te),K=F||(Q||z),le=xe?Math.max(0,ae-xe.updatedAtMs):0,Se=z&&le>12e3,ue=l.useMemo(()=>!y||!w?!1:JSON.stringify(y)!==JSON.stringify(w),[y,w]),je=l.useCallback(U=>{S(de=>de&&U(de))},[]),W=l.useCallback(async()=>{if(!y)return;const U=y3(y);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)})}}},[y,t,m]),me=l.useCallback(async(U,de)=>{const Ee=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(Ee,`ssh ${de}`,U),g(Ee),q.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(_e){return q.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:_e instanceof Error?_e.message:String(_e)}),!1}},[u,g,t]),X=l.useCallback(()=>{O||(M(null),L(""))},[O]),ce=l.useCallback((U,de)=>{if(de){M(U),L(h3(U));return}me(U,U)},[me]),ee=l.useCallback(async()=>{const U=T,de=R.trim();if(U){if(!de){q.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}V(!0);try{await me(U,de)&&(M(null),L(""))}finally{V(!1)}}},[me,R,T,t]),Pe=l.useCallback(async()=>{if(w)try{await b(w.id);return}catch(U){if(!l3(U)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw U;const Ee={...w,localForward:{...w.localForward,preferredLocalPort:ad()}};await m(Ee),await b(Ee.id),q.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[b,w,t,m]),Ne=l.useCallback(async U=>(await fb(U,600)).map(Ee=>x3(Ee)),[]),Y=l.useCallback(async()=>{if(y){j(!0),A(!0),P(null);try{const U=await Ne(y.id);N(U)}catch(U){N([]),P(U instanceof Error?U.message:String(U))}finally{A(!1)}}},[y,Ne]);l.useEffect(()=>{if(!D||!y)return;let U=!1;const de=async()=>{try{const _e=await Ne(y.id);U||(N(_e),P(null))}catch(_e){U||P(_e instanceof Error?_e.message:String(_e))}};de();const Ee=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||de()},1e3);return()=>{U=!0,window.clearInterval(Ee)}},[y,D,Ne]);const he=l.useMemo(()=>k.join(`
|
|
176
|
-
`),[k]),ke=l.useCallback(()=>{if(!he.trim()){q.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Rn(he).then(U=>{U.ok&&q.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[he,t]),be=l.useCallback(async()=>{if(y)try{await gb(y.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)})}},[y,t]),fe=l.useCallback(async()=>{if(!xe?.localUrl){q.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const U=xe.localUrl.trim();if(!U){q.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}b3(U)},[xe?.localUrl,t]),Te=l.useCallback(()=>{if(!y)return;_(!0),(K?h(y.id):Pe()).catch(de=>{const Ee=K?F?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";q.error(t(Ee),{description:de instanceof Error?de.message:String(de)})}).finally(()=>{_(!1)})},[K,Pe,h,y,F,t]),Ve=l.useCallback(()=>{if(!y||Q)return;oe(!0),(z?h(y.id).then(()=>Pe()):v(y.id)).catch(de=>{q.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:de instanceof Error?de.message:String(de)})}).finally(()=>{oe(!1)})},[Pe,h,y,Q,z,v,t]),G=t(Q?"settings.remoteInstances.page.actions.connecting":z?Se?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Ie=!H&&!se&&(te==="error"||te==="idle"||!te||z&&Se)&&!Q,Oe=t(F?"settings.remoteInstances.sidebar.actions.disconnect":K?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!y)return s.jsxs(Jm,{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:i?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(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ce(U.host,U.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${U.source}:${U.host}`))})})]}),s.jsx(ws,{open:!!T,onOpenChange:U=>{U||X()},children:s.jsxs(vs,{className:"sm:max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Rs,{children:T?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:T}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:U=>{U.preventDefault(),ee()},children:[s.jsx(Ut,{value:R,onChange:U=>L(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(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:X,disabled:O,children:t("settings.common.actions.cancel")}),s.jsx(ve,{type:"submit",size:"xs",className:"!font-normal",disabled:O,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const De=y.remoteOpenchamber.mode==="managed",ge=y.nickname?.trim()||y.sshParsed?.destination||y.id;return s.jsxs(Jm,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ge}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${u3(te)}`}),s.jsx("span",{children:t(c3(te))}),xe?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:xe.localUrl}):null,Se?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.actions")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.actionsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ve,{type:"button",variant:K?"outline":"default",size:"xs",className:"!font-normal",onClick:Te,disabled:H||se,children:[K?s.jsx(C,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"plug-2",className:"h-3.5 w-3.5"}),Oe]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ve,disabled:!Ie,children:[s.jsx(C,{name:"refresh",className:`h-3.5 w-3.5 ${Q||z&&!Se?"animate-spin":""}`}),G]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Y()},children:[s.jsx(C,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&f(y.id).then(()=>{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(C,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),xe?.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:xe.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(Ut,{className:"h-7 md:max-w-xl",value:y.sshCommand,onChange:U=>je(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(Ut,{className:"h-7 md:max-w-sm",value:y.nickname||"",onChange:U=>je(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(yn,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:y.connectionTimeoutSec,onValueChange:U=>{je(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(Br,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(ps,{value:y.remoteOpenchamber.mode,onValueChange:U=>je(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,mode:U==="external"?"external":"managed"}})),children:[s.jsx(hs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(Ft,{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(Br,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(yn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.remoteOpenchamber.preferredPort,onValueChange:U=>{je(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,preferredPort:Number.isFinite(U)&&U>0?U:void 0}}))},onClear:()=>{je(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),De?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Br,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(ps,{value:y.remoteOpenchamber.installMethod,onValueChange:U=>je(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,installMethod:U==="npm"||U==="download_release"||U==="upload_bundle"?U:"bun"}})),children:[s.jsx(hs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"bun",children:"bun"}),s.jsx(Ft,{value:"npm",children:"npm"}),s.jsx(Ft,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(Ft,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,De?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Br,{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(al,{checked:y.remoteOpenchamber.keepRunning,onCheckedChange:U=>je(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(Br,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(ps,{value:y.localForward.bindHost,onValueChange:U=>{U==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||je(de=>({...de,localForward:{...de.localForward,bindHost:U==="localhost"||U==="0.0.0.0"?U:"127.0.0.1"}}))},children:[s.jsx(hs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(Ft,{value:"localhost",children:"localhost"}),s.jsx(Ft,{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(Br,{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(yn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.localForward.preferredLocalPort,onValueChange:U=>{je(de=>({...de,localForward:{...de.localForward,preferredLocalPort:Number.isFinite(U)&&U>0?U:void 0}}))},onClear:()=>{je(U=>({...U,localForward:{...U.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>je(U=>({...U,localForward:{...U.localForward,preferredLocalPort:ad()}})),children:s.jsx(C,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.authentication")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.authenticationDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshPasswordOptional")}),s.jsx(Ut,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.sshPassword?.value||"",onChange:U=>je(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(Ut,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.openchamberPassword?.value||"",onChange:U=>je(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:[y.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,y.portForwards.map((U,de)=>{const Ee=qe=>{je(it=>({...it,portForwards:it.portForwards.map((lt,ye)=>ye===de?qe(lt):lt)}))},_e=U.type==="remote"?"Local target":"Local listen",Z=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",Ce=U.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",He=Qm(U.localHost||"localhost",U.localPort),Ge=Qm(U.remoteHost||"localhost",U.remotePort),Xe=U.type==="local"&&typeof U.localPort=="number"&&U.localPort>0,we=Xe?`http://${g3(U.localHost)}:${U.localPort}`:"",tt=!!$[U.id],st=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(cr,{open:tt,onOpenChange:qe=>{B(it=>({...it,[U.id]:qe}))},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(jr,{className:"flex items-center gap-2 group",children:[s.jsx(C,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${tt?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:m3(U)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:st})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(al,{checked:U.enabled,onCheckedChange:qe=>Ee(it=>({...it,enabled:qe})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(ve,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>je(qe=>({...qe,portForwards:qe.portForwards.filter(it=>it.id!==U.id)})),children:s.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(dr,{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(f3(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(Br,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(ps,{value:U.type,onValueChange:qe=>Ee(it=>({...it,type:qe==="dynamic"||qe==="remote"?qe:"local"})),children:[s.jsx(hs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(Ft,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(Ft,{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(Br,{label:_e,hint:Z})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ut,{className:"h-7 w-32",value:U.localHost||"127.0.0.1",onChange:qe=>Ee(it=>({...it,localHost:qe.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(yn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:U.localPort,onValueChange:qe=>{Ee(it=>({...it,localPort:Number.isFinite(qe)&&qe>0?qe:void 0}))},onClear:()=>{Ee(qe=>({...qe,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(Br,{label:ie,hint:Ce})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ut,{className:"h-7 w-32",value:U.remoteHost||"",onChange:qe=>Ee(it=>({...it,remoteHost:qe.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(yn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:U.remotePort,onValueChange:qe=>{Ee(it=>({...it,remotePort:Number.isFinite(qe)&&qe>0?qe:void 0}))},onClear:()=>{Ee(qe=>({...qe,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:U.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"computer",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.localSocks5")})]}):U.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ge}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(C,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(C,{name:"computer",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.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"computer",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.local")}),s.jsx(C,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(C,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ge}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Xe?s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Qn(we).then(qe=>{qe||q.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(C,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},U.id)}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const U=p3();je(de=>({...de,portForwards:[...de.portForwards,U]})),B(de=>({...de,[U.id]:!0}))},children:[s.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.import.sectionTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:i?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(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ce(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(ve,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{W()},disabled:!ue||a,children:t("settings.common.actions.saveChanges")}),xe?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Rn(xe.localUrl||"").then(U=>{U.ok&&q.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(C,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{fe()},children:[s.jsx(C,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,o?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:o}):null]})}),s.jsx(ws,{open:D,onOpenChange:j,children:s.jsxs(vs,{className:"sm:max-w-2xl",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Rs,{children:y?.nickname?.trim()||y?.sshParsed?.destination||y?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ke,disabled:I||!he.trim(),children:[s.jsx(C,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{be()},disabled:I,children:[s.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),I?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):E?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:E}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:k.length>0?k.join(`
|
|
177
|
-
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(ws,{open:!!T,onOpenChange:U=>{U||X()},children:s.jsxs(vs,{className:"sm:max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Rs,{children:T?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:T}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:U=>{U.preventDefault(),ee()},children:[s.jsx(Ut,{value:R,onChange:U=>L(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(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:X,disabled:O,children:t("settings.common.actions.cancel")}),s.jsx(ve,{type:"submit",size:"xs",className:"!font-normal",disabled:O,children:t("settings.common.actions.create")})]})]})]})})]})},w3="__add_provider__",j3=()=>{const t=In.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},N3=({onItemSelect:t})=>{const{t:e}=mt(),n=yt(f=>f.providers),r=yt(f=>f.selectedProviderId),i=yt(f=>f.setSelectedProvider),a=Es(f=>f.activeProjectId),[o,c]=l.useState({}),d=l.useMemo(()=>j3(),[a]);l.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const h=n.map(async v=>{try{const x=d?`?directory=${encodeURIComponent(d)}`:"",g=await fetch(`/api/provider/${encodeURIComponent(v.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!g.ok)return;const w=await g.json().catch(()=>null),y=w?.sources??w?.data?.sources;if(!y||f)return;c(S=>({...S,[v.id]:y}))}catch{}});await Promise.all(h)})(),()=>{f=!0}},[d,n]);const p="bg-background",m=l.useMemo(()=>n.filter(f=>!!o[f.id]?.project?.exists),[n,o]),u=l.useMemo(()=>n.filter(f=>!o[f.id]?.project?.exists),[n,o]);return s.jsxs("div",{className: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(io,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{i(w3),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(C,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(As,{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(C,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[u.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),u.map(f=>s.jsx(Ym,{provider:f,selectedProviderId:r,onSelect:()=>{i(f.id),t?.()}},f.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(f=>s.jsx(Ym,{provider:f,selectedProviderId:r,onSelect:()=>{i(f.id),t?.()}},f.id))]})]})})]})},Ym=t=>{const e=rt.c(17),{provider:n,selectedProviderId:r,onSelect:i}=t,a=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(Mn,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const u=n.name||n.id;let f;e[4]!==u?(f=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:u}),e[4]=u,e[5]=f):f=e[5];let b;e[6]!==a?(b=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:a}),e[6]=a,e[7]=b):b=e[7];let h;e[8]!==i||e[9]!==m||e[10]!==f||e[11]!==b?(h=s.jsxs("button",{type:"button",onClick:i,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,f,b]}),e[8]=i,e[9]=m,e[10]=f,e[11]=b,e[12]=h):h=e[12];let v;return e[13]!==n.id||e[14]!==p||e[15]!==h?(v=s.jsx("div",{className:p,children:h},c),e[13]=n.id,e[14]=p,e[15]=h,e[16]=v):v=e[16],v},S3=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),Xm=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=S3.format(t);return e.endsWith(".0")?e.slice(0,-2):e},Po="__add_provider__",fi=t=>typeof t=="object"&&t!==null,Zm=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()},k3=t=>{if(!fi(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(i=>fi(i)));return e},C3=t=>{if(typeof t=="string")return{id:t};if(!fi(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}},I3=t=>{let e=[];Array.isArray(t)?e=t:fi(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(i=>C3(i)).filter(i=>!!i),r=new Set;return n.filter(i=>r.has(i.id)?!1:(r.add(i.id),!0))},P3=()=>{const{t}=mt(),e=yt(X=>X.providers),n=yt(X=>X.selectedProviderId),r=yt(X=>X.setSelectedProvider),i=yt(X=>X.getModelMetadata),a=Me(X=>X.hiddenModels),o=Me(X=>X.toggleHiddenModel),c=Me(X=>X.hideAllModels),d=Me(X=>X.showAllModels),[p,m]=l.useState({}),[u,f]=l.useState(!1),[b,h]=l.useState({}),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,S]=l.useState(null),[D,j]=l.useState({}),[I,A]=l.useState({}),[E,P]=l.useState([]),[k,N]=l.useState(!1),[T,M]=l.useState(null),[R,L]=l.useState(""),[O,V]=l.useState(""),[$,B]=l.useState(!1),[H,_]=l.useState({}),[se,oe]=l.useState(!1);l.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),l.useEffect(()=>{let X=!0;return(async()=>{f(!0);try{const ee=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!ee.ok)throw new Error(`Auth methods request failed (${ee.status})`);const Pe=await ee.json().catch(()=>({}));if(!X)return;m(k3(Pe))}catch(ee){if(!X)return;console.error("Failed to load provider auth methods:",ee),q.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{X&&f(!1)}})(),()=>{X=!1}},[t]),l.useEffect(()=>{let X=!0;return(async()=>{N(!0),M(null);try{const ee=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!ee.ok)throw new Error(`Provider list request failed (${ee.status})`);const Pe=await ee.json().catch(()=>({}));if(!X)return;P(I3(Pe))}catch(ee){if(!X)return;console.error("Failed to load available providers:",ee),M(t("settings.providers.page.state.unableToLoadProviderList"))}finally{X&&N(!1)}})(),()=>{X=!1}},[t]);const ae=l.useMemo(()=>new Set(e.map(X=>X.id)),[e]),ne=l.useMemo(()=>E.filter(X=>!ae.has(X.id)).sort((X,ce)=>{const ee=(X.name||X.id).toLowerCase(),Pe=(ce.name||ce.id).toLowerCase();return ee.localeCompare(Pe)}),[E,ae]);l.useEffect(()=>{n===Po&&R&&!ne.some(X=>X.id===R)&&L("")},[n,R,ne]),l.useEffect(()=>{if(n===Po){oe(!0);return}oe(!1)},[n,t]),l.useEffect(()=>{if(!n||n===Po)return;let X=!1;return(async()=>{try{const ee=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),Pe=await ee.json().catch(()=>null);if(!ee.ok)throw new Error(Pe?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Ne=Pe?.sources??Pe?.data?.sources;!X&&Ne&&_(Y=>({...Y,[n]:Ne}))}catch(ee){X||console.error("Failed to load provider sources:",ee)}})(),()=>{X=!0}},[n,t]);const xe=e.find(X=>X.id===n),te=n?H[n]:void 0,F=async X=>{const ce=b[X]?.trim()??"";if(!ce){q.error(t("settings.providers.page.toast.apiKeyRequired"));return}const ee=`api:${X}`;x(ee);try{const Pe=await fetch(`/api/auth/${encodeURIComponent(X)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:ce})}),Ne=await Pe.json().catch(()=>null);if(!Pe.ok){const Y=Ne?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(Y)}q.success(t("settings.providers.page.toast.apiKeySaved")),h(Y=>({...Y,[X]:""})),await ni({scopes:["providers"],mode:"active"}),r(X)}catch(Pe){console.error("Failed to save API key:",Pe),q.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},z=async(X,ce)=>{const ee=`oauth:${X}:${ce}`;x(ee);try{const Pe=await fetch(`/api/provider/${encodeURIComponent(X)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:ce})}),Ne=await Pe.json().catch(()=>null);if(!Pe.ok){const Ve=Ne?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(Ve)}const Y=fi(Ne)?Ne:{},he=fi(Y.data)?Y.data:Y,ke=typeof he.url=="string"&&he.url||typeof he.verification_uri_complete=="string"&&he.verification_uri_complete||typeof he.verification_uri=="string"&&he.verification_uri||void 0,be=typeof he.instructions=="string"&&he.instructions||typeof he.message=="string"&&he.message||void 0,fe=typeof he.user_code=="string"&&he.user_code||typeof he.code=="string"&&he.code||typeof he.userCode=="string"&&he.userCode||void 0;if(!ke&&!be&&!fe)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const Te=`${X}:${ce}`;A(Ve=>({...Ve,[Te]:{url:ke,instructions:be,userCode:fe}})),ke&&Qn(ke),S({providerId:X,methodIndex:ce}),q.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(Pe){console.error("Failed to start OAuth flow:",Pe),q.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},Q=async(X,ce)=>{const ee=`${X}:${ce}`,Pe=D[ee]?.trim(),Ne=`oauth-complete:${X}:${ce}`;x(Ne);try{const Y={method:ce};Pe&&(Y.code=Pe);const he=await fetch(`/api/provider/${encodeURIComponent(X)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Y)}),ke=await he.json().catch(()=>null);if(!he.ok){const be=ke?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(be)}q.success(t("settings.providers.page.toast.oauthCompleted")),j(be=>({...be,[ee]:""})),S(null),await ni({scopes:["providers"],mode:"active"}),r(X)}catch(Y){console.error("Failed to complete OAuth flow:",Y),q.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},re=async X=>{const ce=await Rn(X);if(ce.ok){q.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",ce.error),q.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},K=async X=>{const ce=await Rn(X);if(ce.ok){q.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",ce.error),q.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},le=async X=>{const ce=`disconnect:${X}`;x(ce);try{const ee=await fetch(`/api/provider/${encodeURIComponent(X)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),Pe=await ee.json().catch(()=>null);if(!ee.ok){const Ne=Pe?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(Ne)}q.success(t("settings.providers.page.toast.providerDisconnected")),await ni({scopes:["providers"],mode:"active"})}catch(ee){console.error("Failed to disconnect provider:",ee),q.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}},Se=n===Po;if(!Se&&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(C,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(Se)return s.jsx(As,{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")}),k?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):T?s.jsx("p",{className:"typography-meta text-muted-foreground",children:T}):ne.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(Bs,{open:$,onOpenChange:X=>{B(X),X||V("")},children:[s.jsx(Os,{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:[R?s.jsx(Mn,{providerId:R,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:pe("truncate typography-ui-label font-normal",R?"text-foreground":"text-muted-foreground"),children:R?ne.find(X=>X.id===R)?.name||R:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs($s,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:X=>X.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:X=>X.stopPropagation(),children:[s.jsx(C,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:O,onChange:X=>V(X.target.value),onKeyDown:X=>X.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(As,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const X=ne.filter(ce=>{const ee=O.toLowerCase();return(ce.name||ce.id).toLowerCase().includes(ee)||ce.id.toLowerCase().includes(ee)});return X.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):X.map(ce=>s.jsxs(zt,{onSelect:()=>{L(ce.id),B(!1),V("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Mn,{providerId:ce.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ce.name||ce.id})]}),R===ce.id&&s.jsx(C,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ce.id))})()})]})]})]})})]}),R&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")})}),u?s.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Ut,{type:"password",value:b[R]??"",onChange:X=>h(ce=>({...ce,[R]:X.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal shrink-0",onClick:()=>F(R),disabled:v===`api:${R}`,children:v===`api:${R}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const ce=(p[R]??[]).filter(ee=>Zm(ee)==="oauth");return ce.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ce.map((ee,Pe)=>{const Ne=ee.label||ee.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Pe+1)}),Y=`${R}:${Pe}`,he=y?.providerId===R&&y?.methodIndex===Pe;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:Ne}),(ee.description||ee.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(ee.description||ee.help)})]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>z(R,Pe),disabled:v===`oauth:${R}:${Pe}`,children:t("settings.providers.page.actions.connect")})]}),I[Y]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:I[Y]?.instructions}),I[Y]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Ut,{value:I[Y]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(I[Y]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),I[Y]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Ut,{value:I[Y]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Qn(I[Y]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>re(I[Y]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),he&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Ut,{value:D[Y]??"",onChange:ke=>j(be=>({...be,[Y]:ke.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal",onClick:()=>Q(R,Pe),disabled:v===`oauth-complete:${R}:${Pe}`,children:v===`oauth-complete:${R}:${Pe}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${R}-${Ne}`)})})})()]})]})]})});if(!xe)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(C,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const ue=Array.isArray(xe.models)?xe.models:[],W=(p[xe.id]??[]).filter(X=>Zm(X)==="oauth"),me=ue.filter(X=>{const ce=typeof X?.name=="string"?X.name:"",ee=typeof X?.id=="string"?X.id:"",Pe=g.trim().toLowerCase();return Pe?ce.toLowerCase().includes(Pe)||ee.toLowerCase().includes(Pe):!0});return s.jsx(As,{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(Mn,{providerId:xe.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:xe.name||xe.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:xe.id})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>oe(X=>!X),children:t(se?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:se?u?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Ut,{type:"password",value:b[xe.id]??"",onChange:X=>h(ce=>({...ce,[xe.id]:X.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal shrink-0",onClick:()=>F(xe.id),disabled:v===`api:${xe.id}`,children:v===`api:${xe.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),W.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:W.map((X,ce)=>{const ee=X.label||X.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(ce+1)}),Pe=`${xe.id}:${ce}`,Ne=y?.providerId===xe.id&&y?.methodIndex===ce;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:ee}),(X.description||X.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(X.description||X.help)})]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>z(xe.id,ce),disabled:v===`oauth:${xe.id}:${ce}`,children:t("settings.providers.page.actions.connect")})]}),I[Pe]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:I[Pe]?.instructions}),I[Pe]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Ut,{value:I[Pe]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(I[Pe]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),I[Pe]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Ut,{value:I[Pe]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Qn(I[Pe]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>re(I[Pe]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Ne&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Ut,{value:D[Pe]??"",onChange:Y=>j(he=>({...he,[Pe]:Y.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal",onClick:()=>Q(xe.id,ce),disabled:v===`oauth-complete:${xe.id}:${ce}`,children:v===`oauth-complete:${xe.id}:${ce}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${xe.id}-${ee}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(C,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-1",children:t("settings.providers.page.auth.useReconnectHint")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.connectionDetails.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children: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(ve,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>le(xe.id),disabled:v===`disconnect:${xe.id}`,children:v===`disconnect:${xe.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"),ue.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ue.length,")"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const X=ue.map(ce=>typeof ce?.id=="string"?ce.id:"").filter(ce=>ce.length>0);c(xe.id,X)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(xe.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(C,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Ut,{value:g,onChange:X=>w(X.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),me.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:me.map(X=>{const ce=typeof X?.id=="string"?X.id:"",ee=typeof X?.name=="string"?X.name:ce,Pe=ce?i(xe.id,ce):void 0,Ne=a.some(be=>be.providerID===xe.id&&be.modelID===ce),Y=Xm(Pe?.limit?.context),he=Xm(Pe?.limit?.output),ke=[];return Pe?.tool_call&&ke.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Pe?.reasoning&&ke.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Pe?.attachment&&ke.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:pe("flex items-center gap-3",Ne&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:ee}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Y||he)&&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&&he?" · ":"",he?`${he} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),ke.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:ke.map(({key:be,icon:fe,label:Te})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Te,"aria-label":Te,children:s.jsx(C,{name:fe,className:"h-3 w-3"})},be))}),s.jsx("button",{type:"button",onClick:()=>o(xe.id,ce),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(Ne?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Ne?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Ne?s.jsx(C,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ce)})})]})]})]})})},A3=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)},D3=t=>{const e=rt.c(106),{onItemSelect:n}=t,{t:r}=mt(),i=Ls(T3),a=Ls(M3),o=Ls(E3),c=Ls(R3),d=Ls(F3),p=Ls(L3),m=Ls(O3),u=Ls($3),f=Ls(B3),b=Ls(_3),h=Ls(V3),v=Ls(z3);let x,g;e[0]!==v?(x=()=>{v()},g=[v],e[0]=v,e[1]=x,e[2]=g):(x=e[1],g=e[2]),l.useEffect(x,g);const w=U3;let y;e[3]!==f?(y=fe=>{f(fe),w({usageAutoRefresh:fe})},e[3]=f,e[4]=y):y=e[4];const S=y;let D;e[5]!==b?(D=fe=>{const Te=Number(fe);Number.isFinite(Te)&&(b(Te),w({usageRefreshIntervalMs:Te}))},e[5]=b,e[6]=D):D=e[6];const j=D;let I;e[7]!==h?(I=fe=>{fe!=="usage"&&fe!=="remaining"||(h(fe),w({usageDisplayMode:fe}))},e[7]=h,e[8]=I):I=e[8];const A=I;let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=pe("flex h-full flex-col","bg-background"),e[9]=E):E=e[9];let P;e[10]!==r?(P=r("settings.usage.sidebar.title"),e[10]=r,e[11]=P):P=e[11];let k;e[12]!==P?(k=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:P}),e[12]=P,e[13]=k):k=e[13];let N;e[14]!==r?(N=r("settings.usage.sidebar.total",{count:Lr.length}),e[14]=r,e[15]=N):N=e[15];let T;e[16]!==N?(T=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[16]=N,e[17]=T):T=e[17];let M;e[18]!==r?(M=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=M):M=e[19];let R;e[20]!==S||e[21]!==M||e[22]!==p?(R=s.jsx(It,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(bs,{checked:p,onChange:S,ariaLabel:M})})}),e[20]=S,e[21]=M,e[22]=p,e[23]=R):R=e[23];let L;e[24]!==r?(L=r("settings.usage.sidebar.tooltip.autoRefresh"),e[24]=r,e[25]=L):L=e[25];let O;e[26]!==L?(O=s.jsx(Pt,{side:"bottom",children:L}),e[26]=L,e[27]=O):O=e[27];let V;e[28]!==R||e[29]!==O?(V=s.jsxs(Ct,{children:[R,O]}),e[28]=R,e[29]=O,e[30]=V):V=e[30];const $=String(m),B=!p;let H;e[31]!==r?(H=r("settings.usage.sidebar.field.intervalPlaceholder"),e[31]=r,e[32]=H):H=e[32];let _;e[33]!==H?(_=s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:H})}),e[33]=H,e[34]=_):_=e[34];let se;e[35]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsxs(fs,{children:[s.jsx(Ft,{value:"30000",children:"30s"}),s.jsx(Ft,{value:"60000",children:"1m"}),s.jsx(Ft,{value:"300000",children:"5m"})]}),e[35]=se):se=e[35];let oe;e[36]!==j||e[37]!==$||e[38]!==B||e[39]!==_?(oe=s.jsxs(ps,{value:$,onValueChange:j,disabled:B,children:[_,se]}),e[36]=j,e[37]=$,e[38]=B,e[39]=_,e[40]=oe):oe=e[40];let ae;e[41]!==c?(ae=()=>c(),e[41]=c,e[42]=ae):ae=e[42];let ne;e[43]!==r?(ne=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=ne):ne=e[44];let xe;e[45]!==r?(xe=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=xe):xe=e[46];const te=d&&"animate-spin";let F;e[47]!==te?(F=pe("h-3.5 w-3.5",te),e[47]=te,e[48]=F):F=e[48];let z;e[49]!==F?(z=s.jsx(C,{name:"refresh",className:F}),e[49]=F,e[50]=z):z=e[50];let Q;e[51]!==d||e[52]!==ae||e[53]!==ne||e[54]!==xe||e[55]!==z?(Q=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ae,"aria-label":ne,title:xe,disabled:d,children:z}),e[51]=d,e[52]=ae,e[53]=ne,e[54]=xe,e[55]=z,e[56]=Q):Q=e[56];let re;e[57]!==V||e[58]!==oe||e[59]!==Q?(re=s.jsxs("div",{className:"flex items-center gap-2",children:[V,oe,Q]}),e[57]=V,e[58]=oe,e[59]=Q,e[60]=re):re=e[60];let K;e[61]!==T||e[62]!==re?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[T,re]}),e[61]=T,e[62]=re,e[63]=K):K=e[63];let le;e[64]!==r?(le=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=le):le=e[65];let Se;e[66]!==le?(Se=s.jsx("span",{className:"typography-micro text-muted-foreground",children:le}),e[66]=le,e[67]=Se):Se=e[67];let ue;e[68]!==r?(ue=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=ue):ue=e[69];let je;e[70]!==ue?(je=s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:ue})}),e[70]=ue,e[71]=je):je=e[71];let W;e[72]!==r?(W=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=W):W=e[73];let me;e[74]!==W?(me=s.jsx(Ft,{value:"usage",children:W}),e[74]=W,e[75]=me):me=e[75];let X;e[76]!==r?(X=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=X):X=e[77];let ce;e[78]!==X?(ce=s.jsx(Ft,{value:"remaining",children:X}),e[78]=X,e[79]=ce):ce=e[79];let ee;e[80]!==me||e[81]!==ce?(ee=s.jsxs(fs,{children:[me,ce]}),e[80]=me,e[81]=ce,e[82]=ee):ee=e[82];let Pe;e[83]!==A||e[84]!==je||e[85]!==ee||e[86]!==u?(Pe=s.jsxs(ps,{value:u,onValueChange:A,children:[je,ee]}),e[83]=A,e[84]=je,e[85]=ee,e[86]=u,e[87]=Pe):Pe=e[87];let Ne;e[88]!==Se||e[89]!==Pe?(Ne=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[Se,Pe]}),e[88]=Se,e[89]=Pe,e[90]=Ne):Ne=e[90];let Y;e[91]!==K||e[92]!==Ne||e[93]!==k?(Y=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[k,K,Ne]}),e[91]=K,e[92]=Ne,e[93]=k,e[94]=Y):Y=e[94];let he;e[95]!==n||e[96]!==i||e[97]!==a||e[98]!==o||e[99]!==r?(he=Lr.map(fe=>{const Te=i.find(ge=>ge.providerId===fe.id),Ve=A3(Te?.usage),G=Xh(Ve),Ie=fe.id===a,Oe=Te?.configured??!1,De=Oe?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",Ie?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{o(fe.id),n?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:De}),s.jsx(Mn,{providerId:fe.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:fe.name}),!Oe&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},fe.id)}),e[95]=n,e[96]=i,e[97]=a,e[98]=o,e[99]=r,e[100]=he):he=e[100];let ke;e[101]!==he?(ke=s.jsx(As,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:he}),e[101]=he,e[102]=ke):ke=e[102];let be;return e[103]!==Y||e[104]!==ke?(be=s.jsxs("div",{className:E,children:[Y,ke]}),e[103]=Y,e[104]=ke,e[105]=be):be=e[105],be};function T3(t){return t.results}function M3(t){return t.selectedProviderId}function E3(t){return t.setSelectedProvider}function R3(t){return t.fetchAllQuotas}function F3(t){return t.isLoading}function L3(t){return t.autoRefresh}function O3(t){return t.refreshIntervalMs}function $3(t){return t.displayMode}function B3(t){return t.setAutoRefresh}function _3(t){return t.setRefreshInterval}function V3(t){return t.setDisplayMode}function z3(t){return t.loadSettings}async function U3(t){try{await Ps(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const bc=t=>{const e=rt.c(49),{title:n,window:r,subtitle:i,showToggle:a,toggleEnabled:o,onToggle:c}=t,d=a===void 0?!1:a,p=o===void 0?!1:o,m=Ls(W3),u=m==="remaining"?r.remainingPercent:r.usedPercent,f=m==="remaining"?"remaining":"used";let b;e[0]!==u||e[1]!==r.valueLabel?(b=Gi(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=b):b=e[2];const h=b,v=r.resetAfterFormatted??r.resetAtFormatted??"";let x;e[3]!==n?(x=Dd(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=qi(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 y=w;let S;e:{if(!y||y.dailyAllocationPercent===null){S=null;break e}const _=zr(y.elapsedRatio);S=m==="remaining"?100-_:_}const D=S;let j;e[10]!==c||e[11]!==d||e[12]!==p?(j=d&&s.jsx(bs,{checked:p,onChange:_=>c?.(_),ariaLabel:"Show in dropdown"}),e[10]=c,e[11]=d,e[12]=p,e[13]=j):j=e[13];let I;e[14]!==g?(I=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:g}),e[14]=g,e[15]=I):I=e[15];let A;e[16]!==i?(A=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[16]=i,e[17]=A):A=e[17];let E;e[18]!==I||e[19]!==A?(E=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[I,A]}),e[18]=I,e[19]=A,e[20]=E):E=e[20];let P;e[21]!==E||e[22]!==j?(P=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[j,E]}),e[21]=E,e[22]=j,e[23]=P):P=e[23];const k=h==="-"?"":h;let N;e[24]!==k?(N=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:k}),e[24]=k,e[25]=N):N=e[25];let T;e[26]!==P||e[27]!==N?(T=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[P,N]}),e[26]=P,e[27]=N,e[28]=T):T=e[28];let M;e[29]!==u||e[30]!==D||e[31]!==r.usedPercent?(M=s.jsx(Qi,{percent:u,tonePercent:r.usedPercent,expectedMarkerPercent:D,className:"h-1.5"}),e[29]=u,e[30]=D,e[31]=r.usedPercent,e[32]=M):M=e[32];const R=v?`Resets ${v}`:"";let L;e[33]!==R?(L=s.jsx("span",{className:"typography-micro text-muted-foreground",children:R}),e[33]=R,e[34]=L):L=e[34];let O;e[35]!==f?(O=s.jsx("span",{className:"typography-micro text-muted-foreground",children:f}),e[35]=f,e[36]=O):O=e[36];let V;e[37]!==L||e[38]!==O?(V=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[L,O]}),e[37]=L,e[38]=O,e[39]=V):V=e[39];let $;e[40]!==M||e[41]!==V?($=s.jsxs("div",{className:"mt-2.5",children:[M,V]}),e[40]=M,e[41]=V,e[42]=$):$=e[42];let B;e[43]!==y?(B=y&&s.jsx("div",{className:"mt-1.5",children:s.jsx(Yi,{paceInfo:y})}),e[43]=y,e[44]=B):B=e[44];let H;return e[45]!==T||e[46]!==$||e[47]!==B?(H=s.jsxs("div",{className:"py-3",children:[T,$,B]}),e[45]=T,e[46]=$,e[47]=B,e[48]=H):H=e[48],H};function W3(t){return t.displayMode}const K3=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},H3=()=>{const{t}=mt(),e=Ls(N=>N.results),n=Ls(N=>N.selectedProviderId),r=Ls(N=>N.setSelectedProvider),i=Ls(N=>N.loadSettings),a=Ls(N=>N.fetchAllQuotas),o=Ls(N=>N.isLoading),c=Ls(N=>N.lastUpdated),d=Ls(N=>N.error),p=Ls(N=>N.dropdownProviderIds),m=Ls(N=>N.setDropdownProviderIds),u=Ls(N=>N.selectedModels),f=Ls(N=>N.toggleModelSelected),b=Ls(N=>N.applyDefaultSelections);nf(),l.useEffect(()=>{i(),a()},[i,a]),l.useEffect(()=>{if(n||e.length===0)return;const N=e.find(T=>T.configured)?.providerId;r(N??Lr[0]?.id??null)},[e,n,r]);const h=e.find(N=>N.providerId===n)??null,x=Lr.find(N=>N.id===n)?.name??n??t("settings.usage.sidebar.title"),g=h?.usage,w=n?p.includes(n):!1,y=l.useCallback(N=>{if(!n)return;const T=N?Array.from(new Set([...p,n])):p.filter(M=>M!==n);m(T),Ps({usageDropdownProviders:T})},[p,n,m]),S=l.useMemo(()=>g?.models?Object.entries(g.models).map(([N,T])=>({name:N,windows:T})).filter(N=>Object.keys(N.windows.windows).length>0):[],[g?.models]);l.useEffect(()=>{n&&S.length>0&&b(n,S.map(N=>N.name))},[n,S,b]);const D=l.useMemo(()=>!n||S.length===0?new Map:gv(S,N=>N.name,n),[S,n]),j=l.useMemo(()=>{if(!n)return[];const N=tf(n);return sf(N)},[n]),[I,A]=l.useState(()=>({})),E=l.useCallback(N=>{A(T=>({...T,[N]:!T[N]}))},[]),P=l.useCallback(N=>{if(!n)return;f(n,N);const T=u[n]??[],R=T.includes(N)?T.filter(O=>O!==N):[...T,N],L={...u,[n]:R};Ps({usageSelectedModels:L})},[n,u,f]),k=n?u[n]??[]:[];return n?s.jsx(As,{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(Mn,{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:K3(c)})})]})]}),s.jsx("div",{className:"mb-8 px-2",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>y(!w),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),y(!w))},children:[s.jsx(bs,{checked:w,onChange:y,ariaLabel:t("settings.usage.page.options.showInHeaderAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.options.showInHeader")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!h&&s.jsx("div",{className:"mb-8 px-2",children:s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noData")})}),d&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:d})]}),h&&!h.configured&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([N,T])=>s.jsx(bc,{title:N,window:T},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 T=D.get(N.id)??[];if(T.length===0)return null;const M=I[N.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(cr,{open:!M,onOpenChange:()=>E(N.id),children:[s.jsxs(jr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:N.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",T.length,")"]})]}),M?s.jsx(C,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(dr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:T.map(R=>{const L=Object.entries(R.windows.windows);if(L.length===0)return null;const[O,V]=L[0],$=k.includes(R.name);return s.jsx(bc,{title:O,subtitle:rl(R.name),window:V,showToggle:!0,toggleEnabled:$,onToggle:()=>P(R.name)},R.name)})})})]})},N.id)}),(()=>{const N=D.get(null)??[];if(N.length===0)return null;const T=I.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(cr,{open:!T,onOpenChange:()=>E("other"),children:[s.jsxs(jr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",N.length,")"]})]}),T?s.jsx(C,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(dr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:N.map(M=>{const R=Object.entries(M.windows.windows);if(R.length===0)return null;const[L,O]=R[0],V=k.includes(M.name);return s.jsx(bc,{title:L,subtitle:rl(M.name),window:O,showToggle:!0,toggleEnabled:V,onToggle:()=>P(M.name)},M.name)})})})]})})})()]})]}),h?.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")})})},G3="git.commit.generate",id=ur(t=>({selectedPromptId:G3,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),q3=t=>{const e=rt.c(23),{onItemSelect:n}=t,{t:r}=mt(),i=id(J3),a=id(Q3);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 f;e[6]!==u?(f=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:u}),e[6]=u,e[7]=f):f=e[7];let b;e[8]!==r?(b=r("settings.magicPrompts.sidebar.description"),e[8]=r,e[9]=b):b=e[9];let h;e[10]!==b?(h=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[10]=b,e[11]=h):h=e[11];let v;e[12]!==f||e[13]!==h?(v=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[f,h]}),e[12]=f,e[13]=h,e[14]=v):v=e[14];let x;e[15]!==n||e[16]!==i||e[17]!==a||e[18]!==r?(x=s.jsx(As,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(w=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:r(w.groupKey)}),w.items.map(y=>{const S=i===y.id;return s.jsx("button",{type:"button",onClick:()=>{a(y.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(y.titleKey)})},y.id)})]},w.groupKey))}),e[15]=n,e[16]=i,e[17]=a,e[18]=r,e[19]=x):x=e[19];let g;return e[20]!==x||e[21]!==v?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[v,x]}),e[20]=x,e[21]=v,e[22]=g):g=e[22],g};function J3(t){return t.selectedPromptId}function Q3(t){return t.setSelectedPromptId}const ep={"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"}]}},tp=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),sp=t=>t.endsWith(".visible"),Y3=()=>{const{t}=mt(),e=l.useCallback(j=>t(j),[t]),n=id(j=>j.selectedPromptId),[r,i]=l.useState(!0),[a,o]=l.useState({}),[c,d]=l.useState({}),[p,m]=l.useState({}),[u,f]=l.useState({}),[b,h]=l.useState(!1);l.useEffect(()=>{let j=!0;return(async()=>{i(!0);try{const A=await vb();if(!j)return;o(A)}catch(A){console.warn("Failed to load magic prompts:",A),q.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&i(!1)}})(),()=>{j=!1}},[t]);const v=ep[n]??ep["git.commit.generate"],x=l.useCallback(j=>tp(a,j)?a[j]:zl(j),[a]),g=l.useCallback(j=>c[j]??x(j),[c,x]),w=l.useCallback((j,I)=>{d(A=>A[j]===I?A:{...A,[j]:I})},[]),y=l.useCallback(async j=>{const I=g(j);if(sp(j)&&I.trim().length===0){q.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(A=>({...A,[j]:!0}));try{const A=I===zl(j)?await ou(j):await xb(j,I);o(A.overrides),q.success(t("settings.magicPrompts.page.toast.saved"))}catch(A){const E=A instanceof Error?A.message:String(A);q.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:E})}finally{m(A=>({...A,[j]:!1}))}},[g,t]),S=l.useCallback(async j=>{f(I=>({...I,[j]:!0}));try{const I=await ou(j);o(I.overrides),d(A=>({...A,[j]:zl(j)})),q.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(I){const A=I instanceof Error?I.message:String(I);q.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:A})}finally{f(I=>({...I,[j]:!1}))}},[t]),D=l.useCallback(async()=>{h(!0);try{const j=await bb();o(j.overrides),d({}),q.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const I=j instanceof Error?j.message:String(j);q.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:I})}finally{h(!1)}},[t]);return r?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(v.titleKey)}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:e(v.descriptionKey)})]})]})}),s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>{D()},disabled:b||Object.keys(a).length===0,children:t(b?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),v.blocks.map((j,I)=>{const A=yb(j.id),E=x(j.id),P=g(j.id),k=tp(a,j.id),N=P!==E,T=sp(j.id)&&P.trim().length===0,M=p[j.id]===!0,R=u[j.id]===!0;return s.jsxs("section",{className:I>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label text-foreground",children:e(j.titleKey)}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:A.description})]})]}),A.placeholders&&A.placeholders.length>0&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[t("settings.magicPrompts.page.placeholdersLabel")," ",A.placeholders.map(L=>`{{${L.key}}}`).join(", ")]})]}),s.jsx(vn,{value:P,onChange:L=>w(j.id,L.target.value),className:"min-h-[220px] font-mono text-sm"}),T&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(N?"settings.magicPrompts.page.status.unsavedChanges":k?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>{S(j.id)},disabled:!k||M||R,children:t(R?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(ve,{size:"sm",onClick:()=>{y(j.id)},disabled:!N||M||R||T,children:t(M?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})]})})},Zf=()=>{const{t}=mt(),e=yt(u=>u.settingsGitmojiEnabled),n=yt(u=>u.setSettingsGitmojiEnabled),r=Nd(),i=Me(u=>u.gitChangesViewMode),a=Me(u=>u.setGitChangesViewMode),[o,c]=l.useState(!0),d=l.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);l.useEffect(()=>{(async()=>{try{let f=null;if(!f){const b=lr()?.settings;if(b)try{const v=(await b.load())?.settings;v&&(f={gitmojiEnabled:typeof v.gitmojiEnabled=="boolean"?v.gitmojiEnabled:void 0,gitChangesViewMode:v.gitChangesViewMode==="flat"||v.gitChangesViewMode==="tree"?v.gitChangesViewMode:void 0})}catch{}}if(!f){const b=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});b.ok&&(f=await b.json())}f&&(typeof f.gitmojiEnabled=="boolean"&&n(f.gitmojiEnabled),(f.gitChangesViewMode==="flat"||f.gitChangesViewMode==="tree")&&a(f.gitChangesViewMode))}catch(f){console.warn("Failed to load git settings:",f)}finally{c(!1)}})()},[a,n]);const p=l.useCallback(async u=>{n(u);try{await Ps({gitmojiEnabled:u})}catch(f){console.warn("Failed to save gitmoji setting:",f)}},[n]),m=l.useCallback(u=>{u!==i&&(a(u),Ps({gitChangesViewMode:u}))},[i,a]);return o?null:s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"pt-1 pb-1",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.changesViewTitle")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.openchamber.git.changesViewAria"),className:"mt-0.5 space-y-0",children:d.map(u=>{const f=i===u.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>{m(u.id)},onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),m(u.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:f,onChange:()=>{m(u.id)},ariaLabel:t("settings.openchamber.git.optionAria",{option:u.label})}),s.jsx("span",{className:f?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:u.label})]},u.id)})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{p(!e)},onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),p(!e))},children:[s.jsx(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:()=>Ul(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),Ul(!r))},children:[s.jsx(bs,{checked:r,onChange:Ul,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},eg=()=>{const{t}=mt(),{isMobile:e}=rn(),n=lr()?.github,r=Kn(A=>A.status),i=Kn(A=>A.isLoading),a=Kn(A=>A.hasChecked),o=Kn(A=>A.refreshStatus),c=Kn(A=>A.setStatus),d=l.useCallback(async A=>{await Qn(A)},[]),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState(null),v=l.useRef(null),x=l.useCallback(()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null),h(null)},[]);l.useEffect(()=>((async()=>{try{a||await o(n)}catch(A){console.warn("Failed to load GitHub auth status:",A)}})(),()=>{x()}),[a,o,n,x]);const g=l.useCallback(async()=>{m(!0);try{const A=n?await n.authStart():await(async()=>{const P=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),k=await P.json().catch(()=>null);if(!P.ok||!k||!("deviceCode"in k))throw new Error(k?.error||P.statusText);return k})();f(A),h(Math.max(1,A.interval)*1e3);const E=A.verificationUriComplete||A.verificationUri;d(E)}catch(A){console.error("Failed to start GitHub connect:",A),q.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),w=l.useCallback(async A=>{if(n)return n.authComplete(A);const E=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:A})}),P=await E.json().catch(()=>null);if(!E.ok||!P)throw new Error(P?.error||E.statusText);return P},[n]);l.useEffect(()=>{if(!(!u?.deviceCode||!b)&&v.current==null)return v.current=window.setInterval(()=>{(async()=>{try{const A=await w(u.deviceCode);if(A.connected){q.success(t("settings.github.page.toast.connected")),f(null),x(),await o(n,{force:!0});return}A.status==="slow_down"&&h(E=>E?E+5e3:5e3),(A.status==="expired_token"||A.status==="access_denied")&&(q.error(A.error||t("settings.github.page.toast.authorizationFailed")),f(null),x())}catch(A){console.warn("GitHub polling failed:",A)}})()},b),()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null)}},[u,b,w,o,n,x,t]);const y=l.useCallback(async()=>{m(!0);try{if(x(),f(null),n)await n.authDisconnect();else{const A=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!A.ok)throw new Error(A.statusText)}q.success(t("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(A){console.error("Failed to disconnect GitHub:",A),q.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[o,n,x,t]),S=l.useCallback(async A=>{if(A){m(!0);try{const E=n?await n.authActivate(A):await(async()=>{const P=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:A})}),k=await P.json().catch(()=>null);if(!P.ok||!k)throw new Error(k?.error||P.statusText);return k})();c(E),q.success(t("settings.github.page.toast.accountSwitched"))}catch(E){console.error("Failed to switch GitHub account:",E),q.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(i)return null;const D=!!r?.connected,j=r?.user,I=r?.accounts??[];return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"GitHub"}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.github.page.tooltip.connectAccount")})]})]})}),s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[D?s.jsxs("div",{className: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(C,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:j?.login||t("settings.github.page.label.unknownUser")}),j?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&s.jsx("span",{children:j.email})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:r.scope})})]})]}),s.jsx(ve,{size:"sm",variant:"outline",onClick:y,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(ve,{size:"sm",variant:"default",onClick:g,disabled:p,children:t("settings.github.page.actions.connect")})]}),I.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:I.map(A=>{const E=A.user,P=!!A.current;return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[E?.avatarUrl?s.jsx("img",{src:E.avatarUrl,alt:E.login?t("settings.github.page.avatarAlt.withLogin",{login:E.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(C,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:E?.name?.trim()||E?.login||"GitHub"}),E?.login&&s.jsx("span",{className:"typography-micro text-muted-foreground truncate font-mono",children:E.login})]})]}),P?s.jsx("span",{className:"typography-micro text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:t("settings.github.page.status.active")}):s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>S(A.id),disabled:p,children:t("settings.github.page.actions.switchTo")})]},A.id)})})]})]}),D&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(ve,{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(ve,{size:"sm",asChild:!0,children:s.jsx("a",{href:u.verificationUriComplete||u.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(ve,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{x(),f(null)},children:t("settings.common.actions.cancel")})]})]})]})},np=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],X3=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],Z3=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:i}=mt(),a=Gn(_=>_.getProfileById),o=Gn(_=>_.createProfile),c=Gn(_=>_.updateProfile),d=Gn(_=>_.deleteProfile),p=l.useMemo(()=>n&&n!=="new"&&!r?a(n):null,[n,a,r]),m=n==="new"||r!=null,u=n==="global",[f,b]=l.useState(""),[h,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState("ssh"),[S,D]=l.useState(""),[j,I]=l.useState(""),[A,E]=l.useState("keyword"),[P,k]=l.useState("branch"),[N,T]=l.useState(!1),[M,R]=l.useState(!1),[L,O]=l.useState(!1);l.useEffect(()=>{if(t){if(r){const _=r.host.split("/"),se=_.length>=3?_[_.length-1]:r.host;b(se),v(r.username),g(""),y("token"),D(""),I(r.host),E("string"),k("code")}else if(m)b(""),v(""),g(""),y("ssh"),D(""),I(""),E("keyword"),k("branch");else if(p)b(p.name),v(p.userName),g(p.userEmail),y(p.authType||"ssh"),D(p.sshKey||""),I(p.host||""),E(p.color||"keyword"),k(p.icon||"branch");else if(u){const _=a("global");_&&(b(_.name),v(_.userName),g(_.userEmail),y(_.authType||"ssh"),D(_.sshKey||""),I(_.host||""),E(_.color||"keyword"),k(_.icon||"branch"))}}},[t,n,p,m,r,u,a]);const V=async()=>{if(!h.trim()||!x.trim()){q.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(w==="token"&&!j.trim()){q.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}T(!0);try{const _={name:f.trim()||h.trim(),userName:h.trim(),userEmail:x.trim(),authType:w,sshKey:w==="ssh"&&S.trim()||null,host:w==="token"&&j.trim()||null,color:A,icon:P};let se;if(m)se=await o(_);else if(n)se=await c(n,_);else return;se?(q.success(i(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):q.error(i(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(_){console.error("Error saving profile:",_),q.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{T(!1)}},$=async()=>{if(!(!n||m)){O(!0);try{await d(n)?(q.success(i("settings.gitIdentities.editor.toast.profileDeleted")),R(!1),e(!1)):q.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(_){console.error("Error deleting profile:",_),q.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{O(!1)}}},B=l.useMemo(()=>np.find(se=>se.key===A)?.cssVar||"var(--syntax-keyword)",[A]),H=r?i("settings.gitIdentities.editor.title.importCredential"):m?i("settings.gitIdentities.editor.title.newIdentity"):u?i("settings.gitIdentities.editor.title.globalIdentity"):p?.name||i("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(Ss,{children:[s.jsx(js,{children:H}),s.jsx(Rs,{children:i(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:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(Ut,{value:f,onChange:_=>b(_.target.value),placeholder:i("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:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:np.map(_=>s.jsx("button",{type:"button",onClick:()=>E(_.key),className:pe("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",A===_.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:_.cssVar},title:_.label},_.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:X3.map(_=>{const se=_.Icon;return s.jsx("button",{type:"button",onClick:()=>k(_.key),className:pe("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",P===_.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:_.label,children:s.jsx(C,{name:se,className:"w-3.5 h-3.5",style:{color:P===_.key?B:"var(--surface-muted-foreground)"}})},_.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:i("settings.gitIdentities.editor.field.userName")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),s.jsx(Ut,{value:h,onChange:_=>v(_.target.value),placeholder:i("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:i("settings.gitIdentities.editor.field.emailAddress")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),s.jsx(Ut,{type:"email",value:x,onChange:_=>g(_.target.value),placeholder:i("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:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(ve,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="ssh",onClick:()=>y("ssh"),children:[s.jsx(C,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(ve,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="token",onClick:()=>y("token"),children:[s.jsx(C,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("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:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),s.jsx(Ut,{value:S,onChange:_=>D(_.target.value),placeholder:i("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:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]})]}),s.jsx(Ut,{value:j,onChange:_=>I(_.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Gs,{className:"gap-2",children:[!u&&!m&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>R(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(C,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.common.actions.delete")]}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:i(u?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!u&&s.jsx(ve,{size:"sm",onClick:V,disabled:N,children:i(N?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(ws,{open:M,onOpenChange:_=>{L||R(_)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Rs,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||f})})]}),s.jsxs(Gs,{children:[s.jsx(ve,{variant:"ghost",onClick:()=>R(!1),disabled:L,children:i("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:L,children:i("settings.common.actions.delete")})]})]})})]})},e5={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},t5={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},s5=()=>{const t=rt.c(116),{t:e}=mt(),{profiles:n,globalIdentity:r,defaultGitIdentityId:i,deleteProfile:a,loadProfiles:o,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=Gn(mr(r5)),[f,b]=l.useState(!1),[h,v]=l.useState(null),[x,g]=l.useState(null),[w,y]=l.useState(null),[S,D]=l.useState(!1);let j,I;t[0]!==p||t[1]!==d||t[2]!==c||t[3]!==o?(j=()=>{o(),c(),d(),p()},I=[o,c,d,p],t[0]=p,t[1]=d,t[2]=c,t[3]=o,t[4]=j,t[5]=I):(j=t[4],I=t[5]),l.useEffect(j,I);let A,E,P,k,N,T,M,R,L,O,V,$,B;if(t[6]!==i||t[7]!==w||t[8]!==a||t[9]!==u||t[10]!==r||t[11]!==n||t[12]!==m||t[13]!==e){const Y=u();let he;t[27]===Symbol.for("react.memo_cache_sentinel")?(he=(U,de)=>{v(U),g(de??null),b(!0)},t[27]=he):he=t[27];const ke=he;let be;t[28]!==i||t[29]!==m||t[30]!==e?(be=async U=>{const de=i===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]=i,t[29]=m,t[30]=e,t[31]=be):be=t[31];const fe=be;let Te;t[32]!==w||t[33]!==a||t[34]!==e?(Te=async()=>{if(!w)return;D(!0),await a(w.id)?(q.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:w.name})),y(null)):q.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),D(!1)},t[32]=w,t[33]=a,t[34]=e,t[35]=Te):Te=t[35],E=Te,A=As,k="h-full",N="w-full bg-background",B="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",t[36]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(eg,{}),t[36]=P):P=t[36],V="border-t border-border/40 pt-6";let Ve;t[37]!==e?(Ve=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=Ve):Ve=t[38];let G;t[39]!==Ve?(G=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:Ve})}),t[39]=Ve,t[40]=G):G=t[40];let Ie,Oe;t[41]===Symbol.for("react.memo_cache_sentinel")?(Ie=()=>ke("new"),Oe=s.jsx(C,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Ie,t[42]=Oe):(Ie=t[41],Oe=t[42]);let De;t[43]!==e?(De=e("settings.common.badge.new"),t[43]=e,t[44]=De):De=t[44];let ge;t[45]!==De?(ge=s.jsxs(ve,{size:"sm",variant:"outline",onClick:Ie,children:[Oe," ",De]}),t[45]=De,t[46]=ge):ge=t[46],t[47]!==G||t[48]!==ge?($=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[G,ge]}),t[47]=G,t[48]=ge,t[49]=$):$=t[49],T="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",M=r&&s.jsx(rp,{profile:r,isDefault:i==="global",onEdit:()=>ke("global"),onToggleDefault:()=>fe("global"),isReadOnly:!0,hasBorder:n.length>0||Y.length>0}),R=n.map((U,de)=>s.jsx(rp,{profile:U,isDefault:i===U.id,onEdit:()=>ke(U.id),onToggleDefault:()=>fe(U.id),onDelete:()=>y(U),hasBorder:de<n.length-1||Y.length>0},U.id)),L=!r&&n.length===0&&Y.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(C,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),O=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(n5,{credential:U,onImport:()=>ke("new",{host:U.host,username:U.username}),hasBorder:de<Y.length-1},`${U.host}-${U.username}`))]}),t[6]=i,t[7]=w,t[8]=a,t[9]=u,t[10]=r,t[11]=n,t[12]=m,t[13]=e,t[14]=A,t[15]=E,t[16]=P,t[17]=k,t[18]=N,t[19]=T,t[20]=M,t[21]=R,t[22]=L,t[23]=O,t[24]=V,t[25]=$,t[26]=B}else A=t[14],E=t[15],P=t[16],k=t[17],N=t[18],T=t[19],M=t[20],R=t[21],L=t[22],O=t[23],V=t[24],$=t[25],B=t[26];let H;t[50]!==T||t[51]!==M||t[52]!==R||t[53]!==L||t[54]!==O?(H=s.jsxs("div",{className:T,children:[M,R,L,O]}),t[50]=T,t[51]=M,t[52]=R,t[53]=L,t[54]=O,t[55]=H):H=t[55];let _;t[56]!==H||t[57]!==V||t[58]!==$?(_=s.jsxs("div",{className:V,children:[$,H]}),t[56]=H,t[57]=V,t[58]=$,t[59]=_):_=t[59];let se;t[60]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(Zf,{}),t[60]=se):se=t[60];let oe;t[61]!==P||t[62]!==_||t[63]!==B?(oe=s.jsxs("div",{className:B,children:[P,_,se]}),t[61]=P,t[62]=_,t[63]=B,t[64]=oe):oe=t[64];let ae;t[65]!==A||t[66]!==k||t[67]!==N||t[68]!==oe?(ae=s.jsx(A,{outerClassName:k,className:N,children:oe}),t[65]=A,t[66]=k,t[67]=N,t[68]=oe,t[69]=ae):ae=t[69];let ne;t[70]!==x||t[71]!==f||t[72]!==h?(ne=s.jsx(Z3,{open:f,onOpenChange:b,profileId:h,importData:x}),t[70]=x,t[71]=f,t[72]=h,t[73]=ne):ne=t[73];const xe=w!==null;let te;t[74]!==S?(te=Y=>{S||Y||y(null)},t[74]=S,t[75]=te):te=t[75];let F;t[76]!==e?(F=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=F):F=t[77];let z;t[78]!==F?(z=s.jsx(js,{children:F}),t[78]=F,t[79]=z):z=t[79];const Q=w?.name??"";let re;t[80]!==e||t[81]!==Q?(re=e("settings.gitIdentities.page.deleteDialog.description",{name:Q}),t[80]=e,t[81]=Q,t[82]=re):re=t[82];let K;t[83]!==re?(K=s.jsx(Rs,{children:re}),t[83]=re,t[84]=K):K=t[84];let le;t[85]!==z||t[86]!==K?(le=s.jsxs(Ss,{children:[z,K]}),t[85]=z,t[86]=K,t[87]=le):le=t[87];let Se;t[88]===Symbol.for("react.memo_cache_sentinel")?(Se=()=>y(null),t[88]=Se):Se=t[88];let ue;t[89]!==e?(ue=e("settings.common.actions.cancel"),t[89]=e,t[90]=ue):ue=t[90];let je;t[91]!==S||t[92]!==ue?(je=s.jsx(ve,{variant:"ghost",onClick:Se,disabled:S,children:ue}),t[91]=S,t[92]=ue,t[93]=je):je=t[93];let W;t[94]!==E?(W=()=>{E()},t[94]=E,t[95]=W):W=t[95];let me;t[96]!==e?(me=e("settings.common.actions.delete"),t[96]=e,t[97]=me):me=t[97];let X;t[98]!==S||t[99]!==W||t[100]!==me?(X=s.jsx(ve,{size:"sm",variant:"destructive",onClick:W,disabled:S,children:me}),t[98]=S,t[99]=W,t[100]=me,t[101]=X):X=t[101];let ce;t[102]!==je||t[103]!==X?(ce=s.jsxs(Gs,{children:[je,X]}),t[102]=je,t[103]=X,t[104]=ce):ce=t[104];let ee;t[105]!==le||t[106]!==ce?(ee=s.jsxs(vs,{className:"max-w-md",children:[le,ce]}),t[105]=le,t[106]=ce,t[107]=ee):ee=t[107];let Pe;t[108]!==xe||t[109]!==te||t[110]!==ee?(Pe=s.jsx(ws,{open:xe,onOpenChange:te,children:ee}),t[108]=xe,t[109]=te,t[110]=ee,t[111]=Pe):Pe=t[111];let Ne;return t[112]!==ae||t[113]!==ne||t[114]!==Pe?(Ne=s.jsxs(s.Fragment,{children:[ae,ne,Pe]}),t[112]=ae,t[113]=ne,t[114]=Pe,t[115]=Ne):Ne=t[115],Ne},rp=t=>{const e=rt.c(54),{profile:n,isDefault:r,onEdit:i,onToggleDefault:a,onDelete:o,isReadOnly:c,hasBorder:d}=t,{t:p}=mt(),m=e5[n.icon||"branch"]||"git-branch",u=t5[n.color||""],f=n.authType||"ssh",b=d&&"border-b border-[var(--surface-subtle)]";let h;e[0]!==b?(h=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]=h):h=e[1];let v;e[2]!==i?(v=V=>{(V.key==="Enter"||V.key===" ")&&i()},e[2]=i,e[3]=v):v=e[3];let x;e[4]!==u?(x={color:u},e[4]=u,e[5]=x):x=e[5];let g;e[6]!==m||e[7]!==x?(g=s.jsx(C,{name:m,className:"w-4 h-4 shrink-0",style:x}),e[6]=m,e[7]=x,e[8]=g):g=e[8];let w;e[9]!==n.name?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=w):w=e[10];let y;e[11]!==f?(y=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f}),e[11]=f,e[12]=y):y=e[12];let 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 D;e[16]!==c||e[17]!==p?(D=c&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:p("settings.agents.sidebar.badge.system")}),e[16]=c,e[17]=p,e[18]=D):D=e[18];let j;e[19]!==w||e[20]!==y||e[21]!==S||e[22]!==D?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,y,S,D]}),e[19]=w,e[20]=y,e[21]=S,e[22]=D,e[23]=j):j=e[23];const I=f==="token"&&n.host?n.host:n.userEmail;let A;e[24]!==I?(A=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:I}),e[24]=I,e[25]=A):A=e[25];let E;e[26]!==j||e[27]!==A?(E=s.jsxs("div",{className:"min-w-0",children:[j,A]}),e[26]=j,e[27]=A,e[28]=E):E=e[28];let P;e[29]!==E||e[30]!==g?(P=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[g,E]}),e[29]=E,e[30]=g,e[31]=P):P=e[31];let k;e[32]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(Os,{asChild:!0,children:s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:a5,children:s.jsx(C,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=k):k=e[32];let N;e[33]!==a?(N=V=>{V.stopPropagation(),a()},e[33]=a,e[34]=N):N=e[34];let T;e[35]!==r||e[36]!==p?(T=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=T):T=e[37];let M;e[38]!==N||e[39]!==T?(M=s.jsx(zt,{onClick:N,children:T}),e[38]=N,e[39]=T,e[40]=M):M=e[40];let R;e[41]!==c||e[42]!==o||e[43]!==p?(R=!c&&o&&s.jsxs(zt,{onClick:V=>{V.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]}),e[41]=c,e[42]=o,e[43]=p,e[44]=R):R=e[44];let L;e[45]!==M||e[46]!==R?(L=s.jsxs(Bs,{children:[k,s.jsxs($s,{align:"end",className:"w-fit min-w-28",children:[M,R]})]}),e[45]=M,e[46]=R,e[47]=L):L=e[47];let O;return e[48]!==i||e[49]!==P||e[50]!==h||e[51]!==L||e[52]!==v?(O=s.jsxs("div",{className:h,onClick:i,role:"button",tabIndex:0,onKeyDown:v,children:[P,L]}),e[48]=i,e[49]=P,e[50]=h,e[51]=L,e[52]=v,e[53]=O):O=e[53],O},n5=t=>{const e=rt.c(21),{credential:n,onImport:r,hasBorder:i}=t,{t:a}=mt();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=i&&"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 f;e[4]!==d?(f=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=f):f=e[5];const b=p?n.host:n.username;let h;e[6]!==b?(h=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:b}),e[6]=b,e[7]=h):h=e[7];let v;e[8]!==f||e[9]!==h?(v=s.jsxs("div",{className:"min-w-0",children:[f,h]}),e[8]=f,e[9]=h,e[10]=v):v=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(C,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let g;e[12]!==a?(g=a("settings.gitIdentities.page.actions.import"),e[12]=a,e[13]=g):g=e[13];let w;e[14]!==r||e[15]!==g?(w=s.jsxs(ve,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[x,g]}),e[14]=r,e[15]=g,e[16]=w):w=e[16];let y;return e[17]!==w||e[18]!==u||e[19]!==v?(y=s.jsxs("div",{className:u,children:[v,w]}),e[17]=w,e[18]=u,e[19]=v,e[20]=y):y=e[20],y};function r5(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 a5(t){return t.stopPropagation()}const tg=()=>{const t=wb();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},sg=()=>{const t=rt.c(2),[e,n]=l.useState(i5);let r,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const a=[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(tg())};o();for(const c of a)typeof c.addEventListener=="function"?c.addEventListener("change",o):typeof c.addListener=="function"&&c.addListener(o);return window.addEventListener("appinstalled",o),window.addEventListener("focus",o),()=>{for(const c of a)typeof c.removeEventListener=="function"?c.removeEventListener("change",o):typeof c.removeListener=="function"&&c.removeListener(o);window.removeEventListener("appinstalled",o),window.removeEventListener("focus",o)}},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),l.useEffect(r,i),e};function i5(){return tg()}const o5=[{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"}],l5=[{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"}],c5=[{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"}],d5=[{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"}],Pi="OpenChamber - AI Coding Assistant",ap=[{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"}],ip=[{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"}],yc=t=>t==="portrait"||t==="landscape"?t:"system",u5=[{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"}],m5=[{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"}],op=[{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"}],p5=[{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"}],lp=[{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"}],cp=[{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"}],h5=t=>t==="markdown"?"markdown":"plain",_d=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:i,t:a}=mt(),o=l.useCallback(J=>a(J),[a]),{isMobile:c}=rn(),{browserTab:d}=sg(),p=jl(),m=Me(J=>J.showReasoningTraces),u=Me(J=>J.setShowReasoningTraces),f=Me(J=>J.mermaidRenderingMode),b=Me(J=>J.setMermaidRenderingMode),h=Me(J=>J.userMessageRenderingMode),v=Me(J=>J.setUserMessageRenderingMode),x=Me(J=>J.stickyUserHeader),g=Me(J=>J.setStickyUserHeader),w=Me(J=>J.wideChatLayoutEnabled),y=Me(J=>J.setWideChatLayoutEnabled),S=Me(J=>J.chatRenderMode),D=Me(J=>J.setChatRenderMode),j=Me(J=>J.activityRenderMode),I=Me(J=>J.setActivityRenderMode),A=Me(J=>J.fontSize),E=Me(J=>J.setFontSize),P=Me(J=>J.terminalFontSize),k=Me(J=>J.setTerminalFontSize),N=Me(J=>J.uiFont),T=Me(J=>J.setUiFont),M=Me(J=>J.monoFont),R=Me(J=>J.setMonoFont),L=Me(J=>J.padding),O=Me(J=>J.setPadding),V=Me(J=>J.inputBarOffset),$=Me(J=>J.setInputBarOffset),B=Me(J=>J.mobileKeyboardMode),H=Me(J=>J.setMobileKeyboardMode),_=Me(J=>J.diffLayoutPreference),se=Me(J=>J.setDiffLayoutPreference),oe=Me(J=>J.diffViewMode),ae=Me(J=>J.setDiffViewMode),ne=Me(J=>J.showTerminalQuickKeysOnDesktop),xe=Me(J=>J.setShowTerminalQuickKeysOnDesktop),te=lu(J=>J.queueModeEnabled),F=lu(J=>J.setQueueMode),z=Me(J=>J.persistChatDraft),Q=Me(J=>J.setPersistChatDraft),re=Me(J=>J.inputSpellcheckEnabled),K=Me(J=>J.setInputSpellcheckEnabled),le=Me(J=>J.showToolFileIcons),Se=Me(J=>J.setShowToolFileIcons),ue=Me(J=>J.showExpandedBashTools),je=Me(J=>J.setShowExpandedBashTools),W=Me(J=>J.showExpandedEditTools),me=Me(J=>J.setShowExpandedEditTools),X=Me(J=>J.timeFormatPreference),ce=Me(J=>J.setTimeFormatPreference),ee=Me(J=>J.weekStartPreference),Pe=Me(J=>J.setWeekStartPreference),Ne=Me(J=>J.showSplitAssistantMessageActions),Y=Me(J=>J.setShowSplitAssistantMessageActions),he=Me(J=>J.showMobileSessionStatusBar),ke=Me(J=>J.setShowMobileSessionStatusBar),be=yt(J=>J.settingsMessageStreamTransport),fe=yt(J=>J.setSettingsMessageStreamTransport),Te=Me(J=>J.isSettingsDialogOpen),{themeMode:Ve,setThemeMode:G,availableThemes:Ie,customThemesLoading:Oe,reloadCustomThemes:De,lightThemeId:ge,darkThemeId:U,setLightThemePreference:de,setDarkThemePreference:Ee}=Nr(),[_e,Z]=l.useState(!1),[ie,Ce]=l.useState(0),He=Me(J=>J.reportUsage),Ge=Me(J=>J.setReportUsage),Xe=l.useCallback(J=>{Ge(J),Ps({reportUsage:J})},[Ge]),we=Te&&(t?t.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!we)return;let J=null,pt=Date.now();const jt=()=>{const es=Date.now();es-pt>=420&&(Ce(ns=>(ns+1)%24),pt=es),J=requestAnimationFrame(jt)};(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(jt));const Wt=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(jt):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",Wt),()=>{document.removeEventListener("visibilitychange",Wt),J!==null&&cancelAnimationFrame(J)}},[we]);const tt=l.useCallback(J=>{v(J),Ps({userMessageRenderingMode:J})},[v]),st=l.useCallback(J=>{g(J),Ps({stickyUserHeader:J})},[g]),qe=l.useCallback(J=>{y(J),Ps({wideChatLayoutEnabled:J})},[y]),it=l.useCallback(J=>{Y(J),Ps({showSplitAssistantMessageActions:J})},[Y]),lt=l.useCallback(J=>{K(J),Ps({inputSpellcheckEnabled:J})},[K]),ye=l.useCallback(J=>{D(J),Ps({chatRenderMode:J})},[D]),Je=l.useCallback(J=>{fe(J),Ps({messageStreamTransport:J})},[fe]),Be=l.useCallback(J=>{I(J),Ps({activityRenderMode:J})},[I]),ze=l.useCallback(J=>{b(J),Ps({mermaidRenderingMode:J})},[b]),nt=l.useCallback(J=>{Se(J),Ps({showToolFileIcons:J})},[Se]),Ye=l.useCallback(J=>{je(J),Ps({showExpandedBashTools:J})},[je]),Ue=l.useCallback(J=>{me(J),Ps({showExpandedEditTools:J})},[me]),vt=l.useCallback(J=>{ce(J),Ps({timeFormatPreference:J})},[ce]),Et=l.useCallback(J=>{Pe(J),Ps({weekStartPreference:J})},[Pe]),Gt=l.useMemo(()=>Ie.filter(J=>J.metadata.variant==="light").sort((J,pt)=>J.metadata.name.localeCompare(pt.metadata.name)),[Ie]),ts=l.useMemo(()=>Ie.filter(J=>J.metadata.variant==="dark").sort((J,pt)=>J.metadata.name.localeCompare(pt.metadata.name)),[Ie]),Nt=l.useMemo(()=>Gt.find(J=>J.metadata.id===ge)??Gt[0],[Gt,ge]),St=l.useMemo(()=>ts.find(J=>J.metadata.id===U)??ts[0],[ts,U]),Zt=l.useCallback((J,pt)=>{const jt=pt==="dark"?" Dark":" Light";return J.endsWith(jt)?J.slice(0,-jt.length):J},[]),ut=J=>t?t.includes(J):!0,Xt=pn(),as=ut("theme")&&!Xt,Bt=ut("theme")||ut("timeFormat")||ut("weekStart"),ls=Xt?Bt:ut("theme")||ut("pwaInstallName")||ut("pwaOrientation")||ut("timeFormat")||ut("weekStart"),gs=ut("fontSize")||ut("terminalFontSize")||ut("spacing")||ut("inputBarOffset"),us=ut("terminalQuickKeys")&&!c,xs=ut("mermaidRendering")||ut("userMessageRendering")||ut("chatRenderMode")||ut("messageTransport")||ut("activityRenderMode")&&S==="sorted"||ut("stickyUserHeader")||ut("wideChatLayout")||ut("splitAssistantMessageActions")||ut("diffLayout")||ut("mobileStatusBar")&&c||ut("dotfiles")||ut("reasoning")||ut("queueMode")||ut("persistDraft")||ut("showToolFileIcons")||ut("expandedTools")||!c&&ut("inputSpellcheck"),At=ut("pwaInstallName")&&sa()&&d&&!wn()&&!Xt,We=ut("pwaOrientation")&&sa()&&!wn()&&!Xt,Rt=ut("mobileKeyboardMode")&&sa()&&!wn()&&!Xt&&jb(),[Dt,wt]=l.useState(""),[Jt,_t]=l.useState("system"),Fs=l.useMemo(()=>{const J=lp.find(pt=>pt.id===X);return o(J?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[X,o]),ft=l.useMemo(()=>{const J=cp.find(pt=>pt.id===ee);return o(J?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[ee,o]),ds=l.useMemo(()=>{const J=ap.find(pt=>pt.id===Jt);return J?o(J.labelKey):void 0},[Jt,o]),Qt=l.useMemo(()=>{const J=ip.find(pt=>pt.id===B);return J?o(J.labelKey):void 0},[B,o]),ks=l.useCallback(async J=>{if(typeof window>"u")return;const pt=window,Wt=J.trim().replace(/\s+/g," ").slice(0,64);if(await Ps({pwaAppName:Wt}),typeof pt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const es=pt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Wt);wt(es);return}wt(Wt||Pi),pt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),_s=l.useCallback(async J=>{if(typeof window>"u")return;const pt=window,jt=yc(J);if(await Ps({pwaOrientation:jt}),typeof pt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Wt=pt.__OPENCHAMBER_SET_PWA_ORIENTATION__(jt);_t(Wt);return}_t(jt),pt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!At&&!We&&!Rt)return;let J=!1;return(async()=>{try{const jt=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!jt.ok){J||wt(Pi);return}const Wt=await jt.json().catch(()=>({})),ns=(typeof Wt?.pwaAppName=="string"?Wt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Cs=yc(Wt?.pwaOrientation),Is=pu(Wt?.mobileKeyboardMode);J||(At&&wt(ns||Pi),We&&_t(Cs),Rt&&H(Is))}catch{J||(At&&wt(Pi),We&&_t("system"),Rt&&H("native"))}})(),()=>{J=!0}},[H,Rt,At,We]),s.jsxs("div",{className:"space-y-8",children:[ls&&s.jsxs("div",{className:"mb-8 space-y-6",children:[as&&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:a("settings.openchamber.visual.section.colorMode")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:o5.map(J=>s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":Ve===J.value,className:"!font-normal",onClick:()=>G(J.value),children:o(J.labelKey)},J.value))})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:a("settings.openchamber.visual.field.lightTheme")}),s.jsxs(ps,{value:Nt?.metadata.id??"",onValueChange:de,children:[s.jsx(hs,{"aria-label":a("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(ys,{placeholder:a("settings.openchamber.visual.field.selectThemePlaceholder"),children:Nt?Zt(Nt.metadata.name,"light"):void 0})}),s.jsx(fs,{children:Gt.map(J=>s.jsx(Ft,{value:J.metadata.id,children:Zt(J.metadata.name,"light")},J.metadata.id))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:a("settings.openchamber.visual.field.darkTheme")}),s.jsxs(ps,{value:St?.metadata.id??"",onValueChange:Ee,children:[s.jsx(hs,{"aria-label":a("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(ys,{placeholder:a("settings.openchamber.visual.field.selectThemePlaceholder"),children:St?Zt(St.metadata.name,"dark"):void 0})}),s.jsx(fs,{children:ts.map(J=>s.jsx(Ft,{value:J.metadata.id,children:Zt(J.metadata.name,"dark")},J.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:Oe||_e,onClick:()=>{const J=Date.now();Z(!0),De().finally(()=>{const pt=Date.now()-J;if(pt<500){window.setTimeout(()=>{Z(!1)},500-pt);return}Z(!1)})},className:"inline-flex items-center typography-ui-label font-normal text-foreground underline decoration-[1px] underline-offset-2 hover:text-foreground/80 disabled:cursor-not-allowed disabled:text-muted-foreground/60",children:a(_e?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"flex items-center justify-center rounded-md p-1 text-muted-foreground/70 hover:text-foreground","aria-label":a("settings.openchamber.visual.field.themeImportInfoAria"),children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(Pt,{sideOffset:8,children:a("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),Bt&&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:a("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:a("settings.appearance.language.label")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.appearance.language.description")})]}),s.jsxs(ps,{value:e,onValueChange:J=>r(J),children:[s.jsx(hs,{"aria-label":a("settings.appearance.language.select"),className:"w-fit",children:s.jsx(ys,{children:i(e)})}),s.jsx(fs,{children:n.map(J=>s.jsx(Ft,{value:J,children:i(J)},J))})]})]}),!Xt&&(ut("timeFormat")||ut("weekStart"))&&s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[ut("timeFormat")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:a("settings.openchamber.visual.field.timeFormat")}),s.jsxs(ps,{value:X,onValueChange:J=>vt(J),children:[s.jsx(hs,{"aria-label":a("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(ys,{children:Fs})}),s.jsx(fs,{children:lp.map(J=>s.jsx(Ft,{value:J.id,children:o(J.labelKey)},J.id))})]})]}),ut("weekStart")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:a("settings.openchamber.visual.field.weekStartsOn")}),s.jsxs(ps,{value:ee,onValueChange:J=>Et(J),children:[s.jsx(hs,{"aria-label":a("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(ys,{children:ft})}),s.jsx(fs,{children:cp.map(J=>s.jsx(Ft,{value:J.id,children:o(J.labelKey)},J.id))})]})]})]})]}),(At||We||Rt)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[At&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.installAppName")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.openchamber.visual.field.installAppNameHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[s.jsx(Ut,{value:Dt,onChange:J=>{wt(J.target.value)},onBlur:()=>{ks(Dt)},onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),ks(Dt))},className:"h-7",maxLength:64,"aria-label":a("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>{wt(Pi),ks("")},className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:a("settings.common.actions.reset"),children:s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),We&&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:a("settings.openchamber.visual.field.installOrientation")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.openchamber.visual.field.installOrientationHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(ps,{value:Jt,onValueChange:J=>{const pt=yc(J);_t(pt),_s(pt)},children:[s.jsx(hs,{"aria-label":a("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(ys,{placeholder:a("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:ds})}),s.jsx(fs,{children:ap.map(J=>s.jsx(Ft,{value:J.id,children:o(J.labelKey)},J.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>{_t("system"),_s("system")},disabled:Jt==="system",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:a("settings.common.actions.reset"),children:s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Rt&&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:a("settings.openchamber.visual.field.mobileKeyboardMode")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.openchamber.visual.field.mobileKeyboardModeHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(ps,{value:B,onValueChange:J=>{const pt=pu(J);H(pt),Ps({mobileKeyboardMode:pt})},children:[s.jsx(hs,{"aria-label":a("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(ys,{placeholder:a("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Qt})}),s.jsx(fs,{children:ip.map(J=>s.jsx(Ft,{value:J.id,children:o(J.labelKey)},J.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>{H("native"),Ps({mobileKeyboardMode:"native"})},disabled:B==="native",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:a("settings.common.actions.reset"),children:s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),gs&&s.jsx("div",{className:"mb-8 space-y-3",children:s.jsxs("section",{className:"p-2 space-y-0.5",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.openchamber.visual.section.spacingAndLayout")}),s.jsxs("div",{className:"pl-2",children:[ut("fontSize")&&!c&&s.jsxs("div",{className:"flex items-center gap-8 py-1",children:[s.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.interfaceFont")})}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsxs(ps,{value:N,onValueChange:J=>T(J),children:[s.jsx(hs,{"aria-label":a("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(ys,{children:cu.find(J=>J.id===N)?.label})}),s.jsx(fs,{children:cu.map(J=>s.jsx(Ft,{value:J.id,children:s.jsx("span",{style:{fontFamily:J.stack},children:J.label})},J.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>T(du),disabled:N===du,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:a("settings.common.actions.reset"),children:s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("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:a("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:M,onValueChange:J=>R(J),children:[s.jsx(hs,{"aria-label":a("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(ys,{children:uu.find(J=>J.id===M)?.label})}),s.jsx(fs,{children:uu.map(J=>s.jsx(Ft,{value:J.id,children:s.jsx("span",{style:{fontFamily:J.stack},children:J.label})},J.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(mu),disabled:M===mu,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.openchamber.visual.actions.resetCodeFontAria"),title:a("settings.common.actions.reset"),children:s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("fontSize")&&!c&&s.jsxs("div",{className:"flex items-center gap-8 py-1",children:[s.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.interfaceFontSize")})}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(yn,{value:A,onValueChange:E,min:50,max:200,step:5,"aria-label":a("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>E(100),disabled:A===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.openchamber.visual.actions.resetFontSizeAria"),title:a("settings.common.actions.reset"),children:s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("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:a("settings.openchamber.visual.field.terminalFontSize")})}),s.jsxs("div",{className:pe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(yn,{value:P,onValueChange:k,min:9,max:52,step:1,className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>k(13),disabled:P===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:a("settings.common.actions.reset"),children:s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("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:a("settings.openchamber.visual.field.spacingDensity")})}),s.jsxs("div",{className:pe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(yn,{value:L,onValueChange:O,min:50,max:200,step:5,className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>O(100),disabled:L===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.openchamber.visual.actions.resetSpacingAria"),title:a("settings.common.actions.reset"),children:s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("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:a("settings.openchamber.visual.field.inputBarOffset")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:a("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),s.jsxs("div",{className:pe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(yn,{value:V,onValueChange:$,min:0,max:100,step:5,className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>$(0),disabled:V===0,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":a("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:a("settings.common.actions.reset"),children:s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),us&&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:a("settings.openchamber.visual.section.navigation")}),ut("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ne,onClick:()=>xe(!ne),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),xe(!ne))},children:[s.jsx(bs,{checked:ne,onChange:xe,ariaLabel:a("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:a("settings.openchamber.visual.field.terminalQuickKeys")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:a("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),xs&&s.jsxs("div",{className:"space-y-3",children:[(ut("userMessageRendering")||ut("mermaidRendering")||ut("chatRenderMode")||ut("messageTransport")||ut("activityRenderMode")&&S==="sorted"||ut("diffLayout")&&!Xt)&&s.jsxs("div",{className:"grid grid-cols-1 gap-y-2 md:grid-cols-[minmax(0,16rem)_minmax(0,16rem)] md:justify-start md:gap-x-2",children:[ut("chatRenderMode")&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.openchamber.visual.section.chatRenderMode")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.openchamber.visual.section.chatRenderModeAria"),className:"mt-1 grid w-full max-w-[26rem] grid-cols-1 gap-3 sm:grid-cols-2",children:m5.map(J=>{const pt=S===J.id,jt=ie%12;return s.jsxs("button",{type:"button",onClick:()=>ye(J.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(J.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:J.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Wt=>{const es=Wt*3+1,ns=jt-es+1,Cs=ns<=0?0:ns===1?42:ns===2?68:92,Is=Cs>0;return s.jsxs("div",{className:pe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Is?"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:`${Cs}%`}})]},Wt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Wt=>{const es=jt>=(Wt+1)*3;return s.jsxs("div",{className:pe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",es?"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%"}})]},Wt)})})})]},J.id)})})]}),ut("messageTransport")&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("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:op.map(J=>s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":be===J.id,className:"!font-normal",onClick:()=>Je(J.id),children:o(J.labelKey)},J.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const J=op.find(pt=>pt.id===be);return J?.descriptionKey?o(J.descriptionKey):""})()})]})]}),ut("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:a("settings.openchamber.visual.section.activityDefault")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.openchamber.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:p5.map(J=>{const pt=j===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>Be(J.id),onKeyDown:jt=>{(jt.key===" "||jt.key==="Enter")&&(jt.preventDefault(),Be(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:pt,onChange:()=>Be(J.id),ariaLabel:a("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(J.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]}),ut("expandedTools")&&s.jsxs("section",{className:"p-2 md:col-span-2 space-y-0.5",children:[s.jsx("div",{className:"typography-ui-header font-medium text-foreground py-1.5",children:a("settings.openchamber.visual.section.showToolsOpenedByDefault")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ue,onClick:()=>Ye(!ue),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),Ye(!ue))},children:[s.jsx(bs,{checked:ue,onChange:Ye,ariaLabel:a("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("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":W,onClick:()=>Ue(!W),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),Ue(!W))},children:[s.jsx(bs,{checked:W,onChange:Ue,ariaLabel:a("settings.openchamber.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.editTools")})]})]}),ut("userMessageRendering")&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.openchamber.visual.section.userMessageRendering")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.openchamber.visual.section.userMessageRenderingAria"),className:"mt-0.5 space-y-0",children:u5.map(J=>{const pt=h5(h)===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>tt(J.id),onKeyDown:jt=>{(jt.key===" "||jt.key==="Enter")&&(jt.preventDefault(),tt(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:pt,onChange:()=>tt(J.id),ariaLabel:a("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(J.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]}),ut("mermaidRendering")&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.openchamber.visual.section.mermaidRendering")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.openchamber.visual.section.mermaidRenderingAria"),className:"mt-0.5 space-y-0",children:d5.map(J=>{const pt=f===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>ze(J.id),onKeyDown:jt=>{(jt.key===" "||jt.key==="Enter")&&(jt.preventDefault(),ze(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:pt,onChange:()=>ze(J.id),ariaLabel:a("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(J.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]}),ut("diffLayout")&&!Xt&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.openchamber.visual.section.diffLayout")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.openchamber.visual.section.diffLayoutAria"),className:"mt-0.5 space-y-0",children:l5.map(J=>{const pt=_===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>se(J.id),onKeyDown:jt=>{(jt.key===" "||jt.key==="Enter")&&(jt.preventDefault(),se(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:pt,onChange:()=>se(J.id),ariaLabel:a("settings.openchamber.visual.field.diffLayoutAria",{option:o(J.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]}),ut("diffLayout")&&!Xt&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:a("settings.openchamber.visual.section.diffViewMode")}),s.jsx("div",{role:"radiogroup","aria-label":a("settings.openchamber.visual.section.diffViewModeAria"),className:"mt-0.5 space-y-0",children:c5.map(J=>{const pt=oe===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>ae(J.id),onKeyDown:jt=>{(jt.key===" "||jt.key==="Enter")&&(jt.preventDefault(),ae(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:pt,onChange:()=>ae(J.id),ariaLabel:a("settings.openchamber.visual.field.diffViewModeAria",{option:o(J.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]})]}),(ut("stickyUserHeader")||ut("wideChatLayout")||ut("splitAssistantMessageActions")||ut("mobileStatusBar")&&c||ut("dotfiles")||ut("queueMode")||ut("persistDraft")||ut("showToolFileIcons")||!c&&ut("inputSpellcheck")||ut("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[ut("reasoning")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),u(!m))},children:[s.jsx(bs,{checked:m,onChange:u,ariaLabel:a("settings.openchamber.visual.field.showReasoningTracesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.showReasoningTraces")})]}),ut("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":x,onClick:()=>st(!x),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),st(!x))},children:[s.jsx(bs,{checked:x,onChange:st,ariaLabel:a("settings.openchamber.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.stickyUserHeader")})]}),ut("wideChatLayout")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>qe(!w),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),qe(!w))},children:[s.jsx(bs,{checked:w,onChange:qe,ariaLabel:a("settings.openchamber.visual.field.wideChatLayoutAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.wideChatLayout")})]}),ut("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Ne,onClick:()=>it(!Ne),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),it(!Ne))},children:[s.jsx(bs,{checked:Ne,onChange:it,ariaLabel:a("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:a("settings.openchamber.visual.field.showSplitAssistantMessageActions")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:a("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),ut("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":le,onClick:()=>nt(!le),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),nt(!le))},children:[s.jsx(bs,{checked:le,onChange:nt,ariaLabel:a("settings.openchamber.visual.field.showToolFileIconsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.showToolFileIcons")})]}),ut("mobileStatusBar")&&c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":he,onClick:()=>ke(!he),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),ke(!he))},children:[s.jsx(bs,{checked:he,onChange:ke,ariaLabel:a("settings.openchamber.visual.field.showMobileStatusBarAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.showMobileStatusBar")})]}),ut("dotfiles")&&!pn()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>Lo(!p),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),Lo(!p))},children:[s.jsx(bs,{checked:p,onChange:Lo,ariaLabel:a("settings.openchamber.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.showDotfiles")})]}),ut("queueMode")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":te,onClick:()=>F(!te),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),F(!te))},children:[s.jsx(bs,{checked:te,onChange:F,ariaLabel:a("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:a("settings.openchamber.visual.field.queueMessagesByDefault")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:a("settings.openchamber.visual.field.queueMessagesByDefaultTooltip",{modifier:nl()})})]})]})]}),ut("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":z,onClick:()=>Q(!z),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),Q(!z))},children:[s.jsx(bs,{checked:z,onChange:Q,ariaLabel:a("settings.openchamber.visual.field.persistDraftMessagesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.persistDraftMessages")})]}),!c&&ut("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":re,onClick:()=>lt(!re),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),lt(!re))},children:[s.jsx(bs,{checked:re,onChange:lt,ariaLabel:a("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),ut("reportUsage")&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground mb-2",children:a("settings.openchamber.visual.section.privacy")}),s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(bs,{checked:He,onChange:Xe,ariaLabel:a("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":He,onClick:()=>Xe(!He),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),Xe(!He))},children:s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.openchamber.visual.field.sendAnonymousUsageReports")})}),s.jsx("span",{className:"typography-meta text-muted-foreground pointer-events-none",children:a("settings.openchamber.visual.field.sendAnonymousUsageReportsHint")})]})]})]})})]})};function f5(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=Cb();return t}catch{return"unknown"}}function g5(){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 x5(){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 b5(t){const e=Me.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",f5()),n.set("arch",g5()),n.set("platform",x5()),t==="desktop"?(n.set("appType",kb()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",Ur()?"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 vc(t,e){try{const n=b5(t),r=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e?n.set("currentVersion",e):t==="vscode"&&r&&n.set("currentVersion",r);const i=await fetch(`/api/openchamber/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!i.ok)throw new Error(`Server responded with ${i.status}`);const a=await i.json();return{available:a.available??!1,version:a.version,currentVersion:a.currentVersion??"unknown",body:a.body,nextSuggestedCheckInSec:typeof a.nextSuggestedCheckInSec=="number"&&Number.isFinite(a.nextSuggestedCheckInSec)?a.nextSuggestedCheckInSec:void 0,packageManager:a.packageManager,updateCommand:a.updateCommand}}catch(n){return console.warn("Failed to check for updates:",n),null}}function y5(){return ka()?Ur()?"desktop":"web":pn()?"vscode":sa()?"web":null}const dp={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Na=ur()((t,e)=>({...dp,checkForUpdates:async()=>{const n=y5();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,i=null;if(n==="desktop"){let a=await Wl();t({checking:!1,available:a?.available??!1,info:a,lastChecked:Date.now(),nextCheckInSec:null});const o=await vc("desktop",a?.currentVersion);if(i=o?.nextSuggestedCheckInSec??null,o?.available&&!a?.available){const c=await Wl();c&&(a=c)}if(o){const c={...a??{available:!1,currentVersion:o.currentVersion??"unknown"},...o,currentVersion:a?.currentVersion??o.currentVersion??"unknown",available:o.available};t({available:c.available,info:c,nextCheckInSec:i})}else t({nextCheckInSec:i});return i}else n==="web"?(r=await vc("web"),i=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(i=(await vc("vscode"))?.nextSuggestedCheckInSec??null);return t({checking:!1,available:n==="vscode"?!1:r?.available??!1,info:n==="vscode"?null:r,lastChecked:Date.now(),nextCheckInSec:i}),i}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 i=await Wl();if(!i?.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,...i,body:o.info.body||i.body,available:o.info.available}:i})),!await Sb(o=>{t({progress:o})}))throw new Error("Desktop update only works on Local instance");t({downloading:!1,downloaded:!0})}catch(i){t({downloading:!1,error:i instanceof Error?i.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:r}=e();if(!(r!=="desktop"||!n))try{if(!await Nb())throw new Error("Desktop restart only works on Local instance")}catch(i){t({error:i instanceof Error?i.message:"Failed to restart"})}},dismiss:()=>{t({available:!1,downloaded:!1,info:null})},reset:()=>{t(dp)}})),up="https://github.com/btriapitsyn/openchamber/releases";function v5(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 w5(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function mp(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function j5(t,e){const n=t.split(".").map(i=>Number.parseInt(i,10)),r=e.split(".").map(i=>Number.parseInt(i,10));for(let i=0;i<3;i+=1){const a=Number.isFinite(n[i])?n[i]:0,o=Number.isFinite(r[i])?r[i]:0;if(a!==o)return o-a}return 0}function N5(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((i,a)=>{const o=n[a+1]?.start??t.length,c=t.slice(i.start,o).trim();return{version:i.version,date:i.date,start:i.start,end:o,raw:c}})}const pp=2e3,S5=600*1e3;async function k5(){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 C5(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function I5(t,e=Math.ceil(S5/pp),n=pp){for(let r=0;r<e;r++){try{const i=await fetch("/api/openchamber/update-check",{method:"GET",headers:{Accept:"application/json"}});if(i.ok){const a=await i.json().catch(()=>null);if(a&&a.available===!1||a&&typeof a.currentVersion=="string"&&typeof t=="string"&&a.currentVersion!==t)return!0}else if((i.status===401||i.status===403)&&await C5())return!0}catch{}await new Promise(i=>setTimeout(i,n))}return!1}const od=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:i,progress:a,error:o,onDownload:c,onRestart:d,runtimeType:p="desktop"})=>{const{t:m}=mt(),[u,f]=$e.useState(!1),[b,h]=$e.useState("idle"),[v,x]=$e.useState(null),g=n?.version?`${up}/tag/v${n.version}`:up,w=a?.total?Math.round(a.downloaded/a.total*100):0,y=p==="web",S=n?.updateCommand||"openchamber update";$e.useEffect(()=>{t||(h("idle"),x(null))},[t]);const D=async()=>{(await Rn(S)).ok&&(f(!0),setTimeout(()=>f(!1),2e3))},j=$e.useCallback(async P=>{await Qn(P)},[]),I=$e.useCallback(async()=>{h("updating"),x(null);const P=await k5();if(!P.success){h("error"),x(P.error||m("updateDialog.error.updateFailed"));return}P.autoRestart&&(h("restarting"),await new Promise(N=>setTimeout(N,2e3))),h("reconnecting"),await I5(n?.currentVersion)?window.location.reload():(h("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),A=b!=="idle"&&b!=="error",E=$e.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const k=N5(P);if(k.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:mp(P)};const N=[...k].sort((T,M)=>j5(T.version,M.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:N.map(T=>({version:T.version,dateLabel:v5(T.date),content:mp(w5(T.raw)||P)}))}},[n?.body,m]);return s.jsx(ws,{open:t,onOpenChange:A?void 0:e,children:s.jsxs(vs,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[s.jsxs("div",{className:"flex items-center mb-1",children:[s.jsxs(js,{className:"flex items-center gap-2.5",children:[s.jsx(C,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),s.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(b==="restarting"||b==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&s.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&s.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&s.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&s.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),s.jsxs("div",{className:"space-y-2",children:[y&&A&&s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(C,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),s.jsxs("div",{className:"typography-ui-label text-foreground",children:[b==="updating"&&m("updateDialog.status.installingUpdate"),b==="restarting"&&m("updateDialog.status.serverRestarting"),b==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),s.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),E&&!A&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(As,{className:"max-h-[400px] p-0",fillContainer:!1,children:E.kind==="raw"?s.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline hover:[&_a]:!underline",onClickCapture:P=>{const N=P.target.closest("a");N&&N.href&&(P.preventDefault(),P.stopPropagation(),j(N.href))},children:s.jsx(Ia,{content:E.content,disableLinkSafety:!0})}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:E.sections.map(P=>s.jsxs("div",{className:"p-4 hover:bg-background/40 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[s.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",P.version]}),s.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:P.dateLabel})]}),s.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline hover:[&_a]:!underline",onClickCapture:k=>{const T=k.target.closest("a");T&&T.href&&(k.preventDefault(),k.stopPropagation(),j(T.href))},children:s.jsx(Ia,{content:P.content,disableLinkSafety:!0})})]},P.version))})})}),y&&b==="error"&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(C,{name:"terminal",className:"h-4 w-4"}),s.jsx("span",{children:m("updateDialog.fallback.updateViaTerminal")})]}),s.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[s.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:S}),s.jsx("button",{onClick:D,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(C,{name:"check",className:"h-4 w-4"}):s.jsx(C,{name:"clipboard",className:"h-4 w-4"})})]})]}),!y&&r&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center justify-between text-sm",children:[s.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),s.jsxs("span",{className:"font-mono text-foreground",children:[w,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${w}%`}})})]}),(o||v)&&s.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:s.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||v})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[s.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[s.jsx(C,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),s.jsxs("div",{className:"flex-1 flex justify-end",children:[!y&&!i&&!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(C,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!y&&r&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(C,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!y&&i&&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(C,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),y&&!A&&s.jsxs("button",{onClick:I,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(C,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),y&&A&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(C,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},hp="https://github.com/btriapitsyn/openchamber",P5=800,A5=()=>{const t=rt.c(103),{t:e}=mt(),[n,r]=l.useState(!1),[i,a]=l.useState(!1),o=Na(mr(D5)),{isMobile:c}=rn(),d=o.info?.currentVersion||"unknown",p=l.useRef(!1);let m,u;t[0]!==i||t[1]!==e||t[2]!==o.available||t[3]!==o.checking||t[4]!==o.error?(m=()=>{if(o.checking)a(!0),p.current=!0;else if(i){const V=setTimeout(()=>{a(!1),p.current&&!o.available&&!o.error&&(q.success(e("settings.openchamber.about.toast.latestVersion")),p.current=!1)},P5);return()=>clearTimeout(V)}},u=[e,o.checking,i,o.available,o.error],t[0]=i,t[1]=e,t[2]=o.available,t[3]=o.checking,t[4]=o.error,t[5]=m,t[6]=u):(m=t[5],u=t[6]),l.useEffect(m,u);const f=o.checking||i;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 $;t[9]!==f||t[10]!==e||t[11]!==o?($=!o.available&&!o.error&&s.jsx("button",{onClick:()=>o.checkForUpdates(),disabled:f,className:pe("typography-meta text-muted-foreground/60 hover:text-muted-foreground disabled:cursor-default",f&&"animate-pulse [animation-duration:1s]"),children:e("settings.openchamber.about.actions.checkUpdates")}),t[9]=f,t[10]=e,t[11]=o,t[12]=$):$=t[12];let B;t[13]!==f||t[14]!==e||t[15]!==o.available?(B=!f&&o.available&&s.jsxs("button",{onClick:()=>r(!0),className:"flex items-center gap-1 typography-meta text-[var(--primary-base)] hover:underline",children:[s.jsx(C,{name:"download",className:"h-3.5 w-3.5"}),e("settings.openchamber.about.actions.update")]}),t[13]=f,t[14]=e,t[15]=o.available,t[16]=B):B=t[16];let H;t[17]!==V||t[18]!==$||t[19]!==B?(H=s.jsxs("div",{className:"flex items-center justify-between",children:[V,$,B]}),t[17]=V,t[18]=$,t[19]=B,t[20]=H):H=t[20];let _;t[21]!==o.error?(_=o.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:o.error}),t[21]=o.error,t[22]=_):_=t[22];let se;t[23]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsxs("a",{href:hp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(C,{name:"github-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),t[23]=se):se=t[23];let oe;t[24]===Symbol.for("react.memo_cache_sentinel")?(oe=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(C,{name:"discord-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),t[24]=oe):oe=t[24];let ae;t[25]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsxs("div",{className:"flex items-center gap-3",children:[se,oe,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(C,{name:"twitter-xfill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[25]=ae):ae=t[25];let ne;t[26]!==n||t[27]!==o.downloadUpdate||t[28]!==o.downloaded||t[29]!==o.downloading||t[30]!==o.error||t[31]!==o.info||t[32]!==o.progress||t[33]!==o.restartToUpdate||t[34]!==o.runtimeType?(ne=s.jsx(od,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[26]=n,t[27]=o.downloadUpdate,t[28]=o.downloaded,t[29]=o.downloading,t[30]=o.error,t[31]=o.info,t[32]=o.progress,t[33]=o.restartToUpdate,t[34]=o.runtimeType,t[35]=ne):ne=t[35];let xe;return t[36]!==ne||t[37]!==H||t[38]!==_?(xe=s.jsxs("div",{className:"w-full space-y-2",children:[H,_,ae,ne]}),t[36]=ne,t[37]=H,t[38]=_,t[39]=xe):xe=t[39],xe}let b;t[40]!==e?(b=e("settings.openchamber.about.title"),t[40]=e,t[41]=b):b=t[41];let h;t[42]!==b?(h=s.jsx("div",{className:"mb-3 px-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:b})}),t[42]=b,t[43]=h):h=t[43];let v;t[44]!==e?(v=e("settings.openchamber.about.field.version"),t[44]=e,t[45]=v):v=t[45];let x;t[46]!==v?(x=s.jsx("span",{className:"typography-ui-label text-foreground",children:v}),t[46]=v,t[47]=x):x=t[47];let g;t[48]!==d?(g=s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d}),t[48]=d,t[49]=g):g=t[49];let w;t[50]!==x||t[51]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-col",children:[x,g]}),t[50]=x,t[51]=g,t[52]=w):w=t[52];let y;t[53]!==e||t[54]!==o.checking?(y=o.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(C,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),t[53]=e,t[54]=o.checking,t[55]=y):y=t[55];let S;t[56]!==e||t[57]!==o.available||t[58]!==o.checking||t[59]!==o.info?.version?(S=!o.checking&&o.available&&s.jsxs(ve,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(C,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:o.info?.version||""})]}),t[56]=e,t[57]=o.available,t[58]=o.checking,t[59]=o.info?.version,t[60]=S):S=t[60];let D;t[61]!==e||t[62]!==o.available||t[63]!==o.checking||t[64]!==o.error?(D=!o.checking&&!o.available&&!o.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t[61]=e,t[62]=o.available,t[63]=o.checking,t[64]=o.error,t[65]=D):D=t[65];let j;t[66]!==o?(j=()=>o.checkForUpdates(),t[66]=o,t[67]=j):j=t[67];const I=o.checking;let A;t[68]!==e?(A=e("settings.openchamber.about.actions.checkForUpdates"),t[68]=e,t[69]=A):A=t[69];let E;t[70]!==j||t[71]!==A||t[72]!==o.checking?(E=s.jsx(ve,{size:"sm",variant:"outline",onClick:j,disabled:I,children:A}),t[70]=j,t[71]=A,t[72]=o.checking,t[73]=E):E=t[73];let P;t[74]!==D||t[75]!==E||t[76]!==y||t[77]!==S?(P=s.jsxs("div",{className:"flex items-center gap-3",children:[y,S,D,E]}),t[74]=D,t[75]=E,t[76]=y,t[77]=S,t[78]=P):P=t[78];let k;t[79]!==P||t[80]!==w?(k=s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[w,P]}),t[79]=P,t[80]=w,t[81]=k):k=t[81];let N;t[82]!==o.error?(N=o.error&&s.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:o.error})}),t[82]=o.error,t[83]=N):N=t[83];let T;t[84]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsxs("a",{href:hp,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(C,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),t[84]=T):T=t[84];let M;t[85]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[T,s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(C,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[85]=M):M=t[85];let R;t[86]!==k||t[87]!==N?(R=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[k,N,M]}),t[86]=k,t[87]=N,t[88]=R):R=t[88];let L;t[89]!==n||t[90]!==o.downloadUpdate||t[91]!==o.downloaded||t[92]!==o.downloading||t[93]!==o.error||t[94]!==o.info||t[95]!==o.progress||t[96]!==o.restartToUpdate||t[97]!==o.runtimeType?(L=s.jsx(od,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[89]=n,t[90]=o.downloadUpdate,t[91]=o.downloaded,t[92]=o.downloading,t[93]=o.error,t[94]=o.info,t[95]=o.progress,t[96]=o.restartToUpdate,t[97]=o.runtimeType,t[98]=L):L=t[98];let O;return t[99]!==R||t[100]!==L||t[101]!==h?(O=s.jsxs("div",{className:"mb-8",children:[h,R,L]}),t[99]=R,t[100]=L,t[101]=h,t[102]=O):O=t[102],O};function D5(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 T5=1,M5=365,fp=30,E5=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],ng=()=>{const t=rt.c(113),{t:e}=mt(),n=Me(R5),r=Me(F5),i=Me(L5),a=Me(O5),o=Me($5),c=Me(B5);let d;t[0]===Symbol.for("react.memo_cache_sentinel")?(d={autoRun:!1},t[0]=d):d=t[0];const{candidates:p,isRunning:m,runCleanup:u,action:f}=Ib(d),b=p.length;let h;t[1]!==u||t[2]!==e?(h=async()=>{const ee=await u({force:!0});if(ee.completedIds.length===0&&ee.failedIds.length===0){q.message(ee.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ee.completedIds.length>0&&q.success(ee.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ee.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ee.completedIds.length})),ee.failedIds.length>0&&q.error(ee.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ee.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ee.failedIds.length}))},t[1]=u,t[2]=e,t[3]=h):h=t[3];const v=h;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let g;t[6]!==x?(g=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),t[6]=x,t[7]=g):g=t[7];let w;t[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=w):w=t[8];let y;t[9]!==e?(y=e("settings.openchamber.sessionRetention.tooltip"),t[9]=e,t[10]=y):y=t[10];let S;t[11]!==y?(S=s.jsxs(Ct,{children:[w,s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:y})]}),t[11]=y,t[12]=S):S=t[12];let D;t[13]!==g||t[14]!==S?(D=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]=D):D=t[15];let j,I;t[16]!==n||t[17]!==a?(j=()=>a(!n),I=ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),a(!n))},t[16]=n,t[17]=a,t[18]=j,t[19]=I):(j=t[18],I=t[19]);let A;t[20]!==e?(A=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[20]=e,t[21]=A):A=t[21];let E;t[22]!==n||t[23]!==a||t[24]!==A?(E=s.jsx(bs,{checked:n,onChange:a,ariaLabel:A}),t[22]=n,t[23]=a,t[24]=A,t[25]=E):E=t[25];let P;t[26]!==e?(P=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[26]=e,t[27]=P):P=t[27];let k;t[28]!==P?(k=s.jsx("span",{className:"typography-ui-label text-foreground",children:P}),t[28]=P,t[29]=k):k=t[29];let N;t[30]!==n||t[31]!==E||t[32]!==k||t[33]!==j||t[34]!==I?(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:I,children:[E,k]}),t[30]=n,t[31]=E,t[32]=k,t[33]=j,t[34]=I,t[35]=N):N=t[35];let T;t[36]!==e?(T=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=T):T=t[37];let M;t[38]!==T?(M=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:T})}),t[38]=T,t[39]=M):M=t[39];let R;t[40]!==e?(R=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=R):R=t[41];let L;t[42]!==r||t[43]!==o||t[44]!==R?(L=s.jsx(yn,{value:r,onValueChange:o,min:T5,max:M5,step:1,"aria-label":R,className:"w-20 tabular-nums"}),t[42]=r,t[43]=o,t[44]=R,t[45]=L):L=t[45];let O;t[46]!==e?(O=e("settings.openchamber.sessionRetention.field.days"),t[46]=e,t[47]=O):O=t[47];let V;t[48]!==O?(V=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:O}),t[48]=O,t[49]=V):V=t[49];let $;t[50]!==o?($=()=>o(fp),t[50]=o,t[51]=$):$=t[51];const B=r===fp;let H;t[52]!==e?(H=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=H):H=t[53];let _;t[54]!==e?(_=e("settings.common.actions.reset"),t[54]=e,t[55]=_):_=t[55];let se;t[56]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(C,{name:"restart",className:"h-3.5 w-3.5"}),t[56]=se):se=t[56];let oe;t[57]!==$||t[58]!==B||t[59]!==H||t[60]!==_?(oe=s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:$,disabled:B,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":H,title:_,children:se}),t[57]=$,t[58]=B,t[59]=H,t[60]=_,t[61]=oe):oe=t[61];let ae;t[62]!==L||t[63]!==V||t[64]!==oe?(ae=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[L,V,oe]}),t[62]=L,t[63]=V,t[64]=oe,t[65]=ae):ae=t[65];let ne;t[66]!==M||t[67]!==ae?(ne=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[M,ae]}),t[66]=M,t[67]=ae,t[68]=ne):ne=t[68];let xe;t[69]!==e?(xe=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=xe):xe=t[70];let te;t[71]!==xe?(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:xe})}),t[71]=xe,t[72]=te):te=t[72];let F;t[73]!==i||t[74]!==c||t[75]!==e?(F=E5.map(ee=>s.jsx(ve,{type:"button",variant:"chip",size:"xs","aria-pressed":i===ee.value,className:"!font-normal",onClick:()=>c(ee.value),children:e(ee.labelKey)},ee.value)),t[73]=i,t[74]=c,t[75]=e,t[76]=F):F=t[76];let z;t[77]!==F?(z=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:F}),t[77]=F,t[78]=z):z=t[78];let Q;t[79]!==te||t[80]!==z?(Q=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]=Q):Q=t[81];let re;t[82]!==N||t[83]!==ne||t[84]!==Q?(re=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[N,ne,Q]}),t[82]=N,t[83]=ne,t[84]=Q,t[85]=re):re=t[85];let K;t[86]!==e?(K=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=K):K=t[87];let le;t[88]!==K?(le=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:K})}),t[88]=K,t[89]=le):le=t[89];let Se;t[90]!==m||t[91]!==e?(Se=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=Se):Se=t[92];let ue;t[93]!==v||t[94]!==m||t[95]!==Se?(ue=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(ve,{type:"button",variant:"outline",size:"xs",onClick:v,disabled:m,className:"!font-normal",children:Se})}),t[93]=v,t[94]=m,t[95]=Se,t[96]=ue):ue=t[96];let je;t[97]!==le||t[98]!==ue?(je=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[le,ue]}),t[97]=le,t[98]=ue,t[99]=je):je=t[99];let W;t[100]!==f||t[101]!==b||t[102]!==e?(W=f==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:b}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:b}),t[100]=f,t[101]=b,t[102]=e,t[103]=W):W=t[103];let me;t[104]!==W?(me=s.jsx("p",{className:"typography-meta text-muted-foreground",children:W}),t[104]=W,t[105]=me):me=t[105];let X;t[106]!==je||t[107]!==me?(X=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[je,me]}),t[106]=je,t[107]=me,t[108]=X):X=t[108];let ce;return t[109]!==re||t[110]!==X||t[111]!==D?(ce=s.jsxs("div",{className:"mb-8",children:[D,re,X]}),t[109]=re,t[110]=X,t[111]=D,t[112]=ce):ce=t[112],ce};function R5(t){return t.autoDeleteEnabled}function F5(t){return t.autoDeleteAfterDays}function L5(t){return t.sessionRetentionAction}function O5(t){return t.setAutoDeleteEnabled}function $5(t){return t.setAutoDeleteAfterDays}function B5(t){return t.setSessionRetentionAction}const gp=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),rg=()=>{const{t}=mt(),[e,n]=l.useState(!1),[r,i]=l.useState(!0),[a,o]=l.useState(!1),[c,d]=l.useState(null),[p,m]=l.useState(!1),[u,f]=l.useState([]),[b,h]=l.useState(Pb),[v,x]=l.useState(""),g=l.useMemo(()=>Ab(),[]),w=l.useCallback(async()=>{i(!0),x("");try{const j=await Db();f(j)}catch(j){const I=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.loadFailed");x(I)}finally{i(!1)}},[t]);l.useEffect(()=>{let j=!1;return(async()=>{try{if(!g.supported){j||(n(!1),i(!1));return}j||n(!0)}catch{j||n(!1)}if(!j){const I=await Kl();if(h(I),!I.enabled){f([]),i(!1);return}await w()}})(),()=>{j=!0,hu()}},[w,g.supported]);const y=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(a){hu(),o(!1);return}x(""),o(!0);try{await Tb(),h(await Kl()),await w(),q.success(t("settings.openchamber.passkeys.toast.added"))}catch(j){if(Mb(j)){q.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const I=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.addFailed");x(I),q.error(I)}finally{o(!1)}},[a,w,b.enabled,g.reason,e,t]),S=l.useCallback(async j=>{d(j),x("");try{await Eb(j),h(await Kl()),await w(),q.success(t("settings.openchamber.passkeys.toast.removed"))}catch(I){const A=I instanceof Error?I.message:t("settings.openchamber.passkeys.toast.removeFailed");x(A),q.error(A)}finally{d(null)}},[w,t]),D=l.useCallback(async()=>{m(!0),x("");try{await Rb(),window.location.reload()}catch(j){const I=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");x(I),q.error(I),m(!1)}},[t]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.passkeys.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.passkeys.field.currentDevice")})}),s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[s.jsx(ve,{type:"button",variant:a?"secondary":"outline",size:"xs",onClick:()=>{y()},disabled:r||p,className:"!font-normal",children:t(a?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(ve,{type:"button",variant:"ghost",size:"xs",onClick:()=>{D()},disabled:r||a||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:gp(j.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:gp(j.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(ve,{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))})]}),v&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v})})]})},_5=t=>{const e=mi(t);return e||{providerId:"",modelId:""}},ag=()=>{const{t}=mt(),e=yt(M=>M.setProvider),n=yt(M=>M.setModel),r=yt(M=>M.setAgent),i=yt(M=>M.setCurrentVariant),a=yt(M=>M.setSettingsDefaultModel),o=yt(M=>M.setSettingsDefaultVariant),c=yt(M=>M.setSettingsDefaultAgent),d=yt(M=>M.setSettingsDefaultFileViewerPreview),p=yt(M=>M.settingsDefaultFileViewerPreview),m=Me(M=>M.showDeletionDialog),u=Me(M=>M.setShowDeletionDialog),f=yt(M=>M.providers),[b,h]=l.useState(),[v,x]=l.useState(),[g,w]=l.useState(),[y,S]=l.useState(!0),D=l.useMemo(()=>_5(b),[b]);l.useEffect(()=>{(async()=>{try{let R=null;if(!R){const L=lr()?.settings;if(L)try{const V=(await L.load())?.settings;V&&(R={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(!R){const L=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});L.ok&&(R=await L.json())}if(R){const L=typeof R.defaultModel=="string"&&R.defaultModel.trim().length>0?R.defaultModel.trim():void 0,O=typeof R.defaultVariant=="string"&&R.defaultVariant.trim().length>0?R.defaultVariant.trim():void 0,V=typeof R.defaultAgent=="string"&&R.defaultAgent.trim().length>0?R.defaultAgent.trim():void 0;L!==void 0&&h(L),O!==void 0&&x(O),V!==void 0&&w(V)}}catch(R){console.warn("Failed to load defaults settings:",R)}finally{S(!1)}})()},[]);const j=l.useCallback(async(M,R)=>{const L=M&&R?`${M}/${R}`:void 0;h(L),x(void 0),o(void 0),i(void 0),a(L),M&&R&&f.find(V=>V.id===M)&&(e(M),n(R));try{await Ps({defaultModel:L??"",defaultVariant:""});const O=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:L})});O.ok||console.warn("Failed to save default model to server:",O.status,O.statusText)}catch(O){console.warn("Failed to save default model:",O)}},[f,i,n,e,a,o]),I="__default__",A=l.useCallback(M=>M===I?t("settings.openchamber.defaults.option.default"):M.charAt(0).toUpperCase()+M.slice(1),[t]),E=l.useCallback(async M=>{const R=M===I?void 0:M||void 0;x(R),o(R),i(R);try{await Ps({defaultVariant:R??""})}catch(L){console.warn("Failed to save default variant:",L)}},[i,o]),P=l.useCallback(async M=>{const R=M||void 0;w(R),c(R),M&&r(M);try{await Ps({defaultAgent:R??""})}catch(L){console.warn("Failed to save default agent:",L)}},[r,c]),k=l.useCallback(()=>{const M=!p;d(M),Ps({defaultFileViewerPreview:M}).catch(console.warn)},[p,d]),N=l.useMemo(()=>{if(!D.providerId||!D.modelId)return[];const L=f.find(O=>O.id===D.providerId)?.models.find(O=>O.id===D.modelId)?.variants;return L?Object.keys(L):[]},[D.modelId,D.providerId,f]),T=N.length>0;return l.useEffect(()=>{!T&&v&&(x(void 0),o(void 0),i(void 0),Ps({defaultVariant:""}).catch(()=>{}))},[v,i,o,T]),y?null:s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-0.5 px-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.defaults.title")})})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",D.providerId?s.jsxs("span",{className:"text-foreground",children:[D.providerId,"/",D.modelId,T?` (${v??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),g&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:g})]})]}),s.jsxs("div",{className: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(ao,{providerId:D.providerId,modelId:D.modelId,onChange:j})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultThinking")})}),s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsxs(ps,{value:v??I,onValueChange:E,disabled:!T,children:[s.jsx(hs,{className:"w-fit min-w-[120px]",children:s.jsx(ys,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:A(v??I)})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:I,children:t("settings.openchamber.defaults.option.default")}),N.map(M=>s.jsx(Ft,{value:M,children:A(M)},M))]})]})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Il,{agentName:g||"",onChange:P})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),u(!m))},children:[s.jsx(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:k,onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),k())},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")})]})]})]})},xp={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"}},V5={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"},bp="big-pickle",wc="__not_selected__",yp=200,vp=100,wp=250,z5=()=>{const{t}=mt(),{isMobile:e}=rn(),n=l.useMemo(()=>wn(),[]),r=l.useMemo(()=>pn(),[]),i=!n&&!r,a=Me(W=>W.nativeNotificationsEnabled),o=Me(W=>W.setNativeNotificationsEnabled),c=Me(W=>W.notificationMode),d=Me(W=>W.setNotificationMode),p=Me(W=>W.notifyOnSubtasks),m=Me(W=>W.setNotifyOnSubtasks),u=Me(W=>W.notifyOnCompletion),f=Me(W=>W.setNotifyOnCompletion),b=Me(W=>W.notifyOnError),h=Me(W=>W.setNotifyOnError),v=Me(W=>W.notifyOnQuestion),x=Me(W=>W.setNotifyOnQuestion),g=Me(W=>W.notificationTemplates),w=Me(W=>W.setNotificationTemplates),y=Me(W=>W.summarizeLastMessage),S=Me(W=>W.setSummarizeLastMessage),D=Me(W=>W.summaryThreshold),j=Me(W=>W.setSummaryThreshold),I=Me(W=>W.summaryLength),A=Me(W=>W.setSummaryLength),E=Me(W=>W.maxLastMessageLength),P=Me(W=>W.setMaxLastMessageLength),k=yt(W=>W.settingsZenModel),N=yt(W=>W.setSettingsZenModel),[T,M]=l.useState("default"),[R,L]=l.useState(!1),[O,V]=l.useState(!1),[$,B]=l.useState(!1),[H,_]=l.useState([]);l.useEffect(()=>{const W=new AbortController;return fetch("/api/zen/models",{method:"GET",headers:{Accept:"application/json"},signal:W.signal}).then(async me=>{if(!me.ok)return[];const X=await me.json().catch(()=>({}));return(Array.isArray(X?.models)?X.models:[]).map(ee=>{const Pe=typeof ee?.id=="string"?ee.id.trim():"";return Pe?{id:Pe,name:Pe}:null}).filter(ee=>ee!==null)}).then(me=>{_(me)}).catch(me=>{me?.name!=="AbortError"&&console.warn("Failed to load zen utility models:",me)}),()=>{W.abort()}},[]);const se=l.useMemo(()=>H,[H]),oe=l.useMemo(()=>k&&se.some(W=>W.id===k)?k:se.some(W=>W.id===bp)?bp:se[0]?.id??"",[k,se]),ae=l.useCallback(async W=>{const me=W===wc?void 0:W;N(me);try{await Ps({zenModel:me??"",gitProviderId:"",gitModelId:""})}catch(X){console.warn("Failed to save utility model setting:",X)}},[N]);l.useEffect(()=>{if(!i){L(!1),V(!1);return}typeof Notification<"u"&&M(Notification.permission);const W=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;L(W),(async()=>{if(!W){V(!1);return}try{const X=await navigator.serviceWorker.getRegistration();if(!X){V(!1);return}const ce=await X.pushManager.getSubscription();V(!!ce)}catch{V(!1)}})()},[i]);const ne=async W=>{if(n){o(W);return}if(!i){o(W);return}if(W&&typeof Notification<"u"&&Notification.permission==="default")try{const me=await Notification.requestPermission();M(me),me==="granted"?o(!0):q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(me){console.error("Failed to request notification permission:",me),q.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else o(!!(W&&T==="granted"))},xe=n||r||i&&typeof Notification<"u"&&Notification.permission==="granted",te=(W,me,X)=>{w({...g,[W]:{...g[W],[me]:X}})},F=W=>{const me="=".repeat((4-W.length%4)%4),X=(W+me).replace(/-/g,"+").replace(/_/g,"/"),ce=atob(X),ee=new Uint8Array(ce.length);for(let Pe=0;Pe<ce.length;Pe+=1)ee[Pe]=ce.charCodeAt(Pe);return ee},z=async(W,me,X)=>{let ce=null;const ee=new Promise((Pe,Ne)=>{ce=setTimeout(()=>{Ne(new Error(X))},me)});try{return await Promise.race([W,ee])}finally{ce&&clearTimeout(ce)}},Q=async W=>{if(W.active)return;const me=W.installing||W.waiting;me&&me.state!=="activated"&&await z(new Promise(X=>{const ce=()=>{me.state==="activated"&&(me.removeEventListener("statechange",ce),X())};me.addEventListener("statechange",ce),ce()}),15e3,"Service worker activation timed out")},re=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const W=[{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 me=null;for(const X of W)try{const ce=X.opts?navigator.serviceWorker.register("/sw.js",X.opts):navigator.serviceWorker.register("/sw.js");return await z(ce,1e4,`Service worker registration timed out (${X.label})`)}catch(ce){me=ce}throw me instanceof Error?me:new Error("Service worker registration failed")},K=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const W=await navigator.serviceWorker.getRegistration();if(W)return W;const me=await re();try{await me.update()}catch{}return await Q(me),me},le=W=>{const me=W,X=[`type=${typeof W}`,`toString=${String(W)}`,`name=${String(me?.name??"")}`,`message=${String(me?.message??"")}`];let ce="";try{ce=JSON.stringify(W)}catch{}return{summary:X.filter(Boolean).join(" | "),json:ce,stack:typeof me?.stack=="string"?me.stack:""}},Se=async()=>{const W=lr();if(!W?.notifications){q.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await W.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(me){console.error("Test notification failed:",me),q.error(t("settings.notifications.page.toast.testNotificationFailed"))}},ue=async()=>{if(!R){q.error(t("settings.notifications.page.toast.pushUnsupported"));return}const W=lr();if(!W?.push){q.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}B(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const he=await Notification.requestPermission();if(M(he),he!=="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 me=await W.push.getVapidPublicKey();if(!me?.publicKey){q.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const X=await K();await Q(X);const ce=await X.pushManager.getSubscription();if(!("pushManager"in X)||!X.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Pe=(ce??await z(X.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:F(me.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Ne=Pe.keys;if(!Pe.endpoint||!Ne?.p256dh||!Ne.auth)throw new Error("Push subscription missing keys");if(!(await z(W.push.subscribe({endpoint:Pe.endpoint,keys:{p256dh:Ne.p256dh,auth:Ne.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(me){console.error("[Push] Enable failed:",me);const X=le(me);q.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:X.summary})}finally{B(!1)}},je=async()=>{if(!R){V(!1);return}const W=lr();if(!W?.push){q.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}B(!0);try{const X=await(await K()).pushManager.getSubscription();if(!X){V(!1);return}const ce=X.endpoint;await X.unsubscribe(),await W.push.unsubscribe({endpoint:ce}),V(!1),q.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{B(!1)}};return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.delivery.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":a&&xe,onClick:()=>{ne(!(a&&xe))},onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),ne(!(a&&xe)))},children:[s.jsx(bs,{checked:a&&xe,onChange:W=>{ne(W)},ariaLabel:t("settings.notifications.page.delivery.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.enableLabel")})]}),a&&xe&&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:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),d(c==="always"?"hidden-only":"always"))},children:[s.jsx(bs,{checked:c==="always",onChange:W=>d(W?"always":"hidden-only"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.focusedLabel")})]}),s.jsx("div",{className:"py-2",children:s.jsx(ve,{type:"button",variant:"outline",size:"sm",onClick:()=>{Se()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1 px-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.browserPermissionHint")}),T==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),T==="granted"&&!a&&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")})})]}),a&&xe&&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:()=>f(!u),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),f(!u))},children:[s.jsx(bs,{checked:u,onChange:f,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:W=>{(W.key===" "||W.key==="Enter")&&(W.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:()=>h(!b),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),h(!b))},children:[s.jsx(bs,{checked:b,onChange:h,ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.errorLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":v,onClick:()=>x(!v),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),x(!v))},children:[s.jsx(bs,{checked:v,onChange:x,ariaLabel:t("settings.notifications.page.events.questionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.questionLabel")})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.template.title")}),s.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),s.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(W=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(V5[W])}),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(Ut,{value:g[W].title,onChange:me=>te(W,"title",me.target.value),className:"h-7",placeholder:t(xp[W].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(Ut,{value:g[W].message,onChange:me=>te(W,"message",me.target.value),className:"h-7",placeholder:t(xp[W].messageKey)})]})]})]},W))})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.summary.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":y,onClick:()=>S(!y),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),S(!y))},children:[s.jsx(bs,{checked:y,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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.notifications.page.summary.modelTooltip")})]})]})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsxs(ps,{value:oe||wc,onValueChange:ae,children:[s.jsx(hs,{className:"w-fit min-w-[220px]",children:s.jsx(ys,{placeholder:t("settings.notifications.page.summary.notSelected")})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:wc,children:t("settings.notifications.page.summary.notSelected")}),se.map(W=>s.jsx(Ft,{value:W.id,children:W.name},W.id))]})]})})]}),y?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-8 py-1.5 mt-1 border-t border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.thresholdLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.thresholdHint")})]}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(yn,{value:D,onValueChange:j,min:50,max:2e3,step:50,className:"w-20 tabular-nums"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(yp),disabled:D===yp,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(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.lengthLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.lengthHint")})]}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(yn,{value:I,onValueChange:A,min:20,max:500,step:10,className:"w-20 tabular-nums"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>A(vp),disabled:I===vp,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(C,{name:"restart",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(yn,{value:E,onValueChange:P,min:50,max:1e3,step:10,className:"w-20 tabular-nums"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>P(wp),disabled:E===wp,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(C,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})]}),i&&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:R?O:!1,disabled:!R||$,onChange:W=>{W?ue():je()},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",R?"text-foreground":"text-muted-foreground"),children:t("settings.notifications.page.push.enableLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t(R?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),$&&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")})})]})})]})]})},U5=[{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:"Українська"}],W5=t=>{const e=rt.c(45),{modelId:n}=t,{t:r}=mt();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=Ti.getModelStatus(),e[0]=i):i=e[0];const[a,o]=$e.useState(i),[c,d]=$e.useState(!1);let p,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{const j=I=>o(I);return Ti.onModelStatusChange=j,G5},m=[],e[1]=p,e[2]=m):(p=e[1],m=e[2]),$e.useEffect(p,m);const u=Ti.getCurrentModelId(),f=a.state==="downloading"||a.state==="loading";let b,h;e[3]!==a.state?(b=()=>{a.state!=="downloading"&&a.state!=="loading"&&d(!1)},h=[a.state],e[3]=a.state,e[4]=b,e[5]=h):(b=e[4],h=e[5]),$e.useEffect(b,h);let v;e[6]!==n?(v=async()=>{d(!0);try{await Ti.loadModel(n)}catch{}},e[6]=n,e[7]=v):v=e[7];const x=v;if(a.state==="ready"&&u===n){let j;e[8]!==r?(j=r("settings.voice.page.stt.wasmLoaded"),e[8]=r,e[9]=j):j=e[9];let I;return e[10]!==j?(I=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-compact text-green-600 dark:text-green-400",children:j})}),e[10]=j,e[11]=I):I=e[11],I}if(f){let j;e[12]!==a.progress||e[13]!==a.state?(j=a.state==="downloading"?Math.round(a.progress):void 0,e[12]=a.progress,e[13]=a.state,e[14]=j):j=e[14];const I=j;let A;e[15]!==a.state||e[16]!==r?(A=a.state==="downloading"?r("settings.voice.page.stt.wasmDownloading"):r("settings.voice.page.stt.wasmLoading"),e[15]=a.state,e[16]=r,e[17]=A):A=e[17];const E=I!==void 0?` (${I}%)`:"";let P;return e[18]!==A||e[19]!==E?(P=s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[A,E]})}),e[18]=A,e[19]=E,e[20]=P):P=e[20],P}if(a.state==="error"){let j;e[21]!==a.error?(j=s.jsx("span",{className:"typography-ui-compact text-destructive",children:a.error}),e[21]=a.error,e[22]=j):j=e[22];let I;e[23]!==r?(I=r("settings.voice.page.stt.wasmRetry"),e[23]=r,e[24]=I):I=e[24];let A;e[25]!==x||e[26]!==c||e[27]!==I?(A=s.jsx(ve,{variant:"chip",size:"xs",disabled:c,onClick:x,children:I}),e[25]=x,e[26]=c,e[27]=I,e[28]=A):A=e[28];let E;return e[29]!==j||e[30]!==A?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[j,A]}),e[29]=j,e[30]=A,e[31]=E):E=e[31],E}let g;e[32]!==r?(g=r("settings.voice.page.stt.wasmNotLoaded"),e[32]=r,e[33]=g):g=e[33];let w;e[34]!==g?(w=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:g}),e[34]=g,e[35]=w):w=e[35];let y;e[36]!==r?(y=r("settings.voice.page.stt.wasmDownload"),e[36]=r,e[37]=y):y=e[37];let S;e[38]!==x||e[39]!==c||e[40]!==y?(S=s.jsx(ve,{variant:"chip",size:"xs",disabled:c,onClick:x,children:y}),e[38]=x,e[39]=c,e[40]=y,e[41]=S):S=e[41];let D;return e[42]!==S||e[43]!==w?(D=s.jsxs("div",{className:"flex items-center gap-2",children:[w,S]}),e[42]=S,e[43]=w,e[44]=D):D=e[44],D},K5=[{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"}],H5=()=>{const{t}=mt(),{isMobile:e}=rn(),{isSupported:n,language:r,setLanguage:i}=Fb(),a=yt(we=>we.voiceProvider),o=yt(we=>we.setVoiceProvider),c=yt(we=>we.speechRate),d=yt(we=>we.setSpeechRate),p=yt(we=>we.speechPitch),m=yt(we=>we.setSpeechPitch),u=yt(we=>we.speechVolume),f=yt(we=>we.setSpeechVolume),b=yt(we=>we.sayVoice),h=yt(we=>we.setSayVoice),v=yt(we=>we.browserVoice),x=yt(we=>we.setBrowserVoice),g=yt(we=>we.openaiVoice),w=yt(we=>we.setOpenaiVoice),y=yt(we=>we.openaiApiKey),S=yt(we=>we.setOpenaiApiKey),D=yt(we=>we.openaiCompatibleUrl),j=yt(we=>we.setOpenaiCompatibleUrl),I=yt(we=>we.openaiCompatibleVoice),A=yt(we=>we.setOpenaiCompatibleVoice),E=yt(we=>we.openaiCompatibleTtsModel),P=yt(we=>we.setOpenaiCompatibleTtsModel),k=yt(we=>we.showMessageTTSButtons),N=yt(we=>we.sttProvider),T=yt(we=>we.setSttProvider),M=yt(we=>we.sttServerUrl),R=yt(we=>we.setSttServerUrl),L=yt(we=>we.sttModel),O=yt(we=>we.setSttModel),V=yt(we=>we.wasmSttModel),$=yt(we=>we.setWasmSttModel),B=yt(we=>we.sttLanguage),H=yt(we=>we.setSttLanguage),_=yt(we=>we.sttSilenceThresholdDb),se=yt(we=>we.setSttSilenceThresholdDb),oe=yt(we=>we.sttSilenceHoldMs),ae=yt(we=>we.setSttSilenceHoldMs),ne=yt(we=>we.sttTranscribeOnStop),xe=yt(we=>we.setSttTranscribeOnStop),te=yt(we=>we.setShowMessageTTSButtons),F=yt(we=>we.voiceModeEnabled),z=yt(we=>we.setVoiceModeEnabled),Q=yt(we=>we.summarizeMessageTTS),re=yt(we=>we.setSummarizeMessageTTS),K=yt(we=>we.summarizeVoiceConversation),le=yt(we=>we.setSummarizeVoiceConversation),Se=yt(we=>we.summarizeCharacterThreshold),ue=yt(we=>we.setSummarizeCharacterThreshold),je=yt(we=>we.summarizeMaxLength),W=yt(we=>we.setSummarizeMaxLength),[me,X]=$e.useState(!1),[ce,ee]=$e.useState([]),[Pe,Ne]=$e.useState(!1),[Y,he]=$e.useState(null),[ke,be]=$e.useState(!1),[fe,Te]=$e.useState(!1),[Ve,G]=$e.useState(null),[Ie,Oe]=$e.useState(!1),[De,ge]=$e.useState(null),[U,de]=$e.useState([]),[Ee,_e]=$e.useState(!1);$e.useEffect(()=>((async()=>{const tt=await Hl.waitForVoices();de(tt)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{de(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Z=$e.useMemo(()=>U.filter(we=>we.lang).sort((we,tt)=>{const st=we.lang.startsWith("en"),qe=tt.lang.startsWith("en");if(st&&!qe)return-1;if(!st&&qe)return 1;const it=we.lang.localeCompare(tt.lang);return it!==0?it:we.name.localeCompare(tt.name)}),[U]),ie=$e.useCallback(()=>{if(Ee){Hl.cancelSpeech(),_e(!1);return}const we=U.find(it=>it.name===v),tt=we?.name??t("settings.voice.page.preview.browserVoiceFallback"),st=t("settings.voice.page.preview.voiceLine",{voiceName:tt});_e(!0);const qe=new SpeechSynthesisUtterance(st);qe.rate=c,qe.pitch=p,qe.volume=u,we&&(qe.voice=we,qe.lang=we.lang),qe.onend=()=>_e(!1),qe.onerror=()=>_e(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(qe)},[v,U,c,p,u,Ee,t]);$e.useEffect(()=>()=>{Ee&&Hl.cancelSpeech()},[Ee]),$e.useEffect(()=>{if(!F||a!=="openai"&&a!=="openai-compatible"){be(y.trim().length>0);return}(async()=>{try{const qe=(await(await fetch("/api/tts/status")).json()).available,it=y.trim().length>0;be(qe||it)}catch{be(y.trim().length>0)}})()},[y,F,a]),$e.useEffect(()=>{if(!F){X(!1),ee([]);return}fetch("/api/tts/say/status").then(we=>we.json()).then(we=>{if(X(we.available),we.voices){const tt=we.voices.filter((st,qe,it)=>it.findIndex(lt=>lt.name===st.name)===qe).sort((st,qe)=>st.name.localeCompare(qe.name));ee(tt)}}).catch(()=>{X(!1)})},[F]);const Ce=$e.useCallback(async()=>{if(Y){Y.pause(),Y.currentTime=0,he(null),Ne(!1);return}Ne(!0);try{const we=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(!we.ok)throw new Error("Preview failed");const tt=await we.blob(),st=URL.createObjectURL(tt),qe=new Audio(st);qe.onended=()=>{URL.revokeObjectURL(st),he(null),Ne(!1)},qe.onerror=()=>{URL.revokeObjectURL(st),he(null),Ne(!1)},he(qe),await qe.play()}catch{Ne(!1)}},[b,c,Y,t]);$e.useEffect(()=>()=>{Y&&Y.pause()},[Y]);const He=$e.useCallback(async()=>{if(Ve){Ve.pause(),Ve.currentTime=0,G(null),Te(!1);return}Te(!0);try{const we=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:g}),voice:g,speed:c,apiKey:y||void 0})});if(!we.ok){const it=await we.json().catch(()=>({error:"Unknown error"}));throw new Error(it.error||`HTTP ${we.status}`)}const tt=await we.blob(),st=URL.createObjectURL(tt),qe=new Audio(st);qe.onended=()=>{URL.revokeObjectURL(st),G(null),Te(!1)},qe.onerror=()=>{URL.revokeObjectURL(st),G(null),Te(!1)},G(qe),await qe.play()}catch{Te(!1)}},[g,c,Ve,y,t]);$e.useEffect(()=>()=>{Ve&&Ve.pause()},[Ve]);const Ge=$e.useCallback(async()=>{if(De){De.pause(),De.currentTime=0,ge(null),Oe(!1);return}if(D.trim()){Oe(!0);try{const we=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:I,model:E||void 0,speed:c,baseURL:D})});if(!we.ok){const it=await we.json().catch(()=>({error:"Unknown error"}));throw new Error(it.error||`HTTP ${we.status}`)}const tt=await we.blob(),st=URL.createObjectURL(tt),qe=new Audio(st);qe.onended=()=>{URL.revokeObjectURL(st),ge(null),Oe(!1)},qe.onerror=()=>{URL.revokeObjectURL(st),ge(null),Oe(!1)},ge(qe),await qe.play()}catch{Oe(!1)}}},[D,I,E,c,De,t]);$e.useEffect(()=>()=>{De&&De.pause()},[De]);const Xe="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.voiceSetup")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":F,onClick:()=>z(!F),onKeyDown:we=>{(we.key===" "||we.key==="Enter")&&(we.preventDefault(),z(!F))},children:[s.jsx(bs,{checked:F,onChange:z,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),F&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:"OpenAI:"})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":a==="browser",onClick:()=>o("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":a==="openai",onClick:()=>o("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":a==="openai-compatible",onClick:()=>o("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),me&&s.jsxs(ve,{variant:"chip",size:"xs","aria-pressed":a==="say",onClick:()=>o("say"),className:"!font-normal",children:[s.jsx(C,{name:"apple",className:"w-3.5 h-3.5 mr-0.5"}),t("settings.voice.page.provider.say")]})]})]})}),a==="openai"&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:pe("typography-ui-label text-foreground",!ke&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:pe("typography-meta ml-2",ke?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(ke&&!y?"settings.voice.page.field.apiKeyHintUsingConfig":ke?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:y,onChange:we=>S(we.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),y&&s.jsx("button",{type:"button",onClick:()=>S(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(C,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="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",!D.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.serverUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:D,onChange:we=>j(we.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),D&&s.jsx("button",{type:"button",onClick:()=>j(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(C,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:E,onChange:we=>P(we.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:I,onChange:we=>A(we.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:Ge,title:t("settings.voice.page.actions.preview"),disabled:!D.trim(),children:Ie?s.jsx(C,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(C,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.voice")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[a==="openai"&&ke&&s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:g,onValueChange:w,children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(fs,{children:K5.map(we=>s.jsx(Ft,{value:we.value,children:we.label},we.value))})]}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:He,title:t("settings.voice.page.actions.preview"),children:fe?s.jsx(C,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(C,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&me&&ce.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:b,onValueChange:h,children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(fs,{children:ce.map(we=>s.jsx(Ft,{value:we.name,children:we.name},we.name))})]}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:Ce,title:t("settings.voice.page.actions.preview"),children:Pe?s.jsx(C,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(C,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Z.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:v||"$auto",onValueChange:we=>x(we==="$auto"?"":we),children:[s.jsx(hs,{className:"w-fit max-w-[200px]",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"$auto",children:t("settings.voice.page.field.auto")}),Z.map(we=>s.jsxs(Ft,{value:we.name,children:[we.name," (",we.lang,")"]},we.name))]})]}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:ie,title:t("settings.voice.page.actions.preview"),children:Ee?s.jsx(C,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(C,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechRate")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:c,onChange:we=>d(Number(we.target.value)),disabled:!n,className:Xe}),s.jsx(yn,{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:we=>m(Number(we.target.value)),disabled:!n,className:Xe}),s.jsx(yn,{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:we=>f(Number(we.target.value)),disabled:!n,className:Xe}),e?s.jsx(yn,{value:Math.round(u*100),onValueChange:we=>f(we/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:i,disabled:!n,children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(fs,{children:U5.map(we=>s.jsx(Ft,{value:we.value,children:we.label},we.value))})]})})]})]})]})]}),F&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.speechRecognition")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.sttBrowser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":N==="browser",onClick:()=>T("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":N==="server",onClick:()=>T("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":N==="wasm",onClick:()=>T("wasm"),className:"!font-normal",children:t("settings.voice.page.provider.wasm")})]})]})}),N==="server"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ne,onClick:()=>xe(!ne),onKeyDown:we=>{(we.key===" "||we.key==="Enter")&&(we.preventDefault(),xe(!ne))},children:[s.jsx(bs,{checked:ne,onChange:xe,ariaLabel:t("settings.voice.page.field.transcribeOnStopAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.transcribeOnStop")})]}),!Lb.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",!M.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttServerUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:M,onChange:we=>R(we.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),M&&s.jsx("button",{type:"button",onClick:()=>R(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(C,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:L,onChange:we=>O(we.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:B,onChange:we=>H(we.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:_,onChange:we=>se(Number(we.target.value)),className:Xe}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[_," 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:oe,onChange:we=>ae(Number(we.target.value)),className:Xe}),s.jsx(yn,{value:oe,onValueChange:ae,min:500,max:3e3,step:100,className:"w-20 tabular-nums"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.millisecondsUnit")})]})]})]}),N==="wasm"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:t("settings.voice.page.stt.wasmModel")}),s.jsxs(ps,{value:V,onValueChange:$,children:[s.jsx(hs,{className:"mt-0.5",children:s.jsx(ys,{placeholder:t("settings.voice.page.stt.wasmModel")})}),s.jsx(fs,{children:fu.map(we=>s.jsx(Ft,{value:we.id,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{children:we.name}),s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[we.size," · ",we.languages]})]})},we.id))})]}),s.jsx("p",{className:"typography-ui-compact text-muted-foreground mt-0.5",children:fu.find(we=>we.id===V)?.description})]}),s.jsx(W5,{modelId:V})]})]})]}),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":k,onClick:()=>te(!k),onKeyDown:we=>{(we.key===" "||we.key==="Enter")&&(we.preventDefault(),te(!k))},children:[s.jsx(bs,{checked:k,onChange:te,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":Q,onClick:()=>re(!Q),onKeyDown:we=>{(we.key===" "||we.key==="Enter")&&(we.preventDefault(),re(!Q))},children:[s.jsx(bs,{checked:Q,onChange:re,ariaLabel:t("settings.voice.page.field.summarizeBeforePlaybackAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.summarizeBeforePlayback")})]}),F&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":K,onClick:()=>le(!K),onKeyDown:we=>{(we.key===" "||we.key==="Enter")&&(we.preventDefault(),le(!K))},children:[s.jsx(bs,{checked:K,onChange:le,ariaLabel:t("settings.voice.page.field.summarizeVoiceModeResponsesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.summarizeVoiceModeResponses")})]}),(Q||K)&&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:Se,onChange:we=>ue(Number(we.target.value)),className:Xe}),s.jsx(yn,{value:Se,onValueChange:ue,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:je,onChange:we=>W(Number(we.target.value)),className:Xe}),s.jsx(yn,{value:je,onValueChange:W,min:50,max:2e3,step:50,className:"w-16 tabular-nums"})]})]})]})]}),F&&n&&s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t("settings.voice.page.hint.shiftClickPrefix")," ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Shift"})," + ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Click"})," ",t("settings.voice.page.hint.shiftClickSuffix")]})})]})]})};function G5(){Ti.onModelStatusChange=null}const jc=[{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}],Nc=[{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}],q5="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",J5="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",jp=[{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"}],Q5=[".yml",".yaml",".json"],Y5="settings.openchamber.tunnel.error.invalidConfigExtension",Ai=t=>{const e=t.trim().toLowerCase();return Q5.some(n=>e.endsWith(n))},ig=t=>t==="cloudflare"?"Cloudflare":t,Np=t=>{const e=rt.c(11),{provider:n}=t;let r;e[0]!==n?(r=ig(n),e[0]=n,e[1]=r):r=e[1];const i=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(C,{name:"cloud",className:c}),e[4]=c,e[5]=d):d=e[5];let p;e[6]!==i?(p=s.jsx("span",{children:i}),e[6]=i,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},ma=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Sp=(t,e,n)=>t.find(i=>i.ms===e)?.value||n,kp=t=>{const e=Math.max(0,t),n=Math.floor(e/1e3),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60;return r>0?`${r}h ${i}m`:i>0?`${i}m ${a}s`:`${a}s`},X5=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Ko=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()}},Z5=t=>{if(!Array.isArray(t))return[];const e=new Set,n=new Set,r=[];for(const i of t){if(!i||typeof i!="object")continue;const a=i,o=typeof a.id=="string"?a.id.trim():"",c=typeof a.name=="string"?a.name.trim():"",d=Ko(typeof a.hostname=="string"?a.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},eC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,tC=()=>{const{t}=mt(),e=l.useCallback(ye=>t(ye),[t]),[n,r]=l.useState("checking"),[i,a]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(null),[h,v]=l.useState(!1),[x,g]=l.useState(!1),[w,y]=l.useState(!1),[S,D]=l.useState("cloudflare"),[j,I]=l.useState([]),[A,E]=l.useState("quick"),[P,k]=l.useState(null),[N,T]=l.useState([]),[M,R]=l.useState({}),[L,O]=l.useState(""),[V,$]=l.useState({}),[B,H]=l.useState(new Set),[_,se]=l.useState(!1),[oe,ae]=l.useState(""),[ne,xe]=l.useState(""),[te,F]=l.useState(""),[z,Q]=l.useState(1800*1e3),[re,K]=l.useState(480*60*1e3),[le,Se]=l.useState(""),[ue,je]=l.useState([]),[W,me]=l.useState(()=>Date.now()),[X,ce]=l.useState(null),ee=t(Y5),Pe=l.useRef(null),Ne=l.useMemo(()=>P?!Ai(P):!1,[P]),Y=l.useMemo(()=>N.find(ye=>ye.id===L)||N[0]||null,[N,L]),he=l.useMemo(()=>ue.map(ye=>{const Je=ye.expiresAt<=W,Be=ye.status==="active"&&!Je,ze=Be?kp(ye.expiresAt-W):ye.inactiveReason==="expired"||Je?"expired":"inactive",nt=ze==="expired"?t("settings.openchamber.tunnel.state.expired"):ye.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),Ye=ma(ye.mode);return{...ye,isActive:Be,mode:Ye,remainingTextForSession:ze,inactiveLabel:nt}}),[W,ue,t]),ke=l.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>W:!1,[W,i?.bootstrapExpiresAt,i?.connectUrl]),be=l.useMemo(()=>!i||n!=="active"&&n!=="stopping"?!1:o===A,[o,n,i,A]),fe=l.useMemo(()=>!i||n!=="active"||!o?!1:o!==A,[o,n,i,A]),Te=l.useMemo(()=>{if(typeof X=="number"&&Number.isFinite(X)&&X>0)return X;if(typeof window>"u")return null;const ye=Number(window.location.port);return Number.isFinite(ye)&&ye>0?ye:null},[X]),Ve=l.useCallback(async ye=>{await Qn(ye)},[]),G=l.useCallback(async ye=>{try{const[Je,Be,ze,nt]=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})]),Ye=await Je.json(),Ue=await Be.json(),vt=ze.ok?await ze.json():{},Et=nt.ok?await nt.json():{},Gt=Ue.ttlConfig?.bootstrapTtlMs??(vt?.tunnelBootstrapTtlMs===null?null:typeof vt?.tunnelBootstrapTtlMs=="number"?vt.tunnelBootstrapTtlMs:1800*1e3),ts=typeof Ue.ttlConfig?.sessionTtlMs=="number"?Ue.ttlConfig.sessionTtlMs:typeof vt?.tunnelSessionTtlMs=="number"?vt.tunnelSessionTtlMs:480*60*1e3,Nt=ma(Ue.mode??vt?.tunnelMode),St=typeof vt?.tunnelProvider=="string"&&vt.tunnelProvider.trim().length>0?vt.tunnelProvider.trim().toLowerCase():"cloudflare",Zt=typeof vt?.managedLocalTunnelConfigPath=="string"&&vt.managedLocalTunnelConfigPath.trim()||null,ut=Z5(Ue?.managedRemoteTunnelPresets),Xt=typeof Ue.managedRemoteTunnelHostname=="string"?Ue.managedRemoteTunnelHostname:"",as=ut.length>0?ut:Xt?[{id:`legacy-${Ko(Xt)}`,name:Xt,hostname:Ko(Xt)}]:[],Bt=as[0]?.id||"";if(Q(Gt),K(ts),D(St),I(Array.isArray(Et?.providers)?Et.providers:[]),E(Nt),k(Zt),T(as),O(Bt),je(Array.isArray(Ue.activeSessions)?Ue.activeSessions:[]),c(Ue.activeTunnelMode?ma(Ue.activeTunnelMode):Ue.active&&Ue.mode?ma(Ue.mode):null),H(new Set(Array.isArray(Ue.managedRemoteTunnelTokenPresetIds)?Ue.managedRemoteTunnelTokenPresetIds:[])),ce(typeof Ue.localPort=="number"?Ue.localPort:null),Ue.active&&Ue.url){a({url:Ue.url,connectUrl:null,bootstrapExpiresAt:typeof Ue.bootstrapExpiresAt=="number"?Ue.bootstrapExpiresAt:null}),r("active");return}r(Ye.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(!i?.connectUrl){p(null);return}let ye=!1;return ix.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Je=>{ye||p(Je)}).catch(()=>{ye||p(null)}),()=>{ye=!0}},[i?.connectUrl]),l.useEffect(()=>{if(!i?.bootstrapExpiresAt){Se(t("settings.openchamber.tunnel.state.noExpiry"));return}let ye=null,Je=Date.now();const Be=()=>{const Ye=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;Ye<=0?Se(t("settings.openchamber.tunnel.state.expired")):Se(kp(Ye))},ze=()=>{const Ye=Date.now();Ye-Je>=1e3&&(Be(),Je=Ye),ye=requestAnimationFrame(ze)};Be(),(typeof document>"u"||document.visibilityState==="visible")&&(ye=requestAnimationFrame(ze));const nt=()=>{document.visibilityState==="visible"&&ye===null?ye=requestAnimationFrame(ze):document.visibilityState!=="visible"&&ye!==null&&(cancelAnimationFrame(ye),ye=null)};return document.addEventListener("visibilitychange",nt),()=>{document.removeEventListener("visibilitychange",nt),ye!==null&&cancelAnimationFrame(ye)}},[t,i?.bootstrapExpiresAt]),l.useEffect(()=>{let ye=null,Je=Date.now();const Be=()=>{const nt=Date.now();nt-Je>=1e3&&(me(nt),Je=nt),ye=requestAnimationFrame(Be)};(typeof document>"u"||document.visibilityState==="visible")&&(ye=requestAnimationFrame(Be));const ze=()=>{document.visibilityState==="visible"&&ye===null?ye=requestAnimationFrame(Be):document.visibilityState!=="visible"&&ye!==null&&(cancelAnimationFrame(ye),ye=null)};return document.addEventListener("visibilitychange",ze),()=>{document.removeEventListener("visibilitychange",ze),ye!==null&&cancelAnimationFrame(ye)}},[]),l.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let ye=!1;const Je=async()=>{try{const ze=await fetch("/api/openchamber/tunnel/status");if(!ze.ok||ye)return;const nt=await ze.json();if(ye)return;je(Array.isArray(nt.activeSessions)?nt.activeSessions:[]),H(new Set(Array.isArray(nt.managedRemoteTunnelTokenPresetIds)?nt.managedRemoteTunnelTokenPresetIds:[])),ce(typeof nt.localPort=="number"?nt.localPort:null)}catch{}},Be=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Je()},5e3);return()=>{ye=!0,window.clearInterval(Be)}},[n]);const Ie=l.useCallback(async ye=>{y(!0);try{await Ps(ye),Object.prototype.hasOwnProperty.call(ye,"tunnelMode")&&ye.tunnelMode&&E(ye.tunnelMode),Object.prototype.hasOwnProperty.call(ye,"tunnelProvider")&&typeof ye.tunnelProvider=="string"&&D(ye.tunnelProvider),Object.prototype.hasOwnProperty.call(ye,"managedLocalTunnelConfigPath")&&k(ye.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ye,"managedRemoteTunnelPresets")&&ye.managedRemoteTunnelPresets&&T(ye.managedRemoteTunnelPresets)}catch{q.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{y(!1)}},[t]),Oe=l.useCallback(async(ye,Je)=>{g(!0);try{await Ps({tunnelBootstrapTtlMs:ye,tunnelSessionTtlMs:Je})}catch{q.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),De=l.useCallback(async ye=>{const Je=ye.token.trim();if(Je)try{const Be={...V,[ye.presetId]:Je};await Ps({managedRemoteTunnelPresetTokens:Be}),H(ze=>{const nt=new Set(ze);return nt.add(ye.presetId),nt})}catch{q.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[V,t]),ge=l.useCallback(async ye=>{b(null),u(null),await Ie({tunnelProvider:ye})},[Ie]),U=l.useCallback(async()=>{const ye=await Ob({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ye.success&&typeof ye.path=="string"&&ye.path.trim().length>0){const Je=ye.path.trim();if(!Ai(Je)){q.error(ee);return}k(Je),await Ie({managedLocalTunnelConfigPath:Je});return}Pe.current?.click()},[ee,Ie]),de=l.useCallback(ye=>{const Je=ye.trim();k(Je.length>0?Je:null)},[]),Ee=l.useCallback(async()=>{if(P&&!Ai(P)){q.error(ee);return}await Ie({managedLocalTunnelConfigPath:P})},[ee,P,Ie]),_e=l.useCallback(async()=>{k(null),await Ie({managedLocalTunnelConfigPath:null})},[Ie]),Z=l.useCallback(async ye=>{const Je=ye.target.files?.[0];if(!Je)return;const Be=Je.name.trim();if(Be.length!==0){if(!Ai(Be)){q.error(ee);return}k(Be),await Ie({managedLocalTunnelConfigPath:Be}),ye.target.value=""}},[ee,Ie]),ie=l.useCallback(async()=>{if(u(null),b(null),A==="managed-local"&&P&&!Ai(P)){u(ee),q.error(ee);return}r("starting");try{let ye="",Je="";if(A==="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,Je=(V[Y.id]||"").trim(),await Ie({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const Be=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:S,mode:A,...A==="managed-remote"&&Y?{managedRemoteTunnelPresetId:Y.id,managedRemoteTunnelPresetName:Y.name}:{},...A==="managed-remote"&&ye?{managedRemoteTunnelHostname:ye}:{},...A==="managed-remote"&&Je?{managedRemoteTunnelToken:Je}:{},...A==="managed-local"&&P?{configPath:P}:{}})}),ze=await Be.json();if(!Be.ok||!ze.ok){if(A==="managed-remote"&&typeof ze.error=="string"&&ze.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(ze.error||t("settings.openchamber.tunnel.toast.startFailed")),q.error(ze.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const nt=typeof ze.url=="string"?ze.url:"";if(!nt){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),q.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(a({url:nt,connectUrl:typeof ze.connectUrl=="string"?ze.connectUrl:null,bootstrapExpiresAt:typeof ze.bootstrapExpiresAt=="number"?ze.bootstrapExpiresAt:null}),c(ze.activeTunnelMode?ma(ze.activeTunnelMode):ze.mode?ma(ze.mode):A),je(Array.isArray(ze.activeSessions)?ze.activeSessions:[]),Array.isArray(ze.managedRemoteTunnelTokenPresetIds)&&H(new Set(ze.managedRemoteTunnelTokenPresetIds)),typeof ze.localPort=="number"&&ce(ze.localPort),typeof ze.mode=="string"&&E(ma(ze.mode)),r("active"),ze.replacedTunnel){const Ye=typeof ze.revokedBootstrapCount=="number"?ze.revokedBootstrapCount:0,Ue=typeof ze.invalidatedSessionCount=="number"?ze.invalidatedSessionCount:0;Ye===1&&Ue===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):Ye===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Ue})):Ue===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:Ye})):q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:Ye,invalidatedSessionCount:Ue}))}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"))}},[ee,N,Ie,Y,V,t,S,A,P]),Ce=l.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const ye=await fetch("/api/openchamber/tunnel/status");if(ye.ok){const Je=await ye.json();je(Array.isArray(Je.activeSessions)?Je.activeSessions:[]),H(new Set(Array.isArray(Je.managedRemoteTunnelTokenPresetIds)?Je.managedRemoteTunnelTokenPresetIds:[])),ce(typeof Je.localPort=="number"?Je.localPort:null)}a(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]),He=l.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),v(!0),q.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>v(!1),2e3)}catch{q.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,i?.connectUrl]),Ge=l.useCallback(async ye=>{const Je=jc.find(Be=>Be.value===ye);Je&&(Q(Je.ms),await Oe(Je.ms,re))},[Oe,re]),Xe=l.useCallback(async ye=>{const Je=Nc.find(Be=>Be.value===ye);!Je||Je.ms===null||(K(Je.ms),await Oe(z,Je.ms))},[z,Oe]),we=l.useCallback(async ye=>{b(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await Ie({tunnelMode:ye,managedRemoteTunnelPresets:N})},[N,Ie,n]),tt=l.useCallback(async(ye,Je)=>{try{await Ps({managedRemoteTunnelPresets:Je})}catch{q.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),st=l.useCallback(ye=>{const Je=N.find(Be=>Be.id===ye);Je&&(O(Je.id),b(null),tt(Je,N))},[N,tt]),qe=l.useCallback(async()=>{const ye=oe.trim(),Je=Ko(ne),Be=te.trim();if(!ye){q.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Je){q.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Be){q.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(Ye=>Ye.hostname===Je)){q.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const ze={id:eC(),name:ye,hostname:Je},nt=[...N,ze];T(nt),O(ze.id),R(Ye=>({...Ye,[ze.id]:!0})),$(Ye=>({...Ye,[ze.id]:Be})),b(null),se(!1),ae(""),xe(""),F(""),await Ie({tunnelMode:"managed-remote",managedRemoteTunnelPresets:nt,managedRemoteTunnelPresetTokens:{...V,[ze.id]:Be}}),await De({presetId:ze.id,presetName:ze.name,hostname:ze.hostname,token:Be}),q.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,ne,oe,te,De,Ie,V,t]),it=l.useCallback(async ye=>{const Je=N.find(Ue=>Ue.id===ye);if(!Je)return;const Be=N.filter(Ue=>Ue.id!==Je.id),ze=Be[0]?.id||"",nt=L===Je.id?ze:L,Ye=Object.fromEntries(Object.entries(V).filter(([Ue,vt])=>Ue!==Je.id&&vt.trim().length>0));T(Be),O(nt),R(Ue=>{const vt={...Ue};return delete vt[Je.id],vt}),$(Ue=>{const vt={...Ue};return delete vt[Je.id],vt}),H(Ue=>{const vt=new Set(Ue);return vt.delete(Je.id),vt}),b(null),await Ie({managedRemoteTunnelPresets:Be,managedRemoteTunnelPresetTokens:Ye}),q.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,Ie,L,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")})]}),he.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(C,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:he.map(ye=>{const Je=ye.mode==="quick",Be=ye.mode==="managed-remote",ze=Je?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Be?"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)]",nt=ye.isActive?Je?"text-[var(--status-warning)]":Be?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",Ye=t(Je?"settings.openchamber.tunnel.badge.quick":Be?"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(C,{name:"checkbox-blank-circle-fill",className:pe("size-2.5 shrink-0",nt)}),s.jsx("span",{className:pe("typography-micro rounded border px-1.5 py-0.5 uppercase",ze),children:Ye}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:X5(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(C,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.notAvailable.cloudflaredNotFound")}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:"brew install cloudflared"})]})]})}),n!=="not-available"&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(ps,{value:S,onValueChange:ye=>{ge(ye)},disabled:w||n==="starting"||n==="stopping",children:[s.jsx(hs,{className:"max-w-[16rem]",children:s.jsx(ys,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:ig(S)})}),s.jsxs(fs,{children:[j.length>0?j.map(ye=>s.jsx(Ft,{value:ye.provider,children:s.jsx(Np,{provider:ye.provider})},ye.provider)):s.jsx(Ft,{value:"cloudflare",children:s.jsx(Np,{provider:"cloudflare"})}),s.jsx(Ft,{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:jp.map(ye=>s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":A===ye.value,className:"!font-normal",onClick:()=>{we(ye.value)},disabled:w||n==="starting"||n==="stopping",children:e(ye.labelKey)})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:e(ye.tooltipKey)})]},ye.value))})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(ps,{value:Sp(jc,z,"1800000"),onValueChange:ye=>{Ge(ye)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(hs,{className:"max-w-[11rem] min-w-0",children:s.jsx(ys,{className:"truncate"})}),s.jsx(fs,{children:jc.map(ye=>s.jsx(Ft,{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:Sp(Nc,re,"28800000"),onValueChange:ye=>{Xe(ye)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(hs,{className:"max-w-[11rem] min-w-0",children:s.jsx(ys,{className:"truncate"})}),s.jsx(fs,{children:Nc.map(ye=>s.jsx(Ft,{value:ye.value,children:ye.label},ye.value))})]})]})]}),A==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(C,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),A==="managed-remote"&&s.jsxs("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Te=="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:",Te]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(ve,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>se(ye=>!ye),disabled:n==="starting"||n==="stopping"||w,children:[s.jsx(C,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),N.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:N.map((ye,Je)=>{const Be=V[ye.id]||"",ze=B.has(ye.id),nt=M[ye.id]??!1;return s.jsx("div",{className:pe(Je<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(cr,{open:nt,onOpenChange:Ye=>{R(Ue=>({...Ue,[ye.id]:Ye})),Ye&&st(ye.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(jr,{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:[nt?s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(C,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:ye.name})]}),s.jsx(ve,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:ye.name}),onClick:()=>{it(ye.id)},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(dr,{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(Ut,{type:"password",value:Be,onChange:Ye=>{const Ue=Ye.target.value;b(null),$(vt=>({...vt,[ye.id]:Ue}))},onBlur:Ye=>{const Ue=Ye.currentTarget.value.trim();Ue&&De({presetId:ye.id,presetName:ye.name,hostname:ye.hostname,token:Ue})},placeholder:t(ze?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Be.trim().length===0,onClick:()=>{De({presetId:ye.id,presetName:ye.name,hostname:ye.hostname,token:Be})},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")}),_&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Ut,{value:oe,onChange:ye=>ae(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Ut,{value:ne,onChange:ye=>xe(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Ut,{type:"password",value:te,onChange:ye=>F(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),typeof Te=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Te]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{qe()},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{se(!1),ae(""),xe(""),F("")},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground/70 hover:text-foreground","aria-label":t("settings.openchamber.tunnel.field.managedRemoteTokenInfoAria"),children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!Y&&f&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:f})]}),A==="managed-local"&&s.jsx("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Pe,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:ye=>{Z(ye)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ut,{value:P||"",onChange:ye=>{de(ye.target.value)},onBlur:()=>{Ee()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||w}),s.jsx(ve,{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(C,{name:"folder",className:"size-3.5"})}),P&&s.jsx(ve,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{_e()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(C,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(P?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Ne&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ee})]})}),!be&&s.jsxs("div",{className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(C,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[A==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ve(q5)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(C,{name:"external-link",className:"size-3.5"})]})]}),A==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ve(J5)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(C,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:e(jp.find(ye=>ye.value===A)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),A==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(ps,{value:L||(N[0]?.id??""),onValueChange:ye=>{st(ye)},disabled:w||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(hs,{children:s.jsx(ys,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Y?.name})}),s.jsx(fs,{fitContent:!0,children:N.map(ye=>s.jsx(Ft,{value:ye.id,children:ye.name},ye.id))})]})]}),fe&&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(C,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(ve,{size:"sm",variant:"outline",onClick:ie,disabled:n==="starting"||w||A==="managed-remote"&&!Y||A==="managed-local"&&Ne,className:pe(lt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),be&&i&&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:i.url})]}),ke&&i.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:i.connectUrl}),s.jsxs(ve,{size:"sm",variant:"ghost",onClick:He,className:"shrink-0 gap-1.5",children:[h?s.jsx(C,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(C,{name:"file-copy",className:"size-3.5"}),t(h?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",i.bootstrapExpiresAt?le:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[d?s.jsx("img",{src:d,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ve,{size:"sm",variant:"outline",onClick:ie,disabled:n==="stopping"||w||A==="managed-local"&&Ne,className:lt,children:[s.jsx(C,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(ve,{size:"sm",variant:"ghost",onClick:Ce,disabled:n==="stopping"||w,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&m&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m}),s.jsx(ve,{size:"sm",variant:"ghost",onClick:ie,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},og=()=>{const{t}=mt(),[e,n]=$e.useState(""),[r,i]=$e.useState(!0),[a,o]=$e.useState(!1);$e.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 f=typeof u.opencodeBinary=="string"?u.opencodeBinary.trim():"";n(f)}catch{}finally{p||i(!1)}})(),()=>{p=!0}},[]);const c=$e.useCallback(async()=>{if(typeof window>"u"||!wn()||!ka())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=$e.useCallback(async()=>{o(!0);try{await Ps({opencodeBinary:e.trim()}),await ni({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{o(!1)}},[t,e]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.opencodeCli.title")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Pt,{sideOffset:8,className:"max-w-xs",children:[t("settings.openchamber.opencodeCli.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs",children:"opencode"}),t("settings.openchamber.opencodeCli.tooltipSuffix")]})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-3",children:[s.jsx("div",{className:"flex min-w-0 flex-col shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.opencodeCli.field.binaryPath")})}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:w-[20rem]",children:[s.jsx(Ut,{value:e,onChange:p=>n(p.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:r||a,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),s.jsx(ve,{type:"button",variant:"outline",size:"xs",onClick:c,disabled:r||a||!wn()||!ka(),className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(C,{name:"folder",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"typography-micro text-muted-foreground/70",children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]})}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(ve,{type:"button",size:"xs",onClick:d,disabled:r||a,className:"shrink-0 !font-normal",children:t(a?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},lg=()=>{const{t}=mt(),e=wn()&&Ur(),[n,r]=$e.useState(!1),[i,a]=$e.useState(!1),[o,c]=$e.useState(!0),[d,p]=$e.useState(!1),[m,u]=$e.useState(null),[f,b]=$e.useState(null);$e.useEffect(()=>{if(!e){c(!1);return}let y=!1;return(async()=>{try{const 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 D=await S.json().catch(()=>null);if(y)return;const j=D?.desktopLanAccessEnabled===!0;r(j),a(j),u(null)}catch(S){y||u(S instanceof Error?S.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{y||c(!1)}})(),()=>{y=!0}},[e,t]),$e.useEffect(()=>{if(!e||!i){b(null);return}let y=!1;return(async()=>{const S=await $b();y||b(S)})(),()=>{y=!0}},[i,e]);const h=i!==n,v=$e.useMemo(()=>{if(typeof window>"u")return null;const y=Number(window.location.port);return Number.isFinite(y)&&y>0?y:null},[]),x=i&&f&&v?`http://${f}:${v}`:null,g=$e.useCallback(()=>{a(y=>!y)},[]),w=$e.useCallback(async()=>{if(h){p(!0),u(null);try{if(!(await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:i})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(i),!await _h())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(y){u(y instanceof Error?y.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),p(!1)}}},[i,h,t]);return e?s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.desktopNetwork.title")})}),s.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:g,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),g())},children:[s.jsx(bs,{checked:i,onChange:g,ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:o||d}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.desktopNetwork.field.allowLanAccess")}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription")}),s.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")})]})]}),m?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:m}):null,x?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(h&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:x})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(ve,{type:"button",size:"xs",onClick:w,disabled:o||d||!h,className:"shrink-0 !font-normal",children:t(d?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},sC=new Set(["shift","control","alt","meta"]),nC=t=>{if(sC.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=_b(t.key);return n?(e.push(n),Ya(e.join("+"))):null},rC=()=>{const t=rt.c(58),{t:e}=mt();let n;t[0]!==e?(n=te=>e(te),t[0]=e,t[1]=n):n=t[1];const r=n,i=Me(aC),a=Me(iC),o=Me(oC),c=Me(lC);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=Bb(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(te,F)=>{const z=`settings.openchamber.keyboardShortcuts.action.${te}.label`,Q=r(z);return Q===z?F:Q},t[3]=r,t[4]=m):m=t[4];const u=m,[f,b]=l.useState(null);let h;t[5]===Symbol.for("react.memo_cache_sentinel")?(h={},t[5]=h):h=t[5];const[v,x]=l.useState(h),[g,w]=l.useState(""),[y,S]=l.useState(""),[D,j]=l.useState(null);let I;t[6]!==i?(I=(te,F)=>{const z=Ya(F);for(const Q of p){if(Q.id===te)continue;const re=Vr(Q.id,i);if(Ya(re)===z)return Q.id}return null},t[6]=i,t[7]=I):I=t[7];const A=I;let E;t[8]!==A||t[9]!==a||t[10]!==e?(E=(te,F)=>{const z=Ya(F),Q=A(te,z);if(Q){j({actionId:te,combo:z,conflictActionId:Q}),w("");return}a(te,z),j(null),w(""),S(gu(z)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(re=>{const K={...re};return delete K[te],K})},t[8]=A,t[9]=a,t[10]=e,t[11]=E):E=t[11];const P=E;let k;t[12]!==D||t[13]!==a||t[14]!==e?(k=()=>{D&&(a(D.conflictActionId,Vb),a(D.actionId,D.combo),j(null),w(""),S(gu(D.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(te=>{const F={...te};return delete F[D.actionId],F}))},t[12]=D,t[13]=a,t[14]=e,t[15]=k):k=t[15];const N=k;let T;t[16]!==o?(T=te=>{o(te),x(F=>{const z={...F};return delete z[te],z}),j(null),w(""),S("")},t[16]=o,t[17]=T):T=t[17];const M=T;let R;t[18]!==e?(R=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=R):R=t[19];let L;t[20]!==R?(L=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:R}),t[20]=R,t[21]=L):L=t[21];let O;t[22]!==c?(O=()=>{c(),x({}),j(null),w(""),S("")},t[22]=c,t[23]=O):O=t[23];let V;t[24]!==e?(V=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=V):V=t[25];let $;t[26]!==O||t[27]!==V?($=s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:O,children:V}),t[26]=O,t[27]=V,t[28]=$):$=t[28];let B;t[29]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(It,{asChild:!0,children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=B):B=t[29];let H;t[30]!==e?(H=e("settings.openchamber.keyboardShortcuts.tooltip"),t[30]=e,t[31]=H):H=t[31];let _;t[32]!==H?(_=s.jsxs(Ct,{children:[B,s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:H})]}),t[32]=H,t[33]=_):_=t[33];let se;t[34]!==$||t[35]!==_||t[36]!==L?(se=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[L,$,_]})}),t[34]=$,t[35]=_,t[36]=L,t[37]=se):se=t[37];let oe;t[38]!==N||t[39]!==g||t[40]!==D||t[41]!==e||t[42]!==y?(oe=(g||y||D)&&s.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[D&&s.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),s.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",onClick:N,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>j(null),children:e("settings.common.actions.cancel")})]})]}),g&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:g}),y&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:y})]}),t[38]=N,t[39]=g,t[40]=D,t[41]=e,t[42]=y,t[43]=oe):oe=t[43];let ae;t[44]!==u||t[45]!==f||t[46]!==v||t[47]!==M||t[48]!==P||t[49]!==i||t[50]!==e?(ae=p.map((te,F)=>{const z=Vr(te.id,i),Q=v[te.id],re=Q??z,K=typeof Q=="string"&&Ya(Q)!==Ya(z);return s.jsxs("div",{className:pe("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",F>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:u(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(Ut,{readOnly:!0,value:f===te.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):yl(re),onFocus:()=>{b(te.id),w("")},onBlur:()=>{f===te.id&&b(null)},onKeyDown:le=>{if(le.preventDefault(),le.stopPropagation(),le.key==="Escape"){b(null);return}const Se=nC(le);Se&&(x(ue=>({...ue,[te.id]:Se})),b(null),j(null),w(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(ve,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const le=v[te.id];if(!le){w(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}P(te.id,le)},disabled:!K,children:e("settings.common.actions.saveChanges")}),s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>M(te.id),children:e("settings.common.actions.reset")})]})]},te.id)}),t[44]=u,t[45]=f,t[46]=v,t[47]=M,t[48]=P,t[49]=i,t[50]=e,t[51]=ae):ae=t[51];let ne;t[52]!==ae?(ne=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:ae}),t[52]=ae,t[53]=ne):ne=t[53];let xe;return t[54]!==se||t[55]!==oe||t[56]!==ne?(xe=s.jsxs("div",{className:"mb-8",children:[se,oe,ne]}),t[54]=se,t[55]=oe,t[56]=ne,t[57]=xe):xe=t[57],xe};function aC(t){return t.shortcutOverrides}function iC(t){return t.setShortcutOverride}function oC(t){return t.clearShortcutOverride}function lC(t){return t.resetAllShortcutOverrides}const cC=t=>{const e=rt.c(20),{section:n}=t,{isMobile:r}=rn();let i;e[0]!==r?(i=r&&sa(),e[0]=r,e[1]=i):i=e[1];const a=i;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=pn(),e[2]=o):o=e[2];const c=o;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=wn()&&Ur(),e[3]=d):d=e[3];const p=d;if(!n){let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(_d,{}),e[4]=h):h=e[4];let v,x,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(ag,{})}),x=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(og,{})}),g=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(lg,{})}),e[5]=v,e[6]=x,e[7]=g):(v=e[5],x=e[6],g=e[7]);let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(ng,{})}),e[8]=w):w=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(rg,{})}),e[9]=y):y=e[9];let S;e[10]!==a?(S=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(A5,{})}),e[10]=a,e[11]=S):S=e[11];let D;return e[12]!==S?(D=s.jsx(As,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[h,v,x,g,w,y,S]})}),e[12]=S,e[13]=D):D=e[13],D}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(uC,{});case"chat":return s.jsx(mC,{});case"sessions":return s.jsx(pC,{});case"shortcuts":return s.jsx(dC,{});case"git":return s.jsx(hC,{});case"github":return s.jsx(fC,{});case"notifications":return s.jsx(gC,{});case"voice":return s.jsx(xC,{});case"tunnel":return s.jsx(bC,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const u=m;let f;e[16]!==u?(f=u(),e[16]=u,e[17]=f):f=e[17];let b;return e[18]!==f?(b=s.jsx(As,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",children:f})}),e[18]=f,e[19]=b):b=e[19],b},dC=()=>{const t=rt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(rC,{}),t[0]=e):e=t[0],e},uC=()=>{const t=rt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=pn(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(_d,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},mC=()=>{const t=rt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(_d,{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},pC=()=>{const t=rt.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=pn(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=wn()&&Ur(),t[1]=r):r=t[1];const i=r;let a,o,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(ag,{}),o=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(og,{})}),c=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(lg,{})}),t[2]=a,t[3]=o,t[4]=c):(a=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(ng,{})}),t[5]=d):d=t[5];let p;return t[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs("div",{className:"space-y-6",children:[a,o,c,d,s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(rg,{})})]}),t[6]=p):p=t[6],p},hC=()=>{const t=rt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(Zf,{})}),t[0]=e):e=t[0],e},fC=()=>{const t=rt.c(1);if(pn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(eg,{}),t[0]=e):e=t[0],e},gC=()=>{const t=rt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(z5,{}),t[0]=e):e=t[0],e},xC=()=>{const t=rt.c(1);if(pn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(H5,{}),t[0]=e):e=t[0],e},bC=()=>{const t=rt.c(1);if(pn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(tC,{}),t[0]=e):e=t[0],e},ld=176,cd=280,Cp=8;function Sc(t){return Math.min(cd,Math.max(ld,t))}const yC=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","projects","remote-instances","agents","behavior","commands","mcp","providers","usage","skills.installed","skills.catalog","voice","tunnel"];function vC(t){const e=pn(),n=!t&&sa();return{isVSCode:e,isWeb:n,isDesktop:t}}function Ip(t,e){return t.isAvailable?t.isAvailable(e):!0}function Vd(t){switch(t){case"projects":return"folders";case"remote-instances":return"server";case"appearance":return"palette";case"chat":return"chat-ai-3";case"magic-prompts":return"ai-generate-2";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"chat-history";case"providers":return"cloud";case"agents":return"ai-agent";case"behavior":return"brain";case"commands":return"slash-commands-2";case"mcp":return"plug-2";case"skills.installed":return"book-open";case"skills.catalog":return"book";case"git":return"git-branch";case"usage":return"bar-chart-2";case"voice":return"mic";case"tunnel":return"global";case"home":return null;default:return"robot-2"}}const kc=t=>{const e=rt.c(95),{onOpen:n}=t,{t:r}=mt();let i;e[0]!==r?(i=r("settings.view.home.title"),e[0]=r,e[1]=i):i=e[1];let a;e[2]!==i?(a=s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:i}),e[2]=i,e[3]=a):a=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]!==a||e[9]!==c?(d=s.jsxs("div",{className:"space-y-1",children:[a,c]}),e[8]=a,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 f;e[16]!==u?(f=s.jsx("div",{className:"typography-ui-label text-foreground",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==r?(b=r("settings.view.home.cards.providers.description"),e[18]=r,e[19]=b):b=e[19];let h;e[20]!==b?(h=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:b}),e[20]=b,e[21]=h):h=e[21];let v;e[22]!==h||e[23]!==p||e[24]!==f?(v=s.jsxs("button",{type:"button",onClick:p,className:m,children:[f,h]}),e[22]=h,e[23]=p,e[24]=f,e[25]=v):v=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let g;e[28]===Symbol.for("react.memo_cache_sentinel")?(g=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 y;e[31]!==w?(y=s.jsx("div",{className:"typography-ui-label text-foreground",children:w}),e[31]=w,e[32]=y):y=e[32];let S;e[33]!==r?(S=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=S):S=e[34];let D;e[35]!==S?(D=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:S}),e[35]=S,e[36]=D):D=e[36];let j;e[37]!==x||e[38]!==y||e[39]!==D?(j=s.jsxs("button",{type:"button",onClick:x,className:g,children:[y,D]}),e[37]=x,e[38]=y,e[39]=D,e[40]=j):j=e[40];let I;e[41]!==n?(I=()=>n("skills.catalog"),e[41]=n,e[42]=I):I=e[42];let A;e[43]===Symbol.for("react.memo_cache_sentinel")?(A=pe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=A):A=e[43];let E;e[44]!==r?(E=r("settings.view.home.cards.skillsCatalog.title"),e[44]=r,e[45]=E):E=e[45];let P;e[46]!==E?(P=s.jsx("div",{className:"typography-ui-label text-foreground",children:E}),e[46]=E,e[47]=P):P=e[47];let k;e[48]!==r?(k=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=k):k=e[49];let N;e[50]!==k?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:k}),e[50]=k,e[51]=N):N=e[51];let T;e[52]!==I||e[53]!==P||e[54]!==N?(T=s.jsxs("button",{type:"button",onClick:I,className:A,children:[P,N]}),e[52]=I,e[53]=P,e[54]=N,e[55]=T):T=e[55];let M;e[56]!==n?(M=()=>n("mcp"),e[56]=n,e[57]=M):M=e[57];let R;e[58]===Symbol.for("react.memo_cache_sentinel")?(R=pe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=R):R=e[58];let L;e[59]!==r?(L=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=L):L=e[60];let O;e[61]!==L?(O=s.jsx("div",{className:"typography-ui-label text-foreground",children:L}),e[61]=L,e[62]=O):O=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 $;e[65]!==V?($=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:V}),e[65]=V,e[66]=$):$=e[66];let B;e[67]!==M||e[68]!==O||e[69]!==$?(B=s.jsxs("button",{type:"button",onClick:M,className:R,children:[O,$]}),e[67]=M,e[68]=O,e[69]=$,e[70]=B):B=e[70];let H;e[71]!==n?(H=()=>n("usage"),e[71]=n,e[72]=H):H=e[72];let _;e[73]===Symbol.for("react.memo_cache_sentinel")?(_=pe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=_):_=e[73];let se;e[74]!==r?(se=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=se):se=e[75];let oe;e[76]!==se?(oe=s.jsx("div",{className:"typography-ui-label text-foreground",children:se}),e[76]=se,e[77]=oe):oe=e[77];let ae;e[78]!==r?(ae=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=ae):ae=e[79];let ne;e[80]!==ae?(ne=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ae}),e[80]=ae,e[81]=ne):ne=e[81];let xe;e[82]!==H||e[83]!==oe||e[84]!==ne?(xe=s.jsxs("button",{type:"button",onClick:H,className:_,children:[oe,ne]}),e[82]=H,e[83]=oe,e[84]=ne,e[85]=xe):xe=e[85];let te;e[86]!==v||e[87]!==j||e[88]!==T||e[89]!==B||e[90]!==xe?(te=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[v,j,T,B,xe]}),e[86]=v,e[87]=j,e[88]=T,e[89]=B,e[90]=xe,e[91]=te):te=e[91];let F;return e[92]!==te||e[93]!==d?(F=s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl px-6 py-6 space-y-6",children:[d,te]})}),e[92]=te,e[93]=d,e[94]=F):F=e[94],F},wC=t=>{const e=rt.c(102),{onClose:n,forceMobile:r,isWindowed:i}=t,{t:a}=mt(),o=rn(),c=r??o.isMobile,d=Me(jC),p=Me(NC),m=Me(SC);let u;e[0]!==d?(u=Uf(d),e[0]=d,e[1]=u):u=e[1];const f=u,[b,h]=l.useState("nav"),v=l.useRef(null),[x,g]=l.useState(216),[w,y]=l.useState(!1),[S,D]=l.useState(!1),j=l.useRef(0),I=l.useRef(x),A=l.useRef(null);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=wn(),e[2]=E):E=e[2];const P=E;let k;e[3]===Symbol.for("react.memo_cache_sentinel")?(k=vC(P),e[3]=k):k=e[3];const N=k;let T;if(e[4]!==c){let De;e[6]===Symbol.for("react.memo_cache_sentinel")?(De=U=>Ip(U,N),e[6]=De):De=e[6];let ge;e[7]===Symbol.for("react.memo_cache_sentinel")?(ge=U=>!(N.isVSCode&&U.slug==="projects"),e[7]=ge):ge=e[7],T=Od.filter(kC).filter(De).filter(ge).filter(U=>!(c&&U.slug==="shortcuts")),e[4]=c,e[5]=T}else T=e[5];const M=T;let R;e[8]===Symbol.for("react.memo_cache_sentinel")?(R=new Map(yC.map(CC)),e[8]=R):R=e[8];const L=R;let O;if(e[9]!==M){let De;e[11]===Symbol.for("react.memo_cache_sentinel")?(De=(ge,U)=>(L.get(ge.slug)??999)-(L.get(U.slug)??999),e[11]=De):De=e[11],O=M.slice().sort(De),e[9]=M,e[10]=O}else O=e[10];const V=O,$=Es(IC);let B,H;e[12]!==w?(B=()=>{if(typeof window>"u")return;const De=()=>{if(!w){const ge=Sc(Math.floor(window.innerWidth*.12));g(ge)}};return window.addEventListener("resize",De),()=>window.removeEventListener("resize",De)},H=[w],e[12]=w,e[13]=B,e[14]=H):(B=e[13],H=e[14]),l.useEffect(B,H);let _,se;e[15]!==S?(se=()=>{if(!S)return;const De=U=>{const de=U.clientX-j.current,Ee=Sc(I.current+de);g(Ee),y(!0)},ge=()=>D(!1);return window.addEventListener("pointermove",De),window.addEventListener("pointerup",ge,{once:!0}),()=>{window.removeEventListener("pointermove",De),window.removeEventListener("pointerup",ge)}},_=[S],e[15]=S,e[16]=_,e[17]=se):(_=e[16],se=e[17]),l.useEffect(se,_);let oe;e[18]!==x?(oe=De=>{D(!0),j.current=De.clientX,I.current=x,De.preventDefault()},e[18]=x,e[19]=oe):oe=e[19];const ae=oe;let ne;e[20]!==x?(ne=De=>{const ge=De.shiftKey?Cp*4:Cp;let U;e:switch(De.key){case"ArrowLeft":{U=x-ge;break e}case"ArrowRight":{U=x+ge;break e}case"Home":{U=ld;break e}case"End":{U=cd;break e}default:return}De.preventDefault(),g(Sc(U)),y(!0)},e[20]=x,e[21]=ne):ne=e[21];const xe=ne;let te;e[22]!==p||e[23]!==f?(te=()=>{if(!(!p&&!N.isVSCode)){if(f==="agents"){li.getState().loadAgents();return}if(f==="commands"){Id.getState().loadCommands();return}if(f==="mcp"){Ji.getState().loadMcpConfigs();return}(f==="skills.installed"||f==="skills.catalog")&&(ea.getState().loadSkills(),wa.getState().loadCatalog())}},e[22]=p,e[23]=f,e[24]=te):te=e[24];let F;e[25]!==$||e[26]!==p||e[27]!==f?(F=[$,p,N.isVSCode,f],e[25]=$,e[26]=p,e[27]=f,e[28]=F):F=e[28],l.useEffect(te,F);let z;e[29]!==c||e[30]!==m?(z=De=>{if(m(De),v.current=De,!c)return;const ge=Ei(De);if(!ge||ge.slug==="home"){h("nav");return}h(ge.kind==="split"?"page-sidebar":"page-content")},e[29]=c,e[30]=m,e[31]=z):z=e[31];const Q=z;let re;e[32]!==f?(re=Ei(f),e[32]=f,e[33]=re):re=e[33];const K=re;let le;e[34]===Symbol.for("react.memo_cache_sentinel")?(le={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[34]=le):le=e[34];const Se=le;let ue;e[35]!==a?(ue=De=>{switch(De){case"projects":return a("settings.page.projects.title");case"remote-instances":return a("settings.page.remoteInstances.title");case"providers":return a("settings.page.providers.title");case"usage":return a("settings.page.usage.title");case"agents":return a("settings.page.agents.title");case"behavior":return a("settings.page.behavior.title");case"commands":return a("settings.page.commands.title");case"mcp":return a("settings.page.mcp.title");case"skills.installed":return a("settings.page.skills.title");case"skills.catalog":return a("settings.page.skillsCatalog.title");case"git":return a("settings.page.git.title");case"appearance":return a("settings.page.appearance.title");case"chat":return a("settings.page.chat.title");case"shortcuts":return a("settings.page.shortcuts.title");case"sessions":return a("settings.page.sessions.title");case"magic-prompts":return a("settings.page.magicPrompts.title");case"notifications":return a("settings.page.notifications.title");case"voice":return a("settings.page.voice.title");case"tunnel":return a("settings.page.tunnel.title");default:return a("settings.view.home.title")}},e[35]=a,e[36]=ue):ue=e[36];const je=ue;let W;e[37]!==a?(W=()=>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:a("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:a("settings.view.unavailable.description")})]})}),e[37]=a,e[38]=W):W=e[38];const me=W,X=PC;let ce;e[39]!==Q||e[40]!==me?(ce=De=>{const ge=Ei(De);if(ge&&!Ip(ge,N))return me();switch(De){case"home":return s.jsx(kc,{onOpen:Q});case"projects":return s.jsx(qk,{});case"remote-instances":return s.jsx(v3,{});case"agents":return s.jsx(vS,{});case"behavior":return s.jsx(kS,{});case"commands":return s.jsx(RS,{});case"mcp":return s.jsx(lk,{});case"skills.installed":return s.jsx(qm,{view:"installed"});case"skills.catalog":return s.jsx(qm,{view:"catalog"});case"providers":return s.jsx(P3,{});case"usage":return s.jsx(H3,{});case"magic-prompts":return s.jsx(Y3,{});case"git":return s.jsx(s5,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const U=Se[De]??"visual";return s.jsx(cC,{section:U})}default:return s.jsx(kc,{onOpen:Q})}},e[39]=Q,e[40]=me,e[41]=ce):ce=e[41];const ee=ce;let Pe,Ne;e[42]!==c||e[43]!==b||e[44]!==f?(Pe=()=>{if(!c||b!=="nav"||f==="home"||v.current===f)return;const De=Ei(f);!De||De.slug==="home"||(v.current=f,h(De.kind==="split"?"page-sidebar":"page-content"))},Ne=[c,b,f],e[42]=c,e[43]=b,e[44]=f,e[45]=Pe,e[46]=Ne):(Pe=e[45],Ne=e[46]),l.useEffect(Pe,Ne);const Y=c&&b!=="nav";let he,ke,be,fe,Te,Ve,G;if(e[47]!==K||e[48]!==je||e[49]!==c||e[50]!==i||e[51]!==b||e[52]!==n||e[53]!==Q||e[54]!==ee||e[55]!==f||e[56]!==Y||e[57]!==V||e[58]!==a){const De=nl();let ge;e[66]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>{h("nav")},e[66]=ge):ge=e[66];const U=ge;let de;e[67]===Symbol.for("react.memo_cache_sentinel")?(de=()=>{h("page-sidebar")},e[67]=de):de=e[67];const Ee=de;let _e;e[68]!==je||e[69]!==Q||e[70]!==f||e[71]!==V||e[72]!==a?(_e=()=>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(Ce=>{const He=f===Ce.slug,Ge=Vd(Ce.slug);return Ge?s.jsx(Ct,{children:s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>Q(Ce.slug),"aria-current":He?"page":void 0,className:pe("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",He?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(C,{name:Ge,className:"h-4 w-4 shrink-0"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:je(Ce.slug)}),(Ce.slug==="voice"||Ce.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:a("settings.view.badge.beta")})]})]})})},Ce.slug):null})})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-sidebar px-2 py-1 space-y-0.5",children:!N.isVSCode&&s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",className: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:AC,children:[s.jsx(C,{name:"restart",className:"h-4 w-4 shrink-0"}),s.jsx("span",{children:a("settings.view.actions.reloadOpenCode")})]})}),s.jsx(Pt,{children:a("settings.view.actions.reloadOpenCodeTooltip")})]})})})]}),e[68]=je,e[69]=Q,e[70]=f,e[71]=V,e[72]=a,e[73]=_e):_e=e[73],be=_e;let Z;e[74]!==K||e[75]!==b||e[76]!==ee||e[77]!==be||e[78]!==f?(Z=()=>{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(Ys,{children:be()})})});if(!K)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(K.kind!=="split"){const He=ee(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Ys,{children:He})})}return s.jsx("div",{className:pe("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(Ys,{children:X(f,{onItemSelect:()=>h("page-content")})})})}const Ce=ee(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Ys,{children:Ce})})},e[74]=K,e[75]=b,e[76]=ee,e[77]=be,e[78]=f,e[79]=Z):Z=e[79],ke=Z;let ie;e[80]!==K||e[81]!==Q||e[82]!==ee||e[83]!==f?(ie=()=>!K||f==="home"?s.jsx(kc,{onOpen:Q}):K.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(Ys,{children:X(f,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Ys,{children:ee(f)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(Ys,{children:ee(f)})}),e[80]=K,e[81]=Q,e[82]=ee,e[83]=f,e[84]=ie):ie=e[84],he=ie,fe=A,Te="true",e[85]===Symbol.for("react.memo_cache_sentinel")?(Ve=pe("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[85]=Ve):Ve=e[85],G=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:Y?U:n,"aria-label":a(Y?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(C,{name:"arrow-left-s",className:"h-5 w-5"})}),s.jsx("div",{className:"min-w-0 flex-1 typography-ui-label font-medium text-foreground truncate",children:b==="nav"?a("settings.view.home.title"):K?je(K.slug):a("settings.view.home.title")}),b==="page-content"&&K?.kind==="split"&&s.jsx("button",{type:"button",onClick:Ee,"aria-label":a("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(C,{name:"list-unordered",className:"h-5 w-5"})}),n&&s.jsx("button",{type:"button",onClick:n,"aria-label":a("settings.view.actions.closeSettings"),title:a("settings.view.actions.closeSettingsWithShortcut",{shortcut:De}),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(C,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Y&&s.jsx("div",{className:pe("absolute left-3 z-50",i?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:U,"aria-label":a("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(C,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&s.jsx("div",{className:pe("absolute right-0.5 z-50",i?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:n,"aria-label":a("settings.view.actions.closeSettings"),title:a("settings.view.actions.closeSettingsWithShortcut",{shortcut:De}),className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(C,{name:"close",className:"h-5 w-5"})})})]}),e[47]=K,e[48]=je,e[49]=c,e[50]=i,e[51]=b,e[52]=n,e[53]=Q,e[54]=ee,e[55]=f,e[56]=Y,e[57]=V,e[58]=a,e[59]=he,e[60]=ke,e[61]=be,e[62]=fe,e[63]=Te,e[64]=Ve,e[65]=G}else he=e[59],ke=e[60],be=e[61],fe=e[62],Te=e[63],Ve=e[64],G=e[65];let Ie;e[86]!==ae||e[87]!==xe||e[88]!==c||e[89]!==S||e[90]!==x||e[91]!==he||e[92]!==ke||e[93]!==be||e[94]!==a?(Ie=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?ke():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:pe("relative flex h-full min-h-0 flex-col overflow-hidden border-r",P?"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","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",S?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:ae,onKeyDown:xe,role:"separator","aria-orientation":"vertical","aria-valuemin":ld,"aria-valuemax":cd,"aria-valuenow":x,"aria-label":a("settings.view.actions.resizeNavigation")}),s.jsx(Ys,{children:be()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:he()})]})}),e[86]=ae,e[87]=xe,e[88]=c,e[89]=S,e[90]=x,e[91]=he,e[92]=ke,e[93]=be,e[94]=a,e[95]=Ie):Ie=e[95];let Oe;return e[96]!==fe||e[97]!==Te||e[98]!==Ve||e[99]!==G||e[100]!==Ie?(Oe=s.jsxs("div",{ref:fe,"data-settings-view":Te,className:Ve,children:[G,Ie]}),e[96]=fe,e[97]=Te,e[98]=Ve,e[99]=G,e[100]=Ie,e[101]=Oe):Oe=e[101],Oe};function jC(t){return t.settingsPage}function NC(t){return t.isSettingsDialogOpen}function SC(t){return t.setSettingsPage}function kC(t){return t.slug!=="home"}function CC(t,e){return[t,e]}function IC(t){return t.activeProjectId}function PC(t,e){switch(t){case"projects":return s.jsx(Bk,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(o3,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(pS,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(CS,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(FS,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(ck,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(N3,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(D3,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(q3,{onItemSelect:e.onItemSelect});default:return null}}function AC(){ni({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const DC=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:wC,getSettingsNavIcon:Vd},Symbol.toStringTag,{value:"Module"})),dd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const i=r==="/",a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,"")),r},TC=()=>{const t=rt.c(162),{t:e}=mt(),n=Me(MC),r=Me(EC),i=Me(RC),a=Me(FC),o=Me(LC),c=Me(OC),d=Me($C),p=Me(BC),m=Me(_C),u=Me(VC),f=Me(zC),b=Me(UC),h=Ht(WC),v=Ht(KC),x=$i(HC),g=Ws(GC),w=Es(qC),y=Or(),S=Sd(JC),{files:D,git:j}=_n(),I=on(QC),{isMobile:A}=rn();let E;t[0]!==y?(E=y?dd(y):null,t[0]=y,t[1]=E):E=t[1];const P=E,[k,N]=l.useState(""),T=Nl(k,200);let M;t[2]!==T?(M=T.trim(),t[2]=T,t[3]=M):M=t[3];const R=M;let L;t[4]!==k?(L=k.trim(),t[4]=k,t[5]=L):L=t[5];const O=L;let V,$;t[6]!==n?(V=()=>{n&&N("")},$=[n],t[6]=n,t[7]=V,t[8]=$):(V=t[7],$=t[8]),l.useEffect(V,$);let B,H;t[9]!==x||t[10]!==I||t[11]!==j||t[12]!==n?(B=()=>{if(!n||!j)return;const Ye=setTimeout(()=>{const Ue=new Set;for(const vt of x){const Et=Oo(vt);!Et||Ue.has(Et)||(Ue.add(Et),I(Et,j))}},0);return()=>clearTimeout(Ye)},H=[n,x,j,I],t[9]=x,t[10]=I,t[11]=j,t[12]=n,t[13]=B,t[14]=H):(B=t[13],H=t[14]),l.useEffect(B,H);let _;t[15]!==r?(_=()=>r(!1),t[15]=r,t[16]=_):_=t[16];const se=_;let oe;t[17]!==se?(oe=Ye=>()=>{se(),Ye()},t[17]=se,t[18]=oe):oe=t[18];const ae=oe;let ne;t[19]!==w?.id||t[20]!==w?.path||t[21]!==g||t[22]!==A||t[23]!==u||t[24]!==h||t[25]!==ae||t[26]!==i||t[27]!==c||t[28]!==a||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(ne=()=>{const Ye=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(C,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:ae(()=>{i("chat"),c(!1),h()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(C,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:ae(YC)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(C,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:ae(XC)},{id:"toggle-sidebar",title:e(A?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(C,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(A?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:ae(()=>{if(A){const{isSessionSwitcherOpen:Ue}=Me.getState();c(!Ue)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(C,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:ae(()=>p())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(C,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:ae(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(C,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:ae(()=>{g&&u(g)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(C,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:ae(()=>a(!0))}];return yd()&&Ye.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(C,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:ae(()=>{el("desktop_open_draft_mini_chat_window",{directory:dd(g||w?.path||""),projectId:w?.id??null}).catch(ZC)})}),Ye},t[19]=w?.id,t[20]=w?.path,t[21]=g,t[22]=A,t[23]=u,t[24]=h,t[25]=ae,t[26]=i,t[27]=c,t[28]=a,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=ne):ne=t[33],w?.id,w?.path;let xe;t[34]!==ne?(xe=ne(),t[34]=ne,t[35]=xe):xe=t[35];const te=xe;let F;t[36]===Symbol.for("react.memo_cache_sentinel")?(F=wn(),t[36]=F):F=t[36];const z=F;let Q;t[37]===Symbol.for("react.memo_cache_sentinel")?(Q={isVSCode:pn(),isWeb:!z&&sa(),isDesktop:z},t[37]=Q):Q=t[37];const re=Q;let K;if(t[38]!==ae||t[39]!==a||t[40]!==o){let Ye;t[42]===Symbol.for("react.memo_cache_sentinel")?(Ye=Ue=>Ue.isAvailable?Ue.isAvailable(re):!0,t[42]=Ye):Ye=t[42],K=Od.filter(e4).filter(Ye).map(Ue=>{const vt=Vd(Ue.slug)??"settings-3",Et=(Ue.keywords??[]).join(" ");return{id:`settings:${Ue.slug}`,title:Ue.title,icon:s.jsx(C,{name:vt,className:"mr-2 h-4 w-4"}),searchText:`${Ue.title} ${Ue.group} ${Et}`,onSelect:ae(()=>{o(Ue.slug),a(!0)})}}),t[38]=ae,t[39]=a,t[40]=o,t[41]=K}else K=t[41];const le=K,Se=t4;let ue;if(t[43]!==x){let Ye;t[45]===Symbol.for("react.memo_cache_sentinel")?(Ye=(Ue,vt)=>Se(vt)-Se(Ue),t[45]=Ye):Ye=t[45],ue=[...x].sort(Ye),t[43]=x,t[44]=ue}else ue=t[44];const je=ue,W=Vh(),me=Ht(s4);let X;t[46]!==W||t[47]!==me?(X=(Ye,Ue)=>{const vt=me.get(Ye);return vt?.branch?vt.branch.trim()||null:Ue&&W.get(Ue)?.trim()||null},t[46]=W,t[47]=me,t[48]=X):X=t[48];const ce=X;let ee;t[49]===Symbol.for("react.memo_cache_sentinel")?(ee=[],t[49]=ee):ee=t[49];const[Pe,Ne]=l.useState(ee),[Y,he]=l.useState(!1);let ke,be;t[50]!==P||t[51]!==n||t[52]!==S||t[53]!==R?(ke=()=>{if(!n){Ne([]),he(!1);return}if(!P||R.length===0){Ne([]),he(!1);return}let Ye=!1;return he(!0),S(P,R,10,{type:"file"}).then(Ue=>{Ye||Ne(Ue.map(n4))}).catch(()=>{Ye||Ne([])}).finally(()=>{Ye||he(!1)}),()=>{Ye=!0}},be=[n,P,R,S],t[50]=P,t[51]=n,t[52]=S,t[53]=R,t[54]=ke,t[55]=be):(ke=t[54],be=t[55]),l.useEffect(ke,be);const fe=O.length>0;let Te;e:{if(!fe){let Ue;t[56]!==te?(Ue=te.map(r4),t[56]=te,t[57]=Ue):Ue=t[57],Te=Ue;break e}let Ye;t[58]!==te||t[59]!==O?(Ye=fo(te,O,a4,{limit:7,noFuzzy:!0}),t[58]=te,t[59]=O,t[60]=Ye):Ye=t[60],Te=Ye}const Ve=Te;let G;e:{if(!fe){let Ue;t[61]===Symbol.for("react.memo_cache_sentinel")?(Ue=[],t[61]=Ue):Ue=t[61],G=Ue;break e}let Ye;t[62]!==O||t[63]!==le?(Ye=fo(le,O,i4,{limit:7,noFuzzy:!0}),t[62]=O,t[63]=le,t[64]=Ye):Ye=t[64],G=Ye}const Ie=G;let Oe;e:{if(!fe){let Ue;t[65]!==je?(Ue=je.slice(0,5).map(o4),t[65]=je,t[66]=Ue):Ue=t[66],Oe=Ue;break e}let Ye;t[67]!==O||t[68]!==je?(Ye=fo(je,O,l4,{limit:7,threshold:.2}),t[67]=O,t[68]=je,t[69]=Ye):Ye=t[69],Oe=Ye}const De=Oe;let ge;e:{if(!fe||Pe.length===0){let Ue;t[70]===Symbol.for("react.memo_cache_sentinel")?(Ue=[],t[70]=Ue):Ue=t[70],ge=Ue;break e}let Ye;t[71]!==Pe||t[72]!==O?(Ye=fo(Pe,O,c4,{limit:10,threshold:.4}),t[71]=Pe,t[72]=O,t[73]=Ye):Ye=t[73],ge=Ye}const U=ge;let de,Ee,_e,Z,ie,Ce,He,Ge,Xe,we,tt,st,qe,it,lt;if(t[74]!==ce||t[75]!==se||t[76]!==P||t[77]!==D||t[78]!==fe||t[79]!==n||t[80]!==f||t[81]!==k||t[82]!==Ve||t[83]!==U||t[84]!==De||t[85]!==Ie||t[86]!==r||t[87]!==v||t[88]!==b||t[89]!==e){const Ye=Ve.map(d4),Ue=Ie.map(u4),vt=De.map(m4);lt=fe?U.map(p4):[];let Et;e:{if(!fe){Et=["commands","sessions"];break e}const At=h4,We=[{key:"commands",score:At(Ve)},{key:"settings",score:At(Ie)},{key:"sessions",score:At(De)},{key:"files",score:At(U)}];We.sort(f4),Et=We.map(g4)}const Gt=Et;let ts;t[105]!==se||t[106]!==v?(ts=At=>{se(),v(At.id,Oo(At))},t[105]=se,t[106]=v,t[107]=ts):ts=t[107];const Nt=ts;let St;t[108]!==se||t[109]!==P||t[110]!==D||t[111]!==f?(St=async At=>{if(!P)return;const We=await Rd(D,At);if(!We.ok){q.error(Fd(We.reason));return}f(P,At),se()},t[108]=se,t[109]=P,t[110]=D,t[111]=f,t[112]=St):St=t[112];const Zt=St;let ut;t[113]!==b?(ut=At=>yl(Vr(At,b)),t[113]=b,t[114]=ut):ut=t[114];const Xt=ut;Z=ws,st=n,qe=r;let as;t[115]!==e?(as=e("commandPalette.title"),t[115]=e,t[116]=as):as=t[116];let Bt;t[117]!==as?(Bt=s.jsx(js,{children:as}),t[117]=as,t[118]=Bt):Bt=t[118];let ls;t[119]!==e?(ls=e("commandPalette.description"),t[119]=e,t[120]=ls):ls=t[120];let gs;t[121]!==ls?(gs=s.jsx(Rs,{children:ls}),t[121]=ls,t[122]=gs):gs=t[122],t[123]!==Bt||t[124]!==gs?(it=s.jsxs(Ss,{className:"sr-only",children:[Bt,gs]}),t[123]=Bt,t[124]=gs,t[125]=it):it=t[125],_e=vs,we="overflow-hidden p-0",tt=!0,Ee=Aa,He=!1,Ge="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let us;t[126]!==e?(us=e("commandPalette.input.placeholder"),t[126]=e,t[127]=us):us=t[127],t[128]!==k||t[129]!==us?(Xe=s.jsx(ra,{value:k,onValueChange:N,placeholder:us}),t[128]=k,t[129]=us,t[130]=Xe):Xe=t[130],de=Da;let xs;t[131]!==e?(xs=e("commandPalette.empty.noResults"),t[131]=e,t[132]=xs):xs=t[132],t[133]!==xs?(ie=s.jsx(Ta,{children:xs}),t[133]=xs,t[134]=ie):ie=t[134],Ce=Gt.map(At=>At==="commands"&&Ye.length>0?s.jsx(Bn,{children:Ye.map(We=>s.jsxs(Pn,{value:We.id,onSelect:We.onSelect,children:[We.icon,s.jsx("span",{children:We.title}),We.shortcutId?s.jsx(iw,{children:Xt(We.shortcutId)}):null]},We.id))},"commands"):At==="settings"&&Ue.length>0?s.jsx(Bn,{children:Ue.map(x4)},"settings"):At==="sessions"&&vt.length>0?s.jsx(Bn,{children:vt.map(We=>{const Rt=We.title||e("commandPalette.session.untitled"),Dt=Oo(We),wt=ce(We.id,Dt);return s.jsxs(Pn,{value:`session:${We.id}`,onSelect:()=>Nt(We),children:[s.jsx(C,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Rt}),wt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(C,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:wt})]}):null]},We.id)})},"sessions"):At==="files"&<.length>0?s.jsx(Bn,{children:lt.map(We=>{const Rt=zb(We.relativePath||We.name,{maxLength:80});return s.jsxs(Pn,{value:`file:${We.path}`,onSelect:()=>{Zt(We.path)},children:[s.jsx(yr,{filePath:We.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":We.relativePath,children:Rt})]},`file:${We.path}`)})},"files"):null),t[74]=ce,t[75]=se,t[76]=P,t[77]=D,t[78]=fe,t[79]=n,t[80]=f,t[81]=k,t[82]=Ve,t[83]=U,t[84]=De,t[85]=Ie,t[86]=r,t[87]=v,t[88]=b,t[89]=e,t[90]=de,t[91]=Ee,t[92]=_e,t[93]=Z,t[94]=ie,t[95]=Ce,t[96]=He,t[97]=Ge,t[98]=Xe,t[99]=we,t[100]=tt,t[101]=st,t[102]=qe,t[103]=it,t[104]=lt}else de=t[90],Ee=t[91],_e=t[92],Z=t[93],ie=t[94],Ce=t[95],He=t[96],Ge=t[97],Xe=t[98],we=t[99],tt=t[100],st=t[101],qe=t[102],it=t[103],lt=t[104];let ye;t[135]!==fe||t[136]!==Y||t[137]!==e||t[138]!==lt?(ye=fe&&Y&<.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=fe,t[136]=Y,t[137]=e,t[138]=lt,t[139]=ye):ye=t[139];let Je;t[140]!==de||t[141]!==ie||t[142]!==Ce||t[143]!==ye?(Je=s.jsxs(de,{children:[ie,Ce,ye]}),t[140]=de,t[141]=ie,t[142]=Ce,t[143]=ye,t[144]=Je):Je=t[144];let Be;t[145]!==Ee||t[146]!==He||t[147]!==Ge||t[148]!==Xe||t[149]!==Je?(Be=s.jsxs(Ee,{shouldFilter:He,className:Ge,children:[Xe,Je]}),t[145]=Ee,t[146]=He,t[147]=Ge,t[148]=Xe,t[149]=Je,t[150]=Be):Be=t[150];let ze;t[151]!==_e||t[152]!==we||t[153]!==tt||t[154]!==Be?(ze=s.jsx(_e,{className:we,showCloseButton:tt,children:Be}),t[151]=_e,t[152]=we,t[153]=tt,t[154]=Be,t[155]=ze):ze=t[155];let nt;return t[156]!==Z||t[157]!==st||t[158]!==qe||t[159]!==it||t[160]!==ze?(nt=s.jsxs(Z,{open:st,onOpenChange:qe,children:[it,ze]}),t[156]=Z,t[157]=st,t[158]=qe,t[159]=it,t[160]=ze,t[161]=nt):nt=t[161],nt};function MC(t){return t.isCommandPaletteOpen}function EC(t){return t.setCommandPaletteOpen}function RC(t){return t.setActiveMainTab}function FC(t){return t.setSettingsDialogOpen}function LC(t){return t.setSettingsPage}function OC(t){return t.setSessionSwitcherOpen}function $C(t){return t.toggleSidebar}function BC(t){return t.toggleRightSidebar}function _C(t){return t.toggleBottomTerminal}function VC(t){return t.openContextOverview}function zC(t){return t.openContextFile}function UC(t){return t.shortcutOverrides}function WC(t){return t.openNewSessionDraft}function KC(t){return t.setCurrentSession}function HC(t){return t.activeSessions}function GC(t){return t.currentDirectory}function qC(t){return t.getActiveProject()}function JC(t){return t.searchFiles}function QC(t){return t.ensureStatus}function YC(){zh()}function XC(){vr.requestDirectoryDialog()}function ZC(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function e4(t){return t.slug!=="home"}function t4(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function s4(t){return t.worktreeMetadata}function n4(t){return{path:dd(t.path),name:t.name,relativePath:t.relativePath}}function r4(t){return{item:t,score:0}}function a4(t){return t.searchText}function i4(t){return t.searchText}function o4(t){return{item:t,score:0}}function l4(t){return t.title||""}function c4(t){return t.name}function d4(t){return t.item}function u4(t){return t.item}function m4(t){return t.item}function p4(t){return t.item}function h4(t){return t.length?t[0].score:1/0}function f4(t,e){return t.score-e.score}function g4(t){return t.key}function x4(t){return s.jsxs(Pn,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Pp=(t,e,n)=>Wb(t)?yl(Vr(t,n)):e,b4=()=>{const t=rt.c(68),{t:e}=mt(),n=Me(y4),r=Me(v4),i=Me(w4);let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=Ub(),t[0]=a):a=t[0];const o=a;let c,d,p,m,u,f,b,h,v;if(t[1]!==n||t[2]!==r||t[3]!==i||t[4]!==e){const R=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{keys:["Tab"],descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${o} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${o} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];d=ws,h=n,v=r,c=vs,f="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let L;t[14]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(C,{name:"settings-3",className:"h-5 w-5"}),t[14]=L):L=t[14];let O;t[15]!==e?(O=e("helpDialog.title"),t[15]=e,t[16]=O):O=t[16];let V;t[17]!==O?(V=s.jsxs(js,{className:"flex items-center gap-2",children:[L,O]}),t[17]=O,t[18]=V):V=t[18];let $;t[19]!==e?($=e("helpDialog.description"),t[19]=e,t[20]=$):$=t[20];let B;t[21]!==$?(B=s.jsx(Rs,{children:$}),t[21]=$,t[22]=B):B=t[22],t[23]!==V||t[24]!==B?(b=s.jsxs(Ss,{children:[V,B]}),t[23]=V,t[24]=B,t[25]=b):b=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",p="space-y-4",m=R.map(H=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(H.categoryKey)}),s.jsx("div",{className:"space-y-1",children:H.items.map(_=>{const se=_.id?Pp(_.id,Array.isArray(_.keys)?_.keys[0]:_.keys,i):Array.isArray(_.keys)?_.keys:_.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:[_.icon&&s.jsx(C,{name:_.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(_.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(se)?se:[se]).map((oe,ae)=>s.jsxs(l.Fragment,{children:[ae>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:oe})]},`${oe}-${ae}`))})]},_.id||_.descriptionKey)})})]},H.categoryKey)),t[1]=n,t[2]=r,t[3]=i,t[4]=e,t[5]=c,t[6]=d,t[7]=p,t[8]=m,t[9]=u,t[10]=f,t[11]=b,t[12]=h,t[13]=v}else c=t[5],d=t[6],p=t[7],m=t[8],u=t[9],f=t[10],b=t[11],h=t[12],v=t[13];let x;t[26]!==p||t[27]!==m?(x=s.jsx("div",{className:p,children:m}),t[26]=p,t[27]=m,t[28]=x):x=t[28];let g;t[29]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(C,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=g):g=t[29];let w;t[30]!==e?(w=e("helpDialog.proTips.title"),t[30]=e,t[31]=w):w=t[31];let y;t[32]!==w?(y=s.jsx("p",{className:"font-medium mb-1",children:w}),t[32]=w,t[33]=y):y=t[33];let S;t[34]!==i||t[35]!==e?(S=e("helpDialog.proTips.commandPalette",{shortcut:Pp("open_command_palette",`${o} P`,i)}),t[34]=i,t[35]=e,t[36]=S):S=t[36];let D;t[37]!==S?(D=s.jsxs("li",{children:["• ",S]}),t[37]=S,t[38]=D):D=t[38];let j;t[39]!==e?(j=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=j):j=t[40];let I;t[41]!==j?(I=s.jsxs("li",{children:["• ",j]}),t[41]=j,t[42]=I):I=t[42];let A;t[43]!==e?(A=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=A):A=t[44];let E;t[45]!==A?(E=s.jsxs("li",{children:["• ",A]}),t[45]=A,t[46]=E):E=t[46];let P;t[47]!==D||t[48]!==I||t[49]!==E?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[D,I,E]}),t[47]=D,t[48]=I,t[49]=E,t[50]=P):P=t[50];let k;t[51]!==y||t[52]!==P?(k=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[g,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[y,P]})]})}),t[51]=y,t[52]=P,t[53]=k):k=t[53];let N;t[54]!==k||t[55]!==u||t[56]!==x?(N=s.jsxs("div",{className:u,children:[x,k]}),t[54]=k,t[55]=u,t[56]=x,t[57]=N):N=t[57];let T;t[58]!==c||t[59]!==N||t[60]!==f||t[61]!==b?(T=s.jsxs(c,{className:f,children:[b,N]}),t[58]=c,t[59]=N,t[60]=f,t[61]=b,t[62]=T):T=t[62];let M;return t[63]!==d||t[64]!==T||t[65]!==h||t[66]!==v?(M=s.jsx(d,{open:h,onOpenChange:v,children:T}),t[63]=d,t[64]=T,t[65]=h,t[66]=v,t[67]=M):M=t[67],M};function y4(t){return t.isHelpDialogOpen}function v4(t){return t.setHelpDialogOpen}function w4(t){return t.shortcutOverrides}const j4=()=>{const t=rt.c(32),{t:e}=mt(),n=Me(N4),r=Me(S4),i=Me(k4);let a;t[0]!==i||t[1]!==e?(a=async()=>{if(!i)return;if((await Rn(i)).ok){q.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}q.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=i,t[1]=e,t[2]=a):a=t[2];const o=a;let c;t[3]!==e?(c=e("openCodeStatusDialog.title"),t[3]=e,t[4]=c):c=t[4];let d;t[5]!==c?(d=s.jsx(js,{children:c}),t[5]=c,t[6]=d):d=t[6];let p;t[7]!==e?(p=e("openCodeStatusDialog.description"),t[7]=e,t[8]=p):p=t[8];let m;t[9]!==p?(m=s.jsx(Rs,{children:p}),t[9]=p,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(Ss,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let f;t[14]!==e?(f=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=f):f=t[15];let b;t[16]!==o||t[17]!==f?(b=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:o,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:f})}),t[16]=o,t[17]=f,t[18]=b):b=t[18];let h;t[19]!==i||t[20]!==e?(h=i||e("openCodeStatusDialog.empty.noData"),t[19]=i,t[20]=e,t[21]=h):h=t[21];let v;t[22]!==h?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:h}),t[22]=h,t[23]=v):v=t[23];let x;t[24]!==u||t[25]!==b||t[26]!==v?(x=s.jsxs(vs,{className:"max-w-2xl",children:[u,b,v]}),t[24]=u,t[25]=b,t[26]=v,t[27]=x):x=t[27];let g;return t[28]!==n||t[29]!==r||t[30]!==x?(g=s.jsx(ws,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=g):g=t[31],g};function N4(t){return t.isOpenCodeStatusDialogOpen}function S4(t){return t.setOpenCodeStatusDialogOpen}function k4(t){return t.openCodeStatusText}const C4=180,Ap=600,I4=1,P4=6,A4=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const i=l.useRef(new Map),a=l.useRef([]),o=l.useRef(new Set),c=l.useCallback(()=>{if(!(typeof window>"u"))for(;o.current.size<I4&&a.current.length>0;){const p=a.current.shift();if(!p)break;Ht.getState().currentSessionId!==p&&(xu(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"||xu(p).renderable||o.current.has(p)||a.current.includes(p))return;a.current.length>=P4&&a.current.shift();const m=i.current.get(p);m!==void 0&&window.clearTimeout(m);const u=window.setTimeout(()=>{i.current.delete(p),a.current.push(p),c()},C4);i.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))},Ap);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]))},Ap);return()=>window.clearTimeout(p)},[t,n,d]),l.useEffect(()=>{const p=i.current;return()=>{p.forEach(m=>{clearTimeout(m)}),p.clear(),a.current=[]}},[])};function Dp(t){const{localBranches:e,remoteBranches:n,query:r}=t,i=r.trim();if(!i)return{matching:[],otherLocal:e,otherRemote:n};const a=bu(e,i,m=>m),o=bu(n,i,m=>m),c=[],d=a.other,p=o.other;for(const m of a.matching)c.push({label:m,value:m,source:"local"});for(const m of o.matching)c.push({label:m,value:`remotes/${m}`,source:"remote"});return c.sort((m,u)=>{const f=m.label.localeCompare(u.label,void 0,{sensitivity:"accent"});return f!==0?f:m.source!==u.source?m.source.localeCompare(u.source):m.value.localeCompare(u.value)}),{matching:c,otherLocal:d,otherRemote:p}}function D4({open:t,onOpenChange:e,onSelect:n}){const{t:r}=mt(),i=Me(W=>W.isMobile),{github:a}=_n(),o=Kn(W=>W.status),c=Kn(W=>W.hasChecked),d=Me(W=>W.setSettingsDialogOpen),p=Me(W=>W.setSettingsPage),m=Es(W=>W.getActiveProject()),u=m?.path??null,f=$e.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[b,h]=$e.useState("issues"),[v,x]=$e.useState(""),[g,w]=$e.useState([]),[y,S]=$e.useState([]),[D,j]=$e.useState(!1),[I,A]=$e.useState(!1),[E,P]=$e.useState(null),[k,N]=$e.useState(null),[T,M]=$e.useState(null),[R,L]=$e.useState(!1),[O,V]=$e.useState(new Map),[$,B]=$e.useState(1),[H,_]=$e.useState(!1),se=$e.useCallback(async()=>{if(!(!u||!a)&&!(c&&o?.connected===!1)){j(!0),P(null),B(1),_(!1);try{if(b==="issues"&&a.issuesList){const W=await a.issuesList(u,{page:1});W.connected===!1?(P(r("session.githubIntegration.error.notConnected")),w([])):(w(W.issues??[]),B(W.page??1),_(!!W.hasMore))}else if(b==="prs"&&a.prsList){const W=await a.prsList(u,{page:1});W.connected===!1?(P(r("session.githubIntegration.error.notConnected")),S([])):(S(W.prs??[]),B(W.page??1),_(!!W.hasMore))}}catch(W){P(W instanceof Error?W.message:r("session.githubIntegration.error.loadDataFailed"))}finally{j(!1)}}},[u,a,c,o,b,r]),oe=$e.useCallback(async()=>{if(!(!u||!a)&&!(D||I)&&H){A(!0);try{const W=$+1;if(b==="issues"&&a.issuesList){const me=await a.issuesList(u,{page:W});me.connected!==!1&&(w(X=>[...X,...me.issues??[]]),B(me.page??W),_(!!me.hasMore))}else if(b==="prs"&&a.prsList){const me=await a.prsList(u,{page:W});me.connected!==!1&&(S(X=>[...X,...me.prs??[]]),B(me.page??W),_(!!me.hasMore))}}catch{}finally{A(!1)}}},[u,a,b,$,H,D,I]);$e.useEffect(()=>{if(!t){h("issues"),x(""),w([]),S([]),N(null),M(null),L(!1),P(null),V(new Map),B(1),_(!1);return}se()},[t,se]);const ae=$e.useCallback(async W=>{if(!(!f||!W)&&!O.has(W))try{const X=(await Uh(f,{mode:"new",branchName:W,worktreeName:W})).errors.find(ce=>ce.code==="branch_in_use");V(ce=>new Map(ce).set(W,{isValid:!X,error:X?r(X.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{V(me=>new Map(me).set(W,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[f,O,r]);$e.useEffect(()=>{!t||b!=="prs"||y.forEach(W=>{W.head&&ae(W.head)})},[t,b,y,ae]);const ne=$e.useMemo(()=>{const W=v.trim().toLowerCase();return W?g.filter(me=>String(me.number)===W.replace(/^#/,"")?!0:me.title.toLowerCase().includes(W)):g},[g,v]),xe=$e.useMemo(()=>{const W=v.trim().toLowerCase();return W?y.filter(me=>String(me.number)===W.replace(/^#/,"")?!0:me.title.toLowerCase().includes(W)):y},[y,v]),te=c&&o?.connected===!0,F=()=>{p("github"),d(!0)},z=W=>{N(W),M(null)},Q=W=>{M(W),N(null)},re=()=>{k?n({type:"issue",item:k}):T&&n({type:"pr",item:T,includeDiff:R}),e(!1)},K=()=>{N(null),M(null),L(!1)},le=k||T&&O.get(T.head??"")?.isValid!==!1,Se=W=>W.head?O.get(W.head)?.isValid===!1:!0,ue=s.jsx(s.Fragment,{children:te?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(C,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(Ut,{value:v,onChange:W=>x(W.target.value),placeholder:r(b==="issues"?"session.githubIntegration.search.issuesPlaceholder":"session.githubIntegration.search.prsPlaceholder"),className:"h-8 pl-9"})]}),s.jsx("div",{className:"mt-2 h-[300px] overflow-hidden",children:s.jsxs("div",{className:"h-full overflow-y-auto",children:[D&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(C,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),E&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[s.jsx(C,{name:"error-warning",className:"h-4 w-4"}),s.jsx("span",{className:"typography-small",children:E})]})}),!D&&!E&&b==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[ne.length>0?ne.map(W=>s.jsx("button",{onClick:()=>z(W),className:pe("w-full text-left px-2 py-1.5 rounded transition-colors",k?.number===W.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:["#",W.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:W.title}),W.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:[W.sourceRepo.owner,"/",W.sourceRepo.repo]}):null]})]})},`${W.sourceRepo?.owner??""}-${W.sourceRepo?.repo??""}-${W.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")}),H&&!I&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{oe()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),I&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!D&&!E&&b==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[xe.length>0?xe.map(W=>{const me=Se(W),X=W.head?O.get(W.head):void 0;return s.jsx("button",{onClick:()=>!me&&Q(W),disabled:me,className:pe("w-full text-left px-2 py-1.5 rounded transition-colors",T?.number===W.number?"bg-interactive-selection text-interactive-selection-foreground":me?"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:["#",W.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:W.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[W.head," → ",W.base]}),W.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[W.sourceRepo.owner,"/",W.sourceRepo.repo]}):null,me&&X?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:X.error})]})]})]})},`${W.sourceRepo?.owner??""}-${W.sourceRepo?.repo??""}-${W.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")}),H&&!I&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{oe()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),I&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]})]})})]}):s.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 gap-4",children:[s.jsx(C,{name:"github",className:"h-12 w-12 text-muted-foreground"}),s.jsxs("div",{className:"text-center",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:r("session.githubIntegration.connect.title")}),s.jsx("p",{className:"typography-small text-muted-foreground mt-1",children:r("session.githubIntegration.connect.description")})]}),s.jsx(ve,{onClick:F,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),je=s.jsxs("div",{className:pe("w-full",i?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:pe("flex items-center gap-4",i?"w-full justify-center order-1":"flex-1"),children:[!i&&(k||T)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate max-w-[150px]",children:k?r("session.githubIntegration.selected.issueNumber",{number:k.number}):r("session.githubIntegration.selected.prNumber",{number:T?.number??""})}),s.jsx("button",{onClick:K,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]}),b==="prs"&&T&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(bs,{checked:R,onChange:W=>L(W),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",i?"w-full order-2":"justify-end"),children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),className:pe(i&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:re,disabled:!le,className:pe(i&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:i?s.jsx(Dr,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:te?je:void 0,renderHeader:W=>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")}),W]}),s.jsx("div",{className:"w-full",children:s.jsx(Tr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(C,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:me=>{h(me),x("")},variant:"active-pill",layoutMode:"fit"})}),(k||T)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:k?r("session.githubIntegration.selected.issueNumber",{number:k.number}):r("session.githubIntegration.selected.prNumber",{number:T?.number??""})}),s.jsx("button",{onClick:K,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:ue}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(Ss,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(js,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(C,{name:"github",className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(Tr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(C,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:W=>{h(W),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),ue,s.jsx(Gs,{className:"mt-1",children:je})]})})})}const Ri=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),On=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,"").split("/").join("-").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"").slice(0,80),Tp="oc:lastWorktreeSourceBranch",T4=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",Mp=(t,e,n)=>{const r=Ri(t.head||"");if(!r)throw new Error("PR head branch is missing");if(e.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};const i=n.find(p=>{const m=p.indexOf("/");return m<=0||m>=p.length-1?!1:p.slice(m+1)===r});if(i){const p=i.indexOf("/"),m=i.slice(0,p);return{existingBranch:`remotes/${i}`,setUpstream:!0,upstreamRemote:m,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${m}/${r}`}}const a=String(t.headLabel||"").split(":")[0]?.trim(),o=t.headRepo?.owner||a||"pr-head",c=`pr-${T4(o)}`,d=t.headRepo?.sshUrl||t.headRepo?.cloneUrl||"";if(!d)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${c}/${r}`,setUpstream:!0,upstreamRemote:c,upstreamBranch:r,ensureRemoteName:c,ensureRemoteUrl:d,sourceLabel:`${c}/${r}`}},M4=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
|
|
178
|
-
${JSON.stringify(e,null,2)}`},E4=t=>`GitHub pull request context (JSON)
|
|
179
|
-
${JSON.stringify(t,null,2)}`;function R4({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=mt(),{github:i,git:a}=_n(),o=Me(ie=>ie.isMobile),c=Kn(ie=>ie.status),d=Kn(ie=>ie.hasChecked),p=Es(ie=>ie.getActiveProject()),m=p?.path??null,u=$e.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[f,b]=$e.useState("new-branch"),[h,v]=$e.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,g]=$e.useState({selectedBranch:"",worktreeName:""}),w=jd(m),y=Wh(m),S=on(ie=>ie.fetchBranches),D=$e.useMemo(()=>w?.all?w.all.filter(ie=>!ie.startsWith("remotes/")).sort():[],[w]),j=$e.useMemo(()=>w?.all?w.all.filter(ie=>ie.startsWith("remotes/")).map(ie=>ie.replace(/^remotes\//,"")).sort():[],[w]),I=Ht(ie=>ie.availableWorktreesByProject),A=$e.useMemo(()=>{if(!m)return new Set;const ie=I.get(m)??[];return new Set(ie.map(Ce=>Ce.name))},[I,m]),E=$e.useCallback((ie=10)=>{for(let Ce=0;Ce<ie;Ce++){const He=Gl();if(!A.has(He))return He}return`${Gl()}-${Date.now().toString(36).slice(-4)}`},[A]),[P,k]=$e.useState(!1),[N,T]=$e.useState(!1),[M,R]=$e.useState(!1),[L,O]=$e.useState(!1),[V,$]=$e.useState(!1),[B,H]=$e.useState(""),[_,se]=$e.useState(""),oe=$e.useRef(null),ae=$e.useRef(null),ne=$e.useRef(null),xe=$e.useRef(null),te=$e.useCallback(ie=>{let Ce=ie;for(;Ce&&Ce!==document.body;){const{overflowY:He}=window.getComputedStyle(Ce);if((He==="auto"||He==="scroll")&&Ce.scrollHeight>Ce.clientHeight)return Ce;Ce=Ce.parentElement}return null},[]),F=$e.useCallback(ie=>{ie&&(ie.scrollTop=0)},[]),z=$e.useCallback(ie=>{const Ce=ie.current?.querySelector('[data-slot="command-list"]')??null;F(Ce)},[F]),Q=$e.useCallback(ie=>{const Ce=te(ie.current);F(Ce)},[te,F]),re=$e.useMemo(()=>Dp({localBranches:D,remoteBranches:j,query:B}),[D,j,B]),K=$e.useMemo(()=>Dp({localBranches:D,remoteBranches:j,query:_}),[D,j,_]),le=B.trim().length>0,Se=_.trim().length>0,ue=re.matching.length>0,je=K.matching.length>0,W=!!(m&&a),me=$e.useCallback(()=>{!m||!a||S(m,a)},[m,a,S]);$e.useEffect(()=>{!N&&!L&&H("")},[N,L]),$e.useEffect(()=>{!M&&!V&&se("")},[M,V]),$e.useEffect(()=>{N&&z(oe),L&&Q(ne)},[N,L,B,z,Q]),$e.useEffect(()=>{M&&z(ae),V&&Q(xe)},[M,V,_,z,Q]);const[X,ce]=$e.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[ee,Pe]=$e.useState(!1),[Ne,Y]=$e.useState(null),he=$e.useCallback(()=>{const ie=yt.getState(),Ce=ie.getVisibleAgents();if(ie.settingsDefaultAgent){const He=Ce.find(Ge=>Ge.name===ie.settingsDefaultAgent);if(He)return He.name}return Ce.find(He=>He.name==="build")?.name||Ce[0]?.name},[]),ke=$e.useCallback(()=>{const ie=yt.getState(),Ce=ie.settingsDefaultModel;if(!Ce)return null;const He=mi(Ce);if(!He)return null;const{providerId:Ge,modelId:Xe}=He;return ie.getModelMetadata(Ge,Xe)?{providerID:Ge,modelID:Xe}:null},[]),be=$e.useCallback((ie,Ce)=>{const He=yt.getState(),Ge=He.settingsDefaultVariant;if(!Ge)return;const tt=He.providers.find(st=>st.id===ie)?.models.find(st=>st.id===Ce)?.variants;if(tt&&Object.prototype.hasOwnProperty.call(tt,Ge))return Ge},[]),fe=$e.useCallback(ie=>{const Ce=yt.getState();try{go.getState().saveSessionModelSelection(ie.sessionId,ie.providerID,ie.modelID)}catch{}if(ie.agentName){try{Ce.setAgent(ie.agentName)}catch{}try{go.getState().saveSessionAgentSelection(ie.sessionId,ie.agentName)}catch{}try{go.getState().saveAgentModelForSession(ie.sessionId,ie.agentName,ie.providerID,ie.modelID)}catch{}if(ie.variant!==void 0){try{Ce.setCurrentVariant(ie.variant)}catch{}try{go.getState().saveAgentModelVariantForSession(ie.sessionId,ie.agentName,ie.providerID,ie.modelID,ie.variant)}catch{}}}},[]),Te=$e.useCallback(async ie=>{if(!m||!i)return;const Ce=yt.getState(),He=vl.getState().lastUsedProvider,Ge=ke(),Xe=Ge?.providerID||Ce.currentProviderId||He?.providerID,we=Ge?.modelID||Ce.currentModelId||He?.modelID,tt=he()||Ce.currentAgentName||void 0;if(!Xe||!we){q.error(r("session.newWorktree.error.noModelSelected"));return}const st=be(Xe,we);if(fe({sessionId:ie.sessionId,providerID:Xe,modelID:we,agentName:tt,variant:st}),ie.issue){if(!i.issueGet||!i.issueComments)return;const qe=await i.issueGet(m,ie.issue.number);if(qe.connected===!1||!qe.repo||!qe.issue)throw new Error("Failed to load issue context");const it=await i.issueComments(m,ie.issue.number);if(it.connected===!1)throw new Error("Failed to load issue comments");const lt=await En("github.issue.review.visible",{issue_number:String(ie.issue.number)}),ye=await En("github.issue.review.instructions"),Je=M4({repo:qe.repo,issue:qe.issue,comments:it.comments??[]});await In.sendMessage({id:ie.sessionId,providerID:Xe,modelID:we,agent:tt,variant:st,text:lt,additionalParts:[{text:ye,synthetic:!0},{text:Je,synthetic:!0}]}),q.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(ie.pr){if(!i.prContext)return;const qe=await i.prContext(m,ie.pr.number,{includeDiff:ie.includeDiff,includeCheckDetails:!1});if(qe.connected===!1||!qe.repo||!qe.pr)throw new Error("Failed to load PR context");const it=await En("github.pr.review.visible",{pr_number:String(ie.pr.number)}),lt=await En("github.pr.review.instructions"),ye=E4(qe);await In.sendMessage({id:ie.sessionId,providerID:Xe,modelID:we,agent:tt,variant:st,text:it,additionalParts:[{text:lt,synthetic:!0},{text:ye,synthetic:!0}]}),q.success(r("session.newWorktree.toast.sessionFromPr"))}},[fe,i,m,he,ke,be,r]),Ve=f==="new-branch"?h:x;$e.useEffect(()=>{if(!w?.all||!m||h.sourceBranch)return;(async()=>{try{const Ce=await eo(m).catch(()=>null),He=localStorage.getItem(Tp),Ge=He&&w.all?.includes(He)?He:Ce&&w.all?.includes(Ce)?Ce:w.all?.includes("main")?"main":w.all?.includes("master")?"master":w.all?.[0]||"";Ge&&v(Xe=>({...Xe,sourceBranch:Ge}))}catch{}})()},[w,m,h.sourceBranch]),$e.useEffect(()=>{if(!t)return;b("new-branch"),g({selectedBranch:"",worktreeName:""}),T(!1),R(!1),O(!1),$(!1),H(""),se(""),ce({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const ie=E();v({branchName:ie,worktreeName:ie,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,E]),$e.useEffect(()=>{if(f!=="new-branch"||!h.isSyncingWorktreeName)return;const ie=Ri(h.branchName),Ce=On(ie);v(He=>({...He,worktreeName:Ce}))},[f,h.branchName,h.isSyncingWorktreeName]);const G=$e.useCallback(async()=>{if(!u||!X.touched||ee)return;Ne&&Ne.abort();const ie=new AbortController;Y(ie),ce(Ce=>({...Ce,isValidating:!0}));try{const Ce=f==="new-branch"?h.branchName:x.selectedBranch,He=Ve.worktreeName,Ge=Ri(Ce),Xe=On(He);let we=null,tt=null;if(Ge||(we=r("session.newWorktree.error.branchNameRequired")),Xe||(tt=r("session.newWorktree.error.worktreeDirectoryRequired")),Ge&&Xe){const st=f==="new-branch"?h.linkedPr:null,qe=st?Mp(st,D,j):null,it=await Uh(u,{mode:f==="existing-branch"||qe?"existing":"new",branchName:Ge,worktreeName:Xe,existingBranch:qe?.existingBranch??(f==="existing-branch"?Ge:void 0),...qe?.ensureRemoteName?{ensureRemoteName:qe.ensureRemoteName}:{},...qe?.ensureRemoteUrl?{ensureRemoteUrl:qe.ensureRemoteUrl}:{}});if(ie.signal.aborted)return;it.ok||it.errors.forEach(lt=>{if(lt.code==="worktree_exists"){tt=tt??lt.message;return}lt.code.startsWith("branch_")&&(we=we??lt.message)})}ie.signal.aborted||ce(st=>({...st,isValidating:!1,branchError:we,worktreeError:tt}))}catch{ie.signal.aborted||ce(Ce=>({...Ce,isValidating:!1}))}},[u,f,h.branchName,h.linkedPr,x.selectedBranch,Ve.worktreeName,D,j,X.touched,Ne,ee,r]),Ie=f==="new-branch"?h.branchName:x.selectedBranch;$e.useEffect(()=>{if(!t||!u||!X.touched||ee)return;const ie=setTimeout(()=>{G()},300);return()=>clearTimeout(ie)},[Ve.worktreeName,Ie,t,u,G,X.touched,ee]);const Oe=async()=>{if(!u||!m){q.error(r("session.newWorktree.error.noActiveProject"));return}ce(Xe=>({...Xe,touched:!0}));const ie=f==="new-branch"?h.branchName:x.selectedBranch,Ce=Ve.worktreeName,He=Ri(ie),Ge=On(Ce);if(!He){q.error(r("session.newWorktree.error.branchNameRequired"));return}if(!Ge){q.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}Ne&&(Ne.abort(),Y(null)),ce(Xe=>({...Xe,isValidating:!1,branchError:null,worktreeError:null})),Pe(!0);try{const Xe=await Pd(u),we=f==="new-branch"?h.linkedPr:null,tt=h.sourceBranch;let st="";const qe=(()=>{if(we){const nt=Mp(we,D,j);return st=nt.sourceLabel,{preferredName:He||Ge,mode:"existing",branchName:He,worktreeName:Ge,existingBranch:nt.existingBranch,setupCommands:Xe,setUpstream:nt.setUpstream,upstreamRemote:nt.upstreamRemote,upstreamBranch:nt.upstreamBranch,...nt.ensureRemoteName?{ensureRemoteName:nt.ensureRemoteName}:{},...nt.ensureRemoteUrl?{ensureRemoteUrl:nt.ensureRemoteUrl}:{}}}return st=f==="new-branch"?tt:"",{preferredName:He||Ge,mode:f==="existing-branch"?"existing":"new",branchName:f==="existing-branch"?void 0:He,worktreeName:Ge,existingBranch:f==="existing-branch"?He:void 0,setupCommands:Xe,...tt&&f==="new-branch"?{startRef:tt}:{}}})(),it=await Kb(m,qe),lt=await Hb(u,it),ye=f==="new-branch"?h.linkedIssue:null,Je=f==="new-branch"?h.linkedPr:null,Be=f==="new-branch"?h.includePrDiff:!1;let ze=null;if(ye||Je){const nt=ye?`#${ye.number} ${ye.title}`.trim():Je?`#${Je.number} ${Je.title}`.trim():r("session.newWorktree.newSessionTitle"),Ye=await Gb(nt,lt.path,null);if(!Ye?.id)throw new Error("Failed to create session");ze=Ye.id,qb(Ye.id,nt).catch(()=>{});try{Ht.getState().initializeNewOpenChamberSession(Ye.id,yt.getState().agents)}catch{}}h.sourceBranch&&f==="new-branch"&&!h.linkedPr&&localStorage.setItem(Tp,h.sourceBranch),q.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${lt.branch||lt.name}${st?` ${r("session.newWorktree.fromSource",{source:st})}`:""}`})}),e(!1),ze?(n?.(lt.path,{sessionId:ze}),Te({sessionId:ze,issue:ye,pr:Je,includeDiff:Be}).catch(nt=>{const Ye=nt instanceof Error?nt.message:r("session.newWorktree.error.sendGitHubContextFailed");q.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:Ye})})):n?.(lt.path)}catch(Xe){const we=Xe instanceof Error?Xe.message:r("session.newWorktree.error.createWorktreeFailed");q.error(r("session.newWorktree.error.createWorktreeFailed"),{description:we})}finally{Pe(!1)}},De=ie=>{b(ie),ce(Ce=>({...Ce,touched:!1,branchError:null,worktreeError:null}))},ge=ie=>{if(!ie){v(Ce=>({...Ce,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(ie.type==="issue"){const Ce=ie.item,He=`issue-${Ce.number}-${Gl()}`;v(Ge=>({...Ge,linkedIssue:Ce,linkedPr:null,includePrDiff:!1,branchName:He,worktreeName:On(He),isSyncingWorktreeName:!0}))}else if(ie.type==="pr"){const Ce=ie.item;v(He=>({...He,linkedPr:Ce,linkedIssue:null,includePrDiff:ie.includeDiff??!1,branchName:Ce.head,worktreeName:On(Ce.head),isSyncingWorktreeName:!0}))}},U=d&&c?.connected===!0,Ee=(f==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!X.branchError&&!X.worktreeError:!!Ri(h.branchName)&&!!h.worktreeName&&!X.branchError&&!X.worktreeError)&&!ee,_e=()=>{v(ie=>({...ie,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Z=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:X.touched&&(X.branchError||X.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:X.branchError||X.worktreeError})]})}),s.jsxs("div",{className:pe("flex gap-2",o&&"w-full"),children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:ee,className:pe(o&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(ve,{size:"sm",onClick:Oe,disabled:!Ee||ee,className:pe("gap-1.5",o&&"flex-1"),children:[ee&&s.jsx(C,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(ee?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[o?s.jsxs(Dr,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:Z,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Tr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(C,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:f,onSelect:ie=>De(ie),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>O(!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(C,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:me,disabled:!W||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"refresh",className:"size-4"})})]}),s.jsx(Dr,{open:L,title:r("session.newWorktree.selectBranch"),onClose:()=>O(!1),children:s.jsxs("div",{className:"space-y-4",ref:ne,children:[s.jsx(Ut,{value:B,onChange:ie=>H(ie.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[le&&ue&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:re.matching.map(ie=>s.jsx("button",{onClick:()=>{g(Ce=>({...Ce,selectedBranch:ie.value,worktreeName:On(ie.label)})),ce(Ce=>({...Ce,touched:!0})),O(!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}`))})]}),le&&!ue&&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(le?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:re.otherLocal.map(ie=>s.jsx("button",{onClick:()=>{g(Ce=>({...Ce,selectedBranch:ie,worktreeName:On(ie)})),ce(Ce=>({...Ce,touched:!0})),O(!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))})]}),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(le?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:re.otherRemote.map(ie=>s.jsx("button",{onClick:()=>{g(Ce=>({...Ce,selectedBranch:`remotes/${ie}`,worktreeName:On(ie)})),ce(Ce=>({...Ce,touched:!0})),O(!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")}),f==="new-branch"&&U&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>k(!0),className:"gap-1.5 h-7",children:[s.jsx(C,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Ut,{value:h.branchName,onChange:ie=>{v(Ce=>({...Ce,branchName:ie.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ce(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:pe("h-8",X.touched&&X.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const ie=On(f==="new-branch"?h.branchName:"");v(Ce=>({...Ce,worktreeName:ie,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===On(h.branchName),className:pe("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===On(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(C,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Ut,{value:Ve.worktreeName,onChange:ie=>{f==="new-branch"?v(Ce=>({...Ce,worktreeName:ie.target.value,isSyncingWorktreeName:!1})):g(Ce=>({...Ce,worktreeName:ie.target.value}))},onBlur:()=>ce(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:pe("h-8",X.touched&&X.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>$(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:h.sourceBranch?"text-foreground":"text-muted-foreground",children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(C,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})}),s.jsx(Dr,{open:V,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>$(!1),children:s.jsxs("div",{className:"space-y-4",ref:xe,children:[s.jsx(Ut,{value:_,onChange:ie=>se(ie.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[Se&&je&&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:K.matching.map(ie=>s.jsx("button",{onClick:()=>{v(Ce=>({...Ce,sourceBranch:ie.value})),$(!1)},className:pe("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.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}`))})]}),Se&&!je&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),K.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(Se?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:K.otherLocal.map(ie=>s.jsx("button",{onClick:()=>{v(Ce=>({...Ce,sourceBranch:ie})),$(!1)},className:pe("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.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))})]}),K.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(Se?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:K.otherRemote.map(ie=>s.jsx("button",{onClick:()=>{v(Ce=>({...Ce,sourceBranch:`remotes/${ie}`})),$(!1)},className:pe("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.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}`))})]})]})]})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:ie=>ie.stopPropagation(),children:s.jsx(C,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:_e,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(Ss,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(js,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(C,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Tr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(C,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:f,onSelect:ie=>De(ie),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(Bs,{open:N,onOpenChange:T,children:[s.jsx(Os,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:pe("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx($s,{align:"start",sideOffset:6,portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:oe,children:s.jsxs(Aa,{shouldFilter:!1,children:[s.jsx(ra,{placeholder:r("session.newWorktree.searchBranches"),value:B,onValueChange:H}),s.jsx(Da,{disableHorizontal:!0,children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx(Ta,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[le&&ue&&s.jsx(Bn,{heading:r("session.newWorktree.matchingBranches"),children:re.matching.map(ie=>s.jsx(Pn,{value:ie.value,onSelect:()=>{g(Ce=>({...Ce,selectedBranch:ie.value,worktreeName:On(ie.label)})),ce(Ce=>({...Ce,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))}),le&&!ue&&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:[le&&s.jsx(ya,{}),s.jsx(Bn,{heading:r(le?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:re.otherLocal.map(ie=>s.jsx(Pn,{value:ie,onSelect:()=>{g(Ce=>({...Ce,selectedBranch:ie,worktreeName:On(ie)})),ce(Ce=>({...Ce,touched:!0})),T(!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||le)&&s.jsx(ya,{}),s.jsx(Bn,{heading:r(le?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:re.otherRemote.map(ie=>s.jsx(Pn,{value:`remotes/${ie}`,onSelect:()=>{g(Ce=>({...Ce,selectedBranch:`remotes/${ie}`,worktreeName:On(ie)})),ce(Ce=>({...Ce,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remote-${ie}`))})]})]})})]})})]}),s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:me,disabled:!W||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(C,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(C,{name:"refresh",className:"size-4"})})]})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&U&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>k(!0),className:"gap-1.5 h-7",children:[s.jsx(C,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Ut,{value:h.branchName,onChange:ie=>{v(Ce=>({...Ce,branchName:ie.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ce(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:pe("h-8",X.touched&&X.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(C,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const ie=On(f==="new-branch"?h.branchName:"");v(Ce=>({...Ce,worktreeName:ie,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===On(h.branchName),className:pe("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===On(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(C,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Ut,{value:Ve.worktreeName,onChange:ie=>{f==="new-branch"?v(Ce=>({...Ce,worktreeName:ie.target.value,isSyncingWorktreeName:!1})):g(Ce=>({...Ce,worktreeName:ie.target.value}))},onBlur:()=>ce(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:pe("h-8",X.touched&&X.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(Bs,{open:M,onOpenChange:R,children:[s.jsx(Os,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:pe("truncate",h.sourceBranch?"text-foreground":"text-muted-foreground"),children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx($s,{align:"start",portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:ae,children:s.jsxs(Aa,{shouldFilter:!1,children:[s.jsx(ra,{placeholder:r("session.newWorktree.searchBranches"),value:_,onValueChange:se}),s.jsx(Da,{disableHorizontal:!0,children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx(Ta,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[Se&&je&&s.jsx(Bn,{heading:r("session.newWorktree.matchingBranches"),children:K.matching.map(ie=>s.jsx(Pn,{value:ie.value,onSelect:()=>{v(Ce=>({...Ce,sourceBranch:ie.value})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))}),Se&&!je&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),K.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[Se&&s.jsx(ya,{}),s.jsx(Bn,{heading:r(Se?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:K.otherLocal.map(ie=>s.jsx(Pn,{value:ie,onSelect:()=>{v(Ce=>({...Ce,sourceBranch:ie})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`local-${ie}`))})]}),K.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(K.otherLocal.length>0||Se)&&s.jsx(ya,{}),s.jsx(Bn,{heading:r(Se?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:K.otherRemote.map(ie=>s.jsx(Pn,{value:`remotes/${ie}`,onSelect:()=>{v(Ce=>({...Ce,sourceBranch:`remotes/${ie}`})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remote-${ie}`))})]})]})})]})})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:ie=>ie.stopPropagation(),children:s.jsx(C,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:_e,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]}),s.jsxs(Gs,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:X.touched&&(X.branchError||X.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:X.branchError||X.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:ee,children:r("session.newWorktree.actions.cancel")}),s.jsxs(ve,{size:"sm",onClick:Oe,disabled:!Ee||ee,className:"gap-1.5",children:[ee&&s.jsx(C,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(ee?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(D4,{open:P,onOpenChange:k,onSelect:ge})]})}let ai=null,ii=null,Ho=null,hl=0;const Sa=new Set,F4=3e4,L4=45e3,cg=()=>{Ho&&(clearTimeout(Ho),Ho=null)},dg=()=>{if(ii||Sa.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(hl,5)),F4);ii=setTimeout(()=>{ii=null,hl+=1,ug()},t)},fl=()=>{cg(),ai&&ai.close(),ai=null},Ep=()=>{cg(),Sa.size!==0&&(Ho=setTimeout(()=>{fl(),dg()},L4))},O4=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}},$4=t=>{if(t.type==="openchamber:event-stream-ready"){hl=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:"",i=typeof e?.ranAt=="number"?e.ranAt:Date.now(),a=e?.status,o=a==="running"||a==="error"?a:"success";if(!n||!r)return;const c={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:i,status:o,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of Sa)d(c)},ug=()=>{if(typeof window>"u"||Sa.size===0||typeof EventSource!="function"||ai&&ai.readyState!==EventSource.CLOSED)return;fl();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{Ep()},t.onmessage=e=>{Ep();const n=O4(e.data);n&&$4(n)},t.onerror=()=>{fl(),dg()},ai=t},mg=t=>(Sa.add(t),ug(),()=>{Sa.delete(t),Sa.size===0&&(ii&&(clearTimeout(ii),ii=null),hl=0,fl())}),Al=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},gi=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},B4=async t=>{const e=gi(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Al(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Rp=async(t,e)=>{const n=gi(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 Al(r,"Failed to save scheduled task"));const i=await r.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},_4=async(t,e)=>{const n=gi(t),r=gi(e),i=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!i.ok)throw new Error(await Al(i,"Failed to delete scheduled task"));const a=await i.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},V4=async(t,e)=>{const n=gi(t),r=gi(e),i=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!i.ok)throw new Error(await Al(i,"Failed to run scheduled task"));const a=await i.json().catch(()=>null);return{sessionId:typeof a?.sessionId=="string"&&a.sessionId.length>0?a.sessionId:void 0}},pg=[0,1,2,3,4,5,6],Fp=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"],Lp=()=>{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}`},Go=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),i=Number(e[3]),a=new Date(n,r-1,i);return Number.isNaN(a.getTime())||a.getFullYear()!==n||a.getMonth()!==r-1||a.getDate()!==i?null:a},Op=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},z4=(t,e,n)=>{const r=Go(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},$p=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),U4=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),o=(new Date(n,r,1).getDay()-e+7)%7,c=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),p=[];for(let m=0;m<42;m+=1){const u=m-o+1;if(u<=0){const f=d+u;p.push({date:new Date(n,r-1,f),inCurrentMonth:!1});continue}if(u>c){p.push({date:new Date(n,r+1,u-c),inCurrentMonth:!1});continue}p.push({date:new Date(n,r,u),inCurrentMonth:!0})}return p},W4=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],i=n>=12?"PM":"AM",a=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(a).padStart(2,"0"),minute:r,meridiem:i}},pa=(t,e,n)=>{const r=Number(t),i=Number(e),a=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,o=Number.isFinite(i)?Math.min(59,Math.max(0,i)):0;let c=a%12;return n==="PM"&&(c+=12),`${String(c).padStart(2,"0")}:${String(o).padStart(2,"0")}`},yi=(t,e)=>{const{max:n,min:r=0,loop:i=!1}=e;let a=Number.parseInt(t,10);return Number.isFinite(a)?(i?(a>n&&(a=r),a<r&&(a=n)):(a>n&&(a=n),a<r&&(a=r)),String(a).padStart(2,"0")):"00"},Bp=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:yi(t,{min:1,max:12}),Ao=t=>/^[0-5][0-9]$/.test(t)?t:yi(t,{max:59}),K4=(t,e)=>yi(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),_p=(t,e)=>yi(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),H4=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}},G4=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}},q4=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return pg.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},J4=(t,e)=>[...t.slice(e),...t.slice(0,e)],xr=t=>{const e=rt.c(6),{htmlFor:n,required:r,children:i}=t;let a;e[0]!==r?(a=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=a):a=e[1];let o;return e[2]!==i||e[3]!==n||e[4]!==a?(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:[i,a]})}),e[2]=i,e[3]=n,e[4]=a,e[5]=o):o=e[5],o},Vp=t=>{const e=rt.c(84),{value:n,onChange:r,use24Hour:i,hourAriaLabel:a,minuteAriaLabel:o,periodAriaLabel:c,amLabel:d,pmLabel:p}=t;let m;e[0]!==n?(m=W4(n),e[0]=n,e[1]=m):m=e[1];const u=m,f=$e.useRef(null),b=$e.useRef(null),[h,v]=$e.useState(null),[x,g]=$e.useState(null),w=$e.useRef(null),y=$e.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=ee=>{w.current=ee,v(ee)},e[2]=S):S=e[2];const D=S;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=ee=>{y.current=ee,g(ee)},e[3]=j):j=e[3];const I=j,A=tI,E=sI,P=nI;let k;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==i?(k=ee=>{const Pe=ee.replace(/\D/g,"").slice(0,2);D(Pe),Pe.length===2&&(r(i?P(A(Pe),u.minute):pa(Bp(Pe),u.minute,u.meridiem)),D(null),b.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=i,e[8]=k):k=e[8];const N=k;let T;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==i?(T=()=>{const ee=w.current;if(ee!==null&&(D(null),ee.length!==0)){if(i){r(P(A(ee.padStart(2,"0")),u.minute));return}r(pa(Bp(ee.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=i,e[13]=T):T=e[13];const M=T;let R;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==i?(R=ee=>{const Pe=ee.replace(/\D/g,"").slice(0,2);I(Pe),Pe.length===2&&(r(i?P(u.hour24,Ao(Pe)):pa(u.hour12,Ao(Pe),u.meridiem)),I(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=i,e[19]=R):R=e[19];const L=R;let O;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==i?(O=()=>{const ee=y.current;ee!==null&&(I(null),ee.length!==0&&r(i?P(u.hour24,Ao(ee.padStart(2,"0"))):pa(u.hour12,Ao(ee.padStart(2,"0")),u.meridiem)))},e[20]=r,e[21]=u.hour12,e[22]=u.hour24,e[23]=u.meridiem,e[24]=i,e[25]=O):O=e[25];const V=O;let $;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==i?($=ee=>r(i?P(E(u.hour24,ee),u.minute):pa(K4(u.hour12,ee),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]=i,e[32]=$):$=e[32];const B=$;let H;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==i?(H=ee=>r(i?P(u.hour24,_p(u.minute,ee)):pa(u.hour12,_p(u.minute,ee),u.meridiem)),e[33]=r,e[34]=u.hour12,e[35]=u.hour24,e[36]=u.meridiem,e[37]=u.minute,e[38]=i,e[39]=H):H=e[39];const _=H;let se;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(se=ee=>{ee!==u.meridiem&&r(pa(u.hour12,u.minute,ee))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=se):se=e[44];const oe=se;let ae;e[45]!==M||e[46]!==B?(ae=ee=>{if(ee.key==="ArrowRight"){ee.preventDefault(),M(),b.current?.focus();return}(ee.key==="ArrowUp"||ee.key==="ArrowDown")&&(ee.preventDefault(),D(null),B(ee.key==="ArrowUp"?1:-1))},e[45]=M,e[46]=B,e[47]=ae):ae=e[47];const ne=ae;let xe;e[48]!==V||e[49]!==_?(xe=ee=>{if(ee.key==="ArrowLeft"&&(ee.currentTarget.selectionStart??0)===0){ee.preventDefault(),V(),f.current?.focus();return}(ee.key==="ArrowUp"||ee.key==="ArrowDown")&&(ee.preventDefault(),I(null),_(ee.key==="ArrowUp"?1:-1))},e[48]=V,e[49]=_,e[50]=xe):xe=e[50];const te=xe,F=i?"px-2":"pl-2 pr-1";let z;e[51]!==F?(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",F),e[51]=F,e[52]=z):z=e[52];const Q=h??(i?u.hour24:u.hour12);let re;e[53]!==N?(re=ee=>N(ee.target.value),e[53]=N,e[54]=re):re=e[54];let K;e[55]===Symbol.for("react.memo_cache_sentinel")?(K=()=>D(""),e[55]=K):K=e[55];let le;e[56]!==M||e[57]!==a||e[58]!==ne||e[59]!==Q||e[60]!==re?(le=s.jsx("input",{ref:f,inputMode:"numeric",value:Q,onChange:re,onKeyDown:ne,onFocus:K,onBlur:M,maxLength:2,"aria-label":a,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=M,e[57]=a,e[58]=ne,e[59]=Q,e[60]=re,e[61]=le):le=e[61];let Se;e[62]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=Se):Se=e[62];const ue=x??u.minute;let je;e[63]!==L?(je=ee=>L(ee.target.value),e[63]=L,e[64]=je):je=e[64];let W;e[65]===Symbol.for("react.memo_cache_sentinel")?(W=()=>I(""),e[65]=W):W=e[65];let me;e[66]!==V||e[67]!==o||e[68]!==te||e[69]!==ue||e[70]!==je?(me=s.jsx("input",{ref:b,inputMode:"numeric",value:ue,onChange:je,onKeyDown:te,onFocus:W,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]=ue,e[70]=je,e[71]=me):me=e[71];let X;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==oe||e[77]!==i?(X=i?null:s.jsxs(ps,{value:u.meridiem,onValueChange:ee=>oe(ee),children:[s.jsx(hs,{"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(fs,{children:[s.jsx(Ft,{value:"AM",children:d}),s.jsx(Ft,{value:"PM",children:p})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=p,e[76]=oe,e[77]=i,e[78]=X):X=e[78];let ce;return e[79]!==z||e[80]!==le||e[81]!==me||e[82]!==X?(ce=s.jsxs("div",{className:z,children:[le,Se,me,X]}),e[79]=z,e[80]=le,e[81]=me,e[82]=X,e[83]=ce):ce=e[83],ce},zp=t=>new Date(t.getFullYear(),t.getMonth(),1),Q4=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Up=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),Y4=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(i=>typeof i=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(i)).map(i=>i.trim()),r=Array.from(new Set(n)).sort((i,a)=>i.localeCompare(a));return r.length>0?r:["09:00"]},Wp=(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:Y4(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Lp(),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:Lp(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},X4=(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")},Z4=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 eI(t){const{open:e,task:n,onOpenChange:r,onSave:i}=t,{t:a,locale:o}=mt(),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),f=yt(G=>G.currentVariant||""),b=yt(G=>G.currentAgentName||""),h=Me(G=>G.timeFormatPreference),v=Me(G=>G.weekStartPreference),x=Me(G=>G.isMobile),[g,w]=$e.useState(()=>Wp(n,{providerID:m,modelID:u,variant:f,agent:b})),[y,S]=$e.useState(!1),[D,j]=$e.useState(!1),[I,A]=$e.useState(!1),[E,P]=$e.useState(""),[k,N]=$e.useState(!1),[T,M]=$e.useState(""),[R,L]=$e.useState(()=>{const G=Go(n?.schedule?.date||"")||new Date;return new Date(G.getFullYear(),G.getMonth(),1)}),O=$e.useRef(null),V=$e.useRef(null),$=$e.useRef(null),B=$e.useRef(null),H=$e.useMemo(()=>G4(o),[o]),_=$e.useMemo(()=>H4(o),[o]),se=$e.useMemo(()=>h==="24h"?!0:h==="12h"?!1:H,[h,H]),oe=$e.useMemo(()=>v==="sunday"?0:v==="monday"?1:_,[v,_]),ae=$e.useMemo(()=>{const G=q4(o);return J4(pg.map(Ie=>({value:Ie,label:G[Ie]||""})),oe)},[o,oe]);$e.useEffect(()=>{e&&(c(),d())},[e,c,d]),$e.useEffect(()=>{if(!e)return;w(Wp(n,{providerID:m,modelID:u,variant:f,agent:b}));const G=Go(n?.schedule?.date||"")||new Date;L(new Date(G.getFullYear(),G.getMonth(),1)),j(!1),N(!1),A(!1),M(""),P("")},[e,n,m,u,f,b]),$e.useEffect(()=>{if(!D)return;const G=Ie=>{O.current&&!O.current.contains(Ie.target)&&j(!1)};return document.addEventListener("mousedown",G),()=>{document.removeEventListener("mousedown",G)}},[D]);const ne=$e.useMemo(()=>{const Ie=p.find(Oe=>Oe.id===g.execution.providerID)?.models?.find(Oe=>Oe.id===g.execution.modelID);return Ie?.variants?Object.keys(Ie.variants):[]},[p,g.execution.providerID,g.execution.modelID]),xe=ne.length>0,te=$e.useMemo(()=>!xe||!g.execution.variant?"__default":ne.includes(g.execution.variant)?g.execution.variant:"__default",[g.execution.variant,xe,ne]);$e.useEffect(()=>{xe||!g.execution.variant||w(G=>({...G,execution:{...G.execution,variant:""}}))},[xe,g.execution.variant]);const F=$e.useCallback((G,Ie)=>{w(Oe=>{const De=new Set(Oe.schedule.weekdays);return Ie?De.add(G):De.delete(G),{...Oe,schedule:{...Oe.schedule,weekdays:Array.from(De).sort((ge,U)=>ge-U)}}})},[]),z=$e.useCallback((G,Ie)=>{w(Oe=>{const De=Oe.schedule.times.slice();return De[G]=Ie,{...Oe,schedule:{...Oe.schedule,times:De}}})},[]),Q=$e.useCallback(G=>{w(Ie=>{const Oe=Ie.schedule.times.filter((De,ge)=>ge!==G);return{...Ie,schedule:{...Ie.schedule,times:Oe.length>0?Oe:["09:00"]}}})},[]),re=$e.useCallback(()=>{w(G=>({...G,schedule:{...G.schedule,times:[...G.schedule.times,"12:00"]}}))},[]),K=$e.useMemo(()=>Q4(),[]),le=$e.useMemo(()=>zp(K),[K]),Se=$e.useMemo(()=>{const G=Go(g.schedule.onceDate);return G?Up(G,K)?a("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(o,{weekday:"short"}).format(G):null},[g.schedule.onceDate,o,a,K]),ue=$e.useMemo(()=>zp(R).getTime()<=le.getTime(),[R,le]),je=$e.useMemo(()=>ae.map(G=>G.label),[ae]),W=$e.useCallback(G=>{w(Ie=>({...Ie,schedule:{...Ie.schedule,onceDate:G}}))},[]),me=$e.useCallback((G,Ie)=>{if(G.startsWith("/")){const ge=G.indexOf(" "),U=G.indexOf(`
|
|
180
|
-
`),de=Math.min(ge===-1?G.length:ge,U===-1?G.length:U);if(Ie<=de&&ge===-1){M(G.substring(1,de)),N(!0),A(!1);return}}N(!1);const Oe=G.substring(0,Ie),De=Oe.lastIndexOf("@");if(De!==-1){const ge=De>0?Oe[De-1]:null,U=Oe.substring(De+1);(!ge||/\s/.test(ge))&&!U.includes(" ")&&!U.includes(`
|
|
181
|
-
`)?(P(U),A(!0)):A(!1);return}A(!1)},[]),X=$e.useCallback(G=>{w(Ie=>({...Ie,execution:{...Ie.execution,prompt:G}}))},[]),ce=$e.useCallback(G=>{const Ie=g.execution.prompt,De=V.current?.selectionStart??Ie.length,U=Ie.substring(0,De).lastIndexOf("@"),de=G.relativePath&&G.relativePath.trim().length>0?G.relativePath.trim():G.path||G.name,Ee=U!==-1?U:De,_e=`${Ie.substring(0,Ee)}@${de} ${Ie.substring(De)}`,Z=Ee+de.length+2;X(_e),A(!1),P(""),requestAnimationFrame(()=>{const ie=V.current;ie&&(ie.selectionStart=Z,ie.selectionEnd=Z,ie.focus()),me(_e,Z)})},[g.execution.prompt,X,me]),ee=$e.useCallback(G=>{const Ie=g.execution.prompt,De=V.current?.selectionStart??Ie.length,U=Ie.substring(0,De).lastIndexOf("@"),de=U!==-1?U:De,Ee=`${Ie.substring(0,de)}@${G} ${Ie.substring(De)}`,_e=de+G.length+2;X(Ee),A(!1),P(""),requestAnimationFrame(()=>{const Z=V.current;Z&&(Z.selectionStart=_e,Z.selectionEnd=_e,Z.focus()),me(Ee,_e)})},[g.execution.prompt,X,me]),Pe=$e.useCallback(G=>{const Ie=`/${G.name} `;X(Ie),N(!1),M(""),requestAnimationFrame(()=>{const Oe=V.current;Oe&&(Oe.focus(),Oe.selectionStart=Oe.value.length,Oe.selectionEnd=Oe.value.length),me(Ie,Ie.length)})},[X,me]),Ne=$e.useCallback(G=>{if(k&&B.current&&(G.key==="Enter"||G.key==="ArrowUp"||G.key==="ArrowDown"||G.key==="Escape"||G.key==="Tab")){G.preventDefault(),B.current.handleKeyDown(G.key);return}I&&$.current&&(G.key==="Enter"||G.key==="ArrowUp"||G.key==="ArrowDown"||G.key==="Escape"||G.key==="Tab")&&(G.preventDefault(),$.current.handleKeyDown(G.key))},[k,I]),Y=$e.useCallback(async()=>{const G=X4(g,a);if(G){q.error(G);return}const Ie=Z4(g.schedule.times),Oe={...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:Ie,...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 i(Oe),r(!1)}catch(De){q.error(De instanceof Error?De.message:a("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[g,r,i,a]),he=$e.useId(),ke=$e.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),be=a(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),fe=a("sessions.scheduledTasks.editor.description"),Te=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(xr,{htmlFor:"sched-name",required:!0,children:a("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Ut,{id:"sched-name",value:g.name,onChange:G=>w(Ie=>({...Ie,name:G.target.value})),placeholder:a("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(xr,{children:a("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(ps,{value:g.schedule.kind,onValueChange:G=>{w(Ie=>({...Ie,schedule:{...Ie.schedule,kind:G}}))},children:[s.jsx(hs,{className:"w-fit max-w-full",children:s.jsx(ys,{children:G=>a(G==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":G==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"daily",children:a("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Ft,{value:"weekly",children:a("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Ft,{value:"once",children:a("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:O,children:[s.jsx(xr,{children:a("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(C,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:z4(g.schedule.onceDate,a("sessions.scheduledTasks.editor.date.placeholder"),o)})]}),s.jsx(C,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),D?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>L(G=>$p(G,-1)),"aria-label":a("sessions.scheduledTasks.editor.date.previousMonth"),disabled:ue,children:s.jsx(C,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(o,{month:"long",year:"numeric"}).format(R)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>L(G=>$p(G,1)),"aria-label":a("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(C,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:je.map((G,Ie)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:G},`${G}-${Ie}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:U4(R,oe).map(({date:G,inCurrentMonth:Ie})=>{const Oe=Op(G),De=Oe===g.schedule.onceDate,ge=Up(G,K),U=G.getTime()<K.getTime(),de=De?"bg-interactive-selection text-interactive-selection-foreground":U?"text-muted-foreground/40":Ie?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{U||(W(Oe),j(!1))},disabled:U,className:["h-8 rounded-md typography-ui-label",de,ge&&!De?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",U?"cursor-not-allowed opacity-45":""].join(" "),children:G.getDate()},Oe)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:Se||""}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:()=>{W(Op(K)),L(new Date(K.getFullYear(),K.getMonth(),1))},children:a("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(xr,{children:a("sessions.scheduledTasks.editor.time.label")}),s.jsx(Vp,{value:g.schedule.onceTime,use24Hour:se,hourAriaLabel:a("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:a("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:a("sessions.scheduledTasks.editor.time.periodAria"),amLabel:a("sessions.scheduledTasks.editor.time.period.am"),pmLabel:a("sessions.scheduledTasks.editor.time.period.pm"),onChange:G=>w(Ie=>({...Ie,schedule:{...Ie.schedule,onceTime:G}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(xr,{children:a("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ps,{value:g.schedule.timezone,onValueChange:G=>{w(Ie=>({...Ie,schedule:{...Ie.schedule,timezone:G}}))},children:[s.jsx(hs,{className:"w-fit max-w-full",children:s.jsx(ys,{})}),s.jsx(fs,{children:Fp.map(G=>s.jsx(Ft,{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(xr,{children:a("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:ae.map(G=>{const Ie=g.schedule.weekdays.includes(G.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",Ie?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(bs,{checked:Ie,onChange:Oe=>F(G.value,Oe),ariaLabel:G.label}),s.jsx("button",{type:"button",onClick:()=>F(G.value,!Ie),className:"group-hover:text-foreground",children:G.label})]},G.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(xr,{children:a("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:g.schedule.times.map((G,Ie)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vp,{value:G,use24Hour:se,hourAriaLabel:a("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:a("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:a("sessions.scheduledTasks.editor.time.periodAria"),amLabel:a("sessions.scheduledTasks.editor.time.period.am"),pmLabel:a("sessions.scheduledTasks.editor.time.period.pm"),onChange:Oe=>z(Ie,Oe)}),g.schedule.times.length>1?s.jsx(ve,{type:"button",size:"icon",variant:"ghost",onClick:()=>Q(Ie),"aria-label":a("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(C,{name:"close",className:"h-4 w-4"})}):null]},Ie))}),s.jsx("div",{children:s.jsxs(ve,{type:"button",size:"sm",variant:"outline",onClick:re,children:[s.jsx(C,{name:"add",className:"mr-1 h-4 w-4"})," ",a("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(xr,{children:a("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ps,{value:g.schedule.timezone,onValueChange:G=>{w(Ie=>({...Ie,schedule:{...Ie.schedule,timezone:G}}))},children:[s.jsx(hs,{className:"w-fit max-w-full",children:s.jsx(ys,{})}),s.jsx(fs,{children:Fp.map(G=>s.jsx(Ft,{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(xr,{required:!0,children:a("sessions.scheduledTasks.editor.model.label")}),s.jsx(ao,{providerId:g.execution.providerID,modelId:g.execution.modelID,onChange:(G,Ie)=>{w(Oe=>({...Oe,execution:{...Oe.execution,providerID:G,modelID:Ie,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(xr,{children:a("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(ps,{value:te,disabled:!xe,onValueChange:G=>{w(Ie=>({...Ie,execution:{...Ie.execution,variant:G==="__default"?"":G}}))},children:[s.jsx(hs,{className:"w-fit max-w-full",children:s.jsx(ys,{children:G=>G==="__default"?a("sessions.scheduledTasks.editor.thinkingLevel.default"):G})}),s.jsxs(fs,{children:[s.jsx(Ft,{value:"__default",children:a("sessions.scheduledTasks.editor.thinkingLevel.default")}),ne.map(G=>s.jsx(Ft,{value:G,children:G},G))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(xr,{children:a("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Il,{agentName:g.execution.agent,filter:G=>Ah(G.mode),onChange:G=>w(Ie=>({...Ie,execution:{...Ie.execution,agent:G}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(xr,{htmlFor:"sched-prompt",required:!0,children:a("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(vn,{id:"sched-prompt",ref:V,value:g.execution.prompt,onChange:G=>{const Ie=G.target.value;X(Ie);const Oe=G.target.selectionStart??Ie.length;me(Ie,Oe)},onKeyDown:Ne,rows:8,placeholder:a("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),k?s.jsx(Kh,{ref:B,searchQuery:T,onCommandSelect:Pe,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,I?s.jsx(Hh,{ref:$,searchQuery:E,onFileSelect:ce,onAgentSelect:ee,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),Ve=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(Ie=>({...Ie,enabled:G})),ariaLabel:a("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:a("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y,children:a("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(ve,{type:"button",size:"sm",onClick:Y,disabled:y,children:a(y?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Dr,{open:e,title:be,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:G=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:be}),G]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:fe})]}),footer:Ve,children:Te}):s.jsx(ws,{open:e,onOpenChange:G=>{!G&&ke()||r(G)},children:s.jsxs(vs,{"aria-describedby":he,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Rs,{id:he,className:"sr-only",children:fe}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(js,{className:"typography-ui-label font-medium text-foreground",children:be}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:fe})]})}),s.jsx(Zi,{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:Te})}),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:Ve})})]})})}function tI(t){return yi(t,{min:0,max:23})}function sI(t,e){return yi(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function nI(t,e){const n=Number(t),r=Number(e),i=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,a=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(i).padStart(2,"0")}:${String(a).padStart(2,"0")}`}const rI=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,i)=>r.localeCompare(i))},aI=(t,e)=>{const n=rI(t).join(", ")||"--:--",r=i=>e(i===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":i===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":i===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":i===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":i===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":i===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":i===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 i=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(a=>r(a)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:i,time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:i,time:n})}if(t.schedule.kind==="once"){const i=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),a=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:i,time:a,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.once",{date:i,time:a})}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||""})},iI=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),Kp=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),i=6e4,a=60*i,o=24*a,c=n>=0;if(r<i)return e(c?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<a){const u=Math.round(r/i);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/a),f=Math.round(r%a/i),b=f>0?`${u}h ${f}m`:`${u}h`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:b}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:b})}const d=Math.floor(r/o),p=Math.round(r%o/a),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})},oI={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},lI=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function cI(){const{t}=mt(),e=Me(M=>M.isScheduledTasksDialogOpen),n=Me(M=>M.setScheduledTasksDialogOpen),r=Me(M=>M.isMobile),i=Es(M=>M.projects),a=Es(M=>M.getActiveProject()),o=Ws(M=>M.homeDirectory),{currentTheme:c}=Nr(),[d,p]=$e.useState(""),[m,u]=$e.useState([]),[f,b]=$e.useState(!0),[h,v]=$e.useState(!1),[x,g]=$e.useState(null),[w,y]=$e.useState(null),S=$e.useMemo(()=>i.find(M=>M.id===d)||null,[i,d]),D=$e.useCallback(M=>{const R=M.label?.trim()||Pa(M.path,o||void 0),L=no({id:M.id,iconImage:M.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),O=M.icon?kl[M.icon]:null,V=M.color?ro[M.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[L?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:M.iconBackground?{backgroundColor:M.iconBackground}:void 0,children:s.jsx("img",{src:L,alt:"",className:"h-full w-full object-contain",draggable:!1})}):O?s.jsx(C,{name:O,className:"h-3.5 w-3.5 shrink-0",style:V?{color:V}:void 0}):s.jsx(C,{name:"folder",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:R})]})},[o,c.metadata.variant,c.colors.surface.foreground]),j=$e.useCallback(async(M,R)=>{if(!M){u([]);return}R?.silent||b(!0);try{const L=await B4(M);L.sort((O,V)=>{if(O.enabled!==V.enabled)return O.enabled?-1:1;const $=O.name.localeCompare(V.name);return $!==0?$:(O.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u(L)}catch(L){q.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),R?.silent||u([])}finally{R?.silent||b(!1)}},[t]);$e.useEffect(()=>{if(!e)return;const M=a?.id||i[0]?.id||"";p(M),M?j(M):(u([]),b(!1))},[e,a,i,j]),$e.useEffect(()=>{if(!e)return;let M=null;const R=mg(L=>{L.type==="scheduled-task-ran"&&L.projectId===d&&(M&&clearTimeout(M),M=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{M&&clearTimeout(M),R()}},[e,d,j]);const I=$e.useCallback(async M=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Rp(d,M),await j(d),q.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),A=$e.useCallback(async(M,R)=>{if(d){y(M.id),u(L=>L.map(O=>O.id===M.id?{...O,enabled:R}:O));try{await Rp(d,{...M,enabled:R}),await j(d,{silent:!0})}catch(L){q.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{y(null)}}},[d,j,t]),E=$e.useCallback(async M=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:M.name})))){y(M.id);try{await _4(d,M.id),await j(d,{silent:!0}),q.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(L){q.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{y(null)}}},[d,j,t]),P=$e.useCallback(async M=>{if(d){y(M.id);try{await V4(d,M.id),await Promise.all([j(d,{silent:!0}),$c()]),q.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(R){q.error(R instanceof Error?R.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{y(null)}}},[d,j,t]),k=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:M=>{const R=M==="__none"?"":M;p(R),R?j(R):u([])},children:[s.jsx(hs,{className:r?"w-full":void 0,children:S?s.jsx(ys,{children:D(S)}):s.jsx(ys,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(fs,{children:[i.length===0?s.jsx(Ft,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,i.map(M=>s.jsx(Ft,{value:M.id,children:D(M)},M.id))]})]})]}),N=()=>{g(null),v(!0)},T=s.jsxs("div",{className:"space-y-4",children:[r?k:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[k,s.jsxs(ve,{onClick:N,disabled:!d,children:[s.jsx(C,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:f?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(C,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(M=>{const R=w===M.id,L=M.state?.lastStatus||"idle",O=oI[L],V=t(L==="success"?"sessions.scheduledTasks.dialog.status.success":L==="error"?"sessions.scheduledTasks.dialog.status.error":L==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),$=M.state?.nextRunAt,B=M.state?.lastRunAt;return s.jsxs("div",{className:pe("rounded-lg border border-border p-4 transition-opacity",!M.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:M.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:aI(M,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(C,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),$?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Kp($,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:iI($)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(C,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),L==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(C,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):B?s.jsxs(s.Fragment,{children:[O.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${O.tone})`},children:[s.jsx(C,{name:O.Icon,className:"h-3.5 w-3.5"}),V]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Kp(B,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),M.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:lI("error"),children:[s.jsx(C,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:M.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:pe("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",M.enabled?"text-foreground":"text-muted-foreground",R&&"cursor-not-allowed opacity-50"),children:[s.jsx(bs,{checked:M.enabled,onChange:H=>{A(M,H)},ariaLabel:M.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:M.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:M.name}),disabled:R}),M.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{P(M)},disabled:R,children:[s.jsx(C,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{g(M),v(!0)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:M.name}),children:[s.jsx(C,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:()=>{E(M)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:M.name}),children:s.jsx(C,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},M.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Dr,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:M=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),M]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(ve,{className:"w-full",onClick:N,disabled:!d,children:[s.jsx(C,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:T}):s.jsx(ws,{open:e,onOpenChange:n,children:s.jsxs(vs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Rs,{children:t("sessions.scheduledTasks.dialog.description")})]}),T]})}),s.jsx(eI,{open:h,task:x,onOpenChange:v,onSave:I})]})}const dI=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(c=>Ns(c.path)??c.path).filter(c=>!!c)]),a=(c=>c.filter(d=>Hi(d,t.normalizedPath,r)))(e.archivedSessions),o=e.sessions.filter(c=>c.time?.archived||Ns(c.directory??null)?!1:Hi(c,t.normalizedPath,r));return pi([...a,...o])},uI=t=>{const e=rt.c(12),{normalizedProjects:n,sessions:r,archivedSessions:i,availableWorktreesByProject:a,isVSCode:o,isSessionsLoading:c,foldersMap:d,createFolder:p,addSessionToFolder:m,cleanupSessions:u}=t;let f,b;e[0]!==m||e[1]!==i||e[2]!==a||e[3]!==u||e[4]!==p||e[5]!==d||e[6]!==c||e[7]!==o||e[8]!==n||e[9]!==r?(f=()=>{c||n.forEach(h=>{const v=Ad(h.normalizedPath),x=dI(h,{sessions:r,archivedSessions:i,availableWorktreesByProject:a,isVSCode:o}),g=new Set(x.map(mI)),w=d[v]??[],y=new Map(w.map(pI));x.forEach(S=>{const D=Jb(S,h.normalizedPath),j=D.toLowerCase();let I=y.get(j);I||(I=p(v,D),y.set(j,I)),I.sessionIds.includes(S.id)||m(v,I.id,S.id)}),u(v,g)})},b=[n,r,i,a,o,c,d,p,m,u],e[0]=m,e[1]=i,e[2]=a,e[3]=u,e[4]=p,e[5]=d,e[6]=c,e[7]=o,e[8]=n,e[9]=r,e[10]=f,e[11]=b):(f=e[10],b=e[11]),l.useEffect(f,b)};function mI(t){return t.id}function pI(t){return[t.name.toLowerCase(),t]}const hI=t=>{const e=rt.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:i,availableWorktreesByProject:a,projectRepoStatus:o,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:f,buildGroupSearchText:b,foldersMap:h}=t;let v;if(e[0]!==a||e[1]!==p||e[2]!==i||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==o||e[7]!==c){let P;e[9]!==a||e[10]!==p||e[11]!==i||e[12]!==r||e[13]!==d||e[14]!==o||e[15]!==c?(P=k=>{const N=pi([...r(k),...i(k)]),T=a.get(k.normalizedPath)??[],M=o.has(k.id)?!!o.get(k.id):d,R=p(N,k.normalizedPath,T,c.get(k.id)??null,M);return{project:k,groups:R}},e[9]=a,e[10]=p,e[11]=i,e[12]=r,e[13]=d,e[14]=o,e[15]=c,e[16]=P):P=e[16],v=n.map(P),e[0]=a,e[1]=p,e[2]=i,e[3]=r,e[4]=d,e[5]=n,e[6]=o,e[7]=c,e[8]=v}else v=e[8];const x=v,g=x;let w;if(e[17]!==b||e[18]!==f||e[19]!==h||e[20]!==m||e[21]!==u||e[22]!==g){e:{const P=new WeakMap;if(!m){w=P;break e}const k=N=>N.reduce((T,M)=>T+1+k(M.children),0);g.forEach(N=>{N.groups.forEach(T=>{const M=f(T.sessions,u),R=k(M),L=b(T).includes(u),O=Ns(T.directory??null),$=(O?h[O]??[]:[]).filter(B=>B.name.toLowerCase().includes(u)).length;P.set(T,{filteredNodes:M,matchedSessionCount:R,folderNameMatchCount:$,groupMatches:L,hasMatch:L||R>0||$>0})})}),w=P}e[17]=b,e[18]=f,e[19]=h,e[20]=m,e[21]=u,e[22]=g,e[23]=w}else w=e[23];const y=w;let S;e:{if(!m){S=g;break e}let P;if(e[24]!==y||e[25]!==g){let k;e[27]!==y?(k=N=>({...N,groups:N.groups.filter(T=>y.get(T)?.hasMatch===!0)}),e[27]=y,e[28]=k):k=e[28],P=g.map(k).filter(fI),e[24]=y,e[25]=g,e[26]=P}else P=e[26];S=P}const D=S,j=m?D:g;let I;e:{if(!m){I=0;break e}let P;if(e[29]!==y||e[30]!==j){let k;e[32]!==y?(k=(N,T)=>N+T.groups.reduce((M,R)=>{const L=y.get(R);if(!L)return M;const O=L.folderNameMatchCount+(L.groupMatches?1:0);return M+L.matchedSessionCount+O},0),e[32]=y,e[33]=k):k=e[33],P=j.reduce(k,0),e[29]=y,e[30]=j,e[31]=P}else P=e[31];I=P}const A=I;let E;return e[34]!==y||e[35]!==x||e[36]!==A||e[37]!==D||e[38]!==j||e[39]!==g?(E={projectSections:x,visibleProjectSections:g,groupSearchDataByGroup:y,searchableProjectSections:D,sectionsForRender:j,searchMatchCount:A},e[34]=y,e[35]=x,e[36]=A,e[37]=D,e[38]=j,e[39]=g,e[40]=E):E=e[40],E};function fI(t){return t.groups.length>0}const gI=t=>{const e=rt.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:i,setActiveSessionByProject:a,currentSessionId:o,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:f,sessions:b,worktreeMetadata:h}=t;let v,x;if(e[0]!==n){x=new Map,v=new Map;const k=(N,T,M,R)=>{x.has(N)||x.set(N,new Map);const L=x.get(N);R.forEach(O=>{const V=Ns(O.worktree?.path??O.session.directory??M??T);L.set(O.session.id,{directory:V}),v.has(N)||v.set(N,{id:O.session.id,directory:V}),O.children.length>0&&k(N,T,V,O.children)})};n.forEach(N=>{N.groups.forEach(T=>{k(N.project.id,N.project.normalizedPath,T.directory,T.sessions)})}),e[0]=n,e[1]=v,e[2]=x}else v=e[1],x=e[2];let g;e[3]!==v||e[4]!==x?(g={metaByProject:x,firstSessionByProject:v},e[3]=v,e[4]=x,e[5]=g):g=e[5];const w=g,y=l.useRef(null);let S,D;e[6]!==r||e[7]!==i||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]!==a||e[17]!==f?(S=()=>{if(!r||d||y.current===r)return;const k=n.find(V=>V.project.id===r);if(!k)return;y.current=r;const N=w.metaByProject.get(r);if(o&&N&&N.has(o)){a(V=>{if(V.get(r)===o)return V;const $=new Map(V);return $.set(r,o),$});return}if(!N||N.size===0){u("chat"),p&&f(!1),m({directoryOverride:k.project.normalizedPath});return}const T=i.get(r),M=T&&N.has(T)?T:null,R=w.firstSessionByProject.get(r)?.id??null,L=M??R;if(!L||L===o)return;const O=N.get(L)?.directory??null;c(L,O,!1,r)},D=[r,i,o,c,d,p,m,n,w,u,f,a],e[6]=r,e[7]=i,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]=a,e[17]=f,e[18]=S,e[19]=D):(S=e[18],D=e[19]),l.useLayoutEffect(S,D);let j,I;e[20]!==r||e[21]!==o||e[22]!==w||e[23]!==a?(j=()=>{if(!r||!o)return;const k=w.metaByProject.get(r);!k||!k.has(o)||a(N=>{if(N.get(r)===o)return N;const T=new Map(N);return T.set(r,o),T})},I=[r,o,w,a],e[20]=r,e[21]=o,e[22]=w,e[23]=a,e[24]=j,e[25]=I):(j=e[24],I=e[25]),l.useEffect(j,I);let A;if(e[26]!==o||e[27]!==b||e[28]!==h){e:{if(!o){A=null;break e}const k=h.get(o)?.path;if(k){A=Ns(k)??k;break e}let N;e[30]!==o?(N=M=>M.id===o,e[30]=o,e[31]=N):N=e[31];const T=b.find(N);if(!T){A=null;break e}A=Ns(T.directory??null)}e[26]=o,e[27]=b,e[28]=h,e[29]=A}else A=e[29];const E=A;let P;return e[32]!==E?(P={currentSessionDirectory:E},e[32]=E,e[33]=P):P=e[33],P},xI=t=>{const e=rt.c(4);let n;e[0]!==t?(n=(a,o)=>{const c=t.get(a);if(!c||c.length===0)return o;const d=new Map(o.map(bI)),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 i;return e[2]!==r?(i={getOrderedGroups:r},e[2]=r,e[3]=i):i=e[3],i};function bI(t){return[t.id,t]}const Do=t=>!!t.time?.archived,yI=t=>{const{t:e}=mt(),n=l.useCallback(o=>[o.label,o.branch??"",o.description??"",o.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(o=>{const c=Ns(o.directory??null)??"";return`${(o.title||e("sessions.sidebar.session.untitled")).trim()} ${c}`.toLowerCase()},[e]),i=l.useCallback((o,c)=>c?o.flatMap(d=>{if(r(d.session).includes(c))return[d];const m=i(d.children,c);return m.length===0?[]:[{...d,children:m}]}):o,[r]),a=l.useCallback((o,c,d,p,m)=>{const u=Ns(c??null),f=pi(o).sort((k,N)=>ri(k,N,t.pinnedSessionIds)),b=new Map(f.map(k=>[k.id,k])),h=new Map;f.forEach(k=>{const N=k.parentID;if(!N)return;const T=b.get(N);if(!T||Do(T)!==Do(k))return;const M=h.get(N)??[];M.push(k),h.set(N,M)}),h.forEach(k=>k.sort((N,T)=>ri(N,T,t.pinnedSessionIds)));const v=new Map;d.forEach(k=>{if(k.path){const N=Ns(k.path)??k.path;v.set(N,k)}});const x=k=>{const N=Ns(k.directory??null),T=t.worktreeMetadata.get(k.id)??null;if(T)return T;if(N){const M=v.get(N)??null;if(M&&N!==u)return M}return null},g=k=>{const N=h.get(k.id)??[];return{session:k,children:N.map(T=>g(T)),worktree:x(k)}},w=f.filter(k=>{const N=k.parentID;if(!N)return!0;const T=b.get(N);return T?Do(T)!==Do(k):!0}),y=new Map,S="__archived__",D=k=>{if(k.time?.archived)return S;const N=Ns(t.worktreeMetadata.get(k.id)?.path??null),T=Ns(k.directory??null);if(!N&&!T)return S;const M=Ns(k.project?.worktree??null),R=N??T??M;return R?R!==u&&v.has(R)?R:R===u?u??"__project_root__":S:S};w.forEach(k=>{const N=g(k),T=D(k);y.has(T)||y.set(T,[]),y.get(T)?.push(N)});const j=u??"__project_root__",I=[{id:"root",label:m&&p&&p!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:p}):e("sessions.sidebar.grouping.projectRoot"),branch:p??null,description:u?Ki(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:y.get(j)??[]}],A=new Map;d.forEach(k=>{const N=Ns(k.path)??k.path,T=y.get(N)??[],M=T.length>0,R=T.reduce((L,O)=>{const V=Number(O.session.time?.updated??O.session.time?.created??0);return Number.isFinite(V)?Math.max(L,V):L},0);A.set(N,{hasActiveSession:M,lastUpdatedAt:R})}),[...d].sort((k,N)=>{const T=Ns(k.path)??k.path,M=Ns(N.path)??N.path,R=A.get(T)??{hasActiveSession:!1,lastUpdatedAt:0},L=A.get(M)??{hasActiveSession:!1,lastUpdatedAt:0};if(R.hasActiveSession!==L.hasActiveSession)return R.hasActiveSession?-1:1;if(R.hasActiveSession&&L.hasActiveSession)return L.lastUpdatedAt-R.lastUpdatedAt;const O=(k.label||k.branch||k.name||k.path||"").toLowerCase(),V=(N.label||N.branch||N.name||N.path||"").toLowerCase();return O.localeCompare(V)}).forEach(k=>{const N=Ns(k.path)??k.path,T=t.gitBranches.get(N)?.trim()||null,M=k.branch?.trim()||null,L=!!(T&&M&&k.label&&yu(k.label)===yu(M))?T:k.label||k.name||Pa(N,t.homeDirectory)||N;I.push({id:`worktree:${N}`,label:L,branch:T||M,description:Ki(N,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:k,directory:N,folderScopeKey:N,sessions:y.get(N)??[]})});const P=y.get(S)??[];return P.length>0&&I.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?Ad(u):null,sessions:P}),I},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:i,buildGroupedSessions:a}},vI=t=>{const e=rt.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:i,sessionSearchContainerRef:a}=t;let o,c;e[0]!==n||e[1]!==i?(o=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()});return()=>window.cancelAnimationFrame(m)},c=[n,i],e[0]=n,e[1]=i,e[2]=o,e[3]=c):(o=e[2],c=e[3]),l.useEffect(o,c);let d,p;e[4]!==n||e[5]!==a||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=u=>{a.current&&(a.current.contains(u.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},p=[n,r,a],e[4]=n,e[5]=a,e[6]=r,e[7]=d,e[8]=p):(d=e[7],p=e[8]),l.useEffect(d,p)},wI=t=>{const e=rt.c(42),{t:n}=mt(),[r,i]=l.useState(null),a=l.useRef(null);let o,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>()=>{a.current&&clearTimeout(a.current)},c=[],e[0]=o,e[1]=c):(o=e[0],c=e[1]),l.useEffect(o,c);let d;e[2]!==t?(d=(R,L,O,V)=>{if(O)return;const $=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(V&&V!==t.activeProjectId&&t.setActiveProjectIdOnly(V),L&&L!==t.currentDirectory&&t.setDirectory(L,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),R===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(R),$();return}t.setCurrentSession(R,L??null),t.onSessionSelected?.(R),$()},e[2]=t,e[3]=d):d=e[3];const p=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const u=m;let f;e[6]!==t?(f=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=f):f=e[7];const b=f;let h;e[8]!==t?(h=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=h):h=e[9];const v=h;let x;e[10]!==t||e[11]!==n?(x=async R=>{const L=await t.shareSession(R.id);L&&L.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=(R,L)=>{Rn(R).then(O=>{if(!O.ok){q.error(n("sessions.sidebar.session.share.copyUrlError"));return}i(L),a.current&&clearTimeout(a.current),a.current=window.setTimeout(()=>{i(null),a.current=null},2e3)}).catch(()=>{q.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=w):w=e[14];const y=w;let S;e[15]!==t||e[16]!==n?(S=async R=>{await t.unshareSession(R)?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 D=S;let j;e[18]!==t.childrenMap?(j=R=>{const L=[],O=V=>{(t.childrenMap.get(V)??[]).forEach(B=>{L.push(B),O(B.id)})};return O(R),L},e[18]=t.childrenMap,e[19]=j):j=e[19];const I=j;let A;e[20]!==t||e[21]!==I||e[22]!==n?(A=async(R,L)=>{const O=I(R.id),V=L?.archivedBucket===!0;if(O.length===0){(V?await t.deleteSession(R.id):await t.archiveSession(R.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 $=[R.id,...O.map(jI)];if(V){const{deletedIds:_,failedIds:se}=await t.deleteSessions($);_.length>0&&q.success(_.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:_.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:_.length})),se.length>0&&q.error(se.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:se.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:se.length}));return}const{archivedIds:B,failedIds:H}=await t.archiveSessions($);B.length>0&&q.success(B.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:B.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:B.length})),H.length>0&&q.error(H.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:H.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:H.length}))},e[20]=t,e[21]=I,e[22]=n,e[23]=A):A=e[23];const E=A;let P;e[24]!==t||e[25]!==I||e[26]!==E?(P=(R,L)=>{const O=I(R.id);if(!t.showDeletionDialog){E(R,L);return}t.setDeleteSessionConfirm({session:R,descendantCount:O.length,archivedBucket:L?.archivedBucket===!0})},e[24]=t,e[25]=I,e[26]=E,e[27]=P):P=e[27];const k=P;let N;e[28]!==t||e[29]!==E?(N=async()=>{if(!t.deleteSessionConfirm)return;const{session:R,archivedBucket:L}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await E(R,{archivedBucket:L})},e[28]=t,e[29]=E,e[30]=N):N=e[30];const T=N;let M;return e[31]!==T||e[32]!==r||e[33]!==v||e[34]!==y||e[35]!==k||e[36]!==b||e[37]!==u||e[38]!==p||e[39]!==g||e[40]!==D?(M={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:b,handleCancelEdit:v,handleShareSession:g,handleCopyShareUrl:y,handleUnshareSession:D,handleDeleteSession:k,confirmDeleteSession:T},e[31]=T,e[32]=r,e[33]=v,e[34]=y,e[35]=k,e[36]=b,e[37]=u,e[38]=p,e[39]=g,e[40]=D,e[41]=M):M=e[41],M};function jI(t){return t.id}const NI=t=>{const e=rt.c(41),{isVSCode:n,hasLoadedGlobalSessions:r,safeStorage:i,keys:a,sessions:o,pinnedSessionIds:c,setPinnedSessionIds:d,groupOrderByProject:p,activeSessionByProject:m,collapsedGroups:u,setExpandedParents:f,setCollapsedProjects:b}=t,h=l.useRef(null),v=l.useRef(null);let x;e[0]!==n?(x=()=>{if(n)return;const $=v.current;if(v.current=null,h.current=null,!$)return;const{projects:B}=Es.getState(),H=B.map(_=>({..._,sidebarCollapsed:$.has(_.id)}));Ps({projects:H}).catch(SI)},e[0]=n,e[1]=x):x=e[1];const g=x;let w;e[2]!==g||e[3]!==n?(w=$=>{typeof window>"u"||n||(v.current=$,h.current!==null&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{g()},700))},e[2]=g,e[3]=n,e[4]=w):w=e[4];const y=w;let S,D;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=()=>()=>{typeof window<"u"&&h.current!==null&&window.clearTimeout(h.current),h.current=null,v.current=null},D=[],e[5]=S,e[6]=D):(S=e[5],D=e[6]),l.useEffect(S,D);let j,I;e[7]!==a.projectCollapse||e[8]!==a.sessionExpanded||e[9]!==i||e[10]!==b||e[11]!==f?(j=()=>{try{const $=i.getItem(a.sessionExpanded);if($){const H=JSON.parse($);Array.isArray(H)&&f(new Set(H.filter(kI)))}const B=i.getItem(a.projectCollapse);if(B){const H=JSON.parse(B);Array.isArray(H)&&b(new Set(H.filter(CI)))}}catch{}},I=[a.projectCollapse,a.sessionExpanded,i,b,f],e[7]=a.projectCollapse,e[8]=a.sessionExpanded,e[9]=i,e[10]=b,e[11]=f,e[12]=j,e[13]=I):(j=e[12],I=e[13]),l.useEffect(j,I);let A,E;e[14]!==r||e[15]!==o||e[16]!==d?(A=()=>{if(!r)return;const $=new Set(o.map(II));d(B=>{let H=!1;const _=new Set;return B.forEach(se=>{$.has(se)?_.add(se):H=!0}),H?_:B})},E=[r,o,d],e[14]=r,e[15]=o,e[16]=d,e[17]=A,e[18]=E):(A=e[17],E=e[18]),l.useEffect(A,E);let P,k;e[19]!==a.sessionPinned||e[20]!==c||e[21]!==i?(P=()=>{try{i.setItem(a.sessionPinned,JSON.stringify(Array.from(c)))}catch{}},k=[a.sessionPinned,c,i],e[19]=a.sessionPinned,e[20]=c,e[21]=i,e[22]=P,e[23]=k):(P=e[22],k=e[23]),l.useEffect(P,k);let N,T;e[24]!==p||e[25]!==a.groupOrder||e[26]!==i?(N=()=>{try{const $=Object.fromEntries(p.entries());i.setItem(a.groupOrder,JSON.stringify($))}catch{}},T=[p,a.groupOrder,i],e[24]=p,e[25]=a.groupOrder,e[26]=i,e[27]=N,e[28]=T):(N=e[27],T=e[28]),l.useEffect(N,T);let M,R;e[29]!==m||e[30]!==a.projectActiveSession||e[31]!==i?(M=()=>{try{const $=Object.fromEntries(m.entries());i.setItem(a.projectActiveSession,JSON.stringify($))}catch{}},R=[m,a.projectActiveSession,i],e[29]=m,e[30]=a.projectActiveSession,e[31]=i,e[32]=M,e[33]=R):(M=e[32],R=e[33]),l.useEffect(M,R);let L,O;e[34]!==u||e[35]!==a.groupCollapse||e[36]!==i?(L=()=>{try{i.setItem(a.groupCollapse,JSON.stringify(Array.from(u)))}catch{}},O=[u,a.groupCollapse,i],e[34]=u,e[35]=a.groupCollapse,e[36]=i,e[37]=L,e[38]=O):(L=e[37],O=e[38]),l.useEffect(L,O);let V;return e[39]!==y?(V={scheduleCollapsedProjectsPersist:y},e[39]=y,e[40]=V):V=e[40],V};function SI(){}function kI(t){return typeof t=="string"}function CI(t){return typeof t=="string"}function II(t){return t.id}const PI=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),i=new Array(t.length);let a=0;const o=async()=>{for(;;){const c=a;if(a+=1,c>=t.length)return;i[c]=await n(t[c])}};return await Promise.all(Array.from({length:r},()=>o())),i},AI=t=>{const e=rt.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:i,setProjectRootBranches:a}=t,{git:o}=_n(),c=on(DI);let d,p;e[0]!==c||e[1]!==o||e[2]!==n||e[3]!==i?(d=()=>{if(!o||n.length===0){i(new Map);return}n.forEach(x=>{c(x.normalizedPath,o)})},p=[n,o,c,i],e[0]=c,e[1]=o,e[2]=n,e[3]=i,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]!==i?(m=()=>{const x=new Map;n.forEach(g=>{x.set(g.id,r.get(g.normalizedPath)?.isGitRepo??null)}),i(x)},u=[n,r,i],e[6]=r,e[7]=n,e[8]=i,e[9]=m,e[10]=u):(m=e[9],u=e[10]),l.useEffect(m,u);let f;if(e[11]!==r||e[12]!==n){let x;e[14]!==r?(x=g=>{const w=r.get(g.normalizedPath)?.branch??"";return`${g.id}:${w}`},e[14]=r,e[15]=x):x=e[15],f=n.map(x).join("|"),e[11]=r,e[12]=n,e[13]=f}else f=e[13];const b=f;let h;e[16]!==n||e[17]!==a?(h=()=>{let x=!1;return(async()=>{const w=await PI(n,2,MI);x||a(y=>{const S=new Map(y);return w.forEach(D=>{const{id:j,branch:I}=D;I&&S.set(j,I)}),S})})(),()=>{x=!0}},e[16]=n,e[17]=a,e[18]=h):h=e[18];let v;e[19]!==n||e[20]!==b||e[21]!==a?(v=[n,b,a],e[19]=n,e[20]=b,e[21]=a,e[22]=v):v=e[22],l.useEffect(h,v)};function DI(t){return t.ensureStatus}function TI(){return null}async function MI(t){const e=await eo(t.normalizedPath).catch(TI);return{id:t.id,branch:e}}const EI=t=>{const e=rt.c(14),{isVSCode:n,sessions:r,archivedSessions:i,availableWorktreesByProject:a}=t;let o;e[0]!==r?(o=new Map,r.forEach(b=>{const h=Ns(b.directory??null)??Ns(b.project?.worktree??null);if(!h)return;const v=o.get(h)??[];v.push(b),o.set(h,v)}),e[0]=r,e[1]=o):o=e[1];const c=o;let d;e[2]!==a||e[3]!==n||e[4]!==c?(d=b=>{const h=n?[]:a.get(b.normalizedPath)??[],v=[b.normalizedPath,...h.map(RI).filter(FI)],x=new Set,g=[];return v.forEach(w=>{(c.get(w)??[]).forEach(S=>{x.has(S.id)||(x.add(S.id),g.push(S))})}),g},e[2]=a,e[3]=n,e[4]=c,e[5]=d):d=e[5];const p=d;let m;e[6]!==i||e[7]!==a||e[8]!==n||e[9]!==r?(m=b=>{if(n){const y=i.filter(D=>{const j=Ns(D.directory??null),I=Ns(D.project?.worktree??null);return j?j===b.normalizedPath:I===b.normalizedPath}),S=r.filter(D=>D.time?.archived||Ns(D.directory??null)?!1:Ns(D.project?.worktree??null)===b.normalizedPath);return pi([...y,...S])}const h=n?[]:a.get(b.normalizedPath)??[],v=new Set([b.normalizedPath,...h.map(LI).filter(OI)]),g=(y=>y.filter(S=>Hi(S,b.normalizedPath,v)))(i),w=r.filter(y=>{if(y.time?.archived||Ns(y.directory??null))return!1;const D=Ns(y.project?.worktree??null);return D?D===b.normalizedPath||D.startsWith(`${b.normalizedPath}/`):!1});return pi([...g,...w])},e[6]=i,e[7]=a,e[8]=n,e[9]=r,e[10]=m):m=e[10];const u=m;let f;return e[11]!==u||e[12]!==p?(f={getSessionsForProject:p,getArchivedSessionsForProject:u},e[11]=u,e[12]=p,e[13]=f):f=e[13],f};function RI(t){return Ns(t.path)??t.path}function FI(t){return!!t}function LI(t){return Ns(t.path)??t.path}function OI(t){return!!t}const $I=t=>{const e=rt.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:i,normalizedProjects:a,isVSCode:o,availableWorktreesByProject:c,cleanupSessions:d}=t;let p,m;e[0]!==i||e[1]!==c||e[2]!==d||e[3]!==n||e[4]!==o||e[5]!==a||e[6]!==r?(p=()=>{if(n)return;const u=new Map;r.forEach(h=>{const v=Ns(h.directory??null);if(!v)return;const x=u.get(v);if(x){x.add(h.id);return}u.set(v,new Set([h.id]))}),a.forEach(h=>{const v=Ad(h.normalizedPath),x=o?[]:c.get(h.normalizedPath)??[],g=new Set([h.normalizedPath,...x.map(BI).filter(_I)]),w=pi([...i,...r.filter(y=>y.time?.archived||Ns(y.directory??null)?!1:Hi(y,h.normalizedPath,g))]).filter(y=>Hi(y,h.normalizedPath,g));u.set(v,new Set(w.map(VI)))});const f=Hn.getState().foldersMap;new Set([...Object.keys(f),...u.keys()]).forEach(h=>{d(h,u.get(h)??new Set)})},m=[i,c,d,n,o,a,r],e[0]=i,e[1]=c,e[2]=d,e[3]=n,e[4]=o,e[5]=a,e[6]=r,e[7]=p,e[8]=m):(p=e[7],m=e[8]),l.useEffect(p,m)};function BI(t){return Ns(t.path)??t.path}function _I(t){return!!t}function VI(t){return t.id}const zI=t=>{const e=rt.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:i}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[o,c]=l.useState(a);let d;e[1]!==n||e[2]!==i?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(f=>{const b=f.target.dataset.projectId;b&&c(h=>{const v=new Set(h);return f.isIntersecting?v.delete(b):v.add(b),v})})},{threshold:0});return i.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=i,e[3]=d):d=e[3];let p;return e[4]!==n||e[5]!==i||e[6]!==r?(p=[n,i,r],e[4]=n,e[5]=i,e[6]=r,e[7]=p):p=e[7],l.useEffect(d,p),o},UI=t=>{const e=rt.c(85),{folder:n,sessions:r,subFolderItems:i,isCollapsed:a,onToggle:o,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:f,alwaysShowActions:b,isRenaming:h,renameDraft:v,onRenameDraftChange:x,onRenameSave:g,onRenameCancel:w,droppableRef:y,isDropTarget:S,onNewSession:D,onNewSubFolder:j,depth:I,hideActions:A,archivedBucket:E}=t,k=b===void 0?f===void 0?!1:f:b,N=h===void 0?!1:h,T=v===void 0?"":v,M=S===void 0?!1:S,R=I===void 0?0:I,L=A===void 0?!1:A,O=E===void 0?!1:E,{t:V}=mt(),[$,B]=l.useState(!1),[H,_]=l.useState(""),se=l.useRef(null),oe=N||$,ae=N?T:H;let ne;e[0]!==n.name?(ne=()=>{_(n.name),B(!0)},e[0]=n.name,e[1]=ne):ne=e[1];const xe=ne;let te;e[2]!==ae||e[3]!==n.name||e[4]!==N||e[5]!==c||e[6]!==g?(te=()=>{const de=ae.trim();de&&de!==n.name&&c(de),N&&g&&g(),B(!1),_("")},e[2]=ae,e[3]=n.name,e[4]=N,e[5]=c,e[6]=g,e[7]=te):te=e[7];const F=te;let z;e[8]!==N||e[9]!==w?(z=()=>{N&&w&&w(),B(!1),_("")},e[8]=N,e[9]=w,e[10]=z):z=e[10];const Q=z;let re;e[11]!==N||e[12]!==x?(re=de=>{N&&x?x(de):_(de)},e[11]=N,e[12]=x,e[13]=re):re=e[13];const K=re;let le,Se;e[14]!==N?(le=()=>{if(!N)return;const de=()=>{const Z=se.current;Z&&(Z.focus(),Z.select())},Ee=requestAnimationFrame(de),_e=window.setTimeout(de,0);return()=>{cancelAnimationFrame(Ee),window.clearTimeout(_e)}},Se=[N],e[14]=N,e[15]=le,e[16]=Se):(le=e[15],Se=e[16]),l.useEffect(le,Se);const ue=a?"folder":"folder-open",W=R>0&&"ml-3";let me;e[17]!==W?(me=pe("oc-folder",W),e[17]=W,e[18]=me):me=e[18];const X=M&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ce;e[19]!==X?(ce=pe("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",X),e[19]=X,e[20]=ce):ce=e[20];const ee=oe?void 0:o,Pe=oe?void 0:"button",Ne=oe?void 0:0;let Y;e[21]!==o||e[22]!==oe?(Y=oe?void 0:de=>{(de.key==="Enter"||de.key===" ")&&(de.preventDefault(),o())},e[21]=o,e[22]=oe,e[23]=Y):Y=e[23];let he;e[24]!==n.name||e[25]!==a||e[26]!==V?(he=a?V("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):V("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=a,e[26]=V,e[27]=he):he=e[27];const ke=O?k?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let be;e[28]!==ke?(be=pe("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",ke),e[28]=ke,e[29]=be):be=e[29];const fe=M?"text-primary":"text-muted-foreground";let Te;e[30]!==fe?(Te=pe("h-3.5 w-3.5 flex-shrink-0",fe),e[30]=fe,e[31]=Te):Te=e[31];let Ve;e[32]!==ue||e[33]!==Te?(Ve=s.jsx(C,{name:ue,className:Te}),e[32]=ue,e[33]=Te,e[34]=Ve):Ve=e[34];let G;e[35]!==ae||e[36]!==n.name||e[37]!==Q||e[38]!==K||e[39]!==F||e[40]!==a||e[41]!==M||e[42]!==oe||e[43]!==r||e[44]!==V?(G=oe?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:KI,onMouseDown:HI,onSubmit:de=>{de.preventDefault(),F()},children:[s.jsx("input",{ref:se,value:ae,onChange:de=>K(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:GI,onPointerDown:qI,onMouseDown:JI,onKeyDown:de=>{if(de.key==="Escape"){de.stopPropagation(),Q();return}(de.key===" "||de.key==="Enter")&&de.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:QI,onPointerDown:YI,onMouseDown:XI,children:s.jsx(C,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),Q()},onPointerDown:ZI,onMouseDown:eP,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(C,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:pe("typography-ui-label font-semibold truncate",M?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),a?s.jsx(C,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(C,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=ae,e[36]=n.name,e[37]=Q,e[38]=K,e[39]=F,e[40]=a,e[41]=M,e[42]=oe,e[43]=r,e[44]=V,e[45]=G):G=e[45];let Ie;e[46]!==be||e[47]!==Ve||e[48]!==G?(Ie=s.jsxs("div",{className:be,children:[Ve,G]}),e[46]=be,e[47]=Ve,e[48]=G,e[49]=Ie):Ie=e[49];let Oe;e[50]!==k||e[51]!==O||e[52]!==R||e[53]!==n.name||e[54]!==xe||e[55]!==L||e[56]!==d||e[57]!==D||e[58]!==j||e[59]!==oe||e[60]!==V?(Oe=!oe&&(!L||O)?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",k?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",O&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!O&&D?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-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(C,{name:"add",className:"h-3.5 w-3.5"})}):null,!O&&j&&R===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(C,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,O?null:s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),xe()},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(C,{name:"pencil-ai",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":O?V("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):V("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(C,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=k,e[51]=O,e[52]=R,e[53]=n.name,e[54]=xe,e[55]=L,e[56]=d,e[57]=D,e[58]=j,e[59]=oe,e[60]=V,e[61]=Oe):Oe=e[61];let De;e[62]!==y||e[63]!==ce||e[64]!==ee||e[65]!==Pe||e[66]!==Ne||e[67]!==Y||e[68]!==he||e[69]!==Ie||e[70]!==Oe?(De=s.jsxs("div",{ref:y,className:ce,onClick:ee,role:Pe,tabIndex:Ne,onKeyDown:Y,"aria-label":he,children:[Ie,Oe]}),e[62]=y,e[63]=ce,e[64]=ee,e[65]=Pe,e[66]=Ne,e[67]=Y,e[68]=he,e[69]=Ie,e[70]=Oe,e[71]=De):De=e[71];let ge;e[72]!==O||e[73]!==m||e[74]!==a||e[75]!==u||e[76]!==p||e[77]!==r||e[78]!==i||e[79]!==V?(ge=a?null:s.jsxs("div",{className:"pb-1 pl-2",children:[i,r.length>0?r.map(de=>p(de,0,m??null,u??null,O)):i?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]=O,e[73]=m,e[74]=a,e[75]=u,e[76]=p,e[77]=r,e[78]=i,e[79]=V,e[80]=ge):ge=e[80];let U;return e[81]!==me||e[82]!==De||e[83]!==ge?(U=s.jsxs("div",{className:me,children:[De,ge]}),e[81]=me,e[82]=De,e[83]=ge,e[84]=U):U=e[84],U},WI=l.memo(UI);function KI(t){return t.stopPropagation()}function HI(t){return t.stopPropagation()}function GI(t){return t.stopPropagation()}function qI(t){return t.stopPropagation()}function JI(t){return t.stopPropagation()}function QI(t){return t.stopPropagation()}function YI(t){return t.stopPropagation()}function XI(t){return t.stopPropagation()}function ZI(t){return t.stopPropagation()}function eP(t){return t.stopPropagation()}const tP=t=>{const e=rt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:i,children:a}=t,o=`session-drag:${n}`;let c;e[0]!==r||e[1]!==n||e[2]!==i?(c={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:i},e[0]=r,e[1]=n,e[2]=i,e[3]=c):c=e[3];let d;e[4]!==o||e[5]!==c?(d={id:o,data:c},e[4]=o,e[5]=c,e[6]=d):d=e[6];const{attributes:p,listeners:m,setNodeRef:u,isDragging:f}=ox(d);let b;e[7]!==m?(b=g=>{g.stopPropagation(),m?.onPointerDown&&m.onPointerDown(g)},e[7]=m,e[8]=b):b=e[8];const h=b,v=f?"opacity-30":void 0;let x;return e[9]!==p||e[10]!==a||e[11]!==h||e[12]!==u||e[13]!==v?(x=s.jsx("div",{ref:u,...p,onPointerDown:h,className:v,children:a}),e[9]=p,e[10]=a,e[11]=h,e[12]=u,e[13]=v,e[14]=x):x=e[14],x},sP=t=>{const e=rt.c(11),{folderId:n,children:r}=t,i=`folder-drop:${n}`;let a;e[0]!==n?(a={type:"folder",folderId:n},e[0]=n,e[1]=a):a=e[1];let o;e[2]!==i||e[3]!==a?(o={id:i,data:a},e[2]=i,e[3]=a,e[4]=o):o=e[4];const{setNodeRef:c,isOver:d}=lx(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},nP=t=>{const e=rt.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:i,children:a}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[0]=o):o=e[0];const c=qo(Fi(Jo,o)),[d,p]=l.useState(null),[m,u]=l.useState("Session"),[f,b]=l.useState(null),[h,v]=l.useState(null);if(!n){let I;return e[1]!==a?(I=s.jsx(s.Fragment,{children:a}),e[1]=a,e[2]=I):I=e[2],I}let x;e[3]!==i?(x=I=>{p(null),b(null),v(null);const{active:A,over:E}=I;if(!E)return;const P=A.data.current,k=E.data.current;P?.type==="session"&&P.sessionId&&k?.type==="folder"&&k.folderId&&i(P.sessionId,k.folderId)},e[3]=i,e[4]=x):x=e[4];const g=x;let w,y;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=I=>{const A=I.active.data.current;if(A?.type==="session"&&A.sessionId){p(A.sessionId),u(A.sessionTitle??"Session");const E=I.active.rect.current.initial?.width,P=I.active.rect.current.initial?.height;b(typeof E=="number"?E:null),v(typeof P=="number"?P:null)}},y=()=>{p(null),b(null),v(null)},e[5]=w,e[6]=y):(w=e[5],y=e[6]);let S;e[7]!==h||e[8]!==d||e[9]!==m||e[10]!==f||e[11]!==r?(S=d&&r?s.jsxs("div",{style:{width:f?`${f}px`:"auto",height:h?`${h}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(C,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=h,e[8]=d,e[9]=m,e[10]=f,e[11]=r,e[12]=S):S=e[12];let D;e[13]!==S?(D=s.jsx(Qo,{children:S}),e[13]=S,e[14]=D):D=e[14];let j;return e[15]!==a||e[16]!==g||e[17]!==c||e[18]!==D?(j=s.jsxs(Yo,{sensors:c,collisionDetection:Xo,onDragStart:w,onDragCancel:y,onDragEnd:g,children:[a,D]}),e[15]=a,e[16]=g,e[17]=c,e[18]=D,e[19]=j):j=e[19],j},va=ur()(Xi(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 rP(t){const e=rt.c(289),{t:n}=mt(),{group:r,groupKey:i,projectId:a,hideGroupLabel:o,hasSessionSearchQuery:c,normalizedSessionSearchQuery:d,groupSearchDataByGroup:p,expandedSessionGroups:m,collapsedGroups:u,hideDirectoryControls:f,collapsedFolderIds:b,toggleFolderCollapse:h,renameFolder:v,deleteFolder:x,showDeletionDialog:g,setDeleteFolderConfirm:w,renderSessionNode:y,projectRepoStatus:S,lastRepoStatus:D,toggleGroupSessionLimit:j,mobileVariant:I,alwaysShowActions:A,activeProjectId:E,setActiveProjectIdOnly:P,setActiveMainTab:k,setSessionSwitcherOpen:N,openNewSessionDraft:T,addSessionToFolder:M,createFolderAndStartRename:R,renamingFolderId:L,renameFolderDraft:O,setRenameFolderDraft:V,setRenamingFolderId:$,pinnedSessionIds:B,sessionOrderIndex:H,prVisualStateByDirectoryBranch:_,onToggleCollapsedGroup:se,dragHandleProps:oe,compactBodyPadding:ae}=t,ne=ae===void 0?!1:ae;let xe;e[0]!==B||e[1]!==H?(xe=(at,Lt)=>{const os=H.get(at.session.id),rs=H.get(Lt.session.id);if(os!==void 0||rs!==void 0){if(os===void 0)return 1;if(rs===void 0)return-1;if(os!==rs)return os-rs}return ri(at.session,Lt.session,B)},e[0]=B,e[1]=H,e[2]=xe):xe=e[2];const te=xe;let F;e[3]!==r||e[4]!==p||e[5]!==c?(F=c?p.get(r):null,e[3]=r,e[4]=p,e[5]=c,e[6]=F):F=e[6];const z=F,Q=va(pP),re=Hn(mP),K=Q==="minimal";let le;e[7]!==m||e[8]!==i?(le=m.has(i),e[7]=m,e[8]=i,e[9]=le):le=e[9];const Se=le;let ue;e[10]!==u||e[11]!==i||e[12]!==c?(ue=c?!1:u.has(i),e[10]=u,e[11]=i,e[12]=c,e[13]=ue):ue=e[13];const je=ue,W=f?10:5,me=c?z?.groupMatches===!0:!1,X=c;z?.filteredNodes;let ce;e[14]!==te||e[15]!==r.sessions||e[16]!==z?.filteredNodes||e[17]!==X?(ce=[...X?z?.filteredNodes??[]:r.sessions].sort(te),e[14]=te,e[15]=r.sessions,e[16]=z?.filteredNodes,e[17]=X,e[18]=ce):ce=e[18];const ee=ce;let Pe;e[19]!==r.directory||e[20]!==r.folderScopeKey?(Pe=r.folderScopeKey??Ns(r.directory??null),e[19]=r.directory,e[20]=r.folderScopeKey,e[21]=Pe):Pe=e[21];const Ne=Pe;let Y;e[22]!==Ne||e[23]!==re?(Y=Ne?re[Ne]??[]:[],e[22]=Ne,e[23]=re,e[24]=Y):Y=e[24];const he=Y;let ke;if(e[25]!==ee){ke=new Map;const at=Lt=>{Lt.forEach(os=>{ke.set(os.session.id,os),os.children.length>0&&at(os.children)})};at(ee),e[25]=ee,e[26]=ke}else ke=e[26];const be=ke;let fe;if(e[27]!==te||e[28]!==be||e[29]!==he){let at;e[31]!==te||e[32]!==be?(at=Lt=>{const os=Lt.sessionIds.map(rs=>be.get(rs)).filter(uP).sort(te);return{folder:Lt,nodes:os}},e[31]=te,e[32]=be,e[33]=at):at=e[33],fe=he.map(at),e[27]=te,e[28]=be,e[29]=he,e[30]=fe}else fe=e[30];const Te=fe;let Ve;if(e[34]!==Te||e[35]!==r.isArchivedBucket||e[36]!==c||e[37]!==d){const at=new Map(Te.map(dP)),Lt=new Map;for(const{folder:Vt}of Te){if(!Vt.parentId)continue;const cs=Lt.get(Vt.parentId);cs?cs.push(Vt.id):Lt.set(Vt.parentId,[Vt.id])}const os=new Map,rs=Vt=>{const cs=os.get(Vt);if(cs!==void 0)return cs;const sn=at.get(Vt);if(!sn)return os.set(Vt,!1),!1;const Js=Lt.get(Vt)??[];if(r.isArchivedBucket&&sn.nodes.length===0){const nn=Js.some(cn=>rs(cn));return os.set(Vt,nn),nn}if(!c||sn.folder.name.toLowerCase().includes(d)||sn.nodes.length>0)return os.set(Vt,!0),!0;const ln=Js.some(nn=>rs(nn));return os.set(Vt,ln),ln};Ve=Te.filter(Vt=>{const{folder:cs}=Vt;return rs(cs.id)}),e[34]=Te,e[35]=r.isArchivedBucket,e[36]=c,e[37]=d,e[38]=Ve}else Ve=e[38];const G=Ve;let Ie;e[39]!==G?(Ie=new Set(G.flatMap(cP)),e[39]=G,e[40]=Ie):Ie=e[40];const Oe=Ie;let De;if(e[41]!==Oe||e[42]!==ee){let at;e[44]!==Oe?(at=Lt=>!Oe.has(Lt.session.id),e[44]=Oe,e[45]=at):at=e[45],De=ee.filter(at),e[41]=Oe,e[42]=ee,e[43]=De}else De=e[43];const ge=De;let U;e[46]!==G?(U=G.filter(lP),e[46]=G,e[47]=U):U=e[47];const de=U;if(c&&!me&&de.length===0&&ge.length===0)return null;const Ee=ge.length;let _e;e[48]!==r.isArchivedBucket||e[49]!==c||e[50]!==Se||e[51]!==W||e[52]!==ge?(_e=r.isArchivedBucket||c||Se?ge:ge.slice(0,W),e[48]=r.isArchivedBucket,e[49]=c,e[50]=Se,e[51]=W,e[52]=ge,e[53]=_e):_e=e[53];const Z=_e,ie=Ee-Z.length,Ce=oP;let He;e[54]!==ee?(He=Ce(ee),e[54]=ee,e[55]=He):He=e[55];const Ge=He;let Xe;e[56]!==D||e[57]!==a||e[58]!==S?(Xe=a&&S.has(a)?!!S.get(a):D,e[56]=D,e[57]=a,e[58]=S,e[59]=Xe):Xe=e[59];const we=Xe,tt=r.directory??null;let st;e[60]!==tt?(st=Ns(tt),e[60]=tt,e[61]=st):st=e[61];const qe=st;let it;e[62]!==r.branch?(it=r.branch?.trim()??null,e[62]=r.branch,e[63]=it):it=e[63];const lt=it;let ye,Je,Be,ze,nt,Ye,Ue,vt;e[64]!==r.branch||e[65]!==r.isMain||e[66]!==lt||e[67]!==qe||e[68]!==_||e[69]!==n?(ze=qe&<?_.get(`${qe}::${lt}`)??null:null,Ue=!!(ze&&r.branch),Ye=!ze&&!r.isMain&&!!r.branch,nt=ze?.visualState??null,ye=ze&&ze.state==="open"&&ze.checks?n("sessions.sidebar.group.pr.checksPassed",{success:ze.checks.success,total:ze.checks.total}):null,Je=ze&&ze.state==="open"&&ze.checks?[ze.checks.failure>0?n("sessions.sidebar.group.pr.failingCount",{count:ze.checks.failure}):null,ze.checks.pending>0?n("sessions.sidebar.group.pr.pendingCount",{count:ze.checks.pending}):null].filter(iP).join(", "):null,Be=ze&&ze.state==="open"?ze.mergeableState==="blocked"||ze.mergeableState==="dirty"?n("sessions.sidebar.group.pr.conflictsOrBlocked"):ze.mergeableState==="clean"||ze.canMerge===!0?n("sessions.sidebar.group.pr.mergeable"):null:null,vt=ze&&ze.state==="open"&&ze.mergeableState?n("sessions.sidebar.group.pr.mergeState",{state:ze.mergeableState}):null,e[64]=r.branch,e[65]=r.isMain,e[66]=lt,e[67]=qe,e[68]=_,e[69]=n,e[70]=ye,e[71]=Je,e[72]=Be,e[73]=ze,e[74]=nt,e[75]=Ye,e[76]=Ue,e[77]=vt):(ye=e[70],Je=e[71],Be=e[72],ze=e[73],nt=e[74],Ye=e[75],Ue=e[76],vt=e[77]);const Et=vt,Gt=ze?.base??null,ts=ze?.head??null;let Nt;e:{if(!ze){let at;e[78]!==r.branch||e[79]!==r.label?(at=r.branch&&Qb(r.branch,r.label)?{label:r.branch,color:null}:null,e[78]=r.branch,e[79]=r.label,e[80]=at):at=e[80],Nt=at;break e}switch(ze.visualState){case"merged":{let at;e[81]!==n?(at=n("sessions.sidebar.group.pr.status.merged"),e[81]=n,e[82]=at):at=e[82];let Lt;e[83]!==at?(Lt={label:at,color:"var(--pr-merged)"},e[83]=at,e[84]=Lt):Lt=e[84],Nt=Lt;break e}case"open":{let at;e[85]!==ze.canMerge||e[86]!==ze.checks?.state||e[87]!==ze.mergeableState||e[88]!==n?(at=ze.canMerge===!0||ze.mergeableState==="clean"||ze.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]=ze.canMerge,e[86]=ze.checks?.state,e[87]=ze.mergeableState,e[88]=n,e[89]=at):at=e[89],Nt=at;break e}case"blocked":{let at;e[90]!==ze.mergeableState||e[91]!==n?(at=ze.mergeableState==="dirty"?n("sessions.sidebar.group.pr.status.mergeConflicts"):n("sessions.sidebar.group.pr.status.mergeBlocked"),e[90]=ze.mergeableState,e[91]=n,e[92]=at):at=e[92];let Lt;e[93]!==at?(Lt={label:at,color:"var(--pr-blocked)"},e[93]=at,e[94]=Lt):Lt=e[94],Nt=Lt;break e}case"draft":{let at;e[95]!==n?(at=n("sessions.sidebar.group.pr.status.draft"),e[95]=n,e[96]=at):at=e[96];let Lt;e[97]!==at?(Lt={label:at,color:"var(--pr-draft)"},e[97]=at,e[98]=Lt):Lt=e[98],Nt=Lt;break e}case"closed":{let at;e[99]!==n?(at=n("sessions.sidebar.group.pr.status.closed"),e[99]=n,e[100]=at):at=e[100];let Lt;e[101]!==at?(Lt={label:at,color:"var(--pr-closed)"},e[101]=at,e[102]=Lt):Lt=e[102],Nt=Lt;break e}default:Nt=null}}const St=Nt,Zt=St?.color??(nt?`var(--pr-${nt})`:void 0);let ut;e[103]!==ze?.url?(ut=at=>{at.preventDefault(),at.stopPropagation();const Lt=ze?.url;Lt&&Qn(Lt)},e[103]=ze?.url,e[104]=ut):ut=e[104];const Xt=ut;let as,Bt,ls,gs,us,xs;if(e[105]!==E||e[106]!==M||e[107]!==G||e[108]!==A||e[109]!==b||e[110]!==R||e[111]!==x||e[112]!==Ne||e[113]!==r.directory||e[114]!==r.isArchivedBucket||e[115]!==r.isMain||e[116]!==r.worktree||e[117]!==c||e[118]!==K||e[119]!==I||e[120]!==T||e[121]!==a||e[122]!==v||e[123]!==O||e[124]!==L||e[125]!==y||e[126]!==de||e[127]!==k||e[128]!==P||e[129]!==w||e[130]!==V||e[131]!==$||e[132]!==N||e[133]!==g||e[134]!==h){const at=(rs,Vt,cs)=>{const sn=G.filter(nn=>{const{folder:cn}=nn;return cn.parentId===rs.id}),Js=sn.length>0?s.jsx(s.Fragment,{children:sn.map(nn=>{const{folder:cn,nodes:un}=nn;return at(cn,un,cs+1)})}):void 0,Us=nn=>{const cn=G.find(jn=>{const{folder:an}=jn;return an.id===nn})?.nodes??[],un=G.filter(jn=>{const{folder:an}=jn;return an.parentId===nn});return[...Ce(cn),...un.flatMap(jn=>{const{folder:an}=jn;return Us(an.id)})]},ln=r.isArchivedBucket?Us(rs.id):[];return s.jsx(sP,{folderId:rs.id,children:(nn,cn)=>s.jsx(WI,{folder:rs,sessions:Vt,subFolderItems:Js,isCollapsed:c?!1:b.has(rs.id),onToggle:()=>h(rs.id),onRename:un=>{Ne&&v(Ne,rs.id,un)},onDelete:()=>{if(r.isArchivedBucket){vr.requestDelete({sessions:ln,mode:"session"});return}if(!Ne)return;if(!g){x(Ne,rs.id);return}const un=G.filter(an=>{const{folder:gn}=an;return gn.parentId===rs.id}).length,jn=Vt.length;w({scopeKey:Ne,folderId:rs.id,folderName:rs.name,subFolderCount:un,sessionCount:jn})},renderSessionNode:y,groupDirectory:r.directory,projectId:a,mobileVariant:I,alwaysShowActions:A,isRenaming:L===rs.id,renameDraft:L===rs.id?O:void 0,onRenameDraftChange:un=>V(un),onRenameSave:()=>{const un=O.trim();un&&Ne&&v(Ne,rs.id,un),$(null),V("")},onRenameCancel:()=>{$(null),V("")},droppableRef:nn,isDropTarget:cn,depth:cs,onNewSession:()=>{a&&a!==E&&P(a),k("chat"),I&&N(!1),T({directoryOverride:r.directory,targetFolderId:rs.id})},onNewSubFolder:cs===0?()=>{Ne&&R(Ne,rs.id)}:void 0,hideActions:!1,archivedBucket:r.isArchivedBucket===!0})},rs.id)},Lt=()=>de.map(rs=>{const{folder:Vt,nodes:cs}=rs;return at(Vt,cs,0)}),os=!!(!r.isMain&&r.worktree);Bt=A?os?"pr-14":"pr-7":K?os?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":os?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",as=nP,ls=Ne,gs=G.length>0,e[141]!==M||e[142]!==Ne?(us=(rs,Vt)=>{Ne&&M(Ne,Vt,rs)},e[141]=M,e[142]=Ne,e[143]=us):us=e[143],xs=Lt(),e[105]=E,e[106]=M,e[107]=G,e[108]=A,e[109]=b,e[110]=R,e[111]=x,e[112]=Ne,e[113]=r.directory,e[114]=r.isArchivedBucket,e[115]=r.isMain,e[116]=r.worktree,e[117]=c,e[118]=K,e[119]=I,e[120]=T,e[121]=a,e[122]=v,e[123]=O,e[124]=L,e[125]=y,e[126]=de,e[127]=k,e[128]=P,e[129]=w,e[130]=V,e[131]=$,e[132]=N,e[133]=g,e[134]=h,e[135]=as,e[136]=Bt,e[137]=ls,e[138]=gs,e[139]=us,e[140]=xs}else as=e[135],Bt=e[136],ls=e[137],gs=e[138],us=e[139],xs=e[140];let At;if(e[144]!==r.directory||e[145]!==r.isArchivedBucket||e[146]!==a||e[147]!==y||e[148]!==Z){let at;e[150]!==r.directory||e[151]!==r.isArchivedBucket||e[152]!==a||e[153]!==y?(at=Lt=>y(Lt,0,r.directory,a,r.isArchivedBucket===!0),e[150]=r.directory,e[151]=r.isArchivedBucket,e[152]=a,e[153]=y,e[154]=at):at=e[154],At=Z.map(at),e[144]=r.directory,e[145]=r.isArchivedBucket,e[146]=a,e[147]=y,e[148]=Z,e[149]=At}else At=e[149];let We;e[155]!==G.length||e[156]!==r.isArchivedBucket||e[157]!==n||e[158]!==Ee?(We=Ee===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]=Ee,e[159]=We):We=e[159];let Rt;e[160]!==i||e[161]!==Se||e[162]!==ie||e[163]!==n||e[164]!==j?(Rt=ie>0&&!Se?s.jsx("button",{type:"button",onClick:()=>j(i),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]=i,e[161]=Se,e[162]=ie,e[163]=n,e[164]=j,e[165]=Rt):Rt=e[165];let Dt;e[166]!==i||e[167]!==Se||e[168]!==W||e[169]!==n||e[170]!==j||e[171]!==Ee?(Dt=Se&&Ee>W?s.jsx("button",{type:"button",onClick:()=>j(i),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]=i,e[167]=Se,e[168]=W,e[169]=n,e[170]=j,e[171]=Ee,e[172]=Dt):Dt=e[172];let wt;e[173]!==as||e[174]!==ls||e[175]!==gs||e[176]!==us||e[177]!==xs||e[178]!==At||e[179]!==We||e[180]!==Rt||e[181]!==Dt?(wt=s.jsxs(as,{scopeKey:ls,hasFolders:gs,onSessionDroppedOnFolder:us,children:[xs,At,We,Rt,Dt]}),e[173]=as,e[174]=ls,e[175]=gs,e[176]=us,e[177]=xs,e[178]=At,e[179]=We,e[180]=Rt,e[181]=Dt,e[182]=wt):wt=e[182];const Jt=wt,_t=ne?"pb-2 pl-1":"pb-3 pl-4";if(o){let at;e[183]!==_t?(at=pe("oc-group-body",_t),e[183]=_t,e[184]=at):at=e[184];let Lt;return e[185]!==Jt||e[186]!==at?(Lt=s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:at,children:Jt})}),e[185]=Jt,e[186]=at,e[187]=Lt):Lt=e[187],Lt}let Fs;e[188]===Symbol.for("react.memo_cache_sentinel")?(Fs=pe("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),e[188]=Fs):Fs=e[188];let ft;e[189]!==i||e[190]!==se?(ft=()=>se(i),e[189]=i,e[190]=se,e[191]=ft):ft=e[191];let ds;e[192]!==i||e[193]!==se?(ds=at=>{(at.key==="Enter"||at.key===" ")&&(at.preventDefault(),se(i))},e[192]=i,e[193]=se,e[194]=ds):ds=e[194];let Qt;e[195]!==r.label||e[196]!==je||e[197]!==n?(Qt=je?n("sessions.sidebar.group.expandAria",{label:r.label}):n("sessions.sidebar.group.collapseAria",{label:r.label}),e[195]=r.label,e[196]=je,e[197]=n,e[198]=Qt):Qt=e[198];const ks=!je,_s=oe?.setActivatorNodeRef;let J;e[199]!==Bt?(J=pe("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",Bt),e[199]=Bt,e[200]=J):J=e[200];let pt;e[201]!==oe?.listeners?(pt=oe?.listeners??{},e[201]=oe?.listeners,e[202]=pt):pt=e[202];let jt;e[203]!==A||e[204]!==Gt||e[205]!==Zt||e[206]!==ye||e[207]!==Je||e[208]!==r.branch||e[209]!==r.isArchivedBucket||e[210]!==r.isMain||e[211]!==r.label||e[212]!==r.worktree||e[213]!==Xt||e[214]!==ts||e[215]!==je||e[216]!==Et||e[217]!==Be||e[218]!==d||e[219]!==ze||e[220]!==Ue?(jt=Ue&&ze?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(C,{name:"git-branch",className:pe("h-3.5 w-3.5 shrink-0",A?"hidden":"group-hover/gh:hidden"),style:Zt?{color:Zt}:void 0}),s.jsx("span",{className:pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:je?s.jsx(C,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),ze.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:aP,onClick:Xt,children:["#",ze.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",ze.number]})]})}),s.jsx(Pt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Gt||ts?s.jsx("div",{className:"text-muted-foreground truncate",children:Gt&&ts?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Gt}),s.jsx(C,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:ts})]}):s.jsx("span",{children:Gt??ts??""})}):null,Et?s.jsx("div",{className:"text-muted-foreground truncate",children:Et}):null,Be||ye?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Be??"",Be&&ye?" • ":"",ye??"",Je?` (${Je})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:r.branch})]}):r.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(C,{name:"archive",className:pe("h-3.5 w-3.5 shrink-0 text-muted-foreground",A?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:je?s.jsx(C,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Bi(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(C,{name:"git-branch",className:pe("h-3.5 w-3.5 shrink-0 text-muted-foreground",A?"hidden":"group-hover/gh:hidden"),style:Zt?{color:Zt}:void 0}),s.jsx("span",{className:pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:je?s.jsx(C,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Bi(r.label,d)})]}):Bi(r.label,d),e[203]=A,e[204]=Gt,e[205]=Zt,e[206]=ye,e[207]=Je,e[208]=r.branch,e[209]=r.isArchivedBucket,e[210]=r.isMain,e[211]=r.label,e[212]=r.worktree,e[213]=Xt,e[214]=ts,e[215]=je,e[216]=Et,e[217]=Be,e[218]=d,e[219]=ze,e[220]=Ue,e[221]=jt):jt=e[221];let Wt;e[222]!==jt?(Wt=s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:jt}),e[222]=jt,e[223]=Wt):Wt=e[223];let es;e[224]!==Gt||e[225]!==Zt||e[226]!==ye||e[227]!==Je||e[228]!==r.isArchivedBucket||e[229]!==r.isMain||e[230]!==ts||e[231]!==we||e[232]!==Et||e[233]!==Be||e[234]!==ze||e[235]!==Ye||e[236]!==Ue||e[237]!==St?(es=Ye&&St?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[r.isArchivedBucket?s.jsx(C,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!r.isMain||we?Ue&&ze?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:Zt?{color:Zt}:void 0})})}),s.jsx(Pt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Gt||ts?s.jsx("div",{className:"text-muted-foreground truncate",children:Gt&&ts?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Gt}),s.jsx(C,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:ts})]}):s.jsx("span",{children:Gt??ts??""})}):null,Et?s.jsx("div",{className:"text-muted-foreground truncate",children:Et}):null,Be||ye?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Be??"",Be&&ye?" • ":"",ye??"",Je?` (${Je})`:""]}):null]})})]}):s.jsx(C,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Zt?{color:Zt}:void 0}):null,s.jsx("span",{className:pe("min-w-0 truncate text-[11px] font-medium",!St.color&&"text-muted-foreground/80"),style:St.color?{color:St.color}:void 0,children:St.label})]}):null,e[224]=Gt,e[225]=Zt,e[226]=ye,e[227]=Je,e[228]=r.isArchivedBucket,e[229]=r.isMain,e[230]=ts,e[231]=we,e[232]=Et,e[233]=Be,e[234]=ze,e[235]=Ye,e[236]=Ue,e[237]=St,e[238]=es):es=e[238];let ns;e[239]!==Wt||e[240]!==es?(ns=s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[Wt,es]}),e[239]=Wt,e[240]=es,e[241]=ns):ns=e[241];let Cs;e[242]!==_s||e[243]!==J||e[244]!==pt||e[245]!==ns?(Cs=s.jsx("div",{ref:_s,className:J,...pt,children:ns}),e[242]=_s,e[243]=J,e[244]=pt,e[245]=ns,e[246]=Cs):Cs=e[246];let Is;e[247]!==Ge||e[248]!==A||e[249]!==r.isArchivedBucket||e[250]!==r.label||e[251]!==n?(Is=r.isArchivedBucket&&Ge.length>0?s.jsx("div",{className:pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:at=>{at.stopPropagation(),vr.requestDelete({sessions:Ge,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(C,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,e[247]=Ge,e[248]=A,e[249]=r.isArchivedBucket,e[250]=r.label,e[251]=n,e[252]=Is):Is=e[252];let Ke;e[253]!==Ge||e[254]!==A||e[255]!==r.directory||e[256]!==r.isMain||e[257]!==r.label||e[258]!==r.worktree||e[259]!==n?(Ke=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",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:at=>{at.stopPropagation(),vr.requestDelete({sessions:Ge,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(C,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,e[253]=Ge,e[254]=A,e[255]=r.directory,e[256]=r.isMain,e[257]=r.label,e[258]=r.worktree,e[259]=n,e[260]=Ke):Ke=e[260];let xt;e[261]!==E||e[262]!==A||e[263]!==r.directory||e[264]!==r.label||e[265]!==I||e[266]!==T||e[267]!==a||e[268]!==k||e[269]!==P||e[270]!==N||e[271]!==n?(xt=r.directory?s.jsx("div",{className:pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:at=>{at.stopPropagation(),a&&a!==E&&P(a),k("chat"),I&&N(!1),T({directoryOverride:r.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.newDraftInGroupAria",{label:r.label}),children:s.jsx(C,{name:"add",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.project.actions.newDraftSession")})})]})}):null,e[261]=E,e[262]=A,e[263]=r.directory,e[264]=r.label,e[265]=I,e[266]=T,e[267]=a,e[268]=k,e[269]=P,e[270]=N,e[271]=n,e[272]=xt):xt=e[272];let kt;e[273]!==ft||e[274]!==ds||e[275]!==Qt||e[276]!==ks||e[277]!==Cs||e[278]!==Is||e[279]!==Ke||e[280]!==xt?(kt=s.jsxs("div",{className:Fs,onClick:ft,role:"button",tabIndex:0,onKeyDown:ds,"aria-label":Qt,"aria-expanded":ks,children:[Cs,Is,Ke,xt]}),e[273]=ft,e[274]=ds,e[275]=Qt,e[276]=ks,e[277]=Cs,e[278]=Is,e[279]=Ke,e[280]=xt,e[281]=kt):kt=e[281];let Tt;e[282]!==Jt||e[283]!==_t||e[284]!==je?(Tt=je?null:s.jsx("div",{className:pe("oc-group-body",_t),children:Jt}),e[282]=Jt,e[283]=_t,e[284]=je,e[285]=Tt):Tt=e[285];let ss;return e[286]!==kt||e[287]!==Tt?(ss=s.jsxs("div",{className:"oc-group",children:[kt,Tt]}),e[286]=kt,e[287]=Tt,e[288]=ss):ss=e[288],ss}function aP(t){return t.stopPropagation()}function iP(t){return!!t}function oP(t){const e=[],n=r=>{r.forEach(i=>{e.push(i.session),i.children.length>0&&n(i.children)})};return n(t),e}function lP(t){const{folder:e}=t;return!e.parentId}function cP(t){return t.folder.sessionIds}function dP(t){return[t.folder.id,t]}function uP(t){return!!t}function mP(t){return t.foldersMap}function pP(t){return t.displayMode}function hP(t){const e=rt.c(37),{t:n}=mt(),{hideDirectoryControls:r,handleOpenDirectoryDialog:i,handleNewSession:a,canOpenMultiRun:o,openMultiRunLauncher:c,headerActionIconClass:d,reserveHeaderActionsSpace:p,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:f,sessionSearchInputRef:b,sessionSearchQuery:h,setSessionSearchQuery:v,hasSessionSearchQuery:x,searchMatchCount:g,collapseAllProjects:w,expandAllProjects:y,openScheduledTasksDialog:S,selectionModeEnabled:D,onToggleSelectionMode:j,showSidebarToggle:I,onToggleSidebar:A,avoidWindowControlsOverlay:E}=t,P=I===void 0?!1:I,k=E===void 0?!1:E,N=va(yP),T=va(bP),M=va(xP),R=va(gP);if(r)return null;const L=P?k?"pl-[5.5rem] pr-3":"pl-3 pr-3":"px-2.5 py-1";let O;e[0]!==L?(O=pe("select-none flex-shrink-0",L),e[0]=L,e[1]=O):O=e[1];let V;e[2]!==k||e[3]!==P?(V=P&&k?{paddingTop:"var(--oc-safe-area-top, 0px)"}:void 0,e[2]=k,e[3]=P,e[4]=V):V=e[4];let $;e[5]!==k||e[6]!==o||e[7]!==w||e[8]!==N||e[9]!==y||e[10]!==a||e[11]!==i||e[12]!==x||e[13]!==m||e[14]!==d||e[15]!==u||e[16]!==j||e[17]!==A||e[18]!==c||e[19]!==S||e[20]!==p||e[21]!==g||e[22]!==D||e[23]!==b||e[24]!==h||e[25]!==M||e[26]!==f||e[27]!==v||e[28]!==T||e[29]!==P||e[30]!==n||e[31]!==R?($=p?s.jsxs("div",{className:pe("flex h-auto flex-col gap-1",P?k?"min-h-[calc(var(--oc-header-height,56px)-var(--oc-safe-area-top,0px))] justify-center":"min-h-[var(--oc-header-height,56px)] justify-center":"min-h-8"),children:[s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[P&&A?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50","aria-label":n("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(C,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.closeSessions")})})]}):null,s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:m,"aria-label":n("sessions.sidebar.header.actions.addProject"),children:s.jsx(C,{name:"folder-add",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.addProject")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:m,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(C,{name:"chat-new",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{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(Yb,{className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newMultiRun")})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,className:m,"aria-label":n("sessions.sidebar.header.actions.scheduledTasks"),children:s.jsx(C,{name:"calendar-schedule",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.scheduledTasks")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>f(fP),className:m,"aria-label":n("sessions.sidebar.header.actions.searchSessions"),"aria-expanded":u,children:s.jsx(C,{name:"search",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.searchSessions")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:pe(m,D&&"bg-interactive-hover text-primary"),"aria-label":n(D?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),"aria-pressed":D,children:s.jsx(C,{name:"checkbox-multiple",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n(D?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions")})})]}),s.jsxs(Bs,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":n("sessions.sidebar.header.actions.sessionDisplayMode"),children:s.jsx(C,{name:"equalizer-2",className:d})})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.displayMode.label")})})]}),s.jsxs($s,{align:"end",className:"min-w-[160px]",children:[s.jsxs(zt,{onClick:()=>M("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),N==="default"?s.jsx(C,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(zt,{onClick:()=>M("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),N==="minimal"?s.jsx(C,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(An,{}),s.jsxs(zt,{onClick:R,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),T?s.jsx(C,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(An,{}),s.jsxs(zt,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(C,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(zt,{onClick:y,className:"flex items-center gap-2",children:[s.jsx(C,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]})]})]})]}),u?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[x?s.jsx("span",{children:g===1?n("sessions.sidebar.header.search.matchCountSingle",{count:g}):n("sessions.sidebar.header.search.matchCountPlural",{count:g})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(C,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:b,value:h,onChange:H=>v(H.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:H=>{H.key==="Escape"&&(H.stopPropagation(),x?v(""):f(!1))}}),h.length>0?s.jsx("button",{type:"button",onClick:()=>v(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[5]=k,e[6]=o,e[7]=w,e[8]=N,e[9]=y,e[10]=a,e[11]=i,e[12]=x,e[13]=m,e[14]=d,e[15]=u,e[16]=j,e[17]=A,e[18]=c,e[19]=S,e[20]=p,e[21]=g,e[22]=D,e[23]=b,e[24]=h,e[25]=M,e[26]=f,e[27]=v,e[28]=T,e[29]=P,e[30]=n,e[31]=R,e[32]=$):$=e[32];let B;return e[33]!==O||e[34]!==V||e[35]!==$?(B=s.jsx("div",{className:O,style:V,children:$}),e[33]=O,e[34]=V,e[35]=$,e[36]=B):B=e[36],B}function fP(t){return!t}function gP(t){return t.toggleRecentSection}function xP(t){return t.setDisplayMode}function bP(t){return t.showRecentSection}function yP(t){return t.displayMode}const Hp=7;function vP(t){const e=rt.c(20),{sections:n,renderSessionNode:r}=t,{t:i}=mt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[o,c]=l.useState(a);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[p,m]=l.useState(d);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=y=>{c(S=>{const D=new Set(S);return D.has(y)?D.delete(y):D.add(y),D})},e[2]=u):u=e[2];const f=u;let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=y=>{m(S=>{const D=new Set(S);return D.has(y)?D.delete(y):D.add(y),D})},e[3]=b):b=e[3];const h=b;let v,x,g;if(e[4]!==o||e[5]!==p||e[6]!==r||e[7]!==n||e[8]!==i){g=Symbol.for("react.early_return_sentinel");e:{const y=n.filter(wP);if(y.length===0){g=null;break e}v="space-y-2 pb-2 pt-1";let S;e[12]!==o||e[13]!==p||e[14]!==r||e[15]!==i?(S=D=>{const j=o.has(D.key),I=p.has(D.key),A=I?D.items:D.items.slice(0,Hp),E=D.items.length-A.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>f(D.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?s.jsx(C,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:D.title})]}),j?null:s.jsxs("div",{className:pe("space-y-0.5 pl-7"),children:[A.map(P=>r(P.node,0,P.groupDirectory,P.projectId,!1,P.secondaryMeta,"recent")),E>0&&!I?s.jsx("button",{type:"button",onClick:()=>h(D.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:E===1?i("sessions.sidebar.group.showMoreSingle",{count:E}):i("sessions.sidebar.group.showMorePlural",{count:E})}):null,I&&D.items.length>Hp?s.jsx("button",{type:"button",onClick:()=>h(D.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:i("sessions.sidebar.group.showFewer")}):null]})]},D.key)},e[12]=o,e[13]=p,e[14]=r,e[15]=i,e[16]=S):S=e[16],x=y.map(S)}e[4]=o,e[5]=p,e[6]=r,e[7]=n,e[8]=i,e[9]=v,e[10]=x,e[11]=g}else v=e[9],x=e[10],g=e[11];if(g!==Symbol.for("react.early_return_sentinel"))return g;let w;return e[17]!==v||e[18]!==x?(w=s.jsx("div",{className:v,children:x}),e[17]=v,e[18]=x,e[19]=w):w=e[19],w}function wP(t){return t.items.length>0}const Cc="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 jP(t){const e=rt.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:i,onOpenUpdate:a,showRuntimeButtons:o,showUpdateButton:c}=t,d=o===void 0?!0:o,p=c===void 0?!0:c,{t:m}=mt();let u;e[0]!==i||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(u=d?s.jsxs(s.Fragment,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Cc,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(C,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:Cc,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(C,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:Cc,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(C,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=i,e[1]=n,e[2]=r,e[3]=d,e[4]=m,e[5]=u):u=e[5];let f;e[6]!==a||e[7]!==p||e[8]!==m?(f=p?s.jsx(ve,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:a,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=a,e[7]=p,e[8]=m,e[9]=f):f=e[9];let b;return e[10]!==u||e[11]!==f?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[u,f]}),e[10]=u,e[11]=f,e[12]=b):b=e[12],b}const NP=t=>{const e=rt.c(58),{id:n,projectLabel:r,projectDescription:i,projectIcon:a,projectColor:o,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:f,isStuck:b,hideDirectoryControls:h,alwaysShowActions:v,onToggle:x,onNewSession:g,onNewWorktreeSession:w,onRenameStart:y,onClose:S,sentinelRef:D,children:j,showCreateButtons:I,hideHeader:A,openSidebarMenuKey:E,setOpenSidebarMenuKey:P}=t,k=I===void 0?!0:I,N=A===void 0?!1:A,{t:T}=mt(),{currentTheme:M}=Nr();let R;e[0]!==n?(R={id:n},e[0]=n,e[1]=R):R=e[1];const{attributes:L,listeners:O,setNodeRef:V,transform:$,transition:B,isDragging:H}=xd(R),[_,se]=l.useState(!1),oe=l.useRef(!1),ae=`project:${n}`,ne=E===ae;let xe;e[2]===Symbol.for("react.memo_cache_sentinel")?(xe=()=>{se(!1)},e[2]=xe):xe=e[2];const te=c?.updatedAt;let F;e[3]!==n||e[4]!==te?(F=[n,te],e[3]=n,e[4]=te,e[5]=F):F=e[5],l.useEffect(xe,F);const z=a?kl[a]:null,Q=o?ro[o]??null:null;let re;e[6]!==M||e[7]!==n||e[8]!==_||e[9]!==c?(re=_?null:no({id:n,iconImage:c},{themeVariant:M.metadata.variant,iconColor:M.colors.surface.foreground}),e[6]=M,e[7]=n,e[8]=_,e[9]=c,e[10]=re):re=e[10];const K=re;let le;e[11]!==ae||e[12]!==P?(le=fe=>{P(fe?ae:null)},e[11]=ae,e[12]=P,e[13]=le):le=e[13];const Se=le,ue=CP,je=IP,W=PP;let me;e[14]===Symbol.for("react.memo_cache_sentinel")?(me=fe=>{(fe.button===2||fe.button===0&&fe.ctrlKey)&&(oe.current=!0)},e[14]=me):me=e[14];const X=me;let ce;e[15]!==x?(ce=()=>{if(oe.current){oe.current=!1;return}x()},e[15]=x,e[16]=ce):ce=e[16];const ee=ce;let Pe;e[17]!==$?(Pe=bd.Transform.toString($),e[17]=$,e[18]=Pe):Pe=e[18];let Ne;e[19]!==Pe||e[20]!==B?(Ne={transform:Pe,transition:B},e[19]=Pe,e[20]=B,e[21]=Ne):Ne=e[21];const Y=H&&"opacity-30";let he;e[22]!==Y?(he=pe("relative",Y),e[22]=Y,e[23]=he):he=e[23];let ke;e[24]!==v||e[25]!==L||e[26]!==Se||e[27]!==ee||e[28]!==h||e[29]!==N||e[30]!==Q||e[31]!==n||e[32]!==K||e[33]!==m||e[34]!==p||e[35]!==f||e[36]!==ne||e[37]!==u||e[38]!==b||e[39]!==O||e[40]!==S||e[41]!==g||e[42]!==w||e[43]!==y||e[44]!==i||e[45]!==d||e[46]!==z||e[47]!==r||e[48]!==D||e[49]!==k||e[50]!==T?(ke=N?null:s.jsxs(s.Fragment,{children:[f&&s.jsx("div",{ref:D,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:pe("w-full text-left group/project select-none"),style:{backgroundColor:f&&b?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...L,children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:X,onClick:ee,...O,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&&!h?v?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":v?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:pe("h-3.5 w-3.5 items-center justify-center text-muted-foreground",v?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:p?s.jsx(C,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(C,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),K?s.jsx("span",{className:pe("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",v?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:K,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>se(!0)})}):z?s.jsx(C,{name:z,className:pe("h-3.5 w-3.5",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:Q?{color:Q}:void 0}):s.jsx(C,{name:"folder",className:pe("h-3.5 w-3.5 text-muted-foreground/80",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:Q?{color:Q}:void 0})]}),s.jsx("span",{className:pe("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(Pt,{side:"right",sideOffset:8,children:i})]}),s.jsxs("div",{className:pe("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",k?"right-7":"right-0.5"),children:[k&&u&&!h&&w?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:fe=>{fe.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",v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":T("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(C,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(Bs,{open:ne,onOpenChange:Se,children:[s.jsx(Os,{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",ne?"opacity-100 pointer-events-auto":v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":T("sessions.sidebar.project.actions.projectMenu"),onPointerDown:je,onMouseDown:W,onClick:ue,children:s.jsx(C,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs($s,{align:"end",className:"min-w-[180px]",children:[k&&!u&&!h&&g&&s.jsxs(zt,{onClick:g,children:[s.jsx(C,{name:"add",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.newSession")]}),s.jsxs(zt,{onClick:y,children:[s.jsx(C,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.session.menu.rename")]}),s.jsxs(zt,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"close",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.closeProject")]})]})]})]}),k&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:fe=>{fe.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",v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":T(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(C,{name:"add",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=v,e[25]=L,e[26]=Se,e[27]=ee,e[28]=h,e[29]=N,e[30]=Q,e[31]=n,e[32]=K,e[33]=m,e[34]=p,e[35]=f,e[36]=ne,e[37]=u,e[38]=b,e[39]=O,e[40]=S,e[41]=g,e[42]=w,e[43]=y,e[44]=i,e[45]=d,e[46]=z,e[47]=r,e[48]=D,e[49]=k,e[50]=T,e[51]=ke):ke=e[51];let be;return e[52]!==j||e[53]!==V||e[54]!==Ne||e[55]!==he||e[56]!==ke?(be=s.jsxs("div",{ref:V,style:Ne,className:he,children:[ke,j]}),e[52]=j,e[53]=V,e[54]=Ne,e[55]=he,e[56]=ke,e[57]=be):be=e[57],be},SP=t=>{const e=rt.c(21),{id:n,disabled:r,children:i}=t,a=r===void 0?!1:r;let o;e[0]!==a||e[1]!==n?(o={id:n,disabled:a},e[0]=a,e[1]=n,e[2]=o):o=e[2];const{listeners:c,setNodeRef:d,setActivatorNodeRef:p,transform:m,transition:u,isDragging:f}=xd(o);let b;e[3]!==c||e[4]!==p?(b={listeners:c,setActivatorNodeRef:p},e[3]=c,e[4]=p,e[5]=b):b=e[5];const h=b;let v;e[6]!==m?(v=bd.Transform.toString(m),e[6]=m,e[7]=v):v=e[7];let x;e[8]!==v||e[9]!==u?(x={transform:v,transition:u},e[8]=v,e[9]=u,e[10]=x):x=e[10];const g=f&&"opacity-50";let w;e[11]!==g?(w=pe("space-y-0.5 rounded-md",g),e[11]=g,e[12]=w):w=e[12];let y;e[13]!==i||e[14]!==h?(y=typeof i=="function"?i(h):i,e[13]=i,e[14]=h,e[15]=y):y=e[15];let S;return e[16]!==d||e[17]!==x||e[18]!==w||e[19]!==y?(S=s.jsx("div",{ref:d,style:x,className:w,children:y}),e[16]=d,e[17]=x,e[18]=w,e[19]=y,e[20]=S):S=e[20],S},kP=l.memo(SP);function CP(t){t.stopPropagation()}function IP(t){t.stopPropagation()}function PP(t){t.stopPropagation()}function AP(t){const e=rt.c(25),{t:n}=mt();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let i;e[1]===Symbol.for("react.memo_cache_sentinel")?(i={coordinateGetter:ux},e[1]=i):i=e[1];const a=qo(Fi(Jo,r),Fi(cx,i));let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[2]=o):o=e[2];const c=qo(Fi(Jo,o));if(t.projectSections.length===0){const f=(t.mobileVariant,"");let b;e[3]!==f?(b=pe("space-y-1 pb-1 pl-2.5 pr-2",f),e[3]=f,e[4]=b):b=e[4];let h;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==b?(h=s.jsxs(As,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=b,e[8]=h):h=e[8],h}if(t.sectionsForRender.length===0){const f=(t.mobileVariant,"");let b;e[9]!==f?(b=pe("space-y-1 pb-1 pl-2.5 pr-2",f),e[9]=f,e[10]=b):b=e[10];let h;return e[11]!==t.searchEmptyState||e[12]!==b?(h=s.jsx(As,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=b,e[13]=h):h=e[13],h}const d=(t.mobileVariant,"");let p;e[14]!==d?(p=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]!==a||e[18]!==t||e[19]!==n?(m=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const f=t.sectionsForRender.find(x=>x.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!f)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const b=f.groups.find(OP)??f.groups.find(LP)??f.groups.find(FP)??f.groups[0];if(!b)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const h=f.groups.find(RP);return[b,...h&&h.id!==b.id?[h]:[]].map(x=>{const g=`${f.project.id}:${x.id}`,w=x.id===b.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(x,g,f.project.id,w,null,!0)},g)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Yo,{sensors:a,collisionDetection:Xo,onDragEnd:f=>{if(t.isInlineEditing)return;const{active:b,over:h}=f;if(!h||b.id===h.id)return;const v=t.sectionsForRender.findIndex(g=>g.project.id===b.id),x=t.sectionsForRender.findIndex(g=>g.project.id===h.id);v===-1||x===-1||v===x||t.reorderProjects(v,x)},children:[s.jsx(Ec,{items:t.sectionsForRender.map(EP),strategy:Yd,children:t.sectionsForRender.map(f=>{const b=f.project,h=b.id,v=Gh(b.label?.trim()||Pa(b.normalizedPath,t.homeDirectory)||b.normalizedPath),x=Ki(b.normalizedPath,t.homeDirectory),g=t.collapsedProjects.has(h),w=h===t.activeProjectId,y=t.projectRepoStatus.get(h),S=t.getOrderedGroups(h,f.groups),D=S.find(MP)??null,j=D?S.filter(I=>I.id!==D.id):S;return s.jsx(NP,{id:h,projectLabel:v,projectDescription:x,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground,isCollapsed:g,isActiveProject:w,isRepo:!!y,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(h),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(h),onNewSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:b.normalizedPath})},onNewWorktreeSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(h),onClose:()=>t.removeProject(h),sentinelRef:I=>{t.projectHeaderSentinelRefs.current.set(h,I)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:g?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:f.groups.length>0?s.jsxs(Yo,{sensors:c,collisionDetection:Xo,onDragEnd:I=>{if(t.isInlineEditing)return;const{active:A,over:E}=I;if(!E||A.id===E.id)return;const P=j.findIndex(M=>M.id===A.id),k=j.findIndex(M=>M.id===E.id);if(P===-1||k===-1||P===k)return;const N=dx(j,P,k).map(TP),T=D?[D.id,...N]:N;t.setGroupOrderByProject(M=>{const R=new Map(M);return R.set(h,T),R})},children:[D?t.renderGroupSessions(D,`${h}:${D.id}`,h,!0):null,s.jsx(Ec,{items:j.map(DP),strategy:Yd,children:j.map(I=>{const A=`${h}:${I.id}`;return s.jsx(kP,{id:I.id,disabled:t.isInlineEditing,children:E=>t.renderGroupSessions(I,A,h,!1,E)},I.id)})}),s.jsx(Qo,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},h)})}),s.jsx(Qo,{dropAnimation:null})]})}),e[16]=c,e[17]=a,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(As,{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 DP(t){return t.id}function TP(t){return t.id}function MP(t){return t.isMain}function EP(t){return t.project.id}function RP(t){return t.isArchivedBucket}function FP(t){return t.isMain}function LP(t){return t.sessions.length>0}function OP(t){return t.isMain&&t.sessions.length>0}function $P(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(),i=e.getFullYear(),a=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${i}, ${a}:${o}`}function BP(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 _P(t){const e=t.info.role==="user"?"User":"Assistant",n=$P(t.info.time?.created),r=BP(t),i=n&&r?`${n} (${r})`:n||r;return i?`**${e}**
|
|
182
|
-
|
|
183
|
-
*${i}*`:`**${e}**`}function VP(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function hg(t){const e=_P(t),n=VP(t.parts).trim();return n?`${e}
|
|
184
|
-
|
|
185
|
-
${n}`:""}function fg(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",i=`${n} Sub-agent: ${t.title}${r}
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
`,a=t.records.map(hg).filter(Boolean).join(`
|
|
190
|
-
|
|
191
|
-
---
|
|
192
|
-
|
|
193
|
-
`),o=[i+a];for(const c of t.children)o.push(fg(c,e+1));return o.join(`
|
|
194
|
-
|
|
195
|
-
---
|
|
196
|
-
|
|
197
|
-
`)}function zP(t,e,n){const r=e?.trim()||"Session",i=new Date().toISOString().split("T")[0],a=`# ${r}
|
|
198
|
-
|
|
199
|
-
*Exported on ${i}*
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
`,o=t.map(hg).filter(Boolean).join(`
|
|
204
|
-
|
|
205
|
-
---
|
|
206
|
-
|
|
207
|
-
`);let c=a+o;if(n&&n.length>0){const d=n.map(p=>fg(p,1)).join(`
|
|
208
|
-
|
|
209
|
-
---
|
|
210
|
-
|
|
211
|
-
`);c+=`
|
|
212
|
-
|
|
213
|
-
---
|
|
214
|
-
|
|
215
|
-
`+d}return c}function UP(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}async function WP(t,e){const n=await Xb(e,t);if(n)return n;if(!pn())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 i=await r.json();if(i.saved!==!0)return null;const a=typeof i.path=="string"?i.path.trim():"";return a.length>0?a:null}catch{return null}}async function KP(t){const e=lr()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Zb(t)?!0:Zo(t)}function HP(){return kd()}function GP(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",i=new Date().toISOString().split("T")[0];return`${r}-${i}.md`}const qP=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const i of t){r.has(i)||(r.add(i),n.push(i));const a=e.get(i);if(a)for(const o of a)r.has(o)||(r.add(o),n.push(o))}return n},ir=ur()((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,i)=>{const a=e(),o=new Set(a.selectedIds);let c=a.scopeKey,d=a.anchorId;r!==null&&a.scopeKey!==null&&r!==a.scopeKey?(o.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const m=i&&i.length>0?[n,...i]:[n];if(o.has(n)){for(const f of m)o.delete(f);d===n&&(d=null)}else{for(const f of m)o.add(f);d=n}o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o,scopeKey:c,anchorId:d})},setRange:(n,r,i,a,o)=>{const c=e();if(i.length===0)return;const d=n&&i.includes(n)?n:i[0],p=i.indexOf(d),m=i.indexOf(r);if(p<0||m<0)return;const[u,f]=p<=m?[p,m]:[m,p],b=i.slice(u,f+1),h=qP(b,o),x=a!==null&&c.scopeKey!==null&&a!==c.scopeKey?new Set:new Set(c.selectedIds);for(const g of h)x.add(g);t({selectedIds:x,scopeKey:a??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 i=new Set(r.selectedIds);for(const a of n)i.delete(a);i.size!==r.selectedIds.size&&(i.size===0?t({selectedIds:i,scopeKey:null,anchorId:null}):t({selectedIds:i}))}})),Gp=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),ga=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(ga(n,e))return!0;return!1},ud=(t,e,n,r)=>{if(!e)return!1;if(`${n}:${r?"archived":"active"}:${t.session.id}`===e)return!0;for(const a of t.children)if(ud(a,e,n,r))return!0;return!1},JP=(t,e)=>{const n=t.node.session,r=e.node.session,i=n.id,a=r.id;if(i!==a||t.node.session!==e.node.session||Gp(t.node)!==Gp(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=ga(t.node,t.currentSessionId),u=ga(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(i)!==e.pinnedSessionIds.has(a)||t.expandedParents.has(i)!==e.expandedParents.has(a)||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=ga(t.node,t.editingId),u=ga(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=ga(t.node,t.editingId),u=ga(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===i!=(e.copiedSessionId===a))return!1;const o=ud(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=ud(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(o!==c)return!1;const d=Ns(n.directory??null)??Ns(t.groupDirectory??null),p=Ns(r.directory??null)??Ns(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 QP(t){const{t:e}=mt(),{node:n,depth:r=0,groupDirectory:i,projectId:a,archivedBucket:o=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:f,notifyOnSubtasks:b,editingId:h,setEditingId:v,editTitle:x,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:y,toggleParent:S,handleSessionSelect:D,handleSessionDoubleClick:j,togglePinnedSession:I,handleShareSession:A,copiedSessionId:E,handleCopyShareUrl:P,handleUnshareSession:k,openSidebarMenuKey:N,setOpenSidebarMenuKey:T,renamingFolderId:M,getFoldersForScope:R,getSessionFolderId:L,removeSessionFromFolder:O,addSessionToFolder:V,createFolderAndStartRename:$,openContextPanelTab:B,handleDeleteSession:H,mobileVariant:_,alwaysShowActions:se,renderSessionNode:oe,secondaryMeta:ae,renderContext:ne="project"}=t,xe=!!ae?.projectLabel,te=!!ae?.branchLabel,z=va(ft=>ft.displayMode)==="minimal",Q=l.useMemo(()=>pn(),[]),re=l.useMemo(()=>yd(),[]),K=Q?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",le=Q?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",Se=!o&&!_,ue=z?Q?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":Q?Se?"group-hover:pr-12":"group-hover:pr-5":Se?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",je=Se?"pr-13":"pr-7",W=l.useRef(!1),[me,X]=l.useState(!1),ce=n.session,Pe=jh(ce.id)??ce,Ne=Ns(ce.directory??null)??Ns(i??null),Y=ey(Ne??void 0),he=qh(),ke=ir(ft=>ft.enabled),be=ir(l.useCallback(ft=>ft.selectedIds.has(ce.id),[ce.id])),fe=ir(ft=>ft.toggleSelected),Te=ir(ft=>ft.setRange),Ve=l.useCallback(ft=>{const ds=[],Qt=ks=>{ks.children.forEach(_s=>{ds.push(_s.session.id),Qt(_s)})};return Qt(ft),ds},[]),[G,Ie]=l.useState(!1),[Oe,De]=l.useState(!0),ge=`${ne}:${o?"archived":"active"}:${ce.id}`,U=Jh(l.useCallback(ft=>!!ft.sessionMemoryState.get(ce.id)?.isZombie,[ce.id])),de=ty(ce.id),Ee=sy(ce.id,Ne??void 0),Z=(Ne?c.get(Ne):null)==="missing",ie=d===ce.id,Ce=Pe.title||e("sessions.sidebar.session.untitled"),He=n.children.length>0,Ge=p.has(ce.id),Xe=u?!0:m.has(ce.id),we=!!Pe.parentID,st=ny(ce.id)>0&&(!we||b),qe=Pe.summary,it=kh(qe),lt=Pe.time?.updated||Pe.time?.created||Date.now(),ye=ry(lt),Je=ly(lt),Be=N===ge,ze=l.useMemo(()=>Ve(n).length,[Ve,n]),nt=l.useCallback(async ft=>{const ds=[];let Qt=0;for(const ks of ft)try{await he.ensureSessionRenderable(ks.session.id);const _s=vu(Y.getState(),ks.session.id).list,J=ks.session.title||e("sessions.sidebar.session.export.untitledSubagent"),pt=ks.session.agent,jt=await nt(ks.children);Qt+=jt.skipped,ds.push({title:J,agent:pt,records:_s,children:jt.children})}catch{Qt+=Ve(ks).length+1}return{children:ds,skipped:Qt}},[Ve,Y,he,e]),Ye=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]),Ue=l.useCallback(async ft=>{if(!Ne){q.error(e("sessions.sidebar.session.export.nothingToExport"));return}await he.ensureSessionRenderable(ce.id);const ds=vu(Y.getState(),ce.id).list;if(ds.length===0){q.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Qt,ks=0;if(ft&&n.children.length>0){const jt=await nt(n.children);Qt=jt.children,ks=jt.skipped}const _s=zP(ds,Pe.title??null,Qt),J=GP(Pe.title??null),pt=await WP(_s,J);if(pt){q.success(e("sessions.sidebar.session.export.success"),{action:{label:e(HP()),onClick:()=>{KP(pt).then(jt=>{jt||q.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Ye(ks);return}UP(_s,J),q.success(e("sessions.sidebar.session.export.success")),Ye(ks)},[nt,Y,n.children,Pe.title,ce.id,Ne,Ye,he,e]),vt=l.useCallback(async()=>{if(n.children.length>0){De(!0),Ie(!0);return}await Ue(!1)},[Ue,n.children.length]),Et=l.useCallback(()=>{Ne&&el("desktop_open_session_mini_chat_window",{sessionId:ce.id,directory:Ne}).catch(ft=>{console.warn("[session-sidebar] failed to open mini chat window",ft)})},[ce.id,Ne]);if(h===ce.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(),y();return}(ft.key===" "||ft.key==="Enter")&&ft.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(C,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:y,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(C,{name:"close",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:[He?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Xe?s.jsx(C,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(C,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:ye}),it?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:["+",it.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",it.deletions]})]}):null,xe?s.jsx("span",{className:"truncate",children:ae?.projectLabel}):null,te?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(C,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ae?.branchLabel})]}):null]})})]})},ce.id);const Gt=de?.type??"idle",ts=Gt==="busy"||Gt==="retry",Nt=Ee.length,Zt=ts||!ts&&st&&!ie,ut=ts?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")}),Xt=Zt||Ge?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",Zt&&Ge?"left-[-18px] w-6":"left-[-10px] w-3.5",He&&!se?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[Zt?ut:null,Ge?s.jsx(C,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,as=He?s.jsx("span",{role:"button",tabIndex:0,onClick:ft=>{ft.stopPropagation(),S(ce.id)},onKeyDown:ft=>{(ft.key==="Enter"||ft.key===" ")&&(ft.preventDefault(),ft.stopPropagation(),S(ce.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&&Zt&&!se?"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(Xe?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Xe?s.jsx(C,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(C,{name:"arrow-right-s",className:"h-3 w-3"})}):null,Bt=U?s.jsx(C,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,ls=ft=>{T(ft?ge:null)},gs=ft=>{ft.preventDefault(),ft.stopPropagation(),T(Be?null:ge)},us=ft=>{ft.preventDefault(),ft.stopPropagation()},xs=ft=>{ft.preventDefault(),ft.stopPropagation()},At=ft=>{ft.preventDefault(),ft.stopPropagation()},We=ft=>{ft.preventDefault(),ft.stopPropagation()},Rt=ft=>{ft.preventDefault(),ft.stopPropagation(),T(null),H(ce,{archivedBucket:o})},Dt=ft=>{if(W.current){W.current=!1;return}if(ke){if(ft?.preventDefault(),ft?.stopPropagation(),ft?.shiftKey){const Qt=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(J=>J.getAttribute("data-session-row")).filter(J=>typeof J=="string"&&J.length>0),ks=ir.getState().anchorId,_s=new Map;_s.set(ce.id,Ve(n)),Te(ks,ce.id,Qt,Ne??null,_s);return}fe(ce.id,Ne??null,Ve(n));return}D(ce.id,Ne,Z,a)},wt=ft=>{(ft.button===2||ft.button===0&&ft.ctrlKey&&!ke)&&(W.current=!0)},Jt=ft=>{_&&ft.pointerType==="touch"&&X(!0)},_t=ft=>{_&&ft.pointerType==="touch"&&X(!1)},Fs=s.jsxs($s,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:ft=>{M&&ft.preventDefault()},children:[s.jsxs(zt,{onClick:()=>{v(ce.id),g(Ce)},className:"[&>svg]:mr-1",children:[s.jsx(C,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(zt,{onClick:()=>I(ce.id),className:"[&>svg]:mr-1",children:[Ge?s.jsx(C,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(C,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(Ge?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Pe.share?s.jsxs(s.Fragment,{children:[s.jsx(zt,{onClick:()=>{Pe.share?.url&&P(Pe.share.url,ce.id)},className:"[&>svg]:mr-1",children:E===ce.id?s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(C,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(zt,{onClick:()=>k(ce.id),className:"[&>svg]:mr-1",children:[s.jsx(C,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(zt,{onClick:()=>A(Pe),className:"[&>svg]:mr-1",children:[s.jsx(C,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(zt,{onClick:()=>{vt()},className:"[&>svg]:mr-1",children:[s.jsx(C,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),Ne&&!o?(()=>{const ft=R(Ne),ds=L(Ne,ce.id);return s.jsxs(s.Fragment,{children:[s.jsx(An,{}),s.jsxs(ay,{children:[s.jsxs(iy,{className:"[&>svg]:mr-1",children:[s.jsx(C,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(oy,{className:"min-w-[180px]",children:[ft.length===0?s.jsx(zt,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):ft.map(Qt=>s.jsxs(zt,{onClick:()=>{ds===Qt.id?O(Ne,ce.id):V(Ne,Qt.id,ce.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Qt.name}),ds===Qt.id?s.jsx(C,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Qt.id)),s.jsx(An,{}),s.jsxs(zt,{onClick:()=>{const Qt=$(Ne);Qt&&V(Ne,Qt.id,ce.id)},children:[s.jsx(C,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),ds?s.jsxs(zt,{onClick:()=>{O(Ne,ce.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,Q?null:s.jsxs(zt,{disabled:!Ne,onClick:()=>{Ne&&B(Ne,{mode:"chat",dedupeKey:`session:${ce.id}`,label:Ce})},className:"[&>svg]:mr-1",children:[s.jsx(C,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),re?s.jsxs(zt,{disabled:!Ne,onClick:Et,className:"[&>svg]:mr-1",children:[s.jsx(C,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(An,{}),s.jsxs(zt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>H(ce,{archivedBucket:o}),children:[s.jsx(C,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(l.Fragment,{children:[s.jsx(tP,{sessionId:ce.id,sessionDirectory:Ne??null,sessionTitle:Ce,children:s.jsxs("div",{"data-session-row":ce.id,"data-session-scope":Ne??"","data-session-archived":o?"1":"0",className:pe("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",Z?"opacity-75":"",r>0&&"pl-[20px]",be&&"bg-primary/15"),children:[Xt,as,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:z?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",disabled:Z,onPointerDown:Jt,onPointerUp:_t,onPointerCancel:_t,onMouseDown:wt,onClick:ft=>Dt(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]",me&&"bg-interactive-hover/70",se?Q?ue:je:ue),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:Bi(Ce,f)}),se?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Je}):null,se?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",Be?"opacity-0":le),children:Je})}),Nt>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(C,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Nt})]}):null]})})}),s.jsx(Pt,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:pe("flex items-center gap-3 text-left text-muted-foreground",ae?.projectLabel?"justify-between":"justify-start"),children:[ae?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ae.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:ye})]}),ae?.branchLabel||it?s.jsxs("div",{className:pe("flex items-center gap-3 text-left text-muted-foreground",ae?.branchLabel?"justify-between":"justify-start"),children:[ae?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(C,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ae.branchLabel})]})}):null,it?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",it.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",it.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:Z,onPointerDown:Jt,onPointerUp:_t,onPointerCancel:_t,onMouseDown:wt,onClick:ft=>Dt(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]",me&&"bg-interactive-hover/70",se?Q?ue:je:ue),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:Bi(Ce,f)}),Nt>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(C,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Nt})]}):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}),it?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:["+",it.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",it.deletions]})]}):null,xe?s.jsx("span",{className:"truncate",children:ae?.projectLabel}):null,te?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(C,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ae?.branchLabel})]}):null]})})]})}),Bt&&!_?s.jsx("div",{className:pe("absolute top-1/2 -translate-y-1/2 z-10",z?"right-0":"right-[30px]"),children:Bt}):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",Be||se&&!Q?"opacity-100":pe("opacity-0",K)),children:[Se?s.jsxs(Ct,{children:[s.jsx(It,{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&&!se?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:At,onMouseDown:We,onClick:Rt,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(C,{name:"archive",className:pe(z&&!se?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Pt,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(Bs,{open:Be,onOpenChange:ls,children:[s.jsx(Os,{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&&!se?Be?"h-4 w-4 opacity-100":pe("h-4 w-4 opacity-0",K):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:us,onMouseDown:xs,onClick:gs,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(C,{name:"more-2",className:pe(z&&!se?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),Fs]})]})]})}),He&&Xe?n.children.map(ft=>oe(ft,r+1,Ne??i,a,o,void 0,ne)):null,s.jsx(ws,{open:G,onOpenChange:Ie,children:s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Ss,{children:[s.jsx(js,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Rs,{children:ze===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:ze}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:ze})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Oe,onChange:ft=>De(ft.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Gs,{children:[s.jsx(ve,{type:"button",onClick:()=>Ie(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{type:"button",onClick:()=>{Ie(!1),Ue(Oe)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})})]},ce.id)}const YP=l.memo(QP,JP);function XP(t){const e=rt.c(71),{t:n}=mt(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:o,onConfirm:c}=t;let d,p,m,u,f,b,h,v,x,g;if(e[0]!==i||e[1]!==n||e[2]!==r){const $=n("sessions.sidebar.session.untitled");u=ws,x=!!r,e[13]!==i?(g=H=>{H||i(null)},e[13]=i,e[14]=g):g=e[14],m=vs,h=!1,v="max-w-sm gap-5",p=Ss;let B;e[15]!==n||e[16]!==r?.archivedBucket?(B=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=B):B=e[17],e[18]!==B?(b=s.jsx(js,{children:B}),e[18]=B,e[19]=b):b=e[19],d=Rs,f=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||$}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||$}),e[0]=i,e[1]=n,e[2]=r,e[3]=d,e[4]=p,e[5]=m,e[6]=u,e[7]=f,e[8]=b,e[9]=h,e[10]=v,e[11]=x,e[12]=g}else d=e[3],p=e[4],m=e[5],u=e[6],f=e[7],b=e[8],h=e[9],v=e[10],x=e[11],g=e[12];let w;e[20]!==d||e[21]!==f?(w=s.jsx(d,{children:f}),e[20]=d,e[21]=f,e[22]=w):w=e[22];let y;e[23]!==p||e[24]!==b||e[25]!==w?(y=s.jsxs(p,{children:[b,w]}),e[23]=p,e[24]=b,e[25]=w,e[26]=y):y=e[26];let S;e[27]!==o||e[28]!==a?(S=()=>o(!a),e[27]=o,e[28]=a,e[29]=S):S=e[29];const D=!a;let j;e[30]!==a?(j=a?s.jsx(C,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(C,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=a,e[31]=j):j=e[31];let I;e[32]!==n?(I=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=I):I=e[33];let A;e[34]!==j||e[35]!==I||e[36]!==S||e[37]!==D?(A=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":D,children:[j,I]}),e[34]=j,e[35]=I,e[36]=S,e[37]=D,e[38]=A):A=e[38];let E;e[39]!==i?(E=()=>i(null),e[39]=i,e[40]=E):E=e[40];let P;e[41]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=P):P=e[42];let k;e[43]!==E||e[44]!==P?(k=s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:P}),e[43]=E,e[44]=P,e[45]=k):k=e[45];let N;e[46]!==c?(N=()=>{c()},e[46]=c,e[47]=N):N=e[47];let T;e[48]!==n||e[49]!==r?.archivedBucket?(T=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=T):T=e[50];let M;e[51]!==N||e[52]!==T?(M=s.jsx("button",{type:"button",onClick:N,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:T}),e[51]=N,e[52]=T,e[53]=M):M=e[53];let R;e[54]!==k||e[55]!==M?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[k,M]}),e[54]=k,e[55]=M,e[56]=R):R=e[56];let L;e[57]!==A||e[58]!==R?(L=s.jsxs(Gs,{className:"w-full sm:items-center sm:justify-between",children:[A,R]}),e[57]=A,e[58]=R,e[59]=L):L=e[59];let O;e[60]!==m||e[61]!==h||e[62]!==L||e[63]!==v||e[64]!==y?(O=s.jsxs(m,{showCloseButton:h,className:v,children:[y,L]}),e[60]=m,e[61]=h,e[62]=L,e[63]=v,e[64]=y,e[65]=O):O=e[65];let V;return e[66]!==u||e[67]!==O||e[68]!==x||e[69]!==g?(V=s.jsx(u,{open:x,onOpenChange:g,children:O}),e[66]=u,e[67]=O,e[68]=x,e[69]=g,e[70]=V):V=e[70],V}function ZP(t){const e=rt.c(57),{t:n}=mt(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:o,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let f;e[4]!==d||e[5]!==p||e[6]!==n?(f=d?p===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:p}):p===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:p}),e[4]=d,e[5]=p,e[6]=n,e[7]=f):f=e[7];const b=f,h=!!r;let v;e[8]!==i?(v=V=>{V||i(null)},e[8]=i,e[9]=v):v=e[9];let x;e[10]!==u?(x=s.jsx(js,{children:u}),e[10]=u,e[11]=x):x=e[11];let g;e[12]!==b?(g=s.jsx(Rs,{children:b}),e[12]=b,e[13]=g):g=e[13];let w;e[14]!==x||e[15]!==g?(w=s.jsxs(Ss,{children:[x,g]}),e[14]=x,e[15]=g,e[16]=w):w=e[16];let y;e[17]!==o||e[18]!==a?(y=()=>o(!a),e[17]=o,e[18]=a,e[19]=y):y=e[19];const S=!a;let D;e[20]!==a?(D=a?s.jsx(C,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(C,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=a,e[21]=D):D=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let I;e[24]!==j||e[25]!==y||e[26]!==S||e[27]!==D?(I=s.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":S,children:[D,j]}),e[24]=j,e[25]=y,e[26]=S,e[27]=D,e[28]=I):I=e[28];let A;e[29]!==i?(A=()=>i(null),e[29]=i,e[30]=A):A=e[30];let E;e[31]!==n?(E=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=E):E=e[32];let P;e[33]!==A||e[34]!==E?(P=s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:E}),e[33]=A,e[34]=E,e[35]=P):P=e[35];let k;e[36]!==c?(k=()=>{c()},e[36]=c,e[37]=k):k=e[37];let N;e[38]!==d||e[39]!==n?(N=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=N):N=e[40];let T;e[41]!==k||e[42]!==N?(T=s.jsx("button",{type:"button",onClick:k,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]=k,e[42]=N,e[43]=T):T=e[43];let M;e[44]!==P||e[45]!==T?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[P,T]}),e[44]=P,e[45]=T,e[46]=M):M=e[46];let R;e[47]!==I||e[48]!==M?(R=s.jsxs(Gs,{className:"w-full sm:items-center sm:justify-between",children:[I,M]}),e[47]=I,e[48]=M,e[49]=R):R=e[49];let L;e[50]!==R||e[51]!==w?(L=s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,R]}),e[50]=R,e[51]=w,e[52]=L):L=e[52];let O;return e[53]!==h||e[54]!==L||e[55]!==v?(O=s.jsx(ws,{open:h,onOpenChange:v,children:L}),e[53]=h,e[54]=L,e[55]=v,e[56]=O):O=e[56],O}function eA(t){const e=rt.c(36),{t:n}=mt(),{value:r,setValue:i,onConfirm:a}=t,o=!!r;let c;e[0]!==i?(c=D=>{D||i(null)},e[0]=i,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(js,{children:d}),e[4]=d,e[5]=p):p=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let u;e[9]!==m?(u=s.jsx(Rs,{children:m}),e[9]=m,e[10]=u):u=e[10];let f;e[11]!==p||e[12]!==u?(f=s.jsxs(Ss,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=f):f=e[13];let b;e[14]!==i?(b=()=>i(null),e[14]=i,e[15]=b):b=e[15];let h;e[16]!==n?(h=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=h):h=e[17];let v;e[18]!==b||e[19]!==h?(v=s.jsx("button",{type:"button",onClick:b,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:h}),e[18]=b,e[19]=h,e[20]=v):v=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=x):x=e[22];let g;e[23]!==a||e[24]!==x?(g=s.jsx("button",{type:"button",onClick:a,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:x}),e[23]=a,e[24]=x,e[25]=g):g=e[25];let w;e[26]!==g||e[27]!==v?(w=s.jsxs(Gs,{children:[v,g]}),e[26]=g,e[27]=v,e[28]=w):w=e[28];let y;e[29]!==w||e[30]!==f?(y=s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[f,w]}),e[29]=w,e[30]=f,e[31]=y):y=e[31];let S;return e[32]!==o||e[33]!==c||e[34]!==y?(S=s.jsx(ws,{open:o,onOpenChange:c,children:y}),e[32]=o,e[33]=c,e[34]=y,e[35]=S):S=e[35],S}const tA=t=>{const e=rt.c(46),{selectedCount:n,scopeKey:r,scopeFolders:i,archivedBucket:a,onMoveToFolder:o,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:f}=mt(),b=!!r&&!a;let h;e[0]!==a||e[1]!==f?(h=f(a?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=a,e[1]=f,e[2]=h):h=e[2];const v=h;let x;e[3]!==n||e[4]!==f?(x=f("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=f,e[5]=x):x=e[5];let g;e[6]!==x?(g=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:x}),e[6]=x,e[7]=g):g=e[7];let w;e[8]!==b||e[9]!==p||e[10]!==c||e[11]!==o||e[12]!==d||e[13]!==i||e[14]!==f?(w=b?s.jsxs(Bs,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":f("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(C,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:f("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs($s,{align:"end",className:"min-w-[180px]",children:[i.length===0?s.jsx(zt,{disabled:!0,className:"text-muted-foreground",children:f("sessions.sidebar.folders.none")}):i.map(L=>s.jsx(zt,{onClick:()=>o(L.id),children:s.jsx("span",{className:"flex-1 truncate",children:L.name})},L.id)),s.jsx(An,{}),s.jsxs(zt,{onClick:c,children:[s.jsx(C,{name:"add",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs(zt,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(C,{name:"close",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=b,e[9]=p,e[10]=c,e[11]=o,e[12]=d,e[13]=i,e[14]=f,e[15]=w):w=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=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]=y):y=e[16];let S;e[17]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(C,{name:"delete-bin",className:"h-4 w-4"}),e[17]=S):S=e[17];let D;e[18]!==v||e[19]!==m?(D=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:y,"aria-label":v,children:S})}),e[18]=v,e[19]=m,e[20]=D):D=e[20];let j;e[21]!==v?(j=s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:v})}),e[21]=v,e[22]=j):j=e[22];let I;e[23]!==D||e[24]!==j?(I=s.jsxs(Ct,{children:[D,j]}),e[23]=D,e[24]=j,e[25]=I):I=e[25];let A;e[26]!==f?(A=f("sessions.sidebar.header.actions.exitSelection"),e[26]=f,e[27]=A):A=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(C,{name:"close",className:"h-4 w-4"}),e[28]=E):E=e[28];let P;e[29]!==u||e[30]!==A?(P=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":A,children:E})}),e[29]=u,e[30]=A,e[31]=P):P=e[31];let k;e[32]!==f?(k=f("sessions.sidebar.header.actions.exitSelection"),e[32]=f,e[33]=k):k=e[33];let N;e[34]!==k?(N=s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:k})}),e[34]=k,e[35]=N):N=e[35];let T;e[36]!==P||e[37]!==N?(T=s.jsxs(Ct,{children:[P,N]}),e[36]=P,e[37]=N,e[38]=T):T=e[38];let M;e[39]!==T||e[40]!==w||e[41]!==I?(M=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,I,T]}),e[39]=T,e[40]=w,e[41]=I,e[42]=M):M=e[42];let R;return e[43]!==M||e[44]!==g?(R=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[g,M]}),e[43]=M,e[44]=g,e[45]=R):R=e[45],R},gg="oc.sessions.activeNow",sA=2160*60*1e3,xg=t=>!!t.parentID,zd=t=>!!t.time?.archived,md=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},nA=t=>{try{const e=t.getItem(gg);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,i=[];return n.forEach(a=>{const o=typeof a=="string"?a:a&&typeof a=="object"&&"sessionId"in a&&typeof a.sessionId=="string"?a.sessionId:null;!o||r.has(o)||(r.add(o),i.push({sessionId:o}))}),i}catch{return[]}},qp=(t,e)=>{try{t.setItem(gg,JSON.stringify(e))}catch{}},rA=(t,e,n=Date.now())=>{const r=n-sA;return t.filter(i=>{const a=e.get(i.sessionId);return a?zd(a)?!1:md(a)>=r:!0})},aA=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],bg=t=>[...t].sort((e,n)=>md(n)-md(e)),iA=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!zd(r)).filter(r=>!xg(r));return bg(n)},oA=(t,e)=>{const n=t.filter(r=>{if(zd(r)||xg(r))return!1;const i=e[r.id];return i?.type==="busy"||i?.type==="retry"});return bg(n)},To="oc.sessions.projectCollapse",Jp="oc.sessions.groupOrder",Qp="oc.sessions.groupCollapse",Yp="oc.sessions.activeSessionByProject",Ic="oc.sessions.expandedParents",Xp="oc.sessions.pinned",lA=(t,e)=>{const n=new Set;for(const r of t){const i=Ns(r.path)?.toLowerCase();i&&n.add(i)}for(const r of e.values())for(const i of r){const a=Ns(i.path)?.toLowerCase();a&&n.add(a)}return n},cA=(t,e)=>{if(t.time?.archived)return!0;const n=Ns(Oo(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},dA=5*6e4,Zp=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:i=!1})=>{const{t:a}=mt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),m=l.useRef(null),u=l.useRef(null),f=l.useRef(new Set),[b,h]=l.useState(null),[v,x]=l.useState(""),[g,w]=l.useState(null),[y,S]=l.useState(new Set),[D]=l.useState(()=>new Map),j=l.useMemo(()=>Zr(),[]),[I,A]=l.useState(()=>nA(j)),[E,P]=l.useState(new Set),[k,N]=l.useState(new Map),[T,M]=l.useState(new Set),[R,L]=l.useState(!1),[O,V]=l.useState(!1),[$,B]=l.useState(null),[H,_]=l.useState(null),[se,oe]=l.useState(""),[ae,ne]=l.useState(null),[xe,te]=l.useState(null),[F,z]=l.useState(null),[Q,re]=l.useState(()=>{try{const Re=Zr().getItem(Xp);if(!Re)return new Set;const bt=JSON.parse(Re);return new Set(Array.isArray(bt)?bt.filter(dt=>typeof dt=="string"):[])}catch{return new Set}}),[K,le]=l.useState(()=>{try{const Re=Zr().getItem(Qp);if(!Re)return new Set;const bt=JSON.parse(Re);return new Set(Array.isArray(bt)?bt.filter(dt=>typeof dt=="string"):[])}catch{return new Set}}),[Se,ue]=l.useState(()=>{try{const Re=Zr().getItem(Jp);if(!Re)return new Map;const bt=JSON.parse(Re),dt=new Map;return Object.entries(bt).forEach(([Yt,Ts])=>{Array.isArray(Ts)&&dt.set(Yt,Ts.filter(Ae=>typeof Ae=="string"))}),dt}catch{return new Map}}),[je,W]=l.useState(()=>{try{const Re=Zr().getItem(Yp);if(!Re)return new Map;const bt=JSON.parse(Re),dt=new Map;return Object.entries(bt).forEach(([Yt,Ts])=>{typeof Ts=="string"&&Ts.length>0&&dt.set(Yt,Ts)}),dt}catch{return new Map}}),[me,X]=l.useState(new Map),ce=l.useRef(new Map),ee=l.useRef(0),Pe=Ws(Re=>Re.homeDirectory),Ne=Ws(Re=>Re.currentDirectory),Y=Ws(Re=>Re.setDirectory),he=Es(Re=>Re.projects),ke=Es(Re=>Re.activeProjectId),be=Es(Re=>Re.removeProject),fe=Es(Re=>Re.setActiveProjectIdOnly),Te=Es(Re=>Re.updateProjectMeta),Ve=Es(Re=>Re.reorderProjects),G=Me(Re=>Re.setActiveMainTab),Ie=Me(Re=>Re.openContextPanelTab),Oe=Me(Re=>Re.setSettingsDialogOpen),De=Me(Re=>Re.toggleHelpDialog),ge=Me(Re=>Re.setAboutDialogOpen),U=Me(Re=>Re.setSessionSwitcherOpen),de=Me(Re=>Re.setScheduledTasksDialogOpen),Ee=Me(Re=>Re.toggleSidebar),_e=Me(Re=>Re.openMultiRunLauncher),Z=Me(Re=>Re.notifyOnSubtasks),ie=Me(Re=>Re.showDeletionDialog),Ce=Me(Re=>Re.setShowDeletionDialog),He=Nl(d,120),Ge=l.useMemo(()=>He.trim().toLowerCase(),[He]),Xe=Ge.length>0,we=Hn(Re=>Re.collapsedFolderIds),tt=Hn(Re=>Re.foldersMap),st=Hn(Re=>Re.getFoldersForScope),qe=Hn(Re=>Re.createFolder),it=Hn(Re=>Re.renameFolder),lt=Hn(Re=>Re.deleteFolder),ye=Hn(Re=>Re.addSessionToFolder),Je=Hn(Re=>Re.addSessionsToFolder),Be=Hn(Re=>Re.removeSessionFromFolder),ze=Hn(Re=>Re.removeSessionsFromFolders),nt=Hn(Re=>Re.toggleFolderCollapse),Ye=Hn(Re=>Re.cleanupSessions),Ue=Hn(Re=>Re.getSessionFolderId);vI({isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const vt=Vh(),Et=qh(),Gt=Nh(),ts=cy(),Nt=$i(Re=>Re.hasLoaded),St=$i(Re=>Re.activeSessions),Zt=$i(Re=>Re.archivedSessions),ut=Ht(Re=>Re.currentSessionId),Xt=Ht(Re=>!!Re.newSessionDraft?.open),as=Ht(Re=>Re.setCurrentSession),Bt=Ht(Re=>Re.updateSessionTitle),ls=Ht(Re=>Re.shareSession),gs=Ht(Re=>Re.unshareSession),us=Ht(Re=>Re.worktreeMetadata),xs=Ht(Re=>Re.availableWorktreesByProject),At=Ht(Re=>Re.openNewSessionDraft),We=Na(mr(Re=>({checkForUpdates:Re.checkForUpdates,available:Re.available,runtimeType:Re.runtimeType,info:Re.info,downloading:Re.downloading,downloaded:Re.downloaded,progress:Re.progress,error:Re.error,downloadUpdate:Re.downloadUpdate,restartToUpdate:Re.restartToUpdate}))),Rt=l.useMemo(()=>lA(he,xs),[xs,he]),Dt=l.useMemo(()=>{const Re=new Map(Gt.map(Yt=>[Yt.id,Yt])),bt=St.map(Yt=>Re.get(Yt.id)??Yt),dt=new Set(bt.map(Yt=>Yt.id));return Gt.forEach(Yt=>{dt.has(Yt.id)||bt.push(Yt)}),bt.filter(Yt=>cA(Yt,Rt))},[St,Rt,Gt]),wt=l.useMemo(()=>Gt.map(Re=>{const bt=Ns(Re.directory??null)??"";return`${Re.id}:${Re.title??""}:${Re.time?.archived?1:0}:${bt}`}).join("|"),[Gt]),Jt=l.useRef(Gt);l.useEffect(()=>{Jt.current=Gt},[wt,Gt]),l.useEffect(()=>{let Re=!1;const bt=async()=>{const dt=Es.getState().projects;if(dt.length===0)return;const Yt=new Map,Ts=[];await Promise.all(dt.map(async Ae=>{const Qe=Ns(Ae.path);if(Qe)try{if(!(on.getState().directories.get(Qe)?.isGitRepo??await wr(()=>import("./modelPrefsAutoSave-D5z_F_WP.js").then(qt=>qt.eW),__vite__mapDeps([2,0,1,3,4])).then(qt=>qt.checkIsGitRepository(Qe))))return;const $t=await Oc({id:Ae.id,path:Qe});if(Re||$t.length===0)return;Yt.set(Qe,$t),Ts.push(...$t)}catch{}})),!Re&&Ht.setState({availableWorktrees:Ts,availableWorktreesByProject:Yt})};return $c(Jt.current),bt(),()=>{Re=!0}},[Ne,wt,he]),l.useEffect(()=>{let Re=null;const bt=mg(dt=>{dt.type==="scheduled-task-ran"&&(Re&&clearTimeout(Re),Re=setTimeout(()=>{$c(Jt.current)},500))});return()=>{Re&&clearTimeout(Re),bt()}},[]);const _t=l.useMemo(()=>wn(),[]),Fs=bl(),[ft,ds]=l.useState(!1),Qt=l.useMemo(()=>pn(),[]),{isTablet:ks}=rn(),_s=t||ks,J=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),pt=!t&&!Qt&&!_t,jt=!t&&!Qt&&!pt,Wt=_t&&J&&!ft||Fs?"pl-[5.5rem]":"pl-3",es="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(!_t||!J){ds(!1);return}let Re=!1,bt=null;const dt=async()=>{try{const Ts=await my();Re||ds(Ts)}catch{Re||ds(!1)}},Yt=async()=>{try{bt=py(()=>{dt()})}catch{}};return dt(),Yt(),()=>{Re=!0,bt&&bt()}},[_t,J]);const ns=l.useCallback(async Re=>{const bt=Re.target;bt.closest(".app-region-no-drag")||bt.closest("button, a, input, select, textarea")||Re.button===0&&_t&&await Qh()},[_t]),{buildGroupSearchText:Cs,filterSessionNodesForSearch:Is,buildGroupedSessions:Ke}=yI({homeDirectory:Pe,worktreeMetadata:us,pinnedSessionIds:Q,gitBranches:vt,isVSCode:Qt}),{scheduleCollapsedProjectsPersist:xt}=NI({isVSCode:Qt,hasLoadedGlobalSessions:Nt,safeStorage:j,keys:{sessionExpanded:Ic,projectCollapse:To,sessionPinned:Xp,groupOrder:Jp,projectActiveSession:Yp,groupCollapse:Qp},sessions:Dt,pinnedSessionIds:Q,setPinnedSessionIds:re,groupOrderByProject:Se,activeSessionByProject:je,collapsedGroups:K,setExpandedParents:S,setCollapsedProjects:P}),kt=l.useCallback(Re=>{re(bt=>{const dt=new Set(bt);return dt.has(Re)?dt.delete(Re):dt.add(Re),dt})},[]),Tt=l.useMemo(()=>[...Dt].sort((Re,bt)=>ri(Re,bt,Q)),[Dt,Q]),ss=l.useMemo(()=>new Map(Tt.map((Re,bt)=>[Re.id,bt])),[Tt]),at=l.useMemo(()=>{const Re=new Map;return Tt.forEach(bt=>{const dt=bt.parentID;if(!dt)return;const Yt=Re.get(dt)??[];Yt.push(bt),Re.set(dt,Yt)}),Re.forEach(bt=>bt.sort((dt,Yt)=>ri(dt,Yt,Q))),Re},[Tt,Q]),Lt=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noSessions.description")})]}),os=l.useMemo(()=>he.find(Re=>Re.id===g)??null,[he,g]),rs=l.useCallback(Re=>{g&&(Te(g,Re),w(null))},[g,Te]),Vt=l.useCallback(()=>{L(!0)},[]),cs=l.useCallback(()=>{const Re=Na.getState();if(Re.available&&Re.info){V(!0);return}We.checkForUpdates().then(()=>{const{available:bt,error:dt}=Na.getState();if(dt){q.error(a("sessions.sidebar.updateCheck.errorTitle"),{description:dt});return}if(!bt){q.success(a("sessions.sidebar.updateCheck.latestVersion"));return}V(!0)})},[a,We]),sn=l.useCallback(()=>{t&&U(!1),Oe(!0)},[t,U,Oe]),Js=We.available&&(We.runtimeType==="desktop"||We.runtimeType==="web"),Us=Ht(Re=>Re.deleteSession),ln=Ht(Re=>Re.deleteSessions),nn=Ht(Re=>Re.archiveSession),cn=Ht(Re=>Re.archiveSessions),{copiedSessionId:un,handleSessionSelect:jn,handleSessionDoubleClick:an,handleSaveEdit:gn,handleCancelEdit:pr,handleShareSession:Fn,handleCopyShareUrl:Dn,handleUnshareSession:Tn,handleDeleteSession:Fe,confirmDeleteSession:Mt}=wI({activeProjectId:ke,currentDirectory:Ne,currentSessionId:ut,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:o,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:fe,setDirectory:Y,setActiveMainTab:G,setSessionSwitcherOpen:U,setCurrentSession:as,updateSessionTitle:Bt,shareSession:ls,unshareSession:gs,deleteSession:Us,deleteSessions:ln,archiveSession:nn,archiveSessions:cn,childrenMap:at,showDeletionDialog:ie,setDeleteSessionConfirm:ne,deleteSessionConfirm:ae,setEditingId:h,setEditTitle:x,editingId:b,editTitle:v}),is=l.useCallback(()=>{if(!xe)return;const{scopeKey:Re,folderId:bt}=xe;te(null),lt(Re,bt)},[xe,lt]),ms=l.useCallback(()=>{vr.requestDirectoryDialog()},[]);l.useEffect(()=>{if(!ut)return;const bt=Dt.find(dt=>dt.id===ut)?.parentID;bt&&S(dt=>{if(dt.has(bt))return dt;const Yt=new Set(dt);Yt.add(bt);try{j.setItem(Ic,JSON.stringify(Array.from(Yt)))}catch{}return Yt})},[ut,Dt,j]);const qs=l.useCallback(Re=>{S(bt=>{const dt=new Set(bt);dt.has(Re)?dt.delete(Re):dt.add(Re);try{j.setItem(Ic,JSON.stringify(Array.from(dt)))}catch{}return dt})},[j]),Vs=l.useCallback((Re,bt)=>{if(!Re)return null;bt&&we.has(bt)&&nt(bt);const dt=qe(Re,a("sessions.sidebar.folder.newFolderName"),bt);return _(dt.id),oe(dt.name),dt},[we,nt,qe,a]),Ds=l.useCallback(Re=>{M(bt=>{const dt=new Set(bt);return dt.has(Re)?dt.delete(Re):dt.add(Re),dt})},[]),Xs=l.useCallback(()=>{ee.current=Date.now()+150,P(()=>{const Re=new Set(he.map(bt=>bt.id));try{j.setItem(To,JSON.stringify(Array.from(Re)))}catch{}return Qt||xt(Re),Re})},[he,Qt,j,xt]),hn=l.useCallback(()=>{ee.current=Date.now()+150,P(()=>{const Re=new Set;try{j.setItem(To,JSON.stringify([]))}catch{}return Qt||xt(Re),Re})},[Qt,j,xt]),tr=l.useCallback(Re=>{ee.current=Date.now()+150,P(bt=>{const dt=new Set(bt);dt.has(Re)?dt.delete(Re):dt.add(Re);try{j.setItem(To,JSON.stringify(Array.from(dt)))}catch{}return Qt||xt(dt),dt})},[Qt,j,xt]),Sn=l.useMemo(()=>he.map(Re=>({...Re,normalizedPath:Ns(Re.path)})).filter(Re=>!!Re.normalizedPath),[he]),Mr=l.useMemo(()=>Sn.map(Re=>Re.normalizedPath),[Sn]),{github:Sr}=_n(),kr=Kn(Re=>Re.status),Zs=Kn(Re=>Re.hasChecked),Yn=dy(Mr),kn=or(Re=>Re.ensureEntry),Xn=or(Re=>Re.setParams),hr=or(Re=>Re.refreshTargets);AI({normalizedProjects:Sn,gitRepoStatus:Yn,setProjectRepoStatus:N,setProjectRootBranches:X});const Er=Ht(Re=>Re.isLoading);$I({isSessionsLoading:Er,sessions:Dt,archivedSessions:Zt,normalizedProjects:Sn,isVSCode:Qt,availableWorktreesByProject:xs,cleanupSessions:Ye});const{getSessionsForProject:fr,getArchivedSessionsForProject:Ln}=EI({isVSCode:Qt,sessions:Dt,archivedSessions:Zt,availableWorktreesByProject:xs});uI({normalizedProjects:Sn,sessions:Dt,archivedSessions:Zt,availableWorktreesByProject:xs,isVSCode:Qt,isSessionsLoading:Er,foldersMap:tt,createFolder:qe,addSessionToFolder:ye,cleanupSessions:Ye});const fn=l.useRef(!1);ke&&k.has(ke)&&(fn.current=!!k.get(ke));const{projectSections:en,groupSearchDataByGroup:gr,sectionsForRender:Rr,searchMatchCount:Ra}=hI({normalizedProjects:Sn,getSessionsForProject:fr,getArchivedSessionsForProject:Ln,availableWorktreesByProject:xs,projectRepoStatus:k,projectRootBranches:me,lastRepoStatus:fn.current,buildGroupedSessions:Ke,hasSessionSearchQuery:Xe,normalizedSessionSearchQuery:Ge,filterSessionNodesForSearch:Is,buildGroupSearchText:Cs,foldersMap:tt}),Hr=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noMatches.description")})]}),Fa=!0,{currentSessionDirectory:Nn}=gI({projectSections:en,activeProjectId:ke,activeSessionByProject:je,setActiveSessionByProject:W,currentSessionId:ut,handleSessionSelect:jn,newSessionDraftOpen:Xt,mobileVariant:t,openNewSessionDraft:At,setActiveMainTab:G,setSessionSwitcherOpen:U,sessions:Dt,worktreeMetadata:us}),{getOrderedGroups:La}=xI(Se),Oa=l.useRef(!1);l.useEffect(()=>{if(Oa.current||en.length===0)return;const Re=en.flatMap(bt=>bt.groups.filter(dt=>dt.isArchivedBucket).map(dt=>`${bt.project.id}:${dt.id}`));Re.length>0&&le(bt=>new Set([...bt,...Re])),Oa.current=!0},[en]);const $a=l.useMemo(()=>{const Re=new Map,bt=new Map;return en.forEach(dt=>{const Yt=Gh(dt.project.label?.trim()||Pa(dt.project.normalizedPath,Pe)||dt.project.normalizedPath);dt.groups.forEach(Ts=>{const Ae=Ts.branch&&Ts.branch!==Yt?{projectLabel:Yt,branchLabel:Ts.branch}:{projectLabel:Yt,branchLabel:null},Qe=ht=>{ht.forEach(gt=>{const $t=dt.project.normalizedPath.length,qt=bt.get(gt.session.id)??-1;$t<qt||(Re.set(gt.session.id,{node:gt,projectId:dt.project.id,groupDirectory:Ts.directory,secondaryMeta:Ae}),bt.set(gt.session.id,$t),gt.children.length>0&&Qe(gt.children))})};Qe(Ts.sessions)})}),Re},[en,Pe]),Vn=va(Re=>Re.showRecentSection),Le=l.useMemo(()=>Vn?iA(I,new Map(Dt.map(Re=>[Re.id,Re]))).sort((Re,bt)=>ri(Re,bt,Q)):[],[I,Q,Dt,Vn]),Ze=l.useMemo(()=>Vn?oA(Dt,ts):[],[ts,Dt,Vn]);l.useEffect(()=>{!Vn||Ze.length===0||A(Re=>{const bt=Ze.reduce((dt,Yt)=>aA(dt,Yt.id),Re);return bt===Re?Re:(qp(j,bt),bt)})},[Ze,j,Vn]),l.useEffect(()=>{if(!Vn)return;const Re=new Map;[...Dt,...Zt].forEach(dt=>{Re.set(dt.id,dt)});const bt=rA(I,Re);bt.length===I.length&&bt.every((dt,Yt)=>dt.sessionId===I[Yt]?.sessionId)||(A(bt),qp(j,bt))},[I,Zt,j,Dt,Vn]);const et=l.useMemo(()=>{if(!Vn)return[];const Re=bt=>{const dt=$a.get(bt.id),Yt=Ns(bt.directory??null);return{node:dt?.node??{session:bt,children:[],worktree:null},projectId:dt?.projectId??null,groupDirectory:dt?.groupDirectory??Yt,secondaryMeta:dt?.secondaryMeta??null}};return[{key:"active-now",title:a("sessions.sidebar.activity.recentTitle"),items:Le.map(Re)}]},[Le,$a,Vn,a]),ct=l.useMemo(()=>new Set(Le.map(Re=>Re.id)),[Le]),Ot=l.useMemo(()=>[...ct],[ct]);A4({currentSessionId:ut,sortedSessions:Tt,recentSessionIds:Ot,ensureSessionRenderable:Et.ensureSessionRenderable});const Kt=l.useMemo(()=>{if(!Qt||Xe||ct.size===0)return Rr;const Re=bt=>bt.reduce((dt,Yt)=>{if(ct.has(Yt.session.id))return dt;const Ts=Re(Yt.children);return Ts.length===Yt.children.length?(dt.push(Yt),dt):(dt.push({...Yt,children:Ts}),dt)},[]);return Rr.map(bt=>({...bt,groups:bt.groups.map(dt=>({...dt,sessions:Re(dt.sessions)}))}))},[Qt,Xe,ct,Rr]),zs=l.useMemo(()=>{const Re=new Set;return Kt.forEach(bt=>{bt.groups.forEach(dt=>{const Yt=Ns(dt.directory??null),Ts=dt.branch?.trim()||vt.get(Yt||"")?.trim();!Yt||!Ts||Re.add(Vi(Yt,Ts))})}),[...Re]},[vt,Kt]),mn=gj(zs);l.useEffect(()=>{if(!Zs||!kr?.connected||!Sr)return;const Re=[],bt=Date.now();if(Kt.forEach(Yt=>{E.has(Yt.project.id)||Yt.groups.forEach(Ts=>{const Ae=Ns(Ts.directory??null),Qe=Ts.branch?.trim()||vt.get(Ae||"")?.trim();if(!Ae||!Qe)return;const ht=Vi(Ae,Qe),gt=or.getState().entries[ht],$t=!!gt?.status?.pr,qt=`${Ae}::${Qe}`,Ms=Math.max(gt?.lastRefreshAt??0,gt?.lastDiscoveryPollAt??0),Hs=!!(gt?.isInitialStatusResolved&&!$t&&(!f.current.has(qt)||bt-Ms>=dA));(!gt||!gt.isInitialStatusResolved||Hs)&&(Hs&&f.current.add(qt),Re.push({directory:Ae,branch:Qe}))})}),Re.length===0)return;const dt=new Map;Re.forEach(Yt=>{const Ts=Vi(Yt.directory,Yt.branch,Yt.remoteName??null);dt.has(Ts)||dt.set(Ts,Yt)}),dt.forEach((Yt,Ts)=>{kn(Ts),Xn(Ts,{directory:Yt.directory,branch:Yt.branch,remoteName:Yt.remoteName??null,canShow:!0,github:Sr,githubAuthChecked:Zs,githubConnected:kr.connected})}),hr([...dt.values()],{force:!0,silent:!0,markInitialResolved:!0})},[E,kn,Sr,Zs,kr?.connected,vt,hr,Kt,Xn]);const oo=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",_a="h-4.5 w-4.5",er=zI({isDesktopShellRuntime:_t,projectSections:en,projectHeaderSentinelRefs:ce}),Fr=l.useCallback((Re,bt=0,dt,Yt,Ts=!1,Ae,Qe="project")=>s.jsx(YP,{node:Re,depth:bt,groupDirectory:dt,projectId:Yt,archivedBucket:Ts,directoryStatus:D,currentSessionId:ut,pinnedSessionIds:Q,expandedParents:y,hasSessionSearchQuery:Xe,normalizedSessionSearchQuery:Ge,notifyOnSubtasks:Z,editingId:b,setEditingId:h,editTitle:v,setEditTitle:x,handleSaveEdit:gn,handleCancelEdit:pr,toggleParent:qs,handleSessionSelect:jn,handleSessionDoubleClick:an,togglePinnedSession:kt,handleShareSession:Fn,copiedSessionId:un,handleCopyShareUrl:Dn,handleUnshareSession:Tn,openSidebarMenuKey:$,setOpenSidebarMenuKey:B,renamingFolderId:H,getFoldersForScope:st,getSessionFolderId:Ue,removeSessionFromFolder:Be,addSessionToFolder:ye,createFolderAndStartRename:Vs,openContextPanelTab:Ie,handleDeleteSession:Fe,mobileVariant:t,alwaysShowActions:_s,renderSessionNode:Fr,secondaryMeta:Ae,renderContext:Qe}),[D,ut,Q,y,Xe,Ge,Z,b,h,v,x,gn,pr,qs,jn,an,kt,Fn,un,Dn,Tn,$,B,H,st,Ue,Be,ye,Vs,Ie,Fe,t,_s]),Va=l.useCallback(Re=>{le(bt=>{const dt=new Set(bt);return dt.has(Re)?dt.delete(Re):dt.add(Re),dt})},[]),za=l.useMemo(()=>{const Re=new Map;for(const[bt,dt]of mn)Re.set(bt,{visualState:dt.visualState,number:dt.number,url:dt.url,state:dt.prState,draft:dt.draft,title:dt.title,base:dt.base,head:dt.head,checks:dt.checks,canMerge:dt.canMerge,mergeableState:dt.mergeableState,repo:dt.repo});return Re},[mn]),Kd=l.useCallback((Re,bt,dt,Yt,Ts,Ae)=>s.jsx(rP,{group:Re,groupKey:bt,projectId:dt,hideGroupLabel:Yt,compactBodyPadding:Ae,hasSessionSearchQuery:Xe,normalizedSessionSearchQuery:Ge,groupSearchDataByGroup:gr,expandedSessionGroups:T,collapsedGroups:K,hideDirectoryControls:r,collapsedFolderIds:we,toggleFolderCollapse:nt,renameFolder:it,deleteFolder:lt,showDeletionDialog:ie,setDeleteFolderConfirm:te,renderSessionNode:Fr,currentSessionDirectory:Nn,projectRepoStatus:k,lastRepoStatus:fn.current,toggleGroupSessionLimit:Ds,mobileVariant:t,alwaysShowActions:_s,activeProjectId:ke,setActiveProjectIdOnly:fe,setActiveMainTab:G,setSessionSwitcherOpen:U,openNewSessionDraft:At,addSessionToFolder:ye,createFolderAndStartRename:Vs,renamingFolderId:H,renameFolderDraft:se,setRenameFolderDraft:oe,setRenamingFolderId:_,pinnedSessionIds:Q,sessionOrderIndex:ss,prVisualStateByDirectoryBranch:za,onToggleCollapsedGroup:Va,dragHandleProps:Ts}),[Xe,Ge,gr,T,K,r,we,nt,it,lt,ie,Fr,Nn,k,Ds,t,_s,ke,fe,G,U,At,ye,Vs,H,se,Q,ss,za,Va]),vi=Vn&&!Xe?s.jsx(vP,{sections:et,renderSessionNode:Fr}):null,Gr=!!(H||b||g),aa=ir(Re=>Re.enabled),tn=ir(Re=>Re.selectedIds),Ua=ir(Re=>Re.scopeKey),Wa=ir,lo=l.useCallback(()=>{ir.getState().toggleMode()},[]),Dl=l.useCallback(()=>{ir.getState().disable()},[]),ia=l.useMemo(()=>{if(tn.size===0||typeof document>"u")return!1;let Re=!1,bt=!1;for(const dt of tn){const Yt=document.querySelectorAll(`[data-session-row="${CSS.escape(dt)}"]`);for(const Ts of Yt)Ts.getAttribute("data-session-archived")==="1"?bt=!0:Re=!0}return bt&&!Re},[tn]),xn=l.useMemo(()=>{if(Ua)return Ua;if(tn.size===0||typeof document>"u")return null;for(const Re of tn){const dt=document.querySelector(`[data-session-row="${CSS.escape(Re)}"]`)?.getAttribute("data-session-scope");if(dt&&dt.length>0)return dt}return null},[tn,Ua]),Tl=l.useMemo(()=>xn?tt[xn]??[]:[],[tt,xn]),Ml=l.useMemo(()=>{if(!xn||tn.size===0)return!1;const Re=tt[xn]??[];for(const bt of Re)for(const dt of bt.sessionIds)if(tn.has(dt))return!0;return!1},[tt,xn,tn]),co=l.useCallback(Re=>{!xn||tn.size===0||Je(xn,Re,Array.from(tn))},[Je,tn,xn]),qr=l.useCallback(()=>{if(!xn||tn.size===0)return;const Re=Vs(xn);Re&&Je(xn,Re.id,Array.from(tn))},[Je,Vs,tn,xn]),uo=l.useCallback(()=>{!xn||tn.size===0||ze(xn,Array.from(tn))},[ze,tn,xn]),oa=l.useCallback(async()=>{const Re=Array.from(tn);if(Re.length!==0){if(ia){const{deletedIds:bt,failedIds:dt}=await ln(Re);bt.length>0&&q.success(bt.length===1?a("sessions.sidebar.bulkActions.deletedSingle",{count:bt.length}):a("sessions.sidebar.bulkActions.deletedPlural",{count:bt.length})),dt.length>0&&q.error(dt.length===1?a("sessions.sidebar.bulkActions.failedDeleteSingle",{count:dt.length}):a("sessions.sidebar.bulkActions.failedDeletePlural",{count:dt.length}))}else{const{archivedIds:bt,failedIds:dt}=await cn(Re);bt.length>0&&q.success(bt.length===1?a("sessions.sidebar.bulkActions.archivedSingle",{count:bt.length}):a("sessions.sidebar.bulkActions.archivedPlural",{count:bt.length})),dt.length>0&&q.error(dt.length===1?a("sessions.sidebar.bulkActions.failedArchiveSingle",{count:dt.length}):a("sessions.sidebar.bulkActions.failedArchivePlural",{count:dt.length}))}ir.getState().clear()}},[cn,ia,ln,tn,a]),Ka=l.useCallback(()=>{const Re=tn.size;if(Re!==0){if(!ie){oa();return}z({sessionCount:Re,archivedBucket:ia})}},[ia,oa,tn,ie]),El=l.useCallback(async()=>{z(null),await oa()},[oa]);l.useEffect(()=>{if(!aa)return;const Re=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),bt=dt=>{if(Gr)return;const Yt=dt.target;if(Yt&&(Yt.tagName==="INPUT"||Yt.tagName==="TEXTAREA"||Yt.isContentEditable))return;const Ts=Re?dt.metaKey:dt.ctrlKey;if(dt.key==="Escape"){dt.preventDefault(),ir.getState().disable();return}if(Ts&&dt.key==="Backspace"){dt.preventDefault(),Ka();return}if(Ts&&(dt.key==="a"||dt.key==="A")){const Ae=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Ae.length===0)return;dt.preventDefault();const ht=Wa.getState().scopeKey??Ae[0]?.getAttribute("data-session-scope")??null,gt=qt=>ht?qt.getAttribute("data-session-scope")===ht:!0,$t=Ae.filter(gt).map(qt=>qt.getAttribute("data-session-row")).filter(qt=>typeof qt=="string"&&qt.length>0);if($t.length===0)return;Wa.getState().replaceAll($t,ht||null)}};return window.addEventListener("keydown",bt),()=>window.removeEventListener("keydown",bt)},[Ka,Gr,Wa,aa]);const Rl=l.useCallback(()=>{G("chat"),t&&U(!1),At()},[t,At,G,U]),mo=l.useCallback(()=>{G("chat"),t&&U(!1),_e()},[t,_e,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:[jt?s.jsx("div",{onMouseDown:ns,className:pe("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",Wt),children:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ee,className:es,"aria-label":a("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(C,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Pt,{children:s.jsx("p",{children:a("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(hP,{hideDirectoryControls:r,handleOpenDirectoryDialog:ms,handleNewSession:Rl,canOpenMultiRun:he.length>0,openMultiRunLauncher:mo,headerActionIconClass:_a,reserveHeaderActionsSpace:Fa,headerActionButtonClass:oo,isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:Xe,searchMatchCount:Ra,collapseAllProjects:Xs,expandAllProjects:hn,openScheduledTasksDialog:()=>de(!0),selectionModeEnabled:aa,onToggleSelectionMode:lo,showSidebarToggle:pt,onToggleSidebar:Ee,avoidWindowControlsOverlay:Fs}),s.jsx(AP,{topContent:vi,sectionsForRender:Kt,projectSections:en,activeProjectId:ke,showOnlyMainWorkspace:i,hasSessionSearchQuery:Xe,emptyState:Lt,searchEmptyState:Hr,renderGroupSessions:Kd,homeDirectory:Pe,collapsedProjects:E,hideDirectoryControls:r,projectRepoStatus:k,isDesktopShellRuntime:_t,stuckProjectHeaders:er,mobileVariant:t,alwaysShowActions:_s,toggleProject:tr,setActiveProjectIdOnly:fe,setActiveMainTab:G,setSessionSwitcherOpen:U,openNewSessionDraft:At,openNewWorktreeDialog:Vt,openProjectEditDialog:w,removeProject:be,projectHeaderSentinelRefs:ce,reorderProjects:Ve,getOrderedGroups:La,setGroupOrderByProject:ue,openSidebarMenuKey:$,setOpenSidebarMenuKey:B,isInlineEditing:Gr}),aa&&tn.size>0?s.jsx(tA,{selectedCount:tn.size,scopeKey:xn,scopeFolders:Tl,archivedBucket:ia,onMoveToFolder:co,onCreateFolderAndMove:qr,onRemoveFromFolder:uo,canRemoveFromFolder:Ml,onDelete:Ka,onDone:Dl}):null,s.jsx(jP,{onOpenSettings:sn,onOpenShortcuts:De,onOpenAbout:()=>ge(!0),onOpenUpdate:cs,showRuntimeButtons:!Qt,showUpdateButton:Js}),s.jsx(od,{open:O,onOpenChange:V,info:We.info,downloading:We.downloading,downloaded:We.downloaded,progress:We.progress,error:We.error,onDownload:We.downloadUpdate,onRestart:We.restartToUpdate,runtimeType:We.runtimeType}),os?s.jsx(uy,{open:!!os,onOpenChange:Re=>{Re||w(null)},projectId:os.id,projectName:os.label||Pa(os.path,Pe),projectPath:os.path,initialIcon:os.icon,initialColor:os.color,initialIconBackground:os.iconBackground,onSave:rs}):null,s.jsx(R4,{open:R,onOpenChange:L,onWorktreeCreated:(Re,bt)=>{if(G("chat"),t&&U(!1),bt?.sessionId){as(bt.sessionId);return}At({directoryOverride:Re})}}),s.jsx(cI,{}),s.jsx(XP,{value:ae,setValue:ne,showDeletionDialog:ie,setShowDeletionDialog:Ce,onConfirm:Mt}),s.jsx(eA,{value:xe,setValue:te,onConfirm:is}),s.jsx(ZP,{value:F,setValue:z,showDeletionDialog:ie,setShowDeletionDialog:Ce,onConfirm:El})]})},uA=()=>{const t=rt.c(13),[e,n]=$e.useState(!1);let r,i;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(wn())},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),$e.useEffect(r,i);let a;t[2]!==e?(a=async f=>e?await hy(f):{success:!0,path:f},t[2]=e,t[3]=a):a=t[3];const o=a;let c;t[4]!==e?(c=async f=>e?await fy():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async f=>e?await gy():{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},mA=t=>t==="/",gl=t=>t.replace(/\\/g,"/"),Ud=t=>{if(!t||mA(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},oi=t=>t.endsWith("/"),pA=t=>{const e=t.trim();return!e||oi(e)?e:`${e}/`},Wd=t=>t.lastIndexOf("/"),yg=t=>{if(oi(t))return t;const e=Wd(t);return e<0?t:t.slice(0,e+1)},hA=t=>{const e=Wd(t);return t.slice(e+1)},vg=t=>{const e=Ud(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=Wd(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},fA=t=>oi(t)&&vg(t)!==null,gA=(t,e)=>`${yg(t)}${e}/`,qa=t=>{if(!t)return null;const e=Ud(gl(t.trim()));return e?e.toLowerCase():null},eh=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},xA=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,Pc=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},bA=async()=>{try{const t=await fetch("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(t.ok){const e=await t.json();if(typeof e.home=="string"&&e.home.trim().length>0)return gl(e.home.trim())}}catch{}return In.getFilesystemHome().catch(()=>null)},yA=({open:t,onOpenChange:e})=>{const{t:n}=mt(),r=Ws(Z=>Z.homeDirectory),i=Es(Z=>Z.projects),a=Es(Z=>Z.addProject),o=Gn(Z=>Z.profiles),c=Gn(Z=>Z.globalIdentity),d=Gn(Z=>Z.defaultGitIdentityId),p=Gn(Z=>Z.loadProfiles),m=Gn(Z=>Z.loadGlobalIdentity),u=Gn(Z=>Z.loadDefaultGitIdentityId),f=jl(),{isDesktop:b,requestAccess:h,startAccessing:v}=uA(),{isMobile:x}=rn(),g=l.useRef(null),w=l.useRef(null),y=l.useRef(new Map),[S,D]=l.useState(""),[j,I]=l.useState("~/"),[A,E]=l.useState([]),[P,k]=l.useState(!1),[N,T]=l.useState(!1),[M,R]=l.useState(0),[L,O]=l.useState(!1),[V,$]=l.useState(!1),[B,H]=l.useState(0),[_,se]=l.useState(!1),[oe,ae]=l.useState(""),[ne,xe]=l.useState(null),te=S||r,F=l.useMemo(()=>new Set(i.map(Z=>qa(Z.path)).filter(Z=>!!Z)),[i]);l.useEffect(()=>{if(!t)return;I("~/"),E([]),R(0),O(!1),$(!1),se(!1),ae(""),xe(null),requestAnimationFrame(()=>Pc(g.current));let Z=!1;return(async()=>{const Ce=await bA();Z||(D(Ce||r||""),requestAnimationFrame(()=>Pc(g.current)))})(),()=>{Z=!0}},[r,t]),l.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const z=l.useMemo(()=>{const Z=new Map;c&&Z.set(c.id,c);for(const ie of o)Z.set(ie.id,ie);return Array.from(Z.values())},[o,c]);l.useEffect(()=>{if(!t||!_||ne!==null)return;const Z=typeof d=="string"?d.trim():"";if(Z&&z.some(Ce=>Ce.id===Z)){xe(Z);return}const ie=z.find(Ce=>Ce.authType==="ssh"||Ce.sshKey);ie&&xe(ie.id)},[z,d,_,t,ne]);const Q=l.useMemo(()=>z.find(Z=>Z.id===ne)??null,[z,ne]),re=l.useMemo(()=>yg(j),[j]),K=l.useMemo(()=>oi(j)?"":hA(j),[j]),le=l.useMemo(()=>te?eh(re,te):"",[re,te]);l.useEffect(()=>{if(!t||!le){E([]);return}let Z=!1;return k(!0),T(!1),In.listLocalDirectory(le).then(ie=>{if(Z)return;T(!1);const Ce=ie.filter(He=>He.isDirectory).map(He=>({name:He.name,path:gl(He.path)})).sort((He,Ge)=>He.name.localeCompare(Ge.name));E(Ce)}).catch(()=>{Z||(E([]),T(!0))}).finally(()=>{Z||k(!1)}),()=>{Z=!0}},[le,t]);const Se=l.useMemo(()=>{const Z=K.toLowerCase(),ie=f||K.startsWith(".");return A.filter(Ce=>Ce.name.toLowerCase().startsWith(Z)&&(ie||!Ce.name.startsWith(".")))},[K,A,f]),ue=l.useMemo(()=>{const Z=[];fA(j)&&Z.push({type:"up",value:"browse:up",name:"..",path:vg(j)});for(const ie of Se){const Ce=qa(ie.path);Z.push({type:"directory",value:`browse:${ie.path}`,name:ie.name,path:ie.path,disabled:!!(Ce&&F.has(Ce))})}return Z},[F,Se,j]);l.useEffect(()=>{R(0)},[j,ue.length]);const je=l.useMemo(()=>te?Ud(eh(j,te)):"",[te,j]),W=qa(je),me=!!(W&&F.has(W)),X=l.useMemo(()=>K?Se.find(Z=>Z.name===K)??null:null,[K,Se]),ce=!!(je&&!me&&(oi(j)&&N||!oi(j)&&K.trim().length>0&&X===null)),ee=!L&&!V&&!me&&!!je,Pe=ee&&oe.trim().length>0,Ne=ue[M]??null,Y=!!(Ne&&(Ne.type==="up"||Ne.type==="directory"&&!Ne.disabled)),he=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",ke=n(me?"directoryExplorerDialog.actions.alreadyAdded":_?L?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":L?"directoryExplorerDialog.actions.adding":ce?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const Z=w.current;if(!Z)return;const ie=()=>H(Math.ceil(Z.getBoundingClientRect().width));if(ie(),typeof ResizeObserver>"u")return;const Ce=new ResizeObserver(ie);return Ce.observe(Z),()=>Ce.disconnect()},[ke]),l.useLayoutEffect(()=>{const Z=g.current;Z&&(Z.scrollLeft=Z.scrollWidth)},[B,j]),l.useLayoutEffect(()=>{t&&Pc(g.current)},[t]),l.useLayoutEffect(()=>{const Z=ue[M];Z&&y.current.get(Z.value)?.scrollIntoView({block:"nearest"})},[M,ue]);const be=l.useCallback(()=>{e(!1)},[e]),fe=l.useCallback(async Z=>{if(!Z||L)return;const ie=qa(Z);if(ie&&F.has(ie))return;let Ce=Z;O(!0);try{const He=!_&&ce&&qa(Z)===qa(je);if(_){const Xe=oe.trim();if(!Xe){q.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ce=(await In.cloneRepository({remoteUrl:Xe,destinationPath:Z,gitIdentityId:Q?.id??null})).path}else He&&await In.createDirectory(Z,{allowOutsideWorkspace:!0});if(!a(Ce)){q.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}be()}catch(He){q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:He instanceof Error?He.message:n("directoryExplorerDialog.toast.unknownError")})}finally{O(!1)}},[a,F,oe,be,_,L,Q?.id,ce,je,n]),Te=l.useCallback(Z=>{I(pA(Z))},[]),Ve=l.useCallback(Z=>{I(gA(j,Z.name))},[j]),G=l.useCallback(Z=>{if(Z){if(Z.type==="up"){Z.path&&Te(Z.path);return}Z.disabled||Ve(Z)}},[Te,Ve]),Ie=l.useCallback(async()=>{if(!(!b||V)){$(!0);try{const Z=await h(je);if(!Z.success||!Z.path){Z.error&&Z.error!=="Directory selection cancelled"&&q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Z.error});return}const ie=await v(Z.path);if(!ie.success){q.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:ie.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await fe(Z.path)}catch(Z){q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Z instanceof Error?Z.message:n("directoryExplorerDialog.toast.unknownError")})}finally{$(!1)}}},[fe,b,V,h,v,n,je]),Oe=l.useCallback(Z=>{if(Z.key==="ArrowDown"){Z.preventDefault(),R(ie=>Math.min(ue.length-1,ie+1));return}if(Z.key==="ArrowUp"){Z.preventDefault(),R(ie=>Math.max(0,ie-1));return}if(Z.key==="Enter"){if(Z.preventDefault(),xA(Z)){fe(je);return}Y&&G(Ne);return}Z.key==="Backspace"&&j===""&&(Z.preventDefault(),be())},[G,fe,be,Y,Ne,j,ue.length,je]),De=s.jsxs("button",{type:"button",onClick:()=>Lo(!f),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[f?s.jsx(C,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(C,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),ge=s.jsxs("div",{className:"px-2.5 py-1.5",children:[_?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Ut,{value:oe,onChange:Z=>ae(Z.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(bf,{activeProfile:Q,identities:z,onSelect:Z=>xe(Z.id),isApplying:L,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(C,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(Ut,{ref:g,value:j,onChange:Z=>I(gl(Z.target.value)),onKeyDown:Oe,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&&B>0?{paddingRight:`${B+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),x?null:s.jsx(ve,{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:_?!Pe:!ee,onMouseDown:Z=>Z.preventDefault(),onClick:()=>{fe(je)},title:ke,children:ke})]})]}),U=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsx("div",{className:"px-2 pb-1 pt-0.5 typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),P?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):ue.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:ue.map((Z,ie)=>{const Ce=ie===M;return s.jsxs("button",{ref:He=>{He?y.current.set(Z.value,He):y.current.delete(Z.value)},type:"button",disabled:Z.type==="directory"&&Z.disabled,onMouseEnter:()=>R(ie),onMouseDown:He=>He.preventDefault(),onClick:()=>G(Z),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",Ce&&"bg-interactive-selection text-interactive-selection-foreground",!Ce&&"hover:bg-interactive-hover/50",Z.type==="directory"&&Z.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Z.type==="up"?s.jsx(C,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(C,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Z.name})}),Z.type==="directory"&&Z.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]},Z.value)})})]})}),de=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[ge,U]}),Ee=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(C,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(C,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(C,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:he}),s.jsx(C,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),_e=()=>s.jsxs(s.Fragment,{children:[x?null:Ee,s.jsxs("div",{className:pe("flex w-full flex-row justify-end gap-2 sm:w-auto",x&&"justify-stretch"),children:[b?s.jsx(ve,{variant:"ghost",size:"xs",onClick:Ie,disabled:L||V||_,children:n(V?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(ve,{variant:"ghost",size:"xs",onClick:()=>se(Z=>!Z),disabled:L||V,className:pe(x&&"flex-1"),children:n(_?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),x?s.jsx(ve,{size:"xs",onClick:()=>{fe(je)},disabled:_?!Pe:!ee,className:"flex-1",children:ke}):null]})]});return x?s.jsx(Dr,{open:t,onClose:be,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:s.jsx("div",{className:"flex flex-col gap-2",children:_e()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:De}),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:Z=>Z.preventDefault(),children:[s.jsx(Ss,{className:"px-5 pb-2 pt-5",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx(js,{children:n("directoryExplorerDialog.title")}),s.jsx(Rs,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),De]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:de}),s.jsx(Gs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:_e()})]})})},ha=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Ir=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},vA=()=>{const{t}=mt(),[e,n]=l.useState(!1),[r,i]=l.useState(!1),[a,o]=l.useState(null),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(!1),[b,h]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(new Set),y=Ht(ee=>ee.getWorktreeMetadata),S=Ht(ee=>ee.newSessionDraft),D=Ht(ee=>ee.setNewSessionDraftTarget),j=Ht(ee=>ee.setDraftBootstrapPendingDirectory),I=xy,A=vy,E=Ht(ee=>ee.deleteSessions),P=Ht(ee=>ee.archiveSessions),k=Me(ee=>ee.showDeletionDialog),N=Me(ee=>ee.setShowDeletionDialog),T=Ws(ee=>ee.currentDirectory),M=Ws(ee=>ee.homeDirectory),R=Ws(ee=>ee.isHomeReady),L=Es(ee=>ee.projects),O=Es(ee=>ee.activeProjectId),{isMobile:V,isTablet:$,hasTouchInput:B}=rn(),H=V||$||B,_=l.useMemo(()=>{const Pe=(O?L.find(Ne=>Ne.id===O)??null:null)?.path??T;return Ir(Pe)},[O,T,L]),se=l.useCallback(ee=>{const Ne=Ir(ee.projectDirectory)||_;return{id:(L.find(he=>Ir(he.path)===Ne)??null)?.id??`path:${Ne}`,path:Ne}},[_,L]),oe=v&&g.size>0,ae=l.useMemo(()=>{const ee=a?.worktree;return ee&&typeof ee.branch=="string"&&ee.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Pe})=>typeof Pe.branch=="string"&&Pe.branch.trim().length>0)},[a?.worktree,c]),ne=a?.mode==="worktree",xe=ne,te=b||!ne||!ae,F=b||!ne;l.useEffect(()=>{r||!R||L.length>0||(i(!0),n(!0))},[r,R,L.length]);const z=l.useCallback(ee=>{o({sessions:ee.sessions,dateLabel:ee.dateLabel,mode:ee.mode??"session",worktree:ee.worktree??null})},[]),Q=l.useCallback(()=>{o(null),d([]),m(!1),f(!1),h(!1),x(!1),w(new Set)},[]),re=l.useCallback(async ee=>{if(ee.sessions.length===0)return;if(ee.sessions.length===1){const he=ee.sessions[0];await I(he.id)?q.success(t("sessions.sidebar.session.delete.success")):q.error(t("sessions.sidebar.session.delete.error"));return}const Pe=ee.sessions.map(he=>he.id),{deletedIds:Ne,failedIds:Y}=await E(Pe);if(Ne.length>0){const he=Y.length>0?Y.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Y.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Y.length}):ee.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:ee.dateLabel}):void 0;q.success(Ne.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ne.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ne.length}),{description:ha(he)})}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:ha(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[I,E,t]);l.useEffect(()=>vr.onDeleteRequest(ee=>{if(!k&&(ee.mode??"session")==="session"){re(ee);return}z(ee)}),[z,k,re]),l.useEffect(()=>vr.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!a){d([]),m(!1),f(!1),x(!1),w(new Set);return}const ee=a.sessions.map(Y=>{const he=y(Y.id);return he?{session:Y,metadata:he}:null}).filter(Y=>!!Y);d(ee),m(!1),x(!1),w(new Set);const Pe=new Map;if(a.worktree?.path&&Pe.set(Ir(a.worktree.path),a.worktree),ee.forEach(({metadata:Y})=>{Y.path&&Pe.set(Ir(Y.path),Y)}),Pe.size===0){x(!0);return}let Ne=!1;return(async()=>{const Y=new Map,he=new Set;await Promise.all(Array.from(Pe.entries()).map(async([ke,be])=>{try{const fe=await by(be.path);Y.set(ke,fe),fe?.isDirty&&he.add(ke)}catch{be.status&&(Y.set(ke,be.status),be.status.isDirty&&he.add(ke))}})).catch(ke=>{console.warn("Failed to inspect worktree status before deletion:",ke)}),!Ne&&(w(he),x(!0),o(ke=>{if(!ke?.worktree?.path)return ke;const be=Ir(ke.worktree.path),fe=Y.get(be);if(!fe)return ke;const Te=ke.worktree.status;return Te?.isDirty===fe.isDirty&&Te?.ahead===fe.ahead&&Te?.behind===fe.behind&&Te?.upstream===fe.upstream?ke:{...ke,worktree:{...ke.worktree,status:fe}}}),d(ke=>ke.map(be=>{const fe=Ir(be.metadata.path),Te=Y.get(fe);return Te?{session:be.session,metadata:{...be.metadata,status:Te}}:be})))})(),()=>{Ne=!0}},[a,y]),l.useEffect(()=>{ae||m(!1)},[ae]);const K=l.useCallback(async(ee,Pe)=>{const Ne=p&&ae,Y=se(ee),he=Ir(ee.path),ke=Ir(Y.path);try{await yy(Y,ee,{deleteRemoteBranch:Ne,deleteLocalBranch:Pe});const be=Ir(S?.directoryOverride);return S?.open&&he&&be===he&&ke&&(j(null),D({projectId:Y.id,directoryOverride:ke},{force:!0})),Ir(T)===he&&ke&&Ws.getState().setDirectory(ke,{showOverlay:!1}),!0}catch(be){return q.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:ha(be instanceof Error?be.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ae,T,p,se,S?.directoryOverride,S?.open,j,D,t]),le=l.useCallback(async()=>{if(a){h(!0);try{const ee=xe,Pe=ee&&p,Ne=ee&&u;if(a.sessions.length===0&&ne&&a.worktree){if(!await K(a.worktree,Ne)){Q();return}const ke=t(p&&ae?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");q.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:ha(ke)}),Q();return}if(a.sessions.length===1){const Y=a.sessions[0];if(!(ne?await A(Y.id):await I(Y.id,{archiveWorktree:!1,deleteRemoteBranch:Pe,deleteLocalBranch:Ne}))){q.error(t(ne?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),h(!1);return}const ke=!ne&&ee?t(Pe?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;q.success(t(ne?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:ha(ke),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const Y=a.sessions.map(be=>be.id);let he=[],ke=[];if(ne){const be=await P(Y);he=be.archivedIds,ke=be.failedIds}else{const be=await E(Y);he=be.deletedIds,ke=be.failedIds}if(ne&&a.worktree&&ke.length===0&&await K(a.worktree,Ne),he.length>0){const be=!ne&&ee?t(Pe?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Te=[ke.length>0?ne?ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:ke.length}):ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ke.length}):a.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:a.dateLabel}):void 0,be].filter(Boolean).join(" ");q.success(ne?he.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:he.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:he.length}):he.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:he.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:he.length}),{description:ha(Te||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ke.length>0&&(q.error(ne?ke.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:ke.length}):ke.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ke.length}),{description:ha(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),he.length===0)){h(!1);return}}ne&&a.sessions.length===1&&a.worktree&&await K(a.worktree,Ne),Q()}finally{h(!1)}}},[a,p,u,I,E,A,P,Q,xe,ne,ae,K,t]),Se=a?.worktree??c[0]?.metadata??null,ue=a?a.mode==="worktree"?a.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):a.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:a.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:a.sessions.length}):a.sessions.length===1?a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:a.sessions.length,dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:a.sessions.length}):"",je=a?s.jsxs("div",{className:pe(ne?"space-y-3":"space-y-2"),children:[a.sessions.length>0&&s.jsxs("div",{className:pe(ne?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[ne&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:a.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:a.sessions.length})]}),s.jsxs("ul",{className:pe(ne?"mt-2 space-y-1":"space-y-0.5"),children:[a.sessions.slice(0,5).map(ee=>s.jsxs("li",{className:pe(ne?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:pe(!ne&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:ee.title||t("sessions.sidebar.session.untitled")})]},ee.id)),a.sessions.length>5&&s.jsx("li",{className:pe(ne?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:a.sessions.length-5})})]})]}),ne?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(C,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),Se?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:Se.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:Se?Ki(Se.path,M):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),oe&&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,W=ne?ae?s.jsxs("button",{type:"button",onClick:()=>{te||m(ee=>!ee)},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(C,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(C,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,me=ne?s.jsxs("button",{type:"button",onClick:()=>{F||f(ee=>!ee)},disabled:F,className:pe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",F?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(C,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(C,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,X=ne?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[me,W]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:Q,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:le,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(!k),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":!k,children:[k?s.jsx(C,{name:"checkbox-blank",className:"size-4"}):s.jsx(C,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:Q,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:le,disabled:b,children:b?t("sessions.sidebar.sessionDialogs.actions.deleting"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ce=ne?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[H?s.jsx(Dr,{open:!!a,onClose:()=>{b||Q()},title:ce,footer:s.jsx("div",{className:"flex justify-end gap-2",children:X}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[ue&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:ue}),je]})}):s.jsx(ws,{open:!!a,onOpenChange:ee=>{if(!ee){if(b)return;Q()}},children:s.jsxs(vs,{className:pe(ne?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(Ss,{children:[s.jsxs(js,{className:pe(ne&&"flex items-center gap-2"),children:[ne&&s.jsx(C,{name:"delete-bin",className:"h-5 w-5"}),ce]}),ue&&s.jsx(Rs,{children:ue})]}),s.jsx("div",{className:pe(ne&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:je}),s.jsx(Gs,{className:"mt-2 gap-2 pt-1 pb-1",children:X})]})}),s.jsx(yA,{open:e,onOpenChange:n})]})},pd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),wA=(t,e)=>{const n=pd(t),r=pd(e);return`${n}-${r}`.substring(0,60)},th=(t,e)=>`${t}/${e}`,jA=()=>{const t=Es.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(i=>i.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 i=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${i}`,path:i}}return null},Ac=ur()(xi(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:i,agent:a,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(i.length<1)return t({error:"Select at least 1 model"}),null;if(i.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=jA();if(!d)return t({error:"Select a project",isLoading:!1}),null;const p=d.path;if(!await $h(p))return t({error:"Not in a git repository",isLoading:!1}),null;const u=pd(n),f=await eo(p),b=await wy(p),h=[],v=c?.filter(j=>j.trim().length>0)??[],x=new Map;for(const j of i){const I=`${j.providerID}:${j.modelID}`;x.set(I,(x.get(I)||0)+1)}const g=new Map;for(const j of i){const I=`${j.providerID}:${j.modelID}`,A=x.get(I)||1,E=(g.get(I)||0)+1;g.set(I,E);const P=wA(j.providerID,j.modelID),k=A>1?th(u,`${P}/${E}`):th(u,P);try{const N=await jy(d,{preferredName:k,mode:"new",branchName:k,worktreeName:k,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:v},{resolvedRootTrackingRemote:b}),T={...N,createdFromBranch:f,kind:"standard"},M=A>1?`${u}/${j.providerID}/${j.modelID}/${E}`:`${u}/${j.providerID}/${j.modelID}`,R=await In.withDirectory(N.path,()=>In.createSession({title:M}));Ht.getState().setWorktreeMetadata(R.id,T),h.push({sessionId:R.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&&Bh(d,w).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const y=h.map(j=>j.sessionId),S=h[0]?.sessionId??null;if(y.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const D=o?.map(j=>({type:"file",mime:j.mime,filename:j.filename,url:j.url}));return(async()=>{try{await Promise.allSettled(h.map(async j=>{try{await In.withDirectory(j.worktreePath,()=>In.sendMessage({id:j.sessionId,providerID:j.providerID,modelID:j.modelID,variant:j.variant,text:r,agent:a,files:D}))}catch(I){console.warn("[MultiRun] Failed to start run:",I)}}))}catch(j){console.warn("[MultiRun] Failed to start runs:",j)}})(),t({isLoading:!1}),{groupSlug:u,sessionIds:y,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"})),wg="h-7",hd=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,NA=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),SA=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=NA.format(t);return e.endsWith(".0")?e.slice(0,-2):e},kA=t=>{const e=rt.c(12),{model:n,instanceIndex:r,totalSameModel:i,onRemove:a}=t,o=n.displayName||`${n.providerID}/${n.modelID}`,c=i>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",wg),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(Mn,{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(C,{name:"close",className:"h-3.5 w-3.5"}),e[5]=u):u=e[5];let f;e[6]!==a?(f=s.jsx("button",{type:"button",onClick:a,className:"text-muted-foreground hover:text-foreground ml-0.5",children:u}),e[6]=a,e[7]=f):f=e[7];let b;return e[8]!==p||e[9]!==m||e[10]!==f?(b=s.jsxs("div",{className:d,children:[p,m,f]}),e[8]=p,e[9]=m,e[10]=f,e[11]=b):b=e[11],b},CA=({selectedModels:t,onAdd:e,onRemove:n,onUpdate:r,minModels:i,addButtonLabel:a,showChips:o=!0,maxModels:c,addButtonClassName:d})=>{const{t:p}=mt(),m=yt(H=>H.providers),u=yt(H=>H.modelsMetadata),{favoriteModelsList:f,recentModelsList:b}=Ph(),[h,v]=l.useState(!1),[x,g]=l.useState(""),[w,y]=l.useState(0),[S,D]=l.useState(null),j=l.useRef(null),I=l.useRef(null),A=l.useRef(null),E=l.useRef([]),P=c===void 0||t.length<c,k=l.useMemo(()=>{const H=new Map;for(const _ of t){const se=`${_.providerID}:${_.modelID}`;H.set(se,(H.get(se)||0)+1)}return H},[t]),N=l.useCallback(H=>t.filter(se=>se.providerID===H.providerID&&se.modelID===H.modelID).findIndex(se=>se.instanceId===H.instanceId)+1,[t]),T=(H,_)=>{const se=`${H}/${_}`;return u.get(se)},M=H=>{const _=H?.name||H?.id||"",se=String(_);return se.length>40?se.substring(0,37)+"...":se},R=l.useCallback((H,_)=>{if(!x.trim())return!0;const se=x.toLowerCase();return H.toLowerCase().includes(se)||_.toLowerCase().includes(se)},[x]),L=l.useMemo(()=>f.filter(({model:H,providerID:_})=>{const oe=m.find(ne=>ne.id===_)?.name||_,ae=M(H);return R(ae,oe)}),[f,m,R]),O=l.useMemo(()=>b.filter(({model:H,providerID:_})=>{const oe=m.find(ne=>ne.id===_)?.name||_,ae=M(H);return R(ae,oe)}),[b,m,R]),V=l.useMemo(()=>m.map(H=>{const se=(Array.isArray(H.models)?H.models:[]).filter(oe=>{const ae=M(oe);return R(ae,H.name||H.id||"")});return{...H,models:se}}).filter(H=>H.models.length>0),[m,R]),$=L.length>0||O.length>0||V.length>0;l.useEffect(()=>{if(!h||!A.current)return;const H=A.current.getBoundingClientRect();let _=A.current.parentElement;for(;_&&!(_.getAttribute("role")==="dialog"||_.hasAttribute("data-scroll-shadow"));){const ae=getComputedStyle(_);if(ae.overflow==="auto"||ae.overflow==="hidden"||ae.overflowY==="auto"||ae.overflowY==="hidden")break;_=_.parentElement}const se=_?_.getBoundingClientRect().top:0,oe=H.top-se-16;D(Math.max(150,Math.min(300,oe)))},[h]),l.useEffect(()=>{h&&j.current&&j.current.focus()},[h]),l.useEffect(()=>{!P&&h&&(v(!1),g(""),y(0))},[P,h]),l.useEffect(()=>{if(!h)return;const H=_=>{I.current&&!I.current.contains(_.target)&&(v(!1),g(""),y(0))};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[h]),l.useEffect(()=>{y(0)},[x]);const B=(H,_,se,oe,ae,ne)=>{const xe=`${_}:${se}`,te=k.get(xe)||0,F=T(_,se),z=SA(F?.limit?.context),Q=oe==="fav"||oe==="recent";return s.jsxs("button",{ref:re=>{E.current[ae]=re},type:"button",disabled:!P,onClick:()=>{e({providerID:_,modelID:se,displayName:H.name||se,instanceId:hd()})},onMouseEnter:()=>y(ae),className:pe("w-full text-left px-2 py-1.5 rounded-md typography-meta transition-colors flex items-center gap-2",P&&(ne?"bg-interactive-selection":"hover:bg-interactive-hover/50"),!P&&"cursor-not-allowed opacity-60"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[Q&&s.jsx(Mn,{providerId:_,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:M(H)}),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]})]},`${oe}-${xe}`)};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:I,children:[s.jsxs(ve,{ref:A,type:"button",variant:"outline",size:"sm",className:pe(wg,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",d),disabled:!P,onClick:()=>{v(!h)},children:[s.jsx(C,{name:"add",className:"h-3.5 w-3.5 mr-1"}),a??p("multirun.modelMultiSelect.actions.addModel")]}),h&&(()=>{const H=[];L.forEach(({model:ae,providerID:ne,modelID:xe})=>{H.push({model:ae,providerID:ne,modelID:xe,section:"fav"})}),O.forEach(({model:ae,providerID:ne,modelID:xe})=>{H.push({model:ae,providerID:ne,modelID:xe,section:"recent"})}),V.forEach(ae=>{ae.models.forEach(ne=>{H.push({model:ne,providerID:ae.id,modelID:ne.id,section:"provider"})})});const _=H.length,se=ae=>{if(!Ny(ae))if(ae.key==="ArrowDown"){ae.preventDefault(),ae.stopPropagation();const ne=(w+1)%Math.max(1,_);y(ne),setTimeout(()=>{E.current[ne]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(ae.key==="ArrowUp"){ae.preventDefault(),ae.stopPropagation();const ne=(w-1+Math.max(1,_))%Math.max(1,_);y(ne),setTimeout(()=>{E.current[ne]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(ae.key==="Enter"){ae.preventDefault(),ae.stopPropagation();const ne=H[w];ne&&P&&e({providerID:ne.providerID,modelID:ne.modelID,displayName:ne.model.name||ne.modelID,instanceId:hd()})}else ae.key==="Escape"&&(ae.preventDefault(),ae.stopPropagation(),v(!1),g(""),y(0))};let oe=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(C,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Ut,{ref:j,type:"text",placeholder:p("multirun.modelMultiSelect.search.placeholder"),value:x,onChange:ae=>g(ae.target.value),onKeyDown:se,className:"h-8 pl-8 typography-meta"})]})}),s.jsx(As,{outerClassName:"flex-1",style:{maxHeight:S?`${S}px`:"300px"},children:s.jsxs("div",{className:"p-1",children:[!$&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:p("multirun.modelMultiSelect.search.noResults")}),L.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(C,{name:"star-fill",className:"h-4 w-4 text-primary"}),p("multirun.modelMultiSelect.sections.favorites")]}),L.map(({model:ae,providerID:ne,modelID:xe})=>{const te=oe++;return B(ae,ne,xe,"fav",te,w===te)})]}),O.length>0&&s.jsxs(s.Fragment,{children:[L.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(C,{name:"time",className:"h-4 w-4"}),p("multirun.modelMultiSelect.sections.recent")]}),O.map(({model:ae,providerID:ne,modelID:xe})=>{const te=oe++;return B(ae,ne,xe,"recent",te,w===te)})]}),(L.length>0||O.length>0)&&V.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),V.map((ae,ne)=>s.jsxs(l.Fragment,{children:[ne>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(Mn,{providerId:ae.id,className:"h-4 w-4 flex-shrink-0"}),ae.name]}),ae.models.map(xe=>{const te=oe++;return B(xe,ae.id,xe.id,"provider",te,w===te)})]},ae.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((H,_)=>{const se=`${H.providerID}:${H.modelID}`,oe=k.get(se)||1,ae=N(H),xe=m.find(re=>re.id===H.providerID)?.models.find(re=>re.id===H.modelID),te=xe?.variants?Object.keys(xe.variants):[],F=te.length>0,z="__default__",Q=H.variant??z;return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(kA,{model:H,instanceIndex:ae,totalSameModel:oe,onRemove:()=>n(_)}),F&&s.jsxs(ps,{value:Q,onValueChange:re=>{if(!r)return;r(_,{...H,variant:re===z?void 0:re})},children:[s.jsxs(hs,{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(C,{name:"brain-ai-3",className:pe("h-3.5 w-3.5 flex-shrink-0",Q===z?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(ys,{placeholder:p("multirun.modelMultiSelect.variant.placeholder")})]}),s.jsxs(fs,{fitContent:!0,children:[s.jsx(Ft,{value:z,className:"pr-2 [&>span:first-child]:hidden",children:p("multirun.modelMultiSelect.variant.default")}),te.map(re=>s.jsx(Ft,{value:re,className:"pr-2 [&>span:first-child]:hidden",children:re},re))]})]})]},H.instanceId)})})]}),i!==void 0&&t.length<i&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:c!==void 0?p("multirun.modelMultiSelect.validation.minToMax",{min:i,max:c}):p("multirun.modelMultiSelect.validation.minOnly",{min:i})})]})},IA="oc:lastWorktreeSourceBranch";function jg(t){const e=rt.c(21),{git:n}=_n(),r=jd(t),i=Wh(t),a=on(TA);let o;e[0]!==r?.all||e[1]!==t||e[2]!==a||e[3]!==n?(o=()=>{!t||!n||r?.all||a(t,n)},e[0]=r?.all,e[1]=t,e[2]=a,e[3]=n,e[4]=o):o=e[4];const c=r?.all;let d;e[5]!==t||e[6]!==a||e[7]!==n||e[8]!==c?(d=[t,n,c,a],e[5]=t,e[6]=a,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(DA).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(AA).map(PA).sort(),e[14]=r.all,e[15]=x):x=e[15],u=x}const f=u;let b;e:{if(!t){b=null;break e}if(i){b=null;break e}if(!r){b=null;break e}b=!!r.all}const h=b;let v;return e[16]!==h||e[17]!==i||e[18]!==m||e[19]!==f?(v={localBranches:m,remoteBranches:f,isLoading:i,isGitRepository:h},e[16]=h,e[17]=i,e[18]=m,e[19]=f,e[20]=v):v=e[20],v}function PA(t){return t.replace(/^remotes\//,"")}function AA(t){return t.startsWith("remotes/")}function DA(t){return!t.startsWith("remotes/")}function TA(t){return t.fetchBranches}const MA=({directory:t,value:e,onChange:n,className:r,disabled:i,id:a})=>{const{t:o}=mt(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=jg(t),u=l.useMemo(()=>[...c,...d.map(b=>`remotes/${b}`)],[c,d]);l.useEffect(()=>{if(i||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const h=t?await eo(t).catch(()=>null):null,v=localStorage.getItem(IA);v&&u.includes(v)?n(v):h&&u.includes(h)?n(h):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,i,p,n,e]);const f=i||!m||p;return s.jsxs("div",{children:[s.jsxs(ps,{value:e,onValueChange:n,disabled:f,children:[s.jsx(hs,{id:a,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(fs,{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(Bc,{children:[s.jsx(wu,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.localBranches")}),c.map(b=>s.jsx(Ft,{value:b,className:"whitespace-normal break-all",children:b},b))]}),c.length>0&&d.length>0&&s.jsx(Sy,{}),d.length>0&&s.jsxs(Bc,{children:[s.jsx(wu,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(Ft,{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")})]})},EA=t=>{const e=rt.c(34),{value:n,onChange:r,className:i,disabled:a,id:o}=t,{t:c}=mt(),d=yt(RA),p=yt(FA),m=yt(LA);let u;e[0]!==d?(u=d(),e[0]=d,e[1]=u):u=e[1];const f=u;let b;e[2]!==f?(b=f.filter(OA),e[2]=f,e[3]=b):b=e[3];const h=b;let v,x;e[4]!==p?(v=()=>{p()},x=[p],e[4]=p,e[5]=v,e[6]=x):(v=e[5],x=e[6]),l.useEffect(v,x);let g,w;e[7]!==m||e[8]!==a||e[9]!==r||e[10]!==h||e[11]!==n?(g=()=>{if(a)return;const k=n.trim();if(k.length>0&&h.some(M=>M.name===k))return;const N=typeof m=="string"&&m.trim().length>0?m.trim():null;if(N&&h.some(M=>M.name===N)){r(N);return}const T=h[0]?.name;T&&r(T)},w=[m,a,r,h,n],e[7]=m,e[8]=a,e[9]=r,e[10]=h,e[11]=n,e[12]=g,e[13]=w):(g=e[12],w=e[13]),l.useEffect(g,w);const y=n.trim().length>0?n:void 0;let S;e[14]!==i?(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",i),e[14]=i,e[15]=S):S=e[15];let D;e[16]!==c?(D=c("multirun.agentSelector.placeholder"),e[16]=c,e[17]=D):D=e[17];let j;e[18]!==D?(j=s.jsx(ys,{placeholder:D}),e[18]=D,e[19]=j):j=e[19];let I;e[20]!==o||e[21]!==S||e[22]!==j?(I=s.jsx(hs,{id:o,size:"lg",className:S,children:j}),e[20]=o,e[21]=S,e[22]=j,e[23]=I):I=e[23];let A;e[24]!==h?(A=h.length>0&&s.jsx(Bc,{children:h.map($A)}),e[24]=h,e[25]=A):A=e[25];let E;e[26]!==A?(E=s.jsx(fs,{fitContent:!0,children:A}),e[26]=A,e[27]=E):E=e[27];let P;return e[28]!==a||e[29]!==r||e[30]!==y||e[31]!==I||e[32]!==E?(P=s.jsxs(ps,{value:y,onValueChange:r,disabled:a,children:[I,E]}),e[28]=a,e[29]=r,e[30]=y,e[31]=I,e[32]=E,e[33]=P):P=e[33],P};function RA(t){return t.getVisibleAgents}function FA(t){return t.loadAgents}function LA(t){return t.currentAgentName}function OA(t){return t.mode!=="subagent"}function $A(t){return s.jsx(Ft,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const BA=10*1024*1024,Dc=5,Mo=t=>{const e=rt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(C,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let i;return e[1]!==n?(i=s.jsxs(Ct,{children:[r,s.jsx(Pt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=i):i=e[2],i},Ja=t=>{const e=rt.c(9),{htmlFor:n,required:r,children:i,info:a}=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]!==i||e[3]!==n||e[4]!==o?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,o]}),e[2]=i,e[3]=n,e[4]=o,e[5]=c):c=e[5];const d=a&&a;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},_A=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:i}=mt(),[a,o]=l.useState(""),[c,d]=l.useState(()=>t??""),[p,m]=l.useState([]),[u,f]=l.useState(""),[b,h]=l.useState([]),[v,x]=l.useState(!1),[g,w]=l.useState([]),[y,S]=l.useState(!1),[D,j]=l.useState(!1),[I,A]=l.useState(!1),[E,P]=l.useState(""),[k,N]=l.useState(!1),[T,M]=l.useState(""),R=l.useRef(null),L=l.useRef(null),O=l.useRef(null),V=l.useRef(null),$=Ws(Z=>Z.currentDirectory??null),B=Ws(Z=>Z.homeDirectory??null),H=l.useMemo(()=>{if(typeof window>"u")return null;const Z=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Z=="string"&&Z.trim().length>0?Z.trim():null},[]),_=Es(Z=>Z.activeProjectId),se=Es(Z=>Z.setActiveProjectIdOnly),oe=Es(Z=>Z.projects),[ae,ne]=l.useState(()=>_??null);l.useEffect(()=>{if(_){ne(_);return}!ae&&oe.length>0&&ne(oe[0].id)},[_,oe,ae]);const xe=l.useMemo(()=>ae?oe.find(Z=>Z.id===ae)??null:null,[oe,ae]),te=xe?.path??$,F=l.useCallback(Z=>{ne(Z),Z!==_&&se(Z)},[_,se]),{currentTheme:z}=Nr(),Q=l.useCallback(Z=>{const ie=Z.label?.trim()||Pa(Z.path,B),Ce=no({id:Z.id,iconImage:Z.iconImage??null},{themeVariant:z.metadata.variant,iconColor:z.colors.surface.foreground}),He=Z.icon?kl[Z.icon]:null,Ge=Z.color?ro[Z.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[Ce?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Z.iconBackground?{backgroundColor:Z.iconBackground}:void 0,children:s.jsx("img",{src:Ce,alt:"",className:"h-full w-full object-contain",draggable:!1})}):He?s.jsx(C,{name:He,className:"h-3.5 w-3.5 shrink-0",style:Ge?{color:Ge}:void 0}):s.jsx(C,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Ge?{color:Ge}:void 0}),s.jsx("span",{className:"truncate",children:ie})]})},[B,z.metadata.variant,z.colors.surface.foreground]),re=l.useMemo(()=>{if(xe?.path)return{id:xe.id,path:xe.path};const Z=$??H;return Z?{id:`path:${Z}`,path:Z}:null},[xe,$,H]),[K,le]=l.useState(()=>typeof window>"u"?!1:wn()),Se=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ue=bl();l.useEffect(()=>{typeof window>"u"||le(wn())},[]);const je=l.useMemo(()=>{if(typeof window>"u")return null;const Z=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Z=="number"&&Number.isFinite(Z)&&Z>0)return Z;if(typeof navigator>"u")return null;const ie=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ie)return null;const Ce=Number.parseInt(ie[1],10),He=Number.parseInt(ie[2],10);return Number.isNaN(Ce)?null:Ce===10?He:Ce},[]),W=l.useMemo(()=>K&&Se||ue?"pl-[5.5rem]":"pl-3",[K,Se,ue]),me=l.useMemo(()=>!K||!Se||je===null?"":je>=26?"h-12":je<=15?"h-14":"",[K,Se,je]),X=l.useCallback(async Z=>{Z.target.closest("button, a, input, select, textarea")||Z.button===0&&K&&await Qh()},[K]);l.useEffect(()=>{if(!n)return;const Z=ie=>{ie.key==="Escape"&&(ie.preventDefault(),ie.stopPropagation(),n())};return window.addEventListener("keydown",Z,!0),()=>window.removeEventListener("keydown",Z,!0)},[n]);const[ce,ee]=l.useState(""),{isLoading:Pe,isGitRepository:Ne}=jg(te),Y=Ac(Z=>Z.createMultiRun),he=Ac(Z=>Z.error),ke=Ac(Z=>Z.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Z=>Z.trim().length>0?Z:t)},[t]),l.useEffect(()=>{if(!re)return;let Z=!1;return j(!0),(async()=>{try{const ie=await Pd(re);Z||w(ie)}catch{}finally{Z||j(!1)}})(),()=>{Z=!0}},[re]);const be=Z=>{p.length>=Dc||(m(ie=>[...ie,Z]),ke())},fe=Z=>{m(ie=>ie.filter((Ce,He)=>He!==Z)),ke()},Te=l.useCallback((Z,ie)=>{m(Ce=>Ce.map((He,Ge)=>Ge===Z?ie:He))},[]),Ve=async Z=>{const ie=Z.target.files;if(!ie)return;let Ce=0;for(let He=0;He<ie.length;He++){const Ge=ie[He];if(Ge.size>BA){q.error(i("multirun.launcher.toast.fileTooLarge",{fileName:Ge.name}));continue}try{const Xe=await new Promise((tt,st)=>{const qe=new FileReader;qe.onload=()=>tt(qe.result),qe.onerror=st,qe.readAsDataURL(Ge)}),we={id:hd(),filename:Ge.name,mimeType:Ge.type||"application/octet-stream",size:Ge.size,dataUrl:Xe};h(tt=>[...tt,we]),Ce++}catch(Xe){console.error("File attach failed",Xe),q.error(i("multirun.launcher.toast.attachFailed",{fileName:Ge.name}))}}Ce>0&&q.success(Ce===1?i("multirun.launcher.toast.attachedSingle",{count:Ce}):i("multirun.launcher.toast.attachedPlural",{count:Ce})),R.current&&(R.current.value="")},G=Z=>{h(ie=>ie.filter(Ce=>Ce.id!==Z))},Ie=l.useCallback((Z,ie)=>{if(Z.startsWith("/")){const Ge=Z.indexOf(" "),Xe=Z.indexOf(`
|
|
216
|
-
`),we=Math.min(Ge===-1?Z.length:Ge,Xe===-1?Z.length:Xe);if(ie<=we&&Ge===-1){M(Z.substring(1,we)),N(!0),A(!1);return}}N(!1);const Ce=Z.substring(0,ie),He=Ce.lastIndexOf("@");if(He!==-1){const Ge=He>0?Ce[He-1]:null,Xe=Ce.substring(He+1);(!Ge||/\s/.test(Ge))&&!Xe.includes(" ")&&!Xe.includes(`
|
|
217
|
-
`)?(P(Xe),A(!0)):A(!1);return}A(!1)},[]),Oe=l.useCallback(Z=>{if(k&&V.current&&(Z.key==="Enter"||Z.key==="ArrowUp"||Z.key==="ArrowDown"||Z.key==="Escape"||Z.key==="Tab")){Z.preventDefault(),V.current.handleKeyDown(Z.key);return}I&&O.current&&(Z.key==="Enter"||Z.key==="ArrowUp"||Z.key==="ArrowDown"||Z.key==="Escape"||Z.key==="Tab")&&(Z.preventDefault(),O.current.handleKeyDown(Z.key))},[k,I]),De=l.useCallback(Z=>{const Ce=L.current?.selectionStart??c.length,Ge=c.substring(0,Ce).lastIndexOf("@"),Xe=Z.relativePath&&Z.relativePath.trim().length>0?Z.relativePath.trim():Z.path||Z.name,we=Ge!==-1?Ge:Ce,tt=`${c.substring(0,we)}@${Xe} ${c.substring(Ce)}`,st=we+Xe.length+2;d(tt),A(!1),P(""),requestAnimationFrame(()=>{const qe=L.current;qe&&(qe.selectionStart=st,qe.selectionEnd=st,qe.focus()),Ie(tt,st)})},[c,Ie]),ge=l.useCallback(Z=>{const Ce=L.current?.selectionStart??c.length,Ge=c.substring(0,Ce).lastIndexOf("@"),Xe=Ge!==-1?Ge:Ce,we=`${c.substring(0,Xe)}@${Z} ${c.substring(Ce)}`,tt=Xe+Z.length+2;d(we),A(!1),P(""),requestAnimationFrame(()=>{const st=L.current;st&&(st.selectionStart=tt,st.selectionEnd=tt,st.focus()),Ie(we,tt)})},[c,Ie]),U=l.useCallback(Z=>{const ie=`/${Z.name} `;d(ie),N(!1),M(""),requestAnimationFrame(()=>{const Ce=L.current;Ce&&(Ce.focus(),Ce.selectionStart=Ce.value.length,Ce.selectionEnd=Ce.value.length),Ie(ie,ie.length)})},[Ie]),de=async Z=>{if(Z.preventDefault(),!!c.trim()&&!(p.length<2)){x(!0),ke();try{ae&&ae!==_&&se(ae);const ie=p.map(({instanceId:we,...tt})=>tt),Ce=b.map(we=>({mime:we.mimeType,filename:we.filename,url:we.dataUrl})),He=g.filter(we=>we.trim().length>0),Ge={name:a.trim(),prompt:c.trim(),models:ie,agent:u||void 0,worktreeBaseBranch:ce,files:Ce.length>0?Ce:void 0,setupCommands:He.length>0?He:void 0},Xe=await Y(Ge);Xe&&(Xe.firstSessionId&&Ht.getState().setCurrentSession(Xe.firstSessionId),e?.())}finally{x(!1)}}},Ee=!!(a.trim()&&c.trim()&&p.length>=2&&ce&&Ne&&!Pe),_e=g.filter(Z=>Z.trim()).length;return s.jsxs("form",{onSubmit:de,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:X,className:pe("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",W,me),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:i("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("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(C,{name:"close",className:"h-5 w-5"})})}),s.jsx(Pt,{children:s.jsx("p",{children:i("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Zi,{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(Ja,{htmlFor:"multirun-project",required:!0,children:i("multirun.launcher.project.label")}),oe.length>0?s.jsxs(ps,{value:ae??void 0,onValueChange:F,children:[s.jsx(hs,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:xe?s.jsx(ys,{children:Q(xe)}):s.jsx(ys,{placeholder:i("multirun.launcher.project.placeholder")})}),s.jsx(fs,{fitContent:!0,children:oe.map(Z=>s.jsx(Ft,{value:Z.id,className:"max-w-[24rem]",children:Q(Z)},Z.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:i("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ja,{htmlFor:"group-name",required:!0,info:s.jsx(Mo,{children:i("multirun.launcher.groupName.info")}),children:i("multirun.launcher.groupName.label")}),s.jsx(Ut,{id:"group-name",value:a,onChange:Z=>o(Z.target.value),placeholder:i("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ja,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Mo,{children:i("multirun.launcher.baseBranch.info")}),children:i("multirun.launcher.baseBranch.label")}),s.jsx(MA,{directory:te,value:ce,onChange:ee,id:"multirun-worktree-base-branch"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ja,{htmlFor:"multirun-agent",info:s.jsx(Mo,{children:i("multirun.launcher.agent.info")}),children:i("multirun.launcher.agent.label")}),s.jsx(EA,{value:u,onChange:f,id:"multirun-agent"})]})]}),s.jsxs(cr,{open:y,onOpenChange:S,children:[s.jsxs(jr,{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(C,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:i("multirun.launcher.setupCommands.label")}),_e>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:_e}),s.jsx(C,{name:"arrow-down-s",className:pe("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",y&&"rotate-180")})]}),s.jsx(dr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:D?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:i("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[g.map((Z,ie)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Ut,{value:Z,onChange:Ce=>{const He=[...g];He[ie]=Ce.target.value,w(He)},placeholder:i("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const Ce=g.filter((He,Ge)=>Ge!==ie);w(Ce)},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":i("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(C,{name:"close",className:"h-3.5 w-3.5"})})]},`${Z}-${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(C,{name:"add",className:"h-3 w-3"}),i("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ja,{htmlFor:"prompt",required:!0,children:i("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(vn,{id:"prompt",ref:L,value:c,onChange:Z=>{const ie=Z.target.value;d(ie);const Ce=Z.target.selectionStart??ie.length;Ie(ie,Ce)},onKeyDown:Oe,placeholder:i("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),k?s.jsx(Kh,{ref:V,searchQuery:T,onCommandSelect:U,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,I?s.jsx(Hh,{ref:O,searchQuery:E,onFileSelect:De,onAgentSelect:ge,onClose:()=>A(!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:R,type:"file",multiple:!0,className:"hidden",onChange:Ve,accept:"*/*"}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>R.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(C,{name:"attachment-2",className:"h-3 w-3"}),i("multirun.launcher.attachments.attach")]})}),s.jsx(Pt,{children:i("multirun.launcher.attachments.tooltip")})]}),b.map(Z=>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:[Z.mimeType.startsWith("image/")?s.jsx(C,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(C,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Z.filename,children:Z.filename}),s.jsx("button",{type:"button",onClick:()=>G(Z.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(C,{name:"close",className:"h-3 w-3"})})]},Z.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ja,{required:!0,info:s.jsx(Mo,{children:i("multirun.launcher.models.info",{max:Dc})}),children:i("multirun.launcher.models.label")}),s.jsx(CA,{selectedModels:p,onAdd:be,onRemove:fe,onUpdate:Te,minModels:2,maxModels:Dc})]}),he&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:he})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:n,children:i("multirun.launcher.actions.cancel")}),s.jsx(ve,{type:"submit",size:"sm",disabled:!Ee||v,children:v?i("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:i("multirun.launcher.actions.startWithModelCount",{count:p.length})})})]})})]})};class VA 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(Yh,{className:"w-full max-w-md",children:[s.jsx(ky,{className:"text-center",children:s.jsxs(Cy,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(C,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Iy,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(ve,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(C,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function zA(t){const e=rt.c(22),{t:n}=mt();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let i;e[2]!==n?(i=n("chat.errorBoundary.description"),e[2]=n,e[3]=i):i=e[3];let a;e[4]!==n?(a=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=a):a=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]!==i||e[14]!==a||e[15]!==o||e[16]!==c||e[17]!==d?(p={title:r,description:i,sessionLabel:a,detailsSummary:o,resetAction:c,persistentHint:d},e[12]=r,e[13]=i,e[14]=a,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(VA,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const fd=()=>{const t=rt.c(3),n=Ht(UA)||void 0;let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Py,{}),t[0]=r):r=t[0];let i;return t[1]!==n?(i=s.jsx(zA,{sessionId:n,children:r}),t[1]=n,t[2]=i):i=t[2],i};function UA(t){return t.currentSessionId}const WA=Kr(()=>wr(()=>Promise.resolve().then(()=>g2),void 0).then(t=>({default:t.PlanView}))),sh=Kr(()=>wr(()=>Promise.resolve().then(()=>Qj),void 0).then(t=>({default:t.GitView}))),KA=Kr(()=>wr(()=>Promise.resolve().then(()=>$N),void 0).then(t=>({default:t.DiffView}))),nh=Kr(()=>wr(()=>import("./TerminalView-BpoHWJj6.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),HA=Kr(()=>wr(()=>Promise.resolve().then(()=>d2),void 0).then(t=>({default:t.FilesView}))),GA=Kr(()=>wr(()=>Promise.resolve().then(()=>DC),void 0).then(t=>({default:t.SettingsView}))),qA=Kr(()=>wr(()=>import("./SettingsWindow-B4B2bn0C.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),JA=Kr(()=>wr(()=>import("./MultiRunWindow-Cwc0x7fs.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),Eo=85,QA=250,YA=500,XA=400,ZA=860,e6=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},t6=()=>{const{t}=mt(),e=1140,n=1220,r=640,i=700,a=Me(te=>te.isSidebarOpen),o=Me(te=>te.isRightSidebarOpen),c=Me(te=>te.isBottomTerminalOpen),d=Me(te=>te.setRightSidebarOpen),p=Me(te=>te.setBottomTerminalOpen),m=Me(te=>te.activeMainTab),u=Me(te=>te.setIsMobile),f=Me(te=>te.isSessionSwitcherOpen),b=Me(te=>te.isSettingsDialogOpen),h=Me(te=>te.setSettingsDialogOpen),v=Me(te=>te.isMultiRunLauncherOpen),x=Me(te=>te.setMultiRunLauncherOpen),g=Me(te=>te.multiRunLauncherPrefillPrompt),{isMobile:w,isTablet:y}=rn(),S=l.useMemo(()=>wn(),[]),D=Me(te=>te.sidebarWidth),j=Me(te=>te.rightSidebarWidth),[I,A]=l.useState(null),E=Or()??"",P=l.useMemo(()=>e6(E),[E]),k=Me(te=>{if(!P)return!1;const F=te.contextPanelByDirectory[P],z=F?.tabs??[],Q=z.find(re=>re.id===F?.activeTabId)??z[z.length-1];return!!(F?.isOpen&&Q)}),N=Me(te=>te.setSidebarOpen),T=l.useRef(!1),M=l.useRef(!1),R=l.useRef(!1),[L,O]=l.useState(!1),V=l.useRef(!1),$=Xd(0),B=$e.useRef(0),H=Xd(0),_=$e.useRef(0);$e.useEffect(()=>{w&&(B.current=window.innerWidth*(Eo/100),_.current=window.innerWidth*(Eo/100))},[w]),$e.useEffect(()=>{if(!w)return;const te=L?0:-B.current;Zd($,te,{type:"spring",stiffness:400,damping:35,mass:.8})},[L,w,$]),$e.useEffect(()=>{if(!w)return;V.current=o;const te=o?0:_.current;Zd(H,te,{type:"spring",stiffness:400,damping:35,mass:.8})},[w,o,H]),$e.useEffect(()=>{w&&O(f)},[f,w]),$e.useEffect(()=>{!w||!b||(O(!1),f&&Me.getState().setSessionSwitcherOpen(!1),o&&d(!1))},[w,b,f,o,d]),$e.useEffect(()=>{w&&(V.current=o)},[o,w]);const se=Na(te=>te.checkForUpdates);l.useEffect(()=>{let re=!1,K=null;const le=ue=>{const je=Math.round(ue*1e3);return Math.max(3e5,Math.min(864e5,je))},Se=ue=>{re||(K=window.setTimeout(async()=>{const je=await se(),W=typeof je=="number"&&Number.isFinite(je)?le(je):36e5;Se(W)},ue))};return Se(3e3),()=>{re=!0,K!==null&&window.clearTimeout(K)}},[se]),l.useEffect(()=>{Me.getState().isMobile!==w&&u(w)},[w,u]),l.useEffect(()=>{if(typeof window>"u")return;let te;const F=()=>{te!==void 0&&window.clearTimeout(te),te=window.setTimeout(()=>{Me.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F),te!==void 0&&window.clearTimeout(te)}},[]),l.useEffect(()=>{if(k){Me.getState().isSidebarOpen&&(N(!1),R.current=!0);return}R.current&&(N(!0),R.current=!1)},[k,N]),l.useEffect(()=>{if(typeof window>"u")return;let te;const F=()=>{const Q=Me.getState(),re=window.innerWidth,K=window.innerHeight;if(!w&&!y){const le=re<e,Se=re>=n;le?Q.isRightSidebarOpen&&(d(!1),T.current=!0):Se&&T.current&&(d(!0),T.current=!1);const ue=K<r,je=K>=i;ue?Q.isBottomTerminalOpen&&(p(!1),M.current=!0):je&&M.current&&(p(!0),M.current=!1)}},z=()=>{te!==void 0&&window.clearTimeout(te),te=window.setTimeout(()=>{F()},100)};return F(),window.addEventListener("resize",z),()=>{window.removeEventListener("resize",z),te!==void 0&&window.clearTimeout(te)}},[w,y,p,d]),l.useEffect(()=>{if(typeof window>"u")return;const te=Me.subscribe((F,z)=>{const Q=window.innerWidth,re=window.innerHeight,K=Q>=n,le=re>=i;F.isRightSidebarOpen!==z.isRightSidebarOpen&&K&&(T.current=!1),F.isBottomTerminalOpen!==z.isBottomTerminalOpen&&le&&(M.current=!1)});return()=>{te()}},[w,y,p,d]);const oe=l.useMemo(()=>{switch(m){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(WA,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(sh,{})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(KA,{})});case"terminal":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(nh,{})});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(HA,{})});default:return null}},[m]),ae=m==="chat",ne=l.useMemo(()=>Math.min(YA,Math.max(QA,D||Kc)),[D]),xe=l.useMemo(()=>Math.min(ZA,Math.max(XA,j||mf)),[j]);return s.jsx(aN,{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(TC,{}),s.jsx(b4,{}),s.jsx(j4,{}),s.jsx(vA,{}),w?s.jsxs(Ay,{value:{leftDrawerOpen:L,rightDrawerOpen:o,toggleLeftDrawer:()=>{o&&d(!1),O(!L)},toggleRightDrawer:()=>{L&&O(!1),d(!o)},leftDrawerX:$,rightDrawerX:H,leftDrawerWidth:B,rightDrawerWidth:_,setMobileLeftDrawerOpen:O,setRightSidebarOpen:d},children:[!b&&s.jsx(Uu,{onToggleLeftDrawer:()=>{o&&d(!1),O(!L)},onToggleRightDrawer:()=>{L&&O(!1),d(!o)},leftDrawerOpen:L,rightDrawerOpen:o}),s.jsx(Ol.button,{type:"button",initial:!1,animate:{opacity:L||o?1:0,pointerEvents:L||o?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{O(!1),d(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Ol.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(B.current||window.innerWidth*.85),right:0},style:{width:`${Eo}%`,x:$},onDragEnd:(te,F)=>{const z=B.current||window.innerWidth*.85,Q=z*.3,re=500,K=$.get(),le=F.offset.x<-Q||F.velocity.x<-re,Se=F.offset.x>Q||F.velocity.x>re;le?($.set(-z),O(!1)):Se?($.set(0),O(!0)):K>-z/2?$.set(0):$.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":!L,children:s.jsx("div",{"data-page-scroll-lock":"true",className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col","data-page-scroll-lock":"true",children:s.jsx(Ys,{children:s.jsx(Zp,{mobileVariant:!0})})})})}),s.jsx(Ol.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:_.current||window.innerWidth*.85},style:{width:`${Eo}%`,x:H},onDragEnd:(te,F)=>{const z=_.current||window.innerWidth*.85,Q=z*.3,re=500,K=H.get(),le=F.offset.x>Q||F.velocity.x>re,Se=F.offset.x<-Q||F.velocity.x<-re;le?(H.set(z),d(!1)):Se?(H.set(0),d(!0)):K<z/2?H.set(0):H.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(Ys,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(sh,{})})})})}),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",!ae&&"invisible"),children:s.jsx(Ys,{children:s.jsx(fd,{})})}),oe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Ys,{children:oe})}),v&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Ys,{children:s.jsx(_A,{initialPrompt:g,onCreated:()=>x(!1),onCancel:()=>x(!1)})})})]})}),b&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Ys,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(GA,{onClose:()=>h(!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:[a?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:`${ne}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:`${ne}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:`${xe}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:`${xe}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(P1,{isOpen:a,isMobile:w,className:"border-0",children:s.jsx(Zp,{})}),s.jsxs("div",{className:pe("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",a&&"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(Uu,{desktopRightSidebarActionsHost:I}),s.jsx("div",{className:pe("flex flex-1 min-h-0 overflow-hidden",a||ae?"":"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",!ae&&"invisible"),children:s.jsx(Ys,{children:s.jsx(fd,{})})}),oe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Ys,{children:oe})})]}),s.jsx(sS,{})]})}),s.jsx(N1,{isOpen:c,isMobile:w,children:c?s.jsx(Ys,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(nh,{})})}):null})]}),s.jsx(A1,{isOpen:o,className:"border-0",onTopActionsHostChange:A,children:s.jsx(Ys,{children:s.jsx(D0,{})})})]})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(qA,{open:b,onOpenChange:h})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(JA,{open:v,onOpenChange:x,initialPrompt:g})})]})]})})},s6=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`},ar=t=>{const e=rt.c(8),{label:n,value:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=i):i=e[0];let a;e[1]!==n?(a=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=a):a=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]!==a||e[6]!==o?(c=s.jsxs("div",{className:"rounded-md p-2",style:i,children:[a,o]}),e[5]=a,e[6]=o,e[7]=c):c=e[7],c},rh=t=>{const e=rt.c(43),{title:n,snapshot:r,emptyLabel:i}=t,{t:a}=mt();let o;if(e[0]!==i||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==a||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(a6,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]!==a?(u=r.startedAt?s6(r.durationMs):a("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=a,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==m||e[19]!==f?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,f]}),e[18]=m,e[19]=f,e[20]=b):b=e[20];let h;e[21]!==a?(h=a("memoryDebugPanel.metric.metrics"),e[21]=a,e[22]=h):h=e[22];let v;e[23]!==r.entries.length||e[24]!==h?(v=s.jsx(ar,{label:h,value:r.entries.length}),e[23]=r.entries.length,e[24]=h,e[25]=v):v=e[25];let x;e[26]!==a?(x=a("memoryDebugPanel.metric.samples"),e[26]=a,e[27]=x):x=e[27];let g;e[28]!==x||e[29]!==p?(g=s.jsx(ar,{label:x,value:p}),e[28]=x,e[29]=p,e[30]=g):g=e[30];let w;e[31]!==a?(w=a("memoryDebugPanel.metric.lastUpdate"),e[31]=a,e[32]=w):w=e[32];let y;e[33]!==r.lastUpdatedAt||e[34]!==a?(y=r.lastUpdatedAt?a("memoryDebugPanel.common.live"):a("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=a,e[35]=y):y=e[35];let S;e[36]!==w||e[37]!==y?(S=s.jsx(ar,{label:w,value:y}),e[36]=w,e[37]=y,e[38]=S):S=e[38];let D;e[39]!==g||e[40]!==S||e[41]!==v?(D=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,g,S]}),e[39]=g,e[40]=S,e[41]=v,e[42]=D):D=e[42],o=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[b,D,c.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:i}):s.jsx(As,{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:a("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:a("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:a("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:a("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=i,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=a,e[6]=n,e[7]=o}else o=e[7];return o},n6=t=>{const e=rt.c(101),{onClose:n}=t,{t:r}=mt(),[i,a]=l.useState("memory"),[o,c]=l.useState("idle"),d=Ht(i6),p=Jh(o6),m=to(),u=Lh(l6),f=or(c6),[b,h]=l.useState(d6),[v,x]=l.useState(u6);let g;e[0]!==b.entries?(g=new Map,b.entries.forEach(Ne=>{g.set(Ne.metric,Ne.count)}),e[0]=b.entries,e[1]=g):g=e[1];let w;e[2]!==g?(w=g.get("ui.message_list.render")??0,e[2]=g,e[3]=w):w=e[3];let y;e[4]!==g?(y=g.get("ui.message_list.render.streaming")??0,e[4]=g,e[5]=y):y=e[5];let S;e[6]!==g?(S=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=S):S=e[7];let D;e[8]!==g?(D=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=D):D=e[9];let j;e[10]!==g?(j=g.get("ui.chat_message.render.static_during_stream")??0,e[10]=g,e[11]=j):j=e[11];let I;e[12]!==g?(I=g.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=g,e[13]=I):I=e[13];let A;e[14]!==w||e[15]!==y||e[16]!==S||e[17]!==D||e[18]!==j||e[19]!==I?(A={messageListRender:w,messageListRenderStreaming:y,chatMessageRender:S,chatMessageRenderStreaming:D,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:I},e[14]=w,e[15]=y,e[16]=S,e[17]=D,e[18]=j,e[19]=I,e[20]=A):A=e[20];const E=A;let P,k;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const Ne=()=>{h($o()),x(Bo())};Ne();const Y=window.setInterval(Ne,500);return()=>window.clearInterval(Y)},k=[],e[21]=P,e[22]=k):(P=e[21],k=e[22]),l.useEffect(P,k);let N,T;e[23]!==o?(N=()=>{if(o==="idle")return;const Ne=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Ne)},T=[o],e[23]=o,e[24]=N,e[25]=T):(N=e[24],T=e[25]),l.useEffect(N,T);let M=0,R;if(e[26]!==u?(R=Object.keys(u),e[26]=u,e[27]=R):R=e[27],e[28]!==u||e[29]!==R||e[30]!==M){for(const Ne of R)M=M+(u[Ne]?.length??0);e[28]=u,e[29]=R,e[30]=M,e[31]=M}else M=e[31];const L=M;let O;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Ne;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Ne=Y=>{const he=u[Y.id]?.length||0,ke=p.get(Y.id);return{id:Y.id,title:Y.title||r("memoryDebugPanel.common.untitled"),messageCount:he,isStreaming:ke?.isStreaming||!1,isZombie:ke?.isZombie||!1,backgroundCount:ke?.backgroundMessageCount||0,lastAccessed:ke?.lastAccessedAt||0,isCurrent:Y.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=Ne):Ne=e[42],O=m.map(Ne).sort(m6),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=O}else O=e[37];const V=O;let $;e[43]!==u?($=Object.keys(u),e[43]=u,e[44]=$):$=e[44];const B=$.length;let H;e[45]===Symbol.for("react.memo_cache_sentinel")?(H=async()=>{try{const Ne={generatedAt:new Date().toISOString(),ui:$o(),vscode:Bo()};await navigator.clipboard.writeText(JSON.stringify(Ne,null,2)),c("copied")}catch{c("error")}},e[45]=H):H=e[45];const _=H;let se;e[46]===Symbol.for("react.memo_cache_sentinel")?(se={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=se):se=e[46];let oe;e[47]!==i?(oe=i==="memory"?s.jsx(C,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(C,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=i,e[48]=oe):oe=e[48];let ae;e[49]!==r?(ae=r("memoryDebugPanel.title"),e[49]=r,e[50]=ae):ae=e[50];let ne;e[51]!==ae?(ne=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ae}),e[51]=ae,e[52]=ne):ne=e[52];let xe;e[53]!==oe||e[54]!==ne?(xe=s.jsxs("div",{className:"flex items-center gap-2",children:[oe,ne]}),e[53]=oe,e[54]=ne,e[55]=xe):xe=e[55];let te;e[56]!==i?(te=i==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ve,{size:"xs",variant:"ghost",onClick:_,children:s.jsx(C,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:()=>{Ty(),h($o()),x(Bo())},children:s.jsx(C,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=i,e[57]=te):te=e[57];let F;e[58]!==n?(F=n?s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(C,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=F):F=e[59];let z;e[60]!==te||e[61]!==F?(z=s.jsxs("div",{className:"flex items-center gap-1",children:[te,F]}),e[60]=te,e[61]=F,e[62]=z):z=e[62];let Q;e[63]!==xe||e[64]!==z?(Q=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[xe,z]}),e[63]=xe,e[64]=z,e[65]=Q):Q=e[65];let re;e[66]===Symbol.for("react.memo_cache_sentinel")?(re={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=re):re=e[66];const K=i==="memory"?"secondary":"ghost";let le;e[67]===Symbol.for("react.memo_cache_sentinel")?(le=()=>a("memory"),e[67]=le):le=e[67];let Se;e[68]!==r?(Se=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=Se):Se=e[69];let ue;e[70]!==K||e[71]!==Se?(ue=s.jsx(ve,{size:"sm",variant:K,className:"flex-1",onClick:le,children:Se}),e[70]=K,e[71]=Se,e[72]=ue):ue=e[72];const je=i==="streaming"?"secondary":"ghost";let W;e[73]===Symbol.for("react.memo_cache_sentinel")?(W=()=>a("streaming"),e[73]=W):W=e[73];let me;e[74]!==r?(me=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=me):me=e[75];let X;e[76]!==je||e[77]!==me?(X=s.jsx(ve,{size:"sm",variant:je,className:"flex-1",onClick:W,children:me}),e[76]=je,e[77]=me,e[78]=X):X=e[78];let ce;e[79]!==ue||e[80]!==X?(ce=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:re,children:[ue,X]}),e[79]=ue,e[80]=X,e[81]=ce):ce=e[81];let ee;e[82]!==i||e[83]!==B||e[84]!==o||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==V||e[89]!==m||e[90]!==E||e[91]!==b||e[92]!==r||e[93]!==f||e[94]!==L||e[95]!==v?(ee=i==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(ar,{label:r("memoryDebugPanel.metric.totalMessages"),value:L}),s.jsx(ar,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${B} / ${ju.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:Dy()})})]}),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:ju.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:f})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(As,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(Ne=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ne.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Ne.title}),Ne.isStreaming?s.jsx(C,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ne.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Ne.messageCount})}),Ne.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ne.backgroundCount]}):null]})]},Ne.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ve,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(p6),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Pt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(o==="copied"?"memoryDebugPanel.streaming.copy.copied":o==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ve,{size:"xs",variant:"outline",onClick:_,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(ar,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(ar,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(ar,{label:r("memoryDebugPanel.metric.messageListRenders"),value:E.messageListRender}),s.jsx(ar,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:E.messageListRenderStreaming}),s.jsx(ar,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:E.chatMessageRender}),s.jsx(ar,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:E.chatMessageRenderStreaming}),s.jsx(ar,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:E.chatMessageRenderStaticDuringStream}),s.jsx(ar,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:E.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(rh,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(rh,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=i,e[83]=B,e[84]=o,e[85]=d,e[86]=u,e[87]=p,e[88]=V,e[89]=m,e[90]=E,e[91]=b,e[92]=r,e[93]=f,e[94]=L,e[95]=v,e[96]=ee):ee=e[96];let Pe;return e[97]!==Q||e[98]!==ce||e[99]!==ee?(Pe=s.jsxs(Yh,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:se,children:[Q,ce,ee]}),e[97]=Q,e[98]=ce,e[99]=ee,e[100]=Pe):Pe=e[100],Pe},r6=n6;function a6(t,e){return t+e.count}function i6(t){return t.currentSessionId}function o6(t){return t.sessionMemoryState}function l6(t){return t.message}function c6(t){return t.totalRequestCount}function d6(){return $o()}function u6(){return Bo()}function m6(t,e){return e.lastAccessed-t.lastAccessed}function p6(t){return{id:t.id,title:t.title}}const h6=()=>{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()??"":""},f6=async()=>{const t=h6()||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")},ah="openchamber:menu-action",Tc="openchamber:check-for-updates",g6=t=>{const e=Ht(x=>x.openNewSessionDraft),n=Me(x=>x.toggleCommandPalette),r=Me(x=>x.setCommandPaletteOpen),i=Me(x=>x.toggleHelpDialog),a=Me(x=>x.toggleSidebar),o=Me(x=>x.setSessionSwitcherOpen),c=Me(x=>x.setActiveMainTab),d=Me(x=>x.setSettingsDialogOpen),p=Me(x=>x.setAboutDialogOpen),m=Na(x=>x.checkForUpdates),{setThemeMode:u}=Nr(),f=l.useRef(!1),b=l.useCallback(()=>{f.current||(f.current=!0,m().then(()=>{const{available:x,error:g}=Na.getState();if(g){q.error("Failed to check for updates",{description:g});return}x||q.success("You are on the latest version")}).finally(()=>{f.current=!1}))},[m]),h=l.useCallback(()=>{vr.requestDirectoryDialog()},[]),v=l.useCallback(x=>{switch(x){case"about":p(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),o(!1),e();break;case"new-worktree-session":c("chat"),o(!1),zh();break;case"change-workspace":h();break;case"open-git-tab":{const{activeMainTab:g}=Me.getState();c(g==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:g}=Me.getState();c(g==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:g}=Me.getState();c(g==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:g}=Me.getState();c(g==="terminal"?"chat":"terminal");break}case"copy":{const g=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(g)||f6();break}case"theme-light":u("light");break;case"theme-dark":u("dark");break;case"theme-system":u("system");break;case"toggle-sidebar":a();break;case"toggle-memory-debug":t?.();break;case"help-dialog":i();break;case"download-logs":{My().catch(()=>{q.error("Failed to collect OpenCode status")});break}}},[h,t,e,p,c,o,r,d,u,n,i,a]);l.useEffect(()=>{const x=w=>{const y=w.detail;y&&v(y)},g=()=>{b()};return window.addEventListener(ah,x),window.addEventListener(Tc,g),()=>{window.removeEventListener(ah,x),window.removeEventListener(Tc,g)}},[v,b]),l.useEffect(()=>{if(typeof window>"u")return;const g=window.__TAURI__?.event?.listen;if(typeof g!="function")return;let w=null,y=null;return g("openchamber:menu-action",S=>{const D=S?.payload;typeof D=="string"&&v(D)}).then(S=>{w=S}).catch(()=>{}),g("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Tc))}).then(S=>{y=S}).catch(()=>{}),()=>{(async()=>{try{const D=w?.();D instanceof Promise&&await D}catch{}try{const D=y?.();D instanceof Promise&&await D}catch{}})()}},[v])},x6=["chat","git","diff","terminal","files"],b6=["settings","agents","commands","skills","providers","usage","git-identities"],br={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function ih(t){const e=y6();return{sessionId:v6(e),tab:w6(e),settingsPath:j6(e),diffFile:N6(e)}}function y6(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function v6(t){const e=t.get(br.SESSION);return!e||e.trim().length===0?null:e.trim()}function w6(t){const e=t.get(br.TAB);if(!e)return null;const n=e.toLowerCase().trim();return x6.includes(n)?n:null}function j6(t){const e=t.get(br.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(b6.includes(n),n)}function N6(t){const e=t.get(br.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function oh(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(br.SESSION)||t.has(br.TAB)||t.has(br.SETTINGS)||t.has(br.FILE)}catch{return!1}}const S6="chat";function Ng(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(br.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(br.SETTINGS,n),e}return t.tab!==S6&&e.set(br.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(br.FILE,t.diffFile),e}function k6(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function C6(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Ng(t),r=[...e.entries()].sort((a,o)=>a[0].localeCompare(o[0])),i=[...n.entries()].sort((a,o)=>a[0].localeCompare(o[0]));if(r.length!==i.length)return!1;for(let a=0;a<r.length;a++)if(r[a][0]!==i[a][0]||r[a][1]!==i[a][1])return!1;return!0}catch{return!0}}function I6(t,e={}){if(!(typeof window>"u")&&!P6()&&!(!e.force&&C6(t)))try{const n=Ng(t),r=k6(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function P6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function A6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function D6(){const t=l.useMemo(()=>A6(),[]),e=l.useRef(!1),n=l.useRef(!1),r=Ht(u=>u.setCurrentSession),i=Me(u=>u.setActiveMainTab),a=Me(u=>u.setSettingsDialogOpen),o=Me(u=>u.setSettingsPage),c=Me(u=>u.navigateToDiff),d=l.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const f=Ht.getState().currentSessionId;u.sessionId!==f&&await r(u.sessionId)}if(u.settingsPath){o(Uf(u.settingsPath)),a(!0);return}Me.getState().isSettingsDialogOpen&&a(!1),u.tab&&i(u.tab),u.diffFile&&(u.tab==="diff"||!u.tab)&&c(u.diffFile)}finally{n.current=!1}}},[r,i,a,o,c]),p=l.useCallback(()=>{const u=Ht.getState(),f=Me.getState();return{sessionId:u.currentSessionId,tab:f.activeMainTab,isSettingsOpen:f.isSettingsDialogOpen,settingsPath:f.settingsPage,diffFile:f.pendingDiffFile}},[]),m=l.useCallback((u={})=>{if(t||n.current)return;const f=p();I6(f,u)},[t,p]);l.useEffect(()=>{if(e.current||(e.current=!0,!oh()))return;const u=ih();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),l.useEffect(()=>{if(t)return;let u=Ht.getState().currentSessionId;return Ht.subscribe(b=>{const h=b.currentSessionId;h===u||n.current||(u=h,m())})},[t,m]),l.useEffect(()=>{if(t)return;let u=Me.getState().activeMainTab,f=Me.getState().isSettingsDialogOpen,b=Me.getState().settingsPage,h=Me.getState().pendingDiffFile;return Me.subscribe(x=>{if(n.current)return;const g=x.activeMainTab!==u,w=x.isSettingsDialogOpen!==f,y=x.settingsPage!==b,S=x.pendingDiffFile!==h&&x.activeMainTab==="diff";u=x.activeMainTab,f=x.isSettingsDialogOpen,b=x.settingsPage,h=x.pendingDiffFile,(g||w||y||S)&&m()})},[t,m]),l.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const f=ih();if(oh())d(f);else{const b=Me.getState();b.isSettingsDialogOpen&&a(!1),b.activeMainTab!=="chat"&&i("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,i,a])}const lh="pwa-install-toast-shown",T6=()=>{const t=rt.c(6),{browserTab:e}=sg(),{t:n}=mt(),r=l.useRef(n);let i,a;t[0]!==n?(i=()=>{r.current=n},a=[n],t[0]=n,t[1]=i,t[2]=a):(i=t[1],a=t[2]),l.useEffect(i,a);let o,c;t[3]!==e?(o=()=>{if(typeof window>"u"||!sa()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(q.dismiss(p),p=null)},u=async()=>{if(!d)return;const h=d;d=null,m(),await h.prompt();const{outcome:v}=await h.userChoice;v==="accepted"&&q.success(r.current("pwa.installPrompt.started"))},f=h=>{const v=h;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const x=wh();x.getItem(lh)!=="true"&&p===null&&(x.setItem(lh,"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",f),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",f),window.removeEventListener("appinstalled",b)}},c=[e],t[3]=e,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c)},M6=["local","remote",null],E6=["ok","not-configured","unreachable","wrong-service","missing"];function Sg(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!M6.includes(n)))return{valid:!1};if(typeof r!="string"||!E6.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 R6(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function F6(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function dh(){if(gd()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=Sg(e);return n.valid?n.outcome:null}function gd(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Sg(t).valid?"valid":"malformed"}const L6=()=>{const t=rt.c(5),[e,n]=l.useState(O6),{isUpdating:r,message:i}=e;let a,o;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>Ry(n),o=[],t[0]=a,t[1]=o):(a=t[0],o=t[1]),l.useEffect(a,o),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Cd,{width:80,height:80}),t[2]=c):c=t[2];let d;return t[3]!==i?(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:i})]}),t[3]=i,t[4]=d):d=t[4],d};function O6(){return Ey()}const $6=({open:t,onOpenChange:e})=>{const{t:n}=mt(),[r,i]=l.useState(null),[a,o]=l.useState(null),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState(!1),v=l.useCallback(async()=>{if(!c){d(!0),m(!1);try{if(!u){q.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const g=await Nu.copyTextToClipboard(u);g.ok?(m(!0),q.success(n("aboutDialog.toast.diagnosticsCopied"))):q.error(n("aboutDialog.toast.copyFailed"),{description:g.error})}catch(g){q.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",g)}finally{d(!1)}}},[u,c,n]);l.useEffect(()=>{if(!t)return;(async()=>{try{const w=await fetch("/api/system/info");if(w.ok){const y=await w.json();if(typeof y.openchamberVersion=="string"&&y.openchamberVersion.trim()){i(y.openchamberVersion);return}}}catch{}i(await Fy())})()},[t]),l.useEffect(()=>{if(!t)return;let g=!1;return(async()=>{try{const y=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!y.ok)return;const S=await y.json().catch(()=>null),D=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!g&&D&&o(D)}catch{}})(),()=>{g=!0}},[t]),l.useEffect(()=>{if(!t){f(null),h(!1);return}let g=!1;return h(!0),Nu.buildDiagnosticsReport().then(w=>{g||f(w)}).catch(w=>{g||(console.error("Failed to prepare diagnostics:",w),f(null))}).finally(()=>{g||h(!1)}),()=>{g=!0}},[t]);const x=r;return s.jsx(ws,{open:t,onOpenChange:e,children:s.jsx(vs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(Cd,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[x&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:x})}),a&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:a})})]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:v,disabled:c||b||!u,className:pe("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(p?"aboutDialog.actions.diagnosticsCopied":b?"aboutDialog.actions.preparingDiagnostics":"aboutDialog.actions.copyDiagnostics")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("aboutDialog.diagnosticsDescription")})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(C,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(C,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(C,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},Mc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},B6=(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},_6=()=>{const t=Cn(a=>a.completeAuth),[e,n]=l.useState("working"),[r,i]=l.useState("Completing MCP authorization...");return l.useEffect(()=>{if(typeof window>"u"){n("error"),i("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),o=Mc(a,"code"),c=qf(a),d=$d(a),p=Mc(a,"error"),m=Mc(a,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),i(m??p);return}(async()=>{try{if(!o)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let u=c;if(!u&&d){const f=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(f.ok){const b=await f.json().catch(()=>null);b?.name?.trim()&&(u={name:b.name.trim(),directory:typeof b.directory=="string"&&b.directory.trim()?b.directory.trim():null})}}if(!u?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(u.name,o,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),i("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"),i(B6(u,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(ve,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},uh="opencode-update-available",Ro="opencode-upgrade-progress",V6=5e3,z6=[1e4,6e4],mh=()=>{const{t}=mt(),e=$e.useRef(new Set),n=$e.useRef(!1),r=$e.useCallback(()=>{q.dismiss(Ro),ni({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=$e.useCallback(async()=>{if(!n.current){n.current=!0,q.dismiss(uh),q.message(t("opencodeUpdate.toast.upgrading.title"),{id:Ro,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(C,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const a=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),o=await a.json().catch(()=>null);if(!a.ok||o?.success===!1)throw new Error(o?.error||a.statusText||t("opencodeUpdate.toast.failed.description"));q.success(t("opencodeUpdate.toast.updated.title"),{id:Ro,description:o?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:o.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(C,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(a){q.error(t("opencodeUpdate.toast.failed.title"),{id:Ro,description:a instanceof Error?a.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{n.current=!1}}},[r,t]);return $e.useEffect(()=>{const a=m=>{m&&(e.current.has(m)||(e.current.add(m),q.info(t("opencodeUpdate.toast.available.title"),{id:uh,description:t("opencodeUpdate.toast.available.description",{version:m}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i}})))},o=m=>{const u=typeof m.detail?.version=="string"?String(m.detail.version).trim():"";a(u)};let c=!1;const d=[],p=async m=>{try{const u=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!u.ok)throw new Error(u.statusText||"OpenCode upgrade status check failed");const f=await u.json().catch(()=>null),b=typeof f?.latestVersion=="string"?f.latestVersion.trim():"";!c&&f?.available===!0&&b&&a(b)}catch{const u=z6[m];!c&&u!==void 0&&d.push(setTimeout(()=>{p(m+1)},u))}};return d.push(setTimeout(()=>{p(0)},V6)),window.addEventListener("openchamber:opencode-update-available",o),()=>{c=!0;for(const m of d)clearTimeout(m);window.removeEventListener("openchamber:opencode-update-available",o)}},[i,t]),null},ph=Kr(()=>wr(()=>import("./OnboardingScreen-BhozUlcE.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),U6=()=>{const t=rt.c(3),e=Me(J6),n=Me(Q6);let r;return t[0]!==e||t[1]!==n?(r=s.jsx($6,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},W6=t=>{const e=rt.c(21),{onRetry:n,isRetrying:r}=t,{t:i}=mt();let a;e[0]!==i?(a=i("startup.initRecovery.title"),e[0]=i,e[1]=a):a=e[1];let o;e[2]!==a?(o=s.jsx("h1",{className:"typography-title text-foreground",children:a}),e[2]=a,e[3]=o):o=e[3];let c;e[4]!==i?(c=i("startup.initRecovery.description"),e[4]=i,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]!==i?(m=i(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=i,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(ve,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let f;return e[18]!==p||e[19]!==u?(f=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[p,u]})}),e[18]=p,e[19]=u,e[20]=f):f=e[20],f},K6=()=>{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"),i=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:i}},H6=()=>typeof window>"u"?!1:window.location.pathname===Gf,G6=t=>{const e=rt.c(7),{embeddedSessionChat:n,isVSCodeRuntime:r}=t,i=to(),a=Ht(Y6),o=Ht(X6);let c,d;return e[0]!==a||e[1]!==n||e[2]!==r||e[3]!==i||e[4]!==o?(c=()=>{!n||r||a!==n.sessionId&&i.some(p=>p.id===n.sessionId)&&o(n.sessionId)},d=[a,n,r,i,o],e[0]=a,e[1]=n,e[2]=r,e[3]=i,e[4]=o,e[5]=c,e[6]=d):(c=e[5],d=e[6]),l.useEffect(c,d),null};function q6({apis:t}){const e=yt(F=>F.initializeApp),n=yt(F=>F.isInitialized),r=yt(F=>F.isConnected),i=yt(F=>F.providers.length),a=yt(F=>F.agents.length),o=yt(F=>F.loadProviders),c=yt(F=>F.loadAgents),d=Ht(F=>F.error),p=Ht(F=>F.clearError),m=Ws(F=>F.currentDirectory),u=Ws(F=>F.setDirectory),f=Ws(F=>F.isSwitchingDirectory),[b,h]=l.useState(!1),v=Kn(F=>F.refreshStatus),[x,g]=l.useState(()=>t.runtime.isVSCode),[w,y]=l.useState(!0),[S,D]=l.useState(!1),[j,I]=l.useState(0),[A,E]=l.useState(!1),P=Me(F=>F.wideChatLayoutEnabled),k=Me(F=>F.mobileKeyboardMode),N=l.useMemo(()=>wn(),[]),T=vd(F=>F.setPlanModeEnabled),[M,R]=l.useState(()=>gd()),[L,O]=l.useState(()=>{const F=dh();return F!==null?ch({isDesktopShell:!0,bootOutcome:F}):null}),V=l.useRef(!1),$=l.useMemo(()=>K6(),[]),B=!$||w,H=l.useMemo(()=>H6(),[]);l.useEffect(()=>(Su(b),()=>{Su(!1)}),[b]),l.useEffect(()=>{Ly(k)},[k]),l.useEffect(()=>{g(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",P),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[P]),l.useEffect(()=>(ku(t),()=>ku(null)),[t]),l.useEffect(()=>{$||v(t.github,{force:!0})},[t.github,$,v]),Oy();const _=M==="valid",se=L?.screen==="main";l.useEffect(()=>{if(!R6({isDesktopShell:N,isInitialized:n,bootOutcomeKnown:_,bootViewIsMain:se}))return;const F=setTimeout(()=>{const z=document.getElementById("initial-loading");z&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},150);return()=>clearTimeout(F)},[N,n,_,se]),l.useEffect(()=>{if(!N||M!=="malformed")return;const F=document.getElementById("initial-loading");F&&(F.textContent="Desktop startup failed — please restart the app.")},[N,M]),l.useEffect(()=>{if(N)return;const F=setTimeout(()=>{const z=document.getElementById("initial-loading");z&&!n&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},5e3);return()=>clearTimeout(F)},[N,n]),l.useEffect(()=>{let F=!1;return(async()=>{const Q=await fetch("/health",{method:"GET"}).catch(()=>null);if(!Q||!Q.ok||F)return;const re=await Q.json().catch(()=>null);if(!re||F)return;const K=re.planModeExperimentalEnabled;T(K===!0||K===1||K==="1"||K==="true")})(),()=>{F=!0}},[T]),l.useEffect(()=>{x||e()},[e,x]),l.useEffect(()=>{if(x||n)return;let F=!0,z,Q=0;const re=10,K=1e3,le=async()=>{if(!F)return;if(Q>=re){D(!0);return}const Se=yt.getState();if(Se.isInitialized){D(!1);return}Q+=1,await Se.initializeApp();const ue=yt.getState();if(!F)return;if(ue.isInitialized){D(!1);return}if(Q>=re){D(!0);return}const je=Math.min(K*Math.pow(2,Q-1),16e3);z=setTimeout(le,je)};return z=setTimeout(le,K),()=>{F=!1,z&&clearTimeout(z)}},[j,n,x]),l.useEffect(()=>{n&&D(!1)},[n]),l.useEffect(()=>{if(!S)return;const F=document.getElementById("initial-loading");F&&(F.classList.add("fade-out"),setTimeout(()=>{F.remove()},300))},[S]),l.useEffect(()=>{if(x||!r||i>0&&a>0)return;let F=!0,z=0;const Q=15,re=async()=>{const le=yt.getState();if(!(le.providers.length>0&&le.agents.length>0))try{le.providers.length===0&&await o(),yt.getState().agents.length===0&&await c()}catch{}};re();const K=setInterval(()=>{if(F){if(++z>=Q){clearInterval(K);return}re()}},2e3);return()=>{F=!1,clearInterval(K)}},[r,x,c,o,i,a]),l.useEffect(()=>{f||x||r&&In.setDirectory(m)},[m,f,r,x]),l.useEffect(()=>{if(!$||typeof window>"u")return;const F=re=>{const K=re?.visible===!0;y(K)},z=re=>{if(re.origin!==window.location.origin)return;const K=re.data;K?.type==="openchamber:embedded-visibility"&&F(K.payload)},Q=window;return Q.__openchamberSetEmbeddedVisibility=F,window.addEventListener("message",z),()=>{window.removeEventListener("message",z),Q.__openchamberSetEmbeddedVisibility===F&&delete Q.__openchamberSetEmbeddedVisibility}},[$]),l.useEffect(()=>{!$?.directory||x||m!==$.directory&&u($.directory,{showOverlay:!1})},[m,$,x,u]),l.useEffect(()=>{if(!$||typeof window>"u")return;const F=z=>{z.storageArea===window.localStorage&&z.key==="ui-store"&&Me.persist.rehydrate()};return window.addEventListener("storage",F),()=>{window.removeEventListener("storage",F)}},[$]),l.useEffect(()=>{if(typeof window>"u")return;const F=z=>{const Q=z.detail,re=typeof Q?.sessionId=="string"?Q.sessionId.trim():"";if(!re)return;const K=typeof Q?.directory=="string"&&Q.directory.trim().length>0?Q.directory.trim():null;Me.getState().setActiveMainTab("chat"),Ht.getState().setCurrentSession(re,K)};return window.addEventListener("openchamber:open-session",F),()=>window.removeEventListener("openchamber:open-session",F)},[]),l.useEffect(()=>{if(typeof window>"u")return;const F=z=>{const Q=z.detail,re=typeof Q?.directory=="string"&&Q.directory.trim().length>0?Q.directory.trim():null,K=typeof Q?.projectId=="string"&&Q.projectId.trim().length>0?Q.projectId.trim():null;Me.getState().setActiveMainTab("chat"),Me.getState().setSessionSwitcherOpen(!1),Ht.getState().openNewSessionDraft({selectedProjectId:K,directoryOverride:re,preserveDirectoryOverride:!!re})};return window.addEventListener("openchamber:open-draft-session",F),()=>window.removeEventListener("openchamber:open-draft-session",F)},[]),l.useEffect(()=>{if(typeof window>"u")return;const F=z=>{const Q=z.detail,re=typeof Q?.projectPath=="string"?Q.projectPath.trim():"";if(!re)return;const K=Es.getState(),le=K.projects.find(Se=>Se.path===re);le?K.setActiveProject(le.id):K.addProject(re)};return window.addEventListener("openchamber:open-project",F),()=>window.removeEventListener("openchamber:open-project",F)},[]),l.useEffect(()=>{typeof window>"u"||!n||f||V.current||(V.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,f]),$y({enabled:B}),T6(),By(),D6();const oe=l.useCallback(()=>{h(F=>!F)},[]);g6(oe),l.useEffect(()=>{if($)return;const F=z=>{wd(z)&&z.shiftKey&&!z.altKey&&(z.code==="KeyD"||z.key.toLowerCase()==="d")&&(z.preventDefault(),h(re=>!re))};return window.addEventListener("keydown",F,!0),()=>window.removeEventListener("keydown",F,!0)},[$]),l.useEffect(()=>{$||d&&setTimeout(()=>p(),5e3)},[p,$,d]),l.useEffect(()=>{if(!N||M!=="not-injected")return;let F=!1,z=0;const Q=200,re=2e3,K=50,le=()=>{if(F)return;z++;const Se=gd();if(Se!=="not-injected"){if(F=!0,R(Se),Se==="valid"){const je=dh();je&&O(ch({isDesktopShell:!0,bootOutcome:je}))}return}const ue=Math.min(Q*Math.pow(1.1,z),re);if(z>=K){const je=document.getElementById("initial-loading");je&&!je.textContent?.includes("taking longer")&&(je.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(le,ue)};return window.setTimeout(le,Q),()=>{F=!0}},[N,M]);const ae=l.useCallback(async()=>{if(F6({isTauriShell:ka(),isDesktopLocalOriginActive:Ur()})){await _h();return}window.location.reload()},[]),ne=l.useCallback(async()=>{if(!A){D(!1),E(!0);try{await yt.getState().initializeApp()}finally{E(!1)}yt.getState().isInitialized||I(F=>F+1)}},[A]),xe=F=>{if(F.screen==="recovery")return F.variant};if(N&&L&&L.screen!=="main"){if(L.screen==="chooser")return s.jsx(Ys,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(ph,{mode:"first-launch",onCliAvailable:ae,onChooseRemote:()=>{}})})})});const F=xe(L),z=L.screen==="recovery"&&"url"in L?L.url:void 0;return s.jsx(Ys,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(ph,{mode:"recovery",recoveryVariant:F,recoveryHostUrl:z,recoveryHostLabel:void 0,onCliAvailable:ae})})})})}if($)return s.jsx(Ys,{children:s.jsx(Cu,{sdk:In.getSdkClient(),directory:m||"",children:s.jsx(Iu,{apis:t,children:s.jsx(Pu,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(G6,{embeddedSessionChat:$,isVSCodeRuntime:x}),s.jsx(Au,{embeddedBackgroundWorkEnabled:B}),s.jsx(mh,{}),s.jsx(fd,{}),s.jsx(Du,{})]})})})})});if(H)return s.jsx(Ys,{children:s.jsx(_6,{})});if(S&&!n&&!x&&!$)return s.jsx(Ys,{children:s.jsx(W6,{onRetry:()=>{ne()},isRetrying:A})});const te=!n&&!N;return s.jsx(Ys,{children:s.jsx(Cu,{sdk:In.getSdkClient(),directory:m||"",children:s.jsx(Iu,{apis:t,children:s.jsx(rw,{children:s.jsx(_y,{children:s.jsx(Pu,{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(Au,{embeddedBackgroundWorkEnabled:B}),s.jsx(mh,{}),s.jsx(t6,{}),s.jsx(Du,{}),!te&&s.jsxs(s.Fragment,{children:[s.jsx(L6,{}),s.jsx(U6,{}),b&&s.jsx(r6,{onClose:()=>h(!1)})]})]})})})})})})})}function J6(t){return t.isAboutDialogOpen}function Q6(t){return t.setAboutDialogOpen}function Y6(t){return t.currentSessionId}function X6(t){return t.setCurrentSession}const Z6=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Vy();zy().then(()=>{Promise.all([Uy(),Wy()]).catch(t=>{console.error("[main] settings init failed:",t)}),Ky(),Hy(),Gy()}).catch(t=>{console.error("[main] appearance init failed:",t)});const kg=document.getElementById("root");if(!kg)throw new Error("Root element not found");mx.createRoot(kg).render(s.jsx($e.StrictMode,{children:s.jsx(qy,{children:s.jsx(Jy,{children:s.jsx(Qy,{children:s.jsx(Yy,{children:s.jsx(q6,{apis:Z6})})})})})}));const lD=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{_A as M,_o as P,Tr as S,wC as a,lD as m,dn as u};
|