@openchamber/web 1.13.5 → 1.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/assets/{DiagramView-Bbj-QI7h.js → DiagramView-C_f1Il8p.js} +1 -1
  2. package/dist/assets/{MarkdownRendererImpl-BNr_9Jsb.js → MarkdownRendererImpl-BR0DXO9F.js} +3 -3
  3. package/dist/assets/{MultiRunWindow-DMMu53kw.js → MultiRunWindow-WBqBXcts.js} +1 -1
  4. package/dist/assets/NewWorktreeDialog-D7l2VA7o.js +167 -0
  5. package/dist/assets/{OnboardingScreen-BucKVBD7.js → OnboardingScreen-ChaxLu9k.js} +1 -1
  6. package/dist/assets/{SessionSwitcherDropdown-B6kvduse.js → SessionSwitcherDropdown-xaYa-FIx.js} +1 -1
  7. package/dist/assets/{SettingsWindow-BEfDro9b.js → SettingsWindow-D5aAKCEM.js} +1 -1
  8. package/dist/assets/{TerminalView-CMdqMpTy.js → TerminalView-D8GzsMZF.js} +1 -1
  9. package/dist/assets/{es-Bk-yR0w-.js → es-D0PPWgfL.js} +1 -1
  10. package/dist/assets/{fr-f1ibV7QU.js → fr-4AxG2GNC.js} +1 -1
  11. package/dist/assets/index-DJHN0H4h.js +3 -0
  12. package/dist/assets/{index-B82A6jBD.css → index-DxqTiFfR.css} +1 -1
  13. package/dist/assets/{ja-D9mS3zWP.js → ja-BPVJtPU2.js} +1 -1
  14. package/dist/assets/{ko-Cpl1IA3D.js → ko-BJHERh2a.js} +1 -1
  15. package/dist/assets/{main-KEVf2Yak.js → main-CLkcy9_q.js} +2 -2
  16. package/dist/assets/main-DUn82Iwq.js +214 -0
  17. package/dist/assets/miniChat-Ag1CYNF5.js +2 -0
  18. package/dist/assets/mobile-DtojUfiY.js +2 -0
  19. package/dist/assets/{pl-CYke_fxL.js → pl-CH00wT_K.js} +1 -1
  20. package/dist/assets/{pt-BR-Clb6Z8up.js → pt-BR-1tfKEfvN.js} +1 -1
  21. package/dist/assets/{renderElectronMiniChatApp-Cb1iUq8M.js → renderElectronMiniChatApp-BTsP-lHc.js} +2 -2
  22. package/dist/assets/{renderMobileApp-7chEBHPK.js → renderMobileApp-CSEgabkw.js} +3 -3
  23. package/dist/assets/{uk-CXn8cxXa.js → uk-BkeRI8D4.js} +1 -1
  24. package/dist/assets/{useAppFontEffects-Bd0ks39c.js → useAppFontEffects-BPhei6aO.js} +107 -107
  25. package/dist/assets/{zh-CN-BRwwlEdG.js → zh-CN-DtROWolc.js} +1 -1
  26. package/dist/assets/{zh-TW-D5pg5Z8l.js → zh-TW-CDqNEP6z.js} +1 -1
  27. package/dist/index.html +3 -3
  28. package/dist/mini-chat.html +3 -3
  29. package/dist/mobile.html +3 -3
  30. package/package.json +1 -1
  31. package/dist/assets/NewWorktreeDialog-5TYBoMMA.js +0 -167
  32. package/dist/assets/index-BsXkdBYx.js +0 -3
  33. package/dist/assets/main-DOdUrt3s.js +0 -214
  34. package/dist/assets/miniChat-Nlzqr3Df.js +0 -2
  35. package/dist/assets/mobile-BIhOFhia.js +0 -2
@@ -1,167 +0,0 @@
1
- import{ak as gc,e as rt,al as hc,j as t,H as je,am as fc,an as xc,a as rn,d as Zn,p as $r,b as Ur,R as l,L as Ss,ab as bc,ac as yc,aa as vc,ad as jc,a8 as wc,a9 as Nc,ae as kc,ao as Sc,ap as Cc,aq as Pc,u as Ic,l as Dc,n as Ac,w as Ec,C as Mc,S as Rc,ar as Tc,a6 as Fc,D as Oc,q as Lc,as as zc,at as Kc,au as $c,av as Uc,aw as Bc,X as Rs,ax as Vc,ay as bn,az as Zr,aA as _c,aB as Hc,aC as Ha,aD as Wc,aE as qc,aF as Gc,aG as ei,aH as Ma,aI as ti,k as wa,aJ as ml,aK as Br,aL as La,aM as ul,aN as si,aO as Jc,aP as Qc,aQ as Yc,aR as Xc,aS as ni,aT as Te,aU as na,aV as Zc,aW as ed,aX as td,aY as sd,aZ as nd,a_ as pl,a7 as ad,a$ as ai,b0 as rd,b1 as id,b2 as od,b3 as ld}from"./vendor-.bun-By2L9XvG.js";import{dx as za,r as Ra,v as Ta,m as de,dy as Na,dz as ka,dA as Sa,D as as,u as dt,I as A,aw as Dt,ax as At,ay as Et,dB as cd,au as Hs,a_ as Ut,aZ as Bt,aY as Vt,bC as Jt,w as jr,bb as Vr,p as un,at as Cs,t as V,ck as gl,B as J,dC as In,dD as dd,dE as md,dh as ud,dF as pd,dG as gd,dH as hd,z as Ps,dI as fd,cP as xd,cQ as bd,cR as yd,c2 as vd,ap as ds,ar as ms,c3 as jd,as as us,aS as Ka,dJ as wd,dK as kn,aX as _t,bo as qt,bK as Yt,n as it,dL as Qn,ao as js,Q as ut,de as Nd,bD as Ft,bE as Ot,bF as Kt,bG as Lt,bH as ht,b9 as ps,aT as _r,dM as pn,ba as Pt,dN as hl,dO as kd,dP as Sd,dQ as $a,dR as _s,dS as Dn,aV as fl,dT as Sn,dU as Cd,dV as Pd,dW as Id,dX as Dd,dY as Ad,dZ as Ed,d_ as Bs,d$ as Md,q as Ua,c8 as ri,k as Rd,ca as wr,a3 as xl,E as Td,P as bl,G as yl,cc as Fd,O as ii,cY as Od,dc as vl,d1 as jl,d3 as Ld,e0 as zd,cx as Kd,e1 as oi,e2 as $d,e3 as Ud,e4 as li,e5 as Bd,e6 as Vd,e7 as _d,e8 as Hd,av as Wd,e9 as qd,H as Gd,K as Jd,a as Hr,aG as ci,ea as di,eb as mi,aJ as zn,ec as Wa,ed as Qd,ee as Yd,ac as An,ab as wl,aa as Xd,ef as Zd,eg as ui,ad as em,ae as tm,a5 as sm,aA as nm,aB as am,aC as Nl,eh as qa,ei as pi,ej as rm,ek as im,el as om,em as lm,d4 as Ba,R as Vs,en as cm,cb as kl,eo as dm,ep as mm,eq as um,er as pm,es as Ga,et as gi,eu as gm,ev as hm,ew as fm,ex as xm,ey as bm,ez as Ja,eA as ym,eB as hi,eC as Wn,eD as vm,aP as fi,eE as wn,aO as jm,eF as wm,eG as xi,eH as bi,X as Ys,F as Nm,S as km,eI as Sm,ci as aa,bg as Nr,bh as kr,bi as Sr,bj as Cr,bk as Us,bl as Es,bL as Cn,M as Gn,eJ as yi,bX as Cm,eK as Sl,bN as Pm,d8 as Im,f as Dm,eL as Qa,a2 as Am,b3 as ra,bR as Em,eM as Mm,eN as Rm,d2 as Tm,eO as Fm,eP as Om}from"./useAppFontEffects-Bd0ks39c.js";import{D as Yn,e as jt,o as Ns,u as vs,a2 as Lm,a3 as vi,a4 as zm,a5 as Km,w as gs,K as mn,b as Ke,j as ea,f as It,a as Xn,q as Fs,h as fs,a6 as $m,F as Um,a7 as Ya,E as Bm,a8 as ji,a9 as Vm,x as _m,aa as wi,ab as Ni,ac as ki,ad as Si,ae as Xa,af as Ci,C as Cl,ag as Hm,ah as Wm,ai as qm,a1 as Gm,L as Jm,aj as Qm,ak as Ym,al as Xm}from"./index-BsXkdBYx.js";import{g as Zm,s as eu}from"./mobileLayoutPreference-Dio-WWkI.js";function tu(){return new Worker(gc,{type:"module"})}const su=["typescript","javascript","tsx","jsx","json","markdown"],Pr={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Pi,Ii;const Di=s=>{const e=Pr[s],n=new hc({workerFactory:tu,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:su,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},nu=s=>{if(!(typeof window>"u"))return s==="split"?(Ii??=Di("split"),Ii):(Pi??=Di("unified"),Pi)},au=s=>{const e=rt.c(7),{children:n,renderTheme:a}=s,r=Ir("unified"),i=Ir("split");let o,d;e[0]!==a||e[1]!==i||e[2]!==r?(o=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:Pr.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:Pr.split.lineDiffType})},d=[a,i,r],e[0]=a,e[1]=i,e[2]=r,e[3]=o,e[4]=d):(o=e[3],d=e[4]),je.useEffect(o,d);let c;return e[5]!==n?(c=t.jsx(t.Fragment,{children:n}),e[5]=n,e[6]=c):c=e[6],c},Av=s=>{const e=rt.c(11),{children:n}=s,a=za();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const x=Ra(!1),m=Ra(!0),p=a?.lightThemeId??x.metadata.id,u=a?.darkThemeId??m.metadata.id;i=a?.availableThemes.find(S=>S.metadata.id===p)??x,r=a?.availableThemes.find(S=>S.metadata.id===u)??m,Ta(i),Ta(r),e[0]=a?.availableThemes,e[1]=a?.darkThemeId,e[2]=a?.lightThemeId,e[3]=r,e[4]=i}else r=e[3],i=e[4];let o;e[5]!==r.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:r.metadata.id},e[5]=r.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const d=o;let c;return e[8]!==n||e[9]!==d?(c=t.jsx(au,{renderTheme:d,children:n}),e[8]=n,e[9]=d,e[10]=c):c=e[10],c},Ir=s=>{const e=rt.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=nu(n),e[0]=n,e[1]=a):a=e[1],a};function ru(s){const e=rt.c(4);let n,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=t.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"}),a=t.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]=a):(n=e[0],a=e[1]);let r;return e[2]!==s?(r=t.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",...s,children:[n,a]}),e[2]=s,e[3]=r):r=e[3],r}const Fa=je.forwardRef((s,e)=>{const n=rt.c(11);let a,r;n[0]!==s?({className:a,...r}=s,n[0]=s,n[1]=a,n[2]=r):(a=n[1],r=n[2]);let i;n[3]!==a?(i=de("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",a),n[3]=a,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 d;n[6]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(fc,{className:de("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=d):d=n[6];let c;return n[7]!==r||n[8]!==e||n[9]!==i?(c=t.jsx(xc,{className:i,style:o,...r,ref:e,children:d}),n[7]=r,n[8]=e,n[9]=i,n[10]=c):c=n[10],c});Fa.displayName="Switch";const ia=()=>{try{const e=as.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=Ns.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[McpConfigStore] Error resolving config directory:",s)}return null},Ai=s=>s?Object.entries(s).map(([e,n])=>({key:e,value:n})):[],Ei=s=>{const e=s.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},oa=s=>typeof s!="string"?void 0:s.trim()||void 0,Za=800,iu=5e3,ou="__default__",Dr=new Map,er=new Map,Pl=s=>s?.trim()||ou,tr=s=>{Dr.delete(Pl(s))},Mn=rn()(Zn($r((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=ia(),r=Pl(a),i=Date.now(),o=Dr.get(r)??0,d=e().mcpServers.length>0;if(!n?.force&&d&&i-o<iu)return!0;const c=er.get(r);if(!n?.force&&c)return c;const x=(async()=>{s({isLoading:!0});try{const m=a?`?directory=${encodeURIComponent(a)}`:"",p=await jt(`/api/config/mcp${m}`,{headers:a?{"x-opencode-directory":a}:void 0});if(!p.ok)throw new Error("Failed to load MCP configs");const u=await p.json();return s({mcpServers:u,isLoading:!1}),Dr.set(r,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),s({isLoading:!1}),!1}})();er.set(r,x);try{return await x}finally{er.delete(r)}},createMcp:async n=>{Na("Creating MCP server configuration…");let a=!1;try{const r=Mi(n),i=ia(),o=i?`?directory=${encodeURIComponent(i)}`:"",d=await jt(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(r)}),c=await d.json().catch(()=>null);if(!d.ok)throw new Error(c?.error||"Failed to create MCP server");return tr(i),c?.requiresReload?(a=!0,await ka({message:c.message,delayMs:c.reloadDelayMs??Za,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning})}catch(r){return console.error("[McpConfigStore] Failed to create MCP:",r),{ok:!1}}finally{a||Sa()}},updateMcp:async(n,a)=>{Na("Updating MCP server configuration…");let r=!1;try{const i=Mi(a),o=ia(),d=o?`?directory=${encodeURIComponent(o)}`:"",c=await jt(`/api/config/mcp/${encodeURIComponent(n)}${d}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),x=await c.json().catch(()=>null);if(!c.ok)throw new Error(x?.error||"Failed to update MCP server");return tr(o),x?.requiresReload?(r=!0,await ka({message:x.message,delayMs:x.reloadDelayMs??Za,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:x?.reloadFailed===!0,message:x?.message,warning:x?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:x?.reloadFailed===!0,message:x?.message,warning:x?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||Sa()}},deleteMcp:async n=>{Na("Deleting MCP server configuration…");let a=!1;try{const r=ia(),i=r?`?directory=${encodeURIComponent(r)}`:"",o=await jt(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:r?{"x-opencode-directory":r}:void 0}),d=await o.json().catch(()=>null);if(!o.ok)throw new Error(d?.error||"Failed to delete MCP server");return tr(r),d?.requiresReload&&(a=!0,await ka({message:d.message,delayMs:d.reloadDelayMs??Za,scopes:["all"]})),e().selectedMcpName===n&&s({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}}catch(r){return console.error("[McpConfigStore] Failed to delete MCP:",r),{ok:!1}}finally{a||Sa()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:Ur(()=>Yn()),partialize:s=>({selectedMcpName:s.selectedMcpName})}),{name:"mcp-config-store"}));function Mi(s){const e={};if(s.scope!==void 0&&(e.scope=s.scope),s.type!==void 0&&(e.type=s.type),(s.type==="local"||s.command!==void 0)&&(e.command=(s.command??[]).filter(n=>n.trim())),(s.type==="remote"||s.url!==void 0)&&(e.url=s.url?.trim()??""),s.environment!==void 0&&(e.environment=Ei(s.environment)??{}),s.headers!==void 0&&(e.headers=Ei(s.headers)??{}),s.oauthEnabled!==void 0||s.oauthClientId!==void 0||s.oauthClientSecret!==void 0||s.oauthScope!==void 0||s.oauthRedirectUri!==void 0)if(s.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:oa(s.oauthClientId),clientSecret:oa(s.oauthClientSecret),scope:oa(s.oauthScope),redirectUri:oa(s.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:s.oauthEnabled?e.oauth={}:e.oauth=!1}if(s.timeout!==void 0){const n=Number(s.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return s.enabled!==void 0&&(e.enabled=s.enabled),e}const lu={},cu={},$s=s=>{if(typeof s!="string")return null;const e=s.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},vn=s=>$s(s)??"__global__",ln=s=>{const e=$s(s);return e?Ns.getScopedApiClient(e):Ns.getApiClient()},is=rn()(Zn((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=vn(n??vs.getState().currentDirectory);return e().byDirectory[a]??lu},getDiagnosticForDirectory:n=>{const a=vn(n??vs.getState().currentDirectory);return e().diagnosticsByDirectory[a]??cu},getErrorForDirectory:n=>{const a=vn(n??vs.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=$s(n?.directory??vs.getState().currentDirectory),r=vn(a);n?.silent||s(i=>({loadingKeys:{...i.loadingKeys,[r]:!0},lastErrorKeys:{...i.lastErrorKeys,[r]:null}}));try{const d=(await ln(a).mcp.status()).data??{};s(c=>({byDirectory:{...c.byDirectory,[r]:d},diagnosticsByDirectory:{...c.diagnosticsByDirectory,[r]:Object.fromEntries(Object.entries(c.diagnosticsByDirectory[r]??{}).filter(([x])=>!d[x]))},loadingKeys:{...c.loadingKeys,[r]:!1},lastErrorKeys:{...c.lastErrorKeys,[r]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";s(d=>({loadingKeys:{...d.loadingKeys,[r]:!1},lastErrorKeys:{...d.lastErrorKeys,[r]:o}}))}},connect:async(n,a)=>{const r=$s(a??vs.getState().currentDirectory),i=vn(r),o=ln(r);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(d){const c=d instanceof Error?d.message:"Connection failed";throw s(x=>({diagnosticsByDirectory:{...x.diagnosticsByDirectory,[i]:{...x.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:c}}}})),d}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=$s(a??vs.getState().currentDirectory);await ln(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=$s(a??vs.getState().currentDirectory),d=(await ln(r).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!d)throw new Error("Authorization URL was not returned");return d},completeAuth:async(n,a,r)=>{const i=$s(r??vs.getState().currentDirectory);await ln(i).mcp.auth.callback({name:n,code:a},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,a)=>{const r=$s(a??vs.getState().currentDirectory);await ln(r).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},testConnection:async(n,a)=>{const r=$s(a??vs.getState().currentDirectory),i=vn(r),o=ln(r),c=e().getStatusForDirectory(r)[n]?.status==="connected";let x,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(S){x=S instanceof Error?S.message:"Connection failed",s(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:x??"Connection failed"}}}}))}await e().refresh({directory:r,silent:!0});const p=e().getStatusForDirectory(r)[n],u=p;if(!c&&p?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(S){m=`Connection test succeeded, but cleanup disconnect failed: ${S instanceof Error?S.message:"Disconnect failed"}`}await e().refresh({directory:r,silent:!0})}return{status:u??e().getStatusForDirectory(r)[n],error:x,warning:m}}}))),du=(s,e)=>{if(!s)return e("mcpDropdown.status.unknown");switch(s.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:s.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:s.error||""});default:return s.status}},mu=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Ev=({active:s,className:e,headerAction:n,listClassName:a,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:o}=dt(),c=vs(N=>N.currentDirectory)??null,x=is(N=>N.getStatusForDirectory(c)),m=is(N=>N.refresh),p=is(N=>N.connect),u=is(N=>N.disconnect),S=Mn(N=>N.mcpServers),f=Mn(N=>N.loadMcpConfigs),[g,h]=l.useState(!1),[D,k]=l.useState(null);l.useEffect(()=>{m({directory:c,silent:!0})},[m,c]),l.useEffect(()=>{f({force:!0})},[f]),l.useEffect(()=>{s&&Promise.all([m({directory:c,silent:!0}),f({force:!0})])},[s,m,c,f]);const w=l.useMemo(()=>{const N=new Set(Object.keys(x));for(const y of S)y?.name&&N.add(y.name);return Array.from(N).sort((y,b)=>y.localeCompare(b))},[S,x]),E=l.useCallback(N=>{if(N?.preventDefault(),g)return;h(!0);const y=new Promise(b=>setTimeout(b,500));Promise.all([m({directory:c}),y]).finally(()=>{h(!1)})},[g,m,c]);return t.jsxs("div",{className:de("w-full",e),children:[r?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:t.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:o("mcpDropdown.title")}),c&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:c.split("/").pop()||c})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n,t.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:g,onClick:E,"aria-label":o("mcpDropdown.actions.refreshAria"),children:t.jsx(A,{name:"refresh",className:de("h-4 w-4",g&&"animate-spin")})})]})]})}),t.jsxs("div",{className:de("max-h-64 overflow-y-auto py-2",i&&"space-y-1 py-3",a),children:[w.map(N=>{const y=x[N],b=mu(y),P=y?.status==="connected",z=D===N,M=du(y,o);return t.jsxs("div",{className:de("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",i?"gap-3 px-4 py-3":"gap-2 px-4 py-1.5"),children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx("span",{className:de("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",b==="success"&&"bg-status-success",b==="error"&&"bg-status-error",b==="warning"&&"bg-status-warning",b==="default"&&"bg-muted-foreground/40"),"aria-label":M})}),t.jsx(Et,{side:"left",children:t.jsx("p",{children:M})})]}),t.jsx("span",{className:de("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:N})]})}),t.jsx(Fa,{checked:P,disabled:z,className:"data-[checked]:bg-status-info",onCheckedChange:async I=>{k(N);try{I?await p(N,c):await u(N,c)}finally{k(null)}}})]},N)}),w.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:o("mcpDropdown.empty.configureInConfig")})]})]})};function uu(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=cd();return s}catch{return"unknown"}}function pu(){const s=typeof window<"u"?window.__VSCODE_CONFIG__?.arch?.toLowerCase?.():void 0;if(s==="arm64"||s==="aarch64")return"arm64";if(s==="x64"||s==="amd64"||s==="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 a=typeof navigator<"u"?navigator.userAgent.toLowerCase():"";return a.includes("aarch64")||a.includes("arm64")||a.includes("armv")?"arm64":a.includes("x86_64")||a.includes("x64")||a.includes("amd64")||a.includes("win64")?"x64":"unknown"}function gu(){if(typeof navigator>"u")return"web";const s=(navigator.platform||"").toLowerCase();return s.includes("mac")?"macos":s.includes("win")?"windows":s.includes("linux")?"linux":"web"}function hu(s){const e=Ke.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",uu()),n.set("arch",pu()),n.set("platform",gu()),s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",ea()?"local":"remote"),n):s==="vscode"?(n.set("appType","vscode"),n.set("instanceMode","local"),n):(n.set("appType","web"),n.set("instanceMode","unknown"),n)}async function Ri(s,e){try{const n=hu(s),a=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e||s==="vscode"&&a&&n.set("currentVersion",a);const r=await jt(`/api/openchamber/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!r.ok)throw new Error(`Server responded with ${r.status}`);const i=await r.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 fu(){return Km()?"desktop":gs()?"vscode":mn()?"web":null}const Ti={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Il=rn()((s,e)=>({...Ti,checkForUpdates:async()=>{const n=fu();if(!n)return null;s({checking:!0,error:null,runtimeType:n});try{let a=null,r=null;if(n==="desktop"){const i=await vi();return s({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null}),r}else n==="web"?(a=await Ri("web"),r=a?.nextSuggestedCheckInSec??null):n==="vscode"&&(r=(await Ri("vscode"))?.nextSuggestedCheckInSec??null);return s({checking:!1,available:n==="vscode"?!1:a?.available??!1,info:n==="vscode"?null:a,lastChecked:Date.now(),nextCheckInSec:r}),r}catch(a){return s({checking:!1,error:a instanceof Error?a.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:a}=e();if(!(a!=="desktop"||!n)){s({downloading:!0,error:null,progress:null});try{const r=await vi();if(!r?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(s(o=>({info:o.info?{...o.info,...r,body:o.info.body||r.body,available:o.info.available}:r})),!await zm(o=>{s({progress:o})}))throw new Error("Desktop update only works on Local instance");s({downloading:!1,downloaded:!0})}catch(r){s({downloading:!1,error:r instanceof Error?r.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:a}=e();if(!(a!=="desktop"||!n))try{if(!await Lm())throw new Error("Desktop restart only works on Local instance")}catch(r){s({error:r instanceof Error?r.message:"Failed to restart"})}},dismiss:()=>{s({available:!1,downloaded:!1,info:null})},reset:()=>{s(Ti)}})),Fi="https://github.com/btriapitsyn/openchamber/releases";function xu(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(Vr(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function bu(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Oi(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function yu(s,e){const n=s.split(".").map(r=>Number.parseInt(r,10)),a=e.split(".").map(r=>Number.parseInt(r,10));for(let r=0;r<3;r+=1){const i=Number.isFinite(n[r])?n[r]:0,o=Number.isFinite(a[r])?a[r]:0;if(i!==o)return o-i}return 0}function vu(s){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let a;for(;(a=e.exec(s))!==null;)n.push({version:a[1]??"",date:a[2]??"",start:a.index});return n.length===0?[]:n.map((r,i)=>{const o=n[i+1]?.start??s.length,d=s.slice(r.start,o).trim();return{version:r.version,date:r.date,start:r.start,end:o,raw:d}})}const Li=2e3,ju=600*1e3;async function wu(){try{const s=await jt("/api/openchamber/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});return s.ok?{success:!0,autoRestart:(await s.json().catch(()=>({}))).autoRestart!==!1}:{success:!1,error:(await s.json().catch(()=>({}))).error||`Server error: ${s.status}`}}catch(s){return{success:!1,error:s instanceof Error?s.message:void 0}}}async function Nu(){try{return(await jt("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function ku(s,e=Math.ceil(ju/Li),n=Li){for(let a=0;a<e;a++){try{const r=await jt("/api/openchamber/update-check",{method:"GET",headers:{Accept:"application/json"}});if(r.ok){const i=await r.json().catch(()=>null);if(i&&i.available===!1||i&&typeof i.currentVersion=="string"&&typeof s=="string"&&i.currentVersion!==s)return!0}else if((r.status===401||r.status===403)&&await Nu())return!0}catch{}await new Promise(r=>setTimeout(r,n))}return!1}const zi=({open:s,onOpenChange:e,info:n,downloading:a,downloaded:r,progress:i,error:o,onDownload:d,onRestart:c,runtimeType:x="desktop"})=>{const{t:m}=dt(),[p,u]=je.useState(!1),[S,f]=je.useState("idle"),[g,h]=je.useState(null),D=n?.version?`${Fi}/tag/v${n.version}`:Fi,k=i?.total?Math.round(i.downloaded/i.total*100):0,w=x==="web",E=n?.updateCommand||"openchamber update";je.useEffect(()=>{s||(f("idle"),h(null))},[s]);const N=async()=>{(await un(E)).ok&&(u(!0),setTimeout(()=>u(!1),2e3))},y=je.useCallback(async M=>{await Hs(M)},[]),b=je.useCallback(async()=>{f("updating"),h(null);const M=await wu();if(!M.success){f("error"),h(M.error||m("updateDialog.error.updateFailed"));return}M.autoRestart&&(f("restarting"),await new Promise(v=>setTimeout(v,2e3))),f("reconnecting"),await ku(n?.currentVersion)?window.location.reload():(f("error"),h(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),P=S!=="idle"&&S!=="error",z=je.useMemo(()=>{if(!n?.body)return null;const M=n.body.trim();if(!M)return null;const I=vu(M);if(I.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Oi(M)};const v=[...I].sort((j,O)=>yu(j.version,O.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:v.map(j=>({version:j.version,dateLabel:xu(j.date),content:Oi(bu(j.raw)||M)}))}},[n?.body,m]);return t.jsx(Ut,{open:s,onOpenChange:P?void 0:e,children:t.jsxs(Bt,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[t.jsxs("div",{className:"flex items-center mb-1",children:[t.jsxs(Vt,{className:"flex items-center gap-2.5",children:[t.jsx(A,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),t.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(S==="restarting"||S==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&t.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&t.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&t.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&t.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),t.jsxs("div",{className:"space-y-2",children:[w&&P&&t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(A,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),t.jsxs("div",{className:"typography-ui-label text-foreground",children:[S==="updating"&&m("updateDialog.status.installingUpdate"),S==="restarting"&&m("updateDialog.status.serverRestarting"),S==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),z&&!P&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(Jt,{className:"max-h-[400px] p-0",fillContainer:!1,children:z.kind==="raw"?t.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:M=>{const v=M.target.closest("a");v&&v.href&&(M.preventDefault(),M.stopPropagation(),y(v.href))},children:t.jsx(jr,{content:z.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:z.sections.map(M=>t.jsxs("div",{className:"p-4",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.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",M.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:M.dateLabel})]}),t.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:I=>{const j=I.target.closest("a");j&&j.href&&(I.preventDefault(),I.stopPropagation(),y(j.href))},children:t.jsx(jr,{content:M.content,disableLinkSafety:!0,enableFileReferences:!1})})]},M.version))})})}),w&&S==="error"&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx(A,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:m("updateDialog.fallback.updateViaTerminal")})]}),t.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:[t.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:E}),t.jsx("button",{onClick:N,className:de("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",p&&"text-[var(--status-success)]"),title:m(p?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:p?t.jsx(A,{name:"check",className:"h-4 w-4"}):t.jsx(A,{name:"clipboard",className:"h-4 w-4"})})]})]}),!w&&a&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),t.jsxs("span",{className:"font-mono text-foreground",children:[k,"%"]})]}),t.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${k}%`}})})]}),(o||g)&&t.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:t.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||g})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:D,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:[t.jsx(A,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!w&&!r&&!a&&t.jsxs("button",{onClick:d,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:[t.jsx(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!w&&a&&t.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:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!w&&r&&t.jsxs("button",{onClick:c,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:[t.jsx(A,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),w&&!P&&t.jsxs("button",{onClick:b,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:[t.jsx(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),w&&P&&t.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:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},Ki="https://github.com/openchamber/openchamber",Su="https://discord.gg/ZYRSdnwwKA",$i="https://x.com/openchamber_dev",Cu=800,Dl=({initialUpdateDialogOpen:s=!1})=>{const{t:e}=dt(),[n,a]=l.useState(s),[r,i]=l.useState(!1),[o,d]=l.useState(null),[c,x]=l.useState(null),m=Il(Ss(g=>({info:g.info,checking:g.checking,available:g.available,error:g.error,downloading:g.downloading,downloaded:g.downloaded,progress:g.progress,runtimeType:g.runtimeType,checkForUpdates:g.checkForUpdates,downloadUpdate:g.downloadUpdate,restartToUpdate:g.restartToUpdate}))),{isMobile:p}=Cs(),u=o||m.info?.currentVersion||"unknown";l.useEffect(()=>{let g=!1;return(async()=>{try{const D=await jt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const k=await D.json().catch(()=>null),w=typeof k?.openchamberVersion=="string"&&k.openchamberVersion.trim().length>0?k.openchamberVersion.trim():null;g||d(w)}catch{g||d(null)}})(),()=>{g=!0}},[]),l.useEffect(()=>{let g=!1;return(async()=>{try{const D=await jt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const k=await D.json().catch(()=>null),w=typeof k?.currentVersion=="string"&&k.currentVersion.trim().length>0?k.currentVersion.trim():null;g||x(w)}catch{g||x(null)}})(),()=>{g=!0}},[]);const S=l.useRef(!1);l.useEffect(()=>{if(m.checking)i(!0),S.current=!0;else if(r){const g=setTimeout(()=>{i(!1),S.current&&!m.available&&!m.error&&(V.success(e("settings.openchamber.about.toast.latestVersion")),S.current=!1)},Cu);return()=>clearTimeout(g)}},[e,m.checking,r,m.available,m.error]);const f=m.checking||r;return p?t.jsxs("div",{className:"w-full space-y-6 pb-2",children:[t.jsxs("div",{className:"flex flex-col items-center text-center",children:[t.jsx(gl,{width:72,height:72}),t.jsx("h2",{className:"mt-4 typography-ui-header font-semibold text-foreground",children:"OpenChamber"}),t.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[t.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:u})}),t.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]})]}),t.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&t.jsxs(J,{type:"button",variant:"outline",size:"sm",onClick:()=>m.checkForUpdates(),disabled:f,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[f?t.jsx(A,{name:"loader",className:"size-4 animate-spin"}):t.jsx(A,{name:"refresh",className:"size-4"}),e(f?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!f&&m.available&&t.jsxs(J,{type:"button",variant:"default",size:"sm",onClick:()=>a(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[t.jsx(A,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]})]}),m.error&&t.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:m.error}),t.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[t.jsxs("div",{className:"flex items-center justify-center gap-5",children:[t.jsxs("a",{href:Ki,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(A,{name:"github-fill",className:"size-5"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:Su,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(A,{name:"discord-fill",className:"size-5"}),t.jsx("span",{children:"Discord"})]})]}),t.jsxs("a",{href:$i,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(A,{name:"twitter-xfill",className:"size-5"}),t.jsx("span",{children:"@openchamber_dev"})]})]}),t.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),t.jsx(zi,{open:n,onOpenChange:a,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]}):t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-3 px-1",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:e("settings.openchamber.about.title")})}),t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[t.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:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.version")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:u})]}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.openCodeVersion")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!m.checking&&m.available&&t.jsxs(J,{size:"sm",variant:"default",onClick:()=>a(!0),children:[t.jsx(A,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]}),!m.checking&&!m.available&&!m.error&&t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t.jsx(J,{size:"sm",variant:"outline",onClick:()=>m.checkForUpdates(),disabled:m.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),m.error&&t.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m.error})}),t.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[t.jsxs("a",{href:Ki,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[t.jsx(A,{name:"github-fill",className:"h-4 w-4"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:$i,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[t.jsx(A,{name:"twitter-xfill",className:"h-4 w-4"}),t.jsx("span",{children:"@openchamber_dev"})]})]})]}),t.jsx(zi,{open:n,onOpenChange:a,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]})},Mv=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),Pu=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),Iu=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},Du=s=>!s||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),Kn="opencode-update-available",la="opencode-upgrade-progress",Au=5e3,Eu=[1e4,6e4],Ui="opencode-update-toast-dismissed-version",Rv=()=>{const{t:s}=dt(),e=Ke(o=>o.showOpenCodeUpdateNotifications),n=je.useRef(new Set),a=je.useRef(!1);je.useEffect(()=>{e||V.dismiss(Kn)},[e]);const r=je.useCallback(()=>{V.dismiss(la),In({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),i=je.useCallback(async()=>{if(!a.current){a.current=!0,V.dismiss(Kn),V.message(s("opencodeUpdate.toast.upgrading.title"),{id:la,description:s("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:t.jsx(A,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const o=await jt("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),d=await o.json().catch(()=>null);if(!o.ok||d?.success===!1)throw new Error(d?.error||o.statusText||s("opencodeUpdate.toast.failed.description"));V.success(s("opencodeUpdate.toast.updated.title"),{id:la,description:d?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:d.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(o){V.error(s("opencodeUpdate.toast.failed.title"),{id:la,description:o instanceof Error?o.message:s("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{a.current=!1}}},[r,s]);return je.useEffect(()=>{const o=p=>{if(!Ke.getState().showOpenCodeUpdateNotifications){V.dismiss(Kn);return}Pu({version:p,dismissedVersion:Yn().getItem(Ui),seenVersions:n.current})&&(n.current.add(p),V.info(s("opencodeUpdate.toast.available.title"),{id:Kn,description:s("opencodeUpdate.toast.available.description",{version:p}),duration:1/0,action:{label:s("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:s("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{Yn().setItem(Ui,p),It({openCodeUpdateToastDismissedVersion:p}),V.dismiss(Kn)}}}))},d=p=>{const u=Iu(p.detail);o(u)};let c=!1;const x=[],m=async p=>{try{const u=await jt("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!u.ok)throw new Error(u.statusText||"OpenCode upgrade status check failed");const S=await u.json().catch(()=>null),f=Du(S);!c&&f&&o(f)}catch{const u=Eu[p];!c&&u!==void 0&&x.push(setTimeout(()=>{m(p+1)},u))}};return e&&x.push(setTimeout(()=>{m(0)},Au)),window.addEventListener("openchamber:opencode-update-available",d),()=>{c=!0;for(const p of x)clearTimeout(p);window.removeEventListener("openchamber:opencode-update-available",d)}},[i,e,s]),null},Tv=()=>{const s=rt.c(3),[e,n]=l.useState(Mu),{isUpdating:a}=e;let r,i;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>md(n),i=[],s[0]=r,s[1]=i):(r=s[0],i=s[1]),l.useEffect(r,i),!a)return null;let o;return s[2]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:t.jsx(gl,{width:80,height:80,isAnimated:!0})}),s[2]=o):o=s[2],o};function Mu(){return dd()}class Ru 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?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(ud,{className:"w-full max-w-md",children:[t.jsx(pd,{className:"text-center",children:t.jsxs(gd,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(A,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(hd,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(J,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function Tu(s){const e=rt.c(22),{t:n}=dt();let a;e[0]!==n?(a=n("chat.errorBoundary.title"),e[0]=n,e[1]=a):a=e[1];let r;e[2]!==n?(r=n("chat.errorBoundary.description"),e[2]=n,e[3]=r):r=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 d;e[8]!==n?(d=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=d):d=e[9];let c;e[10]!==n?(c=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=c):c=e[11];let x;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==o||e[16]!==d||e[17]!==c?(x={title:a,description:r,sessionLabel:i,detailsSummary:o,resetAction:d,persistentHint:c},e[12]=a,e[13]=r,e[14]=i,e[15]=o,e[16]=d,e[17]=c,e[18]=x):x=e[18];let m;return e[19]!==s||e[20]!==x?(m=t.jsx(Ru,{...s,texts:x}),e[19]=s,e[20]=x,e[21]=m):m=e[21],m}const Fv=s=>{const e=rt.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=Ps(Fu)||void 0;let o;e[0]!==a?(o=t.jsx(fd,{readOnly:a}),e[0]=a,e[1]=o):o=e[1];let d;return e[2]!==i||e[3]!==o?(d=t.jsx(Tu,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=d):d=e[4],d};function Fu(s){return s.currentSessionId}function en(s){const e=rt.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let a;return e[2]!==n?(a=t.jsx(bc,{...n}),e[2]=n,e[3]=a):a=e[3],a}function tn(s){const e=rt.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let a;return e[2]!==n?(a=t.jsx(yc,{...n}),e[2]=n,e[3]=a):a=e[3],a}function sn(s){const e=rt.c(20);let n,a,r,i,o;e[0]!==s?({className:a,positionerClassName:r,children:n,style:o,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i,e[5]=o):(n=e[1],a=e[2],r=e[3],i=e[4],o=e[5]);let d;e[6]!==r?(d=de("app-region-no-drag z-50",r),e[6]=r,e[7]=d):d=e[7];let c;e[8]!==o?(c={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",...o},e[8]=o,e[9]=c):c=e[9];let x;e[10]!==a?(x=de(xd,a),e[10]=a,e[11]=x):x=e[11];let m;e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==x?(m=t.jsx(vc,{"data-slot":"dropdown-menu-content",style:c,className:x,...i,children:n}),e[12]=n,e[13]=i,e[14]=c,e[15]=x,e[16]=m):m=e[16];let p;return e[17]!==d||e[18]!==m?(p=t.jsx(wc,{children:t.jsx(Nc,{className:d,children:m})}),e[17]=d,e[18]=m,e[19]=p):p=e[19],p}function Ws(s){const e=rt.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=de(bd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(jc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}function Ov(s){const e=rt.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=de(yd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(kc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}const Al=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),ta=s=>{const e=rt.c(39),{className:n}=s,{t:a}=dt(),r=as(Ou),i=as(Lu),o=as(zu),d=gs();let c;e[0]!==r?(c=[...r].sort(Ku),e[0]=r,e[1]=c):c=e[1];const x=c;let m;e:{if(x.length===0){m=null;break e}let O;e[2]!==i||e[3]!==x?(O=x.find(T=>T.id===i)??x[0],e[2]=i,e[3]=x,e[4]=O):O=e[4],m=O}const p=m;if(d||x.length===0)return null;let u;e[5]!==p||e[6]!==a?(u=p?.label&&p.label.trim().length>0?p.label:p?.path.split("/").filter(Boolean).pop()||p?.path||a("settings.shared.projectSelector.fallbackProject"),e[5]=p,e[6]=a,e[7]=u):u=e[7];const S=u;let f;e[8]!==S?(f=Al(S),e[8]=S,e[9]=f):f=e[9];const g=f;let h;e[10]!==n?(h=de(n),e[10]=n,e[11]=h):h=e[11];let D;e[12]!==a?(D=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=D):D=e[13];let k;e[14]!==a?(k=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=k):k=e[15];let w,E;e[16]===Symbol.for("react.memo_cache_sentinel")?(w=de("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"),E=t.jsx(A,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=w,e[17]=E):(w=e[16],E=e[17]);let N;e[18]!==g?(N=t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:g}),e[18]=g,e[19]=N):N=e[19];let y;e[20]===Symbol.for("react.memo_cache_sentinel")?(y=t.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=y):y=e[20];let b;e[21]!==N||e[22]!==D||e[23]!==k?(b=t.jsx(ds,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":D,title:k,className:w,children:[E,N,y]})}),e[21]=N,e[22]=D,e[23]=k,e[24]=b):b=e[24];const P=p?.id??"";let z;e[25]!==o?(z=O=>{O&&o(O)},e[25]=o,e[26]=z):z=e[26];let M;e[27]!==x?(M=x.map($u),e[27]=x,e[28]=M):M=e[28];let I;e[29]!==P||e[30]!==z||e[31]!==M?(I=t.jsx(ms,{align:"start",className:"w-auto",children:t.jsx(jd,{value:P,onValueChange:z,children:M})}),e[29]=P,e[30]=z,e[31]=M,e[32]=I):I=e[32];let v;e[33]!==b||e[34]!==I?(v=t.jsxs(us,{children:[b,I]}),e[33]=b,e[34]=I,e[35]=v):v=e[35];let j;return e[36]!==v||e[37]!==h?(j=t.jsx("div",{className:h,children:v}),e[36]=v,e[37]=h,e[38]=j):j=e[38],j};function Ou(s){return s.projects}function Lu(s){return s.activeProjectId}function zu(s){return s.setActiveProject}function Ku(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function $u(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=Al(e);return t.jsx(vd,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function Uu(s,e){return`opencode:sidebar-group:${s}:${e}`}const Ar=s=>{const e=rt.c(33),{label:n,count:a,storageKey:r,defaultExpanded:i,children:o}=s,d=i===void 0?!0:i;let c;e[0]!==n||e[1]!==r?(c=Uu(r,n),e[0]=n,e[1]=r,e[2]=c):c=e[2];const x=c,m=l.useId();let p;e[3]!==d||e[4]!==x?(p=()=>{try{const I=localStorage.getItem(x);if(I!==null)return I==="true"}catch{}return d},e[3]=d,e[4]=x,e[5]=p):p=e[5];const[u,S]=je.useState(p);let f,g;e[6]!==u||e[7]!==x?(f=()=>{try{localStorage.setItem(x,String(u))}catch{}},g=[x,u],e[6]=u,e[7]=x,e[8]=f,e[9]=g):(f=e[8],g=e[9]),je.useEffect(f,g);let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=()=>S(Bu),e[10]=h):h=e[10];let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=de("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]=D):D=e[11];const k=!u&&"-rotate-90";let w;e[12]!==k?(w=de("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",k),e[12]=k,e[13]=w):w=e[13];let E;e[14]!==w?(E=t.jsx(A,{name:"arrow-down-s",className:w}),e[14]=w,e[15]=E):E=e[15];let N;e[16]!==n?(N=t.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=N):N=e[17];let y;e[18]!==a?(y=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=y):y=e[19];let b;e[20]!==m||e[21]!==u||e[22]!==E||e[23]!==N||e[24]!==y?(b=t.jsxs("button",{type:"button",onClick:h,"aria-expanded":u,"aria-controls":m,className:D,children:[E,N,y]}),e[20]=m,e[21]=u,e[22]=E,e[23]=N,e[24]=y,e[25]=b):b=e[25];const P=!u;let z;e[26]!==o||e[27]!==m||e[28]!==P?(z=t.jsx("div",{id:m,hidden:P,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]=P,e[29]=z):z=e[29];let M;return e[30]!==b||e[31]!==z?(M=t.jsxs("div",{children:[b,z]}),e[30]=b,e[31]=z,e[32]=M):M=e[32],M};function Bu(s){return!s}const Vu=s=>{if(!Array.isArray(s))return[];const e=[];for(const n of s){if(!n||typeof n!="object")continue;const a=n;typeof a.permission!="string"||typeof a.pattern!="string"||typeof a.action!="string"||a.action!=="allow"&&a.action!=="ask"&&a.action!=="deny"||e.push({permission:a.permission,pattern:a.pattern,action:a.action})}return e},_u=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},Bi=s=>{const e=_u(Vu(s));if(e.length===0)return;const n={};for(const r of e)r.permission&&((n[r.permission]||={})[r.pattern]=r.action);const a={};for(const[r,i]of Object.entries(n)){const o=Object.keys(i);if(o.length===1&&o[0]==="*"){a[r]=i["*"];continue}a[r]=i}return Object.keys(a).length>0?a:void 0},Hu=({onItemSelect:s})=>{const{t:e}=dt(),[n,a]=l.useState(null),[r,i]=l.useState(""),[o,d]=l.useState(null),[c,x]=l.useState(null),[m,p]=l.useState(!1),[u,S]=l.useState(null),{selectedAgentName:f,agents:g,setSelectedAgent:h,setAgentDraft:D,createAgent:k,deleteAgent:w,loadAgents:E}=Ka(Ss(R=>({selectedAgentName:R.selectedAgentName,agents:R.agents,setSelectedAgent:R.setSelectedAgent,setAgentDraft:R.setAgentDraft,createAgent:R.createAgent,deleteAgent:R.deleteAgent,loadAgents:R.loadAgents})));l.useEffect(()=>{E()},[E]);const N="bg-background",y=()=>{const R="new-agent";let Y=R,F=1;for(;g.some(H=>H.name===Y);)Y=`${R}-${F}`,F++;D({name:Y,scope:"user"}),h(Y),s?.()},b=async R=>{if(kn(R)){V.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(R),x("delete")},P=async R=>{kn(R)&&(d(R),x("reset"))},z=()=>{d(null),x(null)},M=async()=>{if(!(!o||!c)){p(!0);try{const R=await w(o.name,o.scope);R.ok?(R.requiresManualRestart?V.warning(e("settings.agents.page.toast.savedManualRestart")):c==="delete"?V.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):V.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),z()):c==="delete"?V.error(e("settings.agents.sidebar.toast.deleteFailed")):V.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(R){const Y=R instanceof Error?R.message:"",F=/built-in|not deletable|not found/i.test(Y);c==="delete"?V.error(e(F?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):V.error(e("settings.agents.sidebar.toast.resetFailed"))}p(!1)}},I=R=>{const Y=R.name;let F=1,H=`${Y}-copy`;for(;g.some(se=>se.name===H);)F++,H=`${Y}-copy-${F}`;const X=R,re=R.model?.providerID&&R.model?.modelID?`${R.model.providerID}/${R.model.modelID}`:null,Z=R;D({name:H,scope:X.scope||"user",description:R.description,model:re,variant:R.variant,temperature:R.temperature,top_p:R.topP,prompt:R.prompt,mode:R.mode,permission:Bi(R.permission),disable:Z.disable}),h(H)},v=R=>{i(R.name),a(R)},j=async()=>{if(!n)return;const R=r.trim().replace(/\s+/g,"-");if(!R){V.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(R===n.name){a(null);return}if(g.some(X=>X.name===R)){V.error(e("settings.agents.sidebar.toast.agentExists"));return}const Y=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,F=n,H=await k({name:R,description:n.description,model:Y,variant:n.variant,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Bi(n.permission),disable:F.disable,scope:F.scope});if(H.ok){const X=await w(n.name,F.scope);X.ok?(H.requiresManualRestart||X.requiresManualRestart?V.warning(e("settings.agents.page.toast.savedManualRestart")):V.success(e("settings.agents.sidebar.toast.agentRenamed",{name:R})),h(R)):V.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else V.error(e("settings.agents.sidebar.toast.renameFailed"));a(null)},O=R=>{switch(R){case"primary":return t.jsx(A,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(A,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(A,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},T=g.filter(R=>!wd(R)),U=T.filter(kn),B=T.filter(R=>!kn(R)),{groupedCustomAgents:Q,ungroupedCustomAgents:W}=je.useMemo(()=>{const R={},Y=[];for(const H of B){const X=H;X.group?(R[X.group]||(R[X.group]=[]),R[X.group].push(H)):Y.push(H)}return{groupedCustomAgents:Object.keys(R).sort((H,X)=>H.localeCompare(X)).map(H=>({name:H,agents:R[H]})),ungroupedCustomAgents:Y}},[B]);return t.jsxs("div",{className:de("flex h-full flex-col",N),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),t.jsx(ta,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:T.length})}),t.jsx(J,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:y,children:t.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:T.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[U.length>0&&t.jsxs(t.Fragment,{children:[t.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")}),U.map(R=>t.jsx(sr,{agent:R,isSelected:f===R.name,onSelect:()=>{h(R.name),s?.()},onReset:()=>P(R),onDuplicate:()=>I(R),getAgentModeIcon:O,isMenuOpen:u===R.name,onMenuOpenChange:Y=>S(Y?R.name:null)},R.name))]}),B.length>0&&t.jsxs(t.Fragment,{children:[t.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")}),Q.map(({name:R,agents:Y})=>t.jsx(Ar,{label:R,count:Y.length,storageKey:"agents",children:Y.map(F=>t.jsx(sr,{agent:F,isSelected:f===F.name,onSelect:()=>{h(F.name),s?.()},onRename:()=>v(F),onDelete:()=>b(F),onDuplicate:()=>I(F),getAgentModeIcon:O,isMenuOpen:u===F.name,onMenuOpenChange:H=>S(H?F.name:null)},F.name))},R)),W.map(R=>t.jsx(sr,{agent:R,isSelected:f===R.name,onSelect:()=>{h(R.name),s?.()},onRename:()=>v(R),onDelete:()=>b(R),onDuplicate:()=>I(R),getAgentModeIcon:O,isMenuOpen:u===R.name,onMenuOpenChange:Y=>S(Y?R.name:null)},R.name))]})]})}),t.jsx(Ut,{open:o!==null&&c!==null,onOpenChange:R=>{!R&&!m&&z()},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(qt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),t.jsxs(Yt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:z,disabled:m,children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:M,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx(Ut,{open:n!==null,onOpenChange:R=>!R&&a(null),children:t.jsxs(Bt,{children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(qt,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(it,{value:r,onChange:R=>i(R.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:R=>{R.key==="Enter"&&j()}}),t.jsxs(Yt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:j,children:e("settings.common.actions.rename")})]})]})})]})},sr=s=>{const e=rt.c(52),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,getAgentModeIcon:x,isMenuOpen:m,onMenuOpenChange:p}=s,{t:u}=dt(),S=n;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Qn(),e[0]=f):f=e[0];const g=f,[h,D]=l.useState(!1);let k;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==u?(k=F=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(F,{onClick:H=>{H.stopPropagation(),d()},children:[t.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),t.jsxs(F,{onClick:H=>{H.stopPropagation(),c()},children:[t.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),o&&t.jsxs(F,{onClick:H=>{H.stopPropagation(),o()},children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),i&&t.jsxs(F,{onClick:H=>{H.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=o,e[5]=u,e[6]=k):k=e[6];const w=k,E=a?"bg-interactive-selection":"hover:bg-interactive-hover";let N;e[7]!==E?(N=de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",E),e[7]=E,e[8]=N):N=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=g?void 0:F=>{F.preventDefault(),D(!0)},e[9]=y):y=e[9];let b;e[10]!==N?(b=t.jsx("div",{className:N,onContextMenu:y}),e[10]=N,e[11]=b):b=e[11];let P;e[12]!==n.name?(P=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[12]=n.name,e[13]=P):P=e[13];let z;e[14]!==n.mode||e[15]!==x?(z=x(n.mode),e[14]=n.mode,e[15]=x,e[16]=z):z=e[16];let M;e[17]!==n||e[18]!==S.scope||e[19]!==u?(M=(S.scope||kn(n))&&t.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:kn(n)?u("settings.agents.sidebar.badge.system"):S.scope}),e[17]=n,e[18]=S.scope,e[19]=u,e[20]=M):M=e[20];let I;e[21]!==P||e[22]!==z||e[23]!==M?(I=t.jsxs("div",{className:"flex items-center gap-1.5",children:[P,z,M]}),e[21]=P,e[22]=z,e[23]=M,e[24]=I):I=e[24];let v;e[25]!==n.description?(v=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[25]=n.description,e[26]=v):v=e[26];let j;e[27]!==r||e[28]!==I||e[29]!==v?(j=t.jsxs("button",{onClick:r,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:[I,v]}),e[27]=r,e[28]=I,e[29]=v,e[30]=j):j=e[30];let O;e[31]!==p?(O=F=>{F&&D(!1),p(F)},e[31]=p,e[32]=O):O=e[32];let T;e[33]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(ds,{asChild:!0,children:t.jsx(J,{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:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=T):T=e[33];let U;e[34]!==w?(U=t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:w(js)}),e[34]=w,e[35]=U):U=e[35];let B;e[36]!==m||e[37]!==O||e[38]!==U?(B=t.jsxs(us,{open:m,onOpenChange:O,children:[T,U]}),e[36]=m,e[37]=O,e[38]=U,e[39]=B):B=e[39];let Q;e[40]!==j||e[41]!==B?(Q=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[j,B]}),e[40]=j,e[41]=B,e[42]=Q):Q=e[42];let W;e[43]!==Q||e[44]!==b?(W=t.jsx(tn,{render:b,children:Q}),e[43]=Q,e[44]=b,e[45]=W):W=e[45];let R;e[46]!==w?(R=t.jsx(sn,{className:"w-fit min-w-20",children:w(Ws)}),e[46]=w,e[47]=R):R=e[47];let Y;return e[48]!==h||e[49]!==W||e[50]!==R?(Y=t.jsxs(en,{open:h,onOpenChange:D,children:[W,R]}),e[48]=h,e[49]=W,e[50]=R,e[51]=Y):Y=e[51],Y};function Vi(s,e,n){return Math.min(n,Math.max(e,s))}function Wu(s){if(!Number.isFinite(s))return 0;const e=String(s);if(e.includes("e-")){const[,a]=e.split("e-");return Number(a)||0}const n=e.split(".");return n.length===2?n[1].length:0}function _i(s,e){const n=Wu(e);return n<=0?s:Number(s.toFixed(n))}const xs=je.forwardRef((s,e)=>{const n=rt.c(125);let a,r,i,o,d,c,x,m,p,u,S,f,g;n[0]!==s?({value:g,onValueChange:x,min:p,max:u,step:S,className:a,containerClassName:r,onBlur:d,disabled:i,fallbackValue:o,onClear:c,emptyLabel:f,...m}=s,n[0]=s,n[1]=a,n[2]=r,n[3]=i,n[4]=o,n[5]=d,n[6]=c,n[7]=x,n[8]=m,n[9]=p,n[10]=u,n[11]=S,n[12]=f,n[13]=g):(a=n[1],r=n[2],i=n[3],o=n[4],d=n[5],c=n[6],x=n[7],m=n[8],p=n[9],u=n[10],S=n[11],f=n[12],g=n[13]);const h=p===void 0?-1/0:p,D=u===void 0?1/0:u,k=S===void 0?1:S,w=f===void 0?"—":f,{t:E}=dt();let N;n[14]!==g?(N=()=>g===void 0?"":String(g),n[14]=g,n[15]=N):N=n[15];const[y,b]=je.useState(N),{isMobile:P}=Cs(),z=je.useRef(!1),M=je.useRef(null);let I;n[16]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{if(typeof document>"u"||typeof window>"u")return;M.current?.();const Ae=Oe=>{Oe.preventDefault(),Oe.stopPropagation(),Oe.stopImmediatePropagation?.(),M.current?.()},Pe=window.setTimeout(()=>{M.current?.()},700),Re=()=>{window.clearTimeout(Pe),document.removeEventListener("click",Ae,!0),M.current=null};M.current=Re,document.addEventListener("click",Ae,!0)},n[16]=I):I=n[16];const v=I;let j,O;n[17]===Symbol.for("react.memo_cache_sentinel")?(j=()=>()=>{M.current?.()},O=[],n[17]=j,n[18]=O):(j=n[17],O=n[18]),je.useEffect(j,O);let T,U;n[19]!==g?(U=()=>{b(g===void 0?"":String(g))},T=[g],n[19]=g,n[20]=T,n[21]=U):(T=n[20],U=n[21]),je.useEffect(U,T);let B;e:{if(g!==void 0){B=g;break e}if(o!==void 0){B=o;break e}if(Number.isFinite(h)){B=h;break e}B=0}const Q=B;let W;n[22]!==D||n[23]!==h||n[24]!==x||n[25]!==k?(W=Ae=>{const Pe=Vi(Ae,h,D);x(_i(Pe,k))},n[22]=D,n[23]=h,n[24]=x,n[25]=k,n[26]=W):W=n[26];const R=W;let Y;n[27]!==R||n[28]!==c?(Y=Ae=>{const Pe=Ae.target.value;if(b(Pe),Pe.trim()===""){c?.();return}const Re=Number(Pe);Number.isFinite(Re)&&R(Re)},n[27]=R,n[28]=c,n[29]=Y):Y=n[29];const F=Y;let H;n[30]!==y||n[31]!==D||n[32]!==h||n[33]!==d||n[34]!==c||n[35]!==x||n[36]!==k||n[37]!==g?(H=Ae=>{if(y.trim()===""){c||b(g===void 0?"":String(g)),d?.(Ae);return}const Pe=Number(y);if(!Number.isFinite(Pe))b(g===void 0?"":String(g));else{const Re=Vi(Pe,h,D),Oe=_i(Re,k);Oe!==g&&x(Oe),b(String(Oe))}d?.(Ae)},n[30]=y,n[31]=D,n[32]=h,n[33]=d,n[34]=c,n[35]=x,n[36]=k,n[37]=g,n[38]=H):H=n[38];const X=H,re=!!(i||Q>=D),Z=!!(i||Q<=h);let se;n[39]!==Q||n[40]!==R||n[41]!==Z||n[42]!==k?(se=()=>{Z||R(Q-k)},n[39]=Q,n[40]=R,n[41]=Z,n[42]=k,n[43]=se):se=n[43];const ce=se;let oe;n[44]!==Q||n[45]!==R||n[46]!==re||n[47]!==k?(oe=()=>{re||R(Q+k)},n[44]=Q,n[45]=R,n[46]=re,n[47]=k,n[48]=oe):oe=n[48];const xe=oe;let we;if(n[49]!==a||n[50]!==r||n[51]!==Z||n[52]!==y||n[53]!==w||n[54]!==ce||n[55]!==xe||n[56]!==re||n[57]!==P||n[58]!==E||n[59]!==g){we=Symbol.for("react.early_return_sentinel");e:{const Ae=Re=>Oe=>{Oe.preventDefault(),Oe.stopPropagation(),z.current=!0,v(),Re()},Pe=Re=>Oe=>{if(z.current){z.current=!1,Oe.preventDefault(),Oe.stopPropagation();return}Re()};if(P){let Re;n[61]!==r?(Re=de("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",r),n[61]=r,n[62]=Re):Re=n[62];let Oe;n[63]!==E?(Oe=E("numberInput.actions.decreaseAria"),n[63]=E,n[64]=Oe):Oe=n[64];const $e=Ae(ce),Be=Pe(ce),Le=!Z&&"active:bg-interactive-hover";let Ue;n[65]!==Le?(Ue=de("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",Le),n[65]=Le,n[66]=Ue):Ue=n[66];let le;n[67]===Symbol.for("react.memo_cache_sentinel")?(le=t.jsx(A,{name:"subtract",className:"block h-4 w-4"}),n[67]=le):le=n[67];const q=t.jsx("button",{type:"button","aria-label":Oe,disabled:Z,onTouchStart:$e,onClick:Be,className:Ue,children:le});let me;n[68]!==a?(me=de("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]",a),n[68]=a,n[69]=me):me=n[69];const Ne=g===void 0?w:y;let Ee;n[70]!==me||n[71]!==Ne?(Ee=t.jsx("div",{className:me,"aria-live":"polite",children:Ne}),n[70]=me,n[71]=Ne,n[72]=Ee):Ee=n[72];let Ce;n[73]!==E?(Ce=E("numberInput.actions.increaseAria"),n[73]=E,n[74]=Ce):Ce=n[74];const He=Ae(xe),G=Pe(xe),$=!re&&"active:bg-interactive-hover";let fe;n[75]!==$?(fe=de("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",$),n[75]=$,n[76]=fe):fe=n[76];let L;n[77]===Symbol.for("react.memo_cache_sentinel")?(L=t.jsx(A,{name:"add",className:"block h-4 w-4"}),n[77]=L):L=n[77];const Fe=t.jsx("button",{type:"button","aria-label":Ce,disabled:re,onTouchStart:He,onClick:G,className:fe,children:L});let Je;n[78]!==Re||n[79]!==q||n[80]!==Ee||n[81]!==Fe?(Je=t.jsxs("div",{className:Re,children:[q,Ee,Fe]}),n[78]=Re,n[79]=q,n[80]=Ee,n[81]=Fe,n[82]=Je):Je=n[82],we=Je;break e}}n[49]=a,n[50]=r,n[51]=Z,n[52]=y,n[53]=w,n[54]=ce,n[55]=xe,n[56]=re,n[57]=P,n[58]=E,n[59]=g,n[60]=we}else we=n[60];if(we!==Symbol.for("react.early_return_sentinel"))return we;let he;n[83]!==r?(he=de("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",r),n[83]=r,n[84]=he):he=n[84];let Ie;n[85]!==E?(Ie=E("numberInput.actions.decreaseAria"),n[85]=E,n[86]=Ie):Ie=n[86];let ve;n[87]!==Q||n[88]!==R||n[89]!==k?(ve=()=>R(Q-k),n[87]=Q,n[88]=R,n[89]=k,n[90]=ve):ve=n[90];let be,ye;n[91]===Symbol.for("react.memo_cache_sentinel")?(be=de("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"),ye=t.jsx(A,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=be,n[92]=ye):(be=n[91],ye=n[92]);let te;n[93]!==Z||n[94]!==Ie||n[95]!==ve?(te=t.jsx("button",{type:"button","aria-label":Ie,disabled:Z,onClick:ve,className:be,children:ye}),n[93]=Z,n[94]=Ie,n[95]=ve,n[96]=te):te=n[96];const ie=m.inputMode??"numeric";let ge;n[97]!==a?(ge=de("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",a),n[97]=a,n[98]=ge):ge=n[98];let _;n[99]!==i||n[100]!==y||n[101]!==X||n[102]!==F||n[103]!==m||n[104]!==e||n[105]!==ie||n[106]!==ge?(_=t.jsx("input",{...m,ref:e,type:"text",inputMode:ie,value:y,onChange:F,onBlur:X,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ge}),n[99]=i,n[100]=y,n[101]=X,n[102]=F,n[103]=m,n[104]=e,n[105]=ie,n[106]=ge,n[107]=_):_=n[107];let ee;n[108]!==E?(ee=E("numberInput.actions.increaseAria"),n[108]=E,n[109]=ee):ee=n[109];let ne;n[110]!==Q||n[111]!==R||n[112]!==k?(ne=()=>R(Q+k),n[110]=Q,n[111]=R,n[112]=k,n[113]=ne):ne=n[113];let ue,Me;n[114]===Symbol.for("react.memo_cache_sentinel")?(ue=de("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"),Me=t.jsx(A,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=ue,n[115]=Me):(ue=n[114],Me=n[115]);let ke;n[116]!==re||n[117]!==ee||n[118]!==ne?(ke=t.jsx("button",{type:"button","aria-label":ee,disabled:re,onClick:ne,className:ue,children:Me}),n[116]=re,n[117]=ee,n[118]=ne,n[119]=ke):ke=n[119];let De;return n[120]!==he||n[121]!==te||n[122]!==_||n[123]!==ke?(De=t.jsxs("div",{className:he,children:[te,_,ke]}),n[120]=he,n[121]=te,n[122]=_,n[123]=ke,n[124]=De):De=n[124],De});xs.displayName="NumberInput";const Hi=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Ca=s=>s==="allow"||s==="ask"||s==="deny",dn=(s,e)=>`${s}::${e}`,nn=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&Ca(n.action)&&e.set(dn(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},ca=s=>{const e=new Map;for(const n of nn(s))e.set(dn(n.permission,n.pattern),n);return e},Wi=s=>[...s].sort((e,n)=>{const a=e.permission.localeCompare(n.permission);return a!==0?a:e.pattern.localeCompare(n.pattern)}),qu=(s,e)=>{const n=Wi(nn(s)),a=Wi(nn(e));return n.length!==a.length?!1:n.every((r,i)=>{const o=a[i];return r.permission===o.permission&&r.pattern===o.pattern&&r.action===o.action})},Gu=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",Ju=(s,e)=>nn(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),nr=s=>{if(Array.isArray(s))return nn(s);if(Ca(s))return[{permission:"*",pattern:"*",action:s}];if(!s||typeof s!="object"||Array.isArray(s))return[];const e=[];for(const[n,a]of Object.entries(s))if(n!=="__originalKeys"){if(Ca(a)){e.push({permission:n,pattern:"*",action:a});continue}if(a&&typeof a=="object"&&!Array.isArray(a))for(const[r,i]of Object.entries(a))Ca(i)&&e.push({permission:n,pattern:r,action:i})}return e},Qu=(s,e)=>{const n=nn(e),a={};for(const i of n)(a[i.permission]||={})[i.pattern]=i.action;const r={};for(const[i,o]of Object.entries(a))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){r[i]=o["*"];continue}r[i]=o}return Object.keys(r).length===0?s:(s!=="allow"&&(r["*"]=s),r)},Yu=(s,e)=>{const n=pn(e);if(!n)return[];const r=s.find(i=>i.id===n.providerId)?.models?.find(i=>i.id===n.modelId);return r?.variants?Object.keys(r.variants):[]},Xu=()=>{const{t:s}=dt(),{isMobile:e}=Cs(),n=ut(q=>q.providers),{selectedAgentName:a,getAgentByName:r,createAgent:i,updateAgent:o,agents:d,agentDraft:c,setAgentDraft:x}=Ka(Ss(q=>({selectedAgentName:q.selectedAgentName,getAgentByName:q.getAgentByName,createAgent:q.createAgent,updateAgent:q.updateAgent,agents:q.agents,agentDraft:q.agentDraft,setAgentDraft:q.setAgentDraft}))),m=a?r(a):null,p=!!(c&&c.name===a&&!m),[u,S]=l.useState(""),[f,g]=l.useState("user"),[h,D]=l.useState(""),[k,w]=l.useState("subagent"),[E,N]=l.useState(""),[y,b]=l.useState(""),[P,z]=l.useState(void 0),[M,I]=l.useState(void 0),[v,j]=l.useState(""),[O,T]=l.useState("allow"),[U,B]=l.useState([]),[Q,W]=l.useState([]),[R,Y]=l.useState(""),[F,H]=l.useState("*"),[X,re]=l.useState(!1),[Z,se]=l.useState(!1),ce=l.useRef(null),oe=vs(q=>q.currentDirectory??null),[xe,we]=l.useState([]),he=l.useMemo(()=>Yu(n,E),[E,n]),Ie=he.length>0,ve=l.useMemo(()=>!y||!he.includes(y)?"__default":y,[y,he]),be=Ie&&(!y||he.includes(y)),ye=Nd(q=>q.permission);l.useEffect(()=>{let q=!1;return(async()=>{const Ne=await Ns.listToolIds({directory:oe});if(q)return;const Ee=new Set(["write","patch","multiedit"]),Ce=Ne.map(He=>typeof He=="string"?He.trim():"").filter(Boolean).filter(He=>He!=="*").filter(He=>He!=="invalid").filter(He=>!Ee.has(He));we(Array.from(new Set(Ce)).sort((He,G)=>He.localeCompare(G)))})(),()=>{q=!0}},[oe]);const te=l.useMemo(()=>{const q=new Set;for(const me of d){const Ne=nn(nr(me.permission));for(const Ee of Ne)Ee.permission&&Ee.permission!=="*"&&Ee.permission!=="invalid"&&q.add(Ee.permission)}for(const me of Object.values(ye))for(const Ne of me){const Ee=Ne.permission?.trim();Ee&&Ee!=="invalid"&&q.add(Ee)}for(const me of xe)q.add(me);return Array.from(q).sort((me,Ne)=>me.localeCompare(Ne))},[d,ye,xe]),ie=l.useMemo(()=>ca(U),[U]),ge=l.useMemo(()=>ca(Q),[Q]),_=l.useCallback(q=>ge.get(dn(q,"*"))?.action,[ge]),ee=l.useCallback(q=>Q.filter(me=>me.permission===q&&me.pattern!=="*").sort((me,Ne)=>me.pattern.localeCompare(Ne.pattern)),[Q]),ne=l.useMemo(()=>{const q=new Set;for(const me of Hi)q.add(me);for(const me of te)q.add(me);return Array.from(q).sort((me,Ne)=>me.localeCompare(Ne))},[te]),ue=l.useCallback(q=>{const me=q==="*"?O:_(q)??O,Ne=ee(q),Ee=!1,Ce=Ne.reduce((G,$)=>(G[$.action]=(G[$.action]??0)+1,G),{allow:0,ask:0,deny:0}),He=["allow","ask","deny"].filter(G=>Ce[G]>0).map(G=>`${Ce[G]} ${G}`).join(", ");return{defaultAction:me,patternRulesCount:Ne.length,patternSummary:He,hasDefaultHint:Ee}},[ee,_,O]),Me=l.useCallback(q=>s(q==="allow"?"settings.common.permission.allow":q==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),ke=l.useCallback(q=>q==="global"?s("settings.common.scope.global"):Me(q),[Me,s]),De=l.useMemo(()=>{const q=new Set;for(const me of Hi)q.add(me);for(const me of te)q.add(me);return Array.from(q).sort((me,Ne)=>me.localeCompare(Ne))},[te]),Ae=l.useCallback((q,me,Ne)=>{W(Ee=>{const Ce=ca(Ee);return Ce.set(dn(q,me),{permission:q,pattern:me,action:Ne}),Array.from(Ce.values())})},[]),Pe=l.useCallback((q,me)=>{W(Ne=>{const Ee=ca(Ne);return Ee.delete(dn(q,me)),Array.from(Ee.values())})},[]),Re=l.useCallback((q,me)=>{const Ne=ie.get(dn(q,me));if(Ne){Ae(q,me,Ne.action);return}Pe(q,me)},[ie,Pe,Ae]),Oe=l.useCallback((q,me,Ne)=>{Ae(q,me,Ne)},[Ae]),$e=l.useCallback(q=>{T(q),W(me=>me.filter(Ne=>!(Ne.pattern==="*"&&Ne.action===q)))},[]),Be=l.useCallback(q=>{const me=R.trim();if(!me){V.error(s("settings.agents.page.toast.permissionNameRequired"));return}const Ne=F.trim()||"*";if(me==="*"&&Ne==="*"){$e(q),Y(""),H("*");return}Ne==="*"&&me!=="*"&&q===O?Pe(me,"*"):Ae(me,Ne,q),Y(""),H("*")},[O,R,F,Pe,$e,s,Ae]),Le=l.useCallback(q=>q==="*"?s("settings.agents.page.permissions.defaultLabel"):q==="webfetch"?"WebFetch":q==="websearch"?"WebSearch":q==="codesearch"?"CodeSearch":q==="doom_loop"?"Doom Loop":q==="external_directory"?"External Directory":q==="todowrite"?"TodoWrite":q==="todoread"?"TodoRead":q.split(/[_-]+/g).filter(Boolean).map(me=>me.charAt(0).toUpperCase()+me.slice(1)).join(" "),[s]);l.useEffect(()=>{Y(""),H("*");const q=me=>{const Ne=nn(me),Ee=Gu(Ne),Ce=Ju(Ne,Ee);return T(Ee),B(Ce),W(Ce),{global:Ee,rules:Ce}};if(p&&c){const me=c.name||"",Ne=c.scope||"user",Ee=c.description||"",Ce=c.mode||"subagent",He=c.model||"",G=c.variant||"",$=c.temperature??void 0,fe=c.top_p??void 0,L=c.prompt||"";S(me),g(Ne),D(Ee),w(Ce),N(He),b(G),z($),I(fe),j(L);const Fe=nr(c.permission),Je=q(Fe);ce.current={draftName:me,draftScope:Ne,description:Ee,mode:Ce,model:He,variant:G,temperature:$,topP:fe,prompt:L,globalPermission:Je.global,permissionRules:Je.rules};return}if(m&&a===m.name){const me=m.description||"",Ne=m.mode||"subagent",Ee=m.model?.providerID&&m.model?.modelID?`${m.model.providerID}/${m.model.modelID}`:"",Ce=m.variant||"",He=m.temperature,G=m.topP,$=m.prompt||"";D(me),w(Ne),N(Ee),b(Ce),z(He),I(G),j($);const fe=q(nr(m.permission));ce.current={draftName:"",draftScope:"user",description:me,mode:Ne,model:Ee,variant:Ce,temperature:He,topP:G,prompt:$,globalPermission:fe.global,permissionRules:fe.rules}}},[c,p,m,a]);const Ue=l.useMemo(()=>{const q=ce.current;return q?!!(p&&(u!==q.draftName||f!==q.draftScope)||h!==q.description||k!==q.mode||E!==q.model||y!==q.variant||P!==q.temperature||M!==q.topP||v!==q.prompt||O!==q.globalPermission||!qu(Q,q.permissionRules)):!1},[h,u,f,O,p,k,E,Q,v,P,M,y]),le=async()=>{const q=p?u.trim().replace(/\s+/g,"-"):a?.trim();if(!q){V.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(p&&d.some(me=>me.name===q)){V.error(s("settings.agents.sidebar.toast.agentExists"));return}se(!0);try{const me=E.trim(),Ne=y.trim(),Ee=v.trim(),Ce=Qu(O,Q),He={name:q,description:h.trim()||void 0,mode:k,model:me===""?null:me,variant:Ne===""?null:Ne||void 0,temperature:P??null,top_p:M??null,prompt:Ee||(p?void 0:null),permission:Ce,scope:p?f:void 0};let G;p?(G=await i(He),G.ok&&x(null)):G=await o(q,He),G.ok?G.requiresManualRestart?V.warning(s("settings.agents.page.toast.savedManualRestart")):V.success(s(p?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):V.error(s(p?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(me){console.error("Error saving agent:",me);const Ne=me instanceof Error&&me.message?me.message:s("settings.agents.page.toast.saveUnexpectedError");V.error(Ne)}finally{se(!1)}};return a?t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p?s("settings.agents.page.title.new"):a}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(p?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.identityRole")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&t.jsxs("div",{"data-settings-item":"agents.name",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.agentName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),t.jsx(it,{value:u,onChange:q=>S(q.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Ft,{value:f,onValueChange:q=>g(q),children:[t.jsx(Ot,{className:"w-fit min-w-[100px]",children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ht,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(ps,{value:h,onChange:q=>D(q.target.value),placeholder:s("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),t.jsx("div",{"data-settings-item":"agents.mode",className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.mode")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.modeTooltip")})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":k==="primary",onClick:()=>w("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":k==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":k==="all",onClick:()=>w("all"),className:"!font-normal",children:s("settings.agents.page.mode.all")})]})]})})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.modelParameters")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{"data-settings-item":"agents.model",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(_r,{providerId:pn(E)?.providerId??"",modelId:pn(E)?.modelId??"",onChange:(q,me)=>{N(q&&me?`${q}/${me}`:""),b("")}})})]}),t.jsxs("div",{"data-settings-item":"agents.variant",className:de("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:de("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.variant")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.variantTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.variantHint")})]}),t.jsx("div",{className:de("flex items-center gap-2",e?"w-full":"w-fit"),children:be?t.jsxs(Ft,{value:ve,onValueChange:q=>b(q==="__default"?"":q),children:[t.jsx(Ot,{className:de("max-w-full",e?"w-full":"w-fit min-w-[10rem]"),children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.variantPlaceholder"),children:q=>q==="__default"?s("chat.modelControls.default"):q})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"__default",children:s("chat.modelControls.default")}),he.map(q=>t.jsx(ht,{value:q,children:q},q))]})]}):t.jsxs(t.Fragment,{children:[t.jsx(it,{value:y,onChange:q=>b(q.target.value),placeholder:s("settings.agents.page.field.variantPlaceholder"),disabled:!E&&!y,className:de("h-7 w-40",e&&"w-full")}),y&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>b(""),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.common.actions.clear"),title:s("settings.common.actions.clear"),children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})})]}),t.jsxs("div",{"data-settings-item":"agents.temperature",className:de("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:de("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.temperature")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.temperatureTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.temperatureRange")})]}),t.jsxs("div",{className:de("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(xs,{value:P,fallbackValue:.7,onValueChange:z,onClear:()=>z(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),P!==void 0&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>z(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTemperatureAria"),title:s("settings.common.actions.clear"),children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{"data-settings-item":"agents.top-p",className:de("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:de("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.topP")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.topPTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.topPRange")})]}),t.jsxs("div",{className:de("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(xs,{value:M,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),M!==void 0&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTopPAria"),title:s("settings.common.actions.clear"),children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),t.jsxs("div",{"data-settings-item":"agents.system-prompt",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.systemPrompt")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(ps,{value:v,onChange:q=>j(q.target.value),placeholder:s("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),t.jsxs("div",{"data-settings-item":"agents.permissions",className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.toolPermissions")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>re(q=>!q),children:s(X?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),X?t.jsxs("div",{className:"space-y-6 px-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.permissions.globalDefault")}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),t.jsxs(Ft,{value:O,onValueChange:q=>$e(q),children:[t.jsx(Ot,{className:"w-[100px]",children:t.jsx(Kt,{children:Me(O)})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ht,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ht,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:ne.filter(q=>q!=="*").map(q=>{const me=Le(q),{defaultAction:Ne,patternRulesCount:Ee}=ue(q),Ce=_(q),He=Ce??"global",G=ee(q),$=["allow","ask","deny"].filter(fe=>fe!==O);return t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[t.jsxs("div",{className:"flex items-center justify-between py-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:me}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:q})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Ee>0?s("settings.agents.page.permissions.globalSummary",{summary:Ne}):Ne})]}),t.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Ce&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>Re(q,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Ft,{value:He,onValueChange:fe=>{if(fe==="global"){Pe(q,"*");return}Ae(q,"*",fe)},children:[t.jsx(Ot,{className:"w-[90px]",children:t.jsx(Kt,{children:ke(He)})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"global",children:s("settings.common.scope.global")}),$.map(fe=>t.jsx(ht,{value:fe,className:"capitalize",children:Me(fe)},fe))]})]})]}),G.map(fe=>{const L=dn(fe.permission,fe.pattern),Fe=ie.get(L),Je=!Fe,Xe=!!(Fe&&Fe.action!==fe.action);return t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:fe.pattern}),Je&&t.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:s("settings.common.badge.new")}),Xe&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:s("settings.common.badge.modified")}),(Je||Xe)&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>Je?Pe(fe.permission,fe.pattern):Re(fe.permission,fe.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Ft,{value:fe.action,onValueChange:et=>Oe(fe.permission,fe.pattern,et),children:[t.jsx(Ot,{className:"w-[90px]",children:t.jsx(Kt,{children:Me(fe.action)})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ht,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ht,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},L)})]})]},q)})}),t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[t.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:s("settings.agents.page.permissions.addCustomRule")}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[t.jsxs(Ft,{value:R,onValueChange:Y,children:[t.jsx(Ot,{className:"w-full sm:w-[160px]",children:R?t.jsx("span",{className:"truncate",children:Le(R)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Lt,{children:De.map(q=>t.jsx(ht,{value:q,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:Le(q)})})},q))})]}),t.jsx(it,{value:F,onChange:q=>H(q.target.value),placeholder:s("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Be("allow"),children:s("settings.common.permission.allow")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Be("ask"),children:s("settings.common.permission.ask")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Be("deny"),children:s("settings.common.permission.deny")})]})]})]})]}):t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ne.map((q,me)=>{const{defaultAction:Ne,patternRulesCount:Ee,patternSummary:Ce,hasDefaultHint:He}=ue(q),G=Le(q),$=He?`${Ne} (env blocked)`:Ne;return t.jsxs("div",{className:de("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",me>0&&"border-t border-[var(--surface-subtle)]"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:G}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:q})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Ee>0?t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.globalSummary",{summary:$})}):t.jsx("span",{className:de("typography-micro capitalize px-1.5 py-0.5 rounded",$==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":$==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:$}),Ee>0&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.rulesSummary",{summary:Ce})})]})]},q)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:le,disabled:Z||!Ue,size:"xs",className:"!font-normal",children:s(Z?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.agents.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.agents.page.empty.description")})]})})},Zu="~/.config/opencode/AGENTS.md",El=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},ep=s=>s.length>0&&!s.endsWith(`
2
- `)?`${s}
3
- `:s,da={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},tp=(s,e)=>s==="custom"?e:Sd(s),sp=s=>s==="custom"?"custom":hl(s)?s:"concise",qi={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"},Gi=async(s,e)=>{const n=await jt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(s)});if(!n.ok)throw new Error(await El(n,e))},np=()=>{const{t:s}=dt(),[e,n]=l.useState(""),[a,r]=l.useState(da.responseStyleEnabled),[i,o]=l.useState(da.responseStylePreset),[d,c]=l.useState(da.responseStyleCustomInstructions),[x,m]=l.useState(!0),[p,u]=l.useState(!1),[S,f]=l.useState(""),g=l.useRef(null);l.useEffect(()=>{const w=new AbortController;return(async()=>{try{const[N,y]=await Promise.all([jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:w.signal}),jt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:w.signal})]);let b=da;if(N.ok){const P=await N.json();b={...b,responseStyleEnabled:P.responseStyleEnabled===!0,responseStylePreset:sp(P.responseStylePreset),responseStyleCustomInstructions:typeof P.responseStyleCustomInstructions=="string"?P.responseStyleCustomInstructions:""},typeof P.globalBehaviorPrompt=="string"&&(b={...b,prompt:P.globalBehaviorPrompt})}if(!b.prompt.trim()&&y.ok){const P=await y.json();typeof P.content=="string"&&(b={...b,prompt:P.content})}n(b.prompt),r(b.responseStyleEnabled),o(b.responseStylePreset),c(b.responseStyleCustomInstructions),f(b.prompt),g.current={enabled:b.responseStyleEnabled,preset:b.responseStylePreset,custom:b.responseStyleCustomInstructions}}catch(N){N.name!=="AbortError"&&console.warn("Failed to load behavior settings:",N)}finally{m(!1)}})(),()=>w.abort()},[]),l.useEffect(()=>{if(x)return;const w=g.current;if(w&&w.enabled===a&&w.preset===i&&w.custom===d)return;const E={enabled:a,preset:i,custom:d},N=setTimeout(async()=>{try{await Gi({responseStyleEnabled:E.enabled,responseStylePreset:E.preset,responseStyleCustomInstructions:E.custom},s("settings.behavior.page.toast.saveFailed")),g.current=E}catch(y){const b=y instanceof Error?y.message:s("settings.behavior.page.toast.saveFailed");V.error(b)}},400);return()=>clearTimeout(N)},[a,i,d,x,s]);const h=tp(i,d),D=e!==S,k=async()=>{u(!0);try{const w=ep(e),E=await jt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:w})});if(!E.ok)throw new Error(await El(E,s("settings.behavior.page.toast.saveFailed")));await Gi({globalBehaviorPrompt:w},s("settings.behavior.page.toast.saveFailed")),n(w),f(w),V.success(s("settings.behavior.page.toast.saved"))}catch(w){console.error("Failed to save behavior:",w);const E=w instanceof Error?w.message:s("settings.behavior.page.toast.saveFailed");V.error(E)}finally{u(!1)}};return t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8 space-y-6",children:[t.jsx("div",{className:"space-y-1",children:t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.behavior.page.title")})}),t.jsxs("div",{"data-settings-item":"behavior.system-prompt",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.systemPrompt")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"font-medium text-foreground",children:s("settings.behavior.page.warning.title")}),t.jsx("p",{children:s("settings.behavior.page.warning.description",{path:Zu})})]})})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsx(ps,{value:e,onChange:w=>n(w.target.value),placeholder:s("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:x,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),t.jsx(J,{onClick:k,disabled:p||!D||x,size:"xs",className:"!font-normal",children:s(p?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),t.jsxs("div",{"data-settings-item":"behavior.response-style",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.responseStyle")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.behavior.page.responseStyle.tooltip")})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[t.jsx(Pt,{checked:a,onChange:r,disabled:x,ariaLabel:s("settings.behavior.page.responseStyle.enableAria")}),s("settings.behavior.page.responseStyle.enable")]}),t.jsxs(Ft,{value:i,onValueChange:w=>o(w),disabled:x||!a,children:[t.jsx(Ot,{className:"w-full sm:w-56",size:"lg",children:t.jsx(Kt,{children:w=>w==="custom"?s("settings.behavior.page.responseStyle.option.custom"):hl(w)?s(qi[w]):null})}),t.jsxs(Lt,{children:[kd.map(w=>t.jsx(ht,{value:w,children:s(qi[w])},w)),t.jsx(ht,{value:"custom",children:s("settings.behavior.page.responseStyle.option.custom")})]})]}),t.jsx(ps,{value:h,onChange:w=>c(w.target.value),placeholder:s("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:x||!a||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},ap=s=>{const e=rt.c(169),{onItemSelect:n}=s,{t:a}=dt(),[r,i]=l.useState(null),[o,d]=l.useState(""),[c,x]=l.useState(null),[m,p]=l.useState(null),[u,S]=l.useState(!1),[f,g]=l.useState(null),{selectedCommandName:h,commands:D,setSelectedCommand:k,setCommandDraft:w,createCommand:E,deleteCommand:N,loadCommands:y}=$a(Ss(rp)),b=_s(ip),P=_s(op);let z,M;e[0]!==y||e[1]!==P?(z=()=>{y(),P()},M=[y,P],e[0]=y,e[1]=P,e[2]=z,e[3]=M):(z=e[2],M=e[3]),l.useEffect(z,M);let I;e[4]!==b?(I=new Set(b.map(lp)),e[4]=b,e[5]=I):I=e[5];const v=I;let j;if(e[6]!==D||e[7]!==v){let pe;e[9]!==v?(pe=st=>!v.has(st.name),e[9]=v,e[10]=pe):pe=e[10],j=D.filter(pe),e[6]=D,e[7]=v,e[8]=j}else j=e[8];const O=j;let T,U;e[11]!==h||e[12]!==k||e[13]!==v?(T=()=>{h&&v.has(h)&&k(null)},U=[h,k,v],e[11]=h,e[12]=k,e[13]=v,e[14]=T,e[15]=U):(T=e[14],U=e[15]),l.useEffect(T,U);let B;e[16]!==D||e[17]!==n||e[18]!==w||e[19]!==k?(B=()=>{let pe="new-command",st=1;for(;D.some(nt=>nt.name===pe);)pe=`new-command-${st}`,st++;w({name:pe,scope:"user"}),k(pe),n?.()},e[16]=D,e[17]=n,e[18]=w,e[19]=k,e[20]=B):B=e[20];const Q=B;let W;e[21]!==a?(W=async pe=>{if(Dn(pe)){V.error(a("settings.commands.sidebar.toast.builtInCannotDelete"));return}x(pe),p("delete")},e[21]=a,e[22]=W):W=e[22];const R=W;let Y;e[23]===Symbol.for("react.memo_cache_sentinel")?(Y=async pe=>{Dn(pe)&&(x(pe),p("reset"))},e[23]=Y):Y=e[23];const F=Y;let H;e[24]===Symbol.for("react.memo_cache_sentinel")?(H=()=>{x(null),p(null)},e[24]=H):H=e[24];const X=H;let re;e[25]!==c||e[26]!==m||e[27]!==N||e[28]!==a?(re=async()=>{if(!c||!m)return;S(!0),await N(c.name)?(m==="delete"?V.success(a("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):V.success(a("settings.commands.sidebar.toast.commandReset",{name:c.name})),X()):m==="delete"?V.error(a("settings.commands.sidebar.toast.deleteFailed")):V.error(a("settings.commands.sidebar.toast.resetFailed")),S(!1)},e[25]=c,e[26]=m,e[27]=N,e[28]=a,e[29]=re):re=e[29];const Z=re;let se;e[30]!==D||e[31]!==w||e[32]!==k?(se=pe=>{const st=pe.name;let nt=1,Ge=`${st}-copy`;for(;D.some(ft=>ft.name===Ge);)nt++,Ge=`${st}-copy-${nt}`;w({name:Ge,scope:pe.scope||"user",description:pe.description,template:pe.template,agent:pe.agent,model:pe.model}),k(Ge)},e[30]=D,e[31]=w,e[32]=k,e[33]=se):se=e[33];const ce=se;let oe;e[34]===Symbol.for("react.memo_cache_sentinel")?(oe=pe=>{d(pe.name),i(pe)},e[34]=oe):oe=e[34];const xe=oe;let we;e[35]!==D||e[36]!==E||e[37]!==N||e[38]!==r||e[39]!==o||e[40]!==k||e[41]!==a?(we=async()=>{if(!r)return;const pe=o.trim().replace(/\s+/g,"-");if(!pe){V.error(a("settings.commands.sidebar.toast.commandNameRequired"));return}if(pe===r.name){i(null);return}if(D.some(nt=>nt.name===pe)){V.error(a("settings.commands.sidebar.toast.commandExists"));return}await E({name:pe,description:r.description,template:r.template,agent:r.agent,model:r.model})?await N(r.name)?(V.success(`Command renamed to "${pe}"`),k(pe)):V.error(a("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):V.error(a("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=D,e[36]=E,e[37]=N,e[38]=r,e[39]=o,e[40]=k,e[41]=a,e[42]=we):we=e[42];const he=we;let Ie,ve,be,ye,te,ie;if(e[43]!==O||e[44]!==Q||e[45]!==R||e[46]!==ce||e[47]!==n||e[48]!==f||e[49]!==h||e[50]!==k||e[51]!==a){const pe=O.filter(Dn),st=O.filter(cp);e[58]===Symbol.for("react.memo_cache_sentinel")?(te=de("flex h-full flex-col","bg-background"),e[58]=te):te=e[58];let nt;e[59]!==a?(nt=a("settings.commands.sidebar.title"),e[59]=a,e[60]=nt):nt=e[60];let Ge;e[61]!==nt?(Ge=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:nt}),e[61]=nt,e[62]=Ge):Ge=e[62];let ft;e[63]===Symbol.for("react.memo_cache_sentinel")?(ft=t.jsx(ta,{className:"mb-3"}),e[63]=ft):ft=e[63];let wt;e[64]!==O.length||e[65]!==a?(wt=a("settings.commands.sidebar.total",{count:O.length}),e[64]=O.length,e[65]=a,e[66]=wt):wt=e[66];let Ct;e[67]!==wt?(Ct=t.jsx("span",{className:"typography-meta text-muted-foreground",children:wt}),e[67]=wt,e[68]=Ct):Ct=e[68];let ae;e[69]===Symbol.for("react.memo_cache_sentinel")?(ae=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[69]=ae):ae=e[69];let Ve;e[70]!==Q?(Ve=t.jsx(J,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,children:ae}),e[70]=Q,e[71]=Ve):Ve=e[71];let tt;e[72]!==Ct||e[73]!==Ve?(tt=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ct,Ve]}),e[72]=Ct,e[73]=Ve,e[74]=tt):tt=e[74],e[75]!==Ge||e[76]!==tt?(ie=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Ge,ft,tt]}),e[75]=Ge,e[76]=tt,e[77]=ie):ie=e[77],Ie=Jt,ve="flex-1 min-h-0",be="space-y-1 px-3 py-2",ye=O.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.commands.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.commands.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[pe.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.commands.sidebar.section.builtIn")}),[...pe].sort(dp).map(Ye=>t.jsx(Ji,{command:Ye,isSelected:h===Ye.name,onSelect:()=>{k(Ye.name),n?.()},onReset:()=>F(Ye),onDuplicate:()=>ce(Ye),isMenuOpen:f===Ye.name,onMenuOpenChange:bt=>g(bt?Ye.name:null)},Ye.name))]}),st.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.commands.sidebar.section.custom")}),[...st].sort(mp).map(Ye=>t.jsx(Ji,{command:Ye,isSelected:h===Ye.name,onSelect:()=>{k(Ye.name),n?.()},onRename:()=>xe(Ye),onDelete:()=>R(Ye),onDuplicate:()=>ce(Ye),isMenuOpen:f===Ye.name,onMenuOpenChange:bt=>g(bt?Ye.name:null)},Ye.name))]})]}),e[43]=O,e[44]=Q,e[45]=R,e[46]=ce,e[47]=n,e[48]=f,e[49]=h,e[50]=k,e[51]=a,e[52]=Ie,e[53]=ve,e[54]=be,e[55]=ye,e[56]=te,e[57]=ie}else Ie=e[52],ve=e[53],be=e[54],ye=e[55],te=e[56],ie=e[57];let ge;e[78]!==Ie||e[79]!==ve||e[80]!==be||e[81]!==ye?(ge=t.jsx(Ie,{outerClassName:ve,className:be,children:ye}),e[78]=Ie,e[79]=ve,e[80]=be,e[81]=ye,e[82]=ge):ge=e[82];const _=c!==null&&m!==null;let ee;e[83]!==u?(ee=pe=>{!pe&&!u&&X()},e[83]=u,e[84]=ee):ee=e[84];let ne;e[85]!==m||e[86]!==a?(ne=a(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=a,e[87]=ne):ne=e[87];let ue;e[88]!==ne?(ue=t.jsx(Vt,{children:ne}),e[88]=ne,e[89]=ue):ue=e[89];let Me;e[90]!==c?.name||e[91]!==m||e[92]!==a?(Me=m==="delete"?a("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):a("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[90]=c?.name,e[91]=m,e[92]=a,e[93]=Me):Me=e[93];let ke;e[94]!==Me?(ke=t.jsx(qt,{children:Me}),e[94]=Me,e[95]=ke):ke=e[95];let De;e[96]!==ue||e[97]!==ke?(De=t.jsxs(_t,{children:[ue,ke]}),e[96]=ue,e[97]=ke,e[98]=De):De=e[98];let Ae;e[99]!==a?(Ae=a("settings.common.actions.cancel"),e[99]=a,e[100]=Ae):Ae=e[100];let Pe;e[101]!==u||e[102]!==Ae?(Pe=t.jsx(J,{size:"sm",variant:"ghost",onClick:X,disabled:u,children:Ae}),e[101]=u,e[102]=Ae,e[103]=Pe):Pe=e[103];let Re;e[104]!==m||e[105]!==a?(Re=a(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=a,e[106]=Re):Re=e[106];let Oe;e[107]!==Z||e[108]!==u||e[109]!==Re?(Oe=t.jsx(J,{size:"sm",onClick:Z,disabled:u,children:Re}),e[107]=Z,e[108]=u,e[109]=Re,e[110]=Oe):Oe=e[110];let $e;e[111]!==Pe||e[112]!==Oe?($e=t.jsxs(Yt,{children:[Pe,Oe]}),e[111]=Pe,e[112]=Oe,e[113]=$e):$e=e[113];let Be;e[114]!==De||e[115]!==$e?(Be=t.jsxs(Bt,{className:"max-w-md",children:[De,$e]}),e[114]=De,e[115]=$e,e[116]=Be):Be=e[116];let Le;e[117]!==_||e[118]!==ee||e[119]!==Be?(Le=t.jsx(Ut,{open:_,onOpenChange:ee,children:Be}),e[117]=_,e[118]=ee,e[119]=Be,e[120]=Le):Le=e[120];const Ue=r!==null;let le;e[121]===Symbol.for("react.memo_cache_sentinel")?(le=pe=>!pe&&i(null),e[121]=le):le=e[121];let q;e[122]!==a?(q=a("settings.commands.sidebar.renameDialog.title"),e[122]=a,e[123]=q):q=e[123];let me;e[124]!==q?(me=t.jsx(Vt,{children:q}),e[124]=q,e[125]=me):me=e[125];const Ne=r?.name??"";let Ee;e[126]!==a||e[127]!==Ne?(Ee=a("settings.commands.sidebar.renameDialog.description",{name:Ne}),e[126]=a,e[127]=Ne,e[128]=Ee):Ee=e[128];let Ce;e[129]!==Ee?(Ce=t.jsx(qt,{children:Ee}),e[129]=Ee,e[130]=Ce):Ce=e[130];let He;e[131]!==me||e[132]!==Ce?(He=t.jsxs(_t,{children:[me,Ce]}),e[131]=me,e[132]=Ce,e[133]=He):He=e[133];let G;e[134]===Symbol.for("react.memo_cache_sentinel")?(G=pe=>d(pe.target.value),e[134]=G):G=e[134];let $;e[135]!==a?($=a("settings.commands.sidebar.renameDialog.placeholder"),e[135]=a,e[136]=$):$=e[136];let fe;e[137]!==he?(fe=pe=>{pe.key==="Enter"&&he()},e[137]=he,e[138]=fe):fe=e[138];let L;e[139]!==o||e[140]!==$||e[141]!==fe?(L=t.jsx(it,{value:o,onChange:G,placeholder:$,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:fe}),e[139]=o,e[140]=$,e[141]=fe,e[142]=L):L=e[142];let Fe;e[143]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>i(null),e[143]=Fe):Fe=e[143];let Je;e[144]!==a?(Je=a("settings.common.actions.cancel"),e[144]=a,e[145]=Je):Je=e[145];let Xe;e[146]!==Je?(Xe=t.jsx(J,{size:"sm",variant:"ghost",onClick:Fe,children:Je}),e[146]=Je,e[147]=Xe):Xe=e[147];let et;e[148]!==a?(et=a("settings.common.actions.rename"),e[148]=a,e[149]=et):et=e[149];let at;e[150]!==he||e[151]!==et?(at=t.jsx(J,{size:"sm",onClick:he,children:et}),e[150]=he,e[151]=et,e[152]=at):at=e[152];let lt;e[153]!==Xe||e[154]!==at?(lt=t.jsxs(Yt,{children:[Xe,at]}),e[153]=Xe,e[154]=at,e[155]=lt):lt=e[155];let Ze;e[156]!==He||e[157]!==L||e[158]!==lt?(Ze=t.jsxs(Bt,{children:[He,L,lt]}),e[156]=He,e[157]=L,e[158]=lt,e[159]=Ze):Ze=e[159];let We;e[160]!==Ue||e[161]!==Ze?(We=t.jsx(Ut,{open:Ue,onOpenChange:le,children:Ze}),e[160]=Ue,e[161]=Ze,e[162]=We):We=e[162];let pt;return e[163]!==te||e[164]!==ie||e[165]!==ge||e[166]!==Le||e[167]!==We?(pt=t.jsxs("div",{className:te,children:[ie,ge,Le,We]}),e[163]=te,e[164]=ie,e[165]=ge,e[166]=Le,e[167]=We,e[168]=pt):pt=e[168],pt},Ji=s=>{const e=rt.c(47),{command:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,isMenuOpen:x,onMenuOpenChange:m}=s,{t:p}=dt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Qn(),e[0]=u):u=e[0];const S=u,[f,g]=l.useState(!1);let h;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==p?(h=W=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(W,{onClick:R=>{R.stopPropagation(),d()},children:[t.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),t.jsxs(W,{onClick:R=>{R.stopPropagation(),c()},children:[t.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),o&&t.jsxs(W,{onClick:R=>{R.stopPropagation(),o()},children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),i&&t.jsxs(W,{onClick:R=>{R.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=o,e[5]=p,e[6]=h):h=e[6];const D=h,k=a?"bg-interactive-selection":"hover:bg-interactive-hover";let w;e[7]!==k?(w=de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",k),e[7]=k,e[8]=w):w=e[8];let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=S?void 0:W=>{W.preventDefault(),g(!0)},e[9]=E):E=e[9];let N;e[10]!==w?(N=t.jsx("div",{className:w,onContextMenu:E}),e[10]=w,e[11]=N):N=e[11];let y;e[12]!==n.name?(y=t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[12]=n.name,e[13]=y):y=e[13];let b;e[14]!==n||e[15]!==p?(b=(n.scope||Dn(n))&&t.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:Dn(n)?p("settings.agents.sidebar.badge.system"):n.scope}),e[14]=n,e[15]=p,e[16]=b):b=e[16];let P;e[17]!==y||e[18]!==b?(P=t.jsxs("div",{className:"flex items-center gap-2",children:[y,b]}),e[17]=y,e[18]=b,e[19]=P):P=e[19];let z;e[20]!==n.description?(z=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[20]=n.description,e[21]=z):z=e[21];let M;e[22]!==r||e[23]!==z||e[24]!==P?(M=t.jsxs("button",{onClick:r,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:[P,z]}),e[22]=r,e[23]=z,e[24]=P,e[25]=M):M=e[25];let I;e[26]!==m?(I=W=>{W&&g(!1),m(W)},e[26]=m,e[27]=I):I=e[27];let v;e[28]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(ds,{asChild:!0,children:t.jsx(J,{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:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=v):v=e[28];let j;e[29]!==D?(j=t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:D(js)}),e[29]=D,e[30]=j):j=e[30];let O;e[31]!==x||e[32]!==I||e[33]!==j?(O=t.jsxs(us,{open:x,onOpenChange:I,children:[v,j]}),e[31]=x,e[32]=I,e[33]=j,e[34]=O):O=e[34];let T;e[35]!==M||e[36]!==O?(T=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[M,O]}),e[35]=M,e[36]=O,e[37]=T):T=e[37];let U;e[38]!==T||e[39]!==N?(U=t.jsx(tn,{render:N,children:T}),e[38]=T,e[39]=N,e[40]=U):U=e[40];let B;e[41]!==D?(B=t.jsx(sn,{className:"w-fit min-w-20",children:D(Ws)}),e[41]=D,e[42]=B):B=e[42];let Q;return e[43]!==f||e[44]!==U||e[45]!==B?(Q=t.jsxs(en,{open:f,onOpenChange:g,children:[U,B]}),e[43]=f,e[44]=U,e[45]=B,e[46]=Q):Q=e[46],Q};function rp(s){return{selectedCommandName:s.selectedCommandName,commands:s.commands,setSelectedCommand:s.setSelectedCommand,setCommandDraft:s.setCommandDraft,createCommand:s.createCommand,deleteCommand:s.deleteCommand,loadCommands:s.loadCommands}}function ip(s){return s.skills}function op(s){return s.loadSkills}function lp(s){return s.name}function cp(s){return!Dn(s)}function dp(s,e){return s.name.localeCompare(e.name)}function mp(s,e){return s.name.localeCompare(e.name)}const up=()=>{const{t:s}=dt(),{selectedCommandName:e,getCommandByName:n,createCommand:a,updateCommand:r,commands:i,commandDraft:o,setCommandDraft:d}=$a(Ss(I=>({selectedCommandName:I.selectedCommandName,getCommandByName:I.getCommandByName,createCommand:I.createCommand,updateCommand:I.updateCommand,commands:I.commands,commandDraft:I.commandDraft,setCommandDraft:I.setCommandDraft}))),c=e?n(e):null,x=!!(o&&o.name===e&&!c),[m,p]=l.useState(""),[u,S]=l.useState("user"),[f,g]=l.useState(""),[h,D]=l.useState(""),[k,w]=l.useState(""),[E,N]=l.useState(""),[y,b]=l.useState(!1),P=l.useRef(null);l.useEffect(()=>{if(x&&o){const I=o.name||"",v=o.scope||"user",j=o.description||"",O=o.agent||"",T=o.model||"",U=o.template||"";p(I),S(v),g(j),D(O),w(T),N(U),P.current={draftName:I,draftScope:v,description:j,agent:O,model:T,template:U}}else if(c){const I=c.description||"",v=c.agent||"",j=c.model||"",O=c.template||"";g(I),D(v),w(j),N(O),P.current={draftName:"",draftScope:"user",description:I,agent:v,model:j,template:O}}},[c,x,e,i,o]);const z=l.useMemo(()=>{const I=P.current;return I?!!(x&&(m!==I.draftName||u!==I.draftScope)||f!==I.description||h!==I.agent||k!==I.model||E!==I.template):!1},[h,f,m,u,x,k,E]),M=async()=>{const I=x?m.trim().replace(/\s+/g,"-"):e?.trim();if(!I){V.error(s("settings.commands.sidebar.toast.commandNameRequired"));return}if(!E.trim()){V.error(s("settings.commands.page.toast.templateRequired"));return}if(x&&i.some(v=>v.name===I)){V.error(s("settings.commands.sidebar.toast.commandExists"));return}b(!0);try{const v=h.trim(),j=k.trim(),O=E.trim(),T={name:I,description:f.trim()||void 0,agent:v===""?null:v,model:j===""?null:j,template:O,scope:x?u:void 0};let U;x?(U=await a(T),U&&d(null)):U=await r(I,T),U?V.success(s(x?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):V.error(s(x?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(v){console.error("Error saving command:",v),V.error(s("settings.commands.page.toast.saveUnexpectedError"))}finally{b(!1)}};return e?t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:x?s("settings.commands.page.title.new"):`/${e}`}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(x?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.identity")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[x&&t.jsxs("div",{"data-settings-item":"commands.name",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.commands.page.field.commandName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),t.jsx(it,{value:m,onChange:I=>p(I.target.value),placeholder:s("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Ft,{value:u,onValueChange:I=>S(I),children:[t.jsx(Ot,{className:"w-fit min-w-[100px]",children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ht,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(ps,{value:f,onChange:I=>g(I.target.value),placeholder:s("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.executionContext")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{"data-settings-item":"commands.agent",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.commands.page.field.overrideAgent")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(fl,{agentName:h,onChange:I=>D(I)})})]}),t.jsxs("div",{"data-settings-item":"commands.model",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(_r,{providerId:pn(k)?.providerId??"",modelId:pn(k)?.modelId??"",onChange:(I,v)=>{w(I&&v?`${I}/${v}`:"")}})})]})]})]}),t.jsxs("div",{"data-settings-item":"commands.template",className:"mb-2",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.template")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(ps,{value:E,onChange:I=>N(I.target.value),placeholder:s("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),t.jsx("div",{className:"mt-2 px-2",children:t.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",s("settings.commands.page.templateHint.userInput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",s("settings.commands.page.templateHint.shellOutput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"@file"})," ",s("settings.commands.page.templateHint.fileContents")]})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:M,disabled:y||!z,size:"xs",className:"!font-normal",children:s(y?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.commands.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.commands.page.empty.description")})]})})},Qi=s=>{switch(s){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Yi=s=>{const e=rt.c(5),{tone:n,enabled:a}=s;if(!a){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=t.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 r;e[1]!==n?(r=de("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]=r):r=e[2];let i;return e[3]!==r?(i=t.jsx("span",{className:r}),e[3]=r,e[4]=i):i=e[4],i},pp=s=>{const e=rt.c(120),{onItemSelect:n}=s,{t:a}=dt(),{mcpServers:r,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:d,loadMcpConfigs:c,deleteMcp:x}=Mn(Ss(gp)),m=vs(hp);let p;e[0]!==m?(p=Ce=>Ce.getStatusForDirectory(m??null),e[0]=m,e[1]=p):p=e[1];const u=is(p),S=is(fp),f=is(xp),[g,h]=l.useState(null),[D,k]=l.useState(!1),[w,E]=l.useState(null),[N,y]=l.useState(null),[b,P]=l.useState(!1);let z;e[2]!==r?(z=r.filter(bp),e[2]=r,e[3]=z):z=e[3];const M=z;let I;e[4]!==r?(I=r.filter(yp),e[4]=r,e[5]=I):I=e[5];const v=I;let j,O;e[6]!==c?(j=()=>{c()},O=[c],e[6]=c,e[7]=j,e[8]=O):(j=e[7],O=e[8]),l.useEffect(j,O);let T;e[9]!==m||e[10]!==f||e[11]!==b||e[12]!==S?(T=()=>{if(b)return;P(!0);const Ce=new Promise(vp);Promise.all([S({directory:m,silent:!0}),Ce]).then(()=>{const He=f(m);He&&V.error(He)}).finally(()=>{P(!1)})},e[9]=m,e[10]=f,e[11]=b,e[12]=S,e[13]=T):T=e[13];const U=T;let B;e[14]!==r||e[15]!==n||e[16]!==d||e[17]!==o?(B=()=>{let Ce="new-mcp-server",He=1;for(;r.some($=>$.name===Ce);)Ce=`new-mcp-server-${He}`,He++;d({name:Ce,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(Ce),n?.()},e[14]=r,e[15]=n,e[16]=d,e[17]=o,e[18]=B):B=e[18];const Q=B;let W;e[19]!==x||e[20]!==g||e[21]!==a?(W=async()=>{if(!g)return;k(!0);const Ce=await x(g.name);Ce.ok?Ce.reloadFailed?V.warning(Ce.message||`MCP server "${g.name}" deleted, but OpenCode reload failed`,{description:Ce.warning||a("settings.mcp.sidebar.toast.refreshListIfStale")}):V.success(Ce.message||a("settings.mcp.sidebar.toast.serverDeleted",{name:g.name})):V.error(a("settings.mcp.sidebar.toast.deleteFailed")),h(null),k(!1)},e[19]=x,e[20]=g,e[21]=a,e[22]=W):W=e[22];const R=W;let Y;e[23]!==a?(Y=(Ce,He)=>t.jsxs(He,{onClick:G=>{G.stopPropagation(),h(Ce)},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]}),e[23]=a,e[24]=Y):Y=e[24];const F=Y;let H;e[25]===Symbol.for("react.memo_cache_sentinel")?(H=de("flex h-full flex-col","bg-background"),e[25]=H):H=e[25];let X;e[26]!==a?(X=a("settings.mcp.sidebar.title"),e[26]=a,e[27]=X):X=e[27];let re;e[28]!==X?(re=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:X}),e[28]=X,e[29]=re):re=e[29];let Z;e[30]!==a?(Z=a("settings.mcp.sidebar.actions.refreshStatusAria"),e[30]=a,e[31]=Z):Z=e[31];let se;e[32]!==a?(se=a("settings.mcp.sidebar.actions.refreshStatusTitle"),e[32]=a,e[33]=se):se=e[33];const ce=b&&"animate-spin";let oe;e[34]!==ce?(oe=de("h-4 w-4",ce),e[34]=ce,e[35]=oe):oe=e[35];let xe;e[36]!==oe?(xe=t.jsx(A,{name:"refresh",className:oe}),e[36]=oe,e[37]=xe):xe=e[37];let we;e[38]!==U||e[39]!==b||e[40]!==Z||e[41]!==se||e[42]!==xe?(we=t.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:b,onClick:U,"aria-label":Z,title:se,children:xe}),e[38]=U,e[39]=b,e[40]=Z,e[41]=se,e[42]=xe,e[43]=we):we=e[43];let he;e[44]!==re||e[45]!==we?(he=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[re,we]}),e[44]=re,e[45]=we,e[46]=he):he=e[46];let Ie;e[47]===Symbol.for("react.memo_cache_sentinel")?(Ie=t.jsx(ta,{className:"mb-3"}),e[47]=Ie):Ie=e[47];let ve;e[48]!==r.length||e[49]!==a?(ve=a("settings.mcp.sidebar.total",{count:r.length}),e[48]=r.length,e[49]=a,e[50]=ve):ve=e[50];let be;e[51]!==ve?(be=t.jsx("span",{className:"typography-meta text-muted-foreground",children:ve}),e[51]=ve,e[52]=be):be=e[52];let ye;e[53]!==a?(ye=a("settings.mcp.sidebar.actions.addServerTitle"),e[53]=a,e[54]=ye):ye=e[54];let te;e[55]===Symbol.for("react.memo_cache_sentinel")?(te=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[55]=te):te=e[55];let ie;e[56]!==Q||e[57]!==ye?(ie=t.jsx(J,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,title:ye,children:te}),e[56]=Q,e[57]=ye,e[58]=ie):ie=e[58];let ge;e[59]!==be||e[60]!==ie?(ge=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[be,ie]}),e[59]=be,e[60]=ie,e[61]=ge):ge=e[61];let _;e[62]!==he||e[63]!==ge?(_=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[he,Ie,ge]}),e[62]=he,e[63]=ge,e[64]=_):_=e[64];let ee;e[65]!==r.length||e[66]!==u||e[67]!==n||e[68]!==w||e[69]!==M||e[70]!==F||e[71]!==N||e[72]!==i||e[73]!==d||e[74]!==o||e[75]!==a||e[76]!==v?(ee=t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:r.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.mcp.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.mcp.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[M.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.mcp.sidebar.group.projectServers")}),M.map(Ce=>{const He=u[Ce.name],G=Qi(He?.status),$=i===Ce.name,fe=Qn();return t.jsxs(en,{open:N===Ce.name,onOpenChange:L=>y(L?Ce.name:null),children:[t.jsxs(tn,{render:t.jsx("div",{className:de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",$?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:fe?void 0:L=>{L.preventDefault(),y(Ce.name)}}),children:[t.jsxs("button",{onClick:()=>{o(Ce.name),d(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:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Yi,{tone:G,enabled:Ce.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ce.name}),t.jsx("span",{title:Ce.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Ce.type==="local"?t.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(A,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ce.type==="local"?Ce.command?.join(" ")??"":Ce.url??""})]}),t.jsxs(us,{open:w===Ce.name,onOpenChange:L=>{L&&y(null),E(L?Ce.name:null)},children:[t.jsx(ds,{asChild:!0,children:t.jsx(J,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:F(Ce,js)})]})]}),t.jsx(sn,{className:"w-fit min-w-20",children:F(Ce,Ws)})]},Ce.name)})]}),v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.mcp.sidebar.group.userServers")}),v.map(Ce=>{const He=u[Ce.name],G=Qi(He?.status),$=i===Ce.name,fe=Qn();return t.jsxs(en,{open:N===Ce.name,onOpenChange:L=>y(L?Ce.name:null),children:[t.jsxs(tn,{render:t.jsx("div",{className:de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",$?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:fe?void 0:L=>{L.preventDefault(),y(Ce.name)}}),children:[t.jsxs("button",{onClick:()=>{o(Ce.name),d(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:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Yi,{tone:G,enabled:Ce.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ce.name}),t.jsx("span",{title:Ce.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Ce.type==="local"?t.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(A,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ce.type==="local"?Ce.command?.join(" ")??"":Ce.url??""})]}),t.jsxs(us,{open:w===Ce.name,onOpenChange:L=>{L&&y(null),E(L?Ce.name:null)},children:[t.jsx(ds,{asChild:!0,children:t.jsx(J,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:F(Ce,js)})]})]}),t.jsx(sn,{className:"w-fit min-w-20",children:F(Ce,Ws)})]},Ce.name)})]})]})}),e[65]=r.length,e[66]=u,e[67]=n,e[68]=w,e[69]=M,e[70]=F,e[71]=N,e[72]=i,e[73]=d,e[74]=o,e[75]=a,e[76]=v,e[77]=ee):ee=e[77];const ne=g!==null;let ue;e[78]!==D?(ue=Ce=>{!Ce&&!D&&h(null)},e[78]=D,e[79]=ue):ue=e[79];let Me;e[80]!==a?(Me=a("settings.mcp.sidebar.deleteDialog.title"),e[80]=a,e[81]=Me):Me=e[81];let ke;e[82]!==Me?(ke=t.jsx(Vt,{children:Me}),e[82]=Me,e[83]=ke):ke=e[83];const De=g?.name||"";let Ae;e[84]!==a||e[85]!==De?(Ae=a("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:De}),e[84]=a,e[85]=De,e[86]=Ae):Ae=e[86];let Pe;e[87]===Symbol.for("react.memo_cache_sentinel")?(Pe=t.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[87]=Pe):Pe=e[87];let Re;e[88]!==Ae?(Re=t.jsxs(qt,{children:[Ae," ",Pe,"."]}),e[88]=Ae,e[89]=Re):Re=e[89];let Oe;e[90]!==ke||e[91]!==Re?(Oe=t.jsxs(_t,{children:[ke,Re]}),e[90]=ke,e[91]=Re,e[92]=Oe):Oe=e[92];let $e;e[93]===Symbol.for("react.memo_cache_sentinel")?($e=()=>h(null),e[93]=$e):$e=e[93];let Be;e[94]!==a?(Be=a("settings.common.actions.cancel"),e[94]=a,e[95]=Be):Be=e[95];let Le;e[96]!==D||e[97]!==Be?(Le=t.jsx(J,{size:"sm",variant:"ghost",onClick:$e,disabled:D,children:Be}),e[96]=D,e[97]=Be,e[98]=Le):Le=e[98];let Ue;e[99]!==D||e[100]!==a?(Ue=a(D?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[99]=D,e[100]=a,e[101]=Ue):Ue=e[101];let le;e[102]!==R||e[103]!==D||e[104]!==Ue?(le=t.jsx(J,{size:"sm",onClick:R,disabled:D,children:Ue}),e[102]=R,e[103]=D,e[104]=Ue,e[105]=le):le=e[105];let q;e[106]!==Le||e[107]!==le?(q=t.jsxs(Yt,{children:[Le,le]}),e[106]=Le,e[107]=le,e[108]=q):q=e[108];let me;e[109]!==Oe||e[110]!==q?(me=t.jsxs(Bt,{className:"max-w-md",children:[Oe,q]}),e[109]=Oe,e[110]=q,e[111]=me):me=e[111];let Ne;e[112]!==ne||e[113]!==ue||e[114]!==me?(Ne=t.jsx(Ut,{open:ne,onOpenChange:ue,children:me}),e[112]=ne,e[113]=ue,e[114]=me,e[115]=Ne):Ne=e[115];let Ee;return e[116]!==_||e[117]!==ee||e[118]!==Ne?(Ee=t.jsxs("div",{className:H,children:[_,ee,Ne]}),e[116]=_,e[117]=ee,e[118]=Ne,e[119]=Ee):Ee=e[119],Ee};function gp(s){return{mcpServers:s.mcpServers,selectedMcpName:s.selectedMcpName,setSelectedMcp:s.setSelectedMcp,setMcpDraft:s.setMcpDraft,loadMcpConfigs:s.loadMcpConfigs,deleteMcp:s.deleteMcp}}function hp(s){return s.currentDirectory}function fp(s){return s.refresh}function xp(s){return s.getErrorForDirectory}function bp(s){return s.scope==="project"}function yp(s){return s.scope!=="project"}function vp(s){return setTimeout(s,500)}function Ts(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function $n(s){return Array.isArray(s)&&s.every(e=>typeof e=="string")}function Ms(s,e){return e!==void 0?{ok:!1,error:s,parsed:e}:{ok:!1,error:s}}function ma(s,e,n){const a=jp(n),r=typeof n.url=="string"?n.url.trim():"",i=Xi(n,"env","environment"),o=Xi(n,"headers"),d=wp(n),c=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",x=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():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",u=Np(n),S=kp(n);return{ok:!0,name:s,type:e,command:a,url:r,environment:i,headers:o,oauthEnabled:d,oauthClientId:c,oauthClientSecret:x,oauthScope:m,oauthRedirectUri:p,timeout:u,enabled:S}}function jp(s){const e=s.command,n=s.args;if($n(e)&&$n(n))return[...e,...n];if($n(e))return e;if(typeof e=="string"&&e.trim()){const a=e.trim().split(/\s+/);return $n(n)?[...a,...n]:a}return $n(n)?n:[]}function Xi(s,...e){for(const n of e){const a=s[n];if(!Ts(a))continue;const r=Object.entries(a).filter(([i,o])=>i&&typeof o=="string");if(r.length>0)return r.map(([i,o])=>({key:i,value:String(o)}))}return[]}function wp(s){if(s.oauth===!1||s.oauth===null||s.oauth===void 0||!Ts(s.oauth))return!1;const e=s.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 Np(s){const e=s.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 kp(s){return"disabled"in s&&s.disabled===!0?!1:"enabled"in s?!!s.enabled:!0}function Sp(s){const e=s.mcpServers;if(Ts(e)){const a=Object.keys(e);if(a.length===1){const r=a[0],i=e[r];if(Ts(i))return{name:r,entry:i}}if(a.length>1)return null}const n=Object.keys(s).filter(a=>{const r=s[a];return a!=="mcpServers"&&Ts(r)});if(n.length===1){const a=n[0],r=s[a];if(Ml(r))return{name:a,entry:r}}return null}function Ml(s){return s.type==="local"||s.type==="remote"||Array.isArray(s.command)||typeof s.url=="string"||Array.isArray(s.args)}function Cp(s,e){let n;try{const d=s.trim();if(!d)return Ms("No JSON content provided");n=JSON.parse(d)}catch(d){return Ms(d instanceof Error?`Invalid JSON: ${d.message}`:"Invalid JSON")}if(!Ts(n))return Ms("Expected a JSON object, not an array or primitive");const a=n,r=a.mcpServers;if(Ts(r)){const d=Object.keys(r);if(d.length===0)return Ms("mcpServers object is empty",n);if(d.length>1)return Ms("Paste one server at a time. Found "+d.length+" servers in mcpServers",n);const c=d[0],x=r[c];return Ts(x)?ma(c,ua(x),x):Ms("Server entry is not a valid object",n)}const i=a.mcp;if(Ts(i)){const d=Object.keys(i);if(d.length===0)return Ms("mcp object is empty",n);if(d.length>1)return Ms("Paste one server at a time. Found "+d.length+" servers in mcp",n);const c=d[0],x=i[c];return Ts(x)?ma(c,ua(x),x):Ms("Server entry in mcp is not a valid object",n)}const o=Sp(a);if(o)return ma(o.name,ua(o.entry),o.entry);if(Ml(a)){const d=ua(a),c=typeof a.name=="string"&&a.name.trim()?a.name.trim():e?.fallbackName;return ma(c,d,a)}return Ms("No recognizable MCP server configuration found in JSON",n)}function ua(s){return s.type==="remote"?"remote":s.type==="local"?"local":typeof s.url=="string"&&s.url.trim()?"remote":(Array.isArray(s.command)||typeof s.command=="string"||Array.isArray(s.args),"local")}function Pp(s,e,n){const a=n?.isNewServer??!1,r=s.name,i=a&&r?r:e.name??"";return{...e,name:i,type:s.type,command:s.type==="local"?s.command:[],url:s.type==="remote"?s.url:"",environment:s.environment,headers:s.type==="remote"?s.headers:[],oauthEnabled:s.type==="remote"?s.oauthEnabled:!1,oauthClientId:s.type==="remote"?s.oauthClientId:"",oauthClientSecret:s.type==="remote"?s.oauthClientSecret:"",oauthScope:s.type==="remote"?s.oauthScope:"",oauthRedirectUri:s.type==="remote"?s.oauthRedirectUri:"",timeout:s.type==="remote"?s.timeout:"",enabled:s.enabled}}const Ip="/mcp/oauth/callback",Dp=s=>{if(typeof window>"u")return null;try{const e=s.replace(/-/g,"+").replace(/_/g,"/"),n=e.length%4===0?"":"=".repeat(4-e.length%4),a=window.atob(e+n),r=Uint8Array.from(a,i=>i.charCodeAt(0));return new TextDecoder().decode(r)}catch{return null}},Ap=s=>{const e=Ep(s.get("state"));if(e)return e;const n=s.get("server");if(typeof n!="string"||!n.trim())return null;const a=s.get("directory");return{name:n.trim(),directory:typeof a=="string"&&a.trim()?a.trim():null}},Rl=s=>{const e=s.get("state");return typeof e!="string"?null:e.trim()||null},Ep=s=>{if(typeof s!="string"||!s.trim())return null;const e=Dp(s.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}},gn=Cc,hn=s=>{const e=rt.c(14);let n,a,r,i;e[0]!==s?({className:r,asChild:n,children:a,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i):(n=e[1],a=e[2],r=e[3],i=e[4]);let o;e[5]!==n||e[6]!==a?(o=n&&je.isValidElement(a)?{render:a}:{children:a},e[5]=n,e[6]=a,e[7]=o):o=e[7];const d=o;let c;e[8]!==r?(c=de("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",r),e[8]=r,e[9]=c):c=e[9];let x;return e[10]!==i||e[11]!==d||e[12]!==c?(x=t.jsx(Sc,{className:c,...i,...d}),e[10]=i,e[11]=d,e[12]=c,e[13]=x):x=e[13],x},fn=s=>{const e=rt.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=de("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(Pc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i};function Mp(s){const e=[];let n="",a=!1,r=!1;for(let i=0;i<s.length;i++){const o=s[i];if(o==="'"&&!r){a=!a;continue}if(o==='"'&&!a){r=!r;continue}if((o===" "||o===" ")&&!a&&!r){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function Rp(s){const e=s.trim();if(!e)return{code:null,context:null,stateKey:null};try{const n=new URL(e),a=n.searchParams.get("code");if(typeof a=="string"&&a.trim())return{code:a.trim(),context:Ap(n.searchParams),stateKey:Rl(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Tp=({value:s,onChange:e,pasteCommandTitle:n,pasteCommandLabel:a,pasteSuccess:r,clipboardReadFailed:i,preview:o})=>{const[d,c]=l.useState(()=>s.join(`
4
- `)),x=l.useRef(s);l.useEffect(()=>{JSON.stringify(x.current)!==JSON.stringify(s)&&(x.current=s,c(s.join(`
5
- `)))},[s]);const m=u=>{const S=u.split(`
6
- `).filter(f=>f.trim().length>0);e(S)},p=async()=>{try{const S=(await navigator.clipboard.readText()).trim(),f=S.includes(`
7
- `)?S.split(`
8
- `).filter(g=>g.trim()):Mp(S);c(f.join(`
9
- `)),e(f),V.success(r(f.length))}catch{V.error(i)}};return t.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[t.jsx("div",{className:"flex items-center justify-end gap-2",children:t.jsxs(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:p,type:"button",title:n,children:[t.jsx(A,{name:"clipboard",className:"h-3 w-3"}),a]})}),t.jsx(ps,{value:d,onChange:u=>{c(u.target.value),m(u.target.value)},onBlur:()=>{const u=d.split(`
10
- `).map(S=>S.trimEnd()).join(`
11
- `);c(u),m(u)},placeholder:`npx
12
- -y
13
- @modelcontextprotocol/server-postgres
14
- postgresql://user:pass@host/db`,rows:Math.max(4,s.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),s.length>0&&t.jsxs("details",{className:"group",children:[t.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:o(s.length)}),t.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:t.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:s.map((u,S)=>t.jsxs("span",{className:"block",children:[t.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",S,"]"]}),u]},S))})})]})]})},Fp=s=>s.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Zi=({value:s,onChange:e,keyTransform:n=Fp,keyPlaceholder:a="API_KEY",keyInputClassName:r="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:o="Paste KEY=VALUE lines from clipboard",noPairsFoundError:d,importSuccess:c,clipboardReadFailed:x,keyLabel:m,valueLabel:p,valuePlaceholder:u,hideValueTitle:S,showValueTitle:f,addVariable:g,plainTextWarning:h,removeVariableAria:D})=>{const[k,w]=l.useState(new Set),E=()=>e([...s,{key:"",value:""}]),N=M=>{e(s.filter((I,v)=>v!==M)),w(I=>{const v=new Set(I);return v.delete(M),v})},y=(M,I,v)=>{const j=[...s];j[M]={...j[M],[I]:v},e(j)},b=M=>{w(I=>{const v=new Set(I);return v.has(M)?v.delete(M):v.add(M),v})},P=async()=>{try{const M=await navigator.clipboard.readText(),I=[];for(const j of M.split(`
15
- `)){const O=j.trim();if(!O||O.startsWith("#"))continue;const T=O.indexOf("=");if(T===-1)continue;const U=O.slice(0,T).trim();let B=O.slice(T+1).trim();(B.startsWith('"')&&B.endsWith('"')||B.startsWith("'")&&B.endsWith("'"))&&(B=B.slice(1,-1)),U&&I.push({key:U,value:B})}if(I.length===0){V.error(d);return}const v=[...s];for(const j of I){const O=v.findIndex(T=>T.key===j.key);O!==-1?v[O]=j:v.push(j)}e(v),V.success(c(I.length))}catch{V.error(x)}},z=s.some(M=>M.value.length>0);return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:p})]}),t.jsxs(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:P,type:"button",title:o,children:[t.jsx(A,{name:"clipboard",className:"h-3 w-3"}),i]})]}),t.jsx("div",{className:"space-y-1.5",children:s.map((M,I)=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(it,{value:M.key,onChange:v=>y(I,"key",n(v.target.value)),placeholder:a,className:r,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),t.jsxs("div",{className:"relative flex-1 flex items-center",children:[t.jsx(it,{type:k.has(I)?"text":"password",value:M.value,onChange:v=>y(I,"value",v.target.value),placeholder:u,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),t.jsx("button",{type:"button",onClick:()=>b(I),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:k.has(I)?S:f,children:k.has(I)?t.jsx(A,{name:"eye-off",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"eye",className:"h-3.5 w-3.5"})})]}),t.jsx(J,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>N(I),"aria-label":D,children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},I))}),t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:E,type:"button",children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),g]}),z&&t.jsx("p",{className:"typography-micro text-muted-foreground/60",children:h})]})},eo=s=>{const e=rt.c(14),{status:n,enabled:a,getStatusLabel:r,variant:i}=s,o=i===void 0?"compact":i;if(!a||!n)return null;let d,c;if(e[0]!==r||e[1]!==n||e[2]!==o){c=Symbol.for("react.early_return_sentinel");e:{const u={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 S=de("typography-micro font-medium rounded-full px-2 py-0.5",u.text,u.bg);let f;e[5]!==r||e[6]!==n?(f=r(n),e[5]=r,e[6]=n,e[7]=f):f=e[7],c=t.jsxs("span",{className:S,children:["● ",f]});break e}d=de("typography-micro font-medium",u.text)}e[0]=r,e[1]=n,e[2]=o,e[3]=d,e[4]=c}else d=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let x;e[8]!==r||e[9]!==n?(x=r(n),e[8]=r,e[9]=n,e[10]=x):x=e[10];let m;return e[11]!==d||e[12]!==x?(m=t.jsxs("span",{className:d,children:["● ",x]}),e[11]=d,e[12]=x,e[13]=m):m=e[13],m},Op=(s,e,n)=>{switch(s){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")}},Lp=s=>{switch(s){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)]"}},zp=(s,e,n,a)=>!!(s==="failed"||s==="needs_auth"||s==="needs_client_registration"||e||n||a),to=(s,e)=>{if(typeof window>"u")return null;const n=new URL(Ip,Xn()||window.location.origin);return typeof s=="string"&&s.trim()&&n.searchParams.set("server",s.trim()),typeof e=="string"&&e.trim()&&n.searchParams.set("directory",e.trim()),n.toString()},Kp=async s=>{const e=await jt("/api/mcp/auth/pending",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:s.state,name:s.name,directory:typeof s.directory=="string"&&s.directory.trim()?s.directory.trim():null})});if(!e.ok){const n=await e.json().catch(()=>null);throw new Error(n?.error||"Failed to prepare MCP authorization callback")}},$p=async s=>{const e=await jt(`/api/mcp/auth/pending?state=${encodeURIComponent(s)}`);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},Un=async s=>{typeof s!="string"||!s.trim()||await jt(`/api/mcp/auth/pending?state=${encodeURIComponent(s.trim())}`,{method:"DELETE"}).catch(()=>{})},ar=(s,e,n)=>{const a=s instanceof Error?s.message:e;return/oauth state required/i.test(a)?n("settings.mcp.page.toast.authSessionExpired"):a},Up=(s,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${s??"__none__"}::${n}`},Bp=()=>{const{t:s}=dt(),e=l.useCallback((Se,vt)=>s(Se,vt),[s]),{selectedMcpName:n,mcpServers:a,mcpDraft:r,setMcpDraft:i,setSelectedMcp:o,getMcpByName:d,createMcp:c,updateMcp:x,deleteMcp:m}=Mn(Ss(Se=>({selectedMcpName:Se.selectedMcpName,mcpServers:Se.mcpServers,mcpDraft:Se.mcpDraft,setMcpDraft:Se.setMcpDraft,setSelectedMcp:Se.setSelectedMcp,getMcpByName:Se.getMcpByName,createMcp:Se.createMcp,updateMcp:Se.updateMcp,deleteMcp:Se.deleteMcp}))),p=vs(Se=>Se.currentDirectory),u=l.useMemo(()=>gs(),[]),S=is(Se=>Se.getStatusForDirectory(p??null)),f=is(Se=>Se.getDiagnosticForDirectory(p??null)),g=is(Se=>Se.refresh),h=is(Se=>Se.connect),D=is(Se=>Se.disconnect),k=is(Se=>Se.startAuth),w=is(Se=>Se.completeAuth),E=is(Se=>Se.clearAuth),N=is(Se=>Se.testConnection),y=n?d(n):null,b=!!(r&&r.name===n&&!y),[P,z]=l.useState(""),[M,I]=l.useState("user"),[v,j]=l.useState("local"),[O,T]=l.useState([]),[U,B]=l.useState(""),[Q,W]=l.useState([]),[R,Y]=l.useState([]),[F,H]=l.useState(!0),[X,re]=l.useState(""),[Z,se]=l.useState(""),[ce,oe]=l.useState(""),[xe,we]=l.useState(""),[he,Ie]=l.useState(""),[ve,be]=l.useState(!0),[ye,te]=l.useState(!1),[ie,ge]=l.useState(!1),[_,ee]=l.useState(!1),[ne,ue]=l.useState(!1),[Me,ke]=l.useState(!1),[De,Ae]=l.useState(!1),[Pe,Re]=l.useState(!1),[Oe,$e]=l.useState(!1),[Be,Le]=l.useState(null),[Ue,le]=l.useState(null),[q,me]=l.useState(""),[Ne,Ee]=l.useState(!1),Ce=l.useRef(0),He=l.useRef(!1),[G,$]=l.useState(!1),[fe,L]=l.useState(!1),[Fe,Je]=l.useState(""),[Xe,et]=l.useState(null),at=l.useMemo(()=>Up(n,p),[p,n]),lt=l.useRef(at),Ze=l.useRef(null),We=l.useCallback(()=>{Le(null),le(null),me(""),Ee(!1),Ce.current=0,$e(!1),ke(!1),Ae(!1),He.current=!1},[]),pt=l.useCallback(()=>{Je(""),et(null),L(!0)},[]),pe=l.useCallback(async()=>{try{const Se=await navigator.clipboard.readText();Je(Se),et(null)}catch{V.error(s("settings.mcp.page.toast.clipboardReadFailed"))}},[s]),st=l.useCallback(()=>{const Se=Cp(Fe,{fallbackName:P});if(!Se.ok){et(Se.error);return}const Nt=Pp(Se,{name:P,scope:M,type:v,command:O,url:U,environment:Q,headers:R,oauthEnabled:F,oauthClientId:X,oauthClientSecret:Z,oauthScope:ce,oauthRedirectUri:xe,timeout:he,enabled:ve},{isNewServer:b});z(Nt.name),j(Nt.type),T(Nt.command??[]),B(Nt.url??""),W(Nt.environment??[]),Y(Nt.headers??[]),H(Nt.oauthEnabled??!1),re(Nt.oauthClientId??""),se(Nt.oauthClientSecret??""),oe(Nt.oauthScope??""),we(Nt.oauthRedirectUri??""),Ie(Nt.timeout??""),be(Nt.enabled??!0),L(!1),Je(""),et(null),V.success(s("settings.mcp.page.toast.configImported"))},[Fe,P,M,v,O,U,Q,R,F,X,Z,ce,xe,he,ve,b,s]);l.useEffect(()=>{if(b&&r){z(r.name),I(r.scope||"user"),j(r.type),T(r.command),B(r.url),W(r.environment),Y(r.headers),H(r.oauthEnabled),re(r.oauthClientId),se(r.oauthClientSecret),oe(r.oauthScope),we(r.oauthRedirectUri),Ie(r.timeout),be(r.enabled),$(!1),Ze.current={mcpType:r.type,command:r.command,url:r.url,envEntries:r.environment,headerEntries:r.headers,oauthEnabled:r.oauthEnabled,oauthClientId:r.oauthClientId,oauthClientSecret:r.oauthClientSecret,oauthScope:r.oauthScope,oauthRedirectUri:r.oauthRedirectUri,timeout:r.timeout,enabled:r.enabled};return}if(y){I(y.scope==="project"?"project":"user");const Se=Ai(y.environment),vt=y.type==="remote"?y:null,Nt=Ai(vt?.headers),ct=vt?.oauth,St=ct&&typeof ct=="object"?ct:null,$t=ct!==!1,bs=y.type,ns=bs==="local"?y.command??[]:[],ys=bs==="remote"?y.url??"":"",Qe=typeof vt?.timeout=="number"&&Number.isFinite(vt.timeout)?String(vt.timeout):"";j(bs),T(ns),B(ys),W(Se),Y(Nt),H($t),re($t?St?.clientId??"":""),se($t?St?.clientSecret??"":""),oe($t?St?.scope??"":""),we($t?St?.redirectUri??"":""),Ie(Qe),be(y.enabled),$(!1),Ze.current={mcpType:bs,command:ns,url:ys,envEntries:Se,headerEntries:Nt,oauthEnabled:$t,oauthClientId:$t?St?.clientId??"":"",oauthClientSecret:$t?St?.clientSecret??"":"",oauthScope:$t?St?.scope??"":"",oauthRedirectUri:$t?St?.redirectUri??"":"",timeout:Qe,enabled:y.enabled}}},[y,b,r]);const nt=l.useMemo(()=>{const Se=Ze.current;return Se?v!==Se.mcpType||ve!==Se.enabled||JSON.stringify(O)!==JSON.stringify(Se.command)||U!==Se.url||JSON.stringify(Q)!==JSON.stringify(Se.envEntries)||JSON.stringify(R)!==JSON.stringify(Se.headerEntries)||F!==Se.oauthEnabled||X!==Se.oauthClientId||Z!==Se.oauthClientSecret||ce!==Se.oauthScope||xe!==Se.oauthRedirectUri||he!==Se.timeout:!1},[v,O,U,Q,R,F,X,Z,ce,xe,he,ve]),Ge=async()=>{const Se=b?P.trim():n??"";if(!Se){V.error(s("settings.mcp.page.toast.nameRequired"));return}if(b&&a.some(Nt=>Nt.name===Se)){V.error(s("settings.mcp.page.toast.serverNameExists"));return}if(v==="local"&&O.filter(Boolean).length===0){V.error(s("settings.mcp.page.toast.localCommandRequired"));return}if(v==="remote"&&!U.trim()){V.error(s("settings.mcp.page.toast.remoteUrlRequired"));return}const vt={name:Se,scope:M,type:v,command:O,url:U,environment:Q,headers:R,oauthEnabled:F,oauthClientId:X,oauthClientSecret:Z,oauthScope:ce,oauthRedirectUri:xe,timeout:he,enabled:ve};te(!0);try{const Nt=b?await c(vt):await x(Se,vt);Nt.ok?(await Un(Ue),We(),b&&(i(null),o(Se)),await g({directory:p,silent:!0}),Nt.reloadFailed?V.warning(Nt.message||s(b?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Nt.warning||s("settings.mcp.page.toast.retryRefreshHint")}):V.success(Nt.message||s(b?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):V.error(s("settings.mcp.page.toast.saveFailed"))}catch(Nt){V.error(Nt instanceof Error?Nt.message:s("settings.mcp.page.toast.unexpectedError"))}finally{te(!1)}},ft=async()=>{if(!n)return;ee(!0);const Se=await m(n);Se.ok?(await Un(Ue),We(),Se.reloadFailed?V.warning(Se.message||s("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Se.warning||s("settings.mcp.page.toast.refreshListIfStale")}):V.success(Se.message||s("settings.mcp.page.toast.serverDeleted",{name:n})),ge(!1)):V.error(s("settings.mcp.page.toast.deleteFailed")),ee(!1)},wt=async()=>{if(n){ue(!0);try{if(S[n]?.status==="connected")await D(n,p),V.success(s("settings.mcp.page.toast.disconnected"));else{await h(n,p),await g({directory:p,silent:!0});const vt=is.getState().getStatusForDirectory(p??null)[n];vt?.status==="connected"?V.success(s("settings.mcp.page.toast.connected")):vt?.status==="needs_auth"?V.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):vt?.status==="needs_client_registration"?V.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):vt?.status==="failed"?V.error(vt.error||s("settings.mcp.page.toast.connectionFailed")):V.message(s("settings.mcp.page.toast.connectionAttemptFinished"));return}await g({directory:p,silent:!0})}catch(Se){V.error(Se instanceof Error?Se.message:s("settings.mcp.page.toast.connectionFailed"))}finally{ue(!1)}}},Ct=l.useCallback(()=>b?(V.error(s("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):nt?(V.error(s("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[nt,b,s]),ae=l.useCallback(async(Se=!1)=>{try{await g({directory:p,silent:Se})}catch(vt){Se||V.error(vt instanceof Error?vt.message:s("settings.mcp.page.toast.refreshStatusFailed"))}},[p,g,s]);l.useEffect(()=>{ae(!0)},[ae]),l.useEffect(()=>{lt.current=at,ue(!1),Re(!1),We()},[We,at]);const Ve=l.useCallback(async()=>{if(!n||v!=="remote"||!Ct())return;ke(!0);const Se=at;let vt=null;try{const Nt=is.getState().getStatusForDirectory(p??null)[n]?.status;He.current=Nt==="needs_auth"||Nt==="needs_client_registration";const ct=to(n,p);if(!ct)throw new Error(s("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!xe.trim()&&!u){const ns=await x(n,{oauthEnabled:F,oauthClientId:X,oauthClientSecret:Z,oauthScope:ce,oauthRedirectUri:ct});if(!ns.ok)throw new Error(s("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(ns.reloadFailed)throw new Error(ns.warning||ns.message||s("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(lt.current!==Se)return;we(ct),Ze.current=Ze.current?{...Ze.current,oauthRedirectUri:ct}:Ze.current}const St=await k(n,p),$t=Rl(new URL(St).searchParams);if($t&&(vt=$t,await Kp({state:$t,name:n,directory:p})),lt.current!==Se)return;Le(St),le($t??null),Ee(!0),Ce.current=0;const bs=await Hs(St);if(lt.current!==Se)return;bs?V.message(s(u?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):V.error(s("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Nt){await Un(vt),lt.current===Se&&V.error(ar(Nt,s("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{lt.current===Se&&ke(!1)}},[p,u,v,X,Z,F,xe,ce,Ct,at,n,k,s,e,x]),tt=l.useCallback(async()=>{if(!n||!Ct())return;Ae(!0);const Se=at;try{if(await E(n,p),lt.current!==Se)return;Le(null),le(null),me(""),Ee(!1),Ce.current=0,await Un(Ue),V.success(s("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(vt){lt.current===Se&&V.error(ar(vt,s("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{lt.current===Se&&Ae(!1)}},[Ue,E,p,Ct,at,n,s,e]),Ye=l.useCallback(async()=>{if(!Be)return;if((await un(Be)).ok){V.success(s("settings.mcp.page.toast.authorizationUrlCopied"));return}V.error(s("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Be,s]),bt=l.useCallback(async()=>{const Se=Rp(q);if(!Se.code){V.error(s("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const vt=Se.stateKey?await $p(Se.stateKey):null,Nt=Se.context??vt,ct=Nt?.name??n,St=Nt?.directory??p;if(!ct){V.error(s("settings.mcp.page.toast.missingServerDetails"));return}if(!Nt&&!Ct())return;$e(!0);const $t=at;try{if(await w(ct,Se.code,St),await Un(Se.stateKey??Ue),lt.current!==$t)return;me(""),Le(null),le(null),Ee(!1),Ce.current=0,V.success(ct===n?s("settings.mcp.page.toast.authorizationCompleted"):s("settings.mcp.page.toast.authorizationCompletedFor",{name:ct}))}catch(bs){lt.current===$t&&V.error(ar(bs,s("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{lt.current===$t&&$e(!1)}},[q,Ue,w,p,Ct,at,n,s,e]),ze=l.useCallback(async()=>{if(!(!n||!Ct())){if(!ve){V.error(s("settings.mcp.page.toast.enableServerBeforeTest"));return}Re(!0);try{const Se=await N(n,p),vt=Se.status?.status;Se.warning?V.warning(Se.warning):vt==="connected"?V.success(s("settings.mcp.page.toast.connectionTestSucceeded")):vt==="needs_auth"?V.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):vt==="needs_client_registration"?V.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):vt==="failed"?V.error(Se.status?.error||Se.error||s("settings.mcp.page.toast.connectionTestFailed")):Se.error?V.error(Se.error):V.message(s("settings.mcp.page.toast.connectionTestFinished"))}catch(Se){V.error(Se instanceof Error?Se.message:s("settings.mcp.page.toast.connectionTestFailed"))}finally{Re(!1)}}},[p,ve,Ct,n,s,N]);if(l.useEffect(()=>{if(!Ne||!n)return;const Se=window.setInterval(()=>{(async()=>{Ce.current+=1,await g({directory:p,silent:!0});const vt=is.getState().getStatusForDirectory(p??null)[n];if(vt){if(He.current&&vt.status!=="needs_auth"&&vt.status!=="needs_client_registration"){Ee(!1),Ce.current=0,He.current=!1,Le(null),me(""),vt.status==="connected"&&V.success(s("settings.mcp.page.toast.authorizationCompleted"));return}if(!He.current&&vt.status==="failed"){Ee(!1),Ce.current=0,He.current=!1,V.error(vt.error||s("settings.mcp.page.toast.authorizationFailed"));return}Ce.current>=30&&(Ee(!1),Ce.current=0,He.current=!1,V.message(s("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Se)}},[p,Ne,g,n,s]),!n)return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.mcp.page.empty.selectServer")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.mcp.page.empty.addNewOne")})]})});const _e=S[n],ot=n?f[n]:void 0,yt=_e??ot,Mt=_e?.status==="connected",Qt=_e?.status==="needs_auth"||_e?.status==="needs_client_registration",Xt=u?null:to(n,p),rs=Op(yt?.status,e,yt&&"error"in yt?yt.error:void 0),Wt=Se=>{switch(Se){case"connected":return s("settings.mcp.page.status.label.connected");case"failed":return s("settings.mcp.page.status.label.failed");case"needs_auth":return s("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return s("settings.mcp.page.status.label.needsRegistration");default:return Se}};return t.jsxs(Jt,{outerClassName:"h-full",className:"w-full",children:[t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4",children:t.jsxs("div",{className:"min-w-0",children:[b?t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:s("settings.mcp.page.header.newServer")}):t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:n}),t.jsx(eo,{status:yt?.status,enabled:ve,getStatusLabel:Wt,variant:"pill"})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:b?s("settings.mcp.page.header.configureNewServer"):s("settings.mcp.page.header.transport",{type:s(v==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!b&&t.jsxs(t.Fragment,{children:[t.jsx(J,{variant:Mt?"outline":"default",size:"xs",className:"!font-normal",onClick:wt,disabled:ne||!ve,children:s(ne?"settings.mcp.page.actions.working":Mt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),v==="remote"&&t.jsxs(t.Fragment,{children:[t.jsx(J,{variant:Qt?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{Ve()},disabled:Me||!ve,children:s(Me?"settings.mcp.page.actions.starting":Qt?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{tt()},disabled:De||!ve,children:s(De?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Mt&&t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ze()},disabled:Pe||!ve,children:s(Pe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!b&&zp(yt?.status,Be,Qt,Ne)&&t.jsx("div",{className:"mb-6 px-2",children:t.jsxs("div",{className:de("rounded-lg border p-3",Lp(yt?.status)),children:[t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"min-w-0 space-y-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.status.runtimeStatus")}),t.jsx(eo,{status:yt?.status,enabled:ve,getStatusLabel:Wt})]}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:rs}),t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:M==="project"?s("settings.mcp.page.status.projectScopedTo",{directory:p??s("settings.mcp.page.status.activeProject")}):s("settings.mcp.page.status.userScoped")})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Mt&&t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ze()},disabled:Pe||!ve,children:s(Pe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Be&&t.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.authorizationUrl")}),t.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:Be}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Hs(Be)},children:[t.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.mcp.page.actions.openInBrowser")]}),t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ye()},children:[t.jsx(A,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.actions.copyLink")]})]})]})}),v==="remote"&&(Qt||Ne||Be)&&t.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.auth.manualFallbackTitle")}),t.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.manualFallbackDescription")})]}),t.jsx(ps,{value:q,onChange:Se=>me(Se.target.value),placeholder:s("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{bt()},disabled:Oe,children:s(Oe?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Ne&&t.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.waitingForOpenCode")})]})}),t.jsxs("div",{"data-settings-item":"mcp.server",className:"mb-6",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.mcp.page.server.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[b&&t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.server.name")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsx(it,{value:P,onChange:Se=>z(Se.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:s("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 font-mono px-2",autoFocus:!0}),t.jsxs(Ft,{value:M,onValueChange:Se=>I(Se),children:[t.jsx(Ot,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:s(M==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:M==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ht,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),b&&t.jsx("div",{className:"py-1.5",children:t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:pt,type:"button",title:s("settings.mcp.page.server.importJsonTitle"),children:[t.jsx(A,{name:"file-code",className:"h-3.5 w-3.5"}),s("settings.mcp.page.server.importJson")]})}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ve,onClick:()=>be(!ve),onKeyDown:Se=>{(Se.key===" "||Se.key==="Enter")&&(Se.preventDefault(),be(!ve))},children:[t.jsx(Pt,{checked:ve,onChange:be,ariaLabel:s("settings.mcp.page.server.enableAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.server.enable")})]}),t.jsx("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:t.jsxs("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.server.transportMode")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":v==="local",onClick:()=>j("local"),className:"!font-normal",children:s("settings.mcp.page.transport.local")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":v==="remote",onClick:()=>j("remote"),className:"!font-normal",children:s("settings.mcp.page.transport.remote")})]})]})})]})]}),t.jsxs("div",{"data-settings-item":"mcp.command",className:"mb-6",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s(v==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:v==="local"?t.jsx(Tp,{value:O,onChange:T,pasteCommandTitle:s("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:s("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Se=>s("settings.mcp.page.toast.pastedArgumentsCount",{count:Se}),clipboardReadFailed:s("settings.mcp.page.toast.clipboardReadFailed"),preview:Se=>s("settings.mcp.page.connection.previewArgs",{count:Se})}):t.jsx(it,{value:U,onChange:Se=>B(Se.target.value),placeholder:s("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),v==="remote"&&t.jsxs("div",{"data-settings-item":"mcp.advanced",className:"mb-6",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.mcp.page.advanced.title")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsxs(gn,{open:G,onOpenChange:$,children:[t.jsxs(hn,{className:"flex w-full items-center justify-between py-0.5 group",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[t.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:s("settings.mcp.page.advanced.configure")}),t.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",s(F?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",R.length," ",s("settings.mcp.page.advanced.headers"),he?` · ${he}ms`:"",")"]})]}),G?t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(fn,{className:"pt-2",children:t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.advanced.timeoutMs")})}),t.jsx("div",{className:"flex items-center gap-2",children:t.jsx(it,{type:"number",min:"1",step:"1",value:he,onChange:Se=>Ie(Se.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]}),t.jsx("p",{className:"typography-micro text-muted-foreground sm:pl-64",children:s("settings.mcp.page.advanced.timeoutHint")})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"mb-2 typography-ui-label text-foreground",children:[s("settings.mcp.page.advanced.requestHeaders"),R.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",R.length,")"]})]}),t.jsx(Zi,{value:R,onChange:Y,keyTransform:Se=>Se.trimStart(),keyPlaceholder:s("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:s("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:s("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:s("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Se=>s("settings.mcp.page.toast.importedVariablesCount",{count:Se}),clipboardReadFailed:s("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:s("settings.mcp.page.env.key"),valueLabel:s("settings.mcp.page.env.value"),valuePlaceholder:s("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:s("settings.mcp.page.env.hide"),showValueTitle:s("settings.mcp.page.env.show"),addVariable:s("settings.mcp.page.env.addVariable"),plainTextWarning:s("settings.mcp.page.env.plainTextWarning"),removeVariableAria:s("settings.mcp.page.env.removeVariableAria")})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":F,onClick:()=>H(!F),onKeyDown:Se=>{(Se.key===" "||Se.key==="Enter")&&(Se.preventDefault(),H(!F))},children:[t.jsx(Pt,{checked:F,onChange:H,ariaLabel:s("settings.mcp.page.advanced.oauthAutoDetectionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.advanced.oauthAutoDetection")})]}),t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.jsx(it,{value:X,onChange:Se=>re(Se.target.value),placeholder:s("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!F,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(it,{value:Z,onChange:Se=>se(Se.target.value),placeholder:s("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!F,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(it,{value:ce,onChange:Se=>oe(Se.target.value),placeholder:s("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!F,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(it,{value:xe,onChange:Se=>we(Se.target.value),placeholder:s("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!F,"data-bwignore":"true","data-1p-ignore":"true"})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:s("settings.mcp.page.advanced.oauthHint")}),Xt&&t.jsxs("p",{className:"typography-micro text-muted-foreground",children:[s("settings.mcp.page.advanced.oauthCallbackHint"),t.jsx("span",{className:"mt-1 block break-all font-mono text-foreground/80",children:Xt})]})]})]})})]})})]}),t.jsxs("div",{"data-settings-item":"mcp.environment",className:"mb-2",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[s("settings.mcp.page.env.title"),Q.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",Q.length,")"]})]})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:Q.length===0?t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>W([{key:"",value:""}]),children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.mcp.page.env.addEnvironmentVariable")]}):t.jsx(Zi,{value:Q,onChange:W,keyPlaceholder:s("settings.mcp.page.env.keyPlaceholder"),pasteLabel:s("settings.mcp.page.env.pasteEnv"),pasteTitle:s("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:s("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Se=>s("settings.mcp.page.toast.importedVariablesCount",{count:Se}),clipboardReadFailed:s("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:s("settings.mcp.page.env.key"),valueLabel:s("settings.mcp.page.env.value"),valuePlaceholder:s("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:s("settings.mcp.page.env.hide"),showValueTitle:s("settings.mcp.page.env.show"),addVariable:s("settings.mcp.page.env.addVariable"),plainTextWarning:s("settings.mcp.page.env.plainTextWarning"),removeVariableAria:s("settings.mcp.page.env.removeVariableAria")})})]}),t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[t.jsx(J,{onClick:Ge,disabled:ye||!nt&&!b,size:"xs",className:"!font-normal",children:s(ye?"settings.common.actions.saving":b?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!b&&t.jsx(J,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ge(!0),children:s("settings.common.actions.delete")})]})]}),t.jsx(Ut,{open:fe,onOpenChange:Se=>{Se||(L(!1),Je(""),et(null))},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("settings.mcp.page.importDialog.title")}),t.jsx(qt,{children:s("settings.mcp.page.importDialog.description")})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx(ps,{value:Fe,onChange:Se=>{Je(Se.target.value),et(null)},placeholder:`{
16
- "mcpServers": {
17
- "postgres": {
18
- "command": "npx",
19
- "args": ["-y", "@modelcontextprotocol/server-postgres"]
20
- }
21
- }
22
- }`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),Xe&&t.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Xe}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:pe,type:"button",children:[t.jsx(A,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),t.jsxs(Yt,{children:[t.jsx(J,{variant:"outline",onClick:()=>{L(!1),Je(""),et(null)},className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(J,{onClick:st,disabled:!Fe.trim(),size:"sm",children:s("settings.common.actions.import")})]})]})}),t.jsx(Ut,{open:ie,onOpenChange:Se=>{!Se&&!_&&ge(!1)},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("settings.mcp.page.deleteDialog.title",{name:n??""})}),t.jsxs(qt,{children:[s("settings.mcp.page.deleteDialog.descriptionPrefix")," ",t.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",s("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),t.jsxs(Yt,{children:[t.jsx(J,{variant:"outline",onClick:()=>ge(!1),disabled:_,className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(J,{variant:"destructive",size:"sm",onClick:ft,disabled:_,children:s(_?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},Vp=({transform:s})=>({...s,y:0}),_p=s=>{const e=rt.c(18),{id:n,children:a,className:r}=s;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:o,listeners:d,setNodeRef:c,transform:x,transition:m,isDragging:p}=Ec(i);let u;e[2]!==x?(u=Mc.Transform.toString(x),e[2]=x,e[3]=u):u=e[3];let S;e[4]!==u||e[5]!==m?(S={transform:u,transition:m},e[4]=u,e[5]=m,e[6]=S):S=e[6];const f=p&&"opacity-50";let g;e[7]!==r||e[8]!==f?(g=de("h-full rounded-md",r,f),e[7]=r,e[8]=f,e[9]=g):g=e[9];let h;return e[10]!==o||e[11]!==a||e[12]!==n||e[13]!==d||e[14]!==c||e[15]!==S||e[16]!==g?(h=t.jsx("div",{ref:c,"data-sortable-tab-id":n,style:S,className:g,...o,...d,children:a}),e[10]=o,e[11]=a,e[12]=n,e[13]=d,e[14]=c,e[15]=S,e[16]=g,e[17]=h):h=e[17],h},Hp=s=>{const e=rt.c(6),{id:n,children:a,className:r}=s;let i;e[0]!==r?(i=de("h-full",r),e[0]=r,e[1]=i):i=e[1];let o;return e[2]!==a||e[3]!==n||e[4]!==i?(o=t.jsx("div",{className:i,"data-sortable-tab-id":n,children:a}),e[2]=a,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},xn=s=>{const e=rt.c(121),{items:n,activeId:a,onSelect:r,onClose:i,onReorder:o,layoutMode:d,variant:c,activePillInsetClassName:x,activePillButtonClassName:m,inactiveTabsIconOnly:p,iconOnlyActiveTab:u,animateActivePill:S,activePillLowercase:f,className:g}=s,h=d===void 0?"scrollable":d,D=c===void 0?"default":c,k=p===void 0?!1:p,w=u===void 0?!1:u,E=f===void 0?!0:f,{t:N}=dt(),y=Ke(Wp),{isTablet:b}=Cs(),P=y||b,z=l.useRef(null);let M;e[0]===Symbol.for("react.memo_cache_sentinel")?(M={left:!1,right:!1},e[0]=M):M=e[0];const[I,v]=l.useState(M);let j;e[1]!==n?(j=n.map(qp),e[1]=n,e[2]=j):j=e[2];const O=j,T=h==="scrollable",U=D==="default",B=D==="active-pill",Q=D==="animated",W=B||Q,R=U,Y=W||R,F=B&&T,H=W,X=S??Q,re=typeof o=="function",Z=re?_p:Hp;let se;e[3]===Symbol.for("react.memo_cache_sentinel")?(se=new Map,e[3]=se):se=e[3];const ce=l.useRef(se),[oe,xe]=l.useState(null);let we;e[4]===Symbol.for("react.memo_cache_sentinel")?(we={activationConstraint:{distance:8}},e[4]=we):we=e[4];const he=Ic(Dc(Ac,we)),Ie=Gp;let ve;e[5]===Symbol.for("react.memo_cache_sentinel")?(ve=(Ze,We)=>{if(We){ce.current.set(Ze,We);return}ce.current.delete(Ze)},e[5]=ve):ve=e[5];const be=ve;let ye;e[6]!==a||e[7]!==Y?(ye=()=>{if(!Y||!a){xe(Jp);return}const Ze=z.current,We=ce.current.get(a);if(!Ze||!We){xe(Qp);return}let pt=0,pe=0,st=We;for(;st&&st!==Ze;)pt=pt+st.offsetLeft,pe=pe+st.offsetTop,st=st.offsetParent;const nt={left:pt,top:pe,width:We.offsetWidth,height:We.offsetHeight};xe(Ge=>Ie(Ge,nt)?Ge:nt)},e[6]=a,e[7]=Y,e[8]=ye):ye=e[8];const te=ye;let ie;e[9]!==T?(ie=()=>{if(!T){v({left:!1,right:!1});return}const Ze=z.current;if(!Ze){v({left:!1,right:!1});return}v({left:Ze.scrollLeft>2,right:Ze.scrollLeft+Ze.clientWidth<Ze.scrollWidth-2})},e[9]=T,e[10]=ie):ie=e[10];const ge=ie;let _;e[11]!==T||e[12]!==ge?(_=()=>{if(!T){v({left:!1,right:!1});return}const Ze=z.current;if(!Ze)return;ge(),Ze.addEventListener("scroll",ge,{passive:!0});const We=new ResizeObserver(ge);return We.observe(Ze),()=>{Ze.removeEventListener("scroll",ge),We.disconnect()}},e[11]=T,e[12]=ge,e[13]=_):_=e[13];let ee;e[14]!==T||e[15]!==n.length||e[16]!==ge?(ee=[T,n.length,ge],e[14]=T,e[15]=n.length,e[16]=ge,e[17]=ee):ee=e[17],l.useEffect(_,ee);let ne;e[18]!==a||e[19]!==te||e[20]!==Y?(ne=()=>{if(!Y){xe(null);return}te();const Ze=z.current;if(!Ze)return;const We=new ResizeObserver(te);if(We.observe(Ze),a){const pt=ce.current.get(a);pt&&We.observe(pt)}return()=>{We.disconnect()}},e[18]=a,e[19]=te,e[20]=Y,e[21]=ne):ne=e[21];let ue;e[22]!==a||e[23]!==n.length||e[24]!==te||e[25]!==Y?(ue=[a,n.length,te,Y],e[22]=a,e[23]=n.length,e[24]=te,e[25]=Y,e[26]=ue):ue=e[26],l.useEffect(ne,ue);let Me;e[27]!==te?(Me=()=>{te()},e[27]=te,e[28]=Me):Me=e[28],l.useLayoutEffect(Me);let ke;e[29]!==a||e[30]!==T||e[31]!==ge?(ke=()=>{if(!T||!a)return;const Ze=z.current;if(!Ze)return;const We=window.requestAnimationFrame(()=>{const pt=typeof window.CSS?.escape=="function"?window.CSS.escape(a):a.replace(/"/g,'\\"'),pe=Ze.querySelector(`[data-sortable-tab-id="${pt}"]`);pe&&(pe.scrollIntoView({block:"nearest",inline:"nearest"}),ge())});return()=>{window.cancelAnimationFrame(We)}},e[29]=a,e[30]=T,e[31]=ge,e[32]=ke):ke=e[32];let De;e[33]!==a||e[34]!==T||e[35]!==n.length||e[36]!==ge?(De=[a,T,n.length,ge],e[33]=a,e[34]=T,e[35]=n.length,e[36]=ge,e[37]=De):De=e[37],l.useEffect(ke,De);let Ae;e[38]!==o?(Ae=Ze=>{if(!o)return;const{active:We,over:pt}=Ze;!pt||We.id===pt.id||o(String(We.id),String(pt.id))},e[38]=o,e[39]=Ae):Ae=e[39];const Pe=Ae;let Re;e[40]!==g?(Re=de("relative flex h-full min-w-0 flex-1",g),e[40]=g,e[41]=Re):Re=e[41];let Oe;e[42]!==T||e[43]!==I||e[44]!==W?(Oe=T&&I.left?t.jsx("div",{className:de("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",W?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=T,e[43]=I,e[44]=W,e[45]=Oe):Oe=e[45];let $e;e[46]!==T||e[47]!==I||e[48]!==W?($e=T&&I.right?t.jsx("div",{className:de("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",W?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=T,e[47]=I,e[48]=W,e[49]=$e):$e=e[49];const Be=W?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Le=W&&"@container/pill-tabs",Ue=W&&"pill-tabs__track",le=W&&(x??"gap-0.5 py-0.5"),q=R&&"items-center overflow-y-hidden",me=H&&"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",Ne=T?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Ee;e[50]!==Be||e[51]!==Le||e[52]!==Ue||e[53]!==le||e[54]!==q||e[55]!==me||e[56]!==Ne?(Ee=de("relative flex h-full min-w-0 flex-1",Be,Le,Ue,le,q,me,Ne),e[50]=Be,e[51]=Le,e[52]=Ue,e[53]=le,e[54]=q,e[55]=me,e[56]=Ne,e[57]=Ee):Ee=e[57];let Ce;e[58]!==T?(Ce=T?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=T,e[59]=Ce):Ce=e[59];let He;e[60]!==N?(He=N("sortableTabsStrip.aria.tabs"),e[60]=N,e[61]=He):He=e[61];let G;e[62]!==oe||e[63]!==X||e[64]!==W?(G=W&&oe?t.jsx("div",{className:de("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${oe.left}px, ${oe.top}px, 0)`,width:`${oe.width}px`,height:`${oe.height}px`,transition:X?"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]=oe,e[63]=X,e[64]=W,e[65]=G):G=e[65];let $;e[66]!==oe||e[67]!==R?($=R&&oe?t.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(${oe.left}px, 0, 0)`,width:`${oe.width}px`},"aria-hidden":!0}):null,e[66]=oe,e[67]=R,e[68]=$):$=e[68];let fe;if(e[69]!==Z||e[70]!==a||e[71]!==m||e[72]!==E||e[73]!==P||e[74]!==w||e[75]!==k||e[76]!==B||e[77]!==y||e[78]!==T||e[79]!==n||e[80]!==i||e[81]!==r||e[82]!==F||e[83]!==W){let Ze;e[85]!==Z||e[86]!==a||e[87]!==m||e[88]!==E||e[89]!==P||e[90]!==w||e[91]!==k||e[92]!==B||e[93]!==y||e[94]!==T||e[95]!==i||e[96]!==r||e[97]!==F||e[98]!==W?(Ze=We=>{const pt=We.id===a,pe=k&&W&&!pt&&!!We.icon,st=!pe,nt=!!We.icon&&(!w||pt),Ge=k&&W&&pt&&!T&&!F,ft=We.closable!==!1&&!!i,wt=ft&&!!We.icon,Ct=T||F?void 0:W?Ge?"flex-none basis-auto":y?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",ae=ft?tt=>{tt.button===1&&(tt.preventDefault(),tt.stopPropagation(),i?.(We.id))}:void 0,Ve=ft?Yp:void 0;return t.jsx(Z,{id:We.id,className:Ct,children:t.jsxs("div",{ref:tt=>be(We.id,tt),onAuxClick:ae,onMouseDown:Ve,className:de("group flex h-full min-w-0 flex-nowrap items-center",T||F?"shrink-0":W?"w-full":"w-full min-w-0",W?"relative z-10 bg-transparent":pt?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[t.jsx("button",{type:"button",role:"tab","aria-selected":pt,"aria-label":pe?We.title??We.label:void 0,onClick:()=>r(We.id),className:de(W?"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",W&&E?"lowercase":null,W&&(pe?"gap-0":"gap-1.5"),W?F?"shrink-0 whitespace-nowrap px-3 text-center":T?"max-w-56 shrink-0 px-3 text-center":pe?"px-2 !min-w-0 text-center":Ge?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":T?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",W?m??(B?y?"h-[38px]":"h-[31px]":"h-7"):null,W?pt?"text-foreground":"text-muted-foreground hover:text-foreground":null,W?"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:We.title??We.label,children:W?t.jsxs(t.Fragment,{children:[nt?t.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[t.jsx("span",{className:de("flex items-center justify-center transition-opacity",wt&&(P?"opacity-0":"group-hover:opacity-0")),children:We.icon}),wt?t.jsx("span",{role:"button",tabIndex:-1,className:de("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",P?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Xp,onClick:tt=>{tt.stopPropagation(),i?.(We.id)},"aria-label":We.closeLabel??`Close ${We.label} tab`,title:We.closeLabel??`Close ${We.label} tab`,children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,st?t.jsx("span",{className:"animated-tabs__label truncate",children:We.label}):null]}):t.jsxs("span",{className:de("flex min-w-0 flex-nowrap items-center gap-1.5",!T&&"justify-center"),children:[nt?t.jsxs("span",{className:de("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",pt?"text-[var(--primary-base)]":"text-muted-foreground"),children:[t.jsx("span",{className:de("flex items-center justify-center transition-opacity",wt&&(P?"opacity-0":"group-hover:opacity-0")),children:We.icon}),wt?t.jsx("span",{role:"button",tabIndex:-1,className:de("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",P?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Zp,onClick:tt=>{tt.stopPropagation(),i?.(We.id)},"aria-label":We.closeLabel??`Close ${We.label} tab`,title:We.closeLabel??`Close ${We.label} tab`,children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,t.jsx("span",{className:"truncate leading-[1.2]",children:We.label})]})}),ft&&!wt?t.jsx("button",{type:"button",onPointerDown:eg,onClick:tt=>{tt.stopPropagation(),i?.(We.id)},className:de("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",W?"-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",W?pt?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":pt?"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":We.closeLabel??`Close ${We.label} tab`,title:We.closeLabel??`Close ${We.label} tab`,children:t.jsx(A,{name:"close",className:"h-3 w-3"})}):null]})},We.id)},e[85]=Z,e[86]=a,e[87]=m,e[88]=E,e[89]=P,e[90]=w,e[91]=k,e[92]=B,e[93]=y,e[94]=T,e[95]=i,e[96]=r,e[97]=F,e[98]=W,e[99]=Ze):Ze=e[99],fe=n.map(Ze),e[69]=Z,e[70]=a,e[71]=m,e[72]=E,e[73]=P,e[74]=w,e[75]=k,e[76]=B,e[77]=y,e[78]=T,e[79]=n,e[80]=i,e[81]=r,e[82]=F,e[83]=W,e[84]=fe}else fe=e[84];let L;e[100]!==Ee||e[101]!==Ce||e[102]!==He||e[103]!==G||e[104]!==$||e[105]!==fe?(L=t.jsxs("div",{ref:z,className:Ee,style:Ce,role:"tablist","aria-label":He,children:[G,$,fe]}),e[100]=Ee,e[101]=Ce,e[102]=He,e[103]=G,e[104]=$,e[105]=fe,e[106]=L):L=e[106];let Fe;e[107]!==Re||e[108]!==Oe||e[109]!==$e||e[110]!==L?(Fe=t.jsxs("div",{className:Re,children:[Oe,$e,L]}),e[107]=Re,e[108]=Oe,e[109]=$e,e[110]=L,e[111]=Fe):Fe=e[111];const Je=Fe;if(!re)return Je;let Xe;e[112]===Symbol.for("react.memo_cache_sentinel")?(Xe=[Vp],e[112]=Xe):Xe=e[112];let et;e[113]!==O||e[114]!==Je?(et=t.jsx(Rc,{items:O,strategy:Tc,children:Je}),e[113]=O,e[114]=Je,e[115]=et):et=e[115];let at;e[116]===Symbol.for("react.memo_cache_sentinel")?(at=t.jsx(Fc,{dropAnimation:null}),e[116]=at):at=e[116];let lt;return e[117]!==Pe||e[118]!==he||e[119]!==et?(lt=t.jsxs(Oc,{sensors:he,collisionDetection:Lc,onDragEnd:Pe,modifiers:Xe,children:[et,at]}),e[117]=Pe,e[118]=he,e[119]=et,e[120]=lt):lt=e[120],lt};function Wp(s){return s.isMobile}function qp(s){return s.id}function Gp(s,e){return!s||!e?s===e:Math.abs(s.left-e.left)<.5&&Math.abs(s.top-e.top)<.5&&Math.abs(s.width-e.width)<.5&&Math.abs(s.height-e.height)<.5}function Jp(s){return s===null?s:null}function Qp(s){return s===null?s:null}function Yp(s){s.button===1&&s.preventDefault()}function Xp(s){s.stopPropagation()}function Zp(s){s.stopPropagation()}function eg(s){s.stopPropagation()}const Pa=()=>{try{const e=as.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=Ns.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[PluginsStore] Error resolving config directory:",s)}return null},tg=800,sg=5e3,ng="__default__",Er=new Map,rr=new Map,ag=1500,Tl=s=>s?.trim()||ng,rg=s=>{Er.delete(Tl(s))},os=rn()(Zn($r((s,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:n=>s({selectedId:n}),setDraft:n=>s({draft:n}),loadPlugins:async n=>{const a=Pa(),r=Tl(a),i=Date.now(),o=Er.get(r)??0,d=e().entries.length>0||e().files.length>0;if(!n?.force&&d&&i-o<sg)return!0;const c=rr.get(r);if(!n?.force&&c)return c;const x=(async()=>{s({isLoading:!0});try{const m=await jt(Xs("/api/config/plugins",a),{headers:Bn(a)});if(!m.ok)throw new Error("Failed to load plugins");const p=await Ia(m);return s({entries:p.entries??[],files:p.files??[],isLoading:!1}),Er.set(r,Date.now()),n?.force||e().loadRegistryInfo(),!0}catch(m){return console.error("[PluginsStore] Failed to load plugins:",m),s({isLoading:!1}),!1}})();rr.set(r,x);try{return await x}finally{rr.delete(r)}},loadRegistryInfo:async n=>{const a=og(n?.specs??e().entries.map(r=>r.spec));if(a.length===0){s({isLoadingRegistry:!1});return}s({isLoadingRegistry:!0});try{const r=Pa(),i={...e().registryInfo};for(const o of lg(a)){const d=await jt(ig(o,n?.force===!0,r),{headers:Bn(r)});if(!d.ok)throw new Error("Failed to load plugin registry info");const c=await Ia(d);for(const x of c.results??[])i[x.spec]=x}s({registryInfo:i,isLoadingRegistry:!1})}catch(r){console.error("[PluginsStore] Failed to load plugin registry info:",r),s({isLoadingRegistry:!1})}},updateToLatest:async n=>{const a=e().entries.find(i=>i.id===n);if(!a)return{ok:!1};const r=e().registryInfo[a.spec];return!r||r.kind!=="npm-ok"||!r.hasUpdate||!r.latestVersion?{ok:!1}:await e().updateEntry(n,{spec:`${r.name}@${r.latestVersion}`})},createEntry:async n=>{const a=await jn("Creating plugin entry…",async r=>await jt(Xs("/api/config/plugins/entry",r),{method:"POST",headers:pa(r),body:JSON.stringify(so(n))}),e);return a.ok&&e().loadRegistryInfo({specs:[n.spec],force:!0}),a},updateEntry:async(n,a)=>{const r=e().entries.find(d=>d.id===n)?.spec,i=a.spec??r,o=await jn("Updating plugin entry…",async d=>await jt(Xs(`/api/config/plugins/entry/${encodeURIComponent(n)}`,d),{method:"PATCH",headers:pa(d),body:JSON.stringify(so(a))}),e);return o.ok&&i&&e().loadRegistryInfo({specs:[i],force:!0}),o},deleteEntry:async n=>{const a=e().entries.find(i=>i.id===n),r=await jn("Deleting plugin entry…",async i=>await jt(Xs(`/api/config/plugins/entry/${encodeURIComponent(n)}`,i),{method:"DELETE",headers:Bn(i)}),e);if(r.ok&&e().selectedId===n&&s({selectedId:null}),r.ok&&a){const i={...e().registryInfo};delete i[a.spec],s({registryInfo:i})}return r},readFile:async n=>{try{const a=Pa(),r=await jt(Xs(`/api/config/plugins/file/${encodeURIComponent(n)}`,a),{headers:Bn(a)});if(!r.ok)throw new Error("Failed to read plugin file");return await Ia(r)}catch(a){return console.error("[PluginsStore] Failed to read plugin file:",a),null}},createFile:async n=>jn("Creating plugin file…",async a=>await jt(Xs("/api/config/plugins/file",a),{method:"POST",headers:pa(a),body:JSON.stringify(n)}),e),updateFile:async(n,a)=>jn("Updating plugin file…",async r=>await jt(Xs(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{method:"PUT",headers:pa(r),body:JSON.stringify(a)}),e),deleteFile:async n=>{const a=await jn("Deleting plugin file…",async r=>await jt(Xs(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{method:"DELETE",headers:Bn(r)}),e);return a.ok&&e().selectedId===n&&s({selectedId:null}),a},getById:n=>e().entries.find(a=>a.id===n)??e().files.find(a=>a.id===n)}),{name:"plugins-store",storage:Ur(()=>Yn()),partialize:s=>({selectedId:s.selectedId})}),{name:"plugins-store"}));function Xs(s,e){const n=e?`?directory=${encodeURIComponent(e)}`:"";return`${s}${n}`}function ig(s,e,n){const a=new URLSearchParams;e&&a.set("refresh","true"),n&&a.set("directory",n);const r=a.toString();return`/api/config/plugins/registry?${`specs=${s.map(encodeURIComponent).join(",")}`}${r?`&${r}`:""}`}function og(s){return Array.from(new Set(s.map(e=>e.trim()).filter(Boolean)))}function lg(s){const e=[];let n=[],a=0;for(const r of s){const i=encodeURIComponent(r),o=n.length===0?i.length:a+1+i.length;n.length>0&&o>ag?(e.push(n),n=[r],a=i.length):(n.push(r),a=o)}return n.length>0&&e.push(n),e}function Bn(s){return s?{"x-opencode-directory":s}:void 0}function pa(s){return{"Content-Type":"application/json",...s?{"x-opencode-directory":s}:{}}}function so(s){const e={};return s.spec!==void 0&&(e.spec=s.spec),s.options!==void 0&&(e.options=s.options),s.scope!==void 0&&(e.scope=s.scope),e}async function jn(s,e,n){Na(s);let a=!1;try{const r=Pa(),i=await e(r),o=await Ia(i).catch(()=>null);if(!i.ok)throw new Error(o?.error||"Failed to update plugin configuration");return rg(r),o?.requiresReload&&(a=!0,await ka({message:o.message,delayMs:o.reloadDelayMs??tg,scopes:["all"]})),await n().loadPlugins({force:!0}),{ok:!0,reloadFailed:o?.reloadFailed===!0,message:o?.message,warning:o?.warning}}catch(r){return console.error("[PluginsStore] Failed to update plugin configuration:",r),{ok:!1}}finally{a||Sa()}}async function Ia(s){return await s.json()}const cg=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function dg(s){const e=s.trim();if(e==="")return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}const mg=({open:s,onOpenChange:e,defaultScope:n="user"})=>{const{t:a}=dt(),r=os(T=>T.createEntry),i=os(T=>T.createFile),[o,d]=l.useState("npm"),[c,x]=l.useState(""),[m,p]=l.useState(""),[u,S]=l.useState(""),[f,g]=l.useState(""),[h,D]=l.useState(n),[k,w]=l.useState(!1),E=l.useCallback(()=>{x(""),p(""),S(""),g(""),D(n)},[n]);l.useEffect(()=>{s&&(d("npm"),E())},[s,E]);const N=T=>{T!==o&&(d(T),E())},y=l.useMemo(()=>dg(m),[m]),b=!y.ok,P=o==="file"&&u.trim()!==""&&!cg.test(u.trim()),z=(o==="npm"||o==="path")&&c.trim()==="",M=o==="file"&&f.trim()==="",I=o==="file"&&u.trim()==="",v=k||b||o==="npm"&&z||o==="path"&&z||o==="file"&&(I||P||M),j=async()=>{if(!v){w(!0);try{let T;o==="file"?T=await i({fileName:u.trim(),content:f,scope:h}):T=await r({spec:c.trim(),options:y.ok?y.value:void 0,scope:h}),T.ok?(V.success(T.message||a("settings.plugins.toast.created")),T.reloadFailed&&V.warning(a("settings.plugins.toast.reloadFailed")),e(!1)):V.error(T.message||a("settings.plugins.sidebar.toast.deleteFailed"))}finally{w(!1)}}},O=l.useMemo(()=>[{id:"npm",label:a("settings.plugins.dialog.add.tab.npm")},{id:"path",label:a("settings.plugins.dialog.add.tab.path")},{id:"file",label:a("settings.plugins.dialog.add.tab.file")}],[a]);return t.jsx(Ut,{open:s,onOpenChange:T=>{!T&&k||e(T)},children:t.jsxs(Bt,{className:"max-w-xl",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:a("settings.plugins.dialog.add.title")}),t.jsx(qt,{children:a("settings.plugins.sidebar.empty.description")})]}),t.jsx(xn,{items:O,activeId:o,onSelect:T=>N(T),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),t.jsxs("div",{className:"flex flex-col gap-4",children:[(o==="npm"||o==="path")&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[t.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.spec")}),t.jsx(it,{id:"plugin-spec",value:c,onChange:T=>x(T.target.value),placeholder:a("settings.plugins.page.field.spec.placeholder"),"aria-invalid":z?!1:void 0,disabled:k}),z&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.plugins.validation.specRequired")})]}),t.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[t.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.options")}),t.jsx(ps,{id:"plugin-options",value:m,onChange:T=>p(T.target.value),rows:5,className:"font-mono",hasError:b,disabled:k}),b&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:a("settings.plugins.page.field.options.invalidJson")})]})]}),o==="file"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[t.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.fileName")}),t.jsx(it,{id:"plugin-filename",value:u,onChange:T=>S(T.target.value),placeholder:"my-plugin.ts","aria-invalid":P||void 0,disabled:k}),P&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:a("settings.plugins.validation.fileName")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.content")}),t.jsx(ps,{id:"plugin-content",value:f,onChange:T=>g(T.target.value),rows:16,className:"font-mono",disabled:k})]})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.scope")}),t.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(T=>{const U=h===T,B=a(T==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return t.jsxs("button",{type:"button",onClick:()=>D(T),disabled:k,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[t.jsx(Sn,{checked:U,onChange:()=>D(T),ariaLabel:B}),t.jsx("span",{className:de("typography-ui-label font-normal",U?"text-foreground":"text-foreground/60"),children:B})]},T)})})]})]}),t.jsxs(Yt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:k,children:a("settings.plugins.dialog.add.action.cancel")}),t.jsxs(J,{size:"sm",onClick:()=>{j()},disabled:v,children:[k?t.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,a("settings.plugins.dialog.add.action.submit")]})]})]})})},ug=s=>{const e=rt.c(33),{spec:n}=s;let a;e[0]!==n?(a=d=>d.registryInfo[n],e[0]=n,e[1]=a):a=e[1];const r=os(a),{t:i}=dt();if(!r)return null;const o=pg;switch(r.kind){case"npm-ok":{if(!r.hasUpdate||!r.latestVersion)return null;let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(A,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=d):d=e[2];let c;e[3]!==r.latestVersion?(c=t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[d,r.latestVersion]}),e[3]=r.latestVersion,e[4]=c):c=e[4];let x;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==c?(x=o(c,i("settings.plugins.registry.badge.update.tooltip",{current:r.currentVersion??"",latest:r.latestVersion})),e[5]=r.currentVersion,e[6]=r.latestVersion,e[7]=i,e[8]=c,e[9]=x):x=e[9],x}case"npm-missing-version":{let d;e[10]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=d):d=e[10];let c;return e[11]!==r.currentVersion||e[12]!==r.name||e[13]!==i?(c=o(d,i("settings.plugins.registry.badge.missingVersion.tooltip",{version:r.currentVersion,name:r.name})),e[11]=r.currentVersion,e[12]=r.name,e[13]=i,e[14]=c):c=e[14],c}case"npm-missing-package":{let d;e[15]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=d):d=e[15];let c;return e[16]!==r.name||e[17]!==i?(c=o(d,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:r.name})),e[16]=r.name,e[17]=i,e[18]=c):c=e[18],c}case"npm-malformed":{let d;e[19]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=d):d=e[19];let c;return e[20]!==i?(c=o(d,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=c):c=e[21],c}case"npm-network":{let d;e[22]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(A,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=d):d=e[22];let c;return e[23]!==i?(c=o(d,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=c):c=e[24],c}case"path-missing":{let d;e[25]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=d):d=e[25];let c;return e[26]!==r.absolutePath||e[27]!==i?(c=o(d,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:r.absolutePath})),e[26]=r.absolutePath,e[27]=i,e[28]=c):c=e[28],c}case"path-unreadable":{let d;e[29]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=d):d=e[29];let c;return e[30]!==r.absolutePath||e[31]!==i?(c=o(d,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:r.absolutePath})),e[30]=r.absolutePath,e[31]=i,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function pg(s,e){return t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:s})}),t.jsx(Et,{children:e})]})}const Fl=s=>{const e=rt.c(26),{header:n,footer:a,children:r,className:i,variant:o}=s,d=o===void 0?"sidebar":o,c=gs(),x=l.useRef(null),[m,p]=l.useState(!1),[u,S]=l.useState(!1),f=d==="background"||c?"bg-background":"bg-sidebar",g=f==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const v=x.current;if(!v){p(!1),S(!1);return}if(!(v.scrollHeight>v.clientHeight+1)){p(!1),S(!1);return}p(v.scrollTop>1),S(v.scrollTop+v.clientHeight<v.scrollHeight-1)},e[0]=h):h=e[0];const D=h;let k;e[1]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{D()},e[1]=k):k=e[1];let w;e[2]!==r?(w=[r,D],e[2]=r,e[3]=w):w=e[3],l.useEffect(k,w);let E,N;e[4]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{const v=x.current;if(!v)return;const j=()=>D();return v.addEventListener("scroll",j,{passive:!0}),()=>v.removeEventListener("scroll",j)},N=[D],e[4]=E,e[5]=N):(E=e[4],N=e[5]),l.useEffect(E,N);let y;e[6]!==f||e[7]!==i?(y=de("flex h-full flex-col",f,i),e[6]=f,e[7]=i,e[8]=y):y=e[8];let b;e[9]!==r?(b=t.jsx(Jt,{ref:x,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:r}),e[9]=r,e[10]=b):b=e[10];let P;e[11]!==g||e[12]!==m?(P=m&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${g} 0%, transparent 100%)`}}),e[11]=g,e[12]=m,e[13]=P):P=e[13];let z;e[14]!==g||e[15]!==u?(z=u&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${g} 0%, transparent 100%)`}}),e[14]=g,e[15]=u,e[16]=z):z=e[16];let M;e[17]!==z||e[18]!==b||e[19]!==P?(M=t.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[b,P,z]}),e[17]=z,e[18]=b,e[19]=P,e[20]=M):M=e[20];let I;return e[21]!==a||e[22]!==n||e[23]!==M||e[24]!==y?(I=t.jsxs("div",{className:y,children:[n,M,a]}),e[21]=a,e[22]=n,e[23]=M,e[24]=y,e[25]=I):I=e[25],I},Mr=s=>{const e=rt.c(23),{title:n,metadata:a,selected:r,onSelect:i,icon:o,actions:d,className:c}=s,x=r===void 0?!1:r,m=d&&d.length>0,p=x?"bg-interactive-selection":"hover:bg-interactive-hover";let u;e[0]!==c||e[1]!==p?(u=de("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",p,c),e[0]=c,e[1]=p,e[2]=u):u=e[2];let S;e[3]!==n?(S=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=S):S=e[4];let f;e[5]!==o||e[6]!==S?(f=t.jsxs("div",{className:"flex items-center gap-1.5",children:[o,S]}),e[5]=o,e[6]=S,e[7]=f):f=e[7];let g;e[8]!==a?(g=a&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a}),e[8]=a,e[9]=g):g=e[9];let h;e[10]!==i||e[11]!==f||e[12]!==g?(h=t.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[f,g]}),e[10]=i,e[11]=f,e[12]=g,e[13]=h):h=e[13];let D;e[14]!==d||e[15]!==m?(D=m&&t.jsxs(us,{children:[t.jsx(ds,{asChild:!0,children:t.jsx(J,{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:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:d.map(gg)})]}),e[14]=d,e[15]=m,e[16]=D):D=e[16];let k;e[17]!==h||e[18]!==D?(k=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[h,D]}),e[17]=h,e[18]=D,e[19]=k):k=e[19];let w;return e[20]!==u||e[21]!==k?(w=t.jsx("div",{className:u,children:k}),e[20]=u,e[21]=k,e[22]=w):w=e[22],w};function gg(s){const e=s.icon;return t.jsxs(js,{onClick:n=>{n.stopPropagation(),s.onClick()},className:de(s.destructive&&"text-destructive focus:text-destructive"),children:[e&&t.jsx(A,{name:e,className:"h-4 w-4 mr-px"}),s.label]},s.label)}const hg=s=>s.parsedKind==="npm"?"code-box":"folder",fg=s=>{const e=rt.c(144),{onItemSelect:n,onAddClick:a}=s,{t:r}=dt(),{entries:i,files:o,selectedId:d,setSelected:c,deleteEntry:x,deleteFile:m,loadPlugins:p}=os(Ss(xg)),u=os(bg),S=os(yg),f=os(vg),g=os(jg),[h,D]=l.useState(null),[k,w]=l.useState(!1),[E,N]=l.useState(!1);let y,b;e[0]!==p?(y=()=>{p()},b=[p],e[0]=p,e[1]=y,e[2]=b):(y=e[1],b=e[2]),l.useEffect(y,b);let P,z;e[3]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const pe=()=>N(!0);return window.addEventListener("openchamber:settings-open-plugin-add",pe),()=>window.removeEventListener("openchamber:settings-open-plugin-add",pe)},z=[],e[3]=P,e[4]=z):(P=e[3],z=e[4]),l.useEffect(P,z);let M;if(e[5]!==i||e[6]!==u){M={userEntries:0,projectEntries:0};for(const pe of i){const st=u[pe.spec];st?.kind==="npm-ok"&&st.hasUpdate&&(pe.scope==="user"?M.userEntries=M.userEntries+1:pe.scope==="project"&&(M.projectEntries=M.projectEntries+1))}e[5]=i,e[6]=u,e[7]=M}else M=e[7];const I=M;let v;e[8]!==i?(v=i.filter(wg),e[8]=i,e[9]=v):v=e[9];const j=v;let O;e[10]!==i?(O=i.filter(Ng),e[10]=i,e[11]=O):O=e[11];const T=O;let U;e[12]!==o?(U=o.filter(kg),e[12]=o,e[13]=U):U=e[13];const B=U;let Q;e[14]!==o?(Q=o.filter(Sg),e[14]=o,e[15]=Q):Q=e[15];const W=Q,R=i.length+o.length,Y=R===0;let F;e[16]!==a?(F=()=>{a?a():N(!0)},e[16]=a,e[17]=F):F=e[17];const H=F;let X;e[18]!==n||e[19]!==c?(X=pe=>{c(pe),n?.()},e[18]=n,e[19]=c,e[20]=X):X=e[20];const re=X;let Z;e[21]!==i||e[22]!==u||e[23]!==r||e[24]!==g?(Z=async pe=>{const st=i.find(wt=>wt.id===pe);if(!st)return;const nt=u[st.spec];if(!nt||nt.kind!=="npm-ok"||!nt.hasUpdate||!nt.latestVersion)return;const Ge=nt.latestVersion;(await g(pe)).ok?V.success(r("settings.plugins.toast.updatedToLatest",{version:Ge})):V.error(r("settings.plugins.toast.refreshFailed"))},e[21]=i,e[22]=u,e[23]=r,e[24]=g,e[25]=Z):Z=e[25];const se=Z;let ce;e[26]!==f||e[27]!==r?(ce=async()=>{V.info(r("settings.plugins.toast.refreshing"));try{await f({force:!0})}catch{V.error(r("settings.plugins.toast.refreshFailed"))}},e[26]=f,e[27]=r,e[28]=ce):ce=e[28];const oe=ce;let xe;e[29]!==x||e[30]!==m||e[31]!==h||e[32]!==r?(xe=async()=>{if(!h)return;w(!0);const pe=h.kind==="entry"?await x(h.id):await m(h.id);pe.ok?V.success(pe.message||r("settings.plugins.sidebar.toast.deleted",{name:h.label})):V.error(r("settings.plugins.sidebar.toast.deleteFailed")),D(null),w(!1)},e[29]=x,e[30]=m,e[31]=h,e[32]=r,e[33]=xe):xe=e[33];const we=xe;let he;e[34]!==re||e[35]!==se||e[36]!==u||e[37]!==d||e[38]!==r?(he=pe=>{const st=u[pe.spec],nt=st?.kind==="npm-ok"&&st.hasUpdate&&!!st.latestVersion,Ge=[];return nt&&Ge.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{se(pe.id)}}),Ge.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>D({kind:"entry",id:pe.id,label:pe.spec})}),t.jsx(Mr,{title:t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate",children:pe.spec}),t.jsx(ug,{spec:pe.spec})]}),metadata:pe.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:d===pe.id,onSelect:()=>re(pe.id),icon:t.jsx(A,{name:hg(pe),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Ge},pe.id)},e[34]=re,e[35]=se,e[36]=u,e[37]=d,e[38]=r,e[39]=he):he=e[39];const Ie=he;let ve;e[40]!==re||e[41]!==d||e[42]!==r?(ve=pe=>t.jsx(Mr,{title:pe.fileName,metadata:r("settings.plugins.sidebar.kind.file"),selected:d===pe.id,onSelect:()=>re(pe.id),icon:t.jsx(A,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>D({kind:"file",id:pe.id,label:pe.fileName})}]},pe.id),e[40]=re,e[41]=d,e[42]=r,e[43]=ve):ve=e[43];const be=ve;let ye;e[44]!==r?(ye=(pe,st,nt)=>{const Ge=nt===void 0?0:nt;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[pe,Ge>0&&t.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(Ge===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Ge})})]}),st]})},e[44]=r,e[45]=ye):ye=e[45];const te=ye;let ie;e[46]!==r?(ie=r("settings.plugins.sidebar.title"),e[46]=r,e[47]=ie):ie=e[47];let ge;e[48]!==ie?(ge=t.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:t.jsx("h2",{className:"text-base font-semibold text-foreground",children:ie})}),e[48]=ie,e[49]=ge):ge=e[49];let _;e[50]!==r||e[51]!==R?(_=r("settings.plugins.sidebar.total",{count:R}),e[50]=r,e[51]=R,e[52]=_):_=e[52];let ee;e[53]!==_?(ee=t.jsx("span",{className:"typography-meta text-muted-foreground",children:_}),e[53]=_,e[54]=ee):ee=e[54];let ne;e[55]!==oe?(ne=()=>{oe()},e[55]=oe,e[56]=ne):ne=e[56];let ue;e[57]!==r?(ue=r("settings.plugins.sidebar.actions.refresh"),e[57]=r,e[58]=ue):ue=e[58];let Me;e[59]!==r?(Me=r("settings.plugins.sidebar.actions.refresh"),e[59]=r,e[60]=Me):Me=e[60];const ke=S?"size-4 animate-spin":"size-4";let De;e[61]!==ke?(De=t.jsx(A,{name:"refresh",className:ke}),e[61]=ke,e[62]=De):De=e[62];let Ae;e[63]!==S||e[64]!==ne||e[65]!==ue||e[66]!==Me||e[67]!==De?(Ae=t.jsx(J,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:ne,disabled:S,"aria-label":ue,title:Me,children:De}),e[63]=S,e[64]=ne,e[65]=ue,e[66]=Me,e[67]=De,e[68]=Ae):Ae=e[68];let Pe;e[69]!==r?(Pe=r("settings.plugins.sidebar.actions.addTitle"),e[69]=r,e[70]=Pe):Pe=e[70];let Re;e[71]!==r?(Re=r("settings.plugins.sidebar.actions.addTitle"),e[71]=r,e[72]=Re):Re=e[72];let Oe;e[73]===Symbol.for("react.memo_cache_sentinel")?(Oe=t.jsx(A,{name:"add",className:"size-4"}),e[73]=Oe):Oe=e[73];let $e;e[74]!==H||e[75]!==Pe||e[76]!==Re?($e=t.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:H,"aria-label":Pe,title:Re,children:Oe}),e[74]=H,e[75]=Pe,e[76]=Re,e[77]=$e):$e=e[77];let Be;e[78]!==Ae||e[79]!==$e?(Be=t.jsxs("div",{className:"flex items-center gap-1",children:[Ae,$e]}),e[78]=Ae,e[79]=$e,e[80]=Be):Be=e[80];let Le;e[81]!==ee||e[82]!==Be?(Le=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ee,Be]}),e[81]=ee,e[82]=Be,e[83]=Le):Le=e[83];let Ue;e[84]!==ge||e[85]!==Le?(Ue=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ge,Le]}),e[84]=ge,e[85]=Le,e[86]=Ue):Ue=e[86];let le;e[87]!==Y||e[88]!==T||e[89]!==W||e[90]!==Ie||e[91]!==be||e[92]!==te||e[93]!==r||e[94]!==I||e[95]!==j||e[96]!==B?(le=Y?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.plugins.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.plugins.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[j.length>0&&te(r("settings.plugins.sidebar.group.userEntries"),j.map(Ie),I.userEntries),B.length>0&&te(r("settings.plugins.sidebar.group.userFiles"),B.map(be)),T.length>0&&te(r("settings.plugins.sidebar.group.projectEntries"),T.map(Ie),I.projectEntries),W.length>0&&te(r("settings.plugins.sidebar.group.projectFiles"),W.map(be))]}),e[87]=Y,e[88]=T,e[89]=W,e[90]=Ie,e[91]=be,e[92]=te,e[93]=r,e[94]=I,e[95]=j,e[96]=B,e[97]=le):le=e[97];let q;e[98]!==Ue||e[99]!==le?(q=t.jsx(Fl,{variant:"background",header:Ue,children:le}),e[98]=Ue,e[99]=le,e[100]=q):q=e[100];let me;e[101]!==E?(me=t.jsx(mg,{open:E,onOpenChange:N}),e[101]=E,e[102]=me):me=e[102];const Ne=h!==null;let Ee;e[103]!==k?(Ee=pe=>{!pe&&!k&&D(null)},e[103]=k,e[104]=Ee):Ee=e[104];let Ce;e[105]!==r?(Ce=r("settings.plugins.sidebar.deleteDialog.title"),e[105]=r,e[106]=Ce):Ce=e[106];let He;e[107]!==Ce?(He=t.jsx(Vt,{children:Ce}),e[107]=Ce,e[108]=He):He=e[108];const G=h?.label??"";let $;e[109]!==r||e[110]!==G?($=r("settings.plugins.sidebar.deleteDialog.description",{name:G}),e[109]=r,e[110]=G,e[111]=$):$=e[111];let fe;e[112]!==$?(fe=t.jsx(qt,{children:$}),e[112]=$,e[113]=fe):fe=e[113];let L;e[114]!==He||e[115]!==fe?(L=t.jsxs(_t,{children:[He,fe]}),e[114]=He,e[115]=fe,e[116]=L):L=e[116];let Fe;e[117]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>D(null),e[117]=Fe):Fe=e[117];let Je;e[118]!==r?(Je=r("settings.common.actions.cancel"),e[118]=r,e[119]=Je):Je=e[119];let Xe;e[120]!==k||e[121]!==Je?(Xe=t.jsx(J,{size:"sm",variant:"ghost",onClick:Fe,disabled:k,children:Je}),e[120]=k,e[121]=Je,e[122]=Xe):Xe=e[122];let et;e[123]!==k||e[124]!==r?(et=r(k?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=k,e[124]=r,e[125]=et):et=e[125];let at;e[126]!==we||e[127]!==k||e[128]!==et?(at=t.jsx(J,{size:"sm",variant:"destructive",onClick:we,disabled:k,children:et}),e[126]=we,e[127]=k,e[128]=et,e[129]=at):at=e[129];let lt;e[130]!==Xe||e[131]!==at?(lt=t.jsxs(Yt,{children:[Xe,at]}),e[130]=Xe,e[131]=at,e[132]=lt):lt=e[132];let Ze;e[133]!==L||e[134]!==lt?(Ze=t.jsxs(Bt,{className:"max-w-md",children:[L,lt]}),e[133]=L,e[134]=lt,e[135]=Ze):Ze=e[135];let We;e[136]!==Ne||e[137]!==Ee||e[138]!==Ze?(We=t.jsx(Ut,{open:Ne,onOpenChange:Ee,children:Ze}),e[136]=Ne,e[137]=Ee,e[138]=Ze,e[139]=We):We=e[139];let pt;return e[140]!==q||e[141]!==me||e[142]!==We?(pt=t.jsxs(t.Fragment,{children:[q,me,We]}),e[140]=q,e[141]=me,e[142]=We,e[143]=pt):pt=e[143],pt};function xg(s){return{entries:s.entries,files:s.files,selectedId:s.selectedId,setSelected:s.setSelected,deleteEntry:s.deleteEntry,deleteFile:s.deleteFile,loadPlugins:s.loadPlugins}}function bg(s){return s.registryInfo}function yg(s){return s.isLoadingRegistry}function vg(s){return s.loadRegistryInfo}function jg(s){return s.updateToLatest}function wg(s){return s.scope==="user"}function Ng(s){return s.scope==="project"}function kg(s){return s.scope==="user"}function Sg(s){return s.scope==="project"}const Rr=s=>{const e=rt.c(10),{children:n,className:a,outerClassName:r}=s;let i;e[0]!==r?(i=de("h-full",r),e[0]=r,e[1]=i):i=e[1];let o;e[2]!==a?(o=de("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",a),e[2]=a,e[3]=o):o=e[3];let d;e[4]!==n||e[5]!==o?(d=t.jsx("div",{className:o,children:n}),e[4]=n,e[5]=o,e[6]=d):d=e[6];let c;return e[7]!==i||e[8]!==d?(c=t.jsx(Jt,{outerClassName:i,className:"w-full",children:d}),e[7]=i,e[8]=d,e[9]=c):c=e[9],c},Cg=({entryId:s,spec:e})=>{const{t:n}=dt(),a=os(p=>p.registryInfo[e]),r=os(p=>p.updateToLatest),[i,o]=l.useState(!1);if(!a)return null;if(a.kind==="npm-ok"){if(!a.hasUpdate||!a.latestVersion)return null;const p=a.latestVersion,u=a.currentVersion??"",S=async()=>{o(!0);try{(await r(s)).ok?V.success(n("settings.plugins.toast.updatedToLatest",{version:p})):V.error(n("settings.plugins.toast.refreshFailed"))}finally{o(!1)}};return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(A,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"typography-label text-[var(--status-success)]",children:n("settings.plugins.registry.banner.updateAvailable.title")}),t.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:n("settings.plugins.registry.banner.updateAvailable.description",{current:u,latest:p})})]}),t.jsx(J,{variant:"default",size:"sm",onClick:()=>{S()},disabled:i,children:n("settings.plugins.registry.banner.updateAvailable.action",{latest:p})})]})}if(a.kind==="path-ok")return null;if(a.kind==="npm-network")return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(A,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx("p",{className:"typography-micro text-muted-foreground",children:n("settings.plugins.registry.badge.network.tooltip")})})]});const d=a.kind==="path-unreadable",c=d?"var(--status-warning)":"var(--status-error)",x=d?"alert":"error-warning",m=(()=>{switch(a.kind){case"npm-missing-version":return n("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return n("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return n("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return n("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return n("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(A,{name:x,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"typography-label",style:{color:c},children:n("settings.plugins.registry.banner.invalid.title")}),t.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:m})]})]})};function Pg(s){const e=s.trim();if(e.length===0)return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}function Ol(s){return!s||Object.keys(s).length===0?"":JSON.stringify(s,null,2)}function no(s){return{mode:"entry",scope:s.scope,spec:s.spec,optionsJson:Ol(s.options),fileName:"",content:""}}function ao(s,e){return{mode:"file",scope:s.scope,spec:"",optionsJson:"",fileName:s.fileName,content:e}}const ro=s=>{const e=rt.c(4),{scope:n,label:a}=s;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=de("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=r):r=e[0];let i;return e[1]!==a||e[2]!==n?(i=t.jsx("span",{className:r,"data-scope":n,children:a}),e[1]=a,e[2]=n,e[3]=i):i=e[3],i},Ig=()=>{const{t:s}=dt(),e=os(h=>h.selectedId),n=os(h=>h.entries),a=os(h=>h.files),r=os(h=>h.draft),i=os(h=>h.setDraft),o=os(h=>h.updateEntry),d=os(h=>h.updateFile),c=os(h=>h.readFile),x=l.useMemo(()=>e?n.find(h=>h.id===e)??null:null,[n,e]),m=l.useMemo(()=>e?a.find(h=>h.id===e)??null:null,[a,e]),[p,u]=l.useState(!1),[S,f]=l.useState(!1),g=l.useRef(new Map);if(l.useEffect(()=>{let h=!1;return x?(i(no(x)),()=>{h=!0}):m?(f(!0),(async()=>{const D=await c(m.id);if(h)return;f(!1);const k=D?.content??"";g.current.set(m.id,k),i(ao(m,k))})(),()=>{h=!0}):(i(null),()=>{h=!0})},[x,m,c,i]),!e)return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.plugins.page.empty.select")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.plugins.page.empty.add")})]})});if(x&&r&&r.mode==="entry"){const h=Pg(r.optionsJson),D=h.ok,k=r.spec!==x.spec||r.optionsJson!==Ol(x.options),w=()=>{i(no(x))},E=async()=>{if(!D)return;const N=r.spec.trim();if(!N){V.error(s("settings.plugins.validation.specRequired"));return}u(!0);try{const y=await o(x.id,{spec:N,options:h.value});y.ok?y.reloadFailed?V.warning(y.message||s("settings.plugins.toast.reloadFailed"),{description:y.warning}):V.success(y.message||s("settings.plugins.toast.updated")):V.error(y.message||s("settings.plugins.toast.reloadFailed"))}finally{u(!1)}};return t.jsxs(Rr,{children:[t.jsx("div",{children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:s("settings.plugins.page.header.entry")}),t.jsx(ro,{scope:x.scope,label:x.scope==="project"?s("settings.plugins.sidebar.group.projectEntries"):s("settings.plugins.sidebar.group.userEntries")})]})}),t.jsx(Cg,{entryId:x.id,spec:x.spec}),t.jsxs("div",{"data-settings-item":"plugins.spec",className:"space-y-1.5",children:[t.jsx("label",{className:"typography-meta text-muted-foreground",children:s("settings.plugins.page.field.spec")}),t.jsx(it,{value:r.spec,onChange:N=>i({...r,spec:N.target.value}),placeholder:s("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})]}),t.jsxs("div",{"data-settings-item":"plugins.options",className:"space-y-1.5",children:[t.jsx("label",{className:"typography-meta text-muted-foreground",children:s("settings.plugins.page.field.options")}),t.jsx(ps,{value:r.optionsJson,onChange:N=>i({...r,optionsJson:N.target.value}),rows:10,className:de("font-mono typography-meta min-h-[200px]",!D&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!D&&t.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:s("settings.plugins.page.field.options.invalidJson")})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"default",size:"sm",onClick:()=>{E()},disabled:!k||!D||p,children:s("settings.plugins.page.action.save")}),t.jsx(J,{variant:"outline",size:"sm",onClick:w,disabled:!k||p,children:s("settings.plugins.page.action.discard")})]})]})}if(m&&r&&r.mode==="file"){const h=g.current.get(m.id)??"",D=r.content!==h||r.fileName!==m.fileName,k=()=>{(async()=>{f(!0);const N=(await c(m.id))?.content??"";f(!1),g.current.set(m.id,N),i(ao(m,N))})()},w=async()=>{u(!0);try{const E=await d(m.id,{content:r.content});E.ok?(g.current.set(m.id,r.content),E.reloadFailed?V.warning(E.message||s("settings.plugins.toast.reloadFailed"),{description:E.warning}):V.success(E.message||s("settings.plugins.toast.updated"))):V.error(E.message||s("settings.plugins.toast.reloadFailed"))}finally{u(!1)}};return t.jsxs(Rr,{children:[t.jsx("div",{children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:s("settings.plugins.page.header.file")}),t.jsx(ro,{scope:m.scope,label:m.scope==="project"?s("settings.plugins.sidebar.group.projectFiles"):s("settings.plugins.sidebar.group.userFiles")}),t.jsx("span",{className:de("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:m.fileName})]})}),t.jsxs("div",{"data-settings-item":"plugins.content",className:"space-y-1.5",children:[t.jsx("label",{className:"typography-meta text-muted-foreground",children:s("settings.plugins.page.field.content")}),t.jsx(ps,{value:r.content,onChange:E=>i({...r,content:E.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:S})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"default",size:"sm",onClick:()=>{w()},disabled:!D||p||S,children:s("settings.plugins.page.action.save")}),t.jsx(J,{variant:"outline",size:"sm",onClick:k,disabled:p||S,children:s("settings.plugins.page.action.discard")})]})]})}return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsx("div",{className:"text-center text-muted-foreground",children:t.jsx(A,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Dg="<built-in>",Nn=s=>s?.path===Dg,Ag=s=>{const e=rt.c(150),{onItemSelect:n}=s,{t:a}=dt(),[r,i]=l.useState(null),[o,d]=l.useState(""),[c,x]=l.useState(null),[m,p]=l.useState(!1),[u,S]=l.useState(null),{selectedSkillName:f,skills:g,setSelectedSkill:h,setSkillDraft:D,createSkill:k,deleteSkill:w,getSkillDetail:E}=_s(Ss(Eg));let N;e[0]!==n||e[1]!==h||e[2]!==D||e[3]!==g?(N=()=>{let pe="new-skill",st=1;for(;g.some(nt=>nt.name===pe);)pe=`new-skill-${st}`,st++;D({name:pe,scope:"user",source:"opencode",description:""}),h(pe),n?.()},e[0]=n,e[1]=h,e[2]=D,e[3]=g,e[4]=N):N=e[4];const y=N;let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=async pe=>{Nn(pe)||x(pe)},e[5]=b):b=e[5];const P=b;let z;e[6]!==c||e[7]!==w||e[8]!==a?(z=async()=>{if(!c)return;if(Nn(c)){x(null);return}p(!0),await w(c.name)?(V.success(a("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),x(null)):V.error(a("settings.skills.sidebar.toast.deleteSkillFailed")),p(!1)},e[6]=c,e[7]=w,e[8]=a,e[9]=z):z=e[9];const M=z;let I;e[10]!==E||e[11]!==h||e[12]!==D||e[13]!==g||e[14]!==a?(I=async pe=>{if(Nn(pe))return;const st=pe.name;let nt=1,Ge=`${st}-copy`;for(;g.some(wt=>wt.name===Ge);)nt++,Ge=`${st}-copy-${nt}`;const ft=await E(pe.name);if(!ft){V.error(a("settings.skills.sidebar.toast.duplicateLoadFailed"));return}D({name:Ge,scope:pe.scope||"user",source:pe.source||"opencode",description:(ft.sources.md.fields.includes("description"),""),instructions:""}),h(Ge)},e[10]=E,e[11]=h,e[12]=D,e[13]=g,e[14]=a,e[15]=I):I=e[15];const v=I;let j;e[16]===Symbol.for("react.memo_cache_sentinel")?(j=pe=>{Nn(pe)||(d(pe.name),i(pe))},e[16]=j):j=e[16];const O=j;let T;e[17]!==k||e[18]!==w||e[19]!==E||e[20]!==r||e[21]!==o||e[22]!==h||e[23]!==g||e[24]!==a?(T=async()=>{if(!r)return;if(Nn(r)){i(null);return}const pe=o.trim().replace(/\s+/g,"-").toLowerCase();if(!pe){V.error(a("settings.skills.page.toast.skillNameRequired"));return}if(pe===r.name){i(null);return}if(g.some(Ge=>Ge.name===pe)){V.error(a("settings.skills.page.toast.skillExists"));return}if(!await E(r.name)){V.error(a("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await k({name:pe,description:"Renamed skill",scope:r.scope,source:r.source})?await w(r.name)?(V.success(`Skill renamed to "${pe}"`),h(pe)):V.error(a("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):V.error(a("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=k,e[18]=w,e[19]=E,e[20]=r,e[21]=o,e[22]=h,e[23]=g,e[24]=a,e[25]=T):T=e[25];const U=T;let B;e[26]!==g?(B=g.filter(Mg),e[26]=g,e[27]=B):B=e[27];const Q=B;let W;e[28]!==g?(W=g.filter(Rg),e[28]=g,e[29]=W):W=e[29];const R=W;let Y;e[30]===Symbol.for("react.memo_cache_sentinel")?(Y=function(st){const nt={},Ge=[];for(const wt of st)wt.group?(nt[wt.group]||(nt[wt.group]=[]),nt[wt.group].push(wt)):Ge.push(wt);const ft=Object.keys(nt).sort(Tg).map(wt=>({name:wt,skills:[...nt[wt]].sort(Fg)}));return Ge.sort(Og),{sortedGroups:ft,ungrouped:Ge}},e[30]=Y):Y=e[30];const F=Y;let H;e[31]!==Q?(H=F(Q),e[31]=Q,e[32]=H):H=e[32];const X=H;let re;e[33]!==R?(re=F(R),e[33]=R,e[34]=re):re=e[34];const Z=re;let se;e[35]===Symbol.for("react.memo_cache_sentinel")?(se=de("flex h-full flex-col","bg-background"),e[35]=se):se=e[35];let ce;e[36]!==a?(ce=a("settings.skills.sidebar.title"),e[36]=a,e[37]=ce):ce=e[37];let oe;e[38]!==ce?(oe=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:ce}),e[38]=ce,e[39]=oe):oe=e[39];let xe;e[40]===Symbol.for("react.memo_cache_sentinel")?(xe=t.jsx(ta,{className:"mb-3"}),e[40]=xe):xe=e[40];let we;e[41]!==g.length||e[42]!==a?(we=a("settings.skills.sidebar.total",{count:g.length}),e[41]=g.length,e[42]=a,e[43]=we):we=e[43];let he;e[44]!==we?(he=t.jsx("span",{className:"typography-meta text-muted-foreground",children:we}),e[44]=we,e[45]=he):he=e[45];let Ie;e[46]===Symbol.for("react.memo_cache_sentinel")?(Ie=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[46]=Ie):Ie=e[46];let ve;e[47]!==y?(ve=t.jsx(J,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:y,children:Ie}),e[47]=y,e[48]=ve):ve=e[48];let be;e[49]!==he||e[50]!==ve?(be=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[he,ve]}),e[49]=he,e[50]=ve,e[51]=be):be=e[51];let ye;e[52]!==oe||e[53]!==be?(ye=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[oe,xe,be]}),e[52]=oe,e[53]=be,e[54]=ye):ye=e[54];let te;e[55]!==X||e[56]!==Z||e[57]!==v||e[58]!==n||e[59]!==u||e[60]!==Q||e[61]!==f||e[62]!==h||e[63]!==g.length||e[64]!==a||e[65]!==R?(te=t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:g.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.skills.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.skills.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[Q.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.skills.sidebar.section.project")}),X.sortedGroups.map(pe=>{const{name:st,skills:nt}=pe;return t.jsx(Ar,{label:st,count:nt.length,storageKey:"project-skills",children:nt.map(Ge=>t.jsx(ga,{skill:Ge,isSelected:f===Ge.name,onSelect:()=>{h(Ge.name),n?.()},onRename:()=>O(Ge),onDelete:()=>P(Ge),onDuplicate:()=>v(Ge),isMenuOpen:u===Ge.name,onMenuOpenChange:ft=>S(ft?Ge.name:null)},Ge.name))},st)}),X.ungrouped.map(pe=>t.jsx(ga,{skill:pe,isSelected:f===pe.name,onSelect:()=>{h(pe.name),n?.()},onRename:()=>O(pe),onDelete:()=>P(pe),onDuplicate:()=>v(pe),isMenuOpen:u===pe.name,onMenuOpenChange:st=>S(st?pe.name:null)},pe.name))]}),R.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.skills.sidebar.section.user")}),Z.sortedGroups.map(pe=>{const{name:st,skills:nt}=pe;return t.jsx(Ar,{label:st,count:nt.length,storageKey:"user-skills",children:nt.map(Ge=>t.jsx(ga,{skill:Ge,isSelected:f===Ge.name,onSelect:()=>{h(Ge.name),n?.()},onRename:()=>O(Ge),onDelete:()=>P(Ge),onDuplicate:()=>v(Ge),isMenuOpen:u===Ge.name,onMenuOpenChange:ft=>S(ft?Ge.name:null)},Ge.name))},st)}),Z.ungrouped.map(pe=>t.jsx(ga,{skill:pe,isSelected:f===pe.name,onSelect:()=>{h(pe.name),n?.()},onRename:()=>O(pe),onDelete:()=>P(pe),onDuplicate:()=>v(pe),isMenuOpen:u===pe.name,onMenuOpenChange:st=>S(st?pe.name:null)},pe.name))]})]})}),e[55]=X,e[56]=Z,e[57]=v,e[58]=n,e[59]=u,e[60]=Q,e[61]=f,e[62]=h,e[63]=g.length,e[64]=a,e[65]=R,e[66]=te):te=e[66];const ie=c!==null;let ge;e[67]!==m?(ge=pe=>{!pe&&!m&&x(null)},e[67]=m,e[68]=ge):ge=e[68];let _;e[69]!==a?(_=a("settings.skills.sidebar.deleteDialog.title"),e[69]=a,e[70]=_):_=e[70];let ee;e[71]!==_?(ee=t.jsx(Vt,{children:_}),e[71]=_,e[72]=ee):ee=e[72];const ne=c?.name??"";let ue;e[73]!==a||e[74]!==ne?(ue=a("settings.skills.sidebar.deleteDialog.description",{name:ne}),e[73]=a,e[74]=ne,e[75]=ue):ue=e[75];let Me;e[76]!==ue?(Me=t.jsx(qt,{children:ue}),e[76]=ue,e[77]=Me):Me=e[77];let ke;e[78]!==ee||e[79]!==Me?(ke=t.jsxs(_t,{children:[ee,Me]}),e[78]=ee,e[79]=Me,e[80]=ke):ke=e[80];let De;e[81]===Symbol.for("react.memo_cache_sentinel")?(De=()=>x(null),e[81]=De):De=e[81];let Ae;e[82]!==a?(Ae=a("settings.common.actions.cancel"),e[82]=a,e[83]=Ae):Ae=e[83];let Pe;e[84]!==m||e[85]!==Ae?(Pe=t.jsx(J,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:De,disabled:m,children:Ae}),e[84]=m,e[85]=Ae,e[86]=Pe):Pe=e[86];let Re;e[87]!==a?(Re=a("settings.common.actions.delete"),e[87]=a,e[88]=Re):Re=e[88];let Oe;e[89]!==M||e[90]!==m||e[91]!==Re?(Oe=t.jsx(J,{size:"sm",onClick:M,disabled:m,children:Re}),e[89]=M,e[90]=m,e[91]=Re,e[92]=Oe):Oe=e[92];let $e;e[93]!==Pe||e[94]!==Oe?($e=t.jsxs(Yt,{children:[Pe,Oe]}),e[93]=Pe,e[94]=Oe,e[95]=$e):$e=e[95];let Be;e[96]!==ke||e[97]!==$e?(Be=t.jsxs(Bt,{className:"max-w-md",children:[ke,$e]}),e[96]=ke,e[97]=$e,e[98]=Be):Be=e[98];let Le;e[99]!==ie||e[100]!==ge||e[101]!==Be?(Le=t.jsx(Ut,{open:ie,onOpenChange:ge,children:Be}),e[99]=ie,e[100]=ge,e[101]=Be,e[102]=Le):Le=e[102];const Ue=r!==null;let le;e[103]===Symbol.for("react.memo_cache_sentinel")?(le=pe=>!pe&&i(null),e[103]=le):le=e[103];let q;e[104]!==a?(q=a("settings.skills.sidebar.renameDialog.title"),e[104]=a,e[105]=q):q=e[105];let me;e[106]!==q?(me=t.jsx(Vt,{children:q}),e[106]=q,e[107]=me):me=e[107];const Ne=r?.name??"";let Ee;e[108]!==a||e[109]!==Ne?(Ee=a("settings.skills.sidebar.renameDialog.description",{name:Ne}),e[108]=a,e[109]=Ne,e[110]=Ee):Ee=e[110];let Ce;e[111]!==Ee?(Ce=t.jsx(qt,{children:Ee}),e[111]=Ee,e[112]=Ce):Ce=e[112];let He;e[113]!==me||e[114]!==Ce?(He=t.jsxs(_t,{children:[me,Ce]}),e[113]=me,e[114]=Ce,e[115]=He):He=e[115];let G;e[116]===Symbol.for("react.memo_cache_sentinel")?(G=pe=>d(pe.target.value),e[116]=G):G=e[116];let $;e[117]!==a?($=a("settings.skills.sidebar.renameDialog.placeholder"),e[117]=a,e[118]=$):$=e[118];let fe;e[119]!==U?(fe=pe=>{pe.key==="Enter"&&U()},e[119]=U,e[120]=fe):fe=e[120];let L;e[121]!==o||e[122]!==$||e[123]!==fe?(L=t.jsx(it,{value:o,onChange:G,placeholder:$,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:fe}),e[121]=o,e[122]=$,e[123]=fe,e[124]=L):L=e[124];let Fe;e[125]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>i(null),e[125]=Fe):Fe=e[125];let Je;e[126]!==a?(Je=a("settings.common.actions.cancel"),e[126]=a,e[127]=Je):Je=e[127];let Xe;e[128]!==Je?(Xe=t.jsx(J,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Fe,children:Je}),e[128]=Je,e[129]=Xe):Xe=e[129];let et;e[130]!==a?(et=a("settings.common.actions.rename"),e[130]=a,e[131]=et):et=e[131];let at;e[132]!==U||e[133]!==et?(at=t.jsx(J,{size:"sm",onClick:U,children:et}),e[132]=U,e[133]=et,e[134]=at):at=e[134];let lt;e[135]!==Xe||e[136]!==at?(lt=t.jsxs(Yt,{children:[Xe,at]}),e[135]=Xe,e[136]=at,e[137]=lt):lt=e[137];let Ze;e[138]!==He||e[139]!==L||e[140]!==lt?(Ze=t.jsxs(Bt,{children:[He,L,lt]}),e[138]=He,e[139]=L,e[140]=lt,e[141]=Ze):Ze=e[141];let We;e[142]!==Ue||e[143]!==Ze?(We=t.jsx(Ut,{open:Ue,onOpenChange:le,children:Ze}),e[142]=Ue,e[143]=Ze,e[144]=We):We=e[144];let pt;return e[145]!==ye||e[146]!==te||e[147]!==Le||e[148]!==We?(pt=t.jsxs("div",{className:se,children:[ye,te,Le,We]}),e[145]=ye,e[146]=te,e[147]=Le,e[148]=We,e[149]=pt):pt=e[149],pt},ga=s=>{const e=rt.c(49),{skill:n,isSelected:a,onSelect:r,onDelete:i,onRename:o,onDuplicate:d,isMenuOpen:c,onMenuOpenChange:x}=s,{t:m}=dt();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=Qn(),e[0]=p):p=e[0];const u=p;let S;e[1]!==n.source||e[2]!==m?(S=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]=S):S=e[3];const f=S;let g;e[4]!==n?(g=Nn(n),e[4]=n,e[5]=g):g=e[5];const h=g,[D,k]=l.useState(!1);let w;e[6]!==i||e[7]!==d||e[8]!==o||e[9]!==m?(w=R=>t.jsxs(t.Fragment,{children:[t.jsxs(R,{onClick:Y=>{Y.stopPropagation(),o()},children:[t.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),t.jsxs(R,{onClick:Y=>{Y.stopPropagation(),d()},children:[t.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),t.jsxs(R,{onClick:Y=>{Y.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[6]=i,e[7]=d,e[8]=o,e[9]=m,e[10]=w):w=e[10];const E=w,N=!h&&D,y=a?"bg-interactive-selection":"hover:bg-interactive-hover";let b;e[11]!==y?(b=de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",y),e[11]=y,e[12]=b):b=e[12];let P;e[13]!==h?(P=!u&&!h?R=>{R.preventDefault(),k(!0)}:void 0,e[13]=h,e[14]=P):P=e[14];let z;e[15]!==b||e[16]!==P?(z=t.jsx("div",{className:b,onContextMenu:P}),e[15]=b,e[16]=P,e[17]=z):z=e[17];let M;e[18]!==n.name?(M=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[18]=n.name,e[19]=M):M=e[19];let I;e[20]!==n.scope?(I=t.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[20]=n.scope,e[21]=I):I=e[21];let v;e[22]!==f?(v=t.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:f}),e[22]=f,e[23]=v):v=e[23];let j;e[24]!==M||e[25]!==I||e[26]!==v?(j=t.jsxs("div",{className:"flex items-center gap-1.5",children:[M,I,v]}),e[24]=M,e[25]=I,e[26]=v,e[27]=j):j=e[27];let O;e[28]!==r||e[29]!==j?(O=t.jsx("button",{onClick:r,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}),e[28]=r,e[29]=j,e[30]=O):O=e[30];let T;e[31]!==h||e[32]!==c||e[33]!==x||e[34]!==E?(T=h?null:t.jsxs(us,{open:c,onOpenChange:R=>{R&&k(!1),x(R)},children:[t.jsx(ds,{asChild:!0,children:t.jsx(J,{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:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:E(js)})]}),e[31]=h,e[32]=c,e[33]=x,e[34]=E,e[35]=T):T=e[35];let U;e[36]!==O||e[37]!==T?(U=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[O,T]}),e[36]=O,e[37]=T,e[38]=U):U=e[38];let B;e[39]!==U||e[40]!==z?(B=t.jsx(tn,{render:z,children:U}),e[39]=U,e[40]=z,e[41]=B):B=e[41];let Q;e[42]!==h||e[43]!==E?(Q=h?null:t.jsx(sn,{className:"w-fit min-w-20",children:E(Ws)}),e[42]=h,e[43]=E,e[44]=Q):Q=e[44];let W;return e[45]!==B||e[46]!==Q||e[47]!==N?(W=t.jsxs(en,{open:N,onOpenChange:k,children:[B,Q]}),e[45]=B,e[46]=Q,e[47]=N,e[48]=W):W=e[48],W};function Eg(s){return{selectedSkillName:s.selectedSkillName,skills:s.skills,setSelectedSkill:s.setSelectedSkill,setSkillDraft:s.setSkillDraft,createSkill:s.createSkill,deleteSkill:s.deleteSkill,getSkillDetail:s.getSkillDetail}}function Mg(s){return s.scope==="project"}function Rg(s){return s.scope==="user"}function Tg(s,e){return s.localeCompare(e)}function Fg(s,e){return s.name.localeCompare(e.name)}function Og(s,e){return s.name.localeCompare(e.name)}const Lg=s=>s!==null&&typeof s=="object"&&"updateStatus"in s&&typeof s.updateStatus=="function",zg=s=>{const e=document.createElement("div");e.className="cm-vim-panel";const n=Uc(s);if(!n)return{top:!1,dom:e};n.state.statusbar=e;const a=n.state.vimPlugin;return Lg(a)&&a.updateStatus(),{top:!1,dom:e,destroy(){n.state.statusbar===e&&(n.state.statusbar=null)}}};function io(s){return s?[zc(),Kc.of(zg),$c()]:[]}const Kg={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},$g={case:"Match case",re:"Regular expression",word:"Match whole word"};function Ug(s){const e=s.querySelector(".cm-search");if(e){for(const[n,a]of Object.entries(Kg)){const r=e.querySelector(`button[name="${n}"]`);r&&!r.title&&(r.title=a)}for(const[n,a]of Object.entries($g)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=a)}}}const ir=new WeakMap;function Bg(s,e){const n=Ma(s.state);if(!n.valid)return ir.delete(s),0;const a=ir.get(s);if(!e&&a?.doc===s.state.doc&&a.query.eq(n))return a.total;const r=n.getCursor(s.state);let i=0;for(let o=r.next();!o.done;o=r.next())i+=1;return ir.set(s,{query:n,doc:s.state.doc,total:i}),i}function Vg(s){const e=Ma(s.state);if(!e.valid)return 0;const n=s.state.selection.main,a=e.getCursor(s.state);let r=0,i=0;for(let o=a.next();!o.done;o=a.next()){const d=o.value;if(r+=1,i===0&&(i=r),n.from===d.from&&n.to===d.to||n.from<d.to&&n.to>d.from||d.from>=n.head)return r}return i}function oo(s,e,n=!1){const a=s.querySelector(".cm-search");if(!a)return;let r=a.querySelector(".cm-search-message");if(!r){r=document.createElement("span"),r.className="cm-search-message",r.setAttribute("aria-live","polite");const d=a.querySelector('button[name="next"]'),c=d?.parentNode===a?d:a.firstChild;a.insertBefore(r,c)}const i=Bg(e,n),o=i===0?0:Vg(e);r.textContent=i===0?"":`${o}/${i}`}const lo=new bn,co=new bn,mo=new bn,uo=new bn,po=new bn,go=new bn,ho=new bn,fo=s=>s,or=Jc,_g=Qc,Hg=Yc;class Wg extends Xc{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 xo=(s,e)=>!s||s.length===0?[]:ul.define({create(n){const a=new Br,r=[...s].sort((i,o)=>i.afterLine-o.afterLine);for(const i of r){const o=n.doc.lines;if(i.afterLine>o)continue;const d=n.doc.line(i.afterLine);a.add(d.to,d.to,La.widget({widget:new Wg(i.id,e),block:!0,side:1}))}return a.finish()},update(n,a){return n.map(a.changes)},provide:n=>Rs.decorations.from(n)}),bo=s=>{if(!s)return[];const e=Math.max(1,s.start),n=Math.max(e,s.end);return ml.fromClass(class{decorations;constructor(a){this.decorations=this.build(a)}update(a){(a.docChanged||a.viewportChanged)&&(this.decorations=this.build(a.view))}build(a){const r=new Br;for(let i=e;i<=n&&i<=a.state.doc.lines;i+=1){const o=a.state.doc.line(i);r.add(o.from,o.from,La.line({class:"oc-cm-selected-line"}))}return r.finish()}},{decorations:a=>a.decorations})};function yo({value:s,onChange:e,extensions:n,className:a,readOnly:r,lineNumbersConfig:i,highlightLines:o,onViewReady:d,onViewDestroy:c,blockWidgets:x,enableSearch:m,searchOpen:p,onSearchOpenChange:u,vimMode:S}){const f=l.useRef(null),g=l.useRef(null),h=l.useRef(s),D=l.useRef(e),k=l.useRef(d),w=l.useRef(c),E=l.useRef(u),N=l.useRef(x),y=l.useRef(S),b=l.useRef(new Map),[P,z]=l.useState([]),M=l.useCallback(v=>{const j=(v??[]).map(O=>{const T=b.current.get(O.id);return T?{id:O.id,content:O.content,container:T}:null}).filter(O=>O!==null);z(O=>O.length===j.length&&O.every((T,U)=>{const B=j[U];return T.id===B.id&&T.content===B.content&&T.container===B.container})?O:j)},[]),I=l.useCallback(v=>{const j=f.current,O=v??g.current;if(!j||!O)return;const T=O.dom.querySelector(".cm-gutters"),U=T instanceof HTMLElement?T.getBoundingClientRect().width:0;j.style.setProperty("--oc-editor-gutter-width",`${U}px`)},[]);return l.useEffect(()=>{h.current=s},[s]),l.useEffect(()=>{D.current=e},[e]),l.useEffect(()=>{k.current=d,w.current=c},[d,c]),l.useEffect(()=>{E.current=u},[u]),l.useEffect(()=>{N.current=x,M(x)},[x,M]),l.useEffect(()=>{if(!f.current)return;const v=(()=>{if(typeof document>"u")return null;const O=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(O)return O;const T=window.__OPENCHAMBER_CSP_NONCE__;return typeof T=="string"&&T.length>0?T:null})(),j=Bc.create({doc:h.current,extensions:[...v?[Rs.cspNonce.of(v)]:[],Vc({fixed:!0}),lo.of(Zr(i)),_c(),Hc.of(" "),ho.of(io(S)),Ha.of([Wc,...qc,...Gc]),Rs.updateListener.of(O=>{I(O.view),(O.viewportChanged||O.geometryChanged)&&M(N.current);const T=ei(O.startState),U=ei(O.state);T!==U&&E.current?.(U);const B=!Ma(O.startState).eq(Ma(O.state));if(U&&(T!==U||B||O.docChanged||O.selectionSet)&&oo(O.view.dom,O.view,T!==U||B||O.docChanged),!O.docChanged)return;const Q=O.state.doc.toString();h.current=Q,D.current(Q),M(N.current)}),co.of(Rs.editable.of(!r)),mo.of(n??[]),uo.of(bo(o)),po.of(xo(x,b.current)),go.of(m?[ti({top:!0}),Ha.of(fo(si))]:[])]});return g.current=new Rs({state:j,parent:f.current}),or(g.current,g.current.state.doc.length,200),g.current.requestMeasure(),requestAnimationFrame(()=>{I(g.current),M(N.current)}),g.current&&k.current?.(g.current),()=>{w.current?.(),g.current?.destroy(),g.current=null,z([])}},[N,I,M]),l.useEffect(()=>{const v=g.current;v&&(v.dispatch({effects:[lo.reconfigure(Zr(i)),co.reconfigure(Rs.editable.of(!r)),mo.reconfigure(n??[]),uo.reconfigure(bo(o)),po.reconfigure(xo(x,b.current)),go.reconfigure(m?[ti({top:!0}),Ha.of(fo(si))]:[])]}),or(v,v.state.doc.length,200),v.requestMeasure(),requestAnimationFrame(()=>{I(v),M(N.current)}))},[n,o,i,r,x,m,I,M]),l.useEffect(()=>{const v=g.current;if(!v){y.current=S;return}y.current!==S&&(y.current=S,v.dispatch({effects:ho.reconfigure(io(S))}))},[S]),l.useEffect(()=>{const v=g.current;!v||m===!1||(p?(_g(v),requestAnimationFrame(()=>{Ug(v.dom),oo(v.dom,v,!0)})):Hg(v))},[p,m]),l.useEffect(()=>{const v=g.current;if(!v)return;const j=v.state.doc.toString();j!==s&&(v.dispatch({changes:{from:0,to:j.length,insert:s}}),or(v,v.state.doc.length,300),v.requestMeasure(),requestAnimationFrame(()=>I(v)))},[s,I]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:f,className:de("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",a)}),P.map(v=>wa.createPortal(v.content,v.container,v.id))]})}const qg=s=>{const e=rt.c(11),{currentMode:n,onToggle:a}=s,r=n==="preview",i=r?"Switch to edit mode":"Switch to preview mode",o=r?"Edit":"Preview";let d;e[0]!==r?(d=r?t.jsx(A,{name:"eye",className:"size-4","aria-hidden":"true"}):t.jsx(A,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=r,e[1]=d):d=e[1];let c;e[2]!==i||e[3]!==a||e[4]!==d?(c=t.jsx(At,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"sm",onClick:a,"aria-label":i,className:"h-5 w-5 p-0",children:d})}),e[2]=i,e[3]=a,e[4]=d,e[5]=c):c=e[5];let x;e[6]!==o?(x=t.jsx(Et,{sideOffset:8,children:o}),e[6]=o,e[7]=x):x=e[7];let m;return e[8]!==c||e[9]!==x?(m=t.jsxs(Dt,{children:[c,x]}),e[8]=c,e[9]=x,e[10]=m):m=e[10],m},ks=rn()(Zn($r((s,e)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{s({selectedProfileId:n})},loadProfiles:async()=>{s({isLoading:!0});const n=e().profiles;try{const a=await Ed();return s({profiles:a,isLoading:!1}),!0}catch(a){return console.error("Failed to load git identity profiles:",a),s({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=await Ad();if(n&&n.userName&&n.userEmail){const a={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"};s({globalIdentity:a})}else s({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),s({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=await Dd();return s({discoveredCredentials:n}),!0}catch(n){return console.error("Failed to discover git credentials:",n),s({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=a=>{if(typeof a!="string")return null;const r=a.trim();return r.length>0?r:null};try{let a=null;if(a===null){const r=Fs()?.settings;if(r)try{const o=(await r.load())?.settings||{};a=n(o.defaultGitIdentityId)}catch{}}if(a===null)try{const r=await jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(r.ok){const i=await r.json().catch(()=>null);a=n(i?.defaultGitIdentityId)}}catch{}return s({defaultGitIdentityId:a}),!0}catch(a){return console.error("Failed to load default git identity setting:",a),!1}},setDefaultGitIdentityId:async n=>{try{const a=typeof n=="string"?n.trim():"",r=a.length>0?a:"";return await It({defaultGitIdentityId:r}),s({defaultGitIdentityId:r.length>0?r:null}),!0}catch(a){return console.error("Failed to save default git identity setting:",a),!1}},createProfile:async n=>{try{const a={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};return await Id(a),await e().loadProfiles(),!0}catch(a){return console.error("Failed to create git identity profile:",a),!1}},updateProfile:async(n,a)=>{try{const r=e().profiles.find(o=>o.id===n);if(!r)throw new Error("Profile not found");const i={...r,...a};return await Pd(n,i),await e().loadProfiles(),!0}catch(r){return console.error("Failed to update git identity profile:",r),!1}},deleteProfile:async n=>{try{return await Cd(n),e().selectedProfileId===n&&s({selectedProfileId:null}),await e().loadProfiles(),!0}catch(a){return console.error("Failed to delete git identity profile:",a),!1}},getProfileById:n=>{const{profiles:a,globalIdentity:r}=e();return n==="global"?r||void 0:a.find(i=>i.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:a}=e();return a.filter(r=>!n.some(i=>i.authType==="token"&&i.host===r.host))}}),{name:"git-identities-store",storage:Ur(()=>Yn()),partialize:s=>({selectedProfileId:s.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=ks);const Gg=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Jg=s=>{const e=s.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 a=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return a?`${a[1]}/${a[2].replace(/\.git$/i,"")}`:e},Qg=async()=>{try{const s=Fs()?.settings;if(s)return(await s.load())?.settings||{};const e=await jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Yg=s=>{const e=rt.c(160),{open:n,onOpenChange:a}=s,{t:r}=dt(),i=Bs(Xg),o=Bs(Zg),d=Bs(eh),c=Bs(th),x=Bs(sh),m=ks(nh),p=ks(ah),[u,S]=l.useState(""),[f,g]=l.useState(""),[h,D]=l.useState("");let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[0]=k):k=e[0];const[w,E]=l.useState(k),[N,y]=l.useState(null),[b,P]=l.useState(!1);let z;e[1]===Symbol.for("react.memo_cache_sentinel")?(z=[],e[1]=z):z=e[1];const[M,I]=l.useState(z),[v,j]=l.useState(null),O=l.useRef(0);let T;e[2]===Symbol.for("react.memo_cache_sentinel")?(T=pe=>{O.current=O.current+1,P(!1),y(null),pe?.clearIdentity&&(I([]),j(null))},e[2]=T):T=e[2];const U=T;let B,Q;e[3]!==p||e[4]!==n?(B=()=>{n&&(O.current=O.current+1,S(""),g(""),D(""),y(null),P(!1),I([]),j(null),p(),(async()=>{const pe=await Qg(),st=Array.isArray(pe?.skillCatalogs)?pe?.skillCatalogs:[];E(st||[])})())},Q=[n,p],e[3]=p,e[4]=n,e[5]=B,e[6]=Q):(B=e[5],Q=e[6]),l.useEffect(B,Q);let W;e[7]!==f?(W=f.trim(),e[7]=f,e[8]=W):W=e[8];const R=W;let Y;e[9]!==h?(Y=h.trim(),e[9]=h,e[10]=Y):Y=e[10];const F=Y;let H;if(e[11]!==w||e[12]!==R||e[13]!==F){let pe;e[15]!==R||e[16]!==F?(pe=st=>{const nt=(st.source||"").trim(),Ge=(st.subpath||"").trim();return nt===R&&Ge===F},e[15]=R,e[16]=F,e[17]=pe):pe=e[17],H=w.some(pe),e[11]=w,e[12]=R,e[13]=F,e[14]=H}else H=e[14];const X=H;let re;e[18]!==m||e[19]!==v||e[20]!==u||e[21]!==i||e[22]!==f||e[23]!==h||e[24]!==r?(re=async()=>{const pe=f.trim();if(!pe){V.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}u.trim()||S(Jg(pe)),P(!1),y(null);const st=O.current+1;O.current=st;const nt=await i({source:pe,subpath:h.trim()||void 0,gitIdentityId:v||void 0});if(O.current!==st)return;if(!nt.ok){if(nt.error?.kind==="authRequired"){if(gs()){V.error(r("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const ft=nt.error.identities||[];if(I(ft),!v&&ft.length>0){const wt=m&&m!=="global"&&ft.some(Ct=>Ct.id===m)?m:ft[0].id;j(wt)}V.error(r("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}V.error(nt.error?.message||r("settings.skills.catalog.add.toast.scanFailed"));return}const Ge=nt.items?.length||0;if(y(Ge),Ge===0){V.error(r("settings.skills.catalog.add.toast.noSkillsFound")),P(!1);return}I([]),P(!0),V.success(r("settings.skills.catalog.shared.toast.foundSkills",{count:Ge}))},e[18]=m,e[19]=v,e[20]=u,e[21]=i,e[22]=f,e[23]=h,e[24]=r,e[25]=re):re=e[25];const Z=re;let se;e[26]!==w||e[27]!==v||e[28]!==X||e[29]!==u||e[30]!==o||e[31]!==d||e[32]!==a||e[33]!==b||e[34]!==c||e[35]!==f||e[36]!==h||e[37]!==r?(se=async()=>{const pe=u.trim(),st=f.trim(),nt=h.trim();if(!pe){V.error(r("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!st){V.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!b){V.error(r("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(X){V.error(r("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const Ge={id:Gg(),label:pe,source:st,...nt?{subpath:nt}:{},...v?{gitIdentityId:v}:{}},ft=[...w,Ge];try{await It({skillCatalogs:ft}),E(ft),V.success(r("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),await d(Ge.id,{refresh:!0}),c(Ge.id),a(!1)}catch(wt){const Ct=wt;V.error(Ct instanceof Error?Ct.message:r("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=w,e[27]=v,e[28]=X,e[29]=u,e[30]=o,e[31]=d,e[32]=a,e[33]=b,e[34]=c,e[35]=f,e[36]=h,e[37]=r,e[38]=se):se=e[38];const ce=se;let oe;e[39]!==r?(oe=r("settings.skills.catalog.add.title"),e[39]=r,e[40]=oe):oe=e[40];let xe;e[41]!==oe?(xe=t.jsx(Vt,{children:oe}),e[41]=oe,e[42]=xe):xe=e[42];let we;e[43]!==r?(we=r("settings.skills.catalog.add.descriptionPrefix"),e[43]=r,e[44]=we):we=e[44];let he;e[45]===Symbol.for("react.memo_cache_sentinel")?(he=t.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=he):he=e[45];let Ie;e[46]!==r?(Ie=r("settings.skills.catalog.add.descriptionSuffix"),e[46]=r,e[47]=Ie):Ie=e[47];let ve;e[48]!==we||e[49]!==Ie?(ve=t.jsxs(qt,{children:[we," ",he,Ie]}),e[48]=we,e[49]=Ie,e[50]=ve):ve=e[50];let be;e[51]!==xe||e[52]!==ve?(be=t.jsxs(_t,{children:[xe,ve]}),e[51]=xe,e[52]=ve,e[53]=be):be=e[53];let ye;e[54]!==r?(ye=r("settings.skills.catalog.add.field.catalogName"),e[54]=r,e[55]=ye):ye=e[55];let te;e[56]!==ye?(te=t.jsx("label",{className:"typography-ui-label text-foreground",children:ye}),e[56]=ye,e[57]=te):te=e[57];let ie;e[58]===Symbol.for("react.memo_cache_sentinel")?(ie=pe=>S(pe.target.value),e[58]=ie):ie=e[58];let ge;e[59]!==r?(ge=r("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=r,e[60]=ge):ge=e[60];let _;e[61]!==u||e[62]!==ge?(_=t.jsx(it,{value:u,onChange:ie,placeholder:ge}),e[61]=u,e[62]=ge,e[63]=_):_=e[63];let ee;e[64]!==te||e[65]!==_?(ee=t.jsxs("div",{className:"space-y-2",children:[te,_]}),e[64]=te,e[65]=_,e[66]=ee):ee=e[66];let ne;e[67]!==r?(ne=r("settings.skills.catalog.add.field.repository"),e[67]=r,e[68]=ne):ne=e[68];let ue;e[69]!==ne?(ue=t.jsx("label",{className:"typography-ui-label text-foreground",children:ne}),e[69]=ne,e[70]=ue):ue=e[70];let Me;e[71]===Symbol.for("react.memo_cache_sentinel")?(Me=pe=>{g(pe.target.value),U({clearIdentity:!0})},e[71]=Me):Me=e[71];let ke;e[72]!==r?(ke=r("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[72]=r,e[73]=ke):ke=e[73];let De;e[74]!==f||e[75]!==ke?(De=t.jsx(it,{value:f,onChange:Me,placeholder:ke}),e[74]=f,e[75]=ke,e[76]=De):De=e[76];let Ae;e[77]!==r?(Ae=r("settings.skills.catalog.add.field.repositoryHint"),e[77]=r,e[78]=Ae):Ae=e[78];let Pe;e[79]!==Ae?(Pe=t.jsx("p",{className:"typography-micro text-muted-foreground",children:Ae}),e[79]=Ae,e[80]=Pe):Pe=e[80];let Re;e[81]!==ue||e[82]!==De||e[83]!==Pe?(Re=t.jsxs("div",{className:"space-y-2",children:[ue,De,Pe]}),e[81]=ue,e[82]=De,e[83]=Pe,e[84]=Re):Re=e[84];let Oe;e[85]!==r?(Oe=r("settings.skills.catalog.add.field.optionalSubpath"),e[85]=r,e[86]=Oe):Oe=e[86];let $e;e[87]!==Oe?($e=t.jsx("label",{className:"typography-ui-label text-foreground",children:Oe}),e[87]=Oe,e[88]=$e):$e=e[88];let Be;e[89]===Symbol.for("react.memo_cache_sentinel")?(Be=pe=>{D(pe.target.value),U({clearIdentity:!0})},e[89]=Be):Be=e[89];let Le;e[90]!==r?(Le=r("settings.skills.catalog.shared.field.subpathPlaceholder"),e[90]=r,e[91]=Le):Le=e[91];let Ue;e[92]!==h||e[93]!==Le?(Ue=t.jsx(it,{value:h,onChange:Be,placeholder:Le}),e[92]=h,e[93]=Le,e[94]=Ue):Ue=e[94];let le;e[95]!==$e||e[96]!==Ue?(le=t.jsxs("div",{className:"space-y-2",children:[$e,Ue]}),e[95]=$e,e[96]=Ue,e[97]=le):le=e[97];let q;e[98]!==v||e[99]!==M||e[100]!==r?(q=M.length>0&&!gs()?t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:r("settings.skills.catalog.shared.auth.title")}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:r("settings.skills.catalog.shared.auth.description")})]}),t.jsxs(Ft,{value:v||"",onValueChange:pe=>{j(pe),U()},children:[t.jsx(Ot,{className:"w-fit",children:t.jsx("span",{children:M.find(pe=>pe.id===v)?.name||r("settings.skills.catalog.shared.auth.chooseIdentity")})}),t.jsx(Lt,{align:"start",children:M.map(rh)})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:r("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[98]=v,e[99]=M,e[100]=r,e[101]=q):q=e[101];let me;e[102]!==N||e[103]!==r?(me=N!==null?t.jsx("div",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.add.scanResult",{count:N})}):null,e[102]=N,e[103]=r,e[104]=me):me=e[104];let Ne;e[105]!==X||e[106]!==r?(Ne=X?t.jsx("div",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.add.duplicateMessage")}):null,e[105]=X,e[106]=r,e[107]=Ne):Ne=e[107];let Ee;e[108]!==ee||e[109]!==Re||e[110]!==le||e[111]!==q||e[112]!==me||e[113]!==Ne?(Ee=t.jsxs("div",{className:"space-y-4",children:[ee,Re,le,q,me,Ne]}),e[108]=ee,e[109]=Re,e[110]=le,e[111]=q,e[112]=me,e[113]=Ne,e[114]=Ee):Ee=e[114];let Ce;e[115]!==a?(Ce=()=>a(!1),e[115]=a,e[116]=Ce):Ce=e[116];let He;e[117]!==r?(He=r("settings.common.actions.cancel"),e[117]=r,e[118]=He):He=e[118];let G;e[119]!==Ce||e[120]!==He?(G=t.jsx(J,{size:"sm",variant:"ghost",onClick:Ce,children:He}),e[119]=Ce,e[120]=He,e[121]=G):G=e[121];let $;e[122]!==Z?($=()=>{Z()},e[122]=Z,e[123]=$):$=e[123];let fe;e[124]!==x||e[125]!==f?(fe=x||!f.trim(),e[124]=x,e[125]=f,e[126]=fe):fe=e[126];let L;e[127]===Symbol.for("react.memo_cache_sentinel")?(L=t.jsx(A,{name:"git-repository",className:"h-4 w-4"}),e[127]=L):L=e[127];let Fe;e[128]!==x||e[129]!==r?(Fe=r(x?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[128]=x,e[129]=r,e[130]=Fe):Fe=e[130];let Je;e[131]!==$||e[132]!==fe||e[133]!==Fe?(Je=t.jsxs(J,{size:"sm",className:"gap-2",variant:"ghost",onClick:$,disabled:fe,children:[L,Fe]}),e[131]=$,e[132]=fe,e[133]=Fe,e[134]=Je):Je=e[134];let Xe;e[135]!==ce?(Xe=()=>{ce()},e[135]=ce,e[136]=Xe):Xe=e[136];let et;e[137]!==X||e[138]!==u||e[139]!==b||e[140]!==f?(et=!b||X||!u.trim()||!f.trim(),e[137]=X,e[138]=u,e[139]=b,e[140]=f,e[141]=et):et=e[141];let at;e[142]!==r?(at=r("settings.skills.catalog.add.actions.addCatalog"),e[142]=r,e[143]=at):at=e[143];let lt;e[144]!==Xe||e[145]!==et||e[146]!==at?(lt=t.jsx(J,{size:"sm",onClick:Xe,disabled:et,children:at}),e[144]=Xe,e[145]=et,e[146]=at,e[147]=lt):lt=e[147];let Ze;e[148]!==G||e[149]!==Je||e[150]!==lt?(Ze=t.jsxs(Yt,{children:[G,Je,lt]}),e[148]=G,e[149]=Je,e[150]=lt,e[151]=Ze):Ze=e[151];let We;e[152]!==be||e[153]!==Ee||e[154]!==Ze?(We=t.jsxs(Bt,{className:"max-w-xl",children:[be,Ee,Ze]}),e[152]=be,e[153]=Ee,e[154]=Ze,e[155]=We):We=e[155];let pt;return e[156]!==a||e[157]!==n||e[158]!==We?(pt=t.jsx(Ut,{open:n,onOpenChange:a,children:We}),e[156]=a,e[157]=n,e[158]=We,e[159]=pt):pt=e[159],pt};function Xg(s){return s.scanRepo}function Zg(s){return s.loadCatalog}function eh(s){return s.loadSource}function th(s){return s.setSelectedSource}function sh(s){return s.isScanning}function nh(s){return s.defaultGitIdentityId}function ah(s){return s.loadDefaultGitIdentityId}function rh(s){return t.jsx(ht,{value:s.id,children:s.name},s.id)}const ih=s=>{const e=rt.c(85),{open:n,onOpenChange:a,conflicts:r,onConfirm:i}=s,{t:o}=dt();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];const[c,x]=l.useState(d);let m,p;e[1]!==r||e[2]!==n?(m=()=>{if(!n)return;const ce={};for(const oe of r)ce[oe.skillName]="skip";x(ce)},p=[n,r],e[1]=r,e[2]=n,e[3]=m,e[4]=p):(m=e[3],p=e[4]),l.useEffect(m,p);let u;e[5]!==r?(u=ce=>{const oe={};for(const xe of r)oe[xe.skillName]=ce;x(oe)},e[5]=r,e[6]=u):u=e[6];const S=u;let f;e[7]!==r||e[8]!==c?(f=r.length>0&&r.every(ce=>c[ce.skillName]),e[7]=r,e[8]=c,e[9]=f):f=e[9];const g=f;let h;e[10]!==o?(h=o("settings.skills.catalog.conflicts.title"),e[10]=o,e[11]=h):h=e[11];let D;e[12]!==h?(D=t.jsx(Vt,{children:h}),e[12]=h,e[13]=D):D=e[13];let k;e[14]!==o?(k=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=k):k=e[15];let w;e[16]!==k?(w=t.jsx(qt,{children:k}),e[16]=k,e[17]=w):w=e[17];let E;e[18]!==D||e[19]!==w?(E=t.jsxs(_t,{children:[D,w]}),e[18]=D,e[19]=w,e[20]=E):E=e[20];let N;e[21]!==r.length||e[22]!==o?(N=o("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=o,e[23]=N):N=e[23];let y;e[24]!==N?(y=t.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[24]=N,e[25]=y):y=e[25];let b;e[26]!==S?(b=()=>S("skip"),e[26]=S,e[27]=b):b=e[27];let P;e[28]!==o?(P=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=P):P=e[29];let z;e[30]!==b||e[31]!==P?(z=t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:b,children:P}),e[30]=b,e[31]=P,e[32]=z):z=e[32];let M;e[33]!==S?(M=()=>S("overwrite"),e[33]=S,e[34]=M):M=e[34];let I;e[35]!==o?(I=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=I):I=e[36];let v;e[37]!==M||e[38]!==I?(v=t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:M,children:I}),e[37]=M,e[38]=I,e[39]=v):v=e[39];let j;e[40]!==z||e[41]!==v?(j=t.jsxs("div",{className:"flex items-center gap-2",children:[z,v]}),e[40]=z,e[41]=v,e[42]=j):j=e[42];let O;e[43]!==y||e[44]!==j?(O=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[y,j]}),e[43]=y,e[44]=j,e[45]=O):O=e[45];let T;if(e[46]!==r||e[47]!==c||e[48]!==o){let ce;e[50]!==c||e[51]!==o?(ce=oe=>t.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label truncate",children:oe.skillName}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:oe.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:oe.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),t.jsxs(Ft,{value:c[oe.skillName]||"skip",onValueChange:xe=>x(we=>({...we,[oe.skillName]:xe})),children:[t.jsx(Ot,{className:"w-fit",children:t.jsx("span",{className:"capitalize",children:(c[oe.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),t.jsx(ht,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},oe.skillName),e[50]=c,e[51]=o,e[52]=ce):ce=e[52],T=r.map(ce),e[46]=r,e[47]=c,e[48]=o,e[49]=T}else T=e[49];let U;e[53]!==T?(U=t.jsx("div",{className:"space-y-2",children:T}),e[53]=T,e[54]=U):U=e[54];let B;e[55]!==O||e[56]!==U?(B=t.jsxs("div",{className:"space-y-3",children:[O,U]}),e[55]=O,e[56]=U,e[57]=B):B=e[57];let Q;e[58]!==a?(Q=()=>a(!1),e[58]=a,e[59]=Q):Q=e[59];let W;e[60]!==o?(W=o("settings.common.actions.cancel"),e[60]=o,e[61]=W):W=e[61];let R;e[62]!==Q||e[63]!==W?(R=t.jsx(J,{size:"sm",variant:"ghost",onClick:Q,children:W}),e[62]=Q,e[63]=W,e[64]=R):R=e[64];let Y;e[65]!==c||e[66]!==i?(Y=()=>i(c),e[65]=c,e[66]=i,e[67]=Y):Y=e[67];const F=!g;let H;e[68]!==o?(H=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=H):H=e[69];let X;e[70]!==Y||e[71]!==F||e[72]!==H?(X=t.jsx(J,{size:"sm",onClick:Y,disabled:F,children:H}),e[70]=Y,e[71]=F,e[72]=H,e[73]=X):X=e[73];let re;e[74]!==R||e[75]!==X?(re=t.jsxs(Yt,{children:[R,X]}),e[74]=R,e[75]=X,e[76]=re):re=e[76];let Z;e[77]!==E||e[78]!==B||e[79]!==re?(Z=t.jsxs(Bt,{className:"max-w-2xl",children:[E,B,re]}),e[77]=E,e[78]=B,e[79]=re,e[80]=Z):Z=e[80];let se;return e[81]!==a||e[82]!==n||e[83]!==Z?(se=t.jsx(Ut,{open:n,onOpenChange:a,children:Z}),e[81]=a,e[82]=n,e[83]=Z,e[84]=se):se=e[84],se},Wr=[{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 Jn(s,e){return s==="project"&&e==="claude"?"project-claude":s==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":s==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Ll(s){if(s==="user-claude")return{scope:"user",source:"claude"};if(s==="project-claude")return{scope:"project",source:"claude"};const e=Wr.find(n=>n.value===s);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const oh=s=>{const e=rt.c(124),{open:n,onOpenChange:a,item:r}=s,{t:i}=dt(),o=Bs(lh),d=Bs(ch),[c,x]=l.useState("user"),[m,p]=l.useState("opencode"),u=as(dh),S=as(mh),[f,g]=l.useState(null),[h,D]=l.useState(!1);let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[0]=k):k=e[0];const[w,E]=l.useState(k),[N,y]=l.useState(null);let b,P;e[1]!==S||e[2]!==n?(b=()=>{n&&(x("user"),p("opencode"),g(S),D(!1),E([]),y(null))},P=[n,S],e[1]=S,e[2]=n,e[3]=b,e[4]=P):(b=e[3],P=e[4]),l.useEffect(b,P);let z;e[5]!==i?(z=le=>{switch(le){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]=z):z=e[6];const M=z;let I;e[7]!==i?(I=le=>{switch(le){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]=I):I=e[8];const v=I;let j;e:{if(u.length===0){j=null;break e}if(f&&u.some(le=>le.id===f)){j=f;break e}if(S&&u.some(le=>le.id===S)){j=S;break e}j=u[0]?.id??null}const O=j;let T;e:{if(c!=="project"){T=null;break e}const le=O;if(!le){T=null;break e}let q;if(e[9]!==le||e[10]!==u){let Ne;e[12]!==le?(Ne=Ee=>Ee.id===le,e[12]=le,e[13]=Ne):Ne=e[13],q=u.find(Ne),e[9]=le,e[10]=u,e[11]=q}else q=e[11];T=q?.path??null}const U=T;let B;e[14]!==o||e[15]!==r||e[16]!==a||e[17]!==i?(B=async le=>{const q={skillDir:le.skillDir};r?.clawdhub&&(q.clawdhub={slug:r.clawdhub.slug,version:r.clawdhub.version});const me=await o({source:le.source,subpath:le.subpath,gitIdentityId:r?.gitIdentityId,scope:le.scope,targetSource:le.targetSource,selections:[q],conflictPolicy:"prompt",conflictDecisions:le.conflictDecisions},{directory:le.directoryOverride??null});if(me.ok){V.success(i("settings.skills.catalog.installSkill.toast.installed")),a(!1);return}if(me.error?.kind==="conflicts"){y({source:le.source,subpath:le.subpath,scope:le.scope,targetSource:le.targetSource,skillDir:le.skillDir,directoryOverride:le.directoryOverride??null}),E(me.error.conflicts),D(!0);return}if(me.error?.kind==="authRequired"){V.error(me.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}V.error(me.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=o,e[15]=r,e[16]=a,e[17]=i,e[18]=B):B=e[18];const Q=B;if(!r)return null;let W;e[19]!==i?(W=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=W):W=e[20];let R;e[21]!==W?(R=t.jsx(Vt,{children:W}),e[21]=W,e[22]=R):R=e[22];let Y;e[23]!==i?(Y=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=Y):Y=e[24];let F;e[25]!==r.skillName?(F=t.jsx("span",{className:"font-semibold text-foreground",children:r.skillName}),e[25]=r.skillName,e[26]=F):F=e[26];let H;e[27]!==i?(H=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=H):H=e[28];let X;e[29]!==Y||e[30]!==F||e[31]!==H?(X=t.jsxs(qt,{children:[Y," ",F," ",H]}),e[29]=Y,e[30]=F,e[31]=H,e[32]=X):X=e[32];let re;e[33]!==R||e[34]!==X?(re=t.jsxs(_t,{children:[R,X]}),e[33]=R,e[34]=X,e[35]=re):re=e[35];let Z;e[36]!==i?(Z=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=Z):Z=e[37];let se;e[38]!==Z?(se=t.jsx("span",{className:"typography-ui-label text-foreground",children:Z}),e[38]=Z,e[39]=se):se=e[39];let ce;e[40]!==c||e[41]!==m?(ce=Jn(c,m),e[40]=c,e[41]=m,e[42]=ce):ce=e[42];let oe;e[43]===Symbol.for("react.memo_cache_sentinel")?(oe=le=>{const q=Ll(le);x(q.scope),p(q.source==="agents"?"agents":"opencode")},e[43]=oe):oe=e[43];let xe;e[44]!==c?(xe=c==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=xe):xe=e[45];let we;e[46]!==m?(we=m==="agents"?t.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=we):we=e[47];let he;e[48]!==M||e[49]!==c||e[50]!==m?(he=M(Jn(c,m)),e[48]=M,e[49]=c,e[50]=m,e[51]=he):he=e[51];let Ie;e[52]!==he?(Ie=t.jsx("span",{children:he}),e[52]=he,e[53]=Ie):Ie=e[53];let ve;e[54]!==xe||e[55]!==we||e[56]!==Ie?(ve=t.jsxs(Ot,{className:"w-fit gap-1.5",children:[xe,we,Ie]}),e[54]=xe,e[55]=we,e[56]=Ie,e[57]=ve):ve=e[57];let be;e[58]!==v||e[59]!==M?(be=Wr.map(le=>t.jsx(ht,{value:le.value,className:"pr-2 [&>span:first-child]:hidden",children:t.jsxs("div",{className:"flex flex-col gap-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[le.scope==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),le.source==="agents"?t.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:M(le.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:v(le.value)})]})},le.value)),e[58]=v,e[59]=M,e[60]=be):be=e[60];let ye;e[61]!==be?(ye=t.jsx(Lt,{align:"start",children:be}),e[61]=be,e[62]=ye):ye=e[62];let te;e[63]!==ce||e[64]!==ve||e[65]!==ye?(te=t.jsxs(Ft,{value:ce,onValueChange:oe,children:[ve,ye]}),e[63]=ce,e[64]=ve,e[65]=ye,e[66]=te):te=e[66];let ie;e[67]!==se||e[68]!==te?(ie=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[se,te]}),e[67]=se,e[68]=te,e[69]=ie):ie=e[69];let ge;e[70]!==u||e[71]!==O||e[72]!==c||e[73]!==i?(ge=c==="project"&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),u.length===0?t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):t.jsxs(Ft,{value:O??"",onValueChange:le=>g(le),disabled:u.length===1,children:[t.jsx(Ot,{className:"w-fit",children:t.jsx(Kt,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),t.jsx(Lt,{align:"start",children:u.map(uh)})]})]}),e[70]=u,e[71]=O,e[72]=c,e[73]=i,e[74]=ge):ge=e[74];let _;e[75]!==r.warnings?(_=r.warnings?.length?t.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:r.warnings.join(" · ")}):null,e[75]=r.warnings,e[76]=_):_=e[76];let ee;e[77]!==ie||e[78]!==ge||e[79]!==_?(ee=t.jsxs("div",{className:"mt-2 space-y-3",children:[ie,ge,_]}),e[77]=ie,e[78]=ge,e[79]=_,e[80]=ee):ee=e[80];let ne;e[81]!==a?(ne=()=>a(!1),e[81]=a,e[82]=ne):ne=e[82];let ue;e[83]!==i?(ue=i("settings.common.actions.cancel"),e[83]=i,e[84]=ue):ue=e[84];let Me;e[85]!==ne||e[86]!==ue?(Me=t.jsx(J,{size:"sm",variant:"ghost",onClick:ne,children:ue}),e[85]=ne,e[86]=ue,e[87]=Me):Me=e[87];const ke=d||!r.installable||c==="project"&&!U;let De;e[88]!==U||e[89]!==Q||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==m?(De=()=>{Q({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:m,skillDir:r.skillDir,directoryOverride:U})},e[88]=U,e[89]=Q,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=m,e[95]=De):De=e[95];let Ae;e[96]!==d||e[97]!==i?(Ae=i(d?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=d,e[97]=i,e[98]=Ae):Ae=e[98];let Pe;e[99]!==ke||e[100]!==De||e[101]!==Ae?(Pe=t.jsx(J,{size:"sm",disabled:ke,onClick:De,children:Ae}),e[99]=ke,e[100]=De,e[101]=Ae,e[102]=Pe):Pe=e[102];let Re;e[103]!==Me||e[104]!==Pe?(Re=t.jsxs(Yt,{children:[Me,Pe]}),e[103]=Me,e[104]=Pe,e[105]=Re):Re=e[105];let Oe;e[106]!==re||e[107]!==ee||e[108]!==Re?(Oe=t.jsxs(Bt,{className:"max-w-md",children:[re,ee,Re]}),e[106]=re,e[107]=ee,e[108]=Re,e[109]=Oe):Oe=e[109];let $e;e[110]!==a||e[111]!==n||e[112]!==Oe?($e=t.jsx(Ut,{open:n,onOpenChange:a,children:Oe}),e[110]=a,e[111]=n,e[112]=Oe,e[113]=$e):$e=e[113];let Be;e[114]!==N||e[115]!==Q?(Be=le=>{N&&(Q({source:N.source,subpath:N.subpath,scope:N.scope,targetSource:N.targetSource,skillDir:N.skillDir,conflictDecisions:le,directoryOverride:N.directoryOverride??null}),D(!1))},e[114]=N,e[115]=Q,e[116]=Be):Be=e[116];let Le;e[117]!==w||e[118]!==h||e[119]!==Be?(Le=t.jsx(ih,{open:h,onOpenChange:D,conflicts:w,onConfirm:Be}),e[117]=w,e[118]=h,e[119]=Be,e[120]=Le):Le=e[120];let Ue;return e[121]!==$e||e[122]!==Le?(Ue=t.jsxs(t.Fragment,{children:[$e,Le]}),e[121]=$e,e[122]=Le,e[123]=Ue):Ue=e[123],Ue};function lh(s){return s.installSkills}function ch(s){return s.isInstalling}function dh(s){return s.projects}function mh(s){return s.activeProjectId}function uh(s){return t.jsx(ht,{value:s.id,children:s.label||s.path},s.id)}const ph=async()=>{try{const s=Fs()?.settings;if(s)return(await s.load())?.settings||{};const e=await jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},gh=({mode:s,onModeChange:e,showModeTabs:n=!0})=>{const{t:a}=dt(),{sources:r,itemsBySource:i,selectedSourceId:o,setSelectedSource:d,loadCatalog:c,loadSource:x,loadMoreClawdHub:m,isLoadingCatalog:p,isLoadingSource:u,isLoadingMore:S,loadedSourceIds:f,clawdhubHasMoreBySource:g,lastCatalogError:h}=Bs(Ss(R=>({sources:R.sources,itemsBySource:R.itemsBySource,selectedSourceId:R.selectedSourceId,setSelectedSource:R.setSelectedSource,loadCatalog:R.loadCatalog,loadSource:R.loadSource,loadMoreClawdHub:R.loadMoreClawdHub,isLoadingCatalog:R.isLoadingCatalog,isLoadingSource:R.isLoadingSource,isLoadingMore:R.isLoadingMore,loadedSourceIds:R.loadedSourceIds,clawdhubHasMoreBySource:R.clawdhubHasMoreBySource,lastCatalogError:R.lastCatalogError}))),[D,k]=l.useState(""),[w,E]=l.useState(!1),[N,y]=l.useState(!1),[b,P]=l.useState(null),[z,M]=l.useState(!1),[I,v]=l.useState(!1);l.useEffect(()=>{c()},[c]),l.useEffect(()=>{o&&(f[o]||x(o))},[o,f,x]);const j=l.useMemo(()=>o?i[o]||[]:[],[i,o]),O=l.useMemo(()=>{const R=D.trim().toLowerCase();return R?j.filter(Y=>{const F=Y.skillName.toLowerCase(),H=(Y.description||"").toLowerCase(),X=(Y.frontmatterName||"").toLowerCase();return F.includes(R)||H.includes(R)||X.includes(R)}):j},[j,D]),T=l.useMemo(()=>r.find(R=>R.id===o)||null,[r,o]),U=!!(o&&o.startsWith("custom:")),B=T?.source==="clawdhub:registry"||T?.sourceType==="clawdhub",Q=!!(o&&(g[o]??!0)),W=async()=>{if(!(!o||!U)){M(!0);try{const R=await ph(),F=(Array.isArray(R?.skillCatalogs)?R?.skillCatalogs:[]).filter(H=>H.id!==o);await It({skillCatalogs:F}),await c({refresh:!0}),v(!1)}finally{M(!1)}}};return t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsxs("div",{className:"mb-4",children:[n&&t.jsx("div",{className:"mb-4",children:t.jsx("div",{className:"h-10",children:t.jsx(xn,{items:[{id:"manual",label:a("settings.skills.catalog.page.mode.manual")},{id:"external",label:a("settings.skills.catalog.page.mode.external")}],activeId:s,onSelect:R=>e(R),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground px-1",children:a("settings.skills.catalog.page.title")})]}),t.jsxs("div",{"data-settings-item":"skills.catalog.source",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:a("settings.skills.catalog.page.section.sourceRepository")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[t.jsxs(Ft,{value:o||"",onValueChange:R=>d(R),children:[t.jsx(Ot,{className:"w-fit",children:t.jsx(Kt,{placeholder:a("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:T?.label})}),t.jsx(Lt,{align:"start",children:r.map(R=>t.jsx(ht,{value:R.id,children:R.label},R.id))})]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{o?x(o,{refresh:!0}):c({refresh:!0})},disabled:p||u,title:a("settings.skills.catalog.page.actions.refreshTitle"),children:t.jsx(A,{name:"refresh",className:de("h-3.5 w-3.5",(p||u)&&"animate-spin")})}),U&&t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>v(!0),disabled:z,title:a("settings.skills.catalog.page.actions.removeCatalogTitle"),children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})}),t.jsxs(J,{"data-settings-item":"skills.catalog.add-catalog",size:"xs",className:"!font-normal gap-1",onClick:()=>E(!0),children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"})," ",a("settings.skills.catalog.page.actions.addCatalog")]})]}),t.jsxs("div",{"data-settings-item":"skills.catalog.search",className:"py-1.5",children:[t.jsxs("div",{className:"relative",children:[t.jsx(A,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),t.jsx(it,{value:D,onChange:R=>k(R.target.value),placeholder:a("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),t.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:p?a("settings.skills.catalog.page.loading.catalog"):a("settings.skills.catalog.page.foundCount",{count:O.length})})]})]})]}),h&&t.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[t.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:a("settings.skills.catalog.page.error.catalogTitle")}),t.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:h.message})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("section",{className:"px-2 pb-2 pt-0",children:O.length===0&&!u?t.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[t.jsx("p",{className:"typography-body",children:a("settings.skills.catalog.page.empty.noSkillsTitle")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.skills.catalog.page.empty.noSkillsDescription")})]}):u?t.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[t.jsx(A,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),t.jsx("p",{className:"typography-meta",children:a("settings.skills.catalog.page.loading.skills")})]}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:O.map(R=>{const Y=R.installed?.isInstalled,F=R.installed?.scope;return t.jsx("div",{className:"py-2",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:R.skillName}),Y&&t.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:a("settings.skills.catalog.page.badge.installed",{scope:F||a("settings.skills.catalog.page.badge.unknown")})}),!R.installable&&t.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:a("settings.skills.catalog.page.badge.notInstallable")})]}),R.description?t.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:R.description}):t.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:a("settings.skills.catalog.shared.noDescription")}),R.clawdhub&&t.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[R.clawdhub.owner&&t.jsxs("span",{children:[a("settings.skills.catalog.page.byOwnerPrefix")," ",t.jsx("span",{className:"font-medium text-foreground/80",children:R.clawdhub.owner})]}),t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(A,{name:"download",className:"h-3 w-3"}),R.clawdhub.downloads?.toLocaleString()??0]}),(R.clawdhub.stars??0)>0&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(A,{name:"star",className:"h-3 w-3"}),R.clawdhub.stars]}),t.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",R.clawdhub.version]})]}),R.warnings?.length?t.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:R.warnings.join(" · ")}):null]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!R.installable,onClick:()=>{P(R),y(!0)},children:a("settings.skills.catalog.shared.actions.install")})]})},`${R.sourceId}:${R.skillDir}`)})})}),B&&Q&&!u&&O.length>0&&t.jsx("div",{className:"flex justify-center mt-2 px-2",children:t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:S,children:a(S?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),t.jsx(Yg,{open:w,onOpenChange:E}),t.jsx(oh,{open:N,onOpenChange:y,item:b}),t.jsx(Ut,{open:I,onOpenChange:R=>{z||v(R)},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:a("settings.skills.catalog.page.removeDialog.title")}),t.jsx(qt,{children:a("settings.skills.catalog.page.removeDialog.description")})]}),t.jsxs(Yt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>v(!1),disabled:z,children:a("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",variant:"destructive",onClick:()=>{W()},disabled:z,children:a("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})};function vo(s,e){const n=s.metadata.variant==="dark",a=s.config?.fonts?.mono||"monospace",r=s.colors.syntax.highlights||{},i=s.colors.syntax.tokens||{},o=Rs.theme({"&":{backgroundColor:"var(--background)",color:s.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:a,backgroundColor:"var(--background)"},".cm-comment":{color:s.colors.syntax.base.comment},".cm-keyword":{color:s.colors.syntax.base.keyword},".cm-string":{color:s.colors.syntax.base.string},".cm-string-2":{color:i.stringEscape||s.colors.syntax.base.string},".cm-number":{color:s.colors.syntax.base.number},".cm-operator":{color:s.colors.syntax.base.operator},".cm-punctuation":{color:i.punctuation||s.colors.syntax.base.comment},".cm-atom":{color:i.boolean||s.colors.syntax.base.number},".cm-builtin":{color:i.functionCall||s.colors.syntax.base.function},".cm-def":{color:i.variableGlobal||s.colors.syntax.base.variable},".cm-attribute":{color:i.variableOther||i.variableProperty||s.colors.syntax.base.operator},".cm-meta":{color:s.colors.syntax.base.comment},".cm-property":{color:i.variableProperty||s.colors.syntax.base.keyword},".cm-variable":{color:s.colors.syntax.base.variable},".cm-variable-2":{color:i.variableOther||s.colors.syntax.base.function},".cm-variable-3":{color:i.variableGlobal||s.colors.syntax.base.type},".cm-tag":{color:i.tag||s.colors.syntax.base.keyword},".cm-link":{color:i.url||s.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:s.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:s.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:s.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||s.colors.syntax.base.comment,borderRight:`1px solid ${s.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||s.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:s.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:s.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-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${s.colors.interactive.border}`,backgroundColor:s.colors.surface.elevated,color:s.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${s.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${s.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${s.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:s.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 ${s.colors.interactive.border}`,backgroundColor:s.colors.surface.background,color:s.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:s.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:s.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:s.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:s.colors.interactive.hover,borderColor:s.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:s.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:s.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:s.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:s.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:s.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:s.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:s.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:s.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${s.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:s.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:s.colors.interactive.hover,color:s.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:s.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${s.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:s.colors.interactive.selection,color:s.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${s.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:n}),d=ni.define([{tag:[Te.comment,Te.docComment,Te.meta,Te.documentMeta],class:"cm-comment"},{tag:[Te.keyword,Te.controlKeyword,Te.moduleKeyword,Te.definitionKeyword,Te.modifier],class:"cm-keyword"},{tag:[Te.operatorKeyword,Te.operator,Te.derefOperator,Te.updateOperator,Te.definitionOperator,Te.typeOperator,Te.controlOperator,Te.logicOperator,Te.bitwiseOperator,Te.arithmeticOperator,Te.compareOperator],class:"cm-operator"},{tag:[Te.punctuation,Te.separator,Te.bracket,Te.paren,Te.brace,Te.squareBracket,Te.angleBracket],class:"cm-punctuation"},{tag:[Te.string,Te.regexp,Te.attributeValue,Te.special(Te.string),Te.monospace],class:"cm-string"},{tag:Te.escape,class:"cm-string-2"},{tag:[Te.number,Te.bool,Te.atom,Te.null,Te.self],class:"cm-number"},{tag:[Te.function(Te.variableName),Te.function(Te.definition(Te.variableName)),Te.function(Te.propertyName),Te.standard(Te.variableName),Te.special(Te.variableName)],class:"cm-builtin"},{tag:Te.definition(Te.variableName),class:"cm-def"},{tag:[Te.variableName,Te.local(Te.variableName),Te.constant(Te.variableName),Te.literal],class:"cm-variable"},{tag:Te.propertyName,class:"cm-property"},{tag:Te.attributeName,class:"cm-attribute"},{tag:[Te.className,Te.typeName,Te.namespace],class:"cm-variable-3"},{tag:[Te.tagName,Te.labelName,Te.annotation,Te.macroName],class:"cm-tag"},{tag:Te.link,class:"cm-link"},{tag:[Te.heading,Te.heading1,Te.heading2,Te.heading3,Te.heading4,Te.heading5,Te.heading6],class:"cm-keyword"}]),c=ni.define([{tag:[Te.comment,Te.docComment,Te.meta,Te.documentMeta],color:s.colors.syntax.base.comment},{tag:[Te.keyword,Te.controlKeyword,Te.moduleKeyword,Te.definitionKeyword,Te.modifier],color:s.colors.syntax.base.keyword},{tag:[Te.operatorKeyword,Te.operator,Te.derefOperator,Te.updateOperator,Te.definitionOperator,Te.typeOperator,Te.controlOperator,Te.logicOperator,Te.bitwiseOperator,Te.arithmeticOperator,Te.compareOperator],color:s.colors.syntax.base.operator},{tag:[Te.string,Te.regexp,Te.attributeValue,Te.special(Te.string),Te.monospace],color:s.colors.syntax.base.string},{tag:Te.escape,color:i.stringEscape||s.colors.syntax.base.string},{tag:[Te.number,Te.bool,Te.atom,Te.null,Te.self],color:s.colors.syntax.base.number},{tag:[Te.function(Te.variableName),Te.function(Te.definition(Te.variableName)),Te.function(Te.propertyName),Te.standard(Te.variableName),Te.special(Te.variableName)],color:s.colors.syntax.base.function},{tag:Te.definition(Te.variableName),color:i.variableGlobal||s.colors.syntax.base.variable},{tag:[Te.variableName,Te.local(Te.variableName),Te.constant(Te.variableName),Te.literal],color:s.colors.syntax.base.variable},{tag:Te.propertyName,color:i.variableProperty||s.colors.syntax.base.variable},{tag:Te.attributeName,color:i.variableOther||s.colors.syntax.base.variable},{tag:[Te.className,Te.typeName,Te.namespace],color:s.colors.syntax.base.type},{tag:[Te.tagName,Te.labelName,Te.annotation,Te.macroName],color:i.tag||s.colors.syntax.base.keyword},{tag:Te.link,color:i.url||s.colors.syntax.base.function,textDecoration:"underline"},{tag:[Te.punctuation,Te.separator,Te.bracket,Te.paren,Te.brace,Te.squareBracket,Te.angleBracket],color:i.punctuation||s.colors.syntax.base.comment}]);return e?.syntaxColors===!1?[o]:[o,na(Zc,{fallback:!0}),na(ed),na(d),na(c)]}const hh=180,zl=td.define(),fh=1,xh=2,bh=4,jo=new Map,yh=(s,e)=>{const n=`${s}|${e}`,a=jo.get(n);if(a)return a;let r="";s&&(r+=`color:${s};`),e&fh&&(r+="font-style:italic;"),e&xh&&(r+="font-weight:bold;"),e&bh&&(r+="text-decoration:underline;");const i=La.mark({attributes:{style:r}});return jo.set(n,i),i},vh=(s,e)=>{const n=new Br,a=s.state.doc,r=Math.min(e.length,a.lines);for(let i=0;i<r;i+=1){const o=e[i];if(!o||o.length===0)continue;const d=a.line(i+1);let c=d.from;for(const[x,m,p]of o){if(x<=0)continue;const u=c,S=Math.min(c+x,d.to);c+=x,!(S<=u)&&(!m&&!p||n.add(u,S,yh(m,p)))}}return n.finish()},jh=ul.define({create(){return La.none},update(s,e){let n=s.map(e.changes);for(const a of e.effects)a.is(zl)&&(n=a.value);return n},provide:s=>Rs.decorations.from(s)}),wh=s=>ml.fromClass(class{timer;generation=0;constructor(e){this.tokenize(e)}update(e){e.docChanged&&this.schedule(e.view)}schedule(e){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.tokenize(e)},hh)}async tokenize(e){const n=++this.generation,a=e.state.doc.toString(),r=await Md(a,s.language,s.themeName,s.theme);r&&n===this.generation&&e.state.doc.length===a.length&&e.dispatch({effects:zl.of(vh(e,r))})}destroy(){this.timer&&clearTimeout(this.timer)}}),Nh=s=>[jh,wh(s)],kh=()=>{const s=rt.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(gh,{mode:"external",onModeChange:Ah,showModeTabs:!1}),s[0]=e):e=s[0],e},Sh="SKILL.md",Ch="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",Da=(s,e)=>{const n=sd({description:s}).trimEnd(),a=e.trimStart();return`---
23
- ${n}
24
- ---${a?`
25
-
26
- ${a}`:`
27
- `}`},Ph=s=>typeof s=="object"&&s!==null&&!Array.isArray(s),Kl=s=>{const e=s.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:s};let n=null;try{const a=nd(e[1]);if(Ph(a)){const r=a.description;typeof r=="string"&&(n=r)}}catch{n=null}return{description:n,instructions:e[2].replace(/^\r?\n/,"")}},Ih=(s,e)=>{const n=Kl(s);return Da(e,n.instructions)},Dh=()=>{const{t:s}=dt(),{currentTheme:e}=Ua(),{selectedSkillName:n,getSkillByName:a,getSkillDetail:r,createSkill:i,updateSkill:o,skills:d,skillDraft:c,setSkillDraft:x,setSelectedSkill:m}=_s(Ss(le=>({selectedSkillName:le.selectedSkillName,getSkillByName:le.getSkillByName,getSkillDetail:le.getSkillDetail,createSkill:le.createSkill,updateSkill:le.updateSkill,skills:le.skills,skillDraft:le.skillDraft,setSkillDraft:le.setSkillDraft,setSelectedSkill:le.setSelectedSkill}))),p=n?a(n):null,u=!!(c&&c.name===n&&!p),S=!!(n&&!p&&!c),f=p?.path==="<built-in>";l.useEffect(()=>{S&&m(null)},[S,m]);const[g,h]=l.useState(""),[D,k]=l.useState("user"),[w,E]=l.useState("opencode"),[N,y]=l.useState(""),[b,P]=l.useState(""),[z,M]=l.useState(()=>Da("","")),[I,v]=l.useState("edit"),[j,O]=l.useState([]),[T,U]=l.useState([]),[B,Q]=l.useState(!1),[W,R]=l.useState(!1),[Y,F]=l.useState(""),[H,X]=l.useState(""),[re,Z]=l.useState(!1),[se,ce]=l.useState(""),[oe,xe]=l.useState(""),[we,he]=l.useState(null),[Ie,ve]=l.useState(!1),[be,ye]=l.useState(""),[te,ie]=l.useState(null),[ge,_]=l.useState(!1),ee=u?g.trim()!==""||N.trim()!==""||b.trim()!==""||T.length>0:N!==Y||b!==H,ne=we?oe!==be:se.trim()!=="",ue=l.useCallback(le=>{switch(le){case"project-opencode":return s("settings.skills.location.option.projectOpencode.label");case"user-claude":return s("settings.skills.location.option.userClaude.label");case"project-claude":return s("settings.skills.location.option.projectClaude.label");case"user-agents":return s("settings.skills.location.option.userAgents.label");case"project-agents":return s("settings.skills.location.option.projectAgents.label");default:return s("settings.skills.location.option.userOpencode.label")}},[s]),Me=l.useCallback(le=>{switch(le){case"project-opencode":return s("settings.skills.location.option.projectOpencode.description");case"user-claude":return s("settings.skills.location.option.userClaude.description");case"project-claude":return s("settings.skills.location.option.projectClaude.description");case"user-agents":return s("settings.skills.location.option.userAgents.description");case"project-agents":return s("settings.skills.location.option.projectAgents.description");default:return s("settings.skills.location.option.userOpencode.description")}},[s]);l.useEffect(()=>{(async()=>{if(u&&c){const q=c.description||"",me=c.instructions||"";h(c.name||""),k(c.scope||"user"),E(c.source==="agents"?"agents":"opencode"),y(q),P(me),M(Da(q,me)),F(""),X(""),O([]),U(c.pendingFiles||[])}else if(n&&p){R(!0);try{const q=await r(n);if(q){const me=q.sources.md,Ne=me.description||"",Ee=me.instructions||"";y(Ne),P(Ee),M(Da(Ne,Ee)),F(Ne),X(Ee),O(me.supportingFiles||[])}}catch(q){console.error("Failed to load skill details:",q)}finally{R(!1)}}})()},[p,u,n,d,c,r]);const ke=l.useMemo(()=>{const le=[vo(e)],q=ri(Sh);return q&&le.push(q),le.push(Rs.lineWrapping),le},[e]),De=l.useMemo(()=>{const le=se.trim()||"supporting-file.md",q=Rd(le),me=!!q&&q!=="markdown",Ne=[vo(e,me?{syntaxColors:!1}:void 0)],Ee=ri(le);return Ee&&Ne.push(Ee),me&&q&&Ne.push(Nh({language:q,themeName:e.metadata.id,theme:wr(e)})),Ne.push(Rs.lineWrapping),Ne},[e,se]),Ae=l.useCallback(le=>{y(le),M(q=>Ih(q,le))},[]),Pe=l.useCallback(le=>{M(le);const q=Kl(le);y(q.description??""),P(q.instructions)},[]),Re=async()=>{const le=u?g.trim().replace(/\s+/g,"-").toLowerCase():n?.trim();if(!le){V.error(s("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(le)||le.length>64){V.error(s("settings.skills.page.toast.invalidSkillName"));return}if(!N.trim()){V.error(s("settings.skills.page.toast.descriptionRequired"));return}if(u&&d.some(q=>q.name===le)){V.error(s("settings.skills.page.toast.skillExists"));return}Q(!0);try{const q={name:le,description:N.trim(),instructions:b.trim()||void 0,scope:u?D:void 0,source:u?w:void 0,targetPath:u?void 0:p?.path,supportingFiles:u&&T.length>0?T:void 0};let me;u?(me=await i(q),me&&(x(null),U([]),m(le))):(me=await o(le,q),me&&(F(N.trim()),X(b.trim()))),me?V.success(s(u?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):V.error(s(u?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(q){console.error("Error saving skill:",q),V.error(s("settings.skills.page.toast.saveUnexpectedError"))}finally{Q(!1)}},Oe=()=>{he(null),ce(""),xe(""),ye(""),Z(!0)},$e=async le=>{if(he(le),ce(le),u){const me=T.find(Ne=>Ne.path===le)?.content||"";xe(me),ye(me),Z(!0);return}if(n){ve(!0),Z(!0);try{const{readSupportingFile:q}=_s.getState(),me=await q(n,le);xe(me||""),ye(me||"")}catch{V.error(s("settings.skills.page.toast.loadFileContentFailed")),xe(""),ye("")}finally{ve(!1)}}},Be=async()=>{if(!se.trim()){V.error(s("settings.skills.page.toast.fileNameRequired"));return}const le=se.trim(),q=we!==null;if(u){if(q)U(Ee=>Ee.map(Ce=>Ce.path===we?{path:le,content:oe}:Ce)),V.success(s("settings.skills.page.toast.fileUpdated",{path:le}));else{if(T.some(Ee=>Ee.path===le)){V.error(s("settings.skills.page.toast.fileExists"));return}U(Ee=>[...Ee,{path:le,content:oe}]),V.success(s("settings.skills.page.toast.fileAdded",{path:le}))}Z(!1),he(null);return}if(!n){V.error(s("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:me}=_s.getState();if(await me(n,le,oe)){V.success(q?s("settings.skills.page.toast.fileUpdated",{path:le}):s("settings.skills.page.toast.fileCreated",{path:le})),Z(!1),he(null);const Ee=await r(n);Ee&&O(Ee.sources.md.supportingFiles||[])}else V.error(s(q?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Le=le=>{if(u){U(q=>q.filter(me=>me.path!==le)),V.success(s("settings.skills.page.toast.fileRemoved",{path:le}));return}n&&ie(le)},Ue=async()=>{if(!te||!n)return;_(!0);const{deleteSupportingFile:le}=_s.getState();if(await le(n,te)){V.success(s("settings.skills.page.toast.fileDeleted",{path:te}));const me=await r(n);me&&O(me.sources.md.supportingFiles||[]),ie(null)}else V.error(s("settings.skills.page.toast.deleteFileFailed"));_(!1)};return!n&&!c||S?t.jsx("div",{className:"flex h-full items-center justify-center px-4",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.skills.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.skills.page.empty.description")})]})}):W?t.jsx("div",{className:"flex h-full items-center justify-center px-4",children:t.jsx("div",{className:"text-center text-muted-foreground",children:t.jsx("p",{className:"typography-body",children:s("settings.skills.page.loading.details")})})}):t.jsxs(Jt,{outerClassName:"h-full",className:"w-full",children:[t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:u?s("settings.skills.page.title.newSkill"):n}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:p?s("settings.skills.page.subtitle.skillLocation",{location:ue(Jn(p.scope,p.source))}):s("settings.skills.page.subtitle.newSkill")})]})}),t.jsxs("div",{"data-settings-item":"skills.basic-information",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.skills.page.section.basicInformation")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[u&&t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.skills.page.field.skillNameLocation")}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:s("settings.skills.page.field.skillNameHint")}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[t.jsx(it,{value:g,onChange:le=>h(le.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:s("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),t.jsxs(Ft,{value:Jn(D,w),onValueChange:le=>{const q=Ll(le);k(q.scope),E(q.source==="agents"?"agents":"opencode")},children:[t.jsxs(Ot,{className:"w-fit gap-1.5",children:[D==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),w==="agents"?t.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:ue(Jn(D,w))})]}),t.jsx(Lt,{align:"start",children:Wr.map(le=>t.jsx(ht,{value:le.value,children:t.jsxs("div",{className:"flex flex-col gap-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[le.scope==="user"?t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),le.source==="agents"?t.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:ue(le.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Me(le.value)})]})},le.value))})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsxs("span",{className:"typography-ui-label text-foreground",children:[s("settings.common.field.description")," ",t.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:s("settings.skills.page.field.descriptionHint")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(ps,{value:N,onChange:le=>Ae(le.target.value),placeholder:s("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:f})})]})]})]}),t.jsxs("div",{"data-settings-item":"skills.instructions",className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.skills.page.section.instructions")}),t.jsx(qg,{currentMode:I==="preview"?"preview":"edit",onToggle:()=>v(le=>le==="preview"?"edit":"preview")})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx("div",{className:de("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Ch),children:I==="preview"?t.jsx(Jt,{outerClassName:"h-full",className:"h-full",children:t.jsx("div",{className:"min-h-full px-4 py-3",children:t.jsx(jr,{content:z,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):t.jsx(yo,{value:z,onChange:Pe,readOnly:f,extensions:ke,className:"h-full",enableSearch:!0})})})]}),t.jsxs("div",{"data-settings-item":"skills.supporting-files",className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.skills.page.section.supportingFiles")}),t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Oe,disabled:f,children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"})," ",s("settings.skills.page.actions.addFile")]})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:(()=>{const le=u?T:j;return le.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:s("settings.skills.page.supportingFiles.empty")}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:le.map(q=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>$e(q.path),children:[t.jsx(A,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.path}),u&&t.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:s("settings.skills.page.badge.pending")}),!f&&t.jsx(J,{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:me=>{me.stopPropagation(),Le(q.path)},children:t.jsx(A,{name:"delete-bin",className:"h-3 w-3"})})]},q.path))})})()})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:Re,disabled:f||B||!ee,size:"xs",className:"!font-normal",children:s(B?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),t.jsx(Ut,{open:te!==null,onOpenChange:le=>{!le&&!ge&&ie(null)},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("settings.skills.page.deleteFileDialog.title")}),t.jsx(qt,{children:s("settings.skills.page.deleteFileDialog.description",{path:te??""})})]}),t.jsxs(Yt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>ie(null),disabled:ge,children:s("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",variant:"destructive",onClick:Ue,disabled:ge,children:s("settings.common.actions.delete")})]})]})}),t.jsx(Ut,{open:re,onOpenChange:le=>{Z(le),le||he(null)},children:t.jsxs(Bt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[t.jsxs(_t,{className:"flex-shrink-0",children:[t.jsx(Vt,{children:s(we?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),t.jsx(qt,{children:s(we?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),Ie?t.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.skills.page.loading.fileContent")})}):t.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[t.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:s("settings.skills.page.fileDialog.field.filePath")}),t.jsx(it,{value:se,onChange:le=>ce(le.target.value),placeholder:s("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:we!==null}),!we&&t.jsx("p",{className:"typography-micro text-muted-foreground",children:s("settings.skills.page.fileDialog.field.filePathHint")})]}),t.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground flex-shrink-0",children:s("settings.skills.page.fileDialog.field.content")}),t.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:t.jsx(yo,{value:oe,onChange:xe,extensions:De,className:"h-full",enableSearch:!0})})]})]}),t.jsxs(Yt,{className:"mt-4",children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>{Z(!1),he(null)},children:s("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:Be,disabled:Ie||!ne,children:s(we?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},wo=s=>{const e=rt.c(2),{view:n}=s,a=n===void 0?"installed":n;let r;return e[0]!==a?(r=a==="catalog"?t.jsx(kh,{}):t.jsx(Dh,{}),e[0]=a,e[1]=r):r=e[1],r};function Ah(){}const Eh=s=>{const e=rt.c(38),{onItemSelect:n}=s,{t:a}=dt(),r=as(Mh),i=Ke(Rh),o=Ke(Th),{currentTheme:d}=Ua();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=gs(),e[0]=c):c=e[0];const x=c,m=Fh;let p,u;e[1]!==r||e[2]!==i||e[3]!==o?(p=()=>{if(r.length===0){i!==null&&o(null);return}i&&r.some(b=>b.id===i)||o(r[0].id)},u=[r,i,o],e[1]=r,e[2]=i,e[3]=o,e[4]=p,e[5]=u):(p=e[4],u=e[5]),l.useEffect(p,u);let S;e[6]===Symbol.for("react.memo_cache_sentinel")?(S=de("border-b px-3","pt-4 pb-3"),e[6]=S):S=e[6];let f;e[7]!==a?(f=a("settings.page.projects.title"),e[7]=a,e[8]=f):f=e[8];let g;e[9]!==f?(g=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:f}),e[9]=f,e[10]=g):g=e[10];let h;e[11]!==r.length||e[12]!==a?(h=a("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=a,e[13]=h):h=e[13];let D;e[14]!==h?(D=t.jsx("span",{className:"typography-meta text-muted-foreground",children:h}),e[14]=h,e[15]=D):D=e[15];let k;e[16]!==a?(k=!x&&t.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:m,"aria-label":a("settings.projects.sidebar.actions.addProject"),children:t.jsx(A,{name:"add",className:"size-4"})}),e[16]=a,e[17]=k):k=e[17];let w;e[18]!==D||e[19]!==k?(w=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[D,k]}),e[18]=D,e[19]=k,e[20]=w):w=e[20];let E;e[21]!==w||e[22]!==g?(E=t.jsxs("div",{className:S,children:[g,w]}),e[21]=w,e[22]=g,e[23]=E):E=e[23];let N;if(e[24]!==d||e[25]!==n||e[26]!==r||e[27]!==i||e[28]!==o){let b;e[30]!==d||e[31]!==n||e[32]!==i||e[33]!==o?(b=P=>{const z=P.id===i,M=P.icon?Td[P.icon]:null,I=P.color?bl[P.color]??null:null,v=M?t.jsx(A,{name:M,className:de("h-4 w-4",z?"text-foreground":"text-muted-foreground/70"),style:I?{color:I}:void 0}):t.jsx(A,{name:"folder",className:de("h-4 w-4",z?"text-foreground":"text-muted-foreground/70"),style:I?{color:I}:void 0}),j=P.iconImage?t.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:P.iconBackground?{backgroundColor:P.iconBackground}:void 0,children:t.jsx(yl,{project:P,options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:v})}):v;return t.jsx(Mr,{title:P.label||P.path,icon:j,selected:z,onSelect:()=>{o(P.id),n?.()}},P.id)},e[30]=d,e[31]=n,e[32]=i,e[33]=o,e[34]=b):b=e[34],N=r.map(b),e[24]=d,e[25]=n,e[26]=r,e[27]=i,e[28]=o,e[29]=N}else N=e[29];let y;return e[35]!==E||e[36]!==N?(y=t.jsx(Fl,{variant:"background",header:E,children:N}),e[35]=E,e[36]=N,e[37]=y):y=e[37],y};function Mh(s){return s.projects}function Rh(s){return s.settingsProjectsSelectedId}function Th(s){return s.setSettingsProjectsSelectedId}function Fh(){xl.requestDirectoryDialog()}const Oh=({projectRef:s=null})=>{const{t:e}=dt(),{isMobile:n,isTablet:a}=Cs(),r=n||a,i=as(U=>U.getActiveProject()),o=s?.path??i?.path??null,d=Ps(U=>U.getWorktreeMetadata),c=Fd(),x=vs(U=>U.homeDirectory),[m,p]=l.useState([]),[u,S]=l.useState(!1),[f,g]=l.useState(!1),[h,D]=l.useState(null),[k,w]=l.useState([]),[E,N]=l.useState(!1),y=l.useMemo(()=>s?.id&&s?.path?{id:s.id,path:s.path}:!i?.id||!o?null:{id:i.id,path:o},[i?.id,o,s?.id,s?.path]),b=l.useCallback(async()=>{if(!(!y||h===!1))try{const U=await ii(y);w(U)}catch{}},[y,h]);l.useEffect(()=>{if(!o)return;let U=!1;return D(null),(async()=>{try{const B=await Od(o);if(U)return;D(B)}catch{}})(),()=>{U=!0}},[o]),l.useEffect(()=>{if(!y){w([]),N(!1);return}if(h===!1){w([]),N(!1);return}let U=!1;return N(!0),w([]),(async()=>{try{const B=await ii(y);if(U)return;w(B)}catch{}finally{U||N(!1)}})(),()=>{U=!0}},[y,h]),l.useEffect(()=>{if(!y)return;let U=!1;return g(!0),(async()=>{try{const[B,Q]=await Promise.all([vl(y),jl(y)]);U||(p(B.length>0?B:[""]),S(Q))}catch{U||(p([""]),S(!1))}finally{U||g(!1)}})(),()=>{U=!0}},[y]);const P=l.useCallback((U,B)=>{p(Q=>{const W=[...Q];return W[U]=B,W})},[]),z=l.useCallback(()=>{p(U=>[...U,""])},[]),M=l.useCallback(async U=>{if(!y)return;const B=U.filter(Q=>Q.trim().length>0);await Ld(y,B)},[y]),I=l.useCallback(U=>{p(B=>{const Q=B.filter((W,R)=>R!==U);return M(Q),Q.length>0?Q:[""]})},[M]),v=l.useCallback(()=>{M(m)},[M,m]),j=l.useCallback(U=>{S(U),y&&zd(y,U)},[y]),O=l.useCallback(U=>{const B=re=>re.replace(/\\/g,"/").replace(/\/+$/,""),Q=B(U.path),W=c.filter(re=>{const Z=d(re.id);if(Z?.path&&B(Z.path)===Q)return!0;const se=re.directory;return!!(se&&B(se)===Q)}),R=new Set(W.map(re=>re.id)),Y=re=>{const Z=c.filter(ce=>{const oe=ce.parentID;return oe&&re.has(oe)});if(Z.length===0)return[];const se=new Set(Z.map(ce=>ce.id));return[...Z,...Y(se)]},F=Y(R),H=new Set,X=[...W,...F].filter(re=>H.has(re.id)?!1:(H.add(re.id),!0));xl.requestDelete({sessions:X,mode:"worktree",worktree:U})},[c,d]),T=l.useMemo(()=>c.map(U=>U.id).join(","),[c]);return l.useEffect(()=>{h&&o&&b()},[T,h,o,b]),o?h===!1?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")}):t.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.setup.title")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(Et,{sideOffset:8,className:"max-w-xs",children:[e("settings.openchamber.worktrees.setup.tooltipPrefix")," ",t.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?t.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.setup.loading")}):t.jsxs("div",{className:"space-y-2 px-1",children:[m.map((U,B)=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(it,{value:U,onChange:Q=>P(B,Q.target.value),onBlur:v,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 w-[30rem] max-w-full font-mono text-xs"}),t.jsx("button",{type:"button",onClick:()=>{I(B)},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:t.jsx(A,{name:"close",className:"h-4 w-4"})})]},B)),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:z,children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e("settings.openchamber.worktrees.setup.addCommand")]}),t.jsxs("label",{"data-settings-item":"projects.worktree.setup.wait",className:"flex cursor-pointer items-center gap-2 py-1.5",children:[t.jsx(Pt,{checked:u,onChange:j,ariaLabel:e("settings.openchamber.worktrees.setup.waitForCommandsAria")}),t.jsx("span",{className:de("typography-ui-label font-normal",u?"text-foreground":"text-foreground/60"),children:e("settings.openchamber.worktrees.setup.waitForCommands")})]})]})]}),t.jsxs("div",{className:"space-y-2 border-t border-border/40 pt-4",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.list.title")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]})]})}),E?t.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.list.loading")}):k.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.openchamber.worktrees.list.empty")}):t.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:k.map(U=>t.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx("p",{className:"typography-meta text-foreground truncate min-w-0",children:U.label||U.branch||e("settings.openchamber.worktrees.list.detachedHead")}),t.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"})]}),t.jsx("p",{className:"typography-micro text-muted-foreground/60 truncate",children:Kd(U.path,x)})]}),t.jsx("button",{type:"button",onClick:()=>O(U),className:de("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",r?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:U.branch||U.label||U.path}),children:t.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})]},U.path))})]})]}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},No=(s,e)=>e.updatedAtMs-s.updatedAtMs,cs=rn((s,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){s({isLoading:!0,error:null});try{const[n,a]=await Promise.all([Vd(),li()]),r={};for(const i of a.sort(No))r[i.id]=i;e().listenerReady||await _d(i=>{s(o=>({statusesById:{...o.statusesById,[i.id]:i}}))}),s({instances:n.instances,statusesById:r,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){s({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){s({isImportsLoading:!0,error:null});try{const n=await Bd();s({importCandidates:n,isImportsLoading:!1})}catch(n){s({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await li(),a={};for(const r of n.sort(No))a[r.id]=r;s({statusesById:a})}catch(n){s({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{s({isSaving:!0,error:null});try{await Ud({instances:n}),s({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(a){throw s({isSaving:!1,error:a instanceof Error?a.message:String(a)}),a}},upsertInstance:async n=>{const a=e().instances,r=a.some(i=>i.id===n.id)?a.map(i=>i.id===n.id?n:i):[n,...a];await e().setInstances(r)},createFromCommand:async(n,a,r)=>{const i=Hd(n,a);r&&r.trim()&&(i.nickname=r.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await oi(n).catch(()=>{});const a=e().instances.filter(r=>r.id!==n);await e().setInstances(a),s(r=>{const i={...r.statusesById};return delete i[n],{statusesById:i}})},connect:async n=>{s({error:null});try{await $d(n),await e().refreshStatuses()}catch(a){throw s({error:a instanceof Error?a.message:String(a)}),a}},disconnect:async n=>{s({error:null});try{await oi(n),await e().refreshStatuses()}catch(a){throw s({error:a instanceof Error?a.message:String(a)}),a}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>s({error:null})})),$l=[{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"}],Lh=Object.fromEntries($l.map(s=>[s.key,s.Icon])),zh="openchamber:project-actions-updated",Kh=s=>{const e=(s||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},Lv=(s,e)=>`${Kh(s)}::${e}`,$h=s=>{const e=s.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},ko=s=>{if(typeof s!="number"||!Number.isFinite(s))return null;const e=Math.round(s);return e<1||e>65535?null:e},Uh=(s,e)=>{if(!e.enabled||e.type!=="local")return null;const n=ko(e.localPort),a=ko(e.remotePort);if(!n||!a)return null;const r=$h(e.localHost||s.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),o=(s.nickname||s.id||"instance").trim();return{id:`${s.id}::${e.id}`,label:`${o} - ${r}:${n} -> ${i}:${a}`,url:`http://${r}:${n}`}},Ul=s=>{const e=[];for(const n of s)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const a of n.portForwards){const r=Uh(n,a);r&&e.push(r)}return e},zv=(s,e)=>{const n=(s||"").trim();return n&&Ul(e).find(i=>i.id===n)?.url||null},Bh=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,Vh=()=>({id:Bh(),name:"",command:"",icon:"play"}),_h=({projectRef:s})=>{const{t:e}=dt(),n=l.useMemo(()=>fs(),[]),a=cs(b=>b.instances),r=cs(b=>b.load),[i,o]=l.useState([]),[d,c]=l.useState(!1),[x,m]=l.useState(!1),[p,u]=l.useState(null),[S,f]=l.useState({});l.useEffect(()=>{n&&r().catch(()=>{})},[n,r]),l.useEffect(()=>{let b=!1;return c(!0),(async()=>{try{const P=await Wd(s);if(b)return;o(P.actions),u(JSON.stringify({actions:P.actions}))}catch{if(b)return;o([]),u(JSON.stringify({actions:[]}))}finally{b||c(!1)}})(),()=>{b=!0}},[s]);const g=l.useMemo(()=>n?Ul(a):[],[a,n]),h=l.useMemo(()=>i.some(P=>P.name.trim().length===0||P.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),D=l.useMemo(()=>p===null?!1:p!==JSON.stringify({actions:i}),[i,p]),k=l.useCallback(()=>{const b=Vh();o(P=>[...P,b]),f(P=>({...P,[b.id]:!0}))},[]),w=l.useCallback(b=>{o(P=>P.filter(z=>z.id!==b)),f(P=>{const z={...P};return delete z[b],z})},[]),E=l.useCallback((b,P)=>{o(z=>z.map(M=>M.id===b?P(M):M))},[]),N=l.useCallback(async()=>{if(h){V.error(h);return}m(!0);try{if(!await qd(s,{actions:i,primaryActionId:null})){V.error(e("settings.projects.actions.toast.saveFailed"));return}u(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(zh,{detail:{projectId:s.id}})),V.success(e("settings.projects.actions.toast.saved"))}catch{V.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[i,s,e,h]),y=!x&&!d&&D&&!h;return t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:k,children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]})]}),t.jsxs("section",{className:"pb-2 pt-0 space-y-2",children:[d?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):i.length===0?t.jsx("div",{className:"py-2",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")})}):t.jsx("div",{className:"space-y-0 max-w-[30rem]",children:i.map(b=>{const P=b.icon||"play",z=Lh[P]||"play",M=S[b.id]??!1,I=b.name.trim()||e("settings.projects.actions.state.untitled");return t.jsxs(gn,{open:M,onOpenChange:v=>{f(j=>({...j,[b.id]:v}))},className:de("py-1.5"),children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs(hn,{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:[M?t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):t.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),t.jsx(A,{name:z,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:I})})})]}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>w(b.id),children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(fn,{className:"pt-1.5",children:t.jsxs("div",{className:"space-y-2 pb-6 pl-3 pr-3",children:[t.jsxs("div",{className:"flex items-center gap-2 py-1",children:[t.jsxs(us,{children:[t.jsx(ds,{asChild:!0,children:t.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:t.jsx(A,{name:z,className:"h-4 w-4"})})}),t.jsx(ms,{align:"start",className:"w-56 p-2",children:t.jsx("div",{className:"grid grid-cols-6 gap-1",children:$l.map(v=>{const j=v.Icon,O=(b.icon||"play")===v.key;return t.jsx("button",{type:"button",onClick:()=>E(b.id,T=>({...T,icon:v.key})),className:de("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",O&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:v.label}),children:t.jsx(A,{name:j,className:"h-4 w-4"})},v.key)})})})]}),t.jsx(it,{value:b.name,onChange:v=>E(b.id,j=>({...j,name:v.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),t.jsxs("div",{className:"py-1",children:[t.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),t.jsx(ps,{value:b.command,onChange:v=>E(b.id,j=>({...j,command:v.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] font-mono text-xs"})]}),t.jsxs("div",{className:"py-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":b.autoOpenUrl===!0,onClick:()=>E(b.id,v=>({...v,...v.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:v=>{(v.key===" "||v.key==="Enter")&&(v.preventDefault(),E(b.id,j=>({...j,...j.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[t.jsx(Pt,{checked:b.autoOpenUrl===!0,onChange:v=>E(b.id,j=>({...j,...v?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:I})}),t.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),b.autoOpenUrl===!0?t.jsxs("div",{className:"mt-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(it,{value:b.openUrl||"",onChange:v=>E(b.id,j=>({...j,openUrl:v.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]})]}),n?t.jsxs("div",{className:"mt-2",children:[t.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),g.length>0?t.jsxs(Ft,{value:b.desktopOpenSshForward&&g.some(v=>v.id===b.desktopOpenSshForward)?b.desktopOpenSshForward:"__none__",onValueChange:v=>{E(b.id,j=>({...j,...v==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:v}}))},children:[t.jsx(Ot,{className:"h-7 w-full max-w-[30rem]",children:t.jsx(Kt,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),g.map(v=>t.jsx(ht,{value:v.id,children:v.label},v.id))]})]}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},b.id)})}),t.jsxs("div",{className:"pt-3",children:[h?t.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:h}):null,t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:N,disabled:!y,children:e(x?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},Hh=()=>{const s=rt.c(197),{t:e}=dt(),n=as(Wh),a=as(qh),r=as(Gh),i=as(Jh),o=as(Qh),d=Ke(Yh),c=Ke(Xh),{currentTheme:x}=Ua();let m;e:{if(!d){m=null;break e}let ct;s[0]!==n||s[1]!==d?(ct=n.find(St=>St.id===d)??null,s[0]=n,s[1]=d,s[2]=ct):ct=s[2],m=ct}const p=m;let u,S;s[3]!==n||s[4]!==d||s[5]!==c?(u=()=>{if(n.length===0){c(null);return}d&&n.some(ct=>ct.id===d)||c(n[0].id)},S=[n,d,c],s[3]=n,s[4]=d,s[5]=c,s[6]=u,s[7]=S):(u=s[6],S=s[7]),l.useEffect(u,S);const[f,g]=l.useState(""),[h,D]=l.useState(null),[k,w]=l.useState(null),[E,N]=l.useState(null),[y,b]=l.useState(!1),[P,z]=l.useState(!1),[M,I]=l.useState(!1),[v,j]=l.useState(!1),[O,T]=l.useState(null),[U,B]=l.useState(null),[Q,W]=l.useState(!1),R=l.useRef(null);let Y;s[8]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>{T(null),B(Zh)},s[8]=Y):Y=s[8];const F=Y;let H;e:{if(!p){H=null;break e}let ct;s[9]!==p.id||s[10]!==p.path?(ct={id:p.id,path:p.path},s[9]=p.id,s[10]=p.path,s[11]=ct):ct=s[11],H=ct}const X=H;let re,Z;s[12]!==p?(re=()=>{if(!p){g(""),D(null),w(null),N(null);return}g(p.label??""),D(p.icon??null),w(p.color??null),N(p.iconBackground??null),j(!1),F(),W(!1)},Z=[p,F],s[12]=p,s[13]=re,s[14]=Z):(re=s[13],Z=s[14]),l.useEffect(re,Z);let se,ce;s[15]===Symbol.for("react.memo_cache_sentinel")?(se=()=>()=>{F()},ce=[F],s[15]=se,s[16]=ce):(se=s[15],ce=s[16]),l.useEffect(se,ce);let oe;s[17]!==k||s[18]!==h||s[19]!==E||s[20]!==f||s[21]!==v||s[22]!==O||s[23]!==p?(oe=!!p&&(f.trim()!==(p?.label??"").trim()||h!==(p?.icon??null)||k!==(p?.color??null)||E!==(p?.iconBackground??null)||v||!!O),s[17]=k,s[18]=h,s[19]=E,s[20]=f,s[21]=v,s[22]=O,s[23]=p,s[24]=oe):oe=s[24];const xe=oe;let we;s[25]!==k||s[26]!==h||s[27]!==E||s[28]!==f||s[29]!==v||s[30]!==O||s[31]!==i||s[32]!==p||s[33]!==e||s[34]!==a||s[35]!==r?(we=async()=>{if(!p)return;if(O){b(!0);const St=await r(p.id,O);if(b(!1),!St.ok){V.error(St.error||e("settings.projects.page.toast.uploadIconFailed"));return}V.success(e("settings.projects.page.toast.iconUpdated")),F(),j(!1)}const ct=v&&!!p.iconImage;if(ct){z(!0);const St=await i(p.id);if(z(!1),!St.ok){V.error(St.error||e("settings.projects.page.toast.removeIconFailed"));return}V.success(e("settings.projects.page.toast.iconRemoved")),j(!1),N(null)}a(p.id,{label:f.trim(),icon:h,color:k,iconBackground:ct?null:E})},s[25]=k,s[26]=h,s[27]=E,s[28]=f,s[29]=v,s[30]=O,s[31]=i,s[32]=p,s[33]=e,s[34]=a,s[35]=r,s[36]=we):we=s[36];const he=we,Ie=k?bl[k]??null:null,ve=!!p?.iconImage,be=!!(O&&U),ye=p?.iconImage?.source==="custom",te=ve&&!v||be,ie=te,_=!Q&&(be||!!(p&&ve&&!v));let ee;s[37]!==y||s[38]!==p?(ee=ct=>{!p||!ct||y||(j(!1),W(!1),T(ct),B(St=>(St&&URL.revokeObjectURL(St),URL.createObjectURL(ct))))},s[37]=y,s[38]=p,s[39]=ee):ee=s[39];const ne=ee;let ue;s[40]!==be||s[41]!==ie||s[42]!==ve||s[43]!==P||s[44]!==p?(ue=()=>{!p||!ie||P||(be&&F(),j(!!ve),W(!1))},s[40]=be,s[41]=ie,s[42]=ve,s[43]=P,s[44]=p,s[45]=ue):ue=s[45];const Me=ue;let ke;s[46]!==o||s[47]!==M||s[48]!==p||s[49]!==e?(ke=async()=>{!p||M||(F(),j(!1),W(!1),I(!0),o(p.id).then(ct=>{if(!ct.ok){V.error(ct.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(ct.skipped){V.success(e("settings.projects.page.toast.customIconAlreadySet"));return}V.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{I(!1)}))},s[46]=o,s[47]=M,s[48]=p,s[49]=e,s[50]=ke):ke=s[50];const De=ke;if(!p){let ct;s[51]!==e?(ct=e("settings.projects.page.empty.noProjects"),s[51]=e,s[52]=ct):ct=s[52];let St;return s[53]!==ct?(St=t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsx("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:ct})})}),s[53]=ct,s[54]=St):St=s[54],St}let Ae;s[55]!==p.label||s[56]!==e?(Ae=p.label??e("settings.projects.page.title.default"),s[55]=p.label,s[56]=e,s[57]=Ae):Ae=s[57];let Pe;s[58]!==Ae?(Pe=t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:Ae}),s[58]=Ae,s[59]=Pe):Pe=s[59];let Re;s[60]!==p.path?(Re=t.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:p.path,children:p.path}),s[60]=p.path,s[61]=Re):Re=s[61];let Oe;s[62]!==Pe||s[63]!==Re?(Oe=t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[Pe,Re]})}),s[62]=Pe,s[63]=Re,s[64]=Oe):Oe=s[64];let $e;s[65]!==e?($e=e("settings.projects.page.field.projectName"),s[65]=e,s[66]=$e):$e=s[66];let Be;s[67]!==$e?(Be=t.jsx("div",{className:"flex min-w-0 flex-col",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:$e})}),s[67]=$e,s[68]=Be):Be=s[68];let Le;s[69]===Symbol.for("react.memo_cache_sentinel")?(Le=ct=>g(ct.target.value),s[69]=Le):Le=s[69];let Ue;s[70]!==e?(Ue=e("settings.projects.page.field.projectNamePlaceholder"),s[70]=e,s[71]=Ue):Ue=s[71];let le;s[72]!==f||s[73]!==Ue?(le=t.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:t.jsx(it,{value:f,onChange:Le,placeholder:Ue,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),s[72]=f,s[73]=Ue,s[74]=le):le=s[74];let q;s[75]!==Be||s[76]!==le?(q=t.jsxs("div",{"data-settings-item":"projects.name",className:"py-1.5",children:[Be,le]}),s[75]=Be,s[76]=le,s[77]=q):q=s[77];let me;s[78]!==e?(me=e("settings.projects.page.field.accentColor"),s[78]=e,s[79]=me):me=s[79];let Ne;s[80]!==me?(Ne=t.jsx("div",{className:"flex min-w-0 flex-col",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:me})}),s[80]=me,s[81]=Ne):Ne=s[81];let Ee;s[82]===Symbol.for("react.memo_cache_sentinel")?(Ee=()=>w(null),s[82]=Ee):Ee=s[82];const Ce=k===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let He;s[83]!==Ce?(He=de("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Ce),s[83]=Ce,s[84]=He):He=s[84];let G;s[85]!==e?(G=e("settings.projects.page.field.none"),s[85]=e,s[86]=G):G=s[86];let $;s[87]===Symbol.for("react.memo_cache_sentinel")?($=t.jsx(A,{name:"close",className:"h-4 w-4 text-muted-foreground"}),s[87]=$):$=s[87];let fe;s[88]!==He||s[89]!==G?(fe=t.jsx("button",{type:"button",onClick:Ee,className:He,title:G,children:$}),s[88]=He,s[89]=G,s[90]=fe):fe=s[90];let L;s[91]!==k?(L=Gd.map(ct=>t.jsx("button",{type:"button",onClick:()=>w(ct.key),className:de("h-7 w-7 rounded-md border transition-colors",k===ct.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:ct.cssVar},title:ct.label},ct.key)),s[91]=k,s[92]=L):L=s[92];let Fe;s[93]!==fe||s[94]!==L?(Fe=t.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[fe,L]}),s[93]=fe,s[94]=L,s[95]=Fe):Fe=s[95];let Je;s[96]!==Ne||s[97]!==Fe?(Je=t.jsxs("div",{"data-settings-item":"projects.accent-color",className:"py-1.5",children:[Ne,Fe]}),s[96]=Ne,s[97]=Fe,s[98]=Je):Je=s[98];let Xe;s[99]!==e?(Xe=e("settings.projects.page.field.projectIcon"),s[99]=e,s[100]=Xe):Xe=s[100];let et;s[101]!==Xe?(et=t.jsx("div",{className:"flex min-w-0 flex-col",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:Xe})}),s[101]=Xe,s[102]=et):et=s[102];let at;s[103]!==ne?(at=t.jsx("input",{ref:R,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:ct=>{const St=ct.target.files?.[0]??null;ne(St),ct.currentTarget.value=""}}),s[103]=ne,s[104]=at):at=s[104];let lt;s[105]===Symbol.for("react.memo_cache_sentinel")?(lt=()=>D(null),s[105]=lt):lt=s[105];const Ze=h===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let We;s[106]!==Ze?(We=de("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Ze),s[106]=Ze,s[107]=We):We=s[107];let pt;s[108]!==e?(pt=e("settings.projects.page.field.none"),s[108]=e,s[109]=pt):pt=s[109];let pe;s[110]===Symbol.for("react.memo_cache_sentinel")?(pe=t.jsx(A,{name:"close",className:"h-4 w-4 text-muted-foreground"}),s[110]=pe):pe=s[110];let st;s[111]!==We||s[112]!==pt?(st=t.jsx("button",{type:"button",onClick:lt,className:We,title:pt,children:pe}),s[111]=We,s[112]=pt,s[113]=st):st=s[113];let nt;s[114]!==Ie||s[115]!==h?(nt=Jd.map(ct=>{const St=ct.Icon;return t.jsx("button",{type:"button",onClick:()=>D(ct.key),className:de("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",h===ct.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:ct.label,children:t.jsx(A,{name:St,className:"w-4 h-4",style:Ie&&h===ct.key?{color:Ie}:void 0})},ct.key)}),s[114]=Ie,s[115]=h,s[116]=nt):nt=s[116];let Ge;s[117]!==st||s[118]!==nt?(Ge=t.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[st,nt]}),s[117]=st,s[118]=nt,s[119]=Ge):Ge=s[119];let ft;s[120]!==x||s[121]!==te||s[122]!==be||s[123]!==E||s[124]!==U||s[125]!==p||s[126]!==_||s[127]!==e?(ft=te&&_&&t.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.projects.page.field.preview")}),t.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:t.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:E?{backgroundColor:E}:void 0,children:be&&U?t.jsx("img",{src:U,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>W(!0)}):p?t.jsx(yl,{project:p,options:{themeVariant:x.metadata.variant,iconColor:x.colors.surface.foreground},className:"h-full w-full object-contain",onError:()=>W(!0)}):null})})]}),s[120]=x,s[121]=te,s[122]=be,s[123]=E,s[124]=U,s[125]=p,s[126]=_,s[127]=e,s[128]=ft):ft=s[128];let wt;s[129]!==te||s[130]!==E||s[131]!==e?(wt=te&&t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[t.jsx("input",{type:"color",value:E??"#000000",onChange:ct=>N(ct.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")}),t.jsx(it,{value:E??"",onChange:ct=>N(ct.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),t.jsx(J,{type:"button",size:"xs",variant:"outline",onClick:()=>N(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!E,children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),s[129]=te,s[130]=E,s[131]=e,s[132]=wt):wt=s[132];let Ct;s[133]!==De||s[134]!==ye||s[135]!==M||s[136]!==y||s[137]!==e?(Ct=!ye&&t.jsxs(t.Fragment,{children:[t.jsx(J,{size:"xs",className:"h-6 !font-normal",onClick:()=>R.current?.click(),disabled:y,children:e(y?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),t.jsx(J,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{De()},disabled:M,children:e(M?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),s[133]=De,s[134]=ye,s[135]=M,s[136]=y,s[137]=e,s[138]=Ct):Ct=s[138];let ae;s[139]!==Me||s[140]!==ie||s[141]!==P||s[142]!==e?(ae=ie&&t.jsx(J,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Me()},disabled:P,children:e(P?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),s[139]=Me,s[140]=ie,s[141]=P,s[142]=e,s[143]=ae):ae=s[143];let Ve;s[144]!==P||s[145]!==v||s[146]!==e?(Ve=v&&t.jsx(J,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>j(!1),disabled:P,children:e("settings.projects.page.actions.undoRemove")}),s[144]=P,s[145]=v,s[146]=e,s[147]=Ve):Ve=s[147];let tt;s[148]!==Ct||s[149]!==ae||s[150]!==Ve?(tt=t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Ct,ae,Ve]}),s[148]=Ct,s[149]=ae,s[150]=Ve,s[151]=tt):tt=s[151];let Ye;s[152]!==et||s[153]!==at||s[154]!==Ge||s[155]!==ft||s[156]!==wt||s[157]!==tt?(Ye=t.jsxs("div",{"data-settings-item":"projects.icon",className:"py-1.5",children:[et,at,Ge,ft,wt,tt]}),s[152]=et,s[153]=at,s[154]=Ge,s[155]=ft,s[156]=wt,s[157]=tt,s[158]=Ye):Ye=s[158];let bt;s[159]!==q||s[160]!==Je||s[161]!==Ye?(bt=t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[q,Je,Ye]}),s[159]=q,s[160]=Je,s[161]=Ye,s[162]=bt):bt=s[162];let ze;s[163]!==xe||s[164]!==P||s[165]!==y||s[166]!==f?(ze=!xe||f.trim().length===0||y||P,s[163]=xe,s[164]=P,s[165]=y,s[166]=f,s[167]=ze):ze=s[167];let _e;s[168]!==e?(_e=e("settings.common.actions.saveChanges"),s[168]=e,s[169]=_e):_e=s[169];let ot;s[170]!==he||s[171]!==ze||s[172]!==_e?(ot=t.jsx("div",{className:"mt-0.5 px-2 py-1",children:t.jsx(J,{onClick:he,disabled:ze,size:"xs",className:"!font-normal",children:_e})}),s[170]=he,s[171]=ze,s[172]=_e,s[173]=ot):ot=s[173];let yt;s[174]!==bt||s[175]!==ot?(yt=t.jsxs("div",{className:"mb-8",children:[bt,ot]}),s[174]=bt,s[175]=ot,s[176]=yt):yt=s[176];let Mt;s[177]!==X?(Mt=X&&t.jsx(_h,{projectRef:X}),s[177]=X,s[178]=Mt):Mt=s[178];let Qt;s[179]!==Mt?(Qt=t.jsx("div",{"data-settings-item":"projects.worktree",className:"mb-8",children:t.jsx("section",{className:"px-2 pb-2 pt-0",children:Mt})}),s[179]=Mt,s[180]=Qt):Qt=s[180];let Xt;s[181]!==e?(Xt=e("settings.projects.page.section.worktree"),s[181]=e,s[182]=Xt):Xt=s[182];let rs;s[183]!==Xt?(rs=t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:Xt})}),s[183]=Xt,s[184]=rs):rs=s[184];let Wt;s[185]!==X?(Wt=X&&t.jsx(Oh,{projectRef:X}),s[185]=X,s[186]=Wt):Wt=s[186];let Se;s[187]!==Wt?(Se=t.jsx("section",{className:"px-2 pb-2 pt-0",children:Wt}),s[187]=Wt,s[188]=Se):Se=s[188];let vt;s[189]!==rs||s[190]!==Se?(vt=t.jsxs("div",{className:"mb-8",children:[rs,Se]}),s[189]=rs,s[190]=Se,s[191]=vt):vt=s[191];let Nt;return s[192]!==Oe||s[193]!==yt||s[194]!==Qt||s[195]!==vt?(Nt=t.jsx(Jt,{outerClassName:"h-full",className:"w-full bg-background",children:t.jsxs("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:[Oe,yt,Qt,vt]})}),s[192]=Oe,s[193]=yt,s[194]=Qt,s[195]=vt,s[196]=Nt):Nt=s[196],Nt};function Wh(s){return s.projects}function qh(s){return s.updateProjectMeta}function Gh(s){return s.uploadProjectIcon}function Jh(s){return s.removeProjectIcon}function Qh(s){return s.discoverProjectIcon}function Yh(s){return s.settingsProjectsSelectedId}function Xh(s){return s.setSettingsProjectsSelectedId}function Zh(s){return s&&URL.revokeObjectURL(s),null}const Bl=s=>({v:1,serverUrl:s.serverUrl.trim().replace(/\/+$/,""),token:s.token.trim(),...s.label?.trim()?{label:s.label.trim()}:{}}),ef=s=>{const e=new URLSearchParams;return e.set("v",String(s.v)),e.set("server",s.serverUrl),e.set("token",s.token),s.label&&e.set("label",s.label),`openchamber://connect?${e.toString()}`},tf=s=>{const e=s.trim();if(!e)return null;try{const n=new URL(e);if(n.protocol!=="openchamber:"||n.hostname!=="connect")return null;const a=n.searchParams.get("v"),r=n.searchParams.get("server")?.trim()||"",i=n.searchParams.get("token")?.trim()||"",o=n.searchParams.get("label")?.trim()||"";if(a!=="1"||!r||!i)return null;try{const d=new URL(r);if(d.protocol!=="http:"&&d.protocol!=="https:")return null}catch{return null}return Bl({serverUrl:r,token:i,label:o})}catch{return null}},Tr=()=>Math.floor(2e4+Math.random()*3e4),sf=s=>{const e=(s instanceof Error?s.message:String(s)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},So=s=>{switch(s){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"}},nf=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Vl=s=>!!(s&&nf.has(s)),Co=s=>s==="ready"?"bg-[var(--status-success)] animate-pulse":s==="error"?"bg-[var(--status-error)] animate-pulse":s==="degraded"||Vl(s)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",af=s=>s.type==="dynamic"?`${s.localHost||"127.0.0.1"}:${s.localPort||0}`:s.type==="remote"?`${s.remoteHost||"127.0.0.1"}:${s.remotePort||0} -> ${s.localHost||"127.0.0.1"}:${s.localPort||0}`:`${s.localHost||"127.0.0.1"}:${s.localPort||0} -> ${s.remoteHost||"127.0.0.1"}:${s.remotePort||0}`,rf=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Tr(),remoteHost:"127.0.0.1",remotePort:80}),of=s=>s.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Ks=s=>{const e=rt.c(8),{label:n,hint:a}=s;let r;e[0]!==n?(r=t.jsx("span",{children:n}),e[0]=n,e[1]=r):r=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(At,{asChild:!0,children:t.jsx(A,{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]!==a?(o=t.jsxs(Dt,{children:[i,t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:t.jsx("div",{className:"typography-meta text-foreground",children:a})})]}),e[3]=a,e[4]=o):o=e[4];let d;return e[5]!==r||e[6]!==o?(d=t.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[r,o]}),e[5]=r,e[6]=o,e[7]=d):d=e[7],d},lf=s=>{switch(s){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},Po=(s,e)=>{const n=(s||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},cf=s=>{const e=(s||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},df=s=>{const e=s.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return s;const n=Number(e[1]),a=Number.isFinite(n)?new Date(n).toISOString():e[1],r=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${a}] [${r}] ${i}`},lr=s=>{const e=s.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},mf=s=>{const e=s.sshCommand.trim(),n=s.nickname?.trim(),a=s.portForwards.map(r=>({...r,localHost:r.localHost?.trim()||"127.0.0.1",localPort:typeof r.localPort=="number"?Math.max(1,Math.min(65535,Math.round(r.localPort))):void 0,remoteHost:r.remoteHost?.trim(),remotePort:typeof r.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(r.remotePort))):void 0}));return{...s,sshCommand:e,...n?{nickname:n}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(s.connectionTimeoutSec||60))),localForward:{...s.localForward,bindHost:s.localForward.bindHost==="localhost"||s.localForward.bindHost==="0.0.0.0"?s.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof s.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(s.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...s.remoteOpenchamber,preferredPort:typeof s.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(s.remoteOpenchamber.preferredPort))):void 0},portForwards:a}},uf=()=>{const{t:s}=dt(),{clientAuth:e}=Hr(),n=fs(),a=cs(K=>K.instances),r=cs(K=>K.statusesById),i=cs(K=>K.importCandidates),o=cs(K=>K.isLoading),d=cs(K=>K.isImportsLoading),c=cs(K=>K.isSaving),x=cs(K=>K.error),m=cs(K=>K.load),p=cs(K=>K.loadImports),u=cs(K=>K.refreshStatuses),S=cs(K=>K.upsertInstance),f=cs(K=>K.createFromCommand),g=cs(K=>K.removeInstance),h=cs(K=>K.connect),D=cs(K=>K.disconnect),k=cs(K=>K.retry),w=Ke(K=>K.settingsRemoteInstancesSelectedId),E=Ke(K=>K.setSettingsRemoteInstancesSelectedId),N=l.useMemo(()=>w&&a.find(K=>K.id===w)||null,[a,w]),[y,b]=l.useState(null),[P,z]=l.useState(!1),[M,I]=l.useState(!1),[v,j]=l.useState(null),[O,T]=l.useState([]),[U,B]=l.useState(null),[Q,W]=l.useState(""),[R,Y]=l.useState(!1),[F,H]=l.useState({}),[X,re]=l.useState(!1),[Z,se]=l.useState(!1),[ce,oe]=l.useState(()=>Date.now()),[xe,we]=l.useState([]),[he,Ie]=l.useState("local"),[ve,be]=l.useState(!1),[ye,te]=l.useState(!1),[ie,ge]=l.useState(""),[_,ee]=l.useState(""),[ne,ue]=l.useState(""),[Me,ke]=l.useState(""),[De,Ae]=l.useState(null),[Pe,Re]=l.useState(!1),[Oe,$e]=l.useState(!1),[Be,Le]=l.useState(null),[Ue,le]=l.useState(""),[q,me]=l.useState(""),[Ne,Ee]=l.useState(""),[Ce,He]=l.useState([]),[G,$]=l.useState(!1),[fe,L]=l.useState(""),[Fe,Je]=l.useState(null),[Xe,et]=l.useState(null),[at,lt]=l.useState(null),[Ze,We]=l.useState(null),pt=l.useMemo(()=>Ce.filter(K=>!!K.revokedAt).length,[Ce]),[pe,st]=l.useState(!1),[nt,Ge]=l.useState("ssh user@example.com"),[ft,wt]=l.useState("");l.useEffect(()=>{m(),p()},[m,p]);const Ct=l.useCallback(async()=>{be(!0),Ae(null);try{const K=await ci();we(K.hosts||[]),Ie(K.defaultHostId||"local")}catch(K){Ae(K instanceof Error?K.message:String(K))}finally{be(!1)}},[]);l.useEffect(()=>{Ct()},[Ct]);const ae=l.useCallback(async(K,qe=he)=>{te(!0),Ae(null);try{await di({hosts:K,defaultHostId:qe,initialHostChoiceCompleted:!0}),we(K),Ie(qe)}catch(kt){Ae(kt instanceof Error?kt.message:String(kt))}finally{te(!1)}},[he]),Ve=l.useCallback(async()=>{const K=mi(_);if(!K){Ae(s("desktopHostSwitcher.error.invalidUrl"));return}const qe=K.persistedUrl,Tt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:ie.trim()||zn(qe),url:qe,apiUrl:qe,...ne.trim()?{clientToken:ne.trim()}:{}};await ae([Tt,...xe],he),ge(""),ee(""),ue(""),Re(!1),K.redeemUrl&&lr(K.redeemUrl)},[he,xe,ie,ne,_,ae,s]),tt=l.useCallback(async()=>{const K=tf(Me);if(!K){Ae(s("settings.remoteInstances.direct.error.invalidConnectLink"));return}const qe=Wa(K.serverUrl);if(!qe){Ae(s("desktopHostSwitcher.error.invalidUrl"));return}const kt=xe.find(Tt=>Wa(Tt.apiUrl||Tt.url)===qe);if(kt){const Tt=xe.map(ts=>ts.id===kt.id?{...ts,label:K.label||ts.label,url:qe,apiUrl:qe,clientToken:K.token}:ts);await ae(Tt,he)}else{const Tt=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`;await ae([{id:Tt,label:K.label||zn(qe),url:qe,apiUrl:qe,clientToken:K.token},...xe],he)}ke(""),Ae(null),$e(!1)},[Me,he,xe,ae,s]),Ye=l.useCallback(async K=>{const qe=xe.filter(Tt=>Tt.id!==K);await ae(qe,he===K?"local":he),Be===K&&Le(null)},[he,Be,xe,ae]),bt=l.useCallback(K=>{Le(K.id),le(K.label),me(K.apiUrl||K.url),Ee(K.clientToken||""),Ae(null)},[]),ze=l.useCallback(async()=>{if(!Be)return;const K=mi(q);if(!K){Ae(s("desktopHostSwitcher.error.invalidUrl"));return}const qe=K.persistedUrl,kt=xe.map(Tt=>Tt.id===Be?{...Tt,label:Ue.trim()||zn(qe),url:qe,apiUrl:qe,clientToken:Ne.trim()||void 0}:Tt);await ae(kt,he),Le(null),K.redeemUrl&&lr(K.redeemUrl)},[he,Ue,Ne,q,Be,xe,ae,s]),_e=l.useCallback(async()=>{const K=nt.trim();if(!K){V.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}const qe=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await f(qe,K,ft.trim()||s("settings.remoteInstances.sidebar.newSshInstanceName")),E(qe),st(!1),Ge("ssh user@example.com"),wt(""),V.success(s("settings.remoteInstances.page.toast.instanceCreated"))}catch(kt){V.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:kt instanceof Error?kt.message:String(kt)})}},[f,E,nt,ft,s]),ot=l.useCallback(async K=>{await ae(xe,K)},[xe,ae]),yt=l.useCallback(async()=>{if(e){$(!0),et(null);try{He(await e.listClients())}catch(K){et(K instanceof Error?K.message:String(K))}finally{$(!1)}}},[e]);l.useEffect(()=>{yt()},[yt]);const Mt=l.useCallback(async()=>{if(e){et(null);try{const K=await e.createClient({label:fe.trim()||void 0});Je(K.token),L(""),await yt()}catch(K){et(K instanceof Error?K.message:String(K))}}},[e,yt,fe]),Qt=l.useCallback(async()=>{if(e){et(null);try{const K=Wa(Xn())||window.location.origin,qe=await e.createClient({label:fe.trim()||"Paired client"}),kt=Bl({serverUrl:K,token:qe.token,label:fe||"OpenChamber"}),Tt=ef(kt);Je(qe.token),lt(Tt),We(await pl.toDataURL(Tt,{width:192,margin:1})),L(""),await yt()}catch(K){et(K instanceof Error?K.message:String(K))}}},[e,yt,fe]),Xt=l.useCallback(async K=>{if(!e)return;const qe=K.clientKind==="desktop-local";et(null);try{if(await e.revokeClient(K.id),qe&&fs()){const kt=await ci();await di({hosts:kt.hosts,defaultHostId:kt.defaultHostId,initialHostChoiceCompleted:kt.initialHostChoiceCompleted,localClientToken:null}),He(Tt=>Tt.map(ts=>ts.id===K.id?{...ts,revokedAt:new Date().toISOString()}:ts)),$m({apiBaseUrl:Xn(),clientToken:null,runtimeKey:"local"});return}await yt()}catch(kt){et(kt instanceof Error?kt.message:String(kt))}},[e,yt]),rs=l.useCallback(async()=>{if(e){et(null);try{await e.purgeRevokedClients(),await yt()}catch(K){et(K instanceof Error?K.message:String(K))}}},[e,yt]);l.useEffect(()=>{b(N)},[N]),l.useEffect(()=>{if(!w)return;const K=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||u()},2e3);return()=>{window.clearInterval(K)}},[u,w]),l.useEffect(()=>{let K=null,qe=Date.now();const kt=()=>{const ts=Date.now();ts-qe>=1e3&&(oe(ts),qe=ts),K=requestAnimationFrame(kt)};(typeof document>"u"||document.visibilityState==="visible")&&(K=requestAnimationFrame(kt));const Tt=()=>{document.visibilityState==="visible"&&K===null?K=requestAnimationFrame(kt):document.visibilityState!=="visible"&&K!==null&&(cancelAnimationFrame(K),K=null)};return document.addEventListener("visibilitychange",Tt),()=>{document.removeEventListener("visibilitychange",Tt),K!==null&&cancelAnimationFrame(K)}},[]);const Wt=w?r[w]:null,Se=Wt?.phase,vt=Se==="ready",Nt=Se==="degraded",ct=Vl(Se),$t=vt||(ct||Nt),bs=Wt?Math.max(0,ce-Wt.updatedAtMs):0,ns=Nt&&bs>12e3,ys=l.useMemo(()=>!y||!N?!1:JSON.stringify(y)!==JSON.stringify(N),[y,N]),Qe=l.useCallback(K=>{b(qe=>qe&&K(qe))},[]),mt=l.useCallback(async()=>{if(!y)return;const K=mf(y);if(!K.sshCommand.trim()){V.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(K.localForward.bindHost==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(K.auth.sshPassword?.enabled&&K.auth.sshPassword.value?.trim()&&K.auth.sshPassword.store!=="settings"){const qe=window.confirm(s("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));K.auth.sshPassword.store=qe?"settings":"never",qe||(K.auth.sshPassword.value=void 0)}if(K.auth.openchamberPassword?.enabled&&K.auth.openchamberPassword.value?.trim()&&K.auth.openchamberPassword.store!=="settings"){const qe=window.confirm(s("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));K.auth.openchamberPassword.store=qe?"settings":"never",qe||(K.auth.openchamberPassword.value=void 0)}try{await S(K),V.success(s("settings.remoteInstances.page.toast.instanceSaved"))}catch(qe){V.error(s("settings.remoteInstances.page.toast.saveFailed"),{description:qe instanceof Error?qe.message:String(qe)})}}},[y,s,S]),xt=l.useCallback(async(K,qe)=>{const kt=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await f(kt,`ssh ${qe}`,K),E(kt),V.success(s("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Tt){return V.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:Tt instanceof Error?Tt.message:String(Tt)}),!1}},[f,E,s]),Rt=l.useCallback(()=>{R||(B(null),W(""))},[R]),es=l.useCallback((K,qe)=>{if(qe){B(K),W(of(K));return}xt(K,K)},[xt]),Zt=l.useCallback(async()=>{const K=U,qe=Q.trim();if(K){if(!qe){V.error(s("settings.remoteInstances.page.toast.destinationRequired"));return}Y(!0);try{await xt(K,qe)&&(B(null),W(""))}finally{Y(!1)}}},[xt,Q,U,s]),qs=l.useCallback(async()=>{if(N)try{await h(N.id);return}catch(K){if(!sf(K)||!window.confirm(s("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw K;const kt={...N,localForward:{...N.localForward,preferredLocalPort:Tr()}};await S(kt),await h(kt.id),V.success(s("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[h,N,s,S]),Os=l.useCallback(async K=>(await Qd(K,600)).map(kt=>df(kt)),[]),Tn=l.useCallback(async()=>{if(y){z(!0),I(!0),j(null);try{const K=await Os(y.id);T(K)}catch(K){T([]),j(K instanceof Error?K.message:String(K))}finally{I(!1)}}},[y,Os]);l.useEffect(()=>{if(!P||!y)return;let K=!1;const qe=async()=>{try{const Tt=await Os(y.id);K||(T(Tt),j(null))}catch(Tt){K||j(Tt instanceof Error?Tt.message:String(Tt))}};qe();const kt=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||qe()},1e3);return()=>{K=!0,window.clearInterval(kt)}},[y,P,Os]);const As=l.useMemo(()=>O.join(`
28
- `),[O]),Gs=l.useCallback(()=>{if(!As.trim()){V.error(s("settings.remoteInstances.page.toast.noLogsToCopy"));return}un(As).then(K=>{K.ok&&V.success(s("settings.remoteInstances.page.toast.logsCopied"))})},[As,s]),Js=l.useCallback(async()=>{if(y)try{await Yd(y.id),T([]),V.success(s("settings.remoteInstances.page.toast.logsCleared"))}catch(K){V.error(s("settings.remoteInstances.page.toast.clearLogsFailed"),{description:K instanceof Error?K.message:String(K)})}},[y,s]),Fn=l.useCallback(async()=>{if(!Wt?.localUrl){V.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const K=Wt.localUrl.trim();if(!K){V.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}lr(K)},[Wt?.localUrl,s]),Va=l.useCallback(()=>{if(!y)return;re(!0),($t?D(y.id):qs()).catch(qe=>{const kt=$t?vt?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";V.error(s(kt),{description:qe instanceof Error?qe.message:String(qe)})}).finally(()=>{re(!1)})},[$t,qs,D,y,vt,s]),On=l.useCallback(()=>{if(!y||ct)return;se(!0),(Nt?D(y.id).then(()=>qs()):k(y.id)).catch(qe=>{V.error(s("settings.remoteInstances.page.toast.retryFailed"),{description:qe instanceof Error?qe.message:String(qe)})}).finally(()=>{se(!1)})},[qs,D,y,ct,Nt,k,s]),Ls=s(ct?"settings.remoteInstances.page.actions.connecting":Nt?ns?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),yn=!X&&!Z&&(Se==="error"||Se==="idle"||!Se||Nt&&ns)&&!ct,Qs=s(vt?"settings.remoteInstances.sidebar.actions.disconnect":$t?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!y)return t.jsxs(Rr,{children:[e?t.jsxs("div",{"data-settings-item":"remote-instances.client-auth",className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.clientAuth.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.description")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[t.jsx(it,{className:"h-8",value:fe,onChange:K=>L(K.target.value),placeholder:s("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Mt()},children:s("settings.remoteInstances.clientAuth.actions.create")}),t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Qt()},children:s("settings.remoteInstances.clientAuth.actions.pair")})]}),at?t.jsxs("div",{className:"flex flex-col gap-3 rounded-md border border-[var(--interactive-border)] p-2 sm:flex-row",children:[Ze?t.jsx("img",{src:Ze,alt:s("settings.remoteInstances.clientAuth.qrAlt"),className:"size-48 self-start"}):null,t.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.pairingUrl")}),t.jsx("code",{className:"block select-all break-all typography-code text-foreground",children:at}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{un(at)},children:[t.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),s("settings.common.actions.copyAll")]})]})]}):null,Fe?t.jsxs("div",{className:"space-y-1 rounded-md border border-[var(--interactive-border)] p-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.createdToken")}),t.jsx("code",{className:"block select-all break-all typography-code text-foreground",children:Fe})]}):null,t.jsxs("div",{className:"space-y-1",children:[pt>0?t.jsx("div",{className:"flex justify-end",children:t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{rs()},children:s("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,G?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.state.loading")}):Ce.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.state.empty")}):Ce.map(K=>{const qe=K.clientKind==="desktop-local";return t.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:K.label}),qe?t.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:s("settings.remoteInstances.clientAuth.state.thisDevice")}):null]}),t.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:K.revokedAt?s("settings.remoteInstances.clientAuth.state.revoked"):K.lastUsedAt?s("settings.remoteInstances.clientAuth.lastUsed",{date:K.lastUsedAt}):s("settings.remoteInstances.clientAuth.neverUsed")})]}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Xt(K)},disabled:!!K.revokedAt,children:s("settings.remoteInstances.clientAuth.actions.revoke")})]},K.id)})]}),Xe?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Xe}):null]})]}):null,n?t.jsxs("div",{"data-settings-item":"remote-instances.direct-hosts",className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.direct.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.description")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.remoteInstances.direct.note")}),t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$e(!0),disabled:ye,children:s("settings.remoteInstances.direct.import.action")}),t.jsxs(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Re(!0),disabled:ye,children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.actions.add")]})]})]}),t.jsx("div",{className:"space-y-1",children:ve?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.state.loading")}):xe.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.state.empty")}):xe.map(K=>t.jsx("div",{className:"py-1.5",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:zn(K.label)}),he===K.id?t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("desktopHostSwitcher.header.default")}):null]}),t.jsx("p",{className:"typography-micro text-muted-foreground font-mono truncate",children:zn(K.apiUrl||K.url)})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ot(K.id)},disabled:ye||he===K.id,"aria-label":s("desktopHostSwitcher.actions.setAsDefaultAria"),children:he===K.id?t.jsx(A,{name:"star-fill",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"star",className:"h-3.5 w-3.5"})}),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>bt(K),disabled:ye,children:[t.jsx(A,{name:"pencil",className:"h-3.5 w-3.5"}),s("desktopHostSwitcher.actions.edit")]}),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ye(K.id)},disabled:ye,children:[t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]})},K.id))}),De?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:De}):null]})]}):null,n?t.jsx(Ut,{open:Pe,onOpenChange:Re,children:t.jsxs(Bt,{className:"sm:max-w-lg",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("settings.remoteInstances.direct.actions.add")}),t.jsx(qt,{children:s("settings.remoteInstances.direct.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),Ve()},children:[t.jsx(it,{className:"h-8",value:ie,onChange:K=>ge(K.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ye}),t.jsx(it,{className:"h-8",value:_,onChange:K=>ee(K.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ye,autoFocus:!0}),t.jsx(it,{className:"h-8",value:ne,onChange:K=>ue(K.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ye}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Re(!1),disabled:ye,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:ye||!_.trim(),children:s("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?t.jsx(Ut,{open:!!Be,onOpenChange:K=>{K||Le(null)},children:t.jsxs(Bt,{className:"sm:max-w-lg",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("desktopHostSwitcher.actions.edit")}),t.jsx(qt,{children:s("settings.remoteInstances.direct.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),ze()},children:[t.jsx(it,{className:"h-8",value:Ue,onChange:K=>le(K.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ye}),t.jsx(it,{className:"h-8",value:q,onChange:K=>me(K.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ye,autoFocus:!0}),t.jsx(it,{className:"h-8",value:Ne,onChange:K=>Ee(K.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ye}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Le(null),disabled:ye,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:ye,children:s("settings.common.actions.saveChanges")})]})]})]})}):null,n?t.jsx(Ut,{open:Oe,onOpenChange:$e,children:t.jsxs(Bt,{className:"sm:max-w-lg",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("settings.remoteInstances.direct.import.action")}),t.jsx(qt,{children:s("settings.remoteInstances.direct.import.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),tt()},children:[t.jsx(it,{className:"h-8",value:Me,onChange:K=>ke(K.target.value),placeholder:s("settings.remoteInstances.direct.import.placeholder"),disabled:ye,autoFocus:!0}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$e(!1),disabled:ye,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:ye||!Me.trim(),children:s("settings.remoteInstances.direct.import.action")})]})]})]})}):null,n?t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.sidebar.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.sidebar.total",{count:a.length})})]}),t.jsxs(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>st(!0),children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.sidebar.actions.addSshInstance")]})]})}),t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-1",children:o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.loading")}):a.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.noneFound")}):a.map(K=>{const qe=r[K.id],kt=K.nickname?.trim()||K.sshParsed?.destination||K.id,Tt=qe?.phase,ts=Tt==="ready";return t.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:`h-2 w-2 rounded-full ${Co(Tt)}`}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:kt})]}),t.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[s(So(Tt)),qe?.localUrl?` · ${qe.localUrl}`:""]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(ts?D(K.id):h(K.id)).catch(gt=>V.error(s(ts?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:gt instanceof Error?gt.message:String(gt)}))},children:[ts?t.jsx(A,{name:"stop",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"plug-2",className:"h-3.5 w-3.5"}),s(ts?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>E(K.id),children:[t.jsx(A,{name:"pencil",className:"h-3.5 w-3.5"}),s("desktopHostSwitcher.actions.edit")]}),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(s("settings.remoteInstances.page.confirm.removeInstance"))&&g(K.id).catch(gt=>V.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:gt instanceof Error?gt.message:String(gt)}))},children:[t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]},K.id)})})]}):null,n?t.jsx(Ut,{open:pe,onOpenChange:st,children:t.jsxs(Bt,{className:"sm:max-w-lg",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("settings.remoteInstances.sidebar.actions.addSshInstance")}),t.jsx(qt,{children:s("settings.remoteInstances.page.section.instanceDescription")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),_e()},children:[t.jsx(it,{className:"h-8",value:ft,onChange:K=>wt(K.target.value),placeholder:s("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:c}),t.jsx(it,{className:"h-8",value:nt,onChange:K=>Ge(K.target.value),placeholder:s("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:c,autoFocus:!0}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>st(!1),disabled:c,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:c||!nt.trim(),children:s("settings.common.actions.create")})]})]})]})}):null,n?t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.import.sectionTitle")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:d?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.loading")}):i.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.noneFound")}):t.jsx("div",{children:i.map(K=>t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] py-3 last:border-b-0",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"typography-ui-label font-medium text-foreground truncate",children:[K.host,K.pattern?` ${s("settings.remoteInstances.page.import.patternSuffix")}`:""]}),t.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:K.sshCommand})]}),t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{es(K.host,K.pattern)},children:s("settings.common.actions.import")})]},`${K.source}:${K.host}`))})})]}):null,t.jsx(Ut,{open:!!U,onOpenChange:K=>{K||Rt()},children:t.jsxs(Bt,{className:"sm:max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx(qt,{children:U?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:U}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),Zt()},children:[t.jsx(it,{value:Q,onChange:K=>W(K.target.value),placeholder:s("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Rt,disabled:R,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:R,children:s("settings.remoteInstances.page.actions.create")})]})]})]})})]});const sa=y.remoteOpenchamber.mode==="managed",_a=y.nickname?.trim()||y.sshParsed?.destination||y.id;return t.jsx(Ut,{open:!!y,onOpenChange:K=>{K||E(null)},children:t.jsxs(Bt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[t.jsxs("div",{className:"mb-6 px-1",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:_a}),t.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${Co(Se)}`}),t.jsx("span",{children:s(So(Se))}),Wt?.localUrl?t.jsx("span",{className:"font-mono text-foreground/80",children:Wt.localUrl}):null,ns?t.jsx("span",{children:s("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.actions")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.actionsDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(J,{type:"button",variant:$t?"outline":"default",size:"xs",className:"!font-normal",onClick:Va,disabled:X||Z,children:[$t?t.jsx(A,{name:"stop",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"plug-2",className:"h-3.5 w-3.5"}),Qs]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:On,disabled:!yn,children:[t.jsx(A,{name:"refresh",className:`h-3.5 w-3.5 ${ct||Nt&&!ns?"animate-spin":""}`}),Ls]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Tn()},children:[t.jsx(A,{name:"terminal-window",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.logs")]}),t.jsxs(J,{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(s("settings.remoteInstances.page.confirm.removeInstance"))&&g(y.id).then(()=>{E(null),V.success(s("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(qe=>{V.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:qe instanceof Error?qe.message:String(qe)})})},children:[t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.sidebar.actions.remove")]})]}),Wt?.localUrl?t.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx("span",{children:s("settings.remoteInstances.page.status.currentLocalUrl")}),t.jsx("span",{className:"font-mono text-foreground/90",children:Wt.localUrl})]}):null]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.instance")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.instanceDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.sshCommand")}),t.jsx(it,{className:"h-7 md:max-w-xl",value:y.sshCommand,onChange:K=>Qe(qe=>({...qe,sshCommand:K.target.value})),placeholder:s("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.nickname")}),t.jsx(it,{className:"h-7 md:max-w-sm",value:y.nickname||"",onChange:K=>Qe(qe=>({...qe,nickname:K.target.value})),placeholder:s("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),t.jsx(xs,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:y.connectionTimeoutSec,onValueChange:K=>{Qe(qe=>({...qe,connectionTimeoutSec:Number.isFinite(K)?K:qe.connectionTimeoutSec}))}})]})]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.remoteServer")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.remoteServerDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Ks,{label:s("settings.remoteInstances.page.field.mode"),hint:s("settings.remoteInstances.page.field.modeHint")})}),t.jsxs(Ft,{value:y.remoteOpenchamber.mode,onValueChange:K=>Qe(qe=>({...qe,remoteOpenchamber:{...qe.remoteOpenchamber,mode:K==="external"?"external":"managed"}})),children:[t.jsx(Ot,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Kt,{placeholder:s("settings.remoteInstances.page.field.modePlaceholder")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"managed",children:s("settings.remoteInstances.page.field.modeManaged")}),t.jsx(ht,{value:"external",children:s("settings.remoteInstances.page.field.modeExternal")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Ks,{label:s("settings.remoteInstances.page.field.preferredRemotePort"),hint:s("settings.remoteInstances.page.field.preferredRemotePortHint")})}),t.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.remoteOpenchamber.preferredPort,onValueChange:K=>{Qe(qe=>({...qe,remoteOpenchamber:{...qe.remoteOpenchamber,preferredPort:Number.isFinite(K)&&K>0?K:void 0}}))},onClear:()=>{Qe(K=>({...K,remoteOpenchamber:{...K.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]}),sa?t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Ks,{label:s("settings.remoteInstances.page.field.installMethod"),hint:s("settings.remoteInstances.page.field.installMethodHint")})}),t.jsxs(Ft,{value:y.remoteOpenchamber.installMethod,onValueChange:K=>Qe(qe=>({...qe,remoteOpenchamber:{...qe.remoteOpenchamber,installMethod:K==="npm"||K==="download_release"||K==="upload_bundle"?K:"bun"}})),children:[t.jsx(Ot,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Kt,{placeholder:s("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"bun",children:"bun"}),t.jsx(ht,{value:"npm",children:"npm"}),t.jsx(ht,{value:"download_release",children:s("settings.remoteInstances.page.field.installMethodDownloadRelease")}),t.jsx(ht,{value:"upload_bundle",children:s("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,sa?t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Ks,{label:s("settings.remoteInstances.page.field.keepServerRunning"),hint:s("settings.remoteInstances.page.field.keepServerRunningHint")})}),t.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:t.jsx(Fa,{checked:y.remoteOpenchamber.keepRunning,onCheckedChange:K=>Qe(qe=>({...qe,remoteOpenchamber:{...qe.remoteOpenchamber,keepRunning:K}}))})})]}):null]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.mainTunnel")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.mainTunnelDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Ks,{label:s("settings.remoteInstances.page.field.bindHost"),hint:s("settings.remoteInstances.page.field.bindHostHint")})}),t.jsxs(Ft,{value:y.localForward.bindHost,onValueChange:K=>{K==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces"))||Qe(qe=>({...qe,localForward:{...qe.localForward,bindHost:K==="localhost"||K==="0.0.0.0"?K:"127.0.0.1"}}))},children:[t.jsx(Ot,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Kt,{placeholder:s("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"127.0.0.1",children:"127.0.0.1"}),t.jsx(ht,{value:"localhost",children:"localhost"}),t.jsx(ht,{value:"0.0.0.0",children:"0.0.0.0"})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Ks,{label:s("settings.remoteInstances.page.field.preferredLocalPort"),hint:s("settings.remoteInstances.page.field.preferredLocalPortHint")})}),t.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[t.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.localForward.preferredLocalPort,onValueChange:K=>{Qe(qe=>({...qe,localForward:{...qe.localForward,preferredLocalPort:Number.isFinite(K)&&K>0?K:void 0}}))},onClear:()=>{Qe(K=>({...K,localForward:{...K.localForward,preferredLocalPort:void 0}}))},emptyLabel:s("settings.remoteInstances.page.field.auto")}),t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:s("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>Qe(K=>({...K,localForward:{...K.localForward,preferredLocalPort:Tr()}})),children:t.jsx(A,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]})]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.authentication")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.authenticationDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.sshPasswordOptional")}),t.jsx(it,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.sshPassword?.value||"",onChange:K=>Qe(qe=>({...qe,auth:{...qe.auth,sshPassword:{enabled:K.target.value.trim().length>0,value:K.target.value,store:qe.auth.sshPassword?.store||"never"}}})),placeholder:s("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.uiPasswordOptional")}),t.jsx(it,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.openchamberPassword?.value||"",onChange:K=>Qe(qe=>({...qe,auth:{...qe.auth,openchamberPassword:{enabled:K.target.value.trim().length>0,value:K.target.value,store:qe.auth.openchamberPassword?.store||"never"}}})),placeholder:s("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.portForwards")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.portForwardsDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[y.portForwards.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:s("settings.remoteInstances.page.empty.noExtraForwards")}):null,y.portForwards.map((K,qe)=>{const kt=Gt=>{Qe(ls=>({...ls,portForwards:ls.portForwards.map((Xr,pc)=>pc===qe?Gt(Xr):Xr)}))},Tt=K.type==="remote"?"Local target":"Local listen",ts=K.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.",C=K.type==="remote"?"Remote listen":"Remote target",gt=K.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",zt=Po(K.localHost||"localhost",K.localPort),ss=Po(K.remoteHost||"localhost",K.remotePort),Is=K.type==="local"&&typeof K.localPort=="number"&&K.localPort>0,zs=Is?`http://${cf(K.localHost)}:${K.localPort}`:"",on=!!F[K.id],Ln=K.type==="local"?s("settings.remoteInstances.page.forwardType.local"):K.type==="remote"?s("settings.remoteInstances.page.forwardType.remote"):s("settings.remoteInstances.page.forwardType.dynamic");return t.jsxs(gn,{open:on,onOpenChange:Gt=>{H(ls=>({...ls,[K.id]:Gt}))},className:`${qe>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("div",{className:"min-w-0 flex items-center gap-2",children:t.jsxs(hn,{className:"flex items-center gap-2 group",children:[t.jsx(A,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${on?"rotate-180":""}`}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:af(K)}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Ln})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Fa,{checked:K.enabled,onCheckedChange:Gt=>kt(ls=>({...ls,enabled:Gt})),"aria-label":s("settings.remoteInstances.page.actions.enableForwardAria")}),t.jsx(J,{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:()=>Qe(Gt=>({...Gt,portForwards:Gt.portForwards.filter(ls=>ls.id!==K.id)})),children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),t.jsx(fn,{className:"pt-2",children:t.jsxs("div",{className:"space-y-0 pb-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:s(lf(K.type))}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Ks,{label:s("settings.remoteInstances.page.field.forwardType"),hint:s("settings.remoteInstances.page.field.forwardTypeHint")})}),t.jsxs(Ft,{value:K.type,onValueChange:Gt=>kt(ls=>({...ls,type:Gt==="dynamic"||Gt==="remote"?Gt:"local"})),children:[t.jsx(Ot,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Kt,{placeholder:s("settings.remoteInstances.page.field.typePlaceholder")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"local",children:s("settings.remoteInstances.page.forwardType.local")}),t.jsx(ht,{value:"remote",children:s("settings.remoteInstances.page.forwardType.remote")}),t.jsx(ht,{value:"dynamic",children:s("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Ks,{label:Tt,hint:ts})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(it,{className:"h-7 w-32",value:K.localHost||"127.0.0.1",onChange:Gt=>kt(ls=>({...ls,localHost:Gt.target.value})),placeholder:s("settings.remoteInstances.page.field.localHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:K.localPort,onValueChange:Gt=>{kt(ls=>({...ls,localPort:Number.isFinite(Gt)&&Gt>0?Gt:void 0}))},onClear:()=>{kt(Gt=>({...Gt,localPort:void 0}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]})]}),K.type!=="dynamic"?t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Ks,{label:C,hint:gt})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(it,{className:"h-7 w-32",value:K.remoteHost||"",onChange:Gt=>kt(ls=>({...ls,remoteHost:Gt.target.value})),placeholder:s("settings.remoteInstances.page.field.remoteHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:K.remotePort,onValueChange:Gt=>{kt(ls=>({...ls,remotePort:Number.isFinite(Gt)&&Gt>0?Gt:void 0}))},onClear:()=>{kt(Gt=>({...Gt,remotePort:void 0}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]})]}):null,t.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[t.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:K.type==="dynamic"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:zt}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.localSocks5")})]}):K.type==="remote"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"server",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:ss}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.remote")}),t.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"}),t.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:zt}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.local")})]}):t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:zt}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.local")}),t.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"}),t.jsx(A,{name:"server",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:ss}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.remote")})]})}),Is?t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Hs(zs).then(Gt=>{Gt||V.error(s("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[t.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},K.id)}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const K=rf();Qe(qe=>({...qe,portForwards:[...qe.portForwards,K]})),H(qe=>({...qe,[K.id]:!0}))},children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.addForward")]})]})]}),t.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{mt()},disabled:!ys||c,children:s("settings.common.actions.saveChanges")}),Wt?.localUrl?t.jsxs(t.Fragment,{children:[t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{un(Wt.localUrl||"").then(K=>{K.ok&&V.success(s("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[t.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.copyLocalUrl")]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Fn()},children:[t.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.open")]})]}):null,x?t.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:x}):null]})}),t.jsx(Ut,{open:P,onOpenChange:z,children:t.jsxs(Bt,{className:"sm:max-w-2xl",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("settings.remoteInstances.page.logsDialog.title")}),t.jsx(qt,{children:y?.nickname?.trim()||y?.sshParsed?.destination||y?.id||s("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Gs,disabled:M||!As.trim(),children:[t.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),s("settings.common.actions.copyAll")]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Js()},disabled:M,children:[t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.clear")]})]}),M?t.jsx("div",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.logsDialog.loading")}):v?t.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:v}):t.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:O.length>0?O.join(`
29
- `):s("settings.remoteInstances.page.logsDialog.empty")})]})}),t.jsx(Ut,{open:!!U,onOpenChange:K=>{K||Rt()},children:t.jsxs(Bt,{className:"sm:max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx(qt,{children:U?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:U}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:K=>{K.preventDefault(),Zt()},children:[t.jsx(it,{value:Q,onChange:K=>W(K.target.value),placeholder:s("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Rt,disabled:R,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:R,children:s("settings.common.actions.create")})]})]})]})})]})})},pf="__add_provider__",gf=()=>{const s=Ns.getDirectory();return typeof s=="string"&&s.trim().length>0?s.trim():null},hf=({onItemSelect:s})=>{const{t:e}=dt(),n=ut(u=>u.providers),a=ut(u=>u.selectedProviderId),r=ut(u=>u.setSelectedProvider),i=as(u=>u.activeProjectId),[o,d]=l.useState({}),c=l.useMemo(()=>gf(),[i]);l.useEffect(()=>{if(n.length===0){d({});return}let u=!1;return(async()=>{const f=n.map(async g=>{try{const h=c?`?directory=${encodeURIComponent(c)}`:"",D=await jt(`/api/provider/${encodeURIComponent(g.id)}/source${h}`,{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const k=await D.json().catch(()=>null),w=k?.sources??k?.data?.sources;if(!w||u)return;d(E=>({...E,[g.id]:w}))}catch{}});await Promise.all(f)})(),()=>{u=!0}},[c,n]);const x="bg-background",m=l.useMemo(()=>n.filter(u=>!!o[u.id]?.project?.exists),[n,o]),p=l.useMemo(()=>n.filter(u=>!o[u.id]?.project?.exists),[n,o]);return t.jsxs("div",{className:de("flex h-full flex-col",x),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.providers.sidebar.title")}),t.jsx(ta,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),t.jsx(J,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(pf),s?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:t.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[p.length>0&&t.jsxs(t.Fragment,{children:[t.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")}),p.map(u=>t.jsx(Io,{provider:u,selectedProviderId:a,onSelect:()=>{r(u.id),s?.()}},u.id))]}),m.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:de("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",p.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(u=>t.jsx(Io,{provider:u,selectedProviderId:a,onSelect:()=>{r(u.id),s?.()}},u.id))]})]})})]})},Io=s=>{const e=rt.c(17),{provider:n,selectedProviderId:a,onSelect:r}=s,i=Array.isArray(n.models)?n.models.length:0,o=n.id===a,d=n.id,c=o?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[0]!==c?(x=de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=x):x=e[1];let m;e[2]!==n.id?(m=t.jsx(An,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const p=n.name||n.id;let u;e[4]!==p?(u=t.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:p}),e[4]=p,e[5]=u):u=e[5];let S;e[6]!==i?(S=t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=S):S=e[7];let f;e[8]!==r||e[9]!==m||e[10]!==u||e[11]!==S?(f=t.jsxs("button",{type:"button",onClick:r,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,u,S]}),e[8]=r,e[9]=m,e[10]=u,e[11]=S,e[12]=f):f=e[12];let g;return e[13]!==n.id||e[14]!==x||e[15]!==f?(g=t.jsx("div",{className:x,children:f},d),e[13]=n.id,e[14]=x,e[15]=f,e[16]=g):g=e[16],g},ff=s=>s,xf=s=>new Intl.NumberFormat(Vr(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(s),Do=s=>{if(typeof s!="number"||Number.isNaN(s))return null;if(s===0)return"0";const e=xf(s);return e.endsWith(".0")?e.slice(0,-2):e},ha="__add_provider__",Rn=s=>typeof s=="object"&&s!==null,Ao=s=>{const e=typeof s.type=="string"?s.type:"",n=`${s.name??""} ${s.label??""}`.toLowerCase(),a=`${e} ${n}`.toLowerCase();return a.includes("oauth")?"oauth":a.includes("api")?"api":e.toLowerCase()},bf=s=>{if(!Rn(s))return{};const e={};for(const[n,a]of Object.entries(s))Array.isArray(a)&&(e[n]=a.filter(r=>Rn(r)));return e},yf=s=>{if(typeof s=="string")return{id:s};if(!Rn(s))return null;const e=typeof s.id=="string"&&s.id||typeof s.providerID=="string"&&s.providerID||typeof s.slug=="string"&&s.slug||typeof s.name=="string"&&s.name;if(!e)return null;const n=typeof s.name=="string"?s.name:void 0;return{id:e,name:n}},vf=s=>{let e=[];Array.isArray(s)?e=s:Rn(s)&&(Array.isArray(s.all)?e=s.all:Array.isArray(s.providers)&&(e=s.providers));const n=e.map(r=>yf(r)).filter(r=>!!r),a=new Set;return n.filter(r=>a.has(r.id)?!1:(a.add(r.id),!0))},jf=()=>{const{t:s}=dt(),e=ut(_=>_.providers),n=ut(_=>_.selectedProviderId),a=ut(_=>_.setSelectedProvider),r=ut(_=>_.getModelMetadata),i=Ke(_=>_.hiddenModels),o=Ke(_=>_.toggleHiddenModel),d=Ke(_=>_.hideAllModels),c=Ke(_=>_.showAllModels),[x,m]=l.useState({}),[p,u]=l.useState(!1),[S,f]=l.useState({}),[g,h]=l.useState(null),[D,k]=l.useState(""),[w,E]=l.useState(null),[N,y]=l.useState({}),[b,P]=l.useState({}),[z,M]=l.useState([]),[I,v]=l.useState(!1),[j,O]=l.useState(null),[T,U]=l.useState(""),[B,Q]=l.useState(""),[W,R]=l.useState(!1),[Y,F]=l.useState({}),[H,X]=l.useState(!1),re=n===ha;l.useEffect(()=>{!n&&e.length>0&&a(e[0].id)},[e,n,a]),l.useEffect(()=>{if(!re)return;let _=!0;return(async()=>{u(!0);try{const ne=await Ns.getSdkClient().provider.auth();if(ne.error)throw new Error(`provider.auth failed: ${String(ne.error)}`);if(!_)return;m(bf(ne.data))}catch(ne){if(!_)return;console.error("Failed to load provider auth methods:",ne),V.error(s("settings.providers.page.toast.authMethodsLoadFailed"))}finally{_&&u(!1)}})(),()=>{_=!1}},[re,s]),l.useEffect(()=>{if(!ff(re))return;let _=!0;return(async()=>{v(!0),O(null);try{const ne=await Ns.getSdkClient().provider.list();if(ne.error)throw new Error(`provider.list failed: ${String(ne.error)}`);if(!_)return;M(vf(ne.data))}catch(ne){if(!_)return;console.error("Failed to load available providers:",ne),O(s("settings.providers.page.state.unableToLoadProviderList"))}finally{_&&v(!1)}})(),()=>{_=!1}},[re,s]);const Z=l.useMemo(()=>new Set(e.map(_=>_.id)),[e]),se=l.useMemo(()=>z.filter(_=>!Z.has(_.id)).sort((_,ee)=>{const ne=(_.name||_.id).toLowerCase(),ue=(ee.name||ee.id).toLowerCase();return ne.localeCompare(ue)}),[z,Z]);l.useEffect(()=>{n===ha&&T&&!se.some(_=>_.id===T)&&U("")},[n,T,se]),l.useEffect(()=>{if(n===ha){X(!0);return}X(!1)},[n,s]),l.useEffect(()=>{if(!n||n===ha)return;let _=!1;return(async()=>{try{const ne=await jt(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),ue=await ne.json().catch(()=>null);if(!ne.ok)throw new Error(ue?.error||s("settings.providers.page.toast.providerSourcesLoadFailed"));const Me=ue?.sources??ue?.data?.sources;!_&&Me&&F(ke=>({...ke,[n]:Me}))}catch(ne){_||console.error("Failed to load provider sources:",ne)}})(),()=>{_=!0}},[n,s]);const ce=e.find(_=>_.id===n),oe=n?Y[n]:void 0,xe=async _=>{const ee=S[_]?.trim()??"";if(!ee){V.error(s("settings.providers.page.toast.apiKeyRequired"));return}const ne=`api:${_}`;h(ne);try{if((await Ns.getSdkClient().auth.set({providerID:_,auth:{type:"api",key:ee}})).error)throw new Error(s("settings.providers.page.toast.apiKeySaveFailed"));V.success(s("settings.providers.page.toast.apiKeySaved")),f(Me=>({...Me,[_]:""})),await In({scopes:["providers"],mode:"active"}),a(_)}catch(ue){console.error("Failed to save API key:",ue),V.error(s("settings.providers.page.toast.apiKeySaveFailed"))}finally{h(null)}},we=async(_,ee)=>{const ne=`oauth:${_}:${ee}`;h(ne);try{const ue=await Ns.getSdkClient().provider.oauth.authorize({providerID:_,method:ee});if(ue.error)throw new Error(s("settings.providers.page.toast.oauthStartFailed"));const Me=Rn(ue.data)?ue.data:{},ke=Me.data,De=Rn(ke)?ke:Me,Ae=typeof De.url=="string"&&De.url||typeof De.verification_uri_complete=="string"&&De.verification_uri_complete||typeof De.verification_uri=="string"&&De.verification_uri||void 0,Pe=typeof De.instructions=="string"&&De.instructions||typeof De.message=="string"&&De.message||void 0,Re=typeof De.user_code=="string"&&De.user_code||typeof De.code=="string"&&De.code||typeof De.userCode=="string"&&De.userCode||void 0;if(!Ae&&!Pe&&!Re)throw new Error(s("settings.providers.page.toast.oauthDetailsMissing"));const Oe=`${_}:${ee}`;P($e=>({...$e,[Oe]:{url:Ae,instructions:Pe,userCode:Re}})),Ae&&Hs(Ae),E({providerId:_,methodIndex:ee}),V.message(s("settings.providers.page.toast.completeOAuthInBrowser"))}catch(ue){console.error("Failed to start OAuth flow:",ue),V.error(s("settings.providers.page.toast.oauthStartFailed"))}finally{h(null)}},he=async(_,ee)=>{const ne=`${_}:${ee}`,ue=N[ne]?.trim(),Me=`oauth-complete:${_}:${ee}`;h(Me);try{const ke={method:ee};if(ue&&(ke.code=ue),(await Ns.getSdkClient().provider.oauth.callback({providerID:_,method:ke.method,code:ke.code})).error)throw new Error(s("settings.providers.page.toast.oauthCompleteFailed"));V.success(s("settings.providers.page.toast.oauthCompleted")),y(Ae=>({...Ae,[ne]:""})),E(null),await In({scopes:["providers"],mode:"active"}),a(_)}catch(ke){console.error("Failed to complete OAuth flow:",ke),V.error(s("settings.providers.page.toast.oauthCompleteFailed"))}finally{h(null)}},Ie=async _=>{const ee=await un(_);if(ee.ok){V.success(s("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",ee.error),V.error(s("settings.providers.page.toast.oauthLinkCopyFailed"))},ve=async _=>{const ee=await un(_);if(ee.ok){V.success(s("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",ee.error),V.error(s("settings.providers.page.toast.deviceCodeCopyFailed"))},be=async _=>{const ee=`disconnect:${_}`;h(ee);try{const ne=await jt(`/api/provider/${encodeURIComponent(_)}/auth?scope=all`,{method:"DELETE",headers:{Accept:"application/json"}}),ue=await ne.json().catch(()=>null);if(!ne.ok)throw new Error(ue?.error||s("settings.providers.page.toast.providerDisconnectFailed"));V.success(s("settings.providers.page.toast.providerDisconnected")),await In({scopes:["providers"],mode:"active"})}catch(ne){console.error("Failed to disconnect provider:",ne),V.error(s("settings.providers.page.toast.providerDisconnectFailed"))}finally{h(null)}};if(!re&&e.length===0)return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.providers.page.empty.noProvidersDetected")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(re)return t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{"data-settings-item":"providers.connect",className:"mb-4",children:t.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.providers.page.connect.title")})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.connect.selectProviderTitle")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.providers.page.connect.providerField")}),I?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.state.loading")}):j?t.jsx("p",{className:"typography-meta text-muted-foreground",children:j}):se.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.connect.allProvidersConnected")}):t.jsxs(us,{open:W,onOpenChange:_=>{R(_),_||Q("")},children:[t.jsx(ds,{asChild:!0,children:t.jsxs("button",{type:"button",className:de("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:[t.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[T?t.jsx(An,{providerId:T,className:"h-3.5 w-3.5 flex-shrink-0"}):null,t.jsx("span",{className:de("truncate typography-ui-label font-normal",T?"text-foreground":"text-muted-foreground"),children:T?se.find(_=>_.id===T)?.name||T:s("settings.providers.page.connect.selectProviderPlaceholder")})]}),t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),t.jsxs(ms,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:_=>_.preventDefault(),children:[t.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:_=>_.stopPropagation(),children:[t.jsx(A,{name:"search",className:"h-4 w-4 text-muted-foreground"}),t.jsx("input",{type:"text",value:B,onChange:_=>Q(_.target.value),onKeyDown:_=>_.stopPropagation(),placeholder:s("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),t.jsx(Jt,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const _=se.filter(ee=>{const ne=B.toLowerCase();return(ee.name||ee.id).toLowerCase().includes(ne)||ee.id.toLowerCase().includes(ne)});return _.length===0?t.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:s("settings.providers.page.connect.noProvidersFound")}):_.map(ee=>t.jsxs(js,{onSelect:()=>{U(ee.id),R(!1),Q("")},className:"flex items-center justify-between",children:[t.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(An,{providerId:ee.id,className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:ee.name||ee.id})]}),T===ee.id&&t.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ee.id))})()})]})]})]})})]}),T&&t.jsxs("div",{"data-settings-item":"providers.auth",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.auth.title")})}),p?t.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:s("settings.providers.page.auth.loadingMethods")}):t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[t.jsxs("div",{className:"py-1.5",children:[t.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[s("settings.providers.page.auth.apiKeyLabel"),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.providers.page.auth.apiKeyTooltip")})]})]}),t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[t.jsx(it,{type:"password",value:S[T]??"",onChange:_=>f(ee=>({...ee,[T]:_.target.value})),placeholder:s("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal shrink-0",onClick:()=>xe(T),disabled:g===`api:${T}`,children:g===`api:${T}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),(()=>{const ee=(x[T]??[]).filter(ne=>Ao(ne)==="oauth");return ee.length===0?null:t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ee.map((ne,ue)=>{const Me=ne.label||ne.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String(ue+1)}),ke=`${T}:${ue}`,De=w?.providerId===T&&w?.methodIndex===ue;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:Me}),(ne.description||ne.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(ne.description||ne.help)})]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>we(T,ue),disabled:g===`oauth:${T}:${ue}`,children:s("settings.providers.page.actions.connect")})]}),b[ke]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:b[ke]?.instructions}),b[ke]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(it,{value:b[ke]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ve(b[ke]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),b[ke]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(it,{value:b[ke]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Hs(b[ke]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie(b[ke]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),De&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(it,{value:N[ke]??"",onChange:Ae=>y(Pe=>({...Pe,[ke]:Ae.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal",onClick:()=>he(T,ue),disabled:g===`oauth-complete:${T}:${ue}`,children:g===`oauth-complete:${T}:${ue}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${T}-${Me}`)})})})()]})]})]})});if(!ce)return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.providers.page.empty.selectProviderFromSidebar")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const ye=Array.isArray(ce.models)?ce.models:[],ie=(x[ce.id]??[]).filter(_=>Ao(_)==="oauth"),ge=ye.filter(_=>{const ee=typeof _?.name=="string"?_.name:"",ne=typeof _?.id=="string"?_.id:"",ue=D.trim().toLowerCase();return ue?ee.toLowerCase().includes(ue)||ne.toLowerCase().includes(ue):!0});return t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[t.jsx(An,{providerId:ce.id,className:"h-5 w-5 shrink-0"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ce.name||ce.id}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t.jsx("span",{className:"font-mono",children:ce.id})})]})]}),t.jsxs("div",{"data-settings-item":"providers.auth",className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.auth.title")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>X(_=>!_),children:s(H?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:H?p?t.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:s("settings.providers.page.auth.loadingMethods")}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"py-1.5",children:[t.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[s("settings.providers.page.auth.apiKeyLabel"),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.providers.page.auth.apiKeyTooltip")})]})]}),t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[t.jsx(it,{type:"password",value:S[ce.id]??"",onChange:_=>f(ee=>({...ee,[ce.id]:_.target.value})),placeholder:s("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal shrink-0",onClick:()=>xe(ce.id),disabled:g===`api:${ce.id}`,children:g===`api:${ce.id}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),ie.length>0&&t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ie.map((_,ee)=>{const ne=_.label||_.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String(ee+1)}),ue=`${ce.id}:${ee}`,Me=w?.providerId===ce.id&&w?.methodIndex===ee;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:ne}),(_.description||_.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(_.description||_.help)})]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>we(ce.id,ee),disabled:g===`oauth:${ce.id}:${ee}`,children:s("settings.providers.page.actions.connect")})]}),b[ue]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:b[ue]?.instructions}),b[ue]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(it,{value:b[ue]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ve(b[ue]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),b[ue]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(it,{value:b[ue]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Hs(b[ue]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie(b[ue]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),Me&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(it,{value:N[ue]??"",onChange:ke=>y(De=>({...De,[ue]:ke.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal",onClick:()=>he(ce.id,ee),disabled:g===`oauth-complete:${ce.id}:${ee}`,children:g===`oauth-complete:${ce.id}:${ee}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${ce.id}-${ne}`)})})]}):t.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[t.jsx(A,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.providers.page.auth.connected")}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-1",children:s("settings.providers.page.auth.useReconnectHint")})]})})]}),t.jsxs("div",{"data-settings-item":"providers.connection-details",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.connectionDetails.title")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col",children:oe&&(oe.auth.exists||oe.user.exists||oe.project.exists||oe.custom?.exists)?t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[s("settings.providers.page.connectionDetails.configuredIn")," ",[oe.auth.exists?s("settings.providers.page.connectionDetails.source.authCredentials"):null,oe.user.exists?s("settings.providers.page.connectionDetails.source.userConfig"):null,oe.project.exists?s("settings.providers.page.connectionDetails.source.projectConfig"):null,oe.custom?.exists?s("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.connectionDetails.noActiveSource")})}),t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>be(ce.id),disabled:g===`disconnect:${ce.id}`,children:g===`disconnect:${ce.id}`?s("settings.providers.page.actions.disconnecting"):s("settings.providers.page.actions.disconnect")})]})})]}),t.jsxs("div",{"data-settings-item":"providers.models",className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[t.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[s("settings.providers.page.models.title"),ye.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ye.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const _=ye.map(ee=>typeof ee?.id=="string"?ee.id:"").filter(ee=>ee.length>0);d(ce.id,_)},children:s("settings.providers.page.actions.hideAll")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>c(ce.id),children:s("settings.providers.page.actions.showAll")})]})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0",children:[t.jsxs("div",{className:"relative mb-2",children:[t.jsx(A,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),t.jsx(it,{value:D,onChange:_=>k(_.target.value),placeholder:s("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ge.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:s("settings.providers.page.models.noModelsMatchFilter")}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:ge.map(_=>{const ee=typeof _?.id=="string"?_.id:"",ne=typeof _?.name=="string"?_.name:ee,ue=ee?r(ce.id,ee):void 0,Me=i.some(Pe=>Pe.providerID===ce.id&&Pe.modelID===ee),ke=Do(ue?.limit?.context),De=Do(ue?.limit?.output),Ae=[];return ue?.tool_call&&Ae.push({key:"tools",icon:"tools",label:s("settings.providers.page.models.capability.toolCalling")}),ue?.reasoning&&Ae.push({key:"reasoning",icon:"brain-ai-3",label:s("settings.providers.page.models.capability.reasoning")}),ue?.attachment&&Ae.push({key:"image",icon:"file-image",label:s("settings.providers.page.models.capability.imageInput")}),t.jsx("div",{className:"py-1.5",children:t.jsxs("div",{className:de("flex items-center gap-3",Me&&"opacity-50"),children:[t.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:ne}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(ke||De)&&t.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[ke?`${ke} ${s("settings.providers.page.models.tokenBadge.context")}`:"",ke&&De?" · ":"",De?`${De} ${s("settings.providers.page.models.tokenBadge.output")}`:""]}),Ae.length>0&&t.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Ae.map(({key:Pe,icon:Re,label:Oe})=>t.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Oe,"aria-label":Oe,children:t.jsx(A,{name:Re,className:"h-3 w-3"})},Pe))}),t.jsx("button",{type:"button",onClick:()=>o(ce.id,ee),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:s(Me?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":s(Me?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Me?t.jsx(A,{name:"eye-off",className:"h-3.5 w-3.5"}):t.jsx(A,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ee)})})]})]})]})})},an=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"cursor",name:"Cursor"},{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"}];function Eo(s){const e=s.indexOf("/");if(e!==-1){const n=s.substring(0,e);if(n==="gemini"||n==="antigravity")return s.substring(e+1)}return s}const wf=[{id:"gemini-auth",label:"Gemini",matcher:s=>s.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:s=>s.startsWith("antigravity/"),order:2}],_l={google:wf};function Hl(s,e){const n=_l[e]??[];for(const a of n)if(a.matcher(s))return a;return null}function Nf(s){return _l[s]??[]}function kf(s){return[...s].sort((e,n)=>e.order-n.order)}function Kv(s,e){const n=new Map;for(const a of Object.keys(s)){const i=Hl(a,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(a)}return n}function Sf(s,e,n){const a=new Map;for(const r of s){const i=e(r),d=Hl(i,n)?.id??null;a.has(d)||a.set(d,[]),a.get(d).push(r)}return a}function Cf(s,e){return e.filter(n=>{const a=n.toLowerCase(),r=a.includes("/")?a.split("/")[1]:a;return!!(r.startsWith("gemini-3-")||r.startsWith("claude-"))})}const qr=6e4,Mo=s=>{const e=an.map(u=>u.id),n=typeof s?.usageAutoRefresh=="boolean"?s.usageAutoRefresh:!1,a=typeof s?.usageRefreshIntervalMs=="number"&&Number.isFinite(s.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(s.usageRefreshIntervalMs))):qr,r=s?.usageDisplayMode==="remaining"?"remaining":"usage",i=typeof s?.usageShowPredValues=="boolean"?s.usageShowPredValues:!1,o=Array.isArray(s?.usageDropdownProviders)?s?.usageDropdownProviders:null,d=o?o.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},x=s?.usageSelectedModels;if(x&&typeof x=="object")for(const[u,S]of Object.entries(x))Array.isArray(S)&&(c[u]=S.filter(f=>typeof f=="string"));const m={},p=s?.usageExpandedFamilies;if(p&&typeof p=="object")for(const[u,S]of Object.entries(p))Array.isArray(S)&&(m[u]=S.filter(f=>typeof f=="string"));return{autoRefresh:n,refreshIntervalMs:a,displayMode:r,showPredValues:i,dropdownProviderIds:d,selectedModels:c,expandedFamilies:m}},Pf=async()=>{const s=Fs()?.settings;if(s)try{const n=(await s.load())?.settings;return Mo(n??null)}catch{}if(!gs()){const e=await jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Mo(n)}}return{autoRefresh:!1,refreshIntervalMs:qr,displayMode:"usage",showPredValues:!1,dropdownProviderIds:an.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ht=rn()(Zn((s,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:qr,displayMode:"usage",showPredValues:!1,dropdownProviderIds:an.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Pf();s(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{s({isLoading:!0,error:null});const n=an.map(a=>a.id);try{await Promise.all(n.map(a=>e().fetchProviderQuota(a))),s({isLoading:!1,lastUpdated:Date.now()})}catch(a){const r=a instanceof Error?a.message:"Failed to fetch quotas";s({isLoading:!1,error:r})}},fetchProviderQuota:async n=>{s(a=>({isFetchingProvider:{...a.isFetchingProvider,[n]:!0}}));try{const a=await jt(`/api/quota/${encodeURIComponent(n)}`),r=await a.json().catch(()=>null);if(!a.ok)throw new Error(r?.error||"Failed to fetch quota");const i=r;s(o=>{const d=o.results.filter(c=>c.providerId!==n);return d.push(i),{results:d,error:null}})}catch(a){const r=a instanceof Error?a.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:r,usage:null,fetchedAt:Date.now()};s(o=>{const d=o.results.filter(c=>c.providerId!==n);return d.push(i),{results:d,error:r}})}finally{s(a=>({isFetchingProvider:{...a.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>s({selectedProviderId:n}),setAutoRefresh:n=>s({autoRefresh:n}),setRefreshInterval:n=>{const a=Math.max(3e4,Math.min(3e5,Math.round(n)));s({refreshIntervalMs:a})},setDisplayMode:n=>s({displayMode:n}),setShowPredValues:n=>s({showPredValues:n}),setDropdownProviderIds:n=>s({dropdownProviderIds:n}),setSelectedModels:(n,a)=>{s(r=>({selectedModels:{...r.selectedModels,[n]:a}}))},toggleModelSelected:(n,a)=>{s(r=>{const i=r.selectedModels[n]??[],d=i.includes(a)?i.filter(c=>c!==a):[...i,a];return{selectedModels:{...r.selectedModels,[n]:d}}})},setExpandedFamilies:(n,a)=>{s(r=>({expandedFamilies:{...r.expandedFamilies,[n]:a}})),It({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,a)=>{s(r=>{const i=r.expandedFamilies[n]??[],d=i.includes(a)?i.filter(c=>c!==a):[...i,a];return{expandedFamilies:{...r.expandedFamilies,[n]:d}}}),It({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,a)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=Cf(n,a);i.length!==0&&(s(o=>({selectedModels:{...o.selectedModels,[n]:i}})),It({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),If=()=>{const s=rt.c(5),e=Ht(Df),n=Ht(Af),a=Ht(Ef);let r,i;s[0]!==e||s[1]!==a||s[2]!==n?(r=()=>{if(!e)return;const o=window.setInterval(()=>{a()},n);return()=>window.clearInterval(o)},i=[e,n,a],s[0]=e,s[1]=a,s[2]=n,s[3]=r,s[4]=i):(r=s[3],i=s[4]),l.useEffect(r,i)};function Df(s){return s.autoRefresh}function Af(s){return s.refreshIntervalMs}function Ef(s){return s.fetchAllQuotas}const Mf=s=>{const e=s?.windows??{},n=Object.values(e).map(a=>a.usedPercent).filter(a=>typeof a=="number");return n.length===0?null:Math.max(...n)},Rf=s=>{const e=rt.c(122),{onItemSelect:n}=s,{t:a}=dt(),r=Ht(Tf),i=Ht(Ff),o=Ht(Of),d=Ht(Lf),c=Ht(zf),x=Ht(Kf),m=Ht($f),p=Ht(Uf),u=Ht(Bf),S=Ht(Vf),f=Ht(_f),g=Ht(Hf),h=Ht(Wf),D=Ht(qf);let k,w;e[0]!==D?(k=()=>{D()},w=[D],e[0]=D,e[1]=k,e[2]=w):(k=e[1],w=e[2]),l.useEffect(k,w);const E=Gf;let N;e[3]!==u?(N=Ne=>{u(Ne),E({usageAutoRefresh:Ne})},e[3]=u,e[4]=N):N=e[4];const y=N;let b;e[5]!==S?(b=Ne=>{const Ee=Number(Ne);Number.isFinite(Ee)&&(S(Ee),E({usageRefreshIntervalMs:Ee}))},e[5]=S,e[6]=b):b=e[6];const P=b;let z;e[7]!==f?(z=Ne=>{Ne!=="usage"&&Ne!=="remaining"||(f(Ne),E({usageDisplayMode:Ne}))},e[7]=f,e[8]=z):z=e[8];const M=z;let I;e[9]!==h?(I=Ne=>{h(Ne),E({usageShowPredValues:Ne})},e[9]=h,e[10]=I):I=e[10];const v=I;let j;e[11]===Symbol.for("react.memo_cache_sentinel")?(j=de("flex h-full flex-col","bg-background"),e[11]=j):j=e[11];let O;e[12]!==a?(O=a("settings.usage.sidebar.title"),e[12]=a,e[13]=O):O=e[13];let T;e[14]!==O?(T=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:O}),e[14]=O,e[15]=T):T=e[15];let U;e[16]!==a?(U=a("settings.usage.sidebar.total",{count:an.length}),e[16]=a,e[17]=U):U=e[17];let B;e[18]!==U?(B=t.jsx("span",{className:"typography-meta text-muted-foreground",children:U}),e[18]=U,e[19]=B):B=e[19];let Q;e[20]!==a?(Q=a("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[20]=a,e[21]=Q):Q=e[21];let W;e[22]!==y||e[23]!==Q||e[24]!==x?(W=t.jsx(At,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:t.jsx(Pt,{checked:x,onChange:y,ariaLabel:Q})})}),e[22]=y,e[23]=Q,e[24]=x,e[25]=W):W=e[25];let R;e[26]!==a?(R=a("settings.usage.sidebar.tooltip.autoRefresh"),e[26]=a,e[27]=R):R=e[27];let Y;e[28]!==R?(Y=t.jsx(Et,{side:"bottom",children:R}),e[28]=R,e[29]=Y):Y=e[29];let F;e[30]!==W||e[31]!==Y?(F=t.jsxs(Dt,{children:[W,Y]}),e[30]=W,e[31]=Y,e[32]=F):F=e[32];const H=String(m),X=!x;let re;e[33]!==a?(re=a("settings.usage.sidebar.field.intervalPlaceholder"),e[33]=a,e[34]=re):re=e[34];let Z;e[35]!==re?(Z=t.jsx(Ot,{className:"w-fit",children:t.jsx(Kt,{placeholder:re})}),e[35]=re,e[36]=Z):Z=e[36];let se;e[37]===Symbol.for("react.memo_cache_sentinel")?(se=t.jsxs(Lt,{children:[t.jsx(ht,{value:"30000",children:"30s"}),t.jsx(ht,{value:"60000",children:"1m"}),t.jsx(ht,{value:"300000",children:"5m"})]}),e[37]=se):se=e[37];let ce;e[38]!==P||e[39]!==H||e[40]!==X||e[41]!==Z?(ce=t.jsxs(Ft,{value:H,onValueChange:P,disabled:X,children:[Z,se]}),e[38]=P,e[39]=H,e[40]=X,e[41]=Z,e[42]=ce):ce=e[42];let oe;e[43]!==d?(oe=()=>d(),e[43]=d,e[44]=oe):oe=e[44];let xe;e[45]!==a?(xe=a("settings.usage.sidebar.actions.refreshAria"),e[45]=a,e[46]=xe):xe=e[46];let we;e[47]!==a?(we=a("settings.usage.sidebar.actions.refreshTitle"),e[47]=a,e[48]=we):we=e[48];const he=c&&"animate-spin";let Ie;e[49]!==he?(Ie=de("h-3.5 w-3.5",he),e[49]=he,e[50]=Ie):Ie=e[50];let ve;e[51]!==Ie?(ve=t.jsx(A,{name:"refresh",className:Ie}),e[51]=Ie,e[52]=ve):ve=e[52];let be;e[53]!==c||e[54]!==oe||e[55]!==xe||e[56]!==we||e[57]!==ve?(be=t.jsx(J,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:oe,"aria-label":xe,title:we,disabled:c,children:ve}),e[53]=c,e[54]=oe,e[55]=xe,e[56]=we,e[57]=ve,e[58]=be):be=e[58];let ye;e[59]!==F||e[60]!==ce||e[61]!==be?(ye=t.jsxs("div",{className:"flex items-center gap-2",children:[F,ce,be]}),e[59]=F,e[60]=ce,e[61]=be,e[62]=ye):ye=e[62];let te;e[63]!==B||e[64]!==ye?(te=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[B,ye]}),e[63]=B,e[64]=ye,e[65]=te):te=e[65];let ie;e[66]!==a?(ie=a("settings.usage.sidebar.field.display"),e[66]=a,e[67]=ie):ie=e[67];let ge;e[68]!==ie?(ge=t.jsx("span",{className:"typography-micro text-muted-foreground",children:ie}),e[68]=ie,e[69]=ge):ge=e[69];let _;e[70]!==a?(_=a("settings.usage.sidebar.field.displayModePlaceholder"),e[70]=a,e[71]=_):_=e[71];let ee;e[72]!==_?(ee=t.jsx(Ot,{className:"w-fit",children:t.jsx(Kt,{placeholder:_})}),e[72]=_,e[73]=ee):ee=e[73];let ne;e[74]!==a?(ne=a("settings.usage.sidebar.field.displayModeUsage"),e[74]=a,e[75]=ne):ne=e[75];let ue;e[76]!==ne?(ue=t.jsx(ht,{value:"usage",children:ne}),e[76]=ne,e[77]=ue):ue=e[77];let Me;e[78]!==a?(Me=a("settings.usage.sidebar.field.displayModeRemaining"),e[78]=a,e[79]=Me):Me=e[79];let ke;e[80]!==Me?(ke=t.jsx(ht,{value:"remaining",children:Me}),e[80]=Me,e[81]=ke):ke=e[81];let De;e[82]!==ue||e[83]!==ke?(De=t.jsxs(Lt,{children:[ue,ke]}),e[82]=ue,e[83]=ke,e[84]=De):De=e[84];let Ae;e[85]!==M||e[86]!==ee||e[87]!==De||e[88]!==p?(Ae=t.jsxs(Ft,{value:p,onValueChange:M,children:[ee,De]}),e[85]=M,e[86]=ee,e[87]=De,e[88]=p,e[89]=Ae):Ae=e[89];let Pe;e[90]!==ge||e[91]!==Ae?(Pe=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ge,Ae]}),e[90]=ge,e[91]=Ae,e[92]=Pe):Pe=e[92];let Re;e[93]!==a?(Re=a("settings.usage.sidebar.field.showPredictions"),e[93]=a,e[94]=Re):Re=e[94];let Oe;e[95]!==Re?(Oe=t.jsx("span",{className:"typography-micro text-muted-foreground",children:Re}),e[95]=Re,e[96]=Oe):Oe=e[96];let $e;e[97]!==a?($e=a("settings.usage.sidebar.field.showPredictions"),e[97]=a,e[98]=$e):$e=e[98];let Be;e[99]!==v||e[100]!==g||e[101]!==$e?(Be=t.jsx(Pt,{checked:g,onChange:v,ariaLabel:$e}),e[99]=v,e[100]=g,e[101]=$e,e[102]=Be):Be=e[102];let Le;e[103]!==Oe||e[104]!==Be?(Le=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[Oe,Be]}),e[103]=Oe,e[104]=Be,e[105]=Le):Le=e[105];let Ue;e[106]!==te||e[107]!==Pe||e[108]!==Le||e[109]!==T?(Ue=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,te,Pe,Le]}),e[106]=te,e[107]=Pe,e[108]=Le,e[109]=T,e[110]=Ue):Ue=e[110];let le;e[111]!==n||e[112]!==r||e[113]!==i||e[114]!==o||e[115]!==a?(le=an.map(Ne=>{const Ee=r.find(L=>L.providerId===Ne.id),Ce=Mf(Ee?.usage),He=wl(Ce),G=Ne.id===i,$=Ee?.configured??!1,fe=$?He==="critical"?{backgroundColor:"var(--status-error)"}:He==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return t.jsx("div",{className:de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",G?"bg-interactive-selection":"hover:bg-interactive-hover"),children:t.jsxs("button",{type:"button",onClick:()=>{o(Ne.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:[t.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:fe}),t.jsx(An,{providerId:Ne.id,className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:Ne.name}),!$&&t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:a("settings.usage.sidebar.status.notSet")})]})},Ne.id)}),e[111]=n,e[112]=r,e[113]=i,e[114]=o,e[115]=a,e[116]=le):le=e[116];let q;e[117]!==le?(q=t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:le}),e[117]=le,e[118]=q):q=e[118];let me;return e[119]!==Ue||e[120]!==q?(me=t.jsxs("div",{className:j,children:[Ue,q]}),e[119]=Ue,e[120]=q,e[121]=me):me=e[121],me};function Tf(s){return s.results}function Ff(s){return s.selectedProviderId}function Of(s){return s.setSelectedProvider}function Lf(s){return s.fetchAllQuotas}function zf(s){return s.isLoading}function Kf(s){return s.autoRefresh}function $f(s){return s.refreshIntervalMs}function Uf(s){return s.displayMode}function Bf(s){return s.setAutoRefresh}function Vf(s){return s.setRefreshInterval}function _f(s){return s.setDisplayMode}function Hf(s){return s.showPredValues}function Wf(s){return s.setShowPredValues}function qf(s){return s.loadSettings}async function Gf(s){try{await It(s)}catch(e){console.warn("Failed to save usage settings:",e)}}const Jf=s=>{const e=rt.c(20),{percent:n,tonePercent:a,className:r,expectedMarkerPercent:i}=s;let o;e[0]!==n?(o=Xd(n)??0,e[0]=n,e[1]=o):o=e[1];const d=o,c=a??n;let x;e[2]!==c?(x=wl(c),e[2]=c,e[3]=x):x=e[3];const m=x,p=i!=null?Math.max(0,Math.min(100,i)):null;let u;e[4]!==m?(u=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=u):u=e[5];const S=u;let f;e[6]!==r?(f=de("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=f):f=e[7];const g=`${d}%`;let h;e[8]!==S||e[9]!==g?(h={...S,width:g},e[8]=S,e[9]=g,e[10]=h):h=e[10];let D;e[11]!==d||e[12]!==h?(D=t.jsx("div",{className:"h-full transition-all duration-300",style:h,role:"progressbar","aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100}),e[11]=d,e[12]=h,e[13]=D):D=e[13];let k;e[14]!==p?(k=p!=null&&p>0&&p<100&&t.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${p}%`},title:`Expected usage if spread evenly: ${Math.round(p)}% of quota`,"aria-hidden":"true"}),e[14]=p,e[15]=k):k=e[15];let w;return e[16]!==f||e[17]!==D||e[18]!==k?(w=t.jsxs("div",{className:f,children:[D,k]}),e[16]=f,e[17]=D,e[18]=k,e[19]=w):w=e[19],w},Qf=s=>{const e=rt.c(67),{paceInfo:n,className:a,compact:r}=s,i=r===void 0?!1:r,{t:o}=dt();let d;e[0]!==n.status?(d=Zd(n.status),e[0]=n.status,e[1]=d):d=e[1];const c=d;let x;e:{switch(n.status){case"on-track":{let b;e[2]!==o?(b=o("settings.usage.pace.status.onTrack"),e[2]=o,e[3]=b):b=e[3],x=b;break e}case"slightly-fast":{let b;e[4]!==o?(b=o("settings.usage.pace.status.slightlyFast"),e[4]=o,e[5]=b):b=e[5],x=b;break e}case"too-fast":{let b;e[6]!==o?(b=o("settings.usage.pace.status.tooFast"),e[6]=o,e[7]=b):b=e[7],x=b;break e}case"exhausted":{let b;e[8]!==o?(b=o("settings.usage.pace.status.usedUp"),e[8]=o,e[9]=b):b=e[9],x=b;break e}}x=void 0}const m=x;let p;e[10]!==n.predictText||e[11]!==o?(p=o("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=o,e[12]=p):p=e[12];const u=p;if(i){let b;e[13]!==a?(b=de("flex items-center gap-1.5",a),e[13]=a,e[14]=b):b=e[14];let P;e[15]!==c?(P={backgroundColor:c},e[15]=c,e[16]=P):P=e[16];let z;e[17]!==m||e[18]!==P?(z=t.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:P,title:m}),e[17]=m,e[18]=P,e[19]=z):z=e[19];let M;e[20]!==c?(M={color:c},e[20]=c,e[21]=M):M=e[21];const I=n.isExhausted?void 0:u;let v;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==o?(v=n.isExhausted?t.jsx(t.Fragment,{children:o("settings.usage.pace.wait",{duration:ui(n.remainingSeconds)})}):t.jsx(t.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]=v):v=e[26];let j;e[27]!==v||e[28]!==M||e[29]!==I?(j=t.jsx("span",{className:"typography-micro tabular-nums",style:M,title:I,children:v}),e[27]=v,e[28]=M,e[29]=I,e[30]=j):j=e[30];let O;return e[31]!==j||e[32]!==b||e[33]!==z?(O=t.jsxs("div",{className:b,children:[z,j]}),e[31]=j,e[32]=b,e[33]=z,e[34]=O):O=e[34],O}let S;e[35]!==a?(S=de("flex items-center justify-between gap-2",a),e[35]=a,e[36]=S):S=e[36];let f;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==o?(f=!n.isExhausted&&t.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=o,e[40]=f):f=e[40];let g;e[41]!==f?(g=t.jsx("div",{className:"flex items-center gap-1.5",children:f}),e[41]=f,e[42]=g):g=e[42];let h;e[43]!==c?(h={color:c},e[43]=c,e[44]=h):h=e[44];let D;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==u||e[49]!==m||e[50]!==o?(D=n.isExhausted?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"font-medium",children:m}),t.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.waitSeparator")}),t.jsx("span",{className:"font-medium",children:ui(n.remainingSeconds)})]}):t.jsxs("span",{title:u,children:[t.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.predictionLabel")}),t.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=u,e[49]=m,e[50]=o,e[51]=D):D=e[51];let k;e[52]!==h||e[53]!==D?(k=t.jsx("span",{className:"typography-micro tabular-nums",style:h,children:D}),e[52]=h,e[53]=D,e[54]=k):k=e[54];let w;e[55]!==c?(w={backgroundColor:c},e[55]=c,e[56]=w):w=e[56];let E;e[57]!==m||e[58]!==w?(E=t.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:w,title:m}),e[57]=m,e[58]=w,e[59]=E):E=e[59];let N;e[60]!==k||e[61]!==E?(N=t.jsxs("div",{className:"flex items-center gap-1.5",children:[k,E]}),e[60]=k,e[61]=E,e[62]=N):N=e[62];let y;return e[63]!==N||e[64]!==S||e[65]!==g?(y=t.jsxs("div",{className:S,children:[g,N]}),e[63]=N,e[64]=S,e[65]=g,e[66]=y):y=e[66],y},cr=s=>{const e=rt.c(54),{title:n,window:a,subtitle:r,showToggle:i,toggleEnabled:o,onToggle:d}=s,c=i===void 0?!1:i,x=o===void 0?!1:o,m=Ht(Yf),p=Ht(Xf),u=Ke(Zf),S=m==="remaining"?a.remainingPercent:a.usedPercent,f=m==="remaining"?"remaining":"used";let g;e[0]!==S||e[1]!==a.valueLabel?(g=em(a.valueLabel,S),e[0]=S,e[1]=a.valueLabel,e[2]=g):g=e[2];const h=g,D=a.resetAfterFormatted??a.resetAtFormatted;let k;e[3]!==D||e[4]!==u||e[5]!==a.resetAt?(k=tm(a.resetAt,D,u),e[3]=D,e[4]=u,e[5]=a.resetAt,e[6]=k):k=e[6];const w=k;let E;e[7]!==n?(E=sm(n),e[7]=n,e[8]=E):E=e[8];const N=E;let y;e[9]!==n||e[10]!==a.resetAt||e[11]!==a.usedPercent||e[12]!==a.windowSeconds?(y=nm(a.usedPercent,a.resetAt,a.windowSeconds,n),e[9]=n,e[10]=a.resetAt,e[11]=a.usedPercent,e[12]=a.windowSeconds,e[13]=y):y=e[13];const b=y;let P;e:{if(!b||b.dailyAllocationPercent===null){P=null;break e}const Z=am(b.elapsedRatio);P=m==="remaining"?100-Z:Z}const z=P;let M;e[14]!==d||e[15]!==c||e[16]!==x?(M=c&&t.jsx(Pt,{checked:x,onChange:Z=>d?.(Z),ariaLabel:"Show in dropdown"}),e[14]=d,e[15]=c,e[16]=x,e[17]=M):M=e[17];let I;e[18]!==N?(I=t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:N}),e[18]=N,e[19]=I):I=e[19];let v;e[20]!==r?(v=r&&t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[20]=r,e[21]=v):v=e[21];let j;e[22]!==I||e[23]!==v?(j=t.jsxs("div",{className:"min-w-0 flex flex-col",children:[I,v]}),e[22]=I,e[23]=v,e[24]=j):j=e[24];let O;e[25]!==j||e[26]!==M?(O=t.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[M,j]}),e[25]=j,e[26]=M,e[27]=O):O=e[27];const T=h==="-"?"":h;let U;e[28]!==T?(U=t.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:T}),e[28]=T,e[29]=U):U=e[29];let B;e[30]!==O||e[31]!==U?(B=t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[O,U]}),e[30]=O,e[31]=U,e[32]=B):B=e[32];let Q;e[33]!==S||e[34]!==z||e[35]!==a.usedPercent?(Q=t.jsx(Jf,{percent:S,tonePercent:a.usedPercent,expectedMarkerPercent:z,className:"h-1.5"}),e[33]=S,e[34]=z,e[35]=a.usedPercent,e[36]=Q):Q=e[36];const W=w?`Resets ${w}`:"";let R;e[37]!==W?(R=t.jsx("span",{className:"typography-micro text-muted-foreground",children:W}),e[37]=W,e[38]=R):R=e[38];let Y;e[39]!==f?(Y=t.jsx("span",{className:"typography-micro text-muted-foreground",children:f}),e[39]=f,e[40]=Y):Y=e[40];let F;e[41]!==R||e[42]!==Y?(F=t.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[R,Y]}),e[41]=R,e[42]=Y,e[43]=F):F=e[43];let H;e[44]!==Q||e[45]!==F?(H=t.jsxs("div",{className:"mt-2.5",children:[Q,F]}),e[44]=Q,e[45]=F,e[46]=H):H=e[46];let X;e[47]!==b||e[48]!==p?(X=b&&p&&t.jsx("div",{className:"mt-1.5",children:t.jsx(Qf,{paceInfo:b})}),e[47]=b,e[48]=p,e[49]=X):X=e[49];let re;return e[50]!==B||e[51]!==H||e[52]!==X?(re=t.jsxs("div",{className:"py-3",children:[B,H,X]}),e[50]=B,e[51]=H,e[52]=X,e[53]=re):re=e[53],re};function Yf(s){return s.displayMode}function Xf(s){return s.showPredValues}function Zf(s){return s.timeFormatPreference}const ex=(s,e)=>{if(!s)return"-";try{return Nl(s,e,{fallback:"-"})}catch{return"-"}},tx=()=>{const{t:s}=dt(),e=Ke(j=>j.timeFormatPreference),n=Ht(j=>j.results),a=Ht(j=>j.selectedProviderId),r=Ht(j=>j.setSelectedProvider),i=Ht(j=>j.loadSettings),o=Ht(j=>j.fetchAllQuotas),d=Ht(j=>j.isLoading),c=Ht(j=>j.lastUpdated),x=Ht(j=>j.error),m=Ht(j=>j.dropdownProviderIds),p=Ht(j=>j.setDropdownProviderIds),u=Ht(j=>j.selectedModels),S=Ht(j=>j.toggleModelSelected),f=Ht(j=>j.applyDefaultSelections);If(),l.useEffect(()=>{i(),o()},[i,o]),l.useEffect(()=>{if(a||n.length===0)return;const j=n.find(O=>O.configured)?.providerId;r(j??an[0]?.id??null)},[n,a,r]);const g=n.find(j=>j.providerId===a)??null,D=an.find(j=>j.id===a)?.name??a??s("settings.usage.sidebar.title"),k=g?.usage,w=a?m.includes(a):!1,E=l.useCallback(j=>{if(!a)return;const O=j?Array.from(new Set([...m,a])):m.filter(T=>T!==a);p(O),It({usageDropdownProviders:O})},[m,a,p]),N=l.useMemo(()=>k?.models?Object.entries(k.models).map(([j,O])=>({name:j,windows:O})).filter(j=>Object.keys(j.windows.windows).length>0):[],[k?.models]);l.useEffect(()=>{a&&N.length>0&&f(a,N.map(j=>j.name))},[a,N,f]);const y=l.useMemo(()=>!a||N.length===0?new Map:Sf(N,j=>j.name,a),[N,a]),b=l.useMemo(()=>{if(!a)return[];const j=Nf(a);return kf(j)},[a]),[P,z]=l.useState(()=>({})),M=l.useCallback(j=>{z(O=>({...O,[j]:!O[j]}))},[]),I=l.useCallback(j=>{if(!a)return;S(a,j);const O=u[a]??[],U=O.includes(j)?O.filter(Q=>Q!==j):[...O,j],B={...u,[a]:U};It({usageSelectedModels:B})},[a,u,S]),v=a?u[a]??[]:[];return a?t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[t.jsx(An,{providerId:a,className:"h-5 w-5 shrink-0"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:s("settings.usage.page.header.providerUsage",{provider:D})}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:d?t.jsx("span",{className:"animate-pulse",children:s("settings.usage.page.header.refreshing")}):s("settings.usage.page.header.lastUpdated",{time:ex(c,e)})})]})]}),t.jsx("div",{"data-settings-item":"usage.header-menu",className:"mb-8 px-2",children:t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>E(!w),onKeyDown:j=>{(j.key===" "||j.key==="Enter")&&(j.preventDefault(),E(!w))},children:[t.jsx(Pt,{checked:w,onChange:E,ariaLabel:s("settings.usage.page.options.showInHeaderAria")}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.usage.page.options.showInHeader")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!g&&t.jsx("div",{className:"mb-8 px-2",children:t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.usage.page.state.noData")})}),x&&t.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[t.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:s("settings.usage.page.state.refreshFailedTitle")}),t.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x})]}),g&&!g.configured&&t.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[t.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:s("settings.usage.page.state.providerNotConfiguredTitle")}),t.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:s("settings.usage.page.state.providerNotConfiguredDescription")})]}),k?.windows&&Object.keys(k.windows).length>0&&t.jsx("div",{"data-settings-item":"usage.model-quotas",className:"mb-8",children:t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(k.windows).map(([j,O])=>t.jsx(cr,{title:j,window:O},j))})})}),N.length>0&&t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.usage.page.section.modelQuotas")})}),t.jsxs("div",{className:"space-y-3",children:[b.map(j=>{const O=y.get(j.id)??[];if(O.length===0)return null;const T=P[j.id]??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(gn,{open:!T,onOpenChange:()=>M(j.id),children:[t.jsxs(hn,{className:"flex w-full items-center justify-between py-0.5 group",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[t.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:j.label}),t.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",O.length,")"]})]}),T?t.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(fn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:O.map(U=>{const B=Object.entries(U.windows.windows);if(B.length===0)return null;const[Q,W]=B[0],R=v.includes(U.name);return t.jsx(cr,{title:Q,subtitle:Eo(U.name),window:W,showToggle:!0,toggleEnabled:R,onToggle:()=>I(U.name)},U.name)})})})]})},j.id)}),(()=>{const j=y.get(null)??[];if(j.length===0)return null;const O=P.other??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(gn,{open:!O,onOpenChange:()=>M("other"),children:[t.jsxs(hn,{className:"flex w-full items-center justify-between py-0.5 group",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[t.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:s("settings.usage.page.section.otherModels")}),t.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",j.length,")"]})]}),O?t.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(fn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:j.map(T=>{const U=Object.entries(T.windows.windows);if(U.length===0)return null;const[B,Q]=U[0],W=v.includes(T.name);return t.jsx(cr,{title:B,subtitle:Eo(T.name),window:Q,showToggle:!0,toggleEnabled:W,onToggle:()=>I(T.name)},T.name)})})})]})})})()]})]}),g?.configured&&k&&Object.keys(k.windows??{}).length===0&&N.length===0&&t.jsxs("div",{className:"mb-8 px-2",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.usage.page.state.noQuotaWindowsTitle")}),t.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:s("settings.usage.page.state.noQuotaWindowsDescription")})]})]})}):t.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:t.jsx("p",{className:"typography-body",children:s("settings.usage.page.empty.selectProvider")})})},sx="git.commit.generate",Fr=rn(s=>({selectedPromptId:sx,setSelectedPromptId:e=>{s(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),nx=s=>{const e=rt.c(23),{onItemSelect:n}=s,{t:a}=dt(),r=Fr(ax),i=Fr(rx);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 d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={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]=d):d=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={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]=c):c=e[2];let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=[o,d,c,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=x):x=e[3];const m=x;let p;e[4]!==a?(p=a("settings.magicPrompts.sidebar.title"),e[4]=a,e[5]=p):p=e[5];let u;e[6]!==p?(u=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:p}),e[6]=p,e[7]=u):u=e[7];let S;e[8]!==a?(S=a("settings.magicPrompts.sidebar.description"),e[8]=a,e[9]=S):S=e[9];let f;e[10]!==S?(f=t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:S}),e[10]=S,e[11]=f):f=e[11];let g;e[12]!==u||e[13]!==f?(g=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[u,f]}),e[12]=u,e[13]=f,e[14]=g):g=e[14];let h;e[15]!==n||e[16]!==r||e[17]!==i||e[18]!==a?(h=t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(k=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:a(k.groupKey)}),k.items.map(w=>{const E=r===w.id;return t.jsx("button",{type:"button",onClick:()=>{i(w.id),n?.()},className:de("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",E?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-ui-label truncate font-normal",children:a(w.titleKey)})},w.id)})]},k.groupKey))}),e[15]=n,e[16]=r,e[17]=i,e[18]=a,e[19]=h):h=e[19];let D;return e[20]!==h||e[21]!==g?(D=t.jsxs("div",{className:"flex h-full flex-col bg-background",children:[g,h]}),e[20]=h,e[21]=g,e[22]=D):D=e[22],D};function ax(s){return s.selectedPromptId}function rx(s){return s.setSelectedPromptId}const Ro={"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.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.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"}]}},To=(s,e)=>Object.prototype.hasOwnProperty.call(s,e),dr=s=>s.endsWith(".visible"),ix=()=>{const{t:s}=dt(),e=l.useCallback(y=>s(y),[s]),n=Fr(y=>y.selectedPromptId),[a,r]=l.useState(!0),[i,o]=l.useState({}),[d,c]=l.useState({}),[x,m]=l.useState({}),[p,u]=l.useState({}),[S,f]=l.useState(!1);l.useEffect(()=>{let y=!0;return(async()=>{r(!0);try{const P=await lm();if(!y)return;o(P)}catch(P){console.warn("Failed to load magic prompts:",P),V.error(s("settings.magicPrompts.page.toast.loadFailed"))}finally{y&&r(!1)}})(),()=>{y=!1}},[s]);const g=Ro[n]??Ro["git.commit.generate"],h=l.useCallback(y=>To(i,y)?i[y]:qa(y),[i]),D=l.useCallback(y=>d[y]??h(y),[d,h]),k=l.useCallback((y,b)=>{c(P=>P[y]===b?P:{...P,[y]:b})},[]),w=l.useCallback(async y=>{const b=D(y);if(dr(y)&&b.trim().length===0){V.error(s("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(P=>({...P,[y]:!0}));try{const P=b===qa(y)?await pi(y):await rm(y,b);o(P.overrides),V.success(s("settings.magicPrompts.page.toast.saved"))}catch(P){const z=P instanceof Error?P.message:String(P);V.error(s("settings.magicPrompts.page.toast.saveFailed"),{description:z})}finally{m(P=>({...P,[y]:!1}))}},[D,s]),E=l.useCallback(async y=>{u(b=>({...b,[y]:!0}));try{const b=await pi(y);o(b.overrides),c(P=>({...P,[y]:qa(y)})),V.success(s("settings.magicPrompts.page.toast.resetSuccess"))}catch(b){const P=b instanceof Error?b.message:String(b);V.error(s("settings.magicPrompts.page.toast.resetFailed"),{description:P})}finally{u(b=>({...b,[y]:!1}))}},[s]),N=l.useCallback(async()=>{f(!0);try{const y=await im();o(y.overrides),c({}),V.success(s("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(y){const b=y instanceof Error?y.message:String(y);V.error(s("settings.magicPrompts.page.toast.resetAllFailed"),{description:b})}finally{f(!1)}},[s]);return a?t.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[t.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":s("settings.magicPrompts.page.loading.aria")}),t.jsx("span",{className:"typography-ui",children:s("settings.magicPrompts.page.loading.text")})]}):t.jsx("div",{className:"h-full overflow-auto",children:t.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[t.jsx("div",{className:"space-y-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(g.titleKey)}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:e(g.descriptionKey)})]})]})}),t.jsx(J,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{N()},disabled:S||Object.keys(i).length===0,children:s(S?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),g.blocks.map((y,b)=>{const P=om(y.id),z=h(y.id),M=D(y.id),I=To(i,y.id),v=M!==z,j=dr(y.id)&&M.trim().length===0,O=x[y.id]===!0,T=p[y.id]===!0;return t.jsxs("section",{"data-settings-item":dr(y.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",className:b>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:e(y.titleKey)}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:P.description})]})]}),P.placeholders&&P.placeholders.length>0&&t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[s("settings.magicPrompts.page.placeholdersLabel")," ",P.placeholders.map(U=>`{{${U.key}}}`).join(", ")]})]}),t.jsx(ps,{value:M,onChange:U=>k(y.id,U.target.value),className:"min-h-[220px] font-mono text-sm"}),j&&t.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:s("settings.magicPrompts.page.validation.visiblePromptRequired")}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s(v?"settings.magicPrompts.page.status.unsavedChanges":I?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>{E(y.id)},disabled:!I||O||T,children:s(T?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),t.jsx(J,{size:"sm",onClick:()=>{w(y.id)},disabled:!v||O||T||j,children:s(O?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},y.id)})]})})},ox=s=>{const e=rt.c(89),{onItemSelect:n}=s,{t:a}=dt(),[r,i]=l.useState(null),[o,d]=l.useState(null),[c,x]=l.useState(null),{selectedSnippetName:m,snippets:p,setSelectedSnippet:u,setSnippetDraft:S,deleteSnippet:f,loadSnippets:g}=Ba(Ss(lx));let h,D;e[0]!==g?(h=()=>{g()},D=[g],e[0]=g,e[1]=h,e[2]=D):(h=e[1],D=e[2]),l.useEffect(h,D);let k;e[3]!==n||e[4]!==u||e[5]!==S||e[6]!==p?(k=async()=>{const te=new Set(p.map(cx));let ie="new-snippet",ge=1;for(;te.has(ie);)ie=`new-snippet-${ge++}`;S({name:ie,scope:"global"}),u(ie),n?.()},e[3]=n,e[4]=u,e[5]=S,e[6]=p,e[7]=k):k=e[7];const w=k;let E;e[8]!==r||e[9]!==f||e[10]!==a?(E=async()=>{if(!r)return;await f(r.name)?(V.success(a("settings.snippets.sidebar.toast.deleted")),i(null)):V.error(a("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=f,e[10]=a,e[11]=E):E=e[11];const N=E;let y;e[12]!==p?(y=[...p].sort(dx),e[12]=p,e[13]=y):y=e[13];const b=y;let P;e[14]===Symbol.for("react.memo_cache_sentinel")?(P=de("flex h-full flex-col","bg-background"),e[14]=P):P=e[14];let z;e[15]!==a?(z=a("settings.snippets.sidebar.title"),e[15]=a,e[16]=z):z=e[16];let M;e[17]!==z?(M=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:z}),e[17]=z,e[18]=M):M=e[18];let I;e[19]!==p.length||e[20]!==a?(I=a("settings.snippets.sidebar.total",{count:p.length}),e[19]=p.length,e[20]=a,e[21]=I):I=e[21];let v;e[22]!==I?(v=t.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[22]=I,e[23]=v):v=e[23];let j;e[24]!==a?(j=a("settings.snippets.sidebar.actions.create"),e[24]=a,e[25]=j):j=e[25];let O;e[26]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[26]=O):O=e[26];let T;e[27]!==w||e[28]!==j?(T=t.jsx(J,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:w,"aria-label":j,children:O}),e[27]=w,e[28]=j,e[29]=T):T=e[29];let U;e[30]!==v||e[31]!==T?(U=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[v,T]}),e[30]=v,e[31]=T,e[32]=U):U=e[32];let B;e[33]!==U||e[34]!==M?(B=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[M,U]}),e[33]=U,e[34]=M,e[35]=B):B=e[35];let Q;if(e[36]!==n||e[37]!==o||e[38]!==c||e[39]!==m||e[40]!==u||e[41]!==b||e[42]!==a){let te;e[44]!==n||e[45]!==o||e[46]!==c||e[47]!==m||e[48]!==u||e[49]!==a?(te=ie=>t.jsxs(en,{open:c===ie.name,onOpenChange:ge=>x(ge?ie.name:null),children:[t.jsxs(tn,{render:t.jsx("div",{className:de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m===ie.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ge=>{ge.preventDefault(),x(ie.name)}}),children:[t.jsxs("button",{onClick:()=>{u(ie.name),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:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",ie.name]}),t.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:a(`snippets.source.${ie.source}`)})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:ie.description||ie.content.replace(/\s+/g," ").substring(0,80)})]}),t.jsxs(us,{open:o===ie.name,onOpenChange:ge=>{ge&&x(null),d(ge?ie.name:null)},children:[t.jsx(ds,{asChild:!0,children:t.jsx(J,{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","aria-label":a("settings.snippets.sidebar.actions.more",{name:ie.name}),children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:t.jsxs(js,{onClick:ge=>{ge.stopPropagation(),i(ie)},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]})]}),t.jsx(sn,{className:"w-fit min-w-20",children:t.jsxs(Ws,{onClick:ge=>{ge.stopPropagation(),i(ie)},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]},`${ie.source}:${ie.filePath}`),e[44]=n,e[45]=o,e[46]=c,e[47]=m,e[48]=u,e[49]=a,e[50]=te):te=e[50],Q=b.map(te),e[36]=n,e[37]=o,e[38]=c,e[39]=m,e[40]=u,e[41]=b,e[42]=a,e[43]=Q}else Q=e[43];let W;e[51]!==Q?(W=t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:Q}),e[51]=Q,e[52]=W):W=e[52];const R=r!==null;let Y;e[53]===Symbol.for("react.memo_cache_sentinel")?(Y=te=>{te||i(null)},e[53]=Y):Y=e[53];let F;e[54]!==a?(F=a("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=a,e[55]=F):F=e[55];let H;e[56]!==F?(H=t.jsx(Vt,{children:F}),e[56]=F,e[57]=H):H=e[57];const X=r?.name??"";let re;e[58]!==a||e[59]!==X?(re=a("settings.snippets.sidebar.dialog.deleteDescription",{name:X}),e[58]=a,e[59]=X,e[60]=re):re=e[60];let Z;e[61]!==re?(Z=t.jsx(qt,{children:re}),e[61]=re,e[62]=Z):Z=e[62];let se;e[63]!==H||e[64]!==Z?(se=t.jsxs(_t,{children:[H,Z]}),e[63]=H,e[64]=Z,e[65]=se):se=e[65];let ce;e[66]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>i(null),e[66]=ce):ce=e[66];let oe;e[67]!==a?(oe=a("settings.common.actions.cancel"),e[67]=a,e[68]=oe):oe=e[68];let xe;e[69]!==oe?(xe=t.jsx(J,{size:"sm",variant:"ghost",onClick:ce,children:oe}),e[69]=oe,e[70]=xe):xe=e[70];let we;e[71]!==a?(we=a("settings.common.actions.delete"),e[71]=a,e[72]=we):we=e[72];let he;e[73]!==N||e[74]!==we?(he=t.jsx(J,{size:"sm",onClick:N,children:we}),e[73]=N,e[74]=we,e[75]=he):he=e[75];let Ie;e[76]!==xe||e[77]!==he?(Ie=t.jsxs(Yt,{children:[xe,he]}),e[76]=xe,e[77]=he,e[78]=Ie):Ie=e[78];let ve;e[79]!==se||e[80]!==Ie?(ve=t.jsxs(Bt,{className:"max-w-md",children:[se,Ie]}),e[79]=se,e[80]=Ie,e[81]=ve):ve=e[81];let be;e[82]!==R||e[83]!==ve?(be=t.jsx(Ut,{open:R,onOpenChange:Y,children:ve}),e[82]=R,e[83]=ve,e[84]=be):be=e[84];let ye;return e[85]!==B||e[86]!==W||e[87]!==be?(ye=t.jsxs("div",{className:P,children:[B,W,be]}),e[85]=B,e[86]=W,e[87]=be,e[88]=ye):ye=e[88],ye};function lx(s){return{selectedSnippetName:s.selectedSnippetName,snippets:s.snippets,setSelectedSnippet:s.setSelectedSnippet,setSnippetDraft:s.setSnippetDraft,deleteSnippet:s.deleteSnippet,loadSnippets:s.loadSnippets}}function cx(s){return s.name}function dx(s,e){return s.name.localeCompare(e.name)}const mx=()=>{const{t:s}=dt(),{selectedSnippetName:e,snippets:n,snippetDraft:a,setSnippetDraft:r,updateSnippet:i,createSnippet:o}=Ba(Ss(P=>({selectedSnippetName:P.selectedSnippetName,snippets:P.snippets,snippetDraft:P.snippetDraft,setSnippetDraft:P.setSnippetDraft,updateSnippet:P.updateSnippet,createSnippet:P.createSnippet}))),d=l.useMemo(()=>e?n.find(P=>P.name===e||P.aliases.includes(e))??null:null,[e,n]),c=!!(a&&a.name===e&&!d),[x,m]=l.useState(""),[p,u]=l.useState("global"),[S,f]=l.useState(""),[g,h]=l.useState(""),[D,k]=l.useState(""),[w,E]=l.useState(!1),N=l.useRef(null);l.useEffect(()=>{if(c&&a){const P={draftName:a.name||"",draftScope:a.scope||"global",description:a.description||"",aliases:(a.aliases||[]).join(", "),content:a.content||""};m(P.draftName),u(P.draftScope),f(P.description),h(P.aliases),k(P.content),N.current=P}else if(d){const P={draftName:"",draftScope:"global",description:d.description??"",aliases:d.aliases.join(", "),content:d.content};f(P.description),h(P.aliases),k(P.content),N.current=P}},[d,c,e,a]);const y=l.useMemo(()=>{const P=N.current;return P?c&&x!==P.draftName||c&&p!==P.draftScope?!0:S!==P.description||g!==P.aliases||D!==P.content:!1},[g,D,S,x,p,c]),b=async()=>{const P=c?x.trim().replace(/\s+/g,"-"):e?.trim();if(!P){V.error(s("settings.snippets.page.toast.nameRequired"));return}if(!D.trim()){V.error(s("settings.snippets.page.toast.contentRequired"));return}const z=g.split(",").map(M=>M.trim()).filter(Boolean);E(!0);try{if(!(c?await o(P,D,{aliases:z,description:S,scope:p}):await i(P,{content:D,aliases:z,description:S}))){V.error(s("settings.snippets.page.toast.saveFailed"));return}V.success(s("settings.snippets.page.toast.saved")),c&&r(null)}finally{E(!1)}};return e?t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsxs("div",{className:"mb-4 min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:c?s("settings.snippets.page.title.new"):`#${e}`}),d?t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:d.filePath}):null]}),t.jsxs("div",{className:"mb-8 space-y-3 px-2",children:[t.jsxs("div",{children:[c?t.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:"#"}),t.jsx(it,{value:x,onChange:P=>m(P.target.value),placeholder:s("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),t.jsxs(Ft,{value:p,onValueChange:P=>u(P),children:[t.jsx(Ot,{className:"w-fit min-w-[100px]",children:t.jsx(Kt,{})}),t.jsxs(Lt,{align:"end",children:[t.jsx(ht,{value:"global",children:s("settings.common.scope.global")}),t.jsx(ht,{value:"project",children:s("settings.common.scope.project")})]})]})]}):null,t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx(it,{value:S,onChange:P=>f(P.target.value),placeholder:s("settings.snippets.page.field.descriptionPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.snippets.page.field.aliases")}),t.jsx(it,{value:g,onChange:P=>h(P.target.value),placeholder:s("settings.snippets.page.field.aliasesPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]})]}),t.jsxs("div",{"data-settings-item":"snippets.content",className:"mb-2 px-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.snippets.page.field.content")}),t.jsx(ps,{value:D,onChange:P=>k(P.target.value),placeholder:s("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),t.jsx("p",{className:"mt-2 typography-meta text-muted-foreground",children:s("settings.snippets.page.hint")})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:b,disabled:w||!y,size:"xs",className:"!font-normal",children:s(w?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.snippets.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.snippets.page.empty.description")})]})})},Wl=()=>{const{t:s}=dt(),e=ut(p=>p.settingsGitmojiEnabled),n=ut(p=>p.setSettingsGitmojiEnabled),a=Um(),r=Ke(p=>p.gitChangesViewMode),i=Ke(p=>p.setGitChangesViewMode),[o,d]=l.useState(!0),c=l.useMemo(()=>[{id:"flat",label:s("settings.openchamber.git.option.flatList")},{id:"tree",label:s("settings.openchamber.git.option.treeView")}],[s]);l.useEffect(()=>{(async()=>{try{let u=null;if(!u){const S=Fs()?.settings;if(S)try{const g=(await S.load())?.settings;g&&(u={gitmojiEnabled:typeof g.gitmojiEnabled=="boolean"?g.gitmojiEnabled:void 0,gitChangesViewMode:g.gitChangesViewMode==="flat"||g.gitChangesViewMode==="tree"?g.gitChangesViewMode:void 0})}catch{}}if(!u){const S=await jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});S.ok&&(u=await S.json())}u&&(typeof u.gitmojiEnabled=="boolean"&&n(u.gitmojiEnabled),(u.gitChangesViewMode==="flat"||u.gitChangesViewMode==="tree")&&i(u.gitChangesViewMode))}catch(u){console.warn("Failed to load git settings:",u)}finally{d(!1)}})()},[i,n]);const x=l.useCallback(async p=>{n(p);try{await It({gitmojiEnabled:p})}catch(u){console.warn("Failed to save gitmoji setting:",u)}},[n]),m=l.useCallback(p=>{p!==r&&(i(p),It({gitChangesViewMode:p}))},[r,i]);return o?null:t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.git.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[t.jsxs("div",{"data-settings-item":"git.changes-view",className:"pt-1 pb-1",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.git.changesViewTitle")}),t.jsx("div",{role:"radiogroup","aria-label":s("settings.openchamber.git.changesViewAria"),className:"mt-0.5 space-y-0",children:c.map(p=>{const u=r===p.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>{m(p.id)},onKeyDown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),m(p.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Sn,{checked:u,onChange:()=>{m(p.id)},ariaLabel:s("settings.openchamber.git.optionAria",{option:p.label})}),t.jsx("span",{className:u?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:p.label})]},p.id)})})]}),t.jsxs("div",{"data-settings-item":"git.gitmoji",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{x(!e)},onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),x(!e))},children:[t.jsx(Pt,{checked:e,onChange:p=>{x(p)},ariaLabel:s("settings.openchamber.git.enableGitmojiAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.git.enableGitmoji")})]}),t.jsxs("div",{"data-settings-item":"git.gitignored-files",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":a,onClick:()=>Ya(!a),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Ya(!a))},children:[t.jsx(Pt,{checked:a,onChange:Ya,ariaLabel:s("settings.openchamber.git.showGitignoredAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.git.showGitignored")})]})]})]})},ql=()=>{const{t:s}=dt(),{isMobile:e}=Cs(),n=Fs()?.github,a=Vs(v=>v.status),r=Vs(v=>v.isLoading),i=Vs(v=>v.hasChecked),o=Vs(v=>v.refreshStatus),d=Vs(v=>v.setStatus),c=l.useCallback(async v=>{await Hs(v)},[]),[x,m]=l.useState(!1),[p,u]=l.useState(null),[S,f]=l.useState(null),g=l.useRef(null),h=l.useCallback(()=>{g.current!=null&&(window.clearInterval(g.current),g.current=null),f(null)},[]);l.useEffect(()=>((async()=>{try{i||await o(n)}catch(v){console.warn("Failed to load GitHub auth status:",v)}})(),()=>{h()}),[i,o,n,h]);const D=l.useCallback(async()=>{m(!0);try{const v=n?await n.authStart():await(async()=>{const O=await jt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),T=await O.json().catch(()=>null);if(!O.ok||!T||!("deviceCode"in T))throw new Error(T?.error||O.statusText);return T})();u(v),f(Math.max(1,v.interval)*1e3);const j=v.verificationUriComplete||v.verificationUri;c(j)}catch(v){console.error("Failed to start GitHub connect:",v),V.error(s("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[c,n,s]),k=l.useCallback(async v=>{if(n)return n.authComplete(v);const j=await jt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:v})}),O=await j.json().catch(()=>null);if(!j.ok||!O)throw new Error(O?.error||j.statusText);return O},[n]);l.useEffect(()=>{if(!(!p?.deviceCode||!S)&&g.current==null)return g.current=window.setInterval(()=>{(async()=>{try{const v=await k(p.deviceCode);if(v.connected){V.success(s("settings.github.page.toast.connected")),u(null),h(),await o(n,{force:!0});return}v.status==="slow_down"&&f(j=>j?j+5e3:5e3),(v.status==="expired_token"||v.status==="access_denied")&&(V.error(v.error||s("settings.github.page.toast.authorizationFailed")),u(null),h())}catch(v){console.warn("GitHub polling failed:",v)}})()},S),()=>{g.current!=null&&(window.clearInterval(g.current),g.current=null)}},[p,S,k,o,n,h,s]);const w=l.useCallback(async v=>{m(!0);try{if(n)await n.authSetGhCliDisabled(v);else{const j=await jt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:v})}),O=await j.json().catch(()=>null);if(!j.ok)throw new Error(O?.error||j.statusText)}V.success(s(v?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await o(n,{force:!0})}catch(j){console.error("Failed to update gh CLI setting:",j),V.error(s("settings.github.page.toast.ghCliUpdateFailed"))}finally{m(!1)}},[o,n,s]),E=l.useCallback(async()=>{m(!0);try{if(h(),u(null),n)await n.authDisconnect();else{const v=await jt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!v.ok)throw new Error(v.statusText)}V.success(s("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(v){console.error("Failed to disconnect GitHub:",v),V.error(s("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[o,n,h,s]),N=l.useCallback(async v=>{if(v){m(!0);try{const j=n?await n.authActivate(v):await(async()=>{const O=await jt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:v})}),T=await O.json().catch(()=>null);if(!O.ok||!T)throw new Error(T?.error||O.statusText);return T})();d(j),V.success(s("settings.github.page.toast.accountSwitched"))}catch(j){console.error("Failed to switch GitHub account:",j),V.error(s("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,d,s]);if(r)return null;const y=!!a?.connected,b=a?.user,z=(a?.accounts??[]).filter(v=>!v.current),M=a?.ghCli??null,I=M?.active?s("settings.github.page.accountSource.cli"):s("settings.github.page.accountSource.oauth");return t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.github.page.oauth.title")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.github.page.tooltip.connectAccount")})]})]})}),t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[y?t.jsxs("div",{className:de("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:de("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[b?.avatarUrl?t.jsx("img",{src:b.avatarUrl,alt:b.login?s("settings.github.page.avatarAlt.withLogin",{login:b.login}):s("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"}):t.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:b?.name?.trim()||b?.login||"GitHub"}),t.jsxs("div",{className:de("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[t.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"font-mono",children:b?.login||s("settings.github.page.label.unknownUser")}),b?.email&&t.jsx("span",{className:"opacity-50",children:"•"}),b?.email&&t.jsx("span",{children:b.email}),t.jsx("span",{className:"opacity-50",children:"•"}),t.jsx("span",{children:I})]}),a?.scope&&t.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:s("settings.github.page.label.scopes",{value:a.scope})}),M?.active&&t.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:s("settings.github.page.ghCli.activeDescription")})]})]}),M?.active?t.jsx(J,{size:"sm",variant:"outline",onClick:()=>w(!0),disabled:x,className:de(e?"w-full":void 0),children:s("settings.github.page.ghCli.actions.disable")}):t.jsx(J,{size:"sm",variant:"outline",onClick:E,disabled:x,className:de("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:s("settings.github.page.actions.disconnect")})]}):t.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[t.jsx("div",{className:"flex min-w-0 flex-col",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.github.page.status.notConnected")})}),t.jsx(J,{size:"sm",variant:"default",onClick:D,disabled:x,children:s("settings.github.page.actions.connect")})]}),z.length>0&&t.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[t.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:s("settings.github.page.label.otherAccounts")}),t.jsx("div",{className:"space-y-1",children:z.map(v=>{const j=v.user,O=v.source==="gh-cli"?s("settings.github.page.accountSource.cli"):s("settings.github.page.accountSource.oauth");return t.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:[t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[j?.avatarUrl?t.jsx("img",{src:j.avatarUrl,alt:j.login?s("settings.github.page.avatarAlt.withLogin",{login:j.login}):s("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"}):t.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:t.jsx(A,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),t.jsxs("div",{className:"min-w-0 flex flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j?.name?.trim()||j?.login||"GitHub"}),j?.login&&t.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[t.jsx("span",{className:"font-mono",children:j.login}),t.jsx("span",{className:"mx-1 opacity-50",children:"·"}),t.jsx("span",{children:O})]})]})]}),t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>N(v.id),disabled:x,children:s("settings.github.page.actions.switchTo")})]},v.id)})})]})]}),y&&t.jsx("div",{className:"mt-2 px-2 pb-2",children:t.jsx(J,{size:"sm",variant:"outline",onClick:D,disabled:x,className:de(e?"w-full":void 0),children:s("settings.github.page.actions.addAccount")})}),p&&t.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("h4",{className:"typography-ui-label text-foreground",children:s("settings.github.page.flow.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.github.page.flow.description")})]}),t.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[t.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:p.userCode}),t.jsx(J,{size:"sm",asChild:!0,children:t.jsx("a",{href:p.verificationUriComplete||p.verificationUri,target:"_blank",rel:"noopener noreferrer",children:s("settings.github.page.actions.openGithub")})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[t.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:s("settings.github.page.flow.waiting")}),t.jsx(J,{size:"sm",variant:"ghost",disabled:x,onClick:()=>{h(),u(null)},children:s("settings.common.actions.cancel")})]})]}),M?.available&&!M?.active&&(!M.user||M.disabled)&&t.jsxs("div",{className:"mt-6",children:[t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground mb-3 px-1",children:s("settings.github.page.ghCli.title")}),t.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:t.jsxs("div",{className:de("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:de("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[M.user?.avatarUrl?t.jsx("img",{src:M.user.avatarUrl,alt:M.user.login?s("settings.github.page.avatarAlt.withLogin",{login:M.user.login}):s("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"}):t.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:t.jsx(A,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[!M.disabled&&M.user&&t.jsx("div",{className:"typography-ui-label text-foreground truncate",children:M.user.name?.trim()||M.user.login||"GitHub"}),!M.disabled&&M.user?.login&&t.jsxs("div",{className:de("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[t.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"font-mono",children:M.user.login}),M.user.email&&t.jsx("span",{className:"opacity-50",children:"•"}),M.user.email&&t.jsx("span",{children:M.user.email})]}),t.jsx("div",{className:de("typography-meta text-muted-foreground",M.disabled?"opacity-60":void 0),children:M.disabled?s("settings.github.page.ghCli.disabledDescription"):s("settings.github.page.ghCli.fallbackDescription")})]})]}),t.jsx(J,{size:"sm",variant:"outline",onClick:()=>w(!M.disabled),disabled:x,className:de(e?"w-full":void 0),children:M.disabled?s("settings.github.page.ghCli.actions.enable"):s("settings.github.page.ghCli.actions.disable")})]})})]})]})},Fo=[{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)"}],ux=[{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"}],px=({open:s,onOpenChange:e,profileId:n,importData:a})=>{const{t:r}=dt(),i=ks(Z=>Z.getProfileById),o=ks(Z=>Z.createProfile),d=ks(Z=>Z.updateProfile),c=ks(Z=>Z.deleteProfile),x=l.useMemo(()=>n&&n!=="new"&&!a?i(n):null,[n,i,a]),m=n==="new"||a!=null,p=n==="global",[u,S]=l.useState(""),[f,g]=l.useState(""),[h,D]=l.useState(""),[k,w]=l.useState("ssh"),[E,N]=l.useState(""),[y,b]=l.useState(!1),[P,z]=l.useState(""),[M,I]=l.useState(""),[v,j]=l.useState("keyword"),[O,T]=l.useState("branch"),[U,B]=l.useState(!1),[Q,W]=l.useState(!1),[R,Y]=l.useState(!1);l.useEffect(()=>{if(s){if(a){const Z=a.host.split("/"),se=Z.length>=3?Z[Z.length-1]:a.host;S(se),g(a.username),D(""),w("token"),N(""),b(!1),z(""),I(a.host),j("string"),T("code")}else if(m)S(""),g(""),D(""),w("ssh"),N(""),b(!1),z(""),I(""),j("keyword"),T("branch");else if(x)S(x.name),g(x.userName),D(x.userEmail),w(x.authType||"ssh"),N(x.sshKey||""),b(x.signCommits===!0),z(x.signingKey||""),I(x.host||""),j(x.color||"keyword"),T(x.icon||"branch");else if(p){const Z=i("global");Z&&(S(Z.name),g(Z.userName),D(Z.userEmail),w(Z.authType||"ssh"),N(Z.sshKey||""),b(!1),z(""),I(Z.host||""),j(Z.color||"keyword"),T(Z.icon||"branch"))}}},[s,n,x,m,a,p,i]);const F=async()=>{if(!f.trim()||!h.trim()){V.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(k==="token"&&!M.trim()){V.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(y&&!P.trim()){V.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}B(!0);try{const Z={name:u.trim()||f.trim(),userName:f.trim(),userEmail:h.trim(),authType:k,sshKey:k==="ssh"&&E.trim()||null,signCommits:y,signingKey:P.trim()||null,host:k==="token"&&M.trim()||null,color:v,icon:O};let se;if(m)se=await o(Z);else if(n)se=await d(n,Z);else return;se?(V.success(r(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):V.error(r(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(Z){console.error("Error saving profile:",Z),V.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{B(!1)}},H=async()=>{if(!(!n||m)){Y(!0);try{await c(n)?(V.success(r("settings.gitIdentities.editor.toast.profileDeleted")),W(!1),e(!1)):V.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(Z){console.error("Error deleting profile:",Z),V.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{Y(!1)}}},X=l.useMemo(()=>Fo.find(se=>se.key===v)?.cssVar||"var(--syntax-keyword)",[v]),re=a?r("settings.gitIdentities.editor.title.importCredential"):m?r("settings.gitIdentities.editor.title.newIdentity"):p?r("settings.gitIdentities.editor.title.globalIdentity"):x?.name||r("settings.gitIdentities.editor.title.editIdentity");return t.jsxs(t.Fragment,{children:[t.jsx(Ut,{open:s,onOpenChange:e,children:t.jsxs(Bt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:re}),t.jsx(qt,{children:r(p?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),t.jsxs("div",{className:"space-y-5 py-2",children:[!p&&t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"typography-ui-label text-foreground block mb-1.5",children:r("settings.gitIdentities.editor.field.profileName")}),t.jsx(it,{value:u,onChange:Z=>S(Z.target.value),placeholder:r("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.color")}),t.jsx("div",{className:"flex gap-1.5",children:Fo.map(Z=>t.jsx("button",{type:"button",onClick:()=>j(Z.key),className:de("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",v===Z.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:Z.cssVar},title:Z.label},Z.key))})]}),t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.icon")}),t.jsx("div",{className:"flex gap-1.5",children:ux.map(Z=>{const se=Z.Icon;return t.jsx("button",{type:"button",onClick:()=>T(Z.key),className:de("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",O===Z.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:Z.label,children:t.jsx(A,{name:se,className:"w-3.5 h-3.5",style:{color:O===Z.key?X:"var(--surface-muted-foreground)"}})},Z.key)})})]})]}),!p&&t.jsx("div",{className:"border-t border-border/40"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.userName")}),!p&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),t.jsx(it,{value:f,onChange:Z=>g(Z.target.value),placeholder:r("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!p,readOnly:p,disabled:p,className:"h-8"})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.emailAddress")}),!p&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),t.jsx(it,{type:"email",value:h,onChange:Z=>D(Z.target.value),placeholder:r("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!p,readOnly:p,disabled:p,className:"h-8"})]})]}),!p&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"border-t border-border/40"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.authMethod")}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsxs(J,{size:"sm",type:"button",variant:"chip","aria-pressed":k==="ssh",onClick:()=>w("ssh"),children:[t.jsx(A,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),t.jsxs(J,{size:"sm",type:"button",variant:"chip","aria-pressed":k==="token",onClick:()=>w("token"),children:[t.jsx(A,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.gitIdentities.editor.field.authToken")]})]})]}),k==="ssh"&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.sshKeyPath")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),t.jsx(it,{value:E,onChange:Z=>N(Z.target.value),placeholder:r("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),t.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(Pt,{checked:y,onChange:b,ariaLabel:r("settings.gitIdentities.editor.field.signCommits")}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.signCommits")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:r("settings.gitIdentities.editor.section.commitSigning")})]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.signingKey")})}),t.jsx(it,{value:P,onChange:Z=>z(Z.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!y,className:"h-8 font-mono text-xs"})]})]}),k==="token"&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.host")}),t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]})]}),t.jsx(it,{value:M,onChange:Z=>I(Z.target.value),placeholder:r("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),t.jsxs(Yt,{className:"gap-2",children:[!p&&!m&&t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>W(!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:[t.jsx(A,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.common.actions.delete")]}),t.jsx(J,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:r(p?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!p&&t.jsx(J,{size:"sm",onClick:F,disabled:U,children:r(U?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),t.jsx(Ut,{open:Q,onOpenChange:Z=>{R||W(Z)},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:r("settings.gitIdentities.page.deleteDialog.title")}),t.jsx(qt,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:x?.name||u})})]}),t.jsxs(Yt,{children:[t.jsx(J,{variant:"ghost",onClick:()=>W(!1),disabled:R,children:r("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",variant:"destructive",onClick:()=>{H()},disabled:R,children:r("settings.common.actions.delete")})]})]})})]})},gx={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},hx={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},fx=()=>{const s=rt.c(118),{t:e}=dt(),{profiles:n,globalIdentity:a,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:o,loadGlobalIdentity:d,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:x,setDefaultGitIdentityId:m,getUnimportedCredentials:p}=ks(Ss(bx)),[u,S]=l.useState(!1),[f,g]=l.useState(null),[h,D]=l.useState(null),[k,w]=l.useState(null),[E,N]=l.useState(!1);let y,b;s[0]!==x||s[1]!==c||s[2]!==d||s[3]!==o?(y=()=>{o(),d(),c(),x()},b=[o,d,c,x],s[0]=x,s[1]=c,s[2]=d,s[3]=o,s[4]=y,s[5]=b):(y=s[4],b=s[5]),l.useEffect(y,b);let P,z,M,I,v,j,O,T,U,B,Q,W,R,Y;if(s[6]!==r||s[7]!==k||s[8]!==i||s[9]!==p||s[10]!==a||s[11]!==n||s[12]!==m||s[13]!==e){const De=p();let Ae;s[28]===Symbol.for("react.memo_cache_sentinel")?(Ae=(Ne,Ee)=>{g(Ne),D(Ee??null),S(!0)},s[28]=Ae):Ae=s[28];const Pe=Ae;let Re;s[29]!==r||s[30]!==m||s[31]!==e?(Re=async Ne=>{const Ee=r===Ne?null:Ne;if(!await m(Ee)){V.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}V.success(e(Ee?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},s[29]=r,s[30]=m,s[31]=e,s[32]=Re):Re=s[32];const Oe=Re;let $e;s[33]!==k||s[34]!==i||s[35]!==e?($e=async()=>{if(!k)return;N(!0),await i(k.id)?(V.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:k.name})),w(null)):V.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),N(!1)},s[33]=k,s[34]=i,s[35]=e,s[36]=$e):$e=s[36],z=$e,P=Jt,v="h-full",j="w-full bg-background",M="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",s[37]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx("div",{"data-settings-item":"git.github-account",children:t.jsx(ql,{})}),s[37]=I):I=s[37],W="git.identities",R="border-t border-border/40 pt-6";let Be;s[38]!==e?(Be=e("settings.gitIdentities.page.section.title"),s[38]=e,s[39]=Be):Be=s[39];let Le;s[40]!==Be?(Le=t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:Be})}),s[40]=Be,s[41]=Le):Le=s[41];let Ue,le;s[42]===Symbol.for("react.memo_cache_sentinel")?(Ue=()=>Pe("new"),le=t.jsx(A,{name:"add",className:"w-3.5 h-3.5 mr-1"}),s[42]=Ue,s[43]=le):(Ue=s[42],le=s[43]);let q;s[44]!==e?(q=e("settings.common.badge.new"),s[44]=e,s[45]=q):q=s[45];let me;s[46]!==q?(me=t.jsxs(J,{size:"sm",variant:"outline",onClick:Ue,children:[le," ",q]}),s[46]=q,s[47]=me):me=s[47],s[48]!==Le||s[49]!==me?(Y=t.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[Le,me]}),s[48]=Le,s[49]=me,s[50]=Y):Y=s[50],O="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",T=a&&t.jsx(Oo,{profile:a,isDefault:r==="global",onEdit:()=>Pe("global"),onToggleDefault:()=>Oe("global"),isReadOnly:!0,hasBorder:n.length>0||De.length>0}),U=n.map((Ne,Ee)=>t.jsx(Oo,{profile:Ne,isDefault:r===Ne.id,onEdit:()=>Pe(Ne.id),onToggleDefault:()=>Oe(Ne.id),onDelete:()=>w(Ne),hasBorder:Ee<n.length-1||De.length>0},Ne.id)),B=!a&&n.length===0&&De.length===0&&t.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),t.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),Q=De.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:t.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),De.map((Ne,Ee)=>t.jsx(xx,{credential:Ne,onImport:()=>Pe("new",{host:Ne.host,username:Ne.username}),hasBorder:Ee<De.length-1},`${Ne.host}-${Ne.username}`))]}),s[6]=r,s[7]=k,s[8]=i,s[9]=p,s[10]=a,s[11]=n,s[12]=m,s[13]=e,s[14]=P,s[15]=z,s[16]=M,s[17]=I,s[18]=v,s[19]=j,s[20]=O,s[21]=T,s[22]=U,s[23]=B,s[24]=Q,s[25]=W,s[26]=R,s[27]=Y}else P=s[14],z=s[15],M=s[16],I=s[17],v=s[18],j=s[19],O=s[20],T=s[21],U=s[22],B=s[23],Q=s[24],W=s[25],R=s[26],Y=s[27];let F;s[51]!==O||s[52]!==T||s[53]!==U||s[54]!==B||s[55]!==Q?(F=t.jsxs("div",{className:O,children:[T,U,B,Q]}),s[51]=O,s[52]=T,s[53]=U,s[54]=B,s[55]=Q,s[56]=F):F=s[56];let H;s[57]!==F||s[58]!==W||s[59]!==R||s[60]!==Y?(H=t.jsxs("div",{"data-settings-item":W,className:R,children:[Y,F]}),s[57]=F,s[58]=W,s[59]=R,s[60]=Y,s[61]=H):H=s[61];let X;s[62]===Symbol.for("react.memo_cache_sentinel")?(X=t.jsx(Wl,{}),s[62]=X):X=s[62];let re;s[63]!==M||s[64]!==I||s[65]!==H?(re=t.jsxs("div",{className:M,children:[I,H,X]}),s[63]=M,s[64]=I,s[65]=H,s[66]=re):re=s[66];let Z;s[67]!==P||s[68]!==v||s[69]!==j||s[70]!==re?(Z=t.jsx(P,{outerClassName:v,className:j,children:re}),s[67]=P,s[68]=v,s[69]=j,s[70]=re,s[71]=Z):Z=s[71];let se;s[72]!==h||s[73]!==u||s[74]!==f?(se=t.jsx(px,{open:u,onOpenChange:S,profileId:f,importData:h}),s[72]=h,s[73]=u,s[74]=f,s[75]=se):se=s[75];const ce=k!==null;let oe;s[76]!==E?(oe=De=>{E||De||w(null)},s[76]=E,s[77]=oe):oe=s[77];let xe;s[78]!==e?(xe=e("settings.gitIdentities.page.deleteDialog.title"),s[78]=e,s[79]=xe):xe=s[79];let we;s[80]!==xe?(we=t.jsx(Vt,{children:xe}),s[80]=xe,s[81]=we):we=s[81];const he=k?.name??"";let Ie;s[82]!==e||s[83]!==he?(Ie=e("settings.gitIdentities.page.deleteDialog.description",{name:he}),s[82]=e,s[83]=he,s[84]=Ie):Ie=s[84];let ve;s[85]!==Ie?(ve=t.jsx(qt,{children:Ie}),s[85]=Ie,s[86]=ve):ve=s[86];let be;s[87]!==we||s[88]!==ve?(be=t.jsxs(_t,{children:[we,ve]}),s[87]=we,s[88]=ve,s[89]=be):be=s[89];let ye;s[90]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>w(null),s[90]=ye):ye=s[90];let te;s[91]!==e?(te=e("settings.common.actions.cancel"),s[91]=e,s[92]=te):te=s[92];let ie;s[93]!==E||s[94]!==te?(ie=t.jsx(J,{variant:"ghost",onClick:ye,disabled:E,children:te}),s[93]=E,s[94]=te,s[95]=ie):ie=s[95];let ge;s[96]!==z?(ge=()=>{z()},s[96]=z,s[97]=ge):ge=s[97];let _;s[98]!==e?(_=e("settings.common.actions.delete"),s[98]=e,s[99]=_):_=s[99];let ee;s[100]!==E||s[101]!==ge||s[102]!==_?(ee=t.jsx(J,{size:"sm",variant:"destructive",onClick:ge,disabled:E,children:_}),s[100]=E,s[101]=ge,s[102]=_,s[103]=ee):ee=s[103];let ne;s[104]!==ie||s[105]!==ee?(ne=t.jsxs(Yt,{children:[ie,ee]}),s[104]=ie,s[105]=ee,s[106]=ne):ne=s[106];let ue;s[107]!==be||s[108]!==ne?(ue=t.jsxs(Bt,{className:"max-w-md",children:[be,ne]}),s[107]=be,s[108]=ne,s[109]=ue):ue=s[109];let Me;s[110]!==ce||s[111]!==oe||s[112]!==ue?(Me=t.jsx(Ut,{open:ce,onOpenChange:oe,children:ue}),s[110]=ce,s[111]=oe,s[112]=ue,s[113]=Me):Me=s[113];let ke;return s[114]!==Z||s[115]!==se||s[116]!==Me?(ke=t.jsxs(t.Fragment,{children:[Z,se,Me]}),s[114]=Z,s[115]=se,s[116]=Me,s[117]=ke):ke=s[117],ke},Oo=s=>{const e=rt.c(56),{profile:n,isDefault:a,onEdit:r,onToggleDefault:i,onDelete:o,isReadOnly:d,hasBorder:c}=s,{t:x}=dt(),[m,p]=l.useState(!1),u=gx[n.icon||"branch"]||"git-branch",S=hx[n.color||""],f=n.authType||"ssh";let g;e[0]!==r?(g=H=>{H.currentTarget===H.target&&(H.key!=="Enter"&&H.key!==" "||(H.preventDefault(),r()))},e[0]=r,e[1]=g):g=e[1];const h=g;let D;e[2]!==a||e[3]!==d||e[4]!==o||e[5]!==i||e[6]!==x?(D=H=>t.jsxs(t.Fragment,{children:[t.jsx(H,{onClick:X=>{X.stopPropagation(),i()},children:x(a?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!d&&o&&t.jsxs(H,{onClick:X=>{X.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),x("settings.common.actions.delete")]})]}),e[2]=a,e[3]=d,e[4]=o,e[5]=i,e[6]=x,e[7]=D):D=e[7];const k=D,w=c&&"border-b border-[var(--surface-subtle)]";let E;e[8]!==w?(E=de("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",w),e[8]=w,e[9]=E):E=e[9];let N;e[10]===Symbol.for("react.memo_cache_sentinel")?(N=H=>{H.preventDefault(),p(!0)},e[10]=N):N=e[10];let y;e[11]!==h||e[12]!==r||e[13]!==E?(y=t.jsx("div",{className:E,onClick:r,role:"button",tabIndex:0,onKeyDown:h,onContextMenu:N}),e[11]=h,e[12]=r,e[13]=E,e[14]=y):y=e[14];let b;e[15]!==S?(b={color:S},e[15]=S,e[16]=b):b=e[16];let P;e[17]!==u||e[18]!==b?(P=t.jsx(A,{name:u,className:"w-4 h-4 shrink-0",style:b}),e[17]=u,e[18]=b,e[19]=P):P=e[19];let z;e[20]!==n.name?(z=t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[20]=n.name,e[21]=z):z=e[21];let M;e[22]!==f?(M=t.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[22]=f,e[23]=M):M=e[23];let I;e[24]!==a||e[25]!==x?(I=a&&t.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:x("settings.gitIdentities.page.badge.default")}),e[24]=a,e[25]=x,e[26]=I):I=e[26];let v;e[27]!==d||e[28]!==x?(v=d&&t.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:x("settings.agents.sidebar.badge.system")}),e[27]=d,e[28]=x,e[29]=v):v=e[29];let j;e[30]!==M||e[31]!==I||e[32]!==v||e[33]!==z?(j=t.jsxs("div",{className:"flex items-center gap-1.5",children:[z,M,I,v]}),e[30]=M,e[31]=I,e[32]=v,e[33]=z,e[34]=j):j=e[34];const O=f==="token"&&n.host?n.host:n.userEmail;let T;e[35]!==O?(T=t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:O}),e[35]=O,e[36]=T):T=e[36];let U;e[37]!==j||e[38]!==T?(U=t.jsxs("div",{className:"min-w-0",children:[j,T]}),e[37]=j,e[38]=T,e[39]=U):U=e[39];let B;e[40]!==U||e[41]!==P?(B=t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[P,U]}),e[40]=U,e[41]=P,e[42]=B):B=e[42];let Q;e[43]===Symbol.for("react.memo_cache_sentinel")?(Q=t.jsx(ds,{asChild:!0,children:t.jsx(J,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:yx,children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=Q):Q=e[43];let W;e[44]!==k?(W=t.jsxs(us,{children:[Q,t.jsx(ms,{align:"end",className:"w-fit min-w-28",children:k(js)})]}),e[44]=k,e[45]=W):W=e[45];let R;e[46]!==B||e[47]!==W||e[48]!==y?(R=t.jsxs(tn,{render:y,children:[B,W]}),e[46]=B,e[47]=W,e[48]=y,e[49]=R):R=e[49];let Y;e[50]!==k?(Y=t.jsx(sn,{className:"w-fit min-w-28",children:k(Ws)}),e[50]=k,e[51]=Y):Y=e[51];let F;return e[52]!==m||e[53]!==R||e[54]!==Y?(F=t.jsxs(en,{open:m,onOpenChange:p,children:[R,Y]}),e[52]=m,e[53]=R,e[54]=Y,e[55]=F):F=e[55],F},xx=s=>{const e=rt.c(21),{credential:n,onImport:a,hasBorder:r}=s,{t:i}=dt();let o;e[0]!==n.host?(o=n.host.split("/"),e[0]=n.host,e[1]=o):o=e[1];const d=o,c=d.length>=3?d[d.length-1]:n.host,x=n.host.includes("/"),m=r&&"border-b border-[var(--surface-subtle)]";let p;e[2]!==m?(p=de("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]=p):p=e[3];let u;e[4]!==c?(u=t.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=u):u=e[5];const S=x?n.host:n.username;let f;e[6]!==S?(f=t.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:S}),e[6]=S,e[7]=f):f=e[7];let g;e[8]!==u||e[9]!==f?(g=t.jsxs("div",{className:"min-w-0",children:[u,f]}),e[8]=u,e[9]=f,e[10]=g):g=e[10];let h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(A,{name:"download",className:"h-3 w-3"}),e[11]=h):h=e[11];let D;e[12]!==i?(D=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=D):D=e[13];let k;e[14]!==a||e[15]!==D?(k=t.jsxs(J,{size:"sm",variant:"ghost",onClick:a,className:"gap-1 shrink-0",children:[h,D]}),e[14]=a,e[15]=D,e[16]=k):k=e[16];let w;return e[17]!==k||e[18]!==p||e[19]!==g?(w=t.jsxs("div",{className:p,children:[g,k]}),e[17]=k,e[18]=p,e[19]=g,e[20]=w):w=e[20],w};function bx(s){return{profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,deleteProfile:s.deleteProfile,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDiscoveredCredentials:s.loadDiscoveredCredentials,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId,setDefaultGitIdentityId:s.setDefaultGitIdentityId,getUnimportedCredentials:s.getUnimportedCredentials}}function yx(s){return s.stopPropagation()}const Gl=()=>{const s=cm();return{displayMode:s,installed:s!=="browser",browserTab:s==="browser"}},vx=()=>{const s=rt.c(2),[e,n]=l.useState(jx);let a,r;return s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{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(Gl())};o();for(const d of i)typeof d.addEventListener=="function"?d.addEventListener("change",o):typeof d.addListener=="function"&&d.addListener(o);return window.addEventListener("appinstalled",o),window.addEventListener("focus",o),()=>{for(const d of i)typeof d.removeEventListener=="function"?d.removeEventListener("change",o):typeof d.removeListener=="function"&&d.removeListener(o);window.removeEventListener("appinstalled",o),window.removeEventListener("focus",o)}},r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),l.useEffect(a,r),e};function jx(){return Gl()}const wx=[{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"}],Nx=[{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"}],kx=[{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"}],Vn="OpenChamber - AI Coding Assistant",Lo=[{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"}],zo=[{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"}],Sx=[{value:"default",labelKey:"settings.openchamber.visual.option.mobileLayout.default"},{value:"new",labelKey:"settings.openchamber.visual.option.mobileLayout.new"}],mr=s=>s==="portrait"||s==="landscape"?s:"system",Cx=[{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"}],Px=[{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"}],Ko=[{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"}],Ix=[{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"}],$o=[{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"}],Uo=[{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"}],Dx=s=>s==="markdown"?"markdown":"plain",Gr=({visibleSettings:s})=>{const{locale:e,locales:n,setLocale:a,label:r,t:i}=dt(),o=l.useCallback(C=>i(C),[i]),{isMobile:d}=Cs(),{browserTab:c}=vx(),x=Bm(),m=Ke(C=>C.showReasoningTraces),p=Ke(C=>C.setShowReasoningTraces),u=Ke(C=>C.collapsibleThinkingBlocks),S=Ke(C=>C.setCollapsibleThinkingBlocks),f=Ke(C=>C.mermaidRenderingMode),g=Ke(C=>C.setMermaidRenderingMode),h=Ke(C=>C.userMessageRenderingMode),D=Ke(C=>C.setUserMessageRenderingMode),k=Ke(C=>C.collapsibleUserMessages),w=Ke(C=>C.setCollapsibleUserMessages),E=Ke(C=>C.stickyUserHeader),N=Ke(C=>C.setStickyUserHeader),y=Ke(C=>C.expandedEditorToolbar),b=Ke(C=>C.setExpandedEditorToolbar),P=Ke(C=>C.wideChatLayoutEnabled),z=Ke(C=>C.setWideChatLayoutEnabled),M=Ke(C=>C.chatRenderMode),I=Ke(C=>C.setChatRenderMode),v=Ke(C=>C.activityRenderMode),j=Ke(C=>C.setActivityRenderMode),O=Ke(C=>C.fontSize),T=Ke(C=>C.setFontSize),U=Ke(C=>C.terminalFontSize),B=Ke(C=>C.setTerminalFontSize),Q=Ke(C=>C.uiFont),W=Ke(C=>C.setUiFont),R=Ke(C=>C.monoFont),Y=Ke(C=>C.setMonoFont),F=Ke(C=>C.padding),H=Ke(C=>C.setPadding),X=Ke(C=>C.inputBarOffset),re=Ke(C=>C.setInputBarOffset),Z=Ke(C=>C.mobileKeyboardMode),se=Ke(C=>C.setMobileKeyboardMode),ce=Ke(C=>C.diffLayoutPreference),oe=Ke(C=>C.setDiffLayoutPreference),xe=Ke(C=>C.showTerminalQuickKeysOnDesktop),we=Ke(C=>C.setShowTerminalQuickKeysOnDesktop),he=Ke(C=>C.fileEditorKeymap),Ie=Ke(C=>C.setFileEditorKeymap),ve=ji(C=>C.queueModeEnabled),be=ji(C=>C.setQueueMode),ye=Ke(C=>C.persistChatDraft),te=Ke(C=>C.setPersistChatDraft),ie=Ke(C=>C.inputSpellcheckEnabled),ge=Ke(C=>C.setInputSpellcheckEnabled),_=Ke(C=>C.showToolFileIcons),ee=Ke(C=>C.setShowToolFileIcons),ne=Ke(C=>C.showTurnChangedFiles),ue=Ke(C=>C.setShowTurnChangedFiles),Me=Ke(C=>C.showExpandedBashTools),ke=Ke(C=>C.setShowExpandedBashTools),De=Ke(C=>C.showExpandedEditTools),Ae=Ke(C=>C.setShowExpandedEditTools),Pe=Ke(C=>C.timeFormatPreference),Re=Ke(C=>C.setTimeFormatPreference),Oe=Ke(C=>C.weekStartPreference),$e=Ke(C=>C.setWeekStartPreference),Be=Ke(C=>C.showSplitAssistantMessageActions),Le=Ke(C=>C.setShowSplitAssistantMessageActions),Ue=ut(C=>C.settingsMessageStreamTransport),le=ut(C=>C.setSettingsMessageStreamTransport),q=ut(C=>C.settingsDefaultFileViewerPreview),me=ut(C=>C.setSettingsDefaultFileViewerPreview),Ne=Ke(C=>C.isSettingsDialogOpen),{themeMode:Ee,setThemeMode:Ce,availableThemes:He,customThemesLoading:G,reloadCustomThemes:$,lightThemeId:fe,darkThemeId:L,setLightThemePreference:Fe,setDarkThemePreference:Je}=Ua(),[Xe,et]=l.useState(!1),at=l.useMemo(()=>fs()&&typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancySupported===!0,[]),lt=typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancy===!0,[Ze,We]=l.useState(lt),[pt,pe]=l.useState(!1),[st,nt]=l.useState(0),Ge=Ke(C=>C.reportUsage),ft=Ke(C=>C.setReportUsage),wt=l.useCallback(C=>{ft(C),It({reportUsage:C})},[ft]),Ct=Ne&&(s?s.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!Ct)return;let C=null,gt=Date.now();const zt=()=>{const Is=Date.now();Is-gt>=420&&(nt(zs=>(zs+1)%24),gt=Is),C=requestAnimationFrame(zt)};(typeof document>"u"||document.visibilityState==="visible")&&(C=requestAnimationFrame(zt));const ss=()=>{document.visibilityState==="visible"&&C===null?C=requestAnimationFrame(zt):document.visibilityState!=="visible"&&C!==null&&(cancelAnimationFrame(C),C=null)};return document.addEventListener("visibilitychange",ss),()=>{document.removeEventListener("visibilitychange",ss),C!==null&&cancelAnimationFrame(C)}},[Ct]);const ae=l.useCallback(C=>{D(C),It({userMessageRenderingMode:C})},[D]),Ve=l.useCallback(C=>{N(C),It({stickyUserHeader:C})},[N]),tt=l.useCallback(C=>{b(C),It({expandedEditorToolbar:C})},[b]),Ye=l.useCallback(C=>{w(C),It({collapsibleUserMessages:C})},[w]),bt=l.useCallback(C=>{z(C),It({wideChatLayoutEnabled:C})},[z]),ze=l.useCallback(C=>{Le(C),It({showSplitAssistantMessageActions:C})},[Le]),_e=l.useCallback(C=>{ge(C),It({inputSpellcheckEnabled:C})},[ge]),ot=l.useCallback(C=>{I(C),It({chatRenderMode:C})},[I]),yt=l.useCallback(C=>{le(C),It({messageStreamTransport:C})},[le]),Mt=l.useCallback(C=>{j(C),It({activityRenderMode:C})},[j]),Qt=l.useCallback(C=>{g(C),It({mermaidRenderingMode:C})},[g]),Xt=l.useCallback(C=>{ee(C),It({showToolFileIcons:C})},[ee]),rs=l.useCallback(C=>{ue(C),It({showTurnChangedFiles:C})},[ue]),Wt=l.useCallback(C=>{me(C),It({defaultFileViewerPreview:C}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:C}}))},[me]),Se=l.useCallback(C=>{ke(C),It({showExpandedBashTools:C})},[ke]),vt=l.useCallback(C=>{Ae(C),It({showExpandedEditTools:C})},[Ae]),Nt=l.useCallback(C=>{Re(C),It({timeFormatPreference:C})},[Re]),ct=l.useCallback(C=>{$e(C),It({weekStartPreference:C})},[$e]),St=l.useMemo(()=>He.filter(C=>C.metadata.variant==="light").sort((C,gt)=>C.metadata.name.localeCompare(gt.metadata.name)),[He]),$t=l.useMemo(()=>He.filter(C=>C.metadata.variant==="dark").sort((C,gt)=>C.metadata.name.localeCompare(gt.metadata.name)),[He]),bs=l.useMemo(()=>St.find(C=>C.metadata.id===fe)??St[0],[St,fe]),ns=l.useMemo(()=>$t.find(C=>C.metadata.id===L)??$t[0],[$t,L]),ys=l.useCallback((C,gt)=>{const zt=gt==="dark"?" Dark":" Light";return C.endsWith(zt)?C.slice(0,-zt.length):C},[]),Qe=C=>s?s.includes(C):!0,mt=gs(),xt=Qe("theme")&&!mt,Rt=Qe("theme")||Qe("timeFormat")||Qe("weekStart"),es=d&&mn()&&!fs()&&!mt,Zt=mt?Rt:Qe("theme")||es||Qe("pwaInstallName")||Qe("pwaOrientation")||Qe("timeFormat")||Qe("weekStart"),qs=Qe("fontSize")||Qe("terminalFontSize")||Qe("spacing")||Qe("inputBarOffset"),Os=Qe("terminalQuickKeys")&&!d||Qe("fileEditorKeymap")||Qe("expandedEditorToolbar"),Tn=Qe("mermaidRendering")||Qe("userMessageRendering")||Qe("chatRenderMode")||Qe("messageTransport")||Qe("activityRenderMode")&&M==="sorted"||Qe("collapsibleUserMessages")||Qe("stickyUserHeader")||Qe("wideChatLayout")||Qe("splitAssistantMessageActions")||Qe("diffLayout")||Qe("dotfiles")||Qe("fileViewerPreview")||Qe("reasoning")||Qe("queueMode")||Qe("persistDraft")||Qe("showToolFileIcons")||Qe("expandedTools")||!d&&Qe("inputSpellcheck"),As=Qe("pwaInstallName")&&mn()&&c&&!fs()&&!mt,Gs=Qe("pwaOrientation")&&mn()&&!fs()&&!mt,Js=Qe("mobileKeyboardMode")&&mn()&&!fs()&&!mt&&Vm(),[Fn,Va]=l.useState(()=>Zm()),[On,Ls]=l.useState(""),[yn,Qs]=l.useState("system"),sa=l.useMemo(()=>{const C=$o.find(gt=>gt.id===Pe);return o(C?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Pe,o]),_a=l.useMemo(()=>{const C=Uo.find(gt=>gt.id===Oe);return o(C?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[Oe,o]),K=l.useMemo(()=>{const C=Lo.find(gt=>gt.id===yn);return C?o(C.labelKey):void 0},[yn,o]),qe=l.useMemo(()=>{const C=zo.find(gt=>gt.id===Z);return C?o(C.labelKey):void 0},[Z,o]),kt=l.useCallback(C=>{C!==Fn&&(Va(C),eu(C),window.location.reload())},[Fn]),Tt=l.useCallback(async C=>{if(typeof window>"u")return;const gt=window,ss=C.trim().replace(/\s+/g," ").slice(0,64);if(await It({pwaAppName:ss}),typeof gt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const Is=gt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(ss);Ls(Is);return}Ls(ss||Vn),gt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),ts=l.useCallback(async C=>{if(typeof window>"u")return;const gt=window,zt=mr(C);if(await It({pwaOrientation:zt}),typeof gt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const ss=gt.__OPENCHAMBER_SET_PWA_ORIENTATION__(zt);Qs(ss);return}Qs(zt),gt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!As&&!Gs&&!Js)return;let C=!1;return(async()=>{try{const zt=await jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!zt.ok){C||Ls(Vn);return}const ss=await zt.json().catch(()=>({})),zs=(typeof ss?.pwaAppName=="string"?ss.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),on=mr(ss?.pwaOrientation),Ln=Ci(ss?.mobileKeyboardMode);C||(As&&Ls(zs||Vn),Gs&&Qs(on),Js&&se(Ln))}catch{C||(As&&Ls(Vn),Gs&&Qs("system"),Js&&se("native"))}})(),()=>{C=!0}},[se,Js,As,Gs]),t.jsxs("div",{className:"space-y-8",children:[Zt&&t.jsxs("div",{className:"mb-8 space-y-6",children:[xt&&t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsx("span",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.colorMode")}),t.jsx("div",{className:"flex flex-wrap items-center gap-1",children:wx.map(C=>t.jsx(J,{variant:"chip",size:"xs","aria-pressed":Ee===C.value,className:"!font-normal",onClick:()=>Ce(C.value),children:o(C.labelKey)},C.value))})]}),es&&t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5 py-1.5",children:[t.jsx("span",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.mobileLayout")}),t.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Sx.map(C=>t.jsx(J,{variant:"chip",size:"xs","aria-pressed":Fn===C.value,className:"!font-normal",onClick:()=>kt(C.value),children:o(C.labelKey)},C.value))})]}),t.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:[t.jsxs("div",{"data-settings-item":"appearance.light-theme",className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.lightTheme")}),t.jsxs(Ft,{value:bs?.metadata.id??"",onValueChange:Fe,children:[t.jsx(Ot,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:t.jsx(Kt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:bs?ys(bs.metadata.name,"light"):void 0})}),t.jsx(Lt,{children:St.map(C=>t.jsx(ht,{value:C.metadata.id,children:ys(C.metadata.name,"light")},C.metadata.id))})]})]}),t.jsxs("div",{"data-settings-item":"appearance.dark-theme",className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.darkTheme")}),t.jsxs(Ft,{value:ns?.metadata.id??"",onValueChange:Je,children:[t.jsx(Ot,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:t.jsx(Kt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:ns?ys(ns.metadata.name,"dark"):void 0})}),t.jsx(Lt,{children:$t.map(C=>t.jsx(ht,{value:C.metadata.id,children:ys(C.metadata.name,"dark")},C.metadata.id))})]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[t.jsx("button",{type:"button",disabled:G||Xe,onClick:()=>{const C=Date.now();et(!0),$().finally(()=>{const gt=Date.now()-C;if(gt<500){window.setTimeout(()=>{et(!1)},500-gt);return}et(!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(Xe?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.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:t.jsx(A,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(Et,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]}),at&&t.jsxs("div",{"data-settings-item":"appearance.window-transparency",className:"flex flex-col gap-1.5 border-t border-border/40 pt-3",children:[t.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Ze,onClick:()=>{pt||We(!Ze)},onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),pt||We(!Ze))},children:[t.jsx(Pt,{checked:Ze,onChange:We,disabled:pt,ariaLabel:i("settings.openchamber.visual.field.macVibrancy")}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.macVibrancy")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.macVibrancyHint")})]})]}),Ze!==lt&&t.jsx("div",{className:"pl-6",children:t.jsx(J,{variant:"outline",size:"sm",disabled:pt,onClick:()=>{pe(!0),_m("desktop_set_vibrancy",{enabled:Ze})},children:i(pt?"settings.openchamber.visual.actions.restarting":"settings.openchamber.visual.actions.saveAndRestart")})})]})]}),Rt&&t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.localization")}),t.jsxs("div",{"data-settings-item":"appearance.language",className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.appearance.language.label")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.appearance.language.description")})]}),t.jsxs(Ft,{value:e,onValueChange:C=>a(C),children:[t.jsx(Ot,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:t.jsx(Kt,{children:r(e)})}),t.jsx(Lt,{children:n.map(C=>t.jsx(ht,{value:C,children:r(C)},C))})]})]}),(Qe("timeFormat")||Qe("weekStart"))&&t.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:[Qe("timeFormat")&&t.jsxs("div",{"data-settings-item":"appearance.time-format",className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.timeFormat")}),t.jsxs(Ft,{value:Pe,onValueChange:C=>Nt(C),children:[t.jsx(Ot,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:t.jsx(Kt,{children:sa})}),t.jsx(Lt,{children:$o.map(C=>t.jsx(ht,{value:C.id,children:o(C.labelKey)},C.id))})]})]}),Qe("weekStart")&&t.jsxs("div",{"data-settings-item":"appearance.week-start",className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.weekStartsOn")}),t.jsxs(Ft,{value:Oe,onValueChange:C=>ct(C),children:[t.jsx(Ot,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:t.jsx(Kt,{children:_a})}),t.jsx(Lt,{children:Uo.map(C=>t.jsx(ht,{value:C.id,children:o(C.labelKey)},C.id))})]})]})]})]}),(As||Gs||Js)&&t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[As&&t.jsxs("div",{"data-settings-item":"appearance.pwa-install-name",className:"py-1.5 space-y-1.5",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installAppName")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installAppNameHint")})]}),t.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[t.jsx(it,{value:On,onChange:C=>{Ls(C.target.value)},onBlur:()=>{Tt(On)},onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),Tt(On))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ls(Vn),Tt("")},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:t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Gs&&t.jsxs("div",{"data-settings-item":"appearance.pwa-orientation",className:"py-1.5 space-y-1.5",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installOrientation")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installOrientationHint")})]}),t.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[t.jsxs(Ft,{value:yn,onValueChange:C=>{const gt=mr(C);Qs(gt),ts(gt)},children:[t.jsx(Ot,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:t.jsx(Kt,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:K})}),t.jsx(Lt,{children:Lo.map(C=>t.jsx(ht,{value:C.id,children:o(C.labelKey)},C.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Qs("system"),ts("system")},disabled:yn==="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:t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Js&&t.jsxs("div",{"data-settings-item":"appearance.mobile-keyboard-mode",className:"py-1.5 space-y-1.5",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardMode")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardModeHint")})]}),t.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[t.jsxs(Ft,{value:Z,onValueChange:C=>{const gt=Ci(C);se(gt),It({mobileKeyboardMode:gt})},children:[t.jsx(Ot,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:t.jsx(Kt,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:qe})}),t.jsx(Lt,{children:zo.map(C=>t.jsx(ht,{value:C.id,children:o(C.labelKey)},C.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>{se("native"),It({mobileKeyboardMode:"native"})},disabled:Z==="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:t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),qs&&t.jsx("div",{className:"mb-8 space-y-3",children:t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.spacingAndLayout")}),t.jsxs("div",{className:"pl-2",children:[Qe("fontSize")&&!d&&t.jsxs("div",{"data-settings-item":"appearance.interface-font-size",className:"flex items-center gap-8 py-1",children:[t.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFont")})}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[t.jsxs(Ft,{value:Q,onValueChange:C=>W(C),children:[t.jsx(Ot,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:t.jsx(Kt,{children:wi.find(C=>C.id===Q)?.label})}),t.jsx(Lt,{children:wi.map(C=>t.jsx(ht,{value:C.id,children:t.jsx("span",{style:{fontFamily:C.stack},children:C.label})},C.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>W(Ni),disabled:Q===Ni,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:t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("terminalFontSize")&&t.jsxs("div",{className:de("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:de("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeFont")})}),t.jsxs("div",{className:de("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsxs(Ft,{value:R,onValueChange:C=>Y(C),children:[t.jsx(Ot,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:t.jsx(Kt,{children:ki.find(C=>C.id===R)?.label})}),t.jsx(Lt,{children:ki.map(C=>t.jsx(ht,{value:C.id,children:t.jsx("span",{style:{fontFamily:C.stack},children:C.label})},C.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>Y(Si),disabled:R===Si,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:t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("fontSize")&&!d&&t.jsxs("div",{className:"flex items-center gap-8 py-1",children:[t.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFontSize")})}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[t.jsx(xs,{value:O,onValueChange:T,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>T(100),disabled:O===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:t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("terminalFontSize")&&t.jsxs("div",{"data-settings-item":"appearance.terminal-font-size",className:de("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:de("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalFontSize")})}),t.jsxs("div",{className:de("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(xs,{value:U,onValueChange:B,min:9,max:52,step:1,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>B(13),disabled:U===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:t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("spacing")&&t.jsxs("div",{"data-settings-item":"appearance.spacing-density",className:de("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:de("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.spacingDensity")})}),t.jsxs("div",{className:de("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(xs,{value:F,onValueChange:H,min:50,max:200,step:5,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>H(100),disabled:F===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:t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Qe("inputBarOffset")&&t.jsxs("div",{"data-settings-item":"appearance.input-bar-offset",className:de("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:de("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.inputBarOffset")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),t.jsxs("div",{className:de("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(xs,{value:X,onValueChange:re,min:0,max:100,step:5,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>re(0),disabled:X===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:t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),Os&&t.jsx("div",{className:"space-y-3",children:t.jsxs("section",{className:"px-2 pb-2 pt-0",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.navigation")}),Qe("fileEditorKeymap")&&t.jsxs("div",{"data-settings-item":"appearance.file-editor-keymap",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-start sm:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:i("settings.openchamber.visual.field.fileEditorKeymap")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.field.fileEditorKeymap"),className:"space-y-0",children:["default","vim"].map(C=>{const gt=he===C,zt=i(`settings.openchamber.visual.option.fileEditorKeymap.${C}`);return t.jsxs("button",{type:"button",className:"flex cursor-pointer items-center gap-2 py-0.5 text-left",role:"radio","aria-checked":gt,onClick:()=>Ie(C),children:[t.jsx("span",{"aria-hidden":!0,className:de("relative flex h-[14px] w-[14px] min-h-[14px] min-w-[14px] shrink-0 self-center items-center justify-center rounded-full transition-[background-color,box-shadow] duration-200 ease-out",gt?"bg-[color-mix(in_srgb,var(--primary-base)_80%,transparent)] shadow-none":"bg-[var(--surface-muted)] shadow-[inset_0_0_0_1px_var(--interactive-border)]"),children:t.jsx("span",{className:de("block h-[5px] w-[5px] rounded-full bg-white",!gt&&"opacity-0")})}),t.jsx("span",{className:de("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:zt})]},C)})})]}),Qe("expandedEditorToolbar")&&t.jsxs("div",{"data-settings-item":"appearance.expanded-editor-toolbar",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":y,onClick:()=>tt(!y),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),tt(!y))},children:[t.jsx(Pt,{checked:y,onChange:tt,ariaLabel:i("settings.openchamber.visual.field.expandedEditorToolbarAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.expandedEditorToolbar")})]}),Qe("terminalQuickKeys")&&!d&&t.jsxs("div",{"data-settings-item":"appearance.terminal-quick-keys",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":xe,onClick:()=>we(!xe),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),we(!xe))},children:[t.jsx(Pt,{checked:xe,onChange:we,ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria")}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalQuickKeys")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),Tn&&t.jsxs("div",{className:"space-y-3",children:[(Qe("userMessageRendering")||Qe("mermaidRendering")||Qe("chatRenderMode")||Qe("messageTransport")||Qe("activityRenderMode")&&M==="sorted"||Qe("diffLayout")&&!mt)&&t.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:[Qe("chatRenderMode")&&t.jsxs("section",{"data-settings-item":"chat.render-mode",className:"p-2 md:col-span-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.chatRenderMode")}),t.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:Px.map(C=>{const gt=M===C.id,zt=st%12;return t.jsxs("button",{type:"button",onClick:()=>ot(C.id),"aria-pressed":gt,className:de("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",gt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsx("span",{className:de("typography-ui-label",gt?"text-foreground":"text-muted-foreground"),children:o(C.labelKey)}),t.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:C.id==="live"?t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ss=>{const Is=ss*3+1,zs=zt-Is+1,on=zs<=0?0:zs===1?42:zs===2?68:92,Ln=on>0;return t.jsxs("div",{className:de("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Ln?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[t.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),t.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${on}%`}})]},ss)})}):t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ss=>{const Is=zt>=(ss+1)*3;return t.jsxs("div",{className:de("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Is?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[t.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),t.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},ss)})})})]},C.id)})})]}),Qe("messageTransport")&&t.jsxs("section",{"data-settings-item":"chat.message-transport",className:"p-2 md:col-span-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.messageStreamTransport")}),t.jsxs("div",{className:"mt-1 flex max-w-[24rem] flex-col gap-2",children:[t.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Ko.map(C=>t.jsx(J,{variant:"chip",size:"xs","aria-pressed":Ue===C.id,className:"!font-normal",onClick:()=>yt(C.id),children:o(C.labelKey)},C.id))}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const C=Ko.find(gt=>gt.id===Ue);return C?.descriptionKey?o(C.descriptionKey):""})()})]})]}),Qe("activityRenderMode")&&M==="sorted"&&t.jsxs("section",{className:"p-2 md:col-span-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.activityDefault")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:Ix.map(C=>{const gt=v===C.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":gt,onClick:()=>Mt(C.id),onKeyDown:zt=>{(zt.key===" "||zt.key==="Enter")&&(zt.preventDefault(),Mt(C.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Sn,{checked:gt,onChange:()=>Mt(C.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(C.labelKey)})}),t.jsx("span",{className:de("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:o(C.labelKey)})]},C.id)})})]}),Qe("expandedTools")&&t.jsxs("section",{className:"p-2 md:col-span-2 space-y-0.5",children:[t.jsx("div",{className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.showToolsOpenedByDefault")}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Me,onClick:()=>Se(!Me),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),Se(!Me))},children:[t.jsx(Pt,{checked:Me,onChange:Se,ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.bash")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":De,onClick:()=>vt(!De),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),vt(!De))},children:[t.jsx(Pt,{checked:De,onChange:vt,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),Qe("userMessageRendering")&&t.jsxs("section",{className:"p-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.userMessageRendering")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.userMessageRenderingAria"),className:"mt-0.5 space-y-0",children:Cx.map(C=>{const gt=Dx(h)===C.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":gt,onClick:()=>ae(C.id),onKeyDown:zt=>{(zt.key===" "||zt.key==="Enter")&&(zt.preventDefault(),ae(C.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Sn,{checked:gt,onChange:()=>ae(C.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(C.labelKey)})}),t.jsx("span",{className:de("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:o(C.labelKey)})]},C.id)})})]}),Qe("mermaidRendering")&&t.jsxs("section",{className:"p-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.mermaidRendering")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.mermaidRenderingAria"),className:"mt-0.5 space-y-0",children:kx.map(C=>{const gt=f===C.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":gt,onClick:()=>Qt(C.id),onKeyDown:zt=>{(zt.key===" "||zt.key==="Enter")&&(zt.preventDefault(),Qt(C.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Sn,{checked:gt,onChange:()=>Qt(C.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(C.labelKey)})}),t.jsx("span",{className:de("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:o(C.labelKey)})]},C.id)})})]}),Qe("diffLayout")&&!mt&&t.jsxs("section",{className:"p-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.diffLayout")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.diffLayoutAria"),className:"mt-0.5 space-y-0",children:Nx.map(C=>{const gt=ce===C.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":gt,onClick:()=>oe(C.id),onKeyDown:zt=>{(zt.key===" "||zt.key==="Enter")&&(zt.preventDefault(),oe(C.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Sn,{checked:gt,onChange:()=>oe(C.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:o(C.labelKey)})}),t.jsx("span",{className:de("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:o(C.labelKey)})]},C.id)})})]})]}),(Qe("collapsibleUserMessages")||Qe("stickyUserHeader")||Qe("wideChatLayout")||Qe("splitAssistantMessageActions")||Qe("dotfiles")||Qe("fileViewerPreview")||Qe("queueMode")||Qe("persistDraft")||Qe("showToolFileIcons")||Qe("showTurnChangedFiles")||!d&&Qe("inputSpellcheck")||Qe("reasoning"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[Qe("reasoning")&&t.jsxs("div",{"data-settings-item":"chat.reasoning-traces",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>p(!m),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),p(!m))},children:[t.jsx(Pt,{checked:m,onChange:p,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),Qe("reasoning")&&m&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>S(!u),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),S(!u))},children:[t.jsx(Pt,{checked:u,onChange:S,ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleThinkingBlocks")})]}),Qe("collapsibleUserMessages")&&t.jsxs("div",{"data-settings-item":"chat.collapsible-user-messages",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":k,onClick:()=>Ye(!k),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),Ye(!k))},children:[t.jsx(Pt,{checked:k,onChange:Ye,ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleUserMessages")})]}),Qe("stickyUserHeader")&&t.jsxs("div",{"data-settings-item":"chat.sticky-user-header",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":E,onClick:()=>Ve(!E),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),Ve(!E))},children:[t.jsx(Pt,{checked:E,onChange:Ve,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),Qe("wideChatLayout")&&t.jsxs("div",{"data-settings-item":"chat.wide-layout",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":P,onClick:()=>bt(!P),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),bt(!P))},children:[t.jsx(Pt,{checked:P,onChange:bt,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),Qe("splitAssistantMessageActions")&&t.jsxs("div",{"data-settings-item":"chat.inline-assistant-actions",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Be,onClick:()=>ze(!Be),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),ze(!Be))},children:[t.jsx(Pt,{checked:Be,onChange:ze,ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria")}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActions")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),Qe("showToolFileIcons")&&t.jsxs("div",{"data-settings-item":"chat.tool-file-icons",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":_,onClick:()=>Xt(!_),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),Xt(!_))},children:[t.jsx(Pt,{checked:_,onChange:Xt,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),Qe("showTurnChangedFiles")&&t.jsxs("div",{"data-settings-item":"chat.changed-files",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ne,onClick:()=>rs(!ne),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),rs(!ne))},children:[t.jsx(Pt,{checked:ne,onChange:rs,ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showTurnChangedFiles")})]}),Qe("dotfiles")&&!gs()&&t.jsxs("div",{"data-settings-item":"chat.dotfiles",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":x,onClick:()=>Xa(!x),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),Xa(!x))},children:[t.jsx(Pt,{checked:x,onChange:Xa,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),Qe("fileViewerPreview")&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":q,onClick:()=>Wt(!q),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),Wt(!q))},children:[t.jsx("span",{onClick:C=>C.stopPropagation(),children:t.jsx(Pt,{checked:q,onChange:Wt,ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.defaults.field.openFilesPreview")})]}),Qe("queueMode")&&t.jsxs("div",{"data-settings-item":"chat.queue-mode",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ve,onClick:()=>be(!ve),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),be(!ve))},children:[t.jsx(Pt,{checked:ve,onChange:be,ariaLabel:i("settings.openchamber.visual.field.queueMessagesByDefaultAria")}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.queueMessagesByDefault")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.queueMessagesByDefaultTooltip",{modifier:kl()})})]})]})]}),Qe("persistDraft")&&t.jsxs("div",{"data-settings-item":"chat.persist-drafts",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ye,onClick:()=>te(!ye),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),te(!ye))},children:[t.jsx(Pt,{checked:ye,onChange:te,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!d&&Qe("inputSpellcheck")&&t.jsxs("div",{"data-settings-item":"chat.spellcheck",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ie,onClick:()=>_e(!ie),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),_e(!ie))},children:[t.jsx(Pt,{checked:ie,onChange:_e,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),Qe("reportUsage")&&t.jsx("div",{className:"space-y-3",children:t.jsxs("section",{className:"px-2 pb-2 pt-0",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground mb-2",children:i("settings.openchamber.visual.section.privacy")}),t.jsxs("div",{"data-settings-item":"appearance.usage-reports",className:"flex items-start gap-2 py-1.5",children:[t.jsx(Pt,{checked:Ge,onChange:wt,ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria")}),t.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[t.jsx("div",{className:"group flex cursor-pointer",role:"button",tabIndex:0,"aria-pressed":Ge,onClick:()=>wt(!Ge),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),wt(!Ge))},children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sendAnonymousUsageReports")})}),t.jsx("span",{className:"typography-meta text-muted-foreground pointer-events-none",children:i("settings.openchamber.visual.field.sendAnonymousUsageReportsHint")})]})]})]})})]})},Ax=1,Ex=365,Bo=30,Mx=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Jl=()=>{const s=rt.c(113),{t:e}=dt(),n=Ke(Rx),a=Ke(Tx),r=Ke(Fx),i=Ke(Ox),o=Ke(Lx),d=Ke(zx);let c;s[0]===Symbol.for("react.memo_cache_sentinel")?(c={autoRun:!1},s[0]=c):c=s[0];const{candidates:x,isRunning:m,runCleanup:p,action:u}=dm(c),S=x.length;let f;s[1]!==p||s[2]!==e?(f=async()=>{const ne=await p({force:!0});if(ne.completedIds.length===0&&ne.failedIds.length===0){V.message(ne.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ne.completedIds.length>0&&V.success(ne.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ne.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ne.completedIds.length})),ne.failedIds.length>0&&V.error(ne.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ne.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ne.failedIds.length}))},s[1]=p,s[2]=e,s[3]=f):f=s[3];const g=f;let h;s[4]!==e?(h=e("settings.openchamber.sessionRetention.title"),s[4]=e,s[5]=h):h=s[5];let D;s[6]!==h?(D=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:h}),s[6]=h,s[7]=D):D=s[7];let k;s[8]===Symbol.for("react.memo_cache_sentinel")?(k=t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[8]=k):k=s[8];let w;s[9]!==e?(w=e("settings.openchamber.sessionRetention.tooltip"),s[9]=e,s[10]=w):w=s[10];let E;s[11]!==w?(E=t.jsxs(Dt,{children:[k,t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:w})]}),s[11]=w,s[12]=E):E=s[12];let N;s[13]!==D||s[14]!==E?(N=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[D,E]})}),s[13]=D,s[14]=E,s[15]=N):N=s[15];let y,b;s[16]!==n||s[17]!==i?(y=()=>i(!n),b=ne=>{(ne.key===" "||ne.key==="Enter")&&(ne.preventDefault(),i(!n))},s[16]=n,s[17]=i,s[18]=y,s[19]=b):(y=s[18],b=s[19]);let P;s[20]!==e?(P=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),s[20]=e,s[21]=P):P=s[21];let z;s[22]!==n||s[23]!==i||s[24]!==P?(z=t.jsx(Pt,{checked:n,onChange:i,ariaLabel:P}),s[22]=n,s[23]=i,s[24]=P,s[25]=z):z=s[25];let M;s[26]!==e?(M=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),s[26]=e,s[27]=M):M=s[27];let I;s[28]!==M?(I=t.jsx("span",{className:"typography-ui-label text-foreground",children:M}),s[28]=M,s[29]=I):I=s[29];let v;s[30]!==n||s[31]!==z||s[32]!==I||s[33]!==y||s[34]!==b?(v=t.jsxs("div",{"data-settings-item":"sessions.auto-cleanup",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:y,onKeyDown:b,children:[z,I]}),s[30]=n,s[31]=z,s[32]=I,s[33]=y,s[34]=b,s[35]=v):v=s[35];let j;s[36]!==e?(j=e("settings.openchamber.sessionRetention.field.retentionPeriod"),s[36]=e,s[37]=j):j=s[37];let O;s[38]!==j?(O=t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:j})}),s[38]=j,s[39]=O):O=s[39];let T;s[40]!==e?(T=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),s[40]=e,s[41]=T):T=s[41];let U;s[42]!==a||s[43]!==o||s[44]!==T?(U=t.jsx(xs,{value:a,onValueChange:o,min:Ax,max:Ex,step:1,"aria-label":T,className:"w-20 tabular-nums"}),s[42]=a,s[43]=o,s[44]=T,s[45]=U):U=s[45];let B;s[46]!==e?(B=e("settings.openchamber.sessionRetention.field.days"),s[46]=e,s[47]=B):B=s[47];let Q;s[48]!==B?(Q=t.jsx("span",{className:"typography-ui-label text-muted-foreground",children:B}),s[48]=B,s[49]=Q):Q=s[49];let W;s[50]!==o?(W=()=>o(Bo),s[50]=o,s[51]=W):W=s[51];const R=a===Bo;let Y;s[52]!==e?(Y=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),s[52]=e,s[53]=Y):Y=s[53];let F;s[54]!==e?(F=e("settings.common.actions.reset"),s[54]=e,s[55]=F):F=s[55];let H;s[56]===Symbol.for("react.memo_cache_sentinel")?(H=t.jsx(A,{name:"restart",className:"h-3.5 w-3.5"}),s[56]=H):H=s[56];let X;s[57]!==W||s[58]!==R||s[59]!==Y||s[60]!==F?(X=t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:W,disabled:R,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":Y,title:F,children:H}),s[57]=W,s[58]=R,s[59]=Y,s[60]=F,s[61]=X):X=s[61];let re;s[62]!==U||s[63]!==Q||s[64]!==X?(re=t.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[U,Q,X]}),s[62]=U,s[63]=Q,s[64]=X,s[65]=re):re=s[65];let Z;s[66]!==O||s[67]!==re?(Z=t.jsxs("div",{"data-settings-item":"sessions.retention-period",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[O,re]}),s[66]=O,s[67]=re,s[68]=Z):Z=s[68];let se;s[69]!==e?(se=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),s[69]=e,s[70]=se):se=s[70];let ce;s[71]!==se?(ce=t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:se})}),s[71]=se,s[72]=ce):ce=s[72];let oe;s[73]!==r||s[74]!==d||s[75]!==e?(oe=Mx.map(ne=>t.jsx(J,{type:"button",variant:"chip",size:"xs","aria-pressed":r===ne.value,className:"!font-normal",onClick:()=>d(ne.value),children:e(ne.labelKey)},ne.value)),s[73]=r,s[74]=d,s[75]=e,s[76]=oe):oe=s[76];let xe;s[77]!==oe?(xe=t.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:oe}),s[77]=oe,s[78]=xe):xe=s[78];let we;s[79]!==ce||s[80]!==xe?(we=t.jsxs("div",{"data-settings-item":"sessions.retention-action",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[ce,xe]}),s[79]=ce,s[80]=xe,s[81]=we):we=s[81];let he;s[82]!==v||s[83]!==Z||s[84]!==we?(he=t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[v,Z,we]}),s[82]=v,s[83]=Z,s[84]=we,s[85]=he):he=s[85];let Ie;s[86]!==e?(Ie=e("settings.openchamber.sessionRetention.manualCleanup.title"),s[86]=e,s[87]=Ie):Ie=s[87];let ve;s[88]!==Ie?(ve=t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("p",{className:"typography-meta text-foreground font-medium",children:Ie})}),s[88]=Ie,s[89]=ve):ve=s[89];let be;s[90]!==m||s[91]!==e?(be=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),s[90]=m,s[91]=e,s[92]=be):be=s[92];let ye;s[93]!==g||s[94]!==m||s[95]!==be?(ye=t.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:t.jsx(J,{type:"button",variant:"outline",size:"xs",onClick:g,disabled:m,className:"!font-normal",children:be})}),s[93]=g,s[94]=m,s[95]=be,s[96]=ye):ye=s[96];let te;s[97]!==ve||s[98]!==ye?(te=t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ve,ye]}),s[97]=ve,s[98]=ye,s[99]=te):te=s[99];let ie;s[100]!==u||s[101]!==S||s[102]!==e?(ie=u==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:S}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:S}),s[100]=u,s[101]=S,s[102]=e,s[103]=ie):ie=s[103];let ge;s[104]!==ie?(ge=t.jsx("p",{className:"typography-meta text-muted-foreground",children:ie}),s[104]=ie,s[105]=ge):ge=s[105];let _;s[106]!==te||s[107]!==ge?(_=t.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[te,ge]}),s[106]=te,s[107]=ge,s[108]=_):_=s[108];let ee;return s[109]!==he||s[110]!==_||s[111]!==N?(ee=t.jsxs("div",{className:"mb-8",children:[N,he,_]}),s[109]=he,s[110]=_,s[111]=N,s[112]=ee):ee=s[112],ee};function Rx(s){return s.autoDeleteEnabled}function Tx(s){return s.autoDeleteAfterDays}function Fx(s){return s.sessionRetentionAction}function Ox(s){return s.setAutoDeleteEnabled}function Lx(s){return s.setAutoDeleteAfterDays}function zx(s){return s.setSessionRetentionAction}const Vo=(s,e,n)=>!s||!Number.isFinite(s)?e:new Intl.DateTimeFormat(Vr(),{dateStyle:"medium",timeStyle:"short",hour12:n==="auto"?void 0:n==="12h"}).format(s),Ql=()=>{const{t:s}=dt(),e=Ke(b=>b.timeFormatPreference),[n,a]=l.useState(!1),[r,i]=l.useState(!0),[o,d]=l.useState(!1),[c,x]=l.useState(null),[m,p]=l.useState(!1),[u,S]=l.useState([]),[f,g]=l.useState(mm),[h,D]=l.useState(""),k=l.useMemo(()=>um(),[]),w=l.useCallback(async()=>{i(!0),D("");try{const b=await pm();S(b)}catch(b){const P=b instanceof Error?b.message:s("settings.openchamber.passkeys.toast.loadFailed");D(P)}finally{i(!1)}},[s]);l.useEffect(()=>{let b=!1;return(async()=>{try{if(!k.supported){b||(a(!1),i(!1));return}b||a(!0)}catch{b||a(!1)}if(!b){const P=await Ga();if(g(P),!P.enabled){S([]),i(!1);return}await w()}})(),()=>{b=!0,gi()}},[w,k.supported]);const E=l.useCallback(async()=>{if(!f.enabled){const b=s("settings.openchamber.passkeys.toast.enableUiPasswordFirst");D(b),V.message(b);return}if(!n){D(k.reason),V.message(k.reason);return}if(o){gi(),d(!1);return}D(""),d(!0);try{await gm(),g(await Ga()),await w(),V.success(s("settings.openchamber.passkeys.toast.added"))}catch(b){if(hm(b)){V.message(s("settings.openchamber.passkeys.toast.setupCanceled"));return}const P=b instanceof Error?b.message:s("settings.openchamber.passkeys.toast.addFailed");D(P),V.error(P)}finally{d(!1)}},[o,w,f.enabled,k.reason,n,s]),N=l.useCallback(async b=>{x(b),D("");try{await fm(b),g(await Ga()),await w(),V.success(s("settings.openchamber.passkeys.toast.removed"))}catch(P){const z=P instanceof Error?P.message:s("settings.openchamber.passkeys.toast.removeFailed");D(z),V.error(z)}finally{x(null)}},[w,s]),y=l.useCallback(async()=>{p(!0),D("");try{await xm(),window.location.reload()}catch(b){const P=b instanceof Error?b.message:s("settings.openchamber.passkeys.toast.clearAuthFailed");D(P),V.error(P),p(!1)}},[s]);return t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.passkeys.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.passkeys.field.currentDevice")})}),t.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[t.jsx(J,{type:"button",variant:o?"secondary":"outline",size:"xs",onClick:()=>{E()},disabled:r||m,className:"!font-normal",children:s(o?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",onClick:()=>{y()},disabled:r||o||m,className:"!font-normal text-muted-foreground hover:text-foreground",children:s(m?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]})]}),!f.enabled&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.uiPasswordRequired")}),f.enabled&&!n&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:k.reason}),r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.loading")}):u.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.noneSaved")}):t.jsx("div",{className:"space-y-1 pt-1",children:u.map(b=>t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:b.label})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:b.lastUsedAt?s("settings.openchamber.passkeys.item.lastUsed",{time:Vo(b.lastUsedAt,s("settings.openchamber.passkeys.time.neverUsed"),e)}):s("settings.openchamber.passkeys.item.added",{time:Vo(b.createdAt,s("settings.openchamber.passkeys.time.neverUsed"),e)})}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",onClick:()=>{N(b.id)},disabled:c===b.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===b.id?s("settings.openchamber.passkeys.actions.removing"):s("settings.common.actions.delete")})]})]},b.id))})]}),h&&t.jsx("div",{className:"mt-1 px-2 py-1.5",children:t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:h})})]})},Kx=s=>{const e=pn(s);return e||{providerId:"",modelId:""}},Yl=()=>{const{t:s}=dt(),e=ut(I=>I.setProvider),n=ut(I=>I.setModel),a=ut(I=>I.setAgent),r=ut(I=>I.setCurrentVariant),i=ut(I=>I.setSettingsDefaultModel),o=ut(I=>I.setSettingsDefaultVariant),d=ut(I=>I.setSettingsDefaultAgent),c=Ke(I=>I.showDeletionDialog),x=Ke(I=>I.setShowDeletionDialog),m=ut(I=>I.providers),[p,u]=l.useState(),[S,f]=l.useState(),[g,h]=l.useState(),[D,k]=l.useState(!0),w=l.useMemo(()=>Kx(p),[p]);l.useEffect(()=>{(async()=>{try{let v=null;if(!v){const j=Fs()?.settings;if(j)try{const T=(await j.load())?.settings;T&&(v={defaultModel:typeof T.defaultModel=="string"?T.defaultModel:void 0,defaultVariant:typeof T.defaultVariant=="string"?T.defaultVariant:void 0,defaultAgent:typeof T.defaultAgent=="string"?T.defaultAgent:void 0})}catch{}}if(!v){const j=await jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});j.ok&&(v=await j.json())}if(v){const j=typeof v.defaultModel=="string"&&v.defaultModel.trim().length>0?v.defaultModel.trim():void 0,O=typeof v.defaultVariant=="string"&&v.defaultVariant.trim().length>0?v.defaultVariant.trim():void 0,T=typeof v.defaultAgent=="string"&&v.defaultAgent.trim().length>0?v.defaultAgent.trim():void 0;j!==void 0&&u(j),O!==void 0&&f(O),T!==void 0&&h(T)}}catch(v){console.warn("Failed to load defaults settings:",v)}finally{k(!1)}})()},[]);const E=l.useCallback(async(I,v)=>{const j=I&&v?`${I}/${v}`:void 0;u(j),f(void 0),o(void 0),r(void 0),i(j),I&&v&&m.find(T=>T.id===I)&&(e(I),n(v));try{await It({defaultModel:j??"",defaultVariant:""});const O=await jt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:j})});O.ok||console.warn("Failed to save default model to server:",O.status,O.statusText)}catch(O){console.warn("Failed to save default model:",O)}},[m,r,n,e,i,o]),N="__default__",y=l.useCallback(I=>I===N?s("settings.openchamber.defaults.option.default"):I.charAt(0).toUpperCase()+I.slice(1),[s]),b=l.useCallback(async I=>{const v=I===N?void 0:I||void 0;f(v),o(v),r(v);try{await It({defaultVariant:v??""})}catch(j){console.warn("Failed to save default variant:",j)}},[r,o]),P=l.useCallback(async I=>{const v=I||void 0;h(v),d(v),I&&a(I);try{await It({defaultAgent:v??""})}catch(j){console.warn("Failed to save default agent:",j)}},[a,d]),z=l.useMemo(()=>{if(!w.providerId||!w.modelId)return[];const j=m.find(O=>O.id===w.providerId)?.models.find(O=>O.id===w.modelId)?.variants;return j?Object.keys(j):[]},[w.modelId,w.providerId,m]),M=z.length>0;return l.useEffect(()=>{!M&&S&&(f(void 0),o(void 0),r(void 0),It({defaultVariant:""}).catch(()=>{}))},[S,r,o,M]),D?null:t.jsxs("div",{className:"mb-6",children:[t.jsx("div",{className:"mb-0.5 px-1",children:t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.defaults.title")})})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[s("settings.openchamber.defaults.summaryPrefix")," ",w.providerId?t.jsxs("span",{className:"text-foreground",children:[w.providerId,"/",w.modelId,M?` (${S??s("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):t.jsx("span",{className:"text-foreground",children:s("settings.openchamber.defaults.summaryOpenCodeDefault")}),g&&t.jsxs(t.Fragment,{children:[" / ",t.jsx("span",{className:"text-foreground",children:g})]})]}),t.jsxs("div",{"data-settings-item":"sessions.default-model",className:de("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.field.defaultModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(_r,{providerId:w.providerId,modelId:w.modelId,onChange:E})})]}),t.jsxs("div",{"data-settings-item":"sessions.default-thinking",className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.field.defaultThinking")})}),t.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:t.jsxs(Ft,{value:S??N,onValueChange:b,disabled:!M,children:[t.jsx(Ot,{className:"w-fit min-w-[120px]",children:t.jsx(Kt,{placeholder:s("settings.openchamber.defaults.field.thinkingPlaceholder"),children:y(S??N)})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:N,children:s("settings.openchamber.defaults.option.default")}),z.map(I=>t.jsx(ht,{value:I,children:y(I)},I))]})]})})]}),t.jsxs("div",{"data-settings-item":"sessions.default-agent",className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.field.defaultAgent")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(fl,{agentName:g||"",onChange:P})})]}),t.jsxs("div",{"data-settings-item":"sessions.deletion-dialog",className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":c,onClick:()=>x(!c),onKeyDown:I=>{(I.key===" "||I.key==="Enter")&&(I.preventDefault(),x(!c))},children:[t.jsx(Pt,{checked:c,onChange:x,ariaLabel:s("settings.openchamber.defaults.field.showDeletionDialogAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.field.showDeletionDialog")})]})]})]})},_o={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"}},$x={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"},Ux=()=>{const{t:s}=dt(),e=l.useMemo(()=>fs(),[]),n=l.useMemo(()=>gs(),[]),a=!e&&!n,r=Ke(F=>F.nativeNotificationsEnabled),i=Ke(F=>F.setNativeNotificationsEnabled),o=Ke(F=>F.notificationMode),d=Ke(F=>F.setNotificationMode),c=Ke(F=>F.notifyOnSubtasks),x=Ke(F=>F.setNotifyOnSubtasks),m=Ke(F=>F.notifyOnCompletion),p=Ke(F=>F.setNotifyOnCompletion),u=Ke(F=>F.notifyOnError),S=Ke(F=>F.setNotifyOnError),f=Ke(F=>F.notifyOnQuestion),g=Ke(F=>F.setNotifyOnQuestion),h=Ke(F=>F.notificationTemplates),D=Ke(F=>F.setNotificationTemplates),[k,w]=l.useState("default"),[E,N]=l.useState(!1),[y,b]=l.useState(!1),[P,z]=l.useState(!1);l.useEffect(()=>{if(!a){N(!1),b(!1);return}typeof Notification<"u"&&w(Notification.permission);const F=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;N(F),(async()=>{if(!F){b(!1);return}try{const X=await navigator.serviceWorker.getRegistration();if(!X){b(!1);return}const re=await X.pushManager.getSubscription();b(!!re)}catch{b(!1)}})()},[a]);const M=async F=>{if(e){i(F);return}if(!a){i(F);return}if(F&&typeof Notification<"u"&&Notification.permission==="default")try{const H=await Notification.requestPermission();w(H),H==="granted"?i(!0):V.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.description")})}catch(H){console.error("Failed to request notification permission:",H),V.error(s("settings.notifications.page.toast.requestPermissionFailed"))}else i(!!(F&&k==="granted"))},I=e||n||a&&typeof Notification<"u"&&Notification.permission==="granted",v=(F,H,X)=>{D({...h,[F]:{...h[F],[H]:X}})},j=F=>{const H="=".repeat((4-F.length%4)%4),X=(F+H).replace(/-/g,"+").replace(/_/g,"/"),re=atob(X),Z=new Uint8Array(re.length);for(let se=0;se<re.length;se+=1)Z[se]=re.charCodeAt(se);return Z},O=async(F,H,X)=>{let re=null;const Z=new Promise((se,ce)=>{re=setTimeout(()=>{ce(new Error(X))},H)});try{return await Promise.race([F,Z])}finally{re&&clearTimeout(re)}},T=async F=>{if(F.active)return;const H=F.installing||F.waiting;H&&H.state!=="activated"&&await O(new Promise(X=>{const re=()=>{H.state==="activated"&&(H.removeEventListener("statechange",re),X())};H.addEventListener("statechange",re),re()}),15e3,"Service worker activation timed out")},U=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const F=[{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 H=null;for(const X of F)try{const re=X.opts?navigator.serviceWorker.register("/sw.js",X.opts):navigator.serviceWorker.register("/sw.js");return await O(re,1e4,`Service worker registration timed out (${X.label})`)}catch(re){H=re}throw H instanceof Error?H:new Error("Service worker registration failed")},B=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const F=await navigator.serviceWorker.getRegistration();if(F)return F;const H=await U();try{await H.update()}catch{}return await T(H),H},Q=F=>{const H=F,X=[`type=${typeof F}`,`toString=${String(F)}`,`name=${String(H?.name??"")}`,`message=${String(H?.message??"")}`];let re="";try{re=JSON.stringify(F)}catch{}return{summary:X.filter(Boolean).join(" | "),json:re,stack:typeof H?.stack=="string"?H.stack:""}},W=async()=>{const F=Fs();if(!F?.notifications){V.error(s("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await F.notifications.notifyAgentCompletion({title:s("settings.notifications.page.testNotification.title"),body:s("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?V.success(s("settings.notifications.page.toast.testNotificationSent")):V.error(s("settings.notifications.page.toast.testNotificationFailed"))}catch(H){console.error("Test notification failed:",H),V.error(s("settings.notifications.page.toast.testNotificationFailed"))}},R=async()=>{if(!E){V.error(s("settings.notifications.page.toast.pushUnsupported"));return}const F=Fs();if(!F?.push){V.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}z(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const xe=await Notification.requestPermission();if(w(xe),xe!=="granted"){V.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){V.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const H=await F.push.getVapidPublicKey();if(!H?.publicKey){V.error(s("settings.notifications.page.toast.pushKeyLoadFailed"));return}const X=await B();await T(X);const re=await X.pushManager.getSubscription();if(!("pushManager"in X)||!X.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const se=(re??await O(X.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:j(H.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ce=se.keys;if(!se.endpoint||!ce?.p256dh||!ce.auth)throw new Error("Push subscription missing keys");if(!(await O(F.push.subscribe({endpoint:se.endpoint,keys:{p256dh:ce.p256dh,auth:ce.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){V.error(s("settings.notifications.page.toast.enableBackgroundFailed"));return}b(!0),V.success(s("settings.notifications.page.toast.backgroundEnabled"))}catch(H){console.error("[Push] Enable failed:",H);const X=Q(H);V.error(s("settings.notifications.page.toast.enableBackgroundFailed"),{description:X.summary})}finally{z(!1)}},Y=async()=>{if(!E){b(!1);return}const F=Fs();if(!F?.push){V.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}z(!0);try{const X=await(await B()).pushManager.getSubscription();if(!X){b(!1);return}const re=X.endpoint;await X.unsubscribe(),await F.push.unsubscribe({endpoint:re}),b(!1),V.success(s("settings.notifications.page.toast.backgroundDisabled"))}finally{z(!1)}};return t.jsxs("div",{className:"space-y-8",children:[t.jsxs("div",{"data-settings-item":"notifications.delivery",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.delivery.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":r&&I,onClick:()=>{M(!(r&&I))},onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),M(!(r&&I)))},children:[t.jsx(Pt,{checked:r&&I,onChange:F=>{M(F)},ariaLabel:s("settings.notifications.page.delivery.enableAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.delivery.enableLabel")})]}),r&&I&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":o==="always",onClick:()=>d(o==="always"?"hidden-only":"always"),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),d(o==="always"?"hidden-only":"always"))},children:[t.jsx(Pt,{checked:o==="always",onChange:F=>d(F?"always":"hidden-only"),ariaLabel:s("settings.notifications.page.delivery.focusedAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.delivery.focusedLabel")})]}),t.jsx("div",{className:"py-2",children:t.jsx(J,{type:"button",variant:"outline",size:"sm",onClick:()=>{W()},children:s("settings.notifications.page.delivery.testAction")})})]})]}),a&&t.jsxs("div",{className:"mt-1 px-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.notifications.page.delivery.browserPermissionHint")}),k==="denied"&&t.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:s("settings.notifications.page.delivery.permissionDenied")}),k==="granted"&&!r&&t.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:s("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),n&&t.jsx("div",{className:"mt-1 px-2",children:t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.notifications.page.delivery.vscodeHint")})})]}),r&&I&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-settings-item":"notifications.events",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.events.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>p(!m),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),p(!m))},children:[t.jsx(Pt,{checked:m,onChange:p,ariaLabel:s("settings.notifications.page.events.completionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.completionLabel")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":c,onClick:()=>x(!c),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),x(!c))},children:[t.jsx(Pt,{checked:c,onChange:x,ariaLabel:s("settings.notifications.page.events.subtaskAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.subtaskLabel")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>S(!u),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),S(!u))},children:[t.jsx(Pt,{checked:u,onChange:S,ariaLabel:s("settings.notifications.page.events.errorAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.errorLabel")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>g(!f),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),g(!f))},children:[t.jsx(Pt,{checked:f,onChange:g,ariaLabel:s("settings.notifications.page.events.questionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.questionLabel")})]})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.template.title")}),t.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[s("settings.notifications.page.template.variablesLabel")," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),t.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(F=>t.jsxs("section",{className:"p-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:s($x[F])}),t.jsxs("div",{className:"mt-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:s("settings.notifications.page.template.field.title")}),t.jsx(it,{value:h[F].title,onChange:H=>v(F,"title",H.target.value),className:"h-7",placeholder:s(_o[F].titleKey)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:s("settings.notifications.page.template.field.message")}),t.jsx(it,{value:h[F].message,onChange:H=>v(F,"message",H.target.value),className:"h-7",placeholder:s(_o[F].messageKey)})]})]})]},F))})]})]}),a&&t.jsxs("div",{"data-settings-item":"notifications.push",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.push.title")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[t.jsx(Pt,{checked:E?y:!1,disabled:!E||P,onChange:F=>{F?R():Y()},ariaLabel:s("settings.notifications.page.push.enableAria")}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:de("typography-ui-label",E?"text-foreground":"text-muted-foreground"),children:s("settings.notifications.page.push.enableLabel")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s(E?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),P&&t.jsx("div",{className:"pt-0.5 text-muted-foreground",children:t.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":s("settings.notifications.page.push.loadingAria")})})]})})]})]})},ws=s=>{if(!s)return;s.pause();const{src:e}=s;e.startsWith("blob:")&&URL.revokeObjectURL(e),s.removeAttribute("src"),s.load()},Bx=[{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:"Українська"}],Vx=s=>{const e=rt.c(45),{modelId:n}=s,{t:a}=dt();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=Wn.getModelStatus(),e[0]=r):r=e[0];const[i,o]=je.useState(r),[d,c]=je.useState(!1);let x,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const y=b=>o(b);return Wn.onModelStatusChange=y,Wx},m=[],e[1]=x,e[2]=m):(x=e[1],m=e[2]),je.useEffect(x,m);const p=Wn.getCurrentModelId(),u=i.state==="downloading"||i.state==="loading";let S,f;e[3]!==i.state?(S=()=>{i.state!=="downloading"&&i.state!=="loading"&&c(!1)},f=[i.state],e[3]=i.state,e[4]=S,e[5]=f):(S=e[4],f=e[5]),je.useEffect(S,f);let g;e[6]!==n?(g=async()=>{c(!0);try{await Wn.loadModel(n)}catch{}},e[6]=n,e[7]=g):g=e[7];const h=g;if(i.state==="ready"&&p===n){let y;e[8]!==a?(y=a("settings.voice.page.stt.wasmLoaded"),e[8]=a,e[9]=y):y=e[9];let b;return e[10]!==y?(b=t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("span",{className:"typography-ui-compact text-green-600 dark:text-green-400",children:y})}),e[10]=y,e[11]=b):b=e[11],b}if(u){let y;e[12]!==i.progress||e[13]!==i.state?(y=i.state==="downloading"?Math.round(i.progress):void 0,e[12]=i.progress,e[13]=i.state,e[14]=y):y=e[14];const b=y;let P;e[15]!==i.state||e[16]!==a?(P=i.state==="downloading"?a("settings.voice.page.stt.wasmDownloading"):a("settings.voice.page.stt.wasmLoading"),e[15]=i.state,e[16]=a,e[17]=P):P=e[17];const z=b!==void 0?` (${b}%)`:"";let M;return e[18]!==P||e[19]!==z?(M=t.jsx("div",{className:"flex items-center gap-2",children:t.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[P,z]})}),e[18]=P,e[19]=z,e[20]=M):M=e[20],M}if(i.state==="error"){let y;e[21]!==i.error?(y=t.jsx("span",{className:"typography-ui-compact text-destructive",children:i.error}),e[21]=i.error,e[22]=y):y=e[22];let b;e[23]!==a?(b=a("settings.voice.page.stt.wasmRetry"),e[23]=a,e[24]=b):b=e[24];let P;e[25]!==h||e[26]!==d||e[27]!==b?(P=t.jsx(J,{variant:"chip",size:"xs",disabled:d,onClick:h,children:b}),e[25]=h,e[26]=d,e[27]=b,e[28]=P):P=e[28];let z;return e[29]!==y||e[30]!==P?(z=t.jsxs("div",{className:"flex items-center gap-2",children:[y,P]}),e[29]=y,e[30]=P,e[31]=z):z=e[31],z}let D;e[32]!==a?(D=a("settings.voice.page.stt.wasmNotLoaded"),e[32]=a,e[33]=D):D=e[33];let k;e[34]!==D?(k=t.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:D}),e[34]=D,e[35]=k):k=e[35];let w;e[36]!==a?(w=a("settings.voice.page.stt.wasmDownload"),e[36]=a,e[37]=w):w=e[37];let E;e[38]!==h||e[39]!==d||e[40]!==w?(E=t.jsx(J,{variant:"chip",size:"xs",disabled:d,onClick:h,children:w}),e[38]=h,e[39]=d,e[40]=w,e[41]=E):E=e[41];let N;return e[42]!==E||e[43]!==k?(N=t.jsxs("div",{className:"flex items-center gap-2",children:[k,E]}),e[42]=E,e[43]=k,e[44]=N):N=e[44],N},_x=[{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"}],Hx=()=>{const{t:s}=dt(),{isMobile:e}=Cs(),{isSupported:n,language:a,setLanguage:r}=bm(),i=ut(L=>L.voiceProvider),o=ut(L=>L.setVoiceProvider),d=ut(L=>L.speechRate),c=ut(L=>L.setSpeechRate),x=ut(L=>L.speechPitch),m=ut(L=>L.setSpeechPitch),p=ut(L=>L.speechVolume),u=ut(L=>L.setSpeechVolume),S=ut(L=>L.sayVoice),f=ut(L=>L.setSayVoice),g=ut(L=>L.browserVoice),h=ut(L=>L.setBrowserVoice),D=ut(L=>L.openaiVoice),k=ut(L=>L.setOpenaiVoice),w=ut(L=>L.openaiApiKey),E=ut(L=>L.setOpenaiApiKey),N=ut(L=>L.openaiCompatibleUrl),y=ut(L=>L.setOpenaiCompatibleUrl),b=ut(L=>L.openaiCompatibleApiKey),P=ut(L=>L.setOpenaiCompatibleApiKey),z=ut(L=>L.openaiCompatibleVoice),M=ut(L=>L.setOpenaiCompatibleVoice),I=ut(L=>L.openaiCompatibleTtsModel),v=ut(L=>L.setOpenaiCompatibleTtsModel),j=ut(L=>L.showMessageTTSButtons),O=ut(L=>L.ttsInputMode),T=ut(L=>L.setTtsInputMode),U=ut(L=>L.sttProvider),B=ut(L=>L.setSttProvider),Q=ut(L=>L.sttServerUrl),W=ut(L=>L.setSttServerUrl),R=ut(L=>L.sttApiKey),Y=ut(L=>L.setSttApiKey),F=ut(L=>L.sttModel),H=ut(L=>L.setSttModel),X=ut(L=>L.wasmSttModel),re=ut(L=>L.setWasmSttModel),Z=ut(L=>L.sttLanguage),se=ut(L=>L.setSttLanguage),ce=ut(L=>L.sttSilenceThresholdDb),oe=ut(L=>L.setSttSilenceThresholdDb),xe=ut(L=>L.sttSilenceHoldMs),we=ut(L=>L.setSttSilenceHoldMs),he=ut(L=>L.sttTranscribeOnStop),Ie=ut(L=>L.setSttTranscribeOnStop),ve=ut(L=>L.setShowMessageTTSButtons),be=ut(L=>L.voiceModeEnabled),ye=ut(L=>L.setVoiceModeEnabled),[te,ie]=je.useState(!1),[ge,_]=je.useState([]),[ee,ne]=je.useState(!1),[ue,Me]=je.useState(null),[ke,De]=je.useState(!1),[Ae,Pe]=je.useState(!1),[Re,Oe]=je.useState(null),[$e,Be]=je.useState(!1),[Le,Ue]=je.useState(null),[le,q]=je.useState([]),[me,Ne]=je.useState(!1);je.useEffect(()=>((async()=>{const Fe=await Ja.waitForVoices();q(Fe)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{q(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ee=je.useMemo(()=>le.filter(L=>L.lang).sort((L,Fe)=>{const Je=L.lang.startsWith("en"),Xe=Fe.lang.startsWith("en");if(Je&&!Xe)return-1;if(!Je&&Xe)return 1;const et=L.lang.localeCompare(Fe.lang);return et!==0?et:L.name.localeCompare(Fe.name)}),[le]),Ce=je.useCallback(()=>{if(me){Ja.cancelSpeech(),Ne(!1);return}const L=le.find(et=>et.name===g),Fe=L?.name??s("settings.voice.page.preview.browserVoiceFallback"),Je=s("settings.voice.page.preview.voiceLine",{voiceName:Fe});Ne(!0);const Xe=new SpeechSynthesisUtterance(Je);Xe.rate=d,Xe.pitch=x,Xe.volume=p,L&&(Xe.voice=L,Xe.lang=L.lang),Xe.onend=()=>Ne(!1),Xe.onerror=()=>Ne(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(Xe)},[g,le,d,x,p,me,s]);je.useEffect(()=>()=>{me&&Ja.cancelSpeech()},[me]),je.useEffect(()=>{if(!be||i!=="openai"&&i!=="openai-compatible"){De(w.trim().length>0);return}(async()=>{try{const Xe=(await(await jt("/api/tts/status")).json()).available,et=w.trim().length>0;De(Xe||et)}catch{De(w.trim().length>0)}})()},[w,be,i]),je.useEffect(()=>{if(!be){ie(!1),_([]);return}jt("/api/tts/say/status").then(L=>L.json()).then(L=>{if(ie(L.available),L.voices){const Fe=L.voices.filter((Je,Xe,et)=>et.findIndex(at=>at.name===Je.name)===Xe).sort((Je,Xe)=>Je.name.localeCompare(Xe.name));_(Fe)}}).catch(()=>{ie(!1)})},[be]);const He=je.useCallback(async()=>{if(ue){ws(ue),Me(null),ne(!1);return}ne(!0);let L=null;try{const Fe=await jt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.voiceLine",{voiceName:S}),voice:S,rate:Math.round(100+(d-.5)*200)})});if(!Fe.ok)throw new Error("Preview failed");const Je=await Fe.blob(),Xe=URL.createObjectURL(Je);L=new Audio(Xe),L.onended=()=>{ws(L),Me(null),ne(!1)},L.onerror=()=>{ws(L),Me(null),ne(!1)},Me(L),await L.play()}catch{ws(L),Me(null),ne(!1)}},[S,d,ue,s]);je.useEffect(()=>()=>{ws(ue)},[ue]);const G=je.useCallback(async()=>{if(Re){ws(Re),Oe(null),Pe(!1);return}Pe(!0);let L=null;try{const Fe=await jt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.voiceLine",{voiceName:D}),voice:D,speed:d,apiKey:w||void 0})});if(!Fe.ok){const et=await Fe.json().catch(()=>({error:"Unknown error"}));throw new Error(et.error||`HTTP ${Fe.status}`)}const Je=await Fe.blob(),Xe=URL.createObjectURL(Je);L=new Audio(Xe),L.onended=()=>{ws(L),Oe(null),Pe(!1)},L.onerror=()=>{ws(L),Oe(null),Pe(!1)},Oe(L),await L.play()}catch{ws(L),Oe(null),Pe(!1)}},[D,d,Re,w,s]);je.useEffect(()=>()=>{ws(Re)},[Re]);const $=je.useCallback(async()=>{if(Le){ws(Le),Ue(null),Be(!1);return}if(!N.trim())return;Be(!0);let L=null;try{const Fe=await jt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.customServerLine"),voice:z,model:I||void 0,speed:d,baseURL:N,apiKey:b||void 0})});if(!Fe.ok){const et=await Fe.json().catch(()=>({error:"Unknown error"}));throw new Error(et.error||`HTTP ${Fe.status}`)}const Je=await Fe.blob(),Xe=URL.createObjectURL(Je);L=new Audio(Xe),L.onended=()=>{ws(L),Ue(null),Be(!1)},L.onerror=()=>{ws(L),Ue(null),Be(!1)},Ue(L),await L.play()}catch{ws(L),Ue(null),Be(!1)}},[N,z,I,b,d,Le,s]);je.useEffect(()=>()=>{ws(Le)},[Le]);const fe="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 t.jsxs("div",{className:"space-y-8",children:[t.jsxs("div",{"data-settings-item":"voice.voice-setup",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.voice.page.section.voiceSetup")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":be,onClick:()=>ye(!be),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),ye(!be))},children:[t.jsx(Pt,{checked:be,onChange:ye,ariaLabel:s("settings.voice.page.field.enableVoiceModeAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.enableVoiceMode")})]}),be&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.provider")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:t.jsxs("ul",{className:"space-y-1",children:[t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.browser")})," ",s("settings.voice.page.tooltip.browser")]}),t.jsxs("li",{children:[t.jsx("strong",{children:"OpenAI:"})," ",s("settings.voice.page.tooltip.openai")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.custom")})," ",s("settings.voice.page.tooltip.custom")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.say")})," ",s("settings.voice.page.tooltip.say")]})]})})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>o("browser"),className:"!font-normal",children:s("settings.voice.page.provider.browser")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>o("openai"),className:"!font-normal",children:"OpenAI"}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>o("openai-compatible"),className:"!font-normal",children:s("settings.voice.page.provider.custom")}),te&&t.jsxs(J,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>o("say"),className:"!font-normal",children:[t.jsx(A,{name:"apple",className:"w-3.5 h-3.5 mr-0.5"}),s("settings.voice.page.provider.say")]})]})]})}),i==="openai"&&t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:de("typography-ui-label text-foreground",!ke&&"text-[var(--status-error)]"),children:s("settings.voice.page.field.apiKey")}),t.jsx("span",{className:de("typography-meta ml-2",ke?"text-muted-foreground":"text-[var(--status-error)]/80"),children:s(ke&&!w?"settings.voice.page.field.apiKeyHintUsingConfig":ke?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"password",value:w,onChange:L=>E(L.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"}),w&&t.jsx("button",{type:"button",onClick:()=>E(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),i==="openai-compatible"&&t.jsxs("div",{className:"py-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:de("typography-ui-label text-foreground",!N.trim()&&"text-[var(--status-error)]"),children:s("settings.voice.page.field.serverUrl")}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:s("settings.voice.page.field.serverUrlHint")}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"text",value:N,onChange:L=>y(L.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"}),N&&t.jsx("button",{type:"button",onClick:()=>y(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:"API Key"}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:"Optional"}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"password",value:b,onChange:L=>P(L.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"}),b&&t.jsx("button",{type:"button",onClick:()=>P(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.model")}),t.jsx("div",{className:"relative mt-1.5 max-w-xs",children:t.jsx("input",{type:"text",value:I,onChange:L=>v(L.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"})})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.voice")}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:s("settings.voice.page.field.voiceIdentifierHint")}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[t.jsx("div",{className:"relative max-w-xs flex-1",children:t.jsx("input",{type:"text",value:z,onChange:L=>M(L.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"})}),t.jsx(J,{size:"xs",variant:"ghost",onClick:$,title:s("settings.voice.page.actions.preview"),disabled:!N.trim(),children:$e?t.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),t.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.voice")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[i==="openai"&&ke&&t.jsxs(t.Fragment,{children:[t.jsxs(Ft,{value:D,onValueChange:k,children:[t.jsx(Ot,{className:"w-fit",children:t.jsx(Kt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Lt,{children:_x.map(L=>t.jsx(ht,{value:L.value,children:L.label},L.value))})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:G,title:s("settings.voice.page.actions.preview"),children:Ae?t.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="openai-compatible"&&t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.voice.page.field.configuredAbove")}),i==="say"&&te&&ge.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(Ft,{value:S,onValueChange:f,children:[t.jsx(Ot,{className:"w-fit",children:t.jsx(Kt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Lt,{children:ge.map(L=>t.jsx(ht,{value:L.name,children:L.name},L.name))})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:He,title:s("settings.voice.page.actions.preview"),children:ee?t.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="browser"&&Ee.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(Ft,{value:g||"$auto",onValueChange:L=>h(L==="$auto"?"":L),children:[t.jsx(Ot,{className:"w-fit max-w-[200px]",children:t.jsx(Kt,{placeholder:s("settings.voice.page.field.auto")})}),t.jsxs(Lt,{children:[t.jsx(ht,{value:"$auto",children:s("settings.voice.page.field.auto")}),Ee.map(L=>t.jsxs(ht,{value:L.name,children:[L.name," (",L.lang,")"]},L.name))]})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:Ce,title:s("settings.voice.page.actions.preview"),children:me?t.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),t.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.speechRate")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&t.jsx("input",{type:"range",min:.5,max:2,step:.1,value:d,onChange:L=>c(Number(L.target.value)),disabled:!n,className:fe}),t.jsx(xs,{value:d,onValueChange:c,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),t.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.speechPitch")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&t.jsx("input",{type:"range",min:.5,max:2,step:.1,value:x,onChange:L=>m(Number(L.target.value)),disabled:!n,className:fe}),t.jsx(xs,{value:x,onValueChange:m,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),t.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.speechVolume")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&t.jsx("input",{type:"range",min:0,max:1,step:.1,value:p,onChange:L=>u(Number(L.target.value)),disabled:!n,className:fe}),e?t.jsx(xs,{value:Math.round(p*100),onValueChange:L=>u(L/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):t.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(p*100),"%"]})]})]}),t.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.language")}),t.jsx("div",{className:"flex items-center gap-2 w-fit",children:t.jsxs(Ft,{value:a,onValueChange:r,disabled:!n,children:[t.jsx(Ot,{className:"w-fit",children:t.jsx(Kt,{placeholder:s("settings.voice.page.field.selectLanguagePlaceholder")})}),t.jsx(Lt,{children:Bx.map(L=>t.jsx(ht,{value:L.value,children:L.label},L.value))})]})})]})]})]})]}),be&&t.jsxs("div",{"data-settings-item":"voice.speech-recognition",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.voice.page.section.speechRecognition")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.provider")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:t.jsxs("ul",{className:"space-y-1",children:[t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.browser")})," ",s("settings.voice.page.tooltip.sttBrowser")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.server")})," ",s("settings.voice.page.tooltip.sttServer")]})]})})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":U==="browser",onClick:()=>B("browser"),className:"!font-normal",children:s("settings.voice.page.provider.browser")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":U==="server",onClick:()=>B("server"),className:"!font-normal",children:s("settings.voice.page.provider.server")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":U==="wasm",onClick:()=>B("wasm"),className:"!font-normal",children:s("settings.voice.page.provider.wasm")})]})]})}),U==="server"&&t.jsxs("div",{className:"py-1.5 space-y-2",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":he,onClick:()=>Ie(!he),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),Ie(!he))},children:[t.jsx(Pt,{checked:he,onChange:Ie,ariaLabel:s("settings.voice.page.field.transcribeOnStopAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.transcribeOnStop")})]}),!ym.isSupported()&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:s("settings.voice.page.field.sttBrowserSupportError")}),t.jsxs("div",{children:[t.jsx("span",{className:de("typography-ui-label text-foreground",!Q.trim()&&"text-[var(--status-error)]"),children:s("settings.voice.page.field.serverUrl")}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:s("settings.voice.page.field.sttServerUrlHint")}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"text",value:Q,onChange:L=>W(L.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"}),Q&&t.jsx("button",{type:"button",onClick:()=>W(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:"API Key"}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:"Optional"}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"password",value:R,onChange:L=>Y(L.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"}),R&&t.jsx("button",{type:"button",onClick:()=>Y(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.model")}),t.jsx("div",{className:"relative mt-1.5 max-w-xs",children:t.jsx("input",{type:"text",value:F,onChange:L=>H(L.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"})})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.language")}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:s("settings.voice.page.field.sttLanguageHint")}),t.jsx("div",{className:"relative mt-1.5 max-w-[8rem]",children:t.jsx("input",{type:"text",value:Z,onChange:L=>se(L.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"})})]}),t.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.silenceThreshold")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&t.jsx("input",{type:"range",min:-60,max:-20,step:1,value:ce,onChange:L=>oe(Number(L.target.value)),className:fe}),t.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[ce," dB"]})]})]}),t.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.silenceHold")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&t.jsx("input",{type:"range",min:500,max:3e3,step:100,value:xe,onChange:L=>we(Number(L.target.value)),className:fe}),t.jsx(xs,{value:xe,onValueChange:we,min:500,max:3e3,step:100,className:"w-20 tabular-nums"}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.voice.page.field.millisecondsUnit")})]})]})]}),U==="wasm"&&t.jsxs("div",{className:"py-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground",children:s("settings.voice.page.stt.wasmModel")}),t.jsxs(Ft,{value:X,onValueChange:re,children:[t.jsx(Ot,{className:"mt-0.5",children:t.jsx(Kt,{placeholder:s("settings.voice.page.stt.wasmModel")})}),t.jsx(Lt,{children:hi.map(L=>t.jsx(ht,{value:L.id,children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{children:L.name}),t.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[L.size," · ",L.languages]})]})},L.id))})]}),t.jsx("p",{className:"typography-ui-compact text-muted-foreground mt-0.5",children:hi.find(L=>L.id===X)?.description})]}),t.jsx(Vx,{modelId:X})]})]})]}),t.jsxs("div",{"data-settings-item":"voice.playback",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.voice.page.section.playbackAndSummary")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":j,onClick:()=>ve(!j),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),ve(!j))},children:[t.jsx(Pt,{checked:j,onChange:ve,ariaLabel:s("settings.voice.page.field.messageReadAloudButtonAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.messageReadAloudButton")})]}),t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.ttsInputMode")})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":O==="sanitized",onClick:()=>T("sanitized"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeSanitized")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":O==="raw",onClick:()=>T("raw"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeRaw")})]})]})})]}),be&&n&&t.jsx("div",{className:"mt-2 px-2",children:t.jsxs("p",{className:"typography-meta text-muted-foreground",children:[s("settings.voice.page.hint.shiftClickPrefix")," ",t.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"})," + ",t.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"})," ",s("settings.voice.page.hint.shiftClickSuffix")]})})]})]})};function Wx(){Wn.onModelStatusChange=null}const fa=[{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}],xa=[{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}],qx="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",Gx="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",ur=[{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"}],Jx=[".yml",".yaml",".json"],Qx="settings.openchamber.tunnel.error.invalidConfigExtension",_n=s=>{const e=s.trim().toLowerCase();return Jx.some(n=>e.endsWith(n))},Yx=s=>s==="ngrok"?"ngrok":"cloudflared",Xl=()=>{if(typeof window<"u"&&typeof window.__OPENCHAMBER_PLATFORM__=="string"){const e=window.__OPENCHAMBER_PLATFORM__;if(e==="win32"||e==="darwin"||e==="linux")return e}const s=typeof navigator<"u"?`${navigator.platform||""} ${navigator.userAgent||""}`.toLowerCase():"";return s.includes("win")?"win32":s.includes("mac")?"darwin":"linux"},Xx=(s,e=Xl())=>s==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/",pr=(s,e)=>{const n=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():s,a=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():Yx(n),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Xl(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Xx(n,r);return{provider:n,dependency:a,installCommand:i}},Zl=s=>s==="cloudflare"?"Cloudflare":s==="ngrok"?"Ngrok":s,Ho=s=>{const e=rt.c(11),{provider:n}=s;let a;e[0]!==n?(a=Zl(n),e[0]=n,e[1]=a):a=e[1];const r=a,d=n==="cloudflare"||n==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==d?(c=de("size-4 shrink-0",d),e[2]=d,e[3]=c):c=e[3];let x;e[4]!==c?(x=t.jsx(A,{name:"cloud",className:c}),e[4]=c,e[5]=x):x=e[5];let m;e[6]!==r?(m=t.jsx("span",{children:r}),e[6]=r,e[7]=m):m=e[7];let p;return e[8]!==x||e[9]!==m?(p=t.jsxs("span",{className:"flex items-center gap-2",children:[x,m]}),e[8]=x,e[9]=m,e[10]=p):p=e[10],p},Zs=s=>s==="quick"?"quick":s==="managed-remote"?"managed-remote":s==="managed-local"?"managed-local":"quick",Or=(s,e,n)=>s.find(r=>r.ms===e)?.value||n,Wo=(s,e,n)=>{const a=Or(s,e,n);return s.find(r=>r.value===a)?.label||a},qo=s=>{const e=Math.max(0,s),n=Math.floor(e/1e3),a=Math.floor(n/3600),r=Math.floor(n%3600/60),i=n%60;return a>0?`${a}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`},Zx=(s,e)=>Nl(s,e,{hour:"2-digit",precision:"second"}),Aa=s=>{const e=s.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},eb=s=>{if(!Array.isArray(s))return[];const e=new Set,n=new Set,a=[];for(const r of s){if(!r||typeof r!="object")continue;const i=r,o=typeof i.id=="string"?i.id.trim():"",d=typeof i.name=="string"?i.name.trim():"",c=Aa(typeof i.hostname=="string"?i.hostname:"");!o||!d||!c||e.has(o)||n.has(c)||(e.add(o),n.add(c),a.push({id:o,name:d,hostname:c}))}return a},tb=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,sb=()=>{const{t:s}=dt(),e=Ke(ae=>ae.timeFormatPreference),n=l.useCallback(ae=>s(ae),[s]),[a,r]=l.useState("checking"),[i,o]=l.useState(null),[d,c]=l.useState(null),[x,m]=l.useState(null),[p,u]=l.useState(null),[S,f]=l.useState(null),[g,h]=l.useState(!1),[D,k]=l.useState(!1),[w,E]=l.useState(!1),[N,y]=l.useState("cloudflare"),[b,P]=l.useState(()=>pr("cloudflare")),[z,M]=l.useState([]),[I,v]=l.useState("quick"),[j,O]=l.useState(null),[T,U]=l.useState([]),[B,Q]=l.useState({}),[W,R]=l.useState(""),[Y,F]=l.useState({}),[H,X]=l.useState(new Set),[re,Z]=l.useState(!1),[se,ce]=l.useState(""),[oe,xe]=l.useState(""),[we,he]=l.useState(""),[Ie,ve]=l.useState(1800*1e3),[be,ye]=l.useState(480*60*1e3),[te,ie]=l.useState(""),[ge,_]=l.useState([]),[ee,ne]=l.useState(()=>Date.now()),[ue,Me]=l.useState(null),ke=s(Qx),De=l.useRef(null),Ae=l.useMemo(()=>j?!_n(j):!1,[j]),Pe=l.useMemo(()=>T.find(ae=>ae.id===W)||T[0]||null,[T,W]),Re=l.useMemo(()=>ge.map(ae=>{const Ve=ae.expiresAt<=ee,tt=ae.status==="active"&&!Ve,Ye=tt?qo(ae.expiresAt-ee):ae.inactiveReason==="expired"||Ve?"expired":"inactive",bt=Ye==="expired"?s("settings.openchamber.tunnel.state.expired"):ae.inactiveReason==="tunnel-revoked"?s("settings.openchamber.tunnel.state.revoked"):s("settings.openchamber.tunnel.state.inactive"),ze=Zs(ae.mode);return{...ae,isActive:tt,mode:ze,remainingTextForSession:Ye,inactiveLabel:bt}}),[ee,ge,s]),Oe=l.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>ee:!1,[ee,i?.bootstrapExpiresAt,i?.connectUrl]),$e=l.useMemo(()=>!i||a!=="active"&&a!=="stopping"?!1:d===I,[d,a,i,I]),Be=l.useMemo(()=>!i||a!=="active"||!d?!1:d!==I,[d,a,i,I]),Le=l.useMemo(()=>{if(typeof ue=="number"&&Number.isFinite(ue)&&ue>0)return ue;if(typeof window>"u")return null;const Ve=Xn()||window.location.href;let tt=0;try{tt=Number(new URL(Ve).port)}catch{tt=Number(window.location.port)}return Number.isFinite(tt)&&tt>0?tt:null},[ue]),Ue=l.useMemo(()=>z.find(ae=>ae.provider===N)??null,[z,N]),le=l.useMemo(()=>{const ae=new Set(Ue?.modes?.map(Ve=>Ve.key).filter(Ve=>Ve==="quick"||Ve==="managed-remote"||Ve==="managed-local"));return ae.size===0?ur:ur.filter(Ve=>ae.has(Ve.value))},[Ue]),q=l.useMemo(()=>le.some(ae=>ae.value==="managed-remote"||ae.value==="managed-local"),[le]),me=l.useMemo(()=>b.provider===N?b:pr(N),[b,N]),Ne=l.useCallback(async ae=>{await Hs(ae)},[]),Ee=l.useCallback((ae,Ve)=>(P(pr(Ve,ae)),ae.available===!0),[]),Ce=l.useCallback(async(ae,Ve)=>{try{const tt=await jt("/api/openchamber/tunnel/check",{query:{provider:ae},...Ve?{signal:Ve}:{}});if(!tt.ok)return null;const Ye=await tt.json();if(Ve?.aborted)return null;const bt=Ee(Ye,ae);return r(ze=>ze==="checking"||ze==="starting"||ze==="active"||ze==="stopping"?ze:bt?"idle":"not-available"),bt}catch{return null}},[Ee]),He=l.useCallback(async ae=>{try{const[Ve,tt,Ye,bt]=await Promise.all([jt("/api/openchamber/tunnel/check",{signal:ae}),jt("/api/openchamber/tunnel/status",{signal:ae}),jt("/api/config/settings",{signal:ae,headers:{Accept:"application/json"}}),jt("/api/openchamber/tunnel/providers",{signal:ae})]),ze=await Ve.json(),_e=await tt.json(),ot=Ye.ok?await Ye.json():{},yt=bt.ok?await bt.json():{},Mt=_e.ttlConfig?.bootstrapTtlMs??(ot?.tunnelBootstrapTtlMs===null?null:typeof ot?.tunnelBootstrapTtlMs=="number"?ot.tunnelBootstrapTtlMs:1800*1e3),Qt=typeof _e.ttlConfig?.sessionTtlMs=="number"?_e.ttlConfig.sessionTtlMs:typeof ot?.tunnelSessionTtlMs=="number"?ot.tunnelSessionTtlMs:480*60*1e3,Xt=Zs(_e.mode??ot?.tunnelMode),rs=typeof ot?.tunnelProvider=="string"&&ot.tunnelProvider.trim().length>0?ot.tunnelProvider.trim().toLowerCase():"cloudflare",Wt=typeof ot?.managedLocalTunnelConfigPath=="string"&&ot.managedLocalTunnelConfigPath.trim()||null,Se=Ee(ze,rs),vt=eb(_e?.managedRemoteTunnelPresets),Nt=typeof _e.managedRemoteTunnelHostname=="string"?_e.managedRemoteTunnelHostname:"",ct=vt.length>0?vt:Nt?[{id:`legacy-${Aa(Nt)}`,name:Nt,hostname:Aa(Nt)}]:[],St=ct[0]?.id||"";if(ve(Mt),ye(Qt),y(rs),M(Array.isArray(yt?.providers)?yt.providers:[]),v(Xt),O(Wt),U(ct),R(St),_(Array.isArray(_e.activeSessions)?_e.activeSessions:[]),c(_e.activeTunnelMode?Zs(_e.activeTunnelMode):_e.active&&_e.mode?Zs(_e.mode):null),X(new Set(Array.isArray(_e.managedRemoteTunnelTokenPresetIds)?_e.managedRemoteTunnelTokenPresetIds:[])),Me(typeof _e.localPort=="number"?_e.localPort:null),_e.active&&_e.url){o({url:_e.url,connectUrl:null,bootstrapExpiresAt:typeof _e.bootstrapExpiresAt=="number"?_e.bootstrapExpiresAt:null}),r("active");return}r(Se?"idle":"not-available")}catch{ae.aborted||(r("error"),u(s("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Ee,s]);l.useEffect(()=>{const ae=new AbortController;return He(ae.signal),()=>ae.abort()},[He]),l.useEffect(()=>{if(!i?.connectUrl){m(null);return}let ae=!1;return pl.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Ve=>{ae||m(Ve)}).catch(()=>{ae||m(null)}),()=>{ae=!0}},[i?.connectUrl]),l.useEffect(()=>{if(!i?.bootstrapExpiresAt){ie(s("settings.openchamber.tunnel.state.noExpiry"));return}let ae=null,Ve=Date.now();const tt=()=>{const ze=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;ze<=0?ie(s("settings.openchamber.tunnel.state.expired")):ie(qo(ze))},Ye=()=>{const ze=Date.now();ze-Ve>=1e3&&(tt(),Ve=ze),ae=requestAnimationFrame(Ye)};tt(),(typeof document>"u"||document.visibilityState==="visible")&&(ae=requestAnimationFrame(Ye));const bt=()=>{document.visibilityState==="visible"&&ae===null?ae=requestAnimationFrame(Ye):document.visibilityState!=="visible"&&ae!==null&&(cancelAnimationFrame(ae),ae=null)};return document.addEventListener("visibilitychange",bt),()=>{document.removeEventListener("visibilitychange",bt),ae!==null&&cancelAnimationFrame(ae)}},[s,i?.bootstrapExpiresAt]),l.useEffect(()=>{let ae=null,Ve=Date.now();const tt=()=>{const bt=Date.now();bt-Ve>=1e3&&(ne(bt),Ve=bt),ae=requestAnimationFrame(tt)};(typeof document>"u"||document.visibilityState==="visible")&&(ae=requestAnimationFrame(tt));const Ye=()=>{document.visibilityState==="visible"&&ae===null?ae=requestAnimationFrame(tt):document.visibilityState!=="visible"&&ae!==null&&(cancelAnimationFrame(ae),ae=null)};return document.addEventListener("visibilitychange",Ye),()=>{document.removeEventListener("visibilitychange",Ye),ae!==null&&cancelAnimationFrame(ae)}},[]),l.useEffect(()=>{if(a==="starting"||a==="stopping"||a==="checking")return;let ae=!1;const Ve=async()=>{try{const Ye=await jt("/api/openchamber/tunnel/status");if(!Ye.ok||ae)return;const bt=await Ye.json();if(ae)return;_(Array.isArray(bt.activeSessions)?bt.activeSessions:[]),X(new Set(Array.isArray(bt.managedRemoteTunnelTokenPresetIds)?bt.managedRemoteTunnelTokenPresetIds:[])),Me(typeof bt.localPort=="number"?bt.localPort:null)}catch{}},tt=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ve()},5e3);return()=>{ae=!0,window.clearInterval(tt)}},[a]);const G=l.useCallback(async ae=>{E(!0);try{await It(ae),Object.prototype.hasOwnProperty.call(ae,"tunnelMode")&&ae.tunnelMode&&v(ae.tunnelMode),Object.prototype.hasOwnProperty.call(ae,"tunnelProvider")&&typeof ae.tunnelProvider=="string"&&y(ae.tunnelProvider),Object.prototype.hasOwnProperty.call(ae,"managedLocalTunnelConfigPath")&&O(ae.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ae,"managedRemoteTunnelPresets")&&ae.managedRemoteTunnelPresets&&U(ae.managedRemoteTunnelPresets)}catch{V.error(s("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{E(!1)}},[s]),$=l.useCallback(async(ae,Ve)=>{k(!0);try{await It({tunnelBootstrapTtlMs:ae,tunnelSessionTtlMs:Ve})}catch{V.error(s("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{k(!1)}},[s]),fe=l.useCallback(async ae=>{const Ve=ae.token.trim();if(Ve)try{const tt={...Y,[ae.presetId]:Ve};await It({managedRemoteTunnelPresetTokens:tt}),X(Ye=>{const bt=new Set(Ye);return bt.add(ae.presetId),bt})}catch{V.error(s("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[Y,s]),L=l.useCallback(async ae=>{f(null),u(null);const Ve=z.find(Ye=>Ye.provider===ae),tt=Ve?.modes?.some(Ye=>Ye.key===I)?I:Zs(Ve?.modes?.[0]?.key);await G({tunnelProvider:ae,tunnelMode:tt}),Ce(ae)},[z,Ce,G,I]),Fe=l.useCallback(async()=>{const ae=await Cl({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ae.success&&typeof ae.path=="string"&&ae.path.trim().length>0){const Ve=ae.path.trim();if(!_n(Ve)){V.error(ke);return}O(Ve),await G({managedLocalTunnelConfigPath:Ve});return}De.current?.click()},[ke,G]),Je=l.useCallback(ae=>{const Ve=ae.trim();O(Ve.length>0?Ve:null)},[]),Xe=l.useCallback(async()=>{if(j&&!_n(j)){V.error(ke);return}await G({managedLocalTunnelConfigPath:j})},[ke,j,G]),et=l.useCallback(async()=>{O(null),await G({managedLocalTunnelConfigPath:null})},[G]),at=l.useCallback(async ae=>{const Ve=ae.target.files?.[0];if(!Ve)return;const tt=Ve.name.trim();if(tt.length!==0){if(!_n(tt)){V.error(ke);return}O(tt),await G({managedLocalTunnelConfigPath:tt}),ae.target.value=""}},[ke,G]),lt=l.useCallback(async()=>{if(u(null),f(null),I==="managed-local"&&j&&!_n(j)){u(ke),V.error(ke);return}r("starting");try{let ae="",Ve="";if(I==="managed-remote"){if(!Pe){r("idle"),f(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),V.error(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}ae=Pe.hostname,Ve=(Y[Pe.id]||"").trim(),await G({tunnelMode:"managed-remote",managedRemoteTunnelPresets:T})}const tt=await jt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:N,mode:I,...I==="managed-remote"&&Pe?{managedRemoteTunnelPresetId:Pe.id,managedRemoteTunnelPresetName:Pe.name}:{},...I==="managed-remote"&&ae?{managedRemoteTunnelHostname:ae}:{},...I==="managed-remote"&&Ve?{managedRemoteTunnelToken:Ve}:{},...I==="managed-local"&&j?{configPath:j}:{}})}),Ye=await tt.json();if(!tt.ok||!Ye.ok){if(I==="managed-remote"&&typeof Ye.error=="string"&&Ye.error.includes("Managed remote tunnel token is required")){r("idle"),f(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),V.error(s("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(Ye.error||s("settings.openchamber.tunnel.toast.startFailed")),V.error(Ye.error||s("settings.openchamber.tunnel.toast.startFailed"));return}const bt=typeof Ye.url=="string"?Ye.url:"";if(!bt){r("error"),u(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),V.error(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(o({url:bt,connectUrl:typeof Ye.connectUrl=="string"?Ye.connectUrl:null,bootstrapExpiresAt:typeof Ye.bootstrapExpiresAt=="number"?Ye.bootstrapExpiresAt:null}),c(Ye.activeTunnelMode?Zs(Ye.activeTunnelMode):Ye.mode?Zs(Ye.mode):I),_(Array.isArray(Ye.activeSessions)?Ye.activeSessions:[]),Array.isArray(Ye.managedRemoteTunnelTokenPresetIds)&&X(new Set(Ye.managedRemoteTunnelTokenPresetIds)),typeof Ye.localPort=="number"&&Me(Ye.localPort),typeof Ye.mode=="string"&&v(Zs(Ye.mode)),r("active"),Ye.replacedTunnel){const ze=typeof Ye.revokedBootstrapCount=="number"?Ye.revokedBootstrapCount:0,_e=typeof Ye.invalidatedSessionCount=="number"?Ye.invalidatedSessionCount:0;ze===1&&_e===1?V.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):ze===1?V.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:_e})):_e===1?V.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:ze})):V.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:ze,invalidatedSessionCount:_e}))}else V.success(s("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(s("settings.openchamber.tunnel.toast.startFailed")),V.error(s("settings.openchamber.tunnel.toast.startFailed"))}},[ke,T,G,Pe,Y,s,N,I,j]),Ze=l.useCallback(async()=>{r("stopping");try{await jt("/api/openchamber/tunnel/stop",{method:"POST"});const ae=await jt("/api/openchamber/tunnel/status");if(ae.ok){const Ve=await ae.json();_(Array.isArray(Ve.activeSessions)?Ve.activeSessions:[]),X(new Set(Array.isArray(Ve.managedRemoteTunnelTokenPresetIds)?Ve.managedRemoteTunnelTokenPresetIds:[])),Me(typeof Ve.localPort=="number"?Ve.localPort:null)}o(null),c(null),m(null),r("idle"),V.success(s("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(s("settings.openchamber.tunnel.toast.stopFailed")),V.error(s("settings.openchamber.tunnel.toast.stopFailed"))}},[s]),We=l.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),h(!0),V.success(s("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>h(!1),2e3)}catch{V.error(s("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[s,i?.connectUrl]),pt=l.useCallback(async ae=>{const Ve=fa.find(tt=>tt.value===ae);Ve&&(ve(Ve.ms),await $(Ve.ms,be))},[$,be]),pe=l.useCallback(async ae=>{const Ve=xa.find(tt=>tt.value===ae);!Ve||Ve.ms===null||(ye(Ve.ms),await $(Ie,Ve.ms))},[Ie,$]),st=l.useCallback(async ae=>{f(null),u(null),a!=="active"&&a!=="stopping"&&a!=="starting"&&r("idle"),await G({tunnelMode:ae,managedRemoteTunnelPresets:T})},[T,G,a]),nt=l.useCallback(async(ae,Ve)=>{try{await It({managedRemoteTunnelPresets:Ve})}catch{V.error(s("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[s]),Ge=l.useCallback(ae=>{const Ve=T.find(tt=>tt.id===ae);Ve&&(R(Ve.id),f(null),nt(Ve,T))},[T,nt]),ft=l.useCallback(async()=>{const ae=se.trim(),Ve=Aa(oe),tt=we.trim();if(!ae){V.error(s("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Ve){V.error(s("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!tt){V.error(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(T.some(ze=>ze.hostname===Ve)){V.error(s("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ye={id:tb(),name:ae,hostname:Ve},bt=[...T,Ye];U(bt),R(Ye.id),Q(ze=>({...ze,[Ye.id]:!0})),F(ze=>({...ze,[Ye.id]:tt})),f(null),Z(!1),ce(""),xe(""),he(""),await G({tunnelMode:"managed-remote",managedRemoteTunnelPresets:bt,managedRemoteTunnelPresetTokens:{...Y,[Ye.id]:tt}}),await fe({presetId:Ye.id,presetName:Ye.name,hostname:Ye.hostname,token:tt}),V.success(s("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[T,oe,se,we,fe,G,Y,s]),wt=l.useCallback(async ae=>{const Ve=T.find(_e=>_e.id===ae);if(!Ve)return;const tt=T.filter(_e=>_e.id!==Ve.id),Ye=tt[0]?.id||"",bt=W===Ve.id?Ye:W,ze=Object.fromEntries(Object.entries(Y).filter(([_e,ot])=>_e!==Ve.id&&ot.trim().length>0));U(tt),R(bt),Q(_e=>{const ot={..._e};return delete ot[Ve.id],ot}),F(_e=>{const ot={..._e};return delete ot[Ve.id],ot}),X(_e=>{const ot=new Set(_e);return ot.delete(Ve.id),ot}),f(null),await G({managedRemoteTunnelPresets:tt,managedRemoteTunnelPresetTokens:ze}),V.success(s("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[T,G,W,Y,s]),Ct="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 a==="checking"?t.jsx("div",{className:"flex items-center justify-center py-12",children:t.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":s("settings.openchamber.tunnel.state.loading")})}):t.jsxs("div",{className:"space-y-6",children:[t.jsxs("div",{children:[t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.openchamber.tunnel.title")}),t.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/70",children:s("settings.openchamber.tunnel.description")}),t.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:s("settings.openchamber.tunnel.note.serverSideEnforced")}),t.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:s("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),Re.length>0&&t.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:t.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[t.jsx(A,{name:"information",className:"size-4 text-[var(--status-info)]"}),t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),t.jsx("div",{className:"space-y-1",children:Re.map(ae=>{const Ve=ae.mode==="quick",tt=ae.mode==="managed-remote",Ye=Ve?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":tt?"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)]",bt=ae.isActive?Ve?"text-[var(--status-warning)]":tt?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",ze=s(Ve?"settings.openchamber.tunnel.badge.quick":tt?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return t.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:[t.jsx(A,{name:"checkbox-blank-circle-fill",className:de("size-2.5 shrink-0",bt)}),t.jsx("span",{className:de("typography-micro rounded border px-1.5 py-0.5 uppercase",Ye),children:ze}),t.jsx("span",{className:"typography-meta text-muted-foreground/80",children:s("settings.openchamber.tunnel.session.redeemedAt",{time:Zx(ae.createdAt,e)})}),t.jsx("span",{className:"typography-meta text-foreground",children:ae.isActive?s("settings.openchamber.tunnel.session.expiresIn",{remaining:ae.remainingTextForSession}):ae.inactiveLabel===s("settings.openchamber.tunnel.state.inactive")?s("settings.openchamber.tunnel.state.inactive"):s("settings.openchamber.tunnel.session.inactiveWithReason",{reason:ae.inactiveLabel})})]},ae.sessionId)})})]})}),a==="not-available"&&t.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:t.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[t.jsx(A,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"typography-meta font-medium text-foreground",children:s("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:me.dependency})}),t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.openchamber.tunnel.notAvailable.installHint")}),t.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:me.installCommand})]})]})}),t.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{"data-settings-item":"tunnel.provider",className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.field.provider")}),t.jsxs(Ft,{value:N,onValueChange:ae=>{L(ae)},disabled:w||a==="starting"||a==="stopping",children:[t.jsx(Ot,{className:"max-w-[16rem]",children:t.jsx(Kt,{placeholder:s("settings.openchamber.tunnel.field.providerPlaceholder"),children:Zl(N)})}),t.jsxs(Lt,{children:[z.length>0?z.map(ae=>t.jsx(ht,{value:ae.provider,children:t.jsx(Ho,{provider:ae.provider})},ae.provider)):t.jsx(ht,{value:"cloudflare",children:t.jsx(Ho,{provider:"cloudflare"})}),t.jsx(ht,{value:"__more-soon",disabled:!0,children:s("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),t.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.field.tunnelType")}),t.jsx("div",{className:"flex flex-wrap items-center gap-1",children:le.map(ae=>t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(J,{variant:"chip",size:"xs","aria-pressed":I===ae.value,className:"!font-normal",onClick:()=>{st(ae.value)},disabled:w||a==="starting"||a==="stopping",children:n(ae.labelKey)})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:n(ae.tooltipKey)})]},ae.value))})]})]}),t.jsxs("div",{"data-settings-item":"tunnel.ttl",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:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:s("settings.openchamber.tunnel.field.connectLinkTtl")}),t.jsxs(Ft,{value:Or(fa,Ie,"1800000"),onValueChange:ae=>{pt(ae)},disabled:D||w||a==="starting"||a==="stopping",children:[t.jsx(Ot,{className:"max-w-[11rem] min-w-0",children:t.jsx(Kt,{className:"truncate",children:Wo(fa,Ie,"1800000")})}),t.jsx(Lt,{children:fa.map(ae=>t.jsx(ht,{value:ae.value,children:ae.label},ae.value))})]})]}),t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:s("settings.openchamber.tunnel.field.tunnelSessionTtl")}),t.jsxs(Ft,{value:Or(xa,be,"28800000"),onValueChange:ae=>{pe(ae)},disabled:D||w||a==="starting"||a==="stopping",children:[t.jsx(Ot,{className:"max-w-[11rem] min-w-0",children:t.jsx(Kt,{className:"truncate",children:Wo(xa,be,"28800000")})}),t.jsx(Lt,{children:xa.map(ae=>t.jsx(ht,{value:ae.value,children:ae.label},ae.value))})]})]})]}),I==="quick"&&t.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(A,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),t.jsxs("div",{children:[t.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:s("settings.openchamber.tunnel.option.mode.quick.tooltip")}),q&&t.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:s("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),I==="managed-remote"&&t.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Le=="number"&&t.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:t.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[s("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",t.jsxs("code",{children:["http://localhost:",Le]})]})}),t.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),t.jsxs(J,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Z(ae=>!ae),disabled:a==="starting"||a==="stopping"||w,children:[t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),s("settings.common.actions.create")]})]}),T.length>0?t.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:T.map((ae,Ve)=>{const tt=Y[ae.id]||"",Ye=H.has(ae.id),bt=B[ae.id]??!1;return t.jsx("div",{className:de(Ve<T.length-1&&"border-b border-[var(--surface-subtle)]"),children:t.jsxs(gn,{open:bt,onOpenChange:ze=>{Q(_e=>({..._e,[ae.id]:ze})),ze&&Ge(ae.id)},className:"py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-2 px-3",children:[t.jsxs(hn,{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:a==="starting"||a==="stopping"||w,children:[bt?t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):t.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),t.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:ae.name})]}),t.jsx(J,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":s("settings.openchamber.tunnel.actions.removePresetAria",{name:ae.name}),onClick:()=>{wt(ae.id)},disabled:a==="starting"||a==="stopping"||w,children:t.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(fn,{className:"pt-1.5",children:t.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[t.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[s("settings.openchamber.tunnel.field.hostnameLabel")," ",t.jsx("code",{children:ae.hostname})]}),t.jsx(it,{type:"password",value:tt,onChange:ze=>{const _e=ze.target.value;f(null),F(ot=>({...ot,[ae.id]:_e}))},onBlur:ze=>{const _e=ze.currentTarget.value.trim();_e&&fe({presetId:ae.id,presetName:ae.name,hostname:ae.hostname,token:_e})},placeholder:s(Ye?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:a==="starting"||a==="stopping"}),t.jsx("div",{className:"flex items-center justify-end",children:t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal",disabled:a==="starting"||a==="stopping"||tt.trim().length===0,onClick:()=>{fe({presetId:ae.id,presetName:ae.name,hostname:ae.hostname,token:tt})},children:s("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},ae.id)})}):t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),re&&t.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[t.jsx(it,{value:se,onChange:ae=>ce(ae.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||a==="starting"||a==="stopping"}),t.jsx(it,{value:oe,onChange:ae=>xe(ae.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||a==="starting"||a==="stopping"}),t.jsx(it,{type:"password",value:we,onChange:ae=>he(ae.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||a==="starting"||a==="stopping"}),typeof Le=="number"&&t.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[s("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",t.jsxs("code",{children:["http://localhost:",Le]}),"."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ft()},disabled:w||a==="starting"||a==="stopping",children:s("settings.common.actions.saveChanges")}),t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Z(!1),ce(""),xe(""),he("")},disabled:w||a==="starting"||a==="stopping",children:s("settings.common.actions.cancel")})]})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("p",{className:"typography-meta text-muted-foreground/80",children:s("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground/70 hover:text-foreground","aria-label":s("settings.openchamber.tunnel.field.managedRemoteTokenInfoAria"),children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:s("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!Pe&&S&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:S})]}),I==="managed-local"&&t.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.field.configurationFile")}),t.jsx("input",{ref:De,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:ae=>{at(ae)}}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(it,{value:j||"",onChange:ae=>{Je(ae.target.value)},onBlur:()=>{Xe()},placeholder:s("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:a==="starting"||a==="stopping"||w}),t.jsx(J,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Fe()},disabled:a==="starting"||a==="stopping"||w,children:t.jsx(A,{name:"folder",className:"size-3.5"})}),j&&t.jsx(J,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{et()},disabled:a==="starting"||a==="stopping"||w,children:t.jsx(A,{name:"close",className:"size-3.5"})})]}),t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s(j?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Ae&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ke})]})}),!$e&&t.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[t.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(A,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),t.jsxs("div",{className:"space-y-1",children:[I==="managed-remote"&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:s("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),t.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:()=>{Ne(qx)},children:[s("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),t.jsx(A,{name:"external-link",className:"size-3.5"})]})]}),I==="managed-local"&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:s("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),t.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:()=>{Ne(Gx)},children:[s("settings.openchamber.tunnel.actions.openManagedLocalDocs"),t.jsx(A,{name:"external-link",className:"size-3.5"})]})]}),t.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:s("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:n(ur.find(ae=>ae.value===I)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),I==="managed-remote"&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),t.jsxs(Ft,{value:W||(T[0]?.id??""),onValueChange:ae=>{Ge(ae)},disabled:w||a==="starting"||a==="stopping"||T.length<=1,children:[t.jsx(Ot,{children:t.jsx(Kt,{placeholder:s("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Pe?.name})}),t.jsx(Lt,{fitContent:!0,children:T.map(ae=>t.jsx(ht,{value:ae.id,children:ae.name},ae.id))})]})]}),Be&&t.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(A,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),t.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:s("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),t.jsx(J,{size:"sm",variant:"outline",onClick:lt,disabled:a==="starting"||w||I==="managed-remote"&&!Pe||I==="managed-local"&&Ae,className:de(Ct,a==="starting"&&"opacity-70"),children:a==="starting"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"})," ",s("settings.openchamber.tunnel.actions.startingTunnel")]}):s("settings.openchamber.tunnel.actions.startTunnel")})]})]}),$e&&i&&t.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),t.jsx("p",{className:"typography-meta font-medium text-foreground",children:s("settings.openchamber.tunnel.state.tunnelReady")})]}),t.jsxs("div",{children:[t.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:s("settings.openchamber.tunnel.field.publicUrlHint")}),t.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.url})]}),Oe&&i.connectUrl&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:s("settings.openchamber.tunnel.field.connectLink")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.connectUrl}),t.jsxs(J,{size:"sm",variant:"ghost",onClick:We,className:"shrink-0 gap-1.5",children:[g?t.jsx(A,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):t.jsx(A,{name:"file-copy",className:"size-3.5"}),s(g?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),t.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[s("settings.openchamber.tunnel.field.expires"),": ",i.bootstrapExpiresAt?te:s("settings.openchamber.tunnel.state.never")]})]}),t.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[x?t.jsx("img",{src:x,alt:s("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):t.jsx("div",{className:"size-48 rounded bg-muted/30"}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),t.jsx("div",{className:"pt-1",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(J,{size:"sm",variant:"outline",onClick:lt,disabled:a==="stopping"||w||I==="managed-local"&&Ae,className:Ct,children:[t.jsx(A,{name:"restart",className:"size-3.5"}),s("settings.openchamber.tunnel.actions.newConnectLink")]}),t.jsx(J,{size:"sm",variant:"ghost",onClick:Ze,disabled:a==="stopping"||w,className:"gap-2 text-[var(--status-error)]",children:a==="stopping"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"})," ",s("settings.openchamber.tunnel.actions.stopping")]}):s("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),a==="error"&&p&&t.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:p}),t.jsx(J,{size:"sm",variant:"ghost",onClick:lt,children:s("settings.openchamber.tunnel.actions.retry")})]})]})},ec=()=>{const{t:s}=dt(),[e,n]=je.useState(""),[a,r]=je.useState(!0),[i,o]=je.useState(!1),d=Ke(u=>u.showOpenCodeUpdateNotifications),c=Ke(u=>u.setShowOpenCodeUpdateNotifications);je.useEffect(()=>{let u=!1;return(async()=>{try{const S=await jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const f=await S.json().catch(()=>null);if(u||!f)return;const g=typeof f.opencodeBinary=="string"?f.opencodeBinary.trim():"";n(g)}catch{}finally{u||r(!1)}})(),()=>{u=!0}},[]);const x=je.useCallback(async()=>{if(!(typeof window>"u")&&fs())try{const u=await Cl();u.success&&u.path&&u.path.trim().length>0&&n(u.path.trim())}catch{}},[]),m=je.useCallback(async()=>{o(!0);try{await It({opencodeBinary:e.trim()}),await In({message:s("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{o(!1)}},[s,e]),p=je.useCallback(u=>{c(u),It({showOpenCodeUpdateNotifications:u})},[c]);return t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.opencodeCli.title")}),t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(Et,{sideOffset:8,className:"max-w-xs",children:[s("settings.openchamber.opencodeCli.tooltipPrefix")," ",t.jsx("code",{className:"font-mono text-xs",children:"opencode"}),s("settings.openchamber.opencodeCli.tooltipSuffix")]})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[t.jsxs("div",{"data-settings-item":"sessions.opencode-binary",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-3",children:[t.jsx("div",{className:"flex min-w-0 flex-col shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.opencodeCli.field.binaryPath")})}),t.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:w-[20rem]",children:[t.jsx(it,{value:e,onChange:u=>n(u.target.value),placeholder:s("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:a||i,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),t.jsx(J,{type:"button",variant:"outline",size:"xs",onClick:x,disabled:a||i||!fs(),className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.opencodeCli.actions.browseAria"),title:s("settings.openchamber.opencodeCli.actions.browse"),children:t.jsx(A,{name:"folder",className:"h-4 w-4"})})]})]}),t.jsx("div",{className:"py-1.5",children:t.jsxs("div",{className:"typography-micro text-muted-foreground/70",children:[s("settings.openchamber.opencodeCli.tipPrefix")," ",t.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",s("settings.openchamber.opencodeCli.tipMiddle")," ",t.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]})}),t.jsxs("label",{"data-settings-item":"sessions.opencode-update-notifications",className:"flex cursor-pointer items-center gap-2 py-1.5",children:[t.jsx(Pt,{checked:d,onChange:p,ariaLabel:s("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.opencodeCli.field.showUpdateNotifications")})]}),t.jsx("div",{className:"flex justify-start py-1.5",children:t.jsx(J,{type:"button",size:"xs",onClick:m,disabled:a||i,className:"shrink-0 !font-normal",children:s(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},tc=()=>{const{t:s}=dt(),e=fs()&&ea(),[n,a]=je.useState(!1),[r,i]=je.useState(!1),[o,d]=je.useState(""),[c,x]=je.useState(""),[m,p]=je.useState(!1),[u,S]=je.useState(null),[f,g]=je.useState(!0),[h,D]=je.useState(!1),[k,w]=je.useState(!1),[E,N]=je.useState(!1),[y,b]=je.useState(!1),[P,z]=je.useState(null),[M,I]=je.useState(null);je.useEffect(()=>{if(!e){g(!1);return}let F=!1;return(async()=>{try{const H=await jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!H.ok)throw new Error(s("settings.openchamber.desktopNetwork.error.loadFailed"));const X=await H.json().catch(()=>null);if(F)return;const re=X?.desktopLanAccessEnabled===!0,Z=typeof X?.desktopUiPassword=="string"?X.desktopUiPassword:"";a(re),i(re),d(Z),x(Z),p(X?.desktopLanAccessActive===!0),S(typeof X?.desktopLanAccessBlockedReason=="string"?X.desktopLanAccessBlockedReason:null),z(null)}catch(H){F||z(H instanceof Error?H.message:s("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{F||g(!1)}})(),()=>{F=!0}},[e,s]),je.useEffect(()=>{if(!e){w(!1);return}let F=!1;return(async()=>{const H=await Hm();F||(w(H?.supported===!0),N(H?.enabled===!0))})(),()=>{F=!0}},[e]),je.useEffect(()=>{if(!e||!r){I(null);return}let F=!1;return(async()=>{const H=await Wm();F||I(H)})(),()=>{F=!0}},[r,e]);const v=r!==n||c!==o,j=je.useMemo(()=>{if(typeof window>"u")return null;const H=Xn()||window.location.href;let X=0;try{X=Number(new URL(H).port)}catch{X=Number(window.location.port)}return Number.isFinite(X)&&X>0?X:null},[]),O=r&&m&&M&&j?`http://${M}:${j}`:null,T=r&&!c.trim(),U=n&&!m&&u==="missing-password",B=f||h||!v||T,Q=je.useCallback(()=>{i(F=>!F)},[]),W=je.useCallback(F=>{x(F),F.trim()||i(!1)},[]),R=je.useCallback(async()=>{if(!k||y)return;const F=!E;N(F),b(!0),z(null);try{const H=await qm(F);if(!H?.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));N(H.enabled)}catch(H){N(!F),z(H instanceof Error?H.message:s("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{b(!1)}},[y,E,k,s]),Y=je.useCallback(async()=>{if(v){D(!0),z(null);try{if(!(await jt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:c})})).ok)throw new Error(s("settings.openchamber.desktopNetwork.error.saveFailed"));if(a(r),d(c),!await Gm())throw new Error(s("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(F){z(F instanceof Error?F.message:s("settings.openchamber.desktopNetwork.error.saveFailed")),D(!1)}}},[c,r,v,s]);return e?t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.desktopNetwork.title")})}),t.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[k?t.jsxs("div",{"data-settings-item":"sessions.desktop-launch-at-login",className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:R,onKeyDown:F=>{(F.key==="Enter"||F.key===" ")&&(F.preventDefault(),R())},children:[t.jsx(Pt,{checked:E,onChange:R,ariaLabel:s("settings.openchamber.desktopNetwork.field.launchAtLoginAria"),disabled:y}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.desktopNetwork.field.launchAtLogin")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.launchAtLoginDescription")})]})]}):null,t.jsxs("div",{"data-settings-item":"sessions.desktop-ui-password",className:"space-y-1 py-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",htmlFor:"desktop-ui-password",children:s("settings.openchamber.desktopPassword.field.password")}),t.jsx(it,{id:"desktop-ui-password",type:"password",className:"h-7 max-w-sm",value:c,onChange:F=>W(F.target.value),placeholder:s("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:f||h,required:r,"aria-invalid":T}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopPassword.field.passwordDescription")})]}),t.jsxs("div",{"data-settings-item":"sessions.desktop-lan-access",className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:Q,onKeyDown:F=>{(F.key==="Enter"||F.key===" ")&&(F.preventDefault(),Q())},children:[t.jsx(Pt,{checked:r,onChange:Q,ariaLabel:s("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:f||h}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.desktopNetwork.field.allowLanAccess")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.allowLanAccessDescription")}),t.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:s("settings.openchamber.desktopNetwork.field.warning")}),T||U?t.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:s("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]})]}),P?t.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:P}):null,O?t.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[s(v&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),t.jsx("span",{className:"font-mono text-foreground",children:O})]}):null,t.jsx("div",{className:"flex justify-start py-1.5",children:t.jsx(J,{type:"button",size:"xs",onClick:Y,disabled:B,className:"shrink-0 !font-normal",children:s(h?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},nb=new Set(["shift","control","alt","meta"]),ab=s=>{if(nb.has(s.key.toLowerCase()))return null;const e=[];(s.metaKey||s.ctrlKey)&&e.push("mod"),s.shiftKey&&e.push("shift"),s.altKey&&e.push("alt");const n=wm(s.key);return n?(e.push(n),wn(e.join("+"))):null},rb=()=>{const s=rt.c(61),{t:e}=dt();let n;s[0]!==e?(n=oe=>e(oe),s[0]=e,s[1]=n):n=s[1];const a=n,r=Ke(ib),i=Ke(ob),o=Ke(lb),d=Ke(cb);let c;s[2]===Symbol.for("react.memo_cache_sentinel")?(c=vm(),s[2]=c):c=s[2];const x=c;let m;s[3]!==a?(m=(oe,xe)=>{const we=`settings.openchamber.keyboardShortcuts.action.${oe}.label`,he=a(we);return he===we?xe:he},s[3]=a,s[4]=m):m=s[4];const p=m,[u,S]=l.useState(null);let f;s[5]===Symbol.for("react.memo_cache_sentinel")?(f={},s[5]=f):f=s[5];const[g,h]=l.useState(f),[D,k]=l.useState(""),[w,E]=l.useState(""),[N,y]=l.useState(null),b=db;let P;s[6]!==r?(P=(oe,xe)=>{const we=wn(xe);for(const he of x){if(he.id===oe)continue;const Ie=fi(he.id,r);if(wn(Ie)===we)return he.id}return null},s[6]=r,s[7]=P):P=s[7];const z=P;let M;s[8]!==z||s[9]!==i||s[10]!==r||s[11]!==e?(M=(oe,xe)=>{const we=wn(xe),he=z(oe,we);if(he){y({actionId:oe,combo:we,conflictActionId:he}),k("");return}const Ie={...r,[oe]:we};i(oe,we),b(Ie),y(null),k(""),E(xi(we)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),h(ve=>{const be={...ve};return delete be[oe],be})},s[8]=z,s[9]=i,s[10]=r,s[11]=e,s[12]=M):M=s[12];const I=M;let v;s[13]!==N||s[14]!==i||s[15]!==r||s[16]!==e?(v=()=>{if(!N)return;const oe={...r,[N.conflictActionId]:bi,[N.actionId]:N.combo};i(N.conflictActionId,bi),i(N.actionId,N.combo),b(oe),y(null),k(""),E(xi(N.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),h(xe=>{const we={...xe};return delete we[N.actionId],we})},s[13]=N,s[14]=i,s[15]=r,s[16]=e,s[17]=v):v=s[17];const j=v;let O;s[18]!==o||s[19]!==r?(O=oe=>{const xe={...r};delete xe[oe],o(oe),b(xe),h(we=>{const he={...we};return delete he[oe],he}),y(null),k(""),E("")},s[18]=o,s[19]=r,s[20]=O):O=s[20];const T=O;let U;s[21]!==e?(U=e("settings.openchamber.keyboardShortcuts.title"),s[21]=e,s[22]=U):U=s[22];let B;s[23]!==U?(B=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:U}),s[23]=U,s[24]=B):B=s[24];let Q;s[25]!==d?(Q=()=>{d(),b({}),h({}),y(null),k(""),E("")},s[25]=d,s[26]=Q):Q=s[26];let W;s[27]!==e?(W=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),s[27]=e,s[28]=W):W=s[28];let R;s[29]!==Q||s[30]!==W?(R=t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Q,children:W}),s[29]=Q,s[30]=W,s[31]=R):R=s[31];let Y;s[32]===Symbol.for("react.memo_cache_sentinel")?(Y=t.jsx(At,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[32]=Y):Y=s[32];let F;s[33]!==e?(F=e("settings.openchamber.keyboardShortcuts.tooltip"),s[33]=e,s[34]=F):F=s[34];let H;s[35]!==F?(H=t.jsxs(Dt,{children:[Y,t.jsx(Et,{sideOffset:8,className:"max-w-xs",children:F})]}),s[35]=F,s[36]=H):H=s[36];let X;s[37]!==R||s[38]!==H||s[39]!==B?(X=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[B,R,H]})}),s[37]=R,s[38]=H,s[39]=B,s[40]=X):X=s[40];let re;s[41]!==j||s[42]!==D||s[43]!==N||s[44]!==e||s[45]!==w?(re=(D||w||N)&&t.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[N&&t.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:[t.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),t.jsxs("div",{className:"flex gap-2 shrink-0",children:[t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:j,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),t.jsx(J,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>y(null),children:e("settings.common.actions.cancel")})]})]}),D&&t.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:D}),w&&t.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:w})]}),s[41]=j,s[42]=D,s[43]=N,s[44]=e,s[45]=w,s[46]=re):re=s[46];let Z;s[47]!==p||s[48]!==u||s[49]!==g||s[50]!==T||s[51]!==I||s[52]!==r||s[53]!==e?(Z=x.map((oe,xe)=>{const we=fi(oe.id,r),he=g[oe.id],Ie=he??we,ve=typeof he=="string"&&wn(he)!==wn(we);return t.jsxs("div",{className:de("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",xe>0&&"border-t border-[var(--surface-subtle)]"),children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:p(oe.id,oe.label)})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsx(it,{readOnly:!0,value:u===oe.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):jm(Ie),onFocus:()=>{S(oe.id),k("")},onBlur:()=>{u===oe.id&&S(null)},onKeyDown:be=>{if(be.preventDefault(),be.stopPropagation(),be.key==="Escape"){S(null);return}const ye=ab(be);ye&&(h(te=>({...te,[oe.id]:ye})),S(null),y(null),k(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),t.jsx(J,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const be=g[oe.id];if(!be){k(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}I(oe.id,be)},disabled:!ve,children:e("settings.common.actions.saveChanges")}),t.jsx(J,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>T(oe.id),children:e("settings.common.actions.reset")})]})]},oe.id)}),s[47]=p,s[48]=u,s[49]=g,s[50]=T,s[51]=I,s[52]=r,s[53]=e,s[54]=Z):Z=s[54];let se;s[55]!==Z?(se=t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:Z}),s[55]=Z,s[56]=se):se=s[56];let ce;return s[57]!==X||s[58]!==re||s[59]!==se?(ce=t.jsxs("div",{"data-settings-item":"shortcuts.keyboard-shortcuts",className:"mb-8",children:[X,re,se]}),s[57]=X,s[58]=re,s[59]=se,s[60]=ce):ce=s[60],ce};function ib(s){return s.shortcutOverrides}function ob(s){return s.setShortcutOverride}function lb(s){return s.clearShortcutOverride}function cb(s){return s.resetAllShortcutOverrides}function db(s){It({shortcutOverrides:s})}const sc=()=>{const s=rt.c(2),[e,n]=l.useState(0);let a,r;return s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>Jm(()=>n(jb)),r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),l.useEffect(a,r),e},mb=s=>{const e=rt.c(20),{section:n}=s,{isMobile:a}=Cs();sc();let r;e[0]!==a?(r=a&&mn(),e[0]=a,e[1]=r):r=e[1];const i=r;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=gs(),e[2]=o):o=e[2];const d=o;let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=fs()&&ea(),e[3]=c):c=e[3];const x=c;if(!n){let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx(Gr,{}),e[4]=f):f=e[4];let g,h,D;e[5]===Symbol.for("react.memo_cache_sentinel")?(g=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Yl,{})}),h=x&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(tc,{})}),D=!d&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(ec,{})}),e[5]=g,e[6]=h,e[7]=D):(g=e[5],h=e[6],D=e[7]);let k;e[8]===Symbol.for("react.memo_cache_sentinel")?(k=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Jl,{})}),e[8]=k):k=e[8];let w;e[9]===Symbol.for("react.memo_cache_sentinel")?(w=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Ql,{})}),e[9]=w):w=e[9];let E;e[10]!==i?(E=i&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Dl,{})}),e[10]=i,e[11]=E):E=e[11];let N;return e[12]!==E?(N=t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[f,g,h,D,k,w,E]})}),e[12]=E,e[13]=N):N=e[13],N}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return t.jsx(pb,{});case"chat":return t.jsx(gb,{});case"sessions":return t.jsx(hb,{});case"shortcuts":return t.jsx(ub,{});case"git":return t.jsx(fb,{});case"github":return t.jsx(xb,{});case"notifications":return t.jsx(bb,{});case"voice":return t.jsx(yb,{});case"tunnel":return t.jsx(vb,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const p=m;let u;e[16]!==p?(u=p(),e[16]=p,e[17]=u):u=e[17];let S;return e[18]!==u?(S=t.jsx(Jt,{outerClassName:"h-full",className:"w-full",children:t.jsx("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",children:u})}),e[18]=u,e[19]=S):S=e[19],S},ub=()=>{const s=rt.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(rb,{}),s[0]=e):e=s[0],e},pb=()=>{const s=rt.c(3);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=gs(),s[0]=e):e=s[0];const n=e;let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=n?[]:["weekStart"],s[1]=a):a=s[1];let r;return s[2]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(Gr,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a,"fontSize","terminalFontSize","fileEditorKeymap","spacing","inputBarOffset","expandedEditorToolbar",...n?[]:["terminalQuickKeys"],"reportUsage"]}),s[2]=r):r=s[2],r},gb=()=>{const s=rt.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Gr,{visibleSettings:["chatRenderMode","messageTransport","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader","wideChatLayout","splitAssistantMessageActions","diffLayout","dotfiles","fileViewerPreview","queueMode","persistDraft","inputSpellcheck"]}),s[0]=e):e=s[0],e},hb=()=>{const s=rt.c(7);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=gs(),s[0]=e):e=s[0];const n=e;sc();let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=fs()&&ea(),s[1]=a):a=s[1];const r=a;let i,o,d;s[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(Yl,{}),o=r&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(tc,{})}),d=!n&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(ec,{})}),s[2]=i,s[3]=o,s[4]=d):(i=s[2],o=s[3],d=s[4]);let c;s[5]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Jl,{})}),s[5]=c):c=s[5];let x;return s[6]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsxs("div",{className:"space-y-6",children:[i,o,d,c,t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Ql,{})})]}),s[6]=x):x=s[6],x},fb=()=>{const s=rt.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx("div",{className:"space-y-6",children:t.jsx(Wl,{})}),s[0]=e):e=s[0],e},xb=()=>{const s=rt.c(1);if(gs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(ql,{}),s[0]=e):e=s[0],e},bb=()=>{const s=rt.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Ux,{}),s[0]=e):e=s[0],e},yb=()=>{const s=rt.c(1);if(gs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Hx,{}),s[0]=e):e=s[0],e},vb=()=>{const s=rt.c(1);if(gs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(sb,{}),s[0]=e):e=s[0],e};function jb(s){return s+1}const nc=[{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:"single",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:s=>!s.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:"plugins",title:"Plugins",group:"opencode",kind:"split",keywords:["plugin","plugins","extensions","addons","npm","opencode-wakatime"]},{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:s=>!s.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:s=>!s.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:s=>!s.isVSCode},{slug:"snippets",title:"Snippets",group:"general",kind:"split",keywords:["prompt","templates","multi-run","strategy","approach"]},{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:s=>!s.isVSCode},{slug:"tunnel",title:"Remote Tunnel",group:"advanced",kind:"single",keywords:["tunnel","cloudflare","qr","remote","mobile","share"],isAvailable:s=>!s.isVSCode},{slug:"about",title:"About",group:"advanced",kind:"single",keywords:["about","version","updates","release","changelog"],isAvailable:s=>s.isMobile}],wb={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function Pn(s){const e=s.trim().toLowerCase();return nc.find(n=>n.slug===e)??null}function Jr(s){const e=(s??"").trim().toLowerCase();if(!e)return"home";const n=wb[e];if(n)return n;const a=Pn(e);return a?a.slug:"home"}const Nb=[{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.openchamber.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.openchamber.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"],isAvailable:s=>!s.isVSCode},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:s=>!s.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:s=>!s.isVSCode},{id:"appearance.window-transparency",page:"appearance",titleKey:"settings.openchamber.visual.field.macVibrancy",descriptionKey:"settings.openchamber.visual.field.macVibrancyHint",keywords:["transparent","transparency","vibrancy","blur","macos","opaque"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:s=>s.isWeb&&!s.isDesktop&&!s.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:s=>s.isWeb&&!s.isDesktop&&!s.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.openchamber.visual.field.mobileKeyboardMode",descriptionKey:"settings.openchamber.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:s=>s.isMobile&&s.isWeb&&!s.isDesktop&&!s.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:s=>!s.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"]},{id:"appearance.expanded-editor-toolbar",page:"appearance",titleKey:"settings.openchamber.visual.field.expandedEditorToolbar",keywords:["editor","toolbar","tabs","docked","files"]},{id:"appearance.file-editor-keymap",page:"appearance",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.terminal-quick-keys",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:s=>!s.isMobile&&!s.isVSCode},{id:"appearance.usage-reports",page:"appearance",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"chat",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:s=>!s.isVSCode},{id:"chat.queue-mode",page:"chat",titleKey:"settings.openchamber.visual.field.queueMessagesByDefault",descriptionKey:"settings.openchamber.visual.field.queueMessagesByDefaultTooltip",keywords:["queue","enter","send"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:s=>!s.isMobile},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.openchamber.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"sessions",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"sessions",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:s=>!s.isVSCode},{id:"sessions.opencode-update-notifications",page:"sessions",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:s=>!s.isVSCode},{id:"git.github-account",page:"git",titleKey:"settings.github.page.actions.connect",keywords:["github","account","oauth","prs","issues"]},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.openchamber.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.openchamber.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.openchamber.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.header-menu",page:"usage",titleKey:"settings.usage.page.options.showInHeader",descriptionKey:"settings.usage.page.options.showInHeaderTooltip",keywords:["quota","header","dropdown"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.accent-color",page:"projects",titleKey:"settings.projects.page.field.accentColor",keywords:["color","appearance","project metadata"]},{id:"projects.icon",page:"projects",titleKey:"settings.projects.page.field.projectIcon",keywords:["icon","favicon","upload","project metadata"]},{id:"projects.worktree",page:"projects",titleKey:"settings.projects.page.section.worktree",keywords:["worktree","branch","repository"]},{id:"projects.worktree.setup.wait",page:"projects",titleKey:"settings.openchamber.worktrees.setup.waitForCommands",keywords:["worktree","setup commands","bootstrap","wait"]},{id:"remote-instances.client-auth",page:"remote-instances",titleKey:"settings.remoteInstances.clientAuth.title",descriptionKey:"settings.remoteInstances.clientAuth.description",keywords:["pairing link","client token","connect desktop","remote access"],isAvailable:s=>!s.isVSCode},{id:"remote-instances.direct-hosts",page:"remote-instances",titleKey:"settings.remoteInstances.direct.title",descriptionKey:"settings.remoteInstances.direct.description",keywords:["server url","connection token","import link","host switcher"],isAvailable:s=>s.isDesktop},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.auth",page:"providers",titleKey:"settings.providers.page.auth.title",keywords:["api key","oauth","credentials"]},{id:"providers.connection-details",page:"providers",titleKey:"settings.providers.page.connectionDetails.title",keywords:["config","source","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:s=>!s.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:s=>!s.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:s=>!s.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.openchamber.keyboardShortcuts.title",descriptionKey:"settings.openchamber.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.voice-setup",page:"voice",titleKey:"settings.voice.page.section.voiceSetup",keywords:["tts","voice mode","provider","speech rate","speech pitch","speech volume","language"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","transcribe","whisper","microphone","silence threshold"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["read aloud","tts input mode","summary","markdown"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.provider",descriptionKey:"settings.openchamber.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:s=>!s.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:s=>!s.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.connectLinkTtl",descriptionKey:"settings.openchamber.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:s=>!s.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:s=>!s.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.configurationFile",descriptionKey:"settings.openchamber.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:s=>!s.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.openchamber.tunnel.actions.startTunnel",descriptionKey:"settings.openchamber.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:s=>!s.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:s=>s.isWeb&&!s.isDesktop&&!s.isVSCode}];function Go(s){return s.trim().toLocaleLowerCase()}function kb({query:s,runtimeCtx:e,visiblePageSlugs:n,t:a,getPageTitle:r}){const i=Go(s);if(!i)return[];const o=n?new Set(n):null,d=i.split(/\s+/).filter(Boolean);return Nb.flatMap(c=>{if(o&&!o.has(c.page))return[];const x=Pn(c.page);if(!x||x.isAvailable&&!x.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const m=a(c.titleKey),p=c.descriptionKey?a(c.descriptionKey):null,u=Go([m,p,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return d.every(S=>u.includes(S))?[{...c,title:m,description:p,pageTitle:r(c.page)}]:[]})}const Lr=176,zr=280,Jo=8,ac="__openchamberSettingsDetail";function gr(s){return Math.min(zr,Math.max(Lr,s))}const Sb=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","snippets","projects","remote-instances","agents","behavior","commands","mcp","plugins","providers","usage","skills.installed","skills.catalog","voice","tunnel","about"],Cb={icon:"chat-thread"},Pb="__add_provider__";function Ib(s,e){const n=gs(),a=!s&&mn();return{isVSCode:n,isWeb:a,isDesktop:s,isMobile:e}}function Qo(s,e){return s.isAvailable?s.isAvailable(e):!0}function Kr(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function Hn(s,e){const n=new Set(e);let a=s,r=1;for(;n.has(a);)a=`${s}-${r}`,r+=1;return a}function hr(s){if(!Kr(s))return null;const e=s[ac];if(!Kr(e))return null;const n=e.page,a=e.stage;return typeof n!="string"||a!=="page-content"?null:{page:Jr(n),stage:a}}function Db(){return typeof window>"u"||!Kr(window.history.state)?{}:window.history.state}function rc(s){switch(s){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"snippets":return Cb.icon;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 null;case"plugins":return"code-box";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"about":return"information";case"home":return null;default:return"robot-2"}}const fr=s=>{const e=rt.c(95),{onOpen:n}=s,{t:a}=dt();let r;e[0]!==a?(r=a("settings.view.home.title"),e[0]=a,e[1]=r):r=e[1];let i;e[2]!==r?(i=t.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:r}),e[2]=r,e[3]=i):i=e[3];let o;e[4]!==a?(o=a("settings.view.home.description"),e[4]=a,e[5]=o):o=e[5];let d;e[6]!==o?(d=t.jsx("p",{className:"typography-ui text-muted-foreground",children:o}),e[6]=o,e[7]=d):d=e[7];let c;e[8]!==i||e[9]!==d?(c=t.jsxs("div",{className:"space-y-1",children:[i,d]}),e[8]=i,e[9]=d,e[10]=c):c=e[10];let x;e[11]!==n?(x=()=>n("providers"),e[11]=n,e[12]=x):x=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=de("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 p;e[14]!==a?(p=a("settings.view.home.cards.providers.title"),e[14]=a,e[15]=p):p=e[15];let u;e[16]!==p?(u=t.jsx("div",{className:"typography-ui-label text-foreground",children:p}),e[16]=p,e[17]=u):u=e[17];let S;e[18]!==a?(S=a("settings.view.home.cards.providers.description"),e[18]=a,e[19]=S):S=e[19];let f;e[20]!==S?(f=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:S}),e[20]=S,e[21]=f):f=e[21];let g;e[22]!==f||e[23]!==x||e[24]!==u?(g=t.jsxs("button",{type:"button",onClick:x,className:m,children:[u,f]}),e[22]=f,e[23]=x,e[24]=u,e[25]=g):g=e[25];let h;e[26]!==n?(h=()=>n("agents"),e[26]=n,e[27]=h):h=e[27];let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=de("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=D):D=e[28];let k;e[29]!==a?(k=a("settings.view.home.cards.agents.title"),e[29]=a,e[30]=k):k=e[30];let w;e[31]!==k?(w=t.jsx("div",{className:"typography-ui-label text-foreground",children:k}),e[31]=k,e[32]=w):w=e[32];let E;e[33]!==a?(E=a("settings.view.home.cards.agents.description"),e[33]=a,e[34]=E):E=e[34];let N;e[35]!==E?(N=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:E}),e[35]=E,e[36]=N):N=e[36];let y;e[37]!==h||e[38]!==w||e[39]!==N?(y=t.jsxs("button",{type:"button",onClick:h,className:D,children:[w,N]}),e[37]=h,e[38]=w,e[39]=N,e[40]=y):y=e[40];let b;e[41]!==n?(b=()=>n("skills.catalog"),e[41]=n,e[42]=b):b=e[42];let P;e[43]===Symbol.for("react.memo_cache_sentinel")?(P=de("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=P):P=e[43];let z;e[44]!==a?(z=a("settings.view.home.cards.skillsCatalog.title"),e[44]=a,e[45]=z):z=e[45];let M;e[46]!==z?(M=t.jsx("div",{className:"typography-ui-label text-foreground",children:z}),e[46]=z,e[47]=M):M=e[47];let I;e[48]!==a?(I=a("settings.view.home.cards.skillsCatalog.description"),e[48]=a,e[49]=I):I=e[49];let v;e[50]!==I?(v=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:I}),e[50]=I,e[51]=v):v=e[51];let j;e[52]!==b||e[53]!==M||e[54]!==v?(j=t.jsxs("button",{type:"button",onClick:b,className:P,children:[M,v]}),e[52]=b,e[53]=M,e[54]=v,e[55]=j):j=e[55];let O;e[56]!==n?(O=()=>n("mcp"),e[56]=n,e[57]=O):O=e[57];let T;e[58]===Symbol.for("react.memo_cache_sentinel")?(T=de("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=T):T=e[58];let U;e[59]!==a?(U=a("settings.view.home.cards.mcp.title"),e[59]=a,e[60]=U):U=e[60];let B;e[61]!==U?(B=t.jsx("div",{className:"typography-ui-label text-foreground",children:U}),e[61]=U,e[62]=B):B=e[62];let Q;e[63]!==a?(Q=a("settings.view.home.cards.mcp.description"),e[63]=a,e[64]=Q):Q=e[64];let W;e[65]!==Q?(W=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:Q}),e[65]=Q,e[66]=W):W=e[66];let R;e[67]!==O||e[68]!==B||e[69]!==W?(R=t.jsxs("button",{type:"button",onClick:O,className:T,children:[B,W]}),e[67]=O,e[68]=B,e[69]=W,e[70]=R):R=e[70];let Y;e[71]!==n?(Y=()=>n("usage"),e[71]=n,e[72]=Y):Y=e[72];let F;e[73]===Symbol.for("react.memo_cache_sentinel")?(F=de("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=F):F=e[73];let H;e[74]!==a?(H=a("settings.view.home.cards.usage.title"),e[74]=a,e[75]=H):H=e[75];let X;e[76]!==H?(X=t.jsx("div",{className:"typography-ui-label text-foreground",children:H}),e[76]=H,e[77]=X):X=e[77];let re;e[78]!==a?(re=a("settings.view.home.cards.usage.description"),e[78]=a,e[79]=re):re=e[79];let Z;e[80]!==re?(Z=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:re}),e[80]=re,e[81]=Z):Z=e[81];let se;e[82]!==Y||e[83]!==X||e[84]!==Z?(se=t.jsxs("button",{type:"button",onClick:Y,className:F,children:[X,Z]}),e[82]=Y,e[83]=X,e[84]=Z,e[85]=se):se=e[85];let ce;e[86]!==g||e[87]!==y||e[88]!==j||e[89]!==R||e[90]!==se?(ce=t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[g,y,j,R,se]}),e[86]=g,e[87]=y,e[88]=j,e[89]=R,e[90]=se,e[91]=ce):ce=e[91];let oe;return e[92]!==ce||e[93]!==c?(oe=t.jsx("div",{className:"h-full overflow-auto",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl px-6 py-6 space-y-6",children:[c,ce]})}),e[92]=ce,e[93]=c,e[94]=oe):oe=e[94],oe},Ab=s=>{const e=rt.c(126),{onClose:n,forceMobile:a,isWindowed:r,visiblePageSlugs:i,initialMobileStage:o}=s,d=o===void 0?"nav":o,{t:c}=dt(),x=Cs(),m=a??x.isMobile,p=Ke(Eb),u=Ke(Mb),S=Ke(Rb);let f;e[0]!==p?(f=Jr(p),e[0]=p,e[1]=f):f=e[1];const g=f,[h,D]=l.useState(d),k=l.useRef(null),[w,E]=l.useState(216),[N,y]=l.useState(""),[b,P]=l.useState(null),[z,M]=l.useState(0),[I,v]=l.useState(!1),[j,O]=l.useState(!1),T=l.useRef(0),U=l.useRef(w),B=l.useRef(null);let Q;e[2]===Symbol.for("react.memo_cache_sentinel")?(Q=[],e[2]=Q):Q=e[2];const W=l.useRef(Q),R=l.useRef(0),Y=l.useRef(!1);let F;e[3]===Symbol.for("react.memo_cache_sentinel")?(F=fs(),e[3]=F):F=e[3];const H=F;let X;e[4]===Symbol.for("react.memo_cache_sentinel")?(X=fs()&&ea(),e[4]=X):X=e[4];const re=X;let Z;e[5]!==m?(Z=Ib(H,m),e[5]=m,e[6]=Z):Z=e[6];const se=Z;let ce;if(e[7]!==m||e[8]!==se||e[9]!==i){const mt=i?new Set(i):null;let xt;e[11]!==se?(xt=Zt=>Qo(Zt,se),e[11]=se,e[12]=xt):xt=e[12];let Rt;e[13]!==se.isVSCode?(Rt=Zt=>!(se.isVSCode&&Zt.slug==="projects"),e[13]=se.isVSCode,e[14]=Rt):Rt=e[14];let es;e[15]!==m?(es=Zt=>!(m&&Zt.slug==="shortcuts"),e[15]=m,e[16]=es):es=e[16],ce=nc.filter(Tb).filter(Zt=>!mt||mt.has(Zt.slug)).filter(xt).filter(Rt).filter(es),e[7]=m,e[8]=se,e[9]=i,e[10]=ce}else ce=e[10];const oe=ce;let xe;e[17]===Symbol.for("react.memo_cache_sentinel")?(xe=new Map(Sb.map(Fb)),e[17]=xe):xe=e[17];const we=xe;let he;if(e[18]!==oe){let mt;e[20]===Symbol.for("react.memo_cache_sentinel")?(mt=(xt,Rt)=>(we.get(xt.slug)??999)-(we.get(Rt.slug)??999),e[20]=mt):mt=e[20],he=oe.slice().sort(mt),e[18]=oe,e[19]=he}else he=e[19];const Ie=he,ve=as(Ob);let be,ye;e[21]!==I?(be=()=>{if(typeof window>"u")return;const mt=()=>{if(!I){const xt=gr(Math.floor(window.innerWidth*.12));E(xt)}};return window.addEventListener("resize",mt),()=>window.removeEventListener("resize",mt)},ye=[I],e[21]=I,e[22]=be,e[23]=ye):(be=e[22],ye=e[23]),l.useEffect(be,ye);let te,ie;e[24]!==j?(te=()=>{if(!j)return;const mt=Rt=>{const es=Rt.clientX-T.current,Zt=gr(U.current+es);E(Zt),v(!0)},xt=()=>O(!1);return window.addEventListener("pointermove",mt),window.addEventListener("pointerup",xt,{once:!0}),()=>{window.removeEventListener("pointermove",mt),window.removeEventListener("pointerup",xt)}},ie=[j],e[24]=j,e[25]=te,e[26]=ie):(te=e[25],ie=e[26]),l.useEffect(te,ie);let ge;e[27]!==w?(ge=mt=>{O(!0),T.current=mt.clientX,U.current=w,mt.preventDefault()},e[27]=w,e[28]=ge):ge=e[28];const _=ge;let ee;e[29]!==w?(ee=mt=>{const xt=mt.shiftKey?Jo*4:Jo;let Rt;e:switch(mt.key){case"ArrowLeft":{Rt=w-xt;break e}case"ArrowRight":{Rt=w+xt;break e}case"Home":{Rt=Lr;break e}case"End":{Rt=zr;break e}default:return}mt.preventDefault(),E(gr(Rt)),v(!0)},e[29]=w,e[30]=ee):ee=e[30];const ne=ee;let ue;e[31]!==u||e[32]!==r||e[33]!==se.isVSCode||e[34]!==g?(ue=()=>{if(!(!u&&!se.isVSCode&&!r)){if(g==="agents"){Ka.getState().loadAgents();return}if(g==="commands"){$a.getState().loadCommands();return}if(g==="mcp"){Mn.getState().loadMcpConfigs();return}if(g==="plugins"){os.getState().loadPlugins();return}(g==="skills.installed"||g==="skills.catalog")&&(_s.getState().loadSkills(),Bs.getState().loadCatalog()),g==="snippets"&&Ba.getState().loadSnippets()}},e[31]=u,e[32]=r,e[33]=se.isVSCode,e[34]=g,e[35]=ue):ue=e[35];let Me;e[36]!==ve||e[37]!==u||e[38]!==r||e[39]!==se.isVSCode||e[40]!==g?(Me=[ve,u,r,se.isVSCode,g],e[36]=ve,e[37]=u,e[38]=r,e[39]=se.isVSCode,e[40]=g,e[41]=Me):Me=e[41],l.useEffect(ue,Me);let ke;e[42]!==m||e[43]!==S?(ke=mt=>{if(S(mt),k.current=mt,!m)return;const xt=Pn(mt);if(!xt||xt.slug==="home"){D("nav");return}D(xt.kind==="split"?"page-sidebar":"page-content")},e[42]=m,e[43]=S,e[44]=ke):ke=e[44];const De=ke;let Ae;e[45]!==g?(Ae=Pn(g),e[45]=g,e[46]=Ae):Ae=e[46];const Pe=Ae;let Re;e[47]===Symbol.for("react.memo_cache_sentinel")?(Re={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[47]=Re):Re=e[47];const Oe=Re;let $e;e[48]!==c?($e=mt=>{switch(mt){case"projects":return c("settings.page.projects.title");case"remote-instances":return c("settings.page.remoteInstances.title");case"providers":return c("settings.page.providers.title");case"usage":return c("settings.page.usage.title");case"agents":return c("settings.page.agents.title");case"behavior":return c("settings.page.behavior.title");case"commands":return c("settings.page.commands.title");case"mcp":return c("settings.page.mcp.title");case"plugins":return c("settings.page.plugins.title");case"skills.installed":return c("settings.page.skills.title");case"skills.catalog":return c("settings.page.skillsCatalog.title");case"git":return c("settings.page.git.title");case"appearance":return c("settings.page.appearance.title");case"chat":return c("settings.page.chat.title");case"shortcuts":return c("settings.page.shortcuts.title");case"sessions":return c("settings.page.sessions.title");case"magic-prompts":return c("settings.page.magicPrompts.title");case"snippets":return c("settings.page.snippets.title");case"notifications":return c("settings.page.notifications.title");case"voice":return c("settings.page.voice.title");case"tunnel":return c("settings.page.tunnel.title");case"about":return c("settings.page.about.title");default:return c("settings.view.home.title")}},e[48]=c,e[49]=$e):$e=e[49];const Be=$e;let Le;e[50]!==Be||e[51]!==se||e[52]!==N||e[53]!==c||e[54]!==i?(Le=kb({query:N,runtimeCtx:{...se,isDesktopLocalOrigin:re},visiblePageSlugs:i,t:c,getPageTitle:Be}),e[50]=Be,e[51]=se,e[52]=N,e[53]=c,e[54]=i,e[55]=Le):Le=e[55];const Ue=Le,le=Bb;let q;if(e[56]!==Ue){q=[];const mt=new Map;for(const xt of Ue){let Rt=mt.get(xt.page);Rt||(Rt={page:xt.page,pageTitle:xt.pageTitle,results:[]},mt.set(xt.page,Rt),q.push(Rt)),Rt.results.push(xt)}e[56]=Ue,e[57]=q}else q=e[57];const me=q;let Ne;e[58]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>{M(0),R.current=0,Y.current=!1},e[58]=Ne):Ne=e[58];let Ee;e[59]!==N?(Ee=[N],e[59]=N,e[60]=Ee):Ee=e[60],l.useEffect(Ne,Ee);let Ce,He;e[61]!==z?(Ce=()=>{R.current=z},He=[z],e[61]=z,e[62]=Ce,e[63]=He):(Ce=e[62],He=e[63]),l.useEffect(Ce,He);let G,$;e[64]!==z?(G=()=>{W.current[z]?.scrollIntoView({block:"nearest"})},$=[z],e[64]=z,e[65]=G,e[66]=$):(G=e[65],$=e[66]),l.useEffect(G,$);let fe,L;e[67]!==z||e[68]!==Ue.length?(fe=()=>{z>=Ue.length&&M(Math.max(0,Ue.length-1)),W.current.length=Ue.length},L=[z,Ue.length],e[67]=z,e[68]=Ue.length,e[69]=fe,e[70]=L):(fe=e[69],L=e[70]),l.useEffect(fe,L);let Fe;e[71]!==m||e[72]!==De?(Fe=mt=>{const xt=le(mt);P(xt),De(mt.page),m&&D("page-content"),mt.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(Vb,50)},e[71]=m,e[72]=De,e[73]=Fe):Fe=e[73];const Je=Fe;let Xe;e[74]!==Je||e[75]!==N||e[76]!==Ue?(Xe=mt=>{if(N.trim()){if(mt.key==="Escape"){mt.preventDefault(),y("");return}if(Ue.length!==0){if(mt.key==="ArrowDown"){mt.preventDefault(),Y.current=!0,M(xt=>(xt+1)%Ue.length);return}if(mt.key==="ArrowUp"){mt.preventDefault(),Y.current=!0,M(xt=>(xt-1+Ue.length)%Ue.length);return}if(mt.key==="Enter"){mt.preventDefault();const xt=(R.current%Ue.length+Ue.length)%Ue.length,Rt=Ue[xt]??Ue[0];Rt&&Je(Rt)}}}},e[74]=Je,e[75]=N,e[76]=Ue,e[77]=Xe):Xe=e[77];const et=Xe;let at;e[78]!==b?(at=()=>{const mt=b;if(!mt)return;let xt=!1;const Rt=window.requestAnimationFrame(()=>{if(xt)return;const es=typeof CSS<"u"&&CSS.escape?CSS.escape(mt):mt.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Zt=B.current?.querySelector(`[data-settings-item="${es}"]`);Zt&&(P(null),Zt.scrollIntoView({block:"center",behavior:"smooth"}),Zt.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Zt.removeAttribute("data-settings-search-highlight")},1600))});return()=>{xt=!0,window.cancelAnimationFrame(Rt)}},e[78]=b,e[79]=at):at=e[79];let lt;e[80]!==b||e[81]!==g?(lt=[b,g],e[80]=b,e[81]=g,e[82]=lt):lt=e[82],l.useEffect(at,lt);let Ze;e[83]!==c?(Ze=()=>t.jsx("div",{className:"flex h-full items-center justify-center px-6",children:t.jsxs("div",{className:"max-w-md text-center",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("settings.view.unavailable.title")}),t.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:c("settings.view.unavailable.description")})]})}),e[83]=c,e[84]=Ze):Ze=e[84];const We=Ze,pt=_b;let pe;e[85]!==De||e[86]!==We||e[87]!==se?(pe=mt=>{const xt=Pn(mt);if(xt&&!Qo(xt,se))return We();switch(mt){case"home":return t.jsx(fr,{onOpen:De});case"projects":return t.jsx(Hh,{});case"remote-instances":return t.jsx(uf,{});case"agents":return t.jsx(Xu,{});case"behavior":return t.jsx(np,{});case"commands":return t.jsx(up,{});case"mcp":return t.jsx(Bp,{});case"plugins":return t.jsx(Ig,{});case"skills.installed":return t.jsx(wo,{view:"installed"});case"skills.catalog":return t.jsx(wo,{view:"catalog"});case"providers":return t.jsx(jf,{});case"usage":return t.jsx(tx,{});case"about":return t.jsx("div",{className:"h-full overflow-auto px-5 py-6",children:t.jsx(Dl,{})});case"magic-prompts":return t.jsx(ix,{});case"snippets":return t.jsx(mx,{});case"git":return t.jsx(fx,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const Rt=Oe[mt]??"visual";return t.jsx(mb,{section:Rt})}default:return t.jsx(fr,{onOpen:De})}},e[85]=De,e[86]=We,e[87]=se,e[88]=pe):pe=e[88];const st=pe;let nt,Ge;e[89]!==m||e[90]!==h||e[91]!==g?(nt=()=>{if(!m||h!=="nav"||g==="home"||k.current===g)return;const mt=Pn(g);!mt||mt.slug==="home"||(k.current=g,D(mt.kind==="split"?"page-sidebar":"page-content"))},Ge=[m,h,g],e[89]=m,e[90]=h,e[91]=g,e[92]=nt,e[93]=Ge):(nt=e[92],Ge=e[93]),l.useEffect(nt,Ge);const ft=m&&h!=="nav",wt=m&&h==="page-content"&&g==="skills.installed",Ct=h==="page-content"&&Pe?.kind==="split"&&!wt;let ae;e[94]!==wt||e[95]!==ft||e[96]!==c?(ae=c(wt?"settings.view.actions.back":ft?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[94]=wt,e[95]=ft,e[96]=c,e[97]=ae):ae=e[97];const Ve=ae,tt=kl();let Ye;e[98]!==se.isVSCode?(Ye=mt=>{if(typeof window>"u"||se.isVSCode)return;const xt=hr(window.history.state);xt?.page===mt&&xt.stage==="page-content"||window.history.pushState({...Db(),[ac]:{page:mt,stage:"page-content"}},"",window.location.href)},e[98]=se.isVSCode,e[99]=Ye):Ye=e[99];const bt=Ye;let ze;e[100]!==bt||e[101]!==g?(ze=()=>{D("page-content"),g==="skills.installed"&&bt(g)},e[100]=bt,e[101]=g,e[102]=ze):ze=e[102];const _e=ze;let ot;e[103]!==wt||e[104]!==se.isVSCode||e[105]!==g?(ot=()=>{if(wt){if((typeof window<"u"?hr(window.history.state):null)?.page===g&&!se.isVSCode){window.history.back();return}D("page-sidebar");return}D("nav")},e[103]=wt,e[104]=se.isVSCode,e[105]=g,e[106]=ot):ot=e[106];const yt=ot;let Mt,Qt;e[107]!==m||e[108]!==se.isVSCode||e[109]!==g?(Mt=()=>{if(!m||se.isVSCode)return;const mt=xt=>{if(g!=="skills.installed")return;if(hr(xt.state)?.page==="skills.installed"){D("page-content");return}D(Hb)};return window.addEventListener("popstate",mt),()=>{window.removeEventListener("popstate",mt)}},Qt=[m,se.isVSCode,g],e[107]=m,e[108]=se.isVSCode,e[109]=g,e[110]=Mt,e[111]=Qt):(Mt=e[110],Qt=e[111]),l.useEffect(Mt,Qt);let Xt;e[112]===Symbol.for("react.memo_cache_sentinel")?(Xt=()=>{D("page-sidebar")},e[112]=Xt):Xt=e[112];const rs=Xt,Wt=()=>{const mt=N.trim().length>0;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[t.jsx("div",{className:"px-2 pt-3",children:t.jsxs("div",{className:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[t.jsx(A,{name:"search",className:"h-4 w-4 shrink-0"}),t.jsx("input",{value:N,onChange:xt=>y(xt.target.value),onKeyDown:et,placeholder:c("settings.view.search.placeholder"),"aria-label":c("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),mt&&t.jsx("button",{type:"button",onClick:()=>y(""),"aria-label":c("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:t.jsx("div",{className:"flex flex-col gap-0.5 pt-4 pb-2 px-2",children:mt?Ue.length>0?(()=>{let xt=0;return me.map(Rt=>t.jsxs("div",{className:"space-y-0.5",children:[t.jsx("div",{className:"px-2 pb-0.5 pt-2 typography-micro font-medium text-muted-foreground/70",children:Rt.pageTitle}),Rt.results.map(es=>{const Zt=xt;xt=xt+1;const qs=Zt===z,Os=!!es.description;return t.jsxs("button",{type:"button",ref:Tn=>{W.current[Zt]=Tn},onMouseMove:()=>{Y.current=!1,M(Zt)},onClick:()=>Je(es),className:de("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Os?"min-h-11 py-1.5":"py-2",qs?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:es.title}),Os&&t.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:es.description})]},es.id)})]},Rt.page))})():t.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:c("settings.view.search.noResults")}):Ie.map(xt=>{const Rt=g===xt.slug,es=rc(xt.slug);return!es&&xt.slug!=="mcp"?null:t.jsx(Dt,{children:t.jsx(At,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:()=>De(xt.slug),"aria-current":Rt?"page":void 0,className:de("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",Rt?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[xt.slug==="mcp"?t.jsx(ru,{className:"h-4 w-4 shrink-0"}):t.jsx(A,{name:es,className:"h-4 w-4 shrink-0"}),t.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[t.jsx("span",{className:"typography-ui-label font-normal truncate",children:Be(xt.slug)}),(xt.slug==="voice"||xt.slug==="tunnel")&&t.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:c("settings.view.badge.beta")})]})]})})},xt.slug)})})}),t.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:t.jsx("div",{className:"border-t border-border bg-sidebar px-2 py-1 space-y-0.5",children:!se.isVSCode&&t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsxs("button",{type:"button",className:de("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:qb,children:[t.jsx(A,{name:"restart",className:"h-4 w-4 shrink-0"}),t.jsx("span",{children:c("settings.view.actions.reloadOpenCode")})]})}),t.jsx(Et,{children:c("settings.view.actions.reloadOpenCodeTooltip")})]})})})]})},Se=()=>{if(h==="nav")return t.jsx("div",{className:de("flex-1 min-h-0 overflow-hidden",se.isVSCode?"bg-background":"bg-sidebar"),children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:t.jsx(Ys,{children:Wt()})})});if(!Pe)return t.jsx("div",{className:"flex-1 bg-background"});if(h==="page-sidebar"){if(Pe.kind!=="split"){const xt=st(g);return t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(Ys,{children:xt})})}return t.jsx("div",{className:de("flex-1 min-h-0 overflow-hidden",se.isVSCode?"bg-background":"bg-sidebar"),children:t.jsx(Ys,{children:pt(g,{onItemSelect:_e})})})}const mt=st(g);return t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(Ys,{children:mt})})};let vt;e[113]!==Pe||e[114]!==De||e[115]!==st||e[116]!==se.isVSCode||e[117]!==g?(vt=()=>!Pe||g==="home"?t.jsx(fr,{onOpen:De}):Pe.kind==="split"?t.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[t.jsx("div",{className:de("w-[264px] min-w-[264px] border-r",se.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:t.jsx(Ys,{children:pt(g,{})})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(Ys,{children:st(g)})})]}):t.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:t.jsx(Ys,{children:st(g)})}),e[113]=Pe,e[114]=De,e[115]=st,e[116]=se.isVSCode,e[117]=g,e[118]=vt):vt=e[118];const Nt=vt,ct="true";let St;e[119]===Symbol.for("react.memo_cache_sentinel")?(St=de("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[119]=St):St=e[119];const $t=m?t.jsxs("div",{className:de("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 border-b px-3","bg-background"),style:{borderColor:"var(--interactive-border)"},children:[ft||n?t.jsx("button",{type:"button",onClick:ft?yt:n,"aria-label":Ve,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:t.jsx(A,{name:"arrow-left-s",className:"h-5 w-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:h==="nav"?c("settings.view.home.title"):Pe?Be(Pe.slug):c("settings.view.home.title")}),Ct&&t.jsx("button",{type:"button",onClick:rs,"aria-label":c("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:t.jsx(A,{name:"list-unordered",className:"h-5 w-5"})}),n&&t.jsx("button",{type:"button",onClick:n,"aria-label":c("settings.view.actions.closeSettings"),title:c("settings.view.actions.closeSettingsWithShortcut",{shortcut:tt}),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:t.jsx(A,{name:"close",className:"h-5 w-5"})})]}):t.jsxs(t.Fragment,{children:[ft&&t.jsx("div",{className:de("absolute left-3 z-50",r?"top-2":"top-3"),children:t.jsx("button",{type:"button",onClick:yt,"aria-label":c("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:t.jsx(A,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&t.jsx("div",{className:de("absolute right-0.5 z-50",r?"top-0.5":"top-1"),children:t.jsx("button",{type:"button",onClick:n,"aria-label":c("settings.view.actions.closeSettings"),title:c("settings.view.actions.closeSettingsWithShortcut",{shortcut:tt}),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:t.jsx(A,{name:"close",className:"h-5 w-5"})})})]}),bs="flex flex-1 min-h-0 overflow-hidden",ns=m?Se():t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:de("relative flex h-full min-h-0 flex-col overflow-hidden border-r",H?"bg-sidebar":se.isVSCode?"bg-background":"bg-sidebar",j?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${w}px`,minWidth:`${w}px`,borderColor:"var(--interactive-border)"},children:[t.jsx("div",{className:de("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)]",j?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:_,onKeyDown:ne,role:"separator","aria-orientation":"vertical","aria-valuemin":Lr,"aria-valuemax":zr,"aria-valuenow":w,"aria-label":c("settings.view.actions.resizeNavigation")}),t.jsx(Ys,{children:Wt()})]}),t.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Nt()})]});let ys;e[120]!==ns?(ys=t.jsx("div",{className:bs,children:ns}),e[120]=ns,e[121]=ys):ys=e[121];let Qe;return e[122]!==St||e[123]!==$t||e[124]!==ys?(Qe=t.jsxs("div",{ref:B,"data-settings-view":ct,className:St,children:[$t,ys]}),e[122]=St,e[123]=$t,e[124]=ys,e[125]=Qe):Qe=e[125],Qe};function Eb(s){return s.settingsPage}function Mb(s){return s.isSettingsDialogOpen}function Rb(s){return s.setSettingsPage}function Tb(s){return s.slug!=="home"}function Fb(s,e){return[s,e]}function Ob(s){return s.activeProjectId}function Lb(s){return s.name}function zb(s){return s.name}function Kb(s){return s.name}function $b(s){return s.name}function Ub(s){return s.name}function Bb(s){if(s.id.startsWith("agents.")){const e=Ka.getState(),n=Hn("new-agent",e.agents.map(Lb));return e.setAgentDraft({name:n,scope:"user"}),e.setSelectedAgent(n),s.id==="agents.create"?"agents.name":s.id}if(s.id.startsWith("commands.")){const e=$a.getState(),n=Hn("new-command",e.commands.map(zb));return e.setCommandDraft({name:n,scope:"user"}),e.setSelectedCommand(n),s.id==="commands.create"?"commands.name":s.id}if(s.id.startsWith("mcp.")){const e=Mn.getState(),n=Hn("new-mcp-server",e.mcpServers.map(Kb));return e.setMcpDraft({name:n,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),e.setSelectedMcp(n),s.id==="mcp.create"?"mcp.server":s.id}if(s.id.startsWith("snippets.")){const e=Ba.getState(),n=Hn("new-snippet",e.snippets.map($b));return e.setSnippetDraft({name:n,scope:"global"}),e.setSelectedSnippet(n),s.id==="snippets.create"?"snippets.content":s.id}if(s.id.startsWith("skills.")){const e=_s.getState(),n=Hn("new-skill",e.skills.map(Ub));return e.setSkillDraft({name:n,scope:"user",source:"opencode",description:"",instructions:""}),e.setSelectedSkill(n),s.id==="skills.create"?"skills.basic-information":s.id}return s.id==="providers.connect"&&ut.getState().setSelectedProvider(Pb),s.id==="plugins.create"?"plugins.spec":s.id}function Vb(){window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))}function _b(s,e){switch(s){case"projects":return t.jsx(Eh,{onItemSelect:e.onItemSelect});case"agents":return t.jsx(Hu,{onItemSelect:e.onItemSelect});case"commands":return t.jsx(ap,{onItemSelect:e.onItemSelect});case"mcp":return t.jsx(pp,{onItemSelect:e.onItemSelect});case"plugins":return t.jsx(fg,{onItemSelect:e.onItemSelect});case"skills.installed":return t.jsx(Ag,{onItemSelect:e.onItemSelect});case"providers":return t.jsx(hf,{onItemSelect:e.onItemSelect});case"usage":return t.jsx(Rf,{onItemSelect:e.onItemSelect});case"magic-prompts":return t.jsx(nx,{onItemSelect:e.onItemSelect});case"snippets":return t.jsx(ox,{onItemSelect:e.onItemSelect});default:return null}}function Hb(s){return s==="page-content"?"page-sidebar":s}function Wb(){}function qb(){In({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]}).catch(Wb)}const $v=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:Ab,getSettingsNavIcon:rc},Symbol.toStringTag,{value:"Module"})),Gb=["chat","git","diff","terminal","files","diagram"],Jb=["settings","agents","commands","skills","providers","usage","git-identities"],Ds={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Yo(s){const e=Qb();return{sessionId:Yb(e),tab:Xb(e),settingsPath:Zb(e),diffFile:ey(e)}}function Qb(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function Yb(s){const e=s.get(Ds.SESSION);return!e||e.trim().length===0?null:e.trim()}function Xb(s){const e=s.get(Ds.TAB);if(!e)return null;const n=e.toLowerCase().trim();return Gb.includes(n)?n:null}function Zb(s){const e=s.get(Ds.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(Jb.includes(n),n)}function ey(s){const e=s.get(Ds.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Xo(){if(typeof window>"u")return!1;try{const s=new URLSearchParams(window.location.search);return s.has(Ds.SESSION)||s.has(Ds.TAB)||s.has(Ds.SETTINGS)||s.has(Ds.FILE)}catch{return!1}}const ty="chat";function ic(s){const e=new URLSearchParams;if(s.sessionId&&s.sessionId.trim().length>0&&e.set(Ds.SESSION,s.sessionId),s.isSettingsOpen){const n=s.settingsPath.trim().length>0?s.settingsPath:"home";return e.set(Ds.SETTINGS,n),e}return s.tab!==ty&&e.set(Ds.TAB,s.tab),s.tab==="diff"&&s.diffFile&&s.diffFile.trim().length>0&&e.set(Ds.FILE,s.diffFile),e}function sy(s,e){const n=typeof window<"u"?window.location.pathname:"/",a=s.toString();return a?`${n}?${a}`:n}function ny(s){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=ic(s),a=[...e.entries()].sort((i,o)=>i[0].localeCompare(o[0])),r=[...n.entries()].sort((i,o)=>i[0].localeCompare(o[0]));if(a.length!==r.length)return!1;for(let i=0;i<a.length;i++)if(a[i][0]!==r[i][0]||a[i][1]!==r[i][1])return!1;return!0}catch{return!0}}function ay(s,e={}){if(!(typeof window>"u")&&!ry()&&!(!e.force&&ny(s)))try{const n=ic(s),a=sy(n);e.replace?window.history.replaceState({...window.history.state,route:s},"",a):window.history.pushState({route:s},"",a)}catch{}}function ry(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function iy(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function Uv(){const s=l.useMemo(()=>iy(),[]),e=l.useRef(!1),n=l.useRef(!1),a=Ps(p=>p.setCurrentSession),r=Ke(p=>p.setActiveMainTab),i=Ke(p=>p.setSettingsDialogOpen),o=Ke(p=>p.setSettingsPage),d=Ke(p=>p.navigateToDiff),c=l.useCallback(async p=>{if(!n.current){n.current=!0;try{if(p.sessionId){const u=Ps.getState().currentSessionId;p.sessionId!==u&&await a(p.sessionId)}if(p.settingsPath){o(Jr(p.settingsPath)),i(!0);return}Ke.getState().isSettingsDialogOpen&&i(!1),p.tab&&r(p.tab),p.diffFile&&(p.tab==="diff"||!p.tab)&&d(p.diffFile)}finally{n.current=!1}}},[a,r,i,o,d]),x=l.useCallback(()=>{const p=Ps.getState(),u=Ke.getState();return{sessionId:p.currentSessionId,tab:u.activeMainTab,isSettingsOpen:u.isSettingsDialogOpen,settingsPath:u.settingsPage,diffFile:u.pendingDiffFile}},[]),m=l.useCallback((p={})=>{if(s||n.current)return;const u=x();ay(u,p)},[s,x]);l.useEffect(()=>{if(e.current||(e.current=!0,!Xo()))return;const p=Yo();(async()=>(await c(p),s||m({replace:!0})))()},[c,s,m]),l.useEffect(()=>{if(s)return;let p=Ps.getState().currentSessionId;return Ps.subscribe(S=>{const f=S.currentSessionId;f===p||n.current||(p=f,m())})},[s,m]),l.useEffect(()=>{if(s)return;let p=Ke.getState().activeMainTab,u=Ke.getState().isSettingsDialogOpen,S=Ke.getState().settingsPage,f=Ke.getState().pendingDiffFile;return Ke.subscribe(h=>{if(n.current)return;const D=h.activeMainTab!==p,k=h.isSettingsDialogOpen!==u,w=h.settingsPage!==S,E=h.pendingDiffFile!==f&&h.activeMainTab==="diff";p=h.activeMainTab,u=h.isSettingsDialogOpen,S=h.settingsPage,f=h.pendingDiffFile,(D||k||w||E)&&m()})},[s,m]),l.useEffect(()=>{if(typeof window>"u"||s)return;const p=()=>{const u=Yo();if(Xo())c(u);else{const S=Ke.getState();S.isSettingsDialogOpen&&i(!1),S.activeMainTab!=="chat"&&r("chat")}};return window.addEventListener("popstate",p),()=>{window.removeEventListener("popstate",p)}},[c,s,r,i])}function Bv(){const s=rt.c(5),e=Il(ly),n=l.useRef(e);let a,r;s[0]!==e?(a=()=>{n.current=e},r=[e],s[0]=e,s[1]=a,s[2]=r):(a=s[1],r=s[2]),l.useEffect(a,r);let i,o;s[3]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{let d=!1,c=null;const x=oy,m=p=>{d||(c=window.setTimeout(async()=>{const u=await n.current(),S=typeof u=="number"&&Number.isFinite(u)?x(u):36e5;m(S)},p))};return m(3e3),()=>{d=!0,c!==null&&window.clearTimeout(c)}},o=[],s[3]=i,s[4]=o):(i=s[3],o=s[4]),l.useEffect(i,o)}function oy(s){const e=Math.round(s*1e3);return Math.max(3e5,Math.min(864e5,e))}function ly(s){return s.checkForUpdates}const oc={"?":{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"}},cy=oc.M;function dy(s){const e=s.index?.trim(),n=s.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"}function my(s){const e=dy(s);return oc[e]??cy}const uy=l.memo(function(e){const n=rt.c(58),{file:a,actionLabel:r,actionSymbol:i,onAction:o,onViewDiff:d,onRevert:c,isReverting:x,stats:m,rowPaddingClassName:p,indentPx:u,actionAtStart:S,showRevert:f}=e,g=u===void 0?0:u,h=S===void 0?!1:S,D=f===void 0?!0:f;let k;n[0]!==a?(k=my(a),n[0]=a,n[1]=k):k=n[1];const w=k,{t:E}=dt(),N=w.description,y=m?.insertions??0,b=m?.deletions??0;let P;n[2]!==o||n[3]!==d?(P=he=>{he.key===" "?(he.preventDefault(),o()):he.key==="Enter"&&(he.preventDefault(),d())},n[2]=o,n[3]=d,n[4]=P):P=n[4];const z=P;let M;n[5]!==o?(M=he=>{he.preventDefault(),he.stopPropagation(),o()},n[5]=o,n[6]=M):M=n[6];const I=M;let v;n[7]!==c?(v=he=>{he.preventDefault(),he.stopPropagation(),c()},n[7]=c,n[8]=v):v=n[8];const j=v;let O;n[9]!==r||n[10]!==i||n[11]!==I?(O=t.jsx("button",{type:"button",onClick:I,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":r,title:r,children:i}),n[9]=r,n[10]=i,n[11]=I,n[12]=O):O=n[12];const T=O,U=`group flex items-center gap-2 py-1.5 cursor-pointer ${p??"px-3"}`;let B;n[13]!==g?(B=g>0?{paddingLeft:`${g}px`}:void 0,n[13]=g,n[14]=B):B=n[14];const Q=h?T:null;let W;n[15]!==w.color?(W={color:w.color},n[15]=w.color,n[16]=W):W=n[16];let R;n[17]!==w.code||n[18]!==N||n[19]!==W?(R=t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:W,title:N,"aria-label":N,children:w.code}),n[17]=w.code,n[18]=N,n[19]=W,n[20]=R):R=n[20];let Y;n[21]!==a.path?(Y=t.jsx(Nm,{filePath:a.path,className:"h-3.5 w-3.5 shrink-0"}),n[21]=a.path,n[22]=Y):Y=n[22];let F;if(n[23]!==a.path){e:{const he=a.path.lastIndexOf("/");if(he===-1){let ge;n[25]===Symbol.for("react.memo_cache_sentinel")?(ge={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[25]=ge):ge=n[25],F=t.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:ge,title:a.path,children:a.path});break e}const Ie=a.path.slice(0,he),ve=a.path.slice(he);let be;n[26]===Symbol.for("react.memo_cache_sentinel")?(be={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[26]=be):be=n[26];let ye;n[27]===Symbol.for("react.memo_cache_sentinel")?(ye=t.jsx("span",{className:"text-muted-foreground",children:"/"}),n[27]=ye):ye=n[27];const te=t.jsx("span",{className:"text-foreground",children:ve.slice(1)});let ie;n[28]!==te?(ie=t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[ye,te]}),n[28]=te,n[29]=ie):ie=n[29],F=t.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:a.path,children:[t.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:be,children:Ie}),ie]})}n[23]=a.path,n[24]=F}else F=n[24];let H;n[30]===Symbol.for("react.memo_cache_sentinel")?(H={color:"var(--status-success)"},n[30]=H):H=n[30];let X;n[31]!==y?(X=t.jsxs("span",{style:H,children:["+",y]}),n[31]=y,n[32]=X):X=n[32];let re,Z;n[33]===Symbol.for("react.memo_cache_sentinel")?(re=t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),Z={color:"var(--status-error)"},n[33]=re,n[34]=Z):(re=n[33],Z=n[34]);let se;n[35]!==b?(se=t.jsxs("span",{style:Z,children:["-",b]}),n[35]=b,n[36]=se):se=n[36];let ce;n[37]!==X||n[38]!==se?(ce=t.jsxs("span",{className:"shrink-0 typography-micro",children:[X,re,se]}),n[37]=X,n[38]=se,n[39]=ce):ce=n[39];let oe;n[40]!==a.path||n[41]!==j||n[42]!==x||n[43]!==D||n[44]!==E?(oe=D?t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx("button",{type:"button",onClick:j,disabled:x,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":E("gitView.changes.revertFileAria",{path:a.path}),children:x?t.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(A,{name:"arrow-go-back",className:"size-3.5"})})}),t.jsx(Et,{sideOffset:8,children:E("gitView.changes.revertFileTooltip")})]}):null,n[40]=a.path,n[41]=j,n[42]=x,n[43]=D,n[44]=E,n[45]=oe):oe=n[45];const xe=h?null:T;let we;return n[46]!==z||n[47]!==d||n[48]!==B||n[49]!==Q||n[50]!==R||n[51]!==Y||n[52]!==F||n[53]!==ce||n[54]!==oe||n[55]!==xe||n[56]!==U?(we=t.jsxs("div",{className:U,role:"button",tabIndex:0,onClick:d,onKeyDown:z,style:B,children:[Q,R,Y,F,ce,oe,xe]}),n[46]=z,n[47]=d,n[48]=B,n[49]=Q,n[50]=R,n[51]=Y,n[52]=F,n[53]=ce,n[54]=oe,n[55]=xe,n[56]=U,n[57]=we):we=n[57],we}),Zo=14,lc=s=>s.replace(/\\/g,"/").replace(/^\/+/,"").trim(),el=(s,e)=>({id:`dir:${s}`,path:s,name:e,children:new Map,directFiles:[],files:[]}),py=s=>{const e=el("","");for(const n of s){const a=lc(n.path);if(!a)continue;const i=a.split("/").filter(Boolean).slice(0,-1);let o=e;if(o.files.push(n),i.length>0){let d="";for(const c of i){d=d?`${d}/${c}`:c;const x=o.children.get(c);if(x){x.files.push(n),o=x;continue}const m=el(d,c);m.files.push(n),o.children.set(c,m),o=m}}o.directFiles.push(n)}return e},gy=(s,e)=>{const n=[],a=(r,i)=>{const o=Array.from(r.children.values()).sort((c,x)=>c.path.localeCompare(x.path));for(const c of o)n.push({key:c.id,kind:"directory",depth:i,directory:c}),e.has(c.path)&&a(c,i+1);const d=[...r.directFiles].sort((c,x)=>c.path.localeCompare(x.path));for(const c of d)n.push({key:`file:${lc(c.path)}`,kind:"file",depth:i,file:c})};return a(s,0),n},hy=1e3,ba=34,xr=30,ya="pl-0 pr-2",br=(s,e)=>`${s} ${e}`,Vv=s=>{const e=rt.c(158),{groups:n,diffStats:a,revertingPaths:r,isRevertingAll:i,headerBackgroundClassName:o,onVisiblePathsChange:d,onRevertAll:c,onRevertDirectory:x}=s,m=i===void 0?!1:i,p=o===void 0?"bg-sidebar":o,{t:u}=dt(),S=l.useRef(null),g=Ke(fy)==="tree";let h;e[0]!==n?(h=n.filter(xy),e[0]=n,e[1]=h):h=e[1];const D=h;let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=new Set,e[2]=k):k=e[2];const[w,E]=l.useState(k);let N;e[3]===Symbol.for("react.memo_cache_sentinel")?(N=new Set,e[3]=N):N=e[3];const[y,b]=l.useState(N),[P,z]=l.useState(!1),[M,I]=l.useState(null);let v;e[4]!==D?(v=D.map(by),e[4]=D,e[5]=v):v=e[5];const j=v;let O;e[6]!==j||e[7]!==D?(O=[],D.forEach((ze,_e)=>{Array.from(j[_e]?.children.values()??[]).forEach(ot=>{O.push(br(ze.id,ot.path))})}),e[6]=j,e[7]=D,e[8]=O):O=e[8];const T=O;let U,B;e[9]!==g||e[10]!==T?(U=()=>{g&&b(ze=>{const _e=new Set,ot=new Set(T);return ze.forEach(yt=>{(yt.slice(yt.indexOf(" ")+1).includes("/")||ot.has(yt))&&_e.add(yt)}),T.forEach(yt=>_e.add(yt)),_e})},B=[g,T],e[9]=g,e[10]=T,e[11]=U,e[12]=B):(U=e[11],B=e[12]),l.useEffect(U,B);let Q;if(e[13]!==w||e[14]!==y||e[15]!==g||e[16]!==c||e[17]!==j||e[18]!==D){if(Q=[],D.forEach((ze,_e)=>{if(Q.push({type:"header",key:`header:${ze.id}`,groupIndex:_e}),!w.has(ze.id)){if(g){const ot=new Set;y.forEach(Mt=>{Mt.startsWith(`${ze.id} `)&&ot.add(Mt.slice(ze.id.length+1))}),gy(j[_e],ot).forEach(Mt=>{Mt.kind==="file"?Q.push({type:"file",key:`${ze.id}:${Mt.key}`,groupIndex:_e,file:Mt.file,depth:Mt.depth}):Q.push({type:"directory",key:`${ze.id}:${Mt.key}`,groupIndex:_e,directory:Mt.directory,depth:Mt.depth})});return}ze.entries.forEach(ot=>{Q.push({type:"file",key:`${ze.id}:file:${ot.path}`,groupIndex:_e,file:ot,depth:0})})}}),c&&D.length>0){let ze;e[20]===Symbol.for("react.memo_cache_sentinel")?(ze={type:"revert-all",key:"revert-all"},e[20]=ze):ze=e[20],Q.push(ze)}e[13]=w,e[14]=y,e[15]=g,e[16]=c,e[17]=j,e[18]=D,e[19]=Q}else Q=e[19];const W=Q,R=W.length,Y=R>=hy,F=l.useRef(null),[H,X]=l.useState(0);let re;e[21]===Symbol.for("react.memo_cache_sentinel")?(re=ze=>{const _e=F.current,ot=_e?_e.findItemIndex(ze):Math.floor(ze/ba);X(yt=>yt===ot?yt:ot)},e[21]=re):re=e[21];const Z=re;let se,ce;e[22]!==d||e[23]!==R||e[24]!==W||e[25]!==Y||e[26]!==H?(se=()=>{if(!d)return;const ze=yy;if(R===0){d([]);return}if(!Y){const _e=[];for(const ot of W)if(ot.type==="file"&&(_e.push(ot.file.path),_e.length>=xr))break;d(_e);return}d(W.slice(H,H+Math.ceil((S.current?.clientHeight??0)/ba)+xr).map(_e=>ze(_e)).filter(vy).slice(0,xr))},ce=[d,R,W,Y,H],e[22]=d,e[23]=R,e[24]=W,e[25]=Y,e[26]=H,e[27]=se,e[28]=ce):(se=e[27],ce=e[28]),l.useEffect(se,ce);let oe;e[29]===Symbol.for("react.memo_cache_sentinel")?(oe=ze=>{E(_e=>{const ot=new Set(_e);return ot.has(ze)?ot.delete(ze):ot.add(ze),ot})},e[29]=oe):oe=e[29];const xe=oe;let we;e[30]===Symbol.for("react.memo_cache_sentinel")?(we=(ze,_e)=>{b(ot=>{const yt=new Set(ot),Mt=br(ze,_e);return yt.has(Mt)?yt.delete(Mt):yt.add(Mt),yt})},e[30]=we):we=e[30];const he=we;let Ie;e[31]!==D?(Ie=new Set,D.forEach(ze=>ze.entries.forEach(_e=>Ie.add(_e.path))),e[31]=D,e[32]=Ie):Ie=e[32];let ve;e[33]!==Ie?(ve=Array.from(Ie),e[33]=Ie,e[34]=ve):ve=e[34];const be=ve,ye=be.length;let te;e[35]!==m||e[36]!==M||e[37]!==r?(te=M?m||M.paths.some(ze=>r.has(ze)):!1,e[35]=m,e[36]=M,e[37]=r,e[38]=te):te=e[38];const ie=te;let ge;e[39]!==be||e[40]!==m||e[41]!==c?(ge=async()=>{!c||m||be.length===0||(await c(be),z(!1))},e[39]=be,e[40]=m,e[41]=c,e[42]=ge):ge=e[42];const _=ge;let ee;e[43]!==ie||e[44]!==x||e[45]!==M?(ee=async()=>{!x||!M||ie||(await x(M.paths),I(null))},e[43]=ie,e[44]=x,e[45]=M,e[46]=ee):ee=e[46];const ne=ee;let ue;e[47]!==w||e[48]!==p?(ue=(ze,_e)=>{const ot=w.has(ze.id),yt=ze.entries.length;return t.jsxs("div",{className:de("sticky top-0 z-10 flex items-center gap-2 py-2",p,ya,!_e&&"mt-1 border-t border-border/40"),children:[t.jsx("button",{type:"button",onClick:()=>ze.onActionAll(ze.entries.map(jy)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":ze.actionAllLabel,title:ze.actionAllLabel,children:ze.actionSymbol}),t.jsxs("button",{type:"button",onClick:()=>xe(ze.id),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-[var(--interactive-focus-ring)]","aria-expanded":!ot,children:[t.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:ze.title}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:yt}),t.jsx(A,{name:"arrow-down-s",className:de("size-3.5 shrink-0 text-muted-foreground transition-transform",ot&&"-rotate-90")})]})]})},e[47]=w,e[48]=p,e[49]=ue):ue=e[49];const Me=ue;let ke;e[50]!==y||e[51]!==m||e[52]!==x||e[53]!==r||e[54]!==u?(ke=(ze,_e,ot)=>{const yt=y.has(br(ze.id,_e.path)),Mt=_e.files.map(wy),Qt=m||Mt.some(Xt=>r.has(Xt));return t.jsxs("div",{className:de("group flex items-center gap-2 py-1.5",ya),style:{paddingLeft:`${ot*Zo}px`},children:[t.jsxs("button",{type:"button",onClick:()=>he(ze.id,_e.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":yt?u("gitView.changes.collapseDirectoryAria",{path:_e.path}):u("gitView.changes.expandDirectoryAria",{path:_e.path}),children:[yt?t.jsx(A,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):t.jsx(A,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:_e.path,children:_e.name}),t.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:_e.files.length})]}),ze.showRevertActions!==!1&&x?t.jsx("button",{type:"button",onClick:()=>I({path:_e.path,paths:Mt,count:Mt.length}),disabled:Qt,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-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50","aria-label":u("gitView.changes.revertDirectoryAria",{path:_e.path}),title:u("gitView.changes.revertDirectoryTooltip"),children:Qt?t.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(A,{name:"arrow-go-back",className:"size-3.5"})}):null,t.jsx("button",{type:"button",onClick:()=>ze.onActionAll(_e.files.map(Ny)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":u(ze.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:_e.path}),title:u(ze.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:_e.path}),children:ze.actionSymbol})]})},e[50]=y,e[51]=m,e[52]=x,e[53]=r,e[54]=u,e[55]=ke):ke=e[55];const De=ke;let Ae;e[56]!==a||e[57]!==m||e[58]!==g||e[59]!==De||e[60]!==Me||e[61]!==r||e[62]!==u||e[63]!==D?(Ae=(ze,_e)=>{if(ze.type==="revert-all")return t.jsx("div",{className:de("flex justify-end py-2",ya),children:t.jsxs(J,{variant:"ghost",size:"sm",onClick:()=>z(!0),disabled:m,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[t.jsx(A,{name:"arrow-go-back",className:"size-3.5"}),u("gitView.changes.revertAll")]})});const ot=D[ze.groupIndex];if(!ot)return null;if(ze.type==="header")return Me(ot,_e);if(ze.type==="directory")return De(ot,ze.directory,ze.depth);const yt=ze.file;return t.jsx(uy,{file:yt,actionLabel:ot.getActionLabel(yt.path),actionSymbol:ot.actionSymbol,onAction:()=>ot.onActionFile(yt.path),stats:a?.[yt.path],onViewDiff:()=>ot.onViewDiff(yt.path),onRevert:()=>ot.onRevertFile(yt.path),isReverting:r.has(yt.path)||m,rowPaddingClassName:ya,indentPx:ze.depth*Zo,actionAtStart:!g,showRevert:ot.showRevertActions!==!1})},e[56]=a,e[57]=m,e[58]=g,e[59]=De,e[60]=Me,e[61]=r,e[62]=u,e[63]=D,e[64]=Ae):Ae=e[64];const Pe=Ae;let Re;e[65]!==W?(Re=ze=>{const _e=W[ze],ot=W[ze-1];return!_e||!ot||_e.type!=="file"&&_e.type!=="directory"||ot.type!=="file"&&ot.type!=="directory"?!1:ot.groupIndex===_e.groupIndex},e[65]=W,e[66]=Re):Re=e[66];const Oe=Re;let $e;e[67]!==Pe||e[68]!==W||e[69]!==Y||e[70]!==Oe||e[71]!==u?($e=t.jsx(km,{ref:S,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:Y?t.jsx(ad,{ref:F,data:W,itemSize:ba,bufferSize:ba*12,scrollRef:S,onScroll:Z,children:(ze,_e)=>t.jsx("div",{className:de("relative",Oe(_e)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:Pe(ze,_e===0)},ze.key)}):t.jsx("div",{role:"list","aria-label":u("gitView.changes.changedFilesAria"),children:W.map((ze,_e)=>t.jsx("div",{className:de("relative",Oe(_e)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:Pe(ze,_e===0)},ze.key))})}),e[67]=Pe,e[68]=W,e[69]=Y,e[70]=Oe,e[71]=u,e[72]=$e):$e=e[72];let Be;e[73]===Symbol.for("react.memo_cache_sentinel")?(Be=t.jsx(Sm,{containerRef:S,disableHorizontal:!0}),e[73]=Be):Be=e[73];let Le;e[74]!==$e?(Le=t.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[$e,Be]}),e[74]=$e,e[75]=Le):Le=e[75];let Ue;e[76]!==m?(Ue=ze=>{!m&&!ze&&z(!1)},e[76]=m,e[77]=Ue):Ue=e[77];let le;e[78]!==u?(le=u("gitView.changes.revertAllDialogTitle"),e[78]=u,e[79]=le):le=e[79];let q;e[80]!==le?(q=t.jsx(Vt,{children:le}),e[80]=le,e[81]=q):q=e[81];let me;e[82]!==ye||e[83]!==u?(me=ye===1?u("gitView.changes.revertAllDescriptionSingle",{count:ye}):u("gitView.changes.revertAllDescriptionPlural",{count:ye}),e[82]=ye,e[83]=u,e[84]=me):me=e[84];let Ne;e[85]!==me?(Ne=t.jsx(qt,{children:me}),e[85]=me,e[86]=Ne):Ne=e[86];let Ee;e[87]!==q||e[88]!==Ne?(Ee=t.jsxs(_t,{children:[q,Ne]}),e[87]=q,e[88]=Ne,e[89]=Ee):Ee=e[89];let Ce;e[90]===Symbol.for("react.memo_cache_sentinel")?(Ce=()=>z(!1),e[90]=Ce):Ce=e[90];let He;e[91]!==u?(He=u("gitView.common.cancel"),e[91]=u,e[92]=He):He=e[92];let G;e[93]!==m||e[94]!==He?(G=t.jsx(J,{variant:"outline",size:"sm",onClick:Ce,disabled:m,children:He}),e[93]=m,e[94]=He,e[95]=G):G=e[95];let $;e[96]!==_?($=()=>{_()},e[96]=_,e[97]=$):$=e[97];let fe;e[98]!==m||e[99]!==u?(fe=u(m?"gitView.changes.reverting":"gitView.changes.revertAll"),e[98]=m,e[99]=u,e[100]=fe):fe=e[100];let L;e[101]!==m||e[102]!==$||e[103]!==fe?(L=t.jsx(J,{variant:"destructive",size:"sm",onClick:$,disabled:m,children:fe}),e[101]=m,e[102]=$,e[103]=fe,e[104]=L):L=e[104];let Fe;e[105]!==G||e[106]!==L?(Fe=t.jsxs(Yt,{children:[G,L]}),e[105]=G,e[106]=L,e[107]=Fe):Fe=e[107];let Je;e[108]!==Ee||e[109]!==Fe?(Je=t.jsxs(Bt,{className:"max-w-md",children:[Ee,Fe]}),e[108]=Ee,e[109]=Fe,e[110]=Je):Je=e[110];let Xe;e[111]!==P||e[112]!==Ue||e[113]!==Je?(Xe=t.jsx(Ut,{open:P,onOpenChange:Ue,children:Je}),e[111]=P,e[112]=Ue,e[113]=Je,e[114]=Xe):Xe=e[114];const et=!!M;let at;e[115]!==ie?(at=ze=>{!ie&&!ze&&I(null)},e[115]=ie,e[116]=at):at=e[116];let lt;e[117]!==u?(lt=u("gitView.changes.revertDirectoryDialogTitle"),e[117]=u,e[118]=lt):lt=e[118];let Ze;e[119]!==lt?(Ze=t.jsx(Vt,{children:lt}),e[119]=lt,e[120]=Ze):Ze=e[120];let We;e[121]!==M||e[122]!==u?(We=M?M.count===1?u("gitView.changes.revertDirectoryDescriptionSingle",{count:M.count,path:M.path}):u("gitView.changes.revertDirectoryDescriptionPlural",{count:M.count,path:M.path}):null,e[121]=M,e[122]=u,e[123]=We):We=e[123];let pt;e[124]!==We?(pt=t.jsx(qt,{children:We}),e[124]=We,e[125]=pt):pt=e[125];let pe;e[126]!==Ze||e[127]!==pt?(pe=t.jsxs(_t,{children:[Ze,pt]}),e[126]=Ze,e[127]=pt,e[128]=pe):pe=e[128];let st;e[129]===Symbol.for("react.memo_cache_sentinel")?(st=()=>I(null),e[129]=st):st=e[129];let nt;e[130]!==u?(nt=u("gitView.common.cancel"),e[130]=u,e[131]=nt):nt=e[131];let Ge;e[132]!==ie||e[133]!==nt?(Ge=t.jsx(J,{variant:"outline",size:"sm",onClick:st,disabled:ie,children:nt}),e[132]=ie,e[133]=nt,e[134]=Ge):Ge=e[134];let ft;e[135]!==ne?(ft=()=>{ne()},e[135]=ne,e[136]=ft):ft=e[136];const wt=ie||!M;let Ct;e[137]!==ie||e[138]!==u?(Ct=u(ie?"gitView.changes.reverting":"gitView.changes.revertDirectory"),e[137]=ie,e[138]=u,e[139]=Ct):Ct=e[139];let ae;e[140]!==ft||e[141]!==wt||e[142]!==Ct?(ae=t.jsx(J,{variant:"destructive",size:"sm",onClick:ft,disabled:wt,children:Ct}),e[140]=ft,e[141]=wt,e[142]=Ct,e[143]=ae):ae=e[143];let Ve;e[144]!==Ge||e[145]!==ae?(Ve=t.jsxs(Yt,{children:[Ge,ae]}),e[144]=Ge,e[145]=ae,e[146]=Ve):Ve=e[146];let tt;e[147]!==pe||e[148]!==Ve?(tt=t.jsxs(Bt,{className:"max-w-md",children:[pe,Ve]}),e[147]=pe,e[148]=Ve,e[149]=tt):tt=e[149];let Ye;e[150]!==et||e[151]!==at||e[152]!==tt?(Ye=t.jsx(Ut,{open:et,onOpenChange:at,children:tt}),e[150]=et,e[151]=at,e[152]=tt,e[153]=Ye):Ye=e[153];let bt;return e[154]!==Le||e[155]!==Xe||e[156]!==Ye?(bt=t.jsxs(t.Fragment,{children:[Le,Xe,Ye]}),e[154]=Le,e[155]=Xe,e[156]=Ye,e[157]=bt):bt=e[157],bt};function fy(s){return s.gitChangesViewMode}function xy(s){return s.entries.length>0}function by(s){return py(s.entries)}function yy(s){return s&&s.type==="file"?s.file.path:null}function vy(s){return!!s}function jy(s){return s.path}function wy(s){return s.path}function Ny(s){return s.path}const yr=38,va=200,ky=s=>{const e=rt.c(20),{value:n,onChange:a,placeholder:r,disabled:i,hasTouchInput:o,isMobile:d}=s,c=i===void 0?!1:i,x=o===void 0?!1:o,m=d===void 0?!1:d,{t:p}=dt(),u=l.useRef(null),S=Ke(Sy);let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{const z=u.current;if(!z)return;const M=document.activeElement===z,I=()=>{z.style.height=`${yr}px`;const j=z.scrollHeight,O=Math.min(Math.max(j,yr),va);z.style.height=`${O}px`,z.style.overflowY=j>va?"auto":"hidden",j>va&&!M&&(z.scrollTop=z.scrollHeight)};I();const v=window.requestAnimationFrame(I);return()=>{window.cancelAnimationFrame(v)}},e[0]=f):f=e[0];let g;e[1]!==n?(g=[n],e[1]=n,e[2]=g):g=e[2],l.useLayoutEffect(f,g);let h;e[3]!==a?(h=z=>a(z.target.value),e[3]=a,e[4]=h):h=e[4];let D;e[5]!==r||e[6]!==p?(D=r??p("gitView.commit.messagePlaceholder"),e[5]=r,e[6]=p,e[7]=D):D=e[7];const k=x?"on":"off",w=x?"sentences":"off",E=m||S,N=c&&"opacity-50";let y;e[8]!==N?(y=de("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)]",N),e[8]=N,e[9]=y):y=e[9];let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b={minHeight:yr,maxHeight:va},e[10]=b):b=e[10];let P;return e[11]!==c||e[12]!==E||e[13]!==y||e[14]!==h||e[15]!==D||e[16]!==k||e[17]!==w||e[18]!==n?(P=t.jsx("textarea",{ref:u,value:n,onChange:h,placeholder:D,rows:1,disabled:c,autoCorrect:k,autoCapitalize:w,spellCheck:E,className:y,style:b}),e[11]=c,e[12]=E,e[13]=y,e[14]=h,e[15]=D,e[16]=k,e[17]=w,e[18]=n,e[19]=P):P=e[19],P};function Sy(s){return s.inputSpellcheckEnabled}const Cy=s=>{const e=rt.c(30),{highlights:n,onInsert:a}=s,{t:r}=dt();if(n.length===0)return null;let i;e[0]!==n||e[1]!==a?(i=()=>{a(n)},e[0]=n,e[1]=a,e[2]=i):i=e[2];const o=i;let d;e[3]!==r?(d=r("gitView.commit.aiHighlights.title"),e[3]=r,e[4]=d):d=e[4];let c;e[5]!==d?(c=t.jsx("p",{className:"typography-micro text-muted-foreground",children:d}),e[5]=d,e[6]=c):c=e[6];let x;e[7]!==r?(x=r("gitView.commit.aiHighlights.insertAria"),e[7]=r,e[8]=x):x=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsx(A,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let p;e[10]!==o||e[11]!==x?(p=t.jsx(At,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"icon",className:"size-6",onClick:o,"aria-label":x,children:m})}),e[10]=o,e[11]=x,e[12]=p):p=e[12];let u;e[13]!==r?(u=r("gitView.commit.aiHighlights.insertTooltip"),e[13]=r,e[14]=u):u=e[14];let S;e[15]!==u?(S=t.jsx(Et,{sideOffset:8,children:u}),e[15]=u,e[16]=S):S=e[16];let f;e[17]!==p||e[18]!==S?(f=t.jsxs(Dt,{children:[p,S]}),e[17]=p,e[18]=S,e[19]=f):f=e[19];let g;e[20]!==c||e[21]!==f?(g=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c,f]}),e[20]=c,e[21]=f,e[22]=g):g=e[22];let h;e[23]!==n?(h=n.map(Py),e[23]=n,e[24]=h):h=e[24];let D;e[25]!==h?(D=t.jsx("ul",{className:"space-y-1",children:h}),e[25]=h,e[26]=D):D=e[26];let k;return e[27]!==g||e[28]!==D?(k=t.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[g,D]}),e[27]=g,e[28]=D,e[29]=k):k=e[29],k};function Py(s,e){return t.jsx("li",{className:"typography-meta text-foreground",children:s},`${s}-${e}`)}const _v=s=>{const e=rt.c(75),{stagedCount:n,commitMessage:a,onCommitMessageChange:r,generatedHighlights:i,onInsertHighlights:o,onGenerateMessage:d,isGeneratingMessage:c,onCommit:x,onCommitAndPush:m,commitAction:p,hasPendingIndexMutation:u,gitmojiEnabled:S,onOpenGitmojiPicker:f}=s,g=u===void 0?!1:u,{t:h}=dt(),D=n>0;let k;e[0]!==p||e[1]!==a||e[2]!==g||e[3]!==D?(k=a.trim()&&D&&p===null&&!g,e[0]=p,e[1]=a,e[2]=g,e[3]=D,e[4]=k):k=e[4];const w=k,{isMobile:E,hasTouchInput:N}=Cs();let y;e[5]!==h?(y=h("gitView.commit.title"),e[5]=h,e[6]=y):y=e[6];let b;e[7]!==y?(b=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:y}),e[7]=y,e[8]=b):b=e[8];let P;e[9]!==D||e[10]!==h?(P=D?null:t.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:h("gitView.commit.stageFilesHint")}),e[9]=D,e[10]=h,e[11]=P):P=e[11];let z;e[12]!==b||e[13]!==P?(z=t.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[b,P]}),e[12]=b,e[13]=P,e[14]=z):z=e[14];let M;e[15]!==i||e[16]!==o?(M=t.jsx(Cy,{highlights:i,onInsert:o}),e[15]=i,e[16]=o,e[17]=M):M=e[17];let I;e[18]!==h?(I=h("gitView.commit.messagePlaceholder"),e[18]=h,e[19]=I):I=e[19];const v=p!==null;let j;e[20]!==a||e[21]!==N||e[22]!==E||e[23]!==r||e[24]!==I||e[25]!==v?(j=t.jsx(ky,{value:a,onChange:r,placeholder:I,disabled:v,hasTouchInput:N,isMobile:E}),e[20]=a,e[21]=N,e[22]=E,e[23]=r,e[24]=I,e[25]=v,e[26]=j):j=e[26];let O;e[27]!==S||e[28]!==f||e[29]!==h?(O=S&&t.jsxs(J,{variant:"outline",size:"sm",onClick:f,className:"w-fit",type:"button",children:[t.jsx(A,{name:"emotion-happy",className:"size-4"}),h("gitView.commit.addGitmoji")]}),e[27]=S,e[28]=f,e[29]=h,e[30]=O):O=e[30];const T=c||p!==null||g||n===0;let U;e[31]!==h?(U=h("gitView.commit.generateAria"),e[31]=h,e[32]=U):U=e[32];let B;e[33]!==c?(B=c?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"ai-generate-2",className:"size-4 text-primary"}),e[33]=c,e[34]=B):B=e[34];let Q;e[35]!==h?(Q=h("gitView.commit.generate"),e[35]=h,e[36]=Q):Q=e[36];let W;e[37]!==Q?(W=t.jsx("span",{className:"commit-actions__label",children:Q}),e[37]=Q,e[38]=W):W=e[38];let R;e[39]!==d||e[40]!==T||e[41]!==U||e[42]!==B||e[43]!==W?(R=t.jsxs(J,{variant:"outline",size:"sm",onClick:d,disabled:T,type:"button","aria-label":U,className:"commit-actions__btn",children:[B,W]}),e[39]=d,e[40]=T,e[41]=U,e[42]=B,e[43]=W,e[44]=R):R=e[44];let Y;e[45]===Symbol.for("react.memo_cache_sentinel")?(Y=t.jsx("div",{className:"flex-1"}),e[45]=Y):Y=e[45];const F=!w||c;let H;e[46]!==h?(H=h("gitView.commit.commitAria"),e[46]=h,e[47]=H):H=e[47];let X;e[48]!==p||e[49]!==h?(X=p==="commit"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.committing")})]}):t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"git-commit",className:"size-4"}),t.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.commit")})]}),e[48]=p,e[49]=h,e[50]=X):X=e[50];let re;e[51]!==x||e[52]!==F||e[53]!==H||e[54]!==X?(re=t.jsx(J,{size:"sm",variant:"outline",onClick:x,disabled:F,className:"commit-actions__btn whitespace-nowrap","aria-label":H,children:X}),e[51]=x,e[52]=F,e[53]=H,e[54]=X,e[55]=re):re=e[55];let Z;e[56]!==w||e[57]!==p||e[58]!==c||e[59]!==E||e[60]!==m||e[61]!==h?(Z=E?t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(J,{variant:"default",size:"sm",onClick:()=>m(),disabled:!w||c,className:"h-7 w-7 p-0","aria-label":h("gitView.commit.pushAria"),children:p==="commitAndPush"?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"arrow-up",className:"size-3.5"})})}),t.jsx(Et,{side:"top",children:t.jsx("p",{children:h("gitView.commit.push")})})]}):t.jsx(J,{size:"sm",variant:"default",onClick:()=>m(),disabled:!w||c,className:"commit-actions__btn","aria-label":h("gitView.commit.pushAria"),children:p==="commitAndPush"?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:h("gitView.commit.pushing")})]}):t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"arrow-up",className:"size-3.5"}),t.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:h("gitView.commit.push")})]})}),e[56]=w,e[57]=p,e[58]=c,e[59]=E,e[60]=m,e[61]=h,e[62]=Z):Z=e[62];let se;e[63]!==R||e[64]!==re||e[65]!==Z?(se=t.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[R,Y,re,Z]}),e[63]=R,e[64]=re,e[65]=Z,e[66]=se):se=e[66];let ce;e[67]!==j||e[68]!==O||e[69]!==se||e[70]!==M?(ce=t.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[M,j,O,se]}),e[67]=j,e[68]=O,e[69]=se,e[70]=M,e[71]=ce):ce=e[71];let oe;return e[72]!==ce||e[73]!==z?(oe=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[z,ce]}),e[72]=ce,e[73]=z,e[74]=oe):oe=e[74],oe},Iy=s=>{const e=rt.c(41),{syncAction:n,remotes:a,onFetch:r,onSync:i,onRemoveRemote:o,disabled:d,removingRemoteName:c,aheadCount:x,behindCount:m,trackingRemoteName:p,hasUncommittedChanges:u}=s,S=a===void 0?[]:a,f=c===void 0?null:c,g=x===void 0?0:x,h=m===void 0?0:m,D=u===void 0?!1:u,{t:k}=dt(),w=l.useRef(!1),E=!!f,N=S.find(ie=>ie.name===p)??S[0],y=h>0&&D,b=d||n!==null||E||!N||y,P=d||n!==null||E||S.length===0,z=g>0||h>0;let M;e[0]!==k?(M=k("gitView.sync.sync"),e[0]=k,e[1]=M):M=e[1];const I=h>0?`↓${h}`:null,v=g>0?`↑${g}`:null;let j;e[2]!==M||e[3]!==I||e[4]!==v?(j=[M,I,v].filter(Boolean),e[2]=M,e[3]=I,e[4]=v,e[5]=j):j=e[5];const O=j.join(" "),T=y?k("gitView.sync.commitOrStashTooltip"):N?z?k("gitView.sync.syncChangesTooltip",{ahead:g,behind:h}):k("gitView.sync.syncChanges"):k("gitView.sync.noRemoteTooltip"),U=()=>{N&&i(N)},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 Q;e[6]===Symbol.for("react.memo_cache_sentinel")?(Q=de("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=Q):Q=e[6];let W;e[7]!==k?(W=k("gitView.sync.syncChanges"),e[7]=k,e[8]=W):W=e[8];let R;e[9]!==n?(R=n==="sync"?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=R):R=e[10];let Y;e[11]!==O?(Y=t.jsx("span",{className:"whitespace-nowrap tabular-nums",children:O}),e[11]=O,e[12]=Y):Y=e[12];let F;e[13]!==U||e[14]!==b||e[15]!==W||e[16]!==R||e[17]!==Y?(F=t.jsx(At,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:U,disabled:b,className:Q,"aria-label":W,children:[R,Y]})}),e[13]=U,e[14]=b,e[15]=W,e[16]=R,e[17]=Y,e[18]=F):F=e[18];let H;e[19]!==T?(H=t.jsx(Et,{sideOffset:8,children:T}),e[19]=T,e[20]=H):H=e[20];let X;e[21]!==F||e[22]!==H?(X=t.jsxs(Dt,{children:[F,H]}),e[21]=F,e[22]=H,e[23]=X):X=e[23];const re=us;let Z;e[24]===Symbol.for("react.memo_cache_sentinel")?(Z=de("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[24]=Z):Z=e[24];let se;e[25]!==k?(se=k("gitView.sync.moreActionsAria"),e[25]=k,e[26]=se):se=e[26];let ce;e[27]===Symbol.for("react.memo_cache_sentinel")?(ce=t.jsx(A,{name:"arrow-down-s",className:"size-4"}),e[27]=ce):ce=e[27];let oe;e[28]!==P||e[29]!==se?(oe=t.jsx(ds,{asChild:!0,children:t.jsx("button",{type:"button",className:Z,disabled:P,"aria-label":se,children:ce})}),e[28]=P,e[29]=se,e[30]=oe):oe=e[30];const xe=ms,we="start",he=-40,Ie="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ve=S.map(ie=>t.jsx(js,{onSelect:ge=>{if(w.current){ge.preventDefault(),w.current=!1;return}r(ie)},children:t.jsxs("div",{className:"flex w-full items-center gap-2",children:[t.jsx(A,{name:"refresh",className:"size-4 text-muted-foreground"}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:k("gitView.sync.fetchFromRemote",{name:ie.name})}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:ie.fetchUrl})]})}),o&&ie.name!==p?t.jsx(J,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||E,onPointerDown:ge=>{w.current=!0,ge.preventDefault(),ge.stopPropagation()},onClick:ge=>{w.current=!0,ge.preventDefault(),ge.stopPropagation(),o(ie)},"aria-label":k("gitView.header.removeRemoteAria",{name:ie.name}),title:k("gitView.header.removeRemoteTitle",{name:ie.name}),children:f===ie.name?t.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(A,{name:"close",className:"size-3.5"})}):null]})},ie.name));let be;e[31]!==xe||e[32]!==ve?(be=t.jsx(xe,{align:we,alignOffset:he,className:Ie,children:ve}),e[31]=xe,e[32]=ve,e[33]=be):be=e[33];let ye;e[34]!==re||e[35]!==oe||e[36]!==be?(ye=t.jsxs(re,{children:[oe,be]}),e[34]=re,e[35]=oe,e[36]=be,e[37]=ye):ye=e[37];let te;return e[38]!==X||e[39]!==ye?(te=t.jsxs("div",{className:B,children:[X,ye]}),e[38]=X,e[39]=ye,e[40]=te):te=e[40],te};function Dy(s){const e=rt.c(85),{draft:n,onEdit:a,onDelete:r,className:i,maxWidth:o}=s,{t:d}=dt(),x=za()?.currentTheme,[m,p]=je.useState(!1),[u,S]=je.useState(!1),f=typeof n.text=="string"?n.text:"";let g;e[0]!==f?(g=f.length>150||f.split(`
30
- `).length>3,e[0]=f,e[1]=g):g=e[1];const h=g;let D;e[2]!==i?(D=de("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]=D):D=e[3];const k=x?.colors?.surface?.elevated,w=x?.colors?.interactive?.border,E=o?`${Math.max(200,Math.floor(o))}px`:void 0;let N;e[4]!==k||e[5]!==w||e[6]!==E?(N={backgroundColor:k,borderColor:w,maxWidth:E},e[4]=k,e[5]=w,e[6]=E,e[7]=N):N=e[7];let y;e[8]===Symbol.for("react.memo_cache_sentinel")?(y=_=>{_.preventDefault(),S(!0)},e[8]=y):y=e[8];let b;e[9]!==D||e[10]!==N?(b=t.jsx("div",{className:D,style:N,"data-comment-card":"true",onContextMenu:y}),e[9]=D,e[10]=N,e[11]=b):b=e[11];let P;e[12]!==n.fileLabel?(P=t.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[12]=n.fileLabel,e[13]=P):P=e[13];let z;e[14]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx("span",{children:"•"}),e[14]=z):z=e[14];let M;e[15]!==n.endLine||e[16]!==n.startLine||e[17]!==d?(M=d("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[15]=n.endLine,e[16]=n.startLine,e[17]=d,e[18]=M):M=e[18];let I;e[19]!==M?(I=t.jsx("span",{children:M}),e[19]=M,e[20]=I):I=e[20];let v;e[21]!==n.side?(v=n.side&&t.jsxs("span",{children:["(",n.side,")"]}),e[21]=n.side,e[22]=v):v=e[22];let j;e[23]!==I||e[24]!==v||e[25]!==P?(j=t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[P,z,I,v]}),e[23]=I,e[24]=v,e[25]=P,e[26]=j):j=e[26];const O=m||!h,T=!m&&h&&"line-clamp-3";let U;e[27]!==T?(U=de("text-sm whitespace-pre-wrap break-words leading-relaxed",T),e[27]=T,e[28]=U):U=e[28];let B;e[29]!==f||e[30]!==U?(B=t.jsx("div",{className:U,children:f}),e[29]=f,e[30]=U,e[31]=B):B=e[31];let Q;e[32]!==h||e[33]!==m||e[34]!==d?(Q=h&&t.jsx(hn,{asChild:!0,children:t.jsx(J,{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?t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"arrow-up-s",className:"size-3 mr-1"}),d("inlineComment.actions.showLess")]}):t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"arrow-down-s",className:"size-3 mr-1"}),d("inlineComment.actions.showMore")]})})}),e[32]=h,e[33]=m,e[34]=d,e[35]=Q):Q=e[35];let W;e[36]===Symbol.for("react.memo_cache_sentinel")?(W=t.jsx(fn,{}),e[36]=W):W=e[36];let R;e[37]!==O||e[38]!==B||e[39]!==Q?(R=t.jsxs(gn,{open:O,onOpenChange:p,children:[B,Q,W]}),e[37]=O,e[38]=B,e[39]=Q,e[40]=R):R=e[40];let Y;e[41]!==j||e[42]!==R?(Y=t.jsxs("div",{className:"flex-1 min-w-0",children:[j,R]}),e[41]=j,e[42]=R,e[43]=Y):Y=e[43];let F;e[44]===Symbol.for("react.memo_cache_sentinel")?(F=t.jsx(ds,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:t.jsx(A,{name:"more",className:"size-4"})})}),e[44]=F):F=e[44];let H;e[45]===Symbol.for("react.memo_cache_sentinel")?(H=t.jsx(A,{name:"edit",className:"size-4 mr-2"}),e[45]=H):H=e[45];let X;e[46]!==d?(X=d("inlineComment.actions.editComment"),e[46]=d,e[47]=X):X=e[47];let re;e[48]!==a||e[49]!==X?(re=t.jsxs(js,{onClick:a,children:[H,X]}),e[48]=a,e[49]=X,e[50]=re):re=e[50];let Z;e[51]===Symbol.for("react.memo_cache_sentinel")?(Z=t.jsx(A,{name:"delete-bin",className:"size-4 mr-2"}),e[51]=Z):Z=e[51];let se;e[52]!==d?(se=d("inlineComment.actions.deleteComment"),e[52]=d,e[53]=se):se=e[53];let ce;e[54]!==r||e[55]!==se?(ce=t.jsxs(js,{onClick:r,className:"text-destructive",children:[Z,se]}),e[54]=r,e[55]=se,e[56]=ce):ce=e[56];let oe;e[57]!==re||e[58]!==ce?(oe=t.jsxs(us,{children:[F,t.jsxs(ms,{align:"end",children:[re,ce]})]}),e[57]=re,e[58]=ce,e[59]=oe):oe=e[59];let xe;e[60]!==Y||e[61]!==oe?(xe=t.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[Y,oe]}),e[60]=Y,e[61]=oe,e[62]=xe):xe=e[62];let we;e[63]!==xe||e[64]!==b?(we=t.jsx(tn,{render:b,children:xe}),e[63]=xe,e[64]=b,e[65]=we):we=e[65];let he;e[66]===Symbol.for("react.memo_cache_sentinel")?(he=t.jsx(A,{name:"edit",className:"size-4 mr-2"}),e[66]=he):he=e[66];let Ie;e[67]!==d?(Ie=d("inlineComment.actions.editComment"),e[67]=d,e[68]=Ie):Ie=e[68];let ve;e[69]!==a||e[70]!==Ie?(ve=t.jsxs(Ws,{onClick:a,children:[he,Ie]}),e[69]=a,e[70]=Ie,e[71]=ve):ve=e[71];let be;e[72]===Symbol.for("react.memo_cache_sentinel")?(be=t.jsx(A,{name:"delete-bin",className:"size-4 mr-2"}),e[72]=be):be=e[72];let ye;e[73]!==d?(ye=d("inlineComment.actions.deleteComment"),e[73]=d,e[74]=ye):ye=e[74];let te;e[75]!==r||e[76]!==ye?(te=t.jsxs(Ws,{onClick:r,className:"text-destructive focus:text-destructive",children:[be,ye]}),e[75]=r,e[76]=ye,e[77]=te):te=e[77];let ie;e[78]!==ve||e[79]!==te?(ie=t.jsxs(sn,{children:[ve,te]}),e[78]=ve,e[79]=te,e[80]=ie):ie=e[80];let ge;return e[81]!==u||e[82]!==we||e[83]!==ie?(ge=t.jsxs(en,{open:u,onOpenChange:S,children:[we,ie]}),e[81]=u,e[82]=we,e[83]=ie,e[84]=ge):ge=e[84],ge}function tl(s){const e=rt.c(62),{initialText:n,onTextChange:a,onSave:r,onCancel:i,fileLabel:o,lineRange:d,isEditing:c,className:x,maxWidth:m}=s,p=n===void 0?"":n,u=c===void 0?!1:c,{t:S}=dt(),g=za()?.currentTheme,{isMobile:h}=Cs(),[D,k]=l.useState(p),w=je.useRef(null);let E;e[0]!==a?(E=ne=>{k(ne),a?.(ne)},e[0]=a,e[1]=E):E=e[1];const N=E,y=je.useRef(d);let b,P;e[2]!==d?(b=()=>{d&&(y.current=d)},P=[d],e[2]=d,e[3]=b,e[4]=P):(b=e[3],P=e[4]),je.useEffect(b,P);const z=Oy,M=z(d);let I,v;e[5]!==h?(I=()=>{const ne=w.current;if(!ne)return;const ue=ne.closest(".overlay-scrollbar-container"),Me=ue?.scrollTop??window.scrollY,ke=ue?.scrollLeft??window.scrollX;if(h){ne.scrollIntoView({behavior:"auto",block:"nearest"});try{ne.focus({preventScroll:!0})}catch{ne.focus()}return}try{ne.focus({preventScroll:!0})}catch{ne.focus()}const De=ne.value.length;try{ne.setSelectionRange(De,De)}catch{}requestAnimationFrame(()=>{ue?(ue.scrollTop=Me,ue.scrollLeft=ke):window.scrollTo({top:Me,left:ke})})},v=[h],e[5]=h,e[6]=I,e[7]=v):(I=e[6],v=e[7]),je.useEffect(I,v);let j;e[8]!==i||e[9]!==r||e[10]!==D?(j=ne=>{(ne.metaKey||ne.ctrlKey)&&ne.key==="Enter"?(ne.preventDefault(),D.trim()&&r(D,z(y.current))):ne.key==="Escape"&&(ne.preventDefault(),i())},e[8]=i,e[9]=r,e[10]=D,e[11]=j):j=e[11];const O=j;let T;e[12]!==r||e[13]!==D?(T=ne=>{ne.stopPropagation(),D.trim()&&r(D,z(y.current))},e[12]=r,e[13]=D,e[14]=T):T=e[14];const U=T;let B;e[15]!==x?(B=de("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",x),e[15]=x,e[16]=B):B=e[16];const Q=g?.colors?.surface?.elevated,W=g?.colors?.interactive?.border,R=m?`${Math.max(200,Math.floor(m))}px`:void 0;let Y;e[17]!==Q||e[18]!==W||e[19]!==R?(Y={backgroundColor:Q,borderColor:W,maxWidth:R},e[17]=Q,e[18]=W,e[19]=R,e[20]=Y):Y=e[20];const F="true",H=Fy,X=Ty,re="p-3",Z=(o||d)&&t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[o&&t.jsx("span",{className:"truncate max-w-[200px]",children:o}),o&&d&&t.jsx("span",{children:"•"}),M&&t.jsx("span",{children:S("inlineComment.range.lines",{start:M.start,end:M.end})})]});let se;e[21]!==N?(se=ne=>N(ne.target.value),e[21]=N,e[22]=se):se=e[22];let ce;e[23]!==h||e[24]!==S?(ce=S(h?"inlineComment.input.placeholderShort":"inlineComment.input.placeholder"),e[23]=h,e[24]=S,e[25]=ce):ce=e[25];let oe;e[26]!==O||e[27]!==se||e[28]!==ce||e[29]!==D?(oe=t.jsx(ps,{simple:!0,ref:w,value:D,onChange:se,onKeyDown:O,placeholder:ce,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[26]=O,e[27]=se,e[28]=ce,e[29]=D,e[30]=oe):oe=e[30];let xe;e[31]!==S?(xe=S("inlineComment.actions.cancel"),e[31]=S,e[32]=xe):xe=e[32];let we;e[33]!==i||e[34]!==xe?(we=t.jsx(J,{variant:"ghost",size:"sm",onClick:i,onPointerDown:Ry,onTouchStart:My,className:"h-8 text-muted-foreground hover:text-foreground",children:xe}),e[33]=i,e[34]=xe,e[35]=we):we=e[35];let he;e[36]!==D?(he=D.trim(),e[36]=D,e[37]=he):he=e[37];const Ie=!he,ve=g?.colors?.status?.success,be=g?.colors?.status?.successForeground;let ye;e[38]!==ve||e[39]!==be?(ye={backgroundColor:ve,color:be},e[38]=ve,e[39]=be,e[40]=ye):ye=e[40];let te;e[41]!==u||e[42]!==S?(te=S(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[41]=u,e[42]=S,e[43]=te):te=e[43];let ie;e[44]!==U||e[45]!==Ie||e[46]!==ye||e[47]!==te?(ie=t.jsx(J,{size:"sm",onClick:U,onPointerDown:Ey,onTouchStart:Ay,disabled:Ie,className:"h-8 min-w-[80px]",style:ye,children:te}),e[44]=U,e[45]=Ie,e[46]=ye,e[47]=te,e[48]=ie):ie=e[48];let ge;e[49]!==we||e[50]!==ie?(ge=t.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[we,ie]}),e[49]=we,e[50]=ie,e[51]=ge):ge=e[51];let _;e[52]!==Z||e[53]!==oe||e[54]!==ge?(_=t.jsxs("div",{className:re,children:[Z,oe,ge]}),e[52]=Z,e[53]=oe,e[54]=ge,e[55]=_):_=e[55];let ee;return e[56]!==B||e[57]!==Y||e[58]!==H||e[59]!==X||e[60]!==_?(ee=t.jsx("div",{className:B,style:Y,"data-comment-input":F,onPointerDown:H,onTouchStart:X,children:_}),e[56]=B,e[57]=Y,e[58]=H,e[59]=X,e[60]=_,e[61]=ee):ee=e[61],ee}function Ay(s){return s.stopPropagation()}function Ey(s){return s.stopPropagation()}function My(s){return s.stopPropagation()}function Ry(s){return s.stopPropagation()}function Ty(s){return s.stopPropagation()}function Fy(s){return s.stopPropagation()}function Oy(s){if(!s)return;const e=Math.min(s.start,s.end),n=Math.max(s.start,s.end);return{...s,start:e,end:n}}const Ly=s=>{const e=Math.min(s.startLine,s.endLine),n=Math.max(s.startLine,s.endLine);return{...s,startLine:e,endLine:n}},sl=s=>{const e=Math.min(s.start,s.end),n=Math.max(s.start,s.end);return{...s,start:e,end:n}};function zy(s){const e=rt.c(40),{t:n}=dt(),{source:a,fileLabel:r,language:i,getCodeForRange:o,toStoreRange:d,fromDraftRange:c}=s,x=Ps(_y),m=Ps(Vy),p=aa(By),u=aa(Uy),S=aa($y),f=aa(Ky),[g,h]=l.useState(null),[D,k]=l.useState(""),[w,E]=l.useState(null),N=x??(m?"draft":null);let y;e:{if(!N||!r){let F;e[0]===Symbol.for("react.memo_cache_sentinel")?(F=[],e[0]=F):F=e[0],y=F;break e}let W;e[1]!==f||e[2]!==N?(W=f[N]??[],e[1]=f,e[2]=N,e[3]=W):W=e[3];const R=W;let Y;if(e[4]!==r||e[5]!==R||e[6]!==a){let F;e[8]!==r||e[9]!==a?(F=H=>H.source===a&&H.fileLabel===r,e[8]=r,e[9]=a,e[10]=F):F=e[10],Y=R.filter(F),e[4]=r,e[5]=R,e[6]=a,e[7]=Y}else Y=e[7];y=Y}const b=y;let P;e[11]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{h(null),k(""),E(null)},e[11]=P):P=e[11];const z=P;let M;e[12]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{z()},e[12]=M):M=e[12];const I=M;let v;e[13]!==c?(v=W=>{const R=sl(c(W));h(R),k(W.text),E(W.id)},e[13]=c,e[14]=v):v=e[14];const j=v;let O;e[15]!==w||e[16]!==S?(O=W=>{S(W.sessionKey,W.id),w===W.id&&z()},e[15]=w,e[16]=S,e[17]=O):O=e[17];const T=O;let U;e[18]!==p||e[19]!==w||e[20]!==r||e[21]!==o||e[22]!==i||e[23]!==g||e[24]!==N||e[25]!==a||e[26]!==n||e[27]!==d||e[28]!==u?(U=(W,R)=>{const Y=R??g,F=W.trim();if(!Y||!F||!r)return;if(!N){V.error(n("inlineComment.toast.selectSessionToSave"));return}const H=sl(Y),X=Ly(d(H)),re=o(H);w?u(N,w,{fileLabel:r,startLine:X.startLine,endLine:X.endLine,side:X.side,code:re,language:i,text:F}):p({sessionKey:N,source:a,fileLabel:r,startLine:X.startLine,endLine:X.endLine,side:X.side,code:re,language:i,text:F}),z()},e[18]=p,e[19]=w,e[20]=r,e[21]=o,e[22]=i,e[23]=g,e[24]=N,e[25]=a,e[26]=n,e[27]=d,e[28]=u,e[29]=U):U=e[29];const B=U;let Q;return e[30]!==D||e[31]!==T||e[32]!==b||e[33]!==w||e[34]!==c||e[35]!==B||e[36]!==g||e[37]!==N||e[38]!==j?(Q={sessionKey:N,drafts:b,selection:g,setSelection:h,commentText:D,setCommentText:k,editingDraftId:w,setEditingDraftId:E,reset:z,cancel:I,startEdit:j,deleteDraft:T,saveComment:B,fromDraftRange:c},e[30]=D,e[31]=T,e[32]=b,e[33]=w,e[34]=c,e[35]=B,e[36]=g,e[37]=N,e[38]=j,e[39]=Q):Q=e[39],Q}function Ky(s){return s.drafts}function $y(s){return s.removeDraft}function Uy(s){return s.updateDraft}function By(s){return s.addDraft}function Vy(s){return s.newSessionDraft?.open}function _y(s){return s.currentSessionId}const Ea=s=>{if(s.type==="new"){const e=Math.min(s.selection.start,s.selection.end),n=Math.max(s.selection.start,s.selection.end);return`new-comment-${s.selection.side??"additions"}-${e}-${n}`}return`draft-${s.draft.id}`},Hy=s=>{const{drafts:e,editingDraftId:n,selection:a}=s,r=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const o=Math.max(1,Math.floor(i.endLine)),d=i.side==="original"?"deletions":"additions";r.push({lineNumber:o,side:d,metadata:{type:i.id===n?"edit":"saved",draft:i}})}return a&&!n&&r.push({lineNumber:Math.max(a.start,a.end),side:a.side??"additions",metadata:{type:"new",selection:a}}),r};function Wy(s){const e=s.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 nl(s){if(!(!s||s<=0))return Math.max(200,Math.floor(s))}function qy(s){const{diffRootRef:e,drafts:n,selection:a,editingDraftId:r,commentText:i,onTextChange:o,fileLabel:d,onSave:c,onCancel:x,onEdit:m,onDelete:p}=s,[u,S]=l.useState(0),[f,g]=l.useState(null),h=l.useMemo(()=>!a||r?null:Ea({type:"new",selection:a}),[r,a]),D=l.useMemo(()=>{const E=n.map(N=>Ea({type:N.id===r?"edit":"saved",draft:N}));return h&&E.push(h),E},[n,r,h]),k=l.useCallback(E=>{const N=e.current;if(!N)return null;const y=N.querySelector("diffs-container");if(!(y instanceof HTMLElement))return null;const b=y.querySelector(`[data-annotation-id="${E}"]`);if(b instanceof HTMLElement)return b;const P=y.shadowRoot;return P?P.querySelector(`[data-annotation-id="${E}"]`):null},[e]);l.useEffect(()=>{if(D.length===0)return;let E=!1,N=0;const y=12,b=()=>{E||D.every(z=>!!k(z))||N>=y||(N+=1,requestAnimationFrame(()=>{E||(S(z=>z+1),b())}))};return b(),()=>{E=!0}},[D,k]),l.useEffect(()=>{const E=e.current;if(!E)return;const N=()=>{const b=getComputedStyle(E),P=Wy(b.getPropertyValue("--oc-context-panel-width")),z=E.getBoundingClientRect(),M=P??z.width;g(M>0?M:null)};N();const y=new ResizeObserver(()=>{N()});return y.observe(E),window.addEventListener("resize",N),()=>{y.disconnect(),window.removeEventListener("resize",N)}},[e]);const w=l.useCallback(E=>{const y=e.current?.getBoundingClientRect(),b=E.closest("[data-annotation-content]"),P=b instanceof HTMLElement?b.getBoundingClientRect():E.getBoundingClientRect(),z=[P.width];y&&z.push(y.right-P.left);const M=z.filter(I=>Number.isFinite(I)&&I>0);return M.length>0?nl(Math.min(...M)):nl(f)},[e,f]);return t.jsxs(t.Fragment,{children:[n.map(E=>{const N=Ea({type:E.id===r?"edit":"saved",draft:E}),y=k(N);if(!y)return null;const b=w(y);return E.id===r?wa.createPortal(t.jsx(tl,{initialText:i,onTextChange:o,fileLabel:d,lineRange:{start:E.startLine,end:E.endLine,side:E.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:x,maxWidth:b}),y,`draft-edit-${E.id}`):wa.createPortal(t.jsx(Dy,{draft:E,onEdit:()=>m(E),onDelete:()=>p(E),maxWidth:b}),y,`draft-card-${E.id}`)}),a&&!r&&h&&(()=>{const E=k(h);if(!E)return null;const N=w(E);return wa.createPortal(t.jsx(tl,{initialText:i,onTextChange:o,fileLabel:d,lineRange:a,isEditing:!1,onSave:c,onCancel:x,maxWidth:N}),E,h)})()]})}const al=5e5,Gy=`
31
- :host {
32
- font-family: var(--font-mono);
33
- font-size: var(--text-code);
34
- }
35
-
36
- pre, [data-code] {
37
- font-family: var(--font-mono);
38
- font-size: var(--text-code);
39
- }
40
-
41
- /* Mobile touch selection support */
42
- [data-line-number] {
43
- touch-action: manipulation;
44
- -webkit-tap-highlight-color: transparent;
45
- cursor: pointer;
46
- }
47
-
48
- /* Ensure interactive line numbers work on touch */
49
- pre[data-interactive-line-numbers] [data-line-number] {
50
- touch-action: manipulation;
51
- }
52
- `,Jy=`
53
- ${Gy}
54
-
55
- :host {
56
- --diffs-bg-separator-override: var(--surface-elevated);
57
- }
58
-
59
- [data-diff-header],
60
- [data-diff] {
61
- [data-separator] {
62
- height: 24px !important;
63
- }
64
- }
65
-
66
- [data-separator="line-info-basic"] {
67
- height: 24px !important;
68
- background: var(--diffs-bg) !important;
69
- position: relative;
70
- }
71
-
72
- [data-diff-type="single"] [data-gutter],
73
- [data-diff-type="split"] [data-deletions] [data-gutter] {
74
- [data-separator-wrapper] {
75
- position: absolute;
76
- left: 100%;
77
- display: flex;
78
- align-items: center;
79
- gap: unset;
80
- width: max-content;
81
- background: transparent;
82
- color: var(--diffs-fg-number);
83
- font-family: var(--diffs-header-font-family, var(--font-sans));
84
- font-size: 0.75rem;
85
- line-height: 1;
86
- margin-left: calc(-2ch - 2px);
87
- }
88
-
89
- [data-separator-wrapper][data-separator-multi-button] {
90
- margin-left: calc(-3ch - 2px);
91
- }
92
-
93
- [data-expand-button],
94
- [data-separator-content] {
95
- display: block;
96
- align-self: unset;
97
- min-width: unset;
98
- min-height: unset;
99
- padding: 0;
100
- flex-shrink: 0;
101
- grid-column: unset;
102
- border: none;
103
- width: auto;
104
- height: auto;
105
- background-color: transparent;
106
- color: inherit;
107
- font: inherit;
108
- }
109
-
110
- [data-expand-button]:not([data-expand-all-button]) {
111
- &[data-expand-down]::before {
112
- content: '\\2191';
113
- }
114
-
115
- &[data-expand-up]::before {
116
- content: '\\2193';
117
- }
118
-
119
- &[data-expand-both]::before {
120
- content: '\\2195';
121
- }
122
-
123
- svg {
124
- display: none;
125
- }
126
- }
127
-
128
- [data-separator-content] {
129
- background: transparent;
130
- margin-left: calc(2px + 1ch);
131
- }
132
-
133
- [data-expand-all-button] {
134
- position: relative;
135
- margin-left: 14px;
136
- text-transform: lowercase;
137
- }
138
-
139
- [data-expand-all-button]::before {
140
- content: '';
141
- display: block;
142
- position: absolute;
143
- top: 50%;
144
- left: -8px;
145
- margin-top: -1px;
146
- width: 3px;
147
- height: 3px;
148
- border-radius: 2px;
149
- background-color: var(--diffs-fg-number);
150
- pointer-events: none;
151
- }
152
-
153
- [data-separator-content]:hover,
154
- [data-expand-button]:hover,
155
- [data-expand-all-button]:hover {
156
- color: var(--diffs-fg);
157
- }
158
-
159
- [data-expand-all-button]:hover {
160
- text-decoration: underline;
161
- }
162
- }
163
- `;function Qy(s){let e=2166136261;for(let n=0;n<s.length;n+=1)e^=s.charCodeAt(n),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return e.toString(16)}function rl(s){const e=s.length>400?`${s.slice(0,200)}${s.slice(-200)}`:s;return`${s.length}:${Qy(e)}`}const Yy=(s,e,n,a)=>{const r=a.side==="deletions",o=(n?(r?n.deletionLines:n.additionLines).join(""):r?s:e).split(`
164
- `),d=Math.min(a.start,a.end),c=Math.max(a.start,a.end),x=Math.max(1,d),m=Math.min(o.length,c);return x>m?"":o.slice(x-1,m).join(`
165
- `)},Xy=(s,e)=>s===e?!0:!s||!e?!1:s.start===e.start&&s.end===e.end&&s.side===e.side,Zy=s=>s==="auto"||s==="scroll"||s==="overlay",ev=s=>{let e=s?.parentElement??null;for(;e;){const n=window.getComputedStyle(e);if(Zy(n.overflowY))return e;e=e.parentElement}return null},tv=(s,e)=>{if(!s||!e||typeof window>"u")return()=>{};const n=ev(s);if(!n)return()=>{};const a=e.getBoundingClientRect().height;if(!a)return()=>{};const r=s.getBoundingClientRect().top-n.getBoundingClientRect().top,i=e.style.minHeight;e.style.minHeight=`${Math.ceil(a)}px`;let o=!1;return()=>{if(o)return;o=!0,e.style.minHeight=i;const c=s.getBoundingClientRect().top-n.getBoundingClientRect().top-r;c&&(n.scrollTop+=c)}},sv=(s,e)=>{if(typeof window>"u")return()=>{};let n=null,a=null,r=!1;const i=()=>{r||(a?.disconnect(),a=null,n=window.requestAnimationFrame(()=>{n=window.requestAnimationFrame(()=>{r||e()})}))},o=()=>s.querySelector("diffs-container")?.shadowRoot??void 0,d=(c=o())=>!!c?.querySelector("[data-line]");return d()?i():typeof MutationObserver<"u"?(a=new MutationObserver(()=>{const c=o();if(c){if(d(c)){i();return}a?.disconnect(),a=new MutationObserver(()=>{d(c)&&i()}),a.observe(c,{childList:!0,subtree:!0})}}),a.observe(s,{childList:!0,subtree:!0})):n=window.requestAnimationFrame(i),()=>{r=!0,a?.disconnect(),n!==null&&window.cancelAnimationFrame(n)}},ja=new WeakMap,nv={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function av(s){const e=s.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 rv(s){if(typeof document>"u")return null;const e=av(s);let n=ja.get(e.key);if(!n){const r=new ld;r.setup(e.root,e.content),n={virtualizer:r,refs:0},ja.set(e.key,n)}n.refs+=1;let a=!1;return{virtualizer:n.virtualizer,root:e.root,release:()=>{if(a)return;a=!0;const r=ja.get(e.key);r&&(r.refs-=1,!(r.refs>0)&&(r.virtualizer.cleanUp(),ja.delete(e.key)))}}}const iv=(s,e,n)=>{if(typeof window>"u")return()=>{};const a=[],r=()=>{try{s.rerender()}catch{}const i=e?.root;i instanceof HTMLElement?i.dispatchEvent(new Event("scroll",{bubbles:!1})):document.dispatchEvent(new Event("scroll",{bubbles:!1})),window.dispatchEvent(new Event("resize")),n()};return a.push(window.requestAnimationFrame(r)),a.push(window.requestAnimationFrame(()=>{a.push(window.requestAnimationFrame(r))})),()=>{for(const i of a)window.cancelAnimationFrame(i)}},Hv=({original:s,modified:e,fileDiff:n,language:a,fileName:r,renderSideBySide:i,wrapLines:o,layout:d="fill",enableComments:c=!0})=>{const x=za(),m=x?.currentTheme.metadata.variant==="dark",p=x?.availableThemes.find(_=>_.metadata.id===x.lightThemeId)??Ra(!1),u=x?.availableThemes.find(_=>_.metadata.id===x.darkThemeId)??Ra(!0),{isMobile:S}=Cs(),f=zy({source:"diff",fileLabel:r||"unknown",language:a,getCodeForRange:_=>Yy(s,e,n,_),toStoreRange:_=>({startLine:_.start,endLine:_.end,side:_.side==="deletions"?"original":"modified"}),fromDraftRange:_=>({start:_.startLine,end:_.endLine,side:_.side==="original"?"deletions":"additions"})}),{drafts:g,selection:h,setSelection:D,commentText:k,setCommentText:w,editingDraftId:E,saveComment:N,cancel:y,startEdit:b,deleteDraft:P}=f,z=je.useRef(null),M=je.useRef(null),I=je.useRef(""),v=je.useRef(!1),j=je.useRef(null);je.useEffect(()=>{z.current=h},[h]),je.useEffect(()=>{M.current=E},[E]),je.useEffect(()=>{I.current=k},[k]);const O=je.useCallback(_=>{if(!c||v.current)return;const ee=z.current;if(!(!_&&ee&&I.current.trim())){if(S&&ee&&_&&_.side===ee.side){const ne=Math.min(ee.start,_.start),ue=Math.max(ee.end,_.end);D({..._,start:ne,end:ue})}else D(_);_&&(M.current||w(""))}},[c,S,w,D]),T=je.useCallback(()=>{y()},[y]),U=je.useCallback(_=>{const ee=document.createElement("div");ee.style.position="relative";const ne=Ea(_.metadata);return ee.dataset.annotationId=ne,ee.dataset.annotationSide=_.side,ee.dataset.annotationLine=String(_.lineNumber),ee},[]),B=je.useCallback((_,ee)=>{N(_,ee??h??void 0)},[N,h]),Q=je.useCallback(_=>{D(_);const ee=X.current;if(ee)try{v.current=!0,ee.setSelectedLines(_),j.current=_}catch{}finally{v.current=!1}},[D]),W=je.useCallback(_=>{const ee=_.closest("[data-line-type]")?.getAttribute("data-line-type")??_.getAttribute("data-line-type");if(ee==="change-deletion")return"deletions";if(ee==="change-addition")return"additions";const ne=_.getAttribute("data-column-side")??_.getAttribute("data-side")??_.closest("[data-column-side]")?.getAttribute("data-column-side");if(ne==="deletions"||ne==="left"||ne==="original")return"deletions";if(ne==="additions"||ne==="right"||ne==="modified")return"additions";const ue=_.closest("[data-line-type]");if(ue instanceof HTMLElement){const Me=ue.getBoundingClientRect(),ke=_.getBoundingClientRect(),De=Me.left+Me.width/2;return ke.left+ke.width/2<De?"deletions":"additions"}return"additions"},[]);Ta(p),Ta(u);const R=`${p.metadata.id}:${u.metadata.id}:${m?"dark":"light"}`,Y=je.useMemo(()=>{if(n){const _=n.deletionLines.reduce((ne,ue)=>ne+ue.length,0),ee=n.additionLines.reduce((ne,ue)=>ne+ue.length,0);return Math.max(_,ee)>al}return Math.max(s.length,e.length)>al},[n,e.length,s.length]),F=je.useRef(null),H=je.useRef(null),X=je.useRef(null),re=je.useRef(null),Z=je.useRef(null),se=je.useRef(null),ce=je.useRef(void 0),oe=je.useRef(void 0),xe=je.useRef(void 0),we=je.useRef(void 0),[,he]=l.useReducer(_=>_+1,0),Ie=Ir(Y?"unified":i?"split":"unified"),ve=je.useMemo(()=>wr(p),[p]),be=je.useMemo(()=>wr(u),[u]);l.useLayoutEffect(()=>{const _=F.current;if(!_)return;const ee=_.querySelector("diffs-container");if(!ee)return;const ne=m?be:ve,ue=(Ue,le)=>Ue.colors?.[le],Me=ue(ve,"terminal.ansiGreen"),ke=ue(ve,"terminal.ansiRed"),De=ue(ve,"terminal.ansiBlue"),Ae=ue(be,"terminal.ansiGreen"),Pe=ue(be,"terminal.ansiRed"),Re=ue(be,"terminal.ansiBlue");ee.style.setProperty("--shiki-light",ve.fg),ee.style.setProperty("--shiki-light-bg",ve.bg),Me&&ee.style.setProperty("--shiki-light-addition-color",Me),ke&&ee.style.setProperty("--shiki-light-deletion-color",ke),De&&ee.style.setProperty("--shiki-light-modified-color",De),ee.style.setProperty("--shiki-dark",be.fg),ee.style.setProperty("--shiki-dark-bg",be.bg),Ae&&ee.style.setProperty("--shiki-dark-addition-color",Ae),Pe&&ee.style.setProperty("--shiki-dark-deletion-color",Pe),Re&&ee.style.setProperty("--shiki-dark-modified-color",Re),ee.style.setProperty("--diffs-bg",ne.bg),ee.style.setProperty("--diffs-fg",ne.fg);const Oe=m?Ae:Me,$e=m?Pe:ke,Be=m?Re:De;Oe&&ee.style.setProperty("--diffs-addition-color-override",Oe),$e&&ee.style.setProperty("--diffs-deletion-color-override",$e),Be&&ee.style.setProperty("--diffs-modified-color-override",Be);const Le=ee.shadowRoot?.querySelector("pre");Le&&(Le.style.setProperty("--shiki-light",ve.fg),Le.style.setProperty("--shiki-light-bg",ve.bg),Me&&Le.style.setProperty("--shiki-light-addition-color",Me),ke&&Le.style.setProperty("--shiki-light-deletion-color",ke),De&&Le.style.setProperty("--shiki-light-modified-color",De),Le.style.setProperty("--shiki-dark",be.fg),Le.style.setProperty("--shiki-dark-bg",be.bg),Ae&&Le.style.setProperty("--shiki-dark-addition-color",Ae),Pe&&Le.style.setProperty("--shiki-dark-deletion-color",Pe),Re&&Le.style.setProperty("--shiki-dark-modified-color",Re),Le.style.setProperty("--diffs-bg",ne.bg),Le.style.setProperty("--diffs-fg",ne.fg),Oe&&Le.style.setProperty("--diffs-addition-color-override",Oe),$e&&Le.style.setProperty("--diffs-deletion-color-override",$e),Be&&Le.style.setProperty("--diffs-modified-color-override",Be))},[be,R,m,ve]);const ye=je.useMemo(()=>({theme:{dark:u.metadata.id,light:p.metadata.id},themeType:m?"dark":"light",diffStyle:i?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:Y?0:1e3,maxLineLengthForHighlighting:Y?1:1e3,tokenizeMaxLineLength:Y?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:o?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:c,enableHoverUtility:!1,onLineSelected:c?O:void 0,unsafeCSS:Jy,renderAnnotation:c?U:void 0}),[u.metadata.id,c,m,Y,p.metadata.id,i,o,O,U]),te=je.useMemo(()=>c?Hy({drafts:g,editingDraftId:E,selection:h}):[],[E,c,g,h]),ie=je.useRef(te);if(je.useEffect(()=>{ie.current=te},[te]),je.useEffect(()=>{const _=H.current;return()=>{X.current?.cleanUp(),X.current=null,re.current?.release(),re.current=null,Z.current=null,se.current=null,ce.current=void 0,oe.current=void 0,xe.current=void 0,we.current=void 0,_&&(_.innerHTML="")}},[]),je.useEffect(()=>{if(typeof window>"u")return;const _=H.current,ee=F.current;if(!_||!Ie)return;const ne=tv(ee,_);let ue=re.current;ue||(ue=rv(_),re.current=ue),re.current=ue;const Me=ue?.virtualizer??null,ke=n?void 0:{name:r||"",contents:s,lang:a,cacheKey:`old:${R}:${r}:${rl(s)}`},De=n?void 0:{name:r||"",contents:e,lang:a,cacheKey:`new:${R}:${r}:${rl(e)}`},Ae=n?oe.current!==n:oe.current!==void 0||!ke||!De||!xe.current||!we.current||!ai(xe.current,ke)||!ai(we.current,De),Pe=X.current,Re=!!(Pe&&(Z.current!==Me||se.current!==Ie||Me&&(ce.current!==ye.hunkSeparators||Ae)));Re&&(Pe?.cleanUp(),X.current=null,_.innerHTML="");let Oe=X.current;const $e=!Re&&Pe?!rd(Pe.options,ye):!1;if(Oe?Oe.setOptions(ye):(Oe=ue?new id(ye,ue.virtualizer,nv,Ie):new od(ye,Ie),X.current=Oe,j.current=null),Z.current=Me,se.current=Ie,ce.current=Me?ye.hunkSeparators:void 0,oe.current=n,xe.current=ke,we.current=De,n)Oe.render({fileDiff:n,forceRender:$e,lineAnnotations:ie.current,containerWrapper:_});else{if(!ke||!De)return;Oe.render({oldFile:ke,newFile:De,forceRender:$e,lineAnnotations:ie.current,containerWrapper:_})}const Be=sv(_,()=>{ne(),iv(Oe,ue,he)});return()=>{Be(),ne()}},[R,n,r,a,e,ye,s,Ie]),je.useEffect(()=>{const _=X.current;if(_){try{_.setLineAnnotations(te)}catch(ee){console.error("Failed to apply diff line annotations",ee);try{_.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(X.current===_){try{_.rerender()}catch{}he()}})}},[te]),je.useEffect(()=>{const _=X.current;if(!_||h!==null)return;const ee=j.current;if(!Xy(h,ee))try{v.current=!0,_.setSelectedLines(h),j.current=h}catch{}finally{v.current=!1}},[h]),je.useEffect(()=>{if(!c)return;const _=H.current;if(!_)return;let ee=null,ne=()=>{};const ue=()=>{const ke=_.querySelector("diffs-container")?.shadowRoot;if(!ke){ee=requestAnimationFrame(ue);return}const De=Ae=>{if(!(Ae instanceof MouseEvent)||Ae.button!==0||!(Ae.target instanceof Element))return;const Pe=Ae.target.closest("[data-column-number]");if(!(Pe instanceof HTMLElement))return;const Re=Pe.getAttribute("data-column-number"),Oe=Re?parseInt(Re,10):NaN;if(Number.isNaN(Oe))return;const $e=W(Pe);O({start:Oe,end:Oe,side:$e}),Ae.preventDefault(),Ae.stopPropagation()};ke.addEventListener("click",De,!0),ne=()=>{ke.removeEventListener("click",De,!0)}};return ue(),()=>{ee!==null&&cancelAnimationFrame(ee),ne()}},[R,c,r,O,W]),je.useEffect(()=>{const _=H.current;if(!_)return;let ee=null,ne=null;const Me=setTimeout(()=>{const ke=_.querySelector("diffs-container");if(!(ke instanceof HTMLElement))return;const De=ke.shadowRoot;ee=new MutationObserver(()=>{ne&&cancelAnimationFrame(ne),ne=requestAnimationFrame(()=>{he(),ne=null})}),ee.observe(ke,{childList:!0,subtree:!0}),De&&ee.observe(De,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(Me),ne&&cancelAnimationFrame(ne),ee?.disconnect()}},[R,r]),typeof window>"u")return null;const ge=c?t.jsx(qy,{diffRootRef:F,drafts:g,selection:h,editingDraftId:E,commentText:k,onTextChange:w,fileLabel:r?.split("/").pop()??"",onSave:B,onCancel:T,onEdit:_=>{Q({start:_.startLine,end:_.endLine,side:_.side==="original"?"deletions":"additions"}),b(_)},onDelete:P}):null;return d==="fill"?t.jsx("div",{className:de("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:t.jsxs("div",{className:"flex-1 relative min-h-0",children:[t.jsx(Jt,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:t.jsx("div",{ref:F,className:"size-full relative",children:t.jsx("div",{ref:H,className:"size-full"})})}),ge]})}):t.jsxs("div",{className:de("relative","w-full"),children:[t.jsx("div",{ref:F,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:t.jsx("div",{ref:H,className:"w-full"})}),ge]})},ov=()=>{const s=rt.c(13),[e,n]=je.useState(!1);let a,r;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{n(fs())},r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),je.useEffect(a,r);let i;s[2]!==e?(i=async u=>e?await Qm(u):{success:!0,path:u},s[2]=e,s[3]=i):i=s[3];const o=i;let d;s[4]!==e?(d=async u=>e?await Ym():{success:!0},s[4]=e,s[5]=d):d=s[5];const c=d;let x;s[6]!==e?(x=async u=>e?await Xm():{success:!0},s[6]=e,s[7]=x):x=s[7];const m=x;let p;return s[8]!==e||s[9]!==o||s[10]!==c||s[11]!==m?(p={isDesktop:e,requestAccess:o,startAccessing:c,stopAccessing:m},s[8]=e,s[9]=o,s[10]=c,s[11]=m,s[12]=p):p=s[12],p},lv=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),cv=({currentBranch:s,localBranches:e,remoteBranches:n,branchInfo:a,onCheckout:r,onCreate:i,remotes:o=[],disabled:d=!1})=>{const{t:c}=dt(),[x,m]=l.useState(!1),[p,u]=l.useState(""),[S,f]=l.useState(!1),[g,h]=l.useState(!1),[D,k]=l.useState(""),[w,E]=l.useState(!1),N=l.useRef(null),y=l.useCallback(B=>{B.stopPropagation()},[]),b=o.length>1,P=l.useMemo(()=>lv(D),[D]),z=l.useMemo(()=>{const B=p.toLowerCase();return B?e.filter(Q=>Q.toLowerCase().includes(B)):e},[p,e]),M=l.useMemo(()=>{const B=p.toLowerCase();return B?n.filter(Q=>Q.toLowerCase().includes(B)):n},[p,n]),I=B=>{if(B===s){m(!1);return}r(B),m(!1),u("")},v=()=>{f(!0),setTimeout(()=>N.current?.focus(),50)},j=async()=>{if(!(!P||w)){if(b){h(!0);return}E(!0);try{await i(P,o[0]),k(""),f(!1),m(!1)}finally{E(!1)}}},O=async B=>{if(!(!P||w)){E(!0);try{await i(P,B),k(""),f(!1),h(!1),m(!1)}finally{E(!1)}}},T=()=>{h(!1)},U=()=>{k(""),f(!1),h(!1)};return l.useEffect(()=>{x||(u(""),f(!1),h(!1),k(""))},[x]),t.jsxs(us,{open:x,onOpenChange:m,children:[t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(ds,{asChild:!0,children:t.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:d,children:[t.jsx(A,{name:"git-branch",className:"size-4 text-primary"}),t.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:s||c("gitView.branch.detachedHead")}),t.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),t.jsx(Et,{sideOffset:8,children:c("gitView.branch.currentBranchTooltip")})]}),t.jsx(ms,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:t.jsxs(Nr,{className:"h-full min-h-0",children:[t.jsx(kr,{placeholder:c("gitView.branch.searchPlaceholder"),value:p,onValueChange:u,onKeyDown:y}),t.jsxs(Sr,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Cr,{children:c("gitView.branch.empty")}),t.jsx(Us,{children:g?t.jsxs("div",{className:"px-2 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("button",{type:"button",onClick:T,disabled:w,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(A,{name:"arrow-left",className:"size-4"})}),t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[c("gitView.branch.pushToPrefix")," ",t.jsx("span",{className:"text-foreground font-medium",children:P})," ",c("gitView.branch.pushToSuffix")]})]}),t.jsx("div",{className:"flex flex-col gap-1",children:o.map(B=>t.jsxs("button",{type:"button",onClick:()=>O(B),disabled:w,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:[t.jsxs("span",{className:"typography-ui-label text-foreground",children:[w?t.jsx(A,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,B.name]}),t.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:B.pushUrl})]},B.name))})]}):S?t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[t.jsx("input",{ref:N,placeholder:c("gitView.branch.newBranchPlaceholder"),value:D,onChange:B=>k(B.target.value),onClick:B=>B.stopPropagation(),onKeyDown:B=>{y(B),B.key==="Enter"?(B.preventDefault(),j()):B.key==="Escape"&&(B.preventDefault(),U())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),t.jsx("button",{type:"button",onClick:j,disabled:!P||w,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:w?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"add",className:"size-4"})}),t.jsx("button",{type:"button",onClick:U,disabled:w,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(A,{name:"close",className:"size-4"})})]}):t.jsxs(Es,{onSelect:v,children:[t.jsx(A,{name:"add",className:"size-4"}),t.jsx("span",{children:c("gitView.branch.create")})]})}),t.jsx(Cn,{}),t.jsxs(Us,{heading:c("gitView.branch.localBranches"),children:[z.map(B=>t.jsxs(Es,{onSelect:()=>I(B),children:[t.jsxs("span",{className:"flex flex-1 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:B}),(a?.[B]?.ahead||a?.[B]?.behind)&&t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[a[B].ahead||0," ahead ·"," ",a[B].behind||0," behind"]})]}),s===B&&t.jsx("span",{className:"typography-micro text-primary",children:c("gitView.branch.currentBadge")})]},`local-${B}`)),z.length===0&&t.jsx(Es,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noLocalBranches")})})]}),t.jsx(Cn,{}),t.jsxs(Us,{heading:c("gitView.branch.remoteBranches"),children:[M.map(B=>t.jsx(Es,{onSelect:()=>I(B),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:B})},`remote-${B}`)),M.length===0&&t.jsx(Es,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noRemoteBranches")})})]})]})]})})]})},dv=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),mv=({currentBranch:s,onRename:e,showEditButton:n=!0})=>{const{t:a}=dt(),[r,i]=l.useState(!1),[o,d]=l.useState(s||""),[c,x]=l.useState(!1),m=l.useRef(null),p=()=>{!s||!e||(d(s),i(!0),setTimeout(()=>m.current?.focus(),0))},u=async()=>{if(!s||!e||!o.trim())return;const g=dv(o);if(g===s){i(!1);return}x(!0);try{await e(s,g),i(!1),d("")}finally{x(!1)}},S=()=>{i(!1),d("")},f=g=>{g.key==="Enter"?(g.preventDefault(),u()):g.key==="Escape"&&(g.preventDefault(),S())};return r?t.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:t.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:g=>{g.preventDefault(),u()},children:[t.jsx(A,{name:"git-branch",className:"size-4 text-primary"}),t.jsx("input",{ref:m,value:o,onChange:g=>d(g.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:a("gitView.branch.namePlaceholder"),onKeyDown:f,autoFocus:!0}),t.jsx("button",{type:"submit",disabled:c,"aria-label":a(c?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:a(c?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:c?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"check",className:"size-4"})}),t.jsx("button",{type:"button",onClick:S,disabled:c,"aria-label":a("gitView.branch.renameCancel"),title:a("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(A,{name:"close",className:"size-4"})})]})}):t.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[t.jsx(A,{name:"git-branch",className:"size-4 text-primary shrink-0"}),t.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[t.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:s||a("gitView.branch.detachedHead")}),n&&e&&s&&t.jsx(J,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:p,title:a("gitView.branch.renameTitle"),children:t.jsx(A,{name:"edit",className:"size-4"})})]})]})},uv={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},pv={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 cc(s){return s&&pv[s]||"var(--primary)"}const il=s=>{const e=rt.c(8),{icon:n,className:a,colorToken:r}=s,i=uv[n??"branch"]??"user-3";let o;e[0]!==r?(o=cc(r),e[0]=r,e[1]=o):o=e[1];let d;e[2]!==o?(d={color:o},e[2]=o,e[3]=d):d=e[3];let c;return e[4]!==a||e[5]!==i||e[6]!==d?(c=t.jsx(A,{name:i,className:a,style:d}),e[4]=a,e[5]=i,e[6]=d,e[7]=c):c=e[7],c},dc=s=>{const e=rt.c(35),{activeProfile:n,identities:a,onSelect:r,isApplying:i,iconOnly:o}=s,d=o===void 0?!1:o,{t:c}=dt(),x=i||a.length===0,m=n?.color;let p;e[0]!==m?(p=cc(m),e[0]=m,e[1]=p):p=e[1];let u;e[2]!==p?(u={color:p},e[2]=p,e[3]=u):u=e[3];let S;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(S=i?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(il,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=S):S=e[7];let f;e[8]!==n?.name||e[9]!==d||e[10]!==c?(f=!d&&t.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||c("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=d,e[10]=c,e[11]=f):f=e[11];let g;e[12]===Symbol.for("react.memo_cache_sentinel")?(g=t.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=g):g=e[12];let h;e[13]!==x||e[14]!==u||e[15]!==S||e[16]!==f?(h=t.jsx(At,{asChild:!0,children:t.jsx(ds,{asChild:!0,children:t.jsxs(J,{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:u,disabled:x,children:[S,f,g]})})}),e[13]=x,e[14]=u,e[15]=S,e[16]=f,e[17]=h):h=e[17];let D;e[18]!==c?(D=c("gitView.header.identityTooltip"),e[18]=c,e[19]=D):D=e[19];let k;e[20]!==D?(k=t.jsx(Et,{sideOffset:8,children:D}),e[20]=D,e[21]=k):k=e[21];let w;e[22]!==k||e[23]!==h?(w=t.jsxs(Dt,{children:[h,k]}),e[22]=k,e[23]=h,e[24]=w):w=e[24];let E;e[25]!==n?.id||e[26]!==a||e[27]!==r||e[28]!==c?(E=a.length===0?t.jsx("div",{className:"px-2 py-1.5",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:c("gitView.header.noProfiles")})}):a.map(b=>{const P=n?.id===b.id;return t.jsx(js,{onSelect:()=>r(b),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(il,{icon:b.icon,colorToken:b.color,className:"size-4"}),t.jsxs("span",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:b.name}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:b.userEmail})]}),P?t.jsx(A,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},b.id)}),e[25]=n?.id,e[26]=a,e[27]=r,e[28]=c,e[29]=E):E=e[29];let N;e[30]!==E?(N=t.jsx(ms,{align:"end",className:"w-64",children:E}),e[30]=E,e[31]=N):N=e[31];let y;return e[32]!==w||e[33]!==N?(y=t.jsxs(us,{children:[w,N]}),e[32]=w,e[33]=N,e[34]=y):y=e[34],y},gv=s=>{const e=rt.c(21),{comparison:n,trackingBranch:a,tooltipDelayMs:r}=s,i=r===void 0?1e3:r,{t:o}=dt(),d=`${n.remote}/${n.branch}`,c=n.ahead===0&&n.behind===0;let x;e[0]!==o||e[1]!==d||e[2]!==a?(x=a?o("gitView.header.upstreamTooltipTracking",{target:d,tracking:a}):o("gitView.header.upstreamTooltip",{target:d}),e[0]=o,e[1]=d,e[2]=a,e[3]=x):x=e[3];const m=x;let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(A,{name:"git-branch",className:"size-3.5 shrink-0"}),e[4]=p):p=e[4];let u;e[5]!==d?(u=t.jsx("span",{className:"min-w-0 truncate text-foreground/80",children:d}),e[5]=d,e[6]=u):u=e[6];let S;e[7]!==n.ahead||e[8]!==n.behind||e[9]!==c||e[10]!==o?(S=c?t.jsx("span",{className:"tabular-nums text-muted-foreground",children:o("gitView.header.upstreamSynced")}):t.jsxs("span",{className:"inline-flex items-center gap-1 tabular-nums",children:[n.ahead>0?t.jsxs("span",{className:"text-[var(--status-info)]",children:["↑",n.ahead]}):null,n.behind>0?t.jsxs("span",{className:"text-[var(--status-warning)]",children:["↓",n.behind]}):null]}),e[7]=n.ahead,e[8]=n.behind,e[9]=c,e[10]=o,e[11]=S):S=e[11];let f;e[12]!==u||e[13]!==S?(f=t.jsx(At,{asChild:!0,children:t.jsxs("div",{className:"inline-flex h-8 max-w-full items-center gap-1.5 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2 typography-micro text-muted-foreground",children:[p,u,S]})}),e[12]=u,e[13]=S,e[14]=f):f=e[14];let g;e[15]!==m?(g=t.jsx(Et,{sideOffset:8,children:m}),e[15]=m,e[16]=g):g=e[16];let h;return e[17]!==f||e[18]!==g||e[19]!==i?(h=t.jsxs(Dt,{delayDuration:i,children:[f,g]}),e[17]=f,e[18]=g,e[19]=i,e[20]=h):h=e[20],h},Wv=s=>{const e=rt.c(54),{status:n,localBranches:a,remoteBranches:r,branchInfo:i,syncAction:o,remotes:d,onFetch:c,onSync:x,onRemoveRemote:m,removingRemoteName:p,onCheckoutBranch:u,onCreateBranch:S,onRenameBranch:f,activeIdentityProfile:g,availableIdentities:h,onSelectIdentity:D,isApplyingIdentity:k,isWorktreeMode:w,onOpenHistory:E,onOpenGraph:N,onOpenStashes:y,actionTabItems:b,activeActionTab:P,onSelectActionTab:z}=s,{t:M}=dt();if(!n)return null;let I;e[0]!==N||e[1]!==E||e[2]!==y||e[3]!==M?(I=E||N||y?t.jsxs(us,{children:[t.jsxs(Dt,{children:[t.jsx(At,{asChild:!0,children:t.jsx(ds,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":M("gitView.header.repositoryViews"),children:t.jsx(A,{name:"git-repository",className:"size-4"})})})}),t.jsx(Et,{sideOffset:8,children:M("gitView.header.repositoryViews")})]}),t.jsxs(ms,{align:"end",children:[E?t.jsxs(js,{onSelect:E,children:[t.jsx(A,{name:"history",className:"size-4"}),M("gitView.history.title")]}):null,N?t.jsxs(js,{onSelect:N,children:[t.jsx(A,{name:"git-merge",className:"size-4"}),M("gitView.graph.title")]}):null,y?t.jsxs(js,{onSelect:y,children:[t.jsx(A,{name:"archive-stack",className:"size-4"}),M("gitView.stashes.title")]}):null]})]}):null,e[0]=N,e[1]=E,e[2]=y,e[3]=M,e[4]=I):I=e[4];let v;e[5]!==I?(v=t.jsx("div",{className:"flex items-center gap-1 shrink-0",children:I}),e[5]=I,e[6]=v):v=e[6];const j=v,O=!n;let T;e[7]!==n.tracking?(T=n.tracking?.split("/")[0],e[7]=n.tracking,e[8]=T):T=e[8];const U=(n.files?.length??0)>0;let B;e[9]!==c||e[10]!==m||e[11]!==x||e[12]!==d||e[13]!==p||e[14]!==n.ahead||e[15]!==n.behind||e[16]!==o||e[17]!==O||e[18]!==T||e[19]!==U?(B=t.jsx(Iy,{syncAction:o,remotes:d,onFetch:c,onSync:x,onRemoveRemote:m,removingRemoteName:p,disabled:O,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:T,hasUncommittedChanges:U}),e[9]=c,e[10]=m,e[11]=x,e[12]=d,e[13]=p,e[14]=n.ahead,e[15]=n.behind,e[16]=o,e[17]=O,e[18]=T,e[19]=U,e[20]=B):B=e[20];const Q=B;let W;e[21]!==n.tracking||e[22]!==n.upstreamComparison?(W=n.upstreamComparison?t.jsx(gv,{comparison:n.upstreamComparison,trackingBranch:n.tracking,tooltipDelayMs:1e3}):null,e[21]=n.tracking,e[22]=n.upstreamComparison,e[23]=W):W=e[23];const R=W;let Y;e[24]!==g||e[25]!==h||e[26]!==k||e[27]!==D?(Y=t.jsx(dc,{activeProfile:g,identities:h,onSelect:D,isApplying:k,iconOnly:!0}),e[24]=g,e[25]=h,e[26]=k,e[27]=D,e[28]=Y):Y=e[28];const F=Y;let H;e[29]!==i||e[30]!==w||e[31]!==a||e[32]!==u||e[33]!==S||e[34]!==f||e[35]!==r||e[36]!==d||e[37]!==n.current?(H=t.jsx("div",{className:"min-w-0 flex-1",children:w?t.jsx(mv,{currentBranch:n.current,onRename:f}):t.jsx(cv,{currentBranch:n.current,localBranches:a,remoteBranches:r,branchInfo:i,onCheckout:u,onCreate:S,remotes:d})}),e[29]=i,e[30]=w,e[31]=a,e[32]=u,e[33]=S,e[34]=f,e[35]=r,e[36]=d,e[37]=n.current,e[38]=H):H=e[38];let X;e[39]!==F||e[40]!==j?(X=t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[j,F]}),e[39]=F,e[40]=j,e[41]=X):X=e[41];let re;e[42]!==X||e[43]!==H?(re=t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[H,X]}),e[42]=X,e[43]=H,e[44]=re):re=e[44];let Z;e[45]!==b||e[46]!==P||e[47]!==z||e[48]!==Q||e[49]!==R?(Z=b&&P&&z?t.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(xn,{items:b,activeId:P,onSelect:z,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),R?t.jsx("div",{className:"min-w-0 shrink",children:R}):null,t.jsx("div",{className:"shrink-0",children:Q})]}):null,e[45]=b,e[46]=P,e[47]=z,e[48]=Q,e[49]=R,e[50]=Z):Z=e[50];let se;return e[51]!==re||e[52]!==Z?(se=t.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[re,Z]}),e[51]=re,e[52]=Z,e[53]=se):se=e[53],se},hv=s=>s==="/",Oa=s=>s.replace(/\\/g,"/"),Qr=s=>{if(!s||hv(s))return s;let e=s;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},En=s=>s.endsWith("/"),fv=s=>{const e=s.trim();return!e||En(e)?e:`${e}/`},Yr=s=>s.lastIndexOf("/"),mc=s=>{if(En(s))return s;const e=Yr(s);return e<0?s:s.slice(0,e+1)},xv=s=>{const e=Yr(s);return s.slice(e+1)},uc=s=>{const e=Qr(s.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=Yr(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},bv=s=>En(s)&&uc(s)!==null,yv=(s,e)=>`${mc(s)}${e}/`,cn=s=>{if(!s)return null;const e=Qr(Oa(s.trim()));return e?e.toLowerCase():null},ol=(s,e)=>{const n=s.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},vv=s=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey,vr=s=>{if(!s)return;s.focus({preventScroll:!0});const e=s.value.length;s.setSelectionRange(e,e),s.scrollLeft=s.scrollWidth},jv=async()=>{try{const s=await jt("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(s.ok){const e=await s.json();if(typeof e.home=="string"&&e.home.trim().length>0)return Oa(e.home.trim())}}catch{}return Ns.getFilesystemHome().catch(()=>null)},qv=({open:s,onOpenChange:e})=>{const{t:n}=dt(),a=vs($=>$.homeDirectory),r=as($=>$.projects),i=as($=>$.addProject),o=ks($=>$.profiles),d=ks($=>$.globalIdentity),c=ks($=>$.defaultGitIdentityId),x=ks($=>$.loadProfiles),m=ks($=>$.loadGlobalIdentity),p=ks($=>$.loadDefaultGitIdentityId),{isDesktop:u,requestAccess:S,startAccessing:f}=ov(),{isMobile:g}=Cs(),h=l.useRef(null),D=l.useRef(null),k=l.useRef(new Map),[w,E]=l.useState(""),[N,y]=l.useState("~/"),[b,P]=l.useState([]),[z,M]=l.useState(!1),[I,v]=l.useState(!1),[j,O]=l.useState(0),[T,U]=l.useState(!1),[B,Q]=l.useState(!1),[W,R]=l.useState(0),[Y,F]=l.useState(!1),[H,X]=l.useState(""),[re,Z]=l.useState(null),[se,ce]=l.useState(!1),oe=w||a,xe=l.useMemo(()=>new Set(r.map($=>cn($.path)).filter($=>!!$)),[r]);l.useEffect(()=>{if(!s)return;y("~/"),P([]),O(0),U(!1),Q(!1),F(!1),X(""),Z(null),ce(!1),requestAnimationFrame(()=>vr(h.current));let $=!1;return(async()=>{const L=await jv();$||(E(L||a||""),requestAnimationFrame(()=>vr(h.current)))})(),()=>{$=!0}},[a,s]),l.useEffect(()=>{s&&(x(),m(),p())},[p,x,m,s]);const we=l.useMemo(()=>{const $=new Map;d&&$.set(d.id,d);for(const fe of o)$.set(fe.id,fe);return Array.from($.values())},[o,d]);l.useEffect(()=>{if(!s||!Y||re!==null)return;const $=typeof c=="string"?c.trim():"";if($&&we.some(L=>L.id===$)){Z($);return}const fe=we.find(L=>L.authType==="ssh"||L.sshKey);fe&&Z(fe.id)},[we,c,Y,s,re]);const he=l.useMemo(()=>we.find($=>$.id===re)??null,[we,re]),Ie=l.useMemo(()=>mc(N),[N]),ve=l.useMemo(()=>En(N)?"":xv(N),[N]),be=l.useMemo(()=>oe?ol(Ie,oe):"",[Ie,oe]);l.useEffect(()=>{if(!s||!be){P([]);return}let $=!1;return M(!0),v(!1),Ns.listLocalDirectory(be).then(fe=>{if($)return;v(!1);const L=fe.filter(Fe=>Fe.isDirectory).map(Fe=>({name:Fe.name,path:Oa(Fe.path)})).sort((Fe,Je)=>Fe.name.localeCompare(Je.name));P(L)}).catch(()=>{$||(P([]),v(!0))}).finally(()=>{$||M(!1)}),()=>{$=!0}},[be,s]);const ye=l.useMemo(()=>{const $=ve.toLowerCase(),fe=se||ve.startsWith(".");return b.filter(L=>L.name.toLowerCase().startsWith($)&&(fe||!L.name.startsWith(".")))},[ve,b,se]),te=l.useMemo(()=>{const $=[];bv(N)&&$.push({type:"up",value:"browse:up",name:"..",path:uc(N)});for(const fe of ye){const L=cn(fe.path);$.push({type:"directory",value:`browse:${fe.path}`,name:fe.name,path:fe.path,disabled:!!(L&&xe.has(L))})}return $},[xe,ye,N]);l.useEffect(()=>{O(0)},[N,te.length]);const ie=l.useMemo(()=>oe?Qr(ol(N,oe)):"",[oe,N]),ge=cn(ie),_=!!(ge&&xe.has(ge)),ee=l.useMemo(()=>ve?ye.find($=>$.name===ve)??null:null,[ve,ye]),ne=!!(ie&&!_&&(En(N)&&I||!En(N)&&ve.trim().length>0&&ee===null)),ue=!T&&!B&&!_&&!!ie,Me=ue&&H.trim().length>0,ke=te[j]??null,De=!!(ke&&(ke.type==="up"||ke.type==="directory"&&!ke.disabled)),Ae=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Pe=n(_?"directoryExplorerDialog.actions.alreadyAdded":Y?T?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":T?"directoryExplorerDialog.actions.adding":ne?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const $=D.current;if(!$)return;const fe=()=>R(Math.ceil($.getBoundingClientRect().width));if(fe(),typeof ResizeObserver>"u")return;const L=new ResizeObserver(fe);return L.observe($),()=>L.disconnect()},[Pe]),l.useLayoutEffect(()=>{const $=h.current;$&&($.scrollLeft=$.scrollWidth)},[W,N]),l.useLayoutEffect(()=>{s&&vr(h.current)},[s]),l.useLayoutEffect(()=>{const $=te[j];$&&k.current.get($.value)?.scrollIntoView({block:"nearest"})},[j,te]);const Re=l.useCallback(()=>{e(!1)},[e]),Oe=l.useCallback(($,fe)=>{$.stopPropagation();const L=cn(fe);if(L&&xe.has(L))return;i(fe)||V.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")})},[i,xe,n]),$e=l.useCallback(async $=>{if(!$||T)return;const fe=cn($);if(fe&&xe.has(fe))return;let L=$;U(!0);try{const Fe=!Y&&ne&&cn($)===cn(ie);if(Y){const Xe=H.trim();if(!Xe){V.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}L=(await Ns.cloneRepository({remoteUrl:Xe,destinationPath:$,gitIdentityId:he?.id??null})).path}else Fe&&await Ns.createDirectory($);if(!i(L)){V.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}Re()}catch(Fe){V.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Fe instanceof Error?Fe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{U(!1)}},[i,xe,H,Re,Y,T,he?.id,ne,ie,n]),Be=l.useCallback($=>{y(fv($))},[]),Le=l.useCallback($=>{y(yv(N,$.name))},[N]),Ue=l.useCallback($=>{if($){if($.type==="up"){$.path&&Be($.path);return}$.disabled||Le($)}},[Be,Le]),le=l.useCallback(async()=>{if(!(!u||B)){Q(!0);try{const $=await S(ie);if(!$.success||!$.path){$.error&&$.error!=="Directory selection cancelled"&&V.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:$.error});return}const fe=await f($.path);if(!fe.success){V.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:fe.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await $e($.path)}catch($){V.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:$ instanceof Error?$.message:n("directoryExplorerDialog.toast.unknownError")})}finally{Q(!1)}}},[$e,u,B,S,f,n,ie]),q=l.useCallback($=>{if($.key==="ArrowDown"){$.preventDefault(),O(fe=>Math.min(te.length-1,fe+1));return}if($.key==="ArrowUp"){$.preventDefault(),O(fe=>Math.max(0,fe-1));return}if($.key==="Enter"){if($.preventDefault(),vv($)){$e(ie);return}De&&Ue(ke);return}$.key==="Backspace"&&N===""&&($.preventDefault(),Re())},[Ue,$e,Re,De,ke,N,te.length,ie]),me=t.jsxs("button",{type:"button",onClick:()=>ce($=>!$),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:[se?t.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}):t.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),Ne=t.jsxs("div",{className:"px-2.5 py-1.5",children:[Y?t.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[t.jsx(it,{value:H,onChange:$=>X($.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"}),t.jsx(dc,{activeProfile:he,identities:we,onSelect:$=>Z($.id),isApplying:T,iconOnly:!0})]}):null,t.jsxs("div",{className:"relative",children:[t.jsx(A,{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"}),t.jsx(it,{ref:h,value:N,onChange:$=>y(Oa($.target.value)),onKeyDown:q,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!g&&W>0?{paddingRight:`${W+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),g?null:t.jsx(J,{ref:D,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:Y?!Me:!ue,onMouseDown:$=>$.preventDefault(),onClick:()=>{$e(ie)},title:Pe,children:Pe})]})]}),Ee=t.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:t.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[t.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")}),z?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):te.length===0?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):t.jsx("div",{className:"space-y-0.5",children:te.map(($,fe)=>{const L=fe===j;return t.jsxs("button",{ref:Fe=>{Fe?k.current.set($.value,Fe):k.current.delete($.value)},type:"button",disabled:$.type==="directory"&&$.disabled,onMouseEnter:()=>O(fe),onMouseDown:Fe=>Fe.preventDefault(),onClick:()=>Ue($),className:de("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",L&&"bg-interactive-selection text-interactive-selection-foreground",!L&&"hover:bg-interactive-hover/50",$.type==="directory"&&$.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[$.type==="up"?t.jsx(A,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):t.jsx(A,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),t.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:t.jsx("span",{className:"truncate typography-ui-label text-foreground",children:$.name})}),$.type==="directory"&&$.disabled?t.jsx("span",{className:"rounded-full border border-border/60 px-2 py-0.5 typography-meta text-muted-foreground",children:n("directoryExplorerDialog.browse.addedBadge")}):$.type==="directory"?t.jsx("button",{type:"button",onMouseDown:Fe=>Fe.stopPropagation(),onClick:Fe=>Oe(Fe,$.path),className:"flex-shrink-0 rounded-full p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",title:n("directoryExplorerDialog.browse.quickAdd"),children:t.jsx(A,{name:"add",className:"h-3.5 w-3.5"})}):null]},$.value)})})]})}),Ce=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[Ne,Ee]}),He=t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(A,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),t.jsx(A,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(A,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx("span",{children:Ae}),t.jsx(A,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),G=()=>t.jsxs(t.Fragment,{children:[g?null:He,t.jsxs("div",{className:de("flex w-full flex-row justify-end gap-2 sm:w-auto",g&&"justify-stretch"),children:[u?t.jsx(J,{variant:"ghost",size:"xs",onClick:le,disabled:T||B||Y,children:n(B?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,t.jsx(J,{variant:"ghost",size:"xs",onClick:()=>F($=>!$),disabled:T||B,className:de(g&&"flex-1"),children:n(Y?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),g?t.jsx(J,{size:"xs",onClick:()=>{$e(ie)},disabled:Y?!Me:!ue,className:"flex-1",children:Pe}):null]})]});return g?t.jsx(Gn,{open:s,onClose:Re,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:t.jsx("div",{className:"flex flex-col gap-2",children:G()}),children:t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[t.jsx("div",{className:"flex justify-end",children:me}),Ce]})}):t.jsx(Ut,{open:s,onOpenChange:e,children:t.jsxs(Bt,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(_t,{className:"px-5 pb-2 pt-5",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{children:[t.jsx(Vt,{children:n("directoryExplorerDialog.title")}),t.jsx(qt,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),me]})}),t.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:Ce}),t.jsx(Yt,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:G()})]})})};function ll(s){const{localBranches:e,remoteBranches:n,query:a}=s,r=a.trim();if(!r)return{matching:[],otherLocal:e,otherRemote:n};const i=yi(e,r,m=>m),o=yi(n,r,m=>m),d=[],c=i.other,x=o.other;for(const m of i.matching)d.push({label:m,value:m,source:"local"});for(const m of o.matching)d.push({label:m,value:`remotes/${m}`,source:"remote"});return d.sort((m,p)=>{const u=m.label.localeCompare(p.label,void 0,{sensitivity:"accent"});return u!==0?u:m.source!==p.source?m.source.localeCompare(p.source):m.value.localeCompare(p.value)}),{matching:d,otherLocal:c,otherRemote:x}}function wv({open:s,onOpenChange:e,onSelect:n}){const{t:a}=dt(),r=Ke(te=>te.isMobile),{github:i}=Hr(),o=Vs(te=>te.status),d=Vs(te=>te.hasChecked),c=Ke(te=>te.setSettingsDialogOpen),x=Ke(te=>te.setSettingsPage),m=as(te=>te.getActiveProject()),p=m?.path??null,u=je.useMemo(()=>p&&m?{id:m.id,path:p}:null,[m,p]),[S,f]=je.useState("issues"),[g,h]=je.useState(""),[D,k]=je.useState([]),[w,E]=je.useState([]),[N,y]=je.useState(!1),[b,P]=je.useState(!1),[z,M]=je.useState(null),[I,v]=je.useState(null),[j,O]=je.useState(null),[T,U]=je.useState(!1),[B,Q]=je.useState(new Map),[W,R]=je.useState(1),[Y,F]=je.useState(!1),H=Cm(g,350),X=je.useCallback(async te=>{if(!(!p||!i)&&!(d&&o?.connected===!1)){y(!0),M(null),R(1),F(!1);try{if(S==="issues"&&i.issuesList){const ie=await i.issuesList(p,{page:1,query:te});ie.connected===!1?(M(a("session.githubIntegration.error.notConnected")),k([])):(k(ie.issues??[]),R(ie.page??1),F(!!ie.hasMore))}else if(S==="prs"&&i.prsList){const ie=await i.prsList(p,{page:1,query:te});ie.connected===!1?(M(a("session.githubIntegration.error.notConnected")),E([])):(E(ie.prs??[]),R(ie.page??1),F(!!ie.hasMore))}}catch(ie){M(ie instanceof Error?ie.message:a("session.githubIntegration.error.loadDataFailed"))}finally{y(!1)}}},[p,i,d,o,S,a]);je.useEffect(()=>{if(!s||!p||d&&o?.connected===!1||!i)return;if(!H.trim()){X();return}const te=new AbortController;y(!0),M(null),R(1),F(!1);const ie=S==="issues"&&i.issuesList?i.issuesList(p,{page:1,query:H.trim()}):S==="prs"&&i.prsList?i.prsList(p,{page:1,query:H.trim()}):null;if(!ie){y(!1);return}return ie.then(ge=>{te.signal.aborted||("issues"in ge?ge.connected===!1?(M(a("session.githubIntegration.error.notConnected")),k([])):(k(ge.issues??[]),R(ge.page??1),F(!!ge.hasMore)):"prs"in ge&&(ge.connected===!1?(M(a("session.githubIntegration.error.notConnected")),E([])):(E(ge.prs??[]),R(ge.page??1),F(!!ge.hasMore))))}).catch(ge=>{te.signal.aborted||M(ge instanceof Error?ge.message:a("session.githubIntegration.error.loadDataFailed"))}).finally(()=>{te.signal.aborted||y(!1)}),()=>te.abort()},[s,p,i,d,o,S,H,X,a]);const re=je.useCallback(async()=>{if(!(!p||!i)&&!(N||b)&&Y){P(!0);try{const te=W+1;if(S==="issues"&&i.issuesList){const ie=H.trim()?await i.issuesList(p,{page:te,query:H.trim()}):await i.issuesList(p,{page:te});ie.connected!==!1&&(k(ge=>[...ge,...ie.issues??[]]),R(ie.page??te),F(!!ie.hasMore))}else if(S==="prs"&&i.prsList){const ie=H.trim()?await i.prsList(p,{page:te,query:H.trim()}):await i.prsList(p,{page:te});ie.connected!==!1&&(E(ge=>[...ge,...ie.prs??[]]),R(ie.page??te),F(!!ie.hasMore))}}catch{}finally{P(!1)}}},[p,i,S,W,Y,N,b,H]);je.useEffect(()=>{if(!s){f("issues"),h(""),k([]),E([]),v(null),O(null),U(!1),M(null),Q(new Map),R(1),F(!1);return}X()},[s,X]);const Z=je.useCallback(async te=>{if(!(!u||!te)&&!B.has(te))try{const ge=(await Sl(u,{mode:"new",branchName:te,worktreeName:te})).errors.find(_=>_.code==="branch_in_use");Q(_=>new Map(_).set(te,{isValid:!ge,error:ge?a(ge.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{Q(ie=>new Map(ie).set(te,{isValid:!1,error:a("session.githubIntegration.validation.failed")}))}},[u,B,a]);je.useEffect(()=>{!s||S!=="prs"||w.forEach(te=>{te.head&&Z(te.head)})},[s,S,w,Z]);const se=d&&o?.connected===!0,ce=()=>{x("github"),c(!0)},oe=te=>{v(te),O(null)},xe=te=>{O(te),v(null)},we=()=>{I?n({type:"issue",item:I}):j&&n({type:"pr",item:j,includeDiff:T}),e(!1)},he=()=>{v(null),O(null),U(!1)},Ie=I||j&&B.get(j.head??"")?.isValid!==!1,ve=te=>te.head?B.get(te.head)?.isValid===!1:!0,be=t.jsx(t.Fragment,{children:se?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative mt-2",children:[t.jsx(A,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),t.jsx(it,{value:g,onChange:te=>h(te.target.value),placeholder:a(S==="issues"?"session.githubIntegration.search.issuesPlaceholder":"session.githubIntegration.search.prsPlaceholder"),className:"h-8 pl-9"})]}),t.jsx("div",{className:"mt-2 h-[300px] overflow-hidden",children:t.jsxs("div",{className:"h-full overflow-y-auto",children:[N&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx(A,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),z&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[t.jsx(A,{name:"error-warning",className:"h-4 w-4"}),t.jsx("span",{className:"typography-small",children:z})]})}),!N&&!z&&S==="issues"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[D.length>0?D.map(te=>t.jsx("button",{onClick:()=>oe(te),className:de("w-full text-left px-2 py-1.5 rounded transition-colors",I?.number===te.number?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",te.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-2",children:te.title}),te.sourceRepo?.source==="upstream"?t.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block",children:[te.sourceRepo.owner,"/",te.sourceRepo.repo]}):null]})]})},`${te.sourceRepo?.owner??""}-${te.sourceRepo?.repo??""}-${te.number}`)):t.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:a("session.githubIntegration.empty.noIssuesFound")}),Y&&!b&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(J,{variant:"ghost",size:"sm",onClick:()=>{re()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),b&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!N&&!z&&S==="prs"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[w.length>0?w.map(te=>{const ie=ve(te),ge=te.head?B.get(te.head):void 0;return t.jsx("button",{onClick:()=>!ie&&xe(te),disabled:ie,className:de("w-full text-left px-2 py-1.5 rounded transition-colors",j?.number===te.number?"bg-interactive-selection text-interactive-selection-foreground":ie?"opacity-50 cursor-not-allowed":"hover:bg-interactive-hover"),children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",te.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-1",children:te.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[te.head," → ",te.base]}),te.sourceRepo?.source==="upstream"?t.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[te.sourceRepo.owner,"/",te.sourceRepo.repo]}):null,ie&&ge?.error&&t.jsx("span",{className:"typography-micro text-destructive",children:ge.error})]})]})]})},`${te.sourceRepo?.owner??""}-${te.sourceRepo?.repo??""}-${te.number}`)}):t.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:a("session.githubIntegration.empty.noPullRequestsFound")}),Y&&!b&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(J,{variant:"ghost",size:"sm",onClick:()=>{re()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),b&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]})]})})]}):t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 gap-4",children:[t.jsx(A,{name:"github",className:"h-12 w-12 text-muted-foreground"}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:a("session.githubIntegration.connect.title")}),t.jsx("p",{className:"typography-small text-muted-foreground mt-1",children:a("session.githubIntegration.connect.description")})]}),t.jsx(J,{onClick:ce,size:"sm",children:a("session.githubIntegration.connect.action")})]})}),ye=t.jsxs("div",{className:de("w-full",r?"flex flex-col gap-2":"flex flex-row items-center"),children:[t.jsxs("div",{className:de("flex items-center gap-4",r?"w-full justify-center order-1":"flex-1"),children:[!r&&(I||j)&&t.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[t.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),t.jsx("span",{className:"typography-small truncate max-w-[150px]",children:I?a("session.githubIntegration.selected.issueNumber",{number:I.number}):a("session.githubIntegration.selected.prNumber",{number:j?.number??""})}),t.jsx("button",{onClick:he,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),S==="prs"&&j&&t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[t.jsx(Pt,{checked:T,onChange:te=>U(te),ariaLabel:a("session.githubIntegration.includeDiffAria")}),t.jsx("span",{className:"typography-small text-foreground",children:a("session.githubIntegration.includeDiff")})]})]}),t.jsxs("div",{className:de("flex gap-2",r?"w-full order-2":"justify-end"),children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>e(!1),className:de(r&&"flex-1"),children:a("session.githubIntegration.actions.cancel")}),t.jsx(J,{size:"sm",onClick:we,disabled:!Ie,className:de(r&&"flex-1"),children:a("session.githubIntegration.actions.select")})]})]});return t.jsx(t.Fragment,{children:r?t.jsx(Gn,{open:s,title:a("session.githubIntegration.title"),onClose:()=>e(!1),footer:se?ye:void 0,renderHeader:te=>t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2 border-b border-border/40",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:a("session.githubIntegration.title")}),te]}),t.jsx("div",{className:"w-full",children:t.jsx(xn,{items:[{id:"issues",label:a("session.githubIntegration.tabs.issues"),icon:t.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:a("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:S,onSelect:ie=>{f(ie),h("")},variant:"active-pill",layoutMode:"fit"})}),(I||j)&&t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[t.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),t.jsx("span",{className:"typography-small truncate flex-1",children:I?a("session.githubIntegration.selected.issueNumber",{number:I.number}):a("session.githubIntegration.selected.prNumber",{number:j?.number??""})}),t.jsx("button",{onClick:he,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:be}):t.jsx(Ut,{open:s,onOpenChange:e,children:t.jsxs(Bt,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsx(_t,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(Vt,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(A,{name:"github",className:"h-5 w-5"}),a("session.githubIntegration.title")]}),t.jsx("div",{className:"w-[220px]",children:t.jsx(xn,{items:[{id:"issues",label:a("session.githubIntegration.tabs.issues"),icon:t.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:a("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:S,onSelect:te=>{f(te),h("")},variant:"active-pill",layoutMode:"fit"})})]})}),be,t.jsx(Yt,{className:"mt-1",children:ye})]})})})}const qn=s=>s.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),hs=s=>s.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),cl="oc:lastWorktreeSourceBranch",Nv=s=>String(s).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",dl=(s,e,n)=>{const a=qn(s.head||"");if(!a)throw new Error("PR head branch is missing");if(e.includes(a))return{existingBranch:a,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:a};const r=n.find(x=>{const m=x.indexOf("/");return m<=0||m>=x.length-1?!1:x.slice(m+1)===a});if(r){const x=r.indexOf("/"),m=r.slice(0,x);return{existingBranch:`remotes/${r}`,setUpstream:!0,upstreamRemote:m,upstreamBranch:a,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${m}/${a}`}}const i=String(s.headLabel||"").split(":")[0]?.trim(),o=s.headRepo?.owner||i||"pr-head",d=`pr-${Nv(o)}`,c=s.headRepo?.sshUrl||s.headRepo?.cloneUrl||"";if(!c)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${d}/${a}`,setUpstream:!0,upstreamRemote:d,upstreamBranch:a,ensureRemoteName:d,ensureRemoteUrl:c,sourceLabel:`${d}/${a}`}},kv=s=>{const e={repo:s.repo??null,issue:s.issue,comments:s.comments};return`GitHub issue context (JSON)
166
- ${JSON.stringify(e,null,2)}`},Sv=s=>`GitHub pull request context (JSON)
167
- ${JSON.stringify(s,null,2)}`;function Gv({open:s,onOpenChange:e,onWorktreeCreated:n}){const{t:a}=dt(),{github:r,git:i}=Hr(),o=Ke(G=>G.isMobile),d=Vs(G=>G.status),c=Vs(G=>G.hasChecked),x=as(G=>G.getActiveProject()),m=x?.path??null,p=je.useMemo(()=>m&&x?{id:x.id,path:m}:null,[x,m]),[u,S]=je.useState("new-branch"),[f,g]=je.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[h,D]=je.useState({selectedBranch:"",worktreeName:""}),k=Pm(m),w=Im(m),E=Dm(G=>G.fetchBranches),N=je.useMemo(()=>k?.all?k.all.filter(G=>!G.startsWith("remotes/")).sort():[],[k]),y=je.useMemo(()=>k?.all?k.all.filter(G=>G.startsWith("remotes/")).map(G=>G.replace(/^remotes\//,"")).sort():[],[k]),b=Ps(G=>G.availableWorktreesByProject),P=je.useMemo(()=>{if(!m)return new Set;const G=b.get(m)??[];return new Set(G.map($=>$.name))},[b,m]),z=je.useCallback((G=10)=>{for(let $=0;$<G;$++){const fe=Qa();if(!P.has(fe))return fe}return`${Qa()}-${Date.now().toString(36).slice(-4)}`},[P]),[M,I]=je.useState(!1),[v,j]=je.useState(!1),[O,T]=je.useState(!1),[U,B]=je.useState(!1),[Q,W]=je.useState(!1),[R,Y]=je.useState(""),[F,H]=je.useState(""),X=je.useRef(null),re=je.useRef(null),Z=je.useRef(null),se=je.useRef(null),ce=je.useCallback(G=>{G.stopPropagation()},[]),oe=je.useCallback(G=>{let $=G;for(;$&&$!==document.body;){const{overflowY:fe}=window.getComputedStyle($);if((fe==="auto"||fe==="scroll")&&$.scrollHeight>$.clientHeight)return $;$=$.parentElement}return null},[]),xe=je.useCallback(G=>{G&&(G.scrollTop=0)},[]),we=je.useCallback(G=>{const $=G.current?.querySelector('[data-slot="command-list"]')??null;xe($)},[xe]),he=je.useCallback(G=>{const $=oe(G.current);xe($)},[oe,xe]),Ie=je.useMemo(()=>ll({localBranches:N,remoteBranches:y,query:R}),[N,y,R]),ve=je.useMemo(()=>ll({localBranches:N,remoteBranches:y,query:F}),[N,y,F]),be=R.trim().length>0,ye=F.trim().length>0,te=Ie.matching.length>0,ie=ve.matching.length>0,ge=!!(m&&i),_=je.useCallback(()=>{!m||!i||E(m,i)},[m,i,E]);je.useEffect(()=>{!s||!m||!i||k?.all||E(m,i)},[s,m,i,k?.all,E]),je.useEffect(()=>{!v&&!U&&Y("")},[v,U]),je.useEffect(()=>{!O&&!Q&&H("")},[O,Q]),je.useEffect(()=>{v&&we(X),U&&he(Z)},[v,U,R,we,he]),je.useEffect(()=>{O&&we(re),Q&&he(se)},[O,Q,F,we,he]);const[ee,ne]=je.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[ue,Me]=je.useState(!1),[ke,De]=je.useState(null),Ae=je.useCallback(()=>{const G=ut.getState(),$=G.getVisibleAgents();if(G.settingsDefaultAgent){const fe=$.find(L=>L.name===G.settingsDefaultAgent);if(fe)return fe.name}return $.find(fe=>fe.name==="build")?.name||$[0]?.name},[]),Pe=je.useCallback(()=>{const G=ut.getState(),$=G.settingsDefaultModel;if(!$)return null;const fe=pn($);if(!fe)return null;const{providerId:L,modelId:Fe}=fe;return G.getModelMetadata(L,Fe)?{providerID:L,modelID:Fe}:null},[]),Re=je.useCallback((G,$)=>{const fe=ut.getState(),L=fe.settingsDefaultVariant,Fe=fe.currentProviderId===G&&fe.currentModelId===$?fe.currentVariant:void 0,et=fe.providers.find(at=>at.id===G)?.models.find(at=>at.id===$)?.variants;if(!et)return L||Fe||void 0;if(L&&Object.prototype.hasOwnProperty.call(et,L))return L;if(Fe&&Object.prototype.hasOwnProperty.call(et,Fe))return Fe},[]),Oe=je.useCallback(async G=>{if(!m||!r)return;const $=ut.getState(),fe=Am.getState().lastUsedProvider,L=Pe(),Fe=L?.providerID||$.currentProviderId||fe?.providerID,Je=L?.modelID||$.currentModelId||fe?.modelID,Xe=Ae()||$.currentAgentName||void 0;if(!Fe||!Je){V.error(a("session.newWorktree.error.noModelSelected"));return}const et=Re(Fe,Je);if(G.issue){if(!r.issueGet||!r.issueComments)return;const at=await r.issueGet(m,G.issue.number);if(at.connected===!1||!at.repo||!at.issue)throw new Error("Failed to load issue context");const lt=await r.issueComments(m,G.issue.number);if(lt.connected===!1)throw new Error("Failed to load issue comments");const Ze=await ra("github.issue.review.visible",{issue_number:String(G.issue.number)}),We=await ra("github.issue.review.instructions"),pt=kv({repo:at.repo,issue:at.issue,comments:lt.comments??[]});await Ps.getState().sendMessage(Ze,Fe,Je,Xe,void 0,void 0,[{text:We,synthetic:!0},{text:pt,synthetic:!0}],et,void 0,{sessionId:G.sessionId}),V.success(a("session.newWorktree.toast.sessionFromIssue"));return}if(G.pr){if(!r.prContext)return;const at=await r.prContext(m,G.pr.number,{includeDiff:G.includeDiff,includeCheckDetails:!1});if(at.connected===!1||!at.repo||!at.pr)throw new Error("Failed to load PR context");const lt=await ra("github.pr.review.visible",{pr_number:String(G.pr.number)}),Ze=await ra("github.pr.review.instructions"),We=Sv(at);await Ps.getState().sendMessage(lt,Fe,Je,Xe,void 0,void 0,[{text:Ze,synthetic:!0},{text:We,synthetic:!0}],et,void 0,{sessionId:G.sessionId}),V.success(a("session.newWorktree.toast.sessionFromPr"))}},[r,m,Ae,Pe,Re,a]),$e=u==="new-branch"?f:h;je.useEffect(()=>{if(!k?.all||!m||f.sourceBranch)return;(async()=>{try{const $=await Em(m).catch(()=>null),fe=localStorage.getItem(cl),L=fe&&k.all?.includes(fe)?fe:$&&k.all?.includes($)?$:k.all?.includes("main")?"main":k.all?.includes("master")?"master":k.all?.[0]||"";L&&g(Fe=>({...Fe,sourceBranch:L}))}catch{}})()},[k,m,f.sourceBranch]),je.useEffect(()=>{if(!s)return;S("new-branch"),D({selectedBranch:"",worktreeName:""}),j(!1),T(!1),B(!1),W(!1),Y(""),H(""),ne({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const G=z();g({branchName:G,worktreeName:G,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[s,z]),je.useEffect(()=>{if(u!=="new-branch"||!f.isSyncingWorktreeName)return;const G=qn(f.branchName),$=hs(G);g(fe=>({...fe,worktreeName:$}))},[u,f.branchName,f.isSyncingWorktreeName]);const Be=je.useCallback(async()=>{if(!p||!ee.touched||ue)return;ke&&ke.abort();const G=new AbortController;De(G),ne($=>({...$,isValidating:!0}));try{const $=u==="new-branch"?f.branchName:h.selectedBranch,fe=$e.worktreeName,L=qn($),Fe=hs(fe);let Je=null,Xe=null;if(L||(Je=a("session.newWorktree.error.branchNameRequired")),Fe||(Xe=a("session.newWorktree.error.worktreeDirectoryRequired")),L&&Fe){const et=u==="new-branch"?f.linkedPr:null,at=et?dl(et,N,y):null,lt=await Sl(p,{mode:u==="existing-branch"||at?"existing":"new",branchName:L,worktreeName:Fe,existingBranch:at?.existingBranch??(u==="existing-branch"?L:void 0),...at?.ensureRemoteName?{ensureRemoteName:at.ensureRemoteName}:{},...at?.ensureRemoteUrl?{ensureRemoteUrl:at.ensureRemoteUrl}:{}});if(G.signal.aborted)return;lt.ok||lt.errors.forEach(Ze=>{if(Ze.code==="worktree_exists"){Xe=Xe??Ze.message;return}Ze.code.startsWith("branch_")&&(Je=Je??Ze.message)})}G.signal.aborted||ne(et=>({...et,isValidating:!1,branchError:Je,worktreeError:Xe}))}catch{G.signal.aborted||ne($=>({...$,isValidating:!1}))}},[p,u,f.branchName,f.linkedPr,h.selectedBranch,$e.worktreeName,N,y,ee.touched,ke,ue,a]),Le=u==="new-branch"?f.branchName:h.selectedBranch;je.useEffect(()=>{if(!s||!p||!ee.touched||ue)return;const G=setTimeout(()=>{Be()},300);return()=>clearTimeout(G)},[$e.worktreeName,Le,s,p,Be,ee.touched,ue]);const Ue=async()=>{if(!p||!m){V.error(a("session.newWorktree.error.noActiveProject"));return}ne(Fe=>({...Fe,touched:!0}));const G=u==="new-branch"?f.branchName:h.selectedBranch,$=$e.worktreeName,fe=qn(G),L=hs($);if(!fe){V.error(a("session.newWorktree.error.branchNameRequired"));return}if(!L){V.error(a("session.newWorktree.error.worktreeDirectoryRequired"));return}ke&&(ke.abort(),De(null)),ne(Fe=>({...Fe,isValidating:!1,branchError:null,worktreeError:null})),Me(!0);try{const Fe=u==="new-branch"?f.linkedPr:null,Je=u==="new-branch"?f.linkedIssue:null,Xe=u==="new-branch"?f.linkedPr:null,et=u==="new-branch"?f.includePrDiff:!1,at=!!(Je||Xe),lt=await vl(p),Ze=f.sourceBranch;let We="";const pt=(()=>{if(Fe){const Ge=dl(Fe,N,y);return We=Ge.sourceLabel,{preferredName:fe||L,mode:"existing",branchName:fe,worktreeName:L,existingBranch:Ge.existingBranch,setupCommands:lt,setUpstream:Ge.setUpstream,upstreamRemote:Ge.upstreamRemote,upstreamBranch:Ge.upstreamBranch,returnAfterDirectoryCreated:!0,...Ge.ensureRemoteName?{ensureRemoteName:Ge.ensureRemoteName}:{},...Ge.ensureRemoteUrl?{ensureRemoteUrl:Ge.ensureRemoteUrl}:{}}}return We=u==="new-branch"?Ze:"",{preferredName:fe||L,mode:u==="existing-branch"?"existing":"new",branchName:u==="existing-branch"?void 0:fe,worktreeName:L,existingBranch:u==="existing-branch"?fe:void 0,setupCommands:lt,returnAfterDirectoryCreated:!0,...Ze&&u==="new-branch"?{startRef:Ze}:{}}})(),pe=await Mm(m,pt),st=await Rm(p,pe);let nt=null;if(at){await jl(p)&&await Tm(st.path);const Ge=Je?`#${Je.number} ${Je.title}`.trim():Xe?`#${Xe.number} ${Xe.title}`.trim():a("session.newWorktree.newSessionTitle"),ft=await Fm(Ge,st.path,null);if(!ft?.id)throw new Error("Failed to create session");nt=ft.id,n?.(st.path,{sessionId:nt}),e(!1),Me(!1),Om(ft.id,Ge).catch(()=>{});try{Ps.getState().initializeNewOpenChamberSession(ft.id,ut.getState().agents)}catch{}}else e(!1),Me(!1);f.sourceBranch&&u==="new-branch"&&!f.linkedPr&&localStorage.setItem(cl,f.sourceBranch),V.success(a("session.newWorktree.toast.worktreeCreated"),{description:a("session.newWorktree.toast.worktreeCreatedDescription",{target:`${st.branch||st.name}${We?` ${a("session.newWorktree.fromSource",{source:We})}`:""}`})}),nt?Oe({sessionId:nt,directory:st.path,issue:Je,pr:Xe,includeDiff:et}).catch(Ge=>{const ft=Ge instanceof Error?Ge.message:a("session.newWorktree.error.sendGitHubContextFailed");V.error(a("session.newWorktree.error.sendGitHubContextFailed"),{description:ft})}):n?.(st.path)}catch(Fe){const Je=Fe instanceof Error?Fe.message:a("session.newWorktree.error.createWorktreeFailed");V.error(a("session.newWorktree.error.createWorktreeFailed"),{description:Je})}finally{Me(!1)}},le=G=>{S(G),ne($=>({...$,touched:!1,branchError:null,worktreeError:null}))},q=G=>{if(!G){g($=>({...$,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(G.type==="issue"){const $=G.item,fe=`issue-${$.number}-${Qa()}`;g(L=>({...L,linkedIssue:$,linkedPr:null,includePrDiff:!1,branchName:fe,worktreeName:hs(fe),isSyncingWorktreeName:!0}))}else if(G.type==="pr"){const $=G.item;g(fe=>({...fe,linkedPr:$,linkedIssue:null,includePrDiff:G.includeDiff??!1,branchName:$.head,worktreeName:hs($.head),isSyncingWorktreeName:!0}))}},me=c&&d?.connected===!0,Ee=(u==="existing-branch"?!!h.selectedBranch&&!!h.worktreeName&&!ee.branchError&&!ee.worktreeError:!!qn(f.branchName)&&!!f.worktreeName&&!ee.branchError&&!ee.worktreeError)&&!ue,Ce=()=>{g(G=>({...G,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},He=t.jsxs("div",{className:de("flex gap-2",o?"flex-col w-full":"flex-row items-center"),children:[t.jsx("div",{className:de("flex items-center gap-1.5 text-destructive",o?"w-full justify-center order-first":"mr-auto"),children:ee.touched&&(ee.branchError||ee.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:ee.branchError||ee.worktreeError})]})}),t.jsxs("div",{className:de("flex gap-2",o&&"w-full"),children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:ue,className:de(o&&"flex-1"),children:a("session.newWorktree.actions.cancel")}),t.jsxs(J,{size:"sm",onClick:Ue,disabled:!Ee||ue,className:de("gap-1.5",o&&"flex-1"),children:[ue&&t.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(ue?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return t.jsxs(t.Fragment,{children:[o?t.jsxs(Gn,{open:s,title:a("session.newWorktree.title"),onClose:()=>e(!1),footer:He,children:[t.jsx("div",{className:"w-full mb-4",children:t.jsx(xn,{items:[{id:"new-branch",label:a("session.newWorktree.mode.newBranch"),icon:t.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:a("session.newWorktree.mode.existingBranch"),icon:t.jsx(A,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:u,onSelect:G=>le(G),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),t.jsxs("div",{className:"space-y-6",children:[u==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>B(!0),className:"flex-1 justify-between h-9",children:[t.jsx("span",{className:h.selectedBranch?"text-foreground":"text-muted-foreground",children:h.selectedBranch||a("session.newWorktree.chooseBranch")}),t.jsx(A,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),t.jsx(J,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:_,disabled:!ge||w,title:a("session.newWorktree.fetchBranches"),children:w?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"refresh",className:"size-4"})})]}),t.jsx(Gn,{open:U,title:a("session.newWorktree.selectBranch"),onClose:()=>B(!1),children:t.jsxs("div",{className:"space-y-4",ref:Z,children:[t.jsx(it,{value:R,onChange:G=>Y(G.target.value),placeholder:a("session.newWorktree.searchBranches"),className:"h-8"}),w?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):N.length===0&&y.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[be&&te&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a("session.newWorktree.matchingBranches")}),t.jsx("div",{className:"space-y-1",children:Ie.matching.map(G=>t.jsx("button",{onClick:()=>{D($=>({...$,selectedBranch:G.value,worktreeName:hs(G.label)})),ne($=>({...$,touched:!0})),B(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.selectedBranch===G.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:G.label})},`${G.source}-${G.value}`))})]}),be&&!te&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),Ie.otherLocal.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(be?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:Ie.otherLocal.map(G=>t.jsx("button",{onClick:()=>{D($=>({...$,selectedBranch:G,worktreeName:hs(G)})),ne($=>({...$,touched:!0})),B(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.selectedBranch===G?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:G})},G))})]}),Ie.otherRemote.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(be?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:Ie.otherRemote.map(G=>t.jsx("button",{onClick:()=>{D($=>({...$,selectedBranch:`remotes/${G}`,worktreeName:hs(G)})),ne($=>({...$,touched:!0})),B(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.selectedBranch===`remotes/${G}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:G})},`remotes/${G}`))})]})]})]})})]}):t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.branchName")}),u==="new-branch"&&me&&t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>I(!0),className:"gap-1.5 h-7",children:[t.jsx(A,{name:"github",className:"size-4 text-status-success"}),f.linkedIssue||f.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(it,{value:f.branchName,onChange:G=>{g($=>({...$,branchName:G.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ne(G=>({...G,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!f.linkedPr,className:de("h-8",ee.touched&&ee.branchError&&"border-destructive",f.linkedPr&&"bg-muted text-muted-foreground")}),f.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.usingPrBranch",{branch:f.linkedPr.head})})]}),f.linkedIssue&&!f.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.fromIssue",{number:f.linkedIssue.number,title:f.linkedIssue.title})})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:a("session.newWorktree.worktreeDirectory")}),u!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const G=hs(u==="new-branch"?f.branchName:"");g($=>({...$,worktreeName:G,isSyncingWorktreeName:!0}))},disabled:!f.branchName||f.worktreeName===hs(f.branchName),className:de("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",f.worktreeName===hs(f.branchName)||!f.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:a("session.newWorktree.resetToMatchBranchName"),children:[t.jsx(A,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:a("session.newWorktree.actions.reset")})]})]}),t.jsx(it,{value:$e.worktreeName,onChange:G=>{u==="new-branch"?g($=>({...$,worktreeName:G.target.value,isSyncingWorktreeName:!1})):D($=>({...$,worktreeName:G.target.value}))},onBlur:()=>ne(G=>({...G,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:de("h-8",ee.touched&&ee.worktreeError&&"border-destructive")})]}),u==="new-branch"&&!f.linkedPr&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.sourceBranch")}),t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>W(!0),className:"w-full justify-between h-9",children:[t.jsx("span",{className:f.sourceBranch?"text-foreground":"text-muted-foreground",children:f.sourceBranch||a("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(A,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),f.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:a("session.newWorktree.newBranchFromSource",{source:f.sourceBranch})}),t.jsx(Gn,{open:Q,title:a("session.newWorktree.selectSourceBranch"),onClose:()=>W(!1),children:t.jsxs("div",{className:"space-y-4",ref:se,children:[t.jsx(it,{value:F,onChange:G=>H(G.target.value),placeholder:a("session.newWorktree.searchBranches"),className:"h-8"}),w?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):N.length===0&&y.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[ye&&ie&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a("session.newWorktree.matchingBranches")}),t.jsx("div",{className:"space-y-1",children:ve.matching.map(G=>t.jsx("button",{onClick:()=>{g($=>({...$,sourceBranch:G.value})),W(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===G.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:G.label})},`${G.source}-${G.value}`))})]}),ye&&!ie&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),ve.otherLocal.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(ye?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:ve.otherLocal.map(G=>t.jsx("button",{onClick:()=>{g($=>({...$,sourceBranch:G})),W(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===G?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:G})},G))})]}),ve.otherRemote.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(ye?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:ve.otherRemote.map(G=>t.jsx("button",{onClick:()=>{g($=>({...$,sourceBranch:`remotes/${G}`})),W(!1)},className:de("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===`remotes/${G}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:G})},`remotes/${G}`))})]})]})]})})]}),(f.linkedIssue||f.linkedPr)&&u==="new-branch"&&t.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),f.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.issueNumber",{number:f.linkedIssue.number})}),f.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.prNumber",{number:f.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:f.linkedIssue?.title||f.linkedPr?.title}),t.jsx("a",{href:f.linkedIssue?.url||f.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:G=>G.stopPropagation(),children:t.jsx(A,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:Ce,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),f.linkedPr&&t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[f.linkedPr.head," → ",f.linkedPr.base]}),f.includePrDiff&&t.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:a("session.newWorktree.includeDiffBadge")})]})]})]})]}):t.jsx(Ut,{open:s,onOpenChange:e,children:t.jsxs(Bt,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[t.jsx(_t,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(Vt,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(A,{name:"git-branch",className:"h-5 w-5"}),a("session.newWorktree.title")]}),t.jsx("div",{className:"w-[280px] shrink-0",children:t.jsx(xn,{items:[{id:"new-branch",label:a("session.newWorktree.mode.newBranch"),icon:t.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:a("session.newWorktree.mode.existingBranch"),icon:t.jsx(A,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:u,onSelect:G=>le(G),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),t.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[u==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(us,{open:v,onOpenChange:j,children:[t.jsx(ds,{asChild:!0,children:t.jsxs(J,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[t.jsx("span",{className:de("truncate",h.selectedBranch?"text-foreground":"text-muted-foreground"),children:h.selectedBranch||a("session.newWorktree.chooseBranch")}),t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(ms,{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:X,children:t.jsxs(Nr,{shouldFilter:!1,children:[t.jsx(kr,{placeholder:a("session.newWorktree.searchBranches"),value:R,onValueChange:Y,onKeyDown:ce}),t.jsx(Sr,{disableHorizontal:!0,children:w?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):N.length===0&&y.length===0?t.jsx(Cr,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[be&&te&&t.jsx(Us,{heading:a("session.newWorktree.matchingBranches"),children:Ie.matching.map(G=>t.jsx(Es,{value:G.value,onSelect:()=>{D($=>({...$,selectedBranch:G.value,worktreeName:hs(G.label)})),ne($=>({...$,touched:!0})),j(!1)},children:t.jsx("span",{className:"typography-small break-all",children:G.label})},`${G.source}-${G.value}`))}),be&&!te&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),Ie.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[be&&t.jsx(Cn,{}),t.jsx(Us,{heading:a(be?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:Ie.otherLocal.map(G=>t.jsx(Es,{value:G,onSelect:()=>{D($=>({...$,selectedBranch:G,worktreeName:hs(G)})),ne($=>({...$,touched:!0})),j(!1)},children:t.jsx("span",{className:"typography-small break-all",children:G})},`local-${G}`))})]}),Ie.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(Ie.otherLocal.length>0||be)&&t.jsx(Cn,{}),t.jsx(Us,{heading:a(be?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:Ie.otherRemote.map(G=>t.jsx(Es,{value:`remotes/${G}`,onSelect:()=>{D($=>({...$,selectedBranch:`remotes/${G}`,worktreeName:hs(G)})),ne($=>({...$,touched:!0})),j(!1)},children:t.jsx("span",{className:"typography-small break-all",children:G})},`remote-${G}`))})]})]})})]})})]}),t.jsx(J,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:_,disabled:!ge||w,title:a("session.newWorktree.fetchBranches"),children:w?t.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(A,{name:"refresh",className:"size-4"})})]})]}):t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.branchName")}),u==="new-branch"&&me&&t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>I(!0),className:"gap-1.5 h-7",children:[t.jsx(A,{name:"github",className:"size-4 text-status-success"}),f.linkedIssue||f.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(it,{value:f.branchName,onChange:G=>{g($=>({...$,branchName:G.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ne(G=>({...G,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!f.linkedPr,className:de("h-8",ee.touched&&ee.branchError&&"border-destructive",f.linkedPr&&"bg-muted text-muted-foreground")}),f.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.usingPrBranch",{branch:f.linkedPr.head})})]}),f.linkedIssue&&!f.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.fromIssue",{number:f.linkedIssue.number,title:f.linkedIssue.title})})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:a("session.newWorktree.worktreeDirectory")}),u!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const G=hs(u==="new-branch"?f.branchName:"");g($=>({...$,worktreeName:G,isSyncingWorktreeName:!0}))},disabled:!f.branchName||f.worktreeName===hs(f.branchName),className:de("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",f.worktreeName===hs(f.branchName)||!f.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:a("session.newWorktree.resetToMatchBranchName"),children:[t.jsx(A,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:a("session.newWorktree.actions.reset")})]})]}),t.jsx(it,{value:$e.worktreeName,onChange:G=>{u==="new-branch"?g($=>({...$,worktreeName:G.target.value,isSyncingWorktreeName:!1})):D($=>({...$,worktreeName:G.target.value}))},onBlur:()=>ne(G=>({...G,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:de("h-8",ee.touched&&ee.worktreeError&&"border-destructive")})]}),u==="new-branch"&&!f.linkedPr&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.sourceBranch")}),t.jsxs(us,{open:O,onOpenChange:T,children:[t.jsx(ds,{asChild:!0,children:t.jsxs(J,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[t.jsx("span",{className:de("truncate",f.sourceBranch?"text-foreground":"text-muted-foreground"),children:f.sourceBranch||a("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(ms,{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:t.jsxs(Nr,{shouldFilter:!1,children:[t.jsx(kr,{placeholder:a("session.newWorktree.searchBranches"),value:F,onValueChange:H,onKeyDown:ce}),t.jsx(Sr,{disableHorizontal:!0,children:w?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):N.length===0&&y.length===0?t.jsx(Cr,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[ye&&ie&&t.jsx(Us,{heading:a("session.newWorktree.matchingBranches"),children:ve.matching.map(G=>t.jsx(Es,{value:G.value,onSelect:()=>{g($=>({...$,sourceBranch:G.value})),T(!1)},children:t.jsx("span",{className:"typography-small break-all",children:G.label})},`${G.source}-${G.value}`))}),ye&&!ie&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),ve.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[ye&&t.jsx(Cn,{}),t.jsx(Us,{heading:a(ye?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ve.otherLocal.map(G=>t.jsx(Es,{value:G,onSelect:()=>{g($=>({...$,sourceBranch:G})),T(!1)},children:t.jsx("span",{className:"typography-small break-all",children:G})},`local-${G}`))})]}),ve.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(ve.otherLocal.length>0||ye)&&t.jsx(Cn,{}),t.jsx(Us,{heading:a(ye?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ve.otherRemote.map(G=>t.jsx(Es,{value:`remotes/${G}`,onSelect:()=>{g($=>({...$,sourceBranch:`remotes/${G}`})),T(!1)},children:t.jsx("span",{className:"typography-small break-all",children:G})},`remote-${G}`))})]})]})})]})})]}),f.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:a("session.newWorktree.newBranchFromSource",{source:f.sourceBranch})})]}),(f.linkedIssue||f.linkedPr)&&u==="new-branch"&&t.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),f.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.issueNumber",{number:f.linkedIssue.number})}),f.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.prNumber",{number:f.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:f.linkedIssue?.title||f.linkedPr?.title}),t.jsx("a",{href:f.linkedIssue?.url||f.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:G=>G.stopPropagation(),children:t.jsx(A,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:Ce,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),f.linkedPr&&t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[f.linkedPr.head," → ",f.linkedPr.base]}),f.includePrDiff&&t.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:a("session.newWorktree.includeDiffBadge")})]})]})]}),t.jsxs(Yt,{className:"mt-1 flex items-center justify-between",children:[t.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:ee.touched&&(ee.branchError||ee.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(A,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:ee.branchError||ee.worktreeError})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:ue,children:a("session.newWorktree.actions.cancel")}),t.jsxs(J,{size:"sm",onClick:Ue,disabled:!Ee||ue,className:"gap-1.5",children:[ue&&t.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(ue?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),t.jsx(wv,{open:M,onOpenChange:I,onSelect:q})]})}export{yo as $,Dl as A,fn as B,Vv as C,qv as D,Kv as E,Nf as F,kf as G,zi as H,tl as I,ks as J,Wv as K,sn as L,Ev as M,Gv as N,Rv as O,Hv as P,an as Q,Ov as R,Iy as S,Ws as T,Jf as U,tn as V,en as W,zy as X,sl as Y,vo as Z,Nh as _,_v as a,qg as a0,nc as a1,rc as a2,vx as a3,Mv as a4,Ap as a5,Rl as a6,Ip as a7,$v as a8,Gy as b,Uv as c,Tv as d,Il as e,Mn as f,is as g,Ab as h,Ht as i,If as j,Eo as k,ru as l,Fv as m,Av as n,Dy as o,cs as p,Kh as q,zh as r,zv as s,Lv as t,Bv as u,Lh as v,xn as w,Qf as x,gn as y,hn as z};