@openchamber/web 1.11.3 → 1.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{JsonTreeView-4KDa8lGo.js → JsonTreeView-YQcDxcEK.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-h6uFn35l.js +6 -0
- package/dist/assets/{MultiRunWindow-BBmUkZot.js → MultiRunWindow-BXZBRXf8.js} +1 -1
- package/dist/assets/{OnboardingScreen-CmfCd-NF.js → OnboardingScreen-AGACaSpL.js} +2 -2
- package/dist/assets/{SettingsWindow-Cju1ws5b.js → SettingsWindow-DbIrbkwH.js} +1 -1
- package/dist/assets/TerminalView-ClACTVsY.js +1 -0
- package/dist/assets/{ToolOutputDialog-v9jBbw8P.js → ToolOutputDialog-C9M1QAxc.js} +1 -1
- package/dist/assets/{es-jann2TW8.js → es-nmO_Sy-z.js} +4 -4
- package/dist/assets/index-BWxr-Sly.css +1 -0
- package/dist/assets/{ko-BI4PbFHS.js → ko-DgzWO49N.js} +4 -4
- package/dist/assets/{main-d-4uuoz4.js → main-BG6I-VaN.js} +2 -2
- package/dist/assets/main-DLomPR7m.js +227 -0
- package/dist/assets/miniChat-ata1oHqJ.js +2 -0
- package/dist/assets/{modelPrefsAutoSave-bm-G98P3.js → modelPrefsAutoSave-D4IOtl1d.js} +97 -98
- package/dist/assets/{pl-eehxx-j8.js → pl-CdOdV9f8.js} +3 -3
- package/dist/assets/{pt-BR-D34YtT2a.js → pt-BR-gg2QcqbT.js} +5 -5
- package/dist/assets/renderElectronMiniChatApp-F0L1QF1k.js +2 -0
- package/dist/assets/{uk-Ce5zhj4w.js → uk-CrnDWkt0.js} +4 -4
- package/dist/assets/{vendor-.bun-CJSRTa27.js → vendor-.bun-BIr1wmDP.js} +2 -10
- package/dist/assets/{zh-CN-DOs9jvCa.js → zh-CN-CWGQwc9R.js} +5 -5
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/package.json +1 -1
- package/server/lib/opencode/DOCUMENTATION.md +4 -0
- package/server/lib/opencode/config-entity-routes.js +115 -0
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/core-routes.test.js +17 -1
- package/server/lib/opencode/feature-routes-runtime.js +12 -0
- package/server/lib/opencode/index.js +9 -0
- package/server/lib/opencode/routes.js +14 -1
- package/server/lib/opencode/snippets.js +233 -0
- package/server/lib/opencode/snippets.test.js +68 -0
- package/server/lib/scheduled-tasks/runtime.js +4 -3
- package/dist/assets/MarkdownRendererImpl-ShCeV10r.js +0 -6
- package/dist/assets/TerminalView-K9P6-TDg.js +0 -1
- package/dist/assets/index-BG2LvnTV.css +0 -1
- package/dist/assets/main-BCXofLIN.js +0 -225
- package/dist/assets/miniChat-DCx1bzpk.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-exfEAtnm.js +0 -2
- /package/dist/assets/{index-CQjRYgmJ.js → index-Dc1XJWqt.js} +0 -0
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-CJSRTa27.js","assets/vendor--V65Sl9C2.css","assets/modelPrefsAutoSave-bm-G98P3.js","assets/index-CQjRYgmJ.js","assets/index-BG2LvnTV.css","assets/TerminalView-K9P6-TDg.js","assets/JsonTreeView-4KDa8lGo.js","assets/SettingsWindow-Cju1ws5b.js","assets/MultiRunWindow-BBmUkZot.js","assets/OnboardingScreen-CmfCd-NF.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as ot,R as l,u as Gi,a as ni,j as s,b as Nl,C as Sl,P as qi,S as sl,d as qg,D as nl,e as Yi,f as Ji,g as nr,i as vi,r as $e,k as Yg,l as Jg,p as ao,m as kl,n as Qg,o as Xg,q as Zg,_ as jr,s as _i,t as Ef,v as Kc,w as _a,x as Rf,W as ex,y as tx,V as sx,F as nx,z as rx,A as hr,E as ax,B as Xn,G as ix,H as wi,I as cu,J as ox,K as lx,L as Hl,M as cx,N as dx,O as ux,Q as du,T as uu,U as mx,X as Ff,Y as Of,Z as px,$ as mu,a0 as fx,a1 as hx,a2 as gx,a3 as xx,a4 as bx,a5 as yx,a6 as vx,a7 as Lf,a8 as wx,a9 as Hc,aa as $f,ab as Bf,ac as ei,ad as Fi,ae as Gc,af as lt,ag as _f,ah as zf,ai as jx,aj as Nx,ak as Sx,al as kx,am as Cx,an as Ix,ao as Px,ap as Ax,aq as Dx,ar as Tx,as as pu,at as fu,au as Gl,av as Mx}from"./vendor-.bun-CJSRTa27.js";import{a as Ex,b as Rx,f as Fx}from"./index-CQjRYgmJ.js";import{u as pt,a as De,b as nn,c as ue,I,d as Is,i as ln,g as sr,e as br,s as ql,r as Yl,f as Jl,h as Ts,o as en,j as _s,T as St,k as kt,l as Ct,m as Ma,n as Gr,p as hu,D as $t,q as Ox,t as rl,v as An,w as H,x as Es,y as Cn,z as Rs,A as Fs,B as Vf,C as gu,E as Lx,F as $x,G as xu,H as Bx,J as _x,K as zx,L as Vx,M as On,N as dn,O as Zn,P as qc,Q as xn,R as zi,S as Ux,U as vt,V as Lt,W as Wx,X as Uf,Y as Ia,Z as Ad,_ as zn,$ as Dd,a0 as Cl,a1 as Kx,a2 as bu,a3 as Hx,a4 as Gx,a5 as Wf,a6 as qx,a7 as Yx,a8 as Kf,a9 as Td,aa as al,ab as Hf,ac as Il,ad as Wr,ae as Md,af as Vo,ag as Jx,ah as Qx,ai as Qs,aj as Gf,ak as qf,al as Vt,am as Ns,an as Mr,ao as di,ap as Xx,aq as Yf,ar as vs,as as gs,at as xe,au as ms,av as ps,aw as Ea,ax as Zx,ay as eb,az as vo,aA as bn,aB as Jf,aC as Qf,aD as Pl,aE as tb,aF as Xf,aG as yu,aH as vu,aI as fn,aJ as ds,aK as sb,aL as nb,aM as rb,aN as ab,aO as ib,aP as ob,aQ as lb,aR as Vs,aS as cb,aT as db,aU as Ps,aV as ub,aW as mb,aX as pb,aY as fb,aZ as vr,a_ as io,a$ as hb,b0 as Us,b1 as Al,b2 as ti,b3 as ui,b4 as mi,b5 as wu,b6 as pi,b7 as gb,b8 as is,b9 as os,ba as us,bb as ls,bc as Ft,bd as xb,be as Ra,bf as bb,bg as Lr,bh as Ed,bi as Dl,bj as yb,bk as Rd,bl as vb,bm as wb,bn as Fd,bo as jb,bp as Zs,bq as oo,br as wr,bs as Nb,bt as Sb,bu as Ql,bv as Tl,bw as Od,bx as Ld,by as Ml,bz as En,bA as $d,bB as Fa,bC as il,bD as ol,bE as fi,bF as Zf,bG as kb,bH as Sr,bI as Cb,bJ as ju,bK as ll,bL as El,bM as eh,bN as Ib,bO as Pb,bP as lo,bQ as Ab,bR as Bd,bS as Db,bT as si,bU as Qi,bV as th,bW as hi,bX as sh,bY as Tb,bZ as Mb,b_ as _d,b$ as ra,c0 as ri,c1 as Pa,c2 as Rl,c3 as co,c4 as uo,c5 as Yc,c6 as nh,c7 as zd,c8 as rh,c9 as Xi,ca as Eb,cb as Rb,cc as Fb,cd as Ob,ce as Lb,cf as ai,cg as Xl,ch as Nu,ci as $b,cj as Bb,ck as _b,cl as zb,cm as Qa,cn as Zl,co as Vb,cp as Su,cq as Hr,cr as Ub,cs as ku,ct as Cu,cu as Iu,cv as Pu,cw as Uo,cx as Au,cy as Wb,cz as ec,cA as Kb,cB as Hb,cC as Gb,cD as qb,cE as Yb,cF as Jb,cG as Qb,cH as tc,cI as Du,cJ as Xb,cK as Zb,cL as ey,cM as ty,cN as sy,cO as sc,cP as ny,cQ as Tu,cR as Oi,cS as ry,cT as ah,cU as ay,cV as Xa,cW as iy,cX as Mu,cY as oy,cZ as ih,c_ as wo,c$ as Vi,d0 as ly,d1 as oh,d2 as cy,d3 as dy,d4 as Eu,d5 as Ru,d6 as lh,d7 as ch,d8 as nc,d9 as jo,da as uy,db as my,dc as py,dd as fy,de as dh,df as uh,dg as Jc,dh as Vd,di as hy,dj as ys,dk as Zi,dl as gi,dm as ii,dn as Fu,dp as Yn,dq as gy,dr as Ui,ds as xy,dt as mh,du as by,dv as yy,dw as Qc,dx as vy,dy as wy,dz as Ou,dA as jy,dB as Ny,dC as Sy,dD as Ud,dE as ph,dF as ky,dG as Cy,dH as Iy,dI as Py,dJ as Lu,dK as Ay,dL as Dy,dM as Ty,dN as My,dO as rc,dP as Ey,dQ as fh,dR as Ry,dS as Fy,dT as Oy,dU as Ly,dV as $y,dW as By,dX as _y,dY as zy,dZ as Vy,d_ as Uy,d$ as Wy,e0 as Ky,e1 as Hy,e2 as $u,e3 as Gy,e4 as hh,e5 as qy,e6 as Yy,e7 as Jy,e8 as Qy,e9 as Yr,ea as Xy,eb as Bu,ec as Zy,ed as Wo,ee as Ko,ef as ev,eg as tv,eh as sv,ei as nv,ej as _u,ek as rv,el as zu,em as av,en as Vu,eo as iv,ep as ov,eq as lv,er as Uu,es as Wu,et as Ku,eu as cv,ev as gh,ew as xh,ex as dv,ey as uv,ez as mv,eA as pv,eB as fv,eC as hv,eD as gv,eE as xv,eF as bv,eG as yv,eH as vv}from"./modelPrefsAutoSave-bm-G98P3.js";import{J as wv}from"./JsonTreeView-4KDa8lGo.js";const jv=({transform:t})=>({...t,y:0}),Nv=t=>{const e=ot.c(18),{id:n,children:r,className:a}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:o,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=Nl(i);let f;e[2]!==p?(f=Sl.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let b;e[4]!==f||e[5]!==m?(b={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=b):b=e[6];const h=u&&"opacity-50";let v;e[7]!==a||e[8]!==h?(v=ue("h-full rounded-md",a,h),e[7]=a,e[8]=h,e[9]=v):v=e[9];let x;return e[10]!==o||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==b||e[16]!==v?(x=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:b,className:v,...o,...c,children:r}),e[10]=o,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=b,e[16]=v,e[17]=x):x=e[17],x},Sv=t=>{const e=ot.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=ue("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;return e[2]!==r||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},Er=t=>{const e=ot.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:o,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:f,animateActivePill:b,activePillLowercase:h,className:v}=t,x=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,y=f===void 0?!1:f,k=h===void 0?!0:h,{t:A}=pt(),j=De(kv),{isTablet:S}=nn(),D=j||S,E=l.useRef(null);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P={left:!1,right:!1},e[0]=P):P=e[0];const[C,N]=l.useState(P);let T;e[1]!==n?(T=n.map(Cv),e[1]=n,e[2]=T):T=e[2];const M=T,F=x==="scrollable",_=g==="default",B=g==="active-pill",V=g==="animated",$=B||V,z=_,Q=$||z,L=B&&F,J=$,ee=b??V,re=typeof o=="function",q=re?Nv:Sv;let ce;e[3]===Symbol.for("react.memo_cache_sentinel")?(ce=new Map,e[3]=ce):ce=e[3];const ae=l.useRef(ce),[R,U]=l.useState(null);let W;e[4]===Symbol.for("react.memo_cache_sentinel")?(W={activationConstraint:{distance:8}},e[4]=W):W=e[4];const Z=Gi(ni(qi,W)),K=Iv;let ie;e[5]===Symbol.for("react.memo_cache_sentinel")?(ie=(nt,be)=>{if(be){ae.current.set(nt,be);return}ae.current.delete(nt)},e[5]=ie):ie=e[5];const Ne=ie;let ne;e[6]!==r||e[7]!==Q?(ne=()=>{if(!Q||!r){U(Pv);return}const nt=E.current,be=ae.current.get(r);if(!nt||!be){U(Av);return}let He=0,_e=0,tt=be;for(;tt&&tt!==nt;)He=He+tt.offsetLeft,_e=_e+tt.offsetTop,tt=tt.offsetParent;const ut={left:He,top:_e,width:be.offsetWidth,height:be.offsetHeight};U(qe=>K(qe,ut)?qe:ut)},e[6]=r,e[7]=Q,e[8]=ne):ne=e[8];const fe=ne;let pe;e[9]!==F?(pe=()=>{if(!F){N({left:!1,right:!1});return}const nt=E.current;if(!nt){N({left:!1,right:!1});return}N({left:nt.scrollLeft>2,right:nt.scrollLeft+nt.clientWidth<nt.scrollWidth-2})},e[9]=F,e[10]=pe):pe=e[10];const je=pe;let oe;e[11]!==F||e[12]!==je?(oe=()=>{if(!F){N({left:!1,right:!1});return}const nt=E.current;if(!nt)return;je(),nt.addEventListener("scroll",je,{passive:!0});const be=new ResizeObserver(je);return be.observe(nt),()=>{nt.removeEventListener("scroll",je),be.disconnect()}},e[11]=F,e[12]=je,e[13]=oe):oe=e[13];let Se;e[14]!==F||e[15]!==n.length||e[16]!==je?(Se=[F,n.length,je],e[14]=F,e[15]=n.length,e[16]=je,e[17]=Se):Se=e[17],l.useEffect(oe,Se);let se;e[18]!==r||e[19]!==fe||e[20]!==Q?(se=()=>{if(!Q){U(null);return}fe();const nt=E.current;if(!nt)return;const be=new ResizeObserver(fe);if(be.observe(nt),r){const He=ae.current.get(r);He&&be.observe(He)}return()=>{be.disconnect()}},e[18]=r,e[19]=fe,e[20]=Q,e[21]=se):se=e[21];let we;e[22]!==r||e[23]!==n.length||e[24]!==fe||e[25]!==Q?(we=[r,n.length,fe,Q],e[22]=r,e[23]=n.length,e[24]=fe,e[25]=Q,e[26]=we):we=e[26],l.useEffect(se,we);let Ae;e[27]!==fe?(Ae=()=>{fe()},e[27]=fe,e[28]=Ae):Ae=e[28],l.useLayoutEffect(Ae);let ve;e[29]!==r||e[30]!==F||e[31]!==je?(ve=()=>{if(!F||!r)return;const nt=E.current;if(!nt)return;const be=window.requestAnimationFrame(()=>{const He=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),_e=nt.querySelector(`[data-sortable-tab-id="${He}"]`);_e&&(_e.scrollIntoView({block:"nearest",inline:"nearest"}),je())});return()=>{window.cancelAnimationFrame(be)}},e[29]=r,e[30]=F,e[31]=je,e[32]=ve):ve=e[32];let ye;e[33]!==r||e[34]!==F||e[35]!==n.length||e[36]!==je?(ye=[r,F,n.length,je],e[33]=r,e[34]=F,e[35]=n.length,e[36]=je,e[37]=ye):ye=e[37],l.useEffect(ve,ye);let Ie;e[38]!==o?(Ie=nt=>{if(!o)return;const{active:be,over:He}=nt;!He||be.id===He.id||o(String(be.id),String(He.id))},e[38]=o,e[39]=Ie):Ie=e[39];const he=Ie;let me;e[40]!==v?(me=ue("relative flex h-full min-w-0 flex-1",v),e[40]=v,e[41]=me):me=e[41];let Ee;e[42]!==F||e[43]!==C||e[44]!==$?(Ee=F&&C.left?s.jsx("div",{className:ue("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=F,e[43]=C,e[44]=$,e[45]=Ee):Ee=e[45];let Ve;e[46]!==F||e[47]!==C||e[48]!==$?(Ve=F&&C.right?s.jsx("div",{className:ue("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=F,e[47]=C,e[48]=$,e[49]=Ve):Ve=e[49];const Y=$?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",ke=$&&"@container/pill-tabs",Be=$&&"pill-tabs__track",Ce=$&&(p??"gap-0.5 py-0.5"),ge=z&&"items-center overflow-y-hidden",O=J&&"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",X=F?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let G;e[50]!==Y||e[51]!==ke||e[52]!==Be||e[53]!==Ce||e[54]!==ge||e[55]!==O||e[56]!==X?(G=ue("relative flex h-full min-w-0 flex-1",Y,ke,Be,Ce,ge,O,X),e[50]=Y,e[51]=ke,e[52]=Be,e[53]=Ce,e[54]=ge,e[55]=O,e[56]=X,e[57]=G):G=e[57];let Te;e[58]!==F?(Te=F?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=F,e[59]=Te):Te=e[59];let le;e[60]!==A?(le=A("sortableTabsStrip.aria.tabs"),e[60]=A,e[61]=le):le=e[61];let We;e[62]!==R||e[63]!==ee||e[64]!==$?(We=$&&R?s.jsx("div",{className:ue("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(${R.left}px, ${R.top}px, 0)`,width:`${R.width}px`,height:`${R.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]=R,e[63]=ee,e[64]=$,e[65]=We):We=e[65];let de;e[66]!==R||e[67]!==z?(de=z&&R?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(${R.left}px, 0, 0)`,width:`${R.width}px`},"aria-hidden":!0}):null,e[66]=R,e[67]=z,e[68]=de):de=e[68];let Fe;if(e[69]!==q||e[70]!==r||e[71]!==m||e[72]!==k||e[73]!==D||e[74]!==y||e[75]!==w||e[76]!==B||e[77]!==j||e[78]!==F||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==L||e[83]!==$){let nt;e[85]!==q||e[86]!==r||e[87]!==m||e[88]!==k||e[89]!==D||e[90]!==y||e[91]!==w||e[92]!==B||e[93]!==j||e[94]!==F||e[95]!==i||e[96]!==a||e[97]!==L||e[98]!==$?(nt=be=>{const He=be.id===r,_e=w&&$&&!He&&!!be.icon,tt=!_e,ut=!!be.icon&&(!y||He),qe=w&&$&&He&&!F&&!L,ze=be.closable!==!1&&!!i,st=ze&&!!be.icon,yt=F||L?void 0:$?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",Mt=ze?ft=>{ft.button===1&&(ft.preventDefault(),ft.stopPropagation(),i?.(be.id))}:void 0,Bt=ze?Dv:void 0;return s.jsx(q,{id:be.id,className:yt,children:s.jsxs("div",{ref:ft=>Ne(be.id,ft),onAuxClick:Mt,onMouseDown:Bt,className:ue("group flex h-full min-w-0 flex-nowrap items-center",F||L?"shrink-0":$?"w-full":"w-full min-w-0",$?"relative z-10 bg-transparent":He?"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":He,"aria-label":_e?be.title??be.label:void 0,onClick:()=>a(be.id),className:ue($?"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?"lowercase":null,$&&(_e?"gap-0":"gap-1.5"),$?L?"shrink-0 whitespace-nowrap px-3 text-center":F?"max-w-56 shrink-0 px-3 text-center":_e?"px-2 !min-w-0 text-center":qe?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":F?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",$?m??(B?j?"h-[38px]":"h-[31px]":"h-7"):null,$?He?"text-foreground":"text-muted-foreground hover:text-foreground":null,$?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:be.title??be.label,children:$?s.jsxs(s.Fragment,{children:[ut?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:ue("flex items-center justify-center transition-opacity",st&&(D?"opacity-0":"group-hover:opacity-0")),children:be.icon}),st?s.jsx("span",{role:"button",tabIndex:-1,className:ue("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",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Tv,onClick:ft=>{ft.stopPropagation(),i?.(be.id)},"aria-label":be.closeLabel??`Close ${be.label} tab`,title:be.closeLabel??`Close ${be.label} tab`,children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,tt?s.jsx("span",{className:"animated-tabs__label truncate",children:be.label}):null]}):s.jsxs("span",{className:ue("flex min-w-0 flex-nowrap items-center gap-1.5",!F&&"justify-center"),children:[ut?s.jsxs("span",{className:ue("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",He?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:ue("flex items-center justify-center transition-opacity",st&&(D?"opacity-0":"group-hover:opacity-0")),children:be.icon}),st?s.jsx("span",{role:"button",tabIndex:-1,className:ue("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",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Mv,onClick:ft=>{ft.stopPropagation(),i?.(be.id)},"aria-label":be.closeLabel??`Close ${be.label} tab`,title:be.closeLabel??`Close ${be.label} tab`,children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:be.label})]})}),ze&&!st?s.jsx("button",{type:"button",onPointerDown:Ev,onClick:ft=>{ft.stopPropagation(),i?.(be.id)},className:ue("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",$?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",$?He?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":He?"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":be.closeLabel??`Close ${be.label} tab`,title:be.closeLabel??`Close ${be.label} tab`,children:s.jsx(I,{name:"close",className:"h-3 w-3"})}):null]})},be.id)},e[85]=q,e[86]=r,e[87]=m,e[88]=k,e[89]=D,e[90]=y,e[91]=w,e[92]=B,e[93]=j,e[94]=F,e[95]=i,e[96]=a,e[97]=L,e[98]=$,e[99]=nt):nt=e[99],Fe=n.map(nt),e[69]=q,e[70]=r,e[71]=m,e[72]=k,e[73]=D,e[74]=y,e[75]=w,e[76]=B,e[77]=j,e[78]=F,e[79]=n,e[80]=i,e[81]=a,e[82]=L,e[83]=$,e[84]=Fe}else Fe=e[84];let rt;e[100]!==G||e[101]!==Te||e[102]!==le||e[103]!==We||e[104]!==de||e[105]!==Fe?(rt=s.jsxs("div",{ref:E,className:G,style:Te,role:"tablist","aria-label":le,children:[We,de,Fe]}),e[100]=G,e[101]=Te,e[102]=le,e[103]=We,e[104]=de,e[105]=Fe,e[106]=rt):rt=e[106];let Oe;e[107]!==me||e[108]!==Ee||e[109]!==Ve||e[110]!==rt?(Oe=s.jsxs("div",{className:me,children:[Ee,Ve,rt]}),e[107]=me,e[108]=Ee,e[109]=Ve,e[110]=rt,e[111]=Oe):Oe=e[111];const Ye=Oe;if(!re)return Ye;let Ge;e[112]===Symbol.for("react.memo_cache_sentinel")?(Ge=[jv],e[112]=Ge):Ge=e[112];let it;e[113]!==M||e[114]!==Ye?(it=s.jsx(sl,{items:M,strategy:qg,children:Ye}),e[113]=M,e[114]=Ye,e[115]=it):it=e[115];let Qe;e[116]===Symbol.for("react.memo_cache_sentinel")?(Qe=s.jsx(nl,{dropAnimation:null}),e[116]=Qe):Qe=e[116];let at;return e[117]!==he||e[118]!==Z||e[119]!==it?(at=s.jsxs(Yi,{sensors:Z,collisionDetection:Ji,onDragEnd:he,modifiers:Ge,children:[it,Qe]}),e[117]=he,e[118]=Z,e[119]=it,e[120]=at):at=e[120],at};function kv(t){return t.isMobile}function Cv(t){return t.id}function Iv(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 Pv(t){return t===null?t:null}function Av(t){return t===null?t:null}function Dv(t){t.button===1&&t.preventDefault()}function Tv(t){t.stopPropagation()}function Mv(t){t.stopPropagation()}function Ev(t){t.stopPropagation()}function Hu(t){const e=ot.c(14);let n,r,a,i;e[0]!==t?({size:a,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);const o=typeof a=="number"?`${a}px`:a,c=typeof a=="number"?`${a}px`:a;let d;e[5]!==i||e[6]!==o||e[7]!==c?(d={width:o,height:c,...i},e[5]=i,e[6]=o,e[7]=c,e[8]=d):d=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=p):p=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:p}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Or=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"wafer",name:"Wafer.ai"}];Or.reduce((t,e)=>(t[e.id]=e,t),{});const Rv=t=>typeof t!="number"||!Number.isFinite(t)?null:Math.max(0,Math.min(100,Math.round(t))),Fv=t=>typeof t!="number"||!Number.isFinite(t)?"-":`${Math.round(t)}%`,eo=(t,e)=>t??Fv(e),Wd=(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??""}},bh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",Kd=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,Ov=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},to=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=Ov(r)),t===null||e===null||a===null||a<=0)return null;const i=Date.now(),o=Math.max(0,(e-i)/1e3),c=Math.max(0,Math.min(a,a-o)),d=Math.max(0,Math.min(1,c/a)),p=t/100,m=t>=100&&o>0;let u;d>.01?u=Math.min(999,p/d*100):u=t;let f;m?f="exhausted":p<=d?f="on-track":u<=130?f="slightly-fast":f="too-fast";const b=a>=120*3600,h=b?86400:3600,v=b?"d":"h",x=a/h,g=Math.max(c/h,x*.01),w=t/g,y=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${v}`:"-",k=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let A=null;const j=a/86400;return j>=7&&(A=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:o,isExhausted:m,elapsedSeconds:c,totalSeconds:a,status:f,paceRateText:y,predictText:k,dailyAllocationPercent:A}},Lv=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)"}},Gu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),a=Math.floor(r/24),i=r%24,o=n%60;return a>0?`${a}d ${i}h`:r>0?`${r}h`:n===0?"<1m":`${o}m`},Kr=t=>Math.min(100,Math.max(0,t*100));function cl(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 $v=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],yh={google:$v};function vh(t,e){const n=yh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function wh(t){return yh[t]??[]}function jh(t){return[...t].sort((e,n)=>e.order-n.order)}function Bv(t,e){const n=new Map;for(const r of Object.keys(t)){const i=vh(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function _v(t,e,n){const r=new Map;for(const a of t){const i=e(a),c=vh(i,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(a)}return r}function zv(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 Hd=6e4,qu=t=>{const e=Or.map(u=>u.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):Hd,a=t?.usageDisplayMode==="remaining"?"remaining":"usage",i=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,o=i?i.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[u,f]of Object.entries(d))Array.isArray(f)&&(c[u]=f.filter(b=>typeof b=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,f]of Object.entries(m))Array.isArray(f)&&(p[u]=f.filter(b=>typeof b=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:a,dropdownProviderIds:o,selectedModels:c,expandedFamilies:p}},Vv=async()=>{const t=sr()?.settings;if(t)try{const n=(await t.load())?.settings;return qu(n??null)}catch{}if(!ln()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return qu(n)}}return{autoRefresh:!1,refreshIntervalMs:Hd,displayMode:"usage",dropdownProviderIds:Or.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ms=nr()(vi((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Hd,displayMode:"usage",dropdownProviderIds:Or.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Vv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Or.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:a})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),a=await r.json().catch(()=>null);if(!r.ok)throw new Error(a?.error||"Failed to fetch quota");const i=a;t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:null}})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:a,usage:null,fetchedAt:Date.now()};t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:a}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(a=>({selectedModels:{...a.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(a=>{const i=a.selectedModels[n]??[],c=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{selectedModels:{...a.selectedModels,[n]:c}}})},setExpandedFamilies:(n,r)=>{t(a=>({expandedFamilies:{...a.expandedFamilies,[n]:r}})),Is({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(a=>{const i=a.expandedFamilies[n]??[],c=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{expandedFamilies:{...a.expandedFamilies,[n]:c}}}),Is({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=zv(n,r);i.length!==0&&(t(o=>({selectedModels:{...o.selectedModels,[n]:i}})),Is({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Nh=()=>{const t=ot.c(5),e=Ms(Uv),n=Ms(Wv),r=Ms(Kv);let a,i;t[0]!==e||t[1]!==r||t[2]!==n?(a=()=>{if(!e)return;const o=window.setInterval(()=>{r()},n);return()=>window.clearInterval(o)},i=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=a,t[4]=i):(a=t[3],i=t[4]),l.useEffect(a,i)};function Uv(t){return t.autoRefresh}function Wv(t){return t.refreshIntervalMs}function Kv(t){return t.fetchAllQuotas}const dl=$e.forwardRef((t,e)=>{const n=ot.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=ue("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=i):i=n[4];let o;n[5]===Symbol.for("react.memo_cache_sentinel")?(o={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=o):o=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Yg,{className:ue("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=c):c=n[6];let d;return n[7]!==a||n[8]!==e||n[9]!==i?(d=s.jsx(Jg,{className:i,style:o,...a,ref:e,children:c}),n[7]=a,n[8]=e,n[9]=i,n[10]=d):d=n[10],d});dl.displayName="Switch";const No=()=>{try{const e=Ts.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=en.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},Yu=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]))},So=t=>typeof t!="string"?void 0:t.trim()||void 0,ac=800,Hv=5e3,Gv="__default__",Xc=new Map,ic=new Map,Sh=t=>t?.trim()||Gv,oc=t=>{Xc.delete(Sh(t))},so=nr()(vi(ao((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=No(),a=Sh(r),i=Date.now(),o=Xc.get(a)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-o<Hv)return!0;const d=ic.get(a);if(!n?.force&&d)return d;const p=(async()=>{t({isLoading:!0});try{const m=r?`?directory=${encodeURIComponent(r)}`:"",u=await fetch(`/api/config/mcp${m}`,{headers:r?{"x-opencode-directory":r}:void 0});if(!u.ok)throw new Error("Failed to load MCP configs");const f=await u.json();return t({mcpServers:f,isLoading:!1}),Xc.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();ic.set(a,p);try{return await p}finally{ic.delete(a)}},createMcp:async n=>{ql("Creating MCP server configuration…");let r=!1;try{const a=Qu(n),i=No(),o=i?`?directory=${encodeURIComponent(i)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(a)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return oc(i),d?.requiresReload?(r=!0,await Yl({message:d.message,delayMs:d.reloadDelayMs??ac,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||Jl()}},updateMcp:async(n,r)=>{ql("Updating MCP server configuration…");let a=!1;try{const i=Qu(r),o=No(),c=o?`?directory=${encodeURIComponent(o)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),p=await d.json().catch(()=>null);if(!d.ok)throw new Error(p?.error||"Failed to update MCP server");return oc(o),p?.requiresReload?(a=!0,await Yl({message:p.message,delayMs:p.reloadDelayMs??ac,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{a||Jl()}},deleteMcp:async n=>{ql("Deleting MCP server configuration…");let r=!1;try{const a=No(),i=a?`?directory=${encodeURIComponent(a)}`:"",o=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:a?{"x-opencode-directory":a}:void 0}),c=await o.json().catch(()=>null);if(!o.ok)throw new Error(c?.error||"Failed to delete MCP server");return oc(a),c?.requiresReload&&(r=!0,await Yl({message:c.message,delayMs:c.reloadDelayMs??ac,scopes:["all"]})),e().selectedMcpName===n&&t({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}}catch(a){return console.error("[McpConfigStore] Failed to delete MCP:",a),{ok:!1}}finally{r||Jl()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:kl(()=>br()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function Qu(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:So(t.oauthClientId),clientSecret:So(t.oauthClientSecret),scope:So(t.oauthScope),redirectUri:So(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 qv={},Yv={},Ur=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},Ga=t=>Ur(t)??"__global__",ha=t=>{const e=Ur(t);return e?en.getScopedApiClient(e):en.getApiClient()},gn=nr()(vi((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Ga(n??_s.getState().currentDirectory);return e().byDirectory[r]??qv},getDiagnosticForDirectory:n=>{const r=Ga(n??_s.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Yv},getErrorForDirectory:n=>{const r=Ga(n??_s.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Ur(n?.directory??_s.getState().currentDirectory),a=Ga(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const c=(await ha(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[a]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[a]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[a]??{}).filter(([p])=>!c[p]))},loadingKeys:{...d.loadingKeys,[a]:!1},lastErrorKeys:{...d.lastErrorKeys,[a]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[a]:!1},lastErrorKeys:{...c.lastErrorKeys,[a]:o}}))}},connect:async(n,r)=>{const a=Ur(r??_s.getState().currentDirectory),i=Ga(a),o=ha(a);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw t(p=>({diagnosticsByDirectory:{...p.diagnosticsByDirectory,[i]:{...p.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:a,silent:!0})},disconnect:async(n,r)=>{const a=Ur(r??_s.getState().currentDirectory);await ha(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=Ur(r??_s.getState().currentDirectory),c=(await ha(a).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!c)throw new Error("Authorization URL was not returned");return c},completeAuth:async(n,r,a)=>{const i=Ur(a??_s.getState().currentDirectory);await ha(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=Ur(r??_s.getState().currentDirectory);await ha(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=Ur(r??_s.getState().currentDirectory),i=Ga(a),o=ha(a),d=e().getStatusForDirectory(a)[n]?.status==="connected";let p,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(b){p=b instanceof Error?b.message:"Connection failed",t(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:a,silent:!0});const u=e().getStatusForDirectory(a)[n],f=u;if(!d&&u?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(b){m=`Connection test succeeded, but cleanup disconnect failed: ${b instanceof Error?b.message:"Disconnect failed"}`}await e().refresh({directory:a,silent:!0})}return{status:f??e().getStatusForDirectory(a)[n],error:p,warning:m}}})));function Jv(t){const e=ot.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 Qv=(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}},Xv=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},kh=({active:t,className:e})=>{const{t:n}=pt(),a=_s(g=>g.currentDirectory)??null,i=gn(g=>g.getStatusForDirectory(a)),o=gn(g=>g.refresh),c=gn(g=>g.connect),d=gn(g=>g.disconnect),p=so(g=>g.mcpServers),m=so(g=>g.loadMcpConfigs),[u,f]=l.useState(!1),[b,h]=l.useState(null);l.useEffect(()=>{o({directory:a,silent:!0})},[o,a]),l.useEffect(()=>{m({force:!0})},[m]),l.useEffect(()=>{t&&Promise.all([o({directory:a,silent:!0}),m({force:!0})])},[t,o,a,m]);const v=l.useMemo(()=>{const g=new Set(Object.keys(i));for(const w of p)w?.name&&g.add(w.name);return Array.from(g).sort((w,y)=>w.localeCompare(y))},[p,i]),x=l.useCallback(g=>{if(g?.preventDefault(),u)return;f(!0);const w=new Promise(y=>setTimeout(y,500));Promise.all([o({directory:a}),w]).finally(()=>{f(!1)})},[u,o,a]);return s.jsxs("div",{className:ue("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),a&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:a.split("/").pop()||a})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:u,onClick:x,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:ue("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[v.map(g=>{const w=i[g],y=Xv(w),k=w?.status==="connected",A=b===g,j=Qv(w,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:ue("h-2 w-2 rounded-full flex-shrink-0",y==="success"&&"bg-status-success",y==="error"&&"bg-status-error",y==="warning"&&"bg-status-warning",y==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(Ct,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(dl,{checked:k,disabled:A,className:"data-[checked]:bg-status-info",onCheckedChange:async S=>{h(g);try{S?await c(g,a):await d(g,a)}finally{h(null)}}})]},g)}),v.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},no=t=>{const e=ot.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let o;e[0]!==n?(o=Rv(n)??0,e[0]=n,e[1]=o):o=e[1];const c=o,d=r??n;let p;e[2]!==d?(p=bh(d),e[2]=d,e[3]=p):p=e[3];const m=p,u=i!=null?Math.max(0,Math.min(100,i)):null;let f;e[4]!==m?(f=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=f):f=e[5];const b=f;let h;e[6]!==a?(h=ue("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=h):h=e[7];const v=`${c}%`;let x;e[8]!==b||e[9]!==v?(x={...b,width:v},e[8]=b,e[9]=v,e[10]=x):x=e[10];let g;e[11]!==c||e[12]!==x?(g=s.jsx("div",{className:"h-full transition-all duration-300",style:x,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=x,e[13]=g):g=e[13];let w;e[14]!==u?(w=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=w):w=e[15];let y;return e[16]!==h||e[17]!==g||e[18]!==w?(y=s.jsxs("div",{className:h,children:[g,w]}),e[16]=h,e[17]=g,e[18]=w,e[19]=y):y=e[19],y},ro=t=>{const e=ot.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:o}=pt();let c;e[0]!==n.status?(c=Lv(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let p;e:{switch(n.status){case"on-track":{let S;e[2]!==o?(S=o("settings.usage.pace.status.onTrack"),e[2]=o,e[3]=S):S=e[3],p=S;break e}case"slightly-fast":{let S;e[4]!==o?(S=o("settings.usage.pace.status.slightlyFast"),e[4]=o,e[5]=S):S=e[5],p=S;break e}case"too-fast":{let S;e[6]!==o?(S=o("settings.usage.pace.status.tooFast"),e[6]=o,e[7]=S):S=e[7],p=S;break e}case"exhausted":{let S;e[8]!==o?(S=o("settings.usage.pace.status.usedUp"),e[8]=o,e[9]=S):S=e[9],p=S;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==o?(u=o("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=o,e[12]=u):u=e[12];const f=u;if(i){let S;e[13]!==r?(S=ue("flex items-center gap-1.5",r),e[13]=r,e[14]=S):S=e[14];let D;e[15]!==d?(D={backgroundColor:d},e[15]=d,e[16]=D):D=e[16];let E;e[17]!==m||e[18]!==D?(E=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:D,title:m}),e[17]=m,e[18]=D,e[19]=E):E=e[19];let P;e[20]!==d?(P={color:d},e[20]=d,e[21]=P):P=e[21];const C=n.isExhausted?void 0:f;let N;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==o?(N=n.isExhausted?s.jsx(s.Fragment,{children:o("settings.usage.pace.wait",{duration:Gu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:o("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=o,e[26]=N):N=e[26];let T;e[27]!==N||e[28]!==P||e[29]!==C?(T=s.jsx("span",{className:"typography-micro tabular-nums",style:P,title:C,children:N}),e[27]=N,e[28]=P,e[29]=C,e[30]=T):T=e[30];let M;return e[31]!==T||e[32]!==S||e[33]!==E?(M=s.jsxs("div",{className:S,children:[E,T]}),e[31]=T,e[32]=S,e[33]=E,e[34]=M):M=e[34],M}let b;e[35]!==r?(b=ue("flex items-center justify-between gap-2",r),e[35]=r,e[36]=b):b=e[36];let h;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==o?(h=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=o,e[40]=h):h=e[40];let v;e[41]!==h?(v=s.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[41]=h,e[42]=v):v=e[42];let x;e[43]!==d?(x={color:d},e[43]=d,e[44]=x):x=e[44];let g;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==f||e[49]!==m||e[50]!==o?(g=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:Gu(n.remainingSeconds)})]}):s.jsxs("span",{title:f,children:[s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=f,e[49]=m,e[50]=o,e[51]=g):g=e[51];let w;e[52]!==x||e[53]!==g?(w=s.jsx("span",{className:"typography-micro tabular-nums",style:x,children:g}),e[52]=x,e[53]=g,e[54]=w):w=e[54];let y;e[55]!==d?(y={backgroundColor:d},e[55]=d,e[56]=y):y=e[56];let k;e[57]!==m||e[58]!==y?(k=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:y,title:m}),e[57]=m,e[58]=y,e[59]=k):k=e[59];let A;e[60]!==w||e[61]!==k?(A=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,k]}),e[60]=w,e[61]=k,e[62]=A):A=e[62];let j;return e[63]!==A||e[64]!==b||e[65]!==v?(j=s.jsxs("div",{className:b,children:[v,A]}),e[63]=A,e[64]=b,e[65]=v,e[66]=j):j=e[66],j},pr=Qg,Nr=t=>{const e=ot.c(14);let n,r,a,i;e[0]!==t?({className:a,asChild:n,children:r,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);let o;e[5]!==n||e[6]!==r?(o=n&&$e.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=o):o=e[7];const c=o;let d;e[8]!==a?(d=ue("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",a),e[8]=a,e[9]=d):d=e[9];let p;return e[10]!==i||e[11]!==c||e[12]!==d?(p=s.jsx(Xg,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},fr=t=>{const e=ot.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=ue("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(Zg,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},aa=[{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"}],Zc="finder",ed=new Set(["finder","terminal"]),td=t=>t?aa.find(e=>e.id===t)??null:null,lc=()=>aa.filter(t=>ed.has(t.id)).map(t=>({...t})),Zv=()=>{if(typeof window>"u")return Zc;const t=window.localStorage.getItem("openInAppId");return t&&td(t)?t:Zc};let cc=!1,qa=!1,ea=!1,ta=0,Wi=null;const Xu=()=>{Wi&&(clearTimeout(Wi),Wi=null)},Dr=nr()((t,e)=>({selectedAppId:Zv(),availableApps:lc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(cc||typeof window>"u")return;cc=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:lc(),hasLoadedApps:p});return}const m=new Set(d.map(h=>h.name)),u=new Map(d.map(h=>[h.name,h.iconDataUrl??void 0])),b=aa.filter(h=>m.has(h.appName)||ed.has(h.id)).map(h=>({...h,iconDataUrl:u.get(h.appName)}));t({availableApps:b,hasLoadedApps:!0})},r=async d=>{if(!Ma()||!Gr()||qa||e().hasLoadedApps&&!d)return;const m=aa.map(u=>u.appName);Xu(),qa=!0,ea=!1,t({isScanning:!0});try{const{apps:u,success:f,hasCache:b,isCacheStale:h}=await hu(m,d),v=f&&!b&&u.length===0&&ta<3;if(t({isCacheStale:b?h:!1}),n(u,f?!v:!1),f){if(v){const g=[800,1600,3200][ta]??3200;ta+=1,ea=!0,Wi=setTimeout(()=>{r()},g);return}ta=0,ea=!1;return}if(ta<3){const g=[1e3,3e3,7e3][ta]??7e3;ta+=1,ea=!0,Wi=setTimeout(()=>{r()},g)}}finally{qa=!1,ea||t({isScanning:!1})}};r();const a=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&td(p.openInAppId)?p.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},i=()=>{r()},o=d=>{const p=d.detail;Array.isArray(p)&&(ta=3,ea=!1,t({isScanning:!1,isCacheStale:!1}),n(p))};window.addEventListener("openchamber:settings-synced",a),window.addEventListener("openchamber:app-ready",i),window.addEventListener("openchamber:installed-apps-updated",o),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(cc||e().initialize(),!Ma()||!Gr()||qa||e().hasLoadedApps&&!n)return;const a=aa.map(i=>i.appName);Xu(),n&&t({hasLoadedApps:!1}),qa=!0,ea=!1,t({isScanning:!0});try{const{apps:i,hasCache:o,isCacheStale:c}=await hu(a,n),d=new Set(i.map(f=>f.name)),p=new Map(i.map(f=>[f.name,f.iconDataUrl??void 0])),u=aa.filter(f=>d.has(f.appName)||ed.has(f.id)).map(f=>({...f,iconDataUrl:p.get(f.appName)}));t({availableApps:u.length>0?u:lc(),hasLoadedApps:u.length>0,isCacheStale:o?c:!1})}finally{qa=!1,ea||t({isScanning:!1})}},selectApp:async n=>{td(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Is({openInAppId:n}))}})),ew="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",tw="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",dc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?ew:t.id==="terminal"?tw:void 0}),Zu=t=>{const e=ot.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:a}=t,[i,o]=l.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||a;if(p&&!i){let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=()=>o(!0),e[2]=f):f=e[2];let b;return e[3]!==p?(b=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:f}),e[3]=p,e[4]=b):b=e[4],b}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=ue("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let u;return e[6]!==d?(u=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=u):u=e[7],u},sw=t=>{const e=ot.c(82),{directory:n,className:r}=t,{t:a}=pt(),i=Dr(nw),o=Dr(rw),c=Dr(aw),d=Dr(iw),p=Dr(ow),m=Dr(lw),u=Dr(cw);let f,b;e[0]!==p?(f=()=>{p()},b=[p],e[0]=p,e[1]=f,e[2]=b):(f=e[1],b=e[2]),l.useEffect(f,b);const h=Ma()&&Gr();let v;e:{let K;e[3]!==o||e[4]!==i?(K=o.find(ne=>ne.id===i)??o.find(dw)??o[0]??aa[0],e[3]=o,e[4]=i,e[5]=K):K=e[5];const ie=K;if(ie){let ne;e[6]!==ie?(ne=dc(ie),e[6]=ie,e[7]=ne):ne=e[7],v=ne;break e}let Ne;e[8]===Symbol.for("react.memo_cache_sentinel")?(Ne=dc(aa[0]),e[8]=Ne):Ne=e[8],v=Ne}const x=v;if(!h||!n||o.length===0)return null;let g;e[9]!==n?(g=async K=>{await Ox(n,K.id,K.appName)||await rl(n,K.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let y;e[11]!==w||e[12]!==u?(y=async K=>{await u(K.id),await w(K)},e[11]=w,e[12]=u,e[13]=y):y=e[13];const k=y;let A;e[14]!==n||e[15]!==a?(A=async()=>{(await An(n)).ok&&H.success(a("openInApp.toast.pathCopied"))},e[14]=n,e[15]=a,e[16]=A):A=e[16];const j=A;let S;e[17]!==r?(S=ue("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=S):S=e[18];let D;e[19]!==w||e[20]!==x?(D=()=>{w(x)},e[19]=w,e[20]=x,e[21]=D):D=e[21];let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=ue("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=E):E=e[22];let P;e[23]!==x.label||e[24]!==a?(P=a("openInApp.actions.openInAria",{app:x.label}),e[23]=x.label,e[24]=a,e[25]=P):P=e[25];let C;e[26]!==x.fallbackIconDataUrl||e[27]!==x.iconDataUrl||e[28]!==x.label?(C=s.jsx(Zu,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[26]=x.fallbackIconDataUrl,e[27]=x.iconDataUrl,e[28]=x.label,e[29]=C):C=e[29];const N=d?"animate-pulse text-muted-foreground":void 0;let T;e[30]!==N?(T=ue("header-open-label",N),e[30]=N,e[31]=T):T=e[31];let M;e[32]!==a?(M=a("openInApp.actions.open"),e[32]=a,e[33]=M):M=e[33];let F;e[34]!==T||e[35]!==M?(F=s.jsx("span",{className:T,children:M}),e[34]=T,e[35]=M,e[36]=F):F=e[36];let _;e[37]!==P||e[38]!==C||e[39]!==F||e[40]!==D?(_=s.jsxs("button",{type:"button",onClick:D,className:E,"aria-label":P,children:[C,F]}),e[37]=P,e[38]=C,e[39]=F,e[40]=D,e[41]=_):_=e[41];let B;e[42]===Symbol.for("react.memo_cache_sentinel")?(B=ue("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[42]=B):B=e[42];let V;e[43]!==a?(V=a("openInApp.actions.chooseAppAria"),e[43]=a,e[44]=V):V=e[44];let $;e[45]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"}),e[45]=$):$=e[45];let z;e[46]!==V?(z=s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:B,"aria-label":V,children:$})}),e[46]=V,e[47]=z):z=e[47];let Q;e[48]===Symbol.for("react.memo_cache_sentinel")?(Q={translate:"-30px 0"},e[48]=Q):Q=e[48];let L;e[49]!==j?(L=()=>{j()},e[49]=j,e[50]=L):L=e[50];let J;e[51]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(I,{name:"file-copy",className:"h-4 w-4"}),e[51]=J):J=e[51];let ee;e[52]!==a?(ee=a("openInApp.actions.copyPath"),e[52]=a,e[53]=ee):ee=e[53];let re;e[54]!==ee?(re=s.jsx("span",{className:"typography-ui-label text-foreground",children:ee}),e[54]=ee,e[55]=re):re=e[55];let q;e[56]!==L||e[57]!==re?(q=s.jsxs($t,{className:"flex items-center gap-2",onClick:L,children:[J,re]}),e[56]=L,e[57]=re,e[58]=q):q=e[58];let ce;e[59]===Symbol.for("react.memo_cache_sentinel")?(ce=s.jsx(Cn,{}),e[59]=ce):ce=e[59];let ae;if(e[60]!==o||e[61]!==k||e[62]!==x.id){let K;e[64]!==k||e[65]!==x.id?(K=ie=>{const Ne=dc(ie);return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{k(ie)},children:[s.jsx(Zu,{label:ie.label,iconDataUrl:ie.iconDataUrl,fallbackIconDataUrl:Ne.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ie.label}),x.id===ie.id?s.jsx(I,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},ie.id)},e[64]=k,e[65]=x.id,e[66]=K):K=e[66],ae=o.map(K),e[60]=o,e[61]=k,e[62]=x.id,e[63]=ae}else ae=e[63];let R;e[67]!==c||e[68]!==m||e[69]!==a?(R=c?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(I,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("openInApp.actions.refreshApps")})]}):null,e[67]=c,e[68]=m,e[69]=a,e[70]=R):R=e[70];let U;e[71]!==q||e[72]!==ae||e[73]!==R?(U=s.jsxs(Rs,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:Q,children:[q,ce,ae,R]}),e[71]=q,e[72]=ae,e[73]=R,e[74]=U):U=e[74];let W;e[75]!==z||e[76]!==U?(W=s.jsxs(Fs,{children:[z,U]}),e[75]=z,e[76]=U,e[77]=W):W=e[77];let Z;return e[78]!==_||e[79]!==W||e[80]!==S?(Z=s.jsxs("div",{className:S,children:[_,W]}),e[78]=_,e[79]=W,e[80]=S,e[81]=Z):Z=e[81],Z};function nw(t){return t.selectedAppId}function rw(t){return t.availableApps}function aw(t){return t.isCacheStale}function iw(t){return t.isScanning}function ow(t){return t.initialize}function lw(t){return t.loadInstalledApps}function cw(t){return t.selectApp}function dw(t){return t.id===Zc}const uw=1e6,mw="terminal-store";let em=!1;const uc=t=>typeof t=="object"&&t!==null,pw=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function Bn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const mc=(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}),Ch=/\x1b\[[0-9;]*m/g,fw=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,hw=new Set([".",",",";",":","!","?"]),gw=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",a=e.slice(0,-1),i=(a.match(new RegExp(`\\${r}`,"g"))||[]).length,o=(a.match(new RegExp(`\\${n}`,"g"))||[]).length;if(i>o)break;e=a;continue}if(hw.has(n)){e=e.slice(0,-1);continue}break}return e},xw=t=>{if(!t)return null;const n=t.replace(Ch,"").match(fw);if(!n?.[1])return null;let r=gw(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},bw=t=>{if(!t)return null;const n=t.replace(Ch,"").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}/`},pc=t=>({tabs:[t],activeTabId:t.id}),Pr=(t,e)=>t.tabs.findIndex(n=>n.id===e),rn=nr()(vi(ao((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=Bn(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),o=`tab-${a.nextTabId}`,c=mc(o,"Terminal");return i.set(r,pc(c)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=Bn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=Bn(n),a=e().sessions.get(r);if(!a)return;const i=a.activeTabId;return i?a.tabs.find(o=>o.id===i)??a.tabs[0]:a.tabs[0]},createTab:n=>{const r=Bn(n);if(!r)return"tab-invalid";const a=`tab-${e().nextTabId}`;return t(i=>{const o=new Map(i.sessions),c=o.get(r),d=i.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=mc(a,m);return c?o.set(r,{...c,tabs:[...c.tabs,u]}):o.set(r,pc(u)),{sessions:o,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=Bn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);return!c||c.activeTabId===r||Pr(c,r)<0?i:(o.set(a,{...c,activeTabId:r}),{sessions:o})})},setTabLabel:(n,r,a)=>{const i=Bn(n),o=a.trim();o&&t(c=>{const d=new Map(c.sessions),p=d.get(i);if(!p)return c;const m=Pr(p,r);if(m<0||p.tabs[m]?.label===o)return c;const u=[...p.tabs];return u[m]={...u[m],label:o},d.set(i,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,a)=>{const i=Bn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=a?.trim()||null;if(d.tabs[p]?.iconKey===m)return o;const u=[...d.tabs];return u[p]={...u[p],iconKey:m},c.set(i,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const a=Bn(n),c=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await Ex(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(a);if(!m)return d;const u=Pr(m,r);if(u<0)return d;const f=m.tabs.filter(x=>x.id!==r),b=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,x])=>!(x.directory===a&&x.tabId===r))),h=Object.keys(b).length!==Object.keys(d.projectActionRuns).length;if(f.length===0){const x=`tab-${d.nextTabId}`,g=mc(x,"Terminal");return p.set(a,pc(g)),{sessions:p,nextTabId:d.nextTabId+1,...h?{projectActionRuns:b}:{}}}let v=m.activeTabId;return m.activeTabId===r&&(v=f[Math.min(u,f.length-1)]?.id??f[0]?.id??null),p.set(a,{...m,tabs:f,activeTabId:v}),{sessions:p,...h?{projectActionRuns:b}:{}}})},setTabSessionId:(n,r,a)=>{const i=Bn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=d.tabs[p],u=a!==null&&m.terminalSessionId!==a,f=a?"running":m.terminalSessionId?"exited":m.lifecycle,b={...m,terminalSessionId:a,lifecycle:f,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},h=[...d.tabs];return h[p]=b,c.set(i,{...d,tabs:h}),{sessions:c}})},setTabLifecycle:(n,r,a)=>{const i=Bn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],lifecycle:a,isConnecting:!1},c.set(i,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,a)=>{const i=Bn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],isConnecting:a},c.set(i,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,a)=>{if(!a)return;const i=Bn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=d.tabs[p],u=o.nextChunkId,f={id:u,data:a},b=[...m.bufferChunks,f];let h=m.bufferLength+a.length;for(;h>uw&&b.length>1;){const w=b.shift();if(!w)break;h-=w.data.length}const v=m.previewUrlLocked?null:xw(a)??bw(a),x=!!(v&&v!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:b,bufferLength:h,...x?{previewUrl:v,previewAutoOpened:!1}:null},c.set(i,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const o=Bn(n);t(c=>{const d=new Map(c.sessions),p=d.get(o);if(!p)return c;const m=Pr(p,r);if(m<0)return c;const u=p.tabs[m],f=i.autoOpened??u.previewAutoOpened,b=i.locked??u.previewUrlLocked;if(u.previewUrl===a&&u.previewAutoOpened===f&&u.previewUrlLocked===b)return c;const h=[...p.tabs];return h[m]={...u,previewUrl:a,previewAutoOpened:f,previewUrlLocked:b},d.set(o,{...p,tabs:h}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=Bn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Pr(c,r);if(d<0)return i;const p=c.tabs[d];if(!p.previewUrl||p.previewAutoOpened)return i;const m=[...c.tabs];return m[d]={...p,previewAutoOpened:!0},o.set(a,{...c,tabs:m}),{sessions:o}})},setProjectActionRun:n=>{t(r=>{const a=r.projectActionRuns[n.key];return a&&a.directory===n.directory&&a.actionId===n.actionId&&a.tabId===n.tabId&&a.sessionId===n.sessionId&&a.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(a=>{const i=a.projectActionRuns[n];return!i||i.status===r?a:{projectActionRuns:{...a.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const a={...r.projectActionRuns};return delete a[n],{projectActionRuns:a}})},clearBuffer:(n,r)=>{const a=Bn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Pr(c,r);if(d<0)return i;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},o.set(a,{...c,tabs:p}),{sessions:o}})},removeDirectory:n=>{const r=Bn(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const o=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:i,projectActionRuns:o}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:mw,storage:kl(()=>Vf()),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(!uc(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let a=0;for(const c of n){if(!Array.isArray(c)||c.length!==2)continue;const[d,p]=c;if(typeof d!="string"||!uc(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const h of m){if(!uc(h))continue;const v=typeof h.id=="string"?h.id:null;if(!v)continue;const x=pw(v);x!==null&&(a=Math.max(a,x));const g=typeof h.terminalSessionId=="string"||h.terminalSessionId===null?h.terminalSessionId:null,w=h.lifecycle,y=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:v,label:typeof h.label=="string"?h.label:"Terminal",iconKey:typeof h.iconKey=="string"?h.iconKey:null,terminalSessionId:g,lifecycle:y,createdAt:typeof h.createdAt=="number"?h.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const f=typeof p.activeTabId=="string"?p.activeTabId:null,b=f?u.some(h=>h.id===f):!1;r.set(d,{tabs:u,activeTabId:b?f:u[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,o=Math.max(e.nextTabId,i,a+1);return{...e,sessions:r,nextChunkId:1,nextTabId:o,hasHydrated:!0}}})));if(typeof window<"u"&&!em){em=!0;const t=rn.persist,e=()=>{rn.getState().hasHydrated||rn.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const tm=(t,e)=>e.updatedAtMs-t.updatedAtMs,Ys=nr((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([_x(),xu()]),a={};for(const i of r.sort(tm))a[i.id]=i;e().listenerReady||await zx(i=>{t(o=>({statusesById:{...o.statusesById,[i.id]:i}}))}),t({instances:n.instances,statusesById:a,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await Bx();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await xu(),r={};for(const a of n.sort(tm))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 $x({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=Vx(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await gu(n).catch(()=>{});const r=e().instances.filter(a=>a.id!==n);await e().setInstances(r),t(a=>{const i={...a.statusesById};return delete i[n],{statusesById:i}})},connect:async n=>{t({error:null});try{await Lx(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},disconnect:async n=>{t({error:null});try{await gu(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>t({error:null})})),Ih=[{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"}],Ho=Object.fromEntries(Ih.map(t=>[t.key,t.Icon])),sd="openchamber:project-actions-updated",Ph=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},sa=(t,e)=>`${Ph(t)}::${e}`,yw=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},sm=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},vw=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=sm(e.localPort),r=sm(e.remotePort);if(!n||!r)return null;const a=yw(e.localHost||t.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),o=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${o} - ${a}:${n} -> ${i}:${r}`,url:`http://${a}:${n}`}},Ah=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=vw(n,r);a&&e.push(a)}return e},ww=(t,e)=>{const n=(t||"").trim();return n&&Ah(e).find(i=>i.id===n)?.url||null},jw=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Nw=["dev","start","preview","serve"];async function Sw(t,e,n){if(!t)return null;const r=Iw(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=Pw(n);if(a){const i=await Aw(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 kw(t)){const a=await Cw(),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 kw(t){const e=`${t}/index.html`,n=await ul(e);return typeof n=="string"&&n.trim().length>0}async function Cw(){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 Iw(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Nw.some(a=>n.includes(a)))return e}return null}function Pw(t){for(const{pattern:e}of jw)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Aw(t){const e=await ul(`${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 ul(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function ul(t){const e=sr()?.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 Dw(t){try{const e=await ul(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const Tw=t=>new Promise(e=>{window.setTimeout(e,t)}),Mw="\x1B",Ew=new RegExp(`${Mw}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Rw=/https?:\/\/[^\s<>'"`]+/gi,or="__openchamber_auto_discover_preview__",Fw=15e3,Ow=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},Lw=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}},$w=t=>{const n=t.replace(Ew,"").match(Rw);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const a=[];for(const i of r)try{const o=new URL(i);o.port&&o.port.length>0&&a.push({raw:i,parsed:o})}catch{}if(a.length>0){const i=o=>{const{parsed:c}=o,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,f=m==="/"||m==="",b=!!(c.search||c.hash);let h=0;return p&&(h+=50),f&&(h+=30),h-=Math.min(u*5,20),b&&(h-=10),h};return a.sort((o,c)=>i(c)-i(o)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},Bw=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const a=r[0],i=r[1].slice(0,3),o=`${a} ${i}`.trim();return r.length>2||o.length<n.length?`${o}...`:o}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},nm=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=pt(),{terminal:o,runtime:c}=On(),{isMobile:d}=nn(),p=l.useMemo(()=>dn(),[]),m=Ys(Y=>Y.instances),u=Ys(Y=>Y.load),f=De(Y=>Y.setBottomTerminalOpen),b=De(Y=>Y.setActiveMainTab),h=De(Y=>Y.setSettingsPage),v=De(Y=>Y.setSettingsDialogOpen),x=De(Y=>Y.setSettingsProjectsSelectedId),g=De(Y=>Y.openContextPreview),w=rn(Y=>Y.sessions),y=rn(Y=>Y.ensureDirectory),k=rn(Y=>Y.setTabLabel),A=rn(Y=>Y.setTabIconKey),j=rn(Y=>Y.setActiveTab),S=rn(Y=>Y.setConnecting),D=rn(Y=>Y.setTabSessionId),E=rn(Y=>Y.setTabPreviewUrl),P=rn(Y=>Y.projectActionRuns),C=rn(Y=>Y.setProjectActionRun),N=rn(Y=>Y.updateProjectActionRunStatus),T=rn(Y=>Y.removeProjectActionRun),[M,F]=l.useState([]),[_,B]=l.useState(null),[V,$]=l.useState(!1),z=l.useRef({}),Q=l.useRef({}),L=l.useRef({}),J=l.useRef({}),ee=l.useRef(0),re=t?.id??null,q=t?.path??"",ce=l.useMemo(()=>re?{id:re,path:q}:null,[re,q]);l.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const ae=l.useCallback(async Y=>{await Zn(Y)},[]),R=l.useCallback(async()=>{if(!ce)return;const Y=ee.current+1;ee.current=Y,$(!0);try{const ke=await qc(ce);if(ee.current!==Y)return;const Be=ke.actions;F(Be),B(Ce=>Ce===or||Ce&&Be.some(ge=>ge.id===Ce)?Ce:null)}catch{if(ee.current!==Y)return}finally{ee.current===Y&&$(!1)}},[ce]),U=l.useMemo(()=>Ph(e||ce?.path||""),[e,ce?.path]),W=l.useMemo(()=>_?M.find(Y=>Y.id===_)??null:null,[M,_]),Z=l.useMemo(()=>({id:or,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),K=!d,ie=l.useMemo(()=>K?[Z,...M]:M,[M,Z,K]);l.useEffect(()=>{R()},[R]),l.useEffect(()=>{if(typeof window>"u")return;const Y=ke=>{const Be=ke.detail;re&&(Be?.projectId&&Be.projectId!==re||R())};return window.addEventListener(sd,Y),()=>{window.removeEventListener(sd,Y)}},[R,re]),l.useEffect(()=>{_&&(_===or&&K||M.some(Y=>Y.id===_)||B(null))},[M,K,_]),l.useEffect(()=>{for(const[Y,ke]of Object.entries(P)){const Ce=w.get(ke.directory)?.tabs.find(ge=>ge.id===ke.tabId);(!Ce||Ce.terminalSessionId!==ke.sessionId)&&T(Y)}},[P,T,w]),l.useEffect(()=>{for(const[Y,ke]of Object.entries(P)){const Be=Q.current[Y]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};Q.current[Y]=Be;const Ce=ie.find(de=>de.id===ke.actionId);if(!Ce)continue;const O=w.get(ke.directory)?.tabs.find(de=>de.id===ke.tabId);if(!O||!Array.isArray(O.bufferChunks)||O.bufferChunks.length===0)continue;const X=O.bufferChunks.filter(de=>Be.lastSeenChunkId===null?!0:de.id>Be.lastSeenChunkId);if(X.length===0)continue;const G=X.map(de=>de.data).join(""),Te=`${Be.tail}${G}`,le=!Be.openedUrl&&Ce.autoOpenUrl===!0?$w(Te):null,We=X[X.length-1]?.id??Be.lastSeenChunkId;if(Be.lastSeenChunkId=We,Be.tail=Te.slice(-512),le)if(Be.openedUrl=!0,Be.openInPreview){const de=P[Y];de&&(E(de.directory,de.tabId,le,{locked:!1,autoOpened:!1}),de.status==="waiting-for-preview"&&N(Y,"running"),window.clearTimeout(J.current[Y]),delete J.current[Y],g(de.directory,le))}else ae(le),H.success(i("projectActions.toast.openedUrlFromOutput"));Q.current[Y]=Be}for(const Y of Object.keys(Q.current))P[Y]||(delete Q.current[Y],window.clearTimeout(J.current[Y]),delete J.current[Y])},[ie,g,ae,P,E,i,w,N]);const Ne=l.useCallback(async(Y,ke={})=>{if(!U)throw new Error(i("projectActions.error.noActiveDirectory"));const Be=sa(U,Y.id);y(U);const Ce=rn.getState(),ge=Ce.getDirectoryState(U);let O=z.current[Be]||null;const X=O?!!ge?.tabs.some(le=>le.id===O):!1;(!O||!X)&&(O=Ce.createTab(U),z.current[Be]=O),k(U,O,`Action: ${Y.name}`),A(U,O,Y.icon||"play"),ke.revealTerminal!==!1&&(j(U,O),f(!0),b("terminal"));const Te=rn.getState().getDirectoryState(U)?.tabs.find(le=>le.id===O);return{key:Be,tabId:O,sessionId:Te?.terminalSessionId??null}},[y,U,b,j,f,A,k,i]),ne=l.useCallback(async Y=>{if(c.isVSCode||!a&&d)return;if(!U){H.error(i("projectActions.error.noActiveDirectoryForAction"));return}const ke=sa(U,Y.id),Be=P[ke];if(!(Be&&Be.status==="running"))try{const Ce=Y.id===or?await(async()=>{const[Oe,Ye]=await Promise.all([qc({id:ce?.id??"",path:U}),Dw(U)]),Ge=await Sw(U,Oe.actions,Ye);if(!Ge)throw new Error(i("contextPanel.preview.noDevServer"));return{id:or,name:i("projectActions.actions.autoDiscover"),command:Ge.command,icon:"search",autoOpenUrl:!0,openUrl:Ge.previewUrlHint||""}})():Y,ge=Ce.autoOpenUrl===!0&&(Ce.openUrl||"").trim().length>0,{key:O,tabId:X,sessionId:G}=await Ne(Ce,{revealTerminal:!ge&&Y.id!==or});let Te=G,le=!1;if(!Te){S(U,X,!0);try{Te=(await o.createSession({cwd:U})).sessionId,le=!0,D(U,X,Te)}finally{S(U,X,!1)}}if(!Te)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));le&&await Tw(350),Ce.id===or&&(L.current[O]?.(),S(U,X,!0),L.current[O]=Rx(Te,Oe=>{Oe.type==="data"&&typeof Oe.data=="string"&&Oe.data.length>0&&rn.getState().appendToBuffer(U,X,Oe.data),Oe.type==="exit"&&(rn.getState().setTabLifecycle(U,X,"exited"),rn.getState().setConnecting(U,X,!1),rn.getState().removeProjectActionRun(O),delete Q.current[O],L.current[O]?.(),delete L.current[O],window.clearTimeout(J.current[O]),delete J.current[O])},()=>{rn.getState().setConnecting(U,X,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const We=Ce.autoOpenUrl===!0&&p&&(Ce.desktopOpenSshForward||"").trim().length>0,de=Ce.autoOpenUrl?Lw(Ce.openUrl):null,Fe=Ce.autoOpenUrl&&p?ww(Ce.desktopOpenSshForward,m):null;C({key:O,directory:U,actionId:Ce.id,tabId:X,sessionId:Te,status:Ce.id===or&&!de?"waiting-for-preview":"running"}),window.clearTimeout(J.current[O]),delete J.current[O],Ce.id===or&&!de&&(J.current[O]=window.setTimeout(()=>{rn.getState().updateProjectActionRunStatus(O,"running"),delete J.current[O]},Fw)),Fe?(E(U,X,null,{locked:!0}),ae(Fe),H.success(i("projectActions.toast.openedForwardedUrl"))):de?(E(U,X,de,{locked:!0,autoOpened:!0}),g(U,de),H.success(i("projectActions.toast.openedActionUrl"))):ge?(E(U,X,null,{locked:!0}),H.error(i("projectActions.error.invalidCustomUrlFormat"))):We?(E(U,X,null,{locked:!0}),H.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):E(U,X,null,{locked:!1,autoOpened:!1}),Q.current[O]={lastSeenChunkId:null,openedUrl:!!Fe||!!de||ge,tail:"",openInPreview:Ce.id===or};const rt=Ow(Ce.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
-
`));await o.sendInput(Te,`${rt}\r`)}catch(Ce){T(ke),delete Q.current[ke],L.current[ke]?.(),delete L.current[ke],window.clearTimeout(J.current[ke]),delete J.current[ke],H.error(Ce instanceof Error?Ce.message:i("projectActions.error.failedToRunAction"))}},[m,Ne,a,d,p,U,ae,g,P,c.isVSCode,T,S,C,E,D,ce?.id,i,o]),fe=l.useCallback(async Y=>{const ke=sa(U,Y.id),Be=P[ke];if(!Be)return;N(ke,"stopping");try{await o.sendInput(Be.sessionId,"")}catch{}if(await new Promise(O=>{window.setTimeout(O,1e3)}),rn.getState().getDirectoryState(Be.directory)?.tabs.find(O=>O.id===Be.tabId)?.terminalSessionId===Be.sessionId){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:Be.sessionId})}catch{}else try{await o.close(Be.sessionId)}catch{}D(Be.directory,Be.tabId,null)}T(ke),delete Q.current[ke],L.current[ke]?.(),delete L.current[ke],window.clearTimeout(J.current[ke]),delete J.current[ke]},[U,P,T,D,o,N]),pe=l.useCallback(()=>{const Y=W??ie[0];if(!Y)return;const ke=sa(U,Y.id),Be=P[ke];if(Be?.status!=="stopping"){if(Be){fe(Y);return}ne(Y)}},[ie,U,ne,P,W,fe]),je=l.useCallback((Y,ke=!1)=>{if(B(Y.id),!ke){ne(Y);return}const Be=sa(U,Y.id),Ce=P[Be];if(Ce?.status!=="stopping"){if(Ce){fe(Y);return}ne(Y)}},[U,ne,P,fe]),oe=l.useCallback(()=>{ce?.id&&(x(ce.id),h("projects"),v(!0))},[v,h,x,ce?.id]);if(c.isVSCode||!a&&d||!ce||!U)return null;const Se=W??ie[0]??null;if(!Se)return null;const se=Se.icon||"play",we=Se.id===or?"search":Ho[se]||"play",Ae=Bw(Se.name,i("projectActions.label.fallbackAction")),ve=sa(U,Se.id),ye=P[ve],Ie=ye?.status==="stopping",he=ye?.status==="waiting-for-preview",me=ye?w.get(ye.directory)?.tabs.find(Y=>Y.id===ye.tabId)?.previewUrl??null:null,Ee=!!(ye&&me),Ve=()=>{!ye||!me||g(ye.directory,me)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:V||Ie,className:ue("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:pe,"aria-label":ye?i("projectActions.actions.stopNamedAria",{name:Se.name}):i("projectActions.actions.runNamedAria",{name:Se.name}),children:Ie||he?s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):ye?s.jsx(I,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(I,{name:we,className:"h-5 w-5"})}),Ee?s.jsxs(St,{children:[s.jsx(kt,{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:Ve,children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(Ct,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Rs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:oe,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Cn,{}),ie.map(Y=>{const ke=Y.icon||"play",Be=Y.id===or?"search":Ho[ke]||"play",Ce=sa(U,Y.id),ge=P[Ce],O=!!ge,X=ge?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{je(Y,!0)},children:[s.jsx(I,{name:Be,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Y.name}),X||ge?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):O?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},Y.id)})]})]})]}):s.jsxs("div",{className:ue("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:pe,disabled:V||Ie,className:ue("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":ye?i("projectActions.actions.stopNamedAria",{name:Se.name}):i("projectActions.actions.runNamedAria",{name:Se.name}),children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:Ie||he?s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):ye?s.jsx(I,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(I,{name:we,className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:Ae})]}),Ee?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ve,className:ue(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(Ct,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:ue(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Rs,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:oe,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Cn,{}),ie.map(Y=>{const ke=Y.icon||"play",Be=Y.id===or?"search":Ho[ke]||"play",Ce=sa(U,Y.id),ge=P[Ce],O=!!ge,X=ge?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{je(Y)},children:[s.jsx(I,{name:Be,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Y.name}),X||ge?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):O?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},Y.id)})]})]})]})},Fl="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",_w="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",Ci=l.memo(function(e){const n=ot.c(13),{visible:r,title:a,ariaLabel:i,onClick:o,className:c,Icon:d,iconClassName:p}=e;if(!(r===void 0?!0:r))return null;const u=c??Fl,f=p??"h-[18px] w-[18px]";let b;n[0]!==d||n[1]!==f?(b=s.jsx(I,{name:d,className:f}),n[0]=d,n[1]=f,n[2]=b):b=n[2];let h;n[3]!==i||n[4]!==o||n[5]!==u||n[6]!==b?(h=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,"aria-label":i,className:u,children:b})}),n[3]=i,n[4]=o,n[5]=u,n[6]=b,n[7]=h):h=n[7];let v;n[8]!==a?(v=s.jsx(Ct,{children:s.jsx("p",{children:a})}),n[8]=a,n[9]=v):v=n[9];let x;return n[10]!==h||n[11]!==v?(x=s.jsxs(St,{children:[h,v]}),n[10]=h,n[11]=v,n[12]=x):x=n[12],x}),zw=l.memo(function(e){const n=ot.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:o,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=pt();if(!a?.connected||r)return null;if(i.length>1){let h;n[0]===Symbol.for("react.memo_cache_sentinel")?(h=ue(Fl,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=h):h=n[0];let v;n[1]!==c||n[2]!==m?(v=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=v):v=n[3];let x;n[4]!==o||n[5]!==c||n[6]!==m?(x=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=o,n[5]=c,n[6]=m,n[7]=x):x=n[7];let g;n[8]!==d||n[9]!==v||n[10]!==x?(g=s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:h,title:v,disabled:d,children:x})}),n[8]=d,n[9]=v,n[10]=x,n[11]=g):g=n[11];let w;n[12]!==m?(w=m("header.github.accountsTitle"),n[12]=m,n[13]=w):w=n[13];let y;n[14]!==w?(y=s.jsx(zi,{className:"typography-ui-header font-semibold text-foreground",children:w}),n[14]=w,n[15]=y):y=n[15];let k;n[16]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(Cn,{}),n[16]=k):k=n[16];let A;if(n[17]!==i||n[18]!==p||n[19]!==d||n[20]!==m){let D;n[22]!==p||n[23]!==d||n[24]!==m?(D=E=>{const P=E.user,C=!!E.current;return s.jsxs($t,{className:"gap-2",disabled:C||d,onSelect:()=>{C||p(E.id)},children:[P?.avatarUrl?s.jsx("img",{src:P.avatarUrl,alt:P.login?m("header.github.avatarWithLogin",{login:P.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(I,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:P?.name?.trim()||P?.login||"GitHub"}),P?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:P.login}):null]}),C?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},E.id)},n[22]=p,n[23]=d,n[24]=m,n[25]=D):D=n[25],A=i.map(D),n[17]=i,n[18]=p,n[19]=d,n[20]=m,n[21]=A}else A=n[21];let j;n[26]!==y||n[27]!==A?(j=s.jsxs(Rs,{align:"end",className:"w-64",children:[y,k,A]}),n[26]=y,n[27]=A,n[28]=j):j=n[28];let S;return n[29]!==g||n[30]!==j?(S=s.jsxs(Fs,{children:[g,j]}),n[29]=g,n[30]=j,n[31]=S):S=n[31],S}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let f;n[35]!==o||n[36]!==c||n[37]!==m?(f=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=o,n[36]=c,n[37]=m,n[38]=f):f=n[38];let b;return n[39]!==u||n[40]!==f?(b=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:u,children:f}),n[39]=u,n[40]=f,n[41]=b):b=n[41],b}),Vw=l.memo(function(e){const n=ot.c(76),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:o,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:f,servicesTabItems:b,quotaLastUpdated:h,quotaDisplayMode:v,quotaDisplayTabItems:x,handleDisplayModeChange:g,handleUsageRefresh:w,isQuotaLoading:y,isUsageRefreshSpinning:k,hasRateLimits:A,rateLimitGroups:j,expandedFamilies:S,toggleFamilyExpanded:D,shortcutLabel:E,showDevShutdown:P,isDevShutdownInFlight:C,onDevShutdown:N}=e,{t:T}=pt();let M;n[0]!==p||n[1]!==f||n[2]!==u||n[3]!==d||n[4]!==c?(M=Z=>{c(Z),Z&&(d(),p==="usage"&&u===0&&f())},n[0]=p,n[1]=f,n[2]=u,n[3]=d,n[4]=c,n[5]=M):M=n[5];let F;n[6]!==a||n[7]!==r||n[8]!==T?(F=r?T("header.services.openWithCurrent",{current:a}):T("header.services.open"),n[6]=a,n[7]=r,n[8]=T,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 B;n[10]!==_?(B=ue(Fl,_),n[10]=_,n[11]=B):B=n[11];let V;n[12]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(I,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=V):V=n[12];let $;n[13]!==i||n[14]!==r?($=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=$):$=n[15];let z;n[16]!==F||n[17]!==B||n[18]!==$?(z=s.jsx(kt,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":F,className:B,children:[V,$]})})}),n[16]=F,n[17]=B,n[18]=$,n[19]=z):z=n[19];let Q;n[20]!==a||n[21]!==r||n[22]!==E||n[23]!==T?(Q=r?T("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}):T("header.services.tooltip.servicesWithShortcuts",{toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}),n[20]=a,n[21]=r,n[22]=E,n[23]=T,n[24]=Q):Q=n[24];let L;n[25]!==Q?(L=s.jsx(Ct,{children:s.jsx("p",{children:Q})}),n[25]=Q,n[26]=L):L=n[26];let J;n[27]!==z||n[28]!==L?(J=s.jsxs(St,{children:[z,L]}),n[27]=z,n[28]=L,n[29]=J):J=n[29];let ee;n[30]!==f||n[31]!==u||n[32]!==m?(ee=Z=>{const K=Z;m(K),K==="usage"&&u===0&&f()},n[30]=f,n[31]=u,n[32]=m,n[33]=ee):ee=n[33];let re;n[34]!==p||n[35]!==b||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(Er,{items:b,activeId:p,onSelect:ee,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=p,n[35]=b,n[36]=ee,n[37]=re):re=n[37];let q;n[38]!==p||n[39]!==r||n[40]!==o||n[41]!==c?(q=r&&p==="instance"?s.jsx(Ux,{embedded:!0,open:o&&p==="instance",onOpenChange:Kw,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=o,n[41]=c,n[42]=q):q=n[42];let ce;n[43]!==p||n[44]!==o?(ce=p==="mcp"?s.jsx(kh,{active:o&&p==="mcp"}):null,n[43]=p,n[44]=o,n[45]=ce):ce=n[45];let ae;n[46]!==p||n[47]!==S||n[48]!==g||n[49]!==w||n[50]!==A||n[51]!==y||n[52]!==k||n[53]!==v||n[54]!==x||n[55]!==h||n[56]!==j||n[57]!==T||n[58]!==D?(ae=p==="usage"?s.jsxs("div",{className:"overflow-x-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5",children:[s.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:T("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Dh(h)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Er,{items:x,activeId:v,onSelect:Z=>{g(Z)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:ue("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:w,disabled:y||k,"aria-label":T("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:ue("h-4 w-4",k&&"animate-spin")})})]})]}),A?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:T("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:j.map((Z,K)=>{const ie=S[Z.providerId]??[];return s.jsxs(l.Fragment,{children:[K>0?s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(xn,{providerId:Z.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Z.providerName})]}),Z.entries.length===0&&(!Z.modelFamilies||Z.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Z.error??T("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Z.entries.map(Ne=>{const[ne,fe]=Ne,pe=v==="remaining"?fe.remainingPercent:fe.usedPercent,je=to(fe.usedPercent,fe.resetAt,fe.windowSeconds,ne),oe=je?.dailyAllocationPercent!=null?v==="remaining"?100-Kr(je.elapsedRatio):Kr(je.elapsedRatio):null,Se=eo(fe.valueLabel,pe),se=Wd(fe.resetAt,fe.resetAfterFormatted??fe.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:Kd(ne)}),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:Se==="-"?"":Se})]}),s.jsx(no,{percent:pe,tonePercent:fe.usedPercent,className:"h-1.5",expectedMarkerPercent:oe}),je?s.jsx(ro,{paceInfo:je,compact:!0}):null]},`${Z.providerId}-${ne}`)}),Z.modelFamilies&&Z.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:Z.modelFamilies.map(Ne=>{const ne=Ne.familyId??"other",fe=ie.includes(ne);return s.jsxs(pr,{open:fe,onOpenChange:()=>D(Z.providerId,ne),children:[s.jsxs(Nr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Ne.familyLabel}),fe?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(fr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Ne.models.map(pe=>{const[je,oe]=pe,Se=v==="remaining"?oe.remainingPercent:oe.usedPercent,se=to(oe.usedPercent,oe.resetAt,oe.windowSeconds),we=se?.dailyAllocationPercent!=null?v==="remaining"?100-Kr(se.elapsedRatio):Kr(se.elapsedRatio):null,Ae=eo(oe.valueLabel,Se);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:cl(je)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ae==="-"?"":Ae})]}),s.jsx(no,{percent:Se,tonePercent:oe.usedPercent,className:"h-1.5",expectedMarkerPercent:we}),se?s.jsx(ro,{paceInfo:se,compact:!0}):null]},`${Z.providerId}-${je}`)})})})]},ne)})}):null]})]},Z.providerId)})})]}):null,n[46]=p,n[47]=S,n[48]=g,n[49]=w,n[50]=A,n[51]=y,n[52]=k,n[53]=v,n[54]=x,n[55]=h,n[56]=j,n[57]=T,n[58]=D,n[59]=ae):ae=n[59];let R;n[60]!==C||n[61]!==N||n[62]!==P||n[63]!==T?(R=P?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx($t,{disabled:C,onSelect:()=>{N()},children:T("header.services.shutdownDev")})})]}):null,n[60]=C,n[61]=N,n[62]=P,n[63]=T,n[64]=R):R=n[64];let U;n[65]!==re||n[66]!==q||n[67]!==ce||n[68]!==ae||n[69]!==R?(U=s.jsxs(Rs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[re,q,ce,ae,R]}),n[65]=re,n[66]=q,n[67]=ce,n[68]=ae,n[69]=R,n[70]=U):U=n[70];let W;return n[71]!==o||n[72]!==M||n[73]!==J||n[74]!==U?(W=s.jsxs(Fs,{open:o,onOpenChange:M,children:[J,U]}),n[71]=o,n[72]=M,n[73]=J,n[74]=U,n[75]=W):W=n[75],W}),Uw=(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??""),Ww=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],a=n[1].slice(0,3),i=`${r} ${a}`.trim();return n.length>2||i.length<e.length?`${i}...`:i}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},Dh=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},lr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},ko=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,rm=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:a=null})=>{const{t:i}=pt(),o=De(Le=>Le.setSessionSwitcherOpen),c=De(Le=>Le.toggleSidebar),d=De(Le=>Le.isSidebarOpen),p=De(Le=>Le.isRightSidebarOpen),m=De(Le=>Le.toggleBottomTerminal),u=De(Le=>Le.toggleRightSidebar),f=De(Le=>Le.openContextOverview),b=De(Le=>Le.openContextPlan),h=De(Le=>Le.openContextBrowser),v=De(Le=>Le.closeContextPanel),x=De(Le=>Le.contextPanelByDirectory),g=De(Le=>Le.activeMainTab),w=De(Le=>Le.setActiveMainTab),y=De(Le=>Le.shortcutOverrides),k=vt(Le=>Le.getCurrentModel),A=On(),[j,S]=l.useState(!1),D=Lt(Le=>Le.getContextUsage),E=Lt(Le=>Le.openNewSessionDraft),P=Lt(Le=>!!Le.newSessionDraft?.open),C=Lt(Le=>Le.currentSessionId),N=Wx(C??""),T=Uf(C??null),M=Ia(Le=>Le.activeSessions),F=Ad(),_=Ts(Le=>Le.activeProjectId?Le.projects.find(Tt=>Tt.id===Le.activeProjectId)??null:null),B=l.useMemo(()=>{if(!_)return null;const Le=_.label?.trim();if(Le)return Le;const Tt=_.path.split(/[\\/]/).filter(Boolean);return Tt[Tt.length-1]??null},[_]),V=Ms(Le=>Le.results),$=Ms(Le=>Le.fetchAllQuotas),z=Ms(Le=>Le.isLoading),Q=Ms(Le=>Le.lastUpdated),L=Ms(Le=>Le.displayMode),J=Ms(Le=>Le.dropdownProviderIds),ee=Ms(Le=>Le.loadSettings),re=Ms(Le=>Le.setDisplayMode),{isMobile:q}=nn(),ce=zn(Le=>Le.status),ae=zn(Le=>Le.setStatus),R=l.useRef(null),[U,W]=l.useState(()=>typeof window>"u"?!1:dn()),Z=l.useMemo(()=>Dd(),[]),K=Cl(),[ie,Ne]=l.useState(!1),ne=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),fe=l.useMemo(()=>{if(typeof window>"u")return null;const Le=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Le=="number"&&Number.isFinite(Le)&&Le>0)return Le;if(typeof navigator>"u")return null;const Tt=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Tt)return null;const Qt=Number.parseInt(Tt[1],10),cs=Number.parseInt(Tt[2],10);return Number.isNaN(Qt)?null:Qt===10?cs:Qt},[]);$e.useEffect(()=>{typeof window>"u"||W(dn())},[]);const pe=k(),je=pe&&typeof pe.limit=="object"&&pe.limit!==null?pe.limit:null,oe=je&&typeof je.context=="number"?je.context:0,Se=je&&typeof je.output=="number"?je.output:0,se=D(oe,Se),[we,Ae]=l.useState(null),ve=!C||N;$e.useEffect(()=>{if(!C){Ae(Le=>Le===null?Le:null);return}if(se&&se.totalTokens>0){Ae(Le=>Uw(Le,se)?Le:se);return}ve&&Ae(Le=>Le===null?Le:null)},[se,C,ve]);const ye=De(Le=>Le.isSessionSwitcherOpen),Ie=ce?.connected?ce.user?.avatarUrl??null:null,he=ce?.connected?ce.user?.login??null:null,me=ce?.accounts??[],[Ee,Ve]=l.useState(!1),[Y,ke]=l.useState(!1),[Be,Ce]=l.useState(!1),[ge,O]=l.useState(!1),[X,G]=l.useState("Local"),Te=l.useMemo(()=>Ww(X),[X]),[le,We]=l.useState(U?"instance":"usage"),[de,Fe]=l.useState("usage");$e.useEffect(()=>{!U&&le==="instance"&&We("usage")},[le,U]);const rt=l.useMemo(()=>ln(),[]),Oe=l.useMemo(()=>q?typeof t=="function"?!!n:ye:d,[q,ye,d,n,t]),Ye=!rt&&g==="chat"&&!!we&&we.totalTokens>0,Ge=we&&we.contextLimit>0?Math.min(999,we.totalTokens/we.contextLimit*100):0,it=l.useCallback(async()=>{if(!(typeof window>"u"||!U))try{const Le=await Kx(),Tt=window.location.href,Qt=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(bu(Tt,Qt)){G("Local");return}const cs=Le.hosts.find(Gs=>bu(Tt,Gs.url));if(cs?.label?.trim()){G(Hx(cs.label.trim()));return}G("Instance")}catch{G("Local")}},[U]);$e.useEffect(()=>{it()},[it]),Nh();const Qe=Ms(Le=>Le.selectedModels),at=Ms(Le=>Le.expandedFamilies),nt=Ms(Le=>Le.toggleFamilyExpanded),be=l.useMemo(()=>{const Le=[];for(const Tt of Or){if(!J.includes(Tt.id))continue;const Qt=V.find(Hs=>Hs.providerId===Tt.id),cs=Qt?.usage?.windows??{},Gs=Qt?.usage?.models,Ks=Object.entries(cs),bs={providerId:Tt.id,providerName:Tt.name,entries:Ks,error:Qt&&!Qt.ok&&Qt.configured?Qt.error:void 0};if(Gs&&Object.keys(Gs).length>0){const Hs=Qe[Tt.id]??[],on=Hs.length>0,rr=Bv(Gs,Tt.id),Dn=wh(Tt.id),Wn=jh(Dn);bs.modelFamilies=[];for(const Pn of Wn){const Kn=rr.get(Pn.id)??[];if(Kn.length===0)continue;const un=on?Kn.filter(jn=>Hs.includes(jn)):Kn;if(un.length===0)continue;const Hn=[];for(const jn of un){const Fr=Gs[jn];if(Fr?.windows){const ar=Object.entries(Fr.windows);ar.length>0&&Hn.push([jn,ar[0][1]])}}Hn.length>0&&bs.modelFamilies.push({familyId:Pn.id,familyLabel:Pn.label,models:Hn})}const $r=rr.get(null)??[],Ir=on?$r.filter(Pn=>Hs.includes(Pn)):$r;if(Ir.length>0){const Pn=[];for(const Kn of Ir){const un=Gs[Kn];if(un?.windows){const Hn=Object.entries(un.windows);Hn.length>0&&Pn.push([Kn,Hn[0][1]])}}Pn.length>0&&bs.modelFamilies.push({familyId:null,familyLabel:i("header.services.modelFamily.other"),models:Pn})}}(Ks.length>0||bs.modelFamilies&&bs.modelFamilies.length>0||bs.error)&&Le.push(bs)}return Le},[J,V,Qe,i]),He=be.length>0;l.useEffect(()=>{ee()},[ee]);const _e=l.useCallback(async Le=>{re(Le);try{await Is({usageDisplayMode:Le})}catch(Tt){console.warn("Failed to update usage display mode:",Tt)}},[re]),tt=l.useCallback(()=>{if(ge)return;O(!0);const Le=new Promise(Tt=>setTimeout(Tt,500));Promise.all([$(),Le]).finally(()=>{O(!1)})},[$,ge]),ut=l.useMemo(()=>C?F.find(Le=>Le.id===C)??M.find(Le=>Le.id===C)??T??Gx().find(Le=>Le.id===C)??null:null,[C,T,M,F]),qe=l.useRef(null),[ze,st]=l.useState(0);l.useEffect(()=>{if(!C){qe.current&&(qe.current=null,st(cs=>cs+1));return}if(ut){qe.current={sessionId:C,session:ut,expiresAt:Date.now()+2e3};return}const Le=qe.current;if(!Le||Le.sessionId!==C)return;const Tt=Le.expiresAt-Date.now();if(Tt<=0){qe.current=null,st(cs=>cs+1);return}const Qt=window.setTimeout(()=>{qe.current?.sessionId===C&&(qe.current=null),st(cs=>cs+1)},Tt);return()=>{window.clearTimeout(Qt)}},[C,ut]);const yt=(()=>{if(ut)return ut;if(!C)return null;const Le=qe.current;return Le&&Le.sessionId===C&&Le.expiresAt>Date.now()?Le.session:null})(),Mt=Lt(Le=>C?Le.worktreeMetadata.get(C)?.path??"":""),Bt=Lt(Le=>C?Le.worktreeMetadata.get(C)?.branch?.trim()??null:null),ft=Wf(Le=>C?Le.getAttachment(C):void 0),It=l.useMemo(()=>ft?qx(ft):null,[ft]),ss=l.useMemo(()=>ft?ft.legacy?"legacy":ft.degraded?"degraded":ft.worktreeStatus==="missing"?"missing":ft.worktreeStatus==="invalid"?"invalid":ft.attentionReason?"attention":null:null,[ft]),_t=l.useMemo(()=>lr(Mt||""),[Mt]),qt=l.useMemo(()=>{const Le=typeof yt?.directory=="string"?yt.directory:"";return lr(Le||"")},[yt?.directory]),ct=Lt(Le=>Le.newSessionDraft?.open?lr(Le.newSessionDraft.bootstrapPendingDirectory??Le.newSessionDraft.directoryOverride??""):""),jt=l.useMemo(()=>_t||qt||ct,[ct,qt,_t]),as=Lt(Le=>{const Tt=lr(_t||qt||"");if(!Tt)return null;for(const Qt of Le.availableWorktreesByProject.values()){const Gs=Qt.find(Ks=>lr(Ks.path)===Tt)?.branch?.trim();if(Gs)return Gs}return null}),ws=Yx(jt||null)||Bt||as,As=l.useMemo(()=>{if(!C)return B??"OpenChamber";const Le=yt?.title?.trim();return Le&&Le.length>0?Le:"Untitled Session"},[B,yt?.title,C]),Gt=l.useMemo(()=>Kf(yt?.summary),[yt?.summary]),Ke=l.useMemo(()=>Gt||{additions:0,deletions:0},[Gt]),Pt=Ke.additions>0||Ke.deletions>0,Ot=l.useMemo(()=>lr(jt||_?.path||""),[_?.path,jt]),Nt=l.useMemo(()=>_?{id:_.id,path:_.path}:null,[_]),Ht=l.useRef(null);l.useEffect(()=>{!Nt||!Ot||(Ht.current={projectRef:Nt,directory:Ot})},[Ot,Nt]);const ns=l.useMemo(()=>Nt&&Ot?{projectRef:Nt,directory:Ot}:Ht.current,[Ot,Nt]),Ss=Td(Le=>Le.planModeEnabled),fs=Lt(Le=>Le.isSessionPlanAvailable),Os=Ss&&C?fs(C):!1,zs=Os,tn=l.useRef("");l.useEffect(()=>{if(!Ss){De.getState().activeMainTab==="plan"&&De.getState().setActiveMainTab("chat");return}if(!C)return;const Le=`${C||"none"}:${qt||"none"}:${yt?.time?.created||0}:${yt?.slug||"none"}`;tn.current!==Le&&(tn.current=Le),!Os&&De.getState().activeMainTab==="plan"&&De.getState().setActiveMainTab("chat")},[Ss,Os,yt?.slug,yt?.time?.created,C,qt]);const Ds=l.useCallback(async Le=>{if(!(!Le||Ee)){Ve(!0);try{const Tt=A.github?await A.github.authActivate(Le):await(async()=>{const Qt=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Le})}),cs=await Qt.json().catch(()=>null);if(!Qt.ok||!cs)throw new Error(cs?.error||Qt.statusText);return cs})();ae(Tt)}catch(Tt){console.error("Failed to switch GitHub account:",Tt)}finally{Ve(!1)}}},[Ee,A.github,ae]),zt=l.useCallback(()=>{if(typeof document>"u")return;const Le=document.activeElement;if(!Le)return;const Tt=Le.tagName;(Tt==="INPUT"||Tt==="TEXTAREA"||Tt==="SELECT"||Le.isContentEditable)&&Le.blur()},[]),Kt=l.useCallback(()=>{if(q){zt(),o(!ye);return}c()},[zt,q,ye,o,c]),te=l.useCallback(()=>{w("chat"),o(!1),E()},[E,w,o]),bt=l.useCallback(()=>{al("desktop_open_draft_mini_chat_window",{directory:lr(jt||_?.path||""),projectId:_?.id??null}).catch(Le=>{console.warn("[header] failed to open draft mini chat window",Le)})},[_?.id,_?.path,jt]),Ze=l.useCallback(()=>{if(P){bt();return}C&&al("desktop_open_session_mini_chat_window",{sessionId:C,directory:lr(jt||_?.path||"")}).catch(Le=>{console.warn("[header] failed to open session mini chat window",Le)})},[_?.path,C,bt,P,jt]),Wt=l.useCallback(()=>{const Le=lr(jt||"");if(!Le)return;const Tt=x[Le];if(ko(Tt)==="context"){v(Le);return}f(Le)},[v,x,f,jt]),es=l.useMemo(()=>{const Le=lr(jt||"");if(!Le)return!1;const Tt=x[Le];return ko(Tt)==="context"},[x,jt]),rs=l.useCallback(()=>{const Le=lr(jt||"");if(!Le)return;const Tt=x[Le];if(ko(Tt)==="plan"){v(Le);return}b(Le)},[v,x,b,jt]),Ue=l.useCallback(()=>{const Le=lr(jt||"");Le&&h(Le)},[h,jt]),xt=l.useMemo(()=>{const Le=lr(jt||"");if(!Le)return!1;const Tt=x[Le];return ko(Tt)==="plan"},[x,jt]),At=Fl,Dt=_w,Zt=l.useMemo(()=>!d&&(U&&ne&&!ie||K)?"pl-[5.5rem]":"pl-3",[U,ie,ne,d,K]);$e.useEffect(()=>{if(!U||!ne){Ne(!1);return}let Le=!1,Tt=null;const Qt=async()=>{try{const{getCurrentWindow:Gs}=await jr(async()=>{const{getCurrentWindow:Hs}=await import("./vendor-.bun-CJSRTa27.js").then(on=>on.bK);return{getCurrentWindow:Hs}},__vite__mapDeps([0,1])),bs=await Gs().isFullscreen();Le||Ne(bs)}catch{Le||Ne(!1)}},cs=async()=>{try{const{getCurrentWindow:Gs}=await jr(async()=>{const{getCurrentWindow:bs}=await import("./vendor-.bun-CJSRTa27.js").then(Hs=>Hs.bK);return{getCurrentWindow:bs}},__vite__mapDeps([0,1]));Tt=await Gs().onResized(()=>{Qt()})}catch{}};return Qt(),cs(),()=>{Le=!0,Tt&&Tt()}},[U,ne]);const Ut=l.useMemo(()=>!U||!ne||fe===null?"":fe>=26?"h-12":fe<=15?"h-14":"",[U,ne,fe]),ks=l.useMemo(()=>{if(!(U||rt))return{paddingLeft:K&&!d?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[U,d,K,rt]),Js=l.useCallback(()=>{if(typeof document>"u")return;const Le=R.current?.getBoundingClientRect().height;Le&&document.documentElement.style.setProperty("--oc-header-height",`${Le}px`)},[]);$e.useEffect(()=>{if(typeof window>"u")return;Js();const Le=R.current;if(!Le||typeof ResizeObserver>"u")return()=>{};let Tt=0;const Qt=()=>{Tt||(Tt=requestAnimationFrame(()=>{Tt=0,Js()}))},cs=new ResizeObserver(Qt);return cs.observe(Le),window.addEventListener("resize",Qt),window.addEventListener("orientationchange",Qt),()=>{Tt&&cancelAnimationFrame(Tt),cs.disconnect(),window.removeEventListener("resize",Qt),window.removeEventListener("orientationchange",Qt)}},[Js]),$e.useEffect(()=>{Js()},[Js,q,Ut]);const Ls=l.useCallback(async Le=>{const Tt=Le.target;Tt.closest(".app-region-no-drag")||Tt.closest("button, a, input, select, textarea")||Le.button===0&&U&&await Hf()},[U]),ts=l.useMemo(()=>{if(q){const Le=[{id:"chat",label:i("layout.mainTab.chat"),icon:"chat-4"}];return zs&&Le.push({id:"plan",label:i("layout.mainTab.plan"),icon:"file-text"}),Le.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"}),Le}return[]},[q,zs,i]),js=l.useCallback(Le=>Il(Wr(Le,y)),[y]);$e.useEffect(()=>{!q&&(g==="git"||g==="terminal"||g==="diff"||g==="files")&&w("chat")},[g,q,w]);const yn=l.useMemo(()=>{const Le=[];return U&&Le.push({value:"instance",label:i("layout.services.instance"),icon:"server"}),Le.push({value:"usage",label:i("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:Jv}),Le},[U,i]),cn=l.useMemo(()=>yn.map(Le=>({id:Le.value,label:Le.label,icon:s.jsx(I,{name:Le.icon,className:"h-3.5 w-3.5"})})),[yn]),Rr=l.useMemo(()=>{if(typeof window>"u"||U||rt)return!1;const Le=window.location.hostname;return Le==="localhost"||Le==="127.0.0.1"||Le==="::1"},[U,rt]),kr=l.useCallback(async()=>{if(j)return;S(!0),Ce(!1);const Le=[];let Tt=!1;try{try{for(const[,Qt]of rn.getState().sessions.entries())for(const cs of Qt.tabs)cs.previewUrl&&Le.push(cs.previewUrl)}catch{}try{await Fx({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Le})})).ok?Tt=!0:Tt=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Tt||S(!1)}},[j,Ce]),Ws=l.useMemo(()=>[{value:"usage",label:i("header.services.used")},{value:"remaining",label:i("header.services.remaining")}],[i]),Ln=l.useMemo(()=>Ws.map(Le=>({id:Le.value,label:Le.label})),[Ws]),Vn=l.useMemo(()=>[{id:"usage",label:i("layout.services.usage"),icon:s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(I,{name:"command",className:"h-3.5 w-3.5"})}],[i]);$e.useEffect(()=>{const Le=Tt=>{if(Md(Tt)&&!Tt.shiftKey&&!Tt.altKey){const Qt=parseInt(Tt.key,10);Qt>=1&&Qt<=ts.length&&(Tt.preventDefault(),w(ts[Qt-1].id))}};return window.addEventListener("keydown",Le),()=>window.removeEventListener("keydown",Le)},[ts,w]),$e.useEffect(()=>{const Le=Tt=>{const Qt=Wr("toggle_services_menu",y);if(Vo(Tt,Qt)){Tt.preventDefault(),Be?Ce(!1):(Ce(!0),it(),le==="usage"&&V.length===0&&$());return}const cs=Wr("cycle_services_tab",y);if(Vo(Tt,cs)){Tt.preventDefault();const Ks=yn.map(rr=>rr.value);if(Ks.length===0)return;const bs=Ks.indexOf(le),Hs=bs===-1?0:(bs+1)%Ks.length,on=Ks[Hs];We(on),Ce(!0),it(),on==="usage"&&V.length===0&&$();return}const Gs=Wr("toggle_context_plan",y);Vo(Tt,Gs)&&(Tt.preventDefault(),rs())};return window.addEventListener("keydown",Le),()=>window.removeEventListener("keydown",Le)},[y,Be,le,yn,V.length,$,it,rs]);const er=Le=>{const Tt=g===Le.id,Qt=Le.icon==="diff",cs=Qt?null:Le.icon,Gs=Le.id==="chat",Ks=Hs=>Qt?s.jsx(Hu,{size:Hs}):cs?s.jsx(I,{name:cs,className:`h-${Hs/4} w-${Hs/4}`}):null,bs=s.jsxs("button",{type:"button",onClick:()=>w(Le.id),className:ue("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Tt?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",Gs&&!q&&"min-w-[100px] justify-center"),"aria-label":Le.label,"aria-selected":Tt,role:"tab",children:[q?Ks(20):s.jsxs(s.Fragment,{children:[Ks(16),s.jsx("span",{className:"header-tab-label",children:Le.label})]}),Le.badge!==void 0&&Le.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Le.badge})]});return s.jsx(l.Fragment,{children:bs},Le.id)},Cr=s.jsxs(s.Fragment,{children:[zs&&s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.openPlanAria"),onClick:rs,className:ue(At,xt&&"bg-[var(--interactive-hover)]"),children:s.jsx(I,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(Ct,{children:s.jsx("p",{children:i("header.actions.planWithShortcut",{shortcut:js("toggle_context_plan")})})})]}),s.jsx(sw,{directory:Ot,className:"mr-1"}),s.jsx(Vw,{isDesktopApp:U,currentInstanceLabel:X,compactCurrentInstanceLabel:Te,isDesktopServicesOpen:Be,setIsDesktopServicesOpen:Ce,refreshCurrentInstanceLabel:it,desktopServicesTab:le,setDesktopServicesTab:We,quotaResultsLength:V.length,fetchAllQuotas:$,servicesTabItems:cn,quotaLastUpdated:Q,quotaDisplayMode:L,quotaDisplayTabItems:Ln,handleDisplayModeChange:_e,handleUsageRefresh:tt,isQuotaLoading:z,isUsageRefreshSpinning:ge,hasRateLimits:He,rateLimitGroups:be,expandedFamilies:at,toggleFamilyExpanded:nt,shortcutLabel:js,showDevShutdown:Rr,isDevShutdownInFlight:j,onDevShutdown:kr}),s.jsx(Ci,{title:i("header.actions.terminalPanelWithShortcut",{shortcut:js("toggle_terminal")}),ariaLabel:i("header.actions.toggleTerminalPanelAria"),onClick:m,Icon:"terminal-box"}),Z?s.jsx(Ci,{title:i("contextPanel.browser.open"),ariaLabel:i("contextPanel.browser.open"),onClick:Ue,Icon:"global"}):null,s.jsx(Ci,{title:i("header.actions.rightSidebarWithShortcut",{shortcut:js("toggle_right_sidebar")}),ariaLabel:i("header.actions.toggleRightSidebarAria"),onClick:u,Icon:"layout-right"}),s.jsx(zw,{isMobile:q,githubAuthStatus:ce,githubAccounts:me,githubAvatarUrl:Ie,githubLogin:he,isSwitchingGitHubAccount:Ee,handleGitHubAccountSwitch:Ds})]}),Un=!p||!a,In=Z&&(P||!!C),an=()=>s.jsxs("div",{onMouseDown:Ls,className:ue("app-region-drag relative flex h-12 select-none items-center pr-3",Zt,Ut),style:ks,role:"tablist","aria-label":i("header.navigation.mainAria"),children:[s.jsx(Ci,{visible:!d,title:i("header.actions.openSessionsWithShortcut",{shortcut:js("toggle_sidebar")}),ariaLabel:i("header.actions.openSessionsAria"),onClick:Kt,className:`${At} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:ue("flex min-w-0 flex-1 items-center",!d&&"pl-3"),children:[Oe?null:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.newSessionAria"),onClick:te,className:ue(At,"mr-6 shrink-0"),children:s.jsx(I,{name:"chat-new",className:"h-[18px] w-[18px]"})})}),s.jsx(Ct,{children:s.jsx("p",{children:i("header.actions.newSessionWithShortcut",{shortcut:js("new_chat")})})})]}),ns&&s.jsx(nm,{projectRef:ns.projectRef,directory:ns.directory,className:"mr-2"}),s.jsx(Jx,{children:s.jsxs("button",{type:"button","aria-label":i("sessions.switcher.openAria"),className:"app-region-no-drag mr-3 flex min-w-0 flex-col items-start rounded-md px-1 py-0.5 -my-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:P?i("sessions.switcher.draftTitle"):As}),B||ws||!P&&(Pt||ss)?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[B?s.jsx("span",{className:"truncate",children:B}):null,ws?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ws})]}):null,!P&&Pt?s.jsxs("span",{className:"inline-flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Ke.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Ke.deletions]})]}):null,!P&&ss?s.jsxs("span",{className:ue("inline-flex min-w-0 items-center gap-0.5",ss==="attention"||ss==="invalid"||ss==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(I,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:It})]}):null]}):null]})}),ts.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:ts.map(Le=>er(Le))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ye&&we?s.jsx(Qx,{totalTokens:we.totalTokens,percentage:Ge,colorPercentage:we.percentage,contextLimit:we.contextLimit,outputLimit:we.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:Wt,pressed:es,className:Un&&!In?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Ci,{visible:In,title:i(P?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:i(P?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Ze,className:ue(At,Un&&Ye?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),Un?Cr:null,!Un&&a?_i.createPortal(Cr,a):null]})]})]}),vn=()=>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:ue(Dt,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":i(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(I,{name:"layout-left",className:"h-5 w-5"})}):ye?s.jsx("button",{type:"button",onClick:()=>o(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":i("header.actions.backAria"),children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Kt,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":i("header.actions.openSessionsAria"),children:s.jsx(I,{name:"play-list-add",className:"h-5 w-5"})}),ye&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:i("header.sessions.title")})]}),!ye&&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:ts.map(Le=>{const Tt=g===Le.id,Qt=Le.icon==="diff",cs=Qt?null:Le.icon;return s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{q&&zt(),w(Le.id)},"aria-label":Le.label,"aria-selected":Tt,role:"tab",className:ue(Dt,"relative rounded-lg",Tt&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Qt?s.jsx(Hu,{className:"h-5 w-5"}):cs?s.jsx(I,{name:cs,className:"h-5 w-5"}):null,Le.badge!==void 0&&Le.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Le.badge}),Le.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":i("header.changes.availableAria")})]})}),s.jsx(Ct,{children:s.jsx("p",{children:Le.label})})]},Le.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[ns&&s.jsx(nm,{projectRef:ns.projectRef,directory:ns.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(Fs,{open:Y,onOpenChange:Le=>{ke(Le),Le&&V.length===0&&$()},children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.services.viewAria"),className:Dt,children:s.jsx(I,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Ct,{children:s.jsx("p",{children:i("header.services.title")})})]}),s.jsx(Rs,{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(Er,{items:Vn,activeId:de,onSelect:Le=>{const Tt=Le;Fe(Tt),Tt==="usage"&&V.length===0&&$()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>ke(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":i("header.services.closeAria"),children:s.jsx(I,{name:"close",className:"h-5 w-5"})})]})}),de==="mcp"&&s.jsx(kh,{active:Y&&de==="mcp"}),de==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:i("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Dh(Q)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>_e("usage"),className:ue("typography-ui-label px-1 pb-0.5 transition-colors",L==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>_e("remaining"),className:ue("typography-ui-label px-1 pb-0.5 transition-colors",L==="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:ue("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:tt,disabled:z||ge,"aria-label":i("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:ue("h-4 w-4",ge&&"animate-spin")})})]})]})}),!He&&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:be.map((Le,Tt)=>s.jsxs(l.Fragment,{children:[Tt>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(xn,{providerId:Le.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Le.providerName})]}),Le.entries.length===0&&(!Le.modelFamilies||Le.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Le.error??i("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Le.entries.map(([Qt,cs])=>{const Gs=L==="remaining"?cs.remainingPercent:cs.usedPercent,Ks=to(cs.usedPercent,cs.resetAt,cs.windowSeconds,Qt),bs=Ks?.dailyAllocationPercent!=null?L==="remaining"?100-Kr(Ks.elapsedRatio):Kr(Ks.elapsedRatio):null,Hs=eo(cs.valueLabel,Gs),on=Wd(cs.resetAt,cs.resetAfterFormatted??cs.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:Kd(Qt)}),on?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:on}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Hs==="-"?"":Hs})]}),s.jsx(no,{percent:Gs,tonePercent:cs.usedPercent,className:"h-1.5",expectedMarkerPercent:bs}),Ks?s.jsx(ro,{paceInfo:Ks,compact:!0}):null]},`${Le.providerId}-${Qt}`)}),Le.modelFamilies&&Le.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Le.modelFamilies.map(Qt=>{const Gs=(at[Le.providerId]??[]).includes(Qt.familyId??"other");return s.jsxs(pr,{open:Gs,onOpenChange:()=>nt(Le.providerId,Qt.familyId??"other"),children:[s.jsxs(Nr,{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:Qt.familyLabel}),Gs?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(fr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Qt.models.map(([Ks,bs])=>{const Hs=L==="remaining"?bs.remainingPercent:bs.usedPercent,on=to(bs.usedPercent,bs.resetAt,bs.windowSeconds),rr=on?.dailyAllocationPercent!=null?L==="remaining"?100-Kr(on.elapsedRatio):Kr(on.elapsedRatio):null,Dn=eo(bs.valueLabel,Hs);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:cl(Ks)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Dn==="-"?"":Dn})]}),s.jsx(no,{percent:Hs,tonePercent:bs.usedPercent,className:"h-1.5",expectedMarkerPercent:rr}),on?s.jsx(ro,{paceInfo:on,compact:!0}):null]},`${Le.providerId}-${Ks}`)})})})]},Qt.familyId??"other")})})]})]},Le.providerId))})]})]})})]}),e?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:ue(Dt,"relative",r&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(I,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Ct,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),wn=ue("header-safe-area relative z-10",q&&"border-b border-border/50","bg-background");return s.jsx("header",{ref:R,className:wn,style:{"--padding-scale":"1"},children:q?vn():an()})};function Kw(){}const am=180,im=640,Hw=110,Gw=t=>{const e=ot.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=pt(),o=De(qw),c=De(Yw),d=De(Jw),p=De(Qw),[m,u]=l.useState(null),[f,b]=l.useState(!1),h=l.useRef(null),v=l.useRef(0),x=l.useRef(o||300),g=Math.min(im,Math.max(am,o||300));let w,y;e[0]!==n?(w=()=>{n||(u(null),b(!1))},y=[n],e[0]=n,e[1]=w,e[2]=y):(w=e[1],y=e[2]),l.useEffect(w,y);let k,A;e[3]!==c||e[4]!==r||e[5]!==n?(k=()=>{if(r||!n||!c)return;const ee=()=>{const ce=h.current?.parentElement?.getBoundingClientRect().height;if(!ce||ce<=0)return;const ae=Math.max(0,Math.round(ce));u(R=>R===ae?R:ae)};ee();const re=h.current?.parentElement;if(!re)return;const q=new ResizeObserver(ee);return q.observe(re),()=>{q.disconnect()}},A=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=k,e[7]=A):(k=e[6],A=e[7]),l.useEffect(k,A);let j,S;if(e[8]!==c||e[9]!==r||e[10]!==f||e[11]!==d||e[12]!==p?(j=()=>{if(r||!f||c)return;const ee=q=>{const ce=v.current-q.clientY,ae=Math.min(im,Math.max(am,x.current+ce));d(ae)},re=()=>{b(!1),De.getState().bottomTerminalHeight<=Hw&&p(!1)};return window.addEventListener("pointermove",ee),window.addEventListener("pointerup",re,{once:!0}),()=>{window.removeEventListener("pointermove",ee),window.removeEventListener("pointerup",re)}},S=[c,r,f,d,p],e[8]=c,e[9]=r,e[10]=f,e[11]=d,e[12]=p,e[13]=j,e[14]=S):(j=e[13],S=e[14]),l.useEffect(j,S),r)return null;const D=n?c?Math.max(0,m??g):g:0,E=n&&c;let P;e[15]!==D||e[16]!==c||e[17]!==n?(P=ee=>{!n||c||(b(!0),v.current=ee.clientY,x.current=D,ee.preventDefault())},e[15]=D,e[16]=c,e[17]=n,e[18]=P):P=e[18];const C=P,N=E?"absolute inset-x-0 bottom-0 z-40":"relative",T=f?"transition-none":"transition-[height] duration-300 ease-in-out",M=!n&&"border-t-0";let F;e[19]!==M||e[20]!==N||e[21]!==T?(F=ue("flex overflow-hidden border-t border-border bg-sidebar",N,T,M),e[19]=M,e[20]=N,e[21]=T,e[22]=F):F=e[22];let _;e[23]!==D||e[24]!==E?(_=E?{top:"var(--oc-header-height, 48px)"}:{height:`${D}px`,minHeight:`${D}px`,maxHeight:`${D}px`},e[23]=D,e[24]=E,e[25]=_):_=e[25];const B=!n||!c&&D===0;let V;e[26]!==C||e[27]!==c||e[28]!==n||e[29]!==f||e[30]!==i?(V=n&&!c&&s.jsx("div",{className:ue("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",f&&"bg-[var(--interactive-border)]"),onPointerDown:C,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=C,e[27]=c,e[28]=n,e[29]=f,e[30]=i,e[31]=V):V=e[31];const $=!n&&"pointer-events-none select-none opacity-0";let z;e[32]!==$?(z=ue("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",$),e[32]=$,e[33]=z):z=e[33];const Q=!n;let L;e[34]!==a||e[35]!==z||e[36]!==Q?(L=s.jsx("div",{className:z,"aria-hidden":Q,children:a}),e[34]=a,e[35]=z,e[36]=Q,e[37]=L):L=e[37];let J;return e[38]!==F||e[39]!==_||e[40]!==B||e[41]!==V||e[42]!==L?(J=s.jsxs("section",{ref:h,className:F,style:_,"aria-hidden":B,children:[V,L]}),e[38]=F,e[39]=_,e[40]=B,e[41]=V,e[42]=L,e[43]=J):J=e[43],J};function qw(t){return t.bottomTerminalHeight}function Yw(t){return t.isBottomTerminalExpanded}function Jw(t){return t.setBottomTerminalHeight}function Qw(t){return t.setBottomTerminalOpen}const nd=280,om=280,lm=500,Xw=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=pt(),i=De(k=>k.sidebarWidth),o=De(k=>k.setSidebarWidth),[c,d]=l.useState(!1),p=l.useRef(0),m=l.useRef(i||nd),u=l.useRef(null),f=l.useRef(null),b=l.useRef(null),h=l.useCallback(k=>Math.min(lm,Math.max(om,k)),[]),v=l.useCallback(k=>{const A=b.current;A&&A.style.setProperty("--oc-left-sidebar-width",`${k}px`)},[]);if(l.useEffect(()=>{e&&c&&d(!1)},[e,c]),l.useEffect(()=>{c||(u.current=null,f.current=null)},[c]),e)return null;const x=t?Math.min(lm,Math.max(om,i||nd)):0,g=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}f.current=k.pointerId,d(!0),p.current=k.clientX,m.current=x,u.current=x,v(x),k.preventDefault()}},w=k=>{if(e||!c||f.current!==k.pointerId)return;const A=k.clientX-p.current,j=h(m.current+A);u.current!==j&&(u.current=j,v(j))},y=k=>{if(f.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const A=h(u.current??x);f.current=null,u.current=null,d(!1),o(A)};return s.jsxs("aside",{ref:b,className:ue("relative flex h-full overflow-hidden border-r border-border/40","bg-sidebar",c?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-r-0",r),style:{width:"var(--oc-left-sidebar-width)",minWidth:"var(--oc-left-sidebar-width)",maxWidth:"var(--oc-left-sidebar-width)","--oc-left-sidebar-width":`${c?u.current??x:x}px`,overflowX:"clip"},"aria-hidden":!t||x===0,children:[t&&s.jsx("div",{className:ue("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:g,onPointerMove:w,onPointerUp:y,onPointerCancel:y,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:ue("relative z-10 flex h-full flex-col transition-opacity duration-300 ease-in-out",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Qs,{children:n})})})]})},Th=420,cm=400,dm=860,Zw=({isOpen:t,children:e,className:n,onTopActionsHostChange:r})=>{const{t:a}=pt(),i=De(E=>E.rightSidebarWidth),o=De(E=>E.setRightSidebarWidth),c=l.useMemo(()=>dn(),[]),d=l.useMemo(()=>ln(),[]),p=Cl(),[m,u]=l.useState(!1),f=l.useRef(0),b=l.useRef(i||420),h=l.useRef(null),v=l.useRef(null),x=l.useRef(null),g=l.useCallback(E=>Math.min(dm,Math.max(cm,E)),[]),w=l.useCallback(E=>{const P=x.current;P&&P.style.setProperty("--oc-right-sidebar-width",`${E}px`)},[]),y=t?Math.min(dm,Math.max(cm,i||Th)):0,k=E=>{if(t){try{E.currentTarget.setPointerCapture(E.pointerId)}catch{}v.current=E.pointerId,u(!0),f.current=E.clientX,b.current=y,h.current=y,w(y),E.preventDefault()}},A=E=>{if(!m||v.current!==E.pointerId)return;const P=f.current-E.clientX,C=g(b.current+P);h.current!==C&&(h.current=C,w(C))},j=E=>{if(v.current!==E.pointerId)return;try{E.currentTarget.releasePointerCapture(E.pointerId)}catch{}const P=g(h.current??y);v.current=null,h.current=null,u(!1),o(P)};l.useEffect(()=>{m||(h.current=null,v.current=null)},[m]),l.useEffect(()=>{t||r?.(null)},[t,r]);const S=l.useCallback(async E=>{const P=E.target;P.closest(".app-region-no-drag")||P.closest("button, a, input, select, textarea")||E.button===0&&c&&await Hf()},[c]),D=l.useMemo(()=>{if(!(c||d))return{paddingLeft:"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",...p?{paddingTop:"var(--oc-safe-area-top, 0px)"}:null}},[c,p,d]);return s.jsxs("aside",{ref:x,className:ue("relative flex h-full overflow-hidden border-l border-border/40","bg-sidebar",m?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-l-0",n),style:{width:"var(--oc-right-sidebar-width)",minWidth:"var(--oc-right-sidebar-width)",maxWidth:"var(--oc-right-sidebar-width)","--oc-right-sidebar-width":`${m?h.current??y:y}px`,overflowX:"clip"},"aria-hidden":!t||y===0,children:[t?s.jsx("div",{onMouseDown:S,className:ue("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:D,"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:ue("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",m&&"bg-[var(--interactive-border)]"),onPointerDown:k,onPointerMove:A,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:ue("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})]})},e1=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),t1=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=e1.format(t);return e.endsWith(".0")?e.slice(0,-2):e},mo=({providerId:t,modelId:e,onChange:n,className:r,allowedProviderIds:a,placeholder:i})=>{const{t:o}=pt(),{isReady:c,isUnavailable:d}=Gf(),p=vt(R=>R.providers),m=vt(R=>R.modelsMetadata),u=De(R=>R.isMobile),f=De(R=>R.hiddenModels),b=De(R=>R.toggleFavoriteModel),h=De(R=>R.isFavoriteModel),v=De(R=>R.addRecentModel),{favoriteModelsList:x,recentModelsList:g}=qf(),{isMobile:w}=nn(),y=u||w,[k,A]=l.useState(!1),[j,S]=l.useState(new Set),[D,E]=l.useState(!1),[P,C]=l.useState(""),[N,T]=l.useState(0),M=l.useRef([]),F=l.useMemo(()=>!Array.isArray(a)||a.length===0?null:new Set(a),[a]),_=l.useMemo(()=>(F?p.filter(U=>F.has(String(U.id))):p).map(U=>{const Z=(Array.isArray(U.models)?U.models:[]).filter(K=>{const ie=typeof K?.id=="string"?K.id:"";return!f.some(Ne=>Ne.providerID===String(U.id)&&Ne.modelID===ie)});return{...U,models:Z}}).filter(U=>U.models.length>0),[p,F,f]),B=()=>A(!1),V=R=>{S(U=>{const W=new Set(U);return W.has(R)?W.delete(R):W.add(R),W})};l.useEffect(()=>{D||(C(""),T(0))},[D]),l.useEffect(()=>{T(0)},[P]);const $=R=>{const U=R?.name||R?.id||"",W=String(U);return W.length>40?W.substring(0,37)+"...":W},z=(R,U)=>{const W=`${R}/${U}`;return m.get(W)},Q=(R,U)=>{n(R,U),R&&U&&v(R,U),E(!1)},L=(R,U)=>{if(!P.trim())return!0;const W=P.toLowerCase();return R.toLowerCase().includes(W)||U.toLowerCase().includes(W)},J=(R,U,W,Z,K,ie)=>{const Ne=z(U,W),ne=t1(Ne?.limit?.context),fe=t===U&&e===W,pe=h(U,W),je=Z==="fav"||Z==="recent";return s.jsxs($t,{ref:oe=>{M.current[K]=oe},className:ue("group flex items-center gap-2",ie&&"bg-interactive-selection"),onSelect:()=>Q(U,W),onMouseEnter:()=>T(K),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[je&&s.jsx(xn,{providerId:U,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(R)}),ne?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:ne}):null]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[fe&&s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}),s.jsx("button",{onClick:oe=>{oe.preventDefault(),oe.stopPropagation(),b(U,W)},className:ue("model-favorite-button flex h-4 w-4 items-center justify-center hover:text-primary/80",pe?"text-primary":"text-muted-foreground"),"aria-label":o(pe?"settings.agents.modelSelector.actions.unfavorite":"settings.agents.modelSelector.actions.favorite"),title:o(pe?"settings.agents.modelSelector.actions.removeFromFavorites":"settings.agents.modelSelector.actions.addToFavorites"),children:pe?s.jsx(I,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"star",className:"h-3.5 w-3.5"})})]})]},`${Z}-${U}-${W}`)},ee=x.filter(({model:R,providerID:U})=>{if(F&&!F.has(U))return!1;const Z=p.find(ie=>ie.id===U)?.name||U,K=$(R);return L(K,Z)}),re=g.filter(({model:R,providerID:U})=>{if(F&&!F.has(U))return!1;const Z=p.find(ie=>ie.id===U)?.name||U,K=$(R);return L(K,Z)}),q=_.map(R=>{const W=(Array.isArray(R.models)?R.models:[]).filter(Z=>{const K=$(Z);return L(K,R.name||R.id||"")});return{...R,models:W}}).filter(R=>R.models.length>0),ce=ee.length>0||re.length>0||q.length>0,ae=()=>y?s.jsx(Mr,{open:k,onClose:B,title:o("settings.agents.modelSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[x.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.favorites")}),s.jsx("div",{className:"border-t border-border/20",children:x.map(({model:R,providerID:U,modelID:W})=>{const Z=U===t&&W===e;return s.jsxs("div",{className:ue("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",Z?"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:()=>{Q(U,W),B()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xn,{providerId:U,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(R)})]})}),s.jsx("button",{onClick:K=>{K.preventDefault(),K.stopPropagation(),b(U,W)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-primary hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.unfavorite"),children:s.jsx(I,{name:"star-fill",className:"h-4 w-4"})})]},`fav-mobile-${U}-${W}`)})})]}),g.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.recents")}),s.jsx("div",{className:"border-t border-border/20",children:g.map(({model:R,providerID:U,modelID:W})=>{const Z=U===t&&W===e;return s.jsxs("div",{className:ue("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",Z?"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:()=>{Q(U,W),B()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xn,{providerId:U,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(R)})]})}),s.jsx("button",{onClick:K=>{K.preventDefault(),K.stopPropagation(),b(U,W)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-muted-foreground/50 hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.favorite"),children:s.jsx(I,{name:"star",className:"h-4 w-4"})})]},`recent-mobile-${U}-${W}`)})})]}),_.map(R=>{const U=Array.isArray(R.models)?R.models:[];if(U.length===0)return null;const W=R.id===t,Z=j.has(R.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(R.id),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xn,{providerId:R.id,className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:R.name}),W&&s.jsx("span",{className:"typography-micro text-primary/80",children:o("settings.agents.modelSelector.badge.current")})]}),Z?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3 text-muted-foreground"})]}),Z&&s.jsx("div",{className:"border-t border-border/20",children:U.map(K=>{const ie=R.id===t&&K.id===e;return s.jsxs("div",{className:ue("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",ie?"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:()=>{Q(R.id,K.id),B()},children:s.jsx("span",{className:"font-medium truncate",children:$(K)})}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx("button",{onClick:Ne=>{Ne.preventDefault(),Ne.stopPropagation(),b(R.id,K.id)},className:ue("flex h-8 w-8 items-center justify-center active:scale-95 touch-manipulation hover:text-primary/80",h(R.id,K.id)?"text-primary":"text-muted-foreground/50"),"aria-label":h(R.id,K.id)?o("settings.agents.modelSelector.actions.unfavorite"):o("settings.agents.modelSelector.actions.favorite"),children:h(R.id,K.id)?s.jsx(I,{name:"star-fill",className:"h-4 w-4"}):s.jsx(I,{name:"star",className:"h-4 w-4"})}),ie&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]})]},K.id)})})]},R.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:()=>{Q("",""),B()},children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:i||o("settings.agents.modelSelector.noModelOptional")})})]})}):null;return s.jsxs(s.Fragment,{children:[y?s.jsxs("button",{type:"button",onClick:c?()=>A(!0):void 0,disabled:!c,className:ue("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",r),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[c?t?s.jsx(xn,{providerId:t,className:"h-3.5 w-3.5"}):s.jsx(I,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),c&&s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t&&e?`${t}/${e}`:i||o("settings.agents.modelSelector.selectPlaceholder")})]}),s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):s.jsxs(Fs,{open:c&&D,onOpenChange:c?E:void 0,children:[s.jsx(Es,{asChild:!0,children:s.jsxs("div",{className:ue("border-input data-[placeholder]:text-muted-foreground flex items-center justify-between gap-2 rounded-lg border bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover data-[popup-open]:bg-interactive-active h-6 w-fit",r),children:[c?s.jsxs(s.Fragment,{children:[t?s.jsxs(s.Fragment,{children:[s.jsx(xn,{providerId:t,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx(I,{name:"pencil-ai",className:"h-3 w-3 text-primary/60 hidden"})]}):s.jsx(I,{name:"pencil-ai",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-foreground",children:t&&e?`${t}/${e}`:i||o("settings.agents.modelSelector.notSelected")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsx(Rs,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:(()=>{const R=[];ee.forEach(({model:K,providerID:ie,modelID:Ne})=>{R.push({model:K,providerID:ie,modelID:Ne,section:"fav"})}),re.forEach(({model:K,providerID:ie,modelID:Ne})=>{R.push({model:K,providerID:ie,modelID:Ne,section:"recent"})}),q.forEach(K=>{K.models.forEach(ie=>{R.push({model:ie,providerID:K.id,modelID:ie.id,section:"provider"})})});const U=R.length,W=K=>{if(K.stopPropagation(),K.key==="ArrowDown"){K.preventDefault();const ie=(N+1)%Math.max(1,U);T(ie),setTimeout(()=>{M.current[ie]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(K.key==="ArrowUp"){K.preventDefault();const ie=(N-1+Math.max(1,U))%Math.max(1,U);T(ie),setTimeout(()=>{M.current[ie]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(K.key==="Enter"){K.preventDefault();const ie=R[N];ie&&Q(ie.providerID,ie.modelID)}else K.key==="Escape"&&(K.preventDefault(),E(!1))};let Z=0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Vt,{type:"text",placeholder:o("settings.agents.modelSelector.searchPlaceholder"),value:P,onChange:K=>C(K.target.value),onKeyDown:W,className:"pl-8 h-8 typography-meta",autoFocus:!0})]})}),s.jsx(Ns,{outerClassName:"max-h-[min(400px,calc(100dvh-12rem))] flex-1",children:s.jsxs("div",{className:"p-1",children:[s.jsxs($t,{className:ue("flex items-center gap-2"),onSelect:()=>Q("",""),children:[s.jsx(I,{name:"close",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-muted-foreground",children:i||o("settings.agents.modelSelector.notSelected")}),!t&&!e&&s.jsx(I,{name:"check",className:"h-4 w-4 text-primary ml-auto"})]}),s.jsx(Cn,{}),!ce&&P&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("settings.agents.modelSelector.state.noModelsFound")}),ee.length>0&&s.jsxs("div",{children:[s.jsxs(zi,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(I,{name:"star-fill",className:"h-4 w-4 text-primary"}),o("settings.agents.modelSelector.section.favorites")]}),ee.map(({model:K,providerID:ie,modelID:Ne})=>{const ne=Z++;return J(K,ie,Ne,"fav",ne,N===ne)})]}),re.length>0&&s.jsxs("div",{children:[ee.length>0&&s.jsx(Cn,{}),s.jsxs(zi,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(I,{name:"time",className:"h-4 w-4"}),o("settings.agents.modelSelector.section.recent")]}),re.map(({model:K,providerID:ie,modelID:Ne})=>{const ne=Z++;return J(K,ie,Ne,"recent",ne,N===ne)})]}),(ee.length>0||re.length>0)&&q.length>0&&s.jsx(Cn,{}),q.map((K,ie)=>s.jsxs("div",{children:[ie>0&&s.jsx(Cn,{}),s.jsxs(zi,{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(xn,{providerId:K.id,className:"h-4 w-4 flex-shrink-0"}),K.name]}),K.models.map(Ne=>{const ne=Z++;return J(Ne,K.id,Ne.id,"provider",ne,N===ne)})]},K.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:o("settings.agents.modelSelector.keyboardHints")})]})})()})]}),ae()]})},Ol=t=>{const e=ot.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:o}=pt(),{isReady:c,isUnavailable:d}=Gf(),p=vt(s1),m=di(n1),u=di(r1),f=vt(a1);let b;e:{if(Array.isArray(p)&&p.length>0){b=p;break e}let B;e[0]!==m?(B=Array.isArray(m)?m:[],e[0]=m,e[1]=B):B=e[1],b=B}const h=b;let v;if(e[2]!==i||e[3]!==h){const B=Xx(h);v=i?B.filter(i):B,e[2]=i,e[3]=h,e[4]=v}else v=e[4];const x=v,g=De(i1),{isMobile:w}=nn(),y=g||w,[k,A]=l.useState(!1);let j,S;e[5]!==u||e[6]!==f||e[7]!==h.length?(j=()=>{h.length>0||(f(),u())},S=[h.length,f,u],e[5]=u,e[6]=f,e[7]=h.length,e[8]=j,e[9]=S):(j=e[8],S=e[9]),l.useEffect(j,S);let D;e[10]===Symbol.for("react.memo_cache_sentinel")?(D=()=>A(!1),e[10]=D):D=e[10];const E=D;let P;e[11]!==r?(P=B=>{r(B)},e[11]=r,e[12]=P):P=e[12];const C=P;let N;e[13]!==n||e[14]!==x||e[15]!==C||e[16]!==y||e[17]!==k||e[18]!==o?(N=()=>y?s.jsx(Mr,{open:k,onClose:E,title:o("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:ue("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",n?"text-foreground":"bg-primary/10 text-primary"),onClick:()=>{C(""),E()},children:[s.jsx("span",{className:ue("typography-meta",n?"text-muted-foreground":"font-medium"),children:o("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),x.map(B=>{const V=B.name===n;return s.jsxs("button",{type:"button",className:ue("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:()=>{C(B.name),E()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:B.name}),B.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:B.description})]}),V&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},B.name)})]})}):null,e[13]=n,e[14]=x,e[15]=C,e[16]=y,e[17]=k,e[18]=o,e[19]=N):N=e[19];const T=N;let M;e[20]!==n||e[21]!==x||e[22]!==a||e[23]!==C||e[24]!==y||e[25]!==c||e[26]!==d||e[27]!==o?(M=y?s.jsxs("button",{type:"button",onClick:c?()=>A(!0):void 0,disabled:!c,className:ue("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",a),children:[s.jsx("div",{className:"flex items-center gap-2",children:c?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:n||o("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]})}),s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsxs("div",{className:ue("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 cursor-pointer hover:bg-interactive-hover/30 h-6 w-fit",a),children:[s.jsx(I,{name:"robot-2",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap",children:n||o("settings.commands.agentSelector.notSelected")}),s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(Rs,{className:"max-w-[300px]",children:[s.jsx($t,{className:"typography-meta",onSelect:()=>C(""),children:s.jsx("span",{className:"text-muted-foreground",children:o("settings.commands.agentSelector.notSelected")})}),x.map(B=>s.jsx($t,{className:"typography-meta",onSelect:()=>C(B.name),children:s.jsx("span",{className:"font-medium",children:B.name})},B.name))]})]}):s.jsxs("div",{className:ue("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60",a),children:[s.jsx(I,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=x,e[22]=a,e[23]=C,e[24]=y,e[25]=c,e[26]=d,e[27]=o,e[28]=M):M=e[28];let F;e[29]!==T?(F=T(),e[29]=T,e[30]=F):F=e[30];let _;return e[31]!==M||e[32]!==F?(_=s.jsxs(s.Fragment,{children:[M,F]}),e[31]=M,e[32]=F,e[33]=_):_=e[33],_};function s1(t){return t.agents}function n1(t){return t.agents}function r1(t){return t.loadAgents}function a1(t){return t.loadAgents}function i1(t){return t.isMobile}const um=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),o1=t=>{const e=ot.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:o}=pt();let c;e[0]!==o||e[1]!==n?(c=n||o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=o,e[1]=n,e[2]=c):c=e[2];const d=c,p=a?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==p?(m=ue("flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2",p),e[3]=p,e[4]=m):m=e[4];let u;e[5]!==d?(u=s.jsx("span",{className:"typography-micro whitespace-nowrap font-medium capitalize",children:d}),e[5]=d,e[6]=u):u=e[6];let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=f):f=e[7];let b;e[8]!==m||e[9]!==u?(b=s.jsxs("div",{className:m,children:[u,f]}),e[8]=m,e[9]=u,e[10]=b):b=e[10];const h=b;if(a)return h;let v;e[11]!==h?(v=s.jsx(Es,{asChild:!0,children:h}),e[11]=h,e[12]=v):v=e[12];let x;e[13]!==i?(x=()=>i(""),e[13]=i,e[14]=x):x=e[14];const g=!n&&"text-primary";let w;e[15]!==g?(w=ue("font-medium",g),e[15]=g,e[16]=w):w=e[16];let y;e[17]!==o?(y=o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=o,e[18]=y):y=e[18];let k;e[19]!==w||e[20]!==y?(k=s.jsx("span",{className:w,children:y}),e[19]=w,e[20]=y,e[21]=k):k=e[21];let A;e[22]!==k||e[23]!==x?(A=s.jsx($t,{className:"typography-meta",onSelect:x,children:k}),e[22]=k,e[23]=x,e[24]=A):A=e[24];let j;if(e[25]!==i||e[26]!==r||e[27]!==n){let E;e[29]!==i||e[30]!==n?(E=P=>s.jsx($t,{className:"typography-meta",onSelect:()=>i(P),children:s.jsx("span",{className:ue("font-medium capitalize",n===P&&"text-primary"),children:P})},P),e[29]=i,e[30]=n,e[31]=E):E=e[31],j=r.map(E),e[25]=i,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let S;e[32]!==A||e[33]!==j?(S=s.jsxs(Rs,{align:"start",className:"max-w-[220px]",children:[A,j]}),e[32]=A,e[33]=j,e[34]=S):S=e[34];let D;return e[35]!==S||e[36]!==v?(D=s.jsxs(Fs,{children:[v,S]}),e[35]=S,e[36]=v,e[37]=D):D=e[37],D};function Mh(t){const e=ot.c(99),{t:n}=pt(),{open:r,onOpenChange:a,target:i,projectDirectory:o,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=vt(x1),u=vt(g1),f=di(h1),b=vt(f1),h=vt(p1),v=vt(m1),x=vt(u1),g=vt(d1);let w;e[0]!==g||e[1]!==v||e[2]!==h||e[3]!==x?(w=()=>um({providerID:h,modelID:v,variant:x,agent:g}),e[0]=g,e[1]=v,e[2]=h,e[3]=x,e[4]=w):w=e[4];const[y,k]=l.useState(w);let A,j;e[5]!==f||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==o?(A=()=>{r&&(m({directory:o}),u({directory:o}),f())},j=[r,m,u,f,o],e[5]=f,e[6]=u,e[7]=m,e[8]=r,e[9]=o,e[10]=A,e[11]=j):(A=e[10],j=e[11]),l.useEffect(A,j);let S,D;e[12]!==g||e[13]!==v||e[14]!==h||e[15]!==x||e[16]!==r?(S=()=>{r&&k(um({providerID:h,modelID:v,variant:x,agent:g}))},D=[r,h,v,x,g],e[12]=g,e[13]=v,e[14]=h,e[15]=x,e[16]=r,e[17]=S,e[18]=D):(S=e[17],D=e[18]),l.useEffect(S,D);let E,P;e[19]!==y.modelID||e[20]!==y.providerID||e[21]!==r||e[22]!==b?(E=()=>{if(!r||b.length===0)return;const ye=b.find(Ee=>Ee.id===y.providerID)??b[0],Ie=Array.isArray(ye?.models)?ye.models:[],he=Ie.some(Ee=>Ee.id===y.modelID),me=Ie[0]?.id??"";ye?.id===y.providerID&&he||k(Ee=>({...Ee,providerID:ye?.id??"",modelID:he?Ee.modelID:me,variant:""}))},P=[r,b,y.providerID,y.modelID],e[19]=y.modelID,e[20]=y.providerID,e[21]=r,e[22]=b,e[23]=E,e[24]=P):(E=e[23],P=e[24]),l.useEffect(E,P);const C=c1;let N;if(e[25]!==y.modelID||e[26]!==y.providerID||e[27]!==b){let ye;e[29]!==y.providerID?(ye=he=>he.id===y.providerID,e[29]=y.providerID,e[30]=ye):ye=e[30],N=b.find(ye)?.models?.find(he=>he.id===y.modelID),e[25]=y.modelID,e[26]=y.providerID,e[27]=b,e[28]=N}else N=e[28];const T=N;let M;e[31]!==T?(M=T?.variants?Object.keys(T.variants):[],e[31]=T,e[32]=M):M=e[32];const F=M,_=F.length>0;let B,V;e[33]!==y.variant||e[34]!==_?(B=()=>{_||!y.variant||k(l1)},V=[_,y.variant],e[33]=y.variant,e[34]=_,e[35]=B,e[36]=V):(B=e[35],V=e[36]),l.useEffect(B,V);let $;e[37]!==y.modelID||e[38]!==y.providerID?($=y.providerID.trim().length>0&&y.modelID.trim().length>0,e[37]=y.modelID,e[38]=y.providerID,e[39]=$):$=e[39];const z=$;let Q;e[40]!==z||e[41]!==y||e[42]!==d||e[43]!==p?(Q=()=>{!z||p||d(y)},e[40]=z,e[41]=y,e[42]=d,e[43]=p,e[44]=Q):Q=e[44];const L=Q;let J,ee;e[45]!==L||e[46]!==r?(J=()=>{if(!r)return;const ye=Ie=>{(Ie.metaKey||Ie.ctrlKey)&&Ie.key==="Enter"&&(Ie.preventDefault(),L())};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},ee=[r,L],e[45]=L,e[46]=r,e[47]=J,e[48]=ee):(J=e[47],ee=e[48]),l.useEffect(J,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 q=re;let ce;e[52]!==a||e[53]!==p?(ce=ye=>{p||a(ye)},e[52]=a,e[53]=p,e[54]=ce):ce=e[54];let ae;e[55]!==q?(ae=s.jsx(vs,{children:s.jsx(gs,{children:q})}),e[55]=q,e[56]=ae):ae=e[56];let R;e[57]===Symbol.for("react.memo_cache_sentinel")?(R=(ye,Ie)=>{k(he=>({...he,providerID:ye,modelID:Ie,variant:""}))},e[57]=R):R=e[57];let U;e[58]!==y.modelID||e[59]!==y.providerID?(U=s.jsx(mo,{providerId:y.providerID,modelId:y.modelID,onChange:R}),e[58]=y.modelID,e[59]=y.providerID,e[60]=U):U=e[60];const W=!_;let Z;e[61]===Symbol.for("react.memo_cache_sentinel")?(Z=ye=>k(Ie=>({...Ie,variant:ye})),e[61]=Z):Z=e[61];let K;e[62]!==y.variant||e[63]!==W||e[64]!==F?(K=s.jsx(o1,{value:y.variant,options:F,disabled:W,onChange:Z}),e[62]=y.variant,e[63]=W,e[64]=F,e[65]=K):K=e[65];let ie;e[66]===Symbol.for("react.memo_cache_sentinel")?(ie=ye=>k(Ie=>({...Ie,agent:ye})),e[66]=ie):ie=e[66];let Ne;e[67]!==y.agent?(Ne=s.jsx(Ol,{agentName:y.agent,filter:C,onChange:ie}),e[67]=y.agent,e[68]=Ne):Ne=e[68];let ne;e[69]!==U||e[70]!==K||e[71]!==Ne?(ne=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[U,K,Ne]}),e[69]=U,e[70]=K,e[71]=Ne,e[72]=ne):ne=e[72];let fe;e[73]!==a?(fe=()=>a(!1),e[73]=a,e[74]=fe):fe=e[74];let pe;e[75]!==n?(pe=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=pe):pe=e[76];let je;e[77]!==p||e[78]!==fe||e[79]!==pe?(je=s.jsx(xe,{variant:"ghost",size:"sm",onClick:fe,disabled:p,children:pe}),e[77]=p,e[78]=fe,e[79]=pe,e[80]=je):je=e[80];const oe=!z||p;let Se;e[81]!==p||e[82]!==n?(Se=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=Se):Se=e[83];let se;e[84]!==L||e[85]!==oe||e[86]!==Se?(se=s.jsx(xe,{size:"sm",onClick:L,disabled:oe,children:Se}),e[84]=L,e[85]=oe,e[86]=Se,e[87]=se):se=e[87];let we;e[88]!==je||e[89]!==se?(we=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[je,se]}),e[88]=je,e[89]=se,e[90]=we):we=e[90];let Ae;e[91]!==ae||e[92]!==ne||e[93]!==we?(Ae=s.jsxs(ms,{className:"max-w-lg",children:[ae,ne,we]}),e[91]=ae,e[92]=ne,e[93]=we,e[94]=Ae):Ae=e[94];let ve;return e[95]!==r||e[96]!==ce||e[97]!==Ae?(ve=s.jsx(ps,{open:r,onOpenChange:ce,children:Ae}),e[95]=r,e[96]=ce,e[97]=Ae,e[98]=ve):ve=e[98],ve}function l1(t){return{...t,variant:""}}function c1(t){return Yf(t.mode)}function d1(t){return t.currentAgentName||""}function u1(t){return t.currentVariant||""}function m1(t){return t.currentModelId}function p1(t){return t.currentProviderId}function f1(t){return t.providers}function h1(t){return t.loadAgents}function g1(t){return t.loadAgents}function x1(t){return t.loadProviders}const rd=5,Eh=15,Go=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},b1=(t,e)=>{const n=Go(e);return Math.max(n*rd,Math.min(n*Eh,n*t))},y1=async(t,e)=>{const n=await sb(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},v1=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,w1=t=>{const e=ot.c(20),{id:n,children:r}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:i,listeners:o,setNodeRef:c,setActivatorNodeRef:d,transform:p,transition:m,isDragging:u}=Nl(a);let f;e[2]!==p?(f=Sl.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let b;e[4]!==f||e[5]!==m?(b={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=b):b=e[6];const h=u&&"opacity-60";let v;e[7]!==h?(v=ue(h),e[7]=h,e[8]=v):v=e[8];let x;e[9]!==i||e[10]!==r||e[11]!==u||e[12]!==o||e[13]!==d?(x=r({attributes:i,listeners:o,setActivatorNodeRef:d,isDragging:u}),e[9]=i,e[10]=r,e[11]=u,e[12]=o,e[13]=d,e[14]=x):x=e[14];let g;return e[15]!==c||e[16]!==b||e[17]!==v||e[18]!==x?(g=s.jsx("li",{ref:c,style:b,className:v,children:x}),e[15]=c,e[16]=b,e[17]=v,e[18]=x,e[19]=g):g=e[19],g},j1=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=pt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),[m,u]=l.useState([]),[f,b]=l.useState(""),[h,v]=l.useState(null),[x,g]=l.useState(()=>new Set),[w,y]=l.useState([]),[k,A]=l.useState(null),[j,S]=l.useState(!1),[D,E]=l.useState(0),P=l.useRef(!1),C=l.useRef(""),N=De(O=>O.todoPanelHeight),T=De(O=>O.setTodoPanelHeight),M=De(O=>O.notesPanelHeight),F=De(O=>O.setNotesPanelHeight),[_,B]=l.useState(!1),V=l.useRef(0),$=l.useRef(N),z=Lt(O=>O.currentSessionId),Q=Lt(O=>O.createSession),L=Lt(O=>O.initializeNewOpenChamberSession),J=Lt(O=>O.sendMessage),ee=Lt(O=>O.setCurrentSession),re=Ea(O=>O.setPendingInputText),q=_s(O=>O.currentDirectory),ce=De(O=>O.openContextPanelTab),ae=De(O=>O.setActiveMainTab),R=De(O=>O.setSessionSwitcherOpen),U=De(O=>O.padding),W=l.useCallback(async(O,X)=>{if(!t)return!1;const G=await Zx(t,{notes:O,todos:X});return G||H.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),G},[t,i]);l.useEffect(()=>{if(!t){p(""),u([]),y([]),b(""),g(new Set);return}let O=!1;return c(!0),(async()=>{try{const X=await eb(t),G=await Promise.all(X.plans.map(Te=>y1(Te,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(O)return;p(X.notes),u(X.todos),y(G),C.current=X.notes,P.current=!0,b(""),g(new Set)}catch{O||(H.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),y([]),C.current="",P.current=!0)}finally{O||c(!1)}})(),()=>{O=!0}},[D,t,i]),l.useEffect(()=>{if(!t)return;const O=X=>{const G=X.detail;G?.projectId&&G.projectId!==t.id||E(Te=>Te+1)};return window.addEventListener("openchamber:project-plan-saved",O),window.addEventListener("openchamber:project-notes-updated",O),()=>{window.removeEventListener("openchamber:project-plan-saved",O),window.removeEventListener("openchamber:project-notes-updated",O)}},[t]),l.useEffect(()=>{if(m.length<7)return;const O=b1(m.length,U),X=Go(U)*rd;(N<X||N>O)&&T(O)},[m.length,U,N,T]),l.useEffect(()=>{if(!_)return;const O=G=>{const Te=G.clientY-V.current,le=Math.min(Go(U)*Eh,Math.max(Go(U)*rd,$.current+Te));T(le)},X=()=>{B(!1)};return window.addEventListener("pointermove",O),window.addEventListener("pointerup",X,{once:!0}),window.addEventListener("pointercancel",X,{once:!0}),()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",X),window.removeEventListener("pointercancel",X)}},[_,U,T]);const Z=l.useCallback(O=>{B(!0),V.current=O.clientY,$.current=N,O.preventDefault()},[N]),K=l.useCallback(()=>{C.current=d,W(d,m)},[d,W,m]);l.useEffect(()=>{if(!t||!P.current||d===C.current)return;const O=window.setTimeout(()=>{C.current=d,W(d,m)},400);return()=>{window.clearTimeout(O)}},[d,W,t,m]);const ie=l.useCallback(()=>{const O=f.trim();if(!O)return;const X=[...m,{id:v1(),text:O.slice(0,vo),completed:!1,createdAt:Date.now()}];u(X),b(""),W(d,X)},[f,d,W,m]),Ne=l.useCallback(O=>{g(X=>{const G=new Set(X);return G.has(O)?G.delete(O):G.add(O),G})},[]),ne=l.useCallback((O,X)=>{const G=m.map(Te=>Te.id===O?{...Te,completed:X}:Te);u(G),W(d,G)},[d,W,m]),fe=l.useCallback(O=>{const X=m.filter(G=>G.id!==O);u(X),W(d,X)},[d,W,m]),pe=l.useCallback(()=>{const O=m.filter(X=>!X.completed);O.length!==m.length&&(u(O),W(d,O))},[d,W,m]),je=l.useCallback(O=>{const{active:X,over:G}=O;if(!G||X.id===G.id)return;const Te=m.findIndex(de=>de.id===X.id),le=m.findIndex(de=>de.id===G.id);if(Te===-1||le===-1)return;const We=Ef(m,Te,le);u(We),W(d,We)},[d,W,m]),oe=Gi(ni(qi,{activationConstraint:{distance:8}})),Se=f.slice(0,vo),se=m.reduce((O,X)=>O+(X.completed?1:0),0),we=l.useCallback(()=>{ae("chat"),R(!1)},[ae,R]),Ae=l.useCallback((O,X)=>{!t||h||A({kind:"session",todoId:O,todoText:X})},[t,h]),ve=l.useCallback(O=>{if(!z){H.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}we();const X=`\`\`\`md
|
|
4
|
-
${O}
|
|
5
|
-
\`\`\``;re(X,"append"),H.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[z,r,we,re,i]),ye=l.useCallback((O,X)=>{if(!(!t||h)){if(!n){H.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}A({kind:"worktree",todoId:O,todoText:X})}},[n,t,h,i]),Ie=l.useCallback(async O=>{if(!t||!k)return;const X=await bn("plan.todo.visible",{todo_text:k.todoText}),Te=[{synthetic:!0,text:await bn("plan.todo.instructions",{todo_text:k.todoText})}];S(!0),v(k.todoId);try{we();let le=null,We=t.path;if(k.kind==="worktree"){if(!n){H.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const Fe=await Jf(t.path,Qf());if(!Fe?.id)return;le=Fe.id,We=null}else{const Fe=await Q(void 0,t.path,null);if(!Fe?.id){H.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}le=Fe.id,We=Fe.directory??t.path,L(Fe.id,vt.getState().agents??[])}if(!le)return;const de=Pl.getState();de.saveSessionModelSelection(le,O.providerID,O.modelID),O.agent.trim()&&(de.saveSessionAgentSelection(le,O.agent),de.saveAgentModelForSession(le,O.agent,O.providerID,O.modelID),de.saveAgentModelVariantForSession(le,O.agent,O.providerID,O.modelID,O.variant||void 0)),ee(le,We),await J(X,O.providerID,O.modelID,O.agent.trim()||void 0,void 0,void 0,Te,O.variant||void 0),H.success(k.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),A(null),r?.()}catch(le){const We=le instanceof Error?le.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),We?{description:We}:void 0)}finally{S(!1),v(null)}},[n,Q,L,r,k,t,we,J,ee,i]),he=l.useRef(null),[me,Ee]=l.useState(!1),[Ve,Y]=l.useState(null),ke=l.useCallback(async O=>{if(!(!t||Ve)){Y(O);try{if(!await tb(t,O)){H.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}y(G=>G.filter(Te=>Te.id!==O)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Y(null)}}},[Ve,t,i]),Be=l.useCallback(async()=>{if(!t||me)return;const O=await Xf({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(O.success&&O.path){Ee(!0);try{const X=new URLSearchParams({path:O.path,allowOutsideWorkspace:"true"}),G=await fetch(`/api/fs/read?${X.toString()}`,{cache:"no-store"});if(!G.ok){H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const Te=await G.text();if(!Te.trim()){H.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const le=O.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await yu(t,Te,le)){H.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),H.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(X){const G=X instanceof Error?X.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),G?{description:G}:void 0)}finally{Ee(!1)}}else O.error==="Native file picker not available"&&he.current?.click()},[me,t,i]),Ce=l.useCallback(async O=>{if(!(!t||!O)){Ee(!0);try{const X=await O.text();if(!X.trim()){H.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const G=O.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await yu(t,X,G)){H.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),H.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(X){const G=X instanceof Error?X.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),G?{description:G}:void 0)}finally{Ee(!1)}}},[t,i]),ge=l.useCallback(O=>{const X=t?.path?.trim(),G=q?.trim()||X;G&&ce(G,{mode:"plan",targetPath:O.path,dedupeKey:O.path,label:O.title})},[q,ce,t]);return t?s.jsxs("div",{className:ue("w-full min-w-0 space-y-3 p-3",a),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:i("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d.length,"/",vu]})]}),s.jsx(fn,{value:d,onChange:O=>p(O.target.value.slice(0,vu)),onBlur:K,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:M,onResizeHeightChange:F,useScrollShadow:!0,scrollShadowSize:56,disabled:o})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:pe,disabled:o||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:[Se.length,"/",vo]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vt,{value:Se,onChange:O=>b(O.target.value.slice(0,vo)),onKeyDown:O=>{O.key==="Enter"&&(O.preventDefault(),ie())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:o,className:"h-8"}),s.jsx("button",{type:"button",onClick:ie,disabled:o||Se.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.addAria"),title:i("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:ue("overflow-y-auto rounded-lg border border-border/60 bg-background/40",_&&"transition-none"),style:m.length<7?void 0:{height:`${N}px`,maxHeight:`${N}px`},children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(Yi,{sensors:oe,collisionDetection:Ji,onDragEnd:je,children:s.jsx(sl,{items:m.map(O=>O.id),strategy:Kc,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(O=>{const X=x.has(O.id);return s.jsx(w1,{id:O.id,children:G=>s.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("button",{type:"button",ref:G.setActivatorNodeRef,...G.attributes,...G.listeners,onClick:Te=>{Te.preventDefault(),Te.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:O.text}),children:s.jsx(I,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(ds,{checked:O.completed,onChange:Te=>ne(O.id,Te),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:O.text})})}),s.jsx("button",{type:"button",onClick:()=>Ne(O.id),className:ue("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-6 text-foreground",X?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",O.completed&&"text-muted-foreground line-through"),title:X?void 0:O.text,"aria-label":X?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:O.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:O.text}),children:O.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>fe(O.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:O.text}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",disabled:h===O.id,className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.send",{text:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:O.text}),children:s.jsx(I,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(Rs,{align:"end",className:"w-56",children:[s.jsx($t,{onClick:()=>ve(O.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx($t,{onClick:()=>Ae(O.id,O.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx($t,{onClick:()=>{ye(O.id,O.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},O.id)})})})})}),m.length>=7&&s.jsx("div",{className:ue("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",_&&"bg-[var(--interactive-border)]"),onPointerDown:Z,role:"separator","aria-orientation":"horizontal","aria-label":i("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:w.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:w.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:w.length})})]}),s.jsx("input",{ref:he,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:O=>{const X=O.target.files?.[0]??null;Ce(X),O.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:Be,disabled:!t||me,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.plans.importFromFile"),title:i("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:w.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:w.map(O=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>ge(O),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:O.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(O.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{ke(O.id)},disabled:Ve===O.id,className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",title:i("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":i("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:O.title}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},O.id))})})]}),s.jsx(Mh,{open:k!==null,onOpenChange:O=>{!O&&!j&&A(null)},target:k?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:Ie})]}):s.jsx("div",{className:ue("w-full min-w-0 p-3",a),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},Rh=12,N1=[{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"}],S1=t=>{const e=ot.c(18),{isActive:n,burstKey:r,className:a,durationMs:i,bursts:o,onComplete:c}=t,d=r===void 0?0:r,p=i===void 0?900:i,m=o===void 0?N1:o,u=$e.useRef(!1);let f,b;e[0]!==n||e[1]!==c?(f=()=>{!n&&u.current&&c?.(),n&&(u.current=!0)},b=[n,c],e[0]=n,e[1]=c,e[2]=f,e[3]=b):(f=e[2],b=e[3]),$e.useEffect(f,b);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=Array.from({length:Rh},k1),e[4]=h):h=e[4];const v=h;if(!n)return null;let x;e[5]!==a?(x=ue("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=x):x=e[6];let g;if(e[7]!==d||e[8]!==m||e[9]!==p){let y;e[11]!==d||e[12]!==p?(y=k=>{const A={"--burst-delay":`${k.delay}ms`,"--burst-x":`${k.x}%`,"--burst-y":`${k.y}%`,"--firework-color":`var(${k.colorVar})`,"--firework-duration":`${p}ms`};return s.jsx("div",{className:"firework-burst",style:A,children:v.map((j,S)=>{const D=j.x*k.radius,E=j.y*k.radius,P={"--translate-x":`${D}px`,"--translate-y":`${E}px`,"--particle-delay":`${j.delay}ms`,color:`var(${k.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${k.id}-${S}-${d}`)})},`${k.id}-${d}`)},e[11]=d,e[12]=p,e[13]=y):y=e[13],g=m.map(y),e[7]=d,e[8]=m,e[9]=p,e[10]=g}else g=e[10];let w;return e[14]!==d||e[15]!==x||e[16]!==g?(w=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":d,children:g}),e[14]=d,e[15]=x,e[16]=g,e[17]=w):w=e[17],w};function k1(t,e){const n=Math.PI*2*e/Rh;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const C1=t=>{const e=ot.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,a=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[o,c]=$e.useState(i),d=$e.useRef(null);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=p):p=e[3];const m=p;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),c(I1)},e[4]=u):u=e[4];const f=u;let b;e[5]!==a?(b=()=>{m(),c(P1),d.current=window.setTimeout(()=>{c(A1),d.current=null},a)},e[5]=a,e[6]=b):b=e[6];const h=b;let v,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>m(),x=[m],e[7]=v,e[8]=x):(v=e[7],x=e[8]),$e.useEffect(v,x);let g;return e[9]!==o.cycle||e[10]!==o.isActive||e[11]!==h?(g={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:h,dismissFireworks:f},e[9]=o.cycle,e[10]=o.isActive,e[11]=h,e[12]=g):g=e[12],g};function I1(t){return t.isActive?{...t,isActive:!1}:t}function P1(t){return{isActive:!0,cycle:t.cycle+1}}function A1(t){return t.isActive?{...t,isActive:!1}:t}const Fh=l.createContext(void 0),D1=t=>{const e=ot.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:o}=C1();let c;e[0]!==o||e[1]!==i?(c={triggerFireworks:i,dismissFireworks:o},e[0]=o,e[1]=i,e[2]=c):c=e[2];const d=c;let p;e[3]!==a||e[4]!==r?(p=s.jsx(S1,{isActive:r,burstKey:a}),e[3]=a,e[4]=r,e[5]=p):p=e[5];let m;return e[6]!==n||e[7]!==p||e[8]!==d?(m=s.jsxs(Fh.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},T1=()=>{const t=l.useContext(Fh);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Jn=nr()(vi(ao((t,e)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{t({selectedProfileId:n})},loadProfiles:async()=>{t({isLoading:!0});const n=e().profiles;try{const r=await lb();return t({profiles:r,isLoading:!1}),!0}catch(r){return console.error("Failed to load git identity profiles:",r),t({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=await ob();if(n&&n.userName&&n.userEmail){const r={id:"global",name:"Global Identity",userName:n.userName,userEmail:n.userEmail,authType:n.sshCommand?"ssh":void 0,sshKey:n.sshCommand?n.sshCommand.replace("ssh -i ",""):null,color:"info",icon:"house"};t({globalIdentity:r})}else t({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),t({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=await ib();return t({discoveredCredentials:n}),!0}catch(n){return console.error("Failed to discover git credentials:",n),t({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=r=>{if(typeof r!="string")return null;const a=r.trim();return a.length>0?a:null};try{let r=null;if(r===null){const a=sr()?.settings;if(a)try{const o=(await a.load())?.settings||{};r=n(o.defaultGitIdentityId)}catch{}}if(r===null)try{const a=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(a.ok){const i=await a.json().catch(()=>null);r=n(i?.defaultGitIdentityId)}}catch{}return t({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",a=r.length>0?r:"";return await Is({defaultGitIdentityId:a}),t({defaultGitIdentityId:a.length>0?a:null}),!0}catch(r){return console.error("Failed to save default git identity setting:",r),!1}},createProfile:async n=>{try{const r={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};return await ab(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const a=e().profiles.find(o=>o.id===n);if(!a)throw new Error("Profile not found");const i={...a,...r};return await rb(n,i),await e().loadProfiles(),!0}catch(a){return console.error("Failed to update git identity profile:",a),!1}},deleteProfile:async n=>{try{return await nb(n),e().selectedProfileId===n&&t({selectedProfileId:null}),await e().loadProfiles(),!0}catch(r){return console.error("Failed to delete git identity profile:",r),!1}},getProfileById:n=>{const{profiles:r,globalIdentity:a}=e();return n==="global"?a||void 0:r.find(i=>i.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=e();return r.filter(a=>!n.some(i=>i.authType==="token"&&i.host===a.host))}}),{name:"git-identities-store",storage:kl(()=>br()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Jn);function Oa(t){const e=ot.c(12);let n,r,a;e[0]!==t?({className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a):(n=e[1],r=e[2],a=e[3]);let i;e[4]!==a?(i={color:"var(--surface-elevated-foreground)",...a},e[4]=a,e[5]=i):i=e[5];let o;e[6]!==n?(o=ue("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=o):o=e[7];let c;return e[8]!==r||e[9]!==i||e[10]!==o?(c=s.jsx(_a,{"data-slot":"command",style:i,className:o,...r}),e[8]=r,e[9]=i,e[10]=o,e[11]=c):c=e[11],c}const oa=$e.forwardRef((t,e)=>{const n=ot.c(10);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(I,{name:"search",className:"size-4 shrink-0 opacity-50"}),n[3]=i):i=n[3];let o;n[4]!==r?(o=ue("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=o):o=n[5];let c;return n[6]!==a||n[7]!==e||n[8]!==o?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[i,s.jsx(_a.Input,{ref:e,"data-slot":"command-input",className:o,...a})]}),n[6]=a,n[7]=e,n[8]=o,n[9]=c):c=n[9],c});oa.displayName="CommandInput";function La(t){const e=ot.c(14);let n,r,a,i,o;e[0]!==t?({className:r,children:n,scrollbarClassName:o,disableHorizontal:a,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o):(n=e[1],r=e[2],a=e[3],i=e[4],o=e[5]);let c;e[6]!==r?(c=ue("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=c):c=e[7];const d=o??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",p=a??!0;let m;return e[8]!==n||e[9]!==i||e[10]!==c||e[11]!==d||e[12]!==p?(m=s.jsx(Ns,{as:_a.List,"data-slot":"command-list",outerClassName:"max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0",className:c,scrollbarClassName:d,disableHorizontal:p,...i,children:n}),e[8]=n,e[9]=i,e[10]=c,e[11]=d,e[12]=p,e[13]=m):m=e[13],m}function $a(t){const e=ot.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(_a.Empty,{"data-slot":"command-empty",className:"py-6 text-center typography-ui-label",...n}),e[2]=n,e[3]=r):r=e[3],r}function Rn(t){const e=ot.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=ue("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(_a.Group,{"data-slot":"command-group",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function ka(t){const e=ot.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=ue("bg-border -mx-1 h-px",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(_a.Separator,{"data-slot":"command-separator",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function kn(t){const e=ot.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=ue("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(_a.Item,{"data-slot":"command-item",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function M1(t){const e=ot.c(12);let n,r,a,i;if(e[0]!==t){const{className:c,...d}=t,p=R1,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(E1).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=ue("text-muted-foreground ml-auto flex items-center gap-1 typography-meta",c),e[5]=c,e[6]=r):r=e[6],a=d,i=u.length>0?u.map((f,b)=>s.jsxs($e.Fragment,{children:[b>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),p(f)]},`${f}-${b}`)):d.children,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i}else n=e[1],r=e[2],a=e[3],i=e[4];let o;return e[7]!==n||e[8]!==r||e[9]!==a||e[10]!==i?(o=s.jsx("span",{"data-slot":n,className:r,...a,children:i}),e[7]=n,e[8]=r,e[9]=a,e[10]=i,e[11]=o):o=e[11],o}function E1(t){return t.trim()}function R1(t){const e=t.trim().toLowerCase();return e==="ctrl"||e==="control"?s.jsx("span",{className:"text-xs font-medium",children:"ctrl"}):e==="cmd"||e==="⌘"||e==="command"||e==="meta"?s.jsx(I,{name:"command",className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(I,{name:"arrow-up",className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const ad=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},F1=t=>{const e=ad(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function O1(t,e,n){const r=ot.c(5),[a,i]=l.useState();let o,c;return r[0]!==n||r[1]!==t||r[2]!==e?(o=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[p,m]=await Promise.all([Vs("git rev-parse --absolute-git-dir",t),Vs("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=ad((p.stdout||"").trim()),f=F1(u);if(!f)return;const b=ad((m.stdout||"").trim());if(!b||b===f)return;const h=n||"",v=b.split("/").filter(Boolean).pop()||b;i({source:"sdk",path:b,projectDirectory:f,branch:h,label:h||v,name:v,worktreeRoot:b,worktreeStatus:"ready",headState:h?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},c=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=o,r[4]=c):(o=r[3],c=r[4]),l.useEffect(o,c),e??a}const Qn=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},xi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),qr=t=>!!t.success,Ll=t=>(t.stdout||"").trim(),Aa=t=>(t.stderr||"").trim();async function L1(t){const n=((await Vs("git worktree list --porcelain",t)).stdout||"").split(/\r?\n/),r=[];let a=null;for(const i of n){if(i.startsWith("worktree ")){a&&r.push(a),a={path:i.slice(9).trim(),branchRef:null};continue}a&&i.startsWith("branch ")&&(a.branchRef=i.slice(7).trim())}return a&&r.push(a),r.filter(i=>!!i.path)}async function $1(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),a=(await L1(t.repoRoot)).filter(o=>o.branchRef===e).map(o=>o.path).filter(o=>o&&!n.has(o)),i=[];for(const o of a){const c=await Vs("git status --porcelain",o);Ll(c)||i.push(o)}return i}async function Oh(t,e){for(const n of e)await Vs("git reset --hard",n).catch(()=>{})}async function B1(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Vs(`git show-ref --verify --quiet ${Qn(`refs/heads/${n}`)}`,t);if(qr(r))return n;if(n.startsWith("remotes/")){const o=n.slice(8).split("/"),c=o[0]||"origin",d=o.slice(1).join("/");if(d)return await Vs(`git branch --track ${Qn(d)} ${Qn(`${c}/${d}`)}`,t),d}const a=await Vs(`git show-ref --verify --quiet ${Qn(`refs/remotes/origin/${n}`)}`,t);return qr(a)&&await Vs(`git branch --track ${Qn(n)} ${Qn(`origin/${n}`)}`,t),n}async function Ii(t){const e=t.repoRoot,n=t.sourceBranch.trim(),r=t.targetBranch.trim();if(!n||!r)return{repoRoot:e,sourceBranch:n,targetBranch:r,commits:[]};const a=await B1(e,r),i=await Vs(`git cherry ${Qn(a)} ${Qn(n)}`,e),o=xi(i.stdout),c=new Set;for(const u of o){const f=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);f&&c.add(f[1])}const d=await Vs(`git rev-list --reverse ${Qn(`${a}..${n}`)}`,e),m=xi(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:a,commits:m}}async function _1(t,e){const n=await Vs('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!qr(n))throw new Error(Aa(n)||"Failed to create temp directory parent");const r=await Vs('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),a=Ll(r);if(!a)throw new Error(Aa(r)||"Failed to create temp directory");const i=await Vs(`git worktree add --force ${Qn(a)} ${Qn(e)}`,t);if(!qr(i))throw new Error(Aa(i)||"Failed to create temp worktree");return a}async function ml(t,e){await Vs(`git worktree remove --force ${Qn(e)}`,t).catch(()=>{}),await Vs("git worktree prune",t).catch(()=>{})}async function z1(t){const e=await Vs("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Ll(e);if(!n)return;await Vs("git fetch",t);const r=await Vs(`git merge --ff-only ${Qn(n)}`,t);if(!qr(r))throw new Error(Aa(r)||"Fast-forward failed")}async function pl(t){const e=await Vs("git status --porcelain",t),n=await Vs("git diff --name-only --diff-filter=U",t),r=await Vs("git diff",t),a=await Vs("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await Vs("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:xi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:a.stdout||a.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function V1(t){return pl(t)}async function U1(t){const e=await Vs("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return qr(e)}async function W1(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await _1(t.repoRoot,t.targetBranch);let n=[];try{await z1(e);const r=await Vs("git status --porcelain",e);if(Ll(r))throw new Error("Target branch has local changes; abort integration and retry");const a=await $1({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],o=await Vs(`git cherry-pick ${Qn(i)}`,e);if(qr(o)){n.shift();continue}const c=await Vs("git diff --name-only --diff-filter=U",e);if(xi(c.stdout).length>0){const p=await pl(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:a,remainingCommits:n,currentCommit:i},details:p}}throw new Error(Aa(o)||"Cherry-pick failed")}return await ml(t.repoRoot,e),await Oh(t.repoRoot,a).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await ml(t.repoRoot,e).catch(()=>{}),r}}async function K1(t){await Vs("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await ml(t.repoRoot,t.tempWorktreePath)}async function H1(t){const e=await Vs("git cherry-pick --continue",t.tempWorktreePath);if(!qr(e)){const i=await Vs("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(xi(i.stdout).length>0){const c=await pl(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(Aa(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const a=[...r];for(;a.length>0;){const i=a[0],o=await Vs(`git cherry-pick ${Qn(i)}`,n);if(qr(o)){a.shift();continue}const c=await Vs("git diff --name-only --diff-filter=U",n);if(xi(c.stdout).length>0){const p=await pl(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:a,currentCommit:i},details:p}}throw new Error(Aa(o)||"Cherry-pick failed")}return await ml(t.repoRoot,t.tempWorktreePath),await Oh(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const G1=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:a,refreshKey:i,onRefresh:o})=>{const{t:c}=pt(),d=Lt($=>$.currentSessionId),p=De($=>$.setActiveMainTab),[m,u]=$e.useState(!1),f=$e.useRef(null),[b,h]=$e.useState(a);$e.useEffect(()=>{h(a)},[a]),$e.useEffect(()=>{if(m){const $=setTimeout(()=>{f.current?.focus()},0);return()=>clearTimeout($)}},[m]);const v=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[x,g]=$e.useState({kind:"idle"}),[w,y]=$e.useState(!1),[k,A]=$e.useState([]),j=$e.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);$e.useEffect(()=>{if(!j||typeof window>"u")return;const $=window.localStorage.getItem(j);if(!$)return;let z=!1;try{const Q=JSON.parse($);if(!Q?.tempWorktreePath||Q.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const L=await U1(Q.tempWorktreePath).catch(()=>!1);if(z)return;if(!L){window.localStorage.removeItem(j);return}const J=await V1(Q.tempWorktreePath).catch(()=>null);z||J&&g({kind:"conflict",state:Q,details:J})})()}catch{window.localStorage.removeItem(j)}return()=>{z=!0}},[j,t]),$e.useEffect(()=>{if(!v){g({kind:"idle"});return}let $=!1;return g({kind:"loading"}),(async()=>{try{const z=await Ii({repoRoot:t,sourceBranch:e,targetBranch:b});if($)return;if(g({kind:"ready",plan:z}),z.commits.length>0){const J=z.commits.slice(-50).reverse().map(ce=>JSON.stringify(ce)).join(" "),re=((await Vs(`git show -s --format=%H%x09%h%x09%s ${J}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),q=[];for(const ce of re){const[ae,R,U]=ce.split(" ");!ae||!R||q.push({sha:ae,short:R,subject:U||""})}$||(A(q),y(!1))}else $||(A([]),y(!1))}catch{$||g({kind:"idle"})}})(),()=>{$=!0}},[v,t,e,b,i]);const S=$e.useCallback($=>{d&&Lt.getState().setWorktreeMetadata(d,{...n,createdFromBranch:$})},[d,n]),D=Lt($=>$.openNewSessionDraft),E=$e.useCallback(async $=>{const z=await bn("git.integrate.cherrypick.resolve.visible",{current_commit:$.state.currentCommit,target_branch:$.state.targetBranch}),Q=await bn("git.integrate.cherrypick.resolve.instructions",{repo_root:$.state.repoRoot,temp_worktree_path:$.state.tempWorktreePath,source_branch:$.state.sourceBranch,target_branch:$.state.targetBranch,current_commit:$.state.currentCommit}),L=`Cherry-pick conflict context (JSON)
|
|
6
|
-
${JSON.stringify({repoRoot:$.state.repoRoot,tempWorktreePath:$.state.tempWorktreePath,sourceBranch:$.state.sourceBranch,targetBranch:$.state.targetBranch,currentCommit:$.state.currentCommit,remainingCommits:$.state.remainingCommits,statusPorcelain:$.details.statusPorcelain,unmergedFiles:$.details.unmergedFiles,currentPatchMeta:$.details.currentPatchMeta,currentPatch:$.details.currentPatch,diff:$.details.diff},null,2)}`;return{visibleText:z,instructionsText:Q,payloadText:L}},[]),P=Ea($=>$.setPendingInputText),C=Ea($=>$.setPendingSyntheticParts),N=$e.useCallback(async($,z)=>{const Q=await E($);if(z){D({directoryOverride:$.state.tempWorktreePath,initialPrompt:Q.visibleText,syntheticParts:[{text:Q.instructionsText,synthetic:!0},{text:Q.payloadText,synthetic:!0}]}),p("chat");return}if(!d){H.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}P(Q.visibleText,"replace"),C([{text:Q.instructionsText,synthetic:!0},{text:Q.payloadText,synthetic:!0}]),p("chat")},[d,p,E,D,P,C,c]),T=$e.useCallback(async()=>{if(x.kind==="ready"){if(x.plan.commits.length===0){H.message(c("gitView.integrate.noCommitsToMoveToast"));return}g({kind:"running",plan:x.plan});try{const $=await W1(x.plan);if($.kind==="success"){H.success(c("gitView.integrate.commitsMovedToast"),{description:$.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:$.moved,branch:x.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:$.moved,branch:x.plan.targetBranch})});const z=await Ii(x.plan);g({kind:"ready",plan:z}),o?.();return}$.kind==="conflict"&&(H.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),g({kind:"conflict",state:$.state,details:$.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify($.state)))}catch($){const z=$ instanceof Error?$.message:String($);H.error(c("gitView.integrate.failedToMoveToast"),{description:z});const Q=await Ii({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(Q?{kind:"ready",plan:Q}:{kind:"idle"})}}},[x,o,t,e,b,j,c]),M=$e.useCallback(async()=>{if(x.kind==="conflict")try{await K1(x.state),H.message(c("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const $=await Ii({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g($?{kind:"ready",plan:$}:{kind:"idle"})}},[x,t,e,b,j,c]),F=$e.useCallback(async()=>{if(x.kind==="conflict")try{const $=await H1(x.state);if($.kind==="success"){H.success(c("gitView.integrate.cherryPickFinishedToast"));const z=await Ii({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(z?{kind:"ready",plan:z}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),o?.();return}$.kind==="conflict"&&(g({kind:"conflict",state:$.state,details:$.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify($.state)))}catch($){const z=$ instanceof Error?$.message:String($);H.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:z})}},[x,t,e,b,o,j,c]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(I,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.integrate.title")}),x.kind==="ready"&&x.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:c("gitView.integrate.toMoveCount",{count:x.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:x.kind==="loading"||x.kind==="running"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",b]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(Fs,{open:m,onOpenChange:u,children:[s.jsx(Es,{asChild:!0,children:s.jsxs(xe,{variant:"outline",size:"sm",className:"gap-1.5",children:[c("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:b}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(Rs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(Oa,{className:"h-full min-h-0",children:[s.jsx(oa,{ref:f,placeholder:c("gitView.branch.searchPlaceholder"),onKeyDown:$=>$.stopPropagation()}),s.jsxs(La,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx($a,{children:c("gitView.branch.empty")}),s.jsx(Rn,{heading:c("gitView.branch.localBranches"),children:r.map($=>s.jsx(kn,{value:$,onSelect:()=>{h($),S($),u(!1)},children:$},$))})]})]})})]}),x.kind==="ready"?s.jsx(xe,{size:"sm",onClick:()=>{T()},disabled:!v||x.plan.commits.length===0,children:c("gitView.integrate.move")}):x.kind==="loading"?s.jsx(xe,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):x.kind==="running"?s.jsx(xe,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.moving")}):null]}),x.kind==="ready"&&x.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.noCommitsToMove")}),x.kind==="ready"&&x.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[c("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",x.plan.commits.length,")"]})]}),k.length>0&&x.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>y($=>!$),className:"typography-micro text-muted-foreground hover:text-foreground",children:c(w?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(w?k:k.slice(0,5)).map($=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:$.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:$.subject||$.sha})]},$.sha)),k.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.previewUnavailable")}),x.plan.commits.length>k.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c("gitView.integrate.showingFirstCommits",{count:k.length})})]})]}),x.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:c("gitView.integrate.conflictsInFiles",{count:x.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[c("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:x.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[x.details.unmergedFiles.slice(0,6).map($=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:$},$)),x.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:c("gitView.integrate.moreFiles",{count:x.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(xe,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{M()},children:c("gitView.operation.abort")}),s.jsxs(xe,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{N({state:x.state,details:x.details},!1)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(xe,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{N({state:x.state,details:x.details},!0)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(xe,{size:"sm",className:"typography-meta",onClick:()=>{F()},children:c("gitView.operation.continue")})]})]})]})]})},q1=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Y1=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:o=[],disabled:c=!1})=>{const{t:d}=pt(),[p,m]=l.useState(!1),[u,f]=l.useState(""),[b,h]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(""),[y,k]=l.useState(!1),A=l.useRef(null),j=l.useCallback(B=>{B.stopPropagation()},[]),S=o.length>1,D=l.useMemo(()=>q1(g),[g]),E=l.useMemo(()=>{const B=u.toLowerCase();return B?e.filter(V=>V.toLowerCase().includes(B)):e},[u,e]),P=l.useMemo(()=>{const B=u.toLowerCase();return B?n.filter(V=>V.toLowerCase().includes(B)):n},[u,n]),C=B=>{if(B===t){m(!1);return}a(B),m(!1),f("")},N=()=>{h(!0),setTimeout(()=>A.current?.focus(),50)},T=async()=>{if(!(!D||y)){if(S){x(!0);return}k(!0);try{await i(D,o[0]),w(""),h(!1),m(!1)}finally{k(!1)}}},M=async B=>{if(!(!D||y)){k(!0);try{await i(D,B),w(""),h(!1),x(!1),m(!1)}finally{k(!1)}}},F=()=>{x(!1)},_=()=>{w(""),h(!1),x(!1)};return l.useEffect(()=>{p||(f(""),h(!1),x(!1),w(""))},[p]),s.jsxs(Fs,{open:p,onOpenChange:m,children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsxs(xe,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:c,children:[s.jsx(I,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:t||d("gitView.branch.detachedHead")}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),s.jsx(Ct,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(Rs,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(Oa,{className:"h-full min-h-0",children:[s.jsx(oa,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:f,onKeyDown:j}),s.jsxs(La,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx($a,{children:d("gitView.branch.empty")}),s.jsx(Rn,{children:v?s.jsxs("div",{className:"px-2 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("button",{type:"button",onClick:F,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(I,{name:"arrow-left",className:"size-4"})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d("gitView.branch.pushToPrefix")," ",s.jsx("span",{className:"text-foreground font-medium",children:D})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:o.map(B=>s.jsxs("button",{type:"button",onClick:()=>M(B),disabled:y,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[y?s.jsx(I,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,B.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:B.pushUrl})]},B.name))})]}):b?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:A,placeholder:d("gitView.branch.newBranchPlaceholder"),value:g,onChange:B=>w(B.target.value),onClick:B=>B.stopPropagation(),onKeyDown:B=>{j(B),B.key==="Enter"?(B.preventDefault(),T()):B.key==="Escape"&&(B.preventDefault(),_())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:T,disabled:!D||y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:_,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(I,{name:"close",className:"size-4"})})]}):s.jsxs(kn,{onSelect:N,children:[s.jsx(I,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(ka,{}),s.jsxs(Rn,{heading:d("gitView.branch.localBranches"),children:[E.map(B=>s.jsxs(kn,{onSelect:()=>C(B),children:[s.jsxs("span",{className:"flex flex-1 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:B}),(r?.[B]?.ahead||r?.[B]?.behind)&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[B].ahead||0," ahead ·"," ",r[B].behind||0," behind"]})]}),t===B&&s.jsx("span",{className:"typography-micro text-primary",children:d("gitView.branch.currentBadge")})]},`local-${B}`)),E.length===0&&s.jsx(kn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(ka,{}),s.jsxs(Rn,{heading:d("gitView.branch.remoteBranches"),children:[P.map(B=>s.jsx(kn,{onSelect:()=>C(B),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:B})},`remote-${B}`)),P.length===0&&s.jsx(kn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},J1=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Q1=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=pt(),[a,i]=l.useState(!1),[o,c]=l.useState(t||""),[d,p]=l.useState(!1),m=l.useRef(null),u=()=>{!t||!e||(c(t),i(!0),setTimeout(()=>m.current?.focus(),0))},f=async()=>{if(!t||!e||!o.trim())return;const v=J1(o);if(v===t){i(!1);return}p(!0);try{await e(t,v),i(!1),c("")}finally{p(!1)}},b=()=>{i(!1),c("")},h=v=>{v.key==="Enter"?(v.preventDefault(),f()):v.key==="Escape"&&(v.preventDefault(),b())};return a?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:v=>{v.preventDefault(),f()},children:[s.jsx(I,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:o,onChange:v=>c(v.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown: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(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:b,disabled:d,"aria-label":r("gitView.branch.renameCancel"),title:r("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(I,{name:"close",className:"size-4"})})]})}):s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[s.jsx(I,{name:"git-branch",className:"size-4 text-primary shrink-0"}),s.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:t||r("gitView.branch.detachedHead")}),n&&e&&t&&s.jsx(xe,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(I,{name:"edit",className:"size-4"})})]})]})},X1=t=>{const e=ot.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:o,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:f}=t,b=r===void 0?[]:r,h=d===void 0?null:d,v=p===void 0?0:p,x=m===void 0?0:m,g=f===void 0?!1:f,{t:w}=pt(),y=l.useRef(!1),k=!!h,A=b.find(pe=>pe.name===u)??b[0],j=x>0&&g,S=c||n!==null||k||!A||j,D=c||n!==null||k||b.length===0,E=v>0||x>0;let P;e[0]!==w?(P=w("gitView.sync.sync"),e[0]=w,e[1]=P):P=e[1];const C=x>0?`↓${x}`:null,N=v>0?`↑${v}`:null;let T;e[2]!==P||e[3]!==C||e[4]!==N?(T=[P,C,N].filter(Boolean),e[2]=P,e[3]=C,e[4]=N,e[5]=T):T=e[5];const M=T.join(" "),F=j?w("gitView.sync.commitOrStashTooltip"):A?E?w("gitView.sync.syncChangesTooltip",{ahead:v,behind:x}):w("gitView.sync.syncChanges"):w("gitView.sync.noRemoteTooltip"),_=()=>{A&&i(A)},B="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=ue("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=V):V=e[6];let $;e[7]!==w?($=w("gitView.sync.syncChanges"),e[7]=w,e[8]=$):$=e[8];let z;e[9]!==n?(z=n==="sync"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=z):z=e[10];let Q;e[11]!==M?(Q=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:M}),e[11]=M,e[12]=Q):Q=e[12];let L;e[13]!==_||e[14]!==S||e[15]!==$||e[16]!==z||e[17]!==Q?(L=s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:_,disabled:S,className:V,"aria-label":$,children:[z,Q]})}),e[13]=_,e[14]=S,e[15]=$,e[16]=z,e[17]=Q,e[18]=L):L=e[18];let J;e[19]!==F?(J=s.jsx(Ct,{sideOffset:8,children:F}),e[19]=F,e[20]=J):J=e[20];let ee;e[21]!==L||e[22]!==J?(ee=s.jsxs(St,{children:[L,J]}),e[21]=L,e[22]=J,e[23]=ee):ee=e[23];const re=Fs;let q;e[24]===Symbol.for("react.memo_cache_sentinel")?(q=ue("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[24]=q):q=e[24];let ce;e[25]!==w?(ce=w("gitView.sync.moreActionsAria"),e[25]=w,e[26]=ce):ce=e[26];let ae;e[27]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(I,{name:"arrow-down-s",className:"size-4"}),e[27]=ae):ae=e[27];let R;e[28]!==D||e[29]!==ce?(R=s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:q,disabled:D,"aria-label":ce,children:ae})}),e[28]=D,e[29]=ce,e[30]=R):R=e[30];const U=Rs,W="start",Z=-40,K="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ie=b.map(pe=>s.jsx($t,{onSelect:je=>{if(y.current){je.preventDefault(),y.current=!1;return}a(pe)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(I,{name:"refresh",className:"size-4 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:w("gitView.sync.fetchFromRemote",{name:pe.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:pe.fetchUrl})]})}),o&&pe.name!==u?s.jsx(xe,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||k,onPointerDown:je=>{y.current=!0,je.preventDefault(),je.stopPropagation()},onClick:je=>{y.current=!0,je.preventDefault(),je.stopPropagation(),o(pe)},"aria-label":w("gitView.header.removeRemoteAria",{name:pe.name}),title:w("gitView.header.removeRemoteTitle",{name:pe.name}),children:h===pe.name?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"close",className:"size-3.5"})}):null]})},pe.name));let Ne;e[31]!==U||e[32]!==ie?(Ne=s.jsx(U,{align:W,alignOffset:Z,className:K,children:ie}),e[31]=U,e[32]=ie,e[33]=Ne):Ne=e[33];let ne;e[34]!==re||e[35]!==R||e[36]!==Ne?(ne=s.jsxs(re,{children:[R,Ne]}),e[34]=re,e[35]=R,e[36]=Ne,e[37]=ne):ne=e[37];let fe;return e[38]!==ee||e[39]!==ne?(fe=s.jsxs("div",{className:B,children:[ee,ne]}),e[38]=ee,e[39]=ne,e[40]=fe):fe=e[40],fe},Z1={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},ej={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)",success:"var(--status-success)",info:"var(--status-info)",warning:"var(--status-warning)"};function Lh(t){return t&&ej[t]||"var(--primary)"}const mm=t=>{const e=ot.c(8),{icon:n,className:r,colorToken:a}=t,i=Z1[n??"branch"]??"user-3";let o;e[0]!==a?(o=Lh(a),e[0]=a,e[1]=o):o=e[1];let c;e[2]!==o?(c={color:o},e[2]=o,e[3]=c):c=e[3];let d;return e[4]!==r||e[5]!==i||e[6]!==c?(d=s.jsx(I,{name:i,className:r,style:c}),e[4]=r,e[5]=i,e[6]=c,e[7]=d):d=e[7],d},$h=t=>{const e=ot.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:o}=t,c=o===void 0?!1:o,{t:d}=pt(),p=i||r.length===0,m=n?.color;let u;e[0]!==m?(u=Lh(m),e[0]=m,e[1]=u):u=e[1];let f;e[2]!==u?(f={color:u},e[2]=u,e[3]=f):f=e[3];let b;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(b=i?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(mm,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=b):b=e[7];let h;e[8]!==n?.name||e[9]!==c||e[10]!==d?(h=!c&&s.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||d("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=c,e[10]=d,e[11]=h):h=e[11];let v;e[12]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=v):v=e[12];let x;e[13]!==p||e[14]!==f||e[15]!==b||e[16]!==h?(x=s.jsx(kt,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsxs(xe,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:f,disabled:p,children:[b,h,v]})})}),e[13]=p,e[14]=f,e[15]=b,e[16]=h,e[17]=x):x=e[17];let g;e[18]!==d?(g=d("gitView.header.identityTooltip"),e[18]=d,e[19]=g):g=e[19];let w;e[20]!==g?(w=s.jsx(Ct,{sideOffset:8,children:g}),e[20]=g,e[21]=w):w=e[21];let y;e[22]!==w||e[23]!==x?(y=s.jsxs(St,{children:[x,w]}),e[22]=w,e[23]=x,e[24]=y):y=e[24];let k;e[25]!==n?.id||e[26]!==r||e[27]!==a||e[28]!==d?(k=r.length===0?s.jsx("div",{className:"px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:d("gitView.header.noProfiles")})}):r.map(S=>{const D=n?.id===S.id;return s.jsx($t,{onSelect:()=>a(S),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(mm,{icon:S.icon,colorToken:S.color,className:"size-4"}),s.jsxs("span",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:S.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:S.userEmail})]}),D?s.jsx(I,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},S.id)}),e[25]=n?.id,e[26]=r,e[27]=a,e[28]=d,e[29]=k):k=e[29];let A;e[30]!==k?(A=s.jsx(Rs,{align:"end",className:"w-64",children:k}),e[30]=k,e[31]=A):A=e[31];let j;return e[32]!==y||e[33]!==A?(j=s.jsxs(Fs,{children:[y,A]}),e[32]=y,e[33]=A,e[34]=j):j=e[34],j},tj=t=>{const e=ot.c(48),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:f,onCreateBranch:b,onRenameBranch:h,activeIdentityProfile:v,availableIdentities:x,onSelectIdentity:g,isApplyingIdentity:w,isWorktreeMode:y,onOpenHistory:k,actionTabItems:A,activeActionTab:j,onSelectActionTab:S}=t,{t:D}=pt();if(!n)return null;let E;e[0]!==k||e[1]!==D?(E=k?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:k,children:s.jsx(I,{name:"history",className:"size-4"})})}),s.jsx(Ct,{sideOffset:8,children:D("gitView.history.title")})]}):null,e[0]=k,e[1]=D,e[2]=E):E=e[2];let P;e[3]!==E?(P=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:E}),e[3]=E,e[4]=P):P=e[4];const C=P,N=!n;let T;e[5]!==n.tracking?(T=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=T):T=e[6];const M=(n.files?.length??0)>0;let F;e[7]!==d||e[8]!==m||e[9]!==p||e[10]!==c||e[11]!==u||e[12]!==n.ahead||e[13]!==n.behind||e[14]!==o||e[15]!==N||e[16]!==T||e[17]!==M?(F=s.jsx(X1,{syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:N,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:T,hasUncommittedChanges:M}),e[7]=d,e[8]=m,e[9]=p,e[10]=c,e[11]=u,e[12]=n.ahead,e[13]=n.behind,e[14]=o,e[15]=N,e[16]=T,e[17]=M,e[18]=F):F=e[18];const _=F;let B;e[19]!==v||e[20]!==x||e[21]!==w||e[22]!==g?(B=s.jsx($h,{activeProfile:v,identities:x,onSelect:g,isApplying:w,iconOnly:!0}),e[19]=v,e[20]=x,e[21]=w,e[22]=g,e[23]=B):B=e[23];const V=B;let $;e[24]!==i||e[25]!==y||e[26]!==r||e[27]!==f||e[28]!==b||e[29]!==h||e[30]!==a||e[31]!==c||e[32]!==n.current?($=s.jsx("div",{className:"min-w-0 flex-1",children:y?s.jsx(Q1,{currentBranch:n.current,onRename:h}):s.jsx(Y1,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:f,onCreate:b,remotes:c})}),e[24]=i,e[25]=y,e[26]=r,e[27]=f,e[28]=b,e[29]=h,e[30]=a,e[31]=c,e[32]=n.current,e[33]=$):$=e[33];let z;e[34]!==V||e[35]!==C?(z=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[C,V]}),e[34]=V,e[35]=C,e[36]=z):z=e[36];let Q;e[37]!==$||e[38]!==z?(Q=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[$,z]}),e[37]=$,e[38]=z,e[39]=Q):Q=e[39];let L;e[40]!==A||e[41]!==j||e[42]!==S||e[43]!==_?(L=A&&j&&S?s.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(Er,{items:A,activeId:j,onSelect:S,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:_})]}):null,e[40]=A,e[41]=j,e[42]=S,e[43]=_,e[44]=L):L=e[44];let J;return e[45]!==Q||e[46]!==L?(J=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[Q,L]}),e[45]=Q,e[46]=L,e[47]=J):J=e[47],J},sj=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,uncommittedFileCount:a,onChanged:i})=>{const{t:o}=pt(),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(""),[b,h]=l.useState(""),[v,x]=l.useState(null),[g,w]=l.useState({}),y=l.useCallback(async()=>{if(n){m(!0);try{const E=await cb(n);d(E.stashes),w({})}catch(E){H.error(E instanceof Error?E.message:o("gitView.stashes.toast.loadFailed"))}finally{m(!1)}}},[n,o]);l.useEffect(()=>{t&&y()},[y,t]),l.useEffect(()=>{if(!t||!n||c.length===0)return;let E=!1;const P=c.map(C=>C.ref);return db(n,P).then(C=>{E||w(C.counts)}).catch(()=>{}),()=>{E=!0}},[n,t,c]);const k=l.useMemo(()=>{const E=u.trim().toLowerCase();return E?c.filter(P=>`${P.ref} ${P.message} ${P.relativeTime}`.toLowerCase().includes(E)):c},[u,c]),A=l.useCallback(async()=>{await y(),await i?.()},[y,i]),j=async()=>{if(!(!n||v)){x("create");try{(await ub(n,{message:b.trim()||void 0})).created?(H.success(o("gitView.stashes.toast.created")),h("")):H.info(o("gitView.stashes.toast.noChanges")),await A()}catch(E){H.error(E instanceof Error?E.message:o("gitView.stashes.toast.createFailed"))}finally{x(null)}}},S=async(E,P)=>{if(!(!n||v)&&!(P==="drop"&&!window.confirm(o("gitView.stashes.confirm.drop",{ref:E.ref})))){x(`${P}:${E.ref}`);try{P==="apply"&&await mb(n,{ref:E.ref}),P==="pop"&&await pb(n,{ref:E.ref}),P==="drop"&&await fb(n,{ref:E.ref});const C=P==="apply"?"gitView.stashes.toast.applySuccess":P==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";H.success(o(C)),await A()}catch(C){const N=P==="apply"?"gitView.stashes.toast.applyFailed":P==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";H.error(C instanceof Error?C.message:o(N)),await A()}finally{x(null)}}},D=v!==null;return s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(vs,{children:[s.jsxs(gs,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"archive-stack",className:"h-5 w-5"}),o("gitView.stashes.title")]}),s.jsx(Ps,{children:o("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(Vt,{value:b,onChange:E=>h(E.target.value),placeholder:o("gitView.stashes.messagePlaceholder"),disabled:D||!r,className:"flex-1"}),s.jsxs(xe,{onClick:j,disabled:!r||D||!n,children:[v==="create"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"inbox-archive",className:"size-4"}),o("gitView.stashes.actions.stashCurrentWithCount",{count:a})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:o("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(I,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(Vt,{value:u,onChange:E=>f(E.target.value),placeholder:o("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:p?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(I,{name:"loader-4",className:"size-5 animate-spin"})}):k.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:o(u?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):k.map((E,P)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:E.message||o("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{children:P===0&&!u.trim()?o("gitView.stashes.latestLabel"):o("gitView.stashes.itemNumber",{number:P+1})})}),s.jsx(Ct,{sideOffset:6,children:E.ref})]})," · ",E.relativeTime," · ",typeof g[E.ref]=="number"?o("gitView.stashes.fileCount",{count:g[E.ref]}):o("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(fc,{label:o("gitView.stashes.actions.apply"),loading:v===`apply:${E.ref}`,onClick:()=>S(E,"apply"),disabled:D,children:s.jsx(I,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(fc,{label:o("gitView.stashes.actions.pop"),loading:v===`pop:${E.ref}`,onClick:()=>S(E,"pop"),disabled:D,children:s.jsx(I,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(fc,{label:o("gitView.stashes.actions.drop"),loading:v===`drop:${E.ref}`,onClick:()=>S(E,"drop"),disabled:D,destructive:!0,children:s.jsx(I,{name:"delete-bin",className:"size-4"})})]})]},E.ref))})]})})},fc=t=>{const e=ot.c(17),{label:n,loading:r,disabled:a,destructive:i,onClick:o,children:c}=t,d=r||void 0,p=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let m;e[0]!==p?(m=ue("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",p),e[0]=p,e[1]=m):m=e[1];let u;e[2]!==c||e[3]!==r?(u=r?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):c,e[2]=c,e[3]=r,e[4]=u):u=e[4];let f;e[5]!==a||e[6]!==n||e[7]!==o||e[8]!==d||e[9]!==m||e[10]!==u?(f=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:o,disabled:a,children:u})}),e[5]=a,e[6]=n,e[7]=o,e[8]=d,e[9]=m,e[10]=u,e[11]=f):f=e[11];let b;e[12]!==n?(b=s.jsx(Ct,{sideOffset:6,children:n}),e[12]=n,e[13]=b):b=e[13];let h;return e[14]!==f||e[15]!==b?(h=s.jsxs(St,{children:[f,b]}),e[14]=f,e[15]=b,e[16]=h):h=e[16],h},Bh={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}},nj=Bh.M;function rj(t){const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"}function aj(t){const e=rj(t);return Bh[e]??nj}const pm=l.memo(function(e){const n=ot.c(71),{file:r,checked:a,onToggle:i,onViewDiff:o,onRevert:c,isReverting:d,stats:p,rowPaddingClassName:m,indentPx:u}=e,f=u===void 0?0:u;let b;n[0]!==r?(b=aj(r),n[0]=r,n[1]=b):b=n[1];const h=b,{t:v}=pt(),x=h.description,g=p?.insertions??0,w=p?.deletions??0;let y;n[2]!==i||n[3]!==o?(y=R=>{R.key===" "?(R.preventDefault(),i()):R.key==="Enter"&&(R.preventDefault(),o())},n[2]=i,n[3]=o,n[4]=y):y=n[4];const k=y;let A;n[5]!==c?(A=R=>{R.preventDefault(),R.stopPropagation(),c()},n[5]=c,n[6]=A):A=n[6];const j=A,S=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${m??"px-3"}`;let D;n[7]!==f?(D=f>0?{paddingLeft:`${f}px`}:void 0,n[7]=f,n[8]=D):D=n[8];let E;n[9]!==i?(E=()=>i(),n[9]=i,n[10]=E):E=n[10];let P;n[11]!==r.path||n[12]!==v?(P=v("gitView.changes.selectFileAria",{path:r.path}),n[11]=r.path,n[12]=v,n[13]=P):P=n[13];let C;n[14]!==a||n[15]!==E||n[16]!==P?(C=s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",onClick:ij,children:s.jsx(ds,{size:"sm",checked:a,onChange:E,ariaLabel:P})}),n[14]=a,n[15]=E,n[16]=P,n[17]=C):C=n[17];let N;n[18]!==h.color?(N={color:h.color},n[18]=h.color,n[19]=N):N=n[19];let T;n[20]!==h.code||n[21]!==x||n[22]!==N?(T=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:N,title:x,"aria-label":x,children:h.code}),n[20]=h.code,n[21]=x,n[22]=N,n[23]=T):T=n[23];let M;n[24]!==r.path?(M=s.jsx(vr,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[24]=r.path,n[25]=M):M=n[25];let F;if(n[26]!==r.path){e:{const R=r.path.lastIndexOf("/");if(R===-1){let ne;n[28]===Symbol.for("react.memo_cache_sentinel")?(ne={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[28]=ne):ne=n[28],F=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:ne,title:r.path,children:r.path});break e}const U=r.path.slice(0,R),W=r.path.slice(R);let Z;n[29]===Symbol.for("react.memo_cache_sentinel")?(Z={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[29]=Z):Z=n[29];let K;n[30]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[30]=K):K=n[30];const ie=s.jsx("span",{className:"text-foreground",children:W.slice(1)});let Ne;n[31]!==ie?(Ne=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[K,ie]}),n[31]=ie,n[32]=Ne):Ne=n[32],F=s.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:r.path,children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:Z,children:U}),Ne]})}n[26]=r.path,n[27]=F}else F=n[27];let _;n[33]===Symbol.for("react.memo_cache_sentinel")?(_={color:"var(--status-success)"},n[33]=_):_=n[33];let B;n[34]!==g?(B=s.jsxs("span",{style:_,children:["+",g]}),n[34]=g,n[35]=B):B=n[35];let V,$;n[36]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),$={color:"var(--status-error)"},n[36]=V,n[37]=$):(V=n[36],$=n[37]);let z;n[38]!==w?(z=s.jsxs("span",{style:$,children:["-",w]}),n[38]=w,n[39]=z):z=n[39];let Q;n[40]!==B||n[41]!==z?(Q=s.jsxs("span",{className:"shrink-0 typography-micro",children:[B,V,z]}),n[40]=B,n[41]=z,n[42]=Q):Q=n[42];let L;n[43]!==r.path||n[44]!==v?(L=v("gitView.changes.revertFileAria",{path:r.path}),n[43]=r.path,n[44]=v,n[45]=L):L=n[45];let J;n[46]!==d?(J=d?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"arrow-go-back",className:"size-3.5"}),n[46]=d,n[47]=J):J=n[47];let ee;n[48]!==j||n[49]!==d||n[50]!==L||n[51]!==J?(ee=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,disabled:d,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":L,children:J})}),n[48]=j,n[49]=d,n[50]=L,n[51]=J,n[52]=ee):ee=n[52];let re;n[53]!==v?(re=v("gitView.changes.revertFileTooltip"),n[53]=v,n[54]=re):re=n[54];let q;n[55]!==re?(q=s.jsx(Ct,{sideOffset:8,children:re}),n[55]=re,n[56]=q):q=n[56];let ce;n[57]!==ee||n[58]!==q?(ce=s.jsxs(St,{children:[ee,q]}),n[57]=ee,n[58]=q,n[59]=ce):ce=n[59];let ae;return n[60]!==k||n[61]!==o||n[62]!==T||n[63]!==M||n[64]!==F||n[65]!==Q||n[66]!==ce||n[67]!==S||n[68]!==D||n[69]!==C?(ae=s.jsxs("div",{className:S,role:"button",tabIndex:0,onClick:o,onKeyDown:k,style:D,children:[C,T,M,F,Q,ce]}),n[60]=k,n[61]=o,n[62]=T,n[63]=M,n[64]=F,n[65]=Q,n[66]=ce,n[67]=S,n[68]=D,n[69]=C,n[70]=ae):ae=n[70],ae});function ij(t){t.stopPropagation()}const oj=1e3,lj=34,fm=14,_h=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),hm=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),cj=t=>{const e=hm("","");for(const n of t){const r=_h(n.path);if(!r)continue;const i=r.split("/").filter(Boolean).slice(0,-1);let o=e;if(o.files.push(n),i.length>0){let c="";for(const d of i){c=c?`${c}/${d}`:d;const p=o.children.get(d);if(p){p.files.push(n),o=p;continue}const m=hm(c,d);m.files.push(n),o.children.set(d,m),o=m}}o.directFiles.push(n)}return e},dj=(t,e)=>{const n=[],r=(a,i)=>{const o=Array.from(a.children.values()).sort((d,p)=>d.path.localeCompare(p.path));for(const d of o)n.push({key:d.id,kind:"directory",depth:i,directory:d}),e.has(d.path)&&r(d,i+1);const c=[...a.directFiles].sort((d,p)=>d.path.localeCompare(p.path));for(const d of c)n.push({key:`file:${_h(d.path)}`,kind:"file",depth:i,file:d})};return r(t,0),n},gm=(t,e)=>{if(t.files.length===0)return"none";let n=0;for(const r of t.files)e.has(r.path)&&(n+=1);return n===0?"none":n===t.files.length?"all":"partial"},uj=({changeEntries:t,selectedPaths:e,diffStats:n,revertingPaths:r,onToggleFile:a,onSelectAll:i,onClearSelection:o,onRevertAll:c,onViewDiff:d,onRevertFile:p,isRevertingAll:m=!1,maxListHeightClassName:u,onVisiblePathsChange:f,onOpenStashes:b})=>{const{t:h}=pt(),v=l.useRef(null),g=De(ae=>ae.gitChangesViewMode)==="tree",w=e.size,y=t.length,[k,A]=l.useState(!1),j=l.useMemo(()=>cj(t),[t]),[S,D]=l.useState(new Set),E=l.useMemo(()=>Array.from(j.children.values()).map(ae=>ae.path),[j]);l.useEffect(()=>{g&&D(ae=>{const R=new Set,U=new Set(E);return ae.forEach(W=>{if(W.includes("/")){R.add(W);return}U.has(W)&&R.add(W)}),E.forEach(W=>R.add(W)),R})},[g,E]);const P=l.useMemo(()=>dj(j,S),[S,j]),C=l.useMemo(()=>g?P:t,[t,g,P]),N=C.length,T=N>=oj,M=w>0,F=y>0&&w===y,_=M&&!F,B=Rf({count:N,getScrollElement:()=>v.current,estimateSize:()=>lj,overscan:10,enabled:T});l.useEffect(()=>{if(!T)return;const ae=v.current;if(!ae)return;const R=new ResizeObserver(()=>{B.measure()});return R.observe(ae),()=>R.disconnect()},[T,B]);const V=B.getTotalSize(),$=l.useMemo(()=>T&&V>=0?B.getVirtualItems():[],[T,B,V]);l.useEffect(()=>{if(!f)return;if(N===0){f([]);return}const ae=R=>{if(!g)return R.path;const U=R;return U.kind==="file"?U.file.path:null};if(!T){f(C.slice(0,Math.min(30,N)).map(R=>ae(R)).filter(R=>!!R));return}f($.map(R=>C[R.index]).map(R=>R?ae(R):null).filter(R=>!!R))},[g,f,N,C,T,$]);const z="flex flex-col flex-1 min-h-0",Q="flex items-center justify-between gap-2 px-0 py-3 border-b border-border/40",L=`flex-1 min-h-0 pr-0 ${u??""}`.trim(),J="pl-0 pr-2",ee=l.useCallback(ae=>{D(R=>{const U=new Set(R);return U.has(ae)?U.delete(ae):U.add(ae),U})},[]),re=l.useCallback(ae=>{const U=gm(ae,e)!=="all";for(const W of ae.files){const Z=e.has(W.path);(U&&!Z||!U&&Z)&&a(W.path)}},[a,e]),q=l.useCallback(ae=>{if(!g){const K=ae;return s.jsx(pm,{file:K,checked:e.has(K.path),stats:n?.[K.path],onToggle:()=>a(K.path),onViewDiff:()=>d(K.path),onRevert:()=>p(K.path),isReverting:r.has(K.path)||m,rowPaddingClassName:J})}const R=ae;if(R.kind==="file"){const K=R.file;return s.jsx(pm,{file:K,checked:e.has(K.path),stats:n?.[K.path],onToggle:()=>a(K.path),onViewDiff:()=>d(K.path),onRevert:()=>p(K.path),isReverting:r.has(K.path)||m,rowPaddingClassName:J,indentPx:R.depth*fm})}const U=R.directory,W=S.has(U.path),Z=gm(U,e);return s.jsxs("div",{className:ue("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",J),style:{paddingLeft:`${R.depth*fm}px`},children:[s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",children:s.jsx(ds,{size:"sm",checked:Z==="all",indeterminate:Z==="partial",onChange:()=>re(U),ariaLabel:h("gitView.changes.toggleDirectorySelectionAria",{path:U.path})})}),s.jsxs("button",{type:"button",onClick:()=>ee(U.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":W?h("gitView.changes.collapseDirectoryAria",{path:U.path}):h("gitView.changes.expandDirectoryAria",{path:U.path}),children:[W?s.jsx(I,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:U.path,children:U.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:U.files.length})]})]})},[n,S,m,g,p,a,d,r,J,e,h,ee,re]),ce=l.useCallback(async()=>{!c||m||t.length===0||(await c(t.map(ae=>ae.path)),A(!1))},[t,m,c]);return s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:z,children:[s.jsxs("header",{className:Q,children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:h("gitView.changes.title")}),y>0?s.jsxs("div",{className:ue("inline-flex h-6 items-center gap-1 rounded px-1.5",m&&"cursor-not-allowed opacity-50"),children:[s.jsx(ds,{size:"sm",checked:M,indeterminate:_,disabled:m,onChange:()=>F?o():i(),ariaLabel:h(F?"gitView.changes.clearSelectionAria":"gitView.changes.selectAllAria")}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[w,"/",y]})]}):null,b?s.jsx(xe,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-1.5",onClick:b,"aria-label":h("gitView.stashes.title"),title:h("gitView.stashes.title"),children:s.jsx(I,{name:"archive-stack",className:"size-4"})}):null]}),s.jsx("div",{className:"flex items-center gap-2 pr-1",children:y>0&&c?s.jsx(xe,{variant:"destructive",size:"xs",onClick:()=>A(!0),disabled:m,children:h("gitView.changes.revertAll")}):null})]}),s.jsxs("div",{className:ue("relative flex flex-col min-h-0 w-full overflow-hidden",L),children:[s.jsx(io,{ref:v,className:"overlay-scrollbar-target overlay-scrollbar-container flex-1 min-h-0 w-full overflow-y-auto overflow-x-hidden",children:T?s.jsx("div",{className:"relative w-full",style:{height:`${B.getTotalSize()}px`},children:$.map(ae=>{const R=C[ae.index];if(!R)return null;const U=g?R.key:`file:${R.path}`;return s.jsx("div",{ref:B.measureElement,"data-index":ae.index,className:ue("absolute left-0 top-0 w-full",ae.index>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),style:{transform:`translateY(${ae.start}px)`},children:q(R)},U)})}):s.jsx("div",{role:"list","aria-label":h("gitView.changes.changedFilesAria"),children:C.map((ae,R)=>s.jsx("div",{className:ue("relative",R>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:q(ae)},g?ae.key:`file:${ae.path}`))})}),s.jsx(hb,{containerRef:v,disableHorizontal:!0})]})]}),s.jsx(ps,{open:k,onOpenChange:ae=>{m||A(ae)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:h("gitView.changes.revertAllDialogTitle")}),s.jsx(Ps,{children:y===1?h("gitView.changes.revertAllDescriptionSingle",{count:y}):h("gitView.changes.revertAllDescriptionPlural",{count:y})})]}),s.jsxs(Us,{children:[s.jsx(xe,{variant:"outline",size:"sm",onClick:()=>A(!1),disabled:m,children:h("gitView.common.cancel")}),s.jsx(xe,{variant:"destructive",size:"sm",onClick:()=>{ce()},disabled:m,children:h(m?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},hc=38,Co=200,mj=t=>{const e=ot.c(20),{value:n,onChange:r,placeholder:a,disabled:i,hasTouchInput:o,isMobile:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=c===void 0?!1:c,{t:u}=pt(),f=l.useRef(null),b=De(pj);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const E=f.current;if(!E)return;const P=document.activeElement===E,C=()=>{E.style.height=`${hc}px`;const T=E.scrollHeight,M=Math.min(Math.max(T,hc),Co);E.style.height=`${M}px`,E.style.overflowY=T>Co?"auto":"hidden",T>Co&&!P&&(E.scrollTop=E.scrollHeight)};C();const N=window.requestAnimationFrame(C);return()=>{window.cancelAnimationFrame(N)}},e[0]=h):h=e[0];let v;e[1]!==n?(v=[n],e[1]=n,e[2]=v):v=e[2],l.useLayoutEffect(h,v);let x;e[3]!==r?(x=E=>r(E.target.value),e[3]=r,e[4]=x):x=e[4];let g;e[5]!==a||e[6]!==u?(g=a??u("gitView.commit.messagePlaceholder"),e[5]=a,e[6]=u,e[7]=g):g=e[7];const w=p?"on":"off",y=p?"sentences":"off",k=m||b,A=d&&"opacity-50";let j;e[8]!==A?(j=ue("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",A),e[8]=A,e[9]=j):j=e[9];let S;e[10]===Symbol.for("react.memo_cache_sentinel")?(S={minHeight:hc,maxHeight:Co},e[10]=S):S=e[10];let D;return e[11]!==d||e[12]!==k||e[13]!==j||e[14]!==x||e[15]!==g||e[16]!==w||e[17]!==y||e[18]!==n?(D=s.jsx("textarea",{ref:f,value:n,onChange:x,placeholder:g,rows:1,disabled:d,autoCorrect:w,autoCapitalize:y,spellCheck:k,className:j,style:S}),e[11]=d,e[12]=k,e[13]=j,e[14]=x,e[15]=g,e[16]=w,e[17]=y,e[18]=n,e[19]=D):D=e[19],D};function pj(t){return t.inputSpellcheckEnabled}const fj=t=>{const e=ot.c(30),{highlights:n,onInsert:r}=t,{t:a}=pt();if(n.length===0)return null;let i;e[0]!==n||e[1]!==r?(i=()=>{r(n)},e[0]=n,e[1]=r,e[2]=i):i=e[2];const o=i;let c;e[3]!==a?(c=a("gitView.commit.aiHighlights.title"),e[3]=a,e[4]=c):c=e[4];let d;e[5]!==c?(d=s.jsx("p",{className:"typography-micro text-muted-foreground",children:c}),e[5]=c,e[6]=d):d=e[6];let p;e[7]!==a?(p=a("gitView.commit.aiHighlights.insertAria"),e[7]=a,e[8]=p):p=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(I,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==o||e[11]!==p?(u=s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"icon",className:"size-6",onClick:o,"aria-label":p,children:m})}),e[10]=o,e[11]=p,e[12]=u):u=e[12];let f;e[13]!==a?(f=a("gitView.commit.aiHighlights.insertTooltip"),e[13]=a,e[14]=f):f=e[14];let b;e[15]!==f?(b=s.jsx(Ct,{sideOffset:8,children:f}),e[15]=f,e[16]=b):b=e[16];let h;e[17]!==u||e[18]!==b?(h=s.jsxs(St,{children:[u,b]}),e[17]=u,e[18]=b,e[19]=h):h=e[19];let v;e[20]!==d||e[21]!==h?(v=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,h]}),e[20]=d,e[21]=h,e[22]=v):v=e[22];let x;e[23]!==n?(x=n.map(hj),e[23]=n,e[24]=x):x=e[24];let g;e[25]!==x?(g=s.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=g):g=e[26];let w;return e[27]!==v||e[28]!==g?(w=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[v,g]}),e[27]=v,e[28]=g,e[29]=w):w=e[29],w};function hj(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const gj=t=>{const e=ot.c(72),{selectedCount:n,commitMessage:r,onCommitMessageChange:a,generatedHighlights:i,onInsertHighlights:o,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,gitmojiEnabled:f,onOpenGitmojiPicker:b}=t,{t:h}=pt(),v=n>0;let x;e[0]!==u||e[1]!==r||e[2]!==v?(x=r.trim()&&v&&u===null,e[0]=u,e[1]=r,e[2]=v,e[3]=x):x=e[3];const g=x,{isMobile:w,hasTouchInput:y}=nn();let k;e[4]!==h?(k=h("gitView.commit.title"),e[4]=h,e[5]=k):k=e[5];let A;e[6]!==k?(A=s.jsx("div",{className:"flex w-full items-center justify-between px-0 pt-2 pb-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:k})}),e[6]=k,e[7]=A):A=e[7];let j;e[8]!==v||e[9]!==h?(j=v?null:s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.commit.selectFilesHint")}),e[8]=v,e[9]=h,e[10]=j):j=e[10];let S;e[11]!==i||e[12]!==o?(S=s.jsx(fj,{highlights:i,onInsert:o}),e[11]=i,e[12]=o,e[13]=S):S=e[13];let D;e[14]!==h?(D=h("gitView.commit.messagePlaceholder"),e[14]=h,e[15]=D):D=e[15];const E=u!==null;let P;e[16]!==r||e[17]!==y||e[18]!==w||e[19]!==a||e[20]!==D||e[21]!==E?(P=s.jsx(mj,{value:r,onChange:a,placeholder:D,disabled:E,hasTouchInput:y,isMobile:w}),e[16]=r,e[17]=y,e[18]=w,e[19]=a,e[20]=D,e[21]=E,e[22]=P):P=e[22];let C;e[23]!==f||e[24]!==b||e[25]!==h?(C=f&&s.jsxs(xe,{variant:"outline",size:"sm",onClick:b,className:"w-fit",type:"button",children:[s.jsx(I,{name:"emotion-happy",className:"size-4"}),h("gitView.commit.addGitmoji")]}),e[23]=f,e[24]=b,e[25]=h,e[26]=C):C=e[26];const N=d||u!==null||n===0;let T;e[27]!==h?(T=h("gitView.commit.generateAria"),e[27]=h,e[28]=T):T=e[28];let M;e[29]!==d?(M=d?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4 text-primary"}),e[29]=d,e[30]=M):M=e[30];let F;e[31]!==h?(F=h("gitView.commit.generate"),e[31]=h,e[32]=F):F=e[32];let _;e[33]!==F?(_=s.jsx("span",{className:"commit-actions__label",children:F}),e[33]=F,e[34]=_):_=e[34];let B;e[35]!==c||e[36]!==N||e[37]!==T||e[38]!==M||e[39]!==_?(B=s.jsxs(xe,{variant:"outline",size:"sm",onClick:c,disabled:N,type:"button","aria-label":T,className:"commit-actions__btn",children:[M,_]}),e[35]=c,e[36]=N,e[37]=T,e[38]=M,e[39]=_,e[40]=B):B=e[40];let V;e[41]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("div",{className:"flex-1"}),e[41]=V):V=e[41];const $=!g||d;let z;e[42]!==h?(z=h("gitView.commit.commitAria"),e[42]=h,e[43]=z):z=e[43];let Q;e[44]!==u||e[45]!==h?(Q=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.commit")})]}),e[44]=u,e[45]=h,e[46]=Q):Q=e[46];let L;e[47]!==p||e[48]!==$||e[49]!==z||e[50]!==Q?(L=s.jsx(xe,{size:"sm",variant:"outline",onClick:p,disabled:$,className:"commit-actions__btn whitespace-nowrap","aria-label":z,children:Q}),e[47]=p,e[48]=$,e[49]=z,e[50]=Q,e[51]=L):L=e[51];let J;e[52]!==g||e[53]!==u||e[54]!==d||e[55]!==w||e[56]!==m||e[57]!==h?(J=w?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"default",size:"sm",onClick:()=>m(),disabled:!g||d,className:"h-7 w-7 p-0","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(Ct,{side:"top",children:s.jsx("p",{children:h("gitView.commit.push")})})]}):s.jsx(xe,{size:"sm",variant:"default",onClick:()=>m(),disabled:!g||d,className:"commit-actions__btn","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.push")})]})}),e[52]=g,e[53]=u,e[54]=d,e[55]=w,e[56]=m,e[57]=h,e[58]=J):J=e[58];let ee;e[59]!==B||e[60]!==L||e[61]!==J?(ee=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[B,V,L,J]}),e[59]=B,e[60]=L,e[61]=J,e[62]=ee):ee=e[62];let re;e[63]!==ee||e[64]!==j||e[65]!==S||e[66]!==P||e[67]!==C?(re=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[j,S,P,C,ee]}),e[63]=ee,e[64]=j,e[65]=S,e[66]=P,e[67]=C,e[68]=re):re=e[68];let q;return e[69]!==re||e[70]!==A?(q=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[A,re]}),e[69]=re,e[70]=A,e[71]=q):q=e[71],q},xj=t=>{const e=ot.c(16),{onOpenStashes:n}=t,{t:r}=pt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(I,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=a):a=e[0];let i;e[1]!==r?(i=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=i):i=e[2];let o;e[3]!==i?(o=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=o):o=e[4];let c;e[5]!==r?(c=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=c):c=e[6];let d;e[7]!==c?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:c}),e[7]=c,e[8]=d):d=e[8];let p;e[9]!==n||e[10]!==r?(p=n?s.jsxs(xe,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(I,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=p):p=e[11];let m;return e[12]!==o||e[13]!==d||e[14]!==p?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[a,o,d,p]}),e[12]=o,e[13]=d,e[14]=p,e[15]=m):m=e[15],m};function zh(t){const e=ot.c(63),{draft:n,onEdit:r,onDelete:a,className:i,maxWidth:o}=t,{t:c}=pt(),p=Al()?.currentTheme,[m,u]=$e.useState(!1),f=typeof n.text=="string"?n.text:"";let b;e[0]!==f?(b=f.length>150||f.split(`
|
|
7
|
-
`).length>3,e[0]=f,e[1]=b):b=e[1];const h=b;let v;e[2]!==i?(v=ue("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",i),e[2]=i,e[3]=v):v=e[3];const x=p?.colors?.surface?.elevated,g=p?.colors?.interactive?.border,w=o?`${Math.max(200,Math.floor(o))}px`:void 0;let y;e[4]!==x||e[5]!==g||e[6]!==w?(y={backgroundColor:x,borderColor:g,maxWidth:w},e[4]=x,e[5]=g,e[6]=w,e[7]=y):y=e[7];let k;e[8]!==n.fileLabel?(k=s.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[8]=n.fileLabel,e[9]=k):k=e[9];let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx("span",{children:"•"}),e[10]=A):A=e[10];let j;e[11]!==n.endLine||e[12]!==n.startLine||e[13]!==c?(j=c("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[11]=n.endLine,e[12]=n.startLine,e[13]=c,e[14]=j):j=e[14];let S;e[15]!==j?(S=s.jsx("span",{children:j}),e[15]=j,e[16]=S):S=e[16];let D;e[17]!==n.side?(D=n.side&&s.jsxs("span",{children:["(",n.side,")"]}),e[17]=n.side,e[18]=D):D=e[18];let E;e[19]!==S||e[20]!==D||e[21]!==k?(E=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[k,A,S,D]}),e[19]=S,e[20]=D,e[21]=k,e[22]=E):E=e[22];const P=m||!h,C=!m&&h&&"line-clamp-3";let N;e[23]!==C?(N=ue("text-sm whitespace-pre-wrap break-words leading-relaxed",C),e[23]=C,e[24]=N):N=e[24];let T;e[25]!==f||e[26]!==N?(T=s.jsx("div",{className:N,children:f}),e[25]=f,e[26]=N,e[27]=T):T=e[27];let M;e[28]!==h||e[29]!==m||e[30]!==c?(M=h&&s.jsx(Nr,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"arrow-up-s",className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"arrow-down-s",className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=h,e[29]=m,e[30]=c,e[31]=M):M=e[31];let F;e[32]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(fr,{}),e[32]=F):F=e[32];let _;e[33]!==P||e[34]!==T||e[35]!==M?(_=s.jsxs(pr,{open:P,onOpenChange:u,children:[T,M,F]}),e[33]=P,e[34]=T,e[35]=M,e[36]=_):_=e[36];let B;e[37]!==E||e[38]!==_?(B=s.jsxs("div",{className:"flex-1 min-w-0",children:[E,_]}),e[37]=E,e[38]=_,e[39]=B):B=e[39];let V;e[40]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(Es,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"more",className:"size-4"})})}),e[40]=V):V=e[40];let $;e[41]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(I,{name:"edit",className:"size-4 mr-2"}),e[41]=$):$=e[41];let z;e[42]!==c?(z=c("inlineComment.actions.editComment"),e[42]=c,e[43]=z):z=e[43];let Q;e[44]!==r||e[45]!==z?(Q=s.jsxs($t,{onClick:r,children:[$,z]}),e[44]=r,e[45]=z,e[46]=Q):Q=e[46];let L;e[47]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(I,{name:"delete-bin",className:"size-4 mr-2"}),e[47]=L):L=e[47];let J;e[48]!==c?(J=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=J):J=e[49];let ee;e[50]!==a||e[51]!==J?(ee=s.jsxs($t,{onClick:a,className:"text-destructive",children:[L,J]}),e[50]=a,e[51]=J,e[52]=ee):ee=e[52];let re;e[53]!==Q||e[54]!==ee?(re=s.jsxs(Fs,{children:[V,s.jsxs(Rs,{align:"end",children:[Q,ee]})]}),e[53]=Q,e[54]=ee,e[55]=re):re=e[55];let q;e[56]!==B||e[57]!==re?(q=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[B,re]}),e[56]=B,e[57]=re,e[58]=q):q=e[58];let ce;return e[59]!==v||e[60]!==q||e[61]!==y?(ce=s.jsx("div",{className:v,style:y,"data-comment-card":"true",children:q}),e[59]=v,e[60]=q,e[61]=y,e[62]=ce):ce=e[62],ce}function fl(t){const e=ot.c(57),{initialText:n,onSave:r,onCancel:a,fileLabel:i,lineRange:o,isEditing:c,className:d,maxWidth:p}=t,m=n===void 0?"":n,u=c===void 0?!1:c,{t:f}=pt(),h=Al()?.currentTheme,{isMobile:v}=nn(),[x,g]=l.useState(m),w=$e.useRef(null),y=$e.useRef(o);let k,A;e[0]!==o?(k=()=>{o&&(y.current=o)},A=[o],e[0]=o,e[1]=k,e[2]=A):(k=e[1],A=e[2]),$e.useEffect(k,A);const j=Sj,S=j(o);let D,E;e[3]!==v?(D=()=>{const je=w.current;if(!je)return;const oe=je.closest(".overlay-scrollbar-container"),Se=oe?.scrollTop??window.scrollY,se=oe?.scrollLeft??window.scrollX;if(v){je.scrollIntoView({behavior:"auto",block:"nearest"});try{je.focus({preventScroll:!0})}catch{je.focus()}return}try{je.focus({preventScroll:!0})}catch{je.focus()}const we=je.value.length;try{je.setSelectionRange(we,we)}catch{}requestAnimationFrame(()=>{oe?(oe.scrollTop=Se,oe.scrollLeft=se):window.scrollTo({top:Se,left:se})})},E=[v],e[3]=v,e[4]=D,e[5]=E):(D=e[4],E=e[5]),$e.useEffect(D,E);let P;e[6]!==a||e[7]!==r||e[8]!==x?(P=je=>{(je.metaKey||je.ctrlKey)&&je.key==="Enter"?(je.preventDefault(),x.trim()&&r(x,j(y.current))):je.key==="Escape"&&(je.preventDefault(),a())},e[6]=a,e[7]=r,e[8]=x,e[9]=P):P=e[9];const C=P;let N;e[10]!==r||e[11]!==x?(N=je=>{je.stopPropagation(),x.trim()&&r(x,j(y.current))},e[10]=r,e[11]=x,e[12]=N):N=e[12];const T=N;let M;e[13]!==d?(M=ue("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",d),e[13]=d,e[14]=M):M=e[14];const F=h?.colors?.surface?.elevated,_=h?.colors?.interactive?.border,B=p?`${Math.max(200,Math.floor(p))}px`:void 0;let V;e[15]!==F||e[16]!==_||e[17]!==B?(V={backgroundColor:F,borderColor:_,maxWidth:B},e[15]=F,e[16]=_,e[17]=B,e[18]=V):V=e[18];const $="true",z=Nj,Q=jj,L="p-3",J=(i||o)&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[i&&s.jsx("span",{className:"truncate max-w-[200px]",children:i}),i&&o&&s.jsx("span",{children:"•"}),S&&s.jsx("span",{children:f("inlineComment.range.lines",{start:S.start,end:S.end})})]});let ee;e[19]===Symbol.for("react.memo_cache_sentinel")?(ee=je=>g(je.target.value),e[19]=ee):ee=e[19];let re;e[20]!==f?(re=f("inlineComment.input.placeholder"),e[20]=f,e[21]=re):re=e[21];let q;e[22]!==C||e[23]!==re||e[24]!==x?(q=s.jsx(fn,{simple:!0,ref:w,value:x,onChange:ee,onKeyDown:C,placeholder:re,outerClassName:"rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]",className:"min-h-[80px] px-3 py-2.5 text-sm resize-y"}),e[22]=C,e[23]=re,e[24]=x,e[25]=q):q=e[25];let ce;e[26]!==f?(ce=f("inlineComment.actions.cancel"),e[26]=f,e[27]=ce):ce=e[27];let ae;e[28]!==a||e[29]!==ce?(ae=s.jsx(xe,{variant:"ghost",size:"sm",onClick:a,onPointerDown:wj,onTouchStart:vj,className:"h-8 text-muted-foreground hover:text-foreground",children:ce}),e[28]=a,e[29]=ce,e[30]=ae):ae=e[30];let R;e[31]!==x?(R=x.trim(),e[31]=x,e[32]=R):R=e[32];const U=!R,W=h?.colors?.status?.success,Z=h?.colors?.status?.successForeground;let K;e[33]!==W||e[34]!==Z?(K={backgroundColor:W,color:Z},e[33]=W,e[34]=Z,e[35]=K):K=e[35];let ie;e[36]!==u||e[37]!==f?(ie=f(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=f,e[38]=ie):ie=e[38];let Ne;e[39]!==T||e[40]!==U||e[41]!==K||e[42]!==ie?(Ne=s.jsx(xe,{size:"sm",onClick:T,onPointerDown:yj,onTouchStart:bj,disabled:U,className:"h-8 min-w-[80px]",style:K,children:ie}),e[39]=T,e[40]=U,e[41]=K,e[42]=ie,e[43]=Ne):Ne=e[43];let ne;e[44]!==ae||e[45]!==Ne?(ne=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[ae,Ne]}),e[44]=ae,e[45]=Ne,e[46]=ne):ne=e[46];let fe;e[47]!==J||e[48]!==q||e[49]!==ne?(fe=s.jsxs("div",{className:L,children:[J,q,ne]}),e[47]=J,e[48]=q,e[49]=ne,e[50]=fe):fe=e[50];let pe;return e[51]!==V||e[52]!==z||e[53]!==Q||e[54]!==fe||e[55]!==M?(pe=s.jsx("div",{className:M,style:V,"data-comment-input":$,onPointerDown:z,onTouchStart:Q,children:fe}),e[51]=V,e[52]=z,e[53]=Q,e[54]=fe,e[55]=M,e[56]=pe):pe=e[56],pe}function bj(t){return t.stopPropagation()}function yj(t){return t.stopPropagation()}function vj(t){return t.stopPropagation()}function wj(t){return t.stopPropagation()}function jj(t){return t.stopPropagation()}function Nj(t){return t.stopPropagation()}function Sj(t){if(!t)return;const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}}const kj=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},hl=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function Gd(t){const e=ot.c(40),{t:n}=pt(),{source:r,fileLabel:a,language:i,getCodeForRange:o,toStoreRange:c,fromDraftRange:d}=t,p=Lt(Tj),m=Lt(Dj),u=ti(Aj),f=ti(Pj),b=ti(Ij),h=ti(Cj),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,k]=l.useState(null),A=p??(m?"draft":null);let j;e:{if(!A||!a){let L;e[0]===Symbol.for("react.memo_cache_sentinel")?(L=[],e[0]=L):L=e[0],j=L;break e}let $;e[1]!==h||e[2]!==A?($=h[A]??[],e[1]=h,e[2]=A,e[3]=$):$=e[3];const z=$;let Q;if(e[4]!==a||e[5]!==z||e[6]!==r){let L;e[8]!==a||e[9]!==r?(L=J=>J.source===r&&J.fileLabel===a,e[8]=a,e[9]=r,e[10]=L):L=e[10],Q=z.filter(L),e[4]=a,e[5]=z,e[6]=r,e[7]=Q}else Q=e[7];j=Q}const S=j;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{x(null),w(""),k(null)},e[11]=D):D=e[11];const E=D;let P;e[12]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{E()},e[12]=P):P=e[12];const C=P;let N;e[13]!==d?(N=$=>{const z=hl(d($));x(z),w($.text),k($.id)},e[13]=d,e[14]=N):N=e[14];const T=N;let M;e[15]!==y||e[16]!==b?(M=$=>{b($.sessionKey,$.id),y===$.id&&E()},e[15]=y,e[16]=b,e[17]=M):M=e[17];const F=M;let _;e[18]!==u||e[19]!==y||e[20]!==a||e[21]!==o||e[22]!==i||e[23]!==v||e[24]!==A||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==f?(_=($,z)=>{const Q=z??v,L=$.trim();if(!Q||!L||!a)return;if(!A){H.error(n("inlineComment.toast.selectSessionToSave"));return}const J=hl(Q),ee=kj(c(J)),re=o(J);y?f(A,y,{fileLabel:a,startLine:ee.startLine,endLine:ee.endLine,side:ee.side,code:re,language:i,text:L}):u({sessionKey:A,source:r,fileLabel:a,startLine:ee.startLine,endLine:ee.endLine,side:ee.side,code:re,language:i,text:L}),E()},e[18]=u,e[19]=y,e[20]=a,e[21]=o,e[22]=i,e[23]=v,e[24]=A,e[25]=r,e[26]=n,e[27]=c,e[28]=f,e[29]=_):_=e[29];const B=_;let V;return e[30]!==g||e[31]!==F||e[32]!==S||e[33]!==y||e[34]!==d||e[35]!==B||e[36]!==v||e[37]!==A||e[38]!==T?(V={sessionKey:A,drafts:S,selection:v,setSelection:x,commentText:g,setCommentText:w,editingDraftId:y,setEditingDraftId:k,reset:E,cancel:C,startEdit:T,deleteDraft:F,saveComment:B,fromDraftRange:d},e[30]=g,e[31]=F,e[32]=S,e[33]=y,e[34]=d,e[35]=B,e[36]=v,e[37]=A,e[38]=T,e[39]=V):V=e[39],V}function Cj(t){return t.drafts}function Ij(t){return t.removeDraft}function Pj(t){return t.updateDraft}function Aj(t){return t.addDraft}function Dj(t){return t.newSessionDraft?.open}function Tj(t){return t.currentSessionId}function Vh(t){const{drafts:e,editingDraftId:n,commentText:r,selection:a,isDragging:i,fileLabel:o,newWidgetId:c,mapDraftToRange:d,onSave:p,onCancel:m,onEdit:u,onDelete:f}=t,b=[];for(const h of e){const v=d(h);if(h.id===n){b.push({afterLine:v.end,id:`edit-${h.id}`,content:s.jsx(fl,{initialText:r,fileLabel:o,lineRange:v,isEditing:!0,onSave:p,onCancel:m},`edit-${h.id}`)});continue}b.push({afterLine:v.end,id:`card-${h.id}`,content:s.jsx(zh,{draft:h,onEdit:()=>u(h),onDelete:()=>f(h)},`card-${h.id}`)})}if(a&&!n&&!i){const h={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};b.push({afterLine:h.end,id:c,content:s.jsx(fl,{initialText:r,fileLabel:o,lineRange:h,isEditing:!1,onSave:p,onCancel:m},c)})}return b}const qo=t=>{if(t.type==="new"){const e=Math.min(t.selection.start,t.selection.end),n=Math.max(t.selection.start,t.selection.end);return`new-comment-${t.selection.side??"additions"}-${e}-${n}`}return`draft-${t.draft.id}`},Mj=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,a=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const o=Math.max(1,Math.floor(i.endLine)),c=i.side==="original"?"deletions":"additions";a.push({lineNumber:o,side:c,metadata:{type:i.id===n?"edit":"saved",draft:i}})}return r&&!n&&a.push({lineNumber:Math.max(r.start,r.end),side:r.side??"additions",metadata:{type:"new",selection:r}}),a};function Ej(t){const e=t.trim();if(!e)return null;if(/^-?\d+(\.\d+)?$/.test(e)){const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}if(e.endsWith("px")){const n=Number.parseFloat(e.slice(0,-2));return Number.isFinite(n)?n:null}return null}function xm(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function Rj(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:a,commentText:i,fileLabel:o,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,f]=l.useState(0),[b,h]=l.useState(null),v=l.useMemo(()=>!r||a?null:qo({type:"new",selection:r}),[a,r]),x=l.useMemo(()=>{const y=n.map(k=>qo({type:k.id===a?"edit":"saved",draft:k}));return v&&y.push(v),y},[n,a,v]),g=l.useCallback(y=>{const k=e.current;if(!k)return null;const A=k.querySelector("diffs-container");if(!(A instanceof HTMLElement))return null;const j=A.querySelector(`[data-annotation-id="${y}"]`);if(j instanceof HTMLElement)return j;const S=A.shadowRoot;return S?S.querySelector(`[data-annotation-id="${y}"]`):null},[e]);l.useEffect(()=>{if(x.length===0)return;let y=!1,k=0;const A=12,j=()=>{y||x.every(D=>!!g(D))||k>=A||(k+=1,requestAnimationFrame(()=>{y||(f(D=>D+1),j())}))};return j(),()=>{y=!0}},[x,g]),l.useEffect(()=>{const y=e.current;if(!y)return;const k=()=>{const j=getComputedStyle(y),S=Ej(j.getPropertyValue("--oc-context-panel-width")),D=y.getBoundingClientRect(),E=S??D.width;h(E>0?E:null)};k();const A=new ResizeObserver(()=>{k()});return A.observe(y),window.addEventListener("resize",k),()=>{A.disconnect(),window.removeEventListener("resize",k)}},[e]);const w=l.useCallback(y=>{const A=e.current?.getBoundingClientRect(),j=y.closest("[data-annotation-content]"),S=j instanceof HTMLElement?j.getBoundingClientRect():y.getBoundingClientRect(),D=[S.width];A&&D.push(A.right-S.left);const E=D.filter(P=>Number.isFinite(P)&&P>0);return E.length>0?xm(Math.min(...E)):xm(b)},[e,b]);return s.jsxs(s.Fragment,{children:[n.map(y=>{const k=qo({type:y.id===a?"edit":"saved",draft:y}),A=g(k);if(!A)return null;const j=w(A);return y.id===a?_i.createPortal(s.jsx(fl,{initialText:i,fileLabel:o,lineRange:{start:y.startLine,end:y.endLine,side:y.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:j}),A,`draft-edit-${y.id}`):_i.createPortal(s.jsx(zh,{draft:y,onEdit:()=>p(y),onDelete:()=>m(y),maxWidth:j}),A,`draft-card-${y.id}`)}),r&&!a&&v&&(()=>{const y=g(v);if(!y)return null;const k=w(y);return _i.createPortal(s.jsx(fl,{initialText:i,fileLabel:o,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:k}),y,v)})()]})}function Fj(){return new Worker(ex,{type:"module"})}const Oj=["typescript","javascript","tsx","jsx","json","markdown"],id={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let bm,ym;const vm=t=>{const e=id[t],n=new tx({workerFactory:Fj,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:Oj,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},Lj=t=>{if(!(typeof window>"u"))return t==="split"?(ym??=vm("split"),ym):(bm??=vm("unified"),bm)},$j=t=>{const e=ot.c(7),{children:n,renderTheme:r}=t,a=od("unified"),i=od("split");let o,c;e[0]!==r||e[1]!==i||e[2]!==a?(o=()=>{a&&a.setRenderOptions({theme:r,lineDiffType:id.unified.lineDiffType}),i&&i.setRenderOptions({theme:r,lineDiffType:id.split.lineDiffType})},c=[r,i,a],e[0]=r,e[1]=i,e[2]=a,e[3]=o,e[4]=c):(o=e[3],c=e[4]),$e.useEffect(o,c);let d;return e[5]!==n?(d=s.jsx(s.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},Bj=t=>{const e=ot.c(11),{children:n}=t,r=Al();let a,i;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=ui(!1),m=ui(!0),u=r?.lightThemeId??p.metadata.id,f=r?.darkThemeId??m.metadata.id;i=r?.availableThemes.find(b=>b.metadata.id===u)??p,a=r?.availableThemes.find(b=>b.metadata.id===f)??m,mi(i),mi(a),e[0]=r?.availableThemes,e[1]=r?.darkThemeId,e[2]=r?.lightThemeId,e[3]=a,e[4]=i}else a=e[3],i=e[4];let o;e[5]!==a.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:a.metadata.id},e[5]=a.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const c=o;let d;return e[8]!==n||e[9]!==c?(d=s.jsx($j,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},od=t=>{const e=ot.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=Lj(n),e[0]=n,e[1]=r):r=e[1],r},_j=5e5,zj=`
|
|
8
|
-
:host {
|
|
9
|
-
font-family: var(--font-mono);
|
|
10
|
-
font-size: var(--text-code);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
pre, [data-code] {
|
|
14
|
-
font-family: var(--font-mono);
|
|
15
|
-
font-size: var(--text-code);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/* Mobile touch selection support */
|
|
19
|
-
[data-line-number] {
|
|
20
|
-
touch-action: manipulation;
|
|
21
|
-
-webkit-tap-highlight-color: transparent;
|
|
22
|
-
cursor: pointer;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/* Ensure interactive line numbers work on touch */
|
|
26
|
-
pre[data-interactive-line-numbers] [data-line-number] {
|
|
27
|
-
touch-action: manipulation;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
[data-diff-header],
|
|
31
|
-
[data-diff] {
|
|
32
|
-
[data-separator] {
|
|
33
|
-
height: 24px !important;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
`;function Vj(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return e.toString(16)}function wm(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${Vj(e)}`}const Uj=(t,e,n)=>{const i=(n.side==="deletions"?t:e).split(`
|
|
37
|
-
`),o=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,o),p=Math.min(i.length,c);return d>p?"":i.slice(d-1,p).join(`
|
|
38
|
-
`)},Wj=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,Io=new WeakMap,Kj={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function Hj(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 Gj(t){if(typeof document>"u")return null;const e=Hj(t);let n=Io.get(e.key);if(!n){const a=new rx;a.setup(e.root,e.content),n={virtualizer:a,refs:0},Io.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=Io.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),Io.delete(e.key)))}}}const qd=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:o="fill"})=>{const c=Al(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(W=>W.metadata.id===c.lightThemeId)??ui(!1),m=c?.availableThemes.find(W=>W.metadata.id===c.darkThemeId)??ui(!0),{isMobile:u}=nn(),f=Gd({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:W=>Uj(t,e,W),toStoreRange:W=>({startLine:W.start,endLine:W.end,side:W.side==="deletions"?"original":"modified"}),fromDraftRange:W=>({start:W.startLine,end:W.endLine,side:W.side==="original"?"deletions":"additions"})}),{drafts:b,selection:h,setSelection:v,commentText:x,setCommentText:g,editingDraftId:w,saveComment:y,cancel:k,startEdit:A,deleteDraft:j}=f,S=$e.useRef(null),D=$e.useRef(null),E=$e.useRef(!1),P=$e.useRef(null);$e.useEffect(()=>{S.current=h},[h]),$e.useEffect(()=>{D.current=w},[w]);const C=$e.useCallback(W=>{if(E.current)return;const Z=S.current;if(u&&Z&&W&&W.side===Z.side){const K=Math.min(Z.start,W.start),ie=Math.max(Z.end,W.end);v({...W,start:K,end:ie})}else v(W);W&&(D.current||g(""))},[u,g,v]),N=$e.useCallback(()=>{k()},[k]),T=$e.useCallback(W=>{const Z=document.createElement("div");Z.style.position="relative";const K=qo(W.metadata);return Z.dataset.annotationId=K,Z.dataset.annotationSide=W.side,Z.dataset.annotationLine=String(W.lineNumber),Z},[]),M=$e.useCallback((W,Z)=>{y(W,Z??h??void 0)},[y,h]),F=$e.useCallback(W=>{v(W);const Z=z.current;if(Z)try{E.current=!0,Z.setSelectedLines(W),P.current=W}catch{}finally{E.current=!1}},[v]),_=$e.useCallback(W=>{const Z=W.closest("[data-line-type]")?.getAttribute("data-line-type")??W.getAttribute("data-line-type");if(Z==="change-deletion")return"deletions";if(Z==="change-addition")return"additions";const K=W.getAttribute("data-column-side")??W.getAttribute("data-side")??W.closest("[data-column-side]")?.getAttribute("data-column-side");if(K==="deletions"||K==="left"||K==="original")return"deletions";if(K==="additions"||K==="right"||K==="modified")return"additions";const ie=W.closest("[data-line-type]");if(ie instanceof HTMLElement){const Ne=ie.getBoundingClientRect(),ne=W.getBoundingClientRect(),fe=Ne.left+Ne.width/2;return ne.left+ne.width/2<fe?"deletions":"additions"}return"additions"},[]);mi(p),mi(m);const B=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,V=$e.useRef(null),$=$e.useRef(null),z=$e.useRef(null),Q=$e.useRef(null),[,L]=l.useReducer(W=>W+1,0),J=od(a?"split":"unified"),ee=$e.useMemo(()=>wu(p),[p]),re=$e.useMemo(()=>wu(m),[m]);l.useLayoutEffect(()=>{const W=V.current;if(!W)return;const Z=W.querySelector("diffs-container");if(!Z)return;const K=d?re:ee,ie=(ve,ye)=>ve.colors?.[ye],Ne=ie(ee,"terminal.ansiGreen"),ne=ie(ee,"terminal.ansiRed"),fe=ie(ee,"terminal.ansiBlue"),pe=ie(re,"terminal.ansiGreen"),je=ie(re,"terminal.ansiRed"),oe=ie(re,"terminal.ansiBlue");Z.style.setProperty("--shiki-light",ee.fg),Z.style.setProperty("--shiki-light-bg",ee.bg),Ne&&Z.style.setProperty("--shiki-light-addition-color",Ne),ne&&Z.style.setProperty("--shiki-light-deletion-color",ne),fe&&Z.style.setProperty("--shiki-light-modified-color",fe),Z.style.setProperty("--shiki-dark",re.fg),Z.style.setProperty("--shiki-dark-bg",re.bg),pe&&Z.style.setProperty("--shiki-dark-addition-color",pe),je&&Z.style.setProperty("--shiki-dark-deletion-color",je),oe&&Z.style.setProperty("--shiki-dark-modified-color",oe),Z.style.setProperty("--diffs-bg",K.bg),Z.style.setProperty("--diffs-fg",K.fg);const Se=d?pe:Ne,se=d?je:ne,we=d?oe:fe;Se&&Z.style.setProperty("--diffs-addition-color-override",Se),se&&Z.style.setProperty("--diffs-deletion-color-override",se),we&&Z.style.setProperty("--diffs-modified-color-override",we);const Ae=Z.shadowRoot?.querySelector("pre");Ae&&(Ae.style.setProperty("--shiki-light",ee.fg),Ae.style.setProperty("--shiki-light-bg",ee.bg),Ne&&Ae.style.setProperty("--shiki-light-addition-color",Ne),ne&&Ae.style.setProperty("--shiki-light-deletion-color",ne),fe&&Ae.style.setProperty("--shiki-light-modified-color",fe),Ae.style.setProperty("--shiki-dark",re.fg),Ae.style.setProperty("--shiki-dark-bg",re.bg),pe&&Ae.style.setProperty("--shiki-dark-addition-color",pe),je&&Ae.style.setProperty("--shiki-dark-deletion-color",je),oe&&Ae.style.setProperty("--shiki-dark-modified-color",oe),Ae.style.setProperty("--diffs-bg",K.bg),Ae.style.setProperty("--diffs-fg",K.fg),Se&&Ae.style.setProperty("--diffs-addition-color-override",Se),se&&Ae.style.setProperty("--diffs-deletion-color-override",se),we&&Ae.style.setProperty("--diffs-modified-color-override",we))},[re,B,d,ee]);const q=$e.useMemo(()=>Math.max(t.length,e.length)>_j,[t.length,e.length]),ce=$e.useMemo(()=>({theme:{dark:m.metadata.id,light:p.metadata.id},themeType:d?"dark":"light",diffStyle:a?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:q?0:1e3,maxLineLengthForHighlighting:q?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:C,unsafeCSS:zj,renderAnnotation:T}),[m.metadata.id,d,q,p.metadata.id,a,i,C,T]),ae=$e.useMemo(()=>Mj({drafts:b,editingDraftId:w,selection:h}),[w,b,h]),R=$e.useRef(ae);if($e.useEffect(()=>{R.current=ae},[ae]),$e.useEffect(()=>{if(typeof window>"u")return;const W=$.current;if(!W||!J)return;z.current?.cleanUp(),z.current=null,Q.current?.release(),Q.current=null,W.innerHTML="";const Z=Gj(W);Q.current=Z;const K=Z?new sx(ce,Z.virtualizer,Kj,J):new nx(ce,J);z.current=K,P.current=null;const ie={name:r||"",contents:t,lang:n,cacheKey:`old:${B}:${r}:${wm(t)}`},Ne={name:r||"",contents:e,lang:n,cacheKey:`new:${B}:${r}:${wm(e)}`};return K.render({oldFile:ie,newFile:Ne,lineAnnotations:R.current,containerWrapper:W}),requestAnimationFrame(()=>{L()}),()=>{K.cleanUp(),z.current===K&&(z.current=null),Z?.release(),Z&&Q.current===Z&&(Q.current=null),W.innerHTML=""}},[B,r,n,e,ce,t,J]),$e.useEffect(()=>{const W=z.current;if(W){try{W.setLineAnnotations(ae)}catch(Z){console.error("Failed to apply diff line annotations",Z);try{W.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(z.current===W){try{W.rerender()}catch{}L()}})}},[ae]),$e.useEffect(()=>{const W=z.current;if(!W||h!==null)return;const Z=P.current;if(!Wj(h,Z))try{E.current=!0,W.setSelectedLines(h),P.current=h}catch{}finally{E.current=!1}},[h]),$e.useEffect(()=>{const W=$.current;if(!W)return;let Z=null,K=()=>{};const ie=()=>{const ne=W.querySelector("diffs-container")?.shadowRoot;if(!ne){Z=requestAnimationFrame(ie);return}const fe=pe=>{if(!(pe instanceof MouseEvent)||pe.button!==0||!(pe.target instanceof Element))return;const je=pe.target.closest("[data-column-number]");if(!(je instanceof HTMLElement))return;const oe=je.getAttribute("data-column-number"),Se=oe?parseInt(oe,10):NaN;if(Number.isNaN(Se))return;const se=_(je);C({start:Se,end:Se,side:se}),pe.preventDefault(),pe.stopPropagation()};ne.addEventListener("click",fe,!0),K=()=>{ne.removeEventListener("click",fe,!0)}};return ie(),()=>{Z!==null&&cancelAnimationFrame(Z),K()}},[B,r,C,_]),$e.useEffect(()=>{const W=$.current;if(!W)return;let Z=null,K=null;const Ne=setTimeout(()=>{const ne=W.querySelector("diffs-container");if(!(ne instanceof HTMLElement))return;const fe=ne.shadowRoot;Z=new MutationObserver(()=>{K&&cancelAnimationFrame(K),K=requestAnimationFrame(()=>{L(),K=null})}),Z.observe(ne,{childList:!0,subtree:!0}),fe&&Z.observe(fe,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(Ne),K&&cancelAnimationFrame(K),Z?.disconnect()}},[B,r]),typeof window>"u")return null;const U=s.jsx(Rj,{diffRootRef:V,drafts:b,selection:h,editingDraftId:w,commentText:x,fileLabel:r?.split("/").pop()??"",onSave:M,onCancel:N,onEdit:W=>{F({start:W.startLine,end:W.endLine,side:W.side==="original"?"deletions":"additions"}),A(W)},onDelete:j});return o==="fill"?s.jsx("div",{className:ue("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:s.jsxs("div",{className:"flex-1 relative min-h-0",children:[s.jsx(Ns,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:s.jsx("div",{ref:V,className:"size-full relative",children:s.jsx("div",{ref:$,className:"size-full"})})}),U]})}):s.jsxs("div",{className:ue("relative","w-full"),children:[s.jsx("div",{ref:V,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:s.jsx("div",{ref:$,className:"w-full"})}),U]})},jm=15e3,Nm=500,Sm=12,km=8*1024*1024,Cm=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Im=t=>{if(t.size<=Sm){let a=0;for(const i of t.values())a+=Cm(i);if(a<=km)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[a,i]of e){if(n.size>=Sm)continue;const o=Cm(i);r+o>km&&n.size>0||(n.set(a,i),r+=o)}return new Map(Array.from(n.entries()).reverse())};function Pm(t){const e=new Date(t);return Number.isNaN(e.getTime())?t:e.toLocaleString(void 0,{hour12:!1,year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function qj(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}const Yj=l.memo(t=>{const e=ot.c(71),{entry:n,isExpanded:r,onToggle:a,files:i,isLoadingFiles:o,onCopyHash:c,directory:d}=t,{t:p}=pt();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[0]=m):m=e[0];const[u,f]=l.useState(m);let b;e[1]===Symbol.for("react.memo_cache_sentinel")?(b=new Map,e[1]=b):b=e[1];const[h,v]=l.useState(b);let x;e[2]===Symbol.for("react.memo_cache_sentinel")?(x=new Set,e[2]=x):x=e[2];const[g,w]=l.useState(x);let y;e[3]!==d||e[4]!==n.hash?(y=async W=>{const Z=W.path;if(!d){v(K=>new Map(K).set(Z,"error"));return}v(K=>Im(new Map(K).set(Z,"loading")));try{const K=gb(d,n.hash,W.path,!1),ie=new Promise(Jj),Ne=await Promise.race([K,ie]);v(ne=>Im(new Map(ne).set(Z,Ne)))}catch{v(K=>new Map(K).set(Z,"error"))}},e[3]=d,e[4]=n.hash,e[5]=y):y=e[5];const k=y;let A;e[6]!==h||e[7]!==g||e[8]!==k||e[9]!==u?(A=async W=>{const Z=W.path;if(W.changeType==="R"||W.isBinary){f(ne=>{const fe=new Set(ne);return fe.has(Z)?fe.delete(Z):fe.add(Z),fe});return}const K=h.get(Z);if(u.has(Z)&&K&&K!=="error"){f(ne=>{const fe=new Set(ne);return fe.delete(Z),fe});return}f(ne=>{const fe=new Set(ne);return fe.add(Z),fe}),!(K&&K!=="error"||W.insertions+W.deletions>Nm&&!g.has(Z))&&await k(W)},e[6]=h,e[7]=g,e[8]=k,e[9]=u,e[10]=A):A=e[10];const j=A,S=r?"bg-sidebar/90":"hover:bg-sidebar/40";let D;e[11]!==S?(D=ue("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",S),e[11]=S,e[12]=D):D=e[12];let E;e[13]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),e[13]=E):E=e[13];let P;e[14]!==n.message?(P=s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:n.message}),e[14]=n.message,e[15]=P):P=e[15];let C;e[16]!==n.author_name?(C=s.jsx("span",{className:"truncate min-w-[3ch]",title:n.author_name,children:n.author_name}),e[16]=n.author_name,e[17]=C):C=e[17];let N;e[18]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx("span",{className:"shrink-0",children:"·"}),e[18]=N):N=e[18];let T;e[19]!==n.date?(T=Pm(n.date),e[19]=n.date,e[20]=T):T=e[20];let M;e[21]!==n.date?(M=Pm(n.date),e[21]=n.date,e[22]=M):M=e[22];let F;e[23]!==T||e[24]!==M?(F=s.jsx("span",{className:"truncate min-w-0",title:T,children:M}),e[23]=T,e[24]=M,e[25]=F):F=e[25];let _;e[26]!==C||e[27]!==F?(_=s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[C,N,F]}),e[26]=C,e[27]=F,e[28]=_):_=e[28];let B;e[29]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx("span",{className:"shrink-0",children:"·"}),e[29]=B):B=e[29];let V;e[30]!==n.hash?(V=n.hash.slice(0,8),e[30]=n.hash,e[31]=V):V=e[31];let $;e[32]!==V?($=s.jsx("code",{className:"shrink-0 font-mono",children:V}),e[32]=V,e[33]=$):$=e[33];let z;e[34]!==n.hash||e[35]!==c?(z=W=>{W.stopPropagation(),c(n.hash)},e[34]=n.hash,e[35]=c,e[36]=z):z=e[36];let Q;e[37]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(I,{name:"file-copy",className:"size-3"}),e[37]=Q):Q=e[37];let L;e[38]!==z?(L=s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:z,children:Q})}),e[38]=z,e[39]=L):L=e[39];let J;e[40]!==p?(J=p("gitView.history.copySha"),e[40]=p,e[41]=J):J=e[41];let ee;e[42]!==J?(ee=s.jsx(Ct,{sideOffset:8,children:J}),e[42]=J,e[43]=ee):ee=e[43];let re;e[44]!==L||e[45]!==ee?(re=s.jsxs(St,{children:[L,ee]}),e[44]=L,e[45]=ee,e[46]=re):re=e[46];let q;e[47]!==_||e[48]!==$||e[49]!==re?(q=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[_,B,$,re]}),e[47]=_,e[48]=$,e[49]=re,e[50]=q):q=e[50];let ce;e[51]!==q||e[52]!==P?(ce=s.jsxs("div",{className:"min-w-0 flex-1",children:[P,q]}),e[51]=q,e[52]=P,e[53]=ce):ce=e[53];let ae;e[54]!==a||e[55]!==ce||e[56]!==D?(ae=s.jsxs("button",{type:"button",onClick:a,className:D,children:[E,ce]}),e[54]=a,e[55]=ce,e[56]=D,e[57]=ae):ae=e[57];let R;e[58]!==h||e[59]!==i||e[60]!==g||e[61]!==r||e[62]!==o||e[63]!==k||e[64]!==u||e[65]!==p||e[66]!==j?(R=r&&s.jsx("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:o?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:p("gitView.history.loadingFiles")})]}):i.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:p("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:i.map(W=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>j(W),className:ue("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",u.has(W.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:ue("font-semibold w-3 text-center shrink-0",qj(W.changeType)),children:W.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:W.path,children:W.path}),!W.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",W.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",W.deletions]})]}),W.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:p("gitView.history.binary")}),s.jsx(I,{name:u.has(W.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),u.has(W.path)&&s.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:W.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.renamedNoDiff")}):W.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.binaryNoDiff")}):(()=>{const Z=W.insertions+W.deletions;if(!g.has(W.path)&&Z>Nm)return s.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:p("gitView.history.largeDiffTitle",{count:Z})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:p("gitView.history.largeDiffDescription")}),s.jsx(xe,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{w(ie=>new Set(ie).add(W.path)),k(W)},children:p("gitView.history.renderDiffAnyway")})]});const K=h.get(W.path);return K==="loading"||K===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.loadingDiff")}):K==="error"?s.jsx("button",{type:"button",onClick:()=>j(W),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:p("gitView.history.diffError")}):s.jsx(qd,{original:K.original,modified:K.modified,language:pi(W.path)||"",fileName:W.path,renderSideBySide:!1,layout:"inline"})})()})]},W.path))})}),e[58]=h,e[59]=i,e[60]=g,e[61]=r,e[62]=o,e[63]=k,e[64]=u,e[65]=p,e[66]=j,e[67]=R):R=e[67];let U;return e[68]!==ae||e[69]!==R?(U=s.jsxs("li",{children:[ae,R]}),e[68]=ae,e[69]=R,e[70]=U):U=e[70],U});function Jj(t,e){setTimeout(()=>e(new Error(`Timed out after ${jm}ms`)),jm)}const Qj=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],Xj=t=>{const e=ot.c(56),{log:n,isLogLoading:r,logMaxCount:a,onLogMaxCountChange:i,expandedCommitHashes:o,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,directory:u,showHeader:f,contentMaxHeightClassName:b,branchDivider:h}=t,v=f===void 0?!0:f,x=b===void 0?"max-h-[50vh]":b,g=h===void 0?null:h,{t:w}=pt(),[y,k]=l.useState(!0);if(!n)return null;const A=g!==null&&g.insertBeforeIndex>0&&g.insertBeforeIndex<n.all.length,j=g!==null&&g.insertBeforeIndex===n.all.length,S=A||j;let D;e[0]!==g||e[1]!==A||e[2]!==j||e[3]!==n.all?(D=A?n.all.slice(0,g.insertBeforeIndex):j?n.all:[],e[0]=g,e[1]=A,e[2]=j,e[3]=n.all,e[4]=D):D=e[4];const E=D;let P;if(e[5]!==g||e[6]!==d||e[7]!==x||e[8]!==u||e[9]!==o||e[10]!==A||e[11]!==S||e[12]!==p||e[13]!==n.all||e[14]!==m||e[15]!==c||e[16]!==w||e[17]!==E){const z=A?n.all.slice(g.insertBeforeIndex):[];let Q;e[19]!==g?.direction?(Q=g?.direction==="down"?s.jsx(I,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(I,{name:"arrow-up",className:"size-3.5"}),e[19]=g?.direction,e[20]=Q):Q=e[20];const L=Q;let J;e[21]!==d||e[22]!==u||e[23]!==o||e[24]!==p||e[25]!==m||e[26]!==c?(J=re=>s.jsx("ul",{className:"divide-y divide-border/60",children:re.map(q=>s.jsx(Yj,{entry:q,isExpanded:o.has(q.hash),onToggle:()=>c(q.hash),files:d.get(q.hash)??[],isLoadingFiles:p.has(q.hash),onCopyHash:m,directory:u},q.hash))}),e[21]=d,e[22]=u,e[23]=o,e[24]=p,e[25]=m,e[26]=c,e[27]=J):J=e[27];const ee=J;P=s.jsx(Ns,{outerClassName:`min-h-0 ${x}`,className:"h-full w-full",children:n.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:w("gitView.history.noCommits")})}):S&&g?s.jsxs("div",{className:"flex flex-col gap-0",children:[E.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ee(E)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:g.branchName,children:g.branchName}),L]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),z.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ee(z)}):null]}):ee(n.all)}),e[5]=g,e[6]=d,e[7]=x,e[8]=u,e[9]=o,e[10]=A,e[11]=S,e[12]=p,e[13]=n.all,e[14]=m,e[15]=c,e[16]=w,e[17]=E,e[18]=P}else P=e[18];const C=P;if(!v){if(S){let Q;return e[28]!==C?(Q=s.jsx("section",{className:"h-full min-h-0",children:C}),e[28]=C,e[29]=Q):Q=e[29],Q}let z;return e[30]!==C?(z=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:C}),e[30]=C,e[31]=z):z=e[31],z}let N;e[32]!==w?(N=w("gitView.history.title"),e[32]=w,e[33]=N):N=e[33];let T;e[34]!==N?(T=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:N}),e[34]=N,e[35]=T):T=e[35];let M;e[36]!==r||e[37]!==y||e[38]!==a||e[39]!==i||e[40]!==w?(M=y&&s.jsx("div",{onClick:Zj,onPointerDown:e0,children:s.jsxs(is,{value:String(a),onValueChange:z=>i(Number(z)),disabled:r,children:[s.jsx(os,{size:"sm",className:"data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0",disabled:r,children:s.jsx(us,{placeholder:w("gitView.history.commitsPlaceholder")})}),s.jsx(ls,{children:Qj.map(z=>s.jsx(Ft,{value:String(z.value),children:w(z.labelKey)},z.value))})]})}),e[36]=r,e[37]=y,e[38]=a,e[39]=i,e[40]=w,e[41]=M):M=e[41];let F;e[42]!==y?(F=y?s.jsx(I,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[42]=y,e[43]=F):F=e[43];let _;e[44]!==M||e[45]!==F?(_=s.jsxs("div",{className:"flex items-center gap-2",children:[M,F]}),e[44]=M,e[45]=F,e[46]=_):_=e[46];let B;e[47]!==_||e[48]!==T?(B=s.jsxs(Nr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[T,_]}),e[47]=_,e[48]=T,e[49]=B):B=e[49];let V;e[50]!==C?(V=s.jsx(fr,{children:C}),e[50]=C,e[51]=V):V=e[51];let $;return e[52]!==y||e[53]!==B||e[54]!==V?($=s.jsxs(pr,{open:y,onOpenChange:k,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[B,V]}),e[52]=y,e[53]=B,e[54]=V,e[55]=$):$=e[55],$};function Zj(t){return t.stopPropagation()}function e0(t){return t.stopPropagation()}const t0=9e4,s0=15e3,n0=5*6e4,r0=[2e3,5e3],a0=6e4,i0=2*6e4,o0=5*6e4,l0=720*6e4,c0="openchamber.github-pr-status",d0=t=>t==="closed"||t==="merged",u0=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Ki=(t,e,n)=>`${t}::${e}`,Po=new Map,Ao=new Map,Pi=new Set,Am=new Map,Li=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),gl=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,Yd=t=>{const e=gl(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},Uh=(t,e)=>Object.entries(t).filter(([,n])=>Yd(n)===e).map(([n])=>n),m0=(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}}},Do=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},p0=(t,e,n)=>{const r=Uh(t,e),a=r.map(d=>Do(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=Do(t[n]);if(i&&Yd(t[n])===e)return i;const o=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&Do(d)));if(o)return Do(o);const c=a.find(d=>!!d.remoteName);return c||(a[0]??null)},f0=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:gl(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),h0=t=>({...Li(),status:t?.status??null,isInitialStatusResolved:t?.isInitialStatusResolved??!1,lastRefreshAt:t?.lastRefreshAt??0,lastDiscoveryPollAt:t?.lastDiscoveryPollAt??0,identity:t?.identity??null,resolvedRemoteName:t?.resolvedRemoteName??t?.status?.resolvedRemoteName??null}),mr=nr()(ao((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:Li()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??Li();return{entries:{...a.entries,[n]:m0(i,r)}}})},startWatching:n=>{if(t(i=>{const o=i.entries[n]??Li();return{entries:{...i.entries,[n]:{...o,watchers:o.watchers+1}}}}),Po.has(n))return;const r=i=>{const o=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const d=e().entries[n];!d||d.watchers<=0||d.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},i),c=Ao.get(n)??[];c.push(o),Ao.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),r0.forEach(i=>r(i));const a=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const i=e().entries[n];if(!i||i.watchers<=0)return;if(!!!i.status?.pr){const p=Date.now();if(p-i.lastDiscoveryPollAt<n0)return;t(m=>{const u=m.entries[n];return u?{entries:{...m.entries,[n]:{...u,lastDiscoveryPollAt:p}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(d0(i.status?.pr?.state))return;const c=Date.now()-i.lastRefreshAt,d=u0(i.status)?a0:i.status?.checks&&i.status.checks.state!=="pending"?o0:i0;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},s0);Po.set(n,a)},stopWatching:n=>{t(o=>{const c=o.entries[n];if(!c)return o;const d=Math.max(0,c.watchers-1);return{entries:{...o.entries,[n]:{...c,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const a=Po.get(n);typeof a=="number"&&window.clearInterval(a),Po.delete(n);const i=Ao.get(n);i&&i.length>0&&i.forEach(o=>{window.clearTimeout(o)}),Ao.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],o=Yd(i);if(!i||!o)return;const c=Uh(a.entries,o),d=c.some(u=>!!a.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const p=Am.get(o)??0;if(!r?.force&&Date.now()-p<t0||Pi.has(o))return;const m=p0(a.entries,o,n);if(m){if(Pi.add(o),Am.set(o,Date.now()),t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,lastRefreshAt:Date.now(),isLoading:r?.silent?h.isLoading:!0,error:null})}),{entries:f}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,status:{connected:!1},error:null,isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),Pi.delete(o);return}if(!m.github?.prStatus){t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),Pi.delete(o);return}try{t(f=>({...f,activeRequestCount:f.activeRequestCount+1,totalRequestCount:f.totalRequestCount+1}));const u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(f=>{const b={...f.entries};return c.forEach(h=>{const v=b[h];if(!v)return;const x=v.status?.pr,g=u.pr,y=!!(g&&x&&g.number===x.number&&(!g.body||!g.body.trim())&&typeof x.body=="string"&&x.body.trim().length>0)&&g&&x?.body?{...u,pr:{...g,body:x.body}}:u,k=y.resolvedRemoteName??v.resolvedRemoteName??m.remoteName??null,A=gl(v)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};b[h]={...v,status:y,error:null,isLoading:r?.silent?v.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?v.isInitialStatusResolved:!0,resolvedRemoteName:k,identity:{...A,remoteName:k??A.remoteName??null}}}),{entries:b}})}catch(u){const f=u instanceof Error?u.message:String(u);t(b=>{const h={...b.entries};return c.forEach(v=>{const x=h[v];x&&(h[v]={...x,error:f||"Failed to load PR status",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:h}})}finally{Pi.delete(o),t(u=>({...u,activeRequestCount:Math.max(0,u.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const a=Array.from(new Set(n.map(i=>{const o=i.directory.trim(),c=i.branch.trim();return!o||!c?null:Ki(o,c,i.remoteName??null)}).filter(i=>!!i)));await Promise.all(a.map(i=>e().refresh(i,r)))},updateStatus:(n,r)=>{t(a=>{const i=a.entries[n]??Li();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:c0,storage:kl(()=>br()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=gl(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<l0}).map(([e,n])=>[e,f0(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,h0(i)]))}}})),g0=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"},x0=t=>{const e=g0(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}},b0=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 gc=new Map,Dm=new Map;const y0=t=>{const e=ot.c(2);let n;return e[0]!==t?(n=r=>{const a=new Map,i=new Map;for(const o of t){const c=r.entries[o];if(!c)continue;const d=x0(c);if(!d)continue;const p=b0(d);a.set(o,p),i.set(o,d)}if(a.size===gc.size){let o=!0;for(const[c,d]of a)if(gc.get(c)!==d){o=!1;break}if(o)return Dm}return gc=a,Dm=i,i},e[0]=t,e[1]=n):n=e[1],mr(n)},v0=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},w0=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",a=e.mergeable===!1||r==="blocked"||r==="dirty";return n||a?"blocked":"open"},j0=[2e3,5e3],Tm=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),na=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},N0=(t,e)=>{const n=na(t);if(!n||n.includes("->"))return"";if(e){const a=`${e}/`;return n.startsWith(a)?n.slice(a.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},S0=(t,e)=>`${t}::${e}`,Jd=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},xc=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(o=>o.name===n);if(i)return i}const r=Jd(e.trackingBranch);if(r){const i=r==="origin"?t.find(c=>c.name==="upstream"):null;if(i)return i;const o=t.find(c=>c.name===r);if(o)return o}const a=t.find(i=>i.name==="origin");return a||(t[0]??null)},k0=t=>t.startsWith("pr-"),C0=(t,e)=>{const n=Jd(e),r=new Map(t.map(o=>[o.name,o])),a=[],i=o=>{o&&(a.some(c=>c.name===o.name)||a.push(o))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(o=>!k0(o.name)).forEach(o=>i(o)),t.forEach(o=>i(o)),a},bc=new Map,yc=Zn;function I0(t,e){const[n,r]=l.useState(null),[a,i]=l.useState([]),o=l.useRef(null);return l.useEffect(()=>{r(null),i([])},[t]),l.useEffect(()=>{if(!t||!e?.repoUpstream||o.current===t)return;o.current=t;let c=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(c||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const p=await e.repoBranches(d.upstream.owner,d.upstream.repo);c||i(p)}catch{}}catch{}})(),()=>{c=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:a}}const P0=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:a=[],remoteBranches:i=[],onGeneratedDescription:o})=>{const{t:c}=pt(),{github:d}=On(),p=zn(Ue=>Ue.status),m=zn(Ue=>Ue.hasChecked),u=De(Ue=>Ue.setSettingsDialogOpen),f=De(Ue=>Ue.setSettingsPage),b=De(Ue=>Ue.setActiveMainTab),h=Lt(Ue=>Ue.currentSessionId),{isMobile:v,hasTouchInput:x}=nn(),g=l.useCallback(()=>{f("github"),u(!0)},[u,f]),w=l.useMemo(()=>S0(t,e),[t,e]),y=l.useMemo(()=>bc.get(w)??null,[w]),k=mr(Ue=>Ue.ensureEntry),A=mr(Ue=>Ue.setParams),j=mr(Ue=>Ue.startWatching),S=mr(Ue=>Ue.stopWatching),D=mr(Ue=>Ue.refresh),E=mr(Ue=>Ue.updateStatus),[P,C]=l.useState(()=>y?.title??Tm(e)),[N,T]=l.useState(()=>y?.body??""),[M,F]=l.useState(()=>y?.draft??!1),[_,B]=l.useState(()=>y?.additionalContext??""),[V,$]=l.useState(()=>{const Ue=typeof y?.targetBaseBranch=="string"?na(y.targetBaseBranch):"";return Ue||na(n)}),[z,Q]=l.useState("squash"),[L,J]=l.useState(!1),[ee,re]=l.useState(!1),[q,ce]=l.useState(!1),[ae,R]=l.useState(!1),[U,W]=l.useState(!1),[Z,K]=l.useState(!1),[ie,Ne]=l.useState(null),[ne,fe]=l.useState(""),[pe,je]=l.useState(""),[oe,Se]=l.useState(!1),[se,we]=l.useState(!1),[Ae,ve]=l.useState(()=>xc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r})),[ye,Ie]=l.useState(!1),{detectedUpstream:he,upstreamBranches:me}=I0(t,d);l.useEffect(()=>{Ie(!1)},[t]);const Ee=a.some(Ue=>Ue.name==="upstream"),Y=!!(t&&e&&n&&(e!==n||(Ee||he!==null))),ke=l.useMemo(()=>Ki(t,e),[t,e]),Be=mr(Ue=>Ue.entries[ke]),Ce=Be?.isLoading??!1,ge=Be?.status??null,O=Be?.error??null,X=Be?.isInitialStatusResolved??!1,G=l.useMemo(()=>{const Ue=ye?null:Ae?.name?.trim()||null,xt=new Set;for(const Zt of i){const Ut=N0(Zt,Ue);!Ut||Ut==="HEAD"||xt.add(Ut)}if(ye)for(const Zt of me)Zt&&Zt!=="HEAD"&&xt.add(Zt);const At=na(n);At&&At!=="HEAD"&&xt.add(At);const Dt=na(V);return Dt&&Dt!=="HEAD"&&xt.add(Dt),Array.from(xt).sort((Zt,Ut)=>Zt.localeCompare(Ut))},[n,i,Ae?.name,V,me,ye]);l.useEffect(()=>{if(a.length===0){Ae&&ve(null);return}(!Ae||!a.some(Ue=>Ue.name===Ae.name))&&ve(xc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r}))},[y?.selectedRemoteName,a,Ae,r]),l.useEffect(()=>{const Ue=na(n);if(!V&&Ue){$(Ue);return}if(G.length!==0&&!G.includes(V)){const xt=G.includes(Ue)?Ue:G[0];xt&&$(xt)}},[G,n,V]);const[Te,le]=l.useState(!1),[We,de]=l.useState(null),[Fe,rt]=l.useState(!1),[Oe,Ye]=l.useState(new Set),[Ge,it]=l.useState(!1),[Qe,at]=l.useState(null),[nt,be]=l.useState(!1),He=l.useRef(new Set),_e=l.useRef(null),tt=l.useRef(!1),ut=l.useRef(new Set),qe=l.useRef([]);l.useEffect(()=>{he&&!Ee&&Ie(!0)},[he,Ee]),l.useEffect(()=>{ye&&he?.defaultBranch&&$(he.defaultBranch)},[ye,he?.defaultBranch]);const ze=ge?.pr??null,st=ze?`${t}#${ze.number}`:null,yt=!!(st&&ie===st);l.useEffect(()=>{if(!d?.prContext||!ze||typeof ze.body=="string"&&ze.body.length>0)return;const Ue=`${t}#${ze.number}`;if(He.current.has(Ue))return;He.current.add(Ue),Ne(Ue);let xt=!1;return d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}).then(At=>{if(xt)return;const Dt=At?.pr;Dt&&E(ke,Zt=>!Zt?.pr||Zt.pr.number!==ze.number?Zt:{...Zt,pr:{...Zt.pr,body:Dt.body||""}})}).catch(()=>{}).finally(()=>{xt||Ne(At=>At===Ue?null:At)}),()=>{xt=!0}},[t,d,ze,ke,E]),l.useEffect(()=>{if(!ze){K(!1),fe(""),je(""),_e.current=null;return}const Ue=_e.current!==null&&_e.current!==ze.number;Ue&&K(!1),(!Z||Ue)&&(fe(ze.title||""),je(ze.body||"")),_e.current=ze.number},[Z,ze]);const Mt=l.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){le(!0),Ye(new Set),rt(!0);try{const Ue=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0});de(Ue)}catch(Ue){const xt=Ue instanceof Error?Ue.message:String(Ue);H.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:xt})}finally{rt(!1)}}},[t,d,ze,c]),Bt=l.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){it(!0),be(!0);try{const Ue=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1});at(Ue)}catch(Ue){const xt=Ue instanceof Error?Ue.message:String(Ue);H.error(c("gitView.pr.toast.loadCommentsFailed"),{description:xt})}finally{be(!1)}}},[t,d,ze,c]),ft=l.useCallback(Ue=>{if(!Ue)return"";const xt=Date.parse(Ue);return Number.isFinite(xt)?new Date(xt).toLocaleString():Ue},[]),It=l.useMemo(()=>{const Ue=p?.user?.login;return typeof Ue=="string"?Ue.trim():""},[p]),ss=l.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),_t=l.useCallback(Ue=>{const xt=It.toLowerCase(),At=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return Ue.replace(At,(Dt,Zt,Ut)=>{const ks=`@${Ut}`,Js=Ut.toLowerCase();return`${Zt}[${ks}](https://github.com/${Js}${xt&&Js===xt?"?oc-self-mention=1":""})`})},[It]),qt=l.useMemo(()=>{const Ue=(Qe?.issueComments??[]).map(Dt=>({id:`issue-${Dt.id}`,body:Dt.body||"",authorName:Dt.author?.name||Dt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Dt.author?.login||null,avatarUrl:Dt.author?.avatarUrl||null,createdAt:Dt.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),xt=(Qe?.reviewComments??[]).map(Dt=>({id:`review-${Dt.id}`,body:Dt.body||"",authorName:Dt.author?.name||Dt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Dt.author?.login||null,avatarUrl:Dt.author?.avatarUrl||null,createdAt:Dt.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Dt.path||null,line:Dt.line??null})),At=[...Ue,...xt];return At.sort((Dt,Zt)=>{const Ut=Dt.createdAt?Date.parse(Dt.createdAt):0,ks=Zt.createdAt?Date.parse(Zt.createdAt):0,Js=Number.isFinite(Ut)?Ut:0,Ls=Number.isFinite(ks)?ks:0;return Js-Ls}),At},[Qe,c]),ct=l.useCallback(()=>{if(!h)return H.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:Ue,currentModelId:xt,currentAgentName:At,currentVariant:Dt}=vt.getState(),Zt=Pl.getState().lastUsedProvider,Ut=Ue||Zt?.providerID,ks=xt||Zt?.modelID;return!Ut||!ks?(H.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:h,providerID:Ut,modelID:ks,currentAgentName:At??null,currentVariant:Dt??null}},[h,c]),jt=l.useCallback((Ue,xt,At,Dt)=>{Lt.getState().sendMessage(xt,Ue.providerID,Ue.modelID,Ue.currentAgentName??void 0,void 0,void 0,[{text:At,synthetic:!0},{text:Dt,synthetic:!0}],Ue.currentVariant??void 0).catch(Zt=>{const Ut=Zt instanceof Error?Zt.message:String(Zt);H.error(c("gitView.pr.toast.sendMessageFailed"),{description:Ut})})},[c]),as=l.useCallback(Ue=>{const xt=Ue.status||"unknown",At=Ue.conclusion??void 0,Dt=At?`${xt} / ${At}`:xt,Zt=Ue.app?.name||Ue.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:Ue.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Zt?`${Zt} · ${Dt}`:Dt})]}),Ue.detailsUrl?s.jsx(xe,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:Ue.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),Ue.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:Ue.output.title}):null,Ue.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:Ue.output.summary}):null,Ue.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:Ue.output.text}):null,Array.isArray(Ue.annotations)&&Ue.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",Ue.annotations.length>20?` (showing 20/${Ue.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:Ue.annotations.slice(0,20).map((Ut,ks)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro text-[var(--status-error)]",children:[Ut.title||Ut.level||"Issue",Ut.path?` · ${Ut.path}`:"",typeof Ut.startLine=="number"?`:${Ut.startLine}`:"",typeof Ut.endLine=="number"&&Ut.endLine!==Ut.startLine?`-${Ut.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:Ut.message}),Ut.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:Ut.rawDetails}):null]},`${Ut.path||"file"}:${Ut.startLine||ks}:${ks}`))})]}):null,Ue.job?.steps&&Ue.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:Ue.job.steps.map((Ut,ks)=>{const Js=(Ut.conclusion||"").toLowerCase(),Ls=Js&&!["success","neutral","skipped"].includes(Js),ts=`${Ue.id??"run"}:${Ue.job?.jobId??"job"}:${Ut.number??ks}:${Ut.name}`,js=Oe.has(ts);return Ls?s.jsxs(pr,{open:js,children:[s.jsxs("button",{type:"button",onClick:()=>{Ye(yn=>{const cn=new Set(yn);return cn.has(ts)?cn.delete(ts):cn.add(ts),cn})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Ls?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[js?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:Ut.name}),Ut.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ut.conclusion}):null]}),s.jsx(fr,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof Ut.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",Ut.number]}):null,Ut.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",Ut.status]}):null,Ut.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",Ut.conclusion]}):null,Ut.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",ft(Ut.startedAt)]}):null,Ut.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",ft(Ut.completedAt)]}):null]})})]},ts):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:Ut.name}),Ut.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ut.conclusion}):null]},ts)})})]}):null]})},[Oe,ft,c]),xs=l.useCallback(async()=>{if(b("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const Ue=ct();if(Ue)try{const xt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0}),Dt=(xt.checkRuns??[]).filter(Ls=>{const ts=typeof Ls.conclusion=="string"?Ls.conclusion.toLowerCase():"";return ts?!["success","neutral","skipped"].includes(ts):!1});if(Dt.length===0){H.message(c("gitView.pr.toast.noFailedChecks"));return}const Zt=await bn("github.pr.checks.review.visible"),Ut=await bn("github.pr.checks.review.instructions"),ks=Dt.flatMap(Ls=>(Array.isArray(Ls.annotations)?Ls.annotations:[]).map(js=>({run:Ls.name,level:js.level,title:js.title,path:js.path,startLine:js.startLine,endLine:js.endLine,message:js.message,rawDetails:js.rawDetails}))),Js=`GitHub PR failed checks (JSON)
|
|
39
|
-
${JSON.stringify({repo:xt.repo??null,pr:xt.pr??null,failedChecks:Dt,failedAnnotations:ks},null,2)}`;jt(Ue,Zt,Ut,Js)}catch(xt){const At=xt instanceof Error?xt.message:String(xt);H.error(c("gitView.pr.toast.loadChecksFailed"),{description:At})}},[t,jt,d,ze,ct,b,c]),ws=l.useCallback(async()=>{if(b("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const Ue=ct();if(Ue)try{const xt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}),At=xt.issueComments??[],Dt=xt.reviewComments??[];if(At.length+Dt.length===0){H.message(c("gitView.pr.toast.noPrComments"));return}const Ut=await bn("github.pr.comments.review.visible"),ks=await bn("github.pr.comments.review.instructions"),Js=`GitHub PR comments (JSON)
|
|
40
|
-
${JSON.stringify({repo:xt.repo??null,pr:xt.pr??null,issueComments:At,reviewComments:Dt},null,2)}`;jt(Ue,Ut,ks,Js)}catch(xt){const At=xt instanceof Error?xt.message:String(xt);H.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:At})}},[t,jt,d,ze,ct,b,c]),As=l.useCallback(async Ue=>{it(!1),b("chat");const xt=ct();if(!xt)return;const At=await bn("github.pr.comment.single.visible"),Dt=await bn("github.pr.comment.single.instructions"),Zt=`GitHub PR comment (JSON)
|
|
41
|
-
${JSON.stringify({repo:Qe?.repo??null,pr:Qe?.pr??ze??null,comment:Ue},null,2)}`;jt(xt,At,Dt,Zt)},[Qe,jt,ze,ct,b]),Gt=l.useCallback(async Ue=>{await D(ke,Ue)},[ke,D]),Ke=l.useCallback(()=>{qe.current.forEach(Ue=>{window.clearTimeout(Ue)}),qe.current=j0.map(Ue=>window.setTimeout(()=>{Gt({force:!0,silent:!0,markInitialResolved:!0})},Ue))},[Gt]);l.useEffect(()=>{if(!d?.prStatus||!Y||a.length<=1||tt.current||ge?.pr)return;const Ue=`${w}::${Ae?.name??""}`;if(ut.current.has(Ue))return;ut.current.add(Ue);const xt=C0(a,r).filter(Zt=>Zt.name!==Ae?.name);if(xt.length===0)return;let At=!1;return(async()=>{for(const Zt of xt){if(At)return;try{if(!(await d.prStatus(t,e,Zt.name))?.pr)continue;if(At)return;ve(ks=>ks?.name===Zt.name?ks:Zt);return}catch{}}})(),()=>{At=!0}},[e,Y,t,d,a,Ae?.name,w,ge?.pr,r]),l.useEffect(()=>{k(ke),A(ke,{directory:t,branch:e,remoteName:Ae?.name??null,canShow:Y,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,Y,t,k,d,m,p?.connected,ke,Ae?.name,A]),l.useEffect(()=>(j(ke),()=>{S(ke)}),[ke,j,S]),l.useEffect(()=>{const Ue=bc.get(w)??null;C(Ue?.title??Tm(e)),T(Ue?.body??""),F(Ue?.draft??!1),$(Ue?.targetBaseBranch?na(Ue.targetBaseBranch):na(n));const xt=xc(a,{selectedRemoteName:Ue?.selectedRemoteName,trackingBranch:r});ve(At=>At?.name===xt?.name?At:xt)},[n,e,a,w,r]),l.useEffect(()=>{Gt({markInitialResolved:!0})},[ke,Gt]),l.useEffect(()=>{!Y||!Ae?.name||Gt({force:!0,silent:!0,markInitialResolved:!0})},[Y,Gt,Ae?.name]),l.useEffect(()=>{const Ue=ge?.resolvedRemoteName?.trim();if(!Ue||tt.current)return;const xt=a.find(At=>At.name===Ue);xt&&ve(At=>At?.name===xt.name?At:xt)},[a,ge?.resolvedRemoteName]),l.useEffect(()=>{const Ue=ge?.pr?.state==="closed"||ge?.pr?.state==="merged",xt=Be?.lastRefreshAt??0,At=Date.now()-xt>6e4,Dt=!Ue&&At,Zt=()=>{Dt&&Gt({force:!0,silent:!0})},Ut=()=>{document.visibilityState==="visible"&&Dt&&Gt({force:!0,silent:!0})};return window.addEventListener("focus",Zt),document.addEventListener("visibilitychange",Ut),()=>{window.removeEventListener("focus",Zt),document.removeEventListener("visibilitychange",Ut)}},[Gt,ge?.pr?.state,Be?.lastRefreshAt]),l.useEffect(()=>{m&&p?.connected===!1&&Gt({force:!0,silent:!0,markInitialResolved:!0})},[m,p,Gt]),l.useEffect(()=>{!t||!e||bc.set(w,{title:P,body:N,draft:M,additionalContext:_,targetBaseBranch:V,selectedRemoteName:Ae?.name})},[w,P,N,M,_,V,Ae?.name,t,e]),l.useEffect(()=>{const Ue=qe.current;return()=>{Ue.forEach(xt=>{window.clearTimeout(xt)}),qe.current=[]}},[]);const Pt=l.useCallback(async()=>{if(!L&&t){J(!0);try{const xt={base:ye&&he?.defaultBranchSha?he.defaultBranchSha:V,head:e};_&&(xt.context=_);const At=await xb(t,xt);At.title?.trim()&&C(At.title.trim()),At.body?.trim()&&T(At.body.trim()),o?.()}catch(Ue){const xt=Ue instanceof Error?Ue.message:String(Ue);H.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:xt})}finally{J(!1)}}},[_,e,he?.defaultBranchSha,t,L,o,V,c,ye]),Ot=l.useCallback(async()=>{if(!d?.prCreate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const Ue=P.trim();if(!Ue){H.error(c("gitView.pr.toast.titleRequired"));return}const xt=V.trim();if(!xt){H.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!ye&&xt===e){H.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}re(!0);try{const At=Jd(r),Dt=ye&&he,Zt=await d.prCreate({directory:t,title:Ue,head:e,base:xt,...N.trim()?{body:N}:{},draft:M,...Dt?{targetRepo:{owner:he.owner,repo:he.repo},headRemote:"origin"}:{...Ae?{remote:Ae.name}:{},...At&&At!==Ae?.name?{headRemote:At}:{}}});H.success(c("gitView.pr.toast.prCreated")),E(ke,Ut=>Ut&&{...Ut,pr:Zt}),await Gt({force:!0}),Ke()}catch(At){const Dt=At instanceof Error?At.message:String(At);H.error(c("gitView.pr.toast.createPrFailed"),{description:Dt})}finally{re(!1)}},[N,e,he,t,M,d,ke,Gt,Ke,Ae,V,P,r,E,ye,c]),Nt=l.useCallback(async Ue=>{if(!d?.prMerge){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}R(!0);try{const xt=await d.prMerge({directory:t,number:Ue.number,method:z});xt.merged?H.success(c("gitView.pr.toast.prMerged")):H.message(c("gitView.pr.toast.prNotMerged"),{description:xt.message||c("gitView.pr.notMergeable")}),await Gt({force:!0}),Ke()}catch(xt){const At=xt instanceof Error?xt.message:String(xt);H.error(c("gitView.pr.toast.mergeFailed"),{description:At}),Ue.url&&yc(Ue.url)}finally{R(!1)}},[t,d,z,Gt,Ke,c]),Ht=l.useCallback(async Ue=>{if(!d?.prReady){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}W(!0);try{await d.prReady({directory:t,number:Ue.number}),H.success(c("gitView.pr.toast.markedReady")),await Gt({force:!0}),Ke()}catch(xt){const At=xt instanceof Error?xt.message:String(xt);H.error(c("gitView.pr.toast.markReadyFailed"),{description:At}),Ue.url&&yc(Ue.url)}finally{W(!1)}},[t,d,Gt,Ke,c]),ns=l.useCallback(async Ue=>{if(!d?.prUpdate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const xt=ne.trim();if(!xt){H.error(c("gitView.pr.toast.titleRequired"));return}ce(!0);try{const At=await d.prUpdate({directory:t,number:Ue.number,title:xt,body:pe});E(ke,Dt=>Dt&&{...Dt,pr:{...Dt.pr??Ue,...At}}),K(!1),H.success(c("gitView.pr.toast.prUpdated")),await Gt({force:!0}),Ke()}catch(At){const Dt=At instanceof Error?At.message:String(At);H.error(c("gitView.pr.toast.updatePrFailed"),{description:Dt})}finally{ce(!1)}},[t,pe,ne,d,ke,Gt,Ke,E,c]);if(!Y)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pullRequest.availableOnFeatureBranches")})]})});const Ss=ge?.repo?.url||null,fs=ye&&he?.url?he.url:Ss,Os=ge?.checks??null,zs=!!ge?.canMerge,tn=!!ge?.connected,Ds=m&&ge?.connected===!1,zt=w0(ge),Kt=zt?`var(--pr-${zt})`:"var(--status-info)",te=zt==="draft"?"git-pr-draft":zt==="merged"?"git-merge":zt==="closed"?"git-close-pull-request":"git-pull-request",bt=ze?[`${ze.state}${ze.draft?" (draft)":""}`,ze.mergeable===!1?c("gitView.pr.notMergeable"):null,ze.state==="open"&&typeof ze.mergeableState=="string"&&ze.mergeableState&&ze.mergeableState!=="unknown"?ze.mergeableState:null].filter(Boolean).join(" · "):"",Ze=Os?Os.total>0?`${Os.success}/${Os.total} ${c("gitView.pr.checks.label")}`:`${Os.state} ${c("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[ze?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{yc(ze.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(I,{name:te,className:"size-4 shrink-0",style:{color:Kt}})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(I,{name:te,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.pullRequest.title")}),ze?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",ze.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ce?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:Ce,onClick:()=>{Gt({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.refresh")})})]})]})]}),ze?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:Kt},children:bt}),Os?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${v0(Os.state)}`}),Ze]}):null,r&&Ae&&r.split("/")[0]!==Ae.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",Ae.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Ds?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(xe,{variant:"outline",size:"sm",onClick:g,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,O?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:O}),fs?s.jsx(xe,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:fs,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!ze&&!X&&!O&&!Ds?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),c("gitView.pr.checkingStatus")]}):ze?s.jsx("div",{className:"flex flex-col gap-2",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[Z?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Vt,{value:ne,onChange:Ue=>fe(Ue.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x}),s.jsx(fn,{value:pe,onChange:Ue=>je(Ue.target.value),className:"min-h-[120px] bg-background/80",placeholder:c("gitView.pr.placeholder.description"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:ze.title}),ze.body?.trim()?s.jsx(Ra,{content:ze.body,className:"typography-markdown-body text-muted-foreground break-words mt-1"}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:c(yt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),zs&&ze.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,zs?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.noMergePermission")})]}),s.jsxs("div",{className:"order-first w-full flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ze.state==="open"?Z?s.jsxs(s.Fragment,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{K(!1),fe(ze.title||""),je(ze.body||"")},disabled:q,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(I,{name:"close",className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>ns(ze),disabled:q||!ne.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:q?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.savePr")})})]})]}):s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>K(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(I,{name:"edit",className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,Os?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Mt,disabled:Fe,"aria-label":c("gitView.pr.actions.openChecksAria"),children:Fe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"information",className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,Os?.failure?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:xs,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(I,{name:"error-warning",className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Bt,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(I,{name:"chat-4",className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.openComments")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:ws,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(I,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),zs&&ze.draft&&ze.state==="open"?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Ht(ze),disabled:U||ae||q||Z,"aria-label":c("gitView.pr.actions.markReadyAria"),children:U?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:zs?s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:z,onValueChange:Ue=>Q(Ue),disabled:ae||ze.state!=="open",children:[s.jsx(os,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(us,{})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"squash",children:c("gitView.pr.mergeMethod.squash")}),s.jsx(Ft,{value:"merge",children:c("gitView.pr.mergeMethod.merge")}),s.jsx(Ft,{value:"rebase",children:c("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>Nt(ze),disabled:ae||U||ze.state!=="open"||ze.draft||q||Z,"aria-label":c("gitView.pr.actions.mergePrAria"),children:ae?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.mergePr")})})]})]}):null})]})]})}):s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",V," ",s.jsxs("span",{className:"opacity-60",children:["(",ye&&he?"upstream":"remote",")"]})]})]}),fs?s.jsx(xe,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:fs,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),c("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.title")}),s.jsx(Vt,{value:P,onChange:Ue=>C(Ue.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.baseBranch")}),G.length>0?s.jsxs(is,{value:V,onValueChange:$,children:[s.jsx(os,{className:"h-9",children:s.jsx(us,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(ls,{children:G.map(Ue=>s.jsx(Ft,{value:Ue,children:Ue},Ue))})]}):s.jsx(Vt,{value:V,onChange:Ue=>$(Ue.target.value),placeholder:c("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.description")}),s.jsx(fn,{value:N,onChange:Ue=>T(Ue.target.value),className:"min-h-[110px]",placeholder:c("gitView.pr.placeholder.whatChanged"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":M,onClick:()=>F(Ue=>!Ue),onKeyDown:Ue=>{(Ue.key===" "||Ue.key==="Enter")&&(Ue.preventDefault(),F(xt=>!xt))},children:[s.jsx(ds,{size:"sm",checked:M,onChange:Ue=>F(Ue),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),v?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx(xe,{variant:"outline",size:"sm",onClick:()=>we(!0),children:_.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),_.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:c("gitView.pr.additionalContext.added")})})]}):s.jsxs(pr,{open:oe,onOpenChange:Se,children:[s.jsxs(Nr,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:oe?c("gitView.pr.actions.hide"):_.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(fr,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(fn,{value:_,onChange:Ue=>B(Ue.target.value),className:"min-h-[100px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(Mr,{open:se,onClose:()=>we(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(xe,{size:"sm",onClick:()=>we(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(fn,{value:_,onChange:Ue=>B(Ue.target.value),className:"min-h-[200px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(xe,{variant:"outline",size:"sm",onClick:Pt,disabled:L||ee,children:[L?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(xe,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Ot,disabled:ee||!tn||!V.trim()||!ye&&V.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:ee?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(ps,{open:Te,onOpenChange:le,children:s.jsxs(ms,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(vs,{children:[s.jsxs(gs,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.checkDetails.title")]}),s.jsx(Ps,{children:ze?c("gitView.pr.numberLabel",{number:ze.number}):c("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[Fe?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,Fe?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(We?.checkRuns)&&We?.checkRuns.length>0?We.checkRuns.map((Ue,xt)=>{const At=`${Ue.id??"run"}:${Ue.job?.jobId??"job"}:${Ue.name}:${xt}`;return s.jsx("div",{className:"p-1",children:as(Ue)},At)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(ps,{open:Ge,onOpenChange:it,children:s.jsxs(ms,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(vs,{children:s.jsxs(gs,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.comments.title"),ze?s.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.numberLabel",{number:ze.number})}):null]})}),s.jsxs(io,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[nt?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,nt?null:s.jsx("div",{className:"space-y-4",children:qt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:qt.map((Ue,xt)=>{const At=(Ue.authorName||"?").charAt(0).toUpperCase(),Dt=xt===qt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Dt?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:Ue.avatarUrl?s.jsx("img",{src:Ue.avatarUrl,alt:Ue.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:At})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[Ue.authorName,Ue.authorLogin&&Ue.authorLogin!==Ue.authorName?` · @${Ue.authorLogin}`:""]}),Ue.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:ft(Ue.createdAt)}):null,s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs(xe,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{As(Ue)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(I,{name:"ai-generate-2",className:"size-3.5"}),c("gitView.pr.actions.sendToAgent")]})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Ue.context,Ue.path?` · ${Ue.path}`:"",Ue.line?`:${Ue.line}`:""]}),s.jsx(Ra,{content:_t(Ue.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",ss].filter(Boolean).join(" ")})]})]},Ue.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},A0=t=>{const e=ot.c(150),{open:n,onOpenChange:r,conflictFiles:a,directory:i,operation:o,onAbort:c,onClearState:d}=t;let p;e[0]!==a?(p=a===void 0?[]:a,e[0]=a,e[1]=p):p=e[1];const m=p,{t:u}=pt(),f=Lt(D0),b=Lt(T0),h=Ea(M0),v=Ea(E0),x=De(R0),[g,w]=l.useState(!1),[y,k]=l.useState(null),[A,j]=l.useState(null);let S,D;e[2]!==i||e[3]!==n||e[4]!==u?(S=()=>{!n||!i||(w(!0),j(null),k(null),bb(i).then(Ie=>{k(Ie)}).catch(Ie=>{const he=Ie instanceof Error?Ie.message:u("gitView.conflict.loadFailed");j(he)}).finally(()=>{w(!1)}))},D=[n,i,u],e[2]=i,e[3]=n,e[4]=u,e[5]=S,e[6]=D):(S=e[5],D=e[6]),l.useEffect(S,D);let E;e[7]!==y||e[8]!==i||e[9]!==o?(E=async()=>{if(!y)return null;const Ie=o==="merge"?"merge":"rebase",he=y.headInfo||(o==="merge"?"MERGE_HEAD":"REBASE_HEAD"),me=o==="merge"?"git commit --no-edit":"git rebase --continue",Ee=await bn("git.conflict.resolve.visible",{operation_label:Ie,head_ref:he}),Ve=await bn("git.conflict.resolve.instructions",{operation_label:Ie,directory:i,operation:o,head_info:y.headInfo||"N/A",continue_cmd:me}),Y=`${Ie} conflict context (JSON)
|
|
42
|
-
${JSON.stringify({directory:i,operation:y.operation,headInfo:y.headInfo,statusPorcelain:y.statusPorcelain,unmergedFiles:y.unmergedFiles,diff:y.diff},null,2)}`;return{visibleText:Ee,instructionsText:Ve,payloadText:Y}},e[7]=y,e[8]=i,e[9]=o,e[10]=E):E=e[10];const P=E;let C;e[11]!==c||e[12]!==r?(C=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=C):C=e[13];const N=C;let T;e[14]!==d||e[15]!==r?(T=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=T):T=e[16];const M=T;let F;e[17]!==P||e[18]!==b||e[19]!==d||e[20]!==r||e[21]!==x||e[22]!==h||e[23]!==v||e[24]!==u?(F=async()=>{const Ie=await P();if(!Ie){H.error(u("gitView.conflict.noDetailsAvailable"));return}if(!b){H.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}h(Ie.visibleText,"replace"),v([{text:Ie.instructionsText,synthetic:!0},{text:Ie.payloadText,synthetic:!0}]),x("chat"),d?.(),r(!1)},e[17]=P,e[18]=b,e[19]=d,e[20]=r,e[21]=x,e[22]=h,e[23]=v,e[24]=u,e[25]=F):F=e[25];const _=F;let B;e[26]!==P||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==f||e[31]!==x||e[32]!==u?(B=async()=>{const Ie=await P();if(!Ie){H.error(u("gitView.conflict.noDetailsAvailable"));return}f({directoryOverride:i,initialPrompt:Ie.visibleText,syntheticParts:[{text:Ie.instructionsText,synthetic:!0},{text:Ie.payloadText,synthetic:!0}]}),x("chat"),d?.(),r(!1)},e[26]=P,e[27]=i,e[28]=d,e[29]=r,e[30]=f,e[31]=x,e[32]=u,e[33]=B):B=e[33];const V=B;let $,z,Q,L,J,ee,re,q,ce,ae,R,U,W,Z,K,ie,Ne,ne,fe,pe,je,oe;if(e[34]!==y||e[35]!==m||e[36]!==b||e[37]!==N||e[38]!==M||e[39]!==_||e[40]!==V||e[41]!==g||e[42]!==A||e[43]!==r||e[44]!==n||e[45]!==o||e[46]!==u){const Ie=u(o==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),he=y?.unmergedFiles||m;Q=ps,je=n,oe=r,z=ms,pe="max-w-md w-[calc(100vw-2rem)]",Z="flex flex-col gap-4 overflow-hidden";let me;e[69]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(I,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=me):me=e[69];const Ee=s.jsxs("div",{className:"flex items-center gap-2",children:[me,s.jsx(gs,{children:u("gitView.conflict.detectedTitle",{operation:Ie})})]});let Ve;e[70]!==o||e[71]!==u?(Ve=u("gitView.conflict.detectedDescription",{operation:o}),e[70]=o,e[71]=u,e[72]=Ve):Ve=e[72];let Y;e[73]!==Ve?(Y=s.jsx(Ps,{children:Ve}),e[73]=Ve,e[74]=Y):Y=e[74],e[75]!==Ee||e[76]!==Y?(K=s.jsxs(vs,{children:[Ee,Y]}),e[75]=Ee,e[76]=Y,e[77]=K):K=e[77],e[78]!==g||e[79]!==u?(ie=g&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:u("gitView.conflict.loading")})]}),e[78]=g,e[79]=u,e[80]=ie):ie=e[80],e[81]!==A||e[82]!==u?(Ne=A&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:u("gitView.conflict.errorLoadingDetails",{message:A})}),e[81]=A,e[82]=u,e[83]=Ne):Ne=e[83],e[84]!==he||e[85]!==u?(ne=he.length>0&&s.jsxs("div",{className:"space-y-2 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:he.length})]}),s.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:s.jsx("ul",{className:"space-y-1",children:he.map(F0)})})]}),e[84]=he,e[85]=u,e[86]=ne):ne=e[86],e[87]!==y||e[88]!==u?(fe=y?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:y.headInfo})]}),e[87]=y,e[88]=u,e[89]=fe):fe=e[89],R="flex flex-col gap-2 pt-2";let ke;e[90]!==V?(ke=()=>{V()},e[90]=V,e[91]=ke):ke=e[91];const Be=g||!y;let Ce;e[92]!==g?(Ce=g?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"add",className:"size-4"}),e[92]=g,e[93]=Ce):Ce=e[93];let ge;e[94]!==u?(ge=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=ge):ge=e[95],e[96]!==ke||e[97]!==Be||e[98]!==Ce||e[99]!==ge?(U=s.jsxs(xe,{variant:"default",onClick:ke,disabled:Be,className:"w-full gap-2",children:[Ce,ge]}),e[96]=ke,e[97]=Be,e[98]=Ce,e[99]=ge,e[100]=U):U=e[100];let O;e[101]!==_?(O=()=>{_()},e[101]=_,e[102]=O):O=e[102];const X=g||!y||!b;let G;e[103]!==g?(G=g?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"chat-1",className:"size-4"}),e[103]=g,e[104]=G):G=e[104];let Te;e[105]!==u?(Te=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=Te):Te=e[106],e[107]!==O||e[108]!==X||e[109]!==G||e[110]!==Te?(W=s.jsxs(xe,{variant:"outline",onClick:O,disabled:X,className:"w-full gap-2",children:[G,Te]}),e[107]=O,e[108]=X,e[109]=G,e[110]=Te,e[111]=W):W=e[111],ce="flex gap-2 pt-1";let le;e[112]!==u?(le=u("gitView.conflict.continueLater"),e[112]=u,e[113]=le):le=e[113],e[114]!==M||e[115]!==le?(ae=s.jsx(xe,{variant:"ghost",size:"sm",onClick:M,className:"flex-1",children:le}),e[114]=M,e[115]=le,e[116]=ae):ae=e[116],$=xe,L="destructive",J="sm",ee=N,re="flex-1",q=u("gitView.conflict.abortOperation",{operation:Ie}),e[34]=y,e[35]=m,e[36]=b,e[37]=N,e[38]=M,e[39]=_,e[40]=V,e[41]=g,e[42]=A,e[43]=r,e[44]=n,e[45]=o,e[46]=u,e[47]=$,e[48]=z,e[49]=Q,e[50]=L,e[51]=J,e[52]=ee,e[53]=re,e[54]=q,e[55]=ce,e[56]=ae,e[57]=R,e[58]=U,e[59]=W,e[60]=Z,e[61]=K,e[62]=ie,e[63]=Ne,e[64]=ne,e[65]=fe,e[66]=pe,e[67]=je,e[68]=oe}else $=e[47],z=e[48],Q=e[49],L=e[50],J=e[51],ee=e[52],re=e[53],q=e[54],ce=e[55],ae=e[56],R=e[57],U=e[58],W=e[59],Z=e[60],K=e[61],ie=e[62],Ne=e[63],ne=e[64],fe=e[65],pe=e[66],je=e[67],oe=e[68];let Se;e[117]!==$||e[118]!==L||e[119]!==J||e[120]!==ee||e[121]!==re||e[122]!==q?(Se=s.jsx($,{variant:L,size:J,onClick:ee,className:re,children:q}),e[117]=$,e[118]=L,e[119]=J,e[120]=ee,e[121]=re,e[122]=q,e[123]=Se):Se=e[123];let se;e[124]!==ce||e[125]!==ae||e[126]!==Se?(se=s.jsxs("div",{className:ce,children:[ae,Se]}),e[124]=ce,e[125]=ae,e[126]=Se,e[127]=se):se=e[127];let we;e[128]!==R||e[129]!==U||e[130]!==W||e[131]!==se?(we=s.jsxs("div",{className:R,children:[U,W,se]}),e[128]=R,e[129]=U,e[130]=W,e[131]=se,e[132]=we):we=e[132];let Ae;e[133]!==Z||e[134]!==K||e[135]!==ie||e[136]!==Ne||e[137]!==ne||e[138]!==fe||e[139]!==we?(Ae=s.jsxs("div",{className:Z,children:[K,ie,Ne,ne,fe,we]}),e[133]=Z,e[134]=K,e[135]=ie,e[136]=Ne,e[137]=ne,e[138]=fe,e[139]=we,e[140]=Ae):Ae=e[140];let ve;e[141]!==z||e[142]!==pe||e[143]!==Ae?(ve=s.jsx(z,{className:pe,children:Ae}),e[141]=z,e[142]=pe,e[143]=Ae,e[144]=ve):ve=e[144];let ye;return e[145]!==Q||e[146]!==je||e[147]!==oe||e[148]!==ve?(ye=s.jsx(Q,{open:je,onOpenChange:oe,children:ve}),e[145]=Q,e[146]=je,e[147]=oe,e[148]=ve,e[149]=ye):ye=e[149],ye};function D0(t){return t.openNewSessionDraft}function T0(t){return t.currentSessionId}function M0(t){return t.setPendingInputText}function E0(t){return t.setPendingSyntheticParts}function R0(t){return t.setActiveMainTab}function F0(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const O0=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:a})=>{const{t:i}=pt(),[o,c]=l.useState(!0),[d,p]=l.useState(!1),m=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{p(!0);try{await a(o),e(!1)}catch(b){const h=b instanceof Error?b.message:`Failed to ${n}`;H.error(h)}finally{p(!1)}},f=()=>{d||e(!1)};return s.jsx(ps,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(vs,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(gs,{children:i("gitView.stash.title")})]}),s.jsx(Ps,{children:i("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:i("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:i("gitView.stash.stepStash")}),s.jsxs("li",{children:[i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",i(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),o&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(ds,{checked:o,onChange:c,disabled:d,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&c(!o),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(Us,{className:"gap-2",children:[s.jsx(xe,{variant:"ghost",size:"sm",onClick:f,disabled:d,children:i("gitView.common.cancel")}),s.jsx(xe,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:m})})]})]})})},L0=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:a,hasUnresolvedConflicts:i=!1,isLoading:o=!1})=>{const{t:c}=pt(),[d,p]=l.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),f=m?"merge":u?"rebase":null;if(!f)return null;const b=async()=>{p("continue");try{await n()}finally{p(null)}},h=async()=>{p("abort");try{await r()}finally{p(null)}},v=d!==null,x=c(f==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),g=f==="merge"?"git-merge":"git-branch";let w="";return t?w=t.message?c("gitView.operation.mergingMessage",{message:t.message}):c("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(w=e.headName?c("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):c("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(I,{name:g,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:c("gitView.operation.inProgressTitle",{operation:x})}),w&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:w})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&a&&s.jsxs(xe,{variant:"outline",size:"sm",onClick:a,disabled:v||o,className:"gap-1.5",children:[s.jsx(I,{name:"sparkling",className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(xe,{variant:"ghost",size:"sm",onClick:h,disabled:v||o,className:"gap-1.5",children:[d==="abort"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"close",className:"size-4"}),c("gitView.operation.abort")]}),!i&&s.jsxs(xe,{variant:"default",size:"sm",onClick:b,disabled:v||o,className:"gap-1.5",children:[d==="continue"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"}),c("gitView.operation.continue")]})]}),i&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:c("gitView.operation.resolveConflictsHint")})]})})},$0=t=>{const e=ot.c(104),{currentBranch:n,localBranches:r,remoteBranches:a,onMerge:i,onRebase:o,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:f}=t,b=c===void 0?!1:c,h=d===void 0?!1:d,v=p===void 0?[]:p,x=u===void 0?"dialog":u,{t:g}=pt(),[w,y]=l.useState(!1),[k,A]=l.useState("merge"),[j,S]=l.useState(null),[D,E]=l.useState(!1),[P,C]=l.useState(""),N=l.useRef(null),T=l.useRef(null),M=b||h,F=n||g("gitView.branch.currentBranchFallback"),_=v.length>0&&v.every(B0),B=v.some(_0);let V;e[0]===Symbol.for("react.memo_cache_sentinel")?(V=()=>{T.current&&(T.current.scrollTop=T.current.scrollHeight)},e[0]=V):V=e[0],l.useEffect(V,[v]);let $;if(e[1]!==P||e[2]!==n||e[3]!==r||e[4]!==a){e:{const O=P.toLowerCase();let X;e[6]!==a?(X=new Set(a.map(z0).filter(Boolean)),e[6]=a,e[7]=X):X=e[7];const G=X;let Te;e[8]!==n||e[9]!==G?(Te=We=>We!==n&&!G.has(We),e[8]=n,e[9]=G,e[10]=Te):Te=e[10];const le=r.filter(Te);if(!O){$=le;break e}$=le.filter(We=>We.toLowerCase().includes(O))}e[1]=P,e[2]=n,e[3]=r,e[4]=a,e[5]=$}else $=e[5];const z=$;let Q;if(e[11]!==P||e[12]!==a){e:{const O=P.toLowerCase();if(!O){Q=a;break e}Q=a.filter(X=>X.toLowerCase().includes(O))}e[11]=P,e[12]=a,e[13]=Q}else Q=e[13];const L=Q;let J;e[14]!==f||e[15]!==r||e[16]!==a?(J=()=>f&&(a.includes(f)||r.includes(f))?f:null,e[14]=f,e[15]=r,e[16]=a,e[17]=J):J=e[17];const ee=J;let re;e[18]!==ee||e[19]!==y?(re=()=>{y(!0),S(ee()),A("merge"),C("")},e[18]=ee,e[19]=y,e[20]=re):re=e[20];const q=re;let ce;e[21]===Symbol.for("react.memo_cache_sentinel")?(ce=O=>{S(O),E(!1),C("")},e[21]=ce):ce=e[21];const ae=ce;let R;e[22]!==i||e[23]!==o||e[24]!==k||e[25]!==j?(R=()=>{j&&(k==="merge"?i(j):o(j))},e[22]=i,e[23]=o,e[24]=k,e[25]=j,e[26]=R):R=e[26];const U=R;let W;e[27]!==h||e[28]!==y?(W=()=>{h||(S(null),A("merge"),C(""),y(!1))},e[27]=h,e[28]=y,e[29]=W):W=e[29];const Z=W,K=()=>{h&&!_||(_&&m?.(),S(null),A("merge"),C(""),y(!1))};let ie,Ne;e[30]!==D?(ie=()=>{D||C("")},Ne=[D],e[30]=D,e[31]=ie,e[32]=Ne):(ie=e[31],Ne=e[32]),l.useEffect(ie,Ne);let ne,fe;e[33]!==x||e[34]!==ee||e[35]!==j?(ne=()=>{x!=="inline"||j||S(ee())},fe=[x,ee,j],e[33]=x,e[34]=ee,e[35]=j,e[36]=ne,e[37]=fe):(ne=e[36],fe=e[37]),l.useEffect(ne,fe);const oe=h?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:T,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:v.map(V0)})}),_?x==="dialog"?s.jsx(Us,{children:s.jsx(xe,{variant:"default",size:"sm",onClick:K,children:g(B?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(xe,{variant:"default",size:"sm",onClick:K,children:g(B?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:g("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>A("merge"),className:ue("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",k==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-merge",className:ue("size-4",k==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:ue("typography-ui-label",k==="merge"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>A("rebase"),className:ue("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",k==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-branch",className:ue("size-4",k==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:ue("typography-ui-label",k==="rebase"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:k==="merge"?g("gitView.branch.branchToMergeInto",{branch:F}):g("gitView.branch.branchToRebaseOnto")}),s.jsxs(Fs,{open:D,onOpenChange:E,modal:!1,children:[s.jsx(Es,{asChild:!0,children:s.jsxs(xe,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:ue("truncate",!j&&"text-muted-foreground"),children:j||g("gitView.branch.selectBranch")}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Rs,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(Oa,{className:"h-full min-h-0",children:[s.jsx(oa,{ref:N,placeholder:g("gitView.branch.searchPlaceholder"),value:P,onValueChange:C,onKeyDown:U0}),s.jsxs(La,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx($a,{children:g("gitView.branch.empty")}),z.length>0&&s.jsx(Rn,{heading:g("gitView.branch.localBranches"),children:z.map(O=>s.jsx(kn,{onSelect:()=>ae(O),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`local-${O}`))}),z.length>0&&L.length>0?s.jsx(ka,{}):null,L.length>0&&s.jsx(Rn,{heading:g("gitView.branch.remoteBranches"),children:L.map(O=>s.jsx(kn,{onSelect:()=>ae(O),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`remote-${O}`))})]})]})})]})]}),j?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:k==="merge"?s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})," ",g("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:F})]}):s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:F})," ",g("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})]})})}):null,x==="dialog"?s.jsxs(Us,{className:"gap-2 pt-1",children:[s.jsx(xe,{variant:"ghost",size:"sm",onClick:Z,children:g("gitView.common.cancel")}),s.jsx(xe,{variant:"default",size:"sm",onClick:U,disabled:!j,className:"gap-1.5",children:k==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-merge",className:"size-4"}),g("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-branch",className:"size-4"}),g("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(xe,{variant:"destructive",size:"sm",onClick:Z,disabled:M,children:g("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(xe,{variant:"default",size:"sm",onClick:U,disabled:M||!j,children:g(k==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(x==="inline"){let O;e[38]!==g?(O=g("gitView.branch.updateTitle"),e[38]=g,e[39]=O):O=e[39];let X;e[40]!==O?(X=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:O}),e[40]=O,e[41]=X):X=e[41];let G;e[42]!==g?(G=g("gitView.branch.updateDescriptionPrefix"),e[42]=g,e[43]=G):G=e[43];let Te;e[44]!==F?(Te=s.jsx("span",{className:"font-mono text-foreground",children:F}),e[44]=F,e[45]=Te):Te=e[45];let le;e[46]!==G||e[47]!==Te?(le=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[G," ",Te,"."]}),e[46]=G,e[47]=Te,e[48]=le):le=e[48];let We;e[49]!==X||e[50]!==le?(We=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[X,le]})}),e[49]=X,e[50]=le,e[51]=We):We=e[51];let de;e[52]!==oe?(de=s.jsx("div",{className:"pt-3",children:oe}),e[52]=oe,e[53]=de):de=e[53];let Fe;return e[54]!==We||e[55]!==de?(Fe=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[We,de]}),e[54]=We,e[55]=de,e[56]=Fe):Fe=e[56],Fe}let Se;e[57]!==h?(Se=h?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"}),e[57]=h,e[58]=Se):Se=e[58];let se;e[59]!==g?(se=g("gitView.branch.mergeRebase"),e[59]=g,e[60]=se):se=e[60];let we;e[61]!==se?(we=s.jsx("span",{children:se}),e[61]=se,e[62]=we):we=e[62];let Ae;e[63]!==q||e[64]!==M||e[65]!==Se||e[66]!==we?(Ae=s.jsx(kt,{asChild:!0,children:s.jsxs(xe,{variant:"outline",size:"sm",className:"gap-1.5",onClick:q,disabled:M,children:[Se,we]})}),e[63]=q,e[64]=M,e[65]=Se,e[66]=we,e[67]=Ae):Ae=e[67];let ve;e[68]!==g?(ve=g("gitView.branch.mergeRebaseTooltip"),e[68]=g,e[69]=ve):ve=e[69];let ye;e[70]!==ve?(ye=s.jsx(Ct,{sideOffset:8,children:ve}),e[70]=ve,e[71]=ye):ye=e[71];let Ie;e[72]!==Ae||e[73]!==ye?(Ie=s.jsxs(St,{children:[Ae,ye]}),e[72]=Ae,e[73]=ye,e[74]=Ie):Ie=e[74];let he;e[75]!==K||e[76]!==y?(he=O=>{O?y(!0):K()},e[75]=K,e[76]=y,e[77]=he):he=e[77];let me;e[78]!==g?(me=g("gitView.branch.updateTitle"),e[78]=g,e[79]=me):me=e[79];let Ee;e[80]!==me?(Ee=s.jsx(gs,{children:me}),e[80]=me,e[81]=Ee):Ee=e[81];let Ve;e[82]!==B||e[83]!==h||e[84]!==k||e[85]!==_||e[86]!==g||e[87]!==F?(Ve=h?g(_?B?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":k==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[g("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:F}),"."]}),e[82]=B,e[83]=h,e[84]=k,e[85]=_,e[86]=g,e[87]=F,e[88]=Ve):Ve=e[88];let Y;e[89]!==Ve?(Y=s.jsx(Ps,{children:Ve}),e[89]=Ve,e[90]=Y):Y=e[90];let ke;e[91]!==Ee||e[92]!==Y?(ke=s.jsxs(vs,{children:[Ee,Y]}),e[91]=Ee,e[92]=Y,e[93]=ke):ke=e[93];let Be;e[94]!==oe||e[95]!==ke?(Be=s.jsxs(ms,{className:"max-w-md",children:[ke,oe]}),e[94]=oe,e[95]=ke,e[96]=Be):Be=e[96];let Ce;e[97]!==w||e[98]!==he||e[99]!==Be?(Ce=s.jsx(ps,{open:w,onOpenChange:he,children:Be}),e[97]=w,e[98]=he,e[99]=Be,e[100]=Ce):Ce=e[100];let ge;return e[101]!==Ie||e[102]!==Ce?(ge=s.jsxs(s.Fragment,{children:[Ie,Ce]}),e[101]=Ie,e[102]=Ce,e[103]=ge):ge=e[103],ge};function B0(t){return t.status==="done"||t.status==="error"}function _0(t){return t.status==="error"}function z0(t){return t.slice(t.indexOf("/")+1)}function V0(t,e){return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"mt-0.5 shrink-0",children:[t.status==="running"&&s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(I,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(I,{name:"close",className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className:ue("typography-micro",t.status==="error"&&"text-destructive",t.status==="done"&&"text-muted-foreground",t.status==="running"&&"text-foreground",t.status==="pending"&&"text-muted-foreground/60"),children:t.message})]},e)}function U0(t){return t.stopPropagation()}const Mm="oc.git.actionTab",W0=t=>t==="commit"||t==="branch"||t==="pr",Wh="gitmojiCache",K0=1e3*60*60*24*7,Kh="1",H0=40,G0=20,q0="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Em={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Hh=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Y0=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(Wh);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==Kh||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Hh),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},J0=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:Kh};localStorage.setItem(Wh,JSON.stringify(e))}catch{return}},Q0=t=>Date.now()-t.fetchedAt<K0,X0=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,a=n.match(r);if(a){const c=a[1],d=Em[c];if(d)return e.find(p=>p.code===d)||null}const i=n.split(" ")[0],o=Em[i];return o&&e.find(c=>c.code===o)||null},Rm=new Map,ga=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Gh=()=>{const{t}=pt(),{git:e}=On(),n=Lr(),[r,a]=l.useState(null),[i,o]=l.useState(!1),c=Lt(Re=>Re.currentSessionId),d=Lt(Re=>Re.newSessionDraft),p=Lt(Re=>Re.setDraftBootstrapPendingDirectory),m=Lt(Re=>Re.worktreeMetadata),u=Lt(Re=>Re.availableWorktrees),f=ga(n),b=l.useMemo(()=>{if(!f)return;const Re=u.find(Xe=>ga(Xe.path)===f);if(Re)return Re;for(const Xe of m.values())if(ga(Xe.path)===f)return Xe},[u,f,m]),h=l.useMemo(()=>{if(c)return m.get(c)??b;if(d?.open)return b},[c,b,d?.open,m]),{profiles:v,globalIdentity:x,defaultGitIdentityId:g,loadProfiles:w,loadGlobalIdentity:y,loadDefaultGitIdentityId:k}=Jn(hr(Re=>({profiles:Re.profiles,globalIdentity:Re.globalIdentity,defaultGitIdentityId:Re.defaultGitIdentityId,loadProfiles:Re.loadProfiles,loadGlobalIdentity:Re.loadGlobalIdentity,loadDefaultGitIdentityId:Re.loadDefaultGitIdentityId}))),A=Ed(n??null),j=Dl(n??null),S=Wf(Re=>c?Re.getAttachment(c):void 0),D=S?yb(S):[],E=S&&!S.degraded&&!S.legacy?S.worktreeRoot??void 0:void 0,P=O1(n,h,j?.current??void 0),C=Rd(n??null),N=vb(n??null),T=wb(n??null),M=Fd(n??null),F=jb(n??null),_=Zs(Re=>Re.setActiveDirectory),B=Zs(Re=>Re.fetchAll),V=Zs(Re=>Re.ensureAll),$=Zs(Re=>Re.fetchStatus),z=Zs(Re=>Re.fetchBranches),Q=Zs(Re=>Re.fetchLog),L=Zs(Re=>Re.fetchIdentity),J=Zs(Re=>Re.prefetchDiffs),ee=Zs(Re=>Re.setLogMaxCount),re=De(Re=>Re.isMobile),q=De(Re=>Re.openContextDiff),ce=De(Re=>Re.navigateToDiff),ae=De(Re=>Re.setRightSidebarOpen),R=l.useRef(null);l.useEffect(()=>{if(!n){a(null),o(!1);return}let Re=!1,Xe=null;const et=async()=>{try{const dt=await Sb(n);if(Re)return;a(dt.status),dt.status==="pending"&&(Xe=window.setTimeout(()=>{et()},500))}catch{Re||a(null)}};return et(),()=>{Re=!0,Xe!==null&&window.clearTimeout(Xe)}},[n]),l.useEffect(()=>{const Re=R.current;R.current=r,!(!n||!e)&&(Re==="pending"&&r==="ready"&&(o(!0),B(n,e).finally(()=>{window.setTimeout(()=>{o(!1)},1200)})),r==="failed"&&(p(null),o(!1)))},[n,B,e,p,r]);const U=ga(d?.bootstrapPendingDirectory??null),W=!!(n&&U&&U===ga(n)),K=!!(n&&(r==="pending"||W))||i,ie=l.useMemo(()=>n?Rm.get(n)??null:null,[n]),Ne=vt(Re=>Re.settingsGitmojiEnabled),[ne,fe]=l.useState(null);l.useEffect(()=>{const Re=E||P?.projectDirectory;if(!Re){fe(null);return}let Xe=!1;return oo(Re).then(et=>{if(Xe)return;const dt=et.trim();fe(dt&&dt!=="HEAD"?dt:null)}).catch(()=>{Xe||fe(null)}),()=>{Xe=!0}},[E,P?.projectDirectory]);const[pe,je]=l.useState(ie?.commitMessage??""),[oe,Se]=l.useState([]),[se,we]=l.useState(!1),Ae=l.useRef(null),[ve,ye]=l.useState(null),[Ie,he]=l.useState(!1),[me,Ee]=l.useState(null),[Ve,Y]=l.useState(25),[ke,Be]=l.useState(!1),{triggerFireworks:Ce}=T1(),ge=l.useRef(new Map),O=l.useRef(0),X=l.useCallback(()=>{O.current+=1,Be(!0)},[]),G=l.useCallback(()=>{O.current=Math.max(0,O.current-1),O.current===0&&Be(!1)},[]),[Te,le]=l.useState(()=>new Set(ie?.selectedPaths??[])),[We,de]=l.useState(!1),[Fe,rt]=l.useState(new Set),[Oe,Ye]=l.useState(!1),[Ge,it]=l.useState(0),[Qe,at]=l.useState(!1),[nt,be]=l.useState(ie?.generatedHighlights??[]),He=l.useCallback(()=>{const Re=Ae.current;Re&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Re.scrollTo({top:Re.scrollHeight,behavior:"smooth"})})})},[]),_e=E||P?.projectDirectory||null,tt=j?.current||null,ut=l.useMemo(()=>{const Re=j?.tracking;return Re?Re.startsWith("origin/"):!0},[j?.tracking]),qe=l.useMemo(()=>{const Re=P?.createdFromBranch,Xe=typeof Re=="string"?Re.trim():"",et=typeof j?.current=="string"?j.current.trim():"",dt=typeof ne=="string"?ne.trim():"";return Xe?Xe===et&&Xe.startsWith("opencode/")&&dt.length>0&&dt!==Xe?dt:Xe:dt||et||"HEAD"},[P?.createdFromBranch,j,ne]),ze=l.useCallback(()=>{be([])},[]),[st,yt]=l.useState(new Set),[Mt,Bt]=l.useState(new Map),[ft,It]=l.useState(new Set),[ss,_t]=l.useState(null),[qt,ct]=l.useState(null),[jt,as]=l.useState([]),[xs,ws]=l.useState(""),[As,Gt]=l.useState(!1),Ke=l.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(I,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(I,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[Pt,Ot]=l.useState(()=>{if(typeof window>"u")return"commit";const Re=window.localStorage.getItem(Mm);return Re==="worktree"?"branch":W0(Re)?Re:"commit"}),[Nt,Ht]=l.useState([]),[ns,Ss]=l.useState(null),[fs,Os]=l.useState(null),[zs,tn]=l.useState([]),[Ds,zt]=l.useState(!1),[Kt,te]=l.useState([]),[bt,Ze]=l.useState("merge"),Wt=l.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),es=l.useCallback((Re,Xe,et)=>{if(!Wt||typeof window>"u")return;const dt={directory:Re,conflictFiles:Xe,operation:et};window.localStorage.setItem(Wt,JSON.stringify(dt))},[Wt]),rs=l.useCallback(()=>{!Wt||typeof window>"u"||window.localStorage.removeItem(Wt)},[Wt]);l.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Mm,Pt)},[Pt]),l.useEffect(()=>{if(!Wt||typeof window>"u"||!n)return;const Re=window.localStorage.getItem(Wt);if(Re)try{const Xe=JSON.parse(Re);if(Xe.directory!==n){window.localStorage.removeItem(Wt);return}te(Xe.conflictFiles??[]),Ze(Xe.operation??"merge"),zt(!0)}catch{window.localStorage.removeItem(Wt)}},[Wt,n]);const[Ue,xt]=l.useState(!1),[At,Dt]=l.useState("merge"),[Zt,Ut]=l.useState(""),ks=l.useCallback(Re=>{An(Re).then(Xe=>{if(Xe.ok){H.success(t("gitView.toast.commitHashCopied"));return}H.error(t("gitView.toast.copyFailed"))})},[t]),Js=l.useCallback(Re=>{yt(Xe=>{const et=new Set(Xe);return et.has(Re)?et.delete(Re):et.add(Re),et})},[]);l.useEffect(()=>{if(!n||!e)return;const Re=Array.from(st).filter(Xe=>!Mt.has(Xe)&&!ft.has(Xe));if(Re.length!==0){It(Xe=>{const et=new Set(Xe);for(const dt of Re)et.add(dt);return et});for(const Xe of Re)e.getCommitFiles(n,Xe).then(et=>{Bt(dt=>new Map(dt).set(Xe,et.files))}).catch(et=>{console.error("Failed to fetch commit files:",et),Bt(dt=>new Map(dt).set(Xe,[]))}).finally(()=>{It(et=>{const dt=new Set(et);return dt.delete(Xe),dt})})}},[st,n,e,Mt,ft]),l.useEffect(()=>{n&&Rm.set(n,{directory:n,selectedPaths:Array.from(Te),commitMessage:pe,generatedHighlights:nt})},[pe,n,Te,nt]),l.useEffect(()=>{w(),y(),k()},[w,y,k]),l.useEffect(()=>{if(!n||!e?.getRemoteUrl){ct(null);return}e.getRemoteUrl(n).then(ct).catch(()=>ct(null))},[n,e]);const Ls=l.useCallback(async()=>{if(!n||!e?.getRemotes){Ht([]);return}try{const Re=await e.getRemotes(n);Ht(Re)}catch{Ht([])}},[n,e]);l.useEffect(()=>{Ls()},[Ls]),l.useEffect(()=>{if(!Ne){as([]);return}let Re=!1;const Xe=Y0();return Xe&&(as(Xe.gitmojis),Q0(Xe))?()=>{Re=!0}:((async()=>{try{const dt=await fetch(q0);if(!dt.ok)throw new Error(`Failed to load gitmojis: ${dt.statusText}`);const Rt=await dt.json(),Xt=Array.isArray(Rt.gitmojis)?Rt.gitmojis.filter(Hh):[];Re||(as(Xt),J0(Xt))}catch(dt){Re||console.warn("Failed to load gitmoji list:",dt)}})(),()=>{Re=!0})},[Ne]),l.useEffect(()=>{n&&(_(n),V(n,e))},[n,_,V,e]),l.useEffect(()=>{if(n)return wr.onGitRefreshHint(Re=>{ga(Re.directory)===ga(n)&&$(n,e)})},[n,$,e]);const ts=l.useCallback(async(Re=!0)=>{if(n)try{await Promise.all([$(n,e),z(n,e)])}catch(Xe){if(Re){const et=Xe instanceof Error?Xe.message:t("gitView.toast.refreshRepositoryFailed");H.error(et)}}},[n,e,$,z,t]),js=l.useCallback(async()=>{n&&await Q(n,e,Ve)},[n,e,Q,Ve]),yn=l.useCallback(async()=>{n&&await L(n,e)},[n,e,L]);l.useEffect(()=>{if(!n||!e?.hasLocalIdentity||A!==!0)return;const Re=typeof g=="string"?g.trim():"";if(!Re||Re==="global"||ge.current.get(n)===Re)return;let et=!1;return(async()=>{try{const Rt=await e.hasLocalIdentity?.(n);if(et||Rt===!0)return;X(),await e.setGitIdentity(n,Re),ge.current.set(n,Re),await yn()}catch(Rt){console.warn("Failed to auto-apply default git identity:",Rt)}finally{et||G()}})(),()=>{et=!0}},[X,n,g,G,e,A,yn]);const cn=l.useMemo(()=>{if(!j)return[];const Re=j.files??[],Xe=new Map;for(const et of Re)Xe.set(et.path,et);return Array.from(Xe.values()).sort((et,dt)=>et.path.localeCompare(dt.path))},[j]);l.useEffect(()=>{if(!n||cn.length===0)return;const Re=[],Xe=new Set,et=Rt=>{!Rt||Xe.has(Rt)||(Xe.add(Rt),Re.push(Rt))};if(Array.from(Te).forEach(et),oe.forEach(et),cn.slice(0,G0).forEach(Rt=>et(Rt.path)),Re.length===0)return;const dt=window.setTimeout(()=>{J(n,e,Re,{maxFiles:H0})},120);return()=>{window.clearTimeout(dt)}},[cn,n,e,J,Te,oe]),l.useEffect(()=>{if(!j||cn.length===0){le(new Set),de(!1);return}le(Re=>{const Xe=new Set,et=Re??new Set;for(const dt of cn)et.has(dt.path)?Xe.add(dt.path):We||Xe.add(dt.path);return Xe})},[j,cn,We]);const Rr=async(Re,Xe)=>{if(n){ye(Re);try{const et=dt=>{const Rt=`${dt.name}/`,Xt=j?.tracking?.startsWith(Rt)?j.tracking.slice(Rt.length):void 0;return{remote:dt.name,branch:Xt,rebase:!0}};if(Re==="fetch"){if(!Xe)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:Xe.name}),H.success(t("gitView.toast.fetchedFromRemote",{name:Xe.name}))}else if(Re==="pull"){if(!Xe)throw new Error("No remote available for pull");const dt=await e.gitPull(n,et(Xe));H.success(dt.files.length===1?t("gitView.toast.pulledFilesSingle",{count:dt.files.length,name:Xe.name}):t("gitView.toast.pulledFilesPlural",{count:dt.files.length,name:Xe.name}))}else if(Re==="push")await e.gitPush(n),H.success(t("gitView.toast.pushedToUpstream"));else if(Re==="sync"){if(!Xe)throw new Error("No remote available for sync");let dt=0,Rt=!1;await e.gitFetch(n,{remote:Xe.name});const Xt=await e.getGitStatus(n);if((Xt.behind??0)>0){if((Xt.files?.length??0)>0){H.error(t("gitView.toast.commitOrStashBeforeSync"));return}dt=(await e.gitPull(n,et(Xe))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Rt=!0),dt>0&&Rt?H.success(dt===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:dt,name:Xe.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:dt,name:Xe.name})):dt>0?H.success(dt===1?t("gitView.toast.pulledFilesSingle",{count:dt,name:Xe.name}):t("gitView.toast.pulledFilesPlural",{count:dt,name:Xe.name})):Rt?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate"))}await ts(!1),await js()}catch(et){const dt=et instanceof Error?et.message:t("gitView.toast.syncActionFailed",{action:Re==="sync"?t("gitView.sync.syncChanges"):Re==="pull"?t("gitView.sync.pull"):Re});H.error(dt)}finally{ye(null)}}},kr=l.useCallback(async Re=>{if(!n)return;const Xe=Re.name.trim();if(!Xe){H.error(t("gitView.toast.remoteNameRequired"));return}if(Xe==="origin"){H.error(t("gitView.toast.cannotRemoveOriginRemote"));return}Ss(Xe);try{await e.removeRemote(n,{remote:Xe}),H.success(t("gitView.toast.removedRemote",{name:Xe})),await Promise.all([ts(!1),Ls()])}catch(et){const dt=et instanceof Error?et.message:`Failed to remove ${Xe}`;H.error(dt)}finally{Ss(null)}},[n,e,Ls,ts,t]),Ws=async(Re={})=>{if(!n)return;if(!pe.trim()){H.error(t("gitView.toast.enterCommitMessage"));return}const Xe=Array.from(Te).sort();if(Xe.length===0){H.error(t("gitView.toast.selectFileToCommit"));return}const et=Re.pushAfter?"commitAndPush":"commit";Ee(et);try{if(await e.createGitCommit(n,pe.trim(),{files:Xe}),H.success(t("gitView.toast.commitCreated")),je(""),le(new Set),de(!1),ze(),await ts(),Re.pushAfter){ye("sync");const dt=j?.tracking?.split("/")[0],Rt=wn.find(Br=>Br.name===dt)??wn[0];if(!Rt)throw new Error("No remote available for sync");const Xt=`${Rt.name}/`,$s=j?.tracking?.startsWith(Xt)?j.tracking.slice(Xt.length):void 0;let Bs=0,qn=!1;await e.gitFetch(n,{remote:Rt.name}),((await e.getGitStatus(n)).behind??0)>0&&(Bs=(await e.gitPull(n,{remote:Rt.name,branch:$s,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),qn=!0),Bs>0&&qn?H.success(Bs===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:Bs,name:Rt.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:Bs,name:Rt.name})):Bs>0?H.success(Bs===1?t("gitView.toast.pulledFilesSingle",{count:Bs,name:Rt.name}):t("gitView.toast.pulledFilesPlural",{count:Bs,name:Rt.name})):qn?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate")),Ce(),await ts(!1)}else await ts(!1);await js(),it(dt=>dt+1)}catch(dt){const Rt=dt instanceof Error?dt.message:t("gitView.toast.createCommitFailed");H.error(Rt)}finally{Ee(null),Re.pushAfter&&ye(null)}},Ln=l.useCallback(async()=>{if(n){if(Te.size===0){H.error(t("gitView.toast.selectFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Te.size}),at(!0);try{const{message:Re}=await Nb(n,Array.from(Te)),Xe=Re.subject?.trim()??"",et=Array.isArray(Re.highlights)?Re.highlights:[];if(Xe){let dt=Xe;if(Ne&&jt.length>0){const Rt=X0(Xe,jt);if(Rt){const{code:Xt,emoji:$s}=Rt;!Xe.startsWith(Xt)&&!Xe.startsWith($s)&&(dt=`${Xt} ${Xe}`)}}je(dt)}be(et),He()}catch(Re){console.error("[git-generation][browser] GitView generate handler failed",{message:Re instanceof Error?Re.message:String(Re),error:Re});const Xe=Re instanceof Error?Re.message:t("gitView.toast.generateCommitMessageFailed");H.error(Xe)}finally{at(!1)}}},[n,Te,Ne,jt,He,t]),Vn=Re=>Re.reason==="attention"?`${Re.attentionReason} in progress`:Re.reason==="missing"?"worktree is missing":"worktree is invalid",er=async(Re,Xe)=>{if(!n||!j)return;const et=Ql(S);if(et.length>0){H.error(t("gitView.toast.cannotCreateBranch",{reason:Vn(et[0])}));return}const dt=j.current??null,Rt=Xe?.name??"origin";try{await e.createBranch(n,Re,dt??"HEAD"),H.success(t("gitView.toast.createdBranch",{name:Re})),await e.checkoutBranch(n,Re);let Xt=!1;try{await e.gitPush(n,{remote:Rt,branch:Re,options:["--set-upstream"]}),Xt=!0}catch($s){const Bs=$s instanceof Error?$s.message:`Unable to push new branch to ${Rt}.`;H.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Bs]})})}await ts(),await js(),Xt&&H.success(t("gitView.toast.upstreamSet",{branch:Re,remote:Rt}))}catch(Xt){const $s=Xt instanceof Error?Xt.message:t("gitView.toast.createBranchFailed");throw H.error($s),Xt}},Cr=async(Re,Xe)=>{if(!n)return;const et=Ql(S);if(et.length>0){H.error(t("gitView.toast.cannotRenameBranch",{reason:Vn(et[0])}));return}try{await e.renameBranch(n,Re,Xe),H.success(t("gitView.toast.renamedBranch",{oldName:Re,newName:Xe})),await ts(),await js()}catch(dt){const Rt=dt instanceof Error?dt.message:t("gitView.toast.renameBranchFailed",{oldName:Re,newName:Xe});H.error(Rt)}},Un=async Re=>{if(!n)return;const Xe=Ql(S);if(Xe.length>0){H.error(t("gitView.toast.cannotCheckout",{reason:Vn(Xe[0])}));return}const et=Re.replace(/^remotes\//,"");if(j?.current!==et)try{await e.checkoutBranch(n,et),H.success(t("gitView.toast.checkedOut",{name:et})),await ts(),await js()}catch(dt){const Rt=dt instanceof Error?dt.message:t("gitView.toast.checkoutFailed",{name:et});H.error(Rt)}},In=async Re=>{if(n){X();try{await e.setGitIdentity(n,Re.id),H.success(t("gitView.toast.appliedIdentity",{name:Re.name})),await yn()}catch(Xe){const et=Xe instanceof Error?Xe.message:t("gitView.toast.applyIdentityFailed");H.error(et)}finally{G()}}},an=l.useMemo(()=>C?.all?C.all.filter(Re=>!Re.startsWith("remotes/")).sort():[],[C]),vn=l.useMemo(()=>C?.all?C.all.filter(Re=>Re.startsWith("remotes/")).map(Re=>Re.replace(/^remotes\//,"")).sort():[],[C]),wn=l.useMemo(()=>{if(Nt.length>0)return Nt;const Re=new Set,Xe=j?.tracking?.trim();Xe&&Xe.includes("/")&&Re.add(Xe.split("/")[0]);for(const et of vn){const dt=et.indexOf("/");dt>0&&Re.add(et.slice(0,dt))}return Re.size===0&&qt&&Re.add("origin"),Array.from(Re).map(et=>({name:et,fetchUrl:qt??"",pushUrl:qt??""}))},[Nt,vn,qt,j?.tracking]),Le=l.useMemo(()=>{const Re=new Set(wn.map(Rt=>Rt.name)),Xe=Rt=>{if(!Rt)return"";let Xt=Rt.trim();if(!Xt||Xt==="HEAD")return"";if(an.includes(Xt))return Xt;Xt.startsWith("refs/heads/")&&(Xt=Xt.slice(11)),Xt.startsWith("heads/")&&(Xt=Xt.slice(6)),Xt.startsWith("remotes/")&&(Xt=Xt.slice(8));const $s=Xt.indexOf("/");if($s>0){const Bs=Xt.slice(0,$s);if(Re.has(Bs)){const qn=Xt.slice($s+1).trim();qn&&(Xt=qn)}}return Xt},et=Xe(typeof P?.createdFromBranch=="string"?P.createdFromBranch:"");if(et)return et;const dt=Xe(typeof ne=="string"?ne:"");return dt||(an.includes("main")?"main":an.includes("master")?"master":an.includes("develop")?"develop":"main")},[wn,an,ne,P?.createdFromBranch]),Tt=l.useMemo(()=>wn.map(et=>et.name).map(et=>`${et}/${Le}`).find(et=>vn.includes(et))??Le,[Le,wn,vn]),Qt=l.useMemo(()=>{const Re=new Map;x&&Re.set(x.id,x);let Xe=null;if(qt)try{let et=qt.trim();et.startsWith("git@")&&(et=`https://${et.slice(4).replace(":","/")}`),et.endsWith(".git")&&(et=et.slice(0,-4));const dt=new URL(et);Xe=dt.hostname+dt.pathname}catch{}for(const et of v){if(et.authType!=="token"){Re.set(et.id,et);continue}const dt=et.host;if(!dt){Re.set(et.id,et);continue}if(!dt.includes("/")){Re.set(et.id,et);continue}Xe&&Xe===dt&&Re.set(et.id,et)}return Array.from(Re.values())},[v,x,qt]),cs=l.useMemo(()=>{if(T?.userName&&T?.userEmail){const Re=v.find(Xe=>Xe.userName===T.userName&&Xe.userEmail===T.userEmail);return Re||(x&&x.userName===T.userName&&x.userEmail===T.userEmail?x:{id:"local-config",name:T.userName,userName:T.userName,userEmail:T.userEmail,sshKey:T.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return x??null},[T,v,x]),Gs=Te.size,Ks=M||ve!==null||me!==null,bs=j?.current??null,Hs=!!(P&&_e&&tt&&ut),on=!!(n&&bs),rr=!!bs,Dn=Hs&&_e&&tt&&P?{repoRoot:_e,sourceBranch:tt,worktreeMetadata:P}:null,Wn=l.useMemo(()=>!on||!n||!bs?null:{directory:n,branch:bs},[on,bs,n]);l.useEffect(()=>{if(!n||!e||!N?.all?.length||!bs||!Le||bs===Le){_t(null);return}let Re=!1;return(async()=>{try{const et=await e.getGitLog(n,{from:Le,to:"HEAD",maxCount:Ve});if(Re)return;const dt=new Set((et?.all??[]).map(Xt=>Xt.hash).filter(Xt=>typeof Xt=="string"&&Xt.length>0));if(dt.size===0){_t(null);return}const Rt=N.all.findIndex(Xt=>!dt.has(Xt.hash));if(Rt===0){_t(null);return}if(Rt===-1){_t({insertBeforeIndex:N.all.length,branchName:bs,direction:"up"});return}_t({insertBeforeIndex:Rt,branchName:bs,direction:"up"})}catch{Re||_t(null)}})(),()=>{Re=!0}},[Le,bs,n,e,N,Ve]);const $r=Re=>{le(Xe=>{const et=new Set(Xe);return et.has(Re)?et.delete(Re):et.add(Re),et}),de(!0)},Ir=()=>{const Re=new Set(cn.map(Xe=>Xe.path));le(Re),de(!0)},Pn=()=>{le(new Set),de(!0)},Kn=l.useCallback(async Re=>{if(n){rt(Xe=>{const et=new Set(Xe);return et.add(Re),et});try{await e.revertGitFile(n,Re),H.success(t("gitView.toast.revertedFile",{path:Re})),await ts(!1)}catch(Xe){const et=Xe instanceof Error?Xe.message:t("gitView.toast.revertFailed");H.error(et)}finally{rt(Xe=>{const et=new Set(Xe);return et.delete(Re),et})}}},[n,ts,e,t]),un=l.useCallback(async Re=>{if(!n||Re.length===0||Oe)return;const Xe=Array.from(new Set(Re));Ye(!0),rt(dt=>{const Rt=new Set(dt);return Xe.forEach(Xt=>Rt.add(Xt)),Rt});const et=[];try{if(await Promise.all(Xe.map(async dt=>{try{await e.revertGitFile(n,dt)}catch(Rt){et.push({path:dt,message:Rt instanceof Error?Rt.message:t("gitView.toast.revertFailed")})}})),await ts(!1),et.length===0)H.success(Xe.length===1?t("gitView.toast.revertedFilesSingle",{count:Xe.length}):t("gitView.toast.revertedFilesPlural",{count:Xe.length}));else if(et.length===Xe.length)H.error(et[0]?.message||t("gitView.toast.revertFailed"));else{const dt=Xe.length-et.length;H.warning(dt===1?t("gitView.toast.revertedSomeSingle",{success:dt,failed:et.length}):t("gitView.toast.revertedSomePlural",{success:dt,failed:et.length}))}}finally{rt(dt=>{const Rt=new Set(dt);return Xe.forEach(Xt=>Rt.delete(Xt)),Rt}),Ye(!1)}},[n,e,Oe,ts,t]),Hn=l.useCallback(Re=>{if(Re.length===0)return;const Xe=Re.map(et=>et.trim()).filter(Boolean);if(Xe.length===0){ze();return}je(et=>{const dt=et.trim(),Rt=dt.length>0?`
|
|
43
|
-
|
|
44
|
-
`:"";return`${dt}${Rt}${Xe.join(`
|
|
45
|
-
`)}`.trim()}),ze()},[ze]),jn=l.useCallback((Re,Xe)=>{const et=Xe||Re;je(dt=>{const Rt=dt.trimStart();return Rt.startsWith(Re)||Xe&&Rt.startsWith(Xe)?dt:`${et.endsWith(" ")?et:`${et} `}${dt}`.trimStart()}),ws(""),we(!1)},[]),Fr=l.useCallback(Re=>{Y(Re),n&&(ee(n,Re),Q(n,e,Re))},[n,ee,Q,e]),ar=l.useCallback(Re=>{const Xe=Re instanceof Error?Re.message.toLowerCase():"";return Xe.includes("uncommitted changes")||Xe.includes("local changes")||Xe.includes("your local changes would be overwritten")||Xe.includes("please commit your changes or stash them")||Xe.includes("cannot rebase: you have unstaged changes")||Xe.includes("error: cannot pull with rebase")},[]),gr=l.useCallback((Re,Xe)=>{tn(et=>[...et,{message:Re,status:Xe,timestamp:Date.now()}])},[]),Nn=l.useCallback((Re,Xe)=>{tn(et=>{if(et.length===0)return et;const dt=[...et];return dt[dt.length-1]={...dt[dt.length-1],status:Re,...Xe?{message:Xe}:{}},dt})},[]),Gn=l.useCallback(()=>{tn([])},[]),tr=l.useCallback(()=>{tn([]),Os(null)},[]),mn=l.useCallback(Re=>{const Xe=Re.trim(),et=new Set(wn.map(Rt=>Rt.name)),dt=Xe.indexOf("/");if(dt>0){const Rt=Xe.slice(0,dt),Xt=Xe.slice(dt+1);if(et.has(Rt)&&Xt)return{branch:Xe,remote:Rt,remoteBranch:Xt}}for(const Rt of wn){const Xt=`${Rt.name}/${Xe}`;if(vn.includes(Xt))return{branch:Xt,remote:Rt.name,remoteBranch:Xe}}return{branch:Xe,remote:null,remoteBranch:null}},[wn,vn]),ir=l.useCallback(async Re=>{if(!n)return;Os("merge"),Gn();const Xe=j?.current,et=mn(Re);try{et.remote&&et.remoteBranch&&(gr(`Fetching ${et.remote}/${et.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:et.remote,branch:et.remoteBranch}),Nn("done",`Fetched ${et.remote}/${et.remoteBranch}`)),gr(`Merging ${et.branch} into ${Xe}...`,"running");const dt=await e.merge(n,{branch:et.branch});dt.conflict?(Nn("error","Merge conflicts detected"),te(dt.conflictFiles??[]),Ze("merge"),zt(!0),es(n,dt.conflictFiles??[],"merge")):(Nn("done",`Merged ${et.branch} into ${Xe}`),rs(),gr("Refreshing repository status...","running"),await ts(),await js(),Nn("done","Repository status updated"))}catch(dt){if(ar(dt))Nn("error","Uncommitted changes detected"),Dt("merge"),Ut(et.branch),xt(!0);else{const Rt=dt instanceof Error?dt.message:`Failed to merge ${et.branch}`;Nn("error",Rt)}}},[n,e,j,mn,ts,js,ar,es,rs,gr,Nn,Gn]),Ni=l.useCallback(async Re=>{if(!n)return;Os("rebase"),Gn();const Xe=j?.current,et=mn(Re);try{et.remote&&et.remoteBranch&&(gr(`Fetching ${et.remote}/${et.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:et.remote,branch:et.remoteBranch}),Nn("done",`Fetched ${et.remote}/${et.remoteBranch}`)),gr(`Rebasing ${Xe} onto ${et.branch}...`,"running");const dt=await e.rebase(n,{onto:et.branch});dt.conflict?(Nn("error","Rebase conflicts detected"),te(dt.conflictFiles??[]),Ze("rebase"),zt(!0),es(n,dt.conflictFiles??[],"rebase")):(Nn("done",`Rebased ${Xe} onto ${et.branch}`),rs(),gr("Refreshing repository status...","running"),await ts(),await js(),Nn("done","Repository status updated"))}catch(dt){if(ar(dt))Nn("error","Uncommitted changes detected"),Dt("rebase"),Ut(et.branch),xt(!0);else{const Rt=dt instanceof Error?dt.message:`Failed to rebase onto ${et.branch}`;Nn("error",Rt)}}},[n,e,j,mn,ts,js,ar,es,rs,gr,Nn,Gn]),za=l.useCallback(async()=>{if(n)try{bt==="merge"?(await e.abortMerge(n),H.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),H.success(t("gitView.toast.rebaseAborted"))),rs(),await ts(),await js()}catch(Re){const Xe=Re instanceof Error?Re.message:`Failed to abort ${bt}`;H.error(Xe)}},[n,e,bt,ts,js,rs,t]),Jr=l.useMemo(()=>j?.files?j.files.some(Re=>Re.index==="U"||Re.working_dir==="U"||Re.index==="A"&&Re.working_dir==="A"||Re.index==="D"&&Re.working_dir==="D"):!1,[j?.files]),la=l.useCallback(async()=>{if(n)try{const Re=!!j?.mergeInProgress?.head,Xe=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(Re){const et=await e.continueMerge(n);et.conflict?(te(et.conflictFiles??[]),Ze("merge"),zt(!0),es(n,et.conflictFiles??[],"merge"),H.error(t("gitView.toast.mergeConflictsDetected"))):(rs(),H.success(t("gitView.toast.mergeCompleted")),await ts(),await js())}else if(Xe){const et=await e.continueRebase(n);et.conflict?(te(et.conflictFiles??[]),Ze("rebase"),zt(!0),es(n,et.conflictFiles??[],"rebase"),H.error(t("gitView.toast.rebaseConflictsDetected"))):(rs(),H.success(t("gitView.toast.rebaseStepCompleted")),await ts(),await js())}}catch(Re){const Xe=Re instanceof Error?Re.message:t("gitView.toast.continueOperationFailed");H.error(Xe)}},[n,e,j,ts,js,es,rs,t]),hn=l.useCallback(async()=>{if(n)try{!!j?.mergeInProgress?.head?(await e.abortMerge(n),H.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),H.success(t("gitView.toast.rebaseAborted"))),rs(),await ts(),await js()}catch(Re){const Xe=Re instanceof Error?Re.message:t("gitView.toast.abortOperationFailed");H.error(Xe)}},[n,e,j,ts,js,rs,t]),ca=l.useCallback(()=>{if(!n)return;const Xe=!!j?.mergeInProgress?.head?"merge":"rebase",et=j?.files?.filter(dt=>dt.index==="U"||dt.working_dir==="U").map(dt=>dt.path)??[];et.length>0&&te(et),Ze(Xe),zt(!0)},[n,j]),Va=l.useCallback(async Re=>{if(!n)return;const Xe=j?.current,et=At,dt=Zt;try{await e.stash(n,{message:`Auto-stash before ${et} with ${dt}`,includeUntracked:!0})}catch($s){const Bs=$s instanceof Error?$s.message:"Failed to stash changes";H.error(Bs);return}let Rt=!1,Xt=!1;try{if(et==="merge"){const $s=await e.merge(n,{branch:dt});$s.conflict?(Xt=!0,te($s.conflictFiles??[]),Ze("merge"),zt(!0)):(Rt=!0,H.success(t("gitView.toast.mergedIntoBranch",{branch:dt,currentBranch:Xe||""})))}else{const $s=await e.rebase(n,{onto:dt});$s.conflict?(Xt=!0,te($s.conflictFiles??[]),Ze("rebase"),zt(!0)):(Rt=!0,H.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:Xe||"",branch:dt})))}if(Re&&Rt)try{await e.stashPop(n),H.success(t("gitView.toast.stashedRestored"))}catch($s){const Bs=$s instanceof Error?$s.message:t("gitView.toast.restoreStashFailed");H.error(Bs)}else Re&&Xt&&H.info(t("gitView.toast.restoreStashManually"));await ts(),await js()}catch($s){if(Re)try{await e.stashPop(n)}catch{}throw $s}},[n,e,j,At,Zt,ts,js,t]);return n?M&&A===null?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):A===!1?K?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.notGitRepositoryDescription")}),D.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:t("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:ue("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(tj,{status:j,localBranches:an,remoteBranches:vn,branchInfo:C?.branches,syncAction:ve,remotes:wn,onFetch:Re=>Rr("fetch",Re),onSync:Re=>Rr("sync",Re),onRemoveRemote:kr,removingRemoteName:ns,onCheckoutBranch:Un,onCreateBranch:er,onRenameBranch:Cr,activeIdentityProfile:cs,availableIdentities:Qt,onSelectIdentity:In,isApplyingIdentity:ke,isWorktreeMode:!!P,onOpenHistory:()=>Gt(!0),actionTabItems:Ke,activeActionTab:Pt,onSelectActionTab:Re=>Ot(Re)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(L0,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:la,onAbort:hn,onResolveWithAI:ca,hasUnresolvedConflicts:Jr,isLoading:M}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:ue("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(Ns,{as:io,ref:Ae,outerClassName:"flex-1 min-h-0",className:ue("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[Pt==="commit"?s.jsx("div",{className:"space-y-4",children:(cn?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx(uj,{maxListHeightClassName:"max-h-[40vh]",changeEntries:cn,onVisiblePathsChange:Se,selectedPaths:Te,diffStats:j?.diffStats,revertingPaths:Fe,onToggleFile:$r,onSelectAll:Ir,onClearSelection:Pn,onRevertAll:un,onViewDiff:Re=>{if(n&&!re){q(n,Re);return}ce(Re),re&&ae(!1)},onRevertFile:Kn,isRevertingAll:Oe,onOpenStashes:()=>he(!0)}),s.jsx(gj,{selectedCount:Gs,commitMessage:pe,onCommitMessageChange:je,generatedHighlights:nt,onInsertHighlights:Hn,onGenerateMessage:Ln,isGeneratingMessage:Qe,onCommit:()=>Ws({pushAfter:!1}),onCommitAndPush:()=>Ws({pushAfter:!0}),commitAction:me,gitmojiEnabled:Ne,onOpenGitmojiPicker:()=>we(!0)})]}):s.jsx(xj,{onOpenStashes:()=>he(!0)})}):null,Pt==="branch"?s.jsx("div",{className:"space-y-4",children:rr?s.jsxs(s.Fragment,{children:[s.jsx($0,{mode:"inline",currentBranch:j?.current,localBranches:an,remoteBranches:vn,defaultTargetBranch:Tt,onMerge:ir,onRebase:Ni,disabled:Ks,isOperating:fs!==null,operationLogs:zs,onOperationComplete:tr}),Dn?s.jsx(G1,{repoRoot:Dn.repoRoot,sourceBranch:Dn.sourceBranch,worktreeMetadata:Dn.worktreeMetadata,localBranches:an,defaultTargetBranch:qe,refreshKey:Ge,onRefresh:()=>{n&&($(n,e),z(n,e),Q(n,e,Ve))}},Dn.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,Pt==="pr"?s.jsx("div",{className:"space-y-4",children:Wn?s.jsx(P0,{directory:Wn.directory,branch:Wn.branch,baseBranch:Le,trackingBranch:j?.tracking??void 0,remotes:Nt,remoteBranches:vn,onGeneratedDescription:He}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:t("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(ps,{open:As,onOpenChange:Gt,children:s.jsxs(ms,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:t("gitView.history.title")}),s.jsx(Ps,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(Xj,{log:N,isLogLoading:F,logMaxCount:Ve,onLogMaxCountChange:Fr,expandedCommitHashes:st,onToggleCommit:Js,commitFilesMap:Mt,loadingCommitHashes:ft,onCopyHash:ks,directory:n??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ss})})]})}),s.jsx(sj,{open:Ie,onOpenChange:he,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,uncommittedFileCount:j?.files?.length??0,onChanged:async()=>{await ts(!1),await js()}}),s.jsx(ps,{open:se,onOpenChange:we,children:s.jsxs(ms,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(vs,{className:"px-4 pt-4",children:s.jsx(gs,{children:t("gitView.gitmoji.title")})}),s.jsxs(Oa,{className:"h-[420px]",children:[s.jsx(oa,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:xs,onValueChange:ws}),s.jsxs(La,{children:[s.jsx($a,{children:t("gitView.gitmoji.empty")}),s.jsx(Rn,{children:(jt.length===0?[]:jt.filter(Re=>{const Xe=xs.trim().toLowerCase();return Xe?Re.emoji.includes(Xe)||Re.code.toLowerCase().includes(Xe)||Re.description.toLowerCase().includes(Xe):!0})).map(Re=>s.jsxs(kn,{onSelect:()=>jn(Re.emoji,Re.code),children:[s.jsx("span",{className:"text-lg",children:Re.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Re.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Re.description})]},Re.code))})]})]})]})}),n&&s.jsx(A0,{open:Ds,onOpenChange:zt,conflictFiles:Kt,directory:n,operation:bt,onAbort:za,onClearState:rs}),s.jsx(O0,{open:Ue,onOpenChange:xt,operation:At,targetBranch:Zt,onConfirm:Va})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:t("gitView.empty.selectSessionOrDirectory")})})},Z0=Object.freeze(Object.defineProperty({__proto__:null,GitView:Gh},Symbol.toStringTag,{value:"Module"})),ld=5e3,eN=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},tN=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"},sN=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()},Qd=async(t,e)=>{try{const n=await sN(t,e);return eN(n,ld)>ld?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:tN(n)}}},Xd=t=>t==="too-large"?`File is too large to open (>${ld.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",nN=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),_n=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},qh=(t,e)=>{const n=_n(e),r=_n(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},rN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),aN=new Set(["node_modules"]),iN=t=>aN.has(t),oN=t=>{const e=_n(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Yh=(t,e)=>s.jsx(vr,{filePath:t,extension:e}),lN=t=>{const e=ot.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},cN=t=>{const e=ot.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:o,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:f,onToggle:b,onRevealPath:h,onOpenDialog:v}=t,{t:x}=pt(),g=n.type==="directory",{canRename:w,canCreateFile:y,canCreateFolder:k,canDelete:A,canReveal:j}=d;let S;e[0]!==y||e[1]!==k||e[2]!==A||e[3]!==w||e[4]!==j||e[5]!==n.path||e[6]!==u?(S=ee=>{!w&&!y&&!k&&!A&&!j||(ee?.preventDefault(),u(n.path))},e[0]=y,e[1]=k,e[2]=A,e[3]=w,e[4]=j,e[5]=n.path,e[6]=u,e[7]=S):S=e[7];const D=S;let E;e[8]!==g||e[9]!==n||e[10]!==f||e[11]!==b?(E=()=>{g?b(n.path):f(n)},e[8]=g,e[9]=n,e[10]=f,e[11]=b,e[12]=E):E=e[12];const P=E;let C;e[13]!==n.path||e[14]!==u?(C=ee=>{ee.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=C):C=e[15];const N=C;let T;e[16]!==n.path||e[17]!==r?(T=ee=>{const re=qh(r,n.path);!re||re==="."||(ee.dataTransfer.setData("application/x-openchamber-file-path",re),ee.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=T):T=e[18];const M=T,F=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let _;e[19]!==F?(_=ue("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 B;e[21]!==g||e[22]!==a||e[23]!==n.extension||e[24]!==n.path?(B=g?a?s.jsx(I,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):Yh(n.path,n.extension),e[21]=g,e[22]=a,e[23]=n.extension,e[24]=n.path,e[25]=B):B=e[25];let V;e[26]!==n.name||e[27]!==n.path?(V=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[26]=n.name,e[27]=n.path,e[28]=V):V=e[28];let $;e[29]!==g||e[30]!==o?($=!g&&o&&s.jsx(lN,{status:o}),e[29]=g,e[30]=o,e[31]=$):$=e[31];let z;e[32]!==c||e[33]!==g?(z=g&&c&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[c.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",c.modified]}),c.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",c.added]})]}),e[32]=c,e[33]=g,e[34]=z):z=e[34];let Q;e[35]!==D||e[36]!==M||e[37]!==P||e[38]!==z||e[39]!==_||e[40]!==B||e[41]!==V||e[42]!==$?(Q=s.jsxs("button",{type:"button",onClick:P,onContextMenu:D,draggable:!0,onDragStart:M,className:_,children:[B,V,$,z]}),e[35]=D,e[36]=M,e[37]=P,e[38]=z,e[39]=_,e[40]=B,e[41]=V,e[42]=$,e[43]=Q):Q=e[43];let L;e[44]!==y||e[45]!==k||e[46]!==A||e[47]!==w||e[48]!==j||e[49]!==m||e[50]!==p||e[51]!==N||e[52]!==g||e[53]!==n||e[54]!==v||e[55]!==h||e[56]!==u||e[57]!==x?(L=(w||y||k||A||j)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(Fs,{open:m===n.path,onOpenChange:ee=>u(ee?n.path:null),children:[s.jsx(Es,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:N,children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsxs(Rs,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[w&&s.jsxs($t,{onClick:ee=>{ee.stopPropagation(),v("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.rename")]}),s.jsxs($t,{onClick:ee=>{ee.stopPropagation(),An(n.path).then(re=>{if(re.ok){H.success(x("sidebarFilesTree.toast.pathCopied"));return}H.error(x("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.copyPath")]}),!g&&p&&s.jsxs($t,{onClick:ee=>{ee.stopPropagation(),p(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.save")]}),j&&s.jsxs($t,{onClick:ee=>{ee.stopPropagation(),h(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",x($d())]}),g&&(y||k)&&s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),y&&s.jsxs($t,{onClick:ee=>{ee.stopPropagation(),v("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFile")]}),k&&s.jsxs($t,{onClick:ee=>{ee.stopPropagation(),v("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFolder")]})]}),A&&s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),s.jsxs($t,{onClick:ee=>{ee.stopPropagation(),v("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=y,e[45]=k,e[46]=A,e[47]=w,e[48]=j,e[49]=m,e[50]=p,e[51]=N,e[52]=g,e[53]=n,e[54]=v,e[55]=h,e[56]=u,e[57]=x,e[58]=L):L=e[58];let J;return e[59]!==D||e[60]!==Q||e[61]!==L?(J=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:D,children:[Q,L]}),e[59]=D,e[60]=Q,e[61]=L,e[62]=J):J=e[62],J},dN=()=>{const t=ot.c(240),{t:e}=pt(),{files:n,runtime:r}=On(),a=Lr()??"";let i;t[0]!==a?(i=_n(a.trim()),t[0]=a,t[1]=i):i=t[1];const o=i,c=Tl(),d=Od(),p=Ld(uN),m=De(mN),u=Dl(a),[f,b]=l.useState(""),h=Ml(f,200),v=l.useRef(null);let x;t[2]===Symbol.for("react.memo_cache_sentinel")?(x=[],t[2]=x):x=t[2];const[g,w]=l.useState(x),[y,k]=l.useState(!1);let A;t[3]===Symbol.for("react.memo_cache_sentinel")?(A={},t[3]=A):A=t[3];const[j,S]=l.useState(A);let D;t[4]===Symbol.for("react.memo_cache_sentinel")?(D=new Set,t[4]=D):D=t[4];const E=l.useRef(D);let P;t[5]===Symbol.for("react.memo_cache_sentinel")?(P=new Set,t[5]=P):P=t[5];const C=l.useRef(P);let N;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=[],t[6]=N):N=t[6];const T=N;let M;t[7]===Symbol.for("react.memo_cache_sentinel")?(M=[],t[7]=M):M=t[7];const F=M;let _;t[8]!==o?(_=zt=>o?zt.byRoot[o]?.expandedPaths??T:T,t[8]=o,t[9]=_):_=t[9];const B=En(_);let V;t[10]!==o?(V=zt=>o?zt.byRoot[o]?.selectedPath??null:null,t[10]=o,t[11]=V):V=t[11];const $=En(V),z=En(pN),Q=En(fN),L=En(hN),J=En(gN);let ee;t[12]!==o?(ee=zt=>o?zt.contextPanelByDirectory[o]?.tabs??F:F,t[12]=o,t[13]=ee):ee=t[13];const re=De(ee);let q;t[14]!==re?(q=new Set(re.map(xN).filter(bN).map(yN)),t[14]=re,t[15]=q):q=t[15];const ce=q,[ae,R]=l.useState(null),[U,W]=l.useState(null),[Z,K]=l.useState(null),[ie,Ne]=l.useState(""),[ne,fe]=l.useState(!1),pe=!!n.writeFile,je=!!n.createDirectory,oe=!!n.rename,Se=!!n.delete,se=!!n.revealPath;let we;t[16]!==pe||t[17]!==je||t[18]!==Se||t[19]!==oe||t[20]!==se?(we={canRename:oe,canCreateFile:pe,canCreateFolder:je,canDelete:Se,canReveal:se},t[16]=pe,t[17]=je,t[18]=Se,t[19]=oe,t[20]=se,t[21]=we):we=t[21];const Ae=we;let ve;t[22]!==n||t[23]!==e?(ve=zt=>{n.revealPath&&n.revealPath(zt).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=ve):ve=t[24];const ye=ve;let Ie;t[25]===Symbol.for("react.memo_cache_sentinel")?(Ie=(zt,Kt)=>{W(zt),K(Kt),Ne(zt==="rename"&&Kt.name||""),fe(!1)},t[25]=Ie):Ie=t[25];const he=Ie;let me;t[26]!==d||t[27]!==c?(me=(zt,Kt)=>{const te=Kt.filter(vN).filter(bt=>c||!bt.name.startsWith(".")).filter(bt=>d||!iN(bt.name)).map(bt=>{const Ze=bt.name,Wt=_n(bt.path||""),es=Wt?rN(Wt)?Wt:_n(`${zt}/${Wt}`):_n(`${zt}/${Ze}`),rs=bt.isDirectory?"directory":"file",Ue=rs==="file"&&Ze.includes(".")?Ze.split(".").pop()?.toLowerCase():void 0;return{name:Ze,path:es,type:rs,extension:Ue}});return nN(te)},t[26]=d,t[27]=c,t[28]=me):me=t[28];const Ee=me;let Ve;t[29]!==n||t[30]!==Ee||t[31]!==r.isDesktop||t[32]!==d?(Ve=async zt=>{const Kt=_n(zt.trim());if(!Kt||E.current.has(Kt)||C.current.has(Kt))return;C.current=new Set(C.current),C.current.add(Kt);const te=!d;await(r.isDesktop?n.listDirectory(Kt,{respectGitignore:te}).then(jN):en.listLocalDirectory(Kt,{respectGitignore:te}).then(SN)).then(Ze=>{const Wt=Ee(Kt,Ze);E.current=new Set(E.current),E.current.add(Kt),S(es=>({...es,[Kt]:Wt}))}).catch(()=>{S(Ze=>({...Ze,[Kt]:Ze[Kt]??[]}))}).finally(()=>{C.current=new Set(C.current),C.current.delete(Kt)})},t[29]=n,t[30]=Ee,t[31]=r.isDesktop,t[32]=d,t[33]=Ve):Ve=t[33];const Y=Ve;let ke;t[34]!==Y||t[35]!==o?(ke=async()=>{o&&(E.current=new Set,C.current=new Set,S(kN),await Y(o))},t[34]=Y,t[35]=o,t[36]=ke):ke=t[36];const Be=ke;let Ce;t[37]!==Y||t[38]!==Be?(Ce=async zt=>{if(!zt){await Be();return}const Kt=_n(zt);E.current=new Set(E.current),E.current.delete(Kt),C.current=new Set(C.current),C.current.delete(Kt),await Y(Kt)},t[37]=Y,t[38]=Be,t[39]=Ce):Ce=t[39];const ge=Ce;let O;t[40]!==Y||t[41]!==o?(O=()=>{o&&(E.current=new Set,C.current=new Set,S(CN),Y(o))},t[40]=Y,t[41]=o,t[42]=O):O=t[42];let X;t[43]!==Y||t[44]!==o||t[45]!==d||t[46]!==c?(X=[Y,o,c,d],t[43]=Y,t[44]=o,t[45]=d,t[46]=c,t[47]=X):X=t[47],l.useEffect(O,X);let G,Te;t[48]!==B||t[49]!==Y||t[50]!==o?(G=()=>{if(!o||B.length===0)return;const zt=B.map(IN).filter(te=>!!te&&te!==o&&te.startsWith(`${o}/`)&&!E.current.has(te)&&!C.current.has(te)).sort(PN);if(zt.length===0)return;let Kt=!1;return(async()=>{for(let te=0;te<zt.length&&!Kt;te=te+3,te){const bt=zt.slice(te,te+3);await Promise.all(bt.map(Ze=>Y(Ze)))}})(),()=>{Kt=!0}},Te=[B,Y,o],t[48]=B,t[49]=Y,t[50]=o,t[51]=G,t[52]=Te):(G=t[51],Te=t[52]),l.useEffect(G,Te);let le,We;t[53]!==a||t[54]!==h||t[55]!==p||t[56]!==d||t[57]!==c?(le=()=>{if(!a){w([]),k(!1);return}const zt=h.trim();if(!zt){w([]),k(!1);return}let Kt=!1;return k(!0),p(a,zt,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(te=>{if(Kt)return;const Ze=te.filter(Wt=>d||!oN(Wt.path)).map(AN);w(Ze)}).catch(()=>{Kt||w([])}).finally(()=>{Kt||k(!1)}),()=>{Kt=!0}},We=[a,h,p,c,d],t[53]=a,t[54]=h,t[55]=p,t[56]=d,t[57]=c,t[58]=le,t[59]=We):(le=t[58],We=t[59]),l.useEffect(le,We);let de;t[60]!==u||t[61]!==ce||t[62]!==o?(de=zt=>{if(ce.has(zt))return"open";if(u?.files){const Kt=zt.startsWith(o+"/")?zt.slice(o.length+1):zt,te=u.files.find(bt=>bt.path===Kt);if(te){if(te.index==="A"||te.working_dir==="?")return"git-added";if(te.index==="D")return"git-deleted";if(te.index==="M"||te.working_dir==="M")return"git-modified"}}return null},t[60]=u,t[61]=ce,t[62]=o,t[63]=de):de=t[63];const Fe=de;let rt;t[64]!==u||t[65]!==o?(rt=zt=>{if(!u?.files)return null;const Kt=zt.startsWith(o+"/")?zt.slice(o.length+1):zt,te=Kt?`${Kt}/`:"";let bt=0,Ze=0;for(const Wt of u.files)Wt.path.startsWith(te)&&((Wt.index==="M"||Wt.working_dir==="M")&&bt++,(Wt.index==="A"||Wt.working_dir==="?")&&Ze++);return bt+Ze>0?{modified:bt,added:Ze}:null},t[64]=u,t[65]=o,t[66]=rt):rt=t[66];const Oe=rt;let Ye;t[67]!==Q||t[68]!==n||t[69]!==m||t[70]!==o||t[71]!==z?(Ye=async zt=>{if(!o)return;const Kt=await Qd(n,zt.path);if(!Kt.ok){H.error(Xd(Kt.reason));return}z(o,zt.path),Q(o,zt.path),m(o,zt.path)},t[67]=Q,t[68]=n,t[69]=m,t[70]=o,t[71]=z,t[72]=Ye):Ye=t[72];const Ge=Ye;let it;t[73]!==Y||t[74]!==o||t[75]!==J?(it=async zt=>{const Kt=_n(zt);o&&(J(o,Kt),E.current.has(Kt)||await Y(Kt))},t[73]=Y,t[74]=o,t[75]=J,t[76]=it):it=t[76];const Qe=it;let at;t[77]!==U||t[78]!==Z||t[79]!==ie||t[80]!==n||t[81]!==ge||t[82]!==L||t[83]!==o||t[84]!==$||t[85]!==z||t[86]!==e?(at=async zt=>{if(zt?.preventDefault(),!Z||!U)return;fe(!0);const Kt=()=>fe(!1),te=()=>W(null);if(U==="createFile"){if(!ie.trim()){H.error(e("sidebarFilesTree.toast.filenameRequired")),Kt();return}if(!n.writeFile){H.error(e("sidebarFilesTree.toast.writeNotSupported")),Kt();return}const bt=Z.path,Ze=bt?`${bt}/`:"",Wt=_n(`${Ze}${ie.trim()}`);await n.writeFile(Wt,"").then(async es=>{es.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await ge(bt)),te()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Kt);return}if(U==="createFolder"){if(!ie.trim()){H.error(e("sidebarFilesTree.toast.folderNameRequired")),Kt();return}const bt=Z.path,Ze=bt?`${bt}/`:"",Wt=_n(`${Ze}${ie.trim()}`);await n.createDirectory(Wt).then(async es=>{es.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await ge(bt)),te()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Kt);return}if(U==="rename"){if(!ie.trim()){H.error(e("sidebarFilesTree.toast.nameRequired")),Kt();return}if(!n.rename){H.error(e("sidebarFilesTree.toast.renameNotSupported")),Kt();return}const bt=Z.path,Ze=bt.split("/").slice(0,-1).join("/"),Wt=Ze?`${Ze}/`:"",es=_n(`${Wt}${ie.trim()}`);await n.rename(bt,es).then(async rs=>{rs.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await ge(Ze),o&&L(o,bt),($===bt||$&&$.startsWith(`${bt}/`))&&z(o,null)),te()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Kt);return}if(U==="delete"){if(!n.delete){H.error(e("sidebarFilesTree.toast.deleteNotSupported")),Kt();return}const bt=Z.path,Ze=bt.split("/").slice(0,-1).join("/");await n.delete(bt).then(async Wt=>{Wt.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await ge(Ze),o&&L(o,bt),($===bt||$&&$.startsWith(bt+"/"))&&z(o,null)),te()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Kt);return}Kt()},t[77]=U,t[78]=Z,t[79]=ie,t[80]=n,t[81]=ge,t[82]=L,t[83]=o,t[84]=$,t[85]=z,t[86]=e,t[87]=at):at=t[87];const nt=at;let be,He,_e,tt,ut,qe,ze;if(t[88]!==pe||t[89]!==je||t[90]!==j||t[91]!==ae||t[92]!==a||t[93]!==B||t[94]!==Ae||t[95]!==n.downloadFile||t[96]!==Fe||t[97]!==Oe||t[98]!==Ge||t[99]!==ye||t[100]!==Be||t[101]!==o||t[102]!==f||t[103]!==g||t[104]!==y||t[105]!==$||t[106]!==e||t[107]!==Qe){let zt=function(ks,Js){const Ls=j[ks]??[];return Ls.map((ts,js)=>{const yn=ts.type==="directory",cn=yn&&B.includes(ts.path),Rr=$===ts.path,kr=js===Ls.length-1;return s.jsxs("li",{className:"relative",children:[Js>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),kr&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(cN,{node:ts,root:o,isExpanded:cn,isActive:Rr,status:yn?void 0:Fe(ts.path),badge:yn?Oe(ts.path):void 0,permissions:Ae,downloadFile:n.downloadFile,contextMenuPath:ae,setContextMenuPath:R,onSelect:Ge,onToggle:Qe,onRevealPath:ye,onOpenDialog:he}),yn&&cn&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:zt(ts.path,Js+1)})]},ts.path)})};const Kt=!!(o&&j[o]);qe="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let te;t[115]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[115]=te):te=t[115];let bt;t[116]===Symbol.for("react.memo_cache_sentinel")?(bt=ks=>b(ks.target.value),t[116]=bt):bt=t[116];let Ze;t[117]!==e?(Ze=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=Ze):Ze=t[118];let Wt;t[119]!==f||t[120]!==Ze?(Wt=s.jsx(Vt,{ref:v,value:f,onChange:bt,placeholder:Ze,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=f,t[120]=Ze,t[121]=Wt):Wt=t[121];let es;t[122]!==f||t[123]!==e?(es=f.trim().length>0?s.jsx("button",{type:"button","aria-label":e("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{b(""),v.current?.focus()},children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,t[122]=f,t[123]=e,t[124]=es):es=t[124];let rs;t[125]!==Wt||t[126]!==es?(rs=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[te,Wt,es]}),t[125]=Wt,t[126]=es,t[127]=rs):rs=t[127];let Ue;t[128]!==pe||t[129]!==a||t[130]!==e?(Ue=pe&&s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>he("createFile",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"h-4 w-4"})}),t[128]=pe,t[129]=a,t[130]=e,t[131]=Ue):Ue=t[131];let xt;t[132]!==je||t[133]!==a||t[134]!==e?(xt=je&&s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>he("createFolder",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"h-4 w-4"})}),t[132]=je,t[133]=a,t[134]=e,t[135]=xt):xt=t[135];let At;t[136]!==Be?(At=()=>{Be()},t[136]=Be,t[137]=At):At=t[137];let Dt;t[138]!==e?(Dt=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Dt):Dt=t[139];let Zt;t[140]===Symbol.for("react.memo_cache_sentinel")?(Zt=s.jsx(I,{name:"refresh",className:"h-4 w-4"}),t[140]=Zt):Zt=t[140];let Ut;t[141]!==At||t[142]!==Dt?(Ut=s.jsx(xe,{variant:"ghost",size:"sm",onClick:At,className:"h-8 w-8 p-0 flex-shrink-0",title:Dt,children:Zt}),t[141]=At,t[142]=Dt,t[143]=Ut):Ut=t[143],t[144]!==rs||t[145]!==Ue||t[146]!==xt||t[147]!==Ut?(ze=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[rs,Ue,xt,Ut]}),t[144]=rs,t[145]=Ue,t[146]=xt,t[147]=Ut,t[148]=ze):ze=t[148],be=Ns,tt="flex-1 min-h-0",ut="p-2",He="flex flex-col",_e=y?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):g.length>0?g.map(ks=>{const Js=$===ks.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Ge(ks),draggable:!0,onDragStart:Ls=>{const ts=ks.relativePath||qh(o??"",ks.path);!ts||ts==="."||(Ls.dataTransfer.setData("application/x-openchamber-file-path",ts),Ls.dataTransfer.effectAllowed="copy")},className:ue("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",Js?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:ks.path,children:[Yh(ks.path,ks.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:ks.relativePath??ks.path})]})},ks.path)}):Kt&&o?zt(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=pe,t[89]=je,t[90]=j,t[91]=ae,t[92]=a,t[93]=B,t[94]=Ae,t[95]=n.downloadFile,t[96]=Fe,t[97]=Oe,t[98]=Ge,t[99]=ye,t[100]=Be,t[101]=o,t[102]=f,t[103]=g,t[104]=y,t[105]=$,t[106]=e,t[107]=Qe,t[108]=be,t[109]=He,t[110]=_e,t[111]=tt,t[112]=ut,t[113]=qe,t[114]=ze}else be=t[108],He=t[109],_e=t[110],tt=t[111],ut=t[112],qe=t[113],ze=t[114];let st;t[149]!==He||t[150]!==_e?(st=s.jsx("ul",{className:He,children:_e}),t[149]=He,t[150]=_e,t[151]=st):st=t[151];let yt;t[152]!==be||t[153]!==tt||t[154]!==ut||t[155]!==st?(yt=s.jsx(be,{outerClassName:tt,className:ut,children:st}),t[152]=be,t[153]=tt,t[154]=ut,t[155]=st,t[156]=yt):yt=t[156];const Mt=!!U;let Bt;t[157]===Symbol.for("react.memo_cache_sentinel")?(Bt=zt=>!zt&&W(null),t[157]=Bt):Bt=t[157];let ft;t[158]!==U||t[159]!==e?(ft=U==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[158]=U,t[159]=e,t[160]=ft):ft=t[160];let It;t[161]!==U||t[162]!==e?(It=U==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[161]=U,t[162]=e,t[163]=It):It=t[163];let ss;t[164]!==U||t[165]!==e?(ss=U==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[164]=U,t[165]=e,t[166]=ss):ss=t[166];let _t;t[167]!==U||t[168]!==e?(_t=U==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[167]=U,t[168]=e,t[169]=_t):_t=t[169];let qt;t[170]!==ft||t[171]!==It||t[172]!==ss||t[173]!==_t?(qt=s.jsxs(gs,{children:[ft,It,ss,_t]}),t[170]=ft,t[171]=It,t[172]=ss,t[173]=_t,t[174]=qt):qt=t[174];let ct;t[175]!==U||t[176]!==Z?.path||t[177]!==e?(ct=U==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:Z?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[175]=U,t[176]=Z?.path,t[177]=e,t[178]=ct):ct=t[178];let jt;t[179]!==U||t[180]!==Z?.path||t[181]!==e?(jt=U==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:Z?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[179]=U,t[180]=Z?.path,t[181]=e,t[182]=jt):jt=t[182];let as;t[183]!==U||t[184]!==Z?.name||t[185]!==e?(as=U==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:Z?.name??""}),t[183]=U,t[184]=Z?.name,t[185]=e,t[186]=as):as=t[186];let xs;t[187]!==U||t[188]!==Z?.name||t[189]!==e?(xs=U==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:Z?.name??""}),t[187]=U,t[188]=Z?.name,t[189]=e,t[190]=xs):xs=t[190];let ws;t[191]!==ct||t[192]!==jt||t[193]!==as||t[194]!==xs?(ws=s.jsxs(Ps,{children:[ct,jt,as,xs]}),t[191]=ct,t[192]=jt,t[193]=as,t[194]=xs,t[195]=ws):ws=t[195];let As;t[196]!==qt||t[197]!==ws?(As=s.jsxs(vs,{children:[qt,ws]}),t[196]=qt,t[197]=ws,t[198]=As):As=t[198];let Gt;t[199]!==U||t[200]!==ie||t[201]!==nt||t[202]!==e?(Gt=U!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Vt,{value:ie,onChange:zt=>Ne(zt.target.value),placeholder:e(U==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:zt=>{zt.key==="Enter"&&nt()},autoFocus:!0})}),t[199]=U,t[200]=ie,t[201]=nt,t[202]=e,t[203]=Gt):Gt=t[203];let Ke;t[204]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>W(null),t[204]=Ke):Ke=t[204];let Pt;t[205]!==e?(Pt=e("sidebarFilesTree.dialog.cancel"),t[205]=e,t[206]=Pt):Pt=t[206];let Ot;t[207]!==ne||t[208]!==Pt?(Ot=s.jsx(xe,{variant:"outline",onClick:Ke,disabled:ne,children:Pt}),t[207]=ne,t[208]=Pt,t[209]=Ot):Ot=t[209];const Nt=U==="delete"?"destructive":"default";let Ht;t[210]!==nt?(Ht=()=>{nt()},t[210]=nt,t[211]=Ht):Ht=t[211];let ns;t[212]!==U||t[213]!==ie||t[214]!==ne?(ns=ne||U!=="delete"&&!ie.trim(),t[212]=U,t[213]=ie,t[214]=ne,t[215]=ns):ns=t[215];let Ss;t[216]!==U||t[217]!==ne||t[218]!==e?(Ss=ne?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e(U==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[216]=U,t[217]=ne,t[218]=e,t[219]=Ss):Ss=t[219];let fs;t[220]!==Nt||t[221]!==Ht||t[222]!==ns||t[223]!==Ss?(fs=s.jsx(xe,{variant:Nt,onClick:Ht,disabled:ns,children:Ss}),t[220]=Nt,t[221]=Ht,t[222]=ns,t[223]=Ss,t[224]=fs):fs=t[224];let Os;t[225]!==Ot||t[226]!==fs?(Os=s.jsxs(Us,{children:[Ot,fs]}),t[225]=Ot,t[226]=fs,t[227]=Os):Os=t[227];let zs;t[228]!==As||t[229]!==Gt||t[230]!==Os?(zs=s.jsxs(ms,{children:[As,Gt,Os]}),t[228]=As,t[229]=Gt,t[230]=Os,t[231]=zs):zs=t[231];let tn;t[232]!==Mt||t[233]!==zs?(tn=s.jsx(ps,{open:Mt,onOpenChange:Bt,children:zs}),t[232]=Mt,t[233]=zs,t[234]=tn):tn=t[234];let Ds;return t[235]!==qe||t[236]!==ze||t[237]!==yt||t[238]!==tn?(Ds=s.jsxs("section",{className:qe,children:[ze,yt,tn]}),t[235]=qe,t[236]=ze,t[237]=yt,t[238]=tn,t[239]=Ds):Ds=t[239],Ds};function uN(t){return t.searchFiles}function mN(t){return t.openContextFile}function pN(t){return t.setSelectedPath}function fN(t){return t.addOpenPath}function hN(t){return t.removeOpenPathsByPrefix}function gN(t){return t.toggleExpandedPath}function xN(t){return t.mode==="file"?t.targetPath:null}function bN(t){return typeof t=="string"&&t.length>0}function yN(t){return _n(t)}function vN(t){return t&&typeof t.name=="string"&&t.name.length>0}function wN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function jN(t){return t.entries.map(wN)}function NN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function SN(t){return t.map(NN)}function kN(t){return Object.keys(t).length===0?t:{}}function CN(t){return Object.keys(t).length===0?t:{}}function IN(t){return _n(t)}function PN(t,e){return t.split("/").length-e.split("/").length}function AN(t){return{name:t.name,path:_n(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function DN(t,e){const n=ot.c(6),{git:r}=On(),a=Zs(TN);let i,o;n[0]!==t||n[1]!==a||n[2]!==r||n[3]!==e?(i=()=>{if(!t||!r||!e)return;a(t,r);const c=setInterval(()=>{typeof document<"u"&&document.hidden||a(t,r)},1e4);return()=>clearInterval(c)},o=[t,r,e,a],n[0]=t,n[1]=a,n[2]=r,n[3]=e,n[4]=i,n[5]=o):(i=n[4],o=n[5]),l.useEffect(i,o)}function TN(t){return t.ensureStatus}const MN=()=>{const t=ot.c(17),e=Ts(RN),n=Ts(FN),r=_s(ON),a=Zs(LN);let i;e:{if(e){let h;t[0]!==e||t[1]!==n?(h=n.find(v=>v.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=h):h=t[2],i=h;break e}i=n[0]??null}const o=i;let c;e:{if(!o){c=null;break e}let h;t[3]!==o.id||t[4]!==o.path?(h={id:o.id,path:o.path},t[3]=o.id,t[4]=o.path,t[5]=h):h=t[5],c=h}const d=c;let p;e:{if(!o){p=null;break e}let h;t[6]!==o.label||t[7]!==o.path||t[8]!==r?(h=o.label?.trim()||Fa(o.path,r)||o.path,t[6]=o.label,t[7]=o.path,t[8]=r,t[9]=h):h=t[9],p=h}const m=p;let u;e:{if(!o){u=!1;break e}let h;t[10]!==o.path||t[11]!==a?(h=a.get(o.path)?.isGitRepo,t[10]=o.path,t[11]=a,t[12]=h):h=t[12],u=h===!0}const f=u;let b;return t[13]!==f||t[14]!==m||t[15]!==d?(b=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(j1,{projectRef:d,projectLabel:m,canCreateWorktree:f})}),t[13]=f,t[14]=m,t[15]=d,t[16]=b):b=t[16],b},EN=()=>{const t=ot.c(38),{t:e}=pt(),n=De($N),r=De(BN),a=De(_N),i=Lr();DN(i,a);let o;t[0]!==e?(o=e("layout.rightSidebar.git"),t[0]=e,t[1]=o):o=t[1];let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=c):c=t[2];let d;t[3]!==o?(d={id:"git",label:o,icon:c},t[3]=o,t[4]=d):d=t[4];let p;t[5]!==e?(p=e("layout.rightSidebar.files"),t[5]=e,t[6]=p):p=t[6];let m;t[7]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(I,{name:"folder-3",className:"h-3.5 w-3.5"}),t[7]=m):m=t[7];let u;t[8]!==p?(u={id:"files",label:p,icon:m},t[8]=p,t[9]=u):u=t[9];let f;t[10]!==e?(f=e("layout.rightSidebar.context"),t[10]=e,t[11]=f):f=t[11];let b;t[12]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(I,{name:"booklet",className:"h-3.5 w-3.5"}),t[12]=b):b=t[12];let h;t[13]!==f?(h={id:"context",label:f,icon:b},t[13]=f,t[14]=h):h=t[14];let v;t[15]!==d||t[16]!==u||t[17]!==h?(v=[d,u,h],t[15]=d,t[16]=u,t[17]=h,t[18]=v):v=t[18];const x=v;let g;t[19]!==r?(g=D=>r(D),t[19]=r,t[20]=g):g=t[20];let w;t[21]!==n||t[22]!==g||t[23]!==x?(w=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Er,{items:x,activeId:n,onSelect:g,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=g,t[23]=x,t[24]=w):w=t[24];let y;t[25]!==n?(y=n==="git"&&s.jsx(Gh,{}),t[25]=n,t[26]=y):y=t[26];let k;t[27]!==n?(k=n==="files"&&s.jsx(dN,{}),t[27]=n,t[28]=k):k=t[28];let A;t[29]!==n?(A=n==="context"&&s.jsx(MN,{}),t[29]=n,t[30]=A):A=t[30];let j;t[31]!==y||t[32]!==k||t[33]!==A?(j=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[y,k,A]}),t[31]=y,t[32]=k,t[33]=A,t[34]=j):j=t[34];let S;return t[35]!==w||t[36]!==j?(S=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[w,j]}),t[35]=w,t[36]=j,t[37]=S):S=t[37],S};function RN(t){return t.activeProjectId}function FN(t){return t.projects}function ON(t){return t.homeDirectory}function LN(t){return t.directories}function $N(t){return t.rightSidebarTab}function BN(t){return t.setRightSidebarTab}function _N(t){return t.isRightSidebarOpen}const zN=1100,cd=15e3,Fm=500,VN=t=>t<=6?t:t<=12?6:t<=25?4:2,Jh=l.memo(()=>{const t=ot.c(4),{t:e}=pt();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),Qh={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},UN=Qh.M,Yo=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],WN=t=>{const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"},Xh=t=>{const e=WN(t);return Qh[e]??UN},KN=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},HN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),GN=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(HN(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},Om=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Lm=(t,e)=>{const n=t.split(`
|
|
46
|
-
`),r=e.split(`
|
|
47
|
-
`),a=Math.min(n.length,r.length);for(let i=0;i<a;i+=1)if(n[i]!==r[i])return i+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},qN=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},xl=(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]})},YN=l.memo(t=>{const e=ot.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:a,onSelectFile:i,isMobile:o,showModeSelector:c,mode:d,onModeChange:p}=t,m=c===void 0?!1:c,{t:u}=pt();let f;e[0]!==o?(f=S=>{if(!o)return S;const D=S.lastIndexOf("/");return D>=0?S.slice(D+1):S},e[0]=o,e[1]=f):f=e[1];const b=f;if(n.length===0)return null;let h;e[2]!==b||e[3]!==a||e[4]!==u?(h=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(vr,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(a.path)}),xl(a.insertions,a.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:u("diffView.selector.selectFile")}),e[2]=b,e[3]=a,e[4]=u,e[5]=h):h=e[5];let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=v):v=e[6];let x;e[7]!==h?(x=s.jsx(Es,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[h,v]})}),e[7]=h,e[8]=x):x=e[8];let g;e[9]!==d||e[10]!==p||e[11]!==m||e[12]!==u?(g=m&&d&&p?s.jsxs(s.Fragment,{children:[s.jsx(zi,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(il,{value:d,onValueChange:S=>p(S),children:Yo.map(S=>s.jsx(ol,{value:S.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(S.labelKey)})},S.value))}),s.jsx(Cn,{})]}):null,e[9]=d,e[10]=p,e[11]=m,e[12]=u,e[13]=g):g=e[13];const w=r??"";let y;if(e[14]!==n||e[15]!==b){let S;e[17]!==b?(S=D=>s.jsx(ol,{value:D.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(vr,{filePath:D.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(D.path)}),s.jsx("span",{className:"ml-auto",children:xl(D.insertions,D.deletions)})]})},D.path),e[17]=b,e[18]=S):S=e[18],y=n.map(S),e[14]=n,e[15]=b,e[16]=y}else y=e[16];let k;e[19]!==i||e[20]!==w||e[21]!==y?(k=s.jsx(il,{value:w,onValueChange:i,children:y}),e[19]=i,e[20]=w,e[21]=y,e[22]=k):k=e[22];let A;e[23]!==g||e[24]!==k?(A=s.jsxs(Rs,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[g,k]}),e[23]=g,e[24]=k,e[25]=A):A=e[25];let j;return e[26]!==A||e[27]!==x?(j=s.jsxs(Fs,{children:[x,A]}),e[26]=A,e[27]=x,e[28]=j):j=e[28],j}),JN=l.memo(t=>{const e=ot.c(31),{mode:n,onModeChange:r}=t,{t:a}=pt();let i,o,c,d,p,m;if(e[0]!==n||e[1]!==a){const y=Yo.find(k=>k.value===n)??Yo[0];o=Fs,i=Es,m=!0,p="flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",c="min-w-0 truncate typography-meta",d=a(y.labelKey),e[0]=n,e[1]=a,e[2]=i,e[3]=o,e[4]=c,e[5]=d,e[6]=p,e[7]=m}else i=e[2],o=e[3],c=e[4],d=e[5],p=e[6],m=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsx("span",{className:c,children:d}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let f;e[11]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=f):f=e[11];let b;e[12]!==p||e[13]!==u?(b=s.jsxs("button",{className:p,children:[u,f]}),e[12]=p,e[13]=u,e[14]=b):b=e[14];let h;e[15]!==i||e[16]!==m||e[17]!==b?(h=s.jsx(i,{asChild:m,children:b}),e[15]=i,e[16]=m,e[17]=b,e[18]=h):h=e[18];let v;e[19]!==r?(v=y=>r(y),e[19]=r,e[20]=v):v=e[20];let x;e[21]!==a?(x=Yo.map(y=>s.jsx(ol,{value:y.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:a(y.labelKey)})},y.value)),e[21]=a,e[22]=x):x=e[22];let g;e[23]!==n||e[24]!==x||e[25]!==v?(g=s.jsx(Rs,{className:"min-w-[140px]",children:s.jsx(il,{value:n,onValueChange:v,children:x})}),e[23]=n,e[24]=x,e[25]=v,e[26]=g):g=e[26];let w;return e[27]!==o||e[28]!==g||e[29]!==h?(w=s.jsxs(o,{children:[h,g]}),e[27]=o,e[28]=g,e[29]=h,e[30]=w):w=e[30],w}),QN=l.memo(t=>{const e=ot.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=pt();if(n.length===0)return null;let o;if(e[0]!==n||e[1]!==a||e[2]!==r||e[3]!==i){let d;e[5]!==a||e[6]!==r||e[7]!==i?(d=p=>{const m=Xh(p),u=r===p.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(p.path),className:ue("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(vr,{filePath:p.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:m.color},title:i(m.descriptionKey),"aria-label":i(m.descriptionKey),children:m.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:p.path,children:p.path}),xl(p.insertions,p.deletions)]})},p.path)},e[5]=a,e[6]=r,e[7]=i,e[8]=d):d=e[8],o=n.map(d),e[0]=n,e[1]=a,e[2]=r,e[3]=i,e[4]=o}else o=e[4];let c;return e[9]!==o?(c=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:o})}),e[9]=o,e[10]=c):c=e[10],c}),XN=l.memo(t=>{const e=ot.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:o}=pt(),c=r.original.length>0,d=r.modified.length>0;if(!a){let v;return e[0]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=v):v=e[0],v}const p=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"size layout"},e[1]=u):u=e[1];let f;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==i||e[7]!==o?(f=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o("diffView.image.original")}),s.jsx("img",{src:r.original,alt:o("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=c,e[5]=m,e[6]=i,e[7]=o,e[8]=f):f=e[8];let b;e[9]!==r.modified||e[10]!==n||e[11]!==d||e[12]!==c||e[13]!==m||e[14]!==i||e[15]!==o?(b=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:o("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=d,e[12]=c,e[13]=m,e[14]=i,e[15]=o,e[16]=b):b=e[16];let h;return e[17]!==p||e[18]!==f||e[19]!==b?(h=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:u,children:s.jsxs("div",{className:p,children:[f,b]})}),e[17]=p,e[18]=f,e[19]=b,e[20]=h):h=e[20],h}),ZN=l.memo(t=>{const e=ot.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=pt(),o=r.original.length>0,c=r.modified.length>0,d=a?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",p=a?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let u;e[1]!==r.original||e[2]!==n||e[3]!==o||e[4]!==p||e[5]!==a||e[6]!==i?(u=o&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=o,e[4]=p,e[5]=a,e[6]=i,e[7]=u):u=e[7];let f;e[8]!==r.modified||e[9]!==n||e[10]!==c||e[11]!==o||e[12]!==p||e[13]!==a||e[14]!==i?(f=c&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(o?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=c,e[11]=o,e[12]=p,e[13]=a,e[14]=i,e[15]=f):f=e[15];let b;return e[16]!==d||e[17]!==u||e[18]!==f?(b=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,f]})}),e[16]=d,e[17]=u,e[18]=f,e[19]=b):b=e[19],b}),e2=l.memo(t=>{const e=ot.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let o;e[0]!==n?(o=pi(n)||"text",e[0]=n,e[1]=o):o=e[1];const c=o;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Jh,{}),e[2]=m):m=e[2],m}if(fi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(ZN,{filePath:n,diff:r,renderSideBySide:a}),e[3]=r,e[4]=n,e[5]=a,e[6]=m):m=e[6],m}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==c||e[12]!==a||e[13]!==i?(p=s.jsx("div",{className:"w-full",style:d,children:s.jsx(qd,{original:r.original,modified:r.modified,language:c,fileName:n,renderSideBySide:a,wrapLines:i,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=c,e[12]=a,e[13]=i,e[14]=p):p=e[14],p}),t2=l.memo(t=>{const e=ot.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:o}=t;let c;e[0]!==n?(c=pi(n)||"text",e[0]=n,e[1]=c):c=e[1];const d=c;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Jh,{}),e[2]=m):m=e[2],m}if(!a)return null;if(fi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(XN,{filePath:n,diff:r,isVisible:a,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=a,e[6]=i,e[7]=m):m=e[7],m}let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==d||e[12]!==i||e[13]!==o?(p=s.jsx(Ns,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(qd,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:i,wrapLines:o,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=i,e[13]=o,e[14]=p):p=e[14],p}),s2=l.memo(t=>{const e=ot.c(122),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:o,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:f,showOpenInEditorAction:b,isOpeningInEditor:h,onOpenInEditor:v}=t,x=m===void 0?!1:m,g=u===void 0?null:u,w=f===void 0?0:f,y=b===void 0?!1:b,k=h===void 0?!1:h,{t:A}=pt(),{git:j}=On();let S;e[0]!==n||e[1]!==r.path?(S=Ge=>Ge.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=S):S=e[2];const D=Zs(S),E=Zs(r2),P=De(a2),[C,N]=l.useState(!x),[T,M]=l.useState(!1),[F,_]=l.useState(0),[B,V]=l.useState(null),[$,z]=l.useState(!1),[Q,L]=l.useState(!1),J=l.useRef(null),ee=l.useRef(null);let re;e[3]!==r?(re=Xh(r),e[3]=r,e[4]=re):re=e[4];const q=re,ce=a==="side-by-side";let ae;e:{if(!D){ae=null;break e}let Ge;e[5]!==D.isBinary||e[6]!==D.modified||e[7]!==D.original?(Ge={original:D.original,modified:D.modified,isBinary:D.isBinary},e[5]=D.isBinary,e[6]=D.modified,e[7]=D.original,e[8]=Ge):Ge=e[8],ae=Ge}const R=ae;let U;e[9]!==r.path||e[10]!==p?(U=Ge=>{ee.current=Ge,p(r.path,Ge)},e[9]=r.path,e[10]=p,e[11]=U):U=e[11];const W=U;let Z;e[12]===Symbol.for("react.memo_cache_sentinel")?(Z=Ge=>{N(Ge),Ge&&M(!0)},e[12]=Z):Z=e[12];const K=Z;let ie;e[13]!==r.path||e[14]!==d?(ie=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=ie):ie=e[15];const Ne=ie;let ne,fe;e[16]!==T||e[17]!==C||e[18]!==o?(ne=()=>{if(!C||T)return;const Ge=ee.current;if(!Ge)return;if(!o.current||typeof IntersectionObserver>"u"){M(!0);return}const it=new IntersectionObserver(Qe=>{Qe.some(i2)&&(M(!0),it.disconnect())},{root:o.current,rootMargin:"200px 0px",threshold:.1});return it.observe(Ge),()=>it.disconnect()},fe=[T,C,o],e[16]=T,e[17]=C,e[18]=o,e[19]=ne,e[20]=fe):(ne=e[19],fe=e[20]),l.useEffect(ne,fe);let pe,je;e[21]!==w||e[22]!==g||e[23]!==r.path?(pe=()=>{w<=0||g!==r.path||(N(!0),M(!0))},je=[w,g,r.path],e[21]=w,e[22]=g,e[23]=r.path,e[24]=pe,e[25]=je):(pe=e[24],je=e[25]),l.useEffect(pe,je);let oe,Se;e[26]!==R||e[27]!==F||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==T||e[32]!==C||e[33]!==E?(oe=()=>{if(!C||!T)return;if(!n||R){J.current=null,z(!1);return}const Ge=`${n}::${r.path}::${F}`;if(J.current===Ge)return;J.current=Ge,V(null),z(!0);let it=!1;const Qe=j.getGitFileDiff(n,{path:r.path}),at=new Promise(o2);return Promise.race([Qe,at]).then(nt=>{it||(E(n,r.path,{original:nt.original??"",modified:nt.modified??"",isBinary:nt.isBinary}),z(!1))}).catch(nt=>{if(it)return;const be=nt instanceof Error?nt.message:String(nt);V(be),z(!1)}),()=>{it=!0,J.current===Ge&&(J.current=null)}},Se=[n,R,F,r.path,j,T,C,E],e[26]=R,e[27]=F,e[28]=n,e[29]=r.path,e[30]=j,e[31]=T,e[32]=C,e[33]=E,e[34]=oe,e[35]=Se):(oe=e[34],Se=e[35]),l.useEffect(oe,Se);let se;e[36]!==Ne||e[37]!==C?(se=()=>{K(!C),Ne()},e[36]=Ne,e[37]=C,e[38]=se):se=e[38];const we=se,Ae=C?"rounded-b-none":"rounded-b-xl",ve=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let ye;e[39]!==Ae||e[40]!==ve?(ye=ue("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Ae,"text-muted-foreground hover:text-foreground",ve),e[39]=Ae,e[40]=ve,e[41]=ye):ye=e[41];let Ie;e[42]===Symbol.for("react.memo_cache_sentinel")?(Ie=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[42]=Ie):Ie=e[42];let he;e[43]!==C?(he=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:C?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"})}),e[43]=C,e[44]=he):he=e[44];let me;e[45]!==q.color?(me={color:q.color},e[45]=q.color,e[46]=me):me=e[46];let Ee;e[47]!==q.descriptionKey||e[48]!==A?(Ee=A(q.descriptionKey),e[47]=q.descriptionKey,e[48]=A,e[49]=Ee):Ee=e[49];let Ve;e[50]!==q.descriptionKey||e[51]!==A?(Ve=A(q.descriptionKey),e[50]=q.descriptionKey,e[51]=A,e[52]=Ve):Ve=e[52];let Y;e[53]!==q.code||e[54]!==me||e[55]!==Ee||e[56]!==Ve?(Y=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:me,title:Ee,"aria-label":Ve,children:q.code}),e[53]=q.code,e[54]=me,e[55]=Ee,e[56]=Ve,e[57]=Y):Y=e[57];const ke=r.path;let Be;e[58]!==r.path?(Be=s.jsx(vr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=Be):Be=e[59];let Ce;if(e[60]!==r.path){e:{const Ge=r.path.lastIndexOf("/");if(Ge===-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 it=r.path.slice(0,Ge),Qe=r.path.slice(Ge+1);let at;e[63]===Symbol.for("react.memo_cache_sentinel")?(at={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=at):at=e[63];let nt;e[64]!==it?(nt=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:at,children:it}),e[64]=it,e[65]=nt):nt=e[65];let be;e[66]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[66]=be):be=e[66];let He;e[67]!==Qe?(He=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[be,s.jsx("span",{className:"text-foreground",children:Qe})]}),e[67]=Qe,e[68]=He):He=e[68];let _e;e[69]!==nt||e[70]!==He?(_e=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[nt,He]}),e[69]=nt,e[70]=He,e[71]=_e):_e=e[71],Ce=_e}e[60]=r.path,e[61]=Ce}else Ce=e[61];let ge;e[72]!==Be||e[73]!==Ce?(ge=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[Be,Ce]}),e[72]=Be,e[73]=Ce,e[74]=ge):ge=e[74];let O;e[75]!==r.path||e[76]!==ge?(O=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:ke,children:ge}),e[75]=r.path,e[76]=ge,e[77]=O):O=e[77];let X;e[78]!==he||e[79]!==Y||e[80]!==O?(X=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[he,Y,O]}),e[78]=he,e[79]=Y,e[80]=O,e[81]=X):X=e[81];let G;e[82]!==r.deletions||e[83]!==r.insertions?(G=xl(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=G):G=e[84];let Te;e[85]!==R||e[86]!==r.path||e[87]!==k||e[88]!==v||e[89]!==y||e[90]!==A?(Te=y&&v?s.jsx(xe,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:A("diffView.actions.openFileInEditorAtChange"),onClick:Ge=>{Ge.stopPropagation(),v(r.path,R)},disabled:k,children:k?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}):null,e[85]=R,e[86]=r.path,e[87]=k,e[88]=v,e[89]=y,e[90]=A,e[91]=Te):Te=e[91];const le=ce?"side-by-side":"unified";let We;e[92]!==r.path||e[93]!==P?(We=Ge=>{const it=Ge==="side-by-side"?"side-by-side":"inline";P(r.path,it)},e[92]=r.path,e[93]=P,e[94]=We):We=e[94];let de;e[95]!==le||e[96]!==We?(de=s.jsx(Zf,{mode:le,onModeChange:We,className:"opacity-70"}),e[95]=le,e[96]=We,e[97]=de):de=e[97];let Fe;e[98]!==G||e[99]!==Te||e[100]!==de?(Fe=s.jsxs("div",{className:"relative flex items-center gap-2",children:[G,Te,de]}),e[98]=G,e[99]=Te,e[100]=de,e[101]=Fe):Fe=e[101];let rt;e[102]!==we||e[103]!==ye||e[104]!==X||e[105]!==Fe?(rt=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:we,className:ye,children:[Ie,X,Fe]})}),e[102]=we,e[103]=ye,e[104]=X,e[105]=Fe,e[106]=rt):rt=e[106];let Oe;e[107]!==R||e[108]!==B||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==Q||e[113]!==C||e[114]!==$||e[115]!==ce||e[116]!==i?(Oe=C&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[B?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:B}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>_(l2),children:"Retry"})]}):null,$&&!R&&!B?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff…"]}):null,R&&!Q&&r.insertions+r.deletions>Fm?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,R&&(Q||r.insertions+r.deletions<=Fm)?s.jsx(e2,{filePath:r.path,diff:R,renderSideBySide:ce,wrapLines:i}):null]}),e[107]=R,e[108]=B,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=Q,e[113]=C,e[114]=$,e[115]=ce,e[116]=i,e[117]=Oe):Oe=e[117];let Ye;return e[118]!==W||e[119]!==rt||e[120]!==Oe?(Ye=s.jsxs("div",{ref:W,className:"scroll-mt-4",children:[rt,Oe]}),e[118]=W,e[119]=rt,e[120]=Oe,e[121]=Ye):Ye=e[121],Ye}),Zh=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1})=>{const{t:i}=pt(),{git:o,files:c}=On(),d=Lr(),{screenWidth:p,isMobile:m}=nn(),u=Ed(d??null),f=Dl(d??null),b=Fd(d??null),h=Zs(X=>X.setActiveDirectory),v=Zs(X=>X.ensureStatus),x=Zs(X=>X.fetchStatus),g=Zs(X=>X.setDiff),[w,y]=l.useState(null),[k,A]=l.useState(null),[j,S]=l.useState(0),[D,E]=l.useState(null),[P,C]=l.useState(0),[N,T]=l.useState(null),M=l.useRef(null),F=De(X=>X.pendingDiffFile),_=De(X=>X.setPendingDiffFile),B=De(X=>X.diffLayoutPreference),V=De(X=>X.diffFileLayout),$=De(X=>X.setDiffFileLayout),z=De(X=>X.diffWrapLines),Q=De(X=>X.setDiffWrapLines),L=De(X=>X.diffViewMode),J=De(X=>X.setDiffViewMode),ee=De(X=>X.openContextFileAtLine),re=z,q=L==="stacked",ce=m||p<=768,ae=!t&&!ce&&p>=1024,R=l.useRef(null),U=l.useRef(new Map),W=l.useRef(null),Z=l.useRef(null),K=l.useRef(!1);l.useEffect(()=>{if(!r||!q||!D)return;const X=R.current;if(!X)return;let G=null,Te=!1,le=0;const We=Date.now()+1200;let de=0;const Fe=()=>{Te||(Te=!0,E(null))},rt=()=>{Fe()},Oe=()=>{if(de>0){de-=1;return}Fe()};window.addEventListener("wheel",rt,{passive:!0,capture:!0}),window.addEventListener("touchstart",rt,{passive:!0,capture:!0}),window.addEventListener("pointerdown",rt,{capture:!0}),window.addEventListener("keydown",rt,{capture:!0}),X.addEventListener("scroll",Oe,{passive:!0});const Ye=()=>{if(Te||Date.now()>We){Fe();return}const Ge=R.current,it=U.current.get(D);if(!Ge||!it){Fe();return}const Qe=Ge.getBoundingClientRect(),nt=it.getBoundingClientRect().top-Qe.top;if(Math.abs(nt)<=1){if(le+=1,le>=2){Fe();return}}else{le=0;const be=Math.max(0,Ge.scrollHeight-Ge.clientHeight),He=Math.min(be,Math.max(0,Ge.scrollTop+nt));if(Math.abs(He-Ge.scrollTop)<=.5){Fe();return}de+=1,Ge.scrollTop=He}G=window.requestAnimationFrame(Ye)};return G=window.requestAnimationFrame(Ye),()=>{Te=!0,G!==null&&window.cancelAnimationFrame(G),window.removeEventListener("wheel",rt,!0),window.removeEventListener("touchstart",rt,!0),window.removeEventListener("pointerdown",rt,!0),window.removeEventListener("keydown",rt,!0),X.removeEventListener("scroll",Oe)}},[q,r,D]);const ie=l.useMemo(()=>{if(!f?.files)return[];const X=f.diffStats??{};return f.files.map(G=>({...G,insertions:X[G.path]?.insertions??0,deletions:X[G.path]?.deletions??0,isNew:KN(G)})).sort((G,Te)=>G.path.localeCompare(Te.path))},[f]),Ne=l.useMemo(()=>w?ie.find(X=>X.path===w)??null:null,[ie,w]),ne=l.useCallback(X=>{const G=V[X.path];if(G)return G;if(B==="inline")return"inline";if(B==="side-by-side")return"side-by-side";const Te=p<zN;return X.isNew||Te?"inline":"side-by-side"},[V,B,p]),fe=l.useMemo(()=>Ne?ne(Ne):null,[ne,Ne]);l.useEffect(()=>{d&&(h(d),v(d,o))},[d,h,v,o]),l.useEffect(()=>{if(d)return wr.onGitRefreshHint(X=>{Om(X.directory)===Om(d)&&x(d,o)})},[d,x,o]),l.useEffect(()=>{F&&(y(F),_(null),q&&(K.current=!0,W.current=F,A(F),S(X=>X+1)))},[q,F,_]),l.useEffect(()=>{!w&&!F&&ie.length>0&&y(ie[0].path)},[ie,w,F]),l.useEffect(()=>{w&&ie.length>0&&(ie.some(G=>G.path===w)||y(ie[0]?.path??null))},[ie,w]);const pe=l.useCallback((X,G)=>{const Te=U.current;G?Te.set(X,G):Te.delete(X)},[]),je=l.useCallback(X=>{const G=U.current.get(X),Te=R.current;if(!G||!Te)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const le=Te.getBoundingClientRect(),de=G.getBoundingClientRect().top-le.top,Fe=Math.max(0,Te.scrollHeight-Te.clientHeight),rt=Te.scrollTop+de,Oe=Math.min(Fe,Math.max(0,rt)),Ye=Math.abs(Oe-Te.scrollTop)>.5;Te.scrollTop=Oe;const Ge=Math.abs(de)<=1,it=Oe<=.5||Oe>=Fe-.5;return{ok:!0,aligned:Ge,didMove:Ye,atScrollLimit:it,delta:de}},[]);l.useEffect(()=>{if(!q){W.current=null,K.current=!1,Z.current!==null&&(window.cancelAnimationFrame(Z.current),Z.current=null);return}if(!W.current)return;let G=0;const Te=120;let le=!1,We=0,de=!1,Fe=0;const rt=Date.now()+2e3,Oe=()=>{de||(de=!0,window.removeEventListener("wheel",Ge,!0),window.removeEventListener("touchstart",Ge,!0),window.removeEventListener("pointerdown",Ge,!0),window.removeEventListener("keydown",Ge,!0),Qe?.removeEventListener("scroll",it))},Ye=()=>{le||(le=!0,Oe(),W.current=null,K.current=!1,Z.current!==null&&(window.cancelAnimationFrame(Z.current),Z.current=null))},Ge=()=>{Ye()},it=()=>{if(We>0){We-=1;return}Ye()},Qe=R.current;window.addEventListener("wheel",Ge,{passive:!0,capture:!0}),window.addEventListener("touchstart",Ge,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Ge,{capture:!0}),window.addEventListener("keydown",Ge,{capture:!0}),Qe?.addEventListener("scroll",it,{passive:!0});const at=()=>{if(Date.now()>rt){Ye(),Z.current=null;return}if(le){Z.current=null;return}const nt=W.current;if(!nt){Ye(),Z.current=null;return}We+=1;const be=je(nt);if(!be.ok){We=Math.max(0,We-1),G+=1,G<Te?Z.current=window.requestAnimationFrame(at):(Ye(),Z.current=null);return}if(!be.aligned){if(G+=1,be.didMove){if(Fe=0,G<Te){Z.current=window.requestAnimationFrame(at);return}}else if(Fe+=1,Fe<6&&(be.atScrollLimit||Math.abs(be.delta)>1)){Z.current=window.requestAnimationFrame(at);return}}r&&K.current&&E(nt),Ye()};return Z.current=window.requestAnimationFrame(at),()=>{le=!0,Oe(),Z.current!==null&&(window.cancelAnimationFrame(Z.current),Z.current=null)}},[q,r,je,w,j]);const oe=l.useCallback(X=>{y(X)},[]),Se=l.useCallback(X=>{if(Z.current!==null&&(window.cancelAnimationFrame(Z.current),Z.current=null),W.current=null,y(X),!q){K.current=!1;return}K.current=!0,W.current=X,je(X)},[q,je]),se=l.useCallback(X=>{J(X),X==="stacked"&&w&&(je(w).aligned||(W.current=w))},[je,w,J]),we=l.useCallback(X=>{const G=X==="side-by-side"?"side-by-side":"inline";if(q){ie.forEach(Te=>{$(Te.path,G)});return}Ne&&$(Ne.path,G)},[ie,q,Ne,$]),Ae=(fe??"side-by-side")==="side-by-side",ve=!n&&(!q||!ae),ye=Zs(l.useCallback(X=>!d||!w?null:X.directories.get(d)?.diffCache.get(w)??null,[d,w])),Ie=l.useMemo(()=>ye?{original:ye.original,modified:ye.modified,isBinary:ye.isBinary}:null,[ye]),[he,me]=l.useState(null),Ee=l.useCallback(async(X,G)=>{if(!(!d||!X)){me(X);try{let Te=null;if(G&&!G.isBinary&&!fi(X)&&(Te=Lm(G.original,G.modified)),Te===null)try{const rt=await o.getGitDiff(d,{path:X,contextLines:3});Te=qN(rt.diff)}catch{Te=null}let le=G;if(Te===null||!le){const rt=await o.getGitFileDiff(d,{path:X});le={original:rt.original??"",modified:rt.modified??"",isBinary:rt.isBinary},g(d,X,le)}const We=Te??(le.isBinary||fi(X)?1:Lm(le.original,le.modified)),de=GN(d,X),Fe=await Qd(c,de);if(!Fe.ok){H.error(Xd(Fe.reason));return}ee(d,de,We,1)}finally{me(Te=>Te===X?null:Te)}}},[d,c,o,ee,g]),Ve=l.useCallback(async()=>{w&&await Ee(w,Ie)},[Ee,Ie,w]),Y=!!(w&&he===w),ke=!!ye,Be=!q&&!!w&&!ke;l.useEffect(()=>{if(q)return;if(T(null),!d||!w){M.current=null;return}if(ye){M.current=null;return}const X=`${d}::${w}::${P}`;if(M.current===X)return;M.current=X;let G=!1;const Te=o.getGitFileDiff(d,{path:w}),le=cd,We=new Promise((de,Fe)=>{setTimeout(()=>Fe(new Error(`Timed out after ${le}ms`)),le)});return Promise.race([Te,We]).then(de=>{G||g(d,w,{original:de.original??"",modified:de.modified??"",isBinary:de.isBinary})}).catch(de=>{if(G)return;const Fe=de instanceof Error?de.message:String(de);T(Fe)}),()=>{G=!0,M.current===X&&(M.current=null)}},[d,q,w,ye,o,g,P]);const Ce=()=>!d||!w||!Ie?null:s.jsx(t2,{filePath:w,diff:Ie,isVisible:!0,renderSideBySide:Ae,wrapLines:re},w),ge=()=>{if(!d)return null;const X=VN(ie.length);return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[ae&&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:ie.length})]}),s.jsx(QN,{changedFiles:ie,selectedFile:w,onSelectFile:Se})]}),s.jsx(Ns,{ref:R,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:ie.map((G,Te)=>s.jsx(s2,{directory:d,file:G,layout:ne(G),wrapLines:re,scrollRootRef:R,isSelected:G.path===w,onSelect:oe,registerSectionRef:pe,defaultCollapsed:e?!0:Te>=X,expandRequestPath:k,expandRequestNonce:j,showOpenInEditorAction:a,isOpeningInEditor:he===G.path,onOpenInEditor:(le,We)=>{Ee(le,We)}},G.path))})})]})},O=()=>d?b&&!f?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),i("diffView.state.loadingRepositoryStatus")]}):u===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.notGitRepository")}):ie.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.cleanWorkingTree")}):q?ge():s.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden px-3 py-3 relative","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[Ce(),Be&&!ke&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:N?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:i("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:N}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{T(null),C(X=>X+1)},children:i("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),i("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!m&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(I,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:b&&!f?i("diffView.state.loadingChanges"):ie.length===1?i("diffView.summary.changedFilesSingle",{count:ie.length}):i("diffView.summary.changedFilesPlural",{count:ie.length})})]}),!ce&&s.jsx(JN,{mode:L,onModeChange:se}),ve&&s.jsx(YN,{changedFiles:ie,selectedFile:w,selectedFileEntry:Ne,onSelectFile:Se,isMobile:ce,showModeSelector:ce,mode:L,onModeChange:se}),s.jsx("div",{className:"flex-1"}),Ne&&s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>Q(!z),className:ue("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(I,{name:"text-wrap",className:"size-4"})}),a&&Ne&&!q&&s.jsx(xe,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Ve()},disabled:Y,title:i("diffView.actions.openFileAtFirstChangedLine"),children:Y?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}),Ne&&fe&&s.jsx(Zf,{mode:fe==="side-by-side"?"side-by-side":"unified",onModeChange:we})]}),O()]})},n2=()=>{const t=ot.c(6),{git:e}=On(),n=Lr(),r=Zs(c2),a=Zs(d2),i=kb(n??null);let o,c;return t[0]!==n||t[1]!==a||t[2]!==e||t[3]!==r?(o=()=>{n&&(r(n),a(n,e))},c=[n,r,a,e],t[0]=n,t[1]=a,t[2]=e,t[3]=r,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c),i};function r2(t){return t.setDiff}function a2(t){return t.setDiffFileLayout}function i2(t){return t.isIntersecting}function o2(t,e){setTimeout(()=>e(new Error(`Timed out after ${cd}ms`)),cd)}function l2(t){return t+1}function c2(t){return t.setActiveDirectory}function d2(t){return t.ensureStatus}const u2=Object.freeze(Object.defineProperty({__proto__:null,DiffView:Zh,useDiffFileCount:n2},Symbol.toStringTag,{value:"Module"})),m2={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},p2={case:"Match case",re:"Regular expression",word:"Match whole word"};function f2(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(m2)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(p2)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const $m=new wi,Bm=new wi,_m=new wi,zm=new wi,Vm=new wi,Um=new wi,Wm=t=>t,vc=fx,h2=hx,g2=gx;class x2 extends xx{constructor(e,n){super(),this.id=e,this.containerMap=n}toDOM(){let e=this.containerMap.get(this.id);return e||(e=document.createElement("div"),e.className="oc-block-widget",e.dataset.widgetId=this.id,this.containerMap.set(this.id,e)),e}eq(e){return e.id===this.id}destroy(){}}const Km=(t,e)=>!t||t.length===0?[]:px.define({create(n){const r=new Ff,a=[...t].sort((i,o)=>i.afterLine-o.afterLine);for(const i of a){const o=n.doc.lines;if(i.afterLine>o)continue;const c=n.doc.line(i.afterLine);r.add(c.to,c.to,Of.widget({widget:new x2(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>Xn.decorations.from(n)}),Hm=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return mx.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 Ff;for(let i=e;i<=n&&i<=r.state.doc.lines;i+=1){const o=r.state.doc.line(i);a.add(o.from,o.from,Of.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function dd({value:t,onChange:e,extensions:n,className:r,readOnly:a,lineNumbersConfig:i,highlightLines:o,onViewReady:c,onViewDestroy:d,blockWidgets:p,enableSearch:m,searchOpen:u,onSearchOpenChange:f}){const b=l.useRef(null),h=l.useRef(null),v=l.useRef(t),x=l.useRef(e),g=l.useRef(c),w=l.useRef(d),y=l.useRef(f),k=l.useRef(p),A=l.useRef(new Map),[j,S]=l.useState([]),D=l.useCallback(P=>{const C=(P??[]).map(N=>{const T=A.current.get(N.id);return T?{id:N.id,content:N.content,container:T}:null}).filter(N=>N!==null);S(N=>N.length===C.length&&N.every((T,M)=>{const F=C[M];return T.id===F.id&&T.content===F.content&&T.container===F.container})?N:C)},[]),E=l.useCallback(P=>{const C=b.current,N=P??h.current;if(!C||!N)return;const T=N.dom.querySelector(".cm-gutters"),M=T instanceof HTMLElement?T.getBoundingClientRect().width:0;C.style.setProperty("--oc-editor-gutter-width",`${M}px`)},[]);return l.useEffect(()=>{v.current=t},[t]),l.useEffect(()=>{x.current=e},[e]),l.useEffect(()=>{g.current=c,w.current=d},[c,d]),l.useEffect(()=>{y.current=f},[f]),l.useEffect(()=>{k.current=p,D(p)},[p,D]),l.useEffect(()=>{if(!b.current)return;const P=(()=>{if(typeof document>"u")return null;const N=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(N)return N;const T=window.__OPENCHAMBER_CSP_NONCE__;return typeof T=="string"&&T.length>0?T:null})(),C=ax.create({doc:v.current,extensions:[...P?[Xn.cspNonce.of(P)]:[],ix({fixed:!0}),$m.of(cu(i)),ox(),lx.of(" "),Hl.of([cx,...dx,...ux]),Xn.updateListener.of(N=>{E(N.view),(N.viewportChanged||N.geometryChanged)&&D(k.current);const T=du(N.startState),M=du(N.state);if(T!==M&&y.current?.(M),!N.docChanged)return;const F=N.state.doc.toString();v.current=F,x.current(F),D(k.current)}),Bm.of(Xn.editable.of(!a)),_m.of(n??[]),zm.of(Hm(o)),Vm.of(Km(p,A.current)),Um.of(m?[uu({top:!0}),Hl.of(Wm(mu))]:[])]});return h.current=new Xn({state:C,parent:b.current}),vc(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{E(h.current),D(k.current)}),h.current&&g.current?.(h.current),()=>{w.current?.(),h.current?.destroy(),h.current=null,S([])}},[k,E,D]),l.useEffect(()=>{const P=h.current;P&&(P.dispatch({effects:[$m.reconfigure(cu(i)),Bm.reconfigure(Xn.editable.of(!a)),_m.reconfigure(n??[]),zm.reconfigure(Hm(o)),Vm.reconfigure(Km(p,A.current)),Um.reconfigure(m?[uu({top:!0}),Hl.of(Wm(mu))]:[])]}),vc(P,P.state.doc.length,200),P.requestMeasure(),requestAnimationFrame(()=>{E(P),D(k.current)}))},[n,o,i,a,p,m,E,D]),l.useEffect(()=>{const P=h.current;!P||m===!1||(u?(h2(P),requestAnimationFrame(()=>{f2(P.dom)})):g2(P))},[u,m]),l.useEffect(()=>{const P=h.current;if(!P)return;const C=P.state.doc.toString();C!==t&&(P.dispatch({changes:{from:0,to:C.length,insert:t}}),vc(P,P.state.doc.length,300),P.requestMeasure(),requestAnimationFrame(()=>E(P)))},[t,E]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:b,className:ue("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),j.map(P=>_i.createPortal(P.content,P.container,P.id))]})}const b2=(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)},Gm=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},qm=(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:bx.cursor(i),effects:Xn.scrollIntoView(i,{y:"center"})})};function y2({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=pt(),[i,o]=l.useState(""),c=l.useRef(null),d=l.useRef(!1),p=l.useRef(null),m=l.useRef(null),u=l.useMemo(()=>b2(i,n),[i,n]);l.useEffect(()=>{!t||!n||(d.current=!1,c.current=Gm(n,n.state.selection),o(""))},[t,n]),l.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),l.useEffect(()=>{if(!(!t||!n||!c.current)){if(u===null){const{selection:x}=c.current;n.dispatch({selection:x,effects:Xn.scrollIntoView(x.main.from,{y:"center"})});return}qm(n,u,c.current.character)}},[u,t,n]);const f=l.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:x}=c.current;n.dispatch({selection:x,effects:Xn.scrollIntoView(x.main.from,{y:"center"})})},[n]),b=l.useCallback(x=>{x||f(),e(x)},[e,f]),h=l.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,qm(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);l.useEffect(()=>{if(!t)return;const x=w=>{const y=p.current,k=w.target;!y||!(k instanceof Node)||y.contains(k)||b(!1)},g=w=>{w.key==="Escape"&&(w.preventDefault(),b(!1))};return document.addEventListener("pointerdown",x,!0),document.addEventListener("keydown",g,!0),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("keydown",g,!0)}},[b,t,r]);const v=l.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(u===null){const x=c.current??Gm(n,n.state.selection);return a("goToLineDialog.helper.currentLineRange",{current:x.lineNumber,max:n.state.doc.lines})}return a("goToLineDialog.helper.goToLine",{line:u})},[u,a,n]);return r==="inline"?t?s.jsxs("div",{ref:p,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Vt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(xe,{variant:"outline",size:"xs",onClick:h,disabled:!n||u===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:p,className:ue("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(Vt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:v})]})})}const ud=t=>{const e=ot.c(11),{currentMode:n,onToggle:r}=t,a=n==="preview",i=a?"Switch to edit mode":"Switch to preview mode",o=a?"Edit":"Preview";let c;e[0]!==a?(c=a?s.jsx(I,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(I,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=a,e[1]=c):c=e[1];let d;e[2]!==i||e[3]!==r||e[4]!==c?(d=s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"sm",onClick:r,"aria-label":i,className:"h-5 w-5 p-0",children:c})}),e[2]=i,e[3]=r,e[4]=c,e[5]=d):d=e[5];let p;e[6]!==o?(p=s.jsx(Ct,{sideOffset:8,children:o}),e[6]=o,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs(St,{children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},md=yx.define(vx);function v2(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return md;case"json":case"jsonc":case"json5":return Bf().language;case"js":case"javascript":return ei().language;case"jsx":return ei({jsx:!0}).language;case"ts":case"typescript":return ei({typescript:!0}).language;case"tsx":return ei({typescript:!0,jsx:!0}).language;case"html":return Hc().language;case"css":return $f().language;case"py":case"python":return Lf().language;case"heex":case"eex":case"leex":return Hc().language;default:return _f.matchLanguageName(zf,e,!0)}}const eg=t=>t.split("/").pop()?.toLowerCase()??"",w2=t=>{const e=eg(t);return e?_f.matchFilename(zf,e):null},j2=()=>Fi(Gc.define([{tag:[lt.heading1,lt.heading2,lt.heading3,lt.heading4,lt.heading5,lt.heading6],fontWeight:"600"},{tag:lt.strong,fontWeight:"600"},{tag:lt.emphasis,fontStyle:"italic"},{tag:lt.strikethrough,textDecoration:"line-through"},{tag:[lt.link,lt.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:lt.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:lt.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:lt.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:lt.heading,color:"var(--markdown-heading1, currentColor)"}]));function tg(t){const e=t.toLowerCase();switch(eg(e)){case"makefile":case"gnumakefile":return md}const r=e.lastIndexOf("."),a=r>=0?e.slice(r+1):"";switch(a){case"ts":case"tsx":case"mts":case"cts":return ei({typescript:!0,jsx:a==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return ei({typescript:!1,jsx:a==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return Bf();case"css":case"scss":case"sass":case"less":return $f();case"html":case"htm":return Hc();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[wx({codeLanguages:v2}),j2()];case"sh":case"bash":case"zsh":case"fish":case"env":return md;case"py":case"pyw":case"pyi":return Lf();default:return null}}async function N2(t){const e=w2(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function pd(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=Xn.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:a.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:a.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:a.boolean||t.colors.syntax.base.number},".cm-builtin":{color:a.functionCall||t.colors.syntax.base.function},".cm-def":{color:a.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:a.variableOther||a.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:a.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:a.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:a.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:a.tag||t.colors.syntax.base.keyword},".cm-link":{color:a.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),o=Gc.define([{tag:[lt.comment,lt.docComment,lt.meta,lt.documentMeta],class:"cm-comment"},{tag:[lt.keyword,lt.controlKeyword,lt.moduleKeyword,lt.definitionKeyword,lt.modifier],class:"cm-keyword"},{tag:[lt.operatorKeyword,lt.operator,lt.derefOperator,lt.updateOperator,lt.definitionOperator,lt.typeOperator,lt.controlOperator,lt.logicOperator,lt.bitwiseOperator,lt.arithmeticOperator,lt.compareOperator],class:"cm-operator"},{tag:[lt.punctuation,lt.separator,lt.bracket,lt.paren,lt.brace,lt.squareBracket,lt.angleBracket],class:"cm-punctuation"},{tag:[lt.string,lt.regexp,lt.attributeValue,lt.special(lt.string),lt.monospace],class:"cm-string"},{tag:lt.escape,class:"cm-string-2"},{tag:[lt.number,lt.bool,lt.atom,lt.null,lt.self],class:"cm-number"},{tag:[lt.function(lt.variableName),lt.function(lt.definition(lt.variableName)),lt.function(lt.propertyName),lt.standard(lt.variableName),lt.special(lt.variableName)],class:"cm-builtin"},{tag:lt.definition(lt.variableName),class:"cm-def"},{tag:[lt.variableName,lt.local(lt.variableName),lt.constant(lt.variableName),lt.literal],class:"cm-variable"},{tag:lt.propertyName,class:"cm-property"},{tag:lt.attributeName,class:"cm-attribute"},{tag:[lt.className,lt.typeName,lt.namespace],class:"cm-variable-3"},{tag:[lt.tagName,lt.labelName,lt.annotation,lt.macroName],class:"cm-tag"},{tag:lt.link,class:"cm-link"},{tag:[lt.heading,lt.heading1,lt.heading2,lt.heading3,lt.heading4,lt.heading5,lt.heading6],class:"cm-keyword"}]),c=Gc.define([{tag:[lt.comment,lt.docComment,lt.meta,lt.documentMeta],color:t.colors.syntax.base.comment},{tag:[lt.keyword,lt.controlKeyword,lt.moduleKeyword,lt.definitionKeyword,lt.modifier],color:t.colors.syntax.base.keyword},{tag:[lt.operatorKeyword,lt.operator,lt.derefOperator,lt.updateOperator,lt.definitionOperator,lt.typeOperator,lt.controlOperator,lt.logicOperator,lt.bitwiseOperator,lt.arithmeticOperator,lt.compareOperator],color:t.colors.syntax.base.operator},{tag:[lt.string,lt.regexp,lt.attributeValue,lt.special(lt.string),lt.monospace],color:t.colors.syntax.base.string},{tag:lt.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[lt.number,lt.bool,lt.atom,lt.null,lt.self],color:t.colors.syntax.base.number},{tag:[lt.function(lt.variableName),lt.function(lt.definition(lt.variableName)),lt.function(lt.propertyName),lt.standard(lt.variableName),lt.special(lt.variableName)],color:t.colors.syntax.base.function},{tag:lt.definition(lt.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[lt.variableName,lt.local(lt.variableName),lt.constant(lt.variableName),lt.literal],color:t.colors.syntax.base.variable},{tag:lt.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:lt.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[lt.className,lt.typeName,lt.namespace],color:t.colors.syntax.base.type},{tag:[lt.tagName,lt.labelName,lt.annotation,lt.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:lt.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[lt.punctuation,lt.separator,lt.bracket,lt.paren,lt.brace,lt.squareBracket,lt.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,Fi(jx,{fallback:!0}),Fi(Nx),Fi(o),Fi(c)]}const S2=t=>{const e=pn(t);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const r=e.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},k2=t=>{const e=ot.c(8),{label:n,iconDataUrl:r}=t,[a,i]=l.useState(!1);let o;e[0]!==n?(o=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=o):o=e[1];const c=o;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=ue("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let p;return e[6]!==c?(p=s.jsx("span",{className:d,children:c}),e[6]=c,e[7]=p):p=e[7],p},C2=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),pn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},I2=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Ym=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,bl=(t,e)=>{const n=pn(e),r=pn(t);if(!n||!r)return!1;const a=Ym(n),i=Ym(r);return i===a||i.startsWith(`${a}/`)},Jm=(t,e)=>{const n=pn(e),r=pn(t);if(!bl(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),o=[];let c=n;for(let d=0;d<i.length-1;d++)c=c?`${c}/${i[d]}`:i[d],o.push(c);return o},fd=(t,e)=>{if(!e)return"";const n=pn(e);if(!t||!bl(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},P2=new Set(["node_modules"]),A2=t=>{const e=ot.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},D2=t=>P2.has(t),T2=t=>{const e=pn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},M2=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Ai=2e5,sg="openchamber:files:auto-save-enabled",E2=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(sg)!=="false"}catch{return!0}},ng=(t,e)=>s.jsx(vr,{filePath:t,extension:e}),R2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},F2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},wc=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},O2=t=>{const e=ot.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:o,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:f,setContextMenuPath:b,onSelect:h,onToggle:v,onRevealPath:x,onOpenDialog:g}=t,{t:w}=pt(),y=n.type==="directory",{canRename:k,canCreateFile:A,canCreateFolder:j,canDelete:S,canReveal:D}=m;let E;e[0]!==A||e[1]!==j||e[2]!==S||e[3]!==k||e[4]!==D||e[5]!==n.path||e[6]!==b?(E=q=>{!k&&!A&&!j&&!S&&!D||(q?.preventDefault(),b(n.path))},e[0]=A,e[1]=j,e[2]=S,e[3]=k,e[4]=D,e[5]=n.path,e[6]=b,e[7]=E):E=e[7];const P=E;let C;e[8]!==y||e[9]!==n||e[10]!==h||e[11]!==v?(C=()=>{y?v(n.path):h(n)},e[8]=y,e[9]=n,e[10]=h,e[11]=v,e[12]=C):C=e[12];const N=C;let T;e[13]!==n.path||e[14]!==b?(T=q=>{q.stopPropagation(),b(n.path)},e[13]=n.path,e[14]=b,e[15]=T):T=e[15];const M=T,F=o?void 0:P,_=o?void 0:P,B=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[16]!==B?(V=ue("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",B),e[16]=B,e[17]=V):V=e[17];let $;e[18]!==y||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?($=y?a?s.jsx(I,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):ng(n.path,n.extension),e[18]=y,e[19]=a,e[20]=n.extension,e[21]=n.path,e[22]=$):$=e[22];let z;e[23]!==n.name||e[24]!==n.path?(z=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=z):z=e[25];let Q;e[26]!==y||e[27]!==d?(Q=!y&&d&&s.jsx(A2,{status:d}),e[26]=y,e[27]=d,e[28]=Q):Q=e[28];let L;e[29]!==p||e[30]!==y?(L=y&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[29]=p,e[30]=y,e[31]=L):L=e[31];let J;e[32]!==N||e[33]!==Q||e[34]!==L||e[35]!==_||e[36]!==V||e[37]!==$||e[38]!==z?(J=s.jsxs("button",{type:"button",onClick:N,onContextMenu:_,className:V,children:[$,z,Q,L]}),e[32]=N,e[33]=Q,e[34]=L,e[35]=_,e[36]=V,e[37]=$,e[38]=z,e[39]=J):J=e[39];let ee;e[40]!==c||e[41]!==A||e[42]!==j||e[43]!==S||e[44]!==k||e[45]!==D||e[46]!==f||e[47]!==u||e[48]!==M||e[49]!==y||e[50]!==o||e[51]!==n||e[52]!==g||e[53]!==x||e[54]!==r||e[55]!==b||e[56]!==w?(ee=(k||A||j||S||D)&&s.jsx("div",{className:ue("absolute right-1 top-1/2 -translate-y-1/2",c?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(Fs,{open:f===n.path,onOpenChange:q=>b(q?n.path:null),children:[s.jsx(Es,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"icon",className:"size-6",onClick:M,children:s.jsx(I,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(Rs,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:[k&&s.jsxs($t,{onClick:q=>{q.stopPropagation(),g("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.rename")]}),s.jsxs($t,{onClick:q=>{q.stopPropagation(),An(n.path).then(ce=>{if(ce.ok){H.success(w("sidebarFilesTree.toast.pathCopied"));return}H.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.copyPath")]}),s.jsxs($t,{onClick:q=>{q.stopPropagation();const ce=fd(r,n.path)||n.path;An(ce).then(ae=>{if(ae.ok){H.success(w("filesView.toast.relativePathCopied"));return}H.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy-2",className:"mr-2 size-4"})," ",w("filesView.tree.menu.copyRelativePath")]}),!y&&u&&s.jsxs($t,{onClick:q=>{q.stopPropagation(),u(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.save")]}),D&&s.jsxs($t,{onClick:q=>{q.stopPropagation(),x(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 size-4"})," ",w($d())]}),y&&(A||j)&&s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),A&&s.jsxs($t,{onClick:q=>{q.stopPropagation(),g("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs($t,{onClick:q=>{q.stopPropagation(),g("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.newFolder")]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),s.jsxs($t,{onClick:q=>{q.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=A,e[42]=j,e[43]=S,e[44]=k,e[45]=D,e[46]=f,e[47]=u,e[48]=M,e[49]=y,e[50]=o,e[51]=n,e[52]=g,e[53]=x,e[54]=r,e[55]=b,e[56]=w,e[57]=ee):ee=e[57];let re;return e[58]!==J||e[59]!==ee||e[60]!==F?(re=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:F,children:[J,ee]}),e[58]=J,e[59]=ee,e[60]=F,e[61]=re):re=e[61],re},L2=t=>{const e=ot.c(83),{activeDialog:n,dialogData:r,dialogInputValue:a,onDialogInputChange:i,isDialogSubmitting:o,onDialogSubmit:c,onClose:d,inputRef:p}=t,{t:m}=pt(),u=!!n;let f;e[0]!==d?(f=$=>!$&&d(),e[0]=d,e[1]=f):f=e[1];let b;e[2]!==n||e[3]!==m?(b=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=b):b=e[4];let h;e[5]!==n||e[6]!==m?(h=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=h):h=e[7];let v;e[8]!==n||e[9]!==m?(v=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=v):v=e[10];let x;e[11]!==n||e[12]!==m?(x=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=x):x=e[13];let g;e[14]!==b||e[15]!==h||e[16]!==v||e[17]!==x?(g=s.jsxs(gs,{children:[b,h,v,x]}),e[14]=b,e[15]=h,e[16]=v,e[17]=x,e[18]=g):g=e[18];let w;e[19]!==n||e[20]!==r?.path||e[21]!==m?(w=n==="createFile"&&m("filesView.dialog.createFile.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=m,e[22]=w):w=e[22];let y;e[23]!==n||e[24]!==r?.path||e[25]!==m?(y=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=m,e[26]=y):y=e[26];let k;e[27]!==n||e[28]!==r?.name||e[29]!==m?(k=n==="rename"&&m("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=m,e[30]=k):k=e[30];let A;e[31]!==n||e[32]!==r?.name||e[33]!==m?(A=n==="delete"&&m("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=m,e[34]=A):A=e[34];let j;e[35]!==k||e[36]!==A||e[37]!==w||e[38]!==y?(j=s.jsxs(Ps,{children:[w,y,k,A]}),e[35]=k,e[36]=A,e[37]=w,e[38]=y,e[39]=j):j=e[39];let S;e[40]!==j||e[41]!==g?(S=s.jsxs(vs,{children:[g,j]}),e[40]=j,e[41]=g,e[42]=S):S=e[42];let D;e[43]!==n||e[44]!==a||e[45]!==p||e[46]!==i||e[47]!==c||e[48]!==m?(D=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Vt,{value:a,onChange:$=>i($.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:$=>{$.key==="Enter"&&c()},ref:p})}),e[43]=n,e[44]=a,e[45]=p,e[46]=i,e[47]=c,e[48]=m,e[49]=D):D=e[49];let E;e[50]!==m?(E=m("filesView.dialog.cancel"),e[50]=m,e[51]=E):E=e[51];let P;e[52]!==o||e[53]!==d||e[54]!==E?(P=s.jsx(xe,{variant:"outline",onClick:d,disabled:o,children:E}),e[52]=o,e[53]=d,e[54]=E,e[55]=P):P=e[55];const C=n==="delete"?"destructive":"default";let N;e[56]!==c?(N=()=>{c()},e[56]=c,e[57]=N):N=e[57];let T;e[58]!==n||e[59]!==a||e[60]!==o?(T=o||n!=="delete"&&!a.trim(),e[58]=n,e[59]=a,e[60]=o,e[61]=T):T=e[61];let M;e[62]!==n||e[63]!==o||e[64]!==m?(M=o?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=o,e[64]=m,e[65]=M):M=e[65];let F;e[66]!==C||e[67]!==N||e[68]!==T||e[69]!==M?(F=s.jsx(xe,{variant:C,onClick:N,disabled:T,children:M}),e[66]=C,e[67]=N,e[68]=T,e[69]=M,e[70]=F):F=e[70];let _;e[71]!==P||e[72]!==F?(_=s.jsxs(Us,{children:[P,F]}),e[71]=P,e[72]=F,e[73]=_):_=e[73];let B;e[74]!==p||e[75]!==S||e[76]!==D||e[77]!==_?(B=s.jsxs(ms,{initialFocus:p,children:[S,D,_]}),e[74]=p,e[75]=S,e[76]=D,e[77]=_,e[78]=B):B=e[78];let V;return e[79]!==u||e[80]!==f||e[81]!==B?(V=s.jsx(ps,{open:u,onOpenChange:f,children:B}),e[79]=u,e[80]=f,e[81]=B,e[82]=V):V=e[82],V},rg=({mode:t="full"})=>{const{t:e}=pt(),{files:n,runtime:r}=On(),{currentTheme:a,availableThemes:i,lightThemeId:o,darkThemeId:c}=Sr(),{isMobile:d,isTablet:p,screenWidth:m}=nn(),u=d||p,f=Tl(),b=Od(),h=Lr()??"",v=pn(h.trim()),x=d||t!=="editor-only",g=t==="editor-only"&&!d,w=Ld(Pe=>Pe.searchFiles),y=Dl(h),[k,A]=l.useState(""),j=Ml(k,200),S=l.useRef(null),[D,E]=l.useState(!1),[P,C]=l.useState(!0),[N,T]=l.useState(!1),[M,F]=l.useState(!1),[_,B]=l.useState(!1),V=l.useRef(null),$=l.useRef(0),z=l.useCallback(Pe=>{$.current=Math.max(0,$.current+(Pe?1:-1))},[]),Q=l.useCallback(Pe=>Pe instanceof Element?Pe.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);l.useEffect(()=>{if(!_)return;const Pe=Je=>{$.current>0||Q(Je.target)||V.current&&!V.current.contains(Je.target)&&B(!1)};return document.addEventListener("mousedown",Pe),()=>document.removeEventListener("mousedown",Pe)},[Q,_]);const[L,J]=l.useState("edit"),[ee,re]=l.useState("edit"),[q,ce]=l.useState("tree"),[ae,R]=l.useState("edit"),U=l.useRef({}),W=l.useRef({}),Z=l.useRef({}),K=l.useMemo(()=>i.find(Pe=>Pe.metadata.id===o)??ui(!1),[i,o]),ie=l.useMemo(()=>i.find(Pe=>Pe.metadata.id===c)??ui(!0),[i,c]);l.useEffect(()=>{mi(K),mi(ie)},[K,ie]);const Ne=l.useMemo(()=>[],[]),ne=En(Pe=>v?Pe.byRoot[v]?.openPaths??Ne:Ne),fe=En(Pe=>v?Pe.byRoot[v]?.selectedPath??null:null),pe=En(Pe=>v?Pe.byRoot[v]?.expandedPaths??Ne:Ne),je=En(Pe=>Pe.addOpenPath),oe=En(Pe=>Pe.removeOpenPath),Se=En(Pe=>Pe.removeOpenPathsByPrefix),se=En(Pe=>Pe.setSelectedPath),we=En(Pe=>Pe.toggleExpandedPath),Ae=En(Pe=>Pe.expandPaths),ve=l.useCallback(Pe=>{const Je=pn(Pe),mt=Je.split("/"),gt=mt[mt.length-1]||Je,Et=gt.includes(".")?gt.split(".").pop()?.toLowerCase():void 0;return{name:gt,path:Je,type:"file",extension:Et}},[]),ye=l.useMemo(()=>ne.map(ve),[ne,ve]),Ie=l.useMemo(()=>fe??ne[0]??null,[ne,fe]),he=l.useMemo(()=>Ie?ve(Ie):null,[Ie,ve]),me=he?.path??"",Ee=!!(v&&me&&!bl(me,v)),Ve=l.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Ee}),[t,Ee]),Y=l.useRef(null),[ke,Be]=l.useState({left:!1,right:!1}),Ce=l.useCallback(()=>{const Pe=Y.current;Pe&&Be({left:Pe.scrollLeft>2,right:Pe.scrollLeft+Pe.clientWidth<Pe.scrollWidth-2})},[]),ge=l.useRef(Ce);ge.current=Ce,l.useEffect(()=>{const Pe=Y.current;if(!Pe)return;const Je=()=>ge.current();Je(),Pe.addEventListener("scroll",Je,{passive:!0});const mt=new ResizeObserver(Je);return mt.observe(Pe),()=>{Pe.removeEventListener("scroll",Je),mt.disconnect()}},[ye.length]);const[O,X]=l.useState({}),G=l.useRef(new Set),Te=l.useRef(new Set),le=l.useRef(new Map),We=l.useRef(0),[de,Fe]=l.useState([]),[rt,Oe]=l.useState(!1),[Ye,Ge]=l.useState(""),[it,Qe]=l.useState(!1),[at,nt]=l.useState(null),[be,He]=l.useState(""),[_e,tt]=l.useState(null),[ut,qe]=l.useState(""),[ze,st]=l.useState(!1),yt=l.useRef(null),Mt=l.useRef(null),Bt=l.useRef(null),ft=l.useRef(0),[It,ss]=l.useState("idle"),[_t,qt]=l.useState(E2),[ct,jt]=l.useState(!1),as=l.useRef(null),xs=l.useRef(null),ws=l.useRef(null),As=l.useRef(!1),Gt=l.useRef(null),Ke=l.useRef(null),Pt=l.useRef(null),Ot=l.useRef(null),[Nt,Ht]=l.useState(0),ns=l.useRef(null),Ss=l.useRef({key:"",attempts:0});l.useEffect(()=>()=>{ns.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(ns.current),ns.current=null)},[]);const[fs,Os]=l.useState(null),[zs,tn]=l.useState(null),[Ds,zt]=l.useState(""),[Kt,te]=l.useState(!1),[bt,Ze]=l.useState(null),[Wt,es]=l.useState(!1),[rs,Ue]=l.useState(!1),[xt,At]=l.useState(!1),Dt=!!n.writeFile,Zt=!!n.createDirectory,Ut=!!n.rename,ks=!!n.delete,Js=!!n.revealPath,Ls=Dr(Pe=>Pe.availableApps),ts=Dr(Pe=>Pe.isCacheStale),js=Dr(Pe=>Pe.initialize),yn=Dr(Pe=>Pe.loadInstalledApps);l.useEffect(()=>{js()},[js]);const cn=l.useCallback(Pe=>{n.revealPath&&n.revealPath(Pe).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),Rr=l.useCallback(async Pe=>{if(!he?.path||await Cb(he.path,Pe.id,Pe.appName)||await rl(he.path,Pe.appName))return;const gt=S2(he.path)||v;gt&&await rl(gt,Pe.appName)||H.error(e("filesView.toast.openInAppFailed",{app:Pe.appName}))},[v,he?.path,e]),kr=l.useCallback((Pe,Je)=>{Os(Pe),tn(Je),zt(Pe==="rename"&&Je.name||""),te(!1)},[]),[Ws,Ln]=l.useState(null),Vn=l.useRef(!1),er=l.useRef(null),[Cr,Un]=l.useState(!1),In=De(Pe=>Pe.setMainTabGuard),an=De(Pe=>Pe.pendingFileNavigation),vn=De(Pe=>Pe.setPendingFileNavigation),wn=De(Pe=>Pe.pendingFileFocusPath),Le=De(Pe=>Pe.setPendingFileFocusPath),Tt=De(Pe=>Pe.shortcutOverrides),Qt=vt(Pe=>Pe.settingsDefaultFileViewerPreview);l.useEffect(()=>{const Pe=()=>{Vn.current=!1,er.current=null,Un(!1)};return document.addEventListener("mouseup",Pe),()=>document.removeEventListener("mouseup",Pe)},[]),l.useEffect(()=>()=>{Gt.current!==null&&window.clearTimeout(Gt.current),Ke.current!==null&&window.clearTimeout(Ke.current)},[]);const cs=l.useCallback((Pe,Je)=>{const mt=Pe.split(`
|
|
48
|
-
`),gt=Math.max(1,Je.start),Et=Math.min(mt.length,Je.end);return gt>Et?"":mt.slice(gt-1,Et).join(`
|
|
49
|
-
`)},[]),Gs=Gd({source:"file",fileLabel:he?.path??null,language:he?.path&&pi(he.path)||"text",getCodeForRange:Pe=>cs(Ye,hl(Pe)),toStoreRange:Pe=>({startLine:Pe.start,endLine:Pe.end}),fromDraftRange:Pe=>({start:Pe.startLine,end:Pe.endLine})}),{drafts:Ks,commentText:bs,editingDraftId:Hs,setSelection:on,saveComment:rr,cancel:Dn,reset:Wn,startEdit:$r,deleteDraft:Ir}=Gs;l.useEffect(()=>{Ln(null),Wn(),In(null),qe(""),st(!1)},[he?.path,Wn,In]),l.useEffect(()=>{on(Ws)},[Ws,on]),l.useEffect(()=>{if(!Ws&&!Hs)return;const Pe=mt=>{const gt=mt.target;gt.closest('[data-comment-input="true"]')||gt.closest('[data-comment-card="true"]')||gt.closest(".cm-gutterElement")||gt.closest("[data-sonner-toast]")||gt.closest("[data-sonner-toaster]")||(Ln(null),Dn())},Je=setTimeout(()=>{document.addEventListener("click",Pe)},100);return()=>{clearTimeout(Je),document.removeEventListener("click",Pe)}},[Dn,Hs,Ws]);const Pn=l.useCallback((Pe,Je)=>{const mt=Je??Ws??void 0;Je&&Ln(Je),rr(Pe,mt),Ln(null)},[Ws,rr]),Kn=l.useCallback((Pe,Je)=>{const mt=[];for(const gt of Je){if(!(gt&&typeof gt.name=="string"&>.name.length>0)||!f&>.name.startsWith(".")||!b&&D2(gt.name))continue;const Et=gt.name,Jt=pn(gt.path||""),Cs=Jt?I2(Jt)?Jt:pn(`${Pe}/${Jt}`):pn(`${Pe}/${Et}`),qs=gt.isDirectory?"directory":"file",$n=qs==="file"&&Et.includes(".")?Et.split(".").pop()?.toLowerCase():void 0;mt.push({name:Et,path:Cs,type:qs,extension:$n})}return C2(mt)},[b,f]),un=l.useCallback(async Pe=>{const Je=pn(Pe.trim());if(!Je||G.current.has(Je)||Te.current.has(Je))return;Te.current=new Set(Te.current),Te.current.add(Je);const mt=We.current+1;We.current=mt,le.current=new Map(le.current),le.current.set(Je,mt);const gt=()=>le.current.get(Je)===mt,Et=!b;await(r.isDesktop?n.listDirectory(Je,{respectGitignore:Et}).then(Cs=>Cs.entries.map(qs=>({name:qs.name,path:qs.path,isDirectory:qs.isDirectory}))):en.listLocalDirectory(Je,{respectGitignore:Et}).then(Cs=>Cs.map(qs=>({name:qs.name,path:qs.path,isDirectory:qs.isDirectory})))).then(Cs=>{if(!gt())return;const qs=Kn(Je,Cs);G.current=new Set(G.current),G.current.add(Je),X($n=>({...$n,[Je]:qs}))}).catch(()=>{gt()&&X(Cs=>({...Cs,[Je]:Cs[Je]??[]}))}).finally(()=>{gt()&&(le.current=new Map(le.current),le.current.delete(Je),Te.current=new Set(Te.current),Te.current.delete(Je))})},[n,Kn,r.isDesktop,b]),Hn=l.useCallback(async()=>{v&&(G.current=new Set,Te.current=new Set,le.current=new Map,X(Pe=>Object.keys(Pe).length===0?Pe:{}),await un(v))},[un,v]),jn=l.useCallback(async Pe=>{if(!Pe){await Hn();return}const Je=pn(Pe);G.current=new Set(G.current),G.current.delete(Je),Te.current=new Set(Te.current),Te.current.delete(Je),await un(Je)},[un,Hn]),Fr=l.useRef(""),ar=l.useRef("");l.useEffect(()=>{if(!v)return;const Pe=`${v}|h${f?"1":"0"}|g${b?"1":"0"}`,Je=Fr.current!==v,mt=ar.current!==Pe;!Je&&!mt||(Je&&(Fr.current=v,Ge(""),nt(null),He(""),tt(null),E(!1)),mt&&(ar.current=Pe,G.current=new Set,Te.current=new Set,le.current=new Map,X(gt=>Object.keys(gt).length===0?gt:{}),un(v)))},[un,v,b,f]),l.useEffect(()=>{if(!n.listDirectory)return;const Pe=()=>{if(!document.hidden&&pe.length>0)for(const Je of pe)jn(Je)};return document.addEventListener("visibilitychange",Pe),()=>document.removeEventListener("visibilitychange",Pe)},[pe,n.listDirectory,jn]),l.useEffect(()=>{if(!n.listDirectory||pe.length===0)return;const Pe=setInterval(()=>{if(!document.hidden)for(const Je of pe)jn(Je)},8e3);return()=>clearInterval(Pe)},[pe,n.listDirectory,jn]);const gr=l.useCallback(async Pe=>{if(Pe?.preventDefault(),!zs||!fs)return;te(!0);const Je=()=>{Os(null)},mt=Et=>{H.error(Et)},gt=()=>{te(!1)};if(fs==="createFile"){if(!Ds.trim()){mt(e("sidebarFilesTree.toast.filenameRequired")),gt();return}if(!n.writeFile){mt(e("sidebarFilesTree.toast.writeNotSupported")),gt();return}const Et=zs.path,Jt=Et?`${Et}/`:"",Cs=pn(`${Jt}${Ds.trim()}`);await n.writeFile(Cs,"").then(async qs=>{qs.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await jn(Et)),Je()}).catch(()=>mt(e("sidebarFilesTree.toast.operationFailed"))).finally(gt);return}if(fs==="createFolder"){if(!Ds.trim()){mt(e("sidebarFilesTree.toast.folderNameRequired")),gt();return}const Et=zs.path,Jt=Et?`${Et}/`:"",Cs=pn(`${Jt}${Ds.trim()}`);await n.createDirectory(Cs).then(async qs=>{qs.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await jn(Et)),Je()}).catch(()=>mt(e("sidebarFilesTree.toast.operationFailed"))).finally(gt);return}if(fs==="rename"){if(!Ds.trim()){mt(e("sidebarFilesTree.toast.nameRequired")),gt();return}if(!n.rename){mt(e("sidebarFilesTree.toast.renameNotSupported")),gt();return}const Et=zs.path,Jt=Et.split("/").slice(0,-1).join("/"),Cs=Jt?`${Jt}/`:"",qs=pn(`${Cs}${Ds.trim()}`);await n.rename(Et,qs).then(async $n=>{$n.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await jn(Jt),v&&Se(v,Et),(he?.path===Et||he?.path.startsWith(`${Et}/`))&&(v&&se(v,null),Ge(""),nt(null),He(""),tt(null),d&&E(!1))),Je()}).catch(()=>mt(e("sidebarFilesTree.toast.operationFailed"))).finally(gt);return}if(fs==="delete"){if(!n.delete){mt(e("sidebarFilesTree.toast.deleteNotSupported")),gt();return}const Et=zs.path,Jt=Et.split("/").slice(0,-1).join("/");await n.delete(Et).then(async Cs=>{Cs.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await jn(Jt),v&&Se(v,Et),(he?.path===Et||he?.path.startsWith(`${Et}/`))&&(v&&se(v,null),Ge(""),nt(null),He(""),tt(null),d&&E(!1))),Je()}).catch(()=>mt(e("sidebarFilesTree.toast.operationFailed"))).finally(gt);return}gt()},[fs,zs,Ds,n,jn,d,Se,v,he?.path,se,e]);l.useEffect(()=>{if(!h){Fe([]),Oe(!1);return}const Pe=j.trim();if(!Pe){Fe([]),Oe(!1);return}let Je=!1;return Oe(!0),w(h,Pe,150,{includeHidden:f,respectGitignore:!b,type:"file"}).then(mt=>{if(Je)return;const Et=mt.filter(Jt=>b||!T2(Jt.path)).map(Jt=>({name:Jt.name,path:pn(Jt.path),type:"file",extension:Jt.extension,relativePath:Jt.relativePath}));Fe(Et)}).catch(()=>{Je||Fe([])}).finally(()=>{Je||Oe(!1)}),()=>{Je=!0}},[h,j,w,f,b]);const Nn=l.useCallback(async(Pe,Je)=>{if(n.readFile)return(await n.readFile(Pe,Je)).content??"";const mt=new URLSearchParams({path:Pe});Je?.allowOutsideWorkspace&&mt.set("allowOutsideWorkspace","true"),Je?.optional&&mt.set("optional","true");const gt=await fetch(`/api/fs/read?${mt.toString()}`,{cache:Je?.optional?"no-store":"default"});if(!gt.ok){const Et=await gt.json().catch(()=>({error:gt.statusText}));throw new Error(Et.error||e("filesView.error.readFileFailed"))}return gt.text()},[n,e]),Gn=l.useCallback(async(Pe,Je)=>{if(n.statFile){const mt=await n.statFile(Pe,Je);return{path:mt.path,size:mt.size,mtimeMs:mt.mtimeMs}}return null},[n]),tr=l.useMemo(()=>Ye.length>Ai?`${Ye.slice(0,Ai)}
|
|
50
|
-
|
|
51
|
-
… truncated …`:Ye,[Ye]),mn=ut!==tr,ir=l.useCallback(async()=>{if(!he||!n.writeFile)return H.error(e("filesView.toast.savingNotSupported")),!1;if(!mn)return!0;st(!0);try{return(await n.writeFile(he.path,ut))?.success?(Ge(ut),Gn(he.path).then(Je=>{Je&&(Bt.current=Je)}).catch(()=>{}),!0):(H.error(e("filesView.toast.writeFileFailed")),!1)}catch(Pe){return H.error(Pe instanceof Error?Pe.message:e("filesView.toast.saveFailed")),!1}finally{st(!1)}},[ut,n,mn,Gn,he,e]);l.useEffect(()=>{if(!mn){In(null);return}const Pe=Je=>As.current?(As.current=!1,!0):(jt(!0),xs.current=Je,!1);return In(Pe),()=>{De.getState().mainTabGuard===Pe&&In(null)}},[mn,In]),l.useEffect(()=>{try{window.localStorage.setItem(sg,_t?"true":"false")}catch{}},[_t]),l.useEffect(()=>{_t||(ss("idle"),Mt.current&&(clearTimeout(Mt.current),Mt.current=null))},[_t]);const Ni=1500;l.useEffect(()=>{const Pe=!!(he&&n.writeFile);if(!(!_t||!mn||!Pe||ze))return Mt.current=setTimeout(()=>{ir().then(Je=>{Je&&(ss("saved"),setTimeout(()=>ss("idle"),2e3))})},Ni),()=>{Mt.current&&(clearTimeout(Mt.current),Mt.current=null)}},[_t,ut,mn,he,n.writeFile,ze,ir]),l.useEffect(()=>{ss("idle")},[he?.path]),l.useEffect(()=>{const Pe=Je=>{Md(Je)&&(Je.key.toLowerCase()==="s"?(Je.preventDefault(),Mt.current&&(clearTimeout(Mt.current),Mt.current=null),ze||ir().then(mt=>{mt&&(ss("saved"),setTimeout(()=>ss("idle"),2e3))})):Je.key.toLowerCase()==="f"&&(Je.preventDefault(),F(!0)))};return window.addEventListener("keydown",Pe),()=>window.removeEventListener("keydown",Pe)},[ze,ir]);const za=l.useCallback(async Pe=>{const Je=ft.current+1;ft.current=Je;const mt=()=>{if(!v)return!1;const Cs=En.getState().byRoot[v],qs=Cs?.selectedPath??Cs?.openPaths[0]??null;return ft.current===Je&&qs===Pe.path};nt(null),He(""),tt(null);const gt=fi(Pe.path),Et=Pe.path.toLowerCase().endsWith(".svg");if(d&&E(!0),r.isDesktop&>&&!Et){Ge(""),qe(""),Qe(!0);return}if(!r.isDesktop&>&&!Et){Ge(""),qe(""),tt(Pe.path),Qe(!1);return}Qe(!0);const Jt={allowOutsideWorkspace:t==="editor-only"&&!!v&&!bl(Pe.path,v)};await Nn(Pe.path,Jt).then(Cs=>{mt()&&(Ge(Cs),qe(Cs.length>Ai?`${Cs.slice(0,Ai)}
|
|
52
|
-
|
|
53
|
-
… truncated …`:Cs),tt(Pe.path),Gn(Pe.path,Jt).then(qs=>{qs&&mt()&&(Bt.current=qs)}).catch(()=>{}))}).catch(Cs=>{if(mt()){if(M2(Cs)){if(Qe(!1),v&&se(v,null),nt(null),Ge(""),qe(""),tt(null),Bt.current=null,k.trim().length>0&&A(""),d&&E(!1),v){const $n=[...Jm(Pe.path,v),Pe.path];$n.length>0&&Ae(v,$n);for(const yo of $n)G.current.has(yo)||un(yo)}return}Ge(""),qe(""),nt(Cs instanceof Error?Cs.message:e("filesView.error.readFileFailed")),Bt.current=null}}).finally(()=>{mt()&&Qe(!1)})},[Ae,d,un,t,Nn,Gn,v,r.isDesktop,k,se,e]),Jr=l.useCallback(async(Pe,Je)=>{if(!v)return;const mt=Jm(Pe,v),gt=Je?[...mt,Pe]:mt;gt.length>0&&Ae(v,gt);const Et=gt.map(Jt=>{if(!G.current.has(Jt))return un(Jt)}).filter(Boolean);await Promise.all(Et)},[Ae,un,v]),la=l.useCallback((Pe,Je)=>{const mt=Je.findIndex(gt=>gt.path===Pe);return mt===-1||Je.length<=1?null:Je[mt+1]??Je[mt-1]??null},[]),hn=l.useCallback(async Pe=>{if(As.current)As.current=!1;else if(mn){jt(!0),as.current=Pe;return}v&&(se(v,Pe.path),je(v,Pe.path),Jr(Pe.path,!1)),nt(null),He(""),Ge(""),qe(""),tt(null),d&&E(!0)},[je,Jr,mn,d,v,se]);l.useEffect(()=>{he?.path&&Jr(he.path,!1)},[Jr,he?.path]),l.useEffect(()=>{if(!he){ft.current+=1,Qe(!1);return}_e!==he.path&&za(he)},[za,_e,he]);const ca=l.useRef(mn);ca.current=mn,l.useEffect(()=>{if(!he?.path||_e!==he.path)return;let Pe=!1;const Je=window.setInterval(()=>{document.hidden||Gn(he.path,Ve).then(mt=>{if(Pe||!mt)return;const gt=Bt.current;if(!gt||gt.path!==he.path){Bt.current=mt;return}const Et=mt.mtimeMs!==void 0&>.mtimeMs!==void 0&&mt.mtimeMs!==gt.mtimeMs,Jt=mt.size!==gt.size;!Et&&!Jt||ca.current||(Bt.current=mt,tt(null))}).catch(()=>{})},2e3);return()=>{Pe=!0,window.clearInterval(Je)}},[_e,Gn,he?.path,Ve]);const Va=l.useCallback(()=>{const Pe=as.current,Je=xs.current,mt=ws.current;if(as.current=null,xs.current=null,ws.current=null,As.current=!0,jt(!1),qe(tr),mt){v&&oe(v,mt),he?.path===mt&&(Pe?hn(Pe):(v&&se(v,null),Ge(""),nt(null),He(""),tt(null),d&&E(!1)));return}if(Pe){hn(Pe);return}Je&&(In(null),De.getState().setActiveMainTab(Je))},[tr,hn,d,oe,v,he?.path,In,se]),Re=l.useCallback(async()=>{const Pe=as.current,Je=xs.current,mt=ws.current;if(!await ir()){As.current=!1;return}if(as.current=null,xs.current=null,ws.current=null,As.current=!0,jt(!1),mt){v&&oe(v,mt),he?.path===mt&&(Pe?await hn(Pe):(v&&se(v,null),Ge(""),nt(null),He(""),tt(null),d&&E(!1)));return}if(Pe){await hn(Pe);return}Je&&(In(null),De.getState().setActiveMainTab(Je))},[hn,d,oe,v,ir,he?.path,In,se]),Xe=l.useCallback(Pe=>{const Je=he?.path===Pe,mt=la(Pe,ye);if(Je&&mn){jt(!0),as.current=mt,ws.current=Pe;return}if(v&&oe(v,Pe),!!Je){if(mt){hn(mt);return}v&&se(v,null),Ge(""),nt(null),He(""),tt(null),d&&E(!1)}},[la,hn,mn,d,ye,oe,v,he?.path,se]),et=l.useCallback(Pe=>{if(ne.includes(Pe))return"open";if(y?.files){const Je=Pe.startsWith(v+"/")?Pe.slice(v.length+1):Pe,mt=y.files.find(gt=>gt.path===Je);if(mt){if(mt.index==="A"||mt.working_dir==="?")return"git-added";if(mt.index==="D")return"git-deleted";if(mt.index==="M"||mt.working_dir==="M")return"git-modified"}}return null},[ne,y,v]),dt=l.useCallback(Pe=>{if(!y?.files)return null;const Je=Pe.startsWith(v+"/")?Pe.slice(v.length+1):Pe,mt=Je?`${Je}/`:"";let gt=0,Et=0;for(const Jt of y.files)Jt.path.startsWith(mt)&&((Jt.index==="M"||Jt.working_dir==="M")&>++,(Jt.index==="A"||Jt.working_dir==="?")&&Et++);return gt+Et>0?{modified:gt,added:Et}:null},[y,v]),Rt=l.useCallback(async Pe=>{const Je=pn(Pe);v&&(we(v,Je),G.current.has(Je)||await un(Je))},[un,v,we]),Xt=l.useMemo(()=>({canRename:Ut,canCreateFile:Dt,canCreateFolder:Zt,canDelete:ks,canReveal:Js}),[Ut,Dt,Zt,ks,Js]);function $s(Pe,Je){const mt=O[Pe]??[];return mt.map((gt,Et)=>{const Jt=gt.type==="directory",Cs=Jt&&pe.includes(gt.path),qs=he?.path===gt.path,$n=Et===mt.length-1;return s.jsxs("li",{className:"relative",children:[Je>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),$n&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(O2,{node:gt,root:v,isExpanded:Cs,isActive:qs,isMobile:d,alwaysShowActions:u,status:Jt?void 0:et(gt.path),badge:Jt?dt(gt.path):void 0,permissions:Xt,downloadFile:n.downloadFile,contextMenuPath:bt,setContextMenuPath:Ze,onSelect:hn,onToggle:Rt,onRevealPath:cn,onOpenDialog:kr}),Jt&&Cs&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:$s(gt.path,Je+1)})]},gt.path)})}const Bs=!!(he?.path&&fi(he.path)),qn=!!(he?.path&&he.path.toLowerCase().endsWith(".svg")),fo=l.useMemo(()=>pn(an?.path??""),[an?.path]),Qr=!!(an&&fo&&me&&me===fo&&!it&&!at&&!Bs),Br=l.useMemo(()=>fd(v,me),[me,v]),Bl=!!(he&&(!Bs||qn)&&Ye.length>0),_l=!!(he&&Br.length>0),Tn=!!(he&&!Ee&&!Bs&&n.writeFile&&Ye.length<=Ai),Xr=!!(he?.path&&R2(he.path)),Ua=!!(he?.path&&F2(he.path)),Si=!!(he?.path&&wc(he.path)),da=!!(he&&!Bs)&&!Xr&&!(Si&&ae==="preview"),_r=l.useMemo(()=>me?tg(me):null,[me]),[Xs,ua]=l.useState(null);l.useEffect(()=>{let Pe=!1;const Je=he?.path;if(!Je||_r){ua(null);return}return ua(null),N2(Je).then(mt=>{Pe||ua(mt)}),()=>{Pe=!0}},[he?.path,_r]),l.useEffect(()=>{!Tn&&L==="edit"&&J("view")},[Tn,L]);const Wa="openchamber:files:md-viewer-mode",ho="openchamber:files:html-viewer-mode",go="openchamber:files:json-viewer-mode";l.useEffect(()=>{const Pe=he?.path;if(!Pe)return;const Je=Qt?"view":"edit";J(U.current[Pe]??Je);let mt=Qt?"preview":"edit";try{const Jt=localStorage.getItem(Wa);(Jt==="preview"||Jt==="edit")&&(mt=Jt)}catch{}re(W.current[Pe]??mt);let gt=Qt?"preview":"edit";try{const Jt=localStorage.getItem(ho);(Jt==="preview"||Jt==="edit")&&(gt=Jt)}catch{}R(Z.current[Pe]??gt);let Et=Qt?"tree":"text";try{const Jt=localStorage.getItem(go);(Jt==="tree"||Jt==="text")&&(Et=Jt)}catch{}ce(Et)},[he?.path,Qt]);const ma=l.useCallback(Pe=>{const Je=he?.path;Je&&(U.current[Je]=Pe),J(Pe)},[he?.path]),Sn=l.useCallback(Pe=>{const Je=he?.path;Je&&(W.current[Je]=Pe),re(Pe);try{localStorage.setItem(Wa,Pe)}catch{}},[he?.path]),Ka=l.useCallback(()=>ee,[ee]),zl=l.useCallback(Pe=>{ce(Pe);try{localStorage.setItem(go,Pe)}catch{}},[]),Vl=l.useCallback(Pe=>{const Je=he?.path;Je&&(Z.current[Je]=Pe),R(Pe);try{localStorage.setItem(ho,Pe)}catch{}},[he?.path]),xo=l.useCallback(()=>ae,[ae]);l.useEffect(()=>{if(!an||!v)return;const Pe=()=>{typeof window>"u"||ns.current===null&&(ns.current=window.requestAnimationFrame(()=>{ns.current=null,Ht(zr=>zr+1)}))},Je=(zr,fa)=>{if(zr.state.doc.length!==fa.length)return!1;if(fa.length===0)return!0;const Kl=Math.min(128,fa.length);if(zr.state.sliceDoc(0,Kl)!==fa.slice(0,Kl))return!1;const lu=Math.max(0,fa.length-Kl);return zr.state.sliceDoc(lu,fa.length)===fa.slice(lu)},mt=pn(an.path);if(!mt){vn(null),Ss.current={key:"",attempts:0};return}const gt=`${mt}:${an.line}:${an.column??1}`;if(Ss.current.key!==gt&&(Ss.current={key:gt,attempts:0}),he?.path!==mt){if(ct)return;hn(ve(mt));return}if(it||_e!==mt)return;if(at||Bs){vn(null),Ss.current={key:"",attempts:0};return}if(!Tn)return;if(L!=="edit"){J("edit");return}const Et=Pt.current;if(!Et){Pe();return}if(!Je(Et,ut)){Pe();return}const Jt=Math.max(1,Math.min(an.line,Et.state.doc.lines)),Cs=Et.state.doc.line(Jt),qs=Math.max(1,an.column||1),$n=Math.max(0,Cs.to-Cs.from),yo=Math.min($n,qs-1),ki=Cs.from+yo;if(!(Et.state.selection.main.head===ki)||Ss.current.attempts===0){Ss.current.attempts+=1,Et.dispatch({selection:{anchor:ki},effects:Xn.scrollIntoView(ki,{y:"center"})}),Et.focus(),Pe();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const zr=Pt.current;zr&&(zr.dispatch({selection:{anchor:ki},effects:Xn.scrollIntoView(ki,{y:"center"})}),zr.focus())}),vn(null),Ss.current={key:"",attempts:0}},[Tn,ct,ut,Nt,at,it,Bs,_e,hn,an,v,he?.path,vn,L,ve]),l.useEffect(()=>{if(!wn||!v)return;const Pe=pn(wn);if(!Pe){Le(null);return}if(he?.path!==Pe){if(ct)return;hn(ve(Pe));return}if(!(it||_e!==Pe||at||Bs)){if(Tn&&L==="edit"){const Je=Pt.current;if(!Je)return;Je.focus()}Le(null)}},[Tn,ct,at,it,hn,Bs,_e,wn,v,he?.path,Le,L,ve]);const Zr=l.useCallback(Pe=>{if(!d||!Pe||!Pe.hasFocus||typeof window>"u")return;const Je=window.visualViewport;if(!Je)return;const mt=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,mt-(Je.offsetTop+Je.height))<=0)return;const Et=Pe.state.selection.main.head,Jt=Pe.coordsAtPos(Et);if(!Jt)return;const Cs=Math.round(Je.offsetTop+Je.height),$n=Jt.bottom+20-Cs;$n<=0||(Pe.scrollDOM.scrollTop+=$n)},[d]);l.useEffect(()=>{if(!d||typeof window>"u")return;const Pe=()=>{window.requestAnimationFrame(()=>{Zr(Pt.current)})},Je=window.visualViewport;return Je?.addEventListener("resize",Pe),Je?.addEventListener("scroll",Pe,{passive:!0}),document.addEventListener("selectionchange",Pe),()=>{Je?.removeEventListener("resize",Pe),Je?.removeEventListener("scroll",Pe),document.removeEventListener("selectionchange",Pe)}},[d,Zr]),l.useEffect(()=>{if(!Tn||L!=="edit"||d)return;const Pe=Wr("open_go_to_line",Tt),Je=mt=>{const gt=mt.target;if(gt?.closest('[role="dialog"]'))return;const Et=!!gt?.closest(".cm-editor");gt?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!Et||!document.activeElement?.closest(".cm-editor")||Vo(mt,Pe)&&(mt.preventDefault(),At(!0))};return window.addEventListener("keydown",Je),()=>window.removeEventListener("keydown",Je)},[Tn,d,Tt,L]);const pa=l.useMemo(()=>{if(!he?.path)return[pd(a)];const Pe=[pd(a)],Je=_r??Xs;return Je&&Pe.push(Je),P&&Pe.push(Xn.lineWrapping),d&&Pe.push(Xn.updateListener.of(mt=>{mt.view.hasFocus&&(mt.selectionSet||mt.focusChanged||mt.viewportChanged||mt.geometryChanged)&&window.requestAnimationFrame(()=>{Zr(mt.view)})})),Pe},[a,he?.path,_r,Xs,P,d,Zr]),Ha=l.useMemo(()=>({light:K.metadata.id,dark:ie.metadata.id}),[K.metadata.id,ie.metadata.id]),bo=he?.path&&Bs?r.isDesktop?qn?`data:${ju(he.path)};utf8,${encodeURIComponent(Ye)}`:be:qn?`data:${ju(he.path)};utf8,${encodeURIComponent(Ye)}`:`/api/fs/raw?${new URLSearchParams({path:he.path,...Ve.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";l.useEffect(()=>{let Pe=!1;return(async()=>{if(!r.isDesktop||!he?.path||!Bs||qn){He("");return}nt(null),await(n.readFileBinary?n.readFileBinary(he.path,Ve).then(gt=>gt.dataUrl):Promise.resolve(kx(he.path,"asset"))).then(gt=>{Pe||(He(gt),tt(he.path))}).catch(gt=>{Pe||(He(""),nt(gt instanceof Error?gt.message:e("filesView.error.readFileFailed")),tt(null))}).finally(()=>{Pe||Qe(!1)})})(),()=>{Pe=!0}},[n,Bs,qn,r.isDesktop,he?.path,Ve,e]);const Ul=l.useCallback(()=>Os(null),[]),Wl=l.useMemo(()=>Vh({drafts:Ks,editingDraftId:Hs,commentText:bs,selection:Ws,isDragging:Cr,fileLabel:he?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Pe=>({start:Pe.startLine,end:Pe.endLine}),onSave:Pn,onCancel:()=>{Ln(null),Dn()},onEdit:Pe=>{$r(Pe),Ln({start:Pe.startLine,end:Pe.endLine})},onDelete:Ir}),[Dn,bs,Ir,Hs,Ks,Pn,Cr,Ws,he?.path,$r]),Me=l.useCallback((Pe,Je)=>s.jsx("div",{className:"h-full",children:s.jsx(Sx,{file:{name:Pe.name,contents:Je,lang:pi(Pe.path)||void 0},options:{disableFileHeader:!0,overflow:P?"wrap":"scroll",theme:Ha,themeType:a.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[a.metadata.variant,Ha,P]),wt=({exitFullscreenOnly:Pe=!1}={})=>he?s.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",children:[Tn&&L==="edit"&&s.jsxs(s.Fragment,{children:[ze?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):_t&&It==="saved"&&!mn?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(I,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):mn?s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>{ir()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(_t?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ll()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${ll()}+S`}),children:s.jsx(I,{name:"save-3",className:"size-4"})}):null,s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>qt(Je=>!Je),className:ue("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",_t?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(_t?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(_t?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:_t?s.jsx(I,{name:"file-check-fill",className:"size-4"}):s.jsx(I,{name:"file-check",className:"size-4"})})]}),s.jsxs(Fs,{onOpenChange:z,children:[s.jsx(Es,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(I,{name:"file-transfer",className:"size-4"})})}),s.jsxs(Rs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ls.map(Je=>s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{Rr(Je)},children:[s.jsx(k2,{label:Je.label,iconDataUrl:Je.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Je.label})]},Je.id)),ts?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{yn(!0)},children:[s.jsx(I,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Bs&&s.jsxs(s.Fragment,{children:[s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>C(!P),className:ue("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",P?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(P?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})}),L==="edit"&&s.jsxs(s.Fragment,{children:[s.jsx(xe,{variant:"ghost",size:"sm",onClick:Je=>{F(!M),Je.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(I,{name:"search",className:"size-4"})}),s.jsx(xe,{variant:"ghost",size:"sm",onClick:Je=>{At(mt=>!mt),Je.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(I,{name:"menu-fold-2",className:"size-4"})}),s.jsx(y2,{open:xt,onOpenChange:At,view:Pt.current,variant:"inline"})]})]}),da&&Tn&&!Ua&&!Si&&s.jsx(ud,{currentMode:L==="view"?"preview":"edit",onToggle:()=>{ma(L==="view"?"edit":"view")}}),(Xr||wc(he?.path??""))&&s.jsx(ud,{currentMode:Xr?Ka():xo(),onToggle:()=>{wc(he?.path??"")?Vl(xo()==="preview"?"edit":"preview"):Sn(Ka()==="preview"?"edit":"preview")}}),Ua&&s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>zl(q==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(q==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:q==="tree"?s.jsx(I,{name:"code-sslash",className:"size-4"}):s.jsx(I,{name:"node-tree",className:"size-4"})}),Bl&&s.jsx(xe,{variant:"ghost",size:"sm",onClick:async()=>{(await An(Ye)).ok?(es(!0),Gt.current!==null&&window.clearTimeout(Gt.current),Gt.current=window.setTimeout(()=>{es(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Wt?s.jsx(I,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"size-4"})}),_l&&s.jsx(xe,{variant:"ghost",size:"sm",onClick:async()=>{(await An(Br)).ok?(Ue(!0),Ke.current!==null&&window.clearTimeout(Ke.current),Ke.current=window.setTimeout(()=>{Ue(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:Br}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:Br}),children:rs?s.jsx(I,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"file-copy-2",className:"size-4"})}),n.downloadFile&&s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>{const Je=n.downloadFile;Je&&Je(he.path)},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(I,{name:"download",className:"size-4"})}),Pe?s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>T(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(I,{name:"fullscreen-exit",className:"size-4"})}):!d&&t==="full"&&s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>T(!N),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:N?s.jsx(I,{name:"fullscreen-exit",className:"size-4"}):s.jsx(I,{name:"fullscreen",className:"size-4"})})]}):null,ht=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(ps,{open:ct,onOpenChange:Pe=>{Pe||jt(!0)},children:s.jsxs(ms,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:e("filesView.unsaved.title")}),s.jsx(Ps,{children:e("filesView.unsaved.description")})]}),s.jsxs(Us,{children:[s.jsx(xe,{variant:"outline",onClick:()=>{Re()},disabled:ze,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(xe,{variant:"destructive",onClick:Va,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:ue("flex flex-col flex-shrink-0",x&&"border-b border-border/40"),children:x?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[d&&D&&s.jsx("button",{type:"button",onClick:()=>E(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"arrow-left-s",className:"size-5"})}),d?he?s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(vr,{filePath:he.path,extension:he.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:he.name}),s.jsx(I,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Rs,{align:"start",className:"min-w-[16rem]",children:ye.map(Pe=>{const Je=he?.path===Pe.path;return s.jsxs($t,{onSelect:mt=>{if(mt.target.closest("[data-close-open-file]")){mt.preventDefault();return}Je||hn(Pe)},className:ue("flex items-center justify-between gap-2",Je&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 truncate",children:[s.jsx(vr,{filePath:Pe.path,extension:Pe.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Pe.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:mt=>{mt.preventDefault(),mt.stopPropagation()},onClick:mt=>{mt.preventDefault(),mt.stopPropagation(),Xe(Pe.path)},className:"inline-flex size-6 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:Pe.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},Pe.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):ye.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[ke.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),ke.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Y,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:ye.map(Pe=>{const Je=he?.path===Pe.path;return s.jsxs("div",{title:fd(v,Pe.path),className:ue("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",Je?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(vr,{filePath:Pe.path,extension:Pe.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{Je||hn(Pe)},className:"max-w-[12rem] truncate text-left",children:Pe.name}),s.jsx("button",{type:"button",onClick:mt=>{mt.stopPropagation(),Xe(Pe.path)},className:ue("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!Je&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:Pe.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},Pe.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[he&&!M&&s.jsx("div",{ref:V,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>B(!0),onMouseLeave:()=>{$.current>0||B(!1)},children:_?wt():s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>B(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(I,{name:"more-2-fill",className:"size-4"})})}),s.jsx(Ns,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:he?it?g?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):at?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:at}):Bs?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:bo,alt:he?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):he&&Ua&&q==="tree"?s.jsx(Qs,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(wv,{jsonString:Ye,maxHeight:"100%",initiallyExpandedDepth:2})})}):he&&Xr&&Ka()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Ye.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Ye.length/1024)})}),s.jsx(Qs,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Ra,{content:Ye,className:"typography-markdown-body",stripFrontmatter:!0})})]}):he&&Si&&ae==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Pe=he.path.substring(0,he.path.lastIndexOf("/")+1);if(!Pe)return Ye;const Je=`<base href="${r.isDesktop,Pe}">`;return Ye.replace(/<head([^>]*)>/i,`<head$1>${Je}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):he&&da&&L==="view"?Me(he,ut):s.jsxs("div",{className:ue("relative h-full",Qr&&"overflow-hidden"),ref:Ot,children:[s.jsx("div",{className:ue("h-full",Qr&&"invisible"),children:s.jsx(dd,{value:ut,onChange:qe,readOnly:!Tn,extensions:pa,className:"h-full",blockWidgets:Wl,onViewReady:Pe=>{Pt.current=Pe,Ht(Je=>Je+1),window.requestAnimationFrame(()=>{Zr(Pe)})},onViewDestroy:()=>{Pt.current&&(Pt.current=null),Ht(Pe=>Pe+1)},enableSearch:!0,searchOpen:M,onSearchOpenChange:F,highlightLines:Ws?{start:Math.min(Ws.start,Ws.end),end:Math.max(Ws.start,Ws.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Pe,Je,mt)=>{if(!(mt instanceof MouseEvent)||mt.button!==0)return!1;mt.preventDefault();const gt=Pe.state.doc.lineAt(Je.from).number;if(d&&Ws&&!mt.shiftKey){const Et=Math.min(Ws.start,Ws.end,gt),Jt=Math.max(Ws.start,Ws.end,gt);return Ln({start:Et,end:Jt}),Vn.current=!1,er.current=null,Un(!1),!0}if(Vn.current=!0,er.current=gt,Un(!0),Ws&&mt.shiftKey){const Et=Math.min(Ws.start,gt),Jt=Math.max(Ws.end,gt);Ln({start:Et,end:Jt})}else Ln({start:gt,end:gt});return!0},mouseover:(Pe,Je,mt)=>{if(!(mt instanceof MouseEvent)||mt.buttons!==1||!Vn.current||er.current===null)return!1;const gt=Pe.state.doc.lineAt(Je.from).number,Et=Math.min(er.current,gt),Jt=Math.max(er.current,gt);return Ln({start:Et,end:Jt}),Un(!0),!1},mouseup:()=>(Vn.current=!1,er.current=null,Un(!1),!1)}}})}),Qr&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),Yt=!!(v&&O[v]),hs=s.jsxs("section",{className:ue("flex min-h-0 flex-col overflow-hidden",d?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:ue("flex flex-col gap-2 py-2",d?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(Vt,{ref:S,value:k,onChange:Pe=>A(Pe.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),k.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{A(""),S.current?.focus()},children:s.jsx(I,{name:"close",className:"size-4"})})]}),s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>kr("createFile",{path:h,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"size-4"})}),s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>kr("createFolder",{path:h,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"size-4"})}),s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>{Hn()},className:"size-8 p-0 flex-shrink-0",children:s.jsx(I,{name:"refresh",className:"size-4"})})]})}),s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:ue("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:rt?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):de.length>0?de.map(Pe=>{const Je=he?.path===Pe.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{hn(Pe)},className:ue("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",Je?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[ng(Pe.path,Pe.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:Pe.path,children:Pe.relativePath??Pe.path})]})},Pe.path)}):Yt?$s(v,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),sn=t==="full"&&N&&he&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:wt({exitFullscreenOnly:!0})}),s.jsx(Ns,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:it?g?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):at?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:at}):Bs?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:bo,alt:he.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):Xr&&Ka()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Ye.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Ye.length/1024)})}),s.jsx(Qs,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Ra,{content:Ye,className:"typography-markdown-body",stripFrontmatter:!0})})]}):da&&L==="view"?Me(he,ut):s.jsxs("div",{className:ue("relative h-full",Qr&&"overflow-hidden"),children:[s.jsx("div",{className:ue("h-full",Qr&&"invisible"),children:s.jsx(dd,{value:ut,onChange:qe,readOnly:!Tn,extensions:pa,className:"h-full",onViewReady:Pe=>{Pt.current=Pe,window.requestAnimationFrame(()=>{Zr(Pe)})},onViewDestroy:()=>{Pt.current&&(Pt.current=null)}})}),Qr&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(L2,{activeDialog:fs,dialogData:zs,dialogInputValue:Ds,onDialogInputChange:zt,isDialogSubmitting:Kt,onDialogSubmit:gr,onClose:Ul,inputRef:yt}),sn,d?D?ht:hs:t==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:ht})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[m>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:hs}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:ht})]})]})},$2=Object.freeze(Object.defineProperty({__proto__:null,FilesView:rg},Symbol.toStringTag,{value:"Module"})),Tr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},jc=(t,e)=>{const n=Tr(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},B2=(t,e,n)=>jc(jc(jc(t,".opencode"),"plans"),`${e}-${n}.md`),_2=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,z2=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},V2=(t,e)=>{const n=Tr(e.currentDirectory),r=Tr(e.homeDirectory),a=Tr(t);return n&&a.startsWith(n+"/")?a.slice(n.length+1):r&&a===r?"~":r&&a.startsWith(r+"/")?`~${a.slice(r.length)}`:a},U2=(t,e,n)=>{const r=Tr(t.trim());if(!r)return null;const a=n?e.find(o=>o.id===n)??null:null;if(a?.path){const o=Tr(a.path);if(r===o||r.startsWith(`${o}/`))return{id:a.id,path:a.path}}const i=e.filter(o=>{const c=Tr(o.path);return r===c||r.startsWith(`${c}/`)}).sort((o,c)=>Tr(c.path).length-Tr(o.path).length)[0];return i?{id:i.id,path:i.path}:null},ag=({targetPath:t=null})=>{const{t:e}=pt(),n=Lt(ge=>ge.currentSessionId),r=Lt(ge=>ge.createSession),a=Lt(ge=>ge.initializeNewOpenChamberSession),i=Lt(ge=>ge.sendMessage),o=Lt(ge=>ge.setCurrentSession),c=El(),d=_s(ge=>ge.homeDirectory),p=Td(ge=>ge.planModeEnabled),m=Ts(ge=>ge.projects),u=Ts(ge=>ge.activeProjectId),f=Zs(ge=>ge.directories),b=Lr()??"",h=De(ge=>ge.setActiveMainTab),v=De(ge=>ge.setSessionSwitcherOpen),x=On(),{isMobile:g}=nn(),{currentTheme:w}=Sr();l.useMemo(()=>eh(w),[w]);const y=l.useMemo(()=>n?c.find(ge=>ge.id===n)??null:null,[n,c]),k=l.useMemo(()=>{const ge=typeof y?.directory=="string"?y.directory:"";return Tr(ge||"")},[y?.directory]),A=l.useMemo(()=>Tr(b||k),[b,k]),j=l.useMemo(()=>U2(A,m,u),[u,A,m]),S=l.useMemo(()=>j?f.get(j.path)?.isGitRepo===!0:!1,[j,f]),[D,E]=l.useState(null),[P,C]=l.useState(!1),[N,T]=l.useState(null),M=l.useMemo(()=>!N||!k||!d?N:V2(N,{currentDirectory:k,homeDirectory:d}),[N,k,d]),[F,_]=l.useState(""),[B,V]=l.useState(null),$=l.useMemo(()=>M&&M.split("/").pop()||e("planView.file.defaultName"),[M,e]),z=l.useMemo(()=>F.trim()&&Ib(F).title||e("planView.title.default"),[F,e]),Q=l.useMemo(()=>z.trim()||e("planView.title.default"),[z,e]),[L,J]=l.useState(!1),[ee,re]=l.useState(!1),[q,ce]=l.useState("edit"),ae=l.useRef(null),[R,U]=l.useState(null),W=l.useRef(null),Z=l.useRef(null),K="openchamber:plan:md-viewer-mode";l.useEffect(()=>{try{const ge=localStorage.getItem(K);if(!ge)return;const O=JSON.parse(ge);(O==="preview"||O==="edit")&&ce(O)}catch{}},[]);const ie=l.useCallback(ge=>{ce(ge);try{localStorage.setItem(K,JSON.stringify(ge))}catch{}},[]),Ne=l.useRef(!1),ne=l.useRef(null),[fe,pe]=l.useState(!1);l.useEffect(()=>{const ge=()=>{Ne.current=!1,ne.current=null,pe(!1)};return document.addEventListener("mouseup",ge),()=>document.removeEventListener("mouseup",ge)},[]);const je=l.useCallback((ge,O)=>{const X=ge.split(`
|
|
54
|
-
`),G=Math.max(1,O.start),Te=Math.min(X.length,O.end);return G>Te?"":X.slice(G-1,Te).join(`
|
|
55
|
-
`)},[]),oe=Gd({source:"plan",fileLabel:$,language:N&&pi(N)||"markdown",getCodeForRange:ge=>je(F,hl(ge)),toStoreRange:ge=>({startLine:ge.start,endLine:ge.end}),fromDraftRange:ge=>({start:ge.startLine,end:ge.endLine})}),{drafts:Se,commentText:se,editingDraftId:we,setSelection:Ae,saveComment:ve,cancel:ye,reset:Ie,startEdit:he,deleteDraft:me}=oe;l.useEffect(()=>{U(null),Ie()},[F,Ie]),l.useEffect(()=>{Ae(R)},[R,Ae]);const Ee=l.useCallback(()=>{U(null),ye()},[ye]),Ve=l.useCallback((ge,O)=>{O&&U(O),ve(ge,O??R??void 0),U(null)},[R,ve]);l.useEffect(()=>{if(!R)return;const ge=X=>{const G=X.target;G.closest('[data-comment-card="true"]')||G.closest('[data-comment-input="true"]')||G.closest(".oc-block-widget")||G.closest(".cm-gutterElement")||G.closest("[data-sonner-toast]")||G.closest("[data-sonner-toaster]")||(U(null),ye())},O=window.setTimeout(()=>{document.addEventListener("click",ge)},100);return()=>{window.clearTimeout(O),document.removeEventListener("click",ge)}},[ye,we,g,R]);const Y=l.useMemo(()=>{const ge=[pd(w)],O=tg(N||"plan.md");return O&&ge.push(O),ge.push(Xn.lineWrapping),ge},[w,N]);l.useEffect(()=>{if(!p&&!t){T(null),_(""),J(!1);return}let ge=!1;const O=async G=>{if(x.files?.readFile)return(await x.files.readFile(G))?.content??"";const Te=sr()?.files;if(Te?.readFile)return(await Te.readFile(G,{optional:!0}))?.content??"";const le=await fetch(`/api/fs/read?path=${encodeURIComponent(G)}&optional=true`,{cache:"no-store"});if(!le.ok)throw new Error(`Failed to read plan file (${le.status})`);return le.text()};return(async()=>{if(T(null),_(""),V(null),t){J(!0);try{const G=await O(t);if(ge)return;T(t),_(G)}catch{if(ge)return;T(null),_("")}finally{ge||J(!1)}return}if(!y?.slug||!y?.time?.created||!k){T(null),_("");return}J(!0);try{const G=B2(k,y.time.created,y.slug),Te=z2(_2(y.time.created,y.slug),d||null);let le=null,We=null;try{We=await O(G),le=G}catch{}if(!le)try{We=await O(Te),le=Te}catch{}if(ge)return;if(!le||We===null){T(null),_("");return}T(le),_(We)}catch{if(ge)return;T(null),_("")}finally{ge||J(!1)}})(),()=>{ge=!0}},[d,p,x.files,k,y?.slug,y?.time?.created,t]),l.useEffect(()=>{if(!N){V(null);return}const ge=window.setTimeout(async()=>{V(null);try{if(x.files?.writeFile){if(!(await x.files.writeFile(N,F))?.success)throw new Error(e("planView.error.writeFailed"))}else{const O=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:N,content:F})});if(!O.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:O.status}))}}catch(O){V(O instanceof Error?O.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(ge)}},[F,N,x.files,e]),l.useEffect(()=>()=>{ae.current!==null&&window.clearTimeout(ae.current)},[]);const ke=l.useCallback(()=>{h("chat"),v(!1)},[h,v]),Be=l.useCallback(async ge=>{if(!j||!D)return;const O=await bn(D.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:Q}),G=[{synthetic:!0,text:await bn(D.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:Q,plan_path:N??""})}];C(!0);try{ke();let Te=null,le=j.path;if(D.target==="worktree"){if(!S)return;const de=await Jf(j.path,Qf());if(!de?.id)return;Te=de.id,le=null}else{const de=await r(void 0,j.path,null);if(!de?.id)return;Te=de.id,le=de.directory??j.path,a(de.id,vt.getState().agents??[])}if(!Te)return;const We=Pl.getState();We.saveSessionModelSelection(Te,ge.providerID,ge.modelID),ge.agent.trim()&&(We.saveSessionAgentSelection(Te,ge.agent),We.saveAgentModelForSession(Te,ge.agent,ge.providerID,ge.modelID),We.saveAgentModelVariantForSession(Te,ge.agent,ge.providerID,ge.modelID,ge.variant||void 0)),o(Te,le),await i(O,ge.providerID,ge.modelID,ge.agent.trim()||void 0,void 0,void 0,G,ge.variant||void 0),E(null)}finally{C(!1)}},[S,r,j,a,D,N,ke,i,Q,o]),Ce=l.useMemo(()=>Vh({drafts:Se,editingDraftId:we,commentText:se,selection:R,isDragging:fe,fileLabel:$,newWidgetId:"plan-new-comment-input",mapDraftToRange:ge=>({start:ge.startLine,end:ge.endLine}),onSave:Ve,onCancel:Ee,onEdit:ge=>{he(ge),U({start:ge.startLine,end:ge.endLine})},onDelete:me}),[se,me,we,Ee,Ve,fe,R,Se,$,he]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:z}),B?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:B,children:e("planView.error.saveFailed")}):null]}),N?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(Fs,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!F.trim(),children:s.jsx(I,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(Ct,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(Rs,{align:"end",children:[s.jsx($t,{onClick:()=>E({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx($t,{onClick:()=>E({action:"improve",target:"worktree"}),disabled:!S,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(Fs,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx(xe,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!F.trim(),children:s.jsx(I,{name:"code-ai",className:"size-4"})})})}),s.jsx(Ct,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(Rs,{align:"end",children:[s.jsx($t,{onClick:()=>E({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx($t,{onClick:()=>E({action:"implement",target:"worktree"}),disabled:!S,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(ud,{currentMode:q,onToggle:()=>ie(q==="preview"?"edit":"preview")}),s.jsx(xe,{variant:"ghost",size:"sm",onClick:async()=>{(await An(F)).ok&&(re(!0),ae.current!==null&&window.clearTimeout(ae.current),ae.current=window.setTimeout(()=>{re(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:ee?s.jsx(I,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(Mh,{open:D!==null,onOpenChange:ge=>{!ge&&!P&&E(null)},target:D?.target??"session",projectDirectory:j?.path??null,submitting:P,onConfirm:Be}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Ns,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:L?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("planView.state.loading")}):s.jsx("div",{className:"relative h-full",children:s.jsx("div",{className:"h-full",children:q==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(Qs,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("planView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("planView.error.switchToEditMode")})]}),children:s.jsx(Ra,{content:F,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:Z,children:s.jsx(dd,{value:F,onChange:_,readOnly:!1,className:"h-full",extensions:Y,onViewReady:ge=>{W.current=ge},onViewDestroy:()=>{W.current=null},blockWidgets:Ce,highlightLines:R?{start:Math.min(R.start,R.end),end:Math.max(R.start,R.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(ge,O,X)=>{if(!(X instanceof MouseEvent)||X.button!==0)return!1;X.preventDefault();const G=ge.state.doc.lineAt(O.from).number;if(g&&R&&!X.shiftKey){const Te=Math.min(R.start,R.end,G),le=Math.max(R.start,R.end,G);return U({start:Te,end:le}),Ne.current=!1,ne.current=null,pe(!1),!0}if(Ne.current=!0,ne.current=G,pe(!0),R&&X.shiftKey){const Te=Math.min(R.start,G),le=Math.max(R.end,G);U({start:Te,end:le})}else U({start:G,end:G});return!0},mouseover:(ge,O,X)=>{if(!(X instanceof MouseEvent)||X.buttons!==1||!Ne.current||ne.current===null)return!1;const G=ge.state.doc.lineAt(O.from).number,Te=Math.min(ne.current,G),le=Math.max(ne.current,G);return U({start:Te,end:le}),pe(!0),!1},mouseup:()=>(Ne.current=!1,ne.current=null,pe(!1),!1)}}})})})})})})]})},W2=Object.freeze(Object.defineProperty({__proto__:null,PlanView:ag},Symbol.toStringTag,{value:"Module"})),hd={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Jo={user:0,assistant:0,tool:0,other:0},wa=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Qm=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(p=>p.tokens!==void 0)?.tokens;if(typeof n=="number")return{...hd,total:wa(n)};if(!n||typeof n!="object")return hd;const r=n,a=wa(r.input),i=wa(r.output),o=wa(r.reasoning),c=wa(r.cache?.read),d=wa(r.cache?.write);return{input:a,output:i,reasoning:o,cacheRead:c,cacheWrite:d,total:a+i+o+c+d}},K2=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},cr=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+cr(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+cr(n),0):0,H2=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...Jo,assistant:cr(n.text)+cr(n.content)};const a=K2(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:cr(n.input)+cr(n.output)+cr(n.error)+cr(n.call?.input)+cr(n.call?.output)+cr(n.call?.error)+cr(n.raw)+Math.round(cr(n.metadata)*.25)+Math.round(cr(n.state)*.1),other:0}:e==="user"?{user:a.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:a.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:a.length}},Xm=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),G2=t=>{const e=lo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},q2=(t,e)=>{if(t.length===0)return{...Jo};const n=t.reduce((r,a)=>{const i=G2(a);let o={...Jo};for(const c of a.parts)o=Xm(o,H2(c,i));return Xm(r,o)},{...Jo});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},Za=t=>t.toLocaleString(),Y2=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,J2=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),Q2=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),X2=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,Z2=(t,e,n)=>{const r=t.find(i=>i.id===e),a=r?.models?.find(i=>i.id===n);return{providerName:r?.name||e||"-",modelName:a?.name||n||"-",contextLimit:typeof a?.limit?.context=="number"?a.limit.context:null}},eS=()=>{const t=ot.c(199),{t:e}=pt(),{currentTheme:n}=Sr();let r;t[0]!==n?(r=eh(n),t[0]=n,t[1]=r):r=t[1];const a=r;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i={},t[2]=i):i=t[2];const[o,c]=l.useState(i),[d,p]=l.useState(null),m=l.useRef(null),u=Lt(tS),f=El(),b=Pb(u??""),h=vt(sS);let v;t[3]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(nS),p(null)},t[3]=v):v=t[3];let x;t[4]!==u?(x=[u],t[4]=u,t[5]=x):x=t[5],l.useEffect(v,x);let g,w;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},w=[],t[6]=g,t[7]=w):(g=t[6],w=t[7]),l.useEffect(g,w);let y;t[8]===Symbol.for("react.memo_cache_sentinel")?(y=async(ft,It)=>{(await An(It)).ok?(p(ft),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(_t=>_t===ft?null:_t),m.current=null},2e3)):p(null)},t[8]=y):y=t[8];const k=y;let A;t[9]!==u||t[10]!==f?(A=u?f.find(ft=>ft.id===u)??null:null,t[9]=u,t[10]=f,t[11]=A):A=t[11];const j=A;let S,D,E,P,C;if(t[12]!==h||t[13]!==b){S=b.filter(rS);let ft;t[19]!==b?(ft=b.filter(aS),t[19]=b,t[20]=ft):ft=t[20],C=ft;let It=null;for(let _t=S.length-1;_t>=0;_t=_t-1,_t){const qt=S[_t];if(Qm(qt).total>0){It=qt;break}}E=It?Qm(It):hd,P=S.reduce(iS,0);const ss=It?.info??null;D=Z2(h,ss?.providerID||"",ss?.modelID||""),t[12]=h,t[13]=b,t[14]=S,t[15]=D,t[16]=E,t[17]=P,t[18]=C}else S=t[14],D=t[15],E=t[16],P=t[17],C=t[18];const N=D,T=N.contextLimit,M=T&&T>0?Math.min(999,E.total/T*100):0;let F;if(t[21]!==b){const ft=[...b].reverse().find(oS)?.info?.system||"";F=q2(b,ft),t[21]=b,t[22]=F}else F=t[22];const _=F,B=_.user,V=_.assistant,$=_.tool,z=Math.max(0,E.input-B-V-$),Q=B+V+$+z,L=b[0]?.info?.time?.created,J=b.length>0?b[b.length-1]?.info?.time?.created:null;let ee;t[23]!==j?.title||t[24]!==e?(ee=j?.title||e("contextSidebar.session.untitled"),t[23]=j?.title,t[24]=e,t[25]=ee):ee=t[25];const re=j?.time?.created??L??null,q=J??j?.time?.created??null;let ce;t[26]!==V||t[27]!==z||t[28]!==$||t[29]!==B?(ce={user:B,assistant:V,tool:$,other:z},t[26]=V,t[27]=z,t[28]=$,t[29]=B,t[30]=ce):ce=t[30];let ae;t[31]!==S.length||t[32]!==Q||t[33]!==T||t[34]!==N||t[35]!==b.length||t[36]!==ee||t[37]!==re||t[38]!==q||t[39]!==ce||t[40]!==E||t[41]!==P||t[42]!==M||t[43]!==C.length?(ae={sessionTitle:ee,messagesCount:b.length,userMessagesCount:C.length,assistantMessagesCount:S.length,createdAt:re,lastActivityAt:q,providerModel:N,tokenBreakdown:E,usagePercent:M,totalAssistantCost:P,contextLimit:T,breakdown:ce,breakdownTotal:Q},t[31]=S.length,t[32]=Q,t[33]=T,t[34]=N,t[35]=b.length,t[36]=ee,t[37]=re,t[38]=q,t[39]=ce,t[40]=E,t[41]=P,t[42]=M,t[43]=C.length,t[44]=ae):ae=t[44];const R=ae;if(!u){let ft;t[45]!==e?(ft=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=ft):ft=t[46];let It;return t[47]!==ft?(It=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:ft}),t[47]=ft,t[48]=It):It=t[48],It}let U;t[49]!==e?(U=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=U):U=t[50];let W;t[51]!==U||t[52]!==R.breakdown.user?(W={key:"user",label:U,value:R.breakdown.user,color:"var(--status-success)"},t[51]=U,t[52]=R.breakdown.user,t[53]=W):W=t[53];let Z;t[54]!==e?(Z=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=Z):Z=t[55];let K;t[56]!==Z||t[57]!==R.breakdown.assistant?(K={key:"assistant",label:Z,value:R.breakdown.assistant,color:"var(--primary-base)"},t[56]=Z,t[57]=R.breakdown.assistant,t[58]=K):K=t[58];let ie;t[59]!==e?(ie=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=ie):ie=t[60];let Ne;t[61]!==ie||t[62]!==R.breakdown.tool?(Ne={key:"tool",label:ie,value:R.breakdown.tool,color:"var(--status-warning)"},t[61]=ie,t[62]=R.breakdown.tool,t[63]=Ne):Ne=t[63];let ne;t[64]!==e?(ne=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=ne):ne=t[65];let fe;t[66]!==ne||t[67]!==R.breakdown.other?(fe={key:"other",label:ne,value:R.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=ne,t[67]=R.breakdown.other,t[68]=fe):fe=t[68];let pe;t[69]!==W||t[70]!==K||t[71]!==Ne||t[72]!==fe?(pe=[W,K,Ne,fe],t[69]=W,t[70]=K,t[71]=Ne,t[72]=fe,t[73]=pe):pe=t[73];const je=pe;let oe;t[74]!==R.sessionTitle?(oe=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:R.sessionTitle}),t[74]=R.sessionTitle,t[75]=oe):oe=t[75];let Se;t[76]!==R.providerModel.modelName||t[77]!==R.providerModel.providerName?(Se=s.jsxs("span",{children:[R.providerModel.providerName," / ",R.providerModel.modelName]}),t[76]=R.providerModel.modelName,t[77]=R.providerModel.providerName,t[78]=Se):Se=t[78];let se;t[79]!==R.createdAt?(se=R.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:J2(R.createdAt)})]}),t[79]=R.createdAt,t[80]=se):se=t[80];let we;t[81]!==Se||t[82]!==se?(we=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[Se,se]}),t[81]=Se,t[82]=se,t[83]=we):we=t[83];let Ae;t[84]!==oe||t[85]!==we?(Ae=s.jsxs("div",{className:"mb-6",children:[oe,we]}),t[84]=oe,t[85]=we,t[86]=Ae):Ae=t[86];let ve;t[87]!==e?(ve=e("contextSidebar.section.context"),t[87]=e,t[88]=ve):ve=t[88];let ye;t[89]!==ve?(ye=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ve}),t[89]=ve,t[90]=ye):ye=t[90];let Ie;t[91]!==R.tokenBreakdown.total?(Ie=Za(R.tokenBreakdown.total),t[91]=R.tokenBreakdown.total,t[92]=Ie):Ie=t[92];let he;t[93]!==R.contextLimit?(he=R.contextLimit?` / ${Za(R.contextLimit)}`:"",t[93]=R.contextLimit,t[94]=he):he=t[94];let me;t[95]!==Ie||t[96]!==he?(me=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[Ie,he]}),t[95]=Ie,t[96]=he,t[97]=me):me=t[97];let Ee;t[98]!==ye||t[99]!==me?(Ee=s.jsxs("div",{className:"flex items-baseline justify-between",children:[ye,me]}),t[98]=ye,t[99]=me,t[100]=Ee):Ee=t[100];let Ve;t[101]!==R.usagePercent?(Ve=R.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,R.usagePercent)}%`,backgroundColor:R.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=R.usagePercent,t[102]=Ve):Ve=t[102];let Y;t[103]!==Ve?(Y=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Ve}),t[103]=Ve,t[104]=Y):Y=t[104];let ke;t[105]!==e||t[106]!==R.usagePercent?(ke=e("contextSidebar.context.percentUsed",{percent:R.usagePercent.toFixed(1)}),t[105]=e,t[106]=R.usagePercent,t[107]=ke):ke=t[107];let Be;t[108]!==ke?(Be=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:ke}),t[108]=ke,t[109]=Be):Be=t[109];let Ce;t[110]!==Ee||t[111]!==Y||t[112]!==Be?(Ce=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Ee,Y,Be]}),t[110]=Ee,t[111]=Y,t[112]=Be,t[113]=Ce):Ce=t[113];let ge;t[114]!==e?(ge=e("contextSidebar.stats.messages"),t[114]=e,t[115]=ge):ge=t[115];let O;t[116]!==R.messagesCount?(O=Za(R.messagesCount),t[116]=R.messagesCount,t[117]=O):O=t[117];let X;t[118]!==ge||t[119]!==O?(X={label:ge,value:O},t[118]=ge,t[119]=O,t[120]=X):X=t[120];let G;t[121]!==e?(G=e("contextSidebar.stats.user"),t[121]=e,t[122]=G):G=t[122];let Te;t[123]!==R.userMessagesCount?(Te=Za(R.userMessagesCount),t[123]=R.userMessagesCount,t[124]=Te):Te=t[124];let le;t[125]!==G||t[126]!==Te?(le={label:G,value:Te},t[125]=G,t[126]=Te,t[127]=le):le=t[127];let We;t[128]!==e?(We=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=We):We=t[129];let de;t[130]!==R.assistantMessagesCount?(de=Za(R.assistantMessagesCount),t[130]=R.assistantMessagesCount,t[131]=de):de=t[131];let Fe;t[132]!==We||t[133]!==de?(Fe={label:We,value:de},t[132]=We,t[133]=de,t[134]=Fe):Fe=t[134];let rt;t[135]!==e?(rt=e("contextSidebar.stats.cost"),t[135]=e,t[136]=rt):rt=t[136];let Oe;t[137]!==R.totalAssistantCost?(Oe=Y2(R.totalAssistantCost),t[137]=R.totalAssistantCost,t[138]=Oe):Oe=t[138];let Ye;t[139]!==rt||t[140]!==Oe?(Ye={label:rt,value:Oe},t[139]=rt,t[140]=Oe,t[141]=Ye):Ye=t[141];let Ge;t[142]!==X||t[143]!==le||t[144]!==Fe||t[145]!==Ye?(Ge=[X,le,Fe,Ye],t[142]=X,t[143]=le,t[144]=Fe,t[145]=Ye,t[146]=Ge):Ge=t[146];const it=Ge;let Qe;t[147]!==it?(Qe=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:it.map(lS)}),t[147]=it,t[148]=Qe):Qe=t[148];let at;t[149]!==e?(at=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=at):at=t[150];let nt;t[151]!==at?(nt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:at}),t[151]=at,t[152]=nt):nt=t[152];let be;t[153]!==e||t[154]!==R.tokenBreakdown.cacheRead||t[155]!==R.tokenBreakdown.cacheWrite||t[156]!==R.tokenBreakdown.input||t[157]!==R.tokenBreakdown.output||t[158]!==R.tokenBreakdown.reasoning?(be=s.jsx("div",{className:"mt-2.5 grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:R.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:R.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:R.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:R.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:R.tokenBreakdown.cacheWrite}].map(cS)}),t[153]=e,t[154]=R.tokenBreakdown.cacheRead,t[155]=R.tokenBreakdown.cacheWrite,t[156]=R.tokenBreakdown.input,t[157]=R.tokenBreakdown.output,t[158]=R.tokenBreakdown.reasoning,t[159]=be):be=t[159];let He;t[160]!==nt||t[161]!==be?(He=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[nt,be]}),t[160]=nt,t[161]=be,t[162]=He):He=t[162];let _e;t[163]!==je||t[164]!==R.breakdownTotal?(_e=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:je.map(ft=>ft.value<=0||R.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${ft.value/R.breakdownTotal*100}%`,backgroundColor:ft.color}},ft.key))}),t[163]=je,t[164]=R.breakdownTotal,t[165]=_e):_e=t[165];let tt;t[166]!==je||t[167]!==R.breakdownTotal?(tt=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:je.map(ft=>{const It=R.breakdownTotal>0?ft.value/R.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:ft.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[ft.label," ",s.jsxs("span",{className:"tabular-nums",children:[It.toFixed(0),"%"]})]})]},ft.key)})}),t[166]=je,t[167]=R.breakdownTotal,t[168]=tt):tt=t[168];let ut;t[169]!==_e||t[170]!==tt?(ut=s.jsxs("div",{className:"mb-6",children:[_e,tt]}),t[169]=_e,t[170]=tt,t[171]=ut):ut=t[171];let qe;t[172]!==e?(qe=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=qe):qe=t[173];let ze;t[174]!==qe?(ze=s.jsx("div",{className:"typography-micro text-muted-foreground",children:qe}),t[174]=qe,t[175]=ze):ze=t[175];let st;if(t[176]!==d||t[177]!==o||t[178]!==b||t[179]!==a||t[180]!==e){let ft;t[182]!==d||t[183]!==o||t[184]!==a||t[185]!==e?(ft=It=>{const ss=lo(It.info).role,_t=o[It.info.id]===!0,qt=d===It.info.id,ct=It.info.time?.created??null,jt=_t?JSON.stringify({info:It.info,parts:It.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":_t,onClick:()=>{c(as=>({...as,[It.info.id]:as[It.info.id]!==!0}))},children:s.jsxs("div",{className:"flex items-center justify-between gap-2 whitespace-nowrap overflow-hidden",children:[s.jsxs("span",{className:"min-w-0 inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:X2(ss)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:It.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:Q2(ct)})]})}),_t&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:as=>{as.stopPropagation(),k(It.info.id,jt)},"aria-label":e(qt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(qt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:qt?s.jsx(I,{name:"check",className:"size-3.5"}):s.jsx(I,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Cx,{language:"json",style:a,PreTag:"div",customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},codeTagProps:{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"break-word"}},wrapLongLines:!0,children:jt})]})})]},It.info.id)},t[182]=d,t[183]=o,t[184]=a,t[185]=e,t[186]=ft):ft=t[186],st=[...b].reverse().map(ft),t[176]=d,t[177]=o,t[178]=b,t[179]=a,t[180]=e,t[181]=st}else st=t[181];let yt;t[187]!==st?(yt=s.jsx("div",{className:"mt-2.5 space-y-1",children:st}),t[187]=st,t[188]=yt):yt=t[188];let Mt;t[189]!==ze||t[190]!==yt?(Mt=s.jsxs("div",{children:[ze,yt]}),t[189]=ze,t[190]=yt,t[191]=Mt):Mt=t[191];let Bt;return t[192]!==Ae||t[193]!==Ce||t[194]!==Qe||t[195]!==He||t[196]!==ut||t[197]!==Mt?(Bt=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[Ae,Ce,Qe,He,ut,Mt]})}),t[192]=Ae,t[193]=Ce,t[194]=Qe,t[195]=He,t[196]=ut,t[197]=Mt,t[198]=Bt):Bt=t[198],Bt};function tS(t){return t.currentSessionId}function sS(t){return t.providers}function nS(t){return Object.keys(t).length>0?{}:t}function rS(t){return lo(t.info).role==="assistant"}function aS(t){return lo(t.info).isUser}function iS(t,e){const n=wa(e.info.cost);return t+n}function oS(t){return lo(t.info).isUser&&typeof t.info.system=="string"}function lS(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function cS(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:Za(t.value)})]},t.label)}const dS=360,uS=1400,ig=600,mS=24,Zm=200,pS=(t,e)=>e==="all"?!0:e==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":e==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",gd=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="string"&&typeof e.selector=="string"&&typeof e.path=="string"&&!!n&&typeof n?.x=="number"&&typeof n?.y=="number"&&typeof n?.width=="number"&&typeof n?.height=="number"},og=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:a,intro:i})=>{const o=r.text.trim(),c=Object.entries(r.attributes).map(([b,h])=>`${b}="${h}"`).join(" "),d=r.computedStyle,p=r.bounds,m=r.center,u=i.replace(/[.:]+$/g,""),f=r.ancestry.map(b=>b.selectorPart).join(" > ");return[`${u}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${a?"attached":"not attached"}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,c?`- Attributes: ${c}`:null,`- Bounds: x=${Math.round(p.x)}, y=${Math.round(p.y)}, width=${Math.round(p.width)}, height=${Math.round(p.height)}`,`- Center: x=${Math.round(m.x)}, y=${Math.round(m.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(b=>typeof b=="string").join(`
|
|
56
|
-
`)},fS=async(t,e)=>{const n=typeof window<"u"?window.__TAURI__:void 0;if(typeof n?.core?.invoke=="function")try{const r=t.getBoundingClientRect(),a=await n.core.invoke("desktop_capture_page_rect",{x:r.left,y:r.top,width:r.width,height:r.height}),i=new Image;await new Promise((v,x)=>{i.onload=()=>v(),i.onerror=()=>x(new Error("Failed to load desktop preview screenshot")),i.src=`data:${a.mime};base64,${a.base64}`});const o=Math.max(1,i.naturalWidth||a.width||Math.floor(r.width)),c=Math.max(1,i.naturalHeight||a.height||Math.floor(r.height)),p=Math.min(1,1200/o),m=document.createElement("canvas");m.width=Math.floor(o*p),m.height=Math.floor(c*p);const u=m.getContext("2d");if(!u)return null;u.scale(p,p),u.drawImage(i,0,0,o,c);const f=o/Math.max(1,r.width),b=c/Math.max(1,r.height);u.fillStyle="rgba(37, 99, 235, 0.28)",u.strokeStyle="rgb(37, 99, 235)",u.lineWidth=Math.max(2,2*f),u.fillRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b),u.strokeRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b);const h=await new Promise(v=>m.toBlob(v,"image/jpeg",.82));return h?new File([h],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},hS=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},ep=t=>Number.isFinite(t)?Math.min(uS,Math.max(dS,Math.round(t))):ig,gS=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},xS=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":t==="browser"?"contextPanel.mode.browser":"contextPanel.mode.context"),bS=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},yS=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return bS(t.targetPath)||e("contextPanel.mode.files");if(t.mode==="preview"){const n=t.targetPath;if(n)try{const r=new URL(n);return r.host||r.hostname||e("contextPanel.mode.preview")}catch{}return e("contextPanel.mode.preview")}return xS(t.mode,e)},vS=t=>{if(t.mode==="file")return t.targetPath?s.jsx(vr,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(I,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(I,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(I,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(I,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5"})},wS=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,jS=`new Promise((resolve) => {
|
|
57
|
-
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
58
|
-
if (existing) existing.remove();
|
|
59
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
60
|
-
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
61
|
-
}
|
|
62
|
-
const overlay = document.createElement('div');
|
|
63
|
-
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
64
|
-
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
65
|
-
document.documentElement.appendChild(overlay);
|
|
66
|
-
const cssEscape = (value) => {
|
|
67
|
-
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
68
|
-
};
|
|
69
|
-
const selectorPart = (element) => {
|
|
70
|
-
const tag = element.tagName.toLowerCase();
|
|
71
|
-
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
72
|
-
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
73
|
-
return tag + className;
|
|
74
|
-
};
|
|
75
|
-
const metadata = (element) => {
|
|
76
|
-
const rect = element.getBoundingClientRect();
|
|
77
|
-
const style = getComputedStyle(element);
|
|
78
|
-
const ancestry = [];
|
|
79
|
-
let current = element;
|
|
80
|
-
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
81
|
-
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
82
|
-
current = current.parentElement;
|
|
83
|
-
}
|
|
84
|
-
const attrs = {};
|
|
85
|
-
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
86
|
-
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
87
|
-
return {
|
|
88
|
-
frame: 'top',
|
|
89
|
-
tag: element.tagName.toLowerCase(),
|
|
90
|
-
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
91
|
-
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
92
|
-
path,
|
|
93
|
-
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
94
|
-
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
95
|
-
attributes: attrs,
|
|
96
|
-
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
97
|
-
ancestry,
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
const move = (event) => {
|
|
101
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
102
|
-
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
103
|
-
const rect = element.getBoundingClientRect();
|
|
104
|
-
overlay.style.display = 'block';
|
|
105
|
-
overlay.style.left = rect.left + 'px';
|
|
106
|
-
overlay.style.top = rect.top + 'px';
|
|
107
|
-
overlay.style.width = rect.width + 'px';
|
|
108
|
-
overlay.style.height = rect.height + 'px';
|
|
109
|
-
};
|
|
110
|
-
const cleanup = () => {
|
|
111
|
-
window.removeEventListener('mousemove', move, true);
|
|
112
|
-
window.removeEventListener('click', click, true);
|
|
113
|
-
window.removeEventListener('keydown', keydown, true);
|
|
114
|
-
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
115
|
-
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
const cancel = () => {
|
|
119
|
-
cleanup();
|
|
120
|
-
overlay.remove();
|
|
121
|
-
resolve(null);
|
|
122
|
-
};
|
|
123
|
-
const click = (event) => {
|
|
124
|
-
event.preventDefault();
|
|
125
|
-
event.stopPropagation();
|
|
126
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
127
|
-
const result = element ? metadata(element) : null;
|
|
128
|
-
cleanup();
|
|
129
|
-
overlay.remove();
|
|
130
|
-
resolve(result);
|
|
131
|
-
};
|
|
132
|
-
const keydown = (event) => {
|
|
133
|
-
if (event.key !== 'Escape') return;
|
|
134
|
-
cancel();
|
|
135
|
-
};
|
|
136
|
-
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
137
|
-
window.addEventListener('mousemove', move, true);
|
|
138
|
-
window.addEventListener('click', click, true);
|
|
139
|
-
window.addEventListener('keydown', keydown, true);
|
|
140
|
-
});`,Nc=`(() => {
|
|
141
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
142
|
-
window.__openchamberDesktopBrowserCancelInspect();
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
146
|
-
if (overlay) overlay.remove();
|
|
147
|
-
})()`,Sc=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},NS=async(t,e,n,r,a,i)=>{if(!t)return null;try{const o=new Image;await new Promise((x,g)=>{o.onload=()=>x(),o.onerror=()=>g(new Error("Failed to load desktop browser screenshot")),o.src=`data:image/jpeg;base64,${t}`});const c=Math.max(1,o.naturalWidth||e),d=Math.max(1,o.naturalHeight||n),m=Math.min(1,1200/c),u=document.createElement("canvas");u.width=Math.floor(c*m),u.height=Math.floor(d*m);const f=u.getContext("2d");if(!f)return null;f.scale(m,m),f.drawImage(o,0,0,c,d);const b=c/Math.max(1,r||c),h=d/Math.max(1,a||d);f.fillStyle="rgba(37, 99, 235, 0.14)",f.strokeStyle="rgb(37, 99, 235)",f.lineWidth=Math.max(2,2*b),f.fillRect(i.bounds.x*b,i.bounds.y*h,i.bounds.width*b,i.bounds.height*h),f.strokeRect(i.bounds.x*b,i.bounds.y*h,i.bounds.width*b,i.bounds.height*h);const v=await new Promise(x=>u.toBlob(x,"image/jpeg",.82));return v?new File([v],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},SS=(t,e,n)=>{if(typeof window>"u")return"";const r=new URL(window.location.pathname,window.location.origin);return r.searchParams.set("ocPanel","session-chat"),r.searchParams.set("sessionId",t),n?r.searchParams.set("readOnly","1"):r.searchParams.delete("readOnly"),e&&e.trim().length>0?r.searchParams.set("directory",e):r.searchParams.delete("directory"),r.hash="",r.toString()},kS=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Na=new Map,CS=3e4,IS=t=>{const e=Na.get(t);return e?e.expiresAt-Date.now()<=CS?(Na.delete(t),null):e:null},PS=({rawUrl:t,onNavigate:e})=>{const{t:n}=pt(),{currentTheme:r}=Sr(),[a,i]=l.useReducer(ne=>ne+1,0),[o,c]=l.useReducer(ne=>ne+1,0),[d,p]=l.useState({status:"idle"}),m=l.useRef(null),u=l.useRef(1),[f,b]=l.useState(!1),[h,v]=l.useState(!1),[x,g]=l.useState("all"),[w,y]=l.useState([]),[k,A]=l.useState(!1),[j,S]=l.useState(null),D=Lt(ne=>ne.currentSessionId),E=Lt(ne=>ne.newSessionDraft?.open),P=ti(ne=>ne.addDraft),C=Ea(ne=>ne.addAttachedFile);let N=null;try{N=t?new URL(t):null}catch{N=null}const T=N?N.hostname==="localhost"||N.hostname==="127.0.0.1"||N.hostname==="::1"||N.hostname==="[::1]"||N.hostname==="0.0.0.0":!1,M=N?N.hostname==="0.0.0.0"?new URL(N.toString().replace("0.0.0.0","127.0.0.1")):N:null,F=M?M.toString():"",_=r.metadata.variant;l.useEffect(()=>{if(!F||!T){p({status:"idle"});return}const ne=IS(F);if(ne){p({status:"ready",proxyBasePath:ne.proxyBasePath,expiresAt:ne.expiresAt});return}let fe=!1;return p({status:"loading"}),(async()=>{try{const pe=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:F})});if(!pe.ok){Na.delete(F);const se=await pe.json().catch(()=>({})),we=typeof se?.error=="string"?se.error:`HTTP ${pe.status}`;fe||p({status:"error",message:we});return}const je=await pe.json(),oe=typeof je.proxyBasePath=="string"?je.proxyBasePath:"",Se=typeof je.expiresAt=="number"?je.expiresAt:0;if(!oe){Na.delete(F),fe||p({status:"error",message:n("contextPanel.preview.proxyError")});return}Na.set(F,{proxyBasePath:oe,expiresAt:Se}),fe||p({status:"ready",proxyBasePath:oe,expiresAt:Se})}catch(pe){if(Na.delete(F),!fe){const je=pe instanceof Error?pe.message:String(pe);p({status:"error",message:je})}}})(),()=>{fe=!0}},[T,o,n,F]);const B=M&&(M.protocol==="http:"||M.protocol==="https:")?M.toString():"",V=T&&d.status==="ready"&&M?(()=>{const ne=M.pathname||"/",fe=new URLSearchParams(M.search);fe.set("ocPreview",String(a));const pe=fe.toString(),je=M.hash||"";return`${d.proxyBasePath}${ne}${pe?`?${pe}`:""}${je}`})():"",$=T?V:B,z=$||B,Q=T&&(d.status==="loading"||d.status==="idle"),L=T&&d.status==="error",J=l.useCallback(ne=>{const fe=D??(E?"draft":null);if(!fe){H.error(n("contextPanel.preview.inspect.attachNoSession"));return}const pe=t||$||"",je=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},oe=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let Se=!1;try{const se=m.current,we=se?await fS(se,ne):null;we&&(await C(we),Se=!0)}catch{Se=!1}P({sessionKey:fe,source:"preview-annotation",fileLabel:pe||"preview",startLine:1,endLine:1,code:og({pageUrl:pe,viewport:je,devicePixelRatio:oe,target:ne,screenshotAttached:Se,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),H.success(n("contextPanel.preview.inspect.attached"))})()},[C,P,D,$,E,t,n]);l.useEffect(()=>{b(!1),y([]),v(!1),g("all"),A(!1),S(null),u.current=1},[$]),l.useEffect(()=>{const ne=m.current?.contentWindow;!f||!ne||ne.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:k},window.location.origin)},[f,k]),l.useEffect(()=>{const ne=m.current?.contentWindow;!f||!ne||ne.postMessage({source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:_},window.location.origin)},[f,_]),l.useEffect(()=>{if(!k||typeof window>"u")return;const ne=fe=>{fe.key==="Escape"&&(fe.preventDefault(),fe.stopImmediatePropagation(),A(!1))};return window.addEventListener("keydown",ne,!0),()=>window.removeEventListener("keydown",ne,!0)},[k]),l.useEffect(()=>{if(!T||typeof window>"u")return;const ne=je=>{if(typeof je=="string")return je;if(je==null)return"";try{return JSON.stringify(je)}catch{return String(je)}},fe=je=>{const oe=u.current;u.current+=1,y(Se=>{const se=[...Se,{...je,id:oe}];return se.length>Zm?se.slice(se.length-Zm):se})},pe=je=>{if(je.source!==m.current?.contentWindow)return;const oe=je.data;if(!(!oe||oe.source!=="openchamber-preview-bridge"||oe.version!==1)){if(oe.type==="ready"){b(!0);return}if(oe.type==="console"){const Se=oe.level==="error"||oe.level==="warn"||oe.level==="info"||oe.level==="debug"?oe.level:"log",se=Array.isArray(oe.args)?oe.args.map(ne).filter(Boolean):[];fe({level:Se,message:se.join(" "),ts:typeof oe.ts=="number"?oe.ts:Date.now()});return}if(oe.type==="runtime-error"){const Se=ne(oe.filename),se=typeof oe.line=="number"?oe.line:null,we=typeof oe.column=="number"?oe.column:null,Ae=Se?`${Se}${se!==null?`:${se}${we!==null?`:${we}`:""}`:""}`:"",ve=ne(oe.stack);fe({level:"runtime",message:ne(oe.message)||n("contextPanel.preview.console.runtimeError"),details:[Ae,ve].filter(Boolean).join(`
|
|
148
|
-
`),ts:typeof oe.ts=="number"?oe.ts:Date.now()});return}if(oe.type==="resource-error"){const Se=ne(oe.tag)||"resource",se=ne(oe.url);fe({level:"resource",message:se?`${Se}: ${se}`:Se,details:ne(oe.outerHTML),ts:typeof oe.ts=="number"?oe.ts:Date.now()});return}if(oe.type==="hover"){S(gd(oe.target)?oe.target:null);return}if(oe.type==="select"&&gd(oe.target)){S(oe.target),A(!1),J(oe.target);return}if(oe.type==="navigate-preview"){const Se=typeof oe.url=="string"?oe.url:"",se=oe.navigation==="external"?"external":"proxy";if(Se&&se==="external"){Zn(Se);return}Se&&e(Se)}}};return window.addEventListener("message",pe),()=>{window.removeEventListener("message",pe)}},[J,T,e,n]);const ee=w.filter(ne=>ne.level==="error"||ne.level==="runtime"||ne.level==="resource").length,re=w.filter(ne=>pS(ne,x)),q=l.useCallback(()=>{const ne=[`Preview URL: ${t||$||""}`,`Events: ${w.length}`,""].join(`
|
|
149
|
-
`),fe=w.map(pe=>{const je=new Date(pe.ts).toISOString(),oe=pe.details?`
|
|
150
|
-
${pe.details}`:"";return`[${je}] [${pe.level}] ${pe.message}${oe}`}).join(`
|
|
151
|
-
`);An(`${ne}${fe}`).then(pe=>{pe.ok?H.success(n("contextPanel.preview.console.copied")):H.error(n("contextPanel.preview.console.copyFailed"))})},[w,$,t,n]),ce=l.useCallback(()=>{const ne=D??(E?"draft":null);if(!ne){H.error(n("contextPanel.preview.console.attachNoSession"));return}const fe=[`Preview URL: ${t||$||""}`,`Events: ${w.length}`,""].join(`
|
|
152
|
-
`),pe=w.map(je=>{const oe=new Date(je.ts).toISOString(),Se=je.details?`
|
|
153
|
-
${je.details}`:"";return`[${oe}] [${je.level}] ${je.message}${Se}`}).join(`
|
|
154
|
-
`);P({sessionKey:ne,source:"preview-console",fileLabel:t||$||"preview",startLine:1,endLine:Math.max(1,w.length),code:`${fe}${pe}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),H.success(n("contextPanel.preview.console.attached"))},[P,w,D,$,E,t,n]),[ae,R]=l.useState("unknown"),U=l.useRef(0),W=l.useRef(0),Z=15e3;l.useEffect(()=>{if(!V){R("unknown"),U.current=0,W.current=0;return}let ne=!1;return U.current||(U.current=Date.now(),W.current=0),R("unknown"),(async()=>{const pe=await(async()=>{try{return await fetch(V,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(ne)return;if(!pe){R("unreachable");return}if(pe.status===403||pe.status===404){Na.delete(F),p({status:"loading"}),c();return}if(pe.status!==502){R("reachable");return}const je=U.current||Date.now();if(Date.now()-je<Z){R("starting"),W.current+=1;const Se=W.current,se=Math.min(2e3,250*Math.pow(2,Math.min(4,Se)));setTimeout(()=>{ne||i()},se).unref?.();return}R("unreachable")})(),()=>{ne=!0}},[V,a,F]);const K=T&&d.status==="ready"&&(ae==="unknown"||ae==="starting"),ie=T&&d.status==="ready"&&ae==="unreachable",Ne=l.useCallback(ne=>{if(!T||d.status!=="ready"||typeof window>"u")return;const fe=ne.currentTarget.contentWindow;if(fe)try{const pe=fe.location;if(pe.origin!==window.location.origin||pe.pathname.startsWith(d.proxyBasePath))return;const je=`${d.proxyBasePath}${pe.pathname}${pe.search}${pe.hash}`;fe.location.replace(je)}catch{}},[T,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:z||t,children:z||t||n("contextPanel.preview.empty")}),s.jsx(xe,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!$,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(xe,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{B&&Zn(B)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!B,children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})}),T?s.jsx(xe,{type:"button",size:"sm",variant:k?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>A(ne=>!ne),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!f,children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}):null,T?s.jsxs(xe,{type:"button",size:"sm",variant:h?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(ne=>!ne),title:n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!f&&w.length===0,children:[s.jsx(I,{name:"terminal-box",className:"h-3.5 w-3.5"}),ee>0?s.jsx("span",{className:"typography-micro text-status-error",children:ee}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[K?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):ie?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(xe,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):$&&(!T||ae==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:$,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:_},onLoad:Ne,sandbox:T?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${$}:${a}`),k&&j?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:j.bounds.x,top:j.bounds.y,width:j.bounds.width,height:j.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[j.tag,j.text?` · ${j.text}`:""]})}):null]}):Q?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):L?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),h?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(xe,{type:"button",size:"xs",variant:"ghost",onClick:ce,disabled:w.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(xe,{type:"button",size:"xs",variant:"ghost",onClick:q,disabled:w.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(xe,{type:"button",size:"xs",variant:"ghost",onClick:()=>y([]),disabled:w.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(ne=>s.jsx(xe,{type:"button",size:"xs",variant:x===ne?"secondary":"ghost",onClick:()=>g(ne),children:n(ne==="all"?"contextPanel.preview.console.filter.all":ne==="errors"?"contextPanel.preview.console.filter.errors":ne==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},ne))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:w.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):re.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):re.map(ne=>s.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:ue("shrink-0 uppercase",ne.level==="error"||ne.level==="runtime"||ne.level==="resource"?"text-status-error":ne.level==="warn"?"text-status-warning":"text-muted-foreground"),children:ne.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:ne.message})]})},ne.id))})]}):null]})]})},AS=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=pt(),a=l.useRef(null),i=De(E=>E.setContextPanelTabTargetPath),o=Sc(t),c=o!=="about:blank"?o:"",[d,p]=l.useState(c),[m,u]=l.useState(c),[f,b]=l.useState(!1),[h,v]=l.useState(!0),x=l.useRef(null),g=h,w=l.useCallback(E=>{!E||E==="about:blank"||!e||!n||i(e,n,E)},[e,n,i]),y=Lt(E=>E.currentSessionId),k=Lt(E=>E.newSessionDraft?.open),A=ti(E=>E.addDraft),j=Ea(E=>E.addAttachedFile);l.useEffect(()=>{const E=a.current;if(!E)return;const P=()=>{try{const F=E.getURL();F&&F!=="about:blank"&&(u(F),p(F),w(F))}catch{}},C=F=>{const _=F.detail;typeof _?.url=="string"&&_.url&&(u(_.url),p(_.url),w(_.url))},N=()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>v(!0),200)},T=()=>{x.current&&clearTimeout(x.current),v(!1),P()},M=F=>{const _=F.detail;if(_?.disposition==="new-window"||_?.disposition==="foreground-tab"||_?.disposition==="background-tab"){F.preventDefault();const B=a.current;typeof B?.loadURL=="function"&&_.url&&B.loadURL(_.url)}};E.addEventListener("did-navigate",C),E.addEventListener("did-navigate-in-page",C),E.addEventListener("did-start-loading",N),E.addEventListener("did-stop-loading",T),E.addEventListener("new-window",M);try{E.isLoading()||(v(!1),P())}catch{}return()=>{x.current&&clearTimeout(x.current),E.removeEventListener("did-navigate",C),E.removeEventListener("did-navigate-in-page",C),E.removeEventListener("did-start-loading",N),E.removeEventListener("did-stop-loading",T),E.removeEventListener("new-window",M)}},[w]),l.useEffect(()=>{const E=setTimeout(()=>v(!1),3e4);return()=>clearTimeout(E)},[]),l.useEffect(()=>{if(!f)return;const E=P=>{if(P.key!=="Escape")return;P.preventDefault(),P.stopImmediatePropagation(),b(!1);const C=a.current;try{C?.executeJavaScript?.(Nc).catch(()=>{})}catch{}};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[f]),l.useEffect(()=>{const E=a.current;return()=>{try{const P=E?.getURL?.();P&&P!=="about:blank"&&i(e,n,P)}catch{}try{E?.executeJavaScript?.(Nc).catch(()=>{})}catch{}}},[e,n,i]);const S=l.useCallback(E=>{const P=a.current;if(typeof P?.loadURL!="function")return;const C=Sc(E);try{P.loadURL(C)}catch{}},[]),D=l.useCallback(()=>{const E=a.current;if(E){if(f){b(!1);try{E.executeJavaScript?.(Nc).catch(()=>{})}catch{}return}b(!0),E.executeJavaScript?.(jS,!0).then(async P=>{if(b(!1),!P||!gd(P))return;const C=y??(k?"draft":null);if(!C){H.error(r("contextPanel.preview.inspect.attachNoSession"));return}const N=typeof E.getWebContentsId=="function"?E.getWebContentsId():null;if(N==null)return;const T=await Ab("desktop_browser_capture_page",{webContentsId:N}),M=await E.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),F=Number.isFinite(M?.width)?M.width:T.width,_=Number.isFinite(M?.height)?M.height:T.height,B=await NS(T.base64,T.width,T.height,F,_,P),V=!!B;B&&await j(B),A({sessionKey:C,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:og({pageUrl:m,viewport:{width:F,height:_},devicePixelRatio:window.devicePixelRatio||1,target:P,screenshotAttached:V,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),H.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[j,A,y,m,f,k,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(xe,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goBack?.()}catch{}},children:s.jsx(I,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(xe,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goForward?.()}catch{}},children:s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(xe,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.reload?.()}catch{}},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:E=>{E.preventDefault(),S(d)},children:s.jsx("input",{value:d,onChange:E=>p(E.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(xe,{type:"button",variant:f?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:D,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(xe,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{Zn(m)},children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:a,src:Sc(t),partition:"persist:openchamber-browser",style:{width:"100%",height:"100%",border:"none"}}),(!m||m==="about:blank")&&!h?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Bd,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,g?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},DS=()=>{const{t}=pt(),e=Lr()??"",n=l.useMemo(()=>hS(e),[e]),r=De(K=>n?K.contextPanelByDirectory[n]:void 0),a=De(K=>K.closeContextPanel),i=De(K=>K.closeContextPanelTab),o=De(K=>K.toggleContextPanelExpanded),c=De(K=>K.setContextPanelWidth),d=De(K=>K.setActiveContextPanelTab),p=De(K=>K.reorderContextPanelTabs),m=De(K=>K.setPendingDiffFile),u=En(K=>K.setSelectedPath),f=De(K=>K.openContextPreview),{themeMode:b,lightThemeId:h,darkThemeId:v,currentTheme:x}=Sr(),g=l.useMemo(()=>r?.tabs??[],[r?.tabs]),w=g.find(K=>K.id===r?.activeTabId)??g[g.length-1]??null,y=!!(r?.isOpen&&w),k=!!(y&&r?.expanded),A=ep(r?.width??ig),[j,S]=l.useState(!1),D=l.useRef(0),E=l.useRef(A),P=l.useRef(null),C=l.useRef(null),N=l.useRef(null),T=l.useRef(new Map),M=l.useRef(!1);l.useEffect(()=>{if(!y||M.current){M.current=y;return}const K=window.requestAnimationFrame(()=>{N.current?.focus({preventScroll:!0})});return M.current=!0,()=>window.cancelAnimationFrame(K)},[y]);const F=l.useCallback(K=>{const ie=N.current;ie&&ie.style.setProperty("--oc-context-panel-width",`${K}px`)},[]),_=l.useCallback(K=>{if(!(!y||k||!n)){try{K.currentTarget.setPointerCapture(K.pointerId)}catch{}C.current=K.pointerId,S(!0),D.current=K.clientX,E.current=A,P.current=A,F(A),K.preventDefault()}},[F,n,k,y,A]),B=l.useCallback(K=>{if(!j||C.current!==K.pointerId)return;const ie=D.current-K.clientX,Ne=ep(E.current+ie);P.current!==Ne&&(P.current=Ne,F(Ne))},[F,j]),V=l.useCallback(K=>{if(C.current!==K.pointerId||!n)return;try{K.currentTarget.releasePointerCapture(K.pointerId)}catch{}const ie=P.current??A;S(!1),C.current=null,P.current=null,c(n,ie)},[n,c,A]);l.useEffect(()=>{j||(P.current=null)},[j]);const $=l.useCallback(()=>{n&&a(n)},[a,n]),z=l.useCallback(()=>{n&&o(n)},[n,o]),Q=l.useCallback(K=>{K.key==="Escape"&&(K.preventDefault(),K.stopPropagation(),$())},[$]);l.useEffect(()=>{if(!(!n||!w)){if(w.mode==="file"&&w.targetPath){u(n,w.targetPath);return}w.mode==="diff"&&w.targetPath&&m(w.targetPath)}},[w,n,m,u]);const L=w?.mode==="chat"?w.id:null,J=l.useCallback(()=>{if(typeof window>"u")return;const K={themeMode:b,lightThemeId:h,darkThemeId:v,currentTheme:x};for(const ie of T.current.values()){const Ne=ie.contentWindow;if(!Ne)continue;const ne=Ne.__openchamberApplyThemeSync;if(typeof ne=="function")try{ne(K);continue}catch{}Ne.postMessage({type:"openchamber:theme-sync",payload:K},window.location.origin)}},[x,v,h,b]),ee=l.useCallback(()=>{if(!(typeof window>"u"))for(const[K,ie]of T.current.entries()){const Ne=ie.contentWindow;if(!Ne)continue;const ne={visible:L===K},fe=Ne.__openchamberSetEmbeddedVisibility;if(typeof fe=="function")try{fe(ne);continue}catch{}Ne.postMessage({type:"openchamber:embedded-visibility",payload:ne},window.location.origin)}},[L]);l.useLayoutEffect(()=>{g.some(ie=>ie.mode==="chat")&&(J(),ee())},[v,h,ee,J,g,b]);const re=l.useMemo(()=>g.map(K=>{const ie=yS(K,t),Ne=kS(ie,mS),ne=gS(K.targetPath,e);return{id:K.id,label:Ne,icon:vS(K),title:ne?`${ie}: ${ne}`:ie,closeLabel:t("contextPanel.tab.closeTabAria",{label:Ne})}}),[e,t,g]),q=w?.mode==="diff"?s.jsx(Zh,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0}):w?.mode==="context"?s.jsx(eS,{}):w?.mode==="plan"?s.jsx(ag,{targetPath:w.targetPath}):w?.mode==="preview"?s.jsx(PS,{rawUrl:w.targetPath??"",onNavigate:K=>f(e,K)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(I,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),ce=l.useMemo(()=>g.filter(K=>K.mode==="chat"),[g]),ae=l.useMemo(()=>g.filter(K=>K.mode==="browser"),[g]),R=l.useMemo(()=>g.some(K=>K.mode==="file"),[g]),U=w?.mode==="file",W=s.jsxs("header",{className:"flex h-8 items-stretch border-b border-transparent",children:[s.jsx(Er,{items:re,activeId:w?.id??null,onSelect:K=>{n&&d(n,K)},onClose:K=>{n&&i(n,K)},onReorder:(K,ie)=>{n&&p(n,K,ie)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(xe,{type:"button",variant:"ghost",size:"sm",onClick:z,className:"h-7 w-7 p-0",title:t(k?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(k?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:k?s.jsx(I,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(xe,{type:"button",variant:"ghost",size:"sm",onClick:$,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]});if(!y)return null;const Z=k?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"var(--oc-context-panel-width)",minWidth:"var(--oc-context-panel-width)",maxWidth:"var(--oc-context-panel-width)","--oc-context-panel-width":`${j?P.current??A:A}px`};return s.jsxs("aside",{ref:N,"data-context-panel":"true",tabIndex:-1,className:ue("flex min-h-0 flex-col overflow-hidden bg-background",!k&&"border-l border-border/40",k?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",j?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:Q,style:Z,children:[!k&&s.jsx("div",{className:ue("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",j&&"bg-[var(--interactive-border)]"),onPointerDown:_,onPointerMove:B,onPointerUp:V,onPointerCancel:V,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),W,s.jsxs("div",{className:ue("relative min-h-0 flex-1 overflow-hidden",j&&"pointer-events-none"),children:[R?s.jsx("div",{className:ue("absolute inset-0",U?"block":"hidden"),children:s.jsx(rg,{mode:"editor-only"})}):null,ce.map(K=>{const ie=wS(K.dedupeKey);if(!ie)return null;const Ne=SS(ie,n||null,K.readOnly);return Ne?s.jsx("iframe",{ref:ne=>{if(!ne){T.current.delete(K.id);return}T.current.set(K.id,ne)},src:Ne,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ie}),className:ue("absolute inset-0 h-full w-full border-0 bg-background",L===K.id?"block":"hidden"),onLoad:()=>{J(),ee()}},K.id):null}),ae.map(K=>s.jsx("div",{className:ue("absolute inset-0",w?.mode!=="browser"&&"hidden"),children:s.jsx(AS,{initialUrl:K.targetPath??"",directory:n,tabID:K.id})},K.id)),w?.mode!=="chat"&&!U&&w?.mode!=="browser"?q:null]})]})},Zd=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"split",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:t=>t.isDesktop&&!t.isWeb&&!t.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"usage",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"skills.installed",title:"Skills",group:"skills",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"skills",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"git",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:t=>!t.isVSCode},{slug:"appearance",title:"Appearance",group:"appearance",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:t=>!t.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"general",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:t=>!t.isVSCode},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"voice",title:"Voice",group:"advanced",kind:"single",keywords:["tts","speech","voice"],isAvailable:t=>!t.isVSCode},{slug:"tunnel",title:"Remote Tunnel",group:"advanced",kind:"single",keywords:["tunnel","cloudflare","qr","remote","mobile","share"],isAvailable:t=>!t.isVSCode}],TS={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function $i(t){const e=t.trim().toLowerCase();return Zd.find(n=>n.slug===e)??null}function lg(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=TS[e];if(n)return n;const r=$i(e);return r?r.slug:"home"}const cg=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),po=t=>{const e=ot.c(39),{className:n}=t,{t:r}=pt(),a=Ts(MS),i=Ts(ES),o=Ts(RS),c=ln();let d;e[0]!==a?(d=[...a].sort(FS),e[0]=a,e[1]=d):d=e[1];const p=d;let m;e:{if(p.length===0){m=null;break e}let M;e[2]!==i||e[3]!==p?(M=p.find(F=>F.id===i)??p[0],e[2]=i,e[3]=p,e[4]=M):M=e[4],m=M}const u=m;if(c||p.length===0)return null;let f;e[5]!==u||e[6]!==r?(f=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||r("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=r,e[7]=f):f=e[7];const b=f;let h;e[8]!==b?(h=cg(b),e[8]=b,e[9]=h):h=e[9];const v=h;let x;e[10]!==n?(x=ue(n),e[10]=n,e[11]=x):x=e[11];let g;e[12]!==r?(g=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=g):g=e[13];let w;e[14]!==r?(w=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=w):w=e[15];let y,k;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=ue("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),k=s.jsx(I,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=y,e[17]=k):(y=e[16],k=e[17]);let A;e[18]!==v?(A=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:v}),e[18]=v,e[19]=A):A=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let S;e[21]!==A||e[22]!==g||e[23]!==w?(S=s.jsx(Es,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":g,title:w,className:y,children:[k,A,j]})}),e[21]=A,e[22]=g,e[23]=w,e[24]=S):S=e[24];const D=u?.id??"";let E;e[25]!==o?(E=M=>{M&&o(M)},e[25]=o,e[26]=E):E=e[26];let P;e[27]!==p?(P=p.map(OS),e[27]=p,e[28]=P):P=e[28];let C;e[29]!==D||e[30]!==E||e[31]!==P?(C=s.jsx(Rs,{align:"start",className:"w-auto",children:s.jsx(il,{value:D,onValueChange:E,children:P})}),e[29]=D,e[30]=E,e[31]=P,e[32]=C):C=e[32];let N;e[33]!==S||e[34]!==C?(N=s.jsxs(Fs,{children:[S,C]}),e[33]=S,e[34]=C,e[35]=N):N=e[35];let T;return e[36]!==N||e[37]!==x?(T=s.jsx("div",{className:x,children:N}),e[36]=N,e[37]=x,e[38]=T):T=e[38],T};function MS(t){return t.projects}function ES(t){return t.activeProjectId}function RS(t){return t.setActiveProject}function FS(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function OS(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=cg(e);return s.jsx(ol,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function LS(t,e){return`opencode:sidebar-group:${t}:${e}`}const xd=t=>{const e=ot.c(33),{label:n,count:r,storageKey:a,defaultExpanded:i,children:o}=t,c=i===void 0?!0:i;let d;e[0]!==n||e[1]!==a?(d=LS(a,n),e[0]=n,e[1]=a,e[2]=d):d=e[2];const p=d,m=l.useId();let u;e[3]!==c||e[4]!==p?(u=()=>{try{const C=localStorage.getItem(p);if(C!==null)return C==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=u):u=e[5];const[f,b]=$e.useState(u);let h,v;e[6]!==f||e[7]!==p?(h=()=>{try{localStorage.setItem(p,String(f))}catch{}},v=[p,f],e[6]=f,e[7]=p,e[8]=h,e[9]=v):(h=e[8],v=e[9]),$e.useEffect(h,v);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>b($S),e[10]=x):x=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=ue("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=g):g=e[11];const w=!f&&"-rotate-90";let y;e[12]!==w?(y=ue("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",w),e[12]=w,e[13]=y):y=e[13];let k;e[14]!==y?(k=s.jsx(I,{name:"arrow-down-s",className:y}),e[14]=y,e[15]=k):k=e[15];let A;e[16]!==n?(A=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=A):A=e[17];let j;e[18]!==r?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:r}),e[18]=r,e[19]=j):j=e[19];let S;e[20]!==m||e[21]!==f||e[22]!==k||e[23]!==A||e[24]!==j?(S=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":f,"aria-controls":m,className:g,children:[k,A,j]}),e[20]=m,e[21]=f,e[22]=k,e[23]=A,e[24]=j,e[25]=S):S=e[25];const D=!f;let E;e[26]!==o||e[27]!==m||e[28]!==D?(E=s.jsx("div",{id:m,hidden:D,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[26]=o,e[27]=m,e[28]=D,e[29]=E):E=e[29];let P;return e[30]!==S||e[31]!==E?(P=s.jsxs("div",{children:[S,E]}),e[30]=S,e[31]=E,e[32]=P):P=e[32],P};function $S(t){return!t}const BS=t=>{if(!Array.isArray(t))return[];const e=[];for(const n of t){if(!n||typeof n!="object")continue;const r=n;typeof r.permission!="string"||typeof r.pattern!="string"||typeof r.action!="string"||r.action!=="allow"&&r.action!=="ask"&&r.action!=="deny"||e.push({permission:r.permission,pattern:r.pattern,action:r.action})}return e},_S=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},tp=t=>{const e=_S(BS(t));if(e.length===0)return;const n={};for(const a of e)a.permission&&((n[a.permission]||={})[a.pattern]=a.action);const r={};for(const[a,i]of Object.entries(n)){const o=Object.keys(i);if(o.length===1&&o[0]==="*"){r[a]=i["*"];continue}r[a]=i}return Object.keys(r).length>0?r:void 0},zS=({onItemSelect:t})=>{const{t:e}=pt(),[n,r]=l.useState(null),[a,i]=l.useState(""),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedAgentName:h,agents:v,setSelectedAgent:x,setAgentDraft:g,createAgent:w,deleteAgent:y,loadAgents:k}=di(hr(z=>({selectedAgentName:z.selectedAgentName,agents:z.agents,setSelectedAgent:z.setSelectedAgent,setAgentDraft:z.setAgentDraft,createAgent:z.createAgent,deleteAgent:z.deleteAgent,loadAgents:z.loadAgents})));l.useEffect(()=>{k()},[k]);const A="bg-background",j=()=>{const z="new-agent";let Q=z,L=1;for(;v.some(J=>J.name===Q);)Q=`${z}-${L}`,L++;g({name:Q,scope:"user"}),x(Q),t?.()},S=async z=>{if(si(z)){H.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(z),p("delete")},D=async z=>{si(z)&&(c(z),p("reset"))},E=()=>{c(null),p(null)},P=async()=>{if(!o||!d)return;u(!0),await y(o.name)?(d==="delete"?H.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):H.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),E()):d==="delete"?H.error(e("settings.agents.sidebar.toast.deleteFailed")):H.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},C=z=>{const Q=z.name;let L=1,J=`${Q}-copy`;for(;v.some(ce=>ce.name===J);)L++,J=`${Q}-copy-${L}`;const ee=z,re=z.model?.providerID&&z.model?.modelID?`${z.model.providerID}/${z.model.modelID}`:null,q=z;g({name:J,scope:ee.scope||"user",description:z.description,model:re,temperature:z.temperature,top_p:z.topP,prompt:z.prompt,mode:z.mode,permission:tp(z.permission),disable:q.disable}),x(J)},N=z=>{i(z.name),r(z)},T=async()=>{if(!n)return;const z=a.trim().replace(/\s+/g,"-");if(!z){H.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(z===n.name){r(null);return}if(v.some(ee=>ee.name===z)){H.error(e("settings.agents.sidebar.toast.agentExists"));return}const Q=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,L=n;await w({name:z,description:n.description,model:Q,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:tp(n.permission),disable:L.disable,scope:L.scope})?await y(n.name)?(H.success(`Agent renamed to "${z}"`),x(z)):H.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):H.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},M=z=>{switch(z){case"primary":return s.jsx(I,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(I,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(I,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},F=v.filter(z=>!Db(z)),_=F.filter(si),B=F.filter(z=>!si(z)),{groupedCustomAgents:V,ungroupedCustomAgents:$}=$e.useMemo(()=>{const z={},Q=[];for(const J of B){const ee=J;ee.group?(z[ee.group]||(z[ee.group]=[]),z[ee.group].push(J)):Q.push(J)}return{groupedCustomAgents:Object.keys(z).sort((J,ee)=>J.localeCompare(ee)).map(J=>({name:J,agents:z[J]})),ungroupedCustomAgents:Q}},[B]);return s.jsxs("div",{className:ue("flex h-full flex-col",A),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),s.jsx(po,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:F.length})}),s.jsx(xe,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:F.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[_.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),_.map(z=>s.jsx(kc,{agent:z,isSelected:h===z.name,onSelect:()=>{x(z.name),t?.()},onReset:()=>D(z),onDuplicate:()=>C(z),getAgentModeIcon:M,isMenuOpen:f===z.name,onMenuOpenChange:Q=>b(Q?z.name:null)},z.name))]}),B.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),V.map(({name:z,agents:Q})=>s.jsx(xd,{label:z,count:Q.length,storageKey:"agents",children:Q.map(L=>s.jsx(kc,{agent:L,isSelected:h===L.name,onSelect:()=>{x(L.name),t?.()},onRename:()=>N(L),onDelete:()=>S(L),onDuplicate:()=>C(L),getAgentModeIcon:M,isMenuOpen:f===L.name,onMenuOpenChange:J=>b(J?L.name:null)},L.name))},z)),$.map(z=>s.jsx(kc,{agent:z,isSelected:h===z.name,onSelect:()=>{x(z.name),t?.()},onRename:()=>N(z),onDelete:()=>S(z),onDuplicate:()=>C(z),getAgentModeIcon:M,isMenuOpen:f===z.name,onMenuOpenChange:Q=>b(Q?z.name:null)},z.name))]})]})}),s.jsx(ps,{open:o!==null&&d!==null,onOpenChange:z=>{!z&&!m&&E()},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Ps,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),s.jsxs(Us,{children:[s.jsx(xe,{size:"sm",variant:"ghost",onClick:E,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(xe,{size:"sm",onClick:P,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(ps,{open:n!==null,onOpenChange:z=>!z&&r(null),children:s.jsxs(ms,{children:[s.jsxs(vs,{children:[s.jsx(gs,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Ps,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Vt,{value:a,onChange:z=>i(z.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:z=>{z.key==="Enter"&&T()}}),s.jsxs(Us,{children:[s.jsx(xe,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(xe,{size:"sm",onClick:T,children:e("settings.common.actions.rename")})]})]})})]})},kc=t=>{const e=ot.c(58),{agent:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,getAgentModeIcon:p,isMenuOpen:m,onMenuOpenChange:u}=t,{t:f}=pt(),b=n;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Qi(),e[0]=h):h=e[0];const v=h,x=r?"bg-interactive-selection":"hover:bg-interactive-hover";let g;e[1]!==x?(g=ue("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",x),e[1]=x,e[2]=g):g=e[2];let w;e[3]!==u?(w=v?void 0:Q=>{Q.preventDefault(),u(!0)},e[3]=u,e[4]=w):w=e[4];let y;e[5]!==n.name?(y=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=y):y=e[6];let k;e[7]!==n.mode||e[8]!==p?(k=p(n.mode),e[7]=n.mode,e[8]=p,e[9]=k):k=e[9];let A;e[10]!==n||e[11]!==b.scope||e[12]!==f?(A=(b.scope||si(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:si(n)?f("settings.agents.sidebar.badge.system"):b.scope}),e[10]=n,e[11]=b.scope,e[12]=f,e[13]=A):A=e[13];let j;e[14]!==y||e[15]!==k||e[16]!==A?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,k,A]}),e[14]=y,e[15]=k,e[16]=A,e[17]=j):j=e[17];let S;e[18]!==n.description?(S=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=S):S=e[19];let D;e[20]!==a||e[21]!==j||e[22]!==S?(D=s.jsxs("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[j,S]}),e[20]=a,e[21]=j,e[22]=S,e[23]=D):D=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Es,{asChild:!0,children:s.jsx(xe,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=E):E=e[24];let P;e[25]!==c||e[26]!==f?(P=c&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),c()},children:[s.jsx(I,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),e[25]=c,e[26]=f,e[27]=P):P=e[27];let C;e[28]!==d?(C=Q=>{Q.stopPropagation(),d()},e[28]=d,e[29]=C):C=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(I,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=N):N=e[30];let T;e[31]!==f?(T=f("settings.common.actions.duplicate"),e[31]=f,e[32]=T):T=e[32];let M;e[33]!==C||e[34]!==T?(M=s.jsxs($t,{onClick:C,children:[N,T]}),e[33]=C,e[34]=T,e[35]=M):M=e[35];let F;e[36]!==o||e[37]!==f?(F=o&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),o()},children:[s.jsx(I,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),e[36]=o,e[37]=f,e[38]=F):F=e[38];let _;e[39]!==i||e[40]!==f?(_=i&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]}),e[39]=i,e[40]=f,e[41]=_):_=e[41];let B;e[42]!==P||e[43]!==M||e[44]!==F||e[45]!==_?(B=s.jsxs(Rs,{align:"end",className:"w-fit min-w-20",children:[P,M,F,_]}),e[42]=P,e[43]=M,e[44]=F,e[45]=_,e[46]=B):B=e[46];let V;e[47]!==m||e[48]!==u||e[49]!==B?(V=s.jsxs(Fs,{open:m,onOpenChange:u,children:[E,B]}),e[47]=m,e[48]=u,e[49]=B,e[50]=V):V=e[50];let $;e[51]!==D||e[52]!==V?($=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[D,V]}),e[51]=D,e[52]=V,e[53]=$):$=e[53];let z;return e[54]!==$||e[55]!==g||e[56]!==w?(z=s.jsx("div",{className:g,onContextMenu:w,children:$}),e[54]=$,e[55]=g,e[56]=w,e[57]=z):z=e[57],z};function sp(t,e,n){return Math.min(n,Math.max(e,t))}function VS(t){if(!Number.isFinite(t))return 0;const e=String(t);if(e.includes("e-")){const[,r]=e.split("e-");return Number(r)||0}const n=e.split(".");return n.length===2?n[1].length:0}function np(t,e){const n=VS(e);return n<=0?t:Number(t.toFixed(n))}const Fn=$e.forwardRef((t,e)=>{const n=ot.c(125);let r,a,i,o,c,d,p,m,u,f,b,h,v;n[0]!==t?({value:v,onValueChange:p,min:u,max:f,step:b,className:r,containerClassName:a,onBlur:c,disabled:i,fallbackValue:o,onClear:d,emptyLabel:h,...m}=t,n[0]=t,n[1]=r,n[2]=a,n[3]=i,n[4]=o,n[5]=c,n[6]=d,n[7]=p,n[8]=m,n[9]=u,n[10]=f,n[11]=b,n[12]=h,n[13]=v):(r=n[1],a=n[2],i=n[3],o=n[4],c=n[5],d=n[6],p=n[7],m=n[8],u=n[9],f=n[10],b=n[11],h=n[12],v=n[13]);const x=u===void 0?-1/0:u,g=f===void 0?1/0:f,w=b===void 0?1:b,y=h===void 0?"—":h,{t:k}=pt();let A;n[14]!==v?(A=()=>v===void 0?"":String(v),n[14]=v,n[15]=A):A=n[15];const[j,S]=$e.useState(A),{isMobile:D}=nn(),E=$e.useRef(!1),P=$e.useRef(null);let C;n[16]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{if(typeof document>"u"||typeof window>"u")return;P.current?.();const Ie=Ee=>{Ee.preventDefault(),Ee.stopPropagation(),Ee.stopImmediatePropagation?.(),P.current?.()},he=window.setTimeout(()=>{P.current?.()},700),me=()=>{window.clearTimeout(he),document.removeEventListener("click",Ie,!0),P.current=null};P.current=me,document.addEventListener("click",Ie,!0)},n[16]=C):C=n[16];const N=C;let T,M;n[17]===Symbol.for("react.memo_cache_sentinel")?(T=()=>()=>{P.current?.()},M=[],n[17]=T,n[18]=M):(T=n[17],M=n[18]),$e.useEffect(T,M);let F,_;n[19]!==v?(_=()=>{S(v===void 0?"":String(v))},F=[v],n[19]=v,n[20]=F,n[21]=_):(F=n[20],_=n[21]),$e.useEffect(_,F);let B;e:{if(v!==void 0){B=v;break e}if(o!==void 0){B=o;break e}if(Number.isFinite(x)){B=x;break e}B=0}const V=B;let $;n[22]!==g||n[23]!==x||n[24]!==p||n[25]!==w?($=Ie=>{const he=sp(Ie,x,g);p(np(he,w))},n[22]=g,n[23]=x,n[24]=p,n[25]=w,n[26]=$):$=n[26];const z=$;let Q;n[27]!==z||n[28]!==d?(Q=Ie=>{const he=Ie.target.value;if(S(he),he.trim()===""){d?.();return}const me=Number(he);Number.isFinite(me)&&z(me)},n[27]=z,n[28]=d,n[29]=Q):Q=n[29];const L=Q;let J;n[30]!==j||n[31]!==g||n[32]!==x||n[33]!==c||n[34]!==d||n[35]!==p||n[36]!==w||n[37]!==v?(J=Ie=>{if(j.trim()===""){d||S(v===void 0?"":String(v)),c?.(Ie);return}const he=Number(j);if(!Number.isFinite(he))S(v===void 0?"":String(v));else{const me=sp(he,x,g),Ee=np(me,w);Ee!==v&&p(Ee),S(String(Ee))}c?.(Ie)},n[30]=j,n[31]=g,n[32]=x,n[33]=c,n[34]=d,n[35]=p,n[36]=w,n[37]=v,n[38]=J):J=n[38];const ee=J,re=!!(i||V>=g),q=!!(i||V<=x);let ce;n[39]!==V||n[40]!==z||n[41]!==q||n[42]!==w?(ce=()=>{q||z(V-w)},n[39]=V,n[40]=z,n[41]=q,n[42]=w,n[43]=ce):ce=n[43];const ae=ce;let R;n[44]!==V||n[45]!==z||n[46]!==re||n[47]!==w?(R=()=>{re||z(V+w)},n[44]=V,n[45]=z,n[46]=re,n[47]=w,n[48]=R):R=n[48];const U=R;let W;if(n[49]!==r||n[50]!==a||n[51]!==q||n[52]!==j||n[53]!==y||n[54]!==ae||n[55]!==U||n[56]!==re||n[57]!==D||n[58]!==k||n[59]!==v){W=Symbol.for("react.early_return_sentinel");e:{const Ie=me=>Ee=>{Ee.preventDefault(),Ee.stopPropagation(),E.current=!0,N(),me()},he=me=>Ee=>{if(E.current){E.current=!1,Ee.preventDefault(),Ee.stopPropagation();return}me()};if(D){let me;n[61]!==a?(me=ue("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",a),n[61]=a,n[62]=me):me=n[62];let Ee;n[63]!==k?(Ee=k("numberInput.actions.decreaseAria"),n[63]=k,n[64]=Ee):Ee=n[64];const Ve=Ie(ae),Y=he(ae),ke=!q&&"active:bg-interactive-hover";let Be;n[65]!==ke?(Be=ue("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",ke),n[65]=ke,n[66]=Be):Be=n[66];let Ce;n[67]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(I,{name:"subtract",className:"block h-4 w-4"}),n[67]=Ce):Ce=n[67];const ge=s.jsx("button",{type:"button","aria-label":Ee,disabled:q,onTouchStart:Ve,onClick:Y,className:Be,children:Ce});let O;n[68]!==r?(O=ue("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",r),n[68]=r,n[69]=O):O=n[69];const X=v===void 0?y:j;let G;n[70]!==O||n[71]!==X?(G=s.jsx("div",{className:O,"aria-live":"polite",children:X}),n[70]=O,n[71]=X,n[72]=G):G=n[72];let Te;n[73]!==k?(Te=k("numberInput.actions.increaseAria"),n[73]=k,n[74]=Te):Te=n[74];const le=Ie(U),We=he(U),de=!re&&"active:bg-interactive-hover";let Fe;n[75]!==de?(Fe=ue("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",de),n[75]=de,n[76]=Fe):Fe=n[76];let rt;n[77]===Symbol.for("react.memo_cache_sentinel")?(rt=s.jsx(I,{name:"add",className:"block h-4 w-4"}),n[77]=rt):rt=n[77];const Oe=s.jsx("button",{type:"button","aria-label":Te,disabled:re,onTouchStart:le,onClick:We,className:Fe,children:rt});let Ye;n[78]!==me||n[79]!==ge||n[80]!==G||n[81]!==Oe?(Ye=s.jsxs("div",{className:me,children:[ge,G,Oe]}),n[78]=me,n[79]=ge,n[80]=G,n[81]=Oe,n[82]=Ye):Ye=n[82],W=Ye;break e}}n[49]=r,n[50]=a,n[51]=q,n[52]=j,n[53]=y,n[54]=ae,n[55]=U,n[56]=re,n[57]=D,n[58]=k,n[59]=v,n[60]=W}else W=n[60];if(W!==Symbol.for("react.early_return_sentinel"))return W;let Z;n[83]!==a?(Z=ue("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",a),n[83]=a,n[84]=Z):Z=n[84];let K;n[85]!==k?(K=k("numberInput.actions.decreaseAria"),n[85]=k,n[86]=K):K=n[86];let ie;n[87]!==V||n[88]!==z||n[89]!==w?(ie=()=>z(V-w),n[87]=V,n[88]=z,n[89]=w,n[90]=ie):ie=n[90];let Ne,ne;n[91]===Symbol.for("react.memo_cache_sentinel")?(Ne=ue("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),ne=s.jsx(I,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=Ne,n[92]=ne):(Ne=n[91],ne=n[92]);let fe;n[93]!==q||n[94]!==K||n[95]!==ie?(fe=s.jsx("button",{type:"button","aria-label":K,disabled:q,onClick:ie,className:Ne,children:ne}),n[93]=q,n[94]=K,n[95]=ie,n[96]=fe):fe=n[96];const pe=m.inputMode??"numeric";let je;n[97]!==r?(je=ue("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",r),n[97]=r,n[98]=je):je=n[98];let oe;n[99]!==i||n[100]!==j||n[101]!==ee||n[102]!==L||n[103]!==m||n[104]!==e||n[105]!==pe||n[106]!==je?(oe=s.jsx("input",{...m,ref:e,type:"text",inputMode:pe,value:j,onChange:L,onBlur:ee,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:je}),n[99]=i,n[100]=j,n[101]=ee,n[102]=L,n[103]=m,n[104]=e,n[105]=pe,n[106]=je,n[107]=oe):oe=n[107];let Se;n[108]!==k?(Se=k("numberInput.actions.increaseAria"),n[108]=k,n[109]=Se):Se=n[109];let se;n[110]!==V||n[111]!==z||n[112]!==w?(se=()=>z(V+w),n[110]=V,n[111]=z,n[112]=w,n[113]=se):se=n[113];let we,Ae;n[114]===Symbol.for("react.memo_cache_sentinel")?(we=ue("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Ae=s.jsx(I,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=we,n[115]=Ae):(we=n[114],Ae=n[115]);let ve;n[116]!==re||n[117]!==Se||n[118]!==se?(ve=s.jsx("button",{type:"button","aria-label":Se,disabled:re,onClick:se,className:we,children:Ae}),n[116]=re,n[117]=Se,n[118]=se,n[119]=ve):ve=n[119];let ye;return n[120]!==Z||n[121]!==fe||n[122]!==oe||n[123]!==ve?(ye=s.jsxs("div",{className:Z,children:[fe,oe,ve]}),n[120]=Z,n[121]=fe,n[122]=oe,n[123]=ve,n[124]=ye):ye=n[124],ye});Fn.displayName="NumberInput";const rp=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Qo=t=>t==="allow"||t==="ask"||t==="deny",Sa=(t,e)=>`${t}::${e}`,Ba=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&Qo(n.action)&&e.set(Sa(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},To=t=>{const e=new Map;for(const n of Ba(t))e.set(Sa(n.permission,n.pattern),n);return e},ap=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),US=(t,e)=>{const n=ap(Ba(t)),r=ap(Ba(e));return n.length!==r.length?!1:n.every((a,i)=>{const o=r[i];return a.permission===o.permission&&a.pattern===o.pattern&&a.action===o.action})},WS=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",KS=(t,e)=>Ba(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),HS=t=>{if(Qo(t))return[{permission:"*",pattern:"*",action:t}];if(!t||typeof t!="object"||Array.isArray(t))return[];const e=[];for(const[n,r]of Object.entries(t))if(n!=="__originalKeys"){if(Qo(r)){e.push({permission:n,pattern:"*",action:r});continue}if(r&&typeof r=="object"&&!Array.isArray(r))for(const[a,i]of Object.entries(r))Qo(i)&&e.push({permission:n,pattern:a,action:i})}return e},GS=(t,e)=>{const n=Ba(e),r={};for(const i of n)(r[i.permission]||={})[i.pattern]=i.action;const a={"*":t};for(const[i,o]of Object.entries(r))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){a[i]=o["*"];continue}a[i]=o}return a},qS=()=>{const{t}=pt(),{isMobile:e}=nn(),{selectedAgentName:n,getAgentByName:r,createAgent:a,updateAgent:i,agents:o,agentDraft:c,setAgentDraft:d}=di(hr(me=>({selectedAgentName:me.selectedAgentName,getAgentByName:me.getAgentByName,createAgent:me.createAgent,updateAgent:me.updateAgent,agents:me.agents,agentDraft:me.agentDraft,setAgentDraft:me.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,f]=l.useState(""),[b,h]=l.useState("user"),[v,x]=l.useState(""),[g,w]=l.useState("subagent"),[y,k]=l.useState(""),[A,j]=l.useState(void 0),[S,D]=l.useState(void 0),[E,P]=l.useState(""),[C,N]=l.useState("allow"),[T,M]=l.useState([]),[F,_]=l.useState([]),[B,V]=l.useState(""),[$,z]=l.useState("*"),[Q,L]=l.useState(!1),[J,ee]=l.useState(!1),re=l.useRef(null),q=_s(me=>me.currentDirectory??null),[ce,ae]=l.useState([]),R=th(me=>me.permission);l.useEffect(()=>{let me=!1;return(async()=>{const Ve=await en.listToolIds({directory:q});if(me)return;const Y=new Set(["write","patch","multiedit"]),ke=Ve.map(Be=>typeof Be=="string"?Be.trim():"").filter(Boolean).filter(Be=>Be!=="*").filter(Be=>Be!=="invalid").filter(Be=>!Y.has(Be));ae(Array.from(new Set(ke)).sort((Be,Ce)=>Be.localeCompare(Ce)))})(),()=>{me=!0}},[q]);const U=l.useMemo(()=>{const me=new Set;for(const Ee of o){const Ve=Ba(Array.isArray(Ee.permission)?Ee.permission:[]);for(const Y of Ve)Y.permission&&Y.permission!=="*"&&Y.permission!=="invalid"&&me.add(Y.permission)}for(const Ee of Object.values(R))for(const Ve of Ee){const Y=Ve.permission?.trim();Y&&Y!=="invalid"&&me.add(Y)}for(const Ee of ce)me.add(Ee);return Array.from(me).sort((Ee,Ve)=>Ee.localeCompare(Ve))},[o,R,ce]),W=l.useMemo(()=>To(T),[T]),Z=l.useMemo(()=>To(F),[F]),K=l.useCallback(me=>Z.get(Sa(me,"*"))?.action,[Z]),ie=l.useCallback(me=>F.filter(Ee=>Ee.permission===me&&Ee.pattern!=="*").sort((Ee,Ve)=>Ee.pattern.localeCompare(Ve.pattern)),[F]),Ne=l.useMemo(()=>{const me=new Set;for(const Ee of rp)me.add(Ee);for(const Ee of U)me.add(Ee);return Array.from(me).sort((Ee,Ve)=>Ee.localeCompare(Ve))},[U]),ne=l.useCallback(me=>{const Ee=me==="*"?C:K(me)??C,Ve=ie(me),Y=!1,ke=Ve.reduce((Ce,ge)=>(Ce[ge.action]=(Ce[ge.action]??0)+1,Ce),{allow:0,ask:0,deny:0}),Be=["allow","ask","deny"].filter(Ce=>ke[Ce]>0).map(Ce=>`${ke[Ce]} ${Ce}`).join(", ");return{defaultAction:Ee,patternRulesCount:Ve.length,patternSummary:Be,hasDefaultHint:Y}},[ie,K,C]),fe=l.useCallback(me=>t(me==="allow"?"settings.common.permission.allow":me==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),pe=l.useCallback(me=>me==="global"?t("settings.common.scope.global"):fe(me),[fe,t]),je=l.useMemo(()=>{const me=new Set;for(const Ee of rp)me.add(Ee);for(const Ee of U)me.add(Ee);return Array.from(me).sort((Ee,Ve)=>Ee.localeCompare(Ve))},[U]),oe=l.useCallback((me,Ee,Ve)=>{_(Y=>{const ke=To(Y);return ke.set(Sa(me,Ee),{permission:me,pattern:Ee,action:Ve}),Array.from(ke.values())})},[]),Se=l.useCallback((me,Ee)=>{_(Ve=>{const Y=To(Ve);return Y.delete(Sa(me,Ee)),Array.from(Y.values())})},[]),se=l.useCallback((me,Ee)=>{const Ve=W.get(Sa(me,Ee));if(Ve){oe(me,Ee,Ve.action);return}Se(me,Ee)},[W,Se,oe]),we=l.useCallback((me,Ee,Ve)=>{oe(me,Ee,Ve)},[oe]),Ae=l.useCallback(me=>{N(me),_(Ee=>Ee.filter(Ve=>!(Ve.pattern==="*"&&Ve.action===me)))},[]),ve=l.useCallback(me=>{const Ee=B.trim();if(!Ee){H.error(t("settings.agents.page.toast.permissionNameRequired"));return}const Ve=$.trim()||"*";if(Ee==="*"&&Ve==="*"){Ae(me),V(""),z("*");return}Ve==="*"&&Ee!=="*"&&me===C?Se(Ee,"*"):oe(Ee,Ve,me),V(""),z("*")},[C,B,$,Se,Ae,t,oe]),ye=l.useCallback(me=>me==="*"?t("settings.agents.page.permissions.defaultLabel"):me==="webfetch"?"WebFetch":me==="websearch"?"WebSearch":me==="codesearch"?"CodeSearch":me==="doom_loop"?"Doom Loop":me==="external_directory"?"External Directory":me==="todowrite"?"TodoWrite":me==="todoread"?"TodoRead":me.split(/[_-]+/g).filter(Boolean).map(Ee=>Ee.charAt(0).toUpperCase()+Ee.slice(1)).join(" "),[t]);l.useEffect(()=>{V(""),z("*");const me=Ee=>{const Ve=Ba(Ee),Y=WS(Ve),ke=KS(Ve,Y);return N(Y),M(ke),_(ke),{global:Y,rules:ke}};if(m&&c){const Ee=c.name||"",Ve=c.scope||"user",Y=c.description||"",ke=c.mode||"subagent",Be=c.model||"",Ce=c.temperature,ge=c.top_p,O=c.prompt||"";f(Ee),h(Ve),x(Y),w(ke),k(Be),j(Ce),D(ge),P(O);const X=HS(c.permission),G=me(X);re.current={draftName:Ee,draftScope:Ve,description:Y,mode:ke,model:Be,temperature:Ce,topP:ge,prompt:O,globalPermission:G.global,permissionRules:G.rules};return}if(p&&n===p.name){const Ee=p.description||"",Ve=p.mode||"subagent",Y=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",ke=p.temperature,Be=p.topP,Ce=p.prompt||"";x(Ee),w(Ve),k(Y),j(ke),D(Be),P(Ce);const ge=me(Array.isArray(p.permission)?p.permission:[]);re.current={draftName:"",draftScope:"user",description:Ee,mode:Ve,model:Y,temperature:ke,topP:Be,prompt:Ce,globalPermission:ge.global,permissionRules:ge.rules}}},[c,m,p,n]);const Ie=l.useMemo(()=>{const me=re.current;return me?!!(m&&(u!==me.draftName||b!==me.draftScope)||v!==me.description||g!==me.mode||y!==me.model||A!==me.temperature||S!==me.topP||E!==me.prompt||C!==me.globalPermission||!US(F,me.permissionRules)):!1},[v,u,b,C,m,g,y,F,E,A,S]),he=async()=>{const me=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!me){H.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(Ee=>Ee.name===me)){H.error(t("settings.agents.sidebar.toast.agentExists"));return}ee(!0);try{const Ee=y.trim(),Ve=GS(C,F),Y={name:me,description:v.trim()||void 0,mode:g,model:Ee===""?null:Ee,temperature:A,top_p:S,prompt:E.trim()||void 0,permission:Ve,scope:m?b:void 0};let ke;m?(ke=await a(Y),ke&&d(null)):ke=await i(me,Y),ke?H.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):H.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(Ee){console.error("Error saving agent:",Ee);const Ve=Ee instanceof Error&&Ee.message?Ee.message:t("settings.agents.page.toast.saveUnexpectedError");H.error(Ve)}finally{ee(!1)}};return n?s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:m?t("settings.agents.page.title.new"):n}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(m?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.identityRole")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[m&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.agentName")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(Vt,{value:u,onChange:me=>f(me.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(is,{value:b,onValueChange:me=>h(me),children:[s.jsx(os,{className:"w-fit min-w-[100px]",children:s.jsx(us,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(ls,{align:"end",children:[s.jsx(Ft,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ft,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(fn,{value:v,onChange:me=>x(me.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.mode")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.modeTooltip")})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":g==="primary",onClick:()=>w("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":g==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":g==="all",onClick:()=>w("all"),className:"!font-normal",children:t("settings.agents.page.mode.all")})]})]})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.modelParameters")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(mo,{providerId:hi(y)?.providerId??"",modelId:hi(y)?.modelId??"",onChange:(me,Ee)=>{k(me&&Ee?`${me}/${Ee}`:"")}})})]}),s.jsxs("div",{className:ue("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:ue("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.temperature")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.temperatureTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.temperatureRange")})]}),s.jsxs("div",{className:ue("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(Fn,{value:A,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),A!==void 0&&s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:ue("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:ue("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.topP")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.topPTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.topPRange")})]}),s.jsxs("div",{className:ue("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(Fn,{value:S,fallbackValue:.9,onValueChange:D,onClear:()=>D(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),S!==void 0&&s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>D(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.systemPrompt")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(fn,{value:E,onChange:me=>P(me.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.toolPermissions")}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>L(me=>!me),children:t(Q?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),Q?s.jsxs("div",{className:"space-y-6 px-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.permissions.globalDefault")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),s.jsxs(is,{value:C,onValueChange:me=>Ae(me),children:[s.jsx(os,{className:"w-[100px]",children:s.jsx(us,{children:fe(C)})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Ft,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Ft,{value:"deny",children:t("settings.common.permission.deny")})]})]})]}),s.jsx("div",{className:"space-y-4",children:Ne.filter(me=>me!=="*").map(me=>{const Ee=ye(me),{defaultAction:Ve,patternRulesCount:Y}=ne(me),ke=K(me),Be=ke??"global",Ce=ie(me),ge=["allow","ask","deny"].filter(O=>O!==C);return s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[s.jsxs("div",{className:"flex items-center justify-between py-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Ee}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:me})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:Y>0?t("settings.agents.page.permissions.globalSummary",{summary:Ve}):Ve})]}),s.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),ke&&s.jsx(xe,{size:"sm",variant:"ghost",onClick:()=>se(me,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(I,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(is,{value:Be,onValueChange:O=>{if(O==="global"){Se(me,"*");return}oe(me,"*",O)},children:[s.jsx(os,{className:"w-[90px]",children:s.jsx(us,{children:pe(Be)})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"global",children:t("settings.common.scope.global")}),ge.map(O=>s.jsx(Ft,{value:O,className:"capitalize",children:fe(O)},O))]})]})]}),Ce.map(O=>{const X=Sa(O.permission,O.pattern),G=W.get(X),Te=!G,le=!!(G&&G.action!==O.action);return s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:O.pattern}),Te&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),le&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(Te||le)&&s.jsx(xe,{size:"sm",variant:"ghost",onClick:()=>Te?Se(O.permission,O.pattern):se(O.permission,O.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(I,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(is,{value:O.action,onValueChange:We=>we(O.permission,O.pattern,We),children:[s.jsx(os,{className:"w-[90px]",children:s.jsx(us,{children:fe(O.action)})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Ft,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Ft,{value:"deny",children:t("settings.common.permission.deny")})]})]})]},X)})]})]},me)})}),s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[s.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:t("settings.agents.page.permissions.addCustomRule")}),s.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[s.jsxs(is,{value:B,onValueChange:V,children:[s.jsx(os,{className:"w-full sm:w-[160px]",children:B?s.jsx("span",{className:"truncate",children:ye(B)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(ls,{children:je.map(me=>s.jsx(Ft,{value:me,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:ye(me)})})},me))})]}),s.jsx(Vt,{value:$,onChange:me=>z(me.target.value),placeholder:t("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),s.jsxs("div",{className:"flex gap-1",children:[s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ve("allow"),children:t("settings.common.permission.allow")}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ve("ask"),children:t("settings.common.permission.ask")}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ve("deny"),children:t("settings.common.permission.deny")})]})]})]})]}):s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:Ne.map((me,Ee)=>{const{defaultAction:Ve,patternRulesCount:Y,patternSummary:ke,hasDefaultHint:Be}=ne(me),Ce=ye(me),ge=Be?`${Ve} (env blocked)`:Ve;return s.jsxs("div",{className:ue("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",Ee>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Ce}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:me})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[Y>0?s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.globalSummary",{summary:ge})}):s.jsx("span",{className:ue("typography-micro capitalize px-1.5 py-0.5 rounded",ge==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":ge==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:ge}),Y>0&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.rulesSummary",{summary:ke})})]})]},me)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(xe,{onClick:he,disabled:J||!Ie,size:"xs",className:"!font-normal",children:t(J?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},YS="~/.config/opencode/AGENTS.md",dg=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},JS=t=>t.length>0&&!t.endsWith(`
|
|
155
|
-
`)?`${t}
|
|
156
|
-
`:t,Mo={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},QS=(t,e)=>t==="custom"?e:Mb(t),XS=t=>t==="custom"?"custom":sh(t)?t:"concise",ip={concise:"settings.behavior.page.responseStyle.option.concise",detailed:"settings.behavior.page.responseStyle.option.detailed",mentor:"settings.behavior.page.responseStyle.option.mentor",pushback:"settings.behavior.page.responseStyle.option.pushback",noFiller:"settings.behavior.page.responseStyle.option.noFiller",matchEnergy:"settings.behavior.page.responseStyle.option.matchEnergy",warmPeer:"settings.behavior.page.responseStyle.option.warmPeer"},op=async(t,e)=>{const n=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(await dg(n,e))},ZS=()=>{const{t}=pt(),[e,n]=l.useState(""),[r,a]=l.useState(Mo.responseStyleEnabled),[i,o]=l.useState(Mo.responseStylePreset),[c,d]=l.useState(Mo.responseStyleCustomInstructions),[p,m]=l.useState(!0),[u,f]=l.useState(!1),[b,h]=l.useState(""),v=l.useRef(null);l.useEffect(()=>{const y=new AbortController;return(async()=>{try{const[A,j]=await Promise.all([fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:y.signal}),fetch("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:y.signal})]);let S=Mo;if(A.ok){const D=await A.json();S={...S,responseStyleEnabled:D.responseStyleEnabled===!0,responseStylePreset:XS(D.responseStylePreset),responseStyleCustomInstructions:typeof D.responseStyleCustomInstructions=="string"?D.responseStyleCustomInstructions:""},typeof D.globalBehaviorPrompt=="string"&&(S={...S,prompt:D.globalBehaviorPrompt})}if(!S.prompt.trim()&&j.ok){const D=await j.json();typeof D.content=="string"&&(S={...S,prompt:D.content})}n(S.prompt),a(S.responseStyleEnabled),o(S.responseStylePreset),d(S.responseStyleCustomInstructions),h(S.prompt),v.current={enabled:S.responseStyleEnabled,preset:S.responseStylePreset,custom:S.responseStyleCustomInstructions}}catch(A){A.name!=="AbortError"&&console.warn("Failed to load behavior settings:",A)}finally{m(!1)}})(),()=>y.abort()},[]),l.useEffect(()=>{if(p)return;const y=v.current;if(y&&y.enabled===r&&y.preset===i&&y.custom===c)return;const k={enabled:r,preset:i,custom:c},A=setTimeout(async()=>{try{await op({responseStyleEnabled:k.enabled,responseStylePreset:k.preset,responseStyleCustomInstructions:k.custom},t("settings.behavior.page.toast.saveFailed")),v.current=k}catch(j){const S=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");H.error(S)}},400);return()=>clearTimeout(A)},[r,i,c,p,t]);const x=QS(i,c),g=e!==b,w=async()=>{f(!0);try{const y=JS(e),k=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:y})});if(!k.ok)throw new Error(await dg(k,t("settings.behavior.page.toast.saveFailed")));await op({globalBehaviorPrompt:y},t("settings.behavior.page.toast.saveFailed")),n(y),h(y),H.success(t("settings.behavior.page.toast.saved"))}catch(y){console.error("Failed to save behavior:",y);const k=y instanceof Error?y.message:t("settings.behavior.page.toast.saveFailed");H.error(k)}finally{f(!1)}};return s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8 space-y-6",children:[s.jsx("div",{className:"space-y-1",children:s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.behavior.page.title")})}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.systemPrompt")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:YS})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(fn,{value:e,onChange:y=>n(y.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(xe,{onClick:w,disabled:u||!g||p,size:"xs",className:"!font-normal",children:t(u?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.responseStyle")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.behavior.page.responseStyle.tooltip")})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[s.jsx(ds,{checked:r,onChange:a,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(is,{value:i,onValueChange:y=>o(y),disabled:p||!r,children:[s.jsx(os,{className:"w-full sm:w-56",size:"lg",children:s.jsx(us,{children:y=>y==="custom"?t("settings.behavior.page.responseStyle.option.custom"):sh(y)?t(ip[y]):null})}),s.jsxs(ls,{children:[Tb.map(y=>s.jsx(Ft,{value:y,children:t(ip[y])},y)),s.jsx(Ft,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(fn,{value:x,onChange:y=>d(y.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!r||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},ek=t=>{const e=ot.c(169),{onItemSelect:n}=t,{t:r}=pt(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(!1),[h,v]=l.useState(null),{selectedCommandName:x,commands:g,setSelectedCommand:w,setCommandDraft:y,createCommand:k,deleteCommand:A,loadCommands:j}=_d(hr(tk)),S=ra(sk),D=ra(nk);let E,P;e[0]!==j||e[1]!==D?(E=()=>{j(),D()},P=[j,D],e[0]=j,e[1]=D,e[2]=E,e[3]=P):(E=e[2],P=e[3]),l.useEffect(E,P);let C;e[4]!==S?(C=new Set(S.map(rk)),e[4]=S,e[5]=C):C=e[5];const N=C;let T;if(e[6]!==g||e[7]!==N){let _e;e[9]!==N?(_e=tt=>!N.has(tt.name),e[9]=N,e[10]=_e):_e=e[10],T=g.filter(_e),e[6]=g,e[7]=N,e[8]=T}else T=e[8];const M=T;let F,_;e[11]!==x||e[12]!==w||e[13]!==N?(F=()=>{x&&N.has(x)&&w(null)},_=[x,w,N],e[11]=x,e[12]=w,e[13]=N,e[14]=F,e[15]=_):(F=e[14],_=e[15]),l.useEffect(F,_);let B;e[16]!==g||e[17]!==n||e[18]!==y||e[19]!==w?(B=()=>{let _e="new-command",tt=1;for(;g.some(ut=>ut.name===_e);)_e=`new-command-${tt}`,tt++;y({name:_e,scope:"user"}),w(_e),n?.()},e[16]=g,e[17]=n,e[18]=y,e[19]=w,e[20]=B):B=e[20];const V=B;let $;e[21]!==r?($=async _e=>{if(ri(_e)){H.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p(_e),u("delete")},e[21]=r,e[22]=$):$=e[22];const z=$;let Q;e[23]===Symbol.for("react.memo_cache_sentinel")?(Q=async _e=>{ri(_e)&&(p(_e),u("reset"))},e[23]=Q):Q=e[23];const L=Q;let J;e[24]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{p(null),u(null)},e[24]=J):J=e[24];const ee=J;let re;e[25]!==d||e[26]!==m||e[27]!==A||e[28]!==r?(re=async()=>{if(!d||!m)return;b(!0),await A(d.name)?(m==="delete"?H.success(r("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):H.success(r("settings.commands.sidebar.toast.commandReset",{name:d.name})),ee()):m==="delete"?H.error(r("settings.commands.sidebar.toast.deleteFailed")):H.error(r("settings.commands.sidebar.toast.resetFailed")),b(!1)},e[25]=d,e[26]=m,e[27]=A,e[28]=r,e[29]=re):re=e[29];const q=re;let ce;e[30]!==g||e[31]!==y||e[32]!==w?(ce=_e=>{const tt=_e.name;let ut=1,qe=`${tt}-copy`;for(;g.some(ze=>ze.name===qe);)ut++,qe=`${tt}-copy-${ut}`;y({name:qe,scope:_e.scope||"user",description:_e.description,template:_e.template,agent:_e.agent,model:_e.model}),w(qe)},e[30]=g,e[31]=y,e[32]=w,e[33]=ce):ce=e[33];const ae=ce;let R;e[34]===Symbol.for("react.memo_cache_sentinel")?(R=_e=>{c(_e.name),i(_e)},e[34]=R):R=e[34];const U=R;let W;e[35]!==g||e[36]!==k||e[37]!==A||e[38]!==a||e[39]!==o||e[40]!==w||e[41]!==r?(W=async()=>{if(!a)return;const _e=o.trim().replace(/\s+/g,"-");if(!_e){H.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if(_e===a.name){i(null);return}if(g.some(ut=>ut.name===_e)){H.error(r("settings.commands.sidebar.toast.commandExists"));return}await k({name:_e,description:a.description,template:a.template,agent:a.agent,model:a.model})?await A(a.name)?(H.success(`Command renamed to "${_e}"`),w(_e)):H.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):H.error(r("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=g,e[36]=k,e[37]=A,e[38]=a,e[39]=o,e[40]=w,e[41]=r,e[42]=W):W=e[42];const Z=W;let K,ie,Ne,ne,fe,pe;if(e[43]!==M||e[44]!==V||e[45]!==z||e[46]!==ae||e[47]!==n||e[48]!==h||e[49]!==x||e[50]!==w||e[51]!==r){const _e=M.filter(ri),tt=M.filter(ak);e[58]===Symbol.for("react.memo_cache_sentinel")?(fe=ue("flex h-full flex-col","bg-background"),e[58]=fe):fe=e[58];let ut;e[59]!==r?(ut=r("settings.commands.sidebar.title"),e[59]=r,e[60]=ut):ut=e[60];let qe;e[61]!==ut?(qe=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:ut}),e[61]=ut,e[62]=qe):qe=e[62];let ze;e[63]===Symbol.for("react.memo_cache_sentinel")?(ze=s.jsx(po,{className:"mb-3"}),e[63]=ze):ze=e[63];let st;e[64]!==M.length||e[65]!==r?(st=r("settings.commands.sidebar.total",{count:M.length}),e[64]=M.length,e[65]=r,e[66]=st):st=e[66];let yt;e[67]!==st?(yt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:st}),e[67]=st,e[68]=yt):yt=e[68];let Mt;e[69]===Symbol.for("react.memo_cache_sentinel")?(Mt=s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e[69]=Mt):Mt=e[69];let Bt;e[70]!==V?(Bt=s.jsx(xe,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:V,children:Mt}),e[70]=V,e[71]=Bt):Bt=e[71];let ft;e[72]!==yt||e[73]!==Bt?(ft=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[yt,Bt]}),e[72]=yt,e[73]=Bt,e[74]=ft):ft=e[74],e[75]!==qe||e[76]!==ft?(pe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[qe,ze,ft]}),e[75]=qe,e[76]=ft,e[77]=pe):pe=e[77],K=Ns,ie="flex-1 min-h-0",Ne="space-y-1 px-3 py-2",ne=M.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[_e.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.builtIn")}),[..._e].sort(ik).map(It=>s.jsx(lp,{command:It,isSelected:x===It.name,onSelect:()=>{w(It.name),n?.()},onReset:()=>L(It),onDuplicate:()=>ae(It),isMenuOpen:h===It.name,onMenuOpenChange:ss=>v(ss?It.name:null)},It.name))]}),tt.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.custom")}),[...tt].sort(ok).map(It=>s.jsx(lp,{command:It,isSelected:x===It.name,onSelect:()=>{w(It.name),n?.()},onRename:()=>U(It),onDelete:()=>z(It),onDuplicate:()=>ae(It),isMenuOpen:h===It.name,onMenuOpenChange:ss=>v(ss?It.name:null)},It.name))]})]}),e[43]=M,e[44]=V,e[45]=z,e[46]=ae,e[47]=n,e[48]=h,e[49]=x,e[50]=w,e[51]=r,e[52]=K,e[53]=ie,e[54]=Ne,e[55]=ne,e[56]=fe,e[57]=pe}else K=e[52],ie=e[53],Ne=e[54],ne=e[55],fe=e[56],pe=e[57];let je;e[78]!==K||e[79]!==ie||e[80]!==Ne||e[81]!==ne?(je=s.jsx(K,{outerClassName:ie,className:Ne,children:ne}),e[78]=K,e[79]=ie,e[80]=Ne,e[81]=ne,e[82]=je):je=e[82];const oe=d!==null&&m!==null;let Se;e[83]!==f?(Se=_e=>{!_e&&!f&&ee()},e[83]=f,e[84]=Se):Se=e[84];let se;e[85]!==m||e[86]!==r?(se=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=se):se=e[87];let we;e[88]!==se?(we=s.jsx(gs,{children:se}),e[88]=se,e[89]=we):we=e[89];let Ae;e[90]!==d?.name||e[91]!==m||e[92]!==r?(Ae=m==="delete"?r("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):r("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[90]=d?.name,e[91]=m,e[92]=r,e[93]=Ae):Ae=e[93];let ve;e[94]!==Ae?(ve=s.jsx(Ps,{children:Ae}),e[94]=Ae,e[95]=ve):ve=e[95];let ye;e[96]!==we||e[97]!==ve?(ye=s.jsxs(vs,{children:[we,ve]}),e[96]=we,e[97]=ve,e[98]=ye):ye=e[98];let Ie;e[99]!==r?(Ie=r("settings.common.actions.cancel"),e[99]=r,e[100]=Ie):Ie=e[100];let he;e[101]!==f||e[102]!==Ie?(he=s.jsx(xe,{size:"sm",variant:"ghost",onClick:ee,disabled:f,children:Ie}),e[101]=f,e[102]=Ie,e[103]=he):he=e[103];let me;e[104]!==m||e[105]!==r?(me=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=me):me=e[106];let Ee;e[107]!==q||e[108]!==f||e[109]!==me?(Ee=s.jsx(xe,{size:"sm",onClick:q,disabled:f,children:me}),e[107]=q,e[108]=f,e[109]=me,e[110]=Ee):Ee=e[110];let Ve;e[111]!==he||e[112]!==Ee?(Ve=s.jsxs(Us,{children:[he,Ee]}),e[111]=he,e[112]=Ee,e[113]=Ve):Ve=e[113];let Y;e[114]!==ye||e[115]!==Ve?(Y=s.jsxs(ms,{className:"max-w-md",children:[ye,Ve]}),e[114]=ye,e[115]=Ve,e[116]=Y):Y=e[116];let ke;e[117]!==oe||e[118]!==Se||e[119]!==Y?(ke=s.jsx(ps,{open:oe,onOpenChange:Se,children:Y}),e[117]=oe,e[118]=Se,e[119]=Y,e[120]=ke):ke=e[120];const Be=a!==null;let Ce;e[121]===Symbol.for("react.memo_cache_sentinel")?(Ce=_e=>!_e&&i(null),e[121]=Ce):Ce=e[121];let ge;e[122]!==r?(ge=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=ge):ge=e[123];let O;e[124]!==ge?(O=s.jsx(gs,{children:ge}),e[124]=ge,e[125]=O):O=e[125];const X=a?.name??"";let G;e[126]!==r||e[127]!==X?(G=r("settings.commands.sidebar.renameDialog.description",{name:X}),e[126]=r,e[127]=X,e[128]=G):G=e[128];let Te;e[129]!==G?(Te=s.jsx(Ps,{children:G}),e[129]=G,e[130]=Te):Te=e[130];let le;e[131]!==O||e[132]!==Te?(le=s.jsxs(vs,{children:[O,Te]}),e[131]=O,e[132]=Te,e[133]=le):le=e[133];let We;e[134]===Symbol.for("react.memo_cache_sentinel")?(We=_e=>c(_e.target.value),e[134]=We):We=e[134];let de;e[135]!==r?(de=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=de):de=e[136];let Fe;e[137]!==Z?(Fe=_e=>{_e.key==="Enter"&&Z()},e[137]=Z,e[138]=Fe):Fe=e[138];let rt;e[139]!==o||e[140]!==de||e[141]!==Fe?(rt=s.jsx(Vt,{value:o,onChange:We,placeholder:de,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Fe}),e[139]=o,e[140]=de,e[141]=Fe,e[142]=rt):rt=e[142];let Oe;e[143]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>i(null),e[143]=Oe):Oe=e[143];let Ye;e[144]!==r?(Ye=r("settings.common.actions.cancel"),e[144]=r,e[145]=Ye):Ye=e[145];let Ge;e[146]!==Ye?(Ge=s.jsx(xe,{size:"sm",variant:"ghost",onClick:Oe,children:Ye}),e[146]=Ye,e[147]=Ge):Ge=e[147];let it;e[148]!==r?(it=r("settings.common.actions.rename"),e[148]=r,e[149]=it):it=e[149];let Qe;e[150]!==Z||e[151]!==it?(Qe=s.jsx(xe,{size:"sm",onClick:Z,children:it}),e[150]=Z,e[151]=it,e[152]=Qe):Qe=e[152];let at;e[153]!==Ge||e[154]!==Qe?(at=s.jsxs(Us,{children:[Ge,Qe]}),e[153]=Ge,e[154]=Qe,e[155]=at):at=e[155];let nt;e[156]!==le||e[157]!==rt||e[158]!==at?(nt=s.jsxs(ms,{children:[le,rt,at]}),e[156]=le,e[157]=rt,e[158]=at,e[159]=nt):nt=e[159];let be;e[160]!==Be||e[161]!==nt?(be=s.jsx(ps,{open:Be,onOpenChange:Ce,children:nt}),e[160]=Be,e[161]=nt,e[162]=be):be=e[162];let He;return e[163]!==fe||e[164]!==pe||e[165]!==je||e[166]!==ke||e[167]!==be?(He=s.jsxs("div",{className:fe,children:[pe,je,ke,be]}),e[163]=fe,e[164]=pe,e[165]=je,e[166]=ke,e[167]=be,e[168]=He):He=e[168],He},lp=t=>{const e=ot.c(53),{command:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=pt();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Qi(),e[0]=f):f=e[0];const b=f,h=r?"bg-interactive-selection":"hover:bg-interactive-hover";let v;e[1]!==h?(v=ue("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",h),e[1]=h,e[2]=v):v=e[2];let x;e[3]!==m?(x=b?void 0:V=>{V.preventDefault(),m(!0)},e[3]=m,e[4]=x):x=e[4];let g;e[5]!==n.name?(g=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[5]=n.name,e[6]=g):g=e[6];let w;e[7]!==n||e[8]!==u?(w=(n.scope||ri(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:ri(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=w):w=e[9];let y;e[10]!==g||e[11]!==w?(y=s.jsxs("div",{className:"flex items-center gap-2",children:[g,w]}),e[10]=g,e[11]=w,e[12]=y):y=e[12];let k;e[13]!==n.description?(k=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[13]=n.description,e[14]=k):k=e[14];let A;e[15]!==a||e[16]!==y||e[17]!==k?(A=s.jsxs("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[y,k]}),e[15]=a,e[16]=y,e[17]=k,e[18]=A):A=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Es,{asChild:!0,children:s.jsx(xe,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[19]=j):j=e[19];let S;e[20]!==c||e[21]!==u?(S=c&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),c()},children:[s.jsx(I,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=S):S=e[22];let D;e[23]!==d?(D=V=>{V.stopPropagation(),d()},e[23]=d,e[24]=D):D=e[24];let E;e[25]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(I,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[25]=E):E=e[25];let P;e[26]!==u?(P=u("settings.common.actions.duplicate"),e[26]=u,e[27]=P):P=e[27];let C;e[28]!==D||e[29]!==P?(C=s.jsxs($t,{onClick:D,children:[E,P]}),e[28]=D,e[29]=P,e[30]=C):C=e[30];let N;e[31]!==o||e[32]!==u?(N=o&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),o()},children:[s.jsx(I,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=o,e[32]=u,e[33]=N):N=e[33];let T;e[34]!==i||e[35]!==u?(T=i&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=i,e[35]=u,e[36]=T):T=e[36];let M;e[37]!==S||e[38]!==C||e[39]!==N||e[40]!==T?(M=s.jsxs(Rs,{align:"end",className:"w-fit min-w-20",children:[S,C,N,T]}),e[37]=S,e[38]=C,e[39]=N,e[40]=T,e[41]=M):M=e[41];let F;e[42]!==p||e[43]!==m||e[44]!==M?(F=s.jsxs(Fs,{open:p,onOpenChange:m,children:[j,M]}),e[42]=p,e[43]=m,e[44]=M,e[45]=F):F=e[45];let _;e[46]!==F||e[47]!==A?(_=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,F]}),e[46]=F,e[47]=A,e[48]=_):_=e[48];let B;return e[49]!==_||e[50]!==v||e[51]!==x?(B=s.jsx("div",{className:v,onContextMenu:x,children:_}),e[49]=_,e[50]=v,e[51]=x,e[52]=B):B=e[52],B};function tk(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function sk(t){return t.skills}function nk(t){return t.loadSkills}function rk(t){return t.name}function ak(t){return!ri(t)}function ik(t,e){return t.name.localeCompare(e.name)}function ok(t,e){return t.name.localeCompare(e.name)}const lk=()=>{const{t}=pt(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:a,commands:i,commandDraft:o,setCommandDraft:c}=_d(hr(C=>({selectedCommandName:C.selectedCommandName,getCommandByName:C.getCommandByName,createCommand:C.createCommand,updateCommand:C.updateCommand,commands:C.commands,commandDraft:C.commandDraft,setCommandDraft:C.setCommandDraft}))),d=e?n(e):null,p=!!(o&&o.name===e&&!d),[m,u]=l.useState(""),[f,b]=l.useState("user"),[h,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState(""),[k,A]=l.useState(""),[j,S]=l.useState(!1),D=l.useRef(null);l.useEffect(()=>{if(p&&o){const C=o.name||"",N=o.scope||"user",T=o.description||"",M=o.agent||"",F=o.model||"",_=o.template||"";u(C),b(N),v(T),g(M),y(F),A(_),D.current={draftName:C,draftScope:N,description:T,agent:M,model:F,template:_}}else if(d){const C=d.description||"",N=d.agent||"",T=d.model||"",M=d.template||"";v(C),g(N),y(T),A(M),D.current={draftName:"",draftScope:"user",description:C,agent:N,model:T,template:M}}},[d,p,e,i,o]);const E=l.useMemo(()=>{const C=D.current;return C?!!(p&&(m!==C.draftName||f!==C.draftScope)||h!==C.description||x!==C.agent||w!==C.model||k!==C.template):!1},[x,h,m,f,p,w,k]),P=async()=>{const C=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!C){H.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!k.trim()){H.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&i.some(N=>N.name===C)){H.error(t("settings.commands.sidebar.toast.commandExists"));return}S(!0);try{const N=x.trim(),T=w.trim(),M=k.trim(),F={name:C,description:h.trim()||void 0,agent:N===""?null:N,model:T===""?null:T,template:M,scope:p?f:void 0};let _;p?(_=await r(F),_&&c(null)):_=await a(C,F),_?H.success(t(p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):H.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(N){console.error("Error saving command:",N),H.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{S(!1)}};return e?s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p?t("settings.commands.page.title.new"):`/${e}`}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(p?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.identity")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.commands.page.field.commandName")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(Vt,{value:m,onChange:C=>u(C.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(is,{value:f,onValueChange:C=>b(C),children:[s.jsx(os,{className:"w-fit min-w-[100px]",children:s.jsx(us,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(ls,{align:"end",children:[s.jsx(Ft,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ft,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(fn,{value:h,onChange:C=>v(C.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.executionContext")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.commands.page.field.overrideAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Ol,{agentName:x,onChange:C=>g(C)})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(mo,{providerId:hi(w)?.providerId??"",modelId:hi(w)?.modelId??"",onChange:(C,N)=>{y(C&&N?`${C}/${N}`:"")}})})]})]})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.template")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(fn,{value:k,onChange:C=>A(C.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(xe,{onClick:P,disabled:j||!E,size:"xs",className:"!font-normal",children:t(j?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},cp=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},dp=t=>{const e=ot.c(5),{tone:n,enabled:r}=t;if(!r){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=o):o=e[0],o}let a;e[1]!==n?(a=ue("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[n]),e[1]=n,e[2]=a):a=e[2];let i;return e[3]!==a?(i=s.jsx("span",{className:a}),e[3]=a,e[4]=i):i=e[4],i},ck=t=>{const e=ot.c(116),{onItemSelect:n}=t,{t:r}=pt(),{mcpServers:a,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=so(hr(dk)),m=_s(uk);let u;e[0]!==m?(u=ge=>ge.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const f=gn(u),b=gn(mk),h=gn(pk),[v,x]=l.useState(null),[g,w]=l.useState(!1),[y,k]=l.useState(null),[A,j]=l.useState(!1);let S;e[2]!==a?(S=a.filter(fk),e[2]=a,e[3]=S):S=e[3];const D=S;let E;e[4]!==a?(E=a.filter(hk),e[4]=a,e[5]=E):E=e[5];const P=E;let C,N;e[6]!==d?(C=()=>{d()},N=[d],e[6]=d,e[7]=C,e[8]=N):(C=e[7],N=e[8]),l.useEffect(C,N);let T;e[9]!==m||e[10]!==h||e[11]!==A||e[12]!==b?(T=()=>{if(A)return;j(!0);const ge=new Promise(gk);Promise.all([b({directory:m,silent:!0}),ge]).then(()=>{const O=h(m);O&&H.error(O)}).finally(()=>{j(!1)})},e[9]=m,e[10]=h,e[11]=A,e[12]=b,e[13]=T):T=e[13];const M=T;let F;e[14]!==a||e[15]!==n||e[16]!==c||e[17]!==o?(F=()=>{let ge="new-mcp-server",O=1;for(;a.some(G=>G.name===ge);)ge=`new-mcp-server-${O}`,O++;c({name:ge,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(ge),n?.()},e[14]=a,e[15]=n,e[16]=c,e[17]=o,e[18]=F):F=e[18];const _=F;let B;e[19]!==p||e[20]!==v||e[21]!==r?(B=async()=>{if(!v)return;w(!0);const ge=await p(v.name);ge.ok?ge.reloadFailed?H.warning(ge.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:ge.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):H.success(ge.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:v.name})):H.error(r("settings.mcp.sidebar.toast.deleteFailed")),x(null),w(!1)},e[19]=p,e[20]=v,e[21]=r,e[22]=B):B=e[22];const V=B;let $;e[23]===Symbol.for("react.memo_cache_sentinel")?($=ue("flex h-full flex-col","bg-background"),e[23]=$):$=e[23];let z;e[24]!==r?(z=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=z):z=e[25];let Q;e[26]!==z?(Q=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:z}),e[26]=z,e[27]=Q):Q=e[27];let L;e[28]!==r?(L=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=L):L=e[29];let J;e[30]!==r?(J=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=J):J=e[31];const ee=A&&"animate-spin";let re;e[32]!==ee?(re=ue("h-4 w-4",ee),e[32]=ee,e[33]=re):re=e[33];let q;e[34]!==re?(q=s.jsx(I,{name:"refresh",className:re}),e[34]=re,e[35]=q):q=e[35];let ce;e[36]!==M||e[37]!==A||e[38]!==L||e[39]!==J||e[40]!==q?(ce=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:A,onClick:M,"aria-label":L,title:J,children:q}),e[36]=M,e[37]=A,e[38]=L,e[39]=J,e[40]=q,e[41]=ce):ce=e[41];let ae;e[42]!==Q||e[43]!==ce?(ae=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[Q,ce]}),e[42]=Q,e[43]=ce,e[44]=ae):ae=e[44];let R;e[45]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(po,{className:"mb-3"}),e[45]=R):R=e[45];let U;e[46]!==a.length||e[47]!==r?(U=r("settings.mcp.sidebar.total",{count:a.length}),e[46]=a.length,e[47]=r,e[48]=U):U=e[48];let W;e[49]!==U?(W=s.jsx("span",{className:"typography-meta text-muted-foreground",children:U}),e[49]=U,e[50]=W):W=e[50];let Z;e[51]!==r?(Z=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=Z):Z=e[52];let K;e[53]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e[53]=K):K=e[53];let ie;e[54]!==_||e[55]!==Z?(ie=s.jsx(xe,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:_,title:Z,children:K}),e[54]=_,e[55]=Z,e[56]=ie):ie=e[56];let Ne;e[57]!==W||e[58]!==ie?(Ne=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[W,ie]}),e[57]=W,e[58]=ie,e[59]=Ne):Ne=e[59];let ne;e[60]!==ae||e[61]!==Ne?(ne=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ae,R,Ne]}),e[60]=ae,e[61]=Ne,e[62]=ne):ne=e[62];let fe;e[63]!==a.length||e[64]!==f||e[65]!==n||e[66]!==y||e[67]!==D||e[68]!==i||e[69]!==c||e[70]!==o||e[71]!==r||e[72]!==P?(fe=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:a.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[D.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.projectServers")}),D.map(ge=>{const O=f[ge.name],X=cp(O?.status),G=i===ge.name,Te=Qi();return s.jsxs("div",{className:ue("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",G?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Te?void 0:le=>{le.preventDefault(),k(ge.name)},children:[s.jsxs("button",{onClick:()=>{o(ge.name),c(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(dp,{tone:X,enabled:ge.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ge.name}),s.jsx("span",{title:ge.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ge.type==="local"?s.jsx(I,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(I,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ge.type==="local"?ge.command?.join(" ")??"":ge.url??""})]}),s.jsxs(Fs,{open:y===ge.name,onOpenChange:le=>k(le?ge.name:null),children:[s.jsx(Es,{asChild:!0,children:s.jsx(xe,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Rs,{align:"end",className:"w-fit min-w-20",children:s.jsxs($t,{onClick:le=>{le.stopPropagation(),x(ge)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ge.name)})]}),P.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.userServers")}),P.map(ge=>{const O=f[ge.name],X=cp(O?.status),G=i===ge.name,Te=Qi();return s.jsxs("div",{className:ue("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",G?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Te?void 0:le=>{le.preventDefault(),k(ge.name)},children:[s.jsxs("button",{onClick:()=>{o(ge.name),c(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(dp,{tone:X,enabled:ge.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ge.name}),s.jsx("span",{title:ge.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ge.type==="local"?s.jsx(I,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(I,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ge.type==="local"?ge.command?.join(" ")??"":ge.url??""})]}),s.jsxs(Fs,{open:y===ge.name,onOpenChange:le=>k(le?ge.name:null),children:[s.jsx(Es,{asChild:!0,children:s.jsx(xe,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Rs,{align:"end",className:"w-fit min-w-20",children:s.jsxs($t,{onClick:le=>{le.stopPropagation(),x(ge)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ge.name)})]})]})}),e[63]=a.length,e[64]=f,e[65]=n,e[66]=y,e[67]=D,e[68]=i,e[69]=c,e[70]=o,e[71]=r,e[72]=P,e[73]=fe):fe=e[73];const pe=v!==null;let je;e[74]!==g?(je=ge=>{!ge&&!g&&x(null)},e[74]=g,e[75]=je):je=e[75];let oe;e[76]!==r?(oe=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=oe):oe=e[77];let Se;e[78]!==oe?(Se=s.jsx(gs,{children:oe}),e[78]=oe,e[79]=Se):Se=e[79];const se=v?.name||"";let we;e[80]!==r||e[81]!==se?(we=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:se}),e[80]=r,e[81]=se,e[82]=we):we=e[82];let Ae;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ae=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=Ae):Ae=e[83];let ve;e[84]!==we?(ve=s.jsxs(Ps,{children:[we," ",Ae,"."]}),e[84]=we,e[85]=ve):ve=e[85];let ye;e[86]!==Se||e[87]!==ve?(ye=s.jsxs(vs,{children:[Se,ve]}),e[86]=Se,e[87]=ve,e[88]=ye):ye=e[88];let Ie;e[89]===Symbol.for("react.memo_cache_sentinel")?(Ie=()=>x(null),e[89]=Ie):Ie=e[89];let he;e[90]!==r?(he=r("settings.common.actions.cancel"),e[90]=r,e[91]=he):he=e[91];let me;e[92]!==g||e[93]!==he?(me=s.jsx(xe,{size:"sm",variant:"ghost",onClick:Ie,disabled:g,children:he}),e[92]=g,e[93]=he,e[94]=me):me=e[94];let Ee;e[95]!==g||e[96]!==r?(Ee=r(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=g,e[96]=r,e[97]=Ee):Ee=e[97];let Ve;e[98]!==V||e[99]!==g||e[100]!==Ee?(Ve=s.jsx(xe,{size:"sm",onClick:V,disabled:g,children:Ee}),e[98]=V,e[99]=g,e[100]=Ee,e[101]=Ve):Ve=e[101];let Y;e[102]!==me||e[103]!==Ve?(Y=s.jsxs(Us,{children:[me,Ve]}),e[102]=me,e[103]=Ve,e[104]=Y):Y=e[104];let ke;e[105]!==ye||e[106]!==Y?(ke=s.jsxs(ms,{className:"max-w-md",children:[ye,Y]}),e[105]=ye,e[106]=Y,e[107]=ke):ke=e[107];let Be;e[108]!==pe||e[109]!==je||e[110]!==ke?(Be=s.jsx(ps,{open:pe,onOpenChange:je,children:ke}),e[108]=pe,e[109]=je,e[110]=ke,e[111]=Be):Be=e[111];let Ce;return e[112]!==ne||e[113]!==fe||e[114]!==Be?(Ce=s.jsxs("div",{className:$,children:[ne,fe,Be]}),e[112]=ne,e[113]=fe,e[114]=Be,e[115]=Ce):Ce=e[115],Ce};function dk(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function uk(t){return t.currentDirectory}function mk(t){return t.refresh}function pk(t){return t.getErrorForDirectory}function fk(t){return t.scope==="project"}function hk(t){return t.scope!=="project"}function gk(t){return setTimeout(t,500)}function ia(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Di(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function xa(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Cc(t,e,n){const r=xk(n),a=typeof n.url=="string"?n.url.trim():"",i=up(n,"env","environment"),o=up(n,"headers"),c=bk(n),d=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",m=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",u=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",f=yk(n),b=vk(n);return{ok:!0,name:t,type:e,command:r,url:a,environment:i,headers:o,oauthEnabled:c,oauthClientId:d,oauthClientSecret:p,oauthScope:m,oauthRedirectUri:u,timeout:f,enabled:b}}function xk(t){const e=t.command,n=t.args;if(Di(e)&&Di(n))return[...e,...n];if(Di(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return Di(n)?[...r,...n]:r}return Di(n)?n:[]}function up(t,...e){for(const n of e){const r=t[n];if(!ia(r))continue;const a=Object.entries(r).filter(([i,o])=>i&&typeof o=="string");if(a.length>0)return a.map(([i,o])=>({key:i,value:String(o)}))}return[]}function bk(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!ia(t.oauth))return!1;const e=t.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function yk(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const n=Number(e);if(Number.isFinite(n)&&n>0)return String(Math.floor(n))}return""}function vk(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function wk(t){const e=t.mcpServers;if(ia(e)){const r=Object.keys(e);if(r.length===1){const a=r[0],i=e[a];if(ia(i))return{name:a,entry:i}}if(r.length>1)return null}const n=Object.keys(t).filter(r=>{const a=t[r];return r!=="mcpServers"&&ia(a)});if(n.length===1){const r=n[0],a=t[r];if(ug(a))return{name:r,entry:a}}return null}function ug(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function jk(t,e){let n;try{const o=t.trim();if(!o)return xa("No JSON content provided");n=JSON.parse(o)}catch(o){return xa(o instanceof Error?`Invalid JSON: ${o.message}`:"Invalid JSON")}if(!ia(n))return xa("Expected a JSON object, not an array or primitive");const r=n,a=r.mcpServers;if(ia(a)){const o=Object.keys(a);if(o.length===0)return xa("mcpServers object is empty",n);if(o.length>1)return xa("Paste one server at a time. Found "+o.length+" servers in mcpServers",n);const c=o[0],d=a[c];return ia(d)?Cc(c,Ic(d),d):xa("Server entry is not a valid object",n)}const i=wk(r);if(i)return Cc(i.name,Ic(i.entry),i.entry);if(ug(r)){const o=Ic(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return Cc(c,o,r)}return xa("No recognizable MCP server configuration found in JSON",n)}function Ic(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function Nk(t,e,n){const r=n?.isNewServer??!1,a=t.name,i=r&&a?a:e.name??"";return{...e,name:i,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}const mg="/mcp/oauth/callback",Sk=t=>{if(typeof window>"u")return null;try{const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=e.length%4===0?"":"=".repeat(4-e.length%4),r=window.atob(e+n),a=Uint8Array.from(r,i=>i.charCodeAt(0));return new TextDecoder().decode(a)}catch{return null}},pg=t=>{const e=kk(t.get("state"));if(e)return e;const n=t.get("server");if(typeof n!="string"||!n.trim())return null;const r=t.get("directory");return{name:n.trim(),directory:typeof r=="string"&&r.trim()?r.trim():null}},eu=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},kk=t=>{if(typeof t!="string"||!t.trim())return null;const e=Sk(t.trim());if(!e)return null;try{const n=JSON.parse(e);return n?.v!==1||typeof n.n!="string"||!n.n.trim()?null:{name:n.n.trim(),directory:typeof n.d=="string"&&n.d.trim()?n.d.trim():null}}catch{return null}};function Ck(t){const e=[];let n="",r=!1,a=!1;for(let i=0;i<t.length;i++){const o=t[i];if(o==="'"&&!a){r=!r;continue}if(o==='"'&&!r){a=!a;continue}if((o===" "||o===" ")&&!r&&!a){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function Ik(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const n=new URL(e),r=n.searchParams.get("code");if(typeof r=="string"&&r.trim())return{code:r.trim(),context:pg(n.searchParams),stateKey:eu(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Pk=({value:t,onChange:e,pasteCommandTitle:n,pasteCommandLabel:r,pasteSuccess:a,clipboardReadFailed:i,preview:o})=>{const[c,d]=l.useState(()=>t.join(`
|
|
157
|
-
`)),p=l.useRef(t);l.useEffect(()=>{JSON.stringify(p.current)!==JSON.stringify(t)&&(p.current=t,d(t.join(`
|
|
158
|
-
`)))},[t]);const m=f=>{const b=f.split(`
|
|
159
|
-
`).filter(h=>h.trim().length>0);e(b)},u=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),h=b.includes(`
|
|
160
|
-
`)?b.split(`
|
|
161
|
-
`).filter(v=>v.trim()):Ck(b);d(h.join(`
|
|
162
|
-
`)),e(h),H.success(a(h.length))}catch{H.error(i)}};return s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[s.jsx("div",{className:"flex items-center justify-end gap-2",children:s.jsxs(xe,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(I,{name:"clipboard",className:"h-3 w-3"}),r]})}),s.jsx(fn,{value:c,onChange:f=>{d(f.target.value),m(f.target.value)},onBlur:()=>{const f=c.split(`
|
|
163
|
-
`).map(b=>b.trimEnd()).join(`
|
|
164
|
-
`);d(f),m(f)},placeholder:`npx
|
|
165
|
-
-y
|
|
166
|
-
@modelcontextprotocol/server-postgres
|
|
167
|
-
postgresql://user:pass@host/db`,rows:Math.max(4,t.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),t.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:o(t.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:t.map((f,b)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),f]},b))})})]})]})},Ak=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),mp=({value:t,onChange:e,keyTransform:n=Ak,keyPlaceholder:r="API_KEY",keyInputClassName:a="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:o="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:p,keyLabel:m,valueLabel:u,valuePlaceholder:f,hideValueTitle:b,showValueTitle:h,addVariable:v,plainTextWarning:x,removeVariableAria:g})=>{const[w,y]=l.useState(new Set),k=()=>e([...t,{key:"",value:""}]),A=P=>{e(t.filter((C,N)=>N!==P)),y(C=>{const N=new Set(C);return N.delete(P),N})},j=(P,C,N)=>{const T=[...t];T[P]={...T[P],[C]:N},e(T)},S=P=>{y(C=>{const N=new Set(C);return N.has(P)?N.delete(P):N.add(P),N})},D=async()=>{try{const P=await navigator.clipboard.readText(),C=[];for(const T of P.split(`
|
|
168
|
-
`)){const M=T.trim();if(!M||M.startsWith("#"))continue;const F=M.indexOf("=");if(F===-1)continue;const _=M.slice(0,F).trim();let B=M.slice(F+1).trim();(B.startsWith('"')&&B.endsWith('"')||B.startsWith("'")&&B.endsWith("'"))&&(B=B.slice(1,-1)),_&&C.push({key:_,value:B})}if(C.length===0){H.error(c);return}const N=[...t];for(const T of C){const M=N.findIndex(F=>F.key===T.key);M!==-1?N[M]=T:N.push(T)}e(N),H.success(d(C.length))}catch{H.error(p)}},E=t.some(P=>P.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:u})]}),s.jsxs(xe,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:D,type:"button",title:o,children:[s.jsx(I,{name:"clipboard",className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((P,C)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vt,{value:P.key,onChange:N=>j(C,"key",n(N.target.value)),placeholder:r,className:a,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Vt,{type:w.has(C)?"text":"password",value:P.value,onChange:N=>j(C,"value",N.target.value),placeholder:f,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>S(C),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:w.has(C)?b:h,children:w.has(C)?s.jsx(I,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(xe,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>A(C),"aria-label":g,children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},C))}),s.jsxs(xe,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:k,type:"button",children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),v]}),E&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},pp=t=>{const e=ot.c(14),{status:n,enabled:r,getStatusLabel:a,variant:i}=t,o=i===void 0?"compact":i;if(!r||!n)return null;let c,d;if(e[0]!==a||e[1]!==n||e[2]!==o){d=Symbol.for("react.early_return_sentinel");e:{const f={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[n]??{text:"text-muted-foreground",bg:""};if(o==="pill"){const b=ue("typography-micro font-medium rounded-full px-2 py-0.5",f.text,f.bg);let h;e[5]!==a||e[6]!==n?(h=a(n),e[5]=a,e[6]=n,e[7]=h):h=e[7],d=s.jsxs("span",{className:b,children:["● ",h]});break e}c=ue("typography-micro font-medium",f.text)}e[0]=a,e[1]=n,e[2]=o,e[3]=c,e[4]=d}else c=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;let p;e[8]!==a||e[9]!==n?(p=a(n),e[8]=a,e[9]=n,e[10]=p):p=e[10];let m;return e[11]!==c||e[12]!==p?(m=s.jsxs("span",{className:c,children:["● ",p]}),e[11]=c,e[12]=p,e[13]=m):m=e[13],m},Dk=(t,e,n)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return n?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return n?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},Tk=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Mk=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),fp=(t,e)=>{if(typeof window>"u")return null;const n=new URL(mg,window.location.origin);return typeof t=="string"&&t.trim()&&n.searchParams.set("server",t.trim()),typeof e=="string"&&e.trim()&&n.searchParams.set("directory",e.trim()),n.toString()},Ek=async t=>{const e=await fetch("/api/mcp/auth/pending",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:t.state,name:t.name,directory:typeof t.directory=="string"&&t.directory.trim()?t.directory.trim():null})});if(!e.ok){const n=await e.json().catch(()=>null);throw new Error(n?.error||"Failed to prepare MCP authorization callback")}},Rk=async t=>{const e=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const n=await e.json().catch(()=>null);return n?.name?.trim()?{name:n.name.trim(),directory:typeof n.directory=="string"&&n.directory.trim()?n.directory.trim():null}:null},Ti=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Pc=(t,e,n)=>{const r=t instanceof Error?t.message:e;return/oauth state required/i.test(r)?n("settings.mcp.page.toast.authSessionExpired"):r},Fk=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},Ok=()=>{const{t}=pt(),e=l.useCallback((Ke,Pt)=>t(Ke,Pt),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:a,setMcpDraft:i,setSelectedMcp:o,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=so(hr(Ke=>({selectedMcpName:Ke.selectedMcpName,mcpServers:Ke.mcpServers,mcpDraft:Ke.mcpDraft,setMcpDraft:Ke.setMcpDraft,setSelectedMcp:Ke.setSelectedMcp,getMcpByName:Ke.getMcpByName,createMcp:Ke.createMcp,updateMcp:Ke.updateMcp,deleteMcp:Ke.deleteMcp}))),u=_s(Ke=>Ke.currentDirectory),f=l.useMemo(()=>ln(),[]),b=gn(Ke=>Ke.getStatusForDirectory(u??null)),h=gn(Ke=>Ke.getDiagnosticForDirectory(u??null)),v=gn(Ke=>Ke.refresh),x=gn(Ke=>Ke.connect),g=gn(Ke=>Ke.disconnect),w=gn(Ke=>Ke.startAuth),y=gn(Ke=>Ke.completeAuth),k=gn(Ke=>Ke.clearAuth),A=gn(Ke=>Ke.testConnection),j=n?c(n):null,S=!!(a&&a.name===n&&!j),[D,E]=l.useState(""),[P,C]=l.useState("user"),[N,T]=l.useState("local"),[M,F]=l.useState([]),[_,B]=l.useState(""),[V,$]=l.useState([]),[z,Q]=l.useState([]),[L,J]=l.useState(!0),[ee,re]=l.useState(""),[q,ce]=l.useState(""),[ae,R]=l.useState(""),[U,W]=l.useState(""),[Z,K]=l.useState(""),[ie,Ne]=l.useState(!0),[ne,fe]=l.useState(!1),[pe,je]=l.useState(!1),[oe,Se]=l.useState(!1),[se,we]=l.useState(!1),[Ae,ve]=l.useState(!1),[ye,Ie]=l.useState(!1),[he,me]=l.useState(!1),[Ee,Ve]=l.useState(!1),[Y,ke]=l.useState(null),[Be,Ce]=l.useState(null),[ge,O]=l.useState(""),[X,G]=l.useState(!1),Te=l.useRef(0),le=l.useRef(!1),[We,de]=l.useState(!1),[Fe,rt]=l.useState(!1),[Oe,Ye]=l.useState(""),[Ge,it]=l.useState(null),Qe=l.useMemo(()=>Fk(n,u),[u,n]),at=l.useRef(Qe),nt=l.useRef(null),be=l.useCallback(()=>{ke(null),Ce(null),O(""),G(!1),Te.current=0,Ve(!1),ve(!1),Ie(!1),le.current=!1},[]),He=l.useCallback(()=>{Ye(""),it(null),rt(!0)},[]),_e=l.useCallback(async()=>{try{const Ke=await navigator.clipboard.readText();Ye(Ke),it(null)}catch{H.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),tt=l.useCallback(()=>{const Ke=jk(Oe,{fallbackName:D});if(!Ke.ok){it(Ke.error);return}const Ot=Nk(Ke,{name:D,scope:P,type:N,command:M,url:_,environment:V,headers:z,oauthEnabled:L,oauthClientId:ee,oauthClientSecret:q,oauthScope:ae,oauthRedirectUri:U,timeout:Z,enabled:ie},{isNewServer:S});E(Ot.name),T(Ot.type),F(Ot.command??[]),B(Ot.url??""),$(Ot.environment??[]),Q(Ot.headers??[]),J(Ot.oauthEnabled??!1),re(Ot.oauthClientId??""),ce(Ot.oauthClientSecret??""),R(Ot.oauthScope??""),W(Ot.oauthRedirectUri??""),K(Ot.timeout??""),Ne(Ot.enabled??!0),rt(!1),Ye(""),it(null),H.success(t("settings.mcp.page.toast.configImported"))},[Oe,D,P,N,M,_,V,z,L,ee,q,ae,U,Z,ie,S,t]);l.useEffect(()=>{if(S&&a){E(a.name),C(a.scope||"user"),T(a.type),F(a.command),B(a.url),$(a.environment),Q(a.headers),J(a.oauthEnabled),re(a.oauthClientId),ce(a.oauthClientSecret),R(a.oauthScope),W(a.oauthRedirectUri),K(a.timeout),Ne(a.enabled),de(!1),nt.current={mcpType:a.type,command:a.command,url:a.url,envEntries:a.environment,headerEntries:a.headers,oauthEnabled:a.oauthEnabled,oauthClientId:a.oauthClientId,oauthClientSecret:a.oauthClientSecret,oauthScope:a.oauthScope,oauthRedirectUri:a.oauthRedirectUri,timeout:a.timeout,enabled:a.enabled};return}if(j){C(j.scope==="project"?"project":"user");const Ke=Yu(j.environment),Pt=j.type==="remote"?j:null,Ot=Yu(Pt?.headers),Nt=Pt?.oauth,Ht=Nt&&typeof Nt=="object"?Nt:null,ns=Nt!==!1,Ss=j.type,fs=Ss==="local"?j.command??[]:[],Os=Ss==="remote"?j.url??"":"",zs=typeof Pt?.timeout=="number"&&Number.isFinite(Pt.timeout)?String(Pt.timeout):"";T(Ss),F(fs),B(Os),$(Ke),Q(Ot),J(ns),re(ns?Ht?.clientId??"":""),ce(ns?Ht?.clientSecret??"":""),R(ns?Ht?.scope??"":""),W(ns?Ht?.redirectUri??"":""),K(zs),Ne(j.enabled),de(!1),nt.current={mcpType:Ss,command:fs,url:Os,envEntries:Ke,headerEntries:Ot,oauthEnabled:ns,oauthClientId:ns?Ht?.clientId??"":"",oauthClientSecret:ns?Ht?.clientSecret??"":"",oauthScope:ns?Ht?.scope??"":"",oauthRedirectUri:ns?Ht?.redirectUri??"":"",timeout:zs,enabled:j.enabled}}},[j,S,a]);const ut=l.useMemo(()=>{const Ke=nt.current;return Ke?N!==Ke.mcpType||ie!==Ke.enabled||JSON.stringify(M)!==JSON.stringify(Ke.command)||_!==Ke.url||JSON.stringify(V)!==JSON.stringify(Ke.envEntries)||JSON.stringify(z)!==JSON.stringify(Ke.headerEntries)||L!==Ke.oauthEnabled||ee!==Ke.oauthClientId||q!==Ke.oauthClientSecret||ae!==Ke.oauthScope||U!==Ke.oauthRedirectUri||Z!==Ke.timeout:!1},[N,M,_,V,z,L,ee,q,ae,U,Z,ie]),qe=async()=>{const Ke=S?D.trim():n??"";if(!Ke){H.error(t("settings.mcp.page.toast.nameRequired"));return}if(S&&r.some(Ot=>Ot.name===Ke)){H.error(t("settings.mcp.page.toast.serverNameExists"));return}if(N==="local"&&M.filter(Boolean).length===0){H.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(N==="remote"&&!_.trim()){H.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const Pt={name:Ke,scope:P,type:N,command:M,url:_,environment:V,headers:z,oauthEnabled:L,oauthClientId:ee,oauthClientSecret:q,oauthScope:ae,oauthRedirectUri:U,timeout:Z,enabled:ie};fe(!0);try{const Ot=S?await d(Pt):await p(Ke,Pt);Ot.ok?(await Ti(Be),be(),S&&(i(null),o(Ke)),await v({directory:u,silent:!0}),Ot.reloadFailed?H.warning(Ot.message||t(S?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Ot.warning||t("settings.mcp.page.toast.retryRefreshHint")}):H.success(Ot.message||t(S?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):H.error(t("settings.mcp.page.toast.saveFailed"))}catch(Ot){H.error(Ot instanceof Error?Ot.message:t("settings.mcp.page.toast.unexpectedError"))}finally{fe(!1)}},ze=async()=>{if(!n)return;Se(!0);const Ke=await m(n);Ke.ok?(await Ti(Be),be(),Ke.reloadFailed?H.warning(Ke.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Ke.warning||t("settings.mcp.page.toast.refreshListIfStale")}):H.success(Ke.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),je(!1)):H.error(t("settings.mcp.page.toast.deleteFailed")),Se(!1)},st=async()=>{if(n){we(!0);try{if(b[n]?.status==="connected")await g(n,u),H.success(t("settings.mcp.page.toast.disconnected"));else{await x(n,u),await v({directory:u,silent:!0});const Pt=gn.getState().getStatusForDirectory(u??null)[n];Pt?.status==="connected"?H.success(t("settings.mcp.page.toast.connected")):Pt?.status==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Pt?.status==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Pt?.status==="failed"?H.error(Pt.error||t("settings.mcp.page.toast.connectionFailed")):H.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await v({directory:u,silent:!0})}catch(Ke){H.error(Ke instanceof Error?Ke.message:t("settings.mcp.page.toast.connectionFailed"))}finally{we(!1)}}},yt=l.useCallback(()=>S?(H.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):ut?(H.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[ut,S,t]),Mt=l.useCallback(async(Ke=!1)=>{try{await v({directory:u,silent:Ke})}catch(Pt){Ke||H.error(Pt instanceof Error?Pt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,v,t]);l.useEffect(()=>{Mt(!0)},[Mt]),l.useEffect(()=>{at.current=Qe,we(!1),me(!1),be()},[be,Qe]);const Bt=l.useCallback(async()=>{if(!n||N!=="remote"||!yt())return;ve(!0);const Ke=Qe;let Pt=null;try{const Ot=gn.getState().getStatusForDirectory(u??null)[n]?.status;le.current=Ot==="needs_auth"||Ot==="needs_client_registration";const Nt=fp(n,u);if(!Nt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!U.trim()&&!f){const fs=await p(n,{oauthEnabled:L,oauthClientId:ee,oauthClientSecret:q,oauthScope:ae,oauthRedirectUri:Nt});if(!fs.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(fs.reloadFailed)throw new Error(fs.warning||fs.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(at.current!==Ke)return;W(Nt),nt.current=nt.current?{...nt.current,oauthRedirectUri:Nt}:nt.current}const Ht=await w(n,u),ns=eu(new URL(Ht).searchParams);if(ns&&(Pt=ns,await Ek({state:ns,name:n,directory:u})),at.current!==Ke)return;ke(Ht),Ce(ns??null),G(!0),Te.current=0;const Ss=await Zn(Ht);if(at.current!==Ke)return;Ss?H.message(t(f?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):H.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Ot){await Ti(Pt),at.current===Ke&&H.error(Pc(Ot,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{at.current===Ke&&ve(!1)}},[u,f,N,ee,q,L,U,ae,yt,Qe,n,w,t,e,p]),ft=l.useCallback(async()=>{if(!n||!yt())return;Ie(!0);const Ke=Qe;try{if(await k(n,u),at.current!==Ke)return;ke(null),Ce(null),O(""),G(!1),Te.current=0,await Ti(Be),H.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(Pt){at.current===Ke&&H.error(Pc(Pt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{at.current===Ke&&Ie(!1)}},[Be,k,u,yt,Qe,n,t,e]),It=l.useCallback(async()=>{if(!Y)return;if((await An(Y)).ok){H.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}H.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Y,t]),ss=l.useCallback(async()=>{const Ke=Ik(ge);if(!Ke.code){H.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const Pt=Ke.stateKey?await Rk(Ke.stateKey):null,Ot=Ke.context??Pt,Nt=Ot?.name??n,Ht=Ot?.directory??u;if(!Nt){H.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Ot&&!yt())return;Ve(!0);const ns=Qe;try{if(await y(Nt,Ke.code,Ht),await Ti(Ke.stateKey??Be),at.current!==ns)return;O(""),ke(null),Ce(null),G(!1),Te.current=0,H.success(Nt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Nt}))}catch(Ss){at.current===ns&&H.error(Pc(Ss,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{at.current===ns&&Ve(!1)}},[ge,Be,y,u,yt,Qe,n,t,e]),_t=l.useCallback(async()=>{if(!(!n||!yt())){if(!ie){H.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}me(!0);try{const Ke=await A(n,u),Pt=Ke.status?.status;Ke.warning?H.warning(Ke.warning):Pt==="connected"?H.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Pt==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Pt==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Pt==="failed"?H.error(Ke.status?.error||Ke.error||t("settings.mcp.page.toast.connectionTestFailed")):Ke.error?H.error(Ke.error):H.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(Ke){H.error(Ke instanceof Error?Ke.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{me(!1)}}},[u,ie,yt,n,t,A]);if(l.useEffect(()=>{if(!X||!n)return;const Ke=window.setInterval(()=>{(async()=>{Te.current+=1,await v({directory:u,silent:!0});const Pt=gn.getState().getStatusForDirectory(u??null)[n];if(Pt){if(le.current&&Pt.status!=="needs_auth"&&Pt.status!=="needs_client_registration"){G(!1),Te.current=0,le.current=!1,ke(null),O(""),Pt.status==="connected"&&H.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!le.current&&Pt.status==="failed"){G(!1),Te.current=0,le.current=!1,H.error(Pt.error||t("settings.mcp.page.toast.authorizationFailed"));return}Te.current>=30&&(G(!1),Te.current=0,le.current=!1,H.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Ke)}},[u,X,v,n,t]),!n)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const qt=b[n],ct=n?h[n]:void 0,jt=qt??ct,as=qt?.status==="connected",xs=qt?.status==="needs_auth"||qt?.status==="needs_client_registration",ws=f?null:fp(n,u),As=Dk(jt?.status,e,jt&&"error"in jt?jt.error:void 0),Gt=Ke=>{switch(Ke){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");default:return Ke}};return s.jsxs(Ns,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[S?s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.mcp.page.header.newServer")}):s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:n}),s.jsx(pp,{status:jt?.status,enabled:ie,getStatusLabel:Gt,variant:"pill"})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:S?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(N==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!S&&s.jsxs(s.Fragment,{children:[s.jsx(xe,{variant:as?"outline":"default",size:"xs",className:"!font-normal",onClick:st,disabled:se||!ie,children:t(se?"settings.mcp.page.actions.working":as?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),N==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(xe,{variant:xs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{Bt()},disabled:Ae||!ie,children:t(Ae?"settings.mcp.page.actions.starting":xs?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(xe,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ft()},disabled:ye||!ie,children:t(ye?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),as&&s.jsx(xe,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{_t()},disabled:he||!ie,children:t(he?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!S&&Mk(jt?.status,Y,xs,X)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:ue("rounded-lg border p-3",Tk(jt?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(pp,{status:jt?.status,enabled:ie,getStatusLabel:Gt})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:As}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:P==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:u??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!as&&s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_t()},disabled:he||!ie,children:t(he?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Y&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:Y}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Zn(Y)},children:[s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{It()},children:[s.jsx(I,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),N==="remote"&&(xs||X||Y)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(fn,{value:ge,onChange:Ke=>O(Ke.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ss()},disabled:Ee,children:t(Ee?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),X&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.server.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[S&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.name")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Vt,{value:D,onChange:Ke=>E(Ke.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 font-mono px-2",autoFocus:!0}),s.jsxs(is,{value:P,onValueChange:Ke=>C(Ke),children:[s.jsx(os,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:t(P==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:P==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"})}),s.jsxs(ls,{align:"end",children:[s.jsx(Ft,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ft,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),S&&s.jsx("div",{className:"py-1.5",children:s.jsxs(xe,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:He,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(I,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]})}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ie,onClick:()=>Ne(!ie),onKeyDown:Ke=>{(Ke.key===" "||Ke.key==="Enter")&&(Ke.preventDefault(),Ne(!ie))},children:[s.jsx(ds,{checked:ie,onChange:Ne,ariaLabel:t("settings.mcp.page.server.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.enable")})]}),s.jsx("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:s.jsxs("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.transportMode")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":N==="local",onClick:()=>T("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":N==="remote",onClick:()=>T("remote"),className:"!font-normal",children:t("settings.mcp.page.transport.remote")})]})]})})]})]}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t(N==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:N==="local"?s.jsx(Pk,{value:M,onChange:F,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Ke=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:Ke}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:Ke=>t("settings.mcp.page.connection.previewArgs",{count:Ke})}):s.jsx(Vt,{value:_,onChange:Ke=>B(Ke.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),N==="remote"&&s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.advanced.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs(pr,{open:We,onOpenChange:de,children:[s.jsxs(Nr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",t(L?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",z.length," ",t("settings.mcp.page.advanced.headers"),Z?` · ${Z}ms`:"",")"]})]}),We?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(fr,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.advanced.timeoutMs")})}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Vt,{type:"number",min:"1",step:"1",value:Z,onChange:Ke=>K(Ke.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground sm:pl-64",children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-2 typography-ui-label text-foreground",children:[t("settings.mcp.page.advanced.requestHeaders"),z.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",z.length,")"]})]}),s.jsx(mp,{value:z,onChange:Q,keyTransform:Ke=>Ke.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ke=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ke}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":L,onClick:()=>J(!L),onKeyDown:Ke=>{(Ke.key===" "||Ke.key==="Enter")&&(Ke.preventDefault(),J(!L))},children:[s.jsx(ds,{checked:L,onChange:J,ariaLabel:t("settings.mcp.page.advanced.oauthAutoDetectionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.advanced.oauthAutoDetection")})]}),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsx(Vt,{value:ee,onChange:Ke=>re(Ke.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!L,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Vt,{value:q,onChange:Ke=>ce(Ke.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!L,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Vt,{value:ae,onChange:Ke=>R(Ke.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!L,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Vt,{value:U,onChange:Ke=>W(Ke.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!L,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),ws&&s.jsxs("p",{className:"typography-micro text-muted-foreground",children:[t("settings.mcp.page.advanced.oauthCallbackHint"),s.jsx("span",{className:"mt-1 block break-all font-mono text-foreground/80",children:ws})]})]})]})})]})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.mcp.page.env.title"),V.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",V.length,")"]})]})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:V.length===0?s.jsxs(xe,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>$([{key:"",value:""}]),children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(mp,{value:V,onChange:$,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ke=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ke}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})})]}),s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[s.jsx(xe,{onClick:qe,disabled:ne||!ut&&!S,size:"xs",className:"!font-normal",children:t(ne?"settings.common.actions.saving":S?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!S&&s.jsx(xe,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>je(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(ps,{open:Fe,onOpenChange:Ke=>{Ke||(rt(!1),Ye(""),it(null))},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Ps,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(fn,{value:Oe,onChange:Ke=>{Ye(Ke.target.value),it(null)},placeholder:`{
|
|
169
|
-
"mcpServers": {
|
|
170
|
-
"postgres": {
|
|
171
|
-
"command": "npx",
|
|
172
|
-
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),Ge&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Ge}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(xe,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:_e,type:"button",children:[s.jsx(I,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Us,{children:[s.jsx(xe,{variant:"outline",onClick:()=>{rt(!1),Ye(""),it(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(xe,{onClick:tt,disabled:!Oe.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(ps,{open:pe,onOpenChange:Ke=>{!Ke&&!oe&&je(!1)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Ps,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Us,{children:[s.jsx(xe,{variant:"outline",onClick:()=>je(!1),disabled:oe,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(xe,{variant:"destructive",size:"sm",onClick:ze,disabled:oe,children:t(oe?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},Lk=t=>{const e=ot.c(150),{onItemSelect:n}=t,{t:r}=pt(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedSkillName:h,skills:v,setSelectedSkill:x,setSkillDraft:g,createSkill:w,deleteSkill:y,getSkillDetail:k}=ra(hr($k));let A;e[0]!==n||e[1]!==x||e[2]!==g||e[3]!==v?(A=()=>{let _e="new-skill",tt=1;for(;v.some(ut=>ut.name===_e);)_e=`new-skill-${tt}`,tt++;g({name:_e,scope:"user",source:"opencode",description:""}),x(_e),n?.()},e[0]=n,e[1]=x,e[2]=g,e[3]=v,e[4]=A):A=e[4];const j=A;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=async _e=>{p(_e)},e[5]=S):S=e[5];const D=S;let E;e[6]!==d||e[7]!==y||e[8]!==r?(E=async()=>{if(!d)return;u(!0),await y(d.name)?(H.success(r("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),p(null)):H.error(r("settings.skills.sidebar.toast.deleteSkillFailed")),u(!1)},e[6]=d,e[7]=y,e[8]=r,e[9]=E):E=e[9];const P=E;let C;e[10]!==k||e[11]!==x||e[12]!==g||e[13]!==v||e[14]!==r?(C=async _e=>{const tt=_e.name;let ut=1,qe=`${tt}-copy`;for(;v.some(st=>st.name===qe);)ut++,qe=`${tt}-copy-${ut}`;const ze=await k(_e.name);if(!ze){H.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}g({name:qe,scope:_e.scope||"user",source:_e.source||"opencode",description:(ze.sources.md.fields.includes("description"),""),instructions:""}),x(qe)},e[10]=k,e[11]=x,e[12]=g,e[13]=v,e[14]=r,e[15]=C):C=e[15];const N=C;let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=_e=>{c(_e.name),i(_e)},e[16]=T):T=e[16];const M=T;let F;e[17]!==w||e[18]!==y||e[19]!==k||e[20]!==a||e[21]!==o||e[22]!==x||e[23]!==v||e[24]!==r?(F=async()=>{if(!a)return;const _e=o.trim().replace(/\s+/g,"-").toLowerCase();if(!_e){H.error(r("settings.skills.page.toast.skillNameRequired"));return}if(_e===a.name){i(null);return}if(v.some(qe=>qe.name===_e)){H.error(r("settings.skills.page.toast.skillExists"));return}if(!await k(a.name)){H.error(r("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await w({name:_e,description:"Renamed skill",scope:a.scope,source:a.source})?await y(a.name)?(H.success(`Skill renamed to "${_e}"`),x(_e)):H.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):H.error(r("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=w,e[18]=y,e[19]=k,e[20]=a,e[21]=o,e[22]=x,e[23]=v,e[24]=r,e[25]=F):F=e[25];const _=F;let B;e[26]!==v?(B=v.filter(Bk),e[26]=v,e[27]=B):B=e[27];const V=B;let $;e[28]!==v?($=v.filter(_k),e[28]=v,e[29]=$):$=e[29];const z=$;let Q;e[30]===Symbol.for("react.memo_cache_sentinel")?(Q=function(tt){const ut={},qe=[];for(const st of tt)st.group?(ut[st.group]||(ut[st.group]=[]),ut[st.group].push(st)):qe.push(st);const ze=Object.keys(ut).sort(zk).map(st=>({name:st,skills:[...ut[st]].sort(Vk)}));return qe.sort(Uk),{sortedGroups:ze,ungrouped:qe}},e[30]=Q):Q=e[30];const L=Q;let J;e[31]!==V?(J=L(V),e[31]=V,e[32]=J):J=e[32];const ee=J;let re;e[33]!==z?(re=L(z),e[33]=z,e[34]=re):re=e[34];const q=re;let ce;e[35]===Symbol.for("react.memo_cache_sentinel")?(ce=ue("flex h-full flex-col","bg-background"),e[35]=ce):ce=e[35];let ae;e[36]!==r?(ae=r("settings.skills.sidebar.title"),e[36]=r,e[37]=ae):ae=e[37];let R;e[38]!==ae?(R=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:ae}),e[38]=ae,e[39]=R):R=e[39];let U;e[40]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(po,{className:"mb-3"}),e[40]=U):U=e[40];let W;e[41]!==v.length||e[42]!==r?(W=r("settings.skills.sidebar.total",{count:v.length}),e[41]=v.length,e[42]=r,e[43]=W):W=e[43];let Z;e[44]!==W?(Z=s.jsx("span",{className:"typography-meta text-muted-foreground",children:W}),e[44]=W,e[45]=Z):Z=e[45];let K;e[46]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e[46]=K):K=e[46];let ie;e[47]!==j?(ie=s.jsx(xe,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:K}),e[47]=j,e[48]=ie):ie=e[48];let Ne;e[49]!==Z||e[50]!==ie?(Ne=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Z,ie]}),e[49]=Z,e[50]=ie,e[51]=Ne):Ne=e[51];let ne;e[52]!==R||e[53]!==Ne?(ne=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[R,U,Ne]}),e[52]=R,e[53]=Ne,e[54]=ne):ne=e[54];let fe;e[55]!==ee||e[56]!==q||e[57]!==N||e[58]!==n||e[59]!==f||e[60]!==V||e[61]!==h||e[62]!==x||e[63]!==v.length||e[64]!==r||e[65]!==z?(fe=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[V.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.project")}),ee.sortedGroups.map(_e=>{const{name:tt,skills:ut}=_e;return s.jsx(xd,{label:tt,count:ut.length,storageKey:"project-skills",children:ut.map(qe=>s.jsx(Eo,{skill:qe,isSelected:h===qe.name,onSelect:()=>{x(qe.name),n?.()},onRename:()=>M(qe),onDelete:()=>D(qe),onDuplicate:()=>N(qe),isMenuOpen:f===qe.name,onMenuOpenChange:ze=>b(ze?qe.name:null)},qe.name))},tt)}),ee.ungrouped.map(_e=>s.jsx(Eo,{skill:_e,isSelected:h===_e.name,onSelect:()=>{x(_e.name),n?.()},onRename:()=>M(_e),onDelete:()=>D(_e),onDuplicate:()=>N(_e),isMenuOpen:f===_e.name,onMenuOpenChange:tt=>b(tt?_e.name:null)},_e.name))]}),z.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.user")}),q.sortedGroups.map(_e=>{const{name:tt,skills:ut}=_e;return s.jsx(xd,{label:tt,count:ut.length,storageKey:"user-skills",children:ut.map(qe=>s.jsx(Eo,{skill:qe,isSelected:h===qe.name,onSelect:()=>{x(qe.name),n?.()},onRename:()=>M(qe),onDelete:()=>D(qe),onDuplicate:()=>N(qe),isMenuOpen:f===qe.name,onMenuOpenChange:ze=>b(ze?qe.name:null)},qe.name))},tt)}),q.ungrouped.map(_e=>s.jsx(Eo,{skill:_e,isSelected:h===_e.name,onSelect:()=>{x(_e.name),n?.()},onRename:()=>M(_e),onDelete:()=>D(_e),onDuplicate:()=>N(_e),isMenuOpen:f===_e.name,onMenuOpenChange:tt=>b(tt?_e.name:null)},_e.name))]})]})}),e[55]=ee,e[56]=q,e[57]=N,e[58]=n,e[59]=f,e[60]=V,e[61]=h,e[62]=x,e[63]=v.length,e[64]=r,e[65]=z,e[66]=fe):fe=e[66];const pe=d!==null;let je;e[67]!==m?(je=_e=>{!_e&&!m&&p(null)},e[67]=m,e[68]=je):je=e[68];let oe;e[69]!==r?(oe=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=oe):oe=e[70];let Se;e[71]!==oe?(Se=s.jsx(gs,{children:oe}),e[71]=oe,e[72]=Se):Se=e[72];const se=d?.name??"";let we;e[73]!==r||e[74]!==se?(we=r("settings.skills.sidebar.deleteDialog.description",{name:se}),e[73]=r,e[74]=se,e[75]=we):we=e[75];let Ae;e[76]!==we?(Ae=s.jsx(Ps,{children:we}),e[76]=we,e[77]=Ae):Ae=e[77];let ve;e[78]!==Se||e[79]!==Ae?(ve=s.jsxs(vs,{children:[Se,Ae]}),e[78]=Se,e[79]=Ae,e[80]=ve):ve=e[80];let ye;e[81]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>p(null),e[81]=ye):ye=e[81];let Ie;e[82]!==r?(Ie=r("settings.common.actions.cancel"),e[82]=r,e[83]=Ie):Ie=e[83];let he;e[84]!==m||e[85]!==Ie?(he=s.jsx(xe,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:ye,disabled:m,children:Ie}),e[84]=m,e[85]=Ie,e[86]=he):he=e[86];let me;e[87]!==r?(me=r("settings.common.actions.delete"),e[87]=r,e[88]=me):me=e[88];let Ee;e[89]!==P||e[90]!==m||e[91]!==me?(Ee=s.jsx(xe,{size:"sm",onClick:P,disabled:m,children:me}),e[89]=P,e[90]=m,e[91]=me,e[92]=Ee):Ee=e[92];let Ve;e[93]!==he||e[94]!==Ee?(Ve=s.jsxs(Us,{children:[he,Ee]}),e[93]=he,e[94]=Ee,e[95]=Ve):Ve=e[95];let Y;e[96]!==ve||e[97]!==Ve?(Y=s.jsxs(ms,{className:"max-w-md",children:[ve,Ve]}),e[96]=ve,e[97]=Ve,e[98]=Y):Y=e[98];let ke;e[99]!==pe||e[100]!==je||e[101]!==Y?(ke=s.jsx(ps,{open:pe,onOpenChange:je,children:Y}),e[99]=pe,e[100]=je,e[101]=Y,e[102]=ke):ke=e[102];const Be=a!==null;let Ce;e[103]===Symbol.for("react.memo_cache_sentinel")?(Ce=_e=>!_e&&i(null),e[103]=Ce):Ce=e[103];let ge;e[104]!==r?(ge=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=ge):ge=e[105];let O;e[106]!==ge?(O=s.jsx(gs,{children:ge}),e[106]=ge,e[107]=O):O=e[107];const X=a?.name??"";let G;e[108]!==r||e[109]!==X?(G=r("settings.skills.sidebar.renameDialog.description",{name:X}),e[108]=r,e[109]=X,e[110]=G):G=e[110];let Te;e[111]!==G?(Te=s.jsx(Ps,{children:G}),e[111]=G,e[112]=Te):Te=e[112];let le;e[113]!==O||e[114]!==Te?(le=s.jsxs(vs,{children:[O,Te]}),e[113]=O,e[114]=Te,e[115]=le):le=e[115];let We;e[116]===Symbol.for("react.memo_cache_sentinel")?(We=_e=>c(_e.target.value),e[116]=We):We=e[116];let de;e[117]!==r?(de=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=de):de=e[118];let Fe;e[119]!==_?(Fe=_e=>{_e.key==="Enter"&&_()},e[119]=_,e[120]=Fe):Fe=e[120];let rt;e[121]!==o||e[122]!==de||e[123]!==Fe?(rt=s.jsx(Vt,{value:o,onChange:We,placeholder:de,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Fe}),e[121]=o,e[122]=de,e[123]=Fe,e[124]=rt):rt=e[124];let Oe;e[125]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>i(null),e[125]=Oe):Oe=e[125];let Ye;e[126]!==r?(Ye=r("settings.common.actions.cancel"),e[126]=r,e[127]=Ye):Ye=e[127];let Ge;e[128]!==Ye?(Ge=s.jsx(xe,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Oe,children:Ye}),e[128]=Ye,e[129]=Ge):Ge=e[129];let it;e[130]!==r?(it=r("settings.common.actions.rename"),e[130]=r,e[131]=it):it=e[131];let Qe;e[132]!==_||e[133]!==it?(Qe=s.jsx(xe,{size:"sm",onClick:_,children:it}),e[132]=_,e[133]=it,e[134]=Qe):Qe=e[134];let at;e[135]!==Ge||e[136]!==Qe?(at=s.jsxs(Us,{children:[Ge,Qe]}),e[135]=Ge,e[136]=Qe,e[137]=at):at=e[137];let nt;e[138]!==le||e[139]!==rt||e[140]!==at?(nt=s.jsxs(ms,{children:[le,rt,at]}),e[138]=le,e[139]=rt,e[140]=at,e[141]=nt):nt=e[141];let be;e[142]!==Be||e[143]!==nt?(be=s.jsx(ps,{open:Be,onOpenChange:Ce,children:nt}),e[142]=Be,e[143]=nt,e[144]=be):be=e[144];let He;return e[145]!==ne||e[146]!==fe||e[147]!==ke||e[148]!==be?(He=s.jsxs("div",{className:ce,children:[ne,fe,ke,be]}),e[145]=ne,e[146]=fe,e[147]=ke,e[148]=be,e[149]=He):He=e[149],He},Eo=t=>{const e=ot.c(61),{skill:n,isSelected:r,onSelect:a,onDelete:i,onRename:o,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=pt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Qi(),e[0]=u):u=e[0];const f=u;let b;e[1]!==n.source||e[2]!==m?(b=n.source==="claude"?m("settings.skills.sidebar.badge.claude"):n.source==="agents"?m("settings.skills.sidebar.badge.agents"):m("settings.skills.sidebar.badge.opencode"),e[1]=n.source,e[2]=m,e[3]=b):b=e[3];const h=b,v=r?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[4]!==v?(x=ue("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",v),e[4]=v,e[5]=x):x=e[5];let g;e[6]!==p?(g=f?void 0:ee=>{ee.preventDefault(),p(!0)},e[6]=p,e[7]=g):g=e[7];let w;e[8]!==n.name?(w=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[8]=n.name,e[9]=w):w=e[9];let y;e[10]!==n.scope?(y=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:n.scope}),e[10]=n.scope,e[11]=y):y=e[11];let k;e[12]!==h?(k=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:h}),e[12]=h,e[13]=k):k=e[13];let A;e[14]!==w||e[15]!==y||e[16]!==k?(A=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,y,k]}),e[14]=w,e[15]=y,e[16]=k,e[17]=A):A=e[17];let j;e[18]!==a||e[19]!==A?(j=s.jsx("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:A}),e[18]=a,e[19]=A,e[20]=j):j=e[20];let S;e[21]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(Es,{asChild:!0,children:s.jsx(xe,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[21]=S):S=e[21];let D;e[22]!==o?(D=ee=>{ee.stopPropagation(),o()},e[22]=o,e[23]=D):D=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(I,{name:"edit",className:"h-4 w-4 mr-px"}),e[24]=E):E=e[24];let P;e[25]!==m?(P=m("settings.common.actions.rename"),e[25]=m,e[26]=P):P=e[26];let C;e[27]!==D||e[28]!==P?(C=s.jsxs($t,{onClick:D,children:[E,P]}),e[27]=D,e[28]=P,e[29]=C):C=e[29];let N;e[30]!==c?(N=ee=>{ee.stopPropagation(),c()},e[30]=c,e[31]=N):N=e[31];let T;e[32]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(I,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[32]=T):T=e[32];let M;e[33]!==m?(M=m("settings.common.actions.duplicate"),e[33]=m,e[34]=M):M=e[34];let F;e[35]!==N||e[36]!==M?(F=s.jsxs($t,{onClick:N,children:[T,M]}),e[35]=N,e[36]=M,e[37]=F):F=e[37];let _;e[38]!==i?(_=ee=>{ee.stopPropagation(),i()},e[38]=i,e[39]=_):_=e[39];let B;e[40]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),e[40]=B):B=e[40];let V;e[41]!==m?(V=m("settings.common.actions.delete"),e[41]=m,e[42]=V):V=e[42];let $;e[43]!==_||e[44]!==V?($=s.jsxs($t,{onClick:_,className:"text-destructive focus:text-destructive",children:[B,V]}),e[43]=_,e[44]=V,e[45]=$):$=e[45];let z;e[46]!==C||e[47]!==F||e[48]!==$?(z=s.jsxs(Rs,{align:"end",className:"w-fit min-w-20",children:[C,F,$]}),e[46]=C,e[47]=F,e[48]=$,e[49]=z):z=e[49];let Q;e[50]!==d||e[51]!==p||e[52]!==z?(Q=s.jsxs(Fs,{open:d,onOpenChange:p,children:[S,z]}),e[50]=d,e[51]=p,e[52]=z,e[53]=Q):Q=e[53];let L;e[54]!==j||e[55]!==Q?(L=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[j,Q]}),e[54]=j,e[55]=Q,e[56]=L):L=e[56];let J;return e[57]!==L||e[58]!==x||e[59]!==g?(J=s.jsx("div",{className:x,onContextMenu:g,children:L}),e[57]=L,e[58]=x,e[59]=g,e[60]=J):J=e[60],J};function $k(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function Bk(t){return t.scope==="project"}function _k(t){return t.scope==="user"}function zk(t,e){return t.localeCompare(e)}function Vk(t,e){return t.name.localeCompare(e.name)}function Uk(t,e){return t.name.localeCompare(e.name)}const Wk=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Kk=t=>{const e=t.trim(),n=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(n==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(n==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const r=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return r?`${r[1]}/${r[2].replace(/\.git$/i,"")}`:e},Hk=async()=>{try{const t=sr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Gk=t=>{const e=ot.c(158),{open:n,onOpenChange:r}=t,{t:a}=pt(),i=Pa(qk),o=Pa(Yk),c=Pa(Jk),d=Jn(Qk),p=Jn(Xk),[m,u]=l.useState(""),[f,b]=l.useState(""),[h,v]=l.useState("");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=[],e[0]=x):x=e[0];const[g,w]=l.useState(x),[y,k]=l.useState(null),[A,j]=l.useState(!1);let S;e[1]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[1]=S):S=e[1];const[D,E]=l.useState(S),[P,C]=l.useState(null),N=l.useRef(0);let T;e[2]===Symbol.for("react.memo_cache_sentinel")?(T=be=>{N.current=N.current+1,j(!1),k(null),be?.clearIdentity&&(E([]),C(null))},e[2]=T):T=e[2];const M=T;let F,_;e[3]!==p||e[4]!==n?(F=()=>{n&&(N.current=N.current+1,u(""),b(""),v(""),k(null),j(!1),E([]),C(null),p(),(async()=>{const be=await Hk(),He=Array.isArray(be?.skillCatalogs)?be?.skillCatalogs:[];w(He||[])})())},_=[n,p],e[3]=p,e[4]=n,e[5]=F,e[6]=_):(F=e[5],_=e[6]),l.useEffect(F,_);let B;e[7]!==f?(B=f.trim(),e[7]=f,e[8]=B):B=e[8];const V=B;let $;e[9]!==h?($=h.trim(),e[9]=h,e[10]=$):$=e[10];const z=$;let Q;if(e[11]!==g||e[12]!==V||e[13]!==z){let be;e[15]!==V||e[16]!==z?(be=He=>{const _e=(He.source||"").trim(),tt=(He.subpath||"").trim();return _e===V&&tt===z},e[15]=V,e[16]=z,e[17]=be):be=e[17],Q=g.some(be),e[11]=g,e[12]=V,e[13]=z,e[14]=Q}else Q=e[14];const L=Q;let J;e[18]!==d||e[19]!==P||e[20]!==m||e[21]!==i||e[22]!==f||e[23]!==h||e[24]!==a?(J=async()=>{const be=f.trim();if(!be){H.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(Kk(be)),j(!1),k(null);const He=N.current+1;N.current=He;const _e=await i({source:be,subpath:h.trim()||void 0,gitIdentityId:P||void 0});if(N.current!==He)return;if(!_e.ok){if(_e.error?.kind==="authRequired"){if(ln()){H.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const ut=_e.error.identities||[];if(E(ut),!P&&ut.length>0){const qe=d&&d!=="global"&&ut.some(ze=>ze.id===d)?d:ut[0].id;C(qe)}H.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}H.error(_e.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const tt=_e.items?.length||0;if(k(tt),tt===0){H.error(a("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}E([]),j(!0),H.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:tt}))},e[18]=d,e[19]=P,e[20]=m,e[21]=i,e[22]=f,e[23]=h,e[24]=a,e[25]=J):J=e[25];const ee=J;let re;e[26]!==g||e[27]!==P||e[28]!==L||e[29]!==m||e[30]!==o||e[31]!==r||e[32]!==A||e[33]!==f||e[34]!==h||e[35]!==a?(re=async()=>{const be=m.trim(),He=f.trim(),_e=h.trim();if(!be){H.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!He){H.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!A){H.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(L){H.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const tt={id:Wk(),label:be,source:He,..._e?{subpath:_e}:{},...P?{gitIdentityId:P}:{}},ut=[...g,tt];try{await Is({skillCatalogs:ut}),w(ut),H.success(a("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),r(!1)}catch(qe){const ze=qe;H.error(ze instanceof Error?ze.message:a("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=g,e[27]=P,e[28]=L,e[29]=m,e[30]=o,e[31]=r,e[32]=A,e[33]=f,e[34]=h,e[35]=a,e[36]=re):re=e[36];const q=re;let ce;e[37]!==a?(ce=a("settings.skills.catalog.add.title"),e[37]=a,e[38]=ce):ce=e[38];let ae;e[39]!==ce?(ae=s.jsx(gs,{children:ce}),e[39]=ce,e[40]=ae):ae=e[40];let R;e[41]!==a?(R=a("settings.skills.catalog.add.descriptionPrefix"),e[41]=a,e[42]=R):R=e[42];let U;e[43]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[43]=U):U=e[43];let W;e[44]!==a?(W=a("settings.skills.catalog.add.descriptionSuffix"),e[44]=a,e[45]=W):W=e[45];let Z;e[46]!==R||e[47]!==W?(Z=s.jsxs(Ps,{children:[R," ",U,W]}),e[46]=R,e[47]=W,e[48]=Z):Z=e[48];let K;e[49]!==ae||e[50]!==Z?(K=s.jsxs(vs,{children:[ae,Z]}),e[49]=ae,e[50]=Z,e[51]=K):K=e[51];let ie;e[52]!==a?(ie=a("settings.skills.catalog.add.field.catalogName"),e[52]=a,e[53]=ie):ie=e[53];let Ne;e[54]!==ie?(Ne=s.jsx("label",{className:"typography-ui-label text-foreground",children:ie}),e[54]=ie,e[55]=Ne):Ne=e[55];let ne;e[56]===Symbol.for("react.memo_cache_sentinel")?(ne=be=>u(be.target.value),e[56]=ne):ne=e[56];let fe;e[57]!==a?(fe=a("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=a,e[58]=fe):fe=e[58];let pe;e[59]!==m||e[60]!==fe?(pe=s.jsx(Vt,{value:m,onChange:ne,placeholder:fe}),e[59]=m,e[60]=fe,e[61]=pe):pe=e[61];let je;e[62]!==Ne||e[63]!==pe?(je=s.jsxs("div",{className:"space-y-2",children:[Ne,pe]}),e[62]=Ne,e[63]=pe,e[64]=je):je=e[64];let oe;e[65]!==a?(oe=a("settings.skills.catalog.add.field.repository"),e[65]=a,e[66]=oe):oe=e[66];let Se;e[67]!==oe?(Se=s.jsx("label",{className:"typography-ui-label text-foreground",children:oe}),e[67]=oe,e[68]=Se):Se=e[68];let se;e[69]===Symbol.for("react.memo_cache_sentinel")?(se=be=>{b(be.target.value),M({clearIdentity:!0})},e[69]=se):se=e[69];let we;e[70]!==a?(we=a("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[70]=a,e[71]=we):we=e[71];let Ae;e[72]!==f||e[73]!==we?(Ae=s.jsx(Vt,{value:f,onChange:se,placeholder:we}),e[72]=f,e[73]=we,e[74]=Ae):Ae=e[74];let ve;e[75]!==a?(ve=a("settings.skills.catalog.add.field.repositoryHint"),e[75]=a,e[76]=ve):ve=e[76];let ye;e[77]!==ve?(ye=s.jsx("p",{className:"typography-micro text-muted-foreground",children:ve}),e[77]=ve,e[78]=ye):ye=e[78];let Ie;e[79]!==Se||e[80]!==Ae||e[81]!==ye?(Ie=s.jsxs("div",{className:"space-y-2",children:[Se,Ae,ye]}),e[79]=Se,e[80]=Ae,e[81]=ye,e[82]=Ie):Ie=e[82];let he;e[83]!==a?(he=a("settings.skills.catalog.add.field.optionalSubpath"),e[83]=a,e[84]=he):he=e[84];let me;e[85]!==he?(me=s.jsx("label",{className:"typography-ui-label text-foreground",children:he}),e[85]=he,e[86]=me):me=e[86];let Ee;e[87]===Symbol.for("react.memo_cache_sentinel")?(Ee=be=>{v(be.target.value),M({clearIdentity:!0})},e[87]=Ee):Ee=e[87];let Ve;e[88]!==a?(Ve=a("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=a,e[89]=Ve):Ve=e[89];let Y;e[90]!==h||e[91]!==Ve?(Y=s.jsx(Vt,{value:h,onChange:Ee,placeholder:Ve}),e[90]=h,e[91]=Ve,e[92]=Y):Y=e[92];let ke;e[93]!==me||e[94]!==Y?(ke=s.jsxs("div",{className:"space-y-2",children:[me,Y]}),e[93]=me,e[94]=Y,e[95]=ke):ke=e[95];let Be;e[96]!==P||e[97]!==D||e[98]!==a?(Be=D.length>0&&!ln()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:a("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:a("settings.skills.catalog.shared.auth.description")})]}),s.jsxs(is,{value:P||"",onValueChange:be=>{C(be),M()},children:[s.jsx(os,{className:"w-fit",children:s.jsx("span",{children:D.find(be=>be.id===P)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(ls,{align:"start",children:D.map(Zk)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=P,e[97]=D,e[98]=a,e[99]=Be):Be=e[99];let Ce;e[100]!==y||e[101]!==a?(Ce=y!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:y})}):null,e[100]=y,e[101]=a,e[102]=Ce):Ce=e[102];let ge;e[103]!==L||e[104]!==a?(ge=L?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=L,e[104]=a,e[105]=ge):ge=e[105];let O;e[106]!==je||e[107]!==Ie||e[108]!==ke||e[109]!==Be||e[110]!==Ce||e[111]!==ge?(O=s.jsxs("div",{className:"space-y-4",children:[je,Ie,ke,Be,Ce,ge]}),e[106]=je,e[107]=Ie,e[108]=ke,e[109]=Be,e[110]=Ce,e[111]=ge,e[112]=O):O=e[112];let X;e[113]!==r?(X=()=>r(!1),e[113]=r,e[114]=X):X=e[114];let G;e[115]!==a?(G=a("settings.common.actions.cancel"),e[115]=a,e[116]=G):G=e[116];let Te;e[117]!==X||e[118]!==G?(Te=s.jsx(xe,{size:"sm",variant:"ghost",onClick:X,children:G}),e[117]=X,e[118]=G,e[119]=Te):Te=e[119];let le;e[120]!==ee?(le=()=>{ee()},e[120]=ee,e[121]=le):le=e[121];let We;e[122]!==c||e[123]!==f?(We=c||!f.trim(),e[122]=c,e[123]=f,e[124]=We):We=e[124];let de;e[125]===Symbol.for("react.memo_cache_sentinel")?(de=s.jsx(I,{name:"git-repository",className:"h-4 w-4"}),e[125]=de):de=e[125];let Fe;e[126]!==c||e[127]!==a?(Fe=a(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=a,e[128]=Fe):Fe=e[128];let rt;e[129]!==le||e[130]!==We||e[131]!==Fe?(rt=s.jsxs(xe,{size:"sm",className:"gap-2",variant:"ghost",onClick:le,disabled:We,children:[de,Fe]}),e[129]=le,e[130]=We,e[131]=Fe,e[132]=rt):rt=e[132];let Oe;e[133]!==q?(Oe=()=>{q()},e[133]=q,e[134]=Oe):Oe=e[134];let Ye;e[135]!==L||e[136]!==m||e[137]!==A||e[138]!==f?(Ye=!A||L||!m.trim()||!f.trim(),e[135]=L,e[136]=m,e[137]=A,e[138]=f,e[139]=Ye):Ye=e[139];let Ge;e[140]!==a?(Ge=a("settings.skills.catalog.add.actions.addCatalog"),e[140]=a,e[141]=Ge):Ge=e[141];let it;e[142]!==Oe||e[143]!==Ye||e[144]!==Ge?(it=s.jsx(xe,{size:"sm",onClick:Oe,disabled:Ye,children:Ge}),e[142]=Oe,e[143]=Ye,e[144]=Ge,e[145]=it):it=e[145];let Qe;e[146]!==Te||e[147]!==rt||e[148]!==it?(Qe=s.jsxs(Us,{children:[Te,rt,it]}),e[146]=Te,e[147]=rt,e[148]=it,e[149]=Qe):Qe=e[149];let at;e[150]!==K||e[151]!==O||e[152]!==Qe?(at=s.jsxs(ms,{className:"max-w-xl",children:[K,O,Qe]}),e[150]=K,e[151]=O,e[152]=Qe,e[153]=at):at=e[153];let nt;return e[154]!==r||e[155]!==n||e[156]!==at?(nt=s.jsx(ps,{open:n,onOpenChange:r,children:at}),e[154]=r,e[155]=n,e[156]=at,e[157]=nt):nt=e[157],nt};function qk(t){return t.scanRepo}function Yk(t){return t.loadCatalog}function Jk(t){return t.isScanning}function Qk(t){return t.defaultGitIdentityId}function Xk(t){return t.loadDefaultGitIdentityId}function Zk(t){return s.jsx(Ft,{value:t.id,children:t.name},t.id)}const e3=t=>{const e=ot.c(85),{open:n,onOpenChange:r,conflicts:a,onConfirm:i}=t,{t:o}=pt();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[d,p]=l.useState(c);let m,u;e[1]!==a||e[2]!==n?(m=()=>{if(!n)return;const ae={};for(const R of a)ae[R.skillName]="skip";p(ae)},u=[n,a],e[1]=a,e[2]=n,e[3]=m,e[4]=u):(m=e[3],u=e[4]),l.useEffect(m,u);let f;e[5]!==a?(f=ae=>{const R={};for(const U of a)R[U.skillName]=ae;p(R)},e[5]=a,e[6]=f):f=e[6];const b=f;let h;e[7]!==a||e[8]!==d?(h=a.length>0&&a.every(ae=>d[ae.skillName]),e[7]=a,e[8]=d,e[9]=h):h=e[9];const v=h;let x;e[10]!==o?(x=o("settings.skills.catalog.conflicts.title"),e[10]=o,e[11]=x):x=e[11];let g;e[12]!==x?(g=s.jsx(gs,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==o?(w=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=w):w=e[15];let y;e[16]!==w?(y=s.jsx(Ps,{children:w}),e[16]=w,e[17]=y):y=e[17];let k;e[18]!==g||e[19]!==y?(k=s.jsxs(vs,{children:[g,y]}),e[18]=g,e[19]=y,e[20]=k):k=e[20];let A;e[21]!==a.length||e[22]!==o?(A=o("settings.skills.catalog.conflicts.count",{count:a.length}),e[21]=a.length,e[22]=o,e[23]=A):A=e[23];let j;e[24]!==A?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:A}),e[24]=A,e[25]=j):j=e[25];let S;e[26]!==b?(S=()=>b("skip"),e[26]=b,e[27]=S):S=e[27];let D;e[28]!==o?(D=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=D):D=e[29];let E;e[30]!==S||e[31]!==D?(E=s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:S,children:D}),e[30]=S,e[31]=D,e[32]=E):E=e[32];let P;e[33]!==b?(P=()=>b("overwrite"),e[33]=b,e[34]=P):P=e[34];let C;e[35]!==o?(C=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=C):C=e[36];let N;e[37]!==P||e[38]!==C?(N=s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:P,children:C}),e[37]=P,e[38]=C,e[39]=N):N=e[39];let T;e[40]!==E||e[41]!==N?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[E,N]}),e[40]=E,e[41]=N,e[42]=T):T=e[42];let M;e[43]!==j||e[44]!==T?(M=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,T]}),e[43]=j,e[44]=T,e[45]=M):M=e[45];let F;if(e[46]!==a||e[47]!==d||e[48]!==o){let ae;e[50]!==d||e[51]!==o?(ae=R=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:R.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:R.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:R.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(is,{value:d[R.skillName]||"skip",onValueChange:U=>p(W=>({...W,[R.skillName]:U})),children:[s.jsx(os,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[R.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(ls,{align:"end",children:[s.jsx(Ft,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Ft,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},R.skillName),e[50]=d,e[51]=o,e[52]=ae):ae=e[52],F=a.map(ae),e[46]=a,e[47]=d,e[48]=o,e[49]=F}else F=e[49];let _;e[53]!==F?(_=s.jsx("div",{className:"space-y-2",children:F}),e[53]=F,e[54]=_):_=e[54];let B;e[55]!==M||e[56]!==_?(B=s.jsxs("div",{className:"space-y-3",children:[M,_]}),e[55]=M,e[56]=_,e[57]=B):B=e[57];let V;e[58]!==r?(V=()=>r(!1),e[58]=r,e[59]=V):V=e[59];let $;e[60]!==o?($=o("settings.common.actions.cancel"),e[60]=o,e[61]=$):$=e[61];let z;e[62]!==V||e[63]!==$?(z=s.jsx(xe,{size:"sm",variant:"ghost",onClick:V,children:$}),e[62]=V,e[63]=$,e[64]=z):z=e[64];let Q;e[65]!==d||e[66]!==i?(Q=()=>i(d),e[65]=d,e[66]=i,e[67]=Q):Q=e[67];const L=!v;let J;e[68]!==o?(J=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=J):J=e[69];let ee;e[70]!==Q||e[71]!==L||e[72]!==J?(ee=s.jsx(xe,{size:"sm",onClick:Q,disabled:L,children:J}),e[70]=Q,e[71]=L,e[72]=J,e[73]=ee):ee=e[73];let re;e[74]!==z||e[75]!==ee?(re=s.jsxs(Us,{children:[z,ee]}),e[74]=z,e[75]=ee,e[76]=re):re=e[76];let q;e[77]!==k||e[78]!==B||e[79]!==re?(q=s.jsxs(ms,{className:"max-w-2xl",children:[k,B,re]}),e[77]=k,e[78]=B,e[79]=re,e[80]=q):q=e[80];let ce;return e[81]!==r||e[82]!==n||e[83]!==q?(ce=s.jsx(ps,{open:n,onOpenChange:r,children:q}),e[81]=r,e[82]=n,e[83]=q,e[84]=ce):ce=e[84],ce},tu=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function Hi(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function fg(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=tu.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const t3=t=>{const e=ot.c(124),{open:n,onOpenChange:r,item:a}=t,{t:i}=pt(),o=Pa(s3),c=Pa(n3),[d,p]=l.useState("user"),[m,u]=l.useState("opencode"),f=Ts(r3),b=Ts(a3),[h,v]=l.useState(null),[x,g]=l.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=[],e[0]=w):w=e[0];const[y,k]=l.useState(w),[A,j]=l.useState(null);let S,D;e[1]!==b||e[2]!==n?(S=()=>{n&&(p("user"),u("opencode"),v(b),g(!1),k([]),j(null))},D=[n,b],e[1]=b,e[2]=n,e[3]=S,e[4]=D):(S=e[3],D=e[4]),l.useEffect(S,D);let E;e[5]!==i?(E=Ce=>{switch(Ce){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=E):E=e[6];const P=E;let C;e[7]!==i?(C=Ce=>{switch(Ce){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=C):C=e[8];const N=C;let T;e:{if(f.length===0){T=null;break e}if(h&&f.some(Ce=>Ce.id===h)){T=h;break e}if(b&&f.some(Ce=>Ce.id===b)){T=b;break e}T=f[0]?.id??null}const M=T;let F;e:{if(d!=="project"){F=null;break e}const Ce=M;if(!Ce){F=null;break e}let ge;if(e[9]!==Ce||e[10]!==f){let X;e[12]!==Ce?(X=G=>G.id===Ce,e[12]=Ce,e[13]=X):X=e[13],ge=f.find(X),e[9]=Ce,e[10]=f,e[11]=ge}else ge=e[11];F=ge?.path??null}const _=F;let B;e[14]!==o||e[15]!==a||e[16]!==r||e[17]!==i?(B=async Ce=>{const ge={skillDir:Ce.skillDir};a?.clawdhub&&(ge.clawdhub={slug:a.clawdhub.slug,version:a.clawdhub.version});const O=await o({source:Ce.source,subpath:Ce.subpath,gitIdentityId:a?.gitIdentityId,scope:Ce.scope,targetSource:Ce.targetSource,selections:[ge],conflictPolicy:"prompt",conflictDecisions:Ce.conflictDecisions},{directory:Ce.directoryOverride??null});if(O.ok){H.success(i("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(O.error?.kind==="conflicts"){j({source:Ce.source,subpath:Ce.subpath,scope:Ce.scope,targetSource:Ce.targetSource,skillDir:Ce.skillDir,directoryOverride:Ce.directoryOverride??null}),k(O.error.conflicts),g(!0);return}if(O.error?.kind==="authRequired"){H.error(O.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}H.error(O.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=o,e[15]=a,e[16]=r,e[17]=i,e[18]=B):B=e[18];const V=B;if(!a)return null;let $;e[19]!==i?($=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=$):$=e[20];let z;e[21]!==$?(z=s.jsx(gs,{children:$}),e[21]=$,e[22]=z):z=e[22];let Q;e[23]!==i?(Q=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=Q):Q=e[24];let L;e[25]!==a.skillName?(L=s.jsx("span",{className:"font-semibold text-foreground",children:a.skillName}),e[25]=a.skillName,e[26]=L):L=e[26];let J;e[27]!==i?(J=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=J):J=e[28];let ee;e[29]!==Q||e[30]!==L||e[31]!==J?(ee=s.jsxs(Ps,{children:[Q," ",L," ",J]}),e[29]=Q,e[30]=L,e[31]=J,e[32]=ee):ee=e[32];let re;e[33]!==z||e[34]!==ee?(re=s.jsxs(vs,{children:[z,ee]}),e[33]=z,e[34]=ee,e[35]=re):re=e[35];let q;e[36]!==i?(q=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=q):q=e[37];let ce;e[38]!==q?(ce=s.jsx("span",{className:"typography-ui-label text-foreground",children:q}),e[38]=q,e[39]=ce):ce=e[39];let ae;e[40]!==d||e[41]!==m?(ae=Hi(d,m),e[40]=d,e[41]=m,e[42]=ae):ae=e[42];let R;e[43]===Symbol.for("react.memo_cache_sentinel")?(R=Ce=>{const ge=fg(Ce);p(ge.scope),u(ge.source==="agents"?"agents":"opencode")},e[43]=R):R=e[43];let U;e[44]!==d?(U=d==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=U):U=e[45];let W;e[46]!==m?(W=m==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=W):W=e[47];let Z;e[48]!==P||e[49]!==d||e[50]!==m?(Z=P(Hi(d,m)),e[48]=P,e[49]=d,e[50]=m,e[51]=Z):Z=e[51];let K;e[52]!==Z?(K=s.jsx("span",{children:Z}),e[52]=Z,e[53]=K):K=e[53];let ie;e[54]!==U||e[55]!==W||e[56]!==K?(ie=s.jsxs(os,{className:"w-fit gap-1.5",children:[U,W,K]}),e[54]=U,e[55]=W,e[56]=K,e[57]=ie):ie=e[57];let Ne;e[58]!==N||e[59]!==P?(Ne=tu.map(Ce=>s.jsx(Ft,{value:Ce.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[Ce.scope==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),Ce.source==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:P(Ce.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:N(Ce.value)})]})},Ce.value)),e[58]=N,e[59]=P,e[60]=Ne):Ne=e[60];let ne;e[61]!==Ne?(ne=s.jsx(ls,{align:"start",children:Ne}),e[61]=Ne,e[62]=ne):ne=e[62];let fe;e[63]!==ae||e[64]!==ie||e[65]!==ne?(fe=s.jsxs(is,{value:ae,onValueChange:R,children:[ie,ne]}),e[63]=ae,e[64]=ie,e[65]=ne,e[66]=fe):fe=e[66];let pe;e[67]!==ce||e[68]!==fe?(pe=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ce,fe]}),e[67]=ce,e[68]=fe,e[69]=pe):pe=e[69];let je;e[70]!==f||e[71]!==M||e[72]!==d||e[73]!==i?(je=d==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),f.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(is,{value:M??"",onValueChange:Ce=>v(Ce),disabled:f.length===1,children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(ls,{align:"start",children:f.map(i3)})]})]}),e[70]=f,e[71]=M,e[72]=d,e[73]=i,e[74]=je):je=e[74];let oe;e[75]!==a.warnings?(oe=a.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:a.warnings.join(" · ")}):null,e[75]=a.warnings,e[76]=oe):oe=e[76];let Se;e[77]!==pe||e[78]!==je||e[79]!==oe?(Se=s.jsxs("div",{className:"mt-2 space-y-3",children:[pe,je,oe]}),e[77]=pe,e[78]=je,e[79]=oe,e[80]=Se):Se=e[80];let se;e[81]!==r?(se=()=>r(!1),e[81]=r,e[82]=se):se=e[82];let we;e[83]!==i?(we=i("settings.common.actions.cancel"),e[83]=i,e[84]=we):we=e[84];let Ae;e[85]!==se||e[86]!==we?(Ae=s.jsx(xe,{size:"sm",variant:"ghost",onClick:se,children:we}),e[85]=se,e[86]=we,e[87]=Ae):Ae=e[87];const ve=c||!a.installable||d==="project"&&!_;let ye;e[88]!==_||e[89]!==V||e[90]!==a.repoSource||e[91]!==a.repoSubpath||e[92]!==a.skillDir||e[93]!==d||e[94]!==m?(ye=()=>{V({source:a.repoSource,subpath:a.repoSubpath,scope:d,targetSource:m,skillDir:a.skillDir,directoryOverride:_})},e[88]=_,e[89]=V,e[90]=a.repoSource,e[91]=a.repoSubpath,e[92]=a.skillDir,e[93]=d,e[94]=m,e[95]=ye):ye=e[95];let Ie;e[96]!==c||e[97]!==i?(Ie=i(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=i,e[98]=Ie):Ie=e[98];let he;e[99]!==ve||e[100]!==ye||e[101]!==Ie?(he=s.jsx(xe,{size:"sm",disabled:ve,onClick:ye,children:Ie}),e[99]=ve,e[100]=ye,e[101]=Ie,e[102]=he):he=e[102];let me;e[103]!==Ae||e[104]!==he?(me=s.jsxs(Us,{children:[Ae,he]}),e[103]=Ae,e[104]=he,e[105]=me):me=e[105];let Ee;e[106]!==re||e[107]!==Se||e[108]!==me?(Ee=s.jsxs(ms,{className:"max-w-md",children:[re,Se,me]}),e[106]=re,e[107]=Se,e[108]=me,e[109]=Ee):Ee=e[109];let Ve;e[110]!==r||e[111]!==n||e[112]!==Ee?(Ve=s.jsx(ps,{open:n,onOpenChange:r,children:Ee}),e[110]=r,e[111]=n,e[112]=Ee,e[113]=Ve):Ve=e[113];let Y;e[114]!==A||e[115]!==V?(Y=Ce=>{A&&(V({source:A.source,subpath:A.subpath,scope:A.scope,targetSource:A.targetSource,skillDir:A.skillDir,conflictDecisions:Ce,directoryOverride:A.directoryOverride??null}),g(!1))},e[114]=A,e[115]=V,e[116]=Y):Y=e[116];let ke;e[117]!==y||e[118]!==x||e[119]!==Y?(ke=s.jsx(e3,{open:x,onOpenChange:g,conflicts:y,onConfirm:Y}),e[117]=y,e[118]=x,e[119]=Y,e[120]=ke):ke=e[120];let Be;return e[121]!==Ve||e[122]!==ke?(Be=s.jsxs(s.Fragment,{children:[Ve,ke]}),e[121]=Ve,e[122]=ke,e[123]=Be):Be=e[123],Be};function s3(t){return t.installSkills}function n3(t){return t.isInstalling}function r3(t){return t.projects}function a3(t){return t.activeProjectId}function i3(t){return s.jsx(Ft,{value:t.id,children:t.label||t.path},t.id)}const o3=async()=>{try{const t=sr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},l3=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=pt(),{sources:a,itemsBySource:i,selectedSourceId:o,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:f,isLoadingMore:b,loadedSourceIds:h,clawdhubHasMoreBySource:v,lastCatalogError:x}=Pa(hr(z=>({sources:z.sources,itemsBySource:z.itemsBySource,selectedSourceId:z.selectedSourceId,setSelectedSource:z.setSelectedSource,loadCatalog:z.loadCatalog,loadSource:z.loadSource,loadMoreClawdHub:z.loadMoreClawdHub,isLoadingCatalog:z.isLoadingCatalog,isLoadingSource:z.isLoadingSource,isLoadingMore:z.isLoadingMore,loadedSourceIds:z.loadedSourceIds,clawdhubHasMoreBySource:z.clawdhubHasMoreBySource,lastCatalogError:z.lastCatalogError}))),[g,w]=l.useState(""),[y,k]=l.useState(!1),[A,j]=l.useState(!1),[S,D]=l.useState(null),[E,P]=l.useState(!1),[C,N]=l.useState(!1);l.useEffect(()=>{d()},[d]),l.useEffect(()=>{o&&(h[o]||p(o))},[o,h,p]);const T=l.useMemo(()=>o?i[o]||[]:[],[i,o]),M=l.useMemo(()=>{const z=g.trim().toLowerCase();return z?T.filter(Q=>{const L=Q.skillName.toLowerCase(),J=(Q.description||"").toLowerCase(),ee=(Q.frontmatterName||"").toLowerCase();return L.includes(z)||J.includes(z)||ee.includes(z)}):T},[T,g]),F=l.useMemo(()=>a.find(z=>z.id===o)||null,[a,o]),_=!!(o&&o.startsWith("custom:")),B=F?.source==="clawdhub:registry"||F?.sourceType==="clawdhub",V=!!(o&&(v[o]??!0)),$=async()=>{if(!(!o||!_)){P(!0);try{const z=await o3(),L=(Array.isArray(z?.skillCatalogs)?z?.skillCatalogs:[]).filter(J=>J.id!==o);await Is({skillCatalogs:L}),await d({refresh:!0}),N(!1)}finally{P(!1)}}};return s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4",children:[n&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(Er,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:z=>e(z),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground px-1",children:r("settings.skills.catalog.page.title")})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:r("settings.skills.catalog.page.section.sourceRepository")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsxs(is,{value:o||"",onValueChange:z=>c(z),children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:F?.label})}),s.jsx(ls,{align:"start",children:a.map(z=>s.jsx(Ft,{value:z.id,children:z.label},z.id))})]}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{o?p(o,{refresh:!0}):d({refresh:!0})},disabled:u||f,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(I,{name:"refresh",className:ue("h-3.5 w-3.5",(u||f)&&"animate-spin")})}),_&&s.jsx(xe,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>N(!0),disabled:E,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(xe,{size:"xs",className:"!font-normal gap-1",onClick:()=>k(!0),children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})," ",r("settings.skills.catalog.page.actions.addCatalog")]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Vt,{value:g,onChange:z=>w(z.target.value),placeholder:r("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:u?r("settings.skills.catalog.page.loading.catalog"):r("settings.skills.catalog.page.foundCount",{count:M.length})})]})]})]}),x&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:r("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x.message})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("section",{className:"px-2 pb-2 pt-0",children:M.length===0&&!f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:r("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.catalog.page.empty.noSkillsDescription")})]}):f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(I,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:r("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:M.map(z=>{const Q=z.installed?.isInstalled,L=z.installed?.scope;return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:z.skillName}),Q&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.installed",{scope:L||r("settings.skills.catalog.page.badge.unknown")})}),!z.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.notInstallable")})]}),z.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:z.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),z.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[z.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:z.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(I,{name:"download",className:"h-3 w-3"}),z.clawdhub.downloads?.toLocaleString()??0]}),(z.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(I,{name:"star",className:"h-3 w-3"}),z.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",z.clawdhub.version]})]}),z.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:z.warnings.join(" · ")}):null]}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!z.installable,onClick:()=>{D(z),j(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${z.sourceId}:${z.skillDir}`)})})}),B&&V&&!f&&M.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:b,children:r(b?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),s.jsx(Gk,{open:y,onOpenChange:k}),s.jsx(t3,{open:A,onOpenChange:j,item:S}),s.jsx(ps,{open:C,onOpenChange:z=>{E||N(z)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Ps,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Us,{children:[s.jsx(xe,{size:"sm",variant:"ghost",onClick:()=>N(!1),disabled:E,children:r("settings.common.actions.cancel")}),s.jsx(xe,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:E,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},c3=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(l3,{mode:"external",onModeChange:u3,showModeTabs:!1}),t[0]=e):e=t[0],e},d3=()=>{const{t}=pt(),{selectedSkillName:e,getSkillByName:n,getSkillDetail:r,createSkill:a,updateSkill:i,skills:o,skillDraft:c,setSkillDraft:d,setSelectedSkill:p}=ra(hr(ve=>({selectedSkillName:ve.selectedSkillName,getSkillByName:ve.getSkillByName,getSkillDetail:ve.getSkillDetail,createSkill:ve.createSkill,updateSkill:ve.updateSkill,skills:ve.skills,skillDraft:ve.skillDraft,setSkillDraft:ve.setSkillDraft,setSelectedSkill:ve.setSelectedSkill}))),m=e?n(e):null,u=!!(c&&c.name===e&&!m),f=!!(e&&!m&&!c);l.useEffect(()=>{f&&p(null)},[f,p]);const[b,h]=l.useState(""),[v,x]=l.useState("user"),[g,w]=l.useState("opencode"),[y,k]=l.useState(""),[A,j]=l.useState(""),[S,D]=l.useState([]),[E,P]=l.useState([]),[C,N]=l.useState(!1),[T,M]=l.useState(!1),[F,_]=l.useState(""),[B,V]=l.useState(""),[$,z]=l.useState(!1),[Q,L]=l.useState(""),[J,ee]=l.useState(""),[re,q]=l.useState(null),[ce,ae]=l.useState(!1),[R,U]=l.useState(""),[W,Z]=l.useState(null),[K,ie]=l.useState(!1),Ne=u?b.trim()!==""||y.trim()!==""||A.trim()!==""||E.length>0:y!==F||A!==B,ne=re?J!==R:Q.trim()!=="",fe=l.useCallback(ve=>{switch(ve){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),pe=l.useCallback(ve=>{switch(ve){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);l.useEffect(()=>{(async()=>{if(u&&c)h(c.name||""),x(c.scope||"user"),w(c.source==="agents"?"agents":"opencode"),k(c.description||""),j(c.instructions||""),_(""),V(""),D([]),P(c.pendingFiles||[]);else if(e&&m){M(!0);try{const ye=await r(e);if(ye){const Ie=ye.sources.md;k(Ie.description||""),j(Ie.instructions||""),_(Ie.description||""),V(Ie.instructions||""),D(Ie.supportingFiles||[])}}catch(ye){console.error("Failed to load skill details:",ye)}finally{M(!1)}}})()},[m,u,e,o,c,r]);const je=async()=>{const ve=u?b.trim().replace(/\s+/g,"-").toLowerCase():e?.trim();if(!ve){H.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ve)||ve.length>64){H.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!y.trim()){H.error(t("settings.skills.page.toast.descriptionRequired"));return}if(u&&o.some(ye=>ye.name===ve)){H.error(t("settings.skills.page.toast.skillExists"));return}N(!0);try{const ye={name:ve,description:y.trim(),instructions:A.trim()||void 0,scope:u?v:void 0,source:u?g:void 0,targetPath:u?void 0:m?.path,supportingFiles:u&&E.length>0?E:void 0};let Ie;u?(Ie=await a(ye),Ie&&(d(null),P([]),p(ve))):(Ie=await i(ve,ye),Ie&&(_(y.trim()),V(A.trim()))),Ie?H.success(t(u?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):H.error(t(u?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(ye){console.error("Error saving skill:",ye),H.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{N(!1)}},oe=()=>{q(null),L(""),ee(""),U(""),z(!0)},Se=async ve=>{if(q(ve),L(ve),u){const Ie=E.find(he=>he.path===ve)?.content||"";ee(Ie),U(Ie),z(!0);return}if(e){ae(!0),z(!0);try{const{readSupportingFile:ye}=ra.getState(),Ie=await ye(e,ve);ee(Ie||""),U(Ie||"")}catch{H.error(t("settings.skills.page.toast.loadFileContentFailed")),ee(""),U("")}finally{ae(!1)}}},se=async()=>{if(!Q.trim()){H.error(t("settings.skills.page.toast.fileNameRequired"));return}const ve=Q.trim(),ye=re!==null;if(u){if(ye)P(me=>me.map(Ee=>Ee.path===re?{path:ve,content:J}:Ee)),H.success(t("settings.skills.page.toast.fileUpdated",{path:ve}));else{if(E.some(me=>me.path===ve)){H.error(t("settings.skills.page.toast.fileExists"));return}P(me=>[...me,{path:ve,content:J}]),H.success(t("settings.skills.page.toast.fileAdded",{path:ve}))}z(!1),q(null);return}if(!e){H.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Ie}=ra.getState();if(await Ie(e,ve,J)){H.success(ye?t("settings.skills.page.toast.fileUpdated",{path:ve}):t("settings.skills.page.toast.fileCreated",{path:ve})),z(!1),q(null);const me=await r(e);me&&D(me.sources.md.supportingFiles||[])}else H.error(t(ye?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},we=ve=>{if(u){P(ye=>ye.filter(Ie=>Ie.path!==ve)),H.success(t("settings.skills.page.toast.fileRemoved",{path:ve}));return}e&&Z(ve)},Ae=async()=>{if(!W||!e)return;ie(!0);const{deleteSupportingFile:ve}=ra.getState();if(await ve(e,W)){H.success(t("settings.skills.page.toast.fileDeleted",{path:W}));const Ie=await r(e);Ie&&D(Ie.sources.md.supportingFiles||[]),Z(null)}else H.error(t("settings.skills.page.toast.deleteFileFailed"));ie(!1)};return!e&&!c||f?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):T?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(Ns,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:u?t("settings.skills.page.title.newSkill"):e}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:m?t("settings.skills.page.subtitle.skillLocation",{location:fe(Hi(m.scope,m.source))}):t("settings.skills.page.subtitle.newSkill")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.basicInformation")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[u&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.skills.page.field.skillNameLocation")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.skillNameHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx(Vt,{value:b,onChange:ve=>h(ve.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(is,{value:Hi(v,g),onValueChange:ve=>{const ye=fg(ve);x(ye.scope),w(ye.source==="agents"?"agents":"opencode")},children:[s.jsxs(os,{className:"w-fit gap-1.5",children:[v==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),g==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:fe(Hi(v,g))})]}),s.jsx(ls,{align:"start",children:tu.map(ve=>s.jsx(Ft,{value:ve.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ve.scope==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),ve.source==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:fe(ve.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:pe(ve.value)})]})},ve.value))})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.descriptionHint")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(fn,{value:y,onChange:ve=>k(ve.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent"})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.instructions")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(fn,{value:A,onChange:ve=>j(ve.target.value),placeholder:t("settings.skills.page.field.instructionsPlaceholder"),className:"min-h-[220px] max-h-[60vh] font-mono typography-meta"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.supportingFiles")}),s.jsxs(xe,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:oe,children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:(()=>{const ve=u?E:S;return ve.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:ve.map(ye=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Se(ye.path),children:[s.jsx(I,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ye.path}),u&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),s.jsx(xe,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:Ie=>{Ie.stopPropagation(),we(ye.path)},children:s.jsx(I,{name:"delete-bin",className:"h-3 w-3"})})]},ye.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(xe,{onClick:je,disabled:C||!Ne,size:"xs",className:"!font-normal",children:t(C?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(ps,{open:W!==null,onOpenChange:ve=>{!ve&&!K&&Z(null)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Ps,{children:t("settings.skills.page.deleteFileDialog.description",{path:W??""})})]}),s.jsxs(Us,{children:[s.jsx(xe,{size:"sm",variant:"ghost",onClick:()=>Z(null),disabled:K,children:t("settings.common.actions.cancel")}),s.jsx(xe,{size:"sm",variant:"destructive",onClick:Ae,disabled:K,children:t("settings.common.actions.delete")})]})]})}),s.jsx(ps,{open:$,onOpenChange:ve=>{z(ve),ve||q(null)},children:s.jsxs(ms,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(vs,{className:"flex-shrink-0",children:[s.jsx(gs,{children:t(re?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Ps,{children:t(re?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),ce?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:t("settings.skills.page.fileDialog.field.filePath")}),s.jsx(Vt,{value:Q,onChange:ve=>L(ve.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:re!==null}),!re&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground flex-shrink-0",children:t("settings.skills.page.fileDialog.field.content")}),s.jsx(fn,{value:J,onChange:ve=>ee(ve.target.value),placeholder:t("settings.skills.page.fileDialog.field.contentPlaceholder"),outerClassName:"h-[45vh] min-h-[250px] max-h-[55vh]",className:"h-full min-h-0 font-mono typography-meta"})]})]}),s.jsxs(Us,{className:"mt-4",children:[s.jsx(xe,{size:"sm",variant:"ghost",onClick:()=>{z(!1),q(null)},children:t("settings.common.actions.cancel")}),s.jsx(xe,{size:"sm",onClick:se,disabled:ce||!ne,children:t(re?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},hp=t=>{const e=ot.c(2),{view:n}=t,r=n===void 0?"installed":n;let a;return e[0]!==r?(a=r==="catalog"?s.jsx(c3,{}):s.jsx(d3,{}),e[0]=r,e[1]=a):a=e[1],a};function u3(){}const hg=t=>{const e=ot.c(26),{header:n,footer:r,children:a,className:i,variant:o}=t,c=o===void 0?"sidebar":o,d=ln(),p=l.useRef(null),[m,u]=l.useState(!1),[f,b]=l.useState(!1),h=c==="background"||d?"bg-background":"bg-sidebar",v=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const N=p.current;if(!N){u(!1),b(!1);return}if(!(N.scrollHeight>N.clientHeight+1)){u(!1),b(!1);return}u(N.scrollTop>1),b(N.scrollTop+N.clientHeight<N.scrollHeight-1)},e[0]=x):x=e[0];const g=x;let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{g()},e[1]=w):w=e[1];let y;e[2]!==a?(y=[a,g],e[2]=a,e[3]=y):y=e[3],l.useEffect(w,y);let k,A;e[4]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const N=p.current;if(!N)return;const T=()=>g();return N.addEventListener("scroll",T,{passive:!0}),()=>N.removeEventListener("scroll",T)},A=[g],e[4]=k,e[5]=A):(k=e[4],A=e[5]),l.useEffect(k,A);let j;e[6]!==h||e[7]!==i?(j=ue("flex h-full flex-col",h,i),e[6]=h,e[7]=i,e[8]=j):j=e[8];let S;e[9]!==a?(S=s.jsx(Ns,{ref:p,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:a}),e[9]=a,e[10]=S):S=e[10];let D;e[11]!==v||e[12]!==m?(D=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${v} 0%, transparent 100%)`}}),e[11]=v,e[12]=m,e[13]=D):D=e[13];let E;e[14]!==v||e[15]!==f?(E=f&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${v} 0%, transparent 100%)`}}),e[14]=v,e[15]=f,e[16]=E):E=e[16];let P;e[17]!==E||e[18]!==S||e[19]!==D?(P=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[S,D,E]}),e[17]=E,e[18]=S,e[19]=D,e[20]=P):P=e[20];let C;return e[21]!==r||e[22]!==n||e[23]!==P||e[24]!==j?(C=s.jsxs("div",{className:j,children:[n,P,r]}),e[21]=r,e[22]=n,e[23]=P,e[24]=j,e[25]=C):C=e[25],C},gg=t=>{const e=ot.c(23),{title:n,metadata:r,selected:a,onSelect:i,icon:o,actions:c,className:d}=t,p=a===void 0?!1:a,m=c&&c.length>0,u=p?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==d||e[1]!==u?(f=ue("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",u,d),e[0]=d,e[1]=u,e[2]=f):f=e[2];let b;e[3]!==n?(b=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=b):b=e[4];let h;e[5]!==o||e[6]!==b?(h=s.jsxs("div",{className:"flex items-center gap-1.5",children:[o,b]}),e[5]=o,e[6]=b,e[7]=h):h=e[7];let v;e[8]!==r?(v=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=v):v=e[9];let x;e[10]!==i||e[11]!==h||e[12]!==v?(x=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[h,v]}),e[10]=i,e[11]=h,e[12]=v,e[13]=x):x=e[13];let g;e[14]!==c||e[15]!==m?(g=m&&s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx(xe,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Rs,{align:"end",className:"w-fit min-w-20",children:c.map(m3)})]}),e[14]=c,e[15]=m,e[16]=g):g=e[16];let w;e[17]!==x||e[18]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,g]}),e[17]=x,e[18]=g,e[19]=w):w=e[19];let y;return e[20]!==f||e[21]!==w?(y=s.jsx("div",{className:f,children:w}),e[20]=f,e[21]=w,e[22]=y):y=e[22],y};function m3(t){const e=t.icon;return s.jsxs($t,{onClick:n=>{n.stopPropagation(),t.onClick()},className:ue(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(I,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const p3=t=>{const e=ot.c(41),{onItemSelect:n}=t,{t:r}=pt(),a=Ts(f3),i=De(h3),o=De(g3),{currentTheme:c}=Sr();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[0]=d):d=e[0];const[p,m]=l.useState(d);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=ln(),e[1]=u):u=e[1];const f=u,b=x3;let h,v;e[2]!==a||e[3]!==i||e[4]!==o?(h=()=>{if(a.length===0){i!==null&&o(null);return}i&&a.some(P=>P.id===i)||o(a[0].id)},v=[a,i,o],e[2]=a,e[3]=i,e[4]=o,e[5]=h,e[6]=v):(h=e[5],v=e[6]),l.useEffect(h,v);let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=ue("border-b px-3","pt-4 pb-3"),e[7]=x):x=e[7];let g;e[8]!==r?(g=r("settings.page.projects.title"),e[8]=r,e[9]=g):g=e[9];let w;e[10]!==g?(w=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[10]=g,e[11]=w):w=e[11];let y;e[12]!==a.length||e[13]!==r?(y=r("settings.projects.sidebar.total",{count:a.length}),e[12]=a.length,e[13]=r,e[14]=y):y=e[14];let k;e[15]!==y?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:y}),e[15]=y,e[16]=k):k=e[16];let A;e[17]!==r?(A=!f&&s.jsx(xe,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:b,"aria-label":r("settings.projects.sidebar.actions.addProject"),children:s.jsx(I,{name:"add",className:"size-4"})}),e[17]=r,e[18]=A):A=e[18];let j;e[19]!==A||e[20]!==k?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,A]}),e[19]=A,e[20]=k,e[21]=j):j=e[21];let S;e[22]!==j||e[23]!==w?(S=s.jsxs("div",{className:x,children:[w,j]}),e[22]=j,e[23]=w,e[24]=S):S=e[24];let D;if(e[25]!==p||e[26]!==c||e[27]!==n||e[28]!==a||e[29]!==i||e[30]!==o){let P;e[32]!==p||e[33]!==c||e[34]!==n||e[35]!==i||e[36]!==o?(P=C=>{const N=C.id===i,T=C.icon?Rl[C.icon]:null,M=`${C.id}:${C.iconImage?.updatedAt??0}`,F=p.has(M)?null:co(C,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),_=C.color?uo[C.color]??null:null,B=F?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:C.iconBackground?{backgroundColor:C.iconBackground}:void 0,children:s.jsx("img",{src:F,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m(V=>{if(V.has(M))return V;const $=new Set(V);return $.add(M),$})}})}):T?s.jsx(I,{name:T,className:ue("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:_?{color:_}:void 0}):s.jsx(I,{name:"folder",className:ue("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:_?{color:_}:void 0});return s.jsx(gg,{title:C.label||C.path,icon:B,selected:N,onSelect:()=>{o(C.id),n?.()}},C.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=i,e[36]=o,e[37]=P):P=e[37],D=a.map(P),e[25]=p,e[26]=c,e[27]=n,e[28]=a,e[29]=i,e[30]=o,e[31]=D}else D=e[31];let E;return e[38]!==S||e[39]!==D?(E=s.jsx(hg,{variant:"background",header:S,children:D}),e[38]=S,e[39]=D,e[40]=E):E=e[40],E};function f3(t){return t.projects}function h3(t){return t.settingsProjectsSelectedId}function g3(t){return t.setSettingsProjectsSelectedId}function x3(){wr.requestDirectoryDialog()}const b3=({projectRef:t=null})=>{const{t:e}=pt(),{isMobile:n,isTablet:r}=nn(),a=n||r,i=Ts(T=>T.getActiveProject()),o=t?.path??i?.path??null,c=Lt(T=>T.getWorktreeMetadata),d=El(),p=_s(T=>T.homeDirectory),[m,u]=l.useState([]),[f,b]=l.useState(!1),[h,v]=l.useState(null),[x,g]=l.useState([]),[w,y]=l.useState(!1),k=l.useMemo(()=>t?.id&&t?.path?{id:t.id,path:t.path}:!i?.id||!o?null:{id:i.id,path:o},[i?.id,o,t?.id,t?.path]),A=l.useCallback(async()=>{if(!(!k||h===!1))try{const T=await Yc(k);g(T)}catch{}},[k,h]);l.useEffect(()=>{if(!o)return;let T=!1;return v(null),(async()=>{try{const M=await nh(o);if(T)return;v(M)}catch{}})(),()=>{T=!0}},[o]),l.useEffect(()=>{if(!k){g([]),y(!1);return}if(h===!1){g([]),y(!1);return}let T=!1;return y(!0),g([]),(async()=>{try{const M=await Yc(k);if(T)return;g(M)}catch{}finally{T||y(!1)}})(),()=>{T=!0}},[k,h]),l.useEffect(()=>{if(!k)return;let T=!1;return b(!0),(async()=>{try{const M=await zd(k);T||u(M.length>0?M:[""])}catch{T||u([""])}finally{T||b(!1)}})(),()=>{T=!0}},[k]);const j=l.useCallback((T,M)=>{u(F=>{const _=[...F];return _[T]=M,_})},[]),S=l.useCallback(()=>{u(T=>[...T,""])},[]),D=l.useCallback(async T=>{if(!k)return;const M=T.filter(F=>F.trim().length>0);await rh(k,M)},[k]),E=l.useCallback(T=>{u(M=>{const F=M.filter((_,B)=>B!==T);return D(F),F.length>0?F:[""]})},[D]),P=l.useCallback(()=>{D(m)},[D,m]),C=l.useCallback(T=>{const M=L=>L.replace(/\\/g,"/").replace(/\/+$/,""),F=M(T.path),_=d.filter(L=>{const J=c(L.id);if(J?.path&&M(J.path)===F)return!0;const ee=L.directory;return!!(ee&&M(ee)===F)}),B=new Set(_.map(L=>L.id)),V=L=>{const J=d.filter(re=>{const q=re.parentID;return q&&L.has(q)});if(J.length===0)return[];const ee=new Set(J.map(re=>re.id));return[...J,...V(ee)]},$=V(B),z=new Set,Q=[..._,...$].filter(L=>z.has(L.id)?!1:(z.add(L.id),!0));wr.requestDelete({sessions:Q,mode:"worktree",worktree:T})},[d,c]),N=l.useMemo(()=>d.map(T=>T.id).join(","),[d]);return l.useEffect(()=>{h&&o&&A()},[N,h,o,A]),o?h===!1?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")}):s.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.setup.title")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Ct,{sideOffset:8,className:"max-w-xs",children:[e("settings.openchamber.worktrees.setup.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs bg-sidebar-accent/50 px-1 rounded",children:"$ROOT_PROJECT_PATH"})," ",e("settings.openchamber.worktrees.setup.tooltipSuffix")]})]})]})}),f?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.setup.loading")}):s.jsxs("div",{className:"space-y-2 px-1",children:[m.map((T,M)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Vt,{value:T,onChange:F=>j(M,F.target.value),onBlur:P,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 w-[30rem] max-w-full font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{E(M)},className:"flex-shrink-0 flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},M)),s.jsxs(xe,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:S,children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e("settings.openchamber.worktrees.setup.addCommand")]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-border/40 pt-4",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.list.title")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]})]})}),w?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.list.loading")}):x.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.openchamber.worktrees.list.empty")}):s.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:x.map(T=>s.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("p",{className:"typography-meta text-foreground truncate min-w-0",children:T.label||T.branch||e("settings.openchamber.worktrees.list.detachedHead")}),s.jsx("span",{className:"typography-micro text-muted-foreground/60 px-1.5 py-[1px] rounded bg-sidebar-accent/40 flex-shrink-0 self-center leading-none",children:"OpenCode"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground/60 truncate",children:Xi(T.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>C(T),className:ue("flex-shrink-0 flex h-7 w-7 items-center justify-center rounded text-muted-foreground/50 hover:text-destructive hover:bg-destructive/10 transition-opacity focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",a?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:T.branch||T.label||T.path}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]},T.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},y3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,v3=()=>({id:y3(),name:"",command:"",icon:"play"}),w3=({projectRef:t})=>{const{t:e}=pt(),n=l.useMemo(()=>dn(),[]),r=Ys(S=>S.instances),a=Ys(S=>S.load),[i,o]=l.useState([]),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState({});l.useEffect(()=>{n&&a().catch(()=>{})},[n,a]),l.useEffect(()=>{let S=!1;return d(!0),(async()=>{try{const D=await qc(t);if(S)return;o(D.actions),f(JSON.stringify({actions:D.actions}))}catch{if(S)return;o([]),f(JSON.stringify({actions:[]}))}finally{S||d(!1)}})(),()=>{S=!0}},[t]);const v=l.useMemo(()=>n?Ah(r):[],[r,n]),x=l.useMemo(()=>i.some(D=>D.name.trim().length===0||D.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),g=l.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:i}),[i,u]),w=l.useCallback(()=>{const S=v3();o(D=>[...D,S]),h(D=>({...D,[S.id]:!0}))},[]),y=l.useCallback(S=>{o(D=>D.filter(E=>E.id!==S)),h(D=>{const E={...D};return delete E[S],E})},[]),k=l.useCallback((S,D)=>{o(E=>E.map(P=>P.id===S?D(P):P))},[]),A=l.useCallback(async()=>{if(x){H.error(x);return}m(!0);try{if(!await Eb(t,{actions:i,primaryActionId:null})){H.error(e("settings.projects.actions.toast.saveFailed"));return}f(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(sd,{detail:{projectId:t.id}})),H.success(e("settings.projects.actions.toast.saved"))}catch{H.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[i,t,e,x]),j=!p&&!c&&g&&!x;return s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:w,children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]})]}),s.jsxs("section",{className:"pb-2 pt-0 space-y-2",children:[c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):i.length===0?s.jsx("div",{className:"py-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")})}):s.jsx("div",{className:"space-y-0 max-w-[30rem]",children:i.map(S=>{const D=S.icon||"play",E=Ho[D]||"play",P=b[S.id]??!1,C=S.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(pr,{open:P,onOpenChange:N=>{h(T=>({...T,[S.id]:N}))},className:ue("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(Nr,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[P?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx(I,{name:E,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:C})})})]}),s.jsx(xe,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>y(S.id),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(fr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-2 pb-6 pl-3 pr-3",children:[s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":e("settings.projects.actions.field.selectIconAria"),children:s.jsx(I,{name:E,className:"h-4 w-4"})})}),s.jsx(Rs,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:Ih.map(N=>{const T=N.Icon,M=(S.icon||"play")===N.key;return s.jsx("button",{type:"button",onClick:()=>k(S.id,F=>({...F,icon:N.key})),className:ue("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",M&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:N.label}),children:s.jsx(I,{name:T,className:"h-4 w-4"})},N.key)})})})]}),s.jsx(Vt,{value:S.name,onChange:N=>k(S.id,T=>({...T,name:N.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),s.jsxs("div",{className:"py-1",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),s.jsx(fn,{value:S.command,onChange:N=>k(S.id,T=>({...T,command:N.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] font-mono text-xs"})]}),s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":S.autoOpenUrl===!0,onClick:()=>k(S.id,N=>({...N,...N.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),k(S.id,T=>({...T,...T.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(ds,{checked:S.autoOpenUrl===!0,onChange:N=>k(S.id,T=>({...T,...N?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:C})}),s.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),S.autoOpenUrl===!0?s.jsxs("div",{className:"mt-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vt,{value:S.openUrl||"",onChange:N=>k(S.id,T=>({...T,openUrl:N.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]})]}),n?s.jsxs("div",{className:"mt-2",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),v.length>0?s.jsxs(is,{value:S.desktopOpenSshForward&&v.some(N=>N.id===S.desktopOpenSshForward)?S.desktopOpenSshForward:"__none__",onValueChange:N=>{k(S.id,T=>({...T,...N==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:N}}))},children:[s.jsx(os,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(us,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),v.map(N=>s.jsx(Ft,{value:N.id,children:N.label},N.id))]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},S.id)})}),s.jsxs("div",{className:"pt-3",children:[x?s.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:x}):null,s.jsx(xe,{type:"button",size:"xs",className:"!font-normal",onClick:A,disabled:!j,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},j3=()=>{const t=ot.c(201),{t:e}=pt(),n=Ts(N3),r=Ts(S3),a=Ts(k3),i=Ts(C3),o=Ts(I3),c=De(P3),d=De(A3),{currentTheme:p}=Sr();let m;e:{if(!c){m=null;break e}let Nt;t[0]!==n||t[1]!==c?(Nt=n.find(Ht=>Ht.id===c)??null,t[0]=n,t[1]=c,t[2]=Nt):Nt=t[2],m=Nt}const u=m;let f,b;t[3]!==n||t[4]!==c||t[5]!==d?(f=()=>{if(n.length===0){d(null);return}c&&n.some(Nt=>Nt.id===c)||d(n[0].id)},b=[n,c,d],t[3]=n,t[4]=c,t[5]=d,t[6]=f,t[7]=b):(f=t[6],b=t[7]),l.useEffect(f,b);const[h,v]=l.useState(""),[x,g]=l.useState(null),[w,y]=l.useState(null),[k,A]=l.useState(null),[j,S]=l.useState(!1),[D,E]=l.useState(!1),[P,C]=l.useState(!1),[N,T]=l.useState(!1),[M,F]=l.useState(null),[_,B]=l.useState(null),[V,$]=l.useState(!1),z=l.useRef(null);let Q;t[8]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>{F(null),B(D3)},t[8]=Q):Q=t[8];const L=Q;let J;e:{if(!u){J=null;break e}let Nt;t[9]!==u.id||t[10]!==u.path?(Nt={id:u.id,path:u.path},t[9]=u.id,t[10]=u.path,t[11]=Nt):Nt=t[11],J=Nt}const ee=J;let re,q;t[12]!==u?(re=()=>{if(!u){v(""),g(null),y(null),A(null);return}v(u.label??""),g(u.icon??null),y(u.color??null),A(u.iconBackground??null),T(!1),L(),$(!1)},q=[u,L],t[12]=u,t[13]=re,t[14]=q):(re=t[13],q=t[14]),l.useEffect(re,q);let ce,ae;t[15]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>()=>{L()},ae=[L],t[15]=ce,t[16]=ae):(ce=t[15],ae=t[16]),l.useEffect(ce,ae);let R;t[17]!==w||t[18]!==x||t[19]!==k||t[20]!==h||t[21]!==N||t[22]!==M||t[23]!==u?(R=!!u&&(h.trim()!==(u?.label??"").trim()||x!==(u?.icon??null)||w!==(u?.color??null)||k!==(u?.iconBackground??null)||N||!!M),t[17]=w,t[18]=x,t[19]=k,t[20]=h,t[21]=N,t[22]=M,t[23]=u,t[24]=R):R=t[24];const U=R;let W;t[25]!==w||t[26]!==x||t[27]!==k||t[28]!==h||t[29]!==N||t[30]!==M||t[31]!==i||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==a?(W=async()=>{if(!u)return;if(M){S(!0);const Ht=await a(u.id,M);if(S(!1),!Ht.ok){H.error(Ht.error||e("settings.projects.page.toast.uploadIconFailed"));return}H.success(e("settings.projects.page.toast.iconUpdated")),L(),T(!1)}const Nt=N&&!!u.iconImage;if(Nt){E(!0);const Ht=await i(u.id);if(E(!1),!Ht.ok){H.error(Ht.error||e("settings.projects.page.toast.removeIconFailed"));return}H.success(e("settings.projects.page.toast.iconRemoved")),T(!1),A(null)}r(u.id,{label:h.trim(),icon:x,color:w,iconBackground:Nt?null:k})},t[25]=w,t[26]=x,t[27]=k,t[28]=h,t[29]=N,t[30]=M,t[31]=i,t[32]=u,t[33]=e,t[34]=r,t[35]=a,t[36]=W):W=t[36];const Z=W,K=w?uo[w]??null:null,ie=!!u?.iconImage,Ne=!!(M&&_),ne=u?.iconImage?.source==="custom",fe=ie&&!N||Ne,pe=fe;let je;t[37]!==p||t[38]!==Ne||t[39]!==ie||t[40]!==N||t[41]!==_||t[42]!==V||t[43]!==u?(je=V?null:Ne?_:u&&ie&&!N?co(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=Ne,t[39]=ie,t[40]=N,t[41]=_,t[42]=V,t[43]=u,t[44]=je):je=t[44];const oe=je;let Se;t[45]!==j||t[46]!==u?(Se=Nt=>{!u||!Nt||j||(T(!1),$(!1),F(Nt),B(Ht=>(Ht&&URL.revokeObjectURL(Ht),URL.createObjectURL(Nt))))},t[45]=j,t[46]=u,t[47]=Se):Se=t[47];const se=Se;let we;t[48]!==Ne||t[49]!==pe||t[50]!==ie||t[51]!==D||t[52]!==u?(we=()=>{!u||!pe||D||(Ne&&L(),T(!!ie),$(!1))},t[48]=Ne,t[49]=pe,t[50]=ie,t[51]=D,t[52]=u,t[53]=we):we=t[53];const Ae=we;let ve;t[54]!==o||t[55]!==P||t[56]!==u||t[57]!==e?(ve=async()=>{!u||P||(L(),T(!1),$(!1),C(!0),o(u.id).then(Nt=>{if(!Nt.ok){H.error(Nt.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(Nt.skipped){H.success(e("settings.projects.page.toast.customIconAlreadySet"));return}H.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{C(!1)}))},t[54]=o,t[55]=P,t[56]=u,t[57]=e,t[58]=ve):ve=t[58];const ye=ve;if(!u){let Nt;t[59]!==e?(Nt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=Nt):Nt=t[60];let Ht;return t[61]!==Nt?(Ht=s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:Nt})})}),t[61]=Nt,t[62]=Ht):Ht=t[62],Ht}let Ie;t[63]!==u.label||t[64]!==e?(Ie=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=Ie):Ie=t[65];let he;t[66]!==Ie?(he=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:Ie}),t[66]=Ie,t[67]=he):he=t[67];let me;t[68]!==u.path?(me=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=me):me=t[69];let Ee;t[70]!==he||t[71]!==me?(Ee=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[he,me]})}),t[70]=he,t[71]=me,t[72]=Ee):Ee=t[72];let Ve;t[73]!==e?(Ve=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=Ve):Ve=t[74];let Y;t[75]!==Ve?(Y=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Ve})}),t[75]=Ve,t[76]=Y):Y=t[76];let ke;t[77]===Symbol.for("react.memo_cache_sentinel")?(ke=Nt=>v(Nt.target.value),t[77]=ke):ke=t[77];let Be;t[78]!==e?(Be=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=Be):Be=t[79];let Ce;t[80]!==h||t[81]!==Be?(Ce=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Vt,{value:h,onChange:ke,placeholder:Be,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=h,t[81]=Be,t[82]=Ce):Ce=t[82];let ge;t[83]!==Y||t[84]!==Ce?(ge=s.jsxs("div",{className:"py-1.5",children:[Y,Ce]}),t[83]=Y,t[84]=Ce,t[85]=ge):ge=t[85];let O;t[86]!==e?(O=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=O):O=t[87];let X;t[88]!==O?(X=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:O})}),t[88]=O,t[89]=X):X=t[89];let G;t[90]===Symbol.for("react.memo_cache_sentinel")?(G=()=>y(null),t[90]=G):G=t[90];const Te=w===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let le;t[91]!==Te?(le=ue("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Te),t[91]=Te,t[92]=le):le=t[92];let We;t[93]!==e?(We=e("settings.projects.page.field.none"),t[93]=e,t[94]=We):We=t[94];let de;t[95]===Symbol.for("react.memo_cache_sentinel")?(de=s.jsx(I,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[95]=de):de=t[95];let Fe;t[96]!==le||t[97]!==We?(Fe=s.jsx("button",{type:"button",onClick:G,className:le,title:We,children:de}),t[96]=le,t[97]=We,t[98]=Fe):Fe=t[98];let rt;t[99]!==w?(rt=Rb.map(Nt=>s.jsx("button",{type:"button",onClick:()=>y(Nt.key),className:ue("h-7 w-7 rounded-md border transition-colors",w===Nt.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:Nt.cssVar},title:Nt.label},Nt.key)),t[99]=w,t[100]=rt):rt=t[100];let Oe;t[101]!==Fe||t[102]!==rt?(Oe=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[Fe,rt]}),t[101]=Fe,t[102]=rt,t[103]=Oe):Oe=t[103];let Ye;t[104]!==X||t[105]!==Oe?(Ye=s.jsxs("div",{className:"py-1.5",children:[X,Oe]}),t[104]=X,t[105]=Oe,t[106]=Ye):Ye=t[106];let Ge;t[107]!==e?(Ge=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=Ge):Ge=t[108];let it;t[109]!==Ge?(it=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Ge})}),t[109]=Ge,t[110]=it):it=t[110];let Qe;t[111]!==se?(Qe=s.jsx("input",{ref:z,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:Nt=>{const Ht=Nt.target.files?.[0]??null;se(Ht),Nt.currentTarget.value=""}}),t[111]=se,t[112]=Qe):Qe=t[112];let at;t[113]===Symbol.for("react.memo_cache_sentinel")?(at=()=>g(null),t[113]=at):at=t[113];const nt=x===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let be;t[114]!==nt?(be=ue("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",nt),t[114]=nt,t[115]=be):be=t[115];let He;t[116]!==e?(He=e("settings.projects.page.field.none"),t[116]=e,t[117]=He):He=t[117];let _e;t[118]===Symbol.for("react.memo_cache_sentinel")?(_e=s.jsx(I,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[118]=_e):_e=t[118];let tt;t[119]!==be||t[120]!==He?(tt=s.jsx("button",{type:"button",onClick:at,className:be,title:He,children:_e}),t[119]=be,t[120]=He,t[121]=tt):tt=t[121];let ut;t[122]!==K||t[123]!==x?(ut=Fb.map(Nt=>{const Ht=Nt.Icon;return s.jsx("button",{type:"button",onClick:()=>g(Nt.key),className:ue("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",x===Nt.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:Nt.label,children:s.jsx(I,{name:Ht,className:"w-4 h-4",style:K&&x===Nt.key?{color:K}:void 0})},Nt.key)}),t[122]=K,t[123]=x,t[124]=ut):ut=t[124];let qe;t[125]!==tt||t[126]!==ut?(qe=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[tt,ut]}),t[125]=tt,t[126]=ut,t[127]=qe):qe=t[127];let ze;t[128]!==fe||t[129]!==k||t[130]!==oe||t[131]!==e?(ze=fe&&oe&&s.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.projects.page.field.preview")}),s.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/60 bg-[var(--surface-elevated)] p-1",children:s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:k?{backgroundColor:k}:void 0,children:s.jsx("img",{src:oe,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>$(!0)})})})]}),t[128]=fe,t[129]=k,t[130]=oe,t[131]=e,t[132]=ze):ze=t[132];let st;t[133]!==fe||t[134]!==k||t[135]!==e?(st=fe&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:k??"#000000",onChange:Nt=>A(Nt.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":e("settings.projects.page.field.projectIconBackgroundAria")}),s.jsx(Vt,{value:k??"",onChange:Nt=>A(Nt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(xe,{type:"button",size:"xs",variant:"outline",onClick:()=>A(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!k,children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),t[133]=fe,t[134]=k,t[135]=e,t[136]=st):st=t[136];let yt;t[137]!==ye||t[138]!==ne||t[139]!==P||t[140]!==j||t[141]!==e?(yt=!ne&&s.jsxs(s.Fragment,{children:[s.jsx(xe,{size:"xs",className:"h-6 !font-normal",onClick:()=>z.current?.click(),disabled:j,children:e(j?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(xe,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{ye()},disabled:P,children:e(P?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=ye,t[138]=ne,t[139]=P,t[140]=j,t[141]=e,t[142]=yt):yt=t[142];let Mt;t[143]!==Ae||t[144]!==pe||t[145]!==D||t[146]!==e?(Mt=pe&&s.jsx(xe,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Ae()},disabled:D,children:e(D?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=Ae,t[144]=pe,t[145]=D,t[146]=e,t[147]=Mt):Mt=t[147];let Bt;t[148]!==D||t[149]!==N||t[150]!==e?(Bt=N&&s.jsx(xe,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>T(!1),disabled:D,children:e("settings.projects.page.actions.undoRemove")}),t[148]=D,t[149]=N,t[150]=e,t[151]=Bt):Bt=t[151];let ft;t[152]!==yt||t[153]!==Mt||t[154]!==Bt?(ft=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[yt,Mt,Bt]}),t[152]=yt,t[153]=Mt,t[154]=Bt,t[155]=ft):ft=t[155];let It;t[156]!==it||t[157]!==Qe||t[158]!==qe||t[159]!==ze||t[160]!==st||t[161]!==ft?(It=s.jsxs("div",{className:"py-1.5",children:[it,Qe,qe,ze,st,ft]}),t[156]=it,t[157]=Qe,t[158]=qe,t[159]=ze,t[160]=st,t[161]=ft,t[162]=It):It=t[162];let ss;t[163]!==ge||t[164]!==Ye||t[165]!==It?(ss=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[ge,Ye,It]}),t[163]=ge,t[164]=Ye,t[165]=It,t[166]=ss):ss=t[166];let _t;t[167]!==U||t[168]!==D||t[169]!==j||t[170]!==h?(_t=!U||h.trim().length===0||j||D,t[167]=U,t[168]=D,t[169]=j,t[170]=h,t[171]=_t):_t=t[171];let qt;t[172]!==e?(qt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=qt):qt=t[173];let ct;t[174]!==Z||t[175]!==_t||t[176]!==qt?(ct=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(xe,{onClick:Z,disabled:_t,size:"xs",className:"!font-normal",children:qt})}),t[174]=Z,t[175]=_t,t[176]=qt,t[177]=ct):ct=t[177];let jt;t[178]!==ss||t[179]!==ct?(jt=s.jsxs("div",{className:"mb-8",children:[ss,ct]}),t[178]=ss,t[179]=ct,t[180]=jt):jt=t[180];let as;t[181]!==ee?(as=ee&&s.jsx(w3,{projectRef:ee}),t[181]=ee,t[182]=as):as=t[182];let xs;t[183]!==as?(xs=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:as})}),t[183]=as,t[184]=xs):xs=t[184];let ws;t[185]!==e?(ws=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=ws):ws=t[186];let As;t[187]!==ws?(As=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:ws})}),t[187]=ws,t[188]=As):As=t[188];let Gt;t[189]!==ee?(Gt=ee&&s.jsx(b3,{projectRef:ee}),t[189]=ee,t[190]=Gt):Gt=t[190];let Ke;t[191]!==Gt?(Ke=s.jsx("section",{className:"px-2 pb-2 pt-0",children:Gt}),t[191]=Gt,t[192]=Ke):Ke=t[192];let Pt;t[193]!==As||t[194]!==Ke?(Pt=s.jsxs("div",{className:"mb-8",children:[As,Ke]}),t[193]=As,t[194]=Ke,t[195]=Pt):Pt=t[195];let Ot;return t[196]!==Ee||t[197]!==jt||t[198]!==xs||t[199]!==Pt?(Ot=s.jsx(Ns,{outerClassName:"h-full",className:"w-full bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:[Ee,jt,xs,Pt]})}),t[196]=Ee,t[197]=jt,t[198]=xs,t[199]=Pt,t[200]=Ot):Ot=t[200],Ot};function N3(t){return t.projects}function S3(t){return t.updateProjectMeta}function k3(t){return t.uploadProjectIcon}function C3(t){return t.removeProjectIcon}function I3(t){return t.discoverProjectIcon}function P3(t){return t.settingsProjectsSelectedId}function A3(t){return t.setSettingsProjectsSelectedId}function D3(t){return t&&URL.revokeObjectURL(t),null}const T3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,M3=()=>Math.floor(2e4+Math.random()*3e4),E3=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},R3=t=>{switch(t){case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"error":return"settings.remoteInstances.sidebar.phase.error";case"degraded":return"settings.remoteInstances.sidebar.phase.reconnect";case"installing":return"settings.remoteInstances.sidebar.phase.installing";case"updating":return"settings.remoteInstances.sidebar.phase.updating";case"forwarding":return"settings.remoteInstances.sidebar.phase.forwarding";case"server_starting":return"settings.remoteInstances.sidebar.phase.starting";case"master_connecting":return"settings.remoteInstances.sidebar.phase.connecting";default:return"settings.remoteInstances.sidebar.phase.idle"}},F3=({onItemSelect:t})=>{const{t:e}=pt(),n=Ys(g=>g.instances),r=Ys(g=>g.statusesById),a=Ys(g=>g.isLoading),i=Ys(g=>g.load),o=Ys(g=>g.loadImports),c=Ys(g=>g.createFromCommand),d=Ys(g=>g.connect),p=Ys(g=>g.disconnect),m=Ys(g=>g.retry),u=Ys(g=>g.removeInstance),f=Ys(g=>g.upsertInstance),b=De(g=>g.settingsRemoteInstancesSelectedId),h=De(g=>g.setSettingsRemoteInstancesSelectedId);l.useEffect(()=>{i(),o()},[i,o]),l.useEffect(()=>{if(!a){if(n.length===0){b!==null&&h(null);return}b&&n.some(g=>g.id===b)||h(n[0].id)}},[n,a,b,h]);const v=l.useCallback(async()=>{const g=T3();try{await c(g,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),h(g),t?.()}catch(w){H.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:w instanceof Error?w.message:String(w)})}},[c,t,h,e]),x=l.useCallback(async g=>{try{await d(g.id);return}catch(w){if(!E3(w)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw w;const k={...g,localForward:{...g.localForward,preferredLocalPort:M3()}};await f(k),await d(k.id),H.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,f]);return s.jsx(hg,{variant:"background",header:s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.remoteInstances.sidebar.title")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.remoteInstances.sidebar.total",{count:n.length})}),s.jsx(xe,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{v()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(I,{name:"add",className:"size-4"})})]})]}),children:n.map(g=>{const w=r[g.id],y=g.id===b,k=g.nickname?.trim()||g.sshParsed?.destination||g.id,A=`${e(R3(w?.phase))}${w?.localUrl?` · ${w.localUrl}`:""}`,j=w?.phase==="ready",S=w?.phase==="error"||w?.phase==="degraded";return s.jsx(gg,{title:k,metadata:A,selected:y,onSelect:()=>{h(g.id),t?.()},actions:[{label:e(j?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:j?"stop":"plug-2",onClick:()=>{(j?p(g.id):x(g)).catch(E=>{H.error(e(j?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:E instanceof Error?E.message:String(E)})})}},{label:e("settings.remoteInstances.sidebar.actions.retry"),icon:"refresh",onClick:()=>{S&&m(g.id).catch(D=>{H.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:D instanceof Error?D.message:String(D)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:"delete-bin",destructive:!0,onClick:()=>{u(g.id).then(()=>{if(b===g.id){const D=n.find(E=>E.id!==g.id);h(D?.id||null)}}).catch(D=>{H.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:D instanceof Error?D.message:String(D)})})}}]},g.id)})})},gp=t=>{const e=ot.c(10),{children:n,className:r,outerClassName:a}=t;let i;e[0]!==a?(i=ue("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==r?(o=ue("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",r),e[2]=r,e[3]=o):o=e[3];let c;e[4]!==n||e[5]!==o?(c=s.jsx("div",{className:o,children:n}),e[4]=n,e[5]=o,e[6]=c):c=e[6];let d;return e[7]!==i||e[8]!==c?(d=s.jsx(Ns,{outerClassName:i,className:"w-full",children:c}),e[7]=i,e[8]=c,e[9]=d):d=e[9],d},bd=()=>Math.floor(2e4+Math.random()*3e4),O3=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},L3=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingOpenChamber";case"updating":return"settings.remoteInstances.page.phase.updatingOpenChamber";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},$3=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),xg=t=>!!(t&&$3.has(t)),B3=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||xg(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",_3=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,z3=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:bd(),remoteHost:"127.0.0.1",remotePort:80}),V3=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Vr=t=>{const e=ot.c(8),{label:n,hint:r}=t;let a;e[0]!==n?(a=s.jsx("span",{children:n}),e[0]=n,e[1]=a):a=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsxs(St,{children:[i,s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:s.jsx("div",{className:"typography-meta text-foreground",children:r})})]}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==a||e[6]!==o?(c=s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[a,o]}),e[5]=a,e[6]=o,e[7]=c):c=e[7],c},U3=t=>{switch(t){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},xp=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},W3=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},K3=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const n=Number(e[1]),r=Number.isFinite(n)?new Date(n).toISOString():e[1],a=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${r}] [${a}] ${i}`},H3=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},G3=t=>{const e=t.sshCommand.trim(),n=t.nickname?.trim(),r=t.portForwards.map(a=>({...a,localHost:a.localHost?.trim()||"127.0.0.1",localPort:typeof a.localPort=="number"?Math.max(1,Math.min(65535,Math.round(a.localPort))):void 0,remoteHost:a.remoteHost?.trim(),remotePort:typeof a.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(a.remotePort))):void 0}));return{...t,sshCommand:e,...n?{nickname:n}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:r}},q3=()=>{const{t}=pt(),e=Ys(O=>O.instances),n=Ys(O=>O.statusesById),r=Ys(O=>O.importCandidates),a=Ys(O=>O.isImportsLoading),i=Ys(O=>O.isSaving),o=Ys(O=>O.error),c=Ys(O=>O.load),d=Ys(O=>O.loadImports),p=Ys(O=>O.refreshStatuses),m=Ys(O=>O.upsertInstance),u=Ys(O=>O.createFromCommand),f=Ys(O=>O.removeInstance),b=Ys(O=>O.connect),h=Ys(O=>O.disconnect),v=Ys(O=>O.retry),x=De(O=>O.settingsRemoteInstancesSelectedId),g=De(O=>O.setSettingsRemoteInstancesSelectedId),w=l.useMemo(()=>x&&e.find(O=>O.id===x)||null,[e,x]),[y,k]=l.useState(null),[A,j]=l.useState(!1),[S,D]=l.useState(!1),[E,P]=l.useState(null),[C,N]=l.useState([]),[T,M]=l.useState(null),[F,_]=l.useState(""),[B,V]=l.useState(!1),[$,z]=l.useState({}),[Q,L]=l.useState(!1),[J,ee]=l.useState(!1),[re,q]=l.useState(()=>Date.now());l.useEffect(()=>{c(),d()},[c,d]),l.useEffect(()=>{k(w)},[w]),l.useEffect(()=>{if(!x)return;const O=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||p()},2e3);return()=>{window.clearInterval(O)}},[p,x]),l.useEffect(()=>{let O=null,X=Date.now();const G=()=>{const le=Date.now();le-X>=1e3&&(q(le),X=le),O=requestAnimationFrame(G)};(typeof document>"u"||document.visibilityState==="visible")&&(O=requestAnimationFrame(G));const Te=()=>{document.visibilityState==="visible"&&O===null?O=requestAnimationFrame(G):document.visibilityState!=="visible"&&O!==null&&(cancelAnimationFrame(O),O=null)};return document.addEventListener("visibilitychange",Te),()=>{document.removeEventListener("visibilitychange",Te),O!==null&&cancelAnimationFrame(O)}},[]);const ce=x?n[x]:null,ae=ce?.phase,R=ae==="ready",U=ae==="degraded",W=xg(ae),K=R||(W||U),ie=ce?Math.max(0,re-ce.updatedAtMs):0,Ne=U&&ie>12e3,ne=l.useMemo(()=>!y||!w?!1:JSON.stringify(y)!==JSON.stringify(w),[y,w]),fe=l.useCallback(O=>{k(X=>X&&O(X))},[]),pe=l.useCallback(async()=>{if(!y)return;const O=G3(y);if(!O.sshCommand.trim()){H.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(O.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(O.auth.sshPassword?.enabled&&O.auth.sshPassword.value?.trim()&&O.auth.sshPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));O.auth.sshPassword.store=X?"settings":"never",X||(O.auth.sshPassword.value=void 0)}if(O.auth.openchamberPassword?.enabled&&O.auth.openchamberPassword.value?.trim()&&O.auth.openchamberPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));O.auth.openchamberPassword.store=X?"settings":"never",X||(O.auth.openchamberPassword.value=void 0)}try{await m(O),H.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(X){H.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:X instanceof Error?X.message:String(X)})}}},[y,t,m]),je=l.useCallback(async(O,X)=>{const G=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(G,`ssh ${X}`,O),g(G),H.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Te){return H.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Te instanceof Error?Te.message:String(Te)}),!1}},[u,g,t]),oe=l.useCallback(()=>{B||(M(null),_(""))},[B]),Se=l.useCallback((O,X)=>{if(X){M(O),_(V3(O));return}je(O,O)},[je]),se=l.useCallback(async()=>{const O=T,X=F.trim();if(O){if(!X){H.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}V(!0);try{await je(O,X)&&(M(null),_(""))}finally{V(!1)}}},[je,F,T,t]),we=l.useCallback(async()=>{if(w)try{await b(w.id);return}catch(O){if(!O3(O)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw O;const G={...w,localForward:{...w.localForward,preferredLocalPort:bd()}};await m(G),await b(G.id),H.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[b,w,t,m]),Ae=l.useCallback(async O=>(await Ob(O,600)).map(G=>K3(G)),[]),ve=l.useCallback(async()=>{if(y){j(!0),D(!0),P(null);try{const O=await Ae(y.id);N(O)}catch(O){N([]),P(O instanceof Error?O.message:String(O))}finally{D(!1)}}},[y,Ae]);l.useEffect(()=>{if(!A||!y)return;let O=!1;const X=async()=>{try{const Te=await Ae(y.id);O||(N(Te),P(null))}catch(Te){O||P(Te instanceof Error?Te.message:String(Te))}};X();const G=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||X()},1e3);return()=>{O=!0,window.clearInterval(G)}},[y,A,Ae]);const ye=l.useMemo(()=>C.join(`
|
|
176
|
-
`),[C]),Ie=l.useCallback(()=>{if(!ye.trim()){H.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}An(ye).then(O=>{O.ok&&H.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[ye,t]),he=l.useCallback(async()=>{if(y)try{await Lb(y.id),N([]),H.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(O){H.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:O instanceof Error?O.message:String(O)})}},[y,t]),me=l.useCallback(async()=>{if(!ce?.localUrl){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const O=ce.localUrl.trim();if(!O){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}H3(O)},[ce?.localUrl,t]),Ee=l.useCallback(()=>{if(!y)return;L(!0),(K?h(y.id):we()).catch(X=>{const G=K?R?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";H.error(t(G),{description:X instanceof Error?X.message:String(X)})}).finally(()=>{L(!1)})},[K,we,h,y,R,t]),Ve=l.useCallback(()=>{if(!y||W)return;ee(!0),(U?h(y.id).then(()=>we()):v(y.id)).catch(X=>{H.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:X instanceof Error?X.message:String(X)})}).finally(()=>{ee(!1)})},[we,h,y,W,U,v,t]),Y=t(W?"settings.remoteInstances.page.actions.connecting":U?Ne?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),ke=!Q&&!J&&(ae==="error"||ae==="idle"||!ae||U&&Ne)&&!W,Be=t(R?"settings.remoteInstances.sidebar.actions.disconnect":K?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!y)return s.jsxs(gp,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.description")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.empty.selectInstance")})})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.import.sectionTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:a?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneFound")}):s.jsx("div",{className:"space-y-2",children:r.map(O=>s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--interactive-border)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label text-foreground truncate",children:[O.host,O.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[O.source," config"]})]}),s.jsx(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Se(O.host,O.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${O.source}:${O.host}`))})})]}),s.jsx(ps,{open:!!T,onOpenChange:O=>{O||oe()},children:s.jsxs(ms,{className:"sm:max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ps,{children:T?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:T}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:O=>{O.preventDefault(),se()},children:[s.jsx(Vt,{value:F,onChange:O=>_(O.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:oe,disabled:B,children:t("settings.common.actions.cancel")}),s.jsx(xe,{type:"submit",size:"xs",className:"!font-normal",disabled:B,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Ce=y.remoteOpenchamber.mode==="managed",ge=y.nickname?.trim()||y.sshParsed?.destination||y.id;return s.jsxs(gp,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ge}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${B3(ae)}`}),s.jsx("span",{children:t(L3(ae))}),ce?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:ce.localUrl}):null,Ne?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.actions")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.actionsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(xe,{type:"button",variant:K?"outline":"default",size:"xs",className:"!font-normal",onClick:Ee,disabled:Q||J,children:[K?s.jsx(I,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"plug-2",className:"h-3.5 w-3.5"}),Be]}),s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ve,disabled:!ke,children:[s.jsx(I,{name:"refresh",className:`h-3.5 w-3.5 ${W||U&&!Ne?"animate-spin":""}`}),Y]}),s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ve()},children:[s.jsx(I,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&f(y.id).then(()=>{g(null),H.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(X=>{H.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:X instanceof Error?X.message:String(X)})})},children:[s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),ce?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:ce.localUrl})]}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.instance")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.instanceDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(Vt,{className:"h-7 md:max-w-xl",value:y.sshCommand,onChange:O=>fe(X=>({...X,sshCommand:O.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(Vt,{className:"h-7 md:max-w-sm",value:y.nickname||"",onChange:O=>fe(X=>({...X,nickname:O.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(Fn,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:y.connectionTimeoutSec,onValueChange:O=>{fe(X=>({...X,connectionTimeoutSec:Number.isFinite(O)?O:X.connectionTimeoutSec}))}})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.remoteServer")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.remoteServerDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vr,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(is,{value:y.remoteOpenchamber.mode,onValueChange:O=>fe(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,mode:O==="external"?"external":"managed"}})),children:[s.jsx(os,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(Ft,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vr,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(Fn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.remoteOpenchamber.preferredPort,onValueChange:O=>{fe(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,preferredPort:Number.isFinite(O)&&O>0?O:void 0}}))},onClear:()=>{fe(O=>({...O,remoteOpenchamber:{...O.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Ce?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vr,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(is,{value:y.remoteOpenchamber.installMethod,onValueChange:O=>fe(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,installMethod:O==="npm"||O==="download_release"||O==="upload_bundle"?O:"bun"}})),children:[s.jsx(os,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"bun",children:"bun"}),s.jsx(Ft,{value:"npm",children:"npm"}),s.jsx(Ft,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(Ft,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,Ce?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vr,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(dl,{checked:y.remoteOpenchamber.keepRunning,onCheckedChange:O=>fe(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,keepRunning:O}}))})})]}):null]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.mainTunnel")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.mainTunnelDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vr,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(is,{value:y.localForward.bindHost,onValueChange:O=>{O==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||fe(X=>({...X,localForward:{...X.localForward,bindHost:O==="localhost"||O==="0.0.0.0"?O:"127.0.0.1"}}))},children:[s.jsx(os,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(Ft,{value:"localhost",children:"localhost"}),s.jsx(Ft,{value:"0.0.0.0",children:"0.0.0.0"})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vr,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(Fn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.localForward.preferredLocalPort,onValueChange:O=>{fe(X=>({...X,localForward:{...X.localForward,preferredLocalPort:Number.isFinite(O)&&O>0?O:void 0}}))},onClear:()=>{fe(O=>({...O,localForward:{...O.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>fe(O=>({...O,localForward:{...O.localForward,preferredLocalPort:bd()}})),children:s.jsx(I,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.authentication")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.authenticationDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshPasswordOptional")}),s.jsx(Vt,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.sshPassword?.value||"",onChange:O=>fe(X=>({...X,auth:{...X.auth,sshPassword:{enabled:O.target.value.trim().length>0,value:O.target.value,store:X.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.uiPasswordOptional")}),s.jsx(Vt,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.openchamberPassword?.value||"",onChange:O=>fe(X=>({...X,auth:{...X.auth,openchamberPassword:{enabled:O.target.value.trim().length>0,value:O.target.value,store:X.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.portForwards")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.portForwardsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[y.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,y.portForwards.map((O,X)=>{const G=Qe=>{fe(at=>({...at,portForwards:at.portForwards.map((nt,be)=>be===X?Qe(nt):nt)}))},Te=O.type==="remote"?"Local target":"Local listen",le=O.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",We=O.type==="remote"?"Remote listen":"Remote target",de=O.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Fe=xp(O.localHost||"localhost",O.localPort),rt=xp(O.remoteHost||"localhost",O.remotePort),Oe=O.type==="local"&&typeof O.localPort=="number"&&O.localPort>0,Ye=Oe?`http://${W3(O.localHost)}:${O.localPort}`:"",Ge=!!$[O.id],it=O.type==="local"?t("settings.remoteInstances.page.forwardType.local"):O.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(pr,{open:Ge,onOpenChange:Qe=>{z(at=>({...at,[O.id]:Qe}))},className:`${X>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(Nr,{className:"flex items-center gap-2 group",children:[s.jsx(I,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Ge?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:_3(O)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:it})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(dl,{checked:O.enabled,onCheckedChange:Qe=>G(at=>({...at,enabled:Qe})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(xe,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>fe(Qe=>({...Qe,portForwards:Qe.portForwards.filter(at=>at.id!==O.id)})),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(fr,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:t(U3(O.type))}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vr,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(is,{value:O.type,onValueChange:Qe=>G(at=>({...at,type:Qe==="dynamic"||Qe==="remote"?Qe:"local"})),children:[s.jsx(os,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(Ft,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(Ft,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vr,{label:Te,hint:le})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vt,{className:"h-7 w-32",value:O.localHost||"127.0.0.1",onChange:Qe=>G(at=>({...at,localHost:Qe.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Fn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:O.localPort,onValueChange:Qe=>{G(at=>({...at,localPort:Number.isFinite(Qe)&&Qe>0?Qe:void 0}))},onClear:()=>{G(Qe=>({...Qe,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),O.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Vr,{label:We,hint:de})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vt,{className:"h-7 w-32",value:O.remoteHost||"",onChange:Qe=>G(at=>({...at,remoteHost:Qe.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Fn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:O.remotePort,onValueChange:Qe=>{G(at=>({...at,remotePort:Number.isFinite(Qe)&&Qe>0?Qe:void 0}))},onClear:()=>{G(Qe=>({...Qe,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:O.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Fe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):O.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:rt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(I,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Fe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Fe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(I,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:rt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Oe?s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Zn(Ye).then(Qe=>{Qe||H.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},O.id)}),s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const O=z3();fe(X=>({...X,portForwards:[...X.portForwards,O]})),z(X=>({...X,[O.id]:!0}))},children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.import.sectionTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:a?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneAvailable")}):s.jsx("div",{children:r.slice(0,8).map((O,X)=>s.jsxs("div",{className:`flex items-center justify-between gap-2 px-1 py-2 ${X>0?"border-t border-[var(--surface-subtle)]":""}`,children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label text-foreground truncate",children:[O.host,O.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:O.sshCommand})]}),s.jsx(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Se(O.host,O.pattern)},children:t("settings.common.actions.import")})]},`${O.source}:${O.host}`))})})]}),s.jsx("div",{className:"sticky bottom-0 z-10 -mx-3 sm:-mx-6 bg-[var(--surface-background)] border-t border-[var(--interactive-border)] px-3 sm:px-6 py-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xe,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{pe()},disabled:!ne||i,children:t("settings.common.actions.saveChanges")}),ce?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{An(ce.localUrl||"").then(O=>{O.ok&&H.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{me()},children:[s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,o?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:o}):null]})}),s.jsx(ps,{open:A,onOpenChange:j,children:s.jsxs(ms,{className:"sm:max-w-2xl",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Ps,{children:y?.nickname?.trim()||y?.sshParsed?.destination||y?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ie,disabled:S||!ye.trim(),children:[s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{he()},disabled:S,children:[s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),S?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):E?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:E}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:C.length>0?C.join(`
|
|
177
|
-
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(ps,{open:!!T,onOpenChange:O=>{O||oe()},children:s.jsxs(ms,{className:"sm:max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ps,{children:T?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:T}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:O=>{O.preventDefault(),se()},children:[s.jsx(Vt,{value:F,onChange:O=>_(O.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:oe,disabled:B,children:t("settings.common.actions.cancel")}),s.jsx(xe,{type:"submit",size:"xs",className:"!font-normal",disabled:B,children:t("settings.common.actions.create")})]})]})]})})]})},Y3="__add_provider__",J3=()=>{const t=en.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},Q3=({onItemSelect:t})=>{const{t:e}=pt(),n=vt(f=>f.providers),r=vt(f=>f.selectedProviderId),a=vt(f=>f.setSelectedProvider),i=Ts(f=>f.activeProjectId),[o,c]=l.useState({}),d=l.useMemo(()=>J3(),[i]);l.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const h=n.map(async v=>{try{const x=d?`?directory=${encodeURIComponent(d)}`:"",g=await fetch(`/api/provider/${encodeURIComponent(v.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!g.ok)return;const w=await g.json().catch(()=>null),y=w?.sources??w?.data?.sources;if(!y||f)return;c(k=>({...k,[v.id]:y}))}catch{}});await Promise.all(h)})(),()=>{f=!0}},[d,n]);const p="bg-background",m=l.useMemo(()=>n.filter(f=>!!o[f.id]?.project?.exists),[n,o]),u=l.useMemo(()=>n.filter(f=>!o[f.id]?.project?.exists),[n,o]);return s.jsxs("div",{className:ue("flex h-full flex-col",p),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.providers.sidebar.title")}),s.jsx(po,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(xe,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{a(Y3),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[u.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),u.map(f=>s.jsx(bp,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ue("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",u.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(f=>s.jsx(bp,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]})]})})]})},bp=t=>{const e=ot.c(17),{provider:n,selectedProviderId:r,onSelect:a}=t,i=Array.isArray(n.models)?n.models.length:0,o=n.id===r,c=n.id,d=o?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==d?(p=ue("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",d),e[0]=d,e[1]=p):p=e[1];let m;e[2]!==n.id?(m=s.jsx(xn,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const u=n.name||n.id;let f;e[4]!==u?(f=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:u}),e[4]=u,e[5]=f):f=e[5];let b;e[6]!==i?(b=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=b):b=e[7];let h;e[8]!==a||e[9]!==m||e[10]!==f||e[11]!==b?(h=s.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,f,b]}),e[8]=a,e[9]=m,e[10]=f,e[11]=b,e[12]=h):h=e[12];let v;return e[13]!==n.id||e[14]!==p||e[15]!==h?(v=s.jsx("div",{className:p,children:h},c),e[13]=n.id,e[14]=p,e[15]=h,e[16]=v):v=e[16],v},X3=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),yp=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=X3.format(t);return e.endsWith(".0")?e.slice(0,-2):e},Ro="__add_provider__",bi=t=>typeof t=="object"&&t!==null,vp=t=>{const e=typeof t.type=="string"?t.type:"",n=`${t.name??""} ${t.label??""}`.toLowerCase(),r=`${e} ${n}`.toLowerCase();return r.includes("oauth")?"oauth":r.includes("api")?"api":e.toLowerCase()},Z3=t=>{if(!bi(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(a=>bi(a)));return e},e5=t=>{if(typeof t=="string")return{id:t};if(!bi(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const n=typeof t.name=="string"?t.name:void 0;return{id:e,name:n}},t5=t=>{let e=[];Array.isArray(t)?e=t:bi(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(a=>e5(a)).filter(a=>!!a),r=new Set;return n.filter(a=>r.has(a.id)?!1:(r.add(a.id),!0))},s5=()=>{const{t}=pt(),e=vt(oe=>oe.providers),n=vt(oe=>oe.selectedProviderId),r=vt(oe=>oe.setSelectedProvider),a=vt(oe=>oe.getModelMetadata),i=De(oe=>oe.hiddenModels),o=De(oe=>oe.toggleHiddenModel),c=De(oe=>oe.hideAllModels),d=De(oe=>oe.showAllModels),[p,m]=l.useState({}),[u,f]=l.useState(!1),[b,h]=l.useState({}),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,k]=l.useState(null),[A,j]=l.useState({}),[S,D]=l.useState({}),[E,P]=l.useState([]),[C,N]=l.useState(!1),[T,M]=l.useState(null),[F,_]=l.useState(""),[B,V]=l.useState(""),[$,z]=l.useState(!1),[Q,L]=l.useState({}),[J,ee]=l.useState(!1);l.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),l.useEffect(()=>{let oe=!0;return(async()=>{f(!0);try{const se=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!se.ok)throw new Error(`Auth methods request failed (${se.status})`);const we=await se.json().catch(()=>({}));if(!oe)return;m(Z3(we))}catch(se){if(!oe)return;console.error("Failed to load provider auth methods:",se),H.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{oe&&f(!1)}})(),()=>{oe=!1}},[t]),l.useEffect(()=>{let oe=!0;return(async()=>{N(!0),M(null);try{const se=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!se.ok)throw new Error(`Provider list request failed (${se.status})`);const we=await se.json().catch(()=>({}));if(!oe)return;P(t5(we))}catch(se){if(!oe)return;console.error("Failed to load available providers:",se),M(t("settings.providers.page.state.unableToLoadProviderList"))}finally{oe&&N(!1)}})(),()=>{oe=!1}},[t]);const re=l.useMemo(()=>new Set(e.map(oe=>oe.id)),[e]),q=l.useMemo(()=>E.filter(oe=>!re.has(oe.id)).sort((oe,Se)=>{const se=(oe.name||oe.id).toLowerCase(),we=(Se.name||Se.id).toLowerCase();return se.localeCompare(we)}),[E,re]);l.useEffect(()=>{n===Ro&&F&&!q.some(oe=>oe.id===F)&&_("")},[n,F,q]),l.useEffect(()=>{if(n===Ro){ee(!0);return}ee(!1)},[n,t]),l.useEffect(()=>{if(!n||n===Ro)return;let oe=!1;return(async()=>{try{const se=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),we=await se.json().catch(()=>null);if(!se.ok)throw new Error(we?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Ae=we?.sources??we?.data?.sources;!oe&&Ae&&L(ve=>({...ve,[n]:Ae}))}catch(se){oe||console.error("Failed to load provider sources:",se)}})(),()=>{oe=!0}},[n,t]);const ce=e.find(oe=>oe.id===n),ae=n?Q[n]:void 0,R=async oe=>{const Se=b[oe]?.trim()??"";if(!Se){H.error(t("settings.providers.page.toast.apiKeyRequired"));return}const se=`api:${oe}`;x(se);try{const we=await fetch(`/api/auth/${encodeURIComponent(oe)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:Se})}),Ae=await we.json().catch(()=>null);if(!we.ok){const ve=Ae?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(ve)}H.success(t("settings.providers.page.toast.apiKeySaved")),h(ve=>({...ve,[oe]:""})),await ai({scopes:["providers"],mode:"active"}),r(oe)}catch(we){console.error("Failed to save API key:",we),H.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},U=async(oe,Se)=>{const se=`oauth:${oe}:${Se}`;x(se);try{const we=await fetch(`/api/provider/${encodeURIComponent(oe)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:Se})}),Ae=await we.json().catch(()=>null);if(!we.ok){const Ve=Ae?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(Ve)}const ve=bi(Ae)?Ae:{},ye=bi(ve.data)?ve.data:ve,Ie=typeof ye.url=="string"&&ye.url||typeof ye.verification_uri_complete=="string"&&ye.verification_uri_complete||typeof ye.verification_uri=="string"&&ye.verification_uri||void 0,he=typeof ye.instructions=="string"&&ye.instructions||typeof ye.message=="string"&&ye.message||void 0,me=typeof ye.user_code=="string"&&ye.user_code||typeof ye.code=="string"&&ye.code||typeof ye.userCode=="string"&&ye.userCode||void 0;if(!Ie&&!he&&!me)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const Ee=`${oe}:${Se}`;D(Ve=>({...Ve,[Ee]:{url:Ie,instructions:he,userCode:me}})),Ie&&Zn(Ie),k({providerId:oe,methodIndex:Se}),H.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(we){console.error("Failed to start OAuth flow:",we),H.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},W=async(oe,Se)=>{const se=`${oe}:${Se}`,we=A[se]?.trim(),Ae=`oauth-complete:${oe}:${Se}`;x(Ae);try{const ve={method:Se};we&&(ve.code=we);const ye=await fetch(`/api/provider/${encodeURIComponent(oe)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ve)}),Ie=await ye.json().catch(()=>null);if(!ye.ok){const he=Ie?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(he)}H.success(t("settings.providers.page.toast.oauthCompleted")),j(he=>({...he,[se]:""})),k(null),await ai({scopes:["providers"],mode:"active"}),r(oe)}catch(ve){console.error("Failed to complete OAuth flow:",ve),H.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},Z=async oe=>{const Se=await An(oe);if(Se.ok){H.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",Se.error),H.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},K=async oe=>{const Se=await An(oe);if(Se.ok){H.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",Se.error),H.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},ie=async oe=>{const Se=`disconnect:${oe}`;x(Se);try{const se=await fetch(`/api/provider/${encodeURIComponent(oe)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),we=await se.json().catch(()=>null);if(!se.ok){const Ae=we?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(Ae)}H.success(t("settings.providers.page.toast.providerDisconnected")),await ai({scopes:["providers"],mode:"active"})}catch(se){console.error("Failed to disconnect provider:",se),H.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}},Ne=n===Ro;if(!Ne&&e.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(Ne)return s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.providers.page.connect.title")})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.connect.selectProviderTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),C?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):T?s.jsx("p",{className:"typography-meta text-muted-foreground",children:T}):q.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(Fs,{open:$,onOpenChange:oe=>{z(oe),oe||V("")},children:[s.jsx(Es,{asChild:!0,children:s.jsxs("button",{type:"button",className:ue("flex items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover h-6 w-fit"),children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[F?s.jsx(xn,{providerId:F,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ue("truncate typography-ui-label font-normal",F?"text-foreground":"text-muted-foreground"),children:F?q.find(oe=>oe.id===F)?.name||F:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Rs,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:oe=>oe.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:oe=>oe.stopPropagation(),children:[s.jsx(I,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:B,onChange:oe=>V(oe.target.value),onKeyDown:oe=>oe.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Ns,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const oe=q.filter(Se=>{const se=B.toLowerCase();return(Se.name||Se.id).toLowerCase().includes(se)||Se.id.toLowerCase().includes(se)});return oe.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):oe.map(Se=>s.jsxs($t,{onSelect:()=>{_(Se.id),z(!1),V("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(xn,{providerId:Se.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Se.name||Se.id})]}),F===Se.id&&s.jsx(I,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Se.id))})()})]})]})]})})]}),F&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")})}),u?s.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Vt,{type:"password",value:b[F]??"",onChange:oe=>h(Se=>({...Se,[F]:oe.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(xe,{size:"xs",className:"!font-normal shrink-0",onClick:()=>R(F),disabled:v===`api:${F}`,children:v===`api:${F}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const Se=(p[F]??[]).filter(se=>vp(se)==="oauth");return Se.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:Se.map((se,we)=>{const Ae=se.label||se.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(we+1)}),ve=`${F}:${we}`,ye=y?.providerId===F&&y?.methodIndex===we;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:Ae}),(se.description||se.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(se.description||se.help)})]}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>U(F,we),disabled:v===`oauth:${F}:${we}`,children:t("settings.providers.page.actions.connect")})]}),S[ve]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:S[ve]?.instructions}),S[ve]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:S[ve]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(S[ve]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),S[ve]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:S[ve]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Zn(S[ve]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Z(S[ve]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),ye&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:A[ve]??"",onChange:Ie=>j(he=>({...he,[ve]:Ie.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(xe,{size:"xs",className:"!font-normal",onClick:()=>W(F,we),disabled:v===`oauth-complete:${F}:${we}`,children:v===`oauth-complete:${F}:${we}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${F}-${Ae}`)})})})()]})]})]})});if(!ce)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const ne=Array.isArray(ce.models)?ce.models:[],pe=(p[ce.id]??[]).filter(oe=>vp(oe)==="oauth"),je=ne.filter(oe=>{const Se=typeof oe?.name=="string"?oe.name:"",se=typeof oe?.id=="string"?oe.id:"",we=g.trim().toLowerCase();return we?Se.toLowerCase().includes(we)||se.toLowerCase().includes(we):!0});return s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s.jsx(xn,{providerId:ce.id,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ce.name||ce.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:ce.id})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ee(oe=>!oe),children:t(J?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:J?u?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Vt,{type:"password",value:b[ce.id]??"",onChange:oe=>h(Se=>({...Se,[ce.id]:oe.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(xe,{size:"xs",className:"!font-normal shrink-0",onClick:()=>R(ce.id),disabled:v===`api:${ce.id}`,children:v===`api:${ce.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),pe.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:pe.map((oe,Se)=>{const se=oe.label||oe.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Se+1)}),we=`${ce.id}:${Se}`,Ae=y?.providerId===ce.id&&y?.methodIndex===Se;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:se}),(oe.description||oe.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(oe.description||oe.help)})]}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>U(ce.id,Se),disabled:v===`oauth:${ce.id}:${Se}`,children:t("settings.providers.page.actions.connect")})]}),S[we]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:S[we]?.instructions}),S[we]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:S[we]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(S[we]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),S[we]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:S[we]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Zn(S[we]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Z(S[we]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Ae&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:A[we]??"",onChange:ve=>j(ye=>({...ye,[we]:ve.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(xe,{size:"xs",className:"!font-normal",onClick:()=>W(ce.id,Se),disabled:v===`oauth-complete:${ce.id}:${Se}`,children:v===`oauth-complete:${ce.id}:${Se}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${ce.id}-${se}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(I,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-1",children:t("settings.providers.page.auth.useReconnectHint")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.connectionDetails.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:ae&&(ae.auth.exists||ae.user.exists||ae.project.exists||ae.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[ae.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,ae.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,ae.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,ae.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(xe,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ie(ce.id),disabled:v===`disconnect:${ce.id}`,children:v===`disconnect:${ce.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.providers.page.models.title"),ne.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ne.length,")"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const oe=ne.map(Se=>typeof Se?.id=="string"?Se.id:"").filter(Se=>Se.length>0);c(ce.id,oe)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(xe,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(ce.id),children:t("settings.providers.page.actions.showAll")})]})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(I,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Vt,{value:g,onChange:oe=>w(oe.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),je.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:je.map(oe=>{const Se=typeof oe?.id=="string"?oe.id:"",se=typeof oe?.name=="string"?oe.name:Se,we=Se?a(ce.id,Se):void 0,Ae=i.some(he=>he.providerID===ce.id&&he.modelID===Se),ve=yp(we?.limit?.context),ye=yp(we?.limit?.output),Ie=[];return we?.tool_call&&Ie.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),we?.reasoning&&Ie.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),we?.attachment&&Ie.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:ue("flex items-center gap-3",Ae&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:se}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(ve||ye)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[ve?`${ve} ${t("settings.providers.page.models.tokenBadge.context")}`:"",ve&&ye?" · ":"",ye?`${ye} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),Ie.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Ie.map(({key:he,icon:me,label:Ee})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Ee,"aria-label":Ee,children:s.jsx(I,{name:me,className:"h-3 w-3"})},he))}),s.jsx("button",{type:"button",onClick:()=>o(ce.id,Se),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(Ae?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Ae?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Ae?s.jsx(I,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},Se)})})]})]})]})})},n5=t=>{const e=t?.windows??{},n=Object.values(e).map(r=>r.usedPercent).filter(r=>typeof r=="number");return n.length===0?null:Math.max(...n)},r5=t=>{const e=ot.c(106),{onItemSelect:n}=t,{t:r}=pt(),a=Ms(a5),i=Ms(i5),o=Ms(o5),c=Ms(l5),d=Ms(c5),p=Ms(d5),m=Ms(u5),u=Ms(m5),f=Ms(p5),b=Ms(f5),h=Ms(h5),v=Ms(g5);let x,g;e[0]!==v?(x=()=>{v()},g=[v],e[0]=v,e[1]=x,e[2]=g):(x=e[1],g=e[2]),l.useEffect(x,g);const w=x5;let y;e[3]!==f?(y=me=>{f(me),w({usageAutoRefresh:me})},e[3]=f,e[4]=y):y=e[4];const k=y;let A;e[5]!==b?(A=me=>{const Ee=Number(me);Number.isFinite(Ee)&&(b(Ee),w({usageRefreshIntervalMs:Ee}))},e[5]=b,e[6]=A):A=e[6];const j=A;let S;e[7]!==h?(S=me=>{me!=="usage"&&me!=="remaining"||(h(me),w({usageDisplayMode:me}))},e[7]=h,e[8]=S):S=e[8];const D=S;let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=ue("flex h-full flex-col","bg-background"),e[9]=E):E=e[9];let P;e[10]!==r?(P=r("settings.usage.sidebar.title"),e[10]=r,e[11]=P):P=e[11];let C;e[12]!==P?(C=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:P}),e[12]=P,e[13]=C):C=e[13];let N;e[14]!==r?(N=r("settings.usage.sidebar.total",{count:Or.length}),e[14]=r,e[15]=N):N=e[15];let T;e[16]!==N?(T=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[16]=N,e[17]=T):T=e[17];let M;e[18]!==r?(M=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=M):M=e[19];let F;e[20]!==k||e[21]!==M||e[22]!==p?(F=s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(ds,{checked:p,onChange:k,ariaLabel:M})})}),e[20]=k,e[21]=M,e[22]=p,e[23]=F):F=e[23];let _;e[24]!==r?(_=r("settings.usage.sidebar.tooltip.autoRefresh"),e[24]=r,e[25]=_):_=e[25];let B;e[26]!==_?(B=s.jsx(Ct,{side:"bottom",children:_}),e[26]=_,e[27]=B):B=e[27];let V;e[28]!==F||e[29]!==B?(V=s.jsxs(St,{children:[F,B]}),e[28]=F,e[29]=B,e[30]=V):V=e[30];const $=String(m),z=!p;let Q;e[31]!==r?(Q=r("settings.usage.sidebar.field.intervalPlaceholder"),e[31]=r,e[32]=Q):Q=e[32];let L;e[33]!==Q?(L=s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:Q})}),e[33]=Q,e[34]=L):L=e[34];let J;e[35]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsxs(ls,{children:[s.jsx(Ft,{value:"30000",children:"30s"}),s.jsx(Ft,{value:"60000",children:"1m"}),s.jsx(Ft,{value:"300000",children:"5m"})]}),e[35]=J):J=e[35];let ee;e[36]!==j||e[37]!==$||e[38]!==z||e[39]!==L?(ee=s.jsxs(is,{value:$,onValueChange:j,disabled:z,children:[L,J]}),e[36]=j,e[37]=$,e[38]=z,e[39]=L,e[40]=ee):ee=e[40];let re;e[41]!==c?(re=()=>c(),e[41]=c,e[42]=re):re=e[42];let q;e[43]!==r?(q=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=q):q=e[44];let ce;e[45]!==r?(ce=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=ce):ce=e[46];const ae=d&&"animate-spin";let R;e[47]!==ae?(R=ue("h-3.5 w-3.5",ae),e[47]=ae,e[48]=R):R=e[48];let U;e[49]!==R?(U=s.jsx(I,{name:"refresh",className:R}),e[49]=R,e[50]=U):U=e[50];let W;e[51]!==d||e[52]!==re||e[53]!==q||e[54]!==ce||e[55]!==U?(W=s.jsx(xe,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:re,"aria-label":q,title:ce,disabled:d,children:U}),e[51]=d,e[52]=re,e[53]=q,e[54]=ce,e[55]=U,e[56]=W):W=e[56];let Z;e[57]!==V||e[58]!==ee||e[59]!==W?(Z=s.jsxs("div",{className:"flex items-center gap-2",children:[V,ee,W]}),e[57]=V,e[58]=ee,e[59]=W,e[60]=Z):Z=e[60];let K;e[61]!==T||e[62]!==Z?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[T,Z]}),e[61]=T,e[62]=Z,e[63]=K):K=e[63];let ie;e[64]!==r?(ie=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=ie):ie=e[65];let Ne;e[66]!==ie?(Ne=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ie}),e[66]=ie,e[67]=Ne):Ne=e[67];let ne;e[68]!==r?(ne=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=ne):ne=e[69];let fe;e[70]!==ne?(fe=s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:ne})}),e[70]=ne,e[71]=fe):fe=e[71];let pe;e[72]!==r?(pe=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=pe):pe=e[73];let je;e[74]!==pe?(je=s.jsx(Ft,{value:"usage",children:pe}),e[74]=pe,e[75]=je):je=e[75];let oe;e[76]!==r?(oe=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=oe):oe=e[77];let Se;e[78]!==oe?(Se=s.jsx(Ft,{value:"remaining",children:oe}),e[78]=oe,e[79]=Se):Se=e[79];let se;e[80]!==je||e[81]!==Se?(se=s.jsxs(ls,{children:[je,Se]}),e[80]=je,e[81]=Se,e[82]=se):se=e[82];let we;e[83]!==D||e[84]!==fe||e[85]!==se||e[86]!==u?(we=s.jsxs(is,{value:u,onValueChange:D,children:[fe,se]}),e[83]=D,e[84]=fe,e[85]=se,e[86]=u,e[87]=we):we=e[87];let Ae;e[88]!==Ne||e[89]!==we?(Ae=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[Ne,we]}),e[88]=Ne,e[89]=we,e[90]=Ae):Ae=e[90];let ve;e[91]!==K||e[92]!==Ae||e[93]!==C?(ve=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,K,Ae]}),e[91]=K,e[92]=Ae,e[93]=C,e[94]=ve):ve=e[94];let ye;e[95]!==n||e[96]!==a||e[97]!==i||e[98]!==o||e[99]!==r?(ye=Or.map(me=>{const Ee=a.find(ge=>ge.providerId===me.id),Ve=n5(Ee?.usage),Y=bh(Ve),ke=me.id===i,Be=Ee?.configured??!1,Ce=Be?Y==="critical"?{backgroundColor:"var(--status-error)"}:Y==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ue("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ke?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{o(me.id),n?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:Ce}),s.jsx(xn,{providerId:me.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:me.name}),!Be&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},me.id)}),e[95]=n,e[96]=a,e[97]=i,e[98]=o,e[99]=r,e[100]=ye):ye=e[100];let Ie;e[101]!==ye?(Ie=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:ye}),e[101]=ye,e[102]=Ie):Ie=e[102];let he;return e[103]!==ve||e[104]!==Ie?(he=s.jsxs("div",{className:E,children:[ve,Ie]}),e[103]=ve,e[104]=Ie,e[105]=he):he=e[105],he};function a5(t){return t.results}function i5(t){return t.selectedProviderId}function o5(t){return t.setSelectedProvider}function l5(t){return t.fetchAllQuotas}function c5(t){return t.isLoading}function d5(t){return t.autoRefresh}function u5(t){return t.refreshIntervalMs}function m5(t){return t.displayMode}function p5(t){return t.setAutoRefresh}function f5(t){return t.setRefreshInterval}function h5(t){return t.setDisplayMode}function g5(t){return t.loadSettings}async function x5(t){try{await Is(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Ac=t=>{const e=ot.c(52),{title:n,window:r,subtitle:a,showToggle:i,toggleEnabled:o,onToggle:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=Ms(b5),u=m==="remaining"?r.remainingPercent:r.usedPercent,f=m==="remaining"?"remaining":"used";let b;e[0]!==u||e[1]!==r.valueLabel?(b=eo(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=b):b=e[2];const h=b,v=r.resetAfterFormatted??r.resetAtFormatted;let x;e[3]!==v||e[4]!==r.resetAt?(x=Wd(r.resetAt,v),e[3]=v,e[4]=r.resetAt,e[5]=x):x=e[5];const g=x;let w;e[6]!==n?(w=Kd(n),e[6]=n,e[7]=w):w=e[7];const y=w;let k;e[8]!==n||e[9]!==r.resetAt||e[10]!==r.usedPercent||e[11]!==r.windowSeconds?(k=to(r.usedPercent,r.resetAt,r.windowSeconds,n),e[8]=n,e[9]=r.resetAt,e[10]=r.usedPercent,e[11]=r.windowSeconds,e[12]=k):k=e[12];const A=k;let j;e:{if(!A||A.dailyAllocationPercent===null){j=null;break e}const ee=Kr(A.elapsedRatio);j=m==="remaining"?100-ee:ee}const S=j;let D;e[13]!==c||e[14]!==d||e[15]!==p?(D=d&&s.jsx(ds,{checked:p,onChange:ee=>c?.(ee),ariaLabel:"Show in dropdown"}),e[13]=c,e[14]=d,e[15]=p,e[16]=D):D=e[16];let E;e[17]!==y?(E=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:y}),e[17]=y,e[18]=E):E=e[18];let P;e[19]!==a?(P=a&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:a}),e[19]=a,e[20]=P):P=e[20];let C;e[21]!==E||e[22]!==P?(C=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[E,P]}),e[21]=E,e[22]=P,e[23]=C):C=e[23];let N;e[24]!==C||e[25]!==D?(N=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[D,C]}),e[24]=C,e[25]=D,e[26]=N):N=e[26];const T=h==="-"?"":h;let M;e[27]!==T?(M=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:T}),e[27]=T,e[28]=M):M=e[28];let F;e[29]!==N||e[30]!==M?(F=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[N,M]}),e[29]=N,e[30]=M,e[31]=F):F=e[31];let _;e[32]!==u||e[33]!==S||e[34]!==r.usedPercent?(_=s.jsx(no,{percent:u,tonePercent:r.usedPercent,expectedMarkerPercent:S,className:"h-1.5"}),e[32]=u,e[33]=S,e[34]=r.usedPercent,e[35]=_):_=e[35];const B=g?`Resets ${g}`:"";let V;e[36]!==B?(V=s.jsx("span",{className:"typography-micro text-muted-foreground",children:B}),e[36]=B,e[37]=V):V=e[37];let $;e[38]!==f?($=s.jsx("span",{className:"typography-micro text-muted-foreground",children:f}),e[38]=f,e[39]=$):$=e[39];let z;e[40]!==V||e[41]!==$?(z=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[V,$]}),e[40]=V,e[41]=$,e[42]=z):z=e[42];let Q;e[43]!==_||e[44]!==z?(Q=s.jsxs("div",{className:"mt-2.5",children:[_,z]}),e[43]=_,e[44]=z,e[45]=Q):Q=e[45];let L;e[46]!==A?(L=A&&s.jsx("div",{className:"mt-1.5",children:s.jsx(ro,{paceInfo:A})}),e[46]=A,e[47]=L):L=e[47];let J;return e[48]!==F||e[49]!==Q||e[50]!==L?(J=s.jsxs("div",{className:"py-3",children:[F,Q,L]}),e[48]=F,e[49]=Q,e[50]=L,e[51]=J):J=e[51],J};function b5(t){return t.displayMode}const y5=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},v5=()=>{const{t}=pt(),e=Ms(N=>N.results),n=Ms(N=>N.selectedProviderId),r=Ms(N=>N.setSelectedProvider),a=Ms(N=>N.loadSettings),i=Ms(N=>N.fetchAllQuotas),o=Ms(N=>N.isLoading),c=Ms(N=>N.lastUpdated),d=Ms(N=>N.error),p=Ms(N=>N.dropdownProviderIds),m=Ms(N=>N.setDropdownProviderIds),u=Ms(N=>N.selectedModels),f=Ms(N=>N.toggleModelSelected),b=Ms(N=>N.applyDefaultSelections);Nh(),l.useEffect(()=>{a(),i()},[a,i]),l.useEffect(()=>{if(n||e.length===0)return;const N=e.find(T=>T.configured)?.providerId;r(N??Or[0]?.id??null)},[e,n,r]);const h=e.find(N=>N.providerId===n)??null,x=Or.find(N=>N.id===n)?.name??n??t("settings.usage.sidebar.title"),g=h?.usage,w=n?p.includes(n):!1,y=l.useCallback(N=>{if(!n)return;const T=N?Array.from(new Set([...p,n])):p.filter(M=>M!==n);m(T),Is({usageDropdownProviders:T})},[p,n,m]),k=l.useMemo(()=>g?.models?Object.entries(g.models).map(([N,T])=>({name:N,windows:T})).filter(N=>Object.keys(N.windows.windows).length>0):[],[g?.models]);l.useEffect(()=>{n&&k.length>0&&b(n,k.map(N=>N.name))},[n,k,b]);const A=l.useMemo(()=>!n||k.length===0?new Map:_v(k,N=>N.name,n),[k,n]),j=l.useMemo(()=>{if(!n)return[];const N=wh(n);return jh(N)},[n]),[S,D]=l.useState(()=>({})),E=l.useCallback(N=>{D(T=>({...T,[N]:!T[N]}))},[]),P=l.useCallback(N=>{if(!n)return;f(n,N);const T=u[n]??[],F=T.includes(N)?T.filter(B=>B!==N):[...T,N],_={...u,[n]:F};Is({usageSelectedModels:_})},[n,u,f]),C=n?u[n]??[]:[];return n?s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s.jsx(xn,{providerId:n,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.usage.page.header.providerUsage",{provider:x})}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:o?s.jsx("span",{className:"animate-pulse",children:t("settings.usage.page.header.refreshing")}):t("settings.usage.page.header.lastUpdated",{time:y5(c)})})]})]}),s.jsx("div",{className:"mb-8 px-2",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>y(!w),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),y(!w))},children:[s.jsx(ds,{checked:w,onChange:y,ariaLabel:t("settings.usage.page.options.showInHeaderAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.options.showInHeader")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!h&&s.jsx("div",{className:"mb-8 px-2",children:s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noData")})}),d&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:d})]}),h&&!h.configured&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([N,T])=>s.jsx(Ac,{title:N,window:T},N))})})}),k.length>0&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.usage.page.section.modelQuotas")})}),s.jsxs("div",{className:"space-y-3",children:[j.map(N=>{const T=A.get(N.id)??[];if(T.length===0)return null;const M=S[N.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(pr,{open:!M,onOpenChange:()=>E(N.id),children:[s.jsxs(Nr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:N.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",T.length,")"]})]}),M?s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(fr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:T.map(F=>{const _=Object.entries(F.windows.windows);if(_.length===0)return null;const[B,V]=_[0],$=C.includes(F.name);return s.jsx(Ac,{title:B,subtitle:cl(F.name),window:V,showToggle:!0,toggleEnabled:$,onToggle:()=>P(F.name)},F.name)})})})]})},N.id)}),(()=>{const N=A.get(null)??[];if(N.length===0)return null;const T=S.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(pr,{open:!T,onOpenChange:()=>E("other"),children:[s.jsxs(Nr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",N.length,")"]})]}),T?s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(fr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:N.map(M=>{const F=Object.entries(M.windows.windows);if(F.length===0)return null;const[_,B]=F[0],V=C.includes(M.name);return s.jsx(Ac,{title:_,subtitle:cl(M.name),window:B,showToggle:!0,toggleEnabled:V,onToggle:()=>P(M.name)},M.name)})})})]})})})()]})]}),h?.configured&&g&&Object.keys(g.windows??{}).length===0&&k.length===0&&s.jsxs("div",{className:"mb-8 px-2",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]})}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},w5="git.commit.generate",yd=nr(t=>({selectedPromptId:w5,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),j5=t=>{const e=ot.c(23),{onItemSelect:n}=t,{t:r}=pt(),a=yd(N5),i=yd(S5);let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=o):o=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[o,c,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=p):p=e[3];const m=p;let u;e[4]!==r?(u=r("settings.magicPrompts.sidebar.title"),e[4]=r,e[5]=u):u=e[5];let f;e[6]!==u?(f=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:u}),e[6]=u,e[7]=f):f=e[7];let b;e[8]!==r?(b=r("settings.magicPrompts.sidebar.description"),e[8]=r,e[9]=b):b=e[9];let h;e[10]!==b?(h=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[10]=b,e[11]=h):h=e[11];let v;e[12]!==f||e[13]!==h?(v=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[f,h]}),e[12]=f,e[13]=h,e[14]=v):v=e[14];let x;e[15]!==n||e[16]!==a||e[17]!==i||e[18]!==r?(x=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(w=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:r(w.groupKey)}),w.items.map(y=>{const k=a===y.id;return s.jsx("button",{type:"button",onClick:()=>{i(y.id),n?.()},className:ue("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",k?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:r(y.titleKey)})},y.id)})]},w.groupKey))}),e[15]=n,e[16]=a,e[17]=i,e[18]=r,e[19]=x):x=e[19];let g;return e[20]!==x||e[21]!==v?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[v,x]}),e[20]=x,e[21]=v,e[22]=g):g=e[22],g};function N5(t){return t.selectedPromptId}function S5(t){return t.setSelectedPromptId}const wp={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},jp=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Np=t=>t.endsWith(".visible"),k5=()=>{const{t}=pt(),e=l.useCallback(j=>t(j),[t]),n=yd(j=>j.selectedPromptId),[r,a]=l.useState(!0),[i,o]=l.useState({}),[c,d]=l.useState({}),[p,m]=l.useState({}),[u,f]=l.useState({}),[b,h]=l.useState(!1);l.useEffect(()=>{let j=!0;return(async()=>{a(!0);try{const D=await zb();if(!j)return;o(D)}catch(D){console.warn("Failed to load magic prompts:",D),H.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&a(!1)}})(),()=>{j=!1}},[t]);const v=wp[n]??wp["git.commit.generate"],x=l.useCallback(j=>jp(i,j)?i[j]:Xl(j),[i]),g=l.useCallback(j=>c[j]??x(j),[c,x]),w=l.useCallback((j,S)=>{d(D=>D[j]===S?D:{...D,[j]:S})},[]),y=l.useCallback(async j=>{const S=g(j);if(Np(j)&&S.trim().length===0){H.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(D=>({...D,[j]:!0}));try{const D=S===Xl(j)?await Nu(j):await $b(j,S);o(D.overrides),H.success(t("settings.magicPrompts.page.toast.saved"))}catch(D){const E=D instanceof Error?D.message:String(D);H.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:E})}finally{m(D=>({...D,[j]:!1}))}},[g,t]),k=l.useCallback(async j=>{f(S=>({...S,[j]:!0}));try{const S=await Nu(j);o(S.overrides),d(D=>({...D,[j]:Xl(j)})),H.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(S){const D=S instanceof Error?S.message:String(S);H.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:D})}finally{f(S=>({...S,[j]:!1}))}},[t]),A=l.useCallback(async()=>{h(!0);try{const j=await Bb();o(j.overrides),d({}),H.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const S=j instanceof Error?j.message:String(j);H.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:S})}finally{h(!1)}},[t]);return r?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(v.titleKey)}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:e(v.descriptionKey)})]})]})}),s.jsx(xe,{variant:"outline",size:"sm",onClick:()=>{A()},disabled:b||Object.keys(i).length===0,children:t(b?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),v.blocks.map((j,S)=>{const D=_b(j.id),E=x(j.id),P=g(j.id),C=jp(i,j.id),N=P!==E,T=Np(j.id)&&P.trim().length===0,M=p[j.id]===!0,F=u[j.id]===!0;return s.jsxs("section",{className:S>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label text-foreground",children:e(j.titleKey)}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:D.description})]})]}),D.placeholders&&D.placeholders.length>0&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[t("settings.magicPrompts.page.placeholdersLabel")," ",D.placeholders.map(_=>`{{${_.key}}}`).join(", ")]})]}),s.jsx(fn,{value:P,onChange:_=>w(j.id,_.target.value),className:"min-h-[220px] font-mono text-sm"}),T&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(N?"settings.magicPrompts.page.status.unsavedChanges":C?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xe,{variant:"outline",size:"sm",onClick:()=>{k(j.id)},disabled:!C||M||F,children:t(F?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(xe,{size:"sm",onClick:()=>{y(j.id)},disabled:!N||M||F||T,children:t(M?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})]})})},bg=()=>{const{t}=pt(),e=vt(u=>u.settingsGitmojiEnabled),n=vt(u=>u.setSettingsGitmojiEnabled),r=Od(),a=De(u=>u.gitChangesViewMode),i=De(u=>u.setGitChangesViewMode),[o,c]=l.useState(!0),d=l.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);l.useEffect(()=>{(async()=>{try{let f=null;if(!f){const b=sr()?.settings;if(b)try{const v=(await b.load())?.settings;v&&(f={gitmojiEnabled:typeof v.gitmojiEnabled=="boolean"?v.gitmojiEnabled:void 0,gitChangesViewMode:v.gitChangesViewMode==="flat"||v.gitChangesViewMode==="tree"?v.gitChangesViewMode:void 0})}catch{}}if(!f){const b=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});b.ok&&(f=await b.json())}f&&(typeof f.gitmojiEnabled=="boolean"&&n(f.gitmojiEnabled),(f.gitChangesViewMode==="flat"||f.gitChangesViewMode==="tree")&&i(f.gitChangesViewMode))}catch(f){console.warn("Failed to load git settings:",f)}finally{c(!1)}})()},[i,n]);const p=l.useCallback(async u=>{n(u);try{await Is({gitmojiEnabled:u})}catch(f){console.warn("Failed to save gitmoji setting:",f)}},[n]),m=l.useCallback(u=>{u!==a&&(i(u),Is({gitChangesViewMode:u}))},[a,i]);return o?null:s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"pt-1 pb-1",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.changesViewTitle")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.openchamber.git.changesViewAria"),className:"mt-0.5 space-y-0",children:d.map(u=>{const f=a===u.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>{m(u.id)},onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),m(u.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:f,onChange:()=>{m(u.id)},ariaLabel:t("settings.openchamber.git.optionAria",{option:u.label})}),s.jsx("span",{className:f?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:u.label})]},u.id)})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{p(!e)},onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),p(!e))},children:[s.jsx(ds,{checked:e,onChange:u=>{p(u)},ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.enableGitmoji")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":r,onClick:()=>Zl(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),Zl(!r))},children:[s.jsx(ds,{checked:r,onChange:Zl,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},yg=()=>{const{t}=pt(),{isMobile:e}=nn(),n=sr()?.github,r=zn(D=>D.status),a=zn(D=>D.isLoading),i=zn(D=>D.hasChecked),o=zn(D=>D.refreshStatus),c=zn(D=>D.setStatus),d=l.useCallback(async D=>{await Zn(D)},[]),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState(null),v=l.useRef(null),x=l.useCallback(()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null),h(null)},[]);l.useEffect(()=>((async()=>{try{i||await o(n)}catch(D){console.warn("Failed to load GitHub auth status:",D)}})(),()=>{x()}),[i,o,n,x]);const g=l.useCallback(async()=>{m(!0);try{const D=n?await n.authStart():await(async()=>{const P=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),C=await P.json().catch(()=>null);if(!P.ok||!C||!("deviceCode"in C))throw new Error(C?.error||P.statusText);return C})();f(D),h(Math.max(1,D.interval)*1e3);const E=D.verificationUriComplete||D.verificationUri;d(E)}catch(D){console.error("Failed to start GitHub connect:",D),H.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),w=l.useCallback(async D=>{if(n)return n.authComplete(D);const E=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:D})}),P=await E.json().catch(()=>null);if(!E.ok||!P)throw new Error(P?.error||E.statusText);return P},[n]);l.useEffect(()=>{if(!(!u?.deviceCode||!b)&&v.current==null)return v.current=window.setInterval(()=>{(async()=>{try{const D=await w(u.deviceCode);if(D.connected){H.success(t("settings.github.page.toast.connected")),f(null),x(),await o(n,{force:!0});return}D.status==="slow_down"&&h(E=>E?E+5e3:5e3),(D.status==="expired_token"||D.status==="access_denied")&&(H.error(D.error||t("settings.github.page.toast.authorizationFailed")),f(null),x())}catch(D){console.warn("GitHub polling failed:",D)}})()},b),()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null)}},[u,b,w,o,n,x,t]);const y=l.useCallback(async()=>{m(!0);try{if(x(),f(null),n)await n.authDisconnect();else{const D=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!D.ok)throw new Error(D.statusText)}H.success(t("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(D){console.error("Failed to disconnect GitHub:",D),H.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[o,n,x,t]),k=l.useCallback(async D=>{if(D){m(!0);try{const E=n?await n.authActivate(D):await(async()=>{const P=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:D})}),C=await P.json().catch(()=>null);if(!P.ok||!C)throw new Error(C?.error||P.statusText);return C})();c(E),H.success(t("settings.github.page.toast.accountSwitched"))}catch(E){console.error("Failed to switch GitHub account:",E),H.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(a)return null;const A=!!r?.connected,j=r?.user,S=r?.accounts??[];return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"GitHub"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.github.page.tooltip.connectAccount")})]})]})}),s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[A?s.jsxs("div",{className:ue("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ue("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:j.login?t("settings.github.page.avatarAlt.withLogin",{login:j.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:j?.name?.trim()||j?.login||"GitHub"}),s.jsxs("div",{className:ue("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:j?.login||t("settings.github.page.label.unknownUser")}),j?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&s.jsx("span",{children:j.email})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:r.scope})})]})]}),s.jsx(xe,{size:"sm",variant:"outline",onClick:y,disabled:p,className:ue("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(xe,{size:"sm",variant:"default",onClick:g,disabled:p,children:t("settings.github.page.actions.connect")})]}),S.length>1&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:S.map(D=>{const E=D.user,P=!!D.current;return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[E?.avatarUrl?s.jsx("img",{src:E.avatarUrl,alt:E.login?t("settings.github.page.avatarAlt.withLogin",{login:E.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(I,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:E?.name?.trim()||E?.login||"GitHub"}),E?.login&&s.jsx("span",{className:"typography-micro text-muted-foreground truncate font-mono",children:E.login})]})]}),P?s.jsx("span",{className:"typography-micro text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:t("settings.github.page.status.active")}):s.jsx(xe,{size:"sm",variant:"ghost",onClick:()=>k(D.id),disabled:p,children:t("settings.github.page.actions.switchTo")})]},D.id)})})]})]}),A&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(xe,{size:"sm",variant:"outline",onClick:g,disabled:p,className:ue(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),u&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h4",{className:"typography-ui-label text-foreground",children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:u.userCode}),s.jsx(xe,{size:"sm",asChild:!0,children:s.jsx("a",{href:u.verificationUriComplete||u.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(xe,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{x(),f(null)},children:t("settings.common.actions.cancel")})]})]})]})},Sp=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],C5=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],I5=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:a}=pt(),i=Jn(L=>L.getProfileById),o=Jn(L=>L.createProfile),c=Jn(L=>L.updateProfile),d=Jn(L=>L.deleteProfile),p=l.useMemo(()=>n&&n!=="new"&&!r?i(n):null,[n,i,r]),m=n==="new"||r!=null,u=n==="global",[f,b]=l.useState(""),[h,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState("ssh"),[k,A]=l.useState(""),[j,S]=l.useState(""),[D,E]=l.useState("keyword"),[P,C]=l.useState("branch"),[N,T]=l.useState(!1),[M,F]=l.useState(!1),[_,B]=l.useState(!1);l.useEffect(()=>{if(t){if(r){const L=r.host.split("/"),J=L.length>=3?L[L.length-1]:r.host;b(J),v(r.username),g(""),y("token"),A(""),S(r.host),E("string"),C("code")}else if(m)b(""),v(""),g(""),y("ssh"),A(""),S(""),E("keyword"),C("branch");else if(p)b(p.name),v(p.userName),g(p.userEmail),y(p.authType||"ssh"),A(p.sshKey||""),S(p.host||""),E(p.color||"keyword"),C(p.icon||"branch");else if(u){const L=i("global");L&&(b(L.name),v(L.userName),g(L.userEmail),y(L.authType||"ssh"),A(L.sshKey||""),S(L.host||""),E(L.color||"keyword"),C(L.icon||"branch"))}}},[t,n,p,m,r,u,i]);const V=async()=>{if(!h.trim()||!x.trim()){H.error(a("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(w==="token"&&!j.trim()){H.error(a("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}T(!0);try{const L={name:f.trim()||h.trim(),userName:h.trim(),userEmail:x.trim(),authType:w,sshKey:w==="ssh"&&k.trim()||null,host:w==="token"&&j.trim()||null,color:D,icon:P};let J;if(m)J=await o(L);else if(n)J=await c(n,L);else return;J?(H.success(a(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):H.error(a(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(L){console.error("Error saving profile:",L),H.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{T(!1)}},$=async()=>{if(!(!n||m)){B(!0);try{await d(n)?(H.success(a("settings.gitIdentities.editor.toast.profileDeleted")),F(!1),e(!1)):H.error(a("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(L){console.error("Error deleting profile:",L),H.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{B(!1)}}},z=l.useMemo(()=>Sp.find(J=>J.key===D)?.cssVar||"var(--syntax-keyword)",[D]),Q=r?a("settings.gitIdentities.editor.title.importCredential"):m?a("settings.gitIdentities.editor.title.newIdentity"):u?a("settings.gitIdentities.editor.title.globalIdentity"):p?.name||a("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:Q}),s.jsx(Ps,{children:a(u?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!u&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-ui-label text-foreground block mb-1.5",children:a("settings.gitIdentities.editor.field.profileName")}),s.jsx(Vt,{value:f,onChange:L=>b(L.target.value),placeholder:a("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Sp.map(L=>s.jsx("button",{type:"button",onClick:()=>E(L.key),className:ue("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",D===L.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:L.cssVar},title:L.label},L.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:C5.map(L=>{const J=L.Icon;return s.jsx("button",{type:"button",onClick:()=>C(L.key),className:ue("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",P===L.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:L.label,children:s.jsx(I,{name:J,className:"w-3.5 h-3.5",style:{color:P===L.key?z:"var(--surface-muted-foreground)"}})},L.key)})})]})]}),!u&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.userName")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),s.jsx(Vt,{value:h,onChange:L=>v(L.target.value),placeholder:a("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.emailAddress")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),s.jsx(Vt,{type:"email",value:x,onChange:L=>g(L.target.value),placeholder:a("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]})]}),!u&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(xe,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="ssh",onClick:()=>y("ssh"),children:[s.jsx(I,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(xe,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="token",onClick:()=>y("token"),children:[s.jsx(I,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.gitIdentities.editor.field.authToken")]})]})]}),w==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),s.jsx(Vt,{value:k,onChange:L=>A(L.target.value),placeholder:a("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),w==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.hostTooltip")})]})]}),s.jsx(Vt,{value:j,onChange:L=>S(L.target.value),placeholder:a("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Us,{className:"gap-2",children:[!u&&!m&&s.jsxs(xe,{variant:"outline",size:"sm",onClick:()=>F(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(I,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:a(u?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!u&&s.jsx(xe,{size:"sm",onClick:V,disabled:N,children:a(N?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(ps,{open:M,onOpenChange:L=>{_||F(L)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Ps,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||f})})]}),s.jsxs(Us,{children:[s.jsx(xe,{variant:"ghost",onClick:()=>F(!1),disabled:_,children:a("settings.common.actions.cancel")}),s.jsx(xe,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:_,children:a("settings.common.actions.delete")})]})]})})]})},P5={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},A5={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},D5=()=>{const t=ot.c(116),{t:e}=pt(),{profiles:n,globalIdentity:r,defaultGitIdentityId:a,deleteProfile:i,loadProfiles:o,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=Jn(hr(M5)),[f,b]=l.useState(!1),[h,v]=l.useState(null),[x,g]=l.useState(null),[w,y]=l.useState(null),[k,A]=l.useState(!1);let j,S;t[0]!==p||t[1]!==d||t[2]!==c||t[3]!==o?(j=()=>{o(),c(),d(),p()},S=[o,c,d,p],t[0]=p,t[1]=d,t[2]=c,t[3]=o,t[4]=j,t[5]=S):(j=t[4],S=t[5]),l.useEffect(j,S);let D,E,P,C,N,T,M,F,_,B,V,$,z;if(t[6]!==a||t[7]!==w||t[8]!==i||t[9]!==u||t[10]!==r||t[11]!==n||t[12]!==m||t[13]!==e){const ve=u();let ye;t[27]===Symbol.for("react.memo_cache_sentinel")?(ye=(O,X)=>{v(O),g(X??null),b(!0)},t[27]=ye):ye=t[27];const Ie=ye;let he;t[28]!==a||t[29]!==m||t[30]!==e?(he=async O=>{const X=a===O?null:O;if(!await m(X)){H.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}H.success(e(X?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[28]=a,t[29]=m,t[30]=e,t[31]=he):he=t[31];const me=he;let Ee;t[32]!==w||t[33]!==i||t[34]!==e?(Ee=async()=>{if(!w)return;A(!0),await i(w.id)?(H.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:w.name})),y(null)):H.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),A(!1)},t[32]=w,t[33]=i,t[34]=e,t[35]=Ee):Ee=t[35],E=Ee,D=Ns,C="h-full",N="w-full bg-background",z="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",t[36]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(yg,{}),t[36]=P):P=t[36],V="border-t border-border/40 pt-6";let Ve;t[37]!==e?(Ve=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=Ve):Ve=t[38];let Y;t[39]!==Ve?(Y=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:Ve})}),t[39]=Ve,t[40]=Y):Y=t[40];let ke,Be;t[41]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>Ie("new"),Be=s.jsx(I,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=ke,t[42]=Be):(ke=t[41],Be=t[42]);let Ce;t[43]!==e?(Ce=e("settings.common.badge.new"),t[43]=e,t[44]=Ce):Ce=t[44];let ge;t[45]!==Ce?(ge=s.jsxs(xe,{size:"sm",variant:"outline",onClick:ke,children:[Be," ",Ce]}),t[45]=Ce,t[46]=ge):ge=t[46],t[47]!==Y||t[48]!==ge?($=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[Y,ge]}),t[47]=Y,t[48]=ge,t[49]=$):$=t[49],T="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",M=r&&s.jsx(kp,{profile:r,isDefault:a==="global",onEdit:()=>Ie("global"),onToggleDefault:()=>me("global"),isReadOnly:!0,hasBorder:n.length>0||ve.length>0}),F=n.map((O,X)=>s.jsx(kp,{profile:O,isDefault:a===O.id,onEdit:()=>Ie(O.id),onToggleDefault:()=>me(O.id),onDelete:()=>y(O),hasBorder:X<n.length-1||ve.length>0},O.id)),_=!r&&n.length===0&&ve.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),B=ve.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),ve.map((O,X)=>s.jsx(T5,{credential:O,onImport:()=>Ie("new",{host:O.host,username:O.username}),hasBorder:X<ve.length-1},`${O.host}-${O.username}`))]}),t[6]=a,t[7]=w,t[8]=i,t[9]=u,t[10]=r,t[11]=n,t[12]=m,t[13]=e,t[14]=D,t[15]=E,t[16]=P,t[17]=C,t[18]=N,t[19]=T,t[20]=M,t[21]=F,t[22]=_,t[23]=B,t[24]=V,t[25]=$,t[26]=z}else D=t[14],E=t[15],P=t[16],C=t[17],N=t[18],T=t[19],M=t[20],F=t[21],_=t[22],B=t[23],V=t[24],$=t[25],z=t[26];let Q;t[50]!==T||t[51]!==M||t[52]!==F||t[53]!==_||t[54]!==B?(Q=s.jsxs("div",{className:T,children:[M,F,_,B]}),t[50]=T,t[51]=M,t[52]=F,t[53]=_,t[54]=B,t[55]=Q):Q=t[55];let L;t[56]!==Q||t[57]!==V||t[58]!==$?(L=s.jsxs("div",{className:V,children:[$,Q]}),t[56]=Q,t[57]=V,t[58]=$,t[59]=L):L=t[59];let J;t[60]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(bg,{}),t[60]=J):J=t[60];let ee;t[61]!==P||t[62]!==L||t[63]!==z?(ee=s.jsxs("div",{className:z,children:[P,L,J]}),t[61]=P,t[62]=L,t[63]=z,t[64]=ee):ee=t[64];let re;t[65]!==D||t[66]!==C||t[67]!==N||t[68]!==ee?(re=s.jsx(D,{outerClassName:C,className:N,children:ee}),t[65]=D,t[66]=C,t[67]=N,t[68]=ee,t[69]=re):re=t[69];let q;t[70]!==x||t[71]!==f||t[72]!==h?(q=s.jsx(I5,{open:f,onOpenChange:b,profileId:h,importData:x}),t[70]=x,t[71]=f,t[72]=h,t[73]=q):q=t[73];const ce=w!==null;let ae;t[74]!==k?(ae=ve=>{k||ve||y(null)},t[74]=k,t[75]=ae):ae=t[75];let R;t[76]!==e?(R=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=R):R=t[77];let U;t[78]!==R?(U=s.jsx(gs,{children:R}),t[78]=R,t[79]=U):U=t[79];const W=w?.name??"";let Z;t[80]!==e||t[81]!==W?(Z=e("settings.gitIdentities.page.deleteDialog.description",{name:W}),t[80]=e,t[81]=W,t[82]=Z):Z=t[82];let K;t[83]!==Z?(K=s.jsx(Ps,{children:Z}),t[83]=Z,t[84]=K):K=t[84];let ie;t[85]!==U||t[86]!==K?(ie=s.jsxs(vs,{children:[U,K]}),t[85]=U,t[86]=K,t[87]=ie):ie=t[87];let Ne;t[88]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>y(null),t[88]=Ne):Ne=t[88];let ne;t[89]!==e?(ne=e("settings.common.actions.cancel"),t[89]=e,t[90]=ne):ne=t[90];let fe;t[91]!==k||t[92]!==ne?(fe=s.jsx(xe,{variant:"ghost",onClick:Ne,disabled:k,children:ne}),t[91]=k,t[92]=ne,t[93]=fe):fe=t[93];let pe;t[94]!==E?(pe=()=>{E()},t[94]=E,t[95]=pe):pe=t[95];let je;t[96]!==e?(je=e("settings.common.actions.delete"),t[96]=e,t[97]=je):je=t[97];let oe;t[98]!==k||t[99]!==pe||t[100]!==je?(oe=s.jsx(xe,{size:"sm",variant:"destructive",onClick:pe,disabled:k,children:je}),t[98]=k,t[99]=pe,t[100]=je,t[101]=oe):oe=t[101];let Se;t[102]!==fe||t[103]!==oe?(Se=s.jsxs(Us,{children:[fe,oe]}),t[102]=fe,t[103]=oe,t[104]=Se):Se=t[104];let se;t[105]!==ie||t[106]!==Se?(se=s.jsxs(ms,{className:"max-w-md",children:[ie,Se]}),t[105]=ie,t[106]=Se,t[107]=se):se=t[107];let we;t[108]!==ce||t[109]!==ae||t[110]!==se?(we=s.jsx(ps,{open:ce,onOpenChange:ae,children:se}),t[108]=ce,t[109]=ae,t[110]=se,t[111]=we):we=t[111];let Ae;return t[112]!==re||t[113]!==q||t[114]!==we?(Ae=s.jsxs(s.Fragment,{children:[re,q,we]}),t[112]=re,t[113]=q,t[114]=we,t[115]=Ae):Ae=t[115],Ae},kp=t=>{const e=ot.c(54),{profile:n,isDefault:r,onEdit:a,onToggleDefault:i,onDelete:o,isReadOnly:c,hasBorder:d}=t,{t:p}=pt(),m=P5[n.icon||"branch"]||"git-branch",u=A5[n.color||""],f=n.authType||"ssh",b=d&&"border-b border-[var(--surface-subtle)]";let h;e[0]!==b?(h=ue("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",b),e[0]=b,e[1]=h):h=e[1];let v;e[2]!==a?(v=V=>{(V.key==="Enter"||V.key===" ")&&a()},e[2]=a,e[3]=v):v=e[3];let x;e[4]!==u?(x={color:u},e[4]=u,e[5]=x):x=e[5];let g;e[6]!==m||e[7]!==x?(g=s.jsx(I,{name:m,className:"w-4 h-4 shrink-0",style:x}),e[6]=m,e[7]=x,e[8]=g):g=e[8];let w;e[9]!==n.name?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=w):w=e[10];let y;e[11]!==f?(y=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f}),e[11]=f,e[12]=y):y=e[12];let k;e[13]!==r||e[14]!==p?(k=r&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:p("settings.gitIdentities.page.badge.default")}),e[13]=r,e[14]=p,e[15]=k):k=e[15];let A;e[16]!==c||e[17]!==p?(A=c&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:p("settings.agents.sidebar.badge.system")}),e[16]=c,e[17]=p,e[18]=A):A=e[18];let j;e[19]!==w||e[20]!==y||e[21]!==k||e[22]!==A?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,y,k,A]}),e[19]=w,e[20]=y,e[21]=k,e[22]=A,e[23]=j):j=e[23];const S=f==="token"&&n.host?n.host:n.userEmail;let D;e[24]!==S?(D=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:S}),e[24]=S,e[25]=D):D=e[25];let E;e[26]!==j||e[27]!==D?(E=s.jsxs("div",{className:"min-w-0",children:[j,D]}),e[26]=j,e[27]=D,e[28]=E):E=e[28];let P;e[29]!==E||e[30]!==g?(P=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[g,E]}),e[29]=E,e[30]=g,e[31]=P):P=e[31];let C;e[32]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(Es,{asChild:!0,children:s.jsx(xe,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:E5,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=C):C=e[32];let N;e[33]!==i?(N=V=>{V.stopPropagation(),i()},e[33]=i,e[34]=N):N=e[34];let T;e[35]!==r||e[36]!==p?(T=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=T):T=e[37];let M;e[38]!==N||e[39]!==T?(M=s.jsx($t,{onClick:N,children:T}),e[38]=N,e[39]=T,e[40]=M):M=e[40];let F;e[41]!==c||e[42]!==o||e[43]!==p?(F=!c&&o&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]}),e[41]=c,e[42]=o,e[43]=p,e[44]=F):F=e[44];let _;e[45]!==M||e[46]!==F?(_=s.jsxs(Fs,{children:[C,s.jsxs(Rs,{align:"end",className:"w-fit min-w-28",children:[M,F]})]}),e[45]=M,e[46]=F,e[47]=_):_=e[47];let B;return e[48]!==a||e[49]!==P||e[50]!==h||e[51]!==_||e[52]!==v?(B=s.jsxs("div",{className:h,onClick:a,role:"button",tabIndex:0,onKeyDown:v,children:[P,_]}),e[48]=a,e[49]=P,e[50]=h,e[51]=_,e[52]=v,e[53]=B):B=e[53],B},T5=t=>{const e=ot.c(21),{credential:n,onImport:r,hasBorder:a}=t,{t:i}=pt();let o;e[0]!==n.host?(o=n.host.split("/"),e[0]=n.host,e[1]=o):o=e[1];const c=o,d=c.length>=3?c[c.length-1]:n.host,p=n.host.includes("/"),m=a&&"border-b border-[var(--surface-subtle)]";let u;e[2]!==m?(u=ue("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=u):u=e[3];let f;e[4]!==d?(f=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=f):f=e[5];const b=p?n.host:n.username;let h;e[6]!==b?(h=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:b}),e[6]=b,e[7]=h):h=e[7];let v;e[8]!==f||e[9]!==h?(v=s.jsxs("div",{className:"min-w-0",children:[f,h]}),e[8]=f,e[9]=h,e[10]=v):v=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(I,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let g;e[12]!==i?(g=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=g):g=e[13];let w;e[14]!==r||e[15]!==g?(w=s.jsxs(xe,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[x,g]}),e[14]=r,e[15]=g,e[16]=w):w=e[16];let y;return e[17]!==w||e[18]!==u||e[19]!==v?(y=s.jsxs("div",{className:u,children:[v,w]}),e[17]=w,e[18]=u,e[19]=v,e[20]=y):y=e[20],y};function M5(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function E5(t){return t.stopPropagation()}const vg=()=>{const t=Vb();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},wg=()=>{const t=ot.c(2),[e,n]=l.useState(R5);let r,a;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const i=[window.matchMedia("(display-mode: standalone)"),window.matchMedia("(display-mode: minimal-ui)"),window.matchMedia("(display-mode: fullscreen)"),window.matchMedia("(display-mode: window-controls-overlay)")],o=()=>{n(vg())};o();for(const c of i)typeof c.addEventListener=="function"?c.addEventListener("change",o):typeof c.addListener=="function"&&c.addListener(o);return window.addEventListener("appinstalled",o),window.addEventListener("focus",o),()=>{for(const c of i)typeof c.removeEventListener=="function"?c.removeEventListener("change",o):typeof c.removeListener=="function"&&c.removeListener(o);window.removeEventListener("appinstalled",o),window.removeEventListener("focus",o)}},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),l.useEffect(r,a),e};function R5(){return vg()}const F5=[{value:"system",labelKey:"settings.openchamber.visual.option.themeMode.system"},{value:"light",labelKey:"settings.openchamber.visual.option.themeMode.light"},{value:"dark",labelKey:"settings.openchamber.visual.option.themeMode.dark"}],O5=[{id:"dynamic",labelKey:"settings.openchamber.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.openchamber.visual.option.diffLayout.inline.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.openchamber.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.sideBySide.description"}],L5=[{id:"single",labelKey:"settings.openchamber.visual.option.diffViewMode.single.label",descriptionKey:"settings.openchamber.visual.option.diffViewMode.single.description"},{id:"stacked",labelKey:"settings.openchamber.visual.option.diffViewMode.stacked.label",descriptionKey:"settings.openchamber.visual.option.diffViewMode.stacked.description"}],$5=[{id:"svg",labelKey:"settings.openchamber.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.openchamber.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.ascii.description"}],Mi="OpenChamber - AI Coding Assistant",Cp=[{id:"system",labelKey:"settings.openchamber.visual.option.pwaOrientation.system.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.openchamber.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.openchamber.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.landscape.description"}],Ip=[{id:"native",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.description"}],Dc=t=>t==="portrait"||t==="landscape"?t:"system",B5=[{id:"markdown",labelKey:"settings.openchamber.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.openchamber.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.plain.description"}],_5=[{id:"sorted",labelKey:"settings.openchamber.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.openchamber.visual.option.chatRenderMode.live.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.live.description"}],Pp=[{id:"auto",labelKey:"settings.openchamber.visual.option.messageTransport.auto.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.openchamber.visual.option.messageTransport.ws.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.openchamber.visual.option.messageTransport.sse.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.sse.description"}],z5=[{id:"collapsed",labelKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.openchamber.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.summary.description"}],Ap=[{id:"auto",labelKey:"settings.openchamber.visual.option.timeFormat.auto.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.openchamber.visual.option.timeFormat.24h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.openchamber.visual.option.timeFormat.12h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.12h.description"}],Dp=[{id:"auto",labelKey:"settings.openchamber.visual.option.weekStart.auto.label",descriptionKey:"settings.openchamber.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.openchamber.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.openchamber.visual.option.weekStart.sunday.label"}],V5=t=>t==="markdown"?"markdown":"plain",su=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:a,t:i}=pt(),o=l.useCallback(te=>i(te),[i]),{isMobile:c}=nn(),{browserTab:d}=wg(),p=Tl(),m=De(te=>te.showReasoningTraces),u=De(te=>te.setShowReasoningTraces),f=De(te=>te.collapsibleThinkingBlocks),b=De(te=>te.setCollapsibleThinkingBlocks),h=De(te=>te.mermaidRenderingMode),v=De(te=>te.setMermaidRenderingMode),x=De(te=>te.userMessageRenderingMode),g=De(te=>te.setUserMessageRenderingMode),w=De(te=>te.stickyUserHeader),y=De(te=>te.setStickyUserHeader),k=De(te=>te.wideChatLayoutEnabled),A=De(te=>te.setWideChatLayoutEnabled),j=De(te=>te.chatRenderMode),S=De(te=>te.setChatRenderMode),D=De(te=>te.activityRenderMode),E=De(te=>te.setActivityRenderMode),P=De(te=>te.fontSize),C=De(te=>te.setFontSize),N=De(te=>te.terminalFontSize),T=De(te=>te.setTerminalFontSize),M=De(te=>te.uiFont),F=De(te=>te.setUiFont),_=De(te=>te.monoFont),B=De(te=>te.setMonoFont),V=De(te=>te.padding),$=De(te=>te.setPadding),z=De(te=>te.inputBarOffset),Q=De(te=>te.setInputBarOffset),L=De(te=>te.mobileKeyboardMode),J=De(te=>te.setMobileKeyboardMode),ee=De(te=>te.diffLayoutPreference),re=De(te=>te.setDiffLayoutPreference),q=De(te=>te.diffViewMode),ce=De(te=>te.setDiffViewMode),ae=De(te=>te.showTerminalQuickKeysOnDesktop),R=De(te=>te.setShowTerminalQuickKeysOnDesktop),U=Su(te=>te.queueModeEnabled),W=Su(te=>te.setQueueMode),Z=De(te=>te.persistChatDraft),K=De(te=>te.setPersistChatDraft),ie=De(te=>te.inputSpellcheckEnabled),Ne=De(te=>te.setInputSpellcheckEnabled),ne=De(te=>te.showToolFileIcons),fe=De(te=>te.setShowToolFileIcons),pe=De(te=>te.showExpandedBashTools),je=De(te=>te.setShowExpandedBashTools),oe=De(te=>te.showExpandedEditTools),Se=De(te=>te.setShowExpandedEditTools),se=De(te=>te.timeFormatPreference),we=De(te=>te.setTimeFormatPreference),Ae=De(te=>te.weekStartPreference),ve=De(te=>te.setWeekStartPreference),ye=De(te=>te.showSplitAssistantMessageActions),Ie=De(te=>te.setShowSplitAssistantMessageActions),he=De(te=>te.showMobileSessionStatusBar),me=De(te=>te.setShowMobileSessionStatusBar),Ee=vt(te=>te.settingsMessageStreamTransport),Ve=vt(te=>te.setSettingsMessageStreamTransport),Y=De(te=>te.isSettingsDialogOpen),{themeMode:ke,setThemeMode:Be,availableThemes:Ce,customThemesLoading:ge,reloadCustomThemes:O,lightThemeId:X,darkThemeId:G,setLightThemePreference:Te,setDarkThemePreference:le}=Sr(),[We,de]=l.useState(!1),[Fe,rt]=l.useState(0),Oe=De(te=>te.reportUsage),Ye=De(te=>te.setReportUsage),Ge=l.useCallback(te=>{Ye(te),Is({reportUsage:te})},[Ye]),it=Y&&(t?t.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!it)return;let te=null,bt=Date.now();const Ze=()=>{const es=Date.now();es-bt>=420&&(rt(rs=>(rs+1)%24),bt=es),te=requestAnimationFrame(Ze)};(typeof document>"u"||document.visibilityState==="visible")&&(te=requestAnimationFrame(Ze));const Wt=()=>{document.visibilityState==="visible"&&te===null?te=requestAnimationFrame(Ze):document.visibilityState!=="visible"&&te!==null&&(cancelAnimationFrame(te),te=null)};return document.addEventListener("visibilitychange",Wt),()=>{document.removeEventListener("visibilitychange",Wt),te!==null&&cancelAnimationFrame(te)}},[it]);const Qe=l.useCallback(te=>{g(te),Is({userMessageRenderingMode:te})},[g]),at=l.useCallback(te=>{y(te),Is({stickyUserHeader:te})},[y]),nt=l.useCallback(te=>{A(te),Is({wideChatLayoutEnabled:te})},[A]),be=l.useCallback(te=>{Ie(te),Is({showSplitAssistantMessageActions:te})},[Ie]),He=l.useCallback(te=>{Ne(te),Is({inputSpellcheckEnabled:te})},[Ne]),_e=l.useCallback(te=>{S(te),Is({chatRenderMode:te})},[S]),tt=l.useCallback(te=>{Ve(te),Is({messageStreamTransport:te})},[Ve]),ut=l.useCallback(te=>{E(te),Is({activityRenderMode:te})},[E]),qe=l.useCallback(te=>{v(te),Is({mermaidRenderingMode:te})},[v]),ze=l.useCallback(te=>{fe(te),Is({showToolFileIcons:te})},[fe]),st=l.useCallback(te=>{je(te),Is({showExpandedBashTools:te})},[je]),yt=l.useCallback(te=>{Se(te),Is({showExpandedEditTools:te})},[Se]),Mt=l.useCallback(te=>{we(te),Is({timeFormatPreference:te})},[we]),Bt=l.useCallback(te=>{ve(te),Is({weekStartPreference:te})},[ve]),ft=l.useMemo(()=>Ce.filter(te=>te.metadata.variant==="light").sort((te,bt)=>te.metadata.name.localeCompare(bt.metadata.name)),[Ce]),It=l.useMemo(()=>Ce.filter(te=>te.metadata.variant==="dark").sort((te,bt)=>te.metadata.name.localeCompare(bt.metadata.name)),[Ce]),ss=l.useMemo(()=>ft.find(te=>te.metadata.id===X)??ft[0],[ft,X]),_t=l.useMemo(()=>It.find(te=>te.metadata.id===G)??It[0],[It,G]),qt=l.useCallback((te,bt)=>{const Ze=bt==="dark"?" Dark":" Light";return te.endsWith(Ze)?te.slice(0,-Ze.length):te},[]),ct=te=>t?t.includes(te):!0,jt=ln(),as=ct("theme")&&!jt,xs=ct("theme")||ct("timeFormat")||ct("weekStart"),ws=jt?xs:ct("theme")||ct("pwaInstallName")||ct("pwaOrientation")||ct("timeFormat")||ct("weekStart"),As=ct("fontSize")||ct("terminalFontSize")||ct("spacing")||ct("inputBarOffset"),Gt=ct("terminalQuickKeys")&&!c,Ke=ct("mermaidRendering")||ct("userMessageRendering")||ct("chatRenderMode")||ct("messageTransport")||ct("activityRenderMode")&&j==="sorted"||ct("stickyUserHeader")||ct("wideChatLayout")||ct("splitAssistantMessageActions")||ct("diffLayout")||ct("mobileStatusBar")&&c||ct("dotfiles")||ct("reasoning")||ct("queueMode")||ct("persistDraft")||ct("showToolFileIcons")||ct("expandedTools")||!c&&ct("inputSpellcheck"),Pt=ct("pwaInstallName")&&Hr()&&d&&!dn()&&!jt,Ot=ct("pwaOrientation")&&Hr()&&!dn()&&!jt,Nt=ct("mobileKeyboardMode")&&Hr()&&!dn()&&!jt&&Ub(),[Ht,ns]=l.useState(""),[Ss,fs]=l.useState("system"),Os=l.useMemo(()=>{const te=Ap.find(bt=>bt.id===se);return o(te?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[se,o]),zs=l.useMemo(()=>{const te=Dp.find(bt=>bt.id===Ae);return o(te?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[Ae,o]),tn=l.useMemo(()=>{const te=Cp.find(bt=>bt.id===Ss);return te?o(te.labelKey):void 0},[Ss,o]),Ds=l.useMemo(()=>{const te=Ip.find(bt=>bt.id===L);return te?o(te.labelKey):void 0},[L,o]),zt=l.useCallback(async te=>{if(typeof window>"u")return;const bt=window,Wt=te.trim().replace(/\s+/g," ").slice(0,64);if(await Is({pwaAppName:Wt}),typeof bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const es=bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Wt);ns(es);return}ns(Wt||Mi),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Kt=l.useCallback(async te=>{if(typeof window>"u")return;const bt=window,Ze=Dc(te);if(await Is({pwaOrientation:Ze}),typeof bt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Wt=bt.__OPENCHAMBER_SET_PWA_ORIENTATION__(Ze);fs(Wt);return}fs(Ze),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!Pt&&!Ot&&!Nt)return;let te=!1;return(async()=>{try{const Ze=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Ze.ok){te||ns(Mi);return}const Wt=await Ze.json().catch(()=>({})),rs=(typeof Wt?.pwaAppName=="string"?Wt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ue=Dc(Wt?.pwaOrientation),xt=Au(Wt?.mobileKeyboardMode);te||(Pt&&ns(rs||Mi),Ot&&fs(Ue),Nt&&J(xt))}catch{te||(Pt&&ns(Mi),Ot&&fs("system"),Nt&&J("native"))}})(),()=>{te=!0}},[J,Nt,Pt,Ot]),s.jsxs("div",{className:"space-y-8",children:[ws&&s.jsxs("div",{className:"mb-8 space-y-6",children:[as&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.colorMode")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:F5.map(te=>s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":ke===te.value,className:"!font-normal",onClick:()=>Be(te.value),children:o(te.labelKey)},te.value))})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.lightTheme")}),s.jsxs(is,{value:ss?.metadata.id??"",onValueChange:Te,children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:ss?qt(ss.metadata.name,"light"):void 0})}),s.jsx(ls,{children:ft.map(te=>s.jsx(Ft,{value:te.metadata.id,children:qt(te.metadata.name,"light")},te.metadata.id))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.darkTheme")}),s.jsxs(is,{value:_t?.metadata.id??"",onValueChange:le,children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:_t?qt(_t.metadata.name,"dark"):void 0})}),s.jsx(ls,{children:It.map(te=>s.jsx(Ft,{value:te.metadata.id,children:qt(te.metadata.name,"dark")},te.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:ge||We,onClick:()=>{const te=Date.now();de(!0),O().finally(()=>{const bt=Date.now()-te;if(bt<500){window.setTimeout(()=>{de(!1)},500-bt);return}de(!1)})},className:"inline-flex items-center typography-ui-label font-normal text-foreground underline decoration-[1px] underline-offset-2 hover:text-foreground/80 disabled:cursor-not-allowed disabled:text-muted-foreground/60",children:i(We?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:"flex items-center justify-center rounded-md p-1 text-muted-foreground/70 hover:text-foreground","aria-label":i("settings.openchamber.visual.field.themeImportInfoAria"),children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(Ct,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),xs&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.localization")}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.appearance.language.label")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.appearance.language.description")})]}),s.jsxs(is,{value:e,onValueChange:te=>r(te),children:[s.jsx(os,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:s.jsx(us,{children:a(e)})}),s.jsx(ls,{children:n.map(te=>s.jsx(Ft,{value:te,children:a(te)},te))})]})]}),!jt&&(ct("timeFormat")||ct("weekStart"))&&s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[ct("timeFormat")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.timeFormat")}),s.jsxs(is,{value:se,onValueChange:te=>Mt(te),children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(us,{children:Os})}),s.jsx(ls,{children:Ap.map(te=>s.jsx(Ft,{value:te.id,children:o(te.labelKey)},te.id))})]})]}),ct("weekStart")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.weekStartsOn")}),s.jsxs(is,{value:Ae,onValueChange:te=>Bt(te),children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(us,{children:zs})}),s.jsx(ls,{children:Dp.map(te=>s.jsx(Ft,{value:te.id,children:o(te.labelKey)},te.id))})]})]})]})]}),(Pt||Ot||Nt)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[Pt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installAppName")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installAppNameHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[s.jsx(Vt,{value:Ht,onChange:te=>{ns(te.target.value)},onBlur:()=>{zt(Ht)},onKeyDown:te=>{te.key==="Enter"&&(te.preventDefault(),zt(Ht))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ns(Mi),zt("")},className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Ot&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installOrientation")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installOrientationHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(is,{value:Ss,onValueChange:te=>{const bt=Dc(te);fs(bt),Kt(bt)},children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:tn})}),s.jsx(ls,{children:Cp.map(te=>s.jsx(Ft,{value:te.id,children:o(te.labelKey)},te.id))})]}),s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>{fs("system"),Kt("system")},disabled:Ss==="system",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Nt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardMode")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardModeHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(is,{value:L,onValueChange:te=>{const bt=Au(te);J(bt),Is({mobileKeyboardMode:bt})},children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Ds})}),s.jsx(ls,{children:Ip.map(te=>s.jsx(Ft,{value:te.id,children:o(te.labelKey)},te.id))})]}),s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>{J("native"),Is({mobileKeyboardMode:"native"})},disabled:L==="native",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),As&&s.jsx("div",{className:"mb-8 space-y-3",children:s.jsxs("section",{className:"p-2 space-y-0.5",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.spacingAndLayout")}),s.jsxs("div",{className:"pl-2",children:[ct("fontSize")&&!c&&s.jsxs("div",{className:"flex items-center gap-8 py-1",children:[s.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFont")})}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsxs(is,{value:M,onValueChange:te=>F(te),children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(us,{children:ku.find(te=>te.id===M)?.label})}),s.jsx(ls,{children:ku.map(te=>s.jsx(Ft,{value:te.id,children:s.jsx("span",{style:{fontFamily:te.stack},children:te.label})},te.id))})]}),s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(Cu),disabled:M===Cu,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ct("terminalFontSize")&&s.jsxs("div",{className:ue("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ue("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeFont")})}),s.jsxs("div",{className:ue("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsxs(is,{value:_,onValueChange:te=>B(te),children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(us,{children:Iu.find(te=>te.id===_)?.label})}),s.jsx(ls,{children:Iu.map(te=>s.jsx(Ft,{value:te.id,children:s.jsx("span",{style:{fontFamily:te.stack},children:te.label})},te.id))})]}),s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>B(Pu),disabled:_===Pu,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ct("fontSize")&&!c&&s.jsxs("div",{className:"flex items-center gap-8 py-1",children:[s.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFontSize")})}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(Fn,{value:P,onValueChange:C,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>C(100),disabled:P===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ct("terminalFontSize")&&s.jsxs("div",{className:ue("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ue("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalFontSize")})}),s.jsxs("div",{className:ue("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Fn,{value:N,onValueChange:T,min:9,max:52,step:1,className:"w-16"}),s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>T(13),disabled:N===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ct("spacing")&&s.jsxs("div",{className:ue("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ue("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.spacingDensity")})}),s.jsxs("div",{className:ue("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Fn,{value:V,onValueChange:$,min:50,max:200,step:5,className:"w-16"}),s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>$(100),disabled:V===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ct("inputBarOffset")&&s.jsxs("div",{className:ue("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ue("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.inputBarOffset")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),s.jsxs("div",{className:ue("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Fn,{value:z,onValueChange:Q,min:0,max:100,step:5,className:"w-16"}),s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:()=>Q(0),disabled:z===0,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),Gt&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.navigation")}),ct("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ae,onClick:()=>R(!ae),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),R(!ae))},children:[s.jsx(ds,{checked:ae,onChange:R,ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalQuickKeys")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),Ke&&s.jsxs("div",{className:"space-y-3",children:[(ct("userMessageRendering")||ct("mermaidRendering")||ct("chatRenderMode")||ct("messageTransport")||ct("activityRenderMode")&&j==="sorted"||ct("diffLayout")&&!jt)&&s.jsxs("div",{className:"grid grid-cols-1 gap-y-2 md:grid-cols-[minmax(0,16rem)_minmax(0,16rem)] md:justify-start md:gap-x-2",children:[ct("chatRenderMode")&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.chatRenderMode")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.chatRenderModeAria"),className:"mt-1 grid w-full max-w-[26rem] grid-cols-1 gap-3 sm:grid-cols-2",children:_5.map(te=>{const bt=j===te.id,Ze=Fe%12;return s.jsxs("button",{type:"button",onClick:()=>_e(te.id),"aria-pressed":bt,className:ue("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",bt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ue("typography-ui-label",bt?"text-foreground":"text-muted-foreground"),children:o(te.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:te.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Wt=>{const es=Wt*3+1,rs=Ze-es+1,Ue=rs<=0?0:rs===1?42:rs===2?68:92,xt=Ue>0;return s.jsxs("div",{className:ue("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",xt?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${Ue}%`}})]},Wt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Wt=>{const es=Ze>=(Wt+1)*3;return s.jsxs("div",{className:ue("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",es?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},Wt)})})})]},te.id)})})]}),ct("messageTransport")&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.messageStreamTransport")}),s.jsxs("div",{className:"mt-1 flex max-w-[24rem] flex-col gap-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Pp.map(te=>s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":Ee===te.id,className:"!font-normal",onClick:()=>tt(te.id),children:o(te.labelKey)},te.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const te=Pp.find(bt=>bt.id===Ee);return te?.descriptionKey?o(te.descriptionKey):""})()})]})]}),ct("activityRenderMode")&&j==="sorted"&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.activityDefault")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:z5.map(te=>{const bt=D===te.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>ut(te.id),onKeyDown:Ze=>{(Ze.key===" "||Ze.key==="Enter")&&(Ze.preventDefault(),ut(te.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:bt,onChange:()=>ut(te.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(te.labelKey)})}),s.jsx("span",{className:ue("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:o(te.labelKey)})]},te.id)})})]}),ct("expandedTools")&&s.jsxs("section",{className:"p-2 md:col-span-2 space-y-0.5",children:[s.jsx("div",{className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.showToolsOpenedByDefault")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":pe,onClick:()=>st(!pe),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),st(!pe))},children:[s.jsx(ds,{checked:pe,onChange:st,ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.bash")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":oe,onClick:()=>yt(!oe),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),yt(!oe))},children:[s.jsx(ds,{checked:oe,onChange:yt,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),ct("userMessageRendering")&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.userMessageRendering")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.userMessageRenderingAria"),className:"mt-0.5 space-y-0",children:B5.map(te=>{const bt=V5(x)===te.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>Qe(te.id),onKeyDown:Ze=>{(Ze.key===" "||Ze.key==="Enter")&&(Ze.preventDefault(),Qe(te.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:bt,onChange:()=>Qe(te.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(te.labelKey)})}),s.jsx("span",{className:ue("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:o(te.labelKey)})]},te.id)})})]}),ct("mermaidRendering")&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.mermaidRendering")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.mermaidRenderingAria"),className:"mt-0.5 space-y-0",children:$5.map(te=>{const bt=h===te.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>qe(te.id),onKeyDown:Ze=>{(Ze.key===" "||Ze.key==="Enter")&&(Ze.preventDefault(),qe(te.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:bt,onChange:()=>qe(te.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(te.labelKey)})}),s.jsx("span",{className:ue("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:o(te.labelKey)})]},te.id)})})]}),ct("diffLayout")&&!jt&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.diffLayout")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.diffLayoutAria"),className:"mt-0.5 space-y-0",children:O5.map(te=>{const bt=ee===te.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>re(te.id),onKeyDown:Ze=>{(Ze.key===" "||Ze.key==="Enter")&&(Ze.preventDefault(),re(te.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:bt,onChange:()=>re(te.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:o(te.labelKey)})}),s.jsx("span",{className:ue("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:o(te.labelKey)})]},te.id)})})]}),ct("diffLayout")&&!jt&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.diffViewMode")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.diffViewModeAria"),className:"mt-0.5 space-y-0",children:L5.map(te=>{const bt=q===te.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>ce(te.id),onKeyDown:Ze=>{(Ze.key===" "||Ze.key==="Enter")&&(Ze.preventDefault(),ce(te.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:bt,onChange:()=>ce(te.id),ariaLabel:i("settings.openchamber.visual.field.diffViewModeAria",{option:o(te.labelKey)})}),s.jsx("span",{className:ue("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:o(te.labelKey)})]},te.id)})})]})]}),(ct("stickyUserHeader")||ct("wideChatLayout")||ct("splitAssistantMessageActions")||ct("mobileStatusBar")&&c||ct("dotfiles")||ct("queueMode")||ct("persistDraft")||ct("showToolFileIcons")||!c&&ct("inputSpellcheck")||ct("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[ct("reasoning")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),u(!m))},children:[s.jsx(ds,{checked:m,onChange:u,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),ct("reasoning")&&m&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>b(!f),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),b(!f))},children:[s.jsx(ds,{checked:f,onChange:b,ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleThinkingBlocks")})]}),ct("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>at(!w),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),at(!w))},children:[s.jsx(ds,{checked:w,onChange:at,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),ct("wideChatLayout")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":k,onClick:()=>nt(!k),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),nt(!k))},children:[s.jsx(ds,{checked:k,onChange:nt,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),ct("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ye,onClick:()=>be(!ye),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),be(!ye))},children:[s.jsx(ds,{checked:ye,onChange:be,ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActions")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),ct("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ne,onClick:()=>ze(!ne),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),ze(!ne))},children:[s.jsx(ds,{checked:ne,onChange:ze,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),ct("mobileStatusBar")&&c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":he,onClick:()=>me(!he),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),me(!he))},children:[s.jsx(ds,{checked:he,onChange:me,ariaLabel:i("settings.openchamber.visual.field.showMobileStatusBarAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showMobileStatusBar")})]}),ct("dotfiles")&&!ln()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>Uo(!p),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),Uo(!p))},children:[s.jsx(ds,{checked:p,onChange:Uo,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),ct("queueMode")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":U,onClick:()=>W(!U),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),W(!U))},children:[s.jsx(ds,{checked:U,onChange:W,ariaLabel:i("settings.openchamber.visual.field.queueMessagesByDefaultAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.queueMessagesByDefault")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.queueMessagesByDefaultTooltip",{modifier:ll()})})]})]})]}),ct("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Z,onClick:()=>K(!Z),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),K(!Z))},children:[s.jsx(ds,{checked:Z,onChange:K,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!c&&ct("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ie,onClick:()=>He(!ie),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),He(!ie))},children:[s.jsx(ds,{checked:ie,onChange:He,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),ct("reportUsage")&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground mb-2",children:i("settings.openchamber.visual.section.privacy")}),s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(ds,{checked:Oe,onChange:Ge,ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[s.jsx("div",{className:"group flex cursor-pointer",role:"button",tabIndex:0,"aria-pressed":Oe,onClick:()=>Ge(!Oe),onKeyDown:te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),Ge(!Oe))},children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sendAnonymousUsageReports")})}),s.jsx("span",{className:"typography-meta text-muted-foreground pointer-events-none",children:i("settings.openchamber.visual.field.sendAnonymousUsageReportsHint")})]})]})]})})]})};function U5(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=Gb();return t}catch{return"unknown"}}function W5(){const t=typeof window<"u"?window.__VSCODE_CONFIG__?.arch?.toLowerCase?.():void 0;if(t==="arm64"||t==="aarch64")return"arm64";if(t==="x64"||t==="amd64"||t==="x86_64")return"x64";const n=(typeof navigator<"u"?navigator.userAgentData:void 0)?.architecture?.toLowerCase?.();if(n==="arm"||n==="arm64"||n==="aarch64")return"arm64";if(n==="x86"||n==="x64"||n==="amd64")return"x64";const r=typeof navigator<"u"?navigator.userAgent.toLowerCase():"";return r.includes("aarch64")||r.includes("arm64")||r.includes("armv")?"arm64":r.includes("x86_64")||r.includes("x64")||r.includes("amd64")||r.includes("win64")?"x64":"unknown"}function K5(){if(typeof navigator>"u")return"web";const t=(navigator.platform||"").toLowerCase();return t.includes("mac")?"macos":t.includes("win")?"windows":t.includes("linux")?"linux":"web"}function H5(t){const e=De.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",U5()),n.set("arch",W5()),n.set("platform",K5()),t==="desktop"?(n.set("appType",Hb()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",Gr()?"local":"remote"),n):t==="vscode"?(n.set("appType","vscode"),n.set("instanceMode","local"),n):(n.set("appType","web"),n.set("instanceMode","unknown"),n)}async function Tc(t,e){try{const n=H5(t),r=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e?n.set("currentVersion",e):t==="vscode"&&r&&n.set("currentVersion",r);const a=await fetch(`/api/openchamber/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!a.ok)throw new Error(`Server responded with ${a.status}`);const i=await a.json();return{available:i.available??!1,version:i.version,currentVersion:i.currentVersion??"unknown",body:i.body,nextSuggestedCheckInSec:typeof i.nextSuggestedCheckInSec=="number"&&Number.isFinite(i.nextSuggestedCheckInSec)?i.nextSuggestedCheckInSec:void 0,packageManager:i.packageManager,updateCommand:i.updateCommand}}catch(n){return console.warn("Failed to check for updates:",n),null}}function G5(){return Ma()?Gr()?"desktop":"web":ln()?"vscode":Hr()?"web":null}const Tp={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Da=nr()((t,e)=>({...Tp,checkForUpdates:async()=>{const n=G5();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,a=null;if(n==="desktop"){let i=await ec();t({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null});const o=await Tc("desktop",i?.currentVersion);if(a=o?.nextSuggestedCheckInSec??null,o?.available&&!i?.available){const c=await ec();c&&(i=c)}if(o){const c={...i??{available:!1,currentVersion:o.currentVersion??"unknown"},...o,currentVersion:i?.currentVersion??o.currentVersion??"unknown",available:o.available};t({available:c.available,info:c,nextCheckInSec:a})}else t({nextCheckInSec:a});return a}else n==="web"?(r=await Tc("web"),a=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(a=(await Tc("vscode"))?.nextSuggestedCheckInSec??null);return t({checking:!1,available:n==="vscode"?!1:r?.available??!1,info:n==="vscode"?null:r,lastChecked:Date.now(),nextCheckInSec:a}),a}catch(r){return t({checking:!1,error:r instanceof Error?r.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:r}=e();if(!(r!=="desktop"||!n)){t({downloading:!0,error:null,progress:null});try{const a=await ec();if(!a?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(t(o=>({info:o.info?{...o.info,...a,body:o.info.body||a.body,available:o.info.available}:a})),!await Kb(o=>{t({progress:o})}))throw new Error("Desktop update only works on Local instance");t({downloading:!1,downloaded:!0})}catch(a){t({downloading:!1,error:a instanceof Error?a.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:r}=e();if(!(r!=="desktop"||!n))try{if(!await Wb())throw new Error("Desktop restart only works on Local instance")}catch(a){t({error:a instanceof Error?a.message:"Failed to restart"})}},dismiss:()=>{t({available:!1,downloaded:!1,info:null})},reset:()=>{t(Tp)}})),Mp="https://github.com/btriapitsyn/openchamber/releases";function q5(t){const e=new Date(`${t}T00:00:00`);return Number.isNaN(e.getTime())?t:new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric"}).format(e)}function Y5(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Ep(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function J5(t,e){const n=t.split(".").map(a=>Number.parseInt(a,10)),r=e.split(".").map(a=>Number.parseInt(a,10));for(let a=0;a<3;a+=1){const i=Number.isFinite(n[a])?n[a]:0,o=Number.isFinite(r[a])?r[a]:0;if(i!==o)return o-i}return 0}function Q5(t){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let r;for(;(r=e.exec(t))!==null;)n.push({version:r[1]??"",date:r[2]??"",start:r.index});return n.length===0?[]:n.map((a,i)=>{const o=n[i+1]?.start??t.length,c=t.slice(a.start,o).trim();return{version:a.version,date:a.date,start:a.start,end:o,raw:c}})}const Rp=2e3,X5=600*1e3;async function Z5(){try{const t=await fetch("/api/openchamber/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});return t.ok?{success:!0,autoRestart:(await t.json().catch(()=>({}))).autoRestart!==!1}:{success:!1,error:(await t.json().catch(()=>({}))).error||`Server error: ${t.status}`}}catch(t){return{success:!1,error:t instanceof Error?t.message:void 0}}}async function eC(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function tC(t,e=Math.ceil(X5/Rp),n=Rp){for(let r=0;r<e;r++){try{const a=await fetch("/api/openchamber/update-check",{method:"GET",headers:{Accept:"application/json"}});if(a.ok){const i=await a.json().catch(()=>null);if(i&&i.available===!1||i&&typeof i.currentVersion=="string"&&typeof t=="string"&&i.currentVersion!==t)return!0}else if((a.status===401||a.status===403)&&await eC())return!0}catch{}await new Promise(a=>setTimeout(a,n))}return!1}const vd=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:a,progress:i,error:o,onDownload:c,onRestart:d,runtimeType:p="desktop"})=>{const{t:m}=pt(),[u,f]=$e.useState(!1),[b,h]=$e.useState("idle"),[v,x]=$e.useState(null),g=n?.version?`${Mp}/tag/v${n.version}`:Mp,w=i?.total?Math.round(i.downloaded/i.total*100):0,y=p==="web",k=n?.updateCommand||"openchamber update";$e.useEffect(()=>{t||(h("idle"),x(null))},[t]);const A=async()=>{(await An(k)).ok&&(f(!0),setTimeout(()=>f(!1),2e3))},j=$e.useCallback(async P=>{await Zn(P)},[]),S=$e.useCallback(async()=>{h("updating"),x(null);const P=await Z5();if(!P.success){h("error"),x(P.error||m("updateDialog.error.updateFailed"));return}P.autoRestart&&(h("restarting"),await new Promise(N=>setTimeout(N,2e3))),h("reconnecting"),await tC(n?.currentVersion)?window.location.reload():(h("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),D=b!=="idle"&&b!=="error",E=$e.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const C=Q5(P);if(C.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Ep(P)};const N=[...C].sort((T,M)=>J5(T.version,M.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:N.map(T=>({version:T.version,dateLabel:q5(T.date),content:Ep(Y5(T.raw)||P)}))}},[n?.body,m]);return s.jsx(ps,{open:t,onOpenChange:D?void 0:e,children:s.jsxs(ms,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[s.jsxs("div",{className:"flex items-center mb-1",children:[s.jsxs(gs,{className:"flex items-center gap-2.5",children:[s.jsx(I,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),s.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(b==="restarting"||b==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&s.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&s.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&s.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&s.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),s.jsxs("div",{className:"space-y-2",children:[y&&D&&s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(I,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),s.jsxs("div",{className:"typography-ui-label text-foreground",children:[b==="updating"&&m("updateDialog.status.installingUpdate"),b==="restarting"&&m("updateDialog.status.serverRestarting"),b==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),s.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),E&&!D&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(Ns,{className:"max-h-[400px] p-0",fillContainer:!1,children:E.kind==="raw"?s.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:P=>{const N=P.target.closest("a");N&&N.href&&(P.preventDefault(),P.stopPropagation(),j(N.href))},children:s.jsx(Ra,{content:E.content,disableLinkSafety:!0})}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:E.sections.map(P=>s.jsxs("div",{className:"p-4",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[s.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",P.version]}),s.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:P.dateLabel})]}),s.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:C=>{const T=C.target.closest("a");T&&T.href&&(C.preventDefault(),C.stopPropagation(),j(T.href))},children:s.jsx(Ra,{content:P.content,disableLinkSafety:!0})})]},P.version))})})}),y&&b==="error"&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"terminal",className:"h-4 w-4"}),s.jsx("span",{children:m("updateDialog.fallback.updateViaTerminal")})]}),s.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[s.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:k}),s.jsx("button",{onClick:A,className:ue("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",u&&"text-[var(--status-success)]"),title:m(u?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:u?s.jsx(I,{name:"check",className:"h-4 w-4"}):s.jsx(I,{name:"clipboard",className:"h-4 w-4"})})]})]}),!y&&r&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center justify-between text-sm",children:[s.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),s.jsxs("span",{className:"font-mono text-foreground",children:[w,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${w}%`}})})]}),(o||v)&&s.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:s.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||v})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[s.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[s.jsx(I,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),s.jsxs("div",{className:"flex-1 flex justify-end",children:[!y&&!a&&!r&&s.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(I,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!y&&r&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(I,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!y&&a&&s.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[s.jsx(I,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),y&&!D&&s.jsxs("button",{onClick:S,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(I,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),y&&D&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(I,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},Fp="https://github.com/btriapitsyn/openchamber",sC=800,nC=()=>{const t=ot.c(103),{t:e}=pt(),[n,r]=l.useState(!1),[a,i]=l.useState(!1),o=Da(hr(rC)),{isMobile:c}=nn(),d=o.info?.currentVersion||"unknown",p=l.useRef(!1);let m,u;t[0]!==a||t[1]!==e||t[2]!==o.available||t[3]!==o.checking||t[4]!==o.error?(m=()=>{if(o.checking)i(!0),p.current=!0;else if(a){const V=setTimeout(()=>{i(!1),p.current&&!o.available&&!o.error&&(H.success(e("settings.openchamber.about.toast.latestVersion")),p.current=!1)},sC);return()=>clearTimeout(V)}},u=[e,o.checking,a,o.available,o.error],t[0]=a,t[1]=e,t[2]=o.available,t[3]=o.checking,t[4]=o.error,t[5]=m,t[6]=u):(m=t[5],u=t[6]),l.useEffect(m,u);const f=o.checking||a;if(c){let V;t[7]!==d?(V=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["v",d]}),t[7]=d,t[8]=V):V=t[8];let $;t[9]!==f||t[10]!==e||t[11]!==o?($=!o.available&&!o.error&&s.jsx("button",{onClick:()=>o.checkForUpdates(),disabled:f,className:ue("typography-meta text-muted-foreground/60 hover:text-muted-foreground disabled:cursor-default",f&&"animate-pulse [animation-duration:1s]"),children:e("settings.openchamber.about.actions.checkUpdates")}),t[9]=f,t[10]=e,t[11]=o,t[12]=$):$=t[12];let z;t[13]!==f||t[14]!==e||t[15]!==o.available?(z=!f&&o.available&&s.jsxs("button",{onClick:()=>r(!0),className:"flex items-center gap-1 typography-meta text-[var(--primary-base)] hover:underline",children:[s.jsx(I,{name:"download",className:"h-3.5 w-3.5"}),e("settings.openchamber.about.actions.update")]}),t[13]=f,t[14]=e,t[15]=o.available,t[16]=z):z=t[16];let Q;t[17]!==V||t[18]!==$||t[19]!==z?(Q=s.jsxs("div",{className:"flex items-center justify-between",children:[V,$,z]}),t[17]=V,t[18]=$,t[19]=z,t[20]=Q):Q=t[20];let L;t[21]!==o.error?(L=o.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:o.error}),t[21]=o.error,t[22]=L):L=t[22];let J;t[23]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsxs("a",{href:Fp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),t[23]=J):J=t[23];let ee;t[24]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"discord-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),t[24]=ee):ee=t[24];let re;t[25]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsxs("div",{className:"flex items-center gap-3",children:[J,ee,s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"twitter-xfill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[25]=re):re=t[25];let q;t[26]!==n||t[27]!==o.downloadUpdate||t[28]!==o.downloaded||t[29]!==o.downloading||t[30]!==o.error||t[31]!==o.info||t[32]!==o.progress||t[33]!==o.restartToUpdate||t[34]!==o.runtimeType?(q=s.jsx(vd,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[26]=n,t[27]=o.downloadUpdate,t[28]=o.downloaded,t[29]=o.downloading,t[30]=o.error,t[31]=o.info,t[32]=o.progress,t[33]=o.restartToUpdate,t[34]=o.runtimeType,t[35]=q):q=t[35];let ce;return t[36]!==q||t[37]!==Q||t[38]!==L?(ce=s.jsxs("div",{className:"w-full space-y-2",children:[Q,L,re,q]}),t[36]=q,t[37]=Q,t[38]=L,t[39]=ce):ce=t[39],ce}let b;t[40]!==e?(b=e("settings.openchamber.about.title"),t[40]=e,t[41]=b):b=t[41];let h;t[42]!==b?(h=s.jsx("div",{className:"mb-3 px-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:b})}),t[42]=b,t[43]=h):h=t[43];let v;t[44]!==e?(v=e("settings.openchamber.about.field.version"),t[44]=e,t[45]=v):v=t[45];let x;t[46]!==v?(x=s.jsx("span",{className:"typography-ui-label text-foreground",children:v}),t[46]=v,t[47]=x):x=t[47];let g;t[48]!==d?(g=s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d}),t[48]=d,t[49]=g):g=t[49];let w;t[50]!==x||t[51]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-col",children:[x,g]}),t[50]=x,t[51]=g,t[52]=w):w=t[52];let y;t[53]!==e||t[54]!==o.checking?(y=o.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(I,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),t[53]=e,t[54]=o.checking,t[55]=y):y=t[55];let k;t[56]!==e||t[57]!==o.available||t[58]!==o.checking||t[59]!==o.info?.version?(k=!o.checking&&o.available&&s.jsxs(xe,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(I,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:o.info?.version||""})]}),t[56]=e,t[57]=o.available,t[58]=o.checking,t[59]=o.info?.version,t[60]=k):k=t[60];let A;t[61]!==e||t[62]!==o.available||t[63]!==o.checking||t[64]!==o.error?(A=!o.checking&&!o.available&&!o.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t[61]=e,t[62]=o.available,t[63]=o.checking,t[64]=o.error,t[65]=A):A=t[65];let j;t[66]!==o?(j=()=>o.checkForUpdates(),t[66]=o,t[67]=j):j=t[67];const S=o.checking;let D;t[68]!==e?(D=e("settings.openchamber.about.actions.checkForUpdates"),t[68]=e,t[69]=D):D=t[69];let E;t[70]!==j||t[71]!==D||t[72]!==o.checking?(E=s.jsx(xe,{size:"sm",variant:"outline",onClick:j,disabled:S,children:D}),t[70]=j,t[71]=D,t[72]=o.checking,t[73]=E):E=t[73];let P;t[74]!==A||t[75]!==E||t[76]!==y||t[77]!==k?(P=s.jsxs("div",{className:"flex items-center gap-3",children:[y,k,A,E]}),t[74]=A,t[75]=E,t[76]=y,t[77]=k,t[78]=P):P=t[78];let C;t[79]!==P||t[80]!==w?(C=s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[w,P]}),t[79]=P,t[80]=w,t[81]=C):C=t[81];let N;t[82]!==o.error?(N=o.error&&s.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:o.error})}),t[82]=o.error,t[83]=N):N=t[83];let T;t[84]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsxs("a",{href:Fp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(I,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),t[84]=T):T=t[84];let M;t[85]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[T,s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(I,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[85]=M):M=t[85];let F;t[86]!==C||t[87]!==N?(F=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[C,N,M]}),t[86]=C,t[87]=N,t[88]=F):F=t[88];let _;t[89]!==n||t[90]!==o.downloadUpdate||t[91]!==o.downloaded||t[92]!==o.downloading||t[93]!==o.error||t[94]!==o.info||t[95]!==o.progress||t[96]!==o.restartToUpdate||t[97]!==o.runtimeType?(_=s.jsx(vd,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[89]=n,t[90]=o.downloadUpdate,t[91]=o.downloaded,t[92]=o.downloading,t[93]=o.error,t[94]=o.info,t[95]=o.progress,t[96]=o.restartToUpdate,t[97]=o.runtimeType,t[98]=_):_=t[98];let B;return t[99]!==F||t[100]!==_||t[101]!==h?(B=s.jsxs("div",{className:"mb-8",children:[h,F,_]}),t[99]=F,t[100]=_,t[101]=h,t[102]=B):B=t[102],B};function rC(t){return{info:t.info,checking:t.checking,available:t.available,error:t.error,downloading:t.downloading,downloaded:t.downloaded,progress:t.progress,runtimeType:t.runtimeType,checkForUpdates:t.checkForUpdates,downloadUpdate:t.downloadUpdate,restartToUpdate:t.restartToUpdate}}const aC=1,iC=365,Op=30,oC=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],jg=()=>{const t=ot.c(113),{t:e}=pt(),n=De(lC),r=De(cC),a=De(dC),i=De(uC),o=De(mC),c=De(pC);let d;t[0]===Symbol.for("react.memo_cache_sentinel")?(d={autoRun:!1},t[0]=d):d=t[0];const{candidates:p,isRunning:m,runCleanup:u,action:f}=qb(d),b=p.length;let h;t[1]!==u||t[2]!==e?(h=async()=>{const se=await u({force:!0});if(se.completedIds.length===0&&se.failedIds.length===0){H.message(se.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}se.completedIds.length>0&&H.success(se.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:se.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:se.completedIds.length})),se.failedIds.length>0&&H.error(se.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:se.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:se.failedIds.length}))},t[1]=u,t[2]=e,t[3]=h):h=t[3];const v=h;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let g;t[6]!==x?(g=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),t[6]=x,t[7]=g):g=t[7];let w;t[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=w):w=t[8];let y;t[9]!==e?(y=e("settings.openchamber.sessionRetention.tooltip"),t[9]=e,t[10]=y):y=t[10];let k;t[11]!==y?(k=s.jsxs(St,{children:[w,s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:y})]}),t[11]=y,t[12]=k):k=t[12];let A;t[13]!==g||t[14]!==k?(A=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[g,k]})}),t[13]=g,t[14]=k,t[15]=A):A=t[15];let j,S;t[16]!==n||t[17]!==i?(j=()=>i(!n),S=se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),i(!n))},t[16]=n,t[17]=i,t[18]=j,t[19]=S):(j=t[18],S=t[19]);let D;t[20]!==e?(D=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[20]=e,t[21]=D):D=t[21];let E;t[22]!==n||t[23]!==i||t[24]!==D?(E=s.jsx(ds,{checked:n,onChange:i,ariaLabel:D}),t[22]=n,t[23]=i,t[24]=D,t[25]=E):E=t[25];let P;t[26]!==e?(P=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[26]=e,t[27]=P):P=t[27];let C;t[28]!==P?(C=s.jsx("span",{className:"typography-ui-label text-foreground",children:P}),t[28]=P,t[29]=C):C=t[29];let N;t[30]!==n||t[31]!==E||t[32]!==C||t[33]!==j||t[34]!==S?(N=s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:j,onKeyDown:S,children:[E,C]}),t[30]=n,t[31]=E,t[32]=C,t[33]=j,t[34]=S,t[35]=N):N=t[35];let T;t[36]!==e?(T=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=T):T=t[37];let M;t[38]!==T?(M=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:T})}),t[38]=T,t[39]=M):M=t[39];let F;t[40]!==e?(F=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=F):F=t[41];let _;t[42]!==r||t[43]!==o||t[44]!==F?(_=s.jsx(Fn,{value:r,onValueChange:o,min:aC,max:iC,step:1,"aria-label":F,className:"w-20 tabular-nums"}),t[42]=r,t[43]=o,t[44]=F,t[45]=_):_=t[45];let B;t[46]!==e?(B=e("settings.openchamber.sessionRetention.field.days"),t[46]=e,t[47]=B):B=t[47];let V;t[48]!==B?(V=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:B}),t[48]=B,t[49]=V):V=t[49];let $;t[50]!==o?($=()=>o(Op),t[50]=o,t[51]=$):$=t[51];const z=r===Op;let Q;t[52]!==e?(Q=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=Q):Q=t[53];let L;t[54]!==e?(L=e("settings.common.actions.reset"),t[54]=e,t[55]=L):L=t[55];let J;t[56]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"}),t[56]=J):J=t[56];let ee;t[57]!==$||t[58]!==z||t[59]!==Q||t[60]!==L?(ee=s.jsx(xe,{size:"sm",type:"button",variant:"ghost",onClick:$,disabled:z,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":Q,title:L,children:J}),t[57]=$,t[58]=z,t[59]=Q,t[60]=L,t[61]=ee):ee=t[61];let re;t[62]!==_||t[63]!==V||t[64]!==ee?(re=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[_,V,ee]}),t[62]=_,t[63]=V,t[64]=ee,t[65]=re):re=t[65];let q;t[66]!==M||t[67]!==re?(q=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[M,re]}),t[66]=M,t[67]=re,t[68]=q):q=t[68];let ce;t[69]!==e?(ce=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=ce):ce=t[70];let ae;t[71]!==ce?(ae=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:ce})}),t[71]=ce,t[72]=ae):ae=t[72];let R;t[73]!==a||t[74]!==c||t[75]!==e?(R=oC.map(se=>s.jsx(xe,{type:"button",variant:"chip",size:"xs","aria-pressed":a===se.value,className:"!font-normal",onClick:()=>c(se.value),children:e(se.labelKey)},se.value)),t[73]=a,t[74]=c,t[75]=e,t[76]=R):R=t[76];let U;t[77]!==R?(U=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:R}),t[77]=R,t[78]=U):U=t[78];let W;t[79]!==ae||t[80]!==U?(W=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[ae,U]}),t[79]=ae,t[80]=U,t[81]=W):W=t[81];let Z;t[82]!==N||t[83]!==q||t[84]!==W?(Z=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[N,q,W]}),t[82]=N,t[83]=q,t[84]=W,t[85]=Z):Z=t[85];let K;t[86]!==e?(K=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=K):K=t[87];let ie;t[88]!==K?(ie=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("p",{className:"typography-meta text-foreground font-medium",children:K})}),t[88]=K,t[89]=ie):ie=t[89];let Ne;t[90]!==m||t[91]!==e?(Ne=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=Ne):Ne=t[92];let ne;t[93]!==v||t[94]!==m||t[95]!==Ne?(ne=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(xe,{type:"button",variant:"outline",size:"xs",onClick:v,disabled:m,className:"!font-normal",children:Ne})}),t[93]=v,t[94]=m,t[95]=Ne,t[96]=ne):ne=t[96];let fe;t[97]!==ie||t[98]!==ne?(fe=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ie,ne]}),t[97]=ie,t[98]=ne,t[99]=fe):fe=t[99];let pe;t[100]!==f||t[101]!==b||t[102]!==e?(pe=f==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:b}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:b}),t[100]=f,t[101]=b,t[102]=e,t[103]=pe):pe=t[103];let je;t[104]!==pe?(je=s.jsx("p",{className:"typography-meta text-muted-foreground",children:pe}),t[104]=pe,t[105]=je):je=t[105];let oe;t[106]!==fe||t[107]!==je?(oe=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[fe,je]}),t[106]=fe,t[107]=je,t[108]=oe):oe=t[108];let Se;return t[109]!==Z||t[110]!==oe||t[111]!==A?(Se=s.jsxs("div",{className:"mb-8",children:[A,Z,oe]}),t[109]=Z,t[110]=oe,t[111]=A,t[112]=Se):Se=t[112],Se};function lC(t){return t.autoDeleteEnabled}function cC(t){return t.autoDeleteAfterDays}function dC(t){return t.sessionRetentionAction}function uC(t){return t.setAutoDeleteEnabled}function mC(t){return t.setAutoDeleteAfterDays}function pC(t){return t.setSessionRetentionAction}const Lp=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),Ng=()=>{const{t}=pt(),[e,n]=l.useState(!1),[r,a]=l.useState(!0),[i,o]=l.useState(!1),[c,d]=l.useState(null),[p,m]=l.useState(!1),[u,f]=l.useState([]),[b,h]=l.useState(Yb),[v,x]=l.useState(""),g=l.useMemo(()=>Jb(),[]),w=l.useCallback(async()=>{a(!0),x("");try{const j=await Qb();f(j)}catch(j){const S=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.loadFailed");x(S)}finally{a(!1)}},[t]);l.useEffect(()=>{let j=!1;return(async()=>{try{if(!g.supported){j||(n(!1),a(!1));return}j||n(!0)}catch{j||n(!1)}if(!j){const S=await tc();if(h(S),!S.enabled){f([]),a(!1);return}await w()}})(),()=>{j=!0,Du()}},[w,g.supported]);const y=l.useCallback(async()=>{if(!b.enabled){const j=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");x(j),H.message(j);return}if(!e){x(g.reason),H.message(g.reason);return}if(i){Du(),o(!1);return}x(""),o(!0);try{await Xb(),h(await tc()),await w(),H.success(t("settings.openchamber.passkeys.toast.added"))}catch(j){if(Zb(j)){H.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const S=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.addFailed");x(S),H.error(S)}finally{o(!1)}},[i,w,b.enabled,g.reason,e,t]),k=l.useCallback(async j=>{d(j),x("");try{await ey(j),h(await tc()),await w(),H.success(t("settings.openchamber.passkeys.toast.removed"))}catch(S){const D=S instanceof Error?S.message:t("settings.openchamber.passkeys.toast.removeFailed");x(D),H.error(D)}finally{d(null)}},[w,t]),A=l.useCallback(async()=>{m(!0),x("");try{await ty(),window.location.reload()}catch(j){const S=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");x(S),H.error(S),m(!1)}},[t]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.passkeys.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.passkeys.field.currentDevice")})}),s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[s.jsx(xe,{type:"button",variant:i?"secondary":"outline",size:"xs",onClick:()=>{y()},disabled:r||p,className:"!font-normal",children:t(i?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(xe,{type:"button",variant:"ghost",size:"xs",onClick:()=>{A()},disabled:r||i||p,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(p?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]})]}),!b.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),b.enabled&&!e&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):u.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:u.map(j=>s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j.label})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:j.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Lp(j.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:Lp(j.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(xe,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k(j.id)},disabled:c===j.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===j.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]})]},j.id))})]}),v&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v})})]})},fC=t=>{const e=hi(t);return e||{providerId:"",modelId:""}},Sg=()=>{const{t}=pt(),e=vt(M=>M.setProvider),n=vt(M=>M.setModel),r=vt(M=>M.setAgent),a=vt(M=>M.setCurrentVariant),i=vt(M=>M.setSettingsDefaultModel),o=vt(M=>M.setSettingsDefaultVariant),c=vt(M=>M.setSettingsDefaultAgent),d=vt(M=>M.setSettingsDefaultFileViewerPreview),p=vt(M=>M.settingsDefaultFileViewerPreview),m=De(M=>M.showDeletionDialog),u=De(M=>M.setShowDeletionDialog),f=vt(M=>M.providers),[b,h]=l.useState(),[v,x]=l.useState(),[g,w]=l.useState(),[y,k]=l.useState(!0),A=l.useMemo(()=>fC(b),[b]);l.useEffect(()=>{(async()=>{try{let F=null;if(!F){const _=sr()?.settings;if(_)try{const V=(await _.load())?.settings;V&&(F={defaultModel:typeof V.defaultModel=="string"?V.defaultModel:void 0,defaultVariant:typeof V.defaultVariant=="string"?V.defaultVariant:void 0,defaultAgent:typeof V.defaultAgent=="string"?V.defaultAgent:void 0})}catch{}}if(!F){const _=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});_.ok&&(F=await _.json())}if(F){const _=typeof F.defaultModel=="string"&&F.defaultModel.trim().length>0?F.defaultModel.trim():void 0,B=typeof F.defaultVariant=="string"&&F.defaultVariant.trim().length>0?F.defaultVariant.trim():void 0,V=typeof F.defaultAgent=="string"&&F.defaultAgent.trim().length>0?F.defaultAgent.trim():void 0;_!==void 0&&h(_),B!==void 0&&x(B),V!==void 0&&w(V)}}catch(F){console.warn("Failed to load defaults settings:",F)}finally{k(!1)}})()},[]);const j=l.useCallback(async(M,F)=>{const _=M&&F?`${M}/${F}`:void 0;h(_),x(void 0),o(void 0),a(void 0),i(_),M&&F&&f.find(V=>V.id===M)&&(e(M),n(F));try{await Is({defaultModel:_??"",defaultVariant:""});const B=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:_})});B.ok||console.warn("Failed to save default model to server:",B.status,B.statusText)}catch(B){console.warn("Failed to save default model:",B)}},[f,a,n,e,i,o]),S="__default__",D=l.useCallback(M=>M===S?t("settings.openchamber.defaults.option.default"):M.charAt(0).toUpperCase()+M.slice(1),[t]),E=l.useCallback(async M=>{const F=M===S?void 0:M||void 0;x(F),o(F),a(F);try{await Is({defaultVariant:F??""})}catch(_){console.warn("Failed to save default variant:",_)}},[a,o]),P=l.useCallback(async M=>{const F=M||void 0;w(F),c(F),M&&r(M);try{await Is({defaultAgent:F??""})}catch(_){console.warn("Failed to save default agent:",_)}},[r,c]),C=l.useCallback(()=>{const M=!p;d(M),Is({defaultFileViewerPreview:M}).catch(console.warn)},[p,d]),N=l.useMemo(()=>{if(!A.providerId||!A.modelId)return[];const _=f.find(B=>B.id===A.providerId)?.models.find(B=>B.id===A.modelId)?.variants;return _?Object.keys(_):[]},[A.modelId,A.providerId,f]),T=N.length>0;return l.useEffect(()=>{!T&&v&&(x(void 0),o(void 0),a(void 0),Is({defaultVariant:""}).catch(()=>{}))},[v,a,o,T]),y?null:s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-0.5 px-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.defaults.title")})})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",A.providerId?s.jsxs("span",{className:"text-foreground",children:[A.providerId,"/",A.modelId,T?` (${v??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),g&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:g})]})]}),s.jsxs("div",{className:ue("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(mo,{providerId:A.providerId,modelId:A.modelId,onChange:j})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultThinking")})}),s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsxs(is,{value:v??S,onValueChange:E,disabled:!T,children:[s.jsx(os,{className:"w-fit min-w-[120px]",children:s.jsx(us,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:D(v??S)})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:S,children:t("settings.openchamber.defaults.option.default")}),N.map(M=>s.jsx(Ft,{value:M,children:D(M)},M))]})]})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Ol,{agentName:g||"",onChange:P})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),u(!m))},children:[s.jsx(ds,{checked:m,onChange:u,ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.showDeletionDialog")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":p,onClick:C,onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),C())},children:[s.jsx(ds,{checked:p,onChange:d,ariaLabel:t("settings.openchamber.defaults.field.openFilesPreviewAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.openFilesPreview")})]})]})]})},$p={completion:{titleKey:"settings.notifications.page.template.defaults.completion.title",messageKey:"settings.notifications.page.template.defaults.completion.message"},error:{titleKey:"settings.notifications.page.template.defaults.error.title",messageKey:"settings.notifications.page.template.defaults.error.message"},question:{titleKey:"settings.notifications.page.template.defaults.question.title",messageKey:"settings.notifications.page.template.defaults.question.message"},subtask:{titleKey:"settings.notifications.page.template.defaults.subtask.title",messageKey:"settings.notifications.page.template.defaults.subtask.message"}},hC={completion:"settings.notifications.page.template.event.completion",subtask:"settings.notifications.page.template.event.subtask",error:"settings.notifications.page.template.event.error",question:"settings.notifications.page.template.event.question"},gC=()=>{const{t}=pt(),e=l.useMemo(()=>dn(),[]),n=l.useMemo(()=>ln(),[]),r=!e&&!n,a=De(L=>L.nativeNotificationsEnabled),i=De(L=>L.setNativeNotificationsEnabled),o=De(L=>L.notificationMode),c=De(L=>L.setNotificationMode),d=De(L=>L.notifyOnSubtasks),p=De(L=>L.setNotifyOnSubtasks),m=De(L=>L.notifyOnCompletion),u=De(L=>L.setNotifyOnCompletion),f=De(L=>L.notifyOnError),b=De(L=>L.setNotifyOnError),h=De(L=>L.notifyOnQuestion),v=De(L=>L.setNotifyOnQuestion),x=De(L=>L.notificationTemplates),g=De(L=>L.setNotificationTemplates),[w,y]=l.useState("default"),[k,A]=l.useState(!1),[j,S]=l.useState(!1),[D,E]=l.useState(!1);l.useEffect(()=>{if(!r){A(!1),S(!1);return}typeof Notification<"u"&&y(Notification.permission);const L=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;A(L),(async()=>{if(!L){S(!1);return}try{const ee=await navigator.serviceWorker.getRegistration();if(!ee){S(!1);return}const re=await ee.pushManager.getSubscription();S(!!re)}catch{S(!1)}})()},[r]);const P=async L=>{if(e){i(L);return}if(!r){i(L);return}if(L&&typeof Notification<"u"&&Notification.permission==="default")try{const J=await Notification.requestPermission();y(J),J==="granted"?i(!0):H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(J){console.error("Failed to request notification permission:",J),H.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else i(!!(L&&w==="granted"))},C=e||n||r&&typeof Notification<"u"&&Notification.permission==="granted",N=(L,J,ee)=>{g({...x,[L]:{...x[L],[J]:ee}})},T=L=>{const J="=".repeat((4-L.length%4)%4),ee=(L+J).replace(/-/g,"+").replace(/_/g,"/"),re=atob(ee),q=new Uint8Array(re.length);for(let ce=0;ce<re.length;ce+=1)q[ce]=re.charCodeAt(ce);return q},M=async(L,J,ee)=>{let re=null;const q=new Promise((ce,ae)=>{re=setTimeout(()=>{ae(new Error(ee))},J)});try{return await Promise.race([L,q])}finally{re&&clearTimeout(re)}},F=async L=>{if(L.active)return;const J=L.installing||L.waiting;J&&J.state!=="activated"&&await M(new Promise(ee=>{const re=()=>{J.state==="activated"&&(J.removeEventListener("statechange",re),ee())};J.addEventListener("statechange",re),re()}),15e3,"Service worker activation timed out")},_=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const L=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let J=null;for(const ee of L)try{const re=ee.opts?navigator.serviceWorker.register("/sw.js",ee.opts):navigator.serviceWorker.register("/sw.js");return await M(re,1e4,`Service worker registration timed out (${ee.label})`)}catch(re){J=re}throw J instanceof Error?J:new Error("Service worker registration failed")},B=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const L=await navigator.serviceWorker.getRegistration();if(L)return L;const J=await _();try{await J.update()}catch{}return await F(J),J},V=L=>{const J=L,ee=[`type=${typeof L}`,`toString=${String(L)}`,`name=${String(J?.name??"")}`,`message=${String(J?.message??"")}`];let re="";try{re=JSON.stringify(L)}catch{}return{summary:ee.filter(Boolean).join(" | "),json:re,stack:typeof J?.stack=="string"?J.stack:""}},$=async()=>{const L=sr();if(!L?.notifications){H.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await L.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?H.success(t("settings.notifications.page.toast.testNotificationSent")):H.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(J){console.error("Test notification failed:",J),H.error(t("settings.notifications.page.toast.testNotificationFailed"))}},z=async()=>{if(!k){H.error(t("settings.notifications.page.toast.pushUnsupported"));return}const L=sr();if(!L?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}E(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const U=await Notification.requestPermission();if(y(U),U!=="granted"){H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const J=await L.push.getVapidPublicKey();if(!J?.publicKey){H.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const ee=await B();await F(ee);const re=await ee.pushManager.getSubscription();if(!("pushManager"in ee)||!ee.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const ce=(re??await M(ee.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:T(J.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ae=ce.keys;if(!ce.endpoint||!ae?.p256dh||!ae.auth)throw new Error("Push subscription missing keys");if(!(await M(L.push.subscribe({endpoint:ce.endpoint,keys:{p256dh:ae.p256dh,auth:ae.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){H.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}S(!0),H.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(J){console.error("[Push] Enable failed:",J);const ee=V(J);H.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:ee.summary})}finally{E(!1)}},Q=async()=>{if(!k){S(!1);return}const L=sr();if(!L?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}E(!0);try{const ee=await(await B()).pushManager.getSubscription();if(!ee){S(!1);return}const re=ee.endpoint;await ee.unsubscribe(),await L.push.unsubscribe({endpoint:re}),S(!1),H.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{E(!1)}};return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.delivery.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":a&&C,onClick:()=>{P(!(a&&C))},onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),P(!(a&&C)))},children:[s.jsx(ds,{checked:a&&C,onChange:L=>{P(L)},ariaLabel:t("settings.notifications.page.delivery.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.enableLabel")})]}),a&&C&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":o==="always",onClick:()=>c(o==="always"?"hidden-only":"always"),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),c(o==="always"?"hidden-only":"always"))},children:[s.jsx(ds,{checked:o==="always",onChange:L=>c(L?"always":"hidden-only"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.focusedLabel")})]}),s.jsx("div",{className:"py-2",children:s.jsx(xe,{type:"button",variant:"outline",size:"sm",onClick:()=>{$()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&s.jsxs("div",{className:"mt-1 px-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.browserPermissionHint")}),w==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),w==="granted"&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),n&&s.jsx("div",{className:"mt-1 px-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.vscodeHint")})})]}),a&&C&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.events.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),u(!m))},children:[s.jsx(ds,{checked:m,onChange:u,ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.completionLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":d,onClick:()=>p(!d),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),p(!d))},children:[s.jsx(ds,{checked:d,onChange:p,ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.subtaskLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>b(!f),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),b(!f))},children:[s.jsx(ds,{checked:f,onChange:b,ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.errorLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":h,onClick:()=>v(!h),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),v(!h))},children:[s.jsx(ds,{checked:h,onChange:v,ariaLabel:t("settings.notifications.page.events.questionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.questionLabel")})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.template.title")}),s.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),s.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(L=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(hC[L])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(Vt,{value:x[L].title,onChange:J=>N(L,"title",J.target.value),className:"h-7",placeholder:t($p[L].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(Vt,{value:x[L].message,onChange:J=>N(L,"message",J.target.value),className:"h-7",placeholder:t($p[L].messageKey)})]})]})]},L))})]})]}),r&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.push.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(ds,{checked:k?j:!1,disabled:!k||D,onChange:L=>{L?z():Q()},ariaLabel:t("settings.notifications.page.push.enableAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:ue("typography-ui-label",k?"text-foreground":"text-muted-foreground"),children:t("settings.notifications.page.push.enableLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t(k?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),D&&s.jsx("div",{className:"pt-0.5 text-muted-foreground",children:s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")})})]})})]})]})},xC=[{value:"en-US",label:"English"},{value:"es-ES",label:"Español"},{value:"fr-FR",label:"Français"},{value:"de-DE",label:"Deutsch"},{value:"ja-JP",label:"日本語"},{value:"zh-CN",label:"中文"},{value:"pt-BR",label:"Português"},{value:"it-IT",label:"Italiano"},{value:"ko-KR",label:"한국어"},{value:"uk-UA",label:"Українська"}],bC=t=>{const e=ot.c(45),{modelId:n}=t,{t:r}=pt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=Oi.getModelStatus(),e[0]=a):a=e[0];const[i,o]=$e.useState(a),[c,d]=$e.useState(!1);let p,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{const j=S=>o(S);return Oi.onModelStatusChange=j,wC},m=[],e[1]=p,e[2]=m):(p=e[1],m=e[2]),$e.useEffect(p,m);const u=Oi.getCurrentModelId(),f=i.state==="downloading"||i.state==="loading";let b,h;e[3]!==i.state?(b=()=>{i.state!=="downloading"&&i.state!=="loading"&&d(!1)},h=[i.state],e[3]=i.state,e[4]=b,e[5]=h):(b=e[4],h=e[5]),$e.useEffect(b,h);let v;e[6]!==n?(v=async()=>{d(!0);try{await Oi.loadModel(n)}catch{}},e[6]=n,e[7]=v):v=e[7];const x=v;if(i.state==="ready"&&u===n){let j;e[8]!==r?(j=r("settings.voice.page.stt.wasmLoaded"),e[8]=r,e[9]=j):j=e[9];let S;return e[10]!==j?(S=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-compact text-green-600 dark:text-green-400",children:j})}),e[10]=j,e[11]=S):S=e[11],S}if(f){let j;e[12]!==i.progress||e[13]!==i.state?(j=i.state==="downloading"?Math.round(i.progress):void 0,e[12]=i.progress,e[13]=i.state,e[14]=j):j=e[14];const S=j;let D;e[15]!==i.state||e[16]!==r?(D=i.state==="downloading"?r("settings.voice.page.stt.wasmDownloading"):r("settings.voice.page.stt.wasmLoading"),e[15]=i.state,e[16]=r,e[17]=D):D=e[17];const E=S!==void 0?` (${S}%)`:"";let P;return e[18]!==D||e[19]!==E?(P=s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[D,E]})}),e[18]=D,e[19]=E,e[20]=P):P=e[20],P}if(i.state==="error"){let j;e[21]!==i.error?(j=s.jsx("span",{className:"typography-ui-compact text-destructive",children:i.error}),e[21]=i.error,e[22]=j):j=e[22];let S;e[23]!==r?(S=r("settings.voice.page.stt.wasmRetry"),e[23]=r,e[24]=S):S=e[24];let D;e[25]!==x||e[26]!==c||e[27]!==S?(D=s.jsx(xe,{variant:"chip",size:"xs",disabled:c,onClick:x,children:S}),e[25]=x,e[26]=c,e[27]=S,e[28]=D):D=e[28];let E;return e[29]!==j||e[30]!==D?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[j,D]}),e[29]=j,e[30]=D,e[31]=E):E=e[31],E}let g;e[32]!==r?(g=r("settings.voice.page.stt.wasmNotLoaded"),e[32]=r,e[33]=g):g=e[33];let w;e[34]!==g?(w=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:g}),e[34]=g,e[35]=w):w=e[35];let y;e[36]!==r?(y=r("settings.voice.page.stt.wasmDownload"),e[36]=r,e[37]=y):y=e[37];let k;e[38]!==x||e[39]!==c||e[40]!==y?(k=s.jsx(xe,{variant:"chip",size:"xs",disabled:c,onClick:x,children:y}),e[38]=x,e[39]=c,e[40]=y,e[41]=k):k=e[41];let A;return e[42]!==k||e[43]!==w?(A=s.jsxs("div",{className:"flex items-center gap-2",children:[w,k]}),e[42]=k,e[43]=w,e[44]=A):A=e[44],A},yC=[{value:"alloy",label:"Alloy"},{value:"ash",label:"Ash"},{value:"ballad",label:"Ballad"},{value:"coral",label:"Coral"},{value:"echo",label:"Echo"},{value:"fable",label:"Fable"},{value:"nova",label:"Nova"},{value:"onyx",label:"Onyx"},{value:"sage",label:"Sage"},{value:"shimmer",label:"Shimmer"},{value:"verse",label:"Verse"},{value:"marin",label:"Marin"},{value:"cedar",label:"Cedar"}],vC=()=>{const{t}=pt(),{isMobile:e}=nn(),{isSupported:n,language:r,setLanguage:a}=sy(),i=vt(G=>G.voiceProvider),o=vt(G=>G.setVoiceProvider),c=vt(G=>G.speechRate),d=vt(G=>G.setSpeechRate),p=vt(G=>G.speechPitch),m=vt(G=>G.setSpeechPitch),u=vt(G=>G.speechVolume),f=vt(G=>G.setSpeechVolume),b=vt(G=>G.sayVoice),h=vt(G=>G.setSayVoice),v=vt(G=>G.browserVoice),x=vt(G=>G.setBrowserVoice),g=vt(G=>G.openaiVoice),w=vt(G=>G.setOpenaiVoice),y=vt(G=>G.openaiApiKey),k=vt(G=>G.setOpenaiApiKey),A=vt(G=>G.openaiCompatibleUrl),j=vt(G=>G.setOpenaiCompatibleUrl),S=vt(G=>G.openaiCompatibleVoice),D=vt(G=>G.setOpenaiCompatibleVoice),E=vt(G=>G.openaiCompatibleTtsModel),P=vt(G=>G.setOpenaiCompatibleTtsModel),C=vt(G=>G.showMessageTTSButtons),N=vt(G=>G.sttProvider),T=vt(G=>G.setSttProvider),M=vt(G=>G.sttServerUrl),F=vt(G=>G.setSttServerUrl),_=vt(G=>G.sttModel),B=vt(G=>G.setSttModel),V=vt(G=>G.wasmSttModel),$=vt(G=>G.setWasmSttModel),z=vt(G=>G.sttLanguage),Q=vt(G=>G.setSttLanguage),L=vt(G=>G.sttSilenceThresholdDb),J=vt(G=>G.setSttSilenceThresholdDb),ee=vt(G=>G.sttSilenceHoldMs),re=vt(G=>G.setSttSilenceHoldMs),q=vt(G=>G.sttTranscribeOnStop),ce=vt(G=>G.setSttTranscribeOnStop),ae=vt(G=>G.setShowMessageTTSButtons),R=vt(G=>G.voiceModeEnabled),U=vt(G=>G.setVoiceModeEnabled),[W,Z]=$e.useState(!1),[K,ie]=$e.useState([]),[Ne,ne]=$e.useState(!1),[fe,pe]=$e.useState(null),[je,oe]=$e.useState(!1),[Se,se]=$e.useState(!1),[we,Ae]=$e.useState(null),[ve,ye]=$e.useState(!1),[Ie,he]=$e.useState(null),[me,Ee]=$e.useState([]),[Ve,Y]=$e.useState(!1);$e.useEffect(()=>((async()=>{const Te=await sc.waitForVoices();Ee(Te)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ee(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const ke=$e.useMemo(()=>me.filter(G=>G.lang).sort((G,Te)=>{const le=G.lang.startsWith("en"),We=Te.lang.startsWith("en");if(le&&!We)return-1;if(!le&&We)return 1;const de=G.lang.localeCompare(Te.lang);return de!==0?de:G.name.localeCompare(Te.name)}),[me]),Be=$e.useCallback(()=>{if(Ve){sc.cancelSpeech(),Y(!1);return}const G=me.find(de=>de.name===v),Te=G?.name??t("settings.voice.page.preview.browserVoiceFallback"),le=t("settings.voice.page.preview.voiceLine",{voiceName:Te});Y(!0);const We=new SpeechSynthesisUtterance(le);We.rate=c,We.pitch=p,We.volume=u,G&&(We.voice=G,We.lang=G.lang),We.onend=()=>Y(!1),We.onerror=()=>Y(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(We)},[v,me,c,p,u,Ve,t]);$e.useEffect(()=>()=>{Ve&&sc.cancelSpeech()},[Ve]),$e.useEffect(()=>{if(!R||i!=="openai"&&i!=="openai-compatible"){oe(y.trim().length>0);return}(async()=>{try{const We=(await(await fetch("/api/tts/status")).json()).available,de=y.trim().length>0;oe(We||de)}catch{oe(y.trim().length>0)}})()},[y,R,i]),$e.useEffect(()=>{if(!R){Z(!1),ie([]);return}fetch("/api/tts/say/status").then(G=>G.json()).then(G=>{if(Z(G.available),G.voices){const Te=G.voices.filter((le,We,de)=>de.findIndex(Fe=>Fe.name===le.name)===We).sort((le,We)=>le.name.localeCompare(We.name));ie(Te)}}).catch(()=>{Z(!1)})},[R]);const Ce=$e.useCallback(async()=>{if(fe){fe.pause(),fe.currentTime=0,pe(null),ne(!1);return}ne(!0);try{const G=await fetch("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:b}),voice:b,rate:Math.round(100+(c-.5)*200)})});if(!G.ok)throw new Error("Preview failed");const Te=await G.blob(),le=URL.createObjectURL(Te),We=new Audio(le);We.onended=()=>{URL.revokeObjectURL(le),pe(null),ne(!1)},We.onerror=()=>{URL.revokeObjectURL(le),pe(null),ne(!1)},pe(We),await We.play()}catch{ne(!1)}},[b,c,fe,t]);$e.useEffect(()=>()=>{fe&&fe.pause()},[fe]);const ge=$e.useCallback(async()=>{if(we){we.pause(),we.currentTime=0,Ae(null),se(!1);return}se(!0);try{const G=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:g}),voice:g,speed:c,apiKey:y||void 0})});if(!G.ok){const de=await G.json().catch(()=>({error:"Unknown error"}));throw new Error(de.error||`HTTP ${G.status}`)}const Te=await G.blob(),le=URL.createObjectURL(Te),We=new Audio(le);We.onended=()=>{URL.revokeObjectURL(le),Ae(null),se(!1)},We.onerror=()=>{URL.revokeObjectURL(le),Ae(null),se(!1)},Ae(We),await We.play()}catch{se(!1)}},[g,c,we,y,t]);$e.useEffect(()=>()=>{we&&we.pause()},[we]);const O=$e.useCallback(async()=>{if(Ie){Ie.pause(),Ie.currentTime=0,he(null),ye(!1);return}if(A.trim()){ye(!0);try{const G=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:S,model:E||void 0,speed:c,baseURL:A})});if(!G.ok){const de=await G.json().catch(()=>({error:"Unknown error"}));throw new Error(de.error||`HTTP ${G.status}`)}const Te=await G.blob(),le=URL.createObjectURL(Te),We=new Audio(le);We.onended=()=>{URL.revokeObjectURL(le),he(null),ye(!1)},We.onerror=()=>{URL.revokeObjectURL(le),he(null),ye(!1)},he(We),await We.play()}catch{ye(!1)}}},[A,S,E,c,Ie,t]);$e.useEffect(()=>()=>{Ie&&Ie.pause()},[Ie]);const X="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.voiceSetup")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":R,onClick:()=>U(!R),onKeyDown:G=>{(G.key===" "||G.key==="Enter")&&(G.preventDefault(),U(!R))},children:[s.jsx(ds,{checked:R,onChange:U,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),R&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:"OpenAI:"})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>o("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>o("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>o("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),W&&s.jsxs(xe,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>o("say"),className:"!font-normal",children:[s.jsx(I,{name:"apple",className:"w-3.5 h-3.5 mr-0.5"}),t("settings.voice.page.provider.say")]})]})]})}),i==="openai"&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:ue("typography-ui-label text-foreground",!je&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ue("typography-meta ml-2",je?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(je&&!y?"settings.voice.page.field.apiKeyHintUsingConfig":je?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:y,onChange:G=>k(G.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),y&&s.jsx("button",{type:"button",onClick:()=>k(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"w-3.5 h-3.5"})})]})]}),i==="openai-compatible"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:ue("typography-ui-label text-foreground",!A.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.serverUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:A,onChange:G=>j(G.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),A&&s.jsx("button",{type:"button",onClick:()=>j(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:E,onChange:G=>P(G.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.voice")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.voiceIdentifierHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx("div",{className:"relative max-w-xs flex-1",children:s.jsx("input",{type:"text",value:S,onChange:G=>D(G.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(xe,{size:"xs",variant:"ghost",onClick:O,title:t("settings.voice.page.actions.preview"),disabled:!A.trim(),children:ve?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.voice")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[i==="openai"&&je&&s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:g,onValueChange:w,children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(ls,{children:yC.map(G=>s.jsx(Ft,{value:G.value,children:G.label},G.value))})]}),s.jsx(xe,{size:"xs",variant:"ghost",onClick:ge,title:t("settings.voice.page.actions.preview"),children:Se?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="openai-compatible"&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.configuredAbove")}),i==="say"&&W&&K.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:b,onValueChange:h,children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(ls,{children:K.map(G=>s.jsx(Ft,{value:G.name,children:G.name},G.name))})]}),s.jsx(xe,{size:"xs",variant:"ghost",onClick:Ce,title:t("settings.voice.page.actions.preview"),children:Ne?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="browser"&&ke.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:v||"$auto",onValueChange:G=>x(G==="$auto"?"":G),children:[s.jsx(os,{className:"w-fit max-w-[200px]",children:s.jsx(us,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"$auto",children:t("settings.voice.page.field.auto")}),ke.map(G=>s.jsxs(Ft,{value:G.name,children:[G.name," (",G.lang,")"]},G.name))]})]}),s.jsx(xe,{size:"xs",variant:"ghost",onClick:Be,title:t("settings.voice.page.actions.preview"),children:Ve?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechRate")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:c,onChange:G=>d(Number(G.target.value)),disabled:!n,className:X}),s.jsx(Fn,{value:c,onValueChange:d,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechPitch")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:p,onChange:G=>m(Number(G.target.value)),disabled:!n,className:X}),s.jsx(Fn,{value:p,onValueChange:m,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechVolume")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:u,onChange:G=>f(Number(G.target.value)),disabled:!n,className:X}),e?s.jsx(Fn,{value:Math.round(u*100),onValueChange:G=>f(G/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(u*100),"%"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.language")}),s.jsx("div",{className:"flex items-center gap-2 w-fit",children:s.jsxs(is,{value:r,onValueChange:a,disabled:!n,children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(ls,{children:xC.map(G=>s.jsx(Ft,{value:G.value,children:G.label},G.value))})]})})]})]})]})]}),R&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.speechRecognition")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.sttBrowser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":N==="browser",onClick:()=>T("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":N==="server",onClick:()=>T("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")}),s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":N==="wasm",onClick:()=>T("wasm"),className:"!font-normal",children:t("settings.voice.page.provider.wasm")})]})]})}),N==="server"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":q,onClick:()=>ce(!q),onKeyDown:G=>{(G.key===" "||G.key==="Enter")&&(G.preventDefault(),ce(!q))},children:[s.jsx(ds,{checked:q,onChange:ce,ariaLabel:t("settings.voice.page.field.transcribeOnStopAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.transcribeOnStop")})]}),!ny.isSupported()&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:t("settings.voice.page.field.sttBrowserSupportError")}),s.jsxs("div",{children:[s.jsx("span",{className:ue("typography-ui-label text-foreground",!M.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttServerUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:M,onChange:G=>F(G.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),M&&s.jsx("button",{type:"button",onClick:()=>F(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:_,onChange:G=>B(G.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.language")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttLanguageHint")}),s.jsx("div",{className:"relative mt-1.5 max-w-[8rem]",children:s.jsx("input",{type:"text",value:z,onChange:G=>Q(G.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceThreshold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:-60,max:-20,step:1,value:L,onChange:G=>J(Number(G.target.value)),className:X}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[L," dB"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceHold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:500,max:3e3,step:100,value:ee,onChange:G=>re(Number(G.target.value)),className:X}),s.jsx(Fn,{value:ee,onValueChange:re,min:500,max:3e3,step:100,className:"w-20 tabular-nums"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.millisecondsUnit")})]})]})]}),N==="wasm"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:t("settings.voice.page.stt.wasmModel")}),s.jsxs(is,{value:V,onValueChange:$,children:[s.jsx(os,{className:"mt-0.5",children:s.jsx(us,{placeholder:t("settings.voice.page.stt.wasmModel")})}),s.jsx(ls,{children:Tu.map(G=>s.jsx(Ft,{value:G.id,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{children:G.name}),s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[G.size," · ",G.languages]})]})},G.id))})]}),s.jsx("p",{className:"typography-ui-compact text-muted-foreground mt-0.5",children:Tu.find(G=>G.id===V)?.description})]}),s.jsx(bC,{modelId:V})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.playbackAndSummary")})}),s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":C,onClick:()=>ae(!C),onKeyDown:G=>{(G.key===" "||G.key==="Enter")&&(G.preventDefault(),ae(!C))},children:[s.jsx(ds,{checked:C,onChange:ae,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]})}),R&&n&&s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t("settings.voice.page.hint.shiftClickPrefix")," ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Shift"})," + ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Click"})," ",t("settings.voice.page.hint.shiftClickSuffix")]})})]})]})};function wC(){Oi.onModelStatusChange=null}const Mc=[{value:"1800000",label:"30m",ms:1800*1e3},{value:"180000",label:"3m",ms:180*1e3},{value:"7200000",label:"2h",ms:7200*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3}],Ec=[{value:"3600000",label:"1h",ms:3600*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"43200000",label:"12h",ms:720*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3},{value:"604800000",label:"1w",ms:10080*60*1e3},{value:"2592000000",label:"30d",ms:720*60*60*1e3}],jC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",NC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Bp=[{value:"quick",labelKey:"settings.openchamber.tunnel.option.mode.quick.label",tooltipKey:"settings.openchamber.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.openchamber.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.openchamber.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedLocal.tooltip"}],SC=[".yml",".yaml",".json"],kC="settings.openchamber.tunnel.error.invalidConfigExtension",Ei=t=>{const e=t.trim().toLowerCase();return SC.some(n=>e.endsWith(n))},kg=t=>t==="cloudflare"?"Cloudflare":t,_p=t=>{const e=ot.c(11),{provider:n}=t;let r;e[0]!==n?(r=kg(n),e[0]=n,e[1]=r):r=e[1];const a=r,o=n==="cloudflare"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==o?(c=ue("size-4 shrink-0",o),e[2]=o,e[3]=c):c=e[3];let d;e[4]!==c?(d=s.jsx(I,{name:"cloud",className:c}),e[4]=c,e[5]=d):d=e[5];let p;e[6]!==a?(p=s.jsx("span",{children:a}),e[6]=a,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs("span",{className:"flex items-center gap-2",children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},ba=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",zp=(t,e,n)=>t.find(a=>a.ms===e)?.value||n,Vp=t=>{const e=Math.max(0,t),n=Math.floor(e/1e3),r=Math.floor(n/3600),a=Math.floor(n%3600/60),i=n%60;return r>0?`${r}h ${a}m`:a>0?`${a}m ${i}s`:`${i}s`},CC=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Xo=t=>{const e=t.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},IC=t=>{if(!Array.isArray(t))return[];const e=new Set,n=new Set,r=[];for(const a of t){if(!a||typeof a!="object")continue;const i=a,o=typeof i.id=="string"?i.id.trim():"",c=typeof i.name=="string"?i.name.trim():"",d=Xo(typeof i.hostname=="string"?i.hostname:"");!o||!c||!d||e.has(o)||n.has(d)||(e.add(o),n.add(d),r.push({id:o,name:c,hostname:d}))}return r},PC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,AC=()=>{const{t}=pt(),e=l.useCallback(be=>t(be),[t]),[n,r]=l.useState("checking"),[a,i]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(null),[h,v]=l.useState(!1),[x,g]=l.useState(!1),[w,y]=l.useState(!1),[k,A]=l.useState("cloudflare"),[j,S]=l.useState([]),[D,E]=l.useState("quick"),[P,C]=l.useState(null),[N,T]=l.useState([]),[M,F]=l.useState({}),[_,B]=l.useState(""),[V,$]=l.useState({}),[z,Q]=l.useState(new Set),[L,J]=l.useState(!1),[ee,re]=l.useState(""),[q,ce]=l.useState(""),[ae,R]=l.useState(""),[U,W]=l.useState(1800*1e3),[Z,K]=l.useState(480*60*1e3),[ie,Ne]=l.useState(""),[ne,fe]=l.useState([]),[pe,je]=l.useState(()=>Date.now()),[oe,Se]=l.useState(null),se=t(kC),we=l.useRef(null),Ae=l.useMemo(()=>P?!Ei(P):!1,[P]),ve=l.useMemo(()=>N.find(be=>be.id===_)||N[0]||null,[N,_]),ye=l.useMemo(()=>ne.map(be=>{const He=be.expiresAt<=pe,_e=be.status==="active"&&!He,tt=_e?Vp(be.expiresAt-pe):be.inactiveReason==="expired"||He?"expired":"inactive",ut=tt==="expired"?t("settings.openchamber.tunnel.state.expired"):be.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),qe=ba(be.mode);return{...be,isActive:_e,mode:qe,remainingTextForSession:tt,inactiveLabel:ut}}),[pe,ne,t]),Ie=l.useMemo(()=>a?.connectUrl?a.bootstrapExpiresAt===null?!0:a.bootstrapExpiresAt>pe:!1,[pe,a?.bootstrapExpiresAt,a?.connectUrl]),he=l.useMemo(()=>!a||n!=="active"&&n!=="stopping"?!1:o===D,[o,n,a,D]),me=l.useMemo(()=>!a||n!=="active"||!o?!1:o!==D,[o,n,a,D]),Ee=l.useMemo(()=>{if(typeof oe=="number"&&Number.isFinite(oe)&&oe>0)return oe;if(typeof window>"u")return null;const be=Number(window.location.port);return Number.isFinite(be)&&be>0?be:null},[oe]),Ve=l.useCallback(async be=>{await Zn(be)},[]),Y=l.useCallback(async be=>{try{const[He,_e,tt,ut]=await Promise.all([fetch("/api/openchamber/tunnel/check",{signal:be}),fetch("/api/openchamber/tunnel/status",{signal:be}),fetch("/api/config/settings",{signal:be,headers:{Accept:"application/json"}}),fetch("/api/openchamber/tunnel/providers",{signal:be})]),qe=await He.json(),ze=await _e.json(),st=tt.ok?await tt.json():{},yt=ut.ok?await ut.json():{},Mt=ze.ttlConfig?.bootstrapTtlMs??(st?.tunnelBootstrapTtlMs===null?null:typeof st?.tunnelBootstrapTtlMs=="number"?st.tunnelBootstrapTtlMs:1800*1e3),Bt=typeof ze.ttlConfig?.sessionTtlMs=="number"?ze.ttlConfig.sessionTtlMs:typeof st?.tunnelSessionTtlMs=="number"?st.tunnelSessionTtlMs:480*60*1e3,ft=ba(ze.mode??st?.tunnelMode),It=typeof st?.tunnelProvider=="string"&&st.tunnelProvider.trim().length>0?st.tunnelProvider.trim().toLowerCase():"cloudflare",ss=typeof st?.managedLocalTunnelConfigPath=="string"&&st.managedLocalTunnelConfigPath.trim()||null,_t=IC(ze?.managedRemoteTunnelPresets),qt=typeof ze.managedRemoteTunnelHostname=="string"?ze.managedRemoteTunnelHostname:"",ct=_t.length>0?_t:qt?[{id:`legacy-${Xo(qt)}`,name:qt,hostname:Xo(qt)}]:[],jt=ct[0]?.id||"";if(W(Mt),K(Bt),A(It),S(Array.isArray(yt?.providers)?yt.providers:[]),E(ft),C(ss),T(ct),B(jt),fe(Array.isArray(ze.activeSessions)?ze.activeSessions:[]),c(ze.activeTunnelMode?ba(ze.activeTunnelMode):ze.active&&ze.mode?ba(ze.mode):null),Q(new Set(Array.isArray(ze.managedRemoteTunnelTokenPresetIds)?ze.managedRemoteTunnelTokenPresetIds:[])),Se(typeof ze.localPort=="number"?ze.localPort:null),ze.active&&ze.url){i({url:ze.url,connectUrl:null,bootstrapExpiresAt:typeof ze.bootstrapExpiresAt=="number"?ze.bootstrapExpiresAt:null}),r("active");return}r(qe.available?"idle":"not-available")}catch{be.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[t]);l.useEffect(()=>{const be=new AbortController;return Y(be.signal),()=>be.abort()},[Y]),l.useEffect(()=>{if(!a?.connectUrl){p(null);return}let be=!1;return Ix.toDataURL(a.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(He=>{be||p(He)}).catch(()=>{be||p(null)}),()=>{be=!0}},[a?.connectUrl]),l.useEffect(()=>{if(!a?.bootstrapExpiresAt){Ne(t("settings.openchamber.tunnel.state.noExpiry"));return}let be=null,He=Date.now();const _e=()=>{const qe=a.bootstrapExpiresAt?a.bootstrapExpiresAt-Date.now():0;qe<=0?Ne(t("settings.openchamber.tunnel.state.expired")):Ne(Vp(qe))},tt=()=>{const qe=Date.now();qe-He>=1e3&&(_e(),He=qe),be=requestAnimationFrame(tt)};_e(),(typeof document>"u"||document.visibilityState==="visible")&&(be=requestAnimationFrame(tt));const ut=()=>{document.visibilityState==="visible"&&be===null?be=requestAnimationFrame(tt):document.visibilityState!=="visible"&&be!==null&&(cancelAnimationFrame(be),be=null)};return document.addEventListener("visibilitychange",ut),()=>{document.removeEventListener("visibilitychange",ut),be!==null&&cancelAnimationFrame(be)}},[t,a?.bootstrapExpiresAt]),l.useEffect(()=>{let be=null,He=Date.now();const _e=()=>{const ut=Date.now();ut-He>=1e3&&(je(ut),He=ut),be=requestAnimationFrame(_e)};(typeof document>"u"||document.visibilityState==="visible")&&(be=requestAnimationFrame(_e));const tt=()=>{document.visibilityState==="visible"&&be===null?be=requestAnimationFrame(_e):document.visibilityState!=="visible"&&be!==null&&(cancelAnimationFrame(be),be=null)};return document.addEventListener("visibilitychange",tt),()=>{document.removeEventListener("visibilitychange",tt),be!==null&&cancelAnimationFrame(be)}},[]),l.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let be=!1;const He=async()=>{try{const tt=await fetch("/api/openchamber/tunnel/status");if(!tt.ok||be)return;const ut=await tt.json();if(be)return;fe(Array.isArray(ut.activeSessions)?ut.activeSessions:[]),Q(new Set(Array.isArray(ut.managedRemoteTunnelTokenPresetIds)?ut.managedRemoteTunnelTokenPresetIds:[])),Se(typeof ut.localPort=="number"?ut.localPort:null)}catch{}},_e=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||He()},5e3);return()=>{be=!0,window.clearInterval(_e)}},[n]);const ke=l.useCallback(async be=>{y(!0);try{await Is(be),Object.prototype.hasOwnProperty.call(be,"tunnelMode")&&be.tunnelMode&&E(be.tunnelMode),Object.prototype.hasOwnProperty.call(be,"tunnelProvider")&&typeof be.tunnelProvider=="string"&&A(be.tunnelProvider),Object.prototype.hasOwnProperty.call(be,"managedLocalTunnelConfigPath")&&C(be.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(be,"managedRemoteTunnelPresets")&&be.managedRemoteTunnelPresets&&T(be.managedRemoteTunnelPresets)}catch{H.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{y(!1)}},[t]),Be=l.useCallback(async(be,He)=>{g(!0);try{await Is({tunnelBootstrapTtlMs:be,tunnelSessionTtlMs:He})}catch{H.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),Ce=l.useCallback(async be=>{const He=be.token.trim();if(He)try{const _e={...V,[be.presetId]:He};await Is({managedRemoteTunnelPresetTokens:_e}),Q(tt=>{const ut=new Set(tt);return ut.add(be.presetId),ut})}catch{H.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[V,t]),ge=l.useCallback(async be=>{b(null),u(null),await ke({tunnelProvider:be})},[ke]),O=l.useCallback(async()=>{const be=await Xf({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(be.success&&typeof be.path=="string"&&be.path.trim().length>0){const He=be.path.trim();if(!Ei(He)){H.error(se);return}C(He),await ke({managedLocalTunnelConfigPath:He});return}we.current?.click()},[se,ke]),X=l.useCallback(be=>{const He=be.trim();C(He.length>0?He:null)},[]),G=l.useCallback(async()=>{if(P&&!Ei(P)){H.error(se);return}await ke({managedLocalTunnelConfigPath:P})},[se,P,ke]),Te=l.useCallback(async()=>{C(null),await ke({managedLocalTunnelConfigPath:null})},[ke]),le=l.useCallback(async be=>{const He=be.target.files?.[0];if(!He)return;const _e=He.name.trim();if(_e.length!==0){if(!Ei(_e)){H.error(se);return}C(_e),await ke({managedLocalTunnelConfigPath:_e}),be.target.value=""}},[se,ke]),We=l.useCallback(async()=>{if(u(null),b(null),D==="managed-local"&&P&&!Ei(P)){u(se),H.error(se);return}r("starting");try{let be="",He="";if(D==="managed-remote"){if(!ve){r("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),H.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}be=ve.hostname,He=(V[ve.id]||"").trim(),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const _e=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:k,mode:D,...D==="managed-remote"&&ve?{managedRemoteTunnelPresetId:ve.id,managedRemoteTunnelPresetName:ve.name}:{},...D==="managed-remote"&&be?{managedRemoteTunnelHostname:be}:{},...D==="managed-remote"&&He?{managedRemoteTunnelToken:He}:{},...D==="managed-local"&&P?{configPath:P}:{}})}),tt=await _e.json();if(!_e.ok||!tt.ok){if(D==="managed-remote"&&typeof tt.error=="string"&&tt.error.includes("Managed remote tunnel token is required")){r("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),H.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(tt.error||t("settings.openchamber.tunnel.toast.startFailed")),H.error(tt.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const ut=typeof tt.url=="string"?tt.url:"";if(!ut){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),H.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(i({url:ut,connectUrl:typeof tt.connectUrl=="string"?tt.connectUrl:null,bootstrapExpiresAt:typeof tt.bootstrapExpiresAt=="number"?tt.bootstrapExpiresAt:null}),c(tt.activeTunnelMode?ba(tt.activeTunnelMode):tt.mode?ba(tt.mode):D),fe(Array.isArray(tt.activeSessions)?tt.activeSessions:[]),Array.isArray(tt.managedRemoteTunnelTokenPresetIds)&&Q(new Set(tt.managedRemoteTunnelTokenPresetIds)),typeof tt.localPort=="number"&&Se(tt.localPort),typeof tt.mode=="string"&&E(ba(tt.mode)),r("active"),tt.replacedTunnel){const qe=typeof tt.revokedBootstrapCount=="number"?tt.revokedBootstrapCount:0,ze=typeof tt.invalidatedSessionCount=="number"?tt.invalidatedSessionCount:0;qe===1&&ze===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):qe===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ze})):ze===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:qe})):H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:qe,invalidatedSessionCount:ze}))}else H.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.startFailed")),H.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[se,N,ke,ve,V,t,k,D,P]),de=l.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const be=await fetch("/api/openchamber/tunnel/status");if(be.ok){const He=await be.json();fe(Array.isArray(He.activeSessions)?He.activeSessions:[]),Q(new Set(Array.isArray(He.managedRemoteTunnelTokenPresetIds)?He.managedRemoteTunnelTokenPresetIds:[])),Se(typeof He.localPort=="number"?He.localPort:null)}i(null),c(null),p(null),r("idle"),H.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.stopFailed")),H.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),Fe=l.useCallback(async()=>{if(a?.connectUrl)try{await navigator.clipboard.writeText(a.connectUrl),v(!0),H.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>v(!1),2e3)}catch{H.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,a?.connectUrl]),rt=l.useCallback(async be=>{const He=Mc.find(_e=>_e.value===be);He&&(W(He.ms),await Be(He.ms,Z))},[Be,Z]),Oe=l.useCallback(async be=>{const He=Ec.find(_e=>_e.value===be);!He||He.ms===null||(K(He.ms),await Be(U,He.ms))},[U,Be]),Ye=l.useCallback(async be=>{b(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await ke({tunnelMode:be,managedRemoteTunnelPresets:N})},[N,ke,n]),Ge=l.useCallback(async(be,He)=>{try{await Is({managedRemoteTunnelPresets:He})}catch{H.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),it=l.useCallback(be=>{const He=N.find(_e=>_e.id===be);He&&(B(He.id),b(null),Ge(He,N))},[N,Ge]),Qe=l.useCallback(async()=>{const be=ee.trim(),He=Xo(q),_e=ae.trim();if(!be){H.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!He){H.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!_e){H.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(qe=>qe.hostname===He)){H.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const tt={id:PC(),name:be,hostname:He},ut=[...N,tt];T(ut),B(tt.id),F(qe=>({...qe,[tt.id]:!0})),$(qe=>({...qe,[tt.id]:_e})),b(null),J(!1),re(""),ce(""),R(""),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:ut,managedRemoteTunnelPresetTokens:{...V,[tt.id]:_e}}),await Ce({presetId:tt.id,presetName:tt.name,hostname:tt.hostname,token:_e}),H.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,q,ee,ae,Ce,ke,V,t]),at=l.useCallback(async be=>{const He=N.find(ze=>ze.id===be);if(!He)return;const _e=N.filter(ze=>ze.id!==He.id),tt=_e[0]?.id||"",ut=_===He.id?tt:_,qe=Object.fromEntries(Object.entries(V).filter(([ze,st])=>ze!==He.id&&st.trim().length>0));T(_e),B(ut),F(ze=>{const st={...ze};return delete st[He.id],st}),$(ze=>{const st={...ze};return delete st[He.id],st}),Q(ze=>{const st=new Set(ze);return st.delete(He.id),st}),b(null),await ke({managedRemoteTunnelPresets:_e,managedRemoteTunnelPresetTokens:qe}),H.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,ke,_,V,t]),nt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.openchamber.tunnel.state.loading")})}):s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.openchamber.tunnel.title")}),s.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/70",children:t("settings.openchamber.tunnel.description")}),s.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:t("settings.openchamber.tunnel.note.serverSideEnforced")}),s.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:t("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),ye.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(I,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ye.map(be=>{const He=be.mode==="quick",_e=be.mode==="managed-remote",tt=He?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":_e?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",ut=be.isActive?He?"text-[var(--status-warning)]":_e?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",qe=t(He?"settings.openchamber.tunnel.badge.quick":_e?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(I,{name:"checkbox-blank-circle-fill",className:ue("size-2.5 shrink-0",ut)}),s.jsx("span",{className:ue("typography-micro rounded border px-1.5 py-0.5 uppercase",tt),children:qe}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:CC(be.createdAt)})}),s.jsx("span",{className:"typography-meta text-foreground",children:be.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:be.remainingTextForSession}):be.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:be.inactiveLabel})})]},be.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.notAvailable.cloudflaredNotFound")}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:"brew install cloudflared"})]})]})}),n!=="not-available"&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(is,{value:k,onValueChange:be=>{ge(be)},disabled:w||n==="starting"||n==="stopping",children:[s.jsx(os,{className:"max-w-[16rem]",children:s.jsx(us,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:kg(k)})}),s.jsxs(ls,{children:[j.length>0?j.map(be=>s.jsx(Ft,{value:be.provider,children:s.jsx(_p,{provider:be.provider})},be.provider)):s.jsx(Ft,{value:"cloudflare",children:s.jsx(_p,{provider:"cloudflare"})}),s.jsx(Ft,{value:"__more-soon",disabled:!0,children:t("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Bp.map(be=>s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{variant:"chip",size:"xs","aria-pressed":D===be.value,className:"!font-normal",onClick:()=>{Ye(be.value)},disabled:w||n==="starting"||n==="stopping",children:e(be.labelKey)})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:e(be.tooltipKey)})]},be.value))})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(is,{value:zp(Mc,U,"1800000"),onValueChange:be=>{rt(be)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(os,{className:"max-w-[11rem] min-w-0",children:s.jsx(us,{className:"truncate"})}),s.jsx(ls,{children:Mc.map(be=>s.jsx(Ft,{value:be.value,children:be.label},be.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(is,{value:zp(Ec,Z,"28800000"),onValueChange:be=>{Oe(be)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(os,{className:"max-w-[11rem] min-w-0",children:s.jsx(us,{className:"truncate"})}),s.jsx(ls,{children:Ec.map(be=>s.jsx(Ft,{value:be.value,children:be.label},be.value))})]})]})]}),D==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),D==="managed-remote"&&s.jsxs("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Ee=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Ee]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(xe,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>J(be=>!be),disabled:n==="starting"||n==="stopping"||w,children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),N.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:N.map((be,He)=>{const _e=V[be.id]||"",tt=z.has(be.id),ut=M[be.id]??!1;return s.jsx("div",{className:ue(He<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(pr,{open:ut,onOpenChange:qe=>{F(ze=>({...ze,[be.id]:qe})),qe&&it(be.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Nr,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||w,children:[ut?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:be.name})]}),s.jsx(xe,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:be.name}),onClick:()=>{at(be.id)},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(fr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:be.hostname})]}),s.jsx(Vt,{type:"password",value:_e,onChange:qe=>{const ze=qe.target.value;b(null),$(st=>({...st,[be.id]:ze}))},onBlur:qe=>{const ze=qe.currentTarget.value.trim();ze&&Ce({presetId:be.id,presetName:be.name,hostname:be.hostname,token:ze})},placeholder:t(tt?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(xe,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||_e.trim().length===0,onClick:()=>{Ce({presetId:be.id,presetName:be.name,hostname:be.hostname,token:_e})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},be.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),L&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Vt,{value:ee,onChange:be=>re(be.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Vt,{value:q,onChange:be=>ce(be.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Vt,{type:"password",value:ae,onChange:be=>R(be.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),typeof Ee=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ee]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xe,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Qe()},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(xe,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{J(!1),re(""),ce(""),R("")},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground/70 hover:text-foreground","aria-label":t("settings.openchamber.tunnel.field.managedRemoteTokenInfoAria"),children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!ve&&f&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:f})]}),D==="managed-local"&&s.jsx("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:we,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:be=>{le(be)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vt,{value:P||"",onChange:be=>{X(be.target.value)},onBlur:()=>{G()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||w}),s.jsx(xe,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{O()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(I,{name:"folder",className:"size-3.5"})}),P&&s.jsx(xe,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{Te()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(I,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(P?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Ae&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:se})]})}),!he&&s.jsxs("div",{className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(I,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[D==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ve(jC)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(I,{name:"external-link",className:"size-3.5"})]})]}),D==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ve(NC)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(I,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:e(Bp.find(be=>be.value===D)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),D==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(is,{value:_||(N[0]?.id??""),onValueChange:be=>{it(be)},disabled:w||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(os,{children:s.jsx(us,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:ve?.name})}),s.jsx(ls,{fitContent:!0,children:N.map(be=>s.jsx(Ft,{value:be.id,children:be.name},be.id))})]})]}),me&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(xe,{size:"sm",variant:"outline",onClick:We,disabled:n==="starting"||w||D==="managed-remote"&&!ve||D==="managed-local"&&Ae,className:ue(nt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),he&&a&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:a.url})]}),Ie&&a.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:a.connectUrl}),s.jsxs(xe,{size:"sm",variant:"ghost",onClick:Fe,className:"shrink-0 gap-1.5",children:[h?s.jsx(I,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(I,{name:"file-copy",className:"size-3.5"}),t(h?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",a.bootstrapExpiresAt?ie:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[d?s.jsx("img",{src:d,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(xe,{size:"sm",variant:"outline",onClick:We,disabled:n==="stopping"||w||D==="managed-local"&&Ae,className:nt,children:[s.jsx(I,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(xe,{size:"sm",variant:"ghost",onClick:de,disabled:n==="stopping"||w,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&m&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m}),s.jsx(xe,{size:"sm",variant:"ghost",onClick:We,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},Cg=()=>{const{t}=pt(),[e,n]=$e.useState(""),[r,a]=$e.useState(!0),[i,o]=$e.useState(!1),c=De(u=>u.showOpenCodeUpdateNotifications),d=De(u=>u.setShowOpenCodeUpdateNotifications);$e.useEffect(()=>{let u=!1;return(async()=>{try{const f=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!f.ok)return;const b=await f.json().catch(()=>null);if(u||!b)return;const h=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";n(h)}catch{}finally{u||a(!1)}})(),()=>{u=!0}},[]);const p=$e.useCallback(async()=>{if(typeof window>"u"||!dn()||!Ma())return;const u=window.__TAURI__;if(u?.dialog?.open)try{const f=await u.dialog.open({title:t("settings.openchamber.opencodeCli.dialog.selectBinaryTitle"),multiple:!1,directory:!1});typeof f=="string"&&f.trim().length>0&&n(f.trim())}catch{}},[t]),m=$e.useCallback(async()=>{o(!0);try{await Is({opencodeBinary:e.trim()}),await ai({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{o(!1)}},[t,e]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.opencodeCli.title")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Ct,{sideOffset:8,className:"max-w-xs",children:[t("settings.openchamber.opencodeCli.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs",children:"opencode"}),t("settings.openchamber.opencodeCli.tooltipSuffix")]})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-3",children:[s.jsx("div",{className:"flex min-w-0 flex-col shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.opencodeCli.field.binaryPath")})}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:w-[20rem]",children:[s.jsx(Vt,{value:e,onChange:u=>n(u.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:r||i,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),s.jsx(xe,{type:"button",variant:"outline",size:"xs",onClick:p,disabled:r||i||!dn()||!Ma(),className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(I,{name:"folder",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"typography-micro text-muted-foreground/70",children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]})}),s.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5",children:[s.jsx(ds,{checked:c,onChange:d,ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.opencodeCli.field.showUpdateNotifications")})]}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(xe,{type:"button",size:"xs",onClick:m,disabled:r||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},Ig=()=>{const{t}=pt(),e=dn()&&Gr(),[n,r]=$e.useState(!1),[a,i]=$e.useState(!1),[o,c]=$e.useState(!0),[d,p]=$e.useState(!1),[m,u]=$e.useState(null),[f,b]=$e.useState(null);$e.useEffect(()=>{if(!e){c(!1);return}let y=!1;return(async()=>{try{const k=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const A=await k.json().catch(()=>null);if(y)return;const j=A?.desktopLanAccessEnabled===!0;r(j),i(j),u(null)}catch(k){y||u(k instanceof Error?k.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{y||c(!1)}})(),()=>{y=!0}},[e,t]),$e.useEffect(()=>{if(!e||!a){b(null);return}let y=!1;return(async()=>{const k=await ry();y||b(k)})(),()=>{y=!0}},[a,e]);const h=a!==n,v=$e.useMemo(()=>{if(typeof window>"u")return null;const y=Number(window.location.port);return Number.isFinite(y)&&y>0?y:null},[]),x=a&&f&&v?`http://${f}:${v}`:null,g=$e.useCallback(()=>{i(y=>!y)},[]),w=$e.useCallback(async()=>{if(h){p(!0),u(null);try{if(!(await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:a})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(a),!await ah())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(y){u(y instanceof Error?y.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),p(!1)}}},[a,h,t]);return e?s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.desktopNetwork.title")})}),s.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:g,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),g())},children:[s.jsx(ds,{checked:a,onChange:g,ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:o||d}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.desktopNetwork.field.allowLanAccess")}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription")}),s.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")})]})]}),m?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:m}):null,x?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(h&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:x})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(xe,{type:"button",size:"xs",onClick:w,disabled:o||d||!h,className:"shrink-0 !font-normal",children:t(d?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},DC=new Set(["shift","control","alt","meta"]),TC=t=>{if(DC.has(t.key.toLowerCase()))return null;const e=[];(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt");const n=iy(t.key);return n?(e.push(n),Xa(e.join("+"))):null},MC=()=>{const t=ot.c(58),{t:e}=pt();let n;t[0]!==e?(n=ae=>e(ae),t[0]=e,t[1]=n):n=t[1];const r=n,a=De(EC),i=De(RC),o=De(FC),c=De(OC);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=ay(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(ae,R)=>{const U=`settings.openchamber.keyboardShortcuts.action.${ae}.label`,W=r(U);return W===U?R:W},t[3]=r,t[4]=m):m=t[4];const u=m,[f,b]=l.useState(null);let h;t[5]===Symbol.for("react.memo_cache_sentinel")?(h={},t[5]=h):h=t[5];const[v,x]=l.useState(h),[g,w]=l.useState(""),[y,k]=l.useState(""),[A,j]=l.useState(null);let S;t[6]!==a?(S=(ae,R)=>{const U=Xa(R);for(const W of p){if(W.id===ae)continue;const Z=Wr(W.id,a);if(Xa(Z)===U)return W.id}return null},t[6]=a,t[7]=S):S=t[7];const D=S;let E;t[8]!==D||t[9]!==i||t[10]!==e?(E=(ae,R)=>{const U=Xa(R),W=D(ae,U);if(W){j({actionId:ae,combo:U,conflictActionId:W}),w("");return}i(ae,U),j(null),w(""),k(Mu(U)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(Z=>{const K={...Z};return delete K[ae],K})},t[8]=D,t[9]=i,t[10]=e,t[11]=E):E=t[11];const P=E;let C;t[12]!==A||t[13]!==i||t[14]!==e?(C=()=>{A&&(i(A.conflictActionId,oy),i(A.actionId,A.combo),j(null),w(""),k(Mu(A.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(ae=>{const R={...ae};return delete R[A.actionId],R}))},t[12]=A,t[13]=i,t[14]=e,t[15]=C):C=t[15];const N=C;let T;t[16]!==o?(T=ae=>{o(ae),x(R=>{const U={...R};return delete U[ae],U}),j(null),w(""),k("")},t[16]=o,t[17]=T):T=t[17];const M=T;let F;t[18]!==e?(F=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=F):F=t[19];let _;t[20]!==F?(_=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:F}),t[20]=F,t[21]=_):_=t[21];let B;t[22]!==c?(B=()=>{c(),x({}),j(null),w(""),k("")},t[22]=c,t[23]=B):B=t[23];let V;t[24]!==e?(V=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=V):V=t[25];let $;t[26]!==B||t[27]!==V?($=s.jsx(xe,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:B,children:V}),t[26]=B,t[27]=V,t[28]=$):$=t[28];let z;t[29]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(kt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=z):z=t[29];let Q;t[30]!==e?(Q=e("settings.openchamber.keyboardShortcuts.tooltip"),t[30]=e,t[31]=Q):Q=t[31];let L;t[32]!==Q?(L=s.jsxs(St,{children:[z,s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:Q})]}),t[32]=Q,t[33]=L):L=t[33];let J;t[34]!==$||t[35]!==L||t[36]!==_?(J=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[_,$,L]})}),t[34]=$,t[35]=L,t[36]=_,t[37]=J):J=t[37];let ee;t[38]!==N||t[39]!==g||t[40]!==A||t[41]!==e||t[42]!==y?(ee=(g||y||A)&&s.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[A&&s.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),s.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.jsx(xe,{type:"button",size:"xs",className:"!font-normal",onClick:N,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(xe,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>j(null),children:e("settings.common.actions.cancel")})]})]}),g&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:g}),y&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:y})]}),t[38]=N,t[39]=g,t[40]=A,t[41]=e,t[42]=y,t[43]=ee):ee=t[43];let re;t[44]!==u||t[45]!==f||t[46]!==v||t[47]!==M||t[48]!==P||t[49]!==a||t[50]!==e?(re=p.map((ae,R)=>{const U=Wr(ae.id,a),W=v[ae.id],Z=W??U,K=typeof W=="string"&&Xa(W)!==Xa(U);return s.jsxs("div",{className:ue("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",R>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:u(ae.id,ae.label)})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Vt,{readOnly:!0,value:f===ae.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):Il(Z),onFocus:()=>{b(ae.id),w("")},onBlur:()=>{f===ae.id&&b(null)},onKeyDown:ie=>{if(ie.preventDefault(),ie.stopPropagation(),ie.key==="Escape"){b(null);return}const Ne=TC(ie);Ne&&(x(ne=>({...ne,[ae.id]:Ne})),b(null),j(null),w(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(xe,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const ie=v[ae.id];if(!ie){w(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}P(ae.id,ie)},disabled:!K,children:e("settings.common.actions.saveChanges")}),s.jsx(xe,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>M(ae.id),children:e("settings.common.actions.reset")})]})]},ae.id)}),t[44]=u,t[45]=f,t[46]=v,t[47]=M,t[48]=P,t[49]=a,t[50]=e,t[51]=re):re=t[51];let q;t[52]!==re?(q=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:re}),t[52]=re,t[53]=q):q=t[53];let ce;return t[54]!==J||t[55]!==ee||t[56]!==q?(ce=s.jsxs("div",{className:"mb-8",children:[J,ee,q]}),t[54]=J,t[55]=ee,t[56]=q,t[57]=ce):ce=t[57],ce};function EC(t){return t.shortcutOverrides}function RC(t){return t.setShortcutOverride}function FC(t){return t.clearShortcutOverride}function OC(t){return t.resetAllShortcutOverrides}const LC=t=>{const e=ot.c(20),{section:n}=t,{isMobile:r}=nn();let a;e[0]!==r?(a=r&&Hr(),e[0]=r,e[1]=a):a=e[1];const i=a;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=ln(),e[2]=o):o=e[2];const c=o;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=dn()&&Gr(),e[3]=d):d=e[3];const p=d;if(!n){let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(su,{}),e[4]=h):h=e[4];let v,x,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Sg,{})}),x=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Cg,{})}),g=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})}),e[5]=v,e[6]=x,e[7]=g):(v=e[5],x=e[6],g=e[7]);let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(jg,{})}),e[8]=w):w=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})}),e[9]=y):y=e[9];let k;e[10]!==i?(k=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(nC,{})}),e[10]=i,e[11]=k):k=e[11];let A;return e[12]!==k?(A=s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[h,v,x,g,w,y,k]})}),e[12]=k,e[13]=A):A=e[13],A}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(BC,{});case"chat":return s.jsx(_C,{});case"sessions":return s.jsx(zC,{});case"shortcuts":return s.jsx($C,{});case"git":return s.jsx(VC,{});case"github":return s.jsx(UC,{});case"notifications":return s.jsx(WC,{});case"voice":return s.jsx(KC,{});case"tunnel":return s.jsx(HC,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const u=m;let f;e[16]!==u?(f=u(),e[16]=u,e[17]=f):f=e[17];let b;return e[18]!==f?(b=s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",children:f})}),e[18]=f,e[19]=b):b=e[19],b},$C=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(MC,{}),t[0]=e):e=t[0],e},BC=()=>{const t=ot.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ln(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(su,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},_C=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(su,{visibleSettings:["chatRenderMode","messageTransport","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","expandedTools","stickyUserHeader","wideChatLayout","splitAssistantMessageActions","diffLayout","mobileStatusBar","dotfiles","queueMode","persistDraft","inputSpellcheck"]}),t[0]=e):e=t[0],e},zC=()=>{const t=ot.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ln(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=dn()&&Gr(),t[1]=r):r=t[1];const a=r;let i,o,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Sg,{}),o=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Cg,{})}),c=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})}),t[2]=i,t[3]=o,t[4]=c):(i=t[2],o=t[3],c=t[4]);let d;t[5]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(jg,{})}),t[5]=d):d=t[5];let p;return t[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs("div",{className:"space-y-6",children:[i,o,c,d,s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})})]}),t[6]=p):p=t[6],p},VC=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(bg,{})}),t[0]=e):e=t[0],e},UC=()=>{const t=ot.c(1);if(ln())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(yg,{}),t[0]=e):e=t[0],e},WC=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(gC,{}),t[0]=e):e=t[0],e},KC=()=>{const t=ot.c(1);if(ln())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(vC,{}),t[0]=e):e=t[0],e},HC=()=>{const t=ot.c(1);if(ln())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(AC,{}),t[0]=e):e=t[0],e},wd=176,jd=280,Up=8;function Rc(t){return Math.min(jd,Math.max(wd,t))}const GC=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","projects","remote-instances","agents","behavior","commands","mcp","providers","usage","skills.installed","skills.catalog","voice","tunnel"];function qC(t){const e=ln(),n=!t&&Hr();return{isVSCode:e,isWeb:n,isDesktop:t}}function Wp(t,e){return t.isAvailable?t.isAvailable(e):!0}function nu(t){switch(t){case"projects":return"folders";case"remote-instances":return"server";case"appearance":return"palette";case"chat":return"chat-ai-3";case"magic-prompts":return"ai-generate-2";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"chat-history";case"providers":return"cloud";case"agents":return"ai-agent";case"behavior":return"brain";case"commands":return"slash-commands-2";case"mcp":return"plug-2";case"skills.installed":return"book-open";case"skills.catalog":return"book";case"git":return"git-branch";case"usage":return"bar-chart-2";case"voice":return"mic";case"tunnel":return"global";case"home":return null;default:return"robot-2"}}const Fc=t=>{const e=ot.c(95),{onOpen:n}=t,{t:r}=pt();let a;e[0]!==r?(a=r("settings.view.home.title"),e[0]=r,e[1]=a):a=e[1];let i;e[2]!==a?(i=s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:a}),e[2]=a,e[3]=i):i=e[3];let o;e[4]!==r?(o=r("settings.view.home.description"),e[4]=r,e[5]=o):o=e[5];let c;e[6]!==o?(c=s.jsx("p",{className:"typography-ui text-muted-foreground",children:o}),e[6]=o,e[7]=c):c=e[7];let d;e[8]!==i||e[9]!==c?(d=s.jsxs("div",{className:"space-y-1",children:[i,c]}),e[8]=i,e[9]=c,e[10]=d):d=e[10];let p;e[11]!==n?(p=()=>n("providers"),e[11]=n,e[12]=p):p=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=ue("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=m):m=e[13];let u;e[14]!==r?(u=r("settings.view.home.cards.providers.title"),e[14]=r,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-ui-label text-foreground",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==r?(b=r("settings.view.home.cards.providers.description"),e[18]=r,e[19]=b):b=e[19];let h;e[20]!==b?(h=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:b}),e[20]=b,e[21]=h):h=e[21];let v;e[22]!==h||e[23]!==p||e[24]!==f?(v=s.jsxs("button",{type:"button",onClick:p,className:m,children:[f,h]}),e[22]=h,e[23]=p,e[24]=f,e[25]=v):v=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let g;e[28]===Symbol.for("react.memo_cache_sentinel")?(g=ue("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=g):g=e[28];let w;e[29]!==r?(w=r("settings.view.home.cards.agents.title"),e[29]=r,e[30]=w):w=e[30];let y;e[31]!==w?(y=s.jsx("div",{className:"typography-ui-label text-foreground",children:w}),e[31]=w,e[32]=y):y=e[32];let k;e[33]!==r?(k=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=k):k=e[34];let A;e[35]!==k?(A=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:k}),e[35]=k,e[36]=A):A=e[36];let j;e[37]!==x||e[38]!==y||e[39]!==A?(j=s.jsxs("button",{type:"button",onClick:x,className:g,children:[y,A]}),e[37]=x,e[38]=y,e[39]=A,e[40]=j):j=e[40];let S;e[41]!==n?(S=()=>n("skills.catalog"),e[41]=n,e[42]=S):S=e[42];let D;e[43]===Symbol.for("react.memo_cache_sentinel")?(D=ue("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=D):D=e[43];let E;e[44]!==r?(E=r("settings.view.home.cards.skillsCatalog.title"),e[44]=r,e[45]=E):E=e[45];let P;e[46]!==E?(P=s.jsx("div",{className:"typography-ui-label text-foreground",children:E}),e[46]=E,e[47]=P):P=e[47];let C;e[48]!==r?(C=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=C):C=e[49];let N;e[50]!==C?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:C}),e[50]=C,e[51]=N):N=e[51];let T;e[52]!==S||e[53]!==P||e[54]!==N?(T=s.jsxs("button",{type:"button",onClick:S,className:D,children:[P,N]}),e[52]=S,e[53]=P,e[54]=N,e[55]=T):T=e[55];let M;e[56]!==n?(M=()=>n("mcp"),e[56]=n,e[57]=M):M=e[57];let F;e[58]===Symbol.for("react.memo_cache_sentinel")?(F=ue("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=F):F=e[58];let _;e[59]!==r?(_=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=_):_=e[60];let B;e[61]!==_?(B=s.jsx("div",{className:"typography-ui-label text-foreground",children:_}),e[61]=_,e[62]=B):B=e[62];let V;e[63]!==r?(V=r("settings.view.home.cards.mcp.description"),e[63]=r,e[64]=V):V=e[64];let $;e[65]!==V?($=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:V}),e[65]=V,e[66]=$):$=e[66];let z;e[67]!==M||e[68]!==B||e[69]!==$?(z=s.jsxs("button",{type:"button",onClick:M,className:F,children:[B,$]}),e[67]=M,e[68]=B,e[69]=$,e[70]=z):z=e[70];let Q;e[71]!==n?(Q=()=>n("usage"),e[71]=n,e[72]=Q):Q=e[72];let L;e[73]===Symbol.for("react.memo_cache_sentinel")?(L=ue("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=L):L=e[73];let J;e[74]!==r?(J=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=J):J=e[75];let ee;e[76]!==J?(ee=s.jsx("div",{className:"typography-ui-label text-foreground",children:J}),e[76]=J,e[77]=ee):ee=e[77];let re;e[78]!==r?(re=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=re):re=e[79];let q;e[80]!==re?(q=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:re}),e[80]=re,e[81]=q):q=e[81];let ce;e[82]!==Q||e[83]!==ee||e[84]!==q?(ce=s.jsxs("button",{type:"button",onClick:Q,className:L,children:[ee,q]}),e[82]=Q,e[83]=ee,e[84]=q,e[85]=ce):ce=e[85];let ae;e[86]!==v||e[87]!==j||e[88]!==T||e[89]!==z||e[90]!==ce?(ae=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[v,j,T,z,ce]}),e[86]=v,e[87]=j,e[88]=T,e[89]=z,e[90]=ce,e[91]=ae):ae=e[91];let R;return e[92]!==ae||e[93]!==d?(R=s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl px-6 py-6 space-y-6",children:[d,ae]})}),e[92]=ae,e[93]=d,e[94]=R):R=e[94],R},YC=t=>{const e=ot.c(104),{onClose:n,forceMobile:r,isWindowed:a}=t,{t:i}=pt(),o=nn(),c=r??o.isMobile,d=De(JC),p=De(QC),m=De(XC);let u;e[0]!==d?(u=lg(d),e[0]=d,e[1]=u):u=e[1];const f=u,[b,h]=l.useState("nav"),v=l.useRef(null),[x,g]=l.useState(216),[w,y]=l.useState(!1),[k,A]=l.useState(!1),j=l.useRef(0),S=l.useRef(x),D=l.useRef(null);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=dn(),e[2]=E):E=e[2];const P=E;let C;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=qC(P),e[3]=C):C=e[3];const N=C;let T;if(e[4]!==c){let Ce;e[6]===Symbol.for("react.memo_cache_sentinel")?(Ce=O=>Wp(O,N),e[6]=Ce):Ce=e[6];let ge;e[7]===Symbol.for("react.memo_cache_sentinel")?(ge=O=>!(N.isVSCode&&O.slug==="projects"),e[7]=ge):ge=e[7],T=Zd.filter(ZC).filter(Ce).filter(ge).filter(O=>!(c&&O.slug==="shortcuts")),e[4]=c,e[5]=T}else T=e[5];const M=T;let F;e[8]===Symbol.for("react.memo_cache_sentinel")?(F=new Map(GC.map(e4)),e[8]=F):F=e[8];const _=F;let B;if(e[9]!==M){let Ce;e[11]===Symbol.for("react.memo_cache_sentinel")?(Ce=(ge,O)=>(_.get(ge.slug)??999)-(_.get(O.slug)??999),e[11]=Ce):Ce=e[11],B=M.slice().sort(Ce),e[9]=M,e[10]=B}else B=e[10];const V=B,$=Ts(t4);let z,Q;e[12]!==w?(z=()=>{if(typeof window>"u")return;const Ce=()=>{if(!w){const ge=Rc(Math.floor(window.innerWidth*.12));g(ge)}};return window.addEventListener("resize",Ce),()=>window.removeEventListener("resize",Ce)},Q=[w],e[12]=w,e[13]=z,e[14]=Q):(z=e[13],Q=e[14]),l.useEffect(z,Q);let L,J;e[15]!==k?(J=()=>{if(!k)return;const Ce=O=>{const X=O.clientX-j.current,G=Rc(S.current+X);g(G),y(!0)},ge=()=>A(!1);return window.addEventListener("pointermove",Ce),window.addEventListener("pointerup",ge,{once:!0}),()=>{window.removeEventListener("pointermove",Ce),window.removeEventListener("pointerup",ge)}},L=[k],e[15]=k,e[16]=L,e[17]=J):(L=e[16],J=e[17]),l.useEffect(J,L);let ee;e[18]!==x?(ee=Ce=>{A(!0),j.current=Ce.clientX,S.current=x,Ce.preventDefault()},e[18]=x,e[19]=ee):ee=e[19];const re=ee;let q;e[20]!==x?(q=Ce=>{const ge=Ce.shiftKey?Up*4:Up;let O;e:switch(Ce.key){case"ArrowLeft":{O=x-ge;break e}case"ArrowRight":{O=x+ge;break e}case"Home":{O=wd;break e}case"End":{O=jd;break e}default:return}Ce.preventDefault(),g(Rc(O)),y(!0)},e[20]=x,e[21]=q):q=e[21];const ce=q;let ae;e[22]!==p||e[23]!==a||e[24]!==f?(ae=()=>{if(!(!p&&!N.isVSCode&&!a)){if(f==="agents"){di.getState().loadAgents();return}if(f==="commands"){_d.getState().loadCommands();return}if(f==="mcp"){so.getState().loadMcpConfigs();return}(f==="skills.installed"||f==="skills.catalog")&&(ra.getState().loadSkills(),Pa.getState().loadCatalog())}},e[22]=p,e[23]=a,e[24]=f,e[25]=ae):ae=e[25];let R;e[26]!==$||e[27]!==p||e[28]!==a||e[29]!==f?(R=[$,p,a,N.isVSCode,f],e[26]=$,e[27]=p,e[28]=a,e[29]=f,e[30]=R):R=e[30],l.useEffect(ae,R);let U;e[31]!==c||e[32]!==m?(U=Ce=>{if(m(Ce),v.current=Ce,!c)return;const ge=$i(Ce);if(!ge||ge.slug==="home"){h("nav");return}h(ge.kind==="split"?"page-sidebar":"page-content")},e[31]=c,e[32]=m,e[33]=U):U=e[33];const W=U;let Z;e[34]!==f?(Z=$i(f),e[34]=f,e[35]=Z):Z=e[35];const K=Z;let ie;e[36]===Symbol.for("react.memo_cache_sentinel")?(ie={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[36]=ie):ie=e[36];const Ne=ie;let ne;e[37]!==i?(ne=Ce=>{switch(Ce){case"projects":return i("settings.page.projects.title");case"remote-instances":return i("settings.page.remoteInstances.title");case"providers":return i("settings.page.providers.title");case"usage":return i("settings.page.usage.title");case"agents":return i("settings.page.agents.title");case"behavior":return i("settings.page.behavior.title");case"commands":return i("settings.page.commands.title");case"mcp":return i("settings.page.mcp.title");case"skills.installed":return i("settings.page.skills.title");case"skills.catalog":return i("settings.page.skillsCatalog.title");case"git":return i("settings.page.git.title");case"appearance":return i("settings.page.appearance.title");case"chat":return i("settings.page.chat.title");case"shortcuts":return i("settings.page.shortcuts.title");case"sessions":return i("settings.page.sessions.title");case"magic-prompts":return i("settings.page.magicPrompts.title");case"notifications":return i("settings.page.notifications.title");case"voice":return i("settings.page.voice.title");case"tunnel":return i("settings.page.tunnel.title");default:return i("settings.view.home.title")}},e[37]=i,e[38]=ne):ne=e[38];const fe=ne;let pe;e[39]!==i?(pe=()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:i("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:i("settings.view.unavailable.description")})]})}),e[39]=i,e[40]=pe):pe=e[40];const je=pe,oe=s4;let Se;e[41]!==W||e[42]!==je?(Se=Ce=>{const ge=$i(Ce);if(ge&&!Wp(ge,N))return je();switch(Ce){case"home":return s.jsx(Fc,{onOpen:W});case"projects":return s.jsx(j3,{});case"remote-instances":return s.jsx(q3,{});case"agents":return s.jsx(qS,{});case"behavior":return s.jsx(ZS,{});case"commands":return s.jsx(lk,{});case"mcp":return s.jsx(Ok,{});case"skills.installed":return s.jsx(hp,{view:"installed"});case"skills.catalog":return s.jsx(hp,{view:"catalog"});case"providers":return s.jsx(s5,{});case"usage":return s.jsx(v5,{});case"magic-prompts":return s.jsx(k5,{});case"git":return s.jsx(D5,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const O=Ne[Ce]??"visual";return s.jsx(LC,{section:O})}default:return s.jsx(Fc,{onOpen:W})}},e[41]=W,e[42]=je,e[43]=Se):Se=e[43];const se=Se;let we,Ae;e[44]!==c||e[45]!==b||e[46]!==f?(we=()=>{if(!c||b!=="nav"||f==="home"||v.current===f)return;const Ce=$i(f);!Ce||Ce.slug==="home"||(v.current=f,h(Ce.kind==="split"?"page-sidebar":"page-content"))},Ae=[c,b,f],e[44]=c,e[45]=b,e[46]=f,e[47]=we,e[48]=Ae):(we=e[47],Ae=e[48]),l.useEffect(we,Ae);const ve=c&&b!=="nav";let ye,Ie,he,me,Ee,Ve,Y;if(e[49]!==K||e[50]!==fe||e[51]!==c||e[52]!==a||e[53]!==b||e[54]!==n||e[55]!==W||e[56]!==se||e[57]!==f||e[58]!==ve||e[59]!==V||e[60]!==i){const Ce=ll();let ge;e[68]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>{h("nav")},e[68]=ge):ge=e[68];const O=ge;let X;e[69]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{h("page-sidebar")},e[69]=X):X=e[69];const G=X;let Te;e[70]!==fe||e[71]!==W||e[72]!==f||e[73]!==V||e[74]!==i?(Te=()=>s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 pt-4 pb-2 px-2",children:V.map(de=>{const Fe=f===de.slug,rt=nu(de.slug);return rt?s.jsx(St,{children:s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>W(de.slug),"aria-current":Fe?"page":void 0,className:ue("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",Fe?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(I,{name:rt,className:"h-4 w-4 shrink-0"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:fe(de.slug)}),(de.slug==="voice"||de.slug==="tunnel")&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:i("settings.view.badge.beta")})]})]})})},de.slug):null})})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-sidebar px-2 py-1 space-y-0.5",children:!N.isVSCode&&s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",className:ue("flex h-7 w-full items-center gap-2 rounded-md px-2 overflow-hidden whitespace-nowrap","text-sm font-semibold text-sidebar-foreground/90","hover:text-sidebar-foreground hover:bg-interactive-hover"),onClick:n4,children:[s.jsx(I,{name:"restart",className:"h-4 w-4 shrink-0"}),s.jsx("span",{children:i("settings.view.actions.reloadOpenCode")})]})}),s.jsx(Ct,{children:i("settings.view.actions.reloadOpenCodeTooltip")})]})})})]}),e[70]=fe,e[71]=W,e[72]=f,e[73]=V,e[74]=i,e[75]=Te):Te=e[75],he=Te;let le;e[76]!==K||e[77]!==b||e[78]!==se||e[79]!==he||e[80]!==f?(le=()=>{if(b==="nav")return s.jsx("div",{className:ue("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(Qs,{children:he()})})});if(!K)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(K.kind!=="split"){const Fe=se(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Qs,{children:Fe})})}return s.jsx("div",{className:ue("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(Qs,{children:oe(f,{onItemSelect:()=>h("page-content")})})})}const de=se(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Qs,{children:de})})},e[76]=K,e[77]=b,e[78]=se,e[79]=he,e[80]=f,e[81]=le):le=e[81],Ie=le;let We;e[82]!==K||e[83]!==W||e[84]!==se||e[85]!==f?(We=()=>!K||f==="home"?s.jsx(Fc,{onOpen:W}):K.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ue("w-[264px] min-w-[264px] border-r",N.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(Qs,{children:oe(f,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Qs,{children:se(f)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(Qs,{children:se(f)})}),e[82]=K,e[83]=W,e[84]=se,e[85]=f,e[86]=We):We=e[86],ye=We,me=D,Ee="true",e[87]===Symbol.for("react.memo_cache_sentinel")?(Ve=ue("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[87]=Ve):Ve=e[87],Y=c?s.jsxs("div",{className:ue("flex items-center gap-2 px-3 py-2 border-b","bg-background"),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("button",{type:"button",onClick:ve?O:n,"aria-label":i(ve?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})}),s.jsx("div",{className:"min-w-0 flex-1 typography-ui-label font-medium text-foreground truncate",children:b==="nav"?i("settings.view.home.title"):K?fe(K.slug):i("settings.view.home.title")}),b==="page-content"&&K?.kind==="split"&&s.jsx("button",{type:"button",onClick:G,"aria-label":i("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"list-unordered",className:"h-5 w-5"})}),n&&s.jsx("button",{type:"button",onClick:n,"aria-label":i("settings.view.actions.closeSettings"),title:i("settings.view.actions.closeSettingsWithShortcut",{shortcut:Ce}),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[ve&&s.jsx("div",{className:ue("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:O,"aria-label":i("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&s.jsx("div",{className:ue("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("settings.view.actions.closeSettings"),title:i("settings.view.actions.closeSettingsWithShortcut",{shortcut:Ce}),className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})})]}),e[49]=K,e[50]=fe,e[51]=c,e[52]=a,e[53]=b,e[54]=n,e[55]=W,e[56]=se,e[57]=f,e[58]=ve,e[59]=V,e[60]=i,e[61]=ye,e[62]=Ie,e[63]=he,e[64]=me,e[65]=Ee,e[66]=Ve,e[67]=Y}else ye=e[61],Ie=e[62],he=e[63],me=e[64],Ee=e[65],Ve=e[66],Y=e[67];let ke;e[88]!==re||e[89]!==ce||e[90]!==c||e[91]!==k||e[92]!==x||e[93]!==ye||e[94]!==Ie||e[95]!==he||e[96]!==i?(ke=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?Ie():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:ue("relative flex h-full min-h-0 flex-col overflow-hidden border-r",P?"bg-sidebar":N.isVSCode?"bg-background":"bg-sidebar",k?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${x}px`,minWidth:`${x}px`,borderColor:"var(--interactive-border)"},children:[s.jsx("div",{className:ue("absolute right-0 top-0 z-20 h-full w-[6px] -mr-[3px] cursor-col-resize","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",k?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:re,onKeyDown:ce,role:"separator","aria-orientation":"vertical","aria-valuemin":wd,"aria-valuemax":jd,"aria-valuenow":x,"aria-label":i("settings.view.actions.resizeNavigation")}),s.jsx(Qs,{children:he()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:ye()})]})}),e[88]=re,e[89]=ce,e[90]=c,e[91]=k,e[92]=x,e[93]=ye,e[94]=Ie,e[95]=he,e[96]=i,e[97]=ke):ke=e[97];let Be;return e[98]!==me||e[99]!==Ee||e[100]!==Ve||e[101]!==Y||e[102]!==ke?(Be=s.jsxs("div",{ref:me,"data-settings-view":Ee,className:Ve,children:[Y,ke]}),e[98]=me,e[99]=Ee,e[100]=Ve,e[101]=Y,e[102]=ke,e[103]=Be):Be=e[103],Be};function JC(t){return t.settingsPage}function QC(t){return t.isSettingsDialogOpen}function XC(t){return t.setSettingsPage}function ZC(t){return t.slug!=="home"}function e4(t,e){return[t,e]}function t4(t){return t.activeProjectId}function s4(t,e){switch(t){case"projects":return s.jsx(p3,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(F3,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(zS,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(ek,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(ck,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(Lk,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(Q3,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(r5,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(j5,{onItemSelect:e.onItemSelect});default:return null}}function n4(){ai({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const r4=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:YC,getSettingsNavIcon:nu},Symbol.toStringTag,{value:"Module"})),Nd=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},a4=()=>{const t=ot.c(162),{t:e}=pt(),n=De(i4),r=De(o4),a=De(l4),i=De(c4),o=De(d4),c=De(u4),d=De(m4),p=De(p4),m=De(f4),u=De(h4),f=De(g4),b=De(x4),h=Lt(b4),v=Lt(y4),x=Ia(v4),g=_s(w4),w=Ts(j4),y=Lr(),k=Ld(N4),{files:A,git:j}=On(),S=Zs(S4),{isMobile:D}=nn();let E;t[0]!==y?(E=y?Nd(y):null,t[0]=y,t[1]=E):E=t[1];const P=E,[C,N]=l.useState(""),T=Ml(C,200);let M;t[2]!==T?(M=T.trim(),t[2]=T,t[3]=M):M=t[3];const F=M;let _;t[4]!==C?(_=C.trim(),t[4]=C,t[5]=_):_=t[5];const B=_;let V,$;t[6]!==n?(V=()=>{n&&N("")},$=[n],t[6]=n,t[7]=V,t[8]=$):(V=t[7],$=t[8]),l.useEffect(V,$);let z,Q;t[9]!==x||t[10]!==S||t[11]!==j||t[12]!==n?(z=()=>{if(!n||!j)return;const qe=setTimeout(()=>{const ze=new Set;for(const st of x){const yt=Vi(st);!yt||ze.has(yt)||(ze.add(yt),S(yt,j))}},0);return()=>clearTimeout(qe)},Q=[n,x,j,S],t[9]=x,t[10]=S,t[11]=j,t[12]=n,t[13]=z,t[14]=Q):(z=t[13],Q=t[14]),l.useEffect(z,Q);let L;t[15]!==r?(L=()=>r(!1),t[15]=r,t[16]=L):L=t[16];const J=L;let ee;t[17]!==J?(ee=qe=>()=>{J(),qe()},t[17]=J,t[18]=ee):ee=t[18];const re=ee;let q;t[19]!==w?.id||t[20]!==w?.path||t[21]!==g||t[22]!==D||t[23]!==u||t[24]!==h||t[25]!==re||t[26]!==a||t[27]!==c||t[28]!==i||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(q=()=>{const qe=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(I,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:re(()=>{a("chat"),c(!1),h()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(I,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:re(k4)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:re(C4)},{id:"toggle-sidebar",title:e(D?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(I,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(D?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:re(()=>{if(D){const{isSessionSwitcherOpen:ze}=De.getState();c(!ze)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(I,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:re(()=>p())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(I,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:re(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(I,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:re(()=>{g&&u(g)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(I,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:re(()=>i(!0))}];return Dd()&&qe.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(I,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:re(()=>{al("desktop_open_draft_mini_chat_window",{directory:Nd(g||w?.path||""),projectId:w?.id??null}).catch(I4)})}),qe},t[19]=w?.id,t[20]=w?.path,t[21]=g,t[22]=D,t[23]=u,t[24]=h,t[25]=re,t[26]=a,t[27]=c,t[28]=i,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=q):q=t[33],w?.id,w?.path;let ce;t[34]!==q?(ce=q(),t[34]=q,t[35]=ce):ce=t[35];const ae=ce;let R;t[36]===Symbol.for("react.memo_cache_sentinel")?(R=dn(),t[36]=R):R=t[36];const U=R;let W;t[37]===Symbol.for("react.memo_cache_sentinel")?(W={isVSCode:ln(),isWeb:!U&&Hr(),isDesktop:U},t[37]=W):W=t[37];const Z=W;let K;if(t[38]!==re||t[39]!==i||t[40]!==o){let qe;t[42]===Symbol.for("react.memo_cache_sentinel")?(qe=ze=>ze.isAvailable?ze.isAvailable(Z):!0,t[42]=qe):qe=t[42],K=Zd.filter(P4).filter(qe).map(ze=>{const st=nu(ze.slug)??"settings-3",yt=(ze.keywords??[]).join(" ");return{id:`settings:${ze.slug}`,title:ze.title,icon:s.jsx(I,{name:st,className:"mr-2 h-4 w-4"}),searchText:`${ze.title} ${ze.group} ${yt}`,onSelect:re(()=>{o(ze.slug),i(!0)})}}),t[38]=re,t[39]=i,t[40]=o,t[41]=K}else K=t[41];const ie=K,Ne=A4;let ne;if(t[43]!==x){let qe;t[45]===Symbol.for("react.memo_cache_sentinel")?(qe=(ze,st)=>Ne(st)-Ne(ze),t[45]=qe):qe=t[45],ne=[...x].sort(qe),t[43]=x,t[44]=ne}else ne=t[44];const fe=ne,pe=ih(),je=Lt(D4);let oe;t[46]!==pe||t[47]!==je?(oe=(qe,ze)=>{const st=je.get(qe);return st?.branch?st.branch.trim()||null:ze&&pe.get(ze)?.trim()||null},t[46]=pe,t[47]=je,t[48]=oe):oe=t[48];const Se=oe;let se;t[49]===Symbol.for("react.memo_cache_sentinel")?(se=[],t[49]=se):se=t[49];const[we,Ae]=l.useState(se),[ve,ye]=l.useState(!1);let Ie,he;t[50]!==P||t[51]!==n||t[52]!==k||t[53]!==F?(Ie=()=>{if(!n){Ae([]),ye(!1);return}if(!P||F.length===0){Ae([]),ye(!1);return}let qe=!1;return ye(!0),k(P,F,10,{type:"file"}).then(ze=>{qe||Ae(ze.map(T4))}).catch(()=>{qe||Ae([])}).finally(()=>{qe||ye(!1)}),()=>{qe=!0}},he=[n,P,F,k],t[50]=P,t[51]=n,t[52]=k,t[53]=F,t[54]=Ie,t[55]=he):(Ie=t[54],he=t[55]),l.useEffect(Ie,he);const me=B.length>0;let Ee;e:{if(!me){let ze;t[56]!==ae?(ze=ae.map(M4),t[56]=ae,t[57]=ze):ze=t[57],Ee=ze;break e}let qe;t[58]!==ae||t[59]!==B?(qe=wo(ae,B,E4,{limit:7,noFuzzy:!0}),t[58]=ae,t[59]=B,t[60]=qe):qe=t[60],Ee=qe}const Ve=Ee;let Y;e:{if(!me){let ze;t[61]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[61]=ze):ze=t[61],Y=ze;break e}let qe;t[62]!==B||t[63]!==ie?(qe=wo(ie,B,R4,{limit:7,noFuzzy:!0}),t[62]=B,t[63]=ie,t[64]=qe):qe=t[64],Y=qe}const ke=Y;let Be;e:{if(!me){let ze;t[65]!==fe?(ze=fe.slice(0,5).map(F4),t[65]=fe,t[66]=ze):ze=t[66],Be=ze;break e}let qe;t[67]!==B||t[68]!==fe?(qe=wo(fe,B,O4,{limit:7,threshold:.2}),t[67]=B,t[68]=fe,t[69]=qe):qe=t[69],Be=qe}const Ce=Be;let ge;e:{if(!me||we.length===0){let ze;t[70]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[70]=ze):ze=t[70],ge=ze;break e}let qe;t[71]!==we||t[72]!==B?(qe=wo(we,B,L4,{limit:10,threshold:.4}),t[71]=we,t[72]=B,t[73]=qe):qe=t[73],ge=qe}const O=ge;let X,G,Te,le,We,de,Fe,rt,Oe,Ye,Ge,it,Qe,at,nt;if(t[74]!==Se||t[75]!==J||t[76]!==P||t[77]!==A||t[78]!==me||t[79]!==n||t[80]!==f||t[81]!==C||t[82]!==Ve||t[83]!==O||t[84]!==Ce||t[85]!==ke||t[86]!==r||t[87]!==v||t[88]!==b||t[89]!==e){const qe=Ve.map($4),ze=ke.map(B4),st=Ce.map(_4);nt=me?O.map(z4):[];let yt;e:{if(!me){yt=["commands","sessions"];break e}const Gt=V4,Ke=[{key:"commands",score:Gt(Ve)},{key:"settings",score:Gt(ke)},{key:"sessions",score:Gt(Ce)},{key:"files",score:Gt(O)}];Ke.sort(U4),yt=Ke.map(W4)}const Mt=yt;let Bt;t[105]!==J||t[106]!==v?(Bt=Gt=>{J(),v(Gt.id,Vi(Gt))},t[105]=J,t[106]=v,t[107]=Bt):Bt=t[107];const ft=Bt;let It;t[108]!==J||t[109]!==P||t[110]!==A||t[111]!==f?(It=async Gt=>{if(!P)return;const Ke=await Qd(A,Gt);if(!Ke.ok){H.error(Xd(Ke.reason));return}f(P,Gt),J()},t[108]=J,t[109]=P,t[110]=A,t[111]=f,t[112]=It):It=t[112];const ss=It;let _t;t[113]!==b?(_t=Gt=>Il(Wr(Gt,b)),t[113]=b,t[114]=_t):_t=t[114];const qt=_t;le=ps,it=n,Qe=r;let ct;t[115]!==e?(ct=e("commandPalette.title"),t[115]=e,t[116]=ct):ct=t[116];let jt;t[117]!==ct?(jt=s.jsx(gs,{children:ct}),t[117]=ct,t[118]=jt):jt=t[118];let as;t[119]!==e?(as=e("commandPalette.description"),t[119]=e,t[120]=as):as=t[120];let xs;t[121]!==as?(xs=s.jsx(Ps,{children:as}),t[121]=as,t[122]=xs):xs=t[122],t[123]!==jt||t[124]!==xs?(at=s.jsxs(vs,{className:"sr-only",children:[jt,xs]}),t[123]=jt,t[124]=xs,t[125]=at):at=t[125],Te=ms,Ye="overflow-hidden p-0",Ge=!0,G=Oa,Fe=!1,rt="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let ws;t[126]!==e?(ws=e("commandPalette.input.placeholder"),t[126]=e,t[127]=ws):ws=t[127],t[128]!==C||t[129]!==ws?(Oe=s.jsx(oa,{value:C,onValueChange:N,placeholder:ws}),t[128]=C,t[129]=ws,t[130]=Oe):Oe=t[130],X=La;let As;t[131]!==e?(As=e("commandPalette.empty.noResults"),t[131]=e,t[132]=As):As=t[132],t[133]!==As?(We=s.jsx($a,{children:As}),t[133]=As,t[134]=We):We=t[134],de=Mt.map(Gt=>Gt==="commands"&&qe.length>0?s.jsx(Rn,{children:qe.map(Ke=>s.jsxs(kn,{value:Ke.id,onSelect:Ke.onSelect,children:[Ke.icon,s.jsx("span",{children:Ke.title}),Ke.shortcutId?s.jsx(M1,{children:qt(Ke.shortcutId)}):null]},Ke.id))},"commands"):Gt==="settings"&&ze.length>0?s.jsx(Rn,{children:ze.map(K4)},"settings"):Gt==="sessions"&&st.length>0?s.jsx(Rn,{children:st.map(Ke=>{const Pt=Ke.title||e("commandPalette.session.untitled"),Ot=Vi(Ke),Nt=Se(Ke.id,Ot);return s.jsxs(kn,{value:`session:${Ke.id}`,onSelect:()=>ft(Ke),children:[s.jsx(I,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Pt}),Nt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:Nt})]}):null]},Ke.id)})},"sessions"):Gt==="files"&&nt.length>0?s.jsx(Rn,{children:nt.map(Ke=>{const Pt=ly(Ke.relativePath||Ke.name,{maxLength:80});return s.jsxs(kn,{value:`file:${Ke.path}`,onSelect:()=>{ss(Ke.path)},children:[s.jsx(vr,{filePath:Ke.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Ke.relativePath,children:Pt})]},`file:${Ke.path}`)})},"files"):null),t[74]=Se,t[75]=J,t[76]=P,t[77]=A,t[78]=me,t[79]=n,t[80]=f,t[81]=C,t[82]=Ve,t[83]=O,t[84]=Ce,t[85]=ke,t[86]=r,t[87]=v,t[88]=b,t[89]=e,t[90]=X,t[91]=G,t[92]=Te,t[93]=le,t[94]=We,t[95]=de,t[96]=Fe,t[97]=rt,t[98]=Oe,t[99]=Ye,t[100]=Ge,t[101]=it,t[102]=Qe,t[103]=at,t[104]=nt}else X=t[90],G=t[91],Te=t[92],le=t[93],We=t[94],de=t[95],Fe=t[96],rt=t[97],Oe=t[98],Ye=t[99],Ge=t[100],it=t[101],Qe=t[102],at=t[103],nt=t[104];let be;t[135]!==me||t[136]!==ve||t[137]!==e||t[138]!==nt?(be=me&&ve&&nt.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=me,t[136]=ve,t[137]=e,t[138]=nt,t[139]=be):be=t[139];let He;t[140]!==X||t[141]!==We||t[142]!==de||t[143]!==be?(He=s.jsxs(X,{children:[We,de,be]}),t[140]=X,t[141]=We,t[142]=de,t[143]=be,t[144]=He):He=t[144];let _e;t[145]!==G||t[146]!==Fe||t[147]!==rt||t[148]!==Oe||t[149]!==He?(_e=s.jsxs(G,{shouldFilter:Fe,className:rt,children:[Oe,He]}),t[145]=G,t[146]=Fe,t[147]=rt,t[148]=Oe,t[149]=He,t[150]=_e):_e=t[150];let tt;t[151]!==Te||t[152]!==Ye||t[153]!==Ge||t[154]!==_e?(tt=s.jsx(Te,{className:Ye,showCloseButton:Ge,children:_e}),t[151]=Te,t[152]=Ye,t[153]=Ge,t[154]=_e,t[155]=tt):tt=t[155];let ut;return t[156]!==le||t[157]!==it||t[158]!==Qe||t[159]!==at||t[160]!==tt?(ut=s.jsxs(le,{open:it,onOpenChange:Qe,children:[at,tt]}),t[156]=le,t[157]=it,t[158]=Qe,t[159]=at,t[160]=tt,t[161]=ut):ut=t[161],ut};function i4(t){return t.isCommandPaletteOpen}function o4(t){return t.setCommandPaletteOpen}function l4(t){return t.setActiveMainTab}function c4(t){return t.setSettingsDialogOpen}function d4(t){return t.setSettingsPage}function u4(t){return t.setSessionSwitcherOpen}function m4(t){return t.toggleSidebar}function p4(t){return t.toggleRightSidebar}function f4(t){return t.toggleBottomTerminal}function h4(t){return t.openContextOverview}function g4(t){return t.openContextFile}function x4(t){return t.shortcutOverrides}function b4(t){return t.openNewSessionDraft}function y4(t){return t.setCurrentSession}function v4(t){return t.activeSessions}function w4(t){return t.currentDirectory}function j4(t){return t.getActiveProject()}function N4(t){return t.searchFiles}function S4(t){return t.ensureStatus}function k4(){oh()}function C4(){wr.requestDirectoryDialog()}function I4(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function P4(t){return t.slug!=="home"}function A4(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function D4(t){return t.worktreeMetadata}function T4(t){return{path:Nd(t.path),name:t.name,relativePath:t.relativePath}}function M4(t){return{item:t,score:0}}function E4(t){return t.searchText}function R4(t){return t.searchText}function F4(t){return{item:t,score:0}}function O4(t){return t.title||""}function L4(t){return t.name}function $4(t){return t.item}function B4(t){return t.item}function _4(t){return t.item}function z4(t){return t.item}function V4(t){return t.length?t[0].score:1/0}function U4(t,e){return t.score-e.score}function W4(t){return t.key}function K4(t){return s.jsxs(kn,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Kp=(t,e,n)=>dy(t)?Il(Wr(t,n)):e,H4=()=>{const t=ot.c(68),{t:e}=pt(),n=De(G4),r=De(q4),a=De(Y4);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=cy(),t[0]=i):i=t[0];const o=i;let c,d,p,m,u,f,b,h,v;if(t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==e){const F=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${o} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${o} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];d=ps,h=n,v=r,c=ms,f="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let _;t[14]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(I,{name:"settings-3",className:"h-5 w-5"}),t[14]=_):_=t[14];let B;t[15]!==e?(B=e("helpDialog.title"),t[15]=e,t[16]=B):B=t[16];let V;t[17]!==B?(V=s.jsxs(gs,{className:"flex items-center gap-2",children:[_,B]}),t[17]=B,t[18]=V):V=t[18];let $;t[19]!==e?($=e("helpDialog.description"),t[19]=e,t[20]=$):$=t[20];let z;t[21]!==$?(z=s.jsx(Ps,{children:$}),t[21]=$,t[22]=z):z=t[22],t[23]!==V||t[24]!==z?(b=s.jsxs(vs,{children:[V,z]}),t[23]=V,t[24]=z,t[25]=b):b=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",p="space-y-4",m=F.map(Q=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(Q.categoryKey)}),s.jsx("div",{className:"space-y-1",children:Q.items.map(L=>{const J=L.id?Kp(L.id,Array.isArray(L.keys)?L.keys[0]:L.keys,a):Array.isArray(L.keys)?L.keys:L.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[L.icon&&s.jsx(I,{name:L.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(L.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(J)?J:[J]).map((ee,re)=>s.jsxs(l.Fragment,{children:[re>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:ee})]},`${ee}-${re}`))})]},L.id||L.descriptionKey)})})]},Q.categoryKey)),t[1]=n,t[2]=r,t[3]=a,t[4]=e,t[5]=c,t[6]=d,t[7]=p,t[8]=m,t[9]=u,t[10]=f,t[11]=b,t[12]=h,t[13]=v}else c=t[5],d=t[6],p=t[7],m=t[8],u=t[9],f=t[10],b=t[11],h=t[12],v=t[13];let x;t[26]!==p||t[27]!==m?(x=s.jsx("div",{className:p,children:m}),t[26]=p,t[27]=m,t[28]=x):x=t[28];let g;t[29]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(I,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=g):g=t[29];let w;t[30]!==e?(w=e("helpDialog.proTips.title"),t[30]=e,t[31]=w):w=t[31];let y;t[32]!==w?(y=s.jsx("p",{className:"font-medium mb-1",children:w}),t[32]=w,t[33]=y):y=t[33];let k;t[34]!==a||t[35]!==e?(k=e("helpDialog.proTips.commandPalette",{shortcut:Kp("open_command_palette",`${o} P`,a)}),t[34]=a,t[35]=e,t[36]=k):k=t[36];let A;t[37]!==k?(A=s.jsxs("li",{children:["• ",k]}),t[37]=k,t[38]=A):A=t[38];let j;t[39]!==e?(j=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=j):j=t[40];let S;t[41]!==j?(S=s.jsxs("li",{children:["• ",j]}),t[41]=j,t[42]=S):S=t[42];let D;t[43]!==e?(D=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=D):D=t[44];let E;t[45]!==D?(E=s.jsxs("li",{children:["• ",D]}),t[45]=D,t[46]=E):E=t[46];let P;t[47]!==A||t[48]!==S||t[49]!==E?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[A,S,E]}),t[47]=A,t[48]=S,t[49]=E,t[50]=P):P=t[50];let C;t[51]!==y||t[52]!==P?(C=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[g,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[y,P]})]})}),t[51]=y,t[52]=P,t[53]=C):C=t[53];let N;t[54]!==C||t[55]!==u||t[56]!==x?(N=s.jsxs("div",{className:u,children:[x,C]}),t[54]=C,t[55]=u,t[56]=x,t[57]=N):N=t[57];let T;t[58]!==c||t[59]!==N||t[60]!==f||t[61]!==b?(T=s.jsxs(c,{className:f,children:[b,N]}),t[58]=c,t[59]=N,t[60]=f,t[61]=b,t[62]=T):T=t[62];let M;return t[63]!==d||t[64]!==T||t[65]!==h||t[66]!==v?(M=s.jsx(d,{open:h,onOpenChange:v,children:T}),t[63]=d,t[64]=T,t[65]=h,t[66]=v,t[67]=M):M=t[67],M};function G4(t){return t.isHelpDialogOpen}function q4(t){return t.setHelpDialogOpen}function Y4(t){return t.shortcutOverrides}const J4=()=>{const t=ot.c(32),{t:e}=pt(),n=De(Q4),r=De(X4),a=De(Z4);let i;t[0]!==a||t[1]!==e?(i=async()=>{if(!a)return;if((await An(a)).ok){H.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}H.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=a,t[1]=e,t[2]=i):i=t[2];const o=i;let c;t[3]!==e?(c=e("openCodeStatusDialog.title"),t[3]=e,t[4]=c):c=t[4];let d;t[5]!==c?(d=s.jsx(gs,{children:c}),t[5]=c,t[6]=d):d=t[6];let p;t[7]!==e?(p=e("openCodeStatusDialog.description"),t[7]=e,t[8]=p):p=t[8];let m;t[9]!==p?(m=s.jsx(Ps,{children:p}),t[9]=p,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(vs,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let f;t[14]!==e?(f=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=f):f=t[15];let b;t[16]!==o||t[17]!==f?(b=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:o,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:f})}),t[16]=o,t[17]=f,t[18]=b):b=t[18];let h;t[19]!==a||t[20]!==e?(h=a||e("openCodeStatusDialog.empty.noData"),t[19]=a,t[20]=e,t[21]=h):h=t[21];let v;t[22]!==h?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:h}),t[22]=h,t[23]=v):v=t[23];let x;t[24]!==u||t[25]!==b||t[26]!==v?(x=s.jsxs(ms,{className:"max-w-2xl",children:[u,b,v]}),t[24]=u,t[25]=b,t[26]=v,t[27]=x):x=t[27];let g;return t[28]!==n||t[29]!==r||t[30]!==x?(g=s.jsx(ps,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=g):g=t[31],g};function Q4(t){return t.isOpenCodeStatusDialogOpen}function X4(t){return t.setOpenCodeStatusDialogOpen}function Z4(t){return t.openCodeStatusText}const eI=180,Hp=600,tI=1,sI=6,nI=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const a=l.useRef(new Map),i=l.useRef([]),o=l.useRef(new Set),c=l.useCallback(()=>{if(!(typeof window>"u"))for(;o.current.size<tI&&i.current.length>0;){const p=i.current.shift();if(!p)break;Lt.getState().currentSessionId!==p&&(Eu(p).renderable||(o.current.add(p),r(p).catch(()=>{}).finally(()=>{o.current.delete(p),c()})))}},[r]),d=l.useCallback(p=>{if(!p||p===t||typeof window>"u"||Eu(p).renderable||o.current.has(p)||i.current.includes(p))return;i.current.length>=sI&&i.current.shift();const m=a.current.get(p);m!==void 0&&window.clearTimeout(m);const u=window.setTimeout(()=>{a.current.delete(p),i.current.push(p),c()},eI);a.current.set(p,u)},[t,c]);l.useEffect(()=>{if(!t||e.length===0)return;const p=window.setTimeout(()=>{const m=e.findIndex(u=>u.id===t);m<0||(d(e[m-1]?.id),d(e[m+1]?.id))},Hp);return()=>window.clearTimeout(p)},[t,d,e]),l.useEffect(()=>{if(!t||n.length===0)return;const p=window.setTimeout(()=>{const m=n.indexOf(t);m<0||(d(n[m-1]),d(n[m+1]))},Hp);return()=>window.clearTimeout(p)},[t,n,d]),l.useEffect(()=>{const p=a.current;return()=>{p.forEach(m=>{clearTimeout(m)}),p.clear(),i.current=[]}},[])};function Gp(t){const{localBranches:e,remoteBranches:n,query:r}=t,a=r.trim();if(!a)return{matching:[],otherLocal:e,otherRemote:n};const i=Ru(e,a,m=>m),o=Ru(n,a,m=>m),c=[],d=i.other,p=o.other;for(const m of i.matching)c.push({label:m,value:m,source:"local"});for(const m of o.matching)c.push({label:m,value:`remotes/${m}`,source:"remote"});return c.sort((m,u)=>{const f=m.label.localeCompare(u.label,void 0,{sensitivity:"accent"});return f!==0?f:m.source!==u.source?m.source.localeCompare(u.source):m.value.localeCompare(u.value)}),{matching:c,otherLocal:d,otherRemote:p}}function rI({open:t,onOpenChange:e,onSelect:n}){const{t:r}=pt(),a=De(pe=>pe.isMobile),{github:i}=On(),o=zn(pe=>pe.status),c=zn(pe=>pe.hasChecked),d=De(pe=>pe.setSettingsDialogOpen),p=De(pe=>pe.setSettingsPage),m=Ts(pe=>pe.getActiveProject()),u=m?.path??null,f=$e.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[b,h]=$e.useState("issues"),[v,x]=$e.useState(""),[g,w]=$e.useState([]),[y,k]=$e.useState([]),[A,j]=$e.useState(!1),[S,D]=$e.useState(!1),[E,P]=$e.useState(null),[C,N]=$e.useState(null),[T,M]=$e.useState(null),[F,_]=$e.useState(!1),[B,V]=$e.useState(new Map),[$,z]=$e.useState(1),[Q,L]=$e.useState(!1),J=$e.useCallback(async()=>{if(!(!u||!i)&&!(c&&o?.connected===!1)){j(!0),P(null),z(1),L(!1);try{if(b==="issues"&&i.issuesList){const pe=await i.issuesList(u,{page:1});pe.connected===!1?(P(r("session.githubIntegration.error.notConnected")),w([])):(w(pe.issues??[]),z(pe.page??1),L(!!pe.hasMore))}else if(b==="prs"&&i.prsList){const pe=await i.prsList(u,{page:1});pe.connected===!1?(P(r("session.githubIntegration.error.notConnected")),k([])):(k(pe.prs??[]),z(pe.page??1),L(!!pe.hasMore))}}catch(pe){P(pe instanceof Error?pe.message:r("session.githubIntegration.error.loadDataFailed"))}finally{j(!1)}}},[u,i,c,o,b,r]),ee=$e.useCallback(async()=>{if(!(!u||!i)&&!(A||S)&&Q){D(!0);try{const pe=$+1;if(b==="issues"&&i.issuesList){const je=await i.issuesList(u,{page:pe});je.connected!==!1&&(w(oe=>[...oe,...je.issues??[]]),z(je.page??pe),L(!!je.hasMore))}else if(b==="prs"&&i.prsList){const je=await i.prsList(u,{page:pe});je.connected!==!1&&(k(oe=>[...oe,...je.prs??[]]),z(je.page??pe),L(!!je.hasMore))}}catch{}finally{D(!1)}}},[u,i,b,$,Q,A,S]);$e.useEffect(()=>{if(!t){h("issues"),x(""),w([]),k([]),N(null),M(null),_(!1),P(null),V(new Map),z(1),L(!1);return}J()},[t,J]);const re=$e.useCallback(async pe=>{if(!(!f||!pe)&&!B.has(pe))try{const oe=(await lh(f,{mode:"new",branchName:pe,worktreeName:pe})).errors.find(Se=>Se.code==="branch_in_use");V(Se=>new Map(Se).set(pe,{isValid:!oe,error:oe?r(oe.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{V(je=>new Map(je).set(pe,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[f,B,r]);$e.useEffect(()=>{!t||b!=="prs"||y.forEach(pe=>{pe.head&&re(pe.head)})},[t,b,y,re]);const q=$e.useMemo(()=>{const pe=v.trim().toLowerCase();return pe?g.filter(je=>String(je.number)===pe.replace(/^#/,"")?!0:je.title.toLowerCase().includes(pe)):g},[g,v]),ce=$e.useMemo(()=>{const pe=v.trim().toLowerCase();return pe?y.filter(je=>String(je.number)===pe.replace(/^#/,"")?!0:je.title.toLowerCase().includes(pe)):y},[y,v]),ae=c&&o?.connected===!0,R=()=>{p("github"),d(!0)},U=pe=>{N(pe),M(null)},W=pe=>{M(pe),N(null)},Z=()=>{C?n({type:"issue",item:C}):T&&n({type:"pr",item:T,includeDiff:F}),e(!1)},K=()=>{N(null),M(null),_(!1)},ie=C||T&&B.get(T.head??"")?.isValid!==!1,Ne=pe=>pe.head?B.get(pe.head)?.isValid===!1:!0,ne=s.jsx(s.Fragment,{children:ae?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(I,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(Vt,{value:v,onChange:pe=>x(pe.target.value),placeholder:r(b==="issues"?"session.githubIntegration.search.issuesPlaceholder":"session.githubIntegration.search.prsPlaceholder"),className:"h-8 pl-9"})]}),s.jsx("div",{className:"mt-2 h-[300px] overflow-hidden",children:s.jsxs("div",{className:"h-full overflow-y-auto",children:[A&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),E&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[s.jsx(I,{name:"error-warning",className:"h-4 w-4"}),s.jsx("span",{className:"typography-small",children:E})]})}),!A&&!E&&b==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[q.length>0?q.map(pe=>s.jsx("button",{onClick:()=>U(pe),className:ue("w-full text-left px-2 py-1.5 rounded transition-colors",C?.number===pe.number?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",pe.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:pe.title}),pe.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block",children:[pe.sourceRepo.owner,"/",pe.sourceRepo.repo]}):null]})]})},`${pe.sourceRepo?.owner??""}-${pe.sourceRepo?.repo??""}-${pe.number}`)):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noIssuesFound")}),Q&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>{ee()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),S&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!A&&!E&&b==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[ce.length>0?ce.map(pe=>{const je=Ne(pe),oe=pe.head?B.get(pe.head):void 0;return s.jsx("button",{onClick:()=>!je&&W(pe),disabled:je,className:ue("w-full text-left px-2 py-1.5 rounded transition-colors",T?.number===pe.number?"bg-interactive-selection text-interactive-selection-foreground":je?"opacity-50 cursor-not-allowed":"hover:bg-interactive-hover"),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",pe.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:pe.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[pe.head," → ",pe.base]}),pe.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[pe.sourceRepo.owner,"/",pe.sourceRepo.repo]}):null,je&&oe?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:oe.error})]})]})]})},`${pe.sourceRepo?.owner??""}-${pe.sourceRepo?.repo??""}-${pe.number}`)}):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noPullRequestsFound")}),Q&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>{ee()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),S&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]})]})})]}):s.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 gap-4",children:[s.jsx(I,{name:"github",className:"h-12 w-12 text-muted-foreground"}),s.jsxs("div",{className:"text-center",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:r("session.githubIntegration.connect.title")}),s.jsx("p",{className:"typography-small text-muted-foreground mt-1",children:r("session.githubIntegration.connect.description")})]}),s.jsx(xe,{onClick:R,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),fe=s.jsxs("div",{className:ue("w-full",a?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:ue("flex items-center gap-4",a?"w-full justify-center order-1":"flex-1"),children:[!a&&(C||T)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate max-w-[150px]",children:C?r("session.githubIntegration.selected.issueNumber",{number:C.number}):r("session.githubIntegration.selected.prNumber",{number:T?.number??""})}),s.jsx("button",{onClick:K,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),b==="prs"&&T&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(ds,{checked:F,onChange:pe=>_(pe),ariaLabel:r("session.githubIntegration.includeDiffAria")}),s.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),s.jsxs("div",{className:ue("flex gap-2",a?"w-full order-2":"justify-end"),children:[s.jsx(xe,{variant:"outline",size:"sm",onClick:()=>e(!1),className:ue(a&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(xe,{size:"sm",onClick:Z,disabled:!ie,className:ue(a&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:a?s.jsx(Mr,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:ae?fe:void 0,renderHeader:pe=>s.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2 border-b border-border/40",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:r("session.githubIntegration.title")}),pe]}),s.jsx("div",{className:"w-full",children:s.jsx(Er,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:je=>{h(je),x("")},variant:"active-pill",layoutMode:"fit"})}),(C||T)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:C?r("session.githubIntegration.selected.issueNumber",{number:C.number}):r("session.githubIntegration.selected.prNumber",{number:T?.number??""})}),s.jsx("button",{onClick:K,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:ne}):s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(vs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(gs,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(I,{name:"github",className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(Er,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:pe=>{h(pe),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),ne,s.jsx(Us,{className:"mt-1",children:fe})]})})})}const Bi=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),Mn=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,"").split("/").join("-").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"").slice(0,80),qp="oc:lastWorktreeSourceBranch",aI=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",Yp=(t,e,n)=>{const r=Bi(t.head||"");if(!r)throw new Error("PR head branch is missing");if(e.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};const a=n.find(p=>{const m=p.indexOf("/");return m<=0||m>=p.length-1?!1:p.slice(m+1)===r});if(a){const p=a.indexOf("/"),m=a.slice(0,p);return{existingBranch:`remotes/${a}`,setUpstream:!0,upstreamRemote:m,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${m}/${r}`}}const i=String(t.headLabel||"").split(":")[0]?.trim(),o=t.headRepo?.owner||i||"pr-head",c=`pr-${aI(o)}`,d=t.headRepo?.sshUrl||t.headRepo?.cloneUrl||"";if(!d)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${c}/${r}`,setUpstream:!0,upstreamRemote:c,upstreamBranch:r,ensureRemoteName:c,ensureRemoteUrl:d,sourceLabel:`${c}/${r}`}},iI=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
|
|
178
|
-
${JSON.stringify(e,null,2)}`},oI=t=>`GitHub pull request context (JSON)
|
|
179
|
-
${JSON.stringify(t,null,2)}`;function lI({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=pt(),{github:a,git:i}=On(),o=De(de=>de.isMobile),c=zn(de=>de.status),d=zn(de=>de.hasChecked),p=Ts(de=>de.getActiveProject()),m=p?.path??null,u=$e.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[f,b]=$e.useState("new-branch"),[h,v]=$e.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,g]=$e.useState({selectedBranch:"",worktreeName:""}),w=Rd(m),y=ch(m),k=Zs(de=>de.fetchBranches),A=$e.useMemo(()=>w?.all?w.all.filter(de=>!de.startsWith("remotes/")).sort():[],[w]),j=$e.useMemo(()=>w?.all?w.all.filter(de=>de.startsWith("remotes/")).map(de=>de.replace(/^remotes\//,"")).sort():[],[w]),S=Lt(de=>de.availableWorktreesByProject),D=$e.useMemo(()=>{if(!m)return new Set;const de=S.get(m)??[];return new Set(de.map(Fe=>Fe.name))},[S,m]),E=$e.useCallback((de=10)=>{for(let Fe=0;Fe<de;Fe++){const rt=nc();if(!D.has(rt))return rt}return`${nc()}-${Date.now().toString(36).slice(-4)}`},[D]),[P,C]=$e.useState(!1),[N,T]=$e.useState(!1),[M,F]=$e.useState(!1),[_,B]=$e.useState(!1),[V,$]=$e.useState(!1),[z,Q]=$e.useState(""),[L,J]=$e.useState(""),ee=$e.useRef(null),re=$e.useRef(null),q=$e.useRef(null),ce=$e.useRef(null),ae=$e.useCallback(de=>{de.stopPropagation()},[]),R=$e.useCallback(de=>{let Fe=de;for(;Fe&&Fe!==document.body;){const{overflowY:rt}=window.getComputedStyle(Fe);if((rt==="auto"||rt==="scroll")&&Fe.scrollHeight>Fe.clientHeight)return Fe;Fe=Fe.parentElement}return null},[]),U=$e.useCallback(de=>{de&&(de.scrollTop=0)},[]),W=$e.useCallback(de=>{const Fe=de.current?.querySelector('[data-slot="command-list"]')??null;U(Fe)},[U]),Z=$e.useCallback(de=>{const Fe=R(de.current);U(Fe)},[R,U]),K=$e.useMemo(()=>Gp({localBranches:A,remoteBranches:j,query:z}),[A,j,z]),ie=$e.useMemo(()=>Gp({localBranches:A,remoteBranches:j,query:L}),[A,j,L]),Ne=z.trim().length>0,ne=L.trim().length>0,fe=K.matching.length>0,pe=ie.matching.length>0,je=!!(m&&i),oe=$e.useCallback(()=>{!m||!i||k(m,i)},[m,i,k]);$e.useEffect(()=>{!N&&!_&&Q("")},[N,_]),$e.useEffect(()=>{!M&&!V&&J("")},[M,V]),$e.useEffect(()=>{N&&W(ee),_&&Z(q)},[N,_,z,W,Z]),$e.useEffect(()=>{M&&W(re),V&&Z(ce)},[M,V,L,W,Z]);const[Se,se]=$e.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[we,Ae]=$e.useState(!1),[ve,ye]=$e.useState(null),Ie=$e.useCallback(()=>{const de=vt.getState(),Fe=de.getVisibleAgents();if(de.settingsDefaultAgent){const rt=Fe.find(Oe=>Oe.name===de.settingsDefaultAgent);if(rt)return rt.name}return Fe.find(rt=>rt.name==="build")?.name||Fe[0]?.name},[]),he=$e.useCallback(()=>{const de=vt.getState(),Fe=de.settingsDefaultModel;if(!Fe)return null;const rt=hi(Fe);if(!rt)return null;const{providerId:Oe,modelId:Ye}=rt;return de.getModelMetadata(Oe,Ye)?{providerID:Oe,modelID:Ye}:null},[]),me=$e.useCallback((de,Fe)=>{const rt=vt.getState(),Oe=rt.settingsDefaultVariant;if(!Oe)return;const it=rt.providers.find(Qe=>Qe.id===de)?.models.find(Qe=>Qe.id===Fe)?.variants;if(it&&Object.prototype.hasOwnProperty.call(it,Oe))return Oe},[]),Ee=$e.useCallback(de=>{const Fe=vt.getState();try{jo.getState().saveSessionModelSelection(de.sessionId,de.providerID,de.modelID)}catch{}if(de.agentName){try{Fe.setAgent(de.agentName)}catch{}try{jo.getState().saveSessionAgentSelection(de.sessionId,de.agentName)}catch{}try{jo.getState().saveAgentModelForSession(de.sessionId,de.agentName,de.providerID,de.modelID)}catch{}if(de.variant!==void 0){try{Fe.setCurrentVariant(de.variant)}catch{}try{jo.getState().saveAgentModelVariantForSession(de.sessionId,de.agentName,de.providerID,de.modelID,de.variant)}catch{}}}},[]),Ve=$e.useCallback(async de=>{if(!m||!a)return;const Fe=vt.getState(),rt=Pl.getState().lastUsedProvider,Oe=he(),Ye=Oe?.providerID||Fe.currentProviderId||rt?.providerID,Ge=Oe?.modelID||Fe.currentModelId||rt?.modelID,it=Ie()||Fe.currentAgentName||void 0;if(!Ye||!Ge){H.error(r("session.newWorktree.error.noModelSelected"));return}const Qe=me(Ye,Ge);if(Ee({sessionId:de.sessionId,providerID:Ye,modelID:Ge,agentName:it,variant:Qe}),de.issue){if(!a.issueGet||!a.issueComments)return;const at=await a.issueGet(m,de.issue.number);if(at.connected===!1||!at.repo||!at.issue)throw new Error("Failed to load issue context");const nt=await a.issueComments(m,de.issue.number);if(nt.connected===!1)throw new Error("Failed to load issue comments");const be=await bn("github.issue.review.visible",{issue_number:String(de.issue.number)}),He=await bn("github.issue.review.instructions"),_e=iI({repo:at.repo,issue:at.issue,comments:nt.comments??[]});await en.sendMessage({id:de.sessionId,providerID:Ye,modelID:Ge,agent:it,variant:Qe,text:be,additionalParts:[{text:He,synthetic:!0},{text:_e,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(de.pr){if(!a.prContext)return;const at=await a.prContext(m,de.pr.number,{includeDiff:de.includeDiff,includeCheckDetails:!1});if(at.connected===!1||!at.repo||!at.pr)throw new Error("Failed to load PR context");const nt=await bn("github.pr.review.visible",{pr_number:String(de.pr.number)}),be=await bn("github.pr.review.instructions"),He=oI(at);await en.sendMessage({id:de.sessionId,providerID:Ye,modelID:Ge,agent:it,variant:Qe,text:nt,additionalParts:[{text:be,synthetic:!0},{text:He,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromPr"))}},[Ee,a,m,Ie,he,me,r]),Y=f==="new-branch"?h:x;$e.useEffect(()=>{if(!w?.all||!m||h.sourceBranch)return;(async()=>{try{const Fe=await oo(m).catch(()=>null),rt=localStorage.getItem(qp),Oe=rt&&w.all?.includes(rt)?rt:Fe&&w.all?.includes(Fe)?Fe:w.all?.includes("main")?"main":w.all?.includes("master")?"master":w.all?.[0]||"";Oe&&v(Ye=>({...Ye,sourceBranch:Oe}))}catch{}})()},[w,m,h.sourceBranch]),$e.useEffect(()=>{if(!t)return;b("new-branch"),g({selectedBranch:"",worktreeName:""}),T(!1),F(!1),B(!1),$(!1),Q(""),J(""),se({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const de=E();v({branchName:de,worktreeName:de,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,E]),$e.useEffect(()=>{if(f!=="new-branch"||!h.isSyncingWorktreeName)return;const de=Bi(h.branchName),Fe=Mn(de);v(rt=>({...rt,worktreeName:Fe}))},[f,h.branchName,h.isSyncingWorktreeName]);const ke=$e.useCallback(async()=>{if(!u||!Se.touched||we)return;ve&&ve.abort();const de=new AbortController;ye(de),se(Fe=>({...Fe,isValidating:!0}));try{const Fe=f==="new-branch"?h.branchName:x.selectedBranch,rt=Y.worktreeName,Oe=Bi(Fe),Ye=Mn(rt);let Ge=null,it=null;if(Oe||(Ge=r("session.newWorktree.error.branchNameRequired")),Ye||(it=r("session.newWorktree.error.worktreeDirectoryRequired")),Oe&&Ye){const Qe=f==="new-branch"?h.linkedPr:null,at=Qe?Yp(Qe,A,j):null,nt=await lh(u,{mode:f==="existing-branch"||at?"existing":"new",branchName:Oe,worktreeName:Ye,existingBranch:at?.existingBranch??(f==="existing-branch"?Oe:void 0),...at?.ensureRemoteName?{ensureRemoteName:at.ensureRemoteName}:{},...at?.ensureRemoteUrl?{ensureRemoteUrl:at.ensureRemoteUrl}:{}});if(de.signal.aborted)return;nt.ok||nt.errors.forEach(be=>{if(be.code==="worktree_exists"){it=it??be.message;return}be.code.startsWith("branch_")&&(Ge=Ge??be.message)})}de.signal.aborted||se(Qe=>({...Qe,isValidating:!1,branchError:Ge,worktreeError:it}))}catch{de.signal.aborted||se(Fe=>({...Fe,isValidating:!1}))}},[u,f,h.branchName,h.linkedPr,x.selectedBranch,Y.worktreeName,A,j,Se.touched,ve,we,r]),Be=f==="new-branch"?h.branchName:x.selectedBranch;$e.useEffect(()=>{if(!t||!u||!Se.touched||we)return;const de=setTimeout(()=>{ke()},300);return()=>clearTimeout(de)},[Y.worktreeName,Be,t,u,ke,Se.touched,we]);const Ce=async()=>{if(!u||!m){H.error(r("session.newWorktree.error.noActiveProject"));return}se(Ye=>({...Ye,touched:!0}));const de=f==="new-branch"?h.branchName:x.selectedBranch,Fe=Y.worktreeName,rt=Bi(de),Oe=Mn(Fe);if(!rt){H.error(r("session.newWorktree.error.branchNameRequired"));return}if(!Oe){H.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}ve&&(ve.abort(),ye(null)),se(Ye=>({...Ye,isValidating:!1,branchError:null,worktreeError:null})),Ae(!0);try{const Ye=await zd(u),Ge=f==="new-branch"?h.linkedPr:null,it=h.sourceBranch;let Qe="";const at=(()=>{if(Ge){const qe=Yp(Ge,A,j);return Qe=qe.sourceLabel,{preferredName:rt||Oe,mode:"existing",branchName:rt,worktreeName:Oe,existingBranch:qe.existingBranch,setupCommands:Ye,setUpstream:qe.setUpstream,upstreamRemote:qe.upstreamRemote,upstreamBranch:qe.upstreamBranch,...qe.ensureRemoteName?{ensureRemoteName:qe.ensureRemoteName}:{},...qe.ensureRemoteUrl?{ensureRemoteUrl:qe.ensureRemoteUrl}:{}}}return Qe=f==="new-branch"?it:"",{preferredName:rt||Oe,mode:f==="existing-branch"?"existing":"new",branchName:f==="existing-branch"?void 0:rt,worktreeName:Oe,existingBranch:f==="existing-branch"?rt:void 0,setupCommands:Ye,...it&&f==="new-branch"?{startRef:it}:{}}})(),nt=await uy(m,at),be=await my(u,nt),He=f==="new-branch"?h.linkedIssue:null,_e=f==="new-branch"?h.linkedPr:null,tt=f==="new-branch"?h.includePrDiff:!1;let ut=null;if(He||_e){const qe=He?`#${He.number} ${He.title}`.trim():_e?`#${_e.number} ${_e.title}`.trim():r("session.newWorktree.newSessionTitle"),ze=await py(qe,be.path,null);if(!ze?.id)throw new Error("Failed to create session");ut=ze.id,fy(ze.id,qe).catch(()=>{});try{Lt.getState().initializeNewOpenChamberSession(ze.id,vt.getState().agents)}catch{}}h.sourceBranch&&f==="new-branch"&&!h.linkedPr&&localStorage.setItem(qp,h.sourceBranch),H.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${be.branch||be.name}${Qe?` ${r("session.newWorktree.fromSource",{source:Qe})}`:""}`})}),e(!1),ut?(n?.(be.path,{sessionId:ut}),Ve({sessionId:ut,issue:He,pr:_e,includeDiff:tt}).catch(qe=>{const ze=qe instanceof Error?qe.message:r("session.newWorktree.error.sendGitHubContextFailed");H.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:ze})})):n?.(be.path)}catch(Ye){const Ge=Ye instanceof Error?Ye.message:r("session.newWorktree.error.createWorktreeFailed");H.error(r("session.newWorktree.error.createWorktreeFailed"),{description:Ge})}finally{Ae(!1)}},ge=de=>{b(de),se(Fe=>({...Fe,touched:!1,branchError:null,worktreeError:null}))},O=de=>{if(!de){v(Fe=>({...Fe,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(de.type==="issue"){const Fe=de.item,rt=`issue-${Fe.number}-${nc()}`;v(Oe=>({...Oe,linkedIssue:Fe,linkedPr:null,includePrDiff:!1,branchName:rt,worktreeName:Mn(rt),isSyncingWorktreeName:!0}))}else if(de.type==="pr"){const Fe=de.item;v(rt=>({...rt,linkedPr:Fe,linkedIssue:null,includePrDiff:de.includeDiff??!1,branchName:Fe.head,worktreeName:Mn(Fe.head),isSyncingWorktreeName:!0}))}},X=d&&c?.connected===!0,Te=(f==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!Se.branchError&&!Se.worktreeError:!!Bi(h.branchName)&&!!h.worktreeName&&!Se.branchError&&!Se.worktreeError)&&!we,le=()=>{v(de=>({...de,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},We=s.jsxs("div",{className:ue("flex gap-2",o?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:ue("flex items-center gap-1.5 text-destructive",o?"w-full justify-center order-first":"mr-auto"),children:Se.touched&&(Se.branchError||Se.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:Se.branchError||Se.worktreeError})]})}),s.jsxs("div",{className:ue("flex gap-2",o&&"w-full"),children:[s.jsx(xe,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:we,className:ue(o&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(xe,{size:"sm",onClick:Ce,disabled:!Te||we,className:ue("gap-1.5",o&&"flex-1"),children:[we&&s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(we?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[o?s.jsxs(Mr,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:We,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Er,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(I,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:f,onSelect:de=>ge(de),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(xe,{variant:"outline",size:"sm",onClick:()=>B(!0),className:"flex-1 justify-between h-9",children:[s.jsx("span",{className:x.selectedBranch?"text-foreground":"text-muted-foreground",children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(I,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(xe,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:oe,disabled:!je||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"refresh",className:"size-4"})})]}),s.jsx(Mr,{open:_,title:r("session.newWorktree.selectBranch"),onClose:()=>B(!1),children:s.jsxs("div",{className:"space-y-4",ref:q,children:[s.jsx(Vt,{value:z,onChange:de=>Q(de.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):A.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[Ne&&fe&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:K.matching.map(de=>s.jsx("button",{onClick:()=>{g(Fe=>({...Fe,selectedBranch:de.value,worktreeName:Mn(de.label)})),se(Fe=>({...Fe,touched:!0})),B(!1)},className:ue("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===de.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de.label})},`${de.source}-${de.value}`))})]}),Ne&&!fe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),K.otherLocal.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(Ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:K.otherLocal.map(de=>s.jsx("button",{onClick:()=>{g(Fe=>({...Fe,selectedBranch:de,worktreeName:Mn(de)})),se(Fe=>({...Fe,touched:!0})),B(!1)},className:ue("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===de?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de})},de))})]}),K.otherRemote.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(Ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:K.otherRemote.map(de=>s.jsx("button",{onClick:()=>{g(Fe=>({...Fe,selectedBranch:`remotes/${de}`,worktreeName:Mn(de)})),se(Fe=>({...Fe,touched:!0})),B(!1)},className:ue("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${de}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de})},`remotes/${de}`))})]})]})]})})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&X&&s.jsxs(xe,{variant:"outline",size:"sm",onClick:()=>C(!0),className:"gap-1.5 h-7",children:[s.jsx(I,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Vt,{value:h.branchName,onChange:de=>{v(Fe=>({...Fe,branchName:de.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>se(de=>({...de,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:ue("h-8",Se.touched&&Se.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(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const de=Mn(f==="new-branch"?h.branchName:"");v(Fe=>({...Fe,worktreeName:de,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===Mn(h.branchName),className:ue("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===Mn(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(I,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Vt,{value:Y.worktreeName,onChange:de=>{f==="new-branch"?v(Fe=>({...Fe,worktreeName:de.target.value,isSyncingWorktreeName:!1})):g(Fe=>({...Fe,worktreeName:de.target.value}))},onBlur:()=>se(de=>({...de,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ue("h-8",Se.touched&&Se.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(xe,{variant:"outline",size:"sm",onClick:()=>$(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:h.sourceBranch?"text-foreground":"text-muted-foreground",children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(I,{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(Mr,{open:V,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>$(!1),children:s.jsxs("div",{className:"space-y-4",ref:ce,children:[s.jsx(Vt,{value:L,onChange:de=>J(de.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):A.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[ne&&pe&&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(de=>s.jsx("button",{onClick:()=>{v(Fe=>({...Fe,sourceBranch:de.value})),$(!1)},className:ue("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===de.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de.label})},`${de.source}-${de.value}`))})]}),ne&&!pe&&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(ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:ie.otherLocal.map(de=>s.jsx("button",{onClick:()=>{v(Fe=>({...Fe,sourceBranch:de})),$(!1)},className:ue("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===de?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de})},de))})]}),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(ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:ie.otherRemote.map(de=>s.jsx("button",{onClick:()=>{v(Fe=>({...Fe,sourceBranch:`remotes/${de}`})),$(!1)},className:ue("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===`remotes/${de}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:de})},`remotes/${de}`))})]})]})]})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{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:de=>de.stopPropagation(),children:s.jsx(I,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:le,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(vs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(gs,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(I,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Er,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(I,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:f,onSelect:de=>ge(de),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(Fs,{open:N,onOpenChange:T,children:[s.jsx(Es,{asChild:!0,children:s.jsxs(xe,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ue("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Rs,{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(Oa,{shouldFilter:!1,children:[s.jsx(oa,{placeholder:r("session.newWorktree.searchBranches"),value:z,onValueChange:Q,onKeyDown:ae}),s.jsx(La,{disableHorizontal:!0,children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):A.length===0&&j.length===0?s.jsx($a,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[Ne&&fe&&s.jsx(Rn,{heading:r("session.newWorktree.matchingBranches"),children:K.matching.map(de=>s.jsx(kn,{value:de.value,onSelect:()=>{g(Fe=>({...Fe,selectedBranch:de.value,worktreeName:Mn(de.label)})),se(Fe=>({...Fe,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de.label})},`${de.source}-${de.value}`))}),Ne&&!fe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),K.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[Ne&&s.jsx(ka,{}),s.jsx(Rn,{heading:r(Ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:K.otherLocal.map(de=>s.jsx(kn,{value:de,onSelect:()=>{g(Fe=>({...Fe,selectedBranch:de,worktreeName:Mn(de)})),se(Fe=>({...Fe,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de})},`local-${de}`))})]}),K.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(K.otherLocal.length>0||Ne)&&s.jsx(ka,{}),s.jsx(Rn,{heading:r(Ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:K.otherRemote.map(de=>s.jsx(kn,{value:`remotes/${de}`,onSelect:()=>{g(Fe=>({...Fe,selectedBranch:`remotes/${de}`,worktreeName:Mn(de)})),se(Fe=>({...Fe,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de})},`remote-${de}`))})]})]})})]})})]}),s.jsx(xe,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:oe,disabled:!je||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"refresh",className:"size-4"})})]})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&X&&s.jsxs(xe,{variant:"outline",size:"sm",onClick:()=>C(!0),className:"gap-1.5 h-7",children:[s.jsx(I,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Vt,{value:h.branchName,onChange:de=>{v(Fe=>({...Fe,branchName:de.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>se(de=>({...de,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:ue("h-8",Se.touched&&Se.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(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const de=Mn(f==="new-branch"?h.branchName:"");v(Fe=>({...Fe,worktreeName:de,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===Mn(h.branchName),className:ue("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===Mn(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(I,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Vt,{value:Y.worktreeName,onChange:de=>{f==="new-branch"?v(Fe=>({...Fe,worktreeName:de.target.value,isSyncingWorktreeName:!1})):g(Fe=>({...Fe,worktreeName:de.target.value}))},onBlur:()=>se(de=>({...de,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ue("h-8",Se.touched&&Se.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(Fs,{open:M,onOpenChange:F,children:[s.jsx(Es,{asChild:!0,children:s.jsxs(xe,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ue("truncate",h.sourceBranch?"text-foreground":"text-muted-foreground"),children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Rs,{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(Oa,{shouldFilter:!1,children:[s.jsx(oa,{placeholder:r("session.newWorktree.searchBranches"),value:L,onValueChange:J,onKeyDown:ae}),s.jsx(La,{disableHorizontal:!0,children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):A.length===0&&j.length===0?s.jsx($a,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ne&&pe&&s.jsx(Rn,{heading:r("session.newWorktree.matchingBranches"),children:ie.matching.map(de=>s.jsx(kn,{value:de.value,onSelect:()=>{v(Fe=>({...Fe,sourceBranch:de.value})),F(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de.label})},`${de.source}-${de.value}`))}),ne&&!pe&&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:[ne&&s.jsx(ka,{}),s.jsx(Rn,{heading:r(ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ie.otherLocal.map(de=>s.jsx(kn,{value:de,onSelect:()=>{v(Fe=>({...Fe,sourceBranch:de})),F(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de})},`local-${de}`))})]}),ie.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(ie.otherLocal.length>0||ne)&&s.jsx(ka,{}),s.jsx(Rn,{heading:r(ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ie.otherRemote.map(de=>s.jsx(kn,{value:`remotes/${de}`,onSelect:()=>{v(Fe=>({...Fe,sourceBranch:`remotes/${de}`})),F(!1)},children:s.jsx("span",{className:"typography-small break-all",children:de})},`remote-${de}`))})]})]})})]})})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{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:de=>de.stopPropagation(),children:s.jsx(I,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:le,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{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(Us,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:Se.touched&&(Se.branchError||Se.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:Se.branchError||Se.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xe,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:we,children:r("session.newWorktree.actions.cancel")}),s.jsxs(xe,{size:"sm",onClick:Ce,disabled:!Te||we,className:"gap-1.5",children:[we&&s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(we?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(rI,{open:P,onOpenChange:C,onSelect:O})]})}let oi=null,li=null,Zo=null,yl=0;const Ta=new Set,cI=3e4,dI=45e3,Pg=()=>{Zo&&(clearTimeout(Zo),Zo=null)},Ag=()=>{if(li||Ta.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(yl,5)),cI);li=setTimeout(()=>{li=null,yl+=1,Dg()},t)},vl=()=>{Pg(),oi&&oi.close(),oi=null},Jp=()=>{Pg(),Ta.size!==0&&(Zo=setTimeout(()=>{vl(),Ag()},dI))},uI=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}},mI=t=>{if(t.type==="openchamber:event-stream-ready"){yl=0;return}if(t.type==="openchamber:heartbeat"||t.type!=="openchamber:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",a=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,o=i==="running"||i==="error"?i:"success";if(!n||!r)return;const c={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:a,status:o,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of Ta)d(c)},Dg=()=>{if(typeof window>"u"||Ta.size===0||typeof EventSource!="function"||oi&&oi.readyState!==EventSource.CLOSED)return;vl();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{Jp()},t.onmessage=e=>{Jp();const n=uI(e.data);n&&mI(n)},t.onerror=()=>{vl(),Ag()},oi=t},Tg=t=>(Ta.add(t),Dg(),()=>{Ta.delete(t),Ta.size===0&&(li&&(clearTimeout(li),li=null),yl=0,vl())}),$l=async(t,e)=>{try{const n=await t.json();if(n&&typeof n.error=="string"&&n.error.trim().length>0)return n.error}catch{return e}return e},yi=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},pI=async t=>{const e=yi(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await $l(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Qp=async(t,e)=>{const n=yi(t),r=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({task:e})});if(!r.ok)throw new Error(await $l(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},fI=async(t,e)=>{const n=yi(t),r=yi(e),a=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!a.ok)throw new Error(await $l(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},hI=async(t,e)=>{const n=yi(t),r=yi(e),a=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!a.ok)throw new Error(await $l(a,"Failed to run scheduled task"));const i=await a.json().catch(()=>null);return{sessionId:typeof i?.sessionId=="string"&&i.sessionId.length>0?i.sessionId:void 0}},Mg=[0,1,2,3,4,5,6],Xp=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"],Zp=()=>{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}`},el=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},ef=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},gI=(t,e,n)=>{const r=el(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},tf=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),xI=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),o=(new Date(n,r,1).getDay()-e+7)%7,c=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),p=[];for(let m=0;m<42;m+=1){const u=m-o+1;if(u<=0){const f=d+u;p.push({date:new Date(n,r-1,f),inCurrentMonth:!1});continue}if(u>c){p.push({date:new Date(n,r+1,u-c),inCurrentMonth:!1});continue}p.push({date:new Date(n,r,u),inCurrentMonth:!0})}return p},bI=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],a=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:a}},ya=(t,e,n)=>{const r=Number(t),a=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,o=Number.isFinite(a)?Math.min(59,Math.max(0,a)):0;let c=i%12;return n==="PM"&&(c+=12),`${String(c).padStart(2,"0")}:${String(o).padStart(2,"0")}`},ji=(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"},sf=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:ji(t,{min:1,max:12}),Fo=t=>/^[0-5][0-9]$/.test(t)?t:ji(t,{max:59}),yI=(t,e)=>ji(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),nf=(t,e)=>ji(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),vI=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}},wI=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}},jI=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Mg.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},NI=(t,e)=>[...t.slice(e),...t.slice(0,e)],xr=t=>{const e=ot.c(6),{htmlFor:n,required:r,children:a}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let o;return e[2]!==a||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,i]})}),e[2]=a,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},rf=t=>{const e=ot.c(84),{value:n,onChange:r,use24Hour:a,hourAriaLabel:i,minuteAriaLabel:o,periodAriaLabel:c,amLabel:d,pmLabel:p}=t;let m;e[0]!==n?(m=bI(n),e[0]=n,e[1]=m):m=e[1];const u=m,f=$e.useRef(null),b=$e.useRef(null),[h,v]=$e.useState(null),[x,g]=$e.useState(null),w=$e.useRef(null),y=$e.useRef(null);let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=se=>{w.current=se,v(se)},e[2]=k):k=e[2];const A=k;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=se=>{y.current=se,g(se)},e[3]=j):j=e[3];const S=j,D=AI,E=DI,P=TI;let C;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==a?(C=se=>{const we=se.replace(/\D/g,"").slice(0,2);A(we),we.length===2&&(r(a?P(D(we),u.minute):ya(sf(we),u.minute,u.meridiem)),A(null),b.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=a,e[8]=C):C=e[8];const N=C;let T;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==a?(T=()=>{const se=w.current;if(se!==null&&(A(null),se.length!==0)){if(a){r(P(D(se.padStart(2,"0")),u.minute));return}r(ya(sf(se.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=a,e[13]=T):T=e[13];const M=T;let F;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==a?(F=se=>{const we=se.replace(/\D/g,"").slice(0,2);S(we),we.length===2&&(r(a?P(u.hour24,Fo(we)):ya(u.hour12,Fo(we),u.meridiem)),S(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=a,e[19]=F):F=e[19];const _=F;let B;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==a?(B=()=>{const se=y.current;se!==null&&(S(null),se.length!==0&&r(a?P(u.hour24,Fo(se.padStart(2,"0"))):ya(u.hour12,Fo(se.padStart(2,"0")),u.meridiem)))},e[20]=r,e[21]=u.hour12,e[22]=u.hour24,e[23]=u.meridiem,e[24]=a,e[25]=B):B=e[25];const V=B;let $;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==a?($=se=>r(a?P(E(u.hour24,se),u.minute):ya(yI(u.hour12,se),u.minute,u.meridiem)),e[26]=r,e[27]=u.hour12,e[28]=u.hour24,e[29]=u.meridiem,e[30]=u.minute,e[31]=a,e[32]=$):$=e[32];const z=$;let Q;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==a?(Q=se=>r(a?P(u.hour24,nf(u.minute,se)):ya(u.hour12,nf(u.minute,se),u.meridiem)),e[33]=r,e[34]=u.hour12,e[35]=u.hour24,e[36]=u.meridiem,e[37]=u.minute,e[38]=a,e[39]=Q):Q=e[39];const L=Q;let J;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(J=se=>{se!==u.meridiem&&r(ya(u.hour12,u.minute,se))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=J):J=e[44];const ee=J;let re;e[45]!==M||e[46]!==z?(re=se=>{if(se.key==="ArrowRight"){se.preventDefault(),M(),b.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),A(null),z(se.key==="ArrowUp"?1:-1))},e[45]=M,e[46]=z,e[47]=re):re=e[47];const q=re;let ce;e[48]!==V||e[49]!==L?(ce=se=>{if(se.key==="ArrowLeft"&&(se.currentTarget.selectionStart??0)===0){se.preventDefault(),V(),f.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),S(null),L(se.key==="ArrowUp"?1:-1))},e[48]=V,e[49]=L,e[50]=ce):ce=e[50];const ae=ce,R=a?"px-2":"pl-2 pr-1";let U;e[51]!==R?(U=ue("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",R),e[51]=R,e[52]=U):U=e[52];const W=h??(a?u.hour24:u.hour12);let Z;e[53]!==N?(Z=se=>N(se.target.value),e[53]=N,e[54]=Z):Z=e[54];let K;e[55]===Symbol.for("react.memo_cache_sentinel")?(K=()=>A(""),e[55]=K):K=e[55];let ie;e[56]!==M||e[57]!==i||e[58]!==q||e[59]!==W||e[60]!==Z?(ie=s.jsx("input",{ref:f,inputMode:"numeric",value:W,onChange:Z,onKeyDown:q,onFocus:K,onBlur:M,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=M,e[57]=i,e[58]=q,e[59]=W,e[60]=Z,e[61]=ie):ie=e[61];let Ne;e[62]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=Ne):Ne=e[62];const ne=x??u.minute;let fe;e[63]!==_?(fe=se=>_(se.target.value),e[63]=_,e[64]=fe):fe=e[64];let pe;e[65]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>S(""),e[65]=pe):pe=e[65];let je;e[66]!==V||e[67]!==o||e[68]!==ae||e[69]!==ne||e[70]!==fe?(je=s.jsx("input",{ref:b,inputMode:"numeric",value:ne,onChange:fe,onKeyDown:ae,onFocus:pe,onBlur:V,maxLength:2,"aria-label":o,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=V,e[67]=o,e[68]=ae,e[69]=ne,e[70]=fe,e[71]=je):je=e[71];let oe;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==ee||e[77]!==a?(oe=a?null:s.jsxs(is,{value:u.meridiem,onValueChange:se=>ee(se),children:[s.jsx(os,{"aria-label":c,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(us,{})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"AM",children:d}),s.jsx(Ft,{value:"PM",children:p})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=p,e[76]=ee,e[77]=a,e[78]=oe):oe=e[78];let Se;return e[79]!==U||e[80]!==ie||e[81]!==je||e[82]!==oe?(Se=s.jsxs("div",{className:U,children:[ie,Ne,je,oe]}),e[79]=U,e[80]=ie,e[81]=je,e[82]=oe,e[83]=Se):Se=e[83],Se},af=t=>new Date(t.getFullYear(),t.getMonth(),1),SI=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},of=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),kI=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"]},lf=(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:kI(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Zp(),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:Zp(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},CI=(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")},II=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 PI(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:o}=pt(),c=vt(Y=>Y.loadProviders),d=vt(Y=>Y.loadAgents),p=vt(Y=>Y.providers),m=vt(Y=>Y.currentProviderId),u=vt(Y=>Y.currentModelId),f=vt(Y=>Y.currentVariant||""),b=vt(Y=>Y.currentAgentName||""),h=De(Y=>Y.timeFormatPreference),v=De(Y=>Y.weekStartPreference),x=De(Y=>Y.isMobile),[g,w]=$e.useState(()=>lf(n,{providerID:m,modelID:u,variant:f,agent:b})),[y,k]=$e.useState(!1),[A,j]=$e.useState(!1),[S,D]=$e.useState(!1),[E,P]=$e.useState(""),[C,N]=$e.useState(!1),[T,M]=$e.useState(""),[F,_]=$e.useState(()=>{const Y=el(n?.schedule?.date||"")||new Date;return new Date(Y.getFullYear(),Y.getMonth(),1)}),B=$e.useRef(null),V=$e.useRef(null),$=$e.useRef(null),z=$e.useRef(null),Q=$e.useMemo(()=>wI(o),[o]),L=$e.useMemo(()=>vI(o),[o]),J=$e.useMemo(()=>h==="24h"?!0:h==="12h"?!1:Q,[h,Q]),ee=$e.useMemo(()=>v==="sunday"?0:v==="monday"?1:L,[v,L]),re=$e.useMemo(()=>{const Y=jI(o);return NI(Mg.map(ke=>({value:ke,label:Y[ke]||""})),ee)},[o,ee]);$e.useEffect(()=>{e&&(c(),d())},[e,c,d]),$e.useEffect(()=>{if(!e)return;w(lf(n,{providerID:m,modelID:u,variant:f,agent:b}));const Y=el(n?.schedule?.date||"")||new Date;_(new Date(Y.getFullYear(),Y.getMonth(),1)),j(!1),N(!1),D(!1),M(""),P("")},[e,n,m,u,f,b]),$e.useEffect(()=>{if(!A)return;const Y=ke=>{B.current&&!B.current.contains(ke.target)&&j(!1)};return document.addEventListener("mousedown",Y),()=>{document.removeEventListener("mousedown",Y)}},[A]);const q=$e.useMemo(()=>{const ke=p.find(Be=>Be.id===g.execution.providerID)?.models?.find(Be=>Be.id===g.execution.modelID);return ke?.variants?Object.keys(ke.variants):[]},[p,g.execution.providerID,g.execution.modelID]),ce=q.length>0,ae=$e.useMemo(()=>!ce||!g.execution.variant?"__default":q.includes(g.execution.variant)?g.execution.variant:"__default",[g.execution.variant,ce,q]);$e.useEffect(()=>{ce||!g.execution.variant||w(Y=>({...Y,execution:{...Y.execution,variant:""}}))},[ce,g.execution.variant]);const R=$e.useCallback((Y,ke)=>{w(Be=>{const Ce=new Set(Be.schedule.weekdays);return ke?Ce.add(Y):Ce.delete(Y),{...Be,schedule:{...Be.schedule,weekdays:Array.from(Ce).sort((ge,O)=>ge-O)}}})},[]),U=$e.useCallback((Y,ke)=>{w(Be=>{const Ce=Be.schedule.times.slice();return Ce[Y]=ke,{...Be,schedule:{...Be.schedule,times:Ce}}})},[]),W=$e.useCallback(Y=>{w(ke=>{const Be=ke.schedule.times.filter((Ce,ge)=>ge!==Y);return{...ke,schedule:{...ke.schedule,times:Be.length>0?Be:["09:00"]}}})},[]),Z=$e.useCallback(()=>{w(Y=>({...Y,schedule:{...Y.schedule,times:[...Y.schedule.times,"12:00"]}}))},[]),K=$e.useMemo(()=>SI(),[]),ie=$e.useMemo(()=>af(K),[K]),Ne=$e.useMemo(()=>{const Y=el(g.schedule.onceDate);return Y?of(Y,K)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(o,{weekday:"short"}).format(Y):null},[g.schedule.onceDate,o,i,K]),ne=$e.useMemo(()=>af(F).getTime()<=ie.getTime(),[F,ie]),fe=$e.useMemo(()=>re.map(Y=>Y.label),[re]),pe=$e.useCallback(Y=>{w(ke=>({...ke,schedule:{...ke.schedule,onceDate:Y}}))},[]),je=$e.useCallback((Y,ke)=>{if(Y.startsWith("/")){const ge=Y.indexOf(" "),O=Y.indexOf(`
|
|
180
|
-
`),X=Math.min(ge===-1?Y.length:ge,O===-1?Y.length:O);if(ke<=X&&ge===-1){M(Y.substring(1,X)),N(!0),D(!1);return}}N(!1);const Be=Y.substring(0,ke),Ce=Be.lastIndexOf("@");if(Ce!==-1){const ge=Ce>0?Be[Ce-1]:null,O=Be.substring(Ce+1);(!ge||/\s/.test(ge))&&!O.includes(" ")&&!O.includes(`
|
|
181
|
-
`)?(P(O),D(!0)):D(!1);return}D(!1)},[]),oe=$e.useCallback(Y=>{w(ke=>({...ke,execution:{...ke.execution,prompt:Y}}))},[]),Se=$e.useCallback(Y=>{const ke=g.execution.prompt,Ce=V.current?.selectionStart??ke.length,O=ke.substring(0,Ce).lastIndexOf("@"),X=Y.relativePath&&Y.relativePath.trim().length>0?Y.relativePath.trim():Y.path||Y.name,G=O!==-1?O:Ce,Te=`${ke.substring(0,G)}@${X} ${ke.substring(Ce)}`,le=G+X.length+2;oe(Te),D(!1),P(""),requestAnimationFrame(()=>{const We=V.current;We&&(We.selectionStart=le,We.selectionEnd=le,We.focus()),je(Te,le)})},[g.execution.prompt,oe,je]),se=$e.useCallback(Y=>{const ke=g.execution.prompt,Ce=V.current?.selectionStart??ke.length,O=ke.substring(0,Ce).lastIndexOf("@"),X=O!==-1?O:Ce,G=`${ke.substring(0,X)}@${Y} ${ke.substring(Ce)}`,Te=X+Y.length+2;oe(G),D(!1),P(""),requestAnimationFrame(()=>{const le=V.current;le&&(le.selectionStart=Te,le.selectionEnd=Te,le.focus()),je(G,Te)})},[g.execution.prompt,oe,je]),we=$e.useCallback(Y=>{const ke=`/${Y.name} `;oe(ke),N(!1),M(""),requestAnimationFrame(()=>{const Be=V.current;Be&&(Be.focus(),Be.selectionStart=Be.value.length,Be.selectionEnd=Be.value.length),je(ke,ke.length)})},[oe,je]),Ae=$e.useCallback(Y=>{if(C&&z.current&&(Y.key==="Enter"||Y.key==="ArrowUp"||Y.key==="ArrowDown"||Y.key==="Escape"||Y.key==="Tab")){Y.preventDefault(),z.current.handleKeyDown(Y.key);return}S&&$.current&&(Y.key==="Enter"||Y.key==="ArrowUp"||Y.key==="ArrowDown"||Y.key==="Escape"||Y.key==="Tab")&&(Y.preventDefault(),$.current.handleKeyDown(Y.key))},[C,S]),ve=$e.useCallback(async()=>{const Y=CI(g,i);if(Y){H.error(Y);return}const ke=II(g.schedule.times),Be={...g.id?{id:g.id}:{},name:g.name.trim(),enabled:g.enabled,schedule:{kind:g.schedule.kind,timezone:g.schedule.timezone.trim(),...g.schedule.kind==="once"?{date:g.schedule.onceDate,time:g.schedule.onceTime}:{times:ke,...g.schedule.kind==="weekly"?{weekdays:g.schedule.weekdays}:{}}},execution:{prompt:g.execution.prompt,providerID:g.execution.providerID,modelID:g.execution.modelID,...g.execution.variant.trim()?{variant:g.execution.variant.trim()}:{},...g.execution.agent.trim()?{agent:g.execution.agent.trim()}:{}},...g.state?{state:g.state}:{}};k(!0);try{await a(Be),r(!1)}catch(Ce){H.error(Ce instanceof Error?Ce.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{k(!1)}},[g,r,a,i]),ye=$e.useId(),Ie=$e.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),he=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),me=i("sessions.scheduledTasks.editor.description"),Ee=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(xr,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Vt,{id:"sched-name",value:g.name,onChange:Y=>w(ke=>({...ke,name:Y.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(xr,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(is,{value:g.schedule.kind,onValueChange:Y=>{w(ke=>({...ke,schedule:{...ke.schedule,kind:Y}}))},children:[s.jsx(os,{className:"w-fit max-w-full",children:s.jsx(us,{children:Y=>i(Y==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":Y==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Ft,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Ft,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),g.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:B,children:[s.jsx(xr,{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(Y=>!Y),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(I,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:gI(g.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),o)})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),A?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>_(Y=>tf(Y,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:ne,children:s.jsx(I,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(o,{month:"long",year:"numeric"}).format(F)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>_(Y=>tf(Y,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:fe.map((Y,ke)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:Y},`${Y}-${ke}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:xI(F,ee).map(({date:Y,inCurrentMonth:ke})=>{const Be=ef(Y),Ce=Be===g.schedule.onceDate,ge=of(Y,K),O=Y.getTime()<K.getTime(),X=Ce?"bg-interactive-selection text-interactive-selection-foreground":O?"text-muted-foreground/40":ke?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{O||(pe(Be),j(!1))},disabled:O,className:["h-8 rounded-md typography-ui-label",X,ge&&!Ce?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",O?"cursor-not-allowed opacity-45":""].join(" "),children:Y.getDate()},Be)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ne||""}),s.jsx(xe,{type:"button",size:"xs",variant:"ghost",onClick:()=>{pe(ef(K)),_(new Date(K.getFullYear(),K.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(xr,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(rf,{value:g.schedule.onceTime,use24Hour:J,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:Y=>w(ke=>({...ke,schedule:{...ke.schedule,onceTime:Y}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(xr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(is,{value:g.schedule.timezone,onValueChange:Y=>{w(ke=>({...ke,schedule:{...ke.schedule,timezone:Y}}))},children:[s.jsx(os,{className:"w-fit max-w-full",children:s.jsx(us,{})}),s.jsx(ls,{children:Xp.map(Y=>s.jsx(Ft,{value:Y,children:Y},Y))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[g.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(xr,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:re.map(Y=>{const ke=g.schedule.weekdays.includes(Y.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",ke?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(ds,{checked:ke,onChange:Be=>R(Y.value,Be),ariaLabel:Y.label}),s.jsx("button",{type:"button",onClick:()=>R(Y.value,!ke),className:"group-hover:text-foreground",children:Y.label})]},Y.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(xr,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:g.schedule.times.map((Y,ke)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(rf,{value:Y,use24Hour:J,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:Be=>U(ke,Be)}),g.schedule.times.length>1?s.jsx(xe,{type:"button",size:"icon",variant:"ghost",onClick:()=>W(ke),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]},ke))}),s.jsx("div",{children:s.jsxs(xe,{type:"button",size:"sm",variant:"outline",onClick:Z,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(xr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(is,{value:g.schedule.timezone,onValueChange:Y=>{w(ke=>({...ke,schedule:{...ke.schedule,timezone:Y}}))},children:[s.jsx(os,{className:"w-fit max-w-full",children:s.jsx(us,{})}),s.jsx(ls,{children:Xp.map(Y=>s.jsx(Ft,{value:Y,children:Y},Y))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(xr,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(mo,{providerId:g.execution.providerID,modelId:g.execution.modelID,onChange:(Y,ke)=>{w(Be=>({...Be,execution:{...Be.execution,providerID:Y,modelID:ke,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(xr,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(is,{value:ae,disabled:!ce,onValueChange:Y=>{w(ke=>({...ke,execution:{...ke.execution,variant:Y==="__default"?"":Y}}))},children:[s.jsx(os,{className:"w-fit max-w-full",children:s.jsx(us,{children:Y=>Y==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):Y})}),s.jsxs(ls,{children:[s.jsx(Ft,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),q.map(Y=>s.jsx(Ft,{value:Y,children:Y},Y))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(xr,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Ol,{agentName:g.execution.agent,filter:Y=>Yf(Y.mode),onChange:Y=>w(ke=>({...ke,execution:{...ke.execution,agent:Y}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(xr,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(fn,{id:"sched-prompt",ref:V,value:g.execution.prompt,onChange:Y=>{const ke=Y.target.value;oe(ke);const Be=Y.target.selectionStart??ke.length;je(ke,Be)},onKeyDown:Ae,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),C?s.jsx(dh,{ref:z,searchQuery:T,onCommandSelect:we,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,S?s.jsx(uh,{ref:$,searchQuery:E,onFileSelect:Se,onAgentSelect:se,onClose:()=>D(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),Ve=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(ds,{checked:g.enabled,onChange:Y=>w(ke=>({...ke,enabled:Y})),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(xe,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(xe,{type:"button",size:"sm",onClick:ve,disabled:y,children:i(y?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Mr,{open:e,title:he,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:Y=>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:he}),Y]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:me})]}),footer:Ve,children:Ee}):s.jsx(ps,{open:e,onOpenChange:Y=>{!Y&&Ie()||r(Y)},children:s.jsxs(ms,{"aria-describedby":ye,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ps,{id:ye,className:"sr-only",children:me}),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(gs,{className:"typography-ui-label font-medium text-foreground",children:he}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:me})]})}),s.jsx(io,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:Ee})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:Ve})})]})})}function AI(t){return ji(t,{min:0,max:23})}function DI(t,e){return ji(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function TI(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 MI=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))},EI=(t,e)=>{const n=MI(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||""})},RI=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),cf=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),a=6e4,i=60*a,o=24*i,c=n>=0;if(r<a)return e(c?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const u=Math.round(r/a);return c?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:u}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:u})}if(r<o){const u=Math.floor(r/i),f=Math.round(r%i/a),b=f>0?`${u}h ${f}m`:`${u}h`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:b}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:b})}const d=Math.floor(r/o),p=Math.round(r%o/i),m=p>0?`${d}d ${p}h`:`${d}d`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},FI={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"}},OI=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function LI(){const{t}=pt(),e=De(M=>M.isScheduledTasksDialogOpen),n=De(M=>M.setScheduledTasksDialogOpen),r=De(M=>M.isMobile),a=Ts(M=>M.projects),i=Ts(M=>M.getActiveProject()),o=_s(M=>M.homeDirectory),{currentTheme:c}=Sr(),[d,p]=$e.useState(""),[m,u]=$e.useState([]),[f,b]=$e.useState(!0),[h,v]=$e.useState(!1),[x,g]=$e.useState(null),[w,y]=$e.useState(null),k=$e.useMemo(()=>a.find(M=>M.id===d)||null,[a,d]),A=$e.useCallback(M=>{const F=M.label?.trim()||Fa(M.path,o||void 0),_=co({id:M.id,iconImage:M.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),B=M.icon?Rl[M.icon]:null,V=M.color?uo[M.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:M.iconBackground?{backgroundColor:M.iconBackground}:void 0,children:s.jsx("img",{src:_,alt:"",className:"h-full w-full object-contain",draggable:!1})}):B?s.jsx(I,{name:B,className:"h-3.5 w-3.5 shrink-0",style:V?{color:V}:void 0}):s.jsx(I,{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})]})},[o,c.metadata.variant,c.colors.surface.foreground]),j=$e.useCallback(async(M,F)=>{if(!M){u([]);return}F?.silent||b(!0);try{const _=await pI(M);_.sort((B,V)=>{if(B.enabled!==V.enabled)return B.enabled?-1:1;const $=B.name.localeCompare(V.name);return $!==0?$:(B.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u(_)}catch(_){H.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),F?.silent||u([])}finally{F?.silent||b(!1)}},[t]);$e.useEffect(()=>{if(!e)return;const M=i?.id||a[0]?.id||"";p(M),M?j(M):(u([]),b(!1))},[e,i,a,j]),$e.useEffect(()=>{if(!e)return;let M=null;const F=Tg(_=>{_.type==="scheduled-task-ran"&&_.projectId===d&&(M&&clearTimeout(M),M=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{M&&clearTimeout(M),F()}},[e,d,j]);const S=$e.useCallback(async M=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Qp(d,M),await j(d),H.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),D=$e.useCallback(async(M,F)=>{if(d){y(M.id),u(_=>_.map(B=>B.id===M.id?{...B,enabled:F}:B));try{await Qp(d,{...M,enabled:F}),await j(d,{silent:!0})}catch(_){H.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{y(null)}}},[d,j,t]),E=$e.useCallback(async M=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:M.name})))){y(M.id);try{await fI(d,M.id),await j(d,{silent:!0}),H.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(_){H.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{y(null)}}},[d,j,t]),P=$e.useCallback(async M=>{if(d){y(M.id);try{await hI(d,M.id),await Promise.all([j(d,{silent:!0}),Jc()]),H.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(F){H.error(F instanceof Error?F.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{y(null)}}},[d,j,t]),C=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(is,{value:d||"__none",onValueChange:M=>{const F=M==="__none"?"":M;p(F),F?j(F):u([])},children:[s.jsx(os,{className:r?"w-full":void 0,children:k?s.jsx(us,{children:A(k)}):s.jsx(us,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(ls,{children:[a.length===0?s.jsx(Ft,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(M=>s.jsx(Ft,{value:M.id,children:A(M)},M.id))]})]})]}),N=()=>{g(null),v(!0)},T=s.jsxs("div",{className:"space-y-4",children:[r?C:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[C,s.jsxs(xe,{onClick:N,disabled:!d,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:f?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(M=>{const F=w===M.id,_=M.state?.lastStatus||"idle",B=FI[_],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"),$=M.state?.nextRunAt,z=M.state?.lastRunAt;return s.jsxs("div",{className:ue("rounded-lg border border-border p-4 transition-opacity",!M.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:M.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:EI(M,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),$?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:cf($,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:RI($)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(I,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),_==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):z?s.jsxs(s.Fragment,{children:[B.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${B.tone})`},children:[s.jsx(I,{name:B.Icon,className:"h-3.5 w-3.5"}),V]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:cf(z,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),M.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:OI("error"),children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:M.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:ue("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",M.enabled?"text-foreground":"text-muted-foreground",F&&"cursor-not-allowed opacity-50"),children:[s.jsx(ds,{checked:M.enabled,onChange:Q=>{D(M,Q)},ariaLabel:M.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:M.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:M.name}),disabled:F}),M.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(xe,{variant:"outline",size:"sm",onClick:()=>{P(M)},disabled:F,children:[s.jsx(I,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(xe,{variant:"outline",size:"sm",onClick:()=>{g(M),v(!0)},disabled:F,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:M.name}),children:[s.jsx(I,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(xe,{variant:"destructive",size:"sm",onClick:()=>{E(M)},disabled:F,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:M.name}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},M.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Mr,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:M=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),M]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(xe,{className:"w-full",onClick:N,disabled:!d,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:T}):s.jsx(ps,{open:e,onOpenChange:n,children:s.jsxs(ms,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Ps,{children:t("sessions.scheduledTasks.dialog.description")})]}),T]})}),s.jsx(PI,{open:h,task:x,onOpenChange:v,onSave:S})]})}const $I=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(c=>ys(c.path)??c.path).filter(c=>!!c)]),i=(c=>c.filter(d=>Zi(d,t.normalizedPath,r)))(e.archivedSessions),o=e.sessions.filter(c=>c.time?.archived||ys(c.directory??null)?!1:Zi(c,t.normalizedPath,r));return gi([...i,...o])},BI=t=>{const e=ot.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o,isSessionsLoading:c,foldersMap:d,createFolder:p,addSessionToFolder:m,cleanupSessions:u}=t;let f,b;e[0]!==m||e[1]!==a||e[2]!==i||e[3]!==u||e[4]!==p||e[5]!==d||e[6]!==c||e[7]!==o||e[8]!==n||e[9]!==r?(f=()=>{c||n.forEach(h=>{const v=Vd(h.normalizedPath),x=$I(h,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o}),g=new Set(x.map(_I)),w=d[v]??[],y=new Map(w.map(zI));x.forEach(k=>{const A=hy(k,h.normalizedPath),j=A.toLowerCase();let S=y.get(j);S||(S=p(v,A),y.set(j,S)),S.sessionIds.includes(k.id)||m(v,S.id,k.id)}),u(v,g)})},b=[n,r,a,i,o,c,d,p,m,u],e[0]=m,e[1]=a,e[2]=i,e[3]=u,e[4]=p,e[5]=d,e[6]=c,e[7]=o,e[8]=n,e[9]=r,e[10]=f,e[11]=b):(f=e[10],b=e[11]),l.useEffect(f,b)};function _I(t){return t.id}function zI(t){return[t.name.toLowerCase(),t]}const VI=t=>{const e=ot.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:f,buildGroupSearchText:b,foldersMap:h}=t;let v;if(e[0]!==i||e[1]!==p||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==o||e[7]!==c){let P;e[9]!==i||e[10]!==p||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==o||e[15]!==c?(P=C=>{const N=gi([...r(C),...a(C)]),T=i.get(C.normalizedPath)??[],M=o.has(C.id)?!!o.get(C.id):d,F=p(N,C.normalizedPath,T,c.get(C.id)??null,M);return{project:C,groups:F}},e[9]=i,e[10]=p,e[11]=a,e[12]=r,e[13]=d,e[14]=o,e[15]=c,e[16]=P):P=e[16],v=n.map(P),e[0]=i,e[1]=p,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=o,e[7]=c,e[8]=v}else v=e[8];const x=v,g=x;let w;if(e[17]!==b||e[18]!==f||e[19]!==h||e[20]!==m||e[21]!==u||e[22]!==g){e:{const P=new WeakMap;if(!m){w=P;break e}const C=N=>N.reduce((T,M)=>T+1+C(M.children),0);g.forEach(N=>{N.groups.forEach(T=>{const M=f(T.sessions,u),F=C(M),_=b(T).includes(u),B=ys(T.directory??null),$=(B?h[B]??[]:[]).filter(z=>z.name.toLowerCase().includes(u)).length;P.set(T,{filteredNodes:M,matchedSessionCount:F,folderNameMatchCount:$,groupMatches:_,hasMatch:_||F>0||$>0})})}),w=P}e[17]=b,e[18]=f,e[19]=h,e[20]=m,e[21]=u,e[22]=g,e[23]=w}else w=e[23];const y=w;let k;e:{if(!m){k=g;break e}let P;if(e[24]!==y||e[25]!==g){let C;e[27]!==y?(C=N=>({...N,groups:N.groups.filter(T=>y.get(T)?.hasMatch===!0)}),e[27]=y,e[28]=C):C=e[28],P=g.map(C).filter(UI),e[24]=y,e[25]=g,e[26]=P}else P=e[26];k=P}const A=k,j=m?A:g;let S;e:{if(!m){S=0;break e}let P;if(e[29]!==y||e[30]!==j){let C;e[32]!==y?(C=(N,T)=>N+T.groups.reduce((M,F)=>{const _=y.get(F);if(!_)return M;const B=_.folderNameMatchCount+(_.groupMatches?1:0);return M+_.matchedSessionCount+B},0),e[32]=y,e[33]=C):C=e[33],P=j.reduce(C,0),e[29]=y,e[30]=j,e[31]=P}else P=e[31];S=P}const D=S;let E;return e[34]!==y||e[35]!==x||e[36]!==D||e[37]!==A||e[38]!==j||e[39]!==g?(E={projectSections:x,visibleProjectSections:g,groupSearchDataByGroup:y,searchableProjectSections:A,sectionsForRender:j,searchMatchCount:D},e[34]=y,e[35]=x,e[36]=D,e[37]=A,e[38]=j,e[39]=g,e[40]=E):E=e[40],E};function UI(t){return t.groups.length>0}const WI=t=>{const e=ot.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:o,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:f,sessions:b,worktreeMetadata:h}=t;let v,x;if(e[0]!==n){x=new Map,v=new Map;const C=(N,T,M,F)=>{x.has(N)||x.set(N,new Map);const _=x.get(N);F.forEach(B=>{const V=ys(B.worktree?.path??B.session.directory??M??T);_.set(B.session.id,{directory:V}),v.has(N)||v.set(N,{id:B.session.id,directory:V}),B.children.length>0&&C(N,T,V,B.children)})};n.forEach(N=>{N.groups.forEach(T=>{C(N.project.id,N.project.normalizedPath,T.directory,T.sessions)})}),e[0]=n,e[1]=v,e[2]=x}else v=e[1],x=e[2];let g;e[3]!==v||e[4]!==x?(g={metaByProject:x,firstSessionByProject:v},e[3]=v,e[4]=x,e[5]=g):g=e[5];const w=g,y=l.useRef(null);let k,A;e[6]!==r||e[7]!==a||e[8]!==o||e[9]!==c||e[10]!==p||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==w||e[15]!==u||e[16]!==i||e[17]!==f?(k=()=>{if(!r||d||y.current===r)return;const C=n.find(V=>V.project.id===r);if(!C)return;y.current=r;const N=w.metaByProject.get(r);if(o&&N&&N.has(o)){i(V=>{if(V.get(r)===o)return V;const $=new Map(V);return $.set(r,o),$});return}if(!N||N.size===0){u("chat"),p&&f(!1),m({directoryOverride:C.project.normalizedPath});return}const T=a.get(r),M=T&&N.has(T)?T:null,F=w.firstSessionByProject.get(r)?.id??null,_=M??F;if(!_||_===o)return;const B=N.get(_)?.directory??null;c(_,B,!1,r)},A=[r,a,o,c,d,p,m,n,w,u,f,i],e[6]=r,e[7]=a,e[8]=o,e[9]=c,e[10]=p,e[11]=d,e[12]=m,e[13]=n,e[14]=w,e[15]=u,e[16]=i,e[17]=f,e[18]=k,e[19]=A):(k=e[18],A=e[19]),l.useLayoutEffect(k,A);let j,S;e[20]!==r||e[21]!==o||e[22]!==w||e[23]!==i?(j=()=>{if(!r||!o)return;const C=w.metaByProject.get(r);!C||!C.has(o)||i(N=>{if(N.get(r)===o)return N;const T=new Map(N);return T.set(r,o),T})},S=[r,o,w,i],e[20]=r,e[21]=o,e[22]=w,e[23]=i,e[24]=j,e[25]=S):(j=e[24],S=e[25]),l.useEffect(j,S);let D;if(e[26]!==o||e[27]!==b||e[28]!==h){e:{if(!o){D=null;break e}const C=h.get(o)?.path;if(C){D=ys(C)??C;break e}let N;e[30]!==o?(N=M=>M.id===o,e[30]=o,e[31]=N):N=e[31];const T=b.find(N);if(!T){D=null;break e}D=ys(T.directory??null)}e[26]=o,e[27]=b,e[28]=h,e[29]=D}else D=e[29];const E=D;let P;return e[32]!==E?(P={currentSessionDirectory:E},e[32]=E,e[33]=P):P=e[33],P},KI=t=>{const e=ot.c(4);let n;e[0]!==t?(n=(i,o)=>{const c=t.get(i);if(!c||c.length===0)return o;const d=new Map(o.map(HI)),p=[];return c.forEach(m=>{const u=d.get(m);u&&(p.push(u),d.delete(m))}),o.forEach(m=>{d.has(m.id)&&p.push(m)}),p},e[0]=t,e[1]=n):n=e[1];const r=n;let a;return e[2]!==r?(a={getOrderedGroups:r},e[2]=r,e[3]=a):a=e[3],a};function HI(t){return[t.id,t]}const Oo=t=>!!t.time?.archived,GI=t=>{const{t:e}=pt(),n=l.useCallback(o=>[o.label,o.branch??"",o.description??"",o.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(o=>{const c=ys(o.directory??null)??"";return`${(o.title||e("sessions.sidebar.session.untitled")).trim()} ${c}`.toLowerCase()},[e]),a=l.useCallback((o,c)=>c?o.flatMap(d=>{if(r(d.session).includes(c))return[d];const m=a(d.children,c);return m.length===0?[]:[{...d,children:m}]}):o,[r]),i=l.useCallback((o,c,d,p,m)=>{const u=ys(c??null),f=gi(o).sort((C,N)=>ii(C,N,t.pinnedSessionIds)),b=new Map(f.map(C=>[C.id,C])),h=new Map;f.forEach(C=>{const N=C.parentID;if(!N)return;const T=b.get(N);if(!T||Oo(T)!==Oo(C))return;const M=h.get(N)??[];M.push(C),h.set(N,M)}),h.forEach(C=>C.sort((N,T)=>ii(N,T,t.pinnedSessionIds)));const v=new Map;d.forEach(C=>{if(C.path){const N=ys(C.path)??C.path;v.set(N,C)}});const x=C=>{const N=ys(C.directory??null),T=t.worktreeMetadata.get(C.id)??null;if(T)return T;if(N){const M=v.get(N)??null;if(M&&N!==u)return M}return null},g=C=>{const N=h.get(C.id)??[];return{session:C,children:N.map(T=>g(T)),worktree:x(C)}},w=f.filter(C=>{const N=C.parentID;if(!N)return!0;const T=b.get(N);return T?Oo(T)!==Oo(C):!0}),y=new Map,k="__archived__",A=C=>{if(C.time?.archived)return k;const N=ys(t.worktreeMetadata.get(C.id)?.path??null),T=ys(C.directory??null);if(!N&&!T)return k;const M=ys(C.project?.worktree??null),F=N??T??M;return F?F!==u&&v.has(F)?F:F===u?u??"__project_root__":k:k};w.forEach(C=>{const N=g(C),T=A(C);y.has(T)||y.set(T,[]),y.get(T)?.push(N)});const j=u??"__project_root__",S=[{id:"root",label:m&&p&&p!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:p}):e("sessions.sidebar.grouping.projectRoot"),branch:p??null,description:u?Xi(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:y.get(j)??[]}],D=new Map;d.forEach(C=>{const N=ys(C.path)??C.path,T=y.get(N)??[],M=T.length>0,F=T.reduce((_,B)=>{const V=Number(B.session.time?.updated??B.session.time?.created??0);return Number.isFinite(V)?Math.max(_,V):_},0);D.set(N,{hasActiveSession:M,lastUpdatedAt:F})}),[...d].sort((C,N)=>{const T=ys(C.path)??C.path,M=ys(N.path)??N.path,F=D.get(T)??{hasActiveSession:!1,lastUpdatedAt:0},_=D.get(M)??{hasActiveSession:!1,lastUpdatedAt:0};if(F.hasActiveSession!==_.hasActiveSession)return F.hasActiveSession?-1:1;if(F.hasActiveSession&&_.hasActiveSession)return _.lastUpdatedAt-F.lastUpdatedAt;const B=(C.label||C.branch||C.name||C.path||"").toLowerCase(),V=(N.label||N.branch||N.name||N.path||"").toLowerCase();return B.localeCompare(V)}).forEach(C=>{const N=ys(C.path)??C.path,T=t.gitBranches.get(N)?.trim()||null,M=C.branch?.trim()||null,_=!!(T&&M&&C.label&&Fu(C.label)===Fu(M))?T:C.label||C.name||Fa(N,t.homeDirectory)||N;S.push({id:`worktree:${N}`,label:_,branch:T||M,description:Xi(N,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:C,directory:N,folderScopeKey:N,sessions:y.get(N)??[]})});const P=y.get(k)??[];return P.length>0&&S.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&u?Vd(u):null,sessions:P}),S},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:a,buildGroupedSessions:i}},qI=t=>{const e=ot.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:a,sessionSearchContainerRef:i}=t;let o,c;e[0]!==n||e[1]!==a?(o=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{a.current?.focus(),a.current?.select()});return()=>window.cancelAnimationFrame(m)},c=[n,a],e[0]=n,e[1]=a,e[2]=o,e[3]=c):(o=e[2],c=e[3]),l.useEffect(o,c);let d,p;e[4]!==n||e[5]!==i||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=u=>{i.current&&(i.current.contains(u.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},p=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=d,e[8]=p):(d=e[7],p=e[8]),l.useEffect(d,p)},YI=t=>{const e=ot.c(42),{t:n}=pt(),[r,a]=l.useState(null),i=l.useRef(null);let o,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>()=>{i.current&&clearTimeout(i.current)},c=[],e[0]=o,e[1]=c):(o=e[0],c=e[1]),l.useEffect(o,c);let d;e[2]!==t?(d=(_,B,V,$)=>{if(V)return;const z=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if($&&$!==t.activeProjectId&&t.setActiveProjectIdOnly($),B&&B!==t.currentDirectory&&t.setDirectory(B,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),_===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(_),z();return}t.setCurrentSession(_,B??null),t.onSessionSelected?.(_),z()},e[2]=t,e[3]=d):d=e[3];const p=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const u=m;let f;e[6]!==t?(f=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=f):f=e[7];const b=f;let h;e[8]!==t?(h=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=h):h=e[9];const v=h;let x;e[10]!==t||e[11]!==n?(x=async _=>{const B=await t.shareSession(_.id);B&&B.share?.url?H.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):H.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=x):x=e[12];const g=x;let w;e[13]!==n?(w=(_,B)=>{An(_).then(V=>{if(!V.ok){H.error(n("sessions.sidebar.session.share.copyUrlError"));return}a(B),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{a(null),i.current=null},2e3)}).catch(()=>{H.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=w):w=e[14];const y=w;let k;e[15]!==t||e[16]!==n?(k=async _=>{await t.unshareSession(_)?H.success(n("sessions.sidebar.session.unshare.success")):H.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=k):k=e[17];const A=k;let j;e[18]!==t.childrenMap?(j=_=>{const B=[],V=$=>{(t.childrenMap.get($)??[]).forEach(Q=>{B.push(Q),V(Q.id)})};return V(_),B},e[18]=t.childrenMap,e[19]=j):j=e[19];const S=j,D=QI;let E;e[20]!==t||e[21]!==S||e[22]!==n?(E=async(_,B,V)=>{const $=B?.archivedBucket===!0,z=V?.descendantIds??D(S(_.id),$).map(XI);if(z.length===0){($?await t.deleteSession(_.id):await t.archiveSession(_.id))?H.success(n($?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):H.error(n($?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const Q=[_.id,...z];if($){const{deletedIds:ee,failedIds:re}=await t.deleteSessions(Q);ee.length>0&&H.success(ee.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:ee.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:ee.length})),re.length>0&&H.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:J}=await t.archiveSessions(Q);L.length>0&&H.success(L.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:L.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:L.length})),J.length>0&&H.error(J.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:J.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:J.length}))},e[20]=t,e[21]=S,e[22]=n,e[23]=E):E=e[23];const P=E;let C;e[24]!==t||e[25]!==S||e[26]!==P?(C=(_,B)=>{const V=B?.archivedBucket===!0,$=D(S(_.id),V).map(ZI);if(!t.showDeletionDialog){P(_,B,{descendantIds:$});return}t.setDeleteSessionConfirm({session:_,descendantCount:$.length,descendantIds:$,archivedBucket:V})},e[24]=t,e[25]=S,e[26]=P,e[27]=C):C=e[27];const N=C;let T;e[28]!==t||e[29]!==P?(T=async()=>{if(!t.deleteSessionConfirm)return;const{session:_,archivedBucket:B,descendantIds:V}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await P(_,{archivedBucket:B},{descendantIds:V})},e[28]=t,e[29]=P,e[30]=T):T=e[30];const M=T;let F;return e[31]!==M||e[32]!==r||e[33]!==v||e[34]!==y||e[35]!==N||e[36]!==b||e[37]!==u||e[38]!==p||e[39]!==g||e[40]!==A?(F={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:b,handleCancelEdit:v,handleShareSession:g,handleCopyShareUrl:y,handleUnshareSession:A,handleDeleteSession:N,confirmDeleteSession:M},e[31]=M,e[32]=r,e[33]=v,e[34]=y,e[35]=N,e[36]=b,e[37]=u,e[38]=p,e[39]=g,e[40]=A,e[41]=F):F=e[41],F};function JI(t){return!t.time?.archived}function QI(t,e){return e?t:t.filter(JI)}function XI(t){return t.id}function ZI(t){return t.id}const eP=["project:active:","project:archived:","recent:active:","recent:archived:"],tP=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:a,sessions:i,setPinnedSessionIds:o,groupOrderByProject:c,activeSessionByProject:d,collapsedGroups:p,setExpandedParents:m,setCollapsedProjects:u}=t,f=l.useRef(null),b=l.useRef(null),h=l.useCallback(()=>{if(e)return;const x=b.current;if(b.current=null,f.current=null,!x)return;const{projects:g}=Ts.getState(),w=g.map(y=>({...y,sidebarCollapsed:x.has(y.id)}));Is({projects:w}).catch(()=>{})},[e]),v=l.useCallback(x=>{typeof window>"u"||e||(b.current=x,f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{h()},700))},[e,h]);return l.useEffect(()=>()=>{typeof window<"u"&&f.current!==null&&window.clearTimeout(f.current),f.current=null,b.current=null},[]),l.useEffect(()=>{try{const x=r.getItem(a.sessionExpanded);if(x){const w=JSON.parse(x);Array.isArray(w)&&m(new Set(w.filter(y=>typeof y=="string")))}else{const w=r.getItem(a.sessionExpandedLegacy);if(w){try{const y=JSON.parse(w);if(Array.isArray(y)){const k=new Set;if(y.forEach(A=>{typeof A!="string"||A.length===0||eP.forEach(j=>k.add(`${j}${A}`))}),k.size>0){m(k);try{r.setItem(a.sessionExpanded,JSON.stringify(Array.from(k)))}catch{}}}}catch{}try{r.removeItem?.(a.sessionExpandedLegacy)}catch{}}}const g=r.getItem(a.projectCollapse);if(g){const w=JSON.parse(g);Array.isArray(w)&&u(new Set(w.filter(y=>typeof y=="string")))}}catch{}},[a.projectCollapse,a.sessionExpanded,a.sessionExpandedLegacy,r,u,m]),l.useEffect(()=>{if(!n)return;const x=new Set(i.map(g=>g.id));o(g=>{let w=!1;const y=new Set;return g.forEach(k=>{x.has(k)?y.add(k):w=!0}),w?y:g})},[n,i,o]),l.useEffect(()=>{try{const x=Object.fromEntries(c.entries());r.setItem(a.groupOrder,JSON.stringify(x))}catch{}},[c,a.groupOrder,r]),l.useEffect(()=>{try{const x=Object.fromEntries(d.entries());r.setItem(a.projectActiveSession,JSON.stringify(x))}catch{}},[d,a.projectActiveSession,r]),l.useEffect(()=>{try{r.setItem(a.groupCollapse,JSON.stringify(Array.from(p)))}catch{}},[p,a.groupCollapse,r]),{scheduleCollapsedProjectsPersist:v}},sP=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length);let i=0;const o=async()=>{for(;;){const c=i;if(i+=1,c>=t.length)return;a[c]=await n(t[c])}};return await Promise.all(Array.from({length:r},()=>o())),a},nP=t=>{const e=ot.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:o}=On(),c=Zs(rP);let d,p;e[0]!==c||e[1]!==o||e[2]!==n||e[3]!==a?(d=()=>{if(!o||n.length===0){a(new Map);return}n.forEach(x=>{c(x.normalizedPath,o)})},p=[n,o,c,a],e[0]=c,e[1]=o,e[2]=n,e[3]=a,e[4]=d,e[5]=p):(d=e[4],p=e[5]),l.useEffect(d,p);let m,u;e[6]!==r||e[7]!==n||e[8]!==a?(m=()=>{const x=new Map;n.forEach(g=>{x.set(g.id,r.get(g.normalizedPath)?.isGitRepo??null)}),a(x)},u=[n,r,a],e[6]=r,e[7]=n,e[8]=a,e[9]=m,e[10]=u):(m=e[9],u=e[10]),l.useEffect(m,u);let f;if(e[11]!==r||e[12]!==n){let x;e[14]!==r?(x=g=>{const w=r.get(g.normalizedPath)?.branch??"";return`${g.id}:${w}`},e[14]=r,e[15]=x):x=e[15],f=n.map(x).join("|"),e[11]=r,e[12]=n,e[13]=f}else f=e[13];const b=f;let h;e[16]!==n||e[17]!==i?(h=()=>{let x=!1;return(async()=>{const w=await sP(n,2,iP);x||i(y=>{const k=new Map(y);return w.forEach(A=>{const{id:j,branch:S}=A;S&&k.set(j,S)}),k})})(),()=>{x=!0}},e[16]=n,e[17]=i,e[18]=h):h=e[18];let v;e[19]!==n||e[20]!==b||e[21]!==i?(v=[n,b,i],e[19]=n,e[20]=b,e[21]=i,e[22]=v):v=e[22],l.useEffect(h,v)};function rP(t){return t.ensureStatus}function aP(){return null}async function iP(t){const e=await oo(t.normalizedPath).catch(aP);return{id:t.id,branch:e}}const oP=t=>{const e=ot.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let o;e[0]!==r?(o=new Map,r.forEach(b=>{const h=ys(b.directory??null)??ys(b.project?.worktree??null);if(!h)return;const v=o.get(h)??[];v.push(b),o.set(h,v)}),e[0]=r,e[1]=o):o=e[1];const c=o;let d;e[2]!==i||e[3]!==n||e[4]!==c?(d=b=>{const h=n?[]:i.get(b.normalizedPath)??[],v=[b.normalizedPath,...h.map(lP).filter(cP)],x=new Set,g=[];return v.forEach(w=>{(c.get(w)??[]).forEach(k=>{x.has(k.id)||(x.add(k.id),g.push(k))})}),g},e[2]=i,e[3]=n,e[4]=c,e[5]=d):d=e[5];const p=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=b=>{if(n){const y=a.filter(A=>{const j=ys(A.directory??null),S=ys(A.project?.worktree??null);return j?j===b.normalizedPath:S===b.normalizedPath}),k=r.filter(A=>A.time?.archived||ys(A.directory??null)?!1:ys(A.project?.worktree??null)===b.normalizedPath);return gi([...y,...k])}const h=n?[]:i.get(b.normalizedPath)??[],v=new Set([b.normalizedPath,...h.map(dP).filter(uP)]),g=(y=>y.filter(k=>Zi(k,b.normalizedPath,v)))(a),w=r.filter(y=>{if(y.time?.archived||ys(y.directory??null))return!1;const A=ys(y.project?.worktree??null);return A?A===b.normalizedPath||A.startsWith(`${b.normalizedPath}/`):!1});return gi([...g,...w])},e[6]=a,e[7]=i,e[8]=n,e[9]=r,e[10]=m):m=e[10];const u=m;let f;return e[11]!==u||e[12]!==p?(f={getSessionsForProject:p,getArchivedSessionsForProject:u},e[11]=u,e[12]=p,e[13]=f):f=e[13],f};function lP(t){return ys(t.path)??t.path}function cP(t){return!!t}function dP(t){return ys(t.path)??t.path}function uP(t){return!!t}const mP=t=>{const e=ot.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:a,normalizedProjects:i,isVSCode:o,availableWorktreesByProject:c,cleanupSessions:d}=t;let p,m;e[0]!==a||e[1]!==c||e[2]!==d||e[3]!==n||e[4]!==o||e[5]!==i||e[6]!==r?(p=()=>{if(n)return;const u=new Map;r.forEach(h=>{const v=ys(h.directory??null);if(!v)return;const x=u.get(v);if(x){x.add(h.id);return}u.set(v,new Set([h.id]))}),i.forEach(h=>{const v=Vd(h.normalizedPath),x=o?[]:c.get(h.normalizedPath)??[],g=new Set([h.normalizedPath,...x.map(pP).filter(fP)]),w=gi([...a,...r.filter(y=>y.time?.archived||ys(y.directory??null)?!1:Zi(y,h.normalizedPath,g))]).filter(y=>Zi(y,h.normalizedPath,g));u.set(v,new Set(w.map(hP)))});const f=Yn.getState().foldersMap;new Set([...Object.keys(f),...u.keys()]).forEach(h=>{d(h,u.get(h)??new Set)})},m=[a,c,d,n,o,i,r],e[0]=a,e[1]=c,e[2]=d,e[3]=n,e[4]=o,e[5]=i,e[6]=r,e[7]=p,e[8]=m):(p=e[7],m=e[8]),l.useEffect(p,m)};function pP(t){return ys(t.path)??t.path}function fP(t){return!!t}function hP(t){return t.id}const gP=t=>{const e=ot.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(f=>{const b=f.target.dataset.projectId;b&&c(h=>{const v=new Set(h);return f.isIntersecting?v.delete(b):v.add(b),v})})},{threshold:0});return a.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=a,e[3]=d):d=e[3];let p;return e[4]!==n||e[5]!==a||e[6]!==r?(p=[n,a,r],e[4]=n,e[5]=a,e[6]=r,e[7]=p):p=e[7],l.useEffect(d,p),o},xP=t=>{const e=ot.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:o,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:f,alwaysShowActions:b,isRenaming:h,renameDraft:v,onRenameDraftChange:x,onRenameSave:g,onRenameCancel:w,droppableRef:y,isDropTarget:k,onNewSession:A,onNewSubFolder:j,depth:S,hideActions:D,archivedBucket:E}=t,C=b===void 0?f===void 0?!1:f:b,N=h===void 0?!1:h,T=v===void 0?"":v,M=k===void 0?!1:k,F=S===void 0?0:S,_=D===void 0?!1:D,B=E===void 0?!1:E,{t:V}=pt(),[$,z]=l.useState(!1),[Q,L]=l.useState(""),J=l.useRef(null),ee=N||$,re=N?T:Q;let q;e[0]!==n.name?(q=()=>{L(n.name),z(!0)},e[0]=n.name,e[1]=q):q=e[1];const ce=q;let ae;e[2]!==re||e[3]!==n.name||e[4]!==N||e[5]!==c||e[6]!==g?(ae=()=>{const X=re.trim();X&&X!==n.name&&c(X),N&&g&&g(),z(!1),L("")},e[2]=re,e[3]=n.name,e[4]=N,e[5]=c,e[6]=g,e[7]=ae):ae=e[7];const R=ae;let U;e[8]!==N||e[9]!==w?(U=()=>{N&&w&&w(),z(!1),L("")},e[8]=N,e[9]=w,e[10]=U):U=e[10];const W=U;let Z;e[11]!==N||e[12]!==x?(Z=X=>{N&&x?x(X):L(X)},e[11]=N,e[12]=x,e[13]=Z):Z=e[13];const K=Z;let ie,Ne;e[14]!==N?(ie=()=>{if(!N)return;const X=()=>{const le=J.current;le&&(le.focus(),le.select())},G=requestAnimationFrame(X),Te=window.setTimeout(X,0);return()=>{cancelAnimationFrame(G),window.clearTimeout(Te)}},Ne=[N],e[14]=N,e[15]=ie,e[16]=Ne):(ie=e[15],Ne=e[16]),l.useEffect(ie,Ne);const ne=i?"folder":"folder-open",pe=F>0&&"ml-3";let je;e[17]!==pe?(je=ue("oc-folder",pe),e[17]=pe,e[18]=je):je=e[18];const oe=M&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let Se;e[19]!==oe?(Se=ue("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",oe),e[19]=oe,e[20]=Se):Se=e[20];const se=ee?void 0:o,we=ee?void 0:"button",Ae=ee?void 0:0;let ve;e[21]!==o||e[22]!==ee?(ve=ee?void 0:X=>{(X.key==="Enter"||X.key===" ")&&(X.preventDefault(),o())},e[21]=o,e[22]=ee,e[23]=ve):ve=e[23];let ye;e[24]!==n.name||e[25]!==i||e[26]!==V?(ye=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]=ye):ye=e[27];const Ie=B?C?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let he;e[28]!==Ie?(he=ue("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",Ie),e[28]=Ie,e[29]=he):he=e[29];const me=M?"text-primary":"text-muted-foreground";let Ee;e[30]!==me?(Ee=ue("h-3.5 w-3.5 flex-shrink-0",me),e[30]=me,e[31]=Ee):Ee=e[31];let Ve;e[32]!==ne||e[33]!==Ee?(Ve=s.jsx(I,{name:ne,className:Ee}),e[32]=ne,e[33]=Ee,e[34]=Ve):Ve=e[34];let Y;e[35]!==re||e[36]!==n.name||e[37]!==W||e[38]!==K||e[39]!==R||e[40]!==i||e[41]!==M||e[42]!==ee||e[43]!==r||e[44]!==V?(Y=ee?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:yP,onMouseDown:vP,onSubmit:X=>{X.preventDefault(),R()},children:[s.jsx("input",{ref:J,value:re,onChange:X=>K(X.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:wP,onPointerDown:jP,onMouseDown:NP,onKeyDown:X=>{if(X.key==="Escape"){X.stopPropagation(),W();return}(X.key===" "||X.key==="Enter")&&X.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:SP,onPointerDown:kP,onMouseDown:CP,children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:X=>{X.stopPropagation(),W()},onPointerDown:IP,onMouseDown:PP,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:ue("typography-ui-label font-semibold truncate",M?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=re,e[36]=n.name,e[37]=W,e[38]=K,e[39]=R,e[40]=i,e[41]=M,e[42]=ee,e[43]=r,e[44]=V,e[45]=Y):Y=e[45];let ke;e[46]!==he||e[47]!==Ve||e[48]!==Y?(ke=s.jsxs("div",{className:he,children:[Ve,Y]}),e[46]=he,e[47]=Ve,e[48]=Y,e[49]=ke):ke=e[49];let Be;e[50]!==C||e[51]!==B||e[52]!==F||e[53]!==n.name||e[54]!==ce||e[55]!==_||e[56]!==d||e[57]!==A||e[58]!==j||e[59]!==ee||e[60]!==V?(Be=!ee&&(!_||B)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:ue("flex items-center gap-0.5 transition-opacity",C?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",B&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!B&&A?s.jsx("button",{type:"button",onClick:X=>{X.stopPropagation(),A()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:V("sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})}):null,!B&&j&&F===0?s.jsx("button",{type:"button",onClick:X=>{X.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(I,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,B?null:s.jsx("button",{type:"button",onClick:X=>{X.stopPropagation(),ce()},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(I,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:X=>{X.stopPropagation(),d()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":B?V("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):V("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=C,e[51]=B,e[52]=F,e[53]=n.name,e[54]=ce,e[55]=_,e[56]=d,e[57]=A,e[58]=j,e[59]=ee,e[60]=V,e[61]=Be):Be=e[61];let Ce;e[62]!==y||e[63]!==Se||e[64]!==se||e[65]!==we||e[66]!==Ae||e[67]!==ve||e[68]!==ye||e[69]!==ke||e[70]!==Be?(Ce=s.jsxs("div",{ref:y,className:Se,onClick:se,role:we,tabIndex:Ae,onKeyDown:ve,"aria-label":ye,children:[ke,Be]}),e[62]=y,e[63]=Se,e[64]=se,e[65]=we,e[66]=Ae,e[67]=ve,e[68]=ye,e[69]=ke,e[70]=Be,e[71]=Ce):Ce=e[71];let ge;e[72]!==B||e[73]!==m||e[74]!==i||e[75]!==u||e[76]!==p||e[77]!==r||e[78]!==a||e[79]!==V?(ge=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(X=>p(X,0,m??null,u??null,B)):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]=B,e[73]=m,e[74]=i,e[75]=u,e[76]=p,e[77]=r,e[78]=a,e[79]=V,e[80]=ge):ge=e[80];let O;return e[81]!==je||e[82]!==Ce||e[83]!==ge?(O=s.jsxs("div",{className:je,children:[Ce,ge]}),e[81]=je,e[82]=Ce,e[83]=ge,e[84]=O):O=e[84],O},bP=l.memo(xP);function yP(t){return t.stopPropagation()}function vP(t){return t.stopPropagation()}function wP(t){return t.stopPropagation()}function jP(t){return t.stopPropagation()}function NP(t){return t.stopPropagation()}function SP(t){return t.stopPropagation()}function kP(t){return t.stopPropagation()}function CP(t){return t.stopPropagation()}function IP(t){return t.stopPropagation()}function PP(t){return t.stopPropagation()}const AP=t=>{const e=ot.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:a,children:i}=t,o=`session-drag:${n}`;let c;e[0]!==r||e[1]!==n||e[2]!==a?(c={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:a},e[0]=r,e[1]=n,e[2]=a,e[3]=c):c=e[3];let d;e[4]!==o||e[5]!==c?(d={id:o,data:c},e[4]=o,e[5]=c,e[6]=d):d=e[6];const{attributes:p,listeners:m,setNodeRef:u,isDragging:f}=Px(d);let b;e[7]!==m?(b=g=>{g.stopPropagation(),m?.onPointerDown&&m.onPointerDown(g)},e[7]=m,e[8]=b):b=e[8];const h=b,v=f?"opacity-30":void 0;let x;return e[9]!==p||e[10]!==i||e[11]!==h||e[12]!==u||e[13]!==v?(x=s.jsx("div",{ref:u,...p,onPointerDown:h,className:v,children:i}),e[9]=p,e[10]=i,e[11]=h,e[12]=u,e[13]=v,e[14]=x):x=e[14],x},DP=t=>{const e=ot.c(11),{folderId:n,children:r}=t,a=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let o;e[2]!==a||e[3]!==i?(o={id:a,data:i},e[2]=a,e[3]=i,e[4]=o):o=e[4];const{setNodeRef:c,isOver:d}=Ax(o);let p;e[5]!==r||e[6]!==d||e[7]!==c?(p=r(c,d),e[5]=r,e[6]=d,e[7]=c,e[8]=p):p=e[8];let m;return e[9]!==p?(m=s.jsx(s.Fragment,{children:p}),e[9]=p,e[10]=m):m=e[10],m},TP=t=>{const e=ot.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:a,children:i}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[0]=o):o=e[0];const c=Gi(ni(qi,o)),[d,p]=l.useState(null),[m,u]=l.useState("Session"),[f,b]=l.useState(null),[h,v]=l.useState(null);if(!n){let S;return e[1]!==i?(S=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=S):S=e[2],S}let x;e[3]!==a?(x=S=>{p(null),b(null),v(null);const{active:D,over:E}=S;if(!E)return;const P=D.data.current,C=E.data.current;P?.type==="session"&&P.sessionId&&C?.type==="folder"&&C.folderId&&a(P.sessionId,C.folderId)},e[3]=a,e[4]=x):x=e[4];const g=x;let w,y;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=S=>{const D=S.active.data.current;if(D?.type==="session"&&D.sessionId){p(D.sessionId),u(D.sessionTitle??"Session");const E=S.active.rect.current.initial?.width,P=S.active.rect.current.initial?.height;b(typeof E=="number"?E:null),v(typeof P=="number"?P:null)}},y=()=>{p(null),b(null),v(null)},e[5]=w,e[6]=y):(w=e[5],y=e[6]);let k;e[7]!==h||e[8]!==d||e[9]!==m||e[10]!==f||e[11]!==r?(k=d&&r?s.jsxs("div",{style:{width:f?`${f}px`:"auto",height:h?`${h}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(I,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=h,e[8]=d,e[9]=m,e[10]=f,e[11]=r,e[12]=k):k=e[12];let A;e[13]!==k?(A=s.jsx(nl,{children:k}),e[13]=k,e[14]=A):A=e[14];let j;return e[15]!==i||e[16]!==g||e[17]!==c||e[18]!==A?(j=s.jsxs(Yi,{sensors:c,collisionDetection:Ji,onDragStart:w,onDragCancel:y,onDragEnd:g,children:[i,A]}),e[15]=i,e[16]=g,e[17]=c,e[18]=A,e[19]=j):j=e[19],j},Ca=nr()(ao(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"})),MP=50,EP=28;function RP(t){const{t:e}=pt(),{group:n,groupKey:r,projectId:a,hideGroupLabel:i,hasSessionSearchQuery:o,normalizedSessionSearchQuery:c,groupSearchDataByGroup:d,expandedSessionGroups:p,collapsedGroups:m,hideDirectoryControls:u,collapsedFolderIds:f,toggleFolderCollapse:b,renameFolder:h,deleteFolder:v,showDeletionDialog:x,setDeleteFolderConfirm:g,renderSessionNode:w,projectRepoStatus:y,lastRepoStatus:k,toggleGroupSessionLimit:A,mobileVariant:j,alwaysShowActions:S,activeProjectId:D,setActiveProjectIdOnly:E,setActiveMainTab:P,setSessionSwitcherOpen:C,openNewSessionDraft:N,addSessionToFolder:T,createFolderAndStartRename:M,renamingFolderId:F,renameFolderDraft:_,setRenameFolderDraft:B,setRenamingFolderId:V,pinnedSessionIds:$,sessionOrderIndex:z,prVisualStateByDirectoryBranch:Q,onToggleCollapsedGroup:L,dragHandleProps:J,compactBodyPadding:ee=!1}=t,re=l.useCallback((st,yt)=>{const Mt=z.get(st.session.id),Bt=z.get(yt.session.id);if(Mt!==void 0||Bt!==void 0){if(Mt===void 0)return 1;if(Bt===void 0)return-1;if(Mt!==Bt)return Mt-Bt}return ii(st.session,yt.session,$)},[$,z]),q=o?d.get(n):null,ce=Ca(st=>st.displayMode),ae=Yn(st=>st.foldersMap),R=ce==="minimal",U=p.has(r),W=o?!1:m.has(r),Z=u?10:5,K=o?q?.groupMatches===!0:!1,ie=o,Ne=l.useMemo(()=>[...ie?q?.filteredNodes??[]:n.sessions].sort(re),[re,n.sessions,q?.filteredNodes,ie]),ne=n.folderScopeKey??ys(n.directory??null),fe=l.useMemo(()=>ne?ae[ne]??[]:[],[ne,ae]),pe=l.useMemo(()=>{const st=new Map,yt=Mt=>{Mt.forEach(Bt=>{st.set(Bt.session.id,Bt),Bt.children.length>0&&yt(Bt.children)})};return yt(Ne),st},[Ne]),je=l.useMemo(()=>fe.map(st=>{const yt=st.sessionIds.map(Mt=>pe.get(Mt)).filter(Mt=>!!Mt).sort(re);return{folder:st,nodes:yt}}),[fe,pe,re]),oe=l.useMemo(()=>{const st=new Map(je.map(ft=>[ft.folder.id,ft])),yt=new Map;for(const{folder:ft}of je){if(!ft.parentId)continue;const It=yt.get(ft.parentId);It?It.push(ft.id):yt.set(ft.parentId,[ft.id])}const Mt=new Map,Bt=ft=>{const It=Mt.get(ft);if(It!==void 0)return It;const ss=st.get(ft);if(!ss)return Mt.set(ft,!1),!1;const _t=yt.get(ft)??[];if(n.isArchivedBucket&&ss.nodes.length===0){const jt=_t.some(as=>Bt(as));return Mt.set(ft,jt),jt}if(!o||ss.folder.name.toLowerCase().includes(c)||ss.nodes.length>0)return Mt.set(ft,!0),!0;const ct=_t.some(jt=>Bt(jt));return Mt.set(ft,ct),ct};return je.filter(({folder:ft})=>Bt(ft.id))},[je,n.isArchivedBucket,o,c]),Se=l.useMemo(()=>new Set(oe.flatMap(st=>st.folder.sessionIds)),[oe]),se=l.useMemo(()=>Ne.filter(st=>!Se.has(st.session.id)),[Ne,Se]),we=l.useMemo(()=>oe.filter(({folder:st})=>!st.parentId),[oe]),Ae=se.length,ve=n.isArchivedBucket||o||U?se:se.slice(0,Z),ye=Ae-ve.length,Ie=n.isArchivedBucket===!0&&!o&&ve.length>=MP,he=l.useRef(null),[me,Ee]=l.useState(null),[Ve,Y]=l.useState(0),ke=Rf({count:ve.length,getScrollElement:()=>me,estimateSize:()=>EP,overscan:8,enabled:Ie&&me!==null,scrollMargin:Ve});l.useLayoutEffect(()=>{if(!Ie){me!==null&&Ee(null),Ve!==0&&Y(0);return}const st=he.current;if(!st)return;let yt=me;if(!yt||!yt.contains(st)){let Bt=st.parentElement;for(;Bt;){const ft=window.getComputedStyle(Bt);if(ft.overflowY==="auto"||ft.overflowY==="scroll"){yt=Bt;break}Bt=Bt.parentElement}if(yt!==me){Ee(yt);return}}if(!yt)return;const Mt=st.getBoundingClientRect().top-yt.getBoundingClientRect().top+yt.scrollTop;Y(Bt=>Math.abs(Bt-Mt)<1?Bt:Mt)}),l.useEffect(()=>{if(!Ie||!me)return;const st=new ResizeObserver(()=>{ke.measure()});return st.observe(me),()=>st.disconnect()},[Ie,me,ke]);const Be=ke.getTotalSize(),Ce=Ie&&me!==null?ke.getVirtualItems():[];if(o&&!K&&we.length===0&&se.length===0)return null;const ge=st=>{const yt=[],Mt=Bt=>{Bt.forEach(ft=>{yt.push(ft.session),ft.children.length>0&&Mt(ft.children)})};return Mt(st),yt},O=ge(Ne),X=a&&y.has(a)?!!y.get(a):k,G=ys(n.directory??null),Te=n.branch?.trim()??null,le=G&&Te?Q.get(`${G}::${Te}`)??null:null,We=!!(le&&n.branch),de=!le&&!n.isMain&&!!n.branch,Fe=le?.visualState??null,rt=le&&le.state==="open"&&le.checks?e("sessions.sidebar.group.pr.checksPassed",{success:le.checks.success,total:le.checks.total}):null,Oe=le&&le.state==="open"&&le.checks?[le.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:le.checks.failure}):null,le.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:le.checks.pending}):null].filter(st=>!!st).join(", "):null,Ye=le&&le.state==="open"?le.mergeableState==="blocked"||le.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):le.mergeableState==="clean"||le.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,Ge=le&&le.state==="open"&&le.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:le.mergeableState}):null,it=le?.base??null,Qe=le?.head??null,at=(()=>{if(!le)return n.branch&&gy(n.branch,n.label)?{label:n.branch,color:null}:null;switch(le.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return le.canMerge===!0||le.mergeableState==="clean"||le.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:le.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked"),color:"var(--pr-blocked)"};case"draft":return{label:e("sessions.sidebar.group.pr.status.draft"),color:"var(--pr-draft)"};case"closed":return{label:e("sessions.sidebar.group.pr.status.closed"),color:"var(--pr-closed)"};default:return null}})(),nt=at?.color??(Fe?`var(--pr-${Fe})`:void 0),be=st=>{st.preventDefault(),st.stopPropagation();const yt=le?.url;yt&&Zn(yt)},He=(st,yt,Mt)=>{const Bt=oe.filter(({folder:_t})=>_t.parentId===st.id),ft=Bt.length>0?s.jsx(s.Fragment,{children:Bt.map(({folder:_t,nodes:qt})=>He(_t,qt,Mt+1))}):void 0,It=_t=>{const qt=oe.find(({folder:jt})=>jt.id===_t)?.nodes??[],ct=oe.filter(({folder:jt})=>jt.parentId===_t);return[...ge(qt),...ct.flatMap(({folder:jt})=>It(jt.id))]},ss=n.isArchivedBucket?It(st.id):[];return s.jsx(DP,{folderId:st.id,children:(_t,qt)=>s.jsx(bP,{folder:st,sessions:yt,subFolderItems:ft,isCollapsed:o?!1:f.has(st.id),onToggle:()=>b(st.id),onRename:ct=>{ne&&h(ne,st.id,ct)},onDelete:()=>{if(n.isArchivedBucket){wr.requestDelete({sessions:ss,mode:"session"});return}if(!ne)return;if(!x){v(ne,st.id);return}const ct=oe.filter(({folder:as})=>as.parentId===st.id).length,jt=yt.length;g({scopeKey:ne,folderId:st.id,folderName:st.name,subFolderCount:ct,sessionCount:jt})},renderSessionNode:w,groupDirectory:n.directory,projectId:a,mobileVariant:j,alwaysShowActions:S,isRenaming:F===st.id,renameDraft:F===st.id?_:void 0,onRenameDraftChange:ct=>B(ct),onRenameSave:()=>{const ct=_.trim();ct&&ne&&h(ne,st.id,ct),V(null),B("")},onRenameCancel:()=>{V(null),B("")},droppableRef:_t,isDropTarget:qt,depth:Mt,onNewSession:()=>{a&&a!==D&&E(a),P("chat"),j&&C(!1),N({directoryOverride:n.directory,targetFolderId:st.id})},onNewSubFolder:Mt===0?()=>{ne&&M(ne,st.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},st.id)},_e=()=>we.map(({folder:st,nodes:yt})=>He(st,yt,0)),tt=!!(!n.isMain&&n.worktree),ut=S?tt?"pr-14":"pr-7":R?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(TP,{scopeKey:ne,hasFolders:oe.length>0,onSessionDroppedOnFolder:(st,yt)=>{ne&&T(ne,yt,st)},children:[_e(),Ie?s.jsx("div",{ref:he,style:{position:"relative",height:Be>0?Be:void 0,width:"100%"},children:Ce.map(st=>{const yt=ve[st.index];return yt?s.jsx("div",{"data-index":st.index,ref:ke.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${st.start-Ve}px)`},children:w(yt,0,n.directory,a,!0)},st.key):null})}):ve.map(st=>w(st,0,n.directory,a,n.isArchivedBucket===!0)),Ae===0&&oe.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,ye>0&&!U?s.jsx("button",{type:"button",onClick:()=>A(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:ye===1?e("sessions.sidebar.group.showMoreSingle",{count:ye}):e("sessions.sidebar.group.showMorePlural",{count:ye})}):null,U&&Ae>Z?s.jsx("button",{type:"button",onClick:()=>A(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:ue("oc-group-body",ze),children:qe})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:ue("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:st=>{(st.key==="Enter"||st.key===" ")&&(st.preventDefault(),L(r))},"aria-label":W?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!W,children:[s.jsx("div",{ref:J?.setActivatorNodeRef,className:ue("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",ut),...J?.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:We&&le?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"git-branch",className:ue("h-3.5 w-3.5 shrink-0",S?"hidden":"group-hover/gh:hidden"),style:nt?{color:nt}:void 0}),s.jsx("span",{className:ue("text-muted-foreground h-3.5 w-3.5 items-center justify-center",S?"inline-flex":"hidden group-hover/gh:inline-flex"),children:W?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),le.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:st=>st.stopPropagation(),onClick:be,children:["#",le.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",le.number]})]})}),s.jsx(Ct,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[it||Qe?s.jsx("div",{className:"text-muted-foreground truncate",children:it&&Qe?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:it}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Qe})]}):s.jsx("span",{children:it??Qe??""})}):null,Ge?s.jsx("div",{className:"text-muted-foreground truncate",children:Ge}):null,Ye||rt?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Ye??"",Ye&&rt?" • ":"",rt??"",Oe?` (${Oe})`:""]}):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(I,{name:"archive",className:ue("h-3.5 w-3.5 shrink-0 text-muted-foreground",S?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:ue("text-muted-foreground h-3.5 w-3.5 items-center justify-center",S?"inline-flex":"hidden group-hover/gh:inline-flex"),children:W?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ui(n.label,c)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"git-branch",className:ue("h-3.5 w-3.5 shrink-0 text-muted-foreground",S?"hidden":"group-hover/gh:hidden"),style:nt?{color:nt}:void 0}),s.jsx("span",{className:ue("text-muted-foreground h-3.5 w-3.5 items-center justify-center",S?"inline-flex":"hidden group-hover/gh:inline-flex"),children:W?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ui(n.label,c)})]}):Ui(n.label,c)}),de&&at?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(I,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||X?We&&le?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:nt?{color:nt}:void 0})})}),s.jsx(Ct,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[it||Qe?s.jsx("div",{className:"text-muted-foreground truncate",children:it&&Qe?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:it}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Qe})]}):s.jsx("span",{children:it??Qe??""})}):null,Ge?s.jsx("div",{className:"text-muted-foreground truncate",children:Ge}):null,Ye||rt?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Ye??"",Ye&&rt?" • ":"",rt??"",Oe?` (${Oe})`:""]}):null]})})]}):s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:nt?{color:nt}:void 0}):null,s.jsx("span",{className:ue("min-w-0 truncate text-[11px] font-medium",!at.color&&"text-muted-foreground/80"),style:at.color?{color:at.color}:void 0,children:at.label})]}):null]})}),n.isArchivedBucket&&O.length>0?s.jsx("div",{className:ue("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",S?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:st=>{st.stopPropagation(),wr.requestDelete({sessions:O,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Ct,{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:ue("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",S?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:st=>{st.stopPropagation(),wr.requestDelete({sessions:O,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:ue("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",S?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:st=>{st.stopPropagation(),a&&a!==D&&E(a),P("chat"),j&&C(!1),N({directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),W?null:s.jsx("div",{className:ue("oc-group-body",ze),children:qe})]})}function FP(t){const e=ot.c(37),{t:n}=pt(),{hideDirectoryControls:r,handleOpenDirectoryDialog:a,handleNewSession:i,canOpenMultiRun:o,openMultiRunLauncher:c,headerActionIconClass:d,reserveHeaderActionsSpace:p,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:f,sessionSearchInputRef:b,sessionSearchQuery:h,setSessionSearchQuery:v,hasSessionSearchQuery:x,searchMatchCount:g,collapseAllProjects:w,expandAllProjects:y,openScheduledTasksDialog:k,selectionModeEnabled:A,onToggleSelectionMode:j,showSidebarToggle:S,onToggleSidebar:D,avoidWindowControlsOverlay:E}=t,P=S===void 0?!1:S,C=E===void 0?!1:E,N=Ca(_P),T=Ca(BP),M=Ca($P),F=Ca(LP);if(r)return null;const _=P?C?"pl-[5.5rem] pr-3":"pl-3 pr-3":"px-2.5 py-1";let B;e[0]!==_?(B=ue("select-none flex-shrink-0",_),e[0]=_,e[1]=B):B=e[1];let V;e[2]!==C||e[3]!==P?(V=P&&C?{paddingTop:"var(--oc-safe-area-top, 0px)"}:void 0,e[2]=C,e[3]=P,e[4]=V):V=e[4];let $;e[5]!==C||e[6]!==o||e[7]!==w||e[8]!==N||e[9]!==y||e[10]!==i||e[11]!==a||e[12]!==x||e[13]!==m||e[14]!==d||e[15]!==u||e[16]!==j||e[17]!==D||e[18]!==c||e[19]!==k||e[20]!==p||e[21]!==g||e[22]!==A||e[23]!==b||e[24]!==h||e[25]!==M||e[26]!==f||e[27]!==v||e[28]!==T||e[29]!==P||e[30]!==n||e[31]!==F?($=p?s.jsxs("div",{className:ue("flex h-auto flex-col gap-1",P?C?"min-h-[calc(var(--oc-header-height,56px)-var(--oc-safe-area-top,0px))] justify-center":"min-h-[var(--oc-header-height,56px)] justify-center":"min-h-8"),children:[s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[P&&D?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50","aria-label":n("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(I,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.closeSessions")})})]}):null,s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:m,"aria-label":n("sessions.sidebar.header.actions.addProject"),children:s.jsx(I,{name:"folder-add",className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.addProject")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:m,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(I,{name:"chat-new",className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:m,"aria-label":n("sessions.sidebar.header.actions.newMultiRun"),disabled:!o,children:s.jsx(xy,{className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newMultiRun")})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:k,className:m,"aria-label":n("sessions.sidebar.header.actions.scheduledTasks"),children:s.jsx(I,{name:"calendar-schedule",className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.scheduledTasks")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>f(OP),className:m,"aria-label":n("sessions.sidebar.header.actions.searchSessions"),"aria-expanded":u,children:s.jsx(I,{name:"search",className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.searchSessions")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:ue(m,A&&"bg-interactive-hover text-primary"),"aria-label":n(A?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),"aria-pressed":A,children:s.jsx(I,{name:"checkbox-multiple",className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n(A?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions")})})]}),s.jsxs(Fs,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":n("sessions.sidebar.header.actions.sessionDisplayMode"),children:s.jsx(I,{name:"equalizer-2",className:d})})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.displayMode.label")})})]}),s.jsxs(Rs,{align:"end",className:"min-w-[160px]",children:[s.jsxs($t,{onClick:()=>M("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),N==="default"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs($t,{onClick:()=>M("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),N==="minimal"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Cn,{}),s.jsxs($t,{onClick:F,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),T?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Cn,{}),s.jsxs($t,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(I,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs($t,{onClick:y,className:"flex items-center gap-2",children:[s.jsx(I,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]})]})]})]}),u?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[x?s.jsx("span",{children:g===1?n("sessions.sidebar.header.search.matchCountSingle",{count:g}):n("sessions.sidebar.header.search.matchCountPlural",{count:g})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:b,value:h,onChange:Q=>v(Q.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:Q=>{Q.key==="Escape"&&(Q.stopPropagation(),x?v(""):f(!1))}}),h.length>0?s.jsx("button",{type:"button",onClick:()=>v(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[5]=C,e[6]=o,e[7]=w,e[8]=N,e[9]=y,e[10]=i,e[11]=a,e[12]=x,e[13]=m,e[14]=d,e[15]=u,e[16]=j,e[17]=D,e[18]=c,e[19]=k,e[20]=p,e[21]=g,e[22]=A,e[23]=b,e[24]=h,e[25]=M,e[26]=f,e[27]=v,e[28]=T,e[29]=P,e[30]=n,e[31]=F,e[32]=$):$=e[32];let z;return e[33]!==B||e[34]!==V||e[35]!==$?(z=s.jsx("div",{className:B,style:V,children:$}),e[33]=B,e[34]=V,e[35]=$,e[36]=z):z=e[36],z}function OP(t){return!t}function LP(t){return t.toggleRecentSection}function $P(t){return t.setDisplayMode}function BP(t){return t.showRecentSection}function _P(t){return t.displayMode}const df=7;function zP(t){const e=ot.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=pt();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[p,m]=l.useState(d);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=y=>{c(k=>{const A=new Set(k);return A.has(y)?A.delete(y):A.add(y),A})},e[2]=u):u=e[2];const f=u;let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=y=>{m(k=>{const A=new Set(k);return A.has(y)?A.delete(y):A.add(y),A})},e[3]=b):b=e[3];const h=b;let v,x,g;if(e[4]!==o||e[5]!==p||e[6]!==r||e[7]!==n||e[8]!==a){g=Symbol.for("react.early_return_sentinel");e:{const y=n.filter(VP);if(y.length===0){g=null;break e}v="space-y-2 pb-2 pt-1";let k;e[12]!==o||e[13]!==p||e[14]!==r||e[15]!==a?(k=A=>{const j=o.has(A.key),S=p.has(A.key),D=S?A.items:A.items.slice(0,df),E=A.items.length-D.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>f(A.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:A.title})]}),j?null:s.jsxs("div",{className:ue("space-y-0.5 pl-7"),children:[D.map(P=>r(P.node,0,P.groupDirectory,P.projectId,!1,P.secondaryMeta,"recent")),E>0&&!S?s.jsx("button",{type:"button",onClick:()=>h(A.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:E===1?a("sessions.sidebar.group.showMoreSingle",{count:E}):a("sessions.sidebar.group.showMorePlural",{count:E})}):null,S&&A.items.length>df?s.jsx("button",{type:"button",onClick:()=>h(A.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:a("sessions.sidebar.group.showFewer")}):null]})]},A.key)},e[12]=o,e[13]=p,e[14]=r,e[15]=a,e[16]=k):k=e[16],x=y.map(k)}e[4]=o,e[5]=p,e[6]=r,e[7]=n,e[8]=a,e[9]=v,e[10]=x,e[11]=g}else v=e[9],x=e[10],g=e[11];if(g!==Symbol.for("react.early_return_sentinel"))return g;let w;return e[17]!==v||e[18]!==x?(w=s.jsx("div",{className:v,children:x}),e[17]=v,e[18]=x,e[19]=w):w=e[19],w}function VP(t){return t.items.length>0}const Oc="inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50";function UP(t){const e=ot.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:a,onOpenUpdate:i,showRuntimeButtons:o,showUpdateButton:c}=t,d=o===void 0?!0:o,p=c===void 0?!0:c,{t:m}=pt();let u;e[0]!==a||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(u=d?s.jsxs(s.Fragment,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Oc,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(I,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:Oc,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(I,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:Oc,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(I,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=m,e[5]=u):u=e[5];let f;e[6]!==i||e[7]!==p||e[8]!==m?(f=p?s.jsx(xe,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=p,e[8]=m,e[9]=f):f=e[9];let b;return e[10]!==u||e[11]!==f?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[u,f]}),e[10]=u,e[11]=f,e[12]=b):b=e[12],b}const WP=t=>{const e=ot.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:o,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:f,isStuck:b,hideDirectoryControls:h,alwaysShowActions:v,onToggle:x,onNewSession:g,onNewWorktreeSession:w,onRenameStart:y,onClose:k,sentinelRef:A,children:j,showCreateButtons:S,hideHeader:D,openSidebarMenuKey:E,setOpenSidebarMenuKey:P}=t,C=S===void 0?!0:S,N=D===void 0?!1:D,{t:T}=pt(),{currentTheme:M}=Sr();let F;e[0]!==n?(F={id:n},e[0]=n,e[1]=F):F=e[1];const{attributes:_,listeners:B,setNodeRef:V,transform:$,transition:z,isDragging:Q}=Nl(F),[L,J]=l.useState(!1),ee=l.useRef(!1),re=`project:${n}`,q=E===re;let ce;e[2]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>{J(!1)},e[2]=ce):ce=e[2];const ae=c?.updatedAt;let R;e[3]!==n||e[4]!==ae?(R=[n,ae],e[3]=n,e[4]=ae,e[5]=R):R=e[5],l.useEffect(ce,R);const U=i?Rl[i]:null,W=o?uo[o]??null:null;let Z;e[6]!==M||e[7]!==n||e[8]!==L||e[9]!==c?(Z=L?null:co({id:n,iconImage:c},{themeVariant:M.metadata.variant,iconColor:M.colors.surface.foreground}),e[6]=M,e[7]=n,e[8]=L,e[9]=c,e[10]=Z):Z=e[10];const K=Z;let ie;e[11]!==re||e[12]!==P?(ie=me=>{P(me?re:null)},e[11]=re,e[12]=P,e[13]=ie):ie=e[13];const Ne=ie,ne=GP,fe=qP,pe=YP;let je;e[14]===Symbol.for("react.memo_cache_sentinel")?(je=me=>{(me.button===2||me.button===0&&me.ctrlKey)&&(ee.current=!0)},e[14]=je):je=e[14];const oe=je;let Se;e[15]!==x?(Se=()=>{if(ee.current){ee.current=!1;return}x()},e[15]=x,e[16]=Se):Se=e[16];const se=Se;let we;e[17]!==$?(we=Sl.Transform.toString($),e[17]=$,e[18]=we):we=e[18];let Ae;e[19]!==we||e[20]!==z?(Ae={transform:we,transition:z},e[19]=we,e[20]=z,e[21]=Ae):Ae=e[21];const ve=Q&&"opacity-30";let ye;e[22]!==ve?(ye=ue("relative",ve),e[22]=ve,e[23]=ye):ye=e[23];let Ie;e[24]!==v||e[25]!==_||e[26]!==Ne||e[27]!==se||e[28]!==h||e[29]!==N||e[30]!==W||e[31]!==n||e[32]!==K||e[33]!==m||e[34]!==p||e[35]!==f||e[36]!==q||e[37]!==u||e[38]!==b||e[39]!==B||e[40]!==k||e[41]!==g||e[42]!==w||e[43]!==y||e[44]!==a||e[45]!==d||e[46]!==U||e[47]!==r||e[48]!==A||e[49]!==C||e[50]!==T?(Ie=N?null:s.jsxs(s.Fragment,{children:[f&&s.jsx("div",{ref:A,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:ue("w-full text-left group/project select-none"),style:{backgroundColor:f&&b?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",..._,children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:oe,onClick:se,...B,className:ue("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",u&&!h?v?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":v?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:ue("h-3.5 w-3.5 items-center justify-center text-muted-foreground",v?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:p?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),K?s.jsx("span",{className:ue("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",v?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:K,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>J(!0)})}):U?s.jsx(I,{name:U,className:ue("h-3.5 w-3.5",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:W?{color:W}:void 0}):s.jsx(I,{name:"folder",className:ue("h-3.5 w-3.5 text-muted-foreground/80",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:W?{color:W}:void 0})]}),s.jsx("span",{className:ue("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(Ct,{side:"right",sideOffset:8,children:a})]}),s.jsxs("div",{className:ue("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",C?"right-7":"right-0.5"),children:[C&&u&&!h&&w?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),w()},className:ue("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":T("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(I,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(Fs,{open:q,onOpenChange:Ne,children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:ue("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",q?"opacity-100 pointer-events-auto":v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":T("sessions.sidebar.project.actions.projectMenu"),onPointerDown:fe,onMouseDown:pe,onClick:ne,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(Rs,{align:"end",className:"min-w-[180px]",children:[C&&!u&&!h&&g&&s.jsxs($t,{onClick:g,children:[s.jsx(I,{name:"add",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.newSession")]}),s.jsxs($t,{onClick:y,children:[s.jsx(I,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.session.menu.rename")]}),s.jsxs($t,{onClick:k,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.closeProject")]})]})]})]}),C&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),g()},className:ue("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":T(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=v,e[25]=_,e[26]=Ne,e[27]=se,e[28]=h,e[29]=N,e[30]=W,e[31]=n,e[32]=K,e[33]=m,e[34]=p,e[35]=f,e[36]=q,e[37]=u,e[38]=b,e[39]=B,e[40]=k,e[41]=g,e[42]=w,e[43]=y,e[44]=a,e[45]=d,e[46]=U,e[47]=r,e[48]=A,e[49]=C,e[50]=T,e[51]=Ie):Ie=e[51];let he;return e[52]!==j||e[53]!==V||e[54]!==Ae||e[55]!==ye||e[56]!==Ie?(he=s.jsxs("div",{ref:V,style:Ae,className:ye,children:[Ie,j]}),e[52]=j,e[53]=V,e[54]=Ae,e[55]=ye,e[56]=Ie,e[57]=he):he=e[57],he},KP=t=>{const e=ot.c(21),{id:n,disabled:r,children:a}=t,i=r===void 0?!1:r;let o;e[0]!==i||e[1]!==n?(o={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=o):o=e[2];const{listeners:c,setNodeRef:d,setActivatorNodeRef:p,transform:m,transition:u,isDragging:f}=Nl(o);let b;e[3]!==c||e[4]!==p?(b={listeners:c,setActivatorNodeRef:p},e[3]=c,e[4]=p,e[5]=b):b=e[5];const h=b;let v;e[6]!==m?(v=Sl.Transform.toString(m),e[6]=m,e[7]=v):v=e[7];let x;e[8]!==v||e[9]!==u?(x={transform:v,transition:u},e[8]=v,e[9]=u,e[10]=x):x=e[10];const g=f&&"opacity-50";let w;e[11]!==g?(w=ue("space-y-0.5 rounded-md",g),e[11]=g,e[12]=w):w=e[12];let y;e[13]!==a||e[14]!==h?(y=typeof a=="function"?a(h):a,e[13]=a,e[14]=h,e[15]=y):y=e[15];let k;return e[16]!==d||e[17]!==x||e[18]!==w||e[19]!==y?(k=s.jsx("div",{ref:d,style:x,className:w,children:y}),e[16]=d,e[17]=x,e[18]=w,e[19]=y,e[20]=k):k=e[20],k},HP=l.memo(KP);function GP(t){t.stopPropagation()}function qP(t){t.stopPropagation()}function YP(t){t.stopPropagation()}function JP(t){const e=ot.c(25),{t:n}=pt();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={coordinateGetter:Tx},e[1]=a):a=e[1];const i=Gi(ni(qi,r),ni(Dx,a));let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[2]=o):o=e[2];const c=Gi(ni(qi,o));if(t.projectSections.length===0){const f=(t.mobileVariant,"");let b;e[3]!==f?(b=ue("space-y-1 pb-1 pl-2.5 pr-2",f),e[3]=f,e[4]=b):b=e[4];let h;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==b?(h=s.jsxs(Ns,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=b,e[8]=h):h=e[8],h}if(t.sectionsForRender.length===0){const f=(t.mobileVariant,"");let b;e[9]!==f?(b=ue("space-y-1 pb-1 pl-2.5 pr-2",f),e[9]=f,e[10]=b):b=e[10];let h;return e[11]!==t.searchEmptyState||e[12]!==b?(h=s.jsx(Ns,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=b,e[13]=h):h=e[13],h}const d=(t.mobileVariant,"");let p;e[14]!==d?(p=ue("space-y-1 pb-1 pl-2.5 pr-2",d),e[14]=d,e[15]=p):p=e[15];let m;e[16]!==c||e[17]!==i||e[18]!==t||e[19]!==n?(m=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const f=t.sectionsForRender.find(x=>x.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!f)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const b=f.groups.find(rA)??f.groups.find(nA)??f.groups.find(sA)??f.groups[0];if(!b)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const h=f.groups.find(tA);return[b,...h&&h.id!==b.id?[h]:[]].map(x=>{const g=`${f.project.id}:${x.id}`,w=x.id===b.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(x,g,f.project.id,w,null,!0)},g)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Yi,{sensors:i,collisionDetection:Ji,onDragEnd:f=>{if(t.isInlineEditing)return;const{active:b,over:h}=f;if(!h||b.id===h.id)return;const v=t.sectionsForRender.findIndex(g=>g.project.id===b.id),x=t.sectionsForRender.findIndex(g=>g.project.id===h.id);v===-1||x===-1||v===x||t.reorderProjects(v,x)},children:[s.jsx(sl,{items:t.sectionsForRender.map(eA),strategy:Kc,children:t.sectionsForRender.map(f=>{const b=f.project,h=b.id,v=mh(b.label?.trim()||Fa(b.normalizedPath,t.homeDirectory)||b.normalizedPath),x=Xi(b.normalizedPath,t.homeDirectory),g=t.collapsedProjects.has(h),w=h===t.activeProjectId,y=t.projectRepoStatus.get(h),k=t.getOrderedGroups(h,f.groups),A=k.find(ZP)??null,j=A?k.filter(S=>S.id!==A.id):k;return s.jsx(WP,{id:h,projectLabel:v,projectDescription:x,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground,isCollapsed:g,isActiveProject:w,isRepo:!!y,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(h),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(h),onNewSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:b.normalizedPath})},onNewWorktreeSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(h),onClose:()=>t.removeProject(h),sentinelRef:S=>{t.projectHeaderSentinelRefs.current.set(h,S)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:g?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:f.groups.length>0?s.jsxs(Yi,{sensors:c,collisionDetection:Ji,onDragEnd:S=>{if(t.isInlineEditing)return;const{active:D,over:E}=S;if(!E||D.id===E.id)return;const P=j.findIndex(M=>M.id===D.id),C=j.findIndex(M=>M.id===E.id);if(P===-1||C===-1||P===C)return;const N=Ef(j,P,C).map(XP),T=A?[A.id,...N]:N;t.setGroupOrderByProject(M=>{const F=new Map(M);return F.set(h,T),F})},children:[A?t.renderGroupSessions(A,`${h}:${A.id}`,h,!0):null,s.jsx(sl,{items:j.map(QP),strategy:Kc,children:j.map(S=>{const D=`${h}:${S.id}`;return s.jsx(HP,{id:S.id,disabled:t.isInlineEditing,children:E=>t.renderGroupSessions(S,D,h,!1,E)},S.id)})}),s.jsx(nl,{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(nl,{dropAnimation:null})]})}),e[16]=c,e[17]=i,e[18]=t,e[19]=n,e[20]=m):m=e[20];let u;return e[21]!==t.topContent||e[22]!==p||e[23]!==m?(u=s.jsxs(Ns,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:p,children:[t.topContent,m]}),e[21]=t.topContent,e[22]=p,e[23]=m,e[24]=u):u=e[24],u}function QP(t){return t.id}function XP(t){return t.id}function ZP(t){return t.isMain}function eA(t){return t.project.id}function tA(t){return t.isArchivedBucket}function sA(t){return t.isMain}function nA(t){return t.sessions.length>0}function rA(t){return t.isMain&&t.sessions.length>0}function aA(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(void 0,{month:"short"}),r=e.getDate(),a=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${a}, ${i}:${o}`}function iA(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function oA(t){const e=t.info.role==="user"?"User":"Assistant",n=aA(t.info.time?.created),r=iA(t),a=n&&r?`${n} (${r})`:n||r;return a?`**${e}**
|
|
182
|
-
|
|
183
|
-
*${a}*`:`**${e}**`}function lA(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Eg(t){const e=oA(t),n=lA(t.parts).trim();return n?`${e}
|
|
184
|
-
|
|
185
|
-
${n}`:""}function Rg(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",a=`${n} Sub-agent: ${t.title}${r}
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
`,i=t.records.map(Eg).filter(Boolean).join(`
|
|
190
|
-
|
|
191
|
-
---
|
|
192
|
-
|
|
193
|
-
`),o=[a+i];for(const c of t.children)o.push(Rg(c,e+1));return o.join(`
|
|
194
|
-
|
|
195
|
-
---
|
|
196
|
-
|
|
197
|
-
`)}function cA(t,e,n){const r=e?.trim()||"Session",a=new Date().toISOString().split("T")[0],i=`# ${r}
|
|
198
|
-
|
|
199
|
-
*Exported on ${a}*
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
`,o=t.map(Eg).filter(Boolean).join(`
|
|
204
|
-
|
|
205
|
-
---
|
|
206
|
-
|
|
207
|
-
`);let c=i+o;if(n&&n.length>0){const d=n.map(p=>Rg(p,1)).join(`
|
|
208
|
-
|
|
209
|
-
---
|
|
210
|
-
|
|
211
|
-
`);c+=`
|
|
212
|
-
|
|
213
|
-
---
|
|
214
|
-
|
|
215
|
-
`+d}return c}function dA(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),a=document.createElement("a");a.href=r,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(r)}async function uA(t,e){const n=await by(e,t);if(n)return n;if(!ln())return null;try{const r=await fetch("/api/vscode/save-markdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileName:e,content:t})});if(!r.ok)return null;const a=await r.json();if(a.saved!==!0)return null;const i=typeof a.path=="string"?a.path.trim():"";return i.length>0?i:null}catch{return null}}async function mA(t){const e=sr()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await yy(t)?!0:rl(t)}function pA(){return $d()}function fA(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",a=new Date().toISOString().split("T")[0];return`${r}-${a}.md`}const hA=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const a of t){r.has(a)||(r.add(a),n.push(a));const i=e.get(a);if(i)for(const o of i)r.has(o)||(r.add(o),n.push(o))}return n},ur=nr()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,a)=>{const i=e(),o=new Set(i.selectedIds);let c=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(o.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const m=a&&a.length>0?[n,...a]:[n];if(o.has(n)){for(const f of m)o.delete(f);d===n&&(d=null)}else{for(const f of m)o.add(f);d=n}o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o,scopeKey:c,anchorId:d})},setRange:(n,r,a,i,o)=>{const c=e();if(a.length===0)return;const d=n&&a.includes(n)?n:a[0],p=a.indexOf(d),m=a.indexOf(r);if(p<0||m<0)return;const[u,f]=p<=m?[p,m]:[m,p],b=a.slice(u,f+1),h=hA(b,o),x=i!==null&&c.scopeKey!==null&&i!==c.scopeKey?new Set:new Set(c.selectedIds);for(const g of h)x.add(g);t({selectedIds:x,scopeKey:i??c.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const a=new Set(r.selectedIds);for(const i of n)a.delete(i);a.size!==r.selectedIds.size&&(a.size===0?t({selectedIds:a,scopeKey:null,anchorId:null}):t({selectedIds:a}))}})),gA=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,tl=t=>{if(!t)return null;const e=t.split("/");if(e.length!==3&&e.length!==4)return null;const[n,r,a,i]=e;if(!gA.test(n)||!r?.trim()||!a?.trim()||r!==r.trim()||a!==a.trim())return null;if(e.length===3)return{groupSlug:n,providerID:r,modelID:a,fusion:!1};if(i==="fusion")return{groupSlug:n,providerID:r,modelID:a,fusion:!0};if(!/^\d+$/.test(i))return null;const o=Number.parseInt(i,10);return!Number.isSafeInteger(o)||o<=0?null:{groupSlug:n,providerID:r,modelID:a,index:o,fusion:!1}},xA=(t,e,n)=>`${t}/${e}/${n}/fusion`,Fg=t=>{const e=ot.c(35),{value:n,onChange:r,className:a,disabled:i,id:o,portalToBody:c}=t,{t:d}=pt(),p=vt(bA),m=vt(yA),u=vt(vA);let f;e[0]!==p?(f=p(),e[0]=p,e[1]=f):f=e[1];const b=f;let h;e[2]!==b?(h=b.filter(wA),e[2]=b,e[3]=h):h=e[3];const v=h;let x,g;e[4]!==m?(x=()=>{m()},g=[m],e[4]=m,e[5]=x,e[6]=g):(x=e[5],g=e[6]),l.useEffect(x,g);let w,y;e[7]!==u||e[8]!==i||e[9]!==r||e[10]!==v||e[11]!==n?(w=()=>{if(i)return;const N=n.trim();if(N.length>0&&v.some(F=>F.name===N))return;const T=typeof u=="string"&&u.trim().length>0?u.trim():null;if(T&&v.some(F=>F.name===T)){r(T);return}const M=v[0]?.name;M&&r(M)},y=[u,i,r,v,n],e[7]=u,e[8]=i,e[9]=r,e[10]=v,e[11]=n,e[12]=w,e[13]=y):(w=e[12],y=e[13]),l.useEffect(w,y);const k=n.trim().length>0?n:void 0;let A;e[14]!==a?(A=ue("max-w-full typography-meta text-foreground !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 data-[popup-open]:!bg-[var(--interactive-active)]/70",a),e[14]=a,e[15]=A):A=e[15];let j;e[16]!==d?(j=d("multirun.agentSelector.placeholder"),e[16]=d,e[17]=j):j=e[17];let S;e[18]!==j?(S=s.jsx(us,{placeholder:j}),e[18]=j,e[19]=S):S=e[19];let D;e[20]!==o||e[21]!==A||e[22]!==S?(D=s.jsx(os,{id:o,size:"lg",className:A,children:S}),e[20]=o,e[21]=A,e[22]=S,e[23]=D):D=e[23];let E;e[24]!==v?(E=v.length>0&&s.jsx(Qc,{children:v.map(jA)}),e[24]=v,e[25]=E):E=e[25];let P;e[26]!==c||e[27]!==E?(P=s.jsx(ls,{fitContent:!0,portalToBody:c,children:E}),e[26]=c,e[27]=E,e[28]=P):P=e[28];let C;return e[29]!==i||e[30]!==r||e[31]!==k||e[32]!==D||e[33]!==P?(C=s.jsxs(is,{value:k,onValueChange:r,disabled:i,children:[D,P]}),e[29]=i,e[30]=r,e[31]=k,e[32]=D,e[33]=P,e[34]=C):C=e[34],C};function bA(t){return t.getVisibleAgents}function yA(t){return t.loadAgents}function vA(t){return t.currentAgentName}function wA(t){return t.mode!=="subagent"}function jA(t){return s.jsx(Ft,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Og="h-7",wl=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,NA=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),SA=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=NA.format(t);return e.endsWith(".0")?e.slice(0,-2):e},kA=t=>{const e=ot.c(12),{model:n,instanceIndex:r,totalSameModel:a,onRemove:i}=t,o=n.displayName||`${n.providerID}/${n.modelID}`,c=a>1?`${o} (${r})`:o;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=ue("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Og),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(xn,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=p):p=e[2];let m;e[3]!==c?(m=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:c}),e[3]=c,e[4]=m):m=e[4];let u;e[5]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(I,{name:"close",className:"h-3.5 w-3.5"}),e[5]=u):u=e[5];let f;e[6]!==i?(f=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:u}),e[6]=i,e[7]=f):f=e[7];let b;return e[8]!==p||e[9]!==m||e[10]!==f?(b=s.jsxs("div",{className:d,children:[p,m,f]}),e[8]=p,e[9]=m,e[10]=f,e[11]=b):b=e[11],b},Lg=({selectedModels:t,onAdd:e,onRemove:n,onUpdate:r,minModels:a,addButtonLabel:i,showChips:o=!0,maxModels:c,addButtonClassName:d,dropdownSide:p="top",dropdownClassName:m,containerClassName:u,triggerIcon:f})=>{const{t:b}=pt(),h=vt(q=>q.providers),v=vt(q=>q.modelsMetadata),{favoriteModelsList:x,recentModelsList:g}=qf(),[w,y]=l.useState(!1),[k,A]=l.useState(""),[j,S]=l.useState(0),[D,E]=l.useState(null),P=l.useRef(null),C=l.useRef(null),N=l.useRef(null),T=l.useRef([]),M=c===1,F=c===void 0||t.length<c||M,_=l.useMemo(()=>{const q=new Map;for(const ce of t){const ae=`${ce.providerID}:${ce.modelID}`;q.set(ae,(q.get(ae)||0)+1)}return q},[t]),B=l.useCallback(q=>t.filter(ae=>ae.providerID===q.providerID&&ae.modelID===q.modelID).findIndex(ae=>ae.instanceId===q.instanceId)+1,[t]),V=(q,ce)=>{const ae=`${q}/${ce}`;return v.get(ae)},$=q=>{const ce=q?.name||q?.id||"",ae=String(ce);return ae.length>40?ae.substring(0,37)+"...":ae},z=l.useCallback((q,ce)=>{if(!k.trim())return!0;const ae=k.toLowerCase();return q.toLowerCase().includes(ae)||ce.toLowerCase().includes(ae)},[k]),Q=l.useMemo(()=>x.filter(({model:q,providerID:ce})=>{const R=h.find(W=>W.id===ce)?.name||ce,U=$(q);return z(U,R)}),[x,h,z]),L=l.useMemo(()=>g.filter(({model:q,providerID:ce})=>{const R=h.find(W=>W.id===ce)?.name||ce,U=$(q);return z(U,R)}),[g,h,z]),J=l.useMemo(()=>h.map(q=>{const ae=(Array.isArray(q.models)?q.models:[]).filter(R=>{const U=$(R);return z(U,q.name||q.id||"")});return{...q,models:ae}}).filter(q=>q.models.length>0),[h,z]),ee=Q.length>0||L.length>0||J.length>0;l.useEffect(()=>{if(!w||!N.current)return;const q=N.current.getBoundingClientRect();if(p==="bottom"){const Z=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-q.bottom-16-112;E(Math.max(160,Math.min(320,Z)));return}let ce=N.current.parentElement;for(;ce&&!(ce.getAttribute("role")==="dialog"||ce.hasAttribute("data-scroll-shadow"));){const U=getComputedStyle(ce);if(U.overflow==="auto"||U.overflow==="hidden"||U.overflowY==="auto"||U.overflowY==="hidden")break;ce=ce.parentElement}const ae=ce?ce.getBoundingClientRect().top:0,R=q.top-ae-16;E(Math.max(150,Math.min(300,R)))},[p,w]),l.useEffect(()=>{w&&P.current&&P.current.focus()},[w]),l.useEffect(()=>{!F&&w&&(y(!1),A(""),S(0))},[F,w]),l.useEffect(()=>{if(!w)return;const q=ce=>{C.current&&!C.current.contains(ce.target)&&(y(!1),A(""),S(0))};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[w]),l.useEffect(()=>{S(0)},[k]);const re=(q,ce,ae,R,U,W)=>{const Z=`${ce}:${ae}`,K=_.get(Z)||0,ie=V(ce,ae),Ne=SA(ie?.limit?.context),ne=R==="fav"||R==="recent";return s.jsxs("button",{ref:fe=>{T.current[U]=fe},type:"button",disabled:!F,onClick:()=>{const fe={providerID:ce,modelID:ae,displayName:q.name||ae,instanceId:wl()};if(M&&t.length>0&&r){r(0,fe),y(!1),A(""),S(0);return}e({...fe}),M&&(y(!1),A(""),S(0))},onMouseEnter:()=>S(U),className:ue("w-full text-left px-2 py-1.5 rounded-md typography-meta transition-colors flex items-center gap-2",F&&(W?"bg-interactive-selection":"hover:bg-interactive-hover/50"),!F&&"cursor-not-allowed opacity-60"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[ne&&s.jsx(xn,{providerId:ce,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(q)}),Ne&&s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:Ne})]}),K>0&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:["×",K]})]},`${R}-${Z}`)};return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[s.jsxs("div",{className:ue("relative",u),ref:C,children:[s.jsxs(xe,{ref:N,type:"button",variant:"outline",size:"sm",className:ue(Og,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",d),disabled:!F,onClick:()=>{y(!w)},children:[f??s.jsx(I,{name:"add",className:"h-3.5 w-3.5 mr-1"}),i??b("multirun.modelMultiSelect.actions.addModel")]}),w&&(()=>{const q=[];Q.forEach(({model:U,providerID:W,modelID:Z})=>{q.push({model:U,providerID:W,modelID:Z,section:"fav"})}),L.forEach(({model:U,providerID:W,modelID:Z})=>{q.push({model:U,providerID:W,modelID:Z,section:"recent"})}),J.forEach(U=>{U.models.forEach(W=>{q.push({model:W,providerID:U.id,modelID:W.id,section:"provider"})})});const ce=q.length,ae=U=>{if(!vy(U))if(U.key==="ArrowDown"){U.preventDefault(),U.stopPropagation();const W=(j+1)%Math.max(1,ce);S(W),setTimeout(()=>{T.current[W]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(U.key==="ArrowUp"){U.preventDefault(),U.stopPropagation();const W=(j-1+Math.max(1,ce))%Math.max(1,ce);S(W),setTimeout(()=>{T.current[W]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(U.key==="Enter"){U.preventDefault(),U.stopPropagation();const W=q[j];if(W&&F){const Z={providerID:W.providerID,modelID:W.modelID,displayName:W.model.name||W.modelID,instanceId:wl()};M&&t.length>0&&r?r(0,Z):e(Z),M&&(y(!1),A(""),S(0))}}else U.key==="Escape"&&(U.preventDefault(),U.stopPropagation(),y(!1),A(""),S(0))};let R=0;return s.jsxs("div",{className:ue("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",p==="top"?"bottom-full mb-1":"top-full mt-1",m),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Vt,{ref:P,type:"text",placeholder:b("multirun.modelMultiSelect.search.placeholder"),value:k,onChange:U=>A(U.target.value),onKeyDown:ae,className:"h-8 pl-8 typography-meta"})]})}),s.jsx(Ns,{outerClassName:"flex-1",style:{maxHeight:D?`${D}px`:"300px"},children:s.jsxs("div",{className:"p-1",children:[!ee&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:b("multirun.modelMultiSelect.search.noResults")}),Q.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(I,{name:"star-fill",className:"h-4 w-4 text-primary"}),b("multirun.modelMultiSelect.sections.favorites")]}),Q.map(({model:U,providerID:W,modelID:Z})=>{const K=R++;return re(U,W,Z,"fav",K,j===K)})]}),L.length>0&&s.jsxs(s.Fragment,{children:[Q.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(I,{name:"time",className:"h-4 w-4"}),b("multirun.modelMultiSelect.sections.recent")]}),L.map(({model:U,providerID:W,modelID:Z})=>{const K=R++;return re(U,W,Z,"recent",K,j===K)})]}),(Q.length>0||L.length>0)&&J.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),J.map((U,W)=>s.jsxs(l.Fragment,{children:[W>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(xn,{providerId:U.id,className:"h-4 w-4 flex-shrink-0"}),U.name]}),U.models.map(Z=>{const K=R++;return re(Z,U.id,Z.id,"provider",K,j===K)})]},U.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:b("multirun.modelMultiSelect.keyboard.hint")})]})})()]}),o&&t.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:t.map((q,ce)=>{const ae=`${q.providerID}:${q.modelID}`,R=_.get(ae)||1,U=B(q),Z=h.find(fe=>fe.id===q.providerID)?.models.find(fe=>fe.id===q.modelID),K=Z?.variants?Object.keys(Z.variants):[],ie=K.length>0,Ne="__default__",ne=q.variant??Ne;return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(kA,{model:q,instanceIndex:U,totalSameModel:R,onRemove:()=>n(ce)}),ie&&s.jsxs(is,{value:ne,onValueChange:fe=>{if(!r)return;r(ce,{...q,variant:fe===Ne?void 0:fe})},children:[s.jsxs(os,{size:"chip",className:"px-2 gap-1.5 rounded-md !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground",children:[s.jsx(I,{name:"brain-ai-3",className:ue("h-3.5 w-3.5 flex-shrink-0",ne===Ne?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(us,{placeholder:b("multirun.modelMultiSelect.variant.placeholder"),children:fe=>fe===Ne?b("multirun.modelMultiSelect.variant.default"):fe})]}),s.jsxs(ls,{fitContent:!0,children:[s.jsx(Ft,{value:Ne,className:"pr-2 [&>span:first-child]:hidden",children:b("multirun.modelMultiSelect.variant.default")}),K.map(fe=>s.jsx(Ft,{value:fe,className:"pr-2 [&>span:first-child]:hidden",children:fe},fe))]})]})]},q.instanceId)})})]}),a!==void 0&&t.length<a&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:c!==void 0?b("multirun.modelMultiSelect.validation.minToMax",{min:a,max:c}):b("multirun.modelMultiSelect.validation.minOnly",{min:a})})]})},CA=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
216
|
-
|
|
217
|
-
--- RESULT ${n+1}: ${r} ---
|
|
218
|
-
${e.trim()}
|
|
219
|
-
--- END RESULT ${n+1} ---`},uf=(t,e)=>Lt.getState().getWorktreeMetadata(t)?.projectDirectory??e,IA=async t=>{const e=t.directory??void 0,n=wy(t.session.id,e);if(n.length===0&&t.directory){const a=(await en.withDirectory(t.directory,()=>en.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=a.length-1;i>=0;i-=1){const o=a[i];if(o.info?.role==="assistant")return Ou(o.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const a=n[r];if(a.role==="assistant")return Ou(jy(a.id,e)).trim()}return""};function PA({session:t,open:e,onOpenChange:n}){const{t:r}=pt(),a=Ad(),i=Ia(V=>V.activeSessions),o=Ia(V=>V.archivedSessions),c=vt(V=>V.providers),d=vt(V=>V.currentProviderId),p=vt(V=>V.currentModelId),m=vt(V=>V.currentAgentName),[u,f]=l.useState(d??""),[b,h]=l.useState(p??""),[v,x]=l.useState(()=>d&&p?[{providerID:d,modelID:p,instanceId:wl()}]:[]),[g,w]=l.useState(""),[y,k]=l.useState(m??""),[A,j]=l.useState([]),[S,D]=l.useState(!1),E=l.useMemo(()=>tl(t.title),[t.title]),P=l.useMemo(()=>{const V=new Map;for(const $ of a)V.set($.id,$);for(const $ of i)V.set($.id,$);for(const $ of o)V.set($.id,$);return t.id&&V.set(t.id,t),Array.from(V.values())},[i,o,a,t]);l.useEffect(()=>{if(!e||!E)return;const V=Lt.getState().getDirectoryForSession(t.id),$=uf(t.id,V),z=P.map(Q=>{const L=tl(Q.title);if(!L||L.groupSlug!==E.groupSlug||L.fusion)return null;const J=Lt.getState().getDirectoryForSession(Q.id)??Vi(Q),ee=uf(Q.id,J);return $&&ee&&$!==ee?null:{session:Q,directory:J,projectDirectory:ee}}).filter(Q=>Q!==null).sort((Q,L)=>(Q.session.time?.created??0)-(L.session.time?.created??0));j(z)},[P,e,E,t.id]);const N=c.find(V=>V.id===u)?.models.find(V=>V.id===b),T=N?.variants?Object.keys(N.variants):[],M=!!(E&&u&&b&&A.length>0&&!S),F=l.useCallback(V=>{x([V]),f(V.providerID),h(V.modelID),w("")},[]),_=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),B=async()=>{if(!(!E||!u||!b)){D(!0);try{const V=await Promise.all(A.map(re=>IA(re))),$=A.map((re,q)=>({source:re,text:V[q]??""})).filter(re=>re.text.trim().length>0);if($.length===0){H.error(r("multirun.fusion.toast.noOutputs"));return}const z=A[0]?.projectDirectory??A[0]?.directory??null,Q=xA(E.groupSlug,u,b),[L,J]=await Promise.all([bn("session.fusion.visible"),bn("session.fusion.instructions")]),ee=await Lt.getState().createSession(Q,z,null);if(!ee)throw new Error("Failed to create fusion session");Lt.getState().setCurrentSession(ee.id,z),n(!1),await en.withDirectory(z??en.getDirectory(),()=>en.sendMessage({id:ee.id,providerID:u,modelID:b,variant:g||void 0,agent:y||void 0,text:L,additionalParts:[{text:J,synthetic:!0},...$.map((re,q)=>({text:CA(re.source,re.text,q),synthetic:!0})),{text:`
|
|
220
|
-
|
|
221
|
-
--- FUSION INPUTS END ---
|
|
222
|
-
Now write the final fused answer.`,synthetic:!0}]}))}catch(V){console.error("[MultiRunFusion] Failed to start fusion",V),H.error(r("multirun.fusion.toast.failed"))}finally{D(!1)}}};return s.jsx(ps,{open:e,onOpenChange:n,children:s.jsxs(ms,{className:"max-w-xl overflow-visible",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:r("multirun.fusion.title")}),s.jsx(Ps,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx(Lg,{selectedModels:v,onAdd:F,onUpdate:(V,$)=>F($),onRemove:()=>{x([]),f(""),h(""),w("")},maxModels:1,addButtonLabel:_,showChips:!1,addButtonClassName:"h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:u?s.jsx(xn,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),T.length>0?s.jsxs(is,{value:g||"__default__",onValueChange:V=>w(V==="__default__"?"":V),children:[s.jsxs(os,{size:"lg",className:"h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5",children:[s.jsx(I,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(us,{children:V=>V==="__default__"?r("multirun.modelMultiSelect.variant.default"):V})]}),s.jsxs(ls,{fitContent:!0,portalToBody:!0,children:[s.jsx(Ft,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),T.map(V=>s.jsx(Ft,{value:V,children:V},V))]})]}):null,s.jsx(Fg,{value:y,onChange:k,portalToBody:!0,className:"h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:A.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:A.map(V=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(xn,{providerId:tl(V.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:V.session.title||V.session.id}),s.jsx("button",{type:"button",onClick:()=>j($=>$.filter(z=>z.session.id!==V.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},V.session.id))})]}),s.jsxs(Us,{children:[s.jsx(xe,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(xe,{onClick:B,disabled:!M,children:r(S?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function AA(t){const e=ot.c(7);let n,r,a,i,o;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),a=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),o=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=a,e[3]=i,e[4]=o):(n=e[0],r=e[1],a=e[2],i=e[3],o=e[4]);let c;return e[5]!==t?(c=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,a,i,o]}),e[5]=t,e[6]=c):c=e[6],c}const mf=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),ja=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(ja(n,e))return!0;return!1},Sd=(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(Sd(i,e,n,r))return!0;return!1},DA=(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||mf(t.node)!==mf(e.node)||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket)return!1;if(t.currentSessionId!==e.currentSessionId){const m=ja(t.node,t.currentSessionId),u=ja(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(a)!==e.pinnedSessionIds.has(i))return!1;{const m=t.renderContext??"project",u=e.renderContext??"project",f=t.archivedBucket??!1,b=e.archivedBucket??!1,h=`${m}:${f?"archived":"active"}:${a}`,v=`${u}:${b?"archived":"active"}:${i}`;if(t.expandedParents.has(h)!==e.expandedParents.has(v))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=ja(t.node,t.editingId),u=ja(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=ja(t.node,t.editingId),u=ja(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const o=Sd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=Sd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(o!==c)return!1;const d=ys(n.directory??null)??ys(t.groupDirectory??null),p=ys(r.directory??null)??ys(e.groupDirectory??null);return!(d!==p||(d?t.directoryStatus.get(d):null)!==(p?e.directoryStatus.get(p):null)||(t.secondaryMeta?.projectLabel??null)!==(e.secondaryMeta?.projectLabel??null)||(t.secondaryMeta?.branchLabel??null)!==(e.secondaryMeta?.branchLabel??null)||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||(t.renderContext??"project")!==(e.renderContext??"project")||t.renamingFolderId!==e.renamingFolderId)};function TA(t){const{t:e}=pt(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:o=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:f,notifyOnSubtasks:b,editingId:h,setEditingId:v,editTitle:x,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:y,toggleParent:k,handleSessionSelect:A,handleSessionDoubleClick:j,togglePinnedSession:S,handleShareSession:D,copiedSessionId:E,handleCopyShareUrl:P,handleUnshareSession:C,openSidebarMenuKey:N,setOpenSidebarMenuKey:T,renamingFolderId:M,getFoldersForScope:F,getSessionFolderId:_,removeSessionFromFolder:B,addSessionToFolder:V,createFolderAndStartRename:$,openContextPanelTab:z,handleDeleteSession:Q,mobileVariant:L,alwaysShowActions:J,renderSessionNode:ee,secondaryMeta:re,renderContext:q="project"}=t,ce=!!re?.projectLabel,ae=!!re?.branchLabel,U=Ca(Ze=>Ze.displayMode)==="minimal",W=l.useMemo(()=>ln(),[]),Z=l.useMemo(()=>Dd(),[]),K=l.useContext(Ny),ie=W?"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",Ne=W?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",ne=W,fe=!o&&!L,pe=U?W?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":W?fe&&ne?"group-hover:pr-18":fe||ne?"group-hover:pr-12":"group-hover:pr-5":fe?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",je=fe?"pr-13":"pr-7",oe=l.useRef(!1),[Se,se]=l.useState(!1),we=n.session,ve=Uf(we.id)??we,ye=ys(we.directory??null)??ys(a??null),Ie=Sy(ye??void 0),he=Ud(),me=ur(Ze=>Ze.enabled),Ee=ur(l.useCallback(Ze=>Ze.selectedIds.has(we.id),[we.id])),Ve=ur(Ze=>Ze.toggleSelected),Y=ur(Ze=>Ze.setRange),ke=l.useCallback(Ze=>{const Wt=[],es=rs=>{rs.children.forEach(Ue=>{Wt.push(Ue.session.id),es(Ue)})};return es(Ze),Wt},[]),[Be,Ce]=l.useState(!1),[ge,O]=l.useState(!0),X=`${q}:${o?"archived":"active"}:${we.id}`,G=ph(l.useCallback(Ze=>!!Ze.sessionMemoryState.get(we.id)?.isZombie,[we.id])),Te=ky(we.id),le=Cy(we.id,ye??void 0),de=(ye?c.get(ye):null)==="missing",Fe=d===we.id,rt=ve.title||e("sessions.sidebar.session.untitled"),Oe=n.children.length>0,Ye=p.has(we.id),Ge=X,it=u?!0:m.has(Ge),Qe=!!ve.parentID,nt=Iy(we.id)>0&&(!Qe||b),be=ve.summary,He=Kf(be),_e=ve.time?.updated||ve.time?.created||Date.now(),tt=Py(_e),ut=My(_e),qe=N===X,ze=l.useMemo(()=>tl(ve.title)!==null,[ve.title]),[st,yt]=l.useState(!1),Mt=l.useMemo(()=>ke(n).length,[ke,n]),Bt=l.useCallback(async Ze=>{const Wt=[];let es=0;for(const rs of Ze)try{await he.ensureSessionRenderable(rs.session.id);const Ue=Lu(Ie.getState(),rs.session.id).list,xt=rs.session.title||e("sessions.sidebar.session.export.untitledSubagent"),At=rs.session.agent,Dt=await Bt(rs.children);es+=Dt.skipped,Wt.push({title:xt,agent:At,records:Ue,children:Dt.children})}catch{es+=ke(rs).length+1}return{children:Wt,skipped:es}},[ke,Ie,he,e]),ft=l.useCallback(Ze=>{Ze<=0||H.warning(Ze===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Ze}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Ze}))},[e]),It=l.useCallback(async Ze=>{if(!ye){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}await he.ensureSessionRenderable(we.id);const Wt=Lu(Ie.getState(),we.id).list;if(Wt.length===0){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}let es,rs=0;if(Ze&&n.children.length>0){const Dt=await Bt(n.children);es=Dt.children,rs=Dt.skipped}const Ue=cA(Wt,ve.title??null,es),xt=fA(ve.title??null),At=await uA(Ue,xt);if(At){H.success(e("sessions.sidebar.session.export.success"),{action:{label:e(pA()),onClick:()=>{mA(At).then(Dt=>{Dt||H.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),ft(rs);return}dA(Ue,xt),H.success(e("sessions.sidebar.session.export.success")),ft(rs)},[Bt,Ie,n.children,ve.title,we.id,ye,ft,he,e]),ss=l.useCallback(async()=>{if(n.children.length>0){O(!0),Ce(!0);return}await It(!1)},[It,n.children.length]),_t=l.useCallback(()=>{ye&&al("desktop_open_session_mini_chat_window",{sessionId:we.id,directory:ye}).catch(Ze=>{console.warn("[session-sidebar] failed to open mini chat window",Ze)})},[we.id,ye]);if(h===we.id)return s.jsx("div",{className:ue("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:Ze=>{Ze.preventDefault(),w()},children:[s.jsx("input",{value:x,onChange:Ze=>g(Ze.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:Ze=>{if(Ze.key==="Escape"){Ze.stopPropagation(),y();return}(Ze.key===" "||Ze.key==="Enter")&&Ze.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:y,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"size-4"})})]}),U?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:[Oe?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:it?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:tt}),He?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:["+",He.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",He.deletions]})]}):null,ce?s.jsx("span",{className:"truncate",children:re?.projectLabel}):null,ae?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:re?.branchLabel})]}):null]})})]})},we.id);const qt=Te?.type??"idle",ct=qt==="busy"||qt==="retry",jt=le.length,xs=ct||!ct&&nt&&!Fe,ws=ct?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")}),As=xs||Ye?s.jsxs("span",{className:ue("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",U?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",xs&&Ye?"left-[-18px] w-6":"left-[-10px] w-3.5",Oe&&!J?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[xs?ws:null,Ye?s.jsx(I,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,Gt=Oe?s.jsx("span",{role:"button",tabIndex:0,onClick:Ze=>{Ze.stopPropagation(),k(Ge)},onKeyDown:Ze=>{(Ze.key==="Enter"||Ze.key===" ")&&(Ze.preventDefault(),Ze.stopPropagation(),k(Ge))},className:ue("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",U?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",U&&xs&&!J?"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(it?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:it?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3"})}):null,Ke=G?s.jsx(I,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Pt=Ze=>{T(Ze?X:null)},Ot=Ze=>{Ze.preventDefault(),Ze.stopPropagation(),T(qe?null:X)},Nt=Ze=>{Ze.preventDefault(),Ze.stopPropagation()},Ht=Ze=>{Ze.preventDefault(),Ze.stopPropagation()},ns=Ze=>{Ze.preventDefault(),Ze.stopPropagation()},Ss=Ze=>{Ze.preventDefault(),Ze.stopPropagation()},fs=Ze=>{Ze.preventDefault(),Ze.stopPropagation(),T(null),Q(we,{archivedBucket:o})},Os=Ze=>{Ze.preventDefault(),Ze.stopPropagation()},zs=Ze=>{Ze.preventDefault(),Ze.stopPropagation()},tn=Ze=>{Ze.preventDefault(),Ze.stopPropagation(),K?.vscode?.executeCommand("openchamber.openSessionInEditor",we.id,rt)},Ds=Ze=>{if(oe.current){oe.current=!1;return}if(me){if(Ze?.preventDefault(),Ze?.stopPropagation(),Ze?.shiftKey){const es=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(xt=>xt.getAttribute("data-session-row")).filter(xt=>typeof xt=="string"&&xt.length>0),rs=ur.getState().anchorId,Ue=new Map;Ue.set(we.id,ke(n)),Y(rs,we.id,es,ye??null,Ue);return}Ve(we.id,ye??null,ke(n));return}A(we.id,ye,de,i)},zt=Ze=>{(Ze.button===2||Ze.button===0&&Ze.ctrlKey&&!me)&&(oe.current=!0)},Kt=Ze=>{L&&Ze.pointerType==="touch"&&se(!0)},te=Ze=>{L&&Ze.pointerType==="touch"&&se(!1)},bt=s.jsxs(Rs,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:Ze=>{M&&Ze.preventDefault()},children:[s.jsxs($t,{onClick:()=>{v(we.id),g(rt)},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs($t,{onClick:()=>S(we.id),className:"[&>svg]:mr-1",children:[Ye?s.jsx(I,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(I,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(Ye?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),ve.share?s.jsxs(s.Fragment,{children:[s.jsx($t,{onClick:()=>{ve.share?.url&&P(ve.share.url,we.id)},className:"[&>svg]:mr-1",children:E===we.id?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs($t,{onClick:()=>C(we.id),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs($t,{onClick:()=>D(ve),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs($t,{onClick:()=>{ss()},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),ze?s.jsxs($t,{onClick:()=>yt(!0),className:"[&>svg]:mr-1",children:[s.jsx(AA,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,ye&&!o?(()=>{const Ze=F(ye),Wt=_(ye,we.id);return s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),s.jsxs(Ay,{children:[s.jsxs(Dy,{className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Ty,{className:"min-w-[180px]",children:[Ze.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Ze.map(es=>s.jsxs($t,{onClick:()=>{Wt===es.id?B(ye,we.id):V(ye,es.id,we.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:es.name}),Wt===es.id?s.jsx(I,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},es.id)),s.jsx(Cn,{}),s.jsxs($t,{onClick:()=>{const es=$(ye);es&&V(ye,es.id,we.id)},children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Wt?s.jsxs($t,{onClick:()=>{B(ye,we.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,W?null:s.jsxs($t,{disabled:!ye,onClick:()=>{ye&&z(ye,{mode:"chat",dedupeKey:`session:${we.id}`,label:rt})},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),Z?s.jsxs($t,{disabled:!ye,onClick:_t,className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Cn,{}),s.jsxs($t,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>Q(we,{archivedBucket:o}),children:[s.jsx(I,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(l.Fragment,{children:[s.jsx(AP,{sessionId:we.id,sessionDirectory:ye??null,sessionTitle:rt,children:s.jsxs("div",{"data-session-row":we.id,"data-session-scope":ye??"","data-session-archived":o?"1":"0",className:ue("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",de?"opacity-75":"",r>0&&"pl-[20px]",Ee&&"bg-primary/15"),children:[As,Gt,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:U?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:de,onPointerDown:Kt,onPointerUp:te,onPointerCancel:te,onMouseDown:zt,onClick:Ze=>Ds(Ze),onDoubleClick:Ze=>{Ze.stopPropagation(),j()},className:ue("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]",Se&&"bg-interactive-hover/70",J?W?pe:je:pe),children:s.jsxs("div",{className:ue("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ue("block min-w-0 flex-1 truncate typography-ui-label font-normal",Fe?"text-primary":"text-foreground"),children:Ui(rt,f)}),J?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:ut}):null,J?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:ue("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",qe?"opacity-0":Ne),children:ut})}),jt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(I,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:jt})]}):null]})})}),s.jsx(Ct,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:ue("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:tt})]}),re?.branchLabel||He?s.jsxs("div",{className:ue("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(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:re.branchLabel})]})}):null,He?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",He.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",He.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:de,onPointerDown:Kt,onPointerUp:te,onPointerCancel:te,onMouseDown:zt,onClick:Ze=>Ds(Ze),onDoubleClick:Ze=>{Ze.stopPropagation(),j()},className:ue("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]",Se&&"bg-interactive-hover/70",J?W?pe:je:pe),children:[s.jsxs("div",{className:ue("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ue("block min-w-0 flex-1 truncate typography-ui-label font-normal",Fe?"text-primary":"text-foreground"),children:Ui(rt,f)}),jt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(I,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:jt})]}):null]}),U?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:tt}),He?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:["+",He.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",He.deletions]})]}):null,ce?s.jsx("span",{className:"truncate",children:re?.projectLabel}):null,ae?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:re?.branchLabel})]}):null]})})]})}),Ke&&!L?s.jsx("div",{className:ue("absolute top-1/2 -translate-y-1/2 z-10",U?"right-0":"right-[30px]"),children:Ke}):null,s.jsxs("div",{className:ue("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",qe||J&&!W?"opacity-100":ue("opacity-0",ie)),children:[fe?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:ue("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",U&&!J?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:ns,onMouseDown:Ss,onClick:fs,onKeyDown:Ze=>Ze.stopPropagation(),children:s.jsx(I,{name:"archive",className:ue(U&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Ct,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,ne?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:ue("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",U&&!J?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:Os,onMouseDown:zs,onClick:tn,onKeyDown:Ze=>Ze.stopPropagation(),children:s.jsx(I,{name:"external-link",className:ue(U&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Ct,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(Fs,{open:qe,onOpenChange:Pt,children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:ue("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",U&&!J?qe?"h-4 w-4 opacity-100":ue("h-4 w-4 opacity-0",ie):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Nt,onMouseDown:Ht,onClick:Ot,onKeyDown:Ze=>Ze.stopPropagation(),children:s.jsx(I,{name:"more-2",className:ue(U&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),bt]})]})]})}),Oe&&it?n.children.map(Ze=>ee(Ze,r+1,ye??a,i,o,void 0,q)):null,s.jsx(ps,{open:Be,onOpenChange:Ce,children:s.jsxs(ms,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(vs,{children:[s.jsx(gs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ps,{children:Mt===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Mt}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Mt})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:ge,onChange:Ze=>O(Ze.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Us,{children:[s.jsx(xe,{type:"button",onClick:()=>Ce(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(xe,{type:"button",onClick:()=>{Ce(!1),It(ge)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),ze?s.jsx(PA,{session:ve,open:st,onOpenChange:yt}):null]},we.id)}const MA=l.memo(TA,DA);function EA(t){const e=ot.c(71),{t:n}=pt(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t;let d,p,m,u,f,b,h,v,x,g;if(e[0]!==a||e[1]!==n||e[2]!==r){const $=n("sessions.sidebar.session.untitled");u=ps,x=!!r,e[13]!==a?(g=Q=>{Q||a(null)},e[13]=a,e[14]=g):g=e[14],m=ms,h=!1,v="max-w-sm gap-5",p=vs;let z;e[15]!==n||e[16]!==r?.archivedBucket?(z=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=z):z=e[17],e[18]!==z?(b=s.jsx(gs,{children:z}),e[18]=z,e[19]=b):b=e[19],d=Ps,f=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||$}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||$}),e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=p,e[5]=m,e[6]=u,e[7]=f,e[8]=b,e[9]=h,e[10]=v,e[11]=x,e[12]=g}else d=e[3],p=e[4],m=e[5],u=e[6],f=e[7],b=e[8],h=e[9],v=e[10],x=e[11],g=e[12];let w;e[20]!==d||e[21]!==f?(w=s.jsx(d,{children:f}),e[20]=d,e[21]=f,e[22]=w):w=e[22];let y;e[23]!==p||e[24]!==b||e[25]!==w?(y=s.jsxs(p,{children:[b,w]}),e[23]=p,e[24]=b,e[25]=w,e[26]=y):y=e[26];let k;e[27]!==o||e[28]!==i?(k=()=>o(!i),e[27]=o,e[28]=i,e[29]=k):k=e[29];const A=!i;let j;e[30]!==i?(j=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=j):j=e[31];let S;e[32]!==n?(S=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=S):S=e[33];let D;e[34]!==j||e[35]!==S||e[36]!==k||e[37]!==A?(D=s.jsxs("button",{type:"button",onClick:k,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":A,children:[j,S]}),e[34]=j,e[35]=S,e[36]=k,e[37]=A,e[38]=D):D=e[38];let E;e[39]!==a?(E=()=>a(null),e[39]=a,e[40]=E):E=e[40];let P;e[41]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=P):P=e[42];let C;e[43]!==E||e[44]!==P?(C=s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:P}),e[43]=E,e[44]=P,e[45]=C):C=e[45];let N;e[46]!==c?(N=()=>{c()},e[46]=c,e[47]=N):N=e[47];let T;e[48]!==n||e[49]!==r?.archivedBucket?(T=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=T):T=e[50];let M;e[51]!==N||e[52]!==T?(M=s.jsx("button",{type:"button",onClick:N,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:T}),e[51]=N,e[52]=T,e[53]=M):M=e[53];let F;e[54]!==C||e[55]!==M?(F=s.jsxs("div",{className:"flex items-center gap-2",children:[C,M]}),e[54]=C,e[55]=M,e[56]=F):F=e[56];let _;e[57]!==D||e[58]!==F?(_=s.jsxs(Us,{className:"w-full sm:items-center sm:justify-between",children:[D,F]}),e[57]=D,e[58]=F,e[59]=_):_=e[59];let B;e[60]!==m||e[61]!==h||e[62]!==_||e[63]!==v||e[64]!==y?(B=s.jsxs(m,{showCloseButton:h,className:v,children:[y,_]}),e[60]=m,e[61]=h,e[62]=_,e[63]=v,e[64]=y,e[65]=B):B=e[65];let V;return e[66]!==u||e[67]!==B||e[68]!==x||e[69]!==g?(V=s.jsx(u,{open:x,onOpenChange:g,children:B}),e[66]=u,e[67]=B,e[68]=x,e[69]=g,e[70]=V):V=e[70],V}function RA(t){const e=ot.c(57),{t:n}=pt(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let f;e[4]!==d||e[5]!==p||e[6]!==n?(f=d?p===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:p}):p===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:p}),e[4]=d,e[5]=p,e[6]=n,e[7]=f):f=e[7];const b=f,h=!!r;let v;e[8]!==a?(v=V=>{V||a(null)},e[8]=a,e[9]=v):v=e[9];let x;e[10]!==u?(x=s.jsx(gs,{children:u}),e[10]=u,e[11]=x):x=e[11];let g;e[12]!==b?(g=s.jsx(Ps,{children:b}),e[12]=b,e[13]=g):g=e[13];let w;e[14]!==x||e[15]!==g?(w=s.jsxs(vs,{children:[x,g]}),e[14]=x,e[15]=g,e[16]=w):w=e[16];let y;e[17]!==o||e[18]!==i?(y=()=>o(!i),e[17]=o,e[18]=i,e[19]=y):y=e[19];const k=!i;let A;e[20]!==i?(A=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=A):A=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let S;e[24]!==j||e[25]!==y||e[26]!==k||e[27]!==A?(S=s.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":k,children:[A,j]}),e[24]=j,e[25]=y,e[26]=k,e[27]=A,e[28]=S):S=e[28];let D;e[29]!==a?(D=()=>a(null),e[29]=a,e[30]=D):D=e[30];let E;e[31]!==n?(E=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=E):E=e[32];let P;e[33]!==D||e[34]!==E?(P=s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:E}),e[33]=D,e[34]=E,e[35]=P):P=e[35];let C;e[36]!==c?(C=()=>{c()},e[36]=c,e[37]=C):C=e[37];let N;e[38]!==d||e[39]!==n?(N=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=N):N=e[40];let T;e[41]!==C||e[42]!==N?(T=s.jsx("button",{type:"button",onClick:C,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:N}),e[41]=C,e[42]=N,e[43]=T):T=e[43];let M;e[44]!==P||e[45]!==T?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[P,T]}),e[44]=P,e[45]=T,e[46]=M):M=e[46];let F;e[47]!==S||e[48]!==M?(F=s.jsxs(Us,{className:"w-full sm:items-center sm:justify-between",children:[S,M]}),e[47]=S,e[48]=M,e[49]=F):F=e[49];let _;e[50]!==F||e[51]!==w?(_=s.jsxs(ms,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,F]}),e[50]=F,e[51]=w,e[52]=_):_=e[52];let B;return e[53]!==h||e[54]!==_||e[55]!==v?(B=s.jsx(ps,{open:h,onOpenChange:v,children:_}),e[53]=h,e[54]=_,e[55]=v,e[56]=B):B=e[56],B}function FA(t){const e=ot.c(36),{t:n}=pt(),{value:r,setValue:a,onConfirm:i}=t,o=!!r;let c;e[0]!==a?(c=A=>{A||a(null)},e[0]=a,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(gs,{children:d}),e[4]=d,e[5]=p):p=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let u;e[9]!==m?(u=s.jsx(Ps,{children:m}),e[9]=m,e[10]=u):u=e[10];let f;e[11]!==p||e[12]!==u?(f=s.jsxs(vs,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=f):f=e[13];let b;e[14]!==a?(b=()=>a(null),e[14]=a,e[15]=b):b=e[15];let h;e[16]!==n?(h=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=h):h=e[17];let v;e[18]!==b||e[19]!==h?(v=s.jsx("button",{type:"button",onClick:b,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:h}),e[18]=b,e[19]=h,e[20]=v):v=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=x):x=e[22];let g;e[23]!==i||e[24]!==x?(g=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:x}),e[23]=i,e[24]=x,e[25]=g):g=e[25];let w;e[26]!==g||e[27]!==v?(w=s.jsxs(Us,{children:[v,g]}),e[26]=g,e[27]=v,e[28]=w):w=e[28];let y;e[29]!==w||e[30]!==f?(y=s.jsxs(ms,{showCloseButton:!1,className:"max-w-sm gap-5",children:[f,w]}),e[29]=w,e[30]=f,e[31]=y):y=e[31];let k;return e[32]!==o||e[33]!==c||e[34]!==y?(k=s.jsx(ps,{open:o,onOpenChange:c,children:y}),e[32]=o,e[33]=c,e[34]=y,e[35]=k):k=e[35],k}const OA=t=>{const e=ot.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:o,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:f}=pt(),b=!!r&&!i;let h;e[0]!==i||e[1]!==f?(h=f(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=f,e[2]=h):h=e[2];const v=h;let x;e[3]!==n||e[4]!==f?(x=f("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=f,e[5]=x):x=e[5];let g;e[6]!==x?(g=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:x}),e[6]=x,e[7]=g):g=e[7];let w;e[8]!==b||e[9]!==p||e[10]!==c||e[11]!==o||e[12]!==d||e[13]!==a||e[14]!==f?(w=b?s.jsxs(Fs,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":f("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(I,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:f("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Rs,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:f("sessions.sidebar.folders.none")}):a.map(_=>s.jsx($t,{onClick:()=>o(_.id),children:s.jsx("span",{className:"flex-1 truncate",children:_.name})},_.id)),s.jsx(Cn,{}),s.jsxs($t,{onClick:c,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs($t,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=b,e[9]=p,e[10]=c,e[11]=o,e[12]=d,e[13]=a,e[14]=f,e[15]=w):w=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=ue("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=y):y=e[16];let k;e[17]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(I,{name:"delete-bin",className:"h-4 w-4"}),e[17]=k):k=e[17];let A;e[18]!==v||e[19]!==m?(A=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:y,"aria-label":v,children:k})}),e[18]=v,e[19]=m,e[20]=A):A=e[20];let j;e[21]!==v?(j=s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:v})}),e[21]=v,e[22]=j):j=e[22];let S;e[23]!==A||e[24]!==j?(S=s.jsxs(St,{children:[A,j]}),e[23]=A,e[24]=j,e[25]=S):S=e[25];let D;e[26]!==f?(D=f("sessions.sidebar.header.actions.exitSelection"),e[26]=f,e[27]=D):D=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(I,{name:"close",className:"h-4 w-4"}),e[28]=E):E=e[28];let P;e[29]!==u||e[30]!==D?(P=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":D,children:E})}),e[29]=u,e[30]=D,e[31]=P):P=e[31];let C;e[32]!==f?(C=f("sessions.sidebar.header.actions.exitSelection"),e[32]=f,e[33]=C):C=e[33];let N;e[34]!==C?(N=s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:C})}),e[34]=C,e[35]=N):N=e[35];let T;e[36]!==P||e[37]!==N?(T=s.jsxs(St,{children:[P,N]}),e[36]=P,e[37]=N,e[38]=T):T=e[38];let M;e[39]!==T||e[40]!==w||e[41]!==S?(M=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,S,T]}),e[39]=T,e[40]=w,e[41]=S,e[42]=M):M=e[42];let F;return e[43]!==M||e[44]!==g?(F=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[g,M]}),e[43]=M,e[44]=g,e[45]=F):F=e[45],F},$g="oc.sessions.activeNow",LA=2160*60*1e3,Bg=t=>!!t.parentID,ru=t=>!!t.time?.archived,kd=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},$A=t=>{try{const e=t.getItem($g);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,a=[];return n.forEach(i=>{const o=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!o||r.has(o)||(r.add(o),a.push({sessionId:o}))}),a}catch{return[]}},Lc=(t,e)=>{try{t.setItem($g,JSON.stringify(e))}catch{}},BA=(t,e,n=Date.now())=>{const r=n-LA;return t.filter(a=>{const i=e.get(a.sessionId);return i?ru(i)?!1:kd(i)>=r:!0})},_A=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],_g=t=>[...t].sort((e,n)=>kd(n)-kd(e)),zA=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!ru(r)).filter(r=>!Bg(r));return _g(n)},VA=(t,e)=>{const n=t.filter(r=>{if(ru(r)||Bg(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return _g(n)},Lo=br(),$c=nr((t,e)=>({entries:$A(Lo),setEntries:n=>{n!==e().entries&&(t({entries:n}),Lc(Lo,n))},addSession:n=>{const r=_A(e().entries,n);r!==e().entries&&(t({entries:r}),Lc(Lo,r))},prune:n=>{const r=e().entries,a=BA(r,n);a.length===r.length&&a.every((i,o)=>i.sessionId===r[o]?.sessionId)||(t({entries:a}),Lc(Lo,a))}})),$o="oc.sessions.projectCollapse",pf="oc.sessions.groupOrder",ff="oc.sessions.groupCollapse",hf="oc.sessions.activeSessionByProject",Bc="oc.sessions.expandedParents.v2",UA="oc.sessions.expandedParents",WA="oc.sessions.pinned",KA=(t,e)=>{const n=new Set;for(const r of t){const a=ys(r.path)?.toLowerCase();a&&n.add(a)}for(const r of e.values())for(const a of r){const i=ys(a.path)?.toLowerCase();i&&n.add(i)}return n},HA=(t,e)=>{if(t.time?.archived)return!0;const n=ys(Vi(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},GA=5*6e4,gf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=pt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),m=l.useRef(null),u=l.useRef(null),f=l.useRef(new Set),[b,h]=l.useState(null),[v,x]=l.useState(""),[g,w]=l.useState(null),[y,k]=l.useState(new Set),[A]=l.useState(()=>new Map),j=l.useMemo(()=>br(),[]),S=$c(Me=>Me.entries),D=$c(Me=>Me.addSession),E=$c(Me=>Me.prune),[P,C]=l.useState(new Set),[N,T]=l.useState(new Map),[M,F]=l.useState(new Set),[_,B]=l.useState(!1),[V,$]=l.useState(!1),[z,Q]=l.useState(null),[L,J]=l.useState(null),[ee,re]=l.useState(""),[q,ce]=l.useState(null),[ae,R]=l.useState(null),[U,W]=l.useState(null),Z=rc(Me=>Me.ids),K=rc(Me=>Me.setIds),ie=rc(Me=>Me.toggle),[Ne,ne]=l.useState(()=>{try{const Me=br().getItem(ff);if(!Me)return new Set;const wt=JSON.parse(Me);return new Set(Array.isArray(wt)?wt.filter(ht=>typeof ht=="string"):[])}catch{return new Set}}),[fe,pe]=l.useState(()=>{try{const Me=br().getItem(pf);if(!Me)return new Map;const wt=JSON.parse(Me),ht=new Map;return Object.entries(wt).forEach(([Yt,hs])=>{Array.isArray(hs)&&ht.set(Yt,hs.filter(sn=>typeof sn=="string"))}),ht}catch{return new Map}}),[je,oe]=l.useState(()=>{try{const Me=br().getItem(hf);if(!Me)return new Map;const wt=JSON.parse(Me),ht=new Map;return Object.entries(wt).forEach(([Yt,hs])=>{typeof hs=="string"&&hs.length>0&&ht.set(Yt,hs)}),ht}catch{return new Map}}),[Se,se]=l.useState(new Map),we=l.useRef(new Map),Ae=l.useRef(0),ve=_s(Me=>Me.homeDirectory),ye=_s(Me=>Me.currentDirectory),Ie=_s(Me=>Me.setDirectory),he=Ts(Me=>Me.projects),me=Ts(Me=>Me.activeProjectId),Ee=Ts(Me=>Me.removeProject),Ve=Ts(Me=>Me.setActiveProjectIdOnly),Y=Ts(Me=>Me.updateProjectMeta),ke=Ts(Me=>Me.reorderProjects),Be=De(Me=>Me.setActiveMainTab),Ce=De(Me=>Me.openContextPanelTab),ge=De(Me=>Me.setSettingsDialogOpen),O=De(Me=>Me.toggleHelpDialog),X=De(Me=>Me.setAboutDialogOpen),G=De(Me=>Me.setSessionSwitcherOpen),Te=De(Me=>Me.setScheduledTasksDialogOpen),le=De(Me=>Me.toggleSidebar),We=De(Me=>Me.openMultiRunLauncher),de=De(Me=>Me.notifyOnSubtasks),Fe=De(Me=>Me.showDeletionDialog),rt=De(Me=>Me.setShowDeletionDialog),Oe=Ml(d,120),Ye=l.useMemo(()=>Oe.trim().toLowerCase(),[Oe]),Ge=Ye.length>0,it=Yn(Me=>Me.collapsedFolderIds),Qe=Yn(Me=>Me.foldersMap),at=Yn(Me=>Me.getFoldersForScope),nt=Yn(Me=>Me.createFolder),be=Yn(Me=>Me.renameFolder),He=Yn(Me=>Me.deleteFolder),_e=Yn(Me=>Me.addSessionToFolder),tt=Yn(Me=>Me.addSessionsToFolder),ut=Yn(Me=>Me.removeSessionFromFolder),qe=Yn(Me=>Me.removeSessionsFromFolders),ze=Yn(Me=>Me.toggleFolderCollapse),st=Yn(Me=>Me.cleanupSessions),yt=Yn(Me=>Me.getSessionFolderId);qI({isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const Mt=ih(),Bt=Ud(),ft=Ad(),It=Ey(),ss=Ia(Me=>Me.hasLoaded),_t=Ia(Me=>Me.activeSessions),qt=Ia(Me=>Me.archivedSessions),ct=Lt(Me=>Me.currentSessionId),jt=Lt(Me=>!!Me.newSessionDraft?.open),as=Lt(Me=>Me.setCurrentSession),xs=Lt(Me=>Me.updateSessionTitle),ws=Lt(Me=>Me.shareSession),As=Lt(Me=>Me.unshareSession),Gt=Lt(Me=>Me.worktreeMetadata),Ke=Lt(Me=>Me.availableWorktreesByProject),Pt=Lt(Me=>Me.openNewSessionDraft),Ot=Da(hr(Me=>({checkForUpdates:Me.checkForUpdates,available:Me.available,runtimeType:Me.runtimeType,info:Me.info,downloading:Me.downloading,downloaded:Me.downloaded,progress:Me.progress,error:Me.error,downloadUpdate:Me.downloadUpdate,restartToUpdate:Me.restartToUpdate}))),Nt=l.useMemo(()=>KA(he,Ke),[Ke,he]),Ht=l.useMemo(()=>{const Me=new Map(ft.map(Yt=>[Yt.id,Yt])),wt=_t.map(Yt=>Me.get(Yt.id)??Yt),ht=new Set(wt.map(Yt=>Yt.id));return ft.forEach(Yt=>{ht.has(Yt.id)||wt.push(Yt)}),wt.filter(Yt=>HA(Yt,Nt))},[_t,Nt,ft]),ns=l.useMemo(()=>ft.map(Me=>{const wt=ys(Me.directory??null)??"";return`${Me.id}:${Me.title??""}:${Me.time?.archived?1:0}:${wt}`}).join("|"),[ft]),Ss=l.useRef(ft);l.useEffect(()=>{Ss.current=ft},[ns,ft]),l.useEffect(()=>{let Me=!1;const wt=async()=>{const ht=Ts.getState().projects;if(ht.length===0)return;const Yt=new Map,hs=[];await Promise.all(ht.map(async sn=>{const Pe=ys(sn.path);if(Pe)try{if(!(Zs.getState().directories.get(Pe)?.isGitRepo??await jr(()=>import("./modelPrefsAutoSave-bm-G98P3.js").then(Et=>Et.f2),__vite__mapDeps([2,0,1,3,4])).then(Et=>Et.checkIsGitRepository(Pe))))return;const gt=await Yc({id:sn.id,path:Pe});if(Me||gt.length===0)return;Yt.set(Pe,gt),hs.push(...gt)}catch{}})),!Me&&Lt.setState({availableWorktrees:hs,availableWorktreesByProject:Yt})};return Jc(Ss.current),wt(),()=>{Me=!0}},[ye,ns,he]),l.useEffect(()=>{let Me=null;const wt=Tg(ht=>{ht.type==="scheduled-task-ran"&&(Me&&clearTimeout(Me),Me=setTimeout(()=>{Jc(Ss.current)},500))});return()=>{Me&&clearTimeout(Me),wt()}},[]);const fs=l.useMemo(()=>dn(),[]),Os=Cl(),[zs,tn]=l.useState(!1),Ds=l.useMemo(()=>ln(),[]),{isTablet:zt}=nn(),Kt=t||zt,te=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),bt=!t&&!Ds&&!fs,Ze=!t&&!Ds&&!bt,Wt=fs&&te&&!zs||Os?"pl-[5.5rem]":"pl-3",es="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";l.useEffect(()=>{if(!fs||!te){tn(!1);return}let Me=!1,wt=null;const ht=async()=>{try{const hs=await Oy();Me||tn(hs)}catch{Me||tn(!1)}},Yt=async()=>{try{wt=Ly(()=>{ht()})}catch{}};return ht(),Yt(),()=>{Me=!0,wt&&wt()}},[fs,te]);const rs=l.useCallback(async Me=>{const wt=Me.target;wt.closest(".app-region-no-drag")||wt.closest("button, a, input, select, textarea")||Me.button===0&&fs&&await fh()},[fs]),{buildGroupSearchText:Ue,filterSessionNodesForSearch:xt,buildGroupedSessions:At}=GI({homeDirectory:ve,worktreeMetadata:Gt,pinnedSessionIds:Z,gitBranches:Mt,isVSCode:Ds}),{scheduleCollapsedProjectsPersist:Dt}=tP({isVSCode:Ds,hasLoadedGlobalSessions:ss,safeStorage:j,keys:{sessionExpanded:Bc,sessionExpandedLegacy:UA,projectCollapse:$o,sessionPinned:WA,groupOrder:pf,projectActiveSession:hf,groupCollapse:ff},sessions:Ht,setPinnedSessionIds:K,groupOrderByProject:fe,activeSessionByProject:je,collapsedGroups:Ne,setExpandedParents:k,setCollapsedProjects:C}),Zt=l.useMemo(()=>[...Ht].sort((Me,wt)=>ii(Me,wt,Z)),[Ht,Z]),Ut=l.useMemo(()=>new Map(Zt.map((Me,wt)=>[Me.id,wt])),[Zt]),ks=l.useMemo(()=>{const Me=new Map;return Zt.forEach(wt=>{const ht=wt.parentID;if(!ht)return;const Yt=Me.get(ht)??[];Yt.push(wt),Me.set(ht,Yt)}),Me.forEach(wt=>wt.sort((ht,Yt)=>ii(ht,Yt,Z))),Me},[Zt,Z]),Js=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noSessions.description")})]}),Ls=l.useMemo(()=>he.find(Me=>Me.id===g)??null,[he,g]),ts=l.useCallback(Me=>{g&&(Y(g,Me),w(null))},[g,Y]),js=l.useCallback(()=>{B(!0)},[]),yn=l.useCallback(()=>{const Me=Da.getState();if(Me.available&&Me.info){$(!0);return}Ot.checkForUpdates().then(()=>{const{available:wt,error:ht}=Da.getState();if(ht){H.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:ht});return}if(!wt){H.success(i("sessions.sidebar.updateCheck.latestVersion"));return}$(!0)})},[i,Ot]),cn=l.useCallback(()=>{t&&G(!1),ge(!0)},[t,G,ge]),Rr=Ot.available&&(Ot.runtimeType==="desktop"||Ot.runtimeType==="web"),kr=Lt(Me=>Me.deleteSession),Ws=Lt(Me=>Me.deleteSessions),Ln=Lt(Me=>Me.archiveSession),Vn=Lt(Me=>Me.archiveSessions),{copiedSessionId:er,handleSessionSelect:Cr,handleSessionDoubleClick:Un,handleSaveEdit:In,handleCancelEdit:an,handleShareSession:vn,handleCopyShareUrl:wn,handleUnshareSession:Le,handleDeleteSession:Tt,confirmDeleteSession:Qt}=YI({activeProjectId:me,currentDirectory:ye,currentSessionId:ct,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:o,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:Ve,setDirectory:Ie,setActiveMainTab:Be,setSessionSwitcherOpen:G,setCurrentSession:as,updateSessionTitle:xs,shareSession:ws,unshareSession:As,deleteSession:kr,deleteSessions:Ws,archiveSession:Ln,archiveSessions:Vn,childrenMap:ks,showDeletionDialog:Fe,setDeleteSessionConfirm:ce,deleteSessionConfirm:q,setEditingId:h,setEditTitle:x,editingId:b,editTitle:v}),cs=l.useCallback(()=>{if(!ae)return;const{scopeKey:Me,folderId:wt}=ae;R(null),He(Me,wt)},[ae,He]),Gs=l.useCallback(()=>{wr.requestDirectoryDialog()},[]);l.useEffect(()=>{if(!ct)return;const wt=Ht.find(Yt=>Yt.id===ct)?.parentID;if(!wt)return;const ht=[`project:active:${wt}`,`project:archived:${wt}`,`recent:active:${wt}`,`recent:archived:${wt}`];k(Yt=>{if(ht.every(sn=>Yt.has(sn)))return Yt;const hs=new Set(Yt);ht.forEach(sn=>hs.add(sn));try{j.setItem(Bc,JSON.stringify(Array.from(hs)))}catch{}return hs})},[ct,Ht,j]);const Ks=l.useCallback(Me=>{k(wt=>{const ht=new Set(wt);ht.has(Me)?ht.delete(Me):ht.add(Me);try{j.setItem(Bc,JSON.stringify(Array.from(ht)))}catch{}return ht})},[j]),bs=l.useCallback((Me,wt)=>{if(!Me)return null;wt&&it.has(wt)&&ze(wt);const ht=nt(Me,i("sessions.sidebar.folder.newFolderName"),wt);return J(ht.id),re(ht.name),ht},[it,ze,nt,i]),Hs=l.useCallback(Me=>{F(wt=>{const ht=new Set(wt);return ht.has(Me)?ht.delete(Me):ht.add(Me),ht})},[]),on=l.useCallback(()=>{Ae.current=Date.now()+150,C(()=>{const Me=new Set(he.map(wt=>wt.id));try{j.setItem($o,JSON.stringify(Array.from(Me)))}catch{}return Ds||Dt(Me),Me})},[he,Ds,j,Dt]),rr=l.useCallback(()=>{Ae.current=Date.now()+150,C(()=>{const Me=new Set;try{j.setItem($o,JSON.stringify([]))}catch{}return Ds||Dt(Me),Me})},[Ds,j,Dt]),Dn=l.useCallback(Me=>{Ae.current=Date.now()+150,C(wt=>{const ht=new Set(wt);ht.has(Me)?ht.delete(Me):ht.add(Me);try{j.setItem($o,JSON.stringify(Array.from(ht)))}catch{}return Ds||Dt(ht),ht})},[Ds,j,Dt]),Wn=l.useMemo(()=>he.map(Me=>({...Me,normalizedPath:ys(Me.path)})).filter(Me=>!!Me.normalizedPath),[he]),$r=l.useMemo(()=>Wn.map(Me=>Me.normalizedPath),[Wn]),{github:Ir}=On(),Pn=zn(Me=>Me.status),Kn=zn(Me=>Me.hasChecked),un=Ry($r),Hn=mr(Me=>Me.ensureEntry),jn=mr(Me=>Me.setParams),Fr=mr(Me=>Me.refreshTargets);nP({normalizedProjects:Wn,gitRepoStatus:un,setProjectRepoStatus:T,setProjectRootBranches:se});const ar=Lt(Me=>Me.isLoading);mP({isSessionsLoading:ar,sessions:Ht,archivedSessions:qt,normalizedProjects:Wn,isVSCode:Ds,availableWorktreesByProject:Ke,cleanupSessions:st});const{getSessionsForProject:gr,getArchivedSessionsForProject:Nn}=oP({isVSCode:Ds,sessions:Ht,archivedSessions:qt,availableWorktreesByProject:Ke});BI({normalizedProjects:Wn,sessions:Ht,archivedSessions:qt,availableWorktreesByProject:Ke,isVSCode:Ds,isSessionsLoading:ar,foldersMap:Qe,createFolder:nt,addSessionToFolder:_e,cleanupSessions:st});const Gn=l.useRef(!1);me&&N.has(me)&&(Gn.current=!!N.get(me));const{projectSections:tr,groupSearchDataByGroup:mn,sectionsForRender:ir,searchMatchCount:Ni}=VI({normalizedProjects:Wn,getSessionsForProject:gr,getArchivedSessionsForProject:Nn,availableWorktreesByProject:Ke,projectRepoStatus:N,projectRootBranches:Se,lastRepoStatus:Gn.current,buildGroupedSessions:At,hasSessionSearchQuery:Ge,normalizedSessionSearchQuery:Ye,filterSessionNodesForSearch:xt,buildGroupSearchText:Ue,foldersMap:Qe}),za=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")})]}),Jr=!0,{currentSessionDirectory:la}=WI({projectSections:tr,activeProjectId:me,activeSessionByProject:je,setActiveSessionByProject:oe,currentSessionId:ct,handleSessionSelect:Cr,newSessionDraftOpen:jt,mobileVariant:t,openNewSessionDraft:Pt,setActiveMainTab:Be,setSessionSwitcherOpen:G,sessions:Ht,worktreeMetadata:Gt}),{getOrderedGroups:hn}=KI(fe),ca=l.useRef(!1);l.useEffect(()=>{if(ca.current||tr.length===0)return;const Me=tr.flatMap(wt=>wt.groups.filter(ht=>ht.isArchivedBucket).map(ht=>`${wt.project.id}:${ht.id}`));Me.length>0&&ne(wt=>new Set([...wt,...Me])),ca.current=!0},[tr]);const Va=l.useMemo(()=>{const Me=new Map,wt=new Map;return tr.forEach(ht=>{const Yt=mh(ht.project.label?.trim()||Fa(ht.project.normalizedPath,ve)||ht.project.normalizedPath);ht.groups.forEach(hs=>{const sn=hs.branch&&hs.branch!=="HEAD"&&hs.branch!==Yt?hs.branch:null,Pe={projectLabel:Yt,branchLabel:sn},Je=mt=>{mt.forEach(gt=>{const Et=ht.project.normalizedPath.length,Jt=wt.get(gt.session.id)??-1;Et<Jt||(Me.set(gt.session.id,{node:gt,projectId:ht.project.id,groupDirectory:hs.directory,secondaryMeta:Pe}),wt.set(gt.session.id,Et),gt.children.length>0&&Je(gt.children))})};Je(hs.sessions)})}),Me},[tr,ve]),Re=Ca(Me=>Me.showRecentSection),Xe=l.useMemo(()=>Re?zA(S,new Map(Ht.map(Me=>[Me.id,Me]))).sort((Me,wt)=>ii(Me,wt,Z)):[],[S,Z,Ht,Re]),et=l.useMemo(()=>Re?VA(Ht,It):[],[It,Ht,Re]);l.useEffect(()=>{!Re||et.length===0||et.forEach(Me=>D(Me.id))},[D,et,Re]),l.useEffect(()=>{if(!Re)return;const Me=new Map;[...Ht,...qt].forEach(wt=>{Me.set(wt.id,wt)}),E(Me)},[qt,E,Ht,Re]);const dt=l.useMemo(()=>{if(!Re)return[];const Me=wt=>{const ht=Va.get(wt.id),Yt=ys(wt.directory??null);return{node:ht?.node??{session:wt,children:[],worktree:null},projectId:ht?.projectId??null,groupDirectory:ht?.groupDirectory??Yt,secondaryMeta:ht?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:Xe.map(Me)}]},[Xe,Va,Re,i]),Rt=l.useMemo(()=>new Set(Xe.map(Me=>Me.id)),[Xe]),Xt=l.useMemo(()=>[...Rt],[Rt]);nI({currentSessionId:ct,sortedSessions:Zt,recentSessionIds:Xt,ensureSessionRenderable:Bt.ensureSessionRenderable});const $s=l.useMemo(()=>{if(!Ds||Ge||Rt.size===0)return ir;const Me=wt=>wt.reduce((ht,Yt)=>{if(Rt.has(Yt.session.id))return ht;const hs=Me(Yt.children);return hs.length===Yt.children.length?(ht.push(Yt),ht):(ht.push({...Yt,children:hs}),ht)},[]);return ir.map(wt=>({...wt,groups:wt.groups.map(ht=>({...ht,sessions:Me(ht.sessions)}))}))},[Ds,Ge,Rt,ir]),Bs=l.useMemo(()=>{const Me=new Set;return $s.forEach(wt=>{wt.groups.forEach(ht=>{const Yt=ys(ht.directory??null),hs=ht.branch?.trim()||Mt.get(Yt||"")?.trim();!Yt||!hs||Me.add(Ki(Yt,hs))})}),[...Me]},[Mt,$s]),qn=y0(Bs);l.useEffect(()=>{if(!Kn||!Pn?.connected||!Ir)return;const Me=[],wt=Date.now();if($s.forEach(Yt=>{P.has(Yt.project.id)||Yt.groups.forEach(hs=>{const sn=ys(hs.directory??null),Pe=hs.branch?.trim()||Mt.get(sn||"")?.trim();if(!sn||!Pe)return;const Je=Ki(sn,Pe),mt=mr.getState().entries[Je],gt=!!mt?.status?.pr,Et=`${sn}::${Pe}`,Jt=Math.max(mt?.lastRefreshAt??0,mt?.lastDiscoveryPollAt??0),Cs=!!(mt?.isInitialStatusResolved&&!gt&&(!f.current.has(Et)||wt-Jt>=GA));(!mt||!mt.isInitialStatusResolved||Cs)&&(Cs&&f.current.add(Et),Me.push({directory:sn,branch:Pe}))})}),Me.length===0)return;const ht=new Map;Me.forEach(Yt=>{const hs=Ki(Yt.directory,Yt.branch,Yt.remoteName??null);ht.has(hs)||ht.set(hs,Yt)}),ht.forEach((Yt,hs)=>{Hn(hs),jn(hs,{directory:Yt.directory,branch:Yt.branch,remoteName:Yt.remoteName??null,canShow:!0,github:Ir,githubAuthChecked:Kn,githubConnected:Pn.connected})}),Fr([...ht.values()],{force:!0,silent:!0,markInitialResolved:!0})},[P,Hn,Ir,Kn,Pn?.connected,Mt,Fr,$s,jn]);const Br=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",Bl="h-4.5 w-4.5",_l=gP({isDesktopShellRuntime:fs,projectSections:tr,projectHeaderSentinelRefs:we}),Tn=l.useCallback((Me,wt=0,ht,Yt,hs=!1,sn,Pe="project")=>s.jsx(MA,{node:Me,depth:wt,groupDirectory:ht,projectId:Yt,archivedBucket:hs,directoryStatus:A,currentSessionId:ct,pinnedSessionIds:Z,expandedParents:y,hasSessionSearchQuery:Ge,normalizedSessionSearchQuery:Ye,notifyOnSubtasks:de,editingId:b,setEditingId:h,editTitle:v,setEditTitle:x,handleSaveEdit:In,handleCancelEdit:an,toggleParent:Ks,handleSessionSelect:Cr,handleSessionDoubleClick:Un,togglePinnedSession:ie,handleShareSession:vn,copiedSessionId:er,handleCopyShareUrl:wn,handleUnshareSession:Le,openSidebarMenuKey:z,setOpenSidebarMenuKey:Q,renamingFolderId:L,getFoldersForScope:at,getSessionFolderId:yt,removeSessionFromFolder:ut,addSessionToFolder:_e,createFolderAndStartRename:bs,openContextPanelTab:Ce,handleDeleteSession:Tt,mobileVariant:t,alwaysShowActions:Kt,renderSessionNode:Tn,secondaryMeta:sn,renderContext:Pe}),[A,ct,Z,y,Ge,Ye,de,b,h,v,x,In,an,Ks,Cr,Un,ie,vn,er,wn,Le,z,Q,L,at,yt,ut,_e,bs,Ce,Tt,t,Kt]),Xr=l.useCallback(Me=>{ne(wt=>{const ht=new Set(wt);return ht.has(Me)?ht.delete(Me):ht.add(Me),ht})},[]),Ua=l.useMemo(()=>{const Me=new Map;for(const[wt,ht]of qn)Me.set(wt,{visualState:ht.visualState,number:ht.number,url:ht.url,state:ht.prState,draft:ht.draft,title:ht.title,base:ht.base,head:ht.head,checks:ht.checks,canMerge:ht.canMerge,mergeableState:ht.mergeableState,repo:ht.repo});return Me},[qn]),Si=l.useCallback((Me,wt,ht,Yt,hs,sn)=>s.jsx(RP,{group:Me,groupKey:wt,projectId:ht,hideGroupLabel:Yt,compactBodyPadding:sn,hasSessionSearchQuery:Ge,normalizedSessionSearchQuery:Ye,groupSearchDataByGroup:mn,expandedSessionGroups:M,collapsedGroups:Ne,hideDirectoryControls:r,collapsedFolderIds:it,toggleFolderCollapse:ze,renameFolder:be,deleteFolder:He,showDeletionDialog:Fe,setDeleteFolderConfirm:R,renderSessionNode:Tn,currentSessionDirectory:la,projectRepoStatus:N,lastRepoStatus:Gn.current,toggleGroupSessionLimit:Hs,mobileVariant:t,alwaysShowActions:Kt,activeProjectId:me,setActiveProjectIdOnly:Ve,setActiveMainTab:Be,setSessionSwitcherOpen:G,openNewSessionDraft:Pt,addSessionToFolder:_e,createFolderAndStartRename:bs,renamingFolderId:L,renameFolderDraft:ee,setRenameFolderDraft:re,setRenamingFolderId:J,pinnedSessionIds:Z,sessionOrderIndex:Ut,prVisualStateByDirectoryBranch:Ua,onToggleCollapsedGroup:Xr,dragHandleProps:hs}),[Ge,Ye,mn,M,Ne,r,it,ze,be,He,Fe,Tn,la,N,Hs,t,Kt,me,Ve,Be,G,Pt,_e,bs,L,ee,Z,Ut,Ua,Xr]),ou=Re&&!Ge?s.jsx(zP,{sections:dt,renderSessionNode:Tn}):null,da=!!(L||b||g),_r=ur(Me=>Me.enabled),Xs=ur(Me=>Me.selectedIds),ua=ur(Me=>Me.scopeKey),Wa=ur,ho=l.useCallback(()=>{ur.getState().toggleMode()},[]),go=l.useCallback(()=>{ur.getState().disable()},[]),ma=l.useMemo(()=>{if(Xs.size===0||typeof document>"u")return!1;let Me=!1,wt=!1;for(const ht of Xs){const Yt=document.querySelectorAll(`[data-session-row="${CSS.escape(ht)}"]`);for(const hs of Yt)hs.getAttribute("data-session-archived")==="1"?wt=!0:Me=!0}return wt&&!Me},[Xs]),Sn=l.useMemo(()=>{if(ua)return ua;if(Xs.size===0||typeof document>"u")return null;for(const Me of Xs){const ht=document.querySelector(`[data-session-row="${CSS.escape(Me)}"]`)?.getAttribute("data-session-scope");if(ht&&ht.length>0)return ht}return null},[Xs,ua]),Ka=l.useMemo(()=>Sn?Qe[Sn]??[]:[],[Qe,Sn]),zl=l.useMemo(()=>{if(!Sn||Xs.size===0)return!1;const Me=Qe[Sn]??[];for(const wt of Me)for(const ht of wt.sessionIds)if(Xs.has(ht))return!0;return!1},[Qe,Sn,Xs]),Vl=l.useCallback(Me=>{!Sn||Xs.size===0||tt(Sn,Me,Array.from(Xs))},[tt,Xs,Sn]),xo=l.useCallback(()=>{if(!Sn||Xs.size===0)return;const Me=bs(Sn);Me&&tt(Sn,Me.id,Array.from(Xs))},[tt,bs,Xs,Sn]),Zr=l.useCallback(()=>{!Sn||Xs.size===0||qe(Sn,Array.from(Xs))},[qe,Xs,Sn]),pa=l.useCallback(async()=>{const Me=Array.from(Xs);if(Me.length!==0){if(ma){const{deletedIds:wt,failedIds:ht}=await Ws(Me);wt.length>0&&H.success(wt.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:wt.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:wt.length})),ht.length>0&&H.error(ht.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ht.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:ht.length}))}else{const{archivedIds:wt,failedIds:ht}=await Vn(Me);wt.length>0&&H.success(wt.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:wt.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:wt.length})),ht.length>0&&H.error(ht.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ht.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:ht.length}))}ur.getState().clear()}},[Vn,ma,Ws,Xs,i]),Ha=l.useCallback(()=>{const Me=Xs.size;if(Me!==0){if(!Fe){pa();return}W({sessionCount:Me,archivedBucket:ma})}},[ma,pa,Xs,Fe]),bo=l.useCallback(async()=>{W(null),await pa()},[pa]);l.useEffect(()=>{if(!_r)return;const Me=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),wt=ht=>{if(da)return;const Yt=ht.target;if(Yt&&(Yt.tagName==="INPUT"||Yt.tagName==="TEXTAREA"||Yt.isContentEditable))return;const hs=Me?ht.metaKey:ht.ctrlKey;if(ht.key==="Escape"){ht.preventDefault(),ur.getState().disable();return}if(hs&&ht.key==="Backspace"){ht.preventDefault(),Ha();return}if(hs&&(ht.key==="a"||ht.key==="A")){const sn=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(sn.length===0)return;ht.preventDefault();const Je=Wa.getState().scopeKey??sn[0]?.getAttribute("data-session-scope")??null,mt=Et=>Je?Et.getAttribute("data-session-scope")===Je:!0,gt=sn.filter(mt).map(Et=>Et.getAttribute("data-session-row")).filter(Et=>typeof Et=="string"&&Et.length>0);if(gt.length===0)return;Wa.getState().replaceAll(gt,Je||null)}};return window.addEventListener("keydown",wt),()=>window.removeEventListener("keydown",wt)},[Ha,da,Wa,_r]);const Ul=l.useCallback(()=>{Be("chat"),t&&G(!1),Pt()},[t,Pt,Be,G]),Wl=l.useCallback(()=>{Be("chat"),t&&G(!1),We()},[t,We,Be,G]);return s.jsxs("div",{ref:m,className:ue("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[Ze?s.jsx("div",{onMouseDown:rs,className:ue("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",Wt),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:le,className:es,"aria-label":i("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(I,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Ct,{children:s.jsx("p",{children:i("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(FP,{hideDirectoryControls:r,handleOpenDirectoryDialog:Gs,handleNewSession:Ul,canOpenMultiRun:he.length>0,openMultiRunLauncher:Wl,headerActionIconClass:Bl,reserveHeaderActionsSpace:Jr,headerActionButtonClass:Br,isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:Ge,searchMatchCount:Ni,collapseAllProjects:on,expandAllProjects:rr,openScheduledTasksDialog:()=>Te(!0),selectionModeEnabled:_r,onToggleSelectionMode:ho,showSidebarToggle:bt,onToggleSidebar:le,avoidWindowControlsOverlay:Os}),s.jsx(JP,{topContent:ou,sectionsForRender:$s,projectSections:tr,activeProjectId:me,showOnlyMainWorkspace:a,hasSessionSearchQuery:Ge,emptyState:Js,searchEmptyState:za,renderGroupSessions:Si,homeDirectory:ve,collapsedProjects:P,hideDirectoryControls:r,projectRepoStatus:N,isDesktopShellRuntime:fs,stuckProjectHeaders:_l,mobileVariant:t,alwaysShowActions:Kt,toggleProject:Dn,setActiveProjectIdOnly:Ve,setActiveMainTab:Be,setSessionSwitcherOpen:G,openNewSessionDraft:Pt,openNewWorktreeDialog:js,openProjectEditDialog:w,removeProject:Ee,projectHeaderSentinelRefs:we,reorderProjects:ke,getOrderedGroups:hn,setGroupOrderByProject:pe,openSidebarMenuKey:z,setOpenSidebarMenuKey:Q,isInlineEditing:da}),_r&&Xs.size>0?s.jsx(OA,{selectedCount:Xs.size,scopeKey:Sn,scopeFolders:Ka,archivedBucket:ma,onMoveToFolder:Vl,onCreateFolderAndMove:xo,onRemoveFromFolder:Zr,canRemoveFromFolder:zl,onDelete:Ha,onDone:go}):null,s.jsx(UP,{onOpenSettings:cn,onOpenShortcuts:O,onOpenAbout:()=>X(!0),onOpenUpdate:yn,showRuntimeButtons:!Ds,showUpdateButton:Rr}),s.jsx(vd,{open:V,onOpenChange:$,info:Ot.info,downloading:Ot.downloading,downloaded:Ot.downloaded,progress:Ot.progress,error:Ot.error,onDownload:Ot.downloadUpdate,onRestart:Ot.restartToUpdate,runtimeType:Ot.runtimeType}),Ls?s.jsx(Fy,{open:!!Ls,onOpenChange:Me=>{Me||w(null)},projectId:Ls.id,projectName:Ls.label||Fa(Ls.path,ve),projectPath:Ls.path,initialIcon:Ls.icon,initialColor:Ls.color,initialIconBackground:Ls.iconBackground,onSave:ts}):null,s.jsx(lI,{open:_,onOpenChange:B,onWorktreeCreated:(Me,wt)=>{if(Be("chat"),t&&G(!1),wt?.sessionId){as(wt.sessionId);return}Pt({directoryOverride:Me})}}),s.jsx(LI,{}),s.jsx(EA,{value:q,setValue:ce,showDeletionDialog:Fe,setShowDeletionDialog:rt,onConfirm:Qt}),s.jsx(FA,{value:ae,setValue:R,onConfirm:cs}),s.jsx(RA,{value:U,setValue:W,showDeletionDialog:Fe,setShowDeletionDialog:rt,onConfirm:bo})]})},qA=()=>{const t=ot.c(13),[e,n]=$e.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(dn())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),$e.useEffect(r,a);let i;t[2]!==e?(i=async f=>e?await $y(f):{success:!0,path:f},t[2]=e,t[3]=i):i=t[3];const o=i;let c;t[4]!==e?(c=async f=>e?await By():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async f=>e?await _y():{success:!0},t[6]=e,t[7]=p):p=t[7];const m=p;let u;return t[8]!==e||t[9]!==o||t[10]!==d||t[11]!==m?(u={isDesktop:e,requestAccess:o,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=o,t[10]=d,t[11]=m,t[12]=u):u=t[12],u},YA=t=>t==="/",jl=t=>t.replace(/\\/g,"/"),au=t=>{if(!t||YA(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},ci=t=>t.endsWith("/"),JA=t=>{const e=t.trim();return!e||ci(e)?e:`${e}/`},iu=t=>t.lastIndexOf("/"),zg=t=>{if(ci(t))return t;const e=iu(t);return e<0?t:t.slice(0,e+1)},QA=t=>{const e=iu(t);return t.slice(e+1)},Vg=t=>{const e=au(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=iu(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},XA=t=>ci(t)&&Vg(t)!==null,ZA=(t,e)=>`${zg(t)}${e}/`,Ya=t=>{if(!t)return null;const e=au(jl(t.trim()));return e?e.toLowerCase():null},xf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},eD=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,_c=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},tD=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 jl(e.home.trim())}}catch{}return en.getFilesystemHome().catch(()=>null)},sD=({open:t,onOpenChange:e})=>{const{t:n}=pt(),r=_s(le=>le.homeDirectory),a=Ts(le=>le.projects),i=Ts(le=>le.addProject),o=Jn(le=>le.profiles),c=Jn(le=>le.globalIdentity),d=Jn(le=>le.defaultGitIdentityId),p=Jn(le=>le.loadProfiles),m=Jn(le=>le.loadGlobalIdentity),u=Jn(le=>le.loadDefaultGitIdentityId),f=Tl(),{isDesktop:b,requestAccess:h,startAccessing:v}=qA(),{isMobile:x}=nn(),g=l.useRef(null),w=l.useRef(null),y=l.useRef(new Map),[k,A]=l.useState(""),[j,S]=l.useState("~/"),[D,E]=l.useState([]),[P,C]=l.useState(!1),[N,T]=l.useState(!1),[M,F]=l.useState(0),[_,B]=l.useState(!1),[V,$]=l.useState(!1),[z,Q]=l.useState(0),[L,J]=l.useState(!1),[ee,re]=l.useState(""),[q,ce]=l.useState(null),ae=k||r,R=l.useMemo(()=>new Set(a.map(le=>Ya(le.path)).filter(le=>!!le)),[a]);l.useEffect(()=>{if(!t)return;S("~/"),E([]),F(0),B(!1),$(!1),J(!1),re(""),ce(null),requestAnimationFrame(()=>_c(g.current));let le=!1;return(async()=>{const de=await tD();le||(A(de||r||""),requestAnimationFrame(()=>_c(g.current)))})(),()=>{le=!0}},[r,t]),l.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const U=l.useMemo(()=>{const le=new Map;c&&le.set(c.id,c);for(const We of o)le.set(We.id,We);return Array.from(le.values())},[o,c]);l.useEffect(()=>{if(!t||!L||q!==null)return;const le=typeof d=="string"?d.trim():"";if(le&&U.some(de=>de.id===le)){ce(le);return}const We=U.find(de=>de.authType==="ssh"||de.sshKey);We&&ce(We.id)},[U,d,L,t,q]);const W=l.useMemo(()=>U.find(le=>le.id===q)??null,[U,q]),Z=l.useMemo(()=>zg(j),[j]),K=l.useMemo(()=>ci(j)?"":QA(j),[j]),ie=l.useMemo(()=>ae?xf(Z,ae):"",[Z,ae]);l.useEffect(()=>{if(!t||!ie){E([]);return}let le=!1;return C(!0),T(!1),en.listLocalDirectory(ie).then(We=>{if(le)return;T(!1);const de=We.filter(Fe=>Fe.isDirectory).map(Fe=>({name:Fe.name,path:jl(Fe.path)})).sort((Fe,rt)=>Fe.name.localeCompare(rt.name));E(de)}).catch(()=>{le||(E([]),T(!0))}).finally(()=>{le||C(!1)}),()=>{le=!0}},[ie,t]);const Ne=l.useMemo(()=>{const le=K.toLowerCase(),We=f||K.startsWith(".");return D.filter(de=>de.name.toLowerCase().startsWith(le)&&(We||!de.name.startsWith(".")))},[K,D,f]),ne=l.useMemo(()=>{const le=[];XA(j)&&le.push({type:"up",value:"browse:up",name:"..",path:Vg(j)});for(const We of Ne){const de=Ya(We.path);le.push({type:"directory",value:`browse:${We.path}`,name:We.name,path:We.path,disabled:!!(de&&R.has(de))})}return le},[R,Ne,j]);l.useEffect(()=>{F(0)},[j,ne.length]);const fe=l.useMemo(()=>ae?au(xf(j,ae)):"",[ae,j]),pe=Ya(fe),je=!!(pe&&R.has(pe)),oe=l.useMemo(()=>K?Ne.find(le=>le.name===K)??null:null,[K,Ne]),Se=!!(fe&&!je&&(ci(j)&&N||!ci(j)&&K.trim().length>0&&oe===null)),se=!_&&!V&&!je&&!!fe,we=se&&ee.trim().length>0,Ae=ne[M]??null,ve=!!(Ae&&(Ae.type==="up"||Ae.type==="directory"&&!Ae.disabled)),ye=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Ie=n(je?"directoryExplorerDialog.actions.alreadyAdded":L?_?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":_?"directoryExplorerDialog.actions.adding":Se?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const le=w.current;if(!le)return;const We=()=>Q(Math.ceil(le.getBoundingClientRect().width));if(We(),typeof ResizeObserver>"u")return;const de=new ResizeObserver(We);return de.observe(le),()=>de.disconnect()},[Ie]),l.useLayoutEffect(()=>{const le=g.current;le&&(le.scrollLeft=le.scrollWidth)},[z,j]),l.useLayoutEffect(()=>{t&&_c(g.current)},[t]),l.useLayoutEffect(()=>{const le=ne[M];le&&y.current.get(le.value)?.scrollIntoView({block:"nearest"})},[M,ne]);const he=l.useCallback(()=>{e(!1)},[e]),me=l.useCallback(async le=>{if(!le||_)return;const We=Ya(le);if(We&&R.has(We))return;let de=le;B(!0);try{const Fe=!L&&Se&&Ya(le)===Ya(fe);if(L){const Oe=ee.trim();if(!Oe){H.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}de=(await en.cloneRepository({remoteUrl:Oe,destinationPath:le,gitIdentityId:W?.id??null})).path}else Fe&&await en.createDirectory(le,{allowOutsideWorkspace:!0});if(!i(de)){H.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}he()}catch(Fe){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Fe instanceof Error?Fe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{B(!1)}},[i,R,ee,he,L,_,W?.id,Se,fe,n]),Ee=l.useCallback(le=>{S(JA(le))},[]),Ve=l.useCallback(le=>{S(ZA(j,le.name))},[j]),Y=l.useCallback(le=>{if(le){if(le.type==="up"){le.path&&Ee(le.path);return}le.disabled||Ve(le)}},[Ee,Ve]),ke=l.useCallback(async()=>{if(!(!b||V)){$(!0);try{const le=await h(fe);if(!le.success||!le.path){le.error&&le.error!=="Directory selection cancelled"&&H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:le.error});return}const We=await v(le.path);if(!We.success){H.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:We.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await me(le.path)}catch(le){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:le instanceof Error?le.message:n("directoryExplorerDialog.toast.unknownError")})}finally{$(!1)}}},[me,b,V,h,v,n,fe]),Be=l.useCallback(le=>{if(le.key==="ArrowDown"){le.preventDefault(),F(We=>Math.min(ne.length-1,We+1));return}if(le.key==="ArrowUp"){le.preventDefault(),F(We=>Math.max(0,We-1));return}if(le.key==="Enter"){if(le.preventDefault(),eD(le)){me(fe);return}ve&&Y(Ae);return}le.key==="Backspace"&&j===""&&(le.preventDefault(),he())},[Y,me,he,ve,Ae,j,ne.length,fe]),Ce=s.jsxs("button",{type:"button",onClick:()=>Uo(!f),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[f?s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),ge=s.jsxs("div",{className:"px-2.5 py-1.5",children:[L?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Vt,{value:ee,onChange:le=>re(le.target.value),placeholder:n("directoryExplorerDialog.clone.remoteUrlPlaceholder"),className:"min-w-0 flex-1 border-border/60 bg-[var(--surface-elevated)] font-mono typography-ui-label shadow-none",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),s.jsx($h,{activeProfile:W,identities:U,onSelect:le=>ce(le.id),isApplying:_,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(Vt,{ref:g,value:j,onChange:le=>S(jl(le.target.value)),onKeyDown:Be,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!x&&z>0?{paddingRight:`${z+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),x?null:s.jsx(xe,{ref:w,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:L?!we:!se,onMouseDown:le=>le.preventDefault(),onClick:()=>{me(fe)},title:Ie,children:Ie})]})]}),O=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsx("div",{className:"px-2 pb-1 pt-0.5 typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),P?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):ne.length===0?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):s.jsx("div",{className:"space-y-0.5",children:ne.map((le,We)=>{const de=We===M;return s.jsxs("button",{ref:Fe=>{Fe?y.current.set(le.value,Fe):y.current.delete(le.value)},type:"button",disabled:le.type==="directory"&&le.disabled,onMouseEnter:()=>F(We),onMouseDown:Fe=>Fe.preventDefault(),onClick:()=>Y(le),className:ue("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",de&&"bg-interactive-selection text-interactive-selection-foreground",!de&&"hover:bg-interactive-hover/50",le.type==="directory"&&le.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[le.type==="up"?s.jsx(I,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(I,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:le.name})}),le.type==="directory"&&le.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]},le.value)})})]})}),X=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[ge,O]}),G=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(I,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(I,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(I,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:ye}),s.jsx(I,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Te=()=>s.jsxs(s.Fragment,{children:[x?null:G,s.jsxs("div",{className:ue("flex w-full flex-row justify-end gap-2 sm:w-auto",x&&"justify-stretch"),children:[b?s.jsx(xe,{variant:"ghost",size:"xs",onClick:ke,disabled:_||V||L,children:n(V?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(xe,{variant:"ghost",size:"xs",onClick:()=>J(le=>!le),disabled:_||V,className:ue(x&&"flex-1"),children:n(L?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),x?s.jsx(xe,{size:"xs",onClick:()=>{me(fe)},disabled:L?!we:!se,className:"flex-1",children:Ie}):null]})]});return x?s.jsx(Mr,{open:t,onClose:he,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:Te()}),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}),X]})}):s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(vs,{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(gs,{children:n("directoryExplorerDialog.title")}),s.jsx(Ps,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),Ce]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:X}),s.jsx(Us,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Te()})]})})},va=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Ar=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},nD=()=>{const{t}=pt(),[e,n]=l.useState(!1),[r,a]=l.useState(!1),[i,o]=l.useState(null),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(!1),[b,h]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(new Set),y=Lt(se=>se.getWorktreeMetadata),k=Lt(se=>se.newSessionDraft),A=Lt(se=>se.setNewSessionDraftTarget),j=Lt(se=>se.setDraftBootstrapPendingDirectory),S=zy,D=Wy,E=Lt(se=>se.deleteSessions),P=Lt(se=>se.archiveSessions),C=De(se=>se.showDeletionDialog),N=De(se=>se.setShowDeletionDialog),T=_s(se=>se.currentDirectory),M=_s(se=>se.homeDirectory),F=_s(se=>se.isHomeReady),_=Ts(se=>se.projects),B=Ts(se=>se.activeProjectId),{isMobile:V,isTablet:$,hasTouchInput:z}=nn(),Q=V||$||z,L=l.useMemo(()=>{const we=(B?_.find(Ae=>Ae.id===B)??null:null)?.path??T;return Ar(we)},[B,T,_]),J=l.useCallback(se=>{const Ae=Ar(se.projectDirectory)||L;return{id:(_.find(ye=>Ar(ye.path)===Ae)??null)?.id??`path:${Ae}`,path:Ae}},[L,_]),ee=v&&g.size>0,re=l.useMemo(()=>{const se=i?.worktree;return se&&typeof se.branch=="string"&&se.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:we})=>typeof we.branch=="string"&&we.branch.trim().length>0)},[i?.worktree,c]),q=i?.mode==="worktree",ce=q,ae=b||!q||!re,R=b||!q;l.useEffect(()=>{r||!F||_.length>0||(a(!0),n(!0))},[r,F,_.length]);const U=l.useCallback(se=>{o({sessions:se.sessions,dateLabel:se.dateLabel,mode:se.mode??"session",worktree:se.worktree??null})},[]),W=l.useCallback(()=>{o(null),d([]),m(!1),f(!1),h(!1),x(!1),w(new Set)},[]),Z=l.useCallback(async se=>{if(se.sessions.length===0)return;if(se.sessions.length===1){const ye=se.sessions[0];await S(ye.id)?H.success(t("sessions.sidebar.session.delete.success")):H.error(t("sessions.sidebar.session.delete.error"));return}const we=se.sessions.map(ye=>ye.id),{deletedIds:Ae,failedIds:ve}=await E(we);if(Ae.length>0){const ye=ve.length>0?ve.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ve.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ve.length}):se.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:se.dateLabel}):void 0;H.success(Ae.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ae.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ae.length}),{description:va(ye)})}ve.length>0&&H.error(ve.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ve.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ve.length}),{description:va(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[S,E,t]);l.useEffect(()=>wr.onDeleteRequest(se=>{if(!C&&(se.mode??"session")==="session"){Z(se);return}U(se)}),[U,C,Z]),l.useEffect(()=>wr.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),f(!1),x(!1),w(new Set);return}const se=i.sessions.map(ve=>{const ye=y(ve.id);return ye?{session:ve,metadata:ye}:null}).filter(ve=>!!ve);d(se),m(!1),x(!1),w(new Set);const we=new Map;if(i.worktree?.path&&we.set(Ar(i.worktree.path),i.worktree),se.forEach(({metadata:ve})=>{ve.path&&we.set(Ar(ve.path),ve)}),we.size===0){x(!0);return}let Ae=!1;return(async()=>{const ve=new Map,ye=new Set;await Promise.all(Array.from(we.entries()).map(async([Ie,he])=>{try{const me=await Vy(he.path);ve.set(Ie,me),me?.isDirty&&ye.add(Ie)}catch{he.status&&(ve.set(Ie,he.status),he.status.isDirty&&ye.add(Ie))}})).catch(Ie=>{console.warn("Failed to inspect worktree status before deletion:",Ie)}),!Ae&&(w(ye),x(!0),o(Ie=>{if(!Ie?.worktree?.path)return Ie;const he=Ar(Ie.worktree.path),me=ve.get(he);if(!me)return Ie;const Ee=Ie.worktree.status;return Ee?.isDirty===me.isDirty&&Ee?.ahead===me.ahead&&Ee?.behind===me.behind&&Ee?.upstream===me.upstream?Ie:{...Ie,worktree:{...Ie.worktree,status:me}}}),d(Ie=>Ie.map(he=>{const me=Ar(he.metadata.path),Ee=ve.get(me);return Ee?{session:he.session,metadata:{...he.metadata,status:Ee}}:he})))})(),()=>{Ae=!0}},[i,y]),l.useEffect(()=>{re||m(!1)},[re]);const K=l.useCallback(async(se,we)=>{const Ae=p&&re,ve=J(se),ye=Ar(se.path),Ie=Ar(ve.path);try{await Uy(ve,se,{deleteRemoteBranch:Ae,deleteLocalBranch:we});const he=Ar(k?.directoryOverride);return k?.open&&ye&&he===ye&&Ie&&(j(null),A({projectId:ve.id,directoryOverride:Ie},{force:!0})),Ar(T)===ye&&Ie&&_s.getState().setDirectory(Ie,{showOverlay:!1}),!0}catch(he){return H.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:va(he instanceof Error?he.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[re,T,p,J,k?.directoryOverride,k?.open,j,A,t]),ie=l.useCallback(async()=>{if(i){h(!0);try{const se=ce,we=se&&p,Ae=se&&u;if(i.sessions.length===0&&q&&i.worktree){if(!await K(i.worktree,Ae)){W();return}const Ie=t(p&&re?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");H.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:va(Ie)}),W();return}if(i.sessions.length===1){const ve=i.sessions[0];if(!(q?await D(ve.id):await S(ve.id,{archiveWorktree:!1,deleteRemoteBranch:we,deleteLocalBranch:Ae}))){H.error(t(q?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),h(!1);return}const Ie=!q&&se?t(we?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;H.success(t(q?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:va(Ie),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const ve=i.sessions.map(he=>he.id);let ye=[],Ie=[];if(q){const he=await P(ve);ye=he.archivedIds,Ie=he.failedIds}else{const he=await E(ve);ye=he.deletedIds,Ie=he.failedIds}if(q&&i.worktree&&Ie.length===0&&await K(i.worktree,Ae),ye.length>0){const he=!q&&se?t(we?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Ee=[Ie.length>0?q?Ie.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:Ie.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:Ie.length}):Ie.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Ie.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Ie.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,he].filter(Boolean).join(" ");H.success(q?ye.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:ye.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:ye.length}):ye.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ye.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ye.length}),{description:va(Ee||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(Ie.length>0&&(H.error(q?Ie.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Ie.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:Ie.length}):Ie.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Ie.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Ie.length}),{description:va(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),ye.length===0)){h(!1);return}}q&&i.sessions.length===1&&i.worktree&&await K(i.worktree,Ae),W()}finally{h(!1)}}},[i,p,u,S,E,D,P,W,ce,q,re,K,t]),Ne=i?.worktree??c[0]?.metadata??null,ne=i?i.mode==="worktree"?i.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):i.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:i.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:i.sessions.length}):i.sessions.length===1?i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:i.sessions.length,dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:i.sessions.length}):"",fe=i?s.jsxs("div",{className:ue(q?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:ue(q?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[q&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:ue(q?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(se=>s.jsxs("li",{className:ue(q?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:ue(!q&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:se.title||t("sessions.sidebar.session.untitled")})]},se.id)),i.sessions.length>5&&s.jsx("li",{className:ue(q?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:i.sessions.length-5})})]})]}),q?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),Ne?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:Ne.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:Ne?Xi(Ne.path,M):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),ee&&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,pe=q?re?s.jsxs("button",{type:"button",onClick:()=>{ae||m(se=>!se)},disabled:ae,className:ue("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",ae?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,je=q?s.jsxs("button",{type:"button",onClick:()=>{R||f(se=>!se)},disabled:R,className:ue("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",R?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,oe=q?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[je,pe]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xe,{variant:"ghost",onClick:W,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(xe,{variant:"destructive",onClick:ie,disabled:b,children:t(b?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>N(!C),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!C,children:[C?s.jsx(I,{name:"checkbox-blank",className:"size-4"}):s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(xe,{variant:"ghost",onClick:W,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(xe,{variant:"destructive",onClick:ie,disabled:b,children:b?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),Se=q?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[Q?s.jsx(Mr,{open:!!i,onClose:()=>{b||W()},title:Se,footer:s.jsx("div",{className:"flex justify-end gap-2",children:oe}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[ne&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:ne}),fe]})}):s.jsx(ps,{open:!!i,onOpenChange:se=>{if(!se){if(b)return;W()}},children:s.jsxs(ms,{className:ue(q?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(vs,{children:[s.jsxs(gs,{className:ue(q&&"flex items-center gap-2"),children:[q&&s.jsx(I,{name:"delete-bin",className:"h-5 w-5"}),Se]}),ne&&s.jsx(Ps,{children:ne})]}),s.jsx("div",{className:ue(q&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:fe}),s.jsx(Us,{className:"mt-2 gap-2 pt-1 pb-1",children:oe})]})}),s.jsx(sD,{open:e,onOpenChange:n})]})},Cd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),rD=(t,e)=>{const n=Cd(t),r=Cd(e);return`${n}-${r}`.substring(0,60)},bf=(t,e)=>`${t}/${e}`,aD=()=>{const t=Ts.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=_s.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},zc=nr()(vi(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:a,agent:i,files:o,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r)return t({error:"Prompt is required"}),null;if(a.length<1)return t({error:"Select at least 1 model"}),null;if(a.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=aD();if(!d)return t({error:"Select a project",isLoading:!1}),null;const p=d.path,u=await nh(p)&&e.isolateRuns!==!1,f=Cd(n),b=u?await oo(p):void 0,h=u?await Ky(p):null,v=[],x=c?.filter(S=>S.trim().length>0)??[],g=new Map;for(const S of a){const D=`${S.providerID}:${S.modelID}`;g.set(D,(g.get(D)||0)+1)}const w=new Map;for(const S of a){const D=`${S.providerID}:${S.modelID}`,E=g.get(D)||1,P=(w.get(D)||0)+1;w.set(D,P);const C=rD(S.providerID,S.modelID),N=E>1?bf(f,`${C}/${P}`):bf(f,C);try{const T=E>1?`${f}/${S.providerID}/${S.modelID}/${P}`:`${f}/${S.providerID}/${S.modelID}`;if(!u){const B=await en.withDirectory(p,()=>en.createSession({title:T}));v.push({sessionId:B.id,worktreePath:p,providerID:S.providerID,modelID:S.modelID,variant:S.variant});continue}const M=await Hy(d,{preferredName:N,mode:"new",branchName:N,worktreeName:N,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:x},{resolvedRootTrackingRemote:h}),F={...M,createdFromBranch:b,kind:"standard"},_=await en.withDirectory(M.path,()=>en.createSession({title:T}));Lt.getState().setWorktreeMetadata(_.id,F),v.push({sessionId:_.id,worktreePath:M.path,providerID:S.providerID,modelID:S.modelID,variant:S.variant})}catch(T){console.warn("[MultiRun] Failed to create session:",T)}}const y=c?.filter(S=>S.trim().length>0)??[];y.length>0&&rh(d,y).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const k=v.map(S=>S.sessionId),A=v[0]?.sessionId??null;if(k.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const j=o?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{await Promise.allSettled(v.map(async S=>{try{await en.withDirectory(S.worktreePath,()=>en.sendMessage({id:S.sessionId,providerID:S.providerID,modelID:S.modelID,variant:S.variant,text:r,agent:i,files:j}))}catch(D){console.warn("[MultiRun] Failed to start run:",D)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:k,firstSessionId:A}}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"})),iD="oc:lastWorktreeSourceBranch";function Ug(t){const e=ot.c(30),{git:n}=On(),r=Rd(t),a=Ed(t),i=Fd(t),o=ch(t),c=Zs(uD),d=Zs(dD);let p,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==a||e[4]!==i?(p=()=>{!t||!n||a!==null||i||d(t,n,{silent:!0})},m=[t,n,d,a,i],e[0]=t,e[1]=d,e[2]=n,e[3]=a,e[4]=i,e[5]=p,e[6]=m):(p=e[5],m=e[6]),l.useEffect(p,m);let u;e[7]!==r?.all||e[8]!==t||e[9]!==c||e[10]!==n||e[11]!==a?(u=()=>{!t||!n||a===!0&&(r?.all||c(t,n))},e[7]=r?.all,e[8]=t,e[9]=c,e[10]=n,e[11]=a,e[12]=u):u=e[12];const f=r?.all;let b;e[13]!==t||e[14]!==c||e[15]!==n||e[16]!==a||e[17]!==f?(b=[t,n,a,f,c],e[13]=t,e[14]=c,e[15]=n,e[16]=a,e[17]=f,e[18]=b):b=e[18],l.useEffect(u,b);const h=i||a===!0&&o;let v;e:{if(!r?.all){let S;e[19]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[19]=S):S=e[19],v=S;break e}let j;e[20]!==r.all?(j=r.all.filter(cD).sort(),e[20]=r.all,e[21]=j):j=e[21],v=j}const x=v;let g;e:{if(!r?.all){let S;e[22]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[22]=S):S=e[22],g=S;break e}let j;e[23]!==r.all?(j=r.all.filter(lD).map(oD).sort(),e[23]=r.all,e[24]=j):j=e[24],g=j}const w=g;let y;e:{if(!t){y=null;break e}if(a!==null){y=a;break e}if(h){y=null;break e}y=r?.all?!0:null}const k=y;let A;return e[25]!==k||e[26]!==h||e[27]!==x||e[28]!==w?(A={localBranches:x,remoteBranches:w,isLoading:h,isGitRepository:k},e[25]=k,e[26]=h,e[27]=x,e[28]=w,e[29]=A):A=e[29],A}function oD(t){return t.replace(/^remotes\//,"")}function lD(t){return t.startsWith("remotes/")}function cD(t){return!t.startsWith("remotes/")}function dD(t){return t.fetchStatus}function uD(t){return t.fetchBranches}const mD=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:o}=pt(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=Ug(t),u=l.useMemo(()=>[...c,...d.map(b=>`remotes/${b}`)],[c,d]);l.useEffect(()=>{if(a||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const h=t?await oo(t).catch(()=>null):null,v=localStorage.getItem(iD);v&&u.includes(v)?n(v):h&&u.includes(h)?n(h):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,a,p,n,e]);const f=a||!m||p;return s.jsxs("div",{children:[s.jsxs(is,{value:e,onValueChange:n,disabled:f,children:[s.jsx(os,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(us,{placeholder:o(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(ls,{className:"max-h-[280px] max-w-[320px]",children:p?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("multiRun.branchSelector.status.loadingBranches")}):c.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[c.length>0&&s.jsxs(Qc,{children:[s.jsx($u,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.localBranches")}),c.map(b=>s.jsx(Ft,{value:b,className:"whitespace-normal break-all",children:b},b))]}),c.length>0&&d.length>0&&s.jsx(Gy,{}),d.length>0&&s.jsxs(Qc,{children:[s.jsx($u,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(Ft,{value:`remotes/${b}`,className:"whitespace-normal break-all",children:b},`remotes/${b}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:o("multiRun.branchSelector.status.notInGitRepository")})]})},pD=10*1024*1024,Vc=5,Bo=t=>{const e=ot.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let a;return e[1]!==n?(a=s.jsxs(St,{children:[r,s.jsx(Ct,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=a):a=e[2],a},Ja=t=>{const e=ot.c(9),{htmlFor:n,required:r,children:a,info:i}=t;let o;e[0]!==r?(o=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=o):o=e[1];let c;e[2]!==a||e[3]!==n||e[4]!==o?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,o]}),e[2]=a,e[3]=n,e[4]=o,e[5]=c):c=e[5];const d=i&&i;let p;return e[6]!==c||e[7]!==d?(p=s.jsxs("div",{className:"flex items-center gap-1.5",children:[c,d]}),e[6]=c,e[7]=d,e[8]=p):p=e[8],p},fD=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=pt(),[i,o]=l.useState(""),[c,d]=l.useState(()=>t??""),[p,m]=l.useState([]),[u,f]=l.useState(""),[b,h]=l.useState([]),[v,x]=l.useState(!1),[g,w]=l.useState([]),[y,k]=l.useState(!1),[A,j]=l.useState(!1),[S,D]=l.useState(!0),[E,P]=l.useState(!1),[C,N]=l.useState(""),[T,M]=l.useState(!1),[F,_]=l.useState(""),B=l.useRef(null),V=l.useRef(null),$=l.useRef(null),z=l.useRef(null),Q=_s(Oe=>Oe.currentDirectory??null),L=_s(Oe=>Oe.homeDirectory??null),J=l.useMemo(()=>{if(typeof window>"u")return null;const Oe=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Oe=="string"&&Oe.trim().length>0?Oe.trim():null},[]),ee=Ts(Oe=>Oe.activeProjectId),re=Ts(Oe=>Oe.setActiveProjectIdOnly),q=Ts(Oe=>Oe.projects),[ce,ae]=l.useState(()=>ee??null);l.useEffect(()=>{if(ee){ae(ee);return}!ce&&q.length>0&&ae(q[0].id)},[ee,q,ce]);const R=l.useMemo(()=>ce?q.find(Oe=>Oe.id===ce)??null:null,[q,ce]),U=R?.path??Q,W=l.useCallback(Oe=>{ae(Oe),Oe!==ee&&re(Oe)},[ee,re]),{currentTheme:Z}=Sr(),K=l.useCallback(Oe=>{const Ye=Oe.label?.trim()||Fa(Oe.path,L),Ge=co({id:Oe.id,iconImage:Oe.iconImage??null},{themeVariant:Z.metadata.variant,iconColor:Z.colors.surface.foreground}),it=Oe.icon?Rl[Oe.icon]:null,Qe=Oe.color?uo[Oe.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[Ge?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Oe.iconBackground?{backgroundColor:Oe.iconBackground}:void 0,children:s.jsx("img",{src:Ge,alt:"",className:"h-full w-full object-contain",draggable:!1})}):it?s.jsx(I,{name:it,className:"h-3.5 w-3.5 shrink-0",style:Qe?{color:Qe}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Qe?{color:Qe}:void 0}),s.jsx("span",{className:"truncate",children:Ye})]})},[L,Z.metadata.variant,Z.colors.surface.foreground]),ie=l.useMemo(()=>{if(R?.path)return{id:R.id,path:R.path};const Oe=Q??J;return Oe?{id:`path:${Oe}`,path:Oe}:null},[R,Q,J]),[Ne,ne]=l.useState(()=>typeof window>"u"?!1:dn()),fe=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),pe=Cl();l.useEffect(()=>{typeof window>"u"||ne(dn())},[]);const je=l.useMemo(()=>{if(typeof window>"u")return null;const Oe=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Oe=="number"&&Number.isFinite(Oe)&&Oe>0)return Oe;if(typeof navigator>"u")return null;const Ye=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Ye)return null;const Ge=Number.parseInt(Ye[1],10),it=Number.parseInt(Ye[2],10);return Number.isNaN(Ge)?null:Ge===10?it:Ge},[]),oe=l.useMemo(()=>Ne&&fe||pe?"pl-[5.5rem]":"pl-3",[Ne,fe,pe]),Se=l.useMemo(()=>!Ne||!fe||je===null?"":je>=26?"h-12":je<=15?"h-14":"",[Ne,fe,je]),se=l.useCallback(async Oe=>{Oe.target.closest("button, a, input, select, textarea")||Oe.button===0&&Ne&&await fh()},[Ne]);l.useEffect(()=>{if(!n)return;const Oe=Ye=>{Ye.key==="Escape"&&(Ye.preventDefault(),Ye.stopPropagation(),n())};return window.addEventListener("keydown",Oe,!0),()=>window.removeEventListener("keydown",Oe,!0)},[n]);const[we,Ae]=l.useState(""),{isLoading:ve,isGitRepository:ye}=Ug(U),Ie=l.useRef(!1),he=ye===!0,me=he&&S;l.useEffect(()=>{if(ye===!1){Ie.current=!0,D(!1);return}ye===!0&&Ie.current&&(Ie.current=!1,D(!0))},[ye]);const Ee=zc(Oe=>Oe.createMultiRun),Ve=zc(Oe=>Oe.error),Y=zc(Oe=>Oe.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Oe=>Oe.trim().length>0?Oe:t)},[t]),l.useEffect(()=>{if(!ie)return;let Oe=!1;return j(!0),(async()=>{try{const Ye=await zd(ie);Oe||w(Ye)}catch{}finally{Oe||j(!1)}})(),()=>{Oe=!0}},[ie]);const ke=Oe=>{p.length>=Vc||(m(Ye=>[...Ye,Oe]),Y())},Be=Oe=>{m(Ye=>Ye.filter((Ge,it)=>it!==Oe)),Y()},Ce=l.useCallback((Oe,Ye)=>{m(Ge=>Ge.map((it,Qe)=>Qe===Oe?Ye:it))},[]),ge=async Oe=>{const Ye=Oe.target.files;if(!Ye)return;let Ge=0;for(let it=0;it<Ye.length;it++){const Qe=Ye[it];if(Qe.size>pD){H.error(a("multirun.launcher.toast.fileTooLarge",{fileName:Qe.name}));continue}try{const at=await new Promise((be,He)=>{const _e=new FileReader;_e.onload=()=>be(_e.result),_e.onerror=He,_e.readAsDataURL(Qe)}),nt={id:wl(),filename:Qe.name,mimeType:Qe.type||"application/octet-stream",size:Qe.size,dataUrl:at};h(be=>[...be,nt]),Ge++}catch(at){console.error("File attach failed",at),H.error(a("multirun.launcher.toast.attachFailed",{fileName:Qe.name}))}}Ge>0&&H.success(Ge===1?a("multirun.launcher.toast.attachedSingle",{count:Ge}):a("multirun.launcher.toast.attachedPlural",{count:Ge})),B.current&&(B.current.value="")},O=Oe=>{h(Ye=>Ye.filter(Ge=>Ge.id!==Oe))},X=l.useCallback((Oe,Ye)=>{if(Oe.startsWith("/")){const Qe=Oe.indexOf(" "),at=Oe.indexOf(`
|
|
223
|
-
`),nt=Math.min(Qe===-1?Oe.length:Qe,at===-1?Oe.length:at);if(Ye<=nt&&Qe===-1){_(Oe.substring(1,nt)),M(!0),P(!1);return}}M(!1);const Ge=Oe.substring(0,Ye),it=Ge.lastIndexOf("@");if(it!==-1){const Qe=it>0?Ge[it-1]:null,at=Ge.substring(it+1);(!Qe||/\s/.test(Qe))&&!at.includes(" ")&&!at.includes(`
|
|
224
|
-
`)?(N(at),P(!0)):P(!1);return}P(!1)},[]),G=l.useCallback(Oe=>{if(T&&z.current&&(Oe.key==="Enter"||Oe.key==="ArrowUp"||Oe.key==="ArrowDown"||Oe.key==="Escape"||Oe.key==="Tab")){Oe.preventDefault(),z.current.handleKeyDown(Oe.key);return}E&&$.current&&(Oe.key==="Enter"||Oe.key==="ArrowUp"||Oe.key==="ArrowDown"||Oe.key==="Escape"||Oe.key==="Tab")&&(Oe.preventDefault(),$.current.handleKeyDown(Oe.key))},[T,E]),Te=l.useCallback(Oe=>{const Ge=V.current?.selectionStart??c.length,Qe=c.substring(0,Ge).lastIndexOf("@"),at=Oe.relativePath&&Oe.relativePath.trim().length>0?Oe.relativePath.trim():Oe.path||Oe.name,nt=Qe!==-1?Qe:Ge,be=`${c.substring(0,nt)}@${at} ${c.substring(Ge)}`,He=nt+at.length+2;d(be),P(!1),N(""),requestAnimationFrame(()=>{const _e=V.current;_e&&(_e.selectionStart=He,_e.selectionEnd=He,_e.focus()),X(be,He)})},[c,X]),le=l.useCallback(Oe=>{const Ge=V.current?.selectionStart??c.length,Qe=c.substring(0,Ge).lastIndexOf("@"),at=Qe!==-1?Qe:Ge,nt=`${c.substring(0,at)}@${Oe} ${c.substring(Ge)}`,be=at+Oe.length+2;d(nt),P(!1),N(""),requestAnimationFrame(()=>{const He=V.current;He&&(He.selectionStart=be,He.selectionEnd=be,He.focus()),X(nt,be)})},[c,X]),We=l.useCallback(Oe=>{const Ye=`/${Oe.name} `;d(Ye),M(!1),_(""),requestAnimationFrame(()=>{const Ge=V.current;Ge&&(Ge.focus(),Ge.selectionStart=Ge.value.length,Ge.selectionEnd=Ge.value.length),X(Ye,Ye.length)})},[X]),de=async Oe=>{if(Oe.preventDefault(),!!c.trim()&&!(p.length<2)){x(!0),Y();try{ce&&ce!==ee&&re(ce);const Ye=p.map(({instanceId:nt,...be})=>be),Ge=b.map(nt=>({mime:nt.mimeType,filename:nt.filename,url:nt.dataUrl})),it=g.filter(nt=>nt.trim().length>0),Qe={name:i.trim(),prompt:c.trim(),models:Ye,agent:u||void 0,worktreeBaseBranch:me?we:void 0,isolateRuns:me,files:Ge.length>0?Ge:void 0,setupCommands:it.length>0?it:void 0},at=await Ee(Qe);at&&(at.firstSessionId&&Lt.getState().setCurrentSession(at.firstSessionId),e?.())}finally{x(!1)}}},Fe=!!(i.trim()&&c.trim()&&p.length>=2&&U&&!ve&&(ye===!1||!me||we)),rt=g.filter(Oe=>Oe.trim()).length;return s.jsxs("form",{onSubmit:de,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:se,className:ue("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",oe,Se),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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":a("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})}),s.jsx(Ct,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(io,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ja,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),q.length>0?s.jsxs(is,{value:ce??void 0,onValueChange:W,children:[s.jsx(os,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:R?s.jsx(us,{children:K(R)}):s.jsx(us,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(ls,{fitContent:!0,children:q.map(Oe=>s.jsx(Ft,{value:Oe.id,className:"max-w-[24rem]",children:K(Oe)},Oe.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(Ja,{htmlFor:"group-name",required:!0,info:s.jsx(Bo,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(Vt,{id:"group-name",value:i,onChange:Oe=>o(Oe.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(Ja,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Bo,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(mD,{directory:U,value:we,onChange:Ae,disabled:!me,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(ds,{checked:S,onChange:D,disabled:!he,ariaLabel:a("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:a("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ja,{htmlFor:"multirun-agent",info:s.jsx(Bo,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(Fg,{value:u,onChange:f,id:"multirun-agent"})]})]}),s.jsxs(pr,{open:y,onOpenChange:k,children:[s.jsxs(Nr,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(I,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:a("multirun.launcher.setupCommands.label")}),rt>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:rt}),s.jsx(I,{name:"arrow-down-s",className:ue("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",y&&"rotate-180")})]}),s.jsx(fr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:A?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[g.map((Oe,Ye)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Vt,{value:Oe,onChange:Ge=>{const it=[...g];it[Ye]=Ge.target.value,w(it)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const Ge=g.filter((it,Qe)=>Qe!==Ye);w(Ge)},className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":a("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]},`${Oe}-${Ye}`)),s.jsxs("button",{type:"button",onClick:()=>w([...g,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(I,{name:"add",className:"h-3 w-3"}),a("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ja,{htmlFor:"prompt",required:!0,children:a("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(fn,{id:"prompt",ref:V,value:c,onChange:Oe=>{const Ye=Oe.target.value;d(Ye);const Ge=Oe.target.selectionStart??Ye.length;X(Ye,Ge)},onKeyDown:G,placeholder:a("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),T?s.jsx(dh,{ref:z,searchQuery:F,onCommandSelect:We,onClose:()=>M(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,E?s.jsx(uh,{ref:$,searchQuery:C,onFileSelect:Te,onAgentSelect:le,onClose:()=>P(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:B,type:"file",multiple:!0,className:"hidden",onChange:ge,accept:"*/*"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>B.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(I,{name:"attachment-2",className:"h-3 w-3"}),a("multirun.launcher.attachments.attach")]})}),s.jsx(Ct,{children:a("multirun.launcher.attachments.tooltip")})]}),b.map(Oe=>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:[Oe.mimeType.startsWith("image/")?s.jsx(I,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(I,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Oe.filename,children:Oe.filename}),s.jsx("button",{type:"button",onClick:()=>O(Oe.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(I,{name:"close",className:"h-3 w-3"})})]},Oe.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ja,{required:!0,info:s.jsx(Bo,{children:a("multirun.launcher.models.info",{max:Vc})}),children:a("multirun.launcher.models.label")}),s.jsx(Lg,{selectedModels:p,onAdd:ke,onRemove:Be,onUpdate:Ce,minModels:2,maxModels:Vc})]}),Ve&&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:Ve})]})})}),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:[!me&&ye!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(I,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:a("multirun.launcher.project.gitRequired")})]}):null,s.jsx(xe,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(xe,{type:"submit",size:"sm",disabled:!Fe||v,children:v?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithModelCount",{count:p.length})})})]})})]})},yf=()=>{if(typeof window>"u")return{height:0,keyboardHeight:0};const t=window.visualViewport?.height??window.innerHeight,e=window.visualViewport?Math.max(0,window.innerHeight-t):0;return{height:t,keyboardHeight:e}},hD=()=>{const t=ot.c(2),[e,n]=l.useState(yf),r=l.useRef(null);let a,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{if(typeof window>"u")return;const o=window.visualViewport,c=()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null;const d=yf();n(p=>p.height===d.height&&p.keyboardHeight===d.keyboardHeight?p:d)}))};return o?(o.addEventListener("resize",c),o.addEventListener("scroll",c,{passive:!0})):window.addEventListener("resize",c),c(),()=>{r.current!==null&&cancelAnimationFrame(r.current),o?(o.removeEventListener("resize",c),o.removeEventListener("scroll",c)):window.removeEventListener("resize",c)}},i=[],t[0]=a,t[1]=i):(a=t[0],i=t[1]),l.useEffect(a,i),e};class gD extends l.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(hh,{className:"w-full max-w-md",children:[s.jsx(qy,{className:"text-center",children:s.jsxs(Yy,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(I,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Jy,{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(xe,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(I,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function xD(t){const e=ot.c(22),{t:n}=pt();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let a;e[2]!==n?(a=n("chat.errorBoundary.description"),e[2]=n,e[3]=a):a=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let p;e[12]!==r||e[13]!==a||e[14]!==i||e[15]!==o||e[16]!==c||e[17]!==d?(p={title:r,description:a,sessionLabel:i,detailsSummary:o,resetAction:c,persistentHint:d},e[12]=r,e[13]=a,e[14]=i,e[15]=o,e[16]=c,e[17]=d,e[18]=p):p=e[18];let m;return e[19]!==t||e[20]!==p?(m=s.jsx(gD,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const Id=t=>{const e=ot.c(5),{readOnly:n}=t,r=n===void 0?!1:n,i=Lt(bD)||void 0;let o;e[0]!==r?(o=s.jsx(Qy,{readOnly:r}),e[0]=r,e[1]=o):o=e[1];let c;return e[2]!==i||e[3]!==o?(c=s.jsx(xD,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=c):c=e[4],c};function bD(t){return t.currentSessionId}const yD=Yr(()=>jr(()=>Promise.resolve().then(()=>W2),void 0).then(t=>({default:t.PlanView}))),vf=Yr(()=>jr(()=>Promise.resolve().then(()=>Z0),void 0).then(t=>({default:t.GitView}))),vD=Yr(()=>jr(()=>Promise.resolve().then(()=>u2),void 0).then(t=>({default:t.DiffView}))),wf=Yr(()=>jr(()=>import("./TerminalView-K9P6-TDg.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),wD=Yr(()=>jr(()=>Promise.resolve().then(()=>$2),void 0).then(t=>({default:t.FilesView}))),jD=Yr(()=>jr(()=>Promise.resolve().then(()=>r4),void 0).then(t=>({default:t.SettingsView}))),ND=Yr(()=>jr(()=>import("./SettingsWindow-Cju1ws5b.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),SD=Yr(()=>jr(()=>import("./MultiRunWindow-BBmUkZot.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),_o=85,kD=250,CD=500,ID=400,PD=860,AD=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},DD=()=>{const{t}=pt(),e=1140,n=1220,r=640,a=700,i=De(R=>R.isSidebarOpen),o=De(R=>R.isRightSidebarOpen),c=De(R=>R.isBottomTerminalOpen),d=De(R=>R.setRightSidebarOpen),p=De(R=>R.setBottomTerminalOpen),m=De(R=>R.activeMainTab),u=De(R=>R.setIsMobile),f=De(R=>R.isSessionSwitcherOpen),b=De(R=>R.isSettingsDialogOpen),h=De(R=>R.setSettingsDialogOpen),v=De(R=>R.isMultiRunLauncherOpen),x=De(R=>R.setMultiRunLauncherOpen),g=De(R=>R.multiRunLauncherPrefillPrompt),{isMobile:w,isTablet:y}=nn(),k=hD(),A=l.useMemo(()=>dn(),[]),j=De(R=>R.sidebarWidth),S=De(R=>R.rightSidebarWidth),[D,E]=l.useState(null),P=Lr()??"",C=l.useMemo(()=>AD(P),[P]),N=De(R=>{if(!C)return!1;const U=R.contextPanelByDirectory[C],W=U?.tabs??[],Z=W.find(K=>K.id===U?.activeTabId)??W[W.length-1];return!!(U?.isOpen&&Z)}),T=De(R=>R.setSidebarOpen),M=l.useRef(!1),F=l.useRef(!1),_=l.useRef(!1),[B,V]=l.useState(!1),$=l.useRef(!1),z=pu(0),Q=$e.useRef(0),L=pu(0),J=$e.useRef(0);$e.useEffect(()=>{w&&(Q.current=window.innerWidth*(_o/100),J.current=window.innerWidth*(_o/100))},[w]),$e.useEffect(()=>{if(!w)return;const R=B?0:-Q.current;fu(z,R,{type:"spring",stiffness:400,damping:35,mass:.8})},[B,w,z]),$e.useEffect(()=>{if(!w)return;$.current=o;const R=o?0:J.current;fu(L,R,{type:"spring",stiffness:400,damping:35,mass:.8})},[w,o,L]),$e.useEffect(()=>{w&&V(f)},[f,w]),$e.useEffect(()=>{!w||!b||(V(!1),f&&De.getState().setSessionSwitcherOpen(!1),o&&d(!1))},[w,b,f,o,d]),$e.useEffect(()=>{w&&($.current=o)},[o,w]);const ee=Da(R=>R.checkForUpdates);l.useEffect(()=>{let K=!1,ie=null;const Ne=fe=>{const pe=Math.round(fe*1e3);return Math.max(3e5,Math.min(864e5,pe))},ne=fe=>{K||(ie=window.setTimeout(async()=>{const pe=await ee(),je=typeof pe=="number"&&Number.isFinite(pe)?Ne(pe):36e5;ne(je)},fe))};return ne(3e3),()=>{K=!0,ie!==null&&window.clearTimeout(ie)}},[ee]),l.useEffect(()=>{De.getState().isMobile!==w&&u(w)},[w,u]),l.useEffect(()=>{if(typeof window>"u")return;let R;const U=()=>{R!==void 0&&window.clearTimeout(R),R=window.setTimeout(()=>{De.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",U),()=>{window.removeEventListener("resize",U),R!==void 0&&window.clearTimeout(R)}},[]),l.useEffect(()=>{if(N){De.getState().isSidebarOpen&&(T(!1),_.current=!0);return}_.current&&(T(!0),_.current=!1)},[N,T]),l.useEffect(()=>{if(typeof window>"u")return;let R;const U=()=>{const Z=De.getState(),K=window.innerWidth,ie=window.innerHeight;if(!w&&!y){const Ne=K<e,ne=K>=n;Ne?Z.isRightSidebarOpen&&(d(!1),M.current=!0):ne&&M.current&&(d(!0),M.current=!1);const fe=ie<r,pe=ie>=a;fe?Z.isBottomTerminalOpen&&(p(!1),F.current=!0):pe&&F.current&&(p(!0),F.current=!1)}},W=()=>{R!==void 0&&window.clearTimeout(R),R=window.setTimeout(()=>{U()},100)};return U(),window.addEventListener("resize",W),()=>{window.removeEventListener("resize",W),R!==void 0&&window.clearTimeout(R)}},[w,y,p,d]),l.useEffect(()=>{if(typeof window>"u")return;const R=De.subscribe((U,W)=>{const Z=window.innerWidth,K=window.innerHeight,ie=Z>=n,Ne=K>=a;U.isRightSidebarOpen!==W.isRightSidebarOpen&&ie&&(M.current=!1),U.isBottomTerminalOpen!==W.isBottomTerminalOpen&&Ne&&(F.current=!1)});return()=>{R()}},[w,y,p,d]);const re=l.useMemo(()=>{switch(m){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(yD,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(vf,{})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(vD,{})});case"terminal":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(wf,{})});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(wD,{})});default:return null}},[m]),q=m==="chat",ce=l.useMemo(()=>Math.min(CD,Math.max(kD,j||nd)),[j]),ae=l.useMemo(()=>Math.min(PD,Math.max(ID,S||Th)),[S]);return s.jsx(Bj,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:ue("main-content-safe-area",w?"flex flex-col":"flex h-[100dvh]","bg-background"),style:w&&k.height>0?{height:k.height}:void 0,children:[s.jsx(a4,{}),s.jsx(H4,{}),s.jsx(J4,{}),s.jsx(nD,{}),w?s.jsxs(Xy,{value:{leftDrawerOpen:B,rightDrawerOpen:o,toggleLeftDrawer:()=>{o&&d(!1),V(!B)},toggleRightDrawer:()=>{B&&V(!1),d(!o)},leftDrawerX:z,rightDrawerX:L,leftDrawerWidth:Q,rightDrawerWidth:J,setMobileLeftDrawerOpen:V,setRightSidebarOpen:d},children:[!b&&s.jsx(rm,{onToggleLeftDrawer:()=>{o&&d(!1),V(!B)},onToggleRightDrawer:()=>{B&&V(!1),d(!o)},leftDrawerOpen:B,rightDrawerOpen:o}),s.jsx(Gl.button,{type:"button",initial:!1,animate:{opacity:B||o?1:0,pointerEvents:B||o?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{V(!1),d(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Gl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(Q.current||window.innerWidth*.85),right:0},style:{width:`${_o}%`,x:z},onDragEnd:(R,U)=>{const W=Q.current||window.innerWidth*.85,Z=W*.3,K=500,ie=z.get(),Ne=U.offset.x<-Z||U.velocity.x<-K,ne=U.offset.x>Z||U.velocity.x>K;Ne?(z.set(-W),V(!1)):ne?(z.set(0),V(!0)):ie>-W/2?z.set(0):z.set(-W)},className:ue("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":!B,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(Qs,{children:s.jsx(gf,{mobileVariant:!0})})})})}),s.jsx(Gl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:J.current||window.innerWidth*.85},style:{width:`${_o}%`,x:L},onDragEnd:(R,U)=>{const W=J.current||window.innerWidth*.85,Z=W*.3,K=500,ie=L.get(),Ne=U.offset.x>Z||U.velocity.x>K,ne=U.offset.x<-Z||U.velocity.x<-K;Ne?(L.set(W),d(!1)):ne?(L.set(0),d(!0)):ie<W/2?L.set(0):L.set(W)},className:ue("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!o,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area","data-page-scroll-lock":"true",children:s.jsx(Qs,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(vf,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:ue("flex flex-1 overflow-hidden relative",b&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ue("absolute inset-0",!q&&"invisible"),children:s.jsx(Qs,{children:s.jsx(Id,{})})}),re&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Qs,{children:re})}),v&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Qs,{children:s.jsx(fD,{initialPrompt:g,onCreated:()=>x(!1),onCancel:()=>x(!1)})})})]})}),b&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Qs,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(jD,{onClose:()=>h(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:ue("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:ue("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${ce}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:ue("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${ce}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}})]}):null,o?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:ue("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${ae}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:ue("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${ae}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(Xw,{isOpen:i,isMobile:w,className:"border-0",children:s.jsx(gf,{})}),s.jsxs("div",{className:ue("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",i&&"border-l border-border/50 rounded-tl-[10px] rounded-bl-[10px]",o&&"border-r border-border/50 rounded-tr-[10px] rounded-br-[10px]"),"data-page-scroll-lock":"true",children:[s.jsx(rm,{desktopRightSidebarActionsHost:D}),s.jsx("div",{className:ue("flex flex-1 min-h-0 overflow-hidden",i||q?"":"border-l border-border/50",o?"":"border-r border-border/50"),"data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ue("absolute inset-0",!q&&"invisible"),children:s.jsx(Qs,{children:s.jsx(Id,{})})}),re&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Qs,{children:re})})]}),s.jsx(DS,{})]})}),s.jsx(Gw,{isOpen:c,isMobile:w,children:c?s.jsx(Qs,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(wf,{})})}):null})]}),s.jsx(Zw,{isOpen:o,className:"border-0",onTopActionsHostChange:E,children:s.jsx(Qs,{children:s.jsx(EN,{})})})]})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(ND,{open:b,onOpenChange:h})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(SD,{open:v,onOpenChange:x,initialPrompt:g})})]})]})})},TD=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},dr=t=>{const e=ot.c(8),{label:n,value:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=a):a=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==i||e[6]!==o?(c=s.jsxs("div",{className:"rounded-md p-2",style:a,children:[i,o]}),e[5]=i,e[6]=o,e[7]=c):c=e[7],c},jf=t=>{const e=ot.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=pt();let o;if(e[0]!==a||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(RD,0),e[8]=r.entries,e[9]=d):d=e[9];const p=d;let m;e[10]!==n?(m=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=m):m=e[11];let u;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(u=r.startedAt?TD(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==m||e[19]!==f?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,f]}),e[18]=m,e[19]=f,e[20]=b):b=e[20];let h;e[21]!==i?(h=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=h):h=e[22];let v;e[23]!==r.entries.length||e[24]!==h?(v=s.jsx(dr,{label:h,value:r.entries.length}),e[23]=r.entries.length,e[24]=h,e[25]=v):v=e[25];let x;e[26]!==i?(x=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=x):x=e[27];let g;e[28]!==x||e[29]!==p?(g=s.jsx(dr,{label:x,value:p}),e[28]=x,e[29]=p,e[30]=g):g=e[30];let w;e[31]!==i?(w=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=w):w=e[32];let y;e[33]!==r.lastUpdatedAt||e[34]!==i?(y=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=y):y=e[35];let k;e[36]!==w||e[37]!==y?(k=s.jsx(dr,{label:w,value:y}),e[36]=w,e[37]=y,e[38]=k):k=e[38];let A;e[39]!==g||e[40]!==k||e[41]!==v?(A=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,g,k]}),e[39]=g,e[40]=k,e[41]=v,e[42]=A):A=e[42],o=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[b,A,c.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:a}):s.jsx(Ns,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=a,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=o}else o=e[7];return o},MD=t=>{const e=ot.c(101),{onClose:n}=t,{t:r}=pt(),[a,i]=l.useState("memory"),[o,c]=l.useState("idle"),d=Lt(FD),p=ph(OD),m=El(),u=th(LD),f=mr($D),[b,h]=l.useState(BD),[v,x]=l.useState(_D);let g;e[0]!==b.entries?(g=new Map,b.entries.forEach(Ae=>{g.set(Ae.metric,Ae.count)}),e[0]=b.entries,e[1]=g):g=e[1];let w;e[2]!==g?(w=g.get("ui.message_list.render")??0,e[2]=g,e[3]=w):w=e[3];let y;e[4]!==g?(y=g.get("ui.message_list.render.streaming")??0,e[4]=g,e[5]=y):y=e[5];let k;e[6]!==g?(k=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=k):k=e[7];let A;e[8]!==g?(A=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=A):A=e[9];let j;e[10]!==g?(j=g.get("ui.chat_message.render.static_during_stream")??0,e[10]=g,e[11]=j):j=e[11];let S;e[12]!==g?(S=g.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=g,e[13]=S):S=e[13];let D;e[14]!==w||e[15]!==y||e[16]!==k||e[17]!==A||e[18]!==j||e[19]!==S?(D={messageListRender:w,messageListRenderStreaming:y,chatMessageRender:k,chatMessageRenderStreaming:A,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:S},e[14]=w,e[15]=y,e[16]=k,e[17]=A,e[18]=j,e[19]=S,e[20]=D):D=e[20];const E=D;let P,C;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const Ae=()=>{h(Wo()),x(Ko())};Ae();const ve=window.setInterval(Ae,500);return()=>window.clearInterval(ve)},C=[],e[21]=P,e[22]=C):(P=e[21],C=e[22]),l.useEffect(P,C);let N,T;e[23]!==o?(N=()=>{if(o==="idle")return;const Ae=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Ae)},T=[o],e[23]=o,e[24]=N,e[25]=T):(N=e[24],T=e[25]),l.useEffect(N,T);let M=0,F;if(e[26]!==u?(F=Object.keys(u),e[26]=u,e[27]=F):F=e[27],e[28]!==u||e[29]!==F||e[30]!==M){for(const Ae of F)M=M+(u[Ae]?.length??0);e[28]=u,e[29]=F,e[30]=M,e[31]=M}else M=e[31];const _=M;let B;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Ae;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Ae=ve=>{const ye=u[ve.id]?.length||0,Ie=p.get(ve.id);return{id:ve.id,title:ve.title||r("memoryDebugPanel.common.untitled"),messageCount:ye,isStreaming:Ie?.isStreaming||!1,isZombie:Ie?.isZombie||!1,backgroundCount:Ie?.backgroundMessageCount||0,lastAccessed:Ie?.lastAccessedAt||0,isCurrent:ve.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=Ae):Ae=e[42],B=m.map(Ae).sort(zD),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=B}else B=e[37];const V=B;let $;e[43]!==u?($=Object.keys(u),e[43]=u,e[44]=$):$=e[44];const z=$.length;let Q;e[45]===Symbol.for("react.memo_cache_sentinel")?(Q=async()=>{try{const Ae={generatedAt:new Date().toISOString(),ui:Wo(),vscode:Ko()};await navigator.clipboard.writeText(JSON.stringify(Ae,null,2)),c("copied")}catch{c("error")}},e[45]=Q):Q=e[45];const L=Q;let J;e[46]===Symbol.for("react.memo_cache_sentinel")?(J={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=J):J=e[46];let ee;e[47]!==a?(ee=a==="memory"?s.jsx(I,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(I,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=ee):ee=e[48];let re;e[49]!==r?(re=r("memoryDebugPanel.title"),e[49]=r,e[50]=re):re=e[50];let q;e[51]!==re?(q=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:re}),e[51]=re,e[52]=q):q=e[52];let ce;e[53]!==ee||e[54]!==q?(ce=s.jsxs("div",{className:"flex items-center gap-2",children:[ee,q]}),e[53]=ee,e[54]=q,e[55]=ce):ce=e[55];let ae;e[56]!==a?(ae=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(xe,{size:"xs",variant:"ghost",onClick:L,children:s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(xe,{size:"xs",variant:"ghost",onClick:()=>{ev(),h(Wo()),x(Ko())},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=ae):ae=e[57];let R;e[58]!==n?(R=n?s.jsx(xe,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=R):R=e[59];let U;e[60]!==ae||e[61]!==R?(U=s.jsxs("div",{className:"flex items-center gap-1",children:[ae,R]}),e[60]=ae,e[61]=R,e[62]=U):U=e[62];let W;e[63]!==ce||e[64]!==U?(W=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[ce,U]}),e[63]=ce,e[64]=U,e[65]=W):W=e[65];let Z;e[66]===Symbol.for("react.memo_cache_sentinel")?(Z={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=Z):Z=e[66];const K=a==="memory"?"secondary":"ghost";let ie;e[67]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>i("memory"),e[67]=ie):ie=e[67];let Ne;e[68]!==r?(Ne=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=Ne):Ne=e[69];let ne;e[70]!==K||e[71]!==Ne?(ne=s.jsx(xe,{size:"sm",variant:K,className:"flex-1",onClick:ie,children:Ne}),e[70]=K,e[71]=Ne,e[72]=ne):ne=e[72];const fe=a==="streaming"?"secondary":"ghost";let pe;e[73]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>i("streaming"),e[73]=pe):pe=e[73];let je;e[74]!==r?(je=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=je):je=e[75];let oe;e[76]!==fe||e[77]!==je?(oe=s.jsx(xe,{size:"sm",variant:fe,className:"flex-1",onClick:pe,children:je}),e[76]=fe,e[77]=je,e[78]=oe):oe=e[78];let Se;e[79]!==ne||e[80]!==oe?(Se=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:Z,children:[ne,oe]}),e[79]=ne,e[80]=oe,e[81]=Se):Se=e[81];let se;e[82]!==a||e[83]!==z||e[84]!==o||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==V||e[89]!==m||e[90]!==E||e[91]!==b||e[92]!==r||e[93]!==f||e[94]!==_||e[95]!==v?(se=a==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(dr,{label:r("memoryDebugPanel.metric.totalMessages"),value:_}),s.jsx(dr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${z} / ${Bu.MAX_SESSIONS}`})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:Zy()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:Bu.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:f})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(Ns,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(Ae=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ae.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Ae.title}),Ae.isStreaming?s.jsx(I,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ae.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Ae.messageCount})}),Ae.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ae.backgroundCount]}):null]})]},Ae.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(xe,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(VD),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Ct,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(o==="copied"?"memoryDebugPanel.streaming.copy.copied":o==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(xe,{size:"xs",variant:"outline",onClick:L,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(dr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:E.messageListRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:E.messageListRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:E.chatMessageRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:E.chatMessageRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:E.chatMessageRenderStaticDuringStream}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:E.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(jf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(jf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=z,e[84]=o,e[85]=d,e[86]=u,e[87]=p,e[88]=V,e[89]=m,e[90]=E,e[91]=b,e[92]=r,e[93]=f,e[94]=_,e[95]=v,e[96]=se):se=e[96];let we;return e[97]!==W||e[98]!==Se||e[99]!==se?(we=s.jsxs(hh,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:J,children:[W,Se,se]}),e[97]=W,e[98]=Se,e[99]=se,e[100]=we):we=e[100],we},ED=MD;function RD(t,e){return t+e.count}function FD(t){return t.currentSessionId}function OD(t){return t.sessionMemoryState}function LD(t){return t.message}function $D(t){return t.totalRequestCount}function BD(){return Wo()}function _D(){return Ko()}function zD(t,e){return e.lastAccessed-t.lastAccessed}function VD(t){return{id:t.id,title:t.title}}const UD=()=>{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()??"":""},WD=async()=>{const t=UD()||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")},Nf="openchamber:menu-action",Uc="openchamber:check-for-updates",KD=t=>{const e=Lt(x=>x.openNewSessionDraft),n=De(x=>x.toggleCommandPalette),r=De(x=>x.setCommandPaletteOpen),a=De(x=>x.toggleHelpDialog),i=De(x=>x.toggleSidebar),o=De(x=>x.setSessionSwitcherOpen),c=De(x=>x.setActiveMainTab),d=De(x=>x.setSettingsDialogOpen),p=De(x=>x.setAboutDialogOpen),m=Da(x=>x.checkForUpdates),{setThemeMode:u}=Sr(),f=l.useRef(!1),b=l.useCallback(()=>{f.current||(f.current=!0,m().then(()=>{const{available:x,error:g}=Da.getState();if(g){H.error("Failed to check for updates",{description:g});return}x||H.success("You are on the latest version")}).finally(()=>{f.current=!1}))},[m]),h=l.useCallback(()=>{wr.requestDirectoryDialog()},[]),v=l.useCallback(x=>{switch(x){case"about":p(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),o(!1),e();break;case"new-worktree-session":c("chat"),o(!1),oh();break;case"change-workspace":h();break;case"open-git-tab":{const{activeMainTab:g}=De.getState();c(g==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:g}=De.getState();c(g==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:g}=De.getState();c(g==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:g}=De.getState();c(g==="terminal"?"chat":"terminal");break}case"copy":{const g=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(g)||WD();break}case"theme-light":u("light");break;case"theme-dark":u("dark");break;case"theme-system":u("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"help-dialog":a();break;case"download-logs":{tv().catch(()=>{H.error("Failed to collect OpenCode status")});break}}},[h,t,e,p,c,o,r,d,u,n,a,i]);l.useEffect(()=>{const x=w=>{const y=w.detail;y&&v(y)},g=()=>{b()};return window.addEventListener(Nf,x),window.addEventListener(Uc,g),()=>{window.removeEventListener(Nf,x),window.removeEventListener(Uc,g)}},[v,b]),l.useEffect(()=>{if(typeof window>"u")return;const g=window.__TAURI__?.event?.listen;if(typeof g!="function")return;let w=null,y=null;return g("openchamber:menu-action",k=>{const A=k?.payload;typeof A=="string"&&v(A)}).then(k=>{w=k}).catch(()=>{}),g("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Uc))}).then(k=>{y=k}).catch(()=>{}),()=>{(async()=>{try{const A=w?.();A instanceof Promise&&await A}catch{}try{const A=y?.();A instanceof Promise&&await A}catch{}})()}},[v])},HD=["chat","git","diff","terminal","files"],GD=["settings","agents","commands","skills","providers","usage","git-identities"],yr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Sf(t){const e=qD();return{sessionId:YD(e),tab:JD(e),settingsPath:QD(e),diffFile:XD(e)}}function qD(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function YD(t){const e=t.get(yr.SESSION);return!e||e.trim().length===0?null:e.trim()}function JD(t){const e=t.get(yr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return HD.includes(n)?n:null}function QD(t){const e=t.get(yr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(GD.includes(n),n)}function XD(t){const e=t.get(yr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function kf(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(yr.SESSION)||t.has(yr.TAB)||t.has(yr.SETTINGS)||t.has(yr.FILE)}catch{return!1}}const ZD="chat";function Wg(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(yr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(yr.SETTINGS,n),e}return t.tab!==ZD&&e.set(yr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(yr.FILE,t.diffFile),e}function e6(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function t6(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Wg(t),r=[...e.entries()].sort((i,o)=>i[0].localeCompare(o[0])),a=[...n.entries()].sort((i,o)=>i[0].localeCompare(o[0]));if(r.length!==a.length)return!1;for(let i=0;i<r.length;i++)if(r[i][0]!==a[i][0]||r[i][1]!==a[i][1])return!1;return!0}catch{return!0}}function s6(t,e={}){if(!(typeof window>"u")&&!n6()&&!(!e.force&&t6(t)))try{const n=Wg(t),r=e6(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function n6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function r6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function a6(){const t=l.useMemo(()=>r6(),[]),e=l.useRef(!1),n=l.useRef(!1),r=Lt(u=>u.setCurrentSession),a=De(u=>u.setActiveMainTab),i=De(u=>u.setSettingsDialogOpen),o=De(u=>u.setSettingsPage),c=De(u=>u.navigateToDiff),d=l.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const f=Lt.getState().currentSessionId;u.sessionId!==f&&await r(u.sessionId)}if(u.settingsPath){o(lg(u.settingsPath)),i(!0);return}De.getState().isSettingsDialogOpen&&i(!1),u.tab&&a(u.tab),u.diffFile&&(u.tab==="diff"||!u.tab)&&c(u.diffFile)}finally{n.current=!1}}},[r,a,i,o,c]),p=l.useCallback(()=>{const u=Lt.getState(),f=De.getState();return{sessionId:u.currentSessionId,tab:f.activeMainTab,isSettingsOpen:f.isSettingsDialogOpen,settingsPath:f.settingsPage,diffFile:f.pendingDiffFile}},[]),m=l.useCallback((u={})=>{if(t||n.current)return;const f=p();s6(f,u)},[t,p]);l.useEffect(()=>{if(e.current||(e.current=!0,!kf()))return;const u=Sf();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),l.useEffect(()=>{if(t)return;let u=Lt.getState().currentSessionId;return Lt.subscribe(b=>{const h=b.currentSessionId;h===u||n.current||(u=h,m())})},[t,m]),l.useEffect(()=>{if(t)return;let u=De.getState().activeMainTab,f=De.getState().isSettingsDialogOpen,b=De.getState().settingsPage,h=De.getState().pendingDiffFile;return De.subscribe(x=>{if(n.current)return;const g=x.activeMainTab!==u,w=x.isSettingsDialogOpen!==f,y=x.settingsPage!==b,k=x.pendingDiffFile!==h&&x.activeMainTab==="diff";u=x.activeMainTab,f=x.isSettingsDialogOpen,b=x.settingsPage,h=x.pendingDiffFile,(g||w||y||k)&&m()})},[t,m]),l.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const f=Sf();if(kf())d(f);else{const b=De.getState();b.isSettingsDialogOpen&&i(!1),b.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,a,i])}const i6="/api/notifications/stream",o6=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),l6=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},c6=t=>{const e=ot.c(3),n=t?.enabled??!0;let r,a;e[0]!==n?(r=()=>{if(!n||dn()||!Hr()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(i6);return i.onmessage=d6,()=>{i.close()}},a=[n],e[0]=n,e[1]=r,e[2]=a):(r=e[1],a=e[2]),l.useEffect(r,a)};function d6(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=De.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&o6())return;const r=l6(e);if(!r)return;sr()?.notifications?.notifyAgentCompletion(r)}const u6=t=>!(t.dismissed==="true"||t.sessionShown==="true"||t.hasActiveToast),m6=t=>!(!t.version||t.seenVersions.has(t.version)||t.dismissedVersion!==null&&t.dismissedVersion===t.version),p6=t=>{if(t===null||typeof t!="object")return"";const e=t.version;return typeof e!="string"?"":e.trim()},f6=t=>!t||t.available!==!0||typeof t.latestVersion!="string"?"":t.latestVersion.trim(),Cf="pwa-install-toast-shown",If="pwa-install-toast-dismissed",h6=()=>{const t=ot.c(6),{browserTab:e}=wg(),{t:n}=pt(),r=l.useRef(n);let a,i;t[0]!==n?(a=()=>{r.current=n},i=[n],t[0]=n,t[1]=a,t[2]=i):(a=t[1],i=t[2]),l.useEffect(a,i);let o,c;t[3]!==e?(o=()=>{if(typeof window>"u"||!Hr()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(H.dismiss(p),p=null)},u=async()=>{if(!d)return;const h=d;d=null,m(),await h.prompt();const{outcome:v}=await h.userChoice;v==="accepted"&&H.success(r.current("pwa.installPrompt.started"))},f=h=>{const v=h;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const x=br(),g=Vf();u6({dismissed:x.getItem(If),sessionShown:g.getItem(Cf),hasActiveToast:p!==null})&&(g.setItem(Cf,"true"),p=H.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{br().setItem(If,"true"),m()}}}))},b=()=>{d=null,m(),H.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",f),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",f),window.removeEventListener("appinstalled",b)}},c=[e],t[3]=e,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c)},g6=["local","remote",null],x6=["ok","not-configured","unreachable","wrong-service","missing"];function Kg(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!g6.includes(n)))return{valid:!1};if(typeof r!="string"||!x6.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 Pf(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 b6(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function y6(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function Af(){if(Pd()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=Kg(e);return n.valid?n.outcome:null}function Pd(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Kg(t).valid?"valid":"malformed"}const v6=()=>{const t=ot.c(5),[e,n]=l.useState(w6),{isUpdating:r,message:a}=e;let i,o;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>nv(n),o=[],t[0]=i,t[1]=o):(i=t[0],o=t[1]),l.useEffect(i,o),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Bd,{width:80,height:80}),t[2]=c):c=t[2];let d;return t[3]!==a?(d=s.jsxs("div",{className:"fixed inset-0 z-[9999] flex flex-col items-center justify-center gap-6 bg-background/90",children:[c,s.jsx("p",{className:"typography-body text-muted-foreground",children:a})]}),t[3]=a,t[4]=d):d=t[4],d};function w6(){return sv()}const j6=({open:t,onOpenChange:e})=>{const{t:n}=pt(),[r,a]=l.useState(null),[i,o]=l.useState(null),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState(!1),v=l.useCallback(async()=>{if(!c){d(!0),m(!1);try{if(!u){H.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const g=await _u.copyTextToClipboard(u);g.ok?(m(!0),H.success(n("aboutDialog.toast.diagnosticsCopied"))):H.error(n("aboutDialog.toast.copyFailed"),{description:g.error})}catch(g){H.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",g)}finally{d(!1)}}},[u,c,n]);l.useEffect(()=>{if(!t)return;(async()=>{try{const w=await fetch("/api/system/info");if(w.ok){const y=await w.json();if(typeof y.openchamberVersion=="string"&&y.openchamberVersion.trim()){a(y.openchamberVersion);return}}}catch{}a(await rv())})()},[t]),l.useEffect(()=>{if(!t)return;let g=!1;return(async()=>{try{const y=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!y.ok)return;const k=await y.json().catch(()=>null),A=typeof k?.currentVersion=="string"?k.currentVersion.trim():"";!g&&A&&o(A)}catch{}})(),()=>{g=!0}},[t]),l.useEffect(()=>{if(!t){f(null),h(!1);return}let g=!1;return h(!0),_u.buildDiagnosticsReport().then(w=>{g||f(w)}).catch(w=>{g||(console.error("Failed to prepare diagnostics:",w),f(null))}).finally(()=>{g||h(!1)}),()=>{g=!0}},[t]);const x=r;return s.jsx(ps,{open:t,onOpenChange:e,children:s.jsx(ms,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(Bd,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[x&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:x})}),i&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:i})})]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:v,disabled:c||b||!u,className:ue("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(p?"aboutDialog.actions.diagnosticsCopied":b?"aboutDialog.actions.preparingDiagnostics":"aboutDialog.actions.copyDiagnostics")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("aboutDialog.diagnosticsDescription")})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},Wc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},N6=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to OpenChamber and click Authorize again.":n},S6=()=>{const t=gn(i=>i.completeAuth),[e,n]=l.useState("working"),[r,a]=l.useState("Completing MCP authorization...");return l.useEffect(()=>{if(typeof window>"u"){n("error"),a("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),o=Wc(i,"code"),c=pg(i),d=eu(i),p=Wc(i,"error"),m=Wc(i,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(m??p);return}(async()=>{try{if(!o)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let u=c;if(!u&&d){const f=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(f.ok){const b=await f.json().catch(()=>null);b?.name?.trim()&&(u={name:b.name.trim(),directory:typeof b.directory=="string"&&b.directory.trim()?b.directory.trim():null})}}if(!u?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(u.name,o,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),a("Authorization completed. You can close this tab and return to OpenChamber.")}catch(u){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(N6(u,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(xe,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},Ri="opencode-update-available",zo="opencode-upgrade-progress",k6=5e3,C6=[1e4,6e4],Df="opencode-update-toast-dismissed-version",Hg=()=>{const{t}=pt(),e=De(o=>o.showOpenCodeUpdateNotifications),n=$e.useRef(new Set),r=$e.useRef(!1);$e.useEffect(()=>{e||H.dismiss(Ri)},[e]);const a=$e.useCallback(()=>{H.dismiss(zo),ai({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=$e.useCallback(async()=>{if(!r.current){r.current=!0,H.dismiss(Ri),H.message(t("opencodeUpdate.toast.upgrading.title"),{id:zo,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(I,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const o=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),c=await o.json().catch(()=>null);if(!o.ok||c?.success===!1)throw new Error(c?.error||o.statusText||t("opencodeUpdate.toast.failed.description"));H.success(t("opencodeUpdate.toast.updated.title"),{id:zo,description:c?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:c.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(I,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:a}})}catch(o){H.error(t("opencodeUpdate.toast.failed.title"),{id:zo,description:o instanceof Error?o.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[a,t]);return $e.useEffect(()=>{const o=u=>{if(!De.getState().showOpenCodeUpdateNotifications){H.dismiss(Ri);return}m6({version:u,dismissedVersion:br().getItem(Df),seenVersions:n.current})&&(n.current.add(u),H.info(t("opencodeUpdate.toast.available.title"),{id:Ri,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:t("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{br().setItem(Df,u),H.dismiss(Ri)}}}))},c=u=>{const f=p6(u.detail);o(f)};let d=!1;const p=[],m=async u=>{try{const f=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!f.ok)throw new Error(f.statusText||"OpenCode upgrade status check failed");const b=await f.json().catch(()=>null),h=f6(b);!d&&h&&o(h)}catch{const f=C6[u];!d&&f!==void 0&&p.push(setTimeout(()=>{m(u+1)},f))}};return e&&p.push(setTimeout(()=>{m(0)},k6)),window.addEventListener("openchamber:opencode-update-available",c),()=>{d=!0;for(const u of p)clearTimeout(u);window.removeEventListener("openchamber:opencode-update-available",c)}},[i,e,t]),null},Tf=Yr(()=>jr(()=>import("./OnboardingScreen-CmfCd-NF.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),I6=()=>{const t=ot.c(3),e=De(E6),n=De(R6);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(j6,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},P6=t=>{const e=ot.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=pt();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==i?(o=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=o):o=e[3];let c;e[4]!==a?(c=a("startup.initRecovery.description"),e[4]=a,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==o||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[o,d]}),e[8]=o,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==a?(m=a(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=a,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(xe,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let f;return e[18]!==p||e[19]!==u?(f=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[p,u]})}),e[18]=p,e[19]=u,e[20]=f):f=e[20],f},Mf=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",A6=()=>{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"}},D6=()=>typeof window>"u"?!1:window.location.pathname===mg,T6=t=>{const e=ot.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:a}=t,i=_s(F6),o=Lt(O6),c=Lt(L6),d=Ud(),p=l.useRef(null);let m;e[0]!==n.directory?(m=Mf(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let f;e[2]!==i?(f=Mf(i),e[2]=i,e[3]=f):f=e[3];const b=f;let h,v;if(e[4]!==b||e[5]!==o||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==c||e[11]!==d?(h=()=>{if(r||u&&b!==u)return;const A=`${u}
|
|
225
|
-
${n.sessionId}`;p.current===A&&o===n.sessionId||(p.current=A,c(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},v=[b,o,n.directory,n.sessionId,u,r,c,d],e[4]=b,e[5]=o,e[6]=n.directory,e[7]=n.sessionId,e[8]=u,e[9]=r,e[10]=c,e[11]=d,e[12]=h,e[13]=v):(h=e[12],v=e[13]),l.useEffect(h,v),u&&b!==u)return null;let x;e[14]!==a?(x=s.jsx(gh,{embeddedBackgroundWorkEnabled:a}),e[14]=a,e[15]=x):x=e[15];let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Hg,{}),e[16]=g):g=e[16];let w;e[17]!==n.readOnly?(w=s.jsx(Id,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=w):w=e[18];let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(xh,{}),e[19]=y):y=e[19];let k;return e[20]!==x||e[21]!==w?(k=s.jsxs(s.Fragment,{children:[x,g,w,y]}),e[20]=x,e[21]=w,e[22]=k):k=e[22],k};function M6({apis:t}){const e=vt(R=>R.initializeApp),n=vt(R=>R.isInitialized),r=vt(R=>R.isConnected),a=vt(R=>R.providers.length),i=vt(R=>R.agents.length),o=vt(R=>R.loadProviders),c=vt(R=>R.loadAgents),d=Lt(R=>R.error),p=Lt(R=>R.clearError),m=_s(R=>R.currentDirectory),u=_s(R=>R.setDirectory),f=_s(R=>R.isSwitchingDirectory),[b,h]=l.useState(!1),v=zn(R=>R.refreshStatus),[x,g]=l.useState(()=>t.runtime.isVSCode),[w,y]=l.useState(!0),[k,A]=l.useState(!1),[j,S]=l.useState(0),[D,E]=l.useState(!1),P=De(R=>R.wideChatLayoutEnabled),C=De(R=>R.mobileKeyboardMode),N=l.useMemo(()=>dn(),[]),T=Td(R=>R.setPlanModeEnabled),[M,F]=l.useState(()=>Pd()),[_,B]=l.useState(()=>{const R=Af();return R!==null?Pf({isDesktopShell:!0,bootOutcome:R}):null}),V=l.useRef(!1),$=l.useMemo(()=>A6(),[]),z=!$||w,Q=l.useMemo(()=>D6(),[]);l.useEffect(()=>(zu(b),()=>{zu(!1)}),[b]),l.useEffect(()=>{av(C)},[C]),l.useEffect(()=>{g(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",P),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[P]),l.useEffect(()=>(Vu(t),()=>Vu(null)),[t]),l.useEffect(()=>{$||v(t.github,{force:!0})},[t.github,$,v]),iv();const L=M==="valid",J=_?.screen==="main";l.useEffect(()=>{if(!b6({isDesktopShell:N,isInitialized:n,bootOutcomeKnown:L,bootViewIsMain:J}))return;const R=setTimeout(()=>{const U=document.getElementById("initial-loading");U&&(U.classList.add("fade-out"),setTimeout(()=>{U.remove()},300))},150);return()=>clearTimeout(R)},[N,n,L,J]),l.useEffect(()=>{if(!N||M!=="malformed")return;const R=document.getElementById("initial-loading");R&&(R.textContent="Desktop startup failed — please restart the app.")},[N,M]),l.useEffect(()=>{if(N)return;const R=setTimeout(()=>{const U=document.getElementById("initial-loading");U&&!n&&(U.classList.add("fade-out"),setTimeout(()=>{U.remove()},300))},5e3);return()=>clearTimeout(R)},[N,n]),l.useEffect(()=>{let R=!1;return(async()=>{const W=await fetch("/health",{method:"GET"}).catch(()=>null);if(!W||!W.ok||R)return;const Z=await W.json().catch(()=>null);if(!Z||R)return;const K=Z.planModeExperimentalEnabled;T(K===!0||K===1||K==="1"||K==="true")})(),()=>{R=!0}},[T]),l.useEffect(()=>{x||e()},[e,x]),l.useEffect(()=>{if(x||n)return;let R=!0,U,W=0;const Z=10,K=1e3,ie=async()=>{if(!R)return;if(W>=Z){A(!0);return}const Ne=vt.getState();if(Ne.isInitialized){A(!1);return}W+=1,await Ne.initializeApp();const ne=vt.getState();if(!R)return;if(ne.isInitialized){A(!1);return}if(W>=Z){A(!0);return}const fe=Math.min(K*Math.pow(2,W-1),16e3);U=setTimeout(ie,fe)};return U=setTimeout(ie,K),()=>{R=!1,U&&clearTimeout(U)}},[j,n,x]),l.useEffect(()=>{n&&A(!1)},[n]),l.useEffect(()=>{if(!k)return;const R=document.getElementById("initial-loading");R&&(R.classList.add("fade-out"),setTimeout(()=>{R.remove()},300))},[k]),l.useEffect(()=>{if(x||!r||a>0&&i>0)return;let R=!0,U=0;const W=15,Z=async()=>{const ie=vt.getState();if(!(ie.providers.length>0&&ie.agents.length>0))try{ie.providers.length===0&&await o(),vt.getState().agents.length===0&&await c()}catch{}};Z();const K=setInterval(()=>{if(R){if(++U>=W){clearInterval(K);return}Z()}},2e3);return()=>{R=!1,clearInterval(K)}},[r,x,c,o,a,i]),l.useEffect(()=>{f||x||r&&en.setDirectory(m)},[m,f,r,x]),l.useEffect(()=>{if(!$||typeof window>"u")return;const R=Z=>{const K=Z?.visible===!0;y(K)},U=Z=>{if(Z.origin!==window.location.origin)return;const K=Z.data;K?.type==="openchamber:embedded-visibility"&&R(K.payload)},W=window;return W.__openchamberSetEmbeddedVisibility=R,window.addEventListener("message",U),()=>{window.removeEventListener("message",U),W.__openchamberSetEmbeddedVisibility===R&&delete W.__openchamberSetEmbeddedVisibility}},[$]),l.useEffect(()=>{!$?.directory||x||m!==$.directory&&u($.directory,{showOverlay:!1})},[m,$,x,u]),l.useEffect(()=>{if(!$||typeof window>"u")return;const R=U=>{U.storageArea===window.localStorage&&U.key==="ui-store"&&De.persist.rehydrate()};return window.addEventListener("storage",R),()=>{window.removeEventListener("storage",R)}},[$]),l.useEffect(()=>{if(typeof window>"u")return;const R=U=>{const W=U.detail,Z=typeof W?.sessionId=="string"?W.sessionId.trim():"";if(!Z)return;const K=typeof W?.directory=="string"&&W.directory.trim().length>0?W.directory.trim():null;De.getState().setActiveMainTab("chat"),Lt.getState().setCurrentSession(Z,K)};return window.addEventListener("openchamber:open-session",R),()=>window.removeEventListener("openchamber:open-session",R)},[]),l.useEffect(()=>{if(typeof window>"u")return;const R=U=>{const W=U.detail,Z=typeof W?.directory=="string"&&W.directory.trim().length>0?W.directory.trim():null,K=typeof W?.projectId=="string"&&W.projectId.trim().length>0?W.projectId.trim():null;De.getState().setActiveMainTab("chat"),De.getState().setSessionSwitcherOpen(!1),Lt.getState().openNewSessionDraft({selectedProjectId:K,directoryOverride:Z,preserveDirectoryOverride:!!Z})};return window.addEventListener("openchamber:open-draft-session",R),()=>window.removeEventListener("openchamber:open-draft-session",R)},[]),l.useEffect(()=>{if(typeof window>"u")return;const R=U=>{const W=U.detail,Z=typeof W?.projectPath=="string"?W.projectPath.trim():"";if(!Z)return;const K=Ts.getState(),ie=K.projects.find(Ne=>Ne.path===Z);ie?K.setActiveProject(ie.id):K.addProject(Z)};return window.addEventListener("openchamber:open-project",R),()=>window.removeEventListener("openchamber:open-project",R)},[]),l.useEffect(()=>{typeof window>"u"||!n||f||V.current||(V.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,f]),ov({enabled:z}),c6({enabled:z}),h6(),lv(),a6();const ee=l.useCallback(()=>{h(R=>!R)},[]);KD(ee),l.useEffect(()=>{if($)return;const R=U=>{Md(U)&&U.shiftKey&&!U.altKey&&(U.code==="KeyD"||U.key.toLowerCase()==="d")&&(U.preventDefault(),h(Z=>!Z))};return window.addEventListener("keydown",R,!0),()=>window.removeEventListener("keydown",R,!0)},[$]),l.useEffect(()=>{$||d&&setTimeout(()=>p(),5e3)},[p,$,d]),l.useEffect(()=>{if(!N||M!=="not-injected")return;let R=!1,U=0;const W=200,Z=2e3,K=50,ie=()=>{if(R)return;U++;const Ne=Pd();if(Ne!=="not-injected"){if(R=!0,F(Ne),Ne==="valid"){const fe=Af();fe&&B(Pf({isDesktopShell:!0,bootOutcome:fe}))}return}const ne=Math.min(W*Math.pow(1.1,U),Z);if(U>=K){const fe=document.getElementById("initial-loading");fe&&!fe.textContent?.includes("taking longer")&&(fe.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ie,ne)};return window.setTimeout(ie,W),()=>{R=!0}},[N,M]);const re=l.useCallback(async()=>{if(y6({isTauriShell:Ma(),isDesktopLocalOriginActive:Gr()})){await ah();return}window.location.reload()},[]),q=l.useCallback(async()=>{if(!D){A(!1),E(!0);try{await vt.getState().initializeApp()}finally{E(!1)}vt.getState().isInitialized||S(R=>R+1)}},[D]),ce=R=>{if(R.screen==="recovery")return R.variant};if(N&&_&&_.screen!=="main"){if(_.screen==="chooser")return s.jsx(Qs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Tf,{mode:"first-launch",onCliAvailable:re,onChooseRemote:()=>{}})})})});const R=ce(_),U=_.screen==="recovery"&&"url"in _?_.url:void 0;return s.jsx(Qs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Tf,{mode:"recovery",recoveryVariant:R,recoveryHostUrl:U,recoveryHostLabel:void 0,onCliAvailable:re})})})})}if($)return s.jsx(Qs,{children:s.jsx(Uu,{sdk:en.getSdkClient(),directory:m||"",children:s.jsx(Wu,{apis:t,children:s.jsx(Ku,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(T6,{embeddedSessionChat:$,isVSCodeRuntime:x,embeddedBackgroundWorkEnabled:z})})})})})});if(Q)return s.jsx(Qs,{children:s.jsx(S6,{})});if(k&&!n&&!x&&!$)return s.jsx(Qs,{children:s.jsx(P6,{onRetry:()=>{q()},isRetrying:D})});const ae=!n&&!N;return s.jsx(Qs,{children:s.jsx(Uu,{sdk:en.getSdkClient(),directory:m||"",children:s.jsx(Wu,{apis:t,children:s.jsx(D1,{children:s.jsx(cv,{children:s.jsx(Ku,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:N?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(gh,{embeddedBackgroundWorkEnabled:z}),s.jsx(Hg,{}),s.jsx(DD,{}),s.jsx(xh,{}),!ae&&s.jsxs(s.Fragment,{children:[s.jsx(v6,{}),s.jsx(I6,{}),b&&s.jsx(ED,{onClose:()=>h(!1)})]})]})})})})})})})}function E6(t){return t.isAboutDialogOpen}function R6(t){return t.setAboutDialogOpen}function F6(t){return t.currentDirectory}function O6(t){return t.currentSessionId}function L6(t){return t.setCurrentSession}const $6=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();dv();uv().then(()=>{Promise.all([mv(),pv()]).catch(t=>{console.error("[main] settings init failed:",t)}),fv(),hv(),gv()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Gg=document.getElementById("root");if(!Gg)throw new Error("Root element not found");Mx.createRoot(Gg).render(s.jsx($e.StrictMode,{children:s.jsx(xv,{children:s.jsx(bv,{children:s.jsx(yv,{children:s.jsx(vv,{children:s.jsx(M6,{apis:$6})})})})})}));const G6=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{fD as M,Ho as P,Er as S,YC as a,G6 as m,rn as u};
|