@openchamber/web 1.16.0 → 1.16.1

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 (54) hide show
  1. package/README.md +5 -5
  2. package/dist/assets/{DiagramView-he_RFVx5.js → DiagramView-Elkp8b4l.js} +1 -1
  3. package/dist/assets/{MarkdownRendererImpl-CdBIHSPZ.js → MarkdownRendererImpl-DLhrL6oX.js} +4 -4
  4. package/dist/assets/{MultiRunWindow-B_C-tvVq.js → MultiRunWindow-DVpNCqnE.js} +1 -1
  5. package/dist/assets/{OnboardingScreen-BBnTt-9w.js → OnboardingScreen-CpcR0gyq.js} +1 -1
  6. package/dist/assets/SessionSwitcherDropdown-DHO5Je6v.js +1 -0
  7. package/dist/assets/{SettingsWindow-CjqLdpTE.js → SettingsWindow-Bewo7vwh.js} +1 -1
  8. package/dist/assets/{TerminalView-DQcdegHp.js → TerminalView-D9C7fNLm.js} +1 -1
  9. package/dist/assets/es-D9nOo8Wx.js +15 -0
  10. package/dist/assets/fr-DEF71lgt.js +13 -0
  11. package/dist/assets/index-BklNmnVr.js +2 -0
  12. package/dist/assets/index-C3uMIExE.css +1 -0
  13. package/dist/assets/ja-CpNfaEje.js +15 -0
  14. package/dist/assets/ko-DLS_rnE-.js +15 -0
  15. package/dist/assets/main-B0CxEOP5.js +237 -0
  16. package/dist/assets/{main-Dfm-VKZ9.js → main-Ck3ZNw8-.js} +2 -2
  17. package/dist/assets/miniChat-BAJj2Ome.js +2 -0
  18. package/dist/assets/mobile-CJoX4Cdj.js +2 -0
  19. package/dist/assets/pl-BjtFn5-n.js +15 -0
  20. package/dist/assets/pt-BR-C0_4Rnzn.js +15 -0
  21. package/dist/assets/renderElectronMiniChatApp-D4-OXCXM.js +2 -0
  22. package/dist/assets/{renderMobileApp-o7Fs9EBx.js → renderMobileApp-DHWdI195.js} +3 -3
  23. package/dist/assets/runtimeEndpointReset-B0P2DED1.js +167 -0
  24. package/dist/assets/uk-BDu4E0s0.js +15 -0
  25. package/dist/assets/{useAppFontEffects-DkPuAMXD.js → useAppFontEffects-9LFMCKYW.js} +127 -127
  26. package/dist/assets/zh-CN-BcwMqxIR.js +15 -0
  27. package/dist/assets/zh-TW-bNDQjKEu.js +15 -0
  28. package/dist/index.html +3 -3
  29. package/dist/mini-chat.html +3 -3
  30. package/dist/mobile.html +3 -3
  31. package/package.json +1 -1
  32. package/server/lib/opencode/settings-helpers.js +9 -0
  33. package/server/lib/package-manager.js +1 -1
  34. package/server/lib/small-model/DOCUMENTATION.md +3 -1
  35. package/server/lib/small-model/call.js +45 -8
  36. package/server/lib/small-model/call.test.js +338 -0
  37. package/server/lib/small-model/index.js +1 -0
  38. package/dist/assets/SessionSwitcherDropdown-CWWrCFzr.js +0 -1
  39. package/dist/assets/es-r0_jT91q.js +0 -15
  40. package/dist/assets/fr-Bo8rtAJ1.js +0 -13
  41. package/dist/assets/index-8J6waVO6.js +0 -2
  42. package/dist/assets/index-DEMqM4Lz.css +0 -1
  43. package/dist/assets/ja-BPWtkG-c.js +0 -15
  44. package/dist/assets/ko-Bv0k-0E3.js +0 -15
  45. package/dist/assets/main-B-GA5Tg5.js +0 -237
  46. package/dist/assets/miniChat-CfmCFFfu.js +0 -2
  47. package/dist/assets/mobile-CXJqeDlm.js +0 -2
  48. package/dist/assets/pl-CiTP50bz.js +0 -15
  49. package/dist/assets/pt-BR-DadIjX5L.js +0 -15
  50. package/dist/assets/renderElectronMiniChatApp-DS7Dy2ii.js +0 -2
  51. package/dist/assets/runtimeEndpointReset-MTaPPm4F.js +0 -167
  52. package/dist/assets/uk-2RpsWGoZ.js +0 -15
  53. package/dist/assets/zh-CN-BwKWaTuz.js +0 -15
  54. package/dist/assets/zh-TW--f_BqBpD.js +0 -15
@@ -0,0 +1,167 @@
1
+ import{am as ld,b as Ze,an as cd,j as t,r as he,ao as dd,ap as ud,a as Nn,d as wa,p as Ii,R as o,O as Ps,ad as md,ae as pd,ac as gd,af as hd,aa as fd,ab as xd,ag as yd,aq as bd,ar as vd,as as jd,u as wd,l as Nd,n as kd,w as Sd,C as Cd,S as Id,at as Pd,a8 as Ad,D as Dd,q as Ed,au as Md,av as Td,aw as Rd,ax as Fd,ay as Ld,$ as Ws,az as Od,aA as Fn,aB as Ui,aC as zd,aD as Kd,aE as kr,aF as Ud,aG as Bd,aH as $d,aI as Bi,aJ as nr,aK as $i,k as Ga,aL as tc,aM as Pi,aN as cr,aO as sc,aP as Vi,aQ as Vd,aR as _d,aS as Hd,aT as Wd,aU as _i,aV as Ee,aW as Aa,aX as Gd,aY as qd,aZ as Jd,a_ as Qd,a$ as Yd,b0 as nc,a9 as Xd,b1 as Hi,b2 as Zd,b3 as eu,b4 as tu,b5 as su}from"./vendor-.bun-BE757pvp.js";import{dK as dr,A as ar,C as rr,v as ce,dL as qa,dM as Ja,dN as Qa,b as es,c as st,I as D,aJ as St,aK as Ct,aL as It,V as nu,as as au,g as ac,o as on,b8 as Mt,b7 as Tt,b6 as Ot,bL as Ht,D as ii,B as J,bk as Ai,y as Dn,aH as Ms,t as _,a2 as rc,dO as Gn,dP as ru,dQ as iu,dy as ou,dR as lu,dS as cu,dT as du,G as ys,dU as uu,d3 as mu,d4 as pu,d5 as gu,cb as hu,aD as ms,aF as ps,cc as fu,aG as gs,a$ as ur,dV as xu,dW as _n,b5 as zt,bx as Bt,bT as qt,w as Xe,dX as ba,aC as Ns,Y as ot,dv as yu,bM as Pt,bN as At,bO as Lt,bP as Dt,bQ as ut,bj as hs,b0 as va,dY as xn,cJ as bs,b3 as xt,dZ as ic,d_ as bu,d$ as vu,e0 as mr,e1 as an,e2 as qn,b2 as oc,e3 as tn,e4 as ju,e5 as wu,e6 as Nu,e7 as ku,e8 as Su,e9 as Cu,ea as sn,eb as Iu,z as pr,ch as Wi,p as Pu,cj as oi,aj as lc,L as Au,P as cc,N as dc,cl as Du,U as Gi,dc as Eu,dt as uc,dh as mc,dj as Mu,ec as Tu,u as li,cL as Ru,ed as qi,ee as Fu,ef as Lu,eg as Ji,eh as Ou,ei as zu,ej as Ku,ek as Uu,aI as Bu,el as $u,O as Vu,Q as _u,d as Di,em as Hu,en as Wu,ao as Jn,an as pc,am as Gu,eo as qu,ep as Qi,ap as Ju,aq as Qu,al as Yu,aN as Xu,aO as Zu,aP as gc,eq as Sr,er as Yi,es as em,et as tm,eu as sm,ev as nm,dk as gr,Z as nn,ew as am,ex as rm,ey as im,ez as om,eA as lm,eB as Cr,eC as Xi,eD as cm,eE as dm,eF as um,eG as mm,eH as pm,eI as Ir,eJ as gm,aY as Zi,eK as Bn,aX as hm,eL as fm,eM as eo,eN as to,ck as xm,a4 as gn,dJ as hc,F as ym,S as bm,eO as vm,cw as Da,bp as ci,bq as di,br as ui,bs as mi,bt as en,bu as Bs,bU as Hn,M as xa,eP as so,c4 as jm,eQ as fc,bW as wm,dp as Nm,j as km,eR as Pr,ai as Sm,bd as Ea,b_ as Cm,eS as Im,eT as Pm,di as Am,eU as Dm,eV as Em,eW as xc,dH as Mm,eX as Tm}from"./useAppFontEffects-9LFMCKYW.js";import{P as Ei,h as dt,o as vs,e as ws,ab as Rm,ac as no,ad as Fm,ae as Lm,E as rs,X as An,u as Ie,w as Zn,a as ao,t as wt,d as ea,l as qs,v as ns,F as ro,af as io,ag as oo,I as la,ah as Om,k as zm,ai as $n,aj as Km,H as Um,ak as Bm,s as $m,al as Vm,am as yc,S as _m,an as Ar,Q as Hm,ao as lo,ap as Wm,J as Gm,aq as co,ar as uo,as as mo,at as po,au as Dr,av as go,O as bc,aw as Mi,ax as qm,ay as Jm,az as Qm,aA as Ym,aB as Xm,aC as Zm,aa as ep,n as tp,aD as sp,aE as np,aF as ap,aG as vc}from"./index-BklNmnVr.js";import{g as rp,s as ip}from"./mobileLayoutPreference-Dio-WWkI.js";function op(){return new Worker(ld,{type:"module"})}const lp=["typescript","javascript","tsx","jsx","json","markdown"],pi={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let ho,fo;const xo=s=>{const e=pi[s],n=new cd({workerFactory:op,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:lp,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},cp=s=>{if(!(typeof window>"u"))return s==="split"?(fo??=xo("split"),fo):(ho??=xo("unified"),ho)},dp=s=>{const e=Ze.c(7),{children:n,renderTheme:a}=s,r=gi("unified"),i=gi("split");let l,u;e[0]!==a||e[1]!==i||e[2]!==r?(l=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:pi.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:pi.split.lineDiffType})},u=[a,i,r],e[0]=a,e[1]=i,e[2]=r,e[3]=l,e[4]=u):(l=e[3],u=e[4]),he.useEffect(l,u);let c;return e[5]!==n?(c=t.jsx(t.Fragment,{children:n}),e[5]=n,e[6]=c):c=e[6],c},Gj=s=>{const e=Ze.c(11),{children:n}=s,a=dr();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const x=ar(!1),m=ar(!0),g=a?.lightThemeId??x.metadata.id,d=a?.darkThemeId??m.metadata.id;i=a?.availableThemes.find(b=>b.metadata.id===g)??x,r=a?.availableThemes.find(b=>b.metadata.id===d)??m,rr(i),rr(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 l;e[5]!==r.metadata.id||e[6]!==i.metadata.id?(l={light:i.metadata.id,dark:r.metadata.id},e[5]=r.metadata.id,e[6]=i.metadata.id,e[7]=l):l=e[7];const u=l;let c;return e[8]!==n||e[9]!==u?(c=t.jsx(dp,{renderTheme:u,children:n}),e[8]=n,e[9]=u,e[10]=c):c=e[10],c},gi=s=>{const e=Ze.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=cp(n),e[0]=n,e[1]=a):a=e[1],a};function up(s){const e=Ze.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 ir=he.forwardRef((s,e)=>{const n=Ze.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=ce("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 l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let u;n[6]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(dd,{className:ce("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=u):u=n[6];let c;return n[7]!==r||n[8]!==e||n[9]!==i?(c=t.jsx(ud,{className:i,style:l,...r,ref:e,children:u}),n[7]=r,n[8]=e,n[9]=i,n[10]=c):c=n[10],c});ir.displayName="Switch";const Ma=()=>{try{const e=es.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=vs.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[McpConfigStore] Error resolving config directory:",s)}return null},yo=s=>s?Object.entries(s).map(([e,n])=>({key:e,value:n})):[],bo=s=>{const e=s.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},Ta=s=>typeof s!="string"?void 0:s.trim()||void 0,Er=800,mp=5e3,pp="__default__",hi=new Map,Mr=new Map,jc=s=>s?.trim()||pp,Tr=s=>{hi.delete(jc(s))},Yn=Nn()(wa(Ii((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=Ma(),r=jc(a),i=Date.now(),l=hi.get(r)??0,u=e().mcpServers.length>0;if(!n?.force&&u&&i-l<mp)return!0;const c=Mr.get(r);if(!n?.force&&c)return c;const x=(async()=>{s({isLoading:!0});try{const m=a?`?directory=${encodeURIComponent(a)}`:"",g=await dt(`/api/config/mcp${m}`,{headers:a?{"x-opencode-directory":a}:void 0});if(!g.ok)throw new Error("Failed to load MCP configs");const d=await g.json();return s({mcpServers:d,isLoading:!1}),hi.set(r,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),s({isLoading:!1}),!1}})();Mr.set(r,x);try{return await x}finally{Mr.delete(r)}},createMcp:async n=>{qa("Creating MCP server configuration…");let a=!1;try{const r=vo(n),i=Ma(),l=i?`?directory=${encodeURIComponent(i)}`:"",u=await dt(`/api/config/mcp/${encodeURIComponent(n.name)}${l}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(r)}),c=await u.json().catch(()=>null);if(!u.ok)throw new Error(c?.error||"Failed to create MCP server");return Tr(i),c?.requiresReload?(a=!0,await Ja({message:c.message,delayMs:c.reloadDelayMs??Er,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||Qa()}},updateMcp:async(n,a)=>{qa("Updating MCP server configuration…");let r=!1;try{const i=vo(a),l=Ma(),u=l?`?directory=${encodeURIComponent(l)}`:"",c=await dt(`/api/config/mcp/${encodeURIComponent(n)}${u}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},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(l),x?.requiresReload?(r=!0,await Ja({message:x.message,delayMs:x.reloadDelayMs??Er,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||Qa()}},deleteMcp:async n=>{qa("Deleting MCP server configuration…");let a=!1;try{const r=Ma(),i=r?`?directory=${encodeURIComponent(r)}`:"",l=await dt(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:r?{"x-opencode-directory":r}:void 0}),u=await l.json().catch(()=>null);if(!l.ok)throw new Error(u?.error||"Failed to delete MCP server");return Tr(r),u?.requiresReload&&(a=!0,await Ja({message:u.message,delayMs:u.reloadDelayMs??Er,scopes:["all"]})),e().selectedMcpName===n&&s({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:u?.reloadFailed===!0,message:u?.message,warning:u?.warning}}catch(r){return console.error("[McpConfigStore] Failed to delete MCP:",r),{ok:!1}}finally{a||Qa()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:Ei(),partialize:s=>({selectedMcpName:s.selectedMcpName})}),{name:"mcp-config-store"}));function vo(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=bo(s.environment)??{}),s.headers!==void 0&&(e.headers=bo(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:Ta(s.oauthClientId),clientSecret:Ta(s.oauthClientSecret),scope:Ta(s.oauthScope),redirectUri:Ta(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 gp={},hp={},Zs=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},Kn=s=>Zs(s)??"__global__",Cn=s=>{const e=Zs(s);return e?vs.getScopedApiClient(e):vs.getApiClient()},os=Nn()(wa((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=Kn(n??ws.getState().currentDirectory);return e().byDirectory[a]??gp},getDiagnosticForDirectory:n=>{const a=Kn(n??ws.getState().currentDirectory);return e().diagnosticsByDirectory[a]??hp},getErrorForDirectory:n=>{const a=Kn(n??ws.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=Zs(n?.directory??ws.getState().currentDirectory),r=Kn(a);n?.silent||s(i=>({loadingKeys:{...i.loadingKeys,[r]:!0},lastErrorKeys:{...i.lastErrorKeys,[r]:null}}));try{const u=(await Cn(a).mcp.status()).data??{};s(c=>({byDirectory:{...c.byDirectory,[r]:u},diagnosticsByDirectory:{...c.diagnosticsByDirectory,[r]:Object.fromEntries(Object.entries(c.diagnosticsByDirectory[r]??{}).filter(([x])=>!u[x]))},loadingKeys:{...c.loadingKeys,[r]:!1},lastErrorKeys:{...c.lastErrorKeys,[r]:null}}))}catch(i){const l=i instanceof Error?i.message:"Failed to load MCP status";s(u=>({loadingKeys:{...u.loadingKeys,[r]:!1},lastErrorKeys:{...u.lastErrorKeys,[r]:l}}))}},connect:async(n,a)=>{const r=Zs(a??ws.getState().currentDirectory),i=Kn(r),l=Cn(r);try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(u){const c=u instanceof Error?u.message:"Connection failed";throw s(x=>({diagnosticsByDirectory:{...x.diagnosticsByDirectory,[i]:{...x.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:c}}}})),u}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=Zs(a??ws.getState().currentDirectory);await Cn(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=Zs(a??ws.getState().currentDirectory),u=(await Cn(r).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!u)throw new Error("Authorization URL was not returned");return u},completeAuth:async(n,a,r)=>{const i=Zs(r??ws.getState().currentDirectory);await Cn(i).mcp.auth.callback({name:n,code:a},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,a)=>{const r=Zs(a??ws.getState().currentDirectory);await Cn(r).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},testConnection:async(n,a)=>{const r=Zs(a??ws.getState().currentDirectory),i=Kn(r),l=Cn(r),c=e().getStatusForDirectory(r)[n]?.status==="connected";let x,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(b){x=b instanceof Error?b.message:"Connection failed",s(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:x??"Connection failed"}}}}))}await e().refresh({directory:r,silent:!0});const g=e().getStatusForDirectory(r)[n],d=g;if(!c&&g?.status==="connected"){try{await l.mcp.disconnect({name:n},{throwOnError:!0})}catch(b){m=`Connection test succeeded, but cleanup disconnect failed: ${b instanceof Error?b.message:"Disconnect failed"}`}await e().refresh({directory:r,silent:!0})}return{status:d??e().getStatusForDirectory(r)[n],error:x,warning:m}}}))),fp=(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}},xp=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},qj=({active:s,className:e,headerAction:n,listClassName:a,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:l}=st(),c=ws(k=>k.currentDirectory)??null,x=os(k=>k.getStatusForDirectory(c)),m=os(k=>k.refresh),g=os(k=>k.connect),d=os(k=>k.disconnect),b=Yn(k=>k.mcpServers),h=Yn(k=>k.loadMcpConfigs),[f,y]=o.useState(!1),[P,I]=o.useState(null);o.useEffect(()=>{m({directory:c,silent:!0})},[m,c]),o.useEffect(()=>{h({force:!0})},[h]),o.useEffect(()=>{s&&Promise.all([m({directory:c,silent:!0}),h({force:!0})])},[s,m,c,h]);const C=o.useMemo(()=>{const k=new Set(Object.keys(x));for(const v of b)v?.name&&k.add(v.name);return Array.from(k).sort((v,w)=>v.localeCompare(w))},[b,x]),L=o.useCallback(k=>{if(k?.preventDefault(),f)return;y(!0);const v=new Promise(w=>setTimeout(w,500));Promise.all([m({directory:c}),v]).finally(()=>{y(!1)})},[f,m,c]);return t.jsxs("div",{className:ce("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:l("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:f,onClick:L,"aria-label":l("mcpDropdown.actions.refreshAria"),children:t.jsx(D,{name:"refresh",className:ce("h-4 w-4",f&&"animate-spin")})})]})]})}),t.jsx("div",{className:ce("max-h-64 overflow-y-auto",i?"space-y-1 py-3":"px-3 py-2.5",a),children:t.jsxs("div",{className:ce(!i&&C.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[C.map(k=>{const v=x[k],w=xp(v),E=v?.status==="connected",K=P===k,U=fp(v,l);return t.jsxs("div",{className:ce("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",i?"gap-3 px-4 py-3":"gap-2 px-2.5 py-2"),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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx("span",{className:ce("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",w==="success"&&"bg-status-success",w==="error"&&"bg-status-error",w==="warning"&&"bg-status-warning",w==="default"&&"bg-muted-foreground/40"),"aria-label":U})}),t.jsx(It,{side:"left",children:t.jsx("p",{children:U})})]}),t.jsx("span",{className:ce("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:k})]})}),t.jsx(ir,{checked:E,disabled:K,className:"data-[checked]:bg-status-info",onCheckedChange:async M=>{I(k);try{M?await g(k,c):await d(k,c)}finally{I(null)}}})]},k)}),C.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:l("mcpDropdown.empty.configureInConfig")})]})})]})};function yp(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=au();return s}catch{return"unknown"}}function bp(){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 vp(){const s=ac();if(s==="android"||s==="ios")return s;if(typeof navigator>"u")return"web";const e=(navigator.platform||"").toLowerCase();return e.includes("mac")?"macos":e.includes("win")?"windows":e.includes("linux")?"linux":"web"}function jp(s){const e=Ie.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",yp()),n.set("arch",bp()),n.set("platform",vp()),s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",Zn()?"local":"remote"),n):s==="vscode"?(n.set("appType","vscode"),n.set("instanceMode","local"),n):s==="mobile"?(n.set("appType","mobile-capacitor"),n.set("instanceMode","remote"),n):(n.set("appType","web"),n.set("instanceMode","unknown"),n)}async function Rr(s,e){try{const n=jp(s),a=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e?n.set("currentVersion",e):s==="vscode"&&a&&n.set("currentVersion",a);const r=await dt(`/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,releaseUrl:i.releaseUrl,downloadUrl:i.downloadUrl,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 wp(){return nu()?"mobile":Lm()?"desktop":rs()?"vscode":An()?"web":null}const jo={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},wc=Nn()((s,e)=>({...jo,checkForUpdates:async()=>{const n=wp();if(!n)return null;s({checking:!0,error:null,runtimeType:n});try{let a=null,r=null;if(n==="desktop"){const i=await no();return s({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null}),r}else n==="web"?(a=await Rr("web"),r=a?.nextSuggestedCheckInSec??null):n==="vscode"?r=(await Rr("vscode"))?.nextSuggestedCheckInSec??null:n==="mobile"&&(a=await Rr("mobile","1.16.1"),r=a?.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 no();if(!r?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(s(l=>({info:l.info?{...l.info,...r,body:l.info.body||r.body,available:l.info.available}:r})),!await Fm(l=>{s({progress:l})}))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 Rm())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(jo)}})),wo="https://github.com/openchamber/openchamber/releases";function Np(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(Ai(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function kp(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function No(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function Sp(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,l=Number.isFinite(a[r])?a[r]:0;if(i!==l)return l-i}return 0}function Cp(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 l=n[i+1]?.start??s.length,u=s.slice(r.start,l).trim();return{version:r.version,date:r.date,start:r.start,end:l,raw:u}})}const ko=2e3,Ip=600*1e3;async function Pp(){try{const s=await dt("/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 Ap(){try{return(await dt("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function Dp(s,e=Math.ceil(Ip/ko),n=ko){for(let a=0;a<e;a++){try{const r=await dt("/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 Ap())return!0}catch{}await new Promise(r=>setTimeout(r,n))}return!1}const So=({open:s,onOpenChange:e,info:n,downloading:a,downloaded:r,progress:i,error:l,onDownload:u,onRestart:c,runtimeType:x="desktop"})=>{const{t:m}=st(),[g,d]=he.useState(!1),[b,h]=he.useState("idle"),[f,y]=he.useState(null),P=n?.version?n.releaseUrl||`${wo}/tag/v${n.version}`:wo,I=n?.downloadUrl||P,C=i?.total?Math.round(i.downloaded/i.total*100):0,L=x==="web",k=x==="mobile",v=n?.updateCommand||"openchamber update";he.useEffect(()=>{s||(h("idle"),y(null))},[s]);const w=async()=>{(await Dn(v)).ok&&(d(!0),setTimeout(()=>d(!1),2e3))},E=he.useCallback(async A=>{await on(A)},[]),K=he.useCallback(async()=>{h("updating"),y(null);const A=await Pp();if(!A.success){h("error"),y(A.error||m("updateDialog.error.updateFailed"));return}A.autoRestart&&(h("restarting"),await new Promise(T=>setTimeout(T,2e3))),h("reconnecting"),await Dp(n?.currentVersion)?window.location.reload():(h("error"),y(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),U=he.useCallback(()=>{E(I)},[E,I]),M=b!=="idle"&&b!=="error",S=he.useMemo(()=>{if(!n?.body)return null;const A=n.body.trim();if(!A)return null;const z=Cp(A);if(z.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:No(A)};const T=[...z].sort((Z,G)=>Sp(Z.version,G.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:T.map(Z=>({version:Z.version,dateLabel:Np(Z.date),content:No(kp(Z.raw)||A)}))}},[n?.body,m]);return t.jsx(Mt,{open:s,onOpenChange:M?void 0:e,children:t.jsxs(Tt,{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(Ot,{className:"flex items-center gap-2.5",children:[t.jsx(D,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),t.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(b==="restarting"||b==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&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:[L&&M&&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(D,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),t.jsxs("div",{className:"typography-ui-label text-foreground",children:[b==="updating"&&m("updateDialog.status.installingUpdate"),b==="restarting"&&m("updateDialog.status.serverRestarting"),b==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),S&&!M&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(Ht,{className:"max-h-[400px] p-0",fillContainer:!1,children:S.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:A=>{const T=A.target.closest("a");T&&T.href&&(A.preventDefault(),A.stopPropagation(),E(T.href))},children:t.jsx(ii,{content:S.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:S.sections.map(A=>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",A.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:A.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:z=>{const Z=z.target.closest("a");Z&&Z.href&&(z.preventDefault(),z.stopPropagation(),E(Z.href))},children:t.jsx(ii,{content:A.content,disableLinkSafety:!0,enableFileReferences:!1})})]},A.version))})})}),L&&b==="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(D,{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:v}),t.jsx("button",{onClick:w,className:ce("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",g&&"text-[var(--status-success)]"),title:m(g?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:g?t.jsx(D,{name:"check",className:"h-4 w-4"}):t.jsx(D,{name:"clipboard",className:"h-4 w-4"})})]})]}),!L&&!k&&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:[C,"%"]})]}),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:`${C}%`}})})]}),(l||f)&&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:l||f})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:P,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(D,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!L&&!k&&!r&&!a&&t.jsxs("button",{onClick:u,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(D,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!L&&!k&&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(D,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!L&&!k&&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(D,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),k&&t.jsxs(J,{onClick:U,size:"default",children:[t.jsx(D,{name:"external-link",className:"h-4 w-4"}),m("updateDialog.actions.openMobileUpdate")]}),L&&!M&&t.jsxs("button",{onClick:K,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(D,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),L&&M&&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(D,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},Co="https://github.com/openchamber/openchamber",Ep="https://discord.gg/ZYRSdnwwKA",Io="https://x.com/openchamber_dev",Mp=800,Nc=({initialUpdateDialogOpen:s=!1})=>{const{t:e}=st(),[n,a]=o.useState(s),[r,i]=o.useState(!1),[l,u]=o.useState(null),[c,x]=o.useState(null),m=wc(Ps(f=>({info:f.info,checking:f.checking,available:f.available,error:f.error,downloading:f.downloading,downloaded:f.downloaded,progress:f.progress,runtimeType:f.runtimeType,checkForUpdates:f.checkForUpdates,downloadUpdate:f.downloadUpdate,restartToUpdate:f.restartToUpdate}))),{isMobile:g}=Ms(),d=l||m.info?.currentVersion||"unknown";o.useEffect(()=>{let f=!1;return(async()=>{try{const P=await dt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!P.ok)return;const I=await P.json().catch(()=>null),C=typeof I?.openchamberVersion=="string"&&I.openchamberVersion.trim().length>0?I.openchamberVersion.trim():null;f||u(C)}catch{f||u(null)}})(),()=>{f=!0}},[]),o.useEffect(()=>{let f=!1;return(async()=>{try{const P=await dt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!P.ok)return;const I=await P.json().catch(()=>null),C=typeof I?.currentVersion=="string"&&I.currentVersion.trim().length>0?I.currentVersion.trim():null;f||x(C)}catch{f||x(null)}})(),()=>{f=!0}},[]);const b=o.useRef(!1);o.useEffect(()=>{if(m.checking)i(!0),b.current=!0;else if(r){const f=setTimeout(()=>{i(!1),b.current&&!m.available&&!m.error&&(_.success(e("settings.openchamber.about.toast.latestVersion")),b.current=!1)},Mp);return()=>clearTimeout(f)}},[e,m.checking,r,m.available,m.error]);const h=m.checking||r;return g?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(rc,{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:d})}),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:h,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[h?t.jsx(D,{name:"loader",className:"size-4 animate-spin"}):t.jsx(D,{name:"refresh",className:"size-4"}),e(h?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!h&&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(D,{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:Co,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(D,{name:"github-fill",className:"size-5"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:Ep,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(D,{name:"discord-fill",className:"size-5"}),t.jsx("span",{children:"Discord"})]})]}),t.jsxs("a",{href:Io,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(D,{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(So,{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:d})]}),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(D,{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(D,{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:Co,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(D,{name:"github-fill",className:"h-4 w-4"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:Io,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(D,{name:"twitter-xfill",className:"h-4 w-4"}),t.jsx("span",{children:"@openchamber_dev"})]})]})]}),t.jsx(So,{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})]})},Jj=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),Tp=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),Rp=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},Fp=s=>!s||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),ca="opencode-update-available",Ra="opencode-upgrade-progress",Lp=5e3,Op=[1e4,6e4],Po="opencode-update-toast-dismissed-version",Qj=()=>{const{t:s}=st(),e=Ie(l=>l.showOpenCodeUpdateNotifications),n=he.useRef(new Set),a=he.useRef(!1);he.useEffect(()=>{e||_.dismiss(ca)},[e]);const r=he.useCallback(()=>{_.dismiss(Ra),Gn({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),i=he.useCallback(async()=>{if(!a.current){a.current=!0,_.dismiss(ca),_.message(s("opencodeUpdate.toast.upgrading.title"),{id:Ra,description:s("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:t.jsx(D,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const l=await dt("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),u=await l.json().catch(()=>null);if(!l.ok||u?.success===!1)throw new Error(u?.error||l.statusText||s("opencodeUpdate.toast.failed.description"));_.success(s("opencodeUpdate.toast.updated.title"),{id:Ra,description:u?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:u.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(D,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(l){_.error(s("opencodeUpdate.toast.failed.title"),{id:Ra,description:l instanceof Error?l.message:s("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{a.current=!1}}},[r,s]);return he.useEffect(()=>{const l=g=>{if(!Ie.getState().showOpenCodeUpdateNotifications){_.dismiss(ca);return}Tp({version:g,dismissedVersion:ao().getItem(Po),seenVersions:n.current})&&(n.current.add(g),_.info(s("opencodeUpdate.toast.available.title"),{id:ca,description:s("opencodeUpdate.toast.available.description",{version:g}),duration:1/0,action:{label:s("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:s("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{ao().setItem(Po,g),wt({openCodeUpdateToastDismissedVersion:g}),_.dismiss(ca)}}}))},u=g=>{const d=Rp(g.detail);l(d)};let c=!1;const x=[],m=async g=>{try{const d=await dt("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!d.ok)throw new Error(d.statusText||"OpenCode upgrade status check failed");const b=await d.json().catch(()=>null),h=Fp(b);!c&&h&&l(h)}catch{const d=Op[g];!c&&d!==void 0&&x.push(setTimeout(()=>{m(g+1)},d))}};return e&&x.push(setTimeout(()=>{m(0)},Lp)),window.addEventListener("openchamber:opencode-update-available",u),()=>{c=!0;for(const g of x)clearTimeout(g);window.removeEventListener("openchamber:opencode-update-available",u)}},[i,e,s]),null},Yj=()=>{const s=Ze.c(3),[e,n]=o.useState(zp),{isUpdating:a}=e;let r,i;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>iu(n),i=[],s[0]=r,s[1]=i):(r=s[0],i=s[1]),o.useEffect(r,i),!a)return null;let l;return s[2]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:t.jsx(rc,{width:80,height:80,isAnimated:!0})}),s[2]=l):l=s[2],l};function zp(){return ru()}class Kp extends o.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(ou,{className:"w-full max-w-md",children:[t.jsx(lu,{className:"text-center",children:t.jsxs(cu,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(D,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(du,{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(D,{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 Up(s){const e=Ze.c(22),{t:n}=st();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 l;e[6]!==n?(l=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=l):l=e[7];let u;e[8]!==n?(u=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=u):u=e[9];let 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]!==l||e[16]!==u||e[17]!==c?(x={title:a,description:r,sessionLabel:i,detailsSummary:l,resetAction:u,persistentHint:c},e[12]=a,e[13]=r,e[14]=i,e[15]=l,e[16]=u,e[17]=c,e[18]=x):x=e[18];let m;return e[19]!==s||e[20]!==x?(m=t.jsx(Kp,{...s,texts:x}),e[19]=s,e[20]=x,e[21]=m):m=e[21],m}const Xj=s=>{const e=Ze.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=ys(Bp)||void 0;let l;e[0]!==a?(l=t.jsx(uu,{readOnly:a}),e[0]=a,e[1]=l):l=e[1];let u;return e[2]!==i||e[3]!==l?(u=t.jsx(Up,{sessionId:i,children:l}),e[2]=i,e[3]=l,e[4]=u):u=e[4],u};function Bp(s){return s.currentSessionId}function yn(s){const e=Ze.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(md,{...n}),e[2]=n,e[3]=a):a=e[3],a}function bn(s){const e=Ze.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(pd,{...n}),e[2]=n,e[3]=a):a=e[3],a}function vn(s){const e=Ze.c(20);let n,a,r,i,l;e[0]!==s?({className:a,positionerClassName:r,children:n,style:l,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i,e[5]=l):(n=e[1],a=e[2],r=e[3],i=e[4],l=e[5]);let u;e[6]!==r?(u=ce("app-region-no-drag z-50",r),e[6]=r,e[7]=u):u=e[7];let c;e[8]!==l?(c={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",...l},e[8]=l,e[9]=c):c=e[9];let x;e[10]!==a?(x=ce(mu,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(gd,{"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 g;return e[17]!==u||e[18]!==m?(g=t.jsx(fd,{children:t.jsx(xd,{className:u,children:m})}),e[17]=u,e[18]=m,e[19]=g):g=e[19],g}function ln(s){const e=Ze.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=ce(pu,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(hd,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}function Zj(s){const e=Ze.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=ce(gu,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(yd,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}const kc=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),Na=s=>{const e=Ze.c(39),{className:n}=s,{t:a}=st(),r=es($p),i=es(Vp),l=es(_p),u=rs();let c;e[0]!==r?(c=[...r].sort(Hp),e[0]=r,e[1]=c):c=e[1];const x=c;let m;e:{if(x.length===0){m=null;break e}let z;e[2]!==i||e[3]!==x?(z=x.find(T=>T.id===i)??x[0],e[2]=i,e[3]=x,e[4]=z):z=e[4],m=z}const g=m;if(u||x.length===0)return null;let d;e[5]!==g||e[6]!==a?(d=g?.label&&g.label.trim().length>0?g.label:g?.path.split("/").filter(Boolean).pop()||g?.path||a("settings.shared.projectSelector.fallbackProject"),e[5]=g,e[6]=a,e[7]=d):d=e[7];const b=d;let h;e[8]!==b?(h=kc(b),e[8]=b,e[9]=h):h=e[9];const f=h;let y;e[10]!==n?(y=ce(n),e[10]=n,e[11]=y):y=e[11];let P;e[12]!==a?(P=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=P):P=e[13];let I;e[14]!==a?(I=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=I):I=e[15];let C,L;e[16]===Symbol.for("react.memo_cache_sentinel")?(C=ce("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"),L=t.jsx(D,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=C,e[17]=L):(C=e[16],L=e[17]);let k;e[18]!==f?(k=t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:f}),e[18]=f,e[19]=k):k=e[19];let v;e[20]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=v):v=e[20];let w;e[21]!==k||e[22]!==P||e[23]!==I?(w=t.jsx(ms,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":P,title:I,className:C,children:[L,k,v]})}),e[21]=k,e[22]=P,e[23]=I,e[24]=w):w=e[24];const E=g?.id??"";let K;e[25]!==l?(K=z=>{z&&l(z)},e[25]=l,e[26]=K):K=e[26];let U;e[27]!==x?(U=x.map(Wp),e[27]=x,e[28]=U):U=e[28];let M;e[29]!==E||e[30]!==K||e[31]!==U?(M=t.jsx(ps,{align:"start",className:"w-auto",children:t.jsx(fu,{value:E,onValueChange:K,children:U})}),e[29]=E,e[30]=K,e[31]=U,e[32]=M):M=e[32];let S;e[33]!==w||e[34]!==M?(S=t.jsxs(gs,{children:[w,M]}),e[33]=w,e[34]=M,e[35]=S):S=e[35];let A;return e[36]!==S||e[37]!==y?(A=t.jsx("div",{className:y,children:S}),e[36]=S,e[37]=y,e[38]=A):A=e[38],A};function $p(s){return s.projects}function Vp(s){return s.activeProjectId}function _p(s){return s.setActiveProject}function Hp(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function Wp(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=kc(e);return t.jsx(hu,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function Gp(s,e){return`opencode:sidebar-group:${s}:${e}`}const fi=s=>{const e=Ze.c(33),{label:n,count:a,storageKey:r,defaultExpanded:i,children:l}=s,u=i===void 0?!0:i;let c;e[0]!==n||e[1]!==r?(c=Gp(r,n),e[0]=n,e[1]=r,e[2]=c):c=e[2];const x=c,m=o.useId();let g;e[3]!==u||e[4]!==x?(g=()=>{try{const M=localStorage.getItem(x);if(M!==null)return M==="true"}catch{}return u},e[3]=u,e[4]=x,e[5]=g):g=e[5];const[d,b]=he.useState(g);let h,f;e[6]!==d||e[7]!==x?(h=()=>{try{localStorage.setItem(x,String(d))}catch{}},f=[x,d],e[6]=d,e[7]=x,e[8]=h,e[9]=f):(h=e[8],f=e[9]),he.useEffect(h,f);let y;e[10]===Symbol.for("react.memo_cache_sentinel")?(y=()=>b(qp),e[10]=y):y=e[10];let P;e[11]===Symbol.for("react.memo_cache_sentinel")?(P=ce("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]=P):P=e[11];const I=!d&&"-rotate-90";let C;e[12]!==I?(C=ce("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",I),e[12]=I,e[13]=C):C=e[13];let L;e[14]!==C?(L=t.jsx(D,{name:"arrow-down-s",className:C}),e[14]=C,e[15]=L):L=e[15];let k;e[16]!==n?(k=t.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=k):k=e[17];let v;e[18]!==a?(v=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=v):v=e[19];let w;e[20]!==m||e[21]!==d||e[22]!==L||e[23]!==k||e[24]!==v?(w=t.jsxs("button",{type:"button",onClick:y,"aria-expanded":d,"aria-controls":m,className:P,children:[L,k,v]}),e[20]=m,e[21]=d,e[22]=L,e[23]=k,e[24]=v,e[25]=w):w=e[25];const E=!d;let K;e[26]!==l||e[27]!==m||e[28]!==E?(K=t.jsx("div",{id:m,hidden:E,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=m,e[28]=E,e[29]=K):K=e[29];let U;return e[30]!==w||e[31]!==K?(U=t.jsxs("div",{children:[w,K]}),e[30]=w,e[31]=K,e[32]=U):U=e[32],U};function qp(s){return!s}const Jp=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},Qp=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())},Ao=s=>{const e=Qp(Jp(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 l=Object.keys(i);if(l.length===1&&l[0]==="*"){a[r]=i["*"];continue}a[r]=i}return Object.keys(a).length>0?a:void 0},Yp=({onItemSelect:s})=>{const{t:e}=st(),[n,a]=o.useState(null),[r,i]=o.useState(""),[l,u]=o.useState(null),[c,x]=o.useState(null),[m,g]=o.useState(!1),[d,b]=o.useState(null),{selectedAgentName:h,agents:f,setSelectedAgent:y,setAgentDraft:P,createAgent:I,deleteAgent:C,loadAgents:L}=ur(Ps(N=>({selectedAgentName:N.selectedAgentName,agents:N.agents,setSelectedAgent:N.setSelectedAgent,setAgentDraft:N.setAgentDraft,createAgent:N.createAgent,deleteAgent:N.deleteAgent,loadAgents:N.loadAgents})));o.useEffect(()=>{L()},[L]);const k="bg-background",v=()=>{const N="new-agent";let W=N,B=1;for(;f.some(F=>F.name===W);)W=`${N}-${B}`,B++;P({name:W,scope:"user"}),y(W),s?.()},w=async N=>{if(_n(N)){_.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}u(N),x("delete")},E=async N=>{_n(N)&&(u(N),x("reset"))},K=()=>{u(null),x(null)},U=async()=>{if(!(!l||!c)){g(!0);try{const N=await C(l.name,l.scope);N.ok?(N.requiresManualRestart?_.warning(e("settings.agents.page.toast.savedManualRestart")):c==="delete"?_.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):_.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),K()):c==="delete"?_.error(e("settings.agents.sidebar.toast.deleteFailed")):_.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(N){const W=N instanceof Error?N.message:"",B=/built-in|not deletable|not found/i.test(W);c==="delete"?_.error(e(B?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):_.error(e("settings.agents.sidebar.toast.resetFailed"))}g(!1)}},M=N=>{const W=N.name;let B=1,F=`${W}-copy`;for(;f.some(ie=>ie.name===F);)B++,F=`${W}-copy-${B}`;const O=N,Q=N.model?.providerID&&N.model?.modelID?`${N.model.providerID}/${N.model.modelID}`:null,H=N;P({name:F,scope:O.scope||"user",description:N.description,model:Q,variant:N.variant,temperature:N.temperature,top_p:N.topP,prompt:N.prompt,mode:N.mode,permission:Ao(N.permission),disable:H.disable}),y(F)},S=N=>{i(N.name),a(N)},A=async()=>{if(!n)return;const N=r.trim().replace(/\s+/g,"-");if(!N){_.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(N===n.name){a(null);return}if(f.some(O=>O.name===N)){_.error(e("settings.agents.sidebar.toast.agentExists"));return}const W=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,B=n,F=await I({name:N,description:n.description,model:W,variant:n.variant,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Ao(n.permission),disable:B.disable,scope:B.scope});if(F.ok){const O=await C(n.name,B.scope);O.ok?(F.requiresManualRestart||O.requiresManualRestart?_.warning(e("settings.agents.page.toast.savedManualRestart")):_.success(e("settings.agents.sidebar.toast.agentRenamed",{name:N})),y(N)):_.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else _.error(e("settings.agents.sidebar.toast.renameFailed"));a(null)},z=N=>{switch(N){case"primary":return t.jsx(D,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(D,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(D,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},T=f.filter(N=>!xu(N)),Z=T.filter(_n),G=T.filter(N=>!_n(N)),{groupedCustomAgents:te,ungroupedCustomAgents:Y}=he.useMemo(()=>{const N={},W=[];for(const F of G){const O=F;O.group?(N[O.group]||(N[O.group]=[]),N[O.group].push(F)):W.push(F)}return{groupedCustomAgents:Object.keys(N).sort((F,O)=>F.localeCompare(O)).map(F=>({name:F,agents:N[F]})),ungroupedCustomAgents:W}},[G]);return t.jsxs("div",{className:ce("flex h-full flex-col",k),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(Na,{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:v,children:t.jsx(D,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Ht,{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(D,{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:[Z.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")}),Z.map(N=>t.jsx(Fr,{agent:N,isSelected:h===N.name,onSelect:()=>{y(N.name),s?.()},onReset:()=>E(N),onDuplicate:()=>M(N),getAgentModeIcon:z,isMenuOpen:d===N.name,onMenuOpenChange:W=>b(W?N.name:null)},N.name))]}),G.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")}),te.map(({name:N,agents:W})=>t.jsx(fi,{label:N,count:W.length,storageKey:"agents",children:W.map(B=>t.jsx(Fr,{agent:B,isSelected:h===B.name,onSelect:()=>{y(B.name),s?.()},onRename:()=>S(B),onDelete:()=>w(B),onDuplicate:()=>M(B),getAgentModeIcon:z,isMenuOpen:d===B.name,onMenuOpenChange:F=>b(F?B.name:null)},B.name))},N)),Y.map(N=>t.jsx(Fr,{agent:N,isSelected:h===N.name,onSelect:()=>{y(N.name),s?.()},onRename:()=>S(N),onDelete:()=>w(N),onDuplicate:()=>M(N),getAgentModeIcon:z,isMenuOpen:d===N.name,onMenuOpenChange:W=>b(W?N.name:null)},N.name))]})]})}),t.jsx(Mt,{open:l!==null&&c!==null,onOpenChange:N=>{!N&&!m&&K()},children:t.jsxs(Tt,{className:"max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(Bt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),t.jsxs(qt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:K,disabled:m,children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:U,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx(Mt,{open:n!==null,onOpenChange:N=>!N&&a(null),children:t.jsxs(Tt,{children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(Bt,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(Xe,{value:r,onChange:N=>i(N.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:N=>{N.key==="Enter"&&A()}}),t.jsxs(qt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:A,children:e("settings.common.actions.rename")})]})]})})]})},Fr=s=>{const e=Ze.c(52),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:l,onRename:u,onDuplicate:c,getAgentModeIcon:x,isMenuOpen:m,onMenuOpenChange:g}=s,{t:d}=st(),b=n;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=ba(),e[0]=h):h=e[0];const f=h,[y,P]=o.useState(!1);let I;e[1]!==i||e[2]!==c||e[3]!==u||e[4]!==l||e[5]!==d?(I=B=>t.jsxs(t.Fragment,{children:[u&&t.jsxs(B,{onClick:F=>{F.stopPropagation(),u()},children:[t.jsx(D,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}),t.jsxs(B,{onClick:F=>{F.stopPropagation(),c()},children:[t.jsx(D,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),l&&t.jsxs(B,{onClick:F=>{F.stopPropagation(),l()},children:[t.jsx(D,{name:"restart",className:"h-4 w-4 mr-px"}),d("settings.common.actions.reset")]}),i&&t.jsxs(B,{onClick:F=>{F.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=u,e[4]=l,e[5]=d,e[6]=I):I=e[6];const C=I,L=a?"bg-interactive-selection":"hover:bg-interactive-hover";let k;e[7]!==L?(k=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",L),e[7]=L,e[8]=k):k=e[8];let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=f?void 0:B=>{B.preventDefault(),P(!0)},e[9]=v):v=e[9];let w;e[10]!==k?(w=t.jsx("div",{className:k,onContextMenu:v}),e[10]=k,e[11]=w):w=e[11];let E;e[12]!==n.name?(E=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[12]=n.name,e[13]=E):E=e[13];let K;e[14]!==n.mode||e[15]!==x?(K=x(n.mode),e[14]=n.mode,e[15]=x,e[16]=K):K=e[16];let U;e[17]!==n||e[18]!==b.scope||e[19]!==d?(U=(b.scope||_n(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:_n(n)?d("settings.agents.sidebar.badge.system"):b.scope}),e[17]=n,e[18]=b.scope,e[19]=d,e[20]=U):U=e[20];let M;e[21]!==E||e[22]!==K||e[23]!==U?(M=t.jsxs("div",{className:"flex items-center gap-1.5",children:[E,K,U]}),e[21]=E,e[22]=K,e[23]=U,e[24]=M):M=e[24];let S;e[25]!==n.description?(S=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[25]=n.description,e[26]=S):S=e[26];let A;e[27]!==r||e[28]!==M||e[29]!==S?(A=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:[M,S]}),e[27]=r,e[28]=M,e[29]=S,e[30]=A):A=e[30];let z;e[31]!==g?(z=B=>{B&&P(!1),g(B)},e[31]=g,e[32]=z):z=e[32];let T;e[33]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(ms,{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(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=T):T=e[33];let Z;e[34]!==C?(Z=t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:C(Ns)}),e[34]=C,e[35]=Z):Z=e[35];let G;e[36]!==m||e[37]!==z||e[38]!==Z?(G=t.jsxs(gs,{open:m,onOpenChange:z,children:[T,Z]}),e[36]=m,e[37]=z,e[38]=Z,e[39]=G):G=e[39];let te;e[40]!==A||e[41]!==G?(te=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,G]}),e[40]=A,e[41]=G,e[42]=te):te=e[42];let Y;e[43]!==te||e[44]!==w?(Y=t.jsx(bn,{render:w,children:te}),e[43]=te,e[44]=w,e[45]=Y):Y=e[45];let N;e[46]!==C?(N=t.jsx(vn,{className:"w-fit min-w-20",children:C(ln)}),e[46]=C,e[47]=N):N=e[47];let W;return e[48]!==y||e[49]!==Y||e[50]!==N?(W=t.jsxs(yn,{open:y,onOpenChange:P,children:[Y,N]}),e[48]=y,e[49]=Y,e[50]=N,e[51]=W):W=e[51],W},Do=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Ya=s=>s==="allow"||s==="ask"||s==="deny",Pn=(s,e)=>`${s}::${e}`,jn=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&Ya(n.action)&&e.set(Pn(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},Fa=s=>{const e=new Map;for(const n of jn(s))e.set(Pn(n.permission,n.pattern),n);return e},Eo=s=>[...s].sort((e,n)=>{const a=e.permission.localeCompare(n.permission);return a!==0?a:e.pattern.localeCompare(n.pattern)}),Xp=(s,e)=>{const n=Eo(jn(s)),a=Eo(jn(e));return n.length!==a.length?!1:n.every((r,i)=>{const l=a[i];return r.permission===l.permission&&r.pattern===l.pattern&&r.action===l.action})},Zp=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",eg=(s,e)=>jn(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),Lr=s=>{if(Array.isArray(s))return jn(s);if(Ya(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(Ya(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))Ya(i)&&e.push({permission:n,pattern:r,action:i})}return e},tg=(s,e)=>{const n=jn(e),a={};for(const i of n)(a[i.permission]||={})[i.pattern]=i.action;const r={};for(const[i,l]of Object.entries(a))if(i!=="*"){if(Object.keys(l).length===1&&l["*"]){r[i]=l["*"];continue}r[i]=l}return Object.keys(r).length===0?s:(s!=="allow"&&(r["*"]=s),r)},sg=(s,e)=>{const n=xn(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):[]},ng=()=>{const{t:s}=st(),{isMobile:e}=Ms(),n=ot(V=>V.providers),{selectedAgentName:a,getAgentByName:r,createAgent:i,updateAgent:l,agents:u,agentDraft:c,setAgentDraft:x}=ur(Ps(V=>({selectedAgentName:V.selectedAgentName,getAgentByName:V.getAgentByName,createAgent:V.createAgent,updateAgent:V.updateAgent,agents:V.agents,agentDraft:V.agentDraft,setAgentDraft:V.setAgentDraft}))),m=a?r(a):null,g=!!(c&&c.name===a&&!m),[d,b]=o.useState(""),[h,f]=o.useState("user"),[y,P]=o.useState(""),[I,C]=o.useState("subagent"),[L,k]=o.useState(""),[v,w]=o.useState(""),[E,K]=o.useState(void 0),[U,M]=o.useState(void 0),[S,A]=o.useState(""),[z,T]=o.useState("allow"),[Z,G]=o.useState([]),[te,Y]=o.useState([]),[N,W]=o.useState(""),[B,F]=o.useState("*"),[O,Q]=o.useState(!1),[H,ie]=o.useState(!1),oe=o.useRef(null),se=ws(V=>V.currentDirectory??null),[xe,ae]=o.useState([]),fe=o.useMemo(()=>sg(n,L),[L,n]),Ce=fe.length>0,ge=o.useMemo(()=>!v||!fe.includes(v)?"__default":v,[v,fe]),ve=Ce&&(!v||fe.includes(v)),Ne=yu(V=>V.permission);o.useEffect(()=>{let V=!1;return(async()=>{const pe=await vs.listToolIds({directory:se});if(V)return;const Le=new Set(["write","patch","multiedit"]),we=pe.map(He=>typeof He=="string"?He.trim():"").filter(Boolean).filter(He=>He!=="*").filter(He=>He!=="invalid").filter(He=>!Le.has(He));ae(Array.from(new Set(we)).sort((He,X)=>He.localeCompare(X)))})(),()=>{V=!0}},[se]);const ne=o.useMemo(()=>{const V=new Set;for(const le of u){const pe=jn(Lr(le.permission));for(const Le of pe)Le.permission&&Le.permission!=="*"&&Le.permission!=="invalid"&&V.add(Le.permission)}for(const le of Object.values(Ne))for(const pe of le){const Le=pe.permission?.trim();Le&&Le!=="invalid"&&V.add(Le)}for(const le of xe)V.add(le);return Array.from(V).sort((le,pe)=>le.localeCompare(pe))},[u,Ne,xe]),re=o.useMemo(()=>Fa(Z),[Z]),ye=o.useMemo(()=>Fa(te),[te]),q=o.useCallback(V=>ye.get(Pn(V,"*"))?.action,[ye]),$=o.useCallback(V=>te.filter(le=>le.permission===V&&le.pattern!=="*").sort((le,pe)=>le.pattern.localeCompare(pe.pattern)),[te]),ee=o.useMemo(()=>{const V=new Set;for(const le of Do)V.add(le);for(const le of ne)V.add(le);return Array.from(V).sort((le,pe)=>le.localeCompare(pe))},[ne]),de=o.useCallback(V=>{const le=V==="*"?z:q(V)??z,pe=$(V),Le=!1,we=pe.reduce((X,j)=>(X[j.action]=(X[j.action]??0)+1,X),{allow:0,ask:0,deny:0}),He=["allow","ask","deny"].filter(X=>we[X]>0).map(X=>`${we[X]} ${X}`).join(", ");return{defaultAction:le,patternRulesCount:pe.length,patternSummary:He,hasDefaultHint:Le}},[$,q,z]),De=o.useCallback(V=>s(V==="allow"?"settings.common.permission.allow":V==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),ke=o.useCallback(V=>V==="global"?s("settings.common.scope.global"):De(V),[De,s]),Pe=o.useMemo(()=>{const V=new Set;for(const le of Do)V.add(le);for(const le of ne)V.add(le);return Array.from(V).sort((le,pe)=>le.localeCompare(pe))},[ne]),Me=o.useCallback((V,le,pe)=>{Y(Le=>{const we=Fa(Le);return we.set(Pn(V,le),{permission:V,pattern:le,action:pe}),Array.from(we.values())})},[]),Te=o.useCallback((V,le)=>{Y(pe=>{const Le=Fa(pe);return Le.delete(Pn(V,le)),Array.from(Le.values())})},[]),Ve=o.useCallback((V,le)=>{const pe=re.get(Pn(V,le));if(pe){Me(V,le,pe.action);return}Te(V,le)},[re,Te,Me]),Ue=o.useCallback((V,le,pe)=>{Me(V,le,pe)},[Me]),Oe=o.useCallback(V=>{T(V),Y(le=>le.filter(pe=>!(pe.pattern==="*"&&pe.action===V)))},[]),_e=o.useCallback(V=>{const le=N.trim();if(!le){_.error(s("settings.agents.page.toast.permissionNameRequired"));return}const pe=B.trim()||"*";if(le==="*"&&pe==="*"){Oe(V),W(""),F("*");return}pe==="*"&&le!=="*"&&V===z?Te(le,"*"):Me(le,pe,V),W(""),F("*")},[z,N,B,Te,Oe,s,Me]),Ke=o.useCallback(V=>V==="*"?s("settings.agents.page.permissions.defaultLabel"):V==="webfetch"?"WebFetch":V==="websearch"?"WebSearch":V==="codesearch"?"CodeSearch":V==="doom_loop"?"Doom Loop":V==="external_directory"?"External Directory":V==="todowrite"?"TodoWrite":V==="todoread"?"TodoRead":V.split(/[_-]+/g).filter(Boolean).map(le=>le.charAt(0).toUpperCase()+le.slice(1)).join(" "),[s]);o.useEffect(()=>{W(""),F("*");const V=le=>{const pe=jn(le),Le=Zp(pe),we=eg(pe,Le);return T(Le),G(we),Y(we),{global:Le,rules:we}};if(g&&c){const le=c.name||"",pe=c.scope||"user",Le=c.description||"",we=c.mode||"subagent",He=c.model||"",X=c.variant||"",j=c.temperature??void 0,be=c.top_p??void 0,Ae=c.prompt||"";b(le),f(pe),P(Le),C(we),k(He),w(X),K(j),M(be),A(Ae);const ze=Lr(c.permission),Ge=V(ze);oe.current={draftName:le,draftScope:pe,description:Le,mode:we,model:He,variant:X,temperature:j,topP:be,prompt:Ae,globalPermission:Ge.global,permissionRules:Ge.rules};return}if(m&&a===m.name){const le=m.description||"",pe=m.mode||"subagent",Le=m.model?.providerID&&m.model?.modelID?`${m.model.providerID}/${m.model.modelID}`:"",we=m.variant||"",He=m.temperature,X=m.topP,j=m.prompt||"";P(le),C(pe),k(Le),w(we),K(He),M(X),A(j);const be=V(Lr(m.permission));oe.current={draftName:"",draftScope:"user",description:le,mode:pe,model:Le,variant:we,temperature:He,topP:X,prompt:j,globalPermission:be.global,permissionRules:be.rules}}},[c,g,m,a]);const Qe=o.useMemo(()=>{const V=oe.current;return V?!!(g&&(d!==V.draftName||h!==V.draftScope)||y!==V.description||I!==V.mode||L!==V.model||v!==V.variant||E!==V.temperature||U!==V.topP||S!==V.prompt||z!==V.globalPermission||!Xp(te,V.permissionRules)):!1},[y,d,h,z,g,I,L,te,S,E,U,v]),Fe=async()=>{const V=g?d.trim().replace(/\s+/g,"-"):a?.trim();if(!V){_.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(g&&u.some(le=>le.name===V)){_.error(s("settings.agents.sidebar.toast.agentExists"));return}ie(!0);try{const le=L.trim(),pe=v.trim(),Le=S.trim(),we=tg(z,te),He={name:V,...y.trim()?{description:y.trim()}:{},mode:I,model:le===""?null:le,variant:pe===""?null:pe||void 0,temperature:E??null,top_p:U??null,prompt:Le||(g?void 0:null),permission:we,...g&&h?{scope:h}:{}};let X;g?(X=await i(He),X.ok&&x(null)):X=await l(V,He),X.ok?X.requiresManualRestart?_.warning(s("settings.agents.page.toast.savedManualRestart")):_.success(s(g?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):_.error(s(g?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(le){console.error("Error saving agent:",le);const pe=le instanceof Error&&le.message?le.message:s("settings.agents.page.toast.saveUnexpectedError");_.error(pe)}finally{ie(!1)}};return a?t.jsx(Ht,{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:g?s("settings.agents.page.title.new"):a}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(g?"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:[g&&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(Xe,{value:d,onChange:V=>b(V.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Pt,{value:h,onValueChange:V=>f(V),children:[t.jsx(At,{className:"w-fit min-w-[100px]",children:t.jsx(Lt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Dt,{align:"end",children:[t.jsx(ut,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ut,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{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(hs,{value:y,onChange:V=>P(V.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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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":I==="primary",onClick:()=>C("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":I==="subagent",onClick:()=>C("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":I==="all",onClick:()=>C("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(va,{providerId:xn(L)?.providerId??"",modelId:xn(L)?.modelId??"",onChange:(V,le)=>{k(V&&le?`${V}/${le}`:""),w("")}})})]}),t.jsxs("div",{"data-settings-item":"agents.variant",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:ve?t.jsxs(Pt,{value:ge,onValueChange:V=>w(V==="__default"?"":V),children:[t.jsx(At,{className:ce("max-w-full",e?"w-full":"w-fit min-w-[10rem]"),children:t.jsx(Lt,{placeholder:s("settings.agents.page.field.variantPlaceholder"),children:V=>V==="__default"?s("chat.modelControls.default"):V})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"__default",children:s("chat.modelControls.default")}),fe.map(V=>t.jsx(ut,{value:V,children:V},V))]})]}):t.jsxs(t.Fragment,{children:[t.jsx(Xe,{value:v,onChange:V=>w(V.target.value),placeholder:s("settings.agents.page.field.variantPlaceholder"),disabled:!L&&!v,className:ce("h-7 w-40",e&&"w-full")}),v&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>w(""),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(D,{name:"close",className:"h-3.5 w-3.5"})})]})})]}),t.jsxs("div",{"data-settings-item":"agents.temperature",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(bs,{value:E,fallbackValue:.7,onValueChange:K,onClear:()=>K(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),E!==void 0&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>K(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(D,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{"data-settings-item":"agents.top-p",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(bs,{value:U,fallbackValue:.9,onValueChange:M,onClear:()=>M(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),U!==void 0&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>M(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(D,{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(hs,{value:S,onChange:V=>A(V.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:()=>Q(V=>!V),children:s(O?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),O?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(Pt,{value:z,onValueChange:V=>Oe(V),children:[t.jsx(At,{className:"w-[100px]",children:t.jsx(Lt,{children:De(z)})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ut,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ut,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:ee.filter(V=>V!=="*").map(V=>{const le=Ke(V),{defaultAction:pe,patternRulesCount:Le}=de(V),we=q(V),He=we??"global",X=$(V),j=["allow","ask","deny"].filter(be=>be!==z);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:le}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:V})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Le>0?s("settings.agents.page.permissions.globalSummary",{summary:pe}):pe})]}),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:"*"}),we&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>Ve(V,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(D,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Pt,{value:He,onValueChange:be=>{if(be==="global"){Te(V,"*");return}Me(V,"*",be)},children:[t.jsx(At,{className:"w-[90px]",children:t.jsx(Lt,{children:ke(He)})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"global",children:s("settings.common.scope.global")}),j.map(be=>t.jsx(ut,{value:be,className:"capitalize",children:De(be)},be))]})]})]}),X.map(be=>{const Ae=Pn(be.permission,be.pattern),ze=re.get(Ae),Ge=!ze,rt=!!(ze&&ze.action!==be.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:be.pattern}),Ge&&t.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:s("settings.common.badge.new")}),rt&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:s("settings.common.badge.modified")}),(Ge||rt)&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>Ge?Te(be.permission,be.pattern):Ve(be.permission,be.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(D,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Pt,{value:be.action,onValueChange:it=>Ue(be.permission,be.pattern,it),children:[t.jsx(At,{className:"w-[90px]",children:t.jsx(Lt,{children:De(be.action)})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ut,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ut,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},Ae)})]})]},V)})}),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(Pt,{value:N,onValueChange:W,children:[t.jsx(At,{className:"w-full sm:w-[160px]",children:N?t.jsx("span",{className:"truncate",children:Ke(N)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Dt,{children:Pe.map(V=>t.jsx(ut,{value:V,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:Ke(V)})})},V))})]}),t.jsx(Xe,{value:B,onChange:V=>F(V.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:()=>_e("allow"),children:s("settings.common.permission.allow")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>_e("ask"),children:s("settings.common.permission.ask")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>_e("deny"),children:s("settings.common.permission.deny")})]})]})]})]}):t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ee.map((V,le)=>{const{defaultAction:pe,patternRulesCount:Le,patternSummary:we,hasDefaultHint:He}=de(V),X=Ke(V),j=He?`${pe} (env blocked)`:pe;return t.jsxs("div",{className:ce("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",le>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:X}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:V})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Le>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:j})}):t.jsx("span",{className:ce("typography-micro capitalize px-1.5 py-0.5 rounded",j==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":j==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:j}),Le>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:we})})]})]},V)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:Fe,disabled:H||!Qe,size:"xs",className:"!font-normal",children:s(H?"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(D,{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")})]})})},ag="~/.config/opencode/AGENTS.md",Sc=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},rg=s=>s.length>0&&!s.endsWith(`
2
+ `)?`${s}
3
+ `:s,La={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},ig=(s,e)=>s==="custom"?e:vu(s),og=s=>s==="custom"?"custom":ic(s)?s:"concise",Mo={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"},To=async(s,e)=>{const n=await dt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(s)});if(!n.ok)throw new Error(await Sc(n,e))},lg=()=>{const{t:s}=st(),[e,n]=o.useState(""),[a,r]=o.useState(La.responseStyleEnabled),[i,l]=o.useState(La.responseStylePreset),[u,c]=o.useState(La.responseStyleCustomInstructions),[x,m]=o.useState(!0),[g,d]=o.useState(!1),[b,h]=o.useState(""),f=o.useRef(null);o.useEffect(()=>{const C=new AbortController;return(async()=>{try{const[k,v]=await Promise.all([dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:C.signal}),dt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:C.signal})]);let w=La;if(k.ok){const E=await k.json();w={...w,responseStyleEnabled:E.responseStyleEnabled===!0,responseStylePreset:og(E.responseStylePreset),responseStyleCustomInstructions:typeof E.responseStyleCustomInstructions=="string"?E.responseStyleCustomInstructions:""},typeof E.globalBehaviorPrompt=="string"&&(w={...w,prompt:E.globalBehaviorPrompt})}if(!w.prompt.trim()&&v.ok){const E=await v.json();typeof E.content=="string"&&(w={...w,prompt:E.content})}n(w.prompt),r(w.responseStyleEnabled),l(w.responseStylePreset),c(w.responseStyleCustomInstructions),h(w.prompt),f.current={enabled:w.responseStyleEnabled,preset:w.responseStylePreset,custom:w.responseStyleCustomInstructions}}catch(k){k.name!=="AbortError"&&console.warn("Failed to load behavior settings:",k)}finally{m(!1)}})(),()=>C.abort()},[]),o.useEffect(()=>{if(x)return;const C=f.current;if(C&&C.enabled===a&&C.preset===i&&C.custom===u)return;const L={enabled:a,preset:i,custom:u},k=setTimeout(async()=>{try{await To({responseStyleEnabled:L.enabled,responseStylePreset:L.preset,responseStyleCustomInstructions:L.custom},s("settings.behavior.page.toast.saveFailed")),f.current=L}catch(v){const w=v instanceof Error?v.message:s("settings.behavior.page.toast.saveFailed");_.error(w)}},400);return()=>clearTimeout(k)},[a,i,u,x,s]);const y=ig(i,u),P=e!==b,I=async()=>{d(!0);try{const C=rg(e),L=await dt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:C})});if(!L.ok)throw new Error(await Sc(L,s("settings.behavior.page.toast.saveFailed")));await To({globalBehaviorPrompt:C},s("settings.behavior.page.toast.saveFailed")),n(C),h(C),_.success(s("settings.behavior.page.toast.saved"))}catch(C){console.error("Failed to save behavior:",C);const L=C instanceof Error?C.message:s("settings.behavior.page.toast.saveFailed");_.error(L)}finally{d(!1)}};return t.jsx(Ht,{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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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:ag})})]})})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsx(hs,{value:e,onChange:C=>n(C.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:I,disabled:g||!P||x,size:"xs",className:"!font-normal",children:s(g?"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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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(xt,{checked:a,onChange:r,disabled:x,ariaLabel:s("settings.behavior.page.responseStyle.enableAria")}),s("settings.behavior.page.responseStyle.enable")]}),t.jsxs(Pt,{value:i,onValueChange:C=>l(C),disabled:x||!a,children:[t.jsx(At,{className:"w-full sm:w-56",size:"lg",children:t.jsx(Lt,{children:C=>C==="custom"?s("settings.behavior.page.responseStyle.option.custom"):ic(C)?s(Mo[C]):null})}),t.jsxs(Dt,{children:[bu.map(C=>t.jsx(ut,{value:C,children:s(Mo[C])},C)),t.jsx(ut,{value:"custom",children:s("settings.behavior.page.responseStyle.option.custom")})]})]}),t.jsx(hs,{value:y,onChange:C=>c(C.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"})]})]})]})})},cg=s=>{const e=Ze.c(169),{onItemSelect:n}=s,{t:a}=st(),[r,i]=o.useState(null),[l,u]=o.useState(""),[c,x]=o.useState(null),[m,g]=o.useState(null),[d,b]=o.useState(!1),[h,f]=o.useState(null),{selectedCommandName:y,commands:P,setSelectedCommand:I,setCommandDraft:C,createCommand:L,deleteCommand:k,loadCommands:v}=mr(Ps(dg)),w=an(ug),E=an(mg);let K,U;e[0]!==v||e[1]!==E?(K=()=>{v(),E()},U=[v,E],e[0]=v,e[1]=E,e[2]=K,e[3]=U):(K=e[2],U=e[3]),o.useEffect(K,U);let M;e[4]!==w?(M=new Set(w.map(pg)),e[4]=w,e[5]=M):M=e[5];const S=M;let A;if(e[6]!==P||e[7]!==S){let me;e[9]!==S?(me=et=>!S.has(et.name),e[9]=S,e[10]=me):me=e[10],A=P.filter(me),e[6]=P,e[7]=S,e[8]=A}else A=e[8];const z=A;let T,Z;e[11]!==y||e[12]!==I||e[13]!==S?(T=()=>{y&&S.has(y)&&I(null)},Z=[y,I,S],e[11]=y,e[12]=I,e[13]=S,e[14]=T,e[15]=Z):(T=e[14],Z=e[15]),o.useEffect(T,Z);let G;e[16]!==P||e[17]!==n||e[18]!==C||e[19]!==I?(G=()=>{let me="new-command",et=1;for(;P.some(nt=>nt.name===me);)me=`new-command-${et}`,et++;C({name:me,scope:"user"}),I(me),n?.()},e[16]=P,e[17]=n,e[18]=C,e[19]=I,e[20]=G):G=e[20];const te=G;let Y;e[21]!==a?(Y=async me=>{if(qn(me)){_.error(a("settings.commands.sidebar.toast.builtInCannotDelete"));return}x(me),g("delete")},e[21]=a,e[22]=Y):Y=e[22];const N=Y;let W;e[23]===Symbol.for("react.memo_cache_sentinel")?(W=async me=>{qn(me)&&(x(me),g("reset"))},e[23]=W):W=e[23];const B=W;let F;e[24]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{x(null),g(null)},e[24]=F):F=e[24];const O=F;let Q;e[25]!==c||e[26]!==m||e[27]!==k||e[28]!==a?(Q=async()=>{if(!c||!m)return;b(!0),await k(c.name)?(m==="delete"?_.success(a("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):_.success(a("settings.commands.sidebar.toast.commandReset",{name:c.name})),O()):m==="delete"?_.error(a("settings.commands.sidebar.toast.deleteFailed")):_.error(a("settings.commands.sidebar.toast.resetFailed")),b(!1)},e[25]=c,e[26]=m,e[27]=k,e[28]=a,e[29]=Q):Q=e[29];const H=Q;let ie;e[30]!==P||e[31]!==C||e[32]!==I?(ie=me=>{const et=me.name;let nt=1,tt=`${et}-copy`;for(;P.some(ft=>ft.name===tt);)nt++,tt=`${et}-copy-${nt}`;C({name:tt,scope:me.scope||"user",description:me.description,template:me.template,agent:me.agent,model:me.model}),I(tt)},e[30]=P,e[31]=C,e[32]=I,e[33]=ie):ie=e[33];const oe=ie;let se;e[34]===Symbol.for("react.memo_cache_sentinel")?(se=me=>{u(me.name),i(me)},e[34]=se):se=e[34];const xe=se;let ae;e[35]!==P||e[36]!==L||e[37]!==k||e[38]!==r||e[39]!==l||e[40]!==I||e[41]!==a?(ae=async()=>{if(!r)return;const me=l.trim().replace(/\s+/g,"-");if(!me){_.error(a("settings.commands.sidebar.toast.commandNameRequired"));return}if(me===r.name){i(null);return}if(P.some(nt=>nt.name===me)){_.error(a("settings.commands.sidebar.toast.commandExists"));return}await L({name:me,description:r.description,template:r.template,agent:r.agent,model:r.model})?await k(r.name)?(_.success(`Command renamed to "${me}"`),I(me)):_.error(a("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):_.error(a("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=P,e[36]=L,e[37]=k,e[38]=r,e[39]=l,e[40]=I,e[41]=a,e[42]=ae):ae=e[42];const fe=ae;let Ce,ge,ve,Ne,ne,re;if(e[43]!==z||e[44]!==te||e[45]!==N||e[46]!==oe||e[47]!==n||e[48]!==h||e[49]!==y||e[50]!==I||e[51]!==a){const me=z.filter(qn),et=z.filter(gg);e[58]===Symbol.for("react.memo_cache_sentinel")?(ne=ce("flex h-full flex-col","bg-background"),e[58]=ne):ne=e[58];let nt;e[59]!==a?(nt=a("settings.commands.sidebar.title"),e[59]=a,e[60]=nt):nt=e[60];let tt;e[61]!==nt?(tt=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:nt}),e[61]=nt,e[62]=tt):tt=e[62];let ft;e[63]===Symbol.for("react.memo_cache_sentinel")?(ft=t.jsx(Na,{className:"mb-3"}),e[63]=ft):ft=e[63];let bt;e[64]!==z.length||e[65]!==a?(bt=a("settings.commands.sidebar.total",{count:z.length}),e[64]=z.length,e[65]=a,e[66]=bt):bt=e[66];let Rt;e[67]!==bt?(Rt=t.jsx("span",{className:"typography-meta text-muted-foreground",children:bt}),e[67]=bt,e[68]=Rt):Rt=e[68];let ue;e[69]===Symbol.for("react.memo_cache_sentinel")?(ue=t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[69]=ue):ue=e[69];let $e;e[70]!==te?($e=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:te,children:ue}),e[70]=te,e[71]=$e):$e=e[71];let Je;e[72]!==Rt||e[73]!==$e?(Je=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Rt,$e]}),e[72]=Rt,e[73]=$e,e[74]=Je):Je=e[74],e[75]!==tt||e[76]!==Je?(re=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[tt,ft,Je]}),e[75]=tt,e[76]=Je,e[77]=re):re=e[77],Ce=Ht,ge="flex-1 min-h-0",ve="space-y-1 px-3 py-2",Ne=z.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(D,{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:[me.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")}),[...me].sort(hg).map(qe=>t.jsx(Ro,{command:qe,isSelected:y===qe.name,onSelect:()=>{I(qe.name),n?.()},onReset:()=>B(qe),onDuplicate:()=>oe(qe),isMenuOpen:h===qe.name,onMenuOpenChange:yt=>f(yt?qe.name:null)},qe.name))]}),et.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")}),[...et].sort(fg).map(qe=>t.jsx(Ro,{command:qe,isSelected:y===qe.name,onSelect:()=>{I(qe.name),n?.()},onRename:()=>xe(qe),onDelete:()=>N(qe),onDuplicate:()=>oe(qe),isMenuOpen:h===qe.name,onMenuOpenChange:yt=>f(yt?qe.name:null)},qe.name))]})]}),e[43]=z,e[44]=te,e[45]=N,e[46]=oe,e[47]=n,e[48]=h,e[49]=y,e[50]=I,e[51]=a,e[52]=Ce,e[53]=ge,e[54]=ve,e[55]=Ne,e[56]=ne,e[57]=re}else Ce=e[52],ge=e[53],ve=e[54],Ne=e[55],ne=e[56],re=e[57];let ye;e[78]!==Ce||e[79]!==ge||e[80]!==ve||e[81]!==Ne?(ye=t.jsx(Ce,{outerClassName:ge,className:ve,children:Ne}),e[78]=Ce,e[79]=ge,e[80]=ve,e[81]=Ne,e[82]=ye):ye=e[82];const q=c!==null&&m!==null;let $;e[83]!==d?($=me=>{!me&&!d&&O()},e[83]=d,e[84]=$):$=e[84];let ee;e[85]!==m||e[86]!==a?(ee=a(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=a,e[87]=ee):ee=e[87];let de;e[88]!==ee?(de=t.jsx(Ot,{children:ee}),e[88]=ee,e[89]=de):de=e[89];let De;e[90]!==c?.name||e[91]!==m||e[92]!==a?(De=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]=De):De=e[93];let ke;e[94]!==De?(ke=t.jsx(Bt,{children:De}),e[94]=De,e[95]=ke):ke=e[95];let Pe;e[96]!==de||e[97]!==ke?(Pe=t.jsxs(zt,{children:[de,ke]}),e[96]=de,e[97]=ke,e[98]=Pe):Pe=e[98];let Me;e[99]!==a?(Me=a("settings.common.actions.cancel"),e[99]=a,e[100]=Me):Me=e[100];let Te;e[101]!==d||e[102]!==Me?(Te=t.jsx(J,{size:"sm",variant:"ghost",onClick:O,disabled:d,children:Me}),e[101]=d,e[102]=Me,e[103]=Te):Te=e[103];let Ve;e[104]!==m||e[105]!==a?(Ve=a(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=a,e[106]=Ve):Ve=e[106];let Ue;e[107]!==H||e[108]!==d||e[109]!==Ve?(Ue=t.jsx(J,{size:"sm",onClick:H,disabled:d,children:Ve}),e[107]=H,e[108]=d,e[109]=Ve,e[110]=Ue):Ue=e[110];let Oe;e[111]!==Te||e[112]!==Ue?(Oe=t.jsxs(qt,{children:[Te,Ue]}),e[111]=Te,e[112]=Ue,e[113]=Oe):Oe=e[113];let _e;e[114]!==Pe||e[115]!==Oe?(_e=t.jsxs(Tt,{className:"max-w-md",children:[Pe,Oe]}),e[114]=Pe,e[115]=Oe,e[116]=_e):_e=e[116];let Ke;e[117]!==q||e[118]!==$||e[119]!==_e?(Ke=t.jsx(Mt,{open:q,onOpenChange:$,children:_e}),e[117]=q,e[118]=$,e[119]=_e,e[120]=Ke):Ke=e[120];const Qe=r!==null;let Fe;e[121]===Symbol.for("react.memo_cache_sentinel")?(Fe=me=>!me&&i(null),e[121]=Fe):Fe=e[121];let V;e[122]!==a?(V=a("settings.commands.sidebar.renameDialog.title"),e[122]=a,e[123]=V):V=e[123];let le;e[124]!==V?(le=t.jsx(Ot,{children:V}),e[124]=V,e[125]=le):le=e[125];const pe=r?.name??"";let Le;e[126]!==a||e[127]!==pe?(Le=a("settings.commands.sidebar.renameDialog.description",{name:pe}),e[126]=a,e[127]=pe,e[128]=Le):Le=e[128];let we;e[129]!==Le?(we=t.jsx(Bt,{children:Le}),e[129]=Le,e[130]=we):we=e[130];let He;e[131]!==le||e[132]!==we?(He=t.jsxs(zt,{children:[le,we]}),e[131]=le,e[132]=we,e[133]=He):He=e[133];let X;e[134]===Symbol.for("react.memo_cache_sentinel")?(X=me=>u(me.target.value),e[134]=X):X=e[134];let j;e[135]!==a?(j=a("settings.commands.sidebar.renameDialog.placeholder"),e[135]=a,e[136]=j):j=e[136];let be;e[137]!==fe?(be=me=>{me.key==="Enter"&&fe()},e[137]=fe,e[138]=be):be=e[138];let Ae;e[139]!==l||e[140]!==j||e[141]!==be?(Ae=t.jsx(Xe,{value:l,onChange:X,placeholder:j,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:be}),e[139]=l,e[140]=j,e[141]=be,e[142]=Ae):Ae=e[142];let ze;e[143]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>i(null),e[143]=ze):ze=e[143];let Ge;e[144]!==a?(Ge=a("settings.common.actions.cancel"),e[144]=a,e[145]=Ge):Ge=e[145];let rt;e[146]!==Ge?(rt=t.jsx(J,{size:"sm",variant:"ghost",onClick:ze,children:Ge}),e[146]=Ge,e[147]=rt):rt=e[147];let it;e[148]!==a?(it=a("settings.common.actions.rename"),e[148]=a,e[149]=it):it=e[149];let at;e[150]!==fe||e[151]!==it?(at=t.jsx(J,{size:"sm",onClick:fe,children:it}),e[150]=fe,e[151]=it,e[152]=at):at=e[152];let lt;e[153]!==rt||e[154]!==at?(lt=t.jsxs(qt,{children:[rt,at]}),e[153]=rt,e[154]=at,e[155]=lt):lt=e[155];let Ye;e[156]!==He||e[157]!==Ae||e[158]!==lt?(Ye=t.jsxs(Tt,{children:[He,Ae,lt]}),e[156]=He,e[157]=Ae,e[158]=lt,e[159]=Ye):Ye=e[159];let We;e[160]!==Qe||e[161]!==Ye?(We=t.jsx(Mt,{open:Qe,onOpenChange:Fe,children:Ye}),e[160]=Qe,e[161]=Ye,e[162]=We):We=e[162];let gt;return e[163]!==ne||e[164]!==re||e[165]!==ye||e[166]!==Ke||e[167]!==We?(gt=t.jsxs("div",{className:ne,children:[re,ye,Ke,We]}),e[163]=ne,e[164]=re,e[165]=ye,e[166]=Ke,e[167]=We,e[168]=gt):gt=e[168],gt},Ro=s=>{const e=Ze.c(47),{command:n,isSelected:a,onSelect:r,onDelete:i,onReset:l,onRename:u,onDuplicate:c,isMenuOpen:x,onMenuOpenChange:m}=s,{t:g}=st();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=ba(),e[0]=d):d=e[0];const b=d,[h,f]=o.useState(!1);let y;e[1]!==i||e[2]!==c||e[3]!==u||e[4]!==l||e[5]!==g?(y=Y=>t.jsxs(t.Fragment,{children:[u&&t.jsxs(Y,{onClick:N=>{N.stopPropagation(),u()},children:[t.jsx(D,{name:"edit",className:"h-4 w-4 mr-px"}),g("settings.common.actions.rename")]}),t.jsxs(Y,{onClick:N=>{N.stopPropagation(),c()},children:[t.jsx(D,{name:"file-copy",className:"h-4 w-4 mr-px"}),g("settings.common.actions.duplicate")]}),l&&t.jsxs(Y,{onClick:N=>{N.stopPropagation(),l()},children:[t.jsx(D,{name:"restart",className:"h-4 w-4 mr-px"}),g("settings.common.actions.reset")]}),i&&t.jsxs(Y,{onClick:N=>{N.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),g("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=u,e[4]=l,e[5]=g,e[6]=y):y=e[6];const P=y,I=a?"bg-interactive-selection":"hover:bg-interactive-hover";let C;e[7]!==I?(C=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",I),e[7]=I,e[8]=C):C=e[8];let L;e[9]===Symbol.for("react.memo_cache_sentinel")?(L=b?void 0:Y=>{Y.preventDefault(),f(!0)},e[9]=L):L=e[9];let k;e[10]!==C?(k=t.jsx("div",{className:C,onContextMenu:L}),e[10]=C,e[11]=k):k=e[11];let v;e[12]!==n.name?(v=t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[12]=n.name,e[13]=v):v=e[13];let w;e[14]!==n||e[15]!==g?(w=(n.scope||qn(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:qn(n)?g("settings.agents.sidebar.badge.system"):n.scope}),e[14]=n,e[15]=g,e[16]=w):w=e[16];let E;e[17]!==v||e[18]!==w?(E=t.jsxs("div",{className:"flex items-center gap-2",children:[v,w]}),e[17]=v,e[18]=w,e[19]=E):E=e[19];let K;e[20]!==n.description?(K=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[20]=n.description,e[21]=K):K=e[21];let U;e[22]!==r||e[23]!==K||e[24]!==E?(U=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:[E,K]}),e[22]=r,e[23]=K,e[24]=E,e[25]=U):U=e[25];let M;e[26]!==m?(M=Y=>{Y&&f(!1),m(Y)},e[26]=m,e[27]=M):M=e[27];let S;e[28]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx(ms,{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(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=S):S=e[28];let A;e[29]!==P?(A=t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:P(Ns)}),e[29]=P,e[30]=A):A=e[30];let z;e[31]!==x||e[32]!==M||e[33]!==A?(z=t.jsxs(gs,{open:x,onOpenChange:M,children:[S,A]}),e[31]=x,e[32]=M,e[33]=A,e[34]=z):z=e[34];let T;e[35]!==U||e[36]!==z?(T=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[U,z]}),e[35]=U,e[36]=z,e[37]=T):T=e[37];let Z;e[38]!==T||e[39]!==k?(Z=t.jsx(bn,{render:k,children:T}),e[38]=T,e[39]=k,e[40]=Z):Z=e[40];let G;e[41]!==P?(G=t.jsx(vn,{className:"w-fit min-w-20",children:P(ln)}),e[41]=P,e[42]=G):G=e[42];let te;return e[43]!==h||e[44]!==Z||e[45]!==G?(te=t.jsxs(yn,{open:h,onOpenChange:f,children:[Z,G]}),e[43]=h,e[44]=Z,e[45]=G,e[46]=te):te=e[46],te};function dg(s){return{selectedCommandName:s.selectedCommandName,commands:s.commands,setSelectedCommand:s.setSelectedCommand,setCommandDraft:s.setCommandDraft,createCommand:s.createCommand,deleteCommand:s.deleteCommand,loadCommands:s.loadCommands}}function ug(s){return s.skills}function mg(s){return s.loadSkills}function pg(s){return s.name}function gg(s){return!qn(s)}function hg(s,e){return s.name.localeCompare(e.name)}function fg(s,e){return s.name.localeCompare(e.name)}const xg=()=>{const{t:s}=st(),{selectedCommandName:e,getCommandByName:n,createCommand:a,updateCommand:r,commands:i,commandDraft:l,setCommandDraft:u}=mr(Ps(M=>({selectedCommandName:M.selectedCommandName,getCommandByName:M.getCommandByName,createCommand:M.createCommand,updateCommand:M.updateCommand,commands:M.commands,commandDraft:M.commandDraft,setCommandDraft:M.setCommandDraft}))),c=e?n(e):null,x=!!(l&&l.name===e&&!c),[m,g]=o.useState(""),[d,b]=o.useState("user"),[h,f]=o.useState(""),[y,P]=o.useState(""),[I,C]=o.useState(""),[L,k]=o.useState(""),[v,w]=o.useState(!1),E=o.useRef(null);o.useEffect(()=>{if(x&&l){const M=l.name||"",S=l.scope||"user",A=l.description||"",z=l.agent||"",T=l.model||"",Z=l.template||"";g(M),b(S),f(A),P(z),C(T),k(Z),E.current={draftName:M,draftScope:S,description:A,agent:z,model:T,template:Z}}else if(c){const M=c.description||"",S=c.agent||"",A=c.model||"",z=c.template||"";f(M),P(S),C(A),k(z),E.current={draftName:"",draftScope:"user",description:M,agent:S,model:A,template:z}}},[c,x,e,i,l]);const K=o.useMemo(()=>{const M=E.current;return M?!!(x&&(m!==M.draftName||d!==M.draftScope)||h!==M.description||y!==M.agent||I!==M.model||L!==M.template):!1},[y,h,m,d,x,I,L]),U=async()=>{const M=x?m.trim().replace(/\s+/g,"-"):e?.trim();if(!M){_.error(s("settings.commands.sidebar.toast.commandNameRequired"));return}if(!L.trim()){_.error(s("settings.commands.page.toast.templateRequired"));return}if(x&&i.some(S=>S.name===M)){_.error(s("settings.commands.sidebar.toast.commandExists"));return}w(!0);try{const S=y.trim(),A=I.trim(),z=L.trim(),T={name:M,description:h.trim()||void 0,agent:S===""?null:S,model:A===""?null:A,template:z,scope:x?d:void 0};let Z;x?(Z=await a(T),Z&&u(null)):Z=await r(M,T),Z?_.success(s(x?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):_.error(s(x?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(S){console.error("Error saving command:",S),_.error(s("settings.commands.page.toast.saveUnexpectedError"))}finally{w(!1)}};return e?t.jsx(Ht,{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(Xe,{value:m,onChange:M=>g(M.target.value),placeholder:s("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Pt,{value:d,onValueChange:M=>b(M),children:[t.jsx(At,{className:"w-fit min-w-[100px]",children:t.jsx(Lt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Dt,{align:"end",children:[t.jsx(ut,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ut,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{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(hs,{value:h,onChange:M=>f(M.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(oc,{agentName:y,onChange:M=>P(M)})})]}),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(va,{providerId:xn(I)?.providerId??"",modelId:xn(I)?.modelId??"",onChange:(M,S)=>{C(M&&S?`${M}/${S}`:"")}})})]})]})]}),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(hs,{value:L,onChange:M=>k(M.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:U,disabled:v||!K,size:"xs",className:"!font-normal",children:s(v?"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(D,{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")})]})})},Fo=s=>{switch(s){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Lo=s=>{const e=Ze.c(5),{tone:n,enabled:a}=s;if(!a){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let r;e[1]!==n?(r=ce("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},yg=s=>{const e=Ze.c(120),{onItemSelect:n}=s,{t:a}=st(),{mcpServers:r,selectedMcpName:i,setSelectedMcp:l,setMcpDraft:u,loadMcpConfigs:c,deleteMcp:x}=Yn(Ps(bg)),m=ws(vg);let g;e[0]!==m?(g=we=>we.getStatusForDirectory(m??null),e[0]=m,e[1]=g):g=e[1];const d=os(g),b=os(jg),h=os(wg),[f,y]=o.useState(null),[P,I]=o.useState(!1),[C,L]=o.useState(null),[k,v]=o.useState(null),[w,E]=o.useState(!1);let K;e[2]!==r?(K=r.filter(Ng),e[2]=r,e[3]=K):K=e[3];const U=K;let M;e[4]!==r?(M=r.filter(kg),e[4]=r,e[5]=M):M=e[5];const S=M;let A,z;e[6]!==c?(A=()=>{c()},z=[c],e[6]=c,e[7]=A,e[8]=z):(A=e[7],z=e[8]),o.useEffect(A,z);let T;e[9]!==m||e[10]!==h||e[11]!==w||e[12]!==b?(T=()=>{if(w)return;E(!0);const we=new Promise(Sg);Promise.all([b({directory:m,silent:!0}),we]).then(()=>{const He=h(m);He&&_.error(He)}).finally(()=>{E(!1)})},e[9]=m,e[10]=h,e[11]=w,e[12]=b,e[13]=T):T=e[13];const Z=T;let G;e[14]!==r||e[15]!==n||e[16]!==u||e[17]!==l?(G=()=>{let we="new-mcp-server",He=1;for(;r.some(j=>j.name===we);)we=`new-mcp-server-${He}`,He++;u({name:we,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),l(we),n?.()},e[14]=r,e[15]=n,e[16]=u,e[17]=l,e[18]=G):G=e[18];const te=G;let Y;e[19]!==x||e[20]!==f||e[21]!==a?(Y=async()=>{if(!f)return;I(!0);const we=await x(f.name);we.ok?we.reloadFailed?_.warning(we.message||`MCP server "${f.name}" deleted, but OpenCode reload failed`,{description:we.warning||a("settings.mcp.sidebar.toast.refreshListIfStale")}):_.success(we.message||a("settings.mcp.sidebar.toast.serverDeleted",{name:f.name})):_.error(a("settings.mcp.sidebar.toast.deleteFailed")),y(null),I(!1)},e[19]=x,e[20]=f,e[21]=a,e[22]=Y):Y=e[22];const N=Y;let W;e[23]!==a?(W=(we,He)=>t.jsxs(He,{onClick:X=>{X.stopPropagation(),y(we)},className:"text-destructive focus:text-destructive",children:[t.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]}),e[23]=a,e[24]=W):W=e[24];const B=W;let F;e[25]===Symbol.for("react.memo_cache_sentinel")?(F=ce("flex h-full flex-col","bg-background"),e[25]=F):F=e[25];let O;e[26]!==a?(O=a("settings.mcp.sidebar.title"),e[26]=a,e[27]=O):O=e[27];let Q;e[28]!==O?(Q=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:O}),e[28]=O,e[29]=Q):Q=e[29];let H;e[30]!==a?(H=a("settings.mcp.sidebar.actions.refreshStatusAria"),e[30]=a,e[31]=H):H=e[31];let ie;e[32]!==a?(ie=a("settings.mcp.sidebar.actions.refreshStatusTitle"),e[32]=a,e[33]=ie):ie=e[33];const oe=w&&"animate-spin";let se;e[34]!==oe?(se=ce("h-4 w-4",oe),e[34]=oe,e[35]=se):se=e[35];let xe;e[36]!==se?(xe=t.jsx(D,{name:"refresh",className:se}),e[36]=se,e[37]=xe):xe=e[37];let ae;e[38]!==Z||e[39]!==w||e[40]!==H||e[41]!==ie||e[42]!==xe?(ae=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:w,onClick:Z,"aria-label":H,title:ie,children:xe}),e[38]=Z,e[39]=w,e[40]=H,e[41]=ie,e[42]=xe,e[43]=ae):ae=e[43];let fe;e[44]!==Q||e[45]!==ae?(fe=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[Q,ae]}),e[44]=Q,e[45]=ae,e[46]=fe):fe=e[46];let Ce;e[47]===Symbol.for("react.memo_cache_sentinel")?(Ce=t.jsx(Na,{className:"mb-3"}),e[47]=Ce):Ce=e[47];let ge;e[48]!==r.length||e[49]!==a?(ge=a("settings.mcp.sidebar.total",{count:r.length}),e[48]=r.length,e[49]=a,e[50]=ge):ge=e[50];let ve;e[51]!==ge?(ve=t.jsx("span",{className:"typography-meta text-muted-foreground",children:ge}),e[51]=ge,e[52]=ve):ve=e[52];let Ne;e[53]!==a?(Ne=a("settings.mcp.sidebar.actions.addServerTitle"),e[53]=a,e[54]=Ne):Ne=e[54];let ne;e[55]===Symbol.for("react.memo_cache_sentinel")?(ne=t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[55]=ne):ne=e[55];let re;e[56]!==te||e[57]!==Ne?(re=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:te,title:Ne,children:ne}),e[56]=te,e[57]=Ne,e[58]=re):re=e[58];let ye;e[59]!==ve||e[60]!==re?(ye=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ve,re]}),e[59]=ve,e[60]=re,e[61]=ye):ye=e[61];let q;e[62]!==fe||e[63]!==ye?(q=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[fe,Ce,ye]}),e[62]=fe,e[63]=ye,e[64]=q):q=e[64];let $;e[65]!==r.length||e[66]!==d||e[67]!==n||e[68]!==C||e[69]!==U||e[70]!==B||e[71]!==k||e[72]!==i||e[73]!==u||e[74]!==l||e[75]!==a||e[76]!==S?($=t.jsx(Ht,{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(D,{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:[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:a("settings.mcp.sidebar.group.projectServers")}),U.map(we=>{const He=d[we.name],X=Fo(He?.status),j=i===we.name,be=ba();return t.jsxs(yn,{open:k===we.name,onOpenChange:Ae=>v(Ae?we.name:null),children:[t.jsxs(bn,{render:t.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:be?void 0:Ae=>{Ae.preventDefault(),v(we.name)}}),children:[t.jsxs("button",{onClick:()=>{l(we.name),u(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(Lo,{tone:X,enabled:we.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:we.name}),t.jsx("span",{title:we.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:we.type==="local"?t.jsx(D,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(D,{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:we.type==="local"?we.command?.join(" ")??"":we.url??""})]}),t.jsxs(gs,{open:C===we.name,onOpenChange:Ae=>{Ae&&v(null),L(Ae?we.name:null)},children:[t.jsx(ms,{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(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:B(we,Ns)})]})]}),t.jsx(vn,{className:"w-fit min-w-20",children:B(we,ln)})]},we.name)})]}),S.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")}),S.map(we=>{const He=d[we.name],X=Fo(He?.status),j=i===we.name,be=ba();return t.jsxs(yn,{open:k===we.name,onOpenChange:Ae=>v(Ae?we.name:null),children:[t.jsxs(bn,{render:t.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:be?void 0:Ae=>{Ae.preventDefault(),v(we.name)}}),children:[t.jsxs("button",{onClick:()=>{l(we.name),u(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(Lo,{tone:X,enabled:we.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:we.name}),t.jsx("span",{title:we.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:we.type==="local"?t.jsx(D,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(D,{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:we.type==="local"?we.command?.join(" ")??"":we.url??""})]}),t.jsxs(gs,{open:C===we.name,onOpenChange:Ae=>{Ae&&v(null),L(Ae?we.name:null)},children:[t.jsx(ms,{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(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:B(we,Ns)})]})]}),t.jsx(vn,{className:"w-fit min-w-20",children:B(we,ln)})]},we.name)})]})]})}),e[65]=r.length,e[66]=d,e[67]=n,e[68]=C,e[69]=U,e[70]=B,e[71]=k,e[72]=i,e[73]=u,e[74]=l,e[75]=a,e[76]=S,e[77]=$):$=e[77];const ee=f!==null;let de;e[78]!==P?(de=we=>{!we&&!P&&y(null)},e[78]=P,e[79]=de):de=e[79];let De;e[80]!==a?(De=a("settings.mcp.sidebar.deleteDialog.title"),e[80]=a,e[81]=De):De=e[81];let ke;e[82]!==De?(ke=t.jsx(Ot,{children:De}),e[82]=De,e[83]=ke):ke=e[83];const Pe=f?.name||"";let Me;e[84]!==a||e[85]!==Pe?(Me=a("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Pe}),e[84]=a,e[85]=Pe,e[86]=Me):Me=e[86];let Te;e[87]===Symbol.for("react.memo_cache_sentinel")?(Te=t.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[87]=Te):Te=e[87];let Ve;e[88]!==Me?(Ve=t.jsxs(Bt,{children:[Me," ",Te,"."]}),e[88]=Me,e[89]=Ve):Ve=e[89];let Ue;e[90]!==ke||e[91]!==Ve?(Ue=t.jsxs(zt,{children:[ke,Ve]}),e[90]=ke,e[91]=Ve,e[92]=Ue):Ue=e[92];let Oe;e[93]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>y(null),e[93]=Oe):Oe=e[93];let _e;e[94]!==a?(_e=a("settings.common.actions.cancel"),e[94]=a,e[95]=_e):_e=e[95];let Ke;e[96]!==P||e[97]!==_e?(Ke=t.jsx(J,{size:"sm",variant:"ghost",onClick:Oe,disabled:P,children:_e}),e[96]=P,e[97]=_e,e[98]=Ke):Ke=e[98];let Qe;e[99]!==P||e[100]!==a?(Qe=a(P?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[99]=P,e[100]=a,e[101]=Qe):Qe=e[101];let Fe;e[102]!==N||e[103]!==P||e[104]!==Qe?(Fe=t.jsx(J,{size:"sm",onClick:N,disabled:P,children:Qe}),e[102]=N,e[103]=P,e[104]=Qe,e[105]=Fe):Fe=e[105];let V;e[106]!==Ke||e[107]!==Fe?(V=t.jsxs(qt,{children:[Ke,Fe]}),e[106]=Ke,e[107]=Fe,e[108]=V):V=e[108];let le;e[109]!==Ue||e[110]!==V?(le=t.jsxs(Tt,{className:"max-w-md",children:[Ue,V]}),e[109]=Ue,e[110]=V,e[111]=le):le=e[111];let pe;e[112]!==ee||e[113]!==de||e[114]!==le?(pe=t.jsx(Mt,{open:ee,onOpenChange:de,children:le}),e[112]=ee,e[113]=de,e[114]=le,e[115]=pe):pe=e[115];let Le;return e[116]!==q||e[117]!==$||e[118]!==pe?(Le=t.jsxs("div",{className:F,children:[q,$,pe]}),e[116]=q,e[117]=$,e[118]=pe,e[119]=Le):Le=e[119],Le};function bg(s){return{mcpServers:s.mcpServers,selectedMcpName:s.selectedMcpName,setSelectedMcp:s.setSelectedMcp,setMcpDraft:s.setMcpDraft,loadMcpConfigs:s.loadMcpConfigs,deleteMcp:s.deleteMcp}}function vg(s){return s.currentDirectory}function jg(s){return s.refresh}function wg(s){return s.getErrorForDirectory}function Ng(s){return s.scope==="project"}function kg(s){return s.scope!=="project"}function Sg(s){return setTimeout(s,500)}function Gs(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function da(s){return Array.isArray(s)&&s.every(e=>typeof e=="string")}function Hs(s,e){return e!==void 0?{ok:!1,error:s,parsed:e}:{ok:!1,error:s}}function Oa(s,e,n){const a=Cg(n),r=typeof n.url=="string"?n.url.trim():"",i=Oo(n,"env","environment"),l=Oo(n,"headers"),u=Ig(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():"",g=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",d=Pg(n),b=Ag(n);return{ok:!0,name:s,type:e,command:a,url:r,environment:i,headers:l,oauthEnabled:u,oauthClientId:c,oauthClientSecret:x,oauthScope:m,oauthRedirectUri:g,timeout:d,enabled:b}}function Cg(s){const e=s.command,n=s.args;if(da(e)&&da(n))return[...e,...n];if(da(e))return e;if(typeof e=="string"&&e.trim()){const a=e.trim().split(/\s+/);return da(n)?[...a,...n]:a}return da(n)?n:[]}function Oo(s,...e){for(const n of e){const a=s[n];if(!Gs(a))continue;const r=Object.entries(a).filter(([i,l])=>i&&typeof l=="string");if(r.length>0)return r.map(([i,l])=>({key:i,value:String(l)}))}return[]}function Ig(s){if(s.oauth===!1||s.oauth===null||s.oauth===void 0||!Gs(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 Pg(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 Ag(s){return"disabled"in s&&s.disabled===!0?!1:"enabled"in s?!!s.enabled:!0}function Dg(s){const e=s.mcpServers;if(Gs(e)){const a=Object.keys(e);if(a.length===1){const r=a[0],i=e[r];if(Gs(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"&&Gs(r)});if(n.length===1){const a=n[0],r=s[a];if(Cc(r))return{name:a,entry:r}}return null}function Cc(s){return s.type==="local"||s.type==="remote"||Array.isArray(s.command)||typeof s.url=="string"||Array.isArray(s.args)}function Eg(s,e){let n;try{const u=s.trim();if(!u)return Hs("No JSON content provided");n=JSON.parse(u)}catch(u){return Hs(u instanceof Error?`Invalid JSON: ${u.message}`:"Invalid JSON")}if(!Gs(n))return Hs("Expected a JSON object, not an array or primitive");const a=n,r=a.mcpServers;if(Gs(r)){const u=Object.keys(r);if(u.length===0)return Hs("mcpServers object is empty",n);if(u.length>1)return Hs("Paste one server at a time. Found "+u.length+" servers in mcpServers",n);const c=u[0],x=r[c];return Gs(x)?Oa(c,za(x),x):Hs("Server entry is not a valid object",n)}const i=a.mcp;if(Gs(i)){const u=Object.keys(i);if(u.length===0)return Hs("mcp object is empty",n);if(u.length>1)return Hs("Paste one server at a time. Found "+u.length+" servers in mcp",n);const c=u[0],x=i[c];return Gs(x)?Oa(c,za(x),x):Hs("Server entry in mcp is not a valid object",n)}const l=Dg(a);if(l)return Oa(l.name,za(l.entry),l.entry);if(Cc(a)){const u=za(a),c=typeof a.name=="string"&&a.name.trim()?a.name.trim():e?.fallbackName;return Oa(c,u,a)}return Hs("No recognizable MCP server configuration found in JSON",n)}function za(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 Mg(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 Tg="/mcp/oauth/callback",Rg=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}},Fg=s=>{const e=Lg(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}},Ic=s=>{const e=s.get("state");return typeof e!="string"?null:e.trim()||null},Lg=s=>{if(typeof s!="string"||!s.trim())return null;const e=Rg(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}},En=vd,Mn=s=>{const e=Ze.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 l;e[5]!==n||e[6]!==a?(l=n&&he.isValidElement(a)?{render:a}:{children:a},e[5]=n,e[6]=a,e[7]=l):l=e[7];const u=l;let c;e[8]!==r?(c=ce("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]!==u||e[12]!==c?(x=t.jsx(bd,{className:c,...i,...u}),e[10]=i,e[11]=u,e[12]=c,e[13]=x):x=e[13],x},Tn=s=>{const e=Ze.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=ce("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(jd,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i};function Og(s){const e=[];let n="",a=!1,r=!1;for(let i=0;i<s.length;i++){const l=s[i];if(l==="'"&&!r){a=!a;continue}if(l==='"'&&!a){r=!r;continue}if((l===" "||l===" ")&&!a&&!r){n&&(e.push(n),n="");continue}n+=l}return n&&e.push(n),e}function zg(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:Fg(n.searchParams),stateKey:Ic(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Kg=({value:s,onChange:e,pasteCommandTitle:n,pasteCommandLabel:a,pasteSuccess:r,clipboardReadFailed:i,preview:l})=>{const[u,c]=o.useState(()=>s.join(`
4
+ `)),x=o.useRef(s);o.useEffect(()=>{JSON.stringify(x.current)!==JSON.stringify(s)&&(x.current=s,c(s.join(`
5
+ `)))},[s]);const m=d=>{const b=d.split(`
6
+ `).filter(h=>h.trim().length>0);e(b)},g=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),h=b.includes(`
7
+ `)?b.split(`
8
+ `).filter(f=>f.trim()):Og(b);c(h.join(`
9
+ `)),e(h),_.success(r(h.length))}catch{_.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:g,type:"button",title:n,children:[t.jsx(D,{name:"clipboard",className:"h-3 w-3"}),a]})}),t.jsx(hs,{value:u,onChange:d=>{c(d.target.value),m(d.target.value)},onBlur:()=>{const d=u.split(`
10
+ `).map(b=>b.trimEnd()).join(`
11
+ `);c(d),m(d)},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:l(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((d,b)=>t.jsxs("span",{className:"block",children:[t.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),d]},b))})})]})]})},Ug=s=>s.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),zo=({value:s,onChange:e,keyTransform:n=Ug,keyPlaceholder:a="API_KEY",keyInputClassName:r="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:u,importSuccess:c,clipboardReadFailed:x,keyLabel:m,valueLabel:g,valuePlaceholder:d,hideValueTitle:b,showValueTitle:h,addVariable:f,plainTextWarning:y,removeVariableAria:P})=>{const[I,C]=o.useState(new Set),L=()=>e([...s,{key:"",value:""}]),k=U=>{e(s.filter((M,S)=>S!==U)),C(M=>{const S=new Set(M);return S.delete(U),S})},v=(U,M,S)=>{const A=[...s];A[U]={...A[U],[M]:S},e(A)},w=U=>{C(M=>{const S=new Set(M);return S.has(U)?S.delete(U):S.add(U),S})},E=async()=>{try{const U=await navigator.clipboard.readText(),M=[];for(const A of U.split(`
15
+ `)){const z=A.trim();if(!z||z.startsWith("#"))continue;const T=z.indexOf("=");if(T===-1)continue;const Z=z.slice(0,T).trim();let G=z.slice(T+1).trim();(G.startsWith('"')&&G.endsWith('"')||G.startsWith("'")&&G.endsWith("'"))&&(G=G.slice(1,-1)),Z&&M.push({key:Z,value:G})}if(M.length===0){_.error(u);return}const S=[...s];for(const A of M){const z=S.findIndex(T=>T.key===A.key);z!==-1?S[z]=A:S.push(A)}e(S),_.success(c(M.length))}catch{_.error(x)}},K=s.some(U=>U.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:g})]}),t.jsxs(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:E,type:"button",title:l,children:[t.jsx(D,{name:"clipboard",className:"h-3 w-3"}),i]})]}),t.jsx("div",{className:"space-y-1.5",children:s.map((U,M)=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xe,{value:U.key,onChange:S=>v(M,"key",n(S.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(Xe,{type:I.has(M)?"text":"password",value:U.value,onChange:S=>v(M,"value",S.target.value),placeholder:d,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:()=>w(M),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:I.has(M)?b:h,children:I.has(M)?t.jsx(D,{name:"eye-off",className:"h-3.5 w-3.5"}):t.jsx(D,{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:()=>k(M),"aria-label":P,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},M))}),t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:L,type:"button",children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),f]}),K&&t.jsx("p",{className:"typography-micro text-muted-foreground/60",children:y})]})},Ko=s=>{const e=Ze.c(14),{status:n,enabled:a,getStatusLabel:r,variant:i}=s,l=i===void 0?"compact":i;if(!a||!n)return null;let u,c;if(e[0]!==r||e[1]!==n||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const d={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(l==="pill"){const b=ce("typography-micro font-medium rounded-full px-2 py-0.5",d.text,d.bg);let h;e[5]!==r||e[6]!==n?(h=r(n),e[5]=r,e[6]=n,e[7]=h):h=e[7],c=t.jsxs("span",{className:b,children:["● ",h]});break e}u=ce("typography-micro font-medium",d.text)}e[0]=r,e[1]=n,e[2]=l,e[3]=u,e[4]=c}else u=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]!==u||e[12]!==x?(m=t.jsxs("span",{className:u,children:["● ",x]}),e[11]=u,e[12]=x,e[13]=m):m=e[13],m},Bg=(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")}},$g=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)]"}},Vg=(s,e,n,a)=>!!(s==="failed"||s==="needs_auth"||s==="needs_client_registration"||e||n||a),Uo=(s,e)=>{if(typeof window>"u")return null;const n=new URL(Tg,ea()||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()},_g=async s=>{const e=await dt("/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")}},Hg=async s=>{const e=await dt(`/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},ua=async s=>{typeof s!="string"||!s.trim()||await dt(`/api/mcp/auth/pending?state=${encodeURIComponent(s.trim())}`,{method:"DELETE"}).catch(()=>{})},Or=(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},Wg=(s,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${s??"__none__"}::${n}`},Gg=()=>{const{t:s}=st(),e=o.useCallback((Se,vt)=>s(Se,vt),[s]),{selectedMcpName:n,mcpServers:a,mcpDraft:r,setMcpDraft:i,setSelectedMcp:l,getMcpByName:u,createMcp:c,updateMcp:x,deleteMcp:m}=Yn(Ps(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}))),g=ws(Se=>Se.currentDirectory),d=o.useMemo(()=>rs(),[]),b=os(Se=>Se.getStatusForDirectory(g??null)),h=os(Se=>Se.getDiagnosticForDirectory(g??null)),f=os(Se=>Se.refresh),y=os(Se=>Se.connect),P=os(Se=>Se.disconnect),I=os(Se=>Se.startAuth),C=os(Se=>Se.completeAuth),L=os(Se=>Se.clearAuth),k=os(Se=>Se.testConnection),v=n?u(n):null,w=!!(r&&r.name===n&&!v),[E,K]=o.useState(""),[U,M]=o.useState("user"),[S,A]=o.useState("local"),[z,T]=o.useState([]),[Z,G]=o.useState(""),[te,Y]=o.useState([]),[N,W]=o.useState([]),[B,F]=o.useState(!0),[O,Q]=o.useState(""),[H,ie]=o.useState(""),[oe,se]=o.useState(""),[xe,ae]=o.useState(""),[fe,Ce]=o.useState(""),[ge,ve]=o.useState(!0),[Ne,ne]=o.useState(!1),[re,ye]=o.useState(!1),[q,$]=o.useState(!1),[ee,de]=o.useState(!1),[De,ke]=o.useState(!1),[Pe,Me]=o.useState(!1),[Te,Ve]=o.useState(!1),[Ue,Oe]=o.useState(!1),[_e,Ke]=o.useState(null),[Qe,Fe]=o.useState(null),[V,le]=o.useState(""),[pe,Le]=o.useState(!1),we=o.useRef(0),He=o.useRef(!1),[X,j]=o.useState(!1),[be,Ae]=o.useState(!1),[ze,Ge]=o.useState(""),[rt,it]=o.useState(null),at=o.useMemo(()=>Wg(n,g),[g,n]),lt=o.useRef(at),Ye=o.useRef(null),We=o.useCallback(()=>{Ke(null),Fe(null),le(""),Le(!1),we.current=0,Oe(!1),ke(!1),Me(!1),He.current=!1},[]),gt=o.useCallback(()=>{Ge(""),it(null),Ae(!0)},[]),me=o.useCallback(async()=>{try{const Se=await navigator.clipboard.readText();Ge(Se),it(null)}catch{_.error(s("settings.mcp.page.toast.clipboardReadFailed"))}},[s]),et=o.useCallback(()=>{const Se=Eg(ze,{fallbackName:E});if(!Se.ok){it(Se.error);return}const jt=Mg(Se,{name:E,scope:U,type:S,command:z,url:Z,environment:te,headers:N,oauthEnabled:B,oauthClientId:O,oauthClientSecret:H,oauthScope:oe,oauthRedirectUri:xe,timeout:fe,enabled:ge},{isNewServer:w});K(jt.name),A(jt.type),T(jt.command??[]),G(jt.url??""),Y(jt.environment??[]),W(jt.headers??[]),F(jt.oauthEnabled??!1),Q(jt.oauthClientId??""),ie(jt.oauthClientSecret??""),se(jt.oauthScope??""),ae(jt.oauthRedirectUri??""),Ce(jt.timeout??""),ve(jt.enabled??!0),Ae(!1),Ge(""),it(null),_.success(s("settings.mcp.page.toast.configImported"))},[ze,E,U,S,z,Z,te,N,B,O,H,oe,xe,fe,ge,w,s]);o.useEffect(()=>{if(w&&r){K(r.name),M(r.scope||"user"),A(r.type),T(r.command),G(r.url),Y(r.environment),W(r.headers),F(r.oauthEnabled),Q(r.oauthClientId),ie(r.oauthClientSecret),se(r.oauthScope),ae(r.oauthRedirectUri),Ce(r.timeout),ve(r.enabled),j(!1),Ye.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(v){M(v.scope==="project"?"project":"user");const Se=yo(v.environment),vt=v.type==="remote"?v:null,jt=yo(vt?.headers),Wt=vt?.oauth,Gt=Wt&&typeof Wt=="object"?Wt:null,$t=Wt!==!1,fs=v.type,ks=fs==="local"?v.command??[]:[],Qt=fs==="remote"?v.url??"":"",Ts=typeof vt?.timeout=="number"&&Number.isFinite(vt.timeout)?String(vt.timeout):"";A(fs),T(ks),G(Qt),Y(Se),W(jt),F($t),Q($t?Gt?.clientId??"":""),ie($t?Gt?.clientSecret??"":""),se($t?Gt?.scope??"":""),ae($t?Gt?.redirectUri??"":""),Ce(Ts),ve(v.enabled),j(!1),Ye.current={mcpType:fs,command:ks,url:Qt,envEntries:Se,headerEntries:jt,oauthEnabled:$t,oauthClientId:$t?Gt?.clientId??"":"",oauthClientSecret:$t?Gt?.clientSecret??"":"",oauthScope:$t?Gt?.scope??"":"",oauthRedirectUri:$t?Gt?.redirectUri??"":"",timeout:Ts,enabled:v.enabled}}},[v,w,r]);const nt=o.useMemo(()=>{const Se=Ye.current;return Se?S!==Se.mcpType||ge!==Se.enabled||JSON.stringify(z)!==JSON.stringify(Se.command)||Z!==Se.url||JSON.stringify(te)!==JSON.stringify(Se.envEntries)||JSON.stringify(N)!==JSON.stringify(Se.headerEntries)||B!==Se.oauthEnabled||O!==Se.oauthClientId||H!==Se.oauthClientSecret||oe!==Se.oauthScope||xe!==Se.oauthRedirectUri||fe!==Se.timeout:!1},[S,z,Z,te,N,B,O,H,oe,xe,fe,ge]),tt=async()=>{const Se=w?E.trim():n??"";if(!Se){_.error(s("settings.mcp.page.toast.nameRequired"));return}if(w&&a.some(jt=>jt.name===Se)){_.error(s("settings.mcp.page.toast.serverNameExists"));return}if(S==="local"&&z.filter(Boolean).length===0){_.error(s("settings.mcp.page.toast.localCommandRequired"));return}if(S==="remote"&&!Z.trim()){_.error(s("settings.mcp.page.toast.remoteUrlRequired"));return}const vt={name:Se,scope:U,type:S,command:z,url:Z,environment:te,headers:N,oauthEnabled:B,oauthClientId:O,oauthClientSecret:H,oauthScope:oe,oauthRedirectUri:xe,timeout:fe,enabled:ge};ne(!0);try{const jt=w?await c(vt):await x(Se,vt);jt.ok?(await ua(Qe),We(),w&&(i(null),l(Se)),await f({directory:g,silent:!0}),jt.reloadFailed?_.warning(jt.message||s(w?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:jt.warning||s("settings.mcp.page.toast.retryRefreshHint")}):_.success(jt.message||s(w?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):_.error(s("settings.mcp.page.toast.saveFailed"))}catch(jt){_.error(jt instanceof Error?jt.message:s("settings.mcp.page.toast.unexpectedError"))}finally{ne(!1)}},ft=async()=>{if(!n)return;$(!0);const Se=await m(n);Se.ok?(await ua(Qe),We(),Se.reloadFailed?_.warning(Se.message||s("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Se.warning||s("settings.mcp.page.toast.refreshListIfStale")}):_.success(Se.message||s("settings.mcp.page.toast.serverDeleted",{name:n})),ye(!1)):_.error(s("settings.mcp.page.toast.deleteFailed")),$(!1)},bt=async()=>{if(n){de(!0);try{if(b[n]?.status==="connected")await P(n,g),_.success(s("settings.mcp.page.toast.disconnected"));else{await y(n,g),await f({directory:g,silent:!0});const vt=os.getState().getStatusForDirectory(g??null)[n];vt?.status==="connected"?_.success(s("settings.mcp.page.toast.connected")):vt?.status==="needs_auth"?_.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):vt?.status==="needs_client_registration"?_.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):vt?.status==="failed"?_.error(vt.error||s("settings.mcp.page.toast.connectionFailed")):_.message(s("settings.mcp.page.toast.connectionAttemptFinished"));return}await f({directory:g,silent:!0})}catch(Se){_.error(Se instanceof Error?Se.message:s("settings.mcp.page.toast.connectionFailed"))}finally{de(!1)}}},Rt=o.useCallback(()=>w?(_.error(s("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):nt?(_.error(s("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[nt,w,s]),ue=o.useCallback(async(Se=!1)=>{try{await f({directory:g,silent:Se})}catch(vt){Se||_.error(vt instanceof Error?vt.message:s("settings.mcp.page.toast.refreshStatusFailed"))}},[g,f,s]);o.useEffect(()=>{ue(!0)},[ue]),o.useEffect(()=>{lt.current=at,de(!1),Ve(!1),We()},[We,at]);const $e=o.useCallback(async()=>{if(!n||S!=="remote"||!Rt())return;ke(!0);const Se=at;let vt=null;try{const jt=os.getState().getStatusForDirectory(g??null)[n]?.status;He.current=jt==="needs_auth"||jt==="needs_client_registration";const Wt=Uo(n,g);if(!Wt)throw new Error(s("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!xe.trim()&&!d){const ks=await x(n,{oauthEnabled:B,oauthClientId:O,oauthClientSecret:H,oauthScope:oe,oauthRedirectUri:Wt});if(!ks.ok)throw new Error(s("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(ks.reloadFailed)throw new Error(ks.warning||ks.message||s("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(lt.current!==Se)return;ae(Wt),Ye.current=Ye.current?{...Ye.current,oauthRedirectUri:Wt}:Ye.current}const Gt=await I(n,g),$t=Ic(new URL(Gt).searchParams);if($t&&(vt=$t,await _g({state:$t,name:n,directory:g})),lt.current!==Se)return;Ke(Gt),Fe($t??null),Le(!0),we.current=0;const fs=await on(Gt);if(lt.current!==Se)return;fs?_.message(s(d?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):_.error(s("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(jt){await ua(vt),lt.current===Se&&_.error(Or(jt,s("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{lt.current===Se&&ke(!1)}},[g,d,S,O,H,B,xe,oe,Rt,at,n,I,s,e,x]),Je=o.useCallback(async()=>{if(!n||!Rt())return;Me(!0);const Se=at;try{if(await L(n,g),lt.current!==Se)return;Ke(null),Fe(null),le(""),Le(!1),we.current=0,await ua(Qe),_.success(s("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(vt){lt.current===Se&&_.error(Or(vt,s("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{lt.current===Se&&Me(!1)}},[Qe,L,g,Rt,at,n,s,e]),qe=o.useCallback(async()=>{if(!_e)return;if((await Dn(_e)).ok){_.success(s("settings.mcp.page.toast.authorizationUrlCopied"));return}_.error(s("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[_e,s]),yt=o.useCallback(async()=>{const Se=zg(V);if(!Se.code){_.error(s("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const vt=Se.stateKey?await Hg(Se.stateKey):null,jt=Se.context??vt,Wt=jt?.name??n,Gt=jt?.directory??g;if(!Wt){_.error(s("settings.mcp.page.toast.missingServerDetails"));return}if(!jt&&!Rt())return;Oe(!0);const $t=at;try{if(await C(Wt,Se.code,Gt),await ua(Se.stateKey??Qe),lt.current!==$t)return;le(""),Ke(null),Fe(null),Le(!1),we.current=0,_.success(Wt===n?s("settings.mcp.page.toast.authorizationCompleted"):s("settings.mcp.page.toast.authorizationCompletedFor",{name:Wt}))}catch(fs){lt.current===$t&&_.error(Or(fs,s("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{lt.current===$t&&Oe(!1)}},[V,Qe,C,g,Rt,at,n,s,e]),kt=o.useCallback(async()=>{if(!(!n||!Rt())){if(!ge){_.error(s("settings.mcp.page.toast.enableServerBeforeTest"));return}Ve(!0);try{const Se=await k(n,g),vt=Se.status?.status;Se.warning?_.warning(Se.warning):vt==="connected"?_.success(s("settings.mcp.page.toast.connectionTestSucceeded")):vt==="needs_auth"?_.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):vt==="needs_client_registration"?_.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):vt==="failed"?_.error(Se.status?.error||Se.error||s("settings.mcp.page.toast.connectionTestFailed")):Se.error?_.error(Se.error):_.message(s("settings.mcp.page.toast.connectionTestFinished"))}catch(Se){_.error(Se instanceof Error?Se.message:s("settings.mcp.page.toast.connectionTestFailed"))}finally{Ve(!1)}}},[g,ge,Rt,n,s,k]);if(o.useEffect(()=>{if(!pe||!n)return;const Se=window.setInterval(()=>{(async()=>{we.current+=1,await f({directory:g,silent:!0});const vt=os.getState().getStatusForDirectory(g??null)[n];if(vt){if(He.current&&vt.status!=="needs_auth"&&vt.status!=="needs_client_registration"){Le(!1),we.current=0,He.current=!1,Ke(null),le(""),vt.status==="connected"&&_.success(s("settings.mcp.page.toast.authorizationCompleted"));return}if(!He.current&&vt.status==="failed"){Le(!1),we.current=0,He.current=!1,_.error(vt.error||s("settings.mcp.page.toast.authorizationFailed"));return}we.current>=30&&(Le(!1),we.current=0,He.current=!1,_.message(s("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Se)}},[g,pe,f,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(D,{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 ht=b[n],Et=n?h[n]:void 0,Jt=ht??Et,Zt=ht?.status==="connected",cs=ht?.status==="needs_auth"||ht?.status==="needs_client_registration",is=d?null:Uo(n,g),ts=Bg(Jt?.status,e,Jt&&"error"in Jt?Jt.error:void 0),As=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(Ht,{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:[w?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(Ko,{status:Jt?.status,enabled:ge,getStatusLabel:As,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:w?s("settings.mcp.page.header.configureNewServer"):s("settings.mcp.page.header.transport",{type:s(S==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!w&&t.jsxs(t.Fragment,{children:[t.jsx(J,{variant:Zt?"outline":"default",size:"xs",className:"!font-normal",onClick:bt,disabled:ee||!ge,children:s(ee?"settings.mcp.page.actions.working":Zt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),S==="remote"&&t.jsxs(t.Fragment,{children:[t.jsx(J,{variant:cs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{$e()},disabled:De||!ge,children:s(De?"settings.mcp.page.actions.starting":cs?"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:()=>{Je()},disabled:Pe||!ge,children:s(Pe?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Zt&&t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{kt()},disabled:Te||!ge,children:s(Te?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!w&&Vg(Jt?.status,_e,cs,pe)&&t.jsx("div",{className:"mb-6 px-2",children:t.jsxs("div",{className:ce("rounded-lg border p-3",$g(Jt?.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(Ko,{status:Jt?.status,enabled:ge,getStatusLabel:As})]}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:ts}),t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:U==="project"?s("settings.mcp.page.status.projectScopedTo",{directory:g??s("settings.mcp.page.status.activeProject")}):s("settings.mcp.page.status.userScoped")})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Zt&&t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{kt()},disabled:Te||!ge,children:s(Te?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),_e&&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:_e}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{on(_e)},children:[t.jsx(D,{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:()=>{qe()},children:[t.jsx(D,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.actions.copyLink")]})]})]})}),S==="remote"&&(cs||pe||_e)&&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(hs,{value:V,onChange:Se=>le(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:()=>{yt()},disabled:Ue,children:s(Ue?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),pe&&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:[w&&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(Xe,{value:E,onChange:Se=>K(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(Pt,{value:U,onValueChange:Se=>M(Se),children:[t.jsx(At,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:s(U==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:U==="user"?t.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"folder",className:"h-3.5 w-3.5"})}),t.jsxs(Dt,{align:"end",children:[t.jsx(ut,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ut,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),w&&t.jsx("div",{className:"py-1.5",children:t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:gt,type:"button",title:s("settings.mcp.page.server.importJsonTitle"),children:[t.jsx(D,{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":ge,onClick:()=>ve(!ge),onKeyDown:Se=>{(Se.key===" "||Se.key==="Enter")&&(Se.preventDefault(),ve(!ge))},children:[t.jsx(xt,{checked:ge,onChange:ve,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":S==="local",onClick:()=>A("local"),className:"!font-normal",children:s("settings.mcp.page.transport.local")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":S==="remote",onClick:()=>A("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(S==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:S==="local"?t.jsx(Kg,{value:z,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(Xe,{value:Z,onChange:Se=>G(Se.target.value),placeholder:s("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),S==="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(En,{open:X,onOpenChange:j,children:[t.jsxs(Mn,{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(B?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",N.length," ",s("settings.mcp.page.advanced.headers"),fe?` · ${fe}ms`:"",")"]})]}),X?t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(Tn,{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(Xe,{type:"number",min:"1",step:"1",value:fe,onChange:Se=>Ce(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"),N.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",N.length,")"]})]}),t.jsx(zo,{value:N,onChange:W,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":B,onClick:()=>F(!B),onKeyDown:Se=>{(Se.key===" "||Se.key==="Enter")&&(Se.preventDefault(),F(!B))},children:[t.jsx(xt,{checked:B,onChange:F,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(Xe,{value:O,onChange:Se=>Q(Se.target.value),placeholder:s("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(Xe,{value:H,onChange:Se=>ie(Se.target.value),placeholder:s("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(Xe,{value:oe,onChange:Se=>se(Se.target.value),placeholder:s("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(Xe,{value:xe,onChange:Se=>ae(Se.target.value),placeholder:s("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:s("settings.mcp.page.advanced.oauthHint")}),is&&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:is})]})]})]})})]})})]}),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"),te.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",te.length,")"]})]})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:te.length===0?t.jsxs(J,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Y([{key:"",value:""}]),children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),s("settings.mcp.page.env.addEnvironmentVariable")]}):t.jsx(zo,{value:te,onChange:Y,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:tt,disabled:Ne||!nt&&!w,size:"xs",className:"!font-normal",children:s(Ne?"settings.common.actions.saving":w?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!w&&t.jsx(J,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ye(!0),children:s("settings.common.actions.delete")})]})]}),t.jsx(Mt,{open:be,onOpenChange:Se=>{Se||(Ae(!1),Ge(""),it(null))},children:t.jsxs(Tt,{className:"max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("settings.mcp.page.importDialog.title")}),t.jsx(Bt,{children:s("settings.mcp.page.importDialog.description")})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx(hs,{value:ze,onChange:Se=>{Ge(Se.target.value),it(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"}),rt&&t.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:rt}),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:me,type:"button",children:[t.jsx(D,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),t.jsxs(qt,{children:[t.jsx(J,{variant:"outline",onClick:()=>{Ae(!1),Ge(""),it(null)},className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(J,{onClick:et,disabled:!ze.trim(),size:"sm",children:s("settings.common.actions.import")})]})]})}),t.jsx(Mt,{open:re,onOpenChange:Se=>{!Se&&!q&&ye(!1)},children:t.jsxs(Tt,{className:"max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("settings.mcp.page.deleteDialog.title",{name:n??""})}),t.jsxs(Bt,{children:[s("settings.mcp.page.deleteDialog.descriptionPrefix")," ",t.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",s("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),t.jsxs(qt,{children:[t.jsx(J,{variant:"outline",onClick:()=>ye(!1),disabled:q,className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(J,{variant:"destructive",size:"sm",onClick:ft,disabled:q,children:s(q?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},qg=({transform:s})=>({...s,y:0}),Jg=s=>{const e=Ze.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:l,listeners:u,setNodeRef:c,transform:x,transition:m,isDragging:g}=Sd(i);let d;e[2]!==x?(d=Cd.Transform.toString(x),e[2]=x,e[3]=d):d=e[3];let b;e[4]!==d||e[5]!==m?(b={transform:d,transition:m},e[4]=d,e[5]=m,e[6]=b):b=e[6];const h=g&&"opacity-50";let f;e[7]!==r||e[8]!==h?(f=ce("h-full rounded-md",r,h),e[7]=r,e[8]=h,e[9]=f):f=e[9];let y;return e[10]!==l||e[11]!==a||e[12]!==n||e[13]!==u||e[14]!==c||e[15]!==b||e[16]!==f?(y=t.jsx("div",{ref:c,"data-sortable-tab-id":n,style:b,className:f,...l,...u,children:a}),e[10]=l,e[11]=a,e[12]=n,e[13]=u,e[14]=c,e[15]=b,e[16]=f,e[17]=y):y=e[17],y},Qg=s=>{const e=Ze.c(6),{id:n,children:a,className:r}=s;let i;e[0]!==r?(i=ce("h-full",r),e[0]=r,e[1]=i):i=e[1];let l;return e[2]!==a||e[3]!==n||e[4]!==i?(l=t.jsx("div",{className:i,"data-sortable-tab-id":n,children:a}),e[2]=a,e[3]=n,e[4]=i,e[5]=l):l=e[5],l},Rn=s=>{const e=Ze.c(121),{items:n,activeId:a,onSelect:r,onClose:i,onReorder:l,layoutMode:u,variant:c,activePillInsetClassName:x,activePillButtonClassName:m,inactiveTabsIconOnly:g,iconOnlyActiveTab:d,animateActivePill:b,activePillLowercase:h,className:f}=s,y=u===void 0?"scrollable":u,P=c===void 0?"default":c,I=g===void 0?!1:g,C=d===void 0?!1:d,L=h===void 0?!0:h,{t:k}=st(),v=Ie(Yg),{isTablet:w}=Ms(),E=v||w,K=o.useRef(null);let U;e[0]===Symbol.for("react.memo_cache_sentinel")?(U={left:!1,right:!1},e[0]=U):U=e[0];const[M,S]=o.useState(U);let A;e[1]!==n?(A=n.map(Xg),e[1]=n,e[2]=A):A=e[2];const z=A,T=y==="scrollable",Z=P==="default",G=P==="active-pill",te=P==="animated",Y=G||te,N=Z,W=Y||N,B=G&&T,F=Y,O=b??te,Q=typeof l=="function",H=Q?Jg:Qg;let ie;e[3]===Symbol.for("react.memo_cache_sentinel")?(ie=new Map,e[3]=ie):ie=e[3];const oe=o.useRef(ie),[se,xe]=o.useState(null);let ae;e[4]===Symbol.for("react.memo_cache_sentinel")?(ae={activationConstraint:{distance:8}},e[4]=ae):ae=e[4];const fe=wd(Nd(kd,ae)),Ce=Zg;let ge;e[5]===Symbol.for("react.memo_cache_sentinel")?(ge=(Ye,We)=>{if(We){oe.current.set(Ye,We);return}oe.current.delete(Ye)},e[5]=ge):ge=e[5];const ve=ge;let Ne;e[6]!==a||e[7]!==W?(Ne=()=>{if(!W||!a){xe(eh);return}const Ye=K.current,We=oe.current.get(a);if(!Ye||!We){xe(th);return}let gt=0,me=0,et=We;for(;et&&et!==Ye;)gt=gt+et.offsetLeft,me=me+et.offsetTop,et=et.offsetParent;const nt={left:gt,top:me,width:We.offsetWidth,height:We.offsetHeight};xe(tt=>Ce(tt,nt)?tt:nt)},e[6]=a,e[7]=W,e[8]=Ne):Ne=e[8];const ne=Ne;let re;e[9]!==T?(re=()=>{if(!T){S({left:!1,right:!1});return}const Ye=K.current;if(!Ye){S({left:!1,right:!1});return}S({left:Ye.scrollLeft>2,right:Ye.scrollLeft+Ye.clientWidth<Ye.scrollWidth-2})},e[9]=T,e[10]=re):re=e[10];const ye=re;let q;e[11]!==T||e[12]!==ye?(q=()=>{if(!T){S({left:!1,right:!1});return}const Ye=K.current;if(!Ye)return;ye(),Ye.addEventListener("scroll",ye,{passive:!0});const We=new ResizeObserver(ye);return We.observe(Ye),()=>{Ye.removeEventListener("scroll",ye),We.disconnect()}},e[11]=T,e[12]=ye,e[13]=q):q=e[13];let $;e[14]!==T||e[15]!==n.length||e[16]!==ye?($=[T,n.length,ye],e[14]=T,e[15]=n.length,e[16]=ye,e[17]=$):$=e[17],o.useEffect(q,$);let ee;e[18]!==a||e[19]!==ne||e[20]!==W?(ee=()=>{if(!W){xe(null);return}ne();const Ye=K.current;if(!Ye)return;const We=new ResizeObserver(ne);if(We.observe(Ye),a){const gt=oe.current.get(a);gt&&We.observe(gt)}return()=>{We.disconnect()}},e[18]=a,e[19]=ne,e[20]=W,e[21]=ee):ee=e[21];let de;e[22]!==a||e[23]!==n.length||e[24]!==ne||e[25]!==W?(de=[a,n.length,ne,W],e[22]=a,e[23]=n.length,e[24]=ne,e[25]=W,e[26]=de):de=e[26],o.useEffect(ee,de);let De;e[27]!==ne?(De=()=>{ne()},e[27]=ne,e[28]=De):De=e[28],o.useLayoutEffect(De);let ke;e[29]!==a||e[30]!==T||e[31]!==ye?(ke=()=>{if(!T||!a)return;const Ye=K.current;if(!Ye)return;const We=window.requestAnimationFrame(()=>{const gt=typeof window.CSS?.escape=="function"?window.CSS.escape(a):a.replace(/"/g,'\\"'),me=Ye.querySelector(`[data-sortable-tab-id="${gt}"]`);me&&(me.scrollIntoView({block:"nearest",inline:"nearest"}),ye())});return()=>{window.cancelAnimationFrame(We)}},e[29]=a,e[30]=T,e[31]=ye,e[32]=ke):ke=e[32];let Pe;e[33]!==a||e[34]!==T||e[35]!==n.length||e[36]!==ye?(Pe=[a,T,n.length,ye],e[33]=a,e[34]=T,e[35]=n.length,e[36]=ye,e[37]=Pe):Pe=e[37],o.useEffect(ke,Pe);let Me;e[38]!==l?(Me=Ye=>{if(!l)return;const{active:We,over:gt}=Ye;!gt||We.id===gt.id||l(String(We.id),String(gt.id))},e[38]=l,e[39]=Me):Me=e[39];const Te=Me;let Ve;e[40]!==f?(Ve=ce("relative flex h-full min-w-0 flex-1",f),e[40]=f,e[41]=Ve):Ve=e[41];let Ue;e[42]!==T||e[43]!==M||e[44]!==Y?(Ue=T&&M.left?t.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",Y?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=T,e[43]=M,e[44]=Y,e[45]=Ue):Ue=e[45];let Oe;e[46]!==T||e[47]!==M||e[48]!==Y?(Oe=T&&M.right?t.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",Y?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=T,e[47]=M,e[48]=Y,e[49]=Oe):Oe=e[49];const _e=Y?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Ke=Y&&"@container/pill-tabs",Qe=Y&&"pill-tabs__track",Fe=Y&&(x??"gap-0.5 py-0.5"),V=N&&"items-center overflow-y-hidden",le=F&&"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",pe=T?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Le;e[50]!==_e||e[51]!==Ke||e[52]!==Qe||e[53]!==Fe||e[54]!==V||e[55]!==le||e[56]!==pe?(Le=ce("relative flex h-full min-w-0 flex-1",_e,Ke,Qe,Fe,V,le,pe),e[50]=_e,e[51]=Ke,e[52]=Qe,e[53]=Fe,e[54]=V,e[55]=le,e[56]=pe,e[57]=Le):Le=e[57];let we;e[58]!==T?(we=T?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=T,e[59]=we):we=e[59];let He;e[60]!==k?(He=k("sortableTabsStrip.aria.tabs"),e[60]=k,e[61]=He):He=e[61];let X;e[62]!==se||e[63]!==O||e[64]!==Y?(X=Y&&se?t.jsx("div",{className:ce("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(${se.left}px, ${se.top}px, 0)`,width:`${se.width}px`,height:`${se.height}px`,transition:O?"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]=se,e[63]=O,e[64]=Y,e[65]=X):X=e[65];let j;e[66]!==se||e[67]!==N?(j=N&&se?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(${se.left}px, 0, 0)`,width:`${se.width}px`},"aria-hidden":!0}):null,e[66]=se,e[67]=N,e[68]=j):j=e[68];let be;if(e[69]!==H||e[70]!==a||e[71]!==m||e[72]!==L||e[73]!==E||e[74]!==C||e[75]!==I||e[76]!==G||e[77]!==v||e[78]!==T||e[79]!==n||e[80]!==i||e[81]!==r||e[82]!==B||e[83]!==Y){let Ye;e[85]!==H||e[86]!==a||e[87]!==m||e[88]!==L||e[89]!==E||e[90]!==C||e[91]!==I||e[92]!==G||e[93]!==v||e[94]!==T||e[95]!==i||e[96]!==r||e[97]!==B||e[98]!==Y?(Ye=We=>{const gt=We.id===a,me=I&&Y&&!gt&&!!We.icon,et=!me,nt=!!We.icon&&(!C||gt),tt=I&&Y&&gt&&!T&&!B,ft=We.closable!==!1&&!!i,bt=ft&&!!We.icon,Rt=T||B?void 0:Y?tt?"flex-none basis-auto":v?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",ue=ft?Je=>{Je.button===1&&(Je.preventDefault(),Je.stopPropagation(),i?.(We.id))}:void 0,$e=ft?sh:void 0;return t.jsx(H,{id:We.id,className:Rt,children:t.jsxs("div",{ref:Je=>ve(We.id,Je),onAuxClick:ue,onMouseDown:$e,className:ce("group flex h-full min-w-0 flex-nowrap items-center",T||B?"shrink-0":Y?"w-full":"w-full min-w-0",Y?"relative z-10 bg-transparent":gt?"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":gt,"aria-label":me?We.title??We.label:void 0,onClick:()=>r(We.id),className:ce(Y?"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",Y&&L?"lowercase":null,Y&&(me?"gap-0":"gap-1.5"),Y?B?"shrink-0 whitespace-nowrap px-3 text-center":T?"max-w-56 shrink-0 px-3 text-center":me?"px-2 !min-w-0 text-center":tt?"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",Y?m??(G?v?"h-[38px]":"h-[31px]":"h-7"):null,Y?gt?"text-foreground":"text-muted-foreground hover:text-foreground":null,Y?"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:Y?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:ce("flex items-center justify-center transition-opacity",bt&&(E?"opacity-0":"group-hover:opacity-0")),children:We.icon}),bt?t.jsx("span",{role:"button",tabIndex:-1,className:ce("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",E?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:nh,onClick:Je=>{Je.stopPropagation(),i?.(We.id)},"aria-label":We.closeLabel??`Close ${We.label} tab`,title:We.closeLabel??`Close ${We.label} tab`,children:t.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,et?t.jsx("span",{className:"animated-tabs__label truncate",children:We.label}):null]}):t.jsxs("span",{className:ce("flex min-w-0 flex-nowrap items-center gap-1.5",!T&&"justify-center"),children:[nt?t.jsxs("span",{className:ce("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",gt?"text-[var(--primary-base)]":"text-muted-foreground"),children:[t.jsx("span",{className:ce("flex items-center justify-center transition-opacity",bt&&(E?"opacity-0":"group-hover:opacity-0")),children:We.icon}),bt?t.jsx("span",{role:"button",tabIndex:-1,className:ce("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",E?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:ah,onClick:Je=>{Je.stopPropagation(),i?.(We.id)},"aria-label":We.closeLabel??`Close ${We.label} tab`,title:We.closeLabel??`Close ${We.label} tab`,children:t.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,t.jsx("span",{className:"truncate leading-[1.2]",children:We.label})]})}),ft&&!bt?t.jsx("button",{type:"button",onPointerDown:rh,onClick:Je=>{Je.stopPropagation(),i?.(We.id)},className:ce("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",Y?"-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",Y?gt?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":gt?"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(D,{name:"close",className:"h-3 w-3"})}):null]})},We.id)},e[85]=H,e[86]=a,e[87]=m,e[88]=L,e[89]=E,e[90]=C,e[91]=I,e[92]=G,e[93]=v,e[94]=T,e[95]=i,e[96]=r,e[97]=B,e[98]=Y,e[99]=Ye):Ye=e[99],be=n.map(Ye),e[69]=H,e[70]=a,e[71]=m,e[72]=L,e[73]=E,e[74]=C,e[75]=I,e[76]=G,e[77]=v,e[78]=T,e[79]=n,e[80]=i,e[81]=r,e[82]=B,e[83]=Y,e[84]=be}else be=e[84];let Ae;e[100]!==Le||e[101]!==we||e[102]!==He||e[103]!==X||e[104]!==j||e[105]!==be?(Ae=t.jsxs("div",{ref:K,className:Le,style:we,role:"tablist","aria-label":He,children:[X,j,be]}),e[100]=Le,e[101]=we,e[102]=He,e[103]=X,e[104]=j,e[105]=be,e[106]=Ae):Ae=e[106];let ze;e[107]!==Ve||e[108]!==Ue||e[109]!==Oe||e[110]!==Ae?(ze=t.jsxs("div",{className:Ve,children:[Ue,Oe,Ae]}),e[107]=Ve,e[108]=Ue,e[109]=Oe,e[110]=Ae,e[111]=ze):ze=e[111];const Ge=ze;if(!Q)return Ge;let rt;e[112]===Symbol.for("react.memo_cache_sentinel")?(rt=[qg],e[112]=rt):rt=e[112];let it;e[113]!==z||e[114]!==Ge?(it=t.jsx(Id,{items:z,strategy:Pd,children:Ge}),e[113]=z,e[114]=Ge,e[115]=it):it=e[115];let at;e[116]===Symbol.for("react.memo_cache_sentinel")?(at=t.jsx(Ad,{dropAnimation:null}),e[116]=at):at=e[116];let lt;return e[117]!==Te||e[118]!==fe||e[119]!==it?(lt=t.jsxs(Dd,{sensors:fe,collisionDetection:Ed,onDragEnd:Te,modifiers:rt,children:[it,at]}),e[117]=Te,e[118]=fe,e[119]=it,e[120]=lt):lt=e[120],lt};function Yg(s){return s.isMobile}function Xg(s){return s.id}function Zg(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 eh(s){return s===null?s:null}function th(s){return s===null?s:null}function sh(s){s.button===1&&s.preventDefault()}function nh(s){s.stopPropagation()}function ah(s){s.stopPropagation()}function rh(s){s.stopPropagation()}const Xa=()=>{try{const e=es.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=vs.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[PluginsStore] Error resolving config directory:",s)}return null},ih=800,oh=5e3,lh="__default__",xi=new Map,zr=new Map,ch=1500,Pc=s=>s?.trim()||lh,dh=s=>{xi.delete(Pc(s))},ls=Nn()(wa(Ii((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=Xa(),r=Pc(a),i=Date.now(),l=xi.get(r)??0,u=e().entries.length>0||e().files.length>0;if(!n?.force&&u&&i-l<oh)return!0;const c=zr.get(r);if(!n?.force&&c)return c;const x=(async()=>{s({isLoading:!0});try{const m=await dt(hn("/api/config/plugins",a),{headers:ma(a)});if(!m.ok)throw new Error("Failed to load plugins");const g=await Za(m);return s({entries:g.entries??[],files:g.files??[],isLoading:!1}),xi.set(r,Date.now()),n?.force||e().loadRegistryInfo(),!0}catch(m){return console.error("[PluginsStore] Failed to load plugins:",m),s({isLoading:!1}),!1}})();zr.set(r,x);try{return await x}finally{zr.delete(r)}},loadRegistryInfo:async n=>{const a=mh(n?.specs??e().entries.map(r=>r.spec));if(a.length===0){s({isLoadingRegistry:!1});return}s({isLoadingRegistry:!0});try{const r=Xa(),i={...e().registryInfo};for(const l of ph(a)){const u=await dt(uh(l,n?.force===!0,r),{headers:ma(r)});if(!u.ok)throw new Error("Failed to load plugin registry info");const c=await Za(u);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 Un("Creating plugin entry…",async r=>await dt(hn("/api/config/plugins/entry",r),{method:"POST",headers:Ka(r),body:JSON.stringify(Bo(n))}),e);return a.ok&&e().loadRegistryInfo({specs:[n.spec],force:!0}),a},updateEntry:async(n,a)=>{const r=e().entries.find(u=>u.id===n)?.spec,i=a.spec??r,l=await Un("Updating plugin entry…",async u=>await dt(hn(`/api/config/plugins/entry/${encodeURIComponent(n)}`,u),{method:"PATCH",headers:Ka(u),body:JSON.stringify(Bo(a))}),e);return l.ok&&i&&e().loadRegistryInfo({specs:[i],force:!0}),l},deleteEntry:async n=>{const a=e().entries.find(i=>i.id===n),r=await Un("Deleting plugin entry…",async i=>await dt(hn(`/api/config/plugins/entry/${encodeURIComponent(n)}`,i),{method:"DELETE",headers:ma(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=Xa(),r=await dt(hn(`/api/config/plugins/file/${encodeURIComponent(n)}`,a),{headers:ma(a)});if(!r.ok)throw new Error("Failed to read plugin file");return await Za(r)}catch(a){return console.error("[PluginsStore] Failed to read plugin file:",a),null}},createFile:async n=>Un("Creating plugin file…",async a=>await dt(hn("/api/config/plugins/file",a),{method:"POST",headers:Ka(a),body:JSON.stringify(n)}),e),updateFile:async(n,a)=>Un("Updating plugin file…",async r=>await dt(hn(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{method:"PUT",headers:Ka(r),body:JSON.stringify(a)}),e),deleteFile:async n=>{const a=await Un("Deleting plugin file…",async r=>await dt(hn(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{method:"DELETE",headers:ma(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:Ei(),partialize:s=>({selectedId:s.selectedId})}),{name:"plugins-store"}));function hn(s,e){const n=e?`?directory=${encodeURIComponent(e)}`:"";return`${s}${n}`}function uh(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 mh(s){return Array.from(new Set(s.map(e=>e.trim()).filter(Boolean)))}function ph(s){const e=[];let n=[],a=0;for(const r of s){const i=encodeURIComponent(r),l=n.length===0?i.length:a+1+i.length;n.length>0&&l>ch?(e.push(n),n=[r],a=i.length):(n.push(r),a=l)}return n.length>0&&e.push(n),e}function ma(s){return s?{"x-opencode-directory":s}:void 0}function Ka(s){return{"Content-Type":"application/json",...s?{"x-opencode-directory":s}:{}}}function Bo(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 Un(s,e,n){qa(s);let a=!1;try{const r=Xa(),i=await e(r),l=await Za(i).catch(()=>null);if(!i.ok)throw new Error(l?.error||"Failed to update plugin configuration");return dh(r),l?.requiresReload&&(a=!0,await Ja({message:l.message,delayMs:l.reloadDelayMs??ih,scopes:["all"]})),await n().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}}catch(r){return console.error("[PluginsStore] Failed to update plugin configuration:",r),{ok:!1}}finally{a||Qa()}}async function Za(s){return await s.json()}const gh=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function hh(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 fh=({open:s,onOpenChange:e,defaultScope:n="user"})=>{const{t:a}=st(),r=ls(T=>T.createEntry),i=ls(T=>T.createFile),[l,u]=o.useState("npm"),[c,x]=o.useState(""),[m,g]=o.useState(""),[d,b]=o.useState(""),[h,f]=o.useState(""),[y,P]=o.useState(n),[I,C]=o.useState(!1),L=o.useCallback(()=>{x(""),g(""),b(""),f(""),P(n)},[n]);o.useEffect(()=>{s&&(u("npm"),L())},[s,L]);const k=T=>{T!==l&&(u(T),L())},v=o.useMemo(()=>hh(m),[m]),w=!v.ok,E=l==="file"&&d.trim()!==""&&!gh.test(d.trim()),K=(l==="npm"||l==="path")&&c.trim()==="",U=l==="file"&&h.trim()==="",M=l==="file"&&d.trim()==="",S=I||w||l==="npm"&&K||l==="path"&&K||l==="file"&&(M||E||U),A=async()=>{if(!S){C(!0);try{let T;l==="file"?T=await i({fileName:d.trim(),content:h,scope:y}):T=await r({spec:c.trim(),options:v.ok?v.value:void 0,scope:y}),T.ok?(_.success(T.message||a("settings.plugins.toast.created")),T.reloadFailed&&_.warning(a("settings.plugins.toast.reloadFailed")),e(!1)):_.error(T.message||a("settings.plugins.sidebar.toast.deleteFailed"))}finally{C(!1)}}},z=o.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(Mt,{open:s,onOpenChange:T=>{!T&&I||e(T)},children:t.jsxs(Tt,{className:"max-w-xl",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:a("settings.plugins.dialog.add.title")}),t.jsx(Bt,{children:a("settings.plugins.sidebar.empty.description")})]}),t.jsx(Rn,{items:z,activeId:l,onSelect:T=>k(T),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),t.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="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(Xe,{id:"plugin-spec",value:c,onChange:T=>x(T.target.value),placeholder:a("settings.plugins.page.field.spec.placeholder"),"aria-invalid":K?!1:void 0,disabled:I}),K&&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(hs,{id:"plugin-options",value:m,onChange:T=>g(T.target.value),rows:5,className:"font-mono",hasError:w,disabled:I}),w&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:a("settings.plugins.page.field.options.invalidJson")})]})]}),l==="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(Xe,{id:"plugin-filename",value:d,onChange:T=>b(T.target.value),placeholder:"my-plugin.ts","aria-invalid":E||void 0,disabled:I}),E&&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(hs,{id:"plugin-content",value:h,onChange:T=>f(T.target.value),rows:16,className:"font-mono",disabled:I})]})]}),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 Z=y===T,G=a(T==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return t.jsxs("button",{type:"button",onClick:()=>P(T),disabled:I,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[t.jsx(tn,{checked:Z,onChange:()=>P(T),ariaLabel:G}),t.jsx("span",{className:ce("typography-ui-label font-normal",Z?"text-foreground":"text-foreground/60"),children:G})]},T)})})]})]}),t.jsxs(qt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:I,children:a("settings.plugins.dialog.add.action.cancel")}),t.jsxs(J,{size:"sm",onClick:()=>{A()},disabled:S,children:[I?t.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,a("settings.plugins.dialog.add.action.submit")]})]})]})})},xh=s=>{const e=Ze.c(33),{spec:n}=s;let a;e[0]!==n?(a=u=>u.registryInfo[n],e[0]=n,e[1]=a):a=e[1];const r=ls(a),{t:i}=st();if(!r)return null;const l=yh;switch(r.kind){case"npm-ok":{if(!r.hasUpdate||!r.latestVersion)return null;let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(D,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=u):u=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:[u,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=l(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 u;e[10]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=u):u=e[10];let c;return e[11]!==r.currentVersion||e[12]!==r.name||e[13]!==i?(c=l(u,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 u;e[15]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=u):u=e[15];let c;return e[16]!==r.name||e[17]!==i?(c=l(u,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 u;e[19]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=u):u=e[19];let c;return e[20]!==i?(c=l(u,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=c):c=e[21],c}case"npm-network":{let u;e[22]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(D,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=u):u=e[22];let c;return e[23]!==i?(c=l(u,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=c):c=e[24],c}case"path-missing":{let u;e[25]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=u):u=e[25];let c;return e[26]!==r.absolutePath||e[27]!==i?(c=l(u,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 u;e[29]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=u):u=e[29];let c;return e[30]!==r.absolutePath||e[31]!==i?(c=l(u,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 yh(s,e){return t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:s})}),t.jsx(It,{children:e})]})}const Ac=s=>{const e=Ze.c(26),{header:n,footer:a,children:r,className:i,variant:l}=s,u=l===void 0?"sidebar":l,c=rs(),x=o.useRef(null),[m,g]=o.useState(!1),[d,b]=o.useState(!1),h=u==="background"||c?"bg-background":"bg-sidebar",f=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{const S=x.current;if(!S){g(!1),b(!1);return}if(!(S.scrollHeight>S.clientHeight+1)){g(!1),b(!1);return}g(S.scrollTop>1),b(S.scrollTop+S.clientHeight<S.scrollHeight-1)},e[0]=y):y=e[0];const P=y;let I;e[1]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{P()},e[1]=I):I=e[1];let C;e[2]!==r?(C=[r,P],e[2]=r,e[3]=C):C=e[3],o.useEffect(I,C);let L,k;e[4]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{const S=x.current;if(!S)return;const A=()=>P();return S.addEventListener("scroll",A,{passive:!0}),()=>S.removeEventListener("scroll",A)},k=[P],e[4]=L,e[5]=k):(L=e[4],k=e[5]),o.useEffect(L,k);let v;e[6]!==h||e[7]!==i?(v=ce("flex h-full flex-col",h,i),e[6]=h,e[7]=i,e[8]=v):v=e[8];let w;e[9]!==r?(w=t.jsx(Ht,{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]=w):w=e[10];let E;e[11]!==f||e[12]!==m?(E=m&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${f} 0%, transparent 100%)`}}),e[11]=f,e[12]=m,e[13]=E):E=e[13];let K;e[14]!==f||e[15]!==d?(K=d&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${f} 0%, transparent 100%)`}}),e[14]=f,e[15]=d,e[16]=K):K=e[16];let U;e[17]!==K||e[18]!==w||e[19]!==E?(U=t.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[w,E,K]}),e[17]=K,e[18]=w,e[19]=E,e[20]=U):U=e[20];let M;return e[21]!==a||e[22]!==n||e[23]!==U||e[24]!==v?(M=t.jsxs("div",{className:v,children:[n,U,a]}),e[21]=a,e[22]=n,e[23]=U,e[24]=v,e[25]=M):M=e[25],M},yi=s=>{const e=Ze.c(23),{title:n,metadata:a,selected:r,onSelect:i,icon:l,actions:u,className:c}=s,x=r===void 0?!1:r,m=u&&u.length>0,g=x?"bg-interactive-selection":"hover:bg-interactive-hover";let d;e[0]!==c||e[1]!==g?(d=ce("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",g,c),e[0]=c,e[1]=g,e[2]=d):d=e[2];let b;e[3]!==n?(b=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=b):b=e[4];let h;e[5]!==l||e[6]!==b?(h=t.jsxs("div",{className:"flex items-center gap-1.5",children:[l,b]}),e[5]=l,e[6]=b,e[7]=h):h=e[7];let f;e[8]!==a?(f=a&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a}),e[8]=a,e[9]=f):f=e[9];let y;e[10]!==i||e[11]!==h||e[12]!==f?(y=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:[h,f]}),e[10]=i,e[11]=h,e[12]=f,e[13]=y):y=e[13];let P;e[14]!==u||e[15]!==m?(P=m&&t.jsxs(gs,{children:[t.jsx(ms,{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(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:u.map(bh)})]}),e[14]=u,e[15]=m,e[16]=P):P=e[16];let I;e[17]!==y||e[18]!==P?(I=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[y,P]}),e[17]=y,e[18]=P,e[19]=I):I=e[19];let C;return e[20]!==d||e[21]!==I?(C=t.jsx("div",{className:d,children:I}),e[20]=d,e[21]=I,e[22]=C):C=e[22],C};function bh(s){const e=s.icon;return t.jsxs(Ns,{onClick:n=>{n.stopPropagation(),s.onClick()},className:ce(s.destructive&&"text-destructive focus:text-destructive"),children:[e&&t.jsx(D,{name:e,className:"h-4 w-4 mr-px"}),s.label]},s.label)}const vh=s=>s.parsedKind==="npm"?"code-box":"folder",jh=s=>{const e=Ze.c(144),{onItemSelect:n,onAddClick:a}=s,{t:r}=st(),{entries:i,files:l,selectedId:u,setSelected:c,deleteEntry:x,deleteFile:m,loadPlugins:g}=ls(Ps(wh)),d=ls(Nh),b=ls(kh),h=ls(Sh),f=ls(Ch),[y,P]=o.useState(null),[I,C]=o.useState(!1),[L,k]=o.useState(!1);let v,w;e[0]!==g?(v=()=>{g()},w=[g],e[0]=g,e[1]=v,e[2]=w):(v=e[1],w=e[2]),o.useEffect(v,w);let E,K;e[3]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{const me=()=>k(!0);return window.addEventListener("openchamber:settings-open-plugin-add",me),()=>window.removeEventListener("openchamber:settings-open-plugin-add",me)},K=[],e[3]=E,e[4]=K):(E=e[3],K=e[4]),o.useEffect(E,K);let U;if(e[5]!==i||e[6]!==d){U={userEntries:0,projectEntries:0};for(const me of i){const et=d[me.spec];et?.kind==="npm-ok"&&et.hasUpdate&&(me.scope==="user"?U.userEntries=U.userEntries+1:me.scope==="project"&&(U.projectEntries=U.projectEntries+1))}e[5]=i,e[6]=d,e[7]=U}else U=e[7];const M=U;let S;e[8]!==i?(S=i.filter(Ih),e[8]=i,e[9]=S):S=e[9];const A=S;let z;e[10]!==i?(z=i.filter(Ph),e[10]=i,e[11]=z):z=e[11];const T=z;let Z;e[12]!==l?(Z=l.filter(Ah),e[12]=l,e[13]=Z):Z=e[13];const G=Z;let te;e[14]!==l?(te=l.filter(Dh),e[14]=l,e[15]=te):te=e[15];const Y=te,N=i.length+l.length,W=N===0;let B;e[16]!==a?(B=()=>{a?a():k(!0)},e[16]=a,e[17]=B):B=e[17];const F=B;let O;e[18]!==n||e[19]!==c?(O=me=>{c(me),n?.()},e[18]=n,e[19]=c,e[20]=O):O=e[20];const Q=O;let H;e[21]!==i||e[22]!==d||e[23]!==r||e[24]!==f?(H=async me=>{const et=i.find(bt=>bt.id===me);if(!et)return;const nt=d[et.spec];if(!nt||nt.kind!=="npm-ok"||!nt.hasUpdate||!nt.latestVersion)return;const tt=nt.latestVersion;(await f(me)).ok?_.success(r("settings.plugins.toast.updatedToLatest",{version:tt})):_.error(r("settings.plugins.toast.refreshFailed"))},e[21]=i,e[22]=d,e[23]=r,e[24]=f,e[25]=H):H=e[25];const ie=H;let oe;e[26]!==h||e[27]!==r?(oe=async()=>{_.info(r("settings.plugins.toast.refreshing"));try{await h({force:!0})}catch{_.error(r("settings.plugins.toast.refreshFailed"))}},e[26]=h,e[27]=r,e[28]=oe):oe=e[28];const se=oe;let xe;e[29]!==x||e[30]!==m||e[31]!==y||e[32]!==r?(xe=async()=>{if(!y)return;C(!0);const me=y.kind==="entry"?await x(y.id):await m(y.id);me.ok?_.success(me.message||r("settings.plugins.sidebar.toast.deleted",{name:y.label})):_.error(r("settings.plugins.sidebar.toast.deleteFailed")),P(null),C(!1)},e[29]=x,e[30]=m,e[31]=y,e[32]=r,e[33]=xe):xe=e[33];const ae=xe;let fe;e[34]!==Q||e[35]!==ie||e[36]!==d||e[37]!==u||e[38]!==r?(fe=me=>{const et=d[me.spec],nt=et?.kind==="npm-ok"&&et.hasUpdate&&!!et.latestVersion,tt=[];return nt&&tt.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{ie(me.id)}}),tt.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>P({kind:"entry",id:me.id,label:me.spec})}),t.jsx(yi,{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:me.spec}),t.jsx(xh,{spec:me.spec})]}),metadata:me.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:u===me.id,onSelect:()=>Q(me.id),icon:t.jsx(D,{name:vh(me),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:tt},me.id)},e[34]=Q,e[35]=ie,e[36]=d,e[37]=u,e[38]=r,e[39]=fe):fe=e[39];const Ce=fe;let ge;e[40]!==Q||e[41]!==u||e[42]!==r?(ge=me=>t.jsx(yi,{title:me.fileName,metadata:r("settings.plugins.sidebar.kind.file"),selected:u===me.id,onSelect:()=>Q(me.id),icon:t.jsx(D,{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:()=>P({kind:"file",id:me.id,label:me.fileName})}]},me.id),e[40]=Q,e[41]=u,e[42]=r,e[43]=ge):ge=e[43];const ve=ge;let Ne;e[44]!==r?(Ne=(me,et,nt)=>{const tt=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:[me,tt>0&&t.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(tt===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:tt})})]}),et]})},e[44]=r,e[45]=Ne):Ne=e[45];const ne=Ne;let re;e[46]!==r?(re=r("settings.plugins.sidebar.title"),e[46]=r,e[47]=re):re=e[47];let ye;e[48]!==re?(ye=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:re})}),e[48]=re,e[49]=ye):ye=e[49];let q;e[50]!==r||e[51]!==N?(q=r("settings.plugins.sidebar.total",{count:N}),e[50]=r,e[51]=N,e[52]=q):q=e[52];let $;e[53]!==q?($=t.jsx("span",{className:"typography-meta text-muted-foreground",children:q}),e[53]=q,e[54]=$):$=e[54];let ee;e[55]!==se?(ee=()=>{se()},e[55]=se,e[56]=ee):ee=e[56];let de;e[57]!==r?(de=r("settings.plugins.sidebar.actions.refresh"),e[57]=r,e[58]=de):de=e[58];let De;e[59]!==r?(De=r("settings.plugins.sidebar.actions.refresh"),e[59]=r,e[60]=De):De=e[60];const ke=b?"size-4 animate-spin":"size-4";let Pe;e[61]!==ke?(Pe=t.jsx(D,{name:"refresh",className:ke}),e[61]=ke,e[62]=Pe):Pe=e[62];let Me;e[63]!==b||e[64]!==ee||e[65]!==de||e[66]!==De||e[67]!==Pe?(Me=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:ee,disabled:b,"aria-label":de,title:De,children:Pe}),e[63]=b,e[64]=ee,e[65]=de,e[66]=De,e[67]=Pe,e[68]=Me):Me=e[68];let Te;e[69]!==r?(Te=r("settings.plugins.sidebar.actions.addTitle"),e[69]=r,e[70]=Te):Te=e[70];let Ve;e[71]!==r?(Ve=r("settings.plugins.sidebar.actions.addTitle"),e[71]=r,e[72]=Ve):Ve=e[72];let Ue;e[73]===Symbol.for("react.memo_cache_sentinel")?(Ue=t.jsx(D,{name:"add",className:"size-4"}),e[73]=Ue):Ue=e[73];let Oe;e[74]!==F||e[75]!==Te||e[76]!==Ve?(Oe=t.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:F,"aria-label":Te,title:Ve,children:Ue}),e[74]=F,e[75]=Te,e[76]=Ve,e[77]=Oe):Oe=e[77];let _e;e[78]!==Me||e[79]!==Oe?(_e=t.jsxs("div",{className:"flex items-center gap-1",children:[Me,Oe]}),e[78]=Me,e[79]=Oe,e[80]=_e):_e=e[80];let Ke;e[81]!==$||e[82]!==_e?(Ke=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[$,_e]}),e[81]=$,e[82]=_e,e[83]=Ke):Ke=e[83];let Qe;e[84]!==ye||e[85]!==Ke?(Qe=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ye,Ke]}),e[84]=ye,e[85]=Ke,e[86]=Qe):Qe=e[86];let Fe;e[87]!==W||e[88]!==T||e[89]!==Y||e[90]!==Ce||e[91]!==ve||e[92]!==ne||e[93]!==r||e[94]!==M||e[95]!==A||e[96]!==G?(Fe=W?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(D,{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:[A.length>0&&ne(r("settings.plugins.sidebar.group.userEntries"),A.map(Ce),M.userEntries),G.length>0&&ne(r("settings.plugins.sidebar.group.userFiles"),G.map(ve)),T.length>0&&ne(r("settings.plugins.sidebar.group.projectEntries"),T.map(Ce),M.projectEntries),Y.length>0&&ne(r("settings.plugins.sidebar.group.projectFiles"),Y.map(ve))]}),e[87]=W,e[88]=T,e[89]=Y,e[90]=Ce,e[91]=ve,e[92]=ne,e[93]=r,e[94]=M,e[95]=A,e[96]=G,e[97]=Fe):Fe=e[97];let V;e[98]!==Qe||e[99]!==Fe?(V=t.jsx(Ac,{variant:"background",header:Qe,children:Fe}),e[98]=Qe,e[99]=Fe,e[100]=V):V=e[100];let le;e[101]!==L?(le=t.jsx(fh,{open:L,onOpenChange:k}),e[101]=L,e[102]=le):le=e[102];const pe=y!==null;let Le;e[103]!==I?(Le=me=>{!me&&!I&&P(null)},e[103]=I,e[104]=Le):Le=e[104];let we;e[105]!==r?(we=r("settings.plugins.sidebar.deleteDialog.title"),e[105]=r,e[106]=we):we=e[106];let He;e[107]!==we?(He=t.jsx(Ot,{children:we}),e[107]=we,e[108]=He):He=e[108];const X=y?.label??"";let j;e[109]!==r||e[110]!==X?(j=r("settings.plugins.sidebar.deleteDialog.description",{name:X}),e[109]=r,e[110]=X,e[111]=j):j=e[111];let be;e[112]!==j?(be=t.jsx(Bt,{children:j}),e[112]=j,e[113]=be):be=e[113];let Ae;e[114]!==He||e[115]!==be?(Ae=t.jsxs(zt,{children:[He,be]}),e[114]=He,e[115]=be,e[116]=Ae):Ae=e[116];let ze;e[117]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>P(null),e[117]=ze):ze=e[117];let Ge;e[118]!==r?(Ge=r("settings.common.actions.cancel"),e[118]=r,e[119]=Ge):Ge=e[119];let rt;e[120]!==I||e[121]!==Ge?(rt=t.jsx(J,{size:"sm",variant:"ghost",onClick:ze,disabled:I,children:Ge}),e[120]=I,e[121]=Ge,e[122]=rt):rt=e[122];let it;e[123]!==I||e[124]!==r?(it=r(I?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=I,e[124]=r,e[125]=it):it=e[125];let at;e[126]!==ae||e[127]!==I||e[128]!==it?(at=t.jsx(J,{size:"sm",variant:"destructive",onClick:ae,disabled:I,children:it}),e[126]=ae,e[127]=I,e[128]=it,e[129]=at):at=e[129];let lt;e[130]!==rt||e[131]!==at?(lt=t.jsxs(qt,{children:[rt,at]}),e[130]=rt,e[131]=at,e[132]=lt):lt=e[132];let Ye;e[133]!==Ae||e[134]!==lt?(Ye=t.jsxs(Tt,{className:"max-w-md",children:[Ae,lt]}),e[133]=Ae,e[134]=lt,e[135]=Ye):Ye=e[135];let We;e[136]!==pe||e[137]!==Le||e[138]!==Ye?(We=t.jsx(Mt,{open:pe,onOpenChange:Le,children:Ye}),e[136]=pe,e[137]=Le,e[138]=Ye,e[139]=We):We=e[139];let gt;return e[140]!==V||e[141]!==le||e[142]!==We?(gt=t.jsxs(t.Fragment,{children:[V,le,We]}),e[140]=V,e[141]=le,e[142]=We,e[143]=gt):gt=e[143],gt};function wh(s){return{entries:s.entries,files:s.files,selectedId:s.selectedId,setSelected:s.setSelected,deleteEntry:s.deleteEntry,deleteFile:s.deleteFile,loadPlugins:s.loadPlugins}}function Nh(s){return s.registryInfo}function kh(s){return s.isLoadingRegistry}function Sh(s){return s.loadRegistryInfo}function Ch(s){return s.updateToLatest}function Ih(s){return s.scope==="user"}function Ph(s){return s.scope==="project"}function Ah(s){return s.scope==="user"}function Dh(s){return s.scope==="project"}const bi=s=>{const e=Ze.c(10),{children:n,className:a,outerClassName:r}=s;let i;e[0]!==r?(i=ce("h-full",r),e[0]=r,e[1]=i):i=e[1];let l;e[2]!==a?(l=ce("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",a),e[2]=a,e[3]=l):l=e[3];let u;e[4]!==n||e[5]!==l?(u=t.jsx("div",{className:l,children:n}),e[4]=n,e[5]=l,e[6]=u):u=e[6];let c;return e[7]!==i||e[8]!==u?(c=t.jsx(Ht,{outerClassName:i,className:"w-full",children:u}),e[7]=i,e[8]=u,e[9]=c):c=e[9],c},Eh=({entryId:s,spec:e})=>{const{t:n}=st(),a=ls(g=>g.registryInfo[e]),r=ls(g=>g.updateToLatest),[i,l]=o.useState(!1);if(!a)return null;if(a.kind==="npm-ok"){if(!a.hasUpdate||!a.latestVersion)return null;const g=a.latestVersion,d=a.currentVersion??"",b=async()=>{l(!0);try{(await r(s)).ok?_.success(n("settings.plugins.toast.updatedToLatest",{version:g})):_.error(n("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(D,{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:d,latest:g})})]}),t.jsx(J,{variant:"default",size:"sm",onClick:()=>{b()},disabled:i,children:n("settings.plugins.registry.banner.updateAvailable.action",{latest:g})})]})}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(D,{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 u=a.kind==="path-unreadable",c=u?"var(--status-warning)":"var(--status-error)",x=u?"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(D,{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 Mh(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 Dc(s){return!s||Object.keys(s).length===0?"":JSON.stringify(s,null,2)}function $o(s){return{mode:"entry",scope:s.scope,spec:s.spec,optionsJson:Dc(s.options),fileName:"",content:""}}function Vo(s,e){return{mode:"file",scope:s.scope,spec:"",optionsJson:"",fileName:s.fileName,content:e}}const _o=s=>{const e=Ze.c(4),{scope:n,label:a}=s;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=ce("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},Th=()=>{const{t:s}=st(),e=ls(y=>y.selectedId),n=ls(y=>y.entries),a=ls(y=>y.files),r=ls(y=>y.draft),i=ls(y=>y.setDraft),l=ls(y=>y.updateEntry),u=ls(y=>y.updateFile),c=ls(y=>y.readFile),x=o.useMemo(()=>e?n.find(y=>y.id===e)??null:null,[n,e]),m=o.useMemo(()=>e?a.find(y=>y.id===e)??null:null,[a,e]),[g,d]=o.useState(!1),[b,h]=o.useState(!1),f=o.useRef(new Map);if(o.useEffect(()=>{let y=!1;return x?(i($o(x)),()=>{y=!0}):m?(h(!0),(async()=>{const P=await c(m.id);if(y)return;h(!1);const I=P?.content??"";f.current.set(m.id,I),i(Vo(m,I))})(),()=>{y=!0}):(i(null),()=>{y=!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(D,{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 y=Mh(r.optionsJson),P=y.ok,I=r.spec!==x.spec||r.optionsJson!==Dc(x.options),C=()=>{i($o(x))},L=async()=>{if(!P)return;const k=r.spec.trim();if(!k){_.error(s("settings.plugins.validation.specRequired"));return}d(!0);try{const v=await l(x.id,{spec:k,options:y.value});v.ok?v.reloadFailed?_.warning(v.message||s("settings.plugins.toast.reloadFailed"),{description:v.warning}):_.success(v.message||s("settings.plugins.toast.updated")):_.error(v.message||s("settings.plugins.toast.reloadFailed"))}finally{d(!1)}};return t.jsxs(bi,{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(_o,{scope:x.scope,label:x.scope==="project"?s("settings.plugins.sidebar.group.projectEntries"):s("settings.plugins.sidebar.group.userEntries")})]})}),t.jsx(Eh,{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(Xe,{value:r.spec,onChange:k=>i({...r,spec:k.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(hs,{value:r.optionsJson,onChange:k=>i({...r,optionsJson:k.target.value}),rows:10,className:ce("font-mono typography-meta min-h-[200px]",!P&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!P&&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:()=>{L()},disabled:!I||!P||g,children:s("settings.plugins.page.action.save")}),t.jsx(J,{variant:"outline",size:"sm",onClick:C,disabled:!I||g,children:s("settings.plugins.page.action.discard")})]})]})}if(m&&r&&r.mode==="file"){const y=f.current.get(m.id)??"",P=r.content!==y||r.fileName!==m.fileName,I=()=>{(async()=>{h(!0);const k=(await c(m.id))?.content??"";h(!1),f.current.set(m.id,k),i(Vo(m,k))})()},C=async()=>{d(!0);try{const L=await u(m.id,{content:r.content});L.ok?(f.current.set(m.id,r.content),L.reloadFailed?_.warning(L.message||s("settings.plugins.toast.reloadFailed"),{description:L.warning}):_.success(L.message||s("settings.plugins.toast.updated"))):_.error(L.message||s("settings.plugins.toast.reloadFailed"))}finally{d(!1)}};return t.jsxs(bi,{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(_o,{scope:m.scope,label:m.scope==="project"?s("settings.plugins.sidebar.group.projectFiles"):s("settings.plugins.sidebar.group.userFiles")}),t.jsx("span",{className:ce("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(hs,{value:r.content,onChange:L=>i({...r,content:L.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:b})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"default",size:"sm",onClick:()=>{C()},disabled:!P||g||b,children:s("settings.plugins.page.action.save")}),t.jsx(J,{variant:"outline",size:"sm",onClick:I,disabled:g||b,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(D,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Rh="<built-in>",Vn=s=>s?.path===Rh,Fh=s=>{const e=Ze.c(150),{onItemSelect:n}=s,{t:a}=st(),[r,i]=o.useState(null),[l,u]=o.useState(""),[c,x]=o.useState(null),[m,g]=o.useState(!1),[d,b]=o.useState(null),{selectedSkillName:h,skills:f,setSelectedSkill:y,setSkillDraft:P,createSkill:I,deleteSkill:C,getSkillDetail:L}=an(Ps(Lh));let k;e[0]!==n||e[1]!==y||e[2]!==P||e[3]!==f?(k=()=>{let me="new-skill",et=1;for(;f.some(nt=>nt.name===me);)me=`new-skill-${et}`,et++;P({name:me,scope:"user",source:"opencode",description:""}),y(me),n?.()},e[0]=n,e[1]=y,e[2]=P,e[3]=f,e[4]=k):k=e[4];const v=k;let w;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=async me=>{Vn(me)||x(me)},e[5]=w):w=e[5];const E=w;let K;e[6]!==c||e[7]!==C||e[8]!==a?(K=async()=>{if(!c)return;if(Vn(c)){x(null);return}g(!0),await C(c.name)?(_.success(a("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),x(null)):_.error(a("settings.skills.sidebar.toast.deleteSkillFailed")),g(!1)},e[6]=c,e[7]=C,e[8]=a,e[9]=K):K=e[9];const U=K;let M;e[10]!==L||e[11]!==y||e[12]!==P||e[13]!==f||e[14]!==a?(M=async me=>{if(Vn(me))return;const et=me.name;let nt=1,tt=`${et}-copy`;for(;f.some(bt=>bt.name===tt);)nt++,tt=`${et}-copy-${nt}`;const ft=await L(me.name);if(!ft){_.error(a("settings.skills.sidebar.toast.duplicateLoadFailed"));return}P({name:tt,scope:me.scope||"user",source:me.source||"opencode",description:(ft.sources.md.fields.includes("description"),""),instructions:""}),y(tt)},e[10]=L,e[11]=y,e[12]=P,e[13]=f,e[14]=a,e[15]=M):M=e[15];const S=M;let A;e[16]===Symbol.for("react.memo_cache_sentinel")?(A=me=>{Vn(me)||(u(me.name),i(me))},e[16]=A):A=e[16];const z=A;let T;e[17]!==I||e[18]!==C||e[19]!==L||e[20]!==r||e[21]!==l||e[22]!==y||e[23]!==f||e[24]!==a?(T=async()=>{if(!r)return;if(Vn(r)){i(null);return}const me=l.trim().replace(/\s+/g,"-").toLowerCase();if(!me){_.error(a("settings.skills.page.toast.skillNameRequired"));return}if(me===r.name){i(null);return}if(f.some(tt=>tt.name===me)){_.error(a("settings.skills.page.toast.skillExists"));return}if(!await L(r.name)){_.error(a("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await I({name:me,description:"Renamed skill",scope:r.scope,source:r.source})?await C(r.name)?(_.success(`Skill renamed to "${me}"`),y(me)):_.error(a("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):_.error(a("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=I,e[18]=C,e[19]=L,e[20]=r,e[21]=l,e[22]=y,e[23]=f,e[24]=a,e[25]=T):T=e[25];const Z=T;let G;e[26]!==f?(G=f.filter(Oh),e[26]=f,e[27]=G):G=e[27];const te=G;let Y;e[28]!==f?(Y=f.filter(zh),e[28]=f,e[29]=Y):Y=e[29];const N=Y;let W;e[30]===Symbol.for("react.memo_cache_sentinel")?(W=function(et){const nt={},tt=[];for(const bt of et)bt.group?(nt[bt.group]||(nt[bt.group]=[]),nt[bt.group].push(bt)):tt.push(bt);const ft=Object.keys(nt).sort(Kh).map(bt=>({name:bt,skills:[...nt[bt]].sort(Uh)}));return tt.sort(Bh),{sortedGroups:ft,ungrouped:tt}},e[30]=W):W=e[30];const B=W;let F;e[31]!==te?(F=B(te),e[31]=te,e[32]=F):F=e[32];const O=F;let Q;e[33]!==N?(Q=B(N),e[33]=N,e[34]=Q):Q=e[34];const H=Q;let ie;e[35]===Symbol.for("react.memo_cache_sentinel")?(ie=ce("flex h-full flex-col","bg-background"),e[35]=ie):ie=e[35];let oe;e[36]!==a?(oe=a("settings.skills.sidebar.title"),e[36]=a,e[37]=oe):oe=e[37];let se;e[38]!==oe?(se=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:oe}),e[38]=oe,e[39]=se):se=e[39];let xe;e[40]===Symbol.for("react.memo_cache_sentinel")?(xe=t.jsx(Na,{className:"mb-3"}),e[40]=xe):xe=e[40];let ae;e[41]!==f.length||e[42]!==a?(ae=a("settings.skills.sidebar.total",{count:f.length}),e[41]=f.length,e[42]=a,e[43]=ae):ae=e[43];let fe;e[44]!==ae?(fe=t.jsx("span",{className:"typography-meta text-muted-foreground",children:ae}),e[44]=ae,e[45]=fe):fe=e[45];let Ce;e[46]===Symbol.for("react.memo_cache_sentinel")?(Ce=t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[46]=Ce):Ce=e[46];let ge;e[47]!==v?(ge=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:v,children:Ce}),e[47]=v,e[48]=ge):ge=e[48];let ve;e[49]!==fe||e[50]!==ge?(ve=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[fe,ge]}),e[49]=fe,e[50]=ge,e[51]=ve):ve=e[51];let Ne;e[52]!==se||e[53]!==ve?(Ne=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[se,xe,ve]}),e[52]=se,e[53]=ve,e[54]=Ne):Ne=e[54];let ne;e[55]!==O||e[56]!==H||e[57]!==S||e[58]!==n||e[59]!==d||e[60]!==te||e[61]!==h||e[62]!==y||e[63]!==f.length||e[64]!==a||e[65]!==N?(ne=t.jsx(Ht,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:f.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(D,{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:[te.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")}),O.sortedGroups.map(me=>{const{name:et,skills:nt}=me;return t.jsx(fi,{label:et,count:nt.length,storageKey:"project-skills",children:nt.map(tt=>t.jsx(Ua,{skill:tt,isSelected:h===tt.name,onSelect:()=>{y(tt.name),n?.()},onRename:()=>z(tt),onDelete:()=>E(tt),onDuplicate:()=>S(tt),isMenuOpen:d===tt.name,onMenuOpenChange:ft=>b(ft?tt.name:null)},tt.name))},et)}),O.ungrouped.map(me=>t.jsx(Ua,{skill:me,isSelected:h===me.name,onSelect:()=>{y(me.name),n?.()},onRename:()=>z(me),onDelete:()=>E(me),onDuplicate:()=>S(me),isMenuOpen:d===me.name,onMenuOpenChange:et=>b(et?me.name:null)},me.name))]}),N.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")}),H.sortedGroups.map(me=>{const{name:et,skills:nt}=me;return t.jsx(fi,{label:et,count:nt.length,storageKey:"user-skills",children:nt.map(tt=>t.jsx(Ua,{skill:tt,isSelected:h===tt.name,onSelect:()=>{y(tt.name),n?.()},onRename:()=>z(tt),onDelete:()=>E(tt),onDuplicate:()=>S(tt),isMenuOpen:d===tt.name,onMenuOpenChange:ft=>b(ft?tt.name:null)},tt.name))},et)}),H.ungrouped.map(me=>t.jsx(Ua,{skill:me,isSelected:h===me.name,onSelect:()=>{y(me.name),n?.()},onRename:()=>z(me),onDelete:()=>E(me),onDuplicate:()=>S(me),isMenuOpen:d===me.name,onMenuOpenChange:et=>b(et?me.name:null)},me.name))]})]})}),e[55]=O,e[56]=H,e[57]=S,e[58]=n,e[59]=d,e[60]=te,e[61]=h,e[62]=y,e[63]=f.length,e[64]=a,e[65]=N,e[66]=ne):ne=e[66];const re=c!==null;let ye;e[67]!==m?(ye=me=>{!me&&!m&&x(null)},e[67]=m,e[68]=ye):ye=e[68];let q;e[69]!==a?(q=a("settings.skills.sidebar.deleteDialog.title"),e[69]=a,e[70]=q):q=e[70];let $;e[71]!==q?($=t.jsx(Ot,{children:q}),e[71]=q,e[72]=$):$=e[72];const ee=c?.name??"";let de;e[73]!==a||e[74]!==ee?(de=a("settings.skills.sidebar.deleteDialog.description",{name:ee}),e[73]=a,e[74]=ee,e[75]=de):de=e[75];let De;e[76]!==de?(De=t.jsx(Bt,{children:de}),e[76]=de,e[77]=De):De=e[77];let ke;e[78]!==$||e[79]!==De?(ke=t.jsxs(zt,{children:[$,De]}),e[78]=$,e[79]=De,e[80]=ke):ke=e[80];let Pe;e[81]===Symbol.for("react.memo_cache_sentinel")?(Pe=()=>x(null),e[81]=Pe):Pe=e[81];let Me;e[82]!==a?(Me=a("settings.common.actions.cancel"),e[82]=a,e[83]=Me):Me=e[83];let Te;e[84]!==m||e[85]!==Me?(Te=t.jsx(J,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Pe,disabled:m,children:Me}),e[84]=m,e[85]=Me,e[86]=Te):Te=e[86];let Ve;e[87]!==a?(Ve=a("settings.common.actions.delete"),e[87]=a,e[88]=Ve):Ve=e[88];let Ue;e[89]!==U||e[90]!==m||e[91]!==Ve?(Ue=t.jsx(J,{size:"sm",onClick:U,disabled:m,children:Ve}),e[89]=U,e[90]=m,e[91]=Ve,e[92]=Ue):Ue=e[92];let Oe;e[93]!==Te||e[94]!==Ue?(Oe=t.jsxs(qt,{children:[Te,Ue]}),e[93]=Te,e[94]=Ue,e[95]=Oe):Oe=e[95];let _e;e[96]!==ke||e[97]!==Oe?(_e=t.jsxs(Tt,{className:"max-w-md",children:[ke,Oe]}),e[96]=ke,e[97]=Oe,e[98]=_e):_e=e[98];let Ke;e[99]!==re||e[100]!==ye||e[101]!==_e?(Ke=t.jsx(Mt,{open:re,onOpenChange:ye,children:_e}),e[99]=re,e[100]=ye,e[101]=_e,e[102]=Ke):Ke=e[102];const Qe=r!==null;let Fe;e[103]===Symbol.for("react.memo_cache_sentinel")?(Fe=me=>!me&&i(null),e[103]=Fe):Fe=e[103];let V;e[104]!==a?(V=a("settings.skills.sidebar.renameDialog.title"),e[104]=a,e[105]=V):V=e[105];let le;e[106]!==V?(le=t.jsx(Ot,{children:V}),e[106]=V,e[107]=le):le=e[107];const pe=r?.name??"";let Le;e[108]!==a||e[109]!==pe?(Le=a("settings.skills.sidebar.renameDialog.description",{name:pe}),e[108]=a,e[109]=pe,e[110]=Le):Le=e[110];let we;e[111]!==Le?(we=t.jsx(Bt,{children:Le}),e[111]=Le,e[112]=we):we=e[112];let He;e[113]!==le||e[114]!==we?(He=t.jsxs(zt,{children:[le,we]}),e[113]=le,e[114]=we,e[115]=He):He=e[115];let X;e[116]===Symbol.for("react.memo_cache_sentinel")?(X=me=>u(me.target.value),e[116]=X):X=e[116];let j;e[117]!==a?(j=a("settings.skills.sidebar.renameDialog.placeholder"),e[117]=a,e[118]=j):j=e[118];let be;e[119]!==Z?(be=me=>{me.key==="Enter"&&Z()},e[119]=Z,e[120]=be):be=e[120];let Ae;e[121]!==l||e[122]!==j||e[123]!==be?(Ae=t.jsx(Xe,{value:l,onChange:X,placeholder:j,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:be}),e[121]=l,e[122]=j,e[123]=be,e[124]=Ae):Ae=e[124];let ze;e[125]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>i(null),e[125]=ze):ze=e[125];let Ge;e[126]!==a?(Ge=a("settings.common.actions.cancel"),e[126]=a,e[127]=Ge):Ge=e[127];let rt;e[128]!==Ge?(rt=t.jsx(J,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:ze,children:Ge}),e[128]=Ge,e[129]=rt):rt=e[129];let it;e[130]!==a?(it=a("settings.common.actions.rename"),e[130]=a,e[131]=it):it=e[131];let at;e[132]!==Z||e[133]!==it?(at=t.jsx(J,{size:"sm",onClick:Z,children:it}),e[132]=Z,e[133]=it,e[134]=at):at=e[134];let lt;e[135]!==rt||e[136]!==at?(lt=t.jsxs(qt,{children:[rt,at]}),e[135]=rt,e[136]=at,e[137]=lt):lt=e[137];let Ye;e[138]!==He||e[139]!==Ae||e[140]!==lt?(Ye=t.jsxs(Tt,{children:[He,Ae,lt]}),e[138]=He,e[139]=Ae,e[140]=lt,e[141]=Ye):Ye=e[141];let We;e[142]!==Qe||e[143]!==Ye?(We=t.jsx(Mt,{open:Qe,onOpenChange:Fe,children:Ye}),e[142]=Qe,e[143]=Ye,e[144]=We):We=e[144];let gt;return e[145]!==Ne||e[146]!==ne||e[147]!==Ke||e[148]!==We?(gt=t.jsxs("div",{className:ie,children:[Ne,ne,Ke,We]}),e[145]=Ne,e[146]=ne,e[147]=Ke,e[148]=We,e[149]=gt):gt=e[149],gt},Ua=s=>{const e=Ze.c(49),{skill:n,isSelected:a,onSelect:r,onDelete:i,onRename:l,onDuplicate:u,isMenuOpen:c,onMenuOpenChange:x}=s,{t:m}=st();let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=ba(),e[0]=g):g=e[0];const d=g;let b;e[1]!==n.source||e[2]!==m?(b=n.source==="claude"?m("settings.skills.sidebar.badge.claude"):n.source==="agents"?m("settings.skills.sidebar.badge.agents"):m("settings.skills.sidebar.badge.opencode"),e[1]=n.source,e[2]=m,e[3]=b):b=e[3];const h=b;let f;e[4]!==n?(f=Vn(n),e[4]=n,e[5]=f):f=e[5];const y=f,[P,I]=o.useState(!1);let C;e[6]!==i||e[7]!==u||e[8]!==l||e[9]!==m?(C=N=>t.jsxs(t.Fragment,{children:[t.jsxs(N,{onClick:W=>{W.stopPropagation(),l()},children:[t.jsx(D,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),t.jsxs(N,{onClick:W=>{W.stopPropagation(),u()},children:[t.jsx(D,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),t.jsxs(N,{onClick:W=>{W.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[6]=i,e[7]=u,e[8]=l,e[9]=m,e[10]=C):C=e[10];const L=C,k=!y&&P,v=a?"bg-interactive-selection":"hover:bg-interactive-hover";let w;e[11]!==v?(w=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",v),e[11]=v,e[12]=w):w=e[12];let E;e[13]!==y?(E=!d&&!y?N=>{N.preventDefault(),I(!0)}:void 0,e[13]=y,e[14]=E):E=e[14];let K;e[15]!==w||e[16]!==E?(K=t.jsx("div",{className:w,onContextMenu:E}),e[15]=w,e[16]=E,e[17]=K):K=e[17];let U;e[18]!==n.name?(U=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[18]=n.name,e[19]=U):U=e[19];let M;e[20]!==n.scope?(M=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]=M):M=e[21];let S;e[22]!==h?(S=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:h}),e[22]=h,e[23]=S):S=e[23];let A;e[24]!==U||e[25]!==M||e[26]!==S?(A=t.jsxs("div",{className:"flex items-center gap-1.5",children:[U,M,S]}),e[24]=U,e[25]=M,e[26]=S,e[27]=A):A=e[27];let z;e[28]!==r||e[29]!==A?(z=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:A}),e[28]=r,e[29]=A,e[30]=z):z=e[30];let T;e[31]!==y||e[32]!==c||e[33]!==x||e[34]!==L?(T=y?null:t.jsxs(gs,{open:c,onOpenChange:N=>{N&&I(!1),x(N)},children:[t.jsx(ms,{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(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:L(Ns)})]}),e[31]=y,e[32]=c,e[33]=x,e[34]=L,e[35]=T):T=e[35];let Z;e[36]!==z||e[37]!==T?(Z=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[z,T]}),e[36]=z,e[37]=T,e[38]=Z):Z=e[38];let G;e[39]!==Z||e[40]!==K?(G=t.jsx(bn,{render:K,children:Z}),e[39]=Z,e[40]=K,e[41]=G):G=e[41];let te;e[42]!==y||e[43]!==L?(te=y?null:t.jsx(vn,{className:"w-fit min-w-20",children:L(ln)}),e[42]=y,e[43]=L,e[44]=te):te=e[44];let Y;return e[45]!==G||e[46]!==te||e[47]!==k?(Y=t.jsxs(yn,{open:k,onOpenChange:I,children:[G,te]}),e[45]=G,e[46]=te,e[47]=k,e[48]=Y):Y=e[48],Y};function Lh(s){return{selectedSkillName:s.selectedSkillName,skills:s.skills,setSelectedSkill:s.setSelectedSkill,setSkillDraft:s.setSkillDraft,createSkill:s.createSkill,deleteSkill:s.deleteSkill,getSkillDetail:s.getSkillDetail}}function Oh(s){return s.scope==="project"}function zh(s){return s.scope==="user"}function Kh(s,e){return s.localeCompare(e)}function Uh(s,e){return s.name.localeCompare(e.name)}function Bh(s,e){return s.name.localeCompare(e.name)}const $h=s=>s!==null&&typeof s=="object"&&"updateStatus"in s&&typeof s.updateStatus=="function",Vh=s=>{const e=document.createElement("div");e.className="cm-vim-panel";const n=Fd(s);if(!n)return{top:!1,dom:e};n.state.statusbar=e;const a=n.state.vimPlugin;return $h(a)&&a.updateStatus(),{top:!1,dom:e,destroy(){n.state.statusbar===e&&(n.state.statusbar=null)}}};function Ho(s){return s?[Md(),Td.of(Vh),Rd()]:[]}const _h={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},Hh={case:"Match case",re:"Regular expression",word:"Match whole word"};function Wh(s){const e=s.querySelector(".cm-search");if(e){for(const[n,a]of Object.entries(_h)){const r=e.querySelector(`button[name="${n}"]`);r&&!r.title&&(r.title=a)}for(const[n,a]of Object.entries(Hh)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=a)}}}const Kr=new WeakMap;function Gh(s,e){const n=nr(s.state);if(!n.valid)return Kr.delete(s),0;const a=Kr.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 l=r.next();!l.done;l=r.next())i+=1;return Kr.set(s,{query:n,doc:s.state.doc,total:i}),i}function qh(s){const e=nr(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 l=a.next();!l.done;l=a.next()){const u=l.value;if(r+=1,i===0&&(i=r),n.from===u.from&&n.to===u.to||n.from<u.to&&n.to>u.from||u.from>=n.head)return r}return i}function Wo(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 u=a.querySelector('button[name="next"]'),c=u?.parentNode===a?u:a.firstChild;a.insertBefore(r,c)}const i=Gh(e,n),l=i===0?0:qh(e);r.textContent=i===0?"":`${l}/${i}`}const Go=new Fn,qo=new Fn,Jo=new Fn,Qo=new Fn,Yo=new Fn,Xo=new Fn,Zo=new Fn,el=s=>s,Ur=Vd,Jh=_d,Qh=Hd;class Yh extends Wd{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 tl=(s,e)=>!s||s.length===0?[]:sc.define({create(n){const a=new Pi,r=[...s].sort((i,l)=>i.afterLine-l.afterLine);for(const i of r){const l=n.doc.lines;if(i.afterLine>l)continue;const u=n.doc.line(i.afterLine);a.add(u.to,u.to,cr.widget({widget:new Yh(i.id,e),block:!0,side:1}))}return a.finish()},update(n,a){return n.map(a.changes)},provide:n=>Ws.decorations.from(n)}),sl=s=>{if(!s)return[];const e=Math.max(1,s.start),n=Math.max(e,s.end);return tc.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 Pi;for(let i=e;i<=n&&i<=a.state.doc.lines;i+=1){const l=a.state.doc.line(i);r.add(l.from,l.from,cr.line({class:"oc-cm-selected-line"}))}return r.finish()}},{decorations:a=>a.decorations})};function nl({value:s,onChange:e,extensions:n,className:a,readOnly:r,lineNumbersConfig:i,highlightLines:l,onViewReady:u,onViewDestroy:c,blockWidgets:x,enableSearch:m,searchOpen:g,onSearchOpenChange:d,vimMode:b}){const h=o.useRef(null),f=o.useRef(null),y=o.useRef(s),P=o.useRef(e),I=o.useRef(u),C=o.useRef(c),L=o.useRef(d),k=o.useRef(x),v=o.useRef(b),w=o.useRef(new Map),[E,K]=o.useState([]),U=o.useCallback(S=>{const A=(S??[]).map(z=>{const T=w.current.get(z.id);return T?{id:z.id,content:z.content,container:T}:null}).filter(z=>z!==null);K(z=>z.length===A.length&&z.every((T,Z)=>{const G=A[Z];return T.id===G.id&&T.content===G.content&&T.container===G.container})?z:A)},[]),M=o.useCallback(S=>{const A=h.current,z=S??f.current;if(!A||!z)return;const T=z.dom.querySelector(".cm-gutters"),Z=T instanceof HTMLElement?T.getBoundingClientRect().width:0;A.style.setProperty("--oc-editor-gutter-width",`${Z}px`)},[]);return o.useEffect(()=>{y.current=s},[s]),o.useEffect(()=>{P.current=e},[e]),o.useEffect(()=>{I.current=u,C.current=c},[u,c]),o.useEffect(()=>{L.current=d},[d]),o.useEffect(()=>{k.current=x,U(x)},[x,U]),o.useEffect(()=>{if(!h.current)return;const S=(()=>{if(typeof document>"u")return null;const z=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(z)return z;const T=window.__OPENCHAMBER_CSP_NONCE__;return typeof T=="string"&&T.length>0?T:null})(),A=Ld.create({doc:y.current,extensions:[...S?[Ws.cspNonce.of(S)]:[],Od({fixed:!0}),Go.of(Ui(i)),zd(),Kd.of(" "),Zo.of(Ho(b)),kr.of([Ud,...Bd,...$d]),Ws.updateListener.of(z=>{M(z.view),(z.viewportChanged||z.geometryChanged)&&U(k.current);const T=Bi(z.startState),Z=Bi(z.state);T!==Z&&L.current?.(Z);const G=!nr(z.startState).eq(nr(z.state));if(Z&&(T!==Z||G||z.docChanged||z.selectionSet)&&Wo(z.view.dom,z.view,T!==Z||G||z.docChanged),!z.docChanged)return;const te=z.state.doc.toString();y.current=te,P.current(te),U(k.current)}),qo.of(Ws.editable.of(!r)),Jo.of(n??[]),Qo.of(sl(l)),Yo.of(tl(x,w.current)),Xo.of(m?[$i({top:!0}),kr.of(el(Vi))]:[])]});return f.current=new Ws({state:A,parent:h.current}),Ur(f.current,f.current.state.doc.length,200),f.current.requestMeasure(),requestAnimationFrame(()=>{M(f.current),U(k.current)}),f.current&&I.current?.(f.current),()=>{C.current?.(),f.current?.destroy(),f.current=null,K([])}},[k,M,U]),o.useEffect(()=>{const S=f.current;S&&(S.dispatch({effects:[Go.reconfigure(Ui(i)),qo.reconfigure(Ws.editable.of(!r)),Jo.reconfigure(n??[]),Qo.reconfigure(sl(l)),Yo.reconfigure(tl(x,w.current)),Xo.reconfigure(m?[$i({top:!0}),kr.of(el(Vi))]:[])]}),Ur(S,S.state.doc.length,200),S.requestMeasure(),requestAnimationFrame(()=>{M(S),U(k.current)}))},[n,l,i,r,x,m,M,U]),o.useEffect(()=>{const S=f.current;if(!S){v.current=b;return}v.current!==b&&(v.current=b,S.dispatch({effects:Zo.reconfigure(Ho(b))}))},[b]),o.useEffect(()=>{const S=f.current;!S||m===!1||(g?(Jh(S),requestAnimationFrame(()=>{Wh(S.dom),Wo(S.dom,S,!0)})):Qh(S))},[g,m]),o.useEffect(()=>{const S=f.current;if(!S)return;const A=S.state.doc.toString();A!==s&&(S.dispatch({changes:{from:0,to:A.length,insert:s}}),Ur(S,S.state.doc.length,300),S.requestMeasure(),requestAnimationFrame(()=>M(S)))},[s,M]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:h,className:ce("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)}),E.map(S=>Ga.createPortal(S.content,S.container,S.id))]})}const Xh=s=>{const e=Ze.c(11),{currentMode:n,onToggle:a}=s,r=n==="preview",i=r?"Switch to edit mode":"Switch to preview mode",l=r?"Edit":"Preview";let u;e[0]!==r?(u=r?t.jsx(D,{name:"eye",className:"size-4","aria-hidden":"true"}):t.jsx(D,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=r,e[1]=u):u=e[1];let c;e[2]!==i||e[3]!==a||e[4]!==u?(c=t.jsx(Ct,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"sm",onClick:a,"aria-label":i,className:"h-5 w-5 p-0",children:u})}),e[2]=i,e[3]=a,e[4]=u,e[5]=c):c=e[5];let x;e[6]!==l?(x=t.jsx(It,{sideOffset:8,children:l}),e[6]=l,e[7]=x):x=e[7];let m;return e[8]!==c||e[9]!==x?(m=t.jsxs(St,{children:[c,x]}),e[8]=c,e[9]=x,e[10]=m):m=e[10],m},Is=Nn()(wa(Ii((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 Cu();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 Su();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 ku();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=qs()?.settings;if(r)try{const l=(await r.load())?.settings||{};a=n(l.defaultGitIdentityId)}catch{}}if(a===null)try{const r=await dt("/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 wt({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 Nu(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(l=>l.id===n);if(!r)throw new Error("Profile not found");const i={...r,...a};return await wu(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 ju(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:Ei(),partialize:s=>({selectedProfileId:s.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Is);const Zh=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,ef=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},tf=async()=>{try{const s=qs()?.settings;if(s)return(await s.load())?.settings||{};const e=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},sf=s=>{const e=Ze.c(160),{open:n,onOpenChange:a}=s,{t:r}=st(),i=sn(nf),l=sn(af),u=sn(rf),c=sn(of),x=sn(lf),m=Is(cf),g=Is(df),[d,b]=o.useState(""),[h,f]=o.useState(""),[y,P]=o.useState("");let I;e[0]===Symbol.for("react.memo_cache_sentinel")?(I=[],e[0]=I):I=e[0];const[C,L]=o.useState(I),[k,v]=o.useState(null),[w,E]=o.useState(!1);let K;e[1]===Symbol.for("react.memo_cache_sentinel")?(K=[],e[1]=K):K=e[1];const[U,M]=o.useState(K),[S,A]=o.useState(null),z=o.useRef(0);let T;e[2]===Symbol.for("react.memo_cache_sentinel")?(T=me=>{z.current=z.current+1,E(!1),v(null),me?.clearIdentity&&(M([]),A(null))},e[2]=T):T=e[2];const Z=T;let G,te;e[3]!==g||e[4]!==n?(G=()=>{n&&(z.current=z.current+1,b(""),f(""),P(""),v(null),E(!1),M([]),A(null),g(),(async()=>{const me=await tf(),et=Array.isArray(me?.skillCatalogs)?me?.skillCatalogs:[];L(et||[])})())},te=[n,g],e[3]=g,e[4]=n,e[5]=G,e[6]=te):(G=e[5],te=e[6]),o.useEffect(G,te);let Y;e[7]!==h?(Y=h.trim(),e[7]=h,e[8]=Y):Y=e[8];const N=Y;let W;e[9]!==y?(W=y.trim(),e[9]=y,e[10]=W):W=e[10];const B=W;let F;if(e[11]!==C||e[12]!==N||e[13]!==B){let me;e[15]!==N||e[16]!==B?(me=et=>{const nt=(et.source||"").trim(),tt=(et.subpath||"").trim();return nt===N&&tt===B},e[15]=N,e[16]=B,e[17]=me):me=e[17],F=C.some(me),e[11]=C,e[12]=N,e[13]=B,e[14]=F}else F=e[14];const O=F;let Q;e[18]!==m||e[19]!==S||e[20]!==d||e[21]!==i||e[22]!==h||e[23]!==y||e[24]!==r?(Q=async()=>{const me=h.trim();if(!me){_.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}d.trim()||b(ef(me)),E(!1),v(null);const et=z.current+1;z.current=et;const nt=await i({source:me,subpath:y.trim()||void 0,gitIdentityId:S||void 0});if(z.current!==et)return;if(!nt.ok){if(nt.error?.kind==="authRequired"){if(rs()){_.error(r("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const ft=nt.error.identities||[];if(M(ft),!S&&ft.length>0){const bt=m&&m!=="global"&&ft.some(Rt=>Rt.id===m)?m:ft[0].id;A(bt)}_.error(r("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}_.error(nt.error?.message||r("settings.skills.catalog.add.toast.scanFailed"));return}const tt=nt.items?.length||0;if(v(tt),tt===0){_.error(r("settings.skills.catalog.add.toast.noSkillsFound")),E(!1);return}M([]),E(!0),_.success(r("settings.skills.catalog.shared.toast.foundSkills",{count:tt}))},e[18]=m,e[19]=S,e[20]=d,e[21]=i,e[22]=h,e[23]=y,e[24]=r,e[25]=Q):Q=e[25];const H=Q;let ie;e[26]!==C||e[27]!==S||e[28]!==O||e[29]!==d||e[30]!==l||e[31]!==u||e[32]!==a||e[33]!==w||e[34]!==c||e[35]!==h||e[36]!==y||e[37]!==r?(ie=async()=>{const me=d.trim(),et=h.trim(),nt=y.trim();if(!me){_.error(r("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!et){_.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!w){_.error(r("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(O){_.error(r("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const tt={id:Zh(),label:me,source:et,...nt?{subpath:nt}:{},...S?{gitIdentityId:S}:{}},ft=[...C,tt];try{await wt({skillCatalogs:ft}),L(ft),_.success(r("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await u(tt.id,{refresh:!0}),c(tt.id),a(!1)}catch(bt){const Rt=bt;_.error(Rt instanceof Error?Rt.message:r("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=C,e[27]=S,e[28]=O,e[29]=d,e[30]=l,e[31]=u,e[32]=a,e[33]=w,e[34]=c,e[35]=h,e[36]=y,e[37]=r,e[38]=ie):ie=e[38];const oe=ie;let se;e[39]!==r?(se=r("settings.skills.catalog.add.title"),e[39]=r,e[40]=se):se=e[40];let xe;e[41]!==se?(xe=t.jsx(Ot,{children:se}),e[41]=se,e[42]=xe):xe=e[42];let ae;e[43]!==r?(ae=r("settings.skills.catalog.add.descriptionPrefix"),e[43]=r,e[44]=ae):ae=e[44];let fe;e[45]===Symbol.for("react.memo_cache_sentinel")?(fe=t.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=fe):fe=e[45];let Ce;e[46]!==r?(Ce=r("settings.skills.catalog.add.descriptionSuffix"),e[46]=r,e[47]=Ce):Ce=e[47];let ge;e[48]!==ae||e[49]!==Ce?(ge=t.jsxs(Bt,{children:[ae," ",fe,Ce]}),e[48]=ae,e[49]=Ce,e[50]=ge):ge=e[50];let ve;e[51]!==xe||e[52]!==ge?(ve=t.jsxs(zt,{children:[xe,ge]}),e[51]=xe,e[52]=ge,e[53]=ve):ve=e[53];let Ne;e[54]!==r?(Ne=r("settings.skills.catalog.add.field.catalogName"),e[54]=r,e[55]=Ne):Ne=e[55];let ne;e[56]!==Ne?(ne=t.jsx("label",{className:"typography-ui-label text-foreground",children:Ne}),e[56]=Ne,e[57]=ne):ne=e[57];let re;e[58]===Symbol.for("react.memo_cache_sentinel")?(re=me=>b(me.target.value),e[58]=re):re=e[58];let ye;e[59]!==r?(ye=r("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=r,e[60]=ye):ye=e[60];let q;e[61]!==d||e[62]!==ye?(q=t.jsx(Xe,{value:d,onChange:re,placeholder:ye}),e[61]=d,e[62]=ye,e[63]=q):q=e[63];let $;e[64]!==ne||e[65]!==q?($=t.jsxs("div",{className:"space-y-2",children:[ne,q]}),e[64]=ne,e[65]=q,e[66]=$):$=e[66];let ee;e[67]!==r?(ee=r("settings.skills.catalog.add.field.repository"),e[67]=r,e[68]=ee):ee=e[68];let de;e[69]!==ee?(de=t.jsx("label",{className:"typography-ui-label text-foreground",children:ee}),e[69]=ee,e[70]=de):de=e[70];let De;e[71]===Symbol.for("react.memo_cache_sentinel")?(De=me=>{f(me.target.value),Z({clearIdentity:!0})},e[71]=De):De=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 Pe;e[74]!==h||e[75]!==ke?(Pe=t.jsx(Xe,{value:h,onChange:De,placeholder:ke}),e[74]=h,e[75]=ke,e[76]=Pe):Pe=e[76];let Me;e[77]!==r?(Me=r("settings.skills.catalog.add.field.repositoryHint"),e[77]=r,e[78]=Me):Me=e[78];let Te;e[79]!==Me?(Te=t.jsx("p",{className:"typography-micro text-muted-foreground",children:Me}),e[79]=Me,e[80]=Te):Te=e[80];let Ve;e[81]!==de||e[82]!==Pe||e[83]!==Te?(Ve=t.jsxs("div",{className:"space-y-2",children:[de,Pe,Te]}),e[81]=de,e[82]=Pe,e[83]=Te,e[84]=Ve):Ve=e[84];let Ue;e[85]!==r?(Ue=r("settings.skills.catalog.add.field.optionalSubpath"),e[85]=r,e[86]=Ue):Ue=e[86];let Oe;e[87]!==Ue?(Oe=t.jsx("label",{className:"typography-ui-label text-foreground",children:Ue}),e[87]=Ue,e[88]=Oe):Oe=e[88];let _e;e[89]===Symbol.for("react.memo_cache_sentinel")?(_e=me=>{P(me.target.value),Z({clearIdentity:!0})},e[89]=_e):_e=e[89];let Ke;e[90]!==r?(Ke=r("settings.skills.catalog.shared.field.subpathPlaceholder"),e[90]=r,e[91]=Ke):Ke=e[91];let Qe;e[92]!==y||e[93]!==Ke?(Qe=t.jsx(Xe,{value:y,onChange:_e,placeholder:Ke}),e[92]=y,e[93]=Ke,e[94]=Qe):Qe=e[94];let Fe;e[95]!==Oe||e[96]!==Qe?(Fe=t.jsxs("div",{className:"space-y-2",children:[Oe,Qe]}),e[95]=Oe,e[96]=Qe,e[97]=Fe):Fe=e[97];let V;e[98]!==S||e[99]!==U||e[100]!==r?(V=U.length>0&&!rs()?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(Pt,{value:S||"",onValueChange:me=>{A(me),Z()},children:[t.jsx(At,{className:"w-fit",children:t.jsx("span",{children:U.find(me=>me.id===S)?.name||r("settings.skills.catalog.shared.auth.chooseIdentity")})}),t.jsx(Dt,{align:"start",children:U.map(uf)})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:r("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[98]=S,e[99]=U,e[100]=r,e[101]=V):V=e[101];let le;e[102]!==k||e[103]!==r?(le=k!==null?t.jsx("div",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.add.scanResult",{count:k})}):null,e[102]=k,e[103]=r,e[104]=le):le=e[104];let pe;e[105]!==O||e[106]!==r?(pe=O?t.jsx("div",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.add.duplicateMessage")}):null,e[105]=O,e[106]=r,e[107]=pe):pe=e[107];let Le;e[108]!==$||e[109]!==Ve||e[110]!==Fe||e[111]!==V||e[112]!==le||e[113]!==pe?(Le=t.jsxs("div",{className:"space-y-4",children:[$,Ve,Fe,V,le,pe]}),e[108]=$,e[109]=Ve,e[110]=Fe,e[111]=V,e[112]=le,e[113]=pe,e[114]=Le):Le=e[114];let we;e[115]!==a?(we=()=>a(!1),e[115]=a,e[116]=we):we=e[116];let He;e[117]!==r?(He=r("settings.common.actions.cancel"),e[117]=r,e[118]=He):He=e[118];let X;e[119]!==we||e[120]!==He?(X=t.jsx(J,{size:"sm",variant:"ghost",onClick:we,children:He}),e[119]=we,e[120]=He,e[121]=X):X=e[121];let j;e[122]!==H?(j=()=>{H()},e[122]=H,e[123]=j):j=e[123];let be;e[124]!==x||e[125]!==h?(be=x||!h.trim(),e[124]=x,e[125]=h,e[126]=be):be=e[126];let Ae;e[127]===Symbol.for("react.memo_cache_sentinel")?(Ae=t.jsx(D,{name:"git-repository",className:"h-4 w-4"}),e[127]=Ae):Ae=e[127];let ze;e[128]!==x||e[129]!==r?(ze=r(x?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[128]=x,e[129]=r,e[130]=ze):ze=e[130];let Ge;e[131]!==j||e[132]!==be||e[133]!==ze?(Ge=t.jsxs(J,{size:"sm",className:"gap-2",variant:"ghost",onClick:j,disabled:be,children:[Ae,ze]}),e[131]=j,e[132]=be,e[133]=ze,e[134]=Ge):Ge=e[134];let rt;e[135]!==oe?(rt=()=>{oe()},e[135]=oe,e[136]=rt):rt=e[136];let it;e[137]!==O||e[138]!==d||e[139]!==w||e[140]!==h?(it=!w||O||!d.trim()||!h.trim(),e[137]=O,e[138]=d,e[139]=w,e[140]=h,e[141]=it):it=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]!==rt||e[145]!==it||e[146]!==at?(lt=t.jsx(J,{size:"sm",onClick:rt,disabled:it,children:at}),e[144]=rt,e[145]=it,e[146]=at,e[147]=lt):lt=e[147];let Ye;e[148]!==X||e[149]!==Ge||e[150]!==lt?(Ye=t.jsxs(qt,{children:[X,Ge,lt]}),e[148]=X,e[149]=Ge,e[150]=lt,e[151]=Ye):Ye=e[151];let We;e[152]!==ve||e[153]!==Le||e[154]!==Ye?(We=t.jsxs(Tt,{className:"max-w-xl",children:[ve,Le,Ye]}),e[152]=ve,e[153]=Le,e[154]=Ye,e[155]=We):We=e[155];let gt;return e[156]!==a||e[157]!==n||e[158]!==We?(gt=t.jsx(Mt,{open:n,onOpenChange:a,children:We}),e[156]=a,e[157]=n,e[158]=We,e[159]=gt):gt=e[159],gt};function nf(s){return s.scanRepo}function af(s){return s.loadCatalog}function rf(s){return s.loadSource}function of(s){return s.setSelectedSource}function lf(s){return s.isScanning}function cf(s){return s.defaultGitIdentityId}function df(s){return s.loadDefaultGitIdentityId}function uf(s){return t.jsx(ut,{value:s.id,children:s.name},s.id)}const mf=s=>{const e=Ze.c(85),{open:n,onOpenChange:a,conflicts:r,onConfirm:i}=s,{t:l}=st();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={},e[0]=u):u=e[0];const[c,x]=o.useState(u);let m,g;e[1]!==r||e[2]!==n?(m=()=>{if(!n)return;const oe={};for(const se of r)oe[se.skillName]="skip";x(oe)},g=[n,r],e[1]=r,e[2]=n,e[3]=m,e[4]=g):(m=e[3],g=e[4]),o.useEffect(m,g);let d;e[5]!==r?(d=oe=>{const se={};for(const xe of r)se[xe.skillName]=oe;x(se)},e[5]=r,e[6]=d):d=e[6];const b=d;let h;e[7]!==r||e[8]!==c?(h=r.length>0&&r.every(oe=>c[oe.skillName]),e[7]=r,e[8]=c,e[9]=h):h=e[9];const f=h;let y;e[10]!==l?(y=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=y):y=e[11];let P;e[12]!==y?(P=t.jsx(Ot,{children:y}),e[12]=y,e[13]=P):P=e[13];let I;e[14]!==l?(I=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=I):I=e[15];let C;e[16]!==I?(C=t.jsx(Bt,{children:I}),e[16]=I,e[17]=C):C=e[17];let L;e[18]!==P||e[19]!==C?(L=t.jsxs(zt,{children:[P,C]}),e[18]=P,e[19]=C,e[20]=L):L=e[20];let k;e[21]!==r.length||e[22]!==l?(k=l("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=l,e[23]=k):k=e[23];let v;e[24]!==k?(v=t.jsx("span",{className:"typography-meta text-muted-foreground",children:k}),e[24]=k,e[25]=v):v=e[25];let w;e[26]!==b?(w=()=>b("skip"),e[26]=b,e[27]=w):w=e[27];let E;e[28]!==l?(E=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=E):E=e[29];let K;e[30]!==w||e[31]!==E?(K=t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:w,children:E}),e[30]=w,e[31]=E,e[32]=K):K=e[32];let U;e[33]!==b?(U=()=>b("overwrite"),e[33]=b,e[34]=U):U=e[34];let M;e[35]!==l?(M=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=M):M=e[36];let S;e[37]!==U||e[38]!==M?(S=t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:U,children:M}),e[37]=U,e[38]=M,e[39]=S):S=e[39];let A;e[40]!==K||e[41]!==S?(A=t.jsxs("div",{className:"flex items-center gap-2",children:[K,S]}),e[40]=K,e[41]=S,e[42]=A):A=e[42];let z;e[43]!==v||e[44]!==A?(z=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[v,A]}),e[43]=v,e[44]=A,e[45]=z):z=e[45];let T;if(e[46]!==r||e[47]!==c||e[48]!==l){let oe;e[50]!==c||e[51]!==l?(oe=se=>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:se.skillName}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:se.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:se.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),t.jsxs(Pt,{value:c[se.skillName]||"skip",onValueChange:xe=>x(ae=>({...ae,[se.skillName]:xe})),children:[t.jsx(At,{className:"w-fit",children:t.jsx("span",{className:"capitalize",children:(c[se.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),t.jsxs(Dt,{align:"end",children:[t.jsx(ut,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),t.jsx(ut,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},se.skillName),e[50]=c,e[51]=l,e[52]=oe):oe=e[52],T=r.map(oe),e[46]=r,e[47]=c,e[48]=l,e[49]=T}else T=e[49];let Z;e[53]!==T?(Z=t.jsx("div",{className:"space-y-2",children:T}),e[53]=T,e[54]=Z):Z=e[54];let G;e[55]!==z||e[56]!==Z?(G=t.jsxs("div",{className:"space-y-3",children:[z,Z]}),e[55]=z,e[56]=Z,e[57]=G):G=e[57];let te;e[58]!==a?(te=()=>a(!1),e[58]=a,e[59]=te):te=e[59];let Y;e[60]!==l?(Y=l("settings.common.actions.cancel"),e[60]=l,e[61]=Y):Y=e[61];let N;e[62]!==te||e[63]!==Y?(N=t.jsx(J,{size:"sm",variant:"ghost",onClick:te,children:Y}),e[62]=te,e[63]=Y,e[64]=N):N=e[64];let W;e[65]!==c||e[66]!==i?(W=()=>i(c),e[65]=c,e[66]=i,e[67]=W):W=e[67];const B=!f;let F;e[68]!==l?(F=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=F):F=e[69];let O;e[70]!==W||e[71]!==B||e[72]!==F?(O=t.jsx(J,{size:"sm",onClick:W,disabled:B,children:F}),e[70]=W,e[71]=B,e[72]=F,e[73]=O):O=e[73];let Q;e[74]!==N||e[75]!==O?(Q=t.jsxs(qt,{children:[N,O]}),e[74]=N,e[75]=O,e[76]=Q):Q=e[76];let H;e[77]!==L||e[78]!==G||e[79]!==Q?(H=t.jsxs(Tt,{className:"max-w-2xl",children:[L,G,Q]}),e[77]=L,e[78]=G,e[79]=Q,e[80]=H):H=e[80];let ie;return e[81]!==a||e[82]!==n||e[83]!==H?(ie=t.jsx(Mt,{open:n,onOpenChange:a,children:H}),e[81]=a,e[82]=n,e[83]=H,e[84]=ie):ie=e[84],ie},Ti=[{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 ya(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 Ec(s){if(s==="user-claude")return{scope:"user",source:"claude"};if(s==="project-claude")return{scope:"project",source:"claude"};const e=Ti.find(n=>n.value===s);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const pf=s=>{const e=Ze.c(124),{open:n,onOpenChange:a,item:r}=s,{t:i}=st(),l=sn(gf),u=sn(hf),[c,x]=o.useState("user"),[m,g]=o.useState("opencode"),d=es(ff),b=es(xf),[h,f]=o.useState(null),[y,P]=o.useState(!1);let I;e[0]===Symbol.for("react.memo_cache_sentinel")?(I=[],e[0]=I):I=e[0];const[C,L]=o.useState(I),[k,v]=o.useState(null);let w,E;e[1]!==b||e[2]!==n?(w=()=>{n&&(x("user"),g("opencode"),f(b),P(!1),L([]),v(null))},E=[n,b],e[1]=b,e[2]=n,e[3]=w,e[4]=E):(w=e[3],E=e[4]),o.useEffect(w,E);let K;e[5]!==i?(K=Fe=>{switch(Fe){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]=K):K=e[6];const U=K;let M;e[7]!==i?(M=Fe=>{switch(Fe){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]=M):M=e[8];const S=M;let A;e:{if(d.length===0){A=null;break e}if(h&&d.some(Fe=>Fe.id===h)){A=h;break e}if(b&&d.some(Fe=>Fe.id===b)){A=b;break e}A=d[0]?.id??null}const z=A;let T;e:{if(c!=="project"){T=null;break e}const Fe=z;if(!Fe){T=null;break e}let V;if(e[9]!==Fe||e[10]!==d){let pe;e[12]!==Fe?(pe=Le=>Le.id===Fe,e[12]=Fe,e[13]=pe):pe=e[13],V=d.find(pe),e[9]=Fe,e[10]=d,e[11]=V}else V=e[11];T=V?.path??null}const Z=T;let G;e[14]!==l||e[15]!==r||e[16]!==a||e[17]!==i?(G=async Fe=>{const V={skillDir:Fe.skillDir};r?.clawdhub&&(V.clawdhub={slug:r.clawdhub.slug,version:r.clawdhub.version});const le=await l({source:Fe.source,subpath:Fe.subpath,gitIdentityId:r?.gitIdentityId,scope:Fe.scope,targetSource:Fe.targetSource,selections:[V],conflictPolicy:"prompt",conflictDecisions:Fe.conflictDecisions},{directory:Fe.directoryOverride??null});if(le.ok){_.success(i("settings.skills.catalog.installSkill.toast.installed")),a(!1);return}if(le.error?.kind==="conflicts"){v({source:Fe.source,subpath:Fe.subpath,scope:Fe.scope,targetSource:Fe.targetSource,skillDir:Fe.skillDir,directoryOverride:Fe.directoryOverride??null}),L(le.error.conflicts),P(!0);return}if(le.error?.kind==="authRequired"){_.error(le.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}_.error(le.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=r,e[16]=a,e[17]=i,e[18]=G):G=e[18];const te=G;if(!r)return null;let Y;e[19]!==i?(Y=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=Y):Y=e[20];let N;e[21]!==Y?(N=t.jsx(Ot,{children:Y}),e[21]=Y,e[22]=N):N=e[22];let W;e[23]!==i?(W=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=W):W=e[24];let B;e[25]!==r.skillName?(B=t.jsx("span",{className:"font-semibold text-foreground",children:r.skillName}),e[25]=r.skillName,e[26]=B):B=e[26];let F;e[27]!==i?(F=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=F):F=e[28];let O;e[29]!==W||e[30]!==B||e[31]!==F?(O=t.jsxs(Bt,{children:[W," ",B," ",F]}),e[29]=W,e[30]=B,e[31]=F,e[32]=O):O=e[32];let Q;e[33]!==N||e[34]!==O?(Q=t.jsxs(zt,{children:[N,O]}),e[33]=N,e[34]=O,e[35]=Q):Q=e[35];let H;e[36]!==i?(H=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=H):H=e[37];let ie;e[38]!==H?(ie=t.jsx("span",{className:"typography-ui-label text-foreground",children:H}),e[38]=H,e[39]=ie):ie=e[39];let oe;e[40]!==c||e[41]!==m?(oe=ya(c,m),e[40]=c,e[41]=m,e[42]=oe):oe=e[42];let se;e[43]===Symbol.for("react.memo_cache_sentinel")?(se=Fe=>{const V=Ec(Fe);x(V.scope),g(V.source==="agents"?"agents":"opencode")},e[43]=se):se=e[43];let xe;e[44]!==c?(xe=c==="user"?t.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=xe):xe=e[45];let ae;e[46]!==m?(ae=m==="agents"?t.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=ae):ae=e[47];let fe;e[48]!==U||e[49]!==c||e[50]!==m?(fe=U(ya(c,m)),e[48]=U,e[49]=c,e[50]=m,e[51]=fe):fe=e[51];let Ce;e[52]!==fe?(Ce=t.jsx("span",{children:fe}),e[52]=fe,e[53]=Ce):Ce=e[53];let ge;e[54]!==xe||e[55]!==ae||e[56]!==Ce?(ge=t.jsxs(At,{className:"w-fit gap-1.5",children:[xe,ae,Ce]}),e[54]=xe,e[55]=ae,e[56]=Ce,e[57]=ge):ge=e[57];let ve;e[58]!==S||e[59]!==U?(ve=Ti.map(Fe=>t.jsx(ut,{value:Fe.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:[Fe.scope==="user"?t.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"folder",className:"h-3.5 w-3.5"}),Fe.source==="agents"?t.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:U(Fe.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:S(Fe.value)})]})},Fe.value)),e[58]=S,e[59]=U,e[60]=ve):ve=e[60];let Ne;e[61]!==ve?(Ne=t.jsx(Dt,{align:"start",children:ve}),e[61]=ve,e[62]=Ne):Ne=e[62];let ne;e[63]!==oe||e[64]!==ge||e[65]!==Ne?(ne=t.jsxs(Pt,{value:oe,onValueChange:se,children:[ge,Ne]}),e[63]=oe,e[64]=ge,e[65]=Ne,e[66]=ne):ne=e[66];let re;e[67]!==ie||e[68]!==ne?(re=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ie,ne]}),e[67]=ie,e[68]=ne,e[69]=re):re=e[69];let ye;e[70]!==d||e[71]!==z||e[72]!==c||e[73]!==i?(ye=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")}),d.length===0?t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):t.jsxs(Pt,{value:z??"",onValueChange:Fe=>f(Fe),disabled:d.length===1,children:[t.jsx(At,{className:"w-fit",children:t.jsx(Lt,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),t.jsx(Dt,{align:"start",children:d.map(yf)})]})]}),e[70]=d,e[71]=z,e[72]=c,e[73]=i,e[74]=ye):ye=e[74];let q;e[75]!==r.warnings?(q=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]=q):q=e[76];let $;e[77]!==re||e[78]!==ye||e[79]!==q?($=t.jsxs("div",{className:"mt-2 space-y-3",children:[re,ye,q]}),e[77]=re,e[78]=ye,e[79]=q,e[80]=$):$=e[80];let ee;e[81]!==a?(ee=()=>a(!1),e[81]=a,e[82]=ee):ee=e[82];let de;e[83]!==i?(de=i("settings.common.actions.cancel"),e[83]=i,e[84]=de):de=e[84];let De;e[85]!==ee||e[86]!==de?(De=t.jsx(J,{size:"sm",variant:"ghost",onClick:ee,children:de}),e[85]=ee,e[86]=de,e[87]=De):De=e[87];const ke=u||!r.installable||c==="project"&&!Z;let Pe;e[88]!==Z||e[89]!==te||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==m?(Pe=()=>{te({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:m,skillDir:r.skillDir,directoryOverride:Z})},e[88]=Z,e[89]=te,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=m,e[95]=Pe):Pe=e[95];let Me;e[96]!==u||e[97]!==i?(Me=i(u?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=u,e[97]=i,e[98]=Me):Me=e[98];let Te;e[99]!==ke||e[100]!==Pe||e[101]!==Me?(Te=t.jsx(J,{size:"sm",disabled:ke,onClick:Pe,children:Me}),e[99]=ke,e[100]=Pe,e[101]=Me,e[102]=Te):Te=e[102];let Ve;e[103]!==De||e[104]!==Te?(Ve=t.jsxs(qt,{children:[De,Te]}),e[103]=De,e[104]=Te,e[105]=Ve):Ve=e[105];let Ue;e[106]!==Q||e[107]!==$||e[108]!==Ve?(Ue=t.jsxs(Tt,{className:"max-w-md",children:[Q,$,Ve]}),e[106]=Q,e[107]=$,e[108]=Ve,e[109]=Ue):Ue=e[109];let Oe;e[110]!==a||e[111]!==n||e[112]!==Ue?(Oe=t.jsx(Mt,{open:n,onOpenChange:a,children:Ue}),e[110]=a,e[111]=n,e[112]=Ue,e[113]=Oe):Oe=e[113];let _e;e[114]!==k||e[115]!==te?(_e=Fe=>{k&&(te({source:k.source,subpath:k.subpath,scope:k.scope,targetSource:k.targetSource,skillDir:k.skillDir,conflictDecisions:Fe,directoryOverride:k.directoryOverride??null}),P(!1))},e[114]=k,e[115]=te,e[116]=_e):_e=e[116];let Ke;e[117]!==C||e[118]!==y||e[119]!==_e?(Ke=t.jsx(mf,{open:y,onOpenChange:P,conflicts:C,onConfirm:_e}),e[117]=C,e[118]=y,e[119]=_e,e[120]=Ke):Ke=e[120];let Qe;return e[121]!==Oe||e[122]!==Ke?(Qe=t.jsxs(t.Fragment,{children:[Oe,Ke]}),e[121]=Oe,e[122]=Ke,e[123]=Qe):Qe=e[123],Qe};function gf(s){return s.installSkills}function hf(s){return s.isInstalling}function ff(s){return s.projects}function xf(s){return s.activeProjectId}function yf(s){return t.jsx(ut,{value:s.id,children:s.label||s.path},s.id)}const bf=async()=>{try{const s=qs()?.settings;if(s)return(await s.load())?.settings||{};const e=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},vf=({mode:s,onModeChange:e,showModeTabs:n=!0})=>{const{t:a}=st(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:u,loadCatalog:c,loadSource:x,loadMoreClawdHub:m,isLoadingCatalog:g,isLoadingSource:d,isLoadingMore:b,loadedSourceIds:h,clawdhubHasMoreBySource:f,lastCatalogError:y}=sn(Ps(N=>({sources:N.sources,itemsBySource:N.itemsBySource,selectedSourceId:N.selectedSourceId,setSelectedSource:N.setSelectedSource,loadCatalog:N.loadCatalog,loadSource:N.loadSource,loadMoreClawdHub:N.loadMoreClawdHub,isLoadingCatalog:N.isLoadingCatalog,isLoadingSource:N.isLoadingSource,isLoadingMore:N.isLoadingMore,loadedSourceIds:N.loadedSourceIds,clawdhubHasMoreBySource:N.clawdhubHasMoreBySource,lastCatalogError:N.lastCatalogError}))),[P,I]=o.useState(""),[C,L]=o.useState(!1),[k,v]=o.useState(!1),[w,E]=o.useState(null),[K,U]=o.useState(!1),[M,S]=o.useState(!1);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{l&&(h[l]||x(l))},[l,h,x]);const A=o.useMemo(()=>l?i[l]||[]:[],[i,l]),z=o.useMemo(()=>{const N=P.trim().toLowerCase();return N?A.filter(W=>{const B=W.skillName.toLowerCase(),F=(W.description||"").toLowerCase(),O=(W.frontmatterName||"").toLowerCase();return B.includes(N)||F.includes(N)||O.includes(N)}):A},[A,P]),T=o.useMemo(()=>r.find(N=>N.id===l)||null,[r,l]),Z=!!(l&&l.startsWith("custom:")),G=T?.source==="clawdhub:registry"||T?.sourceType==="clawdhub",te=!!(l&&(f[l]??!0)),Y=async()=>{if(!(!l||!Z)){U(!0);try{const N=await bf(),B=(Array.isArray(N?.skillCatalogs)?N?.skillCatalogs:[]).filter(F=>F.id!==l);await wt({skillCatalogs:B}),await c({refresh:!0}),S(!1)}finally{U(!1)}}};return t.jsx(Ht,{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(Rn,{items:[{id:"manual",label:a("settings.skills.catalog.page.mode.manual")},{id:"external",label:a("settings.skills.catalog.page.mode.external")}],activeId:s,onSelect:N=>e(N),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(Pt,{value:l||"",onValueChange:N=>u(N),children:[t.jsx(At,{className:"w-fit",children:t.jsx(Lt,{placeholder:a("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:T?.label})}),t.jsx(Dt,{align:"start",children:r.map(N=>t.jsx(ut,{value:N.id,children:N.label},N.id))})]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l?x(l,{refresh:!0}):c({refresh:!0})},disabled:g||d,title:a("settings.skills.catalog.page.actions.refreshTitle"),children:t.jsx(D,{name:"refresh",className:ce("h-3.5 w-3.5",(g||d)&&"animate-spin")})}),Z&&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:()=>S(!0),disabled:K,title:a("settings.skills.catalog.page.actions.removeCatalogTitle"),children:t.jsx(D,{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:()=>L(!0),children:[t.jsx(D,{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(D,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),t.jsx(Xe,{value:P,onChange:N=>I(N.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:g?a("settings.skills.catalog.page.loading.catalog"):a("settings.skills.catalog.page.foundCount",{count:z.length})})]})]})]}),y&&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:y.message})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("section",{className:"px-2 pb-2 pt-0",children:z.length===0&&!d?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")})]}):d?t.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[t.jsx(D,{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:z.map(N=>{const W=N.installed?.isInstalled,B=N.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:N.skillName}),W&&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:B||a("settings.skills.catalog.page.badge.unknown")})}),!N.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")})]}),N.description?t.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:N.description}):t.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:a("settings.skills.catalog.shared.noDescription")}),N.clawdhub&&t.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[N.clawdhub.owner&&t.jsxs("span",{children:[a("settings.skills.catalog.page.byOwnerPrefix")," ",t.jsx("span",{className:"font-medium text-foreground/80",children:N.clawdhub.owner})]}),t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(D,{name:"download",className:"h-3 w-3"}),N.clawdhub.downloads?.toLocaleString()??0]}),(N.clawdhub.stars??0)>0&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(D,{name:"star",className:"h-3 w-3"}),N.clawdhub.stars]}),t.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",N.clawdhub.version]})]}),N.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:N.warnings.join(" · ")}):null]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!N.installable,onClick:()=>{E(N),v(!0)},children:a("settings.skills.catalog.shared.actions.install")})]})},`${N.sourceId}:${N.skillDir}`)})})}),G&&te&&!d&&z.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:b,children:a(b?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),t.jsx(sf,{open:C,onOpenChange:L}),t.jsx(pf,{open:k,onOpenChange:v,item:w}),t.jsx(Mt,{open:M,onOpenChange:N=>{K||S(N)},children:t.jsxs(Tt,{className:"max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:a("settings.skills.catalog.page.removeDialog.title")}),t.jsx(Bt,{children:a("settings.skills.catalog.page.removeDialog.description")})]}),t.jsxs(qt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>S(!1),disabled:K,children:a("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",variant:"destructive",onClick:()=>{Y()},disabled:K,children:a("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})};function al(s,e){const n=s.metadata.variant==="dark",a=s.config?.fonts?.mono||"monospace",r=s.colors.syntax.highlights||{},i=s.colors.syntax.tokens||{},l=e?.fontSize?`${e.fontSize}px`:"var(--text-code)",u=Ws.theme({"&":{backgroundColor:"var(--background)",color:s.colors.syntax.base.foreground,fontSize:l,lineHeight:"1.5",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}),c=_i.define([{tag:[Ee.comment,Ee.docComment,Ee.meta,Ee.documentMeta],class:"cm-comment"},{tag:[Ee.keyword,Ee.controlKeyword,Ee.moduleKeyword,Ee.definitionKeyword,Ee.modifier],class:"cm-keyword"},{tag:[Ee.operatorKeyword,Ee.operator,Ee.derefOperator,Ee.updateOperator,Ee.definitionOperator,Ee.typeOperator,Ee.controlOperator,Ee.logicOperator,Ee.bitwiseOperator,Ee.arithmeticOperator,Ee.compareOperator],class:"cm-operator"},{tag:[Ee.punctuation,Ee.separator,Ee.bracket,Ee.paren,Ee.brace,Ee.squareBracket,Ee.angleBracket],class:"cm-punctuation"},{tag:[Ee.string,Ee.regexp,Ee.attributeValue,Ee.special(Ee.string),Ee.monospace],class:"cm-string"},{tag:Ee.escape,class:"cm-string-2"},{tag:[Ee.number,Ee.bool,Ee.atom,Ee.null,Ee.self],class:"cm-number"},{tag:[Ee.function(Ee.variableName),Ee.function(Ee.definition(Ee.variableName)),Ee.function(Ee.propertyName),Ee.standard(Ee.variableName),Ee.special(Ee.variableName)],class:"cm-builtin"},{tag:Ee.definition(Ee.variableName),class:"cm-def"},{tag:[Ee.variableName,Ee.local(Ee.variableName),Ee.constant(Ee.variableName),Ee.literal],class:"cm-variable"},{tag:Ee.propertyName,class:"cm-property"},{tag:Ee.attributeName,class:"cm-attribute"},{tag:[Ee.className,Ee.typeName,Ee.namespace],class:"cm-variable-3"},{tag:[Ee.tagName,Ee.labelName,Ee.annotation,Ee.macroName],class:"cm-tag"},{tag:Ee.link,class:"cm-link"},{tag:[Ee.heading,Ee.heading1,Ee.heading2,Ee.heading3,Ee.heading4,Ee.heading5,Ee.heading6],class:"cm-keyword"}]),x=_i.define([{tag:[Ee.comment,Ee.docComment,Ee.meta,Ee.documentMeta],color:s.colors.syntax.base.comment},{tag:[Ee.keyword,Ee.controlKeyword,Ee.moduleKeyword,Ee.definitionKeyword,Ee.modifier],color:s.colors.syntax.base.keyword},{tag:[Ee.operatorKeyword,Ee.operator,Ee.derefOperator,Ee.updateOperator,Ee.definitionOperator,Ee.typeOperator,Ee.controlOperator,Ee.logicOperator,Ee.bitwiseOperator,Ee.arithmeticOperator,Ee.compareOperator],color:s.colors.syntax.base.operator},{tag:[Ee.string,Ee.regexp,Ee.attributeValue,Ee.special(Ee.string),Ee.monospace],color:s.colors.syntax.base.string},{tag:Ee.escape,color:i.stringEscape||s.colors.syntax.base.string},{tag:[Ee.number,Ee.bool,Ee.atom,Ee.null,Ee.self],color:s.colors.syntax.base.number},{tag:[Ee.function(Ee.variableName),Ee.function(Ee.definition(Ee.variableName)),Ee.function(Ee.propertyName),Ee.standard(Ee.variableName),Ee.special(Ee.variableName)],color:s.colors.syntax.base.function},{tag:Ee.definition(Ee.variableName),color:i.variableGlobal||s.colors.syntax.base.variable},{tag:[Ee.variableName,Ee.local(Ee.variableName),Ee.constant(Ee.variableName),Ee.literal],color:s.colors.syntax.base.variable},{tag:Ee.propertyName,color:i.variableProperty||s.colors.syntax.base.variable},{tag:Ee.attributeName,color:i.variableOther||s.colors.syntax.base.variable},{tag:[Ee.className,Ee.typeName,Ee.namespace],color:s.colors.syntax.base.type},{tag:[Ee.tagName,Ee.labelName,Ee.annotation,Ee.macroName],color:i.tag||s.colors.syntax.base.keyword},{tag:Ee.link,color:i.url||s.colors.syntax.base.function,textDecoration:"underline"},{tag:[Ee.punctuation,Ee.separator,Ee.bracket,Ee.paren,Ee.brace,Ee.squareBracket,Ee.angleBracket],color:i.punctuation||s.colors.syntax.base.comment}]);return e?.syntaxColors===!1?[u]:[u,Aa(Gd,{fallback:!0}),Aa(qd),Aa(c),Aa(x)]}const jf=180,Mc=Jd.define(),wf=1,Nf=2,kf=4,rl=new Map,Sf=(s,e)=>{const n=`${s}|${e}`,a=rl.get(n);if(a)return a;let r="";s&&(r+=`color:${s};`),e&wf&&(r+="font-style:italic;"),e&Nf&&(r+="font-weight:bold;"),e&kf&&(r+="text-decoration:underline;");const i=cr.mark({attributes:{style:r}});return rl.set(n,i),i},Cf=(s,e)=>{const n=new Pi,a=s.state.doc,r=Math.min(e.length,a.lines);for(let i=0;i<r;i+=1){const l=e[i];if(!l||l.length===0)continue;const u=a.line(i+1);let c=u.from;for(const[x,m,g]of l){if(x<=0)continue;const d=c,b=Math.min(c+x,u.to);c+=x,!(b<=d)&&(!m&&!g||n.add(d,b,Sf(m,g)))}}return n.finish()},If=sc.define({create(){return cr.none},update(s,e){let n=s.map(e.changes);for(const a of e.effects)a.is(Mc)&&(n=a.value);return n},provide:s=>Ws.decorations.from(s)}),Pf=s=>tc.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)},jf)}async tokenize(e){const n=++this.generation,a=e.state.doc.toString(),r=await Iu(a,s.language,s.themeName,s.theme);r&&n===this.generation&&e.state.doc.length===a.length&&e.dispatch({effects:Mc.of(Cf(e,r))})}destroy(){this.timer&&clearTimeout(this.timer)}}),Af=s=>[If,Pf(s)],Df=()=>{const s=Ze.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(vf,{mode:"external",onModeChange:Lf,showModeTabs:!1}),s[0]=e):e=s[0],e},Ef="SKILL.md",Mf="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",er=(s,e)=>{const n=Qd({description:s}).trimEnd(),a=e.trimStart();return`---
23
+ ${n}
24
+ ---${a?`
25
+
26
+ ${a}`:`
27
+ `}`},Tf=s=>typeof s=="object"&&s!==null&&!Array.isArray(s),Tc=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=Yd(e[1]);if(Tf(a)){const r=a.description;typeof r=="string"&&(n=r)}}catch{n=null}return{description:n,instructions:e[2].replace(/^\r?\n/,"")}},Rf=(s,e)=>{const n=Tc(s);return er(e,n.instructions)},Ff=()=>{const{t:s}=st(),{currentTheme:e}=pr(),{selectedSkillName:n,getSkillByName:a,getSkillDetail:r,createSkill:i,updateSkill:l,skills:u,skillDraft:c,setSkillDraft:x,setSelectedSkill:m}=an(Ps(V=>({selectedSkillName:V.selectedSkillName,getSkillByName:V.getSkillByName,getSkillDetail:V.getSkillDetail,createSkill:V.createSkill,updateSkill:V.updateSkill,skills:V.skills,skillDraft:V.skillDraft,setSkillDraft:V.setSkillDraft,setSelectedSkill:V.setSelectedSkill}))),g=n?a(n):null,d=!!(c&&c.name===n&&!g),b=!!(n&&!g&&!c),h=g?.path==="<built-in>";o.useEffect(()=>{b&&m(null)},[b,m]);const[f,y]=o.useState(""),[P,I]=o.useState("user"),[C,L]=o.useState("opencode"),[k,v]=o.useState(""),[w,E]=o.useState(""),[K,U]=o.useState(()=>er("","")),[M,S]=o.useState("edit"),[A,z]=o.useState([]),[T,Z]=o.useState([]),[G,te]=o.useState(!1),[Y,N]=o.useState(!1),[W,B]=o.useState(""),[F,O]=o.useState(""),[Q,H]=o.useState(!1),[ie,oe]=o.useState(""),[se,xe]=o.useState(""),[ae,fe]=o.useState(null),[Ce,ge]=o.useState(!1),[ve,Ne]=o.useState(""),[ne,re]=o.useState(null),[ye,q]=o.useState(!1),$=d?f.trim()!==""||k.trim()!==""||w.trim()!==""||T.length>0:k!==W||w!==F,ee=ae?se!==ve:ie.trim()!=="",de=o.useCallback(V=>{switch(V){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]),De=o.useCallback(V=>{switch(V){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]);o.useEffect(()=>{(async()=>{if(d&&c){const le=c.description||"",pe=c.instructions||"";y(c.name||""),I(c.scope||"user"),L(c.source==="agents"?"agents":"opencode"),v(le),E(pe),U(er(le,pe)),B(""),O(""),z([]),Z(c.pendingFiles||[])}else if(n&&g){N(!0);try{const le=await r(n);if(le){const pe=le.sources.md,Le=pe.description||"",we=pe.instructions||"";v(Le),E(we),U(er(Le,we)),B(Le),O(we),z(pe.supportingFiles||[])}}catch(le){console.error("Failed to load skill details:",le)}finally{N(!1)}}})()},[g,d,n,u,c,r]);const ke=Ie(V=>V.editorFontSize),Pe=o.useMemo(()=>{const V=[al(e,{fontSize:ke})],le=Wi(Ef);return le&&V.push(le),V.push(Ws.lineWrapping),V},[e,ke]),Me=o.useMemo(()=>{const V=ie.trim()||"supporting-file.md",le=Pu(V),pe=!!le&&le!=="markdown",Le=[al(e,pe?{syntaxColors:!1,fontSize:ke}:{fontSize:ke})],we=Wi(V);return we&&Le.push(we),pe&&le&&Le.push(Af({language:le,themeName:e.metadata.id,theme:oi(e)})),Le.push(Ws.lineWrapping),Le},[e,ie,ke]),Te=o.useCallback(V=>{v(V),U(le=>Rf(le,V))},[]),Ve=o.useCallback(V=>{U(V);const le=Tc(V);v(le.description??""),E(le.instructions)},[]),Ue=async()=>{const V=d?f.trim().replace(/\s+/g,"-").toLowerCase():n?.trim();if(!V){_.error(s("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(V)||V.length>64){_.error(s("settings.skills.page.toast.invalidSkillName"));return}if(!k.trim()){_.error(s("settings.skills.page.toast.descriptionRequired"));return}if(d&&u.some(le=>le.name===V)){_.error(s("settings.skills.page.toast.skillExists"));return}te(!0);try{const le={name:V,description:k.trim(),instructions:w.trim()||void 0,scope:d?P:void 0,source:d?C:void 0,targetPath:d?void 0:g?.path,supportingFiles:d&&T.length>0?T:void 0};let pe;d?(pe=await i(le),pe&&(x(null),Z([]),m(V))):(pe=await l(V,le),pe&&(B(k.trim()),O(w.trim()))),pe?_.success(s(d?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):_.error(s(d?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(le){console.error("Error saving skill:",le),_.error(s("settings.skills.page.toast.saveUnexpectedError"))}finally{te(!1)}},Oe=()=>{fe(null),oe(""),xe(""),Ne(""),H(!0)},_e=async V=>{if(fe(V),oe(V),d){const pe=T.find(Le=>Le.path===V)?.content||"";xe(pe),Ne(pe),H(!0);return}if(n){ge(!0),H(!0);try{const{readSupportingFile:le}=an.getState(),pe=await le(n,V);xe(pe||""),Ne(pe||"")}catch{_.error(s("settings.skills.page.toast.loadFileContentFailed")),xe(""),Ne("")}finally{ge(!1)}}},Ke=async()=>{if(!ie.trim()){_.error(s("settings.skills.page.toast.fileNameRequired"));return}const V=ie.trim(),le=ae!==null;if(d){if(le)Z(we=>we.map(He=>He.path===ae?{path:V,content:se}:He)),_.success(s("settings.skills.page.toast.fileUpdated",{path:V}));else{if(T.some(we=>we.path===V)){_.error(s("settings.skills.page.toast.fileExists"));return}Z(we=>[...we,{path:V,content:se}]),_.success(s("settings.skills.page.toast.fileAdded",{path:V}))}H(!1),fe(null);return}if(!n){_.error(s("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:pe}=an.getState();if(await pe(n,V,se)){_.success(le?s("settings.skills.page.toast.fileUpdated",{path:V}):s("settings.skills.page.toast.fileCreated",{path:V})),H(!1),fe(null);const we=await r(n);we&&z(we.sources.md.supportingFiles||[])}else _.error(s(le?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Qe=V=>{if(d){Z(le=>le.filter(pe=>pe.path!==V)),_.success(s("settings.skills.page.toast.fileRemoved",{path:V}));return}n&&re(V)},Fe=async()=>{if(!ne||!n)return;q(!0);const{deleteSupportingFile:V}=an.getState();if(await V(n,ne)){_.success(s("settings.skills.page.toast.fileDeleted",{path:ne}));const pe=await r(n);pe&&z(pe.sources.md.supportingFiles||[]),re(null)}else _.error(s("settings.skills.page.toast.deleteFileFailed"));q(!1)};return!n&&!c||b?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(D,{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")})]})}):Y?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(Ht,{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:d?s("settings.skills.page.title.newSkill"):n}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:g?s("settings.skills.page.subtitle.skillLocation",{location:de(ya(g.scope,g.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:[d&&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(Xe,{value:f,onChange:V=>y(V.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:s("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),t.jsxs(Pt,{value:ya(P,C),onValueChange:V=>{const le=Ec(V);I(le.scope),L(le.source==="agents"?"agents":"opencode")},children:[t.jsxs(At,{className:"w-fit gap-1.5",children:[P==="user"?t.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"folder",className:"h-3.5 w-3.5"}),C==="agents"?t.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:de(ya(P,C))})]}),t.jsx(Dt,{align:"start",children:Ti.map(V=>t.jsx(ut,{value:V.value,children:t.jsxs("div",{className:"flex flex-col gap-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[V.scope==="user"?t.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"folder",className:"h-3.5 w-3.5"}),V.source==="agents"?t.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:de(V.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:De(V.value)})]})},V.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(hs,{value:k,onChange:V=>Te(V.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:h})})]})]})]}),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(Xh,{currentMode:M==="preview"?"preview":"edit",onToggle:()=>S(V=>V==="preview"?"edit":"preview")})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx("div",{className:ce("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Mf),children:M==="preview"?t.jsx(Ht,{outerClassName:"h-full",className:"h-full",children:t.jsx("div",{className:"min-h-full px-4 py-3",children:t.jsx(ii,{content:K,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):t.jsx(nl,{value:K,onChange:Ve,readOnly:h,extensions:Pe,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:h,children:[t.jsx(D,{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 V=d?T:A;return V.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:V.map(le=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>_e(le.path),children:[t.jsx(D,{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:le.path}),d&&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")}),!h&&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:pe=>{pe.stopPropagation(),Qe(le.path)},children:t.jsx(D,{name:"delete-bin",className:"h-3 w-3"})})]},le.path))})})()})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:Ue,disabled:h||G||!$,size:"xs",className:"!font-normal",children:s(G?"settings.common.actions.saving":d?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),t.jsx(Mt,{open:ne!==null,onOpenChange:V=>{!V&&!ye&&re(null)},children:t.jsxs(Tt,{className:"max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("settings.skills.page.deleteFileDialog.title")}),t.jsx(Bt,{children:s("settings.skills.page.deleteFileDialog.description",{path:ne??""})})]}),t.jsxs(qt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>re(null),disabled:ye,children:s("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",variant:"destructive",onClick:Fe,disabled:ye,children:s("settings.common.actions.delete")})]})]})}),t.jsx(Mt,{open:Q,onOpenChange:V=>{H(V),V||fe(null)},children:t.jsxs(Tt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[t.jsxs(zt,{className:"flex-shrink-0",children:[t.jsx(Ot,{children:s(ae?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),t.jsx(Bt,{children:s(ae?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),Ce?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(Xe,{value:ie,onChange:V=>oe(V.target.value),placeholder:s("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:ae!==null}),!ae&&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(nl,{value:se,onChange:xe,extensions:Me,className:"h-full",enableSearch:!0})})]})]}),t.jsxs(qt,{className:"mt-4",children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>{H(!1),fe(null)},children:s("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:Ke,disabled:Ce||!ee,children:s(ae?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},il=s=>{const e=Ze.c(2),{view:n}=s,a=n===void 0?"installed":n;let r;return e[0]!==a?(r=a==="catalog"?t.jsx(Df,{}):t.jsx(Ff,{}),e[0]=a,e[1]=r):r=e[1],r};function Lf(){}const Of=s=>{const e=Ze.c(38),{onItemSelect:n}=s,{t:a}=st(),r=es(zf),i=Ie(Kf),l=Ie(Uf),{currentTheme:u}=pr();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=rs(),e[0]=c):c=e[0];const x=c,m=Bf;let g,d;e[1]!==r||e[2]!==i||e[3]!==l?(g=()=>{if(r.length===0){i!==null&&l(null);return}i&&r.some(w=>w.id===i)||l(r[0].id)},d=[r,i,l],e[1]=r,e[2]=i,e[3]=l,e[4]=g,e[5]=d):(g=e[4],d=e[5]),o.useEffect(g,d);let b;e[6]===Symbol.for("react.memo_cache_sentinel")?(b=ce("border-b px-3","pt-4 pb-3"),e[6]=b):b=e[6];let h;e[7]!==a?(h=a("settings.page.projects.title"),e[7]=a,e[8]=h):h=e[8];let f;e[9]!==h?(f=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:h}),e[9]=h,e[10]=f):f=e[10];let y;e[11]!==r.length||e[12]!==a?(y=a("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=a,e[13]=y):y=e[13];let P;e[14]!==y?(P=t.jsx("span",{className:"typography-meta text-muted-foreground",children:y}),e[14]=y,e[15]=P):P=e[15];let I;e[16]!==a?(I=!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(D,{name:"add",className:"size-4"})}),e[16]=a,e[17]=I):I=e[17];let C;e[18]!==P||e[19]!==I?(C=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,I]}),e[18]=P,e[19]=I,e[20]=C):C=e[20];let L;e[21]!==C||e[22]!==f?(L=t.jsxs("div",{className:b,children:[f,C]}),e[21]=C,e[22]=f,e[23]=L):L=e[23];let k;if(e[24]!==u||e[25]!==n||e[26]!==r||e[27]!==i||e[28]!==l){let w;e[30]!==u||e[31]!==n||e[32]!==i||e[33]!==l?(w=E=>{const K=E.id===i,U=E.icon?Au[E.icon]:null,M=E.color?cc[E.color]??null:null,S=U?t.jsx(D,{name:U,className:ce("h-4 w-4",K?"text-foreground":"text-muted-foreground/70"),style:M?{color:M}:void 0}):t.jsx(D,{name:"folder",className:ce("h-4 w-4",K?"text-foreground":"text-muted-foreground/70"),style:M?{color:M}:void 0}),A=E.iconImage?t.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:E.iconBackground?{backgroundColor:E.iconBackground}:void 0,children:t.jsx(dc,{project:E,options:{themeVariant:u.metadata.variant,iconColor:u.colors.surface.foreground},className:"h-full w-full object-contain",fallback:S})}):S;return t.jsx(yi,{title:E.label||E.path,icon:A,selected:K,onSelect:()=>{l(E.id),n?.()}},E.id)},e[30]=u,e[31]=n,e[32]=i,e[33]=l,e[34]=w):w=e[34],k=r.map(w),e[24]=u,e[25]=n,e[26]=r,e[27]=i,e[28]=l,e[29]=k}else k=e[29];let v;return e[35]!==L||e[36]!==k?(v=t.jsx(Ac,{variant:"background",header:L,children:k}),e[35]=L,e[36]=k,e[37]=v):v=e[37],v};function zf(s){return s.projects}function Kf(s){return s.settingsProjectsSelectedId}function Uf(s){return s.setSettingsProjectsSelectedId}function Bf(){lc.requestDirectoryDialog()}const ja="w-full max-w-[30rem]",rn=s=>{const e=Ze.c(27),{title:n,description:a,settingsItem:r,titleAccessory:i,headerAction:l,children:u,className:c,contentClassName:x}=s;let m;e[0]!==c?(m=ce("border-b border-border/50 py-5 first:pt-0 last:border-b-0",c),e[0]=c,e[1]=m):m=e[1];let g;e[2]!==n?(g=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:n}),e[2]=n,e[3]=g):g=e[3];let d;e[4]!==g||e[5]!==i?(d=t.jsxs("div",{className:"flex items-center gap-2",children:[g,i]}),e[4]=g,e[5]=i,e[6]=d):d=e[6];let b;e[7]!==a?(b=a?t.jsx("p",{className:"mt-0.5 typography-meta text-muted-foreground",children:a}):null,e[7]=a,e[8]=b):b=e[8];let h;e[9]!==d||e[10]!==b?(h=t.jsxs("div",{className:"min-w-0 flex-1",children:[d,b]}),e[9]=d,e[10]=b,e[11]=h):h=e[11];let f;e[12]!==l?(f=l?t.jsx("div",{className:"shrink-0",children:l}):null,e[12]=l,e[13]=f):f=e[13];let y;e[14]!==h||e[15]!==f?(y=t.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3 px-1",children:[h,f]}),e[14]=h,e[15]=f,e[16]=y):y=e[16];let P;e[17]!==x?(P=ce("space-y-2 px-2",x),e[17]=x,e[18]=P):P=e[18];let I;e[19]!==u||e[20]!==P?(I=t.jsx("div",{className:P,children:u}),e[19]=u,e[20]=P,e[21]=I):I=e[21];let C;return e[22]!==r||e[23]!==m||e[24]!==y||e[25]!==I?(C=t.jsxs("section",{"data-settings-item":r,className:m,children:[y,I]}),e[22]=r,e[23]=m,e[24]=y,e[25]=I,e[26]=C):C=e[26],C},$f=450,Vf=({projectRef:s=null})=>{const{t:e}=st(),{isMobile:n,isTablet:a}=Ms(),r=n||a,i=es(B=>B.getActiveProject()),l=s?.path??i?.path??null,u=ys(B=>B.getWorktreeMetadata),c=Du(),x=ws(B=>B.homeDirectory),[m,g]=o.useState([]),[d,b]=o.useState(!1),[h,f]=o.useState(!1),[y,P]=o.useState(null),[I,C]=o.useState(null),[L,k]=o.useState([]),[v,w]=o.useState(!1),E=o.useRef(!1),K=o.useMemo(()=>s?.id&&s?.path?{id:s.id,path:s.path}:!i?.id||!l?null:{id:i.id,path:l},[i?.id,l,s?.id,s?.path]),U=o.useCallback(async()=>{if(!(!K||I===!1))try{const B=await Gi(K);k(B)}catch{}},[K,I]);o.useEffect(()=>{if(!l)return;let B=!1;return C(null),(async()=>{try{const F=await Eu(l);if(B)return;C(F)}catch{}})(),()=>{B=!0}},[l]),o.useEffect(()=>{if(!K){k([]),w(!1);return}if(I===!1){k([]),w(!1);return}let B=!1;return w(!0),k([]),(async()=>{try{const F=await Gi(K);if(B)return;k(F)}catch{}finally{B||w(!1)}})(),()=>{B=!0}},[K,I]),o.useEffect(()=>{if(!K)return;let B=!1;return f(!0),(async()=>{try{const[F,O]=await Promise.all([uc(K),mc(K)]);if(!B){const Q=F.length>0?F:[""];g(Q),P(JSON.stringify(Q)),b(O)}}catch{B||(g([""]),P(JSON.stringify([""])),b(!1))}finally{B||f(!1)}})(),()=>{B=!0}},[K]);const M=o.useCallback(async B=>{if(!K)return!1;const F=B.filter(O=>O.trim().length>0);try{return await Mu(K,F)?(P(JSON.stringify(B)),!0):(_.error(e("settings.openchamber.worktrees.setup.toast.saveFailed")),!1)}catch{return _.error(e("settings.openchamber.worktrees.setup.toast.saveFailed")),!1}},[K,e]),S=o.useMemo(()=>y===null?!1:y!==JSON.stringify(m),[y,m]);o.useEffect(()=>{if(!S||h||E.current)return;const B=window.setTimeout(()=>{E.current||(E.current=!0,(async()=>{try{await M(m)}finally{E.current=!1}})())},$f);return()=>{window.clearTimeout(B)}},[S,h,M,m]);const A=o.useCallback((B,F)=>{g(O=>{const Q=[...O];return Q[B]=F,Q})},[]),z=o.useCallback(()=>{g(B=>[...B,""])},[]),T=o.useCallback(B=>{g(F=>{const O=F.filter((Q,H)=>H!==B);return O.length>0?O:[""]})},[]),Z=o.useCallback(()=>{!S||E.current||(E.current=!0,(async()=>{try{await M(m)}finally{E.current=!1}})())},[S,M,m]),G=o.useCallback(B=>{b(B),K&&Tu(K,B)},[K]),te=o.useCallback(B=>{const F=fe=>fe.replace(/\\/g,"/").replace(/\/+$/,""),O=F(B.path),Q=c.filter(fe=>{const Ce=u(fe.id);if(Ce?.path&&F(Ce.path)===O)return!0;const ge=fe.directory;return!!(ge&&F(ge)===O)}),H=new Set(Q.map(fe=>fe.id)),ie=[...li.getState().activeSessions,...li.getState().archivedSessions],oe=fe=>{const Ce=ie.filter(ve=>{const Ne=ve.parentID;return Ne&&fe.has(Ne)});if(Ce.length===0)return[];const ge=new Set(Ce.map(ve=>ve.id));return[...Ce,...oe(ge)]},se=oe(H),xe=new Set,ae=[...Q,...se].filter(fe=>xe.has(fe.id)?!1:(xe.add(fe.id),!0));lc.requestDelete({sessions:ae,mode:"worktree",worktree:B})},[c,u]),Y=o.useMemo(()=>c.map(B=>B.id).join(","),[c]);o.useEffect(()=>{I&&l&&U()},[Y,I,l,U]);const N=t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(It,{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")]})]}),W=t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]});return l?I===!1?t.jsx(rn,{title:e("settings.projects.page.section.worktree"),settingsItem:"projects.worktree",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")})}):t.jsxs(t.Fragment,{children:[t.jsx(rn,{title:e("settings.projects.page.section.worktree"),settingsItem:"projects.worktree",titleAccessory:N,children:h?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.setup.loading")}):t.jsxs("div",{className:ce("space-y-2",ja),children:[m.map((B,F)=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(Xe,{value:B,onChange:O=>A(F,O.target.value),onBlur:Z,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 min-w-0 flex-1 font-mono text-xs"}),t.jsx("button",{type:"button",onClick:()=>T(F),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:t.jsx(D,{name:"close",className:"h-4 w-4"})})]},F)),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:z,children:[t.jsx(D,{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",children:[t.jsx(xt,{checked:d,onChange:G,ariaLabel:e("settings.openchamber.worktrees.setup.waitForCommandsAria")}),t.jsx("span",{className:ce("typography-ui-label font-normal",d?"text-foreground":"text-foreground/60"),children:e("settings.openchamber.worktrees.setup.waitForCommands")})]})]})}),t.jsx(rn,{title:e("settings.openchamber.worktrees.list.title"),titleAccessory:W,children:v?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.list.loading")}):L.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:e("settings.openchamber.worktrees.list.empty")}):t.jsx("div",{className:ce("space-y-1",ja),children:L.map(B=>t.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("p",{className:"typography-meta min-w-0 truncate text-foreground",children:B.label||B.branch||e("settings.openchamber.worktrees.list.detachedHead")}),t.jsx("span",{className:"typography-micro flex-shrink-0 self-center rounded bg-sidebar-accent/40 px-1.5 py-[1px] leading-none text-muted-foreground/60",children:"OpenCode"})]}),t.jsx("p",{className:"typography-micro truncate text-muted-foreground/60",children:Ru(B.path,x)})]}),t.jsx("button",{type:"button",onClick:()=>te(B),className:ce("flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground/50 transition-opacity hover:bg-destructive/10 hover:text-destructive 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:B.branch||B.label||B.path}),children:t.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})]},B.path))})})]}):t.jsx(rn,{title:e("settings.projects.page.section.worktree"),settingsItem:"projects.worktree",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})})},ol=(s,e)=>e.updatedAtMs-s.updatedAtMs,us=Nn((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([zu(),Ji()]),r={};for(const i of a.sort(ol))r[i.id]=i;e().listenerReady||await Ku(i=>{s(l=>({statusesById:{...l.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 Ou();s({importCandidates:n,isImportsLoading:!1})}catch(n){s({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await Ji(),a={};for(const r of n.sort(ol))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 Lu({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=Uu(n,a);r&&r.trim()&&(i.nickname=r.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await qi(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 Fu(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 qi(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})})),Rc=[{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"}],_f=Object.fromEntries(Rc.map(s=>[s.key,s.Icon])),Hf="openchamber:project-actions-updated",Wf=s=>{const e=(s||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},ew=(s,e)=>`${Wf(s)}::${e}`,Gf=s=>{const e=s.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},ll=s=>{if(typeof s!="number"||!Number.isFinite(s))return null;const e=Math.round(s);return e<1||e>65535?null:e},qf=(s,e)=>{if(!e.enabled||e.type!=="local")return null;const n=ll(e.localPort),a=ll(e.remotePort);if(!n||!a)return null;const r=Gf(e.localHost||s.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),l=(s.nickname||s.id||"instance").trim();return{id:`${s.id}::${e.id}`,label:`${l} - ${r}:${n} -> ${i}:${a}`,url:`http://${r}:${n}`}},Fc=s=>{const e=[];for(const n of s)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const a of n.portForwards){const r=qf(n,a);r&&e.push(r)}return e},tw=(s,e)=>{const n=(s||"").trim();return n&&Fc(e).find(i=>i.id===n)?.url||null},Jf=450,Qf=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,Yf=()=>({id:Qf(),name:"",command:"",icon:"play"}),Xf=({projectRef:s})=>{const{t:e}=st(),n=o.useMemo(()=>ns(),[]),a=us(v=>v.instances),r=us(v=>v.load),[i,l]=o.useState([]),[u,c]=o.useState(!1),[x,m]=o.useState(null),[g,d]=o.useState({}),b=o.useRef(!1),h=o.useRef(null);o.useEffect(()=>{n&&r().catch(()=>{})},[n,r]),o.useEffect(()=>{let v=!1;return c(!0),(async()=>{try{const w=await Bu(s);if(v)return;l(w.actions),m(JSON.stringify({actions:w.actions}))}catch{if(v)return;l([]),m(JSON.stringify({actions:[]}))}finally{v||c(!1)}})(),()=>{v=!0}},[s]);const f=o.useMemo(()=>n?Fc(a):[],[a,n]),y=o.useMemo(()=>i.some(w=>w.name.trim().length===0||w.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),P=o.useMemo(()=>x===null?!1:x!==JSON.stringify({actions:i}),[i,x]),I=o.useCallback(async v=>await $u(s,{actions:v,primaryActionId:null})?(m(JSON.stringify({actions:v})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Hf,{detail:{projectId:s.id}})),!0):(_.error(e("settings.projects.actions.toast.saveFailed")),!1),[s,e]);o.useEffect(()=>{if(!P||u||y||b.current)return;const v=window.setTimeout(()=>{b.current||(b.current=!0,(async()=>{try{await I(i)}finally{b.current=!1}})())},Jf);return()=>{window.clearTimeout(v)}},[i,P,u,I,y]),o.useEffect(()=>{if(!P||!y||u){y||(h.current=null);return}const v=window.setTimeout(()=>{h.current!==y&&(h.current=y,_.error(y))},1e3);return()=>{window.clearTimeout(v)}},[P,u,y]);const C=o.useCallback(()=>{const v=Yf();l(w=>[...w,v]),d(w=>({...w,[v.id]:!0}))},[]),L=o.useCallback(v=>{l(w=>w.filter(E=>E.id!==v)),d(w=>{const E={...w};return delete E[v],E})},[]),k=o.useCallback((v,w)=>{l(E=>E.map(K=>K.id===v?w(K):K))},[]);return t.jsxs(rn,{title:e("settings.projects.actions.title"),description:e("settings.projects.actions.description"),settingsItem:"projects.actions",headerAction:t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:C,children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]}),contentClassName:"space-y-0",children:[u?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):i.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")}):t.jsx("div",{className:ce("space-y-0",ja),children:i.map(v=>{const w=v.icon||"play",E=_f[w]||"play",K=g[v.id]??!1,U=v.name.trim()||e("settings.projects.actions.state.untitled");return t.jsxs(En,{open:K,onOpenChange:M=>{d(S=>({...S,[v.id]:M}))},className:"py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs(Mn,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[K?t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):t.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),t.jsx(D,{name:E,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("span",{className:"typography-ui-label text-foreground truncate",children:U})})]}),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:()=>L(v.id),children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(Tn,{className:"pt-1.5",children:t.jsxs("div",{className:"space-y-2 pb-4 pl-3 pr-1",children:[t.jsxs("div",{className:"flex items-center gap-2 py-1",children:[t.jsxs(gs,{children:[t.jsx(ms,{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(D,{name:E,className:"h-4 w-4"})})}),t.jsx(ps,{align:"start",className:"w-56 p-2",children:t.jsx("div",{className:"grid grid-cols-6 gap-1",children:Rc.map(M=>{const S=M.Icon,A=(v.icon||"play")===M.key;return t.jsx("button",{type:"button",onClick:()=>k(v.id,z=>({...z,icon:M.key})),className:ce("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",A&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:M.label}),children:t.jsx(D,{name:S,className:"h-4 w-4"})},M.key)})})})]}),t.jsx(Xe,{value:v.name,onChange:M=>k(v.id,S=>({...S,name:M.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 flex-1 min-w-0"})]}),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(hs,{value:v.command,onChange:M=>k(v.id,S=>({...S,command:M.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] w-full 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":v.autoOpenUrl===!0,onClick:()=>k(v.id,M=>({...M,...M.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),k(v.id,S=>({...S,...S.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[t.jsx(xt,{checked:v.autoOpenUrl===!0,onChange:M=>k(v.id,S=>({...S,...M?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:U})}),t.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),v.autoOpenUrl===!0?t.jsxs("div",{className:"mt-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xe,{value:v.openUrl||"",onChange:M=>k(v.id,S=>({...S,openUrl:M.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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")}),f.length>0?t.jsxs(Pt,{value:v.desktopOpenSshForward&&f.some(M=>M.id===v.desktopOpenSshForward)?v.desktopOpenSshForward:"__none__",onValueChange:M=>{k(v.id,S=>({...S,...M==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:M}}))},children:[t.jsx(At,{className:"h-7 w-full",children:t.jsx(Lt,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),f.map(M=>t.jsx(ut,{value:M.id,children:M.label},M.id))]})]}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},v.id)})}),y&&i.length>0?t.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:y}):null]})},Zf=s=>{const e=Ze.c(122),{form:n}=s,{t:a}=st(),{currentTheme:r}=pr(),{name:i,setName:l,icon:u,setIcon:c,color:x,setColor:m,iconBackground:g,setIconBackground:d,parsedDefaultModel:b,handleDefaultModelChange:h,isUploadingIcon:f,isRemovingCustomIcon:y,isDiscoveringIcon:P,pendingRemoveImageIcon:I,setPendingRemoveImageIcon:C,pendingUploadIconPreviewUrl:L,setPreviewImageFailed:k,hasPendingUploadImageIcon:v,hasCustomIcon:w,effectiveHasImageIcon:E,hasRemovableImageIcon:K,showImagePreview:U,fileInputRef:M,handleUploadIcon:S,handleRemoveImageIcon:A,handleDiscoverIcon:z,currentIconImage:T,project:Z}=n;if(!Z)return null;const G=x?cc[x]??null:null;let te;e[0]!==a?(te=a("settings.projects.page.field.projectName"),e[0]=a,e[1]=te):te=e[1];let Y;e[2]!==l?(Y=le=>l(le.target.value),e[2]=l,e[3]=Y):Y=e[3];let N;e[4]!==a?(N=a("settings.projects.page.field.projectNamePlaceholder"),e[4]=a,e[5]=N):N=e[5];let W;e[6]===Symbol.for("react.memo_cache_sentinel")?(W=ce("h-7",ja),e[6]=W):W=e[6];let B;e[7]!==i||e[8]!==Y||e[9]!==N?(B=t.jsx(Xe,{value:i,onChange:Y,placeholder:N,className:W}),e[7]=i,e[8]=Y,e[9]=N,e[10]=B):B=e[10];let F;e[11]!==te||e[12]!==B?(F=t.jsx(rn,{title:te,settingsItem:"projects.name",children:B}),e[11]=te,e[12]=B,e[13]=F):F=e[13];let O;e[14]!==a?(O=a("settings.projects.page.field.defaultModel"),e[14]=a,e[15]=O):O=e[15];let Q;e[16]!==a?(Q=a("settings.projects.page.field.defaultModelDescription"),e[16]=a,e[17]=Q):Q=e[17];let H;e[18]!==h||e[19]!==b.modelId||e[20]!==b.providerId?(H=t.jsx(va,{providerId:b.providerId,modelId:b.modelId,onChange:h,className:ja}),e[18]=h,e[19]=b.modelId,e[20]=b.providerId,e[21]=H):H=e[21];let ie;e[22]!==O||e[23]!==Q||e[24]!==H?(ie=t.jsx(rn,{title:O,description:Q,settingsItem:"projects.default-model",children:H}),e[22]=O,e[23]=Q,e[24]=H,e[25]=ie):ie=e[25];let oe;e[26]!==a?(oe=a("settings.projects.page.field.accentColor"),e[26]=a,e[27]=oe):oe=e[27];let se;e[28]!==m?(se=()=>m(null),e[28]=m,e[29]=se):se=e[29];const xe=x===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let ae;e[30]!==xe?(ae=ce("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",xe),e[30]=xe,e[31]=ae):ae=e[31];let fe;e[32]!==a?(fe=a("settings.projects.page.field.none"),e[32]=a,e[33]=fe):fe=e[33];let Ce;e[34]===Symbol.for("react.memo_cache_sentinel")?(Ce=t.jsx(D,{name:"close",className:"h-4 w-4 text-muted-foreground"}),e[34]=Ce):Ce=e[34];let ge;e[35]!==se||e[36]!==ae||e[37]!==fe?(ge=t.jsx("button",{type:"button",onClick:se,className:ae,title:fe,children:Ce}),e[35]=se,e[36]=ae,e[37]=fe,e[38]=ge):ge=e[38];let ve;e[39]!==x||e[40]!==m?(ve=Vu.map(le=>t.jsx("button",{type:"button",onClick:()=>m(le.key),className:ce("h-7 w-7 rounded-md border transition-colors",x===le.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:le.cssVar},title:le.label},le.key)),e[39]=x,e[40]=m,e[41]=ve):ve=e[41];let Ne;e[42]!==ge||e[43]!==ve?(Ne=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ge,ve]}),e[42]=ge,e[43]=ve,e[44]=Ne):Ne=e[44];let ne;e[45]!==oe||e[46]!==Ne?(ne=t.jsx(rn,{title:oe,settingsItem:"projects.accent-color",children:Ne}),e[45]=oe,e[46]=Ne,e[47]=ne):ne=e[47];let re;e[48]!==a?(re=a("settings.projects.page.field.projectIcon"),e[48]=a,e[49]=re):re=e[49];let ye;e[50]!==S?(ye=le=>{const pe=le.target.files?.[0]??null;S(pe),le.currentTarget.value=""},e[50]=S,e[51]=ye):ye=e[51];let q;e[52]!==M||e[53]!==ye?(q=t.jsx("input",{ref:M,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:ye}),e[52]=M,e[53]=ye,e[54]=q):q=e[54];let $;e[55]!==c?($=()=>c(null),e[55]=c,e[56]=$):$=e[56];const ee=u===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let de;e[57]!==ee?(de=ce("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",ee),e[57]=ee,e[58]=de):de=e[58];let De;e[59]!==a?(De=a("settings.projects.page.field.none"),e[59]=a,e[60]=De):De=e[60];let ke;e[61]===Symbol.for("react.memo_cache_sentinel")?(ke=t.jsx(D,{name:"close",className:"h-4 w-4 text-muted-foreground"}),e[61]=ke):ke=e[61];let Pe;e[62]!==$||e[63]!==de||e[64]!==De?(Pe=t.jsx("button",{type:"button",onClick:$,className:de,title:De,children:ke}),e[62]=$,e[63]=de,e[64]=De,e[65]=Pe):Pe=e[65];let Me;e[66]!==G||e[67]!==u||e[68]!==c?(Me=_u.map(le=>{const pe=le.Icon;return t.jsx("button",{type:"button",onClick:()=>c(le.key),className:ce("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",u===le.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:le.label,children:t.jsx(D,{name:pe,className:"w-4 h-4",style:G&&u===le.key?{color:G}:void 0})},le.key)}),e[66]=G,e[67]=u,e[68]=c,e[69]=Me):Me=e[69];let Te;e[70]!==Pe||e[71]!==Me?(Te=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Pe,Me]}),e[70]=Pe,e[71]=Me,e[72]=Te):Te=e[72];let Ve;e[73]!==T||e[74]!==r||e[75]!==E||e[76]!==v||e[77]!==g||e[78]!==L||e[79]!==Z||e[80]!==k||e[81]!==U||e[82]!==a?(Ve=E&&U&&t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:a("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:g?{backgroundColor:g}:void 0,children:v&&L?t.jsx("img",{src:L,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>k(!0)}):t.jsx(dc,{project:{...Z,iconImage:T??Z.iconImage},options:{themeVariant:r.metadata.variant,iconColor:r.colors.surface.foreground},className:"h-full w-full object-contain",onError:()=>k(!0)})})})]}),e[73]=T,e[74]=r,e[75]=E,e[76]=v,e[77]=g,e[78]=L,e[79]=Z,e[80]=k,e[81]=U,e[82]=a,e[83]=Ve):Ve=e[83];let Ue;e[84]!==E||e[85]!==g||e[86]!==d||e[87]!==a?(Ue=E&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("input",{type:"color",value:g??"#000000",onChange:le=>d(le.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":a("settings.projects.page.field.projectIconBackgroundAria")}),t.jsx(Xe,{value:g??"",onChange:le=>d(le.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),t.jsx(J,{type:"button",size:"xs",variant:"outline",onClick:()=>d(null),className:"h-7 w-7 p-0","aria-label":a("settings.projects.page.field.clearIconBackgroundAria"),title:a("settings.projects.page.field.clearBackground"),disabled:!g,children:t.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]}),e[84]=E,e[85]=g,e[86]=d,e[87]=a,e[88]=Ue):Ue=e[88];let Oe;e[89]!==M||e[90]!==z||e[91]!==w||e[92]!==P||e[93]!==f||e[94]!==a?(Oe=!w&&t.jsxs(t.Fragment,{children:[t.jsx(J,{size:"xs",className:"h-6 !font-normal",onClick:()=>M.current?.click(),disabled:f,children:a(f?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),t.jsx(J,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{z()},disabled:P,children:a(P?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),e[89]=M,e[90]=z,e[91]=w,e[92]=P,e[93]=f,e[94]=a,e[95]=Oe):Oe=e[95];let _e;e[96]!==A||e[97]!==K||e[98]!==y||e[99]!==a?(_e=K&&t.jsx(J,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{A()},disabled:y,children:a(y?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),e[96]=A,e[97]=K,e[98]=y,e[99]=a,e[100]=_e):_e=e[100];let Ke;e[101]!==y||e[102]!==I||e[103]!==C||e[104]!==a?(Ke=I&&t.jsx(J,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>C(!1),disabled:y,children:a("settings.projects.page.actions.undoRemove")}),e[101]=y,e[102]=I,e[103]=C,e[104]=a,e[105]=Ke):Ke=e[105];let Qe;e[106]!==Oe||e[107]!==_e||e[108]!==Ke?(Qe=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Oe,_e,Ke]}),e[106]=Oe,e[107]=_e,e[108]=Ke,e[109]=Qe):Qe=e[109];let Fe;e[110]!==re||e[111]!==q||e[112]!==Te||e[113]!==Ve||e[114]!==Ue||e[115]!==Qe?(Fe=t.jsxs(rn,{title:re,settingsItem:"projects.icon",children:[q,Te,Ve,Ue,Qe]}),e[110]=re,e[111]=q,e[112]=Te,e[113]=Ve,e[114]=Ue,e[115]=Qe,e[116]=Fe):Fe=e[116];let V;return e[117]!==ie||e[118]!==ne||e[119]!==Fe||e[120]!==F?(V=t.jsxs(t.Fragment,{children:[F,ie,ne,Fe]}),e[117]=ie,e[118]=ne,e[119]=Fe,e[120]=F,e[121]=V):V=e[121],V},ex=/^#(?:[\da-fA-F]{3}|[\da-fA-F]{6})$/,tx=s=>{if(!s)return null;const e=s.trim();return e&&ex.test(e)?e.toLowerCase():null},sx=s=>{const{t:e}=st(),n=es(ae=>ae.uploadProjectIcon),a=es(ae=>ae.removeProjectIcon),r=es(ae=>ae.discoverProjectIcon),i=es(ae=>s?ae.projects.find(fe=>fe.id===s.id)?.iconImage??null:null),[l,u]=o.useState(""),[c,x]=o.useState(null),[m,g]=o.useState(null),[d,b]=o.useState(null),[h,f]=o.useState(void 0),[y,P]=o.useState(!1),[I,C]=o.useState(!1),[L,k]=o.useState(!1),[v,w]=o.useState(!1),[E,K]=o.useState(null),[U,M]=o.useState(null),[S,A]=o.useState(!1),z=o.useRef(null),T=o.useCallback(()=>{K(null),M(ae=>(ae&&URL.revokeObjectURL(ae),null))},[]),Z=s?.id??null;o.useEffect(()=>{if(!s){u(""),x(null),g(null),b(null),f(void 0);return}u(s.label??""),x(s.icon??null),g(s.color??null),b(s.iconBackground??null),f(s.defaultModel),w(!1),T(),A(!1)},[s,T]),o.useEffect(()=>()=>{T()},[T]);const G=o.useMemo(()=>xn(h)??{providerId:"",modelId:""},[h]),te=!!s?.iconImage,Y=!!(E&&U),N=s?.iconImage?.source==="custom",W=te&&!v||Y,B=W,F=!!(s&&te&&!v),O=!S&&(Y||F),Q=!!s&&(l.trim()!==(s?.label??"").trim()||c!==(s?.icon??null)||m!==(s?.color??null)||d!==(s?.iconBackground??null)||(h??void 0)!==(s?.defaultModel??void 0)||v||!!E),H=o.useCallback((ae,fe)=>{f(ae&&fe?`${ae}/${fe}`:void 0)},[]),ie=o.useCallback(ae=>{!s||!ae||y||(w(!1),A(!1),K(ae),M(fe=>(fe&&URL.revokeObjectURL(fe),URL.createObjectURL(ae))))},[y,s]),oe=o.useCallback(()=>{!s||!B||I||(Y&&T(),w(!!te),A(!1))},[T,Y,B,te,I,s]),se=o.useCallback(async()=>{if(!(!s||L)){T(),w(!1),A(!1),k(!0);try{const ae=await r(s.id);if(!ae.ok){_.error(ae.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(ae.skipped){_.success(e("settings.projects.page.toast.customIconAlreadySet"));return}_.success(e("settings.projects.page.toast.iconDiscovered"))}finally{k(!1)}}},[T,r,L,s,e]),xe=o.useCallback(async ae=>{const fe=ae?.silent===!0;if(!s)return null;const Ce=l.trim();if(!Ce)return null;if(E){P(!0);const ve=await n(s.id,E);if(P(!1),!ve.ok)return _.error(ve.error||e("settings.projects.page.toast.uploadIconFailed")),null;fe||_.success(e("settings.projects.page.toast.iconUpdated")),T(),w(!1)}const ge=v&&!!s.iconImage;if(ge){C(!0);const ve=await a(s.id);if(C(!1),!ve.ok)return _.error(ve.error||e("settings.projects.page.toast.removeIconFailed")),null;fe||_.success(e("settings.projects.page.toast.iconRemoved")),w(!1),b(null)}return{label:Ce,icon:c,color:m,iconBackground:tx(ge?null:d),defaultModel:h??null}},[T,m,h,c,d,l,v,E,s,a,e,n]);return o.useEffect(()=>{A(!1)},[Z,i?.updatedAt]),{name:l,setName:u,icon:c,setIcon:x,color:m,setColor:g,iconBackground:d,setIconBackground:b,defaultModel:h,parsedDefaultModel:G,handleDefaultModelChange:H,isUploadingIcon:y,isRemovingCustomIcon:I,isDiscoveringIcon:L,pendingRemoveImageIcon:v,setPendingRemoveImageIcon:w,pendingUploadIconFile:E,pendingUploadIconPreviewUrl:U,previewImageFailed:S,setPreviewImageFailed:A,hasStoredImageIcon:te,hasPendingUploadImageIcon:Y,hasCustomIcon:N,effectiveHasImageIcon:W,hasRemovableImageIcon:B,showStoredImagePreview:F,showImagePreview:O,fileInputRef:z,clearPendingUploadIcon:T,handleUploadIcon:ie,handleRemoveImageIcon:oe,handleDiscoverIcon:se,hasChanges:Q,prepareSaveData:xe,currentIconImage:i,project:s}},nx=450,ax=(s,e)=>{const{t:n}=st(),{hasChanges:a,name:r,icon:i,color:l,iconBackground:u,defaultModel:c,pendingRemoveImageIcon:x,pendingUploadIconFile:m,isUploadingIcon:g,isRemovingCustomIcon:d,prepareSaveData:b}=s,h=o.useRef(!1);o.useEffect(()=>{if(!a||!r.trim()||g||d||h.current)return;const f=window.setTimeout(()=>{h.current||(h.current=!0,(async()=>{try{const y=await b({silent:!0});if(y)try{await e(y)}catch{_.error(n("settings.projects.page.toast.saveFailed"))}}finally{h.current=!1}})())},nx);return()=>{window.clearTimeout(f)}},[l,c,a,i,u,d,g,r,e,x,m,b,n])},rx=s=>{const e=Ze.c(25),{project:n,onIdentitySave:a}=s,{t:r}=st(),i=sx(n);let l;e:{if(!n){l=null;break e}let C;e[0]!==n.id||e[1]!==n.path?(C={id:n.id,path:n.path},e[0]=n.id,e[1]=n.path,e[2]=C):C=e[2],l=C}const u=l;let c;if(e[3]!==a?(c=async C=>{await a(C)},e[3]=a,e[4]=c):c=e[4],ax(i,c),!n||!u)return null;let m;e[5]!==n.label||e[6]!==r?(m=n.label??r("settings.projects.page.title.default"),e[5]=n.label,e[6]=r,e[7]=m):m=e[7];const g=m;let d;e[8]!==g?(d=t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:g}),e[8]=g,e[9]=d):d=e[9];let b;e[10]!==n.path?(b=t.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:n.path,children:n.path}),e[10]=n.path,e[11]=b):b=e[11];let h;e[12]!==d||e[13]!==b?(h=t.jsxs("div",{className:"mb-5 px-1",children:[d,b]}),e[12]=d,e[13]=b,e[14]=h):h=e[14];let f;e[15]!==i?(f=t.jsx(Zf,{form:i}),e[15]=i,e[16]=f):f=e[16];let y,P;e[17]!==u?(y=t.jsx(Xf,{projectRef:u}),P=t.jsx(Vf,{projectRef:u}),e[17]=u,e[18]=y,e[19]=P):(y=e[18],P=e[19]);let I;return e[20]!==h||e[21]!==f||e[22]!==y||e[23]!==P?(I=t.jsxs("div",{className:"space-y-0",children:[h,f,y,P]}),e[20]=h,e[21]=f,e[22]=y,e[23]=P,e[24]=I):I=e[24],I},ix=()=>{const s=Ze.c(18),{t:e}=st(),n=es(ox),a=es(lx),r=Ie(cx),i=Ie(dx);let l;e:{if(!r){l=null;break e}let b;s[0]!==n||s[1]!==r?(b=n.find(h=>h.id===r)??null,s[0]=n,s[1]=r,s[2]=b):b=s[2],l=b}const u=l;let c,x;s[3]!==n||s[4]!==r||s[5]!==i?(c=()=>{if(n.length===0){i(null);return}r&&n.some(b=>b.id===r)||i(n[0].id)},x=[n,r,i],s[3]=n,s[4]=r,s[5]=i,s[6]=c,s[7]=x):(c=s[6],x=s[7]),o.useEffect(c,x);let m;s[8]!==u||s[9]!==a?(m=async b=>{u&&a(u.id,{label:b.label,icon:b.icon,color:b.color,iconBackground:b.iconBackground,defaultModel:b.defaultModel??null})},s[8]=u,s[9]=a,s[10]=m):m=s[10];const g=m;if(!u){let b;s[11]!==e?(b=e("settings.projects.page.empty.noProjects"),s[11]=e,s[12]=b):b=s[12];let h;return s[13]!==b?(h=t.jsx(Ht,{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:b})})}),s[13]=b,s[14]=h):h=s[14],h}let d;return s[15]!==g||s[16]!==u?(d=t.jsx(Ht,{outerClassName:"h-full",className:"w-full bg-background",children:t.jsx("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:t.jsx(rx,{project:u,onIdentitySave:g})})}),s[15]=g,s[16]=u,s[17]=d):d=s[17],d};function ox(s){return s.projects}function lx(s){return s.updateProjectMeta}function cx(s){return s.settingsProjectsSelectedId}function dx(s){return s.setSettingsProjectsSelectedId}const Br=16384,or=globalThis,ux=s=>{if(or.Buffer)return or.Buffer.from(s,"utf8").toString("base64url");const e=new TextEncoder().encode(s);let n="";for(let a=0;a<e.length;a+=32768)n+=String.fromCharCode(...e.slice(a,a+32768));return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},mx=s=>{try{if(or.Buffer)return or.Buffer.from(s,"base64url").toString("utf8");const e=s.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(s.length/4)*4,"="),n=atob(e),a=new Uint8Array(n.length);for(let r=0;r<n.length;r+=1)a[r]=n.charCodeAt(r);return new TextDecoder().decode(a)}catch{return null}},px=s=>{if(typeof s!="string")return null;const e=s.trim();if(!e)return null;try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?null:(n.hash="",n.toString().replace(/\/+$/g,""))}catch{return null}},gx=s=>{if(typeof s!="string")return null;const e=s.trim();if(!e)return null;try{const n=new URL(e);return n.protocol!=="ws:"&&n.protocol!=="wss:"?null:(n.hash="",n.toString())}catch{return null}},cl=s=>typeof s=="string"&&s.length>0,hx=s=>{if(!s||typeof s!="object"||Array.isArray(s))return null;const e=s;return e.kty!=="EC"||e.crv!=="P-256"||!cl(e.x)||!cl(e.y)?null:{kty:"EC",crv:"P-256",x:e.x,y:e.y}},fx=s=>typeof s=="number"&&Number.isFinite(s)?s:void 0,xx=s=>{if(!s||typeof s!="object")return null;const e=s,n=fx(e.priority);if(e.type==="lan"||e.type==="tunnel"){const a=px(e.url);return a?n===void 0?{type:e.type,url:a}:{type:e.type,url:a,priority:n}:null}if(e.type==="relay"){const a=gx(e.relayUrl);if(!a)return null;const r=typeof e.serverId=="string"?e.serverId.trim():"";if(!r)return null;const i=hx(e.hostEncPubJwk);if(!i)return null;const l=typeof e.grant=="string"&&e.grant.trim()?e.grant.trim():void 0;return{type:"relay",relayUrl:a,serverId:r,hostEncPubJwk:i,...l?{grant:l}:{},...n===void 0?{}:{priority:n}}}return null},Lc=s=>{if(!s||typeof s!="object")return null;const e=s;if(e.v!==2)return null;const n=typeof e.pairingId=="string"?e.pairingId.trim():"",a=typeof e.secret=="string"?e.secret.trim():"";if(!n||!a)return null;const r=Array.isArray(e.candidates)?e.candidates.map(xx).filter(c=>!!c):[];if(r.length===0)return null;const i=typeof e.expiresAt=="string"&&e.expiresAt.trim()?e.expiresAt.trim():void 0;if(i){const c=Date.parse(i);if(!Number.isFinite(c)||c<=Date.now())return null}const l=typeof e.label=="string"&&e.label.trim()?e.label.trim():void 0,u=typeof e.fingerprint=="string"&&e.fingerprint.trim()?e.fingerprint.trim():void 0;return{v:2,pairingId:n,secret:a,...l?{label:l}:{},...u?{fingerprint:u}:{},...i?{expiresAt:i}:{},candidates:r}},yx=s=>({v:2,pairingId:s.pairingId.trim(),secret:s.secret.trim(),...s.label?.trim()?{label:s.label.trim()}:{},...s.fingerprint?.trim()?{fingerprint:s.fingerprint.trim()}:{},...s.expiresAt?.trim()?{expiresAt:s.expiresAt.trim()}:{},candidates:s.candidates}),bx=s=>{const e=Lc(s);if(!e)throw new Error("Invalid pairing connection payload");const n=new URLSearchParams;return n.set("v","2"),n.set("p",ux(JSON.stringify(e))),`openchamber://connect?${n.toString()}`},vx=s=>{const e=s.trim();if(!e||e.length>Br)return null;try{const n=new URL(e);if(n.protocol!=="openchamber:"||n.hostname!=="connect"||n.searchParams.get("v")!=="2")return null;const a=n.searchParams.get("p")||"";if(!a||a.length>Br)return null;const r=mx(a);return!r||r.length>Br?null:Lc(JSON.parse(r))}catch{return null}},vi=()=>Math.floor(2e4+Math.random()*3e4),jx=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")},wx=()=>{if(typeof navigator>"u")return;const s=(navigator.userAgent||"").toLowerCase();if(s.includes("mac"))return"macos";if(s.includes("win"))return"windows";if(s.includes("linux"))return"linux"},dl=s=>{switch((s||"").toLowerCase()){case"ios":return"iOS";case"android":return"Android";case"macos":case"darwin":return"macOS";case"windows":case"win32":return"Windows";case"linux":return"Linux";default:return null}},ul=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"}},Nx=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Oc=s=>!!(s&&Nx.has(s)),ml=s=>s==="ready"?"bg-[var(--status-success)] animate-pulse":s==="error"?"bg-[var(--status-error)] animate-pulse":s==="degraded"||Oc(s)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",kx=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}`,Sx=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:vi(),remoteHost:"127.0.0.1",remotePort:80}),Cx=s=>s.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Xs=s=>{const e=Ze.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(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let l;e[3]!==a?(l=t.jsxs(St,{children:[i,t.jsx(It,{sideOffset:8,className:"max-w-xs",children:t.jsx("div",{className:"typography-meta text-foreground",children:a})})]}),e[3]=a,e[4]=l):l=e[4];let u;return e[5]!==r||e[6]!==l?(u=t.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[r,l]}),e[5]=r,e[6]=l,e[7]=u):u=e[7],u},Ix=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"}},pl=(s,e)=>{const n=(s||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},Px=s=>{const e=(s||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Ax=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}`},ji=(s="",e="")=>({id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`header-${Date.now()}-${Math.random().toString(16).slice(2)}`,name:s,value:e}),Dx=s=>s.trim().toLowerCase()==="authorization",$r=s=>{const e={};for(const n of s){const a=n.name.trim(),r=n.value.trim();a&&r&&!Dx(a)&&(e[a]=r)}return Object.keys(e).length>0?e:void 0},Ex=s=>Object.entries(s||{}).map(([e,n])=>ji(e,n)),zc=()=>{if(typeof window>"u")return null;const e=ea()||window.location.href;try{const n=Number(new URL(e).port||window.location.port);return Number.isFinite(n)&&n>0?n:null}catch{const n=Number(window.location.port);return Number.isFinite(n)&&n>0?n:null}},gl=s=>{try{const e=new URL(s).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},Mx=async()=>{const s=$n(ea())||window.location.origin;if(!ns()||!Zn())return s;let e;try{e=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}})}catch{return s}if(!e.ok||(await e.json().catch(()=>null))?.desktopLanAccessActive!==!0)return s;const a=await yc(),r=zc();return!a||!r?s:`http://${a}:${r}`},Vr=s=>{const e=s.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Tx=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}},Rx=()=>{const{t:s}=st(),{clientAuth:e}=Di(),n=ns(),a=us(R=>R.instances),r=us(R=>R.statusesById),i=us(R=>R.importCandidates),l=us(R=>R.isLoading),u=us(R=>R.isImportsLoading),c=us(R=>R.isSaving),x=us(R=>R.error),m=us(R=>R.load),g=us(R=>R.loadImports),d=us(R=>R.refreshStatuses),b=us(R=>R.upsertInstance),h=us(R=>R.createFromCommand),f=us(R=>R.removeInstance),y=us(R=>R.connect),P=us(R=>R.disconnect),I=us(R=>R.retry),C=Ie(R=>R.settingsRemoteInstancesSelectedId),L=Ie(R=>R.setSettingsRemoteInstancesSelectedId),k=o.useMemo(()=>C&&a.find(R=>R.id===C)||null,[a,C]),[v,w]=o.useState(null),[E,K]=o.useState(!1),[U,M]=o.useState(!1),[S,A]=o.useState(null),[z,T]=o.useState([]),[Z,G]=o.useState(null),[te,Y]=o.useState(""),[N,W]=o.useState(!1),[B,F]=o.useState({}),[O,Q]=o.useState(!1),[H,ie]=o.useState(!1),[oe,se]=o.useState(()=>Date.now()),[xe,ae]=o.useState([]),[fe,Ce]=o.useState({}),[ge,ve]=o.useState("local"),[Ne,ne]=o.useState(!1),[re,ye]=o.useState(!1),[q,$]=o.useState(""),[ee,de]=o.useState(""),[De,ke]=o.useState(""),[Pe,Me]=o.useState([]),[Te,Ve]=o.useState(""),[Ue,Oe]=o.useState(null),[_e,Ke]=o.useState(!1),[Qe,Fe]=o.useState(!1),[V,le]=o.useState(null),[pe,Le]=o.useState(""),[we,He]=o.useState(""),[X,j]=o.useState(""),[be,Ae]=o.useState([]),[ze,Ge]=o.useState([]),[rt,it]=o.useState([]),[at,lt]=o.useState(!1),[Ye,We]=o.useState(""),[gt,me]=o.useState(null),[et,nt]=o.useState(null),[tt,ft]=o.useState(null),[bt,Rt]=o.useState(null),[ue,$e]=o.useState(!1),[Je,qe]=o.useState(!1),[yt,kt]=o.useState("configure"),[ht,Et]=o.useState(!1),[Jt,Zt]=o.useState("relay"),[cs,is]=o.useState(!0),[ts,As]=o.useState(null),Se=o.useMemo(()=>ze.filter(R=>!!R.revokedAt).length,[ze]),[vt,jt]=o.useState(!1),[Wt,Gt]=o.useState("ssh user@example.com"),[$t,fs]=o.useState("");o.useEffect(()=>{m(),g()},[m,g]);const ks=o.useCallback(async()=>{ne(!0),Oe(null);try{const R=await ro();ae(R.hosts||[]),ve(R.defaultHostId||"local")}catch(R){Oe(R instanceof Error?R.message:String(R))}finally{ne(!1)}},[]);o.useEffect(()=>{ks()},[ks]);const Qt=o.useCallback(async(R,je=ge)=>{ye(!0),Oe(null);try{await io({hosts:R,defaultHostId:je,initialHostChoiceCompleted:!0}),ae(R),ve(je)}catch(p){Oe(p instanceof Error?p.message:String(p))}finally{ye(!1)}},[ge]),Ts=o.useCallback(async()=>{const R=oo(ee);if(!R){Oe(s("desktopHostSwitcher.error.invalidUrl"));return}const je=R.persistedUrl,Re={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:q.trim()||la(je),url:je,apiUrl:je,...De.trim()?{clientToken:De.trim()}:{},...$r(Pe)?{requestHeaders:$r(Pe)}:{}};await Qt([Re,...xe],ge),$(""),de(""),ke(""),Me([]),Ke(!1),R.redeemUrl&&Vr(R.redeemUrl)},[ge,Pe,xe,q,De,ee,Qt,s]),kn=o.useCallback(async()=>{const R=vx(Te);if(!R){Oe(s("settings.remoteInstances.direct.error.invalidConnectLink"));return}const je=await Om().catch(()=>""),p=JSON.stringify({pairingId:R.pairingId,secret:R.secret,clientLabel:R.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:wx(),...je?{dedupeKey:`desktop:${je}`}:{}}),Re={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:p},mt=async Kt=>{if(!Kt.ok)return null;const Es=await Kt.json().catch(()=>null);return(typeof Es?.clientToken=="string"?Es.clientToken.trim():"")||null},Vt=[...R.candidates].sort((Kt,Es)=>(Kt.type==="relay"?1:0)-(Es.type==="relay"?1:0));let _t=null;for(const Kt of Vt){if(Kt.type==="relay"){const oa=zm({relayUrl:Kt.relayUrl,serverId:Kt.serverId,hostEncPubJwk:Kt.hostEncPubJwk,...Kt.grant?{grant:Kt.grant}:{}});try{const Pa=await oa.fetch("/api/client-auth/pairing/redeem",Re),Ki=await mt(Pa);if(Ki){_t={kind:"relay",relay:{relayUrl:Kt.relayUrl,serverId:Kt.serverId,hostEncPubJwk:Kt.hostEncPubJwk},token:Ki};break}}catch{}finally{oa.close()}continue}const Es=$n(Kt.url);if(Es)try{const oa=await fetch(`${Es}/api/client-auth/pairing/redeem`,Re),Pa=await mt(oa);if(Pa){_t={kind:"direct",url:Es,token:Pa};break}}catch{}}if(!_t){Oe(s("desktopHostSwitcher.error.invalidUrl"));return}const js=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Ls=R.candidates.find(Kt=>Kt.type==="relay"),Ds=_t.kind==="relay"?_t.relay:Ls?{relayUrl:Ls.relayUrl,serverId:Ls.serverId,hostEncPubJwk:Ls.hostEncPubJwk}:void 0,wr=R.candidates.filter(Kt=>Kt.type!=="relay").map(Kt=>$n(Kt.url)).find(Kt=>!!Kt),ra=_t.kind==="direct"?_t.url:wr,{token:Nr}=_t,Ft=ra||(Ds?Km(Ds.serverId):null);if(!Ft){Oe(s("desktopHostSwitcher.error.invalidUrl"));return}const ss={url:Ft,apiUrl:ra||void 0,clientToken:Nr,...Ds?{relay:Ds}:{}},ia=xe.find(Kt=>Ds?Kt.relay?.serverId===Ds.serverId:!Kt.relay&&$n(Kt.apiUrl||Kt.url)===Ft);if(ia){const Kt=xe.map(Es=>Es.id===ia.id?{...Es,label:R.label||Es.label,...ss}:Es);await Qt(Kt,ge)}else await Qt([{id:js(),label:R.label||la(Ft),...ss},...xe],ge);Ve(""),Oe(null),Fe(!1)},[Te,ge,xe,Qt,s]),Js=o.useCallback(async R=>{const je=xe.filter(Re=>Re.id!==R);await Qt(je,ge===R?"local":ge),V===R&&le(null)},[ge,V,xe,Qt]),Rs=o.useCallback(R=>{le(R.id),Le(R.label),He(R.apiUrl||R.url),j(R.clientToken||""),Ae(Ex(R.requestHeaders)),Oe(null)},[]),$s=o.useCallback(async()=>{if(!V)return;const R=oo(we);if(!R){Oe(s("desktopHostSwitcher.error.invalidUrl"));return}const je=R.persistedUrl,p=xe.map(Re=>Re.id===V?{...Re,label:pe.trim()||la(je),url:je,apiUrl:je,clientToken:X.trim()||void 0,requestHeaders:$r(be)}:Re);await Qt(p,ge),le(null),R.redeemUrl&&Vr(R.redeemUrl)},[ge,be,pe,X,we,V,xe,Qt,s]),ct=o.useCallback(async()=>{const R=Wt.trim();if(!R){_.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}const je=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await h(je,R,$t.trim()||s("settings.remoteInstances.sidebar.newSshInstanceName")),L(je),jt(!1),Gt("ssh user@example.com"),fs(""),_.success(s("settings.remoteInstances.page.toast.instanceCreated"))}catch(p){_.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:p instanceof Error?p.message:String(p)})}},[h,L,Wt,$t,s]),pt=o.useCallback(async R=>{await Qt(xe,R)},[xe,Qt]);o.useEffect(()=>{if(!n||xe.length===0)return;let R=!1;return Promise.all(xe.map(async je=>{const p=()=>Vm(je.relay).catch(()=>({status:"unreachable",latencyMs:0}));if(je.relay&&!je.apiUrl)return[je.id,await p()];const Re=$n(Um(je));if(!Re)return[je.id,je.relay?await p():{status:"unreachable",latencyMs:0}];const mt=await Bm(Re,{clientToken:je.clientToken||null,requestHeaders:je.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(mt.status==="unreachable"&&je.relay){const Vt=await p();if(Vt.status==="ok")return[je.id,Vt]}return[je.id,mt]})).then(je=>{R||Ce(Object.fromEntries(je))}),()=>{R=!0}},[xe,n]);const Nt=o.useCallback(async R=>{if(e){R?.silent||lt(!0),R?.silent||me(null);try{const[je,p]=await Promise.all([e.listClients(),e.listPendingPairings().catch(()=>null)]);Ge(je),p&&it(p)}catch(je){R?.silent||me(je instanceof Error?je.message:String(je))}finally{R?.silent||lt(!1)}}},[e]),Xt=o.useRef(!1);o.useEffect(()=>{if(!(!Je||yt!=="result"||!tt)){if(rt.some(R=>R.id===tt)){Xt.current=!0;return}Xt.current&&(ft(null),qe(!1),ze.some(R=>R.pairingId===tt)&&_.success(s("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Je,yt,tt,rt,ze,s]);const Yt=o.useCallback(async R=>{if(e)try{await e.cancelPairing(R),it(je=>je.filter(p=>p.id!==R)),await Nt({silent:!0})}catch(je){me(je instanceof Error?je.message:String(je))}},[e,Nt]);o.useEffect(()=>{if(!e)return;Nt();const R=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Nt({silent:!0})},5e3);return()=>window.clearInterval(R)},[e,Nt]);const cn=o.useCallback(async()=>{if(e?.getPairingTransports)try{const Re=await e.getPairingTransports();return{localUrl:Re.local,lanUrl:Re.lan,relayAvailable:Re.relayAvailable}}catch{}const R=zc(),je=R?`http://127.0.0.1:${R}`:gl(window.location.origin)?window.location.origin:null;let p=null;try{const Re=$n(await Mx());p=Re&&!gl(Re)?Re:null}catch{}return{localUrl:je,lanUrl:p,relayAvailable:!0}},[e]),dn=o.useCallback(async()=>{me(null),nt(null),Rt(null),$e(!1),ft(null),kt("configure"),is(!0),qe(!0);const R=await cn();As(R),Zt(R.relayAvailable?"relay":R.lanUrl?"lan":"local")},[cn]),Sn=o.useCallback(async()=>{if(!(!e?.createPairingSession||!ts)){me(null),Et(!0);try{const R=Ye.trim()||void 0;let je,p,Re=!0;Jt==="local"?(je=ts.localUrl??void 0,p=!1):Jt==="lan"?(je=ts.lanUrl??void 0,p=cs):cs&&ts.lanUrl?(je=ts.lanUrl,p=!0):(Re=!1,p=!0);const{pairing:mt,server:Vt}=await e.createPairingSession({label:R,allowedClientKinds:["mobile","desktop"],serverUrl:je,includeRelay:p,includeDirect:Re}),_t=yx({pairingId:mt.id,secret:mt.secret,label:Vt.label,fingerprint:mt.fingerprint??void 0,expiresAt:mt.expiresAt,candidates:Vt.candidates}),js=bx(_t);nt(js),Rt(await nc.toDataURL(js,{width:1024,margin:2,errorCorrectionLevel:"L"})),$e(!1),Xt.current=!1,ft(mt.id),kt("result"),await Nt({silent:!0})}catch(R){me(R instanceof Error?R.message:String(R))}finally{Et(!1)}}},[e,ts,Jt,cs,Ye,Nt]),ta=o.useCallback(()=>{et&&Dn(et).then(R=>{R.ok&&($e(!0),window.setTimeout(()=>$e(!1),2e3))})},[et]),sa=o.useCallback(async R=>{if(!e)return;const je=R.clientKind==="desktop-local";me(null);try{if(await e.revokeClient(R.id),je&&ns()){const p=await ro();await io({hosts:p.hosts,defaultHostId:p.defaultHostId,initialHostChoiceCompleted:p.initialHostChoiceCompleted,localClientToken:null}),Ge(Re=>Re.map(mt=>mt.id===R.id?{...mt,revokedAt:new Date().toISOString()}:mt)),$m({apiBaseUrl:ea(),clientToken:null,runtimeKey:"local"});return}await Nt()}catch(p){me(p instanceof Error?p.message:String(p))}},[e,Nt]),na=o.useCallback(async()=>{if(e){me(null);try{await e.purgeRevokedClients(),await Nt()}catch(R){me(R instanceof Error?R.message:String(R))}}},[e,Nt]);o.useEffect(()=>{w(k)},[k]),o.useEffect(()=>{if(!C)return;const R=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||d()},2e3);return()=>{window.clearInterval(R)}},[d,C]),o.useEffect(()=>{let R=null,je=Date.now();const p=()=>{const mt=Date.now();mt-je>=1e3&&(se(mt),je=mt),R=requestAnimationFrame(p)};(typeof document>"u"||document.visibilityState==="visible")&&(R=requestAnimationFrame(p));const Re=()=>{document.visibilityState==="visible"&&R===null?R=requestAnimationFrame(p):document.visibilityState!=="visible"&&R!==null&&(cancelAnimationFrame(R),R=null)};return document.addEventListener("visibilitychange",Re),()=>{document.removeEventListener("visibilitychange",Re),R!==null&&cancelAnimationFrame(R)}},[]);const Cs=C?r[C]:null,Vs=Cs?.phase,Qs=Vs==="ready",Fs=Vs==="degraded",_s=Oc(Vs),zs=Qs||(_s||Fs),Be=Cs?Math.max(0,oe-Cs.updatedAtMs):0,ds=Fs&&Be>12e3,hr=o.useMemo(()=>!v||!k?!1:JSON.stringify(v)!==JSON.stringify(k),[v,k]),as=o.useCallback(R=>{w(je=>je&&R(je))},[]),Sa=o.useCallback(async()=>{if(!v)return;const R=Tx(v);if(!R.sshCommand.trim()){_.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(R.localForward.bindHost==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(R.auth.sshPassword?.enabled&&R.auth.sshPassword.value?.trim()&&R.auth.sshPassword.store!=="settings"){const je=window.confirm(s("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));R.auth.sshPassword.store=je?"settings":"never",je||(R.auth.sshPassword.value=void 0)}if(R.auth.openchamberPassword?.enabled&&R.auth.openchamberPassword.value?.trim()&&R.auth.openchamberPassword.store!=="settings"){const je=window.confirm(s("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));R.auth.openchamberPassword.store=je?"settings":"never",je||(R.auth.openchamberPassword.value=void 0)}try{await b(R),_.success(s("settings.remoteInstances.page.toast.instanceSaved"))}catch(je){_.error(s("settings.remoteInstances.page.toast.saveFailed"),{description:je instanceof Error?je.message:String(je)})}}},[v,s,b]),Ln=o.useCallback(async(R,je)=>{const p=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await h(p,`ssh ${je}`,R),L(p),_.success(s("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Re){return _.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:Re instanceof Error?Re.message:String(Re)}),!1}},[h,L,s]),On=o.useCallback(()=>{N||(G(null),Y(""))},[N]),fr=o.useCallback((R,je)=>{if(je){G(R),Y(Cx(R));return}Ln(R,R)},[Ln]),Ca=o.useCallback(async()=>{const R=Z,je=te.trim();if(R){if(!je){_.error(s("settings.remoteInstances.page.toast.destinationRequired"));return}W(!0);try{await Ln(R,je)&&(G(null),Y(""))}finally{W(!1)}}},[Ln,te,Z,s]),Ks=o.useCallback(async()=>{if(k)try{await y(k.id);return}catch(R){if(!jx(R)||!window.confirm(s("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw R;const p={...k,localForward:{...k.localForward,preferredLocalPort:vi()}};await b(p),await y(p.id),_.success(s("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[y,k,s,b]),Us=o.useCallback(async R=>(await Hu(R,600)).map(p=>Ax(p)),[]),un=o.useCallback(async()=>{if(v){K(!0),M(!0),A(null);try{const R=await Us(v.id);T(R)}catch(R){T([]),A(R instanceof Error?R.message:String(R))}finally{M(!1)}}},[v,Us]);o.useEffect(()=>{if(!E||!v)return;let R=!1;const je=async()=>{try{const Re=await Us(v.id);R||(T(Re),A(null))}catch(Re){R||A(Re instanceof Error?Re.message:String(Re))}};je();const p=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||je()},1e3);return()=>{R=!0,window.clearInterval(p)}},[v,E,Us]);const mn=o.useMemo(()=>z.join(`
28
+ `),[z]),xr=o.useCallback(()=>{if(!mn.trim()){_.error(s("settings.remoteInstances.page.toast.noLogsToCopy"));return}Dn(mn).then(R=>{R.ok&&_.success(s("settings.remoteInstances.page.toast.logsCopied"))})},[mn,s]),aa=o.useCallback(async()=>{if(v)try{await Wu(v.id),T([]),_.success(s("settings.remoteInstances.page.toast.logsCleared"))}catch(R){_.error(s("settings.remoteInstances.page.toast.clearLogsFailed"),{description:R instanceof Error?R.message:String(R)})}},[v,s]),Ys=o.useCallback(async()=>{if(!Cs?.localUrl){_.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const R=Cs.localUrl.trim();if(!R){_.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Vr(R)},[Cs?.localUrl,s]),zn=o.useCallback(()=>{if(!v)return;Q(!0),(zs?P(v.id):Ks()).catch(je=>{const p=zs?Qs?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";_.error(s(p),{description:je instanceof Error?je.message:String(je)})}).finally(()=>{Q(!1)})},[zs,Ks,P,v,Qs,s]),pn=o.useCallback(()=>{if(!v||_s)return;ie(!0),(Fs?P(v.id).then(()=>Ks()):I(v.id)).catch(je=>{_.error(s("settings.remoteInstances.page.toast.retryFailed"),{description:je instanceof Error?je.message:String(je)})}).finally(()=>{ie(!1)})},[Ks,P,v,_s,Fs,I,s]),yr=s(_s?"settings.remoteInstances.page.actions.connecting":Fs?ds?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),br=!O&&!H&&(Vs==="error"||Vs==="idle"||!Vs||Fs&&ds)&&!_s,vr=s(Qs?"settings.remoteInstances.sidebar.actions.disconnect":zs?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!v)return t.jsxs(bi,{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.jsx("div",{children:t.jsxs(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{dn()},children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.clientAuth.actions.addDevice")]})}),t.jsxs("div",{className:"space-y-1",children:[Se>0?t.jsx("div",{className:"flex justify-end",children:t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{na()},children:s("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,at&&ze.length===0&&rt.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.state.loading")}):ze.length===0&&rt.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.state.empty")}):t.jsxs(t.Fragment,{children:[rt.map(R=>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 shrink-0 rounded-full bg-[var(--status-warning)] animate-pulse"}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:R.label||s("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),R.usesRelay?t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:s("settings.remoteInstances.clientAuth.state.viaRelay")}):null]}),t.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:s("settings.remoteInstances.clientAuth.state.pending")})]}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Yt(R.id)},children:s("settings.common.actions.cancel")})]},`pending-${R.id}`)),ze.map(R=>{const je=R.clientKind==="desktop-local",p=R.lastUsedAt?Date.parse(R.lastUsedAt):Number.NaN,Re=!R.revokedAt&&(je||Number.isFinite(p)&&Date.now()-p<9e4),mt=R.revokedAt?s("settings.remoteInstances.clientAuth.state.revoked"):Re?R.lastTransport==="relay"&&!je?s("settings.remoteInstances.clientAuth.state.connectedRelay"):s("settings.remoteInstances.clientAuth.state.connectedDirect"):R.lastUsedAt?s("settings.remoteInstances.clientAuth.lastUsed",{date:R.lastUsedAt}):s("settings.remoteInstances.clientAuth.neverUsed");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:ce("h-2 w-2 shrink-0 rounded-full",R.revokedAt?"bg-muted-foreground/20":Re?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:R.label}),dl(R.devicePlatform)?t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:dl(R.devicePlatform)}):null,je?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:ce("typography-micro truncate",Re&&!R.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:mt})]}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{sa(R)},disabled:!!R.revokedAt,children:s("settings.remoteInstances.clientAuth.actions.revoke")})]},R.id)})]})]}),gt?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:gt}):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 flex items-start justify-between gap-3 px-1",children:[t.jsxs("div",{className:"min-w-0 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("div",{className:"flex shrink-0 items-center gap-2 pt-0.5",children:[t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Fe(!0),disabled:re,children:s("settings.remoteInstances.direct.import.action")}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ke(!0),disabled:re,children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.actions.add")]})]})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[t.jsx("div",{className:"space-y-1",children:Ne?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(R=>{const je=fe[R.id],p=je?je.status==="ok"?"desktopHostSwitcher.status.connected":je.status==="auth"?"desktopHostSwitcher.status.authRequired":je.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":je.status==="incompatible"?"desktopHostSwitcher.status.incompatible":je.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",Re=je?.status==="ok";return 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("span",{className:ce("h-2 w-2 shrink-0 rounded-full",je?Re?"bg-[var(--status-success)]":"bg-[var(--status-error)]":"bg-muted-foreground/30 animate-pulse")}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:la(R.label)}),ge===R.id?t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:s("desktopHostSwitcher.header.default")}):null,t.jsxs("span",{className:ce("typography-micro shrink-0",Re?"text-[var(--status-success)]":"text-muted-foreground"),children:[s(p),Re&&typeof je?.latencyMs=="number"?s("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(je.latencyMs))}):""]})]}),t.jsx("p",{className:ce("typography-micro text-muted-foreground truncate",R.apiUrl&&"font-mono"),children:R.relay&&!R.apiUrl?s("mobile.connect.relay.badge"):la(R.apiUrl||R.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:()=>{pt(R.id)},disabled:re||ge===R.id,"aria-label":s("desktopHostSwitcher.actions.setAsDefaultAria"),children:ge===R.id?t.jsx(D,{name:"star-fill",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"star",className:"h-3.5 w-3.5"})}),R.relay&&!R.apiUrl?null:t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Rs(R),disabled:re,children:[t.jsx(D,{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:()=>{Js(R.id)},disabled:re,children:[t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]})},R.id)})}),Ue?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ue}):null]})]}):null,n?t.jsx(Mt,{open:_e,onOpenChange:Ke,children:t.jsxs(Tt,{className:"sm:max-w-lg",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("settings.remoteInstances.direct.actions.add")}),t.jsx(Bt,{children:s("settings.remoteInstances.direct.addDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:R=>{R.preventDefault(),Ts()},children:[t.jsx(Xe,{className:"h-8",value:q,onChange:R=>$(R.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:re}),t.jsx(Xe,{className:"h-8",value:ee,onChange:R=>de(R.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:re,autoFocus:!0}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(Xe,{className:"h-8",value:De,onChange:R=>ke(R.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:re}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:s("settings.remoteInstances.direct.note")})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.remoteInstances.direct.headers.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.headers.description")})]}),Pe.map(R=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(Xe,{className:"h-8 font-mono text-xs",value:R.name,onChange:je=>Me(p=>p.map(Re=>Re.id===R.id?{...Re,name:je.target.value}:Re)),placeholder:s("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:re}),t.jsx(Xe,{className:"h-8 font-mono text-xs",value:R.value,onChange:je=>Me(p=>p.map(Re=>Re.id===R.id?{...Re,value:je.target.value}:Re)),placeholder:s("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:re}),t.jsx("button",{type:"button",onClick:()=>Me(je=>je.filter(p=>p.id!==R.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":s("settings.remoteInstances.direct.headers.removeAria"),disabled:re,children:t.jsx(D,{name:"close",className:"h-4 w-4"})})]},R.id)),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Me(R=>[...R,ji()]),disabled:re,children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.headers.actions.add")]})]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ke(!1),disabled:re,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:re||!ee.trim(),children:s("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?t.jsx(Mt,{open:!!V,onOpenChange:R=>{R||le(null)},children:t.jsxs(Tt,{className:"sm:max-w-lg",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("desktopHostSwitcher.actions.edit")}),t.jsx(Bt,{children:s("settings.remoteInstances.direct.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:R=>{R.preventDefault(),$s()},children:[t.jsx(Xe,{className:"h-8",value:pe,onChange:R=>Le(R.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:re}),t.jsx(Xe,{className:"h-8",value:we,onChange:R=>He(R.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:re,autoFocus:!0}),t.jsx(Xe,{className:"h-8",value:X,onChange:R=>j(R.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:re}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.remoteInstances.direct.headers.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.headers.description")})]}),be.map(R=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(Xe,{className:"h-8 font-mono text-xs",value:R.name,onChange:je=>Ae(p=>p.map(Re=>Re.id===R.id?{...Re,name:je.target.value}:Re)),placeholder:s("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:re}),t.jsx(Xe,{className:"h-8 font-mono text-xs",value:R.value,onChange:je=>Ae(p=>p.map(Re=>Re.id===R.id?{...Re,value:je.target.value}:Re)),placeholder:s("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:re}),t.jsx("button",{type:"button",onClick:()=>Ae(je=>je.filter(p=>p.id!==R.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":s("settings.remoteInstances.direct.headers.removeAria"),disabled:re,children:t.jsx(D,{name:"close",className:"h-4 w-4"})})]},R.id)),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ae(R=>[...R,ji()]),disabled:re,children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.headers.actions.add")]})]}),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:re,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:re,children:s("settings.common.actions.saveChanges")})]})]})]})}):null,n?t.jsx(Mt,{open:Qe,onOpenChange:Fe,children:t.jsxs(Tt,{className:"sm:max-w-lg",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("settings.remoteInstances.direct.import.action")}),t.jsx(Bt,{children:s("settings.remoteInstances.direct.import.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:R=>{R.preventDefault(),kn()},children:[t.jsx(Xe,{className:"h-8",value:Te,onChange:R=>Ve(R.target.value),placeholder:s("settings.remoteInstances.direct.import.placeholder"),disabled:re,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:()=>Fe(!1),disabled:re,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:re||!Te.trim(),children:s("settings.remoteInstances.direct.import.action")})]})]})]})}):null,t.jsx(Mt,{open:Je,onOpenChange:qe,children:t.jsxs(Tt,{className:yt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s(yt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),t.jsx(Bt,{children:s(yt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),yt==="configure"?t.jsxs("form",{className:"space-y-4",onSubmit:R=>{R.preventDefault(),Sn()},children:[t.jsx(Xe,{className:"h-8",value:Ye,onChange:R=>We(R.target.value),placeholder:s("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),t.jsx("div",{role:"radiogroup","aria-label":s("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:s("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:s("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!ts?.relayAvailable},{key:"lan",label:s("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:s("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!ts?.lanUrl},{key:"local",label:s("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:s("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!ts?.localUrl}].map(R=>{const je=Jt===R.key;return t.jsxs("div",{className:ce("flex items-start gap-2 py-0.5",R.available?"cursor-pointer":"opacity-45"),onClick:()=>{R.available&&Zt(R.key)},role:"presentation",children:[t.jsx(tn,{checked:je,disabled:!R.available,onChange:()=>Zt(R.key),ariaLabel:R.label,className:"mt-0.5"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:ce("typography-ui-label font-normal",je?"text-foreground":"text-foreground/70"),children:R.label}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:R.hint})]})]},R.key)})}),Jt==="lan"?t.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[t.jsx(xt,{checked:cs,onChange:is,ariaLabel:s("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,Jt==="relay"&&ts?.lanUrl?t.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[t.jsx(xt,{checked:cs,onChange:is,ariaLabel:s("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")})]}):null]}),gt?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:gt}):null,t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>qe(!1),disabled:ht,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:ht||!ts,children:s("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):t.jsxs("div",{className:"space-y-3",children:[bt?t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:bt,alt:s("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,et?t.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[t.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:et}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:ta,children:[t.jsx(D,{name:ue?"check":"file-copy",className:ce("h-3.5 w-3.5",ue&&"text-[var(--status-success)]")}),s(ue?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,t.jsx("div",{className:"flex justify-end",children:t.jsx(J,{type:"button",size:"xs",className:"!font-normal",onClick:()=>qe(!1),children:s("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),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:()=>jt(!0),children:[t.jsx(D,{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:l?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(R=>{const je=r[R.id],p=R.nickname?.trim()||R.sshParsed?.destination||R.id,Re=je?.phase,mt=Re==="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 ${ml(Re)}`}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:p})]}),t.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[s(ul(Re)),je?.localUrl?` · ${je.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:()=>{(mt?P(R.id):y(R.id)).catch(_t=>_.error(s(mt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:_t instanceof Error?_t.message:String(_t)}))},children:[mt?t.jsx(D,{name:"stop",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"plug-2",className:"h-3.5 w-3.5"}),s(mt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),t.jsxs(J,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>L(R.id),children:[t.jsx(D,{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"))&&f(R.id).catch(_t=>_.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:_t instanceof Error?_t.message:String(_t)}))},children:[t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]},R.id)})})]}):null,n?t.jsx(Mt,{open:vt,onOpenChange:jt,children:t.jsxs(Tt,{className:"sm:max-w-lg",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("settings.remoteInstances.sidebar.actions.addSshInstance")}),t.jsx(Bt,{children:s("settings.remoteInstances.page.section.instanceDescription")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:R=>{R.preventDefault(),ct()},children:[t.jsx(Xe,{className:"h-8",value:$t,onChange:R=>fs(R.target.value),placeholder:s("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:c}),t.jsx(Xe,{className:"h-8",value:Wt,onChange:R=>Gt(R.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:()=>jt(!1),disabled:c,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:c||!Wt.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:u?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(R=>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:[R.host,R.pattern?` ${s("settings.remoteInstances.page.import.patternSuffix")}`:""]}),t.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:R.sshCommand})]}),t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{fr(R.host,R.pattern)},children:s("settings.common.actions.import")})]},`${R.source}:${R.host}`))})})]}):null,t.jsx(Mt,{open:!!Z,onOpenChange:R=>{R||On()},children:t.jsxs(Tt,{className:"sm:max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx(Bt,{children:Z?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Z}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:R=>{R.preventDefault(),Ca()},children:[t.jsx(Xe,{value:te,onChange:R=>Y(R.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:On,disabled:N,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:N,children:s("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Ia=v.remoteOpenchamber.mode==="managed",jr=v.nickname?.trim()||v.sshParsed?.destination||v.id;return t.jsx(Mt,{open:!!v,onOpenChange:R=>{R||L(null)},children:t.jsxs(Tt,{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:jr}),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 ${ml(Vs)}`}),t.jsx("span",{children:s(ul(Vs))}),Cs?.localUrl?t.jsx("span",{className:"font-mono text-foreground/80",children:Cs.localUrl}):null,ds?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:zs?"outline":"default",size:"xs",className:"!font-normal",onClick:zn,disabled:O||H,children:[zs?t.jsx(D,{name:"stop",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"plug-2",className:"h-3.5 w-3.5"}),vr]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:pn,disabled:!br,children:[t.jsx(D,{name:"refresh",className:`h-3.5 w-3.5 ${_s||Fs&&!ds?"animate-spin":""}`}),yr]}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{un()},children:[t.jsx(D,{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"))&&f(v.id).then(()=>{L(null),_.success(s("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(je=>{_.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:je instanceof Error?je.message:String(je)})})},children:[t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.sidebar.actions.remove")]})]}),Cs?.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:Cs.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(Xe,{className:"h-7 md:max-w-xl",value:v.sshCommand,onChange:R=>as(je=>({...je,sshCommand:R.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(Xe,{className:"h-7 md:max-w-sm",value:v.nickname||"",onChange:R=>as(je=>({...je,nickname:R.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(bs,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:v.connectionTimeoutSec,onValueChange:R=>{as(je=>({...je,connectionTimeoutSec:Number.isFinite(R)?R:je.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(Xs,{label:s("settings.remoteInstances.page.field.mode"),hint:s("settings.remoteInstances.page.field.modeHint")})}),t.jsxs(Pt,{value:v.remoteOpenchamber.mode,onValueChange:R=>as(je=>({...je,remoteOpenchamber:{...je.remoteOpenchamber,mode:R==="external"?"external":"managed"}})),children:[t.jsx(At,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Lt,{placeholder:s("settings.remoteInstances.page.field.modePlaceholder")})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"managed",children:s("settings.remoteInstances.page.field.modeManaged")}),t.jsx(ut,{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(Xs,{label:s("settings.remoteInstances.page.field.preferredRemotePort"),hint:s("settings.remoteInstances.page.field.preferredRemotePortHint")})}),t.jsx(bs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.remoteOpenchamber.preferredPort,onValueChange:R=>{as(je=>({...je,remoteOpenchamber:{...je.remoteOpenchamber,preferredPort:Number.isFinite(R)&&R>0?R:void 0}}))},onClear:()=>{as(R=>({...R,remoteOpenchamber:{...R.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]}),Ia?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(Xs,{label:s("settings.remoteInstances.page.field.installMethod"),hint:s("settings.remoteInstances.page.field.installMethodHint")})}),t.jsxs(Pt,{value:v.remoteOpenchamber.installMethod,onValueChange:R=>as(je=>({...je,remoteOpenchamber:{...je.remoteOpenchamber,installMethod:R==="npm"||R==="download_release"||R==="upload_bundle"?R:"bun"}})),children:[t.jsx(At,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Lt,{placeholder:s("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"bun",children:"bun"}),t.jsx(ut,{value:"npm",children:"npm"}),t.jsx(ut,{value:"download_release",children:s("settings.remoteInstances.page.field.installMethodDownloadRelease")}),t.jsx(ut,{value:"upload_bundle",children:s("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,Ia?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(Xs,{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(ir,{checked:v.remoteOpenchamber.keepRunning,onCheckedChange:R=>as(je=>({...je,remoteOpenchamber:{...je.remoteOpenchamber,keepRunning:R}}))})})]}):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(Xs,{label:s("settings.remoteInstances.page.field.bindHost"),hint:s("settings.remoteInstances.page.field.bindHostHint")})}),t.jsxs(Pt,{value:v.localForward.bindHost,onValueChange:R=>{R==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces"))||as(je=>({...je,localForward:{...je.localForward,bindHost:R==="localhost"||R==="0.0.0.0"?R:"127.0.0.1"}}))},children:[t.jsx(At,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Lt,{placeholder:s("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"127.0.0.1",children:"127.0.0.1"}),t.jsx(ut,{value:"localhost",children:"localhost"}),t.jsx(ut,{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(Xs,{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(bs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.localForward.preferredLocalPort,onValueChange:R=>{as(je=>({...je,localForward:{...je.localForward,preferredLocalPort:Number.isFinite(R)&&R>0?R:void 0}}))},onClear:()=>{as(R=>({...R,localForward:{...R.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:()=>as(R=>({...R,localForward:{...R.localForward,preferredLocalPort:vi()}})),children:t.jsx(D,{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(Xe,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.sshPassword?.value||"",onChange:R=>as(je=>({...je,auth:{...je.auth,sshPassword:{enabled:R.target.value.trim().length>0,value:R.target.value,store:je.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(Xe,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.openchamberPassword?.value||"",onChange:R=>as(je=>({...je,auth:{...je.auth,openchamberPassword:{enabled:R.target.value.trim().length>0,value:R.target.value,store:je.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:[v.portForwards.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:s("settings.remoteInstances.page.empty.noExtraForwards")}):null,v.portForwards.map((R,je)=>{const p=Ft=>{as(ss=>({...ss,portForwards:ss.portForwards.map((ia,Kt)=>Kt===je?Ft(ia):ia)}))},Re=R.type==="remote"?"Local target":"Local listen",mt=R.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.",Vt=R.type==="remote"?"Remote listen":"Remote target",_t=R.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",js=pl(R.localHost||"localhost",R.localPort),Ls=pl(R.remoteHost||"localhost",R.remotePort),Ds=R.type==="local"&&typeof R.localPort=="number"&&R.localPort>0,wr=Ds?`http://${Px(R.localHost)}:${R.localPort}`:"",ra=!!B[R.id],Nr=R.type==="local"?s("settings.remoteInstances.page.forwardType.local"):R.type==="remote"?s("settings.remoteInstances.page.forwardType.remote"):s("settings.remoteInstances.page.forwardType.dynamic");return t.jsxs(En,{open:ra,onOpenChange:Ft=>{F(ss=>({...ss,[R.id]:Ft}))},className:`${je>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(Mn,{className:"flex items-center gap-2 group",children:[t.jsx(D,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${ra?"rotate-180":""}`}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:kx(R)}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Nr})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ir,{checked:R.enabled,onCheckedChange:Ft=>p(ss=>({...ss,enabled:Ft})),"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:()=>as(Ft=>({...Ft,portForwards:Ft.portForwards.filter(ss=>ss.id!==R.id)})),children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Tn,{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(Ix(R.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(Xs,{label:s("settings.remoteInstances.page.field.forwardType"),hint:s("settings.remoteInstances.page.field.forwardTypeHint")})}),t.jsxs(Pt,{value:R.type,onValueChange:Ft=>p(ss=>({...ss,type:Ft==="dynamic"||Ft==="remote"?Ft:"local"})),children:[t.jsx(At,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Lt,{placeholder:s("settings.remoteInstances.page.field.typePlaceholder")})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"local",children:s("settings.remoteInstances.page.forwardType.local")}),t.jsx(ut,{value:"remote",children:s("settings.remoteInstances.page.forwardType.remote")}),t.jsx(ut,{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(Xs,{label:Re,hint:mt})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(Xe,{className:"h-7 w-32",value:R.localHost||"127.0.0.1",onChange:Ft=>p(ss=>({...ss,localHost:Ft.target.value})),placeholder:s("settings.remoteInstances.page.field.localHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(bs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:R.localPort,onValueChange:Ft=>{p(ss=>({...ss,localPort:Number.isFinite(Ft)&&Ft>0?Ft:void 0}))},onClear:()=>{p(Ft=>({...Ft,localPort:void 0}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]})]}),R.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(Xs,{label:Vt,hint:_t})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(Xe,{className:"h-7 w-32",value:R.remoteHost||"",onChange:Ft=>p(ss=>({...ss,remoteHost:Ft.target.value})),placeholder:s("settings.remoteInstances.page.field.remoteHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(bs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:R.remotePort,onValueChange:Ft=>{p(ss=>({...ss,remotePort:Number.isFinite(Ft)&&Ft>0?Ft:void 0}))},onClear:()=>{p(Ft=>({...Ft,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:R.type==="dynamic"?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:js}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.localSocks5")})]}):R.type==="remote"?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"server",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:Ls}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.remote")}),t.jsx(D,{name:"arrow-right",className:"h-3.5 w-3.5"}),t.jsx(D,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:js}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.local")})]}):t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:js}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.local")}),t.jsx(D,{name:"arrow-right",className:"h-3.5 w-3.5"}),t.jsx(D,{name:"server",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:Ls}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.remote")})]})}),Ds?t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{on(wr).then(Ft=>{Ft||_.error(s("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[t.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},R.id)}),t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const R=Sx();as(je=>({...je,portForwards:[...je.portForwards,R]})),F(je=>({...je,[R.id]:!0}))},children:[t.jsx(D,{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:()=>{Sa()},disabled:!hr||c,children:s("settings.common.actions.saveChanges")}),Cs?.localUrl?t.jsxs(t.Fragment,{children:[t.jsxs(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Dn(Cs.localUrl||"").then(R=>{R.ok&&_.success(s("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[t.jsx(D,{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:()=>{Ys()},children:[t.jsx(D,{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(Mt,{open:E,onOpenChange:K,children:t.jsxs(Tt,{className:"sm:max-w-2xl",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("settings.remoteInstances.page.logsDialog.title")}),t.jsx(Bt,{children:v?.nickname?.trim()||v?.sshParsed?.destination||v?.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:xr,disabled:U||!mn.trim(),children:[t.jsx(D,{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:()=>{aa()},disabled:U,children:[t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.clear")]})]}),U?t.jsx("div",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.logsDialog.loading")}):S?t.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:S}):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:z.length>0?z.join(`
29
+ `):s("settings.remoteInstances.page.logsDialog.empty")})]})}),t.jsx(Mt,{open:!!Z,onOpenChange:R=>{R||On()},children:t.jsxs(Tt,{className:"sm:max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx(Bt,{children:Z?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Z}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:R=>{R.preventDefault(),Ca()},children:[t.jsx(Xe,{value:te,onChange:R=>Y(R.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:On,disabled:N,children:s("settings.common.actions.cancel")}),t.jsx(J,{type:"submit",size:"xs",className:"!font-normal",disabled:N,children:s("settings.common.actions.create")})]})]})]})})]})})},Fx="__add_provider__",Lx=()=>{const s=vs.getDirectory();return typeof s=="string"&&s.trim().length>0?s.trim():null},Ox=({onItemSelect:s})=>{const{t:e}=st(),n=ot(d=>d.providers),a=ot(d=>d.selectedProviderId),r=ot(d=>d.setSelectedProvider),i=es(d=>d.activeProjectId),[l,u]=o.useState({}),c=o.useMemo(()=>Lx(),[i]);o.useEffect(()=>{if(n.length===0){u({});return}let d=!1;return(async()=>{const h=n.map(async f=>{try{const y=c?`?directory=${encodeURIComponent(c)}`:"",P=await dt(`/api/provider/${encodeURIComponent(f.id)}/source${y}`,{method:"GET",headers:{Accept:"application/json"}});if(!P.ok)return;const I=await P.json().catch(()=>null),C=I?.sources??I?.data?.sources;if(!C||d)return;u(L=>({...L,[f.id]:C}))}catch{}});await Promise.all(h)})(),()=>{d=!0}},[c,n]);const x="bg-background",m=o.useMemo(()=>n.filter(d=>!!l[d.id]?.project?.exists),[n,l]),g=o.useMemo(()=>n.filter(d=>!l[d.id]?.project?.exists),[n,l]);return t.jsxs("div",{className:ce("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(Na,{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(Fx),s?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:t.jsx(D,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Ht,{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(D,{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:[g.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")}),g.map(d=>t.jsx(hl,{provider:d,selectedProviderId:a,onSelect:()=>{r(d.id),s?.()}},d.id))]}),m.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:ce("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",g.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(d=>t.jsx(hl,{provider:d,selectedProviderId:a,onSelect:()=>{r(d.id),s?.()}},d.id))]})]})})]})},hl=s=>{const e=Ze.c(17),{provider:n,selectedProviderId:a,onSelect:r}=s,i=Array.isArray(n.models)?n.models.length:0,l=n.id===a,u=n.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[0]!==c?(x=ce("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(Jn,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const g=n.name||n.id;let d;e[4]!==g?(d=t.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:g}),e[4]=g,e[5]=d):d=e[5];let b;e[6]!==i?(b=t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=b):b=e[7];let h;e[8]!==r||e[9]!==m||e[10]!==d||e[11]!==b?(h=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,d,b]}),e[8]=r,e[9]=m,e[10]=d,e[11]=b,e[12]=h):h=e[12];let f;return e[13]!==n.id||e[14]!==x||e[15]!==h?(f=t.jsx("div",{className:x,children:h},u),e[13]=n.id,e[14]=x,e[15]=h,e[16]=f):f=e[16],f},zx=s=>s,_r=({providerId:s,providerName:e})=>{const{t:n}=st(),[a,r]=o.useState(null),[i,l]=o.useState({}),[u,c]=o.useState(!1),x=`/api/quota/credentials/${s}`;o.useEffect(()=>{dt(x).then(async d=>{if(!d.ok)throw new Error;const b=await d.json();r(b),l(b.workspaceId?{workspaceId:b.workspaceId}:{})}).catch(()=>r({configured:!1}))},[x]);const m=async(d,b,h)=>{c(!0);try{const f=await dt(d,{method:b,headers:h?{"Content-Type":"application/json"}:void 0,body:h?JSON.stringify(h):void 0}),y=await f.json().catch(()=>null);if(!f.ok)throw new Error(y?.error);y?.configured!==void 0&&r(y),l(P=>P.workspaceId?{workspaceId:P.workspaceId}:{}),_.success(n("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(f){_.error(f instanceof Error&&f.message?f.message:n("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},g=(d,b,h)=>t.jsxs("label",{className:"block typography-ui-label text-foreground",children:[b,t.jsx(Xe,{className:"mt-1 h-7 font-mono text-xs",type:d==="workspaceId"?"text":"password",autoComplete:"off",value:i[d]??"",onChange:f=>l(y=>({...y,[d]:f.target.value})),placeholder:a?.secretMasked??h})]});return t.jsxs("div",{"data-settings-item":`providers.${s}-credentials`,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:e})}),t.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s==="opencode-go"&&g("workspaceId",n("settings.providers.page.openCodeGo.workspaceId"),"wrk_..."),s==="opencode-go"&&g("authCookie",n("settings.providers.page.openCodeGo.authCookie"),"auth=..."),s==="ollama-cloud"&&g("cookie",n("settings.providers.page.openCodeGo.authCookie"),"session=..."),s==="cursor"&&g("accessToken",n("settings.providers.page.auth.apiKeyLabel"),n("settings.providers.page.auth.apiKeyPlaceholder")),s==="cursor"&&g("refreshToken",n("settings.providers.page.auth.apiKeyLabel"),n("settings.providers.page.auth.apiKeyPlaceholder")),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(J,{size:"xs",disabled:u,onClick:()=>m(x,"PUT",i),children:a?.configured?n("settings.providers.page.openCodeGo.replace"):n("settings.providers.page.openCodeGo.save")}),a?.configured&&t.jsx(J,{variant:"outline",size:"xs",disabled:u,onClick:()=>m(`${x}/validate`,"POST"),children:n("settings.providers.page.openCodeGo.validate")}),s==="cursor"&&t.jsx(J,{variant:"outline",size:"xs",disabled:u,onClick:()=>m(`${x}/import`,"POST"),children:n("settings.providers.page.actions.connect")}),a?.configured&&t.jsx(J,{variant:"destructive",size:"xs",disabled:u,onClick:()=>m(x,"DELETE"),children:n("settings.providers.page.openCodeGo.delete")})]})]})]})},Kx=s=>new Intl.NumberFormat(Ai(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(s),fl=s=>{if(typeof s!="number"||Number.isNaN(s))return null;if(s===0)return"0";const e=Kx(s);return e.endsWith(".0")?e.slice(0,-2):e},Ba="__add_provider__",Xn=s=>typeof s=="object"&&s!==null,xl=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()},Ux=s=>{if(!Xn(s))return{};const e={};for(const[n,a]of Object.entries(s))Array.isArray(a)&&(e[n]=a.filter(r=>Xn(r)));return e},Bx=s=>{if(typeof s=="string")return{id:s};if(!Xn(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}},$x=s=>{let e=[];Array.isArray(s)?e=s:Xn(s)&&(Array.isArray(s.all)?e=s.all:Array.isArray(s.providers)&&(e=s.providers));const n=e.map(r=>Bx(r)).filter(r=>!!r),a=new Set;return n.filter(r=>a.has(r.id)?!1:(a.add(r.id),!0))},Vx=()=>{const{t:s}=st(),e=ot(q=>q.providers),n=ot(q=>q.selectedProviderId),a=ot(q=>q.setSelectedProvider),r=ot(q=>q.getModelMetadata),i=Ie(q=>q.hiddenModels),l=Ie(q=>q.toggleHiddenModel),u=Ie(q=>q.hideAllModels),c=Ie(q=>q.showAllModels),[x,m]=o.useState({}),[g,d]=o.useState(!1),[b,h]=o.useState({}),[f,y]=o.useState(null),[P,I]=o.useState(""),[C,L]=o.useState(null),[k,v]=o.useState({}),[w,E]=o.useState({}),[K,U]=o.useState([]),[M,S]=o.useState(!1),[A,z]=o.useState(null),[T,Z]=o.useState(""),[G,te]=o.useState(""),[Y,N]=o.useState(!1),[W,B]=o.useState({}),[F,O]=o.useState(!1),Q=n===Ba;o.useEffect(()=>{!n&&e.length>0&&a(e[0].id)},[e,n,a]),o.useEffect(()=>{if(!Q)return;let q=!0;return(async()=>{d(!0);try{const ee=await vs.getSdkClient().provider.auth();if(ee.error)throw new Error(`provider.auth failed: ${String(ee.error)}`);if(!q)return;m(Ux(ee.data))}catch(ee){if(!q)return;console.error("Failed to load provider auth methods:",ee),_.error(s("settings.providers.page.toast.authMethodsLoadFailed"))}finally{q&&d(!1)}})(),()=>{q=!1}},[Q,s]),o.useEffect(()=>{if(!zx(Q))return;let q=!0;return(async()=>{S(!0),z(null);try{const ee=await vs.getSdkClient().provider.list();if(ee.error)throw new Error(`provider.list failed: ${String(ee.error)}`);if(!q)return;U($x(ee.data))}catch(ee){if(!q)return;console.error("Failed to load available providers:",ee),z(s("settings.providers.page.state.unableToLoadProviderList"))}finally{q&&S(!1)}})(),()=>{q=!1}},[Q,s]);const H=o.useMemo(()=>new Set(e.map(q=>q.id)),[e]),ie=o.useMemo(()=>K.filter(q=>!H.has(q.id)).sort((q,$)=>{const ee=(q.name||q.id).toLowerCase(),de=($.name||$.id).toLowerCase();return ee.localeCompare(de)}),[K,H]);o.useEffect(()=>{n===Ba&&T&&!ie.some(q=>q.id===T)&&Z("")},[n,T,ie]),o.useEffect(()=>{if(n===Ba){O(!0);return}O(!1)},[n,s]),o.useEffect(()=>{if(!n||n===Ba)return;let q=!1;return(async()=>{try{const ee=await dt(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),de=await ee.json().catch(()=>null);if(!ee.ok)throw new Error(de?.error||s("settings.providers.page.toast.providerSourcesLoadFailed"));const De=de?.sources??de?.data?.sources;!q&&De&&B(ke=>({...ke,[n]:De}))}catch(ee){q||console.error("Failed to load provider sources:",ee)}})(),()=>{q=!0}},[n,s]);const oe=e.find(q=>q.id===n),se=n?W[n]:void 0,xe=async q=>{const $=b[q]?.trim()??"";if(!$){_.error(s("settings.providers.page.toast.apiKeyRequired"));return}const ee=`api:${q}`;y(ee);try{if((await vs.getSdkClient().auth.set({providerID:q,auth:{type:"api",key:$}})).error)throw new Error(s("settings.providers.page.toast.apiKeySaveFailed"));_.success(s("settings.providers.page.toast.apiKeySaved")),h(De=>({...De,[q]:""})),await Gn({scopes:["providers"],mode:"active"}),a(q)}catch(de){console.error("Failed to save API key:",de),_.error(s("settings.providers.page.toast.apiKeySaveFailed"))}finally{y(null)}},ae=async(q,$)=>{const ee=`oauth:${q}:${$}`;y(ee);try{const de=await vs.getSdkClient().provider.oauth.authorize({providerID:q,method:$});if(de.error)throw new Error(s("settings.providers.page.toast.oauthStartFailed"));const De=Xn(de.data)?de.data:{},ke=De.data,Pe=Xn(ke)?ke:De,Me=typeof Pe.url=="string"&&Pe.url||typeof Pe.verification_uri_complete=="string"&&Pe.verification_uri_complete||typeof Pe.verification_uri=="string"&&Pe.verification_uri||void 0,Te=typeof Pe.instructions=="string"&&Pe.instructions||typeof Pe.message=="string"&&Pe.message||void 0,Ve=typeof Pe.user_code=="string"&&Pe.user_code||typeof Pe.code=="string"&&Pe.code||typeof Pe.userCode=="string"&&Pe.userCode||void 0;if(!Me&&!Te&&!Ve)throw new Error(s("settings.providers.page.toast.oauthDetailsMissing"));const Ue=`${q}:${$}`;E(Oe=>({...Oe,[Ue]:{url:Me,instructions:Te,userCode:Ve}})),Me&&on(Me),L({providerId:q,methodIndex:$}),_.message(s("settings.providers.page.toast.completeOAuthInBrowser"))}catch(de){console.error("Failed to start OAuth flow:",de),_.error(s("settings.providers.page.toast.oauthStartFailed"))}finally{y(null)}},fe=async(q,$)=>{const ee=`${q}:${$}`,de=k[ee]?.trim(),De=`oauth-complete:${q}:${$}`;y(De);try{const ke={method:$};if(de&&(ke.code=de),(await vs.getSdkClient().provider.oauth.callback({providerID:q,method:ke.method,code:ke.code})).error)throw new Error(s("settings.providers.page.toast.oauthCompleteFailed"));_.success(s("settings.providers.page.toast.oauthCompleted")),v(Me=>({...Me,[ee]:""})),L(null),await Gn({scopes:["providers"],mode:"active"}),a(q)}catch(ke){console.error("Failed to complete OAuth flow:",ke),_.error(s("settings.providers.page.toast.oauthCompleteFailed"))}finally{y(null)}},Ce=async q=>{const $=await Dn(q);if($.ok){_.success(s("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",$.error),_.error(s("settings.providers.page.toast.oauthLinkCopyFailed"))},ge=async q=>{const $=await Dn(q);if($.ok){_.success(s("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",$.error),_.error(s("settings.providers.page.toast.deviceCodeCopyFailed"))},ve=async q=>{const $=`disconnect:${q}`;y($);try{const ee=await dt(`/api/provider/${encodeURIComponent(q)}/auth?scope=all`,{method:"DELETE",headers:{Accept:"application/json"}}),de=await ee.json().catch(()=>null);if(!ee.ok)throw new Error(de?.error||s("settings.providers.page.toast.providerDisconnectFailed"));_.success(s("settings.providers.page.toast.providerDisconnected")),await Gn({scopes:["providers"],mode:"active"})}catch(ee){console.error("Failed to disconnect provider:",ee),_.error(s("settings.providers.page.toast.providerDisconnectFailed"))}finally{y(null)}};if(!Q&&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(D,{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(Q)return t.jsx(Ht,{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")}),M?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.state.loading")}):A?t.jsx("p",{className:"typography-meta text-muted-foreground",children:A}):ie.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.connect.allProvidersConnected")}):t.jsxs(gs,{open:Y,onOpenChange:q=>{N(q),q||te("")},children:[t.jsx(ms,{asChild:!0,children:t.jsxs("button",{type:"button",className:ce("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(Jn,{providerId:T,className:"h-3.5 w-3.5 flex-shrink-0"}):null,t.jsx("span",{className:ce("truncate typography-ui-label font-normal",T?"text-foreground":"text-muted-foreground"),children:T?ie.find(q=>q.id===T)?.name||T:s("settings.providers.page.connect.selectProviderPlaceholder")})]}),t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),t.jsxs(ps,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:q=>q.preventDefault(),children:[t.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:q=>q.stopPropagation(),children:[t.jsx(D,{name:"search",className:"h-4 w-4 text-muted-foreground"}),t.jsx("input",{type:"text",value:G,onChange:q=>te(q.target.value),onKeyDown:q=>q.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(Ht,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const q=ie.filter($=>{const ee=G.toLowerCase();return($.name||$.id).toLowerCase().includes(ee)||$.id.toLowerCase().includes(ee)});return q.length===0?t.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:s("settings.providers.page.connect.noProvidersFound")}):q.map($=>t.jsxs(Ns,{onSelect:()=>{Z($.id),N(!1),te("")},className:"flex items-center justify-between",children:[t.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(Jn,{providerId:$.id,className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:$.name||$.id})]}),T===$.id&&t.jsx(D,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},$.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")})}),g?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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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(Xe,{type:"password",value:b[T]??"",onChange:q=>h($=>({...$,[T]:q.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:f===`api:${T}`,children:f===`api:${T}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),(()=>{const $=(x[T]??[]).filter(ee=>xl(ee)==="oauth");return $.length===0?null:t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:$.map((ee,de)=>{const De=ee.label||ee.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String(de+1)}),ke=`${T}:${de}`,Pe=C?.providerId===T&&C?.methodIndex===de;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:De}),(ee.description||ee.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(ee.description||ee.help)})]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ae(T,de),disabled:f===`oauth:${T}:${de}`,children:s("settings.providers.page.actions.connect")})]}),w[ke]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:w[ke]?.instructions}),w[ke]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:w[ke]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ge(w[ke]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),w[ke]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:w[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:()=>on(w[ke]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ce(w[ke]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),Pe&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:k[ke]??"",onChange:Me=>v(Te=>({...Te,[ke]:Me.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal",onClick:()=>fe(T,de),disabled:f===`oauth-complete:${T}:${de}`,children:f===`oauth-complete:${T}:${de}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${T}-${De}`)})})})()]})]})]})});if(!oe)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(D,{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 Ne=Array.isArray(oe.models)?oe.models:[],re=(x[oe.id]??[]).filter(q=>xl(q)==="oauth"),ye=Ne.filter(q=>{const $=typeof q?.name=="string"?q.name:"",ee=typeof q?.id=="string"?q.id:"",de=P.trim().toLowerCase();return de?$.toLowerCase().includes(de)||ee.toLowerCase().includes(de):!0});return t.jsx(Ht,{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(Jn,{providerId:oe.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:oe.name||oe.id}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t.jsx("span",{className:"font-mono",children:oe.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:()=>O(q=>!q),children:s(F?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:F?g?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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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(Xe,{type:"password",value:b[oe.id]??"",onChange:q=>h($=>({...$,[oe.id]:q.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(oe.id),disabled:f===`api:${oe.id}`,children:f===`api:${oe.id}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),re.length>0&&t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:re.map((q,$)=>{const ee=q.label||q.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String($+1)}),de=`${oe.id}:${$}`,De=C?.providerId===oe.id&&C?.methodIndex===$;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:ee}),(q.description||q.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(q.description||q.help)})]}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ae(oe.id,$),disabled:f===`oauth:${oe.id}:${$}`,children:s("settings.providers.page.actions.connect")})]}),w[de]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:w[de]?.instructions}),w[de]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:w[de]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ge(w[de]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),w[de]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:w[de]?.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:()=>on(w[de]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ce(w[de]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),De&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:k[de]??"",onChange:ke=>v(Pe=>({...Pe,[de]:ke.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(J,{size:"xs",className:"!font-normal",onClick:()=>fe(oe.id,$),disabled:f===`oauth-complete:${oe.id}:${$}`,children:f===`oauth-complete:${oe.id}:${$}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${oe.id}-${ee}`)})})]}):t.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[t.jsx(D,{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")})]})})]}),(oe.id==="opencode"||oe.id==="opencode-go")&&t.jsx(_r,{providerId:"opencode-go",providerName:"OpenCode Go"}),(oe.id==="ollama"||oe.id==="ollama-cloud")&&t.jsx(_r,{providerId:"ollama-cloud",providerName:"Ollama Cloud"}),oe.id==="cursor"&&t.jsx(_r,{providerId:"cursor",providerName:"Cursor"}),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:se&&(se.auth.exists||se.user.exists||se.project.exists||se.custom?.exists)?t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[s("settings.providers.page.connectionDetails.configuredIn")," ",[se.auth.exists?s("settings.providers.page.connectionDetails.source.authCredentials"):null,se.user.exists?s("settings.providers.page.connectionDetails.source.userConfig"):null,se.project.exists?s("settings.providers.page.connectionDetails.source.projectConfig"):null,se.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:()=>ve(oe.id),disabled:f===`disconnect:${oe.id}`,children:f===`disconnect:${oe.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"),Ne.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",Ne.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=Ne.map($=>typeof $?.id=="string"?$.id:"").filter($=>$.length>0);u(oe.id,q)},children:s("settings.providers.page.actions.hideAll")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>c(oe.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(D,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),t.jsx(Xe,{value:P,onChange:q=>I(q.target.value),placeholder:s("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ye.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:ye.map(q=>{const $=typeof q?.id=="string"?q.id:"",ee=typeof q?.name=="string"?q.name:$,de=$?r(oe.id,$):void 0,De=i.some(Te=>Te.providerID===oe.id&&Te.modelID===$),ke=fl(de?.limit?.context),Pe=fl(de?.limit?.output),Me=[];return de?.tool_call&&Me.push({key:"tools",icon:"tools",label:s("settings.providers.page.models.capability.toolCalling")}),de?.reasoning&&Me.push({key:"reasoning",icon:"brain-ai-3",label:s("settings.providers.page.models.capability.reasoning")}),de?.attachment&&Me.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:ce("flex items-center gap-3",De&&"opacity-50"),children:[t.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:ee}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(ke||Pe)&&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&&Pe?" · ":"",Pe?`${Pe} ${s("settings.providers.page.models.tokenBadge.output")}`:""]}),Me.length>0&&t.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Me.map(({key:Te,icon:Ve,label:Ue})=>t.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Ue,"aria-label":Ue,children:t.jsx(D,{name:Ve,className:"h-3 w-3"})},Te))}),t.jsx("button",{type:"button",onClick:()=>l(oe.id,$),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(De?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":s(De?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:De?t.jsx(D,{name:"eye-off",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},$)})})]})]})]})})},wn=[{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"},{id:"opencode-go",name:"OpenCode Go"}];function yl(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 _x=[{id:"gemini-auth",label:"Gemini",matcher:s=>s.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:s=>s.startsWith("antigravity/"),order:2}],Kc={google:_x};function Uc(s,e){const n=Kc[e]??[];for(const a of n)if(a.matcher(s))return a;return null}function Hx(s){return Kc[s]??[]}function Wx(s){return[...s].sort((e,n)=>e.order-n.order)}function sw(s,e){const n=new Map;for(const a of Object.keys(s)){const i=Uc(a,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(a)}return n}function Gx(s,e,n){const a=new Map;for(const r of s){const i=e(r),u=Uc(i,n)?.id??null;a.has(u)||a.set(u,[]),a.get(u).push(r)}return a}function qx(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 Ri=6e4,bl=s=>{const e=wn.map(d=>d.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))):Ri,r=s?.usageDisplayMode==="remaining"?"remaining":"usage",i=typeof s?.usageShowPredValues=="boolean"?s.usageShowPredValues:!1,l=Array.isArray(s?.usageDropdownProviders)?s?.usageDropdownProviders:null,u=l?l.filter(d=>typeof d=="string"&&e.includes(d)):e,c={},x=s?.usageSelectedModels;if(x&&typeof x=="object")for(const[d,b]of Object.entries(x))Array.isArray(b)&&(c[d]=b.filter(h=>typeof h=="string"));const m={},g=s?.usageExpandedFamilies;if(g&&typeof g=="object")for(const[d,b]of Object.entries(g))Array.isArray(b)&&(m[d]=b.filter(h=>typeof h=="string"));return{autoRefresh:n,refreshIntervalMs:a,displayMode:r,showPredValues:i,dropdownProviderIds:u,selectedModels:c,expandedFamilies:m}},Jx=async()=>{const s=qs()?.settings;if(s)try{const n=(await s.load())?.settings;return bl(n??null)}catch{}if(!rs()){const e=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return bl(n)}}return{autoRefresh:!1,refreshIntervalMs:Ri,displayMode:"usage",showPredValues:!1,dropdownProviderIds:wn.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ut=Nn()(wa((s,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Ri,displayMode:"usage",showPredValues:!1,dropdownProviderIds:wn.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Jx();s(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{s({isLoading:!0,error:null});const n=wn.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 dt(`/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(l=>{const u=l.results.filter(c=>c.providerId!==n);return u.push(i),{results:u,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(l=>{const u=l.results.filter(c=>c.providerId!==n);return u.push(i),{results:u,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]??[],u=i.includes(a)?i.filter(c=>c!==a):[...i,a];return{selectedModels:{...r.selectedModels,[n]:u}}})},setExpandedFamilies:(n,a)=>{s(r=>({expandedFamilies:{...r.expandedFamilies,[n]:a}})),wt({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,a)=>{s(r=>{const i=r.expandedFamilies[n]??[],u=i.includes(a)?i.filter(c=>c!==a):[...i,a];return{expandedFamilies:{...r.expandedFamilies,[n]:u}}}),wt({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,a)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=qx(n,a);i.length!==0&&(s(l=>({selectedModels:{...l.selectedModels,[n]:i}})),wt({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Qx=()=>{const s=Ze.c(5),e=Ut(Yx),n=Ut(Xx),a=Ut(Zx);let r,i;s[0]!==e||s[1]!==a||s[2]!==n?(r=()=>{if(!e)return;const l=window.setInterval(()=>{a()},n);return()=>window.clearInterval(l)},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]),o.useEffect(r,i)};function Yx(s){return s.autoRefresh}function Xx(s){return s.refreshIntervalMs}function Zx(s){return s.fetchAllQuotas}const ey=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)},ty=s=>{const e=Ze.c(122),{onItemSelect:n}=s,{t:a}=st(),r=Ut(sy),i=Ut(ny),l=Ut(ay),u=Ut(ry),c=Ut(iy),x=Ut(oy),m=Ut(ly),g=Ut(cy),d=Ut(dy),b=Ut(uy),h=Ut(my),f=Ut(py),y=Ut(gy),P=Ut(hy);let I,C;e[0]!==P?(I=()=>{P()},C=[P],e[0]=P,e[1]=I,e[2]=C):(I=e[1],C=e[2]),o.useEffect(I,C);const L=fy;let k;e[3]!==d?(k=pe=>{d(pe),L({usageAutoRefresh:pe})},e[3]=d,e[4]=k):k=e[4];const v=k;let w;e[5]!==b?(w=pe=>{const Le=Number(pe);Number.isFinite(Le)&&(b(Le),L({usageRefreshIntervalMs:Le}))},e[5]=b,e[6]=w):w=e[6];const E=w;let K;e[7]!==h?(K=pe=>{pe!=="usage"&&pe!=="remaining"||(h(pe),L({usageDisplayMode:pe}))},e[7]=h,e[8]=K):K=e[8];const U=K;let M;e[9]!==y?(M=pe=>{y(pe),L({usageShowPredValues:pe})},e[9]=y,e[10]=M):M=e[10];const S=M;let A;e[11]===Symbol.for("react.memo_cache_sentinel")?(A=ce("flex h-full flex-col","bg-background"),e[11]=A):A=e[11];let z;e[12]!==a?(z=a("settings.usage.sidebar.title"),e[12]=a,e[13]=z):z=e[13];let T;e[14]!==z?(T=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:z}),e[14]=z,e[15]=T):T=e[15];let Z;e[16]!==a?(Z=a("settings.usage.sidebar.total",{count:wn.length}),e[16]=a,e[17]=Z):Z=e[17];let G;e[18]!==Z?(G=t.jsx("span",{className:"typography-meta text-muted-foreground",children:Z}),e[18]=Z,e[19]=G):G=e[19];let te;e[20]!==a?(te=a("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[20]=a,e[21]=te):te=e[21];let Y;e[22]!==v||e[23]!==te||e[24]!==x?(Y=t.jsx(Ct,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:t.jsx(xt,{checked:x,onChange:v,ariaLabel:te})})}),e[22]=v,e[23]=te,e[24]=x,e[25]=Y):Y=e[25];let N;e[26]!==a?(N=a("settings.usage.sidebar.tooltip.autoRefresh"),e[26]=a,e[27]=N):N=e[27];let W;e[28]!==N?(W=t.jsx(It,{side:"bottom",children:N}),e[28]=N,e[29]=W):W=e[29];let B;e[30]!==Y||e[31]!==W?(B=t.jsxs(St,{children:[Y,W]}),e[30]=Y,e[31]=W,e[32]=B):B=e[32];const F=String(m),O=!x;let Q;e[33]!==a?(Q=a("settings.usage.sidebar.field.intervalPlaceholder"),e[33]=a,e[34]=Q):Q=e[34];let H;e[35]!==Q?(H=t.jsx(At,{className:"w-fit",children:t.jsx(Lt,{placeholder:Q})}),e[35]=Q,e[36]=H):H=e[36];let ie;e[37]===Symbol.for("react.memo_cache_sentinel")?(ie=t.jsxs(Dt,{children:[t.jsx(ut,{value:"30000",children:"30s"}),t.jsx(ut,{value:"60000",children:"1m"}),t.jsx(ut,{value:"300000",children:"5m"})]}),e[37]=ie):ie=e[37];let oe;e[38]!==E||e[39]!==F||e[40]!==O||e[41]!==H?(oe=t.jsxs(Pt,{value:F,onValueChange:E,disabled:O,children:[H,ie]}),e[38]=E,e[39]=F,e[40]=O,e[41]=H,e[42]=oe):oe=e[42];let se;e[43]!==u?(se=()=>u(),e[43]=u,e[44]=se):se=e[44];let xe;e[45]!==a?(xe=a("settings.usage.sidebar.actions.refreshAria"),e[45]=a,e[46]=xe):xe=e[46];let ae;e[47]!==a?(ae=a("settings.usage.sidebar.actions.refreshTitle"),e[47]=a,e[48]=ae):ae=e[48];const fe=c&&"animate-spin";let Ce;e[49]!==fe?(Ce=ce("h-3.5 w-3.5",fe),e[49]=fe,e[50]=Ce):Ce=e[50];let ge;e[51]!==Ce?(ge=t.jsx(D,{name:"refresh",className:Ce}),e[51]=Ce,e[52]=ge):ge=e[52];let ve;e[53]!==c||e[54]!==se||e[55]!==xe||e[56]!==ae||e[57]!==ge?(ve=t.jsx(J,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:se,"aria-label":xe,title:ae,disabled:c,children:ge}),e[53]=c,e[54]=se,e[55]=xe,e[56]=ae,e[57]=ge,e[58]=ve):ve=e[58];let Ne;e[59]!==B||e[60]!==oe||e[61]!==ve?(Ne=t.jsxs("div",{className:"flex items-center gap-2",children:[B,oe,ve]}),e[59]=B,e[60]=oe,e[61]=ve,e[62]=Ne):Ne=e[62];let ne;e[63]!==G||e[64]!==Ne?(ne=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[G,Ne]}),e[63]=G,e[64]=Ne,e[65]=ne):ne=e[65];let re;e[66]!==a?(re=a("settings.usage.sidebar.field.display"),e[66]=a,e[67]=re):re=e[67];let ye;e[68]!==re?(ye=t.jsx("span",{className:"typography-micro text-muted-foreground",children:re}),e[68]=re,e[69]=ye):ye=e[69];let q;e[70]!==a?(q=a("settings.usage.sidebar.field.displayModePlaceholder"),e[70]=a,e[71]=q):q=e[71];let $;e[72]!==q?($=t.jsx(At,{className:"w-fit",children:t.jsx(Lt,{placeholder:q})}),e[72]=q,e[73]=$):$=e[73];let ee;e[74]!==a?(ee=a("settings.usage.sidebar.field.displayModeUsage"),e[74]=a,e[75]=ee):ee=e[75];let de;e[76]!==ee?(de=t.jsx(ut,{value:"usage",children:ee}),e[76]=ee,e[77]=de):de=e[77];let De;e[78]!==a?(De=a("settings.usage.sidebar.field.displayModeRemaining"),e[78]=a,e[79]=De):De=e[79];let ke;e[80]!==De?(ke=t.jsx(ut,{value:"remaining",children:De}),e[80]=De,e[81]=ke):ke=e[81];let Pe;e[82]!==de||e[83]!==ke?(Pe=t.jsxs(Dt,{children:[de,ke]}),e[82]=de,e[83]=ke,e[84]=Pe):Pe=e[84];let Me;e[85]!==U||e[86]!==$||e[87]!==Pe||e[88]!==g?(Me=t.jsxs(Pt,{value:g,onValueChange:U,children:[$,Pe]}),e[85]=U,e[86]=$,e[87]=Pe,e[88]=g,e[89]=Me):Me=e[89];let Te;e[90]!==ye||e[91]!==Me?(Te=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ye,Me]}),e[90]=ye,e[91]=Me,e[92]=Te):Te=e[92];let Ve;e[93]!==a?(Ve=a("settings.usage.sidebar.field.showPredictions"),e[93]=a,e[94]=Ve):Ve=e[94];let Ue;e[95]!==Ve?(Ue=t.jsx("span",{className:"typography-micro text-muted-foreground",children:Ve}),e[95]=Ve,e[96]=Ue):Ue=e[96];let Oe;e[97]!==a?(Oe=a("settings.usage.sidebar.field.showPredictions"),e[97]=a,e[98]=Oe):Oe=e[98];let _e;e[99]!==S||e[100]!==f||e[101]!==Oe?(_e=t.jsx(xt,{checked:f,onChange:S,ariaLabel:Oe}),e[99]=S,e[100]=f,e[101]=Oe,e[102]=_e):_e=e[102];let Ke;e[103]!==Ue||e[104]!==_e?(Ke=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[Ue,_e]}),e[103]=Ue,e[104]=_e,e[105]=Ke):Ke=e[105];let Qe;e[106]!==ne||e[107]!==Te||e[108]!==Ke||e[109]!==T?(Qe=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,ne,Te,Ke]}),e[106]=ne,e[107]=Te,e[108]=Ke,e[109]=T,e[110]=Qe):Qe=e[110];let Fe;e[111]!==n||e[112]!==r||e[113]!==i||e[114]!==l||e[115]!==a?(Fe=wn.map(pe=>{const Le=r.find(Ae=>Ae.providerId===pe.id),we=ey(Le?.usage),He=pc(we),X=pe.id===i,j=Le?.configured??!1,be=j?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:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",X?"bg-interactive-selection":"hover:bg-interactive-hover"),children:t.jsxs("button",{type:"button",onClick:()=>{l(pe.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:be}),t.jsx(Jn,{providerId:pe.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:pe.name}),!j&&t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:a("settings.usage.sidebar.status.notSet")})]})},pe.id)}),e[111]=n,e[112]=r,e[113]=i,e[114]=l,e[115]=a,e[116]=Fe):Fe=e[116];let V;e[117]!==Fe?(V=t.jsx(Ht,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:Fe}),e[117]=Fe,e[118]=V):V=e[118];let le;return e[119]!==Qe||e[120]!==V?(le=t.jsxs("div",{className:A,children:[Qe,V]}),e[119]=Qe,e[120]=V,e[121]=le):le=e[121],le};function sy(s){return s.results}function ny(s){return s.selectedProviderId}function ay(s){return s.setSelectedProvider}function ry(s){return s.fetchAllQuotas}function iy(s){return s.isLoading}function oy(s){return s.autoRefresh}function ly(s){return s.refreshIntervalMs}function cy(s){return s.displayMode}function dy(s){return s.setAutoRefresh}function uy(s){return s.setRefreshInterval}function my(s){return s.setDisplayMode}function py(s){return s.showPredValues}function gy(s){return s.setShowPredValues}function hy(s){return s.loadSettings}async function fy(s){try{await wt(s)}catch(e){console.warn("Failed to save usage settings:",e)}}const xy=s=>{const e=Ze.c(20),{percent:n,tonePercent:a,className:r,expectedMarkerPercent:i}=s;let l;e[0]!==n?(l=Gu(n)??0,e[0]=n,e[1]=l):l=e[1];const u=l,c=a??n;let x;e[2]!==c?(x=pc(c),e[2]=c,e[3]=x):x=e[3];const m=x,g=i!=null?Math.max(0,Math.min(100,i)):null;let d;e[4]!==m?(d=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=d):d=e[5];const b=d;let h;e[6]!==r?(h=ce("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=h):h=e[7];const f=`${u}%`;let y;e[8]!==b||e[9]!==f?(y={...b,width:f},e[8]=b,e[9]=f,e[10]=y):y=e[10];let P;e[11]!==u||e[12]!==y?(P=t.jsx("div",{className:"h-full transition-all duration-300",style:y,role:"progressbar","aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100}),e[11]=u,e[12]=y,e[13]=P):P=e[13];let I;e[14]!==g?(I=g!=null&&g>0&&g<100&&t.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${g}%`},title:`Expected usage if spread evenly: ${Math.round(g)}% of quota`,"aria-hidden":"true"}),e[14]=g,e[15]=I):I=e[15];let C;return e[16]!==h||e[17]!==P||e[18]!==I?(C=t.jsxs("div",{className:h,children:[P,I]}),e[16]=h,e[17]=P,e[18]=I,e[19]=C):C=e[19],C},yy=s=>{const e=Ze.c(67),{paceInfo:n,className:a,compact:r}=s,i=r===void 0?!1:r,{t:l}=st();let u;e[0]!==n.status?(u=qu(n.status),e[0]=n.status,e[1]=u):u=e[1];const c=u;let x;e:{switch(n.status){case"on-track":{let w;e[2]!==l?(w=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=w):w=e[3],x=w;break e}case"slightly-fast":{let w;e[4]!==l?(w=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=w):w=e[5],x=w;break e}case"too-fast":{let w;e[6]!==l?(w=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=w):w=e[7],x=w;break e}case"exhausted":{let w;e[8]!==l?(w=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=w):w=e[9],x=w;break e}}x=void 0}const m=x;let g;e[10]!==n.predictText||e[11]!==l?(g=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=g):g=e[12];const d=g;if(i){let w;e[13]!==a?(w=ce("flex items-center gap-1.5",a),e[13]=a,e[14]=w):w=e[14];let E;e[15]!==c?(E={backgroundColor:c},e[15]=c,e[16]=E):E=e[16];let K;e[17]!==m||e[18]!==E?(K=t.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:E,title:m}),e[17]=m,e[18]=E,e[19]=K):K=e[19];let U;e[20]!==c?(U={color:c},e[20]=c,e[21]=U):U=e[21];const M=n.isExhausted?void 0:d;let S;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(S=n.isExhausted?t.jsx(t.Fragment,{children:l("settings.usage.pace.wait",{duration:Qi(n.remainingSeconds)})}):t.jsx(t.Fragment,{children:l("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=l,e[26]=S):S=e[26];let A;e[27]!==S||e[28]!==U||e[29]!==M?(A=t.jsx("span",{className:"typography-micro tabular-nums",style:U,title:M,children:S}),e[27]=S,e[28]=U,e[29]=M,e[30]=A):A=e[30];let z;return e[31]!==A||e[32]!==w||e[33]!==K?(z=t.jsxs("div",{className:w,children:[K,A]}),e[31]=A,e[32]=w,e[33]=K,e[34]=z):z=e[34],z}let b;e[35]!==a?(b=ce("flex items-center justify-between gap-2",a),e[35]=a,e[36]=b):b=e[36];let h;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(h=!n.isExhausted&&t.jsx("span",{className:"typography-micro text-muted-foreground",children:l("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=l,e[40]=h):h=e[40];let f;e[41]!==h?(f=t.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[41]=h,e[42]=f):f=e[42];let y;e[43]!==c?(y={color:c},e[43]=c,e[44]=y):y=e[44];let P;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==d||e[49]!==m||e[50]!==l?(P=n.isExhausted?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"font-medium",children:m}),t.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.waitSeparator")}),t.jsx("span",{className:"font-medium",children:Qi(n.remainingSeconds)})]}):t.jsxs("span",{title:d,children:[t.jsx("span",{className:"text-muted-foreground",children:l("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]=d,e[49]=m,e[50]=l,e[51]=P):P=e[51];let I;e[52]!==y||e[53]!==P?(I=t.jsx("span",{className:"typography-micro tabular-nums",style:y,children:P}),e[52]=y,e[53]=P,e[54]=I):I=e[54];let C;e[55]!==c?(C={backgroundColor:c},e[55]=c,e[56]=C):C=e[56];let L;e[57]!==m||e[58]!==C?(L=t.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:C,title:m}),e[57]=m,e[58]=C,e[59]=L):L=e[59];let k;e[60]!==I||e[61]!==L?(k=t.jsxs("div",{className:"flex items-center gap-1.5",children:[I,L]}),e[60]=I,e[61]=L,e[62]=k):k=e[62];let v;return e[63]!==k||e[64]!==b||e[65]!==f?(v=t.jsxs("div",{className:b,children:[f,k]}),e[63]=k,e[64]=b,e[65]=f,e[66]=v):v=e[66],v},Hr=s=>{const e=Ze.c(54),{title:n,window:a,subtitle:r,showToggle:i,toggleEnabled:l,onToggle:u}=s,c=i===void 0?!1:i,x=l===void 0?!1:l,m=Ut(by),g=Ut(vy),d=Ie(jy),b=m==="remaining"?a.remainingPercent:a.usedPercent,h=m==="remaining"?"remaining":"used";let f;e[0]!==b||e[1]!==a.valueLabel?(f=Ju(a.valueLabel,b),e[0]=b,e[1]=a.valueLabel,e[2]=f):f=e[2];const y=f,P=a.resetAfterFormatted??a.resetAtFormatted;let I;e[3]!==P||e[4]!==d||e[5]!==a.resetAt?(I=Qu(a.resetAt,P,d),e[3]=P,e[4]=d,e[5]=a.resetAt,e[6]=I):I=e[6];const C=I;let L;e[7]!==n?(L=Yu(n),e[7]=n,e[8]=L):L=e[8];const k=L;let v;e[9]!==n||e[10]!==a.resetAt||e[11]!==a.usedPercent||e[12]!==a.windowSeconds?(v=Xu(a.usedPercent,a.resetAt,a.windowSeconds,n),e[9]=n,e[10]=a.resetAt,e[11]=a.usedPercent,e[12]=a.windowSeconds,e[13]=v):v=e[13];const w=v;let E;e:{if(!w||w.dailyAllocationPercent===null){E=null;break e}const H=Zu(w.elapsedRatio);E=m==="remaining"?100-H:H}const K=E;let U;e[14]!==u||e[15]!==c||e[16]!==x?(U=c&&t.jsx(xt,{checked:x,onChange:H=>u?.(H),ariaLabel:"Show in dropdown"}),e[14]=u,e[15]=c,e[16]=x,e[17]=U):U=e[17];let M;e[18]!==k?(M=t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k}),e[18]=k,e[19]=M):M=e[19];let S;e[20]!==r?(S=r&&t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[20]=r,e[21]=S):S=e[21];let A;e[22]!==M||e[23]!==S?(A=t.jsxs("div",{className:"min-w-0 flex flex-col",children:[M,S]}),e[22]=M,e[23]=S,e[24]=A):A=e[24];let z;e[25]!==A||e[26]!==U?(z=t.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[U,A]}),e[25]=A,e[26]=U,e[27]=z):z=e[27];const T=y==="-"?"":y;let Z;e[28]!==T?(Z=t.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:T}),e[28]=T,e[29]=Z):Z=e[29];let G;e[30]!==z||e[31]!==Z?(G=t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[z,Z]}),e[30]=z,e[31]=Z,e[32]=G):G=e[32];let te;e[33]!==b||e[34]!==K||e[35]!==a.usedPercent?(te=t.jsx(xy,{percent:b,tonePercent:a.usedPercent,expectedMarkerPercent:K,className:"h-1.5"}),e[33]=b,e[34]=K,e[35]=a.usedPercent,e[36]=te):te=e[36];const Y=C?`Resets ${C}`:"";let N;e[37]!==Y?(N=t.jsx("span",{className:"typography-micro text-muted-foreground",children:Y}),e[37]=Y,e[38]=N):N=e[38];let W;e[39]!==h?(W=t.jsx("span",{className:"typography-micro text-muted-foreground",children:h}),e[39]=h,e[40]=W):W=e[40];let B;e[41]!==N||e[42]!==W?(B=t.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[N,W]}),e[41]=N,e[42]=W,e[43]=B):B=e[43];let F;e[44]!==te||e[45]!==B?(F=t.jsxs("div",{className:"mt-2.5",children:[te,B]}),e[44]=te,e[45]=B,e[46]=F):F=e[46];let O;e[47]!==w||e[48]!==g?(O=w&&g&&t.jsx("div",{className:"mt-1.5",children:t.jsx(yy,{paceInfo:w})}),e[47]=w,e[48]=g,e[49]=O):O=e[49];let Q;return e[50]!==G||e[51]!==F||e[52]!==O?(Q=t.jsxs("div",{className:"py-3",children:[G,F,O]}),e[50]=G,e[51]=F,e[52]=O,e[53]=Q):Q=e[53],Q};function by(s){return s.displayMode}function vy(s){return s.showPredValues}function jy(s){return s.timeFormatPreference}const wy=(s,e)=>{if(!s)return"-";try{return gc(s,e,{fallback:"-"})}catch{return"-"}},Ny=()=>{const{t:s}=st(),e=Ie(A=>A.timeFormatPreference),n=Ut(A=>A.results),a=Ut(A=>A.selectedProviderId),r=Ut(A=>A.setSelectedProvider),i=Ut(A=>A.loadSettings),l=Ut(A=>A.fetchAllQuotas),u=Ut(A=>A.isLoading),c=Ut(A=>A.lastUpdated),x=Ut(A=>A.error),m=Ut(A=>A.dropdownProviderIds),g=Ut(A=>A.setDropdownProviderIds),d=Ut(A=>A.selectedModels),b=Ut(A=>A.toggleModelSelected),h=Ut(A=>A.applyDefaultSelections);Qx(),o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(a||n.length===0)return;const A=n.find(z=>z.configured)?.providerId;r(A??wn[0]?.id??null)},[n,a,r]);const f=n.find(A=>A.providerId===a)??null,P=wn.find(A=>A.id===a)?.name??a??s("settings.usage.sidebar.title"),I=f?.usage,C=a?m.includes(a):!1,L=o.useCallback(A=>{if(!a)return;const z=A?Array.from(new Set([...m,a])):m.filter(T=>T!==a);g(z),wt({usageDropdownProviders:z})},[m,a,g]),k=o.useMemo(()=>I?.models?Object.entries(I.models).map(([A,z])=>({name:A,windows:z})).filter(A=>Object.keys(A.windows.windows).length>0):[],[I?.models]);o.useEffect(()=>{a&&k.length>0&&h(a,k.map(A=>A.name))},[a,k,h]);const v=o.useMemo(()=>!a||k.length===0?new Map:Gx(k,A=>A.name,a),[k,a]),w=o.useMemo(()=>{if(!a)return[];const A=Hx(a);return Wx(A)},[a]),[E,K]=o.useState(()=>({})),U=o.useCallback(A=>{K(z=>({...z,[A]:!z[A]}))},[]),M=o.useCallback(A=>{if(!a)return;b(a,A);const z=d[a]??[],Z=z.includes(A)?z.filter(te=>te!==A):[...z,A],G={...d,[a]:Z};wt({usageSelectedModels:G})},[a,d,b]),S=a?d[a]??[]:[];return a?t.jsx(Ht,{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(Jn,{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:P})}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:u?t.jsx("span",{className:"animate-pulse",children:s("settings.usage.page.header.refreshing")}):s("settings.usage.page.header.lastUpdated",{time:wy(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":C,onClick:()=>L(!C),onKeyDown:A=>{(A.key===" "||A.key==="Enter")&&(A.preventDefault(),L(!C))},children:[t.jsx(xt,{checked:C,onChange:L,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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!f&&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})]}),f&&!f.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")})]}),I?.windows&&Object.keys(I.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(I.windows).map(([A,z])=>t.jsx(Hr,{title:A,window:z},A))})})}),k.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:[w.map(A=>{const z=v.get(A.id)??[];if(z.length===0)return null;const T=E[A.id]??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(En,{open:!T,onOpenChange:()=>U(A.id),children:[t.jsxs(Mn,{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:A.label}),t.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",z.length,")"]})]}),T?t.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(Tn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:z.map(Z=>{const G=Object.entries(Z.windows.windows);if(G.length===0)return null;const[te,Y]=G[0],N=S.includes(Z.name);return t.jsx(Hr,{title:te,subtitle:yl(Z.name),window:Y,showToggle:!0,toggleEnabled:N,onToggle:()=>M(Z.name)},Z.name)})})})]})},A.id)}),(()=>{const A=v.get(null)??[];if(A.length===0)return null;const z=E.other??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(En,{open:!z,onOpenChange:()=>U("other"),children:[t.jsxs(Mn,{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:["(",A.length,")"]})]}),z?t.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(Tn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:A.map(T=>{const Z=Object.entries(T.windows.windows);if(Z.length===0)return null;const[G,te]=Z[0],Y=S.includes(T.name);return t.jsx(Hr,{title:G,subtitle:yl(T.name),window:te,showToggle:!0,toggleEnabled:Y,onToggle:()=>M(T.name)},T.name)})})})]})})})()]})]}),f?.configured&&I&&Object.keys(I.windows??{}).length===0&&k.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")})})},ky="git.commit.generate",wi=Nn(s=>({selectedPromptId:ky,setSelectedPromptId:e=>{s(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),Sy=s=>{const e=Ze.c(23),{onItemSelect:n}=s,{t:a}=st(),r=wi(Cy),i=wi(Iy);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={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]=l):l=e[0];let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={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]=u):u=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=[l,u,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.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{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 g;e[4]!==a?(g=a("settings.magicPrompts.sidebar.title"),e[4]=a,e[5]=g):g=e[5];let d;e[6]!==g?(d=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:g}),e[6]=g,e[7]=d):d=e[7];let b;e[8]!==a?(b=a("settings.magicPrompts.sidebar.description"),e[8]=a,e[9]=b):b=e[9];let h;e[10]!==b?(h=t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[10]=b,e[11]=h):h=e[11];let f;e[12]!==d||e[13]!==h?(f=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[d,h]}),e[12]=d,e[13]=h,e[14]=f):f=e[14];let y;e[15]!==n||e[16]!==r||e[17]!==i||e[18]!==a?(y=t.jsx(Ht,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(I=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:a(I.groupKey)}),I.items.map(C=>{const L=r===C.id;return t.jsx("button",{type:"button",onClick:()=>{i(C.id),n?.()},className:ce("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",L?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-ui-label truncate font-normal",children:a(C.titleKey)})},C.id)})]},I.groupKey))}),e[15]=n,e[16]=r,e[17]=i,e[18]=a,e[19]=y):y=e[19];let P;return e[20]!==y||e[21]!==f?(P=t.jsxs("div",{className:"flex h-full flex-col bg-background",children:[f,y]}),e[20]=y,e[21]=f,e[22]=P):P=e[22],P};function Cy(s){return s.selectedPromptId}function Iy(s){return s.setSelectedPromptId}const vl={"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.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.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"}]}},jl=(s,e)=>Object.prototype.hasOwnProperty.call(s,e),Wr=s=>s.endsWith(".visible"),Py=()=>{const{t:s}=st(),e=o.useCallback(v=>s(v),[s]),n=wi(v=>v.selectedPromptId),[a,r]=o.useState(!0),[i,l]=o.useState({}),[u,c]=o.useState({}),[x,m]=o.useState({}),[g,d]=o.useState({}),[b,h]=o.useState(!1);o.useEffect(()=>{let v=!0;return(async()=>{r(!0);try{const E=await nm();if(!v)return;l(E)}catch(E){console.warn("Failed to load magic prompts:",E),_.error(s("settings.magicPrompts.page.toast.loadFailed"))}finally{v&&r(!1)}})(),()=>{v=!1}},[s]);const f=vl[n]??vl["git.commit.generate"],y=o.useCallback(v=>jl(i,v)?i[v]:Sr(v),[i]),P=o.useCallback(v=>u[v]??y(v),[u,y]),I=o.useCallback((v,w)=>{c(E=>E[v]===w?E:{...E,[v]:w})},[]),C=o.useCallback(async v=>{const w=P(v);if(Wr(v)&&w.trim().length===0){_.error(s("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(E=>({...E,[v]:!0}));try{const E=w===Sr(v)?await Yi(v):await em(v,w);l(E.overrides),_.success(s("settings.magicPrompts.page.toast.saved"))}catch(E){const K=E instanceof Error?E.message:String(E);_.error(s("settings.magicPrompts.page.toast.saveFailed"),{description:K})}finally{m(E=>({...E,[v]:!1}))}},[P,s]),L=o.useCallback(async v=>{d(w=>({...w,[v]:!0}));try{const w=await Yi(v);l(w.overrides),c(E=>({...E,[v]:Sr(v)})),_.success(s("settings.magicPrompts.page.toast.resetSuccess"))}catch(w){const E=w instanceof Error?w.message:String(w);_.error(s("settings.magicPrompts.page.toast.resetFailed"),{description:E})}finally{d(w=>({...w,[v]:!1}))}},[s]),k=o.useCallback(async()=>{h(!0);try{const v=await tm();l(v.overrides),c({}),_.success(s("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(v){const w=v instanceof Error?v.message:String(v);_.error(s("settings.magicPrompts.page.toast.resetAllFailed"),{description:w})}finally{h(!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(f.titleKey)}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:e(f.descriptionKey)})]})]})}),t.jsx(J,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{k()},disabled:b||Object.keys(i).length===0,children:s(b?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),f.blocks.map((v,w)=>{const E=sm(v.id),K=y(v.id),U=P(v.id),M=jl(i,v.id),S=U!==K,A=Wr(v.id)&&U.trim().length===0,z=x[v.id]===!0,T=g[v.id]===!0;return t.jsxs("section",{"data-settings-item":Wr(v.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",className:w>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(v.titleKey)}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:E.description})]})]}),E.placeholders&&E.placeholders.length>0&&t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[s("settings.magicPrompts.page.placeholdersLabel")," ",E.placeholders.map(Z=>`{{${Z.key}}}`).join(", ")]})]}),t.jsx(hs,{value:U,onChange:Z=>I(v.id,Z.target.value),className:"min-h-[220px] font-mono text-sm"}),A&&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(S?"settings.magicPrompts.page.status.unsavedChanges":M?"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:()=>{L(v.id)},disabled:!M||z||T,children:s(T?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),t.jsx(J,{size:"sm",onClick:()=>{C(v.id)},disabled:!S||z||T||A,children:s(z?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},v.id)})]})})},Ay=s=>{const e=Ze.c(89),{onItemSelect:n}=s,{t:a}=st(),[r,i]=o.useState(null),[l,u]=o.useState(null),[c,x]=o.useState(null),{selectedSnippetName:m,snippets:g,setSelectedSnippet:d,setSnippetDraft:b,deleteSnippet:h,loadSnippets:f}=gr(Ps(Dy));let y,P;e[0]!==f?(y=()=>{f()},P=[f],e[0]=f,e[1]=y,e[2]=P):(y=e[1],P=e[2]),o.useEffect(y,P);let I;e[3]!==n||e[4]!==d||e[5]!==b||e[6]!==g?(I=async()=>{const ne=new Set(g.map(Ey));let re="new-snippet",ye=1;for(;ne.has(re);)re=`new-snippet-${ye++}`;b({name:re,scope:"global"}),d(re),n?.()},e[3]=n,e[4]=d,e[5]=b,e[6]=g,e[7]=I):I=e[7];const C=I;let L;e[8]!==r||e[9]!==h||e[10]!==a?(L=async()=>{if(!r)return;await h(r.name)?(_.success(a("settings.snippets.sidebar.toast.deleted")),i(null)):_.error(a("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=h,e[10]=a,e[11]=L):L=e[11];const k=L;let v;e[12]!==g?(v=[...g].sort(My),e[12]=g,e[13]=v):v=e[13];const w=v;let E;e[14]===Symbol.for("react.memo_cache_sentinel")?(E=ce("flex h-full flex-col","bg-background"),e[14]=E):E=e[14];let K;e[15]!==a?(K=a("settings.snippets.sidebar.title"),e[15]=a,e[16]=K):K=e[16];let U;e[17]!==K?(U=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:K}),e[17]=K,e[18]=U):U=e[18];let M;e[19]!==g.length||e[20]!==a?(M=a("settings.snippets.sidebar.total",{count:g.length}),e[19]=g.length,e[20]=a,e[21]=M):M=e[21];let S;e[22]!==M?(S=t.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[22]=M,e[23]=S):S=e[23];let A;e[24]!==a?(A=a("settings.snippets.sidebar.actions.create"),e[24]=a,e[25]=A):A=e[25];let z;e[26]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[26]=z):z=e[26];let T;e[27]!==C||e[28]!==A?(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:C,"aria-label":A,children:z}),e[27]=C,e[28]=A,e[29]=T):T=e[29];let Z;e[30]!==S||e[31]!==T?(Z=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,T]}),e[30]=S,e[31]=T,e[32]=Z):Z=e[32];let G;e[33]!==Z||e[34]!==U?(G=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[U,Z]}),e[33]=Z,e[34]=U,e[35]=G):G=e[35];let te;if(e[36]!==n||e[37]!==l||e[38]!==c||e[39]!==m||e[40]!==d||e[41]!==w||e[42]!==a){let ne;e[44]!==n||e[45]!==l||e[46]!==c||e[47]!==m||e[48]!==d||e[49]!==a?(ne=re=>t.jsxs(yn,{open:c===re.name,onOpenChange:ye=>x(ye?re.name:null),children:[t.jsxs(bn,{render:t.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m===re.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ye=>{ye.preventDefault(),x(re.name)}}),children:[t.jsxs("button",{onClick:()=>{d(re.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:["#",re.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.${re.source}`)})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:re.description||re.content.replace(/\s+/g," ").substring(0,80)})]}),t.jsxs(gs,{open:l===re.name,onOpenChange:ye=>{ye&&x(null),u(ye?re.name:null)},children:[t.jsx(ms,{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:re.name}),children:t.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:t.jsxs(Ns,{onClick:ye=>{ye.stopPropagation(),i(re)},className:"text-destructive focus:text-destructive",children:[t.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]})]}),t.jsx(vn,{className:"w-fit min-w-20",children:t.jsxs(ln,{onClick:ye=>{ye.stopPropagation(),i(re)},className:"text-destructive focus:text-destructive",children:[t.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]},`${re.source}:${re.filePath}`),e[44]=n,e[45]=l,e[46]=c,e[47]=m,e[48]=d,e[49]=a,e[50]=ne):ne=e[50],te=w.map(ne),e[36]=n,e[37]=l,e[38]=c,e[39]=m,e[40]=d,e[41]=w,e[42]=a,e[43]=te}else te=e[43];let Y;e[51]!==te?(Y=t.jsx(Ht,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:te}),e[51]=te,e[52]=Y):Y=e[52];const N=r!==null;let W;e[53]===Symbol.for("react.memo_cache_sentinel")?(W=ne=>{ne||i(null)},e[53]=W):W=e[53];let B;e[54]!==a?(B=a("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=a,e[55]=B):B=e[55];let F;e[56]!==B?(F=t.jsx(Ot,{children:B}),e[56]=B,e[57]=F):F=e[57];const O=r?.name??"";let Q;e[58]!==a||e[59]!==O?(Q=a("settings.snippets.sidebar.dialog.deleteDescription",{name:O}),e[58]=a,e[59]=O,e[60]=Q):Q=e[60];let H;e[61]!==Q?(H=t.jsx(Bt,{children:Q}),e[61]=Q,e[62]=H):H=e[62];let ie;e[63]!==F||e[64]!==H?(ie=t.jsxs(zt,{children:[F,H]}),e[63]=F,e[64]=H,e[65]=ie):ie=e[65];let oe;e[66]===Symbol.for("react.memo_cache_sentinel")?(oe=()=>i(null),e[66]=oe):oe=e[66];let se;e[67]!==a?(se=a("settings.common.actions.cancel"),e[67]=a,e[68]=se):se=e[68];let xe;e[69]!==se?(xe=t.jsx(J,{size:"sm",variant:"ghost",onClick:oe,children:se}),e[69]=se,e[70]=xe):xe=e[70];let ae;e[71]!==a?(ae=a("settings.common.actions.delete"),e[71]=a,e[72]=ae):ae=e[72];let fe;e[73]!==k||e[74]!==ae?(fe=t.jsx(J,{size:"sm",onClick:k,children:ae}),e[73]=k,e[74]=ae,e[75]=fe):fe=e[75];let Ce;e[76]!==xe||e[77]!==fe?(Ce=t.jsxs(qt,{children:[xe,fe]}),e[76]=xe,e[77]=fe,e[78]=Ce):Ce=e[78];let ge;e[79]!==ie||e[80]!==Ce?(ge=t.jsxs(Tt,{className:"max-w-md",children:[ie,Ce]}),e[79]=ie,e[80]=Ce,e[81]=ge):ge=e[81];let ve;e[82]!==N||e[83]!==ge?(ve=t.jsx(Mt,{open:N,onOpenChange:W,children:ge}),e[82]=N,e[83]=ge,e[84]=ve):ve=e[84];let Ne;return e[85]!==G||e[86]!==Y||e[87]!==ve?(Ne=t.jsxs("div",{className:E,children:[G,Y,ve]}),e[85]=G,e[86]=Y,e[87]=ve,e[88]=Ne):Ne=e[88],Ne};function Dy(s){return{selectedSnippetName:s.selectedSnippetName,snippets:s.snippets,setSelectedSnippet:s.setSelectedSnippet,setSnippetDraft:s.setSnippetDraft,deleteSnippet:s.deleteSnippet,loadSnippets:s.loadSnippets}}function Ey(s){return s.name}function My(s,e){return s.name.localeCompare(e.name)}const Ty=()=>{const{t:s}=st(),{selectedSnippetName:e,snippets:n,snippetDraft:a,setSnippetDraft:r,updateSnippet:i,createSnippet:l}=gr(Ps(E=>({selectedSnippetName:E.selectedSnippetName,snippets:E.snippets,snippetDraft:E.snippetDraft,setSnippetDraft:E.setSnippetDraft,updateSnippet:E.updateSnippet,createSnippet:E.createSnippet}))),u=o.useMemo(()=>e?n.find(E=>E.name===e||E.aliases.includes(e))??null:null,[e,n]),c=!!(a&&a.name===e&&!u),[x,m]=o.useState(""),[g,d]=o.useState("global"),[b,h]=o.useState(""),[f,y]=o.useState(""),[P,I]=o.useState(""),[C,L]=o.useState(!1),k=o.useRef(null);o.useEffect(()=>{if(c&&a){const E={draftName:a.name||"",draftScope:a.scope||"global",description:a.description||"",aliases:(a.aliases||[]).join(", "),content:a.content||""};m(E.draftName),d(E.draftScope),h(E.description),y(E.aliases),I(E.content),k.current=E}else if(u){const E={draftName:"",draftScope:"global",description:u.description??"",aliases:u.aliases.join(", "),content:u.content};h(E.description),y(E.aliases),I(E.content),k.current=E}},[u,c,e,a]);const v=o.useMemo(()=>{const E=k.current;return E?c&&x!==E.draftName||c&&g!==E.draftScope?!0:b!==E.description||f!==E.aliases||P!==E.content:!1},[f,P,b,x,g,c]),w=async()=>{const E=c?x.trim().replace(/\s+/g,"-"):e?.trim();if(!E){_.error(s("settings.snippets.page.toast.nameRequired"));return}if(!P.trim()){_.error(s("settings.snippets.page.toast.contentRequired"));return}const K=f.split(",").map(U=>U.trim()).filter(Boolean);L(!0);try{if(!(c?await l(E,P,{aliases:K,description:b,scope:g}):await i(E,{content:P,aliases:K,description:b}))){_.error(s("settings.snippets.page.toast.saveFailed"));return}_.success(s("settings.snippets.page.toast.saved")),c&&r(null)}finally{L(!1)}};return e?t.jsx(Ht,{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}`}),u?t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:u.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(Xe,{value:x,onChange:E=>m(E.target.value),placeholder:s("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),t.jsxs(Pt,{value:g,onValueChange:E=>d(E),children:[t.jsx(At,{className:"w-fit min-w-[100px]",children:t.jsx(Lt,{})}),t.jsxs(Dt,{align:"end",children:[t.jsx(ut,{value:"global",children:s("settings.common.scope.global")}),t.jsx(ut,{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(Xe,{value:b,onChange:E=>h(E.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(Xe,{value:f,onChange:E=>y(E.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(hs,{value:P,onChange:E=>I(E.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:w,disabled:C||!v,size:"xs",className:"!font-normal",children:s(C?"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(D,{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")})]})})},Bc=()=>{const{t:s}=st(),e=ot(g=>g.settingsGitmojiEnabled),n=ot(g=>g.setSettingsGitmojiEnabled),a=_m(),r=Ie(g=>g.gitChangesViewMode),i=Ie(g=>g.setGitChangesViewMode),[l,u]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:s("settings.openchamber.git.option.flatList")},{id:"tree",label:s("settings.openchamber.git.option.treeView")}],[s]);o.useEffect(()=>{(async()=>{try{let d=null;if(!d){const b=qs()?.settings;if(b)try{const f=(await b.load())?.settings;f&&(d={gitmojiEnabled:typeof f.gitmojiEnabled=="boolean"?f.gitmojiEnabled:void 0,gitChangesViewMode:f.gitChangesViewMode==="flat"||f.gitChangesViewMode==="tree"?f.gitChangesViewMode:void 0})}catch{}}if(!d){const b=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});b.ok&&(d=await b.json())}d&&(typeof d.gitmojiEnabled=="boolean"&&n(d.gitmojiEnabled),(d.gitChangesViewMode==="flat"||d.gitChangesViewMode==="tree")&&i(d.gitChangesViewMode))}catch(d){console.warn("Failed to load git settings:",d)}finally{u(!1)}})()},[i,n]);const x=o.useCallback(async g=>{n(g);try{await wt({gitmojiEnabled:g})}catch(d){console.warn("Failed to save gitmoji setting:",d)}},[n]),m=o.useCallback(g=>{g!==r&&(i(g),wt({gitChangesViewMode:g}))},[r,i]);return l?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(g=>{const d=r===g.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":d,onClick:()=>{m(g.id)},onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),m(g.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:d,onChange:()=>{m(g.id)},ariaLabel:s("settings.openchamber.git.optionAria",{option:g.label})}),t.jsx("span",{className:d?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:g.label})]},g.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:g=>{(g.key===" "||g.key==="Enter")&&(g.preventDefault(),x(!e))},children:[t.jsx(xt,{checked:e,onChange:g=>{x(g)},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:()=>Ar(!a),onKeyDown:g=>{(g.key===" "||g.key==="Enter")&&(g.preventDefault(),Ar(!a))},children:[t.jsx(xt,{checked:a,onChange:Ar,ariaLabel:s("settings.openchamber.git.showGitignoredAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.git.showGitignored")})]})]})]})},$c=()=>{const{t:s}=st(),{isMobile:e}=Ms(),n=qs()?.github,a=nn(S=>S.status),r=nn(S=>S.isLoading),i=nn(S=>S.hasChecked),l=nn(S=>S.refreshStatus),u=nn(S=>S.setStatus),c=o.useCallback(async S=>{await on(S)},[]),[x,m]=o.useState(!1),[g,d]=o.useState(null),[b,h]=o.useState(null),f=o.useRef(null),y=o.useCallback(()=>{f.current!=null&&(window.clearInterval(f.current),f.current=null),h(null)},[]);o.useEffect(()=>((async()=>{try{i||await l(n)}catch(S){console.warn("Failed to load GitHub auth status:",S)}})(),()=>{y()}),[i,l,n,y]);const P=o.useCallback(async()=>{m(!0);try{const S=n?await n.authStart():await(async()=>{const z=await dt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),T=await z.json().catch(()=>null);if(!z.ok||!T||!("deviceCode"in T))throw new Error(T?.error||z.statusText);return T})();d(S),h(Math.max(1,S.interval)*1e3);const A=S.verificationUriComplete||S.verificationUri;c(A)}catch(S){console.error("Failed to start GitHub connect:",S),_.error(s("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[c,n,s]),I=o.useCallback(async S=>{if(n)return n.authComplete(S);const A=await dt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:S})}),z=await A.json().catch(()=>null);if(!A.ok||!z)throw new Error(z?.error||A.statusText);return z},[n]);o.useEffect(()=>{if(!(!g?.deviceCode||!b)&&f.current==null)return f.current=window.setInterval(()=>{(async()=>{try{const S=await I(g.deviceCode);if(S.connected){_.success(s("settings.github.page.toast.connected")),d(null),y(),await l(n,{force:!0});return}S.status==="slow_down"&&h(A=>A?A+5e3:5e3),(S.status==="expired_token"||S.status==="access_denied")&&(_.error(S.error||s("settings.github.page.toast.authorizationFailed")),d(null),y())}catch(S){console.warn("GitHub polling failed:",S)}})()},b),()=>{f.current!=null&&(window.clearInterval(f.current),f.current=null)}},[g,b,I,l,n,y,s]);const C=o.useCallback(async S=>{m(!0);try{if(n)await n.authSetGhCliDisabled(S);else{const A=await dt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:S})}),z=await A.json().catch(()=>null);if(!A.ok)throw new Error(z?.error||A.statusText)}_.success(s(S?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await l(n,{force:!0})}catch(A){console.error("Failed to update gh CLI setting:",A),_.error(s("settings.github.page.toast.ghCliUpdateFailed"))}finally{m(!1)}},[l,n,s]),L=o.useCallback(async()=>{m(!0);try{if(y(),d(null),n)await n.authDisconnect();else{const S=await dt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!S.ok)throw new Error(S.statusText)}_.success(s("settings.github.page.toast.disconnected")),await l(n,{force:!0})}catch(S){console.error("Failed to disconnect GitHub:",S),_.error(s("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[l,n,y,s]),k=o.useCallback(async S=>{if(S){m(!0);try{const A=n?await n.authActivate(S):await(async()=>{const z=await dt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:S})}),T=await z.json().catch(()=>null);if(!z.ok||!T)throw new Error(T?.error||z.statusText);return T})();u(A),_.success(s("settings.github.page.toast.accountSwitched"))}catch(A){console.error("Failed to switch GitHub account:",A),_.error(s("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,u,s]);if(r)return null;const v=!!a?.connected,w=a?.user,K=(a?.accounts??[]).filter(S=>!S.current),U=a?.ghCli??null,M=U?.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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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:[v?t.jsxs("div",{className:ce("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:ce("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[w?.avatarUrl?t.jsx("img",{src:w.avatarUrl,alt:w.login?s("settings.github.page.avatarAlt.withLogin",{login:w.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:w?.name?.trim()||w?.login||"GitHub"}),t.jsxs("div",{className:ce("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[t.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"font-mono",children:w?.login||s("settings.github.page.label.unknownUser")}),w?.email&&t.jsx("span",{className:"opacity-50",children:"•"}),w?.email&&t.jsx("span",{children:w.email}),t.jsx("span",{className:"opacity-50",children:"•"}),t.jsx("span",{children:M})]}),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})}),U?.active&&t.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:s("settings.github.page.ghCli.activeDescription")})]})]}),U?.active?t.jsx(J,{size:"sm",variant:"outline",onClick:()=>C(!0),disabled:x,className:ce(e?"w-full":void 0),children:s("settings.github.page.ghCli.actions.disable")}):t.jsx(J,{size:"sm",variant:"outline",onClick:L,disabled:x,className:ce("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:P,disabled:x,children:s("settings.github.page.actions.connect")})]}),K.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:K.map(S=>{const A=S.user,z=S.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:[A?.avatarUrl?t.jsx("img",{src:A.avatarUrl,alt:A.login?s("settings.github.page.avatarAlt.withLogin",{login:A.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(D,{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:A?.name?.trim()||A?.login||"GitHub"}),A?.login&&t.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[t.jsx("span",{className:"font-mono",children:A.login}),t.jsx("span",{className:"mx-1 opacity-50",children:"·"}),t.jsx("span",{children:z})]})]})]}),t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>k(S.id),disabled:x,children:s("settings.github.page.actions.switchTo")})]},S.id)})})]})]}),v&&t.jsx("div",{className:"mt-2 px-2 pb-2",children:t.jsx(J,{size:"sm",variant:"outline",onClick:P,disabled:x,className:ce(e?"w-full":void 0),children:s("settings.github.page.actions.addAccount")})}),g&&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:g.userCode}),t.jsx(J,{size:"sm",asChild:!0,children:t.jsx("a",{href:g.verificationUriComplete||g.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:()=>{y(),d(null)},children:s("settings.common.actions.cancel")})]})]}),U?.available&&!U?.active&&(!U.user||U.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:ce("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:ce("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[U.user?.avatarUrl?t.jsx("img",{src:U.user.avatarUrl,alt:U.user.login?s("settings.github.page.avatarAlt.withLogin",{login:U.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(D,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[!U.disabled&&U.user&&t.jsx("div",{className:"typography-ui-label text-foreground truncate",children:U.user.name?.trim()||U.user.login||"GitHub"}),!U.disabled&&U.user?.login&&t.jsxs("div",{className:ce("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[t.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"font-mono",children:U.user.login}),U.user.email&&t.jsx("span",{className:"opacity-50",children:"•"}),U.user.email&&t.jsx("span",{children:U.user.email})]}),t.jsx("div",{className:ce("typography-meta text-muted-foreground",U.disabled?"opacity-60":void 0),children:U.disabled?s("settings.github.page.ghCli.disabledDescription"):s("settings.github.page.ghCli.fallbackDescription")})]})]}),t.jsx(J,{size:"sm",variant:"outline",onClick:()=>C(!U.disabled),disabled:x,className:ce(e?"w-full":void 0),children:U.disabled?s("settings.github.page.ghCli.actions.enable"):s("settings.github.page.ghCli.actions.disable")})]})})]})]})},wl=[{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)"}],Ry=[{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"}],Fy=({open:s,onOpenChange:e,profileId:n,importData:a})=>{const{t:r}=st(),i=Is(H=>H.getProfileById),l=Is(H=>H.createProfile),u=Is(H=>H.updateProfile),c=Is(H=>H.deleteProfile),x=o.useMemo(()=>n&&n!=="new"&&!a?i(n):null,[n,i,a]),m=n==="new"||a!=null,g=n==="global",[d,b]=o.useState(""),[h,f]=o.useState(""),[y,P]=o.useState(""),[I,C]=o.useState("ssh"),[L,k]=o.useState(""),[v,w]=o.useState(!1),[E,K]=o.useState(""),[U,M]=o.useState(""),[S,A]=o.useState("keyword"),[z,T]=o.useState("branch"),[Z,G]=o.useState(!1),[te,Y]=o.useState(!1),[N,W]=o.useState(!1);o.useEffect(()=>{if(s){if(a){const H=a.host.split("/"),ie=H.length>=3?H[H.length-1]:a.host;b(ie),f(a.username),P(""),C("token"),k(""),w(!1),K(""),M(a.host),A("string"),T("code")}else if(m)b(""),f(""),P(""),C("ssh"),k(""),w(!1),K(""),M(""),A("keyword"),T("branch");else if(x)b(x.name),f(x.userName),P(x.userEmail),C(x.authType||"ssh"),k(x.sshKey||""),w(x.signCommits===!0),K(x.signingKey||""),M(x.host||""),A(x.color||"keyword"),T(x.icon||"branch");else if(g){const H=i("global");H&&(b(H.name),f(H.userName),P(H.userEmail),C(H.authType||"ssh"),k(H.sshKey||""),w(!1),K(""),M(H.host||""),A(H.color||"keyword"),T(H.icon||"branch"))}}},[s,n,x,m,a,g,i]);const B=async()=>{if(!h.trim()||!y.trim()){_.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(I==="token"&&!U.trim()){_.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(v&&!E.trim()){_.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}G(!0);try{const H={name:d.trim()||h.trim(),userName:h.trim(),userEmail:y.trim(),authType:I,sshKey:I==="ssh"&&L.trim()||null,signCommits:v,signingKey:E.trim()||null,host:I==="token"&&U.trim()||null,color:S,icon:z};let ie;if(m)ie=await l(H);else if(n)ie=await u(n,H);else return;ie?(_.success(r(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):_.error(r(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(H){console.error("Error saving profile:",H),_.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{G(!1)}},F=async()=>{if(!(!n||m)){W(!0);try{await c(n)?(_.success(r("settings.gitIdentities.editor.toast.profileDeleted")),Y(!1),e(!1)):_.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(H){console.error("Error deleting profile:",H),_.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{W(!1)}}},O=o.useMemo(()=>wl.find(ie=>ie.key===S)?.cssVar||"var(--syntax-keyword)",[S]),Q=a?r("settings.gitIdentities.editor.title.importCredential"):m?r("settings.gitIdentities.editor.title.newIdentity"):g?r("settings.gitIdentities.editor.title.globalIdentity"):x?.name||r("settings.gitIdentities.editor.title.editIdentity");return t.jsxs(t.Fragment,{children:[t.jsx(Mt,{open:s,onOpenChange:e,children:t.jsxs(Tt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:Q}),t.jsx(Bt,{children:r(g?"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:[!g&&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(Xe,{value:d,onChange:H=>b(H.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:wl.map(H=>t.jsx("button",{type:"button",onClick:()=>A(H.key),className:ce("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",S===H.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:H.cssVar},title:H.label},H.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:Ry.map(H=>{const ie=H.Icon;return t.jsx("button",{type:"button",onClick:()=>T(H.key),className:ce("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",z===H.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:H.label,children:t.jsx(D,{name:ie,className:"w-3.5 h-3.5",style:{color:z===H.key?O:"var(--surface-muted-foreground)"}})},H.key)})})]})]}),!g&&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")}),!g&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),t.jsx(Xe,{value:h,onChange:H=>f(H.target.value),placeholder:r("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!g,readOnly:g,disabled:g,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")}),!g&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),t.jsx(Xe,{type:"email",value:y,onChange:H=>P(H.target.value),placeholder:r("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!g,readOnly:g,disabled:g,className:"h-8"})]})]}),!g&&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":I==="ssh",onClick:()=>C("ssh"),children:[t.jsx(D,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),t.jsxs(J,{size:"sm",type:"button",variant:"chip","aria-pressed":I==="token",onClick:()=>C("token"),children:[t.jsx(D,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.gitIdentities.editor.field.authToken")]})]})]}),I==="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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),t.jsx(Xe,{value:L,onChange:H=>k(H.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(xt,{checked:v,onChange:w,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(Xe,{value:E,onChange:H=>K(H.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!v,className:"h-8 font-mono text-xs"})]})]}),I==="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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]})]}),t.jsx(Xe,{value:U,onChange:H=>M(H.target.value),placeholder:r("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),t.jsxs(qt,{className:"gap-2",children:[!g&&!m&&t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>Y(!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(D,{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(g?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!g&&t.jsx(J,{size:"sm",onClick:B,disabled:Z,children:r(Z?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),t.jsx(Mt,{open:te,onOpenChange:H=>{N||Y(H)},children:t.jsxs(Tt,{className:"max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:r("settings.gitIdentities.page.deleteDialog.title")}),t.jsx(Bt,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:x?.name||d})})]}),t.jsxs(qt,{children:[t.jsx(J,{variant:"ghost",onClick:()=>Y(!1),disabled:N,children:r("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",variant:"destructive",onClick:()=>{F()},disabled:N,children:r("settings.common.actions.delete")})]})]})})]})},Ly={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},Oy={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},zy=()=>{const s=Ze.c(118),{t:e}=st(),{profiles:n,globalIdentity:a,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:u,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:x,setDefaultGitIdentityId:m,getUnimportedCredentials:g}=Is(Ps(Uy)),[d,b]=o.useState(!1),[h,f]=o.useState(null),[y,P]=o.useState(null),[I,C]=o.useState(null),[L,k]=o.useState(!1);let v,w;s[0]!==x||s[1]!==c||s[2]!==u||s[3]!==l?(v=()=>{l(),u(),c(),x()},w=[l,u,c,x],s[0]=x,s[1]=c,s[2]=u,s[3]=l,s[4]=v,s[5]=w):(v=s[4],w=s[5]),o.useEffect(v,w);let E,K,U,M,S,A,z,T,Z,G,te,Y,N,W;if(s[6]!==r||s[7]!==I||s[8]!==i||s[9]!==g||s[10]!==a||s[11]!==n||s[12]!==m||s[13]!==e){const Pe=g();let Me;s[28]===Symbol.for("react.memo_cache_sentinel")?(Me=(pe,Le)=>{f(pe),P(Le??null),b(!0)},s[28]=Me):Me=s[28];const Te=Me;let Ve;s[29]!==r||s[30]!==m||s[31]!==e?(Ve=async pe=>{const Le=r===pe?null:pe;if(!await m(Le)){_.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}_.success(e(Le?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},s[29]=r,s[30]=m,s[31]=e,s[32]=Ve):Ve=s[32];const Ue=Ve;let Oe;s[33]!==I||s[34]!==i||s[35]!==e?(Oe=async()=>{if(!I)return;k(!0),await i(I.id)?(_.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:I.name})),C(null)):_.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),k(!1)},s[33]=I,s[34]=i,s[35]=e,s[36]=Oe):Oe=s[36],K=Oe,E=Ht,S="h-full",A="w-full bg-background",U="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")?(M=t.jsx("div",{"data-settings-item":"git.github-account",children:t.jsx($c,{})}),s[37]=M):M=s[37],Y="git.identities",N="border-t border-border/40 pt-6";let _e;s[38]!==e?(_e=e("settings.gitIdentities.page.section.title"),s[38]=e,s[39]=_e):_e=s[39];let Ke;s[40]!==_e?(Ke=t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:_e})}),s[40]=_e,s[41]=Ke):Ke=s[41];let Qe,Fe;s[42]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>Te("new"),Fe=t.jsx(D,{name:"add",className:"w-3.5 h-3.5 mr-1"}),s[42]=Qe,s[43]=Fe):(Qe=s[42],Fe=s[43]);let V;s[44]!==e?(V=e("settings.common.badge.new"),s[44]=e,s[45]=V):V=s[45];let le;s[46]!==V?(le=t.jsxs(J,{size:"sm",variant:"outline",onClick:Qe,children:[Fe," ",V]}),s[46]=V,s[47]=le):le=s[47],s[48]!==Ke||s[49]!==le?(W=t.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[Ke,le]}),s[48]=Ke,s[49]=le,s[50]=W):W=s[50],z="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",T=a&&t.jsx(Nl,{profile:a,isDefault:r==="global",onEdit:()=>Te("global"),onToggleDefault:()=>Ue("global"),isReadOnly:!0,hasBorder:n.length>0||Pe.length>0}),Z=n.map((pe,Le)=>t.jsx(Nl,{profile:pe,isDefault:r===pe.id,onEdit:()=>Te(pe.id),onToggleDefault:()=>Ue(pe.id),onDelete:()=>C(pe),hasBorder:Le<n.length-1||Pe.length>0},pe.id)),G=!a&&n.length===0&&Pe.length===0&&t.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[t.jsx(D,{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")})]}),te=Pe.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")})}),Pe.map((pe,Le)=>t.jsx(Ky,{credential:pe,onImport:()=>Te("new",{host:pe.host,username:pe.username}),hasBorder:Le<Pe.length-1},`${pe.host}-${pe.username}`))]}),s[6]=r,s[7]=I,s[8]=i,s[9]=g,s[10]=a,s[11]=n,s[12]=m,s[13]=e,s[14]=E,s[15]=K,s[16]=U,s[17]=M,s[18]=S,s[19]=A,s[20]=z,s[21]=T,s[22]=Z,s[23]=G,s[24]=te,s[25]=Y,s[26]=N,s[27]=W}else E=s[14],K=s[15],U=s[16],M=s[17],S=s[18],A=s[19],z=s[20],T=s[21],Z=s[22],G=s[23],te=s[24],Y=s[25],N=s[26],W=s[27];let B;s[51]!==z||s[52]!==T||s[53]!==Z||s[54]!==G||s[55]!==te?(B=t.jsxs("div",{className:z,children:[T,Z,G,te]}),s[51]=z,s[52]=T,s[53]=Z,s[54]=G,s[55]=te,s[56]=B):B=s[56];let F;s[57]!==B||s[58]!==Y||s[59]!==N||s[60]!==W?(F=t.jsxs("div",{"data-settings-item":Y,className:N,children:[W,B]}),s[57]=B,s[58]=Y,s[59]=N,s[60]=W,s[61]=F):F=s[61];let O;s[62]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx(Bc,{}),s[62]=O):O=s[62];let Q;s[63]!==U||s[64]!==M||s[65]!==F?(Q=t.jsxs("div",{className:U,children:[M,F,O]}),s[63]=U,s[64]=M,s[65]=F,s[66]=Q):Q=s[66];let H;s[67]!==E||s[68]!==S||s[69]!==A||s[70]!==Q?(H=t.jsx(E,{outerClassName:S,className:A,children:Q}),s[67]=E,s[68]=S,s[69]=A,s[70]=Q,s[71]=H):H=s[71];let ie;s[72]!==y||s[73]!==d||s[74]!==h?(ie=t.jsx(Fy,{open:d,onOpenChange:b,profileId:h,importData:y}),s[72]=y,s[73]=d,s[74]=h,s[75]=ie):ie=s[75];const oe=I!==null;let se;s[76]!==L?(se=Pe=>{L||Pe||C(null)},s[76]=L,s[77]=se):se=s[77];let xe;s[78]!==e?(xe=e("settings.gitIdentities.page.deleteDialog.title"),s[78]=e,s[79]=xe):xe=s[79];let ae;s[80]!==xe?(ae=t.jsx(Ot,{children:xe}),s[80]=xe,s[81]=ae):ae=s[81];const fe=I?.name??"";let Ce;s[82]!==e||s[83]!==fe?(Ce=e("settings.gitIdentities.page.deleteDialog.description",{name:fe}),s[82]=e,s[83]=fe,s[84]=Ce):Ce=s[84];let ge;s[85]!==Ce?(ge=t.jsx(Bt,{children:Ce}),s[85]=Ce,s[86]=ge):ge=s[86];let ve;s[87]!==ae||s[88]!==ge?(ve=t.jsxs(zt,{children:[ae,ge]}),s[87]=ae,s[88]=ge,s[89]=ve):ve=s[89];let Ne;s[90]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>C(null),s[90]=Ne):Ne=s[90];let ne;s[91]!==e?(ne=e("settings.common.actions.cancel"),s[91]=e,s[92]=ne):ne=s[92];let re;s[93]!==L||s[94]!==ne?(re=t.jsx(J,{variant:"ghost",onClick:Ne,disabled:L,children:ne}),s[93]=L,s[94]=ne,s[95]=re):re=s[95];let ye;s[96]!==K?(ye=()=>{K()},s[96]=K,s[97]=ye):ye=s[97];let q;s[98]!==e?(q=e("settings.common.actions.delete"),s[98]=e,s[99]=q):q=s[99];let $;s[100]!==L||s[101]!==ye||s[102]!==q?($=t.jsx(J,{size:"sm",variant:"destructive",onClick:ye,disabled:L,children:q}),s[100]=L,s[101]=ye,s[102]=q,s[103]=$):$=s[103];let ee;s[104]!==re||s[105]!==$?(ee=t.jsxs(qt,{children:[re,$]}),s[104]=re,s[105]=$,s[106]=ee):ee=s[106];let de;s[107]!==ve||s[108]!==ee?(de=t.jsxs(Tt,{className:"max-w-md",children:[ve,ee]}),s[107]=ve,s[108]=ee,s[109]=de):de=s[109];let De;s[110]!==oe||s[111]!==se||s[112]!==de?(De=t.jsx(Mt,{open:oe,onOpenChange:se,children:de}),s[110]=oe,s[111]=se,s[112]=de,s[113]=De):De=s[113];let ke;return s[114]!==H||s[115]!==ie||s[116]!==De?(ke=t.jsxs(t.Fragment,{children:[H,ie,De]}),s[114]=H,s[115]=ie,s[116]=De,s[117]=ke):ke=s[117],ke},Nl=s=>{const e=Ze.c(56),{profile:n,isDefault:a,onEdit:r,onToggleDefault:i,onDelete:l,isReadOnly:u,hasBorder:c}=s,{t:x}=st(),[m,g]=o.useState(!1),d=Ly[n.icon||"branch"]||"git-branch",b=Oy[n.color||""],h=n.authType||"ssh";let f;e[0]!==r?(f=F=>{F.currentTarget===F.target&&(F.key!=="Enter"&&F.key!==" "||(F.preventDefault(),r()))},e[0]=r,e[1]=f):f=e[1];const y=f;let P;e[2]!==a||e[3]!==u||e[4]!==l||e[5]!==i||e[6]!==x?(P=F=>t.jsxs(t.Fragment,{children:[t.jsx(F,{onClick:O=>{O.stopPropagation(),i()},children:x(a?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!u&&l&&t.jsxs(F,{onClick:O=>{O.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[t.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),x("settings.common.actions.delete")]})]}),e[2]=a,e[3]=u,e[4]=l,e[5]=i,e[6]=x,e[7]=P):P=e[7];const I=P,C=c&&"border-b border-[var(--surface-subtle)]";let L;e[8]!==C?(L=ce("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",C),e[8]=C,e[9]=L):L=e[9];let k;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=F=>{F.preventDefault(),g(!0)},e[10]=k):k=e[10];let v;e[11]!==y||e[12]!==r||e[13]!==L?(v=t.jsx("div",{className:L,onClick:r,role:"button",tabIndex:0,onKeyDown:y,onContextMenu:k}),e[11]=y,e[12]=r,e[13]=L,e[14]=v):v=e[14];let w;e[15]!==b?(w={color:b},e[15]=b,e[16]=w):w=e[16];let E;e[17]!==d||e[18]!==w?(E=t.jsx(D,{name:d,className:"w-4 h-4 shrink-0",style:w}),e[17]=d,e[18]=w,e[19]=E):E=e[19];let K;e[20]!==n.name?(K=t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[20]=n.name,e[21]=K):K=e[21];let U;e[22]!==h?(U=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:h}),e[22]=h,e[23]=U):U=e[23];let M;e[24]!==a||e[25]!==x?(M=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]=M):M=e[26];let S;e[27]!==u||e[28]!==x?(S=u&&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]=u,e[28]=x,e[29]=S):S=e[29];let A;e[30]!==U||e[31]!==M||e[32]!==S||e[33]!==K?(A=t.jsxs("div",{className:"flex items-center gap-1.5",children:[K,U,M,S]}),e[30]=U,e[31]=M,e[32]=S,e[33]=K,e[34]=A):A=e[34];const z=h==="token"&&n.host?n.host:n.userEmail;let T;e[35]!==z?(T=t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:z}),e[35]=z,e[36]=T):T=e[36];let Z;e[37]!==A||e[38]!==T?(Z=t.jsxs("div",{className:"min-w-0",children:[A,T]}),e[37]=A,e[38]=T,e[39]=Z):Z=e[39];let G;e[40]!==Z||e[41]!==E?(G=t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[E,Z]}),e[40]=Z,e[41]=E,e[42]=G):G=e[42];let te;e[43]===Symbol.for("react.memo_cache_sentinel")?(te=t.jsx(ms,{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:By,children:t.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=te):te=e[43];let Y;e[44]!==I?(Y=t.jsxs(gs,{children:[te,t.jsx(ps,{align:"end",className:"w-fit min-w-28",children:I(Ns)})]}),e[44]=I,e[45]=Y):Y=e[45];let N;e[46]!==G||e[47]!==Y||e[48]!==v?(N=t.jsxs(bn,{render:v,children:[G,Y]}),e[46]=G,e[47]=Y,e[48]=v,e[49]=N):N=e[49];let W;e[50]!==I?(W=t.jsx(vn,{className:"w-fit min-w-28",children:I(ln)}),e[50]=I,e[51]=W):W=e[51];let B;return e[52]!==m||e[53]!==N||e[54]!==W?(B=t.jsxs(yn,{open:m,onOpenChange:g,children:[N,W]}),e[52]=m,e[53]=N,e[54]=W,e[55]=B):B=e[55],B},Ky=s=>{const e=Ze.c(21),{credential:n,onImport:a,hasBorder:r}=s,{t:i}=st();let l;e[0]!==n.host?(l=n.host.split("/"),e[0]=n.host,e[1]=l):l=e[1];const u=l,c=u.length>=3?u[u.length-1]:n.host,x=n.host.includes("/"),m=r&&"border-b border-[var(--surface-subtle)]";let g;e[2]!==m?(g=ce("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]=g):g=e[3];let d;e[4]!==c?(d=t.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=d):d=e[5];const b=x?n.host:n.username;let h;e[6]!==b?(h=t.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:b}),e[6]=b,e[7]=h):h=e[7];let f;e[8]!==d||e[9]!==h?(f=t.jsxs("div",{className:"min-w-0",children:[d,h]}),e[8]=d,e[9]=h,e[10]=f):f=e[10];let y;e[11]===Symbol.for("react.memo_cache_sentinel")?(y=t.jsx(D,{name:"download",className:"h-3 w-3"}),e[11]=y):y=e[11];let P;e[12]!==i?(P=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=P):P=e[13];let I;e[14]!==a||e[15]!==P?(I=t.jsxs(J,{size:"sm",variant:"ghost",onClick:a,className:"gap-1 shrink-0",children:[y,P]}),e[14]=a,e[15]=P,e[16]=I):I=e[16];let C;return e[17]!==I||e[18]!==g||e[19]!==f?(C=t.jsxs("div",{className:g,children:[f,I]}),e[17]=I,e[18]=g,e[19]=f,e[20]=C):C=e[20],C};function Uy(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 By(s){return s.stopPropagation()}const Vc=()=>{const s=am();return{displayMode:s,installed:s!=="browser",browserTab:s==="browser"}},$y=()=>{const s=Ze.c(2),[e,n]=o.useState(Vy);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)")],l=()=>{n(Vc())};l();for(const u of i)typeof u.addEventListener=="function"?u.addEventListener("change",l):typeof u.addListener=="function"&&u.addListener(l);return window.addEventListener("appinstalled",l),window.addEventListener("focus",l),()=>{for(const u of i)typeof u.removeEventListener=="function"?u.removeEventListener("change",l):typeof u.removeListener=="function"&&u.removeListener(l);window.removeEventListener("appinstalled",l),window.removeEventListener("focus",l)}},r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),o.useEffect(a,r),e};function Vy(){return Vc()}const _y=[{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"}],Hy=[{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"}],Wy=[{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"}],pa="OpenChamber - AI Coding Assistant",kl=[{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"}],Sl=[{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"}],Gy=[{value:"default",labelKey:"settings.openchamber.visual.option.mobileLayout.default"},{value:"new",labelKey:"settings.openchamber.visual.option.mobileLayout.new"}],Gr=s=>s==="portrait"||s==="landscape"?s:"system",qy=[{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"}],Jy=[{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"}],Cl=[{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"}],Qy=[{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"}],Il=[{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"}],Pl=[{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"}],Yy=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Xy=s=>s==="markdown"?"markdown":"plain",Fi=({visibleSettings:s})=>{const{locale:e,locales:n,setLocale:a,label:r,t:i}=st(),l=o.useCallback(p=>i(p),[i]),{isMobile:u}=Ms(),{browserTab:c}=$y(),x=Hm(),m=Ie(p=>p.showReasoningTraces),g=Ie(p=>p.sessionRecapEnabled),d=Ie(p=>p.sessionSuggestionEnabled),b=Ie(p=>p.setSessionRecapEnabled),h=Ie(p=>p.setSessionSuggestionEnabled),f=Ie(p=>p.sessionGoalEnabled),y=Ie(p=>p.setSessionGoalEnabled),P=Ie(p=>p.sessionGoalDefaultBudgetEnabled),I=Ie(p=>p.setSessionGoalDefaultBudgetEnabled),C=Ie(p=>p.sessionGoalDefaultBudget),L=Ie(p=>p.setSessionGoalDefaultBudget),k=Ie(p=>p.setShowReasoningTraces),v=Ie(p=>p.collapsibleThinkingBlocks),w=Ie(p=>p.setCollapsibleThinkingBlocks),E=Ie(p=>p.mermaidRenderingMode),K=Ie(p=>p.setMermaidRenderingMode),U=Ie(p=>p.userMessageRenderingMode),M=Ie(p=>p.setUserMessageRenderingMode),S=Ie(p=>p.collapsibleUserMessages),A=Ie(p=>p.setCollapsibleUserMessages),z=Ie(p=>p.stickyUserHeader),T=Ie(p=>p.promptNavigatorEnabled),Z=Ie(p=>p.setStickyUserHeader),G=Ie(p=>p.setPromptNavigatorEnabled),te=Ie(p=>p.expandedEditorToolbar),Y=Ie(p=>p.setExpandedEditorToolbar),N=Ie(p=>p.wideChatLayoutEnabled),W=Ie(p=>p.setWideChatLayoutEnabled),B=Ie(p=>p.codeBlockLineWrap),F=Ie(p=>p.setCodeBlockLineWrap),O=Ie(p=>p.chatRenderMode),Q=Ie(p=>p.setChatRenderMode),H=Ie(p=>p.activityRenderMode),ie=Ie(p=>p.setActivityRenderMode),oe=Ie(p=>p.fontSize),se=Ie(p=>p.setFontSize),xe=Ie(p=>p.terminalFontSize),ae=Ie(p=>p.setTerminalFontSize),fe=Ie(p=>p.editorFontSize),Ce=Ie(p=>p.setEditorFontSize),ge=Ie(p=>p.uiFont),ve=Ie(p=>p.setUiFont),Ne=Ie(p=>p.monoFont),ne=Ie(p=>p.setMonoFont),re=Ie(p=>p.padding),ye=Ie(p=>p.setPadding),q=Ie(p=>p.inputBarOffset),$=Ie(p=>p.setInputBarOffset),ee=Ie(p=>p.mobileKeyboardMode),de=Ie(p=>p.setMobileKeyboardMode),De=Ie(p=>p.diffLayoutPreference),ke=Ie(p=>p.setDiffLayoutPreference),Pe=Ie(p=>p.showTerminalQuickKeysOnDesktop),Me=Ie(p=>p.setShowTerminalQuickKeysOnDesktop),Te=Ie(p=>p.fileEditorKeymap),Ve=Ie(p=>p.setFileEditorKeymap),Ue=lo(p=>p.followUpBehavior),Oe=lo(p=>p.setFollowUpBehavior),_e=Ie(p=>p.persistChatDraft),Ke=Ie(p=>p.setPersistChatDraft),Qe=Ie(p=>p.inputSpellcheckEnabled),Fe=Ie(p=>p.setInputSpellcheckEnabled),V=Ie(p=>p.showToolFileIcons),le=Ie(p=>p.setShowToolFileIcons),pe=Ie(p=>p.showTurnChangedFiles),Le=Ie(p=>p.setShowTurnChangedFiles),we=Ie(p=>p.showExpandedBashTools),He=Ie(p=>p.setShowExpandedBashTools),X=Ie(p=>p.showExpandedEditTools),j=Ie(p=>p.setShowExpandedEditTools),be=Ie(p=>p.timeFormatPreference),Ae=Ie(p=>p.setTimeFormatPreference),ze=Ie(p=>p.weekStartPreference),Ge=Ie(p=>p.setWeekStartPreference),rt=Ie(p=>p.showSplitAssistantMessageActions),it=Ie(p=>p.setShowSplitAssistantMessageActions),at=Ie(p=>p.allowPromptingSubagentSessions),lt=Ie(p=>p.setAllowPromptingSubagentSessions),Ye=ot(p=>p.settingsMessageStreamTransport),We=ot(p=>p.setSettingsMessageStreamTransport),gt=Ye,me=ot(p=>p.settingsDefaultFileViewerPreview),et=ot(p=>p.setSettingsDefaultFileViewerPreview),nt=Ie(p=>p.isSettingsDialogOpen),{themeMode:tt,setThemeMode:ft,availableThemes:bt,customThemesLoading:Rt,reloadCustomThemes:ue,lightThemeId:$e,darkThemeId:Je,setLightThemePreference:qe,setDarkThemePreference:yt}=pr(),[kt,ht]=o.useState(!1),Et=o.useMemo(()=>ns()&&typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancySupported===!0,[]),Jt=typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancy===!0,[Zt,cs]=o.useState(Jt),[is,ts]=o.useState(!1),As=o.useMemo(()=>ns()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Se=Ie(p=>p.dockBadgeEnabled),vt=Ie(p=>p.setDockBadgeEnabled),[jt,Wt]=o.useState(0),Gt=Ie(p=>p.reportUsage),$t=Ie(p=>p.setReportUsage),fs=o.useCallback(p=>{$t(p),wt({reportUsage:p})},[$t]),ks=nt&&(s?s.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!ks)return;let p=null,Re=Date.now();const mt=()=>{const _t=Date.now();_t-Re>=420&&(Wt(js=>(js+1)%24),Re=_t),p=requestAnimationFrame(mt)};(typeof document>"u"||document.visibilityState==="visible")&&(p=requestAnimationFrame(mt));const Vt=()=>{document.visibilityState==="visible"&&p===null?p=requestAnimationFrame(mt):document.visibilityState!=="visible"&&p!==null&&(cancelAnimationFrame(p),p=null)};return document.addEventListener("visibilitychange",Vt),()=>{document.removeEventListener("visibilitychange",Vt),p!==null&&cancelAnimationFrame(p)}},[ks]);const Qt=o.useCallback(p=>{M(p),wt({userMessageRenderingMode:p})},[M]),Ts=o.useCallback(p=>{Z(p),wt({stickyUserHeader:p})},[Z]),kn=o.useCallback(p=>{G(p),wt({promptNavigatorEnabled:p})},[G]),Js=o.useCallback(p=>{Y(p),wt({expandedEditorToolbar:p})},[Y]),Rs=o.useCallback(p=>{A(p),wt({collapsibleUserMessages:p})},[A]),$s=o.useCallback(p=>{W(p),wt({wideChatLayoutEnabled:p})},[W]),ct=o.useCallback(p=>{it(p),wt({showSplitAssistantMessageActions:p})},[it]),pt=o.useCallback(p=>{Fe(p),wt({inputSpellcheckEnabled:p})},[Fe]),Nt=o.useCallback(p=>{Q(p),wt({chatRenderMode:p})},[Q]),Xt=o.useCallback(p=>{We(p),wt({messageStreamTransport:p})},[We]),Yt=o.useCallback(p=>{ie(p),wt({activityRenderMode:p})},[ie]),cn=o.useCallback(p=>{K(p),wt({mermaidRenderingMode:p})},[K]),dn=o.useCallback(p=>{le(p),wt({showToolFileIcons:p})},[le]),Sn=o.useCallback(p=>{Le(p),wt({showTurnChangedFiles:p})},[Le]),ta=o.useCallback(p=>{et(p),wt({defaultFileViewerPreview:p}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:p}}))},[et]),sa=o.useCallback(p=>{He(p),wt({showExpandedBashTools:p})},[He]),na=o.useCallback(p=>{j(p),wt({showExpandedEditTools:p})},[j]),Cs=o.useCallback(p=>{Ae(p),wt({timeFormatPreference:p})},[Ae]),Vs=o.useCallback(p=>{Ge(p),wt({weekStartPreference:p})},[Ge]),Qs=o.useMemo(()=>bt.filter(p=>p.metadata.variant==="light").sort((p,Re)=>p.metadata.name.localeCompare(Re.metadata.name)),[bt]),Fs=o.useMemo(()=>bt.filter(p=>p.metadata.variant==="dark").sort((p,Re)=>p.metadata.name.localeCompare(Re.metadata.name)),[bt]),_s=o.useMemo(()=>Qs.find(p=>p.metadata.id===$e)??Qs[0],[Qs,$e]),ka=o.useMemo(()=>Fs.find(p=>p.metadata.id===Je)??Fs[0],[Fs,Je]),zs=o.useCallback((p,Re)=>{const mt=Re==="dark"?" Dark":" Light";return p.endsWith(mt)?p.slice(0,-mt.length):p},[]),Be=p=>s?s.includes(p):!0,ds=rs(),hr=Be("theme")&&!ds,as=Be("theme")||Be("timeFormat")||Be("weekStart"),Sa=u&&An()&&!ns()&&!ds,Ln=ds?as:Be("theme")||Sa||Be("pwaInstallName")||Be("pwaOrientation")||Be("timeFormat")||Be("weekStart"),On=Be("fontSize")||Be("terminalFontSize")||Be("editorFontSize")||Be("spacing")||Be("inputBarOffset"),fr=Be("terminalQuickKeys")&&!u||Be("fileEditorKeymap")||Be("expandedEditorToolbar"),Ca=Be("mermaidRendering")||Be("userMessageRendering")||Be("chatRenderMode")||Be("messageTransport")||Be("activityRenderMode")&&O==="sorted"||Be("collapsibleUserMessages")||Be("stickyUserHeader")||Be("promptNavigatorEnabled")&&!ds||Be("wideChatLayout")||Be("codeBlockLineWrap")||Be("splitAssistantMessageActions")||Be("subagentReadOnlyBanner")||Be("diffLayout")||Be("dotfiles")||Be("fileViewerPreview")||Be("reasoning")||Be("followUpBehavior")||Be("persistDraft")||Be("showToolFileIcons")||Be("expandedTools")||!u&&Be("inputSpellcheck"),Ks=Be("pwaInstallName")&&An()&&c&&!ns()&&!ds,Us=Be("pwaOrientation")&&An()&&!ns()&&!ds,un=Be("mobileKeyboardMode")&&An()&&!ns()&&!ds&&Wm(),[mn,xr]=o.useState(()=>rp()),[aa,Ys]=o.useState(""),[zn,pn]=o.useState("system"),yr=o.useMemo(()=>{const p=Il.find(Re=>Re.id===be);return l(p?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[be,l]),br=o.useMemo(()=>{const p=Pl.find(Re=>Re.id===ze);return l(p?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[ze,l]),vr=o.useMemo(()=>{const p=kl.find(Re=>Re.id===zn);return p?l(p.labelKey):void 0},[zn,l]),Ia=o.useMemo(()=>{const p=Sl.find(Re=>Re.id===ee);return p?l(p.labelKey):void 0},[ee,l]),jr=o.useCallback(p=>{p!==mn&&(xr(p),ip(p),window.location.reload())},[mn]),R=o.useCallback(async p=>{if(typeof window>"u")return;const Re=window,Vt=p.trim().replace(/\s+/g," ").slice(0,64);if(await wt({pwaAppName:Vt}),typeof Re.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const _t=Re.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Vt);Ys(_t);return}Ys(Vt||pa),Re.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),je=o.useCallback(async p=>{if(typeof window>"u")return;const Re=window,mt=Gr(p);if(await wt({pwaOrientation:mt}),typeof Re.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Vt=Re.__OPENCHAMBER_SET_PWA_ORIENTATION__(mt);pn(Vt);return}pn(mt),Re.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!Ks&&!Us&&!un)return;let p=!1;return(async()=>{try{const mt=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!mt.ok){p||Ys(pa);return}const Vt=await mt.json().catch(()=>({})),js=(typeof Vt?.pwaAppName=="string"?Vt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ls=Gr(Vt?.pwaOrientation),Ds=go(Vt?.mobileKeyboardMode);p||(Ks&&Ys(js||pa),Us&&pn(Ls),un&&de(Ds))}catch{p||(Ks&&Ys(pa),Us&&pn("system"),un&&de("native"))}})(),()=>{p=!0}},[de,un,Ks,Us]),t.jsxs("div",{className:"space-y-8",children:[Ln&&t.jsxs("div",{className:"mb-8 space-y-6",children:[hr&&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:_y.map(p=>t.jsx(J,{variant:"chip",size:"xs","aria-pressed":tt===p.value,className:"!font-normal",onClick:()=>ft(p.value),children:l(p.labelKey)},p.value))})]}),Sa&&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:Gy.map(p=>t.jsx(J,{variant:"chip",size:"xs","aria-pressed":mn===p.value,className:"!font-normal",onClick:()=>jr(p.value),children:l(p.labelKey)},p.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(Pt,{value:_s?.metadata.id??"",onValueChange:qe,children:[t.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:t.jsx(Lt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:_s?zs(_s.metadata.name,"light"):void 0})}),t.jsx(Dt,{children:Qs.map(p=>t.jsx(ut,{value:p.metadata.id,children:zs(p.metadata.name,"light")},p.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(Pt,{value:ka?.metadata.id??"",onValueChange:yt,children:[t.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:t.jsx(Lt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:ka?zs(ka.metadata.name,"dark"):void 0})}),t.jsx(Dt,{children:Fs.map(p=>t.jsx(ut,{value:p.metadata.id,children:zs(p.metadata.name,"dark")},p.metadata.id))})]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[t.jsx("button",{type:"button",disabled:Rt||kt,onClick:()=>{const p=Date.now();ht(!0),ue().finally(()=>{const Re=Date.now()-p;if(Re<500){window.setTimeout(()=>{ht(!1)},500-Re);return}ht(!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(kt?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),t.jsxs(St,{children:[t.jsx(Ct,{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(D,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(It,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]}),Et&&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":Zt,onClick:()=>{is||cs(!Zt)},onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),is||cs(!Zt))},children:[t.jsx(xt,{checked:Zt,onChange:cs,disabled:is,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")})]})]}),Zt!==Jt&&t.jsx("div",{className:"pl-6",children:t.jsx(J,{variant:"outline",size:"sm",disabled:is,onClick:()=>{ts(!0),Gm("desktop_set_vibrancy",{enabled:Zt})},children:i(is?"settings.openchamber.visual.actions.restarting":"settings.openchamber.visual.actions.saveAndRestart")})})]}),As&&t.jsx("div",{"data-settings-item":"appearance.dock-badge",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":Se,onClick:()=>vt(!Se),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),vt(!Se))},children:[t.jsx(xt,{checked:Se,onChange:vt,ariaLabel:i("settings.openchamber.visual.field.dockBadge")}),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.dockBadge")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.dockBadgeHint")})]})]})})]}),as&&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(Pt,{value:e,onValueChange:p=>a(p),children:[t.jsx(At,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:t.jsx(Lt,{children:r(e)})}),t.jsx(Dt,{children:n.map(p=>t.jsx(ut,{value:p,children:r(p)},p))})]})]}),(Be("timeFormat")||Be("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:[Be("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(Pt,{value:be,onValueChange:p=>Cs(p),children:[t.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:t.jsx(Lt,{children:yr})}),t.jsx(Dt,{children:Il.map(p=>t.jsx(ut,{value:p.id,children:l(p.labelKey)},p.id))})]})]}),Be("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(Pt,{value:ze,onValueChange:p=>Vs(p),children:[t.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:t.jsx(Lt,{children:br})}),t.jsx(Dt,{children:Pl.map(p=>t.jsx(ut,{value:p.id,children:l(p.labelKey)},p.id))})]})]})]})]}),(Ks||Us||un)&&t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[Ks&&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(Xe,{value:aa,onChange:p=>{Ys(p.target.value)},onBlur:()=>{R(aa)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),R(aa))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ys(pa),R("")},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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Us&&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(Pt,{value:zn,onValueChange:p=>{const Re=Gr(p);pn(Re),je(Re)},children:[t.jsx(At,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:t.jsx(Lt,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:vr})}),t.jsx(Dt,{children:kl.map(p=>t.jsx(ut,{value:p.id,children:l(p.labelKey)},p.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>{pn("system"),je("system")},disabled:zn==="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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),un&&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(Pt,{value:ee,onValueChange:p=>{const Re=go(p);de(Re),wt({mobileKeyboardMode:Re})},children:[t.jsx(At,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:t.jsx(Lt,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Ia})}),t.jsx(Dt,{children:Sl.map(p=>t.jsx(ut,{value:p.id,children:l(p.labelKey)},p.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>{de("native"),wt({mobileKeyboardMode:"native"})},disabled:ee==="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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),On&&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:[Be("fontSize")&&!u&&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(Pt,{value:ge,onValueChange:p=>ve(p),children:[t.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:t.jsx(Lt,{children:co.find(p=>p.id===ge)?.label})}),t.jsx(Dt,{children:co.map(p=>t.jsx(ut,{value:p.id,children:t.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>ve(uo),disabled:ge===uo,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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Be("terminalFontSize")&&t.jsxs("div",{className:ce("py-1",u?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",u?"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:ce("flex items-center gap-2",u?"w-full":"w-fit"),children:[t.jsxs(Pt,{value:Ne,onValueChange:p=>ne(p),children:[t.jsx(At,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:t.jsx(Lt,{children:mo.find(p=>p.id===Ne)?.label})}),t.jsx(Dt,{children:mo.map(p=>t.jsx(ut,{value:p.id,children:t.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>ne(po),disabled:Ne===po,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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Be("fontSize")&&!u&&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(bs,{value:oe,onValueChange:se,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:()=>se(100),disabled:oe===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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Be("terminalFontSize")&&t.jsxs("div",{"data-settings-item":"appearance.terminal-font-size",className:ce("py-1",u?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",u?"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:ce("flex items-center gap-2",u?"w-full":"w-fit"),children:[t.jsx(bs,{value:xe,onValueChange:ae,min:9,max:52,step:1,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>ae(13),disabled:xe===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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Be("editorFontSize")&&t.jsxs("div",{"data-settings-item":"appearance.editor-font-size",className:ce("py-1",u?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",u?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editorFontSize")})}),t.jsxs("div",{className:ce("flex items-center gap-2",u?"w-full":"w-fit"),children:[t.jsx(bs,{value:fe,onValueChange:Ce,min:9,max:32,step:1,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ce(13),disabled:fe===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:i("settings.common.actions.reset"),children:t.jsx(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Be("spacing")&&t.jsxs("div",{"data-settings-item":"appearance.spacing-density",className:ce("py-1",u?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",u?"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:ce("flex items-center gap-2",u?"w-full":"w-fit"),children:[t.jsx(bs,{value:re,onValueChange:ye,min:50,max:200,step:5,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>ye(100),disabled:re===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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Be("inputBarOffset")&&t.jsxs("div",{"data-settings-item":"appearance.input-bar-offset",className:ce("py-1",u?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",u?"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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),t.jsxs("div",{className:ce("flex items-center gap-2",u?"w-full":"w-fit"),children:[t.jsx(bs,{value:q,onValueChange:$,min:0,max:100,step:5,className:"w-16"}),t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>$(0),disabled:q===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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),fr&&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")}),Be("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(p=>{const Re=Te===p,mt=i(`settings.openchamber.visual.option.fileEditorKeymap.${p}`);return t.jsxs("button",{type:"button",className:"flex cursor-pointer items-center gap-2 py-0.5 text-left",role:"radio","aria-checked":Re,onClick:()=>Ve(p),children:[t.jsx("span",{"aria-hidden":!0,className:ce("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",Re?"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:ce("block h-[5px] w-[5px] rounded-full bg-white",!Re&&"opacity-0")})}),t.jsx("span",{className:ce("typography-ui-label font-normal",Re?"text-foreground":"text-foreground/50"),children:mt})]},p)})})]}),Be("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":te,onClick:()=>Js(!te),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Js(!te))},children:[t.jsx(xt,{checked:te,onChange:Js,ariaLabel:i("settings.openchamber.visual.field.expandedEditorToolbarAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.expandedEditorToolbar")})]}),Be("terminalQuickKeys")&&!u&&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":Pe,onClick:()=>Me(!Pe),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Me(!Pe))},children:[t.jsx(xt,{checked:Pe,onChange:Me,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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),Ca&&t.jsxs("div",{className:"space-y-3",children:[(Be("userMessageRendering")||Be("mermaidRendering")||Be("chatRenderMode")||Be("messageTransport")||Be("activityRenderMode")&&O==="sorted"||Be("diffLayout")&&!ds||Be("followUpBehavior"))&&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:[Be("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:Jy.map(p=>{const Re=O===p.id,mt=jt%12;return t.jsxs("button",{type:"button",onClick:()=>Nt(p.id),"aria-pressed":Re,className:ce("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",Re?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsx("span",{className:ce("typography-ui-label",Re?"text-foreground":"text-muted-foreground"),children:l(p.labelKey)}),t.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:p.id==="live"?t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Vt=>{const _t=Vt*3+1,js=mt-_t+1,Ls=js<=0?0:js===1?42:js===2?68:92,Ds=Ls>0;return t.jsxs("div",{className:ce("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Ds?"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:`${Ls}%`}})]},Vt)})}):t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Vt=>{const _t=mt>=(Vt+1)*3;return t.jsxs("div",{className:ce("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",_t?"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%"}})]},Vt)})})})]},p.id)})})]}),Be("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:Cl.map(p=>t.jsx(J,{variant:"chip",size:"xs","aria-pressed":gt===p.id,className:"!font-normal",onClick:()=>Xt(p.id),children:l(p.labelKey)},p.id))}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const p=Cl.find(Re=>Re.id===gt);return p?.descriptionKey?l(p.descriptionKey):""})()})]})]}),Be("activityRenderMode")&&O==="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:Qy.map(p=>{const Re=H===p.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":Re,onClick:()=>Yt(p.id),onKeyDown:mt=>{(mt.key===" "||mt.key==="Enter")&&(mt.preventDefault(),Yt(p.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:Re,onChange:()=>Yt(p.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(p.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",Re?"text-foreground":"text-foreground/50"),children:l(p.labelKey)})]},p.id)})})]}),Be("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":we,onClick:()=>sa(!we),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),sa(!we))},children:[t.jsx(xt,{checked:we,onChange:sa,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":X,onClick:()=>na(!X),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),na(!X))},children:[t.jsx(xt,{checked:X,onChange:na,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),Be("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:qy.map(p=>{const Re=Xy(U)===p.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":Re,onClick:()=>Qt(p.id),onKeyDown:mt=>{(mt.key===" "||mt.key==="Enter")&&(mt.preventDefault(),Qt(p.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:Re,onChange:()=>Qt(p.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(p.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",Re?"text-foreground":"text-foreground/50"),children:l(p.labelKey)})]},p.id)})})]}),Be("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:Wy.map(p=>{const Re=E===p.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":Re,onClick:()=>cn(p.id),onKeyDown:mt=>{(mt.key===" "||mt.key==="Enter")&&(mt.preventDefault(),cn(p.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:Re,onChange:()=>cn(p.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(p.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",Re?"text-foreground":"text-foreground/50"),children:l(p.labelKey)})]},p.id)})})]}),Be("diffLayout")&&!ds&&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:Hy.map(p=>{const Re=De===p.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":Re,onClick:()=>ke(p.id),onKeyDown:mt=>{(mt.key===" "||mt.key==="Enter")&&(mt.preventDefault(),ke(p.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:Re,onChange:()=>ke(p.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:l(p.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",Re?"text-foreground":"text-foreground/50"),children:l(p.labelKey)})]},p.id)})})]}),Be("followUpBehavior")&&t.jsxs("section",{"data-settings-item":"chat.follow-up-behavior",className:"p-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.followUpBehavior")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.followUpBehaviorAria"),className:"mt-0.5 space-y-0",children:Yy.map(p=>{const Re=Ue===p.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":Re,onClick:()=>Oe(p.id),onKeyDown:mt=>{(mt.key===" "||mt.key==="Enter")&&(mt.preventDefault(),Oe(p.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:Re,onChange:()=>Oe(p.id),ariaLabel:i("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(p.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",Re?"text-foreground":"text-foreground/50"),children:l(p.labelKey)})]},p.id)})})]})]}),Be("sessionGoal")&&!ds&&t.jsxs("section",{className:"p-2 mb-6 space-y-0.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.goal.sectionTitle")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),t.jsx(It,{sideOffset:8,className:"max-w-sm",children:i("settings.openchamber.visual.goal.description")})]})]}),t.jsxs("div",{"data-settings-item":"chat.session-goal",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>y(!f),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),y(!f))},children:[t.jsx(xt,{checked:f,onChange:y,ariaLabel:i("settings.openchamber.visual.field.sessionGoalAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sessionGoal")})]}),t.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2 py-0.5",children:[t.jsxs("div",{className:ce("flex items-center gap-2",f?"cursor-pointer":"opacity-50"),role:"button",tabIndex:f?0:-1,"aria-pressed":P,onClick:()=>{f&&I(!P)},onKeyDown:p=>{f&&(p.key===" "||p.key==="Enter")&&(p.preventDefault(),I(!P))},children:[t.jsx(xt,{checked:P,onChange:I,disabled:!f,ariaLabel:i("settings.openchamber.visual.goal.budgetAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.goal.budgetLabel")})]}),f&&P?t.jsx(bs,{value:C,onValueChange:p=>{typeof p=="number"&&Number.isFinite(p)&&p>0&&L(Math.floor(p))},min:1e3,max:1e8,step:5e4}):null]})]}),(Be("sessionAssist")||Be("collapsibleUserMessages")||Be("stickyUserHeader")||Be("promptNavigatorEnabled")&&!ds||Be("wideChatLayout")||Be("codeBlockLineWrap")||Be("splitAssistantMessageActions")||Be("subagentReadOnlyBanner")||Be("dotfiles")||Be("fileViewerPreview")||Be("persistDraft")||Be("showToolFileIcons")||Be("showTurnChangedFiles")||!u&&Be("inputSpellcheck")||Be("reasoning"))&&t.jsxs("div",{className:"space-y-6",children:[(Be("sessionAssist")||Be("subagentReadOnlyBanner"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.session-assistance",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.sessionAssistance")}),Be("sessionAssist")&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-settings-item":"chat.session-recap",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":g,onClick:()=>b(!g),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),b(!g))},children:[t.jsx(xt,{checked:g,onChange:b,ariaLabel:i("settings.openchamber.visual.field.sessionRecapAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sessionRecap")})]}),t.jsxs("div",{"data-settings-item":"chat.session-suggestion",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":d,onClick:()=>h(!d),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),h(!d))},children:[t.jsx(xt,{checked:d,onChange:h,ariaLabel:i("settings.openchamber.visual.field.sessionSuggestionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sessionSuggestion")})]})]}),Be("subagentReadOnlyBanner")&&t.jsxs("div",{"data-settings-item":"chat.subagent-read-only-banner",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":at,onClick:()=>lt(!at),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),lt(!at))},children:[t.jsx(xt,{checked:at,onChange:lt,ariaLabel:i("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.allowPromptingSubagentSessions")})]})]}),Be("reasoning")&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.reasoning",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.reasoning")}),Be("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:()=>k(!m),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),k(!m))},children:[t.jsx(xt,{checked:m,onChange:k,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),Be("reasoning")&&m&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":v,onClick:()=>w(!v),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),w(!v))},children:[t.jsx(xt,{checked:v,onChange:w,ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleThinkingBlocks")})]})]}),(Be("collapsibleUserMessages")||Be("stickyUserHeader")||Be("promptNavigatorEnabled")&&!ds||Be("wideChatLayout")||Be("splitAssistantMessageActions")||Be("codeBlockLineWrap"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.message-appearance",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.messageAppearance")}),Be("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":S,onClick:()=>Rs(!S),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Rs(!S))},children:[t.jsx(xt,{checked:S,onChange:Rs,ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleUserMessages")})]}),Be("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":z,onClick:()=>Ts(!z),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Ts(!z))},children:[t.jsx(xt,{checked:z,onChange:Ts,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),Be("promptNavigatorEnabled")&&!ds&&t.jsxs("div",{"data-settings-item":"chat.prompt-navigator",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":T,onClick:()=>kn(!T),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),kn(!T))},children:[t.jsx(xt,{checked:T,onChange:kn,ariaLabel:i("settings.openchamber.visual.field.promptNavigatorEnabledAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.promptNavigatorEnabled")})]}),Be("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":N,onClick:()=>$s(!N),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),$s(!N))},children:[t.jsx(xt,{checked:N,onChange:$s,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),Be("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":rt,onClick:()=>ct(!rt),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),ct(!rt))},children:[t.jsx(xt,{checked:rt,onChange:ct,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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),Be("codeBlockLineWrap")&&t.jsxs("div",{"data-settings-item":"chat.code-block-line-wrap",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":B,onClick:()=>F(!B),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),F(!B))},children:[t.jsx(xt,{checked:B,onChange:F,ariaLabel:i("settings.openchamber.visual.field.codeBlockLineWrapAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeBlockLineWrap")})]})]}),(Be("showToolFileIcons")||Be("showTurnChangedFiles")||Be("dotfiles")||Be("fileViewerPreview"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.tools-and-files",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.toolsAndFiles")}),Be("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":V,onClick:()=>dn(!V),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),dn(!V))},children:[t.jsx(xt,{checked:V,onChange:dn,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),Be("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":pe,onClick:()=>Sn(!pe),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Sn(!pe))},children:[t.jsx(xt,{checked:pe,onChange:Sn,ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showTurnChangedFiles")})]}),Be("dotfiles")&&!rs()&&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:()=>Dr(!x),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Dr(!x))},children:[t.jsx(xt,{checked:x,onChange:Dr,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),Be("fileViewerPreview")&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":me,onClick:()=>ta(!me),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),ta(!me))},children:[t.jsx("span",{onClick:p=>p.stopPropagation(),children:t.jsx(xt,{checked:me,onChange:ta,ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.defaults.field.openFilesPreview")})]})]}),(Be("persistDraft")||!u&&Be("inputSpellcheck"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.composer",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.composer")}),Be("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":_e,onClick:()=>Ke(!_e),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Ke(!_e))},children:[t.jsx(xt,{checked:_e,onChange:Ke,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!u&&Be("inputSpellcheck")&&t.jsxs("div",{"data-settings-item":"chat.spellcheck",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Qe,onClick:()=>pt(!Qe),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),pt(!Qe))},children:[t.jsx(xt,{checked:Qe,onChange:pt,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]})]}),Be("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(xt,{checked:Gt,onChange:fs,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":Gt,onClick:()=>fs(!Gt),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),fs(!Gt))},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")})]})]})]})})]})},Zy=1,eb=365,Al=30,tb=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],_c=()=>{const s=Ze.c(113),{t:e}=st(),n=Ie(sb),a=Ie(nb),r=Ie(ab),i=Ie(rb),l=Ie(ib),u=Ie(ob);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:g,action:d}=rm(c),b=x.length;let h;s[1]!==g||s[2]!==e?(h=async()=>{const ee=await g({force:!0});if(ee.completedIds.length===0&&ee.failedIds.length===0){_.message(ee.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ee.completedIds.length>0&&_.success(ee.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ee.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ee.completedIds.length})),ee.failedIds.length>0&&_.error(ee.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ee.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ee.failedIds.length}))},s[1]=g,s[2]=e,s[3]=h):h=s[3];const f=h;let y;s[4]!==e?(y=e("settings.openchamber.sessionRetention.title"),s[4]=e,s[5]=y):y=s[5];let P;s[6]!==y?(P=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:y}),s[6]=y,s[7]=P):P=s[7];let I;s[8]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[8]=I):I=s[8];let C;s[9]!==e?(C=e("settings.openchamber.sessionRetention.tooltip"),s[9]=e,s[10]=C):C=s[10];let L;s[11]!==C?(L=t.jsxs(St,{children:[I,t.jsx(It,{sideOffset:8,className:"max-w-xs",children:C})]}),s[11]=C,s[12]=L):L=s[12];let k;s[13]!==P||s[14]!==L?(k=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[P,L]})}),s[13]=P,s[14]=L,s[15]=k):k=s[15];let v,w;s[16]!==n||s[17]!==i?(v=()=>i(!n),w=ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),i(!n))},s[16]=n,s[17]=i,s[18]=v,s[19]=w):(v=s[18],w=s[19]);let E;s[20]!==e?(E=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),s[20]=e,s[21]=E):E=s[21];let K;s[22]!==n||s[23]!==i||s[24]!==E?(K=t.jsx(xt,{checked:n,onChange:i,ariaLabel:E}),s[22]=n,s[23]=i,s[24]=E,s[25]=K):K=s[25];let U;s[26]!==e?(U=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),s[26]=e,s[27]=U):U=s[27];let M;s[28]!==U?(M=t.jsx("span",{className:"typography-ui-label text-foreground",children:U}),s[28]=U,s[29]=M):M=s[29];let S;s[30]!==n||s[31]!==K||s[32]!==M||s[33]!==v||s[34]!==w?(S=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:v,onKeyDown:w,children:[K,M]}),s[30]=n,s[31]=K,s[32]=M,s[33]=v,s[34]=w,s[35]=S):S=s[35];let A;s[36]!==e?(A=e("settings.openchamber.sessionRetention.field.retentionPeriod"),s[36]=e,s[37]=A):A=s[37];let z;s[38]!==A?(z=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:A})}),s[38]=A,s[39]=z):z=s[39];let T;s[40]!==e?(T=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),s[40]=e,s[41]=T):T=s[41];let Z;s[42]!==a||s[43]!==l||s[44]!==T?(Z=t.jsx(bs,{value:a,onValueChange:l,min:Zy,max:eb,step:1,"aria-label":T,className:"w-20 tabular-nums"}),s[42]=a,s[43]=l,s[44]=T,s[45]=Z):Z=s[45];let G;s[46]!==e?(G=e("settings.openchamber.sessionRetention.field.days"),s[46]=e,s[47]=G):G=s[47];let te;s[48]!==G?(te=t.jsx("span",{className:"typography-ui-label text-muted-foreground",children:G}),s[48]=G,s[49]=te):te=s[49];let Y;s[50]!==l?(Y=()=>l(Al),s[50]=l,s[51]=Y):Y=s[51];const N=a===Al;let W;s[52]!==e?(W=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),s[52]=e,s[53]=W):W=s[53];let B;s[54]!==e?(B=e("settings.common.actions.reset"),s[54]=e,s[55]=B):B=s[55];let F;s[56]===Symbol.for("react.memo_cache_sentinel")?(F=t.jsx(D,{name:"restart",className:"h-3.5 w-3.5"}),s[56]=F):F=s[56];let O;s[57]!==Y||s[58]!==N||s[59]!==W||s[60]!==B?(O=t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:Y,disabled:N,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":W,title:B,children:F}),s[57]=Y,s[58]=N,s[59]=W,s[60]=B,s[61]=O):O=s[61];let Q;s[62]!==Z||s[63]!==te||s[64]!==O?(Q=t.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[Z,te,O]}),s[62]=Z,s[63]=te,s[64]=O,s[65]=Q):Q=s[65];let H;s[66]!==z||s[67]!==Q?(H=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:[z,Q]}),s[66]=z,s[67]=Q,s[68]=H):H=s[68];let ie;s[69]!==e?(ie=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),s[69]=e,s[70]=ie):ie=s[70];let oe;s[71]!==ie?(oe=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:ie})}),s[71]=ie,s[72]=oe):oe=s[72];let se;s[73]!==r||s[74]!==u||s[75]!==e?(se=tb.map(ee=>t.jsx(J,{type:"button",variant:"chip",size:"xs","aria-pressed":r===ee.value,className:"!font-normal",onClick:()=>u(ee.value),children:e(ee.labelKey)},ee.value)),s[73]=r,s[74]=u,s[75]=e,s[76]=se):se=s[76];let xe;s[77]!==se?(xe=t.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:se}),s[77]=se,s[78]=xe):xe=s[78];let ae;s[79]!==oe||s[80]!==xe?(ae=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:[oe,xe]}),s[79]=oe,s[80]=xe,s[81]=ae):ae=s[81];let fe;s[82]!==S||s[83]!==H||s[84]!==ae?(fe=t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[S,H,ae]}),s[82]=S,s[83]=H,s[84]=ae,s[85]=fe):fe=s[85];let Ce;s[86]!==e?(Ce=e("settings.openchamber.sessionRetention.manualCleanup.title"),s[86]=e,s[87]=Ce):Ce=s[87];let ge;s[88]!==Ce?(ge=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:Ce})}),s[88]=Ce,s[89]=ge):ge=s[89];let ve;s[90]!==m||s[91]!==e?(ve=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),s[90]=m,s[91]=e,s[92]=ve):ve=s[92];let Ne;s[93]!==f||s[94]!==m||s[95]!==ve?(Ne=t.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:t.jsx(J,{type:"button",variant:"outline",size:"xs",onClick:f,disabled:m,className:"!font-normal",children:ve})}),s[93]=f,s[94]=m,s[95]=ve,s[96]=Ne):Ne=s[96];let ne;s[97]!==ge||s[98]!==Ne?(ne=t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ge,Ne]}),s[97]=ge,s[98]=Ne,s[99]=ne):ne=s[99];let re;s[100]!==d||s[101]!==b||s[102]!==e?(re=d==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:b}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:b}),s[100]=d,s[101]=b,s[102]=e,s[103]=re):re=s[103];let ye;s[104]!==re?(ye=t.jsx("p",{className:"typography-meta text-muted-foreground",children:re}),s[104]=re,s[105]=ye):ye=s[105];let q;s[106]!==ne||s[107]!==ye?(q=t.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[ne,ye]}),s[106]=ne,s[107]=ye,s[108]=q):q=s[108];let $;return s[109]!==fe||s[110]!==q||s[111]!==k?($=t.jsxs("div",{className:"mb-8",children:[k,fe,q]}),s[109]=fe,s[110]=q,s[111]=k,s[112]=$):$=s[112],$};function sb(s){return s.autoDeleteEnabled}function nb(s){return s.autoDeleteAfterDays}function ab(s){return s.sessionRetentionAction}function rb(s){return s.setAutoDeleteEnabled}function ib(s){return s.setAutoDeleteAfterDays}function ob(s){return s.setSessionRetentionAction}const Dl=(s,e,n)=>!s||!Number.isFinite(s)?e:new Intl.DateTimeFormat(Ai(),{dateStyle:"medium",timeStyle:"short",hour12:n==="auto"?void 0:n==="12h"}).format(s),Hc=()=>{const{t:s}=st(),e=Ie(w=>w.timeFormatPreference),[n,a]=o.useState(!1),[r,i]=o.useState(!0),[l,u]=o.useState(!1),[c,x]=o.useState(null),[m,g]=o.useState(!1),[d,b]=o.useState([]),[h,f]=o.useState(im),[y,P]=o.useState(""),I=o.useMemo(()=>om(),[]),C=o.useCallback(async()=>{i(!0),P("");try{const w=await lm();b(w)}catch(w){const E=w instanceof Error?w.message:s("settings.openchamber.passkeys.toast.loadFailed");P(E)}finally{i(!1)}},[s]);o.useEffect(()=>{let w=!1;return(async()=>{try{if(!I.supported){w||(a(!1),i(!1));return}w||a(!0)}catch{w||a(!1)}if(!w){const E=await Cr();if(f(E),!E.enabled){b([]),i(!1);return}await C()}})(),()=>{w=!0,Xi()}},[C,I.supported]);const L=o.useCallback(async()=>{if(!h.enabled){const w=s("settings.openchamber.passkeys.toast.enableUiPasswordFirst");P(w),_.message(w);return}if(!n){P(I.reason),_.message(I.reason);return}if(l){Xi(),u(!1);return}P(""),u(!0);try{await cm(),f(await Cr()),await C(),_.success(s("settings.openchamber.passkeys.toast.added"))}catch(w){if(dm(w)){_.message(s("settings.openchamber.passkeys.toast.setupCanceled"));return}const E=w instanceof Error?w.message:s("settings.openchamber.passkeys.toast.addFailed");P(E),_.error(E)}finally{u(!1)}},[l,C,h.enabled,I.reason,n,s]),k=o.useCallback(async w=>{x(w),P("");try{await um(w),f(await Cr()),await C(),_.success(s("settings.openchamber.passkeys.toast.removed"))}catch(E){const K=E instanceof Error?E.message:s("settings.openchamber.passkeys.toast.removeFailed");P(K),_.error(K)}finally{x(null)}},[C,s]),v=o.useCallback(async()=>{g(!0),P("");try{await mm(),window.location.reload()}catch(w){const E=w instanceof Error?w.message:s("settings.openchamber.passkeys.toast.clearAuthFailed");P(E),_.error(E),g(!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:l?"secondary":"outline",size:"xs",onClick:()=>{L()},disabled:r||m,className:"!font-normal",children:s(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",onClick:()=>{v()},disabled:r||l||m,className:"!font-normal text-muted-foreground hover:text-foreground",children:s(m?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]})]}),!h.enabled&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.uiPasswordRequired")}),h.enabled&&!n&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:I.reason}),r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.loading")}):d.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:d.map(w=>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:w.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:w.lastUsedAt?s("settings.openchamber.passkeys.item.lastUsed",{time:Dl(w.lastUsedAt,s("settings.openchamber.passkeys.time.neverUsed"),e)}):s("settings.openchamber.passkeys.item.added",{time:Dl(w.createdAt,s("settings.openchamber.passkeys.time.neverUsed"),e)})}),t.jsx(J,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k(w.id)},disabled:c===w.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===w.id?s("settings.openchamber.passkeys.actions.removing"):s("settings.common.actions.delete")})]})]},w.id))})]}),y&&t.jsx("div",{className:"mt-1 px-2 py-1.5",children:t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:y})})]})},El=s=>{const e=xn(s);return e||{providerId:"",modelId:""}},Wc=()=>{const{t:s}=st(),e=ot(N=>N.setProvider),n=ot(N=>N.setModel),a=ot(N=>N.setAgent),r=ot(N=>N.setCurrentVariant),i=ot(N=>N.setSettingsDefaultModel),l=ot(N=>N.setSettingsDefaultVariant),u=ot(N=>N.setSettingsDefaultAgent),c=Ie(N=>N.showDeletionDialog),x=Ie(N=>N.setShowDeletionDialog),m=ot(N=>N.providers),[g,d]=o.useState(),[b,h]=o.useState(),[f,y]=o.useState(),[P,I]=o.useState(!0),[C,L]=o.useState(),[k,v]=o.useState(),[w,E]=o.useState(!0),K=o.useMemo(()=>El(g),[g]);o.useEffect(()=>{(async()=>{try{let W=null;if(!W){const B=qs()?.settings;if(B)try{const O=(await B.load())?.settings;if(O){const Q=O;W={defaultModel:typeof O.defaultModel=="string"?O.defaultModel:void 0,defaultVariant:typeof Q.defaultVariant=="string"?Q.defaultVariant:void 0,defaultAgent:typeof O.defaultAgent=="string"?O.defaultAgent:void 0,smallModelUseDefault:typeof Q.smallModelUseDefault=="boolean"?Q.smallModelUseDefault:void 0,smallModelOverride:typeof Q.smallModelOverride=="string"?Q.smallModelOverride:void 0}}}catch{}}if(!W){const B=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});B.ok&&(W=await B.json())}if(W){const B=typeof W.defaultModel=="string"&&W.defaultModel.trim().length>0?W.defaultModel.trim():void 0,F=typeof W.defaultVariant=="string"&&W.defaultVariant.trim().length>0?W.defaultVariant.trim():void 0,O=typeof W.defaultAgent=="string"&&W.defaultAgent.trim().length>0?W.defaultAgent.trim():void 0;B!==void 0&&d(B),F!==void 0&&h(F),O!==void 0&&y(O),typeof W.smallModelUseDefault=="boolean"&&I(W.smallModelUseDefault),typeof W.smallModelOverride=="string"&&W.smallModelOverride.trim()&&L(W.smallModelOverride.trim())}}catch(W){console.warn("Failed to load defaults settings:",W)}finally{E(!1)}})()},[]);const U=o.useCallback(async(N,W)=>{const B=N&&W?`${N}/${W}`:void 0;d(B),h(void 0),l(void 0),r(void 0),i(B),N&&W&&m.find(O=>O.id===N)&&(e(N),n(W));try{await wt({defaultModel:B??"",defaultVariant:""});const F=await dt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:B})});F.ok||console.warn("Failed to save default model to server:",F.status,F.statusText)}catch(F){console.warn("Failed to save default model:",F)}},[m,r,n,e,i,l]),M="__default__",S=o.useCallback(N=>N===M?s("settings.openchamber.defaults.option.default"):N.charAt(0).toUpperCase()+N.slice(1),[s]),A=o.useCallback(async N=>{const W=N===M?void 0:N||void 0;h(W),l(W),r(W);try{await wt({defaultVariant:W??""})}catch(B){console.warn("Failed to save default variant:",B)}},[r,l]),z=o.useCallback(async N=>{const W=N||void 0;y(W),u(W),N&&a(N);try{await wt({defaultAgent:W??""})}catch(B){console.warn("Failed to save default agent:",B)}},[a,u]),T=o.useCallback(async N=>{I(N);try{await wt({smallModelUseDefault:N})}catch(W){console.warn("Failed to save small model preference:",W)}},[]),Z=o.useCallback(async(N,W)=>{const B=N&&W?`${N}/${W}`:void 0;L(B);try{await wt({smallModelOverride:B??""})}catch(F){console.warn("Failed to save small model override:",F)}},[]),G=o.useMemo(()=>El(C),[C]);o.useEffect(()=>{if(P||k!==void 0)return;let N=!1;return(async()=>{try{const W=await dt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!W.ok)return;const B=await W.json().catch(()=>null);!N&&Array.isArray(B?.authenticatedProviders)&&v(B.authenticatedProviders.filter(F=>typeof F=="string"))}catch{}})(),()=>{N=!0}},[P,k]);const te=o.useMemo(()=>{if(!K.providerId||!K.modelId)return[];const B=m.find(F=>F.id===K.providerId)?.models.find(F=>F.id===K.modelId)?.variants;return B?Object.keys(B):[]},[K.modelId,K.providerId,m]),Y=te.length>0;return o.useEffect(()=>{!Y&&b&&(h(void 0),l(void 0),r(void 0),wt({defaultVariant:""}).catch(()=>{}))},[b,r,l,Y]),w?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")," ",K.providerId?t.jsxs("span",{className:"text-foreground",children:[K.providerId,"/",K.modelId,Y?` (${b??s("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):t.jsx("span",{className:"text-foreground",children:s("settings.openchamber.defaults.summaryOpenCodeDefault")}),f&&t.jsxs(t.Fragment,{children:[" / ",t.jsx("span",{className:"text-foreground",children:f})]})]}),t.jsxs("div",{"data-settings-item":"sessions.default-model",className:ce("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(va,{providerId:K.providerId,modelId:K.modelId,onChange:U})})]}),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(Pt,{value:b??M,onValueChange:A,disabled:!Y,children:[t.jsx(At,{className:"w-fit min-w-[120px]",children:t.jsx(Lt,{placeholder:s("settings.openchamber.defaults.field.thinkingPlaceholder"),children:S(b??M)})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:M,children:s("settings.openchamber.defaults.option.default")}),te.map(N=>t.jsx(ut,{value:N,children:S(N)},N))]})]})})]}),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(oc,{agentName:f||"",onChange:z})})]}),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:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),x(!c))},children:[t.jsx(xt,{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")})]})]}),t.jsx("div",{className:"mt-6 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.smallModel.title")})})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsx("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:s("settings.openchamber.defaults.smallModel.description")}),t.jsxs("div",{"data-settings-item":"sessions.small-model",className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":P,onClick:()=>{T(!P)},onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),T(!P))},children:[t.jsx(xt,{checked:P,onChange:N=>{T(N)},ariaLabel:s("settings.openchamber.defaults.smallModel.useDefaultAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.smallModel.useDefault")})]}),P?null:t.jsxs("div",{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.smallModel.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(va,{providerId:G.providerId,modelId:G.modelId,onChange:Z,allowedProviderIds:k})})]})]})]})},Ml={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"}},lb={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"},cb=()=>{const{t:s}=st(),e=o.useMemo(()=>ns(),[]),n=o.useMemo(()=>rs(),[]),a=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),r=!e&&!n&&!a,i=Ie(F=>F.nativeNotificationsEnabled),l=Ie(F=>F.setNativeNotificationsEnabled),u=Ie(F=>F.notificationMode),c=Ie(F=>F.setNotificationMode),x=Ie(F=>F.notifyOnSubtasks),m=Ie(F=>F.setNotifyOnSubtasks),g=Ie(F=>F.notifyOnCompletion),d=Ie(F=>F.setNotifyOnCompletion),b=Ie(F=>F.notifyOnError),h=Ie(F=>F.setNotifyOnError),f=Ie(F=>F.notifyOnQuestion),y=Ie(F=>F.setNotifyOnQuestion),P=Ie(F=>F.notificationTemplates),I=Ie(F=>F.setNotificationTemplates),[C,L]=o.useState("default"),[k,v]=o.useState(!1),[w,E]=o.useState(!1),[K,U]=o.useState(!1);o.useEffect(()=>{if(!r){v(!1),E(!1);return}typeof Notification<"u"&&L(Notification.permission);const F=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;v(F),(async()=>{if(!F){E(!1);return}try{const Q=await navigator.serviceWorker.getRegistration();if(!Q){E(!1);return}const H=await Q.pushManager.getSubscription();E(!!H)}catch{E(!1)}})()},[r]);const M=async F=>{if(e){l(F);return}if(!r){l(F);return}if(F&&typeof Notification<"u"&&Notification.permission==="default")try{const O=await Notification.requestPermission();L(O),O==="granted"?l(!0):_.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.description")})}catch(O){console.error("Failed to request notification permission:",O),_.error(s("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(F&&C==="granted"))},S=e||n||a||r&&typeof Notification<"u"&&Notification.permission==="granted",A=(F,O,Q)=>{I({...P,[F]:{...P[F],[O]:Q}})},z=F=>{const O="=".repeat((4-F.length%4)%4),Q=(F+O).replace(/-/g,"+").replace(/_/g,"/"),H=atob(Q),ie=new Uint8Array(H.length);for(let oe=0;oe<H.length;oe+=1)ie[oe]=H.charCodeAt(oe);return ie},T=async(F,O,Q)=>{let H=null;const ie=new Promise((oe,se)=>{H=setTimeout(()=>{se(new Error(Q))},O)});try{return await Promise.race([F,ie])}finally{H&&clearTimeout(H)}},Z=async F=>{if(F.active)return;const O=F.installing||F.waiting;O&&O.state!=="activated"&&await T(new Promise(Q=>{const H=()=>{O.state==="activated"&&(O.removeEventListener("statechange",H),Q())};O.addEventListener("statechange",H),H()}),15e3,"Service worker activation timed out")},G=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 O=null;for(const Q of F)try{const H=Q.opts?navigator.serviceWorker.register("/sw.js",Q.opts):navigator.serviceWorker.register("/sw.js");return await T(H,1e4,`Service worker registration timed out (${Q.label})`)}catch(H){O=H}throw O instanceof Error?O:new Error("Service worker registration failed")},te=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const F=await navigator.serviceWorker.getRegistration();if(F)return F;const O=await G();try{await O.update()}catch{}return await Z(O),O},Y=F=>{const O=F,Q=[`type=${typeof F}`,`toString=${String(F)}`,`name=${String(O?.name??"")}`,`message=${String(O?.message??"")}`];let H="";try{H=JSON.stringify(F)}catch{}return{summary:Q.filter(Boolean).join(" | "),json:H,stack:typeof O?.stack=="string"?O.stack:""}},N=async()=>{const F=qs();if(!F?.notifications){_.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"})?_.success(s("settings.notifications.page.toast.testNotificationSent")):_.error(s("settings.notifications.page.toast.testNotificationFailed"))}catch(O){console.error("Test notification failed:",O),_.error(s("settings.notifications.page.toast.testNotificationFailed"))}},W=async()=>{if(!k){_.error(s("settings.notifications.page.toast.pushUnsupported"));return}const F=qs();if(!F?.push){_.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}U(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const ae=await Notification.requestPermission();if(L(ae),ae!=="granted"){_.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){_.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const O=await F.push.getVapidPublicKey();if(!O?.publicKey){_.error(s("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Q=await te();await Z(Q);const H=await Q.pushManager.getSubscription();if(!("pushManager"in Q)||!Q.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const oe=(H??await T(Q.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:z(O.publicKey)}),15e3,"Push subscription timed out")).toJSON(),se=oe.keys;if(!oe.endpoint||!se?.p256dh||!se.auth)throw new Error("Push subscription missing keys");if(!(await T(F.push.subscribe({endpoint:oe.endpoint,keys:{p256dh:se.p256dh,auth:se.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:ac()}),15e3,"Push subscribe request timed out"))?.ok){_.error(s("settings.notifications.page.toast.enableBackgroundFailed"));return}E(!0),_.success(s("settings.notifications.page.toast.backgroundEnabled"))}catch(O){console.error("[Push] Enable failed:",O);const Q=Y(O);_.error(s("settings.notifications.page.toast.enableBackgroundFailed"),{description:Q.summary})}finally{U(!1)}},B=async()=>{if(!k){E(!1);return}const F=qs();if(!F?.push){_.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}U(!0);try{const Q=await(await te()).pushManager.getSubscription();if(!Q){E(!1);return}const H=Q.endpoint;await Q.unsubscribe(),await F.push.unsubscribe({endpoint:H}),E(!1),_.success(s("settings.notifications.page.toast.backgroundDisabled"))}finally{U(!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":i&&S,onClick:()=>{M(!(i&&S))},onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),M(!(i&&S)))},children:[t.jsx(xt,{checked:i&&S,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")})]}),i&&S&&!a&&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":u==="always",onClick:()=>c(u==="always"?"hidden-only":"always"),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),c(u==="always"?"hidden-only":"always"))},children:[t.jsx(xt,{checked:u==="always",onChange:F=>c(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:()=>{N()},children:s("settings.notifications.page.delivery.testAction")})})]})]}),r&&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")}),C==="denied"&&t.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:s("settings.notifications.page.delivery.permissionDenied")}),C==="granted"&&!i&&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")})})]}),i&&S&&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":g,onClick:()=>d(!g),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),d(!g))},children:[t.jsx(xt,{checked:g,onChange:d,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":x,onClick:()=>m(!x),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),m(!x))},children:[t.jsx(xt,{checked:x,onChange:m,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":b,onClick:()=>h(!b),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),h(!b))},children:[t.jsx(xt,{checked:b,onChange:h,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:()=>y(!f),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),y(!f))},children:[t.jsx(xt,{checked:f,onChange:y,ariaLabel:s("settings.notifications.page.events.questionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.questionLabel")})]})]})]}),!a&&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(lb[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(Xe,{value:P[F].title,onChange:O=>A(F,"title",O.target.value),className:"h-7",placeholder:s(Ml[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(Xe,{value:P[F].message,onChange:O=>A(F,"message",O.target.value),className:"h-7",placeholder:s(Ml[F].messageKey)})]})]})]},F))})]})]}),r&&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(xt,{checked:k?w:!1,disabled:!k||K,onChange:F=>{F?W():B()},ariaLabel:s("settings.notifications.page.push.enableAria")}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:ce("typography-ui-label",k?"text-foreground":"text-muted-foreground"),children:s("settings.notifications.page.push.enableLabel")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s(k?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),K&&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")})})]})})]})]})},Ss=s=>{if(!s)return;s.pause();const{src:e}=s;e.startsWith("blob:")&&URL.revokeObjectURL(e),s.removeAttribute("src"),s.load()},db=[{id:"parakeet-tdt-0.6b-v2-int8",labelKey:"settings.voice.page.stt.model.parakeetV2",badgeKey:"settings.voice.page.stt.badge.bestForEnglish",accuracy:5,speed:5,size:"460 MB"},{id:"parakeet-tdt-0.6b-v3-int8",labelKey:"settings.voice.page.stt.model.parakeetV3",badgeKey:"settings.voice.page.stt.badge.bestForMultilingual",accuracy:5,speed:4,size:"465 MB"},{id:"whisper-base-int8",labelKey:"settings.voice.page.stt.model.whisperBase",badgeKey:null,accuracy:3,speed:3,size:"200 MB"},{id:"whisper-tiny-int8",labelKey:"settings.voice.page.stt.model.whisperTiny",badgeKey:null,accuracy:2,speed:4,size:"115 MB"}],Tl=s=>{const e=Ze.c(8),{value:n,label:a}=s,r=`${a}: ${n}/5`,i=`${n/5*100}%`;let l;e[0]!==i?(l=t.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:t.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:i}})}),e[0]=i,e[1]=l):l=e[1];let u;e[2]!==a?(u=t.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:a}),e[2]=a,e[3]=u):u=e[3];let c;return e[4]!==r||e[5]!==l||e[6]!==u?(c=t.jsxs("span",{className:"flex items-center gap-1.5",title:r,children:[l,u]}),e[4]=r,e[5]=l,e[6]=u,e[7]=c):c=e[7],c},ub=({selectedModelId:s,onSelect:e})=>{const{t:n}=st(),a=he.useCallback(d=>n(d),[n]),[r,i]=he.useState(new Map),[l,u]=he.useState(null),c=he.useCallback(async()=>{try{const d=await dt("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const b=await d.json();Array.isArray(b?.models)&&i(new Map(b.models.map(h=>[h.id,h])))}catch{}},[]);he.useEffect(()=>{c()},[c]);const x=Array.from(r.values()).some(d=>d.downloading);he.useEffect(()=>{if(!x)return;const d=setInterval(()=>{c()},2e3);return()=>clearInterval(d)},[x,c]);const m=async d=>{u(d);try{await dt(`/api/dictation/models/${encodeURIComponent(d)}/download`,{method:"POST"}),await c()}catch{}finally{u(null)}},g=async d=>{u(d);try{await dt(`/api/dictation/models/${encodeURIComponent(d)}`,{method:"DELETE"}),await c()}catch{}finally{u(null)}};return t.jsx("div",{role:"radiogroup","aria-label":n("settings.voice.page.field.model"),className:"mt-1 space-y-0",children:db.map(d=>{const b=s===d.id,h=r.get(d.id)??null;return t.jsxs("div",{className:"flex w-full items-start gap-2 py-1.5",children:[t.jsx("div",{className:"pt-0.5",children:t.jsx(tn,{checked:b,onChange:()=>e(d.id),ariaLabel:a(d.labelKey)})}),t.jsxs("div",{className:"min-w-0 flex-1 cursor-pointer",role:"button",tabIndex:0,onClick:()=>e(d.id),onKeyDown:f=>{(f.key===" "||f.key==="Enter")&&(f.preventDefault(),e(d.id))},children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5",children:[t.jsx("span",{className:ce("typography-ui-label font-normal",b?"text-foreground":"text-foreground/50"),children:a(d.labelKey)}),d.badgeKey?t.jsx("span",{className:"rounded px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide",style:{backgroundColor:"var(--status-success-background)",color:"var(--status-success)",border:"1px solid var(--status-success-border)"},children:a(d.badgeKey)}):null]}),t.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-4 gap-y-0.5",children:[t.jsx(Tl,{value:d.accuracy,label:n("settings.voice.page.stt.meta.accuracy")}),t.jsx(Tl,{value:d.speed,label:n("settings.voice.page.stt.meta.speed")}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:d.size})]}),h?.downloadError?t.jsx("p",{className:"mt-0.5 typography-meta text-[var(--status-error)]",children:h.downloadError}):null]}),t.jsx("div",{className:"flex w-14 flex-shrink-0 items-center justify-end gap-1 pt-0.5",children:h?.installed?t.jsxs(t.Fragment,{children:[t.jsx(J,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===d.id,onClick:()=>{g(d.id)},title:n("settings.voice.page.stt.modelDelete"),"aria-label":n("settings.voice.page.stt.modelDelete"),children:t.jsx(D,{name:"delete-bin",className:"h-4 w-4"})}),t.jsx(D,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":n("settings.voice.page.stt.modelInstalled")})]}):h?.downloading?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof h.downloadProgress=="number"?`${h.downloadProgress}%`:""})]}):t.jsx(J,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===d.id,onClick:()=>{m(d.id)},title:n("settings.voice.page.stt.modelDownload"),"aria-label":n("settings.voice.page.stt.modelDownload"),children:t.jsx(D,{name:"download",className:"h-4 w-4"})})})]},d.id)})})},qr=[{id:0,label:"Alloy (af)"},{id:1,label:"Bella (af)"},{id:2,label:"Nicole (af)"},{id:3,label:"Sarah (af)"},{id:4,label:"Sky (af)"},{id:5,label:"Adam (am)"},{id:6,label:"Michael (am)"},{id:7,label:"Emma (bf)"},{id:8,label:"Isabella (bf)"},{id:9,label:"George (bm)"},{id:10,label:"Lewis (bm)"}],Jr="kokoro-en-v0_19",mb=()=>{const{t:s}=st(),[e,n]=he.useState(null),[a,r]=he.useState(!1),i=he.useCallback(async()=>{try{const u=await dt("/api/dictation/status",{query:{provider:"local"}});if(!u.ok)return;const c=await u.json(),x=Array.isArray(c?.ttsModels)?c.ttsModels.find(m=>m.id===Jr):null;x&&n(x)}catch{}},[]);he.useEffect(()=>{i()},[i]),he.useEffect(()=>{if(!e?.downloading)return;const u=setInterval(()=>{i()},2e3);return()=>clearInterval(u)},[e?.downloading,i]);const l=async u=>{r(!0);try{const c=u==="POST"?`/api/dictation/models/${Jr}/download`:`/api/dictation/models/${Jr}`;await dt(c,{method:u}),await i()}catch{}finally{r(!1)}};return e?t.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:"Kokoro"}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:"305 MB"}),e.installed?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":s("settings.voice.page.stt.modelInstalled")}),t.jsx(J,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:a,onClick:()=>{l("DELETE")},title:s("settings.voice.page.stt.modelDelete"),"aria-label":s("settings.voice.page.stt.modelDelete"),children:t.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})]}):e.downloading?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof e.downloadProgress=="number"?`${e.downloadProgress}%`:""})]}):t.jsx(J,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:a,onClick:()=>{l("POST")},title:s("settings.voice.page.stt.modelDownload"),"aria-label":s("settings.voice.page.stt.modelDownload"),children:t.jsx(D,{name:"download",className:"h-4 w-4"})}),e.downloadError?t.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:e.downloadError}):null]}):null},pb=[{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"}],gb=()=>{const{t:s}=st(),{isMobile:e}=Ms(),n=ot(j=>j.voiceProvider),a=ot(j=>j.setVoiceProvider),r=ot(j=>j.speechRate),i=ot(j=>j.setSpeechRate),l=ot(j=>j.speechPitch),u=ot(j=>j.setSpeechPitch),c=ot(j=>j.speechVolume),x=ot(j=>j.setSpeechVolume),m=ot(j=>j.sayVoice),g=ot(j=>j.setSayVoice),d=ot(j=>j.localTtsVoiceId),b=ot(j=>j.setLocalTtsVoiceId),{speak:h,stop:f,isPlaying:y,error:P}=pm(),I=he.useCallback(()=>{if(y){f();return}const j=qr.find(be=>be.id===d)?.label??String(d);h(s("settings.voice.page.preview.voiceLine",{voiceName:j}),{speakerId:d,speed:ot.getState().speechRate})},[y,d,h,f,s]),C=ot(j=>j.browserVoice),L=ot(j=>j.setBrowserVoice),k=ot(j=>j.openaiVoice),v=ot(j=>j.setOpenaiVoice),w=ot(j=>j.openaiApiKey),E=ot(j=>j.setOpenaiApiKey),K=ot(j=>j.openaiCompatibleUrl),U=ot(j=>j.setOpenaiCompatibleUrl),M=ot(j=>j.openaiCompatibleApiKey),S=ot(j=>j.setOpenaiCompatibleApiKey),A=ot(j=>j.openaiCompatibleVoice),z=ot(j=>j.setOpenaiCompatibleVoice),T=ot(j=>j.openaiCompatibleTtsModel),Z=ot(j=>j.setOpenaiCompatibleTtsModel),G=ot(j=>j.showMessageTTSButtons),te=ot(j=>j.ttsInputMode),Y=ot(j=>j.setTtsInputMode),N=ot(j=>j.sttProvider),W=ot(j=>j.setSttProvider),B=ot(j=>j.sttServerUrl),F=ot(j=>j.setSttServerUrl),O=ot(j=>j.sttApiKey),Q=ot(j=>j.setSttApiKey),H=ot(j=>j.sttModel),ie=ot(j=>j.setSttModel),oe=ot(j=>j.sttLocalModel),se=ot(j=>j.setSttLocalModel),xe=ot(j=>j.sttLanguage),ae=ot(j=>j.setSttLanguage),fe=ot(j=>j.setShowMessageTTSButtons),Ce=ot(j=>j.dictationEnabled),ge=ot(j=>j.setDictationEnabled),[ve,Ne]=he.useState(!1),[ne,re]=he.useState([]),[ye,q]=he.useState(!1),[$,ee]=he.useState(null),[de,De]=he.useState(!1),[ke,Pe]=he.useState(!1),[Me,Te]=he.useState(null),[Ve,Ue]=he.useState(!1),[Oe,_e]=he.useState(null),[Ke,Qe]=he.useState([]),[Fe,V]=he.useState(!1);he.useEffect(()=>((async()=>{const be=await Ir.waitForVoices();Qe(be)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Qe(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const le=he.useMemo(()=>Ke.filter(j=>j.lang).sort((j,be)=>{const Ae=j.lang.startsWith("en"),ze=be.lang.startsWith("en");if(Ae&&!ze)return-1;if(!Ae&&ze)return 1;const Ge=j.lang.localeCompare(be.lang);return Ge!==0?Ge:j.name.localeCompare(be.name)}),[Ke]),pe=he.useCallback(()=>{if(Fe){Ir.cancelSpeech(),V(!1);return}const j=Ke.find(Ge=>Ge.name===C),be=j?.name??s("settings.voice.page.preview.browserVoiceFallback"),Ae=s("settings.voice.page.preview.voiceLine",{voiceName:be});V(!0);const ze=new SpeechSynthesisUtterance(Ae);ze.rate=r,ze.pitch=l,ze.volume=c,j&&(ze.voice=j,ze.lang=j.lang),ze.onend=()=>V(!1),ze.onerror=()=>V(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(ze)},[C,Ke,r,l,c,Fe,s]);he.useEffect(()=>()=>{Fe&&Ir.cancelSpeech()},[Fe]),he.useEffect(()=>{if(!G||n!=="openai"&&n!=="openai-compatible"){De(w.trim().length>0);return}(async()=>{try{const ze=(await(await dt("/api/tts/status")).json()).available,Ge=w.trim().length>0;De(ze||Ge)}catch{De(w.trim().length>0)}})()},[w,G,n]),he.useEffect(()=>{if(!G){Ne(!1),re([]);return}dt("/api/tts/say/status").then(j=>j.json()).then(j=>{if(Ne(j.available),j.voices){const be=j.voices.filter((Ae,ze,Ge)=>Ge.findIndex(rt=>rt.name===Ae.name)===ze).sort((Ae,ze)=>Ae.name.localeCompare(ze.name));re(be)}}).catch(()=>{Ne(!1)})},[G]);const Le=he.useCallback(async()=>{if($){Ss($),ee(null),q(!1);return}q(!0);let j=null;try{const be=await dt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.voiceLine",{voiceName:m}),voice:m,rate:Math.round(100+(r-.5)*200)})});if(!be.ok)throw new Error("Preview failed");const Ae=await be.blob(),ze=URL.createObjectURL(Ae);j=new Audio(ze),j.onended=()=>{Ss(j),ee(null),q(!1)},j.onerror=()=>{Ss(j),ee(null),q(!1)},ee(j),await j.play()}catch{Ss(j),ee(null),q(!1)}},[m,r,$,s]);he.useEffect(()=>()=>{Ss($)},[$]);const we=he.useCallback(async()=>{if(Me){Ss(Me),Te(null),Pe(!1);return}Pe(!0);let j=null;try{const be=await dt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.voiceLine",{voiceName:k}),voice:k,speed:r,apiKey:w||void 0})});if(!be.ok){const Ge=await be.json().catch(()=>({error:"Unknown error"}));throw new Error(Ge.error||`HTTP ${be.status}`)}const Ae=await be.blob(),ze=URL.createObjectURL(Ae);j=new Audio(ze),j.onended=()=>{Ss(j),Te(null),Pe(!1)},j.onerror=()=>{Ss(j),Te(null),Pe(!1)},Te(j),await j.play()}catch{Ss(j),Te(null),Pe(!1)}},[k,r,Me,w,s]);he.useEffect(()=>()=>{Ss(Me)},[Me]);const He=he.useCallback(async()=>{if(Oe){Ss(Oe),_e(null),Ue(!1);return}if(!K.trim())return;Ue(!0);let j=null;try{const be=await dt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.customServerLine"),voice:A,model:T||void 0,speed:r,baseURL:K,apiKey:M||void 0})});if(!be.ok){const Ge=await be.json().catch(()=>({error:"Unknown error"}));throw new Error(Ge.error||`HTTP ${be.status}`)}const Ae=await be.blob(),ze=URL.createObjectURL(Ae);j=new Audio(ze),j.onended=()=>{Ss(j),_e(null),Ue(!1)},j.onerror=()=>{Ss(j),_e(null),Ue(!1)},_e(j),await j.play()}catch{Ss(j),_e(null),Ue(!1)}},[K,A,T,M,r,Oe,s]);he.useEffect(()=>()=>{Ss(Oe)},[Oe]);const X="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return t.jsxs("div",{className:"space-y-8",children:[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":G,onClick:()=>fe(!G),onKeyDown:j=>{(j.key===" "||j.key==="Enter")&&(j.preventDefault(),fe(!G))},children:[t.jsx(xt,{checked:G,onChange:fe,ariaLabel:s("settings.voice.page.field.messageReadAloudButtonAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.messageReadAloudButton")})]}),G&&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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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:s("settings.voice.page.provider.local")})," ",s("settings.voice.page.tooltip.localTts")]}),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":n==="browser",onClick:()=>a("browser"),className:"!font-normal",children:s("settings.voice.page.provider.browser")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":n==="local",onClick:()=>a("local"),className:"!font-normal",children:s("settings.voice.page.provider.local")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":n==="openai",onClick:()=>a("openai"),className:"!font-normal",children:"OpenAI"}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":n==="openai-compatible",onClick:()=>a("openai-compatible"),className:"!font-normal",children:s("settings.voice.page.provider.custom")}),ve&&t.jsxs(J,{variant:"chip",size:"xs","aria-pressed":n==="say",onClick:()=>a("say"),className:"!font-normal",children:[t.jsx(D,{name:"apple",className:"w-3.5 h-3.5 mr-0.5"}),s("settings.voice.page.provider.say")]})]})]})}),n==="openai"&&t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:ce("typography-ui-label text-foreground",!de&&"text-[var(--status-error)]"),children:s("settings.voice.page.field.apiKey")}),t.jsx("span",{className:ce("typography-meta ml-2",de?"text-muted-foreground":"text-[var(--status-error)]/80"),children:s(de&&!w?"settings.voice.page.field.apiKeyHintUsingConfig":de?"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:j=>E(j.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(D,{name:"close",className:"w-3.5 h-3.5"})})]})]}),n==="openai-compatible"&&t.jsxs("div",{className:"py-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:ce("typography-ui-label text-foreground",!K.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:K,onChange:j=>U(j.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"}),K&&t.jsx("button",{type:"button",onClick:()=>U(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(D,{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:M,onChange:j=>S(j.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"}),M&&t.jsx("button",{type:"button",onClick:()=>S(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(D,{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:T,onChange:j=>Z(j.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:A,onChange:j=>z(j.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:He,title:s("settings.voice.page.actions.preview"),disabled:!K.trim(),children:Ve?t.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(D,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),n==="local"&&t.jsx(mb,{}),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:[n==="local"&&t.jsxs(t.Fragment,{children:[t.jsxs(Pt,{value:String(d),onValueChange:j=>b(Number.parseInt(j,10)||0),children:[t.jsx(At,{className:"w-fit",children:t.jsx(Lt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder"),children:j=>qr.find(be=>String(be.id)===j)?.label??j})}),t.jsx(Dt,{children:qr.map(j=>t.jsx(ut,{value:String(j.id),children:j.label},j.id))})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:I,title:s("settings.voice.page.actions.preview"),children:y?t.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(D,{name:"play",className:"w-3.5 h-3.5"})}),P?t.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:P}):null]}),n==="openai"&&de&&t.jsxs(t.Fragment,{children:[t.jsxs(Pt,{value:k,onValueChange:v,children:[t.jsx(At,{className:"w-fit",children:t.jsx(Lt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Dt,{children:pb.map(j=>t.jsx(ut,{value:j.value,children:j.label},j.value))})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:we,title:s("settings.voice.page.actions.preview"),children:ke?t.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(D,{name:"play",className:"w-3.5 h-3.5"})})]}),n==="openai-compatible"&&t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.voice.page.field.configuredAbove")}),n==="say"&&ve&&ne.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(Pt,{value:m,onValueChange:g,children:[t.jsx(At,{className:"w-fit",children:t.jsx(Lt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Dt,{children:ne.map(j=>t.jsx(ut,{value:j.name,children:j.name},j.name))})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:Le,title:s("settings.voice.page.actions.preview"),children:ye?t.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(D,{name:"play",className:"w-3.5 h-3.5"})})]}),n==="browser"&&le.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(Pt,{value:C||"$auto",onValueChange:j=>L(j==="$auto"?"":j),children:[t.jsx(At,{className:"w-fit max-w-[200px]",children:t.jsx(Lt,{placeholder:s("settings.voice.page.field.auto")})}),t.jsxs(Dt,{children:[t.jsx(ut,{value:"$auto",children:s("settings.voice.page.field.auto")}),le.map(j=>t.jsxs(ut,{value:j.name,children:[j.name," (",j.lang,")"]},j.name))]})]}),t.jsx(J,{size:"xs",variant:"ghost",onClick:pe,title:s("settings.voice.page.actions.preview"),children:Fe?t.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(D,{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:r,onChange:j=>i(Number(j.target.value)),className:X}),t.jsx(bs,{value:r,onValueChange:i,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:l,onChange:j=>u(Number(j.target.value)),className:X}),t.jsx(bs,{value:l,onValueChange:u,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:c,onChange:j=>x(Number(j.target.value)),className:X}),e?t.jsx(bs,{value:Math.round(c*100),onValueChange:j=>x(j/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(c*100),"%"]})]})]}),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":te==="sanitized",onClick:()=>Y("sanitized"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeSanitized")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":te==="raw",onClick:()=>Y("raw"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeRaw")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":te==="summarized",onClick:()=>Y("summarized"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeSummarized")})]})]})})]})]})]}),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.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":Ce,onClick:()=>ge(!Ce),onKeyDown:j=>{(j.key===" "||j.key==="Enter")&&(j.preventDefault(),ge(!Ce))},children:[t.jsx(xt,{checked:Ce,onChange:ge,ariaLabel:s("settings.voice.page.field.enableVoiceInputAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.enableVoiceInput")})]}),Ce&&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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{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.local")})," ",s("settings.voice.page.tooltip.sttLocal")]}),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":N==="local",onClick:()=>W("local"),className:"!font-normal",children:s("settings.voice.page.provider.local")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":N==="openai-compatible",onClick:()=>W("openai-compatible"),className:"!font-normal",children:s("settings.voice.page.provider.server")})]})]})}),N==="local"&&t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.model")}),t.jsx(ub,{selectedModelId:oe,onSelect:se})]}),N==="openai-compatible"&&t.jsxs("div",{className:"py-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:ce("typography-ui-label text-foreground",!B.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:B,onChange:j=>F(j.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"}),B&&t.jsx("button",{type:"button",onClick:()=>F(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(D,{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:O,onChange:j=>Q(j.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"}),O&&t.jsx("button",{type:"button",onClick:()=>Q(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(D,{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:H,onChange:j=>ie(j.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:xe,onChange:j=>ae(j.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"})})]})]})]})]})]})]})},$a=[{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}],Va=[{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}],hb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",fb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Qr=[{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"}],xb=[".yml",".yaml",".json"],yb="settings.openchamber.tunnel.error.invalidConfigExtension",ga=s=>{const e=s.trim().toLowerCase();return xb.some(n=>e.endsWith(n))},bb=s=>s==="ngrok"?"ngrok":"cloudflared",Gc=()=>{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"},vb=(s,e=Gc())=>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/",Yr=(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():bb(n),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Gc(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():vb(n,r);return{provider:n,dependency:a,installCommand:i}},qc=s=>s==="cloudflare"?"Cloudflare":s==="ngrok"?"Ngrok":s,Rl=s=>{const e=Ze.c(11),{provider:n}=s;let a;e[0]!==n?(a=qc(n),e[0]=n,e[1]=a):a=e[1];const r=a,u=n==="cloudflare"||n==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==u?(c=ce("size-4 shrink-0",u),e[2]=u,e[3]=c):c=e[3];let x;e[4]!==c?(x=t.jsx(D,{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 g;return e[8]!==x||e[9]!==m?(g=t.jsxs("span",{className:"flex items-center gap-2",children:[x,m]}),e[8]=x,e[9]=m,e[10]=g):g=e[10],g},fn=s=>s==="quick"?"quick":s==="managed-remote"?"managed-remote":s==="managed-local"?"managed-local":"quick",Ni=(s,e,n)=>s.find(r=>r.ms===e)?.value||n,Fl=(s,e,n)=>{const a=Ni(s,e,n);return s.find(r=>r.value===a)?.label||a},Ll=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`},jb=(s,e)=>gc(s,e,{hour:"2-digit",precision:"second"}),tr=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()}},wb=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,l=typeof i.id=="string"?i.id.trim():"",u=typeof i.name=="string"?i.name.trim():"",c=tr(typeof i.hostname=="string"?i.hostname:"");!l||!u||!c||e.has(l)||n.has(c)||(e.add(l),n.add(c),a.push({id:l,name:u,hostname:c}))}return a},Nb=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,kb=()=>{const{t:s}=st(),e=Ie(ue=>ue.timeFormatPreference),n=o.useCallback(ue=>s(ue),[s]),[a,r]=o.useState("checking"),[i,l]=o.useState(null),[u,c]=o.useState(null),[x,m]=o.useState(null),[g,d]=o.useState(null),[b,h]=o.useState(null),[f,y]=o.useState(!1),[P,I]=o.useState(!1),[C,L]=o.useState(!1),[k,v]=o.useState("cloudflare"),[w,E]=o.useState(()=>Yr("cloudflare")),[K,U]=o.useState([]),[M,S]=o.useState("quick"),[A,z]=o.useState(null),[T,Z]=o.useState([]),[G,te]=o.useState({}),[Y,N]=o.useState(""),[W,B]=o.useState({}),[F,O]=o.useState(new Set),[Q,H]=o.useState(!1),[ie,oe]=o.useState(""),[se,xe]=o.useState(""),[ae,fe]=o.useState(""),[Ce,ge]=o.useState(1800*1e3),[ve,Ne]=o.useState(480*60*1e3),[ne,re]=o.useState(""),[ye,q]=o.useState([]),[$,ee]=o.useState(()=>Date.now()),[de,De]=o.useState(null),ke=s(yb),Pe=o.useRef(null),Me=o.useMemo(()=>A?!ga(A):!1,[A]),Te=o.useMemo(()=>T.find(ue=>ue.id===Y)||T[0]||null,[T,Y]),Ve=o.useMemo(()=>ye.map(ue=>{const $e=ue.expiresAt<=$,Je=ue.status==="active"&&!$e,qe=Je?Ll(ue.expiresAt-$):ue.inactiveReason==="expired"||$e?"expired":"inactive",yt=qe==="expired"?s("settings.openchamber.tunnel.state.expired"):ue.inactiveReason==="tunnel-revoked"?s("settings.openchamber.tunnel.state.revoked"):s("settings.openchamber.tunnel.state.inactive"),kt=fn(ue.mode);return{...ue,isActive:Je,mode:kt,remainingTextForSession:qe,inactiveLabel:yt}}),[$,ye,s]),Ue=o.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>$:!1,[$,i?.bootstrapExpiresAt,i?.connectUrl]),Oe=o.useMemo(()=>!i||a!=="active"&&a!=="stopping"?!1:u===M,[u,a,i,M]),_e=o.useMemo(()=>!i||a!=="active"||!u?!1:u!==M,[u,a,i,M]),Ke=o.useMemo(()=>{if(typeof de=="number"&&Number.isFinite(de)&&de>0)return de;if(typeof window>"u")return null;const $e=ea()||window.location.href;let Je=0;try{Je=Number(new URL($e).port)}catch{Je=Number(window.location.port)}return Number.isFinite(Je)&&Je>0?Je:null},[de]),Qe=o.useMemo(()=>K.find(ue=>ue.provider===k)??null,[K,k]),Fe=o.useMemo(()=>{const ue=new Set(Qe?.modes?.map($e=>$e.key).filter($e=>$e==="quick"||$e==="managed-remote"||$e==="managed-local"));return ue.size===0?Qr:Qr.filter($e=>ue.has($e.value))},[Qe]),V=o.useMemo(()=>Fe.some(ue=>ue.value==="managed-remote"||ue.value==="managed-local"),[Fe]),le=o.useMemo(()=>w.provider===k?w:Yr(k),[w,k]),pe=o.useCallback(async ue=>{await on(ue)},[]),Le=o.useCallback((ue,$e)=>(E(Yr($e,ue)),ue.available===!0),[]),we=o.useCallback(async(ue,$e)=>{try{const Je=await dt("/api/openchamber/tunnel/check",{query:{provider:ue},...$e?{signal:$e}:{}});if(!Je.ok)return null;const qe=await Je.json();if($e?.aborted)return null;const yt=Le(qe,ue);return r(kt=>kt==="checking"||kt==="starting"||kt==="active"||kt==="stopping"?kt:yt?"idle":"not-available"),yt}catch{return null}},[Le]),He=o.useCallback(async ue=>{try{const[$e,Je,qe,yt]=await Promise.all([dt("/api/openchamber/tunnel/check",{signal:ue}),dt("/api/openchamber/tunnel/status",{signal:ue}),dt("/api/config/settings",{signal:ue,headers:{Accept:"application/json"}}),dt("/api/openchamber/tunnel/providers",{signal:ue})]),kt=await $e.json(),ht=await Je.json(),Et=qe.ok?await qe.json():{},Jt=yt.ok?await yt.json():{},Zt=ht.ttlConfig?.bootstrapTtlMs??(Et?.tunnelBootstrapTtlMs===null?null:typeof Et?.tunnelBootstrapTtlMs=="number"?Et.tunnelBootstrapTtlMs:1800*1e3),cs=typeof ht.ttlConfig?.sessionTtlMs=="number"?ht.ttlConfig.sessionTtlMs:typeof Et?.tunnelSessionTtlMs=="number"?Et.tunnelSessionTtlMs:480*60*1e3,is=fn(ht.mode??Et?.tunnelMode),ts=typeof Et?.tunnelProvider=="string"&&Et.tunnelProvider.trim().length>0?Et.tunnelProvider.trim().toLowerCase():"cloudflare",As=typeof Et?.managedLocalTunnelConfigPath=="string"&&Et.managedLocalTunnelConfigPath.trim()||null,Se=Le(kt,ts),vt=wb(ht?.managedRemoteTunnelPresets),jt=typeof ht.managedRemoteTunnelHostname=="string"?ht.managedRemoteTunnelHostname:"",Wt=vt.length>0?vt:jt?[{id:`legacy-${tr(jt)}`,name:jt,hostname:tr(jt)}]:[],Gt=Wt[0]?.id||"";if(ge(Zt),Ne(cs),v(ts),U(Array.isArray(Jt?.providers)?Jt.providers:[]),S(is),z(As),Z(Wt),N(Gt),q(Array.isArray(ht.activeSessions)?ht.activeSessions:[]),c(ht.activeTunnelMode?fn(ht.activeTunnelMode):ht.active&&ht.mode?fn(ht.mode):null),O(new Set(Array.isArray(ht.managedRemoteTunnelTokenPresetIds)?ht.managedRemoteTunnelTokenPresetIds:[])),De(typeof ht.localPort=="number"?ht.localPort:null),ht.active&&ht.url){l({url:ht.url,connectUrl:null,bootstrapExpiresAt:typeof ht.bootstrapExpiresAt=="number"?ht.bootstrapExpiresAt:null}),r("active");return}r(Se?"idle":"not-available")}catch{ue.aborted||(r("error"),d(s("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Le,s]);o.useEffect(()=>{const ue=new AbortController;return He(ue.signal),()=>ue.abort()},[He]),o.useEffect(()=>{if(!i?.connectUrl){m(null);return}let ue=!1;return nc.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then($e=>{ue||m($e)}).catch(()=>{ue||m(null)}),()=>{ue=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){re(s("settings.openchamber.tunnel.state.noExpiry"));return}let ue=null,$e=Date.now();const Je=()=>{const kt=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;kt<=0?re(s("settings.openchamber.tunnel.state.expired")):re(Ll(kt))},qe=()=>{const kt=Date.now();kt-$e>=1e3&&(Je(),$e=kt),ue=requestAnimationFrame(qe)};Je(),(typeof document>"u"||document.visibilityState==="visible")&&(ue=requestAnimationFrame(qe));const yt=()=>{document.visibilityState==="visible"&&ue===null?ue=requestAnimationFrame(qe):document.visibilityState!=="visible"&&ue!==null&&(cancelAnimationFrame(ue),ue=null)};return document.addEventListener("visibilitychange",yt),()=>{document.removeEventListener("visibilitychange",yt),ue!==null&&cancelAnimationFrame(ue)}},[s,i?.bootstrapExpiresAt]),o.useEffect(()=>{let ue=null,$e=Date.now();const Je=()=>{const yt=Date.now();yt-$e>=1e3&&(ee(yt),$e=yt),ue=requestAnimationFrame(Je)};(typeof document>"u"||document.visibilityState==="visible")&&(ue=requestAnimationFrame(Je));const qe=()=>{document.visibilityState==="visible"&&ue===null?ue=requestAnimationFrame(Je):document.visibilityState!=="visible"&&ue!==null&&(cancelAnimationFrame(ue),ue=null)};return document.addEventListener("visibilitychange",qe),()=>{document.removeEventListener("visibilitychange",qe),ue!==null&&cancelAnimationFrame(ue)}},[]),o.useEffect(()=>{if(a==="starting"||a==="stopping"||a==="checking")return;let ue=!1;const $e=async()=>{try{const qe=await dt("/api/openchamber/tunnel/status");if(!qe.ok||ue)return;const yt=await qe.json();if(ue)return;q(Array.isArray(yt.activeSessions)?yt.activeSessions:[]),O(new Set(Array.isArray(yt.managedRemoteTunnelTokenPresetIds)?yt.managedRemoteTunnelTokenPresetIds:[])),De(typeof yt.localPort=="number"?yt.localPort:null)}catch{}},Je=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||$e()},5e3);return()=>{ue=!0,window.clearInterval(Je)}},[a]);const X=o.useCallback(async ue=>{L(!0);try{await wt(ue),Object.prototype.hasOwnProperty.call(ue,"tunnelMode")&&ue.tunnelMode&&S(ue.tunnelMode),Object.prototype.hasOwnProperty.call(ue,"tunnelProvider")&&typeof ue.tunnelProvider=="string"&&v(ue.tunnelProvider),Object.prototype.hasOwnProperty.call(ue,"managedLocalTunnelConfigPath")&&z(ue.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ue,"managedRemoteTunnelPresets")&&ue.managedRemoteTunnelPresets&&Z(ue.managedRemoteTunnelPresets)}catch{_.error(s("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{L(!1)}},[s]),j=o.useCallback(async(ue,$e)=>{I(!0);try{await wt({tunnelBootstrapTtlMs:ue,tunnelSessionTtlMs:$e})}catch{_.error(s("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{I(!1)}},[s]),be=o.useCallback(async ue=>{const $e=ue.token.trim();if($e)try{const Je={...W,[ue.presetId]:$e};await wt({managedRemoteTunnelPresetTokens:Je}),O(qe=>{const yt=new Set(qe);return yt.add(ue.presetId),yt})}catch{_.error(s("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[W,s]),Ae=o.useCallback(async ue=>{h(null),d(null);const $e=K.find(qe=>qe.provider===ue),Je=$e?.modes?.some(qe=>qe.key===M)?M:fn($e?.modes?.[0]?.key);await X({tunnelProvider:ue,tunnelMode:Je}),we(ue)},[K,we,X,M]),ze=o.useCallback(async()=>{const ue=await bc({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ue.success&&typeof ue.path=="string"&&ue.path.trim().length>0){const $e=ue.path.trim();if(!ga($e)){_.error(ke);return}z($e),await X({managedLocalTunnelConfigPath:$e});return}Pe.current?.click()},[ke,X]),Ge=o.useCallback(ue=>{const $e=ue.trim();z($e.length>0?$e:null)},[]),rt=o.useCallback(async()=>{if(A&&!ga(A)){_.error(ke);return}await X({managedLocalTunnelConfigPath:A})},[ke,A,X]),it=o.useCallback(async()=>{z(null),await X({managedLocalTunnelConfigPath:null})},[X]),at=o.useCallback(async ue=>{const $e=ue.target.files?.[0];if(!$e)return;const Je=$e.name.trim();if(Je.length!==0){if(!ga(Je)){_.error(ke);return}z(Je),await X({managedLocalTunnelConfigPath:Je}),ue.target.value=""}},[ke,X]),lt=o.useCallback(async()=>{if(d(null),h(null),M==="managed-local"&&A&&!ga(A)){d(ke),_.error(ke);return}r("starting");try{let ue="",$e="";if(M==="managed-remote"){if(!Te){r("idle"),h(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),_.error(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}ue=Te.hostname,$e=(W[Te.id]||"").trim(),await X({tunnelMode:"managed-remote",managedRemoteTunnelPresets:T})}const Je=await dt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:k,mode:M,...M==="managed-remote"&&Te?{managedRemoteTunnelPresetId:Te.id,managedRemoteTunnelPresetName:Te.name}:{},...M==="managed-remote"&&ue?{managedRemoteTunnelHostname:ue}:{},...M==="managed-remote"&&$e?{managedRemoteTunnelToken:$e}:{},...M==="managed-local"&&A?{configPath:A}:{}})}),qe=await Je.json();if(!Je.ok||!qe.ok){if(M==="managed-remote"&&typeof qe.error=="string"&&qe.error.includes("Managed remote tunnel token is required")){r("idle"),h(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),_.error(s("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),d(qe.error||s("settings.openchamber.tunnel.toast.startFailed")),_.error(qe.error||s("settings.openchamber.tunnel.toast.startFailed"));return}const yt=typeof qe.url=="string"?qe.url:"";if(!yt){r("error"),d(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),_.error(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:yt,connectUrl:typeof qe.connectUrl=="string"?qe.connectUrl:null,bootstrapExpiresAt:typeof qe.bootstrapExpiresAt=="number"?qe.bootstrapExpiresAt:null}),c(qe.activeTunnelMode?fn(qe.activeTunnelMode):qe.mode?fn(qe.mode):M),q(Array.isArray(qe.activeSessions)?qe.activeSessions:[]),Array.isArray(qe.managedRemoteTunnelTokenPresetIds)&&O(new Set(qe.managedRemoteTunnelTokenPresetIds)),typeof qe.localPort=="number"&&De(qe.localPort),typeof qe.mode=="string"&&S(fn(qe.mode)),r("active"),qe.replacedTunnel){const kt=typeof qe.revokedBootstrapCount=="number"?qe.revokedBootstrapCount:0,ht=typeof qe.invalidatedSessionCount=="number"?qe.invalidatedSessionCount:0;kt===1&&ht===1?_.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):kt===1?_.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ht})):ht===1?_.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:kt})):_.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:kt,invalidatedSessionCount:ht}))}else _.success(s("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),d(s("settings.openchamber.tunnel.toast.startFailed")),_.error(s("settings.openchamber.tunnel.toast.startFailed"))}},[ke,T,X,Te,W,s,k,M,A]),Ye=o.useCallback(async()=>{r("stopping");try{await dt("/api/openchamber/tunnel/stop",{method:"POST"});const ue=await dt("/api/openchamber/tunnel/status");if(ue.ok){const $e=await ue.json();q(Array.isArray($e.activeSessions)?$e.activeSessions:[]),O(new Set(Array.isArray($e.managedRemoteTunnelTokenPresetIds)?$e.managedRemoteTunnelTokenPresetIds:[])),De(typeof $e.localPort=="number"?$e.localPort:null)}l(null),c(null),m(null),r("idle"),_.success(s("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),d(s("settings.openchamber.tunnel.toast.stopFailed")),_.error(s("settings.openchamber.tunnel.toast.stopFailed"))}},[s]),We=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),y(!0),_.success(s("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>y(!1),2e3)}catch{_.error(s("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[s,i?.connectUrl]),gt=o.useCallback(async ue=>{const $e=$a.find(Je=>Je.value===ue);$e&&(ge($e.ms),await j($e.ms,ve))},[j,ve]),me=o.useCallback(async ue=>{const $e=Va.find(Je=>Je.value===ue);!$e||$e.ms===null||(Ne($e.ms),await j(Ce,$e.ms))},[Ce,j]),et=o.useCallback(async ue=>{h(null),d(null),a!=="active"&&a!=="stopping"&&a!=="starting"&&r("idle"),await X({tunnelMode:ue,managedRemoteTunnelPresets:T})},[T,X,a]),nt=o.useCallback(async(ue,$e)=>{try{await wt({managedRemoteTunnelPresets:$e})}catch{_.error(s("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[s]),tt=o.useCallback(ue=>{const $e=T.find(Je=>Je.id===ue);$e&&(N($e.id),h(null),nt($e,T))},[T,nt]),ft=o.useCallback(async()=>{const ue=ie.trim(),$e=tr(se),Je=ae.trim();if(!ue){_.error(s("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!$e){_.error(s("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Je){_.error(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(T.some(kt=>kt.hostname===$e)){_.error(s("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const qe={id:Nb(),name:ue,hostname:$e},yt=[...T,qe];Z(yt),N(qe.id),te(kt=>({...kt,[qe.id]:!0})),B(kt=>({...kt,[qe.id]:Je})),h(null),H(!1),oe(""),xe(""),fe(""),await X({tunnelMode:"managed-remote",managedRemoteTunnelPresets:yt,managedRemoteTunnelPresetTokens:{...W,[qe.id]:Je}}),await be({presetId:qe.id,presetName:qe.name,hostname:qe.hostname,token:Je}),_.success(s("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[T,se,ie,ae,be,X,W,s]),bt=o.useCallback(async ue=>{const $e=T.find(ht=>ht.id===ue);if(!$e)return;const Je=T.filter(ht=>ht.id!==$e.id),qe=Je[0]?.id||"",yt=Y===$e.id?qe:Y,kt=Object.fromEntries(Object.entries(W).filter(([ht,Et])=>ht!==$e.id&&Et.trim().length>0));Z(Je),N(yt),te(ht=>{const Et={...ht};return delete Et[$e.id],Et}),B(ht=>{const Et={...ht};return delete Et[$e.id],Et}),O(ht=>{const Et=new Set(ht);return Et.delete($e.id),Et}),h(null),await X({managedRemoteTunnelPresets:Je,managedRemoteTunnelPresetTokens:kt}),_.success(s("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[T,X,Y,W,s]),Rt="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")})]}),Ve.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(D,{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:Ve.map(ue=>{const $e=ue.mode==="quick",Je=ue.mode==="managed-remote",qe=$e?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Je?"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)]",yt=ue.isActive?$e?"text-[var(--status-warning)]":Je?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",kt=s($e?"settings.openchamber.tunnel.badge.quick":Je?"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(D,{name:"checkbox-blank-circle-fill",className:ce("size-2.5 shrink-0",yt)}),t.jsx("span",{className:ce("typography-micro rounded border px-1.5 py-0.5 uppercase",qe),children:kt}),t.jsx("span",{className:"typography-meta text-muted-foreground/80",children:s("settings.openchamber.tunnel.session.redeemedAt",{time:jb(ue.createdAt,e)})}),t.jsx("span",{className:"typography-meta text-foreground",children:ue.isActive?s("settings.openchamber.tunnel.session.expiresIn",{remaining:ue.remainingTextForSession}):ue.inactiveLabel===s("settings.openchamber.tunnel.state.inactive")?s("settings.openchamber.tunnel.state.inactive"):s("settings.openchamber.tunnel.session.inactiveWithReason",{reason:ue.inactiveLabel})})]},ue.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(D,{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:le.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:le.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(Pt,{value:k,onValueChange:ue=>{Ae(ue)},disabled:C||a==="starting"||a==="stopping",children:[t.jsx(At,{className:"max-w-[16rem]",children:t.jsx(Lt,{placeholder:s("settings.openchamber.tunnel.field.providerPlaceholder"),children:qc(k)})}),t.jsxs(Dt,{children:[K.length>0?K.map(ue=>t.jsx(ut,{value:ue.provider,children:t.jsx(Rl,{provider:ue.provider})},ue.provider)):t.jsx(ut,{value:"cloudflare",children:t.jsx(Rl,{provider:"cloudflare"})}),t.jsx(ut,{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:Fe.map(ue=>t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(J,{variant:"chip",size:"xs","aria-pressed":M===ue.value,className:"!font-normal",onClick:()=>{et(ue.value)},disabled:C||a==="starting"||a==="stopping",children:n(ue.labelKey)})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:n(ue.tooltipKey)})]},ue.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(Pt,{value:Ni($a,Ce,"1800000"),onValueChange:ue=>{gt(ue)},disabled:P||C||a==="starting"||a==="stopping",children:[t.jsx(At,{className:"max-w-[11rem] min-w-0",children:t.jsx(Lt,{className:"truncate",children:Fl($a,Ce,"1800000")})}),t.jsx(Dt,{children:$a.map(ue=>t.jsx(ut,{value:ue.value,children:ue.label},ue.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(Pt,{value:Ni(Va,ve,"28800000"),onValueChange:ue=>{me(ue)},disabled:P||C||a==="starting"||a==="stopping",children:[t.jsx(At,{className:"max-w-[11rem] min-w-0",children:t.jsx(Lt,{className:"truncate",children:Fl(Va,ve,"28800000")})}),t.jsx(Dt,{children:Va.map(ue=>t.jsx(ut,{value:ue.value,children:ue.label},ue.value))})]})]})]}),M==="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(D,{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")}),V&&t.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:s("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),M==="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 Ke=="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:",Ke]})]})}),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:()=>H(ue=>!ue),disabled:a==="starting"||a==="stopping"||C,children:[t.jsx(D,{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((ue,$e)=>{const Je=W[ue.id]||"",qe=F.has(ue.id),yt=G[ue.id]??!1;return t.jsx("div",{className:ce($e<T.length-1&&"border-b border-[var(--surface-subtle)]"),children:t.jsxs(En,{open:yt,onOpenChange:kt=>{te(ht=>({...ht,[ue.id]:kt})),kt&&tt(ue.id)},className:"py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-2 px-3",children:[t.jsxs(Mn,{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"||C,children:[yt?t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):t.jsx(D,{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:ue.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:ue.name}),onClick:()=>{bt(ue.id)},disabled:a==="starting"||a==="stopping"||C,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(Tn,{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:ue.hostname})]}),t.jsx(Xe,{type:"password",value:Je,onChange:kt=>{const ht=kt.target.value;h(null),B(Et=>({...Et,[ue.id]:ht}))},onBlur:kt=>{const ht=kt.currentTarget.value.trim();ht&&be({presetId:ue.id,presetName:ue.name,hostname:ue.hostname,token:ht})},placeholder:s(qe?"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"||Je.trim().length===0,onClick:()=>{be({presetId:ue.id,presetName:ue.name,hostname:ue.hostname,token:Je})},children:s("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},ue.id)})}):t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),Q&&t.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[t.jsx(Xe,{value:ie,onChange:ue=>oe(ue.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:C||a==="starting"||a==="stopping"}),t.jsx(Xe,{value:se,onChange:ue=>xe(ue.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:C||a==="starting"||a==="stopping"}),t.jsx(Xe,{type:"password",value:ae,onChange:ue=>fe(ue.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:C||a==="starting"||a==="stopping"}),typeof Ke=="number"&&t.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[s("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",t.jsxs("code",{children:["http://localhost:",Ke]}),"."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ft()},disabled:C||a==="starting"||a==="stopping",children:s("settings.common.actions.saveChanges")}),t.jsx(J,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{H(!1),oe(""),xe(""),fe("")},disabled:C||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(St,{children:[t.jsx(Ct,{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(D,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!Te&&b&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b})]}),M==="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:Pe,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:ue=>{at(ue)}}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xe,{value:A||"",onChange:ue=>{Ge(ue.target.value)},onBlur:()=>{rt()},placeholder:s("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:a==="starting"||a==="stopping"||C}),t.jsx(J,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{ze()},disabled:a==="starting"||a==="stopping"||C,children:t.jsx(D,{name:"folder",className:"size-3.5"})}),A&&t.jsx(J,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{it()},disabled:a==="starting"||a==="stopping"||C,children:t.jsx(D,{name:"close",className:"size-3.5"})})]}),t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s(A?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Me&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ke})]})}),!Oe&&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(D,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),t.jsxs("div",{className:"space-y-1",children:[M==="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:()=>{pe(hb)},children:[s("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),t.jsx(D,{name:"external-link",className:"size-3.5"})]})]}),M==="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:()=>{pe(fb)},children:[s("settings.openchamber.tunnel.actions.openManagedLocalDocs"),t.jsx(D,{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(Qr.find(ue=>ue.value===M)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),M==="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(Pt,{value:Y||(T[0]?.id??""),onValueChange:ue=>{tt(ue)},disabled:C||a==="starting"||a==="stopping"||T.length<=1,children:[t.jsx(At,{children:t.jsx(Lt,{placeholder:s("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Te?.name})}),t.jsx(Dt,{fitContent:!0,children:T.map(ue=>t.jsx(ut,{value:ue.id,children:ue.name},ue.id))})]})]}),_e&&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(D,{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"||C||M==="managed-remote"&&!Te||M==="managed-local"&&Me,className:ce(Rt,a==="starting"&&"opacity-70"),children:a==="starting"?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"})," ",s("settings.openchamber.tunnel.actions.startingTunnel")]}):s("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Oe&&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})]}),Ue&&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:[f?t.jsx(D,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):t.jsx(D,{name:"file-copy",className:"size-3.5"}),s(f?"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?ne: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"||C||M==="managed-local"&&Me,className:Rt,children:[t.jsx(D,{name:"restart",className:"size-3.5"}),s("settings.openchamber.tunnel.actions.newConnectLink")]}),t.jsx(J,{size:"sm",variant:"ghost",onClick:Ye,disabled:a==="stopping"||C,className:"gap-2 text-[var(--status-error)]",children:a==="stopping"?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"})," ",s("settings.openchamber.tunnel.actions.stopping")]}):s("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),a==="error"&&g&&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:g}),t.jsx(J,{size:"sm",variant:"ghost",onClick:lt,children:s("settings.openchamber.tunnel.actions.retry")})]})]})},Jc=()=>{const{t:s}=st(),[e,n]=he.useState(""),[a,r]=he.useState(!0),[i,l]=he.useState(!1),u=Ie(d=>d.showOpenCodeUpdateNotifications),c=Ie(d=>d.setShowOpenCodeUpdateNotifications);he.useEffect(()=>{let d=!1;return(async()=>{try{const b=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!b.ok)return;const h=await b.json().catch(()=>null);if(d||!h)return;const f=typeof h.opencodeBinary=="string"?h.opencodeBinary.trim():"";n(f)}catch{}finally{d||r(!1)}})(),()=>{d=!0}},[]);const x=he.useCallback(async()=>{if(!(typeof window>"u")&&ns())try{const d=await bc();d.success&&d.path&&d.path.trim().length>0&&n(d.path.trim())}catch{}},[]),m=he.useCallback(async()=>{l(!0);try{const d=e.trim(),b=d.length>=2&&(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'"))?d.slice(1,-1).trim():d;await wt({opencodeBinary:b}),await Gn({message:s("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{l(!1)}},[s,e]),g=he.useCallback(d=>{c(d),wt({showOpenCodeUpdateNotifications:d})},[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(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(It,{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(Xe,{value:e,onChange:d=>n(d.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||!ns(),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(D,{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(xt,{checked:u,onChange:g,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")})})]})]})},Sb=[{id:"auto",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsAuto"},{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],Qc=()=>{const{t:s}=st(),e=he.useCallback($=>s($),[s]),n=ns()&&Zn(),a=Mi(),r=Ie($=>$.desktopWindowControlsPosition),i=Ie($=>$.setDesktopWindowControlsPosition),[l,u]=he.useState(!1),[c,x]=he.useState(!1),[m,g]=he.useState(""),[d,b]=he.useState(""),[h,f]=he.useState(!1),[y,P]=he.useState(null),[I,C]=he.useState(!0),[L,k]=he.useState(!1),[v,w]=he.useState(!1),[E,K]=he.useState(!1),[U,M]=he.useState(!1),[S,A]=he.useState(!1),[z,T]=he.useState(!1),[Z,G]=he.useState(!1),[te,Y]=he.useState(!1),[N,W]=he.useState(!1),[B,F]=he.useState(!1),[O,Q]=he.useState(null),[H,ie]=he.useState(null);he.useEffect(()=>{if(!n){C(!1);return}let $=!1;return(async()=>{try{const ee=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!ee.ok)throw new Error(s("settings.openchamber.desktopNetwork.error.loadFailed"));const de=await ee.json().catch(()=>null);if($)return;const De=de?.desktopLanAccessEnabled===!0,ke=typeof de?.desktopUiPassword=="string"?de.desktopUiPassword:"";u(De),x(De),g(ke),b(ke),f(de?.desktopLanAccessActive===!0),P(typeof de?.desktopLanAccessBlockedReason=="string"?de.desktopLanAccessBlockedReason:null),Q(null)}catch(ee){$||Q(ee instanceof Error?ee.message:s("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{$||C(!1)}})(),()=>{$=!0}},[n,s]),he.useEffect(()=>{if(!n){w(!1);return}let $=!1;return(async()=>{const ee=await qm();$||(w(ee?.supported===!0),K(ee?.enabled===!0))})(),()=>{$=!0}},[n]),he.useEffect(()=>{if(!n){A(!1);return}let $=!1;return(async()=>{const ee=await Jm();$||(A(ee?.supported===!0),T(ee?.enabled===!0))})(),()=>{$=!0}},[n]),he.useEffect(()=>{if(!n){Y(!1);return}let $=!1;return(async()=>{const ee=await Qm();$||(Y(ee?.supported===!0),W(ee?.enabled===!0))})(),()=>{$=!0}},[n]),he.useEffect(()=>{if(!n||!c){ie(null);return}let $=!1;return(async()=>{const ee=await yc();$||ie(ee)})(),()=>{$=!0}},[c,n]);const oe=c!==l||d!==m,se=he.useMemo(()=>{if(typeof window>"u")return null;const ee=ea()||window.location.href;let de=0;try{de=Number(new URL(ee).port)}catch{de=Number(window.location.port)}return Number.isFinite(de)&&de>0?de:null},[]),xe=c&&h&&H&&se?`http://${H}:${se}`:null,ae=c&&!d.trim(),fe=l&&!h&&y==="missing-password",Ce=I||L||!oe||ae,ge=he.useCallback(()=>{x($=>!$)},[]),ve=he.useCallback($=>{b($),$.trim()||x(!1)},[]),Ne=he.useCallback($=>{i($),wt({desktopWindowControlsPosition:$})},[i]),ne=he.useCallback(async()=>{if(!v||U)return;const $=!E;K($),M(!0),Q(null);try{const ee=await Ym($);if(!ee?.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));K(ee.enabled)}catch(ee){K(!$),Q(ee instanceof Error?ee.message:s("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{M(!1)}},[U,E,v,s]),re=he.useCallback(async()=>{if(!S||Z)return;const $=!z;T($),G(!0),Q(null);try{const ee=await Xm($);if(!ee)throw new Error(s("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!ee.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));T(ee.enabled)}catch(ee){T(!$),Q(ee instanceof Error?ee.message:s("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{G(!1)}},[Z,z,S,s]),ye=he.useCallback(async()=>{if(!te||B)return;const $=!N;W($),F(!0),Q(null);try{const ee=await Zm($);if(!ee?.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));W(ee.enabled)}catch(ee){W(!$),Q(ee instanceof Error?ee.message:s("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{F(!1)}},[B,N,te,s]),q=he.useCallback(async()=>{if(oe){k(!0),Q(null);try{if(!(await dt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:c,desktopUiPassword:d})})).ok)throw new Error(s("settings.openchamber.desktopNetwork.error.saveFailed"));if(u(c),g(d),!await ep())throw new Error(s("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch($){Q($ instanceof Error?$.message:s("settings.openchamber.desktopNetwork.error.saveFailed")),k(!1)}}},[d,c,oe,s]);return!n&&!a?null:t.jsxs("div",{className:"mb-8",children:[a?t.jsxs(t.Fragment,{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.field.windowControlsPosition")})}),t.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:t.jsxs("div",{"data-settings-item":"sessions.desktop-window-controls-position",className:"space-y-1 py-1.5",children:[t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription")}),t.jsx("div",{className:"mt-1 flex flex-wrap items-center gap-1",role:"group","aria-label":s("settings.openchamber.desktopNetwork.field.windowControlsPositionAria"),children:Sb.map($=>{const ee=r===$.id;return t.jsx(J,{type:"button",variant:"outline",size:"xs",className:ce("!font-normal",ee?"border-[var(--primary-base)] text-[var(--primary-base)] bg-[var(--primary-base)]/10":"text-foreground"),"aria-pressed":ee,onClick:()=>Ne($.id),children:e($.labelKey)},$.id)})})]})})]}):null,n?t.jsxs(t.Fragment,{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:[v?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:ne,onKeyDown:$=>{($.key==="Enter"||$.key===" ")&&($.preventDefault(),ne())},children:[t.jsx(xt,{checked:E,onChange:ne,ariaLabel:s("settings.openchamber.desktopNetwork.field.launchAtLoginAria"),disabled:U}),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,S?t.jsxs("div",{"data-settings-item":"sessions.desktop-minimize-to-tray",className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:re,onKeyDown:$=>{($.key==="Enter"||$.key===" ")&&($.preventDefault(),re())},children:[t.jsx(xt,{checked:z,onChange:re,ariaLabel:s("settings.openchamber.desktopNetwork.field.minimizeToTrayAria"),disabled:Z}),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.minimizeToTray")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription")})]})]}):null,te?t.jsxs("div",{"data-settings-item":"sessions.desktop-keep-awake",className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:ye,onKeyDown:$=>{($.key==="Enter"||$.key===" ")&&($.preventDefault(),ye())},children:[t.jsx(xt,{checked:N,onChange:ye,ariaLabel:s("settings.openchamber.desktopNetwork.field.keepAwakeAria"),disabled:B}),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.keepAwake")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.keepAwakeDescription")})]})]}):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(Xe,{id:"desktop-ui-password",type:"password",className:"h-7 max-w-sm",value:d,onChange:$=>ve($.target.value),placeholder:s("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:I||L,required:c,"aria-invalid":ae}),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:ge,onKeyDown:$=>{($.key==="Enter"||$.key===" ")&&($.preventDefault(),ge())},children:[t.jsx(xt,{checked:c,onChange:ge,ariaLabel:s("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:I||L}),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")}),ae||fe?t.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:s("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]})]}),O?t.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:O}):null,xe?t.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[s(oe&&!l?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),t.jsx("span",{className:"font-mono text-foreground",children:xe})]}):null,t.jsx("div",{className:"flex justify-start py-1.5",children:t.jsx(J,{type:"button",size:"xs",onClick:q,disabled:Ce,className:"shrink-0 !font-normal",children:s(L?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null]})},Cb=new Set(["shift","control","alt","meta"]),Ib=s=>{if(Cb.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=fm(s.key);return n?(e.push(n),Bn(e.join("+"))):null},Pb=()=>{const s=Ze.c(61),{t:e}=st();let n;s[0]!==e?(n=se=>e(se),s[0]=e,s[1]=n):n=s[1];const a=n,r=Ie(Ab),i=Ie(Db),l=Ie(Eb),u=Ie(Mb);let c;if(s[2]===Symbol.for("react.memo_cache_sentinel")){e:{const se=gm();if(!rs()){c=se;break e}c=se.filter(Tb)}s[2]=c}else c=s[2];const x=c;let m;s[3]!==a?(m=(se,xe)=>{const ae=`settings.openchamber.keyboardShortcuts.action.${se}.label`,fe=a(ae);return fe===ae?xe:fe},s[3]=a,s[4]=m):m=s[4];const g=m,[d,b]=o.useState(null);let h;s[5]===Symbol.for("react.memo_cache_sentinel")?(h={},s[5]=h):h=s[5];const[f,y]=o.useState(h),[P,I]=o.useState(""),[C,L]=o.useState(""),[k,v]=o.useState(null),w=Rb;let E;s[6]!==r?(E=(se,xe)=>{const ae=Bn(xe);for(const fe of x){if(fe.id===se)continue;const Ce=Zi(fe.id,r);if(Bn(Ce)===ae)return fe.id}return null},s[6]=r,s[7]=E):E=s[7];const K=E;let U;s[8]!==K||s[9]!==i||s[10]!==r||s[11]!==e?(U=(se,xe)=>{const ae=Bn(xe),fe=K(se,ae);if(fe){v({actionId:se,combo:ae,conflictActionId:fe}),I("");return}const Ce={...r,[se]:ae};i(se,ae),w(Ce),v(null),I(""),L(eo(ae)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),y(ge=>{const ve={...ge};return delete ve[se],ve})},s[8]=K,s[9]=i,s[10]=r,s[11]=e,s[12]=U):U=s[12];const M=U;let S;s[13]!==k||s[14]!==i||s[15]!==r||s[16]!==e?(S=()=>{if(!k)return;const se={...r,[k.conflictActionId]:to,[k.actionId]:k.combo};i(k.conflictActionId,to),i(k.actionId,k.combo),w(se),v(null),I(""),L(eo(k.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),y(xe=>{const ae={...xe};return delete ae[k.actionId],ae})},s[13]=k,s[14]=i,s[15]=r,s[16]=e,s[17]=S):S=s[17];const A=S;let z;s[18]!==l||s[19]!==r?(z=se=>{const xe={...r};delete xe[se],l(se),w(xe),y(ae=>{const fe={...ae};return delete fe[se],fe}),v(null),I(""),L("")},s[18]=l,s[19]=r,s[20]=z):z=s[20];const T=z;let Z;s[21]!==e?(Z=e("settings.openchamber.keyboardShortcuts.title"),s[21]=e,s[22]=Z):Z=s[22];let G;s[23]!==Z?(G=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:Z}),s[23]=Z,s[24]=G):G=s[24];let te;s[25]!==u?(te=()=>{u(),w({}),y({}),v(null),I(""),L("")},s[25]=u,s[26]=te):te=s[26];let Y;s[27]!==e?(Y=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),s[27]=e,s[28]=Y):Y=s[28];let N;s[29]!==te||s[30]!==Y?(N=t.jsx(J,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:te,children:Y}),s[29]=te,s[30]=Y,s[31]=N):N=s[31];let W;s[32]===Symbol.for("react.memo_cache_sentinel")?(W=t.jsx(Ct,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[32]=W):W=s[32];let B;s[33]!==e?(B=e("settings.openchamber.keyboardShortcuts.tooltip"),s[33]=e,s[34]=B):B=s[34];let F;s[35]!==B?(F=t.jsxs(St,{children:[W,t.jsx(It,{sideOffset:8,className:"max-w-xs",children:B})]}),s[35]=B,s[36]=F):F=s[36];let O;s[37]!==N||s[38]!==F||s[39]!==G?(O=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[G,N,F]})}),s[37]=N,s[38]=F,s[39]=G,s[40]=O):O=s[40];let Q;s[41]!==A||s[42]!==P||s[43]!==k||s[44]!==e||s[45]!==C?(Q=(P||C||k)&&t.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[k&&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:A,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),t.jsx(J,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>v(null),children:e("settings.common.actions.cancel")})]})]}),P&&t.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:P}),C&&t.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:C})]}),s[41]=A,s[42]=P,s[43]=k,s[44]=e,s[45]=C,s[46]=Q):Q=s[46];let H;s[47]!==g||s[48]!==d||s[49]!==f||s[50]!==T||s[51]!==M||s[52]!==r||s[53]!==e?(H=x.map((se,xe)=>{const ae=Zi(se.id,r),fe=f[se.id],Ce=fe??ae,ge=typeof fe=="string"&&Bn(fe)!==Bn(ae);return t.jsxs("div",{className:ce("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:g(se.id,se.label)})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsx(Xe,{readOnly:!0,value:d===se.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):hm(Ce),onFocus:()=>{b(se.id),I("")},onBlur:()=>{d===se.id&&b(null)},onKeyDown:ve=>{if(ve.preventDefault(),ve.stopPropagation(),ve.key==="Escape"){b(null);return}const Ne=Ib(ve);Ne&&(y(ne=>({...ne,[se.id]:Ne})),b(null),v(null),I(""))},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 ve=f[se.id];if(!ve){I(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}M(se.id,ve)},disabled:!ge,children:e("settings.common.actions.saveChanges")}),t.jsx(J,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>T(se.id),children:e("settings.common.actions.reset")})]})]},se.id)}),s[47]=g,s[48]=d,s[49]=f,s[50]=T,s[51]=M,s[52]=r,s[53]=e,s[54]=H):H=s[54];let ie;s[55]!==H?(ie=t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:H}),s[55]=H,s[56]=ie):ie=s[56];let oe;return s[57]!==O||s[58]!==Q||s[59]!==ie?(oe=t.jsxs("div",{"data-settings-item":"shortcuts.keyboard-shortcuts",className:"mb-8",children:[O,Q,ie]}),s[57]=O,s[58]=Q,s[59]=ie,s[60]=oe):oe=s[60],oe};function Ab(s){return s.shortcutOverrides}function Db(s){return s.setShortcutOverride}function Eb(s){return s.clearShortcutOverride}function Mb(s){return s.resetAllShortcutOverrides}function Tb(s){return s.id!=="toggle_prompt_navigator"}function Rb(s){wt({shortcutOverrides:s})}const Yc=()=>{const s=Ze.c(2),[e,n]=o.useState(0);let a,r;return s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>tp(()=>n(Hb)),r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),o.useEffect(a,r),e},Fb=s=>{const e=Ze.c(20),{section:n}=s,{isMobile:a}=Ms();Yc();let r;e[0]!==a?(r=a&&An(),e[0]=a,e[1]=r):r=e[1];const i=r;let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=rs(),e[2]=l):l=e[2];const u=l;let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=ns()&&(Zn()||Mi()),e[3]=c):c=e[3];const x=c;if(!n){let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(Fi,{}),e[4]=h):h=e[4];let f,y,P;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Wc,{})}),y=x&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Qc,{})}),P=!u&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Jc,{})}),e[5]=f,e[6]=y,e[7]=P):(f=e[5],y=e[6],P=e[7]);let I;e[8]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(_c,{})}),e[8]=I):I=e[8];let C;e[9]===Symbol.for("react.memo_cache_sentinel")?(C=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Hc,{})}),e[9]=C):C=e[9];let L;e[10]!==i?(L=i&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Nc,{})}),e[10]=i,e[11]=L):L=e[11];let k;return e[12]!==L?(k=t.jsx(Ht,{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:[h,f,y,P,I,C,L]})}),e[12]=L,e[13]=k):k=e[13],k}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return t.jsx(Ob,{});case"chat":return t.jsx(zb,{});case"sessions":return t.jsx(Kb,{});case"shortcuts":return t.jsx(Lb,{});case"git":return t.jsx(Ub,{});case"github":return t.jsx(Bb,{});case"notifications":return t.jsx($b,{});case"voice":return t.jsx(Vb,{});case"tunnel":return t.jsx(_b,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const g=m;let d;e[16]!==g?(d=g(),e[16]=g,e[17]=d):d=e[17];let b;return e[18]!==d?(b=t.jsx(Ht,{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:d})}),e[18]=d,e[19]=b):b=e[19],b},Lb=()=>{const s=Ze.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Pb,{}),s[0]=e):e=s[0],e},Ob=()=>{const s=Ze.c(3);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=rs(),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(Fi,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a,"fontSize","terminalFontSize","editorFontSize","fileEditorKeymap","spacing","inputBarOffset","expandedEditorToolbar",...n?[]:["terminalQuickKeys"],"reportUsage"]}),s[2]=r):r=s[2],r},zb=()=>{const s=Ze.c(2);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=rs(),s[0]=e):e=s[0];const n=e;let a;return s[1]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(Fi,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","messageTransport","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...n?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck"]}),s[1]=a):a=s[1],a},Kb=()=>{const s=Ze.c(7);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=rs(),s[0]=e):e=s[0];const n=e;Yc();let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=ns()&&(Zn()||Mi()),s[1]=a):a=s[1];const r=a;let i,l,u;s[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(Wc,{}),l=r&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Qc,{})}),u=!n&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Jc,{})}),s[2]=i,s[3]=l,s[4]=u):(i=s[2],l=s[3],u=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(_c,{})}),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,l,u,c,t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Hc,{})})]}),s[6]=x):x=s[6],x},Ub=()=>{const s=Ze.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx("div",{className:"space-y-6",children:t.jsx(Bc,{})}),s[0]=e):e=s[0],e},Bb=()=>{const s=Ze.c(1);if(rs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx($c,{}),s[0]=e):e=s[0],e},$b=()=>{const s=Ze.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(cb,{}),s[0]=e):e=s[0],e},Vb=()=>{const s=Ze.c(1);if(rs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(gb,{}),s[0]=e):e=s[0],e},_b=()=>{const s=Ze.c(1);if(rs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(kb,{}),s[0]=e):e=s[0],e};function Hb(s){return s+1}const Xc=[{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 Wn(s){const e=s.trim().toLowerCase();return Xc.find(n=>n.slug===e)??null}function Li(s){const e=(s??"").trim().toLowerCase();if(!e)return"home";const n=Wb[e];if(n)return n;const a=Wn(e);return a?a.slug:"home"}const Gb=[{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.dock-badge",page:"appearance",titleKey:"settings.openchamber.visual.field.dockBadge",descriptionKey:"settings.openchamber.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:s=>s.isMac},{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.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{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.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:s=>!s.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.openchamber.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:s=>!s.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.openchamber.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:s=>!s.isVSCode},{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.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{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.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{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.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck"]},{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.small-model",page:"sessions",titleKey:"settings.openchamber.defaults.smallModel.title",descriptionKey:"settings.openchamber.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{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-window-controls-position",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.openchamber.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:s=>s.isDesktop&&(s.isWindows||!s.isMac)},{id:"sessions.desktop-minimize-to-tray",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.openchamber.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows"],isAvailable:s=>s.isDesktopLocalOrigin&&s.isWindows},{id:"sessions.desktop-keep-awake",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.keepAwake",descriptionKey:"settings.openchamber.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],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","relay","devices","connect from anywhere"],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","additional headers","request headers","cloudflare access","service token"],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.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{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 Ol(s){return s.trim().toLocaleLowerCase()}function qb({query:s,runtimeCtx:e,visiblePageSlugs:n,t:a,getPageTitle:r}){const i=Ol(s);if(!i)return[];const l=n?new Set(n):null,u=i.split(/\s+/).filter(Boolean);return Gb.flatMap(c=>{if(l&&!l.has(c.page))return[];const x=Wn(c.page);if(!x||x.isAvailable&&!x.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const m=a(c.titleKey),g=c.descriptionKey?a(c.descriptionKey):null,d=Ol([m,g,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return u.every(b=>d.includes(b))?[{...c,title:m,description:g,pageTitle:r(c.page)}]:[]})}const ki=176,Si=280,zl=8,Zc="__openchamberSettingsDetail";function Xr(s){return Math.min(Si,Math.max(ki,s))}const Jb=["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"],Qb={icon:"chat-thread"},Yb="__add_provider__";function Xb(s,e){const n=rs(),a=!s&&An();return{isVSCode:n,isWeb:a,isDesktop:s,isMobile:e}}function Kl(s,e){return s.isAvailable?s.isAvailable(e):!0}function Ci(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function ha(s,e){const n=new Set(e);let a=s,r=1;for(;n.has(a);)a=`${s}-${r}`,r+=1;return a}function Zr(s){if(!Ci(s))return null;const e=s[Zc];if(!Ci(e))return null;const n=e.page,a=e.stage;return typeof n!="string"||a!=="page-content"?null:{page:Li(n),stage:a}}function Zb(){return typeof window>"u"||!Ci(window.history.state)?{}:window.history.state}function ed(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 Qb.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 ei=s=>{const e=Ze.c(95),{onOpen:n}=s,{t:a}=st();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 l;e[4]!==a?(l=a("settings.view.home.description"),e[4]=a,e[5]=l):l=e[5];let u;e[6]!==l?(u=t.jsx("p",{className:"typography-ui text-muted-foreground",children:l}),e[6]=l,e[7]=u):u=e[7];let c;e[8]!==i||e[9]!==u?(c=t.jsxs("div",{className:"space-y-1",children:[i,u]}),e[8]=i,e[9]=u,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=ce("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 g;e[14]!==a?(g=a("settings.view.home.cards.providers.title"),e[14]=a,e[15]=g):g=e[15];let d;e[16]!==g?(d=t.jsx("div",{className:"typography-ui-label text-foreground",children:g}),e[16]=g,e[17]=d):d=e[17];let b;e[18]!==a?(b=a("settings.view.home.cards.providers.description"),e[18]=a,e[19]=b):b=e[19];let h;e[20]!==b?(h=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:b}),e[20]=b,e[21]=h):h=e[21];let f;e[22]!==h||e[23]!==x||e[24]!==d?(f=t.jsxs("button",{type:"button",onClick:x,className:m,children:[d,h]}),e[22]=h,e[23]=x,e[24]=d,e[25]=f):f=e[25];let y;e[26]!==n?(y=()=>n("agents"),e[26]=n,e[27]=y):y=e[27];let P;e[28]===Symbol.for("react.memo_cache_sentinel")?(P=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=P):P=e[28];let I;e[29]!==a?(I=a("settings.view.home.cards.agents.title"),e[29]=a,e[30]=I):I=e[30];let C;e[31]!==I?(C=t.jsx("div",{className:"typography-ui-label text-foreground",children:I}),e[31]=I,e[32]=C):C=e[32];let L;e[33]!==a?(L=a("settings.view.home.cards.agents.description"),e[33]=a,e[34]=L):L=e[34];let k;e[35]!==L?(k=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:L}),e[35]=L,e[36]=k):k=e[36];let v;e[37]!==y||e[38]!==C||e[39]!==k?(v=t.jsxs("button",{type:"button",onClick:y,className:P,children:[C,k]}),e[37]=y,e[38]=C,e[39]=k,e[40]=v):v=e[40];let w;e[41]!==n?(w=()=>n("skills.catalog"),e[41]=n,e[42]=w):w=e[42];let E;e[43]===Symbol.for("react.memo_cache_sentinel")?(E=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=E):E=e[43];let K;e[44]!==a?(K=a("settings.view.home.cards.skillsCatalog.title"),e[44]=a,e[45]=K):K=e[45];let U;e[46]!==K?(U=t.jsx("div",{className:"typography-ui-label text-foreground",children:K}),e[46]=K,e[47]=U):U=e[47];let M;e[48]!==a?(M=a("settings.view.home.cards.skillsCatalog.description"),e[48]=a,e[49]=M):M=e[49];let S;e[50]!==M?(S=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:M}),e[50]=M,e[51]=S):S=e[51];let A;e[52]!==w||e[53]!==U||e[54]!==S?(A=t.jsxs("button",{type:"button",onClick:w,className:E,children:[U,S]}),e[52]=w,e[53]=U,e[54]=S,e[55]=A):A=e[55];let z;e[56]!==n?(z=()=>n("mcp"),e[56]=n,e[57]=z):z=e[57];let T;e[58]===Symbol.for("react.memo_cache_sentinel")?(T=ce("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 Z;e[59]!==a?(Z=a("settings.view.home.cards.mcp.title"),e[59]=a,e[60]=Z):Z=e[60];let G;e[61]!==Z?(G=t.jsx("div",{className:"typography-ui-label text-foreground",children:Z}),e[61]=Z,e[62]=G):G=e[62];let te;e[63]!==a?(te=a("settings.view.home.cards.mcp.description"),e[63]=a,e[64]=te):te=e[64];let Y;e[65]!==te?(Y=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:te}),e[65]=te,e[66]=Y):Y=e[66];let N;e[67]!==z||e[68]!==G||e[69]!==Y?(N=t.jsxs("button",{type:"button",onClick:z,className:T,children:[G,Y]}),e[67]=z,e[68]=G,e[69]=Y,e[70]=N):N=e[70];let W;e[71]!==n?(W=()=>n("usage"),e[71]=n,e[72]=W):W=e[72];let B;e[73]===Symbol.for("react.memo_cache_sentinel")?(B=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=B):B=e[73];let F;e[74]!==a?(F=a("settings.view.home.cards.usage.title"),e[74]=a,e[75]=F):F=e[75];let O;e[76]!==F?(O=t.jsx("div",{className:"typography-ui-label text-foreground",children:F}),e[76]=F,e[77]=O):O=e[77];let Q;e[78]!==a?(Q=a("settings.view.home.cards.usage.description"),e[78]=a,e[79]=Q):Q=e[79];let H;e[80]!==Q?(H=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:Q}),e[80]=Q,e[81]=H):H=e[81];let ie;e[82]!==W||e[83]!==O||e[84]!==H?(ie=t.jsxs("button",{type:"button",onClick:W,className:B,children:[O,H]}),e[82]=W,e[83]=O,e[84]=H,e[85]=ie):ie=e[85];let oe;e[86]!==f||e[87]!==v||e[88]!==A||e[89]!==N||e[90]!==ie?(oe=t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[f,v,A,N,ie]}),e[86]=f,e[87]=v,e[88]=A,e[89]=N,e[90]=ie,e[91]=oe):oe=e[91];let se;return e[92]!==oe||e[93]!==c?(se=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,oe]})}),e[92]=oe,e[93]=c,e[94]=se):se=e[94],se},ev=s=>{const e=Ze.c(128),{onClose:n,forceMobile:a,isWindowed:r,visiblePageSlugs:i,initialMobileStage:l}=s,u=l===void 0?"nav":l,{t:c}=st(),x=Ms(),m=a??x.isMobile,g=Ie(tv),d=Ie(sv),b=Ie(nv);let h;e[0]!==g?(h=Li(g),e[0]=g,e[1]=h):h=e[1];const f=h,[y,P]=o.useState(u),I=o.useRef(null),[C,L]=o.useState(216),[k,v]=o.useState(""),[w,E]=o.useState(null),[K,U]=o.useState(0),[M,S]=o.useState(!1),[A,z]=o.useState(!1),T=o.useRef(0),Z=o.useRef(C),G=o.useRef(null);let te;e[2]===Symbol.for("react.memo_cache_sentinel")?(te=[],e[2]=te):te=e[2];const Y=o.useRef(te),N=o.useRef(0),W=o.useRef(!1);let B;e[3]===Symbol.for("react.memo_cache_sentinel")?(B=ns(),e[3]=B):B=e[3];const F=B;let O;e[4]===Symbol.for("react.memo_cache_sentinel")?(O=ns()&&Zn(),e[4]=O):O=e[4];const Q=O;let H;e[5]===Symbol.for("react.memo_cache_sentinel")?(H=ns()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",e[5]=H):H=e[5];const ie=H;let oe;e[6]===Symbol.for("react.memo_cache_sentinel")?(oe=ns()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",e[6]=oe):oe=e[6];const se=oe;let xe;e[7]!==m?(xe=Xb(F,m),e[7]=m,e[8]=xe):xe=e[8];const ae=xe;let fe;if(e[9]!==m||e[10]!==ae||e[11]!==i){const ct=i?new Set(i):null;let pt;e[13]!==ae?(pt=Yt=>Kl(Yt,ae),e[13]=ae,e[14]=pt):pt=e[14];let Nt;e[15]!==ae.isVSCode?(Nt=Yt=>!(ae.isVSCode&&Yt.slug==="projects"),e[15]=ae.isVSCode,e[16]=Nt):Nt=e[16];let Xt;e[17]!==m?(Xt=Yt=>!(m&&Yt.slug==="shortcuts"),e[17]=m,e[18]=Xt):Xt=e[18],fe=Xc.filter(av).filter(Yt=>!ct||ct.has(Yt.slug)).filter(pt).filter(Nt).filter(Xt),e[9]=m,e[10]=ae,e[11]=i,e[12]=fe}else fe=e[12];const Ce=fe;let ge;e[19]===Symbol.for("react.memo_cache_sentinel")?(ge=new Map(Jb.map(rv)),e[19]=ge):ge=e[19];const ve=ge;let Ne;if(e[20]!==Ce){let ct;e[22]===Symbol.for("react.memo_cache_sentinel")?(ct=(pt,Nt)=>(ve.get(pt.slug)??999)-(ve.get(Nt.slug)??999),e[22]=ct):ct=e[22],Ne=Ce.slice().sort(ct),e[20]=Ce,e[21]=Ne}else Ne=e[21];const ne=Ne,re=es(iv);let ye,q;e[23]!==M?(ye=()=>{if(typeof window>"u")return;const ct=()=>{if(!M){const pt=Xr(Math.floor(window.innerWidth*.12));L(pt)}};return window.addEventListener("resize",ct),()=>window.removeEventListener("resize",ct)},q=[M],e[23]=M,e[24]=ye,e[25]=q):(ye=e[24],q=e[25]),o.useEffect(ye,q);let $,ee;e[26]!==A?($=()=>{if(!A)return;const ct=Nt=>{const Xt=Nt.clientX-T.current,Yt=Xr(Z.current+Xt);L(Yt),S(!0)},pt=()=>z(!1);return window.addEventListener("pointermove",ct),window.addEventListener("pointerup",pt,{once:!0}),()=>{window.removeEventListener("pointermove",ct),window.removeEventListener("pointerup",pt)}},ee=[A],e[26]=A,e[27]=$,e[28]=ee):($=e[27],ee=e[28]),o.useEffect($,ee);let de;e[29]!==C?(de=ct=>{z(!0),T.current=ct.clientX,Z.current=C,ct.preventDefault()},e[29]=C,e[30]=de):de=e[30];const De=de;let ke;e[31]!==C?(ke=ct=>{const pt=ct.shiftKey?zl*4:zl;let Nt;e:switch(ct.key){case"ArrowLeft":{Nt=C-pt;break e}case"ArrowRight":{Nt=C+pt;break e}case"Home":{Nt=ki;break e}case"End":{Nt=Si;break e}default:return}ct.preventDefault(),L(Xr(Nt)),S(!0)},e[31]=C,e[32]=ke):ke=e[32];const Pe=ke;let Me;e[33]!==d||e[34]!==r||e[35]!==ae.isVSCode||e[36]!==f?(Me=()=>{if(!(!d&&!ae.isVSCode&&!r)){if(f==="agents"){ur.getState().loadAgents();return}if(f==="commands"){mr.getState().loadCommands();return}if(f==="mcp"){Yn.getState().loadMcpConfigs();return}if(f==="plugins"){ls.getState().loadPlugins();return}(f==="skills.installed"||f==="skills.catalog")&&(an.getState().loadSkills(),sn.getState().loadCatalog()),f==="snippets"&&gr.getState().loadSnippets()}},e[33]=d,e[34]=r,e[35]=ae.isVSCode,e[36]=f,e[37]=Me):Me=e[37];let Te;e[38]!==re||e[39]!==d||e[40]!==r||e[41]!==ae.isVSCode||e[42]!==f?(Te=[re,d,r,ae.isVSCode,f],e[38]=re,e[39]=d,e[40]=r,e[41]=ae.isVSCode,e[42]=f,e[43]=Te):Te=e[43],o.useEffect(Me,Te);let Ve;e[44]!==m||e[45]!==b?(Ve=ct=>{if(b(ct),I.current=ct,!m)return;const pt=Wn(ct);if(!pt||pt.slug==="home"){P("nav");return}P(pt.kind==="split"?"page-sidebar":"page-content")},e[44]=m,e[45]=b,e[46]=Ve):Ve=e[46];const Ue=Ve;let Oe;e[47]!==f?(Oe=Wn(f),e[47]=f,e[48]=Oe):Oe=e[48];const _e=Oe;let Ke;e[49]===Symbol.for("react.memo_cache_sentinel")?(Ke={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[49]=Ke):Ke=e[49];const Qe=Ke;let Fe;e[50]!==c?(Fe=ct=>{switch(ct){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[50]=c,e[51]=Fe):Fe=e[51];const V=Fe;let le;e[52]!==V||e[53]!==ae||e[54]!==k||e[55]!==c||e[56]!==i?(le=qb({query:k,runtimeCtx:{...ae,isDesktopLocalOrigin:Q,isMac:ie,isWindows:se},visiblePageSlugs:i,t:c,getPageTitle:V}),e[52]=V,e[53]=ae,e[54]=k,e[55]=c,e[56]=i,e[57]=le):le=e[57];const pe=le,Le=mv;let we;if(e[58]!==pe){we=[];const ct=new Map;for(const pt of pe){let Nt=ct.get(pt.page);Nt||(Nt={page:pt.page,pageTitle:pt.pageTitle,results:[]},ct.set(pt.page,Nt),we.push(Nt)),Nt.results.push(pt)}e[58]=pe,e[59]=we}else we=e[59];const He=we;let X;e[60]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{U(0),N.current=0,W.current=!1},e[60]=X):X=e[60];let j;e[61]!==k?(j=[k],e[61]=k,e[62]=j):j=e[62],o.useEffect(X,j);let be,Ae;e[63]!==K?(be=()=>{N.current=K},Ae=[K],e[63]=K,e[64]=be,e[65]=Ae):(be=e[64],Ae=e[65]),o.useEffect(be,Ae);let ze,Ge;e[66]!==K?(ze=()=>{Y.current[K]?.scrollIntoView({block:"nearest"})},Ge=[K],e[66]=K,e[67]=ze,e[68]=Ge):(ze=e[67],Ge=e[68]),o.useEffect(ze,Ge);let rt,it;e[69]!==K||e[70]!==pe.length?(rt=()=>{K>=pe.length&&U(Math.max(0,pe.length-1)),Y.current.length=pe.length},it=[K,pe.length],e[69]=K,e[70]=pe.length,e[71]=rt,e[72]=it):(rt=e[71],it=e[72]),o.useEffect(rt,it);let at;e[73]!==m||e[74]!==Ue?(at=ct=>{const pt=Le(ct);E(pt),Ue(ct.page),m&&P("page-content"),ct.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(pv,50)},e[73]=m,e[74]=Ue,e[75]=at):at=e[75];const lt=at;let Ye;e[76]!==lt||e[77]!==k||e[78]!==pe?(Ye=ct=>{if(k.trim()){if(ct.key==="Escape"){ct.preventDefault(),v("");return}if(pe.length!==0){if(ct.key==="ArrowDown"){ct.preventDefault(),W.current=!0,U(pt=>(pt+1)%pe.length);return}if(ct.key==="ArrowUp"){ct.preventDefault(),W.current=!0,U(pt=>(pt-1+pe.length)%pe.length);return}if(ct.key==="Enter"){ct.preventDefault();const pt=(N.current%pe.length+pe.length)%pe.length,Nt=pe[pt]??pe[0];Nt&&lt(Nt)}}}},e[76]=lt,e[77]=k,e[78]=pe,e[79]=Ye):Ye=e[79];const We=Ye;let gt;e[80]!==w?(gt=()=>{const ct=w;if(!ct)return;let pt=!1;const Nt=window.requestAnimationFrame(()=>{if(pt)return;const Xt=typeof CSS<"u"&&CSS.escape?CSS.escape(ct):ct.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Yt=G.current?.querySelector(`[data-settings-item="${Xt}"]`);Yt&&(E(null),Yt.scrollIntoView({block:"center",behavior:"smooth"}),Yt.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Yt.removeAttribute("data-settings-search-highlight")},1600))});return()=>{pt=!0,window.cancelAnimationFrame(Nt)}},e[80]=w,e[81]=gt):gt=e[81];let me;e[82]!==w||e[83]!==f?(me=[w,f],e[82]=w,e[83]=f,e[84]=me):me=e[84],o.useEffect(gt,me);let et;e[85]!==c?(et=()=>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[85]=c,e[86]=et):et=e[86];const nt=et,tt=gv;let ft;e[87]!==Ue||e[88]!==nt||e[89]!==ae?(ft=ct=>{const pt=Wn(ct);if(pt&&!Kl(pt,ae))return nt();switch(ct){case"home":return t.jsx(ei,{onOpen:Ue});case"projects":return t.jsx(ix,{});case"remote-instances":return t.jsx(Rx,{});case"agents":return t.jsx(ng,{});case"behavior":return t.jsx(lg,{});case"commands":return t.jsx(xg,{});case"mcp":return t.jsx(Gg,{});case"plugins":return t.jsx(Th,{});case"skills.installed":return t.jsx(il,{view:"installed"});case"skills.catalog":return t.jsx(il,{view:"catalog"});case"providers":return t.jsx(Vx,{});case"usage":return t.jsx(Ny,{});case"about":return t.jsx("div",{className:"h-full overflow-auto px-5 py-6",children:t.jsx(Nc,{})});case"magic-prompts":return t.jsx(Py,{});case"snippets":return t.jsx(Ty,{});case"git":return t.jsx(zy,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const Nt=Qe[ct]??"visual";return t.jsx(Fb,{section:Nt})}default:return t.jsx(ei,{onOpen:Ue})}},e[87]=Ue,e[88]=nt,e[89]=ae,e[90]=ft):ft=e[90];const bt=ft;let Rt,ue;e[91]!==m||e[92]!==y||e[93]!==f?(Rt=()=>{if(!m||y!=="nav"||f==="home"||I.current===f)return;const ct=Wn(f);!ct||ct.slug==="home"||(I.current=f,P(ct.kind==="split"?"page-sidebar":"page-content"))},ue=[m,y,f],e[91]=m,e[92]=y,e[93]=f,e[94]=Rt,e[95]=ue):(Rt=e[94],ue=e[95]),o.useEffect(Rt,ue);const $e=m&&y!=="nav",Je=m&&y==="page-content"&&f==="skills.installed",qe=y==="page-content"&&_e?.kind==="split"&&!Je;let yt;e[96]!==Je||e[97]!==$e||e[98]!==c?(yt=c(Je?"settings.view.actions.back":$e?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[96]=Je,e[97]=$e,e[98]=c,e[99]=yt):yt=e[99];const kt=yt,ht=xm();let Et;e[100]!==ae.isVSCode?(Et=ct=>{if(typeof window>"u"||ae.isVSCode)return;const pt=Zr(window.history.state);pt?.page===ct&&pt.stage==="page-content"||window.history.pushState({...Zb(),[Zc]:{page:ct,stage:"page-content"}},"",window.location.href)},e[100]=ae.isVSCode,e[101]=Et):Et=e[101];const Jt=Et;let Zt;e[102]!==Jt||e[103]!==f?(Zt=()=>{P("page-content"),f==="skills.installed"&&Jt(f)},e[102]=Jt,e[103]=f,e[104]=Zt):Zt=e[104];const cs=Zt;let is;e[105]!==Je||e[106]!==ae.isVSCode||e[107]!==f?(is=()=>{if(Je){if((typeof window<"u"?Zr(window.history.state):null)?.page===f&&!ae.isVSCode){window.history.back();return}P("page-sidebar");return}P("nav")},e[105]=Je,e[106]=ae.isVSCode,e[107]=f,e[108]=is):is=e[108];const ts=is;let As,Se;e[109]!==m||e[110]!==ae.isVSCode||e[111]!==f?(As=()=>{if(!m||ae.isVSCode)return;const ct=pt=>{if(f!=="skills.installed")return;if(Zr(pt.state)?.page==="skills.installed"){P("page-content");return}P(hv)};return window.addEventListener("popstate",ct),()=>{window.removeEventListener("popstate",ct)}},Se=[m,ae.isVSCode,f],e[109]=m,e[110]=ae.isVSCode,e[111]=f,e[112]=As,e[113]=Se):(As=e[112],Se=e[113]),o.useEffect(As,Se);let vt;e[114]===Symbol.for("react.memo_cache_sentinel")?(vt=()=>{P("page-sidebar")},e[114]=vt):vt=e[114];const jt=vt,Wt=()=>{const ct=k.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(D,{name:"search",className:"h-4 w-4 shrink-0"}),t.jsx("input",{value:k,onChange:pt=>v(pt.target.value),onKeyDown:We,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"}),ct&&t.jsx("button",{type:"button",onClick:()=>v(""),"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(D,{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:ct?pe.length>0?(()=>{let pt=0;return He.map(Nt=>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:Nt.pageTitle}),Nt.results.map(Xt=>{const Yt=pt;pt=pt+1;const cn=Yt===K,dn=!!Xt.description;return t.jsxs("button",{type:"button",ref:Sn=>{Y.current[Yt]=Sn},onMouseMove:()=>{W.current=!1,U(Yt)},onClick:()=>lt(Xt),className:ce("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",dn?"min-h-11 py-1.5":"py-2",cn?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Xt.title}),dn&&t.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:Xt.description})]},Xt.id)})]},Nt.page))})():t.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:c("settings.view.search.noResults")}):ne.map(pt=>{const Nt=f===pt.slug,Xt=ed(pt.slug);return!Xt&&pt.slug!=="mcp"?null:t.jsx(St,{children:t.jsx(Ct,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:()=>Ue(pt.slug),"aria-current":Nt?"page":void 0,className:ce("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",Nt?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[pt.slug==="mcp"?t.jsx(up,{className:"h-4 w-4 shrink-0"}):t.jsx(D,{name:Xt,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:V(pt.slug)}),pt.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")})]})]})})},pt.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:!ae.isVSCode&&t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsxs("button",{type:"button",className:ce("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:xv,children:[t.jsx(D,{name:"restart",className:"h-4 w-4 shrink-0"}),t.jsx("span",{children:c("settings.view.actions.reloadOpenCode")})]})}),t.jsx(It,{children:c("settings.view.actions.reloadOpenCodeTooltip")})]})})})]})},Gt=()=>{if(y==="nav")return t.jsx("div",{className:ce("flex-1 min-h-0 overflow-hidden",ae.isVSCode?"bg-background":"bg-sidebar"),children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:t.jsx(gn,{children:Wt()})})});if(!_e)return t.jsx("div",{className:"flex-1 bg-background"});if(y==="page-sidebar"){if(_e.kind!=="split"){const pt=bt(f);return t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(gn,{children:pt})})}return t.jsx("div",{className:ce("flex-1 min-h-0 overflow-hidden",ae.isVSCode?"bg-background":"bg-sidebar"),children:t.jsx(gn,{children:tt(f,{onItemSelect:cs})})})}const ct=bt(f);return t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(gn,{children:ct})})};let $t;e[115]!==_e||e[116]!==Ue||e[117]!==bt||e[118]!==ae.isVSCode||e[119]!==f?($t=()=>!_e||f==="home"?t.jsx(ei,{onOpen:Ue}):_e.kind==="split"?t.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[t.jsx("div",{className:ce("w-[264px] min-w-[264px] border-r",ae.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:t.jsx(gn,{children:tt(f,{})})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(gn,{children:bt(f)})})]}):t.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:t.jsx(gn,{children:bt(f)})}),e[115]=_e,e[116]=Ue,e[117]=bt,e[118]=ae.isVSCode,e[119]=f,e[120]=$t):$t=e[120];const fs=$t,ks="true";let Qt;e[121]===Symbol.for("react.memo_cache_sentinel")?(Qt=ce("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[121]=Qt):Qt=e[121];const Ts=m?t.jsxs("div",{className:ce("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:[$e||n?t.jsx("button",{type:"button",onClick:$e?ts:n,"aria-label":kt,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(D,{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:y==="nav"?c("settings.view.home.title"):_e?V(_e.slug):c("settings.view.home.title")}),qe&&t.jsx("button",{type:"button",onClick:jt,"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(D,{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:ht}),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(D,{name:"close",className:"h-5 w-5"})})]}):t.jsxs(t.Fragment,{children:[$e&&t.jsx("div",{className:ce("absolute left-3 z-50",r?"top-2":"top-3"),children:t.jsx("button",{type:"button",onClick:ts,"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(D,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&t.jsx("div",{className:ce("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:ht}),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(D,{name:"close",className:"h-5 w-5"})})})]}),kn="flex flex-1 min-h-0 overflow-hidden",Js=m?Gt():t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:ce("relative flex h-full min-h-0 flex-col overflow-hidden border-r",F?"bg-sidebar":ae.isVSCode?"bg-background":"bg-sidebar",A?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${C}px`,minWidth:`${C}px`,borderColor:"var(--interactive-border)"},children:[t.jsx("div",{className:ce("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)]",A?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:De,onKeyDown:Pe,role:"separator","aria-orientation":"vertical","aria-valuemin":ki,"aria-valuemax":Si,"aria-valuenow":C,"aria-label":c("settings.view.actions.resizeNavigation")}),t.jsx(gn,{children:Wt()})]}),t.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:fs()})]});let Rs;e[122]!==Js?(Rs=t.jsx("div",{className:kn,children:Js}),e[122]=Js,e[123]=Rs):Rs=e[123];let $s;return e[124]!==Qt||e[125]!==Ts||e[126]!==Rs?($s=t.jsxs("div",{ref:G,"data-settings-view":ks,className:Qt,children:[Ts,Rs]}),e[124]=Qt,e[125]=Ts,e[126]=Rs,e[127]=$s):$s=e[127],$s};function tv(s){return s.settingsPage}function sv(s){return s.isSettingsDialogOpen}function nv(s){return s.setSettingsPage}function av(s){return s.slug!=="home"}function rv(s,e){return[s,e]}function iv(s){return s.activeProjectId}function ov(s){return s.name}function lv(s){return s.name}function cv(s){return s.name}function dv(s){return s.name}function uv(s){return s.name}function mv(s){if(s.id.startsWith("agents.")){const e=ur.getState(),n=ha("new-agent",e.agents.map(ov));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=mr.getState(),n=ha("new-command",e.commands.map(lv));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=Yn.getState(),n=ha("new-mcp-server",e.mcpServers.map(cv));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=gr.getState(),n=ha("new-snippet",e.snippets.map(dv));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=an.getState(),n=ha("new-skill",e.skills.map(uv));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"&&ot.getState().setSelectedProvider(Yb),s.id==="plugins.create"?"plugins.spec":s.id}function pv(){window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))}function gv(s,e){switch(s){case"projects":return t.jsx(Of,{onItemSelect:e.onItemSelect});case"agents":return t.jsx(Yp,{onItemSelect:e.onItemSelect});case"commands":return t.jsx(cg,{onItemSelect:e.onItemSelect});case"mcp":return t.jsx(yg,{onItemSelect:e.onItemSelect});case"plugins":return t.jsx(jh,{onItemSelect:e.onItemSelect});case"skills.installed":return t.jsx(Fh,{onItemSelect:e.onItemSelect});case"providers":return t.jsx(Ox,{onItemSelect:e.onItemSelect});case"usage":return t.jsx(ty,{onItemSelect:e.onItemSelect});case"magic-prompts":return t.jsx(Sy,{onItemSelect:e.onItemSelect});case"snippets":return t.jsx(Ay,{onItemSelect:e.onItemSelect});default:return null}}function hv(s){return s==="page-content"?"page-sidebar":s}function fv(){}function xv(){Gn({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]}).catch(fv)}const nw=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:ev,getSettingsNavIcon:ed},Symbol.toStringTag,{value:"Module"})),yv=["chat","git","diff","terminal","files","diagram"],bv=["settings","agents","commands","skills","providers","usage","git-identities"],Os={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Ul(s){const e=vv();return{sessionId:jv(e),tab:wv(e),settingsPath:Nv(e),diffFile:kv(e)}}function vv(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function jv(s){const e=s.get(Os.SESSION);return!e||e.trim().length===0?null:e.trim()}function wv(s){const e=s.get(Os.TAB);if(!e)return null;const n=e.toLowerCase().trim();return yv.includes(n)?n:null}function Nv(s){const e=s.get(Os.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(bv.includes(n),n)}function kv(s){const e=s.get(Os.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Bl(){if(typeof window>"u")return!1;try{const s=new URLSearchParams(window.location.search);return s.has(Os.SESSION)||s.has(Os.TAB)||s.has(Os.SETTINGS)||s.has(Os.FILE)}catch{return!1}}const Sv="chat";function td(s){const e=new URLSearchParams;if(s.sessionId&&s.sessionId.trim().length>0&&e.set(Os.SESSION,s.sessionId),s.isSettingsOpen){const n=s.settingsPath.trim().length>0?s.settingsPath:"home";return e.set(Os.SETTINGS,n),e}return s.tab!==Sv&&e.set(Os.TAB,s.tab),s.tab==="diff"&&s.diffFile&&s.diffFile.trim().length>0&&e.set(Os.FILE,s.diffFile),e}function Cv(s,e){const n=typeof window<"u"?window.location.pathname:"/",a=s.toString();return a?`${n}?${a}`:n}function Iv(s){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=td(s),a=[...e.entries()].sort((i,l)=>i[0].localeCompare(l[0])),r=[...n.entries()].sort((i,l)=>i[0].localeCompare(l[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 $l(s,e={}){if(!(typeof window>"u")&&!(Pv()||hc())&&!(!e.force&&Iv(s)))try{const n=td(s),a=Cv(n);e.replace?window.history.replaceState({...window.history.state,route:s},"",a):window.history.pushState({route:s},"",a)}catch{}}function Pv(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function Av(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function aw(){const s=o.useMemo(()=>Av(),[]),e=o.useMemo(()=>hc(),[]),n=o.useRef(!1),a=o.useRef(!1),r=ys(d=>d.setCurrentSession),i=Ie(d=>d.setActiveMainTab),l=Ie(d=>d.setSettingsDialogOpen),u=Ie(d=>d.setSettingsPage),c=Ie(d=>d.navigateToDiff),x=o.useCallback(async d=>{if(!a.current){a.current=!0;try{if(d.sessionId){const b=ys.getState().currentSessionId;if(d.sessionId!==b){const h=ys.getState().getDirectoryForSession(d.sessionId);r(d.sessionId,h)}}if(d.settingsPath){u(Li(d.settingsPath)),l(!0);return}Ie.getState().isSettingsDialogOpen&&l(!1),d.tab&&i(d.tab),d.diffFile&&(d.tab==="diff"||!d.tab)&&c(d.diffFile)}finally{a.current=!1}}},[r,i,l,u,c]),m=o.useCallback(()=>{const d=ys.getState(),b=Ie.getState();return{sessionId:d.currentSessionId,tab:b.activeMainTab,isSettingsOpen:b.isSettingsDialogOpen,settingsPath:b.settingsPage,diffFile:b.pendingDiffFile}},[]),g=o.useCallback((d={})=>{if(s||e||a.current)return;const b=m();$l(b,d)},[s,e,m]);o.useEffect(()=>{if(n.current||(n.current=!0,!Bl()))return;const d=Ul();(async()=>(await x(d),!s&&!e&&$l({...m(),sessionId:d.sessionId??ys.getState().currentSessionId,tab:d.tab??Ie.getState().activeMainTab,settingsPath:d.settingsPath??Ie.getState().settingsPage,diffFile:d.diffFile??Ie.getState().pendingDiffFile},{replace:!0,force:!0})))()},[x,m,s,e]),o.useEffect(()=>{if(s||e)return;let d=ys.getState().currentSessionId;return ys.subscribe(h=>{const f=h.currentSessionId;f===d||a.current||(d=f,g())})},[s,e,g]),o.useEffect(()=>{if(s||e)return;let d=Ie.getState().activeMainTab,b=Ie.getState().isSettingsDialogOpen,h=Ie.getState().settingsPage,f=Ie.getState().pendingDiffFile;return Ie.subscribe(P=>{if(a.current)return;const I=P.activeMainTab!==d,C=P.isSettingsDialogOpen!==b,L=P.settingsPage!==h,k=P.pendingDiffFile!==f&&P.activeMainTab==="diff";d=P.activeMainTab,b=P.isSettingsDialogOpen,h=P.settingsPage,f=P.pendingDiffFile,(I||C||L||k)&&g()})},[s,e,g]),o.useEffect(()=>{if(typeof window>"u"||s||e)return;const d=()=>{const b=Ul();if(Bl())x(b);else{const h=Ie.getState();h.isSettingsDialogOpen&&l(!1),h.activeMainTab!=="chat"&&i("chat")}};return window.addEventListener("popstate",d),()=>{window.removeEventListener("popstate",d)}},[x,s,e,i,l])}function rw(){const s=Ze.c(5),e=wc(Ev),n=o.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]),o.useEffect(a,r);let i,l;s[3]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{let u=!1,c=null;const x=Dv,m=g=>{u||(c=window.setTimeout(async()=>{const d=await n.current(),b=typeof d=="number"&&Number.isFinite(d)?x(d):36e5;m(b)},g))};return m(3e3),()=>{u=!0,c!==null&&window.clearTimeout(c)}},l=[],s[3]=i,s[4]=l):(i=s[3],l=s[4]),o.useEffect(i,l)}function Dv(s){const e=Math.round(s*1e3);return Math.max(3e5,Math.min(864e5,e))}function Ev(s){return s.checkForUpdates}const sd={"?":{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"}},Mv=sd.M;function Tv(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 Rv(s){const e=Tv(s);return sd[e]??Mv}const Fv=o.memo(function(e){const n=Ze.c(58),{file:a,actionLabel:r,actionSymbol:i,onAction:l,onViewDiff:u,onRevert:c,isReverting:x,stats:m,rowPaddingClassName:g,indentPx:d,actionAtStart:b,showRevert:h}=e,f=d===void 0?0:d,y=b===void 0?!1:b,P=h===void 0?!0:h;let I;n[0]!==a?(I=Rv(a),n[0]=a,n[1]=I):I=n[1];const C=I,{t:L}=st(),k=C.description,v=m?.insertions??0,w=m?.deletions??0;let E;n[2]!==l||n[3]!==u?(E=fe=>{fe.key===" "?(fe.preventDefault(),l()):fe.key==="Enter"&&(fe.preventDefault(),u())},n[2]=l,n[3]=u,n[4]=E):E=n[4];const K=E;let U;n[5]!==l?(U=fe=>{fe.preventDefault(),fe.stopPropagation(),l()},n[5]=l,n[6]=U):U=n[6];const M=U;let S;n[7]!==c?(S=fe=>{fe.preventDefault(),fe.stopPropagation(),c()},n[7]=c,n[8]=S):S=n[8];const A=S;let z;n[9]!==r||n[10]!==i||n[11]!==M?(z=t.jsx("button",{type:"button",onClick:M,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]=M,n[12]=z):z=n[12];const T=z,Z=`group flex items-center gap-2 py-1.5 cursor-pointer ${g??"px-3"}`;let G;n[13]!==f?(G=f>0?{paddingLeft:`${f}px`}:void 0,n[13]=f,n[14]=G):G=n[14];const te=y?T:null;let Y;n[15]!==C.color?(Y={color:C.color},n[15]=C.color,n[16]=Y):Y=n[16];let N;n[17]!==C.code||n[18]!==k||n[19]!==Y?(N=t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:Y,title:k,"aria-label":k,children:C.code}),n[17]=C.code,n[18]=k,n[19]=Y,n[20]=N):N=n[20];let W;n[21]!==a.path?(W=t.jsx(ym,{filePath:a.path,className:"h-3.5 w-3.5 shrink-0"}),n[21]=a.path,n[22]=W):W=n[22];let B;if(n[23]!==a.path){e:{const fe=a.path.lastIndexOf("/");if(fe===-1){let ye;n[25]===Symbol.for("react.memo_cache_sentinel")?(ye={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[25]=ye):ye=n[25],B=t.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:ye,title:a.path,children:a.path});break e}const Ce=a.path.slice(0,fe),ge=a.path.slice(fe);let ve;n[26]===Symbol.for("react.memo_cache_sentinel")?(ve={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[26]=ve):ve=n[26];let Ne;n[27]===Symbol.for("react.memo_cache_sentinel")?(Ne=t.jsx("span",{className:"text-muted-foreground",children:"/"}),n[27]=Ne):Ne=n[27];const ne=t.jsx("span",{className:"text-foreground",children:ge.slice(1)});let re;n[28]!==ne?(re=t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[Ne,ne]}),n[28]=ne,n[29]=re):re=n[29],B=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:ve,children:Ce}),re]})}n[23]=a.path,n[24]=B}else B=n[24];let F;n[30]===Symbol.for("react.memo_cache_sentinel")?(F={color:"var(--status-success)"},n[30]=F):F=n[30];let O;n[31]!==v?(O=t.jsxs("span",{style:F,children:["+",v]}),n[31]=v,n[32]=O):O=n[32];let Q,H;n[33]===Symbol.for("react.memo_cache_sentinel")?(Q=t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),H={color:"var(--status-error)"},n[33]=Q,n[34]=H):(Q=n[33],H=n[34]);let ie;n[35]!==w?(ie=t.jsxs("span",{style:H,children:["-",w]}),n[35]=w,n[36]=ie):ie=n[36];let oe;n[37]!==O||n[38]!==ie?(oe=t.jsxs("span",{className:"shrink-0 typography-micro",children:[O,Q,ie]}),n[37]=O,n[38]=ie,n[39]=oe):oe=n[39];let se;n[40]!==a.path||n[41]!==A||n[42]!==x||n[43]!==P||n[44]!==L?(se=P?t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx("button",{type:"button",onClick:A,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":L("gitView.changes.revertFileAria",{path:a.path}),children:x?t.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(D,{name:"arrow-go-back",className:"size-3.5"})})}),t.jsx(It,{sideOffset:8,children:L("gitView.changes.revertFileTooltip")})]}):null,n[40]=a.path,n[41]=A,n[42]=x,n[43]=P,n[44]=L,n[45]=se):se=n[45];const xe=y?null:T;let ae;return n[46]!==K||n[47]!==u||n[48]!==G||n[49]!==te||n[50]!==N||n[51]!==W||n[52]!==B||n[53]!==oe||n[54]!==se||n[55]!==xe||n[56]!==Z?(ae=t.jsxs("div",{className:Z,role:"button",tabIndex:0,onClick:u,onKeyDown:K,style:G,children:[te,N,W,B,oe,se,xe]}),n[46]=K,n[47]=u,n[48]=G,n[49]=te,n[50]=N,n[51]=W,n[52]=B,n[53]=oe,n[54]=se,n[55]=xe,n[56]=Z,n[57]=ae):ae=n[57],ae}),Vl=14,nd=s=>s.replace(/\\/g,"/").replace(/^\/+/,"").trim(),_l=(s,e)=>({id:`dir:${s}`,path:s,name:e,children:new Map,directFiles:[],files:[]}),Lv=s=>{const e=_l("","");for(const n of s){const a=nd(n.path);if(!a)continue;const i=a.split("/").filter(Boolean).slice(0,-1);let l=e;if(l.files.push(n),i.length>0){let u="";for(const c of i){u=u?`${u}/${c}`:c;const x=l.children.get(c);if(x){x.files.push(n),l=x;continue}const m=_l(u,c);m.files.push(n),l.children.set(c,m),l=m}}l.directFiles.push(n)}return e},Ov=(s,e)=>{const n=[],a=(r,i)=>{const l=Array.from(r.children.values()).sort((c,x)=>c.path.localeCompare(x.path));for(const c of l)n.push({key:c.id,kind:"directory",depth:i,directory:c}),e.has(c.path)&&a(c,i+1);const u=[...r.directFiles].sort((c,x)=>c.path.localeCompare(x.path));for(const c of u)n.push({key:`file:${nd(c.path)}`,kind:"file",depth:i,file:c})};return a(s,0),n},zv=1e3,Hl=34,ti=30,_a="pl-0 pr-2",si=(s,e)=>`${s} ${e}`,iw=({groups:s,diffStats:e,revertingPaths:n,isRevertingAll:a=!1,headerBackgroundClassName:r="bg-sidebar",onVisiblePathsChange:i,onRevertAll:l,onRevertDirectory:u})=>{const{t:c}=st(),x=o.useRef(null),g=Ie(O=>O.gitChangesViewMode)==="tree",d=o.useMemo(()=>s.filter(O=>O.entries.length>0),[s]),[b,h]=o.useState(new Set),[f,y]=o.useState(new Set),[P,I]=o.useState(!1),[C,L]=o.useState(null),k=o.useMemo(()=>d.map(O=>Lv(O.entries)),[d]),v=o.useMemo(()=>{const O=[];return d.forEach((Q,H)=>{Array.from(k[H]?.children.values()??[]).forEach(ie=>{O.push(si(Q.id,ie.path))})}),O},[k,d]);o.useEffect(()=>{g&&y(O=>{const Q=new Set,H=new Set(v);return O.forEach(ie=>{(ie.slice(ie.indexOf(" ")+1).includes("/")||H.has(ie))&&Q.add(ie)}),v.forEach(ie=>Q.add(ie)),Q})},[g,v]);const w=o.useMemo(()=>{const O=[];return d.forEach((Q,H)=>{if(O.push({type:"header",key:`header:${Q.id}`,groupIndex:H}),!b.has(Q.id)){if(g){const ie=new Set;f.forEach(se=>{se.startsWith(`${Q.id} `)&&ie.add(se.slice(Q.id.length+1))}),Ov(k[H],ie).forEach(se=>{se.kind==="file"?O.push({type:"file",key:`${Q.id}:${se.key}`,groupIndex:H,file:se.file,depth:se.depth}):O.push({type:"directory",key:`${Q.id}:${se.key}`,groupIndex:H,directory:se.directory,depth:se.depth})});return}Q.entries.forEach(ie=>{O.push({type:"file",key:`${Q.id}:file:${ie.path}`,groupIndex:H,file:ie,depth:0})})}}),l&&d.length>0&&O.push({type:"revert-all",key:"revert-all"}),O},[b,f,g,l,k,d]),E=w.length,K=E>=zv,U=Xd({count:E,enabled:K,getScrollElement:()=>x.current,estimateSize:()=>Hl,overscan:12,getItemKey:O=>w[O]?.key??O}),M=U.getVirtualItems(),S=o.useMemo(()=>{if(!K)return 0;const O=x.current?.scrollTop??0;return M.find(H=>H.end>O)?.index??0},[K,M,x]);o.useEffect(()=>{if(!i)return;const O=Q=>Q&&Q.type==="file"?Q.file.path:null;if(E===0){i([]);return}if(!K){const Q=[];for(const H of w)if(H.type==="file"&&(Q.push(H.file.path),Q.length>=ti))break;i(Q);return}i(w.slice(S,S+Math.ceil((x.current?.clientHeight??0)/Hl)+ti).map(Q=>O(Q)).filter(Q=>!!Q).slice(0,ti))},[i,E,w,K,S]);const A=o.useCallback(O=>{h(Q=>{const H=new Set(Q);return H.has(O)?H.delete(O):H.add(O),H})},[]),z=o.useCallback((O,Q)=>{y(H=>{const ie=new Set(H),oe=si(O,Q);return ie.has(oe)?ie.delete(oe):ie.add(oe),ie})},[]),T=o.useMemo(()=>{const O=new Set;return d.forEach(Q=>Q.entries.forEach(H=>O.add(H.path))),Array.from(O)},[d]),Z=T.length,G=C?a||C.paths.some(O=>n.has(O)):!1,te=o.useCallback(async()=>{!l||a||T.length===0||(await l(T),I(!1))},[T,a,l]),Y=o.useCallback(async()=>{!u||!C||G||(await u(C.paths),L(null))},[G,u,C]),N=o.useCallback((O,Q)=>{const H=b.has(O.id),ie=O.entries.length;return t.jsxs("div",{className:ce("sticky top-0 z-10 flex items-center gap-2 py-2",r,_a,!Q&&"mt-1 border-t border-border/40"),children:[t.jsx("button",{type:"button",onClick:()=>O.onActionAll(O.entries.map(oe=>oe.path)),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":O.actionAllLabel,title:O.actionAllLabel,children:O.actionSymbol}),t.jsxs("button",{type:"button",onClick:()=>A(O.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":!H,children:[t.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:O.title}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:ie}),t.jsx(D,{name:"arrow-down-s",className:ce("size-3.5 shrink-0 text-muted-foreground transition-transform",H&&"-rotate-90")})]})]})},[b,r,A]),W=o.useCallback((O,Q,H)=>{const ie=f.has(si(O.id,Q.path)),oe=Q.files.map(xe=>xe.path),se=a||oe.some(xe=>n.has(xe));return t.jsxs("div",{className:ce("group flex items-center gap-2 py-1.5",_a),style:{paddingLeft:`${H*Vl}px`},children:[t.jsxs("button",{type:"button",onClick:()=>z(O.id,Q.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":ie?c("gitView.changes.collapseDirectoryAria",{path:Q.path}):c("gitView.changes.expandDirectoryAria",{path:Q.path}),children:[ie?t.jsx(D,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):t.jsx(D,{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:Q.path,children:Q.name}),t.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:Q.files.length})]}),O.showRevertActions!==!1&&u?t.jsx("button",{type:"button",onClick:()=>L({path:Q.path,paths:oe,count:oe.length}),disabled:se,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":c("gitView.changes.revertDirectoryAria",{path:Q.path}),title:c("gitView.changes.revertDirectoryTooltip"),children:se?t.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(D,{name:"arrow-go-back",className:"size-3.5"})}):null,t.jsx("button",{type:"button",onClick:()=>O.onActionAll(Q.files.map(xe=>xe.path)),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":c(O.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:Q.path}),title:c(O.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:Q.path}),children:O.actionSymbol})]})},[f,a,u,n,c,z]),B=o.useCallback((O,Q)=>{if(O.type==="revert-all")return t.jsx("div",{className:ce("flex justify-end py-2",_a),children:t.jsxs(J,{variant:"ghost",size:"sm",onClick:()=>I(!0),disabled:a,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[t.jsx(D,{name:"arrow-go-back",className:"size-3.5"}),c("gitView.changes.revertAll")]})});const H=d[O.groupIndex];if(!H)return null;if(O.type==="header")return N(H,Q);if(O.type==="directory")return W(H,O.directory,O.depth);const ie=O.file;return t.jsx(Fv,{file:ie,actionLabel:H.getActionLabel(ie.path),actionSymbol:H.actionSymbol,onAction:()=>H.onActionFile(ie.path),stats:e?.[ie.path],onViewDiff:()=>H.onViewDiff(ie.path),onRevert:()=>H.onRevertFile(ie.path),isReverting:n.has(ie.path)||a,rowPaddingClassName:_a,indentPx:O.depth*Vl,actionAtStart:!g,showRevert:H.showRevertActions!==!1})},[e,a,g,W,N,n,c,d]),F=o.useCallback(O=>{const Q=w[O],H=w[O-1];return!Q||!H||Q.type!=="file"&&Q.type!=="directory"||H.type!=="file"&&H.type!=="directory"?!1:H.groupIndex===Q.groupIndex},[w]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[t.jsx(bm,{ref:x,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:K?t.jsx("div",{style:{height:U.getTotalSize(),position:"relative"},children:M.map(O=>{const Q=w[O.index];return Q?t.jsx("div",{"data-index":O.index,ref:U.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${O.start}px)`},className:ce(F(O.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:B(Q,O.index===0)},Q.key):null})}):t.jsx("div",{role:"list","aria-label":c("gitView.changes.changedFilesAria"),children:w.map((O,Q)=>t.jsx("div",{className:ce("relative",F(Q)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:B(O,Q===0)},O.key))})}),t.jsx(vm,{containerRef:x,disableHorizontal:!0})]}),t.jsx(Mt,{open:P,onOpenChange:O=>{!a&&!O&&I(!1)},children:t.jsxs(Tt,{className:"max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:c("gitView.changes.revertAllDialogTitle")}),t.jsx(Bt,{children:Z===1?c("gitView.changes.revertAllDescriptionSingle",{count:Z}):c("gitView.changes.revertAllDescriptionPlural",{count:Z})})]}),t.jsxs(qt,{children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>I(!1),disabled:a,children:c("gitView.common.cancel")}),t.jsx(J,{variant:"destructive",size:"sm",onClick:()=>{te()},disabled:a,children:c(a?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})}),t.jsx(Mt,{open:!!C,onOpenChange:O=>{!G&&!O&&L(null)},children:t.jsxs(Tt,{className:"max-w-md",children:[t.jsxs(zt,{children:[t.jsx(Ot,{children:c("gitView.changes.revertDirectoryDialogTitle")}),t.jsx(Bt,{children:C?C.count===1?c("gitView.changes.revertDirectoryDescriptionSingle",{count:C.count,path:C.path}):c("gitView.changes.revertDirectoryDescriptionPlural",{count:C.count,path:C.path}):null})]}),t.jsxs(qt,{children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>L(null),disabled:G,children:c("gitView.common.cancel")}),t.jsx(J,{variant:"destructive",size:"sm",onClick:()=>{Y()},disabled:G||!C,children:c(G?"gitView.changes.reverting":"gitView.changes.revertDirectory")})]})]})})]})},ni=38,Ha=200,Kv=s=>{const e=Ze.c(20),{value:n,onChange:a,placeholder:r,disabled:i,hasTouchInput:l,isMobile:u}=s,c=i===void 0?!1:i,x=l===void 0?!1:l,m=u===void 0?!1:u,{t:g}=st(),d=o.useRef(null),b=Ie(Uv);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const K=d.current;if(!K)return;const U=document.activeElement===K,M=()=>{K.style.height=`${ni}px`;const A=K.scrollHeight,z=Math.min(Math.max(A,ni),Ha);K.style.height=`${z}px`,K.style.overflowY=A>Ha?"auto":"hidden",A>Ha&&!U&&(K.scrollTop=K.scrollHeight)};M();const S=window.requestAnimationFrame(M);return()=>{window.cancelAnimationFrame(S)}},e[0]=h):h=e[0];let f;e[1]!==n?(f=[n],e[1]=n,e[2]=f):f=e[2],o.useLayoutEffect(h,f);let y;e[3]!==a?(y=K=>a(K.target.value),e[3]=a,e[4]=y):y=e[4];let P;e[5]!==r||e[6]!==g?(P=r??g("gitView.commit.messagePlaceholder"),e[5]=r,e[6]=g,e[7]=P):P=e[7];const I=x?"on":"off",C=x?"sentences":"off",L=m||b,k=c&&"opacity-50";let v;e[8]!==k?(v=ce("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)]",k),e[8]=k,e[9]=v):v=e[9];let w;e[10]===Symbol.for("react.memo_cache_sentinel")?(w={minHeight:ni,maxHeight:Ha},e[10]=w):w=e[10];let E;return e[11]!==c||e[12]!==L||e[13]!==v||e[14]!==y||e[15]!==P||e[16]!==I||e[17]!==C||e[18]!==n?(E=t.jsx("textarea",{ref:d,value:n,onChange:y,placeholder:P,rows:1,disabled:c,autoCorrect:I,autoCapitalize:C,spellCheck:L,className:v,style:w}),e[11]=c,e[12]=L,e[13]=v,e[14]=y,e[15]=P,e[16]=I,e[17]=C,e[18]=n,e[19]=E):E=e[19],E};function Uv(s){return s.inputSpellcheckEnabled}const Bv=s=>{const e=Ze.c(30),{highlights:n,onInsert:a}=s,{t:r}=st();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 l=i;let u;e[3]!==r?(u=r("gitView.commit.aiHighlights.title"),e[3]=r,e[4]=u):u=e[4];let c;e[5]!==u?(c=t.jsx("p",{className:"typography-micro text-muted-foreground",children:u}),e[5]=u,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(D,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let g;e[10]!==l||e[11]!==x?(g=t.jsx(Ct,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"icon",className:"size-6",onClick:l,"aria-label":x,children:m})}),e[10]=l,e[11]=x,e[12]=g):g=e[12];let d;e[13]!==r?(d=r("gitView.commit.aiHighlights.insertTooltip"),e[13]=r,e[14]=d):d=e[14];let b;e[15]!==d?(b=t.jsx(It,{sideOffset:8,children:d}),e[15]=d,e[16]=b):b=e[16];let h;e[17]!==g||e[18]!==b?(h=t.jsxs(St,{children:[g,b]}),e[17]=g,e[18]=b,e[19]=h):h=e[19];let f;e[20]!==c||e[21]!==h?(f=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c,h]}),e[20]=c,e[21]=h,e[22]=f):f=e[22];let y;e[23]!==n?(y=n.map($v),e[23]=n,e[24]=y):y=e[24];let P;e[25]!==y?(P=t.jsx("ul",{className:"space-y-1",children:y}),e[25]=y,e[26]=P):P=e[26];let I;return e[27]!==f||e[28]!==P?(I=t.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[f,P]}),e[27]=f,e[28]=P,e[29]=I):I=e[29],I};function $v(s,e){return t.jsx("li",{className:"typography-meta text-foreground",children:s},`${s}-${e}`)}const ow=s=>{const e=Ze.c(75),{stagedCount:n,commitMessage:a,onCommitMessageChange:r,generatedHighlights:i,onInsertHighlights:l,onGenerateMessage:u,isGeneratingMessage:c,onCommit:x,onCommitAndPush:m,commitAction:g,hasPendingIndexMutation:d,gitmojiEnabled:b,onOpenGitmojiPicker:h}=s,f=d===void 0?!1:d,{t:y}=st(),P=n>0;let I;e[0]!==g||e[1]!==a||e[2]!==f||e[3]!==P?(I=a.trim()&&P&&g===null&&!f,e[0]=g,e[1]=a,e[2]=f,e[3]=P,e[4]=I):I=e[4];const C=I,{isMobile:L,hasTouchInput:k}=Ms();let v;e[5]!==y?(v=y("gitView.commit.title"),e[5]=y,e[6]=v):v=e[6];let w;e[7]!==v?(w=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:v}),e[7]=v,e[8]=w):w=e[8];let E;e[9]!==P||e[10]!==y?(E=P?null:t.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:y("gitView.commit.stageFilesHint")}),e[9]=P,e[10]=y,e[11]=E):E=e[11];let K;e[12]!==w||e[13]!==E?(K=t.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[w,E]}),e[12]=w,e[13]=E,e[14]=K):K=e[14];let U;e[15]!==i||e[16]!==l?(U=t.jsx(Bv,{highlights:i,onInsert:l}),e[15]=i,e[16]=l,e[17]=U):U=e[17];let M;e[18]!==y?(M=y("gitView.commit.messagePlaceholder"),e[18]=y,e[19]=M):M=e[19];const S=g!==null;let A;e[20]!==a||e[21]!==k||e[22]!==L||e[23]!==r||e[24]!==M||e[25]!==S?(A=t.jsx(Kv,{value:a,onChange:r,placeholder:M,disabled:S,hasTouchInput:k,isMobile:L}),e[20]=a,e[21]=k,e[22]=L,e[23]=r,e[24]=M,e[25]=S,e[26]=A):A=e[26];let z;e[27]!==b||e[28]!==h||e[29]!==y?(z=b&&t.jsxs(J,{variant:"outline",size:"sm",onClick:h,className:"w-fit",type:"button",children:[t.jsx(D,{name:"emotion-happy",className:"size-4"}),y("gitView.commit.addGitmoji")]}),e[27]=b,e[28]=h,e[29]=y,e[30]=z):z=e[30];const T=c||g!==null||f||n===0;let Z;e[31]!==y?(Z=y("gitView.commit.generateAria"),e[31]=y,e[32]=Z):Z=e[32];let G;e[33]!==c?(G=c?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"ai-generate-2",className:"size-4 text-primary"}),e[33]=c,e[34]=G):G=e[34];let te;e[35]!==y?(te=y("gitView.commit.generate"),e[35]=y,e[36]=te):te=e[36];let Y;e[37]!==te?(Y=t.jsx("span",{className:"commit-actions__label",children:te}),e[37]=te,e[38]=Y):Y=e[38];let N;e[39]!==u||e[40]!==T||e[41]!==Z||e[42]!==G||e[43]!==Y?(N=t.jsxs(J,{variant:"outline",size:"sm",onClick:u,disabled:T,type:"button","aria-label":Z,className:"commit-actions__btn",children:[G,Y]}),e[39]=u,e[40]=T,e[41]=Z,e[42]=G,e[43]=Y,e[44]=N):N=e[44];let W;e[45]===Symbol.for("react.memo_cache_sentinel")?(W=t.jsx("div",{className:"flex-1"}),e[45]=W):W=e[45];const B=!C||c;let F;e[46]!==y?(F=y("gitView.commit.commitAria"),e[46]=y,e[47]=F):F=e[47];let O;e[48]!==g||e[49]!==y?(O=g==="commit"?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"commit-actions__label",children:y("gitView.commit.committing")})]}):t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"git-commit",className:"size-4"}),t.jsx("span",{className:"commit-actions__label",children:y("gitView.commit.commit")})]}),e[48]=g,e[49]=y,e[50]=O):O=e[50];let Q;e[51]!==x||e[52]!==B||e[53]!==F||e[54]!==O?(Q=t.jsx(J,{size:"sm",variant:"outline",onClick:x,disabled:B,className:"commit-actions__btn whitespace-nowrap","aria-label":F,children:O}),e[51]=x,e[52]=B,e[53]=F,e[54]=O,e[55]=Q):Q=e[55];let H;e[56]!==C||e[57]!==g||e[58]!==c||e[59]!==L||e[60]!==m||e[61]!==y?(H=L?t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(J,{variant:"default",size:"sm",onClick:()=>m(),disabled:!C||c,className:"h-7 w-7 p-0","aria-label":y("gitView.commit.pushAria"),children:g==="commitAndPush"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"arrow-up",className:"size-3.5"})})}),t.jsx(It,{side:"top",children:t.jsx("p",{children:y("gitView.commit.push")})})]}):t.jsx(J,{size:"sm",variant:"default",onClick:()=>m(),disabled:!C||c,className:"commit-actions__btn","aria-label":y("gitView.commit.pushAria"),children:g==="commitAndPush"?t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:y("gitView.commit.pushing")})]}):t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"arrow-up",className:"size-3.5"}),t.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:y("gitView.commit.push")})]})}),e[56]=C,e[57]=g,e[58]=c,e[59]=L,e[60]=m,e[61]=y,e[62]=H):H=e[62];let ie;e[63]!==N||e[64]!==Q||e[65]!==H?(ie=t.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[N,W,Q,H]}),e[63]=N,e[64]=Q,e[65]=H,e[66]=ie):ie=e[66];let oe;e[67]!==A||e[68]!==z||e[69]!==ie||e[70]!==U?(oe=t.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[U,A,z,ie]}),e[67]=A,e[68]=z,e[69]=ie,e[70]=U,e[71]=oe):oe=e[71];let se;return e[72]!==oe||e[73]!==K?(se=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[K,oe]}),e[72]=oe,e[73]=K,e[74]=se):se=e[74],se},Vv=s=>{const e=Ze.c(41),{syncAction:n,remotes:a,onFetch:r,onSync:i,onRemoveRemote:l,disabled:u,removingRemoteName:c,aheadCount:x,behindCount:m,trackingRemoteName:g,hasUncommittedChanges:d}=s,b=a===void 0?[]:a,h=c===void 0?null:c,f=x===void 0?0:x,y=m===void 0?0:m,P=d===void 0?!1:d,{t:I}=st(),C=o.useRef(!1),L=!!h,k=b.find(re=>re.name===g)??b[0],v=y>0&&P,w=u||n!==null||L||!k||v,E=u||n!==null||L||b.length===0,K=f>0||y>0;let U;e[0]!==I?(U=I("gitView.sync.sync"),e[0]=I,e[1]=U):U=e[1];const M=y>0?`↓${y}`:null,S=f>0?`↑${f}`:null;let A;e[2]!==U||e[3]!==M||e[4]!==S?(A=[U,M,S].filter(Boolean),e[2]=U,e[3]=M,e[4]=S,e[5]=A):A=e[5];const z=A.join(" "),T=v?I("gitView.sync.commitOrStashTooltip"):k?K?I("gitView.sync.syncChangesTooltip",{ahead:f,behind:y}):I("gitView.sync.syncChanges"):I("gitView.sync.noRemoteTooltip"),Z=()=>{k&&i(k)},G="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 te;e[6]===Symbol.for("react.memo_cache_sentinel")?(te=ce("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]=te):te=e[6];let Y;e[7]!==I?(Y=I("gitView.sync.syncChanges"),e[7]=I,e[8]=Y):Y=e[8];let N;e[9]!==n?(N=n==="sync"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=N):N=e[10];let W;e[11]!==z?(W=t.jsx("span",{className:"whitespace-nowrap tabular-nums",children:z}),e[11]=z,e[12]=W):W=e[12];let B;e[13]!==Z||e[14]!==w||e[15]!==Y||e[16]!==N||e[17]!==W?(B=t.jsx(Ct,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:Z,disabled:w,className:te,"aria-label":Y,children:[N,W]})}),e[13]=Z,e[14]=w,e[15]=Y,e[16]=N,e[17]=W,e[18]=B):B=e[18];let F;e[19]!==T?(F=t.jsx(It,{sideOffset:8,children:T}),e[19]=T,e[20]=F):F=e[20];let O;e[21]!==B||e[22]!==F?(O=t.jsxs(St,{children:[B,F]}),e[21]=B,e[22]=F,e[23]=O):O=e[23];const Q=gs;let H;e[24]===Symbol.for("react.memo_cache_sentinel")?(H=ce("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]=H):H=e[24];let ie;e[25]!==I?(ie=I("gitView.sync.moreActionsAria"),e[25]=I,e[26]=ie):ie=e[26];let oe;e[27]===Symbol.for("react.memo_cache_sentinel")?(oe=t.jsx(D,{name:"arrow-down-s",className:"size-4"}),e[27]=oe):oe=e[27];let se;e[28]!==E||e[29]!==ie?(se=t.jsx(ms,{asChild:!0,children:t.jsx("button",{type:"button",className:H,disabled:E,"aria-label":ie,children:oe})}),e[28]=E,e[29]=ie,e[30]=se):se=e[30];const xe=ps,ae="start",fe=-40,Ce="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ge=b.map(re=>t.jsx(Ns,{onSelect:ye=>{if(C.current){ye.preventDefault(),C.current=!1;return}r(re)},children:t.jsxs("div",{className:"flex w-full items-center gap-2",children:[t.jsx(D,{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:I("gitView.sync.fetchFromRemote",{name:re.name})}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:re.fetchUrl})]})}),l&&re.name!==g?t.jsx(J,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||L,onPointerDown:ye=>{C.current=!0,ye.preventDefault(),ye.stopPropagation()},onClick:ye=>{C.current=!0,ye.preventDefault(),ye.stopPropagation(),l(re)},"aria-label":I("gitView.header.removeRemoteAria",{name:re.name}),title:I("gitView.header.removeRemoteTitle",{name:re.name}),children:h===re.name?t.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(D,{name:"close",className:"size-3.5"})}):null]})},re.name));let ve;e[31]!==xe||e[32]!==ge?(ve=t.jsx(xe,{align:ae,alignOffset:fe,className:Ce,children:ge}),e[31]=xe,e[32]=ge,e[33]=ve):ve=e[33];let Ne;e[34]!==Q||e[35]!==se||e[36]!==ve?(Ne=t.jsxs(Q,{children:[se,ve]}),e[34]=Q,e[35]=se,e[36]=ve,e[37]=Ne):Ne=e[37];let ne;return e[38]!==O||e[39]!==Ne?(ne=t.jsxs("div",{className:G,children:[O,Ne]}),e[38]=O,e[39]=Ne,e[40]=ne):ne=e[40],ne};function _v(s){const e=Ze.c(85),{draft:n,onEdit:a,onDelete:r,className:i,maxWidth:l}=s,{t:u}=st(),x=dr()?.currentTheme,[m,g]=he.useState(!1),[d,b]=he.useState(!1),h=typeof n.text=="string"?n.text:"";let f;e[0]!==h?(f=h.length>150||h.split(`
30
+ `).length>3,e[0]=h,e[1]=f):f=e[1];const y=f;let P;e[2]!==i?(P=ce("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]=P):P=e[3];const I=x?.colors?.surface?.elevated,C=x?.colors?.interactive?.border,L=l?`${Math.max(200,Math.floor(l))}px`:void 0;let k;e[4]!==I||e[5]!==C||e[6]!==L?(k={backgroundColor:I,borderColor:C,maxWidth:L},e[4]=I,e[5]=C,e[6]=L,e[7]=k):k=e[7];let v;e[8]===Symbol.for("react.memo_cache_sentinel")?(v=q=>{q.preventDefault(),b(!0)},e[8]=v):v=e[8];let w;e[9]!==P||e[10]!==k?(w=t.jsx("div",{className:P,style:k,"data-comment-card":"true",onContextMenu:v}),e[9]=P,e[10]=k,e[11]=w):w=e[11];let E;e[12]!==n.fileLabel?(E=t.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[12]=n.fileLabel,e[13]=E):E=e[13];let K;e[14]===Symbol.for("react.memo_cache_sentinel")?(K=t.jsx("span",{children:"•"}),e[14]=K):K=e[14];let U;e[15]!==n.endLine||e[16]!==n.startLine||e[17]!==u?(U=u("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[15]=n.endLine,e[16]=n.startLine,e[17]=u,e[18]=U):U=e[18];let M;e[19]!==U?(M=t.jsx("span",{children:U}),e[19]=U,e[20]=M):M=e[20];let S;e[21]!==n.side?(S=n.side&&t.jsxs("span",{children:["(",n.side,")"]}),e[21]=n.side,e[22]=S):S=e[22];let A;e[23]!==M||e[24]!==S||e[25]!==E?(A=t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[E,K,M,S]}),e[23]=M,e[24]=S,e[25]=E,e[26]=A):A=e[26];const z=m||!y,T=!m&&y&&"line-clamp-3";let Z;e[27]!==T?(Z=ce("text-sm whitespace-pre-wrap break-words leading-relaxed",T),e[27]=T,e[28]=Z):Z=e[28];let G;e[29]!==h||e[30]!==Z?(G=t.jsx("div",{className:Z,children:h}),e[29]=h,e[30]=Z,e[31]=G):G=e[31];let te;e[32]!==y||e[33]!==m||e[34]!==u?(te=y&&t.jsx(Mn,{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(D,{name:"arrow-up-s",className:"size-3 mr-1"}),u("inlineComment.actions.showLess")]}):t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"arrow-down-s",className:"size-3 mr-1"}),u("inlineComment.actions.showMore")]})})}),e[32]=y,e[33]=m,e[34]=u,e[35]=te):te=e[35];let Y;e[36]===Symbol.for("react.memo_cache_sentinel")?(Y=t.jsx(Tn,{}),e[36]=Y):Y=e[36];let N;e[37]!==z||e[38]!==G||e[39]!==te?(N=t.jsxs(En,{open:z,onOpenChange:g,children:[G,te,Y]}),e[37]=z,e[38]=G,e[39]=te,e[40]=N):N=e[40];let W;e[41]!==A||e[42]!==N?(W=t.jsxs("div",{className:"flex-1 min-w-0",children:[A,N]}),e[41]=A,e[42]=N,e[43]=W):W=e[43];let B;e[44]===Symbol.for("react.memo_cache_sentinel")?(B=t.jsx(ms,{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(D,{name:"more",className:"size-4"})})}),e[44]=B):B=e[44];let F;e[45]===Symbol.for("react.memo_cache_sentinel")?(F=t.jsx(D,{name:"edit",className:"size-4 mr-2"}),e[45]=F):F=e[45];let O;e[46]!==u?(O=u("inlineComment.actions.editComment"),e[46]=u,e[47]=O):O=e[47];let Q;e[48]!==a||e[49]!==O?(Q=t.jsxs(Ns,{onClick:a,children:[F,O]}),e[48]=a,e[49]=O,e[50]=Q):Q=e[50];let H;e[51]===Symbol.for("react.memo_cache_sentinel")?(H=t.jsx(D,{name:"delete-bin",className:"size-4 mr-2"}),e[51]=H):H=e[51];let ie;e[52]!==u?(ie=u("inlineComment.actions.deleteComment"),e[52]=u,e[53]=ie):ie=e[53];let oe;e[54]!==r||e[55]!==ie?(oe=t.jsxs(Ns,{onClick:r,className:"text-destructive",children:[H,ie]}),e[54]=r,e[55]=ie,e[56]=oe):oe=e[56];let se;e[57]!==Q||e[58]!==oe?(se=t.jsxs(gs,{children:[B,t.jsxs(ps,{align:"end",children:[Q,oe]})]}),e[57]=Q,e[58]=oe,e[59]=se):se=e[59];let xe;e[60]!==W||e[61]!==se?(xe=t.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[W,se]}),e[60]=W,e[61]=se,e[62]=xe):xe=e[62];let ae;e[63]!==xe||e[64]!==w?(ae=t.jsx(bn,{render:w,children:xe}),e[63]=xe,e[64]=w,e[65]=ae):ae=e[65];let fe;e[66]===Symbol.for("react.memo_cache_sentinel")?(fe=t.jsx(D,{name:"edit",className:"size-4 mr-2"}),e[66]=fe):fe=e[66];let Ce;e[67]!==u?(Ce=u("inlineComment.actions.editComment"),e[67]=u,e[68]=Ce):Ce=e[68];let ge;e[69]!==a||e[70]!==Ce?(ge=t.jsxs(ln,{onClick:a,children:[fe,Ce]}),e[69]=a,e[70]=Ce,e[71]=ge):ge=e[71];let ve;e[72]===Symbol.for("react.memo_cache_sentinel")?(ve=t.jsx(D,{name:"delete-bin",className:"size-4 mr-2"}),e[72]=ve):ve=e[72];let Ne;e[73]!==u?(Ne=u("inlineComment.actions.deleteComment"),e[73]=u,e[74]=Ne):Ne=e[74];let ne;e[75]!==r||e[76]!==Ne?(ne=t.jsxs(ln,{onClick:r,className:"text-destructive focus:text-destructive",children:[ve,Ne]}),e[75]=r,e[76]=Ne,e[77]=ne):ne=e[77];let re;e[78]!==ge||e[79]!==ne?(re=t.jsxs(vn,{children:[ge,ne]}),e[78]=ge,e[79]=ne,e[80]=re):re=e[80];let ye;return e[81]!==d||e[82]!==ae||e[83]!==re?(ye=t.jsxs(yn,{open:d,onOpenChange:b,children:[ae,re]}),e[81]=d,e[82]=ae,e[83]=re,e[84]=ye):ye=e[84],ye}function Wl(s){const e=Ze.c(62),{initialText:n,onTextChange:a,onSave:r,onCancel:i,fileLabel:l,lineRange:u,isEditing:c,className:x,maxWidth:m}=s,g=n===void 0?"":n,d=c===void 0?!1:c,{t:b}=st(),f=dr()?.currentTheme,{isMobile:y}=Ms(),[P,I]=o.useState(g),C=he.useRef(null);let L;e[0]!==a?(L=ee=>{I(ee),a?.(ee)},e[0]=a,e[1]=L):L=e[1];const k=L,v=he.useRef(u);let w,E;e[2]!==u?(w=()=>{u&&(v.current=u)},E=[u],e[2]=u,e[3]=w,e[4]=E):(w=e[3],E=e[4]),he.useEffect(w,E);const K=Yv,U=K(u);let M,S;e[5]!==y?(M=()=>{const ee=C.current;if(!ee)return;const de=ee.closest(".overlay-scrollbar-container"),De=de?.scrollTop??window.scrollY,ke=de?.scrollLeft??window.scrollX;if(y){ee.scrollIntoView({behavior:"auto",block:"nearest"});try{ee.focus({preventScroll:!0})}catch{ee.focus()}return}try{ee.focus({preventScroll:!0})}catch{ee.focus()}const Pe=ee.value.length;try{ee.setSelectionRange(Pe,Pe)}catch{}requestAnimationFrame(()=>{de?(de.scrollTop=De,de.scrollLeft=ke):window.scrollTo({top:De,left:ke})})},S=[y],e[5]=y,e[6]=M,e[7]=S):(M=e[6],S=e[7]),he.useEffect(M,S);let A;e[8]!==i||e[9]!==r||e[10]!==P?(A=ee=>{(ee.metaKey||ee.ctrlKey)&&ee.key==="Enter"?(ee.preventDefault(),P.trim()&&r(P,K(v.current))):ee.key==="Escape"&&(ee.preventDefault(),i())},e[8]=i,e[9]=r,e[10]=P,e[11]=A):A=e[11];const z=A;let T;e[12]!==r||e[13]!==P?(T=ee=>{ee.stopPropagation(),P.trim()&&r(P,K(v.current))},e[12]=r,e[13]=P,e[14]=T):T=e[14];const Z=T;let G;e[15]!==x?(G=ce("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]=G):G=e[16];const te=f?.colors?.surface?.elevated,Y=f?.colors?.interactive?.border,N=m?`${Math.max(200,Math.floor(m))}px`:void 0;let W;e[17]!==te||e[18]!==Y||e[19]!==N?(W={backgroundColor:te,borderColor:Y,maxWidth:N},e[17]=te,e[18]=Y,e[19]=N,e[20]=W):W=e[20];const B="true",F=Qv,O=Jv,Q="p-3",H=(l||u)&&t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[l&&t.jsx("span",{className:"truncate max-w-[200px]",children:l}),l&&u&&t.jsx("span",{children:"•"}),U&&t.jsx("span",{children:b("inlineComment.range.lines",{start:U.start,end:U.end})})]});let ie;e[21]!==k?(ie=ee=>k(ee.target.value),e[21]=k,e[22]=ie):ie=e[22];let oe;e[23]!==y||e[24]!==b?(oe=b(y?"inlineComment.input.placeholderShort":"inlineComment.input.placeholder"),e[23]=y,e[24]=b,e[25]=oe):oe=e[25];let se;e[26]!==z||e[27]!==ie||e[28]!==oe||e[29]!==P?(se=t.jsx(hs,{simple:!0,ref:C,value:P,onChange:ie,onKeyDown:z,placeholder:oe,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]=z,e[27]=ie,e[28]=oe,e[29]=P,e[30]=se):se=e[30];let xe;e[31]!==b?(xe=b("inlineComment.actions.cancel"),e[31]=b,e[32]=xe):xe=e[32];let ae;e[33]!==i||e[34]!==xe?(ae=t.jsx(J,{variant:"ghost",size:"sm",onClick:i,onPointerDown:qv,onTouchStart:Gv,className:"h-8 text-muted-foreground hover:text-foreground",children:xe}),e[33]=i,e[34]=xe,e[35]=ae):ae=e[35];let fe;e[36]!==P?(fe=P.trim(),e[36]=P,e[37]=fe):fe=e[37];const Ce=!fe,ge=f?.colors?.status?.success,ve=f?.colors?.status?.successForeground;let Ne;e[38]!==ge||e[39]!==ve?(Ne={backgroundColor:ge,color:ve},e[38]=ge,e[39]=ve,e[40]=Ne):Ne=e[40];let ne;e[41]!==d||e[42]!==b?(ne=b(d?"inlineComment.actions.save":"inlineComment.actions.comment"),e[41]=d,e[42]=b,e[43]=ne):ne=e[43];let re;e[44]!==Z||e[45]!==Ce||e[46]!==Ne||e[47]!==ne?(re=t.jsx(J,{size:"sm",onClick:Z,onPointerDown:Wv,onTouchStart:Hv,disabled:Ce,className:"h-8 min-w-[80px]",style:Ne,children:ne}),e[44]=Z,e[45]=Ce,e[46]=Ne,e[47]=ne,e[48]=re):re=e[48];let ye;e[49]!==ae||e[50]!==re?(ye=t.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[ae,re]}),e[49]=ae,e[50]=re,e[51]=ye):ye=e[51];let q;e[52]!==H||e[53]!==se||e[54]!==ye?(q=t.jsxs("div",{className:Q,children:[H,se,ye]}),e[52]=H,e[53]=se,e[54]=ye,e[55]=q):q=e[55];let $;return e[56]!==G||e[57]!==W||e[58]!==F||e[59]!==O||e[60]!==q?($=t.jsx("div",{className:G,style:W,"data-comment-input":B,onPointerDown:F,onTouchStart:O,children:q}),e[56]=G,e[57]=W,e[58]=F,e[59]=O,e[60]=q,e[61]=$):$=e[61],$}function Hv(s){return s.stopPropagation()}function Wv(s){return s.stopPropagation()}function Gv(s){return s.stopPropagation()}function qv(s){return s.stopPropagation()}function Jv(s){return s.stopPropagation()}function Qv(s){return s.stopPropagation()}function Yv(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 Xv=s=>{const e=Math.min(s.startLine,s.endLine),n=Math.max(s.startLine,s.endLine);return{...s,startLine:e,endLine:n}},Gl=s=>{const e=Math.min(s.start,s.end),n=Math.max(s.start,s.end);return{...s,start:e,end:n}};function Zv(s){const e=Ze.c(40),{t:n}=st(),{source:a,fileLabel:r,language:i,getCodeForRange:l,toStoreRange:u,fromDraftRange:c}=s,x=ys(rj),m=ys(aj),g=Da(nj),d=Da(sj),b=Da(tj),h=Da(ej),[f,y]=o.useState(null),[P,I]=o.useState(""),[C,L]=o.useState(null),k=x??(m?"draft":null);let v;e:{if(!k||!r){let B;e[0]===Symbol.for("react.memo_cache_sentinel")?(B=[],e[0]=B):B=e[0],v=B;break e}let Y;e[1]!==h||e[2]!==k?(Y=h[k]??[],e[1]=h,e[2]=k,e[3]=Y):Y=e[3];const N=Y;let W;if(e[4]!==r||e[5]!==N||e[6]!==a){let B;e[8]!==r||e[9]!==a?(B=F=>F.source===a&&F.fileLabel===r,e[8]=r,e[9]=a,e[10]=B):B=e[10],W=N.filter(B),e[4]=r,e[5]=N,e[6]=a,e[7]=W}else W=e[7];v=W}const w=v;let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{y(null),I(""),L(null)},e[11]=E):E=e[11];const K=E;let U;e[12]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{K()},e[12]=U):U=e[12];const M=U;let S;e[13]!==c?(S=Y=>{const N=Gl(c(Y));y(N),I(Y.text),L(Y.id)},e[13]=c,e[14]=S):S=e[14];const A=S;let z;e[15]!==C||e[16]!==b?(z=Y=>{b(Y.sessionKey,Y.id),C===Y.id&&K()},e[15]=C,e[16]=b,e[17]=z):z=e[17];const T=z;let Z;e[18]!==g||e[19]!==C||e[20]!==r||e[21]!==l||e[22]!==i||e[23]!==f||e[24]!==k||e[25]!==a||e[26]!==n||e[27]!==u||e[28]!==d?(Z=(Y,N)=>{const W=N??f,B=Y.trim();if(!W||!B||!r)return;if(!k){_.error(n("inlineComment.toast.selectSessionToSave"));return}const F=Gl(W),O=Xv(u(F)),Q=l(F);C?d(k,C,{fileLabel:r,startLine:O.startLine,endLine:O.endLine,side:O.side,code:Q,language:i,text:B}):g({sessionKey:k,source:a,fileLabel:r,startLine:O.startLine,endLine:O.endLine,side:O.side,code:Q,language:i,text:B}),K()},e[18]=g,e[19]=C,e[20]=r,e[21]=l,e[22]=i,e[23]=f,e[24]=k,e[25]=a,e[26]=n,e[27]=u,e[28]=d,e[29]=Z):Z=e[29];const G=Z;let te;return e[30]!==P||e[31]!==T||e[32]!==w||e[33]!==C||e[34]!==c||e[35]!==G||e[36]!==f||e[37]!==k||e[38]!==A?(te={sessionKey:k,drafts:w,selection:f,setSelection:y,commentText:P,setCommentText:I,editingDraftId:C,setEditingDraftId:L,reset:K,cancel:M,startEdit:A,deleteDraft:T,saveComment:G,fromDraftRange:c},e[30]=P,e[31]=T,e[32]=w,e[33]=C,e[34]=c,e[35]=G,e[36]=f,e[37]=k,e[38]=A,e[39]=te):te=e[39],te}function ej(s){return s.drafts}function tj(s){return s.removeDraft}function sj(s){return s.updateDraft}function nj(s){return s.addDraft}function aj(s){return s.newSessionDraft?.open}function rj(s){return s.currentSessionId}const sr=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}`},ij=s=>{const{drafts:e,editingDraftId:n,selection:a}=s,r=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const l=Math.max(1,Math.floor(i.endLine)),u=i.side==="original"?"deletions":"additions";r.push({lineNumber:l,side:u,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 oj(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 ql(s){if(!(!s||s<=0))return Math.max(200,Math.floor(s))}function lj(s){const{diffRootRef:e,drafts:n,selection:a,editingDraftId:r,commentText:i,onTextChange:l,fileLabel:u,onSave:c,onCancel:x,onEdit:m,onDelete:g}=s,[d,b]=o.useState(0),[h,f]=o.useState(null),y=o.useMemo(()=>!a||r?null:sr({type:"new",selection:a}),[r,a]),P=o.useMemo(()=>{const L=n.map(k=>sr({type:k.id===r?"edit":"saved",draft:k}));return y&&L.push(y),L},[n,r,y]),I=o.useCallback(L=>{const k=e.current;if(!k)return null;const v=k.querySelector("diffs-container");if(!(v instanceof HTMLElement))return null;const w=v.querySelector(`[data-annotation-id="${L}"]`);if(w instanceof HTMLElement)return w;const E=v.shadowRoot;return E?E.querySelector(`[data-annotation-id="${L}"]`):null},[e]);o.useEffect(()=>{if(P.length===0)return;let L=!1,k=0;const v=12,w=()=>{L||P.every(K=>!!I(K))||k>=v||(k+=1,requestAnimationFrame(()=>{L||(b(K=>K+1),w())}))};return w(),()=>{L=!0}},[P,I]),o.useEffect(()=>{const L=e.current;if(!L)return;const k=()=>{const w=getComputedStyle(L),E=oj(w.getPropertyValue("--oc-context-panel-width")),K=L.getBoundingClientRect(),U=E??K.width;f(U>0?U:null)};k();const v=new ResizeObserver(()=>{k()});return v.observe(L),window.addEventListener("resize",k),()=>{v.disconnect(),window.removeEventListener("resize",k)}},[e]);const C=o.useCallback(L=>{const v=e.current?.getBoundingClientRect(),w=L.closest("[data-annotation-content]"),E=w instanceof HTMLElement?w.getBoundingClientRect():L.getBoundingClientRect(),K=[E.width];v&&K.push(v.right-E.left);const U=K.filter(M=>Number.isFinite(M)&&M>0);return U.length>0?ql(Math.min(...U)):ql(h)},[e,h]);return t.jsxs(t.Fragment,{children:[n.map(L=>{const k=sr({type:L.id===r?"edit":"saved",draft:L}),v=I(k);if(!v)return null;const w=C(v);return L.id===r?Ga.createPortal(t.jsx(Wl,{initialText:i,onTextChange:l,fileLabel:u,lineRange:{start:L.startLine,end:L.endLine,side:L.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:x,maxWidth:w}),v,`draft-edit-${L.id}`):Ga.createPortal(t.jsx(_v,{draft:L,onEdit:()=>m(L),onDelete:()=>g(L),maxWidth:w}),v,`draft-card-${L.id}`)}),a&&!r&&y&&(()=>{const L=I(y);if(!L)return null;const k=C(L);return Ga.createPortal(t.jsx(Wl,{initialText:i,onTextChange:l,fileLabel:u,lineRange:a,isEditing:!1,onSave:c,onCancel:x,maxWidth:k}),L,y)})()]})}const Jl=5e5,cj=`
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
+ `,dj=`
53
+ ${cj}
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 uj(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 Ql(s){const e=s.length>400?`${s.slice(0,200)}${s.slice(-200)}`:s;return`${s.length}:${uj(e)}`}const mj=(s,e,n,a)=>{const r=a.side==="deletions",l=(n?(r?n.deletionLines:n.additionLines).join(""):r?s:e).split(`
164
+ `),u=Math.min(a.start,a.end),c=Math.max(a.start,a.end),x=Math.max(1,u),m=Math.min(l.length,c);return x>m?"":l.slice(x-1,m).join(`
165
+ `)},pj=(s,e)=>s===e?!0:!s||!e?!1:s.start===e.start&&s.end===e.end&&s.side===e.side,gj=s=>s==="auto"||s==="scroll"||s==="overlay",hj=s=>{let e=s?.parentElement??null;for(;e;){const n=window.getComputedStyle(e);if(gj(n.overflowY))return e;e=e.parentElement}return null},fj=(s,e)=>{if(!s||!e||typeof window>"u")return()=>{};const n=hj(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 l=!1;return()=>{if(l)return;l=!0,e.style.minHeight=i;const c=s.getBoundingClientRect().top-n.getBoundingClientRect().top-r;c&&(n.scrollTop+=c)}},xj=(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()})}))},l=()=>s.querySelector("diffs-container")?.shadowRoot??void 0,u=(c=l())=>!!c?.querySelector("[data-line]");return u()?i():typeof MutationObserver<"u"?(a=new MutationObserver(()=>{const c=l();if(c){if(u(c)){i();return}a?.disconnect(),a=new MutationObserver(()=>{u(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)}},Wa=new WeakMap,yj={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function bj(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 vj(s){if(typeof document>"u")return null;const e=bj(s);let n=Wa.get(e.key);if(!n){const r=new su;r.setup(e.root,e.content),n={virtualizer:r,refs:0},Wa.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=Wa.get(e.key);r&&(r.refs-=1,!(r.refs>0)&&(r.virtualizer.cleanUp(),Wa.delete(e.key)))}}}const jj=(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)}},lw=({original:s,modified:e,fileDiff:n,language:a,fileName:r,renderSideBySide:i,wrapLines:l,layout:u="fill",enableComments:c=!0})=>{const x=dr(),m=x?.currentTheme.metadata.variant==="dark",g=x?.availableThemes.find(q=>q.metadata.id===x.lightThemeId)??ar(!1),d=x?.availableThemes.find(q=>q.metadata.id===x.darkThemeId)??ar(!0),{isMobile:b}=Ms(),h=Zv({source:"diff",fileLabel:r||"unknown",language:a,getCodeForRange:q=>mj(s,e,n,q),toStoreRange:q=>({startLine:q.start,endLine:q.end,side:q.side==="deletions"?"original":"modified"}),fromDraftRange:q=>({start:q.startLine,end:q.endLine,side:q.side==="original"?"deletions":"additions"})}),{drafts:f,selection:y,setSelection:P,commentText:I,setCommentText:C,editingDraftId:L,saveComment:k,cancel:v,startEdit:w,deleteDraft:E}=h,K=he.useRef(null),U=he.useRef(null),M=he.useRef(""),S=he.useRef(!1),A=he.useRef(null);he.useEffect(()=>{K.current=y},[y]),he.useEffect(()=>{U.current=L},[L]),he.useEffect(()=>{M.current=I},[I]);const z=he.useCallback(q=>{if(!c||S.current)return;const $=K.current;if(!(!q&&$&&M.current.trim())){if(b&&$&&q&&q.side===$.side){const ee=Math.min($.start,q.start),de=Math.max($.end,q.end);P({...q,start:ee,end:de})}else P(q);q&&(U.current||C(""))}},[c,b,C,P]),T=he.useCallback(()=>{v()},[v]),Z=he.useCallback(q=>{const $=document.createElement("div");$.style.position="relative";const ee=sr(q.metadata);return $.dataset.annotationId=ee,$.dataset.annotationSide=q.side,$.dataset.annotationLine=String(q.lineNumber),$},[]),G=he.useCallback((q,$)=>{k(q,$??y??void 0)},[k,y]),te=he.useCallback(q=>{P(q);const $=O.current;if($)try{S.current=!0,$.setSelectedLines(q),A.current=q}catch{}finally{S.current=!1}},[P]),Y=he.useCallback(q=>{const $=q.closest("[data-line-type]")?.getAttribute("data-line-type")??q.getAttribute("data-line-type");if($==="change-deletion")return"deletions";if($==="change-addition")return"additions";const ee=q.getAttribute("data-column-side")??q.getAttribute("data-side")??q.closest("[data-column-side]")?.getAttribute("data-column-side");if(ee==="deletions"||ee==="left"||ee==="original")return"deletions";if(ee==="additions"||ee==="right"||ee==="modified")return"additions";const de=q.closest("[data-line-type]");if(de instanceof HTMLElement){const De=de.getBoundingClientRect(),ke=q.getBoundingClientRect(),Pe=De.left+De.width/2;return ke.left+ke.width/2<Pe?"deletions":"additions"}return"additions"},[]);rr(g),rr(d);const N=`${g.metadata.id}:${d.metadata.id}:${m?"dark":"light"}`,W=he.useMemo(()=>{if(n){const q=n.deletionLines.reduce((ee,de)=>ee+de.length,0),$=n.additionLines.reduce((ee,de)=>ee+de.length,0);return Math.max(q,$)>Jl}return Math.max(s.length,e.length)>Jl},[n,e.length,s.length]),B=he.useRef(null),F=he.useRef(null),O=he.useRef(null),Q=he.useRef(null),H=he.useRef(null),ie=he.useRef(null),oe=he.useRef(void 0),se=he.useRef(void 0),xe=he.useRef(void 0),ae=he.useRef(void 0),[,fe]=o.useReducer(q=>q+1,0),Ce=gi(W?"unified":i?"split":"unified"),ge=he.useMemo(()=>oi(g),[g]),ve=he.useMemo(()=>oi(d),[d]);o.useLayoutEffect(()=>{const q=B.current;if(!q)return;const $=q.querySelector("diffs-container");if(!$)return;const ee=m?ve:ge,de=(Qe,Fe)=>Qe.colors?.[Fe],De=de(ge,"terminal.ansiGreen"),ke=de(ge,"terminal.ansiRed"),Pe=de(ge,"terminal.ansiBlue"),Me=de(ve,"terminal.ansiGreen"),Te=de(ve,"terminal.ansiRed"),Ve=de(ve,"terminal.ansiBlue");$.style.setProperty("--shiki-light",ge.fg),$.style.setProperty("--shiki-light-bg",ge.bg),De&&$.style.setProperty("--shiki-light-addition-color",De),ke&&$.style.setProperty("--shiki-light-deletion-color",ke),Pe&&$.style.setProperty("--shiki-light-modified-color",Pe),$.style.setProperty("--shiki-dark",ve.fg),$.style.setProperty("--shiki-dark-bg",ve.bg),Me&&$.style.setProperty("--shiki-dark-addition-color",Me),Te&&$.style.setProperty("--shiki-dark-deletion-color",Te),Ve&&$.style.setProperty("--shiki-dark-modified-color",Ve),$.style.setProperty("--diffs-bg",ee.bg),$.style.setProperty("--diffs-fg",ee.fg);const Ue=m?Me:De,Oe=m?Te:ke,_e=m?Ve:Pe;Ue&&$.style.setProperty("--diffs-addition-color-override",Ue),Oe&&$.style.setProperty("--diffs-deletion-color-override",Oe),_e&&$.style.setProperty("--diffs-modified-color-override",_e);const Ke=$.shadowRoot?.querySelector("pre");Ke&&(Ke.style.setProperty("--shiki-light",ge.fg),Ke.style.setProperty("--shiki-light-bg",ge.bg),De&&Ke.style.setProperty("--shiki-light-addition-color",De),ke&&Ke.style.setProperty("--shiki-light-deletion-color",ke),Pe&&Ke.style.setProperty("--shiki-light-modified-color",Pe),Ke.style.setProperty("--shiki-dark",ve.fg),Ke.style.setProperty("--shiki-dark-bg",ve.bg),Me&&Ke.style.setProperty("--shiki-dark-addition-color",Me),Te&&Ke.style.setProperty("--shiki-dark-deletion-color",Te),Ve&&Ke.style.setProperty("--shiki-dark-modified-color",Ve),Ke.style.setProperty("--diffs-bg",ee.bg),Ke.style.setProperty("--diffs-fg",ee.fg),Ue&&Ke.style.setProperty("--diffs-addition-color-override",Ue),Oe&&Ke.style.setProperty("--diffs-deletion-color-override",Oe),_e&&Ke.style.setProperty("--diffs-modified-color-override",_e))},[ve,N,m,ge]);const Ne=he.useMemo(()=>({theme:{dark:d.metadata.id,light:g.metadata.id},themeType:m?"dark":"light",diffStyle:i?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:W?0:1e3,maxLineLengthForHighlighting:W?1:1e3,tokenizeMaxLineLength:W?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:l?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:c,enableHoverUtility:!1,onLineSelected:c?z:void 0,unsafeCSS:dj,renderAnnotation:c?Z:void 0}),[d.metadata.id,c,m,W,g.metadata.id,i,l,z,Z]),ne=he.useMemo(()=>c?ij({drafts:f,editingDraftId:L,selection:y}):[],[L,c,f,y]),re=he.useRef(ne);if(he.useEffect(()=>{re.current=ne},[ne]),he.useEffect(()=>{const q=F.current;return()=>{O.current?.cleanUp(),O.current=null,Q.current?.release(),Q.current=null,H.current=null,ie.current=null,oe.current=void 0,se.current=void 0,xe.current=void 0,ae.current=void 0,q&&(q.innerHTML="")}},[]),he.useEffect(()=>{if(typeof window>"u")return;const q=F.current,$=B.current;if(!q||!Ce)return;const ee=fj($,q);let de=Q.current;de||(de=vj(q),Q.current=de),Q.current=de;const De=de?.virtualizer??null,ke=n?void 0:{name:r||"",contents:s,lang:a,cacheKey:`old:${N}:${r}:${Ql(s)}`},Pe=n?void 0:{name:r||"",contents:e,lang:a,cacheKey:`new:${N}:${r}:${Ql(e)}`},Me=n?se.current!==n:se.current!==void 0||!ke||!Pe||!xe.current||!ae.current||!Hi(xe.current,ke)||!Hi(ae.current,Pe),Te=O.current,Ve=!!(Te&&(H.current!==De||ie.current!==Ce||De&&(oe.current!==Ne.hunkSeparators||Me)));Ve&&(Te?.cleanUp(),O.current=null,q.innerHTML="");let Ue=O.current;const Oe=!Ve&&Te?!Zd(Te.options,Ne):!1;if(Ue?Ue.setOptions(Ne):(Ue=de?new eu(Ne,de.virtualizer,yj,Ce):new tu(Ne,Ce),O.current=Ue,A.current=null),H.current=De,ie.current=Ce,oe.current=De?Ne.hunkSeparators:void 0,se.current=n,xe.current=ke,ae.current=Pe,n)Ue.render({fileDiff:n,forceRender:Oe,lineAnnotations:re.current,containerWrapper:q});else{if(!ke||!Pe)return;Ue.render({oldFile:ke,newFile:Pe,forceRender:Oe,lineAnnotations:re.current,containerWrapper:q})}const _e=xj(q,()=>{ee(),jj(Ue,de,fe)});return()=>{_e(),ee()}},[N,n,r,a,e,Ne,s,Ce]),he.useEffect(()=>{const q=O.current;if(q){try{q.setLineAnnotations(ne)}catch($){console.error("Failed to apply diff line annotations",$);try{q.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(O.current===q){try{q.rerender()}catch{}fe()}})}},[ne]),he.useEffect(()=>{const q=O.current;if(!q||y!==null)return;const $=A.current;if(!pj(y,$))try{S.current=!0,q.setSelectedLines(y),A.current=y}catch{}finally{S.current=!1}},[y]),he.useEffect(()=>{if(!c)return;const q=F.current;if(!q)return;let $=null,ee=()=>{};const de=()=>{const ke=q.querySelector("diffs-container")?.shadowRoot;if(!ke){$=requestAnimationFrame(de);return}const Pe=Me=>{if(!(Me instanceof MouseEvent)||Me.button!==0||!(Me.target instanceof Element))return;const Te=Me.target.closest("[data-column-number]");if(!(Te instanceof HTMLElement))return;const Ve=Te.getAttribute("data-column-number"),Ue=Ve?parseInt(Ve,10):NaN;if(Number.isNaN(Ue))return;const Oe=Y(Te);z({start:Ue,end:Ue,side:Oe}),Me.preventDefault(),Me.stopPropagation()};ke.addEventListener("click",Pe,!0),ee=()=>{ke.removeEventListener("click",Pe,!0)}};return de(),()=>{$!==null&&cancelAnimationFrame($),ee()}},[N,c,r,z,Y]),he.useEffect(()=>{const q=F.current;if(!q)return;let $=null,ee=null;const De=setTimeout(()=>{const ke=q.querySelector("diffs-container");if(!(ke instanceof HTMLElement))return;const Pe=ke.shadowRoot;$=new MutationObserver(()=>{ee&&cancelAnimationFrame(ee),ee=requestAnimationFrame(()=>{fe(),ee=null})}),$.observe(ke,{childList:!0,subtree:!0}),Pe&&$.observe(Pe,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(De),ee&&cancelAnimationFrame(ee),$?.disconnect()}},[N,r]),typeof window>"u")return null;const ye=c?t.jsx(lj,{diffRootRef:B,drafts:f,selection:y,editingDraftId:L,commentText:I,onTextChange:C,fileLabel:r?.split("/").pop()??"",onSave:G,onCancel:T,onEdit:q=>{te({start:q.startLine,end:q.endLine,side:q.side==="original"?"deletions":"additions"}),w(q)},onDelete:E}):null;return u==="fill"?t.jsx("div",{className:ce("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(Ht,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:t.jsx("div",{ref:B,className:"size-full relative",children:t.jsx("div",{ref:F,className:"size-full"})})}),ye]})}):t.jsxs("div",{className:ce("relative","w-full"),children:[t.jsx("div",{ref:B,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:t.jsx("div",{ref:F,className:"w-full"})}),ye]})},wj=()=>{const s=Ze.c(13),[e,n]=he.useState(!1);let a,r;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{n(ns())},r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),he.useEffect(a,r);let i;s[2]!==e?(i=async d=>e?await sp(d):{success:!0,path:d},s[2]=e,s[3]=i):i=s[3];const l=i;let u;s[4]!==e?(u=async d=>e?await np():{success:!0},s[4]=e,s[5]=u):u=s[5];const c=u;let x;s[6]!==e?(x=async d=>e?await ap():{success:!0},s[6]=e,s[7]=x):x=s[7];const m=x;let g;return s[8]!==e||s[9]!==l||s[10]!==c||s[11]!==m?(g={isDesktop:e,requestAccess:l,startAccessing:c,stopAccessing:m},s[8]=e,s[9]=l,s[10]=c,s[11]=m,s[12]=g):g=s[12],g},Nj=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),kj=({currentBranch:s,localBranches:e,remoteBranches:n,branchInfo:a,onCheckout:r,onCreate:i,remotes:l=[],disabled:u=!1})=>{const{t:c}=st(),[x,m]=o.useState(!1),[g,d]=o.useState(""),[b,h]=o.useState(!1),[f,y]=o.useState(!1),[P,I]=o.useState(""),[C,L]=o.useState(!1),k=o.useRef(null),v=o.useCallback(G=>{G.stopPropagation()},[]),w=l.length>1,E=o.useMemo(()=>Nj(P),[P]),K=o.useMemo(()=>{const G=g.toLowerCase();return G?e.filter(te=>te.toLowerCase().includes(G)):e},[g,e]),U=o.useMemo(()=>{const G=g.toLowerCase();return G?n.filter(te=>te.toLowerCase().includes(G)):n},[g,n]),M=G=>{if(G===s){m(!1);return}r(G),m(!1),d("")},S=()=>{h(!0),setTimeout(()=>k.current?.focus(),50)},A=async()=>{if(!(!E||C)){if(w){y(!0);return}L(!0);try{await i(E,l[0]),I(""),h(!1),m(!1)}finally{L(!1)}}},z=async G=>{if(!(!E||C)){L(!0);try{await i(E,G),I(""),h(!1),y(!1),m(!1)}finally{L(!1)}}},T=()=>{y(!1)},Z=()=>{I(""),h(!1),y(!1)};return o.useEffect(()=>{x||(d(""),h(!1),y(!1),I(""))},[x]),t.jsxs(gs,{open:x,onOpenChange:m,children:[t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(ms,{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:u,children:[t.jsx(D,{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(D,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),t.jsx(It,{sideOffset:8,children:c("gitView.branch.currentBranchTooltip")})]}),t.jsx(ps,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:t.jsxs(ci,{className:"h-full min-h-0",children:[t.jsx(di,{placeholder:c("gitView.branch.searchPlaceholder"),value:g,onValueChange:d,onKeyDown:v}),t.jsxs(ui,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(mi,{children:c("gitView.branch.empty")}),t.jsx(en,{children:f?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:C,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(D,{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:E})," ",c("gitView.branch.pushToSuffix")]})]}),t.jsx("div",{className:"flex flex-col gap-1",children:l.map(G=>t.jsxs("button",{type:"button",onClick:()=>z(G),disabled:C,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:[C?t.jsx(D,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,G.name]}),t.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:G.pushUrl})]},G.name))})]}):b?t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[t.jsx("input",{ref:k,placeholder:c("gitView.branch.newBranchPlaceholder"),value:P,onChange:G=>I(G.target.value),onClick:G=>G.stopPropagation(),onKeyDown:G=>{v(G),G.key==="Enter"?(G.preventDefault(),A()):G.key==="Escape"&&(G.preventDefault(),Z())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),t.jsx("button",{type:"button",onClick:A,disabled:!E||C,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:C?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"add",className:"size-4"})}),t.jsx("button",{type:"button",onClick:Z,disabled:C,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(D,{name:"close",className:"size-4"})})]}):t.jsxs(Bs,{onSelect:S,children:[t.jsx(D,{name:"add",className:"size-4"}),t.jsx("span",{children:c("gitView.branch.create")})]})}),t.jsx(Hn,{}),t.jsxs(en,{heading:c("gitView.branch.localBranches"),children:[K.map(G=>t.jsxs(Bs,{onSelect:()=>M(G),children:[t.jsxs("span",{className:"flex flex-1 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:G}),(a?.[G]?.ahead||a?.[G]?.behind)&&t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[a[G].ahead||0," ahead ·"," ",a[G].behind||0," behind"]})]}),s===G&&t.jsx("span",{className:"typography-micro text-primary",children:c("gitView.branch.currentBadge")})]},`local-${G}`)),K.length===0&&t.jsx(Bs,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noLocalBranches")})})]}),t.jsx(Hn,{}),t.jsxs(en,{heading:c("gitView.branch.remoteBranches"),children:[U.map(G=>t.jsx(Bs,{onSelect:()=>M(G),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:G})},`remote-${G}`)),U.length===0&&t.jsx(Bs,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noRemoteBranches")})})]})]})]})})]})},Sj=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Cj=({currentBranch:s,onRename:e,showEditButton:n=!0})=>{const{t:a}=st(),[r,i]=o.useState(!1),[l,u]=o.useState(s||""),[c,x]=o.useState(!1),m=o.useRef(null),g=()=>{!s||!e||(u(s),i(!0),setTimeout(()=>m.current?.focus(),0))},d=async()=>{if(!s||!e||!l.trim())return;const f=Sj(l);if(f===s){i(!1);return}x(!0);try{await e(s,f),i(!1),u("")}finally{x(!1)}},b=()=>{i(!1),u("")},h=f=>{f.key==="Enter"?(f.preventDefault(),d()):f.key==="Escape"&&(f.preventDefault(),b())};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:f=>{f.preventDefault(),d()},children:[t.jsx(D,{name:"git-branch",className:"size-4 text-primary"}),t.jsx("input",{ref:m,value:l,onChange:f=>u(f.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:h,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(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"check",className:"size-4"})}),t.jsx("button",{type:"button",onClick:b,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(D,{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(D,{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:g,title:a("gitView.branch.renameTitle"),children:t.jsx(D,{name:"edit",className:"size-4"})})]})]})},Ij={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},Pj={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 ad(s){return s&&Pj[s]||"var(--primary)"}const Yl=s=>{const e=Ze.c(8),{icon:n,className:a,colorToken:r}=s,i=Ij[n??"branch"]??"user-3";let l;e[0]!==r?(l=ad(r),e[0]=r,e[1]=l):l=e[1];let u;e[2]!==l?(u={color:l},e[2]=l,e[3]=u):u=e[3];let c;return e[4]!==a||e[5]!==i||e[6]!==u?(c=t.jsx(D,{name:i,className:a,style:u}),e[4]=a,e[5]=i,e[6]=u,e[7]=c):c=e[7],c},rd=s=>{const e=Ze.c(35),{activeProfile:n,identities:a,onSelect:r,isApplying:i,iconOnly:l}=s,u=l===void 0?!1:l,{t:c}=st(),x=i||a.length===0,m=n?.color;let g;e[0]!==m?(g=ad(m),e[0]=m,e[1]=g):g=e[1];let d;e[2]!==g?(d={color:g},e[2]=g,e[3]=d):d=e[3];let b;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(b=i?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(Yl,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=b):b=e[7];let h;e[8]!==n?.name||e[9]!==u||e[10]!==c?(h=!u&&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]=u,e[10]=c,e[11]=h):h=e[11];let f;e[12]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=f):f=e[12];let y;e[13]!==x||e[14]!==d||e[15]!==b||e[16]!==h?(y=t.jsx(Ct,{asChild:!0,children:t.jsx(ms,{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:d,disabled:x,children:[b,h,f]})})}),e[13]=x,e[14]=d,e[15]=b,e[16]=h,e[17]=y):y=e[17];let P;e[18]!==c?(P=c("gitView.header.identityTooltip"),e[18]=c,e[19]=P):P=e[19];let I;e[20]!==P?(I=t.jsx(It,{sideOffset:8,children:P}),e[20]=P,e[21]=I):I=e[21];let C;e[22]!==I||e[23]!==y?(C=t.jsxs(St,{children:[y,I]}),e[22]=I,e[23]=y,e[24]=C):C=e[24];let L;e[25]!==n?.id||e[26]!==a||e[27]!==r||e[28]!==c?(L=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(w=>{const E=n?.id===w.id;return t.jsx(Ns,{onSelect:()=>r(w),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(Yl,{icon:w.icon,colorToken:w.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:w.name}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:w.userEmail})]}),E?t.jsx(D,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},w.id)}),e[25]=n?.id,e[26]=a,e[27]=r,e[28]=c,e[29]=L):L=e[29];let k;e[30]!==L?(k=t.jsx(ps,{align:"end",className:"w-64",children:L}),e[30]=L,e[31]=k):k=e[31];let v;return e[32]!==C||e[33]!==k?(v=t.jsxs(gs,{children:[C,k]}),e[32]=C,e[33]=k,e[34]=v):v=e[34],v},Aj=s=>{const e=Ze.c(21),{comparison:n,trackingBranch:a,tooltipDelayMs:r}=s,i=r===void 0?1e3:r,{t:l}=st(),u=`${n.remote}/${n.branch}`,c=n.ahead===0&&n.behind===0;let x;e[0]!==l||e[1]!==u||e[2]!==a?(x=a?l("gitView.header.upstreamTooltipTracking",{target:u,tracking:a}):l("gitView.header.upstreamTooltip",{target:u}),e[0]=l,e[1]=u,e[2]=a,e[3]=x):x=e[3];const m=x;let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=t.jsx(D,{name:"git-branch",className:"size-3.5 shrink-0"}),e[4]=g):g=e[4];let d;e[5]!==u?(d=t.jsx("span",{className:"min-w-0 truncate text-foreground/80",children:u}),e[5]=u,e[6]=d):d=e[6];let b;e[7]!==n.ahead||e[8]!==n.behind||e[9]!==c||e[10]!==l?(b=c?t.jsx("span",{className:"tabular-nums text-muted-foreground",children:l("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]=l,e[11]=b):b=e[11];let h;e[12]!==d||e[13]!==b?(h=t.jsx(Ct,{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:[g,d,b]})}),e[12]=d,e[13]=b,e[14]=h):h=e[14];let f;e[15]!==m?(f=t.jsx(It,{sideOffset:8,children:m}),e[15]=m,e[16]=f):f=e[16];let y;return e[17]!==h||e[18]!==f||e[19]!==i?(y=t.jsxs(St,{delayDuration:i,children:[h,f]}),e[17]=h,e[18]=f,e[19]=i,e[20]=y):y=e[20],y},cw=s=>{const e=Ze.c(54),{status:n,localBranches:a,remoteBranches:r,branchInfo:i,syncAction:l,remotes:u,onFetch:c,onSync:x,onRemoveRemote:m,removingRemoteName:g,onCheckoutBranch:d,onCreateBranch:b,onRenameBranch:h,activeIdentityProfile:f,availableIdentities:y,onSelectIdentity:P,isApplyingIdentity:I,isWorktreeMode:C,onOpenHistory:L,onOpenGraph:k,onOpenStashes:v,actionTabItems:w,activeActionTab:E,onSelectActionTab:K}=s,{t:U}=st();if(!n)return null;let M;e[0]!==k||e[1]!==L||e[2]!==v||e[3]!==U?(M=L||k||v?t.jsxs(gs,{children:[t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(ms,{asChild:!0,children:t.jsx(J,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":U("gitView.header.repositoryViews"),children:t.jsx(D,{name:"git-repository",className:"size-4"})})})}),t.jsx(It,{sideOffset:8,children:U("gitView.header.repositoryViews")})]}),t.jsxs(ps,{align:"end",children:[L?t.jsxs(Ns,{onSelect:L,children:[t.jsx(D,{name:"history",className:"size-4"}),U("gitView.history.title")]}):null,k?t.jsxs(Ns,{onSelect:k,children:[t.jsx(D,{name:"git-merge",className:"size-4"}),U("gitView.graph.title")]}):null,v?t.jsxs(Ns,{onSelect:v,children:[t.jsx(D,{name:"archive-stack",className:"size-4"}),U("gitView.stashes.title")]}):null]})]}):null,e[0]=k,e[1]=L,e[2]=v,e[3]=U,e[4]=M):M=e[4];let S;e[5]!==M?(S=t.jsx("div",{className:"flex items-center gap-1 shrink-0",children:M}),e[5]=M,e[6]=S):S=e[6];const A=S,z=!n;let T;e[7]!==n.tracking?(T=n.tracking?.split("/")[0],e[7]=n.tracking,e[8]=T):T=e[8];const Z=(n.files?.length??0)>0;let G;e[9]!==c||e[10]!==m||e[11]!==x||e[12]!==u||e[13]!==g||e[14]!==n.ahead||e[15]!==n.behind||e[16]!==l||e[17]!==z||e[18]!==T||e[19]!==Z?(G=t.jsx(Vv,{syncAction:l,remotes:u,onFetch:c,onSync:x,onRemoveRemote:m,removingRemoteName:g,disabled:z,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:T,hasUncommittedChanges:Z}),e[9]=c,e[10]=m,e[11]=x,e[12]=u,e[13]=g,e[14]=n.ahead,e[15]=n.behind,e[16]=l,e[17]=z,e[18]=T,e[19]=Z,e[20]=G):G=e[20];const te=G;let Y;e[21]!==n.tracking||e[22]!==n.upstreamComparison?(Y=n.upstreamComparison?t.jsx(Aj,{comparison:n.upstreamComparison,trackingBranch:n.tracking,tooltipDelayMs:1e3}):null,e[21]=n.tracking,e[22]=n.upstreamComparison,e[23]=Y):Y=e[23];const N=Y;let W;e[24]!==f||e[25]!==y||e[26]!==I||e[27]!==P?(W=t.jsx(rd,{activeProfile:f,identities:y,onSelect:P,isApplying:I,iconOnly:!0}),e[24]=f,e[25]=y,e[26]=I,e[27]=P,e[28]=W):W=e[28];const B=W;let F;e[29]!==i||e[30]!==C||e[31]!==a||e[32]!==d||e[33]!==b||e[34]!==h||e[35]!==r||e[36]!==u||e[37]!==n.current?(F=t.jsx("div",{className:"min-w-0 flex-1",children:C?t.jsx(Cj,{currentBranch:n.current,onRename:h}):t.jsx(kj,{currentBranch:n.current,localBranches:a,remoteBranches:r,branchInfo:i,onCheckout:d,onCreate:b,remotes:u})}),e[29]=i,e[30]=C,e[31]=a,e[32]=d,e[33]=b,e[34]=h,e[35]=r,e[36]=u,e[37]=n.current,e[38]=F):F=e[38];let O;e[39]!==B||e[40]!==A?(O=t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[A,B]}),e[39]=B,e[40]=A,e[41]=O):O=e[41];let Q;e[42]!==O||e[43]!==F?(Q=t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[F,O]}),e[42]=O,e[43]=F,e[44]=Q):Q=e[44];let H;e[45]!==w||e[46]!==E||e[47]!==K||e[48]!==te||e[49]!==N?(H=w&&E&&K?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(Rn,{items:w,activeId:E,onSelect:K,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),N?t.jsx("div",{className:"min-w-0 shrink",children:N}):null,t.jsx("div",{className:"shrink-0",children:te})]}):null,e[45]=w,e[46]=E,e[47]=K,e[48]=te,e[49]=N,e[50]=H):H=e[50];let ie;return e[51]!==Q||e[52]!==H?(ie=t.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[Q,H]}),e[51]=Q,e[52]=H,e[53]=ie):ie=e[53],ie},Dj=s=>s==="/",lr=s=>s.replace(/\\/g,"/"),Oi=s=>{if(!s||Dj(s))return s;let e=s;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},Qn=s=>s.endsWith("/"),Ej=s=>{const e=s.trim();return!e||Qn(e)?e:`${e}/`},zi=s=>s.lastIndexOf("/"),id=s=>{if(Qn(s))return s;const e=zi(s);return e<0?s:s.slice(0,e+1)},Mj=s=>{const e=zi(s);return s.slice(e+1)},od=s=>{const e=Oi(s.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=zi(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},Tj=s=>Qn(s)&&od(s)!==null,Rj=(s,e)=>`${id(s)}${e}/`,In=s=>{if(!s)return null;const e=Oi(lr(s.trim()));return e?e.toLowerCase():null},Xl=(s,e)=>{const n=s.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},Fj=s=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey,ai=s=>{if(!s)return;s.focus({preventScroll:!0});const e=s.value.length;s.setSelectionRange(e,e),s.scrollLeft=s.scrollWidth},Lj=async()=>{try{const s=await dt("/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 lr(e.home.trim())}}catch{}return vs.getFilesystemHome().catch(()=>null)},dw=({open:s,onOpenChange:e})=>{const{t:n}=st(),a=ws(j=>j.homeDirectory),r=es(j=>j.projects),i=es(j=>j.addProject),l=Is(j=>j.profiles),u=Is(j=>j.globalIdentity),c=Is(j=>j.defaultGitIdentityId),x=Is(j=>j.loadProfiles),m=Is(j=>j.loadGlobalIdentity),g=Is(j=>j.loadDefaultGitIdentityId),{isDesktop:d,requestAccess:b,startAccessing:h}=wj(),{isMobile:f}=Ms(),y=o.useRef(null),P=o.useRef(null),I=o.useRef(new Map),[C,L]=o.useState(""),[k,v]=o.useState("~/"),[w,E]=o.useState([]),[K,U]=o.useState(!1),[M,S]=o.useState(!1),[A,z]=o.useState(0),[T,Z]=o.useState(!1),[G,te]=o.useState(!1),[Y,N]=o.useState(0),[W,B]=o.useState(!1),[F,O]=o.useState(""),[Q,H]=o.useState(null),[ie,oe]=o.useState(!1),se=C||a,xe=o.useMemo(()=>new Set(r.map(j=>In(j.path)).filter(j=>!!j)),[r]);o.useEffect(()=>{if(!s)return;v("~/"),E([]),z(0),Z(!1),te(!1),B(!1),O(""),H(null),oe(!1),requestAnimationFrame(()=>ai(y.current));let j=!1;return(async()=>{const Ae=await Lj();j||(L(Ae||a||""),requestAnimationFrame(()=>ai(y.current)))})(),()=>{j=!0}},[a,s]),o.useEffect(()=>{s&&(x(),m(),g())},[g,x,m,s]);const ae=o.useMemo(()=>{const j=new Map;u&&j.set(u.id,u);for(const be of l)j.set(be.id,be);return Array.from(j.values())},[l,u]);o.useEffect(()=>{if(!s||!W||Q!==null)return;const j=typeof c=="string"?c.trim():"";if(j&&ae.some(Ae=>Ae.id===j)){H(j);return}const be=ae.find(Ae=>Ae.authType==="ssh"||Ae.sshKey);be&&H(be.id)},[ae,c,W,s,Q]);const fe=o.useMemo(()=>ae.find(j=>j.id===Q)??null,[ae,Q]),Ce=o.useMemo(()=>id(k),[k]),ge=o.useMemo(()=>Qn(k)?"":Mj(k),[k]),ve=o.useMemo(()=>se?Xl(Ce,se):"",[Ce,se]);o.useEffect(()=>{if(!s||!ve){E([]);return}let j=!1;return U(!0),S(!1),vs.listLocalDirectory(ve).then(be=>{if(j)return;S(!1);const Ae=be.filter(ze=>ze.isDirectory).map(ze=>({name:ze.name,path:lr(ze.path)})).sort((ze,Ge)=>ze.name.localeCompare(Ge.name));E(Ae)}).catch(()=>{j||(E([]),S(!0))}).finally(()=>{j||U(!1)}),()=>{j=!0}},[ve,s]);const Ne=o.useMemo(()=>{const j=ge.toLowerCase(),be=ie||ge.startsWith(".");return w.filter(Ae=>Ae.name.toLowerCase().startsWith(j)&&(be||!Ae.name.startsWith(".")))},[ge,w,ie]),ne=o.useMemo(()=>{const j=[];Tj(k)&&j.push({type:"up",value:"browse:up",name:"..",path:od(k)});for(const be of Ne){const Ae=In(be.path);j.push({type:"directory",value:`browse:${be.path}`,name:be.name,path:be.path,disabled:!!(Ae&&xe.has(Ae))})}return j},[xe,Ne,k]);o.useEffect(()=>{z(0)},[k,ne.length]);const re=o.useMemo(()=>se?Oi(Xl(k,se)):"",[se,k]),ye=In(re),q=!!(ye&&xe.has(ye)),$=o.useMemo(()=>ge?Ne.find(j=>j.name===ge)??null:null,[ge,Ne]),ee=!!(re&&!q&&(Qn(k)&&M||!Qn(k)&&ge.trim().length>0&&$===null)),de=!T&&!G&&!q&&!!re,De=de&&F.trim().length>0,ke=ne[A]??null,Pe=!!(ke&&(ke.type==="up"||ke.type==="directory"&&!ke.disabled)),Me=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Te=n(q?"directoryExplorerDialog.actions.alreadyAdded":W?T?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":T?"directoryExplorerDialog.actions.adding":ee?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const j=P.current;if(!j)return;const be=()=>N(Math.ceil(j.getBoundingClientRect().width));if(be(),typeof ResizeObserver>"u")return;const Ae=new ResizeObserver(be);return Ae.observe(j),()=>Ae.disconnect()},[Te]),o.useLayoutEffect(()=>{const j=y.current;j&&(j.scrollLeft=j.scrollWidth)},[Y,k]),o.useLayoutEffect(()=>{s&&ai(y.current)},[s]),o.useLayoutEffect(()=>{const j=ne[A];j&&I.current.get(j.value)?.scrollIntoView({block:"nearest"})},[A,ne]);const Ve=o.useCallback(()=>{e(!1)},[e]),Ue=o.useCallback((j,be)=>{j.stopPropagation();const Ae=In(be);if(Ae&&xe.has(Ae))return;i(be)||_.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")})},[i,xe,n]),Oe=o.useCallback(async j=>{if(!j||T)return;const be=In(j);if(be&&xe.has(be))return;let Ae=j;Z(!0);try{const ze=!W&&ee&&In(j)===In(re);if(W){const rt=F.trim();if(!rt){_.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ae=(await vs.cloneRepository({remoteUrl:rt,destinationPath:j,gitIdentityId:fe?.id??null})).path}else ze&&await vs.createDirectory(j);if(!i(Ae)){_.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}Ve()}catch(ze){_.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:ze instanceof Error?ze.message:n("directoryExplorerDialog.toast.unknownError")})}finally{Z(!1)}},[i,xe,F,Ve,W,T,fe?.id,ee,re,n]),_e=o.useCallback(j=>{v(Ej(j))},[]),Ke=o.useCallback(j=>{v(Rj(k,j.name))},[k]),Qe=o.useCallback(j=>{if(j){if(j.type==="up"){j.path&&_e(j.path);return}j.disabled||Ke(j)}},[_e,Ke]),Fe=o.useCallback(async()=>{if(!(!d||G)){te(!0);try{const j=await b(re);if(!j.success||!j.path){j.error&&j.error!=="Directory selection cancelled"&&_.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:j.error});return}const be=await h(j.path);if(!be.success){_.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:be.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Oe(j.path)}catch(j){_.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:j instanceof Error?j.message:n("directoryExplorerDialog.toast.unknownError")})}finally{te(!1)}}},[Oe,d,G,b,h,n,re]),V=o.useCallback(j=>{if(j.key==="ArrowDown"){j.preventDefault(),z(be=>Math.min(ne.length-1,be+1));return}if(j.key==="ArrowUp"){j.preventDefault(),z(be=>Math.max(0,be-1));return}if(j.key==="Enter"){if(j.preventDefault(),Fj(j)){Oe(re);return}Pe&&Qe(ke);return}j.key==="Backspace"&&k===""&&(j.preventDefault(),Ve())},[Qe,Oe,Ve,Pe,ke,k,ne.length,re]),le=t.jsxs("button",{type:"button",onClick:()=>oe(j=>!j),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:[ie?t.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}):t.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),pe=t.jsxs("div",{className:"px-2.5 py-1.5",children:[W?t.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[t.jsx(Xe,{value:F,onChange:j=>O(j.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(rd,{activeProfile:fe,identities:ae,onSelect:j=>H(j.id),isApplying:T,iconOnly:!0})]}):null,t.jsxs("div",{className:"relative",children:[t.jsx(D,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),t.jsx(Xe,{ref:y,value:k,onChange:j=>v(lr(j.target.value)),onKeyDown:V,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!f&&Y>0?{paddingRight:`${Y+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),f?null:t.jsx(J,{ref:P,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:W?!De:!de,onMouseDown:j=>j.preventDefault(),onClick:()=>{Oe(re)},title:Te,children:Te})]})]}),Le=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")}),K?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):ne.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:ne.map((j,be)=>{const Ae=be===A;return t.jsxs("button",{ref:ze=>{ze?I.current.set(j.value,ze):I.current.delete(j.value)},type:"button",disabled:j.type==="directory"&&j.disabled,onMouseEnter:()=>z(be),onMouseDown:ze=>ze.preventDefault(),onClick:()=>Qe(j),className:ce("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",Ae&&"bg-interactive-selection text-interactive-selection-foreground",!Ae&&"hover:bg-interactive-hover/50",j.type==="directory"&&j.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[j.type==="up"?t.jsx(D,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):t.jsx(D,{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:j.name})}),j.type==="directory"&&j.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")}):j.type==="directory"?t.jsx("button",{type:"button",onMouseDown:ze=>ze.stopPropagation(),onClick:ze=>Ue(ze,j.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(D,{name:"add",className:"h-3.5 w-3.5"})}):null]},j.value)})})]})}),we=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[pe,Le]}),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(D,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),t.jsx(D,{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(D,{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:Me}),t.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),X=()=>t.jsxs(t.Fragment,{children:[f?null:He,t.jsxs("div",{className:ce("flex w-full flex-row justify-end gap-2 sm:w-auto",f&&"justify-stretch"),children:[d?t.jsx(J,{variant:"ghost",size:"xs",onClick:Fe,disabled:T||G||W,children:n(G?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,t.jsx(J,{variant:"ghost",size:"xs",onClick:()=>B(j=>!j),disabled:T||G,className:ce(f&&"flex-1"),children:n(W?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),f?t.jsx(J,{size:"xs",onClick:()=>{Oe(re)},disabled:W?!De:!de,className:"flex-1",children:Te}):null]})]});return f?t.jsx(xa,{open:s,onClose:Ve,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:X()}),children:t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[t.jsx("div",{className:"flex justify-end",children:le}),we]})}):t.jsx(Mt,{open:s,onOpenChange:e,children:t.jsxs(Tt,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(zt,{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(Ot,{children:n("directoryExplorerDialog.title")}),t.jsx(Bt,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),le]})}),t.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:we}),t.jsx(qt,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:X()})]})})};function Zl(s){const{localBranches:e,remoteBranches:n,query:a}=s,r=a.trim();if(!r)return{matching:[],otherLocal:e,otherRemote:n};const i=so(e,r,m=>m),l=so(n,r,m=>m),u=[],c=i.other,x=l.other;for(const m of i.matching)u.push({label:m,value:m,source:"local"});for(const m of l.matching)u.push({label:m,value:`remotes/${m}`,source:"remote"});return u.sort((m,g)=>{const d=m.label.localeCompare(g.label,void 0,{sensitivity:"accent"});return d!==0?d:m.source!==g.source?m.source.localeCompare(g.source):m.value.localeCompare(g.value)}),{matching:u,otherLocal:c,otherRemote:x}}const ri="oc:lastWorktreeSourceBranch",Oj=({mode:s,sourceBranch:e,linkedPr:n,selectedBranch:a})=>s==="existing-branch"?a||null:n?null:e||null,zj=({branches:s,savedSourceBranch:e,rootBranch:n})=>!!(e&&s.includes(e))&&e?{sourceBranch:e,shouldClearSavedSourceBranch:!1}:{sourceBranch:n&&s.includes(n)?n:s.includes("main")?"main":s.includes("master")?"master":s[0]??"",shouldClearSavedSourceBranch:!!e};function Kj({open:s,onOpenChange:e,onSelect:n}){const{t:a}=st(),r=Ie(ne=>ne.isMobile),{github:i}=Di(),l=nn(ne=>ne.status),u=nn(ne=>ne.hasChecked),c=Ie(ne=>ne.setSettingsDialogOpen),x=Ie(ne=>ne.setSettingsPage),m=es(ne=>ne.getActiveProject()),g=m?.path??null,d=he.useMemo(()=>g&&m?{id:m.id,path:g}:null,[m,g]),[b,h]=he.useState("issues"),[f,y]=he.useState(""),[P,I]=he.useState([]),[C,L]=he.useState([]),[k,v]=he.useState(!1),[w,E]=he.useState(!1),[K,U]=he.useState(null),[M,S]=he.useState(null),[A,z]=he.useState(null),[T,Z]=he.useState(!1),[G,te]=he.useState(new Map),[Y,N]=he.useState(1),[W,B]=he.useState(!1),F=jm(f,350),O=he.useCallback(async ne=>{if(!(!g||!i)&&!(u&&l?.connected===!1)){v(!0),U(null),N(1),B(!1);try{if(b==="issues"&&i.issuesList){const re=await i.issuesList(g,{page:1,query:ne});re.connected===!1?(U(a("session.githubIntegration.error.notConnected")),I([])):(I(re.issues??[]),N(re.page??1),B(!!re.hasMore))}else if(b==="prs"&&i.prsList){const re=await i.prsList(g,{page:1,query:ne});re.connected===!1?(U(a("session.githubIntegration.error.notConnected")),L([])):(L(re.prs??[]),N(re.page??1),B(!!re.hasMore))}}catch(re){U(re instanceof Error?re.message:a("session.githubIntegration.error.loadDataFailed"))}finally{v(!1)}}},[g,i,u,l,b,a]);he.useEffect(()=>{if(!s||!g||u&&l?.connected===!1||!i)return;if(!F.trim()){O();return}const ne=new AbortController;v(!0),U(null),N(1),B(!1);const re=b==="issues"&&i.issuesList?i.issuesList(g,{page:1,query:F.trim()}):b==="prs"&&i.prsList?i.prsList(g,{page:1,query:F.trim()}):null;if(!re){v(!1);return}return re.then(ye=>{ne.signal.aborted||("issues"in ye?ye.connected===!1?(U(a("session.githubIntegration.error.notConnected")),I([])):(I(ye.issues??[]),N(ye.page??1),B(!!ye.hasMore)):"prs"in ye&&(ye.connected===!1?(U(a("session.githubIntegration.error.notConnected")),L([])):(L(ye.prs??[]),N(ye.page??1),B(!!ye.hasMore))))}).catch(ye=>{ne.signal.aborted||U(ye instanceof Error?ye.message:a("session.githubIntegration.error.loadDataFailed"))}).finally(()=>{ne.signal.aborted||v(!1)}),()=>ne.abort()},[s,g,i,u,l,b,F,O,a]);const Q=he.useCallback(async()=>{if(!(!g||!i)&&!(k||w)&&W){E(!0);try{const ne=Y+1;if(b==="issues"&&i.issuesList){const re=F.trim()?await i.issuesList(g,{page:ne,query:F.trim()}):await i.issuesList(g,{page:ne});re.connected!==!1&&(I(ye=>[...ye,...re.issues??[]]),N(re.page??ne),B(!!re.hasMore))}else if(b==="prs"&&i.prsList){const re=F.trim()?await i.prsList(g,{page:ne,query:F.trim()}):await i.prsList(g,{page:ne});re.connected!==!1&&(L(ye=>[...ye,...re.prs??[]]),N(re.page??ne),B(!!re.hasMore))}}catch{}finally{E(!1)}}},[g,i,b,Y,W,k,w,F]);he.useEffect(()=>{if(!s){h("issues"),y(""),I([]),L([]),S(null),z(null),Z(!1),U(null),te(new Map),N(1),B(!1);return}O()},[s,O]);const H=he.useCallback(async ne=>{if(!(!d||!ne)&&!G.has(ne))try{const ye=(await fc(d,{mode:"new",branchName:ne,worktreeName:ne})).errors.find(q=>q.code==="branch_in_use");te(q=>new Map(q).set(ne,{isValid:!ye,error:ye?a(ye.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{te(re=>new Map(re).set(ne,{isValid:!1,error:a("session.githubIntegration.validation.failed")}))}},[d,G,a]);he.useEffect(()=>{!s||b!=="prs"||C.forEach(ne=>{ne.head&&H(ne.head)})},[s,b,C,H]);const ie=u&&l?.connected===!0,oe=()=>{x("github"),c(!0)},se=ne=>{S(ne),z(null)},xe=ne=>{z(ne),S(null)},ae=()=>{M?n({type:"issue",item:M}):A&&n({type:"pr",item:A,includeDiff:T}),e(!1)},fe=()=>{S(null),z(null),Z(!1)},Ce=M||A&&G.get(A.head??"")?.isValid!==!1,ge=ne=>ne.head?G.get(ne.head)?.isValid===!1:!0,ve=t.jsx(t.Fragment,{children:ie?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative mt-2",children:[t.jsx(D,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),t.jsx(Xe,{value:f,onChange:ne=>y(ne.target.value),placeholder:a(b==="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:[k&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx(D,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),K&&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(D,{name:"error-warning",className:"h-4 w-4"}),t.jsx("span",{className:"typography-small",children:K})]})}),!k&&!K&&b==="issues"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[P.length>0?P.map(ne=>t.jsx("button",{onClick:()=>se(ne),className:ce("w-full text-left px-2 py-1.5 rounded transition-colors",M?.number===ne.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:["#",ne.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-2",children:ne.title}),ne.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:[ne.sourceRepo.owner,"/",ne.sourceRepo.repo]}):null]})]})},`${ne.sourceRepo?.owner??""}-${ne.sourceRepo?.repo??""}-${ne.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")}),W&&!w&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(J,{variant:"ghost",size:"sm",onClick:()=>{Q()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),w&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(D,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!k&&!K&&b==="prs"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[C.length>0?C.map(ne=>{const re=ge(ne),ye=ne.head?G.get(ne.head):void 0;return t.jsx("button",{onClick:()=>!re&&xe(ne),disabled:re,className:ce("w-full text-left px-2 py-1.5 rounded transition-colors",A?.number===ne.number?"bg-interactive-selection text-interactive-selection-foreground":re?"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:["#",ne.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-1",children:ne.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[ne.head," → ",ne.base]}),ne.sourceRepo?.source==="upstream"?t.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[ne.sourceRepo.owner,"/",ne.sourceRepo.repo]}):null,re&&ye?.error&&t.jsx("span",{className:"typography-micro text-destructive",children:ye.error})]})]})]})},`${ne.sourceRepo?.owner??""}-${ne.sourceRepo?.repo??""}-${ne.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")}),W&&!w&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(J,{variant:"ghost",size:"sm",onClick:()=>{Q()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),w&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(D,{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(D,{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:oe,size:"sm",children:a("session.githubIntegration.connect.action")})]})}),Ne=t.jsxs("div",{className:ce("w-full",r?"flex flex-col gap-2":"flex flex-row items-center"),children:[t.jsxs("div",{className:ce("flex items-center gap-4",r?"w-full justify-center order-1":"flex-1"),children:[!r&&(M||A)&&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(D,{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:M?a("session.githubIntegration.selected.issueNumber",{number:M.number}):a("session.githubIntegration.selected.prNumber",{number:A?.number??""})}),t.jsx("button",{onClick:fe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]}),b==="prs"&&A&&t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[t.jsx(xt,{checked:T,onChange:ne=>Z(ne),ariaLabel:a("session.githubIntegration.includeDiffAria")}),t.jsx("span",{className:"typography-small text-foreground",children:a("session.githubIntegration.includeDiff")})]})]}),t.jsxs("div",{className:ce("flex gap-2",r?"w-full order-2":"justify-end"),children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>e(!1),className:ce(r&&"flex-1"),children:a("session.githubIntegration.actions.cancel")}),t.jsx(J,{size:"sm",onClick:ae,disabled:!Ce,className:ce(r&&"flex-1"),children:a("session.githubIntegration.actions.select")})]})]});return t.jsx(t.Fragment,{children:r?t.jsx(xa,{open:s,title:a("session.githubIntegration.title"),onClose:()=>e(!1),footer:ie?Ne:void 0,renderHeader:ne=>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")}),ne]}),t.jsx("div",{className:"w-full",children:t.jsx(Rn,{items:[{id:"issues",label:a("session.githubIntegration.tabs.issues"),icon:t.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:a("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(D,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:re=>{h(re),y("")},variant:"active-pill",layoutMode:"fit"})}),(M||A)&&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(D,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),t.jsx("span",{className:"typography-small truncate flex-1",children:M?a("session.githubIntegration.selected.issueNumber",{number:M.number}):a("session.githubIntegration.selected.prNumber",{number:A?.number??""})}),t.jsx("button",{onClick:fe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:ve}):t.jsx(Mt,{open:s,onOpenChange:e,children:t.jsxs(Tt,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsx(zt,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(Ot,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(D,{name:"github",className:"h-5 w-5"}),a("session.githubIntegration.title")]}),t.jsx("div",{className:"w-[220px]",children:t.jsx(Rn,{items:[{id:"issues",label:a("session.githubIntegration.tabs.issues"),icon:t.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:a("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(D,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:ne=>{h(ne),y("")},variant:"active-pill",layoutMode:"fit"})})]})}),ve,t.jsx(qt,{className:"mt-1",children:Ne})]})})})}const fa=s=>s.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),xs=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),Uj=s=>String(s).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",ec=(s,e,n)=>{const a=fa(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(),l=s.headRepo?.owner||i||"pr-head",u=`pr-${Uj(l)}`,c=s.headRepo?.sshUrl||s.headRepo?.cloneUrl||"";if(!c)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${u}/${a}`,setUpstream:!0,upstreamRemote:u,upstreamBranch:a,ensureRemoteName:u,ensureRemoteUrl:c,sourceLabel:`${u}/${a}`}},Bj=s=>{const e={repo:s.repo??null,issue:s.issue,comments:s.comments};return`GitHub issue context (JSON)
166
+ ${JSON.stringify(e,null,2)}`},$j=s=>`GitHub pull request context (JSON)
167
+ ${JSON.stringify(s,null,2)}`;function uw({open:s,onOpenChange:e,onWorktreeCreated:n}){const{t:a}=st(),{github:r,git:i}=Di(),l=Ie(X=>X.isMobile),u=nn(X=>X.status),c=nn(X=>X.hasChecked),x=es(X=>X.getActiveProject()),m=x?.path??null,g=he.useMemo(()=>m&&x?{id:x.id,path:m}:null,[x,m]),[d,b]=he.useState("new-branch"),[h,f]=he.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[y,P]=he.useState({selectedBranch:"",worktreeName:""}),I=wm(m),C=Nm(m),L=km(X=>X.fetchBranches),k=he.useMemo(()=>I?.all?I.all.filter(X=>!X.startsWith("remotes/")).sort():[],[I]),v=he.useMemo(()=>I?.all?I.all.filter(X=>X.startsWith("remotes/")).map(X=>X.replace(/^remotes\//,"")).sort():[],[I]),w=ys(X=>X.availableWorktreesByProject),E=he.useMemo(()=>{if(!m)return new Set;const X=w.get(m)??[];return new Set(X.map(j=>j.name))},[w,m]),K=he.useCallback((X=10)=>{for(let j=0;j<X;j++){const be=Pr();if(!E.has(be))return be}return`${Pr()}-${Date.now().toString(36).slice(-4)}`},[E]),[U,M]=he.useState(!1),[S,A]=he.useState(!1),[z,T]=he.useState(!1),[Z,G]=he.useState(!1),[te,Y]=he.useState(!1),[N,W]=he.useState(""),[B,F]=he.useState(""),O=he.useRef(null),Q=he.useRef(null),H=he.useRef(null),ie=he.useRef(null),oe=he.useCallback(X=>{X.stopPropagation()},[]),se=he.useCallback(X=>{let j=X;for(;j&&j!==document.body;){const{overflowY:be}=window.getComputedStyle(j);if((be==="auto"||be==="scroll")&&j.scrollHeight>j.clientHeight)return j;j=j.parentElement}return null},[]),xe=he.useCallback(X=>{X&&(X.scrollTop=0)},[]),ae=he.useCallback(X=>{const j=X.current?.querySelector('[data-slot="command-list"]')??null;xe(j)},[xe]),fe=he.useCallback(X=>{const j=se(X.current);xe(j)},[se,xe]),Ce=he.useMemo(()=>Zl({localBranches:k,remoteBranches:v,query:N}),[k,v,N]),ge=he.useMemo(()=>Zl({localBranches:k,remoteBranches:v,query:B}),[k,v,B]),ve=N.trim().length>0,Ne=B.trim().length>0,ne=Ce.matching.length>0,re=ge.matching.length>0,ye=!!(m&&i),q=he.useCallback(()=>{!m||!i||L(m,i)},[m,i,L]);he.useEffect(()=>{!s||!m||!i||I?.all||L(m,i)},[s,m,i,I?.all,L]),he.useEffect(()=>{!S&&!Z&&W("")},[S,Z]),he.useEffect(()=>{!z&&!te&&F("")},[z,te]),he.useEffect(()=>{S&&ae(O),Z&&fe(H)},[S,Z,N,ae,fe]),he.useEffect(()=>{z&&ae(Q),te&&fe(ie)},[z,te,B,ae,fe]);const[$,ee]=he.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[de,De]=he.useState(!1),[ke,Pe]=he.useState(null),Me=he.useCallback(()=>{const X=ot.getState(),j=X.getVisibleAgents();if(X.settingsDefaultAgent){const be=j.find(Ae=>Ae.name===X.settingsDefaultAgent);if(be)return be.name}return j.find(be=>be.name==="build")?.name||j[0]?.name},[]),Te=he.useCallback(()=>{const X=ot.getState(),j=X.settingsDefaultModel;if(!j)return null;const be=xn(j);if(!be)return null;const{providerId:Ae,modelId:ze}=be;return X.getModelMetadata(Ae,ze)?{providerID:Ae,modelID:ze}:null},[]),Ve=he.useCallback((X,j)=>{const be=ot.getState(),Ae=be.settingsDefaultVariant,ze=be.currentProviderId===X&&be.currentModelId===j?be.currentVariant:void 0,it=be.providers.find(at=>at.id===X)?.models.find(at=>at.id===j)?.variants;if(!it)return Ae||ze||void 0;if(Ae&&Object.prototype.hasOwnProperty.call(it,Ae))return Ae;if(ze&&Object.prototype.hasOwnProperty.call(it,ze))return ze},[]),Ue=he.useCallback(async X=>{if(!m||!r)return;const j=ot.getState(),be=Sm.getState().lastUsedProvider,Ae=Te(),ze=Ae?.providerID||j.currentProviderId||be?.providerID,Ge=Ae?.modelID||j.currentModelId||be?.modelID,rt=Me()||j.currentAgentName||void 0;if(!ze||!Ge){_.error(a("session.newWorktree.error.noModelSelected"));return}const it=Ve(ze,Ge);if(X.issue){if(!r.issueGet||!r.issueComments)return;const at=await r.issueGet(m,X.issue.number,{sourceRepo:X.issue.sourceRepo??null});if(at.connected===!1||!at.repo||!at.issue)throw new Error("Failed to load issue context");const lt=await r.issueComments(m,X.issue.number,{sourceRepo:X.issue.sourceRepo??null});if(lt.connected===!1)throw new Error("Failed to load issue comments");const Ye=await Ea("github.issue.review.visible",{issue_number:String(X.issue.number)}),We=await Ea("github.issue.review.instructions"),gt=Bj({repo:at.repo,issue:at.issue,comments:lt.comments??[]});await ys.getState().sendMessage(Ye,ze,Ge,rt,void 0,void 0,[{text:We,synthetic:!0},{text:gt,synthetic:!0}],it,void 0,{sessionId:X.sessionId}),_.success(a("session.newWorktree.toast.sessionFromIssue"));return}if(X.pr){if(!r.prContext)return;const at=await r.prContext(m,X.pr.number,{sourceRepo:X.pr.sourceRepo??null,includeDiff:X.includeDiff,includeCheckDetails:!1});if(at.connected===!1||!at.repo||!at.pr)throw new Error("Failed to load PR context");const lt=await Ea("github.pr.review.visible",{pr_number:String(X.pr.number)}),Ye=await Ea("github.pr.review.instructions"),We=$j(at);await ys.getState().sendMessage(lt,ze,Ge,rt,void 0,void 0,[{text:Ye,synthetic:!0},{text:We,synthetic:!0}],it,void 0,{sessionId:X.sessionId}),_.success(a("session.newWorktree.toast.sessionFromPr"))}},[r,m,Me,Te,Ve,a]),Oe=d==="new-branch"?h:y;he.useEffect(()=>{if(!s||!I?.all||!m||h.sourceBranch)return;const X=h.sourceBranch;let j=!1;return(async()=>{try{const Ae=await Cm(m).catch(()=>null);if(j)return;const ze=localStorage.getItem(ri),{sourceBranch:Ge,shouldClearSavedSourceBranch:rt}=zj({branches:I.all,savedSourceBranch:ze,rootBranch:Ae});if(rt&&localStorage.removeItem(ri),j||X)return;Ge&&f(it=>({...it,sourceBranch:Ge}))}catch{}})(),()=>{j=!0}},[s,I?.all,m,h.sourceBranch]),he.useLayoutEffect(()=>{if(!s)return;b("new-branch"),P({selectedBranch:"",worktreeName:""}),A(!1),T(!1),G(!1),Y(!1),W(""),F(""),ee({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const X=K();f({branchName:X,worktreeName:X,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[s,K]),he.useEffect(()=>{if(d!=="new-branch"||!h.isSyncingWorktreeName)return;const X=fa(h.branchName),j=xs(X);f(be=>({...be,worktreeName:j}))},[d,h.branchName,h.isSyncingWorktreeName]);const _e=he.useCallback(async()=>{if(!g||!$.touched||de)return;ke&&ke.abort();const X=new AbortController;Pe(X),ee(j=>({...j,isValidating:!0}));try{const j=d==="new-branch"?h.branchName:y.selectedBranch,be=Oe.worktreeName,Ae=fa(j),ze=xs(be);let Ge=null,rt=null;if(Ae||(Ge=a("session.newWorktree.error.branchNameRequired")),ze||(rt=a("session.newWorktree.error.worktreeDirectoryRequired")),Ae&&ze){const it=d==="new-branch"?h.linkedPr:null,at=it?ec(it,k,v):null,lt=await fc(g,{mode:d==="existing-branch"||at?"existing":"new",branchName:Ae,worktreeName:ze,existingBranch:at?.existingBranch??(d==="existing-branch"?Ae:void 0),...at?.ensureRemoteName?{ensureRemoteName:at.ensureRemoteName}:{},...at?.ensureRemoteUrl?{ensureRemoteUrl:at.ensureRemoteUrl}:{}});if(X.signal.aborted)return;lt.ok||lt.errors.forEach(Ye=>{if(Ye.code==="worktree_exists"){rt=rt??Ye.message;return}Ye.code.startsWith("branch_")&&(Ge=Ge??Ye.message)})}X.signal.aborted||ee(it=>({...it,isValidating:!1,branchError:Ge,worktreeError:rt}))}catch{X.signal.aborted||ee(j=>({...j,isValidating:!1}))}},[g,d,h.branchName,h.linkedPr,y.selectedBranch,Oe.worktreeName,k,v,$.touched,ke,de,a]),Ke=d==="new-branch"?h.branchName:y.selectedBranch;he.useEffect(()=>{if(!s||!g||!$.touched||de)return;const X=setTimeout(()=>{_e()},300);return()=>clearTimeout(X)},[Oe.worktreeName,Ke,s,g,_e,$.touched,de]);const Qe=async()=>{if(!g||!m){_.error(a("session.newWorktree.error.noActiveProject"));return}ee(ze=>({...ze,touched:!0}));const X=d==="new-branch"?h.branchName:y.selectedBranch,j=Oe.worktreeName,be=fa(X),Ae=xs(j);if(!be){_.error(a("session.newWorktree.error.branchNameRequired"));return}if(!Ae){_.error(a("session.newWorktree.error.worktreeDirectoryRequired"));return}ke&&(ke.abort(),Pe(null)),ee(ze=>({...ze,isValidating:!1,branchError:null,worktreeError:null})),De(!0);try{const ze=d==="new-branch"?h.linkedPr:null,Ge=d==="new-branch"?h.linkedIssue:null,rt=d==="new-branch"?h.linkedPr:null,it=d==="new-branch"?h.includePrDiff:!1,at=!!(Ge||rt),lt=await uc(g),Ye=h.sourceBranch;let We="";const gt=(()=>{if(ze){const ft=ec(ze,k,v);return We=ft.sourceLabel,{preferredName:be||Ae,mode:"existing",branchName:be,worktreeName:Ae,existingBranch:ft.existingBranch,setupCommands:lt,setUpstream:ft.setUpstream,upstreamRemote:ft.upstreamRemote,upstreamBranch:ft.upstreamBranch,returnAfterDirectoryCreated:!0,...ft.ensureRemoteName?{ensureRemoteName:ft.ensureRemoteName}:{},...ft.ensureRemoteUrl?{ensureRemoteUrl:ft.ensureRemoteUrl}:{}}}return We=d==="new-branch"?Ye:"",{preferredName:be||Ae,mode:d==="existing-branch"?"existing":"new",branchName:d==="existing-branch"?void 0:be,worktreeName:Ae,existingBranch:d==="existing-branch"?be:void 0,setupCommands:lt,returnAfterDirectoryCreated:!0,...Ye&&d==="new-branch"?{startRef:Ye}:{}}})(),me=await Im(m,gt),et=await Pm(g,me);let nt=null;if(at){await mc(g)&&await Am(et.path);const ft=Ge?`#${Ge.number} ${Ge.title}`.trim():rt?`#${rt.number} ${rt.title}`.trim():a("session.newWorktree.newSessionTitle"),bt=await Dm(ft,et.path,null);if(!bt?.id)throw new Error("Failed to create session");nt=bt.id,n?.(et.path,{sessionId:nt}),e(!1),De(!1),Em(bt.id,ft).catch(()=>{});try{ys.getState().initializeNewOpenChamberSession(bt.id,ot.getState().agents)}catch{}}else e(!1),De(!1);const tt=Oj({mode:d,sourceBranch:h.sourceBranch,linkedPr:!!h.linkedPr,selectedBranch:y.selectedBranch});tt&&localStorage.setItem(ri,tt),_.success(a("session.newWorktree.toast.worktreeCreated"),{description:a("session.newWorktree.toast.worktreeCreatedDescription",{target:`${et.branch||et.name}${We?` ${a("session.newWorktree.fromSource",{source:We})}`:""}`})}),nt?Ue({sessionId:nt,directory:et.path,issue:Ge,pr:rt,includeDiff:it}).catch(ft=>{const bt=ft instanceof Error?ft.message:a("session.newWorktree.error.sendGitHubContextFailed");_.error(a("session.newWorktree.error.sendGitHubContextFailed"),{description:bt})}):n?.(et.path)}catch(ze){const Ge=ze instanceof Error?ze.message:a("session.newWorktree.error.createWorktreeFailed");_.error(a("session.newWorktree.error.createWorktreeFailed"),{description:Ge})}finally{De(!1)}},Fe=X=>{b(X),ee(j=>({...j,touched:!1,branchError:null,worktreeError:null}))},V=X=>{if(!X){f(j=>({...j,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(X.type==="issue"){const j=X.item,be=`issue-${j.number}-${Pr()}`;f(Ae=>({...Ae,linkedIssue:j,linkedPr:null,includePrDiff:!1,branchName:be,worktreeName:xs(be),isSyncingWorktreeName:!0}))}else if(X.type==="pr"){const j=X.item;f(be=>({...be,linkedPr:j,linkedIssue:null,includePrDiff:X.includeDiff??!1,branchName:j.head,worktreeName:xs(j.head),isSyncingWorktreeName:!0}))}},le=c&&u?.connected===!0,Le=(d==="existing-branch"?!!y.selectedBranch&&!!y.worktreeName&&!$.branchError&&!$.worktreeError:!!fa(h.branchName)&&!!h.worktreeName&&!$.branchError&&!$.worktreeError)&&!de,we=()=>{f(X=>({...X,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},He=t.jsxs("div",{className:ce("flex gap-2",l?"flex-col w-full":"flex-row items-center"),children:[t.jsx("div",{className:ce("flex items-center gap-1.5 text-destructive",l?"w-full justify-center order-first":"mr-auto"),children:$.touched&&($.branchError||$.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:$.branchError||$.worktreeError})]})}),t.jsxs("div",{className:ce("flex gap-2",l&&"w-full"),children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:de,className:ce(l&&"flex-1"),children:a("session.newWorktree.actions.cancel")}),t.jsxs(J,{size:"sm",onClick:Qe,disabled:!Le||de,className:ce("gap-1.5",l&&"flex-1"),children:[de&&t.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(de?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return t.jsxs(t.Fragment,{children:[l?t.jsxs(xa,{open:s,title:a("session.newWorktree.title"),onClose:()=>e(!1),footer:He,children:[t.jsx("div",{className:"w-full mb-4",children:t.jsx(Rn,{items:[{id:"new-branch",label:a("session.newWorktree.mode.newBranch"),icon:t.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:a("session.newWorktree.mode.existingBranch"),icon:t.jsx(D,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:d,onSelect:X=>Fe(X),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),t.jsxs("div",{className:"space-y-6",children:[d==="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:()=>G(!0),className:"flex-1 justify-between h-9",children:[t.jsx("span",{className:y.selectedBranch?"text-foreground":"text-muted-foreground",children:y.selectedBranch||a("session.newWorktree.chooseBranch")}),t.jsx(D,{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:q,disabled:!ye||C,title:a("session.newWorktree.fetchBranches"),children:C?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"refresh",className:"size-4"})})]}),t.jsx(xa,{open:Z,title:a("session.newWorktree.selectBranch"),onClose:()=>G(!1),children:t.jsxs("div",{className:"space-y-4",ref:H,children:[t.jsx(Xe,{value:N,onChange:X=>W(X.target.value),placeholder:a("session.newWorktree.searchBranches"),className:"h-8"}),C?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):k.length===0&&v.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:[ve&&ne&&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:Ce.matching.map(X=>t.jsx("button",{onClick:()=>{P(j=>({...j,selectedBranch:X.value,worktreeName:xs(X.label)})),ee(j=>({...j,touched:!0})),G(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",y.selectedBranch===X.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))})]}),ve&&!ne&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),Ce.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(ve?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:Ce.otherLocal.map(X=>t.jsx("button",{onClick:()=>{P(j=>({...j,selectedBranch:X,worktreeName:xs(X)})),ee(j=>({...j,touched:!0})),G(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",y.selectedBranch===X?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X})},X))})]}),Ce.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(ve?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:Ce.otherRemote.map(X=>t.jsx("button",{onClick:()=>{P(j=>({...j,selectedBranch:`remotes/${X}`,worktreeName:xs(X)})),ee(j=>({...j,touched:!0})),G(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",y.selectedBranch===`remotes/${X}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X})},`remotes/${X}`))})]})]})]})})]}):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")}),d==="new-branch"&&le&&t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"gap-1.5 h-7",children:[t.jsx(D,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(Xe,{value:h.branchName,onChange:X=>{f(j=>({...j,branchName:X.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ee(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:ce("h-8",$.touched&&$.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.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")}),d!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const X=xs(d==="new-branch"?h.branchName:"");f(j=>({...j,worktreeName:X,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===xs(h.branchName),className:ce("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===xs(h.branchName)||!h.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(D,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:a("session.newWorktree.actions.reset")})]})]}),t.jsx(Xe,{value:Oe.worktreeName,onChange:X=>{d==="new-branch"?f(j=>({...j,worktreeName:X.target.value,isSyncingWorktreeName:!1})):P(j=>({...j,worktreeName:X.target.value}))},onBlur:()=>ee(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:ce("h-8",$.touched&&$.worktreeError&&"border-destructive")})]}),d==="new-branch"&&!h.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:()=>Y(!0),className:"w-full justify-between h-9",children:[t.jsx("span",{className:h.sourceBranch?"text-foreground":"text-muted-foreground",children:h.sourceBranch||a("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),h.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:a("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})}),t.jsx(xa,{open:te,title:a("session.newWorktree.selectSourceBranch"),onClose:()=>Y(!1),children:t.jsxs("div",{className:"space-y-4",ref:ie,children:[t.jsx(Xe,{value:B,onChange:X=>F(X.target.value),placeholder:a("session.newWorktree.searchBranches"),className:"h-8"}),C?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):k.length===0&&v.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:[Ne&&re&&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:ge.matching.map(X=>t.jsx("button",{onClick:()=>{f(j=>({...j,sourceBranch:X.value})),Y(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===X.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))})]}),Ne&&!re&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),ge.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(Ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:ge.otherLocal.map(X=>t.jsx("button",{onClick:()=>{f(j=>({...j,sourceBranch:X})),Y(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===X?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X})},X))})]}),ge.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(Ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:ge.otherRemote.map(X=>t.jsx("button",{onClick:()=>{f(j=>({...j,sourceBranch:`remotes/${X}`})),Y(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===`remotes/${X}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X})},`remotes/${X}`))})]})]})]})})]}),(h.linkedIssue||h.linkedPr)&&d==="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(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.prNumber",{number:h.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),t.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:X=>X.stopPropagation(),children:t.jsx(D,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:we,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]}),h.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:[h.linkedPr.head," → ",h.linkedPr.base]}),h.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(Mt,{open:s,onOpenChange:e,children:t.jsxs(Tt,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[t.jsx(zt,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(Ot,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(D,{name:"git-branch",className:"h-5 w-5"}),a("session.newWorktree.title")]}),t.jsx("div",{className:"w-[280px] shrink-0",children:t.jsx(Rn,{items:[{id:"new-branch",label:a("session.newWorktree.mode.newBranch"),icon:t.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:a("session.newWorktree.mode.existingBranch"),icon:t.jsx(D,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:d,onSelect:X=>Fe(X),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),t.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[d==="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(gs,{open:S,onOpenChange:A,children:[t.jsx(ms,{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:ce("truncate",y.selectedBranch?"text-foreground":"text-muted-foreground"),children:y.selectedBranch||a("session.newWorktree.chooseBranch")}),t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(ps,{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:O,children:t.jsxs(ci,{shouldFilter:!1,children:[t.jsx(di,{placeholder:a("session.newWorktree.searchBranches"),value:N,onValueChange:W,onKeyDown:oe}),t.jsx(ui,{disableHorizontal:!0,children:C?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):k.length===0&&v.length===0?t.jsx(mi,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[ve&&ne&&t.jsx(en,{heading:a("session.newWorktree.matchingBranches"),children:Ce.matching.map(X=>t.jsx(Bs,{value:X.value,onSelect:()=>{P(j=>({...j,selectedBranch:X.value,worktreeName:xs(X.label)})),ee(j=>({...j,touched:!0})),A(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))}),ve&&!ne&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),Ce.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[ve&&t.jsx(Hn,{}),t.jsx(en,{heading:a(ve?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:Ce.otherLocal.map(X=>t.jsx(Bs,{value:X,onSelect:()=>{P(j=>({...j,selectedBranch:X,worktreeName:xs(X)})),ee(j=>({...j,touched:!0})),A(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`local-${X}`))})]}),Ce.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(Ce.otherLocal.length>0||ve)&&t.jsx(Hn,{}),t.jsx(en,{heading:a(ve?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:Ce.otherRemote.map(X=>t.jsx(Bs,{value:`remotes/${X}`,onSelect:()=>{P(j=>({...j,selectedBranch:`remotes/${X}`,worktreeName:xs(X)})),ee(j=>({...j,touched:!0})),A(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`remote-${X}`))})]})]})})]})})]}),t.jsx(J,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:q,disabled:!ye||C,title:a("session.newWorktree.fetchBranches"),children:C?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{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")}),d==="new-branch"&&le&&t.jsxs(J,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"gap-1.5 h-7",children:[t.jsx(D,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(Xe,{value:h.branchName,onChange:X=>{f(j=>({...j,branchName:X.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ee(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:ce("h-8",$.touched&&$.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.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")}),d!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const X=xs(d==="new-branch"?h.branchName:"");f(j=>({...j,worktreeName:X,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===xs(h.branchName),className:ce("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===xs(h.branchName)||!h.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(D,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:a("session.newWorktree.actions.reset")})]})]}),t.jsx(Xe,{value:Oe.worktreeName,onChange:X=>{d==="new-branch"?f(j=>({...j,worktreeName:X.target.value,isSyncingWorktreeName:!1})):P(j=>({...j,worktreeName:X.target.value}))},onBlur:()=>ee(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:ce("h-8",$.touched&&$.worktreeError&&"border-destructive")})]}),d==="new-branch"&&!h.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(gs,{open:z,onOpenChange:T,children:[t.jsx(ms,{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:ce("truncate",h.sourceBranch?"text-foreground":"text-muted-foreground"),children:h.sourceBranch||a("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(ps,{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:Q,children:t.jsxs(ci,{shouldFilter:!1,children:[t.jsx(di,{placeholder:a("session.newWorktree.searchBranches"),value:B,onValueChange:F,onKeyDown:oe}),t.jsx(ui,{disableHorizontal:!0,children:C?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):k.length===0&&v.length===0?t.jsx(mi,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[Ne&&re&&t.jsx(en,{heading:a("session.newWorktree.matchingBranches"),children:ge.matching.map(X=>t.jsx(Bs,{value:X.value,onSelect:()=>{f(j=>({...j,sourceBranch:X.value})),T(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))}),Ne&&!re&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),ge.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[Ne&&t.jsx(Hn,{}),t.jsx(en,{heading:a(Ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ge.otherLocal.map(X=>t.jsx(Bs,{value:X,onSelect:()=>{f(j=>({...j,sourceBranch:X})),T(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`local-${X}`))})]}),ge.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(ge.otherLocal.length>0||Ne)&&t.jsx(Hn,{}),t.jsx(en,{heading:a(Ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ge.otherRemote.map(X=>t.jsx(Bs,{value:`remotes/${X}`,onSelect:()=>{f(j=>({...j,sourceBranch:`remotes/${X}`})),T(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`remote-${X}`))})]})]})})]})})]}),h.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:a("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})})]}),(h.linkedIssue||h.linkedPr)&&d==="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(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.prNumber",{number:h.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),t.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:X=>X.stopPropagation(),children:t.jsx(D,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:we,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]}),h.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:[h.linkedPr.head," → ",h.linkedPr.base]}),h.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(qt,{className:"mt-1 flex items-center justify-between",children:[t.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:$.touched&&($.branchError||$.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:$.branchError||$.worktreeError})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(J,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:de,children:a("session.newWorktree.actions.cancel")}),t.jsxs(J,{size:"sm",onClick:Qe,disabled:!Le||de,className:"gap-1.5",children:[de&&t.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(de?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),t.jsx(Kj,{open:U,onOpenChange:M,onSelect:V})]})}const mw=()=>{vc(),vs.reconnectToRuntimeBaseUrl(),xc()},pw=s=>{ys.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),Ie.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),s.previousRuntimeKey&&Mm.getState().stopRunningRunsForRuntime(s.previousRuntimeKey),vc(),vs.reconnectToRuntimeBaseUrl(),ot.setState({providers:[],agents:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),es.getState().resetForRuntimeSwitch(),li.getState().resetForRuntimeSwitch(),Tm.getState().reset(),ys.getState().restoreForRuntimeSwitch(s.runtimeKey),Ie.getState().restoreForRuntimeSwitch(s.runtimeKey),xc()};export{Gl as $,Nc as A,yy as B,iw as C,dw as D,En as E,Mn as F,Tn as G,sw as H,Wl as I,Hx as J,Wx as K,So as L,up as M,uw as N,Qj as O,lw as P,wn as Q,Is as R,Vv as S,cw as T,xy as U,vn as V,Zj as W,ln as X,bn as Y,yn as Z,Zv as _,ow as a,al as a0,Af as a1,nl as a2,Xh as a3,Xc as a4,ed as a5,rx as a6,ri as a7,zj as a8,$y as a9,Jj as aa,Fg as ab,Ic as ac,Tg as ad,nw as ae,cj as b,pw as c,rw as d,aw as e,Yj as f,Yn as g,os as h,Xj as i,qj as j,ev as k,Ut as l,Qx as m,yl as n,Gj as o,vx as p,_v as q,mw as r,us as s,Wf as t,wc as u,Hf as v,ew as w,tw as x,_f as y,Rn as z};