@thevinci/web 1.3.1 → 1.3.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.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-DgrCmzWD.js","assets/vendor--DaW60Aqe.css","assets/HtmlEditor-D-cp1Mcb.js","assets/modelPrefsAutoSave-DEc6o6vH.js","assets/index-BW75F1_U.js","assets/index-B_msE9DC.css","assets/GitView-CRci4Kd3.js","assets/JsonTreeView-BE06CPJh.js","assets/TerminalView-Hf0MwY4N.js","assets/SettingsWindow-DabGW7z5.js","assets/MultiRunWindow-C0-pQgUW.js","assets/OnboardingScreen-ClzfZpkc.js"])))=>i.map(i=>d[i]);
2
- import{c as st,R as o,u as ji,a as Ma,j as s,b as rl,C as al,P as Ni,S as Oo,d as ng,D as $o,e as Si,f as ki,g as vn,i as qa,r as Le,k as rg,l as ag,p as $i,m as il,n as ig,o as og,q as lg,_ as Qn,s as gi,t as Bp,v as xc,W as cg,w as dg,V as ug,F as mg,x as pg,E as fg,y as Tn,z as hg,A as Ya,B as Rd,G as gg,H as xg,I as Dl,J as bg,K as yg,L as vg,M as Fd,N as Ld,O as wg,Q as Vp,T as Up,U as jg,X as Od,Y as Ng,Z as Sg,$ as kg,a0 as Cg,a1 as Pg,a2 as Ig,a3 as Dg,a4 as Kp,a5 as Tg,a6 as bc,a7 as Wp,a8 as Hp,a9 as Pa,aa as ui,ab as yc,ac as nt,ad as Gp,ae as qp,af as Ag,ag as Eg,ah as Mg,ai as Rg,aj as Qc,ak as ua,al as wr,am as Fg,an as Lg,ao as Og,ap as $g,aq as _g,ar as zg,as as $d,at as _d,au as Tl,av as Bg}from"./vendor-.bun-DgrCmzWD.js";import{a as Vg,b as Ug,f as Kg}from"./index-BW75F1_U.js";import{u as ct,a as De,b as _s,c as de,I as D,r as Wg,d as Hg,e as Gg,f as rs,i as Ks,g as nr,h as Vr,s as Al,j as El,k as Ml,l as es,o as Bs,m as Ns,T as Tt,n as At,p as Rt,q as Yp,t as zd,v as qg,w as Yg,x as Bd,y as Qg,z as Jg,A as Xg,B as Zg,C as wn,D as Us,E as Yn,F as vc,G as te,H as ys,J as vs,K as ws,L as vt,M as Ys,N as Ft,O as bs,P as hs,Q as jt,R as ve,S as Is,U as os,V as ls,W as In,X as xi,Y as ex,Z as ht,_ as tx,$ as Qp,a0 as bi,a1 as Jp,a2 as zn,a3 as Jc,a4 as ol,a5 as sx,a6 as nx,a7 as rx,a8 as ax,a9 as Xp,aa as Xc,ab as _o,ac as Zp,ad as ll,ae as Ar,af as Zc,ag as jo,ah as ix,ai as As,aj as ef,ak as ox,al as ts,am as hr,an as _a,ao as lx,ap as tf,aq as _i,ar as cx,as as dx,at as Ji,au as Ur,av as sf,aw as nf,ax as ed,ay as ux,az as rf,aA as Vd,aB as Ud,aC as nn,aD as ss,aE as mx,aF as jr,aG as cl,aH as td,aI as sd,aJ as nd,aK as dl,aL as sn,aM as dr,aN as An,aO as af,aP as zo,aQ as Ss,aR as ca,aS as ul,aT as Ia,aU as za,aV as Ba,aW as Kd,aX as Bo,aY as Vo,aZ as Ci,a_ as Pi,a$ as yn,b0 as of,b1 as lf,b2 as gr,b3 as cf,b4 as px,b5 as Ii,b6 as Va,b7 as Wd,b8 as rr,b9 as fx,ba as Hd,bb as hx,bc as gx,bd as xx,be as bx,bf as yx,bg as Rl,bh as Gd,bi as Ua,bj as Uo,bk as ml,bl as df,bm as vx,bn as wx,bo as zi,bp as jx,bq as rd,br as Nx,bs as Da,bt as Di,bu as uf,bv as Qt,bw as Jt,bx as as,by as Xt,bz as Ct,bA as Ka,bB as mf,bC as Sx,bD as kx,bE as ad,bF as Kr,bG as Ra,bH as Cx,bI as Px,bJ as Ix,bK as Dx,bL as Tx,bM as Ax,bN as aa,bO as pl,bP as Bi,bQ as Vi,bR as wc,bS as pf,bT as id,bU as ff,bV as Ti,bW as Ex,bX as Mx,bY as Rx,bZ as Fx,b_ as Lx,b$ as ia,c0 as Fl,c1 as qd,c2 as Ox,c3 as $x,c4 as _x,c5 as zx,c6 as Sa,c7 as Ll,c8 as Bx,c9 as Yd,ca as oa,cb as Vx,cc as Qd,cd as Jd,ce as Xd,cf as Zd,cg as No,ch as eu,ci as Ux,cj as Kx,ck as Wx,cl as Hx,cm as Ol,cn as tu,co as Gx,cp as qx,cq as Yx,cr as Qx,cs as Jx,ct as $l,cu as Xx,cv as su,cw as mi,cx as Zx,cy as hf,cz as eb,cA as ka,cB as tb,cC as nu,cD as sb,cE as nb,cF as gf,cG as Xi,cH as So,cI as rb,cJ as xf,cK as ab,cL as ib,cM as ru,cN as au,cO as bf,cP as yf,cQ as vf,cR as _l,cS as Zi,cT as fl,cU as ob,cV as lb,cW as cb,cX as db,cY as wf,cZ as jf,c_ as Nf,c$ as jc,d0 as od,d1 as ub,d2 as Zt,d3 as Ai,d4 as Wa,d5 as Fa,d6 as iu,d7 as Pn,d8 as mb,d9 as yi,da as Sf,db as pb,dc as ld,dd as kf,de as fb,df as hb,dg as gb,dh as xb,di as bb,dj as ou,dk as yb,dl as vb,dm as wb,dn as jb,dp as Nb,dq as Sb,dr as kb,ds as Cb,dt as Pb,du as Ib,dv as Db,dw as zl,dx as Tb,dy as Cf,dz as Ab,dA as Eb,dB as Mb,dC as Rb,dD as Fb,dE as Lb,dF as Ob,dG as $b,dH as _b,dI as zb,dJ as Bb,dK as Vb,dL as Ub,dM as lu,dN as cu,dO as Kb,dP as Wb,dQ as Hb,dR as Gb,dS as Pf,dT as qb,dU as Yb,dV as Qb,dW as Jb,dX as Mr,dY as Xb,dZ as du,d_ as Zb,d$ as ko,e0 as Co,e1 as ey,e2 as ty,e3 as sy,e4 as ny,e5 as uu,e6 as ry,e7 as mu,e8 as ay,e9 as pu,ea as iy,eb as oy,ec as ly,ed as fu,ee as hu,ef as gu,eg as cy,eh as If,ei as Df,ej as dy,ek as uy,el as my,em as py,en as fy,eo as hy,ep as gy,eq as xy,er as by,es as yy,et as vy}from"./modelPrefsAutoSave-DEc6o6vH.js";import{J as wy}from"./JsonTreeView-BE06CPJh.js";const jy=({transform:t})=>({...t,y:0}),Ny=t=>{const e=st.c(18),{id:n,children:r,className:a}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:l,listeners:u,setNodeRef:d,transform:f,transition:m,isDragging:c}=rl(i);let p;e[2]!==f?(p=al.Transform.toString(f),e[2]=f,e[3]=p):p=e[3];let g;e[4]!==p||e[5]!==m?(g={transform:p,transition:m},e[4]=p,e[5]=m,e[6]=g):g=e[6];const h=c&&"opacity-50";let x;e[7]!==a||e[8]!==h?(x=de("h-full rounded-md",a,h),e[7]=a,e[8]=h,e[9]=x):x=e[9];let w;return e[10]!==l||e[11]!==r||e[12]!==n||e[13]!==u||e[14]!==d||e[15]!==g||e[16]!==x?(w=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:g,className:x,...l,...u,children:r}),e[10]=l,e[11]=r,e[12]=n,e[13]=u,e[14]=d,e[15]=g,e[16]=x,e[17]=w):w=e[17],w},Sy=t=>{const e=st.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=de("h-full",a),e[0]=a,e[1]=i):i=e[1];let l;return e[2]!==r||e[3]!==n||e[4]!==i?(l=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=l):l=e[5],l},ur=t=>{const e=st.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:l,layoutMode:u,variant:d,activePillInsetClassName:f,activePillButtonClassName:m,inactiveTabsIconOnly:c,iconOnlyActiveTab:p,animateActivePill:g,activePillLowercase:h,className:x}=t,w=u===void 0?"scrollable":u,b=d===void 0?"default":d,y=c===void 0?!1:c,v=p===void 0?!1:p,S=h===void 0?!0:h,{t:I}=ct(),j=De(ky),{isTablet:N}=_s(),P=j||N,M=o.useRef(null);let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T={left:!1,right:!1},e[0]=T):T=e[0];const[E,k]=o.useState(T);let C;e[1]!==n?(C=n.map(Cy),e[1]=n,e[2]=C):C=e[2];const A=C,F=w==="scrollable",_=b==="default",O=b==="active-pill",V=b==="animated",K=O||V,$=_,oe=K||$,L=O&&F,Y=K,ee=g??V,re=typeof l=="function",fe=re?Ny:Sy;let ge;e[3]===Symbol.for("react.memo_cache_sentinel")?(ge=new Map,e[3]=ge):ge=e[3];const be=o.useRef(ge),[z,B]=o.useState(null);let Q;e[4]===Symbol.for("react.memo_cache_sentinel")?(Q={activationConstraint:{distance:8}},e[4]=Q):Q=e[4];const X=ji(Ma(Ni,Q)),ie=Py;let le;e[5]===Symbol.for("react.memo_cache_sentinel")?(le=(Ge,me)=>{if(me){be.current.set(Ge,me);return}be.current.delete(Ge)},e[5]=le):le=e[5];const ye=le;let W;e[6]!==r||e[7]!==oe?(W=()=>{if(!oe||!r){B(Iy);return}const Ge=M.current,me=be.current.get(r);if(!Ge||!me){B(Dy);return}let Ke=0,ze=0,tt=me;for(;tt&&tt!==Ge;)Ke=Ke+tt.offsetLeft,ze=ze+tt.offsetTop,tt=tt.offsetParent;const it={left:Ke,top:ze,width:me.offsetWidth,height:me.offsetHeight};B(qe=>ie(qe,it)?qe:it)},e[6]=r,e[7]=oe,e[8]=W):W=e[8];const ue=W;let ae;e[9]!==F?(ae=()=>{if(!F){k({left:!1,right:!1});return}const Ge=M.current;if(!Ge){k({left:!1,right:!1});return}k({left:Ge.scrollLeft>2,right:Ge.scrollLeft+Ge.clientWidth<Ge.scrollWidth-2})},e[9]=F,e[10]=ae):ae=e[10];const U=ae;let G;e[11]!==F||e[12]!==U?(G=()=>{if(!F){k({left:!1,right:!1});return}const Ge=M.current;if(!Ge)return;U(),Ge.addEventListener("scroll",U,{passive:!0});const me=new ResizeObserver(U);return me.observe(Ge),()=>{Ge.removeEventListener("scroll",U),me.disconnect()}},e[11]=F,e[12]=U,e[13]=G):G=e[13];let ne;e[14]!==F||e[15]!==n.length||e[16]!==U?(ne=[F,n.length,U],e[14]=F,e[15]=n.length,e[16]=U,e[17]=ne):ne=e[17],o.useEffect(G,ne);let se;e[18]!==r||e[19]!==ue||e[20]!==oe?(se=()=>{if(!oe){B(null);return}ue();const Ge=M.current;if(!Ge)return;const me=new ResizeObserver(ue);if(me.observe(Ge),r){const Ke=be.current.get(r);Ke&&me.observe(Ke)}return()=>{me.disconnect()}},e[18]=r,e[19]=ue,e[20]=oe,e[21]=se):se=e[21];let xe;e[22]!==r||e[23]!==n.length||e[24]!==ue||e[25]!==oe?(xe=[r,n.length,ue,oe],e[22]=r,e[23]=n.length,e[24]=ue,e[25]=oe,e[26]=xe):xe=e[26],o.useEffect(se,xe);let Se;e[27]!==ue?(Se=()=>{ue()},e[27]=ue,e[28]=Se):Se=e[28],o.useLayoutEffect(Se);let je;e[29]!==r||e[30]!==F||e[31]!==U?(je=()=>{if(!F||!r)return;const Ge=M.current;if(!Ge)return;const me=window.requestAnimationFrame(()=>{const Ke=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),ze=Ge.querySelector(`[data-sortable-tab-id="${Ke}"]`);ze&&(ze.scrollIntoView({block:"nearest",inline:"nearest"}),U())});return()=>{window.cancelAnimationFrame(me)}},e[29]=r,e[30]=F,e[31]=U,e[32]=je):je=e[32];let Ie;e[33]!==r||e[34]!==F||e[35]!==n.length||e[36]!==U?(Ie=[r,F,n.length,U],e[33]=r,e[34]=F,e[35]=n.length,e[36]=U,e[37]=Ie):Ie=e[37],o.useEffect(je,Ie);let Oe;e[38]!==l?(Oe=Ge=>{if(!l)return;const{active:me,over:Ke}=Ge;!Ke||me.id===Ke.id||l(String(me.id),String(Ke.id))},e[38]=l,e[39]=Oe):Oe=e[39];const Ne=Oe;let he;e[40]!==x?(he=de("relative flex h-full min-w-0 flex-1",x),e[40]=x,e[41]=he):he=e[41];let Fe;e[42]!==F||e[43]!==E||e[44]!==K?(Fe=F&&E.left?s.jsx("div",{className:de("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",K?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=F,e[43]=E,e[44]=K,e[45]=Fe):Fe=e[45];let Be;e[46]!==F||e[47]!==E||e[48]!==K?(Be=F&&E.right?s.jsx("div",{className:de("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",K?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=F,e[47]=E,e[48]=K,e[49]=Be):Be=e[49];const q=K?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Pe=K&&"@container/pill-tabs",$e=K&&"pill-tabs__track",Ce=K&&(f??"gap-0.5 py-0.5"),pe=$&&"items-center overflow-y-hidden",R=Y&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_2%,transparent)] p-0.5 gap-0.5",J=F?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let H;e[50]!==q||e[51]!==Pe||e[52]!==$e||e[53]!==Ce||e[54]!==pe||e[55]!==R||e[56]!==J?(H=de("relative flex h-full min-w-0 flex-1",q,Pe,$e,Ce,pe,R,J),e[50]=q,e[51]=Pe,e[52]=$e,e[53]=Ce,e[54]=pe,e[55]=R,e[56]=J,e[57]=H):H=e[57];let Ee;e[58]!==F?(Ee=F?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=F,e[59]=Ee):Ee=e[59];let Ae;e[60]!==I?(Ae=I("sortableTabsStrip.aria.tabs"),e[60]=I,e[61]=Ae):Ae=e[61];let Je;e[62]!==z||e[63]!==ee||e[64]!==K?(Je=K&&z?s.jsx("div",{className:de("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(${z.left}px, ${z.top}px, 0)`,width:`${z.width}px`,height:`${z.height}px`,transition:ee?"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]=z,e[63]=ee,e[64]=K,e[65]=Je):Je=e[65];let ce;e[66]!==z||e[67]!==$?(ce=$&&z?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(${z.left}px, 0, 0)`,width:`${z.width}px`},"aria-hidden":!0}):null,e[66]=z,e[67]=$,e[68]=ce):ce=e[68];let _e;if(e[69]!==fe||e[70]!==r||e[71]!==m||e[72]!==S||e[73]!==P||e[74]!==v||e[75]!==y||e[76]!==O||e[77]!==j||e[78]!==F||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==L||e[83]!==K){let Ge;e[85]!==fe||e[86]!==r||e[87]!==m||e[88]!==S||e[89]!==P||e[90]!==v||e[91]!==y||e[92]!==O||e[93]!==j||e[94]!==F||e[95]!==i||e[96]!==a||e[97]!==L||e[98]!==K?(Ge=me=>{const Ke=me.id===r,ze=y&&K&&!Ke&&!!me.icon,tt=!ze,it=!!me.icon&&(!v||Ke),qe=y&&K&&Ke&&!F&&!L,Ze=me.closable!==!1&&!!i,Xe=Ze&&!!me.icon,mt=F||L?void 0:K?qe?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",wt=Ze?dt=>{dt.button===1&&(dt.preventDefault(),dt.stopPropagation(),i?.(me.id))}:void 0,Et=Ze?Ty:void 0;return s.jsx(fe,{id:me.id,className:mt,children:s.jsxs("div",{ref:dt=>ye(me.id,dt),onAuxClick:wt,onMouseDown:Et,className:de("group flex h-full min-w-0 flex-nowrap items-center",F||L?"shrink-0":K?"w-full":"w-full min-w-0",K?"relative z-10 bg-transparent":Ke?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":Ke,"aria-label":ze?me.title??me.label:void 0,onClick:()=>a(me.id),className:de(K?"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",K&&S?"lowercase":null,K&&(ze?"gap-0":"gap-1.5"),K?L?"shrink-0 whitespace-nowrap px-3 text-center":F?"max-w-56 shrink-0 px-3 text-center":ze?"px-2 !min-w-0 text-center":qe?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":F?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",K?m??(O?j?"h-[38px]":"h-[31px]":"h-7"):null,K?Ke?"text-foreground":"text-muted-foreground hover:text-foreground":null,K?"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:me.title??me.label,children:K?s.jsxs(s.Fragment,{children:[it?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:de("flex items-center justify-center transition-opacity",Xe&&(P?"opacity-0":"group-hover:opacity-0")),children:me.icon}),Xe?s.jsx("span",{role:"button",tabIndex:-1,className:de("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",P?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Ay,onClick:dt=>{dt.stopPropagation(),i?.(me.id)},"aria-label":me.closeLabel??`Close ${me.label} tab`,title:me.closeLabel??`Close ${me.label} tab`,children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,tt?s.jsx("span",{className:"animated-tabs__label truncate",children:me.label}):null]}):s.jsxs("span",{className:de("flex min-w-0 flex-nowrap items-center gap-1.5",!F&&"justify-center"),children:[it?s.jsxs("span",{className:de("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Ke?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:de("flex items-center justify-center transition-opacity",Xe&&(P?"opacity-0":"group-hover:opacity-0")),children:me.icon}),Xe?s.jsx("span",{role:"button",tabIndex:-1,className:de("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",P?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Ey,onClick:dt=>{dt.stopPropagation(),i?.(me.id)},"aria-label":me.closeLabel??`Close ${me.label} tab`,title:me.closeLabel??`Close ${me.label} tab`,children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:me.label})]})}),Ze&&!Xe?s.jsx("button",{type:"button",onPointerDown:My,onClick:dt=>{dt.stopPropagation(),i?.(me.id)},className:de("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",K?"-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",K?Ke?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Ke?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":me.closeLabel??`Close ${me.label} tab`,title:me.closeLabel??`Close ${me.label} tab`,children:s.jsx(D,{name:"close",className:"h-3 w-3"})}):null]})},me.id)},e[85]=fe,e[86]=r,e[87]=m,e[88]=S,e[89]=P,e[90]=v,e[91]=y,e[92]=O,e[93]=j,e[94]=F,e[95]=i,e[96]=a,e[97]=L,e[98]=K,e[99]=Ge):Ge=e[99],_e=n.map(Ge),e[69]=fe,e[70]=r,e[71]=m,e[72]=S,e[73]=P,e[74]=v,e[75]=y,e[76]=O,e[77]=j,e[78]=F,e[79]=n,e[80]=i,e[81]=a,e[82]=L,e[83]=K,e[84]=_e}else _e=e[84];let et;e[100]!==H||e[101]!==Ee||e[102]!==Ae||e[103]!==Je||e[104]!==ce||e[105]!==_e?(et=s.jsxs("div",{ref:M,className:H,style:Ee,role:"tablist","aria-label":Ae,children:[Je,ce,_e]}),e[100]=H,e[101]=Ee,e[102]=Ae,e[103]=Je,e[104]=ce,e[105]=_e,e[106]=et):et=e[106];let Me;e[107]!==he||e[108]!==Fe||e[109]!==Be||e[110]!==et?(Me=s.jsxs("div",{className:he,children:[Fe,Be,et]}),e[107]=he,e[108]=Fe,e[109]=Be,e[110]=et,e[111]=Me):Me=e[111];const He=Me;if(!re)return He;let We;e[112]===Symbol.for("react.memo_cache_sentinel")?(We=[jy],e[112]=We):We=e[112];let Te;e[113]!==A||e[114]!==He?(Te=s.jsx(Oo,{items:A,strategy:ng,children:He}),e[113]=A,e[114]=He,e[115]=Te):Te=e[115];let Ve;e[116]===Symbol.for("react.memo_cache_sentinel")?(Ve=s.jsx($o,{dropAnimation:null}),e[116]=Ve):Ve=e[116];let Ye;return e[117]!==Ne||e[118]!==X||e[119]!==Te?(Ye=s.jsxs(Si,{sensors:X,collisionDetection:ki,onDragEnd:Ne,modifiers:We,children:[Te,Ve]}),e[117]=Ne,e[118]=X,e[119]=Te,e[120]=Ye):Ye=e[120],Ye};function ky(t){return t.isMobile}function Cy(t){return t.id}function Py(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 Iy(t){return t===null?t:null}function Dy(t){return t===null?t:null}function Ty(t){t.button===1&&t.preventDefault()}function Ay(t){t.stopPropagation()}function Ey(t){t.stopPropagation()}function My(t){t.stopPropagation()}function xu(t){const e=st.c(14);let n,r,a,i;e[0]!==t?({size:a,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);const l=typeof a=="number"?`${a}px`:a,u=typeof a=="number"?`${a}px`:a;let d;e[5]!==i||e[6]!==l||e[7]!==u?(d={width:l,height:u,...i},e[5]=i,e[6]=l,e[7]=u,e[8]=d):d=e[8];let f;e[9]===Symbol.for("react.memo_cache_sentinel")?(f=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]=f):f=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:f}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const bu={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,lastChecked:null,updateDialogOpen:!1},tr=vn()((t,e)=>({...bu,checkForUpdates:async()=>{if(!e().checking){t({checking:!0,error:null});try{const r=await Gg();if(!r){t({checking:!1,available:!1,lastChecked:Date.now()});return}t({checking:!1,available:r.available,info:r,lastChecked:Date.now()})}catch(r){t({checking:!1,error:r instanceof Error?r.message:"Update check failed",lastChecked:Date.now()})}}},downloadUpdate:async()=>{t({downloading:!0,error:null,progress:null});try{const n=await Hg(r=>{t({progress:r})});t(n?{downloading:!1,downloaded:!0}:{downloading:!1,error:"Download failed to start"})}catch(n){t({downloading:!1,error:n instanceof Error?n.message:"Download failed"})}},restartToUpdate:async()=>{try{await Wg()}catch(n){t({error:n instanceof Error?n.message:"Restart failed"})}},dismiss:()=>{t({available:!1,downloaded:!1,info:null,error:null})},reset:()=>{t(bu)},setUpdateDialogOpen:n=>{t({updateDialogOpen:n})}})),xr=[{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"}];xr.reduce((t,e)=>(t[e.id]=e,t),{});const Ry=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),Fy=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,Ei=(t,e)=>t??Fy(e),cd=(t,e)=>{if(!t)return e??"";try{const n=new Date(t);if(!Number.isFinite(n.getTime()))return e??"";const r=new Date;return n.toDateString()===r.toDateString()?n.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}):n.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit"})}catch{return e??""}},Tf=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,Ly=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},Mi=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=Ly(r)),t===null||e===null||a===null||a<=0)return null;const i=Date.now(),l=Math.max(0,(e-i)/1e3),u=Math.max(0,Math.min(a,a-l)),d=Math.max(0,Math.min(1,u/a)),f=t/100,m=t>=100&&l>0;let c;d>.01?c=Math.min(999,f/d*100):c=t;let p;m?p="exhausted":f<=d?p="on-track":c<=130?p="slightly-fast":p="too-fast";const g=a>=120*3600,h=g?86400:3600,x=g?"d":"h",w=a/h,b=Math.max(u/h,w*.01),y=t/b,v=Number.isFinite(y)?`${Math.min(999.9,Math.max(0,y)).toFixed(1)}%/${x}`:"-",S=c>100?`+${Math.round(c)}%`:`${Math.round(c)}%`;let I=null;const j=a/86400;return j>=7&&(I=100/j),{elapsedRatio:d,usageRatio:f,predictedFinalPercent:c,remainingSeconds:l,isExhausted:m,elapsedSeconds:u,totalSeconds:a,status:p,paceRateText:v,predictText:S,dailyAllocationPercent:I}},Oy=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)"}},yu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),a=Math.floor(r/24),i=r%24,l=n%60;return a>0?`${a}d ${i}h`:r>0?`${r}h`:n===0?"<1m":`${l}m`},Er=t=>Math.min(100,Math.max(0,t*100));function Ko(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 $y=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],Af={google:$y};function Ef(t,e){const n=Af[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function Mf(t){return Af[t]??[]}function Rf(t){return[...t].sort((e,n)=>e.order-n.order)}function _y(t,e){const n=new Map;for(const r of Object.keys(t)){const i=Ef(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function zy(t,e,n){const r=new Map;for(const a of t){const i=e(a),u=Ef(i,n)?.id??null;r.has(u)||r.set(u,[]),r.get(u).push(a)}return r}function By(t,e){return e.filter(n=>{const r=n.toLowerCase(),a=r.includes("/")?r.split("/")[1]:r;return!!(a.startsWith("gemini-3-")||a.startsWith("claude-"))})}const ud=6e4,vu=t=>{const e=xr.map(c=>c.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):ud,a=t?.usageDisplayMode==="remaining"?"remaining":"usage",i=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,l=i?i.filter(c=>typeof c=="string"&&e.includes(c)):e,u={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[c,p]of Object.entries(d))Array.isArray(p)&&(u[c]=p.filter(g=>typeof g=="string"));const f={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[c,p]of Object.entries(m))Array.isArray(p)&&(f[c]=p.filter(g=>typeof g=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:a,dropdownProviderIds:l,selectedModels:u,expandedFamilies:f}},Vy=async()=>{const t=nr()?.settings;if(t)try{const n=(await t.load())?.settings;return vu(n??null)}catch{}if(!Ks()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return vu(n)}}return{autoRefresh:!1,refreshIntervalMs:ud,displayMode:"usage",dropdownProviderIds:xr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},fs=vn()(qa((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:ud,displayMode:"usage",dropdownProviderIds:xr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Vy();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=xr.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:a})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),a=await r.json().catch(()=>null);if(!r.ok)throw new Error(a?.error||"Failed to fetch quota");const i=a;t(l=>{const u=l.results.filter(d=>d.providerId!==n);return u.push(i),{results:u,error:null}})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:a,usage:null,fetchedAt:Date.now()};t(l=>{const u=l.results.filter(d=>d.providerId!==n);return u.push(i),{results:u,error:a}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(a=>({selectedModels:{...a.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(a=>{const i=a.selectedModels[n]??[],u=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{selectedModels:{...a.selectedModels,[n]:u}}})},setExpandedFamilies:(n,r)=>{t(a=>({expandedFamilies:{...a.expandedFamilies,[n]:r}})),rs({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(a=>{const i=a.expandedFamilies[n]??[],u=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{expandedFamilies:{...a.expandedFamilies,[n]:u}}}),rs({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=By(n,r);i.length!==0&&(t(l=>({selectedModels:{...l.selectedModels,[n]:i}})),rs({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Ff=()=>{const t=st.c(5),e=fs(Uy),n=fs(Ky),r=fs(Wy);let a,i;t[0]!==e||t[1]!==r||t[2]!==n?(a=()=>{if(!e)return;const l=window.setInterval(()=>{r()},n);return()=>window.clearInterval(l)},i=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=a,t[4]=i):(a=t[3],i=t[4]),o.useEffect(a,i)};function Uy(t){return t.autoRefresh}function Ky(t){return t.refreshIntervalMs}function Wy(t){return t.fetchAllQuotas}const Wo=Le.forwardRef((t,e)=>{const n=st.c(11);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]!==r?(i=de("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=i):i=n[4];let l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let u;n[6]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(rg,{className:de("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]=u):u=n[6];let d;return n[7]!==a||n[8]!==e||n[9]!==i?(d=s.jsx(ag,{className:i,style:l,...a,ref:e,children:u}),n[7]=a,n[8]=e,n[9]=i,n[10]=d):d=n[10],d});Wo.displayName="Switch";const eo=()=>{try{const e=es.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=Bs.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},wu=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],ju=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},to=t=>typeof t!="string"?void 0:t.trim()||void 0,Bl=800,Hy=5e3,Gy="__default__",Nc=new Map,Vl=new Map,Lf=t=>t?.trim()||Gy,Ul=t=>{Nc.delete(Lf(t))},Ri=vn()(qa($i((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=eo(),a=Lf(r),i=Date.now(),l=Nc.get(a)??0,u=e().mcpServers.length>0;if(!n?.force&&u&&i-l<Hy)return!0;const d=Vl.get(a);if(!n?.force&&d)return d;const f=(async()=>{t({isLoading:!0});try{const m=r?`?directory=${encodeURIComponent(r)}`:"",c=await fetch(`/api/config/mcp${m}`,{headers:r?{"x-opencode-directory":r}:void 0});if(!c.ok)throw new Error("Failed to load MCP configs");const p=await c.json();return t({mcpServers:p,isLoading:!1}),Nc.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();Vl.set(a,f);try{return await f}finally{Vl.delete(a)}},createMcp:async n=>{Al("Creating MCP server configuration…");let r=!1;try{const a=Nu(n),i=eo(),l=i?`?directory=${encodeURIComponent(i)}`:"",u=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${l}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(a)}),d=await u.json().catch(()=>null);if(!u.ok)throw new Error(d?.error||"Failed to create MCP server");return Ul(i),d?.requiresReload?(r=!0,await El({message:d.message,delayMs:d.reloadDelayMs??Bl,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning})}catch(a){return console.error("[McpConfigStore] Failed to create MCP:",a),{ok:!1}}finally{r||Ml()}},updateMcp:async(n,r)=>{Al("Updating MCP server configuration…");let a=!1;try{const i=Nu(r),l=eo(),u=l?`?directory=${encodeURIComponent(l)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${u}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},body:JSON.stringify(i)}),f=await d.json().catch(()=>null);if(!d.ok)throw new Error(f?.error||"Failed to update MCP server");return Ul(l),f?.requiresReload?(a=!0,await El({message:f.message,delayMs:f.reloadDelayMs??Bl,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{a||Ml()}},deleteMcp:async n=>{Al("Deleting MCP server configuration…");let r=!1;try{const a=eo(),i=a?`?directory=${encodeURIComponent(a)}`:"",l=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:a?{"x-opencode-directory":a}:void 0}),u=await l.json().catch(()=>null);if(!l.ok)throw new Error(u?.error||"Failed to delete MCP server");return Ul(a),u?.requiresReload&&(r=!0,await El({message:u.message,delayMs:u.reloadDelayMs??Bl,scopes:["all"]})),e().selectedMcpName===n&&t({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:u?.reloadFailed===!0,message:u?.message,warning:u?.warning}}catch(a){return console.error("[McpConfigStore] Failed to delete MCP:",a),{ok:!1}}finally{r||Ml()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:il(()=>Vr()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function Nu(t){const e={};if(t.scope!==void 0&&(e.scope=t.scope),t.type!==void 0&&(e.type=t.type),(t.type==="local"||t.command!==void 0)&&(e.command=(t.command??[]).filter(n=>n.trim())),(t.type==="remote"||t.url!==void 0)&&(e.url=t.url?.trim()??""),t.environment!==void 0&&(e.environment=ju(t.environment)??{}),t.headers!==void 0&&(e.headers=ju(t.headers)??{}),t.oauthEnabled!==void 0||t.oauthClientId!==void 0||t.oauthClientSecret!==void 0||t.oauthScope!==void 0||t.oauthRedirectUri!==void 0)if(t.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:to(t.oauthClientId),clientSecret:to(t.oauthClientSecret),scope:to(t.oauthScope),redirectUri:to(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 qy={},Yy={},Tr=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},va=t=>Tr(t)??"__global__",Yr=t=>{const e=Tr(t);return e?Bs.getScopedApiClient(e):Bs.getApiClient()},qs=vn()(qa((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=va(n??Ns.getState().currentDirectory);return e().byDirectory[r]??qy},getDiagnosticForDirectory:n=>{const r=va(n??Ns.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Yy},getErrorForDirectory:n=>{const r=va(n??Ns.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Tr(n?.directory??Ns.getState().currentDirectory),a=va(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const u=(await Yr(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[a]:u},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[a]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[a]??{}).filter(([f])=>!u[f]))},loadingKeys:{...d.loadingKeys,[a]:!1},lastErrorKeys:{...d.lastErrorKeys,[a]:null}}))}catch(i){const l=i instanceof Error?i.message:"Failed to load MCP status";t(u=>({loadingKeys:{...u.loadingKeys,[a]:!1},lastErrorKeys:{...u.lastErrorKeys,[a]:l}}))}},connect:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory),i=va(a),l=Yr(a);try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(u){const d=u instanceof Error?u.message:"Connection failed";throw t(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:d}}}})),u}await e().refresh({directory:a,silent:!0})},disconnect:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory);await Yr(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory),u=(await Yr(a).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!u)throw new Error("Authorization URL was not returned");return u},completeAuth:async(n,r,a)=>{const i=Tr(a??Ns.getState().currentDirectory);await Yr(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory);await Yr(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory),i=va(a),l=Yr(a),d=e().getStatusForDirectory(a)[n]?.status==="connected";let f,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(g){f=g instanceof Error?g.message:"Connection failed",t(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:f??"Connection failed"}}}}))}await e().refresh({directory:a,silent:!0});const c=e().getStatusForDirectory(a)[n],p=c;if(!d&&c?.status==="connected"){try{await l.mcp.disconnect({name:n},{throwOnError:!0})}catch(g){m=`Connection test succeeded, but cleanup disconnect failed: ${g instanceof Error?g.message:"Disconnect failed"}`}await e().refresh({directory:a,silent:!0})}return{status:p??e().getStatusForDirectory(a)[n],error:f,warning:m}}})));function Qy(t){const e=st.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let a;return e[2]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=a):a=e[3],a}const Jy=(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}},Xy=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Of=({active:t,className:e})=>{const{t:n}=ct(),a=Ns(b=>b.currentDirectory)??null,i=qs(b=>b.getStatusForDirectory(a)),l=qs(b=>b.refresh),u=qs(b=>b.connect),d=qs(b=>b.disconnect),f=Ri(b=>b.mcpServers),m=Ri(b=>b.loadMcpConfigs),[c,p]=o.useState(!1),[g,h]=o.useState(null);o.useEffect(()=>{l({directory:a,silent:!0})},[l,a]),o.useEffect(()=>{m({force:!0})},[m]),o.useEffect(()=>{t&&Promise.all([l({directory:a,silent:!0}),m({force:!0})])},[t,l,a,m]);const x=o.useMemo(()=>{const b=new Set(Object.keys(i));for(const y of f)y?.name&&b.add(y.name);return Array.from(b).sort((y,v)=>y.localeCompare(v))},[f,i]),w=o.useCallback(b=>{if(b?.preventDefault(),c)return;p(!0);const y=new Promise(v=>setTimeout(v,500));Promise.all([l({directory:a}),y]).finally(()=>{p(!1)})},[c,l,a]);return s.jsxs("div",{className:de("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),a&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:a.split("/").pop()||a})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:c,onClick:w,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(D,{name:"refresh",className:de("h-4 w-4",c&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[x.map(b=>{const y=i[b],v=Xy(y),S=y?.status==="connected",I=g===b,j=Jy(y,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(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:de("h-2 w-2 rounded-full flex-shrink-0",v==="success"&&"bg-status-success",v==="error"&&"bg-status-error",v==="warning"&&"bg-status-warning",v==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(Rt,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:b})]})}),s.jsx(Wo,{checked:S,disabled:I,className:"data-[checked]:bg-status-info",onCheckedChange:async N=>{h(b);try{N?await u(b,a):await d(b,a)}finally{h(null)}}})]},b)}),x.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},Fi=t=>{const e=st.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let l;e[0]!==n?(l=Ry(n)??0,e[0]=n,e[1]=l):l=e[1];const u=l,d=r??n;let f;e[2]!==d?(f=Tf(d),e[2]=d,e[3]=f):f=e[3];const m=f,c=i!=null?Math.max(0,Math.min(100,i)):null;let p;e[4]!==m?(p=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=p):p=e[5];const g=p;let h;e[6]!==a?(h=de("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=h):h=e[7];const x=`${u}%`;let w;e[8]!==g||e[9]!==x?(w={...g,width:x},e[8]=g,e[9]=x,e[10]=w):w=e[10];let b;e[11]!==u||e[12]!==w?(b=s.jsx("div",{className:"h-full transition-all duration-300",style:w,role:"progressbar","aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100}),e[11]=u,e[12]=w,e[13]=b):b=e[13];let y;e[14]!==c?(y=c!=null&&c>0&&c<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${c}%`},title:`Expected usage if spread evenly: ${Math.round(c)}% of quota`,"aria-hidden":"true"}),e[14]=c,e[15]=y):y=e[15];let v;return e[16]!==h||e[17]!==b||e[18]!==y?(v=s.jsxs("div",{className:h,children:[b,y]}),e[16]=h,e[17]=b,e[18]=y,e[19]=v):v=e[19],v},Li=t=>{const e=st.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:l}=ct();let u;e[0]!==n.status?(u=Oy(n.status),e[0]=n.status,e[1]=u):u=e[1];const d=u;let f;e:{switch(n.status){case"on-track":{let N;e[2]!==l?(N=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=N):N=e[3],f=N;break e}case"slightly-fast":{let N;e[4]!==l?(N=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=N):N=e[5],f=N;break e}case"too-fast":{let N;e[6]!==l?(N=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=N):N=e[7],f=N;break e}case"exhausted":{let N;e[8]!==l?(N=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=N):N=e[9],f=N;break e}}f=void 0}const m=f;let c;e[10]!==n.predictText||e[11]!==l?(c=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=c):c=e[12];const p=c;if(i){let N;e[13]!==r?(N=de("flex items-center gap-1.5",r),e[13]=r,e[14]=N):N=e[14];let P;e[15]!==d?(P={backgroundColor:d},e[15]=d,e[16]=P):P=e[16];let M;e[17]!==m||e[18]!==P?(M=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:P,title:m}),e[17]=m,e[18]=P,e[19]=M):M=e[19];let T;e[20]!==d?(T={color:d},e[20]=d,e[21]=T):T=e[21];const E=n.isExhausted?void 0:p;let k;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(k=n.isExhausted?s.jsx(s.Fragment,{children:l("settings.usage.pace.wait",{duration:yu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:l("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=l,e[26]=k):k=e[26];let C;e[27]!==k||e[28]!==T||e[29]!==E?(C=s.jsx("span",{className:"typography-micro tabular-nums",style:T,title:E,children:k}),e[27]=k,e[28]=T,e[29]=E,e[30]=C):C=e[30];let A;return e[31]!==C||e[32]!==N||e[33]!==M?(A=s.jsxs("div",{className:N,children:[M,C]}),e[31]=C,e[32]=N,e[33]=M,e[34]=A):A=e[34],A}let g;e[35]!==r?(g=de("flex items-center justify-between gap-2",r),e[35]=r,e[36]=g):g=e[36];let h;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(h=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=l,e[40]=h):h=e[40];let x;e[41]!==h?(x=s.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[41]=h,e[42]=x):x=e[42];let w;e[43]!==d?(w={color:d},e[43]=d,e[44]=w):w=e[44];let b;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==p||e[49]!==m||e[50]!==l?(b=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:yu(n.remainingSeconds)})]}):s.jsxs("span",{title:p,children:[s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=p,e[49]=m,e[50]=l,e[51]=b):b=e[51];let y;e[52]!==w||e[53]!==b?(y=s.jsx("span",{className:"typography-micro tabular-nums",style:w,children:b}),e[52]=w,e[53]=b,e[54]=y):y=e[54];let v;e[55]!==d?(v={backgroundColor:d},e[55]=d,e[56]=v):v=e[56];let S;e[57]!==m||e[58]!==v?(S=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:v,title:m}),e[57]=m,e[58]=v,e[59]=S):S=e[59];let I;e[60]!==y||e[61]!==S?(I=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,S]}),e[60]=y,e[61]=S,e[62]=I):I=e[62];let j;return e[63]!==I||e[64]!==g||e[65]!==x?(j=s.jsxs("div",{className:g,children:[x,I]}),e[63]=I,e[64]=g,e[65]=x,e[66]=j):j=e[66],j},br=ig,yr=t=>{const e=st.c(14);let n,r,a,i;e[0]!==t?({className:a,asChild:n,children:r,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);let l;e[5]!==n||e[6]!==r?(l=n&&Le.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=l):l=e[7];const u=l;let d;e[8]!==a?(d=de("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",a),e[8]=a,e[9]=d):d=e[9];let f;return e[10]!==i||e[11]!==u||e[12]!==d?(f=s.jsx(og,{className:d,...i,...u}),e[10]=i,e[11]=u,e[12]=d,e[13]=f):f=e[13],f},vr=t=>{const e=st.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=de("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(lg,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},Zy=1e6,ev="terminal-store";let Su=!1;const Kl=t=>typeof t=="object"&&t!==null,tv=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function xn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const Wl=(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}),$f=/\x1b\[[0-9;]*m/g,sv=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,nv=new Set([".",",",";",":","!","?"]),rv=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",a=e.slice(0,-1),i=(a.match(new RegExp(`\\${r}`,"g"))||[]).length,l=(a.match(new RegExp(`\\${n}`,"g"))||[]).length;if(i>l)break;e=a;continue}if(nv.has(n)){e=e.slice(0,-1);continue}break}return e},av=t=>{if(!t)return null;const n=t.replace($f,"").match(sv);if(!n?.[1])return null;let r=rv(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},iv=t=>{if(!t)return null;const n=t.replace($f,"").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}/`},Hl=t=>({tabs:[t],activeTabId:t.id}),or=(t,e)=>t.tabs.findIndex(n=>n.id===e),Os=vn()(qa($i((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=xn(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),l=`tab-${a.nextTabId}`,u=Wl(l,"Terminal");return i.set(r,Hl(u)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=xn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=xn(n),a=e().sessions.get(r);if(!a)return;const i=a.activeTabId;return i?a.tabs.find(l=>l.id===i)??a.tabs[0]:a.tabs[0]},createTab:n=>{const r=xn(n);if(!r)return"tab-invalid";const a=`tab-${e().nextTabId}`;return t(i=>{const l=new Map(i.sessions),u=l.get(r),d=i.nextTabId+1,m=`Terminal ${(u?.tabs.length??0)+1}`,c=Wl(a,m);return u?l.set(r,{...u,tabs:[...u.tabs,c]}):l.set(r,Hl(c)),{sessions:l,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=xn(n);t(i=>{const l=new Map(i.sessions),u=l.get(a);return!u||u.activeTabId===r||or(u,r)<0?i:(l.set(a,{...u,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,a)=>{const i=xn(n),l=a.trim();l&&t(u=>{const d=new Map(u.sessions),f=d.get(i);if(!f)return u;const m=or(f,r);if(m<0||f.tabs[m]?.label===l)return u;const c=[...f.tabs];return c[m]={...c[m],label:l},d.set(i,{...f,tabs:c}),{sessions:d}})},setTabIconKey:(n,r,a)=>{const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=a?.trim()||null;if(d.tabs[f]?.iconKey===m)return l;const c=[...d.tabs];return c[f]={...c[f],iconKey:m},u.set(i,{...d,tabs:c}),{sessions:u}})},closeTab:async(n,r)=>{const a=xn(n),u=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(u)try{await Vg(u)}catch{}t(d=>{const f=new Map(d.sessions),m=f.get(a);if(!m)return d;const c=or(m,r);if(c<0)return d;const p=m.tabs.filter(w=>w.id!==r),g=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,w])=>!(w.directory===a&&w.tabId===r))),h=Object.keys(g).length!==Object.keys(d.projectActionRuns).length;if(p.length===0){const w=`tab-${d.nextTabId}`,b=Wl(w,"Terminal");return f.set(a,Hl(b)),{sessions:f,nextTabId:d.nextTabId+1,...h?{projectActionRuns:g}:{}}}let x=m.activeTabId;return m.activeTabId===r&&(x=p[Math.min(c,p.length-1)]?.id??p[0]?.id??null),f.set(a,{...m,tabs:p,activeTabId:x}),{sessions:f,...h?{projectActionRuns:g}:{}}})},setTabSessionId:(n,r,a)=>{const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=d.tabs[f],c=a!==null&&m.terminalSessionId!==a,p=a?"running":m.terminalSessionId?"exited":m.lifecycle,g={...m,terminalSessionId:a,lifecycle:p,isConnecting:!1,...c?{bufferChunks:[],bufferLength:0}:{}},h=[...d.tabs];return h[f]=g,u.set(i,{...d,tabs:h}),{sessions:u}})},setTabLifecycle:(n,r,a)=>{const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=[...d.tabs];return m[f]={...m[f],lifecycle:a,isConnecting:!1},u.set(i,{...d,tabs:m}),{sessions:u}})},setConnecting:(n,r,a)=>{const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=[...d.tabs];return m[f]={...m[f],isConnecting:a},u.set(i,{...d,tabs:m}),{sessions:u}})},appendToBuffer:(n,r,a)=>{if(!a)return;const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=d.tabs[f],c=l.nextChunkId,p={id:c,data:a},g=[...m.bufferChunks,p];let h=m.bufferLength+a.length;for(;h>Zy&&g.length>1;){const y=g.shift();if(!y)break;h-=y.data.length}const x=m.previewUrlLocked?null:av(a)??iv(a),w=!!(x&&x!==m.previewUrl),b=[...d.tabs];return b[f]={...m,bufferChunks:g,bufferLength:h,...w?{previewUrl:x,previewAutoOpened:!1}:null},u.set(i,{...d,tabs:b}),{sessions:u,nextChunkId:c+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const l=xn(n);t(u=>{const d=new Map(u.sessions),f=d.get(l);if(!f)return u;const m=or(f,r);if(m<0)return u;const c=f.tabs[m],p=i.autoOpened??c.previewAutoOpened,g=i.locked??c.previewUrlLocked;if(c.previewUrl===a&&c.previewAutoOpened===p&&c.previewUrlLocked===g)return u;const h=[...f.tabs];return h[m]={...c,previewUrl:a,previewAutoOpened:p,previewUrlLocked:g},d.set(l,{...f,tabs:h}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=xn(n);t(i=>{const l=new Map(i.sessions),u=l.get(a);if(!u)return i;const d=or(u,r);if(d<0)return i;const f=u.tabs[d];if(!f.previewUrl||f.previewAutoOpened)return i;const m=[...u.tabs];return m[d]={...f,previewAutoOpened:!0},l.set(a,{...u,tabs:m}),{sessions:l}})},setProjectActionRun:n=>{t(r=>{const a=r.projectActionRuns[n.key];return a&&a.directory===n.directory&&a.actionId===n.actionId&&a.tabId===n.tabId&&a.sessionId===n.sessionId&&a.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(a=>{const i=a.projectActionRuns[n];return!i||i.status===r?a:{projectActionRuns:{...a.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const a={...r.projectActionRuns};return delete a[n],{projectActionRuns:a}})},clearBuffer:(n,r)=>{const a=xn(n);t(i=>{const l=new Map(i.sessions),u=l.get(a);if(!u)return i;const d=or(u,r);if(d<0)return i;const f=[...u.tabs];return f[d]={...f[d],bufferChunks:[],bufferLength:0},l.set(a,{...u,tabs:f}),{sessions:l}})},removeDirectory:n=>{const r=xn(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const l=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,u])=>u.directory!==r));return{sessions:i,projectActionRuns:l}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:ev,storage:il(()=>Yp()),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(!Kl(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let a=0;for(const u of n){if(!Array.isArray(u)||u.length!==2)continue;const[d,f]=u;if(typeof d!="string"||!Kl(f))continue;const m=Array.isArray(f.tabs)?f.tabs:[],c=[];for(const h of m){if(!Kl(h))continue;const x=typeof h.id=="string"?h.id:null;if(!x)continue;const w=tv(x);w!==null&&(a=Math.max(a,w));const b=typeof h.terminalSessionId=="string"||h.terminalSessionId===null?h.terminalSessionId:null,y=h.lifecycle,v=y==="idle"||y==="running"||y==="exited"?y:b?"running":"idle";c.push({id:x,label:typeof h.label=="string"?h.label:"Terminal",iconKey:typeof h.iconKey=="string"?h.iconKey:null,terminalSessionId:b,lifecycle:v,createdAt:typeof h.createdAt=="number"?h.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(c.length===0)continue;const p=typeof f.activeTabId=="string"?f.activeTabId:null,g=p?c.some(h=>h.id===p):!1;r.set(d,{tabs:c,activeTabId:g?p:c[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,l=Math.max(e.nextTabId,i,a+1);return{...e,sessions:r,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!Su){Su=!0;const t=Os.persist,e=()=>{Os.getState().hasHydrated||Os.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const ku=(t,e)=>e.updatedAtMs-t.updatedAtMs,Ts=vn((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([Jg(),Bd()]),a={};for(const i of r.sort(ku))a[i.id]=i;e().listenerReady||await Xg(i=>{t(l=>({statusesById:{...l.statusesById,[i.id]:i}}))}),t({instances:n.instances,statusesById:a,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await Qg();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await Bd(),r={};for(const a of n.sort(ku))r[a.id]=a;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await Yg({instances:n}),t({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw t({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,a=r.some(i=>i.id===n.id)?r.map(i=>i.id===n.id?n:i):[n,...r];await e().setInstances(a)},createFromCommand:async(n,r,a)=>{const i=Zg(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await zd(n).catch(()=>{});const r=e().instances.filter(a=>a.id!==n);await e().setInstances(r),t(a=>{const i={...a.statusesById};return delete i[n],{statusesById:i}})},connect:async n=>{t({error:null});try{await qg(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 zd(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})})),_f=[{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"}],Po=Object.fromEntries(_f.map(t=>[t.key,t.Icon])),Sc="vinci:project-actions-updated",zf=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},_r=(t,e)=>`${zf(t)}::${e}`,ov=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Cu=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},lv=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=Cu(e.localPort),r=Cu(e.remotePort);if(!n||!r)return null;const a=ov(e.localHost||t.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),l=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${l} - ${a}:${n} -> ${i}:${r}`,url:`http://${a}:${n}`}},Bf=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=lv(n,r);a&&e.push(a)}return e},cv=(t,e)=>{const n=(t||"").trim();return n&&Bf(e).find(i=>i.id===n)?.url||null},dv=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],uv=["dev","start","preview","serve"];async function mv(t,e,n){if(!t)return null;const r=hv(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=gv(n);if(a){const i=await xv(t);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${a}`,label:`Start (${a})`}}}if(await pv(t)){const a=await fv(),i=typeof a=="number"&&Number.isFinite(a)&&a>0?a:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function pv(t){const e=`${t}/index.html`,n=await Ho(e);return typeof n=="string"&&n.trim().length>0}async function fv(){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 hv(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(uv.some(a=>n.includes(a)))return e}return null}function gv(t){for(const{pattern:e}of dv)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function xv(t){const e=await Ho(`${t}/package.json`);if(e)try{const r=JSON.parse(e),a=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(a.startsWith("bun@"))return"bun";if(a.startsWith("pnpm@"))return"pnpm";if(a.startsWith("yarn@"))return"yarn";if(a.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,a]of n){const i=await Ho(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function Ho(t){const e=nr()?.files;if(e?.readFile)try{const n=await e.readFile(t,{optional:!0});return typeof n?.content=="string"?n.content:null}catch{return null}try{const n=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return n.ok?n.text():null}catch{return null}}async function bv(t){try{const e=await Ho(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const yv=t=>new Promise(e=>{window.setTimeout(e,t)}),vv="\x1B",wv=new RegExp(`${vv}\\[[0-9;?]*[ -/]*[@-~]`,"g"),jv=/https?:\/\/[^\s<>'"`]+/gi,Zn="__vinci_auto_discover_preview__",Nv=15e3,Sv=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},kv=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}},Cv=t=>{const n=t.replace(wv,"").match(jv);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const a=[];for(const i of r)try{const l=new URL(i);l.port&&l.port.length>0&&a.push({raw:i,parsed:l})}catch{}if(a.length>0){const i=l=>{const{parsed:u}=l,d=u.hostname.toLowerCase(),f=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=u.pathname||"/",c=m.split("/").filter(Boolean).length,p=m==="/"||m==="",g=!!(u.search||u.hash);let h=0;return f&&(h+=50),p&&(h+=30),h-=Math.min(c*5,20),g&&(h-=10),h};return a.sort((l,u)=>i(u)-i(l)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},Pv=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const a=r[0],i=r[1].slice(0,3),l=`${a} ${i}`.trim();return r.length>2||l.length<n.length?`${l}...`:l}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},Pu=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=ct(),{terminal:l,runtime:u}=wn(),{isMobile:d}=_s(),f=o.useMemo(()=>Us(),[]),m=Ts(q=>q.instances),c=Ts(q=>q.load),p=De(q=>q.setBottomTerminalOpen),g=De(q=>q.setActiveMainTab),h=De(q=>q.setSettingsPage),x=De(q=>q.setSettingsDialogOpen),w=De(q=>q.setSettingsProjectsSelectedId),b=De(q=>q.openContextPreview),y=Os(q=>q.sessions),v=Os(q=>q.ensureDirectory),S=Os(q=>q.setTabLabel),I=Os(q=>q.setTabIconKey),j=Os(q=>q.setActiveTab),N=Os(q=>q.setConnecting),P=Os(q=>q.setTabSessionId),M=Os(q=>q.setTabPreviewUrl),T=Os(q=>q.projectActionRuns),E=Os(q=>q.setProjectActionRun),k=Os(q=>q.updateProjectActionRunStatus),C=Os(q=>q.removeProjectActionRun),[A,F]=o.useState([]),[_,O]=o.useState(null),[V,K]=o.useState(!1),$=o.useRef({}),oe=o.useRef({}),L=o.useRef({}),Y=o.useRef({}),ee=o.useRef(0),re=t?.id??null,fe=t?.path??"",ge=o.useMemo(()=>re?{id:re,path:fe}:null,[re,fe]);o.useEffect(()=>{f&&c().catch(()=>{})},[f,c]);const be=o.useCallback(async q=>{await Yn(q)},[]),z=o.useCallback(async()=>{if(!ge)return;const q=ee.current+1;ee.current=q,K(!0);try{const Pe=await vc(ge);if(ee.current!==q)return;const $e=Pe.actions;F($e),O(Ce=>Ce===Zn||Ce&&$e.some(pe=>pe.id===Ce)?Ce:null)}catch{if(ee.current!==q)return}finally{ee.current===q&&K(!1)}},[ge]),B=o.useMemo(()=>zf(e||ge?.path||""),[e,ge?.path]),Q=o.useMemo(()=>_?A.find(q=>q.id===_)??null:null,[A,_]),X=o.useMemo(()=>({id:Zn,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),ie=!1,le=o.useMemo(()=>A,[A,X,ie]);o.useEffect(()=>{z()},[z]),o.useEffect(()=>{if(typeof window>"u")return;const q=Pe=>{const $e=Pe.detail;re&&($e?.projectId&&$e.projectId!==re||z())};return window.addEventListener(Sc,q),()=>{window.removeEventListener(Sc,q)}},[z,re]),o.useEffect(()=>{_&&(A.some(q=>q.id===_)||O(null))},[A,ie,_]),o.useEffect(()=>{for(const[q,Pe]of Object.entries(T)){const Ce=y.get(Pe.directory)?.tabs.find(pe=>pe.id===Pe.tabId);(!Ce||Ce.terminalSessionId!==Pe.sessionId)&&C(q)}},[T,C,y]),o.useEffect(()=>{for(const[q,Pe]of Object.entries(T)){const $e=oe.current[q]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};oe.current[q]=$e;const Ce=le.find(ce=>ce.id===Pe.actionId);if(!Ce)continue;const R=y.get(Pe.directory)?.tabs.find(ce=>ce.id===Pe.tabId);if(!R||!Array.isArray(R.bufferChunks)||R.bufferChunks.length===0)continue;const J=R.bufferChunks.filter(ce=>$e.lastSeenChunkId===null?!0:ce.id>$e.lastSeenChunkId);if(J.length===0)continue;const H=J.map(ce=>ce.data).join(""),Ee=`${$e.tail}${H}`,Ae=!$e.openedUrl&&Ce.autoOpenUrl===!0?Cv(Ee):null,Je=J[J.length-1]?.id??$e.lastSeenChunkId;if($e.lastSeenChunkId=Je,$e.tail=Ee.slice(-512),Ae)if($e.openedUrl=!0,$e.openInPreview){const ce=T[q];ce&&(M(ce.directory,ce.tabId,Ae,{locked:!1,autoOpened:!1}),ce.status==="waiting-for-preview"&&k(q,"running"),window.clearTimeout(Y.current[q]),delete Y.current[q],b(ce.directory,Ae))}else be(Ae),te.success(i("projectActions.toast.openedUrlFromOutput"));oe.current[q]=$e}for(const q of Object.keys(oe.current))T[q]||(delete oe.current[q],window.clearTimeout(Y.current[q]),delete Y.current[q])},[le,b,be,T,M,i,y,k]);const ye=o.useCallback(async(q,Pe={})=>{if(!B)throw new Error(i("projectActions.error.noActiveDirectory"));const $e=_r(B,q.id);v(B);const Ce=Os.getState(),pe=Ce.getDirectoryState(B);let R=$.current[$e]||null;const J=R?!!pe?.tabs.some(Ae=>Ae.id===R):!1;(!R||!J)&&(R=Ce.createTab(B),$.current[$e]=R),S(B,R,`Action: ${q.name}`),I(B,R,q.icon||"play"),Pe.revealTerminal!==!1&&(j(B,R),p(!0),g("terminal"));const Ee=Os.getState().getDirectoryState(B)?.tabs.find(Ae=>Ae.id===R);return{key:$e,tabId:R,sessionId:Ee?.terminalSessionId??null}},[v,B,g,j,p,I,S,i]),W=o.useCallback(async q=>{if(u.isVSCode||!a&&d)return;if(!B){te.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Pe=_r(B,q.id),$e=T[Pe];if(!($e&&$e.status==="running"))try{const Ce=q.id===Zn?await(async()=>{const[Me,He]=await Promise.all([vc({id:ge?.id??"",path:B}),bv(B)]),We=await mv(B,Me.actions,He);if(!We)throw new Error(i("contextPanel.preview.noDevServer"));return{id:Zn,name:i("projectActions.actions.autoDiscover"),command:We.command,icon:"search",autoOpenUrl:!0,openUrl:We.previewUrlHint||""}})():q,pe=Ce.autoOpenUrl===!0&&(Ce.openUrl||"").trim().length>0,{key:R,tabId:J,sessionId:H}=await ye(Ce,{revealTerminal:!pe&&q.id!==Zn});let Ee=H,Ae=!1;if(!Ee){N(B,J,!0);try{Ee=(await l.createSession({cwd:B})).sessionId,Ae=!0,P(B,J,Ee)}finally{N(B,J,!1)}}if(!Ee)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));Ae&&await yv(350),Ce.id===Zn&&(L.current[R]?.(),N(B,J,!0),L.current[R]=Ug(Ee,Me=>{Me.type==="data"&&typeof Me.data=="string"&&Me.data.length>0&&Os.getState().appendToBuffer(B,J,Me.data),Me.type==="exit"&&(Os.getState().setTabLifecycle(B,J,"exited"),Os.getState().setConnecting(B,J,!1),Os.getState().removeProjectActionRun(R),delete oe.current[R],L.current[R]?.(),delete L.current[R],window.clearTimeout(Y.current[R]),delete Y.current[R])},()=>{Os.getState().setConnecting(B,J,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Je=Ce.autoOpenUrl===!0&&f&&(Ce.desktopOpenSshForward||"").trim().length>0,ce=Ce.autoOpenUrl?kv(Ce.openUrl):null,_e=Ce.autoOpenUrl&&f?cv(Ce.desktopOpenSshForward,m):null;E({key:R,directory:B,actionId:Ce.id,tabId:J,sessionId:Ee,status:Ce.id===Zn&&!ce?"waiting-for-preview":"running"}),window.clearTimeout(Y.current[R]),delete Y.current[R],Ce.id===Zn&&!ce&&(Y.current[R]=window.setTimeout(()=>{Os.getState().updateProjectActionRunStatus(R,"running"),delete Y.current[R]},Nv)),_e?(M(B,J,null,{locked:!0}),be(_e),te.success(i("projectActions.toast.openedForwardedUrl"))):ce?(M(B,J,ce,{locked:!0,autoOpened:!0}),b(B,ce),te.success(i("projectActions.toast.openedActionUrl"))):pe?(M(B,J,null,{locked:!0}),te.error(i("projectActions.error.invalidCustomUrlFormat"))):Je?(M(B,J,null,{locked:!0}),te.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):M(B,J,null,{locked:!1,autoOpened:!1}),oe.current[R]={lastSeenChunkId:null,openedUrl:!!_e||!!ce||pe,tail:"",openInPreview:Ce.id===Zn};const et=Sv(Ce.command.trim().replace(/\r\n|\r/g,`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-DgrCmzWD.js","assets/vendor--DaW60Aqe.css","assets/HtmlEditor-DdqeDNYP.js","assets/modelPrefsAutoSave-Czz-2ruh.js","assets/index-BW75F1_U.js","assets/index-B_msE9DC.css","assets/GitView-CIXtUiY4.js","assets/JsonTreeView-nlJTFDBl.js","assets/TerminalView-JImTzVKx.js","assets/SettingsWindow-mltact69.js","assets/MultiRunWindow-Cx2CTWGK.js","assets/OnboardingScreen-C-tioywh.js"])))=>i.map(i=>d[i]);
2
+ import{c as st,R as o,u as ji,a as Ma,j as s,b as rl,C as al,P as Ni,S as Oo,d as ng,D as $o,e as Si,f as ki,g as vn,i as qa,r as Le,k as rg,l as ag,p as $i,m as il,n as ig,o as og,q as lg,_ as Qn,s as gi,t as Bp,v as xc,W as cg,w as dg,V as ug,F as mg,x as pg,E as fg,y as Tn,z as hg,A as Ya,B as Rd,G as gg,H as xg,I as Dl,J as bg,K as yg,L as vg,M as Fd,N as Ld,O as wg,Q as Vp,T as Up,U as jg,X as Od,Y as Ng,Z as Sg,$ as kg,a0 as Cg,a1 as Pg,a2 as Ig,a3 as Dg,a4 as Kp,a5 as Tg,a6 as bc,a7 as Wp,a8 as Hp,a9 as Pa,aa as ui,ab as yc,ac as nt,ad as Gp,ae as qp,af as Ag,ag as Eg,ah as Mg,ai as Rg,aj as Qc,ak as ua,al as wr,am as Fg,an as Lg,ao as Og,ap as $g,aq as _g,ar as zg,as as $d,at as _d,au as Tl,av as Bg}from"./vendor-.bun-DgrCmzWD.js";import{a as Vg,b as Ug,f as Kg}from"./index-BW75F1_U.js";import{u as ct,a as De,b as _s,c as de,I as D,r as Wg,d as Hg,e as Gg,f as rs,i as Ks,g as nr,h as Vr,s as Al,j as El,k as Ml,l as es,o as Bs,m as Ns,T as Tt,n as At,p as Rt,q as Yp,t as zd,v as qg,w as Yg,x as Bd,y as Qg,z as Jg,A as Xg,B as Zg,C as wn,D as Us,E as Yn,F as vc,G as te,H as ys,J as vs,K as ws,L as vt,M as Ys,N as Ft,O as bs,P as hs,Q as jt,R as ve,S as Is,U as os,V as ls,W as In,X as xi,Y as ex,Z as ht,_ as tx,$ as Qp,a0 as bi,a1 as Jp,a2 as zn,a3 as Jc,a4 as ol,a5 as sx,a6 as nx,a7 as rx,a8 as ax,a9 as Xp,aa as Xc,ab as _o,ac as Zp,ad as ll,ae as Ar,af as Zc,ag as jo,ah as ix,ai as As,aj as ef,ak as ox,al as ts,am as hr,an as _a,ao as lx,ap as tf,aq as _i,ar as cx,as as dx,at as Ji,au as Ur,av as sf,aw as nf,ax as ed,ay as ux,az as rf,aA as Vd,aB as Ud,aC as nn,aD as ss,aE as mx,aF as jr,aG as cl,aH as td,aI as sd,aJ as nd,aK as dl,aL as sn,aM as dr,aN as An,aO as af,aP as zo,aQ as Ss,aR as ca,aS as ul,aT as Ia,aU as za,aV as Ba,aW as Kd,aX as Bo,aY as Vo,aZ as Ci,a_ as Pi,a$ as yn,b0 as of,b1 as lf,b2 as gr,b3 as cf,b4 as px,b5 as Ii,b6 as Va,b7 as Wd,b8 as rr,b9 as fx,ba as Hd,bb as hx,bc as gx,bd as xx,be as bx,bf as yx,bg as Rl,bh as Gd,bi as Ua,bj as Uo,bk as ml,bl as df,bm as vx,bn as wx,bo as zi,bp as jx,bq as rd,br as Nx,bs as Da,bt as Di,bu as uf,bv as Qt,bw as Jt,bx as as,by as Xt,bz as Ct,bA as Ka,bB as mf,bC as Sx,bD as kx,bE as ad,bF as Kr,bG as Ra,bH as Cx,bI as Px,bJ as Ix,bK as Dx,bL as Tx,bM as Ax,bN as aa,bO as pl,bP as Bi,bQ as Vi,bR as wc,bS as pf,bT as id,bU as ff,bV as Ti,bW as Ex,bX as Mx,bY as Rx,bZ as Fx,b_ as Lx,b$ as ia,c0 as Fl,c1 as qd,c2 as Ox,c3 as $x,c4 as _x,c5 as zx,c6 as Sa,c7 as Ll,c8 as Bx,c9 as Yd,ca as oa,cb as Vx,cc as Qd,cd as Jd,ce as Xd,cf as Zd,cg as No,ch as eu,ci as Ux,cj as Kx,ck as Wx,cl as Hx,cm as Ol,cn as tu,co as Gx,cp as qx,cq as Yx,cr as Qx,cs as Jx,ct as $l,cu as Xx,cv as su,cw as mi,cx as Zx,cy as hf,cz as eb,cA as ka,cB as tb,cC as nu,cD as sb,cE as nb,cF as gf,cG as Xi,cH as So,cI as rb,cJ as xf,cK as ab,cL as ib,cM as ru,cN as au,cO as bf,cP as yf,cQ as vf,cR as _l,cS as Zi,cT as fl,cU as ob,cV as lb,cW as cb,cX as db,cY as wf,cZ as jf,c_ as Nf,c$ as jc,d0 as od,d1 as ub,d2 as Zt,d3 as Ai,d4 as Wa,d5 as Fa,d6 as iu,d7 as Pn,d8 as mb,d9 as yi,da as Sf,db as pb,dc as ld,dd as kf,de as fb,df as hb,dg as gb,dh as xb,di as bb,dj as ou,dk as yb,dl as vb,dm as wb,dn as jb,dp as Nb,dq as Sb,dr as kb,ds as Cb,dt as Pb,du as Ib,dv as Db,dw as zl,dx as Tb,dy as Cf,dz as Ab,dA as Eb,dB as Mb,dC as Rb,dD as Fb,dE as Lb,dF as Ob,dG as $b,dH as _b,dI as zb,dJ as Bb,dK as Vb,dL as Ub,dM as lu,dN as cu,dO as Kb,dP as Wb,dQ as Hb,dR as Gb,dS as Pf,dT as qb,dU as Yb,dV as Qb,dW as Jb,dX as Mr,dY as Xb,dZ as du,d_ as Zb,d$ as ko,e0 as Co,e1 as ey,e2 as ty,e3 as sy,e4 as ny,e5 as uu,e6 as ry,e7 as mu,e8 as ay,e9 as pu,ea as iy,eb as oy,ec as ly,ed as fu,ee as hu,ef as gu,eg as cy,eh as If,ei as Df,ej as dy,ek as uy,el as my,em as py,en as fy,eo as hy,ep as gy,eq as xy,er as by,es as yy,et as vy}from"./modelPrefsAutoSave-Czz-2ruh.js";import{J as wy}from"./JsonTreeView-nlJTFDBl.js";const jy=({transform:t})=>({...t,y:0}),Ny=t=>{const e=st.c(18),{id:n,children:r,className:a}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:l,listeners:u,setNodeRef:d,transform:f,transition:m,isDragging:c}=rl(i);let p;e[2]!==f?(p=al.Transform.toString(f),e[2]=f,e[3]=p):p=e[3];let g;e[4]!==p||e[5]!==m?(g={transform:p,transition:m},e[4]=p,e[5]=m,e[6]=g):g=e[6];const h=c&&"opacity-50";let x;e[7]!==a||e[8]!==h?(x=de("h-full rounded-md",a,h),e[7]=a,e[8]=h,e[9]=x):x=e[9];let w;return e[10]!==l||e[11]!==r||e[12]!==n||e[13]!==u||e[14]!==d||e[15]!==g||e[16]!==x?(w=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:g,className:x,...l,...u,children:r}),e[10]=l,e[11]=r,e[12]=n,e[13]=u,e[14]=d,e[15]=g,e[16]=x,e[17]=w):w=e[17],w},Sy=t=>{const e=st.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=de("h-full",a),e[0]=a,e[1]=i):i=e[1];let l;return e[2]!==r||e[3]!==n||e[4]!==i?(l=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=l):l=e[5],l},ur=t=>{const e=st.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:l,layoutMode:u,variant:d,activePillInsetClassName:f,activePillButtonClassName:m,inactiveTabsIconOnly:c,iconOnlyActiveTab:p,animateActivePill:g,activePillLowercase:h,className:x}=t,w=u===void 0?"scrollable":u,b=d===void 0?"default":d,y=c===void 0?!1:c,v=p===void 0?!1:p,S=h===void 0?!0:h,{t:I}=ct(),j=De(ky),{isTablet:N}=_s(),P=j||N,M=o.useRef(null);let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T={left:!1,right:!1},e[0]=T):T=e[0];const[E,k]=o.useState(T);let C;e[1]!==n?(C=n.map(Cy),e[1]=n,e[2]=C):C=e[2];const A=C,F=w==="scrollable",_=b==="default",O=b==="active-pill",V=b==="animated",K=O||V,$=_,oe=K||$,L=O&&F,Y=K,ee=g??V,re=typeof l=="function",fe=re?Ny:Sy;let ge;e[3]===Symbol.for("react.memo_cache_sentinel")?(ge=new Map,e[3]=ge):ge=e[3];const be=o.useRef(ge),[z,B]=o.useState(null);let Q;e[4]===Symbol.for("react.memo_cache_sentinel")?(Q={activationConstraint:{distance:8}},e[4]=Q):Q=e[4];const X=ji(Ma(Ni,Q)),ie=Py;let le;e[5]===Symbol.for("react.memo_cache_sentinel")?(le=(Ge,me)=>{if(me){be.current.set(Ge,me);return}be.current.delete(Ge)},e[5]=le):le=e[5];const ye=le;let W;e[6]!==r||e[7]!==oe?(W=()=>{if(!oe||!r){B(Iy);return}const Ge=M.current,me=be.current.get(r);if(!Ge||!me){B(Dy);return}let Ke=0,ze=0,tt=me;for(;tt&&tt!==Ge;)Ke=Ke+tt.offsetLeft,ze=ze+tt.offsetTop,tt=tt.offsetParent;const it={left:Ke,top:ze,width:me.offsetWidth,height:me.offsetHeight};B(qe=>ie(qe,it)?qe:it)},e[6]=r,e[7]=oe,e[8]=W):W=e[8];const ue=W;let ae;e[9]!==F?(ae=()=>{if(!F){k({left:!1,right:!1});return}const Ge=M.current;if(!Ge){k({left:!1,right:!1});return}k({left:Ge.scrollLeft>2,right:Ge.scrollLeft+Ge.clientWidth<Ge.scrollWidth-2})},e[9]=F,e[10]=ae):ae=e[10];const U=ae;let G;e[11]!==F||e[12]!==U?(G=()=>{if(!F){k({left:!1,right:!1});return}const Ge=M.current;if(!Ge)return;U(),Ge.addEventListener("scroll",U,{passive:!0});const me=new ResizeObserver(U);return me.observe(Ge),()=>{Ge.removeEventListener("scroll",U),me.disconnect()}},e[11]=F,e[12]=U,e[13]=G):G=e[13];let ne;e[14]!==F||e[15]!==n.length||e[16]!==U?(ne=[F,n.length,U],e[14]=F,e[15]=n.length,e[16]=U,e[17]=ne):ne=e[17],o.useEffect(G,ne);let se;e[18]!==r||e[19]!==ue||e[20]!==oe?(se=()=>{if(!oe){B(null);return}ue();const Ge=M.current;if(!Ge)return;const me=new ResizeObserver(ue);if(me.observe(Ge),r){const Ke=be.current.get(r);Ke&&me.observe(Ke)}return()=>{me.disconnect()}},e[18]=r,e[19]=ue,e[20]=oe,e[21]=se):se=e[21];let xe;e[22]!==r||e[23]!==n.length||e[24]!==ue||e[25]!==oe?(xe=[r,n.length,ue,oe],e[22]=r,e[23]=n.length,e[24]=ue,e[25]=oe,e[26]=xe):xe=e[26],o.useEffect(se,xe);let Se;e[27]!==ue?(Se=()=>{ue()},e[27]=ue,e[28]=Se):Se=e[28],o.useLayoutEffect(Se);let je;e[29]!==r||e[30]!==F||e[31]!==U?(je=()=>{if(!F||!r)return;const Ge=M.current;if(!Ge)return;const me=window.requestAnimationFrame(()=>{const Ke=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),ze=Ge.querySelector(`[data-sortable-tab-id="${Ke}"]`);ze&&(ze.scrollIntoView({block:"nearest",inline:"nearest"}),U())});return()=>{window.cancelAnimationFrame(me)}},e[29]=r,e[30]=F,e[31]=U,e[32]=je):je=e[32];let Ie;e[33]!==r||e[34]!==F||e[35]!==n.length||e[36]!==U?(Ie=[r,F,n.length,U],e[33]=r,e[34]=F,e[35]=n.length,e[36]=U,e[37]=Ie):Ie=e[37],o.useEffect(je,Ie);let Oe;e[38]!==l?(Oe=Ge=>{if(!l)return;const{active:me,over:Ke}=Ge;!Ke||me.id===Ke.id||l(String(me.id),String(Ke.id))},e[38]=l,e[39]=Oe):Oe=e[39];const Ne=Oe;let he;e[40]!==x?(he=de("relative flex h-full min-w-0 flex-1",x),e[40]=x,e[41]=he):he=e[41];let Fe;e[42]!==F||e[43]!==E||e[44]!==K?(Fe=F&&E.left?s.jsx("div",{className:de("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",K?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=F,e[43]=E,e[44]=K,e[45]=Fe):Fe=e[45];let Be;e[46]!==F||e[47]!==E||e[48]!==K?(Be=F&&E.right?s.jsx("div",{className:de("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",K?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=F,e[47]=E,e[48]=K,e[49]=Be):Be=e[49];const q=K?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Pe=K&&"@container/pill-tabs",$e=K&&"pill-tabs__track",Ce=K&&(f??"gap-0.5 py-0.5"),pe=$&&"items-center overflow-y-hidden",R=Y&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_2%,transparent)] p-0.5 gap-0.5",J=F?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let H;e[50]!==q||e[51]!==Pe||e[52]!==$e||e[53]!==Ce||e[54]!==pe||e[55]!==R||e[56]!==J?(H=de("relative flex h-full min-w-0 flex-1",q,Pe,$e,Ce,pe,R,J),e[50]=q,e[51]=Pe,e[52]=$e,e[53]=Ce,e[54]=pe,e[55]=R,e[56]=J,e[57]=H):H=e[57];let Ee;e[58]!==F?(Ee=F?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=F,e[59]=Ee):Ee=e[59];let Ae;e[60]!==I?(Ae=I("sortableTabsStrip.aria.tabs"),e[60]=I,e[61]=Ae):Ae=e[61];let Je;e[62]!==z||e[63]!==ee||e[64]!==K?(Je=K&&z?s.jsx("div",{className:de("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(${z.left}px, ${z.top}px, 0)`,width:`${z.width}px`,height:`${z.height}px`,transition:ee?"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]=z,e[63]=ee,e[64]=K,e[65]=Je):Je=e[65];let ce;e[66]!==z||e[67]!==$?(ce=$&&z?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(${z.left}px, 0, 0)`,width:`${z.width}px`},"aria-hidden":!0}):null,e[66]=z,e[67]=$,e[68]=ce):ce=e[68];let _e;if(e[69]!==fe||e[70]!==r||e[71]!==m||e[72]!==S||e[73]!==P||e[74]!==v||e[75]!==y||e[76]!==O||e[77]!==j||e[78]!==F||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==L||e[83]!==K){let Ge;e[85]!==fe||e[86]!==r||e[87]!==m||e[88]!==S||e[89]!==P||e[90]!==v||e[91]!==y||e[92]!==O||e[93]!==j||e[94]!==F||e[95]!==i||e[96]!==a||e[97]!==L||e[98]!==K?(Ge=me=>{const Ke=me.id===r,ze=y&&K&&!Ke&&!!me.icon,tt=!ze,it=!!me.icon&&(!v||Ke),qe=y&&K&&Ke&&!F&&!L,Ze=me.closable!==!1&&!!i,Xe=Ze&&!!me.icon,mt=F||L?void 0:K?qe?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",wt=Ze?dt=>{dt.button===1&&(dt.preventDefault(),dt.stopPropagation(),i?.(me.id))}:void 0,Et=Ze?Ty:void 0;return s.jsx(fe,{id:me.id,className:mt,children:s.jsxs("div",{ref:dt=>ye(me.id,dt),onAuxClick:wt,onMouseDown:Et,className:de("group flex h-full min-w-0 flex-nowrap items-center",F||L?"shrink-0":K?"w-full":"w-full min-w-0",K?"relative z-10 bg-transparent":Ke?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":Ke,"aria-label":ze?me.title??me.label:void 0,onClick:()=>a(me.id),className:de(K?"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",K&&S?"lowercase":null,K&&(ze?"gap-0":"gap-1.5"),K?L?"shrink-0 whitespace-nowrap px-3 text-center":F?"max-w-56 shrink-0 px-3 text-center":ze?"px-2 !min-w-0 text-center":qe?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":F?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",K?m??(O?j?"h-[38px]":"h-[31px]":"h-7"):null,K?Ke?"text-foreground":"text-muted-foreground hover:text-foreground":null,K?"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:me.title??me.label,children:K?s.jsxs(s.Fragment,{children:[it?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:de("flex items-center justify-center transition-opacity",Xe&&(P?"opacity-0":"group-hover:opacity-0")),children:me.icon}),Xe?s.jsx("span",{role:"button",tabIndex:-1,className:de("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",P?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Ay,onClick:dt=>{dt.stopPropagation(),i?.(me.id)},"aria-label":me.closeLabel??`Close ${me.label} tab`,title:me.closeLabel??`Close ${me.label} tab`,children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,tt?s.jsx("span",{className:"animated-tabs__label truncate",children:me.label}):null]}):s.jsxs("span",{className:de("flex min-w-0 flex-nowrap items-center gap-1.5",!F&&"justify-center"),children:[it?s.jsxs("span",{className:de("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Ke?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:de("flex items-center justify-center transition-opacity",Xe&&(P?"opacity-0":"group-hover:opacity-0")),children:me.icon}),Xe?s.jsx("span",{role:"button",tabIndex:-1,className:de("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",P?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Ey,onClick:dt=>{dt.stopPropagation(),i?.(me.id)},"aria-label":me.closeLabel??`Close ${me.label} tab`,title:me.closeLabel??`Close ${me.label} tab`,children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:me.label})]})}),Ze&&!Xe?s.jsx("button",{type:"button",onPointerDown:My,onClick:dt=>{dt.stopPropagation(),i?.(me.id)},className:de("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",K?"-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",K?Ke?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Ke?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":me.closeLabel??`Close ${me.label} tab`,title:me.closeLabel??`Close ${me.label} tab`,children:s.jsx(D,{name:"close",className:"h-3 w-3"})}):null]})},me.id)},e[85]=fe,e[86]=r,e[87]=m,e[88]=S,e[89]=P,e[90]=v,e[91]=y,e[92]=O,e[93]=j,e[94]=F,e[95]=i,e[96]=a,e[97]=L,e[98]=K,e[99]=Ge):Ge=e[99],_e=n.map(Ge),e[69]=fe,e[70]=r,e[71]=m,e[72]=S,e[73]=P,e[74]=v,e[75]=y,e[76]=O,e[77]=j,e[78]=F,e[79]=n,e[80]=i,e[81]=a,e[82]=L,e[83]=K,e[84]=_e}else _e=e[84];let et;e[100]!==H||e[101]!==Ee||e[102]!==Ae||e[103]!==Je||e[104]!==ce||e[105]!==_e?(et=s.jsxs("div",{ref:M,className:H,style:Ee,role:"tablist","aria-label":Ae,children:[Je,ce,_e]}),e[100]=H,e[101]=Ee,e[102]=Ae,e[103]=Je,e[104]=ce,e[105]=_e,e[106]=et):et=e[106];let Me;e[107]!==he||e[108]!==Fe||e[109]!==Be||e[110]!==et?(Me=s.jsxs("div",{className:he,children:[Fe,Be,et]}),e[107]=he,e[108]=Fe,e[109]=Be,e[110]=et,e[111]=Me):Me=e[111];const He=Me;if(!re)return He;let We;e[112]===Symbol.for("react.memo_cache_sentinel")?(We=[jy],e[112]=We):We=e[112];let Te;e[113]!==A||e[114]!==He?(Te=s.jsx(Oo,{items:A,strategy:ng,children:He}),e[113]=A,e[114]=He,e[115]=Te):Te=e[115];let Ve;e[116]===Symbol.for("react.memo_cache_sentinel")?(Ve=s.jsx($o,{dropAnimation:null}),e[116]=Ve):Ve=e[116];let Ye;return e[117]!==Ne||e[118]!==X||e[119]!==Te?(Ye=s.jsxs(Si,{sensors:X,collisionDetection:ki,onDragEnd:Ne,modifiers:We,children:[Te,Ve]}),e[117]=Ne,e[118]=X,e[119]=Te,e[120]=Ye):Ye=e[120],Ye};function ky(t){return t.isMobile}function Cy(t){return t.id}function Py(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 Iy(t){return t===null?t:null}function Dy(t){return t===null?t:null}function Ty(t){t.button===1&&t.preventDefault()}function Ay(t){t.stopPropagation()}function Ey(t){t.stopPropagation()}function My(t){t.stopPropagation()}function xu(t){const e=st.c(14);let n,r,a,i;e[0]!==t?({size:a,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);const l=typeof a=="number"?`${a}px`:a,u=typeof a=="number"?`${a}px`:a;let d;e[5]!==i||e[6]!==l||e[7]!==u?(d={width:l,height:u,...i},e[5]=i,e[6]=l,e[7]=u,e[8]=d):d=e[8];let f;e[9]===Symbol.for("react.memo_cache_sentinel")?(f=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]=f):f=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:f}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const bu={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,lastChecked:null,updateDialogOpen:!1},tr=vn()((t,e)=>({...bu,checkForUpdates:async()=>{if(!e().checking){t({checking:!0,error:null});try{const r=await Gg();if(!r){t({checking:!1,available:!1,lastChecked:Date.now()});return}t({checking:!1,available:r.available,info:r,lastChecked:Date.now()})}catch(r){t({checking:!1,error:r instanceof Error?r.message:"Update check failed",lastChecked:Date.now()})}}},downloadUpdate:async()=>{t({downloading:!0,error:null,progress:null});try{const n=await Hg(r=>{t({progress:r})});t(n?{downloading:!1,downloaded:!0}:{downloading:!1,error:"Download failed to start"})}catch(n){t({downloading:!1,error:n instanceof Error?n.message:"Download failed"})}},restartToUpdate:async()=>{try{await Wg()}catch(n){t({error:n instanceof Error?n.message:"Restart failed"})}},dismiss:()=>{t({available:!1,downloaded:!1,info:null,error:null})},reset:()=>{t(bu)},setUpdateDialogOpen:n=>{t({updateDialogOpen:n})}})),xr=[{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"}];xr.reduce((t,e)=>(t[e.id]=e,t),{});const Ry=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),Fy=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,Ei=(t,e)=>t??Fy(e),cd=(t,e)=>{if(!t)return e??"";try{const n=new Date(t);if(!Number.isFinite(n.getTime()))return e??"";const r=new Date;return n.toDateString()===r.toDateString()?n.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}):n.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit"})}catch{return e??""}},Tf=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,Ly=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},Mi=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=Ly(r)),t===null||e===null||a===null||a<=0)return null;const i=Date.now(),l=Math.max(0,(e-i)/1e3),u=Math.max(0,Math.min(a,a-l)),d=Math.max(0,Math.min(1,u/a)),f=t/100,m=t>=100&&l>0;let c;d>.01?c=Math.min(999,f/d*100):c=t;let p;m?p="exhausted":f<=d?p="on-track":c<=130?p="slightly-fast":p="too-fast";const g=a>=120*3600,h=g?86400:3600,x=g?"d":"h",w=a/h,b=Math.max(u/h,w*.01),y=t/b,v=Number.isFinite(y)?`${Math.min(999.9,Math.max(0,y)).toFixed(1)}%/${x}`:"-",S=c>100?`+${Math.round(c)}%`:`${Math.round(c)}%`;let I=null;const j=a/86400;return j>=7&&(I=100/j),{elapsedRatio:d,usageRatio:f,predictedFinalPercent:c,remainingSeconds:l,isExhausted:m,elapsedSeconds:u,totalSeconds:a,status:p,paceRateText:v,predictText:S,dailyAllocationPercent:I}},Oy=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)"}},yu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),a=Math.floor(r/24),i=r%24,l=n%60;return a>0?`${a}d ${i}h`:r>0?`${r}h`:n===0?"<1m":`${l}m`},Er=t=>Math.min(100,Math.max(0,t*100));function Ko(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 $y=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],Af={google:$y};function Ef(t,e){const n=Af[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function Mf(t){return Af[t]??[]}function Rf(t){return[...t].sort((e,n)=>e.order-n.order)}function _y(t,e){const n=new Map;for(const r of Object.keys(t)){const i=Ef(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function zy(t,e,n){const r=new Map;for(const a of t){const i=e(a),u=Ef(i,n)?.id??null;r.has(u)||r.set(u,[]),r.get(u).push(a)}return r}function By(t,e){return e.filter(n=>{const r=n.toLowerCase(),a=r.includes("/")?r.split("/")[1]:r;return!!(a.startsWith("gemini-3-")||a.startsWith("claude-"))})}const ud=6e4,vu=t=>{const e=xr.map(c=>c.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):ud,a=t?.usageDisplayMode==="remaining"?"remaining":"usage",i=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,l=i?i.filter(c=>typeof c=="string"&&e.includes(c)):e,u={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[c,p]of Object.entries(d))Array.isArray(p)&&(u[c]=p.filter(g=>typeof g=="string"));const f={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[c,p]of Object.entries(m))Array.isArray(p)&&(f[c]=p.filter(g=>typeof g=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:a,dropdownProviderIds:l,selectedModels:u,expandedFamilies:f}},Vy=async()=>{const t=nr()?.settings;if(t)try{const n=(await t.load())?.settings;return vu(n??null)}catch{}if(!Ks()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return vu(n)}}return{autoRefresh:!1,refreshIntervalMs:ud,displayMode:"usage",dropdownProviderIds:xr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},fs=vn()(qa((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:ud,displayMode:"usage",dropdownProviderIds:xr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Vy();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=xr.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:a})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),a=await r.json().catch(()=>null);if(!r.ok)throw new Error(a?.error||"Failed to fetch quota");const i=a;t(l=>{const u=l.results.filter(d=>d.providerId!==n);return u.push(i),{results:u,error:null}})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:a,usage:null,fetchedAt:Date.now()};t(l=>{const u=l.results.filter(d=>d.providerId!==n);return u.push(i),{results:u,error:a}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(a=>({selectedModels:{...a.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(a=>{const i=a.selectedModels[n]??[],u=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{selectedModels:{...a.selectedModels,[n]:u}}})},setExpandedFamilies:(n,r)=>{t(a=>({expandedFamilies:{...a.expandedFamilies,[n]:r}})),rs({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(a=>{const i=a.expandedFamilies[n]??[],u=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{expandedFamilies:{...a.expandedFamilies,[n]:u}}}),rs({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=By(n,r);i.length!==0&&(t(l=>({selectedModels:{...l.selectedModels,[n]:i}})),rs({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Ff=()=>{const t=st.c(5),e=fs(Uy),n=fs(Ky),r=fs(Wy);let a,i;t[0]!==e||t[1]!==r||t[2]!==n?(a=()=>{if(!e)return;const l=window.setInterval(()=>{r()},n);return()=>window.clearInterval(l)},i=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=a,t[4]=i):(a=t[3],i=t[4]),o.useEffect(a,i)};function Uy(t){return t.autoRefresh}function Ky(t){return t.refreshIntervalMs}function Wy(t){return t.fetchAllQuotas}const Wo=Le.forwardRef((t,e)=>{const n=st.c(11);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]!==r?(i=de("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=i):i=n[4];let l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let u;n[6]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(rg,{className:de("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]=u):u=n[6];let d;return n[7]!==a||n[8]!==e||n[9]!==i?(d=s.jsx(ag,{className:i,style:l,...a,ref:e,children:u}),n[7]=a,n[8]=e,n[9]=i,n[10]=d):d=n[10],d});Wo.displayName="Switch";const eo=()=>{try{const e=es.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=Bs.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},wu=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],ju=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},to=t=>typeof t!="string"?void 0:t.trim()||void 0,Bl=800,Hy=5e3,Gy="__default__",Nc=new Map,Vl=new Map,Lf=t=>t?.trim()||Gy,Ul=t=>{Nc.delete(Lf(t))},Ri=vn()(qa($i((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=eo(),a=Lf(r),i=Date.now(),l=Nc.get(a)??0,u=e().mcpServers.length>0;if(!n?.force&&u&&i-l<Hy)return!0;const d=Vl.get(a);if(!n?.force&&d)return d;const f=(async()=>{t({isLoading:!0});try{const m=r?`?directory=${encodeURIComponent(r)}`:"",c=await fetch(`/api/config/mcp${m}`,{headers:r?{"x-opencode-directory":r}:void 0});if(!c.ok)throw new Error("Failed to load MCP configs");const p=await c.json();return t({mcpServers:p,isLoading:!1}),Nc.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();Vl.set(a,f);try{return await f}finally{Vl.delete(a)}},createMcp:async n=>{Al("Creating MCP server configuration…");let r=!1;try{const a=Nu(n),i=eo(),l=i?`?directory=${encodeURIComponent(i)}`:"",u=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${l}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(a)}),d=await u.json().catch(()=>null);if(!u.ok)throw new Error(d?.error||"Failed to create MCP server");return Ul(i),d?.requiresReload?(r=!0,await El({message:d.message,delayMs:d.reloadDelayMs??Bl,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning})}catch(a){return console.error("[McpConfigStore] Failed to create MCP:",a),{ok:!1}}finally{r||Ml()}},updateMcp:async(n,r)=>{Al("Updating MCP server configuration…");let a=!1;try{const i=Nu(r),l=eo(),u=l?`?directory=${encodeURIComponent(l)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${u}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},body:JSON.stringify(i)}),f=await d.json().catch(()=>null);if(!d.ok)throw new Error(f?.error||"Failed to update MCP server");return Ul(l),f?.requiresReload?(a=!0,await El({message:f.message,delayMs:f.reloadDelayMs??Bl,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{a||Ml()}},deleteMcp:async n=>{Al("Deleting MCP server configuration…");let r=!1;try{const a=eo(),i=a?`?directory=${encodeURIComponent(a)}`:"",l=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:a?{"x-opencode-directory":a}:void 0}),u=await l.json().catch(()=>null);if(!l.ok)throw new Error(u?.error||"Failed to delete MCP server");return Ul(a),u?.requiresReload&&(r=!0,await El({message:u.message,delayMs:u.reloadDelayMs??Bl,scopes:["all"]})),e().selectedMcpName===n&&t({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:u?.reloadFailed===!0,message:u?.message,warning:u?.warning}}catch(a){return console.error("[McpConfigStore] Failed to delete MCP:",a),{ok:!1}}finally{r||Ml()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:il(()=>Vr()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function Nu(t){const e={};if(t.scope!==void 0&&(e.scope=t.scope),t.type!==void 0&&(e.type=t.type),(t.type==="local"||t.command!==void 0)&&(e.command=(t.command??[]).filter(n=>n.trim())),(t.type==="remote"||t.url!==void 0)&&(e.url=t.url?.trim()??""),t.environment!==void 0&&(e.environment=ju(t.environment)??{}),t.headers!==void 0&&(e.headers=ju(t.headers)??{}),t.oauthEnabled!==void 0||t.oauthClientId!==void 0||t.oauthClientSecret!==void 0||t.oauthScope!==void 0||t.oauthRedirectUri!==void 0)if(t.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:to(t.oauthClientId),clientSecret:to(t.oauthClientSecret),scope:to(t.oauthScope),redirectUri:to(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 qy={},Yy={},Tr=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},va=t=>Tr(t)??"__global__",Yr=t=>{const e=Tr(t);return e?Bs.getScopedApiClient(e):Bs.getApiClient()},qs=vn()(qa((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=va(n??Ns.getState().currentDirectory);return e().byDirectory[r]??qy},getDiagnosticForDirectory:n=>{const r=va(n??Ns.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Yy},getErrorForDirectory:n=>{const r=va(n??Ns.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Tr(n?.directory??Ns.getState().currentDirectory),a=va(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const u=(await Yr(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[a]:u},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[a]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[a]??{}).filter(([f])=>!u[f]))},loadingKeys:{...d.loadingKeys,[a]:!1},lastErrorKeys:{...d.lastErrorKeys,[a]:null}}))}catch(i){const l=i instanceof Error?i.message:"Failed to load MCP status";t(u=>({loadingKeys:{...u.loadingKeys,[a]:!1},lastErrorKeys:{...u.lastErrorKeys,[a]:l}}))}},connect:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory),i=va(a),l=Yr(a);try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(u){const d=u instanceof Error?u.message:"Connection failed";throw t(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:d}}}})),u}await e().refresh({directory:a,silent:!0})},disconnect:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory);await Yr(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory),u=(await Yr(a).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!u)throw new Error("Authorization URL was not returned");return u},completeAuth:async(n,r,a)=>{const i=Tr(a??Ns.getState().currentDirectory);await Yr(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory);await Yr(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=Tr(r??Ns.getState().currentDirectory),i=va(a),l=Yr(a),d=e().getStatusForDirectory(a)[n]?.status==="connected";let f,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(g){f=g instanceof Error?g.message:"Connection failed",t(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:f??"Connection failed"}}}}))}await e().refresh({directory:a,silent:!0});const c=e().getStatusForDirectory(a)[n],p=c;if(!d&&c?.status==="connected"){try{await l.mcp.disconnect({name:n},{throwOnError:!0})}catch(g){m=`Connection test succeeded, but cleanup disconnect failed: ${g instanceof Error?g.message:"Disconnect failed"}`}await e().refresh({directory:a,silent:!0})}return{status:p??e().getStatusForDirectory(a)[n],error:f,warning:m}}})));function Qy(t){const e=st.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let a;return e[2]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=a):a=e[3],a}const Jy=(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}},Xy=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Of=({active:t,className:e})=>{const{t:n}=ct(),a=Ns(b=>b.currentDirectory)??null,i=qs(b=>b.getStatusForDirectory(a)),l=qs(b=>b.refresh),u=qs(b=>b.connect),d=qs(b=>b.disconnect),f=Ri(b=>b.mcpServers),m=Ri(b=>b.loadMcpConfigs),[c,p]=o.useState(!1),[g,h]=o.useState(null);o.useEffect(()=>{l({directory:a,silent:!0})},[l,a]),o.useEffect(()=>{m({force:!0})},[m]),o.useEffect(()=>{t&&Promise.all([l({directory:a,silent:!0}),m({force:!0})])},[t,l,a,m]);const x=o.useMemo(()=>{const b=new Set(Object.keys(i));for(const y of f)y?.name&&b.add(y.name);return Array.from(b).sort((y,v)=>y.localeCompare(v))},[f,i]),w=o.useCallback(b=>{if(b?.preventDefault(),c)return;p(!0);const y=new Promise(v=>setTimeout(v,500));Promise.all([l({directory:a}),y]).finally(()=>{p(!1)})},[c,l,a]);return s.jsxs("div",{className:de("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),a&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:a.split("/").pop()||a})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:c,onClick:w,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(D,{name:"refresh",className:de("h-4 w-4",c&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[x.map(b=>{const y=i[b],v=Xy(y),S=y?.status==="connected",I=g===b,j=Jy(y,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(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:de("h-2 w-2 rounded-full flex-shrink-0",v==="success"&&"bg-status-success",v==="error"&&"bg-status-error",v==="warning"&&"bg-status-warning",v==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(Rt,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:b})]})}),s.jsx(Wo,{checked:S,disabled:I,className:"data-[checked]:bg-status-info",onCheckedChange:async N=>{h(b);try{N?await u(b,a):await d(b,a)}finally{h(null)}}})]},b)}),x.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},Fi=t=>{const e=st.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let l;e[0]!==n?(l=Ry(n)??0,e[0]=n,e[1]=l):l=e[1];const u=l,d=r??n;let f;e[2]!==d?(f=Tf(d),e[2]=d,e[3]=f):f=e[3];const m=f,c=i!=null?Math.max(0,Math.min(100,i)):null;let p;e[4]!==m?(p=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=p):p=e[5];const g=p;let h;e[6]!==a?(h=de("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=h):h=e[7];const x=`${u}%`;let w;e[8]!==g||e[9]!==x?(w={...g,width:x},e[8]=g,e[9]=x,e[10]=w):w=e[10];let b;e[11]!==u||e[12]!==w?(b=s.jsx("div",{className:"h-full transition-all duration-300",style:w,role:"progressbar","aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100}),e[11]=u,e[12]=w,e[13]=b):b=e[13];let y;e[14]!==c?(y=c!=null&&c>0&&c<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${c}%`},title:`Expected usage if spread evenly: ${Math.round(c)}% of quota`,"aria-hidden":"true"}),e[14]=c,e[15]=y):y=e[15];let v;return e[16]!==h||e[17]!==b||e[18]!==y?(v=s.jsxs("div",{className:h,children:[b,y]}),e[16]=h,e[17]=b,e[18]=y,e[19]=v):v=e[19],v},Li=t=>{const e=st.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:l}=ct();let u;e[0]!==n.status?(u=Oy(n.status),e[0]=n.status,e[1]=u):u=e[1];const d=u;let f;e:{switch(n.status){case"on-track":{let N;e[2]!==l?(N=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=N):N=e[3],f=N;break e}case"slightly-fast":{let N;e[4]!==l?(N=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=N):N=e[5],f=N;break e}case"too-fast":{let N;e[6]!==l?(N=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=N):N=e[7],f=N;break e}case"exhausted":{let N;e[8]!==l?(N=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=N):N=e[9],f=N;break e}}f=void 0}const m=f;let c;e[10]!==n.predictText||e[11]!==l?(c=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=c):c=e[12];const p=c;if(i){let N;e[13]!==r?(N=de("flex items-center gap-1.5",r),e[13]=r,e[14]=N):N=e[14];let P;e[15]!==d?(P={backgroundColor:d},e[15]=d,e[16]=P):P=e[16];let M;e[17]!==m||e[18]!==P?(M=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:P,title:m}),e[17]=m,e[18]=P,e[19]=M):M=e[19];let T;e[20]!==d?(T={color:d},e[20]=d,e[21]=T):T=e[21];const E=n.isExhausted?void 0:p;let k;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(k=n.isExhausted?s.jsx(s.Fragment,{children:l("settings.usage.pace.wait",{duration:yu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:l("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=l,e[26]=k):k=e[26];let C;e[27]!==k||e[28]!==T||e[29]!==E?(C=s.jsx("span",{className:"typography-micro tabular-nums",style:T,title:E,children:k}),e[27]=k,e[28]=T,e[29]=E,e[30]=C):C=e[30];let A;return e[31]!==C||e[32]!==N||e[33]!==M?(A=s.jsxs("div",{className:N,children:[M,C]}),e[31]=C,e[32]=N,e[33]=M,e[34]=A):A=e[34],A}let g;e[35]!==r?(g=de("flex items-center justify-between gap-2",r),e[35]=r,e[36]=g):g=e[36];let h;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(h=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=l,e[40]=h):h=e[40];let x;e[41]!==h?(x=s.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[41]=h,e[42]=x):x=e[42];let w;e[43]!==d?(w={color:d},e[43]=d,e[44]=w):w=e[44];let b;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==p||e[49]!==m||e[50]!==l?(b=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:yu(n.remainingSeconds)})]}):s.jsxs("span",{title:p,children:[s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=p,e[49]=m,e[50]=l,e[51]=b):b=e[51];let y;e[52]!==w||e[53]!==b?(y=s.jsx("span",{className:"typography-micro tabular-nums",style:w,children:b}),e[52]=w,e[53]=b,e[54]=y):y=e[54];let v;e[55]!==d?(v={backgroundColor:d},e[55]=d,e[56]=v):v=e[56];let S;e[57]!==m||e[58]!==v?(S=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:v,title:m}),e[57]=m,e[58]=v,e[59]=S):S=e[59];let I;e[60]!==y||e[61]!==S?(I=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,S]}),e[60]=y,e[61]=S,e[62]=I):I=e[62];let j;return e[63]!==I||e[64]!==g||e[65]!==x?(j=s.jsxs("div",{className:g,children:[x,I]}),e[63]=I,e[64]=g,e[65]=x,e[66]=j):j=e[66],j},br=ig,yr=t=>{const e=st.c(14);let n,r,a,i;e[0]!==t?({className:a,asChild:n,children:r,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);let l;e[5]!==n||e[6]!==r?(l=n&&Le.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=l):l=e[7];const u=l;let d;e[8]!==a?(d=de("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",a),e[8]=a,e[9]=d):d=e[9];let f;return e[10]!==i||e[11]!==u||e[12]!==d?(f=s.jsx(og,{className:d,...i,...u}),e[10]=i,e[11]=u,e[12]=d,e[13]=f):f=e[13],f},vr=t=>{const e=st.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=de("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(lg,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},Zy=1e6,ev="terminal-store";let Su=!1;const Kl=t=>typeof t=="object"&&t!==null,tv=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function xn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const Wl=(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}),$f=/\x1b\[[0-9;]*m/g,sv=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,nv=new Set([".",",",";",":","!","?"]),rv=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",a=e.slice(0,-1),i=(a.match(new RegExp(`\\${r}`,"g"))||[]).length,l=(a.match(new RegExp(`\\${n}`,"g"))||[]).length;if(i>l)break;e=a;continue}if(nv.has(n)){e=e.slice(0,-1);continue}break}return e},av=t=>{if(!t)return null;const n=t.replace($f,"").match(sv);if(!n?.[1])return null;let r=rv(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},iv=t=>{if(!t)return null;const n=t.replace($f,"").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}/`},Hl=t=>({tabs:[t],activeTabId:t.id}),or=(t,e)=>t.tabs.findIndex(n=>n.id===e),Os=vn()(qa($i((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=xn(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),l=`tab-${a.nextTabId}`,u=Wl(l,"Terminal");return i.set(r,Hl(u)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=xn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=xn(n),a=e().sessions.get(r);if(!a)return;const i=a.activeTabId;return i?a.tabs.find(l=>l.id===i)??a.tabs[0]:a.tabs[0]},createTab:n=>{const r=xn(n);if(!r)return"tab-invalid";const a=`tab-${e().nextTabId}`;return t(i=>{const l=new Map(i.sessions),u=l.get(r),d=i.nextTabId+1,m=`Terminal ${(u?.tabs.length??0)+1}`,c=Wl(a,m);return u?l.set(r,{...u,tabs:[...u.tabs,c]}):l.set(r,Hl(c)),{sessions:l,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=xn(n);t(i=>{const l=new Map(i.sessions),u=l.get(a);return!u||u.activeTabId===r||or(u,r)<0?i:(l.set(a,{...u,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,a)=>{const i=xn(n),l=a.trim();l&&t(u=>{const d=new Map(u.sessions),f=d.get(i);if(!f)return u;const m=or(f,r);if(m<0||f.tabs[m]?.label===l)return u;const c=[...f.tabs];return c[m]={...c[m],label:l},d.set(i,{...f,tabs:c}),{sessions:d}})},setTabIconKey:(n,r,a)=>{const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=a?.trim()||null;if(d.tabs[f]?.iconKey===m)return l;const c=[...d.tabs];return c[f]={...c[f],iconKey:m},u.set(i,{...d,tabs:c}),{sessions:u}})},closeTab:async(n,r)=>{const a=xn(n),u=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(u)try{await Vg(u)}catch{}t(d=>{const f=new Map(d.sessions),m=f.get(a);if(!m)return d;const c=or(m,r);if(c<0)return d;const p=m.tabs.filter(w=>w.id!==r),g=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,w])=>!(w.directory===a&&w.tabId===r))),h=Object.keys(g).length!==Object.keys(d.projectActionRuns).length;if(p.length===0){const w=`tab-${d.nextTabId}`,b=Wl(w,"Terminal");return f.set(a,Hl(b)),{sessions:f,nextTabId:d.nextTabId+1,...h?{projectActionRuns:g}:{}}}let x=m.activeTabId;return m.activeTabId===r&&(x=p[Math.min(c,p.length-1)]?.id??p[0]?.id??null),f.set(a,{...m,tabs:p,activeTabId:x}),{sessions:f,...h?{projectActionRuns:g}:{}}})},setTabSessionId:(n,r,a)=>{const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=d.tabs[f],c=a!==null&&m.terminalSessionId!==a,p=a?"running":m.terminalSessionId?"exited":m.lifecycle,g={...m,terminalSessionId:a,lifecycle:p,isConnecting:!1,...c?{bufferChunks:[],bufferLength:0}:{}},h=[...d.tabs];return h[f]=g,u.set(i,{...d,tabs:h}),{sessions:u}})},setTabLifecycle:(n,r,a)=>{const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=[...d.tabs];return m[f]={...m[f],lifecycle:a,isConnecting:!1},u.set(i,{...d,tabs:m}),{sessions:u}})},setConnecting:(n,r,a)=>{const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=[...d.tabs];return m[f]={...m[f],isConnecting:a},u.set(i,{...d,tabs:m}),{sessions:u}})},appendToBuffer:(n,r,a)=>{if(!a)return;const i=xn(n);t(l=>{const u=new Map(l.sessions),d=u.get(i);if(!d)return l;const f=or(d,r);if(f<0)return l;const m=d.tabs[f],c=l.nextChunkId,p={id:c,data:a},g=[...m.bufferChunks,p];let h=m.bufferLength+a.length;for(;h>Zy&&g.length>1;){const y=g.shift();if(!y)break;h-=y.data.length}const x=m.previewUrlLocked?null:av(a)??iv(a),w=!!(x&&x!==m.previewUrl),b=[...d.tabs];return b[f]={...m,bufferChunks:g,bufferLength:h,...w?{previewUrl:x,previewAutoOpened:!1}:null},u.set(i,{...d,tabs:b}),{sessions:u,nextChunkId:c+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const l=xn(n);t(u=>{const d=new Map(u.sessions),f=d.get(l);if(!f)return u;const m=or(f,r);if(m<0)return u;const c=f.tabs[m],p=i.autoOpened??c.previewAutoOpened,g=i.locked??c.previewUrlLocked;if(c.previewUrl===a&&c.previewAutoOpened===p&&c.previewUrlLocked===g)return u;const h=[...f.tabs];return h[m]={...c,previewUrl:a,previewAutoOpened:p,previewUrlLocked:g},d.set(l,{...f,tabs:h}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=xn(n);t(i=>{const l=new Map(i.sessions),u=l.get(a);if(!u)return i;const d=or(u,r);if(d<0)return i;const f=u.tabs[d];if(!f.previewUrl||f.previewAutoOpened)return i;const m=[...u.tabs];return m[d]={...f,previewAutoOpened:!0},l.set(a,{...u,tabs:m}),{sessions:l}})},setProjectActionRun:n=>{t(r=>{const a=r.projectActionRuns[n.key];return a&&a.directory===n.directory&&a.actionId===n.actionId&&a.tabId===n.tabId&&a.sessionId===n.sessionId&&a.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(a=>{const i=a.projectActionRuns[n];return!i||i.status===r?a:{projectActionRuns:{...a.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const a={...r.projectActionRuns};return delete a[n],{projectActionRuns:a}})},clearBuffer:(n,r)=>{const a=xn(n);t(i=>{const l=new Map(i.sessions),u=l.get(a);if(!u)return i;const d=or(u,r);if(d<0)return i;const f=[...u.tabs];return f[d]={...f[d],bufferChunks:[],bufferLength:0},l.set(a,{...u,tabs:f}),{sessions:l}})},removeDirectory:n=>{const r=xn(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const l=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,u])=>u.directory!==r));return{sessions:i,projectActionRuns:l}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:ev,storage:il(()=>Yp()),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(!Kl(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let a=0;for(const u of n){if(!Array.isArray(u)||u.length!==2)continue;const[d,f]=u;if(typeof d!="string"||!Kl(f))continue;const m=Array.isArray(f.tabs)?f.tabs:[],c=[];for(const h of m){if(!Kl(h))continue;const x=typeof h.id=="string"?h.id:null;if(!x)continue;const w=tv(x);w!==null&&(a=Math.max(a,w));const b=typeof h.terminalSessionId=="string"||h.terminalSessionId===null?h.terminalSessionId:null,y=h.lifecycle,v=y==="idle"||y==="running"||y==="exited"?y:b?"running":"idle";c.push({id:x,label:typeof h.label=="string"?h.label:"Terminal",iconKey:typeof h.iconKey=="string"?h.iconKey:null,terminalSessionId:b,lifecycle:v,createdAt:typeof h.createdAt=="number"?h.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(c.length===0)continue;const p=typeof f.activeTabId=="string"?f.activeTabId:null,g=p?c.some(h=>h.id===p):!1;r.set(d,{tabs:c,activeTabId:g?p:c[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,l=Math.max(e.nextTabId,i,a+1);return{...e,sessions:r,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!Su){Su=!0;const t=Os.persist,e=()=>{Os.getState().hasHydrated||Os.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const ku=(t,e)=>e.updatedAtMs-t.updatedAtMs,Ts=vn((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([Jg(),Bd()]),a={};for(const i of r.sort(ku))a[i.id]=i;e().listenerReady||await Xg(i=>{t(l=>({statusesById:{...l.statusesById,[i.id]:i}}))}),t({instances:n.instances,statusesById:a,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await Qg();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await Bd(),r={};for(const a of n.sort(ku))r[a.id]=a;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await Yg({instances:n}),t({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw t({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,a=r.some(i=>i.id===n.id)?r.map(i=>i.id===n.id?n:i):[n,...r];await e().setInstances(a)},createFromCommand:async(n,r,a)=>{const i=Zg(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await zd(n).catch(()=>{});const r=e().instances.filter(a=>a.id!==n);await e().setInstances(r),t(a=>{const i={...a.statusesById};return delete i[n],{statusesById:i}})},connect:async n=>{t({error:null});try{await qg(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 zd(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})})),_f=[{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"}],Po=Object.fromEntries(_f.map(t=>[t.key,t.Icon])),Sc="vinci:project-actions-updated",zf=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},_r=(t,e)=>`${zf(t)}::${e}`,ov=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Cu=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},lv=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=Cu(e.localPort),r=Cu(e.remotePort);if(!n||!r)return null;const a=ov(e.localHost||t.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),l=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${l} - ${a}:${n} -> ${i}:${r}`,url:`http://${a}:${n}`}},Bf=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=lv(n,r);a&&e.push(a)}return e},cv=(t,e)=>{const n=(t||"").trim();return n&&Bf(e).find(i=>i.id===n)?.url||null},dv=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],uv=["dev","start","preview","serve"];async function mv(t,e,n){if(!t)return null;const r=hv(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=gv(n);if(a){const i=await xv(t);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${a}`,label:`Start (${a})`}}}if(await pv(t)){const a=await fv(),i=typeof a=="number"&&Number.isFinite(a)&&a>0?a:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function pv(t){const e=`${t}/index.html`,n=await Ho(e);return typeof n=="string"&&n.trim().length>0}async function fv(){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 hv(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(uv.some(a=>n.includes(a)))return e}return null}function gv(t){for(const{pattern:e}of dv)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function xv(t){const e=await Ho(`${t}/package.json`);if(e)try{const r=JSON.parse(e),a=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(a.startsWith("bun@"))return"bun";if(a.startsWith("pnpm@"))return"pnpm";if(a.startsWith("yarn@"))return"yarn";if(a.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,a]of n){const i=await Ho(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function Ho(t){const e=nr()?.files;if(e?.readFile)try{const n=await e.readFile(t,{optional:!0});return typeof n?.content=="string"?n.content:null}catch{return null}try{const n=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return n.ok?n.text():null}catch{return null}}async function bv(t){try{const e=await Ho(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const yv=t=>new Promise(e=>{window.setTimeout(e,t)}),vv="\x1B",wv=new RegExp(`${vv}\\[[0-9;?]*[ -/]*[@-~]`,"g"),jv=/https?:\/\/[^\s<>'"`]+/gi,Zn="__vinci_auto_discover_preview__",Nv=15e3,Sv=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},kv=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}},Cv=t=>{const n=t.replace(wv,"").match(jv);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const a=[];for(const i of r)try{const l=new URL(i);l.port&&l.port.length>0&&a.push({raw:i,parsed:l})}catch{}if(a.length>0){const i=l=>{const{parsed:u}=l,d=u.hostname.toLowerCase(),f=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=u.pathname||"/",c=m.split("/").filter(Boolean).length,p=m==="/"||m==="",g=!!(u.search||u.hash);let h=0;return f&&(h+=50),p&&(h+=30),h-=Math.min(c*5,20),g&&(h-=10),h};return a.sort((l,u)=>i(u)-i(l)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},Pv=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const a=r[0],i=r[1].slice(0,3),l=`${a} ${i}`.trim();return r.length>2||l.length<n.length?`${l}...`:l}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},Pu=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=ct(),{terminal:l,runtime:u}=wn(),{isMobile:d}=_s(),f=o.useMemo(()=>Us(),[]),m=Ts(q=>q.instances),c=Ts(q=>q.load),p=De(q=>q.setBottomTerminalOpen),g=De(q=>q.setActiveMainTab),h=De(q=>q.setSettingsPage),x=De(q=>q.setSettingsDialogOpen),w=De(q=>q.setSettingsProjectsSelectedId),b=De(q=>q.openContextPreview),y=Os(q=>q.sessions),v=Os(q=>q.ensureDirectory),S=Os(q=>q.setTabLabel),I=Os(q=>q.setTabIconKey),j=Os(q=>q.setActiveTab),N=Os(q=>q.setConnecting),P=Os(q=>q.setTabSessionId),M=Os(q=>q.setTabPreviewUrl),T=Os(q=>q.projectActionRuns),E=Os(q=>q.setProjectActionRun),k=Os(q=>q.updateProjectActionRunStatus),C=Os(q=>q.removeProjectActionRun),[A,F]=o.useState([]),[_,O]=o.useState(null),[V,K]=o.useState(!1),$=o.useRef({}),oe=o.useRef({}),L=o.useRef({}),Y=o.useRef({}),ee=o.useRef(0),re=t?.id??null,fe=t?.path??"",ge=o.useMemo(()=>re?{id:re,path:fe}:null,[re,fe]);o.useEffect(()=>{f&&c().catch(()=>{})},[f,c]);const be=o.useCallback(async q=>{await Yn(q)},[]),z=o.useCallback(async()=>{if(!ge)return;const q=ee.current+1;ee.current=q,K(!0);try{const Pe=await vc(ge);if(ee.current!==q)return;const $e=Pe.actions;F($e),O(Ce=>Ce===Zn||Ce&&$e.some(pe=>pe.id===Ce)?Ce:null)}catch{if(ee.current!==q)return}finally{ee.current===q&&K(!1)}},[ge]),B=o.useMemo(()=>zf(e||ge?.path||""),[e,ge?.path]),Q=o.useMemo(()=>_?A.find(q=>q.id===_)??null:null,[A,_]),X=o.useMemo(()=>({id:Zn,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),ie=!1,le=o.useMemo(()=>A,[A,X,ie]);o.useEffect(()=>{z()},[z]),o.useEffect(()=>{if(typeof window>"u")return;const q=Pe=>{const $e=Pe.detail;re&&($e?.projectId&&$e.projectId!==re||z())};return window.addEventListener(Sc,q),()=>{window.removeEventListener(Sc,q)}},[z,re]),o.useEffect(()=>{_&&(A.some(q=>q.id===_)||O(null))},[A,ie,_]),o.useEffect(()=>{for(const[q,Pe]of Object.entries(T)){const Ce=y.get(Pe.directory)?.tabs.find(pe=>pe.id===Pe.tabId);(!Ce||Ce.terminalSessionId!==Pe.sessionId)&&C(q)}},[T,C,y]),o.useEffect(()=>{for(const[q,Pe]of Object.entries(T)){const $e=oe.current[q]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};oe.current[q]=$e;const Ce=le.find(ce=>ce.id===Pe.actionId);if(!Ce)continue;const R=y.get(Pe.directory)?.tabs.find(ce=>ce.id===Pe.tabId);if(!R||!Array.isArray(R.bufferChunks)||R.bufferChunks.length===0)continue;const J=R.bufferChunks.filter(ce=>$e.lastSeenChunkId===null?!0:ce.id>$e.lastSeenChunkId);if(J.length===0)continue;const H=J.map(ce=>ce.data).join(""),Ee=`${$e.tail}${H}`,Ae=!$e.openedUrl&&Ce.autoOpenUrl===!0?Cv(Ee):null,Je=J[J.length-1]?.id??$e.lastSeenChunkId;if($e.lastSeenChunkId=Je,$e.tail=Ee.slice(-512),Ae)if($e.openedUrl=!0,$e.openInPreview){const ce=T[q];ce&&(M(ce.directory,ce.tabId,Ae,{locked:!1,autoOpened:!1}),ce.status==="waiting-for-preview"&&k(q,"running"),window.clearTimeout(Y.current[q]),delete Y.current[q],b(ce.directory,Ae))}else be(Ae),te.success(i("projectActions.toast.openedUrlFromOutput"));oe.current[q]=$e}for(const q of Object.keys(oe.current))T[q]||(delete oe.current[q],window.clearTimeout(Y.current[q]),delete Y.current[q])},[le,b,be,T,M,i,y,k]);const ye=o.useCallback(async(q,Pe={})=>{if(!B)throw new Error(i("projectActions.error.noActiveDirectory"));const $e=_r(B,q.id);v(B);const Ce=Os.getState(),pe=Ce.getDirectoryState(B);let R=$.current[$e]||null;const J=R?!!pe?.tabs.some(Ae=>Ae.id===R):!1;(!R||!J)&&(R=Ce.createTab(B),$.current[$e]=R),S(B,R,`Action: ${q.name}`),I(B,R,q.icon||"play"),Pe.revealTerminal!==!1&&(j(B,R),p(!0),g("terminal"));const Ee=Os.getState().getDirectoryState(B)?.tabs.find(Ae=>Ae.id===R);return{key:$e,tabId:R,sessionId:Ee?.terminalSessionId??null}},[v,B,g,j,p,I,S,i]),W=o.useCallback(async q=>{if(u.isVSCode||!a&&d)return;if(!B){te.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Pe=_r(B,q.id),$e=T[Pe];if(!($e&&$e.status==="running"))try{const Ce=q.id===Zn?await(async()=>{const[Me,He]=await Promise.all([vc({id:ge?.id??"",path:B}),bv(B)]),We=await mv(B,Me.actions,He);if(!We)throw new Error(i("contextPanel.preview.noDevServer"));return{id:Zn,name:i("projectActions.actions.autoDiscover"),command:We.command,icon:"search",autoOpenUrl:!0,openUrl:We.previewUrlHint||""}})():q,pe=Ce.autoOpenUrl===!0&&(Ce.openUrl||"").trim().length>0,{key:R,tabId:J,sessionId:H}=await ye(Ce,{revealTerminal:!pe&&q.id!==Zn});let Ee=H,Ae=!1;if(!Ee){N(B,J,!0);try{Ee=(await l.createSession({cwd:B})).sessionId,Ae=!0,P(B,J,Ee)}finally{N(B,J,!1)}}if(!Ee)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));Ae&&await yv(350),Ce.id===Zn&&(L.current[R]?.(),N(B,J,!0),L.current[R]=Ug(Ee,Me=>{Me.type==="data"&&typeof Me.data=="string"&&Me.data.length>0&&Os.getState().appendToBuffer(B,J,Me.data),Me.type==="exit"&&(Os.getState().setTabLifecycle(B,J,"exited"),Os.getState().setConnecting(B,J,!1),Os.getState().removeProjectActionRun(R),delete oe.current[R],L.current[R]?.(),delete L.current[R],window.clearTimeout(Y.current[R]),delete Y.current[R])},()=>{Os.getState().setConnecting(B,J,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Je=Ce.autoOpenUrl===!0&&f&&(Ce.desktopOpenSshForward||"").trim().length>0,ce=Ce.autoOpenUrl?kv(Ce.openUrl):null,_e=Ce.autoOpenUrl&&f?cv(Ce.desktopOpenSshForward,m):null;E({key:R,directory:B,actionId:Ce.id,tabId:J,sessionId:Ee,status:Ce.id===Zn&&!ce?"waiting-for-preview":"running"}),window.clearTimeout(Y.current[R]),delete Y.current[R],Ce.id===Zn&&!ce&&(Y.current[R]=window.setTimeout(()=>{Os.getState().updateProjectActionRunStatus(R,"running"),delete Y.current[R]},Nv)),_e?(M(B,J,null,{locked:!0}),be(_e),te.success(i("projectActions.toast.openedForwardedUrl"))):ce?(M(B,J,ce,{locked:!0,autoOpened:!0}),b(B,ce),te.success(i("projectActions.toast.openedActionUrl"))):pe?(M(B,J,null,{locked:!0}),te.error(i("projectActions.error.invalidCustomUrlFormat"))):Je?(M(B,J,null,{locked:!0}),te.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):M(B,J,null,{locked:!1,autoOpened:!1}),oe.current[R]={lastSeenChunkId:null,openedUrl:!!_e||!!ce||pe,tail:"",openInPreview:Ce.id===Zn};const et=Sv(Ce.command.trim().replace(/\r\n|\r/g,`
3
3
  `));await l.sendInput(Ee,`${et}\r`)}catch(Ce){C(Pe),delete oe.current[Pe],L.current[Pe]?.(),delete L.current[Pe],window.clearTimeout(Y.current[Pe]),delete Y.current[Pe],te.error(Ce instanceof Error?Ce.message:i("projectActions.error.failedToRunAction"))}},[m,ye,a,d,f,B,be,b,T,u.isVSCode,C,N,E,M,P,ge?.id,i,l]),ue=o.useCallback(async q=>{const Pe=_r(B,q.id),$e=T[Pe];if(!$e)return;k(Pe,"stopping");try{await l.sendInput($e.sessionId,"")}catch{}if(await new Promise(R=>{window.setTimeout(R,1e3)}),Os.getState().getDirectoryState($e.directory)?.tabs.find(R=>R.id===$e.tabId)?.terminalSessionId===$e.sessionId){if(typeof l.forceKill=="function")try{await l.forceKill({sessionId:$e.sessionId})}catch{}else try{await l.close($e.sessionId)}catch{}P($e.directory,$e.tabId,null)}C(Pe),delete oe.current[Pe],L.current[Pe]?.(),delete L.current[Pe],window.clearTimeout(Y.current[Pe]),delete Y.current[Pe]},[B,T,C,P,l,k]),ae=o.useCallback(()=>{const q=Q??le[0];if(!q)return;const Pe=_r(B,q.id),$e=T[Pe];if($e?.status!=="stopping"){if($e){ue(q);return}W(q)}},[le,B,W,T,Q,ue]),U=o.useCallback((q,Pe=!1)=>{if(O(q.id),!Pe){W(q);return}const $e=_r(B,q.id),Ce=T[$e];if(Ce?.status!=="stopping"){if(Ce){ue(q);return}W(q)}},[B,W,T,ue]),G=o.useCallback(()=>{ge?.id&&(w(ge.id),h("projects"),x(!0))},[x,h,w,ge?.id]);if(u.isVSCode||!a&&d||!ge||!B)return null;const ne=Q??le[0]??null;if(!ne)return null;const se=ne.icon||"play",xe=ne.id===Zn?"search":Po[se]||"play",Se=Pv(ne.name,i("projectActions.label.fallbackAction")),je=_r(B,ne.id),Ie=T[je],Oe=Ie?.status==="stopping",Ne=Ie?.status==="waiting-for-preview",he=Ie?y.get(Ie.directory)?.tabs.find(q=>q.id===Ie.tabId)?.previewUrl??null:null,Fe=!!(Ie&&he),Be=()=>{!Ie||!he||b(Ie.directory,he)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:V||Oe,className:de("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:ae,"aria-label":Ie?i("projectActions.actions.stopNamedAria",{name:ne.name}):i("projectActions.actions.runNamedAria",{name:ne.name}),children:Oe||Ne?s.jsx(D,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):Ie?s.jsx(D,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(D,{name:xe,className:"h-5 w-5"})}),Fe?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.openPreview"),onClick:Be,children:s.jsx(D,{name:"global",className:"h-4 w-4"})})}),s.jsx(Rt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(ys,{children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(ws,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(vt,{className:"flex items-center gap-2",onClick:G,children:[s.jsx(D,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Ys,{}),le.map(q=>{const Pe=q.icon||"play",$e=q.id===Zn?"search":Po[Pe]||"play",Ce=_r(B,q.id),pe=T[Ce],R=!!pe,J=pe?.status==="stopping";return s.jsxs(vt,{className:"flex items-center gap-2",onClick:()=>{U(q,!0)},children:[s.jsx(D,{name:$e,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),J||pe?.status==="waiting-for-preview"?s.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):R?s.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]}):s.jsxs("div",{className:de("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:ae,disabled:V||Oe,className:de("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":Ie?i("projectActions.actions.stopNamedAria",{name:ne.name}):i("projectActions.actions.runNamedAria",{name:ne.name}),children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:Oe||Ne?s.jsx(D,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):Ie?s.jsx(D,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(D,{name:xe,className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:Se})]}),Fe?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Be,className:de(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(D,{name:"global",className:"h-4 w-4"})})}),s.jsx(Rt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(ys,{children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:de(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(ws,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs(vt,{className:"flex items-center gap-2",onClick:G,children:[s.jsx(D,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Ys,{}),le.map(q=>{const Pe=q.icon||"play",$e=q.id===Zn?"search":Po[Pe]||"play",Ce=_r(B,q.id),pe=T[Ce],R=!!pe,J=pe?.status==="stopping";return s.jsxs(vt,{className:"flex items-center gap-2",onClick:()=>{U(q)},children:[s.jsx(D,{name:$e,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),J||pe?.status==="waiting-for-preview"?s.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):R?s.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]})};function Vf(t){const e=st.c(33),{open:n,onOpenChange:r}=t,[a,i]=o.useState(""),[l,u]=o.useState(!0),d=Ft(Iv);let f,m;e[0]!==n?(f=()=>{n&&(i(""),u(!0))},m=[n],e[0]=n,e[1]=f,e[2]=m):(f=e[1],m=e[2]),o.useEffect(f,m);let c;e[3]!==d||e[4]!==a||e[5]!==r||e[6]!==l?(c=async()=>{const P=a.trim();P&&(await d(P,l),r(!1))},e[3]=d,e[4]=a,e[5]=r,e[6]=l,e[7]=c):c=e[7];const p=c;let g;e[8]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(bs,{children:s.jsx(hs,{children:"New Project"})}),e[8]=g):g=e[8];let h;e[9]===Symbol.for("react.memo_cache_sentinel")?(h=P=>i(P.target.value),e[9]=h):h=e[9];let x;e[10]!==p?(x=P=>{P.key==="Enter"&&p()},e[10]=p,e[11]=x):x=e[11];let w;e[12]!==a||e[13]!==x?(w=s.jsx(jt,{value:a,onChange:h,onKeyDown:x,placeholder:"Project name",autoFocus:!0}),e[12]=a,e[13]=x,e[14]=w):w=e[14];let b;e[15]===Symbol.for("react.memo_cache_sentinel")?(b=P=>u(P.target.checked),e[15]=b):b=e[15];let y;e[16]!==l?(y=s.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted-foreground cursor-pointer select-none",children:[s.jsx("input",{type:"checkbox",checked:l,onChange:b,className:"rounded border-border accent-primary w-4 h-4"}),"Copy project template (Remotion)"]}),e[16]=l,e[17]=y):y=e[17];let v;e[18]!==r?(v=s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>r(!1),children:"Cancel"}),e[18]=r,e[19]=v):v=e[19];let S;e[20]!==p?(S=s.jsx(ve,{size:"sm",onClick:()=>{p()},children:"Create"}),e[20]=p,e[21]=S):S=e[21];let I;e[22]!==v||e[23]!==S?(I=s.jsxs(Is,{children:[v,S]}),e[22]=v,e[23]=S,e[24]=I):I=e[24];let j;e[25]!==I||e[26]!==w||e[27]!==y?(j=s.jsxs(os,{className:"max-w-sm",children:[g,w,y,I]}),e[25]=I,e[26]=w,e[27]=y,e[28]=j):j=e[28];let N;return e[29]!==r||e[30]!==n||e[31]!==j?(N=s.jsx(ls,{open:n,onOpenChange:r,children:j}),e[29]=r,e[30]=n,e[31]=j,e[32]=N):N=e[32],N}function Iv(t){return t.createNewProject}function Dv(){const t=st.c(59),e=es(Ov),n=es(Lv),r=es(Fv),a=es(Rv),i=es(Mv),l=Ns(Ev),u=Ft(Av),[d,f]=o.useState(null),[m,c]=o.useState(""),[p,g]=o.useState(!1);let h;t[0]!==n||t[1]!==e?(h=e.find(X=>X.id===n)??null,t[0]=n,t[1]=e,t[2]=h):h=t[2];const x=h;let w;e:{if(!x){w="No Project";break e}let X;t[3]!==x.label||t[4]!==x.path?(X=x.label?.trim()||x.path.split(/[\\/]/).filter(Boolean).pop()||"Project",t[3]=x.label,t[4]=x.path,t[5]=X):X=t[5],w=X}const b=w;let y;t[6]!==l?(y=X=>{const ie=X.replace(/\\/g,"/").replace(/\/+$/,"");return l&&ie.startsWith(l)?"~"+ie.slice(l.length):ie},t[6]=l,t[7]=y):y=t[7];const v=y;let S;t[8]===Symbol.for("react.memo_cache_sentinel")?(S=X=>{f(X.id),c(X.label?.trim()||X.path.split(/[\\/]/).filter(Boolean).pop()||"")},t[8]=S):S=t[8];const I=S;let j;t[9]!==i||t[10]!==m||t[11]!==d?(j=()=>{d&&m.trim()&&(i(d,m.trim()),te.success("Project renamed")),f(null),c("")},t[9]=i,t[10]=m,t[11]=d,t[12]=j):j=t[12];const N=j;let P;t[13]!==a?(P=X=>{a(X.id),te.success("Project removed")},t[13]=a,t[14]=P):P=t[14];const M=P;let T;t[15]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(D,{name:"folder-6",className:"h-3.5 w-3.5 flex-shrink-0"}),t[15]=T):T=t[15];let E;t[16]!==b?(E=s.jsx("span",{className:"truncate max-w-[140px]",children:b}),t[16]=b,t[17]=E):E=t[17];let k;t[18]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 opacity-70"}),t[18]=k):k=t[18];let C;t[19]!==E?(C=s.jsx(vs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 h-8 px-2 rounded-md text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 typography-meta",children:[T,E,k]})}),t[19]=E,t[20]=C):C=t[20];let A;t[21]!==n||t[22]!==v||t[23]!==M||t[24]!==e||t[25]!==r||t[26]!==u?(A=e.length===0?s.jsx(vt,{disabled:!0,className:"typography-meta text-muted-foreground",children:"No projects"}):e.map(X=>{const ie=X.label?.trim()||X.path.split(/[\\/]/).filter(Boolean).pop()||"Project",le=X.id===n;return s.jsxs("div",{className:de("group flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer hover:bg-interactive-hover/50",le&&"bg-interactive-hover/50"),onClick:()=>{r(X.id),u({projectId:X.id,directoryOverride:X.path},{force:!0})},children:[le?s.jsx(D,{name:"check",className:"h-3.5 w-3.5 flex-shrink-0 text-primary"}):s.jsx("span",{className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate typography-meta text-foreground",children:ie}),s.jsx("div",{className:"truncate typography-micro text-muted-foreground/60",children:v(X.path)})]}),s.jsxs(ys,{children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Tv,className:"h-5 w-5 flex-shrink-0 flex items-center justify-center rounded text-foreground/70 opacity-0 group-hover:opacity-100 hover:text-foreground hover:bg-interactive-hover/50 focus:outline-none",children:s.jsx(D,{name:"more-2",className:"h-3 w-3"})})}),s.jsxs(ws,{align:"end",className:"min-w-[140px]",children:[s.jsxs(vt,{onClick:ye=>{ye.stopPropagation(),I(X)},children:[s.jsx(D,{name:"pencil-ai",className:"mr-1 h-3.5 w-3.5"}),"Rename"]}),s.jsx(Ys,{}),s.jsxs(vt,{onClick:ye=>{ye.stopPropagation(),M(X)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"close",className:"mr-1 h-3.5 w-3.5"}),"Remove"]})]})]})]},X.id)}),t[21]=n,t[22]=v,t[23]=M,t[24]=e,t[25]=r,t[26]=u,t[27]=A):A=t[27];let F;t[28]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(Ys,{}),t[28]=F):F=t[28];let _;t[29]===Symbol.for("react.memo_cache_sentinel")?(_=()=>g(!0),t[29]=_):_=t[29];let O;t[30]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsxs(vt,{onClick:_,className:"flex items-center gap-2",children:[s.jsx(D,{name:"add",className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-meta text-foreground",children:"New Project"})]}),t[30]=O):O=t[30];let V;t[31]!==A?(V=s.jsxs(ws,{align:"start",className:"w-[280px] max-h-[300px] overflow-y-auto",children:[A,F,O]}),t[31]=A,t[32]=V):V=t[32];let K;t[33]!==V||t[34]!==C?(K=s.jsxs(ys,{children:[C,V]}),t[33]=V,t[34]=C,t[35]=K):K=t[35];const $=d!==null;let oe;t[36]===Symbol.for("react.memo_cache_sentinel")?(oe=X=>{X||(f(null),c(""))},t[36]=oe):oe=t[36];let L;t[37]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(bs,{children:s.jsx(hs,{children:"Rename Project"})}),t[37]=L):L=t[37];let Y;t[38]===Symbol.for("react.memo_cache_sentinel")?(Y=X=>c(X.target.value),t[38]=Y):Y=t[38];let ee;t[39]!==N?(ee=X=>{X.key==="Enter"&&N()},t[39]=N,t[40]=ee):ee=t[40];let re;t[41]!==m||t[42]!==ee?(re=s.jsx(jt,{value:m,onChange:Y,onKeyDown:ee,placeholder:"Project name",autoFocus:!0}),t[41]=m,t[42]=ee,t[43]=re):re=t[43];let fe;t[44]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>{f(null),c("")},children:"Cancel"}),t[44]=fe):fe=t[44];let ge;t[45]!==N?(ge=s.jsxs(Is,{children:[fe,s.jsx(ve,{size:"sm",onClick:N,children:"Save"})]}),t[45]=N,t[46]=ge):ge=t[46];let be;t[47]!==re||t[48]!==ge?(be=s.jsxs(os,{className:"max-w-sm",children:[L,re,ge]}),t[47]=re,t[48]=ge,t[49]=be):be=t[49];let z;t[50]!==$||t[51]!==be?(z=s.jsx(ls,{open:$,onOpenChange:oe,children:be}),t[50]=$,t[51]=be,t[52]=z):z=t[52];let B;t[53]!==p?(B=s.jsx(Vf,{open:p,onOpenChange:g}),t[53]=p,t[54]=B):B=t[54];let Q;return t[55]!==K||t[56]!==z||t[57]!==B?(Q=s.jsxs(s.Fragment,{children:[K,z,B]}),t[55]=K,t[56]=z,t[57]=B,t[58]=Q):Q=t[58],Q}function Tv(t){return t.stopPropagation()}function Av(t){return t.setNewSessionDraftTarget}function Ev(t){return t.homeDirectory}function Mv(t){return t.renameProject}function Rv(t){return t.removeProject}function Fv(t){return t.setActiveProject}function Lv(t){return t.activeProjectId}function Ov(t){return t.projects}const hl="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",$v="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",Ir=o.memo(function(e){const n=st.c(13),{visible:r,title:a,ariaLabel:i,onClick:l,className:u,Icon:d,iconClassName:f}=e;if(!(r===void 0?!0:r))return null;const c=u??hl,p=f??"h-[18px] w-[18px]";let g;n[0]!==d||n[1]!==p?(g=s.jsx(D,{name:d,className:p}),n[0]=d,n[1]=p,n[2]=g):g=n[2];let h;n[3]!==i||n[4]!==l||n[5]!==c||n[6]!==g?(h=s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,"aria-label":i,className:c,children:g})}),n[3]=i,n[4]=l,n[5]=c,n[6]=g,n[7]=h):h=n[7];let x;n[8]!==a?(x=s.jsx(Rt,{children:s.jsx("p",{children:a})}),n[8]=a,n[9]=x):x=n[9];let w;return n[10]!==h||n[11]!==x?(w=s.jsxs(Tt,{children:[h,x]}),n[10]=h,n[11]=x,n[12]=w):w=n[12],w}),_v=o.memo(function(e){const n=st.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:l,githubLogin:u,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:f}=e,{t:m}=ct();if(!a?.connected||r)return null;if(i.length>1){let h;n[0]===Symbol.for("react.memo_cache_sentinel")?(h=de(hl,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=h):h=n[0];let x;n[1]!==u||n[2]!==m?(x=u?m("header.github.connectedWithLogin",{login:u}):m("header.github.connected"),n[1]=u,n[2]=m,n[3]=x):x=n[3];let w;n[4]!==l||n[5]!==u||n[6]!==m?(w=l?s.jsx("img",{src:l,alt:u?m("header.github.avatarWithLogin",{login:u}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=l,n[5]=u,n[6]=m,n[7]=w):w=n[7];let b;n[8]!==d||n[9]!==x||n[10]!==w?(b=s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:h,title:x,disabled:d,children:w})}),n[8]=d,n[9]=x,n[10]=w,n[11]=b):b=n[11];let y;n[12]!==m?(y=m("header.github.accountsTitle"),n[12]=m,n[13]=y):y=n[13];let v;n[14]!==y?(v=s.jsx(xi,{className:"typography-ui-header font-semibold text-foreground",children:y}),n[14]=y,n[15]=v):v=n[15];let S;n[16]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(Ys,{}),n[16]=S):S=n[16];let I;if(n[17]!==i||n[18]!==f||n[19]!==d||n[20]!==m){let P;n[22]!==f||n[23]!==d||n[24]!==m?(P=M=>{const T=M.user,E=!!M.current;return s.jsxs(vt,{className:"gap-2",disabled:E||d,onSelect:()=>{E||f(M.id)},children:[T?.avatarUrl?s.jsx("img",{src:T.avatarUrl,alt:T.login?m("header.github.avatarWithLogin",{login:T.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(D,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:T?.name?.trim()||T?.login||"GitHub"}),T?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:T.login}):null]}),E?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null]},M.id)},n[22]=f,n[23]=d,n[24]=m,n[25]=P):P=n[25],I=i.map(P),n[17]=i,n[18]=f,n[19]=d,n[20]=m,n[21]=I}else I=n[21];let j;n[26]!==v||n[27]!==I?(j=s.jsxs(ws,{align:"end",className:"w-64",children:[v,S,I]}),n[26]=v,n[27]=I,n[28]=j):j=n[28];let N;return n[29]!==b||n[30]!==j?(N=s.jsxs(ys,{children:[b,j]}),n[29]=b,n[30]=j,n[31]=N):N=n[31],N}let c;n[32]!==u||n[33]!==m?(c=u?m("header.github.connectedWithLogin",{login:u}):m("header.github.connected"),n[32]=u,n[33]=m,n[34]=c):c=n[34];let p;n[35]!==l||n[36]!==u||n[37]!==m?(p=l?s.jsx("img",{src:l,alt:u?m("header.github.avatarWithLogin",{login:u}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=l,n[36]=u,n[37]=m,n[38]=p):p=n[38];let g;return n[39]!==c||n[40]!==p?(g=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:c,children:p}),n[39]=c,n[40]=p,n[41]=g):g=n[41],g});o.memo(function(e){const n=st.c(76),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:l,setIsDesktopServicesOpen:u,refreshCurrentInstanceLabel:d,desktopServicesTab:f,setDesktopServicesTab:m,quotaResultsLength:c,fetchAllQuotas:p,servicesTabItems:g,quotaLastUpdated:h,quotaDisplayMode:x,quotaDisplayTabItems:w,handleDisplayModeChange:b,handleUsageRefresh:y,isQuotaLoading:v,isUsageRefreshSpinning:S,hasRateLimits:I,rateLimitGroups:j,expandedFamilies:N,toggleFamilyExpanded:P,shortcutLabel:M,showDevShutdown:T,isDevShutdownInFlight:E,onDevShutdown:k}=e,{t:C}=ct();let A;n[0]!==f||n[1]!==p||n[2]!==c||n[3]!==d||n[4]!==u?(A=X=>{u(X),X&&(d(),f==="usage"&&c===0&&p())},n[0]=f,n[1]=p,n[2]=c,n[3]=d,n[4]=u,n[5]=A):A=n[5];let F;n[6]!==a||n[7]!==r||n[8]!==C?(F=r?C("header.services.openWithCurrent",{current:a}):C("header.services.open"),n[6]=a,n[7]=r,n[8]=C,n[9]=F):F=n[9];const _=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let O;n[10]!==_?(O=de(hl,_),n[10]=_,n[11]=O):O=n[11];let V;n[12]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(D,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=V):V=n[12];let K;n[13]!==i||n[14]!==r?(K=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=K):K=n[15];let $;n[16]!==F||n[17]!==O||n[18]!==K?($=s.jsx(At,{asChild:!0,children:s.jsx(vs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":F,className:O,children:[V,K]})})}),n[16]=F,n[17]=O,n[18]=K,n[19]=$):$=n[19];let oe;n[20]!==a||n[21]!==r||n[22]!==M||n[23]!==C?(oe=r?C("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:M("toggle_services_menu"),nextTab:M("cycle_services_tab")}):C("header.services.tooltip.servicesWithShortcuts",{toggle:M("toggle_services_menu"),nextTab:M("cycle_services_tab")}),n[20]=a,n[21]=r,n[22]=M,n[23]=C,n[24]=oe):oe=n[24];let L;n[25]!==oe?(L=s.jsx(Rt,{children:s.jsx("p",{children:oe})}),n[25]=oe,n[26]=L):L=n[26];let Y;n[27]!==$||n[28]!==L?(Y=s.jsxs(Tt,{children:[$,L]}),n[27]=$,n[28]=L,n[29]=Y):Y=n[29];let ee;n[30]!==p||n[31]!==c||n[32]!==m?(ee=X=>{const ie=X;m(ie),ie==="usage"&&c===0&&p()},n[30]=p,n[31]=c,n[32]=m,n[33]=ee):ee=n[33];let re;n[34]!==f||n[35]!==g||n[36]!==ee?(re=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(ur,{items:g,activeId:f,onSelect:ee,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=f,n[35]=g,n[36]=ee,n[37]=re):re=n[37];let fe;n[38]!==f||n[39]!==r||n[40]!==l||n[41]!==u?(fe=r&&f==="instance"?s.jsx(ex,{embedded:!0,open:l&&f==="instance",onOpenChange:Bv,onHostSwitched:()=>u(!1)}):null,n[38]=f,n[39]=r,n[40]=l,n[41]=u,n[42]=fe):fe=n[42];let ge;n[43]!==f||n[44]!==l?(ge=f==="mcp"?s.jsx(Of,{active:l&&f==="mcp"}):null,n[43]=f,n[44]=l,n[45]=ge):ge=n[45];let be;n[46]!==f||n[47]!==N||n[48]!==b||n[49]!==y||n[50]!==I||n[51]!==v||n[52]!==S||n[53]!==x||n[54]!==w||n[55]!==h||n[56]!==j||n[57]!==C||n[58]!==P?(be=f==="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:C("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(ur,{items:w,activeId:x,onSelect:X=>{b(X)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:de("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:y,disabled:v||S,"aria-label":C("header.services.refreshRateLimitsAria"),children:s.jsx(D,{name:"refresh",className:de("h-4 w-4",S&&"animate-spin")})})]})]}),I?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:C("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:j.map((X,ie)=>{const le=N[X.providerId]??[];return s.jsxs(o.Fragment,{children:[ie>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(In,{providerId:X.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:X.providerName})]}),X.entries.length===0&&(!X.modelFamilies||X.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:X.error??C("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[X.entries.map(ye=>{const[W,ue]=ye,ae=x==="remaining"?ue.remainingPercent:ue.usedPercent,U=Mi(ue.usedPercent,ue.resetAt,ue.windowSeconds,W),G=U?.dailyAllocationPercent!=null?x==="remaining"?100-Er(U.elapsedRatio):Er(U.elapsedRatio):null,ne=Ei(ue.valueLabel,ae),se=cd(ue.resetAt,ue.resetAfterFormatted??ue.resetAtFormatted);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:dd(W)}),se?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:se}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ne==="-"?"":ne})]}),s.jsx(Fi,{percent:ae,tonePercent:ue.usedPercent,className:"h-1.5",expectedMarkerPercent:G}),U?s.jsx(Li,{paceInfo:U,compact:!0}):null]},`${X.providerId}-${W}`)}),X.modelFamilies&&X.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:X.modelFamilies.map(ye=>{const W=ye.familyId??"other",ue=le.includes(W);return s.jsxs(br,{open:ue,onOpenChange:()=>P(X.providerId,W),children:[s.jsxs(yr,{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:ye.familyLabel}),ue?s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(vr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:ye.models.map(ae=>{const[U,G]=ae,ne=x==="remaining"?G.remainingPercent:G.usedPercent,se=Mi(G.usedPercent,G.resetAt,G.windowSeconds),xe=se?.dailyAllocationPercent!=null?x==="remaining"?100-Er(se.elapsedRatio):Er(se.elapsedRatio):null,Se=Ei(G.valueLabel,ne);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:Ko(U)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Se==="-"?"":Se})]}),s.jsx(Fi,{percent:ne,tonePercent:G.usedPercent,className:"h-1.5",expectedMarkerPercent:xe}),se?s.jsx(Li,{paceInfo:se,compact:!0}):null]},`${X.providerId}-${U}`)})})})]},W)})}):null]})]},X.providerId)})})]}):null,n[46]=f,n[47]=N,n[48]=b,n[49]=y,n[50]=I,n[51]=v,n[52]=S,n[53]=x,n[54]=w,n[55]=h,n[56]=j,n[57]=C,n[58]=P,n[59]=be):be=n[59];let z;n[60]!==E||n[61]!==k||n[62]!==T||n[63]!==C?(z=T?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(vt,{disabled:E,onSelect:()=>{k()},children:C("header.services.shutdownDev")})})]}):null,n[60]=E,n[61]=k,n[62]=T,n[63]=C,n[64]=z):z=n[64];let B;n[65]!==re||n[66]!==fe||n[67]!==ge||n[68]!==be||n[69]!==z?(B=s.jsxs(ws,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[re,fe,ge,be,z]}),n[65]=re,n[66]=fe,n[67]=ge,n[68]=be,n[69]=z,n[70]=B):B=n[70];let Q;return n[71]!==l||n[72]!==A||n[73]!==Y||n[74]!==B?(Q=s.jsxs(ys,{open:l,onOpenChange:A,children:[Y,B]}),n[71]=l,n[72]=A,n[73]=Y,n[74]=B,n[75]=Q):Q=n[75],Q});const zv=(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??""),Uf=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},Kn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},so=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,Iu=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:a=null})=>{const{t:i}=ct(),l=De(we=>we.setSessionSwitcherOpen),u=De(we=>we.toggleSidebar),d=De(we=>we.isSidebarOpen),f=De(we=>we.isRightSidebarOpen),m=De(we=>we.toggleBottomTerminal),c=De(we=>we.toggleRightSidebar),p=De(we=>we.setSettingsDialogOpen),g=De(we=>we.toggleHelpDialog),h=De(we=>we.setAboutDialogOpen),x=De(we=>we.openContextOverview),w=De(we=>we.openContextPlan),b=De(we=>we.openContextBrowser),y=De(we=>we.closeContextPanel),v=De(we=>we.contextPanelByDirectory),S=De(we=>we.activeMainTab),I=De(we=>we.setActiveMainTab),j=De(we=>we.shortcutOverrides),N=ht(we=>we.getCurrentModel),P=wn(),[M,T]=o.useState(!1),[E,k]=o.useState(!1),C=tr(we=>we.available),A=tr(we=>we.checking),F=tr(we=>we.info),_=tr(we=>we.setUpdateDialogOpen),O=Ft(we=>we.getContextUsage),V=Ft(we=>we.openNewSessionDraft),K=Ft(we=>!!we.newSessionDraft?.open),$=Ft(we=>we.currentSessionId),oe=tx($??""),L=Qp($??null),Y=bi(we=>we.activeSessions),ee=Jp(),re=es(we=>we.activeProjectId?we.projects.find(at=>at.id===we.activeProjectId)??null:null),fe=o.useMemo(()=>{if(!re)return null;const we=re.label?.trim();if(we)return we;const at=re.path.split(/[\\/]/).filter(Boolean);return at[at.length-1]??null},[re]),ge=fs(we=>we.results),be=fs(we=>we.fetchAllQuotas),z=fs(we=>we.isLoading),B=fs(we=>we.lastUpdated),Q=fs(we=>we.displayMode),X=fs(we=>we.dropdownProviderIds),ie=fs(we=>we.loadSettings),le=fs(we=>we.setDisplayMode),{isMobile:ye}=_s(),W=zn(we=>we.status),ue=zn(we=>we.setStatus),ae=o.useRef(null),[U,G]=o.useState(()=>typeof window>"u"?!1:Us()),ne=o.useMemo(()=>Jc(),[]),se=ol(),[xe,Se]=o.useState(!1),je=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Ie=o.useMemo(()=>{if(typeof window>"u")return null;const we=window.__APP_MACOS_MAJOR__;if(typeof we=="number"&&Number.isFinite(we)&&we>0)return we;if(typeof navigator>"u")return null;const at=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!at)return null;const bt=Number.parseInt(at[1],10),Pt=Number.parseInt(at[2],10);return Number.isNaN(bt)?null:bt===10?Pt:bt},[]);Le.useEffect(()=>{typeof window>"u"||G(Us())},[]);const Oe=N(),Ne=Oe&&typeof Oe.limit=="object"&&Oe.limit!==null?Oe.limit:null,he=Ne&&typeof Ne.context=="number"?Ne.context:0,Fe=Ne&&typeof Ne.output=="number"?Ne.output:0,Be=O(he,Fe),[q,Pe]=o.useState(null),$e=!$||oe;Le.useEffect(()=>{if(!$){Pe(we=>we===null?we:null);return}if(Be&&Be.totalTokens>0){Pe(we=>zv(we,Be)?we:Be);return}$e&&Pe(we=>we===null?we:null)},[Be,$,$e]);const Ce=De(we=>we.isSessionSwitcherOpen),pe=W?.connected?W.user?.avatarUrl??null:null,R=W?.connected?W.user?.login??null:null,J=W?.accounts??[],[H,Ee]=o.useState(!1),[Ae,Je]=o.useState(!1),[ce,_e]=o.useState(!1),[et,Me]=o.useState(!1),[He,We]=o.useState(U?"instance":"usage"),[Te,Ve]=o.useState("usage");Le.useEffect(()=>{!U&&He==="instance"&&We("usage")},[He,U]);const Ye=o.useMemo(()=>Ks(),[]);o.useMemo(()=>ye?typeof t=="function"?!!n:Ce:d,[ye,Ce,d,n,t]);const Ge=!Ye&&S==="chat"&&!!q&&q.totalTokens>0,me=q&&q.contextLimit>0?Math.min(999,q.totalTokens/q.contextLimit*100):0;Ff();const Ke=fs(we=>we.selectedModels),ze=fs(we=>we.expandedFamilies),tt=fs(we=>we.toggleFamilyExpanded),it=o.useMemo(()=>{const we=[];for(const at of xr){if(!X.includes(at.id))continue;const bt=ge.find(ds=>ds.providerId===at.id),Pt=bt?.usage?.windows??{},Ht=bt?.usage?.models,xs=Object.entries(Pt),cs={providerId:at.id,providerName:at.name,entries:xs,error:bt&&!bt.ok&&bt.configured?bt.error:void 0};if(Ht&&Object.keys(Ht).length>0){const ds=Ke[at.id]??[],us=ds.length>0,rn=_y(Ht,at.id),an=Mf(at.id),mn=Rf(an);cs.modelFamilies=[];for(const Qs of mn){const on=rn.get(Qs.id)??[];if(on.length===0)continue;const $s=us?on.filter(fn=>ds.includes(fn)):on;if($s.length===0)continue;const Ln=[];for(const fn of $s){const mr=Ht[fn];if(mr?.windows){const ar=Object.entries(mr.windows);ar.length>0&&Ln.push([fn,ar[0][1]])}}Ln.length>0&&cs.modelFamilies.push({familyId:Qs.id,familyLabel:Qs.label,models:Ln})}const pn=rn.get(null)??[],zs=us?pn.filter(Qs=>ds.includes(Qs)):pn;if(zs.length>0){const Qs=[];for(const on of zs){const $s=Ht[on];if($s?.windows){const Ln=Object.entries($s.windows);Ln.length>0&&Qs.push([on,Ln[0][1]])}}Qs.length>0&&cs.modelFamilies.push({familyId:null,familyLabel:i("header.services.modelFamily.other"),models:Qs})}}(xs.length>0||cs.modelFamilies&&cs.modelFamilies.length>0||cs.error)&&we.push(cs)}return we},[X,ge,Ke,i]),qe=it.length>0;o.useEffect(()=>{ie()},[ie]);const Ze=o.useCallback(async we=>{le(we);try{await rs({usageDisplayMode:we})}catch(at){console.warn("Failed to update usage display mode:",at)}},[le]),Xe=o.useCallback(()=>{if(et)return;Me(!0);const we=new Promise(at=>setTimeout(at,500));Promise.all([be(),we]).finally(()=>{Me(!1)})},[be,et]),mt=o.useMemo(()=>$?ee.find(we=>we.id===$)??Y.find(we=>we.id===$)??L??sx().find(we=>we.id===$)??null:null,[$,L,Y,ee]),wt=o.useRef(null),[Et,dt]=o.useState(0);o.useEffect(()=>{if(!$){wt.current&&(wt.current=null,dt(Pt=>Pt+1));return}if(mt){wt.current={sessionId:$,session:mt,expiresAt:Date.now()+2e3};return}const we=wt.current;if(!we||we.sessionId!==$)return;const at=we.expiresAt-Date.now();if(at<=0){wt.current=null,dt(Pt=>Pt+1);return}const bt=window.setTimeout(()=>{wt.current?.sessionId===$&&(wt.current=null),dt(Pt=>Pt+1)},at);return()=>{window.clearTimeout(bt)}},[$,mt]);const gt=(()=>{if(mt)return mt;if(!$)return null;const we=wt.current;return we&&we.sessionId===$&&we.expiresAt>Date.now()?we.session:null})(),Wt=Ft(we=>$?we.worktreeMetadata.get($)?.path??"":"");Ft(we=>$?we.worktreeMetadata.get($)?.branch?.trim()??null:null);const Ot=nx(we=>$?we.getAttachment($):void 0);o.useMemo(()=>Ot?rx(Ot):null,[Ot]),o.useMemo(()=>Ot?Ot.legacy?"legacy":Ot.degraded?"degraded":Ot.worktreeStatus==="missing"?"missing":Ot.worktreeStatus==="invalid"?"invalid":Ot.attentionReason?"attention":null:null,[Ot]);const Bt=o.useMemo(()=>Kn(Wt||""),[Wt]),rt=o.useMemo(()=>{const we=typeof gt?.directory=="string"?gt.directory:"";return Kn(we||"")},[gt?.directory]),It=Ft(we=>we.newSessionDraft?.open?Kn(we.newSessionDraft.bootstrapPendingDirectory??we.newSessionDraft.directoryOverride??""):""),$t=o.useMemo(()=>Bt||rt||It,[It,rt,Bt]);Ft(we=>{const at=Kn(Bt||rt||"");if(!at)return null;for(const bt of we.availableWorktreesByProject.values()){const Ht=bt.find(xs=>Kn(xs.path)===at)?.branch?.trim();if(Ht)return Ht}return null}),ax($t||null),o.useMemo(()=>{if(!$)return fe??"Vinci";const we=gt?.title?.trim();return we&&we.length>0?we:"Untitled Session"},[fe,gt?.title,$]);const Ut=o.useMemo(()=>Xp(gt?.summary),[gt?.summary]),ms=o.useMemo(()=>Ut||{additions:0,deletions:0},[Ut]);ms.additions>0||ms.deletions>0;const ns=o.useMemo(()=>Kn($t||re?.path||""),[re?.path,$t]),Vt=o.useMemo(()=>re?{id:re.id,path:re.path}:null,[re]),Ue=o.useRef(null);o.useEffect(()=>{!Vt||!ns||(Ue.current={projectRef:Vt,directory:ns})},[ns,Vt]);const kt=o.useMemo(()=>Vt&&ns?{projectRef:Vt,directory:ns}:Ue.current,[ns,Vt]),Mt=Xc(we=>we.planModeEnabled),ut=Ft(we=>we.isSessionPlanAvailable),Kt=Mt&&$?ut($):!1,Yt=Kt,ks=o.useRef("");o.useEffect(()=>{if(!Mt){De.getState().activeMainTab==="plan"&&De.getState().setActiveMainTab("chat");return}if(!$)return;const we=`${$||"none"}:${rt||"none"}:${gt?.time?.created||0}:${gt?.slug||"none"}`;ks.current!==we&&(ks.current=we),!Kt&&De.getState().activeMainTab==="plan"&&De.getState().setActiveMainTab("chat")},[Mt,Kt,gt?.slug,gt?.time?.created,$,rt]);const Cs=o.useCallback(async we=>{if(!(!we||H)){Ee(!0);try{const at=P.github?await P.github.authActivate(we):await(async()=>{const bt=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:we})}),Pt=await bt.json().catch(()=>null);if(!bt.ok||!Pt)throw new Error(Pt?.error||bt.statusText);return Pt})();ue(at)}catch(at){console.error("Failed to switch GitHub account:",at)}finally{Ee(!1)}}},[H,P.github,ue]),Fs=o.useCallback(()=>{if(typeof document>"u")return;const we=document.activeElement;if(!we)return;const at=we.tagName;(at==="INPUT"||at==="TEXTAREA"||at==="SELECT"||we.isContentEditable)&&we.blur()},[]),Ls=o.useCallback(()=>{if(ye){Fs(),l(!Ce);return}u()},[Fs,ye,Ce,l,u]);o.useCallback(()=>{I("chat"),l(!1),V()},[V,I,l]);const dn=o.useCallback(()=>{_o("desktop_open_draft_mini_chat_window",{directory:Kn($t||re?.path||""),projectId:re?.id??null}).catch(we=>{console.warn("[header] failed to open draft mini chat window",we)})},[re?.id,re?.path,$t]),ft=o.useCallback(()=>{if(K){dn();return}$&&_o("desktop_open_session_mini_chat_window",{sessionId:$,directory:Kn($t||re?.path||"")}).catch(we=>{console.warn("[header] failed to open session mini chat window",we)})},[re?.path,$,dn,K,$t]),Es=o.useCallback(()=>{const we=Kn($t||"");if(!we)return;const at=v[we];if(so(at)==="context"){y(we);return}x(we)},[y,v,x,$t]),is=o.useMemo(()=>{const we=Kn($t||"");if(!we)return!1;const at=v[we];return so(at)==="context"},[v,$t]),Z=o.useCallback(()=>{const we=Kn($t||"");if(!we)return;const at=v[we];if(so(at)==="plan"){y(we);return}w(we)},[y,v,w,$t]),yt=o.useCallback(()=>{const we=Kn($t||"");we&&b(we)},[b,$t]),_t=o.useMemo(()=>{const we=Kn($t||"");if(!we)return!1;const at=v[we];return so(at)==="plan"},[v,$t]),gs=hl,Ps=$v,Ws=o.useMemo(()=>!d&&(U&&je&&!xe||se)?"pl-[5.5rem]":"pl-3",[U,xe,je,d,se]);Le.useEffect(()=>{if(!U||!je){Se(!1);return}let we=!1,at=null;const bt=async()=>{try{const{getCurrentWindow:Ht}=await Qn(async()=>{const{getCurrentWindow:ds}=await import("./vendor-.bun-DgrCmzWD.js").then(us=>us.bL);return{getCurrentWindow:ds}},__vite__mapDeps([0,1])),cs=await Ht().isFullscreen();we||Se(cs)}catch{we||Se(!1)}},Pt=async()=>{try{const{getCurrentWindow:Ht}=await Qn(async()=>{const{getCurrentWindow:cs}=await import("./vendor-.bun-DgrCmzWD.js").then(ds=>ds.bL);return{getCurrentWindow:cs}},__vite__mapDeps([0,1]));at=await Ht().onResized(()=>{bt()})}catch{}};return bt(),Pt(),()=>{we=!0,at&&at()}},[U,je]);const Ms=o.useMemo(()=>!U||!je||Ie===null?"":Ie>=26?"h-12":Ie<=15?"h-14":"",[U,je,Ie]),En=o.useMemo(()=>{if(!(U||Ye))return{paddingLeft:se&&!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))"}},[U,d,se,Ye]),Mn=o.useCallback(()=>{if(typeof document>"u")return;const we=ae.current?.getBoundingClientRect().height;we&&document.documentElement.style.setProperty("--oc-header-height",`${we}px`)},[]);Le.useEffect(()=>{if(typeof window>"u")return;Mn();const we=ae.current;if(!we||typeof ResizeObserver>"u")return()=>{};let at=0;const bt=()=>{at||(at=requestAnimationFrame(()=>{at=0,Mn()}))},Pt=new ResizeObserver(bt);return Pt.observe(we),window.addEventListener("resize",bt),window.addEventListener("orientationchange",bt),()=>{at&&cancelAnimationFrame(at),Pt.disconnect(),window.removeEventListener("resize",bt),window.removeEventListener("orientationchange",bt)}},[Mn]),Le.useEffect(()=>{Mn()},[Mn,ye,Ms]);const Jn=o.useCallback(async we=>{const at=we.target;at.closest(".app-region-no-drag")||at.closest("button, a, input, select, textarea")||we.button===0&&U&&await Zp()},[U]),Js=o.useMemo(()=>{if(ye){const we=[{id:"chat",label:i("layout.mainTab.chat"),icon:"chat-4"}];return Yt&&we.push({id:"plan",label:i("layout.mainTab.plan"),icon:"file-text"}),we.push({id:"diff",label:i("layout.mainTab.diff"),icon:"diff"},{id:"files",label:i("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:i("layout.mainTab.terminal"),icon:"terminal-box"}),we}return[]},[ye,Yt,i]),jn=o.useCallback(we=>ll(Ar(we,j)),[j]);Le.useEffect(()=>{!ye&&(S==="git"||S==="terminal"||S==="diff"||S==="files")&&I("chat")},[S,ye,I]);const Xs=o.useMemo(()=>{const we=[];return U&&we.push({value:"instance",label:i("layout.services.instance"),icon:"server"}),we.push({value:"usage",label:i("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:Qy}),we},[U,i]);o.useMemo(()=>Xs.map(we=>({id:we.value,label:we.label,icon:s.jsx(D,{name:we.icon,className:"h-3.5 w-3.5"})})),[Xs]),o.useMemo(()=>{if(typeof window>"u"||U||Ye)return!1;const we=window.location.hostname;return we==="localhost"||we==="127.0.0.1"||we==="::1"},[U,Ye]),o.useCallback(async()=>{if(M)return;T(!0),_e(!1);const we=[];let at=!1;try{try{for(const[,bt]of Os.getState().sessions.entries())for(const Pt of bt.tabs)Pt.previewUrl&&we.push(Pt.previewUrl)}catch{}try{await Kg({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:we})})).ok?at=!0:at=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{at||T(!1)}},[M,_e]);const Nn=o.useMemo(()=>[{value:"usage",label:i("header.services.used")},{value:"remaining",label:i("header.services.remaining")}],[i]);o.useMemo(()=>Nn.map(we=>({id:we.value,label:we.label})),[Nn]);const Sn=o.useMemo(()=>[{id:"usage",label:i("layout.services.usage"),icon:s.jsx(D,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(D,{name:"command",className:"h-3.5 w-3.5"})}],[i]);Le.useEffect(()=>{const we=at=>{if(Zc(at)&&!at.shiftKey&&!at.altKey){const bt=parseInt(at.key,10);bt>=1&&bt<=Js.length&&(at.preventDefault(),I(Js[bt-1].id))}};return window.addEventListener("keydown",we),()=>window.removeEventListener("keydown",we)},[Js,I]),Le.useEffect(()=>{const we=at=>{const bt=Ar("toggle_services_menu",j);if(jo(at,bt)){at.preventDefault(),ce?_e(!1):(_e(!0),He==="usage"&&ge.length===0&&be());return}const Pt=Ar("cycle_services_tab",j);if(jo(at,Pt)){at.preventDefault();const xs=Xs.map(rn=>rn.value);if(xs.length===0)return;const cs=xs.indexOf(He),ds=cs===-1?0:(cs+1)%xs.length,us=xs[ds];We(us),_e(!0),us==="usage"&&ge.length===0&&be();return}const Ht=Ar("toggle_context_plan",j);jo(at,Ht)&&(at.preventDefault(),Z())};return window.addEventListener("keydown",we),()=>window.removeEventListener("keydown",we)},[j,ce,He,Xs,ge.length,be,Z]);const Rn=we=>{const at=S===we.id,bt=we.icon==="diff",Pt=bt?null:we.icon,Ht=we.id==="chat",xs=ds=>bt?s.jsx(xu,{size:ds}):Pt?s.jsx(D,{name:Pt,className:`h-${ds/4} w-${ds/4}`}):null,cs=s.jsxs("button",{type:"button",onClick:()=>I(we.id),className:de("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",at?"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",Ht&&!ye&&"min-w-[100px] justify-center"),"aria-label":we.label,"aria-selected":at,role:"tab",children:[ye?xs(20):s.jsxs(s.Fragment,{children:[xs(16),s.jsx("span",{className:"header-tab-label",children:we.label})]}),we.badge!==void 0&&we.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:we.badge})]});return s.jsx(o.Fragment,{children:cs},we.id)},Fn=s.jsxs(s.Fragment,{children:[s.jsx(Ir,{title:i("sessions.sidebar.footer.actions.settings"),ariaLabel:i("sessions.sidebar.footer.actions.settings"),onClick:()=>p(!0),Icon:"settings-3"}),s.jsx(Ir,{title:i("sessions.sidebar.footer.actions.shortcuts"),ariaLabel:i("sessions.sidebar.footer.actions.shortcuts"),onClick:g,Icon:"question"}),C||A?s.jsx(Ir,{title:C&&F?.version?`Update v${F.version} available`:i("sessions.sidebar.updateCheck.latestVersion"),ariaLabel:i("sessions.sidebar.footer.actions.aboutVinci"),onClick:()=>_(!0),Icon:"download"}):null,s.jsx(Ir,{title:i("sessions.sidebar.footer.actions.aboutVinci"),ariaLabel:i("sessions.sidebar.footer.actions.aboutVinci"),onClick:()=>h(!0),Icon:"information"}),Yt&&s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.openPlanAria"),onClick:Z,className:de(gs,_t&&"bg-[var(--interactive-hover)]"),children:s.jsx(D,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(Rt,{children:s.jsx("p",{children:i("header.actions.planWithShortcut",{shortcut:jn("toggle_context_plan")})})})]}),s.jsx(Ir,{title:i("header.actions.terminalPanelWithShortcut",{shortcut:jn("toggle_terminal")}),ariaLabel:i("header.actions.toggleTerminalPanelAria"),onClick:m,Icon:"terminal-box"}),s.jsx(Ir,{title:"Context Panel",ariaLabel:"Toggle context panel",onClick:()=>{$t&&x($t)},Icon:"layout-column"}),ne?s.jsx(Ir,{title:i("contextPanel.browser.open"),ariaLabel:i("contextPanel.browser.open"),onClick:yt,Icon:"global"}):null,s.jsx(Ir,{title:i("header.actions.rightSidebarWithShortcut",{shortcut:jn("toggle_right_sidebar")}),ariaLabel:i("header.actions.toggleRightSidebarAria"),onClick:c,Icon:"layout-right"}),s.jsx(_v,{isMobile:ye,githubAuthStatus:W,githubAccounts:J,githubAvatarUrl:pe,githubLogin:R,isSwitchingGitHubAccount:H,handleGitHubAccountSwitch:Cs})]}),un=!f||!a,Bn=ne&&(K||!!$),Nt=()=>s.jsx("div",{onMouseDown:Jn,className:de("app-region-drag relative flex h-12 select-none items-center pr-3",Ws,Ms),style:En,role:"tablist","aria-label":i("header.navigation.mainAria"),children:s.jsxs("div",{className:de("flex min-w-0 flex-1 items-center"),children:[s.jsx(Dv,{}),s.jsxs("button",{type:"button","aria-label":i("sessions.sidebar.header.actions.addProject"),onClick:()=>k(!0),className:"inline-flex items-center gap-1.5 h-8 px-2.5 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 typography-meta shrink-0",children:[s.jsx(D,{name:"folder-add",className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{children:"New Project"})]}),kt&&s.jsx(Pu,{projectRef:kt.projectRef,directory:kt.directory,className:"mr-2"}),Js.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Js.map(we=>Rn(we))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ge&&q?s.jsx(ix,{totalTokens:q.totalTokens,percentage:me,colorPercentage:q.percentage,contextLimit:q.contextLimit,outputLimit:q.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:Es,pressed:is,className:un&&!Bn?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Ir,{visible:Bn,title:i(K?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:i(K?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:ft,className:de(gs,un&&Ge?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),un?Fn:null,!un&&a?gi.createPortal(Fn,a):null]})]})}),Lt=()=>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:de(Ps,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":i(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(D,{name:"layout-left",className:"h-5 w-5"})}):Ce?s.jsx("button",{type:"button",onClick:()=>l(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":i("header.actions.backAria"),children:s.jsx(D,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Ls,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":i("header.actions.openSessionsAria"),children:s.jsx(D,{name:"play-list-add",className:"h-5 w-5"})}),Ce&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:i("header.sessions.title")})]}),!Ce&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":i("header.navigation.mainAria"),children:Js.map(we=>{const at=S===we.id,bt=we.icon==="diff",Pt=bt?null:we.icon;return s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{ye&&Fs(),I(we.id)},"aria-label":we.label,"aria-selected":at,role:"tab",className:de(Ps,"relative rounded-lg",at&&"bg-interactive-selection text-interactive-selection-foreground"),children:[bt?s.jsx(xu,{className:"h-5 w-5"}):Pt?s.jsx(D,{name:Pt,className:"h-5 w-5"}):null,we.badge!==void 0&&we.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:we.badge}),we.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":i("header.changes.availableAria")})]})}),s.jsx(Rt,{children:s.jsx("p",{children:we.label})})]},we.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[kt&&s.jsx(Pu,{projectRef:kt.projectRef,directory:kt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(ys,{open:Ae,onOpenChange:we=>{Je(we),we&&ge.length===0&&be()},children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.services.viewAria"),className:Ps,children:s.jsx(D,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Rt,{children:s.jsx("p",{children:i("header.services.title")})})]}),s.jsx(ws,{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(ur,{items:Sn,activeId:Te,onSelect:we=>{const at=we;Ve(at),at==="usage"&&ge.length===0&&be()},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:()=>Je(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":i("header.services.closeAria"),children:s.jsx(D,{name:"close",className:"h-5 w-5"})})]})}),Te==="mcp"&&s.jsx(Of,{active:Ae&&Te==="mcp"}),Te==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:i("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Uf(B)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>Ze("usage"),className:de("typography-ui-label px-1 pb-0.5 transition-colors",Q==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>Ze("remaining"),className:de("typography-ui-label px-1 pb-0.5 transition-colors",Q==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.remaining")})]}),s.jsx("button",{type:"button",className:de("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:Xe,disabled:z||et,"aria-label":i("header.services.refreshRateLimitsAria"),children:s.jsx(D,{name:"refresh",className:de("h-4 w-4",et&&"animate-spin")})})]})]})}),!qe&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:i("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:it.map((we,at)=>s.jsxs(o.Fragment,{children:[at>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(In,{providerId:we.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:we.providerName})]}),we.entries.length===0&&(!we.modelFamilies||we.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:we.error??i("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[we.entries.map(([bt,Pt])=>{const Ht=Q==="remaining"?Pt.remainingPercent:Pt.usedPercent,xs=Mi(Pt.usedPercent,Pt.resetAt,Pt.windowSeconds,bt),cs=xs?.dailyAllocationPercent!=null?Q==="remaining"?100-Er(xs.elapsedRatio):Er(xs.elapsedRatio):null,ds=Ei(Pt.valueLabel,Ht),us=cd(Pt.resetAt,Pt.resetAfterFormatted??Pt.resetAtFormatted);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:dd(bt)}),us?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:us}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:ds==="-"?"":ds})]}),s.jsx(Fi,{percent:Ht,tonePercent:Pt.usedPercent,className:"h-1.5",expectedMarkerPercent:cs}),xs?s.jsx(Li,{paceInfo:xs,compact:!0}):null]},`${we.providerId}-${bt}`)}),we.modelFamilies&&we.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:we.modelFamilies.map(bt=>{const Ht=(ze[we.providerId]??[]).includes(bt.familyId??"other");return s.jsxs(br,{open:Ht,onOpenChange:()=>tt(we.providerId,bt.familyId??"other"),children:[s.jsxs(yr,{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:bt.familyLabel}),Ht?s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(vr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:bt.models.map(([xs,cs])=>{const ds=Q==="remaining"?cs.remainingPercent:cs.usedPercent,us=Mi(cs.usedPercent,cs.resetAt,cs.windowSeconds),rn=us?.dailyAllocationPercent!=null?Q==="remaining"?100-Er(us.elapsedRatio):Er(us.elapsedRatio):null,an=Ei(cs.valueLabel,ds);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:Ko(xs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:an==="-"?"":an})]}),s.jsx(Fi,{percent:ds,tonePercent:cs.usedPercent,className:"h-1.5",expectedMarkerPercent:rn}),us?s.jsx(Li,{paceInfo:us,compact:!0}):null]},`${we.providerId}-${xs}`)})})})]},bt.familyId??"other")})})]})]},we.providerId))})]})]})})]}),e?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:de(Ps,"relative",r&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(D,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Rt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Gt=de("header-safe-area relative z-30",ye&&"border-b border-border/50","bg-background");return s.jsxs("header",{ref:ae,className:Gt,style:{"--padding-scale":"1"},children:[ye?Lt():Nt(),s.jsx(Vf,{open:E,onOpenChange:k})]})};function Bv(){}const Du=180,Tu=640,Vv=110,Uv=t=>{const e=st.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=ct(),l=De(Kv),u=De(Wv),d=De(Hv),f=De(Gv),[m,c]=o.useState(null),[p,g]=o.useState(!1),h=o.useRef(null),x=o.useRef(0),w=o.useRef(l||300),b=Math.min(Tu,Math.max(Du,l||300));let y,v;e[0]!==n?(y=()=>{n||(c(null),g(!1))},v=[n],e[0]=n,e[1]=y,e[2]=v):(y=e[1],v=e[2]),o.useEffect(y,v);let S,I;e[3]!==u||e[4]!==r||e[5]!==n?(S=()=>{if(r||!n||!u)return;const ee=()=>{const ge=h.current?.parentElement?.getBoundingClientRect().height;if(!ge||ge<=0)return;const be=Math.max(0,Math.round(ge));c(z=>z===be?z:be)};ee();const re=h.current?.parentElement;if(!re)return;const fe=new ResizeObserver(ee);return fe.observe(re),()=>{fe.disconnect()}},I=[u,r,n],e[3]=u,e[4]=r,e[5]=n,e[6]=S,e[7]=I):(S=e[6],I=e[7]),o.useEffect(S,I);let j,N;if(e[8]!==u||e[9]!==r||e[10]!==p||e[11]!==d||e[12]!==f?(j=()=>{if(r||!p||u)return;const ee=fe=>{const ge=x.current-fe.clientY,be=Math.min(Tu,Math.max(Du,w.current+ge));d(be)},re=()=>{g(!1),De.getState().bottomTerminalHeight<=Vv&&f(!1)};return window.addEventListener("pointermove",ee),window.addEventListener("pointerup",re,{once:!0}),()=>{window.removeEventListener("pointermove",ee),window.removeEventListener("pointerup",re)}},N=[u,r,p,d,f],e[8]=u,e[9]=r,e[10]=p,e[11]=d,e[12]=f,e[13]=j,e[14]=N):(j=e[13],N=e[14]),o.useEffect(j,N),r)return null;const P=n?u?Math.max(0,m??b):b:0,M=n&&u;let T;e[15]!==P||e[16]!==u||e[17]!==n?(T=ee=>{!n||u||(g(!0),x.current=ee.clientY,w.current=P,ee.preventDefault())},e[15]=P,e[16]=u,e[17]=n,e[18]=T):T=e[18];const E=T,k=M?"absolute inset-x-0 bottom-0 z-40":"relative",C=p?"transition-none":"transition-[height] duration-300 ease-in-out",A=!n&&"border-t-0";let F;e[19]!==A||e[20]!==k||e[21]!==C?(F=de("flex overflow-hidden border-t border-border bg-sidebar",k,C,A),e[19]=A,e[20]=k,e[21]=C,e[22]=F):F=e[22];let _;e[23]!==P||e[24]!==M?(_=M?{top:"var(--oc-header-height, 48px)"}:{height:`${P}px`,minHeight:`${P}px`,maxHeight:`${P}px`},e[23]=P,e[24]=M,e[25]=_):_=e[25];const O=!n||!u&&P===0;let V;e[26]!==E||e[27]!==u||e[28]!==n||e[29]!==p||e[30]!==i?(V=n&&!u&&s.jsx("div",{className:de("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",p&&"bg-[var(--interactive-border)]"),onPointerDown:E,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=E,e[27]=u,e[28]=n,e[29]=p,e[30]=i,e[31]=V):V=e[31];const K=!n&&"pointer-events-none select-none opacity-0";let $;e[32]!==K?($=de("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",K),e[32]=K,e[33]=$):$=e[33];const oe=!n;let L;e[34]!==a||e[35]!==$||e[36]!==oe?(L=s.jsx("div",{className:$,"aria-hidden":oe,children:a}),e[34]=a,e[35]=$,e[36]=oe,e[37]=L):L=e[37];let Y;return e[38]!==F||e[39]!==_||e[40]!==O||e[41]!==V||e[42]!==L?(Y=s.jsxs("section",{ref:h,className:F,style:_,"aria-hidden":O,children:[V,L]}),e[38]=F,e[39]=_,e[40]=O,e[41]=V,e[42]=L,e[43]=Y):Y=e[43],Y};function Kv(t){return t.bottomTerminalHeight}function Wv(t){return t.isBottomTerminalExpanded}function Hv(t){return t.setBottomTerminalHeight}function Gv(t){return t.setBottomTerminalOpen}const kc=280,Au=280,Eu=500,qv=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=ct(),i=De(S=>S.sidebarWidth),l=De(S=>S.setSidebarWidth),[u,d]=o.useState(!1),f=o.useRef(0),m=o.useRef(i||kc),c=o.useRef(null),p=o.useRef(null),g=o.useRef(null),h=o.useCallback(S=>Math.min(Eu,Math.max(Au,S)),[]),x=o.useCallback(S=>{const I=g.current;I&&I.style.setProperty("--oc-left-sidebar-width",`${S}px`)},[]);if(o.useEffect(()=>{e&&u&&d(!1)},[e,u]),o.useEffect(()=>{u||(c.current=null,p.current=null)},[u]),e)return null;const w=t?Math.min(Eu,Math.max(Au,i||kc)):0,b=S=>{if(t){try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}p.current=S.pointerId,d(!0),f.current=S.clientX,m.current=w,c.current=w,x(w),S.preventDefault()}},y=S=>{if(e||!u||p.current!==S.pointerId)return;const I=S.clientX-f.current,j=h(m.current+I);c.current!==j&&(c.current=j,x(j))},v=S=>{if(p.current!==S.pointerId||e)return;try{S.currentTarget.releasePointerCapture(S.pointerId)}catch{}const I=h(c.current??w);p.current=null,c.current=null,d(!1),l(I)};return s.jsxs("aside",{ref:g,className:de("relative flex h-full overflow-hidden border-r border-border/40","bg-sidebar",u?"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":`${u?c.current??w:w}px`,overflowX:"clip"},"aria-hidden":!t||w===0,children:[t&&s.jsx("div",{className:de("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",u&&"bg-[var(--interactive-border)]"),onPointerDown:b,onPointerMove:y,onPointerUp:v,onPointerCancel:v,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:de("relative z-10 flex h-full flex-col transition-opacity duration-300 ease-in-out",u&&"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(As,{children:n})})})]})},Kf=420,Mu=200,Ru=860,Yv=({isOpen:t,children:e,className:n,onTopActionsHostChange:r})=>{const{t:a}=ct(),i=De(M=>M.rightSidebarWidth),l=De(M=>M.setRightSidebarWidth),u=o.useMemo(()=>Us(),[]),d=o.useMemo(()=>Ks(),[]),f=ol(),[m,c]=o.useState(!1),p=o.useRef(0),g=o.useRef(i||420),h=o.useRef(null),x=o.useRef(null),w=o.useRef(null),b=o.useCallback(M=>Math.min(Ru,Math.max(Mu,M)),[]),y=o.useCallback(M=>{const T=w.current;T&&T.style.setProperty("--oc-right-sidebar-width",`${M}px`)},[]),v=t?Math.min(Ru,Math.max(Mu,i||Kf)):0,S=M=>{if(t){try{M.currentTarget.setPointerCapture(M.pointerId)}catch{}x.current=M.pointerId,c(!0),p.current=M.clientX,g.current=v,h.current=v,y(v),M.preventDefault()}},I=M=>{if(!m||x.current!==M.pointerId)return;const T=p.current-M.clientX,E=b(g.current+T);h.current!==E&&(h.current=E,y(E))},j=M=>{if(x.current!==M.pointerId)return;try{M.currentTarget.releasePointerCapture(M.pointerId)}catch{}const T=b(h.current??v);x.current=null,h.current=null,c(!1),l(T)};o.useEffect(()=>{m||(h.current=null,x.current=null)},[m]),o.useEffect(()=>{t||r?.(null)},[t,r]);const N=o.useCallback(async M=>{const T=M.target;T.closest(".app-region-no-drag")||T.closest("button, a, input, select, textarea")||M.button===0&&u&&await Zp()},[u]),P=o.useMemo(()=>{if(!(u||d))return{paddingLeft:"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",...f?{paddingTop:"var(--oc-safe-area-top, 0px)"}:null}},[u,f,d]);return s.jsxs("aside",{ref:w,className:de("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??v:v}px`,overflowX:"clip"},"aria-hidden":!t||v===0,children:[t?s.jsx("div",{onMouseDown:N,className:de("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:P,"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:de("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:I,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:de("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})]})},Qv=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),Jv=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=Qv.format(t);return e.endsWith(".0")?e.slice(0,-2):e},Ui=({providerId:t,modelId:e,onChange:n,className:r,allowedProviderIds:a,placeholder:i})=>{const{t:l}=ct(),{isReady:u,isUnavailable:d}=ef(),f=ht(z=>z.providers),m=ht(z=>z.modelsMetadata),c=De(z=>z.isMobile),p=De(z=>z.hiddenModels),g=De(z=>z.toggleFavoriteModel),h=De(z=>z.isFavoriteModel),x=De(z=>z.addRecentModel),{favoriteModelsList:w,recentModelsList:b}=ox(),{isMobile:y}=_s(),v=c||y,[S,I]=o.useState(!1),[j,N]=o.useState(new Set),[P,M]=o.useState(!1),[T,E]=o.useState(""),[k,C]=o.useState(0),A=o.useRef([]),F=o.useMemo(()=>!Array.isArray(a)||a.length===0?null:new Set(a),[a]),_=o.useMemo(()=>(F?f.filter(B=>F.has(String(B.id))):f).map(B=>{const X=(Array.isArray(B.models)?B.models:[]).filter(ie=>{const le=typeof ie?.id=="string"?ie.id:"";return!p.some(ye=>ye.providerID===String(B.id)&&ye.modelID===le)});return{...B,models:X}}).filter(B=>B.models.length>0),[f,F,p]),O=()=>I(!1),V=z=>{N(B=>{const Q=new Set(B);return Q.has(z)?Q.delete(z):Q.add(z),Q})};o.useEffect(()=>{P||(E(""),C(0))},[P]),o.useEffect(()=>{C(0)},[T]);const K=z=>{const B=z?.name||z?.id||"",Q=String(B);return Q.length>40?Q.substring(0,37)+"...":Q},$=(z,B)=>{const Q=`${z}/${B}`;return m.get(Q)},oe=(z,B)=>{n(z,B),z&&B&&x(z,B),M(!1)},L=(z,B)=>{if(!T.trim())return!0;const Q=T.toLowerCase();return z.toLowerCase().includes(Q)||B.toLowerCase().includes(Q)},Y=(z,B,Q,X,ie,le)=>{const ye=$(B,Q),W=Jv(ye?.limit?.context),ue=t===B&&e===Q,ae=h(B,Q),U=X==="fav"||X==="recent";return s.jsxs(vt,{ref:G=>{A.current[ie]=G},className:de("group flex items-center gap-2",le&&"bg-interactive-selection"),onSelect:()=>oe(B,Q),onMouseEnter:()=>C(ie),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[U&&s.jsx(In,{providerId:B,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:K(z)}),W?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:W}):null]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[ue&&s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}),s.jsx("button",{onClick:G=>{G.preventDefault(),G.stopPropagation(),g(B,Q)},className:de("model-favorite-button flex h-4 w-4 items-center justify-center hover:text-primary/80",ae?"text-primary":"text-muted-foreground"),"aria-label":l(ae?"settings.agents.modelSelector.actions.unfavorite":"settings.agents.modelSelector.actions.favorite"),title:l(ae?"settings.agents.modelSelector.actions.removeFromFavorites":"settings.agents.modelSelector.actions.addToFavorites"),children:ae?s.jsx(D,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"star",className:"h-3.5 w-3.5"})})]})]},`${X}-${B}-${Q}`)},ee=w.filter(({model:z,providerID:B})=>{if(F&&!F.has(B))return!1;const X=f.find(le=>le.id===B)?.name||B,ie=K(z);return L(ie,X)}),re=b.filter(({model:z,providerID:B})=>{if(F&&!F.has(B))return!1;const X=f.find(le=>le.id===B)?.name||B,ie=K(z);return L(ie,X)}),fe=_.map(z=>{const Q=(Array.isArray(z.models)?z.models:[]).filter(X=>{const ie=K(X);return L(ie,z.name||z.id||"")});return{...z,models:Q}}).filter(z=>z.models.length>0),ge=ee.length>0||re.length>0||fe.length>0,be=()=>v?s.jsx(hr,{open:S,onClose:O,title:l("settings.agents.modelSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[w.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:l("settings.agents.modelSelector.section.favorites")}),s.jsx("div",{className:"border-t border-border/20",children:w.map(({model:z,providerID:B,modelID:Q})=>{const X=B===t&&Q===e;return s.jsxs("div",{className:de("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",X?"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:()=>{oe(B,Q),O()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(In,{providerId:B,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:K(z)})]})}),s.jsx("button",{onClick:ie=>{ie.preventDefault(),ie.stopPropagation(),g(B,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":l("settings.agents.modelSelector.actions.unfavorite"),children:s.jsx(D,{name:"star-fill",className:"h-4 w-4"})})]},`fav-mobile-${B}-${Q}`)})})]}),b.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:l("settings.agents.modelSelector.section.recents")}),s.jsx("div",{className:"border-t border-border/20",children:b.map(({model:z,providerID:B,modelID:Q})=>{const X=B===t&&Q===e;return s.jsxs("div",{className:de("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",X?"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:()=>{oe(B,Q),O()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(In,{providerId:B,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:K(z)})]})}),s.jsx("button",{onClick:ie=>{ie.preventDefault(),ie.stopPropagation(),g(B,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":l("settings.agents.modelSelector.actions.favorite"),children:s.jsx(D,{name:"star",className:"h-4 w-4"})})]},`recent-mobile-${B}-${Q}`)})})]}),_.map(z=>{const B=Array.isArray(z.models)?z.models:[];if(B.length===0)return null;const Q=z.id===t,X=j.has(z.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(z.id),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(In,{providerId:z.id,className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:z.name}),Q&&s.jsx("span",{className:"typography-micro text-primary/80",children:l("settings.agents.modelSelector.badge.current")})]}),X?s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"}):s.jsx(D,{name:"arrow-right-s",className:"h-3 w-3 text-muted-foreground"})]}),X&&s.jsx("div",{className:"border-t border-border/20",children:B.map(ie=>{const le=z.id===t&&ie.id===e;return s.jsxs("div",{className:de("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:()=>{oe(z.id,ie.id),O()},children:s.jsx("span",{className:"font-medium truncate",children:K(ie)})}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx("button",{onClick:ye=>{ye.preventDefault(),ye.stopPropagation(),g(z.id,ie.id)},className:de("flex h-8 w-8 items-center justify-center active:scale-95 touch-manipulation hover:text-primary/80",h(z.id,ie.id)?"text-primary":"text-muted-foreground/50"),"aria-label":h(z.id,ie.id)?l("settings.agents.modelSelector.actions.unfavorite"):l("settings.agents.modelSelector.actions.favorite"),children:h(z.id,ie.id)?s.jsx(D,{name:"star-fill",className:"h-4 w-4"}):s.jsx(D,{name:"star",className:"h-4 w-4"})}),le&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]})]},ie.id)})})]},z.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:()=>{oe("",""),O()},children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:i||l("settings.agents.modelSelector.noModelOptional")})})]})}):null;return s.jsxs(s.Fragment,{children:[v?s.jsxs("button",{type:"button",onClick:u?()=>I(!0):void 0,disabled:!u,className:de("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",!u&&"opacity-60 cursor-not-allowed",r),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[u?t?s.jsx(In,{providerId:t,className:"h-3.5 w-3.5"}):s.jsx(D,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),u&&s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t&&e?`${t}/${e}`:i||l("settings.agents.modelSelector.selectPlaceholder")})]}),s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):s.jsxs(ys,{open:u&&P,onOpenChange:u?M:void 0,children:[s.jsx(vs,{asChild:!0,children:s.jsxs("div",{className:de("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:[u?s.jsxs(s.Fragment,{children:[t?s.jsxs(s.Fragment,{children:[s.jsx(In,{providerId:t,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx(D,{name:"pencil-ai",className:"h-3 w-3 text-primary/60 hidden"})]}):s.jsx(D,{name:"pencil-ai",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-foreground",children:t&&e?`${t}/${e}`:i||l("settings.agents.modelSelector.notSelected")})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsx(ws,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:(()=>{const z=[];ee.forEach(({model:ie,providerID:le,modelID:ye})=>{z.push({model:ie,providerID:le,modelID:ye,section:"fav"})}),re.forEach(({model:ie,providerID:le,modelID:ye})=>{z.push({model:ie,providerID:le,modelID:ye,section:"recent"})}),fe.forEach(ie=>{ie.models.forEach(le=>{z.push({model:le,providerID:ie.id,modelID:le.id,section:"provider"})})});const B=z.length,Q=ie=>{if(ie.stopPropagation(),ie.key==="ArrowDown"){ie.preventDefault();const le=(k+1)%Math.max(1,B);C(le),setTimeout(()=>{A.current[le]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(ie.key==="ArrowUp"){ie.preventDefault();const le=(k-1+Math.max(1,B))%Math.max(1,B);C(le),setTimeout(()=>{A.current[le]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(ie.key==="Enter"){ie.preventDefault();const le=z[k];le&&oe(le.providerID,le.modelID)}else ie.key==="Escape"&&(ie.preventDefault(),M(!1))};let X=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(D,{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(jt,{type:"text",placeholder:l("settings.agents.modelSelector.searchPlaceholder"),value:T,onChange:ie=>E(ie.target.value),onKeyDown:Q,className:"pl-8 h-8 typography-meta",autoFocus:!0})]})}),s.jsx(ts,{outerClassName:"max-h-[min(400px,calc(100dvh-12rem))] flex-1",children:s.jsxs("div",{className:"p-1",children:[s.jsxs(vt,{className:de("flex items-center gap-2"),onSelect:()=>oe("",""),children:[s.jsx(D,{name:"close",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-muted-foreground",children:i||l("settings.agents.modelSelector.notSelected")}),!t&&!e&&s.jsx(D,{name:"check",className:"h-4 w-4 text-primary ml-auto"})]}),s.jsx(Ys,{}),!ge&&T&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("settings.agents.modelSelector.state.noModelsFound")}),ee.length>0&&s.jsxs("div",{children:[s.jsxs(xi,{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(D,{name:"star-fill",className:"h-4 w-4 text-primary"}),l("settings.agents.modelSelector.section.favorites")]}),ee.map(({model:ie,providerID:le,modelID:ye})=>{const W=X++;return Y(ie,le,ye,"fav",W,k===W)})]}),re.length>0&&s.jsxs("div",{children:[ee.length>0&&s.jsx(Ys,{}),s.jsxs(xi,{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(D,{name:"time",className:"h-4 w-4"}),l("settings.agents.modelSelector.section.recent")]}),re.map(({model:ie,providerID:le,modelID:ye})=>{const W=X++;return Y(ie,le,ye,"recent",W,k===W)})]}),(ee.length>0||re.length>0)&&fe.length>0&&s.jsx(Ys,{}),fe.map((ie,le)=>s.jsxs("div",{children:[le>0&&s.jsx(Ys,{}),s.jsxs(xi,{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(In,{providerId:ie.id,className:"h-4 w-4 flex-shrink-0"}),ie.name]}),ie.models.map(ye=>{const W=X++;return Y(ye,ie.id,ye.id,"provider",W,k===W)})]},ie.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:l("settings.agents.modelSelector.keyboardHints")})]})})()})]}),be()]})},gl=t=>{const e=st.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:l}=ct(),{isReady:u,isUnavailable:d}=ef(),f=ht(Xv),m=_a(Zv),c=_a(e1),p=ht(t1);let g;e:{if(Array.isArray(f)&&f.length>0){g=f;break e}let O;e[0]!==m?(O=Array.isArray(m)?m:[],e[0]=m,e[1]=O):O=e[1],g=O}const h=g;let x;if(e[2]!==i||e[3]!==h){const O=lx(h);x=i?O.filter(i):O,e[2]=i,e[3]=h,e[4]=x}else x=e[4];const w=x,b=De(s1),{isMobile:y}=_s(),v=b||y,[S,I]=o.useState(!1);let j,N;e[5]!==c||e[6]!==p||e[7]!==h.length?(j=()=>{h.length>0||(p(),c())},N=[h.length,p,c],e[5]=c,e[6]=p,e[7]=h.length,e[8]=j,e[9]=N):(j=e[8],N=e[9]),o.useEffect(j,N);let P;e[10]===Symbol.for("react.memo_cache_sentinel")?(P=()=>I(!1),e[10]=P):P=e[10];const M=P;let T;e[11]!==r?(T=O=>{r(O)},e[11]=r,e[12]=T):T=e[12];const E=T;let k;e[13]!==n||e[14]!==w||e[15]!==E||e[16]!==v||e[17]!==S||e[18]!==l?(k=()=>v?s.jsx(hr,{open:S,onClose:M,title:l("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:de("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:()=>{E(""),M()},children:[s.jsx("span",{className:de("typography-meta",n?"text-muted-foreground":"font-medium"),children:l("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),w.map(O=>{const V=O.name===n;return s.jsxs("button",{type:"button",className:de("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:()=>{E(O.name),M()},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]=w,e[15]=E,e[16]=v,e[17]=S,e[18]=l,e[19]=k):k=e[19];const C=k;let A;e[20]!==n||e[21]!==w||e[22]!==a||e[23]!==E||e[24]!==v||e[25]!==u||e[26]!==d||e[27]!==l?(A=v?s.jsxs("button",{type:"button",onClick:u?()=>I(!0):void 0,disabled:!u,className:de("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",!u&&"opacity-60 cursor-not-allowed",a),children:[s.jsx("div",{className:"flex items-center gap-2",children:u?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:n||l("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]})}),s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):u?s.jsxs(ys,{children:[s.jsx(vs,{asChild:!0,children:s.jsxs("div",{className:de("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 cursor-pointer hover:bg-interactive-hover/30 h-6 w-fit",a),children:[s.jsx(D,{name:"robot-2",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap",children:n||l("settings.commands.agentSelector.notSelected")}),s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(ws,{className:"max-w-[300px]",children:[s.jsx(vt,{className:"typography-meta",onSelect:()=>E(""),children:s.jsx("span",{className:"text-muted-foreground",children:l("settings.commands.agentSelector.notSelected")})}),w.map(O=>s.jsx(vt,{className:"typography-meta",onSelect:()=>E(O.name),children:s.jsx("span",{className:"font-medium",children:O.name})},O.name))]})]}):s.jsxs("div",{className:de("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60",a),children:[s.jsx(D,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=w,e[22]=a,e[23]=E,e[24]=v,e[25]=u,e[26]=d,e[27]=l,e[28]=A):A=e[28];let F;e[29]!==C?(F=C(),e[29]=C,e[30]=F):F=e[30];let _;return e[31]!==A||e[32]!==F?(_=s.jsxs(s.Fragment,{children:[A,F]}),e[31]=A,e[32]=F,e[33]=_):_=e[33],_};function Xv(t){return t.agents}function Zv(t){return t.agents}function e1(t){return t.loadAgents}function t1(t){return t.loadAgents}function s1(t){return t.isMobile}const Fu=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),n1=t=>{const e=st.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:l}=ct();let u;e[0]!==l||e[1]!==n?(u=n||l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=l,e[1]=n,e[2]=u):u=e[2];const d=u,f=a?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==f?(m=de("flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2",f),e[3]=f,e[4]=m):m=e[4];let c;e[5]!==d?(c=s.jsx("span",{className:"typography-micro whitespace-nowrap font-medium capitalize",children:d}),e[5]=d,e[6]=c):c=e[6];let p;e[7]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=p):p=e[7];let g;e[8]!==m||e[9]!==c?(g=s.jsxs("div",{className:m,children:[c,p]}),e[8]=m,e[9]=c,e[10]=g):g=e[10];const h=g;if(a)return h;let x;e[11]!==h?(x=s.jsx(vs,{asChild:!0,children:h}),e[11]=h,e[12]=x):x=e[12];let w;e[13]!==i?(w=()=>i(""),e[13]=i,e[14]=w):w=e[14];const b=!n&&"text-primary";let y;e[15]!==b?(y=de("font-medium",b),e[15]=b,e[16]=y):y=e[16];let v;e[17]!==l?(v=l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=l,e[18]=v):v=e[18];let S;e[19]!==y||e[20]!==v?(S=s.jsx("span",{className:y,children:v}),e[19]=y,e[20]=v,e[21]=S):S=e[21];let I;e[22]!==S||e[23]!==w?(I=s.jsx(vt,{className:"typography-meta",onSelect:w,children:S}),e[22]=S,e[23]=w,e[24]=I):I=e[24];let j;if(e[25]!==i||e[26]!==r||e[27]!==n){let M;e[29]!==i||e[30]!==n?(M=T=>s.jsx(vt,{className:"typography-meta",onSelect:()=>i(T),children:s.jsx("span",{className:de("font-medium capitalize",n===T&&"text-primary"),children:T})},T),e[29]=i,e[30]=n,e[31]=M):M=e[31],j=r.map(M),e[25]=i,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let N;e[32]!==I||e[33]!==j?(N=s.jsxs(ws,{align:"start",className:"max-w-[220px]",children:[I,j]}),e[32]=I,e[33]=j,e[34]=N):N=e[34];let P;return e[35]!==N||e[36]!==x?(P=s.jsxs(ys,{children:[x,N]}),e[35]=N,e[36]=x,e[37]=P):P=e[37],P};function Wf(t){const e=st.c(99),{t:n}=ct(),{open:r,onOpenChange:a,target:i,projectDirectory:l,submitting:u,onConfirm:d}=t,f=u===void 0?!1:u,m=ht(p1),c=ht(m1),p=_a(u1),g=ht(d1),h=ht(c1),x=ht(l1),w=ht(o1),b=ht(i1);let y;e[0]!==b||e[1]!==x||e[2]!==h||e[3]!==w?(y=()=>Fu({providerID:h,modelID:x,variant:w,agent:b}),e[0]=b,e[1]=x,e[2]=h,e[3]=w,e[4]=y):y=e[4];const[v,S]=o.useState(y);let I,j;e[5]!==p||e[6]!==c||e[7]!==m||e[8]!==r||e[9]!==l?(I=()=>{r&&(m({directory:l}),c({directory:l}),p())},j=[r,m,c,p,l],e[5]=p,e[6]=c,e[7]=m,e[8]=r,e[9]=l,e[10]=I,e[11]=j):(I=e[10],j=e[11]),o.useEffect(I,j);let N,P;e[12]!==b||e[13]!==x||e[14]!==h||e[15]!==w||e[16]!==r?(N=()=>{r&&S(Fu({providerID:h,modelID:x,variant:w,agent:b}))},P=[r,h,x,w,b],e[12]=b,e[13]=x,e[14]=h,e[15]=w,e[16]=r,e[17]=N,e[18]=P):(N=e[17],P=e[18]),o.useEffect(N,P);let M,T;e[19]!==v.modelID||e[20]!==v.providerID||e[21]!==r||e[22]!==g?(M=()=>{if(!r||g.length===0)return;const Ie=g.find(Fe=>Fe.id===v.providerID)??g[0],Oe=Array.isArray(Ie?.models)?Ie.models:[],Ne=Oe.some(Fe=>Fe.id===v.modelID),he=Oe[0]?.id??"";Ie?.id===v.providerID&&Ne||S(Fe=>({...Fe,providerID:Ie?.id??"",modelID:Ne?Fe.modelID:he,variant:""}))},T=[r,g,v.providerID,v.modelID],e[19]=v.modelID,e[20]=v.providerID,e[21]=r,e[22]=g,e[23]=M,e[24]=T):(M=e[23],T=e[24]),o.useEffect(M,T);const E=a1;let k;if(e[25]!==v.modelID||e[26]!==v.providerID||e[27]!==g){let Ie;e[29]!==v.providerID?(Ie=Ne=>Ne.id===v.providerID,e[29]=v.providerID,e[30]=Ie):Ie=e[30],k=g.find(Ie)?.models?.find(Ne=>Ne.id===v.modelID),e[25]=v.modelID,e[26]=v.providerID,e[27]=g,e[28]=k}else k=e[28];const C=k;let A;e[31]!==C?(A=C?.variants?Object.keys(C.variants):[],e[31]=C,e[32]=A):A=e[32];const F=A,_=F.length>0;let O,V;e[33]!==v.variant||e[34]!==_?(O=()=>{_||!v.variant||S(r1)},V=[_,v.variant],e[33]=v.variant,e[34]=_,e[35]=O,e[36]=V):(O=e[35],V=e[36]),o.useEffect(O,V);let K;e[37]!==v.modelID||e[38]!==v.providerID?(K=v.providerID.trim().length>0&&v.modelID.trim().length>0,e[37]=v.modelID,e[38]=v.providerID,e[39]=K):K=e[39];const $=K;let oe;e[40]!==$||e[41]!==v||e[42]!==d||e[43]!==f?(oe=()=>{!$||f||d(v)},e[40]=$,e[41]=v,e[42]=d,e[43]=f,e[44]=oe):oe=e[44];const L=oe;let Y,ee;e[45]!==L||e[46]!==r?(Y=()=>{if(!r)return;const Ie=Oe=>{(Oe.metaKey||Oe.ctrlKey)&&Oe.key==="Enter"&&(Oe.preventDefault(),L())};return window.addEventListener("keydown",Ie),()=>window.removeEventListener("keydown",Ie)},ee=[r,L],e[45]=L,e[46]=r,e[47]=Y,e[48]=ee):(Y=e[47],ee=e[48]),o.useEffect(Y,ee);let re;e[49]!==n||e[50]!==i?(re=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=re):re=e[51];const fe=re;let ge;e[52]!==a||e[53]!==f?(ge=Ie=>{f||a(Ie)},e[52]=a,e[53]=f,e[54]=ge):ge=e[54];let be;e[55]!==fe?(be=s.jsx(bs,{children:s.jsx(hs,{children:fe})}),e[55]=fe,e[56]=be):be=e[56];let z;e[57]===Symbol.for("react.memo_cache_sentinel")?(z=(Ie,Oe)=>{S(Ne=>({...Ne,providerID:Ie,modelID:Oe,variant:""}))},e[57]=z):z=e[57];let B;e[58]!==v.modelID||e[59]!==v.providerID?(B=s.jsx(Ui,{providerId:v.providerID,modelId:v.modelID,onChange:z}),e[58]=v.modelID,e[59]=v.providerID,e[60]=B):B=e[60];const Q=!_;let X;e[61]===Symbol.for("react.memo_cache_sentinel")?(X=Ie=>S(Oe=>({...Oe,variant:Ie})),e[61]=X):X=e[61];let ie;e[62]!==v.variant||e[63]!==Q||e[64]!==F?(ie=s.jsx(n1,{value:v.variant,options:F,disabled:Q,onChange:X}),e[62]=v.variant,e[63]=Q,e[64]=F,e[65]=ie):ie=e[65];let le;e[66]===Symbol.for("react.memo_cache_sentinel")?(le=Ie=>S(Oe=>({...Oe,agent:Ie})),e[66]=le):le=e[66];let ye;e[67]!==v.agent?(ye=s.jsx(gl,{agentName:v.agent,filter:E,onChange:le}),e[67]=v.agent,e[68]=ye):ye=e[68];let W;e[69]!==B||e[70]!==ie||e[71]!==ye?(W=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[B,ie,ye]}),e[69]=B,e[70]=ie,e[71]=ye,e[72]=W):W=e[72];let ue;e[73]!==a?(ue=()=>a(!1),e[73]=a,e[74]=ue):ue=e[74];let ae;e[75]!==n?(ae=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=ae):ae=e[76];let U;e[77]!==f||e[78]!==ue||e[79]!==ae?(U=s.jsx(ve,{variant:"ghost",size:"sm",onClick:ue,disabled:f,children:ae}),e[77]=f,e[78]=ue,e[79]=ae,e[80]=U):U=e[80];const G=!$||f;let ne;e[81]!==f||e[82]!==n?(ne=n(f?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=f,e[82]=n,e[83]=ne):ne=e[83];let se;e[84]!==L||e[85]!==G||e[86]!==ne?(se=s.jsx(ve,{size:"sm",onClick:L,disabled:G,children:ne}),e[84]=L,e[85]=G,e[86]=ne,e[87]=se):se=e[87];let xe;e[88]!==U||e[89]!==se?(xe=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[U,se]}),e[88]=U,e[89]=se,e[90]=xe):xe=e[90];let Se;e[91]!==be||e[92]!==W||e[93]!==xe?(Se=s.jsxs(os,{className:"max-w-lg",children:[be,W,xe]}),e[91]=be,e[92]=W,e[93]=xe,e[94]=Se):Se=e[94];let je;return e[95]!==r||e[96]!==ge||e[97]!==Se?(je=s.jsx(ls,{open:r,onOpenChange:ge,children:Se}),e[95]=r,e[96]=ge,e[97]=Se,e[98]=je):je=e[98],je}function r1(t){return{...t,variant:""}}function a1(t){return tf(t.mode)}function i1(t){return t.currentAgentName||""}function o1(t){return t.currentVariant||""}function l1(t){return t.currentModelId}function c1(t){return t.currentProviderId}function d1(t){return t.providers}function u1(t){return t.loadAgents}function m1(t){return t.loadAgents}function p1(t){return t.loadProviders}const Cc=5,Hf=15,Io=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},f1=(t,e)=>{const n=Io(e);return Math.max(n*Cc,Math.min(n*Hf,n*t))},h1=async(t,e)=>{const n=await mx(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},g1=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,x1=t=>{const e=st.c(20),{id:n,children:r}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:i,listeners:l,setNodeRef:u,setActivatorNodeRef:d,transform:f,transition:m,isDragging:c}=rl(a);let p;e[2]!==f?(p=al.Transform.toString(f),e[2]=f,e[3]=p):p=e[3];let g;e[4]!==p||e[5]!==m?(g={transform:p,transition:m},e[4]=p,e[5]=m,e[6]=g):g=e[6];const h=c&&"opacity-60";let x;e[7]!==h?(x=de(h),e[7]=h,e[8]=x):x=e[8];let w;e[9]!==i||e[10]!==r||e[11]!==c||e[12]!==l||e[13]!==d?(w=r({attributes:i,listeners:l,setActivatorNodeRef:d,isDragging:c}),e[9]=i,e[10]=r,e[11]=c,e[12]=l,e[13]=d,e[14]=w):w=e[14];let b;return e[15]!==u||e[16]!==g||e[17]!==x||e[18]!==w?(b=s.jsx("li",{ref:u,style:g,className:x,children:w}),e[15]=u,e[16]=g,e[17]=x,e[18]=w,e[19]=b):b=e[19],b},b1=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=ct(),[l,u]=o.useState(!1),[d,f]=o.useState(""),[m,c]=o.useState([]),[p,g]=o.useState(""),[h,x]=o.useState(null),[w,b]=o.useState(()=>new Set),[y,v]=o.useState([]),[S,I]=o.useState(null),[j,N]=o.useState(!1),[P,M]=o.useState(0),T=o.useRef(!1),E=o.useRef(""),k=De(R=>R.todoPanelHeight),C=De(R=>R.setTodoPanelHeight),A=De(R=>R.notesPanelHeight),F=De(R=>R.setNotesPanelHeight),[_,O]=o.useState(!1),V=o.useRef(0),K=o.useRef(k),$=Ft(R=>R.currentSessionId),oe=Ft(R=>R.createSession),L=Ft(R=>R.initializeNewSession),Y=Ft(R=>R.sendMessage),ee=Ft(R=>R.setCurrentSession),re=_i(R=>R.setPendingInputText),fe=Ns(R=>R.currentDirectory),ge=De(R=>R.openContextPanelTab),be=De(R=>R.setActiveMainTab),z=De(R=>R.setSessionSwitcherOpen),B=De(R=>R.padding),Q=o.useCallback(async(R,J)=>{if(!t)return!1;const H=await cx(t,{notes:R,todos:J});return H||te.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),H},[t,i]);o.useEffect(()=>{if(!t){f(""),c([]),v([]),g(""),b(new Set);return}let R=!1;return u(!0),(async()=>{try{const J=await dx(t),H=await Promise.all(J.plans.map(Ee=>h1(Ee,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(R)return;f(J.notes),c(J.todos),v(H),E.current=J.notes,T.current=!0,g(""),b(new Set)}catch{R||(te.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),f(""),c([]),v([]),E.current="",T.current=!0)}finally{R||u(!1)}})(),()=>{R=!0}},[P,t,i]),o.useEffect(()=>{if(!t)return;const R=J=>{const H=J.detail;H?.projectId&&H.projectId!==t.id||M(Ee=>Ee+1)};return window.addEventListener("vinci:project-plan-saved",R),window.addEventListener("vinci:project-notes-updated",R),()=>{window.removeEventListener("vinci:project-plan-saved",R),window.removeEventListener("vinci:project-notes-updated",R)}},[t]),o.useEffect(()=>{if(m.length<7)return;const R=f1(m.length,B),J=Io(B)*Cc;(k<J||k>R)&&C(R)},[m.length,B,k,C]),o.useEffect(()=>{if(!_)return;const R=H=>{const Ee=H.clientY-V.current,Ae=Math.min(Io(B)*Hf,Math.max(Io(B)*Cc,K.current+Ee));C(Ae)},J=()=>{O(!1)};return window.addEventListener("pointermove",R),window.addEventListener("pointerup",J,{once:!0}),window.addEventListener("pointercancel",J,{once:!0}),()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",J),window.removeEventListener("pointercancel",J)}},[_,B,C]);const X=o.useCallback(R=>{O(!0),V.current=R.clientY,K.current=k,R.preventDefault()},[k]),ie=o.useCallback(()=>{E.current=d,Q(d,m)},[d,Q,m]);o.useEffect(()=>{if(!t||!T.current||d===E.current)return;const R=window.setTimeout(()=>{E.current=d,Q(d,m)},400);return()=>{window.clearTimeout(R)}},[d,Q,t,m]);const le=o.useCallback(()=>{const R=p.trim();if(!R)return;const J=[...m,{id:g1(),text:R.slice(0,Ji),completed:!1,createdAt:Date.now()}];c(J),g(""),Q(d,J)},[p,d,Q,m]),ye=o.useCallback(R=>{b(J=>{const H=new Set(J);return H.has(R)?H.delete(R):H.add(R),H})},[]),W=o.useCallback((R,J)=>{const H=m.map(Ee=>Ee.id===R?{...Ee,completed:J}:Ee);c(H),Q(d,H)},[d,Q,m]),ue=o.useCallback(R=>{const J=m.filter(H=>H.id!==R);c(J),Q(d,J)},[d,Q,m]),ae=o.useCallback(()=>{const R=m.filter(J=>!J.completed);R.length!==m.length&&(c(R),Q(d,R))},[d,Q,m]),U=o.useCallback(R=>{const{active:J,over:H}=R;if(!H||J.id===H.id)return;const Ee=m.findIndex(ce=>ce.id===J.id),Ae=m.findIndex(ce=>ce.id===H.id);if(Ee===-1||Ae===-1)return;const Je=Bp(m,Ee,Ae);c(Je),Q(d,Je)},[d,Q,m]),G=ji(Ma(Ni,{activationConstraint:{distance:8}})),ne=p.slice(0,Ji),se=m.reduce((R,J)=>R+(J.completed?1:0),0),xe=o.useCallback(()=>{be("chat"),z(!1)},[be,z]),Se=o.useCallback((R,J)=>{!t||h||I({kind:"session",todoId:R,todoText:J})},[t,h]),je=o.useCallback(R=>{if(!$){te.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}xe();const J=`\`\`\`md
4
4
  ${R}
5
5
  \`\`\``;re(J,"append"),te.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[$,r,xe,re,i]),Ie=o.useCallback((R,J)=>{if(!(!t||h)){if(!n){te.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}I({kind:"worktree",todoId:R,todoText:J})}},[n,t,h,i]),Oe=o.useCallback(async R=>{if(!t||!S)return;const J=await Ur("plan.todo.visible",{todo_text:S.todoText}),Ee=[{synthetic:!0,text:await Ur("plan.todo.instructions",{todo_text:S.todoText})}];N(!0),x(S.todoId);try{xe();let Ae=null,Je=t.path;if(S.kind==="worktree"){if(!n){te.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const _e=await sf(t.path,nf());if(!_e?.id)return;Ae=_e.id,Je=null}else{const _e=await oe(void 0,t.path,null);if(!_e?.id){te.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}Ae=_e.id,Je=_e.directory??t.path,L(_e.id,ht.getState().agents??[])}if(!Ae)return;const ce=ed.getState();ce.saveSessionModelSelection(Ae,R.providerID,R.modelID),R.agent.trim()&&(ce.saveSessionAgentSelection(Ae,R.agent),ce.saveAgentModelForSession(Ae,R.agent,R.providerID,R.modelID),ce.saveAgentModelVariantForSession(Ae,R.agent,R.providerID,R.modelID,R.variant||void 0)),ee(Ae,Je),await Y(J,R.providerID,R.modelID,R.agent.trim()||void 0,void 0,void 0,Ee,R.variant||void 0),te.success(S.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),I(null),r?.()}catch(Ae){const Je=Ae instanceof Error?Ae.message:void 0;te.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Je?{description:Je}:void 0)}finally{N(!1),x(null)}},[n,oe,L,r,S,t,xe,Y,ee,i]),Ne=o.useRef(null),[he,Fe]=o.useState(!1),[Be,q]=o.useState(null),Pe=o.useCallback(async R=>{if(!(!t||Be)){q(R);try{if(!await ux(t,R)){te.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}v(H=>H.filter(Ee=>Ee.id!==R)),window.dispatchEvent(new CustomEvent("vinci:project-plan-saved",{detail:{projectId:t.id}}))}finally{q(null)}}},[Be,t,i]),$e=o.useCallback(async()=>{if(!t||he)return;const R=await rf({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(R.success&&R.path){Fe(!0);try{const J=new URLSearchParams({path:R.path,allowOutsideWorkspace:"true"}),H=await fetch(`/api/fs/read?${J.toString()}`,{cache:"no-store"});if(!H.ok){te.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const Ee=await H.text();if(!Ee.trim()){te.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Ae=R.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await Vd(t,Ee,Ae)){te.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("vinci:project-plan-saved",{detail:{projectId:t.id}})),te.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(J){const H=J instanceof Error?J.message:void 0;te.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),H?{description:H}:void 0)}finally{Fe(!1)}}else R.error==="Native file picker not available"&&Ne.current?.click()},[he,t,i]),Ce=o.useCallback(async R=>{if(!(!t||!R)){Fe(!0);try{const J=await R.text();if(!J.trim()){te.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const H=R.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await Vd(t,J,H)){te.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("vinci:project-plan-saved",{detail:{projectId:t.id}})),te.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(J){const H=J instanceof Error?J.message:void 0;te.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),H?{description:H}:void 0)}finally{Fe(!1)}}},[t,i]),pe=o.useCallback(R=>{const J=t?.path?.trim(),H=fe?.trim()||J;H&&ge(H,{mode:"plan",targetPath:R.path,dedupeKey:R.path,label:R.title})},[fe,ge,t]);return t?s.jsxs("div",{className:de("w-full min-w-0 space-y-3 p-3",a),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:i("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d.length,"/",Ud]})]}),s.jsx(nn,{value:d,onChange:R=>f(R.target.value.slice(0,Ud)),onBlur:ie,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:A,onResizeHeightChange:F,useScrollShadow:!0,scrollShadowSize:56,disabled:l})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:ae,disabled:l||se===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:i("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[ne.length,"/",Ji]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(jt,{value:ne,onChange:R=>g(R.target.value.slice(0,Ji)),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),le())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:l,className:"h-8"}),s.jsx("button",{type:"button",onClick:le,disabled:l||ne.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.addAria"),title:i("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(D,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:de("overflow-y-auto rounded-lg border border-border/60 bg-background/40",_&&"transition-none"),style:m.length<7?void 0:{height:`${k}px`,maxHeight:`${k}px`},children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(Si,{sensors:G,collisionDetection:ki,onDragEnd:U,children:s.jsx(Oo,{items:m.map(R=>R.id),strategy:xc,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(R=>{const J=w.has(R.id);return s.jsx(x1,{id:R.id,children:H=>s.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("button",{type:"button",ref:H.setActivatorNodeRef,...H.attributes,...H.listeners,onClick:Ee=>{Ee.preventDefault(),Ee.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:R.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:R.text}),children:s.jsx(D,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(ss,{checked:R.completed,onChange:Ee=>W(R.id,Ee),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:R.text})})}),s.jsx("button",{type:"button",onClick:()=>ye(R.id),className:de("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-6 text-foreground",J?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",R.completed&&"text-muted-foreground line-through"),title:J?void 0:R.text,"aria-label":J?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:R.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:R.text}),children:R.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>ue(R.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:R.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:R.text}),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(ys,{children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",disabled:h===R.id,className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.send",{text:R.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:R.text}),children:s.jsx(D,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(ws,{align:"end",className:"w-56",children:[s.jsx(vt,{onClick:()=>je(R.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(vt,{onClick:()=>Se(R.id,R.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(vt,{onClick:()=>{Ie(R.id,R.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},R.id)})})})})}),m.length>=7&&s.jsx("div",{className:de("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",_&&"bg-[var(--interactive-border)]"),onPointerDown:X,role:"separator","aria-orientation":"horizontal","aria-label":i("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:y.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:y.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:y.length})})]}),s.jsx("input",{ref:Ne,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:R=>{const J=R.target.files?.[0]??null;Ce(J),R.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:$e,disabled:!t||he,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.plans.importFromFile"),title:i("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(D,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:y.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:y.map(R=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>pe(R),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:R.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(R.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Pe(R.id)},disabled:Be===R.id,className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",title:i("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":i("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:R.title}),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},R.id))})})]}),s.jsx(Wf,{open:S!==null,onOpenChange:R=>{!R&&!j&&I(null)},target:S?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:Oe})]}):s.jsx("div",{className:de("w-full min-w-0 p-3",a),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},y1=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"},v1=async(t,e)=>{if(t.readFile)return(await t.readFile(e,{allowOutsideWorkspace:!0,optional:!0})).content??"";const n=new URLSearchParams({path:e,allowOutsideWorkspace:"true",optional:"true"}),r=await fetch(`/api/fs/read?${n.toString()}`,{cache:"no-store"});if(!r.ok){const a=await r.json().catch(()=>({error:r.statusText}));throw new Error(a.error||"Failed to read file")}return r.text()},md=async(t,e)=>{try{return await v1(t,e),{ok:!0}}catch(n){return{ok:!1,reason:y1(n)}}},pd=t=>t==="missing"?"File not found":"Failed to open file",w1=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,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Gf=(t,e)=>{const n=bn(e),r=bn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},j1=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),N1=new Set(["node_modules"]),S1=t=>N1.has(t),k1=t=>{const e=bn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},qf=(t,e)=>s.jsx(dr,{filePath:t,extension:e}),C1=t=>{const e=st.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const a=r[n];let i;return e[1]!==a?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:a}}),e[1]=a,e[2]=i):i=e[2],i},P1=t=>{const e=st.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:l,badge:u,permissions:d,downloadFile:f,contextMenuPath:m,setContextMenuPath:c,onSelect:p,onToggle:g,onRevealPath:h,onOpenDialog:x}=t,{t:w}=ct(),b=n.type==="directory",{canRename:y,canCreateFile:v,canCreateFolder:S,canDelete:I,canReveal:j}=d;let N;e[0]!==v||e[1]!==S||e[2]!==I||e[3]!==y||e[4]!==j||e[5]!==n.path||e[6]!==c?(N=ee=>{!y&&!v&&!S&&!I&&!j||(ee?.preventDefault(),c(n.path))},e[0]=v,e[1]=S,e[2]=I,e[3]=y,e[4]=j,e[5]=n.path,e[6]=c,e[7]=N):N=e[7];const P=N;let M;e[8]!==b||e[9]!==n||e[10]!==p||e[11]!==g?(M=()=>{b?g(n.path):p(n)},e[8]=b,e[9]=n,e[10]=p,e[11]=g,e[12]=M):M=e[12];const T=M;let E;e[13]!==n.path||e[14]!==c?(E=ee=>{ee.stopPropagation(),c(n.path)},e[13]=n.path,e[14]=c,e[15]=E):E=e[15];const k=E;let C;e[16]!==n.path||e[17]!==r?(C=ee=>{const re=Gf(r,n.path);!re||re==="."||(ee.dataTransfer.setData("application/x-vinci-file-path",re),ee.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=C):C=e[18];const A=C,F=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let _;e[19]!==F?(_=de("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",F,"cursor-grab active:cursor-grabbing"),e[19]=F,e[20]=_):_=e[20];let O;e[21]!==b||e[22]!==a||e[23]!==n.extension||e[24]!==n.path?(O=b?a?s.jsx(D,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(D,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):qf(n.path,n.extension),e[21]=b,e[22]=a,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 K;e[29]!==b||e[30]!==l?(K=!b&&l&&s.jsx(C1,{status:l}),e[29]=b,e[30]=l,e[31]=K):K=e[31];let $;e[32]!==u||e[33]!==b?($=b&&u&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[u.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",u.modified]}),u.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",u.added]})]}),e[32]=u,e[33]=b,e[34]=$):$=e[34];let oe;e[35]!==P||e[36]!==A||e[37]!==T||e[38]!==$||e[39]!==_||e[40]!==O||e[41]!==V||e[42]!==K?(oe=s.jsxs("button",{type:"button",onClick:T,onContextMenu:P,draggable:!0,onDragStart:A,className:_,children:[O,V,K,$]}),e[35]=P,e[36]=A,e[37]=T,e[38]=$,e[39]=_,e[40]=O,e[41]=V,e[42]=K,e[43]=oe):oe=e[43];let L;e[44]!==v||e[45]!==S||e[46]!==I||e[47]!==y||e[48]!==j||e[49]!==m||e[50]!==f||e[51]!==k||e[52]!==b||e[53]!==n||e[54]!==x||e[55]!==h||e[56]!==c||e[57]!==w?(L=(y||v||S||I||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(ys,{open:m===n.path,onOpenChange:ee=>c(ee?n.path:null),children:[s.jsx(vs,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:k,children:s.jsx(D,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsxs(ws,{align:"end",side:"bottom",onCloseAutoFocus:()=>c(null),children:[y&&s.jsxs(vt,{onClick:ee=>{ee.stopPropagation(),x("rename",n)},children:[s.jsx(D,{name:"edit",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.rename")]}),s.jsxs(vt,{onClick:ee=>{ee.stopPropagation(),An(n.path).then(re=>{if(re.ok){te.success(w("sidebarFilesTree.toast.pathCopied"));return}te.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.copyPath")]}),!b&&f&&s.jsxs(vt,{onClick:ee=>{ee.stopPropagation(),f(n.path)},children:[s.jsx(D,{name:"download",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.save")]}),j&&s.jsxs(vt,{onClick:ee=>{ee.stopPropagation(),h(n.path)},children:[s.jsx(D,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",w(af())]}),b&&(v||S)&&s.jsxs(s.Fragment,{children:[s.jsx(Ys,{}),v&&s.jsxs(vt,{onClick:ee=>{ee.stopPropagation(),x("createFile",n)},children:[s.jsx(D,{name:"file-add",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFile")]}),S&&s.jsxs(vt,{onClick:ee=>{ee.stopPropagation(),x("createFolder",n)},children:[s.jsx(D,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFolder")]})]}),I&&s.jsxs(s.Fragment,{children:[s.jsx(Ys,{}),s.jsxs(vt,{onClick:ee=>{ee.stopPropagation(),x("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=v,e[45]=S,e[46]=I,e[47]=y,e[48]=j,e[49]=m,e[50]=f,e[51]=k,e[52]=b,e[53]=n,e[54]=x,e[55]=h,e[56]=c,e[57]=w,e[58]=L):L=e[58];let Y;return e[59]!==P||e[60]!==oe||e[61]!==L?(Y=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:P,children:[oe,L]}),e[59]=P,e[60]=oe,e[61]=L,e[62]=Y):Y=e[62],Y},I1=()=>{const t=st.c(256),{t:e}=ct(),{files:n,runtime:r}=wn(),a=jr()??"";let i;t[0]!==a?(i=bn(a.trim()),t[0]=a,t[1]=i):i=t[1];const l=i,u=cl(),d=td(),f=sd(D1),m=De(T1),c=nd(a),[p,g]=o.useState(""),h=dl(p,200),x=o.useRef(null);let w;t[2]===Symbol.for("react.memo_cache_sentinel")?(w=[],t[2]=w):w=t[2];const[b,y]=o.useState(w),[v,S]=o.useState(!1);let I;t[3]===Symbol.for("react.memo_cache_sentinel")?(I={},t[3]=I):I=t[3];const[j,N]=o.useState(I);let P;t[4]===Symbol.for("react.memo_cache_sentinel")?(P=new Set,t[4]=P):P=t[4];const M=o.useRef(P);let T;t[5]===Symbol.for("react.memo_cache_sentinel")?(T=new Set,t[5]=T):T=t[5];const E=o.useRef(T);let k;t[6]===Symbol.for("react.memo_cache_sentinel")?(k=[],t[6]=k):k=t[6];const C=k;let A;t[7]===Symbol.for("react.memo_cache_sentinel")?(A=[],t[7]=A):A=t[7];const F=A;let _;t[8]!==l?(_=Nt=>l?Nt.byRoot[l]?.expandedPaths??C:C,t[8]=l,t[9]=_):_=t[9];const O=sn(_);let V;t[10]!==l?(V=Nt=>l?Nt.byRoot[l]?.selectedPath??null:null,t[10]=l,t[11]=V):V=t[11];const K=sn(V),$=sn(A1),oe=sn(E1),L=sn(M1),Y=sn(R1);let ee;t[12]!==l?(ee=Nt=>l?Nt.contextPanelByDirectory[l]?.tabs??F:F,t[12]=l,t[13]=ee):ee=t[13];const re=De(ee);let fe;t[14]!==re?(fe=new Set(re.map(F1).filter(L1).map(O1)),t[14]=re,t[15]=fe):fe=t[15];const ge=fe,[be,z]=o.useState(null),[B,Q]=o.useState(null),[X,ie]=o.useState(null),[le,ye]=o.useState(""),[W,ue]=o.useState(!1),ae=!!n.writeFile,U=!!n.createDirectory,G=!!n.rename,ne=!!n.delete,se=!!n.revealPath,xe=!!n.uploadFile,[Se,je]=o.useState(!1),Ie=o.useRef(null);let Oe;t[16]!==ae||t[17]!==U||t[18]!==ne||t[19]!==G||t[20]!==se?(Oe={canRename:G,canCreateFile:ae,canCreateFolder:U,canDelete:ne,canReveal:se},t[16]=ae,t[17]=U,t[18]=ne,t[19]=G,t[20]=se,t[21]=Oe):Oe=t[21];const Ne=Oe;let he;t[22]!==n||t[23]!==e?(he=Nt=>{n.revealPath&&n.revealPath(Nt).catch(()=>{te.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=he):he=t[24];const Fe=he;let Be;t[25]===Symbol.for("react.memo_cache_sentinel")?(Be=(Nt,Lt)=>{Q(Nt),ie(Lt),ye(Nt==="rename"&&Lt.name||""),ue(!1)},t[25]=Be):Be=t[25];const q=Be;let Pe;t[26]!==d||t[27]!==u?(Pe=(Nt,Lt)=>{const Gt=Lt.filter($1).filter(we=>u||!we.name.startsWith(".")).filter(we=>d||!S1(we.name)).map(we=>{const at=we.name,bt=bn(we.path||""),Pt=bt?j1(bt)?bt:bn(`${Nt}/${bt}`):bn(`${Nt}/${at}`),Ht=we.isDirectory?"directory":"file",xs=Ht==="file"&&at.includes(".")?at.split(".").pop()?.toLowerCase():void 0;return{name:at,path:Pt,type:Ht,extension:xs}});return w1(Gt)},t[26]=d,t[27]=u,t[28]=Pe):Pe=t[28];const $e=Pe;let Ce;t[29]!==n||t[30]!==$e||t[31]!==r.isDesktop||t[32]!==d?(Ce=async Nt=>{const Lt=bn(Nt.trim());if(!Lt||M.current.has(Lt)||E.current.has(Lt))return;E.current=new Set(E.current),E.current.add(Lt);const Gt=!d;await(r.isDesktop?n.listDirectory(Lt,{respectGitignore:Gt}).then(z1):Bs.listLocalDirectory(Lt,{respectGitignore:Gt}).then(V1)).then(at=>{const bt=$e(Lt,at);M.current=new Set(M.current),M.current.add(Lt),N(Pt=>({...Pt,[Lt]:bt}))}).catch(()=>{N(at=>({...at,[Lt]:at[Lt]??[]}))}).finally(()=>{E.current=new Set(E.current),E.current.delete(Lt)})},t[29]=n,t[30]=$e,t[31]=r.isDesktop,t[32]=d,t[33]=Ce):Ce=t[33];const pe=Ce;let R;t[34]!==pe||t[35]!==l?(R=async()=>{l&&(M.current=new Set,E.current=new Set,N(U1),await pe(l))},t[34]=pe,t[35]=l,t[36]=R):R=t[36];const J=R;let H;t[37]!==pe||t[38]!==J?(H=async Nt=>{if(!Nt){await J();return}const Lt=bn(Nt);M.current=new Set(M.current),M.current.delete(Lt),E.current=new Set(E.current),E.current.delete(Lt),await pe(Lt)},t[37]=pe,t[38]=J,t[39]=H):H=t[39];const Ee=H;let Ae;t[40]!==n||t[41]!==Ee||t[42]!==e?(Ae=async(Nt,Lt)=>{if(!n.uploadFile)return;const Gt=Array.from(Lt);if(Gt.length===0)return;let we=0;const at=[];for(const bt of Gt)try{await n.uploadFile(Nt,bt),we++}catch(Pt){const Ht=Pt,xs=Ht instanceof Error?Ht.message:String(Ht);at.push(`${bt.name}: ${xs}`)}if(we>0&&(te.success(e("sidebarFilesTree.toast.uploadSuccess",{count:we})),await Ee(Nt)),at.length>0){const bt=at.slice(0,3).join(`
@@ -38,7 +38,7 @@ ${bt}`)}},t[40]=n,t[41]=Ee,t[42]=e,t[43]=Ae):Ae=t[43];const Je=Ae;let ce;t[44]==
38
38
  `),l=Math.min(n.start,n.end),u=Math.max(n.start,n.end),d=Math.max(1,l),f=Math.min(i.length,u);return d>f?"":i.slice(d-1,f).join(`
39
39
  `)},Pw=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,no=new WeakMap,Iw={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function Dw(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 Tw(t){if(typeof document>"u")return null;const e=Dw(t);let n=no.get(e.key);if(!n){const a=new pg;a.setup(e.root,e.content),n={virtualizer:a,refs:0},no.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=no.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),no.delete(e.key)))}}}const Jf=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:l="fill"})=>{const u=ul(),d=u?.currentTheme.metadata.variant==="dark",f=u?.availableThemes.find(Q=>Q.metadata.id===u.lightThemeId)??za(!1),m=u?.availableThemes.find(Q=>Q.metadata.id===u.darkThemeId)??za(!0),{isMobile:c}=_s(),p=fd({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:Q=>Cw(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:g,selection:h,setSelection:x,commentText:w,setCommentText:b,editingDraftId:y,saveComment:v,cancel:S,startEdit:I,deleteDraft:j}=p,N=Le.useRef(null),P=Le.useRef(null),M=Le.useRef(!1),T=Le.useRef(null);Le.useEffect(()=>{N.current=h},[h]),Le.useEffect(()=>{P.current=y},[y]);const E=Le.useCallback(Q=>{if(M.current)return;const X=N.current;if(c&&X&&Q&&Q.side===X.side){const ie=Math.min(X.start,Q.start),le=Math.max(X.end,Q.end);x({...Q,start:ie,end:le})}else x(Q);Q&&(P.current||b(""))},[c,b,x]),k=Le.useCallback(()=>{S()},[S]),C=Le.useCallback(Q=>{const X=document.createElement("div");X.style.position="relative";const ie=Do(Q.metadata);return X.dataset.annotationId=ie,X.dataset.annotationSide=Q.side,X.dataset.annotationLine=String(Q.lineNumber),X},[]),A=Le.useCallback((Q,X)=>{v(Q,X??h??void 0)},[v,h]),F=Le.useCallback(Q=>{x(Q);const X=$.current;if(X)try{M.current=!0,X.setSelectedLines(Q),T.current=Q}catch{}finally{M.current=!1}},[x]),_=Le.useCallback(Q=>{const X=Q.closest("[data-line-type]")?.getAttribute("data-line-type")??Q.getAttribute("data-line-type");if(X==="change-deletion")return"deletions";if(X==="change-addition")return"additions";const ie=Q.getAttribute("data-column-side")??Q.getAttribute("data-side")??Q.closest("[data-column-side]")?.getAttribute("data-column-side");if(ie==="deletions"||ie==="left"||ie==="original")return"deletions";if(ie==="additions"||ie==="right"||ie==="modified")return"additions";const le=Q.closest("[data-line-type]");if(le instanceof HTMLElement){const ye=le.getBoundingClientRect(),W=Q.getBoundingClientRect(),ue=ye.left+ye.width/2;return W.left+W.width/2<ue?"deletions":"additions"}return"additions"},[]);Ba(f),Ba(m);const O=`${f.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,V=Le.useRef(null),K=Le.useRef(null),$=Le.useRef(null),oe=Le.useRef(null),[,L]=o.useReducer(Q=>Q+1,0),Y=Ic(a?"split":"unified"),ee=Le.useMemo(()=>Kd(f),[f]),re=Le.useMemo(()=>Kd(m),[m]);o.useLayoutEffect(()=>{const Q=V.current;if(!Q)return;const X=Q.querySelector("diffs-container");if(!X)return;const ie=d?re:ee,le=(je,Ie)=>je.colors?.[Ie],ye=le(ee,"terminal.ansiGreen"),W=le(ee,"terminal.ansiRed"),ue=le(ee,"terminal.ansiBlue"),ae=le(re,"terminal.ansiGreen"),U=le(re,"terminal.ansiRed"),G=le(re,"terminal.ansiBlue");X.style.setProperty("--shiki-light",ee.fg),X.style.setProperty("--shiki-light-bg",ee.bg),ye&&X.style.setProperty("--shiki-light-addition-color",ye),W&&X.style.setProperty("--shiki-light-deletion-color",W),ue&&X.style.setProperty("--shiki-light-modified-color",ue),X.style.setProperty("--shiki-dark",re.fg),X.style.setProperty("--shiki-dark-bg",re.bg),ae&&X.style.setProperty("--shiki-dark-addition-color",ae),U&&X.style.setProperty("--shiki-dark-deletion-color",U),G&&X.style.setProperty("--shiki-dark-modified-color",G),X.style.setProperty("--diffs-bg",ie.bg),X.style.setProperty("--diffs-fg",ie.fg);const ne=d?ae:ye,se=d?U:W,xe=d?G:ue;ne&&X.style.setProperty("--diffs-addition-color-override",ne),se&&X.style.setProperty("--diffs-deletion-color-override",se),xe&&X.style.setProperty("--diffs-modified-color-override",xe);const Se=X.shadowRoot?.querySelector("pre");Se&&(Se.style.setProperty("--shiki-light",ee.fg),Se.style.setProperty("--shiki-light-bg",ee.bg),ye&&Se.style.setProperty("--shiki-light-addition-color",ye),W&&Se.style.setProperty("--shiki-light-deletion-color",W),ue&&Se.style.setProperty("--shiki-light-modified-color",ue),Se.style.setProperty("--shiki-dark",re.fg),Se.style.setProperty("--shiki-dark-bg",re.bg),ae&&Se.style.setProperty("--shiki-dark-addition-color",ae),U&&Se.style.setProperty("--shiki-dark-deletion-color",U),G&&Se.style.setProperty("--shiki-dark-modified-color",G),Se.style.setProperty("--diffs-bg",ie.bg),Se.style.setProperty("--diffs-fg",ie.fg),ne&&Se.style.setProperty("--diffs-addition-color-override",ne),se&&Se.style.setProperty("--diffs-deletion-color-override",se),xe&&Se.style.setProperty("--diffs-modified-color-override",xe))},[re,O,d,ee]);const fe=Le.useMemo(()=>Math.max(t.length,e.length)>Nw,[t.length,e.length]),ge=Le.useMemo(()=>({theme:{dark:m.metadata.id,light:f.metadata.id},themeType:d?"dark":"light",diffStyle:a?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:fe?0:1e3,maxLineLengthForHighlighting:fe?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:E,unsafeCSS:Sw,renderAnnotation:C}),[m.metadata.id,d,fe,f.metadata.id,a,i,E,C]),be=Le.useMemo(()=>hw({drafts:g,editingDraftId:y,selection:h}),[y,g,h]),z=Le.useRef(be);if(Le.useEffect(()=>{z.current=be},[be]),Le.useEffect(()=>{if(typeof window>"u")return;const Q=K.current;if(!Q||!Y)return;$.current?.cleanUp(),$.current=null,oe.current?.release(),oe.current=null,Q.innerHTML="";const X=Tw(Q);oe.current=X;const ie=X?new ug(ge,X.virtualizer,Iw,Y):new mg(ge,Y);$.current=ie,T.current=null;const le={name:r||"",contents:t,lang:n,cacheKey:`old:${O}:${r}:${zu(t)}`},ye={name:r||"",contents:e,lang:n,cacheKey:`new:${O}:${r}:${zu(e)}`};return ie.render({oldFile:le,newFile:ye,lineAnnotations:z.current,containerWrapper:Q}),requestAnimationFrame(()=>{L()}),()=>{ie.cleanUp(),$.current===ie&&($.current=null),X?.release(),X&&oe.current===X&&(oe.current=null),Q.innerHTML=""}},[O,r,n,e,ge,t,Y]),Le.useEffect(()=>{const Q=$.current;if(Q){try{Q.setLineAnnotations(be)}catch(X){console.error("Failed to apply diff line annotations",X);try{Q.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if($.current===Q){try{Q.rerender()}catch{}L()}})}},[be]),Le.useEffect(()=>{const Q=$.current;if(!Q||h!==null)return;const X=T.current;if(!Pw(h,X))try{M.current=!0,Q.setSelectedLines(h),T.current=h}catch{}finally{M.current=!1}},[h]),Le.useEffect(()=>{const Q=K.current;if(!Q)return;let X=null,ie=()=>{};const le=()=>{const W=Q.querySelector("diffs-container")?.shadowRoot;if(!W){X=requestAnimationFrame(le);return}const ue=ae=>{if(!(ae instanceof MouseEvent)||ae.button!==0||!(ae.target instanceof Element))return;const U=ae.target.closest("[data-column-number]");if(!(U instanceof HTMLElement))return;const G=U.getAttribute("data-column-number"),ne=G?parseInt(G,10):NaN;if(Number.isNaN(ne))return;const se=_(U);E({start:ne,end:ne,side:se}),ae.preventDefault(),ae.stopPropagation()};W.addEventListener("click",ue,!0),ie=()=>{W.removeEventListener("click",ue,!0)}};return le(),()=>{X!==null&&cancelAnimationFrame(X),ie()}},[O,r,E,_]),Le.useEffect(()=>{const Q=K.current;if(!Q)return;let X=null,ie=null;const ye=setTimeout(()=>{const W=Q.querySelector("diffs-container");if(!(W instanceof HTMLElement))return;const ue=W.shadowRoot;X=new MutationObserver(()=>{ie&&cancelAnimationFrame(ie),ie=requestAnimationFrame(()=>{L(),ie=null})}),X.observe(W,{childList:!0,subtree:!0}),ue&&X.observe(ue,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(ye),ie&&cancelAnimationFrame(ie),X?.disconnect()}},[O,r]),typeof window>"u")return null;const B=s.jsx(xw,{diffRootRef:V,drafts:g,selection:h,editingDraftId:y,commentText:w,fileLabel:r?.split("/").pop()??"",onSave:A,onCancel:k,onEdit:Q=>{F({start:Q.startLine,end:Q.endLine,side:Q.side==="original"?"deletions":"additions"}),I(Q)},onDelete:j});return l==="fill"?s.jsx("div",{className:de("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:s.jsxs("div",{className:"flex-1 relative min-h-0",children:[s.jsx(ts,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:s.jsx("div",{ref:V,className:"size-full relative",children:s.jsx("div",{ref:K,className:"size-full"})})}),B]})}):s.jsxs("div",{className:de("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:K,className:"w-full"})}),B]})},Aw=1100,Dc=15e3,Bu=500,Ew=t=>t<=6?t:t<=12?6:t<=25?4:2,Xf=o.memo(()=>{const t=st.c(4),{t:e}=ct();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}),Zf={"?":{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"}},Mw=Zf.M,To=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],Rw=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"},eh=t=>{const e=Rw(t);return Zf[e]??Mw},Fw=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},Lw=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Ow=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(Lw(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},Vu=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Uu=(t,e)=>{const n=t.split(`
40
40
  `),r=e.split(`
41
- `),a=Math.min(n.length,r.length);for(let i=0;i<a;i+=1)if(n[i]!==r[i])return i+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},$w=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},Yo=(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]})},_w=o.memo(t=>{const e=st.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:a,onSelectFile:i,isMobile:l,showModeSelector:u,mode:d,onModeChange:f}=t,m=u===void 0?!1:u,{t:c}=ct();let p;e[0]!==l?(p=N=>{if(!l)return N;const P=N.lastIndexOf("/");return P>=0?N.slice(P+1):N},e[0]=l,e[1]=p):p=e[1];const g=p;if(n.length===0)return null;let h;e[2]!==g||e[3]!==a||e[4]!==c?(h=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(dr,{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:g(a.path)}),Yo(a.insertions,a.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:c("diffView.selector.selectFile")}),e[2]=g,e[3]=a,e[4]=c,e[5]=h):h=e[5];let x;e[6]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=x):x=e[6];let w;e[7]!==h?(w=s.jsx(vs,{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,x]})}),e[7]=h,e[8]=w):w=e[8];let b;e[9]!==d||e[10]!==f||e[11]!==m||e[12]!==c?(b=m&&d&&f?s.jsxs(s.Fragment,{children:[s.jsx(xi,{className:"typography-meta text-muted-foreground",children:c("diffView.selector.viewMode")}),s.jsx(Bo,{value:d,onValueChange:N=>f(N),children:To.map(N=>s.jsx(Vo,{value:N.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:c(N.labelKey)})},N.value))}),s.jsx(Ys,{})]}):null,e[9]=d,e[10]=f,e[11]=m,e[12]=c,e[13]=b):b=e[13];const y=r??"";let v;if(e[14]!==n||e[15]!==g){let N;e[17]!==g?(N=P=>s.jsx(Vo,{value:P.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(dr,{filePath:P.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:g(P.path)}),s.jsx("span",{className:"ml-auto",children:Yo(P.insertions,P.deletions)})]})},P.path),e[17]=g,e[18]=N):N=e[18],v=n.map(N),e[14]=n,e[15]=g,e[16]=v}else v=e[16];let S;e[19]!==i||e[20]!==y||e[21]!==v?(S=s.jsx(Bo,{value:y,onValueChange:i,children:v}),e[19]=i,e[20]=y,e[21]=v,e[22]=S):S=e[22];let I;e[23]!==b||e[24]!==S?(I=s.jsxs(ws,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[b,S]}),e[23]=b,e[24]=S,e[25]=I):I=e[25];let j;return e[26]!==I||e[27]!==w?(j=s.jsxs(ys,{children:[w,I]}),e[26]=I,e[27]=w,e[28]=j):j=e[28],j}),zw=o.memo(t=>{const e=st.c(31),{mode:n,onModeChange:r}=t,{t:a}=ct();let i,l,u,d,f,m;if(e[0]!==n||e[1]!==a){const v=To.find(S=>S.value===n)??To[0];l=ys,i=vs,m=!0,f="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",u="min-w-0 truncate typography-meta",d=a(v.labelKey),e[0]=n,e[1]=a,e[2]=i,e[3]=l,e[4]=u,e[5]=d,e[6]=f,e[7]=m}else i=e[2],l=e[3],u=e[4],d=e[5],f=e[6],m=e[7];let c;e[8]!==u||e[9]!==d?(c=s.jsx("span",{className:u,children:d}),e[8]=u,e[9]=d,e[10]=c):c=e[10];let p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=p):p=e[11];let g;e[12]!==f||e[13]!==c?(g=s.jsxs("button",{className:f,children:[c,p]}),e[12]=f,e[13]=c,e[14]=g):g=e[14];let h;e[15]!==i||e[16]!==m||e[17]!==g?(h=s.jsx(i,{asChild:m,children:g}),e[15]=i,e[16]=m,e[17]=g,e[18]=h):h=e[18];let x;e[19]!==r?(x=v=>r(v),e[19]=r,e[20]=x):x=e[20];let w;e[21]!==a?(w=To.map(v=>s.jsx(Vo,{value:v.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:a(v.labelKey)})},v.value)),e[21]=a,e[22]=w):w=e[22];let b;e[23]!==n||e[24]!==w||e[25]!==x?(b=s.jsx(ws,{className:"min-w-[140px]",children:s.jsx(Bo,{value:n,onValueChange:x,children:w})}),e[23]=n,e[24]=w,e[25]=x,e[26]=b):b=e[26];let y;return e[27]!==l||e[28]!==b||e[29]!==h?(y=s.jsxs(l,{children:[h,b]}),e[27]=l,e[28]=b,e[29]=h,e[30]=y):y=e[30],y}),Bw=o.memo(t=>{const e=st.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=ct();if(n.length===0)return null;let l;if(e[0]!==n||e[1]!==a||e[2]!==r||e[3]!==i){let d;e[5]!==a||e[6]!==r||e[7]!==i?(d=f=>{const m=eh(f),c=r===f.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(f.path),className:de("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",c?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(dr,{filePath:f.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:m.color},title:i(m.descriptionKey),"aria-label":i(m.descriptionKey),children:m.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:f.path,children:f.path}),Yo(f.insertions,f.deletions)]})},f.path)},e[5]=a,e[6]=r,e[7]=i,e[8]=d):d=e[8],l=n.map(d),e[0]=n,e[1]=a,e[2]=r,e[3]=i,e[4]=l}else l=e[4];let u;return e[9]!==l?(u=s.jsx(ts,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:l})}),e[9]=l,e[10]=u):u=e[10],u}),Vw=o.memo(t=>{const e=st.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:l}=ct(),u=r.original.length>0,d=r.modified.length>0;if(!a){let x;return e[0]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=x):x=e[0],x}const f=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={contain:"size layout"},e[1]=c):c=e[1];let p;e[2]!==r.original||e[3]!==n||e[4]!==u||e[5]!==m||e[6]!==i||e[7]!==l?(p=u&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l("diffView.image.original")}),s.jsx("img",{src:r.original,alt:l("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=u,e[5]=m,e[6]=i,e[7]=l,e[8]=p):p=e[8];let g;e[9]!==r.modified||e[10]!==n||e[11]!==d||e[12]!==u||e[13]!==m||e[14]!==i||e[15]!==l?(g=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l(u?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:l("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=d,e[12]=u,e[13]=m,e[14]=i,e[15]=l,e[16]=g):g=e[16];let h;return e[17]!==f||e[18]!==p||e[19]!==g?(h=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:c,children:s.jsxs("div",{className:f,children:[p,g]})}),e[17]=f,e[18]=p,e[19]=g,e[20]=h):h=e[20],h}),Uw=o.memo(t=>{const e=st.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=ct(),l=r.original.length>0,u=r.modified.length>0,d=a?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",f=a?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let c;e[1]!==r.original||e[2]!==n||e[3]!==l||e[4]!==f||e[5]!==a||e[6]!==i?(c=l&&s.jsxs("div",{className:f,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=l,e[4]=f,e[5]=a,e[6]=i,e[7]=c):c=e[7];let p;e[8]!==r.modified||e[9]!==n||e[10]!==u||e[11]!==l||e[12]!==f||e[13]!==a||e[14]!==i?(p=u&&s.jsxs("div",{className:f,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(l?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=u,e[11]=l,e[12]=f,e[13]=a,e[14]=i,e[15]=p):p=e[15];let g;return e[16]!==d||e[17]!==c||e[18]!==p?(g=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[c,p]})}),e[16]=d,e[17]=c,e[18]=p,e[19]=g):g=e[19],g}),Kw=o.memo(t=>{const e=st.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let l;e[0]!==n?(l=Ci(n)||"text",e[0]=n,e[1]=l):l=e[1];const u=l;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Xf,{}),e[2]=m):m=e[2],m}if(Pi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(Uw,{filePath:n,diff:r,renderSideBySide:a}),e[3]=r,e[4]=n,e[5]=a,e[6]=m):m=e[6],m}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let f;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==u||e[12]!==a||e[13]!==i?(f=s.jsx("div",{className:"w-full",style:d,children:s.jsx(Jf,{original:r.original,modified:r.modified,language:u,fileName:n,renderSideBySide:a,wrapLines:i,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=u,e[12]=a,e[13]=i,e[14]=f):f=e[14],f}),Ww=o.memo(t=>{const e=st.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:l}=t;let u;e[0]!==n?(u=Ci(n)||"text",e[0]=n,e[1]=u):u=e[1];const d=u;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Xf,{}),e[2]=m):m=e[2],m}if(!a)return null;if(Pi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(Vw,{filePath:n,diff:r,isVisible:a,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=a,e[6]=i,e[7]=m):m=e[7],m}let f;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==d||e[12]!==i||e[13]!==l?(f=s.jsx(ts,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Jf,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:i,wrapLines:l,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=i,e[13]=l,e[14]=f):f=e[14],f}),Hw=o.memo(t=>{const e=st.c(122),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:l,isSelected:u,onSelect:d,registerSectionRef:f,defaultCollapsed:m,expandRequestPath:c,expandRequestNonce:p,showOpenInEditorAction:g,isOpeningInEditor:h,onOpenInEditor:x}=t,w=m===void 0?!1:m,b=c===void 0?null:c,y=p===void 0?0:p,v=g===void 0?!1:g,S=h===void 0?!1:h,{t:I}=ct(),{git:j}=wn();let N;e[0]!==n||e[1]!==r.path?(N=We=>We.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=N):N=e[2];const P=yn(N),M=yn(qw),T=De(Yw),[E,k]=o.useState(!w),[C,A]=o.useState(!1),[F,_]=o.useState(0),[O,V]=o.useState(null),[K,$]=o.useState(!1),[oe,L]=o.useState(!1),Y=o.useRef(null),ee=o.useRef(null);let re;e[3]!==r?(re=eh(r),e[3]=r,e[4]=re):re=e[4];const fe=re,ge=a==="side-by-side";let be;e:{if(!P){be=null;break e}let We;e[5]!==P.isBinary||e[6]!==P.modified||e[7]!==P.original?(We={original:P.original,modified:P.modified,isBinary:P.isBinary},e[5]=P.isBinary,e[6]=P.modified,e[7]=P.original,e[8]=We):We=e[8],be=We}const z=be;let B;e[9]!==r.path||e[10]!==f?(B=We=>{ee.current=We,f(r.path,We)},e[9]=r.path,e[10]=f,e[11]=B):B=e[11];const Q=B;let X;e[12]===Symbol.for("react.memo_cache_sentinel")?(X=We=>{k(We),We&&A(!0)},e[12]=X):X=e[12];const ie=X;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 ye=le;let W,ue;e[16]!==C||e[17]!==E||e[18]!==l?(W=()=>{if(!E||C)return;const We=ee.current;if(!We)return;if(!l.current||typeof IntersectionObserver>"u"){A(!0);return}const Te=new IntersectionObserver(Ve=>{Ve.some(Qw)&&(A(!0),Te.disconnect())},{root:l.current,rootMargin:"200px 0px",threshold:.1});return Te.observe(We),()=>Te.disconnect()},ue=[C,E,l],e[16]=C,e[17]=E,e[18]=l,e[19]=W,e[20]=ue):(W=e[19],ue=e[20]),o.useEffect(W,ue);let ae,U;e[21]!==y||e[22]!==b||e[23]!==r.path?(ae=()=>{y<=0||b!==r.path||(k(!0),A(!0))},U=[y,b,r.path],e[21]=y,e[22]=b,e[23]=r.path,e[24]=ae,e[25]=U):(ae=e[24],U=e[25]),o.useEffect(ae,U);let G,ne;e[26]!==z||e[27]!==F||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==C||e[32]!==E||e[33]!==M?(G=()=>{if(!E||!C)return;if(!n||z){Y.current=null,$(!1);return}const We=`${n}::${r.path}::${F}`;if(Y.current===We)return;Y.current=We,V(null),$(!0);let Te=!1;const Ve=j.getGitFileDiff(n,{path:r.path}),Ye=new Promise(Jw);return Promise.race([Ve,Ye]).then(Ge=>{Te||(M(n,r.path,{original:Ge.original??"",modified:Ge.modified??"",isBinary:Ge.isBinary}),$(!1))}).catch(Ge=>{if(Te)return;const me=Ge instanceof Error?Ge.message:String(Ge);V(me),$(!1)}),()=>{Te=!0,Y.current===We&&(Y.current=null)}},ne=[n,z,F,r.path,j,C,E,M],e[26]=z,e[27]=F,e[28]=n,e[29]=r.path,e[30]=j,e[31]=C,e[32]=E,e[33]=M,e[34]=G,e[35]=ne):(G=e[34],ne=e[35]),o.useEffect(G,ne);let se;e[36]!==ye||e[37]!==E?(se=()=>{ie(!E),ye()},e[36]=ye,e[37]=E,e[38]=se):se=e[38];const xe=se,Se=E?"rounded-b-none":"rounded-b-xl",je=u?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let Ie;e[39]!==Se||e[40]!==je?(Ie=de("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Se,"text-muted-foreground hover:text-foreground",je),e[39]=Se,e[40]=je,e[41]=Ie):Ie=e[41];let Oe;e[42]===Symbol.for("react.memo_cache_sentinel")?(Oe=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[42]=Oe):Oe=e[42];let Ne;e[43]!==E?(Ne=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:E?s.jsx(D,{name:"arrow-down-s",className:"size-4"}):s.jsx(D,{name:"arrow-right-s",className:"size-4"})}),e[43]=E,e[44]=Ne):Ne=e[44];let he;e[45]!==fe.color?(he={color:fe.color},e[45]=fe.color,e[46]=he):he=e[46];let Fe;e[47]!==fe.descriptionKey||e[48]!==I?(Fe=I(fe.descriptionKey),e[47]=fe.descriptionKey,e[48]=I,e[49]=Fe):Fe=e[49];let Be;e[50]!==fe.descriptionKey||e[51]!==I?(Be=I(fe.descriptionKey),e[50]=fe.descriptionKey,e[51]=I,e[52]=Be):Be=e[52];let q;e[53]!==fe.code||e[54]!==he||e[55]!==Fe||e[56]!==Be?(q=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:he,title:Fe,"aria-label":Be,children:fe.code}),e[53]=fe.code,e[54]=he,e[55]=Fe,e[56]=Be,e[57]=q):q=e[57];const Pe=r.path;let $e;e[58]!==r.path?($e=s.jsx(dr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=$e):$e=e[59];let Ce;if(e[60]!==r.path){e:{const We=r.path.lastIndexOf("/");if(We===-1){let tt;e[62]===Symbol.for("react.memo_cache_sentinel")?(tt={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[62]=tt):tt=e[62],Ce=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:tt,children:r.path});break e}const Te=r.path.slice(0,We),Ve=r.path.slice(We+1);let Ye;e[63]===Symbol.for("react.memo_cache_sentinel")?(Ye={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=Ye):Ye=e[63];let Ge;e[64]!==Te?(Ge=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:Ye,children:Te}),e[64]=Te,e[65]=Ge):Ge=e[65];let me;e[66]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[66]=me):me=e[66];let Ke;e[67]!==Ve?(Ke=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[me,s.jsx("span",{className:"text-foreground",children:Ve})]}),e[67]=Ve,e[68]=Ke):Ke=e[68];let ze;e[69]!==Ge||e[70]!==Ke?(ze=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[Ge,Ke]}),e[69]=Ge,e[70]=Ke,e[71]=ze):ze=e[71],Ce=ze}e[60]=r.path,e[61]=Ce}else Ce=e[61];let pe;e[72]!==$e||e[73]!==Ce?(pe=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[$e,Ce]}),e[72]=$e,e[73]=Ce,e[74]=pe):pe=e[74];let R;e[75]!==r.path||e[76]!==pe?(R=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Pe,children:pe}),e[75]=r.path,e[76]=pe,e[77]=R):R=e[77];let J;e[78]!==Ne||e[79]!==q||e[80]!==R?(J=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[Ne,q,R]}),e[78]=Ne,e[79]=q,e[80]=R,e[81]=J):J=e[81];let H;e[82]!==r.deletions||e[83]!==r.insertions?(H=Yo(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=H):H=e[84];let Ee;e[85]!==z||e[86]!==r.path||e[87]!==S||e[88]!==x||e[89]!==v||e[90]!==I?(Ee=v&&x?s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:I("diffView.actions.openFileInEditorAtChange"),onClick:We=>{We.stopPropagation(),x(r.path,z)},disabled:S,children:S?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"edit",className:"size-3.5"})}):null,e[85]=z,e[86]=r.path,e[87]=S,e[88]=x,e[89]=v,e[90]=I,e[91]=Ee):Ee=e[91];const Ae=ge?"side-by-side":"unified";let Je;e[92]!==r.path||e[93]!==T?(Je=We=>{const Te=We==="side-by-side"?"side-by-side":"inline";T(r.path,Te)},e[92]=r.path,e[93]=T,e[94]=Je):Je=e[94];let ce;e[95]!==Ae||e[96]!==Je?(ce=s.jsx(cf,{mode:Ae,onModeChange:Je,className:"opacity-70"}),e[95]=Ae,e[96]=Je,e[97]=ce):ce=e[97];let _e;e[98]!==H||e[99]!==Ee||e[100]!==ce?(_e=s.jsxs("div",{className:"relative flex items-center gap-2",children:[H,Ee,ce]}),e[98]=H,e[99]=Ee,e[100]=ce,e[101]=_e):_e=e[101];let et;e[102]!==xe||e[103]!==Ie||e[104]!==J||e[105]!==_e?(et=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:xe,className:Ie,children:[Oe,J,_e]})}),e[102]=xe,e[103]=Ie,e[104]=J,e[105]=_e,e[106]=et):et=e[106];let Me;e[107]!==z||e[108]!==O||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==oe||e[113]!==E||e[114]!==K||e[115]!==ge||e[116]!==i?(Me=E&&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:()=>_(Xw),children:"Retry"})]}):null,K&&!z&&!O?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"animate-spin"}),"Loading diff…"]}):null,z&&!oe&&r.insertions+r.deletions>Bu?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:()=>L(!0),children:"Render anyway"})]}):null,z&&(oe||r.insertions+r.deletions<=Bu)?s.jsx(Kw,{filePath:r.path,diff:z,renderSideBySide:ge,wrapLines:i}):null]}),e[107]=z,e[108]=O,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=oe,e[113]=E,e[114]=K,e[115]=ge,e[116]=i,e[117]=Me):Me=e[117];let He;return e[118]!==Q||e[119]!==et||e[120]!==Me?(He=s.jsxs("div",{ref:Q,className:"scroll-mt-4",children:[et,Me]}),e[118]=Q,e[119]=et,e[120]=Me,e[121]=He):He=e[121],He}),th=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1})=>{const{t:i}=ct(),{git:l,files:u}=wn(),d=jr(),{screenWidth:f,isMobile:m}=_s(),c=of(d??null),p=nd(d??null),g=lf(d??null),h=yn(J=>J.setActiveDirectory),x=yn(J=>J.ensureStatus),w=yn(J=>J.fetchStatus),b=yn(J=>J.setDiff),[y,v]=o.useState(null),[S,I]=o.useState(null),[j,N]=o.useState(0),[P,M]=o.useState(null),[T,E]=o.useState(0),[k,C]=o.useState(null),A=o.useRef(null),F=De(J=>J.pendingDiffFile),_=De(J=>J.setPendingDiffFile),O=De(J=>J.diffLayoutPreference),V=De(J=>J.diffFileLayout),K=De(J=>J.setDiffFileLayout),$=De(J=>J.diffWrapLines),oe=De(J=>J.setDiffWrapLines),L=De(J=>J.diffViewMode),Y=De(J=>J.setDiffViewMode),ee=De(J=>J.openContextFileAtLine),re=$,fe=L==="stacked",ge=m||f<=768,be=!t&&!ge&&f>=1024,z=o.useRef(null),B=o.useRef(new Map),Q=o.useRef(null),X=o.useRef(null),ie=o.useRef(!1);o.useEffect(()=>{if(!r||!fe||!P)return;const J=z.current;if(!J)return;let H=null,Ee=!1,Ae=0;const Je=Date.now()+1200;let ce=0;const _e=()=>{Ee||(Ee=!0,M(null))},et=()=>{_e()},Me=()=>{if(ce>0){ce-=1;return}_e()};window.addEventListener("wheel",et,{passive:!0,capture:!0}),window.addEventListener("touchstart",et,{passive:!0,capture:!0}),window.addEventListener("pointerdown",et,{capture:!0}),window.addEventListener("keydown",et,{capture:!0}),J.addEventListener("scroll",Me,{passive:!0});const He=()=>{if(Ee||Date.now()>Je){_e();return}const We=z.current,Te=B.current.get(P);if(!We||!Te){_e();return}const Ve=We.getBoundingClientRect(),Ge=Te.getBoundingClientRect().top-Ve.top;if(Math.abs(Ge)<=1){if(Ae+=1,Ae>=2){_e();return}}else{Ae=0;const me=Math.max(0,We.scrollHeight-We.clientHeight),Ke=Math.min(me,Math.max(0,We.scrollTop+Ge));if(Math.abs(Ke-We.scrollTop)<=.5){_e();return}ce+=1,We.scrollTop=Ke}H=window.requestAnimationFrame(He)};return H=window.requestAnimationFrame(He),()=>{Ee=!0,H!==null&&window.cancelAnimationFrame(H),window.removeEventListener("wheel",et,!0),window.removeEventListener("touchstart",et,!0),window.removeEventListener("pointerdown",et,!0),window.removeEventListener("keydown",et,!0),J.removeEventListener("scroll",Me)}},[fe,r,P]);const le=o.useMemo(()=>{if(!p?.files)return[];const J=p.diffStats??{};return p.files.map(H=>({...H,insertions:J[H.path]?.insertions??0,deletions:J[H.path]?.deletions??0,isNew:Fw(H)})).sort((H,Ee)=>H.path.localeCompare(Ee.path))},[p]),ye=o.useMemo(()=>y?le.find(J=>J.path===y)??null:null,[le,y]),W=o.useCallback(J=>{const H=V[J.path];if(H)return H;if(O==="inline")return"inline";if(O==="side-by-side")return"side-by-side";const Ee=f<Aw;return J.isNew||Ee?"inline":"side-by-side"},[V,O,f]),ue=o.useMemo(()=>ye?W(ye):null,[W,ye]);o.useEffect(()=>{d&&(h(d),x(d,l))},[d,h,x,l]),o.useEffect(()=>{if(d)return gr.onGitRefreshHint(J=>{Vu(J.directory)===Vu(d)&&w(d,l)})},[d,w,l]),o.useEffect(()=>{F&&(v(F),_(null),fe&&(ie.current=!0,Q.current=F,I(F),N(J=>J+1)))},[fe,F,_]),o.useEffect(()=>{!y&&!F&&le.length>0&&v(le[0].path)},[le,y,F]),o.useEffect(()=>{y&&le.length>0&&(le.some(H=>H.path===y)||v(le[0]?.path??null))},[le,y]);const ae=o.useCallback((J,H)=>{const Ee=B.current;H?Ee.set(J,H):Ee.delete(J)},[]),U=o.useCallback(J=>{const H=B.current.get(J),Ee=z.current;if(!H||!Ee)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const Ae=Ee.getBoundingClientRect(),ce=H.getBoundingClientRect().top-Ae.top,_e=Math.max(0,Ee.scrollHeight-Ee.clientHeight),et=Ee.scrollTop+ce,Me=Math.min(_e,Math.max(0,et)),He=Math.abs(Me-Ee.scrollTop)>.5;Ee.scrollTop=Me;const We=Math.abs(ce)<=1,Te=Me<=.5||Me>=_e-.5;return{ok:!0,aligned:We,didMove:He,atScrollLimit:Te,delta:ce}},[]);o.useEffect(()=>{if(!fe){Q.current=null,ie.current=!1,X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null);return}if(!Q.current)return;let H=0;const Ee=120;let Ae=!1,Je=0,ce=!1,_e=0;const et=Date.now()+2e3,Me=()=>{ce||(ce=!0,window.removeEventListener("wheel",We,!0),window.removeEventListener("touchstart",We,!0),window.removeEventListener("pointerdown",We,!0),window.removeEventListener("keydown",We,!0),Ve?.removeEventListener("scroll",Te))},He=()=>{Ae||(Ae=!0,Me(),Q.current=null,ie.current=!1,X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null))},We=()=>{He()},Te=()=>{if(Je>0){Je-=1;return}He()},Ve=z.current;window.addEventListener("wheel",We,{passive:!0,capture:!0}),window.addEventListener("touchstart",We,{passive:!0,capture:!0}),window.addEventListener("pointerdown",We,{capture:!0}),window.addEventListener("keydown",We,{capture:!0}),Ve?.addEventListener("scroll",Te,{passive:!0});const Ye=()=>{if(Date.now()>et){He(),X.current=null;return}if(Ae){X.current=null;return}const Ge=Q.current;if(!Ge){He(),X.current=null;return}Je+=1;const me=U(Ge);if(!me.ok){Je=Math.max(0,Je-1),H+=1,H<Ee?X.current=window.requestAnimationFrame(Ye):(He(),X.current=null);return}if(!me.aligned){if(H+=1,me.didMove){if(_e=0,H<Ee){X.current=window.requestAnimationFrame(Ye);return}}else if(_e+=1,_e<6&&(me.atScrollLimit||Math.abs(me.delta)>1)){X.current=window.requestAnimationFrame(Ye);return}}r&&ie.current&&M(Ge),He()};return X.current=window.requestAnimationFrame(Ye),()=>{Ae=!0,Me(),X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null)}},[fe,r,U,y,j]);const G=o.useCallback(J=>{v(J)},[]),ne=o.useCallback(J=>{if(X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null),Q.current=null,v(J),!fe){ie.current=!1;return}ie.current=!0,Q.current=J,U(J)},[fe,U]),se=o.useCallback(J=>{Y(J),J==="stacked"&&y&&(U(y).aligned||(Q.current=y))},[U,y,Y]),xe=o.useCallback(J=>{const H=J==="side-by-side"?"side-by-side":"inline";if(fe){le.forEach(Ee=>{K(Ee.path,H)});return}ye&&K(ye.path,H)},[le,fe,ye,K]),Se=(ue??"side-by-side")==="side-by-side",je=!n&&(!fe||!be),Ie=yn(o.useCallback(J=>!d||!y?null:J.directories.get(d)?.diffCache.get(y)??null,[d,y])),Oe=o.useMemo(()=>Ie?{original:Ie.original,modified:Ie.modified,isBinary:Ie.isBinary}:null,[Ie]),[Ne,he]=o.useState(null),Fe=o.useCallback(async(J,H)=>{if(!(!d||!J)){he(J);try{let Ee=null;if(H&&!H.isBinary&&!Pi(J)&&(Ee=Uu(H.original,H.modified)),Ee===null)try{const et=await l.getGitDiff(d,{path:J,contextLines:3});Ee=$w(et.diff)}catch{Ee=null}let Ae=H;if(Ee===null||!Ae){const et=await l.getGitFileDiff(d,{path:J});Ae={original:et.original??"",modified:et.modified??"",isBinary:et.isBinary},b(d,J,Ae)}const Je=Ee??(Ae.isBinary||Pi(J)?1:Uu(Ae.original,Ae.modified)),ce=Ow(d,J),_e=await md(u,ce);if(!_e.ok){te.error(pd(_e.reason));return}ee(d,ce,Je,1)}finally{he(Ee=>Ee===J?null:Ee)}}},[d,u,l,ee,b]),Be=o.useCallback(async()=>{y&&await Fe(y,Oe)},[Fe,Oe,y]),q=!!(y&&Ne===y),Pe=!!Ie,$e=!fe&&!!y&&!Pe;o.useEffect(()=>{if(fe)return;if(C(null),!d||!y){A.current=null;return}if(Ie){A.current=null;return}const J=`${d}::${y}::${T}`;if(A.current===J)return;A.current=J;let H=!1;const Ee=l.getGitFileDiff(d,{path:y}),Ae=Dc,Je=new Promise((ce,_e)=>{setTimeout(()=>_e(new Error(`Timed out after ${Ae}ms`)),Ae)});return Promise.race([Ee,Je]).then(ce=>{H||b(d,y,{original:ce.original??"",modified:ce.modified??"",isBinary:ce.isBinary})}).catch(ce=>{if(H)return;const _e=ce instanceof Error?ce.message:String(ce);C(_e)}),()=>{H=!0,A.current===J&&(A.current=null)}},[d,fe,y,Ie,l,b,T]);const Ce=()=>!d||!y||!Oe?null:s.jsx(Ww,{filePath:y,diff:Oe,isVisible:!0,renderSideBySide:Se,wrapLines:re},y),pe=()=>{if(!d)return null;const J=Ew(le.length);return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[be&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:i("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:le.length})]}),s.jsx(Bw,{changedFiles:le,selectedFile:y,onSelectFile:ne})]}),s.jsx(ts,{ref:z,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((H,Ee)=>s.jsx(Hw,{directory:d,file:H,layout:W(H),wrapLines:re,scrollRootRef:z,isSelected:H.path===y,onSelect:G,registerSectionRef:ae,defaultCollapsed:e?!0:Ee>=J,expandRequestPath:S,expandRequestNonce:j,showOpenInEditorAction:a,isOpeningInEditor:Ne===H.path,onOpenInEditor:(Ae,Je)=>{Fe(Ae,Je)}},H.path))})})]})},R=()=>d?g&&!p?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"animate-spin"}),i("diffView.state.loadingRepositoryStatus")]}):c===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.notGitRepository")}):le.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.cleanWorkingTree")}):fe?pe():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:[Ce(),$e&&!Pe&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:k?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:i("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:k}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{C(null),E(J=>J+1)},children:i("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"animate-spin"}),i("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!m&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(D,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:g&&!p?i("diffView.state.loadingChanges"):le.length===1?i("diffView.summary.changedFilesSingle",{count:le.length}):i("diffView.summary.changedFilesPlural",{count:le.length})})]}),!ge&&s.jsx(zw,{mode:L,onModeChange:se}),je&&s.jsx(_w,{changedFiles:le,selectedFile:y,selectedFileEntry:ye,onSelectFile:ne,isMobile:ge,showModeSelector:ge,mode:L,onModeChange:se}),s.jsx("div",{className:"flex-1"}),ye&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>oe(!$),className:de("h-5 w-5 p-0 transition-opacity",re?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:i(re?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(D,{name:"text-wrap",className:"size-4"})}),a&&ye&&!fe&&s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Be()},disabled:q,title:i("diffView.actions.openFileAtFirstChangedLine"),children:q?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"edit",className:"size-3.5"})}),ye&&ue&&s.jsx(cf,{mode:ue==="side-by-side"?"side-by-side":"unified",onModeChange:xe})]}),R()]})},Gw=()=>{const t=st.c(6),{git:e}=wn(),n=jr(),r=yn(Zw),a=yn(ej),i=px(n??null);let l,u;return t[0]!==n||t[1]!==a||t[2]!==e||t[3]!==r?(l=()=>{n&&(r(n),a(n,e))},u=[n,r,a,e],t[0]=n,t[1]=a,t[2]=e,t[3]=r,t[4]=l,t[5]=u):(l=t[4],u=t[5]),o.useEffect(l,u),i};function qw(t){return t.setDiff}function Yw(t){return t.setDiffFileLayout}function Qw(t){return t.isIntersecting}function Jw(t,e){setTimeout(()=>e(new Error(`Timed out after ${Dc}ms`)),Dc)}function Xw(t){return t+1}function Zw(t){return t.setActiveDirectory}function ej(t){return t.ensureStatus}const tj=Object.freeze(Object.defineProperty({__proto__:null,DiffView:th,useDiffFileCount:Gw},Symbol.toStringTag,{value:"Module"})),sj={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},nj={case:"Match case",re:"Regular expression",word:"Match whole word"};function rj(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(sj)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(nj)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Ku=new Ya,Wu=new Ya,Hu=new Ya,Gu=new Ya,qu=new Ya,Yu=new Ya,Qu=t=>t,Gl=Ng,aj=Sg,ij=kg;class oj extends Cg{constructor(e,n){super(),this.id=e,this.containerMap=n}id;containerMap;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 Ju=(t,e)=>!t||t.length===0?[]:jg.define({create(n){const r=new Vp,a=[...t].sort((i,l)=>i.afterLine-l.afterLine);for(const i of a){const l=n.doc.lines;if(i.afterLine>l)continue;const u=n.doc.line(i.afterLine);r.add(u.to,u.to,Up.widget({widget:new oj(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>Tn.decorations.from(n)}),Xu=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return wg.fromClass(class{decorations;constructor(r){this.decorations=this.build(r)}update(r){(r.docChanged||r.viewportChanged)&&(this.decorations=this.build(r.view))}build(r){const a=new Vp;for(let i=e;i<=n&&i<=r.state.doc.lines;i+=1){const l=r.state.doc.line(i);a.add(l.from,l.from,Up.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function Tc({value:t,onChange:e,extensions:n,className:r,readOnly:a,lineNumbersConfig:i,highlightLines:l,onViewReady:u,onViewDestroy:d,blockWidgets:f,enableSearch:m,searchOpen:c,onSearchOpenChange:p}){const g=o.useRef(null),h=o.useRef(null),x=o.useRef(t),w=o.useRef(e),b=o.useRef(u),y=o.useRef(d),v=o.useRef(p),S=o.useRef(f),I=o.useRef(new Map),[j,N]=o.useState([]),P=o.useCallback(T=>{const E=(T??[]).map(k=>{const C=I.current.get(k.id);return C?{id:k.id,content:k.content,container:C}:null}).filter(k=>k!==null);N(k=>k.length===E.length&&k.every((C,A)=>{const F=E[A];return C.id===F.id&&C.content===F.content&&C.container===F.container})?k:E)},[]),M=o.useCallback(T=>{const E=g.current,k=T??h.current;if(!E||!k)return;const C=k.dom.querySelector(".cm-gutters"),A=C instanceof HTMLElement?C.getBoundingClientRect().width:0;E.style.setProperty("--oc-editor-gutter-width",`${A}px`)},[]);return o.useEffect(()=>{x.current=t},[t]),o.useEffect(()=>{w.current=e},[e]),o.useEffect(()=>{b.current=u,y.current=d},[u,d]),o.useEffect(()=>{v.current=p},[p]),o.useEffect(()=>{S.current=f,P(f)},[f,P]),o.useEffect(()=>{if(!g.current)return;const T=(()=>{if(typeof document>"u")return null;const k=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(k)return k;const C=window.__APP_CSP_NONCE__;return typeof C=="string"&&C.length>0?C:null})(),E=fg.create({doc:x.current,extensions:[...T?[Tn.cspNonce.of(T)]:[],hg({fixed:!0}),Ku.of(Rd(i)),gg(),xg.of(" "),Dl.of([bg,...yg,...vg]),Tn.updateListener.of(k=>{M(k.view),(k.viewportChanged||k.geometryChanged)&&P(S.current);const C=Fd(k.startState),A=Fd(k.state);if(C!==A&&v.current?.(A),!k.docChanged)return;const F=k.state.doc.toString();x.current=F,w.current(F),P(S.current)}),Wu.of(Tn.editable.of(!a)),Hu.of(n??[]),Gu.of(Xu(l)),qu.of(Ju(f,I.current)),Yu.of(m?[Ld({top:!0}),Dl.of(Qu(Od))]:[])]});return h.current=new Tn({state:E,parent:g.current}),Gl(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{M(h.current),P(S.current)}),h.current&&b.current?.(h.current),()=>{y.current?.(),h.current?.destroy(),h.current=null,N([])}},[S,M,P]),o.useEffect(()=>{const T=h.current;T&&(T.dispatch({effects:[Ku.reconfigure(Rd(i)),Wu.reconfigure(Tn.editable.of(!a)),Hu.reconfigure(n??[]),Gu.reconfigure(Xu(l)),qu.reconfigure(Ju(f,I.current)),Yu.reconfigure(m?[Ld({top:!0}),Dl.of(Qu(Od))]:[])]}),Gl(T,T.state.doc.length,200),T.requestMeasure(),requestAnimationFrame(()=>{M(T),P(S.current)}))},[n,l,i,a,f,m,M,P]),o.useEffect(()=>{const T=h.current;!T||m===!1||(c?(aj(T),requestAnimationFrame(()=>{rj(T.dom)})):ij(T))},[c,m]),o.useEffect(()=>{const T=h.current;if(!T)return;const E=T.state.doc.toString();E!==t&&(T.dispatch({changes:{from:0,to:E.length,insert:t}}),Gl(T,T.state.doc.length,300),T.requestMeasure(),requestAnimationFrame(()=>M(T)))},[t,M]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:g,className:de("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(T=>gi.createPortal(T.content,T.container,T.id))]})}const lj=(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)},Zu=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},em=(t,e,n)=>{const r=t.state.doc.line(e),a=Math.max(1,Math.min(n,r.length+1)),i=r.from+a-1;t.dispatch({selection:Pg.cursor(i),effects:Tn.scrollIntoView(i,{y:"center"})})};function cj({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=ct(),[i,l]=o.useState(""),u=o.useRef(null),d=o.useRef(!1),f=o.useRef(null),m=o.useRef(null),c=o.useMemo(()=>lj(i,n),[i,n]);o.useEffect(()=>{!t||!n||(d.current=!1,u.current=Zu(n,n.state.selection),l(""))},[t,n]),o.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),o.useEffect(()=>{if(!(!t||!n||!u.current)){if(c===null){const{selection:w}=u.current;n.dispatch({selection:w,effects:Tn.scrollIntoView(w.main.from,{y:"center"})});return}em(n,c,u.current.character)}},[c,t,n]);const p=o.useCallback(()=>{if(!n||d.current||!u.current)return;const{selection:w}=u.current;n.dispatch({selection:w,effects:Tn.scrollIntoView(w.main.from,{y:"center"})})},[n]),g=o.useCallback(w=>{w||p(),e(w)},[e,p]),h=o.useCallback(()=>{!n||c===null||!u.current||(d.current=!0,em(n,c,u.current.character),e(!1),n.focus())},[c,e,n]);o.useEffect(()=>{if(!t)return;const w=y=>{const v=f.current,S=y.target;!v||!(S instanceof Node)||v.contains(S)||g(!1)},b=y=>{y.key==="Escape"&&(y.preventDefault(),g(!1))};return document.addEventListener("pointerdown",w,!0),document.addEventListener("keydown",b,!0),()=>{document.removeEventListener("pointerdown",w,!0),document.removeEventListener("keydown",b,!0)}},[g,t,r]);const x=o.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(c===null){const w=u.current??Zu(n,n.state.selection);return a("goToLineDialog.helper.currentLineRange",{current:w.lineNumber,max:n.state.doc.lines})}return a("goToLineDialog.helper.goToLine",{line:c})},[c,a,n]);return r==="inline"?t?s.jsxs("div",{ref:f,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(jt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:w=>l(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(ve,{variant:"outline",size:"xs",onClick:h,disabled:!n||c===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:f,className:de("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(jt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:w=>l(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:x})]})})}const Ac=t=>{const e=st.c(11),{currentMode:n,onToggle:r}=t,a=n==="preview",i=a?"Switch to edit mode":"Switch to preview mode",l=a?"Edit":"Preview";let u;e[0]!==a?(u=a?s.jsx(D,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(D,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=a,e[1]=u):u=e[1];let d;e[2]!==i||e[3]!==r||e[4]!==u?(d=s.jsx(At,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:r,"aria-label":i,className:"h-5 w-5 p-0",children:u})}),e[2]=i,e[3]=r,e[4]=u,e[5]=d):d=e[5];let f;e[6]!==l?(f=s.jsx(Rt,{sideOffset:8,children:l}),e[6]=l,e[7]=f):f=e[7];let m;return e[8]!==d||e[9]!==f?(m=s.jsxs(Tt,{children:[d,f]}),e[8]=d,e[9]=f,e[10]=m):m=e[10],m},Ec=Ig.define(Dg);function dj(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return Ec;case"json":case"jsonc":case"json5":return Hp().language;case"js":case"javascript":return Pa().language;case"jsx":return Pa({jsx:!0}).language;case"ts":case"typescript":return Pa({typescript:!0}).language;case"tsx":return Pa({typescript:!0,jsx:!0}).language;case"html":return bc().language;case"css":return Wp().language;case"py":case"python":return Kp().language;case"heex":case"eex":case"leex":return bc().language;default:return Gp.matchLanguageName(qp,e,!0)}}const sh=t=>t.split("/").pop()?.toLowerCase()??"",uj=t=>{const e=sh(t);return e?Gp.matchFilename(qp,e):null},mj=()=>ui(yc.define([{tag:[nt.heading1,nt.heading2,nt.heading3,nt.heading4,nt.heading5,nt.heading6],fontWeight:"600"},{tag:nt.strong,fontWeight:"600"},{tag:nt.emphasis,fontStyle:"italic"},{tag:nt.strikethrough,textDecoration:"line-through"},{tag:[nt.link,nt.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:nt.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:nt.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:nt.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:nt.heading,color:"var(--markdown-heading1, currentColor)"}]));function nh(t){const e=t.toLowerCase();switch(sh(e)){case"makefile":case"gnumakefile":return Ec}const r=e.lastIndexOf("."),a=r>=0?e.slice(r+1):"";switch(a){case"ts":case"tsx":case"mts":case"cts":return Pa({typescript:!0,jsx:a==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return Pa({typescript:!1,jsx:a==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return Hp();case"css":case"scss":case"sass":case"less":return Wp();case"html":case"htm":return bc();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[Tg({codeLanguages:dj}),mj()];case"sh":case"bash":case"zsh":case"fish":case"env":return Ec;case"py":case"pyw":case"pyi":return Kp();default:return null}}async function pj(t){const e=uj(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function Mc(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=Tn.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:a.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:a.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:a.boolean||t.colors.syntax.base.number},".cm-builtin":{color:a.functionCall||t.colors.syntax.base.function},".cm-def":{color:a.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:a.variableOther||a.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:a.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:a.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:a.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:a.tag||t.colors.syntax.base.keyword},".cm-link":{color:a.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),l=yc.define([{tag:[nt.comment,nt.docComment,nt.meta,nt.documentMeta],class:"cm-comment"},{tag:[nt.keyword,nt.controlKeyword,nt.moduleKeyword,nt.definitionKeyword,nt.modifier],class:"cm-keyword"},{tag:[nt.operatorKeyword,nt.operator,nt.derefOperator,nt.updateOperator,nt.definitionOperator,nt.typeOperator,nt.controlOperator,nt.logicOperator,nt.bitwiseOperator,nt.arithmeticOperator,nt.compareOperator],class:"cm-operator"},{tag:[nt.punctuation,nt.separator,nt.bracket,nt.paren,nt.brace,nt.squareBracket,nt.angleBracket],class:"cm-punctuation"},{tag:[nt.string,nt.regexp,nt.attributeValue,nt.special(nt.string),nt.monospace],class:"cm-string"},{tag:nt.escape,class:"cm-string-2"},{tag:[nt.number,nt.bool,nt.atom,nt.null,nt.self],class:"cm-number"},{tag:[nt.function(nt.variableName),nt.function(nt.definition(nt.variableName)),nt.function(nt.propertyName),nt.standard(nt.variableName),nt.special(nt.variableName)],class:"cm-builtin"},{tag:nt.definition(nt.variableName),class:"cm-def"},{tag:[nt.variableName,nt.local(nt.variableName),nt.constant(nt.variableName),nt.literal],class:"cm-variable"},{tag:nt.propertyName,class:"cm-property"},{tag:nt.attributeName,class:"cm-attribute"},{tag:[nt.className,nt.typeName,nt.namespace],class:"cm-variable-3"},{tag:[nt.tagName,nt.labelName,nt.annotation,nt.macroName],class:"cm-tag"},{tag:nt.link,class:"cm-link"},{tag:[nt.heading,nt.heading1,nt.heading2,nt.heading3,nt.heading4,nt.heading5,nt.heading6],class:"cm-keyword"}]),u=yc.define([{tag:[nt.comment,nt.docComment,nt.meta,nt.documentMeta],color:t.colors.syntax.base.comment},{tag:[nt.keyword,nt.controlKeyword,nt.moduleKeyword,nt.definitionKeyword,nt.modifier],color:t.colors.syntax.base.keyword},{tag:[nt.operatorKeyword,nt.operator,nt.derefOperator,nt.updateOperator,nt.definitionOperator,nt.typeOperator,nt.controlOperator,nt.logicOperator,nt.bitwiseOperator,nt.arithmeticOperator,nt.compareOperator],color:t.colors.syntax.base.operator},{tag:[nt.string,nt.regexp,nt.attributeValue,nt.special(nt.string),nt.monospace],color:t.colors.syntax.base.string},{tag:nt.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[nt.number,nt.bool,nt.atom,nt.null,nt.self],color:t.colors.syntax.base.number},{tag:[nt.function(nt.variableName),nt.function(nt.definition(nt.variableName)),nt.function(nt.propertyName),nt.standard(nt.variableName),nt.special(nt.variableName)],color:t.colors.syntax.base.function},{tag:nt.definition(nt.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[nt.variableName,nt.local(nt.variableName),nt.constant(nt.variableName),nt.literal],color:t.colors.syntax.base.variable},{tag:nt.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:nt.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[nt.className,nt.typeName,nt.namespace],color:t.colors.syntax.base.type},{tag:[nt.tagName,nt.labelName,nt.annotation,nt.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:nt.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[nt.punctuation,nt.separator,nt.bracket,nt.paren,nt.brace,nt.squareBracket,nt.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,ui(Ag,{fallback:!0}),ui(Eg),ui(l),ui(u)]}const 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"}],tm="finder",Rc=new Set(["finder","terminal"]),Fc=t=>t?Ta.find(e=>e.id===t)??null:null,ql=()=>Ta.filter(t=>Rc.has(t.id)).map(t=>({...t})),fj=()=>{if(typeof window>"u")return tm;const t=window.localStorage.getItem("openInAppId");return t&&Fc(t)?t:tm};let Yl=!1,wa=!1,zr=!1,Br=0,vi=null;const sm=()=>{vi&&(clearTimeout(vi),vi=null)},ro=vn()((t,e)=>({selectedAppId:fj(),availableApps:ql(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Yl||typeof window>"u")return;Yl=!0;const n=(d,f=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:ql(),hasLoadedApps:f});return}const m=new Set(d.map(h=>h.name)),c=new Map(d.map(h=>[h.name,h.iconDataUrl??void 0])),g=Ta.filter(h=>m.has(h.appName)||Rc.has(h.id)).map(h=>({...h,iconDataUrl:c.get(h.appName)}));t({availableApps:g,hasLoadedApps:!0})},r=async d=>{if(!Ii()||!Va()||wa||e().hasLoadedApps&&!d)return;const m=Ta.map(c=>c.appName);sm(),wa=!0,zr=!1,t({isScanning:!0});try{const{apps:c,success:p,hasCache:g,isCacheStale:h}=await Wd(m,d),x=p&&!g&&c.length===0&&Br<3;if(t({isCacheStale:g?h:!1}),n(c,p?!x:!1),p){if(x){const b=[800,1600,3200][Br]??3200;Br+=1,zr=!0,vi=setTimeout(()=>{r()},b);return}Br=0,zr=!1;return}if(Br<3){const b=[1e3,3e3,7e3][Br]??7e3;Br+=1,zr=!0,vi=setTimeout(()=>{r()},b)}}finally{wa=!1,zr||t({isScanning:!1})}};r();const a=d=>{const f=d.detail,m=f&&typeof f.openInAppId=="string"&&f.openInAppId.length>0&&Fc(f.openInAppId)?f.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},i=()=>{r()},l=d=>{const f=d.detail;Array.isArray(f)&&(Br=3,zr=!1,t({isScanning:!1,isCacheStale:!1}),n(f))};window.addEventListener("vinci:settings-synced",a),window.addEventListener("vinci:app-ready",i),window.addEventListener("vinci:installed-apps-updated",l),window.__vinciAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Yl||e().initialize(),!Ii()||!Va()||wa||e().hasLoadedApps&&!n)return;const a=Ta.map(i=>i.appName);sm(),n&&t({hasLoadedApps:!1}),wa=!0,zr=!1,t({isScanning:!0});try{const{apps:i,hasCache:l,isCacheStale:u}=await Wd(a,n),d=new Set(i.map(p=>p.name)),f=new Map(i.map(p=>[p.name,p.iconDataUrl??void 0])),c=Ta.filter(p=>d.has(p.appName)||Rc.has(p.id)).map(p=>({...p,iconDataUrl:f.get(p.appName)}));t({availableApps:c.length>0?c:ql(),hasLoadedApps:c.length>0,isCacheStale:l?u:!1})}finally{wa=!1,zr||t({isScanning:!1})}},selectApp:async n=>{Fc(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await rs({openInAppId:n}))}})),hj=o.lazy(()=>Qn(()=>import("./HtmlEditor-D-cp1Mcb.js"),__vite__mapDeps([2,0,1,3,4,5]))),gj=t=>{const e=Vs(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},xj=t=>{const e=st.c(8),{label:n,iconDataUrl:r}=t,[a,i]=o.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const u=l;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let c;return e[3]!==r?(c=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=c):c=e[4],c}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=de("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let f;return e[6]!==u?(f=s.jsx("span",{className:d,children:u}),e[6]=u,e[7]=f):f=e[7],f},bj=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Vs=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},yj=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),nm=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,Qo=(t,e)=>{const n=Vs(e),r=Vs(t);if(!n||!r)return!1;const a=nm(n),i=nm(r);return i===a||i.startsWith(`${a}/`)},rm=(t,e)=>{const n=Vs(e),r=Vs(t);if(!Qo(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),l=[];let u=n;for(let d=0;d<i.length-1;d++)u=u?`${u}/${i[d]}`:i[d],l.push(u);return l},Lc=(t,e)=>{if(!e)return"";const n=Vs(e);if(!t||!Qo(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},vj=new Set(["node_modules"]),wj=t=>{const e=st.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const a=r[n];let i;return e[1]!==a?(i=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:a}}),e[1]=a,e[2]=i):i=e[2],i},jj=t=>vj.has(t),Nj=t=>{const e=Vs(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Sj=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},ai=2e5,rh="vinci:files:auto-save-enabled",kj=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(rh)!=="false"}catch{return!0}},ah=(t,e)=>s.jsx(dr,{filePath:t,extension:e}),Cj=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},Pj=t=>{const e=st.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:l,alwaysShowActions:u,status:d,badge:f,permissions:m,downloadFile:c,contextMenuPath:p,setContextMenuPath:g,onSelect:h,onToggle:x,onRevealPath:w,onOpenDialog:b}=t,{t:y}=ct(),v=n.type==="directory",{canRename:S,canCreateFile:I,canCreateFolder:j,canDelete:N,canReveal:P}=m;let M;e[0]!==I||e[1]!==j||e[2]!==N||e[3]!==S||e[4]!==P||e[5]!==n.path||e[6]!==g?(M=fe=>{!S&&!I&&!j&&!N&&!P||(fe?.preventDefault(),g(n.path))},e[0]=I,e[1]=j,e[2]=N,e[3]=S,e[4]=P,e[5]=n.path,e[6]=g,e[7]=M):M=e[7];const T=M;let E;e[8]!==v||e[9]!==n||e[10]!==h||e[11]!==x?(E=()=>{v?x(n.path):h(n)},e[8]=v,e[9]=n,e[10]=h,e[11]=x,e[12]=E):E=e[12];const k=E;let C;e[13]!==n.path||e[14]!==g?(C=fe=>{fe.stopPropagation(),g(n.path)},e[13]=n.path,e[14]=g,e[15]=C):C=e[15];const A=C,F=l?void 0:T,_=l?void 0:T,O=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[16]!==O?(V=de("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 K;e[18]!==v||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?(K=v?a?s.jsx(D,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(D,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):ah(n.path,n.extension),e[18]=v,e[19]=a,e[20]=n.extension,e[21]=n.path,e[22]=K):K=e[22];let $;e[23]!==n.name||e[24]!==n.path?($=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=$):$=e[25];let oe;e[26]!==v||e[27]!==d?(oe=!v&&d&&s.jsx(wj,{status:d}),e[26]=v,e[27]=d,e[28]=oe):oe=e[28];let L;e[29]!==f||e[30]!==v?(L=v&&f&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[f.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",f.modified]}),f.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",f.added]})]}),e[29]=f,e[30]=v,e[31]=L):L=e[31];let Y;e[32]!==k||e[33]!==oe||e[34]!==L||e[35]!==_||e[36]!==V||e[37]!==K||e[38]!==$?(Y=s.jsxs("button",{type:"button",onClick:k,onContextMenu:_,className:V,children:[K,$,oe,L]}),e[32]=k,e[33]=oe,e[34]=L,e[35]=_,e[36]=V,e[37]=K,e[38]=$,e[39]=Y):Y=e[39];let ee;e[40]!==u||e[41]!==I||e[42]!==j||e[43]!==N||e[44]!==S||e[45]!==P||e[46]!==p||e[47]!==c||e[48]!==A||e[49]!==v||e[50]!==l||e[51]!==n||e[52]!==b||e[53]!==w||e[54]!==r||e[55]!==g||e[56]!==y?(ee=(S||I||j||N||P)&&s.jsx("div",{className:de("absolute right-1 top-1/2 -translate-y-1/2",u?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(ys,{open:p===n.path,onOpenChange:fe=>g(fe?n.path:null),children:[s.jsx(vs,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"size-6",onClick:A,children:s.jsx(D,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(ws,{align:"end",side:"bottom",onCloseAutoFocus:()=>g(null),children:[S&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),b("rename",n)},children:[s.jsx(D,{name:"edit",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.rename")]}),s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),An(n.path).then(ge=>{if(ge.ok){te.success(y("sidebarFilesTree.toast.pathCopied"));return}te.error(y("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.copyPath")]}),s.jsxs(vt,{onClick:fe=>{fe.stopPropagation();const ge=Lc(r,n.path)||n.path;An(ge).then(be=>{if(be.ok){te.success(y("filesView.toast.relativePathCopied"));return}te.error(y("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy-2",className:"mr-2 size-4"})," ",y("filesView.tree.menu.copyRelativePath")]}),!v&&c&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),c(n.path)},children:[s.jsx(D,{name:"download",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.save")]}),P&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),w(n.path)},children:[s.jsx(D,{name:"folder-received",className:"mr-2 size-4"})," ",y(af())]}),v&&(I||j)&&s.jsxs(s.Fragment,{children:[s.jsx(Ys,{}),I&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),b("createFile",n)},children:[s.jsx(D,{name:"file-add",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),b("createFolder",n)},children:[s.jsx(D,{name:"folder-add",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.newFolder")]})]}),N&&s.jsxs(s.Fragment,{children:[s.jsx(Ys,{}),s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),b("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=u,e[41]=I,e[42]=j,e[43]=N,e[44]=S,e[45]=P,e[46]=p,e[47]=c,e[48]=A,e[49]=v,e[50]=l,e[51]=n,e[52]=b,e[53]=w,e[54]=r,e[55]=g,e[56]=y,e[57]=ee):ee=e[57];let re;return e[58]!==Y||e[59]!==ee||e[60]!==F?(re=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:F,children:[Y,ee]}),e[58]=Y,e[59]=ee,e[60]=F,e[61]=re):re=e[61],re},Ij=t=>{const e=st.c(83),{activeDialog:n,dialogData:r,dialogInputValue:a,onDialogInputChange:i,isDialogSubmitting:l,onDialogSubmit:u,onClose:d,inputRef:f}=t,{t:m}=ct(),c=!!n;let p;e[0]!==d?(p=K=>!K&&d(),e[0]=d,e[1]=p):p=e[1];let g;e[2]!==n||e[3]!==m?(g=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=g):g=e[4];let h;e[5]!==n||e[6]!==m?(h=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=h):h=e[7];let x;e[8]!==n||e[9]!==m?(x=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=x):x=e[10];let w;e[11]!==n||e[12]!==m?(w=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=w):w=e[13];let b;e[14]!==g||e[15]!==h||e[16]!==x||e[17]!==w?(b=s.jsxs(hs,{children:[g,h,x,w]}),e[14]=g,e[15]=h,e[16]=x,e[17]=w,e[18]=b):b=e[18];let y;e[19]!==n||e[20]!==r?.path||e[21]!==m?(y=n==="createFile"&&m("filesView.dialog.createFile.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=m,e[22]=y):y=e[22];let v;e[23]!==n||e[24]!==r?.path||e[25]!==m?(v=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=m,e[26]=v):v=e[26];let S;e[27]!==n||e[28]!==r?.name||e[29]!==m?(S=n==="rename"&&m("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=m,e[30]=S):S=e[30];let I;e[31]!==n||e[32]!==r?.name||e[33]!==m?(I=n==="delete"&&m("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=m,e[34]=I):I=e[34];let j;e[35]!==S||e[36]!==I||e[37]!==y||e[38]!==v?(j=s.jsxs(Ss,{children:[y,v,S,I]}),e[35]=S,e[36]=I,e[37]=y,e[38]=v,e[39]=j):j=e[39];let N;e[40]!==j||e[41]!==b?(N=s.jsxs(bs,{children:[b,j]}),e[40]=j,e[41]=b,e[42]=N):N=e[42];let P;e[43]!==n||e[44]!==a||e[45]!==f||e[46]!==i||e[47]!==u||e[48]!==m?(P=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(jt,{value:a,onChange:K=>i(K.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:K=>{K.key==="Enter"&&u()},ref:f})}),e[43]=n,e[44]=a,e[45]=f,e[46]=i,e[47]=u,e[48]=m,e[49]=P):P=e[49];let M;e[50]!==m?(M=m("filesView.dialog.cancel"),e[50]=m,e[51]=M):M=e[51];let T;e[52]!==l||e[53]!==d||e[54]!==M?(T=s.jsx(ve,{variant:"outline",onClick:d,disabled:l,children:M}),e[52]=l,e[53]=d,e[54]=M,e[55]=T):T=e[55];const E=n==="delete"?"destructive":"default";let k;e[56]!==u?(k=()=>{u()},e[56]=u,e[57]=k):k=e[57];let C;e[58]!==n||e[59]!==a||e[60]!==l?(C=l||n!=="delete"&&!a.trim(),e[58]=n,e[59]=a,e[60]=l,e[61]=C):C=e[61];let A;e[62]!==n||e[63]!==l||e[64]!==m?(A=l?s.jsx(D,{name:"loader-4",className:"animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=l,e[64]=m,e[65]=A):A=e[65];let F;e[66]!==E||e[67]!==k||e[68]!==C||e[69]!==A?(F=s.jsx(ve,{variant:E,onClick:k,disabled:C,children:A}),e[66]=E,e[67]=k,e[68]=C,e[69]=A,e[70]=F):F=e[70];let _;e[71]!==T||e[72]!==F?(_=s.jsxs(Is,{children:[T,F]}),e[71]=T,e[72]=F,e[73]=_):_=e[73];let O;e[74]!==f||e[75]!==N||e[76]!==P||e[77]!==_?(O=s.jsxs(os,{initialFocus:f,children:[N,P,_]}),e[74]=f,e[75]=N,e[76]=P,e[77]=_,e[78]=O):O=e[78];let V;return e[79]!==c||e[80]!==p||e[81]!==O?(V=s.jsx(ls,{open:c,onOpenChange:p,children:O}),e[79]=c,e[80]=p,e[81]=O,e[82]=V):V=e[82],V},ih=({mode:t="full"})=>{const{t:e}=ct(),{files:n,runtime:r}=wn(),{currentTheme:a,availableThemes:i,lightThemeId:l,darkThemeId:u}=rr(),{isMobile:d,isTablet:f,screenWidth:m}=_s(),c=d||f,p=cl(),g=td(),h=jr()??"",x=Vs(h.trim()),w=d||t!=="editor-only",b=t==="editor-only"&&!d,y=sd(ke=>ke.searchFiles),v=nd(h),[S,I]=o.useState(""),j=dl(S,200),N=o.useRef(null),[P,M]=o.useState(!1),[T,E]=o.useState(!0),[k,C]=o.useState(!1),[A,F]=o.useState(!1),[_,O]=o.useState(!1),V=o.useRef(null),K=o.useRef(0),$=o.useCallback(ke=>{K.current=Math.max(0,K.current+(ke?1:-1))},[]),oe=o.useCallback(ke=>ke instanceof Element?ke.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);o.useEffect(()=>{if(!_)return;const ke=Qe=>{K.current>0||oe(Qe.target)||V.current&&!V.current.contains(Qe.target)&&O(!1)};return document.addEventListener("mousedown",ke),()=>document.removeEventListener("mousedown",ke)},[oe,_]);const[L,Y]=o.useState("edit"),[ee,re]=o.useState("preview"),[fe,ge]=o.useState("tree"),[be,z]=o.useState("visual"),B=o.useRef({}),Q=o.useRef({}),X=o.useRef({}),ie=o.useMemo(()=>i.find(ke=>ke.metadata.id===l)??za(!1),[i,l]),le=o.useMemo(()=>i.find(ke=>ke.metadata.id===u)??za(!0),[i,u]);o.useEffect(()=>{Ba(ie),Ba(le)},[ie,le]);const ye=o.useMemo(()=>[],[]),W=sn(ke=>x?ke.byRoot[x]?.openPaths??ye:ye),ue=sn(ke=>x?ke.byRoot[x]?.selectedPath??null:null),ae=sn(ke=>x?ke.byRoot[x]?.expandedPaths??ye:ye),U=sn(ke=>ke.addOpenPath),G=sn(ke=>ke.removeOpenPath),ne=sn(ke=>ke.removeOpenPathsByPrefix),se=sn(ke=>ke.setSelectedPath),xe=sn(ke=>ke.toggleExpandedPath),Se=sn(ke=>ke.expandPaths),je=o.useCallback(ke=>{const Qe=Vs(ke),ot=Qe.split("/"),xt=ot[ot.length-1]||Qe,St=xt.includes(".")?xt.split(".").pop()?.toLowerCase():void 0;return{name:xt,path:Qe,type:"file",extension:St}},[]),Ie=o.useMemo(()=>W.map(je),[W,je]),Oe=o.useMemo(()=>ue??W[0]??null,[W,ue]),Ne=o.useMemo(()=>Oe?je(Oe):null,[Oe,je]),he=Ne?.path??"",Fe=!!(x&&he&&!Qo(he,x)),Be=o.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Fe}),[t,Fe]),q=o.useRef(null),[Pe,$e]=o.useState({left:!1,right:!1}),Ce=o.useCallback(()=>{const ke=q.current;ke&&$e({left:ke.scrollLeft>2,right:ke.scrollLeft+ke.clientWidth<ke.scrollWidth-2})},[]),pe=o.useRef(Ce);pe.current=Ce,o.useEffect(()=>{const ke=q.current;if(!ke)return;const Qe=()=>pe.current();Qe(),ke.addEventListener("scroll",Qe,{passive:!0});const ot=new ResizeObserver(Qe);return ot.observe(ke),()=>{ke.removeEventListener("scroll",Qe),ot.disconnect()}},[Ie.length]);const[R,J]=o.useState({}),H=o.useRef(new Set),Ee=o.useRef(new Set),Ae=o.useRef(new Map),Je=o.useRef(0),[ce,_e]=o.useState([]),[et,Me]=o.useState(!1),[He,We]=o.useState(""),[Te,Ve]=o.useState(!1),[Ye,Ge]=o.useState(null),[me,Ke]=o.useState(""),[ze,tt]=o.useState(""),[it,qe]=o.useState(null),[Ze,Xe]=o.useState(""),[mt,wt]=o.useState(!1),Et=o.useRef(null),dt=o.useRef(null),gt=o.useRef(null),Wt=o.useRef(0),[Ot,Bt]=o.useState("idle"),[rt,It]=o.useState(kj),[$t,Ut]=o.useState(!1),ms=o.useRef(null),ns=o.useRef(null),Vt=o.useRef(null),Ue=o.useRef(!1),kt=o.useRef(null),Mt=o.useRef(null),ut=o.useRef(null),Kt=o.useRef(null),[Yt,ks]=o.useState(0),Cs=o.useRef(null),Fs=o.useRef({key:"",attempts:0});o.useEffect(()=>()=>{Cs.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Cs.current),Cs.current=null)},[]);const[Ls,dn]=o.useState(null),[ft,Es]=o.useState(null),[is,Z]=o.useState(""),[yt,_t]=o.useState(!1),[gs,Ps]=o.useState(null),[Ws,Ms]=o.useState(!1),[En,Mn]=o.useState(!1),[Jn,Js]=o.useState(!1),jn=!!n.writeFile,Xs=!!n.createDirectory,Nn=!!n.rename,Sn=!!n.delete,Rn=!!n.revealPath,Fn=ro(ke=>ke.availableApps),un=ro(ke=>ke.isCacheStale),Bn=ro(ke=>ke.initialize),Nt=ro(ke=>ke.loadInstalledApps);o.useEffect(()=>{Bn()},[Bn]);const Lt=o.useCallback(ke=>{n.revealPath&&n.revealPath(ke).catch(()=>{te.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),Gt=o.useCallback(async ke=>{if(!Ne?.path||await fx(Ne.path,ke.id,ke.appName)||await Hd(Ne.path,ke.appName))return;const xt=gj(Ne.path)||x;xt&&await Hd(xt,ke.appName)||te.error(e("filesView.toast.openInAppFailed",{app:ke.appName}))},[x,Ne?.path,e]),we=o.useCallback((ke,Qe)=>{dn(ke),Es(Qe),Z(ke==="rename"&&Qe.name||""),_t(!1)},[]),[at,bt]=o.useState(null),Pt=o.useRef(!1),Ht=o.useRef(null),[xs,cs]=o.useState(!1),ds=De(ke=>ke.setMainTabGuard),us=De(ke=>ke.pendingFileNavigation),rn=De(ke=>ke.setPendingFileNavigation),an=De(ke=>ke.pendingFileFocusPath),mn=De(ke=>ke.setPendingFileFocusPath),pn=De(ke=>ke.shortcutOverrides),zs=ht(ke=>ke.settingsDefaultFileViewerPreview);o.useEffect(()=>{const ke=()=>{Pt.current=!1,Ht.current=null,cs(!1)};return document.addEventListener("mouseup",ke),()=>document.removeEventListener("mouseup",ke)},[]),o.useEffect(()=>()=>{kt.current!==null&&window.clearTimeout(kt.current),Mt.current!==null&&window.clearTimeout(Mt.current)},[]);const Qs=o.useCallback((ke,Qe)=>{const ot=ke.split(`
41
+ `),a=Math.min(n.length,r.length);for(let i=0;i<a;i+=1)if(n[i]!==r[i])return i+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},$w=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},Yo=(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]})},_w=o.memo(t=>{const e=st.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:a,onSelectFile:i,isMobile:l,showModeSelector:u,mode:d,onModeChange:f}=t,m=u===void 0?!1:u,{t:c}=ct();let p;e[0]!==l?(p=N=>{if(!l)return N;const P=N.lastIndexOf("/");return P>=0?N.slice(P+1):N},e[0]=l,e[1]=p):p=e[1];const g=p;if(n.length===0)return null;let h;e[2]!==g||e[3]!==a||e[4]!==c?(h=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(dr,{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:g(a.path)}),Yo(a.insertions,a.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:c("diffView.selector.selectFile")}),e[2]=g,e[3]=a,e[4]=c,e[5]=h):h=e[5];let x;e[6]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=x):x=e[6];let w;e[7]!==h?(w=s.jsx(vs,{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,x]})}),e[7]=h,e[8]=w):w=e[8];let b;e[9]!==d||e[10]!==f||e[11]!==m||e[12]!==c?(b=m&&d&&f?s.jsxs(s.Fragment,{children:[s.jsx(xi,{className:"typography-meta text-muted-foreground",children:c("diffView.selector.viewMode")}),s.jsx(Bo,{value:d,onValueChange:N=>f(N),children:To.map(N=>s.jsx(Vo,{value:N.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:c(N.labelKey)})},N.value))}),s.jsx(Ys,{})]}):null,e[9]=d,e[10]=f,e[11]=m,e[12]=c,e[13]=b):b=e[13];const y=r??"";let v;if(e[14]!==n||e[15]!==g){let N;e[17]!==g?(N=P=>s.jsx(Vo,{value:P.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(dr,{filePath:P.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:g(P.path)}),s.jsx("span",{className:"ml-auto",children:Yo(P.insertions,P.deletions)})]})},P.path),e[17]=g,e[18]=N):N=e[18],v=n.map(N),e[14]=n,e[15]=g,e[16]=v}else v=e[16];let S;e[19]!==i||e[20]!==y||e[21]!==v?(S=s.jsx(Bo,{value:y,onValueChange:i,children:v}),e[19]=i,e[20]=y,e[21]=v,e[22]=S):S=e[22];let I;e[23]!==b||e[24]!==S?(I=s.jsxs(ws,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[b,S]}),e[23]=b,e[24]=S,e[25]=I):I=e[25];let j;return e[26]!==I||e[27]!==w?(j=s.jsxs(ys,{children:[w,I]}),e[26]=I,e[27]=w,e[28]=j):j=e[28],j}),zw=o.memo(t=>{const e=st.c(31),{mode:n,onModeChange:r}=t,{t:a}=ct();let i,l,u,d,f,m;if(e[0]!==n||e[1]!==a){const v=To.find(S=>S.value===n)??To[0];l=ys,i=vs,m=!0,f="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",u="min-w-0 truncate typography-meta",d=a(v.labelKey),e[0]=n,e[1]=a,e[2]=i,e[3]=l,e[4]=u,e[5]=d,e[6]=f,e[7]=m}else i=e[2],l=e[3],u=e[4],d=e[5],f=e[6],m=e[7];let c;e[8]!==u||e[9]!==d?(c=s.jsx("span",{className:u,children:d}),e[8]=u,e[9]=d,e[10]=c):c=e[10];let p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=p):p=e[11];let g;e[12]!==f||e[13]!==c?(g=s.jsxs("button",{className:f,children:[c,p]}),e[12]=f,e[13]=c,e[14]=g):g=e[14];let h;e[15]!==i||e[16]!==m||e[17]!==g?(h=s.jsx(i,{asChild:m,children:g}),e[15]=i,e[16]=m,e[17]=g,e[18]=h):h=e[18];let x;e[19]!==r?(x=v=>r(v),e[19]=r,e[20]=x):x=e[20];let w;e[21]!==a?(w=To.map(v=>s.jsx(Vo,{value:v.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:a(v.labelKey)})},v.value)),e[21]=a,e[22]=w):w=e[22];let b;e[23]!==n||e[24]!==w||e[25]!==x?(b=s.jsx(ws,{className:"min-w-[140px]",children:s.jsx(Bo,{value:n,onValueChange:x,children:w})}),e[23]=n,e[24]=w,e[25]=x,e[26]=b):b=e[26];let y;return e[27]!==l||e[28]!==b||e[29]!==h?(y=s.jsxs(l,{children:[h,b]}),e[27]=l,e[28]=b,e[29]=h,e[30]=y):y=e[30],y}),Bw=o.memo(t=>{const e=st.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=ct();if(n.length===0)return null;let l;if(e[0]!==n||e[1]!==a||e[2]!==r||e[3]!==i){let d;e[5]!==a||e[6]!==r||e[7]!==i?(d=f=>{const m=eh(f),c=r===f.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(f.path),className:de("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",c?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(dr,{filePath:f.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:m.color},title:i(m.descriptionKey),"aria-label":i(m.descriptionKey),children:m.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:f.path,children:f.path}),Yo(f.insertions,f.deletions)]})},f.path)},e[5]=a,e[6]=r,e[7]=i,e[8]=d):d=e[8],l=n.map(d),e[0]=n,e[1]=a,e[2]=r,e[3]=i,e[4]=l}else l=e[4];let u;return e[9]!==l?(u=s.jsx(ts,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:l})}),e[9]=l,e[10]=u):u=e[10],u}),Vw=o.memo(t=>{const e=st.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:l}=ct(),u=r.original.length>0,d=r.modified.length>0;if(!a){let x;return e[0]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=x):x=e[0],x}const f=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={contain:"size layout"},e[1]=c):c=e[1];let p;e[2]!==r.original||e[3]!==n||e[4]!==u||e[5]!==m||e[6]!==i||e[7]!==l?(p=u&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l("diffView.image.original")}),s.jsx("img",{src:r.original,alt:l("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=u,e[5]=m,e[6]=i,e[7]=l,e[8]=p):p=e[8];let g;e[9]!==r.modified||e[10]!==n||e[11]!==d||e[12]!==u||e[13]!==m||e[14]!==i||e[15]!==l?(g=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l(u?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:l("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=d,e[12]=u,e[13]=m,e[14]=i,e[15]=l,e[16]=g):g=e[16];let h;return e[17]!==f||e[18]!==p||e[19]!==g?(h=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:c,children:s.jsxs("div",{className:f,children:[p,g]})}),e[17]=f,e[18]=p,e[19]=g,e[20]=h):h=e[20],h}),Uw=o.memo(t=>{const e=st.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=ct(),l=r.original.length>0,u=r.modified.length>0,d=a?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",f=a?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let c;e[1]!==r.original||e[2]!==n||e[3]!==l||e[4]!==f||e[5]!==a||e[6]!==i?(c=l&&s.jsxs("div",{className:f,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=l,e[4]=f,e[5]=a,e[6]=i,e[7]=c):c=e[7];let p;e[8]!==r.modified||e[9]!==n||e[10]!==u||e[11]!==l||e[12]!==f||e[13]!==a||e[14]!==i?(p=u&&s.jsxs("div",{className:f,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(l?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=u,e[11]=l,e[12]=f,e[13]=a,e[14]=i,e[15]=p):p=e[15];let g;return e[16]!==d||e[17]!==c||e[18]!==p?(g=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[c,p]})}),e[16]=d,e[17]=c,e[18]=p,e[19]=g):g=e[19],g}),Kw=o.memo(t=>{const e=st.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let l;e[0]!==n?(l=Ci(n)||"text",e[0]=n,e[1]=l):l=e[1];const u=l;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Xf,{}),e[2]=m):m=e[2],m}if(Pi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(Uw,{filePath:n,diff:r,renderSideBySide:a}),e[3]=r,e[4]=n,e[5]=a,e[6]=m):m=e[6],m}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let f;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==u||e[12]!==a||e[13]!==i?(f=s.jsx("div",{className:"w-full",style:d,children:s.jsx(Jf,{original:r.original,modified:r.modified,language:u,fileName:n,renderSideBySide:a,wrapLines:i,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=u,e[12]=a,e[13]=i,e[14]=f):f=e[14],f}),Ww=o.memo(t=>{const e=st.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:l}=t;let u;e[0]!==n?(u=Ci(n)||"text",e[0]=n,e[1]=u):u=e[1];const d=u;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Xf,{}),e[2]=m):m=e[2],m}if(!a)return null;if(Pi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(Vw,{filePath:n,diff:r,isVisible:a,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=a,e[6]=i,e[7]=m):m=e[7],m}let f;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==d||e[12]!==i||e[13]!==l?(f=s.jsx(ts,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Jf,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:i,wrapLines:l,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=i,e[13]=l,e[14]=f):f=e[14],f}),Hw=o.memo(t=>{const e=st.c(122),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:l,isSelected:u,onSelect:d,registerSectionRef:f,defaultCollapsed:m,expandRequestPath:c,expandRequestNonce:p,showOpenInEditorAction:g,isOpeningInEditor:h,onOpenInEditor:x}=t,w=m===void 0?!1:m,b=c===void 0?null:c,y=p===void 0?0:p,v=g===void 0?!1:g,S=h===void 0?!1:h,{t:I}=ct(),{git:j}=wn();let N;e[0]!==n||e[1]!==r.path?(N=We=>We.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=N):N=e[2];const P=yn(N),M=yn(qw),T=De(Yw),[E,k]=o.useState(!w),[C,A]=o.useState(!1),[F,_]=o.useState(0),[O,V]=o.useState(null),[K,$]=o.useState(!1),[oe,L]=o.useState(!1),Y=o.useRef(null),ee=o.useRef(null);let re;e[3]!==r?(re=eh(r),e[3]=r,e[4]=re):re=e[4];const fe=re,ge=a==="side-by-side";let be;e:{if(!P){be=null;break e}let We;e[5]!==P.isBinary||e[6]!==P.modified||e[7]!==P.original?(We={original:P.original,modified:P.modified,isBinary:P.isBinary},e[5]=P.isBinary,e[6]=P.modified,e[7]=P.original,e[8]=We):We=e[8],be=We}const z=be;let B;e[9]!==r.path||e[10]!==f?(B=We=>{ee.current=We,f(r.path,We)},e[9]=r.path,e[10]=f,e[11]=B):B=e[11];const Q=B;let X;e[12]===Symbol.for("react.memo_cache_sentinel")?(X=We=>{k(We),We&&A(!0)},e[12]=X):X=e[12];const ie=X;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 ye=le;let W,ue;e[16]!==C||e[17]!==E||e[18]!==l?(W=()=>{if(!E||C)return;const We=ee.current;if(!We)return;if(!l.current||typeof IntersectionObserver>"u"){A(!0);return}const Te=new IntersectionObserver(Ve=>{Ve.some(Qw)&&(A(!0),Te.disconnect())},{root:l.current,rootMargin:"200px 0px",threshold:.1});return Te.observe(We),()=>Te.disconnect()},ue=[C,E,l],e[16]=C,e[17]=E,e[18]=l,e[19]=W,e[20]=ue):(W=e[19],ue=e[20]),o.useEffect(W,ue);let ae,U;e[21]!==y||e[22]!==b||e[23]!==r.path?(ae=()=>{y<=0||b!==r.path||(k(!0),A(!0))},U=[y,b,r.path],e[21]=y,e[22]=b,e[23]=r.path,e[24]=ae,e[25]=U):(ae=e[24],U=e[25]),o.useEffect(ae,U);let G,ne;e[26]!==z||e[27]!==F||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==C||e[32]!==E||e[33]!==M?(G=()=>{if(!E||!C)return;if(!n||z){Y.current=null,$(!1);return}const We=`${n}::${r.path}::${F}`;if(Y.current===We)return;Y.current=We,V(null),$(!0);let Te=!1;const Ve=j.getGitFileDiff(n,{path:r.path}),Ye=new Promise(Jw);return Promise.race([Ve,Ye]).then(Ge=>{Te||(M(n,r.path,{original:Ge.original??"",modified:Ge.modified??"",isBinary:Ge.isBinary}),$(!1))}).catch(Ge=>{if(Te)return;const me=Ge instanceof Error?Ge.message:String(Ge);V(me),$(!1)}),()=>{Te=!0,Y.current===We&&(Y.current=null)}},ne=[n,z,F,r.path,j,C,E,M],e[26]=z,e[27]=F,e[28]=n,e[29]=r.path,e[30]=j,e[31]=C,e[32]=E,e[33]=M,e[34]=G,e[35]=ne):(G=e[34],ne=e[35]),o.useEffect(G,ne);let se;e[36]!==ye||e[37]!==E?(se=()=>{ie(!E),ye()},e[36]=ye,e[37]=E,e[38]=se):se=e[38];const xe=se,Se=E?"rounded-b-none":"rounded-b-xl",je=u?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let Ie;e[39]!==Se||e[40]!==je?(Ie=de("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Se,"text-muted-foreground hover:text-foreground",je),e[39]=Se,e[40]=je,e[41]=Ie):Ie=e[41];let Oe;e[42]===Symbol.for("react.memo_cache_sentinel")?(Oe=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[42]=Oe):Oe=e[42];let Ne;e[43]!==E?(Ne=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:E?s.jsx(D,{name:"arrow-down-s",className:"size-4"}):s.jsx(D,{name:"arrow-right-s",className:"size-4"})}),e[43]=E,e[44]=Ne):Ne=e[44];let he;e[45]!==fe.color?(he={color:fe.color},e[45]=fe.color,e[46]=he):he=e[46];let Fe;e[47]!==fe.descriptionKey||e[48]!==I?(Fe=I(fe.descriptionKey),e[47]=fe.descriptionKey,e[48]=I,e[49]=Fe):Fe=e[49];let Be;e[50]!==fe.descriptionKey||e[51]!==I?(Be=I(fe.descriptionKey),e[50]=fe.descriptionKey,e[51]=I,e[52]=Be):Be=e[52];let q;e[53]!==fe.code||e[54]!==he||e[55]!==Fe||e[56]!==Be?(q=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:he,title:Fe,"aria-label":Be,children:fe.code}),e[53]=fe.code,e[54]=he,e[55]=Fe,e[56]=Be,e[57]=q):q=e[57];const Pe=r.path;let $e;e[58]!==r.path?($e=s.jsx(dr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=$e):$e=e[59];let Ce;if(e[60]!==r.path){e:{const We=r.path.lastIndexOf("/");if(We===-1){let tt;e[62]===Symbol.for("react.memo_cache_sentinel")?(tt={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[62]=tt):tt=e[62],Ce=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:tt,children:r.path});break e}const Te=r.path.slice(0,We),Ve=r.path.slice(We+1);let Ye;e[63]===Symbol.for("react.memo_cache_sentinel")?(Ye={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=Ye):Ye=e[63];let Ge;e[64]!==Te?(Ge=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:Ye,children:Te}),e[64]=Te,e[65]=Ge):Ge=e[65];let me;e[66]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[66]=me):me=e[66];let Ke;e[67]!==Ve?(Ke=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[me,s.jsx("span",{className:"text-foreground",children:Ve})]}),e[67]=Ve,e[68]=Ke):Ke=e[68];let ze;e[69]!==Ge||e[70]!==Ke?(ze=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[Ge,Ke]}),e[69]=Ge,e[70]=Ke,e[71]=ze):ze=e[71],Ce=ze}e[60]=r.path,e[61]=Ce}else Ce=e[61];let pe;e[72]!==$e||e[73]!==Ce?(pe=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[$e,Ce]}),e[72]=$e,e[73]=Ce,e[74]=pe):pe=e[74];let R;e[75]!==r.path||e[76]!==pe?(R=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Pe,children:pe}),e[75]=r.path,e[76]=pe,e[77]=R):R=e[77];let J;e[78]!==Ne||e[79]!==q||e[80]!==R?(J=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[Ne,q,R]}),e[78]=Ne,e[79]=q,e[80]=R,e[81]=J):J=e[81];let H;e[82]!==r.deletions||e[83]!==r.insertions?(H=Yo(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=H):H=e[84];let Ee;e[85]!==z||e[86]!==r.path||e[87]!==S||e[88]!==x||e[89]!==v||e[90]!==I?(Ee=v&&x?s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:I("diffView.actions.openFileInEditorAtChange"),onClick:We=>{We.stopPropagation(),x(r.path,z)},disabled:S,children:S?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"edit",className:"size-3.5"})}):null,e[85]=z,e[86]=r.path,e[87]=S,e[88]=x,e[89]=v,e[90]=I,e[91]=Ee):Ee=e[91];const Ae=ge?"side-by-side":"unified";let Je;e[92]!==r.path||e[93]!==T?(Je=We=>{const Te=We==="side-by-side"?"side-by-side":"inline";T(r.path,Te)},e[92]=r.path,e[93]=T,e[94]=Je):Je=e[94];let ce;e[95]!==Ae||e[96]!==Je?(ce=s.jsx(cf,{mode:Ae,onModeChange:Je,className:"opacity-70"}),e[95]=Ae,e[96]=Je,e[97]=ce):ce=e[97];let _e;e[98]!==H||e[99]!==Ee||e[100]!==ce?(_e=s.jsxs("div",{className:"relative flex items-center gap-2",children:[H,Ee,ce]}),e[98]=H,e[99]=Ee,e[100]=ce,e[101]=_e):_e=e[101];let et;e[102]!==xe||e[103]!==Ie||e[104]!==J||e[105]!==_e?(et=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:xe,className:Ie,children:[Oe,J,_e]})}),e[102]=xe,e[103]=Ie,e[104]=J,e[105]=_e,e[106]=et):et=e[106];let Me;e[107]!==z||e[108]!==O||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==oe||e[113]!==E||e[114]!==K||e[115]!==ge||e[116]!==i?(Me=E&&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:()=>_(Xw),children:"Retry"})]}):null,K&&!z&&!O?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"animate-spin"}),"Loading diff…"]}):null,z&&!oe&&r.insertions+r.deletions>Bu?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:()=>L(!0),children:"Render anyway"})]}):null,z&&(oe||r.insertions+r.deletions<=Bu)?s.jsx(Kw,{filePath:r.path,diff:z,renderSideBySide:ge,wrapLines:i}):null]}),e[107]=z,e[108]=O,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=oe,e[113]=E,e[114]=K,e[115]=ge,e[116]=i,e[117]=Me):Me=e[117];let He;return e[118]!==Q||e[119]!==et||e[120]!==Me?(He=s.jsxs("div",{ref:Q,className:"scroll-mt-4",children:[et,Me]}),e[118]=Q,e[119]=et,e[120]=Me,e[121]=He):He=e[121],He}),th=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1})=>{const{t:i}=ct(),{git:l,files:u}=wn(),d=jr(),{screenWidth:f,isMobile:m}=_s(),c=of(d??null),p=nd(d??null),g=lf(d??null),h=yn(J=>J.setActiveDirectory),x=yn(J=>J.ensureStatus),w=yn(J=>J.fetchStatus),b=yn(J=>J.setDiff),[y,v]=o.useState(null),[S,I]=o.useState(null),[j,N]=o.useState(0),[P,M]=o.useState(null),[T,E]=o.useState(0),[k,C]=o.useState(null),A=o.useRef(null),F=De(J=>J.pendingDiffFile),_=De(J=>J.setPendingDiffFile),O=De(J=>J.diffLayoutPreference),V=De(J=>J.diffFileLayout),K=De(J=>J.setDiffFileLayout),$=De(J=>J.diffWrapLines),oe=De(J=>J.setDiffWrapLines),L=De(J=>J.diffViewMode),Y=De(J=>J.setDiffViewMode),ee=De(J=>J.openContextFileAtLine),re=$,fe=L==="stacked",ge=m||f<=768,be=!t&&!ge&&f>=1024,z=o.useRef(null),B=o.useRef(new Map),Q=o.useRef(null),X=o.useRef(null),ie=o.useRef(!1);o.useEffect(()=>{if(!r||!fe||!P)return;const J=z.current;if(!J)return;let H=null,Ee=!1,Ae=0;const Je=Date.now()+1200;let ce=0;const _e=()=>{Ee||(Ee=!0,M(null))},et=()=>{_e()},Me=()=>{if(ce>0){ce-=1;return}_e()};window.addEventListener("wheel",et,{passive:!0,capture:!0}),window.addEventListener("touchstart",et,{passive:!0,capture:!0}),window.addEventListener("pointerdown",et,{capture:!0}),window.addEventListener("keydown",et,{capture:!0}),J.addEventListener("scroll",Me,{passive:!0});const He=()=>{if(Ee||Date.now()>Je){_e();return}const We=z.current,Te=B.current.get(P);if(!We||!Te){_e();return}const Ve=We.getBoundingClientRect(),Ge=Te.getBoundingClientRect().top-Ve.top;if(Math.abs(Ge)<=1){if(Ae+=1,Ae>=2){_e();return}}else{Ae=0;const me=Math.max(0,We.scrollHeight-We.clientHeight),Ke=Math.min(me,Math.max(0,We.scrollTop+Ge));if(Math.abs(Ke-We.scrollTop)<=.5){_e();return}ce+=1,We.scrollTop=Ke}H=window.requestAnimationFrame(He)};return H=window.requestAnimationFrame(He),()=>{Ee=!0,H!==null&&window.cancelAnimationFrame(H),window.removeEventListener("wheel",et,!0),window.removeEventListener("touchstart",et,!0),window.removeEventListener("pointerdown",et,!0),window.removeEventListener("keydown",et,!0),J.removeEventListener("scroll",Me)}},[fe,r,P]);const le=o.useMemo(()=>{if(!p?.files)return[];const J=p.diffStats??{};return p.files.map(H=>({...H,insertions:J[H.path]?.insertions??0,deletions:J[H.path]?.deletions??0,isNew:Fw(H)})).sort((H,Ee)=>H.path.localeCompare(Ee.path))},[p]),ye=o.useMemo(()=>y?le.find(J=>J.path===y)??null:null,[le,y]),W=o.useCallback(J=>{const H=V[J.path];if(H)return H;if(O==="inline")return"inline";if(O==="side-by-side")return"side-by-side";const Ee=f<Aw;return J.isNew||Ee?"inline":"side-by-side"},[V,O,f]),ue=o.useMemo(()=>ye?W(ye):null,[W,ye]);o.useEffect(()=>{d&&(h(d),x(d,l))},[d,h,x,l]),o.useEffect(()=>{if(d)return gr.onGitRefreshHint(J=>{Vu(J.directory)===Vu(d)&&w(d,l)})},[d,w,l]),o.useEffect(()=>{F&&(v(F),_(null),fe&&(ie.current=!0,Q.current=F,I(F),N(J=>J+1)))},[fe,F,_]),o.useEffect(()=>{!y&&!F&&le.length>0&&v(le[0].path)},[le,y,F]),o.useEffect(()=>{y&&le.length>0&&(le.some(H=>H.path===y)||v(le[0]?.path??null))},[le,y]);const ae=o.useCallback((J,H)=>{const Ee=B.current;H?Ee.set(J,H):Ee.delete(J)},[]),U=o.useCallback(J=>{const H=B.current.get(J),Ee=z.current;if(!H||!Ee)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const Ae=Ee.getBoundingClientRect(),ce=H.getBoundingClientRect().top-Ae.top,_e=Math.max(0,Ee.scrollHeight-Ee.clientHeight),et=Ee.scrollTop+ce,Me=Math.min(_e,Math.max(0,et)),He=Math.abs(Me-Ee.scrollTop)>.5;Ee.scrollTop=Me;const We=Math.abs(ce)<=1,Te=Me<=.5||Me>=_e-.5;return{ok:!0,aligned:We,didMove:He,atScrollLimit:Te,delta:ce}},[]);o.useEffect(()=>{if(!fe){Q.current=null,ie.current=!1,X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null);return}if(!Q.current)return;let H=0;const Ee=120;let Ae=!1,Je=0,ce=!1,_e=0;const et=Date.now()+2e3,Me=()=>{ce||(ce=!0,window.removeEventListener("wheel",We,!0),window.removeEventListener("touchstart",We,!0),window.removeEventListener("pointerdown",We,!0),window.removeEventListener("keydown",We,!0),Ve?.removeEventListener("scroll",Te))},He=()=>{Ae||(Ae=!0,Me(),Q.current=null,ie.current=!1,X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null))},We=()=>{He()},Te=()=>{if(Je>0){Je-=1;return}He()},Ve=z.current;window.addEventListener("wheel",We,{passive:!0,capture:!0}),window.addEventListener("touchstart",We,{passive:!0,capture:!0}),window.addEventListener("pointerdown",We,{capture:!0}),window.addEventListener("keydown",We,{capture:!0}),Ve?.addEventListener("scroll",Te,{passive:!0});const Ye=()=>{if(Date.now()>et){He(),X.current=null;return}if(Ae){X.current=null;return}const Ge=Q.current;if(!Ge){He(),X.current=null;return}Je+=1;const me=U(Ge);if(!me.ok){Je=Math.max(0,Je-1),H+=1,H<Ee?X.current=window.requestAnimationFrame(Ye):(He(),X.current=null);return}if(!me.aligned){if(H+=1,me.didMove){if(_e=0,H<Ee){X.current=window.requestAnimationFrame(Ye);return}}else if(_e+=1,_e<6&&(me.atScrollLimit||Math.abs(me.delta)>1)){X.current=window.requestAnimationFrame(Ye);return}}r&&ie.current&&M(Ge),He()};return X.current=window.requestAnimationFrame(Ye),()=>{Ae=!0,Me(),X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null)}},[fe,r,U,y,j]);const G=o.useCallback(J=>{v(J)},[]),ne=o.useCallback(J=>{if(X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null),Q.current=null,v(J),!fe){ie.current=!1;return}ie.current=!0,Q.current=J,U(J)},[fe,U]),se=o.useCallback(J=>{Y(J),J==="stacked"&&y&&(U(y).aligned||(Q.current=y))},[U,y,Y]),xe=o.useCallback(J=>{const H=J==="side-by-side"?"side-by-side":"inline";if(fe){le.forEach(Ee=>{K(Ee.path,H)});return}ye&&K(ye.path,H)},[le,fe,ye,K]),Se=(ue??"side-by-side")==="side-by-side",je=!n&&(!fe||!be),Ie=yn(o.useCallback(J=>!d||!y?null:J.directories.get(d)?.diffCache.get(y)??null,[d,y])),Oe=o.useMemo(()=>Ie?{original:Ie.original,modified:Ie.modified,isBinary:Ie.isBinary}:null,[Ie]),[Ne,he]=o.useState(null),Fe=o.useCallback(async(J,H)=>{if(!(!d||!J)){he(J);try{let Ee=null;if(H&&!H.isBinary&&!Pi(J)&&(Ee=Uu(H.original,H.modified)),Ee===null)try{const et=await l.getGitDiff(d,{path:J,contextLines:3});Ee=$w(et.diff)}catch{Ee=null}let Ae=H;if(Ee===null||!Ae){const et=await l.getGitFileDiff(d,{path:J});Ae={original:et.original??"",modified:et.modified??"",isBinary:et.isBinary},b(d,J,Ae)}const Je=Ee??(Ae.isBinary||Pi(J)?1:Uu(Ae.original,Ae.modified)),ce=Ow(d,J),_e=await md(u,ce);if(!_e.ok){te.error(pd(_e.reason));return}ee(d,ce,Je,1)}finally{he(Ee=>Ee===J?null:Ee)}}},[d,u,l,ee,b]),Be=o.useCallback(async()=>{y&&await Fe(y,Oe)},[Fe,Oe,y]),q=!!(y&&Ne===y),Pe=!!Ie,$e=!fe&&!!y&&!Pe;o.useEffect(()=>{if(fe)return;if(C(null),!d||!y){A.current=null;return}if(Ie){A.current=null;return}const J=`${d}::${y}::${T}`;if(A.current===J)return;A.current=J;let H=!1;const Ee=l.getGitFileDiff(d,{path:y}),Ae=Dc,Je=new Promise((ce,_e)=>{setTimeout(()=>_e(new Error(`Timed out after ${Ae}ms`)),Ae)});return Promise.race([Ee,Je]).then(ce=>{H||b(d,y,{original:ce.original??"",modified:ce.modified??"",isBinary:ce.isBinary})}).catch(ce=>{if(H)return;const _e=ce instanceof Error?ce.message:String(ce);C(_e)}),()=>{H=!0,A.current===J&&(A.current=null)}},[d,fe,y,Ie,l,b,T]);const Ce=()=>!d||!y||!Oe?null:s.jsx(Ww,{filePath:y,diff:Oe,isVisible:!0,renderSideBySide:Se,wrapLines:re},y),pe=()=>{if(!d)return null;const J=Ew(le.length);return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[be&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:i("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:le.length})]}),s.jsx(Bw,{changedFiles:le,selectedFile:y,onSelectFile:ne})]}),s.jsx(ts,{ref:z,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((H,Ee)=>s.jsx(Hw,{directory:d,file:H,layout:W(H),wrapLines:re,scrollRootRef:z,isSelected:H.path===y,onSelect:G,registerSectionRef:ae,defaultCollapsed:e?!0:Ee>=J,expandRequestPath:S,expandRequestNonce:j,showOpenInEditorAction:a,isOpeningInEditor:Ne===H.path,onOpenInEditor:(Ae,Je)=>{Fe(Ae,Je)}},H.path))})})]})},R=()=>d?g&&!p?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"animate-spin"}),i("diffView.state.loadingRepositoryStatus")]}):c===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.notGitRepository")}):le.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.cleanWorkingTree")}):fe?pe():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:[Ce(),$e&&!Pe&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:k?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:i("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:k}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{C(null),E(J=>J+1)},children:i("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"animate-spin"}),i("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!m&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(D,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:g&&!p?i("diffView.state.loadingChanges"):le.length===1?i("diffView.summary.changedFilesSingle",{count:le.length}):i("diffView.summary.changedFilesPlural",{count:le.length})})]}),!ge&&s.jsx(zw,{mode:L,onModeChange:se}),je&&s.jsx(_w,{changedFiles:le,selectedFile:y,selectedFileEntry:ye,onSelectFile:ne,isMobile:ge,showModeSelector:ge,mode:L,onModeChange:se}),s.jsx("div",{className:"flex-1"}),ye&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>oe(!$),className:de("h-5 w-5 p-0 transition-opacity",re?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:i(re?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(D,{name:"text-wrap",className:"size-4"})}),a&&ye&&!fe&&s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Be()},disabled:q,title:i("diffView.actions.openFileAtFirstChangedLine"),children:q?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"edit",className:"size-3.5"})}),ye&&ue&&s.jsx(cf,{mode:ue==="side-by-side"?"side-by-side":"unified",onModeChange:xe})]}),R()]})},Gw=()=>{const t=st.c(6),{git:e}=wn(),n=jr(),r=yn(Zw),a=yn(ej),i=px(n??null);let l,u;return t[0]!==n||t[1]!==a||t[2]!==e||t[3]!==r?(l=()=>{n&&(r(n),a(n,e))},u=[n,r,a,e],t[0]=n,t[1]=a,t[2]=e,t[3]=r,t[4]=l,t[5]=u):(l=t[4],u=t[5]),o.useEffect(l,u),i};function qw(t){return t.setDiff}function Yw(t){return t.setDiffFileLayout}function Qw(t){return t.isIntersecting}function Jw(t,e){setTimeout(()=>e(new Error(`Timed out after ${Dc}ms`)),Dc)}function Xw(t){return t+1}function Zw(t){return t.setActiveDirectory}function ej(t){return t.ensureStatus}const tj=Object.freeze(Object.defineProperty({__proto__:null,DiffView:th,useDiffFileCount:Gw},Symbol.toStringTag,{value:"Module"})),sj={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},nj={case:"Match case",re:"Regular expression",word:"Match whole word"};function rj(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(sj)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(nj)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Ku=new Ya,Wu=new Ya,Hu=new Ya,Gu=new Ya,qu=new Ya,Yu=new Ya,Qu=t=>t,Gl=Ng,aj=Sg,ij=kg;class oj extends Cg{constructor(e,n){super(),this.id=e,this.containerMap=n}id;containerMap;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 Ju=(t,e)=>!t||t.length===0?[]:jg.define({create(n){const r=new Vp,a=[...t].sort((i,l)=>i.afterLine-l.afterLine);for(const i of a){const l=n.doc.lines;if(i.afterLine>l)continue;const u=n.doc.line(i.afterLine);r.add(u.to,u.to,Up.widget({widget:new oj(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>Tn.decorations.from(n)}),Xu=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return wg.fromClass(class{decorations;constructor(r){this.decorations=this.build(r)}update(r){(r.docChanged||r.viewportChanged)&&(this.decorations=this.build(r.view))}build(r){const a=new Vp;for(let i=e;i<=n&&i<=r.state.doc.lines;i+=1){const l=r.state.doc.line(i);a.add(l.from,l.from,Up.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function Tc({value:t,onChange:e,extensions:n,className:r,readOnly:a,lineNumbersConfig:i,highlightLines:l,onViewReady:u,onViewDestroy:d,blockWidgets:f,enableSearch:m,searchOpen:c,onSearchOpenChange:p}){const g=o.useRef(null),h=o.useRef(null),x=o.useRef(t),w=o.useRef(e),b=o.useRef(u),y=o.useRef(d),v=o.useRef(p),S=o.useRef(f),I=o.useRef(new Map),[j,N]=o.useState([]),P=o.useCallback(T=>{const E=(T??[]).map(k=>{const C=I.current.get(k.id);return C?{id:k.id,content:k.content,container:C}:null}).filter(k=>k!==null);N(k=>k.length===E.length&&k.every((C,A)=>{const F=E[A];return C.id===F.id&&C.content===F.content&&C.container===F.container})?k:E)},[]),M=o.useCallback(T=>{const E=g.current,k=T??h.current;if(!E||!k)return;const C=k.dom.querySelector(".cm-gutters"),A=C instanceof HTMLElement?C.getBoundingClientRect().width:0;E.style.setProperty("--oc-editor-gutter-width",`${A}px`)},[]);return o.useEffect(()=>{x.current=t},[t]),o.useEffect(()=>{w.current=e},[e]),o.useEffect(()=>{b.current=u,y.current=d},[u,d]),o.useEffect(()=>{v.current=p},[p]),o.useEffect(()=>{S.current=f,P(f)},[f,P]),o.useEffect(()=>{if(!g.current)return;const T=(()=>{if(typeof document>"u")return null;const k=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(k)return k;const C=window.__APP_CSP_NONCE__;return typeof C=="string"&&C.length>0?C:null})(),E=fg.create({doc:x.current,extensions:[...T?[Tn.cspNonce.of(T)]:[],hg({fixed:!0}),Ku.of(Rd(i)),gg(),xg.of(" "),Dl.of([bg,...yg,...vg]),Tn.updateListener.of(k=>{M(k.view),(k.viewportChanged||k.geometryChanged)&&P(S.current);const C=Fd(k.startState),A=Fd(k.state);if(C!==A&&v.current?.(A),!k.docChanged)return;const F=k.state.doc.toString();x.current=F,w.current(F),P(S.current)}),Wu.of(Tn.editable.of(!a)),Hu.of(n??[]),Gu.of(Xu(l)),qu.of(Ju(f,I.current)),Yu.of(m?[Ld({top:!0}),Dl.of(Qu(Od))]:[])]});return h.current=new Tn({state:E,parent:g.current}),Gl(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{M(h.current),P(S.current)}),h.current&&b.current?.(h.current),()=>{y.current?.(),h.current?.destroy(),h.current=null,N([])}},[S,M,P]),o.useEffect(()=>{const T=h.current;T&&(T.dispatch({effects:[Ku.reconfigure(Rd(i)),Wu.reconfigure(Tn.editable.of(!a)),Hu.reconfigure(n??[]),Gu.reconfigure(Xu(l)),qu.reconfigure(Ju(f,I.current)),Yu.reconfigure(m?[Ld({top:!0}),Dl.of(Qu(Od))]:[])]}),Gl(T,T.state.doc.length,200),T.requestMeasure(),requestAnimationFrame(()=>{M(T),P(S.current)}))},[n,l,i,a,f,m,M,P]),o.useEffect(()=>{const T=h.current;!T||m===!1||(c?(aj(T),requestAnimationFrame(()=>{rj(T.dom)})):ij(T))},[c,m]),o.useEffect(()=>{const T=h.current;if(!T)return;const E=T.state.doc.toString();E!==t&&(T.dispatch({changes:{from:0,to:E.length,insert:t}}),Gl(T,T.state.doc.length,300),T.requestMeasure(),requestAnimationFrame(()=>M(T)))},[t,M]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:g,className:de("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(T=>gi.createPortal(T.content,T.container,T.id))]})}const lj=(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)},Zu=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},em=(t,e,n)=>{const r=t.state.doc.line(e),a=Math.max(1,Math.min(n,r.length+1)),i=r.from+a-1;t.dispatch({selection:Pg.cursor(i),effects:Tn.scrollIntoView(i,{y:"center"})})};function cj({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=ct(),[i,l]=o.useState(""),u=o.useRef(null),d=o.useRef(!1),f=o.useRef(null),m=o.useRef(null),c=o.useMemo(()=>lj(i,n),[i,n]);o.useEffect(()=>{!t||!n||(d.current=!1,u.current=Zu(n,n.state.selection),l(""))},[t,n]),o.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),o.useEffect(()=>{if(!(!t||!n||!u.current)){if(c===null){const{selection:w}=u.current;n.dispatch({selection:w,effects:Tn.scrollIntoView(w.main.from,{y:"center"})});return}em(n,c,u.current.character)}},[c,t,n]);const p=o.useCallback(()=>{if(!n||d.current||!u.current)return;const{selection:w}=u.current;n.dispatch({selection:w,effects:Tn.scrollIntoView(w.main.from,{y:"center"})})},[n]),g=o.useCallback(w=>{w||p(),e(w)},[e,p]),h=o.useCallback(()=>{!n||c===null||!u.current||(d.current=!0,em(n,c,u.current.character),e(!1),n.focus())},[c,e,n]);o.useEffect(()=>{if(!t)return;const w=y=>{const v=f.current,S=y.target;!v||!(S instanceof Node)||v.contains(S)||g(!1)},b=y=>{y.key==="Escape"&&(y.preventDefault(),g(!1))};return document.addEventListener("pointerdown",w,!0),document.addEventListener("keydown",b,!0),()=>{document.removeEventListener("pointerdown",w,!0),document.removeEventListener("keydown",b,!0)}},[g,t,r]);const x=o.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(c===null){const w=u.current??Zu(n,n.state.selection);return a("goToLineDialog.helper.currentLineRange",{current:w.lineNumber,max:n.state.doc.lines})}return a("goToLineDialog.helper.goToLine",{line:c})},[c,a,n]);return r==="inline"?t?s.jsxs("div",{ref:f,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(jt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:w=>l(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(ve,{variant:"outline",size:"xs",onClick:h,disabled:!n||c===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:f,className:de("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(jt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:w=>l(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:x})]})})}const Ac=t=>{const e=st.c(11),{currentMode:n,onToggle:r}=t,a=n==="preview",i=a?"Switch to edit mode":"Switch to preview mode",l=a?"Edit":"Preview";let u;e[0]!==a?(u=a?s.jsx(D,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(D,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=a,e[1]=u):u=e[1];let d;e[2]!==i||e[3]!==r||e[4]!==u?(d=s.jsx(At,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:r,"aria-label":i,className:"h-5 w-5 p-0",children:u})}),e[2]=i,e[3]=r,e[4]=u,e[5]=d):d=e[5];let f;e[6]!==l?(f=s.jsx(Rt,{sideOffset:8,children:l}),e[6]=l,e[7]=f):f=e[7];let m;return e[8]!==d||e[9]!==f?(m=s.jsxs(Tt,{children:[d,f]}),e[8]=d,e[9]=f,e[10]=m):m=e[10],m},Ec=Ig.define(Dg);function dj(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return Ec;case"json":case"jsonc":case"json5":return Hp().language;case"js":case"javascript":return Pa().language;case"jsx":return Pa({jsx:!0}).language;case"ts":case"typescript":return Pa({typescript:!0}).language;case"tsx":return Pa({typescript:!0,jsx:!0}).language;case"html":return bc().language;case"css":return Wp().language;case"py":case"python":return Kp().language;case"heex":case"eex":case"leex":return bc().language;default:return Gp.matchLanguageName(qp,e,!0)}}const sh=t=>t.split("/").pop()?.toLowerCase()??"",uj=t=>{const e=sh(t);return e?Gp.matchFilename(qp,e):null},mj=()=>ui(yc.define([{tag:[nt.heading1,nt.heading2,nt.heading3,nt.heading4,nt.heading5,nt.heading6],fontWeight:"600"},{tag:nt.strong,fontWeight:"600"},{tag:nt.emphasis,fontStyle:"italic"},{tag:nt.strikethrough,textDecoration:"line-through"},{tag:[nt.link,nt.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:nt.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:nt.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:nt.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:nt.heading,color:"var(--markdown-heading1, currentColor)"}]));function nh(t){const e=t.toLowerCase();switch(sh(e)){case"makefile":case"gnumakefile":return Ec}const r=e.lastIndexOf("."),a=r>=0?e.slice(r+1):"";switch(a){case"ts":case"tsx":case"mts":case"cts":return Pa({typescript:!0,jsx:a==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return Pa({typescript:!1,jsx:a==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return Hp();case"css":case"scss":case"sass":case"less":return Wp();case"html":case"htm":return bc();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[Tg({codeLanguages:dj}),mj()];case"sh":case"bash":case"zsh":case"fish":case"env":return Ec;case"py":case"pyw":case"pyi":return Kp();default:return null}}async function pj(t){const e=uj(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function Mc(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=Tn.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:a.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:a.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:a.boolean||t.colors.syntax.base.number},".cm-builtin":{color:a.functionCall||t.colors.syntax.base.function},".cm-def":{color:a.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:a.variableOther||a.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:a.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:a.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:a.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:a.tag||t.colors.syntax.base.keyword},".cm-link":{color:a.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),l=yc.define([{tag:[nt.comment,nt.docComment,nt.meta,nt.documentMeta],class:"cm-comment"},{tag:[nt.keyword,nt.controlKeyword,nt.moduleKeyword,nt.definitionKeyword,nt.modifier],class:"cm-keyword"},{tag:[nt.operatorKeyword,nt.operator,nt.derefOperator,nt.updateOperator,nt.definitionOperator,nt.typeOperator,nt.controlOperator,nt.logicOperator,nt.bitwiseOperator,nt.arithmeticOperator,nt.compareOperator],class:"cm-operator"},{tag:[nt.punctuation,nt.separator,nt.bracket,nt.paren,nt.brace,nt.squareBracket,nt.angleBracket],class:"cm-punctuation"},{tag:[nt.string,nt.regexp,nt.attributeValue,nt.special(nt.string),nt.monospace],class:"cm-string"},{tag:nt.escape,class:"cm-string-2"},{tag:[nt.number,nt.bool,nt.atom,nt.null,nt.self],class:"cm-number"},{tag:[nt.function(nt.variableName),nt.function(nt.definition(nt.variableName)),nt.function(nt.propertyName),nt.standard(nt.variableName),nt.special(nt.variableName)],class:"cm-builtin"},{tag:nt.definition(nt.variableName),class:"cm-def"},{tag:[nt.variableName,nt.local(nt.variableName),nt.constant(nt.variableName),nt.literal],class:"cm-variable"},{tag:nt.propertyName,class:"cm-property"},{tag:nt.attributeName,class:"cm-attribute"},{tag:[nt.className,nt.typeName,nt.namespace],class:"cm-variable-3"},{tag:[nt.tagName,nt.labelName,nt.annotation,nt.macroName],class:"cm-tag"},{tag:nt.link,class:"cm-link"},{tag:[nt.heading,nt.heading1,nt.heading2,nt.heading3,nt.heading4,nt.heading5,nt.heading6],class:"cm-keyword"}]),u=yc.define([{tag:[nt.comment,nt.docComment,nt.meta,nt.documentMeta],color:t.colors.syntax.base.comment},{tag:[nt.keyword,nt.controlKeyword,nt.moduleKeyword,nt.definitionKeyword,nt.modifier],color:t.colors.syntax.base.keyword},{tag:[nt.operatorKeyword,nt.operator,nt.derefOperator,nt.updateOperator,nt.definitionOperator,nt.typeOperator,nt.controlOperator,nt.logicOperator,nt.bitwiseOperator,nt.arithmeticOperator,nt.compareOperator],color:t.colors.syntax.base.operator},{tag:[nt.string,nt.regexp,nt.attributeValue,nt.special(nt.string),nt.monospace],color:t.colors.syntax.base.string},{tag:nt.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[nt.number,nt.bool,nt.atom,nt.null,nt.self],color:t.colors.syntax.base.number},{tag:[nt.function(nt.variableName),nt.function(nt.definition(nt.variableName)),nt.function(nt.propertyName),nt.standard(nt.variableName),nt.special(nt.variableName)],color:t.colors.syntax.base.function},{tag:nt.definition(nt.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[nt.variableName,nt.local(nt.variableName),nt.constant(nt.variableName),nt.literal],color:t.colors.syntax.base.variable},{tag:nt.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:nt.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[nt.className,nt.typeName,nt.namespace],color:t.colors.syntax.base.type},{tag:[nt.tagName,nt.labelName,nt.annotation,nt.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:nt.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[nt.punctuation,nt.separator,nt.bracket,nt.paren,nt.brace,nt.squareBracket,nt.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,ui(Ag,{fallback:!0}),ui(Eg),ui(l),ui(u)]}const 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"}],tm="finder",Rc=new Set(["finder","terminal"]),Fc=t=>t?Ta.find(e=>e.id===t)??null:null,ql=()=>Ta.filter(t=>Rc.has(t.id)).map(t=>({...t})),fj=()=>{if(typeof window>"u")return tm;const t=window.localStorage.getItem("openInAppId");return t&&Fc(t)?t:tm};let Yl=!1,wa=!1,zr=!1,Br=0,vi=null;const sm=()=>{vi&&(clearTimeout(vi),vi=null)},ro=vn()((t,e)=>({selectedAppId:fj(),availableApps:ql(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Yl||typeof window>"u")return;Yl=!0;const n=(d,f=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:ql(),hasLoadedApps:f});return}const m=new Set(d.map(h=>h.name)),c=new Map(d.map(h=>[h.name,h.iconDataUrl??void 0])),g=Ta.filter(h=>m.has(h.appName)||Rc.has(h.id)).map(h=>({...h,iconDataUrl:c.get(h.appName)}));t({availableApps:g,hasLoadedApps:!0})},r=async d=>{if(!Ii()||!Va()||wa||e().hasLoadedApps&&!d)return;const m=Ta.map(c=>c.appName);sm(),wa=!0,zr=!1,t({isScanning:!0});try{const{apps:c,success:p,hasCache:g,isCacheStale:h}=await Wd(m,d),x=p&&!g&&c.length===0&&Br<3;if(t({isCacheStale:g?h:!1}),n(c,p?!x:!1),p){if(x){const b=[800,1600,3200][Br]??3200;Br+=1,zr=!0,vi=setTimeout(()=>{r()},b);return}Br=0,zr=!1;return}if(Br<3){const b=[1e3,3e3,7e3][Br]??7e3;Br+=1,zr=!0,vi=setTimeout(()=>{r()},b)}}finally{wa=!1,zr||t({isScanning:!1})}};r();const a=d=>{const f=d.detail,m=f&&typeof f.openInAppId=="string"&&f.openInAppId.length>0&&Fc(f.openInAppId)?f.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},i=()=>{r()},l=d=>{const f=d.detail;Array.isArray(f)&&(Br=3,zr=!1,t({isScanning:!1,isCacheStale:!1}),n(f))};window.addEventListener("vinci:settings-synced",a),window.addEventListener("vinci:app-ready",i),window.addEventListener("vinci:installed-apps-updated",l),window.__vinciAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Yl||e().initialize(),!Ii()||!Va()||wa||e().hasLoadedApps&&!n)return;const a=Ta.map(i=>i.appName);sm(),n&&t({hasLoadedApps:!1}),wa=!0,zr=!1,t({isScanning:!0});try{const{apps:i,hasCache:l,isCacheStale:u}=await Wd(a,n),d=new Set(i.map(p=>p.name)),f=new Map(i.map(p=>[p.name,p.iconDataUrl??void 0])),c=Ta.filter(p=>d.has(p.appName)||Rc.has(p.id)).map(p=>({...p,iconDataUrl:f.get(p.appName)}));t({availableApps:c.length>0?c:ql(),hasLoadedApps:c.length>0,isCacheStale:l?u:!1})}finally{wa=!1,zr||t({isScanning:!1})}},selectApp:async n=>{Fc(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await rs({openInAppId:n}))}})),hj=o.lazy(()=>Qn(()=>import("./HtmlEditor-DdqeDNYP.js"),__vite__mapDeps([2,0,1,3,4,5]))),gj=t=>{const e=Vs(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},xj=t=>{const e=st.c(8),{label:n,iconDataUrl:r}=t,[a,i]=o.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const u=l;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let c;return e[3]!==r?(c=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=c):c=e[4],c}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=de("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let f;return e[6]!==u?(f=s.jsx("span",{className:d,children:u}),e[6]=u,e[7]=f):f=e[7],f},bj=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Vs=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},yj=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),nm=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,Qo=(t,e)=>{const n=Vs(e),r=Vs(t);if(!n||!r)return!1;const a=nm(n),i=nm(r);return i===a||i.startsWith(`${a}/`)},rm=(t,e)=>{const n=Vs(e),r=Vs(t);if(!Qo(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),l=[];let u=n;for(let d=0;d<i.length-1;d++)u=u?`${u}/${i[d]}`:i[d],l.push(u);return l},Lc=(t,e)=>{if(!e)return"";const n=Vs(e);if(!t||!Qo(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},vj=new Set(["node_modules"]),wj=t=>{const e=st.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const a=r[n];let i;return e[1]!==a?(i=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:a}}),e[1]=a,e[2]=i):i=e[2],i},jj=t=>vj.has(t),Nj=t=>{const e=Vs(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Sj=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},ai=2e5,rh="vinci:files:auto-save-enabled",kj=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(rh)!=="false"}catch{return!0}},ah=(t,e)=>s.jsx(dr,{filePath:t,extension:e}),Cj=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},Pj=t=>{const e=st.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:l,alwaysShowActions:u,status:d,badge:f,permissions:m,downloadFile:c,contextMenuPath:p,setContextMenuPath:g,onSelect:h,onToggle:x,onRevealPath:w,onOpenDialog:b}=t,{t:y}=ct(),v=n.type==="directory",{canRename:S,canCreateFile:I,canCreateFolder:j,canDelete:N,canReveal:P}=m;let M;e[0]!==I||e[1]!==j||e[2]!==N||e[3]!==S||e[4]!==P||e[5]!==n.path||e[6]!==g?(M=fe=>{!S&&!I&&!j&&!N&&!P||(fe?.preventDefault(),g(n.path))},e[0]=I,e[1]=j,e[2]=N,e[3]=S,e[4]=P,e[5]=n.path,e[6]=g,e[7]=M):M=e[7];const T=M;let E;e[8]!==v||e[9]!==n||e[10]!==h||e[11]!==x?(E=()=>{v?x(n.path):h(n)},e[8]=v,e[9]=n,e[10]=h,e[11]=x,e[12]=E):E=e[12];const k=E;let C;e[13]!==n.path||e[14]!==g?(C=fe=>{fe.stopPropagation(),g(n.path)},e[13]=n.path,e[14]=g,e[15]=C):C=e[15];const A=C,F=l?void 0:T,_=l?void 0:T,O=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[16]!==O?(V=de("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 K;e[18]!==v||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?(K=v?a?s.jsx(D,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(D,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):ah(n.path,n.extension),e[18]=v,e[19]=a,e[20]=n.extension,e[21]=n.path,e[22]=K):K=e[22];let $;e[23]!==n.name||e[24]!==n.path?($=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=$):$=e[25];let oe;e[26]!==v||e[27]!==d?(oe=!v&&d&&s.jsx(wj,{status:d}),e[26]=v,e[27]=d,e[28]=oe):oe=e[28];let L;e[29]!==f||e[30]!==v?(L=v&&f&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[f.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",f.modified]}),f.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",f.added]})]}),e[29]=f,e[30]=v,e[31]=L):L=e[31];let Y;e[32]!==k||e[33]!==oe||e[34]!==L||e[35]!==_||e[36]!==V||e[37]!==K||e[38]!==$?(Y=s.jsxs("button",{type:"button",onClick:k,onContextMenu:_,className:V,children:[K,$,oe,L]}),e[32]=k,e[33]=oe,e[34]=L,e[35]=_,e[36]=V,e[37]=K,e[38]=$,e[39]=Y):Y=e[39];let ee;e[40]!==u||e[41]!==I||e[42]!==j||e[43]!==N||e[44]!==S||e[45]!==P||e[46]!==p||e[47]!==c||e[48]!==A||e[49]!==v||e[50]!==l||e[51]!==n||e[52]!==b||e[53]!==w||e[54]!==r||e[55]!==g||e[56]!==y?(ee=(S||I||j||N||P)&&s.jsx("div",{className:de("absolute right-1 top-1/2 -translate-y-1/2",u?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(ys,{open:p===n.path,onOpenChange:fe=>g(fe?n.path:null),children:[s.jsx(vs,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"size-6",onClick:A,children:s.jsx(D,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(ws,{align:"end",side:"bottom",onCloseAutoFocus:()=>g(null),children:[S&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),b("rename",n)},children:[s.jsx(D,{name:"edit",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.rename")]}),s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),An(n.path).then(ge=>{if(ge.ok){te.success(y("sidebarFilesTree.toast.pathCopied"));return}te.error(y("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.copyPath")]}),s.jsxs(vt,{onClick:fe=>{fe.stopPropagation();const ge=Lc(r,n.path)||n.path;An(ge).then(be=>{if(be.ok){te.success(y("filesView.toast.relativePathCopied"));return}te.error(y("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy-2",className:"mr-2 size-4"})," ",y("filesView.tree.menu.copyRelativePath")]}),!v&&c&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),c(n.path)},children:[s.jsx(D,{name:"download",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.save")]}),P&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),w(n.path)},children:[s.jsx(D,{name:"folder-received",className:"mr-2 size-4"})," ",y(af())]}),v&&(I||j)&&s.jsxs(s.Fragment,{children:[s.jsx(Ys,{}),I&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),b("createFile",n)},children:[s.jsx(D,{name:"file-add",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),b("createFolder",n)},children:[s.jsx(D,{name:"folder-add",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.newFolder")]})]}),N&&s.jsxs(s.Fragment,{children:[s.jsx(Ys,{}),s.jsxs(vt,{onClick:fe=>{fe.stopPropagation(),b("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"mr-2 size-4"})," ",y("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=u,e[41]=I,e[42]=j,e[43]=N,e[44]=S,e[45]=P,e[46]=p,e[47]=c,e[48]=A,e[49]=v,e[50]=l,e[51]=n,e[52]=b,e[53]=w,e[54]=r,e[55]=g,e[56]=y,e[57]=ee):ee=e[57];let re;return e[58]!==Y||e[59]!==ee||e[60]!==F?(re=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:F,children:[Y,ee]}),e[58]=Y,e[59]=ee,e[60]=F,e[61]=re):re=e[61],re},Ij=t=>{const e=st.c(83),{activeDialog:n,dialogData:r,dialogInputValue:a,onDialogInputChange:i,isDialogSubmitting:l,onDialogSubmit:u,onClose:d,inputRef:f}=t,{t:m}=ct(),c=!!n;let p;e[0]!==d?(p=K=>!K&&d(),e[0]=d,e[1]=p):p=e[1];let g;e[2]!==n||e[3]!==m?(g=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=g):g=e[4];let h;e[5]!==n||e[6]!==m?(h=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=h):h=e[7];let x;e[8]!==n||e[9]!==m?(x=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=x):x=e[10];let w;e[11]!==n||e[12]!==m?(w=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=w):w=e[13];let b;e[14]!==g||e[15]!==h||e[16]!==x||e[17]!==w?(b=s.jsxs(hs,{children:[g,h,x,w]}),e[14]=g,e[15]=h,e[16]=x,e[17]=w,e[18]=b):b=e[18];let y;e[19]!==n||e[20]!==r?.path||e[21]!==m?(y=n==="createFile"&&m("filesView.dialog.createFile.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=m,e[22]=y):y=e[22];let v;e[23]!==n||e[24]!==r?.path||e[25]!==m?(v=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=m,e[26]=v):v=e[26];let S;e[27]!==n||e[28]!==r?.name||e[29]!==m?(S=n==="rename"&&m("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=m,e[30]=S):S=e[30];let I;e[31]!==n||e[32]!==r?.name||e[33]!==m?(I=n==="delete"&&m("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=m,e[34]=I):I=e[34];let j;e[35]!==S||e[36]!==I||e[37]!==y||e[38]!==v?(j=s.jsxs(Ss,{children:[y,v,S,I]}),e[35]=S,e[36]=I,e[37]=y,e[38]=v,e[39]=j):j=e[39];let N;e[40]!==j||e[41]!==b?(N=s.jsxs(bs,{children:[b,j]}),e[40]=j,e[41]=b,e[42]=N):N=e[42];let P;e[43]!==n||e[44]!==a||e[45]!==f||e[46]!==i||e[47]!==u||e[48]!==m?(P=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(jt,{value:a,onChange:K=>i(K.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:K=>{K.key==="Enter"&&u()},ref:f})}),e[43]=n,e[44]=a,e[45]=f,e[46]=i,e[47]=u,e[48]=m,e[49]=P):P=e[49];let M;e[50]!==m?(M=m("filesView.dialog.cancel"),e[50]=m,e[51]=M):M=e[51];let T;e[52]!==l||e[53]!==d||e[54]!==M?(T=s.jsx(ve,{variant:"outline",onClick:d,disabled:l,children:M}),e[52]=l,e[53]=d,e[54]=M,e[55]=T):T=e[55];const E=n==="delete"?"destructive":"default";let k;e[56]!==u?(k=()=>{u()},e[56]=u,e[57]=k):k=e[57];let C;e[58]!==n||e[59]!==a||e[60]!==l?(C=l||n!=="delete"&&!a.trim(),e[58]=n,e[59]=a,e[60]=l,e[61]=C):C=e[61];let A;e[62]!==n||e[63]!==l||e[64]!==m?(A=l?s.jsx(D,{name:"loader-4",className:"animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=l,e[64]=m,e[65]=A):A=e[65];let F;e[66]!==E||e[67]!==k||e[68]!==C||e[69]!==A?(F=s.jsx(ve,{variant:E,onClick:k,disabled:C,children:A}),e[66]=E,e[67]=k,e[68]=C,e[69]=A,e[70]=F):F=e[70];let _;e[71]!==T||e[72]!==F?(_=s.jsxs(Is,{children:[T,F]}),e[71]=T,e[72]=F,e[73]=_):_=e[73];let O;e[74]!==f||e[75]!==N||e[76]!==P||e[77]!==_?(O=s.jsxs(os,{initialFocus:f,children:[N,P,_]}),e[74]=f,e[75]=N,e[76]=P,e[77]=_,e[78]=O):O=e[78];let V;return e[79]!==c||e[80]!==p||e[81]!==O?(V=s.jsx(ls,{open:c,onOpenChange:p,children:O}),e[79]=c,e[80]=p,e[81]=O,e[82]=V):V=e[82],V},ih=({mode:t="full"})=>{const{t:e}=ct(),{files:n,runtime:r}=wn(),{currentTheme:a,availableThemes:i,lightThemeId:l,darkThemeId:u}=rr(),{isMobile:d,isTablet:f,screenWidth:m}=_s(),c=d||f,p=cl(),g=td(),h=jr()??"",x=Vs(h.trim()),w=d||t!=="editor-only",b=t==="editor-only"&&!d,y=sd(ke=>ke.searchFiles),v=nd(h),[S,I]=o.useState(""),j=dl(S,200),N=o.useRef(null),[P,M]=o.useState(!1),[T,E]=o.useState(!0),[k,C]=o.useState(!1),[A,F]=o.useState(!1),[_,O]=o.useState(!1),V=o.useRef(null),K=o.useRef(0),$=o.useCallback(ke=>{K.current=Math.max(0,K.current+(ke?1:-1))},[]),oe=o.useCallback(ke=>ke instanceof Element?ke.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);o.useEffect(()=>{if(!_)return;const ke=Qe=>{K.current>0||oe(Qe.target)||V.current&&!V.current.contains(Qe.target)&&O(!1)};return document.addEventListener("mousedown",ke),()=>document.removeEventListener("mousedown",ke)},[oe,_]);const[L,Y]=o.useState("edit"),[ee,re]=o.useState("preview"),[fe,ge]=o.useState("tree"),[be,z]=o.useState("visual"),B=o.useRef({}),Q=o.useRef({}),X=o.useRef({}),ie=o.useMemo(()=>i.find(ke=>ke.metadata.id===l)??za(!1),[i,l]),le=o.useMemo(()=>i.find(ke=>ke.metadata.id===u)??za(!0),[i,u]);o.useEffect(()=>{Ba(ie),Ba(le)},[ie,le]);const ye=o.useMemo(()=>[],[]),W=sn(ke=>x?ke.byRoot[x]?.openPaths??ye:ye),ue=sn(ke=>x?ke.byRoot[x]?.selectedPath??null:null),ae=sn(ke=>x?ke.byRoot[x]?.expandedPaths??ye:ye),U=sn(ke=>ke.addOpenPath),G=sn(ke=>ke.removeOpenPath),ne=sn(ke=>ke.removeOpenPathsByPrefix),se=sn(ke=>ke.setSelectedPath),xe=sn(ke=>ke.toggleExpandedPath),Se=sn(ke=>ke.expandPaths),je=o.useCallback(ke=>{const Qe=Vs(ke),ot=Qe.split("/"),xt=ot[ot.length-1]||Qe,St=xt.includes(".")?xt.split(".").pop()?.toLowerCase():void 0;return{name:xt,path:Qe,type:"file",extension:St}},[]),Ie=o.useMemo(()=>W.map(je),[W,je]),Oe=o.useMemo(()=>ue??W[0]??null,[W,ue]),Ne=o.useMemo(()=>Oe?je(Oe):null,[Oe,je]),he=Ne?.path??"",Fe=!!(x&&he&&!Qo(he,x)),Be=o.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Fe}),[t,Fe]),q=o.useRef(null),[Pe,$e]=o.useState({left:!1,right:!1}),Ce=o.useCallback(()=>{const ke=q.current;ke&&$e({left:ke.scrollLeft>2,right:ke.scrollLeft+ke.clientWidth<ke.scrollWidth-2})},[]),pe=o.useRef(Ce);pe.current=Ce,o.useEffect(()=>{const ke=q.current;if(!ke)return;const Qe=()=>pe.current();Qe(),ke.addEventListener("scroll",Qe,{passive:!0});const ot=new ResizeObserver(Qe);return ot.observe(ke),()=>{ke.removeEventListener("scroll",Qe),ot.disconnect()}},[Ie.length]);const[R,J]=o.useState({}),H=o.useRef(new Set),Ee=o.useRef(new Set),Ae=o.useRef(new Map),Je=o.useRef(0),[ce,_e]=o.useState([]),[et,Me]=o.useState(!1),[He,We]=o.useState(""),[Te,Ve]=o.useState(!1),[Ye,Ge]=o.useState(null),[me,Ke]=o.useState(""),[ze,tt]=o.useState(""),[it,qe]=o.useState(null),[Ze,Xe]=o.useState(""),[mt,wt]=o.useState(!1),Et=o.useRef(null),dt=o.useRef(null),gt=o.useRef(null),Wt=o.useRef(0),[Ot,Bt]=o.useState("idle"),[rt,It]=o.useState(kj),[$t,Ut]=o.useState(!1),ms=o.useRef(null),ns=o.useRef(null),Vt=o.useRef(null),Ue=o.useRef(!1),kt=o.useRef(null),Mt=o.useRef(null),ut=o.useRef(null),Kt=o.useRef(null),[Yt,ks]=o.useState(0),Cs=o.useRef(null),Fs=o.useRef({key:"",attempts:0});o.useEffect(()=>()=>{Cs.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Cs.current),Cs.current=null)},[]);const[Ls,dn]=o.useState(null),[ft,Es]=o.useState(null),[is,Z]=o.useState(""),[yt,_t]=o.useState(!1),[gs,Ps]=o.useState(null),[Ws,Ms]=o.useState(!1),[En,Mn]=o.useState(!1),[Jn,Js]=o.useState(!1),jn=!!n.writeFile,Xs=!!n.createDirectory,Nn=!!n.rename,Sn=!!n.delete,Rn=!!n.revealPath,Fn=ro(ke=>ke.availableApps),un=ro(ke=>ke.isCacheStale),Bn=ro(ke=>ke.initialize),Nt=ro(ke=>ke.loadInstalledApps);o.useEffect(()=>{Bn()},[Bn]);const Lt=o.useCallback(ke=>{n.revealPath&&n.revealPath(ke).catch(()=>{te.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),Gt=o.useCallback(async ke=>{if(!Ne?.path||await fx(Ne.path,ke.id,ke.appName)||await Hd(Ne.path,ke.appName))return;const xt=gj(Ne.path)||x;xt&&await Hd(xt,ke.appName)||te.error(e("filesView.toast.openInAppFailed",{app:ke.appName}))},[x,Ne?.path,e]),we=o.useCallback((ke,Qe)=>{dn(ke),Es(Qe),Z(ke==="rename"&&Qe.name||""),_t(!1)},[]),[at,bt]=o.useState(null),Pt=o.useRef(!1),Ht=o.useRef(null),[xs,cs]=o.useState(!1),ds=De(ke=>ke.setMainTabGuard),us=De(ke=>ke.pendingFileNavigation),rn=De(ke=>ke.setPendingFileNavigation),an=De(ke=>ke.pendingFileFocusPath),mn=De(ke=>ke.setPendingFileFocusPath),pn=De(ke=>ke.shortcutOverrides),zs=ht(ke=>ke.settingsDefaultFileViewerPreview);o.useEffect(()=>{const ke=()=>{Pt.current=!1,Ht.current=null,cs(!1)};return document.addEventListener("mouseup",ke),()=>document.removeEventListener("mouseup",ke)},[]),o.useEffect(()=>()=>{kt.current!==null&&window.clearTimeout(kt.current),Mt.current!==null&&window.clearTimeout(Mt.current)},[]);const Qs=o.useCallback((ke,Qe)=>{const ot=ke.split(`
42
42
  `),xt=Math.max(1,Qe.start),St=Math.min(ot.length,Qe.end);return xt>St?"":ot.slice(xt-1,St).join(`
43
43
  `)},[]),on=fd({source:"file",fileLabel:Ne?.path??null,language:Ne?.path&&Ci(Ne.path)||"text",getCodeForRange:ke=>Qs(He,qo(ke)),toStoreRange:ke=>({startLine:ke.start,endLine:ke.end}),fromDraftRange:ke=>({start:ke.startLine,end:ke.endLine})}),{drafts:$s,commentText:Ln,editingDraftId:fn,setSelection:mr,saveComment:ar,cancel:kn,reset:Ja,startEdit:ma,deleteDraft:Wi}=on;o.useEffect(()=>{bt(null),Ja(),ds(null),Xe(""),wt(!1)},[Ne?.path,Ja,ds]),o.useEffect(()=>{mr(at)},[at,mr]),o.useEffect(()=>{if(!at&&!fn)return;const ke=ot=>{const xt=ot.target;xt.closest('[data-comment-input="true"]')||xt.closest('[data-comment-card="true"]')||xt.closest(".cm-gutterElement")||xt.closest("[data-sonner-toast]")||xt.closest("[data-sonner-toaster]")||(bt(null),kn())},Qe=setTimeout(()=>{document.addEventListener("click",ke)},100);return()=>{clearTimeout(Qe),document.removeEventListener("click",ke)}},[kn,fn,at]);const Hi=o.useCallback((ke,Qe)=>{const ot=Qe??at??void 0;Qe&&bt(Qe),ar(ke,ot),bt(null)},[at,ar]),Gi=o.useCallback((ke,Qe)=>{const ot=[];for(const xt of Qe){if(!(xt&&typeof xt.name=="string"&&xt.name.length>0)||!p&&xt.name.startsWith(".")||!g&&jj(xt.name))continue;const St=xt.name,zt=Vs(xt.path||""),ps=zt?yj(zt)?zt:Vs(`${ke}/${zt}`):Vs(`${ke}/${St}`),Ds=xt.isDirectory?"directory":"file",gn=Ds==="file"&&St.includes(".")?St.split(".").pop()?.toLowerCase():void 0;ot.push({name:St,path:ps,type:Ds,extension:gn})}return bj(ot)},[g,p]),Cn=o.useCallback(async ke=>{const Qe=Vs(ke.trim());if(!Qe||H.current.has(Qe)||Ee.current.has(Qe))return;Ee.current=new Set(Ee.current),Ee.current.add(Qe);const ot=Je.current+1;Je.current=ot,Ae.current=new Map(Ae.current),Ae.current.set(Qe,ot);const xt=()=>Ae.current.get(Qe)===ot,St=!g;await(r.isDesktop?n.listDirectory(Qe,{respectGitignore:St}).then(ps=>ps.entries.map(Ds=>({name:Ds.name,path:Ds.path,isDirectory:Ds.isDirectory}))):Bs.listLocalDirectory(Qe,{respectGitignore:St}).then(ps=>ps.map(Ds=>({name:Ds.name,path:Ds.path,isDirectory:Ds.isDirectory})))).then(ps=>{if(!xt())return;const Ds=Gi(Qe,ps);H.current=new Set(H.current),H.current.add(Qe),J(gn=>({...gn,[Qe]:Ds}))}).catch(()=>{xt()&&J(ps=>({...ps,[Qe]:ps[Qe]??[]}))}).finally(()=>{xt()&&(Ae.current=new Map(Ae.current),Ae.current.delete(Qe),Ee.current=new Set(Ee.current),Ee.current.delete(Qe))})},[n,Gi,r.isDesktop,g]),Xa=o.useCallback(async()=>{x&&(H.current=new Set,Ee.current=new Set,Ae.current=new Map,J(ke=>Object.keys(ke).length===0?ke:{}),await Cn(x))},[Cn,x]),Xn=o.useCallback(async ke=>{if(!ke){await Xa();return}const Qe=Vs(ke);H.current=new Set(H.current),H.current.delete(Qe),Ee.current=new Set(Ee.current),Ee.current.delete(Qe),await Cn(Qe)},[Cn,Xa]),Za=o.useRef(""),On=o.useRef("");o.useEffect(()=>{if(!x)return;const ke=`${x}|h${p?"1":"0"}|g${g?"1":"0"}`,Qe=Za.current!==x,ot=On.current!==ke;!Qe&&!ot||(Qe&&(Za.current=x,We(""),Ge(null),Ke(""),qe(null),M(!1)),ot&&(On.current=ke,H.current=new Set,Ee.current=new Set,Ae.current=new Map,J(xt=>Object.keys(xt).length===0?xt:{}),Cn(x)))},[Cn,x,g,p]),o.useEffect(()=>{if(!n.listDirectory)return;const ke=()=>{if(!document.hidden&&ae.length>0)for(const Qe of ae)Xn(Qe)};return document.addEventListener("visibilitychange",ke),()=>document.removeEventListener("visibilitychange",ke)},[ae,n.listDirectory,Xn]),o.useEffect(()=>{if(!n.listDirectory||ae.length===0)return;const ke=setInterval(()=>{if(!document.hidden)for(const Qe of ae)Xn(Qe)},8e3);return()=>clearInterval(ke)},[ae,n.listDirectory,Xn]);const pa=o.useCallback(async ke=>{if(ke?.preventDefault(),!ft||!Ls)return;_t(!0);const Qe=()=>{dn(null)},ot=St=>{te.error(St)},xt=()=>{_t(!1)};if(Ls==="createFile"){if(!is.trim()){ot(e("sidebarFilesTree.toast.filenameRequired")),xt();return}if(!n.writeFile){ot(e("sidebarFilesTree.toast.writeNotSupported")),xt();return}const St=ft.path,zt=St?`${St}/`:"",ps=Vs(`${zt}${is.trim()}`);await n.writeFile(ps,"").then(async Ds=>{Ds.success&&(te.success(e("sidebarFilesTree.toast.fileCreated")),await Xn(St)),Qe()}).catch(()=>ot(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(Ls==="createFolder"){if(!is.trim()){ot(e("sidebarFilesTree.toast.folderNameRequired")),xt();return}const St=ft.path,zt=St?`${St}/`:"",ps=Vs(`${zt}${is.trim()}`);await n.createDirectory(ps).then(async Ds=>{Ds.success&&(te.success(e("sidebarFilesTree.toast.folderCreated")),await Xn(St)),Qe()}).catch(()=>ot(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(Ls==="rename"){if(!is.trim()){ot(e("sidebarFilesTree.toast.nameRequired")),xt();return}if(!n.rename){ot(e("sidebarFilesTree.toast.renameNotSupported")),xt();return}const St=ft.path,zt=St.split("/").slice(0,-1).join("/"),ps=zt?`${zt}/`:"",Ds=Vs(`${ps}${is.trim()}`);await n.rename(St,Ds).then(async gn=>{gn.success&&(te.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Xn(zt),x&&ne(x,St),(Ne?.path===St||Ne?.path.startsWith(`${St}/`))&&(x&&se(x,null),We(""),Ge(null),Ke(""),qe(null),d&&M(!1))),Qe()}).catch(()=>ot(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(Ls==="delete"){if(!n.delete){ot(e("sidebarFilesTree.toast.deleteNotSupported")),xt();return}const St=ft.path,zt=St.split("/").slice(0,-1).join("/");await n.delete(St).then(async ps=>{ps.success&&(te.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Xn(zt),x&&ne(x,St),(Ne?.path===St||Ne?.path.startsWith(`${St}/`))&&(x&&se(x,null),We(""),Ge(null),Ke(""),qe(null),d&&M(!1))),Qe()}).catch(()=>ot(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}xt()},[Ls,ft,is,n,Xn,d,ne,x,Ne?.path,se,e]);o.useEffect(()=>{if(!h){_e([]),Me(!1);return}const ke=j.trim();if(!ke){_e([]),Me(!1);return}let Qe=!1;return Me(!0),y(h,ke,150,{includeHidden:p,respectGitignore:!g,type:"file"}).then(ot=>{if(Qe)return;const St=ot.filter(zt=>g||!Nj(zt.path)).map(zt=>({name:zt.name,path:Vs(zt.path),type:"file",extension:zt.extension,relativePath:zt.relativePath}));_e(St)}).catch(()=>{Qe||_e([])}).finally(()=>{Qe||Me(!1)}),()=>{Qe=!0}},[h,j,y,p,g]);const fa=o.useCallback(async(ke,Qe)=>{if(n.readFile)return(await n.readFile(ke,Qe)).content??"";const ot=new URLSearchParams({path:ke});Qe?.allowOutsideWorkspace&&ot.set("allowOutsideWorkspace","true"),Qe?.optional&&ot.set("optional","true");const xt=await fetch(`/api/fs/read?${ot.toString()}`,{cache:Qe?.optional?"no-store":"default"});if(!xt.ok){const St=await xt.json().catch(()=>({error:xt.statusText}));throw new Error(St.error||e("filesView.error.readFileFailed"))}return xt.text()},[n,e]),Rr=o.useCallback(async(ke,Qe)=>{if(n.statFile){const ot=await n.statFile(ke,Qe);return{path:ot.path,size:ot.size,mtimeMs:ot.mtimeMs}}return null},[n]),Nr=o.useMemo(()=>He.length>ai?`${He.slice(0,ai)}
44
44
 
@@ -173,7 +173,7 @@ postgresql://user:pass@host/db`,rows:Math.max(4,t.length+1),className:"font-mono
173
173
  ${JSON.stringify(e,null,2)}`},V5=t=>`GitHub pull request context (JSON)
174
174
  ${JSON.stringify(t,null,2)}`;function U5({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=ct(),{github:a,git:i}=wn(),l=De(ce=>ce.isMobile),u=zn(ce=>ce.status),d=zn(ce=>ce.hasChecked),f=es(ce=>ce.getActiveProject()),m=f?.path??null,c=Le.useMemo(()=>m&&f?{id:f.id,path:m}:null,[f,m]),[p,g]=Le.useState("new-branch"),[h,x]=Le.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[w,b]=Le.useState({selectedBranch:"",worktreeName:""}),y=yf(m),v=vf(m),S=yn(ce=>ce.fetchBranches),I=Le.useMemo(()=>y?.all?y.all.filter(ce=>!ce.startsWith("remotes/")).sort():[],[y]),j=Le.useMemo(()=>y?.all?y.all.filter(ce=>ce.startsWith("remotes/")).map(ce=>ce.replace(/^remotes\//,"")).sort():[],[y]),N=Ft(ce=>ce.availableWorktreesByProject),P=Le.useMemo(()=>{if(!m)return new Set;const ce=N.get(m)??[];return new Set(ce.map(_e=>_e.name))},[N,m]),M=Le.useCallback((ce=10)=>{for(let _e=0;_e<ce;_e++){const et=_l();if(!P.has(et))return et}return`${_l()}-${Date.now().toString(36).slice(-4)}`},[P]),[T,E]=Le.useState(!1),[k,C]=Le.useState(!1),[A,F]=Le.useState(!1),[_,O]=Le.useState(!1),[V,K]=Le.useState(!1),[$,oe]=Le.useState(""),[L,Y]=Le.useState(""),ee=Le.useRef(null),re=Le.useRef(null),fe=Le.useRef(null),ge=Le.useRef(null),be=Le.useCallback(ce=>{ce.stopPropagation()},[]),z=Le.useCallback(ce=>{let _e=ce;for(;_e&&_e!==document.body;){const{overflowY:et}=window.getComputedStyle(_e);if((et==="auto"||et==="scroll")&&_e.scrollHeight>_e.clientHeight)return _e;_e=_e.parentElement}return null},[]),B=Le.useCallback(ce=>{ce&&(ce.scrollTop=0)},[]),Q=Le.useCallback(ce=>{const _e=ce.current?.querySelector('[data-slot="command-list"]')??null;B(_e)},[B]),X=Le.useCallback(ce=>{const _e=z(ce.current);B(_e)},[z,B]),ie=Le.useMemo(()=>sp({localBranches:I,remoteBranches:j,query:$}),[I,j,$]),le=Le.useMemo(()=>sp({localBranches:I,remoteBranches:j,query:L}),[I,j,L]),ye=$.trim().length>0,W=L.trim().length>0,ue=ie.matching.length>0,ae=le.matching.length>0,U=!!(m&&i),G=Le.useCallback(()=>{!m||!i||S(m,i)},[m,i,S]);Le.useEffect(()=>{!k&&!_&&oe("")},[k,_]),Le.useEffect(()=>{!A&&!V&&Y("")},[A,V]),Le.useEffect(()=>{k&&Q(ee),_&&X(fe)},[k,_,$,Q,X]),Le.useEffect(()=>{A&&Q(re),V&&X(ge)},[A,V,L,Q,X]);const[ne,se]=Le.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[xe,Se]=Le.useState(!1),[je,Ie]=Le.useState(null),Oe=Le.useCallback(()=>{const ce=ht.getState(),_e=ce.getVisibleAgents();if(ce.settingsDefaultAgent){const et=_e.find(Me=>Me.name===ce.settingsDefaultAgent);if(et)return et.name}return _e.find(et=>et.name==="build")?.name||_e[0]?.name},[]),Ne=Le.useCallback(()=>{const ce=ht.getState(),_e=ce.settingsDefaultModel;if(!_e)return null;const et=Ka(_e);if(!et)return null;const{providerId:Me,modelId:He}=et;return ce.getModelMetadata(Me,He)?{providerID:Me,modelID:He}:null},[]),he=Le.useCallback((ce,_e)=>{const et=ht.getState(),Me=et.settingsDefaultVariant;if(!Me)return;const Te=et.providers.find(Ve=>Ve.id===ce)?.models.find(Ve=>Ve.id===_e)?.variants;if(Te&&Object.prototype.hasOwnProperty.call(Te,Me))return Me},[]),Fe=Le.useCallback(ce=>{const _e=ht.getState();try{Zi.getState().saveSessionModelSelection(ce.sessionId,ce.providerID,ce.modelID)}catch{}if(ce.agentName){try{_e.setAgent(ce.agentName)}catch{}try{Zi.getState().saveSessionAgentSelection(ce.sessionId,ce.agentName)}catch{}try{Zi.getState().saveAgentModelForSession(ce.sessionId,ce.agentName,ce.providerID,ce.modelID)}catch{}if(ce.variant!==void 0){try{_e.setCurrentVariant(ce.variant)}catch{}try{Zi.getState().saveAgentModelVariantForSession(ce.sessionId,ce.agentName,ce.providerID,ce.modelID,ce.variant)}catch{}}}},[]),Be=Le.useCallback(async ce=>{if(!m||!a)return;const _e=ht.getState(),et=ed.getState().lastUsedProvider,Me=Ne(),He=Me?.providerID||_e.currentProviderId||et?.providerID,We=Me?.modelID||_e.currentModelId||et?.modelID,Te=Oe()||_e.currentAgentName||void 0;if(!He||!We){te.error(r("session.newWorktree.error.noModelSelected"));return}const Ve=he(He,We);if(Fe({sessionId:ce.sessionId,providerID:He,modelID:We,agentName:Te,variant:Ve}),ce.issue){if(!a.issueGet||!a.issueComments)return;const Ye=await a.issueGet(m,ce.issue.number);if(Ye.connected===!1||!Ye.repo||!Ye.issue)throw new Error("Failed to load issue context");const Ge=await a.issueComments(m,ce.issue.number);if(Ge.connected===!1)throw new Error("Failed to load issue comments");const me=await Ur("github.issue.review.visible",{issue_number:String(ce.issue.number)}),Ke=await Ur("github.issue.review.instructions"),ze=B5({repo:Ye.repo,issue:Ye.issue,comments:Ge.comments??[]});await Bs.sendMessage({id:ce.sessionId,providerID:He,modelID:We,agent:Te,variant:Ve,text:me,additionalParts:[{text:Ke,synthetic:!0},{text:ze,synthetic:!0}]}),te.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(ce.pr){if(!a.prContext)return;const Ye=await a.prContext(m,ce.pr.number,{includeDiff:ce.includeDiff,includeCheckDetails:!1});if(Ye.connected===!1||!Ye.repo||!Ye.pr)throw new Error("Failed to load PR context");const Ge=await Ur("github.pr.review.visible",{pr_number:String(ce.pr.number)}),me=await Ur("github.pr.review.instructions"),Ke=V5(Ye);await Bs.sendMessage({id:ce.sessionId,providerID:He,modelID:We,agent:Te,variant:Ve,text:Ge,additionalParts:[{text:me,synthetic:!0},{text:Ke,synthetic:!0}]}),te.success(r("session.newWorktree.toast.sessionFromPr"))}},[Fe,a,m,Oe,Ne,he,r]),q=p==="new-branch"?h:w;Le.useEffect(()=>{if(!y?.all||!m||h.sourceBranch)return;(async()=>{try{const _e=await fl(m).catch(()=>null),et=localStorage.getItem(np),Me=et&&y.all?.includes(et)?et:_e&&y.all?.includes(_e)?_e:y.all?.includes("main")?"main":y.all?.includes("master")?"master":y.all?.[0]||"";Me&&x(He=>({...He,sourceBranch:Me}))}catch{}})()},[y,m,h.sourceBranch]),Le.useEffect(()=>{if(!t)return;g("new-branch"),b({selectedBranch:"",worktreeName:""}),C(!1),F(!1),O(!1),K(!1),oe(""),Y(""),se({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const ce=M();x({branchName:ce,worktreeName:ce,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,M]),Le.useEffect(()=>{if(p!=="new-branch"||!h.isSyncingWorktreeName)return;const ce=fi(h.branchName),_e=ln(ce);x(et=>({...et,worktreeName:_e}))},[p,h.branchName,h.isSyncingWorktreeName]);const Pe=Le.useCallback(async()=>{if(!c||!ne.touched||xe)return;je&&je.abort();const ce=new AbortController;Ie(ce),se(_e=>({..._e,isValidating:!0}));try{const _e=p==="new-branch"?h.branchName:w.selectedBranch,et=q.worktreeName,Me=fi(_e),He=ln(et);let We=null,Te=null;if(Me||(We=r("session.newWorktree.error.branchNameRequired")),He||(Te=r("session.newWorktree.error.worktreeDirectoryRequired")),Me&&He){const Ve=p==="new-branch"?h.linkedPr:null,Ye=Ve?rp(Ve,I,j):null,Ge=await bf(c,{mode:p==="existing-branch"||Ye?"existing":"new",branchName:Me,worktreeName:He,existingBranch:Ye?.existingBranch??(p==="existing-branch"?Me:void 0),...Ye?.ensureRemoteName?{ensureRemoteName:Ye.ensureRemoteName}:{},...Ye?.ensureRemoteUrl?{ensureRemoteUrl:Ye.ensureRemoteUrl}:{}});if(ce.signal.aborted)return;Ge.ok||Ge.errors.forEach(me=>{if(me.code==="worktree_exists"){Te=Te??me.message;return}me.code.startsWith("branch_")&&(We=We??me.message)})}ce.signal.aborted||se(Ve=>({...Ve,isValidating:!1,branchError:We,worktreeError:Te}))}catch{ce.signal.aborted||se(_e=>({..._e,isValidating:!1}))}},[c,p,h.branchName,h.linkedPr,w.selectedBranch,q.worktreeName,I,j,ne.touched,je,xe,r]),$e=p==="new-branch"?h.branchName:w.selectedBranch;Le.useEffect(()=>{if(!t||!c||!ne.touched||xe)return;const ce=setTimeout(()=>{Pe()},300);return()=>clearTimeout(ce)},[q.worktreeName,$e,t,c,Pe,ne.touched,xe]);const Ce=async()=>{if(!c||!m){te.error(r("session.newWorktree.error.noActiveProject"));return}se(He=>({...He,touched:!0}));const ce=p==="new-branch"?h.branchName:w.selectedBranch,_e=q.worktreeName,et=fi(ce),Me=ln(_e);if(!et){te.error(r("session.newWorktree.error.branchNameRequired"));return}if(!Me){te.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}je&&(je.abort(),Ie(null)),se(He=>({...He,isValidating:!1,branchError:null,worktreeError:null})),Se(!0);try{const He=await id(c),We=p==="new-branch"?h.linkedPr:null,Te=h.sourceBranch;let Ve="";const Ye=(()=>{if(We){const qe=rp(We,I,j);return Ve=qe.sourceLabel,{preferredName:et||Me,mode:"existing",branchName:et,worktreeName:Me,existingBranch:qe.existingBranch,setupCommands:He,setUpstream:qe.setUpstream,upstreamRemote:qe.upstreamRemote,upstreamBranch:qe.upstreamBranch,...qe.ensureRemoteName?{ensureRemoteName:qe.ensureRemoteName}:{},...qe.ensureRemoteUrl?{ensureRemoteUrl:qe.ensureRemoteUrl}:{}}}return Ve=p==="new-branch"?Te:"",{preferredName:et||Me,mode:p==="existing-branch"?"existing":"new",branchName:p==="existing-branch"?void 0:et,worktreeName:Me,existingBranch:p==="existing-branch"?et:void 0,setupCommands:He,...Te&&p==="new-branch"?{startRef:Te}:{}}})(),Ge=await ob(m,Ye),me=await lb(c,Ge),Ke=p==="new-branch"?h.linkedIssue:null,ze=p==="new-branch"?h.linkedPr:null,tt=p==="new-branch"?h.includePrDiff:!1;let it=null;if(Ke||ze){const qe=Ke?`#${Ke.number} ${Ke.title}`.trim():ze?`#${ze.number} ${ze.title}`.trim():r("session.newWorktree.newSessionTitle"),Ze=await cb(qe,me.path,null);if(!Ze?.id)throw new Error("Failed to create session");it=Ze.id,db(Ze.id,qe).catch(()=>{});try{Ft.getState().initializeNewSession(Ze.id,ht.getState().agents)}catch{}}h.sourceBranch&&p==="new-branch"&&!h.linkedPr&&localStorage.setItem(np,h.sourceBranch),te.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${me.branch||me.name}${Ve?` ${r("session.newWorktree.fromSource",{source:Ve})}`:""}`})}),e(!1),it?(n?.(me.path,{sessionId:it}),Be({sessionId:it,issue:Ke,pr:ze,includeDiff:tt}).catch(qe=>{const Ze=qe instanceof Error?qe.message:r("session.newWorktree.error.sendGitHubContextFailed");te.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:Ze})})):n?.(me.path)}catch(He){const We=He instanceof Error?He.message:r("session.newWorktree.error.createWorktreeFailed");te.error(r("session.newWorktree.error.createWorktreeFailed"),{description:We})}finally{Se(!1)}},pe=ce=>{g(ce),se(_e=>({..._e,touched:!1,branchError:null,worktreeError:null}))},R=ce=>{if(!ce){x(_e=>({..._e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(ce.type==="issue"){const _e=ce.item,et=`issue-${_e.number}-${_l()}`;x(Me=>({...Me,linkedIssue:_e,linkedPr:null,includePrDiff:!1,branchName:et,worktreeName:ln(et),isSyncingWorktreeName:!0}))}else if(ce.type==="pr"){const _e=ce.item;x(et=>({...et,linkedPr:_e,linkedIssue:null,includePrDiff:ce.includeDiff??!1,branchName:_e.head,worktreeName:ln(_e.head),isSyncingWorktreeName:!0}))}},J=d&&u?.connected===!0,Ee=(p==="existing-branch"?!!w.selectedBranch&&!!w.worktreeName&&!ne.branchError&&!ne.worktreeError:!!fi(h.branchName)&&!!h.worktreeName&&!ne.branchError&&!ne.worktreeError)&&!xe,Ae=()=>{x(ce=>({...ce,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Je=s.jsxs("div",{className:de("flex gap-2",l?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:de("flex items-center gap-1.5 text-destructive",l?"w-full justify-center order-first":"mr-auto"),children:ne.touched&&(ne.branchError||ne.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:ne.branchError||ne.worktreeError})]})}),s.jsxs("div",{className:de("flex gap-2",l&&"w-full"),children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:xe,className:de(l&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(ve,{size:"sm",onClick:Ce,disabled:!Ee||xe,className:de("gap-1.5",l&&"flex-1"),children:[xe&&s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(xe?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[l?s.jsxs(hr,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:Je,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(ur,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(D,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:p,onSelect:ce=>pe(ce),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[p==="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:w.selectedBranch?"text-foreground":"text-muted-foreground",children:w.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:G,disabled:!U||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"refresh",className:"size-4"})})]}),s.jsx(hr,{open:_,title:r("session.newWorktree.selectBranch"),onClose:()=>O(!1),children:s.jsxs("div",{className:"space-y-4",ref:fe,children:[s.jsx(jt,{value:$,onChange:ce=>oe(ce.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),v?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):I.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:[ye&&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:ie.matching.map(ce=>s.jsx("button",{onClick:()=>{b(_e=>({..._e,selectedBranch:ce.value,worktreeName:ln(ce.label)})),se(_e=>({..._e,touched:!0})),O(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",w.selectedBranch===ce.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ce.label})},`${ce.source}-${ce.value}`))})]}),ye&&!ue&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ie.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(ye?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:ie.otherLocal.map(ce=>s.jsx("button",{onClick:()=>{b(_e=>({..._e,selectedBranch:ce,worktreeName:ln(ce)})),se(_e=>({..._e,touched:!0})),O(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",w.selectedBranch===ce?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ce})},ce))})]}),ie.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(ye?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:ie.otherRemote.map(ce=>s.jsx("button",{onClick:()=>{b(_e=>({..._e,selectedBranch:`remotes/${ce}`,worktreeName:ln(ce)})),se(_e=>({..._e,touched:!0})),O(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",w.selectedBranch===`remotes/${ce}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ce})},`remotes/${ce}`))})]})]})]})})]}):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")}),p==="new-branch"&&J&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>E(!0),className:"gap-1.5 h-7",children:[s.jsx(D,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(jt,{value:h.branchName,onChange:ce=>{x(_e=>({..._e,branchName:ce.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>se(ce=>({...ce,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:de("h-8",ne.touched&&ne.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),p!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const ce=ln(p==="new-branch"?h.branchName:"");x(_e=>({..._e,worktreeName:ce,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===ln(h.branchName),className:de("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===ln(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(D,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(jt,{value:q.worktreeName,onChange:ce=>{p==="new-branch"?x(_e=>({..._e,worktreeName:ce.target.value,isSyncingWorktreeName:!1})):b(_e=>({..._e,worktreeName:ce.target.value}))},onBlur:()=>se(ce=>({...ce,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:de("h-8",ne.touched&&ne.worktreeError&&"border-destructive")})]}),p==="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:()=>K(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:h.sourceBranch?"text-foreground":"text-muted-foreground",children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})}),s.jsx(hr,{open:V,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>K(!1),children:s.jsxs("div",{className:"space-y-4",ref:ge,children:[s.jsx(jt,{value:L,onChange:ce=>Y(ce.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),v?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):I.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:[W&&ae&&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:le.matching.map(ce=>s.jsx("button",{onClick:()=>{x(_e=>({..._e,sourceBranch:ce.value})),K(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===ce.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ce.label})},`${ce.source}-${ce.value}`))})]}),W&&!ae&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),le.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(W?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:le.otherLocal.map(ce=>s.jsx("button",{onClick:()=>{x(_e=>({..._e,sourceBranch:ce})),K(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===ce?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ce})},ce))})]}),le.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(W?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:le.otherRemote.map(ce=>s.jsx("button",{onClick:()=>{x(_e=>({..._e,sourceBranch:`remotes/${ce}`})),K(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===`remotes/${ce}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ce})},`remotes/${ce}`))})]})]})]})})]}),(h.linkedIssue||h.linkedPr)&&p==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:ce=>ce.stopPropagation(),children:s.jsx(D,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Ae,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):s.jsx(ls,{open:t,onOpenChange:e,children:s.jsxs(os,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(bs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(hs,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(D,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(ur,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(D,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:p,onSelect:ce=>pe(ce),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[p==="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(ys,{open:k,onOpenChange:C,children:[s.jsx(vs,{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:de("truncate",w.selectedBranch?"text-foreground":"text-muted-foreground"),children:w.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(ws,{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:ee,children:s.jsxs(Jo,{shouldFilter:!1,children:[s.jsx(Oi,{placeholder:r("session.newWorktree.searchBranches"),value:$,onValueChange:oe,onKeyDown:be}),s.jsx(Xo,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):I.length===0&&j.length===0?s.jsx(Zo,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ye&&ue&&s.jsx(qn,{heading:r("session.newWorktree.matchingBranches"),children:ie.matching.map(ce=>s.jsx(Dn,{value:ce.value,onSelect:()=>{b(_e=>({..._e,selectedBranch:ce.value,worktreeName:ln(ce.label)})),se(_e=>({..._e,touched:!0})),C(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ce.label})},`${ce.source}-${ce.value}`))}),ye&&!ue&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ie.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[ye&&s.jsx(Aa,{}),s.jsx(qn,{heading:r(ye?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ie.otherLocal.map(ce=>s.jsx(Dn,{value:ce,onSelect:()=>{b(_e=>({..._e,selectedBranch:ce,worktreeName:ln(ce)})),se(_e=>({..._e,touched:!0})),C(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ce})},`local-${ce}`))})]}),ie.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(ie.otherLocal.length>0||ye)&&s.jsx(Aa,{}),s.jsx(qn,{heading:r(ye?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ie.otherRemote.map(ce=>s.jsx(Dn,{value:`remotes/${ce}`,onSelect:()=>{b(_e=>({..._e,selectedBranch:`remotes/${ce}`,worktreeName:ln(ce)})),se(_e=>({..._e,touched:!0})),C(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ce})},`remote-${ce}`))})]})]})})]})})]}),s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:G,disabled:!U||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"refresh",className:"size-4"})})]})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),p==="new-branch"&&J&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>E(!0),className:"gap-1.5 h-7",children:[s.jsx(D,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(jt,{value:h.branchName,onChange:ce=>{x(_e=>({..._e,branchName:ce.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>se(ce=>({...ce,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:de("h-8",ne.touched&&ne.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),p!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const ce=ln(p==="new-branch"?h.branchName:"");x(_e=>({..._e,worktreeName:ce,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===ln(h.branchName),className:de("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===ln(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(D,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(jt,{value:q.worktreeName,onChange:ce=>{p==="new-branch"?x(_e=>({..._e,worktreeName:ce.target.value,isSyncingWorktreeName:!1})):b(_e=>({..._e,worktreeName:ce.target.value}))},onBlur:()=>se(ce=>({...ce,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:de("h-8",ne.touched&&ne.worktreeError&&"border-destructive")})]}),p==="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(ys,{open:A,onOpenChange:F,children:[s.jsx(vs,{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:de("truncate",h.sourceBranch?"text-foreground":"text-muted-foreground"),children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(ws,{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:re,children:s.jsxs(Jo,{shouldFilter:!1,children:[s.jsx(Oi,{placeholder:r("session.newWorktree.searchBranches"),value:L,onValueChange:Y,onKeyDown:be}),s.jsx(Xo,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):I.length===0&&j.length===0?s.jsx(Zo,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[W&&ae&&s.jsx(qn,{heading:r("session.newWorktree.matchingBranches"),children:le.matching.map(ce=>s.jsx(Dn,{value:ce.value,onSelect:()=>{x(_e=>({..._e,sourceBranch:ce.value})),F(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ce.label})},`${ce.source}-${ce.value}`))}),W&&!ae&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),le.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[W&&s.jsx(Aa,{}),s.jsx(qn,{heading:r(W?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:le.otherLocal.map(ce=>s.jsx(Dn,{value:ce,onSelect:()=>{x(_e=>({..._e,sourceBranch:ce})),F(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ce})},`local-${ce}`))})]}),le.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(le.otherLocal.length>0||W)&&s.jsx(Aa,{}),s.jsx(qn,{heading:r(W?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:le.otherRemote.map(ce=>s.jsx(Dn,{value:`remotes/${ce}`,onSelect:()=>{x(_e=>({..._e,sourceBranch:`remotes/${ce}`})),F(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ce})},`remote-${ce}`))})]})]})})]})})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})})]}),(h.linkedIssue||h.linkedPr)&&p==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:ce=>ce.stopPropagation(),children:s.jsx(D,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Ae,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]}),s.jsxs(Is,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:ne.touched&&(ne.branchError||ne.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:ne.branchError||ne.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:xe,children:r("session.newWorktree.actions.cancel")}),s.jsxs(ve,{size:"sm",onClick:Ce,disabled:!Ee||xe,className:"gap-1.5",children:[xe&&s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(xe?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(_5,{open:T,onOpenChange:E,onSelect:R})]})}let La=null,Oa=null,Ro=null,el=0;const la=new Set,K5=3e4,W5=45e3,Mh=()=>{Ro&&(clearTimeout(Ro),Ro=null)},Rh=()=>{if(Oa||la.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(el,5)),K5);Oa=setTimeout(()=>{Oa=null,el+=1,Fh()},t)},tl=()=>{Mh(),La&&La.close(),La=null},ap=()=>{Mh(),la.size!==0&&(Ro=setTimeout(()=>{tl(),Rh()},W5))},H5=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}},G5=t=>{if(t.type==="vinci:event-stream-ready"){el=0;return}if(t.type==="vinci:heartbeat"||t.type!=="vinci:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",a=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,l=i==="running"||i==="error"?i:"success";if(!n||!r)return;const u={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:a,status:l,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of la)d(u)},Fh=()=>{if(typeof window>"u"||la.size===0||typeof EventSource!="function"||La&&La.readyState!==EventSource.CLOSED)return;tl();const t=new EventSource("/api/vinci/events");t.onopen=()=>{ap()},t.onmessage=e=>{ap();const n=H5(e.data);n&&G5(n)},t.onerror=()=>{tl(),Rh()},La=t},Lh=t=>(la.add(t),Fh(),()=>{la.delete(t),la.size===0&&(Oa&&(clearTimeout(Oa),Oa=null),el=0,tl())}),yl=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},Ga=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},q5=async t=>{const e=Ga(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await yl(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},ip=async(t,e)=>{const n=Ga(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 yl(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},Y5=async(t,e)=>{const n=Ga(t),r=Ga(e),a=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!a.ok)throw new Error(await yl(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},Q5=async(t,e)=>{const n=Ga(t),r=Ga(e),a=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!a.ok)throw new Error(await yl(a,"Failed to run scheduled task"));const i=await a.json().catch(()=>null);return{sessionId:typeof i?.sessionId=="string"&&i.sessionId.length>0?i.sessionId:void 0}},Oh=[0,1,2,3,4,5,6],op=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}`},Fo=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),a=Number(e[3]),i=new Date(n,r-1,a);return Number.isNaN(i.getTime())||i.getFullYear()!==n||i.getMonth()!==r-1||i.getDate()!==a?null:i},cp=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},J5=(t,e,n)=>{const r=Fo(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},dp=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),X5=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),l=(new Date(n,r,1).getDay()-e+7)%7,u=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),f=[];for(let m=0;m<42;m+=1){const c=m-l+1;if(c<=0){const p=d+c;f.push({date:new Date(n,r-1,p),inCurrentMonth:!1});continue}if(c>u){f.push({date:new Date(n,r+1,c-u),inCurrentMonth:!1});continue}f.push({date:new Date(n,r,c),inCurrentMonth:!0})}return f},Z5=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],a=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:a}},Xr=(t,e,n)=>{const r=Number(t),a=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,l=Number.isFinite(a)?Math.min(59,Math.max(0,a)):0;let u=i%12;return n==="PM"&&(u+=12),`${String(u).padStart(2,"0")}:${String(l).padStart(2,"0")}`},Qa=(t,e)=>{const{max:n,min:r=0,loop:a=!1}=e;let i=Number.parseInt(t,10);return Number.isFinite(i)?(a?(i>n&&(i=r),i<r&&(i=n)):(i>n&&(i=n),i<r&&(i=r)),String(i).padStart(2,"0")):"00"},up=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:Qa(t,{min:1,max:12}),uo=t=>/^[0-5][0-9]$/.test(t)?t:Qa(t,{max:59}),eC=(t,e)=>Qa(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),mp=(t,e)=>Qa(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),tC=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}},sC=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}},nC=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Oh.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},rC=(t,e)=>[...t.slice(e),...t.slice(0,e)],er=t=>{const e=st.c(6),{htmlFor:n,required:r,children:a}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let l;return e[2]!==a||e[3]!==n||e[4]!==i?(l=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,i]})}),e[2]=a,e[3]=n,e[4]=i,e[5]=l):l=e[5],l},pp=t=>{const e=st.c(84),{value:n,onChange:r,use24Hour:a,hourAriaLabel:i,minuteAriaLabel:l,periodAriaLabel:u,amLabel:d,pmLabel:f}=t;let m;e[0]!==n?(m=Z5(n),e[0]=n,e[1]=m):m=e[1];const c=m,p=Le.useRef(null),g=Le.useRef(null),[h,x]=Le.useState(null),[w,b]=Le.useState(null),y=Le.useRef(null),v=Le.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=se=>{y.current=se,x(se)},e[2]=S):S=e[2];const I=S;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=se=>{v.current=se,b(se)},e[3]=j):j=e[3];const N=j,P=dC,M=uC,T=mC;let E;e[4]!==r||e[5]!==c.meridiem||e[6]!==c.minute||e[7]!==a?(E=se=>{const xe=se.replace(/\D/g,"").slice(0,2);I(xe),xe.length===2&&(r(a?T(P(xe),c.minute):Xr(up(xe),c.minute,c.meridiem)),I(null),g.current?.focus())},e[4]=r,e[5]=c.meridiem,e[6]=c.minute,e[7]=a,e[8]=E):E=e[8];const k=E;let C;e[9]!==r||e[10]!==c.meridiem||e[11]!==c.minute||e[12]!==a?(C=()=>{const se=y.current;if(se!==null&&(I(null),se.length!==0)){if(a){r(T(P(se.padStart(2,"0")),c.minute));return}r(Xr(up(se.padStart(2,"0")),c.minute,c.meridiem))}},e[9]=r,e[10]=c.meridiem,e[11]=c.minute,e[12]=a,e[13]=C):C=e[13];const A=C;let F;e[14]!==r||e[15]!==c.hour12||e[16]!==c.hour24||e[17]!==c.meridiem||e[18]!==a?(F=se=>{const xe=se.replace(/\D/g,"").slice(0,2);N(xe),xe.length===2&&(r(a?T(c.hour24,uo(xe)):Xr(c.hour12,uo(xe),c.meridiem)),N(null))},e[14]=r,e[15]=c.hour12,e[16]=c.hour24,e[17]=c.meridiem,e[18]=a,e[19]=F):F=e[19];const _=F;let O;e[20]!==r||e[21]!==c.hour12||e[22]!==c.hour24||e[23]!==c.meridiem||e[24]!==a?(O=()=>{const se=v.current;se!==null&&(N(null),se.length!==0&&r(a?T(c.hour24,uo(se.padStart(2,"0"))):Xr(c.hour12,uo(se.padStart(2,"0")),c.meridiem)))},e[20]=r,e[21]=c.hour12,e[22]=c.hour24,e[23]=c.meridiem,e[24]=a,e[25]=O):O=e[25];const V=O;let K;e[26]!==r||e[27]!==c.hour12||e[28]!==c.hour24||e[29]!==c.meridiem||e[30]!==c.minute||e[31]!==a?(K=se=>r(a?T(M(c.hour24,se),c.minute):Xr(eC(c.hour12,se),c.minute,c.meridiem)),e[26]=r,e[27]=c.hour12,e[28]=c.hour24,e[29]=c.meridiem,e[30]=c.minute,e[31]=a,e[32]=K):K=e[32];const $=K;let oe;e[33]!==r||e[34]!==c.hour12||e[35]!==c.hour24||e[36]!==c.meridiem||e[37]!==c.minute||e[38]!==a?(oe=se=>r(a?T(c.hour24,mp(c.minute,se)):Xr(c.hour12,mp(c.minute,se),c.meridiem)),e[33]=r,e[34]=c.hour12,e[35]=c.hour24,e[36]=c.meridiem,e[37]=c.minute,e[38]=a,e[39]=oe):oe=e[39];const L=oe;let Y;e[40]!==r||e[41]!==c.hour12||e[42]!==c.meridiem||e[43]!==c.minute?(Y=se=>{se!==c.meridiem&&r(Xr(c.hour12,c.minute,se))},e[40]=r,e[41]=c.hour12,e[42]=c.meridiem,e[43]=c.minute,e[44]=Y):Y=e[44];const ee=Y;let re;e[45]!==A||e[46]!==$?(re=se=>{if(se.key==="ArrowRight"){se.preventDefault(),A(),g.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),I(null),$(se.key==="ArrowUp"?1:-1))},e[45]=A,e[46]=$,e[47]=re):re=e[47];const fe=re;let ge;e[48]!==V||e[49]!==L?(ge=se=>{if(se.key==="ArrowLeft"&&(se.currentTarget.selectionStart??0)===0){se.preventDefault(),V(),p.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),N(null),L(se.key==="ArrowUp"?1:-1))},e[48]=V,e[49]=L,e[50]=ge):ge=e[50];const be=ge,z=a?"px-2":"pl-2 pr-1";let B;e[51]!==z?(B=de("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",z),e[51]=z,e[52]=B):B=e[52];const Q=h??(a?c.hour24:c.hour12);let X;e[53]!==k?(X=se=>k(se.target.value),e[53]=k,e[54]=X):X=e[54];let ie;e[55]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>I(""),e[55]=ie):ie=e[55];let le;e[56]!==A||e[57]!==i||e[58]!==fe||e[59]!==Q||e[60]!==X?(le=s.jsx("input",{ref:p,inputMode:"numeric",value:Q,onChange:X,onKeyDown:fe,onFocus:ie,onBlur:A,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=A,e[57]=i,e[58]=fe,e[59]=Q,e[60]=X,e[61]=le):le=e[61];let ye;e[62]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=ye):ye=e[62];const W=w??c.minute;let ue;e[63]!==_?(ue=se=>_(se.target.value),e[63]=_,e[64]=ue):ue=e[64];let ae;e[65]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>N(""),e[65]=ae):ae=e[65];let U;e[66]!==V||e[67]!==l||e[68]!==be||e[69]!==W||e[70]!==ue?(U=s.jsx("input",{ref:g,inputMode:"numeric",value:W,onChange:ue,onKeyDown:be,onFocus:ae,onBlur:V,maxLength:2,"aria-label":l,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=V,e[67]=l,e[68]=be,e[69]=W,e[70]=ue,e[71]=U):U=e[71];let G;e[72]!==d||e[73]!==c.meridiem||e[74]!==u||e[75]!==f||e[76]!==ee||e[77]!==a?(G=a?null:s.jsxs(Qt,{value:c.meridiem,onValueChange:se=>ee(se),children:[s.jsx(Jt,{"aria-label":u,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(as,{})}),s.jsxs(Xt,{children:[s.jsx(Ct,{value:"AM",children:d}),s.jsx(Ct,{value:"PM",children:f})]})]}),e[72]=d,e[73]=c.meridiem,e[74]=u,e[75]=f,e[76]=ee,e[77]=a,e[78]=G):G=e[78];let ne;return e[79]!==B||e[80]!==le||e[81]!==U||e[82]!==G?(ne=s.jsxs("div",{className:B,children:[le,ye,U,G]}),e[79]=B,e[80]=le,e[81]=U,e[82]=G,e[83]=ne):ne=e[83],ne},fp=t=>new Date(t.getFullYear(),t.getMonth(),1),aC=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},hp=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),iC=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(a=>typeof a=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(a)).map(a=>a.trim()),r=Array.from(new Set(n)).sort((a,i)=>a.localeCompare(i));return r.length>0?r:["09:00"]},gp=(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:iC(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}}},oC=(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")},lC=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 cC(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:l}=ct(),u=ht(q=>q.loadProviders),d=ht(q=>q.loadAgents),f=ht(q=>q.providers),m=ht(q=>q.currentProviderId),c=ht(q=>q.currentModelId),p=ht(q=>q.currentVariant||""),g=ht(q=>q.currentAgentName||""),h=De(q=>q.timeFormatPreference),x=De(q=>q.weekStartPreference),w=De(q=>q.isMobile),[b,y]=Le.useState(()=>gp(n,{providerID:m,modelID:c,variant:p,agent:g})),[v,S]=Le.useState(!1),[I,j]=Le.useState(!1),[N,P]=Le.useState(!1),[M,T]=Le.useState(""),[E,k]=Le.useState(!1),[C,A]=Le.useState(""),[F,_]=Le.useState(()=>{const q=Fo(n?.schedule?.date||"")||new Date;return new Date(q.getFullYear(),q.getMonth(),1)}),O=Le.useRef(null),V=Le.useRef(null),K=Le.useRef(null),$=Le.useRef(null),oe=Le.useMemo(()=>sC(l),[l]),L=Le.useMemo(()=>tC(l),[l]),Y=Le.useMemo(()=>h==="24h"?!0:h==="12h"?!1:oe,[h,oe]),ee=Le.useMemo(()=>x==="sunday"?0:x==="monday"?1:L,[x,L]),re=Le.useMemo(()=>{const q=nC(l);return rC(Oh.map(Pe=>({value:Pe,label:q[Pe]||""})),ee)},[l,ee]);Le.useEffect(()=>{e&&(u(),d())},[e,u,d]),Le.useEffect(()=>{if(!e)return;y(gp(n,{providerID:m,modelID:c,variant:p,agent:g}));const q=Fo(n?.schedule?.date||"")||new Date;_(new Date(q.getFullYear(),q.getMonth(),1)),j(!1),k(!1),P(!1),A(""),T("")},[e,n,m,c,p,g]),Le.useEffect(()=>{if(!I)return;const q=Pe=>{O.current&&!O.current.contains(Pe.target)&&j(!1)};return document.addEventListener("mousedown",q),()=>{document.removeEventListener("mousedown",q)}},[I]);const fe=Le.useMemo(()=>{const Pe=f.find($e=>$e.id===b.execution.providerID)?.models?.find($e=>$e.id===b.execution.modelID);return Pe?.variants?Object.keys(Pe.variants):[]},[f,b.execution.providerID,b.execution.modelID]),ge=fe.length>0,be=Le.useMemo(()=>!ge||!b.execution.variant?"__default":fe.includes(b.execution.variant)?b.execution.variant:"__default",[b.execution.variant,ge,fe]);Le.useEffect(()=>{ge||!b.execution.variant||y(q=>({...q,execution:{...q.execution,variant:""}}))},[ge,b.execution.variant]);const z=Le.useCallback((q,Pe)=>{y($e=>{const Ce=new Set($e.schedule.weekdays);return Pe?Ce.add(q):Ce.delete(q),{...$e,schedule:{...$e.schedule,weekdays:Array.from(Ce).sort((pe,R)=>pe-R)}}})},[]),B=Le.useCallback((q,Pe)=>{y($e=>{const Ce=$e.schedule.times.slice();return Ce[q]=Pe,{...$e,schedule:{...$e.schedule,times:Ce}}})},[]),Q=Le.useCallback(q=>{y(Pe=>{const $e=Pe.schedule.times.filter((Ce,pe)=>pe!==q);return{...Pe,schedule:{...Pe.schedule,times:$e.length>0?$e:["09:00"]}}})},[]),X=Le.useCallback(()=>{y(q=>({...q,schedule:{...q.schedule,times:[...q.schedule.times,"12:00"]}}))},[]),ie=Le.useMemo(()=>aC(),[]),le=Le.useMemo(()=>fp(ie),[ie]),ye=Le.useMemo(()=>{const q=Fo(b.schedule.onceDate);return q?hp(q,ie)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(l,{weekday:"short"}).format(q):null},[b.schedule.onceDate,l,i,ie]),W=Le.useMemo(()=>fp(F).getTime()<=le.getTime(),[F,le]),ue=Le.useMemo(()=>re.map(q=>q.label),[re]),ae=Le.useCallback(q=>{y(Pe=>({...Pe,schedule:{...Pe.schedule,onceDate:q}}))},[]),U=Le.useCallback((q,Pe)=>{if(q.startsWith("/")){const pe=q.indexOf(" "),R=q.indexOf(`
175
175
  `),J=Math.min(pe===-1?q.length:pe,R===-1?q.length:R);if(Pe<=J&&pe===-1){A(q.substring(1,J)),k(!0),P(!1);return}}k(!1);const $e=q.substring(0,Pe),Ce=$e.lastIndexOf("@");if(Ce!==-1){const pe=Ce>0?$e[Ce-1]:null,R=$e.substring(Ce+1);(!pe||/\s/.test(pe))&&!R.includes(" ")&&!R.includes(`
176
- `)?(T(R),P(!0)):P(!1);return}P(!1)},[]),G=Le.useCallback(q=>{y(Pe=>({...Pe,execution:{...Pe.execution,prompt:q}}))},[]),ne=Le.useCallback(q=>{const Pe=b.execution.prompt,Ce=V.current?.selectionStart??Pe.length,R=Pe.substring(0,Ce).lastIndexOf("@"),J=q.relativePath&&q.relativePath.trim().length>0?q.relativePath.trim():q.path||q.name,H=R!==-1?R:Ce,Ee=`${Pe.substring(0,H)}@${J} ${Pe.substring(Ce)}`,Ae=H+J.length+2;G(Ee),P(!1),T(""),requestAnimationFrame(()=>{const Je=V.current;Je&&(Je.selectionStart=Ae,Je.selectionEnd=Ae,Je.focus()),U(Ee,Ae)})},[b.execution.prompt,G,U]),se=Le.useCallback(q=>{const Pe=b.execution.prompt,Ce=V.current?.selectionStart??Pe.length,R=Pe.substring(0,Ce).lastIndexOf("@"),J=R!==-1?R:Ce,H=`${Pe.substring(0,J)}@${q} ${Pe.substring(Ce)}`,Ee=J+q.length+2;G(H),P(!1),T(""),requestAnimationFrame(()=>{const Ae=V.current;Ae&&(Ae.selectionStart=Ee,Ae.selectionEnd=Ee,Ae.focus()),U(H,Ee)})},[b.execution.prompt,G,U]),xe=Le.useCallback(q=>{const Pe=`/${q.name} `;G(Pe),k(!1),A(""),requestAnimationFrame(()=>{const $e=V.current;$e&&($e.focus(),$e.selectionStart=$e.value.length,$e.selectionEnd=$e.value.length),U(Pe,Pe.length)})},[G,U]),Se=Le.useCallback(q=>{if(E&&$.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")){q.preventDefault(),$.current.handleKeyDown(q.key);return}N&&K.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")&&(q.preventDefault(),K.current.handleKeyDown(q.key))},[E,N]),je=Le.useCallback(async()=>{const q=oC(b,i);if(q){te.error(q);return}const Pe=lC(b.schedule.times),$e={...b.id?{id:b.id}:{},name:b.name.trim(),enabled:b.enabled,schedule:{kind:b.schedule.kind,timezone:b.schedule.timezone.trim(),...b.schedule.kind==="once"?{date:b.schedule.onceDate,time:b.schedule.onceTime}:{times:Pe,...b.schedule.kind==="weekly"?{weekdays:b.schedule.weekdays}:{}}},execution:{prompt:b.execution.prompt,providerID:b.execution.providerID,modelID:b.execution.modelID,...b.execution.variant.trim()?{variant:b.execution.variant.trim()}:{},...b.execution.agent.trim()?{agent:b.execution.agent.trim()}:{}},...b.state?{state:b.state}:{}};S(!0);try{await a($e),r(!1)}catch(Ce){te.error(Ce instanceof Error?Ce.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[b,r,a,i]),Ie=Le.useId(),Oe=Le.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),Ne=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),he=i("sessions.scheduledTasks.editor.description"),Fe=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(er,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(jt,{id:"sched-name",value:b.name,onChange:q=>y(Pe=>({...Pe,name:q.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Qt,{value:b.schedule.kind,onValueChange:q=>{y(Pe=>({...Pe,schedule:{...Pe.schedule,kind:q}}))},children:[s.jsx(Jt,{className:"w-fit max-w-full",children:s.jsx(as,{children:q=>i(q==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":q==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(Xt,{children:[s.jsx(Ct,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Ct,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Ct,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),b.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(er,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(q=>!q),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(D,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:J5(b.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),l)})]}),s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),I?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:()=>_(q=>dp(q,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:W,children:s.jsx(D,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(l,{month:"long",year:"numeric"}).format(F)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>_(q=>dp(q,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:ue.map((q,Pe)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:q},`${q}-${Pe}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:X5(F,ee).map(({date:q,inCurrentMonth:Pe})=>{const $e=cp(q),Ce=$e===b.schedule.onceDate,pe=hp(q,ie),R=q.getTime()<ie.getTime(),J=Ce?"bg-interactive-selection text-interactive-selection-foreground":R?"text-muted-foreground/40":Pe?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{R||(ae($e),j(!1))},disabled:R,className:["h-8 rounded-md typography-ui-label",J,pe&&!Ce?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",R?"cursor-not-allowed opacity-45":""].join(" "),children:q.getDate()},$e)})}),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:ye||""}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:()=>{ae(cp(ie)),_(new Date(ie.getFullYear(),ie.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(pp,{value:b.schedule.onceTime,use24Hour:Y,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:q=>y(Pe=>({...Pe,schedule:{...Pe.schedule,onceTime:q}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Qt,{value:b.schedule.timezone,onValueChange:q=>{y(Pe=>({...Pe,schedule:{...Pe.schedule,timezone:q}}))},children:[s.jsx(Jt,{className:"w-fit max-w-full",children:s.jsx(as,{})}),s.jsx(Xt,{children:op.map(q=>s.jsx(Ct,{value:q,children:q},q))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[b.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:re.map(q=>{const Pe=b.schedule.weekdays.includes(q.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",Pe?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(ss,{checked:Pe,onChange:$e=>z(q.value,$e),ariaLabel:q.label}),s.jsx("button",{type:"button",onClick:()=>z(q.value,!Pe),className:"group-hover:text-foreground",children:q.label})]},q.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:b.schedule.times.map((q,Pe)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(pp,{value:q,use24Hour:Y,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:$e=>B(Pe,$e)}),b.schedule.times.length>1?s.jsx(ve,{type:"button",size:"icon",variant:"ghost",onClick:()=>Q(Pe),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(D,{name:"close",className:"h-4 w-4"})}):null]},Pe))}),s.jsx("div",{children:s.jsxs(ve,{type:"button",size:"sm",variant:"outline",onClick:X,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Qt,{value:b.schedule.timezone,onValueChange:q=>{y(Pe=>({...Pe,schedule:{...Pe.schedule,timezone:q}}))},children:[s.jsx(Jt,{className:"w-fit max-w-full",children:s.jsx(as,{})}),s.jsx(Xt,{children:op.map(q=>s.jsx(Ct,{value:q,children:q},q))})]})]})]}),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(er,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Ui,{providerId:b.execution.providerID,modelId:b.execution.modelID,onChange:(q,Pe)=>{y($e=>({...$e,execution:{...$e.execution,providerID:q,modelID:Pe,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Qt,{value:be,disabled:!ge,onValueChange:q=>{y(Pe=>({...Pe,execution:{...Pe.execution,variant:q==="__default"?"":q}}))},children:[s.jsx(Jt,{className:"w-fit max-w-full",children:s.jsx(as,{children:q=>q==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):q})}),s.jsxs(Xt,{children:[s.jsx(Ct,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),fe.map(q=>s.jsx(Ct,{value:q,children:q},q))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(gl,{agentName:b.execution.agent,filter:q=>tf(q.mode),onChange:q=>y(Pe=>({...Pe,execution:{...Pe.execution,agent:q}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(nn,{id:"sched-prompt",ref:V,value:b.execution.prompt,onChange:q=>{const Pe=q.target.value;G(Pe);const $e=q.target.selectionStart??Pe.length;U(Pe,$e)},onKeyDown:Se,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),E?s.jsx(wf,{ref:$,searchQuery:C,onCommandSelect:xe,onClose:()=>k(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,N?s.jsx(jf,{ref:K,searchQuery:M,onFileSelect:ne,onAgentSelect:se,onClose:()=>P(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),Be=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(ss,{checked:b.enabled,onChange:q=>y(Pe=>({...Pe,enabled:q})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:v,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(ve,{type:"button",size:"sm",onClick:je,disabled:v,children:i(v?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return w?s.jsx(hr,{open:e,title:Ne,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:q=>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:Ne}),q]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:he})]}),footer:Be,children:Fe}):s.jsx(ls,{open:e,onOpenChange:q=>{!q&&Oe()||r(q)},children:s.jsxs(os,{"aria-describedby":Ie,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ss,{id:Ie,className:"sr-only",children:he}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(hs,{className:"typography-ui-label font-medium text-foreground",children:Ne}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:he})]})}),s.jsx(Nf,{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:Fe})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:Be})})]})})}function dC(t){return Qa(t,{min:0,max:23})}function uC(t,e){return Qa(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function mC(t,e){const n=Number(t),r=Number(e),a=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,i=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(a).padStart(2,"0")}:${String(i).padStart(2,"0")}`}const pC=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,a)=>r.localeCompare(a))},fC=(t,e)=>{const n=pC(t).join(", ")||"--:--",r=a=>e(a===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":a===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":a===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":a===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":a===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":a===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":a===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const a=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(i=>r(i)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:a,time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:a,time:n})}if(t.schedule.kind==="once"){const a=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),i=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:a,time:i,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.once",{date:a,time:i})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},hC=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),xp=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),a=6e4,i=60*a,l=24*i,u=n>=0;if(r<a)return e(u?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const c=Math.round(r/a);return u?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:c}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:c})}if(r<l){const c=Math.floor(r/i),p=Math.round(r%i/a),g=p>0?`${c}h ${p}m`:`${c}h`;return u?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:g}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:g})}const d=Math.floor(r/l),f=Math.round(r%l/i),m=f>0?`${d}d ${f}h`:`${d}d`;return u?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},gC={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"}},xC=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function bC(){const{t}=ct(),e=De(A=>A.isScheduledTasksDialogOpen),n=De(A=>A.setScheduledTasksDialogOpen),r=De(A=>A.isMobile),a=es(A=>A.projects),i=es(A=>A.getActiveProject()),l=Ns(A=>A.homeDirectory),{currentTheme:u}=rr(),[d,f]=Le.useState(""),[m,c]=Le.useState([]),[p,g]=Le.useState(!0),[h,x]=Le.useState(!1),[w,b]=Le.useState(null),[y,v]=Le.useState(null),S=Le.useMemo(()=>a.find(A=>A.id===d)||null,[a,d]),I=Le.useCallback(A=>{const F=A.label?.trim()||ca(A.path,l||void 0),_=Bi({id:A.id,iconImage:A.iconImage??null},{themeVariant:u.metadata.variant,iconColor:u.colors.surface.foreground}),O=A.icon?pl[A.icon]:null,V=A.color?Vi[A.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[_?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:A.iconBackground?{backgroundColor:A.iconBackground}:void 0,children:s.jsx("img",{src:_,alt:"",className:"h-full w-full object-contain",draggable:!1})}):O?s.jsx(D,{name:O,className:"h-3.5 w-3.5 shrink-0",style:V?{color:V}:void 0}):s.jsx(D,{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:F})]})},[l,u.metadata.variant,u.colors.surface.foreground]),j=Le.useCallback(async(A,F)=>{if(!A){c([]);return}F?.silent||g(!0);try{const _=await q5(A);_.sort((O,V)=>{if(O.enabled!==V.enabled)return O.enabled?-1:1;const K=O.name.localeCompare(V.name);return K!==0?K:(O.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),c(_)}catch(_){te.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),F?.silent||c([])}finally{F?.silent||g(!1)}},[t]);Le.useEffect(()=>{if(!e)return;const A=i?.id||a[0]?.id||"";f(A),A?j(A):(c([]),g(!1))},[e,i,a,j]),Le.useEffect(()=>{if(!e)return;let A=null;const F=Lh(_=>{_.type==="scheduled-task-ran"&&_.projectId===d&&(A&&clearTimeout(A),A=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{A&&clearTimeout(A),F()}},[e,d,j]);const N=Le.useCallback(async A=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await ip(d,A),await j(d),te.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),P=Le.useCallback(async(A,F)=>{if(d){v(A.id),c(_=>_.map(O=>O.id===A.id?{...O,enabled:F}:O));try{await ip(d,{...A,enabled:F}),await j(d,{silent:!0})}catch(_){te.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{v(null)}}},[d,j,t]),M=Le.useCallback(async A=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:A.name})))){v(A.id);try{await Y5(d,A.id),await j(d,{silent:!0}),te.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(_){te.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{v(null)}}},[d,j,t]),T=Le.useCallback(async A=>{if(d){v(A.id);try{await Q5(d,A.id),await Promise.all([j(d,{silent:!0}),jc()]),te.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(F){te.error(F instanceof Error?F.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{v(null)}}},[d,j,t]),E=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(Qt,{value:d||"__none",onValueChange:A=>{const F=A==="__none"?"":A;f(F),F?j(F):c([])},children:[s.jsx(Jt,{className:r?"w-full":void 0,children:S?s.jsx(as,{children:I(S)}):s.jsx(as,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(Xt,{children:[a.length===0?s.jsx(Ct,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(A=>s.jsx(Ct,{value:A.id,children:I(A)},A.id))]})]})]}),k=()=>{b(null),x(!0)},C=s.jsxs("div",{className:"space-y-4",children:[r?E:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[E,s.jsxs(ve,{onClick:k,disabled:!d,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:p?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(A=>{const F=y===A.id,_=A.state?.lastStatus||"idle",O=gC[_],V=t(_==="success"?"sessions.scheduledTasks.dialog.status.success":_==="error"?"sessions.scheduledTasks.dialog.status.error":_==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),K=A.state?.nextRunAt,$=A.state?.lastRunAt;return s.jsxs("div",{className:de("rounded-lg border border-border p-4 transition-opacity",!A.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:A.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:fC(A,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(D,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),K?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:xp(K,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:hC(K)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(D,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),_==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):$?s.jsxs(s.Fragment,{children:[O.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${O.tone})`},children:[s.jsx(D,{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:xp($,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),A.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:xC("error"),children:[s.jsx(D,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:A.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:de("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",A.enabled?"text-foreground":"text-muted-foreground",F&&"cursor-not-allowed opacity-50"),children:[s.jsx(ss,{checked:A.enabled,onChange:oe=>{P(A,oe)},ariaLabel:A.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:A.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:A.name}),disabled:F}),A.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:()=>{T(A)},disabled:F,children:[s.jsx(D,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{b(A),x(!0)},disabled:F,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:A.name}),children:[s.jsx(D,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:()=>{M(A)},disabled:F,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:A.name}),children:s.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},A.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(hr,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:A=>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")}),A]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(ve,{className:"w-full",onClick:k,disabled:!d,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:C}):s.jsx(ls,{open:e,onOpenChange:n,children:s.jsxs(os,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(bs,{children:[s.jsx(hs,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Ss,{children:t("sessions.scheduledTasks.dialog.description")})]}),C]})}),s.jsx(cC,{open:h,task:w,onOpenChange:x,onSave:N})]})}const yC=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(u=>Zt(u.path)??u.path).filter(u=>!!u)]),i=(u=>u.filter(d=>Ai(d,t.normalizedPath,r)))(e.archivedSessions),l=e.sessions.filter(u=>u.time?.archived||Zt(u.directory??null)?!1:Ai(u,t.normalizedPath,r));return Wa([...i,...l])},vC=t=>{const e=st.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:l,isSessionsLoading:u,foldersMap:d,createFolder:f,addSessionToFolder:m,cleanupSessions:c}=t;let p,g;e[0]!==m||e[1]!==a||e[2]!==i||e[3]!==c||e[4]!==f||e[5]!==d||e[6]!==u||e[7]!==l||e[8]!==n||e[9]!==r?(p=()=>{u||n.forEach(h=>{const x=od(h.normalizedPath),w=yC(h,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:l}),b=new Set(w.map(wC)),y=d[x]??[],v=new Map(y.map(jC));w.forEach(S=>{const I=ub(S,h.normalizedPath),j=I.toLowerCase();let N=v.get(j);N||(N=f(x,I),v.set(j,N)),N.sessionIds.includes(S.id)||m(x,N.id,S.id)}),c(x,b)})},g=[n,r,a,i,l,u,d,f,m,c],e[0]=m,e[1]=a,e[2]=i,e[3]=c,e[4]=f,e[5]=d,e[6]=u,e[7]=l,e[8]=n,e[9]=r,e[10]=p,e[11]=g):(p=e[10],g=e[11]),o.useEffect(p,g)};function wC(t){return t.id}function jC(t){return[t.name.toLowerCase(),t]}const NC=t=>{const e=st.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:l,projectRootBranches:u,lastRepoStatus:d,buildGroupedSessions:f,hasSessionSearchQuery:m,normalizedSessionSearchQuery:c,filterSessionNodesForSearch:p,buildGroupSearchText:g,foldersMap:h}=t;let x;if(e[0]!==i||e[1]!==f||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==l||e[7]!==u){let T;e[9]!==i||e[10]!==f||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==l||e[15]!==u?(T=E=>{const k=Wa([...r(E),...a(E)]),C=i.get(E.normalizedPath)??[],A=l.has(E.id)?!!l.get(E.id):d,F=f(k,E.normalizedPath,C,u.get(E.id)??null,A);return{project:E,groups:F}},e[9]=i,e[10]=f,e[11]=a,e[12]=r,e[13]=d,e[14]=l,e[15]=u,e[16]=T):T=e[16],x=n.map(T),e[0]=i,e[1]=f,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=l,e[7]=u,e[8]=x}else x=e[8];const w=x,b=w;let y;if(e[17]!==g||e[18]!==p||e[19]!==h||e[20]!==m||e[21]!==c||e[22]!==b){e:{const T=new WeakMap;if(!m){y=T;break e}const E=k=>k.reduce((C,A)=>C+1+E(A.children),0);b.forEach(k=>{k.groups.forEach(C=>{const A=p(C.sessions,c),F=E(A),_=g(C).includes(c),O=Zt(C.directory??null),K=(O?h[O]??[]:[]).filter($=>$.name.toLowerCase().includes(c)).length;T.set(C,{filteredNodes:A,matchedSessionCount:F,folderNameMatchCount:K,groupMatches:_,hasMatch:_||F>0||K>0})})}),y=T}e[17]=g,e[18]=p,e[19]=h,e[20]=m,e[21]=c,e[22]=b,e[23]=y}else y=e[23];const v=y;let S;e:{if(!m){S=b;break e}let T;if(e[24]!==v||e[25]!==b){let E;e[27]!==v?(E=k=>({...k,groups:k.groups.filter(C=>v.get(C)?.hasMatch===!0)}),e[27]=v,e[28]=E):E=e[28],T=b.map(E).filter(SC),e[24]=v,e[25]=b,e[26]=T}else T=e[26];S=T}const I=S,j=m?I:b;let N;e:{if(!m){N=0;break e}let T;if(e[29]!==v||e[30]!==j){let E;e[32]!==v?(E=(k,C)=>k+C.groups.reduce((A,F)=>{const _=v.get(F);if(!_)return A;const O=_.folderNameMatchCount+(_.groupMatches?1:0);return A+_.matchedSessionCount+O},0),e[32]=v,e[33]=E):E=e[33],T=j.reduce(E,0),e[29]=v,e[30]=j,e[31]=T}else T=e[31];N=T}const P=N;let M;return e[34]!==v||e[35]!==w||e[36]!==P||e[37]!==I||e[38]!==j||e[39]!==b?(M={projectSections:w,visibleProjectSections:b,groupSearchDataByGroup:v,searchableProjectSections:I,sectionsForRender:j,searchMatchCount:P},e[34]=v,e[35]=w,e[36]=P,e[37]=I,e[38]=j,e[39]=b,e[40]=M):M=e[40],M};function SC(t){return t.groups.length>0}const kC=t=>{const e=st.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:l,handleSessionSelect:u,newSessionDraftOpen:d,mobileVariant:f,openNewSessionDraft:m,setActiveMainTab:c,setSessionSwitcherOpen:p,sessions:g,worktreeMetadata:h}=t;let x,w;if(e[0]!==n){w=new Map,x=new Map;const E=(k,C,A,F)=>{w.has(k)||w.set(k,new Map);const _=w.get(k);F.forEach(O=>{const V=Zt(O.worktree?.path??O.session.directory??A??C);_.set(O.session.id,{directory:V}),x.has(k)||x.set(k,{id:O.session.id,directory:V}),O.children.length>0&&E(k,C,V,O.children)})};n.forEach(k=>{k.groups.forEach(C=>{E(k.project.id,k.project.normalizedPath,C.directory,C.sessions)})}),e[0]=n,e[1]=x,e[2]=w}else x=e[1],w=e[2];let b;e[3]!==x||e[4]!==w?(b={metaByProject:w,firstSessionByProject:x},e[3]=x,e[4]=w,e[5]=b):b=e[5];const y=b,v=o.useRef(null);let S,I;e[6]!==r||e[7]!==a||e[8]!==l||e[9]!==u||e[10]!==f||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==y||e[15]!==c||e[16]!==i||e[17]!==p?(S=()=>{if(!r||d||v.current===r)return;const E=n.find(V=>V.project.id===r);if(!E)return;v.current=r;const k=y.metaByProject.get(r);if(l&&k&&k.has(l)){i(V=>{if(V.get(r)===l)return V;const K=new Map(V);return K.set(r,l),K});return}if(!k||k.size===0){c("chat"),f&&p(!1),m({directoryOverride:E.project.normalizedPath});return}const C=a.get(r),A=C&&k.has(C)?C:null,F=y.firstSessionByProject.get(r)?.id??null,_=A??F;if(!_||_===l)return;const O=k.get(_)?.directory??null;u(_,O,!1,r)},I=[r,a,l,u,d,f,m,n,y,c,p,i],e[6]=r,e[7]=a,e[8]=l,e[9]=u,e[10]=f,e[11]=d,e[12]=m,e[13]=n,e[14]=y,e[15]=c,e[16]=i,e[17]=p,e[18]=S,e[19]=I):(S=e[18],I=e[19]),o.useLayoutEffect(S,I);let j,N;e[20]!==r||e[21]!==l||e[22]!==y||e[23]!==i?(j=()=>{if(!r||!l)return;const E=y.metaByProject.get(r);!E||!E.has(l)||i(k=>{if(k.get(r)===l)return k;const C=new Map(k);return C.set(r,l),C})},N=[r,l,y,i],e[20]=r,e[21]=l,e[22]=y,e[23]=i,e[24]=j,e[25]=N):(j=e[24],N=e[25]),o.useEffect(j,N);let P;if(e[26]!==l||e[27]!==g||e[28]!==h){e:{if(!l){P=null;break e}const E=h.get(l)?.path;if(E){P=Zt(E)??E;break e}let k;e[30]!==l?(k=A=>A.id===l,e[30]=l,e[31]=k):k=e[31];const C=g.find(k);if(!C){P=null;break e}P=Zt(C.directory??null)}e[26]=l,e[27]=g,e[28]=h,e[29]=P}else P=e[29];const M=P;let T;return e[32]!==M?(T={currentSessionDirectory:M},e[32]=M,e[33]=T):T=e[33],T},CC=t=>{const e=st.c(4);let n;e[0]!==t?(n=(i,l)=>{const u=t.get(i);if(!u||u.length===0)return l;const d=new Map(l.map(PC)),f=[];return u.forEach(m=>{const c=d.get(m);c&&(f.push(c),d.delete(m))}),l.forEach(m=>{d.has(m.id)&&f.push(m)}),f},e[0]=t,e[1]=n):n=e[1];const r=n;let a;return e[2]!==r?(a={getOrderedGroups:r},e[2]=r,e[3]=a):a=e[3],a};function PC(t){return[t.id,t]}const mo=t=>!!t.time?.archived,IC=t=>{const{t:e}=ct(),n=o.useCallback(l=>[l.label,l.branch??"",l.description??"",l.directory??""].join(" ").toLowerCase(),[]),r=o.useCallback(l=>{const u=Zt(l.directory??null)??"";return`${(l.title||e("sessions.sidebar.session.untitled")).trim()} ${u}`.toLowerCase()},[e]),a=o.useCallback((l,u)=>u?l.flatMap(d=>{if(r(d.session).includes(u))return[d];const m=a(d.children,u);return m.length===0?[]:[{...d,children:m}]}):l,[r]),i=o.useCallback((l,u,d,f,m)=>{const c=Zt(u??null),p=Wa(l).sort((E,k)=>Fa(E,k,t.pinnedSessionIds)),g=new Map(p.map(E=>[E.id,E])),h=new Map;p.forEach(E=>{const k=E.parentID;if(!k)return;const C=g.get(k);if(!C||mo(C)!==mo(E))return;const A=h.get(k)??[];A.push(E),h.set(k,A)}),h.forEach(E=>E.sort((k,C)=>Fa(k,C,t.pinnedSessionIds)));const x=new Map;d.forEach(E=>{if(E.path){const k=Zt(E.path)??E.path;x.set(k,E)}});const w=E=>{const k=Zt(E.directory??null),C=t.worktreeMetadata.get(E.id)??null;if(C)return C;if(k){const A=x.get(k)??null;if(A&&k!==c)return A}return null},b=E=>{const k=h.get(E.id)??[];return{session:E,children:k.map(C=>b(C)),worktree:w(E)}},y=p.filter(E=>{const k=E.parentID;if(!k)return!0;const C=g.get(k);return C?mo(C)!==mo(E):!0}),v=new Map,S="__archived__",I=E=>{if(E.time?.archived)return S;const k=Zt(t.worktreeMetadata.get(E.id)?.path??null),C=Zt(E.directory??null);if(!k&&!C)return S;const A=Zt(E.project?.worktree??null),F=k??C??A;return F?F!==c&&x.has(F)?F:F===c?c??"__project_root__":S:S};y.forEach(E=>{const k=b(E),C=I(E);v.has(C)||v.set(C,[]),v.get(C)?.push(k)});const j=c??"__project_root__",N=[{id:"root",label:m&&f&&f!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:f}):e("sessions.sidebar.grouping.projectRoot"),branch:f??null,description:c?Ti(c,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:c,folderScopeKey:c,sessions:v.get(j)??[]}],P=new Map;d.forEach(E=>{const k=Zt(E.path)??E.path,C=v.get(k)??[],A=C.length>0,F=C.reduce((_,O)=>{const V=Number(O.session.time?.updated??O.session.time?.created??0);return Number.isFinite(V)?Math.max(_,V):_},0);P.set(k,{hasActiveSession:A,lastUpdatedAt:F})}),[...d].sort((E,k)=>{const C=Zt(E.path)??E.path,A=Zt(k.path)??k.path,F=P.get(C)??{hasActiveSession:!1,lastUpdatedAt:0},_=P.get(A)??{hasActiveSession:!1,lastUpdatedAt:0};if(F.hasActiveSession!==_.hasActiveSession)return F.hasActiveSession?-1:1;if(F.hasActiveSession&&_.hasActiveSession)return _.lastUpdatedAt-F.lastUpdatedAt;const O=(E.label||E.branch||E.name||E.path||"").toLowerCase(),V=(k.label||k.branch||k.name||k.path||"").toLowerCase();return O.localeCompare(V)}).forEach(E=>{const k=Zt(E.path)??E.path,C=t.gitBranches.get(k)?.trim()||null,A=E.branch?.trim()||null,_=!!(C&&A&&E.label&&iu(E.label)===iu(A))?C:E.label||E.name||ca(k,t.homeDirectory)||k;N.push({id:`worktree:${k}`,label:_,branch:C||A,description:Ti(k,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:E,directory:k,folderScopeKey:k,sessions:v.get(k)??[]})});const T=v.get(S)??[];return T.length>0&&N.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&&c?od(c):null,sessions:T}),N},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:a,buildGroupedSessions:i}},DC=t=>{const e=st.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:a,sessionSearchContainerRef:i}=t;let l,u;e[0]!==n||e[1]!==a?(l=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{a.current?.focus(),a.current?.select()});return()=>window.cancelAnimationFrame(m)},u=[n,a],e[0]=n,e[1]=a,e[2]=l,e[3]=u):(l=e[2],u=e[3]),o.useEffect(l,u);let d,f;e[4]!==n||e[5]!==i||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=c=>{i.current&&(i.current.contains(c.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},f=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=d,e[8]=f):(d=e[7],f=e[8]),o.useEffect(d,f)},TC=t=>{const e=st.c(42),{t:n}=ct(),[r,a]=o.useState(null),i=o.useRef(null);let l,u;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>()=>{i.current&&clearTimeout(i.current)},u=[],e[0]=l,e[1]=u):(l=e[0],u=e[1]),o.useEffect(l,u);let d;e[2]!==t?(d=(_,O,V,K)=>{if(V)return;const $=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(K&&K!==t.activeProjectId&&t.setActiveProjectIdOnly(K),O&&O!==t.currentDirectory&&t.setDirectory(O,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),_===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(_),$();return}t.setCurrentSession(_,O??null),t.onSessionSelected?.(_),$()},e[2]=t,e[3]=d):d=e[3];const f=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const c=m;let p;e[6]!==t?(p=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=p):p=e[7];const g=p;let h;e[8]!==t?(h=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=h):h=e[9];const x=h;let w;e[10]!==t||e[11]!==n?(w=async _=>{const O=await t.shareSession(_.id);O&&O.share?.url?te.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):te.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=w):w=e[12];const b=w;let y;e[13]!==n?(y=(_,O)=>{An(_).then(V=>{if(!V.ok){te.error(n("sessions.sidebar.session.share.copyUrlError"));return}a(O),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{a(null),i.current=null},2e3)}).catch(()=>{te.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=y):y=e[14];const v=y;let S;e[15]!==t||e[16]!==n?(S=async _=>{await t.unshareSession(_)?te.success(n("sessions.sidebar.session.unshare.success")):te.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=S):S=e[17];const I=S;let j;e[18]!==t.childrenMap?(j=_=>{const O=[],V=K=>{(t.childrenMap.get(K)??[]).forEach(oe=>{O.push(oe),V(oe.id)})};return V(_),O},e[18]=t.childrenMap,e[19]=j):j=e[19];const N=j,P=EC;let M;e[20]!==t||e[21]!==N||e[22]!==n?(M=async(_,O,V)=>{const K=O?.archivedBucket===!0,$=V?.descendantIds??P(N(_.id),K).map(MC);if($.length===0){(K?await t.deleteSession(_.id):await t.archiveSession(_.id))?te.success(n(K?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):te.error(n(K?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const oe=[_.id,...$];if(K){const{deletedIds:ee,failedIds:re}=await t.deleteSessions(oe);ee.length>0&&te.success(ee.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:ee.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:ee.length})),re.length>0&&te.error(re.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:re.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:re.length}));return}const{archivedIds:L,failedIds:Y}=await t.archiveSessions(oe);L.length>0&&te.success(L.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:L.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:L.length})),Y.length>0&&te.error(Y.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Y.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:Y.length}))},e[20]=t,e[21]=N,e[22]=n,e[23]=M):M=e[23];const T=M;let E;e[24]!==t||e[25]!==N||e[26]!==T?(E=(_,O)=>{const V=O?.archivedBucket===!0,K=P(N(_.id),V).map(RC);if(!t.showDeletionDialog){T(_,O,{descendantIds:K});return}t.setDeleteSessionConfirm({session:_,descendantCount:K.length,descendantIds:K,archivedBucket:V})},e[24]=t,e[25]=N,e[26]=T,e[27]=E):E=e[27];const k=E;let C;e[28]!==t||e[29]!==T?(C=async()=>{if(!t.deleteSessionConfirm)return;const{session:_,archivedBucket:O,descendantIds:V}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await T(_,{archivedBucket:O},{descendantIds:V})},e[28]=t,e[29]=T,e[30]=C):C=e[30];const A=C;let F;return e[31]!==A||e[32]!==r||e[33]!==x||e[34]!==v||e[35]!==k||e[36]!==g||e[37]!==c||e[38]!==f||e[39]!==b||e[40]!==I?(F={copiedSessionId:r,handleSessionSelect:f,handleSessionDoubleClick:c,handleSaveEdit:g,handleCancelEdit:x,handleShareSession:b,handleCopyShareUrl:v,handleUnshareSession:I,handleDeleteSession:k,confirmDeleteSession:A},e[31]=A,e[32]=r,e[33]=x,e[34]=v,e[35]=k,e[36]=g,e[37]=c,e[38]=f,e[39]=b,e[40]=I,e[41]=F):F=e[41],F};function AC(t){return!t.time?.archived}function EC(t,e){return e?t:t.filter(AC)}function MC(t){return t.id}function RC(t){return t.id}const FC=["project:active:","project:archived:","recent:active:","recent:archived:"],LC=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:a,sessions:i,setPinnedSessionIds:l,groupOrderByProject:u,activeSessionByProject:d,collapsedGroups:f,setExpandedParents:m,setCollapsedProjects:c}=t,p=o.useRef(null),g=o.useRef(null),h=o.useCallback(()=>{if(e)return;const w=g.current;if(g.current=null,p.current=null,!w)return;const{projects:b}=es.getState(),y=b.map(v=>({...v,sidebarCollapsed:w.has(v.id)}));rs({projects:y}).catch(()=>{})},[e]),x=o.useCallback(w=>{typeof window>"u"||e||(g.current=w,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{h()},700))},[e,h]);return o.useEffect(()=>()=>{typeof window<"u"&&p.current!==null&&window.clearTimeout(p.current),p.current=null,g.current=null},[]),o.useEffect(()=>{try{const w=r.getItem(a.sessionExpanded);if(w){const y=JSON.parse(w);Array.isArray(y)&&m(new Set(y.filter(v=>typeof v=="string")))}else{const y=r.getItem(a.sessionExpandedLegacy);if(y){try{const v=JSON.parse(y);if(Array.isArray(v)){const S=new Set;if(v.forEach(I=>{typeof I!="string"||I.length===0||FC.forEach(j=>S.add(`${j}${I}`))}),S.size>0){m(S);try{r.setItem(a.sessionExpanded,JSON.stringify(Array.from(S)))}catch{}}}}catch{}try{r.removeItem?.(a.sessionExpandedLegacy)}catch{}}}const b=r.getItem(a.projectCollapse);if(b){const y=JSON.parse(b);Array.isArray(y)&&c(new Set(y.filter(v=>typeof v=="string")))}}catch{}},[a.projectCollapse,a.sessionExpanded,a.sessionExpandedLegacy,r,c,m]),o.useEffect(()=>{if(!n)return;const w=new Set(i.map(b=>b.id));l(b=>{let y=!1;const v=new Set;return b.forEach(S=>{w.has(S)?v.add(S):y=!0}),y?v:b})},[n,i,l]),o.useEffect(()=>{try{const w=Object.fromEntries(u.entries());r.setItem(a.groupOrder,JSON.stringify(w))}catch{}},[u,a.groupOrder,r]),o.useEffect(()=>{try{const w=Object.fromEntries(d.entries());r.setItem(a.projectActiveSession,JSON.stringify(w))}catch{}},[d,a.projectActiveSession,r]),o.useEffect(()=>{try{r.setItem(a.groupCollapse,JSON.stringify(Array.from(f)))}catch{}},[f,a.groupCollapse,r]),{scheduleCollapsedProjectsPersist:x}},OC=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length);let i=0;const l=async()=>{for(;;){const u=i;if(i+=1,u>=t.length)return;a[u]=await n(t[u])}};return await Promise.all(Array.from({length:r},()=>l())),a},$C=t=>{const e=st.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:l}=wn(),u=yn(_C);let d,f;e[0]!==u||e[1]!==l||e[2]!==n||e[3]!==a?(d=()=>{if(!l||n.length===0){a(new Map);return}n.forEach(w=>{u(w.normalizedPath,l)})},f=[n,l,u,a],e[0]=u,e[1]=l,e[2]=n,e[3]=a,e[4]=d,e[5]=f):(d=e[4],f=e[5]),o.useEffect(d,f);let m,c;e[6]!==r||e[7]!==n||e[8]!==a?(m=()=>{const w=new Map;n.forEach(b=>{w.set(b.id,r.get(b.normalizedPath)?.isGitRepo??null)}),a(w)},c=[n,r,a],e[6]=r,e[7]=n,e[8]=a,e[9]=m,e[10]=c):(m=e[9],c=e[10]),o.useEffect(m,c);let p;if(e[11]!==r||e[12]!==n){let w;e[14]!==r?(w=b=>{const y=r.get(b.normalizedPath)?.branch??"";return`${b.id}:${y}`},e[14]=r,e[15]=w):w=e[15],p=n.map(w).join("|"),e[11]=r,e[12]=n,e[13]=p}else p=e[13];const g=p;let h;e[16]!==n||e[17]!==i?(h=()=>{let w=!1;return(async()=>{const y=await OC(n,2,BC);w||i(v=>{const S=new Map(v);return y.forEach(I=>{const{id:j,branch:N}=I;N&&S.set(j,N)}),S})})(),()=>{w=!0}},e[16]=n,e[17]=i,e[18]=h):h=e[18];let x;e[19]!==n||e[20]!==g||e[21]!==i?(x=[n,g,i],e[19]=n,e[20]=g,e[21]=i,e[22]=x):x=e[22],o.useEffect(h,x)};function _C(t){return t.ensureStatus}function zC(){return null}async function BC(t){const e=await fl(t.normalizedPath).catch(zC);return{id:t.id,branch:e}}const VC=t=>{const e=st.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let l;e[0]!==r?(l=new Map,r.forEach(g=>{const h=Zt(g.directory??null)??Zt(g.project?.worktree??null);if(!h)return;const x=l.get(h)??[];x.push(g),l.set(h,x)}),e[0]=r,e[1]=l):l=e[1];const u=l;let d;e[2]!==i||e[3]!==n||e[4]!==u?(d=g=>{const h=n?[]:i.get(g.normalizedPath)??[],x=[g.normalizedPath,...h.map(UC).filter(KC)],w=new Set,b=[];return x.forEach(y=>{(u.get(y)??[]).forEach(S=>{w.has(S.id)||(w.add(S.id),b.push(S))})}),b},e[2]=i,e[3]=n,e[4]=u,e[5]=d):d=e[5];const f=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=g=>{if(n){const v=a.filter(I=>{const j=Zt(I.directory??null),N=Zt(I.project?.worktree??null);return j?j===g.normalizedPath:N===g.normalizedPath}),S=r.filter(I=>I.time?.archived||Zt(I.directory??null)?!1:Zt(I.project?.worktree??null)===g.normalizedPath);return Wa([...v,...S])}const h=n?[]:i.get(g.normalizedPath)??[],x=new Set([g.normalizedPath,...h.map(WC).filter(HC)]),b=(v=>v.filter(S=>Ai(S,g.normalizedPath,x)))(a),y=r.filter(v=>{if(v.time?.archived||Zt(v.directory??null))return!1;const I=Zt(v.project?.worktree??null);return I?I===g.normalizedPath||I.startsWith(`${g.normalizedPath}/`):!1});return Wa([...b,...y])},e[6]=a,e[7]=i,e[8]=n,e[9]=r,e[10]=m):m=e[10];const c=m;let p;return e[11]!==c||e[12]!==f?(p={getSessionsForProject:f,getArchivedSessionsForProject:c},e[11]=c,e[12]=f,e[13]=p):p=e[13],p};function UC(t){return Zt(t.path)??t.path}function KC(t){return!!t}function WC(t){return Zt(t.path)??t.path}function HC(t){return!!t}const GC=t=>{const e=st.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:a,normalizedProjects:i,isVSCode:l,availableWorktreesByProject:u,cleanupSessions:d}=t;let f,m;e[0]!==a||e[1]!==u||e[2]!==d||e[3]!==n||e[4]!==l||e[5]!==i||e[6]!==r?(f=()=>{if(n)return;const c=new Map;r.forEach(h=>{const x=Zt(h.directory??null);if(!x)return;const w=c.get(x);if(w){w.add(h.id);return}c.set(x,new Set([h.id]))}),i.forEach(h=>{const x=od(h.normalizedPath),w=l?[]:u.get(h.normalizedPath)??[],b=new Set([h.normalizedPath,...w.map(qC).filter(YC)]),y=Wa([...a,...r.filter(v=>v.time?.archived||Zt(v.directory??null)?!1:Ai(v,h.normalizedPath,b))]).filter(v=>Ai(v,h.normalizedPath,b));c.set(x,new Set(y.map(QC)))});const p=Pn.getState().foldersMap;new Set([...Object.keys(p),...c.keys()]).forEach(h=>{d(h,c.get(h)??new Set)})},m=[a,u,d,n,l,i,r],e[0]=a,e[1]=u,e[2]=d,e[3]=n,e[4]=l,e[5]=i,e[6]=r,e[7]=f,e[8]=m):(f=e[7],m=e[8]),o.useEffect(f,m)};function qC(t){return Zt(t.path)??t.path}function YC(t){return!!t}function QC(t){return t.id}const JC=t=>{const e=st.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[l,u]=o.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(c=>{c.forEach(p=>{const g=p.target.dataset.projectId;g&&u(h=>{const x=new Set(h);return p.isIntersecting?x.delete(g):x.add(g),x})})},{threshold:0});return a.current.forEach(c=>{c&&m.observe(c)}),()=>m.disconnect()},e[1]=n,e[2]=a,e[3]=d):d=e[3];let f;return e[4]!==n||e[5]!==a||e[6]!==r?(f=[n,a,r],e[4]=n,e[5]=a,e[6]=r,e[7]=f):f=e[7],o.useEffect(d,f),l},XC=9e4,ZC=15e3,e4=5*6e4,t4=[2e3,5e3],s4=6e4,n4=2*6e4,r4=5*6e4,a4=720*6e4,i4="vinci.github-pr-status",o4=t=>t==="closed"||t==="merged",l4=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Lo=(t,e,n)=>`${t}::${e}`,po=new Map,fo=new Map,di=new Set,bp=new Map,hi=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),sl=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,vd=t=>{const e=sl(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},$h=(t,e)=>Object.entries(t).filter(([,n])=>vd(n)===e).map(([n])=>n),c4=(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}}},ho=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},d4=(t,e,n)=>{const r=$h(t,e),a=r.map(d=>ho(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=ho(t[n]);if(i&&vd(t[n])===e)return i;const l=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&ho(d)));if(l)return ho(l);const u=a.find(d=>!!d.remoteName);return u||(a[0]??null)},u4=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:sl(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),m4=t=>({...hi(),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}),Ea=vn()($i((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:hi()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??hi();return{entries:{...a.entries,[n]:c4(i,r)}}})},startWatching:n=>{if(t(i=>{const l=i.entries[n]??hi();return{entries:{...i.entries,[n]:{...l,watchers:l.watchers+1}}}}),po.has(n))return;const r=i=>{const l=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const d=e().entries[n];!d||d.watchers<=0||d.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},i),u=fo.get(n)??[];u.push(l),fo.set(n,u)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),t4.forEach(i=>r(i));const a=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const i=e().entries[n];if(!i||i.watchers<=0)return;if(!!!i.status?.pr){const f=Date.now();if(f-i.lastDiscoveryPollAt<e4)return;t(m=>{const c=m.entries[n];return c?{entries:{...m.entries,[n]:{...c,lastDiscoveryPollAt:f}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(o4(i.status?.pr?.state))return;const u=Date.now()-i.lastRefreshAt,d=l4(i.status)?s4:i.status?.checks&&i.status.checks.state!=="pending"?r4:n4;u<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},ZC);po.set(n,a)},stopWatching:n=>{t(l=>{const u=l.entries[n];if(!u)return l;const d=Math.max(0,u.watchers-1);return{entries:{...l.entries,[n]:{...u,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const a=po.get(n);typeof a=="number"&&window.clearInterval(a),po.delete(n);const i=fo.get(n);i&&i.length>0&&i.forEach(l=>{window.clearTimeout(l)}),fo.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],l=vd(i);if(!i||!l)return;const u=$h(a.entries,l),d=u.some(c=>!!a.entries[c]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const f=bp.get(l)??0;if(!r?.force&&Date.now()-f<XC||di.has(l))return;const m=d4(a.entries,l,n);if(m){if(di.add(l),bp.set(l,Date.now()),t(c=>{const p={...c.entries};return u.forEach(g=>{const h=p[g];h&&(p[g]={...h,lastRefreshAt:Date.now(),isLoading:r?.silent?h.isLoading:!0,error:null})}),{entries:p}}),m.githubAuthChecked&&m.githubConnected===!1){t(c=>{const p={...c.entries};return u.forEach(g=>{const h=p[g];h&&(p[g]={...h,status:{connected:!1},error:null,isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:p}}),di.delete(l);return}if(!m.github?.prStatus){t(c=>{const p={...c.entries};return u.forEach(g=>{const h=p[g];h&&(p[g]={...h,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:p}}),di.delete(l);return}try{t(p=>({...p,activeRequestCount:p.activeRequestCount+1,totalRequestCount:p.totalRequestCount+1}));const c=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(p=>{const g={...p.entries};return u.forEach(h=>{const x=g[h];if(!x)return;const w=x.status?.pr,b=c.pr,v=!!(b&&w&&b.number===w.number&&(!b.body||!b.body.trim())&&typeof w.body=="string"&&w.body.trim().length>0)&&b&&w?.body?{...c,pr:{...b,body:w.body}}:c,S=v.resolvedRemoteName??x.resolvedRemoteName??m.remoteName??null,I=sl(x)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};g[h]={...x,status:v,error:null,isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0,resolvedRemoteName:S,identity:{...I,remoteName:S??I.remoteName??null}}}),{entries:g}})}catch(c){const p=c instanceof Error?c.message:String(c);t(g=>{const h={...g.entries};return u.forEach(x=>{const w=h[x];w&&(h[x]={...w,error:p||"Failed to load PR status",isLoading:r?.silent?w.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?w.isInitialStatusResolved:!0})}),{entries:h}})}finally{di.delete(l),t(c=>({...c,activeRequestCount:Math.max(0,c.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const a=Array.from(new Set(n.map(i=>{const l=i.directory.trim(),u=i.branch.trim();return!l||!u?null:Lo(l,u,i.remoteName??null)}).filter(i=>!!i)));await Promise.all(a.map(i=>e().refresh(i,r)))},updateStatus:(n,r)=>{t(a=>{const i=a.entries[n]??hi();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:i4,storage:il(()=>Vr()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=sl(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<a4}).map(([e,n])=>[e,u4(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,m4(i)]))}}})),p4=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",a=e.mergeable===!1||r==="blocked"||r==="dirty";return n||a?"blocked":"open"},f4=t=>{const e=p4(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}},h4=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 cc=new Map,yp=new Map;const g4=t=>{const e=st.c(2);let n;return e[0]!==t?(n=r=>{const a=new Map,i=new Map;for(const l of t){const u=r.entries[l];if(!u)continue;const d=f4(u);if(!d)continue;const f=h4(d);a.set(l,f),i.set(l,d)}if(a.size===cc.size){let l=!0;for(const[u,d]of a)if(cc.get(u)!==d){l=!1;break}if(l)return yp}return cc=a,yp=i,i},e[0]=t,e[1]=n):n=e[1],Ea(n)},x4=t=>{const e=st.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:l,onRename:u,onDelete:d,renderSessionNode:f,groupDirectory:m,projectId:c,mobileVariant:p,alwaysShowActions:g,isRenaming:h,renameDraft:x,onRenameDraftChange:w,onRenameSave:b,onRenameCancel:y,droppableRef:v,isDropTarget:S,onNewSession:I,onNewSubFolder:j,depth:N,hideActions:P,archivedBucket:M}=t,E=g===void 0?p===void 0?!1:p:g,k=h===void 0?!1:h,C=x===void 0?"":x,A=S===void 0?!1:S,F=N===void 0?0:N,_=P===void 0?!1:P,O=M===void 0?!1:M,{t:V}=ct(),[K,$]=o.useState(!1),[oe,L]=o.useState(""),Y=o.useRef(null),ee=k||K,re=k?C:oe;let fe;e[0]!==n.name?(fe=()=>{L(n.name),$(!0)},e[0]=n.name,e[1]=fe):fe=e[1];const ge=fe;let be;e[2]!==re||e[3]!==n.name||e[4]!==k||e[5]!==u||e[6]!==b?(be=()=>{const J=re.trim();J&&J!==n.name&&u(J),k&&b&&b(),$(!1),L("")},e[2]=re,e[3]=n.name,e[4]=k,e[5]=u,e[6]=b,e[7]=be):be=e[7];const z=be;let B;e[8]!==k||e[9]!==y?(B=()=>{k&&y&&y(),$(!1),L("")},e[8]=k,e[9]=y,e[10]=B):B=e[10];const Q=B;let X;e[11]!==k||e[12]!==w?(X=J=>{k&&w?w(J):L(J)},e[11]=k,e[12]=w,e[13]=X):X=e[13];const ie=X;let le,ye;e[14]!==k?(le=()=>{if(!k)return;const J=()=>{const Ae=Y.current;Ae&&(Ae.focus(),Ae.select())},H=requestAnimationFrame(J),Ee=window.setTimeout(J,0);return()=>{cancelAnimationFrame(H),window.clearTimeout(Ee)}},ye=[k],e[14]=k,e[15]=le,e[16]=ye):(le=e[15],ye=e[16]),o.useEffect(le,ye);const W=i?"folder":"folder-open",ae=F>0&&"ml-3";let U;e[17]!==ae?(U=de("oc-folder",ae),e[17]=ae,e[18]=U):U=e[18];const G=A&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ne;e[19]!==G?(ne=de("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",G),e[19]=G,e[20]=ne):ne=e[20];const se=ee?void 0:l,xe=ee?void 0:"button",Se=ee?void 0:0;let je;e[21]!==l||e[22]!==ee?(je=ee?void 0:J=>{(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),l())},e[21]=l,e[22]=ee,e[23]=je):je=e[23];let Ie;e[24]!==n.name||e[25]!==i||e[26]!==V?(Ie=i?V("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):V("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=i,e[26]=V,e[27]=Ie):Ie=e[27];const Oe=O?E?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let Ne;e[28]!==Oe?(Ne=de("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",Oe),e[28]=Oe,e[29]=Ne):Ne=e[29];const he=A?"text-primary":"text-muted-foreground";let Fe;e[30]!==he?(Fe=de("h-3.5 w-3.5 flex-shrink-0",he),e[30]=he,e[31]=Fe):Fe=e[31];let Be;e[32]!==W||e[33]!==Fe?(Be=s.jsx(D,{name:W,className:Fe}),e[32]=W,e[33]=Fe,e[34]=Be):Be=e[34];let q;e[35]!==re||e[36]!==n.name||e[37]!==Q||e[38]!==ie||e[39]!==z||e[40]!==i||e[41]!==A||e[42]!==ee||e[43]!==r||e[44]!==V?(q=ee?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:y4,onMouseDown:v4,onSubmit:J=>{J.preventDefault(),z()},children:[s.jsx("input",{ref:Y,value:re,onChange:J=>ie(J.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:w4,onPointerDown:j4,onMouseDown:N4,onKeyDown:J=>{if(J.key==="Escape"){J.stopPropagation(),Q();return}(J.key===" "||J.key==="Enter")&&J.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:S4,onPointerDown:k4,onMouseDown:C4,children:s.jsx(D,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),Q()},onPointerDown:P4,onMouseDown:I4,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:de("typography-ui-label font-semibold truncate",A?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=re,e[36]=n.name,e[37]=Q,e[38]=ie,e[39]=z,e[40]=i,e[41]=A,e[42]=ee,e[43]=r,e[44]=V,e[45]=q):q=e[45];let Pe;e[46]!==Ne||e[47]!==Be||e[48]!==q?(Pe=s.jsxs("div",{className:Ne,children:[Be,q]}),e[46]=Ne,e[47]=Be,e[48]=q,e[49]=Pe):Pe=e[49];let $e;e[50]!==E||e[51]!==O||e[52]!==F||e[53]!==n.name||e[54]!==ge||e[55]!==_||e[56]!==d||e[57]!==I||e[58]!==j||e[59]!==ee||e[60]!==V?($e=!ee&&(!_||O)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:de("flex items-center gap-0.5 transition-opacity",E?"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&&I?s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),I()},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(D,{name:"add",className:"h-3.5 w-3.5"})}):null,!O&&j&&F===0?s.jsx("button",{type:"button",onClick:J=>{J.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(D,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,O?null:s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),ge()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(D,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:J=>{J.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(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=E,e[51]=O,e[52]=F,e[53]=n.name,e[54]=ge,e[55]=_,e[56]=d,e[57]=I,e[58]=j,e[59]=ee,e[60]=V,e[61]=$e):$e=e[61];let Ce;e[62]!==v||e[63]!==ne||e[64]!==se||e[65]!==xe||e[66]!==Se||e[67]!==je||e[68]!==Ie||e[69]!==Pe||e[70]!==$e?(Ce=s.jsxs("div",{ref:v,className:ne,onClick:se,role:xe,tabIndex:Se,onKeyDown:je,"aria-label":Ie,children:[Pe,$e]}),e[62]=v,e[63]=ne,e[64]=se,e[65]=xe,e[66]=Se,e[67]=je,e[68]=Ie,e[69]=Pe,e[70]=$e,e[71]=Ce):Ce=e[71];let pe;e[72]!==O||e[73]!==m||e[74]!==i||e[75]!==c||e[76]!==f||e[77]!==r||e[78]!==a||e[79]!==V?(pe=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(J=>f(J,0,m??null,c??null,O)):a?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:V("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=O,e[73]=m,e[74]=i,e[75]=c,e[76]=f,e[77]=r,e[78]=a,e[79]=V,e[80]=pe):pe=e[80];let R;return e[81]!==U||e[82]!==Ce||e[83]!==pe?(R=s.jsxs("div",{className:U,children:[Ce,pe]}),e[81]=U,e[82]=Ce,e[83]=pe,e[84]=R):R=e[84],R},b4=o.memo(x4);function y4(t){return t.stopPropagation()}function v4(t){return t.stopPropagation()}function w4(t){return t.stopPropagation()}function j4(t){return t.stopPropagation()}function N4(t){return t.stopPropagation()}function S4(t){return t.stopPropagation()}function k4(t){return t.stopPropagation()}function C4(t){return t.stopPropagation()}function P4(t){return t.stopPropagation()}function I4(t){return t.stopPropagation()}const D4=t=>{const e=st.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:a,children:i}=t,l=`session-drag:${n}`;let u;e[0]!==r||e[1]!==n||e[2]!==a?(u={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:a},e[0]=r,e[1]=n,e[2]=a,e[3]=u):u=e[3];let d;e[4]!==l||e[5]!==u?(d={id:l,data:u},e[4]=l,e[5]=u,e[6]=d):d=e[6];const{attributes:f,listeners:m,setNodeRef:c,isDragging:p}=Lg(d);let g;e[7]!==m?(g=b=>{b.stopPropagation(),m?.onPointerDown&&m.onPointerDown(b)},e[7]=m,e[8]=g):g=e[8];const h=g,x=p?"opacity-30":void 0;let w;return e[9]!==f||e[10]!==i||e[11]!==h||e[12]!==c||e[13]!==x?(w=s.jsx("div",{ref:c,...f,onPointerDown:h,className:x,children:i}),e[9]=f,e[10]=i,e[11]=h,e[12]=c,e[13]=x,e[14]=w):w=e[14],w},T4=t=>{const e=st.c(11),{folderId:n,children:r}=t,a=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let l;e[2]!==a||e[3]!==i?(l={id:a,data:i},e[2]=a,e[3]=i,e[4]=l):l=e[4];const{setNodeRef:u,isOver:d}=Og(l);let f;e[5]!==r||e[6]!==d||e[7]!==u?(f=r(u,d),e[5]=r,e[6]=d,e[7]=u,e[8]=f):f=e[8];let m;return e[9]!==f?(m=s.jsx(s.Fragment,{children:f}),e[9]=f,e[10]=m):m=e[10],m},A4=t=>{const e=st.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:a,children:i}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const u=ji(Ma(Ni,l)),[d,f]=o.useState(null),[m,c]=o.useState("Session"),[p,g]=o.useState(null),[h,x]=o.useState(null);if(!n){let N;return e[1]!==i?(N=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=N):N=e[2],N}let w;e[3]!==a?(w=N=>{f(null),g(null),x(null);const{active:P,over:M}=N;if(!M)return;const T=P.data.current,E=M.data.current;T?.type==="session"&&T.sessionId&&E?.type==="folder"&&E.folderId&&a(T.sessionId,E.folderId)},e[3]=a,e[4]=w):w=e[4];const b=w;let y,v;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=N=>{const P=N.active.data.current;if(P?.type==="session"&&P.sessionId){f(P.sessionId),c(P.sessionTitle??"Session");const M=N.active.rect.current.initial?.width,T=N.active.rect.current.initial?.height;g(typeof M=="number"?M:null),x(typeof T=="number"?T:null)}},v=()=>{f(null),g(null),x(null)},e[5]=y,e[6]=v):(y=e[5],v=e[6]);let S;e[7]!==h||e[8]!==d||e[9]!==m||e[10]!==p||e[11]!==r?(S=d&&r?s.jsxs("div",{style:{width:p?`${p}px`:"auto",height:h?`${h}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(D,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=h,e[8]=d,e[9]=m,e[10]=p,e[11]=r,e[12]=S):S=e[12];let I;e[13]!==S?(I=s.jsx($o,{children:S}),e[13]=S,e[14]=I):I=e[14];let j;return e[15]!==i||e[16]!==b||e[17]!==u||e[18]!==I?(j=s.jsxs(Si,{sensors:u,collisionDetection:ki,onDragStart:y,onDragCancel:v,onDragEnd:b,children:[i,I]}),e[15]=i,e[16]=b,e[17]=u,e[18]=I,e[19]=j):j=e[19],j},ra=vn()($i(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"})),E4=50,M4=28;function R4(t){const{t:e}=ct(),{group:n,groupKey:r,projectId:a,hideGroupLabel:i,hasSessionSearchQuery:l,normalizedSessionSearchQuery:u,groupSearchDataByGroup:d,expandedSessionGroups:f,collapsedGroups:m,hideDirectoryControls:c,collapsedFolderIds:p,toggleFolderCollapse:g,renameFolder:h,deleteFolder:x,showDeletionDialog:w,setDeleteFolderConfirm:b,renderSessionNode:y,projectRepoStatus:v,lastRepoStatus:S,toggleGroupSessionLimit:I,mobileVariant:j,alwaysShowActions:N,activeProjectId:P,setActiveProjectIdOnly:M,setActiveMainTab:T,setSessionSwitcherOpen:E,openNewSessionDraft:k,addSessionToFolder:C,createFolderAndStartRename:A,renamingFolderId:F,renameFolderDraft:_,setRenameFolderDraft:O,setRenamingFolderId:V,pinnedSessionIds:K,sessionOrderIndex:$,prVisualStateByDirectoryBranch:oe,onToggleCollapsedGroup:L,dragHandleProps:Y,compactBodyPadding:ee=!1}=t,re=o.useCallback((Xe,mt)=>{const wt=$.get(Xe.session.id),Et=$.get(mt.session.id);if(wt!==void 0||Et!==void 0){if(wt===void 0)return 1;if(Et===void 0)return-1;if(wt!==Et)return wt-Et}return Fa(Xe.session,mt.session,K)},[K,$]),fe=l?d.get(n):null,ge=ra(Xe=>Xe.displayMode),be=Pn(Xe=>Xe.foldersMap),z=ge==="minimal",B=f.has(r),Q=l?!1:m.has(r),X=c?10:5,ie=l?fe?.groupMatches===!0:!1,le=l,ye=o.useMemo(()=>[...le?fe?.filteredNodes??[]:n.sessions].sort(re),[re,n.sessions,fe?.filteredNodes,le]),W=n.folderScopeKey??Zt(n.directory??null),ue=o.useMemo(()=>W?be[W]??[]:[],[W,be]),ae=o.useMemo(()=>{const Xe=new Map,mt=wt=>{wt.forEach(Et=>{Xe.set(Et.session.id,Et),Et.children.length>0&&mt(Et.children)})};return mt(ye),Xe},[ye]),U=o.useMemo(()=>ue.map(Xe=>{const mt=Xe.sessionIds.map(wt=>ae.get(wt)).filter(wt=>!!wt).sort(re);return{folder:Xe,nodes:mt}}),[ue,ae,re]),G=o.useMemo(()=>{const Xe=new Map(U.map(dt=>[dt.folder.id,dt])),mt=new Map;for(const{folder:dt}of U){if(!dt.parentId)continue;const gt=mt.get(dt.parentId);gt?gt.push(dt.id):mt.set(dt.parentId,[dt.id])}const wt=new Map,Et=dt=>{const gt=wt.get(dt);if(gt!==void 0)return gt;const Wt=Xe.get(dt);if(!Wt)return wt.set(dt,!1),!1;const Ot=mt.get(dt)??[];if(n.isArchivedBucket&&Wt.nodes.length===0){const It=Ot.some($t=>Et($t));return wt.set(dt,It),It}if(!l||Wt.folder.name.toLowerCase().includes(u)||Wt.nodes.length>0)return wt.set(dt,!0),!0;const rt=Ot.some(It=>Et(It));return wt.set(dt,rt),rt};return U.filter(({folder:dt})=>Et(dt.id))},[U,n.isArchivedBucket,l,u]),ne=o.useMemo(()=>new Set(G.flatMap(Xe=>Xe.folder.sessionIds)),[G]),se=o.useMemo(()=>ye.filter(Xe=>!ne.has(Xe.session.id)),[ye,ne]),xe=o.useMemo(()=>G.filter(({folder:Xe})=>!Xe.parentId),[G]),Se=se.length,je=n.isArchivedBucket||l||B?se:se.slice(0,X),Ie=Se-je.length,Oe=n.isArchivedBucket===!0&&!l&&je.length>=E4,Ne=o.useRef(null),[he,Fe]=o.useState(null),[Be,q]=o.useState(0),Pe=$g({count:je.length,getScrollElement:()=>he,estimateSize:()=>M4,overscan:8,enabled:Oe&&he!==null,scrollMargin:Be});o.useLayoutEffect(()=>{if(!Oe){he!==null&&Fe(null),Be!==0&&q(0);return}const Xe=Ne.current;if(!Xe)return;let mt=he;if(!mt||!mt.contains(Xe)){let Et=Xe.parentElement;for(;Et;){const dt=window.getComputedStyle(Et);if(dt.overflowY==="auto"||dt.overflowY==="scroll"){mt=Et;break}Et=Et.parentElement}if(mt!==he){Fe(mt);return}}if(!mt)return;const wt=Xe.getBoundingClientRect().top-mt.getBoundingClientRect().top+mt.scrollTop;q(Et=>Math.abs(Et-wt)<1?Et:wt)}),o.useEffect(()=>{if(!Oe||!he)return;const Xe=new ResizeObserver(()=>{Pe.measure()});return Xe.observe(he),()=>Xe.disconnect()},[Oe,he,Pe]);const $e=Pe.getTotalSize(),Ce=Oe&&he!==null?Pe.getVirtualItems():[];if(l&&!ie&&xe.length===0&&se.length===0)return null;const pe=Xe=>{const mt=[],wt=Et=>{Et.forEach(dt=>{mt.push(dt.session),dt.children.length>0&&wt(dt.children)})};return wt(Xe),mt},R=pe(ye),J=a&&v.has(a)?!!v.get(a):S,H=Zt(n.directory??null),Ee=n.branch?.trim()??null,Ae=H&&Ee?oe.get(`${H}::${Ee}`)??null:null,Je=!!(Ae&&n.branch),ce=!Ae&&!n.isMain&&!!n.branch,_e=Ae?.visualState??null,et=Ae&&Ae.state==="open"&&Ae.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Ae.checks.success,total:Ae.checks.total}):null,Me=Ae&&Ae.state==="open"&&Ae.checks?[Ae.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:Ae.checks.failure}):null,Ae.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:Ae.checks.pending}):null].filter(Xe=>!!Xe).join(", "):null,He=Ae&&Ae.state==="open"?Ae.mergeableState==="blocked"||Ae.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):Ae.mergeableState==="clean"||Ae.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,We=Ae&&Ae.state==="open"&&Ae.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Ae.mergeableState}):null,Te=Ae?.base??null,Ve=Ae?.head??null,Ye=(()=>{if(!Ae)return n.branch&&mb(n.branch,n.label)?{label:n.branch,color:null}:null;switch(Ae.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return Ae.canMerge===!0||Ae.mergeableState==="clean"||Ae.checks?.state==="success"?{label:e("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:e("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"};case"blocked":return{label:Ae.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked"),color:"var(--pr-blocked)"};case"draft":return{label:e("sessions.sidebar.group.pr.status.draft"),color:"var(--pr-draft)"};case"closed":return{label:e("sessions.sidebar.group.pr.status.closed"),color:"var(--pr-closed)"};default:return null}})(),Ge=Ye?.color??(_e?`var(--pr-${_e})`:void 0),me=Xe=>{Xe.preventDefault(),Xe.stopPropagation();const mt=Ae?.url;mt&&Yn(mt)},Ke=(Xe,mt,wt)=>{const Et=G.filter(({folder:Ot})=>Ot.parentId===Xe.id),dt=Et.length>0?s.jsx(s.Fragment,{children:Et.map(({folder:Ot,nodes:Bt})=>Ke(Ot,Bt,wt+1))}):void 0,gt=Ot=>{const Bt=G.find(({folder:It})=>It.id===Ot)?.nodes??[],rt=G.filter(({folder:It})=>It.parentId===Ot);return[...pe(Bt),...rt.flatMap(({folder:It})=>gt(It.id))]},Wt=n.isArchivedBucket?gt(Xe.id):[];return s.jsx(T4,{folderId:Xe.id,children:(Ot,Bt)=>s.jsx(b4,{folder:Xe,sessions:mt,subFolderItems:dt,isCollapsed:l?!1:p.has(Xe.id),onToggle:()=>g(Xe.id),onRename:rt=>{W&&h(W,Xe.id,rt)},onDelete:()=>{if(n.isArchivedBucket){gr.requestDelete({sessions:Wt,mode:"session"});return}if(!W)return;if(!w){x(W,Xe.id);return}const rt=G.filter(({folder:$t})=>$t.parentId===Xe.id).length,It=mt.length;b({scopeKey:W,folderId:Xe.id,folderName:Xe.name,subFolderCount:rt,sessionCount:It})},renderSessionNode:y,groupDirectory:n.directory,projectId:a,mobileVariant:j,alwaysShowActions:N,isRenaming:F===Xe.id,renameDraft:F===Xe.id?_:void 0,onRenameDraftChange:rt=>O(rt),onRenameSave:()=>{const rt=_.trim();rt&&W&&h(W,Xe.id,rt),V(null),O("")},onRenameCancel:()=>{V(null),O("")},droppableRef:Ot,isDropTarget:Bt,depth:wt,onNewSession:()=>{a&&a!==P&&M(a),T("chat"),j&&E(!1),k({directoryOverride:n.directory,targetFolderId:Xe.id})},onNewSubFolder:wt===0?()=>{W&&A(W,Xe.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Xe.id)},ze=()=>xe.map(({folder:Xe,nodes:mt})=>Ke(Xe,mt,0)),tt=!!(!n.isMain&&n.worktree),it=N?tt?"pr-14":"pr-7":z?tt?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":tt?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",qe=s.jsxs(A4,{scopeKey:W,hasFolders:G.length>0,onSessionDroppedOnFolder:(Xe,mt)=>{W&&C(W,mt,Xe)},children:[ze(),Oe?s.jsx("div",{ref:Ne,style:{position:"relative",height:$e>0?$e:void 0,width:"100%"},children:Ce.map(Xe=>{const mt=je[Xe.index];return mt?s.jsx("div",{"data-index":Xe.index,ref:Pe.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Xe.start-Be}px)`},children:y(mt,0,n.directory,a,!0)},Xe.key):null})}):je.map(Xe=>y(Xe,0,n.directory,a,n.isArchivedBucket===!0)),Se===0&&G.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,Ie>0&&!B?s.jsx("button",{type:"button",onClick:()=>I(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:Ie===1?e("sessions.sidebar.group.showMoreSingle",{count:Ie}):e("sessions.sidebar.group.showMorePlural",{count:Ie})}):null,B&&Se>X?s.jsx("button",{type:"button",onClick:()=>I(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),Ze=ee?"pb-2 pl-1":"pb-3 pl-4";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:de("oc-group-body",Ze),children:qe})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:de("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>L(r),role:"button",tabIndex:0,onKeyDown:Xe=>{(Xe.key==="Enter"||Xe.key===" ")&&(Xe.preventDefault(),L(r))},"aria-label":Q?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!Q,children:[s.jsx("div",{ref:Y?.setActivatorNodeRef,className:de("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",it),...Y?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:Je&&Ae?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(D,{name:"git-branch",className:de("h-3.5 w-3.5 shrink-0",N?"hidden":"group-hover/gh:hidden"),style:Ge?{color:Ge}:void 0}),s.jsx("span",{className:de("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),Ae.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:Xe=>Xe.stopPropagation(),onClick:me,children:["#",Ae.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Ae.number]})]})}),s.jsx(Rt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Te||Ve?s.jsx("div",{className:"text-muted-foreground truncate",children:Te&&Ve?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Te}),s.jsx(D,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Ve})]}):s.jsx("span",{children:Te??Ve??""})}):null,We?s.jsx("div",{className:"text-muted-foreground truncate",children:We}):null,He||et?s.jsxs("div",{className:"text-muted-foreground truncate",children:[He??"",He&&et?" • ":"",et??"",Me?` (${Me})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:n.branch})]}):n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(D,{name:"archive",className:de("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:de("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:yi(n.label,u)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(D,{name:"git-branch",className:de("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden"),style:Ge?{color:Ge}:void 0}),s.jsx("span",{className:de("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:yi(n.label,u)})]}):yi(n.label,u)}),ce&&Ye?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(D,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||J?Je&&Ae?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:Ge?{color:Ge}:void 0})})}),s.jsx(Rt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Te||Ve?s.jsx("div",{className:"text-muted-foreground truncate",children:Te&&Ve?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Te}),s.jsx(D,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Ve})]}):s.jsx("span",{children:Te??Ve??""})}):null,We?s.jsx("div",{className:"text-muted-foreground truncate",children:We}):null,He||et?s.jsxs("div",{className:"text-muted-foreground truncate",children:[He??"",He&&et?" • ":"",et??"",Me?` (${Me})`:""]}):null]})})]}):s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Ge?{color:Ge}:void 0}):null,s.jsx("span",{className:de("min-w-0 truncate text-[11px] font-medium",!Ye.color&&"text-muted-foreground/80"),style:Ye.color?{color:Ye.color}:void 0,children:Ye.label})]}):null]})}),n.isArchivedBucket&&R.length>0?s.jsx("div",{className:de("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Xe=>{Xe.stopPropagation(),gr.requestDelete({sessions:R,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:de("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Xe=>{Xe.stopPropagation(),gr.requestDelete({sessions:R,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:de("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Xe=>{Xe.stopPropagation(),a&&a!==P&&M(a),T("chat"),j&&E(!1),k({directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(D,{name:"add",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),Q?null:s.jsx("div",{className:de("oc-group-body",Ze),children:qe})]})}function F4(t){const e=st.c(33),{t:n}=ct(),{hideDirectoryControls:r,handleNewSession:a,headerActionIconClass:i,reserveHeaderActionsSpace:l,headerActionButtonClass:u,isSessionSearchOpen:d,setIsSessionSearchOpen:f,sessionSearchInputRef:m,sessionSearchQuery:c,setSessionSearchQuery:p,hasSessionSearchQuery:g,searchMatchCount:h,collapseAllProjects:x,expandAllProjects:w,selectionModeEnabled:b,onToggleSelectionMode:y,showSidebarToggle:v,onToggleSidebar:S,avoidWindowControlsOverlay:I}=t,j=v===void 0?!1:v,N=I===void 0?!1:I,P=ra(z4),M=ra(_4),T=ra($4),E=ra(O4);if(r)return null;const k=j?N?"pl-[5.5rem] pr-3":"pl-3 pr-3":"px-2.5 py-1";let C;e[0]!==k?(C=de("select-none flex-shrink-0",k),e[0]=k,e[1]=C):C=e[1];let A;e[2]!==N||e[3]!==j?(A=j&&N?{paddingTop:"var(--oc-safe-area-top, 0px)"}:void 0,e[2]=N,e[3]=j,e[4]=A):A=e[4];let F;e[5]!==N||e[6]!==x||e[7]!==P||e[8]!==w||e[9]!==a||e[10]!==g||e[11]!==u||e[12]!==i||e[13]!==d||e[14]!==y||e[15]!==S||e[16]!==l||e[17]!==h||e[18]!==b||e[19]!==m||e[20]!==c||e[21]!==T||e[22]!==f||e[23]!==p||e[24]!==M||e[25]!==j||e[26]!==n||e[27]!==E?(F=l?s.jsxs("div",{className:de("flex h-auto flex-col gap-1",j?N?"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:[j&&S?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,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(D,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.closeSessions")})})]}):null,s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:u,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(D,{name:"chat-new",className:i})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>f(L4),className:u,"aria-label":n("sessions.sidebar.header.actions.searchSessions"),"aria-expanded":d,children:s.jsx(D,{name:"search",className:i})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.searchSessions")})})]}),s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:y,className:de(u,b&&"bg-interactive-hover text-primary"),"aria-label":n(b?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),"aria-pressed":b,children:s.jsx(D,{name:"checkbox-multiple",className:i})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n(b?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions")})})]}),s.jsxs(ys,{children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:u,"aria-label":n("sessions.sidebar.header.actions.sessionDisplayMode"),children:s.jsx(D,{name:"equalizer-2",className:i})})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.displayMode.label")})})]}),s.jsxs(ws,{align:"end",className:"min-w-[160px]",children:[s.jsxs(vt,{onClick:()=>T("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),P==="default"?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(vt,{onClick:()=>T("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),P==="minimal"?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Ys,{}),s.jsxs(vt,{onClick:E,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),M?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Ys,{}),s.jsxs(vt,{onClick:x,className:"flex items-center gap-2",children:[s.jsx(D,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(vt,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(D,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]})]})]})]}),d?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[g?s.jsx("span",{children:h===1?n("sessions.sidebar.header.search.matchCountSingle",{count:h}):n("sessions.sidebar.header.search.matchCountPlural",{count:h})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(D,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:m,value:c,onChange:O=>p(O.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:O=>{O.key==="Escape"&&(O.stopPropagation(),g?p(""):f(!1))}}),c.length>0?s.jsx("button",{type:"button",onClick:()=>p(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[5]=N,e[6]=x,e[7]=P,e[8]=w,e[9]=a,e[10]=g,e[11]=u,e[12]=i,e[13]=d,e[14]=y,e[15]=S,e[16]=l,e[17]=h,e[18]=b,e[19]=m,e[20]=c,e[21]=T,e[22]=f,e[23]=p,e[24]=M,e[25]=j,e[26]=n,e[27]=E,e[28]=F):F=e[28];let _;return e[29]!==C||e[30]!==A||e[31]!==F?(_=s.jsx("div",{className:C,style:A,children:F}),e[29]=C,e[30]=A,e[31]=F,e[32]=_):_=e[32],_}function L4(t){return!t}function O4(t){return t.toggleRecentSection}function $4(t){return t.setDisplayMode}function _4(t){return t.showRecentSection}function z4(t){return t.displayMode}const vp=7;function B4(t){const e=st.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=ct();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[l,u]=o.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[f,m]=o.useState(d);let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=v=>{u(S=>{const I=new Set(S);return I.has(v)?I.delete(v):I.add(v),I})},e[2]=c):c=e[2];const p=c;let g;e[3]===Symbol.for("react.memo_cache_sentinel")?(g=v=>{m(S=>{const I=new Set(S);return I.has(v)?I.delete(v):I.add(v),I})},e[3]=g):g=e[3];const h=g;let x,w,b;if(e[4]!==l||e[5]!==f||e[6]!==r||e[7]!==n||e[8]!==a){b=Symbol.for("react.early_return_sentinel");e:{const v=n.filter(V4);if(v.length===0){b=null;break e}x="space-y-2 pb-2 pt-1";let S;e[12]!==l||e[13]!==f||e[14]!==r||e[15]!==a?(S=I=>{const j=l.has(I.key),N=f.has(I.key),P=N?I.items:I.items.slice(0,vp),M=I.items.length-P.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>p(I.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:I.title})]}),j?null:s.jsxs("div",{className:de("space-y-0.5 pl-7"),children:[P.map(T=>r(T.node,0,T.groupDirectory,T.projectId,!1,T.secondaryMeta,"recent")),M>0&&!N?s.jsx("button",{type:"button",onClick:()=>h(I.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:M===1?a("sessions.sidebar.group.showMoreSingle",{count:M}):a("sessions.sidebar.group.showMorePlural",{count:M})}):null,N&&I.items.length>vp?s.jsx("button",{type:"button",onClick:()=>h(I.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:a("sessions.sidebar.group.showFewer")}):null]})]},I.key)},e[12]=l,e[13]=f,e[14]=r,e[15]=a,e[16]=S):S=e[16],w=v.map(S)}e[4]=l,e[5]=f,e[6]=r,e[7]=n,e[8]=a,e[9]=x,e[10]=w,e[11]=b}else x=e[9],w=e[10],b=e[11];if(b!==Symbol.for("react.early_return_sentinel"))return b;let y;return e[17]!==x||e[18]!==w?(y=s.jsx("div",{className:x,children:w}),e[17]=x,e[18]=w,e[19]=y):y=e[19],y}function V4(t){return t.items.length>0}const U4=t=>{const e=st.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:l,projectIconImage:u,projectIconBackground:d,isCollapsed:f,isActiveProject:m,isRepo:c,isDesktopShell:p,isStuck:g,hideDirectoryControls:h,alwaysShowActions:x,onToggle:w,onNewSession:b,onNewWorktreeSession:y,onRenameStart:v,onClose:S,sentinelRef:I,children:j,showCreateButtons:N,hideHeader:P,openSidebarMenuKey:M,setOpenSidebarMenuKey:T}=t,E=N===void 0?!0:N,k=P===void 0?!1:P,{t:C}=ct(),{currentTheme:A}=rr();let F;e[0]!==n?(F={id:n},e[0]=n,e[1]=F):F=e[1];const{attributes:_,listeners:O,setNodeRef:V,transform:K,transition:$,isDragging:oe}=rl(F),[L,Y]=o.useState(!1),ee=o.useRef(!1),re=`project:${n}`,fe=M===re;let ge;e[2]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>{Y(!1)},e[2]=ge):ge=e[2];const be=u?.updatedAt;let z;e[3]!==n||e[4]!==be?(z=[n,be],e[3]=n,e[4]=be,e[5]=z):z=e[5],o.useEffect(ge,z);const B=i?pl[i]:null,Q=l?Vi[l]??null:null;let X;e[6]!==A||e[7]!==n||e[8]!==L||e[9]!==u?(X=L?null:Bi({id:n,iconImage:u},{themeVariant:A.metadata.variant,iconColor:A.colors.surface.foreground}),e[6]=A,e[7]=n,e[8]=L,e[9]=u,e[10]=X):X=e[10];const ie=X;let le;e[11]!==re||e[12]!==T?(le=he=>{T(he?re:null)},e[11]=re,e[12]=T,e[13]=le):le=e[13];const ye=le,W=H4,ue=G4,ae=q4;let U;e[14]===Symbol.for("react.memo_cache_sentinel")?(U=he=>{(he.button===2||he.button===0&&he.ctrlKey)&&(ee.current=!0)},e[14]=U):U=e[14];const G=U;let ne;e[15]!==w?(ne=()=>{if(ee.current){ee.current=!1;return}w()},e[15]=w,e[16]=ne):ne=e[16];const se=ne;let xe;e[17]!==K?(xe=al.Transform.toString(K),e[17]=K,e[18]=xe):xe=e[18];let Se;e[19]!==xe||e[20]!==$?(Se={transform:xe,transition:$},e[19]=xe,e[20]=$,e[21]=Se):Se=e[21];const je=oe&&"opacity-30";let Ie;e[22]!==je?(Ie=de("relative",je),e[22]=je,e[23]=Ie):Ie=e[23];let Oe;e[24]!==x||e[25]!==_||e[26]!==ye||e[27]!==se||e[28]!==h||e[29]!==k||e[30]!==Q||e[31]!==n||e[32]!==ie||e[33]!==m||e[34]!==f||e[35]!==p||e[36]!==fe||e[37]!==c||e[38]!==g||e[39]!==O||e[40]!==S||e[41]!==b||e[42]!==y||e[43]!==v||e[44]!==a||e[45]!==d||e[46]!==B||e[47]!==r||e[48]!==I||e[49]!==E||e[50]!==C?(Oe=k?null:s.jsxs(s.Fragment,{children:[p&&s.jsx("div",{ref:I,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:de("w-full text-left group/project select-none"),style:{backgroundColor:p&&g?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",..._,children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:G,onClick:se,...O,className:de("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]",c&&!h?x?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":x?"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:de("h-3.5 w-3.5 items-center justify-center text-muted-foreground",x?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:f?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),ie?s.jsx("span",{className:de("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",x?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:ie,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>Y(!0)})}):B?s.jsx(D,{name:B,className:de("h-3.5 w-3.5",x?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:Q?{color:Q}:void 0}):s.jsx(D,{name:"folder",className:de("h-3.5 w-3.5 text-muted-foreground/80",x?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:Q?{color:Q}:void 0})]}),s.jsx("span",{className:de("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(Rt,{side:"right",sideOffset:8,children:a})]}),s.jsxs("div",{className:de("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",E?"right-7":"right-0.5"),children:[E&&c&&!h&&y?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:he=>{he.stopPropagation(),y()},className:de("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",x?"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":C("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(D,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:C("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(ys,{open:fe,onOpenChange:ye,children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:de("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",fe?"opacity-100 pointer-events-auto":x?"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":C("sessions.sidebar.project.actions.projectMenu"),onPointerDown:ue,onMouseDown:ae,onClick:W,children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(ws,{align:"end",className:"min-w-[180px]",children:[E&&!c&&!h&&b&&s.jsxs(vt,{onClick:b,children:[s.jsx(D,{name:"add",className:"mr-1.5 h-4 w-4"}),C("sessions.sidebar.project.actions.newSession")]}),s.jsxs(vt,{onClick:v,children:[s.jsx(D,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),C("sessions.sidebar.session.menu.rename")]}),s.jsxs(vt,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"close",className:"mr-1.5 h-4 w-4"}),C("sessions.sidebar.project.actions.closeProject")]})]})]})]}),E&&b?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:he=>{he.stopPropagation(),b()},className:de("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",x?"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":C(c?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(D,{name:"add",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:C(c?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=x,e[25]=_,e[26]=ye,e[27]=se,e[28]=h,e[29]=k,e[30]=Q,e[31]=n,e[32]=ie,e[33]=m,e[34]=f,e[35]=p,e[36]=fe,e[37]=c,e[38]=g,e[39]=O,e[40]=S,e[41]=b,e[42]=y,e[43]=v,e[44]=a,e[45]=d,e[46]=B,e[47]=r,e[48]=I,e[49]=E,e[50]=C,e[51]=Oe):Oe=e[51];let Ne;return e[52]!==j||e[53]!==V||e[54]!==Se||e[55]!==Ie||e[56]!==Oe?(Ne=s.jsxs("div",{ref:V,style:Se,className:Ie,children:[Oe,j]}),e[52]=j,e[53]=V,e[54]=Se,e[55]=Ie,e[56]=Oe,e[57]=Ne):Ne=e[57],Ne},K4=t=>{const e=st.c(21),{id:n,disabled:r,children:a}=t,i=r===void 0?!1:r;let l;e[0]!==i||e[1]!==n?(l={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=l):l=e[2];const{listeners:u,setNodeRef:d,setActivatorNodeRef:f,transform:m,transition:c,isDragging:p}=rl(l);let g;e[3]!==u||e[4]!==f?(g={listeners:u,setActivatorNodeRef:f},e[3]=u,e[4]=f,e[5]=g):g=e[5];const h=g;let x;e[6]!==m?(x=al.Transform.toString(m),e[6]=m,e[7]=x):x=e[7];let w;e[8]!==x||e[9]!==c?(w={transform:x,transition:c},e[8]=x,e[9]=c,e[10]=w):w=e[10];const b=p&&"opacity-50";let y;e[11]!==b?(y=de("space-y-0.5 rounded-md",b),e[11]=b,e[12]=y):y=e[12];let v;e[13]!==a||e[14]!==h?(v=typeof a=="function"?a(h):a,e[13]=a,e[14]=h,e[15]=v):v=e[15];let S;return e[16]!==d||e[17]!==w||e[18]!==y||e[19]!==v?(S=s.jsx("div",{ref:d,style:w,className:y,children:v}),e[16]=d,e[17]=w,e[18]=y,e[19]=v,e[20]=S):S=e[20],S},W4=o.memo(K4);function H4(t){t.stopPropagation()}function G4(t){t.stopPropagation()}function q4(t){t.stopPropagation()}function Y4(t){const e=st.c(25),{t:n}=ct();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={coordinateGetter:zg},e[1]=a):a=e[1];const i=ji(Ma(Ni,r),Ma(_g,a));let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[2]=l):l=e[2];const u=ji(Ma(Ni,l));if(t.projectSections.length===0){const p=(t.mobileVariant,"");let g;e[3]!==p?(g=de("space-y-1 pb-1 pl-2.5 pr-2",p),e[3]=p,e[4]=g):g=e[4];let h;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==g?(h=s.jsxs(ts,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:g,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=g,e[8]=h):h=e[8],h}if(t.sectionsForRender.length===0){const p=(t.mobileVariant,"");let g;e[9]!==p?(g=de("space-y-1 pb-1 pl-2.5 pr-2",p),e[9]=p,e[10]=g):g=e[10];let h;return e[11]!==t.searchEmptyState||e[12]!==g?(h=s.jsx(ts,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:g,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=g,e[13]=h):h=e[13],h}const d=(t.mobileVariant,"");let f;e[14]!==d?(f=de("space-y-1 pb-1 pl-2.5 pr-2",d),e[14]=d,e[15]=f):f=e[15];let m;e[16]!==u||e[17]!==i||e[18]!==t||e[19]!==n?(m=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const p=t.sectionsForRender.find(w=>w.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!p)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const g=p.groups.find(nP)??p.groups.find(sP)??p.groups.find(tP)??p.groups[0];if(!g)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const h=p.groups.find(eP);return[g,...h&&h.id!==g.id?[h]:[]].map(w=>{const b=`${p.project.id}:${w.id}`,y=w.id===g.id;return s.jsx(o.Fragment,{children:t.renderGroupSessions(w,b,p.project.id,y,null,!0)},b)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Si,{sensors:i,collisionDetection:ki,onDragEnd:p=>{if(t.isInlineEditing)return;const{active:g,over:h}=p;if(!h||g.id===h.id)return;const x=t.sectionsForRender.findIndex(b=>b.project.id===g.id),w=t.sectionsForRender.findIndex(b=>b.project.id===h.id);x===-1||w===-1||x===w||t.reorderProjects(x,w)},children:[s.jsx(Oo,{items:t.sectionsForRender.map(Z4),strategy:xc,children:t.sectionsForRender.map(p=>{const g=p.project,h=g.id,x=Sf(g.label?.trim()||ca(g.normalizedPath,t.homeDirectory)||g.normalizedPath),w=Ti(g.normalizedPath,t.homeDirectory),b=t.collapsedProjects.has(h),y=h===t.activeProjectId,v=t.projectRepoStatus.get(h),S=t.getOrderedGroups(h,p.groups),I=S.find(X4)??null,j=I?S.filter(N=>N.id!==I.id):S;return s.jsx(U4,{id:h,projectLabel:x,projectDescription:w,projectIcon:g.icon,projectColor:g.color,projectIconImage:g.iconImage,projectIconBackground:g.iconBackground,isCollapsed:b,isActiveProject:y,isRepo:!!v,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:g.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:N=>{t.projectHeaderSentinelRefs.current.set(h,N)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:b?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:p.groups.length>0?s.jsxs(Si,{sensors:u,collisionDetection:ki,onDragEnd:N=>{if(t.isInlineEditing)return;const{active:P,over:M}=N;if(!M||P.id===M.id)return;const T=j.findIndex(A=>A.id===P.id),E=j.findIndex(A=>A.id===M.id);if(T===-1||E===-1||T===E)return;const k=Bp(j,T,E).map(J4),C=I?[I.id,...k]:k;t.setGroupOrderByProject(A=>{const F=new Map(A);return F.set(h,C),F})},children:[I?t.renderGroupSessions(I,`${h}:${I.id}`,h,!0):null,s.jsx(Oo,{items:j.map(Q4),strategy:xc,children:j.map(N=>{const P=`${h}:${N.id}`;return s.jsx(W4,{id:N.id,disabled:t.isInlineEditing,children:M=>t.renderGroupSessions(N,P,h,!1,M)},N.id)})}),s.jsx($o,{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($o,{dropAnimation:null})]})}),e[16]=u,e[17]=i,e[18]=t,e[19]=n,e[20]=m):m=e[20];let c;return e[21]!==t.topContent||e[22]!==f||e[23]!==m?(c=s.jsxs(ts,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:f,children:[t.topContent,m]}),e[21]=t.topContent,e[22]=f,e[23]=m,e[24]=c):c=e[24],c}function Q4(t){return t.id}function J4(t){return t.id}function X4(t){return t.isMain}function Z4(t){return t.project.id}function eP(t){return t.isArchivedBucket}function tP(t){return t.isMain}function sP(t){return t.sessions.length>0}function nP(t){return t.isMain&&t.sessions.length>0}const rP=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const a of t){r.has(a)||(r.add(a),n.push(a));const i=e.get(a);if(i)for(const l of i)r.has(l)||(r.add(l),n.push(l))}return n},Gn=vn()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,a)=>{const i=e(),l=new Set(i.selectedIds);let u=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(l.clear(),u=r,d=null):u===null&&r!==null&&(u=r);const m=a&&a.length>0?[n,...a]:[n];if(l.has(n)){for(const p of m)l.delete(p);d===n&&(d=null)}else{for(const p of m)l.add(p);d=n}l.size===0?t({selectedIds:l,scopeKey:null,anchorId:null}):t({selectedIds:l,scopeKey:u,anchorId:d})},setRange:(n,r,a,i,l)=>{const u=e();if(a.length===0)return;const d=n&&a.includes(n)?n:a[0],f=a.indexOf(d),m=a.indexOf(r);if(f<0||m<0)return;const[c,p]=f<=m?[f,m]:[m,f],g=a.slice(c,p+1),h=rP(g,l),w=i!==null&&u.scopeKey!==null&&i!==u.scopeKey?new Set:new Set(u.selectedIds);for(const b of h)w.add(b);t({selectedIds:w,scopeKey:i??u.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const a=new Set(r.selectedIds);for(const i of n)a.delete(i);a.size!==r.selectedIds.size&&(a.size===0?t({selectedIds:a,scopeKey:null,anchorId:null}):t({selectedIds:a}))}}));function aP(t){const e=st.c(7);let n,r,a,i,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),a=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),l=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=a,e[3]=i,e[4]=l):(n=e[0],r=e[1],a=e[2],i=e[3],l=e[4]);let u;return e[5]!==t?(u=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,a,i,l]}),e[5]=t,e[6]=u):u=e[6],u}const wp=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),ta=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(ta(n,e))return!0;return!1},Wc=(t,e,n,r)=>{if(!e)return!1;if(`${n}:${r?"archived":"active"}:${t.session.id}`===e)return!0;for(const i of t.children)if(Wc(i,e,n,r))return!0;return!1},iP=(t,e)=>{const n=t.node.session,r=e.node.session,a=n.id,i=r.id;if(a!==i||t.node.session!==e.node.session||wp(t.node)!==wp(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=ta(t.node,t.currentSessionId),c=ta(e.node,e.currentSessionId);if(m||c)return!1}if(t.pinnedSessionIds.has(a)!==e.pinnedSessionIds.has(i))return!1;{const m=t.renderContext??"project",c=e.renderContext??"project",p=t.archivedBucket??!1,g=e.archivedBucket??!1,h=`${m}:${p?"archived":"active"}:${a}`,x=`${c}:${g?"archived":"active"}:${i}`;if(t.expandedParents.has(h)!==e.expandedParents.has(x))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=ta(t.node,t.editingId),c=ta(e.node,e.editingId);if(m||c)return!1}if(t.editTitle!==e.editTitle){const m=ta(t.node,t.editingId),c=ta(e.node,e.editingId);if(m||c)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const l=Wc(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),u=Wc(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(l!==u)return!1;const d=Zt(n.directory??null)??Zt(t.groupDirectory??null),f=Zt(r.directory??null)??Zt(e.groupDirectory??null);return!(d!==f||(d?t.directoryStatus.get(d):null)!==(f?e.directoryStatus.get(f):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 oP(t){const{t:e}=ct(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:l=!1,directoryStatus:u,currentSessionId:d,pinnedSessionIds:f,expandedParents:m,hasSessionSearchQuery:c,normalizedSessionSearchQuery:p,notifyOnSubtasks:g,editingId:h,setEditingId:x,editTitle:w,setEditTitle:b,handleSaveEdit:y,handleCancelEdit:v,toggleParent:S,handleSessionSelect:I,handleSessionDoubleClick:j,togglePinnedSession:N,handleShareSession:P,copiedSessionId:M,handleCopyShareUrl:T,handleUnshareSession:E,openSidebarMenuKey:k,setOpenSidebarMenuKey:C,renamingFolderId:A,getFoldersForScope:F,getSessionFolderId:_,removeSessionFromFolder:O,addSessionToFolder:V,createFolderAndStartRename:K,openContextPanelTab:$,handleDeleteSession:oe,mobileVariant:L,alwaysShowActions:Y,renderSessionNode:ee,secondaryMeta:re,renderContext:fe="project"}=t,ge=!!re?.projectLabel,be=!!re?.branchLabel,B=ra(ft=>ft.displayMode)==="minimal",Q=o.useMemo(()=>Ks(),[]),X=o.useMemo(()=>Jc(),[]),ie=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",ye=!l&&!L,W=B?Q?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":Q?ye?"group-hover:pr-12":"group-hover:pr-5":ye?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",ue=ye?"pr-13":"pr-7",ae=o.useRef(!1),[U,G]=o.useState(!1),ne=n.session,xe=Qp(ne.id)??ne,Se=Zt(ne.directory??null)??Zt(a??null),je=pb(Se??void 0),Ie=ld(),Oe=Gn(ft=>ft.enabled),Ne=Gn(o.useCallback(ft=>ft.selectedIds.has(ne.id),[ne.id])),he=Gn(ft=>ft.toggleSelected),Fe=Gn(ft=>ft.setRange),Be=o.useCallback(ft=>{const Es=[],is=Z=>{Z.children.forEach(yt=>{Es.push(yt.session.id),is(yt)})};return is(ft),Es},[]),[q,Pe]=o.useState(!1),[$e,Ce]=o.useState(!0),pe=`${fe}:${l?"archived":"active"}:${ne.id}`,R=kf(o.useCallback(ft=>!!ft.sessionMemoryState.get(ne.id)?.isZombie,[ne.id])),J=fb(ne.id),H=hb(ne.id,Se??void 0),Ae=(Se?u.get(Se):null)==="missing",Je=d===ne.id,ce=xe.title||e("sessions.sidebar.session.untitled"),_e=n.children.length>0,et=f.has(ne.id),Me=pe,He=c?!0:m.has(Me),We=!!xe.parentID,Ve=gb(ne.id)>0&&(!We||g),Ye=xe.summary,Ge=Xp(Ye),me=xe.time?.updated||xe.time?.created||Date.now(),Ke=xb(me),ze=Db(me),tt=k===pe,it=o.useMemo(()=>bb(xe.title)!==null,[xe.title]),[qe,Ze]=o.useState(!1),Xe=o.useMemo(()=>Be(n).length,[Be,n]),mt=o.useCallback(async ft=>{const Es=[];let is=0;for(const Z of ft)try{await Ie.ensureSessionRenderable(Z.session.id);const yt=ou(je.getState(),Z.session.id).list,_t=Z.session.title||e("sessions.sidebar.session.export.untitledSubagent"),gs=Z.session.agent,Ps=await mt(Z.children);is+=Ps.skipped,Es.push({title:_t,agent:gs,records:yt,children:Ps.children})}catch{is+=Be(Z).length+1}return{children:Es,skipped:is}},[Be,je,Ie,e]),wt=o.useCallback(ft=>{ft<=0||te.warning(ft===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:ft}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:ft}))},[e]),Et=o.useCallback(async ft=>{if(!Se){te.error(e("sessions.sidebar.session.export.nothingToExport"));return}await Ie.ensureSessionRenderable(ne.id);const Es=ou(je.getState(),ne.id).list;if(Es.length===0){te.error(e("sessions.sidebar.session.export.nothingToExport"));return}let is,Z=0;if(ft&&n.children.length>0){const Ps=await mt(n.children);is=Ps.children,Z=Ps.skipped}const yt=yb(Es,xe.title??null,is),_t=vb(xe.title??null),gs=await wb(yt,_t);if(gs){te.success(e("sessions.sidebar.session.export.success"),{action:{label:e(Nb()),onClick:()=>{jb(gs).then(Ps=>{Ps||te.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),wt(Z);return}Sb(yt,_t),te.success(e("sessions.sidebar.session.export.success")),wt(Z)},[mt,je,n.children,xe.title,ne.id,Se,wt,Ie,e]),dt=o.useCallback(async()=>{if(n.children.length>0){Ce(!0),Pe(!0);return}await Et(!1)},[Et,n.children.length]),gt=o.useCallback(()=>{Se&&_o("desktop_open_session_mini_chat_window",{sessionId:ne.id,directory:Se}).catch(ft=>{console.warn("[session-sidebar] failed to open mini chat window",ft)})},[ne.id,Se]);if(h===ne.id)return s.jsx("div",{className:de("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(),y()},children:[s.jsx("input",{value:w,onChange:ft=>b(ft.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:ft=>{if(ft.key==="Escape"){ft.stopPropagation(),v();return}(ft.key===" "||ft.key==="Enter")&&ft.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:v,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"close",className:"size-4"})})]}),B?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[_e?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:He?s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(D,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:Ke}),Ge?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:["+",Ge.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Ge.deletions]})]}):null,ge?s.jsx("span",{className:"truncate",children:re?.projectLabel}):null,be?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:re?.branchLabel})]}):null]})})]})},ne.id);const Wt=J?.type??"idle",Ot=Wt==="busy"||Wt==="retry",Bt=H.length,It=Ot||!Ot&&Ve&&!Je,$t=Ot?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-busy-pulse","aria-label":e("sessions.sidebar.session.status.active"),title:e("sessions.sidebar.session.status.active")}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":e("sessions.sidebar.session.status.unread"),title:e("sessions.sidebar.session.status.unread")}),Ut=It||et?s.jsxs("span",{className:de("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",B?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",It&&et?"left-[-18px] w-6":"left-[-10px] w-3.5",_e&&!Y?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[It?$t:null,et?s.jsx(D,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,ms=_e?s.jsx("span",{role:"button",tabIndex:0,onClick:ft=>{ft.stopPropagation(),S(Me)},onKeyDown:ft=>{(ft.key==="Enter"||ft.key===" ")&&(ft.preventDefault(),ft.stopPropagation(),S(Me))},className:de("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",B?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",B&&It&&!Y?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(He?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:He?s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(D,{name:"arrow-right-s",className:"h-3 w-3"})}):null,ns=R?s.jsx(D,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Vt=ft=>{C(ft?pe:null)},Ue=ft=>{ft.preventDefault(),ft.stopPropagation(),C(tt?null:pe)},kt=ft=>{ft.preventDefault(),ft.stopPropagation()},Mt=ft=>{ft.preventDefault(),ft.stopPropagation()},ut=ft=>{ft.preventDefault(),ft.stopPropagation()},Kt=ft=>{ft.preventDefault(),ft.stopPropagation()},Yt=ft=>{ft.preventDefault(),ft.stopPropagation(),C(null),oe(ne,{archivedBucket:l})},ks=ft=>{if(ae.current){ae.current=!1;return}if(Oe){if(ft?.preventDefault(),ft?.stopPropagation(),ft?.shiftKey){const is=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(_t=>_t.getAttribute("data-session-row")).filter(_t=>typeof _t=="string"&&_t.length>0),Z=Gn.getState().anchorId,yt=new Map;yt.set(ne.id,Be(n)),Fe(Z,ne.id,is,Se??null,yt);return}he(ne.id,Se??null,Be(n));return}I(ne.id,Se,Ae,i)},Cs=ft=>{(ft.button===2||ft.button===0&&ft.ctrlKey&&!Oe)&&(ae.current=!0)},Fs=ft=>{L&&ft.pointerType==="touch"&&G(!0)},Ls=ft=>{L&&ft.pointerType==="touch"&&G(!1)},dn=s.jsxs(ws,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:ft=>{A&&ft.preventDefault()},children:[s.jsxs(vt,{onClick:()=>{x(ne.id),b(ce)},className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(vt,{onClick:()=>N(ne.id),className:"[&>svg]:mr-1",children:[et?s.jsx(D,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(D,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(et?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),xe.share?s.jsxs(s.Fragment,{children:[s.jsx(vt,{onClick:()=>{xe.share?.url&&T(xe.share.url,ne.id)},className:"[&>svg]:mr-1",children:M===ne.id?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(vt,{onClick:()=>E(ne.id),className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(vt,{onClick:()=>P(xe),className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(vt,{onClick:()=>{dt()},className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),it?s.jsxs(vt,{onClick:()=>Ze(!0),className:"[&>svg]:mr-1",children:[s.jsx(aP,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Se&&!l?(()=>{const ft=F(Se),Es=_(Se,ne.id);return s.jsxs(s.Fragment,{children:[s.jsx(Ys,{}),s.jsxs(kb,{children:[s.jsxs(Cb,{className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Pb,{className:"min-w-[180px]",children:[ft.length===0?s.jsx(vt,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):ft.map(is=>s.jsxs(vt,{onClick:()=>{Es===is.id?O(Se,ne.id):V(Se,is.id,ne.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:is.name}),Es===is.id?s.jsx(D,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},is.id)),s.jsx(Ys,{}),s.jsxs(vt,{onClick:()=>{const is=K(Se);is&&V(Se,is.id,ne.id)},children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Es?s.jsxs(vt,{onClick:()=>{O(Se,ne.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,Q?null:s.jsxs(vt,{disabled:!Se,onClick:()=>{Se&&$(Se,{mode:"chat",dedupeKey:`session:${ne.id}`,label:ce})},className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),X?s.jsxs(vt,{disabled:!Se,onClick:gt,className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Ys,{}),s.jsxs(vt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>oe(ne,{archivedBucket:l}),children:[s.jsx(D,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(l?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(o.Fragment,{children:[s.jsx(D4,{sessionId:ne.id,sessionDirectory:Se??null,sessionTitle:ce,children:s.jsxs("div",{"data-session-row":ne.id,"data-session-scope":Se??"","data-session-archived":l?"1":"0",className:de("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",Ae?"opacity-75":"",r>0&&"pl-[20px]",Ne&&"bg-primary/15"),children:[Ut,ms,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:B?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",disabled:Ae,onPointerDown:Fs,onPointerUp:Ls,onPointerCancel:Ls,onMouseDown:Cs,onClick:ft=>ks(ft),onDoubleClick:ft=>{ft.stopPropagation(),j()},className:de("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]",U&&"bg-interactive-hover/70",Y?Q?W:ue:W),children:s.jsxs("div",{className:de("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:de("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:yi(ce,p)}),Y?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:ze}):null,Y?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:de("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",tt?"opacity-0":le),children:ze})}),Bt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(D,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Bt})]}):null]})})}),s.jsx(Rt,{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:de("flex items-center gap-3 text-left text-muted-foreground",re?.projectLabel?"justify-between":"justify-start"),children:[re?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:re.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:Ke})]}),re?.branchLabel||Ge?s.jsxs("div",{className:de("flex items-center gap-3 text-left text-muted-foreground",re?.branchLabel?"justify-between":"justify-start"),children:[re?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:re.branchLabel})]})}):null,Ge?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Ge.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Ge.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:Ae,onPointerDown:Fs,onPointerUp:Ls,onPointerCancel:Ls,onMouseDown:Cs,onClick:ft=>ks(ft),onDoubleClick:ft=>{ft.stopPropagation(),j()},className:de("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]",U&&"bg-interactive-hover/70",Y?Q?W:ue:W),children:[s.jsxs("div",{className:de("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:de("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:yi(ce,p)}),Bt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(D,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Bt})]}):null]}),B?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:Ke}),Ge?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:["+",Ge.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Ge.deletions]})]}):null,ge?s.jsx("span",{className:"truncate",children:re?.projectLabel}):null,be?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:re?.branchLabel})]}):null]})})]})}),ns&&!L?s.jsx("div",{className:de("absolute top-1/2 -translate-y-1/2 z-10",B?"right-0":"right-[30px]"),children:ns}):null,s.jsxs("div",{className:de("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",tt||Y&&!Q?"opacity-100":de("opacity-0",ie)),children:[ye?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",className:de("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",B&&!Y?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:ut,onMouseDown:Kt,onClick:Yt,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(D,{name:"archive",className:de(B&&!Y?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Rt,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(ys,{open:tt,onOpenChange:Vt,children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:de("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",B&&!Y?tt?"h-4 w-4 opacity-100":de("h-4 w-4 opacity-0",ie):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:kt,onMouseDown:Mt,onClick:Ue,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(D,{name:"more-2",className:de(B&&!Y?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),dn]})]})]})}),_e&&He?n.children.map(ft=>ee(ft,r+1,Se??a,i,l,void 0,fe)):null,s.jsx(ls,{open:q,onOpenChange:Pe,children:s.jsxs(os,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(bs,{children:[s.jsx(hs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ss,{children:Xe===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Xe}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Xe})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$e,onChange:ft=>Ce(ft.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Is,{children:[s.jsx(ve,{type:"button",onClick:()=>Pe(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{type:"button",onClick:()=>{Pe(!1),Et($e)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),it?s.jsx(Ib,{session:xe,open:qe,onOpenChange:Ze}):null]},ne.id)}const lP=o.memo(oP,iP);function cP(t){const e=st.c(71),{t:n}=ct(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:l,onConfirm:u}=t;let d,f,m,c,p,g,h,x,w,b;if(e[0]!==a||e[1]!==n||e[2]!==r){const K=n("sessions.sidebar.session.untitled");c=ls,w=!!r,e[13]!==a?(b=oe=>{oe||a(null)},e[13]=a,e[14]=b):b=e[14],m=os,h=!1,x="max-w-sm gap-5",f=bs;let $;e[15]!==n||e[16]!==r?.archivedBucket?($=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=$):$=e[17],e[18]!==$?(g=s.jsx(hs,{children:$}),e[18]=$,e[19]=g):g=e[19],d=Ss,p=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||K,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||K,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||K,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||K,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||K}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||K}),e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=f,e[5]=m,e[6]=c,e[7]=p,e[8]=g,e[9]=h,e[10]=x,e[11]=w,e[12]=b}else d=e[3],f=e[4],m=e[5],c=e[6],p=e[7],g=e[8],h=e[9],x=e[10],w=e[11],b=e[12];let y;e[20]!==d||e[21]!==p?(y=s.jsx(d,{children:p}),e[20]=d,e[21]=p,e[22]=y):y=e[22];let v;e[23]!==f||e[24]!==g||e[25]!==y?(v=s.jsxs(f,{children:[g,y]}),e[23]=f,e[24]=g,e[25]=y,e[26]=v):v=e[26];let S;e[27]!==l||e[28]!==i?(S=()=>l(!i),e[27]=l,e[28]=i,e[29]=S):S=e[29];const I=!i;let j;e[30]!==i?(j=i?s.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=j):j=e[31];let N;e[32]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=N):N=e[33];let P;e[34]!==j||e[35]!==N||e[36]!==S||e[37]!==I?(P=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":I,children:[j,N]}),e[34]=j,e[35]=N,e[36]=S,e[37]=I,e[38]=P):P=e[38];let M;e[39]!==a?(M=()=>a(null),e[39]=a,e[40]=M):M=e[40];let T;e[41]!==n?(T=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=T):T=e[42];let E;e[43]!==M||e[44]!==T?(E=s.jsx("button",{type:"button",onClick:M,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:T}),e[43]=M,e[44]=T,e[45]=E):E=e[45];let k;e[46]!==u?(k=()=>{u()},e[46]=u,e[47]=k):k=e[47];let C;e[48]!==n||e[49]!==r?.archivedBucket?(C=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=C):C=e[50];let A;e[51]!==k||e[52]!==C?(A=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:C}),e[51]=k,e[52]=C,e[53]=A):A=e[53];let F;e[54]!==E||e[55]!==A?(F=s.jsxs("div",{className:"flex items-center gap-2",children:[E,A]}),e[54]=E,e[55]=A,e[56]=F):F=e[56];let _;e[57]!==P||e[58]!==F?(_=s.jsxs(Is,{className:"w-full sm:items-center sm:justify-between",children:[P,F]}),e[57]=P,e[58]=F,e[59]=_):_=e[59];let O;e[60]!==m||e[61]!==h||e[62]!==_||e[63]!==x||e[64]!==v?(O=s.jsxs(m,{showCloseButton:h,className:x,children:[v,_]}),e[60]=m,e[61]=h,e[62]=_,e[63]=x,e[64]=v,e[65]=O):O=e[65];let V;return e[66]!==c||e[67]!==O||e[68]!==w||e[69]!==b?(V=s.jsx(c,{open:w,onOpenChange:b,children:O}),e[66]=c,e[67]=O,e[68]=w,e[69]=b,e[70]=V):V=e[70],V}function dP(t){const e=st.c(57),{t:n}=ct(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:l,onConfirm:u}=t,d=r?.archivedBucket===!0,f=r?.sessionCount??0;let m;e[0]!==d||e[1]!==f||e[2]!==n?(m=n(d?f===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":f===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=f,e[2]=n,e[3]=m):m=e[3];const c=m;let p;e[4]!==d||e[5]!==f||e[6]!==n?(p=d?f===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:f}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:f}):f===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:f}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:f}),e[4]=d,e[5]=f,e[6]=n,e[7]=p):p=e[7];const g=p,h=!!r;let x;e[8]!==a?(x=V=>{V||a(null)},e[8]=a,e[9]=x):x=e[9];let w;e[10]!==c?(w=s.jsx(hs,{children:c}),e[10]=c,e[11]=w):w=e[11];let b;e[12]!==g?(b=s.jsx(Ss,{children:g}),e[12]=g,e[13]=b):b=e[13];let y;e[14]!==w||e[15]!==b?(y=s.jsxs(bs,{children:[w,b]}),e[14]=w,e[15]=b,e[16]=y):y=e[16];let v;e[17]!==l||e[18]!==i?(v=()=>l(!i),e[17]=l,e[18]=i,e[19]=v):v=e[19];const S=!i;let I;e[20]!==i?(I=i?s.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=I):I=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let N;e[24]!==j||e[25]!==v||e[26]!==S||e[27]!==I?(N=s.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":S,children:[I,j]}),e[24]=j,e[25]=v,e[26]=S,e[27]=I,e[28]=N):N=e[28];let P;e[29]!==a?(P=()=>a(null),e[29]=a,e[30]=P):P=e[30];let M;e[31]!==n?(M=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=M):M=e[32];let T;e[33]!==P||e[34]!==M?(T=s.jsx("button",{type:"button",onClick:P,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:M}),e[33]=P,e[34]=M,e[35]=T):T=e[35];let E;e[36]!==u?(E=()=>{u()},e[36]=u,e[37]=E):E=e[37];let k;e[38]!==d||e[39]!==n?(k=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=k):k=e[40];let C;e[41]!==E||e[42]!==k?(C=s.jsx("button",{type:"button",onClick:E,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:k}),e[41]=E,e[42]=k,e[43]=C):C=e[43];let A;e[44]!==T||e[45]!==C?(A=s.jsxs("div",{className:"flex items-center gap-2",children:[T,C]}),e[44]=T,e[45]=C,e[46]=A):A=e[46];let F;e[47]!==N||e[48]!==A?(F=s.jsxs(Is,{className:"w-full sm:items-center sm:justify-between",children:[N,A]}),e[47]=N,e[48]=A,e[49]=F):F=e[49];let _;e[50]!==F||e[51]!==y?(_=s.jsxs(os,{showCloseButton:!1,className:"max-w-sm gap-5",children:[y,F]}),e[50]=F,e[51]=y,e[52]=_):_=e[52];let O;return e[53]!==h||e[54]!==_||e[55]!==x?(O=s.jsx(ls,{open:h,onOpenChange:x,children:_}),e[53]=h,e[54]=_,e[55]=x,e[56]=O):O=e[56],O}function uP(t){const e=st.c(36),{t:n}=ct(),{value:r,setValue:a,onConfirm:i}=t,l=!!r;let u;e[0]!==a?(u=I=>{I||a(null)},e[0]=a,e[1]=u):u=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let f;e[4]!==d?(f=s.jsx(hs,{children:d}),e[4]=d,e[5]=f):f=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 c;e[9]!==m?(c=s.jsx(Ss,{children:m}),e[9]=m,e[10]=c):c=e[10];let p;e[11]!==f||e[12]!==c?(p=s.jsxs(bs,{children:[f,c]}),e[11]=f,e[12]=c,e[13]=p):p=e[13];let g;e[14]!==a?(g=()=>a(null),e[14]=a,e[15]=g):g=e[15];let h;e[16]!==n?(h=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=h):h=e[17];let x;e[18]!==g||e[19]!==h?(x=s.jsx("button",{type:"button",onClick:g,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]=g,e[19]=h,e[20]=x):x=e[20];let w;e[21]!==n?(w=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=w):w=e[22];let b;e[23]!==i||e[24]!==w?(b=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:w}),e[23]=i,e[24]=w,e[25]=b):b=e[25];let y;e[26]!==b||e[27]!==x?(y=s.jsxs(Is,{children:[x,b]}),e[26]=b,e[27]=x,e[28]=y):y=e[28];let v;e[29]!==y||e[30]!==p?(v=s.jsxs(os,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,y]}),e[29]=y,e[30]=p,e[31]=v):v=e[31];let S;return e[32]!==l||e[33]!==u||e[34]!==v?(S=s.jsx(ls,{open:l,onOpenChange:u,children:v}),e[32]=l,e[33]=u,e[34]=v,e[35]=S):S=e[35],S}const mP=t=>{const e=st.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:l,onCreateFolderAndMove:u,onRemoveFromFolder:d,canRemoveFromFolder:f,onDelete:m,onDone:c}=t,{t:p}=ct(),g=!!r&&!i;let h;e[0]!==i||e[1]!==p?(h=p(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=p,e[2]=h):h=e[2];const x=h;let w;e[3]!==n||e[4]!==p?(w=p("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=p,e[5]=w):w=e[5];let b;e[6]!==w?(b=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:w}),e[6]=w,e[7]=b):b=e[7];let y;e[8]!==g||e[9]!==f||e[10]!==u||e[11]!==l||e[12]!==d||e[13]!==a||e[14]!==p?(y=g?s.jsxs(ys,{children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(vs,{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":p("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(D,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Rt,{side:"top",sideOffset:4,children:s.jsx("p",{children:p("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(ws,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx(vt,{disabled:!0,className:"text-muted-foreground",children:p("sessions.sidebar.folders.none")}):a.map(_=>s.jsx(vt,{onClick:()=>l(_.id),children:s.jsx("span",{className:"flex-1 truncate",children:_.name})},_.id)),s.jsx(Ys,{}),s.jsxs(vt,{onClick:u,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.newFolderEllipsis")]}),f?s.jsxs(vt,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"close",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=g,e[9]=f,e[10]=u,e[11]=l,e[12]=d,e[13]=a,e[14]=p,e[15]=y):y=e[15];let v;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=de("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=v):v=e[16];let S;e[17]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(D,{name:"delete-bin",className:"h-4 w-4"}),e[17]=S):S=e[17];let I;e[18]!==x||e[19]!==m?(I=s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:v,"aria-label":x,children:S})}),e[18]=x,e[19]=m,e[20]=I):I=e[20];let j;e[21]!==x?(j=s.jsx(Rt,{side:"top",sideOffset:4,children:s.jsx("p",{children:x})}),e[21]=x,e[22]=j):j=e[22];let N;e[23]!==I||e[24]!==j?(N=s.jsxs(Tt,{children:[I,j]}),e[23]=I,e[24]=j,e[25]=N):N=e[25];let P;e[26]!==p?(P=p("sessions.sidebar.header.actions.exitSelection"),e[26]=p,e[27]=P):P=e[27];let M;e[28]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(D,{name:"close",className:"h-4 w-4"}),e[28]=M):M=e[28];let T;e[29]!==c||e[30]!==P?(T=s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,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":P,children:M})}),e[29]=c,e[30]=P,e[31]=T):T=e[31];let E;e[32]!==p?(E=p("sessions.sidebar.header.actions.exitSelection"),e[32]=p,e[33]=E):E=e[33];let k;e[34]!==E?(k=s.jsx(Rt,{side:"top",sideOffset:4,children:s.jsx("p",{children:E})}),e[34]=E,e[35]=k):k=e[35];let C;e[36]!==T||e[37]!==k?(C=s.jsxs(Tt,{children:[T,k]}),e[36]=T,e[37]=k,e[38]=C):C=e[38];let A;e[39]!==C||e[40]!==y||e[41]!==N?(A=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[y,N,C]}),e[39]=C,e[40]=y,e[41]=N,e[42]=A):A=e[42];let F;return e[43]!==A||e[44]!==b?(F=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[b,A]}),e[43]=A,e[44]=b,e[45]=F):F=e[45],F},_h="oc.sessions.activeNow",pP=2160*60*1e3,zh=t=>!!t.parentID,wd=t=>!!t.time?.archived,Hc=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},fP=t=>{try{const e=t.getItem(_h);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,a=[];return n.forEach(i=>{const l=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!l||r.has(l)||(r.add(l),a.push({sessionId:l}))}),a}catch{return[]}},dc=(t,e)=>{try{t.setItem(_h,JSON.stringify(e))}catch{}},hP=(t,e,n=Date.now())=>{const r=n-pP;return t.filter(a=>{const i=e.get(a.sessionId);return i?wd(i)?!1:Hc(i)>=r:!0})},gP=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],Bh=t=>[...t].sort((e,n)=>Hc(n)-Hc(e)),xP=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!wd(r)).filter(r=>!zh(r));return Bh(n)},bP=(t,e)=>{const n=t.filter(r=>{if(wd(r)||zh(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return Bh(n)},go=Vr(),uc=vn((t,e)=>({entries:fP(go),setEntries:n=>{n!==e().entries&&(t({entries:n}),dc(go,n))},addSession:n=>{const r=gP(e().entries,n);r!==e().entries&&(t({entries:r}),dc(go,r))},prune:n=>{const r=e().entries,a=hP(r,n);a.length===r.length&&a.every((i,l)=>i.sessionId===r[l]?.sessionId)||(t({entries:a}),dc(go,a))}})),xo="oc.sessions.projectCollapse",jp="oc.sessions.groupOrder",Np="oc.sessions.groupCollapse",Sp="oc.sessions.activeSessionByProject",mc="oc.sessions.expandedParents.v2",yP="oc.sessions.expandedParents",vP="oc.sessions.pinned",wP=(t,e)=>{const n=new Set;for(const r of t){const a=Zt(r.path)?.toLowerCase();a&&n.add(a)}for(const r of e.values())for(const a of r){const i=Zt(a.path)?.toLowerCase();i&&n.add(i)}return n},jP=(t,e)=>{if(t.time?.archived)return!0;const n=Zt(So(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},NP=5*6e4,kp=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=ct(),[l,u]=o.useState(!1),[d,f]=o.useState(""),m=o.useRef(null),c=o.useRef(null),p=o.useRef(new Set),[g,h]=o.useState(null),[x,w]=o.useState(""),[b,y]=o.useState(null),[v,S]=o.useState(new Set),[I]=o.useState(()=>new Map),j=o.useMemo(()=>Vr(),[]),N=uc(Re=>Re.entries),P=uc(Re=>Re.addSession),M=uc(Re=>Re.prune),[T,E]=o.useState(new Set),[k,C]=o.useState(new Map),[A,F]=o.useState(new Set),[_,O]=o.useState(!1),[V,K]=o.useState(null),[$,oe]=o.useState(null),[L,Y]=o.useState(""),[ee,re]=o.useState(null),[fe,ge]=o.useState(null),[be,z]=o.useState(null),B=zl(Re=>Re.ids),Q=zl(Re=>Re.setIds),X=zl(Re=>Re.toggle),[ie,le]=o.useState(()=>{try{const Re=Vr().getItem(Np);if(!Re)return new Set;const pt=JSON.parse(Re);return new Set(Array.isArray(pt)?pt.filter(lt=>typeof lt=="string"):[])}catch{return new Set}}),[ye,W]=o.useState(()=>{try{const Re=Vr().getItem(jp);if(!Re)return new Map;const pt=JSON.parse(Re),lt=new Map;return Object.entries(pt).forEach(([Dt,qt])=>{Array.isArray(qt)&&lt.set(Dt,qt.filter(Rs=>typeof Rs=="string"))}),lt}catch{return new Map}}),[ue,ae]=o.useState(()=>{try{const Re=Vr().getItem(Sp);if(!Re)return new Map;const pt=JSON.parse(Re),lt=new Map;return Object.entries(pt).forEach(([Dt,qt])=>{typeof qt=="string"&&qt.length>0&&lt.set(Dt,qt)}),lt}catch{return new Map}}),[U,G]=o.useState(new Map),ne=o.useRef(new Map),se=o.useRef(0),xe=Ns(Re=>Re.homeDirectory),Se=Ns(Re=>Re.currentDirectory),je=Ns(Re=>Re.setDirectory),Ie=es(Re=>Re.projects),Oe=es(Re=>Re.activeProjectId),Ne=es(Re=>Re.removeProject),he=es(Re=>Re.setActiveProjectIdOnly),Fe=es(Re=>Re.updateProjectMeta),Be=es(Re=>Re.reorderProjects),q=De(Re=>Re.setActiveMainTab),Pe=De(Re=>Re.openContextPanelTab),$e=De(Re=>Re.setSessionSwitcherOpen),Ce=De(Re=>Re.toggleSidebar),pe=De(Re=>Re.notifyOnSubtasks),R=De(Re=>Re.showDeletionDialog),J=De(Re=>Re.setShowDeletionDialog),H=dl(d,120),Ee=o.useMemo(()=>H.trim().toLowerCase(),[H]),Ae=Ee.length>0,Je=Pn(Re=>Re.collapsedFolderIds),ce=Pn(Re=>Re.foldersMap),_e=Pn(Re=>Re.getFoldersForScope),et=Pn(Re=>Re.createFolder),Me=Pn(Re=>Re.renameFolder),He=Pn(Re=>Re.deleteFolder),We=Pn(Re=>Re.addSessionToFolder),Te=Pn(Re=>Re.addSessionsToFolder),Ve=Pn(Re=>Re.removeSessionFromFolder),Ye=Pn(Re=>Re.removeSessionsFromFolders),Ge=Pn(Re=>Re.toggleFolderCollapse),me=Pn(Re=>Re.cleanupSessions),Ke=Pn(Re=>Re.getSessionFolderId);DC({isSessionSearchOpen:l,setIsSessionSearchOpen:u,sessionSearchInputRef:c,sessionSearchContainerRef:m});const ze=gf(),tt=ld(),it=Jp(),qe=Tb(),Ze=bi(Re=>Re.hasLoaded),Xe=bi(Re=>Re.activeSessions),mt=bi(Re=>Re.archivedSessions),wt=Ft(Re=>Re.currentSessionId),Et=Ft(Re=>!!Re.newSessionDraft?.open),dt=Ft(Re=>Re.setCurrentSession),gt=Ft(Re=>Re.updateSessionTitle),Wt=Ft(Re=>Re.shareSession),Ot=Ft(Re=>Re.unshareSession),Bt=Ft(Re=>Re.worktreeMetadata),rt=Ft(Re=>Re.availableWorktreesByProject),It=Ft(Re=>Re.openNewSessionDraft),$t=o.useMemo(()=>wP(Ie,rt),[rt,Ie]),Ut=o.useMemo(()=>{const Re=new Map(it.map(Dt=>[Dt.id,Dt])),pt=Xe.map(Dt=>Re.get(Dt.id)??Dt),lt=new Set(pt.map(Dt=>Dt.id));return it.forEach(Dt=>{lt.has(Dt.id)||pt.push(Dt)}),pt.filter(Dt=>jP(Dt,$t))},[Xe,$t,it]),ms=o.useMemo(()=>it.map(Re=>{const pt=Zt(Re.directory??null)??"";return`${Re.id}:${Re.title??""}:${Re.time?.archived?1:0}:${pt}`}).join("|"),[it]),ns=o.useRef(it);o.useEffect(()=>{ns.current=it},[ms,it]),o.useEffect(()=>{let Re=!1;const pt=async()=>{const lt=es.getState().projects;if(lt.length===0)return;const Dt=new Map,qt=[];await Promise.all(lt.map(async Rs=>{const en=Zt(Rs.path);if(en)try{if(!(yn.getState().directories.get(en)?.isGitRepo??await Qn(()=>import("./modelPrefsAutoSave-DEc6o6vH.js").then(tn=>tn.fc),__vite__mapDeps([3,0,1,4,5])).then(tn=>tn.checkIsGitRepository(en))))return;const Gs=await wc({id:Rs.id,path:en});if(Re||Gs.length===0)return;Dt.set(en,Gs),qt.push(...Gs)}catch{}})),!Re&&Ft.setState({availableWorktrees:qt,availableWorktreesByProject:Dt})};return jc(ns.current),pt(),()=>{Re=!0}},[Se,ms,Ie]),o.useEffect(()=>{let Re=null;const pt=Lh(lt=>{lt.type==="scheduled-task-ran"&&(Re&&clearTimeout(Re),Re=setTimeout(()=>{jc(ns.current)},500))});return()=>{Re&&clearTimeout(Re),pt()}},[]);const Vt=o.useMemo(()=>Us(),[]),Ue=ol(),[kt,Mt]=o.useState(!1),ut=o.useMemo(()=>Ks(),[]),{isTablet:Kt}=_s(),Yt=t||Kt,ks=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Cs=!t&&!ut&&!Vt,Fs=!t&&!ut&&!Cs,Ls=Vt&&ks&&!kt||Ue?"pl-[5.5rem]":"pl-3",dn="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";o.useEffect(()=>{if(!Vt||!ks){Mt(!1);return}let Re=!1,pt=null;const lt=async()=>{try{const qt=await Mb();Re||Mt(qt)}catch{Re||Mt(!1)}},Dt=async()=>{try{pt=Rb(()=>{lt()})}catch{}};return lt(),Dt(),()=>{Re=!0,pt&&pt()}},[Vt,ks]);const ft=o.useCallback(async Re=>{const pt=Re.target;pt.closest(".app-region-no-drag")||pt.closest("button, a, input, select, textarea")||Re.button===0&&Vt&&await Cf()},[Vt]),{buildGroupSearchText:Es,filterSessionNodesForSearch:is,buildGroupedSessions:Z}=IC({homeDirectory:xe,worktreeMetadata:Bt,pinnedSessionIds:B,gitBranches:ze,isVSCode:ut}),{scheduleCollapsedProjectsPersist:yt}=LC({isVSCode:ut,hasLoadedGlobalSessions:Ze,safeStorage:j,keys:{sessionExpanded:mc,sessionExpandedLegacy:yP,projectCollapse:xo,sessionPinned:vP,groupOrder:jp,projectActiveSession:Sp,groupCollapse:Np},sessions:Ut,setPinnedSessionIds:Q,groupOrderByProject:ye,activeSessionByProject:ue,collapsedGroups:ie,setExpandedParents:S,setCollapsedProjects:E}),_t=o.useMemo(()=>[...Ut].sort((Re,pt)=>Fa(Re,pt,B)),[Ut,B]),gs=o.useMemo(()=>new Map(_t.map((Re,pt)=>[Re.id,pt])),[_t]),Ps=o.useMemo(()=>{const Re=new Map;return _t.forEach(pt=>{const lt=pt.parentID;if(!lt)return;const Dt=Re.get(lt)??[];Dt.push(pt),Re.set(lt,Dt)}),Re.forEach(pt=>pt.sort((lt,Dt)=>Fa(lt,Dt,B))),Re},[_t,B]),Ws=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noSessions.description")})]}),Ms=o.useMemo(()=>Ie.find(Re=>Re.id===b)??null,[Ie,b]),En=o.useCallback(Re=>{b&&(Fe(b,Re),y(null))},[b,Fe]),Mn=o.useCallback(()=>{O(!0)},[]),Jn=Ft(Re=>Re.deleteSession),Js=Ft(Re=>Re.deleteSessions),jn=Ft(Re=>Re.archiveSession),Xs=Ft(Re=>Re.archiveSessions),{copiedSessionId:Nn,handleSessionSelect:Sn,handleSessionDoubleClick:Rn,handleSaveEdit:Fn,handleCancelEdit:un,handleShareSession:Bn,handleCopyShareUrl:Nt,handleUnshareSession:Lt,handleDeleteSession:Gt,confirmDeleteSession:we}=TC({activeProjectId:Oe,currentDirectory:Se,currentSessionId:wt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:l,sessionSearchQuery:d,setSessionSearchQuery:f,setIsSessionSearchOpen:u,setActiveProjectIdOnly:he,setDirectory:je,setActiveMainTab:q,setSessionSwitcherOpen:$e,setCurrentSession:dt,updateSessionTitle:gt,shareSession:Wt,unshareSession:Ot,deleteSession:Jn,deleteSessions:Js,archiveSession:jn,archiveSessions:Xs,childrenMap:Ps,showDeletionDialog:R,setDeleteSessionConfirm:re,deleteSessionConfirm:ee,setEditingId:h,setEditTitle:w,editingId:g,editTitle:x}),at=o.useCallback(()=>{if(!fe)return;const{scopeKey:Re,folderId:pt}=fe;ge(null),He(Re,pt)},[fe,He]);o.useEffect(()=>{if(!wt)return;const pt=Ut.find(Dt=>Dt.id===wt)?.parentID;if(!pt)return;const lt=[`project:active:${pt}`,`project:archived:${pt}`,`recent:active:${pt}`,`recent:archived:${pt}`];S(Dt=>{if(lt.every(Rs=>Dt.has(Rs)))return Dt;const qt=new Set(Dt);lt.forEach(Rs=>qt.add(Rs));try{j.setItem(mc,JSON.stringify(Array.from(qt)))}catch{}return qt})},[wt,Ut,j]);const bt=o.useCallback(Re=>{S(pt=>{const lt=new Set(pt);lt.has(Re)?lt.delete(Re):lt.add(Re);try{j.setItem(mc,JSON.stringify(Array.from(lt)))}catch{}return lt})},[j]),Pt=o.useCallback((Re,pt)=>{if(!Re)return null;pt&&Je.has(pt)&&Ge(pt);const lt=et(Re,i("sessions.sidebar.folder.newFolderName"),pt);return oe(lt.id),Y(lt.name),lt},[Je,Ge,et,i]),Ht=o.useCallback(Re=>{F(pt=>{const lt=new Set(pt);return lt.has(Re)?lt.delete(Re):lt.add(Re),lt})},[]),xs=o.useCallback(()=>{se.current=Date.now()+150,E(()=>{const Re=new Set(Ie.map(pt=>pt.id));try{j.setItem(xo,JSON.stringify(Array.from(Re)))}catch{}return ut||yt(Re),Re})},[Ie,ut,j,yt]),cs=o.useCallback(()=>{se.current=Date.now()+150,E(()=>{const Re=new Set;try{j.setItem(xo,JSON.stringify([]))}catch{}return ut||yt(Re),Re})},[ut,j,yt]),ds=o.useCallback(Re=>{se.current=Date.now()+150,E(pt=>{const lt=new Set(pt);lt.has(Re)?lt.delete(Re):lt.add(Re);try{j.setItem(xo,JSON.stringify(Array.from(lt)))}catch{}return ut||yt(lt),lt})},[ut,j,yt]),us=o.useMemo(()=>Ie.map(Re=>({...Re,normalizedPath:Zt(Re.path)})).filter(Re=>!!Re.normalizedPath),[Ie]),rn=o.useMemo(()=>us.map(Re=>Re.normalizedPath),[us]),{github:an}=wn(),mn=zn(Re=>Re.status),pn=zn(Re=>Re.hasChecked),zs=Ab(rn),Qs=Ea(Re=>Re.ensureEntry),on=Ea(Re=>Re.setParams),$s=Ea(Re=>Re.refreshTargets);$C({normalizedProjects:us,gitRepoStatus:zs,setProjectRepoStatus:C,setProjectRootBranches:G});const Ln=Ft(Re=>Re.isLoading);GC({isSessionsLoading:Ln,sessions:Ut,archivedSessions:mt,normalizedProjects:us,isVSCode:ut,availableWorktreesByProject:rt,cleanupSessions:me});const{getSessionsForProject:fn,getArchivedSessionsForProject:mr}=VC({isVSCode:ut,sessions:Ut,archivedSessions:mt,availableWorktreesByProject:rt});vC({normalizedProjects:us,sessions:Ut,archivedSessions:mt,availableWorktreesByProject:rt,isVSCode:ut,isSessionsLoading:Ln,foldersMap:ce,createFolder:et,addSessionToFolder:We,cleanupSessions:me});const ar=o.useRef(!1);Oe&&k.has(Oe)&&(ar.current=!!k.get(Oe));const{projectSections:kn,groupSearchDataByGroup:Ja,sectionsForRender:ma,searchMatchCount:Wi}=NC({normalizedProjects:us,getSessionsForProject:fn,getArchivedSessionsForProject:mr,availableWorktreesByProject:rt,projectRepoStatus:k,projectRootBranches:U,lastRepoStatus:ar.current,buildGroupedSessions:Z,hasSessionSearchQuery:Ae,normalizedSessionSearchQuery:Ee,filterSessionNodesForSearch:is,buildGroupSearchText:Es,foldersMap:ce}),Hi=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noMatches.description")})]}),Gi=!0,{currentSessionDirectory:Cn}=kC({projectSections:kn,activeProjectId:Oe,activeSessionByProject:ue,setActiveSessionByProject:ae,currentSessionId:wt,handleSessionSelect:Sn,newSessionDraftOpen:Et,mobileVariant:t,openNewSessionDraft:It,setActiveMainTab:q,setSessionSwitcherOpen:$e,sessions:Ut,worktreeMetadata:Bt}),{getOrderedGroups:Xa}=CC(ye),Xn=o.useRef(!1);o.useEffect(()=>{if(Xn.current||kn.length===0)return;const Re=kn.flatMap(pt=>pt.groups.filter(lt=>lt.isArchivedBucket).map(lt=>`${pt.project.id}:${lt.id}`));Re.length>0&&le(pt=>new Set([...pt,...Re])),Xn.current=!0},[kn]);const Za=o.useMemo(()=>{const Re=new Map,pt=new Map;return kn.forEach(lt=>{const Dt=Sf(lt.project.label?.trim()||ca(lt.project.normalizedPath,xe)||lt.project.normalizedPath);lt.groups.forEach(qt=>{const Rs=qt.branch&&qt.branch!=="HEAD"&&qt.branch!==Dt?qt.branch:null,en={projectLabel:Dt,branchLabel:Rs},ir=Un=>{Un.forEach(Gs=>{const tn=lt.project.normalizedPath.length,Cr=pt.get(Gs.session.id)??-1;tn<Cr||(Re.set(Gs.session.id,{node:Gs,projectId:lt.project.id,groupDirectory:qt.directory,secondaryMeta:en}),pt.set(Gs.session.id,tn),Gs.children.length>0&&ir(Gs.children))})};ir(qt.sessions)})}),Re},[kn,xe]),On=ra(Re=>Re.showRecentSection),pa=o.useMemo(()=>On?xP(N,new Map(Ut.map(Re=>[Re.id,Re]))).sort((Re,pt)=>Fa(Re,pt,B)):[],[N,B,Ut,On]),fa=o.useMemo(()=>On?bP(Ut,qe):[],[qe,Ut,On]);o.useEffect(()=>{!On||fa.length===0||fa.forEach(Re=>P(Re.id))},[P,fa,On]),o.useEffect(()=>{if(!On)return;const Re=new Map;[...Ut,...mt].forEach(pt=>{Re.set(pt.id,pt)}),M(Re)},[mt,M,Ut,On]);const Rr=o.useMemo(()=>{if(!On)return[];const Re=pt=>{const lt=Za.get(pt.id),Dt=Zt(pt.directory??null);return{node:lt?.node??{session:pt,children:[],worktree:null},projectId:lt?.projectId??null,groupDirectory:lt?.groupDirectory??Dt,secondaryMeta:lt?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:pa.map(Re)}]},[pa,Za,On,i]),Nr=o.useMemo(()=>new Set(pa.map(Re=>Re.id)),[pa]),hn=o.useMemo(()=>[...Nr],[Nr]);$5({currentSessionId:wt,sortedSessions:_t,recentSessionIds:hn,ensureSessionRenderable:tt.ensureSessionRenderable});const Vn=o.useMemo(()=>{if(!ut||Ae||Nr.size===0)return ma;const Re=pt=>pt.reduce((lt,Dt)=>{if(Nr.has(Dt.session.id))return lt;const qt=Re(Dt.children);return qt.length===Dt.children.length?(lt.push(Dt),lt):(lt.push({...Dt,children:qt}),lt)},[]);return ma.map(pt=>({...pt,groups:pt.groups.map(lt=>({...lt,sessions:Re(lt.sessions)}))}))},[ut,Ae,Nr,ma]),vl=o.useMemo(()=>{const Re=new Set;return Vn.forEach(pt=>{pt.groups.forEach(lt=>{const Dt=Zt(lt.directory??null),qt=lt.branch?.trim()||ze.get(Dt||"")?.trim();!Dt||!qt||Re.add(Lo(Dt,qt))})}),[...Re]},[ze,Vn]),ei=g4(vl);o.useEffect(()=>{if(!pn||!mn?.connected||!an)return;const Re=[],pt=Date.now();if(Vn.forEach(Dt=>{T.has(Dt.project.id)||Dt.groups.forEach(qt=>{const Rs=Zt(qt.directory??null),en=qt.branch?.trim()||ze.get(Rs||"")?.trim();if(!Rs||!en)return;const ir=Lo(Rs,en),Un=Ea.getState().entries[ir],Gs=!!Un?.status?.pr,tn=`${Rs}::${en}`,Cr=Math.max(Un?.lastRefreshAt??0,Un?.lastDiscoveryPollAt??0),$r=!!(Un?.isInitialStatusResolved&&!Gs&&(!p.current.has(tn)||pt-Cr>=NP));(!Un||!Un.isInitialStatusResolved||$r)&&($r&&p.current.add(tn),Re.push({directory:Rs,branch:en}))})}),Re.length===0)return;const lt=new Map;Re.forEach(Dt=>{const qt=Lo(Dt.directory,Dt.branch,Dt.remoteName??null);lt.has(qt)||lt.set(qt,Dt)}),lt.forEach((Dt,qt)=>{Qs(qt),on(qt,{directory:Dt.directory,branch:Dt.branch,remoteName:Dt.remoteName??null,canShow:!0,github:an,githubAuthChecked:pn,githubConnected:mn.connected})}),$s([...lt.values()],{force:!0,silent:!0,markInitialResolved:!0})},[T,Qs,an,pn,mn?.connected,ze,$s,Vn,on]);const Zs=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",qi="h-4.5 w-4.5",jl=JC({isDesktopShellRuntime:Vt,projectSections:kn,projectHeaderSentinelRefs:ne}),ha=o.useCallback((Re,pt=0,lt,Dt,qt=!1,Rs,en="project")=>s.jsx(lP,{node:Re,depth:pt,groupDirectory:lt,projectId:Dt,archivedBucket:qt,directoryStatus:I,currentSessionId:wt,pinnedSessionIds:B,expandedParents:v,hasSessionSearchQuery:Ae,normalizedSessionSearchQuery:Ee,notifyOnSubtasks:pe,editingId:g,setEditingId:h,editTitle:x,setEditTitle:w,handleSaveEdit:Fn,handleCancelEdit:un,toggleParent:bt,handleSessionSelect:Sn,handleSessionDoubleClick:Rn,togglePinnedSession:X,handleShareSession:Bn,copiedSessionId:Nn,handleCopyShareUrl:Nt,handleUnshareSession:Lt,openSidebarMenuKey:V,setOpenSidebarMenuKey:K,renamingFolderId:$,getFoldersForScope:_e,getSessionFolderId:Ke,removeSessionFromFolder:Ve,addSessionToFolder:We,createFolderAndStartRename:Pt,openContextPanelTab:Pe,handleDeleteSession:Gt,mobileVariant:t,alwaysShowActions:Yt,renderSessionNode:ha,secondaryMeta:Rs,renderContext:en}),[I,wt,B,v,Ae,Ee,pe,g,h,x,w,Fn,un,bt,Sn,Rn,X,Bn,Nn,Nt,Lt,V,K,$,_e,Ke,Ve,We,Pt,Pe,Gt,t,Yt]),si=o.useCallback(Re=>{le(pt=>{const lt=new Set(pt);return lt.has(Re)?lt.delete(Re):lt.add(Re),lt})},[]),Yi=o.useMemo(()=>{const Re=new Map;for(const[pt,lt]of ei)Re.set(pt,{visualState:lt.visualState,number:lt.number,url:lt.url,state:lt.prState,draft:lt.draft,title:lt.title,base:lt.base,head:lt.head,checks:lt.checks,canMerge:lt.canMerge,mergeableState:lt.mergeableState,repo:lt.repo});return Re},[ei]),Nl=o.useCallback((Re,pt,lt,Dt,qt,Rs)=>s.jsx(R4,{group:Re,groupKey:pt,projectId:lt,hideGroupLabel:Dt,compactBodyPadding:Rs,hasSessionSearchQuery:Ae,normalizedSessionSearchQuery:Ee,groupSearchDataByGroup:Ja,expandedSessionGroups:A,collapsedGroups:ie,hideDirectoryControls:r,collapsedFolderIds:Je,toggleFolderCollapse:Ge,renameFolder:Me,deleteFolder:He,showDeletionDialog:R,setDeleteFolderConfirm:ge,renderSessionNode:ha,currentSessionDirectory:Cn,projectRepoStatus:k,lastRepoStatus:ar.current,toggleGroupSessionLimit:Ht,mobileVariant:t,alwaysShowActions:Yt,activeProjectId:Oe,setActiveProjectIdOnly:he,setActiveMainTab:q,setSessionSwitcherOpen:$e,openNewSessionDraft:It,addSessionToFolder:We,createFolderAndStartRename:Pt,renamingFolderId:$,renameFolderDraft:L,setRenameFolderDraft:Y,setRenamingFolderId:oe,pinnedSessionIds:B,sessionOrderIndex:gs,prVisualStateByDirectoryBranch:Yi,onToggleCollapsedGroup:si,dragHandleProps:qt}),[Ae,Ee,Ja,A,ie,r,Je,Ge,Me,He,R,ha,Cn,k,Ht,t,Yt,Oe,he,q,$e,It,We,Pt,$,L,B,gs,Yi,si]),Sl=On&&!Ae?s.jsx(B4,{sections:Rr,renderSessionNode:ha}):null,ni=!!($||g||b),Hr=Gn(Re=>Re.enabled),js=Gn(Re=>Re.selectedIds),Sr=Gn(Re=>Re.scopeKey),pr=Gn,Fr=o.useCallback(()=>{Gn.getState().toggleMode()},[]),Lr=o.useCallback(()=>{Gn.getState().disable()},[]),fr=o.useMemo(()=>{if(js.size===0||typeof document>"u")return!1;let Re=!1,pt=!1;for(const lt of js){const Dt=document.querySelectorAll(`[data-session-row="${CSS.escape(lt)}"]`);for(const qt of Dt)qt.getAttribute("data-session-archived")==="1"?pt=!0:Re=!0}return pt&&!Re},[js]),Hs=o.useMemo(()=>{if(Sr)return Sr;if(js.size===0||typeof document>"u")return null;for(const Re of js){const lt=document.querySelector(`[data-session-row="${CSS.escape(Re)}"]`)?.getAttribute("data-session-scope");if(lt&&lt.length>0)return lt}return null},[js,Sr]),Or=o.useMemo(()=>Hs?ce[Hs]??[]:[],[ce,Hs]),ga=o.useMemo(()=>{if(!Hs||js.size===0)return!1;const Re=ce[Hs]??[];for(const pt of Re)for(const lt of pt.sessionIds)if(js.has(lt))return!0;return!1},[ce,Hs,js]),kl=o.useCallback(Re=>{!Hs||js.size===0||Te(Hs,Re,Array.from(js))},[Te,js,Hs]),Cl=o.useCallback(()=>{if(!Hs||js.size===0)return;const Re=Pt(Hs);Re&&Te(Hs,Re.id,Array.from(js))},[Te,Pt,js,Hs]),$n=o.useCallback(()=>{!Hs||js.size===0||Ye(Hs,Array.from(js))},[Ye,js,Hs]),kr=o.useCallback(async()=>{const Re=Array.from(js);if(Re.length!==0){if(fr){const{deletedIds:pt,failedIds:lt}=await Js(Re);pt.length>0&&te.success(pt.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:pt.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:pt.length})),lt.length>0&&te.error(lt.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:lt.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:lt.length}))}else{const{archivedIds:pt,failedIds:lt}=await Xs(Re);pt.length>0&&te.success(pt.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:pt.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:pt.length})),lt.length>0&&te.error(lt.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:lt.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:lt.length}))}Gn.getState().clear()}},[Xs,fr,Js,js,i]),Gr=o.useCallback(()=>{const Re=js.size;if(Re!==0){if(!R){kr();return}z({sessionCount:Re,archivedBucket:fr})}},[fr,kr,js,R]),xa=o.useCallback(async()=>{z(null),await kr()},[kr]);o.useEffect(()=>{if(!Hr)return;const Re=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),pt=lt=>{if(ni)return;const Dt=lt.target;if(Dt&&(Dt.tagName==="INPUT"||Dt.tagName==="TEXTAREA"||Dt.isContentEditable))return;const qt=Re?lt.metaKey:lt.ctrlKey;if(lt.key==="Escape"){lt.preventDefault(),Gn.getState().disable();return}if(qt&&lt.key==="Backspace"){lt.preventDefault(),Gr();return}if(qt&&(lt.key==="a"||lt.key==="A")){const Rs=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Rs.length===0)return;lt.preventDefault();const ir=pr.getState().scopeKey??Rs[0]?.getAttribute("data-session-scope")??null,Un=tn=>ir?tn.getAttribute("data-session-scope")===ir:!0,Gs=Rs.filter(Un).map(tn=>tn.getAttribute("data-session-row")).filter(tn=>typeof tn=="string"&&tn.length>0);if(Gs.length===0)return;pr.getState().replaceAll(Gs,ir||null)}};return window.addEventListener("keydown",pt),()=>window.removeEventListener("keydown",pt)},[Gr,ni,pr,Hr]);const kd=o.useCallback(()=>{q("chat"),t&&$e(!1),It()},[t,It,q,$e]);return s.jsxs("div",{ref:m,className:de("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[Fs?s.jsx("div",{onMouseDown:ft,className:de("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",Ls),children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ce,className:dn,"aria-label":i("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(D,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Rt,{children:s.jsx("p",{children:i("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(F4,{hideDirectoryControls:r,handleNewSession:kd,headerActionIconClass:qi,reserveHeaderActionsSpace:Gi,headerActionButtonClass:Zs,isSessionSearchOpen:l,setIsSessionSearchOpen:u,sessionSearchInputRef:c,sessionSearchQuery:d,setSessionSearchQuery:f,hasSessionSearchQuery:Ae,searchMatchCount:Wi,collapseAllProjects:xs,expandAllProjects:cs,selectionModeEnabled:Hr,onToggleSelectionMode:Fr,showSidebarToggle:Cs,onToggleSidebar:Ce,avoidWindowControlsOverlay:Ue}),s.jsx(Y4,{topContent:Sl,sectionsForRender:Vn,projectSections:kn,activeProjectId:Oe,showOnlyMainWorkspace:a,hasSessionSearchQuery:Ae,emptyState:Ws,searchEmptyState:Hi,renderGroupSessions:Nl,homeDirectory:xe,collapsedProjects:T,hideDirectoryControls:r,projectRepoStatus:k,isDesktopShellRuntime:Vt,stuckProjectHeaders:jl,mobileVariant:t,alwaysShowActions:Yt,toggleProject:ds,setActiveProjectIdOnly:he,setActiveMainTab:q,setSessionSwitcherOpen:$e,openNewSessionDraft:It,openNewWorktreeDialog:Mn,openProjectEditDialog:y,removeProject:Ne,projectHeaderSentinelRefs:ne,reorderProjects:Be,getOrderedGroups:Xa,setGroupOrderByProject:W,openSidebarMenuKey:V,setOpenSidebarMenuKey:K,isInlineEditing:ni}),Hr&&js.size>0?s.jsx(mP,{selectedCount:js.size,scopeKey:Hs,scopeFolders:Or,archivedBucket:fr,onMoveToFolder:kl,onCreateFolderAndMove:Cl,onRemoveFromFolder:$n,canRemoveFromFolder:ga,onDelete:Gr,onDone:Lr}):null,Ms?s.jsx(Eb,{open:!!Ms,onOpenChange:Re=>{Re||y(null)},projectId:Ms.id,projectName:Ms.label||ca(Ms.path,xe),projectPath:Ms.path,initialIcon:Ms.icon,initialColor:Ms.color,initialIconBackground:Ms.iconBackground,onSave:En}):null,s.jsx(U5,{open:_,onOpenChange:O,onWorktreeCreated:(Re,pt)=>{if(q("chat"),t&&$e(!1),pt?.sessionId){dt(pt.sessionId);return}It({directoryOverride:Re})}}),s.jsx(bC,{}),s.jsx(cP,{value:ee,setValue:re,showDeletionDialog:R,setShowDeletionDialog:J,onConfirm:we}),s.jsx(uP,{value:fe,setValue:ge,onConfirm:at}),s.jsx(dP,{value:be,setValue:z,showDeletionDialog:R,setShowDeletionDialog:J,onConfirm:xa})]})},SP=()=>{const t=st.c(13),[e,n]=Le.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(Us())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),Le.useEffect(r,a);let i;t[2]!==e?(i=async p=>e?await Fb(p):{success:!0,path:p},t[2]=e,t[3]=i):i=t[3];const l=i;let u;t[4]!==e?(u=async p=>e?await Lb():{success:!0},t[4]=e,t[5]=u):u=t[5];const d=u;let f;t[6]!==e?(f=async p=>e?await Ob():{success:!0},t[6]=e,t[7]=f):f=t[7];const m=f;let c;return t[8]!==e||t[9]!==l||t[10]!==d||t[11]!==m?(c={isDesktop:e,requestAccess:l,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=l,t[10]=d,t[11]=m,t[12]=c):c=t[12],c},kP=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),CP=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:l=[],disabled:u=!1})=>{const{t:d}=ct(),[f,m]=o.useState(!1),[c,p]=o.useState(""),[g,h]=o.useState(!1),[x,w]=o.useState(!1),[b,y]=o.useState(""),[v,S]=o.useState(!1),I=o.useRef(null),j=o.useCallback(O=>{O.stopPropagation()},[]),N=l.length>1,P=o.useMemo(()=>kP(b),[b]),M=o.useMemo(()=>{const O=c.toLowerCase();return O?e.filter(V=>V.toLowerCase().includes(O)):e},[c,e]),T=o.useMemo(()=>{const O=c.toLowerCase();return O?n.filter(V=>V.toLowerCase().includes(O)):n},[c,n]),E=O=>{if(O===t){m(!1);return}a(O),m(!1),p("")},k=()=>{h(!0),setTimeout(()=>I.current?.focus(),50)},C=async()=>{if(!(!P||v)){if(N){w(!0);return}S(!0);try{await i(P,l[0]),y(""),h(!1),m(!1)}finally{S(!1)}}},A=async O=>{if(!(!P||v)){S(!0);try{await i(P,O),y(""),h(!1),w(!1),m(!1)}finally{S(!1)}}},F=()=>{w(!1)},_=()=>{y(""),h(!1),w(!1)};return o.useEffect(()=>{f||(p(""),h(!1),w(!1),y(""))},[f]),s.jsxs(ys,{open:f,onOpenChange:m,children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(vs,{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:u,children:[s.jsx(D,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:t||d("gitView.branch.detachedHead")}),s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),s.jsx(Rt,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(ws,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(Jo,{className:"h-full min-h-0",children:[s.jsx(Oi,{placeholder:d("gitView.branch.searchPlaceholder"),value:c,onValueChange:p,onKeyDown:j}),s.jsxs(Xo,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Zo,{children:d("gitView.branch.empty")}),s.jsx(qn,{children:x?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:F,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(D,{name:"arrow-left",className:"size-4"})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d("gitView.branch.pushToPrefix")," ",s.jsx("span",{className:"text-foreground font-medium",children:P})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:l.map(O=>s.jsxs("button",{type:"button",onClick:()=>A(O),disabled:v,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[v?s.jsx(D,{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))})]}):g?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:I,placeholder:d("gitView.branch.newBranchPlaceholder"),value:b,onChange:O=>y(O.target.value),onClick:O=>O.stopPropagation(),onKeyDown:O=>{j(O),O.key==="Enter"?(O.preventDefault(),C()):O.key==="Escape"&&(O.preventDefault(),_())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:C,disabled:!P||v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:v?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:_,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(D,{name:"close",className:"size-4"})})]}):s.jsxs(Dn,{onSelect:k,children:[s.jsx(D,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(Aa,{}),s.jsxs(qn,{heading:d("gitView.branch.localBranches"),children:[M.map(O=>s.jsxs(Dn,{onSelect:()=>E(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}`)),M.length===0&&s.jsx(Dn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(Aa,{}),s.jsxs(qn,{heading:d("gitView.branch.remoteBranches"),children:[T.map(O=>s.jsx(Dn,{onSelect:()=>E(O),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:O})},`remote-${O}`)),T.length===0&&s.jsx(Dn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},PP=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),IP=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=ct(),[a,i]=o.useState(!1),[l,u]=o.useState(t||""),[d,f]=o.useState(!1),m=o.useRef(null),c=()=>{!t||!e||(u(t),i(!0),setTimeout(()=>m.current?.focus(),0))},p=async()=>{if(!t||!e||!l.trim())return;const x=PP(l);if(x===t){i(!1);return}f(!0);try{await e(t,x),i(!1),u("")}finally{f(!1)}},g=()=>{i(!1),u("")},h=x=>{x.key==="Enter"?(x.preventDefault(),p()):x.key==="Escape"&&(x.preventDefault(),g())};return a?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:x=>{x.preventDefault(),p()},children:[s.jsx(D,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:l,onChange:x=>u(x.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:h,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,"aria-label":r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:g,disabled:d,"aria-label":r("gitView.branch.renameCancel"),title:r("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(D,{name:"close",className:"size-4"})})]})}):s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[s.jsx(D,{name:"git-branch",className:"size-4 text-primary shrink-0"}),s.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:t||r("gitView.branch.detachedHead")}),n&&e&&t&&s.jsx(ve,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:c,title:r("gitView.branch.renameTitle"),children:s.jsx(D,{name:"edit",className:"size-4"})})]})]})},DP=t=>{const e=st.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:l,disabled:u,removingRemoteName:d,aheadCount:f,behindCount:m,trackingRemoteName:c,hasUncommittedChanges:p}=t,g=r===void 0?[]:r,h=d===void 0?null:d,x=f===void 0?0:f,w=m===void 0?0:m,b=p===void 0?!1:p,{t:y}=ct(),v=o.useRef(!1),S=!!h,I=g.find(ae=>ae.name===c)??g[0],j=w>0&&b,N=u||n!==null||S||!I||j,P=u||n!==null||S||g.length===0,M=x>0||w>0;let T;e[0]!==y?(T=y("gitView.sync.sync"),e[0]=y,e[1]=T):T=e[1];const E=w>0?`↓${w}`:null,k=x>0?`↑${x}`:null;let C;e[2]!==T||e[3]!==E||e[4]!==k?(C=[T,E,k].filter(Boolean),e[2]=T,e[3]=E,e[4]=k,e[5]=C):C=e[5];const A=C.join(" "),F=j?y("gitView.sync.commitOrStashTooltip"):I?M?y("gitView.sync.syncChangesTooltip",{ahead:x,behind:w}):y("gitView.sync.syncChanges"):y("gitView.sync.noRemoteTooltip"),_=()=>{I&&i(I)},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=de("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 K;e[7]!==y?(K=y("gitView.sync.syncChanges"),e[7]=y,e[8]=K):K=e[8];let $;e[9]!==n?($=n==="sync"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=$):$=e[10];let oe;e[11]!==A?(oe=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:A}),e[11]=A,e[12]=oe):oe=e[12];let L;e[13]!==_||e[14]!==N||e[15]!==K||e[16]!==$||e[17]!==oe?(L=s.jsx(At,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:_,disabled:N,className:V,"aria-label":K,children:[$,oe]})}),e[13]=_,e[14]=N,e[15]=K,e[16]=$,e[17]=oe,e[18]=L):L=e[18];let Y;e[19]!==F?(Y=s.jsx(Rt,{sideOffset:8,children:F}),e[19]=F,e[20]=Y):Y=e[20];let ee;e[21]!==L||e[22]!==Y?(ee=s.jsxs(Tt,{children:[L,Y]}),e[21]=L,e[22]=Y,e[23]=ee):ee=e[23];const re=ys;let fe;e[24]===Symbol.for("react.memo_cache_sentinel")?(fe=de("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]=fe):fe=e[24];let ge;e[25]!==y?(ge=y("gitView.sync.moreActionsAria"),e[25]=y,e[26]=ge):ge=e[26];let be;e[27]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx(D,{name:"arrow-down-s",className:"size-4"}),e[27]=be):be=e[27];let z;e[28]!==P||e[29]!==ge?(z=s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:fe,disabled:P,"aria-label":ge,children:be})}),e[28]=P,e[29]=ge,e[30]=z):z=e[30];const B=ws,Q="start",X=-40,ie="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",le=g.map(ae=>s.jsx(vt,{onSelect:U=>{if(v.current){U.preventDefault(),v.current=!1;return}a(ae)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(D,{name:"refresh",className:"size-4 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:y("gitView.sync.fetchFromRemote",{name:ae.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:ae.fetchUrl})]})}),l&&ae.name!==c?s.jsx(ve,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||S,onPointerDown:U=>{v.current=!0,U.preventDefault(),U.stopPropagation()},onClick:U=>{v.current=!0,U.preventDefault(),U.stopPropagation(),l(ae)},"aria-label":y("gitView.header.removeRemoteAria",{name:ae.name}),title:y("gitView.header.removeRemoteTitle",{name:ae.name}),children:h===ae.name?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"close",className:"size-3.5"})}):null]})},ae.name));let ye;e[31]!==B||e[32]!==le?(ye=s.jsx(B,{align:Q,alignOffset:X,className:ie,children:le}),e[31]=B,e[32]=le,e[33]=ye):ye=e[33];let W;e[34]!==re||e[35]!==z||e[36]!==ye?(W=s.jsxs(re,{children:[z,ye]}),e[34]=re,e[35]=z,e[36]=ye,e[37]=W):W=e[37];let ue;return e[38]!==ee||e[39]!==W?(ue=s.jsxs("div",{className:O,children:[ee,W]}),e[38]=ee,e[39]=W,e[40]=ue):ue=e[40],ue},TP={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},AP={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 Vh(t){return t&&AP[t]||"var(--primary)"}const Cp=t=>{const e=st.c(8),{icon:n,className:r,colorToken:a}=t,i=TP[n??"branch"]??"user-3";let l;e[0]!==a?(l=Vh(a),e[0]=a,e[1]=l):l=e[1];let u;e[2]!==l?(u={color:l},e[2]=l,e[3]=u):u=e[3];let d;return e[4]!==r||e[5]!==i||e[6]!==u?(d=s.jsx(D,{name:i,className:r,style:u}),e[4]=r,e[5]=i,e[6]=u,e[7]=d):d=e[7],d},Uh=t=>{const e=st.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:l}=t,u=l===void 0?!1:l,{t:d}=ct(),f=i||r.length===0,m=n?.color;let c;e[0]!==m?(c=Vh(m),e[0]=m,e[1]=c):c=e[1];let p;e[2]!==c?(p={color:c},e[2]=c,e[3]=p):p=e[3];let g;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(g=i?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(Cp,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=g):g=e[7];let h;e[8]!==n?.name||e[9]!==u||e[10]!==d?(h=!u&&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]=u,e[10]=d,e[11]=h):h=e[11];let x;e[12]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=x):x=e[12];let w;e[13]!==f||e[14]!==p||e[15]!==g||e[16]!==h?(w=s.jsx(At,{asChild:!0,children:s.jsx(vs,{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:p,disabled:f,children:[g,h,x]})})}),e[13]=f,e[14]=p,e[15]=g,e[16]=h,e[17]=w):w=e[17];let b;e[18]!==d?(b=d("gitView.header.identityTooltip"),e[18]=d,e[19]=b):b=e[19];let y;e[20]!==b?(y=s.jsx(Rt,{sideOffset:8,children:b}),e[20]=b,e[21]=y):y=e[21];let v;e[22]!==y||e[23]!==w?(v=s.jsxs(Tt,{children:[w,y]}),e[22]=y,e[23]=w,e[24]=v):v=e[24];let S;e[25]!==n?.id||e[26]!==r||e[27]!==a||e[28]!==d?(S=r.length===0?s.jsx("div",{className:"px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:d("gitView.header.noProfiles")})}):r.map(N=>{const P=n?.id===N.id;return s.jsx(vt,{onSelect:()=>a(N),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(Cp,{icon:N.icon,colorToken:N.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:N.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:N.userEmail})]}),P?s.jsx(D,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},N.id)}),e[25]=n?.id,e[26]=r,e[27]=a,e[28]=d,e[29]=S):S=e[29];let I;e[30]!==S?(I=s.jsx(ws,{align:"end",className:"w-64",children:S}),e[30]=S,e[31]=I):I=e[31];let j;return e[32]!==v||e[33]!==I?(j=s.jsxs(ys,{children:[v,I]}),e[32]=v,e[33]=I,e[34]=j):j=e[34],j},RD=t=>{const e=st.c(48),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:l,remotes:u,onFetch:d,onSync:f,onRemoveRemote:m,removingRemoteName:c,onCheckoutBranch:p,onCreateBranch:g,onRenameBranch:h,activeIdentityProfile:x,availableIdentities:w,onSelectIdentity:b,isApplyingIdentity:y,isWorktreeMode:v,onOpenHistory:S,actionTabItems:I,activeActionTab:j,onSelectActionTab:N}=t,{t:P}=ct();if(!n)return null;let M;e[0]!==S||e[1]!==P?(M=S?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:S,children:s.jsx(D,{name:"history",className:"size-4"})})}),s.jsx(Rt,{sideOffset:8,children:P("gitView.history.title")})]}):null,e[0]=S,e[1]=P,e[2]=M):M=e[2];let T;e[3]!==M?(T=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:M}),e[3]=M,e[4]=T):T=e[4];const E=T,k=!n;let C;e[5]!==n.tracking?(C=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=C):C=e[6];const A=(n.files?.length??0)>0;let F;e[7]!==d||e[8]!==m||e[9]!==f||e[10]!==u||e[11]!==c||e[12]!==n.ahead||e[13]!==n.behind||e[14]!==l||e[15]!==k||e[16]!==C||e[17]!==A?(F=s.jsx(DP,{syncAction:l,remotes:u,onFetch:d,onSync:f,onRemoveRemote:m,removingRemoteName:c,disabled:k,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:C,hasUncommittedChanges:A}),e[7]=d,e[8]=m,e[9]=f,e[10]=u,e[11]=c,e[12]=n.ahead,e[13]=n.behind,e[14]=l,e[15]=k,e[16]=C,e[17]=A,e[18]=F):F=e[18];const _=F;let O;e[19]!==x||e[20]!==w||e[21]!==y||e[22]!==b?(O=s.jsx(Uh,{activeProfile:x,identities:w,onSelect:b,isApplying:y,iconOnly:!0}),e[19]=x,e[20]=w,e[21]=y,e[22]=b,e[23]=O):O=e[23];const V=O;let K;e[24]!==i||e[25]!==v||e[26]!==r||e[27]!==p||e[28]!==g||e[29]!==h||e[30]!==a||e[31]!==u||e[32]!==n.current?(K=s.jsx("div",{className:"min-w-0 flex-1",children:v?s.jsx(IP,{currentBranch:n.current,onRename:h}):s.jsx(CP,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:p,onCreate:g,remotes:u})}),e[24]=i,e[25]=v,e[26]=r,e[27]=p,e[28]=g,e[29]=h,e[30]=a,e[31]=u,e[32]=n.current,e[33]=K):K=e[33];let $;e[34]!==V||e[35]!==E?($=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[E,V]}),e[34]=V,e[35]=E,e[36]=$):$=e[36];let oe;e[37]!==K||e[38]!==$?(oe=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[K,$]}),e[37]=K,e[38]=$,e[39]=oe):oe=e[39];let L;e[40]!==I||e[41]!==j||e[42]!==N||e[43]!==_?(L=I&&j&&N?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(ur,{items:I,activeId:j,onSelect:N,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:_})]}):null,e[40]=I,e[41]=j,e[42]=N,e[43]=_,e[44]=L):L=e[44];let Y;return e[45]!==oe||e[46]!==L?(Y=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[oe,L]}),e[45]=oe,e[46]=L,e[47]=Y):Y=e[47],Y},EP=t=>t==="/",nl=t=>t.replace(/\\/g,"/"),jd=t=>{if(!t||EP(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},$a=t=>t.endsWith("/"),MP=t=>{const e=t.trim();return!e||$a(e)?e:`${e}/`},Nd=t=>t.lastIndexOf("/"),Kh=t=>{if($a(t))return t;const e=Nd(t);return e<0?t:t.slice(0,e+1)},RP=t=>{const e=Nd(t);return t.slice(e+1)},Wh=t=>{const e=jd(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=Nd(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},FP=t=>$a(t)&&Wh(t)!==null,Pp=(t,e)=>`${Kh(t)}${e}/`,ja=t=>{if(!t)return null;const e=jd(nl(t.trim()));return e?e.toLowerCase():null},Ip=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},LP=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},OP=async()=>{try{const t=await fetch("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(t.ok){const e=await t.json();if(typeof e.home=="string"&&e.home.trim().length>0)return nl(e.home.trim())}}catch{}return Bs.getFilesystemHome().catch(()=>null)},$P=({open:t,onOpenChange:e})=>{const{t:n}=ct(),r=Ns(Te=>Te.homeDirectory),a=es(Te=>Te.projects),i=es(Te=>Te.addProject),l=_n(Te=>Te.profiles),u=_n(Te=>Te.globalIdentity),d=_n(Te=>Te.defaultGitIdentityId),f=_n(Te=>Te.loadProfiles),m=_n(Te=>Te.loadGlobalIdentity),c=_n(Te=>Te.loadDefaultGitIdentityId),p=cl(),{isDesktop:g,requestAccess:h,startAccessing:x}=SP(),{isMobile:w}=_s(),b=o.useRef(null),y=o.useRef(null),v=o.useRef(new Map),[S,I]=o.useState(""),[j,N]=o.useState("~/"),[P,M]=o.useState([]),[T,E]=o.useState(!1),[k,C]=o.useState(!1),[A,F]=o.useState(0),[_,O]=o.useState(!1),[V,K]=o.useState(!1),[$,oe]=o.useState(0),[L,Y]=o.useState(!1),[ee,re]=o.useState(""),[fe,ge]=o.useState(null),[be,z]=o.useState(!1),[B,Q]=o.useState(""),[X,ie]=o.useState(!1),le=S||r,ye=o.useMemo(()=>new Set(a.map(Te=>ja(Te.path)).filter(Te=>!!Te)),[a]);o.useEffect(()=>{if(!t)return;N("~/"),M([]),F(0),O(!1),K(!1),Y(!1),re(""),ge(null),z(!1),Q(""),ie(!1),requestAnimationFrame(()=>pc(b.current));let Te=!1;return(async()=>{const Ye=await OP();Te||(I(Ye||r||""),requestAnimationFrame(()=>pc(b.current)))})(),()=>{Te=!0}},[r,t]),o.useEffect(()=>{t&&(f(),m(),c())},[c,f,m,t]);const W=o.useMemo(()=>{const Te=new Map;u&&Te.set(u.id,u);for(const Ve of l)Te.set(Ve.id,Ve);return Array.from(Te.values())},[l,u]);o.useEffect(()=>{if(!t||!L||fe!==null)return;const Te=typeof d=="string"?d.trim():"";if(Te&&W.some(Ye=>Ye.id===Te)){ge(Te);return}const Ve=W.find(Ye=>Ye.authType==="ssh"||Ye.sshKey);Ve&&ge(Ve.id)},[W,d,L,t,fe]);const ue=o.useMemo(()=>W.find(Te=>Te.id===fe)??null,[W,fe]),ae=o.useMemo(()=>Kh(j),[j]),U=o.useMemo(()=>$a(j)?"":RP(j),[j]),G=o.useMemo(()=>le?Ip(ae,le):"",[ae,le]);o.useEffect(()=>{if(!t||!G){M([]);return}let Te=!1;return E(!0),C(!1),Bs.listLocalDirectory(G).then(Ve=>{if(Te)return;C(!1);const Ye=Ve.filter(Ge=>Ge.isDirectory).map(Ge=>({name:Ge.name,path:nl(Ge.path)})).sort((Ge,me)=>Ge.name.localeCompare(me.name));M(Ye)}).catch(()=>{Te||(M([]),C(!0))}).finally(()=>{Te||E(!1)}),()=>{Te=!0}},[G,t]);const ne=o.useMemo(()=>{const Te=U.toLowerCase(),Ve=p||U.startsWith(".");return P.filter(Ye=>Ye.name.toLowerCase().startsWith(Te)&&(Ve||!Ye.name.startsWith(".")))},[U,P,p]),se=o.useMemo(()=>{const Te=[];FP(j)&&Te.push({type:"up",value:"browse:up",name:"..",path:Wh(j)});for(const Ve of ne){const Ye=ja(Ve.path);Te.push({type:"directory",value:`browse:${Ve.path}`,name:Ve.name,path:Ve.path,disabled:!!(Ye&&ye.has(Ye))})}return Te},[ye,ne,j]);o.useEffect(()=>{F(0)},[j,se.length]);const xe=o.useMemo(()=>le?jd(Ip(j,le)):"",[le,j]),Se=ja(xe),je=!!(Se&&ye.has(Se)),Ie=o.useMemo(()=>U?ne.find(Te=>Te.name===U)??null:null,[U,ne]),Oe=!!(xe&&!je&&($a(j)&&k||!$a(j)&&U.trim().length>0&&Ie===null)),Ne=!_&&!V&&!je&&!!xe,he=Ne&&ee.trim().length>0,Fe=se[A]??null,Be=!!(Fe&&(Fe.type==="up"||Fe.type==="directory"&&!Fe.disabled)),q=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Pe=n(je?"directoryExplorerDialog.actions.alreadyAdded":L?_?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":_?"directoryExplorerDialog.actions.adding":Oe?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const Te=y.current;if(!Te)return;const Ve=()=>oe(Math.ceil(Te.getBoundingClientRect().width));if(Ve(),typeof ResizeObserver>"u")return;const Ye=new ResizeObserver(Ve);return Ye.observe(Te),()=>Ye.disconnect()},[Pe]),o.useLayoutEffect(()=>{const Te=b.current;Te&&(Te.scrollLeft=Te.scrollWidth)},[$,j]),o.useLayoutEffect(()=>{t&&pc(b.current)},[t]),o.useLayoutEffect(()=>{const Te=se[A];Te&&v.current.get(Te.value)?.scrollIntoView({block:"nearest"})},[A,se]);const $e=o.useCallback(()=>{e(!1)},[e]),Ce=o.useCallback(async Te=>{if(!Te||_)return;const Ve=ja(Te);if(Ve&&ye.has(Ve))return;let Ye=Te;O(!0);try{const Ge=!L&&Oe&&ja(Te)===ja(xe);if(L){const Ke=ee.trim();if(!Ke){te.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ye=(await Bs.cloneRepository({remoteUrl:Ke,destinationPath:Te,gitIdentityId:ue?.id??null})).path}else Ge&&await Bs.createDirectory(Te,{allowOutsideWorkspace:!0,initializeTemplate:!0});if(!i(Ye)){te.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}$e()}catch(Ge){te.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ge instanceof Error?Ge.message:n("directoryExplorerDialog.toast.unknownError")})}finally{O(!1)}},[i,ye,ee,$e,L,_,ue?.id,Oe,xe,n]),pe=o.useCallback(Te=>{N(MP(Te))},[]),R=o.useCallback(Te=>{N(Pp(j,Te.name))},[j]),J=o.useCallback(Te=>{if(Te){if(Te.type==="up"){Te.path&&pe(Te.path);return}Te.disabled||R(Te)}},[pe,R]),H=o.useCallback(async()=>{if(!(!g||V)){K(!0);try{const Te=await h(xe);if(!Te.success||!Te.path){Te.error&&Te.error!=="Directory selection cancelled"&&te.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te.error});return}const Ve=await x(Te.path);if(!Ve.success){te.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:Ve.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Ce(Te.path)}catch(Te){te.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te instanceof Error?Te.message:n("directoryExplorerDialog.toast.unknownError")})}finally{K(!1)}}},[Ce,g,V,h,x,n,xe]),Ee=o.useCallback(Te=>{if(Te.key==="ArrowDown"){Te.preventDefault(),F(Ve=>Math.min(se.length-1,Ve+1));return}if(Te.key==="ArrowUp"){Te.preventDefault(),F(Ve=>Math.max(0,Ve-1));return}if(Te.key==="Enter"){if(Te.preventDefault(),LP(Te)){Ce(xe);return}Be&&J(Fe);return}Te.key==="Backspace"&&j===""&&(Te.preventDefault(),$e())},[J,Ce,$e,Be,Fe,j,se.length,xe]),Ae=o.useCallback(async()=>{const Te=B.trim();if(!(!Te||X)){ie(!0);try{const Ve=`${G}${Te}`;await Bs.createDirectory(Ve,{allowOutsideWorkspace:!0,initializeTemplate:!0}),te.success(n("directoryExplorerDialog.toast.folderCreated")),N(Pp(j,Te)),z(!1),Q("")}catch(Ve){te.error(n("directoryExplorerDialog.toast.failedToCreateFolder"),{description:Ve instanceof Error?Ve.message:n("directoryExplorerDialog.toast.unknownError")})}finally{ie(!1)}}},[B,X,G,j,n]),Je=o.useCallback(Te=>{Te.stopPropagation(),Te.key==="Enter"?(Te.preventDefault(),Ae()):Te.key==="Escape"&&(Te.preventDefault(),z(!1),Q(""))},[Ae]),ce=s.jsxs("button",{type:"button",onClick:()=>No(!p),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:[p?s.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),_e=s.jsxs("div",{className:"px-2.5 py-1.5",children:[L?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(jt,{value:ee,onChange:Te=>re(Te.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(Uh,{activeProfile:ue,identities:W,onSelect:Te=>ge(Te.id),isApplying:_,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(D,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(jt,{ref:b,value:j,onChange:Te=>N(nl(Te.target.value)),onKeyDown:Ee,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!w&&$>0?{paddingRight:`${$+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),w?null:s.jsx(ve,{ref:y,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:L?!he:!Ne,onMouseDown:Te=>Te.preventDefault(),onClick:()=>{Ce(xe)},title:Pe,children:Pe})]})]}),et=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.jsxs("div",{className:"flex items-center justify-between px-2 pb-1 pt-0.5",children:[s.jsx("div",{className:"typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),!L&&!be&&s.jsxs("button",{type:"button",onClick:()=>{z(!0),Q(""),ie(!1)},className:"flex items-center gap-1 rounded px-1.5 py-0.5 typography-meta text-primary hover:bg-primary/10 transition-colors",children:[s.jsx(D,{name:"folder-add",className:"h-3.5 w-3.5"}),s.jsx("span",{children:n("directoryExplorerDialog.actions.newFolder")})]})]}),T?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):se.length===0&&!be?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):s.jsxs("div",{className:"space-y-0.5",children:[be&&s.jsxs("div",{className:"flex w-full items-center gap-2 rounded-lg px-2 py-1 border border-primary/40 bg-interactive-hover/30",children:[s.jsx(D,{name:"folder-add",className:"h-4 w-4 flex-shrink-0 text-primary"}),s.jsx("input",{type:"text",value:B,onChange:Te=>Q(Te.target.value),onKeyDown:Je,placeholder:n("directoryExplorerDialog.newFolder.placeholder"),className:"min-w-0 flex-1 bg-transparent border-none outline-none font-mono typography-ui-label text-foreground placeholder:text-muted-foreground/60",autoFocus:!0,disabled:X}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",disabled:X||!B.trim(),onClick:Ae,title:n("directoryExplorerDialog.newFolder.confirm"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-primary",children:s.jsx(D,{name:"check",className:"h-4 w-4"})}),s.jsx("button",{type:"button",disabled:X,onClick:()=>{z(!1),Q("")},title:n("directoryExplorerDialog.newFolder.cancel"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-muted-foreground",children:s.jsx(D,{name:"close",className:"h-4 w-4"})})]})]}),se.map((Te,Ve)=>{const Ye=Ve===A;return s.jsxs("button",{ref:Ge=>{Ge?v.current.set(Te.value,Ge):v.current.delete(Te.value)},type:"button",disabled:Te.type==="directory"&&Te.disabled,onMouseEnter:()=>F(Ve),onMouseDown:Ge=>Ge.preventDefault(),onClick:()=>J(Te),className:de("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",Ye&&"bg-interactive-selection text-interactive-selection-foreground",!Ye&&"hover:bg-interactive-hover/50",Te.type==="directory"&&Te.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Te.type==="up"?s.jsx(D,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(D,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Te.name})}),Te.type==="directory"&&Te.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]},Te.value)})]})]})}),Me=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[_e,et]}),He=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(D,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(D,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:q}),s.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),We=()=>s.jsxs(s.Fragment,{children:[w?null:He,s.jsxs("div",{className:de("flex w-full flex-row justify-end gap-2 sm:w-auto",w&&"justify-stretch"),children:[g?s.jsx(ve,{variant:"ghost",size:"xs",onClick:H,disabled:_||V||L,children:n(V?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(ve,{variant:"ghost",size:"xs",onClick:()=>Y(Te=>!Te),disabled:_||V,className:de(w&&"flex-1"),children:n(L?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),w?s.jsx(ve,{size:"xs",onClick:()=>{Ce(xe)},disabled:L?!he:!Ne,className:"flex-1",children:Pe}):null]})]});return w?s.jsx(hr,{open:t,onClose:$e,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:We()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:ce}),Me]})}):s.jsx(ls,{open:t,onOpenChange:e,children:s.jsxs(os,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(bs,{className:"px-5 pb-2 pt-5",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx(hs,{children:n("directoryExplorerDialog.title")}),s.jsx(Ss,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),ce]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:Me}),s.jsx(Is,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:We()})]})})},Zr=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,lr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},_P=()=>{const{t}=ct(),[e,n]=o.useState(!1),[r,a]=o.useState(null),[i,l]=o.useState([]),[u,d]=o.useState(!1),[f,m]=o.useState(!1),[c,p]=o.useState(!1),[g,h]=o.useState(!1),[x,w]=o.useState(new Set),b=Ft(U=>U.getWorktreeMetadata),y=Ft(U=>U.newSessionDraft),v=Ft(U=>U.setNewSessionDraftTarget),S=Ft(U=>U.setDraftBootstrapPendingDirectory),I=$b,j=Bb,N=Ft(U=>U.deleteSessions),P=Ft(U=>U.archiveSessions),M=De(U=>U.showDeletionDialog),T=De(U=>U.setShowDeletionDialog),E=Ns(U=>U.currentDirectory),k=Ns(U=>U.homeDirectory),C=es(U=>U.projects),A=es(U=>U.activeProjectId),{isMobile:F,isTablet:_,hasTouchInput:O}=_s(),V=F||_||O,K=o.useMemo(()=>{const G=(A?C.find(ne=>ne.id===A)??null:null)?.path??E;return lr(G)},[A,E,C]),$=o.useCallback(U=>{const ne=lr(U.projectDirectory)||K;return{id:(C.find(xe=>lr(xe.path)===ne)??null)?.id??`path:${ne}`,path:ne}},[K,C]),oe=g&&x.size>0,L=o.useMemo(()=>{const U=r?.worktree;return U&&typeof U.branch=="string"&&U.branch.trim().length>0?!0:i.length>0&&i.every(({metadata:G})=>typeof G.branch=="string"&&G.branch.trim().length>0)},[r?.worktree,i]),Y=r?.mode==="worktree",ee=Y,re=c||!Y||!L,fe=c||!Y,ge=o.useCallback(U=>{a({sessions:U.sessions,dateLabel:U.dateLabel,mode:U.mode??"session",worktree:U.worktree??null})},[]),be=o.useCallback(()=>{a(null),l([]),d(!1),m(!1),p(!1),h(!1),w(new Set)},[]),z=o.useCallback(async U=>{if(U.sessions.length===0)return;if(U.sessions.length===1){const xe=U.sessions[0];await I(xe.id)?te.success(t("sessions.sidebar.session.delete.success")):te.error(t("sessions.sidebar.session.delete.error"));return}const G=U.sessions.map(xe=>xe.id),{deletedIds:ne,failedIds:se}=await N(G);if(ne.length>0){const xe=se.length>0?se.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:se.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:se.length}):U.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:U.dateLabel}):void 0;te.success(ne.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ne.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ne.length}),{description:Zr(xe)})}se.length>0&&te.error(se.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:se.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:se.length}),{description:Zr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[I,N,t]);o.useEffect(()=>gr.onDeleteRequest(U=>{if(!M&&(U.mode??"session")==="session"){z(U);return}ge(U)}),[ge,M,z]),o.useEffect(()=>gr.onDirectoryRequest(()=>{n(!0)}),[]),o.useEffect(()=>{if(!r){l([]),d(!1),m(!1),h(!1),w(new Set);return}const U=r.sessions.map(se=>{const xe=b(se.id);return xe?{session:se,metadata:xe}:null}).filter(se=>!!se);l(U),d(!1),h(!1),w(new Set);const G=new Map;if(r.worktree?.path&&G.set(lr(r.worktree.path),r.worktree),U.forEach(({metadata:se})=>{se.path&&G.set(lr(se.path),se)}),G.size===0){h(!0);return}let ne=!1;return(async()=>{const se=new Map,xe=new Set;await Promise.all(Array.from(G.entries()).map(async([Se,je])=>{try{const Ie=await _b(je.path);se.set(Se,Ie),Ie?.isDirty&&xe.add(Se)}catch{je.status&&(se.set(Se,je.status),je.status.isDirty&&xe.add(Se))}})).catch(Se=>{console.warn("Failed to inspect worktree status before deletion:",Se)}),!ne&&(w(xe),h(!0),a(Se=>{if(!Se?.worktree?.path)return Se;const je=lr(Se.worktree.path),Ie=se.get(je);if(!Ie)return Se;const Oe=Se.worktree.status;return Oe?.isDirty===Ie.isDirty&&Oe?.ahead===Ie.ahead&&Oe?.behind===Ie.behind&&Oe?.upstream===Ie.upstream?Se:{...Se,worktree:{...Se.worktree,status:Ie}}}),l(Se=>Se.map(je=>{const Ie=lr(je.metadata.path),Oe=se.get(Ie);return Oe?{session:je.session,metadata:{...je.metadata,status:Oe}}:je})))})(),()=>{ne=!0}},[r,b]),o.useEffect(()=>{L||d(!1)},[L]);const B=o.useCallback(async(U,G)=>{const ne=u&&L,se=$(U),xe=lr(U.path),Se=lr(se.path);try{await zb(se,U,{deleteRemoteBranch:ne,deleteLocalBranch:G});const je=lr(y?.directoryOverride);return y?.open&&xe&&je===xe&&Se&&(S(null),v({projectId:se.id,directoryOverride:Se},{force:!0})),lr(E)===xe&&Se&&Ns.getState().setDirectory(Se,{showOverlay:!1}),!0}catch(je){return te.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Zr(je instanceof Error?je.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[L,E,u,$,y?.directoryOverride,y?.open,S,v,t]),Q=o.useCallback(async()=>{if(r){p(!0);try{const U=ee,G=U&&u,ne=U&&f;if(r.sessions.length===0&&Y&&r.worktree){if(!await B(r.worktree,ne)){be();return}const Se=t(u&&L?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");te.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Zr(Se)}),be();return}if(r.sessions.length===1){const se=r.sessions[0];if(!(Y?await j(se.id):await I(se.id,{archiveWorktree:!1,deleteRemoteBranch:G,deleteLocalBranch:ne}))){te.error(t(Y?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),p(!1);return}const Se=!Y&&U?t(G?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;te.success(t(Y?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Zr(Se),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const se=r.sessions.map(je=>je.id);let xe=[],Se=[];if(Y){const je=await P(se);xe=je.archivedIds,Se=je.failedIds}else{const je=await N(se);xe=je.deletedIds,Se=je.failedIds}if(Y&&r.worktree&&Se.length===0&&await B(r.worktree,ne),xe.length>0){const je=!Y&&U?t(G?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Oe=[Se.length>0?Y?Se.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:Se.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:Se.length}):Se.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Se.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Se.length}):r.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:r.dateLabel}):void 0,je].filter(Boolean).join(" ");te.success(Y?xe.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:xe.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:xe.length}):xe.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:xe.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:xe.length}),{description:Zr(Oe||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(Se.length>0&&(te.error(Y?Se.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Se.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:Se.length}):Se.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Se.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Se.length}),{description:Zr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),xe.length===0)){p(!1);return}}Y&&r.sessions.length===1&&r.worktree&&await B(r.worktree,ne),be()}finally{p(!1)}}},[r,u,f,I,N,j,P,be,ee,Y,L,B,t]),X=r?.worktree??i[0]?.metadata??null,ie=r?r.mode==="worktree"?r.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):r.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:r.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:r.sessions.length}):r.sessions.length===1?r.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:r.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):r.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:r.sessions.length,dateLabel:r.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:r.sessions.length}):"",le=r?s.jsxs("div",{className:de(Y?"space-y-3":"space-y-2"),children:[r.sessions.length>0&&s.jsxs("div",{className:de(Y?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[Y&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:r.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:r.sessions.length})]}),s.jsxs("ul",{className:de(Y?"mt-2 space-y-1":"space-y-0.5"),children:[r.sessions.slice(0,5).map(U=>s.jsxs("li",{className:de(Y?"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:de(!Y&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:U.title||t("sessions.sidebar.session.untitled")})]},U.id)),r.sessions.length>5&&s.jsx("li",{className:de(Y?"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:r.sessions.length-5})})]})]}),Y?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),X?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:X.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:X?Ti(X.path,k):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,ye=Y?L?s.jsxs("button",{type:"button",onClick:()=>{re||d(U=>!U)},disabled:re,className:de("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",re?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(D,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,W=Y?s.jsxs("button",{type:"button",onClick:()=>{fe||m(U=>!U)},disabled:fe,className:de("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",fe?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(D,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ue=Y?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:[W,ye]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:be,disabled:c,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:Q,disabled:c,children:t(c?"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:()=>T(!M),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":!M,children:[M?s.jsx(D,{name:"checkbox-blank",className:"size-4"}):s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:be,disabled:c,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:Q,disabled:c,children:c?t("sessions.sidebar.sessionDialogs.actions.deleting"):r?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ae=Y?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):r?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[V?s.jsx(hr,{open:!!r,onClose:()=>{c||be()},title:ae,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ue}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[ie&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:ie}),le]})}):s.jsx(ls,{open:!!r,onOpenChange:U=>{if(!U){if(c)return;be()}},children:s.jsxs(os,{className:de(Y?"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(bs,{children:[s.jsxs(hs,{className:de(Y&&"flex items-center gap-2"),children:[Y&&s.jsx(D,{name:"delete-bin",className:"h-5 w-5"}),ae]}),ie&&s.jsx(Ss,{children:ie})]}),s.jsx("div",{className:de(Y&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:le}),s.jsx(Is,{className:"mt-2 gap-2 pt-1 pb-1",children:ue})]})}),s.jsx($P,{open:e,onOpenChange:n})]})},Gc=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),zP=(t,e)=>{const n=Gc(t),r=Gc(e);return`${n}-${r}`.substring(0,60)},Dp=(t,e)=>`${t}/${e}`,BP=()=>{const t=es.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(a=>a.id===e);if(n?.path)return{id:n.id,path:n.path};const r=Ns.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},fc=vn()(qa(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:a,agent:i,files:l,setupCommands:u}=e;if(!n)return t({error:"Group name is required"}),null;if(!r)return t({error:"Prompt is required"}),null;if(a.length<1)return t({error:"Select at least 1 model"}),null;if(a.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=BP();if(!d)return t({error:"Select a project",isLoading:!1}),null;const f=d.path,c=await pf(f)&&e.isolateRuns!==!1,p=Gc(n),g=c?await fl(f):void 0,h=c?await Vb(f):null,x=[],w=u?.filter(N=>N.trim().length>0)??[],b=new Map;for(const N of a){const P=`${N.providerID}:${N.modelID}`;b.set(P,(b.get(P)||0)+1)}const y=new Map;for(const N of a){const P=`${N.providerID}:${N.modelID}`,M=b.get(P)||1,T=(y.get(P)||0)+1;y.set(P,T);const E=zP(N.providerID,N.modelID),k=M>1?Dp(p,`${E}/${T}`):Dp(p,E);try{const C=M>1?`${p}/${N.providerID}/${N.modelID}/${T}`:`${p}/${N.providerID}/${N.modelID}`;if(!c){const O=await Bs.withDirectory(f,()=>Bs.createSession({title:C}));x.push({sessionId:O.id,worktreePath:f,providerID:N.providerID,modelID:N.modelID,variant:N.variant});continue}const A=await Ub(d,{preferredName:k,mode:"new",branchName:k,worktreeName:k,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:w},{resolvedRootTrackingRemote:h}),F={...A,createdFromBranch:g,kind:"standard"},_=await Bs.withDirectory(A.path,()=>Bs.createSession({title:C}));Ft.getState().setWorktreeMetadata(_.id,F),x.push({sessionId:_.id,worktreePath:A.path,providerID:N.providerID,modelID:N.modelID,variant:N.variant})}catch(C){console.warn("[MultiRun] Failed to create session:",C)}}const v=u?.filter(N=>N.trim().length>0)??[];v.length>0&&ff(d,v).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const S=x.map(N=>N.sessionId),I=x[0]?.sessionId??null;if(S.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const j=l?.map(N=>({type:"file",mime:N.mime,filename:N.filename,url:N.url}));return(async()=>{try{await Promise.allSettled(x.map(async N=>{try{await Bs.withDirectory(N.worktreePath,()=>Bs.sendMessage({id:N.sessionId,providerID:N.providerID,modelID:N.modelID,variant:N.variant,text:r,agent:i,files:j}))}catch(P){console.warn("[MultiRun] Failed to start run:",P)}}))}catch(N){console.warn("[MultiRun] Failed to start runs:",N)}})(),t({isLoading:!1}),{groupSlug:p,sessionIds:S,firstSessionId:I}}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"})),VP="oc:lastWorktreeSourceBranch";function Hh(t){const e=st.c(30),{git:n}=wn(),r=yf(t),a=of(t),i=lf(t),l=vf(t),u=yn(GP),d=yn(HP);let f,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==a||e[4]!==i?(f=()=>{!t||!n||a!==null||i||d(t,n,{silent:!0})},m=[t,n,d,a,i],e[0]=t,e[1]=d,e[2]=n,e[3]=a,e[4]=i,e[5]=f,e[6]=m):(f=e[5],m=e[6]),o.useEffect(f,m);let c;e[7]!==r?.all||e[8]!==t||e[9]!==u||e[10]!==n||e[11]!==a?(c=()=>{!t||!n||a===!0&&(r?.all||u(t,n))},e[7]=r?.all,e[8]=t,e[9]=u,e[10]=n,e[11]=a,e[12]=c):c=e[12];const p=r?.all;let g;e[13]!==t||e[14]!==u||e[15]!==n||e[16]!==a||e[17]!==p?(g=[t,n,a,p,u],e[13]=t,e[14]=u,e[15]=n,e[16]=a,e[17]=p,e[18]=g):g=e[18],o.useEffect(c,g);const h=i||a===!0&&l;let x;e:{if(!r?.all){let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[19]=N):N=e[19],x=N;break e}let j;e[20]!==r.all?(j=r.all.filter(WP).sort(),e[20]=r.all,e[21]=j):j=e[21],x=j}const w=x;let b;e:{if(!r?.all){let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[22]=N):N=e[22],b=N;break e}let j;e[23]!==r.all?(j=r.all.filter(KP).map(UP).sort(),e[23]=r.all,e[24]=j):j=e[24],b=j}const y=b;let v;e:{if(!t){v=null;break e}if(a!==null){v=a;break e}if(h){v=null;break e}v=r?.all?!0:null}const S=v;let I;return e[25]!==S||e[26]!==h||e[27]!==w||e[28]!==y?(I={localBranches:w,remoteBranches:y,isLoading:h,isGitRepository:S},e[25]=S,e[26]=h,e[27]=w,e[28]=y,e[29]=I):I=e[29],I}function UP(t){return t.replace(/^remotes\//,"")}function KP(t){return t.startsWith("remotes/")}function WP(t){return!t.startsWith("remotes/")}function HP(t){return t.fetchStatus}function GP(t){return t.fetchBranches}const qP=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:l}=ct(),{localBranches:u,remoteBranches:d,isLoading:f,isGitRepository:m}=Hh(t),c=o.useMemo(()=>[...u,...d.map(g=>`remotes/${g}`)],[u,d]);o.useEffect(()=>{if(a||f||c.length===0||e&&c.includes(e))return;(async()=>{try{const h=t?await fl(t).catch(()=>null):null,x=localStorage.getItem(VP);x&&c.includes(x)?n(x):h&&c.includes(h)?n(h):c.includes("main")?n("main"):c.includes("master")?n("master"):c[0]&&n(c[0])}catch{}})()},[c,t,a,f,n,e]);const p=a||!m||f;return s.jsxs("div",{children:[s.jsxs(Qt,{value:e,onValueChange:n,disabled:p,children:[s.jsx(Jt,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(as,{placeholder:l(f?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(Xt,{className:"max-h-[280px] max-w-[320px]",children:f?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.loadingBranches")}):u.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[u.length>0&&s.jsxs(lu,{children:[s.jsx(cu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),u.map(g=>s.jsx(Ct,{value:g,className:"whitespace-normal break-all",children:g},g))]}),u.length>0&&d.length>0&&s.jsx(Kb,{}),d.length>0&&s.jsxs(lu,{children:[s.jsx(cu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),d.map(g=>s.jsx(Ct,{value:`remotes/${g}`,className:"whitespace-normal break-all",children:g},`remotes/${g}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:l("multiRun.branchSelector.status.notInGitRepository")})]})},YP=10*1024*1024,hc=5,bo=t=>{const e=st.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let a;return e[1]!==n?(a=s.jsxs(Tt,{children:[r,s.jsx(Rt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=a):a=e[2],a},Na=t=>{const e=st.c(9),{htmlFor:n,required:r,children:a,info:i}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let u;e[2]!==a||e[3]!==n||e[4]!==l?(u=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,l]}),e[2]=a,e[3]=n,e[4]=l,e[5]=u):u=e[5];const d=i&&i;let f;return e[6]!==u||e[7]!==d?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[u,d]}),e[6]=u,e[7]=d,e[8]=f):f=e[8],f},QP=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=ct(),[i,l]=o.useState(""),[u,d]=o.useState(()=>t??""),[f,m]=o.useState([]),[c,p]=o.useState(""),[g,h]=o.useState([]),[x,w]=o.useState(!1),[b,y]=o.useState([]),[v,S]=o.useState(!1),[I,j]=o.useState(!1),[N,P]=o.useState(!0),[M,T]=o.useState(!1),[E,k]=o.useState(""),[C,A]=o.useState(!1),[F,_]=o.useState(""),O=o.useRef(null),V=o.useRef(null),K=o.useRef(null),$=o.useRef(null),oe=Ns(Me=>Me.currentDirectory??null),L=Ns(Me=>Me.homeDirectory??null),Y=o.useMemo(()=>{if(typeof window>"u")return null;const Me=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Me=="string"&&Me.trim().length>0?Me.trim():null},[]),ee=es(Me=>Me.activeProjectId),re=es(Me=>Me.setActiveProjectIdOnly),fe=es(Me=>Me.projects),[ge,be]=o.useState(()=>ee??null);o.useEffect(()=>{if(ee){be(ee);return}!ge&&fe.length>0&&be(fe[0].id)},[ee,fe,ge]);const z=o.useMemo(()=>ge?fe.find(Me=>Me.id===ge)??null:null,[fe,ge]),B=z?.path??oe,Q=o.useCallback(Me=>{be(Me),Me!==ee&&re(Me)},[ee,re]),{currentTheme:X}=rr(),ie=o.useCallback(Me=>{const He=Me.label?.trim()||ca(Me.path,L),We=Bi({id:Me.id,iconImage:Me.iconImage??null},{themeVariant:X.metadata.variant,iconColor:X.colors.surface.foreground}),Te=Me.icon?pl[Me.icon]:null,Ve=Me.color?Vi[Me.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[We?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Me.iconBackground?{backgroundColor:Me.iconBackground}:void 0,children:s.jsx("img",{src:We,alt:"",className:"h-full w-full object-contain",draggable:!1})}):Te?s.jsx(D,{name:Te,className:"h-3.5 w-3.5 shrink-0",style:Ve?{color:Ve}:void 0}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Ve?{color:Ve}:void 0}),s.jsx("span",{className:"truncate",children:He})]})},[L,X.metadata.variant,X.colors.surface.foreground]),le=o.useMemo(()=>{if(z?.path)return{id:z.id,path:z.path};const Me=oe??Y;return Me?{id:`path:${Me}`,path:Me}:null},[z,oe,Y]),[ye,W]=o.useState(()=>typeof window>"u"?!1:Us()),ue=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ae=ol();o.useEffect(()=>{typeof window>"u"||W(Us())},[]);const U=o.useMemo(()=>{if(typeof window>"u")return null;const Me=window.__APP_MACOS_MAJOR__;if(typeof Me=="number"&&Number.isFinite(Me)&&Me>0)return Me;if(typeof navigator>"u")return null;const He=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!He)return null;const We=Number.parseInt(He[1],10),Te=Number.parseInt(He[2],10);return Number.isNaN(We)?null:We===10?Te:We},[]),G=o.useMemo(()=>ye&&ue||ae?"pl-[5.5rem]":"pl-3",[ye,ue,ae]),ne=o.useMemo(()=>!ye||!ue||U===null?"":U>=26?"h-12":U<=15?"h-14":"",[ye,ue,U]),se=o.useCallback(async Me=>{Me.target.closest("button, a, input, select, textarea")||Me.button===0&&ye&&await Cf()},[ye]);o.useEffect(()=>{if(!n)return;const Me=He=>{He.key==="Escape"&&(He.preventDefault(),He.stopPropagation(),n())};return window.addEventListener("keydown",Me,!0),()=>window.removeEventListener("keydown",Me,!0)},[n]);const[xe,Se]=o.useState(""),{isLoading:je,isGitRepository:Ie}=Hh(B),Oe=o.useRef(!1),Ne=Ie===!0,he=Ne&&N;o.useEffect(()=>{if(Ie===!1){Oe.current=!0,P(!1);return}Ie===!0&&Oe.current&&(Oe.current=!1,P(!0))},[Ie]);const Fe=fc(Me=>Me.createMultiRun),Be=fc(Me=>Me.error),q=fc(Me=>Me.clearError);o.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Me=>Me.trim().length>0?Me:t)},[t]),o.useEffect(()=>{if(!le)return;let Me=!1;return j(!0),(async()=>{try{const He=await id(le);Me||y(He)}catch{}finally{Me||j(!1)}})(),()=>{Me=!0}},[le]);const Pe=Me=>{f.length>=hc||(m(He=>[...He,Me]),q())},$e=Me=>{m(He=>He.filter((We,Te)=>Te!==Me)),q()},Ce=o.useCallback((Me,He)=>{m(We=>We.map((Te,Ve)=>Ve===Me?He:Te))},[]),pe=async Me=>{const He=Me.target.files;if(!He)return;let We=0;for(let Te=0;Te<He.length;Te++){const Ve=He[Te];if(Ve.size>YP){te.error(a("multirun.launcher.toast.fileTooLarge",{fileName:Ve.name}));continue}try{const Ye=await new Promise((me,Ke)=>{const ze=new FileReader;ze.onload=()=>me(ze.result),ze.onerror=Ke,ze.readAsDataURL(Ve)}),Ge={id:Gb(),filename:Ve.name,mimeType:Ve.type||"application/octet-stream",size:Ve.size,dataUrl:Ye};h(me=>[...me,Ge]),We++}catch(Ye){console.error("File attach failed",Ye),te.error(a("multirun.launcher.toast.attachFailed",{fileName:Ve.name}))}}We>0&&te.success(We===1?a("multirun.launcher.toast.attachedSingle",{count:We}):a("multirun.launcher.toast.attachedPlural",{count:We})),O.current&&(O.current.value="")},R=Me=>{h(He=>He.filter(We=>We.id!==Me))},J=o.useCallback((Me,He)=>{if(Me.startsWith("/")){const Ve=Me.indexOf(" "),Ye=Me.indexOf(`
176
+ `)?(T(R),P(!0)):P(!1);return}P(!1)},[]),G=Le.useCallback(q=>{y(Pe=>({...Pe,execution:{...Pe.execution,prompt:q}}))},[]),ne=Le.useCallback(q=>{const Pe=b.execution.prompt,Ce=V.current?.selectionStart??Pe.length,R=Pe.substring(0,Ce).lastIndexOf("@"),J=q.relativePath&&q.relativePath.trim().length>0?q.relativePath.trim():q.path||q.name,H=R!==-1?R:Ce,Ee=`${Pe.substring(0,H)}@${J} ${Pe.substring(Ce)}`,Ae=H+J.length+2;G(Ee),P(!1),T(""),requestAnimationFrame(()=>{const Je=V.current;Je&&(Je.selectionStart=Ae,Je.selectionEnd=Ae,Je.focus()),U(Ee,Ae)})},[b.execution.prompt,G,U]),se=Le.useCallback(q=>{const Pe=b.execution.prompt,Ce=V.current?.selectionStart??Pe.length,R=Pe.substring(0,Ce).lastIndexOf("@"),J=R!==-1?R:Ce,H=`${Pe.substring(0,J)}@${q} ${Pe.substring(Ce)}`,Ee=J+q.length+2;G(H),P(!1),T(""),requestAnimationFrame(()=>{const Ae=V.current;Ae&&(Ae.selectionStart=Ee,Ae.selectionEnd=Ee,Ae.focus()),U(H,Ee)})},[b.execution.prompt,G,U]),xe=Le.useCallback(q=>{const Pe=`/${q.name} `;G(Pe),k(!1),A(""),requestAnimationFrame(()=>{const $e=V.current;$e&&($e.focus(),$e.selectionStart=$e.value.length,$e.selectionEnd=$e.value.length),U(Pe,Pe.length)})},[G,U]),Se=Le.useCallback(q=>{if(E&&$.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")){q.preventDefault(),$.current.handleKeyDown(q.key);return}N&&K.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")&&(q.preventDefault(),K.current.handleKeyDown(q.key))},[E,N]),je=Le.useCallback(async()=>{const q=oC(b,i);if(q){te.error(q);return}const Pe=lC(b.schedule.times),$e={...b.id?{id:b.id}:{},name:b.name.trim(),enabled:b.enabled,schedule:{kind:b.schedule.kind,timezone:b.schedule.timezone.trim(),...b.schedule.kind==="once"?{date:b.schedule.onceDate,time:b.schedule.onceTime}:{times:Pe,...b.schedule.kind==="weekly"?{weekdays:b.schedule.weekdays}:{}}},execution:{prompt:b.execution.prompt,providerID:b.execution.providerID,modelID:b.execution.modelID,...b.execution.variant.trim()?{variant:b.execution.variant.trim()}:{},...b.execution.agent.trim()?{agent:b.execution.agent.trim()}:{}},...b.state?{state:b.state}:{}};S(!0);try{await a($e),r(!1)}catch(Ce){te.error(Ce instanceof Error?Ce.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[b,r,a,i]),Ie=Le.useId(),Oe=Le.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),Ne=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),he=i("sessions.scheduledTasks.editor.description"),Fe=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(er,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(jt,{id:"sched-name",value:b.name,onChange:q=>y(Pe=>({...Pe,name:q.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Qt,{value:b.schedule.kind,onValueChange:q=>{y(Pe=>({...Pe,schedule:{...Pe.schedule,kind:q}}))},children:[s.jsx(Jt,{className:"w-fit max-w-full",children:s.jsx(as,{children:q=>i(q==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":q==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(Xt,{children:[s.jsx(Ct,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Ct,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Ct,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),b.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(er,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(q=>!q),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(D,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:J5(b.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),l)})]}),s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),I?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:()=>_(q=>dp(q,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:W,children:s.jsx(D,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(l,{month:"long",year:"numeric"}).format(F)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>_(q=>dp(q,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:ue.map((q,Pe)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:q},`${q}-${Pe}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:X5(F,ee).map(({date:q,inCurrentMonth:Pe})=>{const $e=cp(q),Ce=$e===b.schedule.onceDate,pe=hp(q,ie),R=q.getTime()<ie.getTime(),J=Ce?"bg-interactive-selection text-interactive-selection-foreground":R?"text-muted-foreground/40":Pe?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{R||(ae($e),j(!1))},disabled:R,className:["h-8 rounded-md typography-ui-label",J,pe&&!Ce?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",R?"cursor-not-allowed opacity-45":""].join(" "),children:q.getDate()},$e)})}),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:ye||""}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:()=>{ae(cp(ie)),_(new Date(ie.getFullYear(),ie.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(pp,{value:b.schedule.onceTime,use24Hour:Y,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:q=>y(Pe=>({...Pe,schedule:{...Pe.schedule,onceTime:q}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Qt,{value:b.schedule.timezone,onValueChange:q=>{y(Pe=>({...Pe,schedule:{...Pe.schedule,timezone:q}}))},children:[s.jsx(Jt,{className:"w-fit max-w-full",children:s.jsx(as,{})}),s.jsx(Xt,{children:op.map(q=>s.jsx(Ct,{value:q,children:q},q))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[b.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:re.map(q=>{const Pe=b.schedule.weekdays.includes(q.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",Pe?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(ss,{checked:Pe,onChange:$e=>z(q.value,$e),ariaLabel:q.label}),s.jsx("button",{type:"button",onClick:()=>z(q.value,!Pe),className:"group-hover:text-foreground",children:q.label})]},q.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:b.schedule.times.map((q,Pe)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(pp,{value:q,use24Hour:Y,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:$e=>B(Pe,$e)}),b.schedule.times.length>1?s.jsx(ve,{type:"button",size:"icon",variant:"ghost",onClick:()=>Q(Pe),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(D,{name:"close",className:"h-4 w-4"})}):null]},Pe))}),s.jsx("div",{children:s.jsxs(ve,{type:"button",size:"sm",variant:"outline",onClick:X,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Qt,{value:b.schedule.timezone,onValueChange:q=>{y(Pe=>({...Pe,schedule:{...Pe.schedule,timezone:q}}))},children:[s.jsx(Jt,{className:"w-fit max-w-full",children:s.jsx(as,{})}),s.jsx(Xt,{children:op.map(q=>s.jsx(Ct,{value:q,children:q},q))})]})]})]}),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(er,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Ui,{providerId:b.execution.providerID,modelId:b.execution.modelID,onChange:(q,Pe)=>{y($e=>({...$e,execution:{...$e.execution,providerID:q,modelID:Pe,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Qt,{value:be,disabled:!ge,onValueChange:q=>{y(Pe=>({...Pe,execution:{...Pe.execution,variant:q==="__default"?"":q}}))},children:[s.jsx(Jt,{className:"w-fit max-w-full",children:s.jsx(as,{children:q=>q==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):q})}),s.jsxs(Xt,{children:[s.jsx(Ct,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),fe.map(q=>s.jsx(Ct,{value:q,children:q},q))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(er,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(gl,{agentName:b.execution.agent,filter:q=>tf(q.mode),onChange:q=>y(Pe=>({...Pe,execution:{...Pe.execution,agent:q}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(er,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(nn,{id:"sched-prompt",ref:V,value:b.execution.prompt,onChange:q=>{const Pe=q.target.value;G(Pe);const $e=q.target.selectionStart??Pe.length;U(Pe,$e)},onKeyDown:Se,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),E?s.jsx(wf,{ref:$,searchQuery:C,onCommandSelect:xe,onClose:()=>k(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,N?s.jsx(jf,{ref:K,searchQuery:M,onFileSelect:ne,onAgentSelect:se,onClose:()=>P(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),Be=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(ss,{checked:b.enabled,onChange:q=>y(Pe=>({...Pe,enabled:q})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:v,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(ve,{type:"button",size:"sm",onClick:je,disabled:v,children:i(v?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return w?s.jsx(hr,{open:e,title:Ne,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:q=>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:Ne}),q]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:he})]}),footer:Be,children:Fe}):s.jsx(ls,{open:e,onOpenChange:q=>{!q&&Oe()||r(q)},children:s.jsxs(os,{"aria-describedby":Ie,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ss,{id:Ie,className:"sr-only",children:he}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(hs,{className:"typography-ui-label font-medium text-foreground",children:Ne}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:he})]})}),s.jsx(Nf,{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:Fe})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:Be})})]})})}function dC(t){return Qa(t,{min:0,max:23})}function uC(t,e){return Qa(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function mC(t,e){const n=Number(t),r=Number(e),a=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,i=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(a).padStart(2,"0")}:${String(i).padStart(2,"0")}`}const pC=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,a)=>r.localeCompare(a))},fC=(t,e)=>{const n=pC(t).join(", ")||"--:--",r=a=>e(a===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":a===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":a===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":a===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":a===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":a===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":a===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const a=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(i=>r(i)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:a,time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:a,time:n})}if(t.schedule.kind==="once"){const a=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),i=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:a,time:i,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.once",{date:a,time:i})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},hC=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),xp=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),a=6e4,i=60*a,l=24*i,u=n>=0;if(r<a)return e(u?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const c=Math.round(r/a);return u?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:c}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:c})}if(r<l){const c=Math.floor(r/i),p=Math.round(r%i/a),g=p>0?`${c}h ${p}m`:`${c}h`;return u?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:g}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:g})}const d=Math.floor(r/l),f=Math.round(r%l/i),m=f>0?`${d}d ${f}h`:`${d}d`;return u?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},gC={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"}},xC=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function bC(){const{t}=ct(),e=De(A=>A.isScheduledTasksDialogOpen),n=De(A=>A.setScheduledTasksDialogOpen),r=De(A=>A.isMobile),a=es(A=>A.projects),i=es(A=>A.getActiveProject()),l=Ns(A=>A.homeDirectory),{currentTheme:u}=rr(),[d,f]=Le.useState(""),[m,c]=Le.useState([]),[p,g]=Le.useState(!0),[h,x]=Le.useState(!1),[w,b]=Le.useState(null),[y,v]=Le.useState(null),S=Le.useMemo(()=>a.find(A=>A.id===d)||null,[a,d]),I=Le.useCallback(A=>{const F=A.label?.trim()||ca(A.path,l||void 0),_=Bi({id:A.id,iconImage:A.iconImage??null},{themeVariant:u.metadata.variant,iconColor:u.colors.surface.foreground}),O=A.icon?pl[A.icon]:null,V=A.color?Vi[A.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[_?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:A.iconBackground?{backgroundColor:A.iconBackground}:void 0,children:s.jsx("img",{src:_,alt:"",className:"h-full w-full object-contain",draggable:!1})}):O?s.jsx(D,{name:O,className:"h-3.5 w-3.5 shrink-0",style:V?{color:V}:void 0}):s.jsx(D,{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:F})]})},[l,u.metadata.variant,u.colors.surface.foreground]),j=Le.useCallback(async(A,F)=>{if(!A){c([]);return}F?.silent||g(!0);try{const _=await q5(A);_.sort((O,V)=>{if(O.enabled!==V.enabled)return O.enabled?-1:1;const K=O.name.localeCompare(V.name);return K!==0?K:(O.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),c(_)}catch(_){te.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),F?.silent||c([])}finally{F?.silent||g(!1)}},[t]);Le.useEffect(()=>{if(!e)return;const A=i?.id||a[0]?.id||"";f(A),A?j(A):(c([]),g(!1))},[e,i,a,j]),Le.useEffect(()=>{if(!e)return;let A=null;const F=Lh(_=>{_.type==="scheduled-task-ran"&&_.projectId===d&&(A&&clearTimeout(A),A=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{A&&clearTimeout(A),F()}},[e,d,j]);const N=Le.useCallback(async A=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await ip(d,A),await j(d),te.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),P=Le.useCallback(async(A,F)=>{if(d){v(A.id),c(_=>_.map(O=>O.id===A.id?{...O,enabled:F}:O));try{await ip(d,{...A,enabled:F}),await j(d,{silent:!0})}catch(_){te.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{v(null)}}},[d,j,t]),M=Le.useCallback(async A=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:A.name})))){v(A.id);try{await Y5(d,A.id),await j(d,{silent:!0}),te.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(_){te.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{v(null)}}},[d,j,t]),T=Le.useCallback(async A=>{if(d){v(A.id);try{await Q5(d,A.id),await Promise.all([j(d,{silent:!0}),jc()]),te.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(F){te.error(F instanceof Error?F.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{v(null)}}},[d,j,t]),E=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(Qt,{value:d||"__none",onValueChange:A=>{const F=A==="__none"?"":A;f(F),F?j(F):c([])},children:[s.jsx(Jt,{className:r?"w-full":void 0,children:S?s.jsx(as,{children:I(S)}):s.jsx(as,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(Xt,{children:[a.length===0?s.jsx(Ct,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(A=>s.jsx(Ct,{value:A.id,children:I(A)},A.id))]})]})]}),k=()=>{b(null),x(!0)},C=s.jsxs("div",{className:"space-y-4",children:[r?E:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[E,s.jsxs(ve,{onClick:k,disabled:!d,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:p?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(A=>{const F=y===A.id,_=A.state?.lastStatus||"idle",O=gC[_],V=t(_==="success"?"sessions.scheduledTasks.dialog.status.success":_==="error"?"sessions.scheduledTasks.dialog.status.error":_==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),K=A.state?.nextRunAt,$=A.state?.lastRunAt;return s.jsxs("div",{className:de("rounded-lg border border-border p-4 transition-opacity",!A.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:A.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:fC(A,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(D,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),K?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:xp(K,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:hC(K)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(D,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),_==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):$?s.jsxs(s.Fragment,{children:[O.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${O.tone})`},children:[s.jsx(D,{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:xp($,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),A.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:xC("error"),children:[s.jsx(D,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:A.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:de("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",A.enabled?"text-foreground":"text-muted-foreground",F&&"cursor-not-allowed opacity-50"),children:[s.jsx(ss,{checked:A.enabled,onChange:oe=>{P(A,oe)},ariaLabel:A.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:A.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:A.name}),disabled:F}),A.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:()=>{T(A)},disabled:F,children:[s.jsx(D,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{b(A),x(!0)},disabled:F,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:A.name}),children:[s.jsx(D,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:()=>{M(A)},disabled:F,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:A.name}),children:s.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},A.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(hr,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:A=>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")}),A]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(ve,{className:"w-full",onClick:k,disabled:!d,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:C}):s.jsx(ls,{open:e,onOpenChange:n,children:s.jsxs(os,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(bs,{children:[s.jsx(hs,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Ss,{children:t("sessions.scheduledTasks.dialog.description")})]}),C]})}),s.jsx(cC,{open:h,task:w,onOpenChange:x,onSave:N})]})}const yC=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(u=>Zt(u.path)??u.path).filter(u=>!!u)]),i=(u=>u.filter(d=>Ai(d,t.normalizedPath,r)))(e.archivedSessions),l=e.sessions.filter(u=>u.time?.archived||Zt(u.directory??null)?!1:Ai(u,t.normalizedPath,r));return Wa([...i,...l])},vC=t=>{const e=st.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:l,isSessionsLoading:u,foldersMap:d,createFolder:f,addSessionToFolder:m,cleanupSessions:c}=t;let p,g;e[0]!==m||e[1]!==a||e[2]!==i||e[3]!==c||e[4]!==f||e[5]!==d||e[6]!==u||e[7]!==l||e[8]!==n||e[9]!==r?(p=()=>{u||n.forEach(h=>{const x=od(h.normalizedPath),w=yC(h,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:l}),b=new Set(w.map(wC)),y=d[x]??[],v=new Map(y.map(jC));w.forEach(S=>{const I=ub(S,h.normalizedPath),j=I.toLowerCase();let N=v.get(j);N||(N=f(x,I),v.set(j,N)),N.sessionIds.includes(S.id)||m(x,N.id,S.id)}),c(x,b)})},g=[n,r,a,i,l,u,d,f,m,c],e[0]=m,e[1]=a,e[2]=i,e[3]=c,e[4]=f,e[5]=d,e[6]=u,e[7]=l,e[8]=n,e[9]=r,e[10]=p,e[11]=g):(p=e[10],g=e[11]),o.useEffect(p,g)};function wC(t){return t.id}function jC(t){return[t.name.toLowerCase(),t]}const NC=t=>{const e=st.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:l,projectRootBranches:u,lastRepoStatus:d,buildGroupedSessions:f,hasSessionSearchQuery:m,normalizedSessionSearchQuery:c,filterSessionNodesForSearch:p,buildGroupSearchText:g,foldersMap:h}=t;let x;if(e[0]!==i||e[1]!==f||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==l||e[7]!==u){let T;e[9]!==i||e[10]!==f||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==l||e[15]!==u?(T=E=>{const k=Wa([...r(E),...a(E)]),C=i.get(E.normalizedPath)??[],A=l.has(E.id)?!!l.get(E.id):d,F=f(k,E.normalizedPath,C,u.get(E.id)??null,A);return{project:E,groups:F}},e[9]=i,e[10]=f,e[11]=a,e[12]=r,e[13]=d,e[14]=l,e[15]=u,e[16]=T):T=e[16],x=n.map(T),e[0]=i,e[1]=f,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=l,e[7]=u,e[8]=x}else x=e[8];const w=x,b=w;let y;if(e[17]!==g||e[18]!==p||e[19]!==h||e[20]!==m||e[21]!==c||e[22]!==b){e:{const T=new WeakMap;if(!m){y=T;break e}const E=k=>k.reduce((C,A)=>C+1+E(A.children),0);b.forEach(k=>{k.groups.forEach(C=>{const A=p(C.sessions,c),F=E(A),_=g(C).includes(c),O=Zt(C.directory??null),K=(O?h[O]??[]:[]).filter($=>$.name.toLowerCase().includes(c)).length;T.set(C,{filteredNodes:A,matchedSessionCount:F,folderNameMatchCount:K,groupMatches:_,hasMatch:_||F>0||K>0})})}),y=T}e[17]=g,e[18]=p,e[19]=h,e[20]=m,e[21]=c,e[22]=b,e[23]=y}else y=e[23];const v=y;let S;e:{if(!m){S=b;break e}let T;if(e[24]!==v||e[25]!==b){let E;e[27]!==v?(E=k=>({...k,groups:k.groups.filter(C=>v.get(C)?.hasMatch===!0)}),e[27]=v,e[28]=E):E=e[28],T=b.map(E).filter(SC),e[24]=v,e[25]=b,e[26]=T}else T=e[26];S=T}const I=S,j=m?I:b;let N;e:{if(!m){N=0;break e}let T;if(e[29]!==v||e[30]!==j){let E;e[32]!==v?(E=(k,C)=>k+C.groups.reduce((A,F)=>{const _=v.get(F);if(!_)return A;const O=_.folderNameMatchCount+(_.groupMatches?1:0);return A+_.matchedSessionCount+O},0),e[32]=v,e[33]=E):E=e[33],T=j.reduce(E,0),e[29]=v,e[30]=j,e[31]=T}else T=e[31];N=T}const P=N;let M;return e[34]!==v||e[35]!==w||e[36]!==P||e[37]!==I||e[38]!==j||e[39]!==b?(M={projectSections:w,visibleProjectSections:b,groupSearchDataByGroup:v,searchableProjectSections:I,sectionsForRender:j,searchMatchCount:P},e[34]=v,e[35]=w,e[36]=P,e[37]=I,e[38]=j,e[39]=b,e[40]=M):M=e[40],M};function SC(t){return t.groups.length>0}const kC=t=>{const e=st.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:l,handleSessionSelect:u,newSessionDraftOpen:d,mobileVariant:f,openNewSessionDraft:m,setActiveMainTab:c,setSessionSwitcherOpen:p,sessions:g,worktreeMetadata:h}=t;let x,w;if(e[0]!==n){w=new Map,x=new Map;const E=(k,C,A,F)=>{w.has(k)||w.set(k,new Map);const _=w.get(k);F.forEach(O=>{const V=Zt(O.worktree?.path??O.session.directory??A??C);_.set(O.session.id,{directory:V}),x.has(k)||x.set(k,{id:O.session.id,directory:V}),O.children.length>0&&E(k,C,V,O.children)})};n.forEach(k=>{k.groups.forEach(C=>{E(k.project.id,k.project.normalizedPath,C.directory,C.sessions)})}),e[0]=n,e[1]=x,e[2]=w}else x=e[1],w=e[2];let b;e[3]!==x||e[4]!==w?(b={metaByProject:w,firstSessionByProject:x},e[3]=x,e[4]=w,e[5]=b):b=e[5];const y=b,v=o.useRef(null);let S,I;e[6]!==r||e[7]!==a||e[8]!==l||e[9]!==u||e[10]!==f||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==y||e[15]!==c||e[16]!==i||e[17]!==p?(S=()=>{if(!r||d||v.current===r)return;const E=n.find(V=>V.project.id===r);if(!E)return;v.current=r;const k=y.metaByProject.get(r);if(l&&k&&k.has(l)){i(V=>{if(V.get(r)===l)return V;const K=new Map(V);return K.set(r,l),K});return}if(!k||k.size===0){c("chat"),f&&p(!1),m({directoryOverride:E.project.normalizedPath});return}const C=a.get(r),A=C&&k.has(C)?C:null,F=y.firstSessionByProject.get(r)?.id??null,_=A??F;if(!_||_===l)return;const O=k.get(_)?.directory??null;u(_,O,!1,r)},I=[r,a,l,u,d,f,m,n,y,c,p,i],e[6]=r,e[7]=a,e[8]=l,e[9]=u,e[10]=f,e[11]=d,e[12]=m,e[13]=n,e[14]=y,e[15]=c,e[16]=i,e[17]=p,e[18]=S,e[19]=I):(S=e[18],I=e[19]),o.useLayoutEffect(S,I);let j,N;e[20]!==r||e[21]!==l||e[22]!==y||e[23]!==i?(j=()=>{if(!r||!l)return;const E=y.metaByProject.get(r);!E||!E.has(l)||i(k=>{if(k.get(r)===l)return k;const C=new Map(k);return C.set(r,l),C})},N=[r,l,y,i],e[20]=r,e[21]=l,e[22]=y,e[23]=i,e[24]=j,e[25]=N):(j=e[24],N=e[25]),o.useEffect(j,N);let P;if(e[26]!==l||e[27]!==g||e[28]!==h){e:{if(!l){P=null;break e}const E=h.get(l)?.path;if(E){P=Zt(E)??E;break e}let k;e[30]!==l?(k=A=>A.id===l,e[30]=l,e[31]=k):k=e[31];const C=g.find(k);if(!C){P=null;break e}P=Zt(C.directory??null)}e[26]=l,e[27]=g,e[28]=h,e[29]=P}else P=e[29];const M=P;let T;return e[32]!==M?(T={currentSessionDirectory:M},e[32]=M,e[33]=T):T=e[33],T},CC=t=>{const e=st.c(4);let n;e[0]!==t?(n=(i,l)=>{const u=t.get(i);if(!u||u.length===0)return l;const d=new Map(l.map(PC)),f=[];return u.forEach(m=>{const c=d.get(m);c&&(f.push(c),d.delete(m))}),l.forEach(m=>{d.has(m.id)&&f.push(m)}),f},e[0]=t,e[1]=n):n=e[1];const r=n;let a;return e[2]!==r?(a={getOrderedGroups:r},e[2]=r,e[3]=a):a=e[3],a};function PC(t){return[t.id,t]}const mo=t=>!!t.time?.archived,IC=t=>{const{t:e}=ct(),n=o.useCallback(l=>[l.label,l.branch??"",l.description??"",l.directory??""].join(" ").toLowerCase(),[]),r=o.useCallback(l=>{const u=Zt(l.directory??null)??"";return`${(l.title||e("sessions.sidebar.session.untitled")).trim()} ${u}`.toLowerCase()},[e]),a=o.useCallback((l,u)=>u?l.flatMap(d=>{if(r(d.session).includes(u))return[d];const m=a(d.children,u);return m.length===0?[]:[{...d,children:m}]}):l,[r]),i=o.useCallback((l,u,d,f,m)=>{const c=Zt(u??null),p=Wa(l).sort((E,k)=>Fa(E,k,t.pinnedSessionIds)),g=new Map(p.map(E=>[E.id,E])),h=new Map;p.forEach(E=>{const k=E.parentID;if(!k)return;const C=g.get(k);if(!C||mo(C)!==mo(E))return;const A=h.get(k)??[];A.push(E),h.set(k,A)}),h.forEach(E=>E.sort((k,C)=>Fa(k,C,t.pinnedSessionIds)));const x=new Map;d.forEach(E=>{if(E.path){const k=Zt(E.path)??E.path;x.set(k,E)}});const w=E=>{const k=Zt(E.directory??null),C=t.worktreeMetadata.get(E.id)??null;if(C)return C;if(k){const A=x.get(k)??null;if(A&&k!==c)return A}return null},b=E=>{const k=h.get(E.id)??[];return{session:E,children:k.map(C=>b(C)),worktree:w(E)}},y=p.filter(E=>{const k=E.parentID;if(!k)return!0;const C=g.get(k);return C?mo(C)!==mo(E):!0}),v=new Map,S="__archived__",I=E=>{if(E.time?.archived)return S;const k=Zt(t.worktreeMetadata.get(E.id)?.path??null),C=Zt(E.directory??null);if(!k&&!C)return S;const A=Zt(E.project?.worktree??null),F=k??C??A;return F?F!==c&&x.has(F)?F:F===c?c??"__project_root__":S:S};y.forEach(E=>{const k=b(E),C=I(E);v.has(C)||v.set(C,[]),v.get(C)?.push(k)});const j=c??"__project_root__",N=[{id:"root",label:m&&f&&f!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:f}):e("sessions.sidebar.grouping.projectRoot"),branch:f??null,description:c?Ti(c,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:c,folderScopeKey:c,sessions:v.get(j)??[]}],P=new Map;d.forEach(E=>{const k=Zt(E.path)??E.path,C=v.get(k)??[],A=C.length>0,F=C.reduce((_,O)=>{const V=Number(O.session.time?.updated??O.session.time?.created??0);return Number.isFinite(V)?Math.max(_,V):_},0);P.set(k,{hasActiveSession:A,lastUpdatedAt:F})}),[...d].sort((E,k)=>{const C=Zt(E.path)??E.path,A=Zt(k.path)??k.path,F=P.get(C)??{hasActiveSession:!1,lastUpdatedAt:0},_=P.get(A)??{hasActiveSession:!1,lastUpdatedAt:0};if(F.hasActiveSession!==_.hasActiveSession)return F.hasActiveSession?-1:1;if(F.hasActiveSession&&_.hasActiveSession)return _.lastUpdatedAt-F.lastUpdatedAt;const O=(E.label||E.branch||E.name||E.path||"").toLowerCase(),V=(k.label||k.branch||k.name||k.path||"").toLowerCase();return O.localeCompare(V)}).forEach(E=>{const k=Zt(E.path)??E.path,C=t.gitBranches.get(k)?.trim()||null,A=E.branch?.trim()||null,_=!!(C&&A&&E.label&&iu(E.label)===iu(A))?C:E.label||E.name||ca(k,t.homeDirectory)||k;N.push({id:`worktree:${k}`,label:_,branch:C||A,description:Ti(k,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:E,directory:k,folderScopeKey:k,sessions:v.get(k)??[]})});const T=v.get(S)??[];return T.length>0&&N.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&&c?od(c):null,sessions:T}),N},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:a,buildGroupedSessions:i}},DC=t=>{const e=st.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:a,sessionSearchContainerRef:i}=t;let l,u;e[0]!==n||e[1]!==a?(l=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{a.current?.focus(),a.current?.select()});return()=>window.cancelAnimationFrame(m)},u=[n,a],e[0]=n,e[1]=a,e[2]=l,e[3]=u):(l=e[2],u=e[3]),o.useEffect(l,u);let d,f;e[4]!==n||e[5]!==i||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=c=>{i.current&&(i.current.contains(c.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},f=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=d,e[8]=f):(d=e[7],f=e[8]),o.useEffect(d,f)},TC=t=>{const e=st.c(42),{t:n}=ct(),[r,a]=o.useState(null),i=o.useRef(null);let l,u;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>()=>{i.current&&clearTimeout(i.current)},u=[],e[0]=l,e[1]=u):(l=e[0],u=e[1]),o.useEffect(l,u);let d;e[2]!==t?(d=(_,O,V,K)=>{if(V)return;const $=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(K&&K!==t.activeProjectId&&t.setActiveProjectIdOnly(K),O&&O!==t.currentDirectory&&t.setDirectory(O,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),_===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(_),$();return}t.setCurrentSession(_,O??null),t.onSessionSelected?.(_),$()},e[2]=t,e[3]=d):d=e[3];const f=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const c=m;let p;e[6]!==t?(p=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=p):p=e[7];const g=p;let h;e[8]!==t?(h=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=h):h=e[9];const x=h;let w;e[10]!==t||e[11]!==n?(w=async _=>{const O=await t.shareSession(_.id);O&&O.share?.url?te.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):te.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=w):w=e[12];const b=w;let y;e[13]!==n?(y=(_,O)=>{An(_).then(V=>{if(!V.ok){te.error(n("sessions.sidebar.session.share.copyUrlError"));return}a(O),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{a(null),i.current=null},2e3)}).catch(()=>{te.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=y):y=e[14];const v=y;let S;e[15]!==t||e[16]!==n?(S=async _=>{await t.unshareSession(_)?te.success(n("sessions.sidebar.session.unshare.success")):te.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=S):S=e[17];const I=S;let j;e[18]!==t.childrenMap?(j=_=>{const O=[],V=K=>{(t.childrenMap.get(K)??[]).forEach(oe=>{O.push(oe),V(oe.id)})};return V(_),O},e[18]=t.childrenMap,e[19]=j):j=e[19];const N=j,P=EC;let M;e[20]!==t||e[21]!==N||e[22]!==n?(M=async(_,O,V)=>{const K=O?.archivedBucket===!0,$=V?.descendantIds??P(N(_.id),K).map(MC);if($.length===0){(K?await t.deleteSession(_.id):await t.archiveSession(_.id))?te.success(n(K?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):te.error(n(K?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const oe=[_.id,...$];if(K){const{deletedIds:ee,failedIds:re}=await t.deleteSessions(oe);ee.length>0&&te.success(ee.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:ee.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:ee.length})),re.length>0&&te.error(re.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:re.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:re.length}));return}const{archivedIds:L,failedIds:Y}=await t.archiveSessions(oe);L.length>0&&te.success(L.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:L.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:L.length})),Y.length>0&&te.error(Y.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Y.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:Y.length}))},e[20]=t,e[21]=N,e[22]=n,e[23]=M):M=e[23];const T=M;let E;e[24]!==t||e[25]!==N||e[26]!==T?(E=(_,O)=>{const V=O?.archivedBucket===!0,K=P(N(_.id),V).map(RC);if(!t.showDeletionDialog){T(_,O,{descendantIds:K});return}t.setDeleteSessionConfirm({session:_,descendantCount:K.length,descendantIds:K,archivedBucket:V})},e[24]=t,e[25]=N,e[26]=T,e[27]=E):E=e[27];const k=E;let C;e[28]!==t||e[29]!==T?(C=async()=>{if(!t.deleteSessionConfirm)return;const{session:_,archivedBucket:O,descendantIds:V}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await T(_,{archivedBucket:O},{descendantIds:V})},e[28]=t,e[29]=T,e[30]=C):C=e[30];const A=C;let F;return e[31]!==A||e[32]!==r||e[33]!==x||e[34]!==v||e[35]!==k||e[36]!==g||e[37]!==c||e[38]!==f||e[39]!==b||e[40]!==I?(F={copiedSessionId:r,handleSessionSelect:f,handleSessionDoubleClick:c,handleSaveEdit:g,handleCancelEdit:x,handleShareSession:b,handleCopyShareUrl:v,handleUnshareSession:I,handleDeleteSession:k,confirmDeleteSession:A},e[31]=A,e[32]=r,e[33]=x,e[34]=v,e[35]=k,e[36]=g,e[37]=c,e[38]=f,e[39]=b,e[40]=I,e[41]=F):F=e[41],F};function AC(t){return!t.time?.archived}function EC(t,e){return e?t:t.filter(AC)}function MC(t){return t.id}function RC(t){return t.id}const FC=["project:active:","project:archived:","recent:active:","recent:archived:"],LC=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:a,sessions:i,setPinnedSessionIds:l,groupOrderByProject:u,activeSessionByProject:d,collapsedGroups:f,setExpandedParents:m,setCollapsedProjects:c}=t,p=o.useRef(null),g=o.useRef(null),h=o.useCallback(()=>{if(e)return;const w=g.current;if(g.current=null,p.current=null,!w)return;const{projects:b}=es.getState(),y=b.map(v=>({...v,sidebarCollapsed:w.has(v.id)}));rs({projects:y}).catch(()=>{})},[e]),x=o.useCallback(w=>{typeof window>"u"||e||(g.current=w,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{h()},700))},[e,h]);return o.useEffect(()=>()=>{typeof window<"u"&&p.current!==null&&window.clearTimeout(p.current),p.current=null,g.current=null},[]),o.useEffect(()=>{try{const w=r.getItem(a.sessionExpanded);if(w){const y=JSON.parse(w);Array.isArray(y)&&m(new Set(y.filter(v=>typeof v=="string")))}else{const y=r.getItem(a.sessionExpandedLegacy);if(y){try{const v=JSON.parse(y);if(Array.isArray(v)){const S=new Set;if(v.forEach(I=>{typeof I!="string"||I.length===0||FC.forEach(j=>S.add(`${j}${I}`))}),S.size>0){m(S);try{r.setItem(a.sessionExpanded,JSON.stringify(Array.from(S)))}catch{}}}}catch{}try{r.removeItem?.(a.sessionExpandedLegacy)}catch{}}}const b=r.getItem(a.projectCollapse);if(b){const y=JSON.parse(b);Array.isArray(y)&&c(new Set(y.filter(v=>typeof v=="string")))}}catch{}},[a.projectCollapse,a.sessionExpanded,a.sessionExpandedLegacy,r,c,m]),o.useEffect(()=>{if(!n)return;const w=new Set(i.map(b=>b.id));l(b=>{let y=!1;const v=new Set;return b.forEach(S=>{w.has(S)?v.add(S):y=!0}),y?v:b})},[n,i,l]),o.useEffect(()=>{try{const w=Object.fromEntries(u.entries());r.setItem(a.groupOrder,JSON.stringify(w))}catch{}},[u,a.groupOrder,r]),o.useEffect(()=>{try{const w=Object.fromEntries(d.entries());r.setItem(a.projectActiveSession,JSON.stringify(w))}catch{}},[d,a.projectActiveSession,r]),o.useEffect(()=>{try{r.setItem(a.groupCollapse,JSON.stringify(Array.from(f)))}catch{}},[f,a.groupCollapse,r]),{scheduleCollapsedProjectsPersist:x}},OC=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length);let i=0;const l=async()=>{for(;;){const u=i;if(i+=1,u>=t.length)return;a[u]=await n(t[u])}};return await Promise.all(Array.from({length:r},()=>l())),a},$C=t=>{const e=st.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:l}=wn(),u=yn(_C);let d,f;e[0]!==u||e[1]!==l||e[2]!==n||e[3]!==a?(d=()=>{if(!l||n.length===0){a(new Map);return}n.forEach(w=>{u(w.normalizedPath,l)})},f=[n,l,u,a],e[0]=u,e[1]=l,e[2]=n,e[3]=a,e[4]=d,e[5]=f):(d=e[4],f=e[5]),o.useEffect(d,f);let m,c;e[6]!==r||e[7]!==n||e[8]!==a?(m=()=>{const w=new Map;n.forEach(b=>{w.set(b.id,r.get(b.normalizedPath)?.isGitRepo??null)}),a(w)},c=[n,r,a],e[6]=r,e[7]=n,e[8]=a,e[9]=m,e[10]=c):(m=e[9],c=e[10]),o.useEffect(m,c);let p;if(e[11]!==r||e[12]!==n){let w;e[14]!==r?(w=b=>{const y=r.get(b.normalizedPath)?.branch??"";return`${b.id}:${y}`},e[14]=r,e[15]=w):w=e[15],p=n.map(w).join("|"),e[11]=r,e[12]=n,e[13]=p}else p=e[13];const g=p;let h;e[16]!==n||e[17]!==i?(h=()=>{let w=!1;return(async()=>{const y=await OC(n,2,BC);w||i(v=>{const S=new Map(v);return y.forEach(I=>{const{id:j,branch:N}=I;N&&S.set(j,N)}),S})})(),()=>{w=!0}},e[16]=n,e[17]=i,e[18]=h):h=e[18];let x;e[19]!==n||e[20]!==g||e[21]!==i?(x=[n,g,i],e[19]=n,e[20]=g,e[21]=i,e[22]=x):x=e[22],o.useEffect(h,x)};function _C(t){return t.ensureStatus}function zC(){return null}async function BC(t){const e=await fl(t.normalizedPath).catch(zC);return{id:t.id,branch:e}}const VC=t=>{const e=st.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let l;e[0]!==r?(l=new Map,r.forEach(g=>{const h=Zt(g.directory??null)??Zt(g.project?.worktree??null);if(!h)return;const x=l.get(h)??[];x.push(g),l.set(h,x)}),e[0]=r,e[1]=l):l=e[1];const u=l;let d;e[2]!==i||e[3]!==n||e[4]!==u?(d=g=>{const h=n?[]:i.get(g.normalizedPath)??[],x=[g.normalizedPath,...h.map(UC).filter(KC)],w=new Set,b=[];return x.forEach(y=>{(u.get(y)??[]).forEach(S=>{w.has(S.id)||(w.add(S.id),b.push(S))})}),b},e[2]=i,e[3]=n,e[4]=u,e[5]=d):d=e[5];const f=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=g=>{if(n){const v=a.filter(I=>{const j=Zt(I.directory??null),N=Zt(I.project?.worktree??null);return j?j===g.normalizedPath:N===g.normalizedPath}),S=r.filter(I=>I.time?.archived||Zt(I.directory??null)?!1:Zt(I.project?.worktree??null)===g.normalizedPath);return Wa([...v,...S])}const h=n?[]:i.get(g.normalizedPath)??[],x=new Set([g.normalizedPath,...h.map(WC).filter(HC)]),b=(v=>v.filter(S=>Ai(S,g.normalizedPath,x)))(a),y=r.filter(v=>{if(v.time?.archived||Zt(v.directory??null))return!1;const I=Zt(v.project?.worktree??null);return I?I===g.normalizedPath||I.startsWith(`${g.normalizedPath}/`):!1});return Wa([...b,...y])},e[6]=a,e[7]=i,e[8]=n,e[9]=r,e[10]=m):m=e[10];const c=m;let p;return e[11]!==c||e[12]!==f?(p={getSessionsForProject:f,getArchivedSessionsForProject:c},e[11]=c,e[12]=f,e[13]=p):p=e[13],p};function UC(t){return Zt(t.path)??t.path}function KC(t){return!!t}function WC(t){return Zt(t.path)??t.path}function HC(t){return!!t}const GC=t=>{const e=st.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:a,normalizedProjects:i,isVSCode:l,availableWorktreesByProject:u,cleanupSessions:d}=t;let f,m;e[0]!==a||e[1]!==u||e[2]!==d||e[3]!==n||e[4]!==l||e[5]!==i||e[6]!==r?(f=()=>{if(n)return;const c=new Map;r.forEach(h=>{const x=Zt(h.directory??null);if(!x)return;const w=c.get(x);if(w){w.add(h.id);return}c.set(x,new Set([h.id]))}),i.forEach(h=>{const x=od(h.normalizedPath),w=l?[]:u.get(h.normalizedPath)??[],b=new Set([h.normalizedPath,...w.map(qC).filter(YC)]),y=Wa([...a,...r.filter(v=>v.time?.archived||Zt(v.directory??null)?!1:Ai(v,h.normalizedPath,b))]).filter(v=>Ai(v,h.normalizedPath,b));c.set(x,new Set(y.map(QC)))});const p=Pn.getState().foldersMap;new Set([...Object.keys(p),...c.keys()]).forEach(h=>{d(h,c.get(h)??new Set)})},m=[a,u,d,n,l,i,r],e[0]=a,e[1]=u,e[2]=d,e[3]=n,e[4]=l,e[5]=i,e[6]=r,e[7]=f,e[8]=m):(f=e[7],m=e[8]),o.useEffect(f,m)};function qC(t){return Zt(t.path)??t.path}function YC(t){return!!t}function QC(t){return t.id}const JC=t=>{const e=st.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[l,u]=o.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(c=>{c.forEach(p=>{const g=p.target.dataset.projectId;g&&u(h=>{const x=new Set(h);return p.isIntersecting?x.delete(g):x.add(g),x})})},{threshold:0});return a.current.forEach(c=>{c&&m.observe(c)}),()=>m.disconnect()},e[1]=n,e[2]=a,e[3]=d):d=e[3];let f;return e[4]!==n||e[5]!==a||e[6]!==r?(f=[n,a,r],e[4]=n,e[5]=a,e[6]=r,e[7]=f):f=e[7],o.useEffect(d,f),l},XC=9e4,ZC=15e3,e4=5*6e4,t4=[2e3,5e3],s4=6e4,n4=2*6e4,r4=5*6e4,a4=720*6e4,i4="vinci.github-pr-status",o4=t=>t==="closed"||t==="merged",l4=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Lo=(t,e,n)=>`${t}::${e}`,po=new Map,fo=new Map,di=new Set,bp=new Map,hi=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),sl=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,vd=t=>{const e=sl(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},$h=(t,e)=>Object.entries(t).filter(([,n])=>vd(n)===e).map(([n])=>n),c4=(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}}},ho=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},d4=(t,e,n)=>{const r=$h(t,e),a=r.map(d=>ho(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=ho(t[n]);if(i&&vd(t[n])===e)return i;const l=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&ho(d)));if(l)return ho(l);const u=a.find(d=>!!d.remoteName);return u||(a[0]??null)},u4=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:sl(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),m4=t=>({...hi(),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}),Ea=vn()($i((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:hi()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??hi();return{entries:{...a.entries,[n]:c4(i,r)}}})},startWatching:n=>{if(t(i=>{const l=i.entries[n]??hi();return{entries:{...i.entries,[n]:{...l,watchers:l.watchers+1}}}}),po.has(n))return;const r=i=>{const l=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const d=e().entries[n];!d||d.watchers<=0||d.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},i),u=fo.get(n)??[];u.push(l),fo.set(n,u)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),t4.forEach(i=>r(i));const a=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const i=e().entries[n];if(!i||i.watchers<=0)return;if(!!!i.status?.pr){const f=Date.now();if(f-i.lastDiscoveryPollAt<e4)return;t(m=>{const c=m.entries[n];return c?{entries:{...m.entries,[n]:{...c,lastDiscoveryPollAt:f}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(o4(i.status?.pr?.state))return;const u=Date.now()-i.lastRefreshAt,d=l4(i.status)?s4:i.status?.checks&&i.status.checks.state!=="pending"?r4:n4;u<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},ZC);po.set(n,a)},stopWatching:n=>{t(l=>{const u=l.entries[n];if(!u)return l;const d=Math.max(0,u.watchers-1);return{entries:{...l.entries,[n]:{...u,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const a=po.get(n);typeof a=="number"&&window.clearInterval(a),po.delete(n);const i=fo.get(n);i&&i.length>0&&i.forEach(l=>{window.clearTimeout(l)}),fo.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],l=vd(i);if(!i||!l)return;const u=$h(a.entries,l),d=u.some(c=>!!a.entries[c]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const f=bp.get(l)??0;if(!r?.force&&Date.now()-f<XC||di.has(l))return;const m=d4(a.entries,l,n);if(m){if(di.add(l),bp.set(l,Date.now()),t(c=>{const p={...c.entries};return u.forEach(g=>{const h=p[g];h&&(p[g]={...h,lastRefreshAt:Date.now(),isLoading:r?.silent?h.isLoading:!0,error:null})}),{entries:p}}),m.githubAuthChecked&&m.githubConnected===!1){t(c=>{const p={...c.entries};return u.forEach(g=>{const h=p[g];h&&(p[g]={...h,status:{connected:!1},error:null,isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:p}}),di.delete(l);return}if(!m.github?.prStatus){t(c=>{const p={...c.entries};return u.forEach(g=>{const h=p[g];h&&(p[g]={...h,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:p}}),di.delete(l);return}try{t(p=>({...p,activeRequestCount:p.activeRequestCount+1,totalRequestCount:p.totalRequestCount+1}));const c=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(p=>{const g={...p.entries};return u.forEach(h=>{const x=g[h];if(!x)return;const w=x.status?.pr,b=c.pr,v=!!(b&&w&&b.number===w.number&&(!b.body||!b.body.trim())&&typeof w.body=="string"&&w.body.trim().length>0)&&b&&w?.body?{...c,pr:{...b,body:w.body}}:c,S=v.resolvedRemoteName??x.resolvedRemoteName??m.remoteName??null,I=sl(x)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};g[h]={...x,status:v,error:null,isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0,resolvedRemoteName:S,identity:{...I,remoteName:S??I.remoteName??null}}}),{entries:g}})}catch(c){const p=c instanceof Error?c.message:String(c);t(g=>{const h={...g.entries};return u.forEach(x=>{const w=h[x];w&&(h[x]={...w,error:p||"Failed to load PR status",isLoading:r?.silent?w.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?w.isInitialStatusResolved:!0})}),{entries:h}})}finally{di.delete(l),t(c=>({...c,activeRequestCount:Math.max(0,c.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const a=Array.from(new Set(n.map(i=>{const l=i.directory.trim(),u=i.branch.trim();return!l||!u?null:Lo(l,u,i.remoteName??null)}).filter(i=>!!i)));await Promise.all(a.map(i=>e().refresh(i,r)))},updateStatus:(n,r)=>{t(a=>{const i=a.entries[n]??hi();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:i4,storage:il(()=>Vr()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=sl(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<a4}).map(([e,n])=>[e,u4(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,m4(i)]))}}})),p4=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",a=e.mergeable===!1||r==="blocked"||r==="dirty";return n||a?"blocked":"open"},f4=t=>{const e=p4(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}},h4=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 cc=new Map,yp=new Map;const g4=t=>{const e=st.c(2);let n;return e[0]!==t?(n=r=>{const a=new Map,i=new Map;for(const l of t){const u=r.entries[l];if(!u)continue;const d=f4(u);if(!d)continue;const f=h4(d);a.set(l,f),i.set(l,d)}if(a.size===cc.size){let l=!0;for(const[u,d]of a)if(cc.get(u)!==d){l=!1;break}if(l)return yp}return cc=a,yp=i,i},e[0]=t,e[1]=n):n=e[1],Ea(n)},x4=t=>{const e=st.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:l,onRename:u,onDelete:d,renderSessionNode:f,groupDirectory:m,projectId:c,mobileVariant:p,alwaysShowActions:g,isRenaming:h,renameDraft:x,onRenameDraftChange:w,onRenameSave:b,onRenameCancel:y,droppableRef:v,isDropTarget:S,onNewSession:I,onNewSubFolder:j,depth:N,hideActions:P,archivedBucket:M}=t,E=g===void 0?p===void 0?!1:p:g,k=h===void 0?!1:h,C=x===void 0?"":x,A=S===void 0?!1:S,F=N===void 0?0:N,_=P===void 0?!1:P,O=M===void 0?!1:M,{t:V}=ct(),[K,$]=o.useState(!1),[oe,L]=o.useState(""),Y=o.useRef(null),ee=k||K,re=k?C:oe;let fe;e[0]!==n.name?(fe=()=>{L(n.name),$(!0)},e[0]=n.name,e[1]=fe):fe=e[1];const ge=fe;let be;e[2]!==re||e[3]!==n.name||e[4]!==k||e[5]!==u||e[6]!==b?(be=()=>{const J=re.trim();J&&J!==n.name&&u(J),k&&b&&b(),$(!1),L("")},e[2]=re,e[3]=n.name,e[4]=k,e[5]=u,e[6]=b,e[7]=be):be=e[7];const z=be;let B;e[8]!==k||e[9]!==y?(B=()=>{k&&y&&y(),$(!1),L("")},e[8]=k,e[9]=y,e[10]=B):B=e[10];const Q=B;let X;e[11]!==k||e[12]!==w?(X=J=>{k&&w?w(J):L(J)},e[11]=k,e[12]=w,e[13]=X):X=e[13];const ie=X;let le,ye;e[14]!==k?(le=()=>{if(!k)return;const J=()=>{const Ae=Y.current;Ae&&(Ae.focus(),Ae.select())},H=requestAnimationFrame(J),Ee=window.setTimeout(J,0);return()=>{cancelAnimationFrame(H),window.clearTimeout(Ee)}},ye=[k],e[14]=k,e[15]=le,e[16]=ye):(le=e[15],ye=e[16]),o.useEffect(le,ye);const W=i?"folder":"folder-open",ae=F>0&&"ml-3";let U;e[17]!==ae?(U=de("oc-folder",ae),e[17]=ae,e[18]=U):U=e[18];const G=A&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ne;e[19]!==G?(ne=de("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",G),e[19]=G,e[20]=ne):ne=e[20];const se=ee?void 0:l,xe=ee?void 0:"button",Se=ee?void 0:0;let je;e[21]!==l||e[22]!==ee?(je=ee?void 0:J=>{(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),l())},e[21]=l,e[22]=ee,e[23]=je):je=e[23];let Ie;e[24]!==n.name||e[25]!==i||e[26]!==V?(Ie=i?V("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):V("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=i,e[26]=V,e[27]=Ie):Ie=e[27];const Oe=O?E?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let Ne;e[28]!==Oe?(Ne=de("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",Oe),e[28]=Oe,e[29]=Ne):Ne=e[29];const he=A?"text-primary":"text-muted-foreground";let Fe;e[30]!==he?(Fe=de("h-3.5 w-3.5 flex-shrink-0",he),e[30]=he,e[31]=Fe):Fe=e[31];let Be;e[32]!==W||e[33]!==Fe?(Be=s.jsx(D,{name:W,className:Fe}),e[32]=W,e[33]=Fe,e[34]=Be):Be=e[34];let q;e[35]!==re||e[36]!==n.name||e[37]!==Q||e[38]!==ie||e[39]!==z||e[40]!==i||e[41]!==A||e[42]!==ee||e[43]!==r||e[44]!==V?(q=ee?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:y4,onMouseDown:v4,onSubmit:J=>{J.preventDefault(),z()},children:[s.jsx("input",{ref:Y,value:re,onChange:J=>ie(J.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:w4,onPointerDown:j4,onMouseDown:N4,onKeyDown:J=>{if(J.key==="Escape"){J.stopPropagation(),Q();return}(J.key===" "||J.key==="Enter")&&J.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:S4,onPointerDown:k4,onMouseDown:C4,children:s.jsx(D,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),Q()},onPointerDown:P4,onMouseDown:I4,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:de("typography-ui-label font-semibold truncate",A?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=re,e[36]=n.name,e[37]=Q,e[38]=ie,e[39]=z,e[40]=i,e[41]=A,e[42]=ee,e[43]=r,e[44]=V,e[45]=q):q=e[45];let Pe;e[46]!==Ne||e[47]!==Be||e[48]!==q?(Pe=s.jsxs("div",{className:Ne,children:[Be,q]}),e[46]=Ne,e[47]=Be,e[48]=q,e[49]=Pe):Pe=e[49];let $e;e[50]!==E||e[51]!==O||e[52]!==F||e[53]!==n.name||e[54]!==ge||e[55]!==_||e[56]!==d||e[57]!==I||e[58]!==j||e[59]!==ee||e[60]!==V?($e=!ee&&(!_||O)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:de("flex items-center gap-0.5 transition-opacity",E?"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&&I?s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),I()},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(D,{name:"add",className:"h-3.5 w-3.5"})}):null,!O&&j&&F===0?s.jsx("button",{type:"button",onClick:J=>{J.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(D,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,O?null:s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),ge()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(D,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:J=>{J.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(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=E,e[51]=O,e[52]=F,e[53]=n.name,e[54]=ge,e[55]=_,e[56]=d,e[57]=I,e[58]=j,e[59]=ee,e[60]=V,e[61]=$e):$e=e[61];let Ce;e[62]!==v||e[63]!==ne||e[64]!==se||e[65]!==xe||e[66]!==Se||e[67]!==je||e[68]!==Ie||e[69]!==Pe||e[70]!==$e?(Ce=s.jsxs("div",{ref:v,className:ne,onClick:se,role:xe,tabIndex:Se,onKeyDown:je,"aria-label":Ie,children:[Pe,$e]}),e[62]=v,e[63]=ne,e[64]=se,e[65]=xe,e[66]=Se,e[67]=je,e[68]=Ie,e[69]=Pe,e[70]=$e,e[71]=Ce):Ce=e[71];let pe;e[72]!==O||e[73]!==m||e[74]!==i||e[75]!==c||e[76]!==f||e[77]!==r||e[78]!==a||e[79]!==V?(pe=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(J=>f(J,0,m??null,c??null,O)):a?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:V("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=O,e[73]=m,e[74]=i,e[75]=c,e[76]=f,e[77]=r,e[78]=a,e[79]=V,e[80]=pe):pe=e[80];let R;return e[81]!==U||e[82]!==Ce||e[83]!==pe?(R=s.jsxs("div",{className:U,children:[Ce,pe]}),e[81]=U,e[82]=Ce,e[83]=pe,e[84]=R):R=e[84],R},b4=o.memo(x4);function y4(t){return t.stopPropagation()}function v4(t){return t.stopPropagation()}function w4(t){return t.stopPropagation()}function j4(t){return t.stopPropagation()}function N4(t){return t.stopPropagation()}function S4(t){return t.stopPropagation()}function k4(t){return t.stopPropagation()}function C4(t){return t.stopPropagation()}function P4(t){return t.stopPropagation()}function I4(t){return t.stopPropagation()}const D4=t=>{const e=st.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:a,children:i}=t,l=`session-drag:${n}`;let u;e[0]!==r||e[1]!==n||e[2]!==a?(u={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:a},e[0]=r,e[1]=n,e[2]=a,e[3]=u):u=e[3];let d;e[4]!==l||e[5]!==u?(d={id:l,data:u},e[4]=l,e[5]=u,e[6]=d):d=e[6];const{attributes:f,listeners:m,setNodeRef:c,isDragging:p}=Lg(d);let g;e[7]!==m?(g=b=>{b.stopPropagation(),m?.onPointerDown&&m.onPointerDown(b)},e[7]=m,e[8]=g):g=e[8];const h=g,x=p?"opacity-30":void 0;let w;return e[9]!==f||e[10]!==i||e[11]!==h||e[12]!==c||e[13]!==x?(w=s.jsx("div",{ref:c,...f,onPointerDown:h,className:x,children:i}),e[9]=f,e[10]=i,e[11]=h,e[12]=c,e[13]=x,e[14]=w):w=e[14],w},T4=t=>{const e=st.c(11),{folderId:n,children:r}=t,a=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let l;e[2]!==a||e[3]!==i?(l={id:a,data:i},e[2]=a,e[3]=i,e[4]=l):l=e[4];const{setNodeRef:u,isOver:d}=Og(l);let f;e[5]!==r||e[6]!==d||e[7]!==u?(f=r(u,d),e[5]=r,e[6]=d,e[7]=u,e[8]=f):f=e[8];let m;return e[9]!==f?(m=s.jsx(s.Fragment,{children:f}),e[9]=f,e[10]=m):m=e[10],m},A4=t=>{const e=st.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:a,children:i}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const u=ji(Ma(Ni,l)),[d,f]=o.useState(null),[m,c]=o.useState("Session"),[p,g]=o.useState(null),[h,x]=o.useState(null);if(!n){let N;return e[1]!==i?(N=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=N):N=e[2],N}let w;e[3]!==a?(w=N=>{f(null),g(null),x(null);const{active:P,over:M}=N;if(!M)return;const T=P.data.current,E=M.data.current;T?.type==="session"&&T.sessionId&&E?.type==="folder"&&E.folderId&&a(T.sessionId,E.folderId)},e[3]=a,e[4]=w):w=e[4];const b=w;let y,v;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=N=>{const P=N.active.data.current;if(P?.type==="session"&&P.sessionId){f(P.sessionId),c(P.sessionTitle??"Session");const M=N.active.rect.current.initial?.width,T=N.active.rect.current.initial?.height;g(typeof M=="number"?M:null),x(typeof T=="number"?T:null)}},v=()=>{f(null),g(null),x(null)},e[5]=y,e[6]=v):(y=e[5],v=e[6]);let S;e[7]!==h||e[8]!==d||e[9]!==m||e[10]!==p||e[11]!==r?(S=d&&r?s.jsxs("div",{style:{width:p?`${p}px`:"auto",height:h?`${h}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(D,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=h,e[8]=d,e[9]=m,e[10]=p,e[11]=r,e[12]=S):S=e[12];let I;e[13]!==S?(I=s.jsx($o,{children:S}),e[13]=S,e[14]=I):I=e[14];let j;return e[15]!==i||e[16]!==b||e[17]!==u||e[18]!==I?(j=s.jsxs(Si,{sensors:u,collisionDetection:ki,onDragStart:y,onDragCancel:v,onDragEnd:b,children:[i,I]}),e[15]=i,e[16]=b,e[17]=u,e[18]=I,e[19]=j):j=e[19],j},ra=vn()($i(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"})),E4=50,M4=28;function R4(t){const{t:e}=ct(),{group:n,groupKey:r,projectId:a,hideGroupLabel:i,hasSessionSearchQuery:l,normalizedSessionSearchQuery:u,groupSearchDataByGroup:d,expandedSessionGroups:f,collapsedGroups:m,hideDirectoryControls:c,collapsedFolderIds:p,toggleFolderCollapse:g,renameFolder:h,deleteFolder:x,showDeletionDialog:w,setDeleteFolderConfirm:b,renderSessionNode:y,projectRepoStatus:v,lastRepoStatus:S,toggleGroupSessionLimit:I,mobileVariant:j,alwaysShowActions:N,activeProjectId:P,setActiveProjectIdOnly:M,setActiveMainTab:T,setSessionSwitcherOpen:E,openNewSessionDraft:k,addSessionToFolder:C,createFolderAndStartRename:A,renamingFolderId:F,renameFolderDraft:_,setRenameFolderDraft:O,setRenamingFolderId:V,pinnedSessionIds:K,sessionOrderIndex:$,prVisualStateByDirectoryBranch:oe,onToggleCollapsedGroup:L,dragHandleProps:Y,compactBodyPadding:ee=!1}=t,re=o.useCallback((Xe,mt)=>{const wt=$.get(Xe.session.id),Et=$.get(mt.session.id);if(wt!==void 0||Et!==void 0){if(wt===void 0)return 1;if(Et===void 0)return-1;if(wt!==Et)return wt-Et}return Fa(Xe.session,mt.session,K)},[K,$]),fe=l?d.get(n):null,ge=ra(Xe=>Xe.displayMode),be=Pn(Xe=>Xe.foldersMap),z=ge==="minimal",B=f.has(r),Q=l?!1:m.has(r),X=c?10:5,ie=l?fe?.groupMatches===!0:!1,le=l,ye=o.useMemo(()=>[...le?fe?.filteredNodes??[]:n.sessions].sort(re),[re,n.sessions,fe?.filteredNodes,le]),W=n.folderScopeKey??Zt(n.directory??null),ue=o.useMemo(()=>W?be[W]??[]:[],[W,be]),ae=o.useMemo(()=>{const Xe=new Map,mt=wt=>{wt.forEach(Et=>{Xe.set(Et.session.id,Et),Et.children.length>0&&mt(Et.children)})};return mt(ye),Xe},[ye]),U=o.useMemo(()=>ue.map(Xe=>{const mt=Xe.sessionIds.map(wt=>ae.get(wt)).filter(wt=>!!wt).sort(re);return{folder:Xe,nodes:mt}}),[ue,ae,re]),G=o.useMemo(()=>{const Xe=new Map(U.map(dt=>[dt.folder.id,dt])),mt=new Map;for(const{folder:dt}of U){if(!dt.parentId)continue;const gt=mt.get(dt.parentId);gt?gt.push(dt.id):mt.set(dt.parentId,[dt.id])}const wt=new Map,Et=dt=>{const gt=wt.get(dt);if(gt!==void 0)return gt;const Wt=Xe.get(dt);if(!Wt)return wt.set(dt,!1),!1;const Ot=mt.get(dt)??[];if(n.isArchivedBucket&&Wt.nodes.length===0){const It=Ot.some($t=>Et($t));return wt.set(dt,It),It}if(!l||Wt.folder.name.toLowerCase().includes(u)||Wt.nodes.length>0)return wt.set(dt,!0),!0;const rt=Ot.some(It=>Et(It));return wt.set(dt,rt),rt};return U.filter(({folder:dt})=>Et(dt.id))},[U,n.isArchivedBucket,l,u]),ne=o.useMemo(()=>new Set(G.flatMap(Xe=>Xe.folder.sessionIds)),[G]),se=o.useMemo(()=>ye.filter(Xe=>!ne.has(Xe.session.id)),[ye,ne]),xe=o.useMemo(()=>G.filter(({folder:Xe})=>!Xe.parentId),[G]),Se=se.length,je=n.isArchivedBucket||l||B?se:se.slice(0,X),Ie=Se-je.length,Oe=n.isArchivedBucket===!0&&!l&&je.length>=E4,Ne=o.useRef(null),[he,Fe]=o.useState(null),[Be,q]=o.useState(0),Pe=$g({count:je.length,getScrollElement:()=>he,estimateSize:()=>M4,overscan:8,enabled:Oe&&he!==null,scrollMargin:Be});o.useLayoutEffect(()=>{if(!Oe){he!==null&&Fe(null),Be!==0&&q(0);return}const Xe=Ne.current;if(!Xe)return;let mt=he;if(!mt||!mt.contains(Xe)){let Et=Xe.parentElement;for(;Et;){const dt=window.getComputedStyle(Et);if(dt.overflowY==="auto"||dt.overflowY==="scroll"){mt=Et;break}Et=Et.parentElement}if(mt!==he){Fe(mt);return}}if(!mt)return;const wt=Xe.getBoundingClientRect().top-mt.getBoundingClientRect().top+mt.scrollTop;q(Et=>Math.abs(Et-wt)<1?Et:wt)}),o.useEffect(()=>{if(!Oe||!he)return;const Xe=new ResizeObserver(()=>{Pe.measure()});return Xe.observe(he),()=>Xe.disconnect()},[Oe,he,Pe]);const $e=Pe.getTotalSize(),Ce=Oe&&he!==null?Pe.getVirtualItems():[];if(l&&!ie&&xe.length===0&&se.length===0)return null;const pe=Xe=>{const mt=[],wt=Et=>{Et.forEach(dt=>{mt.push(dt.session),dt.children.length>0&&wt(dt.children)})};return wt(Xe),mt},R=pe(ye),J=a&&v.has(a)?!!v.get(a):S,H=Zt(n.directory??null),Ee=n.branch?.trim()??null,Ae=H&&Ee?oe.get(`${H}::${Ee}`)??null:null,Je=!!(Ae&&n.branch),ce=!Ae&&!n.isMain&&!!n.branch,_e=Ae?.visualState??null,et=Ae&&Ae.state==="open"&&Ae.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Ae.checks.success,total:Ae.checks.total}):null,Me=Ae&&Ae.state==="open"&&Ae.checks?[Ae.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:Ae.checks.failure}):null,Ae.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:Ae.checks.pending}):null].filter(Xe=>!!Xe).join(", "):null,He=Ae&&Ae.state==="open"?Ae.mergeableState==="blocked"||Ae.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):Ae.mergeableState==="clean"||Ae.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,We=Ae&&Ae.state==="open"&&Ae.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Ae.mergeableState}):null,Te=Ae?.base??null,Ve=Ae?.head??null,Ye=(()=>{if(!Ae)return n.branch&&mb(n.branch,n.label)?{label:n.branch,color:null}:null;switch(Ae.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return Ae.canMerge===!0||Ae.mergeableState==="clean"||Ae.checks?.state==="success"?{label:e("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:e("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"};case"blocked":return{label:Ae.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked"),color:"var(--pr-blocked)"};case"draft":return{label:e("sessions.sidebar.group.pr.status.draft"),color:"var(--pr-draft)"};case"closed":return{label:e("sessions.sidebar.group.pr.status.closed"),color:"var(--pr-closed)"};default:return null}})(),Ge=Ye?.color??(_e?`var(--pr-${_e})`:void 0),me=Xe=>{Xe.preventDefault(),Xe.stopPropagation();const mt=Ae?.url;mt&&Yn(mt)},Ke=(Xe,mt,wt)=>{const Et=G.filter(({folder:Ot})=>Ot.parentId===Xe.id),dt=Et.length>0?s.jsx(s.Fragment,{children:Et.map(({folder:Ot,nodes:Bt})=>Ke(Ot,Bt,wt+1))}):void 0,gt=Ot=>{const Bt=G.find(({folder:It})=>It.id===Ot)?.nodes??[],rt=G.filter(({folder:It})=>It.parentId===Ot);return[...pe(Bt),...rt.flatMap(({folder:It})=>gt(It.id))]},Wt=n.isArchivedBucket?gt(Xe.id):[];return s.jsx(T4,{folderId:Xe.id,children:(Ot,Bt)=>s.jsx(b4,{folder:Xe,sessions:mt,subFolderItems:dt,isCollapsed:l?!1:p.has(Xe.id),onToggle:()=>g(Xe.id),onRename:rt=>{W&&h(W,Xe.id,rt)},onDelete:()=>{if(n.isArchivedBucket){gr.requestDelete({sessions:Wt,mode:"session"});return}if(!W)return;if(!w){x(W,Xe.id);return}const rt=G.filter(({folder:$t})=>$t.parentId===Xe.id).length,It=mt.length;b({scopeKey:W,folderId:Xe.id,folderName:Xe.name,subFolderCount:rt,sessionCount:It})},renderSessionNode:y,groupDirectory:n.directory,projectId:a,mobileVariant:j,alwaysShowActions:N,isRenaming:F===Xe.id,renameDraft:F===Xe.id?_:void 0,onRenameDraftChange:rt=>O(rt),onRenameSave:()=>{const rt=_.trim();rt&&W&&h(W,Xe.id,rt),V(null),O("")},onRenameCancel:()=>{V(null),O("")},droppableRef:Ot,isDropTarget:Bt,depth:wt,onNewSession:()=>{a&&a!==P&&M(a),T("chat"),j&&E(!1),k({directoryOverride:n.directory,targetFolderId:Xe.id})},onNewSubFolder:wt===0?()=>{W&&A(W,Xe.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Xe.id)},ze=()=>xe.map(({folder:Xe,nodes:mt})=>Ke(Xe,mt,0)),tt=!!(!n.isMain&&n.worktree),it=N?tt?"pr-14":"pr-7":z?tt?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":tt?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",qe=s.jsxs(A4,{scopeKey:W,hasFolders:G.length>0,onSessionDroppedOnFolder:(Xe,mt)=>{W&&C(W,mt,Xe)},children:[ze(),Oe?s.jsx("div",{ref:Ne,style:{position:"relative",height:$e>0?$e:void 0,width:"100%"},children:Ce.map(Xe=>{const mt=je[Xe.index];return mt?s.jsx("div",{"data-index":Xe.index,ref:Pe.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Xe.start-Be}px)`},children:y(mt,0,n.directory,a,!0)},Xe.key):null})}):je.map(Xe=>y(Xe,0,n.directory,a,n.isArchivedBucket===!0)),Se===0&&G.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,Ie>0&&!B?s.jsx("button",{type:"button",onClick:()=>I(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:Ie===1?e("sessions.sidebar.group.showMoreSingle",{count:Ie}):e("sessions.sidebar.group.showMorePlural",{count:Ie})}):null,B&&Se>X?s.jsx("button",{type:"button",onClick:()=>I(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),Ze=ee?"pb-2 pl-1":"pb-3 pl-4";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:de("oc-group-body",Ze),children:qe})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:de("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>L(r),role:"button",tabIndex:0,onKeyDown:Xe=>{(Xe.key==="Enter"||Xe.key===" ")&&(Xe.preventDefault(),L(r))},"aria-label":Q?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!Q,children:[s.jsx("div",{ref:Y?.setActivatorNodeRef,className:de("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",it),...Y?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:Je&&Ae?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(D,{name:"git-branch",className:de("h-3.5 w-3.5 shrink-0",N?"hidden":"group-hover/gh:hidden"),style:Ge?{color:Ge}:void 0}),s.jsx("span",{className:de("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),Ae.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:Xe=>Xe.stopPropagation(),onClick:me,children:["#",Ae.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Ae.number]})]})}),s.jsx(Rt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Te||Ve?s.jsx("div",{className:"text-muted-foreground truncate",children:Te&&Ve?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Te}),s.jsx(D,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Ve})]}):s.jsx("span",{children:Te??Ve??""})}):null,We?s.jsx("div",{className:"text-muted-foreground truncate",children:We}):null,He||et?s.jsxs("div",{className:"text-muted-foreground truncate",children:[He??"",He&&et?" • ":"",et??"",Me?` (${Me})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:n.branch})]}):n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(D,{name:"archive",className:de("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:de("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:yi(n.label,u)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(D,{name:"git-branch",className:de("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden"),style:Ge?{color:Ge}:void 0}),s.jsx("span",{className:de("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:yi(n.label,u)})]}):yi(n.label,u)}),ce&&Ye?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(D,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||J?Je&&Ae?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:Ge?{color:Ge}:void 0})})}),s.jsx(Rt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Te||Ve?s.jsx("div",{className:"text-muted-foreground truncate",children:Te&&Ve?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Te}),s.jsx(D,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Ve})]}):s.jsx("span",{children:Te??Ve??""})}):null,We?s.jsx("div",{className:"text-muted-foreground truncate",children:We}):null,He||et?s.jsxs("div",{className:"text-muted-foreground truncate",children:[He??"",He&&et?" • ":"",et??"",Me?` (${Me})`:""]}):null]})})]}):s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Ge?{color:Ge}:void 0}):null,s.jsx("span",{className:de("min-w-0 truncate text-[11px] font-medium",!Ye.color&&"text-muted-foreground/80"),style:Ye.color?{color:Ye.color}:void 0,children:Ye.label})]}):null]})}),n.isArchivedBucket&&R.length>0?s.jsx("div",{className:de("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Xe=>{Xe.stopPropagation(),gr.requestDelete({sessions:R,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:de("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Xe=>{Xe.stopPropagation(),gr.requestDelete({sessions:R,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:de("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Xe=>{Xe.stopPropagation(),a&&a!==P&&M(a),T("chat"),j&&E(!1),k({directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(D,{name:"add",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),Q?null:s.jsx("div",{className:de("oc-group-body",Ze),children:qe})]})}function F4(t){const e=st.c(33),{t:n}=ct(),{hideDirectoryControls:r,handleNewSession:a,headerActionIconClass:i,reserveHeaderActionsSpace:l,headerActionButtonClass:u,isSessionSearchOpen:d,setIsSessionSearchOpen:f,sessionSearchInputRef:m,sessionSearchQuery:c,setSessionSearchQuery:p,hasSessionSearchQuery:g,searchMatchCount:h,collapseAllProjects:x,expandAllProjects:w,selectionModeEnabled:b,onToggleSelectionMode:y,showSidebarToggle:v,onToggleSidebar:S,avoidWindowControlsOverlay:I}=t,j=v===void 0?!1:v,N=I===void 0?!1:I,P=ra(z4),M=ra(_4),T=ra($4),E=ra(O4);if(r)return null;const k=j?N?"pl-[5.5rem] pr-3":"pl-3 pr-3":"px-2.5 py-1";let C;e[0]!==k?(C=de("select-none flex-shrink-0",k),e[0]=k,e[1]=C):C=e[1];let A;e[2]!==N||e[3]!==j?(A=j&&N?{paddingTop:"var(--oc-safe-area-top, 0px)"}:void 0,e[2]=N,e[3]=j,e[4]=A):A=e[4];let F;e[5]!==N||e[6]!==x||e[7]!==P||e[8]!==w||e[9]!==a||e[10]!==g||e[11]!==u||e[12]!==i||e[13]!==d||e[14]!==y||e[15]!==S||e[16]!==l||e[17]!==h||e[18]!==b||e[19]!==m||e[20]!==c||e[21]!==T||e[22]!==f||e[23]!==p||e[24]!==M||e[25]!==j||e[26]!==n||e[27]!==E?(F=l?s.jsxs("div",{className:de("flex h-auto flex-col gap-1",j?N?"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:[j&&S?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,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(D,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.closeSessions")})})]}):null,s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:u,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(D,{name:"chat-new",className:i})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>f(L4),className:u,"aria-label":n("sessions.sidebar.header.actions.searchSessions"),"aria-expanded":d,children:s.jsx(D,{name:"search",className:i})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.searchSessions")})})]}),s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:y,className:de(u,b&&"bg-interactive-hover text-primary"),"aria-label":n(b?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),"aria-pressed":b,children:s.jsx(D,{name:"checkbox-multiple",className:i})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n(b?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions")})})]}),s.jsxs(ys,{children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:u,"aria-label":n("sessions.sidebar.header.actions.sessionDisplayMode"),children:s.jsx(D,{name:"equalizer-2",className:i})})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.displayMode.label")})})]}),s.jsxs(ws,{align:"end",className:"min-w-[160px]",children:[s.jsxs(vt,{onClick:()=>T("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),P==="default"?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(vt,{onClick:()=>T("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),P==="minimal"?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Ys,{}),s.jsxs(vt,{onClick:E,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),M?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Ys,{}),s.jsxs(vt,{onClick:x,className:"flex items-center gap-2",children:[s.jsx(D,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(vt,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(D,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]})]})]})]}),d?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[g?s.jsx("span",{children:h===1?n("sessions.sidebar.header.search.matchCountSingle",{count:h}):n("sessions.sidebar.header.search.matchCountPlural",{count:h})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(D,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:m,value:c,onChange:O=>p(O.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:O=>{O.key==="Escape"&&(O.stopPropagation(),g?p(""):f(!1))}}),c.length>0?s.jsx("button",{type:"button",onClick:()=>p(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[5]=N,e[6]=x,e[7]=P,e[8]=w,e[9]=a,e[10]=g,e[11]=u,e[12]=i,e[13]=d,e[14]=y,e[15]=S,e[16]=l,e[17]=h,e[18]=b,e[19]=m,e[20]=c,e[21]=T,e[22]=f,e[23]=p,e[24]=M,e[25]=j,e[26]=n,e[27]=E,e[28]=F):F=e[28];let _;return e[29]!==C||e[30]!==A||e[31]!==F?(_=s.jsx("div",{className:C,style:A,children:F}),e[29]=C,e[30]=A,e[31]=F,e[32]=_):_=e[32],_}function L4(t){return!t}function O4(t){return t.toggleRecentSection}function $4(t){return t.setDisplayMode}function _4(t){return t.showRecentSection}function z4(t){return t.displayMode}const vp=7;function B4(t){const e=st.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=ct();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[l,u]=o.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[f,m]=o.useState(d);let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=v=>{u(S=>{const I=new Set(S);return I.has(v)?I.delete(v):I.add(v),I})},e[2]=c):c=e[2];const p=c;let g;e[3]===Symbol.for("react.memo_cache_sentinel")?(g=v=>{m(S=>{const I=new Set(S);return I.has(v)?I.delete(v):I.add(v),I})},e[3]=g):g=e[3];const h=g;let x,w,b;if(e[4]!==l||e[5]!==f||e[6]!==r||e[7]!==n||e[8]!==a){b=Symbol.for("react.early_return_sentinel");e:{const v=n.filter(V4);if(v.length===0){b=null;break e}x="space-y-2 pb-2 pt-1";let S;e[12]!==l||e[13]!==f||e[14]!==r||e[15]!==a?(S=I=>{const j=l.has(I.key),N=f.has(I.key),P=N?I.items:I.items.slice(0,vp),M=I.items.length-P.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>p(I.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:I.title})]}),j?null:s.jsxs("div",{className:de("space-y-0.5 pl-7"),children:[P.map(T=>r(T.node,0,T.groupDirectory,T.projectId,!1,T.secondaryMeta,"recent")),M>0&&!N?s.jsx("button",{type:"button",onClick:()=>h(I.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:M===1?a("sessions.sidebar.group.showMoreSingle",{count:M}):a("sessions.sidebar.group.showMorePlural",{count:M})}):null,N&&I.items.length>vp?s.jsx("button",{type:"button",onClick:()=>h(I.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:a("sessions.sidebar.group.showFewer")}):null]})]},I.key)},e[12]=l,e[13]=f,e[14]=r,e[15]=a,e[16]=S):S=e[16],w=v.map(S)}e[4]=l,e[5]=f,e[6]=r,e[7]=n,e[8]=a,e[9]=x,e[10]=w,e[11]=b}else x=e[9],w=e[10],b=e[11];if(b!==Symbol.for("react.early_return_sentinel"))return b;let y;return e[17]!==x||e[18]!==w?(y=s.jsx("div",{className:x,children:w}),e[17]=x,e[18]=w,e[19]=y):y=e[19],y}function V4(t){return t.items.length>0}const U4=t=>{const e=st.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:l,projectIconImage:u,projectIconBackground:d,isCollapsed:f,isActiveProject:m,isRepo:c,isDesktopShell:p,isStuck:g,hideDirectoryControls:h,alwaysShowActions:x,onToggle:w,onNewSession:b,onNewWorktreeSession:y,onRenameStart:v,onClose:S,sentinelRef:I,children:j,showCreateButtons:N,hideHeader:P,openSidebarMenuKey:M,setOpenSidebarMenuKey:T}=t,E=N===void 0?!0:N,k=P===void 0?!1:P,{t:C}=ct(),{currentTheme:A}=rr();let F;e[0]!==n?(F={id:n},e[0]=n,e[1]=F):F=e[1];const{attributes:_,listeners:O,setNodeRef:V,transform:K,transition:$,isDragging:oe}=rl(F),[L,Y]=o.useState(!1),ee=o.useRef(!1),re=`project:${n}`,fe=M===re;let ge;e[2]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>{Y(!1)},e[2]=ge):ge=e[2];const be=u?.updatedAt;let z;e[3]!==n||e[4]!==be?(z=[n,be],e[3]=n,e[4]=be,e[5]=z):z=e[5],o.useEffect(ge,z);const B=i?pl[i]:null,Q=l?Vi[l]??null:null;let X;e[6]!==A||e[7]!==n||e[8]!==L||e[9]!==u?(X=L?null:Bi({id:n,iconImage:u},{themeVariant:A.metadata.variant,iconColor:A.colors.surface.foreground}),e[6]=A,e[7]=n,e[8]=L,e[9]=u,e[10]=X):X=e[10];const ie=X;let le;e[11]!==re||e[12]!==T?(le=he=>{T(he?re:null)},e[11]=re,e[12]=T,e[13]=le):le=e[13];const ye=le,W=H4,ue=G4,ae=q4;let U;e[14]===Symbol.for("react.memo_cache_sentinel")?(U=he=>{(he.button===2||he.button===0&&he.ctrlKey)&&(ee.current=!0)},e[14]=U):U=e[14];const G=U;let ne;e[15]!==w?(ne=()=>{if(ee.current){ee.current=!1;return}w()},e[15]=w,e[16]=ne):ne=e[16];const se=ne;let xe;e[17]!==K?(xe=al.Transform.toString(K),e[17]=K,e[18]=xe):xe=e[18];let Se;e[19]!==xe||e[20]!==$?(Se={transform:xe,transition:$},e[19]=xe,e[20]=$,e[21]=Se):Se=e[21];const je=oe&&"opacity-30";let Ie;e[22]!==je?(Ie=de("relative",je),e[22]=je,e[23]=Ie):Ie=e[23];let Oe;e[24]!==x||e[25]!==_||e[26]!==ye||e[27]!==se||e[28]!==h||e[29]!==k||e[30]!==Q||e[31]!==n||e[32]!==ie||e[33]!==m||e[34]!==f||e[35]!==p||e[36]!==fe||e[37]!==c||e[38]!==g||e[39]!==O||e[40]!==S||e[41]!==b||e[42]!==y||e[43]!==v||e[44]!==a||e[45]!==d||e[46]!==B||e[47]!==r||e[48]!==I||e[49]!==E||e[50]!==C?(Oe=k?null:s.jsxs(s.Fragment,{children:[p&&s.jsx("div",{ref:I,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:de("w-full text-left group/project select-none"),style:{backgroundColor:p&&g?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",..._,children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:G,onClick:se,...O,className:de("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]",c&&!h?x?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":x?"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:de("h-3.5 w-3.5 items-center justify-center text-muted-foreground",x?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:f?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),ie?s.jsx("span",{className:de("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",x?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:ie,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>Y(!0)})}):B?s.jsx(D,{name:B,className:de("h-3.5 w-3.5",x?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:Q?{color:Q}:void 0}):s.jsx(D,{name:"folder",className:de("h-3.5 w-3.5 text-muted-foreground/80",x?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:Q?{color:Q}:void 0})]}),s.jsx("span",{className:de("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(Rt,{side:"right",sideOffset:8,children:a})]}),s.jsxs("div",{className:de("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",E?"right-7":"right-0.5"),children:[E&&c&&!h&&y?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:he=>{he.stopPropagation(),y()},className:de("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",x?"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":C("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(D,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:C("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(ys,{open:fe,onOpenChange:ye,children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:de("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",fe?"opacity-100 pointer-events-auto":x?"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":C("sessions.sidebar.project.actions.projectMenu"),onPointerDown:ue,onMouseDown:ae,onClick:W,children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(ws,{align:"end",className:"min-w-[180px]",children:[E&&!c&&!h&&b&&s.jsxs(vt,{onClick:b,children:[s.jsx(D,{name:"add",className:"mr-1.5 h-4 w-4"}),C("sessions.sidebar.project.actions.newSession")]}),s.jsxs(vt,{onClick:v,children:[s.jsx(D,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),C("sessions.sidebar.session.menu.rename")]}),s.jsxs(vt,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"close",className:"mr-1.5 h-4 w-4"}),C("sessions.sidebar.project.actions.closeProject")]})]})]})]}),E&&b?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:he=>{he.stopPropagation(),b()},className:de("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",x?"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":C(c?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(D,{name:"add",className:"h-4 w-4"})})}),s.jsx(Rt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:C(c?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=x,e[25]=_,e[26]=ye,e[27]=se,e[28]=h,e[29]=k,e[30]=Q,e[31]=n,e[32]=ie,e[33]=m,e[34]=f,e[35]=p,e[36]=fe,e[37]=c,e[38]=g,e[39]=O,e[40]=S,e[41]=b,e[42]=y,e[43]=v,e[44]=a,e[45]=d,e[46]=B,e[47]=r,e[48]=I,e[49]=E,e[50]=C,e[51]=Oe):Oe=e[51];let Ne;return e[52]!==j||e[53]!==V||e[54]!==Se||e[55]!==Ie||e[56]!==Oe?(Ne=s.jsxs("div",{ref:V,style:Se,className:Ie,children:[Oe,j]}),e[52]=j,e[53]=V,e[54]=Se,e[55]=Ie,e[56]=Oe,e[57]=Ne):Ne=e[57],Ne},K4=t=>{const e=st.c(21),{id:n,disabled:r,children:a}=t,i=r===void 0?!1:r;let l;e[0]!==i||e[1]!==n?(l={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=l):l=e[2];const{listeners:u,setNodeRef:d,setActivatorNodeRef:f,transform:m,transition:c,isDragging:p}=rl(l);let g;e[3]!==u||e[4]!==f?(g={listeners:u,setActivatorNodeRef:f},e[3]=u,e[4]=f,e[5]=g):g=e[5];const h=g;let x;e[6]!==m?(x=al.Transform.toString(m),e[6]=m,e[7]=x):x=e[7];let w;e[8]!==x||e[9]!==c?(w={transform:x,transition:c},e[8]=x,e[9]=c,e[10]=w):w=e[10];const b=p&&"opacity-50";let y;e[11]!==b?(y=de("space-y-0.5 rounded-md",b),e[11]=b,e[12]=y):y=e[12];let v;e[13]!==a||e[14]!==h?(v=typeof a=="function"?a(h):a,e[13]=a,e[14]=h,e[15]=v):v=e[15];let S;return e[16]!==d||e[17]!==w||e[18]!==y||e[19]!==v?(S=s.jsx("div",{ref:d,style:w,className:y,children:v}),e[16]=d,e[17]=w,e[18]=y,e[19]=v,e[20]=S):S=e[20],S},W4=o.memo(K4);function H4(t){t.stopPropagation()}function G4(t){t.stopPropagation()}function q4(t){t.stopPropagation()}function Y4(t){const e=st.c(25),{t:n}=ct();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={coordinateGetter:zg},e[1]=a):a=e[1];const i=ji(Ma(Ni,r),Ma(_g,a));let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[2]=l):l=e[2];const u=ji(Ma(Ni,l));if(t.projectSections.length===0){const p=(t.mobileVariant,"");let g;e[3]!==p?(g=de("space-y-1 pb-1 pl-2.5 pr-2",p),e[3]=p,e[4]=g):g=e[4];let h;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==g?(h=s.jsxs(ts,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:g,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=g,e[8]=h):h=e[8],h}if(t.sectionsForRender.length===0){const p=(t.mobileVariant,"");let g;e[9]!==p?(g=de("space-y-1 pb-1 pl-2.5 pr-2",p),e[9]=p,e[10]=g):g=e[10];let h;return e[11]!==t.searchEmptyState||e[12]!==g?(h=s.jsx(ts,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:g,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=g,e[13]=h):h=e[13],h}const d=(t.mobileVariant,"");let f;e[14]!==d?(f=de("space-y-1 pb-1 pl-2.5 pr-2",d),e[14]=d,e[15]=f):f=e[15];let m;e[16]!==u||e[17]!==i||e[18]!==t||e[19]!==n?(m=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const p=t.sectionsForRender.find(w=>w.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!p)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const g=p.groups.find(nP)??p.groups.find(sP)??p.groups.find(tP)??p.groups[0];if(!g)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const h=p.groups.find(eP);return[g,...h&&h.id!==g.id?[h]:[]].map(w=>{const b=`${p.project.id}:${w.id}`,y=w.id===g.id;return s.jsx(o.Fragment,{children:t.renderGroupSessions(w,b,p.project.id,y,null,!0)},b)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Si,{sensors:i,collisionDetection:ki,onDragEnd:p=>{if(t.isInlineEditing)return;const{active:g,over:h}=p;if(!h||g.id===h.id)return;const x=t.sectionsForRender.findIndex(b=>b.project.id===g.id),w=t.sectionsForRender.findIndex(b=>b.project.id===h.id);x===-1||w===-1||x===w||t.reorderProjects(x,w)},children:[s.jsx(Oo,{items:t.sectionsForRender.map(Z4),strategy:xc,children:t.sectionsForRender.map(p=>{const g=p.project,h=g.id,x=Sf(g.label?.trim()||ca(g.normalizedPath,t.homeDirectory)||g.normalizedPath),w=Ti(g.normalizedPath,t.homeDirectory),b=t.collapsedProjects.has(h),y=h===t.activeProjectId,v=t.projectRepoStatus.get(h),S=t.getOrderedGroups(h,p.groups),I=S.find(X4)??null,j=I?S.filter(N=>N.id!==I.id):S;return s.jsx(U4,{id:h,projectLabel:x,projectDescription:w,projectIcon:g.icon,projectColor:g.color,projectIconImage:g.iconImage,projectIconBackground:g.iconBackground,isCollapsed:b,isActiveProject:y,isRepo:!!v,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:g.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:N=>{t.projectHeaderSentinelRefs.current.set(h,N)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:b?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:p.groups.length>0?s.jsxs(Si,{sensors:u,collisionDetection:ki,onDragEnd:N=>{if(t.isInlineEditing)return;const{active:P,over:M}=N;if(!M||P.id===M.id)return;const T=j.findIndex(A=>A.id===P.id),E=j.findIndex(A=>A.id===M.id);if(T===-1||E===-1||T===E)return;const k=Bp(j,T,E).map(J4),C=I?[I.id,...k]:k;t.setGroupOrderByProject(A=>{const F=new Map(A);return F.set(h,C),F})},children:[I?t.renderGroupSessions(I,`${h}:${I.id}`,h,!0):null,s.jsx(Oo,{items:j.map(Q4),strategy:xc,children:j.map(N=>{const P=`${h}:${N.id}`;return s.jsx(W4,{id:N.id,disabled:t.isInlineEditing,children:M=>t.renderGroupSessions(N,P,h,!1,M)},N.id)})}),s.jsx($o,{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($o,{dropAnimation:null})]})}),e[16]=u,e[17]=i,e[18]=t,e[19]=n,e[20]=m):m=e[20];let c;return e[21]!==t.topContent||e[22]!==f||e[23]!==m?(c=s.jsxs(ts,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:f,children:[t.topContent,m]}),e[21]=t.topContent,e[22]=f,e[23]=m,e[24]=c):c=e[24],c}function Q4(t){return t.id}function J4(t){return t.id}function X4(t){return t.isMain}function Z4(t){return t.project.id}function eP(t){return t.isArchivedBucket}function tP(t){return t.isMain}function sP(t){return t.sessions.length>0}function nP(t){return t.isMain&&t.sessions.length>0}const rP=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const a of t){r.has(a)||(r.add(a),n.push(a));const i=e.get(a);if(i)for(const l of i)r.has(l)||(r.add(l),n.push(l))}return n},Gn=vn()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,a)=>{const i=e(),l=new Set(i.selectedIds);let u=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(l.clear(),u=r,d=null):u===null&&r!==null&&(u=r);const m=a&&a.length>0?[n,...a]:[n];if(l.has(n)){for(const p of m)l.delete(p);d===n&&(d=null)}else{for(const p of m)l.add(p);d=n}l.size===0?t({selectedIds:l,scopeKey:null,anchorId:null}):t({selectedIds:l,scopeKey:u,anchorId:d})},setRange:(n,r,a,i,l)=>{const u=e();if(a.length===0)return;const d=n&&a.includes(n)?n:a[0],f=a.indexOf(d),m=a.indexOf(r);if(f<0||m<0)return;const[c,p]=f<=m?[f,m]:[m,f],g=a.slice(c,p+1),h=rP(g,l),w=i!==null&&u.scopeKey!==null&&i!==u.scopeKey?new Set:new Set(u.selectedIds);for(const b of h)w.add(b);t({selectedIds:w,scopeKey:i??u.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const a=new Set(r.selectedIds);for(const i of n)a.delete(i);a.size!==r.selectedIds.size&&(a.size===0?t({selectedIds:a,scopeKey:null,anchorId:null}):t({selectedIds:a}))}}));function aP(t){const e=st.c(7);let n,r,a,i,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),a=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),l=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=a,e[3]=i,e[4]=l):(n=e[0],r=e[1],a=e[2],i=e[3],l=e[4]);let u;return e[5]!==t?(u=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,a,i,l]}),e[5]=t,e[6]=u):u=e[6],u}const wp=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),ta=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(ta(n,e))return!0;return!1},Wc=(t,e,n,r)=>{if(!e)return!1;if(`${n}:${r?"archived":"active"}:${t.session.id}`===e)return!0;for(const i of t.children)if(Wc(i,e,n,r))return!0;return!1},iP=(t,e)=>{const n=t.node.session,r=e.node.session,a=n.id,i=r.id;if(a!==i||t.node.session!==e.node.session||wp(t.node)!==wp(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=ta(t.node,t.currentSessionId),c=ta(e.node,e.currentSessionId);if(m||c)return!1}if(t.pinnedSessionIds.has(a)!==e.pinnedSessionIds.has(i))return!1;{const m=t.renderContext??"project",c=e.renderContext??"project",p=t.archivedBucket??!1,g=e.archivedBucket??!1,h=`${m}:${p?"archived":"active"}:${a}`,x=`${c}:${g?"archived":"active"}:${i}`;if(t.expandedParents.has(h)!==e.expandedParents.has(x))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=ta(t.node,t.editingId),c=ta(e.node,e.editingId);if(m||c)return!1}if(t.editTitle!==e.editTitle){const m=ta(t.node,t.editingId),c=ta(e.node,e.editingId);if(m||c)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const l=Wc(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),u=Wc(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(l!==u)return!1;const d=Zt(n.directory??null)??Zt(t.groupDirectory??null),f=Zt(r.directory??null)??Zt(e.groupDirectory??null);return!(d!==f||(d?t.directoryStatus.get(d):null)!==(f?e.directoryStatus.get(f):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 oP(t){const{t:e}=ct(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:l=!1,directoryStatus:u,currentSessionId:d,pinnedSessionIds:f,expandedParents:m,hasSessionSearchQuery:c,normalizedSessionSearchQuery:p,notifyOnSubtasks:g,editingId:h,setEditingId:x,editTitle:w,setEditTitle:b,handleSaveEdit:y,handleCancelEdit:v,toggleParent:S,handleSessionSelect:I,handleSessionDoubleClick:j,togglePinnedSession:N,handleShareSession:P,copiedSessionId:M,handleCopyShareUrl:T,handleUnshareSession:E,openSidebarMenuKey:k,setOpenSidebarMenuKey:C,renamingFolderId:A,getFoldersForScope:F,getSessionFolderId:_,removeSessionFromFolder:O,addSessionToFolder:V,createFolderAndStartRename:K,openContextPanelTab:$,handleDeleteSession:oe,mobileVariant:L,alwaysShowActions:Y,renderSessionNode:ee,secondaryMeta:re,renderContext:fe="project"}=t,ge=!!re?.projectLabel,be=!!re?.branchLabel,B=ra(ft=>ft.displayMode)==="minimal",Q=o.useMemo(()=>Ks(),[]),X=o.useMemo(()=>Jc(),[]),ie=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",ye=!l&&!L,W=B?Q?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":Q?ye?"group-hover:pr-12":"group-hover:pr-5":ye?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",ue=ye?"pr-13":"pr-7",ae=o.useRef(!1),[U,G]=o.useState(!1),ne=n.session,xe=Qp(ne.id)??ne,Se=Zt(ne.directory??null)??Zt(a??null),je=pb(Se??void 0),Ie=ld(),Oe=Gn(ft=>ft.enabled),Ne=Gn(o.useCallback(ft=>ft.selectedIds.has(ne.id),[ne.id])),he=Gn(ft=>ft.toggleSelected),Fe=Gn(ft=>ft.setRange),Be=o.useCallback(ft=>{const Es=[],is=Z=>{Z.children.forEach(yt=>{Es.push(yt.session.id),is(yt)})};return is(ft),Es},[]),[q,Pe]=o.useState(!1),[$e,Ce]=o.useState(!0),pe=`${fe}:${l?"archived":"active"}:${ne.id}`,R=kf(o.useCallback(ft=>!!ft.sessionMemoryState.get(ne.id)?.isZombie,[ne.id])),J=fb(ne.id),H=hb(ne.id,Se??void 0),Ae=(Se?u.get(Se):null)==="missing",Je=d===ne.id,ce=xe.title||e("sessions.sidebar.session.untitled"),_e=n.children.length>0,et=f.has(ne.id),Me=pe,He=c?!0:m.has(Me),We=!!xe.parentID,Ve=gb(ne.id)>0&&(!We||g),Ye=xe.summary,Ge=Xp(Ye),me=xe.time?.updated||xe.time?.created||Date.now(),Ke=xb(me),ze=Db(me),tt=k===pe,it=o.useMemo(()=>bb(xe.title)!==null,[xe.title]),[qe,Ze]=o.useState(!1),Xe=o.useMemo(()=>Be(n).length,[Be,n]),mt=o.useCallback(async ft=>{const Es=[];let is=0;for(const Z of ft)try{await Ie.ensureSessionRenderable(Z.session.id);const yt=ou(je.getState(),Z.session.id).list,_t=Z.session.title||e("sessions.sidebar.session.export.untitledSubagent"),gs=Z.session.agent,Ps=await mt(Z.children);is+=Ps.skipped,Es.push({title:_t,agent:gs,records:yt,children:Ps.children})}catch{is+=Be(Z).length+1}return{children:Es,skipped:is}},[Be,je,Ie,e]),wt=o.useCallback(ft=>{ft<=0||te.warning(ft===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:ft}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:ft}))},[e]),Et=o.useCallback(async ft=>{if(!Se){te.error(e("sessions.sidebar.session.export.nothingToExport"));return}await Ie.ensureSessionRenderable(ne.id);const Es=ou(je.getState(),ne.id).list;if(Es.length===0){te.error(e("sessions.sidebar.session.export.nothingToExport"));return}let is,Z=0;if(ft&&n.children.length>0){const Ps=await mt(n.children);is=Ps.children,Z=Ps.skipped}const yt=yb(Es,xe.title??null,is),_t=vb(xe.title??null),gs=await wb(yt,_t);if(gs){te.success(e("sessions.sidebar.session.export.success"),{action:{label:e(Nb()),onClick:()=>{jb(gs).then(Ps=>{Ps||te.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),wt(Z);return}Sb(yt,_t),te.success(e("sessions.sidebar.session.export.success")),wt(Z)},[mt,je,n.children,xe.title,ne.id,Se,wt,Ie,e]),dt=o.useCallback(async()=>{if(n.children.length>0){Ce(!0),Pe(!0);return}await Et(!1)},[Et,n.children.length]),gt=o.useCallback(()=>{Se&&_o("desktop_open_session_mini_chat_window",{sessionId:ne.id,directory:Se}).catch(ft=>{console.warn("[session-sidebar] failed to open mini chat window",ft)})},[ne.id,Se]);if(h===ne.id)return s.jsx("div",{className:de("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(),y()},children:[s.jsx("input",{value:w,onChange:ft=>b(ft.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:ft=>{if(ft.key==="Escape"){ft.stopPropagation(),v();return}(ft.key===" "||ft.key==="Enter")&&ft.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:v,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"close",className:"size-4"})})]}),B?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[_e?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:He?s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(D,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:Ke}),Ge?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:["+",Ge.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Ge.deletions]})]}):null,ge?s.jsx("span",{className:"truncate",children:re?.projectLabel}):null,be?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:re?.branchLabel})]}):null]})})]})},ne.id);const Wt=J?.type??"idle",Ot=Wt==="busy"||Wt==="retry",Bt=H.length,It=Ot||!Ot&&Ve&&!Je,$t=Ot?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-busy-pulse","aria-label":e("sessions.sidebar.session.status.active"),title:e("sessions.sidebar.session.status.active")}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":e("sessions.sidebar.session.status.unread"),title:e("sessions.sidebar.session.status.unread")}),Ut=It||et?s.jsxs("span",{className:de("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",B?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",It&&et?"left-[-18px] w-6":"left-[-10px] w-3.5",_e&&!Y?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[It?$t:null,et?s.jsx(D,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,ms=_e?s.jsx("span",{role:"button",tabIndex:0,onClick:ft=>{ft.stopPropagation(),S(Me)},onKeyDown:ft=>{(ft.key==="Enter"||ft.key===" ")&&(ft.preventDefault(),ft.stopPropagation(),S(Me))},className:de("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",B?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",B&&It&&!Y?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(He?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:He?s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(D,{name:"arrow-right-s",className:"h-3 w-3"})}):null,ns=R?s.jsx(D,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Vt=ft=>{C(ft?pe:null)},Ue=ft=>{ft.preventDefault(),ft.stopPropagation(),C(tt?null:pe)},kt=ft=>{ft.preventDefault(),ft.stopPropagation()},Mt=ft=>{ft.preventDefault(),ft.stopPropagation()},ut=ft=>{ft.preventDefault(),ft.stopPropagation()},Kt=ft=>{ft.preventDefault(),ft.stopPropagation()},Yt=ft=>{ft.preventDefault(),ft.stopPropagation(),C(null),oe(ne,{archivedBucket:l})},ks=ft=>{if(ae.current){ae.current=!1;return}if(Oe){if(ft?.preventDefault(),ft?.stopPropagation(),ft?.shiftKey){const is=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(_t=>_t.getAttribute("data-session-row")).filter(_t=>typeof _t=="string"&&_t.length>0),Z=Gn.getState().anchorId,yt=new Map;yt.set(ne.id,Be(n)),Fe(Z,ne.id,is,Se??null,yt);return}he(ne.id,Se??null,Be(n));return}I(ne.id,Se,Ae,i)},Cs=ft=>{(ft.button===2||ft.button===0&&ft.ctrlKey&&!Oe)&&(ae.current=!0)},Fs=ft=>{L&&ft.pointerType==="touch"&&G(!0)},Ls=ft=>{L&&ft.pointerType==="touch"&&G(!1)},dn=s.jsxs(ws,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:ft=>{A&&ft.preventDefault()},children:[s.jsxs(vt,{onClick:()=>{x(ne.id),b(ce)},className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(vt,{onClick:()=>N(ne.id),className:"[&>svg]:mr-1",children:[et?s.jsx(D,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(D,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(et?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),xe.share?s.jsxs(s.Fragment,{children:[s.jsx(vt,{onClick:()=>{xe.share?.url&&T(xe.share.url,ne.id)},className:"[&>svg]:mr-1",children:M===ne.id?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(vt,{onClick:()=>E(ne.id),className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(vt,{onClick:()=>P(xe),className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(vt,{onClick:()=>{dt()},className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),it?s.jsxs(vt,{onClick:()=>Ze(!0),className:"[&>svg]:mr-1",children:[s.jsx(aP,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Se&&!l?(()=>{const ft=F(Se),Es=_(Se,ne.id);return s.jsxs(s.Fragment,{children:[s.jsx(Ys,{}),s.jsxs(kb,{children:[s.jsxs(Cb,{className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Pb,{className:"min-w-[180px]",children:[ft.length===0?s.jsx(vt,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):ft.map(is=>s.jsxs(vt,{onClick:()=>{Es===is.id?O(Se,ne.id):V(Se,is.id,ne.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:is.name}),Es===is.id?s.jsx(D,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},is.id)),s.jsx(Ys,{}),s.jsxs(vt,{onClick:()=>{const is=K(Se);is&&V(Se,is.id,ne.id)},children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Es?s.jsxs(vt,{onClick:()=>{O(Se,ne.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,Q?null:s.jsxs(vt,{disabled:!Se,onClick:()=>{Se&&$(Se,{mode:"chat",dedupeKey:`session:${ne.id}`,label:ce})},className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),X?s.jsxs(vt,{disabled:!Se,onClick:gt,className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Ys,{}),s.jsxs(vt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>oe(ne,{archivedBucket:l}),children:[s.jsx(D,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(l?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(o.Fragment,{children:[s.jsx(D4,{sessionId:ne.id,sessionDirectory:Se??null,sessionTitle:ce,children:s.jsxs("div",{"data-session-row":ne.id,"data-session-scope":Se??"","data-session-archived":l?"1":"0",className:de("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",Ae?"opacity-75":"",r>0&&"pl-[20px]",Ne&&"bg-primary/15"),children:[Ut,ms,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:B?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",disabled:Ae,onPointerDown:Fs,onPointerUp:Ls,onPointerCancel:Ls,onMouseDown:Cs,onClick:ft=>ks(ft),onDoubleClick:ft=>{ft.stopPropagation(),j()},className:de("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]",U&&"bg-interactive-hover/70",Y?Q?W:ue:W),children:s.jsxs("div",{className:de("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:de("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:yi(ce,p)}),Y?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:ze}):null,Y?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:de("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",tt?"opacity-0":le),children:ze})}),Bt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(D,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Bt})]}):null]})})}),s.jsx(Rt,{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:de("flex items-center gap-3 text-left text-muted-foreground",re?.projectLabel?"justify-between":"justify-start"),children:[re?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:re.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:Ke})]}),re?.branchLabel||Ge?s.jsxs("div",{className:de("flex items-center gap-3 text-left text-muted-foreground",re?.branchLabel?"justify-between":"justify-start"),children:[re?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:re.branchLabel})]})}):null,Ge?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Ge.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Ge.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:Ae,onPointerDown:Fs,onPointerUp:Ls,onPointerCancel:Ls,onMouseDown:Cs,onClick:ft=>ks(ft),onDoubleClick:ft=>{ft.stopPropagation(),j()},className:de("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]",U&&"bg-interactive-hover/70",Y?Q?W:ue:W),children:[s.jsxs("div",{className:de("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:de("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:yi(ce,p)}),Bt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(D,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Bt})]}):null]}),B?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:Ke}),Ge?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:["+",Ge.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Ge.deletions]})]}):null,ge?s.jsx("span",{className:"truncate",children:re?.projectLabel}):null,be?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:re?.branchLabel})]}):null]})})]})}),ns&&!L?s.jsx("div",{className:de("absolute top-1/2 -translate-y-1/2 z-10",B?"right-0":"right-[30px]"),children:ns}):null,s.jsxs("div",{className:de("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",tt||Y&&!Q?"opacity-100":de("opacity-0",ie)),children:[ye?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",className:de("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",B&&!Y?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:ut,onMouseDown:Kt,onClick:Yt,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(D,{name:"archive",className:de(B&&!Y?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Rt,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(ys,{open:tt,onOpenChange:Vt,children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:de("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",B&&!Y?tt?"h-4 w-4 opacity-100":de("h-4 w-4 opacity-0",ie):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:kt,onMouseDown:Mt,onClick:Ue,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(D,{name:"more-2",className:de(B&&!Y?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),dn]})]})]})}),_e&&He?n.children.map(ft=>ee(ft,r+1,Se??a,i,l,void 0,fe)):null,s.jsx(ls,{open:q,onOpenChange:Pe,children:s.jsxs(os,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(bs,{children:[s.jsx(hs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ss,{children:Xe===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Xe}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Xe})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$e,onChange:ft=>Ce(ft.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Is,{children:[s.jsx(ve,{type:"button",onClick:()=>Pe(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{type:"button",onClick:()=>{Pe(!1),Et($e)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),it?s.jsx(Ib,{session:xe,open:qe,onOpenChange:Ze}):null]},ne.id)}const lP=o.memo(oP,iP);function cP(t){const e=st.c(71),{t:n}=ct(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:l,onConfirm:u}=t;let d,f,m,c,p,g,h,x,w,b;if(e[0]!==a||e[1]!==n||e[2]!==r){const K=n("sessions.sidebar.session.untitled");c=ls,w=!!r,e[13]!==a?(b=oe=>{oe||a(null)},e[13]=a,e[14]=b):b=e[14],m=os,h=!1,x="max-w-sm gap-5",f=bs;let $;e[15]!==n||e[16]!==r?.archivedBucket?($=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=$):$=e[17],e[18]!==$?(g=s.jsx(hs,{children:$}),e[18]=$,e[19]=g):g=e[19],d=Ss,p=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||K,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||K,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||K,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||K,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||K}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||K}),e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=f,e[5]=m,e[6]=c,e[7]=p,e[8]=g,e[9]=h,e[10]=x,e[11]=w,e[12]=b}else d=e[3],f=e[4],m=e[5],c=e[6],p=e[7],g=e[8],h=e[9],x=e[10],w=e[11],b=e[12];let y;e[20]!==d||e[21]!==p?(y=s.jsx(d,{children:p}),e[20]=d,e[21]=p,e[22]=y):y=e[22];let v;e[23]!==f||e[24]!==g||e[25]!==y?(v=s.jsxs(f,{children:[g,y]}),e[23]=f,e[24]=g,e[25]=y,e[26]=v):v=e[26];let S;e[27]!==l||e[28]!==i?(S=()=>l(!i),e[27]=l,e[28]=i,e[29]=S):S=e[29];const I=!i;let j;e[30]!==i?(j=i?s.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=j):j=e[31];let N;e[32]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=N):N=e[33];let P;e[34]!==j||e[35]!==N||e[36]!==S||e[37]!==I?(P=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":I,children:[j,N]}),e[34]=j,e[35]=N,e[36]=S,e[37]=I,e[38]=P):P=e[38];let M;e[39]!==a?(M=()=>a(null),e[39]=a,e[40]=M):M=e[40];let T;e[41]!==n?(T=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=T):T=e[42];let E;e[43]!==M||e[44]!==T?(E=s.jsx("button",{type:"button",onClick:M,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:T}),e[43]=M,e[44]=T,e[45]=E):E=e[45];let k;e[46]!==u?(k=()=>{u()},e[46]=u,e[47]=k):k=e[47];let C;e[48]!==n||e[49]!==r?.archivedBucket?(C=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=C):C=e[50];let A;e[51]!==k||e[52]!==C?(A=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:C}),e[51]=k,e[52]=C,e[53]=A):A=e[53];let F;e[54]!==E||e[55]!==A?(F=s.jsxs("div",{className:"flex items-center gap-2",children:[E,A]}),e[54]=E,e[55]=A,e[56]=F):F=e[56];let _;e[57]!==P||e[58]!==F?(_=s.jsxs(Is,{className:"w-full sm:items-center sm:justify-between",children:[P,F]}),e[57]=P,e[58]=F,e[59]=_):_=e[59];let O;e[60]!==m||e[61]!==h||e[62]!==_||e[63]!==x||e[64]!==v?(O=s.jsxs(m,{showCloseButton:h,className:x,children:[v,_]}),e[60]=m,e[61]=h,e[62]=_,e[63]=x,e[64]=v,e[65]=O):O=e[65];let V;return e[66]!==c||e[67]!==O||e[68]!==w||e[69]!==b?(V=s.jsx(c,{open:w,onOpenChange:b,children:O}),e[66]=c,e[67]=O,e[68]=w,e[69]=b,e[70]=V):V=e[70],V}function dP(t){const e=st.c(57),{t:n}=ct(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:l,onConfirm:u}=t,d=r?.archivedBucket===!0,f=r?.sessionCount??0;let m;e[0]!==d||e[1]!==f||e[2]!==n?(m=n(d?f===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":f===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=f,e[2]=n,e[3]=m):m=e[3];const c=m;let p;e[4]!==d||e[5]!==f||e[6]!==n?(p=d?f===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:f}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:f}):f===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:f}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:f}),e[4]=d,e[5]=f,e[6]=n,e[7]=p):p=e[7];const g=p,h=!!r;let x;e[8]!==a?(x=V=>{V||a(null)},e[8]=a,e[9]=x):x=e[9];let w;e[10]!==c?(w=s.jsx(hs,{children:c}),e[10]=c,e[11]=w):w=e[11];let b;e[12]!==g?(b=s.jsx(Ss,{children:g}),e[12]=g,e[13]=b):b=e[13];let y;e[14]!==w||e[15]!==b?(y=s.jsxs(bs,{children:[w,b]}),e[14]=w,e[15]=b,e[16]=y):y=e[16];let v;e[17]!==l||e[18]!==i?(v=()=>l(!i),e[17]=l,e[18]=i,e[19]=v):v=e[19];const S=!i;let I;e[20]!==i?(I=i?s.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=I):I=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let N;e[24]!==j||e[25]!==v||e[26]!==S||e[27]!==I?(N=s.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":S,children:[I,j]}),e[24]=j,e[25]=v,e[26]=S,e[27]=I,e[28]=N):N=e[28];let P;e[29]!==a?(P=()=>a(null),e[29]=a,e[30]=P):P=e[30];let M;e[31]!==n?(M=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=M):M=e[32];let T;e[33]!==P||e[34]!==M?(T=s.jsx("button",{type:"button",onClick:P,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:M}),e[33]=P,e[34]=M,e[35]=T):T=e[35];let E;e[36]!==u?(E=()=>{u()},e[36]=u,e[37]=E):E=e[37];let k;e[38]!==d||e[39]!==n?(k=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=k):k=e[40];let C;e[41]!==E||e[42]!==k?(C=s.jsx("button",{type:"button",onClick:E,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:k}),e[41]=E,e[42]=k,e[43]=C):C=e[43];let A;e[44]!==T||e[45]!==C?(A=s.jsxs("div",{className:"flex items-center gap-2",children:[T,C]}),e[44]=T,e[45]=C,e[46]=A):A=e[46];let F;e[47]!==N||e[48]!==A?(F=s.jsxs(Is,{className:"w-full sm:items-center sm:justify-between",children:[N,A]}),e[47]=N,e[48]=A,e[49]=F):F=e[49];let _;e[50]!==F||e[51]!==y?(_=s.jsxs(os,{showCloseButton:!1,className:"max-w-sm gap-5",children:[y,F]}),e[50]=F,e[51]=y,e[52]=_):_=e[52];let O;return e[53]!==h||e[54]!==_||e[55]!==x?(O=s.jsx(ls,{open:h,onOpenChange:x,children:_}),e[53]=h,e[54]=_,e[55]=x,e[56]=O):O=e[56],O}function uP(t){const e=st.c(36),{t:n}=ct(),{value:r,setValue:a,onConfirm:i}=t,l=!!r;let u;e[0]!==a?(u=I=>{I||a(null)},e[0]=a,e[1]=u):u=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let f;e[4]!==d?(f=s.jsx(hs,{children:d}),e[4]=d,e[5]=f):f=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 c;e[9]!==m?(c=s.jsx(Ss,{children:m}),e[9]=m,e[10]=c):c=e[10];let p;e[11]!==f||e[12]!==c?(p=s.jsxs(bs,{children:[f,c]}),e[11]=f,e[12]=c,e[13]=p):p=e[13];let g;e[14]!==a?(g=()=>a(null),e[14]=a,e[15]=g):g=e[15];let h;e[16]!==n?(h=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=h):h=e[17];let x;e[18]!==g||e[19]!==h?(x=s.jsx("button",{type:"button",onClick:g,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]=g,e[19]=h,e[20]=x):x=e[20];let w;e[21]!==n?(w=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=w):w=e[22];let b;e[23]!==i||e[24]!==w?(b=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:w}),e[23]=i,e[24]=w,e[25]=b):b=e[25];let y;e[26]!==b||e[27]!==x?(y=s.jsxs(Is,{children:[x,b]}),e[26]=b,e[27]=x,e[28]=y):y=e[28];let v;e[29]!==y||e[30]!==p?(v=s.jsxs(os,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,y]}),e[29]=y,e[30]=p,e[31]=v):v=e[31];let S;return e[32]!==l||e[33]!==u||e[34]!==v?(S=s.jsx(ls,{open:l,onOpenChange:u,children:v}),e[32]=l,e[33]=u,e[34]=v,e[35]=S):S=e[35],S}const mP=t=>{const e=st.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:l,onCreateFolderAndMove:u,onRemoveFromFolder:d,canRemoveFromFolder:f,onDelete:m,onDone:c}=t,{t:p}=ct(),g=!!r&&!i;let h;e[0]!==i||e[1]!==p?(h=p(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=p,e[2]=h):h=e[2];const x=h;let w;e[3]!==n||e[4]!==p?(w=p("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=p,e[5]=w):w=e[5];let b;e[6]!==w?(b=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:w}),e[6]=w,e[7]=b):b=e[7];let y;e[8]!==g||e[9]!==f||e[10]!==u||e[11]!==l||e[12]!==d||e[13]!==a||e[14]!==p?(y=g?s.jsxs(ys,{children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(vs,{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":p("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(D,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Rt,{side:"top",sideOffset:4,children:s.jsx("p",{children:p("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(ws,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx(vt,{disabled:!0,className:"text-muted-foreground",children:p("sessions.sidebar.folders.none")}):a.map(_=>s.jsx(vt,{onClick:()=>l(_.id),children:s.jsx("span",{className:"flex-1 truncate",children:_.name})},_.id)),s.jsx(Ys,{}),s.jsxs(vt,{onClick:u,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.newFolderEllipsis")]}),f?s.jsxs(vt,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"close",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=g,e[9]=f,e[10]=u,e[11]=l,e[12]=d,e[13]=a,e[14]=p,e[15]=y):y=e[15];let v;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=de("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=v):v=e[16];let S;e[17]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(D,{name:"delete-bin",className:"h-4 w-4"}),e[17]=S):S=e[17];let I;e[18]!==x||e[19]!==m?(I=s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:v,"aria-label":x,children:S})}),e[18]=x,e[19]=m,e[20]=I):I=e[20];let j;e[21]!==x?(j=s.jsx(Rt,{side:"top",sideOffset:4,children:s.jsx("p",{children:x})}),e[21]=x,e[22]=j):j=e[22];let N;e[23]!==I||e[24]!==j?(N=s.jsxs(Tt,{children:[I,j]}),e[23]=I,e[24]=j,e[25]=N):N=e[25];let P;e[26]!==p?(P=p("sessions.sidebar.header.actions.exitSelection"),e[26]=p,e[27]=P):P=e[27];let M;e[28]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(D,{name:"close",className:"h-4 w-4"}),e[28]=M):M=e[28];let T;e[29]!==c||e[30]!==P?(T=s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,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":P,children:M})}),e[29]=c,e[30]=P,e[31]=T):T=e[31];let E;e[32]!==p?(E=p("sessions.sidebar.header.actions.exitSelection"),e[32]=p,e[33]=E):E=e[33];let k;e[34]!==E?(k=s.jsx(Rt,{side:"top",sideOffset:4,children:s.jsx("p",{children:E})}),e[34]=E,e[35]=k):k=e[35];let C;e[36]!==T||e[37]!==k?(C=s.jsxs(Tt,{children:[T,k]}),e[36]=T,e[37]=k,e[38]=C):C=e[38];let A;e[39]!==C||e[40]!==y||e[41]!==N?(A=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[y,N,C]}),e[39]=C,e[40]=y,e[41]=N,e[42]=A):A=e[42];let F;return e[43]!==A||e[44]!==b?(F=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[b,A]}),e[43]=A,e[44]=b,e[45]=F):F=e[45],F},_h="oc.sessions.activeNow",pP=2160*60*1e3,zh=t=>!!t.parentID,wd=t=>!!t.time?.archived,Hc=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},fP=t=>{try{const e=t.getItem(_h);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,a=[];return n.forEach(i=>{const l=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!l||r.has(l)||(r.add(l),a.push({sessionId:l}))}),a}catch{return[]}},dc=(t,e)=>{try{t.setItem(_h,JSON.stringify(e))}catch{}},hP=(t,e,n=Date.now())=>{const r=n-pP;return t.filter(a=>{const i=e.get(a.sessionId);return i?wd(i)?!1:Hc(i)>=r:!0})},gP=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],Bh=t=>[...t].sort((e,n)=>Hc(n)-Hc(e)),xP=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!wd(r)).filter(r=>!zh(r));return Bh(n)},bP=(t,e)=>{const n=t.filter(r=>{if(wd(r)||zh(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return Bh(n)},go=Vr(),uc=vn((t,e)=>({entries:fP(go),setEntries:n=>{n!==e().entries&&(t({entries:n}),dc(go,n))},addSession:n=>{const r=gP(e().entries,n);r!==e().entries&&(t({entries:r}),dc(go,r))},prune:n=>{const r=e().entries,a=hP(r,n);a.length===r.length&&a.every((i,l)=>i.sessionId===r[l]?.sessionId)||(t({entries:a}),dc(go,a))}})),xo="oc.sessions.projectCollapse",jp="oc.sessions.groupOrder",Np="oc.sessions.groupCollapse",Sp="oc.sessions.activeSessionByProject",mc="oc.sessions.expandedParents.v2",yP="oc.sessions.expandedParents",vP="oc.sessions.pinned",wP=(t,e)=>{const n=new Set;for(const r of t){const a=Zt(r.path)?.toLowerCase();a&&n.add(a)}for(const r of e.values())for(const a of r){const i=Zt(a.path)?.toLowerCase();i&&n.add(i)}return n},jP=(t,e)=>{if(t.time?.archived)return!0;const n=Zt(So(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},NP=5*6e4,kp=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=ct(),[l,u]=o.useState(!1),[d,f]=o.useState(""),m=o.useRef(null),c=o.useRef(null),p=o.useRef(new Set),[g,h]=o.useState(null),[x,w]=o.useState(""),[b,y]=o.useState(null),[v,S]=o.useState(new Set),[I]=o.useState(()=>new Map),j=o.useMemo(()=>Vr(),[]),N=uc(Re=>Re.entries),P=uc(Re=>Re.addSession),M=uc(Re=>Re.prune),[T,E]=o.useState(new Set),[k,C]=o.useState(new Map),[A,F]=o.useState(new Set),[_,O]=o.useState(!1),[V,K]=o.useState(null),[$,oe]=o.useState(null),[L,Y]=o.useState(""),[ee,re]=o.useState(null),[fe,ge]=o.useState(null),[be,z]=o.useState(null),B=zl(Re=>Re.ids),Q=zl(Re=>Re.setIds),X=zl(Re=>Re.toggle),[ie,le]=o.useState(()=>{try{const Re=Vr().getItem(Np);if(!Re)return new Set;const pt=JSON.parse(Re);return new Set(Array.isArray(pt)?pt.filter(lt=>typeof lt=="string"):[])}catch{return new Set}}),[ye,W]=o.useState(()=>{try{const Re=Vr().getItem(jp);if(!Re)return new Map;const pt=JSON.parse(Re),lt=new Map;return Object.entries(pt).forEach(([Dt,qt])=>{Array.isArray(qt)&&lt.set(Dt,qt.filter(Rs=>typeof Rs=="string"))}),lt}catch{return new Map}}),[ue,ae]=o.useState(()=>{try{const Re=Vr().getItem(Sp);if(!Re)return new Map;const pt=JSON.parse(Re),lt=new Map;return Object.entries(pt).forEach(([Dt,qt])=>{typeof qt=="string"&&qt.length>0&&lt.set(Dt,qt)}),lt}catch{return new Map}}),[U,G]=o.useState(new Map),ne=o.useRef(new Map),se=o.useRef(0),xe=Ns(Re=>Re.homeDirectory),Se=Ns(Re=>Re.currentDirectory),je=Ns(Re=>Re.setDirectory),Ie=es(Re=>Re.projects),Oe=es(Re=>Re.activeProjectId),Ne=es(Re=>Re.removeProject),he=es(Re=>Re.setActiveProjectIdOnly),Fe=es(Re=>Re.updateProjectMeta),Be=es(Re=>Re.reorderProjects),q=De(Re=>Re.setActiveMainTab),Pe=De(Re=>Re.openContextPanelTab),$e=De(Re=>Re.setSessionSwitcherOpen),Ce=De(Re=>Re.toggleSidebar),pe=De(Re=>Re.notifyOnSubtasks),R=De(Re=>Re.showDeletionDialog),J=De(Re=>Re.setShowDeletionDialog),H=dl(d,120),Ee=o.useMemo(()=>H.trim().toLowerCase(),[H]),Ae=Ee.length>0,Je=Pn(Re=>Re.collapsedFolderIds),ce=Pn(Re=>Re.foldersMap),_e=Pn(Re=>Re.getFoldersForScope),et=Pn(Re=>Re.createFolder),Me=Pn(Re=>Re.renameFolder),He=Pn(Re=>Re.deleteFolder),We=Pn(Re=>Re.addSessionToFolder),Te=Pn(Re=>Re.addSessionsToFolder),Ve=Pn(Re=>Re.removeSessionFromFolder),Ye=Pn(Re=>Re.removeSessionsFromFolders),Ge=Pn(Re=>Re.toggleFolderCollapse),me=Pn(Re=>Re.cleanupSessions),Ke=Pn(Re=>Re.getSessionFolderId);DC({isSessionSearchOpen:l,setIsSessionSearchOpen:u,sessionSearchInputRef:c,sessionSearchContainerRef:m});const ze=gf(),tt=ld(),it=Jp(),qe=Tb(),Ze=bi(Re=>Re.hasLoaded),Xe=bi(Re=>Re.activeSessions),mt=bi(Re=>Re.archivedSessions),wt=Ft(Re=>Re.currentSessionId),Et=Ft(Re=>!!Re.newSessionDraft?.open),dt=Ft(Re=>Re.setCurrentSession),gt=Ft(Re=>Re.updateSessionTitle),Wt=Ft(Re=>Re.shareSession),Ot=Ft(Re=>Re.unshareSession),Bt=Ft(Re=>Re.worktreeMetadata),rt=Ft(Re=>Re.availableWorktreesByProject),It=Ft(Re=>Re.openNewSessionDraft),$t=o.useMemo(()=>wP(Ie,rt),[rt,Ie]),Ut=o.useMemo(()=>{const Re=new Map(it.map(Dt=>[Dt.id,Dt])),pt=Xe.map(Dt=>Re.get(Dt.id)??Dt),lt=new Set(pt.map(Dt=>Dt.id));return it.forEach(Dt=>{lt.has(Dt.id)||pt.push(Dt)}),pt.filter(Dt=>jP(Dt,$t))},[Xe,$t,it]),ms=o.useMemo(()=>it.map(Re=>{const pt=Zt(Re.directory??null)??"";return`${Re.id}:${Re.title??""}:${Re.time?.archived?1:0}:${pt}`}).join("|"),[it]),ns=o.useRef(it);o.useEffect(()=>{ns.current=it},[ms,it]),o.useEffect(()=>{let Re=!1;const pt=async()=>{const lt=es.getState().projects;if(lt.length===0)return;const Dt=new Map,qt=[];await Promise.all(lt.map(async Rs=>{const en=Zt(Rs.path);if(en)try{if(!(yn.getState().directories.get(en)?.isGitRepo??await Qn(()=>import("./modelPrefsAutoSave-Czz-2ruh.js").then(tn=>tn.fc),__vite__mapDeps([3,0,1,4,5])).then(tn=>tn.checkIsGitRepository(en))))return;const Gs=await wc({id:Rs.id,path:en});if(Re||Gs.length===0)return;Dt.set(en,Gs),qt.push(...Gs)}catch{}})),!Re&&Ft.setState({availableWorktrees:qt,availableWorktreesByProject:Dt})};return jc(ns.current),pt(),()=>{Re=!0}},[Se,ms,Ie]),o.useEffect(()=>{let Re=null;const pt=Lh(lt=>{lt.type==="scheduled-task-ran"&&(Re&&clearTimeout(Re),Re=setTimeout(()=>{jc(ns.current)},500))});return()=>{Re&&clearTimeout(Re),pt()}},[]);const Vt=o.useMemo(()=>Us(),[]),Ue=ol(),[kt,Mt]=o.useState(!1),ut=o.useMemo(()=>Ks(),[]),{isTablet:Kt}=_s(),Yt=t||Kt,ks=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Cs=!t&&!ut&&!Vt,Fs=!t&&!ut&&!Cs,Ls=Vt&&ks&&!kt||Ue?"pl-[5.5rem]":"pl-3",dn="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";o.useEffect(()=>{if(!Vt||!ks){Mt(!1);return}let Re=!1,pt=null;const lt=async()=>{try{const qt=await Mb();Re||Mt(qt)}catch{Re||Mt(!1)}},Dt=async()=>{try{pt=Rb(()=>{lt()})}catch{}};return lt(),Dt(),()=>{Re=!0,pt&&pt()}},[Vt,ks]);const ft=o.useCallback(async Re=>{const pt=Re.target;pt.closest(".app-region-no-drag")||pt.closest("button, a, input, select, textarea")||Re.button===0&&Vt&&await Cf()},[Vt]),{buildGroupSearchText:Es,filterSessionNodesForSearch:is,buildGroupedSessions:Z}=IC({homeDirectory:xe,worktreeMetadata:Bt,pinnedSessionIds:B,gitBranches:ze,isVSCode:ut}),{scheduleCollapsedProjectsPersist:yt}=LC({isVSCode:ut,hasLoadedGlobalSessions:Ze,safeStorage:j,keys:{sessionExpanded:mc,sessionExpandedLegacy:yP,projectCollapse:xo,sessionPinned:vP,groupOrder:jp,projectActiveSession:Sp,groupCollapse:Np},sessions:Ut,setPinnedSessionIds:Q,groupOrderByProject:ye,activeSessionByProject:ue,collapsedGroups:ie,setExpandedParents:S,setCollapsedProjects:E}),_t=o.useMemo(()=>[...Ut].sort((Re,pt)=>Fa(Re,pt,B)),[Ut,B]),gs=o.useMemo(()=>new Map(_t.map((Re,pt)=>[Re.id,pt])),[_t]),Ps=o.useMemo(()=>{const Re=new Map;return _t.forEach(pt=>{const lt=pt.parentID;if(!lt)return;const Dt=Re.get(lt)??[];Dt.push(pt),Re.set(lt,Dt)}),Re.forEach(pt=>pt.sort((lt,Dt)=>Fa(lt,Dt,B))),Re},[_t,B]),Ws=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noSessions.description")})]}),Ms=o.useMemo(()=>Ie.find(Re=>Re.id===b)??null,[Ie,b]),En=o.useCallback(Re=>{b&&(Fe(b,Re),y(null))},[b,Fe]),Mn=o.useCallback(()=>{O(!0)},[]),Jn=Ft(Re=>Re.deleteSession),Js=Ft(Re=>Re.deleteSessions),jn=Ft(Re=>Re.archiveSession),Xs=Ft(Re=>Re.archiveSessions),{copiedSessionId:Nn,handleSessionSelect:Sn,handleSessionDoubleClick:Rn,handleSaveEdit:Fn,handleCancelEdit:un,handleShareSession:Bn,handleCopyShareUrl:Nt,handleUnshareSession:Lt,handleDeleteSession:Gt,confirmDeleteSession:we}=TC({activeProjectId:Oe,currentDirectory:Se,currentSessionId:wt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:l,sessionSearchQuery:d,setSessionSearchQuery:f,setIsSessionSearchOpen:u,setActiveProjectIdOnly:he,setDirectory:je,setActiveMainTab:q,setSessionSwitcherOpen:$e,setCurrentSession:dt,updateSessionTitle:gt,shareSession:Wt,unshareSession:Ot,deleteSession:Jn,deleteSessions:Js,archiveSession:jn,archiveSessions:Xs,childrenMap:Ps,showDeletionDialog:R,setDeleteSessionConfirm:re,deleteSessionConfirm:ee,setEditingId:h,setEditTitle:w,editingId:g,editTitle:x}),at=o.useCallback(()=>{if(!fe)return;const{scopeKey:Re,folderId:pt}=fe;ge(null),He(Re,pt)},[fe,He]);o.useEffect(()=>{if(!wt)return;const pt=Ut.find(Dt=>Dt.id===wt)?.parentID;if(!pt)return;const lt=[`project:active:${pt}`,`project:archived:${pt}`,`recent:active:${pt}`,`recent:archived:${pt}`];S(Dt=>{if(lt.every(Rs=>Dt.has(Rs)))return Dt;const qt=new Set(Dt);lt.forEach(Rs=>qt.add(Rs));try{j.setItem(mc,JSON.stringify(Array.from(qt)))}catch{}return qt})},[wt,Ut,j]);const bt=o.useCallback(Re=>{S(pt=>{const lt=new Set(pt);lt.has(Re)?lt.delete(Re):lt.add(Re);try{j.setItem(mc,JSON.stringify(Array.from(lt)))}catch{}return lt})},[j]),Pt=o.useCallback((Re,pt)=>{if(!Re)return null;pt&&Je.has(pt)&&Ge(pt);const lt=et(Re,i("sessions.sidebar.folder.newFolderName"),pt);return oe(lt.id),Y(lt.name),lt},[Je,Ge,et,i]),Ht=o.useCallback(Re=>{F(pt=>{const lt=new Set(pt);return lt.has(Re)?lt.delete(Re):lt.add(Re),lt})},[]),xs=o.useCallback(()=>{se.current=Date.now()+150,E(()=>{const Re=new Set(Ie.map(pt=>pt.id));try{j.setItem(xo,JSON.stringify(Array.from(Re)))}catch{}return ut||yt(Re),Re})},[Ie,ut,j,yt]),cs=o.useCallback(()=>{se.current=Date.now()+150,E(()=>{const Re=new Set;try{j.setItem(xo,JSON.stringify([]))}catch{}return ut||yt(Re),Re})},[ut,j,yt]),ds=o.useCallback(Re=>{se.current=Date.now()+150,E(pt=>{const lt=new Set(pt);lt.has(Re)?lt.delete(Re):lt.add(Re);try{j.setItem(xo,JSON.stringify(Array.from(lt)))}catch{}return ut||yt(lt),lt})},[ut,j,yt]),us=o.useMemo(()=>Ie.map(Re=>({...Re,normalizedPath:Zt(Re.path)})).filter(Re=>!!Re.normalizedPath),[Ie]),rn=o.useMemo(()=>us.map(Re=>Re.normalizedPath),[us]),{github:an}=wn(),mn=zn(Re=>Re.status),pn=zn(Re=>Re.hasChecked),zs=Ab(rn),Qs=Ea(Re=>Re.ensureEntry),on=Ea(Re=>Re.setParams),$s=Ea(Re=>Re.refreshTargets);$C({normalizedProjects:us,gitRepoStatus:zs,setProjectRepoStatus:C,setProjectRootBranches:G});const Ln=Ft(Re=>Re.isLoading);GC({isSessionsLoading:Ln,sessions:Ut,archivedSessions:mt,normalizedProjects:us,isVSCode:ut,availableWorktreesByProject:rt,cleanupSessions:me});const{getSessionsForProject:fn,getArchivedSessionsForProject:mr}=VC({isVSCode:ut,sessions:Ut,archivedSessions:mt,availableWorktreesByProject:rt});vC({normalizedProjects:us,sessions:Ut,archivedSessions:mt,availableWorktreesByProject:rt,isVSCode:ut,isSessionsLoading:Ln,foldersMap:ce,createFolder:et,addSessionToFolder:We,cleanupSessions:me});const ar=o.useRef(!1);Oe&&k.has(Oe)&&(ar.current=!!k.get(Oe));const{projectSections:kn,groupSearchDataByGroup:Ja,sectionsForRender:ma,searchMatchCount:Wi}=NC({normalizedProjects:us,getSessionsForProject:fn,getArchivedSessionsForProject:mr,availableWorktreesByProject:rt,projectRepoStatus:k,projectRootBranches:U,lastRepoStatus:ar.current,buildGroupedSessions:Z,hasSessionSearchQuery:Ae,normalizedSessionSearchQuery:Ee,filterSessionNodesForSearch:is,buildGroupSearchText:Es,foldersMap:ce}),Hi=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noMatches.description")})]}),Gi=!0,{currentSessionDirectory:Cn}=kC({projectSections:kn,activeProjectId:Oe,activeSessionByProject:ue,setActiveSessionByProject:ae,currentSessionId:wt,handleSessionSelect:Sn,newSessionDraftOpen:Et,mobileVariant:t,openNewSessionDraft:It,setActiveMainTab:q,setSessionSwitcherOpen:$e,sessions:Ut,worktreeMetadata:Bt}),{getOrderedGroups:Xa}=CC(ye),Xn=o.useRef(!1);o.useEffect(()=>{if(Xn.current||kn.length===0)return;const Re=kn.flatMap(pt=>pt.groups.filter(lt=>lt.isArchivedBucket).map(lt=>`${pt.project.id}:${lt.id}`));Re.length>0&&le(pt=>new Set([...pt,...Re])),Xn.current=!0},[kn]);const Za=o.useMemo(()=>{const Re=new Map,pt=new Map;return kn.forEach(lt=>{const Dt=Sf(lt.project.label?.trim()||ca(lt.project.normalizedPath,xe)||lt.project.normalizedPath);lt.groups.forEach(qt=>{const Rs=qt.branch&&qt.branch!=="HEAD"&&qt.branch!==Dt?qt.branch:null,en={projectLabel:Dt,branchLabel:Rs},ir=Un=>{Un.forEach(Gs=>{const tn=lt.project.normalizedPath.length,Cr=pt.get(Gs.session.id)??-1;tn<Cr||(Re.set(Gs.session.id,{node:Gs,projectId:lt.project.id,groupDirectory:qt.directory,secondaryMeta:en}),pt.set(Gs.session.id,tn),Gs.children.length>0&&ir(Gs.children))})};ir(qt.sessions)})}),Re},[kn,xe]),On=ra(Re=>Re.showRecentSection),pa=o.useMemo(()=>On?xP(N,new Map(Ut.map(Re=>[Re.id,Re]))).sort((Re,pt)=>Fa(Re,pt,B)):[],[N,B,Ut,On]),fa=o.useMemo(()=>On?bP(Ut,qe):[],[qe,Ut,On]);o.useEffect(()=>{!On||fa.length===0||fa.forEach(Re=>P(Re.id))},[P,fa,On]),o.useEffect(()=>{if(!On)return;const Re=new Map;[...Ut,...mt].forEach(pt=>{Re.set(pt.id,pt)}),M(Re)},[mt,M,Ut,On]);const Rr=o.useMemo(()=>{if(!On)return[];const Re=pt=>{const lt=Za.get(pt.id),Dt=Zt(pt.directory??null);return{node:lt?.node??{session:pt,children:[],worktree:null},projectId:lt?.projectId??null,groupDirectory:lt?.groupDirectory??Dt,secondaryMeta:lt?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:pa.map(Re)}]},[pa,Za,On,i]),Nr=o.useMemo(()=>new Set(pa.map(Re=>Re.id)),[pa]),hn=o.useMemo(()=>[...Nr],[Nr]);$5({currentSessionId:wt,sortedSessions:_t,recentSessionIds:hn,ensureSessionRenderable:tt.ensureSessionRenderable});const Vn=o.useMemo(()=>{if(!ut||Ae||Nr.size===0)return ma;const Re=pt=>pt.reduce((lt,Dt)=>{if(Nr.has(Dt.session.id))return lt;const qt=Re(Dt.children);return qt.length===Dt.children.length?(lt.push(Dt),lt):(lt.push({...Dt,children:qt}),lt)},[]);return ma.map(pt=>({...pt,groups:pt.groups.map(lt=>({...lt,sessions:Re(lt.sessions)}))}))},[ut,Ae,Nr,ma]),vl=o.useMemo(()=>{const Re=new Set;return Vn.forEach(pt=>{pt.groups.forEach(lt=>{const Dt=Zt(lt.directory??null),qt=lt.branch?.trim()||ze.get(Dt||"")?.trim();!Dt||!qt||Re.add(Lo(Dt,qt))})}),[...Re]},[ze,Vn]),ei=g4(vl);o.useEffect(()=>{if(!pn||!mn?.connected||!an)return;const Re=[],pt=Date.now();if(Vn.forEach(Dt=>{T.has(Dt.project.id)||Dt.groups.forEach(qt=>{const Rs=Zt(qt.directory??null),en=qt.branch?.trim()||ze.get(Rs||"")?.trim();if(!Rs||!en)return;const ir=Lo(Rs,en),Un=Ea.getState().entries[ir],Gs=!!Un?.status?.pr,tn=`${Rs}::${en}`,Cr=Math.max(Un?.lastRefreshAt??0,Un?.lastDiscoveryPollAt??0),$r=!!(Un?.isInitialStatusResolved&&!Gs&&(!p.current.has(tn)||pt-Cr>=NP));(!Un||!Un.isInitialStatusResolved||$r)&&($r&&p.current.add(tn),Re.push({directory:Rs,branch:en}))})}),Re.length===0)return;const lt=new Map;Re.forEach(Dt=>{const qt=Lo(Dt.directory,Dt.branch,Dt.remoteName??null);lt.has(qt)||lt.set(qt,Dt)}),lt.forEach((Dt,qt)=>{Qs(qt),on(qt,{directory:Dt.directory,branch:Dt.branch,remoteName:Dt.remoteName??null,canShow:!0,github:an,githubAuthChecked:pn,githubConnected:mn.connected})}),$s([...lt.values()],{force:!0,silent:!0,markInitialResolved:!0})},[T,Qs,an,pn,mn?.connected,ze,$s,Vn,on]);const Zs=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",qi="h-4.5 w-4.5",jl=JC({isDesktopShellRuntime:Vt,projectSections:kn,projectHeaderSentinelRefs:ne}),ha=o.useCallback((Re,pt=0,lt,Dt,qt=!1,Rs,en="project")=>s.jsx(lP,{node:Re,depth:pt,groupDirectory:lt,projectId:Dt,archivedBucket:qt,directoryStatus:I,currentSessionId:wt,pinnedSessionIds:B,expandedParents:v,hasSessionSearchQuery:Ae,normalizedSessionSearchQuery:Ee,notifyOnSubtasks:pe,editingId:g,setEditingId:h,editTitle:x,setEditTitle:w,handleSaveEdit:Fn,handleCancelEdit:un,toggleParent:bt,handleSessionSelect:Sn,handleSessionDoubleClick:Rn,togglePinnedSession:X,handleShareSession:Bn,copiedSessionId:Nn,handleCopyShareUrl:Nt,handleUnshareSession:Lt,openSidebarMenuKey:V,setOpenSidebarMenuKey:K,renamingFolderId:$,getFoldersForScope:_e,getSessionFolderId:Ke,removeSessionFromFolder:Ve,addSessionToFolder:We,createFolderAndStartRename:Pt,openContextPanelTab:Pe,handleDeleteSession:Gt,mobileVariant:t,alwaysShowActions:Yt,renderSessionNode:ha,secondaryMeta:Rs,renderContext:en}),[I,wt,B,v,Ae,Ee,pe,g,h,x,w,Fn,un,bt,Sn,Rn,X,Bn,Nn,Nt,Lt,V,K,$,_e,Ke,Ve,We,Pt,Pe,Gt,t,Yt]),si=o.useCallback(Re=>{le(pt=>{const lt=new Set(pt);return lt.has(Re)?lt.delete(Re):lt.add(Re),lt})},[]),Yi=o.useMemo(()=>{const Re=new Map;for(const[pt,lt]of ei)Re.set(pt,{visualState:lt.visualState,number:lt.number,url:lt.url,state:lt.prState,draft:lt.draft,title:lt.title,base:lt.base,head:lt.head,checks:lt.checks,canMerge:lt.canMerge,mergeableState:lt.mergeableState,repo:lt.repo});return Re},[ei]),Nl=o.useCallback((Re,pt,lt,Dt,qt,Rs)=>s.jsx(R4,{group:Re,groupKey:pt,projectId:lt,hideGroupLabel:Dt,compactBodyPadding:Rs,hasSessionSearchQuery:Ae,normalizedSessionSearchQuery:Ee,groupSearchDataByGroup:Ja,expandedSessionGroups:A,collapsedGroups:ie,hideDirectoryControls:r,collapsedFolderIds:Je,toggleFolderCollapse:Ge,renameFolder:Me,deleteFolder:He,showDeletionDialog:R,setDeleteFolderConfirm:ge,renderSessionNode:ha,currentSessionDirectory:Cn,projectRepoStatus:k,lastRepoStatus:ar.current,toggleGroupSessionLimit:Ht,mobileVariant:t,alwaysShowActions:Yt,activeProjectId:Oe,setActiveProjectIdOnly:he,setActiveMainTab:q,setSessionSwitcherOpen:$e,openNewSessionDraft:It,addSessionToFolder:We,createFolderAndStartRename:Pt,renamingFolderId:$,renameFolderDraft:L,setRenameFolderDraft:Y,setRenamingFolderId:oe,pinnedSessionIds:B,sessionOrderIndex:gs,prVisualStateByDirectoryBranch:Yi,onToggleCollapsedGroup:si,dragHandleProps:qt}),[Ae,Ee,Ja,A,ie,r,Je,Ge,Me,He,R,ha,Cn,k,Ht,t,Yt,Oe,he,q,$e,It,We,Pt,$,L,B,gs,Yi,si]),Sl=On&&!Ae?s.jsx(B4,{sections:Rr,renderSessionNode:ha}):null,ni=!!($||g||b),Hr=Gn(Re=>Re.enabled),js=Gn(Re=>Re.selectedIds),Sr=Gn(Re=>Re.scopeKey),pr=Gn,Fr=o.useCallback(()=>{Gn.getState().toggleMode()},[]),Lr=o.useCallback(()=>{Gn.getState().disable()},[]),fr=o.useMemo(()=>{if(js.size===0||typeof document>"u")return!1;let Re=!1,pt=!1;for(const lt of js){const Dt=document.querySelectorAll(`[data-session-row="${CSS.escape(lt)}"]`);for(const qt of Dt)qt.getAttribute("data-session-archived")==="1"?pt=!0:Re=!0}return pt&&!Re},[js]),Hs=o.useMemo(()=>{if(Sr)return Sr;if(js.size===0||typeof document>"u")return null;for(const Re of js){const lt=document.querySelector(`[data-session-row="${CSS.escape(Re)}"]`)?.getAttribute("data-session-scope");if(lt&&lt.length>0)return lt}return null},[js,Sr]),Or=o.useMemo(()=>Hs?ce[Hs]??[]:[],[ce,Hs]),ga=o.useMemo(()=>{if(!Hs||js.size===0)return!1;const Re=ce[Hs]??[];for(const pt of Re)for(const lt of pt.sessionIds)if(js.has(lt))return!0;return!1},[ce,Hs,js]),kl=o.useCallback(Re=>{!Hs||js.size===0||Te(Hs,Re,Array.from(js))},[Te,js,Hs]),Cl=o.useCallback(()=>{if(!Hs||js.size===0)return;const Re=Pt(Hs);Re&&Te(Hs,Re.id,Array.from(js))},[Te,Pt,js,Hs]),$n=o.useCallback(()=>{!Hs||js.size===0||Ye(Hs,Array.from(js))},[Ye,js,Hs]),kr=o.useCallback(async()=>{const Re=Array.from(js);if(Re.length!==0){if(fr){const{deletedIds:pt,failedIds:lt}=await Js(Re);pt.length>0&&te.success(pt.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:pt.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:pt.length})),lt.length>0&&te.error(lt.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:lt.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:lt.length}))}else{const{archivedIds:pt,failedIds:lt}=await Xs(Re);pt.length>0&&te.success(pt.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:pt.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:pt.length})),lt.length>0&&te.error(lt.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:lt.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:lt.length}))}Gn.getState().clear()}},[Xs,fr,Js,js,i]),Gr=o.useCallback(()=>{const Re=js.size;if(Re!==0){if(!R){kr();return}z({sessionCount:Re,archivedBucket:fr})}},[fr,kr,js,R]),xa=o.useCallback(async()=>{z(null),await kr()},[kr]);o.useEffect(()=>{if(!Hr)return;const Re=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),pt=lt=>{if(ni)return;const Dt=lt.target;if(Dt&&(Dt.tagName==="INPUT"||Dt.tagName==="TEXTAREA"||Dt.isContentEditable))return;const qt=Re?lt.metaKey:lt.ctrlKey;if(lt.key==="Escape"){lt.preventDefault(),Gn.getState().disable();return}if(qt&&lt.key==="Backspace"){lt.preventDefault(),Gr();return}if(qt&&(lt.key==="a"||lt.key==="A")){const Rs=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Rs.length===0)return;lt.preventDefault();const ir=pr.getState().scopeKey??Rs[0]?.getAttribute("data-session-scope")??null,Un=tn=>ir?tn.getAttribute("data-session-scope")===ir:!0,Gs=Rs.filter(Un).map(tn=>tn.getAttribute("data-session-row")).filter(tn=>typeof tn=="string"&&tn.length>0);if(Gs.length===0)return;pr.getState().replaceAll(Gs,ir||null)}};return window.addEventListener("keydown",pt),()=>window.removeEventListener("keydown",pt)},[Gr,ni,pr,Hr]);const kd=o.useCallback(()=>{q("chat"),t&&$e(!1),It()},[t,It,q,$e]);return s.jsxs("div",{ref:m,className:de("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[Fs?s.jsx("div",{onMouseDown:ft,className:de("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",Ls),children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ce,className:dn,"aria-label":i("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(D,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Rt,{children:s.jsx("p",{children:i("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(F4,{hideDirectoryControls:r,handleNewSession:kd,headerActionIconClass:qi,reserveHeaderActionsSpace:Gi,headerActionButtonClass:Zs,isSessionSearchOpen:l,setIsSessionSearchOpen:u,sessionSearchInputRef:c,sessionSearchQuery:d,setSessionSearchQuery:f,hasSessionSearchQuery:Ae,searchMatchCount:Wi,collapseAllProjects:xs,expandAllProjects:cs,selectionModeEnabled:Hr,onToggleSelectionMode:Fr,showSidebarToggle:Cs,onToggleSidebar:Ce,avoidWindowControlsOverlay:Ue}),s.jsx(Y4,{topContent:Sl,sectionsForRender:Vn,projectSections:kn,activeProjectId:Oe,showOnlyMainWorkspace:a,hasSessionSearchQuery:Ae,emptyState:Ws,searchEmptyState:Hi,renderGroupSessions:Nl,homeDirectory:xe,collapsedProjects:T,hideDirectoryControls:r,projectRepoStatus:k,isDesktopShellRuntime:Vt,stuckProjectHeaders:jl,mobileVariant:t,alwaysShowActions:Yt,toggleProject:ds,setActiveProjectIdOnly:he,setActiveMainTab:q,setSessionSwitcherOpen:$e,openNewSessionDraft:It,openNewWorktreeDialog:Mn,openProjectEditDialog:y,removeProject:Ne,projectHeaderSentinelRefs:ne,reorderProjects:Be,getOrderedGroups:Xa,setGroupOrderByProject:W,openSidebarMenuKey:V,setOpenSidebarMenuKey:K,isInlineEditing:ni}),Hr&&js.size>0?s.jsx(mP,{selectedCount:js.size,scopeKey:Hs,scopeFolders:Or,archivedBucket:fr,onMoveToFolder:kl,onCreateFolderAndMove:Cl,onRemoveFromFolder:$n,canRemoveFromFolder:ga,onDelete:Gr,onDone:Lr}):null,Ms?s.jsx(Eb,{open:!!Ms,onOpenChange:Re=>{Re||y(null)},projectId:Ms.id,projectName:Ms.label||ca(Ms.path,xe),projectPath:Ms.path,initialIcon:Ms.icon,initialColor:Ms.color,initialIconBackground:Ms.iconBackground,onSave:En}):null,s.jsx(U5,{open:_,onOpenChange:O,onWorktreeCreated:(Re,pt)=>{if(q("chat"),t&&$e(!1),pt?.sessionId){dt(pt.sessionId);return}It({directoryOverride:Re})}}),s.jsx(bC,{}),s.jsx(cP,{value:ee,setValue:re,showDeletionDialog:R,setShowDeletionDialog:J,onConfirm:we}),s.jsx(uP,{value:fe,setValue:ge,onConfirm:at}),s.jsx(dP,{value:be,setValue:z,showDeletionDialog:R,setShowDeletionDialog:J,onConfirm:xa})]})},SP=()=>{const t=st.c(13),[e,n]=Le.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(Us())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),Le.useEffect(r,a);let i;t[2]!==e?(i=async p=>e?await Fb(p):{success:!0,path:p},t[2]=e,t[3]=i):i=t[3];const l=i;let u;t[4]!==e?(u=async p=>e?await Lb():{success:!0},t[4]=e,t[5]=u):u=t[5];const d=u;let f;t[6]!==e?(f=async p=>e?await Ob():{success:!0},t[6]=e,t[7]=f):f=t[7];const m=f;let c;return t[8]!==e||t[9]!==l||t[10]!==d||t[11]!==m?(c={isDesktop:e,requestAccess:l,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=l,t[10]=d,t[11]=m,t[12]=c):c=t[12],c},kP=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),CP=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:l=[],disabled:u=!1})=>{const{t:d}=ct(),[f,m]=o.useState(!1),[c,p]=o.useState(""),[g,h]=o.useState(!1),[x,w]=o.useState(!1),[b,y]=o.useState(""),[v,S]=o.useState(!1),I=o.useRef(null),j=o.useCallback(O=>{O.stopPropagation()},[]),N=l.length>1,P=o.useMemo(()=>kP(b),[b]),M=o.useMemo(()=>{const O=c.toLowerCase();return O?e.filter(V=>V.toLowerCase().includes(O)):e},[c,e]),T=o.useMemo(()=>{const O=c.toLowerCase();return O?n.filter(V=>V.toLowerCase().includes(O)):n},[c,n]),E=O=>{if(O===t){m(!1);return}a(O),m(!1),p("")},k=()=>{h(!0),setTimeout(()=>I.current?.focus(),50)},C=async()=>{if(!(!P||v)){if(N){w(!0);return}S(!0);try{await i(P,l[0]),y(""),h(!1),m(!1)}finally{S(!1)}}},A=async O=>{if(!(!P||v)){S(!0);try{await i(P,O),y(""),h(!1),w(!1),m(!1)}finally{S(!1)}}},F=()=>{w(!1)},_=()=>{y(""),h(!1),w(!1)};return o.useEffect(()=>{f||(p(""),h(!1),w(!1),y(""))},[f]),s.jsxs(ys,{open:f,onOpenChange:m,children:[s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(vs,{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:u,children:[s.jsx(D,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:t||d("gitView.branch.detachedHead")}),s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),s.jsx(Rt,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(ws,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(Jo,{className:"h-full min-h-0",children:[s.jsx(Oi,{placeholder:d("gitView.branch.searchPlaceholder"),value:c,onValueChange:p,onKeyDown:j}),s.jsxs(Xo,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Zo,{children:d("gitView.branch.empty")}),s.jsx(qn,{children:x?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:F,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(D,{name:"arrow-left",className:"size-4"})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d("gitView.branch.pushToPrefix")," ",s.jsx("span",{className:"text-foreground font-medium",children:P})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:l.map(O=>s.jsxs("button",{type:"button",onClick:()=>A(O),disabled:v,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[v?s.jsx(D,{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))})]}):g?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:I,placeholder:d("gitView.branch.newBranchPlaceholder"),value:b,onChange:O=>y(O.target.value),onClick:O=>O.stopPropagation(),onKeyDown:O=>{j(O),O.key==="Enter"?(O.preventDefault(),C()):O.key==="Escape"&&(O.preventDefault(),_())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:C,disabled:!P||v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:v?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:_,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(D,{name:"close",className:"size-4"})})]}):s.jsxs(Dn,{onSelect:k,children:[s.jsx(D,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(Aa,{}),s.jsxs(qn,{heading:d("gitView.branch.localBranches"),children:[M.map(O=>s.jsxs(Dn,{onSelect:()=>E(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}`)),M.length===0&&s.jsx(Dn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(Aa,{}),s.jsxs(qn,{heading:d("gitView.branch.remoteBranches"),children:[T.map(O=>s.jsx(Dn,{onSelect:()=>E(O),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:O})},`remote-${O}`)),T.length===0&&s.jsx(Dn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},PP=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),IP=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=ct(),[a,i]=o.useState(!1),[l,u]=o.useState(t||""),[d,f]=o.useState(!1),m=o.useRef(null),c=()=>{!t||!e||(u(t),i(!0),setTimeout(()=>m.current?.focus(),0))},p=async()=>{if(!t||!e||!l.trim())return;const x=PP(l);if(x===t){i(!1);return}f(!0);try{await e(t,x),i(!1),u("")}finally{f(!1)}},g=()=>{i(!1),u("")},h=x=>{x.key==="Enter"?(x.preventDefault(),p()):x.key==="Escape"&&(x.preventDefault(),g())};return a?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:x=>{x.preventDefault(),p()},children:[s.jsx(D,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:l,onChange:x=>u(x.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:h,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,"aria-label":r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:g,disabled:d,"aria-label":r("gitView.branch.renameCancel"),title:r("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(D,{name:"close",className:"size-4"})})]})}):s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[s.jsx(D,{name:"git-branch",className:"size-4 text-primary shrink-0"}),s.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:t||r("gitView.branch.detachedHead")}),n&&e&&t&&s.jsx(ve,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:c,title:r("gitView.branch.renameTitle"),children:s.jsx(D,{name:"edit",className:"size-4"})})]})]})},DP=t=>{const e=st.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:l,disabled:u,removingRemoteName:d,aheadCount:f,behindCount:m,trackingRemoteName:c,hasUncommittedChanges:p}=t,g=r===void 0?[]:r,h=d===void 0?null:d,x=f===void 0?0:f,w=m===void 0?0:m,b=p===void 0?!1:p,{t:y}=ct(),v=o.useRef(!1),S=!!h,I=g.find(ae=>ae.name===c)??g[0],j=w>0&&b,N=u||n!==null||S||!I||j,P=u||n!==null||S||g.length===0,M=x>0||w>0;let T;e[0]!==y?(T=y("gitView.sync.sync"),e[0]=y,e[1]=T):T=e[1];const E=w>0?`↓${w}`:null,k=x>0?`↑${x}`:null;let C;e[2]!==T||e[3]!==E||e[4]!==k?(C=[T,E,k].filter(Boolean),e[2]=T,e[3]=E,e[4]=k,e[5]=C):C=e[5];const A=C.join(" "),F=j?y("gitView.sync.commitOrStashTooltip"):I?M?y("gitView.sync.syncChangesTooltip",{ahead:x,behind:w}):y("gitView.sync.syncChanges"):y("gitView.sync.noRemoteTooltip"),_=()=>{I&&i(I)},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=de("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 K;e[7]!==y?(K=y("gitView.sync.syncChanges"),e[7]=y,e[8]=K):K=e[8];let $;e[9]!==n?($=n==="sync"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=$):$=e[10];let oe;e[11]!==A?(oe=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:A}),e[11]=A,e[12]=oe):oe=e[12];let L;e[13]!==_||e[14]!==N||e[15]!==K||e[16]!==$||e[17]!==oe?(L=s.jsx(At,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:_,disabled:N,className:V,"aria-label":K,children:[$,oe]})}),e[13]=_,e[14]=N,e[15]=K,e[16]=$,e[17]=oe,e[18]=L):L=e[18];let Y;e[19]!==F?(Y=s.jsx(Rt,{sideOffset:8,children:F}),e[19]=F,e[20]=Y):Y=e[20];let ee;e[21]!==L||e[22]!==Y?(ee=s.jsxs(Tt,{children:[L,Y]}),e[21]=L,e[22]=Y,e[23]=ee):ee=e[23];const re=ys;let fe;e[24]===Symbol.for("react.memo_cache_sentinel")?(fe=de("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]=fe):fe=e[24];let ge;e[25]!==y?(ge=y("gitView.sync.moreActionsAria"),e[25]=y,e[26]=ge):ge=e[26];let be;e[27]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx(D,{name:"arrow-down-s",className:"size-4"}),e[27]=be):be=e[27];let z;e[28]!==P||e[29]!==ge?(z=s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button",className:fe,disabled:P,"aria-label":ge,children:be})}),e[28]=P,e[29]=ge,e[30]=z):z=e[30];const B=ws,Q="start",X=-40,ie="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",le=g.map(ae=>s.jsx(vt,{onSelect:U=>{if(v.current){U.preventDefault(),v.current=!1;return}a(ae)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(D,{name:"refresh",className:"size-4 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:y("gitView.sync.fetchFromRemote",{name:ae.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:ae.fetchUrl})]})}),l&&ae.name!==c?s.jsx(ve,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||S,onPointerDown:U=>{v.current=!0,U.preventDefault(),U.stopPropagation()},onClick:U=>{v.current=!0,U.preventDefault(),U.stopPropagation(),l(ae)},"aria-label":y("gitView.header.removeRemoteAria",{name:ae.name}),title:y("gitView.header.removeRemoteTitle",{name:ae.name}),children:h===ae.name?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"close",className:"size-3.5"})}):null]})},ae.name));let ye;e[31]!==B||e[32]!==le?(ye=s.jsx(B,{align:Q,alignOffset:X,className:ie,children:le}),e[31]=B,e[32]=le,e[33]=ye):ye=e[33];let W;e[34]!==re||e[35]!==z||e[36]!==ye?(W=s.jsxs(re,{children:[z,ye]}),e[34]=re,e[35]=z,e[36]=ye,e[37]=W):W=e[37];let ue;return e[38]!==ee||e[39]!==W?(ue=s.jsxs("div",{className:O,children:[ee,W]}),e[38]=ee,e[39]=W,e[40]=ue):ue=e[40],ue},TP={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},AP={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 Vh(t){return t&&AP[t]||"var(--primary)"}const Cp=t=>{const e=st.c(8),{icon:n,className:r,colorToken:a}=t,i=TP[n??"branch"]??"user-3";let l;e[0]!==a?(l=Vh(a),e[0]=a,e[1]=l):l=e[1];let u;e[2]!==l?(u={color:l},e[2]=l,e[3]=u):u=e[3];let d;return e[4]!==r||e[5]!==i||e[6]!==u?(d=s.jsx(D,{name:i,className:r,style:u}),e[4]=r,e[5]=i,e[6]=u,e[7]=d):d=e[7],d},Uh=t=>{const e=st.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:l}=t,u=l===void 0?!1:l,{t:d}=ct(),f=i||r.length===0,m=n?.color;let c;e[0]!==m?(c=Vh(m),e[0]=m,e[1]=c):c=e[1];let p;e[2]!==c?(p={color:c},e[2]=c,e[3]=p):p=e[3];let g;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(g=i?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(Cp,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=g):g=e[7];let h;e[8]!==n?.name||e[9]!==u||e[10]!==d?(h=!u&&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]=u,e[10]=d,e[11]=h):h=e[11];let x;e[12]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=x):x=e[12];let w;e[13]!==f||e[14]!==p||e[15]!==g||e[16]!==h?(w=s.jsx(At,{asChild:!0,children:s.jsx(vs,{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:p,disabled:f,children:[g,h,x]})})}),e[13]=f,e[14]=p,e[15]=g,e[16]=h,e[17]=w):w=e[17];let b;e[18]!==d?(b=d("gitView.header.identityTooltip"),e[18]=d,e[19]=b):b=e[19];let y;e[20]!==b?(y=s.jsx(Rt,{sideOffset:8,children:b}),e[20]=b,e[21]=y):y=e[21];let v;e[22]!==y||e[23]!==w?(v=s.jsxs(Tt,{children:[w,y]}),e[22]=y,e[23]=w,e[24]=v):v=e[24];let S;e[25]!==n?.id||e[26]!==r||e[27]!==a||e[28]!==d?(S=r.length===0?s.jsx("div",{className:"px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:d("gitView.header.noProfiles")})}):r.map(N=>{const P=n?.id===N.id;return s.jsx(vt,{onSelect:()=>a(N),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(Cp,{icon:N.icon,colorToken:N.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:N.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:N.userEmail})]}),P?s.jsx(D,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},N.id)}),e[25]=n?.id,e[26]=r,e[27]=a,e[28]=d,e[29]=S):S=e[29];let I;e[30]!==S?(I=s.jsx(ws,{align:"end",className:"w-64",children:S}),e[30]=S,e[31]=I):I=e[31];let j;return e[32]!==v||e[33]!==I?(j=s.jsxs(ys,{children:[v,I]}),e[32]=v,e[33]=I,e[34]=j):j=e[34],j},RD=t=>{const e=st.c(48),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:l,remotes:u,onFetch:d,onSync:f,onRemoveRemote:m,removingRemoteName:c,onCheckoutBranch:p,onCreateBranch:g,onRenameBranch:h,activeIdentityProfile:x,availableIdentities:w,onSelectIdentity:b,isApplyingIdentity:y,isWorktreeMode:v,onOpenHistory:S,actionTabItems:I,activeActionTab:j,onSelectActionTab:N}=t,{t:P}=ct();if(!n)return null;let M;e[0]!==S||e[1]!==P?(M=S?s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:S,children:s.jsx(D,{name:"history",className:"size-4"})})}),s.jsx(Rt,{sideOffset:8,children:P("gitView.history.title")})]}):null,e[0]=S,e[1]=P,e[2]=M):M=e[2];let T;e[3]!==M?(T=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:M}),e[3]=M,e[4]=T):T=e[4];const E=T,k=!n;let C;e[5]!==n.tracking?(C=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=C):C=e[6];const A=(n.files?.length??0)>0;let F;e[7]!==d||e[8]!==m||e[9]!==f||e[10]!==u||e[11]!==c||e[12]!==n.ahead||e[13]!==n.behind||e[14]!==l||e[15]!==k||e[16]!==C||e[17]!==A?(F=s.jsx(DP,{syncAction:l,remotes:u,onFetch:d,onSync:f,onRemoveRemote:m,removingRemoteName:c,disabled:k,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:C,hasUncommittedChanges:A}),e[7]=d,e[8]=m,e[9]=f,e[10]=u,e[11]=c,e[12]=n.ahead,e[13]=n.behind,e[14]=l,e[15]=k,e[16]=C,e[17]=A,e[18]=F):F=e[18];const _=F;let O;e[19]!==x||e[20]!==w||e[21]!==y||e[22]!==b?(O=s.jsx(Uh,{activeProfile:x,identities:w,onSelect:b,isApplying:y,iconOnly:!0}),e[19]=x,e[20]=w,e[21]=y,e[22]=b,e[23]=O):O=e[23];const V=O;let K;e[24]!==i||e[25]!==v||e[26]!==r||e[27]!==p||e[28]!==g||e[29]!==h||e[30]!==a||e[31]!==u||e[32]!==n.current?(K=s.jsx("div",{className:"min-w-0 flex-1",children:v?s.jsx(IP,{currentBranch:n.current,onRename:h}):s.jsx(CP,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:p,onCreate:g,remotes:u})}),e[24]=i,e[25]=v,e[26]=r,e[27]=p,e[28]=g,e[29]=h,e[30]=a,e[31]=u,e[32]=n.current,e[33]=K):K=e[33];let $;e[34]!==V||e[35]!==E?($=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[E,V]}),e[34]=V,e[35]=E,e[36]=$):$=e[36];let oe;e[37]!==K||e[38]!==$?(oe=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[K,$]}),e[37]=K,e[38]=$,e[39]=oe):oe=e[39];let L;e[40]!==I||e[41]!==j||e[42]!==N||e[43]!==_?(L=I&&j&&N?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(ur,{items:I,activeId:j,onSelect:N,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:_})]}):null,e[40]=I,e[41]=j,e[42]=N,e[43]=_,e[44]=L):L=e[44];let Y;return e[45]!==oe||e[46]!==L?(Y=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[oe,L]}),e[45]=oe,e[46]=L,e[47]=Y):Y=e[47],Y},EP=t=>t==="/",nl=t=>t.replace(/\\/g,"/"),jd=t=>{if(!t||EP(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},$a=t=>t.endsWith("/"),MP=t=>{const e=t.trim();return!e||$a(e)?e:`${e}/`},Nd=t=>t.lastIndexOf("/"),Kh=t=>{if($a(t))return t;const e=Nd(t);return e<0?t:t.slice(0,e+1)},RP=t=>{const e=Nd(t);return t.slice(e+1)},Wh=t=>{const e=jd(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=Nd(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},FP=t=>$a(t)&&Wh(t)!==null,Pp=(t,e)=>`${Kh(t)}${e}/`,ja=t=>{if(!t)return null;const e=jd(nl(t.trim()));return e?e.toLowerCase():null},Ip=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},LP=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},OP=async()=>{try{const t=await fetch("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(t.ok){const e=await t.json();if(typeof e.home=="string"&&e.home.trim().length>0)return nl(e.home.trim())}}catch{}return Bs.getFilesystemHome().catch(()=>null)},$P=({open:t,onOpenChange:e})=>{const{t:n}=ct(),r=Ns(Te=>Te.homeDirectory),a=es(Te=>Te.projects),i=es(Te=>Te.addProject),l=_n(Te=>Te.profiles),u=_n(Te=>Te.globalIdentity),d=_n(Te=>Te.defaultGitIdentityId),f=_n(Te=>Te.loadProfiles),m=_n(Te=>Te.loadGlobalIdentity),c=_n(Te=>Te.loadDefaultGitIdentityId),p=cl(),{isDesktop:g,requestAccess:h,startAccessing:x}=SP(),{isMobile:w}=_s(),b=o.useRef(null),y=o.useRef(null),v=o.useRef(new Map),[S,I]=o.useState(""),[j,N]=o.useState("~/"),[P,M]=o.useState([]),[T,E]=o.useState(!1),[k,C]=o.useState(!1),[A,F]=o.useState(0),[_,O]=o.useState(!1),[V,K]=o.useState(!1),[$,oe]=o.useState(0),[L,Y]=o.useState(!1),[ee,re]=o.useState(""),[fe,ge]=o.useState(null),[be,z]=o.useState(!1),[B,Q]=o.useState(""),[X,ie]=o.useState(!1),le=S||r,ye=o.useMemo(()=>new Set(a.map(Te=>ja(Te.path)).filter(Te=>!!Te)),[a]);o.useEffect(()=>{if(!t)return;N("~/"),M([]),F(0),O(!1),K(!1),Y(!1),re(""),ge(null),z(!1),Q(""),ie(!1),requestAnimationFrame(()=>pc(b.current));let Te=!1;return(async()=>{const Ye=await OP();Te||(I(Ye||r||""),requestAnimationFrame(()=>pc(b.current)))})(),()=>{Te=!0}},[r,t]),o.useEffect(()=>{t&&(f(),m(),c())},[c,f,m,t]);const W=o.useMemo(()=>{const Te=new Map;u&&Te.set(u.id,u);for(const Ve of l)Te.set(Ve.id,Ve);return Array.from(Te.values())},[l,u]);o.useEffect(()=>{if(!t||!L||fe!==null)return;const Te=typeof d=="string"?d.trim():"";if(Te&&W.some(Ye=>Ye.id===Te)){ge(Te);return}const Ve=W.find(Ye=>Ye.authType==="ssh"||Ye.sshKey);Ve&&ge(Ve.id)},[W,d,L,t,fe]);const ue=o.useMemo(()=>W.find(Te=>Te.id===fe)??null,[W,fe]),ae=o.useMemo(()=>Kh(j),[j]),U=o.useMemo(()=>$a(j)?"":RP(j),[j]),G=o.useMemo(()=>le?Ip(ae,le):"",[ae,le]);o.useEffect(()=>{if(!t||!G){M([]);return}let Te=!1;return E(!0),C(!1),Bs.listLocalDirectory(G).then(Ve=>{if(Te)return;C(!1);const Ye=Ve.filter(Ge=>Ge.isDirectory).map(Ge=>({name:Ge.name,path:nl(Ge.path)})).sort((Ge,me)=>Ge.name.localeCompare(me.name));M(Ye)}).catch(()=>{Te||(M([]),C(!0))}).finally(()=>{Te||E(!1)}),()=>{Te=!0}},[G,t]);const ne=o.useMemo(()=>{const Te=U.toLowerCase(),Ve=p||U.startsWith(".");return P.filter(Ye=>Ye.name.toLowerCase().startsWith(Te)&&(Ve||!Ye.name.startsWith(".")))},[U,P,p]),se=o.useMemo(()=>{const Te=[];FP(j)&&Te.push({type:"up",value:"browse:up",name:"..",path:Wh(j)});for(const Ve of ne){const Ye=ja(Ve.path);Te.push({type:"directory",value:`browse:${Ve.path}`,name:Ve.name,path:Ve.path,disabled:!!(Ye&&ye.has(Ye))})}return Te},[ye,ne,j]);o.useEffect(()=>{F(0)},[j,se.length]);const xe=o.useMemo(()=>le?jd(Ip(j,le)):"",[le,j]),Se=ja(xe),je=!!(Se&&ye.has(Se)),Ie=o.useMemo(()=>U?ne.find(Te=>Te.name===U)??null:null,[U,ne]),Oe=!!(xe&&!je&&($a(j)&&k||!$a(j)&&U.trim().length>0&&Ie===null)),Ne=!_&&!V&&!je&&!!xe,he=Ne&&ee.trim().length>0,Fe=se[A]??null,Be=!!(Fe&&(Fe.type==="up"||Fe.type==="directory"&&!Fe.disabled)),q=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Pe=n(je?"directoryExplorerDialog.actions.alreadyAdded":L?_?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":_?"directoryExplorerDialog.actions.adding":Oe?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const Te=y.current;if(!Te)return;const Ve=()=>oe(Math.ceil(Te.getBoundingClientRect().width));if(Ve(),typeof ResizeObserver>"u")return;const Ye=new ResizeObserver(Ve);return Ye.observe(Te),()=>Ye.disconnect()},[Pe]),o.useLayoutEffect(()=>{const Te=b.current;Te&&(Te.scrollLeft=Te.scrollWidth)},[$,j]),o.useLayoutEffect(()=>{t&&pc(b.current)},[t]),o.useLayoutEffect(()=>{const Te=se[A];Te&&v.current.get(Te.value)?.scrollIntoView({block:"nearest"})},[A,se]);const $e=o.useCallback(()=>{e(!1)},[e]),Ce=o.useCallback(async Te=>{if(!Te||_)return;const Ve=ja(Te);if(Ve&&ye.has(Ve))return;let Ye=Te;O(!0);try{const Ge=!L&&Oe&&ja(Te)===ja(xe);if(L){const Ke=ee.trim();if(!Ke){te.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ye=(await Bs.cloneRepository({remoteUrl:Ke,destinationPath:Te,gitIdentityId:ue?.id??null})).path}else Ge&&await Bs.createDirectory(Te,{allowOutsideWorkspace:!0,initializeTemplate:!0});if(!i(Ye)){te.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}$e()}catch(Ge){te.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ge instanceof Error?Ge.message:n("directoryExplorerDialog.toast.unknownError")})}finally{O(!1)}},[i,ye,ee,$e,L,_,ue?.id,Oe,xe,n]),pe=o.useCallback(Te=>{N(MP(Te))},[]),R=o.useCallback(Te=>{N(Pp(j,Te.name))},[j]),J=o.useCallback(Te=>{if(Te){if(Te.type==="up"){Te.path&&pe(Te.path);return}Te.disabled||R(Te)}},[pe,R]),H=o.useCallback(async()=>{if(!(!g||V)){K(!0);try{const Te=await h(xe);if(!Te.success||!Te.path){Te.error&&Te.error!=="Directory selection cancelled"&&te.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te.error});return}const Ve=await x(Te.path);if(!Ve.success){te.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:Ve.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Ce(Te.path)}catch(Te){te.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te instanceof Error?Te.message:n("directoryExplorerDialog.toast.unknownError")})}finally{K(!1)}}},[Ce,g,V,h,x,n,xe]),Ee=o.useCallback(Te=>{if(Te.key==="ArrowDown"){Te.preventDefault(),F(Ve=>Math.min(se.length-1,Ve+1));return}if(Te.key==="ArrowUp"){Te.preventDefault(),F(Ve=>Math.max(0,Ve-1));return}if(Te.key==="Enter"){if(Te.preventDefault(),LP(Te)){Ce(xe);return}Be&&J(Fe);return}Te.key==="Backspace"&&j===""&&(Te.preventDefault(),$e())},[J,Ce,$e,Be,Fe,j,se.length,xe]),Ae=o.useCallback(async()=>{const Te=B.trim();if(!(!Te||X)){ie(!0);try{const Ve=`${G}${Te}`;await Bs.createDirectory(Ve,{allowOutsideWorkspace:!0,initializeTemplate:!0}),te.success(n("directoryExplorerDialog.toast.folderCreated")),N(Pp(j,Te)),z(!1),Q("")}catch(Ve){te.error(n("directoryExplorerDialog.toast.failedToCreateFolder"),{description:Ve instanceof Error?Ve.message:n("directoryExplorerDialog.toast.unknownError")})}finally{ie(!1)}}},[B,X,G,j,n]),Je=o.useCallback(Te=>{Te.stopPropagation(),Te.key==="Enter"?(Te.preventDefault(),Ae()):Te.key==="Escape"&&(Te.preventDefault(),z(!1),Q(""))},[Ae]),ce=s.jsxs("button",{type:"button",onClick:()=>No(!p),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:[p?s.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),_e=s.jsxs("div",{className:"px-2.5 py-1.5",children:[L?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(jt,{value:ee,onChange:Te=>re(Te.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(Uh,{activeProfile:ue,identities:W,onSelect:Te=>ge(Te.id),isApplying:_,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(D,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(jt,{ref:b,value:j,onChange:Te=>N(nl(Te.target.value)),onKeyDown:Ee,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!w&&$>0?{paddingRight:`${$+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),w?null:s.jsx(ve,{ref:y,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:L?!he:!Ne,onMouseDown:Te=>Te.preventDefault(),onClick:()=>{Ce(xe)},title:Pe,children:Pe})]})]}),et=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.jsxs("div",{className:"flex items-center justify-between px-2 pb-1 pt-0.5",children:[s.jsx("div",{className:"typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),!L&&!be&&s.jsxs("button",{type:"button",onClick:()=>{z(!0),Q(""),ie(!1)},className:"flex items-center gap-1 rounded px-1.5 py-0.5 typography-meta text-primary hover:bg-primary/10 transition-colors",children:[s.jsx(D,{name:"folder-add",className:"h-3.5 w-3.5"}),s.jsx("span",{children:n("directoryExplorerDialog.actions.newFolder")})]})]}),T?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):se.length===0&&!be?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):s.jsxs("div",{className:"space-y-0.5",children:[be&&s.jsxs("div",{className:"flex w-full items-center gap-2 rounded-lg px-2 py-1 border border-primary/40 bg-interactive-hover/30",children:[s.jsx(D,{name:"folder-add",className:"h-4 w-4 flex-shrink-0 text-primary"}),s.jsx("input",{type:"text",value:B,onChange:Te=>Q(Te.target.value),onKeyDown:Je,placeholder:n("directoryExplorerDialog.newFolder.placeholder"),className:"min-w-0 flex-1 bg-transparent border-none outline-none font-mono typography-ui-label text-foreground placeholder:text-muted-foreground/60",autoFocus:!0,disabled:X}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",disabled:X||!B.trim(),onClick:Ae,title:n("directoryExplorerDialog.newFolder.confirm"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-primary",children:s.jsx(D,{name:"check",className:"h-4 w-4"})}),s.jsx("button",{type:"button",disabled:X,onClick:()=>{z(!1),Q("")},title:n("directoryExplorerDialog.newFolder.cancel"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-muted-foreground",children:s.jsx(D,{name:"close",className:"h-4 w-4"})})]})]}),se.map((Te,Ve)=>{const Ye=Ve===A;return s.jsxs("button",{ref:Ge=>{Ge?v.current.set(Te.value,Ge):v.current.delete(Te.value)},type:"button",disabled:Te.type==="directory"&&Te.disabled,onMouseEnter:()=>F(Ve),onMouseDown:Ge=>Ge.preventDefault(),onClick:()=>J(Te),className:de("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",Ye&&"bg-interactive-selection text-interactive-selection-foreground",!Ye&&"hover:bg-interactive-hover/50",Te.type==="directory"&&Te.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Te.type==="up"?s.jsx(D,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(D,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Te.name})}),Te.type==="directory"&&Te.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]},Te.value)})]})]})}),Me=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[_e,et]}),He=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(D,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(D,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:q}),s.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),We=()=>s.jsxs(s.Fragment,{children:[w?null:He,s.jsxs("div",{className:de("flex w-full flex-row justify-end gap-2 sm:w-auto",w&&"justify-stretch"),children:[g?s.jsx(ve,{variant:"ghost",size:"xs",onClick:H,disabled:_||V||L,children:n(V?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(ve,{variant:"ghost",size:"xs",onClick:()=>Y(Te=>!Te),disabled:_||V,className:de(w&&"flex-1"),children:n(L?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),w?s.jsx(ve,{size:"xs",onClick:()=>{Ce(xe)},disabled:L?!he:!Ne,className:"flex-1",children:Pe}):null]})]});return w?s.jsx(hr,{open:t,onClose:$e,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:We()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:ce}),Me]})}):s.jsx(ls,{open:t,onOpenChange:e,children:s.jsxs(os,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(bs,{className:"px-5 pb-2 pt-5",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx(hs,{children:n("directoryExplorerDialog.title")}),s.jsx(Ss,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),ce]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:Me}),s.jsx(Is,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:We()})]})})},Zr=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,lr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},_P=()=>{const{t}=ct(),[e,n]=o.useState(!1),[r,a]=o.useState(null),[i,l]=o.useState([]),[u,d]=o.useState(!1),[f,m]=o.useState(!1),[c,p]=o.useState(!1),[g,h]=o.useState(!1),[x,w]=o.useState(new Set),b=Ft(U=>U.getWorktreeMetadata),y=Ft(U=>U.newSessionDraft),v=Ft(U=>U.setNewSessionDraftTarget),S=Ft(U=>U.setDraftBootstrapPendingDirectory),I=$b,j=Bb,N=Ft(U=>U.deleteSessions),P=Ft(U=>U.archiveSessions),M=De(U=>U.showDeletionDialog),T=De(U=>U.setShowDeletionDialog),E=Ns(U=>U.currentDirectory),k=Ns(U=>U.homeDirectory),C=es(U=>U.projects),A=es(U=>U.activeProjectId),{isMobile:F,isTablet:_,hasTouchInput:O}=_s(),V=F||_||O,K=o.useMemo(()=>{const G=(A?C.find(ne=>ne.id===A)??null:null)?.path??E;return lr(G)},[A,E,C]),$=o.useCallback(U=>{const ne=lr(U.projectDirectory)||K;return{id:(C.find(xe=>lr(xe.path)===ne)??null)?.id??`path:${ne}`,path:ne}},[K,C]),oe=g&&x.size>0,L=o.useMemo(()=>{const U=r?.worktree;return U&&typeof U.branch=="string"&&U.branch.trim().length>0?!0:i.length>0&&i.every(({metadata:G})=>typeof G.branch=="string"&&G.branch.trim().length>0)},[r?.worktree,i]),Y=r?.mode==="worktree",ee=Y,re=c||!Y||!L,fe=c||!Y,ge=o.useCallback(U=>{a({sessions:U.sessions,dateLabel:U.dateLabel,mode:U.mode??"session",worktree:U.worktree??null})},[]),be=o.useCallback(()=>{a(null),l([]),d(!1),m(!1),p(!1),h(!1),w(new Set)},[]),z=o.useCallback(async U=>{if(U.sessions.length===0)return;if(U.sessions.length===1){const xe=U.sessions[0];await I(xe.id)?te.success(t("sessions.sidebar.session.delete.success")):te.error(t("sessions.sidebar.session.delete.error"));return}const G=U.sessions.map(xe=>xe.id),{deletedIds:ne,failedIds:se}=await N(G);if(ne.length>0){const xe=se.length>0?se.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:se.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:se.length}):U.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:U.dateLabel}):void 0;te.success(ne.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ne.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ne.length}),{description:Zr(xe)})}se.length>0&&te.error(se.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:se.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:se.length}),{description:Zr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[I,N,t]);o.useEffect(()=>gr.onDeleteRequest(U=>{if(!M&&(U.mode??"session")==="session"){z(U);return}ge(U)}),[ge,M,z]),o.useEffect(()=>gr.onDirectoryRequest(()=>{n(!0)}),[]),o.useEffect(()=>{if(!r){l([]),d(!1),m(!1),h(!1),w(new Set);return}const U=r.sessions.map(se=>{const xe=b(se.id);return xe?{session:se,metadata:xe}:null}).filter(se=>!!se);l(U),d(!1),h(!1),w(new Set);const G=new Map;if(r.worktree?.path&&G.set(lr(r.worktree.path),r.worktree),U.forEach(({metadata:se})=>{se.path&&G.set(lr(se.path),se)}),G.size===0){h(!0);return}let ne=!1;return(async()=>{const se=new Map,xe=new Set;await Promise.all(Array.from(G.entries()).map(async([Se,je])=>{try{const Ie=await _b(je.path);se.set(Se,Ie),Ie?.isDirty&&xe.add(Se)}catch{je.status&&(se.set(Se,je.status),je.status.isDirty&&xe.add(Se))}})).catch(Se=>{console.warn("Failed to inspect worktree status before deletion:",Se)}),!ne&&(w(xe),h(!0),a(Se=>{if(!Se?.worktree?.path)return Se;const je=lr(Se.worktree.path),Ie=se.get(je);if(!Ie)return Se;const Oe=Se.worktree.status;return Oe?.isDirty===Ie.isDirty&&Oe?.ahead===Ie.ahead&&Oe?.behind===Ie.behind&&Oe?.upstream===Ie.upstream?Se:{...Se,worktree:{...Se.worktree,status:Ie}}}),l(Se=>Se.map(je=>{const Ie=lr(je.metadata.path),Oe=se.get(Ie);return Oe?{session:je.session,metadata:{...je.metadata,status:Oe}}:je})))})(),()=>{ne=!0}},[r,b]),o.useEffect(()=>{L||d(!1)},[L]);const B=o.useCallback(async(U,G)=>{const ne=u&&L,se=$(U),xe=lr(U.path),Se=lr(se.path);try{await zb(se,U,{deleteRemoteBranch:ne,deleteLocalBranch:G});const je=lr(y?.directoryOverride);return y?.open&&xe&&je===xe&&Se&&(S(null),v({projectId:se.id,directoryOverride:Se},{force:!0})),lr(E)===xe&&Se&&Ns.getState().setDirectory(Se,{showOverlay:!1}),!0}catch(je){return te.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Zr(je instanceof Error?je.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[L,E,u,$,y?.directoryOverride,y?.open,S,v,t]),Q=o.useCallback(async()=>{if(r){p(!0);try{const U=ee,G=U&&u,ne=U&&f;if(r.sessions.length===0&&Y&&r.worktree){if(!await B(r.worktree,ne)){be();return}const Se=t(u&&L?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");te.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Zr(Se)}),be();return}if(r.sessions.length===1){const se=r.sessions[0];if(!(Y?await j(se.id):await I(se.id,{archiveWorktree:!1,deleteRemoteBranch:G,deleteLocalBranch:ne}))){te.error(t(Y?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),p(!1);return}const Se=!Y&&U?t(G?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;te.success(t(Y?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Zr(Se),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const se=r.sessions.map(je=>je.id);let xe=[],Se=[];if(Y){const je=await P(se);xe=je.archivedIds,Se=je.failedIds}else{const je=await N(se);xe=je.deletedIds,Se=je.failedIds}if(Y&&r.worktree&&Se.length===0&&await B(r.worktree,ne),xe.length>0){const je=!Y&&U?t(G?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Oe=[Se.length>0?Y?Se.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:Se.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:Se.length}):Se.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Se.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Se.length}):r.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:r.dateLabel}):void 0,je].filter(Boolean).join(" ");te.success(Y?xe.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:xe.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:xe.length}):xe.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:xe.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:xe.length}),{description:Zr(Oe||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(Se.length>0&&(te.error(Y?Se.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Se.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:Se.length}):Se.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Se.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Se.length}),{description:Zr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),xe.length===0)){p(!1);return}}Y&&r.sessions.length===1&&r.worktree&&await B(r.worktree,ne),be()}finally{p(!1)}}},[r,u,f,I,N,j,P,be,ee,Y,L,B,t]),X=r?.worktree??i[0]?.metadata??null,ie=r?r.mode==="worktree"?r.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):r.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:r.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:r.sessions.length}):r.sessions.length===1?r.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:r.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):r.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:r.sessions.length,dateLabel:r.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:r.sessions.length}):"",le=r?s.jsxs("div",{className:de(Y?"space-y-3":"space-y-2"),children:[r.sessions.length>0&&s.jsxs("div",{className:de(Y?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[Y&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:r.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:r.sessions.length})]}),s.jsxs("ul",{className:de(Y?"mt-2 space-y-1":"space-y-0.5"),children:[r.sessions.slice(0,5).map(U=>s.jsxs("li",{className:de(Y?"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:de(!Y&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:U.title||t("sessions.sidebar.session.untitled")})]},U.id)),r.sessions.length>5&&s.jsx("li",{className:de(Y?"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:r.sessions.length-5})})]})]}),Y?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),X?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:X.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:X?Ti(X.path,k):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,ye=Y?L?s.jsxs("button",{type:"button",onClick:()=>{re||d(U=>!U)},disabled:re,className:de("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",re?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(D,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,W=Y?s.jsxs("button",{type:"button",onClick:()=>{fe||m(U=>!U)},disabled:fe,className:de("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",fe?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(D,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ue=Y?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:[W,ye]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:be,disabled:c,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:Q,disabled:c,children:t(c?"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:()=>T(!M),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":!M,children:[M?s.jsx(D,{name:"checkbox-blank",className:"size-4"}):s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:be,disabled:c,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:Q,disabled:c,children:c?t("sessions.sidebar.sessionDialogs.actions.deleting"):r?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ae=Y?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):r?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[V?s.jsx(hr,{open:!!r,onClose:()=>{c||be()},title:ae,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ue}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[ie&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:ie}),le]})}):s.jsx(ls,{open:!!r,onOpenChange:U=>{if(!U){if(c)return;be()}},children:s.jsxs(os,{className:de(Y?"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(bs,{children:[s.jsxs(hs,{className:de(Y&&"flex items-center gap-2"),children:[Y&&s.jsx(D,{name:"delete-bin",className:"h-5 w-5"}),ae]}),ie&&s.jsx(Ss,{children:ie})]}),s.jsx("div",{className:de(Y&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:le}),s.jsx(Is,{className:"mt-2 gap-2 pt-1 pb-1",children:ue})]})}),s.jsx($P,{open:e,onOpenChange:n})]})},Gc=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),zP=(t,e)=>{const n=Gc(t),r=Gc(e);return`${n}-${r}`.substring(0,60)},Dp=(t,e)=>`${t}/${e}`,BP=()=>{const t=es.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(a=>a.id===e);if(n?.path)return{id:n.id,path:n.path};const r=Ns.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},fc=vn()(qa(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:a,agent:i,files:l,setupCommands:u}=e;if(!n)return t({error:"Group name is required"}),null;if(!r)return t({error:"Prompt is required"}),null;if(a.length<1)return t({error:"Select at least 1 model"}),null;if(a.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=BP();if(!d)return t({error:"Select a project",isLoading:!1}),null;const f=d.path,c=await pf(f)&&e.isolateRuns!==!1,p=Gc(n),g=c?await fl(f):void 0,h=c?await Vb(f):null,x=[],w=u?.filter(N=>N.trim().length>0)??[],b=new Map;for(const N of a){const P=`${N.providerID}:${N.modelID}`;b.set(P,(b.get(P)||0)+1)}const y=new Map;for(const N of a){const P=`${N.providerID}:${N.modelID}`,M=b.get(P)||1,T=(y.get(P)||0)+1;y.set(P,T);const E=zP(N.providerID,N.modelID),k=M>1?Dp(p,`${E}/${T}`):Dp(p,E);try{const C=M>1?`${p}/${N.providerID}/${N.modelID}/${T}`:`${p}/${N.providerID}/${N.modelID}`;if(!c){const O=await Bs.withDirectory(f,()=>Bs.createSession({title:C}));x.push({sessionId:O.id,worktreePath:f,providerID:N.providerID,modelID:N.modelID,variant:N.variant});continue}const A=await Ub(d,{preferredName:k,mode:"new",branchName:k,worktreeName:k,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:w},{resolvedRootTrackingRemote:h}),F={...A,createdFromBranch:g,kind:"standard"},_=await Bs.withDirectory(A.path,()=>Bs.createSession({title:C}));Ft.getState().setWorktreeMetadata(_.id,F),x.push({sessionId:_.id,worktreePath:A.path,providerID:N.providerID,modelID:N.modelID,variant:N.variant})}catch(C){console.warn("[MultiRun] Failed to create session:",C)}}const v=u?.filter(N=>N.trim().length>0)??[];v.length>0&&ff(d,v).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const S=x.map(N=>N.sessionId),I=x[0]?.sessionId??null;if(S.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const j=l?.map(N=>({type:"file",mime:N.mime,filename:N.filename,url:N.url}));return(async()=>{try{await Promise.allSettled(x.map(async N=>{try{await Bs.withDirectory(N.worktreePath,()=>Bs.sendMessage({id:N.sessionId,providerID:N.providerID,modelID:N.modelID,variant:N.variant,text:r,agent:i,files:j}))}catch(P){console.warn("[MultiRun] Failed to start run:",P)}}))}catch(N){console.warn("[MultiRun] Failed to start runs:",N)}})(),t({isLoading:!1}),{groupSlug:p,sessionIds:S,firstSessionId:I}}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"})),VP="oc:lastWorktreeSourceBranch";function Hh(t){const e=st.c(30),{git:n}=wn(),r=yf(t),a=of(t),i=lf(t),l=vf(t),u=yn(GP),d=yn(HP);let f,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==a||e[4]!==i?(f=()=>{!t||!n||a!==null||i||d(t,n,{silent:!0})},m=[t,n,d,a,i],e[0]=t,e[1]=d,e[2]=n,e[3]=a,e[4]=i,e[5]=f,e[6]=m):(f=e[5],m=e[6]),o.useEffect(f,m);let c;e[7]!==r?.all||e[8]!==t||e[9]!==u||e[10]!==n||e[11]!==a?(c=()=>{!t||!n||a===!0&&(r?.all||u(t,n))},e[7]=r?.all,e[8]=t,e[9]=u,e[10]=n,e[11]=a,e[12]=c):c=e[12];const p=r?.all;let g;e[13]!==t||e[14]!==u||e[15]!==n||e[16]!==a||e[17]!==p?(g=[t,n,a,p,u],e[13]=t,e[14]=u,e[15]=n,e[16]=a,e[17]=p,e[18]=g):g=e[18],o.useEffect(c,g);const h=i||a===!0&&l;let x;e:{if(!r?.all){let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[19]=N):N=e[19],x=N;break e}let j;e[20]!==r.all?(j=r.all.filter(WP).sort(),e[20]=r.all,e[21]=j):j=e[21],x=j}const w=x;let b;e:{if(!r?.all){let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[22]=N):N=e[22],b=N;break e}let j;e[23]!==r.all?(j=r.all.filter(KP).map(UP).sort(),e[23]=r.all,e[24]=j):j=e[24],b=j}const y=b;let v;e:{if(!t){v=null;break e}if(a!==null){v=a;break e}if(h){v=null;break e}v=r?.all?!0:null}const S=v;let I;return e[25]!==S||e[26]!==h||e[27]!==w||e[28]!==y?(I={localBranches:w,remoteBranches:y,isLoading:h,isGitRepository:S},e[25]=S,e[26]=h,e[27]=w,e[28]=y,e[29]=I):I=e[29],I}function UP(t){return t.replace(/^remotes\//,"")}function KP(t){return t.startsWith("remotes/")}function WP(t){return!t.startsWith("remotes/")}function HP(t){return t.fetchStatus}function GP(t){return t.fetchBranches}const qP=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:l}=ct(),{localBranches:u,remoteBranches:d,isLoading:f,isGitRepository:m}=Hh(t),c=o.useMemo(()=>[...u,...d.map(g=>`remotes/${g}`)],[u,d]);o.useEffect(()=>{if(a||f||c.length===0||e&&c.includes(e))return;(async()=>{try{const h=t?await fl(t).catch(()=>null):null,x=localStorage.getItem(VP);x&&c.includes(x)?n(x):h&&c.includes(h)?n(h):c.includes("main")?n("main"):c.includes("master")?n("master"):c[0]&&n(c[0])}catch{}})()},[c,t,a,f,n,e]);const p=a||!m||f;return s.jsxs("div",{children:[s.jsxs(Qt,{value:e,onValueChange:n,disabled:p,children:[s.jsx(Jt,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(as,{placeholder:l(f?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(Xt,{className:"max-h-[280px] max-w-[320px]",children:f?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.loadingBranches")}):u.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[u.length>0&&s.jsxs(lu,{children:[s.jsx(cu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),u.map(g=>s.jsx(Ct,{value:g,className:"whitespace-normal break-all",children:g},g))]}),u.length>0&&d.length>0&&s.jsx(Kb,{}),d.length>0&&s.jsxs(lu,{children:[s.jsx(cu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),d.map(g=>s.jsx(Ct,{value:`remotes/${g}`,className:"whitespace-normal break-all",children:g},`remotes/${g}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:l("multiRun.branchSelector.status.notInGitRepository")})]})},YP=10*1024*1024,hc=5,bo=t=>{const e=st.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let a;return e[1]!==n?(a=s.jsxs(Tt,{children:[r,s.jsx(Rt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=a):a=e[2],a},Na=t=>{const e=st.c(9),{htmlFor:n,required:r,children:a,info:i}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let u;e[2]!==a||e[3]!==n||e[4]!==l?(u=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,l]}),e[2]=a,e[3]=n,e[4]=l,e[5]=u):u=e[5];const d=i&&i;let f;return e[6]!==u||e[7]!==d?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[u,d]}),e[6]=u,e[7]=d,e[8]=f):f=e[8],f},QP=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=ct(),[i,l]=o.useState(""),[u,d]=o.useState(()=>t??""),[f,m]=o.useState([]),[c,p]=o.useState(""),[g,h]=o.useState([]),[x,w]=o.useState(!1),[b,y]=o.useState([]),[v,S]=o.useState(!1),[I,j]=o.useState(!1),[N,P]=o.useState(!0),[M,T]=o.useState(!1),[E,k]=o.useState(""),[C,A]=o.useState(!1),[F,_]=o.useState(""),O=o.useRef(null),V=o.useRef(null),K=o.useRef(null),$=o.useRef(null),oe=Ns(Me=>Me.currentDirectory??null),L=Ns(Me=>Me.homeDirectory??null),Y=o.useMemo(()=>{if(typeof window>"u")return null;const Me=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Me=="string"&&Me.trim().length>0?Me.trim():null},[]),ee=es(Me=>Me.activeProjectId),re=es(Me=>Me.setActiveProjectIdOnly),fe=es(Me=>Me.projects),[ge,be]=o.useState(()=>ee??null);o.useEffect(()=>{if(ee){be(ee);return}!ge&&fe.length>0&&be(fe[0].id)},[ee,fe,ge]);const z=o.useMemo(()=>ge?fe.find(Me=>Me.id===ge)??null:null,[fe,ge]),B=z?.path??oe,Q=o.useCallback(Me=>{be(Me),Me!==ee&&re(Me)},[ee,re]),{currentTheme:X}=rr(),ie=o.useCallback(Me=>{const He=Me.label?.trim()||ca(Me.path,L),We=Bi({id:Me.id,iconImage:Me.iconImage??null},{themeVariant:X.metadata.variant,iconColor:X.colors.surface.foreground}),Te=Me.icon?pl[Me.icon]:null,Ve=Me.color?Vi[Me.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[We?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Me.iconBackground?{backgroundColor:Me.iconBackground}:void 0,children:s.jsx("img",{src:We,alt:"",className:"h-full w-full object-contain",draggable:!1})}):Te?s.jsx(D,{name:Te,className:"h-3.5 w-3.5 shrink-0",style:Ve?{color:Ve}:void 0}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Ve?{color:Ve}:void 0}),s.jsx("span",{className:"truncate",children:He})]})},[L,X.metadata.variant,X.colors.surface.foreground]),le=o.useMemo(()=>{if(z?.path)return{id:z.id,path:z.path};const Me=oe??Y;return Me?{id:`path:${Me}`,path:Me}:null},[z,oe,Y]),[ye,W]=o.useState(()=>typeof window>"u"?!1:Us()),ue=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ae=ol();o.useEffect(()=>{typeof window>"u"||W(Us())},[]);const U=o.useMemo(()=>{if(typeof window>"u")return null;const Me=window.__APP_MACOS_MAJOR__;if(typeof Me=="number"&&Number.isFinite(Me)&&Me>0)return Me;if(typeof navigator>"u")return null;const He=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!He)return null;const We=Number.parseInt(He[1],10),Te=Number.parseInt(He[2],10);return Number.isNaN(We)?null:We===10?Te:We},[]),G=o.useMemo(()=>ye&&ue||ae?"pl-[5.5rem]":"pl-3",[ye,ue,ae]),ne=o.useMemo(()=>!ye||!ue||U===null?"":U>=26?"h-12":U<=15?"h-14":"",[ye,ue,U]),se=o.useCallback(async Me=>{Me.target.closest("button, a, input, select, textarea")||Me.button===0&&ye&&await Cf()},[ye]);o.useEffect(()=>{if(!n)return;const Me=He=>{He.key==="Escape"&&(He.preventDefault(),He.stopPropagation(),n())};return window.addEventListener("keydown",Me,!0),()=>window.removeEventListener("keydown",Me,!0)},[n]);const[xe,Se]=o.useState(""),{isLoading:je,isGitRepository:Ie}=Hh(B),Oe=o.useRef(!1),Ne=Ie===!0,he=Ne&&N;o.useEffect(()=>{if(Ie===!1){Oe.current=!0,P(!1);return}Ie===!0&&Oe.current&&(Oe.current=!1,P(!0))},[Ie]);const Fe=fc(Me=>Me.createMultiRun),Be=fc(Me=>Me.error),q=fc(Me=>Me.clearError);o.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Me=>Me.trim().length>0?Me:t)},[t]),o.useEffect(()=>{if(!le)return;let Me=!1;return j(!0),(async()=>{try{const He=await id(le);Me||y(He)}catch{}finally{Me||j(!1)}})(),()=>{Me=!0}},[le]);const Pe=Me=>{f.length>=hc||(m(He=>[...He,Me]),q())},$e=Me=>{m(He=>He.filter((We,Te)=>Te!==Me)),q()},Ce=o.useCallback((Me,He)=>{m(We=>We.map((Te,Ve)=>Ve===Me?He:Te))},[]),pe=async Me=>{const He=Me.target.files;if(!He)return;let We=0;for(let Te=0;Te<He.length;Te++){const Ve=He[Te];if(Ve.size>YP){te.error(a("multirun.launcher.toast.fileTooLarge",{fileName:Ve.name}));continue}try{const Ye=await new Promise((me,Ke)=>{const ze=new FileReader;ze.onload=()=>me(ze.result),ze.onerror=Ke,ze.readAsDataURL(Ve)}),Ge={id:Gb(),filename:Ve.name,mimeType:Ve.type||"application/octet-stream",size:Ve.size,dataUrl:Ye};h(me=>[...me,Ge]),We++}catch(Ye){console.error("File attach failed",Ye),te.error(a("multirun.launcher.toast.attachFailed",{fileName:Ve.name}))}}We>0&&te.success(We===1?a("multirun.launcher.toast.attachedSingle",{count:We}):a("multirun.launcher.toast.attachedPlural",{count:We})),O.current&&(O.current.value="")},R=Me=>{h(He=>He.filter(We=>We.id!==Me))},J=o.useCallback((Me,He)=>{if(Me.startsWith("/")){const Ve=Me.indexOf(" "),Ye=Me.indexOf(`
177
177
  `),Ge=Math.min(Ve===-1?Me.length:Ve,Ye===-1?Me.length:Ye);if(He<=Ge&&Ve===-1){_(Me.substring(1,Ge)),A(!0),T(!1);return}}A(!1);const We=Me.substring(0,He),Te=We.lastIndexOf("@");if(Te!==-1){const Ve=Te>0?We[Te-1]:null,Ye=We.substring(Te+1);(!Ve||/\s/.test(Ve))&&!Ye.includes(" ")&&!Ye.includes(`
178
- `)?(k(Ye),T(!0)):T(!1);return}T(!1)},[]),H=o.useCallback(Me=>{if(C&&$.current&&(Me.key==="Enter"||Me.key==="ArrowUp"||Me.key==="ArrowDown"||Me.key==="Escape"||Me.key==="Tab")){Me.preventDefault(),$.current.handleKeyDown(Me.key);return}M&&K.current&&(Me.key==="Enter"||Me.key==="ArrowUp"||Me.key==="ArrowDown"||Me.key==="Escape"||Me.key==="Tab")&&(Me.preventDefault(),K.current.handleKeyDown(Me.key))},[C,M]),Ee=o.useCallback(Me=>{const We=V.current?.selectionStart??u.length,Ve=u.substring(0,We).lastIndexOf("@"),Ye=Me.relativePath&&Me.relativePath.trim().length>0?Me.relativePath.trim():Me.path||Me.name,Ge=Ve!==-1?Ve:We,me=`${u.substring(0,Ge)}@${Ye} ${u.substring(We)}`,Ke=Ge+Ye.length+2;d(me),T(!1),k(""),requestAnimationFrame(()=>{const ze=V.current;ze&&(ze.selectionStart=Ke,ze.selectionEnd=Ke,ze.focus()),J(me,Ke)})},[u,J]),Ae=o.useCallback(Me=>{const We=V.current?.selectionStart??u.length,Ve=u.substring(0,We).lastIndexOf("@"),Ye=Ve!==-1?Ve:We,Ge=`${u.substring(0,Ye)}@${Me} ${u.substring(We)}`,me=Ye+Me.length+2;d(Ge),T(!1),k(""),requestAnimationFrame(()=>{const Ke=V.current;Ke&&(Ke.selectionStart=me,Ke.selectionEnd=me,Ke.focus()),J(Ge,me)})},[u,J]),Je=o.useCallback(Me=>{const He=`/${Me.name} `;d(He),A(!1),_(""),requestAnimationFrame(()=>{const We=V.current;We&&(We.focus(),We.selectionStart=We.value.length,We.selectionEnd=We.value.length),J(He,He.length)})},[J]),ce=async Me=>{if(Me.preventDefault(),!!u.trim()&&!(f.length<2)){w(!0),q();try{ge&&ge!==ee&&re(ge);const He=f.map(({instanceId:Ge,...me})=>me),We=g.map(Ge=>({mime:Ge.mimeType,filename:Ge.filename,url:Ge.dataUrl})),Te=b.filter(Ge=>Ge.trim().length>0),Ve={name:i.trim(),prompt:u.trim(),models:He,agent:c||void 0,worktreeBaseBranch:he?xe:void 0,isolateRuns:he,files:We.length>0?We:void 0,setupCommands:Te.length>0?Te:void 0},Ye=await Fe(Ve);Ye&&(Ye.firstSessionId&&Ft.getState().setCurrentSession(Ye.firstSessionId),e?.())}finally{w(!1)}}},_e=!!(i.trim()&&u.trim()&&f.length>=2&&B&&!je&&(Ie===!1||!he||xe)),et=b.filter(Me=>Me.trim()).length;return s.jsxs("form",{onSubmit:ce,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:se,className:de("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",G,ne),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:a("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":a("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(D,{name:"close",className:"h-5 w-5"})})}),s.jsx(Rt,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Nf,{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(Na,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),fe.length>0?s.jsxs(Qt,{value:ge??void 0,onValueChange:Q,children:[s.jsx(Jt,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:z?s.jsx(as,{children:ie(z)}):s.jsx(as,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(Xt,{fitContent:!0,children:fe.map(Me=>s.jsx(Ct,{value:Me.id,className:"max-w-[24rem]",children:ie(Me)},Me.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:a("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Na,{htmlFor:"group-name",required:!0,info:s.jsx(bo,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(jt,{id:"group-name",value:i,onChange:Me=>l(Me.target.value),placeholder:a("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Na,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(bo,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(qP,{directory:B,value:xe,onChange:Se,disabled:!he,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(ss,{checked:N,onChange:P,disabled:!Ne,ariaLabel:a("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:a("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Na,{htmlFor:"multirun-agent",info:s.jsx(bo,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(Wb,{value:c,onChange:p,id:"multirun-agent"})]})]}),s.jsxs(br,{open:v,onOpenChange:S,children:[s.jsxs(yr,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(D,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:a("multirun.launcher.setupCommands.label")}),et>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:et}),s.jsx(D,{name:"arrow-down-s",className:de("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",v&&"rotate-180")})]}),s.jsx(vr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:I?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[b.map((Me,He)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(jt,{value:Me,onChange:We=>{const Te=[...b];Te[He]=We.target.value,y(Te)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const We=b.filter((Te,Ve)=>Ve!==He);y(We)},className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":a("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]},`${Me}-${He}`)),s.jsxs("button",{type:"button",onClick:()=>y([...b,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(D,{name:"add",className:"h-3 w-3"}),a("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Na,{htmlFor:"prompt",required:!0,children:a("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(nn,{id:"prompt",ref:V,value:u,onChange:Me=>{const He=Me.target.value;d(He);const We=Me.target.selectionStart??He.length;J(He,We)},onKeyDown:H,placeholder:a("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),C?s.jsx(wf,{ref:$,searchQuery:F,onCommandSelect:Je,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,M?s.jsx(jf,{ref:K,searchQuery:E,onFileSelect:Ee,onAgentSelect:Ae,onClose:()=>T(!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:O,type:"file",multiple:!0,className:"hidden",onChange:pe,accept:"*/*"}),s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>O.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(D,{name:"attachment-2",className:"h-3 w-3"}),a("multirun.launcher.attachments.attach")]})}),s.jsx(Rt,{children:a("multirun.launcher.attachments.tooltip")})]}),g.map(Me=>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:[Me.mimeType.startsWith("image/")?s.jsx(D,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(D,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Me.filename,children:Me.filename}),s.jsx("button",{type:"button",onClick:()=>R(Me.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(D,{name:"close",className:"h-3 w-3"})})]},Me.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Na,{required:!0,info:s.jsx(bo,{children:a("multirun.launcher.models.info",{max:hc})}),children:a("multirun.launcher.models.label")}),s.jsx(Hb,{selectedModels:f,onAdd:Pe,onRemove:$e,onUpdate:Ce,minModels:2,maxModels:hc})]}),Be&&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:Be})]})})}),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:[!he&&Ie!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(D,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:a("multirun.launcher.project.gitRequired")})]}):null,s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(ve,{type:"submit",size:"sm",disabled:!_e||x,children:x?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithModelCount",{count:f.length})})})]})})]})},JP=()=>typeof window>"u"?0:window.visualViewport?.height??window.innerHeight,XP=()=>{const t=st.c(2),[e,n]=o.useState(ZP),r=o.useRef(null);let a,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{if(typeof window>"u"||!window.visualViewport)return;const l=()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null;const d=window.visualViewport.height,f=Math.max(0,window.innerHeight-d);n(m=>m.height===d&&m.keyboardHeight===f?m:{height:d,keyboardHeight:f})}))};return window.visualViewport.addEventListener("resize",l),window.visualViewport.addEventListener("scroll",l,{passive:!0}),l(),()=>{r.current!==null&&cancelAnimationFrame(r.current),window.visualViewport?.removeEventListener("resize",l),window.visualViewport?.removeEventListener("scroll",l)}},i=[],t[0]=a,t[1]=i):(a=t[0],i=t[1]),o.useEffect(a,i),e};function ZP(){return{height:JP(),keyboardHeight:0}}class eI extends o.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(Pf,{className:"w-full max-w-md",children:[s.jsx(qb,{className:"text-center",children:s.jsxs(Yb,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(D,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Qb,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(ve,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(D,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function tI(t){const e=st.c(22),{t:n}=ct();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let a;e[2]!==n?(a=n("chat.errorBoundary.description"),e[2]=n,e[3]=a):a=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let l;e[6]!==n?(l=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=l):l=e[7];let u;e[8]!==n?(u=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=u):u=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let f;e[12]!==r||e[13]!==a||e[14]!==i||e[15]!==l||e[16]!==u||e[17]!==d?(f={title:r,description:a,sessionLabel:i,detailsSummary:l,resetAction:u,persistentHint:d},e[12]=r,e[13]=a,e[14]=i,e[15]=l,e[16]=u,e[17]=d,e[18]=f):f=e[18];let m;return e[19]!==t||e[20]!==f?(m=s.jsx(eI,{...t,texts:f}),e[19]=t,e[20]=f,e[21]=m):m=e[21],m}const qc=t=>{const e=st.c(5),{readOnly:n}=t,r=n===void 0?!1:n,i=Ft(sI)||void 0;let l;e[0]!==r?(l=s.jsx(Jb,{readOnly:r}),e[0]=r,e[1]=l):l=e[1];let u;return e[2]!==i||e[3]!==l?(u=s.jsx(tI,{sessionId:i,children:l}),e[2]=i,e[3]=l,e[4]=u):u=e[4],u};function sI(t){return t.currentSessionId}const nI=Mr(()=>Qn(()=>Promise.resolve().then(()=>Fj),void 0).then(t=>({default:t.PlanView}))),Tp=Mr(()=>Qn(()=>import("./GitView-CRci4Kd3.js"),__vite__mapDeps([6,0,1,3,4,5,7])).then(t=>({default:t.GitView}))),rI=Mr(()=>Qn(()=>Promise.resolve().then(()=>tj),void 0).then(t=>({default:t.DiffView}))),Ap=Mr(()=>Qn(()=>import("./TerminalView-Hf0MwY4N.js"),__vite__mapDeps([8,0,1,3,4,5,7])).then(t=>({default:t.TerminalView}))),aI=Mr(()=>Qn(()=>Promise.resolve().then(()=>Dj),void 0).then(t=>({default:t.FilesView}))),iI=Mr(()=>Qn(()=>Promise.resolve().then(()=>_3),void 0).then(t=>({default:t.SettingsView}))),oI=Mr(()=>Qn(()=>import("./SettingsWindow-DabGW7z5.js"),__vite__mapDeps([9,0,1,3,4,5,7])).then(t=>({default:t.SettingsWindow}))),lI=Mr(()=>Qn(()=>import("./MultiRunWindow-C0-pQgUW.js"),__vite__mapDeps([10,0,1,3,4,5,7])).then(t=>({default:t.MultiRunWindow}))),yo=85,cI=250,dI=500,uI=200,mI=860,pI=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},fI=()=>{const{t}=ct(),e=1140,n=1220,r=640,a=700,i=De(B=>B.isSidebarOpen),l=De(B=>B.isRightSidebarOpen),u=De(B=>B.isBottomTerminalOpen),d=De(B=>B.setRightSidebarOpen),f=De(B=>B.setBottomTerminalOpen),m=De(B=>B.activeMainTab),c=De(B=>B.setIsMobile),p=De(B=>B.isSessionSwitcherOpen),g=De(B=>B.isSettingsDialogOpen),h=De(B=>B.setSettingsDialogOpen),x=De(B=>B.isMultiRunLauncherOpen),w=De(B=>B.setMultiRunLauncherOpen),b=De(B=>B.multiRunLauncherPrefillPrompt),{isMobile:y,isTablet:v}=_s(),S=XP(),I=o.useMemo(()=>Us(),[]),j=De(B=>B.sidebarWidth),N=De(B=>B.rightSidebarWidth),[P,M]=o.useState(null),T=jr()??"",E=o.useMemo(()=>pI(T),[T]),k=De(B=>{if(!E)return!1;const Q=B.contextPanelByDirectory[E],X=Q?.tabs??[],ie=X.find(le=>le.id===Q?.activeTabId)??X[X.length-1];return!!(Q?.isOpen&&ie)}),C=De(B=>B.setSidebarOpen),A=De(B=>B.openContextOverview),F=De(B=>B.openContextPanelTab),_=o.useRef(!1),O=o.useRef(!1),V=o.useRef(!1),[K,$]=o.useState(!1),oe=o.useRef(!1),L=$d(0),Y=Le.useRef(0),ee=$d(0),re=Le.useRef(0);Le.useEffect(()=>{y&&(Y.current=window.innerWidth*(yo/100),re.current=window.innerWidth*(yo/100))},[y]),Le.useEffect(()=>{if(!y)return;const B=K?0:-Y.current;_d(L,B,{type:"spring",stiffness:400,damping:35,mass:.8})},[K,y,L]),Le.useEffect(()=>{if(!y)return;oe.current=l;const B=l?0:re.current;_d(ee,B,{type:"spring",stiffness:400,damping:35,mass:.8})},[y,l,ee]),Le.useEffect(()=>{y&&$(p)},[p,y]),Le.useEffect(()=>{!y||!g||($(!1),p&&De.getState().setSessionSwitcherOpen(!1),l&&d(!1))},[y,g,p,l,d]),Le.useEffect(()=>{y&&(oe.current=l)},[l,y]),o.useEffect(()=>{De.getState().isMobile!==y&&c(y)},[y,c]),o.useEffect(()=>{if(typeof window>"u")return;let B;const Q=()=>{B!==void 0&&window.clearTimeout(B),B=window.setTimeout(()=>{De.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",Q),()=>{window.removeEventListener("resize",Q),B!==void 0&&window.clearTimeout(B)}},[]),o.useEffect(()=>{if(k){De.getState().isSidebarOpen&&(C(!1),V.current=!0);return}V.current&&(C(!0),V.current=!1)},[k,C]),o.useEffect(()=>{if(!T)return;const B=De.getState(),Q=T.replace(/\\/g,"/").replace(/\/+$/,"");if(!B.contextPanelByDirectory[Q]?.isOpen){F(T,{mode:"design"}),F(T,{mode:"templates"});const ie=Q+"/output";F(T,{mode:"file",targetPath:ie}),A(T)}},[T,A,F]),o.useEffect(()=>{if(!T)return;let B=!1,Q=zo.getState().changeCounter;const X=zo.subscribe(ie=>{if(ie.changeCounter===Q)return;Q=ie.changeCounter;const{lastFileChange:le}=ie;if(!le||B)return;const ye=T.replace(/\\/g,"/").replace(/\/+$/,""),W=le.file.replace(/\\/g,"/").replace(/\/+$/,"");if(!W.startsWith(ye))return;const ue=De.getState(),ae=ue.contextPanelByDirectory[ye];if(le.event==="add")ue.openContextFile(ye,W);else if(le.event==="change")ae?.tabs.some(G=>G.mode==="file"&&G.targetPath===W)&&(ue.setPendingFileFocusPath(null),setTimeout(()=>{B||ue.openContextFile(ye,W)},50));else if(le.event==="unlink"){const U=ae?.tabs.find(G=>G.mode==="file"&&G.targetPath===W);U&&ue.closeContextPanelTab(ye,U.id)}});return()=>{B=!0,X()}},[T]),o.useEffect(()=>{if(typeof window>"u")return;let B;const Q=()=>{const ie=De.getState(),le=window.innerWidth,ye=window.innerHeight;if(!y&&!v){const W=le<e,ue=le>=n;W?ie.isRightSidebarOpen&&(d(!1),_.current=!0):ue&&_.current&&(d(!0),_.current=!1);const ae=ye<r,U=ye>=a;ae?ie.isBottomTerminalOpen&&(f(!1),O.current=!0):U&&O.current&&(f(!0),O.current=!1)}},X=()=>{B!==void 0&&window.clearTimeout(B),B=window.setTimeout(()=>{Q()},100)};return Q(),window.addEventListener("resize",X),()=>{window.removeEventListener("resize",X),B!==void 0&&window.clearTimeout(B)}},[y,v,f,d]),o.useEffect(()=>{if(typeof window>"u")return;const B=De.subscribe((Q,X)=>{const ie=window.innerWidth,le=window.innerHeight,ye=ie>=n,W=le>=a;Q.isRightSidebarOpen!==X.isRightSidebarOpen&&ye&&(_.current=!1),Q.isBottomTerminalOpen!==X.isBottomTerminalOpen&&W&&(O.current=!1)});return()=>{B()}},[y,v,f,d]);const fe=o.useMemo(()=>{switch(m){case"plan":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(nI,{})});case"git":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Tp,{})});case"diff":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(rI,{})});case"terminal":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Ap,{})});case"files":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(aI,{})});default:return null}},[m]),ge=m==="chat",be=o.useMemo(()=>Math.min(dI,Math.max(cI,j||kc)),[j]),z=o.useMemo(()=>Math.min(mI,Math.max(uI,N||Kf)),[N]);return s.jsx(jw,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:de("main-content-safe-area",y?"flex flex-col":"flex h-[100dvh]","bg-background"),style:y&&S.height>0?{height:S.height}:void 0,children:[s.jsx(z3,{}),s.jsx(P5,{}),s.jsx(A5,{}),s.jsx(_P,{}),y?s.jsxs(Xb,{value:{leftDrawerOpen:K,rightDrawerOpen:l,toggleLeftDrawer:()=>{l&&d(!1),$(!K)},toggleRightDrawer:()=>{K&&$(!1),d(!l)},leftDrawerX:L,rightDrawerX:ee,leftDrawerWidth:Y,rightDrawerWidth:re,setMobileLeftDrawerOpen:$,setRightSidebarOpen:d},children:[!g&&s.jsx(Iu,{onToggleLeftDrawer:()=>{l&&d(!1),$(!K)},onToggleRightDrawer:()=>{K&&$(!1),d(!l)},leftDrawerOpen:K,rightDrawerOpen:l}),s.jsx(Tl.button,{type:"button",initial:!1,animate:{opacity:K||l?1:0,pointerEvents:K||l?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{$(!1),d(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Tl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(Y.current||window.innerWidth*.85),right:0},style:{width:`${yo}%`,x:L},onDragEnd:(B,Q)=>{const X=Y.current||window.innerWidth*.85,ie=X*.3,le=500,ye=L.get(),W=Q.offset.x<-ie||Q.velocity.x<-le,ue=Q.offset.x>ie||Q.velocity.x>le;W?(L.set(-X),$(!1)):ue?(L.set(0),$(!0)):ye>-X/2?L.set(0):L.set(-X)},className:de("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":!K,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(As,{children:s.jsx(kp,{mobileVariant:!0})})})})}),s.jsx(Tl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:re.current||window.innerWidth*.85},style:{width:`${yo}%`,x:ee},onDragEnd:(B,Q)=>{const X=re.current||window.innerWidth*.85,ie=X*.3,le=500,ye=ee.get(),W=Q.offset.x>ie||Q.velocity.x>le,ue=Q.offset.x<-ie||Q.velocity.x<-le;W?(ee.set(X),d(!1)):ue?(ee.set(0),d(!0)):ye<X/2?ee.set(0):ee.set(X)},className:de("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":!l,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(As,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Tp,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:de("flex flex-1 overflow-hidden relative",g&&"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:de("absolute inset-0",!ge&&"invisible"),children:s.jsx(As,{children:s.jsx(qc,{})})}),fe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(As,{children:fe})}),x&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(As,{children:s.jsx(QP,{initialPrompt:b,onCreated:()=>w(!1),onCancel:()=>w(!1)})})})]})}),g&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(As,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(iI,{onClose:()=>h(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:de("absolute inset-0 flex overflow-hidden","bg-sidebar"),"data-page-scroll-lock":"true",children:[i?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:de("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${be}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:de("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${be}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,l?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:de("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${z}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:de("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${z}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(qv,{isOpen:i,isMobile:y,className:"border-0",children:s.jsx(kp,{})}),s.jsxs("div",{className:de("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",l&&"border-r border-border/50 rounded-tr-[10px] rounded-br-[10px]"),"data-page-scroll-lock":"true",children:[s.jsx(Iu,{desktopRightSidebarActionsHost:P}),s.jsx("div",{className:de("flex flex-1 min-h-0 overflow-hidden",l?"":"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:de("absolute inset-0",!ge&&"invisible"),children:s.jsx(As,{children:s.jsx(qc,{})})}),fe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(As,{children:fe})})]}),s.jsx(sN,{})]})}),s.jsx(Uv,{isOpen:u,isMobile:y,children:u?s.jsx(As,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Ap,{})})}):null})]}),s.jsx(Yv,{isOpen:l,className:"border-0",onTopActionsHostChange:M,children:s.jsx(As,{children:s.jsx(Y1,{})})})]})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(oI,{open:g,onOpenChange:h})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(lI,{open:x,onOpenChange:w,initialPrompt:b})})]})]})})},Gh=12,hI=[{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"}],gI=t=>{const e=st.c(18),{isActive:n,burstKey:r,className:a,durationMs:i,bursts:l,onComplete:u}=t,d=r===void 0?0:r,f=i===void 0?900:i,m=l===void 0?hI:l,c=Le.useRef(!1);let p,g;e[0]!==n||e[1]!==u?(p=()=>{!n&&c.current&&u?.(),n&&(c.current=!0)},g=[n,u],e[0]=n,e[1]=u,e[2]=p,e[3]=g):(p=e[2],g=e[3]),Le.useEffect(p,g);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=Array.from({length:Gh},xI),e[4]=h):h=e[4];const x=h;if(!n)return null;let w;e[5]!==a?(w=de("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=w):w=e[6];let b;if(e[7]!==d||e[8]!==m||e[9]!==f){let v;e[11]!==d||e[12]!==f?(v=S=>{const I={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${f}ms`};return s.jsx("div",{className:"firework-burst",style:I,children:x.map((j,N)=>{const P=j.x*S.radius,M=j.y*S.radius,T={"--translate-x":`${P}px`,"--translate-y":`${M}px`,"--particle-delay":`${j.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:T},`${S.id}-${N}-${d}`)})},`${S.id}-${d}`)},e[11]=d,e[12]=f,e[13]=v):v=e[13],b=m.map(v),e[7]=d,e[8]=m,e[9]=f,e[10]=b}else b=e[10];let y;return e[14]!==d||e[15]!==w||e[16]!==b?(y=s.jsx("div",{className:w,"aria-hidden":"true","data-burst-key":d,children:b}),e[14]=d,e[15]=w,e[16]=b,e[17]=y):y=e[17],y};function xI(t,e){const n=Math.PI*2*e/Gh;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const bI=t=>{const e=st.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,a=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[l,u]=Le.useState(i),d=Le.useRef(null);let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=f):f=e[3];const m=f;let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{m(),u(yI)},e[4]=c):c=e[4];const p=c;let g;e[5]!==a?(g=()=>{m(),u(vI),d.current=window.setTimeout(()=>{u(wI),d.current=null},a)},e[5]=a,e[6]=g):g=e[6];const h=g;let x,w;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=()=>()=>m(),w=[m],e[7]=x,e[8]=w):(x=e[7],w=e[8]),Le.useEffect(x,w);let b;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==h?(b={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:h,dismissFireworks:p},e[9]=l.cycle,e[10]=l.isActive,e[11]=h,e[12]=b):b=e[12],b};function yI(t){return t.isActive?{...t,isActive:!1}:t}function vI(t){return{isActive:!0,cycle:t.cycle+1}}function wI(t){return t.isActive?{...t,isActive:!1}:t}const qh=o.createContext(void 0),jI=t=>{const e=st.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:l}=bI();let u;e[0]!==l||e[1]!==i?(u={triggerFireworks:i,dismissFireworks:l},e[0]=l,e[1]=i,e[2]=u):u=e[2];const d=u;let f;e[3]!==a||e[4]!==r?(f=s.jsx(gI,{isActive:r,burstKey:a}),e[3]=a,e[4]=r,e[5]=f):f=e[5];let m;return e[6]!==n||e[7]!==f||e[8]!==d?(m=s.jsxs(qh.Provider,{value:d,children:[n,f]}),e[6]=n,e[7]=f,e[8]=d,e[9]=m):m=e[9],m},FD=()=>{const t=o.useContext(qh);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},NI=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`},Hn=t=>{const e=st.c(8),{label:n,value:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=a):a=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let u;return e[5]!==i||e[6]!==l?(u=s.jsxs("div",{className:"rounded-md p-2",style:a,children:[i,l]}),e[5]=i,e[6]=l,e[7]=u):u=e[7],u},Ep=t=>{const e=st.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=ct();let l;if(e[0]!==a||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const u=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(CI,0),e[8]=r.entries,e[9]=d):d=e[9];const f=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 c;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(c=r.startedAt?NI(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=c):c=e[15];let p;e[16]!==c?(p=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:c}),e[16]=c,e[17]=p):p=e[17];let g;e[18]!==m||e[19]!==p?(g=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,p]}),e[18]=m,e[19]=p,e[20]=g):g=e[20];let h;e[21]!==i?(h=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=h):h=e[22];let x;e[23]!==r.entries.length||e[24]!==h?(x=s.jsx(Hn,{label:h,value:r.entries.length}),e[23]=r.entries.length,e[24]=h,e[25]=x):x=e[25];let w;e[26]!==i?(w=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=w):w=e[27];let b;e[28]!==w||e[29]!==f?(b=s.jsx(Hn,{label:w,value:f}),e[28]=w,e[29]=f,e[30]=b):b=e[30];let y;e[31]!==i?(y=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=y):y=e[32];let v;e[33]!==r.lastUpdatedAt||e[34]!==i?(v=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=v):v=e[35];let S;e[36]!==y||e[37]!==v?(S=s.jsx(Hn,{label:y,value:v}),e[36]=y,e[37]=v,e[38]=S):S=e[38];let I;e[39]!==b||e[40]!==S||e[41]!==x?(I=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[x,b,S]}),e[39]=b,e[40]=S,e[41]=x,e[42]=I):I=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[g,I,u.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:a}):s.jsx(ts,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:u.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=a,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=l}else l=e[7];return l},SI=t=>{const e=st.c(101),{onClose:n}=t,{t:r}=ct(),[a,i]=o.useState("memory"),[l,u]=o.useState("idle"),d=Ft(PI),f=kf(II),m=ml(),c=uf(DI),p=Ea(TI),[g,h]=o.useState(AI),[x,w]=o.useState(EI);let b;e[0]!==g.entries?(b=new Map,g.entries.forEach(Se=>{b.set(Se.metric,Se.count)}),e[0]=g.entries,e[1]=b):b=e[1];let y;e[2]!==b?(y=b.get("ui.message_list.render")??0,e[2]=b,e[3]=y):y=e[3];let v;e[4]!==b?(v=b.get("ui.message_list.render.streaming")??0,e[4]=b,e[5]=v):v=e[5];let S;e[6]!==b?(S=b.get("ui.chat_message.render")??0,e[6]=b,e[7]=S):S=e[7];let I;e[8]!==b?(I=b.get("ui.chat_message.render.streaming")??0,e[8]=b,e[9]=I):I=e[9];let j;e[10]!==b?(j=b.get("ui.chat_message.render.static_during_stream")??0,e[10]=b,e[11]=j):j=e[11];let N;e[12]!==b?(N=b.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=b,e[13]=N):N=e[13];let P;e[14]!==y||e[15]!==v||e[16]!==S||e[17]!==I||e[18]!==j||e[19]!==N?(P={messageListRender:y,messageListRenderStreaming:v,chatMessageRender:S,chatMessageRenderStreaming:I,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:N},e[14]=y,e[15]=v,e[16]=S,e[17]=I,e[18]=j,e[19]=N,e[20]=P):P=e[20];const M=P;let T,E;e[21]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const Se=()=>{h(ko()),w(Co())};Se();const je=window.setInterval(Se,500);return()=>window.clearInterval(je)},E=[],e[21]=T,e[22]=E):(T=e[21],E=e[22]),o.useEffect(T,E);let k,C;e[23]!==l?(k=()=>{if(l==="idle")return;const Se=window.setTimeout(()=>{u("idle")},1500);return()=>window.clearTimeout(Se)},C=[l],e[23]=l,e[24]=k,e[25]=C):(k=e[24],C=e[25]),o.useEffect(k,C);let A=0,F;if(e[26]!==c?(F=Object.keys(c),e[26]=c,e[27]=F):F=e[27],e[28]!==c||e[29]!==F||e[30]!==A){for(const Se of F)A=A+(c[Se]?.length??0);e[28]=c,e[29]=F,e[30]=A,e[31]=A}else A=e[31];const _=A;let O;if(e[32]!==d||e[33]!==c||e[34]!==f||e[35]!==m||e[36]!==r){let Se;e[38]!==d||e[39]!==c||e[40]!==f||e[41]!==r?(Se=je=>{const Ie=c[je.id]?.length||0,Oe=f.get(je.id);return{id:je.id,title:je.title||r("memoryDebugPanel.common.untitled"),messageCount:Ie,isStreaming:Oe?.isStreaming||!1,isZombie:Oe?.isZombie||!1,backgroundCount:Oe?.backgroundMessageCount||0,lastAccessed:Oe?.lastAccessedAt||0,isCurrent:je.id===d}},e[38]=d,e[39]=c,e[40]=f,e[41]=r,e[42]=Se):Se=e[42],O=m.map(Se).sort(MI),e[32]=d,e[33]=c,e[34]=f,e[35]=m,e[36]=r,e[37]=O}else O=e[37];const V=O;let K;e[43]!==c?(K=Object.keys(c),e[43]=c,e[44]=K):K=e[44];const $=K.length;let oe;e[45]===Symbol.for("react.memo_cache_sentinel")?(oe=async()=>{try{const Se={generatedAt:new Date().toISOString(),ui:ko(),vscode:Co()};await navigator.clipboard.writeText(JSON.stringify(Se,null,2)),u("copied")}catch{u("error")}},e[45]=oe):oe=e[45];const L=oe;let Y;e[46]===Symbol.for("react.memo_cache_sentinel")?(Y={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=Y):Y=e[46];let ee;e[47]!==a?(ee=a==="memory"?s.jsx(D,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(D,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=ee):ee=e[48];let re;e[49]!==r?(re=r("memoryDebugPanel.title"),e[49]=r,e[50]=re):re=e[50];let fe;e[51]!==re?(fe=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:re}),e[51]=re,e[52]=fe):fe=e[52];let ge;e[53]!==ee||e[54]!==fe?(ge=s.jsxs("div",{className:"flex items-center gap-2",children:[ee,fe]}),e[53]=ee,e[54]=fe,e[55]=ge):ge=e[55];let be;e[56]!==a?(be=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ve,{size:"xs",variant:"ghost",onClick:L,children:s.jsx(D,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:()=>{ey(),h(ko()),w(Co())},children:s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=be):be=e[57];let z;e[58]!==n?(z=n?s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(D,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=z):z=e[59];let B;e[60]!==be||e[61]!==z?(B=s.jsxs("div",{className:"flex items-center gap-1",children:[be,z]}),e[60]=be,e[61]=z,e[62]=B):B=e[62];let Q;e[63]!==ge||e[64]!==B?(Q=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[ge,B]}),e[63]=ge,e[64]=B,e[65]=Q):Q=e[65];let X;e[66]===Symbol.for("react.memo_cache_sentinel")?(X={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=X):X=e[66];const ie=a==="memory"?"secondary":"ghost";let le;e[67]===Symbol.for("react.memo_cache_sentinel")?(le=()=>i("memory"),e[67]=le):le=e[67];let ye;e[68]!==r?(ye=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=ye):ye=e[69];let W;e[70]!==ie||e[71]!==ye?(W=s.jsx(ve,{size:"sm",variant:ie,className:"flex-1",onClick:le,children:ye}),e[70]=ie,e[71]=ye,e[72]=W):W=e[72];const ue=a==="streaming"?"secondary":"ghost";let ae;e[73]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>i("streaming"),e[73]=ae):ae=e[73];let U;e[74]!==r?(U=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=U):U=e[75];let G;e[76]!==ue||e[77]!==U?(G=s.jsx(ve,{size:"sm",variant:ue,className:"flex-1",onClick:ae,children:U}),e[76]=ue,e[77]=U,e[78]=G):G=e[78];let ne;e[79]!==W||e[80]!==G?(ne=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:X,children:[W,G]}),e[79]=W,e[80]=G,e[81]=ne):ne=e[81];let se;e[82]!==a||e[83]!==$||e[84]!==l||e[85]!==d||e[86]!==c||e[87]!==f||e[88]!==V||e[89]!==m||e[90]!==M||e[91]!==g||e[92]!==r||e[93]!==p||e[94]!==_||e[95]!==x?(se=a==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(Hn,{label:r("memoryDebugPanel.metric.totalMessages"),value:_}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${$} / ${du.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:Zb()})})]}),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:du.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:p})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(ts,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(Se=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Se.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Se.title}),Se.isStreaming?s.jsx(D,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Se.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Se.messageCount})}),Se.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Se.backgroundCount]}):null]})]},Se.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(ve,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(RI),currentSessionId:d,cachedSessions:Object.keys(c),memoryStates:Object.fromEntries(f)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Rt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ve,{size:"xs",variant:"outline",onClick:L,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(Hn,{label:r("memoryDebugPanel.metric.uiMetrics"),value:g.entries.length}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:x.entries.length}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.messageListRenders"),value:M.messageListRender}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:M.messageListRenderStreaming}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:M.chatMessageRender}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:M.chatMessageRenderStreaming}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:M.chatMessageRenderStaticDuringStream}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:M.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Ep,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:g,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),x.entries.length>0?s.jsx(Ep,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=$,e[84]=l,e[85]=d,e[86]=c,e[87]=f,e[88]=V,e[89]=m,e[90]=M,e[91]=g,e[92]=r,e[93]=p,e[94]=_,e[95]=x,e[96]=se):se=e[96];let xe;return e[97]!==Q||e[98]!==ne||e[99]!==se?(xe=s.jsxs(Pf,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:Y,children:[Q,ne,se]}),e[97]=Q,e[98]=ne,e[99]=se,e[100]=xe):xe=e[100],xe},kI=SI;function CI(t,e){return t+e.count}function PI(t){return t.currentSessionId}function II(t){return t.sessionMemoryState}function DI(t){return t.message}function TI(t){return t.totalRequestCount}function AI(){return ko()}function EI(){return Co()}function MI(t,e){return e.lastAccessed-t.lastAccessed}function RI(t){return{id:t.id,title:t.title}}const FI=()=>{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()??"":""},LI=async()=>{const t=FI()||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")},Mp="vinci:menu-action",OI=t=>{const e=Ft(g=>g.openNewSessionDraft),n=De(g=>g.toggleCommandPalette),r=De(g=>g.setCommandPaletteOpen),a=De(g=>g.toggleHelpDialog),i=De(g=>g.toggleSidebar),l=De(g=>g.setSessionSwitcherOpen),u=De(g=>g.setActiveMainTab),d=De(g=>g.setSettingsDialogOpen),f=De(g=>g.setAboutDialogOpen),{setThemeMode:m}=rr(),c=o.useCallback(()=>{gr.requestDirectoryDialog()},[]),p=o.useCallback(g=>{switch(g){case"about":f(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":u("chat"),l(!1),e();break;case"new-worktree-session":u("chat"),l(!1),xf();break;case"change-workspace":c();break;case"open-git-tab":{const{activeMainTab:h}=De.getState();u(h==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:h}=De.getState();u(h==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:h}=De.getState();u(h==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:h}=De.getState();u(h==="terminal"?"chat":"terminal");break}case"copy":{const h=new Event("vinci:copy",{cancelable:!0});!window.dispatchEvent(h)||LI();break}case"theme-light":m("light");break;case"theme-dark":m("dark");break;case"theme-system":m("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"help-dialog":a();break;case"download-logs":{ty().catch(()=>{te.error("Failed to collect OpenCode status")});break}case"check-for-updates":{tr.getState().checkForUpdates(),tr.getState().setUpdateDialogOpen(!0);break}}},[c,t,e,f,u,l,r,d,m,n,a,i]);o.useEffect(()=>{const g=h=>{const x=h.detail;x&&p(x)};return window.addEventListener(Mp,g),()=>{window.removeEventListener(Mp,g)}},[p]),o.useEffect(()=>{const g=()=>{tr.getState().checkForUpdates(),tr.getState().setUpdateDialogOpen(!0)};return window.addEventListener("app:check-for-updates",g),()=>{window.removeEventListener("app:check-for-updates",g)}},[]),o.useEffect(()=>{if(typeof window>"u")return;const h=window.__TAURI__?.event?.listen;if(typeof h!="function")return;let x=null;return h("vinci:menu-action",w=>{const b=w?.payload;typeof b=="string"&&p(b)}).then(w=>{x=w}).catch(()=>{}),()=>{(async()=>{try{const b=x?.();b instanceof Promise&&await b}catch{}})()}},[p])},$I=["chat","git","diff","terminal","files"],_I=["settings","agents","commands","skills","providers","usage","git-identities"],sr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Rp(t){const e=zI();return{sessionId:BI(e),tab:VI(e),settingsPath:UI(e),diffFile:KI(e)}}function zI(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function BI(t){const e=t.get(sr.SESSION);return!e||e.trim().length===0?null:e.trim()}function VI(t){const e=t.get(sr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return $I.includes(n)?n:null}function UI(t){const e=t.get(sr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="vinci"||n==="general"||n==="preferences"?"home":(_I.includes(n),n)}function KI(t){const e=t.get(sr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Fp(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(sr.SESSION)||t.has(sr.TAB)||t.has(sr.SETTINGS)||t.has(sr.FILE)}catch{return!1}}const WI="chat";function Yh(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(sr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(sr.SETTINGS,n),e}return t.tab!==WI&&e.set(sr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(sr.FILE,t.diffFile),e}function HI(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function GI(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Yh(t),r=[...e.entries()].sort((i,l)=>i[0].localeCompare(l[0])),a=[...n.entries()].sort((i,l)=>i[0].localeCompare(l[0]));if(r.length!==a.length)return!1;for(let i=0;i<r.length;i++)if(r[i][0]!==a[i][0]||r[i][1]!==a[i][1])return!1;return!0}catch{return!0}}function qI(t,e={}){if(!(typeof window>"u")&&!YI()&&!(!e.force&&GI(t)))try{const n=Yh(t),r=HI(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function YI(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function QI(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function JI(){const t=o.useMemo(()=>QI(),[]),e=o.useRef(!1),n=o.useRef(!1),r=Ft(c=>c.setCurrentSession),a=De(c=>c.setActiveMainTab),i=De(c=>c.setSettingsDialogOpen),l=De(c=>c.setSettingsPage),u=De(c=>c.navigateToDiff),d=o.useCallback(async c=>{if(!n.current){n.current=!0;try{if(c.sessionId){const p=Ft.getState().currentSessionId;c.sessionId!==p&&await r(c.sessionId)}if(c.settingsPath){l(mh(c.settingsPath)),i(!0);return}De.getState().isSettingsDialogOpen&&i(!1),c.tab&&a(c.tab),c.diffFile&&(c.tab==="diff"||!c.tab)&&u(c.diffFile)}finally{n.current=!1}}},[r,a,i,l,u]),f=o.useCallback(()=>{const c=Ft.getState(),p=De.getState();return{sessionId:c.currentSessionId,tab:p.activeMainTab,isSettingsOpen:p.isSettingsDialogOpen,settingsPath:p.settingsPage,diffFile:p.pendingDiffFile}},[]),m=o.useCallback((c={})=>{if(t||n.current)return;const p=f();qI(p,c)},[t,f]);o.useEffect(()=>{if(e.current||(e.current=!0,!Fp()))return;const c=Rp();(async()=>(await d(c),t||m({replace:!0})))()},[d,t,m]),o.useEffect(()=>{if(t)return;let c=Ft.getState().currentSessionId;return Ft.subscribe(g=>{const h=g.currentSessionId;h===c||n.current||(c=h,m())})},[t,m]),o.useEffect(()=>{if(t)return;let c=De.getState().activeMainTab,p=De.getState().isSettingsDialogOpen,g=De.getState().settingsPage,h=De.getState().pendingDiffFile;return De.subscribe(w=>{if(n.current)return;const b=w.activeMainTab!==c,y=w.isSettingsDialogOpen!==p,v=w.settingsPage!==g,S=w.pendingDiffFile!==h&&w.activeMainTab==="diff";c=w.activeMainTab,p=w.isSettingsDialogOpen,g=w.settingsPage,h=w.pendingDiffFile,(b||y||v||S)&&m()})},[t,m]),o.useEffect(()=>{if(typeof window>"u"||t)return;const c=()=>{const p=Rp();if(Fp())d(p);else{const g=De.getState();g.isSettingsDialogOpen&&i(!1),g.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",c),()=>{window.removeEventListener("popstate",c)}},[d,t,a,i])}const Lp="pwa-install-toast-shown",XI=()=>{const t=st.c(6),{browserTab:e}=kh(),{t:n}=ct(),r=o.useRef(n);let a,i;t[0]!==n?(a=()=>{r.current=n},i=[n],t[0]=n,t[1]=a,t[2]=i):(a=t[1],i=t[2]),o.useEffect(a,i);let l,u;t[3]!==e?(l=()=>{if(typeof window>"u"||!oa()||!e)return;let d=null,f=null;const m=()=>{f!==null&&(te.dismiss(f),f=null)},c=async()=>{if(!d)return;const h=d;d=null,m(),await h.prompt();const{outcome:x}=await h.userChoice;x==="accepted"&&te.success(r.current("pwa.installPrompt.started"))},p=h=>{const x=h;if(typeof x.prompt!="function")return;x.preventDefault(),d=x;const w=Yp();w.getItem(Lp)!=="true"&&f===null&&(w.setItem(Lp,"true"),f=te.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{c()}}}))},g=()=>{d=null,m(),te.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",p),window.addEventListener("appinstalled",g),()=>{m(),window.removeEventListener("beforeinstallprompt",p),window.removeEventListener("appinstalled",g)}},u=[e],t[3]=e,t[4]=l,t[5]=u):(l=t[4],u=t[5]),o.useEffect(l,u)},ZI=["local","remote",null],eD=["ok","not-configured","unreachable","wrong-service","missing"];function Qh(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!ZI.includes(n)))return{valid:!1};if(typeof r!="string"||!eD.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 Op(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 tD(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function sD(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function $p(){if(Yc()!=="valid")return null;const e=window.__APP_DESKTOP_BOOT_OUTCOME__,n=Qh(e);return n.valid?n.outcome:null}function Yc(){if(typeof window>"u")return"not-injected";const t=window.__APP_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Qh(t).valid?"valid":"malformed"}const nD=()=>{const t=st.c(5),[e,n]=o.useState(rD),{isUpdating:r,message:a}=e;let i,l;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>ny(n),l=[],t[0]=i,t[1]=l):(i=t[0],l=t[1]),o.useEffect(i,l),!r)return null;let u;t[2]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(rd,{width:80,height:80}),t[2]=u):u=t[2];let d;return t[3]!==a?(d=s.jsxs("div",{className:"fixed inset-0 z-[9999] flex flex-col items-center justify-center gap-6 bg-background/90",children:[u,s.jsx("p",{className:"typography-body text-muted-foreground",children:a})]}),t[3]=a,t[4]=d):d=t[4],d};function rD(){return sy()}const aD=({open:t,onOpenChange:e})=>{const{t:n}=ct(),[r,a]=o.useState(null),[i,l]=o.useState(null),[u,d]=o.useState(!1),[f,m]=o.useState(!1),[c,p]=o.useState(null),[g,h]=o.useState(!1),x=o.useCallback(async()=>{if(!u){d(!0),m(!1);try{if(!c){te.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const b=await uu.copyTextToClipboard(c);b.ok?(m(!0),te.success(n("aboutDialog.toast.diagnosticsCopied"))):te.error(n("aboutDialog.toast.copyFailed"),{description:b.error})}catch(b){te.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",b)}finally{d(!1)}}},[c,u,n]);o.useEffect(()=>{if(!t)return;(async()=>{try{const y=await fetch("/api/system/info");if(y.ok){const v=await y.json();if(typeof v.vinciVersion=="string"&&v.vinciVersion.trim()){a(v.vinciVersion);return}}}catch{}a(await ry())})()},[t]),o.useEffect(()=>{if(!t)return;let b=!1;return(async()=>{try{const v=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!v.ok)return;const S=await v.json().catch(()=>null),I=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!b&&I&&l(I)}catch{}})(),()=>{b=!0}},[t]),o.useEffect(()=>{if(!t){p(null),h(!1);return}let b=!1;return h(!0),uu.buildDiagnosticsReport().then(y=>{b||p(y)}).catch(y=>{b||(console.error("Failed to prepare diagnostics:",y),p(null))}).finally(()=>{b||h(!1)}),()=>{b=!0}},[t]);const w=r;return s.jsx(ls,{open:t,onOpenChange:e,children:s.jsx(os,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(rd,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Vinci"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[w&&s.jsx("p",{children:n("aboutDialog.vinciVersionLabel",{version:w})}),i&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:i})})]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:x,disabled:u||g||!c,className:de("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(f?"aboutDialog.actions.diagnosticsCopied":g?"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/jaygupta17/vinci",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(D,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/eSSmgeX8Q",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(D,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/guptajay17",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(D,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@guptajay17"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},iD=t=>{const e=st.c(83),{open:n,onOpenChange:r}=t,{t:a}=ct(),{checking:i,available:l,downloading:u,downloaded:d,info:f,progress:m,error:c,checkForUpdates:p,downloadUpdate:g,restartToUpdate:h}=tr();let x;e[0]!==p?(x=()=>{p()},e[0]=p,e[1]=x):x=e[1];const w=x;let b;e[2]!==g?(b=()=>{g()},e[2]=g,e[3]=b):b=e[3];const y=b;let v;e[4]!==h?(v=()=>{h()},e[4]=h,e[5]=v):v=e[5];const S=v;let I,j;e[6]!==p||e[7]!==i||e[8]!==f||e[9]!==n?(I=()=>{n&&f===null&&!i&&p()},j=[n,f,i,p],e[6]=p,e[7]=i,e[8]=f,e[9]=n,e[10]=I,e[11]=j):(I=e[10],j=e[11]),o.useEffect(I,j);const N=oD;let P;e[12]!==l||e[13]!==d||e[14]!==u?(P=d||u?s.jsx(D,{name:"sparkling",className:"h-5 w-5 text-primary"}):l?s.jsx(D,{name:"download",className:"h-5 w-5 text-primary"}):s.jsx(D,{name:"information",className:"h-5 w-5 text-muted-foreground"}),e[12]=l,e[13]=d,e[14]=u,e[15]=P):P=e[15];let M;e[16]!==d||e[17]!==u||e[18]!==a?(M=a(u||d?"updateDialog.header.updating":"updateDialog.header.updateAvailable"),e[16]=d,e[17]=u,e[18]=a,e[19]=M):M=e[19];let T;e[20]!==M?(T=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:M}),e[20]=M,e[21]=T):T=e[21];let E;e[22]!==P||e[23]!==T?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[P,T]}),e[22]=P,e[23]=T,e[24]=E):E=e[24];let k;e[25]!==r?(k=()=>r(!1),e[25]=r,e[26]=k):k=e[26];let C;e[27]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(D,{name:"close",className:"h-4 w-4"}),e[27]=C):C=e[27];let A;e[28]!==k?(A=s.jsx("button",{type:"button",onClick:k,className:"h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50",children:C}),e[28]=k,e[29]=A):A=e[29];let F;e[30]!==A||e[31]!==E?(F=s.jsx("div",{className:"p-5 pb-3",children:s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[E,A]})}),e[30]=A,e[31]=E,e[32]=F):F=e[32];let _;e[33]!==i||e[34]!==a?(_=i&&s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(D,{name:"loader",className:"h-4 w-4 animate-spin"}),a("updateDialog.status.downloading")]}),e[33]=i,e[34]=a,e[35]=_):_=e[35];let O;e[36]!==i||e[37]!==d||e[38]!==u||e[39]!==c||e[40]!==f||e[41]!==m||e[42]!==a?(O=!i&&f&&s.jsxs("div",{className:"space-y-3",children:[f.currentVersion&&f.version&&s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:f.currentVersion}),f.available&&s.jsx(D,{name:"arrow-right",className:"h-3.5 w-3.5"}),f.available&&s.jsx("span",{className:"font-medium text-foreground",children:f.version}),!f.available&&s.jsx("span",{className:"text-muted-foreground/60",children:a("sessions.sidebar.updateCheck.latestVersion")})]}),c&&s.jsx("div",{className:"typography-meta p-2 rounded-lg border",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderColor:"var(--status-error-border)"},children:c}),f.body&&f.available&&!u&&!d&&s.jsx("div",{className:"max-h-40 overflow-y-auto typography-meta text-muted-foreground/80 border border-border/30 rounded-lg p-3",children:s.jsx(Ua,{content:f.body,variant:"tool"})}),u&&m&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between typography-micro text-muted-foreground",children:[s.jsx("span",{children:a("updateDialog.status.downloading")}),s.jsxs("span",{children:[N(m.downloaded),m.total?` / ${N(m.total)}`:""]})]}),s.jsx("div",{className:"h-1.5 rounded-full bg-muted/50 overflow-hidden",children:s.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-300",style:{width:m.total?`${Math.min(100,m.downloaded/m.total*100)}%`:"30%"}})})]}),d&&s.jsx("div",{className:"typography-meta text-muted-foreground/80",children:a("updateDialog.status.installingUpdate")})]}),e[36]=i,e[37]=d,e[38]=u,e[39]=c,e[40]=f,e[41]=m,e[42]=a,e[43]=O):O=e[43];let V;e[44]!==c||e[45]!==w||e[46]!==a?(V=c&&s.jsxs("button",{type:"button",onClick:w,className:"flex-1 inline-flex items-center justify-center gap-1.5 h-8 rounded-lg typography-meta font-medium bg-muted/30 hover:bg-muted/50 text-foreground border border-border/30",children:[s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"}),a("updateDialog.actions.updateNow")]}),e[44]=c,e[45]=w,e[46]=a,e[47]=V):V=e[47];let K;e[48]!==i||e[49]!==d||e[50]!==u||e[51]!==c||e[52]!==y||e[53]!==f?.available||e[54]!==a?(K=!i&&f?.available&&!u&&!d&&!c&&s.jsxs("button",{type:"button",onClick:y,className:"flex-1 inline-flex items-center justify-center gap-1.5 h-8 rounded-lg typography-meta font-medium bg-primary text-primary-foreground hover:opacity-90",children:[s.jsx(D,{name:"download",className:"h-3.5 w-3.5"}),a("updateDialog.actions.downloadUpdate")]}),e[48]=i,e[49]=d,e[50]=u,e[51]=c,e[52]=y,e[53]=f?.available,e[54]=a,e[55]=K):K=e[55];let $;e[56]!==d||e[57]!==c||e[58]!==S||e[59]!==a?($=d&&!c&&s.jsxs("button",{type:"button",onClick:S,className:"flex-1 inline-flex items-center justify-center gap-1.5 h-8 rounded-lg typography-meta font-medium bg-primary text-primary-foreground hover:opacity-90",children:[s.jsx(D,{name:"restart",className:"h-3.5 w-3.5"}),a("updateDialog.actions.restartToUpdate")]}),e[56]=d,e[57]=c,e[58]=S,e[59]=a,e[60]=$):$=e[60];let oe;e[61]!==i||e[62]!==c||e[63]!==w||e[64]!==f?.available||e[65]!==a?(oe=!i&&!f?.available&&!c&&s.jsxs("button",{type:"button",onClick:w,className:"flex-1 inline-flex items-center justify-center gap-1.5 h-8 rounded-lg typography-meta font-medium bg-muted/30 hover:bg-muted/50 text-foreground border border-border/30",children:[s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"}),a("updateDialog.actions.updateNow")]}),e[61]=i,e[62]=c,e[63]=w,e[64]=f?.available,e[65]=a,e[66]=oe):oe=e[66];let L;e[67]!==V||e[68]!==K||e[69]!==$||e[70]!==oe?(L=s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[V,K,$,oe]}),e[67]=V,e[68]=K,e[69]=$,e[70]=oe,e[71]=L):L=e[71];let Y;e[72]!==_||e[73]!==O||e[74]!==L?(Y=s.jsxs("div",{className:"px-5 pb-4 space-y-3",children:[_,O,L]}),e[72]=_,e[73]=O,e[74]=L,e[75]=Y):Y=e[75];let ee;e[76]!==F||e[77]!==Y?(ee=s.jsxs(os,{className:"max-w-md p-0 overflow-hidden",children:[F,Y]}),e[76]=F,e[77]=Y,e[78]=ee):ee=e[78];let re;return e[79]!==r||e[80]!==n||e[81]!==ee?(re=s.jsx(ls,{open:n,onOpenChange:r,children:ee}),e[79]=r,e[80]=n,e[81]=ee,e[82]=re):re=e[82],re};function oD(t){if(t===void 0||t===0)return"";const e=t/1048576;return e>=1?`${e.toFixed(1)} MB`:`${(t/1024).toFixed(0)} KB`}const gc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},lD=(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 Vinci and click Authorize again.":n},cD=()=>{const t=qs(i=>i.completeAuth),[e,n]=o.useState("working"),[r,a]=o.useState("Completing MCP authorization...");return o.useEffect(()=>{if(typeof window>"u"){n("error"),a("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),l=gc(i,"code"),u=xh(i),d=gd(i),f=gc(i,"error"),m=gc(i,"error_description");if(f){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(m??f);return}(async()=>{try{if(!l)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");let c=u;if(!c&&d){const p=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(p.ok){const g=await p.json().catch(()=>null);g?.name?.trim()&&(c={name:g.name.trim(),directory:typeof g.directory=="string"&&g.directory.trim()?g.directory.trim():null})}}if(!c?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");await t(c.name,l,c.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),a("Authorization completed. You can close this tab and return to Vinci.")}catch(c){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(lD(c,"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 Vinci"})})]})})},vo="opencode-update-available",wo="opencode-upgrade-progress",dD=5e3,uD=[1e4,6e4],Jh=()=>{const{t}=ct(),e=De(l=>l.showOpenCodeUpdateNotifications),n=Le.useRef(new Set),r=Le.useRef(!1);Le.useEffect(()=>{e||te.dismiss(vo)},[e]);const a=Le.useCallback(()=>{te.dismiss(wo),ia({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=Le.useCallback(async()=>{if(!r.current){r.current=!0,te.dismiss(vo),te.message(t("opencodeUpdate.toast.upgrading.title"),{id:wo,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(D,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const l=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),u=await l.json().catch(()=>null);if(!l.ok||u?.success===!1)throw new Error(u?.error||l.statusText||t("opencodeUpdate.toast.failed.description"));te.success(t("opencodeUpdate.toast.updated.title"),{id:wo,description:u?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:u.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(D,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:a}})}catch(l){te.error(t("opencodeUpdate.toast.failed.title"),{id:wo,description:l instanceof Error?l.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[a,t]);return Le.useEffect(()=>{const l=c=>{if(!De.getState().showOpenCodeUpdateNotifications){te.dismiss(vo);return}c&&(n.current.has(c)||(n.current.add(c),te.info(t("opencodeUpdate.toast.available.title"),{id:vo,description:t("opencodeUpdate.toast.available.description",{version:c}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i}})))},u=c=>{const p=typeof c.detail?.version=="string"?String(c.detail.version).trim():"";l(p)};let d=!1;const f=[],m=async c=>{try{const p=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!p.ok)throw new Error(p.statusText||"OpenCode upgrade status check failed");const g=await p.json().catch(()=>null),h=typeof g?.latestVersion=="string"?g.latestVersion.trim():"";!d&&g?.available===!0&&h&&l(h)}catch{const p=uD[c];!d&&p!==void 0&&f.push(setTimeout(()=>{m(c+1)},p))}};return e&&f.push(setTimeout(()=>{m(0)},dD)),window.addEventListener("vinci:opencode-update-available",u),()=>{d=!0;for(const c of f)clearTimeout(c);window.removeEventListener("vinci:opencode-update-available",u)}},[i,e,t]),null},_p=Mr(()=>Qn(()=>import("./OnboardingScreen-ClzfZpkc.js"),__vite__mapDeps([11,0,1,3,4,5])).then(t=>({default:t.OnboardingScreen}))),mD=()=>{const t=st.c(3),e=De(yD),n=De(vD);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(aD,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},pD=()=>{const t=st.c(3),e=tr(wD),n=tr(jD);let r;return t[0]!==n||t[1]!==e?(r=s.jsx(iD,{open:e,onOpenChange:n}),t[0]=n,t[1]=e,t[2]=r):r=t[2],r},fD=t=>{const e=st.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=ct();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let l;e[2]!==i?(l=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=l):l=e[3];let u;e[4]!==a?(u=a("startup.initRecovery.description"),e[4]=a,e[5]=u):u=e[5];let d;e[6]!==u?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:u}),e[6]=u,e[7]=d):d=e[7];let f;e[8]!==l||e[9]!==d?(f=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,d]}),e[8]=l,e[9]=d,e[10]=f):f=e[10];let m;e[11]!==r||e[12]!==a?(m=a(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=a,e[13]=m):m=e[13];let c;e[14]!==r||e[15]!==n||e[16]!==m?(c=s.jsx(ve,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=c):c=e[17];let p;return e[18]!==f||e[19]!==c?(p=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:[f,c]})}),e[18]=f,e[19]=c,e[20]=p):p=e[20],p},zp=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",hD=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),a=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:a,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},gD=()=>typeof window>"u"?!1:window.location.pathname===gh,xD=t=>{const e=st.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:a}=t,i=Ns(ND),l=Ft(SD),u=Ft(kD),d=ld(),f=o.useRef(null);let m;e[0]!==n.directory?(m=zp(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const c=m;let p;e[2]!==i?(p=zp(i),e[2]=i,e[3]=p):p=e[3];const g=p;let h,x;if(e[4]!==g||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==c||e[9]!==r||e[10]!==u||e[11]!==d?(h=()=>{if(r||c&&g!==c)return;const I=`${c}
178
+ `)?(k(Ye),T(!0)):T(!1);return}T(!1)},[]),H=o.useCallback(Me=>{if(C&&$.current&&(Me.key==="Enter"||Me.key==="ArrowUp"||Me.key==="ArrowDown"||Me.key==="Escape"||Me.key==="Tab")){Me.preventDefault(),$.current.handleKeyDown(Me.key);return}M&&K.current&&(Me.key==="Enter"||Me.key==="ArrowUp"||Me.key==="ArrowDown"||Me.key==="Escape"||Me.key==="Tab")&&(Me.preventDefault(),K.current.handleKeyDown(Me.key))},[C,M]),Ee=o.useCallback(Me=>{const We=V.current?.selectionStart??u.length,Ve=u.substring(0,We).lastIndexOf("@"),Ye=Me.relativePath&&Me.relativePath.trim().length>0?Me.relativePath.trim():Me.path||Me.name,Ge=Ve!==-1?Ve:We,me=`${u.substring(0,Ge)}@${Ye} ${u.substring(We)}`,Ke=Ge+Ye.length+2;d(me),T(!1),k(""),requestAnimationFrame(()=>{const ze=V.current;ze&&(ze.selectionStart=Ke,ze.selectionEnd=Ke,ze.focus()),J(me,Ke)})},[u,J]),Ae=o.useCallback(Me=>{const We=V.current?.selectionStart??u.length,Ve=u.substring(0,We).lastIndexOf("@"),Ye=Ve!==-1?Ve:We,Ge=`${u.substring(0,Ye)}@${Me} ${u.substring(We)}`,me=Ye+Me.length+2;d(Ge),T(!1),k(""),requestAnimationFrame(()=>{const Ke=V.current;Ke&&(Ke.selectionStart=me,Ke.selectionEnd=me,Ke.focus()),J(Ge,me)})},[u,J]),Je=o.useCallback(Me=>{const He=`/${Me.name} `;d(He),A(!1),_(""),requestAnimationFrame(()=>{const We=V.current;We&&(We.focus(),We.selectionStart=We.value.length,We.selectionEnd=We.value.length),J(He,He.length)})},[J]),ce=async Me=>{if(Me.preventDefault(),!!u.trim()&&!(f.length<2)){w(!0),q();try{ge&&ge!==ee&&re(ge);const He=f.map(({instanceId:Ge,...me})=>me),We=g.map(Ge=>({mime:Ge.mimeType,filename:Ge.filename,url:Ge.dataUrl})),Te=b.filter(Ge=>Ge.trim().length>0),Ve={name:i.trim(),prompt:u.trim(),models:He,agent:c||void 0,worktreeBaseBranch:he?xe:void 0,isolateRuns:he,files:We.length>0?We:void 0,setupCommands:Te.length>0?Te:void 0},Ye=await Fe(Ve);Ye&&(Ye.firstSessionId&&Ft.getState().setCurrentSession(Ye.firstSessionId),e?.())}finally{w(!1)}}},_e=!!(i.trim()&&u.trim()&&f.length>=2&&B&&!je&&(Ie===!1||!he||xe)),et=b.filter(Me=>Me.trim()).length;return s.jsxs("form",{onSubmit:ce,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:se,className:de("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",G,ne),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:a("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":a("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(D,{name:"close",className:"h-5 w-5"})})}),s.jsx(Rt,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Nf,{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(Na,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),fe.length>0?s.jsxs(Qt,{value:ge??void 0,onValueChange:Q,children:[s.jsx(Jt,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:z?s.jsx(as,{children:ie(z)}):s.jsx(as,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(Xt,{fitContent:!0,children:fe.map(Me=>s.jsx(Ct,{value:Me.id,className:"max-w-[24rem]",children:ie(Me)},Me.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:a("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Na,{htmlFor:"group-name",required:!0,info:s.jsx(bo,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(jt,{id:"group-name",value:i,onChange:Me=>l(Me.target.value),placeholder:a("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Na,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(bo,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(qP,{directory:B,value:xe,onChange:Se,disabled:!he,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(ss,{checked:N,onChange:P,disabled:!Ne,ariaLabel:a("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:a("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Na,{htmlFor:"multirun-agent",info:s.jsx(bo,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(Wb,{value:c,onChange:p,id:"multirun-agent"})]})]}),s.jsxs(br,{open:v,onOpenChange:S,children:[s.jsxs(yr,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(D,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:a("multirun.launcher.setupCommands.label")}),et>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:et}),s.jsx(D,{name:"arrow-down-s",className:de("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",v&&"rotate-180")})]}),s.jsx(vr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:I?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[b.map((Me,He)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(jt,{value:Me,onChange:We=>{const Te=[...b];Te[He]=We.target.value,y(Te)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const We=b.filter((Te,Ve)=>Ve!==He);y(We)},className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":a("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]},`${Me}-${He}`)),s.jsxs("button",{type:"button",onClick:()=>y([...b,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(D,{name:"add",className:"h-3 w-3"}),a("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Na,{htmlFor:"prompt",required:!0,children:a("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(nn,{id:"prompt",ref:V,value:u,onChange:Me=>{const He=Me.target.value;d(He);const We=Me.target.selectionStart??He.length;J(He,We)},onKeyDown:H,placeholder:a("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),C?s.jsx(wf,{ref:$,searchQuery:F,onCommandSelect:Je,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,M?s.jsx(jf,{ref:K,searchQuery:E,onFileSelect:Ee,onAgentSelect:Ae,onClose:()=>T(!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:O,type:"file",multiple:!0,className:"hidden",onChange:pe,accept:"*/*"}),s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>O.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(D,{name:"attachment-2",className:"h-3 w-3"}),a("multirun.launcher.attachments.attach")]})}),s.jsx(Rt,{children:a("multirun.launcher.attachments.tooltip")})]}),g.map(Me=>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:[Me.mimeType.startsWith("image/")?s.jsx(D,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(D,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Me.filename,children:Me.filename}),s.jsx("button",{type:"button",onClick:()=>R(Me.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(D,{name:"close",className:"h-3 w-3"})})]},Me.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Na,{required:!0,info:s.jsx(bo,{children:a("multirun.launcher.models.info",{max:hc})}),children:a("multirun.launcher.models.label")}),s.jsx(Hb,{selectedModels:f,onAdd:Pe,onRemove:$e,onUpdate:Ce,minModels:2,maxModels:hc})]}),Be&&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:Be})]})})}),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:[!he&&Ie!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(D,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:a("multirun.launcher.project.gitRequired")})]}):null,s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(ve,{type:"submit",size:"sm",disabled:!_e||x,children:x?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithModelCount",{count:f.length})})})]})})]})},JP=()=>typeof window>"u"?0:window.visualViewport?.height??window.innerHeight,XP=()=>{const t=st.c(2),[e,n]=o.useState(ZP),r=o.useRef(null);let a,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{if(typeof window>"u"||!window.visualViewport)return;const l=()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null;const d=window.visualViewport.height,f=Math.max(0,window.innerHeight-d);n(m=>m.height===d&&m.keyboardHeight===f?m:{height:d,keyboardHeight:f})}))};return window.visualViewport.addEventListener("resize",l),window.visualViewport.addEventListener("scroll",l,{passive:!0}),l(),()=>{r.current!==null&&cancelAnimationFrame(r.current),window.visualViewport?.removeEventListener("resize",l),window.visualViewport?.removeEventListener("scroll",l)}},i=[],t[0]=a,t[1]=i):(a=t[0],i=t[1]),o.useEffect(a,i),e};function ZP(){return{height:JP(),keyboardHeight:0}}class eI extends o.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(Pf,{className:"w-full max-w-md",children:[s.jsx(qb,{className:"text-center",children:s.jsxs(Yb,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(D,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Qb,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(ve,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(D,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function tI(t){const e=st.c(22),{t:n}=ct();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let a;e[2]!==n?(a=n("chat.errorBoundary.description"),e[2]=n,e[3]=a):a=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let l;e[6]!==n?(l=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=l):l=e[7];let u;e[8]!==n?(u=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=u):u=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let f;e[12]!==r||e[13]!==a||e[14]!==i||e[15]!==l||e[16]!==u||e[17]!==d?(f={title:r,description:a,sessionLabel:i,detailsSummary:l,resetAction:u,persistentHint:d},e[12]=r,e[13]=a,e[14]=i,e[15]=l,e[16]=u,e[17]=d,e[18]=f):f=e[18];let m;return e[19]!==t||e[20]!==f?(m=s.jsx(eI,{...t,texts:f}),e[19]=t,e[20]=f,e[21]=m):m=e[21],m}const qc=t=>{const e=st.c(5),{readOnly:n}=t,r=n===void 0?!1:n,i=Ft(sI)||void 0;let l;e[0]!==r?(l=s.jsx(Jb,{readOnly:r}),e[0]=r,e[1]=l):l=e[1];let u;return e[2]!==i||e[3]!==l?(u=s.jsx(tI,{sessionId:i,children:l}),e[2]=i,e[3]=l,e[4]=u):u=e[4],u};function sI(t){return t.currentSessionId}const nI=Mr(()=>Qn(()=>Promise.resolve().then(()=>Fj),void 0).then(t=>({default:t.PlanView}))),Tp=Mr(()=>Qn(()=>import("./GitView-CIXtUiY4.js"),__vite__mapDeps([6,0,1,3,4,5,7])).then(t=>({default:t.GitView}))),rI=Mr(()=>Qn(()=>Promise.resolve().then(()=>tj),void 0).then(t=>({default:t.DiffView}))),Ap=Mr(()=>Qn(()=>import("./TerminalView-JImTzVKx.js"),__vite__mapDeps([8,0,1,3,4,5,7])).then(t=>({default:t.TerminalView}))),aI=Mr(()=>Qn(()=>Promise.resolve().then(()=>Dj),void 0).then(t=>({default:t.FilesView}))),iI=Mr(()=>Qn(()=>Promise.resolve().then(()=>_3),void 0).then(t=>({default:t.SettingsView}))),oI=Mr(()=>Qn(()=>import("./SettingsWindow-mltact69.js"),__vite__mapDeps([9,0,1,3,4,5,7])).then(t=>({default:t.SettingsWindow}))),lI=Mr(()=>Qn(()=>import("./MultiRunWindow-Cx2CTWGK.js"),__vite__mapDeps([10,0,1,3,4,5,7])).then(t=>({default:t.MultiRunWindow}))),yo=85,cI=250,dI=500,uI=200,mI=860,pI=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},fI=()=>{const{t}=ct(),e=1140,n=1220,r=640,a=700,i=De(B=>B.isSidebarOpen),l=De(B=>B.isRightSidebarOpen),u=De(B=>B.isBottomTerminalOpen),d=De(B=>B.setRightSidebarOpen),f=De(B=>B.setBottomTerminalOpen),m=De(B=>B.activeMainTab),c=De(B=>B.setIsMobile),p=De(B=>B.isSessionSwitcherOpen),g=De(B=>B.isSettingsDialogOpen),h=De(B=>B.setSettingsDialogOpen),x=De(B=>B.isMultiRunLauncherOpen),w=De(B=>B.setMultiRunLauncherOpen),b=De(B=>B.multiRunLauncherPrefillPrompt),{isMobile:y,isTablet:v}=_s(),S=XP(),I=o.useMemo(()=>Us(),[]),j=De(B=>B.sidebarWidth),N=De(B=>B.rightSidebarWidth),[P,M]=o.useState(null),T=jr()??"",E=o.useMemo(()=>pI(T),[T]),k=De(B=>{if(!E)return!1;const Q=B.contextPanelByDirectory[E],X=Q?.tabs??[],ie=X.find(le=>le.id===Q?.activeTabId)??X[X.length-1];return!!(Q?.isOpen&&ie)}),C=De(B=>B.setSidebarOpen),A=De(B=>B.openContextOverview),F=De(B=>B.openContextPanelTab),_=o.useRef(!1),O=o.useRef(!1),V=o.useRef(!1),[K,$]=o.useState(!1),oe=o.useRef(!1),L=$d(0),Y=Le.useRef(0),ee=$d(0),re=Le.useRef(0);Le.useEffect(()=>{y&&(Y.current=window.innerWidth*(yo/100),re.current=window.innerWidth*(yo/100))},[y]),Le.useEffect(()=>{if(!y)return;const B=K?0:-Y.current;_d(L,B,{type:"spring",stiffness:400,damping:35,mass:.8})},[K,y,L]),Le.useEffect(()=>{if(!y)return;oe.current=l;const B=l?0:re.current;_d(ee,B,{type:"spring",stiffness:400,damping:35,mass:.8})},[y,l,ee]),Le.useEffect(()=>{y&&$(p)},[p,y]),Le.useEffect(()=>{!y||!g||($(!1),p&&De.getState().setSessionSwitcherOpen(!1),l&&d(!1))},[y,g,p,l,d]),Le.useEffect(()=>{y&&(oe.current=l)},[l,y]),o.useEffect(()=>{De.getState().isMobile!==y&&c(y)},[y,c]),o.useEffect(()=>{if(typeof window>"u")return;let B;const Q=()=>{B!==void 0&&window.clearTimeout(B),B=window.setTimeout(()=>{De.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",Q),()=>{window.removeEventListener("resize",Q),B!==void 0&&window.clearTimeout(B)}},[]),o.useEffect(()=>{if(k){De.getState().isSidebarOpen&&(C(!1),V.current=!0);return}V.current&&(C(!0),V.current=!1)},[k,C]),o.useEffect(()=>{if(!T)return;const B=De.getState(),Q=T.replace(/\\/g,"/").replace(/\/+$/,"");if(!B.contextPanelByDirectory[Q]?.isOpen){F(T,{mode:"design"}),F(T,{mode:"templates"});const ie=Q+"/output";F(T,{mode:"file",targetPath:ie}),A(T)}},[T,A,F]),o.useEffect(()=>{if(!T)return;let B=!1,Q=zo.getState().changeCounter;const X=zo.subscribe(ie=>{if(ie.changeCounter===Q)return;Q=ie.changeCounter;const{lastFileChange:le}=ie;if(!le||B)return;const ye=T.replace(/\\/g,"/").replace(/\/+$/,""),W=le.file.replace(/\\/g,"/").replace(/\/+$/,"");if(!W.startsWith(ye))return;const ue=De.getState(),ae=ue.contextPanelByDirectory[ye];if(le.event==="add")ue.openContextFile(ye,W);else if(le.event==="change")ae?.tabs.some(G=>G.mode==="file"&&G.targetPath===W)&&(ue.setPendingFileFocusPath(null),setTimeout(()=>{B||ue.openContextFile(ye,W)},50));else if(le.event==="unlink"){const U=ae?.tabs.find(G=>G.mode==="file"&&G.targetPath===W);U&&ue.closeContextPanelTab(ye,U.id)}});return()=>{B=!0,X()}},[T]),o.useEffect(()=>{if(typeof window>"u")return;let B;const Q=()=>{const ie=De.getState(),le=window.innerWidth,ye=window.innerHeight;if(!y&&!v){const W=le<e,ue=le>=n;W?ie.isRightSidebarOpen&&(d(!1),_.current=!0):ue&&_.current&&(d(!0),_.current=!1);const ae=ye<r,U=ye>=a;ae?ie.isBottomTerminalOpen&&(f(!1),O.current=!0):U&&O.current&&(f(!0),O.current=!1)}},X=()=>{B!==void 0&&window.clearTimeout(B),B=window.setTimeout(()=>{Q()},100)};return Q(),window.addEventListener("resize",X),()=>{window.removeEventListener("resize",X),B!==void 0&&window.clearTimeout(B)}},[y,v,f,d]),o.useEffect(()=>{if(typeof window>"u")return;const B=De.subscribe((Q,X)=>{const ie=window.innerWidth,le=window.innerHeight,ye=ie>=n,W=le>=a;Q.isRightSidebarOpen!==X.isRightSidebarOpen&&ye&&(_.current=!1),Q.isBottomTerminalOpen!==X.isBottomTerminalOpen&&W&&(O.current=!1)});return()=>{B()}},[y,v,f,d]);const fe=o.useMemo(()=>{switch(m){case"plan":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(nI,{})});case"git":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Tp,{})});case"diff":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(rI,{})});case"terminal":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Ap,{})});case"files":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(aI,{})});default:return null}},[m]),ge=m==="chat",be=o.useMemo(()=>Math.min(dI,Math.max(cI,j||kc)),[j]),z=o.useMemo(()=>Math.min(mI,Math.max(uI,N||Kf)),[N]);return s.jsx(jw,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:de("main-content-safe-area",y?"flex flex-col":"flex h-[100dvh]","bg-background"),style:y&&S.height>0?{height:S.height}:void 0,children:[s.jsx(z3,{}),s.jsx(P5,{}),s.jsx(A5,{}),s.jsx(_P,{}),y?s.jsxs(Xb,{value:{leftDrawerOpen:K,rightDrawerOpen:l,toggleLeftDrawer:()=>{l&&d(!1),$(!K)},toggleRightDrawer:()=>{K&&$(!1),d(!l)},leftDrawerX:L,rightDrawerX:ee,leftDrawerWidth:Y,rightDrawerWidth:re,setMobileLeftDrawerOpen:$,setRightSidebarOpen:d},children:[!g&&s.jsx(Iu,{onToggleLeftDrawer:()=>{l&&d(!1),$(!K)},onToggleRightDrawer:()=>{K&&$(!1),d(!l)},leftDrawerOpen:K,rightDrawerOpen:l}),s.jsx(Tl.button,{type:"button",initial:!1,animate:{opacity:K||l?1:0,pointerEvents:K||l?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{$(!1),d(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Tl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(Y.current||window.innerWidth*.85),right:0},style:{width:`${yo}%`,x:L},onDragEnd:(B,Q)=>{const X=Y.current||window.innerWidth*.85,ie=X*.3,le=500,ye=L.get(),W=Q.offset.x<-ie||Q.velocity.x<-le,ue=Q.offset.x>ie||Q.velocity.x>le;W?(L.set(-X),$(!1)):ue?(L.set(0),$(!0)):ye>-X/2?L.set(0):L.set(-X)},className:de("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":!K,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(As,{children:s.jsx(kp,{mobileVariant:!0})})})})}),s.jsx(Tl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:re.current||window.innerWidth*.85},style:{width:`${yo}%`,x:ee},onDragEnd:(B,Q)=>{const X=re.current||window.innerWidth*.85,ie=X*.3,le=500,ye=ee.get(),W=Q.offset.x>ie||Q.velocity.x>le,ue=Q.offset.x<-ie||Q.velocity.x<-le;W?(ee.set(X),d(!1)):ue?(ee.set(0),d(!0)):ye<X/2?ee.set(0):ee.set(X)},className:de("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":!l,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(As,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Tp,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:de("flex flex-1 overflow-hidden relative",g&&"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:de("absolute inset-0",!ge&&"invisible"),children:s.jsx(As,{children:s.jsx(qc,{})})}),fe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(As,{children:fe})}),x&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(As,{children:s.jsx(QP,{initialPrompt:b,onCreated:()=>w(!1),onCancel:()=>w(!1)})})})]})}),g&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(As,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(iI,{onClose:()=>h(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:de("absolute inset-0 flex overflow-hidden","bg-sidebar"),"data-page-scroll-lock":"true",children:[i?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:de("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${be}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:de("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${be}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,l?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:de("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${z}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:de("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${z}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(qv,{isOpen:i,isMobile:y,className:"border-0",children:s.jsx(kp,{})}),s.jsxs("div",{className:de("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",l&&"border-r border-border/50 rounded-tr-[10px] rounded-br-[10px]"),"data-page-scroll-lock":"true",children:[s.jsx(Iu,{desktopRightSidebarActionsHost:P}),s.jsx("div",{className:de("flex flex-1 min-h-0 overflow-hidden",l?"":"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:de("absolute inset-0",!ge&&"invisible"),children:s.jsx(As,{children:s.jsx(qc,{})})}),fe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(As,{children:fe})})]}),s.jsx(sN,{})]})}),s.jsx(Uv,{isOpen:u,isMobile:y,children:u?s.jsx(As,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Ap,{})})}):null})]}),s.jsx(Yv,{isOpen:l,className:"border-0",onTopActionsHostChange:M,children:s.jsx(As,{children:s.jsx(Y1,{})})})]})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(oI,{open:g,onOpenChange:h})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(lI,{open:x,onOpenChange:w,initialPrompt:b})})]})]})})},Gh=12,hI=[{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"}],gI=t=>{const e=st.c(18),{isActive:n,burstKey:r,className:a,durationMs:i,bursts:l,onComplete:u}=t,d=r===void 0?0:r,f=i===void 0?900:i,m=l===void 0?hI:l,c=Le.useRef(!1);let p,g;e[0]!==n||e[1]!==u?(p=()=>{!n&&c.current&&u?.(),n&&(c.current=!0)},g=[n,u],e[0]=n,e[1]=u,e[2]=p,e[3]=g):(p=e[2],g=e[3]),Le.useEffect(p,g);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=Array.from({length:Gh},xI),e[4]=h):h=e[4];const x=h;if(!n)return null;let w;e[5]!==a?(w=de("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=w):w=e[6];let b;if(e[7]!==d||e[8]!==m||e[9]!==f){let v;e[11]!==d||e[12]!==f?(v=S=>{const I={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${f}ms`};return s.jsx("div",{className:"firework-burst",style:I,children:x.map((j,N)=>{const P=j.x*S.radius,M=j.y*S.radius,T={"--translate-x":`${P}px`,"--translate-y":`${M}px`,"--particle-delay":`${j.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:T},`${S.id}-${N}-${d}`)})},`${S.id}-${d}`)},e[11]=d,e[12]=f,e[13]=v):v=e[13],b=m.map(v),e[7]=d,e[8]=m,e[9]=f,e[10]=b}else b=e[10];let y;return e[14]!==d||e[15]!==w||e[16]!==b?(y=s.jsx("div",{className:w,"aria-hidden":"true","data-burst-key":d,children:b}),e[14]=d,e[15]=w,e[16]=b,e[17]=y):y=e[17],y};function xI(t,e){const n=Math.PI*2*e/Gh;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const bI=t=>{const e=st.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,a=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[l,u]=Le.useState(i),d=Le.useRef(null);let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=f):f=e[3];const m=f;let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{m(),u(yI)},e[4]=c):c=e[4];const p=c;let g;e[5]!==a?(g=()=>{m(),u(vI),d.current=window.setTimeout(()=>{u(wI),d.current=null},a)},e[5]=a,e[6]=g):g=e[6];const h=g;let x,w;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=()=>()=>m(),w=[m],e[7]=x,e[8]=w):(x=e[7],w=e[8]),Le.useEffect(x,w);let b;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==h?(b={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:h,dismissFireworks:p},e[9]=l.cycle,e[10]=l.isActive,e[11]=h,e[12]=b):b=e[12],b};function yI(t){return t.isActive?{...t,isActive:!1}:t}function vI(t){return{isActive:!0,cycle:t.cycle+1}}function wI(t){return t.isActive?{...t,isActive:!1}:t}const qh=o.createContext(void 0),jI=t=>{const e=st.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:l}=bI();let u;e[0]!==l||e[1]!==i?(u={triggerFireworks:i,dismissFireworks:l},e[0]=l,e[1]=i,e[2]=u):u=e[2];const d=u;let f;e[3]!==a||e[4]!==r?(f=s.jsx(gI,{isActive:r,burstKey:a}),e[3]=a,e[4]=r,e[5]=f):f=e[5];let m;return e[6]!==n||e[7]!==f||e[8]!==d?(m=s.jsxs(qh.Provider,{value:d,children:[n,f]}),e[6]=n,e[7]=f,e[8]=d,e[9]=m):m=e[9],m},FD=()=>{const t=o.useContext(qh);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},NI=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`},Hn=t=>{const e=st.c(8),{label:n,value:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=a):a=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let u;return e[5]!==i||e[6]!==l?(u=s.jsxs("div",{className:"rounded-md p-2",style:a,children:[i,l]}),e[5]=i,e[6]=l,e[7]=u):u=e[7],u},Ep=t=>{const e=st.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=ct();let l;if(e[0]!==a||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const u=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(CI,0),e[8]=r.entries,e[9]=d):d=e[9];const f=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 c;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(c=r.startedAt?NI(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=c):c=e[15];let p;e[16]!==c?(p=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:c}),e[16]=c,e[17]=p):p=e[17];let g;e[18]!==m||e[19]!==p?(g=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,p]}),e[18]=m,e[19]=p,e[20]=g):g=e[20];let h;e[21]!==i?(h=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=h):h=e[22];let x;e[23]!==r.entries.length||e[24]!==h?(x=s.jsx(Hn,{label:h,value:r.entries.length}),e[23]=r.entries.length,e[24]=h,e[25]=x):x=e[25];let w;e[26]!==i?(w=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=w):w=e[27];let b;e[28]!==w||e[29]!==f?(b=s.jsx(Hn,{label:w,value:f}),e[28]=w,e[29]=f,e[30]=b):b=e[30];let y;e[31]!==i?(y=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=y):y=e[32];let v;e[33]!==r.lastUpdatedAt||e[34]!==i?(v=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=v):v=e[35];let S;e[36]!==y||e[37]!==v?(S=s.jsx(Hn,{label:y,value:v}),e[36]=y,e[37]=v,e[38]=S):S=e[38];let I;e[39]!==b||e[40]!==S||e[41]!==x?(I=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[x,b,S]}),e[39]=b,e[40]=S,e[41]=x,e[42]=I):I=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[g,I,u.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:a}):s.jsx(ts,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:u.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=a,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=l}else l=e[7];return l},SI=t=>{const e=st.c(101),{onClose:n}=t,{t:r}=ct(),[a,i]=o.useState("memory"),[l,u]=o.useState("idle"),d=Ft(PI),f=kf(II),m=ml(),c=uf(DI),p=Ea(TI),[g,h]=o.useState(AI),[x,w]=o.useState(EI);let b;e[0]!==g.entries?(b=new Map,g.entries.forEach(Se=>{b.set(Se.metric,Se.count)}),e[0]=g.entries,e[1]=b):b=e[1];let y;e[2]!==b?(y=b.get("ui.message_list.render")??0,e[2]=b,e[3]=y):y=e[3];let v;e[4]!==b?(v=b.get("ui.message_list.render.streaming")??0,e[4]=b,e[5]=v):v=e[5];let S;e[6]!==b?(S=b.get("ui.chat_message.render")??0,e[6]=b,e[7]=S):S=e[7];let I;e[8]!==b?(I=b.get("ui.chat_message.render.streaming")??0,e[8]=b,e[9]=I):I=e[9];let j;e[10]!==b?(j=b.get("ui.chat_message.render.static_during_stream")??0,e[10]=b,e[11]=j):j=e[11];let N;e[12]!==b?(N=b.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=b,e[13]=N):N=e[13];let P;e[14]!==y||e[15]!==v||e[16]!==S||e[17]!==I||e[18]!==j||e[19]!==N?(P={messageListRender:y,messageListRenderStreaming:v,chatMessageRender:S,chatMessageRenderStreaming:I,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:N},e[14]=y,e[15]=v,e[16]=S,e[17]=I,e[18]=j,e[19]=N,e[20]=P):P=e[20];const M=P;let T,E;e[21]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const Se=()=>{h(ko()),w(Co())};Se();const je=window.setInterval(Se,500);return()=>window.clearInterval(je)},E=[],e[21]=T,e[22]=E):(T=e[21],E=e[22]),o.useEffect(T,E);let k,C;e[23]!==l?(k=()=>{if(l==="idle")return;const Se=window.setTimeout(()=>{u("idle")},1500);return()=>window.clearTimeout(Se)},C=[l],e[23]=l,e[24]=k,e[25]=C):(k=e[24],C=e[25]),o.useEffect(k,C);let A=0,F;if(e[26]!==c?(F=Object.keys(c),e[26]=c,e[27]=F):F=e[27],e[28]!==c||e[29]!==F||e[30]!==A){for(const Se of F)A=A+(c[Se]?.length??0);e[28]=c,e[29]=F,e[30]=A,e[31]=A}else A=e[31];const _=A;let O;if(e[32]!==d||e[33]!==c||e[34]!==f||e[35]!==m||e[36]!==r){let Se;e[38]!==d||e[39]!==c||e[40]!==f||e[41]!==r?(Se=je=>{const Ie=c[je.id]?.length||0,Oe=f.get(je.id);return{id:je.id,title:je.title||r("memoryDebugPanel.common.untitled"),messageCount:Ie,isStreaming:Oe?.isStreaming||!1,isZombie:Oe?.isZombie||!1,backgroundCount:Oe?.backgroundMessageCount||0,lastAccessed:Oe?.lastAccessedAt||0,isCurrent:je.id===d}},e[38]=d,e[39]=c,e[40]=f,e[41]=r,e[42]=Se):Se=e[42],O=m.map(Se).sort(MI),e[32]=d,e[33]=c,e[34]=f,e[35]=m,e[36]=r,e[37]=O}else O=e[37];const V=O;let K;e[43]!==c?(K=Object.keys(c),e[43]=c,e[44]=K):K=e[44];const $=K.length;let oe;e[45]===Symbol.for("react.memo_cache_sentinel")?(oe=async()=>{try{const Se={generatedAt:new Date().toISOString(),ui:ko(),vscode:Co()};await navigator.clipboard.writeText(JSON.stringify(Se,null,2)),u("copied")}catch{u("error")}},e[45]=oe):oe=e[45];const L=oe;let Y;e[46]===Symbol.for("react.memo_cache_sentinel")?(Y={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=Y):Y=e[46];let ee;e[47]!==a?(ee=a==="memory"?s.jsx(D,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(D,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=ee):ee=e[48];let re;e[49]!==r?(re=r("memoryDebugPanel.title"),e[49]=r,e[50]=re):re=e[50];let fe;e[51]!==re?(fe=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:re}),e[51]=re,e[52]=fe):fe=e[52];let ge;e[53]!==ee||e[54]!==fe?(ge=s.jsxs("div",{className:"flex items-center gap-2",children:[ee,fe]}),e[53]=ee,e[54]=fe,e[55]=ge):ge=e[55];let be;e[56]!==a?(be=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ve,{size:"xs",variant:"ghost",onClick:L,children:s.jsx(D,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:()=>{ey(),h(ko()),w(Co())},children:s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=be):be=e[57];let z;e[58]!==n?(z=n?s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(D,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=z):z=e[59];let B;e[60]!==be||e[61]!==z?(B=s.jsxs("div",{className:"flex items-center gap-1",children:[be,z]}),e[60]=be,e[61]=z,e[62]=B):B=e[62];let Q;e[63]!==ge||e[64]!==B?(Q=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[ge,B]}),e[63]=ge,e[64]=B,e[65]=Q):Q=e[65];let X;e[66]===Symbol.for("react.memo_cache_sentinel")?(X={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=X):X=e[66];const ie=a==="memory"?"secondary":"ghost";let le;e[67]===Symbol.for("react.memo_cache_sentinel")?(le=()=>i("memory"),e[67]=le):le=e[67];let ye;e[68]!==r?(ye=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=ye):ye=e[69];let W;e[70]!==ie||e[71]!==ye?(W=s.jsx(ve,{size:"sm",variant:ie,className:"flex-1",onClick:le,children:ye}),e[70]=ie,e[71]=ye,e[72]=W):W=e[72];const ue=a==="streaming"?"secondary":"ghost";let ae;e[73]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>i("streaming"),e[73]=ae):ae=e[73];let U;e[74]!==r?(U=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=U):U=e[75];let G;e[76]!==ue||e[77]!==U?(G=s.jsx(ve,{size:"sm",variant:ue,className:"flex-1",onClick:ae,children:U}),e[76]=ue,e[77]=U,e[78]=G):G=e[78];let ne;e[79]!==W||e[80]!==G?(ne=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:X,children:[W,G]}),e[79]=W,e[80]=G,e[81]=ne):ne=e[81];let se;e[82]!==a||e[83]!==$||e[84]!==l||e[85]!==d||e[86]!==c||e[87]!==f||e[88]!==V||e[89]!==m||e[90]!==M||e[91]!==g||e[92]!==r||e[93]!==p||e[94]!==_||e[95]!==x?(se=a==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(Hn,{label:r("memoryDebugPanel.metric.totalMessages"),value:_}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${$} / ${du.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:Zb()})})]}),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:du.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:p})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(ts,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(Se=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Se.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Se.title}),Se.isStreaming?s.jsx(D,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Se.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Se.messageCount})}),Se.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Se.backgroundCount]}):null]})]},Se.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Tt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(ve,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(RI),currentSessionId:d,cachedSessions:Object.keys(c),memoryStates:Object.fromEntries(f)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Rt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ve,{size:"xs",variant:"outline",onClick:L,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(Hn,{label:r("memoryDebugPanel.metric.uiMetrics"),value:g.entries.length}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:x.entries.length}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.messageListRenders"),value:M.messageListRender}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:M.messageListRenderStreaming}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:M.chatMessageRender}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:M.chatMessageRenderStreaming}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:M.chatMessageRenderStaticDuringStream}),s.jsx(Hn,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:M.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Ep,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:g,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),x.entries.length>0?s.jsx(Ep,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=$,e[84]=l,e[85]=d,e[86]=c,e[87]=f,e[88]=V,e[89]=m,e[90]=M,e[91]=g,e[92]=r,e[93]=p,e[94]=_,e[95]=x,e[96]=se):se=e[96];let xe;return e[97]!==Q||e[98]!==ne||e[99]!==se?(xe=s.jsxs(Pf,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:Y,children:[Q,ne,se]}),e[97]=Q,e[98]=ne,e[99]=se,e[100]=xe):xe=e[100],xe},kI=SI;function CI(t,e){return t+e.count}function PI(t){return t.currentSessionId}function II(t){return t.sessionMemoryState}function DI(t){return t.message}function TI(t){return t.totalRequestCount}function AI(){return ko()}function EI(){return Co()}function MI(t,e){return e.lastAccessed-t.lastAccessed}function RI(t){return{id:t.id,title:t.title}}const FI=()=>{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()??"":""},LI=async()=>{const t=FI()||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")},Mp="vinci:menu-action",OI=t=>{const e=Ft(g=>g.openNewSessionDraft),n=De(g=>g.toggleCommandPalette),r=De(g=>g.setCommandPaletteOpen),a=De(g=>g.toggleHelpDialog),i=De(g=>g.toggleSidebar),l=De(g=>g.setSessionSwitcherOpen),u=De(g=>g.setActiveMainTab),d=De(g=>g.setSettingsDialogOpen),f=De(g=>g.setAboutDialogOpen),{setThemeMode:m}=rr(),c=o.useCallback(()=>{gr.requestDirectoryDialog()},[]),p=o.useCallback(g=>{switch(g){case"about":f(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":u("chat"),l(!1),e();break;case"new-worktree-session":u("chat"),l(!1),xf();break;case"change-workspace":c();break;case"open-git-tab":{const{activeMainTab:h}=De.getState();u(h==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:h}=De.getState();u(h==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:h}=De.getState();u(h==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:h}=De.getState();u(h==="terminal"?"chat":"terminal");break}case"copy":{const h=new Event("vinci:copy",{cancelable:!0});!window.dispatchEvent(h)||LI();break}case"theme-light":m("light");break;case"theme-dark":m("dark");break;case"theme-system":m("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"help-dialog":a();break;case"download-logs":{ty().catch(()=>{te.error("Failed to collect OpenCode status")});break}case"check-for-updates":{tr.getState().checkForUpdates(),tr.getState().setUpdateDialogOpen(!0);break}}},[c,t,e,f,u,l,r,d,m,n,a,i]);o.useEffect(()=>{const g=h=>{const x=h.detail;x&&p(x)};return window.addEventListener(Mp,g),()=>{window.removeEventListener(Mp,g)}},[p]),o.useEffect(()=>{const g=()=>{tr.getState().checkForUpdates(),tr.getState().setUpdateDialogOpen(!0)};return window.addEventListener("app:check-for-updates",g),()=>{window.removeEventListener("app:check-for-updates",g)}},[]),o.useEffect(()=>{if(typeof window>"u")return;const h=window.__TAURI__?.event?.listen;if(typeof h!="function")return;let x=null;return h("vinci:menu-action",w=>{const b=w?.payload;typeof b=="string"&&p(b)}).then(w=>{x=w}).catch(()=>{}),()=>{(async()=>{try{const b=x?.();b instanceof Promise&&await b}catch{}})()}},[p])},$I=["chat","git","diff","terminal","files"],_I=["settings","agents","commands","skills","providers","usage","git-identities"],sr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Rp(t){const e=zI();return{sessionId:BI(e),tab:VI(e),settingsPath:UI(e),diffFile:KI(e)}}function zI(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function BI(t){const e=t.get(sr.SESSION);return!e||e.trim().length===0?null:e.trim()}function VI(t){const e=t.get(sr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return $I.includes(n)?n:null}function UI(t){const e=t.get(sr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="vinci"||n==="general"||n==="preferences"?"home":(_I.includes(n),n)}function KI(t){const e=t.get(sr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Fp(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(sr.SESSION)||t.has(sr.TAB)||t.has(sr.SETTINGS)||t.has(sr.FILE)}catch{return!1}}const WI="chat";function Yh(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(sr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(sr.SETTINGS,n),e}return t.tab!==WI&&e.set(sr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(sr.FILE,t.diffFile),e}function HI(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function GI(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Yh(t),r=[...e.entries()].sort((i,l)=>i[0].localeCompare(l[0])),a=[...n.entries()].sort((i,l)=>i[0].localeCompare(l[0]));if(r.length!==a.length)return!1;for(let i=0;i<r.length;i++)if(r[i][0]!==a[i][0]||r[i][1]!==a[i][1])return!1;return!0}catch{return!0}}function qI(t,e={}){if(!(typeof window>"u")&&!YI()&&!(!e.force&&GI(t)))try{const n=Yh(t),r=HI(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function YI(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function QI(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function JI(){const t=o.useMemo(()=>QI(),[]),e=o.useRef(!1),n=o.useRef(!1),r=Ft(c=>c.setCurrentSession),a=De(c=>c.setActiveMainTab),i=De(c=>c.setSettingsDialogOpen),l=De(c=>c.setSettingsPage),u=De(c=>c.navigateToDiff),d=o.useCallback(async c=>{if(!n.current){n.current=!0;try{if(c.sessionId){const p=Ft.getState().currentSessionId;c.sessionId!==p&&await r(c.sessionId)}if(c.settingsPath){l(mh(c.settingsPath)),i(!0);return}De.getState().isSettingsDialogOpen&&i(!1),c.tab&&a(c.tab),c.diffFile&&(c.tab==="diff"||!c.tab)&&u(c.diffFile)}finally{n.current=!1}}},[r,a,i,l,u]),f=o.useCallback(()=>{const c=Ft.getState(),p=De.getState();return{sessionId:c.currentSessionId,tab:p.activeMainTab,isSettingsOpen:p.isSettingsDialogOpen,settingsPath:p.settingsPage,diffFile:p.pendingDiffFile}},[]),m=o.useCallback((c={})=>{if(t||n.current)return;const p=f();qI(p,c)},[t,f]);o.useEffect(()=>{if(e.current||(e.current=!0,!Fp()))return;const c=Rp();(async()=>(await d(c),t||m({replace:!0})))()},[d,t,m]),o.useEffect(()=>{if(t)return;let c=Ft.getState().currentSessionId;return Ft.subscribe(g=>{const h=g.currentSessionId;h===c||n.current||(c=h,m())})},[t,m]),o.useEffect(()=>{if(t)return;let c=De.getState().activeMainTab,p=De.getState().isSettingsDialogOpen,g=De.getState().settingsPage,h=De.getState().pendingDiffFile;return De.subscribe(w=>{if(n.current)return;const b=w.activeMainTab!==c,y=w.isSettingsDialogOpen!==p,v=w.settingsPage!==g,S=w.pendingDiffFile!==h&&w.activeMainTab==="diff";c=w.activeMainTab,p=w.isSettingsDialogOpen,g=w.settingsPage,h=w.pendingDiffFile,(b||y||v||S)&&m()})},[t,m]),o.useEffect(()=>{if(typeof window>"u"||t)return;const c=()=>{const p=Rp();if(Fp())d(p);else{const g=De.getState();g.isSettingsDialogOpen&&i(!1),g.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",c),()=>{window.removeEventListener("popstate",c)}},[d,t,a,i])}const Lp="pwa-install-toast-shown",XI=()=>{const t=st.c(6),{browserTab:e}=kh(),{t:n}=ct(),r=o.useRef(n);let a,i;t[0]!==n?(a=()=>{r.current=n},i=[n],t[0]=n,t[1]=a,t[2]=i):(a=t[1],i=t[2]),o.useEffect(a,i);let l,u;t[3]!==e?(l=()=>{if(typeof window>"u"||!oa()||!e)return;let d=null,f=null;const m=()=>{f!==null&&(te.dismiss(f),f=null)},c=async()=>{if(!d)return;const h=d;d=null,m(),await h.prompt();const{outcome:x}=await h.userChoice;x==="accepted"&&te.success(r.current("pwa.installPrompt.started"))},p=h=>{const x=h;if(typeof x.prompt!="function")return;x.preventDefault(),d=x;const w=Yp();w.getItem(Lp)!=="true"&&f===null&&(w.setItem(Lp,"true"),f=te.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{c()}}}))},g=()=>{d=null,m(),te.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",p),window.addEventListener("appinstalled",g),()=>{m(),window.removeEventListener("beforeinstallprompt",p),window.removeEventListener("appinstalled",g)}},u=[e],t[3]=e,t[4]=l,t[5]=u):(l=t[4],u=t[5]),o.useEffect(l,u)},ZI=["local","remote",null],eD=["ok","not-configured","unreachable","wrong-service","missing"];function Qh(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!ZI.includes(n)))return{valid:!1};if(typeof r!="string"||!eD.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 Op(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 tD(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function sD(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function $p(){if(Yc()!=="valid")return null;const e=window.__APP_DESKTOP_BOOT_OUTCOME__,n=Qh(e);return n.valid?n.outcome:null}function Yc(){if(typeof window>"u")return"not-injected";const t=window.__APP_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Qh(t).valid?"valid":"malformed"}const nD=()=>{const t=st.c(5),[e,n]=o.useState(rD),{isUpdating:r,message:a}=e;let i,l;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>ny(n),l=[],t[0]=i,t[1]=l):(i=t[0],l=t[1]),o.useEffect(i,l),!r)return null;let u;t[2]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(rd,{width:80,height:80}),t[2]=u):u=t[2];let d;return t[3]!==a?(d=s.jsxs("div",{className:"fixed inset-0 z-[9999] flex flex-col items-center justify-center gap-6 bg-background/90",children:[u,s.jsx("p",{className:"typography-body text-muted-foreground",children:a})]}),t[3]=a,t[4]=d):d=t[4],d};function rD(){return sy()}const aD=({open:t,onOpenChange:e})=>{const{t:n}=ct(),[r,a]=o.useState(null),[i,l]=o.useState(null),[u,d]=o.useState(!1),[f,m]=o.useState(!1),[c,p]=o.useState(null),[g,h]=o.useState(!1),x=o.useCallback(async()=>{if(!u){d(!0),m(!1);try{if(!c){te.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const b=await uu.copyTextToClipboard(c);b.ok?(m(!0),te.success(n("aboutDialog.toast.diagnosticsCopied"))):te.error(n("aboutDialog.toast.copyFailed"),{description:b.error})}catch(b){te.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",b)}finally{d(!1)}}},[c,u,n]);o.useEffect(()=>{if(!t)return;(async()=>{try{const y=await fetch("/api/system/info");if(y.ok){const v=await y.json();if(typeof v.vinciVersion=="string"&&v.vinciVersion.trim()){a(v.vinciVersion);return}}}catch{}a(await ry())})()},[t]),o.useEffect(()=>{if(!t)return;let b=!1;return(async()=>{try{const v=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!v.ok)return;const S=await v.json().catch(()=>null),I=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!b&&I&&l(I)}catch{}})(),()=>{b=!0}},[t]),o.useEffect(()=>{if(!t){p(null),h(!1);return}let b=!1;return h(!0),uu.buildDiagnosticsReport().then(y=>{b||p(y)}).catch(y=>{b||(console.error("Failed to prepare diagnostics:",y),p(null))}).finally(()=>{b||h(!1)}),()=>{b=!0}},[t]);const w=r;return s.jsx(ls,{open:t,onOpenChange:e,children:s.jsx(os,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(rd,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Vinci"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[w&&s.jsx("p",{children:n("aboutDialog.vinciVersionLabel",{version:w})}),i&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:i})})]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:x,disabled:u||g||!c,className:de("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(f?"aboutDialog.actions.diagnosticsCopied":g?"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/jaygupta17/vinci",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(D,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/eSSmgeX8Q",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(D,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/guptajay17",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(D,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@guptajay17"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},iD=t=>{const e=st.c(83),{open:n,onOpenChange:r}=t,{t:a}=ct(),{checking:i,available:l,downloading:u,downloaded:d,info:f,progress:m,error:c,checkForUpdates:p,downloadUpdate:g,restartToUpdate:h}=tr();let x;e[0]!==p?(x=()=>{p()},e[0]=p,e[1]=x):x=e[1];const w=x;let b;e[2]!==g?(b=()=>{g()},e[2]=g,e[3]=b):b=e[3];const y=b;let v;e[4]!==h?(v=()=>{h()},e[4]=h,e[5]=v):v=e[5];const S=v;let I,j;e[6]!==p||e[7]!==i||e[8]!==f||e[9]!==n?(I=()=>{n&&f===null&&!i&&p()},j=[n,f,i,p],e[6]=p,e[7]=i,e[8]=f,e[9]=n,e[10]=I,e[11]=j):(I=e[10],j=e[11]),o.useEffect(I,j);const N=oD;let P;e[12]!==l||e[13]!==d||e[14]!==u?(P=d||u?s.jsx(D,{name:"sparkling",className:"h-5 w-5 text-primary"}):l?s.jsx(D,{name:"download",className:"h-5 w-5 text-primary"}):s.jsx(D,{name:"information",className:"h-5 w-5 text-muted-foreground"}),e[12]=l,e[13]=d,e[14]=u,e[15]=P):P=e[15];let M;e[16]!==d||e[17]!==u||e[18]!==a?(M=a(u||d?"updateDialog.header.updating":"updateDialog.header.updateAvailable"),e[16]=d,e[17]=u,e[18]=a,e[19]=M):M=e[19];let T;e[20]!==M?(T=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:M}),e[20]=M,e[21]=T):T=e[21];let E;e[22]!==P||e[23]!==T?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[P,T]}),e[22]=P,e[23]=T,e[24]=E):E=e[24];let k;e[25]!==r?(k=()=>r(!1),e[25]=r,e[26]=k):k=e[26];let C;e[27]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(D,{name:"close",className:"h-4 w-4"}),e[27]=C):C=e[27];let A;e[28]!==k?(A=s.jsx("button",{type:"button",onClick:k,className:"h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50",children:C}),e[28]=k,e[29]=A):A=e[29];let F;e[30]!==A||e[31]!==E?(F=s.jsx("div",{className:"p-5 pb-3",children:s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[E,A]})}),e[30]=A,e[31]=E,e[32]=F):F=e[32];let _;e[33]!==i||e[34]!==a?(_=i&&s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(D,{name:"loader",className:"h-4 w-4 animate-spin"}),a("updateDialog.status.downloading")]}),e[33]=i,e[34]=a,e[35]=_):_=e[35];let O;e[36]!==i||e[37]!==d||e[38]!==u||e[39]!==c||e[40]!==f||e[41]!==m||e[42]!==a?(O=!i&&f&&s.jsxs("div",{className:"space-y-3",children:[f.currentVersion&&f.version&&s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:f.currentVersion}),f.available&&s.jsx(D,{name:"arrow-right",className:"h-3.5 w-3.5"}),f.available&&s.jsx("span",{className:"font-medium text-foreground",children:f.version}),!f.available&&s.jsx("span",{className:"text-muted-foreground/60",children:a("sessions.sidebar.updateCheck.latestVersion")})]}),c&&s.jsx("div",{className:"typography-meta p-2 rounded-lg border",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderColor:"var(--status-error-border)"},children:c}),f.body&&f.available&&!u&&!d&&s.jsx("div",{className:"max-h-40 overflow-y-auto typography-meta text-muted-foreground/80 border border-border/30 rounded-lg p-3",children:s.jsx(Ua,{content:f.body,variant:"tool"})}),u&&m&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between typography-micro text-muted-foreground",children:[s.jsx("span",{children:a("updateDialog.status.downloading")}),s.jsxs("span",{children:[N(m.downloaded),m.total?` / ${N(m.total)}`:""]})]}),s.jsx("div",{className:"h-1.5 rounded-full bg-muted/50 overflow-hidden",children:s.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-300",style:{width:m.total?`${Math.min(100,m.downloaded/m.total*100)}%`:"30%"}})})]}),d&&s.jsx("div",{className:"typography-meta text-muted-foreground/80",children:a("updateDialog.status.installingUpdate")})]}),e[36]=i,e[37]=d,e[38]=u,e[39]=c,e[40]=f,e[41]=m,e[42]=a,e[43]=O):O=e[43];let V;e[44]!==c||e[45]!==w||e[46]!==a?(V=c&&s.jsxs("button",{type:"button",onClick:w,className:"flex-1 inline-flex items-center justify-center gap-1.5 h-8 rounded-lg typography-meta font-medium bg-muted/30 hover:bg-muted/50 text-foreground border border-border/30",children:[s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"}),a("updateDialog.actions.updateNow")]}),e[44]=c,e[45]=w,e[46]=a,e[47]=V):V=e[47];let K;e[48]!==i||e[49]!==d||e[50]!==u||e[51]!==c||e[52]!==y||e[53]!==f?.available||e[54]!==a?(K=!i&&f?.available&&!u&&!d&&!c&&s.jsxs("button",{type:"button",onClick:y,className:"flex-1 inline-flex items-center justify-center gap-1.5 h-8 rounded-lg typography-meta font-medium bg-primary text-primary-foreground hover:opacity-90",children:[s.jsx(D,{name:"download",className:"h-3.5 w-3.5"}),a("updateDialog.actions.downloadUpdate")]}),e[48]=i,e[49]=d,e[50]=u,e[51]=c,e[52]=y,e[53]=f?.available,e[54]=a,e[55]=K):K=e[55];let $;e[56]!==d||e[57]!==c||e[58]!==S||e[59]!==a?($=d&&!c&&s.jsxs("button",{type:"button",onClick:S,className:"flex-1 inline-flex items-center justify-center gap-1.5 h-8 rounded-lg typography-meta font-medium bg-primary text-primary-foreground hover:opacity-90",children:[s.jsx(D,{name:"restart",className:"h-3.5 w-3.5"}),a("updateDialog.actions.restartToUpdate")]}),e[56]=d,e[57]=c,e[58]=S,e[59]=a,e[60]=$):$=e[60];let oe;e[61]!==i||e[62]!==c||e[63]!==w||e[64]!==f?.available||e[65]!==a?(oe=!i&&!f?.available&&!c&&s.jsxs("button",{type:"button",onClick:w,className:"flex-1 inline-flex items-center justify-center gap-1.5 h-8 rounded-lg typography-meta font-medium bg-muted/30 hover:bg-muted/50 text-foreground border border-border/30",children:[s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"}),a("updateDialog.actions.updateNow")]}),e[61]=i,e[62]=c,e[63]=w,e[64]=f?.available,e[65]=a,e[66]=oe):oe=e[66];let L;e[67]!==V||e[68]!==K||e[69]!==$||e[70]!==oe?(L=s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[V,K,$,oe]}),e[67]=V,e[68]=K,e[69]=$,e[70]=oe,e[71]=L):L=e[71];let Y;e[72]!==_||e[73]!==O||e[74]!==L?(Y=s.jsxs("div",{className:"px-5 pb-4 space-y-3",children:[_,O,L]}),e[72]=_,e[73]=O,e[74]=L,e[75]=Y):Y=e[75];let ee;e[76]!==F||e[77]!==Y?(ee=s.jsxs(os,{className:"max-w-md p-0 overflow-hidden",children:[F,Y]}),e[76]=F,e[77]=Y,e[78]=ee):ee=e[78];let re;return e[79]!==r||e[80]!==n||e[81]!==ee?(re=s.jsx(ls,{open:n,onOpenChange:r,children:ee}),e[79]=r,e[80]=n,e[81]=ee,e[82]=re):re=e[82],re};function oD(t){if(t===void 0||t===0)return"";const e=t/1048576;return e>=1?`${e.toFixed(1)} MB`:`${(t/1024).toFixed(0)} KB`}const gc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},lD=(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 Vinci and click Authorize again.":n},cD=()=>{const t=qs(i=>i.completeAuth),[e,n]=o.useState("working"),[r,a]=o.useState("Completing MCP authorization...");return o.useEffect(()=>{if(typeof window>"u"){n("error"),a("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),l=gc(i,"code"),u=xh(i),d=gd(i),f=gc(i,"error"),m=gc(i,"error_description");if(f){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(m??f);return}(async()=>{try{if(!l)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");let c=u;if(!c&&d){const p=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(p.ok){const g=await p.json().catch(()=>null);g?.name?.trim()&&(c={name:g.name.trim(),directory:typeof g.directory=="string"&&g.directory.trim()?g.directory.trim():null})}}if(!c?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");await t(c.name,l,c.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),a("Authorization completed. You can close this tab and return to Vinci.")}catch(c){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(lD(c,"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 Vinci"})})]})})},vo="opencode-update-available",wo="opencode-upgrade-progress",dD=5e3,uD=[1e4,6e4],Jh=()=>{const{t}=ct(),e=De(l=>l.showOpenCodeUpdateNotifications),n=Le.useRef(new Set),r=Le.useRef(!1);Le.useEffect(()=>{e||te.dismiss(vo)},[e]);const a=Le.useCallback(()=>{te.dismiss(wo),ia({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=Le.useCallback(async()=>{if(!r.current){r.current=!0,te.dismiss(vo),te.message(t("opencodeUpdate.toast.upgrading.title"),{id:wo,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(D,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const l=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),u=await l.json().catch(()=>null);if(!l.ok||u?.success===!1)throw new Error(u?.error||l.statusText||t("opencodeUpdate.toast.failed.description"));te.success(t("opencodeUpdate.toast.updated.title"),{id:wo,description:u?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:u.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(D,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:a}})}catch(l){te.error(t("opencodeUpdate.toast.failed.title"),{id:wo,description:l instanceof Error?l.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[a,t]);return Le.useEffect(()=>{const l=c=>{if(!De.getState().showOpenCodeUpdateNotifications){te.dismiss(vo);return}c&&(n.current.has(c)||(n.current.add(c),te.info(t("opencodeUpdate.toast.available.title"),{id:vo,description:t("opencodeUpdate.toast.available.description",{version:c}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i}})))},u=c=>{const p=typeof c.detail?.version=="string"?String(c.detail.version).trim():"";l(p)};let d=!1;const f=[],m=async c=>{try{const p=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!p.ok)throw new Error(p.statusText||"OpenCode upgrade status check failed");const g=await p.json().catch(()=>null),h=typeof g?.latestVersion=="string"?g.latestVersion.trim():"";!d&&g?.available===!0&&h&&l(h)}catch{const p=uD[c];!d&&p!==void 0&&f.push(setTimeout(()=>{m(c+1)},p))}};return e&&f.push(setTimeout(()=>{m(0)},dD)),window.addEventListener("vinci:opencode-update-available",u),()=>{d=!0;for(const c of f)clearTimeout(c);window.removeEventListener("vinci:opencode-update-available",u)}},[i,e,t]),null},_p=Mr(()=>Qn(()=>import("./OnboardingScreen-C-tioywh.js"),__vite__mapDeps([11,0,1,3,4,5])).then(t=>({default:t.OnboardingScreen}))),mD=()=>{const t=st.c(3),e=De(yD),n=De(vD);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(aD,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},pD=()=>{const t=st.c(3),e=tr(wD),n=tr(jD);let r;return t[0]!==n||t[1]!==e?(r=s.jsx(iD,{open:e,onOpenChange:n}),t[0]=n,t[1]=e,t[2]=r):r=t[2],r},fD=t=>{const e=st.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=ct();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let l;e[2]!==i?(l=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=l):l=e[3];let u;e[4]!==a?(u=a("startup.initRecovery.description"),e[4]=a,e[5]=u):u=e[5];let d;e[6]!==u?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:u}),e[6]=u,e[7]=d):d=e[7];let f;e[8]!==l||e[9]!==d?(f=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,d]}),e[8]=l,e[9]=d,e[10]=f):f=e[10];let m;e[11]!==r||e[12]!==a?(m=a(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=a,e[13]=m):m=e[13];let c;e[14]!==r||e[15]!==n||e[16]!==m?(c=s.jsx(ve,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=c):c=e[17];let p;return e[18]!==f||e[19]!==c?(p=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:[f,c]})}),e[18]=f,e[19]=c,e[20]=p):p=e[20],p},zp=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",hD=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),a=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:a,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},gD=()=>typeof window>"u"?!1:window.location.pathname===gh,xD=t=>{const e=st.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:a}=t,i=Ns(ND),l=Ft(SD),u=Ft(kD),d=ld(),f=o.useRef(null);let m;e[0]!==n.directory?(m=zp(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const c=m;let p;e[2]!==i?(p=zp(i),e[2]=i,e[3]=p):p=e[3];const g=p;let h,x;if(e[4]!==g||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==c||e[9]!==r||e[10]!==u||e[11]!==d?(h=()=>{if(r||c&&g!==c)return;const I=`${c}
179
179
  ${n.sessionId}`;f.current===I&&l===n.sessionId||(f.current=I,u(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},x=[g,l,n.directory,n.sessionId,c,r,u,d],e[4]=g,e[5]=l,e[6]=n.directory,e[7]=n.sessionId,e[8]=c,e[9]=r,e[10]=u,e[11]=d,e[12]=h,e[13]=x):(h=e[12],x=e[13]),o.useEffect(h,x),c&&g!==c)return null;let w;e[14]!==a?(w=s.jsx(If,{embeddedBackgroundWorkEnabled:a}),e[14]=a,e[15]=w):w=e[15];let b;e[16]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(Jh,{}),e[16]=b):b=e[16];let y;e[17]!==n.readOnly?(y=s.jsx(qc,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=y):y=e[18];let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(Df,{}),e[19]=v):v=e[19];let S;return e[20]!==w||e[21]!==y?(S=s.jsxs(s.Fragment,{children:[w,b,y,v]}),e[20]=w,e[21]=y,e[22]=S):S=e[22],S};function bD({apis:t}){console.log("[App] Rendering with apis:",!!t,"keys:",Object.keys(t||{}));const e=ht(z=>z.initializeApp),n=ht(z=>z.isInitialized),r=ht(z=>z.isConnected),a=ht(z=>z.providers.length),i=ht(z=>z.agents.length),l=ht(z=>z.loadProviders),u=ht(z=>z.loadAgents),d=Ft(z=>z.error),f=Ft(z=>z.clearError),m=Ns(z=>z.currentDirectory),c=Ns(z=>z.setDirectory),p=Ns(z=>z.isSwitchingDirectory),[g,h]=o.useState(!1),x=zn(z=>z.refreshStatus),[w,b]=o.useState(()=>t.runtime.isVSCode),[y,v]=o.useState(!0),[S,I]=o.useState(!1),[j,N]=o.useState(0),[P,M]=o.useState(!1),T=De(z=>z.wideChatLayoutEnabled),E=De(z=>z.mobileKeyboardMode),k=o.useMemo(()=>Us(),[]),C=Xc(z=>z.setPlanModeEnabled),[A,F]=o.useState(()=>Yc()),[_,O]=o.useState(()=>{const z=$p();return z!==null?Op({isDesktopShell:!0,bootOutcome:z}):null}),V=o.useRef(!1),K=o.useMemo(()=>hD(),[]),$=!K||y,oe=o.useMemo(()=>gD(),[]);o.useEffect(()=>(mu(g),()=>{mu(!1)}),[g]),o.useEffect(()=>{ay(E)},[E]),o.useEffect(()=>{b(t.runtime.isVSCode)},[t.runtime.isVSCode]),o.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",T),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[T]),o.useEffect(()=>(pu(t),()=>pu(null)),[t]),o.useEffect(()=>{K||x(t.github,{force:!0})},[t.github,K,x]),iy();const L=A==="valid",Y=_?.screen==="main";o.useEffect(()=>{if(!tD({isDesktopShell:k,isInitialized:n,bootOutcomeKnown:L,bootViewIsMain:Y}))return;const z=setTimeout(()=>{const B=document.getElementById("initial-loading");B&&(B.classList.add("fade-out"),setTimeout(()=>{B.remove()},300))},150);return()=>clearTimeout(z)},[k,n,L,Y]),o.useEffect(()=>{if(!k||A!=="malformed")return;const z=document.getElementById("initial-loading");z&&(z.textContent="Desktop startup failed — please restart the app.")},[k,A]),o.useEffect(()=>{if(k)return;const z=setTimeout(()=>{const B=document.getElementById("initial-loading");B&&!n&&(B.classList.add("fade-out"),setTimeout(()=>{B.remove()},300))},5e3);return()=>clearTimeout(z)},[k,n]),o.useEffect(()=>{let z=!1;return(async()=>{const Q=await fetch("/health",{method:"GET"}).catch(()=>null);if(!Q||!Q.ok||z)return;const X=await Q.json().catch(()=>null);if(!X||z)return;const ie=X.planModeExperimentalEnabled;C(ie===!0||ie===1||ie==="1"||ie==="true")})(),()=>{z=!0}},[C]),o.useEffect(()=>{w||e()},[e,w]),o.useEffect(()=>{if(w||n)return;let z=!0,B,Q=0;const X=10,ie=1e3,le=async()=>{if(!z)return;if(Q>=X){I(!0);return}const ye=ht.getState();if(ye.isInitialized){I(!1);return}Q+=1,await ye.initializeApp();const W=ht.getState();if(!z)return;if(W.isInitialized){I(!1);return}if(Q>=X){I(!0);return}const ue=Math.min(ie*Math.pow(2,Q-1),16e3);B=setTimeout(le,ue)};return B=setTimeout(le,ie),()=>{z=!1,B&&clearTimeout(B)}},[j,n,w]),o.useEffect(()=>{n&&I(!1)},[n]),o.useEffect(()=>{if(!S)return;const z=document.getElementById("initial-loading");z&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},[S]),o.useEffect(()=>{if(w||!r||a>0&&i>0)return;let z=!0,B=0;const Q=15,X=async()=>{const le=ht.getState();if(!(le.providers.length>0&&le.agents.length>0))try{le.providers.length===0&&await l(),ht.getState().agents.length===0&&await u()}catch{}};X();const ie=setInterval(()=>{if(z){if(++B>=Q){clearInterval(ie);return}X()}},2e3);return()=>{z=!1,clearInterval(ie)}},[r,w,u,l,a,i]),o.useEffect(()=>{p||w||r&&Bs.setDirectory(m)},[m,p,r,w]),o.useEffect(()=>{if(!K||typeof window>"u")return;const z=X=>{const ie=X?.visible===!0;v(ie)},B=X=>{if(X.origin!==window.location.origin)return;const ie=X.data;ie?.type==="vinci:embedded-visibility"&&z(ie.payload)},Q=window;return Q.__vinciSetEmbeddedVisibility=z,window.addEventListener("message",B),()=>{window.removeEventListener("message",B),Q.__vinciSetEmbeddedVisibility===z&&delete Q.__vinciSetEmbeddedVisibility}},[K]),o.useEffect(()=>{!K?.directory||w||m!==K.directory&&c(K.directory,{showOverlay:!1})},[m,K,w,c]),o.useEffect(()=>{if(!K||typeof window>"u")return;const z=B=>{B.storageArea===window.localStorage&&B.key==="ui-store"&&De.persist.rehydrate()};return window.addEventListener("storage",z),()=>{window.removeEventListener("storage",z)}},[K]),o.useEffect(()=>{if(typeof window>"u")return;const z=B=>{const Q=B.detail,X=typeof Q?.sessionId=="string"?Q.sessionId.trim():"";if(!X)return;const ie=typeof Q?.directory=="string"&&Q.directory.trim().length>0?Q.directory.trim():null;De.getState().setActiveMainTab("chat"),Ft.getState().setCurrentSession(X,ie)};return window.addEventListener("vinci:open-session",z),()=>window.removeEventListener("vinci:open-session",z)},[]),o.useEffect(()=>{if(typeof window>"u")return;const z=B=>{const Q=B.detail,X=typeof Q?.directory=="string"&&Q.directory.trim().length>0?Q.directory.trim():null,ie=typeof Q?.projectId=="string"&&Q.projectId.trim().length>0?Q.projectId.trim():null;De.getState().setActiveMainTab("chat"),De.getState().setSessionSwitcherOpen(!1),Ft.getState().openNewSessionDraft({selectedProjectId:ie,directoryOverride:X,preserveDirectoryOverride:!!X})};return window.addEventListener("vinci:open-draft-session",z),()=>window.removeEventListener("vinci:open-draft-session",z)},[]),o.useEffect(()=>{if(typeof window>"u")return;const z=B=>{const Q=B.detail,X=typeof Q?.projectPath=="string"?Q.projectPath.trim():"";if(!X)return;const ie=es.getState(),le=ie.projects.find(ye=>ye.path===X);le?ie.setActiveProject(le.id):ie.addProject(X)};return window.addEventListener("vinci:open-project",z),()=>window.removeEventListener("vinci:open-project",z)},[]),o.useEffect(()=>{typeof window>"u"||!n||p||V.current||(V.current=!0,window.__vinciAppReady=!0,window.dispatchEvent(new Event("vinci:app-ready")))},[n,p]),oy({enabled:$}),XI(),ly(),JI();const ee=o.useCallback(()=>{h(z=>!z)},[]);OI(ee),o.useEffect(()=>{if(K)return;const z=B=>{Zc(B)&&B.shiftKey&&!B.altKey&&(B.code==="KeyD"||B.key.toLowerCase()==="d")&&(B.preventDefault(),h(X=>!X))};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)},[K]),o.useEffect(()=>{K||d&&setTimeout(()=>f(),5e3)},[f,K,d]),o.useEffect(()=>{if(!k||A!=="not-injected")return;let z=!1,B=0;const Q=200,X=2e3,ie=50,le=()=>{if(z)return;B++;const ye=Yc();if(ye!=="not-injected"){if(z=!0,F(ye),ye==="valid"){const ue=$p();ue&&O(Op({isDesktopShell:!0,bootOutcome:ue}))}return}const W=Math.min(Q*Math.pow(1.1,B),X);if(B>=ie){const ue=document.getElementById("initial-loading");ue&&!ue.textContent?.includes("taking longer")&&(ue.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(le,W)};return window.setTimeout(le,Q),()=>{z=!0}},[k,A]);const re=o.useCallback(async()=>{if(sD({isTauriShell:Ii(),isDesktopLocalOriginActive:Va()})){await hf();return}window.location.reload()},[]),fe=o.useCallback(async()=>{if(!P){I(!1),M(!0);try{await ht.getState().initializeApp()}finally{M(!1)}ht.getState().isInitialized||N(z=>z+1)}},[P]),ge=z=>{if(z.screen==="recovery")return z.variant};if(k&&_&&_.screen!=="main"){if(_.screen==="chooser")return s.jsx(As,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(_p,{mode:"first-launch",onCliAvailable:re,onChooseRemote:()=>{}})})})});const z=ge(_),B=_.screen==="recovery"&&"url"in _?_.url:void 0;return s.jsx(As,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(_p,{mode:"recovery",recoveryVariant:z,recoveryHostUrl:B,recoveryHostLabel:void 0,onCliAvailable:re})})})})}if(K)return s.jsx(As,{children:s.jsx(fu,{sdk:Bs.getSdkClient(),directory:m||"",children:s.jsx(hu,{apis:t,children:s.jsx(gu,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(xD,{embeddedSessionChat:K,isVSCodeRuntime:w,embeddedBackgroundWorkEnabled:$})})})})})});if(oe)return s.jsx(As,{children:s.jsx(cD,{})});if(S&&!n&&!w&&!K)return s.jsx(As,{children:s.jsx(fD,{onRetry:()=>{fe()},isRetrying:P})});const be=!n&&!k;return s.jsx(As,{children:s.jsx(fu,{sdk:Bs.getSdkClient(),directory:m||"",children:s.jsx(hu,{apis:t,children:s.jsx(jI,{children:s.jsx(cy,{children:s.jsx(gu,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:k?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(If,{embeddedBackgroundWorkEnabled:$}),s.jsx(Jh,{}),s.jsx(fI,{}),s.jsx(Df,{}),!be&&s.jsxs(s.Fragment,{children:[s.jsx(nD,{}),s.jsx(mD,{}),s.jsx(pD,{}),g&&s.jsx(kI,{onClose:()=>h(!1)})]})]})})})})})})})}function yD(t){return t.isAboutDialogOpen}function vD(t){return t.setAboutDialogOpen}function wD(t){return t.updateDialogOpen}function jD(t){return t.setUpdateDialogOpen}function ND(t){return t.currentDirectory}function SD(t){return t.currentSessionId}function kD(t){return t.setCurrentSession}const Sd=typeof window<"u"&&window.__VINCI_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();console.log("[ui-main] Runtime APIs loaded:",!!Sd);console.log("[ui-main] Runtime keys:",Object.keys(Sd||{}));dy();uy().then(()=>{Promise.all([my(),py()]).catch(t=>{console.error("[main] settings init failed:",t)}),fy(),hy(),gy()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Xh=document.getElementById("root");if(!Xh)throw new Error("Root element not found");Bg.createRoot(Xh).render(s.jsx(Le.StrictMode,{children:s.jsx(xy,{children:s.jsx(by,{children:s.jsx(yy,{children:s.jsx(vy,{children:s.jsx(bD,{apis:Sd})})})})})}));const LD=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{Jo as C,RD as G,QP as M,Jf as P,ur as S,Oi as a,Xo as b,Zo as c,qn as d,Dn as e,yr as f,vr as g,br as h,Lo as i,Aa as j,_n as k,FD as l,Os as m,Po as n,T3 as o,LD as p,Ea as u};