@openchamber/web 1.14.1 → 1.15.0

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 (87) hide show
  1. package/bin/cli.test.js +8 -0
  2. package/bin/lib/DOCUMENTATION.md +3 -0
  3. package/bin/lib/cli-args.js +10 -0
  4. package/bin/lib/commands-connect-url.js +169 -22
  5. package/dist/assets/{DiagramView-Cb58svCq.js → DiagramView-HR2xZxJ8.js} +1 -1
  6. package/dist/assets/MarkdownRendererImpl-sm01Q7R7.js +11 -0
  7. package/dist/assets/{MultiRunWindow-BPSxV_B7.js → MultiRunWindow-DlFUaNQK.js} +1 -1
  8. package/dist/assets/OnboardingScreen-DVRz82mJ.js +1 -0
  9. package/dist/assets/{SessionSwitcherDropdown-4FWg9xMC.js → SessionSwitcherDropdown-DvoOalMY.js} +1 -1
  10. package/dist/assets/SettingsWindow-CkInZcj7.js +1 -0
  11. package/dist/assets/{TerminalView-fTYjnQkh.js → TerminalView-D_9BAjtv.js} +3 -3
  12. package/dist/assets/es-cjUissX4.js +15 -0
  13. package/dist/assets/fr-DqbXnTdK.js +13 -0
  14. package/dist/assets/index-Dg0nmvQU.css +1 -0
  15. package/dist/assets/index-ltrmNGAf.js +2 -0
  16. package/dist/assets/ja-Cetyq6Eg.js +15 -0
  17. package/dist/assets/ko-DtunWisP.js +15 -0
  18. package/dist/assets/main-BC0m8s1v.js +236 -0
  19. package/dist/assets/main-DzNa8r0N.js +2 -0
  20. package/dist/assets/miniChat-BRYDE-Se.js +2 -0
  21. package/dist/assets/mobile-C3QJVA97.js +2 -0
  22. package/dist/assets/pl-DctGLgve.js +15 -0
  23. package/dist/assets/pt-BR-CXPhf78S.js +15 -0
  24. package/dist/assets/renderElectronMiniChatApp-CVFbDC5A.js +2 -0
  25. package/dist/assets/renderMobileApp-wkBjh5WR.js +16 -0
  26. package/dist/assets/runtimeEndpointReset-C42u8PvG.js +167 -0
  27. package/dist/assets/uk-Bdrc-kqF.js +15 -0
  28. package/dist/assets/{useAppFontEffects-BUUJYbAZ.js → useAppFontEffects-DzBg8hrC.js} +123 -119
  29. package/dist/assets/{vendor-.bun-C6iL44L9.js → vendor-.bun-BE757pvp.js} +1 -1
  30. package/dist/assets/zh-CN-CeCVKrHP.js +15 -0
  31. package/dist/assets/zh-TW-CoqiQING.js +15 -0
  32. package/dist/index.html +4 -4
  33. package/dist/mini-chat.html +4 -4
  34. package/dist/mobile.html +4 -4
  35. package/package.json +2 -2
  36. package/server/index.js +130 -1
  37. package/server/lib/client-auth/pairing.js +308 -0
  38. package/server/lib/client-auth/pairing.test.js +142 -0
  39. package/server/lib/client-auth/remote-clients.js +65 -3
  40. package/server/lib/notifications/apns-runtime.js +9 -16
  41. package/server/lib/opencode/bootstrap-runtime.js +10 -0
  42. package/server/lib/opencode/core-routes.js +246 -6
  43. package/server/lib/opencode/core-routes.test.js +248 -9
  44. package/server/lib/opencode/network-runtime.js +14 -1
  45. package/server/lib/opencode/network-runtime.test.js +29 -9
  46. package/server/lib/opencode/proxy.js +47 -6
  47. package/server/lib/opencode/settings-helpers.js +3 -0
  48. package/server/lib/opencode/settings-helpers.test.js +11 -0
  49. package/server/lib/opencode/settings-normalization-runtime.js +2 -0
  50. package/server/lib/package-manager.js +18 -5
  51. package/server/lib/relay/DOCUMENTATION.md +78 -0
  52. package/server/lib/relay/cross-compat.test.js +135 -0
  53. package/server/lib/relay/e2ee.js +341 -0
  54. package/server/lib/relay/e2ee.test.js +124 -0
  55. package/server/lib/relay/host-client.js +389 -0
  56. package/server/lib/relay/host-client.test.js +280 -0
  57. package/server/lib/relay/identity.js +73 -0
  58. package/server/lib/relay/identity.test.js +78 -0
  59. package/server/lib/relay/service.js +247 -0
  60. package/server/lib/relay/signing-key.js +50 -0
  61. package/server/lib/relay/tunnel-codec.js +373 -0
  62. package/server/lib/relay/tunnel-codec.test.js +58 -0
  63. package/server/lib/relay/tunnel-host.js +462 -0
  64. package/server/lib/ui-auth/DOCUMENTATION.md +6 -0
  65. package/server/lib/ui-auth/ui-auth.js +10 -0
  66. package/server/opencode-proxy.test.js +38 -0
  67. package/dist/assets/MarkdownRendererImpl-D2yCDL5A.js +0 -7
  68. package/dist/assets/OnboardingScreen-Sl-6JgaP.js +0 -1
  69. package/dist/assets/SettingsWindow-CY8q4msv.js +0 -1
  70. package/dist/assets/es-bWcuDy_2.js +0 -15
  71. package/dist/assets/fr-DzRs3OzV.js +0 -13
  72. package/dist/assets/index-KnWk9fmM.css +0 -1
  73. package/dist/assets/index-ZJTzZ0_U.js +0 -2
  74. package/dist/assets/ja-BqUX_UD3.js +0 -15
  75. package/dist/assets/ko-BQo10SNx.js +0 -15
  76. package/dist/assets/main-BDoqLlQB.js +0 -236
  77. package/dist/assets/main-DUGyTrDt.js +0 -2
  78. package/dist/assets/miniChat-DNDiX8GA.js +0 -2
  79. package/dist/assets/mobile-DnghtOCb.js +0 -2
  80. package/dist/assets/pl-Bgx_ATJT.js +0 -15
  81. package/dist/assets/pt-BR-B1yXRvoX.js +0 -15
  82. package/dist/assets/renderElectronMiniChatApp-BB4C1K7t.js +0 -2
  83. package/dist/assets/renderMobileApp-CZgaXKi5.js +0 -16
  84. package/dist/assets/runtimeEndpointReset-By39StyB.js +0 -167
  85. package/dist/assets/uk-C9k8SP8q.js +0 -15
  86. package/dist/assets/zh-CN-Bri-Vo5y.js +0 -15
  87. package/dist/assets/zh-TW-DAUGzmYG.js +0 -15
@@ -0,0 +1,167 @@
1
+ import{am as od,b as Ze,an as ld,j as t,r as fe,ao as cd,ap as dd,a as Nn,d as Na,p as wi,R as o,O as Es,ad as ud,ae as md,ac as pd,af as gd,aa as hd,ab as fd,ag as xd,aq as yd,ar as bd,as as vd,u as jd,l as wd,n as Nd,w as kd,C as Sd,S as Cd,at as Id,a8 as Pd,D as Ad,q as Dd,au as Ed,av as Md,aw as Td,ax as Rd,ay as Ld,$ as Hs,az as Fd,aA as Fn,aB as Li,aC as Od,aD as zd,aE as jr,aF as Ud,aG as Kd,aH as Bd,aI as Fi,aJ as ar,aK as Oi,k as Ga,aL as Zl,aM as Ni,aN as dr,aO as ec,aP as zi,aQ as $d,aR as Vd,aS as _d,aT as Hd,aU as Ui,aV as Le,aW as Da,aX as Wd,aY as qd,aZ as Gd,a_ as Jd,a$ as Qd,b0 as tc,a9 as Yd,b1 as Ki,b2 as Xd,b3 as Zd,b4 as eu,b5 as tu}from"./vendor-.bun-BE757pvp.js";import{dA as ur,A as rr,C as ir,v as oe,dB as Ja,dC as Qa,dD as Ya,b as ss,c as st,I as D,aH as Ct,aI as It,aJ as Pt,V as su,aq as nu,g as sc,o as on,b5 as Lt,b4 as Ft,b3 as Ut,bJ as Ht,D as ti,B as G,bi as ki,y as En,aF as Ms,t as W,a2 as nc,dE as Qn,dF as au,dG as ru,dp as iu,dH as ou,dI as lu,dJ as cu,G as vs,dK as du,cW as uu,cX as mu,cY as pu,c9 as gu,aB as ms,aD as ps,ca as hu,aE as gs,aZ as mr,dL as fu,dM as qn,b2 as Kt,bv as _t,bR as Jt,w as Xe,dN as va,aA as Ss,Y as it,dl as xu,bK as Dt,bL as Et,bM as zt,bN as Mt,bO as mt,bg as hs,a_ as ja,dO as xn,bh as bt,dP as ac,dQ as yu,dR as bu,dS as pr,dT as an,dU as Yn,b0 as rc,dV as tn,dW as vu,dX as ju,dY as wu,dZ as Nu,d_ as ku,d$ as Su,e0 as sn,e1 as Cu,z as gr,cf as Bi,p as Iu,ch as si,ah as ic,L as Pu,P as oc,N as lc,cj as Au,U as $i,d3 as Du,dj as cc,d8 as dc,da as Eu,e2 as Mu,u as ni,cF as Tu,e3 as Vi,e4 as Ru,e5 as Lu,e6 as _i,e7 as Fu,e8 as Ou,e9 as zu,ea as Uu,aG as Ku,eb as Bu,O as $u,Q as Vu,d as Si,ec as _u,ed as Hu,am as Xn,al as uc,ak as Wu,ee as qu,ef as Hi,an as Gu,ao as Ju,aj as Qu,aL as Yu,aM as Xu,aN as mc,eg as wr,eh as Wi,ei as Zu,ej as em,ek as tm,el as sm,db as hr,Z as nn,em as nm,en as am,eo as rm,ep as im,eq as om,er as Nr,es as qi,et as lm,eu as cm,ev as dm,ew as um,ex as mm,ey as kr,ez as pm,aW as Gi,eA as _n,aV as gm,eB as hm,eC as Ji,eD as Qi,ci as fm,a3 as gn,F as xm,S as ym,eE as bm,cs as Ea,bn as ai,bo as ri,bp as ii,bq as oi,br as en,bs as Ks,bS as Gn,M as ya,eF as Yi,c2 as vm,eG as pc,bU as jm,df as wm,j as Nm,eH as Sr,ag as km,ba as Ma,bY as Sm,eI as Cm,eJ as Im,d9 as Pm,eK as Am,eL as Dm,eM as gc,dy as Em}from"./useAppFontEffects-DzBg8hrC.js";import{O as Ci,h as dt,o as js,e as Ns,aa as Mm,ab as Xi,ac as Tm,ad as Rm,D as fs,W as Dn,u as Fe,v as sa,a as Zi,q as kt,d as na,k as qs,t as rs,E as eo,ae as to,af as so,H as ca,ag as Lm,j as Fm,ah as Hn,ai as Om,G as zm,aj as Um,s as Km,ak as Bm,al as hc,Q as $m,am as Cr,P as Vm,an as no,ao as _m,I as Hm,ap as ao,aq as ro,ar as io,as as oo,at as Ir,au as lo,N as fc,av as Wm,aw as qm,ax as Gm,ay as Jm,az as Qm,aA as Ym,a9 as Xm,m as Zm,aB as ep,aC as tp,aD as sp,aE as xc}from"./index-ltrmNGAf.js";import{g as np,s as ap}from"./mobileLayoutPreference-Dio-WWkI.js";function rp(){return new Worker(od,{type:"module"})}const ip=["typescript","javascript","tsx","jsx","json","markdown"],li={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let co,uo;const mo=s=>{const e=li[s],n=new ld({workerFactory:rp,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:ip,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},op=s=>{if(!(typeof window>"u"))return s==="split"?(uo??=mo("split"),uo):(co??=mo("unified"),co)},lp=s=>{const e=Ze.c(7),{children:n,renderTheme:a}=s,r=ci("unified"),i=ci("split");let l,d;e[0]!==a||e[1]!==i||e[2]!==r?(l=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:li.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:li.split.lineDiffType})},d=[a,i,r],e[0]=a,e[1]=i,e[2]=r,e[3]=l,e[4]=d):(l=e[3],d=e[4]),fe.useEffect(l,d);let c;return e[5]!==n?(c=t.jsx(t.Fragment,{children:n}),e[5]=n,e[6]=c):c=e[6],c},$j=s=>{const e=Ze.c(11),{children:n}=s,a=ur();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const f=rr(!1),m=rr(!0),p=a?.lightThemeId??f.metadata.id,u=a?.darkThemeId??m.metadata.id;i=a?.availableThemes.find(j=>j.metadata.id===p)??f,r=a?.availableThemes.find(j=>j.metadata.id===u)??m,ir(i),ir(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 d=l;let c;return e[8]!==n||e[9]!==d?(c=t.jsx(lp,{renderTheme:d,children:n}),e[8]=n,e[9]=d,e[10]=c):c=e[10],c},ci=s=>{const e=Ze.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=op(n),e[0]=n,e[1]=a):a=e[1],a};function cp(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 or=fe.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=oe("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 d;n[6]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(cd,{className:oe("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=d):d=n[6];let c;return n[7]!==r||n[8]!==e||n[9]!==i?(c=t.jsx(dd,{className:i,style:l,...r,ref:e,children:d}),n[7]=r,n[8]=e,n[9]=i,n[10]=c):c=n[10],c});or.displayName="Switch";const Ta=()=>{try{const e=ss.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=js.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[McpConfigStore] Error resolving config directory:",s)}return null},po=s=>s?Object.entries(s).map(([e,n])=>({key:e,value:n})):[],go=s=>{const e=s.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},Ra=s=>typeof s!="string"?void 0:s.trim()||void 0,Pr=800,dp=5e3,up="__default__",di=new Map,Ar=new Map,yc=s=>s?.trim()||up,Dr=s=>{di.delete(yc(s))},ea=Nn()(Na(wi((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=Ta(),r=yc(a),i=Date.now(),l=di.get(r)??0,d=e().mcpServers.length>0;if(!n?.force&&d&&i-l<dp)return!0;const c=Ar.get(r);if(!n?.force&&c)return c;const f=(async()=>{s({isLoading:!0});try{const m=a?`?directory=${encodeURIComponent(a)}`:"",p=await dt(`/api/config/mcp${m}`,{headers:a?{"x-opencode-directory":a}:void 0});if(!p.ok)throw new Error("Failed to load MCP configs");const u=await p.json();return s({mcpServers:u,isLoading:!1}),di.set(r,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),s({isLoading:!1}),!1}})();Ar.set(r,f);try{return await f}finally{Ar.delete(r)}},createMcp:async n=>{Ja("Creating MCP server configuration…");let a=!1;try{const r=ho(n),i=Ta(),l=i?`?directory=${encodeURIComponent(i)}`:"",d=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 d.json().catch(()=>null);if(!d.ok)throw new Error(c?.error||"Failed to create MCP server");return Dr(i),c?.requiresReload?(a=!0,await Qa({message:c.message,delayMs:c.reloadDelayMs??Pr,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||Ya()}},updateMcp:async(n,a)=>{Ja("Updating MCP server configuration…");let r=!1;try{const i=ho(a),l=Ta(),d=l?`?directory=${encodeURIComponent(l)}`:"",c=await dt(`/api/config/mcp/${encodeURIComponent(n)}${d}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},body:JSON.stringify(i)}),f=await c.json().catch(()=>null);if(!c.ok)throw new Error(f?.error||"Failed to update MCP server");return Dr(l),f?.requiresReload?(r=!0,await Qa({message:f.message,delayMs:f.reloadDelayMs??Pr,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||Ya()}},deleteMcp:async n=>{Ja("Deleting MCP server configuration…");let a=!1;try{const r=Ta(),i=r?`?directory=${encodeURIComponent(r)}`:"",l=await dt(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:r?{"x-opencode-directory":r}:void 0}),d=await l.json().catch(()=>null);if(!l.ok)throw new Error(d?.error||"Failed to delete MCP server");return Dr(r),d?.requiresReload&&(a=!0,await Qa({message:d.message,delayMs:d.reloadDelayMs??Pr,scopes:["all"]})),e().selectedMcpName===n&&s({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}}catch(r){return console.error("[McpConfigStore] Failed to delete MCP:",r),{ok:!1}}finally{a||Ya()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:Ci(),partialize:s=>({selectedMcpName:s.selectedMcpName})}),{name:"mcp-config-store"}));function ho(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=go(s.environment)??{}),s.headers!==void 0&&(e.headers=go(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:Ra(s.oauthClientId),clientSecret:Ra(s.oauthClientSecret),scope:Ra(s.oauthScope),redirectUri:Ra(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 mp={},pp={},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},$n=s=>Zs(s)??"__global__",In=s=>{const e=Zs(s);return e?js.getScopedApiClient(e):js.getApiClient()},os=Nn()(Na((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=$n(n??Ns.getState().currentDirectory);return e().byDirectory[a]??mp},getDiagnosticForDirectory:n=>{const a=$n(n??Ns.getState().currentDirectory);return e().diagnosticsByDirectory[a]??pp},getErrorForDirectory:n=>{const a=$n(n??Ns.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=Zs(n?.directory??Ns.getState().currentDirectory),r=$n(a);n?.silent||s(i=>({loadingKeys:{...i.loadingKeys,[r]:!0},lastErrorKeys:{...i.lastErrorKeys,[r]:null}}));try{const d=(await In(a).mcp.status()).data??{};s(c=>({byDirectory:{...c.byDirectory,[r]:d},diagnosticsByDirectory:{...c.diagnosticsByDirectory,[r]:Object.fromEntries(Object.entries(c.diagnosticsByDirectory[r]??{}).filter(([f])=>!d[f]))},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(d=>({loadingKeys:{...d.loadingKeys,[r]:!1},lastErrorKeys:{...d.lastErrorKeys,[r]:l}}))}},connect:async(n,a)=>{const r=Zs(a??Ns.getState().currentDirectory),i=$n(r),l=In(r);try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(d){const c=d instanceof Error?d.message:"Connection failed";throw s(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:c}}}})),d}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=Zs(a??Ns.getState().currentDirectory);await In(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=Zs(a??Ns.getState().currentDirectory),d=(await In(r).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!d)throw new Error("Authorization URL was not returned");return d},completeAuth:async(n,a,r)=>{const i=Zs(r??Ns.getState().currentDirectory);await In(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??Ns.getState().currentDirectory);await In(r).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},testConnection:async(n,a)=>{const r=Zs(a??Ns.getState().currentDirectory),i=$n(r),l=In(r),c=e().getStatusForDirectory(r)[n]?.status==="connected";let f,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(j){f=j instanceof Error?j.message:"Connection failed",s(g=>({diagnosticsByDirectory:{...g.diagnosticsByDirectory,[i]:{...g.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:f??"Connection failed"}}}}))}await e().refresh({directory:r,silent:!0});const p=e().getStatusForDirectory(r)[n],u=p;if(!c&&p?.status==="connected"){try{await l.mcp.disconnect({name:n},{throwOnError:!0})}catch(j){m=`Connection test succeeded, but cleanup disconnect failed: ${j instanceof Error?j.message:"Disconnect failed"}`}await e().refresh({directory:r,silent:!0})}return{status:u??e().getStatusForDirectory(r)[n],error:f,warning:m}}}))),gp=(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}},hp=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Vj=({active:s,className:e,headerAction:n,listClassName:a,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:l}=st(),c=Ns(k=>k.currentDirectory)??null,f=os(k=>k.getStatusForDirectory(c)),m=os(k=>k.refresh),p=os(k=>k.connect),u=os(k=>k.disconnect),j=ea(k=>k.mcpServers),g=ea(k=>k.loadMcpConfigs),[h,x]=o.useState(!1),[A,S]=o.useState(null);o.useEffect(()=>{m({directory:c,silent:!0})},[m,c]),o.useEffect(()=>{g({force:!0})},[g]),o.useEffect(()=>{s&&Promise.all([m({directory:c,silent:!0}),g({force:!0})])},[s,m,c,g]);const C=o.useMemo(()=>{const k=new Set(Object.keys(f));for(const y of j)y?.name&&k.add(y.name);return Array.from(k).sort((y,v)=>y.localeCompare(v))},[j,f]),R=o.useCallback(k=>{if(k?.preventDefault(),h)return;x(!0);const y=new Promise(v=>setTimeout(v,500));Promise.all([m({directory:c}),y]).finally(()=>{x(!1)})},[h,m,c]);return t.jsxs("div",{className:oe("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:h,onClick:R,"aria-label":l("mcpDropdown.actions.refreshAria"),children:t.jsx(D,{name:"refresh",className:oe("h-4 w-4",h&&"animate-spin")})})]})]})}),t.jsx("div",{className:oe("max-h-64 overflow-y-auto",i?"space-y-1 py-3":"px-3 py-2.5",a),children:t.jsxs("div",{className:oe(!i&&C.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[C.map(k=>{const y=f[k],v=hp(y),E=y?.status==="connected",K=A===k,U=gp(y,l);return t.jsxs("div",{className:oe("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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx("span",{className:oe("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",v==="success"&&"bg-status-success",v==="error"&&"bg-status-error",v==="warning"&&"bg-status-warning",v==="default"&&"bg-muted-foreground/40"),"aria-label":U})}),t.jsx(Pt,{side:"left",children:t.jsx("p",{children:U})})]}),t.jsx("span",{className:oe("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:k})]})}),t.jsx(or,{checked:E,disabled:K,className:"data-[checked]:bg-status-info",onCheckedChange:async M=>{S(k);try{M?await p(k,c):await u(k,c)}finally{S(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 fp(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=nu();return s}catch{return"unknown"}}function xp(){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 yp(){const s=sc();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 bp(s){const e=Fe.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",fp()),n.set("arch",xp()),n.set("platform",yp()),s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",sa()?"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 Er(s,e){try{const n=bp(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 vp(){return su()?"mobile":Rm()?"desktop":fs()?"vscode":Dn()?"web":null}const fo={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},bc=Nn()((s,e)=>({...fo,checkForUpdates:async()=>{const n=vp();if(!n)return null;s({checking:!0,error:null,runtimeType:n});try{let a=null,r=null;if(n==="desktop"){const i=await Xi();return s({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null}),r}else n==="web"?(a=await Er("web"),r=a?.nextSuggestedCheckInSec??null):n==="vscode"?r=(await Er("vscode"))?.nextSuggestedCheckInSec??null:n==="mobile"&&(a=await Er("mobile","1.15.0"),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 Xi();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 Tm(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 Mm())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(fo)}})),xo="https://github.com/openchamber/openchamber/releases";function jp(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(ki(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function wp(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function yo(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function Np(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 kp(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,d=s.slice(r.start,l).trim();return{version:r.version,date:r.date,start:r.start,end:l,raw:d}})}const bo=2e3,Sp=600*1e3;async function Cp(){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 Ip(){try{return(await dt("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function Pp(s,e=Math.ceil(Sp/bo),n=bo){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 Ip())return!0}catch{}await new Promise(r=>setTimeout(r,n))}return!1}const vo=({open:s,onOpenChange:e,info:n,downloading:a,downloaded:r,progress:i,error:l,onDownload:d,onRestart:c,runtimeType:f="desktop"})=>{const{t:m}=st(),[p,u]=fe.useState(!1),[j,g]=fe.useState("idle"),[h,x]=fe.useState(null),A=n?.version?n.releaseUrl||`${xo}/tag/v${n.version}`:xo,S=n?.downloadUrl||A,C=i?.total?Math.round(i.downloaded/i.total*100):0,R=f==="web",k=f==="mobile",y=n?.updateCommand||"openchamber update";fe.useEffect(()=>{s||(g("idle"),x(null))},[s]);const v=async()=>{(await En(y)).ok&&(u(!0),setTimeout(()=>u(!1),2e3))},E=fe.useCallback(async P=>{await on(P)},[]),K=fe.useCallback(async()=>{g("updating"),x(null);const P=await Cp();if(!P.success){g("error"),x(P.error||m("updateDialog.error.updateFailed"));return}P.autoRestart&&(g("restarting"),await new Promise(T=>setTimeout(T,2e3))),g("reconnecting"),await Pp(n?.currentVersion)?window.location.reload():(g("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),U=fe.useCallback(()=>{E(S)},[E,S]),M=j!=="idle"&&j!=="error",I=fe.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const z=kp(P);if(z.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:yo(P)};const T=[...z].sort((J,_)=>Np(J.version,_.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:T.map(J=>({version:J.version,dateLabel:jp(J.date),content:yo(wp(J.raw)||P)}))}},[n?.body,m]);return t.jsx(Lt,{open:s,onOpenChange:M?void 0:e,children:t.jsxs(Ft,{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(Ut,{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(j==="restarting"||j==="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:[R&&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:[j==="updating"&&m("updateDialog.status.installingUpdate"),j==="restarting"&&m("updateDialog.status.serverRestarting"),j==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),I&&!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:I.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:P=>{const T=P.target.closest("a");T&&T.href&&(P.preventDefault(),P.stopPropagation(),E(T.href))},children:t.jsx(ti,{content:I.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:I.sections.map(P=>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",P.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:P.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 J=z.target.closest("a");J&&J.href&&(z.preventDefault(),z.stopPropagation(),E(J.href))},children:t.jsx(ti,{content:P.content,disableLinkSafety:!0,enableFileReferences:!1})})]},P.version))})})}),R&&j==="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:y}),t.jsx("button",{onClick:v,className:oe("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",p&&"text-[var(--status-success)]"),title:m(p?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:p?t.jsx(D,{name:"check",className:"h-4 w-4"}):t.jsx(D,{name:"clipboard",className:"h-4 w-4"})})]})]}),!R&&!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||h)&&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||h})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:A,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:[!R&&!k&&!r&&!a&&t.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(D,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!R&&!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")]}),!R&&!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(G,{onClick:U,size:"default",children:[t.jsx(D,{name:"external-link",className:"h-4 w-4"}),m("updateDialog.actions.openMobileUpdate")]}),R&&!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")]}),R&&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")]})]})]})]})})},jo="https://github.com/openchamber/openchamber",Ap="https://discord.gg/ZYRSdnwwKA",wo="https://x.com/openchamber_dev",Dp=800,vc=({initialUpdateDialogOpen:s=!1})=>{const{t:e}=st(),[n,a]=o.useState(s),[r,i]=o.useState(!1),[l,d]=o.useState(null),[c,f]=o.useState(null),m=bc(Es(h=>({info:h.info,checking:h.checking,available:h.available,error:h.error,downloading:h.downloading,downloaded:h.downloaded,progress:h.progress,runtimeType:h.runtimeType,checkForUpdates:h.checkForUpdates,downloadUpdate:h.downloadUpdate,restartToUpdate:h.restartToUpdate}))),{isMobile:p}=Ms(),u=l||m.info?.currentVersion||"unknown";o.useEffect(()=>{let h=!1;return(async()=>{try{const A=await dt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const S=await A.json().catch(()=>null),C=typeof S?.openchamberVersion=="string"&&S.openchamberVersion.trim().length>0?S.openchamberVersion.trim():null;h||d(C)}catch{h||d(null)}})(),()=>{h=!0}},[]),o.useEffect(()=>{let h=!1;return(async()=>{try{const A=await dt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const S=await A.json().catch(()=>null),C=typeof S?.currentVersion=="string"&&S.currentVersion.trim().length>0?S.currentVersion.trim():null;h||f(C)}catch{h||f(null)}})(),()=>{h=!0}},[]);const j=o.useRef(!1);o.useEffect(()=>{if(m.checking)i(!0),j.current=!0;else if(r){const h=setTimeout(()=>{i(!1),j.current&&!m.available&&!m.error&&(W.success(e("settings.openchamber.about.toast.latestVersion")),j.current=!1)},Dp);return()=>clearTimeout(h)}},[e,m.checking,r,m.available,m.error]);const g=m.checking||r;return p?t.jsxs("div",{className:"w-full space-y-6 pb-2",children:[t.jsxs("div",{className:"flex flex-col items-center text-center",children:[t.jsx(nc,{width:72,height:72}),t.jsx("h2",{className:"mt-4 typography-ui-header font-semibold text-foreground",children:"OpenChamber"}),t.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[t.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:u})}),t.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]})]}),t.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&t.jsxs(G,{type:"button",variant:"outline",size:"sm",onClick:()=>m.checkForUpdates(),disabled:g,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[g?t.jsx(D,{name:"loader",className:"size-4 animate-spin"}):t.jsx(D,{name:"refresh",className:"size-4"}),e(g?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!g&&m.available&&t.jsxs(G,{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:jo,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:Ap,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:wo,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(vo,{open:n,onOpenChange:a,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]}):t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-3 px-1",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:e("settings.openchamber.about.title")})}),t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.version")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:u})]}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.openCodeVersion")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(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(G,{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(G,{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:jo,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:wo,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(vo,{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})]})},_j=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),Ep=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),Mp=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},Tp=s=>!s||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),da="opencode-update-available",La="opencode-upgrade-progress",Rp=5e3,Lp=[1e4,6e4],No="opencode-update-toast-dismissed-version",Hj=()=>{const{t:s}=st(),e=Fe(l=>l.showOpenCodeUpdateNotifications),n=fe.useRef(new Set),a=fe.useRef(!1);fe.useEffect(()=>{e||W.dismiss(da)},[e]);const r=fe.useCallback(()=>{W.dismiss(La),Qn({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),i=fe.useCallback(async()=>{if(!a.current){a.current=!0,W.dismiss(da),W.message(s("opencodeUpdate.toast.upgrading.title"),{id:La,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({})}),d=await l.json().catch(()=>null);if(!l.ok||d?.success===!1)throw new Error(d?.error||l.statusText||s("opencodeUpdate.toast.failed.description"));W.success(s("opencodeUpdate.toast.updated.title"),{id:La,description:d?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:d.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(D,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(l){W.error(s("opencodeUpdate.toast.failed.title"),{id:La,description:l instanceof Error?l.message:s("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{a.current=!1}}},[r,s]);return fe.useEffect(()=>{const l=p=>{if(!Fe.getState().showOpenCodeUpdateNotifications){W.dismiss(da);return}Ep({version:p,dismissedVersion:Zi().getItem(No),seenVersions:n.current})&&(n.current.add(p),W.info(s("opencodeUpdate.toast.available.title"),{id:da,description:s("opencodeUpdate.toast.available.description",{version:p}),duration:1/0,action:{label:s("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:s("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{Zi().setItem(No,p),kt({openCodeUpdateToastDismissedVersion:p}),W.dismiss(da)}}}))},d=p=>{const u=Mp(p.detail);l(u)};let c=!1;const f=[],m=async p=>{try{const u=await dt("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!u.ok)throw new Error(u.statusText||"OpenCode upgrade status check failed");const j=await u.json().catch(()=>null),g=Tp(j);!c&&g&&l(g)}catch{const u=Lp[p];!c&&u!==void 0&&f.push(setTimeout(()=>{m(p+1)},u))}};return e&&f.push(setTimeout(()=>{m(0)},Rp)),window.addEventListener("openchamber:opencode-update-available",d),()=>{c=!0;for(const p of f)clearTimeout(p);window.removeEventListener("openchamber:opencode-update-available",d)}},[i,e,s]),null},Wj=()=>{const s=Ze.c(3),[e,n]=o.useState(Fp),{isUpdating:a}=e;let r,i;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>ru(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(nc,{width:80,height:80,isAnimated:!0})}),s[2]=l):l=s[2],l};function Fp(){return au()}class Op 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(iu,{className:"w-full max-w-md",children:[t.jsx(ou,{className:"text-center",children:t.jsxs(lu,{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(cu,{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(G,{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 zp(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 d;e[8]!==n?(d=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=d):d=e[9];let c;e[10]!==n?(c=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=c):c=e[11];let f;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==l||e[16]!==d||e[17]!==c?(f={title:a,description:r,sessionLabel:i,detailsSummary:l,resetAction:d,persistentHint:c},e[12]=a,e[13]=r,e[14]=i,e[15]=l,e[16]=d,e[17]=c,e[18]=f):f=e[18];let m;return e[19]!==s||e[20]!==f?(m=t.jsx(Op,{...s,texts:f}),e[19]=s,e[20]=f,e[21]=m):m=e[21],m}const qj=s=>{const e=Ze.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=vs(Up)||void 0;let l;e[0]!==a?(l=t.jsx(du,{readOnly:a}),e[0]=a,e[1]=l):l=e[1];let d;return e[2]!==i||e[3]!==l?(d=t.jsx(zp,{sessionId:i,children:l}),e[2]=i,e[3]=l,e[4]=d):d=e[4],d};function Up(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(ud,{...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(md,{...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 d;e[6]!==r?(d=oe("app-region-no-drag z-50",r),e[6]=r,e[7]=d):d=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 f;e[10]!==a?(f=oe(uu,a),e[10]=a,e[11]=f):f=e[11];let m;e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==f?(m=t.jsx(pd,{"data-slot":"dropdown-menu-content",style:c,className:f,...i,children:n}),e[12]=n,e[13]=i,e[14]=c,e[15]=f,e[16]=m):m=e[16];let p;return e[17]!==d||e[18]!==m?(p=t.jsx(hd,{children:t.jsx(fd,{className:d,children:m})}),e[17]=d,e[18]=m,e[19]=p):p=e[19],p}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=oe(mu,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(gd,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}function Gj(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=oe(pu,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(xd,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}const jc=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),ka=s=>{const e=Ze.c(39),{className:n}=s,{t:a}=st(),r=ss(Kp),i=ss(Bp),l=ss($p),d=fs();let c;e[0]!==r?(c=[...r].sort(Vp),e[0]=r,e[1]=c):c=e[1];const f=c;let m;e:{if(f.length===0){m=null;break e}let z;e[2]!==i||e[3]!==f?(z=f.find(T=>T.id===i)??f[0],e[2]=i,e[3]=f,e[4]=z):z=e[4],m=z}const p=m;if(d||f.length===0)return null;let u;e[5]!==p||e[6]!==a?(u=p?.label&&p.label.trim().length>0?p.label:p?.path.split("/").filter(Boolean).pop()||p?.path||a("settings.shared.projectSelector.fallbackProject"),e[5]=p,e[6]=a,e[7]=u):u=e[7];const j=u;let g;e[8]!==j?(g=jc(j),e[8]=j,e[9]=g):g=e[9];const h=g;let x;e[10]!==n?(x=oe(n),e[10]=n,e[11]=x):x=e[11];let A;e[12]!==a?(A=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=A):A=e[13];let S;e[14]!==a?(S=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=S):S=e[15];let C,R;e[16]===Symbol.for("react.memo_cache_sentinel")?(C=oe("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"),R=t.jsx(D,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=C,e[17]=R):(C=e[16],R=e[17]);let k;e[18]!==h?(k=t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:h}),e[18]=h,e[19]=k):k=e[19];let y;e[20]===Symbol.for("react.memo_cache_sentinel")?(y=t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=y):y=e[20];let v;e[21]!==k||e[22]!==A||e[23]!==S?(v=t.jsx(ms,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":A,title:S,className:C,children:[R,k,y]})}),e[21]=k,e[22]=A,e[23]=S,e[24]=v):v=e[24];const E=p?.id??"";let K;e[25]!==l?(K=z=>{z&&l(z)},e[25]=l,e[26]=K):K=e[26];let U;e[27]!==f?(U=f.map(_p),e[27]=f,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(hu,{value:E,onValueChange:K,children:U})}),e[29]=E,e[30]=K,e[31]=U,e[32]=M):M=e[32];let I;e[33]!==v||e[34]!==M?(I=t.jsxs(gs,{children:[v,M]}),e[33]=v,e[34]=M,e[35]=I):I=e[35];let P;return e[36]!==I||e[37]!==x?(P=t.jsx("div",{className:x,children:I}),e[36]=I,e[37]=x,e[38]=P):P=e[38],P};function Kp(s){return s.projects}function Bp(s){return s.activeProjectId}function $p(s){return s.setActiveProject}function Vp(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function _p(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=jc(e);return t.jsx(gu,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function Hp(s,e){return`opencode:sidebar-group:${s}:${e}`}const ui=s=>{const e=Ze.c(33),{label:n,count:a,storageKey:r,defaultExpanded:i,children:l}=s,d=i===void 0?!0:i;let c;e[0]!==n||e[1]!==r?(c=Hp(r,n),e[0]=n,e[1]=r,e[2]=c):c=e[2];const f=c,m=o.useId();let p;e[3]!==d||e[4]!==f?(p=()=>{try{const M=localStorage.getItem(f);if(M!==null)return M==="true"}catch{}return d},e[3]=d,e[4]=f,e[5]=p):p=e[5];const[u,j]=fe.useState(p);let g,h;e[6]!==u||e[7]!==f?(g=()=>{try{localStorage.setItem(f,String(u))}catch{}},h=[f,u],e[6]=u,e[7]=f,e[8]=g,e[9]=h):(g=e[8],h=e[9]),fe.useEffect(g,h);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>j(Wp),e[10]=x):x=e[10];let A;e[11]===Symbol.for("react.memo_cache_sentinel")?(A=oe("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]=A):A=e[11];const S=!u&&"-rotate-90";let C;e[12]!==S?(C=oe("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",S),e[12]=S,e[13]=C):C=e[13];let R;e[14]!==C?(R=t.jsx(D,{name:"arrow-down-s",className:C}),e[14]=C,e[15]=R):R=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 y;e[18]!==a?(y=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=y):y=e[19];let v;e[20]!==m||e[21]!==u||e[22]!==R||e[23]!==k||e[24]!==y?(v=t.jsxs("button",{type:"button",onClick:x,"aria-expanded":u,"aria-controls":m,className:A,children:[R,k,y]}),e[20]=m,e[21]=u,e[22]=R,e[23]=k,e[24]=y,e[25]=v):v=e[25];const E=!u;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]!==v||e[31]!==K?(U=t.jsxs("div",{children:[v,K]}),e[30]=v,e[31]=K,e[32]=U):U=e[32],U};function Wp(s){return!s}const qp=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},Gp=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())},ko=s=>{const e=Gp(qp(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},Jp=({onItemSelect:s})=>{const{t:e}=st(),[n,a]=o.useState(null),[r,i]=o.useState(""),[l,d]=o.useState(null),[c,f]=o.useState(null),[m,p]=o.useState(!1),[u,j]=o.useState(null),{selectedAgentName:g,agents:h,setSelectedAgent:x,setAgentDraft:A,createAgent:S,deleteAgent:C,loadAgents:R}=mr(Es(N=>({selectedAgentName:N.selectedAgentName,agents:N.agents,setSelectedAgent:N.setSelectedAgent,setAgentDraft:N.setAgentDraft,createAgent:N.createAgent,deleteAgent:N.deleteAgent,loadAgents:N.loadAgents})));o.useEffect(()=>{R()},[R]);const k="bg-background",y=()=>{const N="new-agent";let V=N,B=1;for(;h.some(F=>F.name===V);)V=`${N}-${B}`,B++;A({name:V,scope:"user"}),x(V),s?.()},v=async N=>{if(qn(N)){W.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(N),f("delete")},E=async N=>{qn(N)&&(d(N),f("reset"))},K=()=>{d(null),f(null)},U=async()=>{if(!(!l||!c)){p(!0);try{const N=await C(l.name,l.scope);N.ok?(N.requiresManualRestart?W.warning(e("settings.agents.page.toast.savedManualRestart")):c==="delete"?W.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):W.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),K()):c==="delete"?W.error(e("settings.agents.sidebar.toast.deleteFailed")):W.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(N){const V=N instanceof Error?N.message:"",B=/built-in|not deletable|not found/i.test(V);c==="delete"?W.error(e(B?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):W.error(e("settings.agents.sidebar.toast.resetFailed"))}p(!1)}},M=N=>{const V=N.name;let B=1,F=`${V}-copy`;for(;h.some(ie=>ie.name===F);)B++,F=`${V}-copy-${B}`;const O=N,q=N.model?.providerID&&N.model?.modelID?`${N.model.providerID}/${N.model.modelID}`:null,$=N;A({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:ko(N.permission),disable:$.disable}),x(F)},I=N=>{i(N.name),a(N)},P=async()=>{if(!n)return;const N=r.trim().replace(/\s+/g,"-");if(!N){W.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(N===n.name){a(null);return}if(h.some(O=>O.name===N)){W.error(e("settings.agents.sidebar.toast.agentExists"));return}const V=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,B=n,F=await S({name:N,description:n.description,model:V,variant:n.variant,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:ko(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?W.warning(e("settings.agents.page.toast.savedManualRestart")):W.success(e("settings.agents.sidebar.toast.agentRenamed",{name:N})),x(N)):W.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else W.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=h.filter(N=>!fu(N)),J=T.filter(qn),_=T.filter(N=>!qn(N)),{groupedCustomAgents:ee,ungroupedCustomAgents:Q}=fe.useMemo(()=>{const N={},V=[];for(const F of _){const O=F;O.group?(N[O.group]||(N[O.group]=[]),N[O.group].push(F)):V.push(F)}return{groupedCustomAgents:Object.keys(N).sort((F,O)=>F.localeCompare(O)).map(F=>({name:F,agents:N[F]})),ungroupedCustomAgents:V}},[_]);return t.jsxs("div",{className:oe("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(ka,{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(G,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:y,children:t.jsx(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:[J.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")}),J.map(N=>t.jsx(Mr,{agent:N,isSelected:g===N.name,onSelect:()=>{x(N.name),s?.()},onReset:()=>E(N),onDuplicate:()=>M(N),getAgentModeIcon:z,isMenuOpen:u===N.name,onMenuOpenChange:V=>j(V?N.name:null)},N.name))]}),_.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")}),ee.map(({name:N,agents:V})=>t.jsx(ui,{label:N,count:V.length,storageKey:"agents",children:V.map(B=>t.jsx(Mr,{agent:B,isSelected:g===B.name,onSelect:()=>{x(B.name),s?.()},onRename:()=>I(B),onDelete:()=>v(B),onDuplicate:()=>M(B),getAgentModeIcon:z,isMenuOpen:u===B.name,onMenuOpenChange:F=>j(F?B.name:null)},B.name))},N)),Q.map(N=>t.jsx(Mr,{agent:N,isSelected:g===N.name,onSelect:()=>{x(N.name),s?.()},onRename:()=>I(N),onDelete:()=>v(N),onDuplicate:()=>M(N),getAgentModeIcon:z,isMenuOpen:u===N.name,onMenuOpenChange:V=>j(V?N.name:null)},N.name))]})]})}),t.jsx(Lt,{open:l!==null&&c!==null,onOpenChange:N=>{!N&&!m&&K()},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(_t,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),t.jsxs(Jt,{children:[t.jsx(G,{size:"sm",variant:"ghost",onClick:K,disabled:m,children:e("settings.common.actions.cancel")}),t.jsx(G,{size:"sm",onClick:U,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx(Lt,{open:n!==null,onOpenChange:N=>!N&&a(null),children:t.jsxs(Ft,{children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(_t,{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"&&P()}}),t.jsxs(Jt,{children:[t.jsx(G,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(G,{size:"sm",onClick:P,children:e("settings.common.actions.rename")})]})]})})]})},Mr=s=>{const e=Ze.c(52),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,getAgentModeIcon:f,isMenuOpen:m,onMenuOpenChange:p}=s,{t:u}=st(),j=n;let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=va(),e[0]=g):g=e[0];const h=g,[x,A]=o.useState(!1);let S;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==u?(S=B=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(B,{onClick:F=>{F.stopPropagation(),d()},children:[t.jsx(D,{name:"edit",className:"h-4 w-4 mr-px"}),u("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"}),u("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"}),u("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"}),u("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=l,e[5]=u,e[6]=S):S=e[6];const C=S,R=a?"bg-interactive-selection":"hover:bg-interactive-hover";let k;e[7]!==R?(k=oe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",R),e[7]=R,e[8]=k):k=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=h?void 0:B=>{B.preventDefault(),A(!0)},e[9]=y):y=e[9];let v;e[10]!==k?(v=t.jsx("div",{className:k,onContextMenu:y}),e[10]=k,e[11]=v):v=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]!==f?(K=f(n.mode),e[14]=n.mode,e[15]=f,e[16]=K):K=e[16];let U;e[17]!==n||e[18]!==j.scope||e[19]!==u?(U=(j.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)?u("settings.agents.sidebar.badge.system"):j.scope}),e[17]=n,e[18]=j.scope,e[19]=u,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 I;e[25]!==n.description?(I=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[25]=n.description,e[26]=I):I=e[26];let P;e[27]!==r||e[28]!==M||e[29]!==I?(P=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,I]}),e[27]=r,e[28]=M,e[29]=I,e[30]=P):P=e[30];let z;e[31]!==p?(z=B=>{B&&A(!1),p(B)},e[31]=p,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(G,{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 J;e[34]!==C?(J=t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:C(Ss)}),e[34]=C,e[35]=J):J=e[35];let _;e[36]!==m||e[37]!==z||e[38]!==J?(_=t.jsxs(gs,{open:m,onOpenChange:z,children:[T,J]}),e[36]=m,e[37]=z,e[38]=J,e[39]=_):_=e[39];let ee;e[40]!==P||e[41]!==_?(ee=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,_]}),e[40]=P,e[41]=_,e[42]=ee):ee=e[42];let Q;e[43]!==ee||e[44]!==v?(Q=t.jsx(bn,{render:v,children:ee}),e[43]=ee,e[44]=v,e[45]=Q):Q=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 V;return e[48]!==x||e[49]!==Q||e[50]!==N?(V=t.jsxs(yn,{open:x,onOpenChange:A,children:[Q,N]}),e[48]=x,e[49]=Q,e[50]=N,e[51]=V):V=e[51],V};function So(s,e,n){return Math.min(n,Math.max(e,s))}function Qp(s){if(!Number.isFinite(s))return 0;const e=String(s);if(e.includes("e-")){const[,a]=e.split("e-");return Number(a)||0}const n=e.split(".");return n.length===2?n[1].length:0}function Co(s,e){const n=Qp(e);return n<=0?s:Number(s.toFixed(n))}const ks=fe.forwardRef((s,e)=>{const n=Ze.c(125);let a,r,i,l,d,c,f,m,p,u,j,g,h;n[0]!==s?({value:h,onValueChange:f,min:p,max:u,step:j,className:a,containerClassName:r,onBlur:d,disabled:i,fallbackValue:l,onClear:c,emptyLabel:g,...m}=s,n[0]=s,n[1]=a,n[2]=r,n[3]=i,n[4]=l,n[5]=d,n[6]=c,n[7]=f,n[8]=m,n[9]=p,n[10]=u,n[11]=j,n[12]=g,n[13]=h):(a=n[1],r=n[2],i=n[3],l=n[4],d=n[5],c=n[6],f=n[7],m=n[8],p=n[9],u=n[10],j=n[11],g=n[12],h=n[13]);const x=p===void 0?-1/0:p,A=u===void 0?1/0:u,S=j===void 0?1:j,C=g===void 0?"—":g,{t:R}=st();let k;n[14]!==h?(k=()=>h===void 0?"":String(h),n[14]=h,n[15]=k):k=n[15];const[y,v]=fe.useState(k),{isMobile:E}=Ms(),K=fe.useRef(!1),U=fe.useRef(null);let M;n[16]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{if(typeof document>"u"||typeof window>"u")return;U.current?.();const De=Te=>{Te.preventDefault(),Te.stopPropagation(),Te.stopImmediatePropagation?.(),U.current?.()},Pe=window.setTimeout(()=>{U.current?.()},700),Oe=()=>{window.clearTimeout(Pe),document.removeEventListener("click",De,!0),U.current=null};U.current=Oe,document.addEventListener("click",De,!0)},n[16]=M):M=n[16];const I=M;let P,z;n[17]===Symbol.for("react.memo_cache_sentinel")?(P=()=>()=>{U.current?.()},z=[],n[17]=P,n[18]=z):(P=n[17],z=n[18]),fe.useEffect(P,z);let T,J;n[19]!==h?(J=()=>{v(h===void 0?"":String(h))},T=[h],n[19]=h,n[20]=T,n[21]=J):(T=n[20],J=n[21]),fe.useEffect(J,T);let _;e:{if(h!==void 0){_=h;break e}if(l!==void 0){_=l;break e}if(Number.isFinite(x)){_=x;break e}_=0}const ee=_;let Q;n[22]!==A||n[23]!==x||n[24]!==f||n[25]!==S?(Q=De=>{const Pe=So(De,x,A);f(Co(Pe,S))},n[22]=A,n[23]=x,n[24]=f,n[25]=S,n[26]=Q):Q=n[26];const N=Q;let V;n[27]!==N||n[28]!==c?(V=De=>{const Pe=De.target.value;if(v(Pe),Pe.trim()===""){c?.();return}const Oe=Number(Pe);Number.isFinite(Oe)&&N(Oe)},n[27]=N,n[28]=c,n[29]=V):V=n[29];const B=V;let F;n[30]!==y||n[31]!==A||n[32]!==x||n[33]!==d||n[34]!==c||n[35]!==f||n[36]!==S||n[37]!==h?(F=De=>{if(y.trim()===""){c||v(h===void 0?"":String(h)),d?.(De);return}const Pe=Number(y);if(!Number.isFinite(Pe))v(h===void 0?"":String(h));else{const Oe=So(Pe,x,A),Te=Co(Oe,S);Te!==h&&f(Te),v(String(Te))}d?.(De)},n[30]=y,n[31]=A,n[32]=x,n[33]=d,n[34]=c,n[35]=f,n[36]=S,n[37]=h,n[38]=F):F=n[38];const O=F,q=!!(i||ee>=A),$=!!(i||ee<=x);let ie;n[39]!==ee||n[40]!==N||n[41]!==$||n[42]!==S?(ie=()=>{$||N(ee-S)},n[39]=ee,n[40]=N,n[41]=$,n[42]=S,n[43]=ie):ie=n[43];const le=ie;let ne;n[44]!==ee||n[45]!==N||n[46]!==q||n[47]!==S?(ne=()=>{q||N(ee+S)},n[44]=ee,n[45]=N,n[46]=q,n[47]=S,n[48]=ne):ne=n[48];const ye=ne;let ae;if(n[49]!==a||n[50]!==r||n[51]!==$||n[52]!==y||n[53]!==C||n[54]!==le||n[55]!==ye||n[56]!==q||n[57]!==E||n[58]!==R||n[59]!==h){ae=Symbol.for("react.early_return_sentinel");e:{const De=Oe=>Te=>{Te.preventDefault(),Te.stopPropagation(),K.current=!0,I(),Oe()},Pe=Oe=>Te=>{if(K.current){K.current=!1,Te.preventDefault(),Te.stopPropagation();return}Oe()};if(E){let Oe;n[61]!==r?(Oe=oe("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",r),n[61]=r,n[62]=Oe):Oe=n[62];let Te;n[63]!==R?(Te=R("numberInput.actions.decreaseAria"),n[63]=R,n[64]=Te):Te=n[64];const Ue=De(le),Be=Pe(le),Ke=!$&&"active:bg-interactive-hover";let Je;n[65]!==Ke?(Je=oe("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",Ke),n[65]=Ke,n[66]=Je):Je=n[66];let ue;n[67]===Symbol.for("react.memo_cache_sentinel")?(ue=t.jsx(D,{name:"subtract",className:"block h-4 w-4"}),n[67]=ue):ue=n[67];const Y=t.jsx("button",{type:"button","aria-label":Te,disabled:$,onTouchStart:Ue,onClick:Be,className:Je,children:ue});let de;n[68]!==a?(de=oe("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",a),n[68]=a,n[69]=de):de=n[69];const je=h===void 0?C:y;let Re;n[70]!==de||n[71]!==je?(Re=t.jsx("div",{className:de,"aria-live":"polite",children:je}),n[70]=de,n[71]=je,n[72]=Re):Re=n[72];let Ie;n[73]!==R?(Ie=R("numberInput.actions.increaseAria"),n[73]=R,n[74]=Ie):Ie=n[74];const Ve=De(ye),X=Pe(ye),b=!q&&"active:bg-interactive-hover";let be;n[75]!==b?(be=oe("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",b),n[75]=b,n[76]=be):be=n[76];let Ee;n[77]===Symbol.for("react.memo_cache_sentinel")?(Ee=t.jsx(D,{name:"add",className:"block h-4 w-4"}),n[77]=Ee):Ee=n[77];const ze=t.jsx("button",{type:"button","aria-label":Ie,disabled:q,onTouchStart:Ve,onClick:X,className:be,children:Ee});let qe;n[78]!==Oe||n[79]!==Y||n[80]!==Re||n[81]!==ze?(qe=t.jsxs("div",{className:Oe,children:[Y,Re,ze]}),n[78]=Oe,n[79]=Y,n[80]=Re,n[81]=ze,n[82]=qe):qe=n[82],ae=qe;break e}}n[49]=a,n[50]=r,n[51]=$,n[52]=y,n[53]=C,n[54]=le,n[55]=ye,n[56]=q,n[57]=E,n[58]=R,n[59]=h,n[60]=ae}else ae=n[60];if(ae!==Symbol.for("react.early_return_sentinel"))return ae;let ge;n[83]!==r?(ge=oe("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",r),n[83]=r,n[84]=ge):ge=n[84];let Ne;n[85]!==R?(Ne=R("numberInput.actions.decreaseAria"),n[85]=R,n[86]=Ne):Ne=n[86];let he;n[87]!==ee||n[88]!==N||n[89]!==S?(he=()=>N(ee-S),n[87]=ee,n[88]=N,n[89]=S,n[90]=he):he=n[90];let we,ce;n[91]===Symbol.for("react.memo_cache_sentinel")?(we=oe("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),ce=t.jsx(D,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=we,n[92]=ce):(we=n[91],ce=n[92]);let Z;n[93]!==$||n[94]!==Ne||n[95]!==he?(Z=t.jsx("button",{type:"button","aria-label":Ne,disabled:$,onClick:he,className:we,children:ce}),n[93]=$,n[94]=Ne,n[95]=he,n[96]=Z):Z=n[96];const se=m.inputMode??"numeric";let ve;n[97]!==a?(ve=oe("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",a),n[97]=a,n[98]=ve):ve=n[98];let H;n[99]!==i||n[100]!==y||n[101]!==O||n[102]!==B||n[103]!==m||n[104]!==e||n[105]!==se||n[106]!==ve?(H=t.jsx("input",{...m,ref:e,type:"text",inputMode:se,value:y,onChange:B,onBlur:O,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ve}),n[99]=i,n[100]=y,n[101]=O,n[102]=B,n[103]=m,n[104]=e,n[105]=se,n[106]=ve,n[107]=H):H=n[107];let te;n[108]!==R?(te=R("numberInput.actions.increaseAria"),n[108]=R,n[109]=te):te=n[109];let re;n[110]!==ee||n[111]!==N||n[112]!==S?(re=()=>N(ee+S),n[110]=ee,n[111]=N,n[112]=S,n[113]=re):re=n[113];let pe,Me;n[114]===Symbol.for("react.memo_cache_sentinel")?(pe=oe("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Me=t.jsx(D,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=pe,n[115]=Me):(pe=n[114],Me=n[115]);let Se;n[116]!==q||n[117]!==te||n[118]!==re?(Se=t.jsx("button",{type:"button","aria-label":te,disabled:q,onClick:re,className:pe,children:Me}),n[116]=q,n[117]=te,n[118]=re,n[119]=Se):Se=n[119];let Ae;return n[120]!==ge||n[121]!==Z||n[122]!==H||n[123]!==Se?(Ae=t.jsxs("div",{className:ge,children:[Z,H,Se]}),n[120]=ge,n[121]=Z,n[122]=H,n[123]=Se,n[124]=Ae):Ae=n[124],Ae});ks.displayName="NumberInput";const Io=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Xa=s=>s==="allow"||s==="ask"||s==="deny",An=(s,e)=>`${s}::${e}`,jn=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&Xa(n.action)&&e.set(An(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(An(n.permission,n.pattern),n);return e},Po=s=>[...s].sort((e,n)=>{const a=e.permission.localeCompare(n.permission);return a!==0?a:e.pattern.localeCompare(n.pattern)}),Yp=(s,e)=>{const n=Po(jn(s)),a=Po(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})},Xp=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",Zp=(s,e)=>jn(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),Tr=s=>{if(Array.isArray(s))return jn(s);if(Xa(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(Xa(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))Xa(i)&&e.push({permission:n,pattern:r,action:i})}return e},eg=(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)},tg=(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):[]},sg=()=>{const{t:s}=st(),{isMobile:e}=Ms(),n=it(Y=>Y.providers),{selectedAgentName:a,getAgentByName:r,createAgent:i,updateAgent:l,agents:d,agentDraft:c,setAgentDraft:f}=mr(Es(Y=>({selectedAgentName:Y.selectedAgentName,getAgentByName:Y.getAgentByName,createAgent:Y.createAgent,updateAgent:Y.updateAgent,agents:Y.agents,agentDraft:Y.agentDraft,setAgentDraft:Y.setAgentDraft}))),m=a?r(a):null,p=!!(c&&c.name===a&&!m),[u,j]=o.useState(""),[g,h]=o.useState("user"),[x,A]=o.useState(""),[S,C]=o.useState("subagent"),[R,k]=o.useState(""),[y,v]=o.useState(""),[E,K]=o.useState(void 0),[U,M]=o.useState(void 0),[I,P]=o.useState(""),[z,T]=o.useState("allow"),[J,_]=o.useState([]),[ee,Q]=o.useState([]),[N,V]=o.useState(""),[B,F]=o.useState("*"),[O,q]=o.useState(!1),[$,ie]=o.useState(!1),le=o.useRef(null),ne=Ns(Y=>Y.currentDirectory??null),[ye,ae]=o.useState([]),ge=o.useMemo(()=>tg(n,R),[R,n]),Ne=ge.length>0,he=o.useMemo(()=>!y||!ge.includes(y)?"__default":y,[y,ge]),we=Ne&&(!y||ge.includes(y)),ce=xu(Y=>Y.permission);o.useEffect(()=>{let Y=!1;return(async()=>{const je=await js.listToolIds({directory:ne});if(Y)return;const Re=new Set(["write","patch","multiedit"]),Ie=je.map(Ve=>typeof Ve=="string"?Ve.trim():"").filter(Boolean).filter(Ve=>Ve!=="*").filter(Ve=>Ve!=="invalid").filter(Ve=>!Re.has(Ve));ae(Array.from(new Set(Ie)).sort((Ve,X)=>Ve.localeCompare(X)))})(),()=>{Y=!0}},[ne]);const Z=o.useMemo(()=>{const Y=new Set;for(const de of d){const je=jn(Tr(de.permission));for(const Re of je)Re.permission&&Re.permission!=="*"&&Re.permission!=="invalid"&&Y.add(Re.permission)}for(const de of Object.values(ce))for(const je of de){const Re=je.permission?.trim();Re&&Re!=="invalid"&&Y.add(Re)}for(const de of ye)Y.add(de);return Array.from(Y).sort((de,je)=>de.localeCompare(je))},[d,ce,ye]),se=o.useMemo(()=>Fa(J),[J]),ve=o.useMemo(()=>Fa(ee),[ee]),H=o.useCallback(Y=>ve.get(An(Y,"*"))?.action,[ve]),te=o.useCallback(Y=>ee.filter(de=>de.permission===Y&&de.pattern!=="*").sort((de,je)=>de.pattern.localeCompare(je.pattern)),[ee]),re=o.useMemo(()=>{const Y=new Set;for(const de of Io)Y.add(de);for(const de of Z)Y.add(de);return Array.from(Y).sort((de,je)=>de.localeCompare(je))},[Z]),pe=o.useCallback(Y=>{const de=Y==="*"?z:H(Y)??z,je=te(Y),Re=!1,Ie=je.reduce((X,b)=>(X[b.action]=(X[b.action]??0)+1,X),{allow:0,ask:0,deny:0}),Ve=["allow","ask","deny"].filter(X=>Ie[X]>0).map(X=>`${Ie[X]} ${X}`).join(", ");return{defaultAction:de,patternRulesCount:je.length,patternSummary:Ve,hasDefaultHint:Re}},[te,H,z]),Me=o.useCallback(Y=>s(Y==="allow"?"settings.common.permission.allow":Y==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),Se=o.useCallback(Y=>Y==="global"?s("settings.common.scope.global"):Me(Y),[Me,s]),Ae=o.useMemo(()=>{const Y=new Set;for(const de of Io)Y.add(de);for(const de of Z)Y.add(de);return Array.from(Y).sort((de,je)=>de.localeCompare(je))},[Z]),De=o.useCallback((Y,de,je)=>{Q(Re=>{const Ie=Fa(Re);return Ie.set(An(Y,de),{permission:Y,pattern:de,action:je}),Array.from(Ie.values())})},[]),Pe=o.useCallback((Y,de)=>{Q(je=>{const Re=Fa(je);return Re.delete(An(Y,de)),Array.from(Re.values())})},[]),Oe=o.useCallback((Y,de)=>{const je=se.get(An(Y,de));if(je){De(Y,de,je.action);return}Pe(Y,de)},[se,Pe,De]),Te=o.useCallback((Y,de,je)=>{De(Y,de,je)},[De]),Ue=o.useCallback(Y=>{T(Y),Q(de=>de.filter(je=>!(je.pattern==="*"&&je.action===Y)))},[]),Be=o.useCallback(Y=>{const de=N.trim();if(!de){W.error(s("settings.agents.page.toast.permissionNameRequired"));return}const je=B.trim()||"*";if(de==="*"&&je==="*"){Ue(Y),V(""),F("*");return}je==="*"&&de!=="*"&&Y===z?Pe(de,"*"):De(de,je,Y),V(""),F("*")},[z,N,B,Pe,Ue,s,De]),Ke=o.useCallback(Y=>Y==="*"?s("settings.agents.page.permissions.defaultLabel"):Y==="webfetch"?"WebFetch":Y==="websearch"?"WebSearch":Y==="codesearch"?"CodeSearch":Y==="doom_loop"?"Doom Loop":Y==="external_directory"?"External Directory":Y==="todowrite"?"TodoWrite":Y==="todoread"?"TodoRead":Y.split(/[_-]+/g).filter(Boolean).map(de=>de.charAt(0).toUpperCase()+de.slice(1)).join(" "),[s]);o.useEffect(()=>{V(""),F("*");const Y=de=>{const je=jn(de),Re=Xp(je),Ie=Zp(je,Re);return T(Re),_(Ie),Q(Ie),{global:Re,rules:Ie}};if(p&&c){const de=c.name||"",je=c.scope||"user",Re=c.description||"",Ie=c.mode||"subagent",Ve=c.model||"",X=c.variant||"",b=c.temperature??void 0,be=c.top_p??void 0,Ee=c.prompt||"";j(de),h(je),A(Re),C(Ie),k(Ve),v(X),K(b),M(be),P(Ee);const ze=Tr(c.permission),qe=Y(ze);le.current={draftName:de,draftScope:je,description:Re,mode:Ie,model:Ve,variant:X,temperature:b,topP:be,prompt:Ee,globalPermission:qe.global,permissionRules:qe.rules};return}if(m&&a===m.name){const de=m.description||"",je=m.mode||"subagent",Re=m.model?.providerID&&m.model?.modelID?`${m.model.providerID}/${m.model.modelID}`:"",Ie=m.variant||"",Ve=m.temperature,X=m.topP,b=m.prompt||"";A(de),C(je),k(Re),v(Ie),K(Ve),M(X),P(b);const be=Y(Tr(m.permission));le.current={draftName:"",draftScope:"user",description:de,mode:je,model:Re,variant:Ie,temperature:Ve,topP:X,prompt:b,globalPermission:be.global,permissionRules:be.rules}}},[c,p,m,a]);const Je=o.useMemo(()=>{const Y=le.current;return Y?!!(p&&(u!==Y.draftName||g!==Y.draftScope)||x!==Y.description||S!==Y.mode||R!==Y.model||y!==Y.variant||E!==Y.temperature||U!==Y.topP||I!==Y.prompt||z!==Y.globalPermission||!Yp(ee,Y.permissionRules)):!1},[x,u,g,z,p,S,R,ee,I,E,U,y]),ue=async()=>{const Y=p?u.trim().replace(/\s+/g,"-"):a?.trim();if(!Y){W.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(p&&d.some(de=>de.name===Y)){W.error(s("settings.agents.sidebar.toast.agentExists"));return}ie(!0);try{const de=R.trim(),je=y.trim(),Re=I.trim(),Ie=eg(z,ee),Ve={name:Y,description:x.trim()||void 0,mode:S,model:de===""?null:de,variant:je===""?null:je||void 0,temperature:E??null,top_p:U??null,prompt:Re||(p?void 0:null),permission:Ie,scope:p?g:void 0};let X;p?(X=await i(Ve),X.ok&&f(null)):X=await l(Y,Ve),X.ok?X.requiresManualRestart?W.warning(s("settings.agents.page.toast.savedManualRestart")):W.success(s(p?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):W.error(s(p?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(de){console.error("Error saving agent:",de);const je=de instanceof Error&&de.message?de.message:s("settings.agents.page.toast.saveUnexpectedError");W.error(je)}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:p?s("settings.agents.page.title.new"):a}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(p?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.identityRole")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&t.jsxs("div",{"data-settings-item":"agents.name",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.agentName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),t.jsx(Xe,{value:u,onChange:Y=>j(Y.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Dt,{value:g,onValueChange:Y=>h(Y),children:[t.jsx(Et,{className:"w-fit min-w-[100px]",children:t.jsx(zt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Mt,{align:"end",children:[t.jsx(mt,{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(mt,{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:x,onChange:Y=>A(Y.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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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(G,{variant:"chip",size:"xs","aria-pressed":S==="primary",onClick:()=>C("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(G,{variant:"chip",size:"xs","aria-pressed":S==="subagent",onClick:()=>C("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(G,{variant:"chip",size:"xs","aria-pressed":S==="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(ja,{providerId:xn(R)?.providerId??"",modelId:xn(R)?.modelId??"",onChange:(Y,de)=>{k(Y&&de?`${Y}/${de}`:""),v("")}})})]}),t.jsxs("div",{"data-settings-item":"agents.variant",className:oe("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:oe("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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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:oe("flex items-center gap-2",e?"w-full":"w-fit"),children:we?t.jsxs(Dt,{value:he,onValueChange:Y=>v(Y==="__default"?"":Y),children:[t.jsx(Et,{className:oe("max-w-full",e?"w-full":"w-fit min-w-[10rem]"),children:t.jsx(zt,{placeholder:s("settings.agents.page.field.variantPlaceholder"),children:Y=>Y==="__default"?s("chat.modelControls.default"):Y})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"__default",children:s("chat.modelControls.default")}),ge.map(Y=>t.jsx(mt,{value:Y,children:Y},Y))]})]}):t.jsxs(t.Fragment,{children:[t.jsx(Xe,{value:y,onChange:Y=>v(Y.target.value),placeholder:s("settings.agents.page.field.variantPlaceholder"),disabled:!R&&!y,className:oe("h-7 w-40",e&&"w-full")}),y&&t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>v(""),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:oe("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:oe("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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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:oe("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(ks,{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(G,{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:oe("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:oe("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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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:oe("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(ks,{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(G,{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:I,onChange:Y=>P(Y.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(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>q(Y=>!Y),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(Dt,{value:z,onValueChange:Y=>Ue(Y),children:[t.jsx(Et,{className:"w-[100px]",children:t.jsx(zt,{children:Me(z)})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(mt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(mt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:re.filter(Y=>Y!=="*").map(Y=>{const de=Ke(Y),{defaultAction:je,patternRulesCount:Re}=pe(Y),Ie=H(Y),Ve=Ie??"global",X=te(Y),b=["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:de}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:Y})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Re>0?s("settings.agents.page.permissions.globalSummary",{summary:je}):je})]}),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:"*"}),Ie&&t.jsx(G,{size:"sm",variant:"ghost",onClick:()=>Oe(Y,"*"),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(Dt,{value:Ve,onValueChange:be=>{if(be==="global"){Pe(Y,"*");return}De(Y,"*",be)},children:[t.jsx(Et,{className:"w-[90px]",children:t.jsx(zt,{children:Se(Ve)})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"global",children:s("settings.common.scope.global")}),b.map(be=>t.jsx(mt,{value:be,className:"capitalize",children:Me(be)},be))]})]})]}),X.map(be=>{const Ee=An(be.permission,be.pattern),ze=se.get(Ee),qe=!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}),qe&&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")}),(qe||rt)&&t.jsx(G,{size:"sm",variant:"ghost",onClick:()=>qe?Pe(be.permission,be.pattern):Oe(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(Dt,{value:be.action,onValueChange:lt=>Te(be.permission,be.pattern,lt),children:[t.jsx(Et,{className:"w-[90px]",children:t.jsx(zt,{children:Me(be.action)})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(mt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(mt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},Ee)})]})]},Y)})}),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(Dt,{value:N,onValueChange:V,children:[t.jsx(Et,{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(Mt,{children:Ae.map(Y=>t.jsx(mt,{value:Y,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:Ke(Y)})})},Y))})]}),t.jsx(Xe,{value:B,onChange:Y=>F(Y.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(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Be("allow"),children:s("settings.common.permission.allow")}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Be("ask"),children:s("settings.common.permission.ask")}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Be("deny"),children:s("settings.common.permission.deny")})]})]})]})]}):t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:re.map((Y,de)=>{const{defaultAction:je,patternRulesCount:Re,patternSummary:Ie,hasDefaultHint:Ve}=pe(Y),X=Ke(Y),b=Ve?`${je} (env blocked)`:je;return t.jsxs("div",{className:oe("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",de>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:Y})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Re>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:b})}):t.jsx("span",{className:oe("typography-micro capitalize px-1.5 py-0.5 rounded",b==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":b==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:b}),Re>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:Ie})})]})]},Y)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(G,{onClick:ue,disabled:$||!Je,size:"xs",className:"!font-normal",children:s($?"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")})]})})},ng="~/.config/opencode/AGENTS.md",wc=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},ag=s=>s.length>0&&!s.endsWith(`
2
+ `)?`${s}
3
+ `:s,Oa={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},rg=(s,e)=>s==="custom"?e:bu(s),ig=s=>s==="custom"?"custom":ac(s)?s:"concise",Ao={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"},Do=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 wc(n,e))},og=()=>{const{t:s}=st(),[e,n]=o.useState(""),[a,r]=o.useState(Oa.responseStyleEnabled),[i,l]=o.useState(Oa.responseStylePreset),[d,c]=o.useState(Oa.responseStyleCustomInstructions),[f,m]=o.useState(!0),[p,u]=o.useState(!1),[j,g]=o.useState(""),h=o.useRef(null);o.useEffect(()=>{const C=new AbortController;return(async()=>{try{const[k,y]=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 v=Oa;if(k.ok){const E=await k.json();v={...v,responseStyleEnabled:E.responseStyleEnabled===!0,responseStylePreset:ig(E.responseStylePreset),responseStyleCustomInstructions:typeof E.responseStyleCustomInstructions=="string"?E.responseStyleCustomInstructions:""},typeof E.globalBehaviorPrompt=="string"&&(v={...v,prompt:E.globalBehaviorPrompt})}if(!v.prompt.trim()&&y.ok){const E=await y.json();typeof E.content=="string"&&(v={...v,prompt:E.content})}n(v.prompt),r(v.responseStyleEnabled),l(v.responseStylePreset),c(v.responseStyleCustomInstructions),g(v.prompt),h.current={enabled:v.responseStyleEnabled,preset:v.responseStylePreset,custom:v.responseStyleCustomInstructions}}catch(k){k.name!=="AbortError"&&console.warn("Failed to load behavior settings:",k)}finally{m(!1)}})(),()=>C.abort()},[]),o.useEffect(()=>{if(f)return;const C=h.current;if(C&&C.enabled===a&&C.preset===i&&C.custom===d)return;const R={enabled:a,preset:i,custom:d},k=setTimeout(async()=>{try{await Do({responseStyleEnabled:R.enabled,responseStylePreset:R.preset,responseStyleCustomInstructions:R.custom},s("settings.behavior.page.toast.saveFailed")),h.current=R}catch(y){const v=y instanceof Error?y.message:s("settings.behavior.page.toast.saveFailed");W.error(v)}},400);return()=>clearTimeout(k)},[a,i,d,f,s]);const x=rg(i,d),A=e!==j,S=async()=>{u(!0);try{const C=ag(e),R=await dt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:C})});if(!R.ok)throw new Error(await wc(R,s("settings.behavior.page.toast.saveFailed")));await Do({globalBehaviorPrompt:C},s("settings.behavior.page.toast.saveFailed")),n(C),g(C),W.success(s("settings.behavior.page.toast.saved"))}catch(C){console.error("Failed to save behavior:",C);const R=C instanceof Error?C.message:s("settings.behavior.page.toast.saveFailed");W.error(R)}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 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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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:ng})})]})})]})]})}),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:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),t.jsx(G,{onClick:S,disabled:p||!A||f,size:"xs",className:"!font-normal",children:s(p?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),t.jsxs("div",{"data-settings-item":"behavior.response-style",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.responseStyle")}),t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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(bt,{checked:a,onChange:r,disabled:f,ariaLabel:s("settings.behavior.page.responseStyle.enableAria")}),s("settings.behavior.page.responseStyle.enable")]}),t.jsxs(Dt,{value:i,onValueChange:C=>l(C),disabled:f||!a,children:[t.jsx(Et,{className:"w-full sm:w-56",size:"lg",children:t.jsx(zt,{children:C=>C==="custom"?s("settings.behavior.page.responseStyle.option.custom"):ac(C)?s(Ao[C]):null})}),t.jsxs(Mt,{children:[yu.map(C=>t.jsx(mt,{value:C,children:s(Ao[C])},C)),t.jsx(mt,{value:"custom",children:s("settings.behavior.page.responseStyle.option.custom")})]})]}),t.jsx(hs,{value:x,onChange:C=>c(C.target.value),placeholder:s("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!a||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},lg=s=>{const e=Ze.c(169),{onItemSelect:n}=s,{t:a}=st(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,f]=o.useState(null),[m,p]=o.useState(null),[u,j]=o.useState(!1),[g,h]=o.useState(null),{selectedCommandName:x,commands:A,setSelectedCommand:S,setCommandDraft:C,createCommand:R,deleteCommand:k,loadCommands:y}=pr(Es(cg)),v=an(dg),E=an(ug);let K,U;e[0]!==y||e[1]!==E?(K=()=>{y(),E()},U=[y,E],e[0]=y,e[1]=E,e[2]=K,e[3]=U):(K=e[2],U=e[3]),o.useEffect(K,U);let M;e[4]!==v?(M=new Set(v.map(mg)),e[4]=v,e[5]=M):M=e[5];const I=M;let P;if(e[6]!==A||e[7]!==I){let xe;e[9]!==I?(xe=et=>!I.has(et.name),e[9]=I,e[10]=xe):xe=e[10],P=A.filter(xe),e[6]=A,e[7]=I,e[8]=P}else P=e[8];const z=P;let T,J;e[11]!==x||e[12]!==S||e[13]!==I?(T=()=>{x&&I.has(x)&&S(null)},J=[x,S,I],e[11]=x,e[12]=S,e[13]=I,e[14]=T,e[15]=J):(T=e[14],J=e[15]),o.useEffect(T,J);let _;e[16]!==A||e[17]!==n||e[18]!==C||e[19]!==S?(_=()=>{let xe="new-command",et=1;for(;A.some(nt=>nt.name===xe);)xe=`new-command-${et}`,et++;C({name:xe,scope:"user"}),S(xe),n?.()},e[16]=A,e[17]=n,e[18]=C,e[19]=S,e[20]=_):_=e[20];const ee=_;let Q;e[21]!==a?(Q=async xe=>{if(Yn(xe)){W.error(a("settings.commands.sidebar.toast.builtInCannotDelete"));return}f(xe),p("delete")},e[21]=a,e[22]=Q):Q=e[22];const N=Q;let V;e[23]===Symbol.for("react.memo_cache_sentinel")?(V=async xe=>{Yn(xe)&&(f(xe),p("reset"))},e[23]=V):V=e[23];const B=V;let F;e[24]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{f(null),p(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;j(!0),await k(c.name)?(m==="delete"?W.success(a("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):W.success(a("settings.commands.sidebar.toast.commandReset",{name:c.name})),O()):m==="delete"?W.error(a("settings.commands.sidebar.toast.deleteFailed")):W.error(a("settings.commands.sidebar.toast.resetFailed")),j(!1)},e[25]=c,e[26]=m,e[27]=k,e[28]=a,e[29]=q):q=e[29];const $=q;let ie;e[30]!==A||e[31]!==C||e[32]!==S?(ie=xe=>{const et=xe.name;let nt=1,He=`${et}-copy`;for(;A.some(yt=>yt.name===He);)nt++,He=`${et}-copy-${nt}`;C({name:He,scope:xe.scope||"user",description:xe.description,template:xe.template,agent:xe.agent,model:xe.model}),S(He)},e[30]=A,e[31]=C,e[32]=S,e[33]=ie):ie=e[33];const le=ie;let ne;e[34]===Symbol.for("react.memo_cache_sentinel")?(ne=xe=>{d(xe.name),i(xe)},e[34]=ne):ne=e[34];const ye=ne;let ae;e[35]!==A||e[36]!==R||e[37]!==k||e[38]!==r||e[39]!==l||e[40]!==S||e[41]!==a?(ae=async()=>{if(!r)return;const xe=l.trim().replace(/\s+/g,"-");if(!xe){W.error(a("settings.commands.sidebar.toast.commandNameRequired"));return}if(xe===r.name){i(null);return}if(A.some(nt=>nt.name===xe)){W.error(a("settings.commands.sidebar.toast.commandExists"));return}await R({name:xe,description:r.description,template:r.template,agent:r.agent,model:r.model})?await k(r.name)?(W.success(`Command renamed to "${xe}"`),S(xe)):W.error(a("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):W.error(a("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=A,e[36]=R,e[37]=k,e[38]=r,e[39]=l,e[40]=S,e[41]=a,e[42]=ae):ae=e[42];const ge=ae;let Ne,he,we,ce,Z,se;if(e[43]!==z||e[44]!==ee||e[45]!==N||e[46]!==le||e[47]!==n||e[48]!==g||e[49]!==x||e[50]!==S||e[51]!==a){const xe=z.filter(Yn),et=z.filter(pg);e[58]===Symbol.for("react.memo_cache_sentinel")?(Z=oe("flex h-full flex-col","bg-background"),e[58]=Z):Z=e[58];let nt;e[59]!==a?(nt=a("settings.commands.sidebar.title"),e[59]=a,e[60]=nt):nt=e[60];let He;e[61]!==nt?(He=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:nt}),e[61]=nt,e[62]=He):He=e[62];let yt;e[63]===Symbol.for("react.memo_cache_sentinel")?(yt=t.jsx(ka,{className:"mb-3"}),e[63]=yt):yt=e[63];let Nt;e[64]!==z.length||e[65]!==a?(Nt=a("settings.commands.sidebar.total",{count:z.length}),e[64]=z.length,e[65]=a,e[66]=Nt):Nt=e[66];let Tt;e[67]!==Nt?(Tt=t.jsx("span",{className:"typography-meta text-muted-foreground",children:Nt}),e[67]=Nt,e[68]=Tt):Tt=e[68];let me;e[69]===Symbol.for("react.memo_cache_sentinel")?(me=t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[69]=me):me=e[69];let $e;e[70]!==ee?($e=t.jsx(G,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:ee,children:me}),e[70]=ee,e[71]=$e):$e=e[71];let Qe;e[72]!==Tt||e[73]!==$e?(Qe=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Tt,$e]}),e[72]=Tt,e[73]=$e,e[74]=Qe):Qe=e[74],e[75]!==He||e[76]!==Qe?(se=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[He,yt,Qe]}),e[75]=He,e[76]=Qe,e[77]=se):se=e[77],Ne=Ht,he="flex-1 min-h-0",we="space-y-1 px-3 py-2",ce=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:[xe.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")}),[...xe].sort(gg).map(We=>t.jsx(Eo,{command:We,isSelected:x===We.name,onSelect:()=>{S(We.name),n?.()},onReset:()=>B(We),onDuplicate:()=>le(We),isMenuOpen:g===We.name,onMenuOpenChange:xt=>h(xt?We.name:null)},We.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(hg).map(We=>t.jsx(Eo,{command:We,isSelected:x===We.name,onSelect:()=>{S(We.name),n?.()},onRename:()=>ye(We),onDelete:()=>N(We),onDuplicate:()=>le(We),isMenuOpen:g===We.name,onMenuOpenChange:xt=>h(xt?We.name:null)},We.name))]})]}),e[43]=z,e[44]=ee,e[45]=N,e[46]=le,e[47]=n,e[48]=g,e[49]=x,e[50]=S,e[51]=a,e[52]=Ne,e[53]=he,e[54]=we,e[55]=ce,e[56]=Z,e[57]=se}else Ne=e[52],he=e[53],we=e[54],ce=e[55],Z=e[56],se=e[57];let ve;e[78]!==Ne||e[79]!==he||e[80]!==we||e[81]!==ce?(ve=t.jsx(Ne,{outerClassName:he,className:we,children:ce}),e[78]=Ne,e[79]=he,e[80]=we,e[81]=ce,e[82]=ve):ve=e[82];const H=c!==null&&m!==null;let te;e[83]!==u?(te=xe=>{!xe&&!u&&O()},e[83]=u,e[84]=te):te=e[84];let re;e[85]!==m||e[86]!==a?(re=a(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=a,e[87]=re):re=e[87];let pe;e[88]!==re?(pe=t.jsx(Ut,{children:re}),e[88]=re,e[89]=pe):pe=e[89];let Me;e[90]!==c?.name||e[91]!==m||e[92]!==a?(Me=m==="delete"?a("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):a("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[90]=c?.name,e[91]=m,e[92]=a,e[93]=Me):Me=e[93];let Se;e[94]!==Me?(Se=t.jsx(_t,{children:Me}),e[94]=Me,e[95]=Se):Se=e[95];let Ae;e[96]!==pe||e[97]!==Se?(Ae=t.jsxs(Kt,{children:[pe,Se]}),e[96]=pe,e[97]=Se,e[98]=Ae):Ae=e[98];let De;e[99]!==a?(De=a("settings.common.actions.cancel"),e[99]=a,e[100]=De):De=e[100];let Pe;e[101]!==u||e[102]!==De?(Pe=t.jsx(G,{size:"sm",variant:"ghost",onClick:O,disabled:u,children:De}),e[101]=u,e[102]=De,e[103]=Pe):Pe=e[103];let Oe;e[104]!==m||e[105]!==a?(Oe=a(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=a,e[106]=Oe):Oe=e[106];let Te;e[107]!==$||e[108]!==u||e[109]!==Oe?(Te=t.jsx(G,{size:"sm",onClick:$,disabled:u,children:Oe}),e[107]=$,e[108]=u,e[109]=Oe,e[110]=Te):Te=e[110];let Ue;e[111]!==Pe||e[112]!==Te?(Ue=t.jsxs(Jt,{children:[Pe,Te]}),e[111]=Pe,e[112]=Te,e[113]=Ue):Ue=e[113];let Be;e[114]!==Ae||e[115]!==Ue?(Be=t.jsxs(Ft,{className:"max-w-md",children:[Ae,Ue]}),e[114]=Ae,e[115]=Ue,e[116]=Be):Be=e[116];let Ke;e[117]!==H||e[118]!==te||e[119]!==Be?(Ke=t.jsx(Lt,{open:H,onOpenChange:te,children:Be}),e[117]=H,e[118]=te,e[119]=Be,e[120]=Ke):Ke=e[120];const Je=r!==null;let ue;e[121]===Symbol.for("react.memo_cache_sentinel")?(ue=xe=>!xe&&i(null),e[121]=ue):ue=e[121];let Y;e[122]!==a?(Y=a("settings.commands.sidebar.renameDialog.title"),e[122]=a,e[123]=Y):Y=e[123];let de;e[124]!==Y?(de=t.jsx(Ut,{children:Y}),e[124]=Y,e[125]=de):de=e[125];const je=r?.name??"";let Re;e[126]!==a||e[127]!==je?(Re=a("settings.commands.sidebar.renameDialog.description",{name:je}),e[126]=a,e[127]=je,e[128]=Re):Re=e[128];let Ie;e[129]!==Re?(Ie=t.jsx(_t,{children:Re}),e[129]=Re,e[130]=Ie):Ie=e[130];let Ve;e[131]!==de||e[132]!==Ie?(Ve=t.jsxs(Kt,{children:[de,Ie]}),e[131]=de,e[132]=Ie,e[133]=Ve):Ve=e[133];let X;e[134]===Symbol.for("react.memo_cache_sentinel")?(X=xe=>d(xe.target.value),e[134]=X):X=e[134];let b;e[135]!==a?(b=a("settings.commands.sidebar.renameDialog.placeholder"),e[135]=a,e[136]=b):b=e[136];let be;e[137]!==ge?(be=xe=>{xe.key==="Enter"&&ge()},e[137]=ge,e[138]=be):be=e[138];let Ee;e[139]!==l||e[140]!==b||e[141]!==be?(Ee=t.jsx(Xe,{value:l,onChange:X,placeholder:b,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:be}),e[139]=l,e[140]=b,e[141]=be,e[142]=Ee):Ee=e[142];let ze;e[143]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>i(null),e[143]=ze):ze=e[143];let qe;e[144]!==a?(qe=a("settings.common.actions.cancel"),e[144]=a,e[145]=qe):qe=e[145];let rt;e[146]!==qe?(rt=t.jsx(G,{size:"sm",variant:"ghost",onClick:ze,children:qe}),e[146]=qe,e[147]=rt):rt=e[147];let lt;e[148]!==a?(lt=a("settings.common.actions.rename"),e[148]=a,e[149]=lt):lt=e[149];let at;e[150]!==ge||e[151]!==lt?(at=t.jsx(G,{size:"sm",onClick:ge,children:lt}),e[150]=ge,e[151]=lt,e[152]=at):at=e[152];let ct;e[153]!==rt||e[154]!==at?(ct=t.jsxs(Jt,{children:[rt,at]}),e[153]=rt,e[154]=at,e[155]=ct):ct=e[155];let Ye;e[156]!==Ve||e[157]!==Ee||e[158]!==ct?(Ye=t.jsxs(Ft,{children:[Ve,Ee,ct]}),e[156]=Ve,e[157]=Ee,e[158]=ct,e[159]=Ye):Ye=e[159];let _e;e[160]!==Je||e[161]!==Ye?(_e=t.jsx(Lt,{open:Je,onOpenChange:ue,children:Ye}),e[160]=Je,e[161]=Ye,e[162]=_e):_e=e[162];let ft;return e[163]!==Z||e[164]!==se||e[165]!==ve||e[166]!==Ke||e[167]!==_e?(ft=t.jsxs("div",{className:Z,children:[se,ve,Ke,_e]}),e[163]=Z,e[164]=se,e[165]=ve,e[166]=Ke,e[167]=_e,e[168]=ft):ft=e[168],ft},Eo=s=>{const e=Ze.c(47),{command:n,isSelected:a,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,isMenuOpen:f,onMenuOpenChange:m}=s,{t:p}=st();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=va(),e[0]=u):u=e[0];const j=u,[g,h]=o.useState(!1);let x;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==p?(x=Q=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(Q,{onClick:N=>{N.stopPropagation(),d()},children:[t.jsx(D,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),t.jsxs(Q,{onClick:N=>{N.stopPropagation(),c()},children:[t.jsx(D,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),l&&t.jsxs(Q,{onClick:N=>{N.stopPropagation(),l()},children:[t.jsx(D,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),i&&t.jsxs(Q,{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"}),p("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=l,e[5]=p,e[6]=x):x=e[6];const A=x,S=a?"bg-interactive-selection":"hover:bg-interactive-hover";let C;e[7]!==S?(C=oe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",S),e[7]=S,e[8]=C):C=e[8];let R;e[9]===Symbol.for("react.memo_cache_sentinel")?(R=j?void 0:Q=>{Q.preventDefault(),h(!0)},e[9]=R):R=e[9];let k;e[10]!==C?(k=t.jsx("div",{className:C,onContextMenu:R}),e[10]=C,e[11]=k):k=e[11];let y;e[12]!==n.name?(y=t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[12]=n.name,e[13]=y):y=e[13];let v;e[14]!==n||e[15]!==p?(v=(n.scope||Yn(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:Yn(n)?p("settings.agents.sidebar.badge.system"):n.scope}),e[14]=n,e[15]=p,e[16]=v):v=e[16];let E;e[17]!==y||e[18]!==v?(E=t.jsxs("div",{className:"flex items-center gap-2",children:[y,v]}),e[17]=y,e[18]=v,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=Q=>{Q&&h(!1),m(Q)},e[26]=m,e[27]=M):M=e[27];let I;e[28]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx(ms,{asChild:!0,children:t.jsx(G,{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]=I):I=e[28];let P;e[29]!==A?(P=t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:A(Ss)}),e[29]=A,e[30]=P):P=e[30];let z;e[31]!==f||e[32]!==M||e[33]!==P?(z=t.jsxs(gs,{open:f,onOpenChange:M,children:[I,P]}),e[31]=f,e[32]=M,e[33]=P,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 J;e[38]!==T||e[39]!==k?(J=t.jsx(bn,{render:k,children:T}),e[38]=T,e[39]=k,e[40]=J):J=e[40];let _;e[41]!==A?(_=t.jsx(vn,{className:"w-fit min-w-20",children:A(ln)}),e[41]=A,e[42]=_):_=e[42];let ee;return e[43]!==g||e[44]!==J||e[45]!==_?(ee=t.jsxs(yn,{open:g,onOpenChange:h,children:[J,_]}),e[43]=g,e[44]=J,e[45]=_,e[46]=ee):ee=e[46],ee};function cg(s){return{selectedCommandName:s.selectedCommandName,commands:s.commands,setSelectedCommand:s.setSelectedCommand,setCommandDraft:s.setCommandDraft,createCommand:s.createCommand,deleteCommand:s.deleteCommand,loadCommands:s.loadCommands}}function dg(s){return s.skills}function ug(s){return s.loadSkills}function mg(s){return s.name}function pg(s){return!Yn(s)}function gg(s,e){return s.name.localeCompare(e.name)}function hg(s,e){return s.name.localeCompare(e.name)}const fg=()=>{const{t:s}=st(),{selectedCommandName:e,getCommandByName:n,createCommand:a,updateCommand:r,commands:i,commandDraft:l,setCommandDraft:d}=pr(Es(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,f=!!(l&&l.name===e&&!c),[m,p]=o.useState(""),[u,j]=o.useState("user"),[g,h]=o.useState(""),[x,A]=o.useState(""),[S,C]=o.useState(""),[R,k]=o.useState(""),[y,v]=o.useState(!1),E=o.useRef(null);o.useEffect(()=>{if(f&&l){const M=l.name||"",I=l.scope||"user",P=l.description||"",z=l.agent||"",T=l.model||"",J=l.template||"";p(M),j(I),h(P),A(z),C(T),k(J),E.current={draftName:M,draftScope:I,description:P,agent:z,model:T,template:J}}else if(c){const M=c.description||"",I=c.agent||"",P=c.model||"",z=c.template||"";h(M),A(I),C(P),k(z),E.current={draftName:"",draftScope:"user",description:M,agent:I,model:P,template:z}}},[c,f,e,i,l]);const K=o.useMemo(()=>{const M=E.current;return M?!!(f&&(m!==M.draftName||u!==M.draftScope)||g!==M.description||x!==M.agent||S!==M.model||R!==M.template):!1},[x,g,m,u,f,S,R]),U=async()=>{const M=f?m.trim().replace(/\s+/g,"-"):e?.trim();if(!M){W.error(s("settings.commands.sidebar.toast.commandNameRequired"));return}if(!R.trim()){W.error(s("settings.commands.page.toast.templateRequired"));return}if(f&&i.some(I=>I.name===M)){W.error(s("settings.commands.sidebar.toast.commandExists"));return}v(!0);try{const I=x.trim(),P=S.trim(),z=R.trim(),T={name:M,description:g.trim()||void 0,agent:I===""?null:I,model:P===""?null:P,template:z,scope:f?u:void 0};let J;f?(J=await a(T),J&&d(null)):J=await r(M,T),J?W.success(s(f?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):W.error(s(f?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(I){console.error("Error saving command:",I),W.error(s("settings.commands.page.toast.saveUnexpectedError"))}finally{v(!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:f?s("settings.commands.page.title.new"):`/${e}`}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(f?"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:[f&&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=>p(M.target.value),placeholder:s("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Dt,{value:u,onValueChange:M=>j(M),children:[t.jsx(Et,{className:"w-fit min-w-[100px]",children:t.jsx(zt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Mt,{align:"end",children:[t.jsx(mt,{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(mt,{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:g,onChange:M=>h(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(rc,{agentName:x,onChange:M=>A(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(ja,{providerId:xn(S)?.providerId??"",modelId:xn(S)?.modelId??"",onChange:(M,I)=>{C(M&&I?`${M}/${I}`:"")}})})]})]})]}),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:R,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(G,{onClick:U,disabled:y||!K,size:"xs",className:"!font-normal",children:s(y?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(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")})]})})},Mo=s=>{switch(s){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},To=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=oe("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},xg=s=>{const e=Ze.c(120),{onItemSelect:n}=s,{t:a}=st(),{mcpServers:r,selectedMcpName:i,setSelectedMcp:l,setMcpDraft:d,loadMcpConfigs:c,deleteMcp:f}=ea(Es(yg)),m=Ns(bg);let p;e[0]!==m?(p=Ie=>Ie.getStatusForDirectory(m??null),e[0]=m,e[1]=p):p=e[1];const u=os(p),j=os(vg),g=os(jg),[h,x]=o.useState(null),[A,S]=o.useState(!1),[C,R]=o.useState(null),[k,y]=o.useState(null),[v,E]=o.useState(!1);let K;e[2]!==r?(K=r.filter(wg),e[2]=r,e[3]=K):K=e[3];const U=K;let M;e[4]!==r?(M=r.filter(Ng),e[4]=r,e[5]=M):M=e[5];const I=M;let P,z;e[6]!==c?(P=()=>{c()},z=[c],e[6]=c,e[7]=P,e[8]=z):(P=e[7],z=e[8]),o.useEffect(P,z);let T;e[9]!==m||e[10]!==g||e[11]!==v||e[12]!==j?(T=()=>{if(v)return;E(!0);const Ie=new Promise(kg);Promise.all([j({directory:m,silent:!0}),Ie]).then(()=>{const Ve=g(m);Ve&&W.error(Ve)}).finally(()=>{E(!1)})},e[9]=m,e[10]=g,e[11]=v,e[12]=j,e[13]=T):T=e[13];const J=T;let _;e[14]!==r||e[15]!==n||e[16]!==d||e[17]!==l?(_=()=>{let Ie="new-mcp-server",Ve=1;for(;r.some(b=>b.name===Ie);)Ie=`new-mcp-server-${Ve}`,Ve++;d({name:Ie,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),l(Ie),n?.()},e[14]=r,e[15]=n,e[16]=d,e[17]=l,e[18]=_):_=e[18];const ee=_;let Q;e[19]!==f||e[20]!==h||e[21]!==a?(Q=async()=>{if(!h)return;S(!0);const Ie=await f(h.name);Ie.ok?Ie.reloadFailed?W.warning(Ie.message||`MCP server "${h.name}" deleted, but OpenCode reload failed`,{description:Ie.warning||a("settings.mcp.sidebar.toast.refreshListIfStale")}):W.success(Ie.message||a("settings.mcp.sidebar.toast.serverDeleted",{name:h.name})):W.error(a("settings.mcp.sidebar.toast.deleteFailed")),x(null),S(!1)},e[19]=f,e[20]=h,e[21]=a,e[22]=Q):Q=e[22];const N=Q;let V;e[23]!==a?(V=(Ie,Ve)=>t.jsxs(Ve,{onClick:X=>{X.stopPropagation(),x(Ie)},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]=V):V=e[24];const B=V;let F;e[25]===Symbol.for("react.memo_cache_sentinel")?(F=oe("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 $;e[30]!==a?($=a("settings.mcp.sidebar.actions.refreshStatusAria"),e[30]=a,e[31]=$):$=e[31];let ie;e[32]!==a?(ie=a("settings.mcp.sidebar.actions.refreshStatusTitle"),e[32]=a,e[33]=ie):ie=e[33];const le=v&&"animate-spin";let ne;e[34]!==le?(ne=oe("h-4 w-4",le),e[34]=le,e[35]=ne):ne=e[35];let ye;e[36]!==ne?(ye=t.jsx(D,{name:"refresh",className:ne}),e[36]=ne,e[37]=ye):ye=e[37];let ae;e[38]!==J||e[39]!==v||e[40]!==$||e[41]!==ie||e[42]!==ye?(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:v,onClick:J,"aria-label":$,title:ie,children:ye}),e[38]=J,e[39]=v,e[40]=$,e[41]=ie,e[42]=ye,e[43]=ae):ae=e[43];let ge;e[44]!==q||e[45]!==ae?(ge=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[q,ae]}),e[44]=q,e[45]=ae,e[46]=ge):ge=e[46];let Ne;e[47]===Symbol.for("react.memo_cache_sentinel")?(Ne=t.jsx(ka,{className:"mb-3"}),e[47]=Ne):Ne=e[47];let he;e[48]!==r.length||e[49]!==a?(he=a("settings.mcp.sidebar.total",{count:r.length}),e[48]=r.length,e[49]=a,e[50]=he):he=e[50];let we;e[51]!==he?(we=t.jsx("span",{className:"typography-meta text-muted-foreground",children:he}),e[51]=he,e[52]=we):we=e[52];let ce;e[53]!==a?(ce=a("settings.mcp.sidebar.actions.addServerTitle"),e[53]=a,e[54]=ce):ce=e[54];let Z;e[55]===Symbol.for("react.memo_cache_sentinel")?(Z=t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[55]=Z):Z=e[55];let se;e[56]!==ee||e[57]!==ce?(se=t.jsx(G,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:ee,title:ce,children:Z}),e[56]=ee,e[57]=ce,e[58]=se):se=e[58];let ve;e[59]!==we||e[60]!==se?(ve=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[we,se]}),e[59]=we,e[60]=se,e[61]=ve):ve=e[61];let H;e[62]!==ge||e[63]!==ve?(H=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ge,Ne,ve]}),e[62]=ge,e[63]=ve,e[64]=H):H=e[64];let te;e[65]!==r.length||e[66]!==u||e[67]!==n||e[68]!==C||e[69]!==U||e[70]!==B||e[71]!==k||e[72]!==i||e[73]!==d||e[74]!==l||e[75]!==a||e[76]!==I?(te=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(Ie=>{const Ve=u[Ie.name],X=Mo(Ve?.status),b=i===Ie.name,be=va();return t.jsxs(yn,{open:k===Ie.name,onOpenChange:Ee=>y(Ee?Ie.name:null),children:[t.jsxs(bn,{render:t.jsx("div",{className:oe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",b?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:be?void 0:Ee=>{Ee.preventDefault(),y(Ie.name)}}),children:[t.jsxs("button",{onClick:()=>{l(Ie.name),d(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(To,{tone:X,enabled:Ie.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ie.name}),t.jsx("span",{title:Ie.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Ie.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:Ie.type==="local"?Ie.command?.join(" ")??"":Ie.url??""})]}),t.jsxs(gs,{open:C===Ie.name,onOpenChange:Ee=>{Ee&&y(null),R(Ee?Ie.name:null)},children:[t.jsx(ms,{asChild:!0,children:t.jsx(G,{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(Ie,Ss)})]})]}),t.jsx(vn,{className:"w-fit min-w-20",children:B(Ie,ln)})]},Ie.name)})]}),I.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")}),I.map(Ie=>{const Ve=u[Ie.name],X=Mo(Ve?.status),b=i===Ie.name,be=va();return t.jsxs(yn,{open:k===Ie.name,onOpenChange:Ee=>y(Ee?Ie.name:null),children:[t.jsxs(bn,{render:t.jsx("div",{className:oe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",b?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:be?void 0:Ee=>{Ee.preventDefault(),y(Ie.name)}}),children:[t.jsxs("button",{onClick:()=>{l(Ie.name),d(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(To,{tone:X,enabled:Ie.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ie.name}),t.jsx("span",{title:Ie.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Ie.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:Ie.type==="local"?Ie.command?.join(" ")??"":Ie.url??""})]}),t.jsxs(gs,{open:C===Ie.name,onOpenChange:Ee=>{Ee&&y(null),R(Ee?Ie.name:null)},children:[t.jsx(ms,{asChild:!0,children:t.jsx(G,{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(Ie,Ss)})]})]}),t.jsx(vn,{className:"w-fit min-w-20",children:B(Ie,ln)})]},Ie.name)})]})]})}),e[65]=r.length,e[66]=u,e[67]=n,e[68]=C,e[69]=U,e[70]=B,e[71]=k,e[72]=i,e[73]=d,e[74]=l,e[75]=a,e[76]=I,e[77]=te):te=e[77];const re=h!==null;let pe;e[78]!==A?(pe=Ie=>{!Ie&&!A&&x(null)},e[78]=A,e[79]=pe):pe=e[79];let Me;e[80]!==a?(Me=a("settings.mcp.sidebar.deleteDialog.title"),e[80]=a,e[81]=Me):Me=e[81];let Se;e[82]!==Me?(Se=t.jsx(Ut,{children:Me}),e[82]=Me,e[83]=Se):Se=e[83];const Ae=h?.name||"";let De;e[84]!==a||e[85]!==Ae?(De=a("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Ae}),e[84]=a,e[85]=Ae,e[86]=De):De=e[86];let Pe;e[87]===Symbol.for("react.memo_cache_sentinel")?(Pe=t.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[87]=Pe):Pe=e[87];let Oe;e[88]!==De?(Oe=t.jsxs(_t,{children:[De," ",Pe,"."]}),e[88]=De,e[89]=Oe):Oe=e[89];let Te;e[90]!==Se||e[91]!==Oe?(Te=t.jsxs(Kt,{children:[Se,Oe]}),e[90]=Se,e[91]=Oe,e[92]=Te):Te=e[92];let Ue;e[93]===Symbol.for("react.memo_cache_sentinel")?(Ue=()=>x(null),e[93]=Ue):Ue=e[93];let Be;e[94]!==a?(Be=a("settings.common.actions.cancel"),e[94]=a,e[95]=Be):Be=e[95];let Ke;e[96]!==A||e[97]!==Be?(Ke=t.jsx(G,{size:"sm",variant:"ghost",onClick:Ue,disabled:A,children:Be}),e[96]=A,e[97]=Be,e[98]=Ke):Ke=e[98];let Je;e[99]!==A||e[100]!==a?(Je=a(A?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[99]=A,e[100]=a,e[101]=Je):Je=e[101];let ue;e[102]!==N||e[103]!==A||e[104]!==Je?(ue=t.jsx(G,{size:"sm",onClick:N,disabled:A,children:Je}),e[102]=N,e[103]=A,e[104]=Je,e[105]=ue):ue=e[105];let Y;e[106]!==Ke||e[107]!==ue?(Y=t.jsxs(Jt,{children:[Ke,ue]}),e[106]=Ke,e[107]=ue,e[108]=Y):Y=e[108];let de;e[109]!==Te||e[110]!==Y?(de=t.jsxs(Ft,{className:"max-w-md",children:[Te,Y]}),e[109]=Te,e[110]=Y,e[111]=de):de=e[111];let je;e[112]!==re||e[113]!==pe||e[114]!==de?(je=t.jsx(Lt,{open:re,onOpenChange:pe,children:de}),e[112]=re,e[113]=pe,e[114]=de,e[115]=je):je=e[115];let Re;return e[116]!==H||e[117]!==te||e[118]!==je?(Re=t.jsxs("div",{className:F,children:[H,te,je]}),e[116]=H,e[117]=te,e[118]=je,e[119]=Re):Re=e[119],Re};function yg(s){return{mcpServers:s.mcpServers,selectedMcpName:s.selectedMcpName,setSelectedMcp:s.setSelectedMcp,setMcpDraft:s.setMcpDraft,loadMcpConfigs:s.loadMcpConfigs,deleteMcp:s.deleteMcp}}function bg(s){return s.currentDirectory}function vg(s){return s.refresh}function jg(s){return s.getErrorForDirectory}function wg(s){return s.scope==="project"}function Ng(s){return s.scope!=="project"}function kg(s){return setTimeout(s,500)}function Ws(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function ua(s){return Array.isArray(s)&&s.every(e=>typeof e=="string")}function _s(s,e){return e!==void 0?{ok:!1,error:s,parsed:e}:{ok:!1,error:s}}function za(s,e,n){const a=Sg(n),r=typeof n.url=="string"?n.url.trim():"",i=Ro(n,"env","environment"),l=Ro(n,"headers"),d=Cg(n),c=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",f=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",m=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",u=Ig(n),j=Pg(n);return{ok:!0,name:s,type:e,command:a,url:r,environment:i,headers:l,oauthEnabled:d,oauthClientId:c,oauthClientSecret:f,oauthScope:m,oauthRedirectUri:p,timeout:u,enabled:j}}function Sg(s){const e=s.command,n=s.args;if(ua(e)&&ua(n))return[...e,...n];if(ua(e))return e;if(typeof e=="string"&&e.trim()){const a=e.trim().split(/\s+/);return ua(n)?[...a,...n]:a}return ua(n)?n:[]}function Ro(s,...e){for(const n of e){const a=s[n];if(!Ws(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 Cg(s){if(s.oauth===!1||s.oauth===null||s.oauth===void 0||!Ws(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 Ig(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 Pg(s){return"disabled"in s&&s.disabled===!0?!1:"enabled"in s?!!s.enabled:!0}function Ag(s){const e=s.mcpServers;if(Ws(e)){const a=Object.keys(e);if(a.length===1){const r=a[0],i=e[r];if(Ws(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"&&Ws(r)});if(n.length===1){const a=n[0],r=s[a];if(Nc(r))return{name:a,entry:r}}return null}function Nc(s){return s.type==="local"||s.type==="remote"||Array.isArray(s.command)||typeof s.url=="string"||Array.isArray(s.args)}function Dg(s,e){let n;try{const d=s.trim();if(!d)return _s("No JSON content provided");n=JSON.parse(d)}catch(d){return _s(d instanceof Error?`Invalid JSON: ${d.message}`:"Invalid JSON")}if(!Ws(n))return _s("Expected a JSON object, not an array or primitive");const a=n,r=a.mcpServers;if(Ws(r)){const d=Object.keys(r);if(d.length===0)return _s("mcpServers object is empty",n);if(d.length>1)return _s("Paste one server at a time. Found "+d.length+" servers in mcpServers",n);const c=d[0],f=r[c];return Ws(f)?za(c,Ua(f),f):_s("Server entry is not a valid object",n)}const i=a.mcp;if(Ws(i)){const d=Object.keys(i);if(d.length===0)return _s("mcp object is empty",n);if(d.length>1)return _s("Paste one server at a time. Found "+d.length+" servers in mcp",n);const c=d[0],f=i[c];return Ws(f)?za(c,Ua(f),f):_s("Server entry in mcp is not a valid object",n)}const l=Ag(a);if(l)return za(l.name,Ua(l.entry),l.entry);if(Nc(a)){const d=Ua(a),c=typeof a.name=="string"&&a.name.trim()?a.name.trim():e?.fallbackName;return za(c,d,a)}return _s("No recognizable MCP server configuration found in JSON",n)}function Ua(s){return s.type==="remote"?"remote":s.type==="local"?"local":typeof s.url=="string"&&s.url.trim()?"remote":(Array.isArray(s.command)||typeof s.command=="string"||Array.isArray(s.args),"local")}function Eg(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 Mg="/mcp/oauth/callback",Tg=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}},Rg=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}},kc=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=Tg(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}},Mn=bd,Tn=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&&fe.isValidElement(a)?{render:a}:{children:a},e[5]=n,e[6]=a,e[7]=l):l=e[7];const d=l;let c;e[8]!==r?(c=oe("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 f;return e[10]!==i||e[11]!==d||e[12]!==c?(f=t.jsx(yd,{className:c,...i,...d}),e[10]=i,e[11]=d,e[12]=c,e[13]=f):f=e[13],f},Rn=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=oe("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(vd,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i};function Fg(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 Og(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:Rg(n.searchParams),stateKey:kc(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const zg=({value:s,onChange:e,pasteCommandTitle:n,pasteCommandLabel:a,pasteSuccess:r,clipboardReadFailed:i,preview:l})=>{const[d,c]=o.useState(()=>s.join(`
4
+ `)),f=o.useRef(s);o.useEffect(()=>{JSON.stringify(f.current)!==JSON.stringify(s)&&(f.current=s,c(s.join(`
5
+ `)))},[s]);const m=u=>{const j=u.split(`
6
+ `).filter(g=>g.trim().length>0);e(j)},p=async()=>{try{const j=(await navigator.clipboard.readText()).trim(),g=j.includes(`
7
+ `)?j.split(`
8
+ `).filter(h=>h.trim()):Fg(j);c(g.join(`
9
+ `)),e(g),W.success(r(g.length))}catch{W.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(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:p,type:"button",title:n,children:[t.jsx(D,{name:"clipboard",className:"h-3 w-3"}),a]})}),t.jsx(hs,{value:d,onChange:u=>{c(u.target.value),m(u.target.value)},onBlur:()=>{const u=d.split(`
10
+ `).map(j=>j.trimEnd()).join(`
11
+ `);c(u),m(u)},placeholder:`npx
12
+ -y
13
+ @modelcontextprotocol/server-postgres
14
+ postgresql://user:pass@host/db`,rows:Math.max(4,s.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),s.length>0&&t.jsxs("details",{className:"group",children:[t.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children: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((u,j)=>t.jsxs("span",{className:"block",children:[t.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",j,"]"]}),u]},j))})})]})]})},Ug=s=>s.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Lo=({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:d,importSuccess:c,clipboardReadFailed:f,keyLabel:m,valueLabel:p,valuePlaceholder:u,hideValueTitle:j,showValueTitle:g,addVariable:h,plainTextWarning:x,removeVariableAria:A})=>{const[S,C]=o.useState(new Set),R=()=>e([...s,{key:"",value:""}]),k=U=>{e(s.filter((M,I)=>I!==U)),C(M=>{const I=new Set(M);return I.delete(U),I})},y=(U,M,I)=>{const P=[...s];P[U]={...P[U],[M]:I},e(P)},v=U=>{C(M=>{const I=new Set(M);return I.has(U)?I.delete(U):I.add(U),I})},E=async()=>{try{const U=await navigator.clipboard.readText(),M=[];for(const P of U.split(`
15
+ `)){const z=P.trim();if(!z||z.startsWith("#"))continue;const T=z.indexOf("=");if(T===-1)continue;const J=z.slice(0,T).trim();let _=z.slice(T+1).trim();(_.startsWith('"')&&_.endsWith('"')||_.startsWith("'")&&_.endsWith("'"))&&(_=_.slice(1,-1)),J&&M.push({key:J,value:_})}if(M.length===0){W.error(d);return}const I=[...s];for(const P of M){const z=I.findIndex(T=>T.key===P.key);z!==-1?I[z]=P:I.push(P)}e(I),W.success(c(M.length))}catch{W.error(f)}},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:p})]}),t.jsxs(G,{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:I=>y(M,"key",n(I.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:S.has(M)?"text":"password",value:U.value,onChange:I=>y(M,"value",I.target.value),placeholder:u,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),t.jsx("button",{type:"button",onClick:()=>v(M),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:S.has(M)?j:g,children:S.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(G,{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":A,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},M))}),t.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:R,type:"button",children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),h]}),K&&t.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},Fo=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 d,c;if(e[0]!==r||e[1]!==n||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const u={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[n]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const j=oe("typography-micro font-medium rounded-full px-2 py-0.5",u.text,u.bg);let g;e[5]!==r||e[6]!==n?(g=r(n),e[5]=r,e[6]=n,e[7]=g):g=e[7],c=t.jsxs("span",{className:j,children:["● ",g]});break e}d=oe("typography-micro font-medium",u.text)}e[0]=r,e[1]=n,e[2]=l,e[3]=d,e[4]=c}else d=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let f;e[8]!==r||e[9]!==n?(f=r(n),e[8]=r,e[9]=n,e[10]=f):f=e[10];let m;return e[11]!==d||e[12]!==f?(m=t.jsxs("span",{className:d,children:["● ",f]}),e[11]=d,e[12]=f,e[13]=m):m=e[13],m},Kg=(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")}},Bg=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)]"}},$g=(s,e,n,a)=>!!(s==="failed"||s==="needs_auth"||s==="needs_client_registration"||e||n||a),Oo=(s,e)=>{if(typeof window>"u")return null;const n=new URL(Mg,na()||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()},Vg=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")}},_g=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},ma=async s=>{typeof s!="string"||!s.trim()||await dt(`/api/mcp/auth/pending?state=${encodeURIComponent(s.trim())}`,{method:"DELETE"}).catch(()=>{})},Rr=(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},Hg=(s,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${s??"__none__"}::${n}`},Wg=()=>{const{t:s}=st(),e=o.useCallback((Ce,vt)=>s(Ce,vt),[s]),{selectedMcpName:n,mcpServers:a,mcpDraft:r,setMcpDraft:i,setSelectedMcp:l,getMcpByName:d,createMcp:c,updateMcp:f,deleteMcp:m}=ea(Es(Ce=>({selectedMcpName:Ce.selectedMcpName,mcpServers:Ce.mcpServers,mcpDraft:Ce.mcpDraft,setMcpDraft:Ce.setMcpDraft,setSelectedMcp:Ce.setSelectedMcp,getMcpByName:Ce.getMcpByName,createMcp:Ce.createMcp,updateMcp:Ce.updateMcp,deleteMcp:Ce.deleteMcp}))),p=Ns(Ce=>Ce.currentDirectory),u=o.useMemo(()=>fs(),[]),j=os(Ce=>Ce.getStatusForDirectory(p??null)),g=os(Ce=>Ce.getDiagnosticForDirectory(p??null)),h=os(Ce=>Ce.refresh),x=os(Ce=>Ce.connect),A=os(Ce=>Ce.disconnect),S=os(Ce=>Ce.startAuth),C=os(Ce=>Ce.completeAuth),R=os(Ce=>Ce.clearAuth),k=os(Ce=>Ce.testConnection),y=n?d(n):null,v=!!(r&&r.name===n&&!y),[E,K]=o.useState(""),[U,M]=o.useState("user"),[I,P]=o.useState("local"),[z,T]=o.useState([]),[J,_]=o.useState(""),[ee,Q]=o.useState([]),[N,V]=o.useState([]),[B,F]=o.useState(!0),[O,q]=o.useState(""),[$,ie]=o.useState(""),[le,ne]=o.useState(""),[ye,ae]=o.useState(""),[ge,Ne]=o.useState(""),[he,we]=o.useState(!0),[ce,Z]=o.useState(!1),[se,ve]=o.useState(!1),[H,te]=o.useState(!1),[re,pe]=o.useState(!1),[Me,Se]=o.useState(!1),[Ae,De]=o.useState(!1),[Pe,Oe]=o.useState(!1),[Te,Ue]=o.useState(!1),[Be,Ke]=o.useState(null),[Je,ue]=o.useState(null),[Y,de]=o.useState(""),[je,Re]=o.useState(!1),Ie=o.useRef(0),Ve=o.useRef(!1),[X,b]=o.useState(!1),[be,Ee]=o.useState(!1),[ze,qe]=o.useState(""),[rt,lt]=o.useState(null),at=o.useMemo(()=>Hg(n,p),[p,n]),ct=o.useRef(at),Ye=o.useRef(null),_e=o.useCallback(()=>{Ke(null),ue(null),de(""),Re(!1),Ie.current=0,Ue(!1),Se(!1),De(!1),Ve.current=!1},[]),ft=o.useCallback(()=>{qe(""),lt(null),Ee(!0)},[]),xe=o.useCallback(async()=>{try{const Ce=await navigator.clipboard.readText();qe(Ce),lt(null)}catch{W.error(s("settings.mcp.page.toast.clipboardReadFailed"))}},[s]),et=o.useCallback(()=>{const Ce=Dg(ze,{fallbackName:E});if(!Ce.ok){lt(Ce.error);return}const jt=Eg(Ce,{name:E,scope:U,type:I,command:z,url:J,environment:ee,headers:N,oauthEnabled:B,oauthClientId:O,oauthClientSecret:$,oauthScope:le,oauthRedirectUri:ye,timeout:ge,enabled:he},{isNewServer:v});K(jt.name),P(jt.type),T(jt.command??[]),_(jt.url??""),Q(jt.environment??[]),V(jt.headers??[]),F(jt.oauthEnabled??!1),q(jt.oauthClientId??""),ie(jt.oauthClientSecret??""),ne(jt.oauthScope??""),ae(jt.oauthRedirectUri??""),Ne(jt.timeout??""),we(jt.enabled??!0),Ee(!1),qe(""),lt(null),W.success(s("settings.mcp.page.toast.configImported"))},[ze,E,U,I,z,J,ee,N,B,O,$,le,ye,ge,he,v,s]);o.useEffect(()=>{if(v&&r){K(r.name),M(r.scope||"user"),P(r.type),T(r.command),_(r.url),Q(r.environment),V(r.headers),F(r.oauthEnabled),q(r.oauthClientId),ie(r.oauthClientSecret),ne(r.oauthScope),ae(r.oauthRedirectUri),Ne(r.timeout),we(r.enabled),b(!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(y){M(y.scope==="project"?"project":"user");const Ce=po(y.environment),vt=y.type==="remote"?y:null,jt=po(vt?.headers),qt=vt?.oauth,es=qt&&typeof qt=="object"?qt:null,Bt=qt!==!1,ys=y.type,ws=ys==="local"?y.command??[]:[],Qt=ys==="remote"?y.url??"":"",Fs=typeof vt?.timeout=="number"&&Number.isFinite(vt.timeout)?String(vt.timeout):"";P(ys),T(ws),_(Qt),Q(Ce),V(jt),F(Bt),q(Bt?es?.clientId??"":""),ie(Bt?es?.clientSecret??"":""),ne(Bt?es?.scope??"":""),ae(Bt?es?.redirectUri??"":""),Ne(Fs),we(y.enabled),b(!1),Ye.current={mcpType:ys,command:ws,url:Qt,envEntries:Ce,headerEntries:jt,oauthEnabled:Bt,oauthClientId:Bt?es?.clientId??"":"",oauthClientSecret:Bt?es?.clientSecret??"":"",oauthScope:Bt?es?.scope??"":"",oauthRedirectUri:Bt?es?.redirectUri??"":"",timeout:Fs,enabled:y.enabled}}},[y,v,r]);const nt=o.useMemo(()=>{const Ce=Ye.current;return Ce?I!==Ce.mcpType||he!==Ce.enabled||JSON.stringify(z)!==JSON.stringify(Ce.command)||J!==Ce.url||JSON.stringify(ee)!==JSON.stringify(Ce.envEntries)||JSON.stringify(N)!==JSON.stringify(Ce.headerEntries)||B!==Ce.oauthEnabled||O!==Ce.oauthClientId||$!==Ce.oauthClientSecret||le!==Ce.oauthScope||ye!==Ce.oauthRedirectUri||ge!==Ce.timeout:!1},[I,z,J,ee,N,B,O,$,le,ye,ge,he]),He=async()=>{const Ce=v?E.trim():n??"";if(!Ce){W.error(s("settings.mcp.page.toast.nameRequired"));return}if(v&&a.some(jt=>jt.name===Ce)){W.error(s("settings.mcp.page.toast.serverNameExists"));return}if(I==="local"&&z.filter(Boolean).length===0){W.error(s("settings.mcp.page.toast.localCommandRequired"));return}if(I==="remote"&&!J.trim()){W.error(s("settings.mcp.page.toast.remoteUrlRequired"));return}const vt={name:Ce,scope:U,type:I,command:z,url:J,environment:ee,headers:N,oauthEnabled:B,oauthClientId:O,oauthClientSecret:$,oauthScope:le,oauthRedirectUri:ye,timeout:ge,enabled:he};Z(!0);try{const jt=v?await c(vt):await f(Ce,vt);jt.ok?(await ma(Je),_e(),v&&(i(null),l(Ce)),await h({directory:p,silent:!0}),jt.reloadFailed?W.warning(jt.message||s(v?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:jt.warning||s("settings.mcp.page.toast.retryRefreshHint")}):W.success(jt.message||s(v?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):W.error(s("settings.mcp.page.toast.saveFailed"))}catch(jt){W.error(jt instanceof Error?jt.message:s("settings.mcp.page.toast.unexpectedError"))}finally{Z(!1)}},yt=async()=>{if(!n)return;te(!0);const Ce=await m(n);Ce.ok?(await ma(Je),_e(),Ce.reloadFailed?W.warning(Ce.message||s("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Ce.warning||s("settings.mcp.page.toast.refreshListIfStale")}):W.success(Ce.message||s("settings.mcp.page.toast.serverDeleted",{name:n})),ve(!1)):W.error(s("settings.mcp.page.toast.deleteFailed")),te(!1)},Nt=async()=>{if(n){pe(!0);try{if(j[n]?.status==="connected")await A(n,p),W.success(s("settings.mcp.page.toast.disconnected"));else{await x(n,p),await h({directory:p,silent:!0});const vt=os.getState().getStatusForDirectory(p??null)[n];vt?.status==="connected"?W.success(s("settings.mcp.page.toast.connected")):vt?.status==="needs_auth"?W.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):vt?.status==="needs_client_registration"?W.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):vt?.status==="failed"?W.error(vt.error||s("settings.mcp.page.toast.connectionFailed")):W.message(s("settings.mcp.page.toast.connectionAttemptFinished"));return}await h({directory:p,silent:!0})}catch(Ce){W.error(Ce instanceof Error?Ce.message:s("settings.mcp.page.toast.connectionFailed"))}finally{pe(!1)}}},Tt=o.useCallback(()=>v?(W.error(s("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):nt?(W.error(s("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[nt,v,s]),me=o.useCallback(async(Ce=!1)=>{try{await h({directory:p,silent:Ce})}catch(vt){Ce||W.error(vt instanceof Error?vt.message:s("settings.mcp.page.toast.refreshStatusFailed"))}},[p,h,s]);o.useEffect(()=>{me(!0)},[me]),o.useEffect(()=>{ct.current=at,pe(!1),Oe(!1),_e()},[_e,at]);const $e=o.useCallback(async()=>{if(!n||I!=="remote"||!Tt())return;Se(!0);const Ce=at;let vt=null;try{const jt=os.getState().getStatusForDirectory(p??null)[n]?.status;Ve.current=jt==="needs_auth"||jt==="needs_client_registration";const qt=Oo(n,p);if(!qt)throw new Error(s("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!ye.trim()&&!u){const ws=await f(n,{oauthEnabled:B,oauthClientId:O,oauthClientSecret:$,oauthScope:le,oauthRedirectUri:qt});if(!ws.ok)throw new Error(s("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(ws.reloadFailed)throw new Error(ws.warning||ws.message||s("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(ct.current!==Ce)return;ae(qt),Ye.current=Ye.current?{...Ye.current,oauthRedirectUri:qt}:Ye.current}const es=await S(n,p),Bt=kc(new URL(es).searchParams);if(Bt&&(vt=Bt,await Vg({state:Bt,name:n,directory:p})),ct.current!==Ce)return;Ke(es),ue(Bt??null),Re(!0),Ie.current=0;const ys=await on(es);if(ct.current!==Ce)return;ys?W.message(s(u?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):W.error(s("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(jt){await ma(vt),ct.current===Ce&&W.error(Rr(jt,s("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{ct.current===Ce&&Se(!1)}},[p,u,I,O,$,B,ye,le,Tt,at,n,S,s,e,f]),Qe=o.useCallback(async()=>{if(!n||!Tt())return;De(!0);const Ce=at;try{if(await R(n,p),ct.current!==Ce)return;Ke(null),ue(null),de(""),Re(!1),Ie.current=0,await ma(Je),W.success(s("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(vt){ct.current===Ce&&W.error(Rr(vt,s("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{ct.current===Ce&&De(!1)}},[Je,R,p,Tt,at,n,s,e]),We=o.useCallback(async()=>{if(!Be)return;if((await En(Be)).ok){W.success(s("settings.mcp.page.toast.authorizationUrlCopied"));return}W.error(s("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Be,s]),xt=o.useCallback(async()=>{const Ce=Og(Y);if(!Ce.code){W.error(s("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const vt=Ce.stateKey?await _g(Ce.stateKey):null,jt=Ce.context??vt,qt=jt?.name??n,es=jt?.directory??p;if(!qt){W.error(s("settings.mcp.page.toast.missingServerDetails"));return}if(!jt&&!Tt())return;Ue(!0);const Bt=at;try{if(await C(qt,Ce.code,es),await ma(Ce.stateKey??Je),ct.current!==Bt)return;de(""),Ke(null),ue(null),Re(!1),Ie.current=0,W.success(qt===n?s("settings.mcp.page.toast.authorizationCompleted"):s("settings.mcp.page.toast.authorizationCompletedFor",{name:qt}))}catch(ys){ct.current===Bt&&W.error(Rr(ys,s("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{ct.current===Bt&&Ue(!1)}},[Y,Je,C,p,Tt,at,n,s,e]),St=o.useCallback(async()=>{if(!(!n||!Tt())){if(!he){W.error(s("settings.mcp.page.toast.enableServerBeforeTest"));return}Oe(!0);try{const Ce=await k(n,p),vt=Ce.status?.status;Ce.warning?W.warning(Ce.warning):vt==="connected"?W.success(s("settings.mcp.page.toast.connectionTestSucceeded")):vt==="needs_auth"?W.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):vt==="needs_client_registration"?W.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):vt==="failed"?W.error(Ce.status?.error||Ce.error||s("settings.mcp.page.toast.connectionTestFailed")):Ce.error?W.error(Ce.error):W.message(s("settings.mcp.page.toast.connectionTestFinished"))}catch(Ce){W.error(Ce instanceof Error?Ce.message:s("settings.mcp.page.toast.connectionTestFailed"))}finally{Oe(!1)}}},[p,he,Tt,n,s,k]);if(o.useEffect(()=>{if(!je||!n)return;const Ce=window.setInterval(()=>{(async()=>{Ie.current+=1,await h({directory:p,silent:!0});const vt=os.getState().getStatusForDirectory(p??null)[n];if(vt){if(Ve.current&&vt.status!=="needs_auth"&&vt.status!=="needs_client_registration"){Re(!1),Ie.current=0,Ve.current=!1,Ke(null),de(""),vt.status==="connected"&&W.success(s("settings.mcp.page.toast.authorizationCompleted"));return}if(!Ve.current&&vt.status==="failed"){Re(!1),Ie.current=0,Ve.current=!1,W.error(vt.error||s("settings.mcp.page.toast.authorizationFailed"));return}Ie.current>=30&&(Re(!1),Ie.current=0,Ve.current=!1,W.message(s("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Ce)}},[p,je,h,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=j[n],Rt=n?g[n]:void 0,Gt=ht??Rt,cs=ht?.status==="connected",ds=ht?.status==="needs_auth"||ht?.status==="needs_client_registration",xs=u?null:Oo(n,p),Zt=Kg(Gt?.status,e,Gt&&"error"in Gt?Gt.error:void 0),Cs=Ce=>{switch(Ce){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 Ce}};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:[v?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(Fo,{status:Gt?.status,enabled:he,getStatusLabel:Cs,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:v?s("settings.mcp.page.header.configureNewServer"):s("settings.mcp.page.header.transport",{type:s(I==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!v&&t.jsxs(t.Fragment,{children:[t.jsx(G,{variant:cs?"outline":"default",size:"xs",className:"!font-normal",onClick:Nt,disabled:re||!he,children:s(re?"settings.mcp.page.actions.working":cs?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),I==="remote"&&t.jsxs(t.Fragment,{children:[t.jsx(G,{variant:ds?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{$e()},disabled:Me||!he,children:s(Me?"settings.mcp.page.actions.starting":ds?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),t.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{Qe()},disabled:Ae||!he,children:s(Ae?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),cs&&t.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{St()},disabled:Pe||!he,children:s(Pe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!v&&$g(Gt?.status,Be,ds,je)&&t.jsx("div",{className:"mb-6 px-2",children:t.jsxs("div",{className:oe("rounded-lg border p-3",Bg(Gt?.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(Fo,{status:Gt?.status,enabled:he,getStatusLabel:Cs})]}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:Zt}),t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:U==="project"?s("settings.mcp.page.status.projectScopedTo",{directory:p??s("settings.mcp.page.status.activeProject")}):s("settings.mcp.page.status.userScoped")})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!cs&&t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{St()},disabled:Pe||!he,children:s(Pe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Be&&t.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.authorizationUrl")}),t.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:Be}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{on(Be)},children:[t.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.mcp.page.actions.openInBrowser")]}),t.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{We()},children:[t.jsx(D,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.actions.copyLink")]})]})]})}),I==="remote"&&(ds||je||Be)&&t.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.auth.manualFallbackTitle")}),t.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.manualFallbackDescription")})]}),t.jsx(hs,{value:Y,onChange:Ce=>de(Ce.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(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{xt()},disabled:Te,children:s(Te?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),je&&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:[v&&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:Ce=>K(Ce.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(Dt,{value:U,onValueChange:Ce=>M(Ce),children:[t.jsx(Et,{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(Mt,{align:"end",children:[t.jsx(mt,{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(mt,{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")})]})})]})]})]})]}),v&&t.jsx("div",{className:"py-1.5",children:t.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:ft,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":he,onClick:()=>we(!he),onKeyDown:Ce=>{(Ce.key===" "||Ce.key==="Enter")&&(Ce.preventDefault(),we(!he))},children:[t.jsx(bt,{checked:he,onChange:we,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(G,{variant:"chip",size:"xs","aria-pressed":I==="local",onClick:()=>P("local"),className:"!font-normal",children:s("settings.mcp.page.transport.local")}),t.jsx(G,{variant:"chip",size:"xs","aria-pressed":I==="remote",onClick:()=>P("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(I==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:I==="local"?t.jsx(zg,{value:z,onChange:T,pasteCommandTitle:s("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:s("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Ce=>s("settings.mcp.page.toast.pastedArgumentsCount",{count:Ce}),clipboardReadFailed:s("settings.mcp.page.toast.clipboardReadFailed"),preview:Ce=>s("settings.mcp.page.connection.previewArgs",{count:Ce})}):t.jsx(Xe,{value:J,onChange:Ce=>_(Ce.target.value),placeholder:s("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),I==="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(Mn,{open:X,onOpenChange:b,children:[t.jsxs(Tn,{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"),ge?` · ${ge}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(Rn,{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:ge,onChange:Ce=>Ne(Ce.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(Lo,{value:N,onChange:V,keyTransform:Ce=>Ce.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:Ce=>s("settings.mcp.page.toast.importedVariablesCount",{count:Ce}),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:Ce=>{(Ce.key===" "||Ce.key==="Enter")&&(Ce.preventDefault(),F(!B))},children:[t.jsx(bt,{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:Ce=>q(Ce.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:$,onChange:Ce=>ie(Ce.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:le,onChange:Ce=>ne(Ce.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:ye,onChange:Ce=>ae(Ce.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")}),xs&&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:xs})]})]})]})})]})})]}),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"),ee.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ee.length,")"]})]})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:ee.length===0?t.jsxs(G,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Q([{key:"",value:""}]),children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),s("settings.mcp.page.env.addEnvironmentVariable")]}):t.jsx(Lo,{value:ee,onChange:Q,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:Ce=>s("settings.mcp.page.toast.importedVariablesCount",{count:Ce}),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(G,{onClick:He,disabled:ce||!nt&&!v,size:"xs",className:"!font-normal",children:s(ce?"settings.common.actions.saving":v?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!v&&t.jsx(G,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ve(!0),children:s("settings.common.actions.delete")})]})]}),t.jsx(Lt,{open:be,onOpenChange:Ce=>{Ce||(Ee(!1),qe(""),lt(null))},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("settings.mcp.page.importDialog.title")}),t.jsx(_t,{children:s("settings.mcp.page.importDialog.description")})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx(hs,{value:ze,onChange:Ce=>{qe(Ce.target.value),lt(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(G,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:xe,type:"button",children:[t.jsx(D,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),t.jsxs(Jt,{children:[t.jsx(G,{variant:"outline",onClick:()=>{Ee(!1),qe(""),lt(null)},className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(G,{onClick:et,disabled:!ze.trim(),size:"sm",children:s("settings.common.actions.import")})]})]})}),t.jsx(Lt,{open:se,onOpenChange:Ce=>{!Ce&&!H&&ve(!1)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("settings.mcp.page.deleteDialog.title",{name:n??""})}),t.jsxs(_t,{children:[s("settings.mcp.page.deleteDialog.descriptionPrefix")," ",t.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",s("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),t.jsxs(Jt,{children:[t.jsx(G,{variant:"outline",onClick:()=>ve(!1),disabled:H,className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(G,{variant:"destructive",size:"sm",onClick:yt,disabled:H,children:s(H?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},qg=({transform:s})=>({...s,y:0}),Gg=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:d,setNodeRef:c,transform:f,transition:m,isDragging:p}=kd(i);let u;e[2]!==f?(u=Sd.Transform.toString(f),e[2]=f,e[3]=u):u=e[3];let j;e[4]!==u||e[5]!==m?(j={transform:u,transition:m},e[4]=u,e[5]=m,e[6]=j):j=e[6];const g=p&&"opacity-50";let h;e[7]!==r||e[8]!==g?(h=oe("h-full rounded-md",r,g),e[7]=r,e[8]=g,e[9]=h):h=e[9];let x;return e[10]!==l||e[11]!==a||e[12]!==n||e[13]!==d||e[14]!==c||e[15]!==j||e[16]!==h?(x=t.jsx("div",{ref:c,"data-sortable-tab-id":n,style:j,className:h,...l,...d,children:a}),e[10]=l,e[11]=a,e[12]=n,e[13]=d,e[14]=c,e[15]=j,e[16]=h,e[17]=x):x=e[17],x},Jg=s=>{const e=Ze.c(6),{id:n,children:a,className:r}=s;let i;e[0]!==r?(i=oe("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},Ln=s=>{const e=Ze.c(121),{items:n,activeId:a,onSelect:r,onClose:i,onReorder:l,layoutMode:d,variant:c,activePillInsetClassName:f,activePillButtonClassName:m,inactiveTabsIconOnly:p,iconOnlyActiveTab:u,animateActivePill:j,activePillLowercase:g,className:h}=s,x=d===void 0?"scrollable":d,A=c===void 0?"default":c,S=p===void 0?!1:p,C=u===void 0?!1:u,R=g===void 0?!0:g,{t:k}=st(),y=Fe(Qg),{isTablet:v}=Ms(),E=y||v,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,I]=o.useState(U);let P;e[1]!==n?(P=n.map(Yg),e[1]=n,e[2]=P):P=e[2];const z=P,T=x==="scrollable",J=A==="default",_=A==="active-pill",ee=A==="animated",Q=_||ee,N=J,V=Q||N,B=_&&T,F=Q,O=j??ee,q=typeof l=="function",$=q?Gg:Jg;let ie;e[3]===Symbol.for("react.memo_cache_sentinel")?(ie=new Map,e[3]=ie):ie=e[3];const le=o.useRef(ie),[ne,ye]=o.useState(null);let ae;e[4]===Symbol.for("react.memo_cache_sentinel")?(ae={activationConstraint:{distance:8}},e[4]=ae):ae=e[4];const ge=jd(wd(Nd,ae)),Ne=Xg;let he;e[5]===Symbol.for("react.memo_cache_sentinel")?(he=(Ye,_e)=>{if(_e){le.current.set(Ye,_e);return}le.current.delete(Ye)},e[5]=he):he=e[5];const we=he;let ce;e[6]!==a||e[7]!==V?(ce=()=>{if(!V||!a){ye(Zg);return}const Ye=K.current,_e=le.current.get(a);if(!Ye||!_e){ye(eh);return}let ft=0,xe=0,et=_e;for(;et&&et!==Ye;)ft=ft+et.offsetLeft,xe=xe+et.offsetTop,et=et.offsetParent;const nt={left:ft,top:xe,width:_e.offsetWidth,height:_e.offsetHeight};ye(He=>Ne(He,nt)?He:nt)},e[6]=a,e[7]=V,e[8]=ce):ce=e[8];const Z=ce;let se;e[9]!==T?(se=()=>{if(!T){I({left:!1,right:!1});return}const Ye=K.current;if(!Ye){I({left:!1,right:!1});return}I({left:Ye.scrollLeft>2,right:Ye.scrollLeft+Ye.clientWidth<Ye.scrollWidth-2})},e[9]=T,e[10]=se):se=e[10];const ve=se;let H;e[11]!==T||e[12]!==ve?(H=()=>{if(!T){I({left:!1,right:!1});return}const Ye=K.current;if(!Ye)return;ve(),Ye.addEventListener("scroll",ve,{passive:!0});const _e=new ResizeObserver(ve);return _e.observe(Ye),()=>{Ye.removeEventListener("scroll",ve),_e.disconnect()}},e[11]=T,e[12]=ve,e[13]=H):H=e[13];let te;e[14]!==T||e[15]!==n.length||e[16]!==ve?(te=[T,n.length,ve],e[14]=T,e[15]=n.length,e[16]=ve,e[17]=te):te=e[17],o.useEffect(H,te);let re;e[18]!==a||e[19]!==Z||e[20]!==V?(re=()=>{if(!V){ye(null);return}Z();const Ye=K.current;if(!Ye)return;const _e=new ResizeObserver(Z);if(_e.observe(Ye),a){const ft=le.current.get(a);ft&&_e.observe(ft)}return()=>{_e.disconnect()}},e[18]=a,e[19]=Z,e[20]=V,e[21]=re):re=e[21];let pe;e[22]!==a||e[23]!==n.length||e[24]!==Z||e[25]!==V?(pe=[a,n.length,Z,V],e[22]=a,e[23]=n.length,e[24]=Z,e[25]=V,e[26]=pe):pe=e[26],o.useEffect(re,pe);let Me;e[27]!==Z?(Me=()=>{Z()},e[27]=Z,e[28]=Me):Me=e[28],o.useLayoutEffect(Me);let Se;e[29]!==a||e[30]!==T||e[31]!==ve?(Se=()=>{if(!T||!a)return;const Ye=K.current;if(!Ye)return;const _e=window.requestAnimationFrame(()=>{const ft=typeof window.CSS?.escape=="function"?window.CSS.escape(a):a.replace(/"/g,'\\"'),xe=Ye.querySelector(`[data-sortable-tab-id="${ft}"]`);xe&&(xe.scrollIntoView({block:"nearest",inline:"nearest"}),ve())});return()=>{window.cancelAnimationFrame(_e)}},e[29]=a,e[30]=T,e[31]=ve,e[32]=Se):Se=e[32];let Ae;e[33]!==a||e[34]!==T||e[35]!==n.length||e[36]!==ve?(Ae=[a,T,n.length,ve],e[33]=a,e[34]=T,e[35]=n.length,e[36]=ve,e[37]=Ae):Ae=e[37],o.useEffect(Se,Ae);let De;e[38]!==l?(De=Ye=>{if(!l)return;const{active:_e,over:ft}=Ye;!ft||_e.id===ft.id||l(String(_e.id),String(ft.id))},e[38]=l,e[39]=De):De=e[39];const Pe=De;let Oe;e[40]!==h?(Oe=oe("relative flex h-full min-w-0 flex-1",h),e[40]=h,e[41]=Oe):Oe=e[41];let Te;e[42]!==T||e[43]!==M||e[44]!==Q?(Te=T&&M.left?t.jsx("div",{className:oe("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",Q?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=T,e[43]=M,e[44]=Q,e[45]=Te):Te=e[45];let Ue;e[46]!==T||e[47]!==M||e[48]!==Q?(Ue=T&&M.right?t.jsx("div",{className:oe("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",Q?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=T,e[47]=M,e[48]=Q,e[49]=Ue):Ue=e[49];const Be=Q?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Ke=Q&&"@container/pill-tabs",Je=Q&&"pill-tabs__track",ue=Q&&(f??"gap-0.5 py-0.5"),Y=N&&"items-center overflow-y-hidden",de=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",je=T?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Re;e[50]!==Be||e[51]!==Ke||e[52]!==Je||e[53]!==ue||e[54]!==Y||e[55]!==de||e[56]!==je?(Re=oe("relative flex h-full min-w-0 flex-1",Be,Ke,Je,ue,Y,de,je),e[50]=Be,e[51]=Ke,e[52]=Je,e[53]=ue,e[54]=Y,e[55]=de,e[56]=je,e[57]=Re):Re=e[57];let Ie;e[58]!==T?(Ie=T?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=T,e[59]=Ie):Ie=e[59];let Ve;e[60]!==k?(Ve=k("sortableTabsStrip.aria.tabs"),e[60]=k,e[61]=Ve):Ve=e[61];let X;e[62]!==ne||e[63]!==O||e[64]!==Q?(X=Q&&ne?t.jsx("div",{className:oe("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(${ne.left}px, ${ne.top}px, 0)`,width:`${ne.width}px`,height:`${ne.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]=ne,e[63]=O,e[64]=Q,e[65]=X):X=e[65];let b;e[66]!==ne||e[67]!==N?(b=N&&ne?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(${ne.left}px, 0, 0)`,width:`${ne.width}px`},"aria-hidden":!0}):null,e[66]=ne,e[67]=N,e[68]=b):b=e[68];let be;if(e[69]!==$||e[70]!==a||e[71]!==m||e[72]!==R||e[73]!==E||e[74]!==C||e[75]!==S||e[76]!==_||e[77]!==y||e[78]!==T||e[79]!==n||e[80]!==i||e[81]!==r||e[82]!==B||e[83]!==Q){let Ye;e[85]!==$||e[86]!==a||e[87]!==m||e[88]!==R||e[89]!==E||e[90]!==C||e[91]!==S||e[92]!==_||e[93]!==y||e[94]!==T||e[95]!==i||e[96]!==r||e[97]!==B||e[98]!==Q?(Ye=_e=>{const ft=_e.id===a,xe=S&&Q&&!ft&&!!_e.icon,et=!xe,nt=!!_e.icon&&(!C||ft),He=S&&Q&&ft&&!T&&!B,yt=_e.closable!==!1&&!!i,Nt=yt&&!!_e.icon,Tt=T||B?void 0:Q?He?"flex-none basis-auto":y?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",me=yt?Qe=>{Qe.button===1&&(Qe.preventDefault(),Qe.stopPropagation(),i?.(_e.id))}:void 0,$e=yt?th:void 0;return t.jsx($,{id:_e.id,className:Tt,children:t.jsxs("div",{ref:Qe=>we(_e.id,Qe),onAuxClick:me,onMouseDown:$e,className:oe("group flex h-full min-w-0 flex-nowrap items-center",T||B?"shrink-0":Q?"w-full":"w-full min-w-0",Q?"relative z-10 bg-transparent":ft?"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":ft,"aria-label":xe?_e.title??_e.label:void 0,onClick:()=>r(_e.id),className:oe(Q?"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",Q&&R?"lowercase":null,Q&&(xe?"gap-0":"gap-1.5"),Q?B?"shrink-0 whitespace-nowrap px-3 text-center":T?"max-w-56 shrink-0 px-3 text-center":xe?"px-2 !min-w-0 text-center":He?"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",Q?m??(_?y?"h-[38px]":"h-[31px]":"h-7"):null,Q?ft?"text-foreground":"text-muted-foreground hover:text-foreground":null,Q?"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:_e.title??_e.label,children:Q?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:oe("flex items-center justify-center transition-opacity",Nt&&(E?"opacity-0":"group-hover:opacity-0")),children:_e.icon}),Nt?t.jsx("span",{role:"button",tabIndex:-1,className:oe("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:sh,onClick:Qe=>{Qe.stopPropagation(),i?.(_e.id)},"aria-label":_e.closeLabel??`Close ${_e.label} tab`,title:_e.closeLabel??`Close ${_e.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:_e.label}):null]}):t.jsxs("span",{className:oe("flex min-w-0 flex-nowrap items-center gap-1.5",!T&&"justify-center"),children:[nt?t.jsxs("span",{className:oe("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",ft?"text-[var(--primary-base)]":"text-muted-foreground"),children:[t.jsx("span",{className:oe("flex items-center justify-center transition-opacity",Nt&&(E?"opacity-0":"group-hover:opacity-0")),children:_e.icon}),Nt?t.jsx("span",{role:"button",tabIndex:-1,className:oe("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:Qe=>{Qe.stopPropagation(),i?.(_e.id)},"aria-label":_e.closeLabel??`Close ${_e.label} tab`,title:_e.closeLabel??`Close ${_e.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:_e.label})]})}),yt&&!Nt?t.jsx("button",{type:"button",onPointerDown:ah,onClick:Qe=>{Qe.stopPropagation(),i?.(_e.id)},className:oe("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",Q?"-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",Q?ft?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":ft?"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":_e.closeLabel??`Close ${_e.label} tab`,title:_e.closeLabel??`Close ${_e.label} tab`,children:t.jsx(D,{name:"close",className:"h-3 w-3"})}):null]})},_e.id)},e[85]=$,e[86]=a,e[87]=m,e[88]=R,e[89]=E,e[90]=C,e[91]=S,e[92]=_,e[93]=y,e[94]=T,e[95]=i,e[96]=r,e[97]=B,e[98]=Q,e[99]=Ye):Ye=e[99],be=n.map(Ye),e[69]=$,e[70]=a,e[71]=m,e[72]=R,e[73]=E,e[74]=C,e[75]=S,e[76]=_,e[77]=y,e[78]=T,e[79]=n,e[80]=i,e[81]=r,e[82]=B,e[83]=Q,e[84]=be}else be=e[84];let Ee;e[100]!==Re||e[101]!==Ie||e[102]!==Ve||e[103]!==X||e[104]!==b||e[105]!==be?(Ee=t.jsxs("div",{ref:K,className:Re,style:Ie,role:"tablist","aria-label":Ve,children:[X,b,be]}),e[100]=Re,e[101]=Ie,e[102]=Ve,e[103]=X,e[104]=b,e[105]=be,e[106]=Ee):Ee=e[106];let ze;e[107]!==Oe||e[108]!==Te||e[109]!==Ue||e[110]!==Ee?(ze=t.jsxs("div",{className:Oe,children:[Te,Ue,Ee]}),e[107]=Oe,e[108]=Te,e[109]=Ue,e[110]=Ee,e[111]=ze):ze=e[111];const qe=ze;if(!q)return qe;let rt;e[112]===Symbol.for("react.memo_cache_sentinel")?(rt=[qg],e[112]=rt):rt=e[112];let lt;e[113]!==z||e[114]!==qe?(lt=t.jsx(Cd,{items:z,strategy:Id,children:qe}),e[113]=z,e[114]=qe,e[115]=lt):lt=e[115];let at;e[116]===Symbol.for("react.memo_cache_sentinel")?(at=t.jsx(Pd,{dropAnimation:null}),e[116]=at):at=e[116];let ct;return e[117]!==Pe||e[118]!==ge||e[119]!==lt?(ct=t.jsxs(Ad,{sensors:ge,collisionDetection:Dd,onDragEnd:Pe,modifiers:rt,children:[lt,at]}),e[117]=Pe,e[118]=ge,e[119]=lt,e[120]=ct):ct=e[120],ct};function Qg(s){return s.isMobile}function Yg(s){return s.id}function Xg(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 Zg(s){return s===null?s:null}function eh(s){return s===null?s:null}function th(s){s.button===1&&s.preventDefault()}function sh(s){s.stopPropagation()}function nh(s){s.stopPropagation()}function ah(s){s.stopPropagation()}const Za=()=>{try{const e=ss.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=js.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[PluginsStore] Error resolving config directory:",s)}return null},rh=800,ih=5e3,oh="__default__",mi=new Map,Lr=new Map,lh=1500,Sc=s=>s?.trim()||oh,ch=s=>{mi.delete(Sc(s))},ls=Nn()(Na(wi((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=Za(),r=Sc(a),i=Date.now(),l=mi.get(r)??0,d=e().entries.length>0||e().files.length>0;if(!n?.force&&d&&i-l<ih)return!0;const c=Lr.get(r);if(!n?.force&&c)return c;const f=(async()=>{s({isLoading:!0});try{const m=await dt(hn("/api/config/plugins",a),{headers:pa(a)});if(!m.ok)throw new Error("Failed to load plugins");const p=await er(m);return s({entries:p.entries??[],files:p.files??[],isLoading:!1}),mi.set(r,Date.now()),n?.force||e().loadRegistryInfo(),!0}catch(m){return console.error("[PluginsStore] Failed to load plugins:",m),s({isLoading:!1}),!1}})();Lr.set(r,f);try{return await f}finally{Lr.delete(r)}},loadRegistryInfo:async n=>{const a=uh(n?.specs??e().entries.map(r=>r.spec));if(a.length===0){s({isLoadingRegistry:!1});return}s({isLoadingRegistry:!0});try{const r=Za(),i={...e().registryInfo};for(const l of mh(a)){const d=await dt(dh(l,n?.force===!0,r),{headers:pa(r)});if(!d.ok)throw new Error("Failed to load plugin registry info");const c=await er(d);for(const f of c.results??[])i[f.spec]=f}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 Vn("Creating plugin entry…",async r=>await dt(hn("/api/config/plugins/entry",r),{method:"POST",headers:Ka(r),body:JSON.stringify(zo(n))}),e);return a.ok&&e().loadRegistryInfo({specs:[n.spec],force:!0}),a},updateEntry:async(n,a)=>{const r=e().entries.find(d=>d.id===n)?.spec,i=a.spec??r,l=await Vn("Updating plugin entry…",async d=>await dt(hn(`/api/config/plugins/entry/${encodeURIComponent(n)}`,d),{method:"PATCH",headers:Ka(d),body:JSON.stringify(zo(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 Vn("Deleting plugin entry…",async i=>await dt(hn(`/api/config/plugins/entry/${encodeURIComponent(n)}`,i),{method:"DELETE",headers:pa(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=Za(),r=await dt(hn(`/api/config/plugins/file/${encodeURIComponent(n)}`,a),{headers:pa(a)});if(!r.ok)throw new Error("Failed to read plugin file");return await er(r)}catch(a){return console.error("[PluginsStore] Failed to read plugin file:",a),null}},createFile:async n=>Vn("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)=>Vn("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 Vn("Deleting plugin file…",async r=>await dt(hn(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{method:"DELETE",headers:pa(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:Ci(),partialize:s=>({selectedId:s.selectedId})}),{name:"plugins-store"}));function hn(s,e){const n=e?`?directory=${encodeURIComponent(e)}`:"";return`${s}${n}`}function dh(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 uh(s){return Array.from(new Set(s.map(e=>e.trim()).filter(Boolean)))}function mh(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>lh?(e.push(n),n=[r],a=i.length):(n.push(r),a=l)}return n.length>0&&e.push(n),e}function pa(s){return s?{"x-opencode-directory":s}:void 0}function Ka(s){return{"Content-Type":"application/json",...s?{"x-opencode-directory":s}:{}}}function zo(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 Vn(s,e,n){Ja(s);let a=!1;try{const r=Za(),i=await e(r),l=await er(i).catch(()=>null);if(!i.ok)throw new Error(l?.error||"Failed to update plugin configuration");return ch(r),l?.requiresReload&&(a=!0,await Qa({message:l.message,delayMs:l.reloadDelayMs??rh,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||Ya()}}async function er(s){return await s.json()}const ph=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function gh(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 hh=({open:s,onOpenChange:e,defaultScope:n="user"})=>{const{t:a}=st(),r=ls(T=>T.createEntry),i=ls(T=>T.createFile),[l,d]=o.useState("npm"),[c,f]=o.useState(""),[m,p]=o.useState(""),[u,j]=o.useState(""),[g,h]=o.useState(""),[x,A]=o.useState(n),[S,C]=o.useState(!1),R=o.useCallback(()=>{f(""),p(""),j(""),h(""),A(n)},[n]);o.useEffect(()=>{s&&(d("npm"),R())},[s,R]);const k=T=>{T!==l&&(d(T),R())},y=o.useMemo(()=>gh(m),[m]),v=!y.ok,E=l==="file"&&u.trim()!==""&&!ph.test(u.trim()),K=(l==="npm"||l==="path")&&c.trim()==="",U=l==="file"&&g.trim()==="",M=l==="file"&&u.trim()==="",I=S||v||l==="npm"&&K||l==="path"&&K||l==="file"&&(M||E||U),P=async()=>{if(!I){C(!0);try{let T;l==="file"?T=await i({fileName:u.trim(),content:g,scope:x}):T=await r({spec:c.trim(),options:y.ok?y.value:void 0,scope:x}),T.ok?(W.success(T.message||a("settings.plugins.toast.created")),T.reloadFailed&&W.warning(a("settings.plugins.toast.reloadFailed")),e(!1)):W.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(Lt,{open:s,onOpenChange:T=>{!T&&S||e(T)},children:t.jsxs(Ft,{className:"max-w-xl",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:a("settings.plugins.dialog.add.title")}),t.jsx(_t,{children:a("settings.plugins.sidebar.empty.description")})]}),t.jsx(Ln,{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=>f(T.target.value),placeholder:a("settings.plugins.page.field.spec.placeholder"),"aria-invalid":K?!1:void 0,disabled:S}),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=>p(T.target.value),rows:5,className:"font-mono",hasError:v,disabled:S}),v&&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:u,onChange:T=>j(T.target.value),placeholder:"my-plugin.ts","aria-invalid":E||void 0,disabled:S}),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:g,onChange:T=>h(T.target.value),rows:16,className:"font-mono",disabled:S})]})]}),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 J=x===T,_=a(T==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return t.jsxs("button",{type:"button",onClick:()=>A(T),disabled:S,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[t.jsx(tn,{checked:J,onChange:()=>A(T),ariaLabel:_}),t.jsx("span",{className:oe("typography-ui-label font-normal",J?"text-foreground":"text-foreground/60"),children:_})]},T)})})]})]}),t.jsxs(Jt,{children:[t.jsx(G,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:S,children:a("settings.plugins.dialog.add.action.cancel")}),t.jsxs(G,{size:"sm",onClick:()=>{P()},disabled:I,children:[S?t.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,a("settings.plugins.dialog.add.action.submit")]})]})]})})},fh=s=>{const e=Ze.c(33),{spec:n}=s;let a;e[0]!==n?(a=d=>d.registryInfo[n],e[0]=n,e[1]=a):a=e[1];const r=ls(a),{t:i}=st();if(!r)return null;const l=xh;switch(r.kind){case"npm-ok":{if(!r.hasUpdate||!r.latestVersion)return null;let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(D,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=d):d=e[2];let c;e[3]!==r.latestVersion?(c=t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[d,r.latestVersion]}),e[3]=r.latestVersion,e[4]=c):c=e[4];let f;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==c?(f=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]=f):f=e[9],f}case"npm-missing-version":{let d;e[10]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=d):d=e[10];let c;return e[11]!==r.currentVersion||e[12]!==r.name||e[13]!==i?(c=l(d,i("settings.plugins.registry.badge.missingVersion.tooltip",{version:r.currentVersion,name:r.name})),e[11]=r.currentVersion,e[12]=r.name,e[13]=i,e[14]=c):c=e[14],c}case"npm-missing-package":{let d;e[15]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=d):d=e[15];let c;return e[16]!==r.name||e[17]!==i?(c=l(d,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:r.name})),e[16]=r.name,e[17]=i,e[18]=c):c=e[18],c}case"npm-malformed":{let d;e[19]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=d):d=e[19];let c;return e[20]!==i?(c=l(d,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=c):c=e[21],c}case"npm-network":{let d;e[22]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(D,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=d):d=e[22];let c;return e[23]!==i?(c=l(d,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=c):c=e[24],c}case"path-missing":{let d;e[25]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=d):d=e[25];let c;return e[26]!==r.absolutePath||e[27]!==i?(c=l(d,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:r.absolutePath})),e[26]=r.absolutePath,e[27]=i,e[28]=c):c=e[28],c}case"path-unreadable":{let d;e[29]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(D,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=d):d=e[29];let c;return e[30]!==r.absolutePath||e[31]!==i?(c=l(d,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:r.absolutePath})),e[30]=r.absolutePath,e[31]=i,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function xh(s,e){return t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:s})}),t.jsx(Pt,{children:e})]})}const Cc=s=>{const e=Ze.c(26),{header:n,footer:a,children:r,className:i,variant:l}=s,d=l===void 0?"sidebar":l,c=fs(),f=o.useRef(null),[m,p]=o.useState(!1),[u,j]=o.useState(!1),g=d==="background"||c?"bg-background":"bg-sidebar",h=g==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const I=f.current;if(!I){p(!1),j(!1);return}if(!(I.scrollHeight>I.clientHeight+1)){p(!1),j(!1);return}p(I.scrollTop>1),j(I.scrollTop+I.clientHeight<I.scrollHeight-1)},e[0]=x):x=e[0];const A=x;let S;e[1]===Symbol.for("react.memo_cache_sentinel")?(S=()=>{A()},e[1]=S):S=e[1];let C;e[2]!==r?(C=[r,A],e[2]=r,e[3]=C):C=e[3],o.useEffect(S,C);let R,k;e[4]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const I=f.current;if(!I)return;const P=()=>A();return I.addEventListener("scroll",P,{passive:!0}),()=>I.removeEventListener("scroll",P)},k=[A],e[4]=R,e[5]=k):(R=e[4],k=e[5]),o.useEffect(R,k);let y;e[6]!==g||e[7]!==i?(y=oe("flex h-full flex-col",g,i),e[6]=g,e[7]=i,e[8]=y):y=e[8];let v;e[9]!==r?(v=t.jsx(Ht,{ref:f,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]=v):v=e[10];let E;e[11]!==h||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, ${h} 0%, transparent 100%)`}}),e[11]=h,e[12]=m,e[13]=E):E=e[13];let K;e[14]!==h||e[15]!==u?(K=u&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${h} 0%, transparent 100%)`}}),e[14]=h,e[15]=u,e[16]=K):K=e[16];let U;e[17]!==K||e[18]!==v||e[19]!==E?(U=t.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[v,E,K]}),e[17]=K,e[18]=v,e[19]=E,e[20]=U):U=e[20];let M;return e[21]!==a||e[22]!==n||e[23]!==U||e[24]!==y?(M=t.jsxs("div",{className:y,children:[n,U,a]}),e[21]=a,e[22]=n,e[23]=U,e[24]=y,e[25]=M):M=e[25],M},pi=s=>{const e=Ze.c(23),{title:n,metadata:a,selected:r,onSelect:i,icon:l,actions:d,className:c}=s,f=r===void 0?!1:r,m=d&&d.length>0,p=f?"bg-interactive-selection":"hover:bg-interactive-hover";let u;e[0]!==c||e[1]!==p?(u=oe("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",p,c),e[0]=c,e[1]=p,e[2]=u):u=e[2];let j;e[3]!==n?(j=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=j):j=e[4];let g;e[5]!==l||e[6]!==j?(g=t.jsxs("div",{className:"flex items-center gap-1.5",children:[l,j]}),e[5]=l,e[6]=j,e[7]=g):g=e[7];let h;e[8]!==a?(h=a&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a}),e[8]=a,e[9]=h):h=e[9];let x;e[10]!==i||e[11]!==g||e[12]!==h?(x=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:[g,h]}),e[10]=i,e[11]=g,e[12]=h,e[13]=x):x=e[13];let A;e[14]!==d||e[15]!==m?(A=m&&t.jsxs(gs,{children:[t.jsx(ms,{asChild:!0,children:t.jsx(G,{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:d.map(yh)})]}),e[14]=d,e[15]=m,e[16]=A):A=e[16];let S;e[17]!==x||e[18]!==A?(S=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,A]}),e[17]=x,e[18]=A,e[19]=S):S=e[19];let C;return e[20]!==u||e[21]!==S?(C=t.jsx("div",{className:u,children:S}),e[20]=u,e[21]=S,e[22]=C):C=e[22],C};function yh(s){const e=s.icon;return t.jsxs(Ss,{onClick:n=>{n.stopPropagation(),s.onClick()},className:oe(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 bh=s=>s.parsedKind==="npm"?"code-box":"folder",vh=s=>{const e=Ze.c(144),{onItemSelect:n,onAddClick:a}=s,{t:r}=st(),{entries:i,files:l,selectedId:d,setSelected:c,deleteEntry:f,deleteFile:m,loadPlugins:p}=ls(Es(jh)),u=ls(wh),j=ls(Nh),g=ls(kh),h=ls(Sh),[x,A]=o.useState(null),[S,C]=o.useState(!1),[R,k]=o.useState(!1);let y,v;e[0]!==p?(y=()=>{p()},v=[p],e[0]=p,e[1]=y,e[2]=v):(y=e[1],v=e[2]),o.useEffect(y,v);let E,K;e[3]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{const xe=()=>k(!0);return window.addEventListener("openchamber:settings-open-plugin-add",xe),()=>window.removeEventListener("openchamber:settings-open-plugin-add",xe)},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]!==u){U={userEntries:0,projectEntries:0};for(const xe of i){const et=u[xe.spec];et?.kind==="npm-ok"&&et.hasUpdate&&(xe.scope==="user"?U.userEntries=U.userEntries+1:xe.scope==="project"&&(U.projectEntries=U.projectEntries+1))}e[5]=i,e[6]=u,e[7]=U}else U=e[7];const M=U;let I;e[8]!==i?(I=i.filter(Ch),e[8]=i,e[9]=I):I=e[9];const P=I;let z;e[10]!==i?(z=i.filter(Ih),e[10]=i,e[11]=z):z=e[11];const T=z;let J;e[12]!==l?(J=l.filter(Ph),e[12]=l,e[13]=J):J=e[13];const _=J;let ee;e[14]!==l?(ee=l.filter(Ah),e[14]=l,e[15]=ee):ee=e[15];const Q=ee,N=i.length+l.length,V=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=xe=>{c(xe),n?.()},e[18]=n,e[19]=c,e[20]=O):O=e[20];const q=O;let $;e[21]!==i||e[22]!==u||e[23]!==r||e[24]!==h?($=async xe=>{const et=i.find(Nt=>Nt.id===xe);if(!et)return;const nt=u[et.spec];if(!nt||nt.kind!=="npm-ok"||!nt.hasUpdate||!nt.latestVersion)return;const He=nt.latestVersion;(await h(xe)).ok?W.success(r("settings.plugins.toast.updatedToLatest",{version:He})):W.error(r("settings.plugins.toast.refreshFailed"))},e[21]=i,e[22]=u,e[23]=r,e[24]=h,e[25]=$):$=e[25];const ie=$;let le;e[26]!==g||e[27]!==r?(le=async()=>{W.info(r("settings.plugins.toast.refreshing"));try{await g({force:!0})}catch{W.error(r("settings.plugins.toast.refreshFailed"))}},e[26]=g,e[27]=r,e[28]=le):le=e[28];const ne=le;let ye;e[29]!==f||e[30]!==m||e[31]!==x||e[32]!==r?(ye=async()=>{if(!x)return;C(!0);const xe=x.kind==="entry"?await f(x.id):await m(x.id);xe.ok?W.success(xe.message||r("settings.plugins.sidebar.toast.deleted",{name:x.label})):W.error(r("settings.plugins.sidebar.toast.deleteFailed")),A(null),C(!1)},e[29]=f,e[30]=m,e[31]=x,e[32]=r,e[33]=ye):ye=e[33];const ae=ye;let ge;e[34]!==q||e[35]!==ie||e[36]!==u||e[37]!==d||e[38]!==r?(ge=xe=>{const et=u[xe.spec],nt=et?.kind==="npm-ok"&&et.hasUpdate&&!!et.latestVersion,He=[];return nt&&He.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{ie(xe.id)}}),He.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>A({kind:"entry",id:xe.id,label:xe.spec})}),t.jsx(pi,{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:xe.spec}),t.jsx(fh,{spec:xe.spec})]}),metadata:xe.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:d===xe.id,onSelect:()=>q(xe.id),icon:t.jsx(D,{name:bh(xe),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:He},xe.id)},e[34]=q,e[35]=ie,e[36]=u,e[37]=d,e[38]=r,e[39]=ge):ge=e[39];const Ne=ge;let he;e[40]!==q||e[41]!==d||e[42]!==r?(he=xe=>t.jsx(pi,{title:xe.fileName,metadata:r("settings.plugins.sidebar.kind.file"),selected:d===xe.id,onSelect:()=>q(xe.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:()=>A({kind:"file",id:xe.id,label:xe.fileName})}]},xe.id),e[40]=q,e[41]=d,e[42]=r,e[43]=he):he=e[43];const we=he;let ce;e[44]!==r?(ce=(xe,et,nt)=>{const He=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:[xe,He>0&&t.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(He===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:He})})]}),et]})},e[44]=r,e[45]=ce):ce=e[45];const Z=ce;let se;e[46]!==r?(se=r("settings.plugins.sidebar.title"),e[46]=r,e[47]=se):se=e[47];let ve;e[48]!==se?(ve=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:se})}),e[48]=se,e[49]=ve):ve=e[49];let H;e[50]!==r||e[51]!==N?(H=r("settings.plugins.sidebar.total",{count:N}),e[50]=r,e[51]=N,e[52]=H):H=e[52];let te;e[53]!==H?(te=t.jsx("span",{className:"typography-meta text-muted-foreground",children:H}),e[53]=H,e[54]=te):te=e[54];let re;e[55]!==ne?(re=()=>{ne()},e[55]=ne,e[56]=re):re=e[56];let pe;e[57]!==r?(pe=r("settings.plugins.sidebar.actions.refresh"),e[57]=r,e[58]=pe):pe=e[58];let Me;e[59]!==r?(Me=r("settings.plugins.sidebar.actions.refresh"),e[59]=r,e[60]=Me):Me=e[60];const Se=j?"size-4 animate-spin":"size-4";let Ae;e[61]!==Se?(Ae=t.jsx(D,{name:"refresh",className:Se}),e[61]=Se,e[62]=Ae):Ae=e[62];let De;e[63]!==j||e[64]!==re||e[65]!==pe||e[66]!==Me||e[67]!==Ae?(De=t.jsx(G,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:re,disabled:j,"aria-label":pe,title:Me,children:Ae}),e[63]=j,e[64]=re,e[65]=pe,e[66]=Me,e[67]=Ae,e[68]=De):De=e[68];let Pe;e[69]!==r?(Pe=r("settings.plugins.sidebar.actions.addTitle"),e[69]=r,e[70]=Pe):Pe=e[70];let Oe;e[71]!==r?(Oe=r("settings.plugins.sidebar.actions.addTitle"),e[71]=r,e[72]=Oe):Oe=e[72];let Te;e[73]===Symbol.for("react.memo_cache_sentinel")?(Te=t.jsx(D,{name:"add",className:"size-4"}),e[73]=Te):Te=e[73];let Ue;e[74]!==F||e[75]!==Pe||e[76]!==Oe?(Ue=t.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:F,"aria-label":Pe,title:Oe,children:Te}),e[74]=F,e[75]=Pe,e[76]=Oe,e[77]=Ue):Ue=e[77];let Be;e[78]!==De||e[79]!==Ue?(Be=t.jsxs("div",{className:"flex items-center gap-1",children:[De,Ue]}),e[78]=De,e[79]=Ue,e[80]=Be):Be=e[80];let Ke;e[81]!==te||e[82]!==Be?(Ke=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[te,Be]}),e[81]=te,e[82]=Be,e[83]=Ke):Ke=e[83];let Je;e[84]!==ve||e[85]!==Ke?(Je=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ve,Ke]}),e[84]=ve,e[85]=Ke,e[86]=Je):Je=e[86];let ue;e[87]!==V||e[88]!==T||e[89]!==Q||e[90]!==Ne||e[91]!==we||e[92]!==Z||e[93]!==r||e[94]!==M||e[95]!==P||e[96]!==_?(ue=V?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:[P.length>0&&Z(r("settings.plugins.sidebar.group.userEntries"),P.map(Ne),M.userEntries),_.length>0&&Z(r("settings.plugins.sidebar.group.userFiles"),_.map(we)),T.length>0&&Z(r("settings.plugins.sidebar.group.projectEntries"),T.map(Ne),M.projectEntries),Q.length>0&&Z(r("settings.plugins.sidebar.group.projectFiles"),Q.map(we))]}),e[87]=V,e[88]=T,e[89]=Q,e[90]=Ne,e[91]=we,e[92]=Z,e[93]=r,e[94]=M,e[95]=P,e[96]=_,e[97]=ue):ue=e[97];let Y;e[98]!==Je||e[99]!==ue?(Y=t.jsx(Cc,{variant:"background",header:Je,children:ue}),e[98]=Je,e[99]=ue,e[100]=Y):Y=e[100];let de;e[101]!==R?(de=t.jsx(hh,{open:R,onOpenChange:k}),e[101]=R,e[102]=de):de=e[102];const je=x!==null;let Re;e[103]!==S?(Re=xe=>{!xe&&!S&&A(null)},e[103]=S,e[104]=Re):Re=e[104];let Ie;e[105]!==r?(Ie=r("settings.plugins.sidebar.deleteDialog.title"),e[105]=r,e[106]=Ie):Ie=e[106];let Ve;e[107]!==Ie?(Ve=t.jsx(Ut,{children:Ie}),e[107]=Ie,e[108]=Ve):Ve=e[108];const X=x?.label??"";let b;e[109]!==r||e[110]!==X?(b=r("settings.plugins.sidebar.deleteDialog.description",{name:X}),e[109]=r,e[110]=X,e[111]=b):b=e[111];let be;e[112]!==b?(be=t.jsx(_t,{children:b}),e[112]=b,e[113]=be):be=e[113];let Ee;e[114]!==Ve||e[115]!==be?(Ee=t.jsxs(Kt,{children:[Ve,be]}),e[114]=Ve,e[115]=be,e[116]=Ee):Ee=e[116];let ze;e[117]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>A(null),e[117]=ze):ze=e[117];let qe;e[118]!==r?(qe=r("settings.common.actions.cancel"),e[118]=r,e[119]=qe):qe=e[119];let rt;e[120]!==S||e[121]!==qe?(rt=t.jsx(G,{size:"sm",variant:"ghost",onClick:ze,disabled:S,children:qe}),e[120]=S,e[121]=qe,e[122]=rt):rt=e[122];let lt;e[123]!==S||e[124]!==r?(lt=r(S?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=S,e[124]=r,e[125]=lt):lt=e[125];let at;e[126]!==ae||e[127]!==S||e[128]!==lt?(at=t.jsx(G,{size:"sm",variant:"destructive",onClick:ae,disabled:S,children:lt}),e[126]=ae,e[127]=S,e[128]=lt,e[129]=at):at=e[129];let ct;e[130]!==rt||e[131]!==at?(ct=t.jsxs(Jt,{children:[rt,at]}),e[130]=rt,e[131]=at,e[132]=ct):ct=e[132];let Ye;e[133]!==Ee||e[134]!==ct?(Ye=t.jsxs(Ft,{className:"max-w-md",children:[Ee,ct]}),e[133]=Ee,e[134]=ct,e[135]=Ye):Ye=e[135];let _e;e[136]!==je||e[137]!==Re||e[138]!==Ye?(_e=t.jsx(Lt,{open:je,onOpenChange:Re,children:Ye}),e[136]=je,e[137]=Re,e[138]=Ye,e[139]=_e):_e=e[139];let ft;return e[140]!==Y||e[141]!==de||e[142]!==_e?(ft=t.jsxs(t.Fragment,{children:[Y,de,_e]}),e[140]=Y,e[141]=de,e[142]=_e,e[143]=ft):ft=e[143],ft};function jh(s){return{entries:s.entries,files:s.files,selectedId:s.selectedId,setSelected:s.setSelected,deleteEntry:s.deleteEntry,deleteFile:s.deleteFile,loadPlugins:s.loadPlugins}}function wh(s){return s.registryInfo}function Nh(s){return s.isLoadingRegistry}function kh(s){return s.loadRegistryInfo}function Sh(s){return s.updateToLatest}function Ch(s){return s.scope==="user"}function Ih(s){return s.scope==="project"}function Ph(s){return s.scope==="user"}function Ah(s){return s.scope==="project"}const gi=s=>{const e=Ze.c(10),{children:n,className:a,outerClassName:r}=s;let i;e[0]!==r?(i=oe("h-full",r),e[0]=r,e[1]=i):i=e[1];let l;e[2]!==a?(l=oe("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 d;e[4]!==n||e[5]!==l?(d=t.jsx("div",{className:l,children:n}),e[4]=n,e[5]=l,e[6]=d):d=e[6];let c;return e[7]!==i||e[8]!==d?(c=t.jsx(Ht,{outerClassName:i,className:"w-full",children:d}),e[7]=i,e[8]=d,e[9]=c):c=e[9],c},Dh=({entryId:s,spec:e})=>{const{t:n}=st(),a=ls(p=>p.registryInfo[e]),r=ls(p=>p.updateToLatest),[i,l]=o.useState(!1);if(!a)return null;if(a.kind==="npm-ok"){if(!a.hasUpdate||!a.latestVersion)return null;const p=a.latestVersion,u=a.currentVersion??"",j=async()=>{l(!0);try{(await r(s)).ok?W.success(n("settings.plugins.toast.updatedToLatest",{version:p})):W.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:u,latest:p})})]}),t.jsx(G,{variant:"default",size:"sm",onClick:()=>{j()},disabled:i,children:n("settings.plugins.registry.banner.updateAvailable.action",{latest:p})})]})}if(a.kind==="path-ok")return null;if(a.kind==="npm-network")return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(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 d=a.kind==="path-unreadable",c=d?"var(--status-warning)":"var(--status-error)",f=d?"alert":"error-warning",m=(()=>{switch(a.kind){case"npm-missing-version":return n("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return n("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return n("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return n("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return n("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(D,{name:f,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 Eh(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 Ic(s){return!s||Object.keys(s).length===0?"":JSON.stringify(s,null,2)}function Uo(s){return{mode:"entry",scope:s.scope,spec:s.spec,optionsJson:Ic(s.options),fileName:"",content:""}}function Ko(s,e){return{mode:"file",scope:s.scope,spec:"",optionsJson:"",fileName:s.fileName,content:e}}const Bo=s=>{const e=Ze.c(4),{scope:n,label:a}=s;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=oe("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},Mh=()=>{const{t:s}=st(),e=ls(x=>x.selectedId),n=ls(x=>x.entries),a=ls(x=>x.files),r=ls(x=>x.draft),i=ls(x=>x.setDraft),l=ls(x=>x.updateEntry),d=ls(x=>x.updateFile),c=ls(x=>x.readFile),f=o.useMemo(()=>e?n.find(x=>x.id===e)??null:null,[n,e]),m=o.useMemo(()=>e?a.find(x=>x.id===e)??null:null,[a,e]),[p,u]=o.useState(!1),[j,g]=o.useState(!1),h=o.useRef(new Map);if(o.useEffect(()=>{let x=!1;return f?(i(Uo(f)),()=>{x=!0}):m?(g(!0),(async()=>{const A=await c(m.id);if(x)return;g(!1);const S=A?.content??"";h.current.set(m.id,S),i(Ko(m,S))})(),()=>{x=!0}):(i(null),()=>{x=!0})},[f,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(f&&r&&r.mode==="entry"){const x=Eh(r.optionsJson),A=x.ok,S=r.spec!==f.spec||r.optionsJson!==Ic(f.options),C=()=>{i(Uo(f))},R=async()=>{if(!A)return;const k=r.spec.trim();if(!k){W.error(s("settings.plugins.validation.specRequired"));return}u(!0);try{const y=await l(f.id,{spec:k,options:x.value});y.ok?y.reloadFailed?W.warning(y.message||s("settings.plugins.toast.reloadFailed"),{description:y.warning}):W.success(y.message||s("settings.plugins.toast.updated")):W.error(y.message||s("settings.plugins.toast.reloadFailed"))}finally{u(!1)}};return t.jsxs(gi,{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(Bo,{scope:f.scope,label:f.scope==="project"?s("settings.plugins.sidebar.group.projectEntries"):s("settings.plugins.sidebar.group.userEntries")})]})}),t.jsx(Dh,{entryId:f.id,spec:f.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:oe("font-mono typography-meta min-h-[200px]",!A&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!A&&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(G,{variant:"default",size:"sm",onClick:()=>{R()},disabled:!S||!A||p,children:s("settings.plugins.page.action.save")}),t.jsx(G,{variant:"outline",size:"sm",onClick:C,disabled:!S||p,children:s("settings.plugins.page.action.discard")})]})]})}if(m&&r&&r.mode==="file"){const x=h.current.get(m.id)??"",A=r.content!==x||r.fileName!==m.fileName,S=()=>{(async()=>{g(!0);const k=(await c(m.id))?.content??"";g(!1),h.current.set(m.id,k),i(Ko(m,k))})()},C=async()=>{u(!0);try{const R=await d(m.id,{content:r.content});R.ok?(h.current.set(m.id,r.content),R.reloadFailed?W.warning(R.message||s("settings.plugins.toast.reloadFailed"),{description:R.warning}):W.success(R.message||s("settings.plugins.toast.updated"))):W.error(R.message||s("settings.plugins.toast.reloadFailed"))}finally{u(!1)}};return t.jsxs(gi,{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(Bo,{scope:m.scope,label:m.scope==="project"?s("settings.plugins.sidebar.group.projectFiles"):s("settings.plugins.sidebar.group.userFiles")}),t.jsx("span",{className:oe("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:R=>i({...r,content:R.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:j})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(G,{variant:"default",size:"sm",onClick:()=>{C()},disabled:!A||p||j,children:s("settings.plugins.page.action.save")}),t.jsx(G,{variant:"outline",size:"sm",onClick:S,disabled:p||j,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"})})})},Th="<built-in>",Wn=s=>s?.path===Th,Rh=s=>{const e=Ze.c(150),{onItemSelect:n}=s,{t:a}=st(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,f]=o.useState(null),[m,p]=o.useState(!1),[u,j]=o.useState(null),{selectedSkillName:g,skills:h,setSelectedSkill:x,setSkillDraft:A,createSkill:S,deleteSkill:C,getSkillDetail:R}=an(Es(Lh));let k;e[0]!==n||e[1]!==x||e[2]!==A||e[3]!==h?(k=()=>{let xe="new-skill",et=1;for(;h.some(nt=>nt.name===xe);)xe=`new-skill-${et}`,et++;A({name:xe,scope:"user",source:"opencode",description:""}),x(xe),n?.()},e[0]=n,e[1]=x,e[2]=A,e[3]=h,e[4]=k):k=e[4];const y=k;let v;e[5]===Symbol.for("react.memo_cache_sentinel")?(v=async xe=>{Wn(xe)||f(xe)},e[5]=v):v=e[5];const E=v;let K;e[6]!==c||e[7]!==C||e[8]!==a?(K=async()=>{if(!c)return;if(Wn(c)){f(null);return}p(!0),await C(c.name)?(W.success(a("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),f(null)):W.error(a("settings.skills.sidebar.toast.deleteSkillFailed")),p(!1)},e[6]=c,e[7]=C,e[8]=a,e[9]=K):K=e[9];const U=K;let M;e[10]!==R||e[11]!==x||e[12]!==A||e[13]!==h||e[14]!==a?(M=async xe=>{if(Wn(xe))return;const et=xe.name;let nt=1,He=`${et}-copy`;for(;h.some(Nt=>Nt.name===He);)nt++,He=`${et}-copy-${nt}`;const yt=await R(xe.name);if(!yt){W.error(a("settings.skills.sidebar.toast.duplicateLoadFailed"));return}A({name:He,scope:xe.scope||"user",source:xe.source||"opencode",description:(yt.sources.md.fields.includes("description"),""),instructions:""}),x(He)},e[10]=R,e[11]=x,e[12]=A,e[13]=h,e[14]=a,e[15]=M):M=e[15];const I=M;let P;e[16]===Symbol.for("react.memo_cache_sentinel")?(P=xe=>{Wn(xe)||(d(xe.name),i(xe))},e[16]=P):P=e[16];const z=P;let T;e[17]!==S||e[18]!==C||e[19]!==R||e[20]!==r||e[21]!==l||e[22]!==x||e[23]!==h||e[24]!==a?(T=async()=>{if(!r)return;if(Wn(r)){i(null);return}const xe=l.trim().replace(/\s+/g,"-").toLowerCase();if(!xe){W.error(a("settings.skills.page.toast.skillNameRequired"));return}if(xe===r.name){i(null);return}if(h.some(He=>He.name===xe)){W.error(a("settings.skills.page.toast.skillExists"));return}if(!await R(r.name)){W.error(a("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await S({name:xe,description:"Renamed skill",scope:r.scope,source:r.source})?await C(r.name)?(W.success(`Skill renamed to "${xe}"`),x(xe)):W.error(a("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):W.error(a("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=S,e[18]=C,e[19]=R,e[20]=r,e[21]=l,e[22]=x,e[23]=h,e[24]=a,e[25]=T):T=e[25];const J=T;let _;e[26]!==h?(_=h.filter(Fh),e[26]=h,e[27]=_):_=e[27];const ee=_;let Q;e[28]!==h?(Q=h.filter(Oh),e[28]=h,e[29]=Q):Q=e[29];const N=Q;let V;e[30]===Symbol.for("react.memo_cache_sentinel")?(V=function(et){const nt={},He=[];for(const Nt of et)Nt.group?(nt[Nt.group]||(nt[Nt.group]=[]),nt[Nt.group].push(Nt)):He.push(Nt);const yt=Object.keys(nt).sort(zh).map(Nt=>({name:Nt,skills:[...nt[Nt]].sort(Uh)}));return He.sort(Kh),{sortedGroups:yt,ungrouped:He}},e[30]=V):V=e[30];const B=V;let F;e[31]!==ee?(F=B(ee),e[31]=ee,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 $=q;let ie;e[35]===Symbol.for("react.memo_cache_sentinel")?(ie=oe("flex h-full flex-col","bg-background"),e[35]=ie):ie=e[35];let le;e[36]!==a?(le=a("settings.skills.sidebar.title"),e[36]=a,e[37]=le):le=e[37];let ne;e[38]!==le?(ne=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:le}),e[38]=le,e[39]=ne):ne=e[39];let ye;e[40]===Symbol.for("react.memo_cache_sentinel")?(ye=t.jsx(ka,{className:"mb-3"}),e[40]=ye):ye=e[40];let ae;e[41]!==h.length||e[42]!==a?(ae=a("settings.skills.sidebar.total",{count:h.length}),e[41]=h.length,e[42]=a,e[43]=ae):ae=e[43];let ge;e[44]!==ae?(ge=t.jsx("span",{className:"typography-meta text-muted-foreground",children:ae}),e[44]=ae,e[45]=ge):ge=e[45];let Ne;e[46]===Symbol.for("react.memo_cache_sentinel")?(Ne=t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[46]=Ne):Ne=e[46];let he;e[47]!==y?(he=t.jsx(G,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:y,children:Ne}),e[47]=y,e[48]=he):he=e[48];let we;e[49]!==ge||e[50]!==he?(we=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ge,he]}),e[49]=ge,e[50]=he,e[51]=we):we=e[51];let ce;e[52]!==ne||e[53]!==we?(ce=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ne,ye,we]}),e[52]=ne,e[53]=we,e[54]=ce):ce=e[54];let Z;e[55]!==O||e[56]!==$||e[57]!==I||e[58]!==n||e[59]!==u||e[60]!==ee||e[61]!==g||e[62]!==x||e[63]!==h.length||e[64]!==a||e[65]!==N?(Z=t.jsx(Ht,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:h.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:[ee.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(xe=>{const{name:et,skills:nt}=xe;return t.jsx(ui,{label:et,count:nt.length,storageKey:"project-skills",children:nt.map(He=>t.jsx(Ba,{skill:He,isSelected:g===He.name,onSelect:()=>{x(He.name),n?.()},onRename:()=>z(He),onDelete:()=>E(He),onDuplicate:()=>I(He),isMenuOpen:u===He.name,onMenuOpenChange:yt=>j(yt?He.name:null)},He.name))},et)}),O.ungrouped.map(xe=>t.jsx(Ba,{skill:xe,isSelected:g===xe.name,onSelect:()=>{x(xe.name),n?.()},onRename:()=>z(xe),onDelete:()=>E(xe),onDuplicate:()=>I(xe),isMenuOpen:u===xe.name,onMenuOpenChange:et=>j(et?xe.name:null)},xe.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")}),$.sortedGroups.map(xe=>{const{name:et,skills:nt}=xe;return t.jsx(ui,{label:et,count:nt.length,storageKey:"user-skills",children:nt.map(He=>t.jsx(Ba,{skill:He,isSelected:g===He.name,onSelect:()=>{x(He.name),n?.()},onRename:()=>z(He),onDelete:()=>E(He),onDuplicate:()=>I(He),isMenuOpen:u===He.name,onMenuOpenChange:yt=>j(yt?He.name:null)},He.name))},et)}),$.ungrouped.map(xe=>t.jsx(Ba,{skill:xe,isSelected:g===xe.name,onSelect:()=>{x(xe.name),n?.()},onRename:()=>z(xe),onDelete:()=>E(xe),onDuplicate:()=>I(xe),isMenuOpen:u===xe.name,onMenuOpenChange:et=>j(et?xe.name:null)},xe.name))]})]})}),e[55]=O,e[56]=$,e[57]=I,e[58]=n,e[59]=u,e[60]=ee,e[61]=g,e[62]=x,e[63]=h.length,e[64]=a,e[65]=N,e[66]=Z):Z=e[66];const se=c!==null;let ve;e[67]!==m?(ve=xe=>{!xe&&!m&&f(null)},e[67]=m,e[68]=ve):ve=e[68];let H;e[69]!==a?(H=a("settings.skills.sidebar.deleteDialog.title"),e[69]=a,e[70]=H):H=e[70];let te;e[71]!==H?(te=t.jsx(Ut,{children:H}),e[71]=H,e[72]=te):te=e[72];const re=c?.name??"";let pe;e[73]!==a||e[74]!==re?(pe=a("settings.skills.sidebar.deleteDialog.description",{name:re}),e[73]=a,e[74]=re,e[75]=pe):pe=e[75];let Me;e[76]!==pe?(Me=t.jsx(_t,{children:pe}),e[76]=pe,e[77]=Me):Me=e[77];let Se;e[78]!==te||e[79]!==Me?(Se=t.jsxs(Kt,{children:[te,Me]}),e[78]=te,e[79]=Me,e[80]=Se):Se=e[80];let Ae;e[81]===Symbol.for("react.memo_cache_sentinel")?(Ae=()=>f(null),e[81]=Ae):Ae=e[81];let De;e[82]!==a?(De=a("settings.common.actions.cancel"),e[82]=a,e[83]=De):De=e[83];let Pe;e[84]!==m||e[85]!==De?(Pe=t.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Ae,disabled:m,children:De}),e[84]=m,e[85]=De,e[86]=Pe):Pe=e[86];let Oe;e[87]!==a?(Oe=a("settings.common.actions.delete"),e[87]=a,e[88]=Oe):Oe=e[88];let Te;e[89]!==U||e[90]!==m||e[91]!==Oe?(Te=t.jsx(G,{size:"sm",onClick:U,disabled:m,children:Oe}),e[89]=U,e[90]=m,e[91]=Oe,e[92]=Te):Te=e[92];let Ue;e[93]!==Pe||e[94]!==Te?(Ue=t.jsxs(Jt,{children:[Pe,Te]}),e[93]=Pe,e[94]=Te,e[95]=Ue):Ue=e[95];let Be;e[96]!==Se||e[97]!==Ue?(Be=t.jsxs(Ft,{className:"max-w-md",children:[Se,Ue]}),e[96]=Se,e[97]=Ue,e[98]=Be):Be=e[98];let Ke;e[99]!==se||e[100]!==ve||e[101]!==Be?(Ke=t.jsx(Lt,{open:se,onOpenChange:ve,children:Be}),e[99]=se,e[100]=ve,e[101]=Be,e[102]=Ke):Ke=e[102];const Je=r!==null;let ue;e[103]===Symbol.for("react.memo_cache_sentinel")?(ue=xe=>!xe&&i(null),e[103]=ue):ue=e[103];let Y;e[104]!==a?(Y=a("settings.skills.sidebar.renameDialog.title"),e[104]=a,e[105]=Y):Y=e[105];let de;e[106]!==Y?(de=t.jsx(Ut,{children:Y}),e[106]=Y,e[107]=de):de=e[107];const je=r?.name??"";let Re;e[108]!==a||e[109]!==je?(Re=a("settings.skills.sidebar.renameDialog.description",{name:je}),e[108]=a,e[109]=je,e[110]=Re):Re=e[110];let Ie;e[111]!==Re?(Ie=t.jsx(_t,{children:Re}),e[111]=Re,e[112]=Ie):Ie=e[112];let Ve;e[113]!==de||e[114]!==Ie?(Ve=t.jsxs(Kt,{children:[de,Ie]}),e[113]=de,e[114]=Ie,e[115]=Ve):Ve=e[115];let X;e[116]===Symbol.for("react.memo_cache_sentinel")?(X=xe=>d(xe.target.value),e[116]=X):X=e[116];let b;e[117]!==a?(b=a("settings.skills.sidebar.renameDialog.placeholder"),e[117]=a,e[118]=b):b=e[118];let be;e[119]!==J?(be=xe=>{xe.key==="Enter"&&J()},e[119]=J,e[120]=be):be=e[120];let Ee;e[121]!==l||e[122]!==b||e[123]!==be?(Ee=t.jsx(Xe,{value:l,onChange:X,placeholder:b,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:be}),e[121]=l,e[122]=b,e[123]=be,e[124]=Ee):Ee=e[124];let ze;e[125]===Symbol.for("react.memo_cache_sentinel")?(ze=()=>i(null),e[125]=ze):ze=e[125];let qe;e[126]!==a?(qe=a("settings.common.actions.cancel"),e[126]=a,e[127]=qe):qe=e[127];let rt;e[128]!==qe?(rt=t.jsx(G,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:ze,children:qe}),e[128]=qe,e[129]=rt):rt=e[129];let lt;e[130]!==a?(lt=a("settings.common.actions.rename"),e[130]=a,e[131]=lt):lt=e[131];let at;e[132]!==J||e[133]!==lt?(at=t.jsx(G,{size:"sm",onClick:J,children:lt}),e[132]=J,e[133]=lt,e[134]=at):at=e[134];let ct;e[135]!==rt||e[136]!==at?(ct=t.jsxs(Jt,{children:[rt,at]}),e[135]=rt,e[136]=at,e[137]=ct):ct=e[137];let Ye;e[138]!==Ve||e[139]!==Ee||e[140]!==ct?(Ye=t.jsxs(Ft,{children:[Ve,Ee,ct]}),e[138]=Ve,e[139]=Ee,e[140]=ct,e[141]=Ye):Ye=e[141];let _e;e[142]!==Je||e[143]!==Ye?(_e=t.jsx(Lt,{open:Je,onOpenChange:ue,children:Ye}),e[142]=Je,e[143]=Ye,e[144]=_e):_e=e[144];let ft;return e[145]!==ce||e[146]!==Z||e[147]!==Ke||e[148]!==_e?(ft=t.jsxs("div",{className:ie,children:[ce,Z,Ke,_e]}),e[145]=ce,e[146]=Z,e[147]=Ke,e[148]=_e,e[149]=ft):ft=e[149],ft},Ba=s=>{const e=Ze.c(49),{skill:n,isSelected:a,onSelect:r,onDelete:i,onRename:l,onDuplicate:d,isMenuOpen:c,onMenuOpenChange:f}=s,{t:m}=st();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=va(),e[0]=p):p=e[0];const u=p;let j;e[1]!==n.source||e[2]!==m?(j=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]=j):j=e[3];const g=j;let h;e[4]!==n?(h=Wn(n),e[4]=n,e[5]=h):h=e[5];const x=h,[A,S]=o.useState(!1);let C;e[6]!==i||e[7]!==d||e[8]!==l||e[9]!==m?(C=N=>t.jsxs(t.Fragment,{children:[t.jsxs(N,{onClick:V=>{V.stopPropagation(),l()},children:[t.jsx(D,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),t.jsxs(N,{onClick:V=>{V.stopPropagation(),d()},children:[t.jsx(D,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),t.jsxs(N,{onClick:V=>{V.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]=d,e[8]=l,e[9]=m,e[10]=C):C=e[10];const R=C,k=!x&&A,y=a?"bg-interactive-selection":"hover:bg-interactive-hover";let v;e[11]!==y?(v=oe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",y),e[11]=y,e[12]=v):v=e[12];let E;e[13]!==x?(E=!u&&!x?N=>{N.preventDefault(),S(!0)}:void 0,e[13]=x,e[14]=E):E=e[14];let K;e[15]!==v||e[16]!==E?(K=t.jsx("div",{className:v,onContextMenu:E}),e[15]=v,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 I;e[22]!==g?(I=t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:g}),e[22]=g,e[23]=I):I=e[23];let P;e[24]!==U||e[25]!==M||e[26]!==I?(P=t.jsxs("div",{className:"flex items-center gap-1.5",children:[U,M,I]}),e[24]=U,e[25]=M,e[26]=I,e[27]=P):P=e[27];let z;e[28]!==r||e[29]!==P?(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:P}),e[28]=r,e[29]=P,e[30]=z):z=e[30];let T;e[31]!==x||e[32]!==c||e[33]!==f||e[34]!==R?(T=x?null:t.jsxs(gs,{open:c,onOpenChange:N=>{N&&S(!1),f(N)},children:[t.jsx(ms,{asChild:!0,children:t.jsx(G,{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:R(Ss)})]}),e[31]=x,e[32]=c,e[33]=f,e[34]=R,e[35]=T):T=e[35];let J;e[36]!==z||e[37]!==T?(J=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[z,T]}),e[36]=z,e[37]=T,e[38]=J):J=e[38];let _;e[39]!==J||e[40]!==K?(_=t.jsx(bn,{render:K,children:J}),e[39]=J,e[40]=K,e[41]=_):_=e[41];let ee;e[42]!==x||e[43]!==R?(ee=x?null:t.jsx(vn,{className:"w-fit min-w-20",children:R(ln)}),e[42]=x,e[43]=R,e[44]=ee):ee=e[44];let Q;return e[45]!==_||e[46]!==ee||e[47]!==k?(Q=t.jsxs(yn,{open:k,onOpenChange:S,children:[_,ee]}),e[45]=_,e[46]=ee,e[47]=k,e[48]=Q):Q=e[48],Q};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 Fh(s){return s.scope==="project"}function Oh(s){return s.scope==="user"}function zh(s,e){return s.localeCompare(e)}function Uh(s,e){return s.name.localeCompare(e.name)}function Kh(s,e){return s.name.localeCompare(e.name)}const Bh=s=>s!==null&&typeof s=="object"&&"updateStatus"in s&&typeof s.updateStatus=="function",$h=s=>{const e=document.createElement("div");e.className="cm-vim-panel";const n=Rd(s);if(!n)return{top:!1,dom:e};n.state.statusbar=e;const a=n.state.vimPlugin;return Bh(a)&&a.updateStatus(),{top:!1,dom:e,destroy(){n.state.statusbar===e&&(n.state.statusbar=null)}}};function $o(s){return s?[Ed(),Md.of($h),Td()]:[]}const Vh={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},_h={case:"Match case",re:"Regular expression",word:"Match whole word"};function Hh(s){const e=s.querySelector(".cm-search");if(e){for(const[n,a]of Object.entries(Vh)){const r=e.querySelector(`button[name="${n}"]`);r&&!r.title&&(r.title=a)}for(const[n,a]of Object.entries(_h)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=a)}}}const Fr=new WeakMap;function Wh(s,e){const n=ar(s.state);if(!n.valid)return Fr.delete(s),0;const a=Fr.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 Fr.set(s,{query:n,doc:s.state.doc,total:i}),i}function qh(s){const e=ar(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 d=l.value;if(r+=1,i===0&&(i=r),n.from===d.from&&n.to===d.to||n.from<d.to&&n.to>d.from||d.from>=n.head)return r}return i}function Vo(s,e,n=!1){const a=s.querySelector(".cm-search");if(!a)return;let r=a.querySelector(".cm-search-message");if(!r){r=document.createElement("span"),r.className="cm-search-message",r.setAttribute("aria-live","polite");const d=a.querySelector('button[name="next"]'),c=d?.parentNode===a?d:a.firstChild;a.insertBefore(r,c)}const i=Wh(e,n),l=i===0?0:qh(e);r.textContent=i===0?"":`${l}/${i}`}const _o=new Fn,Ho=new Fn,Wo=new Fn,qo=new Fn,Go=new Fn,Jo=new Fn,Qo=new Fn,Yo=s=>s,Or=$d,Gh=Vd,Jh=_d;class Qh extends Hd{constructor(e,n){super(),this.id=e,this.containerMap=n}toDOM(){let e=this.containerMap.get(this.id);return e||(e=document.createElement("div"),e.className="oc-block-widget",e.dataset.widgetId=this.id,this.containerMap.set(this.id,e)),e}eq(e){return e.id===this.id}destroy(){}}const Xo=(s,e)=>!s||s.length===0?[]:ec.define({create(n){const a=new Ni,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 d=n.doc.line(i.afterLine);a.add(d.to,d.to,dr.widget({widget:new Qh(i.id,e),block:!0,side:1}))}return a.finish()},update(n,a){return n.map(a.changes)},provide:n=>Hs.decorations.from(n)}),Zo=s=>{if(!s)return[];const e=Math.max(1,s.start),n=Math.max(e,s.end);return Zl.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 Ni;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,dr.line({class:"oc-cm-selected-line"}))}return r.finish()}},{decorations:a=>a.decorations})};function el({value:s,onChange:e,extensions:n,className:a,readOnly:r,lineNumbersConfig:i,highlightLines:l,onViewReady:d,onViewDestroy:c,blockWidgets:f,enableSearch:m,searchOpen:p,onSearchOpenChange:u,vimMode:j}){const g=o.useRef(null),h=o.useRef(null),x=o.useRef(s),A=o.useRef(e),S=o.useRef(d),C=o.useRef(c),R=o.useRef(u),k=o.useRef(f),y=o.useRef(j),v=o.useRef(new Map),[E,K]=o.useState([]),U=o.useCallback(I=>{const P=(I??[]).map(z=>{const T=v.current.get(z.id);return T?{id:z.id,content:z.content,container:T}:null}).filter(z=>z!==null);K(z=>z.length===P.length&&z.every((T,J)=>{const _=P[J];return T.id===_.id&&T.content===_.content&&T.container===_.container})?z:P)},[]),M=o.useCallback(I=>{const P=g.current,z=I??h.current;if(!P||!z)return;const T=z.dom.querySelector(".cm-gutters"),J=T instanceof HTMLElement?T.getBoundingClientRect().width:0;P.style.setProperty("--oc-editor-gutter-width",`${J}px`)},[]);return o.useEffect(()=>{x.current=s},[s]),o.useEffect(()=>{A.current=e},[e]),o.useEffect(()=>{S.current=d,C.current=c},[d,c]),o.useEffect(()=>{R.current=u},[u]),o.useEffect(()=>{k.current=f,U(f)},[f,U]),o.useEffect(()=>{if(!g.current)return;const I=(()=>{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})(),P=Ld.create({doc:x.current,extensions:[...I?[Hs.cspNonce.of(I)]:[],Fd({fixed:!0}),_o.of(Li(i)),Od(),zd.of(" "),Qo.of($o(j)),jr.of([Ud,...Kd,...Bd]),Hs.updateListener.of(z=>{M(z.view),(z.viewportChanged||z.geometryChanged)&&U(k.current);const T=Fi(z.startState),J=Fi(z.state);T!==J&&R.current?.(J);const _=!ar(z.startState).eq(ar(z.state));if(J&&(T!==J||_||z.docChanged||z.selectionSet)&&Vo(z.view.dom,z.view,T!==J||_||z.docChanged),!z.docChanged)return;const ee=z.state.doc.toString();x.current=ee,A.current(ee),U(k.current)}),Ho.of(Hs.editable.of(!r)),Wo.of(n??[]),qo.of(Zo(l)),Go.of(Xo(f,v.current)),Jo.of(m?[Oi({top:!0}),jr.of(Yo(zi))]:[])]});return h.current=new Hs({state:P,parent:g.current}),Or(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{M(h.current),U(k.current)}),h.current&&S.current?.(h.current),()=>{C.current?.(),h.current?.destroy(),h.current=null,K([])}},[k,M,U]),o.useEffect(()=>{const I=h.current;I&&(I.dispatch({effects:[_o.reconfigure(Li(i)),Ho.reconfigure(Hs.editable.of(!r)),Wo.reconfigure(n??[]),qo.reconfigure(Zo(l)),Go.reconfigure(Xo(f,v.current)),Jo.reconfigure(m?[Oi({top:!0}),jr.of(Yo(zi))]:[])]}),Or(I,I.state.doc.length,200),I.requestMeasure(),requestAnimationFrame(()=>{M(I),U(k.current)}))},[n,l,i,r,f,m,M,U]),o.useEffect(()=>{const I=h.current;if(!I){y.current=j;return}y.current!==j&&(y.current=j,I.dispatch({effects:Qo.reconfigure($o(j))}))},[j]),o.useEffect(()=>{const I=h.current;!I||m===!1||(p?(Gh(I),requestAnimationFrame(()=>{Hh(I.dom),Vo(I.dom,I,!0)})):Jh(I))},[p,m]),o.useEffect(()=>{const I=h.current;if(!I)return;const P=I.state.doc.toString();P!==s&&(I.dispatch({changes:{from:0,to:P.length,insert:s}}),Or(I,I.state.doc.length,300),I.requestMeasure(),requestAnimationFrame(()=>M(I)))},[s,M]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:g,className:oe("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(I=>Ga.createPortal(I.content,I.container,I.id))]})}const Yh=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 d;e[0]!==r?(d=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]=d):d=e[1];let c;e[2]!==i||e[3]!==a||e[4]!==d?(c=t.jsx(It,{asChild:!0,children:t.jsx(G,{variant:"ghost",size:"sm",onClick:a,"aria-label":i,className:"h-5 w-5 p-0",children:d})}),e[2]=i,e[3]=a,e[4]=d,e[5]=c):c=e[5];let f;e[6]!==l?(f=t.jsx(Pt,{sideOffset:8,children:l}),e[6]=l,e[7]=f):f=e[7];let m;return e[8]!==c||e[9]!==f?(m=t.jsxs(Ct,{children:[c,f]}),e[8]=c,e[9]=f,e[10]=m):m=e[10],m},Ds=Nn()(Na(wi((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 Su();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 ku();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 Nu();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 kt({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 wu(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 ju(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 vu(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:Ci(),partialize:s=>({selectedProfileId:s.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Ds);const Xh=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Zh=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},ef=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}},tf=s=>{const e=Ze.c(160),{open:n,onOpenChange:a}=s,{t:r}=st(),i=sn(sf),l=sn(nf),d=sn(af),c=sn(rf),f=sn(of),m=Ds(lf),p=Ds(cf),[u,j]=o.useState(""),[g,h]=o.useState(""),[x,A]=o.useState("");let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[0]=S):S=e[0];const[C,R]=o.useState(S),[k,y]=o.useState(null),[v,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),[I,P]=o.useState(null),z=o.useRef(0);let T;e[2]===Symbol.for("react.memo_cache_sentinel")?(T=xe=>{z.current=z.current+1,E(!1),y(null),xe?.clearIdentity&&(M([]),P(null))},e[2]=T):T=e[2];const J=T;let _,ee;e[3]!==p||e[4]!==n?(_=()=>{n&&(z.current=z.current+1,j(""),h(""),A(""),y(null),E(!1),M([]),P(null),p(),(async()=>{const xe=await ef(),et=Array.isArray(xe?.skillCatalogs)?xe?.skillCatalogs:[];R(et||[])})())},ee=[n,p],e[3]=p,e[4]=n,e[5]=_,e[6]=ee):(_=e[5],ee=e[6]),o.useEffect(_,ee);let Q;e[7]!==g?(Q=g.trim(),e[7]=g,e[8]=Q):Q=e[8];const N=Q;let V;e[9]!==x?(V=x.trim(),e[9]=x,e[10]=V):V=e[10];const B=V;let F;if(e[11]!==C||e[12]!==N||e[13]!==B){let xe;e[15]!==N||e[16]!==B?(xe=et=>{const nt=(et.source||"").trim(),He=(et.subpath||"").trim();return nt===N&&He===B},e[15]=N,e[16]=B,e[17]=xe):xe=e[17],F=C.some(xe),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]!==I||e[20]!==u||e[21]!==i||e[22]!==g||e[23]!==x||e[24]!==r?(q=async()=>{const xe=g.trim();if(!xe){W.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}u.trim()||j(Zh(xe)),E(!1),y(null);const et=z.current+1;z.current=et;const nt=await i({source:xe,subpath:x.trim()||void 0,gitIdentityId:I||void 0});if(z.current!==et)return;if(!nt.ok){if(nt.error?.kind==="authRequired"){if(fs()){W.error(r("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const yt=nt.error.identities||[];if(M(yt),!I&&yt.length>0){const Nt=m&&m!=="global"&&yt.some(Tt=>Tt.id===m)?m:yt[0].id;P(Nt)}W.error(r("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}W.error(nt.error?.message||r("settings.skills.catalog.add.toast.scanFailed"));return}const He=nt.items?.length||0;if(y(He),He===0){W.error(r("settings.skills.catalog.add.toast.noSkillsFound")),E(!1);return}M([]),E(!0),W.success(r("settings.skills.catalog.shared.toast.foundSkills",{count:He}))},e[18]=m,e[19]=I,e[20]=u,e[21]=i,e[22]=g,e[23]=x,e[24]=r,e[25]=q):q=e[25];const $=q;let ie;e[26]!==C||e[27]!==I||e[28]!==O||e[29]!==u||e[30]!==l||e[31]!==d||e[32]!==a||e[33]!==v||e[34]!==c||e[35]!==g||e[36]!==x||e[37]!==r?(ie=async()=>{const xe=u.trim(),et=g.trim(),nt=x.trim();if(!xe){W.error(r("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!et){W.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!v){W.error(r("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(O){W.error(r("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const He={id:Xh(),label:xe,source:et,...nt?{subpath:nt}:{},...I?{gitIdentityId:I}:{}},yt=[...C,He];try{await kt({skillCatalogs:yt}),R(yt),W.success(r("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await d(He.id,{refresh:!0}),c(He.id),a(!1)}catch(Nt){const Tt=Nt;W.error(Tt instanceof Error?Tt.message:r("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=C,e[27]=I,e[28]=O,e[29]=u,e[30]=l,e[31]=d,e[32]=a,e[33]=v,e[34]=c,e[35]=g,e[36]=x,e[37]=r,e[38]=ie):ie=e[38];const le=ie;let ne;e[39]!==r?(ne=r("settings.skills.catalog.add.title"),e[39]=r,e[40]=ne):ne=e[40];let ye;e[41]!==ne?(ye=t.jsx(Ut,{children:ne}),e[41]=ne,e[42]=ye):ye=e[42];let ae;e[43]!==r?(ae=r("settings.skills.catalog.add.descriptionPrefix"),e[43]=r,e[44]=ae):ae=e[44];let ge;e[45]===Symbol.for("react.memo_cache_sentinel")?(ge=t.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=ge):ge=e[45];let Ne;e[46]!==r?(Ne=r("settings.skills.catalog.add.descriptionSuffix"),e[46]=r,e[47]=Ne):Ne=e[47];let he;e[48]!==ae||e[49]!==Ne?(he=t.jsxs(_t,{children:[ae," ",ge,Ne]}),e[48]=ae,e[49]=Ne,e[50]=he):he=e[50];let we;e[51]!==ye||e[52]!==he?(we=t.jsxs(Kt,{children:[ye,he]}),e[51]=ye,e[52]=he,e[53]=we):we=e[53];let ce;e[54]!==r?(ce=r("settings.skills.catalog.add.field.catalogName"),e[54]=r,e[55]=ce):ce=e[55];let Z;e[56]!==ce?(Z=t.jsx("label",{className:"typography-ui-label text-foreground",children:ce}),e[56]=ce,e[57]=Z):Z=e[57];let se;e[58]===Symbol.for("react.memo_cache_sentinel")?(se=xe=>j(xe.target.value),e[58]=se):se=e[58];let ve;e[59]!==r?(ve=r("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=r,e[60]=ve):ve=e[60];let H;e[61]!==u||e[62]!==ve?(H=t.jsx(Xe,{value:u,onChange:se,placeholder:ve}),e[61]=u,e[62]=ve,e[63]=H):H=e[63];let te;e[64]!==Z||e[65]!==H?(te=t.jsxs("div",{className:"space-y-2",children:[Z,H]}),e[64]=Z,e[65]=H,e[66]=te):te=e[66];let re;e[67]!==r?(re=r("settings.skills.catalog.add.field.repository"),e[67]=r,e[68]=re):re=e[68];let pe;e[69]!==re?(pe=t.jsx("label",{className:"typography-ui-label text-foreground",children:re}),e[69]=re,e[70]=pe):pe=e[70];let Me;e[71]===Symbol.for("react.memo_cache_sentinel")?(Me=xe=>{h(xe.target.value),J({clearIdentity:!0})},e[71]=Me):Me=e[71];let Se;e[72]!==r?(Se=r("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[72]=r,e[73]=Se):Se=e[73];let Ae;e[74]!==g||e[75]!==Se?(Ae=t.jsx(Xe,{value:g,onChange:Me,placeholder:Se}),e[74]=g,e[75]=Se,e[76]=Ae):Ae=e[76];let De;e[77]!==r?(De=r("settings.skills.catalog.add.field.repositoryHint"),e[77]=r,e[78]=De):De=e[78];let Pe;e[79]!==De?(Pe=t.jsx("p",{className:"typography-micro text-muted-foreground",children:De}),e[79]=De,e[80]=Pe):Pe=e[80];let Oe;e[81]!==pe||e[82]!==Ae||e[83]!==Pe?(Oe=t.jsxs("div",{className:"space-y-2",children:[pe,Ae,Pe]}),e[81]=pe,e[82]=Ae,e[83]=Pe,e[84]=Oe):Oe=e[84];let Te;e[85]!==r?(Te=r("settings.skills.catalog.add.field.optionalSubpath"),e[85]=r,e[86]=Te):Te=e[86];let Ue;e[87]!==Te?(Ue=t.jsx("label",{className:"typography-ui-label text-foreground",children:Te}),e[87]=Te,e[88]=Ue):Ue=e[88];let Be;e[89]===Symbol.for("react.memo_cache_sentinel")?(Be=xe=>{A(xe.target.value),J({clearIdentity:!0})},e[89]=Be):Be=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 Je;e[92]!==x||e[93]!==Ke?(Je=t.jsx(Xe,{value:x,onChange:Be,placeholder:Ke}),e[92]=x,e[93]=Ke,e[94]=Je):Je=e[94];let ue;e[95]!==Ue||e[96]!==Je?(ue=t.jsxs("div",{className:"space-y-2",children:[Ue,Je]}),e[95]=Ue,e[96]=Je,e[97]=ue):ue=e[97];let Y;e[98]!==I||e[99]!==U||e[100]!==r?(Y=U.length>0&&!fs()?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(Dt,{value:I||"",onValueChange:xe=>{P(xe),J()},children:[t.jsx(Et,{className:"w-fit",children:t.jsx("span",{children:U.find(xe=>xe.id===I)?.name||r("settings.skills.catalog.shared.auth.chooseIdentity")})}),t.jsx(Mt,{align:"start",children:U.map(df)})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:r("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[98]=I,e[99]=U,e[100]=r,e[101]=Y):Y=e[101];let de;e[102]!==k||e[103]!==r?(de=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]=de):de=e[104];let je;e[105]!==O||e[106]!==r?(je=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]=je):je=e[107];let Re;e[108]!==te||e[109]!==Oe||e[110]!==ue||e[111]!==Y||e[112]!==de||e[113]!==je?(Re=t.jsxs("div",{className:"space-y-4",children:[te,Oe,ue,Y,de,je]}),e[108]=te,e[109]=Oe,e[110]=ue,e[111]=Y,e[112]=de,e[113]=je,e[114]=Re):Re=e[114];let Ie;e[115]!==a?(Ie=()=>a(!1),e[115]=a,e[116]=Ie):Ie=e[116];let Ve;e[117]!==r?(Ve=r("settings.common.actions.cancel"),e[117]=r,e[118]=Ve):Ve=e[118];let X;e[119]!==Ie||e[120]!==Ve?(X=t.jsx(G,{size:"sm",variant:"ghost",onClick:Ie,children:Ve}),e[119]=Ie,e[120]=Ve,e[121]=X):X=e[121];let b;e[122]!==$?(b=()=>{$()},e[122]=$,e[123]=b):b=e[123];let be;e[124]!==f||e[125]!==g?(be=f||!g.trim(),e[124]=f,e[125]=g,e[126]=be):be=e[126];let Ee;e[127]===Symbol.for("react.memo_cache_sentinel")?(Ee=t.jsx(D,{name:"git-repository",className:"h-4 w-4"}),e[127]=Ee):Ee=e[127];let ze;e[128]!==f||e[129]!==r?(ze=r(f?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[128]=f,e[129]=r,e[130]=ze):ze=e[130];let qe;e[131]!==b||e[132]!==be||e[133]!==ze?(qe=t.jsxs(G,{size:"sm",className:"gap-2",variant:"ghost",onClick:b,disabled:be,children:[Ee,ze]}),e[131]=b,e[132]=be,e[133]=ze,e[134]=qe):qe=e[134];let rt;e[135]!==le?(rt=()=>{le()},e[135]=le,e[136]=rt):rt=e[136];let lt;e[137]!==O||e[138]!==u||e[139]!==v||e[140]!==g?(lt=!v||O||!u.trim()||!g.trim(),e[137]=O,e[138]=u,e[139]=v,e[140]=g,e[141]=lt):lt=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 ct;e[144]!==rt||e[145]!==lt||e[146]!==at?(ct=t.jsx(G,{size:"sm",onClick:rt,disabled:lt,children:at}),e[144]=rt,e[145]=lt,e[146]=at,e[147]=ct):ct=e[147];let Ye;e[148]!==X||e[149]!==qe||e[150]!==ct?(Ye=t.jsxs(Jt,{children:[X,qe,ct]}),e[148]=X,e[149]=qe,e[150]=ct,e[151]=Ye):Ye=e[151];let _e;e[152]!==we||e[153]!==Re||e[154]!==Ye?(_e=t.jsxs(Ft,{className:"max-w-xl",children:[we,Re,Ye]}),e[152]=we,e[153]=Re,e[154]=Ye,e[155]=_e):_e=e[155];let ft;return e[156]!==a||e[157]!==n||e[158]!==_e?(ft=t.jsx(Lt,{open:n,onOpenChange:a,children:_e}),e[156]=a,e[157]=n,e[158]=_e,e[159]=ft):ft=e[159],ft};function sf(s){return s.scanRepo}function nf(s){return s.loadCatalog}function af(s){return s.loadSource}function rf(s){return s.setSelectedSource}function of(s){return s.isScanning}function lf(s){return s.defaultGitIdentityId}function cf(s){return s.loadDefaultGitIdentityId}function df(s){return t.jsx(mt,{value:s.id,children:s.name},s.id)}const uf=s=>{const e=Ze.c(85),{open:n,onOpenChange:a,conflicts:r,onConfirm:i}=s,{t:l}=st();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];const[c,f]=o.useState(d);let m,p;e[1]!==r||e[2]!==n?(m=()=>{if(!n)return;const le={};for(const ne of r)le[ne.skillName]="skip";f(le)},p=[n,r],e[1]=r,e[2]=n,e[3]=m,e[4]=p):(m=e[3],p=e[4]),o.useEffect(m,p);let u;e[5]!==r?(u=le=>{const ne={};for(const ye of r)ne[ye.skillName]=le;f(ne)},e[5]=r,e[6]=u):u=e[6];const j=u;let g;e[7]!==r||e[8]!==c?(g=r.length>0&&r.every(le=>c[le.skillName]),e[7]=r,e[8]=c,e[9]=g):g=e[9];const h=g;let x;e[10]!==l?(x=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=x):x=e[11];let A;e[12]!==x?(A=t.jsx(Ut,{children:x}),e[12]=x,e[13]=A):A=e[13];let S;e[14]!==l?(S=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=S):S=e[15];let C;e[16]!==S?(C=t.jsx(_t,{children:S}),e[16]=S,e[17]=C):C=e[17];let R;e[18]!==A||e[19]!==C?(R=t.jsxs(Kt,{children:[A,C]}),e[18]=A,e[19]=C,e[20]=R):R=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 y;e[24]!==k?(y=t.jsx("span",{className:"typography-meta text-muted-foreground",children:k}),e[24]=k,e[25]=y):y=e[25];let v;e[26]!==j?(v=()=>j("skip"),e[26]=j,e[27]=v):v=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]!==v||e[31]!==E?(K=t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:v,children:E}),e[30]=v,e[31]=E,e[32]=K):K=e[32];let U;e[33]!==j?(U=()=>j("overwrite"),e[33]=j,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 I;e[37]!==U||e[38]!==M?(I=t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:U,children:M}),e[37]=U,e[38]=M,e[39]=I):I=e[39];let P;e[40]!==K||e[41]!==I?(P=t.jsxs("div",{className:"flex items-center gap-2",children:[K,I]}),e[40]=K,e[41]=I,e[42]=P):P=e[42];let z;e[43]!==y||e[44]!==P?(z=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[y,P]}),e[43]=y,e[44]=P,e[45]=z):z=e[45];let T;if(e[46]!==r||e[47]!==c||e[48]!==l){let le;e[50]!==c||e[51]!==l?(le=ne=>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:ne.skillName}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:ne.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:ne.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),t.jsxs(Dt,{value:c[ne.skillName]||"skip",onValueChange:ye=>f(ae=>({...ae,[ne.skillName]:ye})),children:[t.jsx(Et,{className:"w-fit",children:t.jsx("span",{className:"capitalize",children:(c[ne.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),t.jsxs(Mt,{align:"end",children:[t.jsx(mt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),t.jsx(mt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},ne.skillName),e[50]=c,e[51]=l,e[52]=le):le=e[52],T=r.map(le),e[46]=r,e[47]=c,e[48]=l,e[49]=T}else T=e[49];let J;e[53]!==T?(J=t.jsx("div",{className:"space-y-2",children:T}),e[53]=T,e[54]=J):J=e[54];let _;e[55]!==z||e[56]!==J?(_=t.jsxs("div",{className:"space-y-3",children:[z,J]}),e[55]=z,e[56]=J,e[57]=_):_=e[57];let ee;e[58]!==a?(ee=()=>a(!1),e[58]=a,e[59]=ee):ee=e[59];let Q;e[60]!==l?(Q=l("settings.common.actions.cancel"),e[60]=l,e[61]=Q):Q=e[61];let N;e[62]!==ee||e[63]!==Q?(N=t.jsx(G,{size:"sm",variant:"ghost",onClick:ee,children:Q}),e[62]=ee,e[63]=Q,e[64]=N):N=e[64];let V;e[65]!==c||e[66]!==i?(V=()=>i(c),e[65]=c,e[66]=i,e[67]=V):V=e[67];const B=!h;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]!==V||e[71]!==B||e[72]!==F?(O=t.jsx(G,{size:"sm",onClick:V,disabled:B,children:F}),e[70]=V,e[71]=B,e[72]=F,e[73]=O):O=e[73];let q;e[74]!==N||e[75]!==O?(q=t.jsxs(Jt,{children:[N,O]}),e[74]=N,e[75]=O,e[76]=q):q=e[76];let $;e[77]!==R||e[78]!==_||e[79]!==q?($=t.jsxs(Ft,{className:"max-w-2xl",children:[R,_,q]}),e[77]=R,e[78]=_,e[79]=q,e[80]=$):$=e[80];let ie;return e[81]!==a||e[82]!==n||e[83]!==$?(ie=t.jsx(Lt,{open:n,onOpenChange:a,children:$}),e[81]=a,e[82]=n,e[83]=$,e[84]=ie):ie=e[84],ie},Ii=[{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 ba(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 Pc(s){if(s==="user-claude")return{scope:"user",source:"claude"};if(s==="project-claude")return{scope:"project",source:"claude"};const e=Ii.find(n=>n.value===s);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const mf=s=>{const e=Ze.c(124),{open:n,onOpenChange:a,item:r}=s,{t:i}=st(),l=sn(pf),d=sn(gf),[c,f]=o.useState("user"),[m,p]=o.useState("opencode"),u=ss(hf),j=ss(ff),[g,h]=o.useState(null),[x,A]=o.useState(!1);let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[0]=S):S=e[0];const[C,R]=o.useState(S),[k,y]=o.useState(null);let v,E;e[1]!==j||e[2]!==n?(v=()=>{n&&(f("user"),p("opencode"),h(j),A(!1),R([]),y(null))},E=[n,j],e[1]=j,e[2]=n,e[3]=v,e[4]=E):(v=e[3],E=e[4]),o.useEffect(v,E);let K;e[5]!==i?(K=ue=>{switch(ue){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=ue=>{switch(ue){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 I=M;let P;e:{if(u.length===0){P=null;break e}if(g&&u.some(ue=>ue.id===g)){P=g;break e}if(j&&u.some(ue=>ue.id===j)){P=j;break e}P=u[0]?.id??null}const z=P;let T;e:{if(c!=="project"){T=null;break e}const ue=z;if(!ue){T=null;break e}let Y;if(e[9]!==ue||e[10]!==u){let je;e[12]!==ue?(je=Re=>Re.id===ue,e[12]=ue,e[13]=je):je=e[13],Y=u.find(je),e[9]=ue,e[10]=u,e[11]=Y}else Y=e[11];T=Y?.path??null}const J=T;let _;e[14]!==l||e[15]!==r||e[16]!==a||e[17]!==i?(_=async ue=>{const Y={skillDir:ue.skillDir};r?.clawdhub&&(Y.clawdhub={slug:r.clawdhub.slug,version:r.clawdhub.version});const de=await l({source:ue.source,subpath:ue.subpath,gitIdentityId:r?.gitIdentityId,scope:ue.scope,targetSource:ue.targetSource,selections:[Y],conflictPolicy:"prompt",conflictDecisions:ue.conflictDecisions},{directory:ue.directoryOverride??null});if(de.ok){W.success(i("settings.skills.catalog.installSkill.toast.installed")),a(!1);return}if(de.error?.kind==="conflicts"){y({source:ue.source,subpath:ue.subpath,scope:ue.scope,targetSource:ue.targetSource,skillDir:ue.skillDir,directoryOverride:ue.directoryOverride??null}),R(de.error.conflicts),A(!0);return}if(de.error?.kind==="authRequired"){W.error(de.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}W.error(de.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=r,e[16]=a,e[17]=i,e[18]=_):_=e[18];const ee=_;if(!r)return null;let Q;e[19]!==i?(Q=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=Q):Q=e[20];let N;e[21]!==Q?(N=t.jsx(Ut,{children:Q}),e[21]=Q,e[22]=N):N=e[22];let V;e[23]!==i?(V=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=V):V=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]!==V||e[30]!==B||e[31]!==F?(O=t.jsxs(_t,{children:[V," ",B," ",F]}),e[29]=V,e[30]=B,e[31]=F,e[32]=O):O=e[32];let q;e[33]!==N||e[34]!==O?(q=t.jsxs(Kt,{children:[N,O]}),e[33]=N,e[34]=O,e[35]=q):q=e[35];let $;e[36]!==i?($=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=$):$=e[37];let ie;e[38]!==$?(ie=t.jsx("span",{className:"typography-ui-label text-foreground",children:$}),e[38]=$,e[39]=ie):ie=e[39];let le;e[40]!==c||e[41]!==m?(le=ba(c,m),e[40]=c,e[41]=m,e[42]=le):le=e[42];let ne;e[43]===Symbol.for("react.memo_cache_sentinel")?(ne=ue=>{const Y=Pc(ue);f(Y.scope),p(Y.source==="agents"?"agents":"opencode")},e[43]=ne):ne=e[43];let ye;e[44]!==c?(ye=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]=ye):ye=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 ge;e[48]!==U||e[49]!==c||e[50]!==m?(ge=U(ba(c,m)),e[48]=U,e[49]=c,e[50]=m,e[51]=ge):ge=e[51];let Ne;e[52]!==ge?(Ne=t.jsx("span",{children:ge}),e[52]=ge,e[53]=Ne):Ne=e[53];let he;e[54]!==ye||e[55]!==ae||e[56]!==Ne?(he=t.jsxs(Et,{className:"w-fit gap-1.5",children:[ye,ae,Ne]}),e[54]=ye,e[55]=ae,e[56]=Ne,e[57]=he):he=e[57];let we;e[58]!==I||e[59]!==U?(we=Ii.map(ue=>t.jsx(mt,{value:ue.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:[ue.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"}),ue.source==="agents"?t.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:U(ue.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:I(ue.value)})]})},ue.value)),e[58]=I,e[59]=U,e[60]=we):we=e[60];let ce;e[61]!==we?(ce=t.jsx(Mt,{align:"start",children:we}),e[61]=we,e[62]=ce):ce=e[62];let Z;e[63]!==le||e[64]!==he||e[65]!==ce?(Z=t.jsxs(Dt,{value:le,onValueChange:ne,children:[he,ce]}),e[63]=le,e[64]=he,e[65]=ce,e[66]=Z):Z=e[66];let se;e[67]!==ie||e[68]!==Z?(se=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ie,Z]}),e[67]=ie,e[68]=Z,e[69]=se):se=e[69];let ve;e[70]!==u||e[71]!==z||e[72]!==c||e[73]!==i?(ve=c==="project"&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),u.length===0?t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):t.jsxs(Dt,{value:z??"",onValueChange:ue=>h(ue),disabled:u.length===1,children:[t.jsx(Et,{className:"w-fit",children:t.jsx(zt,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),t.jsx(Mt,{align:"start",children:u.map(xf)})]})]}),e[70]=u,e[71]=z,e[72]=c,e[73]=i,e[74]=ve):ve=e[74];let H;e[75]!==r.warnings?(H=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]=H):H=e[76];let te;e[77]!==se||e[78]!==ve||e[79]!==H?(te=t.jsxs("div",{className:"mt-2 space-y-3",children:[se,ve,H]}),e[77]=se,e[78]=ve,e[79]=H,e[80]=te):te=e[80];let re;e[81]!==a?(re=()=>a(!1),e[81]=a,e[82]=re):re=e[82];let pe;e[83]!==i?(pe=i("settings.common.actions.cancel"),e[83]=i,e[84]=pe):pe=e[84];let Me;e[85]!==re||e[86]!==pe?(Me=t.jsx(G,{size:"sm",variant:"ghost",onClick:re,children:pe}),e[85]=re,e[86]=pe,e[87]=Me):Me=e[87];const Se=d||!r.installable||c==="project"&&!J;let Ae;e[88]!==J||e[89]!==ee||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==m?(Ae=()=>{ee({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:m,skillDir:r.skillDir,directoryOverride:J})},e[88]=J,e[89]=ee,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=m,e[95]=Ae):Ae=e[95];let De;e[96]!==d||e[97]!==i?(De=i(d?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=d,e[97]=i,e[98]=De):De=e[98];let Pe;e[99]!==Se||e[100]!==Ae||e[101]!==De?(Pe=t.jsx(G,{size:"sm",disabled:Se,onClick:Ae,children:De}),e[99]=Se,e[100]=Ae,e[101]=De,e[102]=Pe):Pe=e[102];let Oe;e[103]!==Me||e[104]!==Pe?(Oe=t.jsxs(Jt,{children:[Me,Pe]}),e[103]=Me,e[104]=Pe,e[105]=Oe):Oe=e[105];let Te;e[106]!==q||e[107]!==te||e[108]!==Oe?(Te=t.jsxs(Ft,{className:"max-w-md",children:[q,te,Oe]}),e[106]=q,e[107]=te,e[108]=Oe,e[109]=Te):Te=e[109];let Ue;e[110]!==a||e[111]!==n||e[112]!==Te?(Ue=t.jsx(Lt,{open:n,onOpenChange:a,children:Te}),e[110]=a,e[111]=n,e[112]=Te,e[113]=Ue):Ue=e[113];let Be;e[114]!==k||e[115]!==ee?(Be=ue=>{k&&(ee({source:k.source,subpath:k.subpath,scope:k.scope,targetSource:k.targetSource,skillDir:k.skillDir,conflictDecisions:ue,directoryOverride:k.directoryOverride??null}),A(!1))},e[114]=k,e[115]=ee,e[116]=Be):Be=e[116];let Ke;e[117]!==C||e[118]!==x||e[119]!==Be?(Ke=t.jsx(uf,{open:x,onOpenChange:A,conflicts:C,onConfirm:Be}),e[117]=C,e[118]=x,e[119]=Be,e[120]=Ke):Ke=e[120];let Je;return e[121]!==Ue||e[122]!==Ke?(Je=t.jsxs(t.Fragment,{children:[Ue,Ke]}),e[121]=Ue,e[122]=Ke,e[123]=Je):Je=e[123],Je};function pf(s){return s.installSkills}function gf(s){return s.isInstalling}function hf(s){return s.projects}function ff(s){return s.activeProjectId}function xf(s){return t.jsx(mt,{value:s.id,children:s.label||s.path},s.id)}const yf=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}},bf=({mode:s,onModeChange:e,showModeTabs:n=!0})=>{const{t:a}=st(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:d,loadCatalog:c,loadSource:f,loadMoreClawdHub:m,isLoadingCatalog:p,isLoadingSource:u,isLoadingMore:j,loadedSourceIds:g,clawdhubHasMoreBySource:h,lastCatalogError:x}=sn(Es(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}))),[A,S]=o.useState(""),[C,R]=o.useState(!1),[k,y]=o.useState(!1),[v,E]=o.useState(null),[K,U]=o.useState(!1),[M,I]=o.useState(!1);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{l&&(g[l]||f(l))},[l,g,f]);const P=o.useMemo(()=>l?i[l]||[]:[],[i,l]),z=o.useMemo(()=>{const N=A.trim().toLowerCase();return N?P.filter(V=>{const B=V.skillName.toLowerCase(),F=(V.description||"").toLowerCase(),O=(V.frontmatterName||"").toLowerCase();return B.includes(N)||F.includes(N)||O.includes(N)}):P},[P,A]),T=o.useMemo(()=>r.find(N=>N.id===l)||null,[r,l]),J=!!(l&&l.startsWith("custom:")),_=T?.source==="clawdhub:registry"||T?.sourceType==="clawdhub",ee=!!(l&&(h[l]??!0)),Q=async()=>{if(!(!l||!J)){U(!0);try{const N=await yf(),B=(Array.isArray(N?.skillCatalogs)?N?.skillCatalogs:[]).filter(F=>F.id!==l);await kt({skillCatalogs:B}),await c({refresh:!0}),I(!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(Ln,{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(Dt,{value:l||"",onValueChange:N=>d(N),children:[t.jsx(Et,{className:"w-fit",children:t.jsx(zt,{placeholder:a("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:T?.label})}),t.jsx(Mt,{align:"start",children:r.map(N=>t.jsx(mt,{value:N.id,children:N.label},N.id))})]}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l?f(l,{refresh:!0}):c({refresh:!0})},disabled:p||u,title:a("settings.skills.catalog.page.actions.refreshTitle"),children:t.jsx(D,{name:"refresh",className:oe("h-3.5 w-3.5",(p||u)&&"animate-spin")})}),J&&t.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>I(!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(G,{"data-settings-item":"skills.catalog.add-catalog",size:"xs",className:"!font-normal gap-1",onClick:()=>R(!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:A,onChange:N=>S(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:p?a("settings.skills.catalog.page.loading.catalog"):a("settings.skills.catalog.page.foundCount",{count:z.length})})]})]})]}),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("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:x.message})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("section",{className:"px-2 pb-2 pt-0",children:z.length===0&&!u?t.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[t.jsx("p",{className:"typography-body",children:a("settings.skills.catalog.page.empty.noSkillsTitle")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.skills.catalog.page.empty.noSkillsDescription")})]}):u?t.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[t.jsx(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 V=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}),V&&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(G,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!N.installable,onClick:()=>{E(N),y(!0)},children:a("settings.skills.catalog.shared.actions.install")})]})},`${N.sourceId}:${N.skillDir}`)})})}),_&&ee&&!u&&z.length>0&&t.jsx("div",{className:"flex justify-center mt-2 px-2",children:t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:j,children:a(j?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),t.jsx(tf,{open:C,onOpenChange:R}),t.jsx(mf,{open:k,onOpenChange:y,item:v}),t.jsx(Lt,{open:M,onOpenChange:N=>{K||I(N)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:a("settings.skills.catalog.page.removeDialog.title")}),t.jsx(_t,{children:a("settings.skills.catalog.page.removeDialog.description")})]}),t.jsxs(Jt,{children:[t.jsx(G,{size:"sm",variant:"ghost",onClick:()=>I(!1),disabled:K,children:a("settings.common.actions.cancel")}),t.jsx(G,{size:"sm",variant:"destructive",onClick:()=>{Q()},disabled:K,children:a("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})};function tl(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=Hs.theme({"&":{backgroundColor:"var(--background)",color:s.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:a,backgroundColor:"var(--background)"},".cm-comment":{color:s.colors.syntax.base.comment},".cm-keyword":{color:s.colors.syntax.base.keyword},".cm-string":{color:s.colors.syntax.base.string},".cm-string-2":{color:i.stringEscape||s.colors.syntax.base.string},".cm-number":{color:s.colors.syntax.base.number},".cm-operator":{color:s.colors.syntax.base.operator},".cm-punctuation":{color:i.punctuation||s.colors.syntax.base.comment},".cm-atom":{color:i.boolean||s.colors.syntax.base.number},".cm-builtin":{color:i.functionCall||s.colors.syntax.base.function},".cm-def":{color:i.variableGlobal||s.colors.syntax.base.variable},".cm-attribute":{color:i.variableOther||i.variableProperty||s.colors.syntax.base.operator},".cm-meta":{color:s.colors.syntax.base.comment},".cm-property":{color:i.variableProperty||s.colors.syntax.base.keyword},".cm-variable":{color:s.colors.syntax.base.variable},".cm-variable-2":{color:i.variableOther||s.colors.syntax.base.function},".cm-variable-3":{color:i.variableGlobal||s.colors.syntax.base.type},".cm-tag":{color:i.tag||s.colors.syntax.base.keyword},".cm-link":{color:i.url||s.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:s.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:s.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:s.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||s.colors.syntax.base.comment,borderRight:`1px solid ${s.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||s.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:s.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:s.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${s.colors.interactive.border}`,backgroundColor:s.colors.surface.elevated,color:s.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${s.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${s.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${s.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:s.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${s.colors.interactive.border}`,backgroundColor:s.colors.surface.background,color:s.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:s.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:s.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:s.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:s.colors.interactive.hover,borderColor:s.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:s.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:s.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:s.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:s.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:s.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:s.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:s.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:s.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${s.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:s.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:s.colors.interactive.hover,color:s.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:s.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${s.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:s.colors.interactive.selection,color:s.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${s.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:n}),d=Ui.define([{tag:[Le.comment,Le.docComment,Le.meta,Le.documentMeta],class:"cm-comment"},{tag:[Le.keyword,Le.controlKeyword,Le.moduleKeyword,Le.definitionKeyword,Le.modifier],class:"cm-keyword"},{tag:[Le.operatorKeyword,Le.operator,Le.derefOperator,Le.updateOperator,Le.definitionOperator,Le.typeOperator,Le.controlOperator,Le.logicOperator,Le.bitwiseOperator,Le.arithmeticOperator,Le.compareOperator],class:"cm-operator"},{tag:[Le.punctuation,Le.separator,Le.bracket,Le.paren,Le.brace,Le.squareBracket,Le.angleBracket],class:"cm-punctuation"},{tag:[Le.string,Le.regexp,Le.attributeValue,Le.special(Le.string),Le.monospace],class:"cm-string"},{tag:Le.escape,class:"cm-string-2"},{tag:[Le.number,Le.bool,Le.atom,Le.null,Le.self],class:"cm-number"},{tag:[Le.function(Le.variableName),Le.function(Le.definition(Le.variableName)),Le.function(Le.propertyName),Le.standard(Le.variableName),Le.special(Le.variableName)],class:"cm-builtin"},{tag:Le.definition(Le.variableName),class:"cm-def"},{tag:[Le.variableName,Le.local(Le.variableName),Le.constant(Le.variableName),Le.literal],class:"cm-variable"},{tag:Le.propertyName,class:"cm-property"},{tag:Le.attributeName,class:"cm-attribute"},{tag:[Le.className,Le.typeName,Le.namespace],class:"cm-variable-3"},{tag:[Le.tagName,Le.labelName,Le.annotation,Le.macroName],class:"cm-tag"},{tag:Le.link,class:"cm-link"},{tag:[Le.heading,Le.heading1,Le.heading2,Le.heading3,Le.heading4,Le.heading5,Le.heading6],class:"cm-keyword"}]),c=Ui.define([{tag:[Le.comment,Le.docComment,Le.meta,Le.documentMeta],color:s.colors.syntax.base.comment},{tag:[Le.keyword,Le.controlKeyword,Le.moduleKeyword,Le.definitionKeyword,Le.modifier],color:s.colors.syntax.base.keyword},{tag:[Le.operatorKeyword,Le.operator,Le.derefOperator,Le.updateOperator,Le.definitionOperator,Le.typeOperator,Le.controlOperator,Le.logicOperator,Le.bitwiseOperator,Le.arithmeticOperator,Le.compareOperator],color:s.colors.syntax.base.operator},{tag:[Le.string,Le.regexp,Le.attributeValue,Le.special(Le.string),Le.monospace],color:s.colors.syntax.base.string},{tag:Le.escape,color:i.stringEscape||s.colors.syntax.base.string},{tag:[Le.number,Le.bool,Le.atom,Le.null,Le.self],color:s.colors.syntax.base.number},{tag:[Le.function(Le.variableName),Le.function(Le.definition(Le.variableName)),Le.function(Le.propertyName),Le.standard(Le.variableName),Le.special(Le.variableName)],color:s.colors.syntax.base.function},{tag:Le.definition(Le.variableName),color:i.variableGlobal||s.colors.syntax.base.variable},{tag:[Le.variableName,Le.local(Le.variableName),Le.constant(Le.variableName),Le.literal],color:s.colors.syntax.base.variable},{tag:Le.propertyName,color:i.variableProperty||s.colors.syntax.base.variable},{tag:Le.attributeName,color:i.variableOther||s.colors.syntax.base.variable},{tag:[Le.className,Le.typeName,Le.namespace],color:s.colors.syntax.base.type},{tag:[Le.tagName,Le.labelName,Le.annotation,Le.macroName],color:i.tag||s.colors.syntax.base.keyword},{tag:Le.link,color:i.url||s.colors.syntax.base.function,textDecoration:"underline"},{tag:[Le.punctuation,Le.separator,Le.bracket,Le.paren,Le.brace,Le.squareBracket,Le.angleBracket],color:i.punctuation||s.colors.syntax.base.comment}]);return e?.syntaxColors===!1?[l]:[l,Da(Wd,{fallback:!0}),Da(qd),Da(d),Da(c)]}const vf=180,Ac=Gd.define(),jf=1,wf=2,Nf=4,sl=new Map,kf=(s,e)=>{const n=`${s}|${e}`,a=sl.get(n);if(a)return a;let r="";s&&(r+=`color:${s};`),e&jf&&(r+="font-style:italic;"),e&wf&&(r+="font-weight:bold;"),e&Nf&&(r+="text-decoration:underline;");const i=dr.mark({attributes:{style:r}});return sl.set(n,i),i},Sf=(s,e)=>{const n=new Ni,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 d=a.line(i+1);let c=d.from;for(const[f,m,p]of l){if(f<=0)continue;const u=c,j=Math.min(c+f,d.to);c+=f,!(j<=u)&&(!m&&!p||n.add(u,j,kf(m,p)))}}return n.finish()},Cf=ec.define({create(){return dr.none},update(s,e){let n=s.map(e.changes);for(const a of e.effects)a.is(Ac)&&(n=a.value);return n},provide:s=>Hs.decorations.from(s)}),If=s=>Zl.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)},vf)}async tokenize(e){const n=++this.generation,a=e.state.doc.toString(),r=await Cu(a,s.language,s.themeName,s.theme);r&&n===this.generation&&e.state.doc.length===a.length&&e.dispatch({effects:Ac.of(Sf(e,r))})}destroy(){this.timer&&clearTimeout(this.timer)}}),Pf=s=>[Cf,If(s)],Af=()=>{const s=Ze.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(bf,{mode:"external",onModeChange:Lf,showModeTabs:!1}),s[0]=e):e=s[0],e},Df="SKILL.md",Ef="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",tr=(s,e)=>{const n=Jd({description:s}).trimEnd(),a=e.trimStart();return`---
23
+ ${n}
24
+ ---${a?`
25
+
26
+ ${a}`:`
27
+ `}`},Mf=s=>typeof s=="object"&&s!==null&&!Array.isArray(s),Dc=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=Qd(e[1]);if(Mf(a)){const r=a.description;typeof r=="string"&&(n=r)}}catch{n=null}return{description:n,instructions:e[2].replace(/^\r?\n/,"")}},Tf=(s,e)=>{const n=Dc(s);return tr(e,n.instructions)},Rf=()=>{const{t:s}=st(),{currentTheme:e}=gr(),{selectedSkillName:n,getSkillByName:a,getSkillDetail:r,createSkill:i,updateSkill:l,skills:d,skillDraft:c,setSkillDraft:f,setSelectedSkill:m}=an(Es(ue=>({selectedSkillName:ue.selectedSkillName,getSkillByName:ue.getSkillByName,getSkillDetail:ue.getSkillDetail,createSkill:ue.createSkill,updateSkill:ue.updateSkill,skills:ue.skills,skillDraft:ue.skillDraft,setSkillDraft:ue.setSkillDraft,setSelectedSkill:ue.setSelectedSkill}))),p=n?a(n):null,u=!!(c&&c.name===n&&!p),j=!!(n&&!p&&!c),g=p?.path==="<built-in>";o.useEffect(()=>{j&&m(null)},[j,m]);const[h,x]=o.useState(""),[A,S]=o.useState("user"),[C,R]=o.useState("opencode"),[k,y]=o.useState(""),[v,E]=o.useState(""),[K,U]=o.useState(()=>tr("","")),[M,I]=o.useState("edit"),[P,z]=o.useState([]),[T,J]=o.useState([]),[_,ee]=o.useState(!1),[Q,N]=o.useState(!1),[V,B]=o.useState(""),[F,O]=o.useState(""),[q,$]=o.useState(!1),[ie,le]=o.useState(""),[ne,ye]=o.useState(""),[ae,ge]=o.useState(null),[Ne,he]=o.useState(!1),[we,ce]=o.useState(""),[Z,se]=o.useState(null),[ve,H]=o.useState(!1),te=u?h.trim()!==""||k.trim()!==""||v.trim()!==""||T.length>0:k!==V||v!==F,re=ae?ne!==we:ie.trim()!=="",pe=o.useCallback(ue=>{switch(ue){case"project-opencode":return s("settings.skills.location.option.projectOpencode.label");case"user-claude":return s("settings.skills.location.option.userClaude.label");case"project-claude":return s("settings.skills.location.option.projectClaude.label");case"user-agents":return s("settings.skills.location.option.userAgents.label");case"project-agents":return s("settings.skills.location.option.projectAgents.label");default:return s("settings.skills.location.option.userOpencode.label")}},[s]),Me=o.useCallback(ue=>{switch(ue){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(u&&c){const Y=c.description||"",de=c.instructions||"";x(c.name||""),S(c.scope||"user"),R(c.source==="agents"?"agents":"opencode"),y(Y),E(de),U(tr(Y,de)),B(""),O(""),z([]),J(c.pendingFiles||[])}else if(n&&p){N(!0);try{const Y=await r(n);if(Y){const de=Y.sources.md,je=de.description||"",Re=de.instructions||"";y(je),E(Re),U(tr(je,Re)),B(je),O(Re),z(de.supportingFiles||[])}}catch(Y){console.error("Failed to load skill details:",Y)}finally{N(!1)}}})()},[p,u,n,d,c,r]);const Se=o.useMemo(()=>{const ue=[tl(e)],Y=Bi(Df);return Y&&ue.push(Y),ue.push(Hs.lineWrapping),ue},[e]),Ae=o.useMemo(()=>{const ue=ie.trim()||"supporting-file.md",Y=Iu(ue),de=!!Y&&Y!=="markdown",je=[tl(e,de?{syntaxColors:!1}:void 0)],Re=Bi(ue);return Re&&je.push(Re),de&&Y&&je.push(Pf({language:Y,themeName:e.metadata.id,theme:si(e)})),je.push(Hs.lineWrapping),je},[e,ie]),De=o.useCallback(ue=>{y(ue),U(Y=>Tf(Y,ue))},[]),Pe=o.useCallback(ue=>{U(ue);const Y=Dc(ue);y(Y.description??""),E(Y.instructions)},[]),Oe=async()=>{const ue=u?h.trim().replace(/\s+/g,"-").toLowerCase():n?.trim();if(!ue){W.error(s("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ue)||ue.length>64){W.error(s("settings.skills.page.toast.invalidSkillName"));return}if(!k.trim()){W.error(s("settings.skills.page.toast.descriptionRequired"));return}if(u&&d.some(Y=>Y.name===ue)){W.error(s("settings.skills.page.toast.skillExists"));return}ee(!0);try{const Y={name:ue,description:k.trim(),instructions:v.trim()||void 0,scope:u?A:void 0,source:u?C:void 0,targetPath:u?void 0:p?.path,supportingFiles:u&&T.length>0?T:void 0};let de;u?(de=await i(Y),de&&(f(null),J([]),m(ue))):(de=await l(ue,Y),de&&(B(k.trim()),O(v.trim()))),de?W.success(s(u?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):W.error(s(u?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Y){console.error("Error saving skill:",Y),W.error(s("settings.skills.page.toast.saveUnexpectedError"))}finally{ee(!1)}},Te=()=>{ge(null),le(""),ye(""),ce(""),$(!0)},Ue=async ue=>{if(ge(ue),le(ue),u){const de=T.find(je=>je.path===ue)?.content||"";ye(de),ce(de),$(!0);return}if(n){he(!0),$(!0);try{const{readSupportingFile:Y}=an.getState(),de=await Y(n,ue);ye(de||""),ce(de||"")}catch{W.error(s("settings.skills.page.toast.loadFileContentFailed")),ye(""),ce("")}finally{he(!1)}}},Be=async()=>{if(!ie.trim()){W.error(s("settings.skills.page.toast.fileNameRequired"));return}const ue=ie.trim(),Y=ae!==null;if(u){if(Y)J(Re=>Re.map(Ie=>Ie.path===ae?{path:ue,content:ne}:Ie)),W.success(s("settings.skills.page.toast.fileUpdated",{path:ue}));else{if(T.some(Re=>Re.path===ue)){W.error(s("settings.skills.page.toast.fileExists"));return}J(Re=>[...Re,{path:ue,content:ne}]),W.success(s("settings.skills.page.toast.fileAdded",{path:ue}))}$(!1),ge(null);return}if(!n){W.error(s("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:de}=an.getState();if(await de(n,ue,ne)){W.success(Y?s("settings.skills.page.toast.fileUpdated",{path:ue}):s("settings.skills.page.toast.fileCreated",{path:ue})),$(!1),ge(null);const Re=await r(n);Re&&z(Re.sources.md.supportingFiles||[])}else W.error(s(Y?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ke=ue=>{if(u){J(Y=>Y.filter(de=>de.path!==ue)),W.success(s("settings.skills.page.toast.fileRemoved",{path:ue}));return}n&&se(ue)},Je=async()=>{if(!Z||!n)return;H(!0);const{deleteSupportingFile:ue}=an.getState();if(await ue(n,Z)){W.success(s("settings.skills.page.toast.fileDeleted",{path:Z}));const de=await r(n);de&&z(de.sources.md.supportingFiles||[]),se(null)}else W.error(s("settings.skills.page.toast.deleteFileFailed"));H(!1)};return!n&&!c||j?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")})]})}):Q?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:u?s("settings.skills.page.title.newSkill"):n}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:p?s("settings.skills.page.subtitle.skillLocation",{location:pe(ba(p.scope,p.source))}):s("settings.skills.page.subtitle.newSkill")})]})}),t.jsxs("div",{"data-settings-item":"skills.basic-information",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.skills.page.section.basicInformation")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[u&&t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.skills.page.field.skillNameLocation")}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:s("settings.skills.page.field.skillNameHint")}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[t.jsx(Xe,{value:h,onChange:ue=>x(ue.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:s("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),t.jsxs(Dt,{value:ba(A,C),onValueChange:ue=>{const Y=Pc(ue);S(Y.scope),R(Y.source==="agents"?"agents":"opencode")},children:[t.jsxs(Et,{className:"w-fit gap-1.5",children:[A==="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:pe(ba(A,C))})]}),t.jsx(Mt,{align:"start",children:Ii.map(ue=>t.jsx(mt,{value:ue.value,children:t.jsxs("div",{className:"flex flex-col gap-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[ue.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"}),ue.source==="agents"?t.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:pe(ue.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Me(ue.value)})]})},ue.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:ue=>De(ue.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:g})})]})]})]}),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(Yh,{currentMode:M==="preview"?"preview":"edit",onToggle:()=>I(ue=>ue==="preview"?"edit":"preview")})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx("div",{className:oe("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Ef),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(ti,{content:K,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):t.jsx(el,{value:K,onChange:Pe,readOnly:g,extensions:Se,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(G,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Te,disabled:g,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 ue=u?T:P;return ue.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:ue.map(Y=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Ue(Y.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:Y.path}),u&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:s("settings.skills.page.badge.pending")}),!g&&t.jsx(G,{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:de=>{de.stopPropagation(),Ke(Y.path)},children:t.jsx(D,{name:"delete-bin",className:"h-3 w-3"})})]},Y.path))})})()})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(G,{onClick:Oe,disabled:g||_||!te,size:"xs",className:"!font-normal",children:s(_?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),t.jsx(Lt,{open:Z!==null,onOpenChange:ue=>{!ue&&!ve&&se(null)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("settings.skills.page.deleteFileDialog.title")}),t.jsx(_t,{children:s("settings.skills.page.deleteFileDialog.description",{path:Z??""})})]}),t.jsxs(Jt,{children:[t.jsx(G,{size:"sm",variant:"ghost",onClick:()=>se(null),disabled:ve,children:s("settings.common.actions.cancel")}),t.jsx(G,{size:"sm",variant:"destructive",onClick:Je,disabled:ve,children:s("settings.common.actions.delete")})]})]})}),t.jsx(Lt,{open:q,onOpenChange:ue=>{$(ue),ue||ge(null)},children:t.jsxs(Ft,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[t.jsxs(Kt,{className:"flex-shrink-0",children:[t.jsx(Ut,{children:s(ae?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),t.jsx(_t,{children:s(ae?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),Ne?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:ue=>le(ue.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(el,{value:ne,onChange:ye,extensions:Ae,className:"h-full",enableSearch:!0})})]})]}),t.jsxs(Jt,{className:"mt-4",children:[t.jsx(G,{size:"sm",variant:"ghost",onClick:()=>{$(!1),ge(null)},children:s("settings.common.actions.cancel")}),t.jsx(G,{size:"sm",onClick:Be,disabled:Ne||!re,children:s(ae?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},nl=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(Af,{}):t.jsx(Rf,{}),e[0]=a,e[1]=r):r=e[1],r};function Lf(){}const Ff=s=>{const e=Ze.c(38),{onItemSelect:n}=s,{t:a}=st(),r=ss(Of),i=Fe(zf),l=Fe(Uf),{currentTheme:d}=gr();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=fs(),e[0]=c):c=e[0];const f=c,m=Kf;let p,u;e[1]!==r||e[2]!==i||e[3]!==l?(p=()=>{if(r.length===0){i!==null&&l(null);return}i&&r.some(v=>v.id===i)||l(r[0].id)},u=[r,i,l],e[1]=r,e[2]=i,e[3]=l,e[4]=p,e[5]=u):(p=e[4],u=e[5]),o.useEffect(p,u);let j;e[6]===Symbol.for("react.memo_cache_sentinel")?(j=oe("border-b px-3","pt-4 pb-3"),e[6]=j):j=e[6];let g;e[7]!==a?(g=a("settings.page.projects.title"),e[7]=a,e[8]=g):g=e[8];let h;e[9]!==g?(h=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[9]=g,e[10]=h):h=e[10];let x;e[11]!==r.length||e[12]!==a?(x=a("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=a,e[13]=x):x=e[13];let A;e[14]!==x?(A=t.jsx("span",{className:"typography-meta text-muted-foreground",children:x}),e[14]=x,e[15]=A):A=e[15];let S;e[16]!==a?(S=!f&&t.jsx(G,{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]=S):S=e[17];let C;e[18]!==A||e[19]!==S?(C=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[A,S]}),e[18]=A,e[19]=S,e[20]=C):C=e[20];let R;e[21]!==C||e[22]!==h?(R=t.jsxs("div",{className:j,children:[h,C]}),e[21]=C,e[22]=h,e[23]=R):R=e[23];let k;if(e[24]!==d||e[25]!==n||e[26]!==r||e[27]!==i||e[28]!==l){let v;e[30]!==d||e[31]!==n||e[32]!==i||e[33]!==l?(v=E=>{const K=E.id===i,U=E.icon?Pu[E.icon]:null,M=E.color?oc[E.color]??null:null,I=U?t.jsx(D,{name:U,className:oe("h-4 w-4",K?"text-foreground":"text-muted-foreground/70"),style:M?{color:M}:void 0}):t.jsx(D,{name:"folder",className:oe("h-4 w-4",K?"text-foreground":"text-muted-foreground/70"),style:M?{color:M}:void 0}),P=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(lc,{project:E,options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:I})}):I;return t.jsx(pi,{title:E.label||E.path,icon:P,selected:K,onSelect:()=>{l(E.id),n?.()}},E.id)},e[30]=d,e[31]=n,e[32]=i,e[33]=l,e[34]=v):v=e[34],k=r.map(v),e[24]=d,e[25]=n,e[26]=r,e[27]=i,e[28]=l,e[29]=k}else k=e[29];let y;return e[35]!==R||e[36]!==k?(y=t.jsx(Cc,{variant:"background",header:R,children:k}),e[35]=R,e[36]=k,e[37]=y):y=e[37],y};function Of(s){return s.projects}function zf(s){return s.settingsProjectsSelectedId}function Uf(s){return s.setSettingsProjectsSelectedId}function Kf(){ic.requestDirectoryDialog()}const wa="w-full max-w-[30rem]",rn=s=>{const e=Ze.c(27),{title:n,description:a,settingsItem:r,titleAccessory:i,headerAction:l,children:d,className:c,contentClassName:f}=s;let m;e[0]!==c?(m=oe("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 p;e[2]!==n?(p=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:n}),e[2]=n,e[3]=p):p=e[3];let u;e[4]!==p||e[5]!==i?(u=t.jsxs("div",{className:"flex items-center gap-2",children:[p,i]}),e[4]=p,e[5]=i,e[6]=u):u=e[6];let j;e[7]!==a?(j=a?t.jsx("p",{className:"mt-0.5 typography-meta text-muted-foreground",children:a}):null,e[7]=a,e[8]=j):j=e[8];let g;e[9]!==u||e[10]!==j?(g=t.jsxs("div",{className:"min-w-0 flex-1",children:[u,j]}),e[9]=u,e[10]=j,e[11]=g):g=e[11];let h;e[12]!==l?(h=l?t.jsx("div",{className:"shrink-0",children:l}):null,e[12]=l,e[13]=h):h=e[13];let x;e[14]!==g||e[15]!==h?(x=t.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3 px-1",children:[g,h]}),e[14]=g,e[15]=h,e[16]=x):x=e[16];let A;e[17]!==f?(A=oe("space-y-2 px-2",f),e[17]=f,e[18]=A):A=e[18];let S;e[19]!==d||e[20]!==A?(S=t.jsx("div",{className:A,children:d}),e[19]=d,e[20]=A,e[21]=S):S=e[21];let C;return e[22]!==r||e[23]!==m||e[24]!==x||e[25]!==S?(C=t.jsxs("section",{"data-settings-item":r,className:m,children:[x,S]}),e[22]=r,e[23]=m,e[24]=x,e[25]=S,e[26]=C):C=e[26],C},Bf=450,$f=({projectRef:s=null})=>{const{t:e}=st(),{isMobile:n,isTablet:a}=Ms(),r=n||a,i=ss(B=>B.getActiveProject()),l=s?.path??i?.path??null,d=vs(B=>B.getWorktreeMetadata),c=Au(),f=Ns(B=>B.homeDirectory),[m,p]=o.useState([]),[u,j]=o.useState(!1),[g,h]=o.useState(!1),[x,A]=o.useState(null),[S,C]=o.useState(null),[R,k]=o.useState([]),[y,v]=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||S===!1))try{const B=await $i(K);k(B)}catch{}},[K,S]);o.useEffect(()=>{if(!l)return;let B=!1;return C(null),(async()=>{try{const F=await Du(l);if(B)return;C(F)}catch{}})(),()=>{B=!0}},[l]),o.useEffect(()=>{if(!K){k([]),v(!1);return}if(S===!1){k([]),v(!1);return}let B=!1;return v(!0),k([]),(async()=>{try{const F=await $i(K);if(B)return;k(F)}catch{}finally{B||v(!1)}})(),()=>{B=!0}},[K,S]),o.useEffect(()=>{if(!K)return;let B=!1;return h(!0),(async()=>{try{const[F,O]=await Promise.all([cc(K),dc(K)]);if(!B){const q=F.length>0?F:[""];p(q),A(JSON.stringify(q)),j(O)}}catch{B||(p([""]),A(JSON.stringify([""])),j(!1))}finally{B||h(!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 Eu(K,F)?(A(JSON.stringify(B)),!0):(W.error(e("settings.openchamber.worktrees.setup.toast.saveFailed")),!1)}catch{return W.error(e("settings.openchamber.worktrees.setup.toast.saveFailed")),!1}},[K,e]),I=o.useMemo(()=>x===null?!1:x!==JSON.stringify(m),[x,m]);o.useEffect(()=>{if(!I||g||E.current)return;const B=window.setTimeout(()=>{E.current||(E.current=!0,(async()=>{try{await M(m)}finally{E.current=!1}})())},Bf);return()=>{window.clearTimeout(B)}},[I,g,M,m]);const P=o.useCallback((B,F)=>{p(O=>{const q=[...O];return q[B]=F,q})},[]),z=o.useCallback(()=>{p(B=>[...B,""])},[]),T=o.useCallback(B=>{p(F=>{const O=F.filter((q,$)=>$!==B);return O.length>0?O:[""]})},[]),J=o.useCallback(()=>{!I||E.current||(E.current=!0,(async()=>{try{await M(m)}finally{E.current=!1}})())},[I,M,m]),_=o.useCallback(B=>{j(B),K&&Mu(K,B)},[K]),ee=o.useCallback(B=>{const F=ge=>ge.replace(/\\/g,"/").replace(/\/+$/,""),O=F(B.path),q=c.filter(ge=>{const Ne=d(ge.id);if(Ne?.path&&F(Ne.path)===O)return!0;const he=ge.directory;return!!(he&&F(he)===O)}),$=new Set(q.map(ge=>ge.id)),ie=[...ni.getState().activeSessions,...ni.getState().archivedSessions],le=ge=>{const Ne=ie.filter(we=>{const ce=we.parentID;return ce&&ge.has(ce)});if(Ne.length===0)return[];const he=new Set(Ne.map(we=>we.id));return[...Ne,...le(he)]},ne=le($),ye=new Set,ae=[...q,...ne].filter(ge=>ye.has(ge.id)?!1:(ye.add(ge.id),!0));ic.requestDelete({sessions:ae,mode:"worktree",worktree:B})},[c,d]),Q=o.useMemo(()=>c.map(B=>B.id).join(","),[c]);o.useEffect(()=>{S&&l&&U()},[Q,S,l,U]);const N=t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(Pt,{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")]})]}),V=t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]});return l?S===!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:g?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.setup.loading")}):t.jsxs("div",{className:oe("space-y-2",wa),children:[m.map((B,F)=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(Xe,{value:B,onChange:O=>P(F,O.target.value),onBlur:J,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(G,{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(bt,{checked:u,onChange:_,ariaLabel:e("settings.openchamber.worktrees.setup.waitForCommandsAria")}),t.jsx("span",{className:oe("typography-ui-label font-normal",u?"text-foreground":"text-foreground/60"),children:e("settings.openchamber.worktrees.setup.waitForCommands")})]})]})}),t.jsx(rn,{title:e("settings.openchamber.worktrees.list.title"),titleAccessory:V,children:y?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.list.loading")}):R.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:e("settings.openchamber.worktrees.list.empty")}):t.jsx("div",{className:oe("space-y-1",wa),children:R.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:Tu(B.path,f)})]}),t.jsx("button",{type:"button",onClick:()=>ee(B),className:oe("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")})})},al=(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([Ou(),_i()]),r={};for(const i of a.sort(al))r[i.id]=i;e().listenerReady||await zu(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 Fu();s({importCandidates:n,isImportsLoading:!1})}catch(n){s({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await _i(),a={};for(const r of n.sort(al))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 Vi(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 Ru(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 Vi(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})})),Ec=[{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"}],Vf=Object.fromEntries(Ec.map(s=>[s.key,s.Icon])),_f="openchamber:project-actions-updated",Hf=s=>{const e=(s||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},Jj=(s,e)=>`${Hf(s)}::${e}`,Wf=s=>{const e=s.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},rl=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=rl(e.localPort),a=rl(e.remotePort);if(!n||!a)return null;const r=Wf(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}`}},Mc=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},Qj=(s,e)=>{const n=(s||"").trim();return n&&Mc(e).find(i=>i.id===n)?.url||null},Gf=450,Jf=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,Qf=()=>({id:Jf(),name:"",command:"",icon:"play"}),Yf=({projectRef:s})=>{const{t:e}=st(),n=o.useMemo(()=>rs(),[]),a=us(y=>y.instances),r=us(y=>y.load),[i,l]=o.useState([]),[d,c]=o.useState(!1),[f,m]=o.useState(null),[p,u]=o.useState({}),j=o.useRef(!1),g=o.useRef(null);o.useEffect(()=>{n&&r().catch(()=>{})},[n,r]),o.useEffect(()=>{let y=!1;return c(!0),(async()=>{try{const v=await Ku(s);if(y)return;l(v.actions),m(JSON.stringify({actions:v.actions}))}catch{if(y)return;l([]),m(JSON.stringify({actions:[]}))}finally{y||c(!1)}})(),()=>{y=!0}},[s]);const h=o.useMemo(()=>n?Mc(a):[],[a,n]),x=o.useMemo(()=>i.some(v=>v.name.trim().length===0||v.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),A=o.useMemo(()=>f===null?!1:f!==JSON.stringify({actions:i}),[i,f]),S=o.useCallback(async y=>await Bu(s,{actions:y,primaryActionId:null})?(m(JSON.stringify({actions:y})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(_f,{detail:{projectId:s.id}})),!0):(W.error(e("settings.projects.actions.toast.saveFailed")),!1),[s,e]);o.useEffect(()=>{if(!A||d||x||j.current)return;const y=window.setTimeout(()=>{j.current||(j.current=!0,(async()=>{try{await S(i)}finally{j.current=!1}})())},Gf);return()=>{window.clearTimeout(y)}},[i,A,d,S,x]),o.useEffect(()=>{if(!A||!x||d){x||(g.current=null);return}const y=window.setTimeout(()=>{g.current!==x&&(g.current=x,W.error(x))},1e3);return()=>{window.clearTimeout(y)}},[A,d,x]);const C=o.useCallback(()=>{const y=Qf();l(v=>[...v,y]),u(v=>({...v,[y.id]:!0}))},[]),R=o.useCallback(y=>{l(v=>v.filter(E=>E.id!==y)),u(v=>{const E={...v};return delete E[y],E})},[]),k=o.useCallback((y,v)=>{l(E=>E.map(K=>K.id===y?v(K):K))},[]);return t.jsxs(rn,{title:e("settings.projects.actions.title"),description:e("settings.projects.actions.description"),settingsItem:"projects.actions",headerAction:t.jsxs(G,{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:[d?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:oe("space-y-0",wa),children:i.map(y=>{const v=y.icon||"play",E=Vf[v]||"play",K=p[y.id]??!1,U=y.name.trim()||e("settings.projects.actions.state.untitled");return t.jsxs(Mn,{open:K,onOpenChange:M=>{u(I=>({...I,[y.id]:M}))},className:"py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs(Tn,{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(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>R(y.id),children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(Rn,{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:Ec.map(M=>{const I=M.Icon,P=(y.icon||"play")===M.key;return t.jsx("button",{type:"button",onClick:()=>k(y.id,z=>({...z,icon:M.key})),className:oe("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",P&&"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:I,className:"h-4 w-4"})},M.key)})})})]}),t.jsx(Xe,{value:y.name,onChange:M=>k(y.id,I=>({...I,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:y.command,onChange:M=>k(y.id,I=>({...I,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":y.autoOpenUrl===!0,onClick:()=>k(y.id,M=>({...M,...M.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),k(y.id,I=>({...I,...I.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[t.jsx(bt,{checked:y.autoOpenUrl===!0,onChange:M=>k(y.id,I=>({...I,...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")})]})]}),y.autoOpenUrl===!0?t.jsxs("div",{className:"mt-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xe,{value:y.openUrl||"",onChange:M=>k(y.id,I=>({...I,openUrl:M.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),t.jsxs(Ct,{children:[t.jsx(It,{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(Pt,{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")}),h.length>0?t.jsxs(Dt,{value:y.desktopOpenSshForward&&h.some(M=>M.id===y.desktopOpenSshForward)?y.desktopOpenSshForward:"__none__",onValueChange:M=>{k(y.id,I=>({...I,...M==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:M}}))},children:[t.jsx(Et,{className:"h-7 w-full",children:t.jsx(zt,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),h.map(M=>t.jsx(mt,{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]})]})})]},y.id)})}),x&&i.length>0?t.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:x}):null]})},Xf=s=>{const e=Ze.c(122),{form:n}=s,{t:a}=st(),{currentTheme:r}=gr(),{name:i,setName:l,icon:d,setIcon:c,color:f,setColor:m,iconBackground:p,setIconBackground:u,parsedDefaultModel:j,handleDefaultModelChange:g,isUploadingIcon:h,isRemovingCustomIcon:x,isDiscoveringIcon:A,pendingRemoveImageIcon:S,setPendingRemoveImageIcon:C,pendingUploadIconPreviewUrl:R,setPreviewImageFailed:k,hasPendingUploadImageIcon:y,hasCustomIcon:v,effectiveHasImageIcon:E,hasRemovableImageIcon:K,showImagePreview:U,fileInputRef:M,handleUploadIcon:I,handleRemoveImageIcon:P,handleDiscoverIcon:z,currentIconImage:T,project:J}=n;if(!J)return null;const _=f?oc[f]??null:null;let ee;e[0]!==a?(ee=a("settings.projects.page.field.projectName"),e[0]=a,e[1]=ee):ee=e[1];let Q;e[2]!==l?(Q=de=>l(de.target.value),e[2]=l,e[3]=Q):Q=e[3];let N;e[4]!==a?(N=a("settings.projects.page.field.projectNamePlaceholder"),e[4]=a,e[5]=N):N=e[5];let V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=oe("h-7",wa),e[6]=V):V=e[6];let B;e[7]!==i||e[8]!==Q||e[9]!==N?(B=t.jsx(Xe,{value:i,onChange:Q,placeholder:N,className:V}),e[7]=i,e[8]=Q,e[9]=N,e[10]=B):B=e[10];let F;e[11]!==ee||e[12]!==B?(F=t.jsx(rn,{title:ee,settingsItem:"projects.name",children:B}),e[11]=ee,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 $;e[18]!==g||e[19]!==j.modelId||e[20]!==j.providerId?($=t.jsx(ja,{providerId:j.providerId,modelId:j.modelId,onChange:g,className:wa}),e[18]=g,e[19]=j.modelId,e[20]=j.providerId,e[21]=$):$=e[21];let ie;e[22]!==O||e[23]!==q||e[24]!==$?(ie=t.jsx(rn,{title:O,description:q,settingsItem:"projects.default-model",children:$}),e[22]=O,e[23]=q,e[24]=$,e[25]=ie):ie=e[25];let le;e[26]!==a?(le=a("settings.projects.page.field.accentColor"),e[26]=a,e[27]=le):le=e[27];let ne;e[28]!==m?(ne=()=>m(null),e[28]=m,e[29]=ne):ne=e[29];const ye=f===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]!==ye?(ae=oe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",ye),e[30]=ye,e[31]=ae):ae=e[31];let ge;e[32]!==a?(ge=a("settings.projects.page.field.none"),e[32]=a,e[33]=ge):ge=e[33];let Ne;e[34]===Symbol.for("react.memo_cache_sentinel")?(Ne=t.jsx(D,{name:"close",className:"h-4 w-4 text-muted-foreground"}),e[34]=Ne):Ne=e[34];let he;e[35]!==ne||e[36]!==ae||e[37]!==ge?(he=t.jsx("button",{type:"button",onClick:ne,className:ae,title:ge,children:Ne}),e[35]=ne,e[36]=ae,e[37]=ge,e[38]=he):he=e[38];let we;e[39]!==f||e[40]!==m?(we=$u.map(de=>t.jsx("button",{type:"button",onClick:()=>m(de.key),className:oe("h-7 w-7 rounded-md border transition-colors",f===de.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:de.cssVar},title:de.label},de.key)),e[39]=f,e[40]=m,e[41]=we):we=e[41];let ce;e[42]!==he||e[43]!==we?(ce=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[he,we]}),e[42]=he,e[43]=we,e[44]=ce):ce=e[44];let Z;e[45]!==le||e[46]!==ce?(Z=t.jsx(rn,{title:le,settingsItem:"projects.accent-color",children:ce}),e[45]=le,e[46]=ce,e[47]=Z):Z=e[47];let se;e[48]!==a?(se=a("settings.projects.page.field.projectIcon"),e[48]=a,e[49]=se):se=e[49];let ve;e[50]!==I?(ve=de=>{const je=de.target.files?.[0]??null;I(je),de.currentTarget.value=""},e[50]=I,e[51]=ve):ve=e[51];let H;e[52]!==M||e[53]!==ve?(H=t.jsx("input",{ref:M,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:ve}),e[52]=M,e[53]=ve,e[54]=H):H=e[54];let te;e[55]!==c?(te=()=>c(null),e[55]=c,e[56]=te):te=e[56];const re=d===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let pe;e[57]!==re?(pe=oe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",re),e[57]=re,e[58]=pe):pe=e[58];let Me;e[59]!==a?(Me=a("settings.projects.page.field.none"),e[59]=a,e[60]=Me):Me=e[60];let Se;e[61]===Symbol.for("react.memo_cache_sentinel")?(Se=t.jsx(D,{name:"close",className:"h-4 w-4 text-muted-foreground"}),e[61]=Se):Se=e[61];let Ae;e[62]!==te||e[63]!==pe||e[64]!==Me?(Ae=t.jsx("button",{type:"button",onClick:te,className:pe,title:Me,children:Se}),e[62]=te,e[63]=pe,e[64]=Me,e[65]=Ae):Ae=e[65];let De;e[66]!==_||e[67]!==d||e[68]!==c?(De=Vu.map(de=>{const je=de.Icon;return t.jsx("button",{type:"button",onClick:()=>c(de.key),className:oe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",d===de.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:de.label,children:t.jsx(D,{name:je,className:"w-4 h-4",style:_&&d===de.key?{color:_}:void 0})},de.key)}),e[66]=_,e[67]=d,e[68]=c,e[69]=De):De=e[69];let Pe;e[70]!==Ae||e[71]!==De?(Pe=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Ae,De]}),e[70]=Ae,e[71]=De,e[72]=Pe):Pe=e[72];let Oe;e[73]!==T||e[74]!==r||e[75]!==E||e[76]!==y||e[77]!==p||e[78]!==R||e[79]!==J||e[80]!==k||e[81]!==U||e[82]!==a?(Oe=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:p?{backgroundColor:p}:void 0,children:y&&R?t.jsx("img",{src:R,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>k(!0)}):t.jsx(lc,{project:{...J,iconImage:T??J.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]=y,e[77]=p,e[78]=R,e[79]=J,e[80]=k,e[81]=U,e[82]=a,e[83]=Oe):Oe=e[83];let Te;e[84]!==E||e[85]!==p||e[86]!==u||e[87]!==a?(Te=E&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("input",{type:"color",value:p??"#000000",onChange:de=>u(de.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:p??"",onChange:de=>u(de.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),t.jsx(G,{type:"button",size:"xs",variant:"outline",onClick:()=>u(null),className:"h-7 w-7 p-0","aria-label":a("settings.projects.page.field.clearIconBackgroundAria"),title:a("settings.projects.page.field.clearBackground"),disabled:!p,children:t.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]}),e[84]=E,e[85]=p,e[86]=u,e[87]=a,e[88]=Te):Te=e[88];let Ue;e[89]!==M||e[90]!==z||e[91]!==v||e[92]!==A||e[93]!==h||e[94]!==a?(Ue=!v&&t.jsxs(t.Fragment,{children:[t.jsx(G,{size:"xs",className:"h-6 !font-normal",onClick:()=>M.current?.click(),disabled:h,children:a(h?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),t.jsx(G,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{z()},disabled:A,children:a(A?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),e[89]=M,e[90]=z,e[91]=v,e[92]=A,e[93]=h,e[94]=a,e[95]=Ue):Ue=e[95];let Be;e[96]!==P||e[97]!==K||e[98]!==x||e[99]!==a?(Be=K&&t.jsx(G,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{P()},disabled:x,children:a(x?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),e[96]=P,e[97]=K,e[98]=x,e[99]=a,e[100]=Be):Be=e[100];let Ke;e[101]!==x||e[102]!==S||e[103]!==C||e[104]!==a?(Ke=S&&t.jsx(G,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>C(!1),disabled:x,children:a("settings.projects.page.actions.undoRemove")}),e[101]=x,e[102]=S,e[103]=C,e[104]=a,e[105]=Ke):Ke=e[105];let Je;e[106]!==Ue||e[107]!==Be||e[108]!==Ke?(Je=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Ue,Be,Ke]}),e[106]=Ue,e[107]=Be,e[108]=Ke,e[109]=Je):Je=e[109];let ue;e[110]!==se||e[111]!==H||e[112]!==Pe||e[113]!==Oe||e[114]!==Te||e[115]!==Je?(ue=t.jsxs(rn,{title:se,settingsItem:"projects.icon",children:[H,Pe,Oe,Te,Je]}),e[110]=se,e[111]=H,e[112]=Pe,e[113]=Oe,e[114]=Te,e[115]=Je,e[116]=ue):ue=e[116];let Y;return e[117]!==ie||e[118]!==Z||e[119]!==ue||e[120]!==F?(Y=t.jsxs(t.Fragment,{children:[F,ie,Z,ue]}),e[117]=ie,e[118]=Z,e[119]=ue,e[120]=F,e[121]=Y):Y=e[121],Y},Zf=/^#(?:[\da-fA-F]{3}|[\da-fA-F]{6})$/,ex=s=>{if(!s)return null;const e=s.trim();return e&&Zf.test(e)?e.toLowerCase():null},tx=s=>{const{t:e}=st(),n=ss(ae=>ae.uploadProjectIcon),a=ss(ae=>ae.removeProjectIcon),r=ss(ae=>ae.discoverProjectIcon),i=ss(ae=>s?ae.projects.find(ge=>ge.id===s.id)?.iconImage??null:null),[l,d]=o.useState(""),[c,f]=o.useState(null),[m,p]=o.useState(null),[u,j]=o.useState(null),[g,h]=o.useState(void 0),[x,A]=o.useState(!1),[S,C]=o.useState(!1),[R,k]=o.useState(!1),[y,v]=o.useState(!1),[E,K]=o.useState(null),[U,M]=o.useState(null),[I,P]=o.useState(!1),z=o.useRef(null),T=o.useCallback(()=>{K(null),M(ae=>(ae&&URL.revokeObjectURL(ae),null))},[]),J=s?.id??null;o.useEffect(()=>{if(!s){d(""),f(null),p(null),j(null),h(void 0);return}d(s.label??""),f(s.icon??null),p(s.color??null),j(s.iconBackground??null),h(s.defaultModel),v(!1),T(),P(!1)},[s,T]),o.useEffect(()=>()=>{T()},[T]);const _=o.useMemo(()=>xn(g)??{providerId:"",modelId:""},[g]),ee=!!s?.iconImage,Q=!!(E&&U),N=s?.iconImage?.source==="custom",V=ee&&!y||Q,B=V,F=!!(s&&ee&&!y),O=!I&&(Q||F),q=!!s&&(l.trim()!==(s?.label??"").trim()||c!==(s?.icon??null)||m!==(s?.color??null)||u!==(s?.iconBackground??null)||(g??void 0)!==(s?.defaultModel??void 0)||y||!!E),$=o.useCallback((ae,ge)=>{h(ae&&ge?`${ae}/${ge}`:void 0)},[]),ie=o.useCallback(ae=>{!s||!ae||x||(v(!1),P(!1),K(ae),M(ge=>(ge&&URL.revokeObjectURL(ge),URL.createObjectURL(ae))))},[x,s]),le=o.useCallback(()=>{!s||!B||S||(Q&&T(),v(!!ee),P(!1))},[T,Q,B,ee,S,s]),ne=o.useCallback(async()=>{if(!(!s||R)){T(),v(!1),P(!1),k(!0);try{const ae=await r(s.id);if(!ae.ok){W.error(ae.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(ae.skipped){W.success(e("settings.projects.page.toast.customIconAlreadySet"));return}W.success(e("settings.projects.page.toast.iconDiscovered"))}finally{k(!1)}}},[T,r,R,s,e]),ye=o.useCallback(async ae=>{const ge=ae?.silent===!0;if(!s)return null;const Ne=l.trim();if(!Ne)return null;if(E){A(!0);const we=await n(s.id,E);if(A(!1),!we.ok)return W.error(we.error||e("settings.projects.page.toast.uploadIconFailed")),null;ge||W.success(e("settings.projects.page.toast.iconUpdated")),T(),v(!1)}const he=y&&!!s.iconImage;if(he){C(!0);const we=await a(s.id);if(C(!1),!we.ok)return W.error(we.error||e("settings.projects.page.toast.removeIconFailed")),null;ge||W.success(e("settings.projects.page.toast.iconRemoved")),v(!1),j(null)}return{label:Ne,icon:c,color:m,iconBackground:ex(he?null:u),defaultModel:g??null}},[T,m,g,c,u,l,y,E,s,a,e,n]);return o.useEffect(()=>{P(!1)},[J,i?.updatedAt]),{name:l,setName:d,icon:c,setIcon:f,color:m,setColor:p,iconBackground:u,setIconBackground:j,defaultModel:g,parsedDefaultModel:_,handleDefaultModelChange:$,isUploadingIcon:x,isRemovingCustomIcon:S,isDiscoveringIcon:R,pendingRemoveImageIcon:y,setPendingRemoveImageIcon:v,pendingUploadIconFile:E,pendingUploadIconPreviewUrl:U,previewImageFailed:I,setPreviewImageFailed:P,hasStoredImageIcon:ee,hasPendingUploadImageIcon:Q,hasCustomIcon:N,effectiveHasImageIcon:V,hasRemovableImageIcon:B,showStoredImagePreview:F,showImagePreview:O,fileInputRef:z,clearPendingUploadIcon:T,handleUploadIcon:ie,handleRemoveImageIcon:le,handleDiscoverIcon:ne,hasChanges:q,prepareSaveData:ye,currentIconImage:i,project:s}},sx=450,nx=(s,e)=>{const{t:n}=st(),{hasChanges:a,name:r,icon:i,color:l,iconBackground:d,defaultModel:c,pendingRemoveImageIcon:f,pendingUploadIconFile:m,isUploadingIcon:p,isRemovingCustomIcon:u,prepareSaveData:j}=s,g=o.useRef(!1);o.useEffect(()=>{if(!a||!r.trim()||p||u||g.current)return;const h=window.setTimeout(()=>{g.current||(g.current=!0,(async()=>{try{const x=await j({silent:!0});if(x)try{await e(x)}catch{W.error(n("settings.projects.page.toast.saveFailed"))}}finally{g.current=!1}})())},sx);return()=>{window.clearTimeout(h)}},[l,c,a,i,d,u,p,r,e,f,m,j,n])},ax=s=>{const e=Ze.c(25),{project:n,onIdentitySave:a}=s,{t:r}=st(),i=tx(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 d=l;let c;if(e[3]!==a?(c=async C=>{await a(C)},e[3]=a,e[4]=c):c=e[4],nx(i,c),!n||!d)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 p=m;let u;e[8]!==p?(u=t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p}),e[8]=p,e[9]=u):u=e[9];let j;e[10]!==n.path?(j=t.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:n.path,children:n.path}),e[10]=n.path,e[11]=j):j=e[11];let g;e[12]!==u||e[13]!==j?(g=t.jsxs("div",{className:"mb-5 px-1",children:[u,j]}),e[12]=u,e[13]=j,e[14]=g):g=e[14];let h;e[15]!==i?(h=t.jsx(Xf,{form:i}),e[15]=i,e[16]=h):h=e[16];let x,A;e[17]!==d?(x=t.jsx(Yf,{projectRef:d}),A=t.jsx($f,{projectRef:d}),e[17]=d,e[18]=x,e[19]=A):(x=e[18],A=e[19]);let S;return e[20]!==g||e[21]!==h||e[22]!==x||e[23]!==A?(S=t.jsxs("div",{className:"space-y-0",children:[g,h,x,A]}),e[20]=g,e[21]=h,e[22]=x,e[23]=A,e[24]=S):S=e[24],S},rx=()=>{const s=Ze.c(18),{t:e}=st(),n=ss(ix),a=ss(ox),r=Fe(lx),i=Fe(cx);let l;e:{if(!r){l=null;break e}let j;s[0]!==n||s[1]!==r?(j=n.find(g=>g.id===r)??null,s[0]=n,s[1]=r,s[2]=j):j=s[2],l=j}const d=l;let c,f;s[3]!==n||s[4]!==r||s[5]!==i?(c=()=>{if(n.length===0){i(null);return}r&&n.some(j=>j.id===r)||i(n[0].id)},f=[n,r,i],s[3]=n,s[4]=r,s[5]=i,s[6]=c,s[7]=f):(c=s[6],f=s[7]),o.useEffect(c,f);let m;s[8]!==d||s[9]!==a?(m=async j=>{d&&a(d.id,{label:j.label,icon:j.icon,color:j.color,iconBackground:j.iconBackground,defaultModel:j.defaultModel??null})},s[8]=d,s[9]=a,s[10]=m):m=s[10];const p=m;if(!d){let j;s[11]!==e?(j=e("settings.projects.page.empty.noProjects"),s[11]=e,s[12]=j):j=s[12];let g;return s[13]!==j?(g=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:j})})}),s[13]=j,s[14]=g):g=s[14],g}let u;return s[15]!==p||s[16]!==d?(u=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(ax,{project:d,onIdentitySave:p})})}),s[15]=p,s[16]=d,s[17]=u):u=s[17],u};function ix(s){return s.projects}function ox(s){return s.updateProjectMeta}function lx(s){return s.settingsProjectsSelectedId}function cx(s){return s.setSettingsProjectsSelectedId}const zr=16384,lr=globalThis,dx=s=>{if(lr.Buffer)return lr.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,"")},ux=s=>{try{if(lr.Buffer)return lr.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}},mx=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}},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!=="ws:"&&n.protocol!=="wss:"?null:(n.hash="",n.toString())}catch{return null}},il=s=>typeof s=="string"&&s.length>0,gx=s=>{if(!s||typeof s!="object"||Array.isArray(s))return null;const e=s;return e.kty!=="EC"||e.crv!=="P-256"||!il(e.x)||!il(e.y)?null:{kty:"EC",crv:"P-256",x:e.x,y:e.y}},hx=s=>typeof s=="number"&&Number.isFinite(s)?s:void 0,fx=s=>{if(!s||typeof s!="object")return null;const e=s,n=hx(e.priority);if(e.type==="lan"||e.type==="tunnel"){const a=mx(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=px(e.relayUrl);if(!a)return null;const r=typeof e.serverId=="string"?e.serverId.trim():"";if(!r)return null;const i=gx(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},Tc=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(fx).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,d=typeof e.fingerprint=="string"&&e.fingerprint.trim()?e.fingerprint.trim():void 0;return{v:2,pairingId:n,secret:a,...l?{label:l}:{},...d?{fingerprint:d}:{},...i?{expiresAt:i}:{},candidates:r}},xx=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}),yx=s=>{const e=Tc(s);if(!e)throw new Error("Invalid pairing connection payload");const n=new URLSearchParams;return n.set("v","2"),n.set("p",dx(JSON.stringify(e))),`openchamber://connect?${n.toString()}`},bx=s=>{const e=s.trim();if(!e||e.length>zr)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>zr)return null;const r=ux(a);return!r||r.length>zr?null:Tc(JSON.parse(r))}catch{return null}},hi=()=>Math.floor(2e4+Math.random()*3e4),vx=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")},jx=()=>{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"},ol=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}},ll=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"}},wx=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Rc=s=>!!(s&&wx.has(s)),cl=s=>s==="ready"?"bg-[var(--status-success)] animate-pulse":s==="error"?"bg-[var(--status-error)] animate-pulse":s==="degraded"||Rc(s)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Nx=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}`,kx=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:hi(),remoteHost:"127.0.0.1",remotePort:80}),Sx=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(It,{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(Ct,{children:[i,t.jsx(Pt,{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 d;return e[5]!==r||e[6]!==l?(d=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]=d):d=e[7],d},Cx=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"}},dl=(s,e)=>{const n=(s||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},Ix=s=>{const e=(s||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Px=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}`},fi=(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}),Ax=s=>s.trim().toLowerCase()==="authorization",Ur=s=>{const e={};for(const n of s){const a=n.name.trim(),r=n.value.trim();a&&r&&!Ax(a)&&(e[a]=r)}return Object.keys(e).length>0?e:void 0},Dx=s=>Object.entries(s||{}).map(([e,n])=>fi(e,n)),Lc=()=>{if(typeof window>"u")return null;const e=na()||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}},ul=s=>{try{const e=new URL(s).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},Ex=async()=>{const s=Hn(na())||window.location.origin;if(!rs()||!sa())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 hc(),r=Lc();return!a||!r?s:`http://${a}:${r}`},Kr=s=>{const e=s.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Mx=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}},Tx=()=>{const{t:s}=st(),{clientAuth:e}=Si(),n=rs(),a=us(L=>L.instances),r=us(L=>L.statusesById),i=us(L=>L.importCandidates),l=us(L=>L.isLoading),d=us(L=>L.isImportsLoading),c=us(L=>L.isSaving),f=us(L=>L.error),m=us(L=>L.load),p=us(L=>L.loadImports),u=us(L=>L.refreshStatuses),j=us(L=>L.upsertInstance),g=us(L=>L.createFromCommand),h=us(L=>L.removeInstance),x=us(L=>L.connect),A=us(L=>L.disconnect),S=us(L=>L.retry),C=Fe(L=>L.settingsRemoteInstancesSelectedId),R=Fe(L=>L.setSettingsRemoteInstancesSelectedId),k=o.useMemo(()=>C&&a.find(L=>L.id===C)||null,[a,C]),[y,v]=o.useState(null),[E,K]=o.useState(!1),[U,M]=o.useState(!1),[I,P]=o.useState(null),[z,T]=o.useState([]),[J,_]=o.useState(null),[ee,Q]=o.useState(""),[N,V]=o.useState(!1),[B,F]=o.useState({}),[O,q]=o.useState(!1),[$,ie]=o.useState(!1),[le,ne]=o.useState(()=>Date.now()),[ye,ae]=o.useState([]),[ge,Ne]=o.useState({}),[he,we]=o.useState("local"),[ce,Z]=o.useState(!1),[se,ve]=o.useState(!1),[H,te]=o.useState(""),[re,pe]=o.useState(""),[Me,Se]=o.useState(""),[Ae,De]=o.useState([]),[Pe,Oe]=o.useState(""),[Te,Ue]=o.useState(null),[Be,Ke]=o.useState(!1),[Je,ue]=o.useState(!1),[Y,de]=o.useState(null),[je,Re]=o.useState(""),[Ie,Ve]=o.useState(""),[X,b]=o.useState(""),[be,Ee]=o.useState([]),[ze,qe]=o.useState([]),[rt,lt]=o.useState([]),[at,ct]=o.useState(!1),[Ye,_e]=o.useState(""),[ft,xe]=o.useState(null),[et,nt]=o.useState(null),[He,yt]=o.useState(null),[Nt,Tt]=o.useState(null),[me,$e]=o.useState(!1),[Qe,We]=o.useState(!1),[xt,St]=o.useState("configure"),[ht,Rt]=o.useState(!1),[Gt,cs]=o.useState("relay"),[ds,xs]=o.useState(!0),[Zt,Cs]=o.useState(null),Ce=o.useMemo(()=>ze.filter(L=>!!L.revokedAt).length,[ze]),[vt,jt]=o.useState(!1),[qt,es]=o.useState("ssh user@example.com"),[Bt,ys]=o.useState("");o.useEffect(()=>{m(),p()},[m,p]);const ws=o.useCallback(async()=>{Z(!0),Ue(null);try{const L=await eo();ae(L.hosts||[]),we(L.defaultHostId||"local")}catch(L){Ue(L instanceof Error?L.message:String(L))}finally{Z(!1)}},[]);o.useEffect(()=>{ws()},[ws]);const Qt=o.useCallback(async(L,ke=he)=>{ve(!0),Ue(null);try{await to({hosts:L,defaultHostId:ke,initialHostChoiceCompleted:!0}),ae(L),we(ke)}catch(tt){Ue(tt instanceof Error?tt.message:String(tt))}finally{ve(!1)}},[he]),Fs=o.useCallback(async()=>{const L=so(re);if(!L){Ue(s("desktopHostSwitcher.error.invalidUrl"));return}const ke=L.persistedUrl,ut={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:H.trim()||ca(ke),url:ke,apiUrl:ke,...Me.trim()?{clientToken:Me.trim()}:{},...Ur(Ae)?{requestHeaders:Ur(Ae)}:{}};await Qt([ut,...ye],he),te(""),pe(""),Se(""),De([]),Ke(!1),L.redeemUrl&&Kr(L.redeemUrl)},[he,Ae,ye,H,Me,re,Qt,s]),kn=o.useCallback(async()=>{const L=bx(Pe);if(!L){Ue(s("settings.remoteInstances.direct.error.invalidConnectLink"));return}const ke=await Lm().catch(()=>""),tt=JSON.stringify({pairingId:L.pairingId,secret:L.secret,clientLabel:L.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:jx(),...ke?{dedupeKey:`desktop:${ke}`}:{}}),ut={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:tt},Wt=async $t=>{if(!$t.ok)return null;const Ls=await $t.json().catch(()=>null);return(typeof Ls?.clientToken=="string"?Ls.clientToken.trim():"")||null},Us=[...L.candidates].sort(($t,Ls)=>($t.type==="relay"?1:0)-(Ls.type==="relay"?1:0));let is=null;for(const $t of Us){if($t.type==="relay"){const la=Fm({relayUrl:$t.relayUrl,serverId:$t.serverId,hostEncPubJwk:$t.hostEncPubJwk,...$t.grant?{grant:$t.grant}:{}});try{const Aa=await la.fetch("/api/client-auth/pairing/redeem",ut),Ri=await Wt(Aa);if(Ri){is={kind:"relay",relay:{relayUrl:$t.relayUrl,serverId:$t.serverId,hostEncPubJwk:$t.hostEncPubJwk},token:Ri};break}}catch{}finally{la.close()}continue}const Ls=Hn($t.url);if(Ls)try{const la=await fetch(`${Ls}/api/client-auth/pairing/redeem`,ut),Aa=await Wt(la);if(Aa){is={kind:"direct",url:Ls,token:Aa};break}}catch{}}if(!is){Ue(s("desktopHostSwitcher.error.invalidUrl"));return}const pn=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Cn=L.candidates.find($t=>$t.type==="relay"),Ys=is.kind==="relay"?is.relay:Cn?{relayUrl:Cn.relayUrl,serverId:Cn.serverId,hostEncPubJwk:Cn.hostEncPubJwk}:void 0,br=L.candidates.filter($t=>$t.type!=="relay").map($t=>Hn($t.url)).find($t=>!!$t),ia=is.kind==="direct"?is.url:br,{token:vr}=is,Ot=ia||(Ys?Om(Ys.serverId):null);if(!Ot){Ue(s("desktopHostSwitcher.error.invalidUrl"));return}const as={url:Ot,apiUrl:ia||void 0,clientToken:vr,...Ys?{relay:Ys}:{}},oa=ye.find($t=>Ys?$t.relay?.serverId===Ys.serverId:!$t.relay&&Hn($t.apiUrl||$t.url)===Ot);if(oa){const $t=ye.map(Ls=>Ls.id===oa.id?{...Ls,label:L.label||Ls.label,...as}:Ls);await Qt($t,he)}else await Qt([{id:pn(),label:L.label||ca(Ot),...as},...ye],he);Oe(""),Ue(null),ue(!1)},[Pe,he,ye,Qt,s]),Gs=o.useCallback(async L=>{const ke=ye.filter(ut=>ut.id!==L);await Qt(ke,he===L?"local":he),Y===L&&de(null)},[he,Y,ye,Qt]),Bs=o.useCallback(L=>{de(L.id),Re(L.label),Ve(L.apiUrl||L.url),b(L.clientToken||""),Ee(Dx(L.requestHeaders)),Ue(null)},[]),cn=o.useCallback(async()=>{if(!Y)return;const L=so(Ie);if(!L){Ue(s("desktopHostSwitcher.error.invalidUrl"));return}const ke=L.persistedUrl,tt=ye.map(ut=>ut.id===Y?{...ut,label:je.trim()||ca(ke),url:ke,apiUrl:ke,clientToken:X.trim()||void 0,requestHeaders:Ur(be)}:ut);await Qt(tt,he),de(null),L.redeemUrl&&Kr(L.redeemUrl)},[he,be,je,X,Ie,Y,ye,Qt,s]),ot=o.useCallback(async()=>{const L=qt.trim();if(!L){W.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}const ke=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await g(ke,L,Bt.trim()||s("settings.remoteInstances.sidebar.newSshInstanceName")),R(ke),jt(!1),es("ssh user@example.com"),ys(""),W.success(s("settings.remoteInstances.page.toast.instanceCreated"))}catch(tt){W.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:tt instanceof Error?tt.message:String(tt)})}},[g,R,qt,Bt,s]),pt=o.useCallback(async L=>{await Qt(ye,L)},[ye,Qt]);o.useEffect(()=>{if(!n||ye.length===0)return;let L=!1;return Promise.all(ye.map(async ke=>{const tt=()=>Bm(ke.relay).catch(()=>({status:"unreachable",latencyMs:0}));if(ke.relay&&!ke.apiUrl)return[ke.id,await tt()];const ut=Hn(zm(ke));if(!ut)return[ke.id,ke.relay?await tt():{status:"unreachable",latencyMs:0}];const Wt=await Um(ut,{clientToken:ke.clientToken||null,requestHeaders:ke.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Wt.status==="unreachable"&&ke.relay){const Us=await tt();if(Us.status==="ok")return[ke.id,Us]}return[ke.id,Wt]})).then(ke=>{L||Ne(Object.fromEntries(ke))}),()=>{L=!0}},[ye,n]);const wt=o.useCallback(async L=>{if(e){L?.silent||ct(!0),L?.silent||xe(null);try{const[ke,tt]=await Promise.all([e.listClients(),e.listPendingPairings().catch(()=>null)]);qe(ke),tt&&lt(tt)}catch(ke){L?.silent||xe(ke instanceof Error?ke.message:String(ke))}finally{L?.silent||ct(!1)}}},[e]),Yt=o.useRef(!1);o.useEffect(()=>{if(!(!Qe||xt!=="result"||!He)){if(rt.some(L=>L.id===He)){Yt.current=!0;return}Yt.current&&(yt(null),We(!1),ze.some(L=>L.pairingId===He)&&W.success(s("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Qe,xt,He,rt,ze,s]);const Xt=o.useCallback(async L=>{if(e)try{await e.cancelPairing(L),lt(ke=>ke.filter(tt=>tt.id!==L)),await wt({silent:!0})}catch(ke){xe(ke instanceof Error?ke.message:String(ke))}},[e,wt]);o.useEffect(()=>{if(!e)return;wt();const L=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||wt({silent:!0})},5e3);return()=>window.clearInterval(L)},[e,wt]);const Ge=o.useCallback(async()=>{if(e?.getPairingTransports)try{const ut=await e.getPairingTransports();return{localUrl:ut.local,lanUrl:ut.lan,relayAvailable:ut.relayAvailable}}catch{}const L=Lc(),ke=L?`http://127.0.0.1:${L}`:ul(window.location.origin)?window.location.origin:null;let tt=null;try{const ut=Hn(await Ex());tt=ut&&!ul(ut)?ut:null}catch{}return{localUrl:ke,lanUrl:tt,relayAvailable:!0}},[e]),Ts=o.useCallback(async()=>{xe(null),nt(null),Tt(null),$e(!1),yt(null),St("configure"),xs(!0),We(!0);const L=await Ge();Cs(L),cs(L.relayAvailable?"relay":L.lanUrl?"lan":"local")},[Ge]),aa=o.useCallback(async()=>{if(!(!e?.createPairingSession||!Zt)){xe(null),Rt(!0);try{const L=Ye.trim()||void 0;let ke,tt,ut=!0;Gt==="local"?(ke=Zt.localUrl??void 0,tt=!1):Gt==="lan"?(ke=Zt.lanUrl??void 0,tt=ds):ds&&Zt.lanUrl?(ke=Zt.lanUrl,tt=!0):(ut=!1,tt=!0);const{pairing:Wt,server:Us}=await e.createPairingSession({label:L,allowedClientKinds:["mobile","desktop"],serverUrl:ke,includeRelay:tt,includeDirect:ut}),is=xx({pairingId:Wt.id,secret:Wt.secret,label:Us.label,fingerprint:Wt.fingerprint??void 0,expiresAt:Wt.expiresAt,candidates:Us.candidates}),pn=yx(is);nt(pn),Tt(await tc.toDataURL(pn,{width:1024,margin:2,errorCorrectionLevel:"L"})),$e(!1),Yt.current=!1,yt(Wt.id),St("result"),await wt({silent:!0})}catch(L){xe(L instanceof Error?L.message:String(L))}finally{Rt(!1)}}},[e,Zt,Gt,ds,Ye,wt]),Sa=o.useCallback(()=>{et&&En(et).then(L=>{L.ok&&($e(!0),window.setTimeout(()=>$e(!1),2e3))})},[et]),Ca=o.useCallback(async L=>{if(!e)return;const ke=L.clientKind==="desktop-local";xe(null);try{if(await e.revokeClient(L.id),ke&&rs()){const tt=await eo();await to({hosts:tt.hosts,defaultHostId:tt.defaultHostId,initialHostChoiceCompleted:tt.initialHostChoiceCompleted,localClientToken:null}),qe(ut=>ut.map(Wt=>Wt.id===L.id?{...Wt,revokedAt:new Date().toISOString()}:Wt)),Km({apiBaseUrl:na(),clientToken:null,runtimeKey:"local"});return}await wt()}catch(tt){xe(tt instanceof Error?tt.message:String(tt))}},[e,wt]),fr=o.useCallback(async()=>{if(e){xe(null);try{await e.purgeRevokedClients(),await wt()}catch(L){xe(L instanceof Error?L.message:String(L))}}},[e,wt]);o.useEffect(()=>{v(k)},[k]),o.useEffect(()=>{if(!C)return;const L=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||u()},2e3);return()=>{window.clearInterval(L)}},[u,C]),o.useEffect(()=>{let L=null,ke=Date.now();const tt=()=>{const Wt=Date.now();Wt-ke>=1e3&&(ne(Wt),ke=Wt),L=requestAnimationFrame(tt)};(typeof document>"u"||document.visibilityState==="visible")&&(L=requestAnimationFrame(tt));const ut=()=>{document.visibilityState==="visible"&&L===null?L=requestAnimationFrame(tt):document.visibilityState!=="visible"&&L!==null&&(cancelAnimationFrame(L),L=null)};return document.addEventListener("visibilitychange",ut),()=>{document.removeEventListener("visibilitychange",ut),L!==null&&cancelAnimationFrame(L)}},[]);const Ps=C?r[C]:null,$s=Ps?.phase,On=$s==="ready",As=$s==="degraded",Rs=Rc($s),Vs=On||(Rs||As),xr=Ps?Math.max(0,le-Ps.updatedAtMs):0,dn=As&&xr>12e3,Js=o.useMemo(()=>!y||!k?!1:JSON.stringify(y)!==JSON.stringify(k),[y,k]),ts=o.useCallback(L=>{v(ke=>ke&&L(ke))},[]),un=o.useCallback(async()=>{if(!y)return;const L=Mx(y);if(!L.sshCommand.trim()){W.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(L.localForward.bindHost==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(L.auth.sshPassword?.enabled&&L.auth.sshPassword.value?.trim()&&L.auth.sshPassword.store!=="settings"){const ke=window.confirm(s("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));L.auth.sshPassword.store=ke?"settings":"never",ke||(L.auth.sshPassword.value=void 0)}if(L.auth.openchamberPassword?.enabled&&L.auth.openchamberPassword.value?.trim()&&L.auth.openchamberPassword.store!=="settings"){const ke=window.confirm(s("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));L.auth.openchamberPassword.store=ke?"settings":"never",ke||(L.auth.openchamberPassword.value=void 0)}try{await j(L),W.success(s("settings.remoteInstances.page.toast.instanceSaved"))}catch(ke){W.error(s("settings.remoteInstances.page.toast.saveFailed"),{description:ke instanceof Error?ke.message:String(ke)})}}},[y,s,j]),zn=o.useCallback(async(L,ke)=>{const tt=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await g(tt,`ssh ${ke}`,L),R(tt),W.success(s("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(ut){return W.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:ut instanceof Error?ut.message:String(ut)}),!1}},[g,R,s]),Un=o.useCallback(()=>{N||(_(null),Q(""))},[N]),yr=o.useCallback((L,ke)=>{if(ke){_(L),Q(Sx(L));return}zn(L,L)},[zn]),Ia=o.useCallback(async()=>{const L=J,ke=ee.trim();if(L){if(!ke){W.error(s("settings.remoteInstances.page.toast.destinationRequired"));return}V(!0);try{await zn(L,ke)&&(_(null),Q(""))}finally{V(!1)}}},[zn,ee,J,s]),Kn=o.useCallback(async()=>{if(k)try{await x(k.id);return}catch(L){if(!vx(L)||!window.confirm(s("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw L;const tt={...k,localForward:{...k.localForward,preferredLocalPort:hi()}};await j(tt),await x(tt.id),W.success(s("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[x,k,s,j]),mn=o.useCallback(async L=>(await _u(L,600)).map(tt=>Px(tt)),[]),Pa=o.useCallback(async()=>{if(y){K(!0),M(!0),P(null);try{const L=await mn(y.id);T(L)}catch(L){T([]),P(L instanceof Error?L.message:String(L))}finally{M(!1)}}},[y,mn]);o.useEffect(()=>{if(!E||!y)return;let L=!1;const ke=async()=>{try{const ut=await mn(y.id);L||(T(ut),P(null))}catch(ut){L||P(ut instanceof Error?ut.message:String(ut))}};ke();const tt=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ke()},1e3);return()=>{L=!0,window.clearInterval(tt)}},[y,E,mn]);const w=o.useMemo(()=>z.join(`
28
+ `),[z]),gt=o.useCallback(()=>{if(!w.trim()){W.error(s("settings.remoteInstances.page.toast.noLogsToCopy"));return}En(w).then(L=>{L.ok&&W.success(s("settings.remoteInstances.page.toast.logsCopied"))})},[w,s]),At=o.useCallback(async()=>{if(y)try{await Hu(y.id),T([]),W.success(s("settings.remoteInstances.page.toast.logsCleared"))}catch(L){W.error(s("settings.remoteInstances.page.toast.clearLogsFailed"),{description:L instanceof Error?L.message:String(L)})}},[y,s]),ns=o.useCallback(async()=>{if(!Ps?.localUrl){W.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const L=Ps.localUrl.trim();if(!L){W.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Kr(L)},[Ps?.localUrl,s]),zs=o.useCallback(()=>{if(!y)return;q(!0),(Vs?A(y.id):Kn()).catch(ke=>{const tt=Vs?On?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";W.error(s(tt),{description:ke instanceof Error?ke.message:String(ke)})}).finally(()=>{q(!1)})},[Vs,Kn,A,y,On,s]),Qs=o.useCallback(()=>{if(!y||Rs)return;ie(!0),(As?A(y.id).then(()=>Kn()):S(y.id)).catch(ke=>{W.error(s("settings.remoteInstances.page.toast.retryFailed"),{description:ke instanceof Error?ke.message:String(ke)})}).finally(()=>{ie(!1)})},[Kn,A,y,Rs,As,S,s]),Bn=s(Rs?"settings.remoteInstances.page.actions.connecting":As?dn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),ra=!O&&!$&&($s==="error"||$s==="idle"||!$s||As&&dn)&&!Rs,rd=s(On?"settings.remoteInstances.sidebar.actions.disconnect":Vs?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!y)return t.jsxs(gi,{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(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Ts()},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:[Ce>0?t.jsx("div",{className:"flex justify-end",children:t.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{fr()},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(L=>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:L.label||s("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),L.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(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Xt(L.id)},children:s("settings.common.actions.cancel")})]},`pending-${L.id}`)),ze.map(L=>{const ke=L.clientKind==="desktop-local",tt=L.lastUsedAt?Date.parse(L.lastUsedAt):Number.NaN,ut=!L.revokedAt&&(ke||Number.isFinite(tt)&&Date.now()-tt<9e4),Wt=L.revokedAt?s("settings.remoteInstances.clientAuth.state.revoked"):ut?L.lastTransport==="relay"&&!ke?s("settings.remoteInstances.clientAuth.state.connectedRelay"):s("settings.remoteInstances.clientAuth.state.connectedDirect"):L.lastUsedAt?s("settings.remoteInstances.clientAuth.lastUsed",{date:L.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:oe("h-2 w-2 shrink-0 rounded-full",L.revokedAt?"bg-muted-foreground/20":ut?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:L.label}),ol(L.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:ol(L.devicePlatform)}):null,ke?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:oe("typography-micro truncate",ut&&!L.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Wt})]}),t.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ca(L)},disabled:!!L.revokedAt,children:s("settings.remoteInstances.clientAuth.actions.revoke")})]},L.id)})]})]}),ft?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ft}):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(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>ue(!0),disabled:se,children:s("settings.remoteInstances.direct.import.action")}),t.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ke(!0),disabled:se,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:ce?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.state.loading")}):ye.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.state.empty")}):ye.map(L=>{const ke=ge[L.id],tt=ke?ke.status==="ok"?"desktopHostSwitcher.status.connected":ke.status==="auth"?"desktopHostSwitcher.status.authRequired":ke.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":ke.status==="incompatible"?"desktopHostSwitcher.status.incompatible":ke.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",ut=ke?.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:oe("h-2 w-2 shrink-0 rounded-full",ke?ut?"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:ca(L.label)}),he===L.id?t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:s("desktopHostSwitcher.header.default")}):null,t.jsxs("span",{className:oe("typography-micro shrink-0",ut?"text-[var(--status-success)]":"text-muted-foreground"),children:[s(tt),ut&&typeof ke?.latencyMs=="number"?s("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(ke.latencyMs))}):""]})]}),t.jsx("p",{className:oe("typography-micro text-muted-foreground truncate",L.apiUrl&&"font-mono"),children:L.relay&&!L.apiUrl?s("mobile.connect.relay.badge"):ca(L.apiUrl||L.url)})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{pt(L.id)},disabled:se||he===L.id,"aria-label":s("desktopHostSwitcher.actions.setAsDefaultAria"),children:he===L.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"})}),L.relay&&!L.apiUrl?null:t.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Bs(L),disabled:se,children:[t.jsx(D,{name:"pencil",className:"h-3.5 w-3.5"}),s("desktopHostSwitcher.actions.edit")]}),t.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Gs(L.id)},disabled:se,children:[t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]})},L.id)})}),Te?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Te}):null]})]}):null,n?t.jsx(Lt,{open:Be,onOpenChange:Ke,children:t.jsxs(Ft,{className:"sm:max-w-lg",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("settings.remoteInstances.direct.actions.add")}),t.jsx(_t,{children:s("settings.remoteInstances.direct.addDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),Fs()},children:[t.jsx(Xe,{className:"h-8",value:H,onChange:L=>te(L.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:se}),t.jsx(Xe,{className:"h-8",value:re,onChange:L=>pe(L.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:se,autoFocus:!0}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(Xe,{className:"h-8",value:Me,onChange:L=>Se(L.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:se}),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")})]}),Ae.map(L=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(Xe,{className:"h-8 font-mono text-xs",value:L.name,onChange:ke=>De(tt=>tt.map(ut=>ut.id===L.id?{...ut,name:ke.target.value}:ut)),placeholder:s("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:se}),t.jsx(Xe,{className:"h-8 font-mono text-xs",value:L.value,onChange:ke=>De(tt=>tt.map(ut=>ut.id===L.id?{...ut,value:ke.target.value}:ut)),placeholder:s("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:se}),t.jsx("button",{type:"button",onClick:()=>De(ke=>ke.filter(tt=>tt.id!==L.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:se,children:t.jsx(D,{name:"close",className:"h-4 w-4"})})]},L.id)),t.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>De(L=>[...L,fi()]),disabled:se,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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ke(!1),disabled:se,children:s("settings.common.actions.cancel")}),t.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:se||!re.trim(),children:s("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?t.jsx(Lt,{open:!!Y,onOpenChange:L=>{L||de(null)},children:t.jsxs(Ft,{className:"sm:max-w-lg",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("desktopHostSwitcher.actions.edit")}),t.jsx(_t,{children:s("settings.remoteInstances.direct.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),cn()},children:[t.jsx(Xe,{className:"h-8",value:je,onChange:L=>Re(L.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:se}),t.jsx(Xe,{className:"h-8",value:Ie,onChange:L=>Ve(L.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:se,autoFocus:!0}),t.jsx(Xe,{className:"h-8",value:X,onChange:L=>b(L.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:se}),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(L=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(Xe,{className:"h-8 font-mono text-xs",value:L.name,onChange:ke=>Ee(tt=>tt.map(ut=>ut.id===L.id?{...ut,name:ke.target.value}:ut)),placeholder:s("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:se}),t.jsx(Xe,{className:"h-8 font-mono text-xs",value:L.value,onChange:ke=>Ee(tt=>tt.map(ut=>ut.id===L.id?{...ut,value:ke.target.value}:ut)),placeholder:s("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:se}),t.jsx("button",{type:"button",onClick:()=>Ee(ke=>ke.filter(tt=>tt.id!==L.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:se,children:t.jsx(D,{name:"close",className:"h-4 w-4"})})]},L.id)),t.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ee(L=>[...L,fi()]),disabled:se,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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>de(null),disabled:se,children:s("settings.common.actions.cancel")}),t.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:se,children:s("settings.common.actions.saveChanges")})]})]})]})}):null,n?t.jsx(Lt,{open:Je,onOpenChange:ue,children:t.jsxs(Ft,{className:"sm:max-w-lg",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("settings.remoteInstances.direct.import.action")}),t.jsx(_t,{children:s("settings.remoteInstances.direct.import.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),kn()},children:[t.jsx(Xe,{className:"h-8",value:Pe,onChange:L=>Oe(L.target.value),placeholder:s("settings.remoteInstances.direct.import.placeholder"),disabled:se,autoFocus:!0}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ue(!1),disabled:se,children:s("settings.common.actions.cancel")}),t.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:se||!Pe.trim(),children:s("settings.remoteInstances.direct.import.action")})]})]})]})}):null,t.jsx(Lt,{open:Qe,onOpenChange:We,children:t.jsxs(Ft,{className:xt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s(xt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),t.jsx(_t,{children:s(xt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),xt==="configure"?t.jsxs("form",{className:"space-y-4",onSubmit:L=>{L.preventDefault(),aa()},children:[t.jsx(Xe,{className:"h-8",value:Ye,onChange:L=>_e(L.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:!!Zt?.relayAvailable},{key:"lan",label:s("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:s("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Zt?.lanUrl},{key:"local",label:s("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:s("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Zt?.localUrl}].map(L=>{const ke=Gt===L.key;return t.jsxs("div",{className:oe("flex items-start gap-2 py-0.5",L.available?"cursor-pointer":"opacity-45"),onClick:()=>{L.available&&cs(L.key)},role:"presentation",children:[t.jsx(tn,{checked:ke,disabled:!L.available,onChange:()=>cs(L.key),ariaLabel:L.label,className:"mt-0.5"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:oe("typography-ui-label font-normal",ke?"text-foreground":"text-foreground/70"),children:L.label}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:L.hint})]})]},L.key)})}),Gt==="lan"?t.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[t.jsx(bt,{checked:ds,onChange:xs,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,Gt==="relay"&&Zt?.lanUrl?t.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[t.jsx(bt,{checked:ds,onChange:xs,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]}),ft?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ft}):null,t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>We(!1),disabled:ht,children:s("settings.common.actions.cancel")}),t.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:ht||!Zt,children:s("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):t.jsxs("div",{className:"space-y-3",children:[Nt?t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:Nt,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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Sa,children:[t.jsx(D,{name:me?"check":"file-copy",className:oe("h-3.5 w-3.5",me&&"text-[var(--status-success)]")}),s(me?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,t.jsx("div",{className:"flex justify-end",children:t.jsx(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>We(!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(G,{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(L=>{const ke=r[L.id],tt=L.nickname?.trim()||L.sshParsed?.destination||L.id,ut=ke?.phase,Wt=ut==="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 ${cl(ut)}`}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:tt})]}),t.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[s(ll(ut)),ke?.localUrl?` · ${ke.localUrl}`:""]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Wt?A(L.id):x(L.id)).catch(is=>W.error(s(Wt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:is instanceof Error?is.message:String(is)}))},children:[Wt?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(Wt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),t.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>R(L.id),children:[t.jsx(D,{name:"pencil",className:"h-3.5 w-3.5"}),s("desktopHostSwitcher.actions.edit")]}),t.jsxs(G,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(s("settings.remoteInstances.page.confirm.removeInstance"))&&h(L.id).catch(is=>W.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:is instanceof Error?is.message:String(is)}))},children:[t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]},L.id)})})]}):null,n?t.jsx(Lt,{open:vt,onOpenChange:jt,children:t.jsxs(Ft,{className:"sm:max-w-lg",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("settings.remoteInstances.sidebar.actions.addSshInstance")}),t.jsx(_t,{children:s("settings.remoteInstances.page.section.instanceDescription")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),ot()},children:[t.jsx(Xe,{className:"h-8",value:Bt,onChange:L=>ys(L.target.value),placeholder:s("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:c}),t.jsx(Xe,{className:"h-8",value:qt,onChange:L=>es(L.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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>jt(!1),disabled:c,children:s("settings.common.actions.cancel")}),t.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:c||!qt.trim(),children:s("settings.common.actions.create")})]})]})]})}):null,n?t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.import.sectionTitle")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:d?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.loading")}):i.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.noneFound")}):t.jsx("div",{children:i.map(L=>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:[L.host,L.pattern?` ${s("settings.remoteInstances.page.import.patternSuffix")}`:""]}),t.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:L.sshCommand})]}),t.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yr(L.host,L.pattern)},children:s("settings.common.actions.import")})]},`${L.source}:${L.host}`))})})]}):null,t.jsx(Lt,{open:!!J,onOpenChange:L=>{L||Un()},children:t.jsxs(Ft,{className:"sm:max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx(_t,{children:J?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:J}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),Ia()},children:[t.jsx(Xe,{value:ee,onChange:L=>Q(L.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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Un,disabled:N,children:s("settings.common.actions.cancel")}),t.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:N,children:s("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Ti=y.remoteOpenchamber.mode==="managed",id=y.nickname?.trim()||y.sshParsed?.destination||y.id;return t.jsx(Lt,{open:!!y,onOpenChange:L=>{L||R(null)},children:t.jsxs(Ft,{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:id}),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 ${cl($s)}`}),t.jsx("span",{children:s(ll($s))}),Ps?.localUrl?t.jsx("span",{className:"font-mono text-foreground/80",children:Ps.localUrl}):null,dn?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(G,{type:"button",variant:Vs?"outline":"default",size:"xs",className:"!font-normal",onClick:zs,disabled:O||$,children:[Vs?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"}),rd]}),t.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Qs,disabled:!ra,children:[t.jsx(D,{name:"refresh",className:`h-3.5 w-3.5 ${Rs||As&&!dn?"animate-spin":""}`}),Bn]}),t.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pa()},children:[t.jsx(D,{name:"terminal-window",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.logs")]}),t.jsxs(G,{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"))&&h(y.id).then(()=>{R(null),W.success(s("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(ke=>{W.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ke instanceof Error?ke.message:String(ke)})})},children:[t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.sidebar.actions.remove")]})]}),Ps?.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:Ps.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:y.sshCommand,onChange:L=>ts(ke=>({...ke,sshCommand:L.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:y.nickname||"",onChange:L=>ts(ke=>({...ke,nickname:L.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(ks,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:y.connectionTimeoutSec,onValueChange:L=>{ts(ke=>({...ke,connectionTimeoutSec:Number.isFinite(L)?L:ke.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(Dt,{value:y.remoteOpenchamber.mode,onValueChange:L=>ts(ke=>({...ke,remoteOpenchamber:{...ke.remoteOpenchamber,mode:L==="external"?"external":"managed"}})),children:[t.jsx(Et,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(zt,{placeholder:s("settings.remoteInstances.page.field.modePlaceholder")})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"managed",children:s("settings.remoteInstances.page.field.modeManaged")}),t.jsx(mt,{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(ks,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.remoteOpenchamber.preferredPort,onValueChange:L=>{ts(ke=>({...ke,remoteOpenchamber:{...ke.remoteOpenchamber,preferredPort:Number.isFinite(L)&&L>0?L:void 0}}))},onClear:()=>{ts(L=>({...L,remoteOpenchamber:{...L.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]}),Ti?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(Dt,{value:y.remoteOpenchamber.installMethod,onValueChange:L=>ts(ke=>({...ke,remoteOpenchamber:{...ke.remoteOpenchamber,installMethod:L==="npm"||L==="download_release"||L==="upload_bundle"?L:"bun"}})),children:[t.jsx(Et,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(zt,{placeholder:s("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"bun",children:"bun"}),t.jsx(mt,{value:"npm",children:"npm"}),t.jsx(mt,{value:"download_release",children:s("settings.remoteInstances.page.field.installMethodDownloadRelease")}),t.jsx(mt,{value:"upload_bundle",children:s("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,Ti?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(or,{checked:y.remoteOpenchamber.keepRunning,onCheckedChange:L=>ts(ke=>({...ke,remoteOpenchamber:{...ke.remoteOpenchamber,keepRunning:L}}))})})]}):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(Dt,{value:y.localForward.bindHost,onValueChange:L=>{L==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ts(ke=>({...ke,localForward:{...ke.localForward,bindHost:L==="localhost"||L==="0.0.0.0"?L:"127.0.0.1"}}))},children:[t.jsx(Et,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(zt,{placeholder:s("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"127.0.0.1",children:"127.0.0.1"}),t.jsx(mt,{value:"localhost",children:"localhost"}),t.jsx(mt,{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(ks,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.localForward.preferredLocalPort,onValueChange:L=>{ts(ke=>({...ke,localForward:{...ke.localForward,preferredLocalPort:Number.isFinite(L)&&L>0?L:void 0}}))},onClear:()=>{ts(L=>({...L,localForward:{...L.localForward,preferredLocalPort:void 0}}))},emptyLabel:s("settings.remoteInstances.page.field.auto")}),t.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:s("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ts(L=>({...L,localForward:{...L.localForward,preferredLocalPort:hi()}})),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:y.auth.sshPassword?.value||"",onChange:L=>ts(ke=>({...ke,auth:{...ke.auth,sshPassword:{enabled:L.target.value.trim().length>0,value:L.target.value,store:ke.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:y.auth.openchamberPassword?.value||"",onChange:L=>ts(ke=>({...ke,auth:{...ke.auth,openchamberPassword:{enabled:L.target.value.trim().length>0,value:L.target.value,store:ke.auth.openchamberPassword?.store||"never"}}})),placeholder:s("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.portForwards")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.portForwardsDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[y.portForwards.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:s("settings.remoteInstances.page.empty.noExtraForwards")}):null,y.portForwards.map((L,ke)=>{const tt=Ot=>{ts(as=>({...as,portForwards:as.portForwards.map((oa,$t)=>$t===ke?Ot(oa):oa)}))},ut=L.type==="remote"?"Local target":"Local listen",Wt=L.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.",Us=L.type==="remote"?"Remote listen":"Remote target",is=L.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",pn=dl(L.localHost||"localhost",L.localPort),Cn=dl(L.remoteHost||"localhost",L.remotePort),Ys=L.type==="local"&&typeof L.localPort=="number"&&L.localPort>0,br=Ys?`http://${Ix(L.localHost)}:${L.localPort}`:"",ia=!!B[L.id],vr=L.type==="local"?s("settings.remoteInstances.page.forwardType.local"):L.type==="remote"?s("settings.remoteInstances.page.forwardType.remote"):s("settings.remoteInstances.page.forwardType.dynamic");return t.jsxs(Mn,{open:ia,onOpenChange:Ot=>{F(as=>({...as,[L.id]:Ot}))},className:`${ke>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(Tn,{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 ${ia?"rotate-180":""}`}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Nx(L)}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:vr})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(or,{checked:L.enabled,onCheckedChange:Ot=>tt(as=>({...as,enabled:Ot})),"aria-label":s("settings.remoteInstances.page.actions.enableForwardAria")}),t.jsx(G,{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:()=>ts(Ot=>({...Ot,portForwards:Ot.portForwards.filter(as=>as.id!==L.id)})),children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Rn,{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(Cx(L.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(Dt,{value:L.type,onValueChange:Ot=>tt(as=>({...as,type:Ot==="dynamic"||Ot==="remote"?Ot:"local"})),children:[t.jsx(Et,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(zt,{placeholder:s("settings.remoteInstances.page.field.typePlaceholder")})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"local",children:s("settings.remoteInstances.page.forwardType.local")}),t.jsx(mt,{value:"remote",children:s("settings.remoteInstances.page.forwardType.remote")}),t.jsx(mt,{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:ut,hint:Wt})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(Xe,{className:"h-7 w-32",value:L.localHost||"127.0.0.1",onChange:Ot=>tt(as=>({...as,localHost:Ot.target.value})),placeholder:s("settings.remoteInstances.page.field.localHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(ks,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:L.localPort,onValueChange:Ot=>{tt(as=>({...as,localPort:Number.isFinite(Ot)&&Ot>0?Ot:void 0}))},onClear:()=>{tt(Ot=>({...Ot,localPort:void 0}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]})]}),L.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:Us,hint:is})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(Xe,{className:"h-7 w-32",value:L.remoteHost||"",onChange:Ot=>tt(as=>({...as,remoteHost:Ot.target.value})),placeholder:s("settings.remoteInstances.page.field.remoteHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(ks,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:L.remotePort,onValueChange:Ot=>{tt(as=>({...as,remotePort:Number.isFinite(Ot)&&Ot>0?Ot:void 0}))},onClear:()=>{tt(Ot=>({...Ot,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:L.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:pn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.localSocks5")})]}):L.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:Cn}),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:pn}),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:pn}),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:Cn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.remote")})]})}),Ys?t.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{on(br).then(Ot=>{Ot||W.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]})]})})]},L.id)}),t.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const L=kx();ts(ke=>({...ke,portForwards:[...ke.portForwards,L]})),F(ke=>({...ke,[L.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(G,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{un()},disabled:!Js||c,children:s("settings.common.actions.saveChanges")}),Ps?.localUrl?t.jsxs(t.Fragment,{children:[t.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{En(Ps.localUrl||"").then(L=>{L.ok&&W.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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ns()},children:[t.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.open")]})]}):null,f?t.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:f}):null]})}),t.jsx(Lt,{open:E,onOpenChange:K,children:t.jsxs(Ft,{className:"sm:max-w-2xl",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("settings.remoteInstances.page.logsDialog.title")}),t.jsx(_t,{children:y?.nickname?.trim()||y?.sshParsed?.destination||y?.id||s("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:gt,disabled:U||!w.trim(),children:[t.jsx(D,{name:"file-copy",className:"h-3.5 w-3.5"}),s("settings.common.actions.copyAll")]}),t.jsxs(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{At()},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")}):I?t.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:I}):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(Lt,{open:!!J,onOpenChange:L=>{L||Un()},children:t.jsxs(Ft,{className:"sm:max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx(_t,{children:J?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:J}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),Ia()},children:[t.jsx(Xe,{value:ee,onChange:L=>Q(L.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(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Un,disabled:N,children:s("settings.common.actions.cancel")}),t.jsx(G,{type:"submit",size:"xs",className:"!font-normal",disabled:N,children:s("settings.common.actions.create")})]})]})]})})]})})},Rx="__add_provider__",Lx=()=>{const s=js.getDirectory();return typeof s=="string"&&s.trim().length>0?s.trim():null},Fx=({onItemSelect:s})=>{const{t:e}=st(),n=it(u=>u.providers),a=it(u=>u.selectedProviderId),r=it(u=>u.setSelectedProvider),i=ss(u=>u.activeProjectId),[l,d]=o.useState({}),c=o.useMemo(()=>Lx(),[i]);o.useEffect(()=>{if(n.length===0){d({});return}let u=!1;return(async()=>{const g=n.map(async h=>{try{const x=c?`?directory=${encodeURIComponent(c)}`:"",A=await dt(`/api/provider/${encodeURIComponent(h.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const S=await A.json().catch(()=>null),C=S?.sources??S?.data?.sources;if(!C||u)return;d(R=>({...R,[h.id]:C}))}catch{}});await Promise.all(g)})(),()=>{u=!0}},[c,n]);const f="bg-background",m=o.useMemo(()=>n.filter(u=>!!l[u.id]?.project?.exists),[n,l]),p=o.useMemo(()=>n.filter(u=>!l[u.id]?.project?.exists),[n,l]);return t.jsxs("div",{className:oe("flex h-full flex-col",f),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(ka,{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(G,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(Rx),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:[p.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),p.map(u=>t.jsx(ml,{provider:u,selectedProviderId:a,onSelect:()=>{r(u.id),s?.()}},u.id))]}),m.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:oe("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",p.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(u=>t.jsx(ml,{provider:u,selectedProviderId:a,onSelect:()=>{r(u.id),s?.()}},u.id))]})]})})]})},ml=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,d=n.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==c?(f=oe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=f):f=e[1];let m;e[2]!==n.id?(m=t.jsx(Xn,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const p=n.name||n.id;let u;e[4]!==p?(u=t.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:p}),e[4]=p,e[5]=u):u=e[5];let j;e[6]!==i?(j=t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=j):j=e[7];let g;e[8]!==r||e[9]!==m||e[10]!==u||e[11]!==j?(g=t.jsxs("button",{type:"button",onClick:r,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,u,j]}),e[8]=r,e[9]=m,e[10]=u,e[11]=j,e[12]=g):g=e[12];let h;return e[13]!==n.id||e[14]!==f||e[15]!==g?(h=t.jsx("div",{className:f,children:g},d),e[13]=n.id,e[14]=f,e[15]=g,e[16]=h):h=e[16],h},Ox=s=>s,zx=s=>new Intl.NumberFormat(ki(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(s),pl=s=>{if(typeof s!="number"||Number.isNaN(s))return null;if(s===0)return"0";const e=zx(s);return e.endsWith(".0")?e.slice(0,-2):e},$a="__add_provider__",ta=s=>typeof s=="object"&&s!==null,gl=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(!ta(s))return{};const e={};for(const[n,a]of Object.entries(s))Array.isArray(a)&&(e[n]=a.filter(r=>ta(r)));return e},Kx=s=>{if(typeof s=="string")return{id:s};if(!ta(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}},Bx=s=>{let e=[];Array.isArray(s)?e=s:ta(s)&&(Array.isArray(s.all)?e=s.all:Array.isArray(s.providers)&&(e=s.providers));const n=e.map(r=>Kx(r)).filter(r=>!!r),a=new Set;return n.filter(r=>a.has(r.id)?!1:(a.add(r.id),!0))},$x=()=>{const{t:s}=st(),e=it(H=>H.providers),n=it(H=>H.selectedProviderId),a=it(H=>H.setSelectedProvider),r=it(H=>H.getModelMetadata),i=Fe(H=>H.hiddenModels),l=Fe(H=>H.toggleHiddenModel),d=Fe(H=>H.hideAllModels),c=Fe(H=>H.showAllModels),[f,m]=o.useState({}),[p,u]=o.useState(!1),[j,g]=o.useState({}),[h,x]=o.useState(null),[A,S]=o.useState(""),[C,R]=o.useState(null),[k,y]=o.useState({}),[v,E]=o.useState({}),[K,U]=o.useState([]),[M,I]=o.useState(!1),[P,z]=o.useState(null),[T,J]=o.useState(""),[_,ee]=o.useState(""),[Q,N]=o.useState(!1),[V,B]=o.useState({}),[F,O]=o.useState(!1),q=n===$a;o.useEffect(()=>{!n&&e.length>0&&a(e[0].id)},[e,n,a]),o.useEffect(()=>{if(!q)return;let H=!0;return(async()=>{u(!0);try{const re=await js.getSdkClient().provider.auth();if(re.error)throw new Error(`provider.auth failed: ${String(re.error)}`);if(!H)return;m(Ux(re.data))}catch(re){if(!H)return;console.error("Failed to load provider auth methods:",re),W.error(s("settings.providers.page.toast.authMethodsLoadFailed"))}finally{H&&u(!1)}})(),()=>{H=!1}},[q,s]),o.useEffect(()=>{if(!Ox(q))return;let H=!0;return(async()=>{I(!0),z(null);try{const re=await js.getSdkClient().provider.list();if(re.error)throw new Error(`provider.list failed: ${String(re.error)}`);if(!H)return;U(Bx(re.data))}catch(re){if(!H)return;console.error("Failed to load available providers:",re),z(s("settings.providers.page.state.unableToLoadProviderList"))}finally{H&&I(!1)}})(),()=>{H=!1}},[q,s]);const $=o.useMemo(()=>new Set(e.map(H=>H.id)),[e]),ie=o.useMemo(()=>K.filter(H=>!$.has(H.id)).sort((H,te)=>{const re=(H.name||H.id).toLowerCase(),pe=(te.name||te.id).toLowerCase();return re.localeCompare(pe)}),[K,$]);o.useEffect(()=>{n===$a&&T&&!ie.some(H=>H.id===T)&&J("")},[n,T,ie]),o.useEffect(()=>{if(n===$a){O(!0);return}O(!1)},[n,s]),o.useEffect(()=>{if(!n||n===$a)return;let H=!1;return(async()=>{try{const re=await dt(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),pe=await re.json().catch(()=>null);if(!re.ok)throw new Error(pe?.error||s("settings.providers.page.toast.providerSourcesLoadFailed"));const Me=pe?.sources??pe?.data?.sources;!H&&Me&&B(Se=>({...Se,[n]:Me}))}catch(re){H||console.error("Failed to load provider sources:",re)}})(),()=>{H=!0}},[n,s]);const le=e.find(H=>H.id===n),ne=n?V[n]:void 0,ye=async H=>{const te=j[H]?.trim()??"";if(!te){W.error(s("settings.providers.page.toast.apiKeyRequired"));return}const re=`api:${H}`;x(re);try{if((await js.getSdkClient().auth.set({providerID:H,auth:{type:"api",key:te}})).error)throw new Error(s("settings.providers.page.toast.apiKeySaveFailed"));W.success(s("settings.providers.page.toast.apiKeySaved")),g(Me=>({...Me,[H]:""})),await Qn({scopes:["providers"],mode:"active"}),a(H)}catch(pe){console.error("Failed to save API key:",pe),W.error(s("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},ae=async(H,te)=>{const re=`oauth:${H}:${te}`;x(re);try{const pe=await js.getSdkClient().provider.oauth.authorize({providerID:H,method:te});if(pe.error)throw new Error(s("settings.providers.page.toast.oauthStartFailed"));const Me=ta(pe.data)?pe.data:{},Se=Me.data,Ae=ta(Se)?Se:Me,De=typeof Ae.url=="string"&&Ae.url||typeof Ae.verification_uri_complete=="string"&&Ae.verification_uri_complete||typeof Ae.verification_uri=="string"&&Ae.verification_uri||void 0,Pe=typeof Ae.instructions=="string"&&Ae.instructions||typeof Ae.message=="string"&&Ae.message||void 0,Oe=typeof Ae.user_code=="string"&&Ae.user_code||typeof Ae.code=="string"&&Ae.code||typeof Ae.userCode=="string"&&Ae.userCode||void 0;if(!De&&!Pe&&!Oe)throw new Error(s("settings.providers.page.toast.oauthDetailsMissing"));const Te=`${H}:${te}`;E(Ue=>({...Ue,[Te]:{url:De,instructions:Pe,userCode:Oe}})),De&&on(De),R({providerId:H,methodIndex:te}),W.message(s("settings.providers.page.toast.completeOAuthInBrowser"))}catch(pe){console.error("Failed to start OAuth flow:",pe),W.error(s("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},ge=async(H,te)=>{const re=`${H}:${te}`,pe=k[re]?.trim(),Me=`oauth-complete:${H}:${te}`;x(Me);try{const Se={method:te};if(pe&&(Se.code=pe),(await js.getSdkClient().provider.oauth.callback({providerID:H,method:Se.method,code:Se.code})).error)throw new Error(s("settings.providers.page.toast.oauthCompleteFailed"));W.success(s("settings.providers.page.toast.oauthCompleted")),y(De=>({...De,[re]:""})),R(null),await Qn({scopes:["providers"],mode:"active"}),a(H)}catch(Se){console.error("Failed to complete OAuth flow:",Se),W.error(s("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},Ne=async H=>{const te=await En(H);if(te.ok){W.success(s("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",te.error),W.error(s("settings.providers.page.toast.oauthLinkCopyFailed"))},he=async H=>{const te=await En(H);if(te.ok){W.success(s("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",te.error),W.error(s("settings.providers.page.toast.deviceCodeCopyFailed"))},we=async H=>{const te=`disconnect:${H}`;x(te);try{const re=await dt(`/api/provider/${encodeURIComponent(H)}/auth?scope=all`,{method:"DELETE",headers:{Accept:"application/json"}}),pe=await re.json().catch(()=>null);if(!re.ok)throw new Error(pe?.error||s("settings.providers.page.toast.providerDisconnectFailed"));W.success(s("settings.providers.page.toast.providerDisconnected")),await Qn({scopes:["providers"],mode:"active"})}catch(re){console.error("Failed to disconnect provider:",re),W.error(s("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(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")}):P?t.jsx("p",{className:"typography-meta text-muted-foreground",children:P}):ie.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.connect.allProvidersConnected")}):t.jsxs(gs,{open:Q,onOpenChange:H=>{N(H),H||ee("")},children:[t.jsx(ms,{asChild:!0,children:t.jsxs("button",{type:"button",className:oe("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(Xn,{providerId:T,className:"h-3.5 w-3.5 flex-shrink-0"}):null,t.jsx("span",{className:oe("truncate typography-ui-label font-normal",T?"text-foreground":"text-muted-foreground"),children:T?ie.find(H=>H.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:H=>H.preventDefault(),children:[t.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:H=>H.stopPropagation(),children:[t.jsx(D,{name:"search",className:"h-4 w-4 text-muted-foreground"}),t.jsx("input",{type:"text",value:_,onChange:H=>ee(H.target.value),onKeyDown:H=>H.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 H=ie.filter(te=>{const re=_.toLowerCase();return(te.name||te.id).toLowerCase().includes(re)||te.id.toLowerCase().includes(re)});return H.length===0?t.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:s("settings.providers.page.connect.noProvidersFound")}):H.map(te=>t.jsxs(Ss,{onSelect:()=>{J(te.id),N(!1),ee("")},className:"flex items-center justify-between",children:[t.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(Xn,{providerId:te.id,className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:te.name||te.id})]}),T===te.id&&t.jsx(D,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},te.id))})()})]})]})]})})]}),T&&t.jsxs("div",{"data-settings-item":"providers.auth",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.auth.title")})}),p?t.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:s("settings.providers.page.auth.loadingMethods")}):t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[t.jsxs("div",{className:"py-1.5",children:[t.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[s("settings.providers.page.auth.apiKeyLabel"),t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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:j[T]??"",onChange:H=>g(te=>({...te,[T]:H.target.value})),placeholder:s("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),t.jsx(G,{size:"xs",className:"!font-normal shrink-0",onClick:()=>ye(T),disabled:h===`api:${T}`,children:h===`api:${T}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),(()=>{const te=(f[T]??[]).filter(re=>gl(re)==="oauth");return te.length===0?null:t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:te.map((re,pe)=>{const Me=re.label||re.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String(pe+1)}),Se=`${T}:${pe}`,Ae=C?.providerId===T&&C?.methodIndex===pe;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:Me}),(re.description||re.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(re.description||re.help)})]}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ae(T,pe),disabled:h===`oauth:${T}:${pe}`,children:s("settings.providers.page.actions.connect")})]}),v[Se]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:v[Se]?.instructions}),v[Se]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:v[Se]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>he(v[Se]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),v[Se]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:v[Se]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>on(v[Se]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ne(v[Se]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),Ae&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:k[Se]??"",onChange:De=>y(Pe=>({...Pe,[Se]:De.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(G,{size:"xs",className:"!font-normal",onClick:()=>ge(T,pe),disabled:h===`oauth-complete:${T}:${pe}`,children:h===`oauth-complete:${T}:${pe}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${T}-${Me}`)})})})()]})]})]})});if(!le)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 ce=Array.isArray(le.models)?le.models:[],se=(f[le.id]??[]).filter(H=>gl(H)==="oauth"),ve=ce.filter(H=>{const te=typeof H?.name=="string"?H.name:"",re=typeof H?.id=="string"?H.id:"",pe=A.trim().toLowerCase();return pe?te.toLowerCase().includes(pe)||re.toLowerCase().includes(pe):!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(Xn,{providerId:le.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:le.name||le.id}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t.jsx("span",{className:"font-mono",children:le.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(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>O(H=>!H),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?p?t.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:s("settings.providers.page.auth.loadingMethods")}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"py-1.5",children:[t.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[s("settings.providers.page.auth.apiKeyLabel"),t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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:j[le.id]??"",onChange:H=>g(te=>({...te,[le.id]:H.target.value})),placeholder:s("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),t.jsx(G,{size:"xs",className:"!font-normal shrink-0",onClick:()=>ye(le.id),disabled:h===`api:${le.id}`,children:h===`api:${le.id}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),se.length>0&&t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:se.map((H,te)=>{const re=H.label||H.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String(te+1)}),pe=`${le.id}:${te}`,Me=C?.providerId===le.id&&C?.methodIndex===te;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:re}),(H.description||H.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(H.description||H.help)})]}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ae(le.id,te),disabled:h===`oauth:${le.id}:${te}`,children:s("settings.providers.page.actions.connect")})]}),v[pe]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:v[pe]?.instructions}),v[pe]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:v[pe]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>he(v[pe]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),v[pe]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:v[pe]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>on(v[pe]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ne(v[pe]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),Me&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:k[pe]??"",onChange:Se=>y(Ae=>({...Ae,[pe]:Se.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(G,{size:"xs",className:"!font-normal",onClick:()=>ge(le.id,te),disabled:h===`oauth-complete:${le.id}:${te}`,children:h===`oauth-complete:${le.id}:${te}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${le.id}-${re}`)})})]}):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")})]})})]}),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:ne&&(ne.auth.exists||ne.user.exists||ne.project.exists||ne.custom?.exists)?t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[s("settings.providers.page.connectionDetails.configuredIn")," ",[ne.auth.exists?s("settings.providers.page.connectionDetails.source.authCredentials"):null,ne.user.exists?s("settings.providers.page.connectionDetails.source.userConfig"):null,ne.project.exists?s("settings.providers.page.connectionDetails.source.projectConfig"):null,ne.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(G,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>we(le.id),disabled:h===`disconnect:${le.id}`,children:h===`disconnect:${le.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"),ce.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ce.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const H=ce.map(te=>typeof te?.id=="string"?te.id:"").filter(te=>te.length>0);d(le.id,H)},children:s("settings.providers.page.actions.hideAll")}),t.jsx(G,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>c(le.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:A,onChange:H=>S(H.target.value),placeholder:s("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ve.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:ve.map(H=>{const te=typeof H?.id=="string"?H.id:"",re=typeof H?.name=="string"?H.name:te,pe=te?r(le.id,te):void 0,Me=i.some(Pe=>Pe.providerID===le.id&&Pe.modelID===te),Se=pl(pe?.limit?.context),Ae=pl(pe?.limit?.output),De=[];return pe?.tool_call&&De.push({key:"tools",icon:"tools",label:s("settings.providers.page.models.capability.toolCalling")}),pe?.reasoning&&De.push({key:"reasoning",icon:"brain-ai-3",label:s("settings.providers.page.models.capability.reasoning")}),pe?.attachment&&De.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:oe("flex items-center gap-3",Me&&"opacity-50"),children:[t.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:re}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Se||Ae)&&t.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Se?`${Se} ${s("settings.providers.page.models.tokenBadge.context")}`:"",Se&&Ae?" · ":"",Ae?`${Ae} ${s("settings.providers.page.models.tokenBadge.output")}`:""]}),De.length>0&&t.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:De.map(({key:Pe,icon:Oe,label:Te})=>t.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Te,"aria-label":Te,children:t.jsx(D,{name:Oe,className:"h-3 w-3"})},Pe))}),t.jsx("button",{type:"button",onClick:()=>l(le.id,te),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:s(Me?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":s(Me?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Me?t.jsx(D,{name:"eye-off",className:"h-3.5 w-3.5"}):t.jsx(D,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},te)})})]})]})]})})},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"}];function hl(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 Vx=[{id:"gemini-auth",label:"Gemini",matcher:s=>s.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:s=>s.startsWith("antigravity/"),order:2}],Fc={google:Vx};function Oc(s,e){const n=Fc[e]??[];for(const a of n)if(a.matcher(s))return a;return null}function _x(s){return Fc[s]??[]}function Hx(s){return[...s].sort((e,n)=>e.order-n.order)}function Yj(s,e){const n=new Map;for(const a of Object.keys(s)){const i=Oc(a,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(a)}return n}function Wx(s,e,n){const a=new Map;for(const r of s){const i=e(r),d=Oc(i,n)?.id??null;a.has(d)||a.set(d,[]),a.get(d).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 Pi=6e4,fl=s=>{const e=wn.map(u=>u.id),n=typeof s?.usageAutoRefresh=="boolean"?s.usageAutoRefresh:!1,a=typeof s?.usageRefreshIntervalMs=="number"&&Number.isFinite(s.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(s.usageRefreshIntervalMs))):Pi,r=s?.usageDisplayMode==="remaining"?"remaining":"usage",i=typeof s?.usageShowPredValues=="boolean"?s.usageShowPredValues:!1,l=Array.isArray(s?.usageDropdownProviders)?s?.usageDropdownProviders:null,d=l?l.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},f=s?.usageSelectedModels;if(f&&typeof f=="object")for(const[u,j]of Object.entries(f))Array.isArray(j)&&(c[u]=j.filter(g=>typeof g=="string"));const m={},p=s?.usageExpandedFamilies;if(p&&typeof p=="object")for(const[u,j]of Object.entries(p))Array.isArray(j)&&(m[u]=j.filter(g=>typeof g=="string"));return{autoRefresh:n,refreshIntervalMs:a,displayMode:r,showPredValues:i,dropdownProviderIds:d,selectedModels:c,expandedFamilies:m}},Gx=async()=>{const s=qs()?.settings;if(s)try{const n=(await s.load())?.settings;return fl(n??null)}catch{}if(!fs()){const e=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return fl(n)}}return{autoRefresh:!1,refreshIntervalMs:Pi,displayMode:"usage",showPredValues:!1,dropdownProviderIds:wn.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Vt=Nn()(Na((s,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Pi,displayMode:"usage",showPredValues:!1,dropdownProviderIds:wn.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Gx();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 d=l.results.filter(c=>c.providerId!==n);return d.push(i),{results:d,error:null}})}catch(a){const r=a instanceof Error?a.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:r,usage:null,fetchedAt:Date.now()};s(l=>{const d=l.results.filter(c=>c.providerId!==n);return d.push(i),{results:d,error:r}})}finally{s(a=>({isFetchingProvider:{...a.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>s({selectedProviderId:n}),setAutoRefresh:n=>s({autoRefresh:n}),setRefreshInterval:n=>{const a=Math.max(3e4,Math.min(3e5,Math.round(n)));s({refreshIntervalMs:a})},setDisplayMode:n=>s({displayMode:n}),setShowPredValues:n=>s({showPredValues:n}),setDropdownProviderIds:n=>s({dropdownProviderIds:n}),setSelectedModels:(n,a)=>{s(r=>({selectedModels:{...r.selectedModels,[n]:a}}))},toggleModelSelected:(n,a)=>{s(r=>{const i=r.selectedModels[n]??[],d=i.includes(a)?i.filter(c=>c!==a):[...i,a];return{selectedModels:{...r.selectedModels,[n]:d}}})},setExpandedFamilies:(n,a)=>{s(r=>({expandedFamilies:{...r.expandedFamilies,[n]:a}})),kt({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,a)=>{s(r=>{const i=r.expandedFamilies[n]??[],d=i.includes(a)?i.filter(c=>c!==a):[...i,a];return{expandedFamilies:{...r.expandedFamilies,[n]:d}}}),kt({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}})),kt({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Jx=()=>{const s=Ze.c(5),e=Vt(Qx),n=Vt(Yx),a=Vt(Xx);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 Qx(s){return s.autoRefresh}function Yx(s){return s.refreshIntervalMs}function Xx(s){return s.fetchAllQuotas}const Zx=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)},ey=s=>{const e=Ze.c(122),{onItemSelect:n}=s,{t:a}=st(),r=Vt(ty),i=Vt(sy),l=Vt(ny),d=Vt(ay),c=Vt(ry),f=Vt(iy),m=Vt(oy),p=Vt(ly),u=Vt(cy),j=Vt(dy),g=Vt(uy),h=Vt(my),x=Vt(py),A=Vt(gy);let S,C;e[0]!==A?(S=()=>{A()},C=[A],e[0]=A,e[1]=S,e[2]=C):(S=e[1],C=e[2]),o.useEffect(S,C);const R=hy;let k;e[3]!==u?(k=je=>{u(je),R({usageAutoRefresh:je})},e[3]=u,e[4]=k):k=e[4];const y=k;let v;e[5]!==j?(v=je=>{const Re=Number(je);Number.isFinite(Re)&&(j(Re),R({usageRefreshIntervalMs:Re}))},e[5]=j,e[6]=v):v=e[6];const E=v;let K;e[7]!==g?(K=je=>{je!=="usage"&&je!=="remaining"||(g(je),R({usageDisplayMode:je}))},e[7]=g,e[8]=K):K=e[8];const U=K;let M;e[9]!==x?(M=je=>{x(je),R({usageShowPredValues:je})},e[9]=x,e[10]=M):M=e[10];const I=M;let P;e[11]===Symbol.for("react.memo_cache_sentinel")?(P=oe("flex h-full flex-col","bg-background"),e[11]=P):P=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 J;e[16]!==a?(J=a("settings.usage.sidebar.total",{count:wn.length}),e[16]=a,e[17]=J):J=e[17];let _;e[18]!==J?(_=t.jsx("span",{className:"typography-meta text-muted-foreground",children:J}),e[18]=J,e[19]=_):_=e[19];let ee;e[20]!==a?(ee=a("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[20]=a,e[21]=ee):ee=e[21];let Q;e[22]!==y||e[23]!==ee||e[24]!==f?(Q=t.jsx(It,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:t.jsx(bt,{checked:f,onChange:y,ariaLabel:ee})})}),e[22]=y,e[23]=ee,e[24]=f,e[25]=Q):Q=e[25];let N;e[26]!==a?(N=a("settings.usage.sidebar.tooltip.autoRefresh"),e[26]=a,e[27]=N):N=e[27];let V;e[28]!==N?(V=t.jsx(Pt,{side:"bottom",children:N}),e[28]=N,e[29]=V):V=e[29];let B;e[30]!==Q||e[31]!==V?(B=t.jsxs(Ct,{children:[Q,V]}),e[30]=Q,e[31]=V,e[32]=B):B=e[32];const F=String(m),O=!f;let q;e[33]!==a?(q=a("settings.usage.sidebar.field.intervalPlaceholder"),e[33]=a,e[34]=q):q=e[34];let $;e[35]!==q?($=t.jsx(Et,{className:"w-fit",children:t.jsx(zt,{placeholder:q})}),e[35]=q,e[36]=$):$=e[36];let ie;e[37]===Symbol.for("react.memo_cache_sentinel")?(ie=t.jsxs(Mt,{children:[t.jsx(mt,{value:"30000",children:"30s"}),t.jsx(mt,{value:"60000",children:"1m"}),t.jsx(mt,{value:"300000",children:"5m"})]}),e[37]=ie):ie=e[37];let le;e[38]!==E||e[39]!==F||e[40]!==O||e[41]!==$?(le=t.jsxs(Dt,{value:F,onValueChange:E,disabled:O,children:[$,ie]}),e[38]=E,e[39]=F,e[40]=O,e[41]=$,e[42]=le):le=e[42];let ne;e[43]!==d?(ne=()=>d(),e[43]=d,e[44]=ne):ne=e[44];let ye;e[45]!==a?(ye=a("settings.usage.sidebar.actions.refreshAria"),e[45]=a,e[46]=ye):ye=e[46];let ae;e[47]!==a?(ae=a("settings.usage.sidebar.actions.refreshTitle"),e[47]=a,e[48]=ae):ae=e[48];const ge=c&&"animate-spin";let Ne;e[49]!==ge?(Ne=oe("h-3.5 w-3.5",ge),e[49]=ge,e[50]=Ne):Ne=e[50];let he;e[51]!==Ne?(he=t.jsx(D,{name:"refresh",className:Ne}),e[51]=Ne,e[52]=he):he=e[52];let we;e[53]!==c||e[54]!==ne||e[55]!==ye||e[56]!==ae||e[57]!==he?(we=t.jsx(G,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ne,"aria-label":ye,title:ae,disabled:c,children:he}),e[53]=c,e[54]=ne,e[55]=ye,e[56]=ae,e[57]=he,e[58]=we):we=e[58];let ce;e[59]!==B||e[60]!==le||e[61]!==we?(ce=t.jsxs("div",{className:"flex items-center gap-2",children:[B,le,we]}),e[59]=B,e[60]=le,e[61]=we,e[62]=ce):ce=e[62];let Z;e[63]!==_||e[64]!==ce?(Z=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[_,ce]}),e[63]=_,e[64]=ce,e[65]=Z):Z=e[65];let se;e[66]!==a?(se=a("settings.usage.sidebar.field.display"),e[66]=a,e[67]=se):se=e[67];let ve;e[68]!==se?(ve=t.jsx("span",{className:"typography-micro text-muted-foreground",children:se}),e[68]=se,e[69]=ve):ve=e[69];let H;e[70]!==a?(H=a("settings.usage.sidebar.field.displayModePlaceholder"),e[70]=a,e[71]=H):H=e[71];let te;e[72]!==H?(te=t.jsx(Et,{className:"w-fit",children:t.jsx(zt,{placeholder:H})}),e[72]=H,e[73]=te):te=e[73];let re;e[74]!==a?(re=a("settings.usage.sidebar.field.displayModeUsage"),e[74]=a,e[75]=re):re=e[75];let pe;e[76]!==re?(pe=t.jsx(mt,{value:"usage",children:re}),e[76]=re,e[77]=pe):pe=e[77];let Me;e[78]!==a?(Me=a("settings.usage.sidebar.field.displayModeRemaining"),e[78]=a,e[79]=Me):Me=e[79];let Se;e[80]!==Me?(Se=t.jsx(mt,{value:"remaining",children:Me}),e[80]=Me,e[81]=Se):Se=e[81];let Ae;e[82]!==pe||e[83]!==Se?(Ae=t.jsxs(Mt,{children:[pe,Se]}),e[82]=pe,e[83]=Se,e[84]=Ae):Ae=e[84];let De;e[85]!==U||e[86]!==te||e[87]!==Ae||e[88]!==p?(De=t.jsxs(Dt,{value:p,onValueChange:U,children:[te,Ae]}),e[85]=U,e[86]=te,e[87]=Ae,e[88]=p,e[89]=De):De=e[89];let Pe;e[90]!==ve||e[91]!==De?(Pe=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ve,De]}),e[90]=ve,e[91]=De,e[92]=Pe):Pe=e[92];let Oe;e[93]!==a?(Oe=a("settings.usage.sidebar.field.showPredictions"),e[93]=a,e[94]=Oe):Oe=e[94];let Te;e[95]!==Oe?(Te=t.jsx("span",{className:"typography-micro text-muted-foreground",children:Oe}),e[95]=Oe,e[96]=Te):Te=e[96];let Ue;e[97]!==a?(Ue=a("settings.usage.sidebar.field.showPredictions"),e[97]=a,e[98]=Ue):Ue=e[98];let Be;e[99]!==I||e[100]!==h||e[101]!==Ue?(Be=t.jsx(bt,{checked:h,onChange:I,ariaLabel:Ue}),e[99]=I,e[100]=h,e[101]=Ue,e[102]=Be):Be=e[102];let Ke;e[103]!==Te||e[104]!==Be?(Ke=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[Te,Be]}),e[103]=Te,e[104]=Be,e[105]=Ke):Ke=e[105];let Je;e[106]!==Z||e[107]!==Pe||e[108]!==Ke||e[109]!==T?(Je=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,Z,Pe,Ke]}),e[106]=Z,e[107]=Pe,e[108]=Ke,e[109]=T,e[110]=Je):Je=e[110];let ue;e[111]!==n||e[112]!==r||e[113]!==i||e[114]!==l||e[115]!==a?(ue=wn.map(je=>{const Re=r.find(Ee=>Ee.providerId===je.id),Ie=Zx(Re?.usage),Ve=uc(Ie),X=je.id===i,b=Re?.configured??!1,be=b?Ve==="critical"?{backgroundColor:"var(--status-error)"}:Ve==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return t.jsx("div",{className:oe("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(je.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(Xn,{providerId:je.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:je.name}),!b&&t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:a("settings.usage.sidebar.status.notSet")})]})},je.id)}),e[111]=n,e[112]=r,e[113]=i,e[114]=l,e[115]=a,e[116]=ue):ue=e[116];let Y;e[117]!==ue?(Y=t.jsx(Ht,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:ue}),e[117]=ue,e[118]=Y):Y=e[118];let de;return e[119]!==Je||e[120]!==Y?(de=t.jsxs("div",{className:P,children:[Je,Y]}),e[119]=Je,e[120]=Y,e[121]=de):de=e[121],de};function ty(s){return s.results}function sy(s){return s.selectedProviderId}function ny(s){return s.setSelectedProvider}function ay(s){return s.fetchAllQuotas}function ry(s){return s.isLoading}function iy(s){return s.autoRefresh}function oy(s){return s.refreshIntervalMs}function ly(s){return s.displayMode}function cy(s){return s.setAutoRefresh}function dy(s){return s.setRefreshInterval}function uy(s){return s.setDisplayMode}function my(s){return s.showPredValues}function py(s){return s.setShowPredValues}function gy(s){return s.loadSettings}async function hy(s){try{await kt(s)}catch(e){console.warn("Failed to save usage settings:",e)}}const fy=s=>{const e=Ze.c(20),{percent:n,tonePercent:a,className:r,expectedMarkerPercent:i}=s;let l;e[0]!==n?(l=Wu(n)??0,e[0]=n,e[1]=l):l=e[1];const d=l,c=a??n;let f;e[2]!==c?(f=uc(c),e[2]=c,e[3]=f):f=e[3];const m=f,p=i!=null?Math.max(0,Math.min(100,i)):null;let u;e[4]!==m?(u=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=u):u=e[5];const j=u;let g;e[6]!==r?(g=oe("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=g):g=e[7];const h=`${d}%`;let x;e[8]!==j||e[9]!==h?(x={...j,width:h},e[8]=j,e[9]=h,e[10]=x):x=e[10];let A;e[11]!==d||e[12]!==x?(A=t.jsx("div",{className:"h-full transition-all duration-300",style:x,role:"progressbar","aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100}),e[11]=d,e[12]=x,e[13]=A):A=e[13];let S;e[14]!==p?(S=p!=null&&p>0&&p<100&&t.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${p}%`},title:`Expected usage if spread evenly: ${Math.round(p)}% of quota`,"aria-hidden":"true"}),e[14]=p,e[15]=S):S=e[15];let C;return e[16]!==g||e[17]!==A||e[18]!==S?(C=t.jsxs("div",{className:g,children:[A,S]}),e[16]=g,e[17]=A,e[18]=S,e[19]=C):C=e[19],C},xy=s=>{const e=Ze.c(67),{paceInfo:n,className:a,compact:r}=s,i=r===void 0?!1:r,{t:l}=st();let d;e[0]!==n.status?(d=qu(n.status),e[0]=n.status,e[1]=d):d=e[1];const c=d;let f;e:{switch(n.status){case"on-track":{let v;e[2]!==l?(v=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=v):v=e[3],f=v;break e}case"slightly-fast":{let v;e[4]!==l?(v=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=v):v=e[5],f=v;break e}case"too-fast":{let v;e[6]!==l?(v=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=v):v=e[7],f=v;break e}case"exhausted":{let v;e[8]!==l?(v=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=v):v=e[9],f=v;break e}}f=void 0}const m=f;let p;e[10]!==n.predictText||e[11]!==l?(p=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=p):p=e[12];const u=p;if(i){let v;e[13]!==a?(v=oe("flex items-center gap-1.5",a),e[13]=a,e[14]=v):v=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:u;let I;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(I=n.isExhausted?t.jsx(t.Fragment,{children:l("settings.usage.pace.wait",{duration:Hi(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]=I):I=e[26];let P;e[27]!==I||e[28]!==U||e[29]!==M?(P=t.jsx("span",{className:"typography-micro tabular-nums",style:U,title:M,children:I}),e[27]=I,e[28]=U,e[29]=M,e[30]=P):P=e[30];let z;return e[31]!==P||e[32]!==v||e[33]!==K?(z=t.jsxs("div",{className:v,children:[K,P]}),e[31]=P,e[32]=v,e[33]=K,e[34]=z):z=e[34],z}let j;e[35]!==a?(j=oe("flex items-center justify-between gap-2",a),e[35]=a,e[36]=j):j=e[36];let g;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(g=!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]=g):g=e[40];let h;e[41]!==g?(h=t.jsx("div",{className:"flex items-center gap-1.5",children:g}),e[41]=g,e[42]=h):h=e[42];let x;e[43]!==c?(x={color:c},e[43]=c,e[44]=x):x=e[44];let A;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==u||e[49]!==m||e[50]!==l?(A=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:Hi(n.remainingSeconds)})]}):t.jsxs("span",{title:u,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]=u,e[49]=m,e[50]=l,e[51]=A):A=e[51];let S;e[52]!==x||e[53]!==A?(S=t.jsx("span",{className:"typography-micro tabular-nums",style:x,children:A}),e[52]=x,e[53]=A,e[54]=S):S=e[54];let C;e[55]!==c?(C={backgroundColor:c},e[55]=c,e[56]=C):C=e[56];let R;e[57]!==m||e[58]!==C?(R=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]=R):R=e[59];let k;e[60]!==S||e[61]!==R?(k=t.jsxs("div",{className:"flex items-center gap-1.5",children:[S,R]}),e[60]=S,e[61]=R,e[62]=k):k=e[62];let y;return e[63]!==k||e[64]!==j||e[65]!==h?(y=t.jsxs("div",{className:j,children:[h,k]}),e[63]=k,e[64]=j,e[65]=h,e[66]=y):y=e[66],y},Br=s=>{const e=Ze.c(54),{title:n,window:a,subtitle:r,showToggle:i,toggleEnabled:l,onToggle:d}=s,c=i===void 0?!1:i,f=l===void 0?!1:l,m=Vt(yy),p=Vt(by),u=Fe(vy),j=m==="remaining"?a.remainingPercent:a.usedPercent,g=m==="remaining"?"remaining":"used";let h;e[0]!==j||e[1]!==a.valueLabel?(h=Gu(a.valueLabel,j),e[0]=j,e[1]=a.valueLabel,e[2]=h):h=e[2];const x=h,A=a.resetAfterFormatted??a.resetAtFormatted;let S;e[3]!==A||e[4]!==u||e[5]!==a.resetAt?(S=Ju(a.resetAt,A,u),e[3]=A,e[4]=u,e[5]=a.resetAt,e[6]=S):S=e[6];const C=S;let R;e[7]!==n?(R=Qu(n),e[7]=n,e[8]=R):R=e[8];const k=R;let y;e[9]!==n||e[10]!==a.resetAt||e[11]!==a.usedPercent||e[12]!==a.windowSeconds?(y=Yu(a.usedPercent,a.resetAt,a.windowSeconds,n),e[9]=n,e[10]=a.resetAt,e[11]=a.usedPercent,e[12]=a.windowSeconds,e[13]=y):y=e[13];const v=y;let E;e:{if(!v||v.dailyAllocationPercent===null){E=null;break e}const $=Xu(v.elapsedRatio);E=m==="remaining"?100-$:$}const K=E;let U;e[14]!==d||e[15]!==c||e[16]!==f?(U=c&&t.jsx(bt,{checked:f,onChange:$=>d?.($),ariaLabel:"Show in dropdown"}),e[14]=d,e[15]=c,e[16]=f,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 I;e[20]!==r?(I=r&&t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[20]=r,e[21]=I):I=e[21];let P;e[22]!==M||e[23]!==I?(P=t.jsxs("div",{className:"min-w-0 flex flex-col",children:[M,I]}),e[22]=M,e[23]=I,e[24]=P):P=e[24];let z;e[25]!==P||e[26]!==U?(z=t.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[U,P]}),e[25]=P,e[26]=U,e[27]=z):z=e[27];const T=x==="-"?"":x;let J;e[28]!==T?(J=t.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:T}),e[28]=T,e[29]=J):J=e[29];let _;e[30]!==z||e[31]!==J?(_=t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[z,J]}),e[30]=z,e[31]=J,e[32]=_):_=e[32];let ee;e[33]!==j||e[34]!==K||e[35]!==a.usedPercent?(ee=t.jsx(fy,{percent:j,tonePercent:a.usedPercent,expectedMarkerPercent:K,className:"h-1.5"}),e[33]=j,e[34]=K,e[35]=a.usedPercent,e[36]=ee):ee=e[36];const Q=C?`Resets ${C}`:"";let N;e[37]!==Q?(N=t.jsx("span",{className:"typography-micro text-muted-foreground",children:Q}),e[37]=Q,e[38]=N):N=e[38];let V;e[39]!==g?(V=t.jsx("span",{className:"typography-micro text-muted-foreground",children:g}),e[39]=g,e[40]=V):V=e[40];let B;e[41]!==N||e[42]!==V?(B=t.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[N,V]}),e[41]=N,e[42]=V,e[43]=B):B=e[43];let F;e[44]!==ee||e[45]!==B?(F=t.jsxs("div",{className:"mt-2.5",children:[ee,B]}),e[44]=ee,e[45]=B,e[46]=F):F=e[46];let O;e[47]!==v||e[48]!==p?(O=v&&p&&t.jsx("div",{className:"mt-1.5",children:t.jsx(xy,{paceInfo:v})}),e[47]=v,e[48]=p,e[49]=O):O=e[49];let q;return e[50]!==_||e[51]!==F||e[52]!==O?(q=t.jsxs("div",{className:"py-3",children:[_,F,O]}),e[50]=_,e[51]=F,e[52]=O,e[53]=q):q=e[53],q};function yy(s){return s.displayMode}function by(s){return s.showPredValues}function vy(s){return s.timeFormatPreference}const jy=(s,e)=>{if(!s)return"-";try{return mc(s,e,{fallback:"-"})}catch{return"-"}},wy=()=>{const{t:s}=st(),e=Fe(P=>P.timeFormatPreference),n=Vt(P=>P.results),a=Vt(P=>P.selectedProviderId),r=Vt(P=>P.setSelectedProvider),i=Vt(P=>P.loadSettings),l=Vt(P=>P.fetchAllQuotas),d=Vt(P=>P.isLoading),c=Vt(P=>P.lastUpdated),f=Vt(P=>P.error),m=Vt(P=>P.dropdownProviderIds),p=Vt(P=>P.setDropdownProviderIds),u=Vt(P=>P.selectedModels),j=Vt(P=>P.toggleModelSelected),g=Vt(P=>P.applyDefaultSelections);Jx(),o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(a||n.length===0)return;const P=n.find(z=>z.configured)?.providerId;r(P??wn[0]?.id??null)},[n,a,r]);const h=n.find(P=>P.providerId===a)??null,A=wn.find(P=>P.id===a)?.name??a??s("settings.usage.sidebar.title"),S=h?.usage,C=a?m.includes(a):!1,R=o.useCallback(P=>{if(!a)return;const z=P?Array.from(new Set([...m,a])):m.filter(T=>T!==a);p(z),kt({usageDropdownProviders:z})},[m,a,p]),k=o.useMemo(()=>S?.models?Object.entries(S.models).map(([P,z])=>({name:P,windows:z})).filter(P=>Object.keys(P.windows.windows).length>0):[],[S?.models]);o.useEffect(()=>{a&&k.length>0&&g(a,k.map(P=>P.name))},[a,k,g]);const y=o.useMemo(()=>!a||k.length===0?new Map:Wx(k,P=>P.name,a),[k,a]),v=o.useMemo(()=>{if(!a)return[];const P=_x(a);return Hx(P)},[a]),[E,K]=o.useState(()=>({})),U=o.useCallback(P=>{K(z=>({...z,[P]:!z[P]}))},[]),M=o.useCallback(P=>{if(!a)return;j(a,P);const z=u[a]??[],J=z.includes(P)?z.filter(ee=>ee!==P):[...z,P],_={...u,[a]:J};kt({usageSelectedModels:_})},[a,u,j]),I=a?u[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(Xn,{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:A})}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:d?t.jsx("span",{className:"animate-pulse",children:s("settings.usage.page.header.refreshing")}):s("settings.usage.page.header.lastUpdated",{time:jy(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:()=>R(!C),onKeyDown:P=>{(P.key===" "||P.key==="Enter")&&(P.preventDefault(),R(!C))},children:[t.jsx(bt,{checked:C,onChange:R,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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:s("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!h&&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")})}),f&&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:f})]}),h&&!h.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")})]}),S?.windows&&Object.keys(S.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(S.windows).map(([P,z])=>t.jsx(Br,{title:P,window:z},P))})})}),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:[v.map(P=>{const z=y.get(P.id)??[];if(z.length===0)return null;const T=E[P.id]??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(Mn,{open:!T,onOpenChange:()=>U(P.id),children:[t.jsxs(Tn,{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:P.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(Rn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:z.map(J=>{const _=Object.entries(J.windows.windows);if(_.length===0)return null;const[ee,Q]=_[0],N=I.includes(J.name);return t.jsx(Br,{title:ee,subtitle:hl(J.name),window:Q,showToggle:!0,toggleEnabled:N,onToggle:()=>M(J.name)},J.name)})})})]})},P.id)}),(()=>{const P=y.get(null)??[];if(P.length===0)return null;const z=E.other??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(Mn,{open:!z,onOpenChange:()=>U("other"),children:[t.jsxs(Tn,{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:["(",P.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(Rn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:P.map(T=>{const J=Object.entries(T.windows.windows);if(J.length===0)return null;const[_,ee]=J[0],Q=I.includes(T.name);return t.jsx(Br,{title:_,subtitle:hl(T.name),window:ee,showToggle:!0,toggleEnabled:Q,onToggle:()=>M(T.name)},T.name)})})})]})})})()]})]}),h?.configured&&S&&Object.keys(S.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")})})},Ny="git.commit.generate",xi=Nn(s=>({selectedPromptId:Ny,setSelectedPromptId:e=>{s(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),ky=s=>{const e=Ze.c(23),{onItemSelect:n}=s,{t:a}=st(),r=xi(Sy),i=xi(Cy);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 d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=d):d=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=c):c=e[2];let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=[l,d,c,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=f):f=e[3];const m=f;let p;e[4]!==a?(p=a("settings.magicPrompts.sidebar.title"),e[4]=a,e[5]=p):p=e[5];let u;e[6]!==p?(u=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:p}),e[6]=p,e[7]=u):u=e[7];let j;e[8]!==a?(j=a("settings.magicPrompts.sidebar.description"),e[8]=a,e[9]=j):j=e[9];let g;e[10]!==j?(g=t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:j}),e[10]=j,e[11]=g):g=e[11];let h;e[12]!==u||e[13]!==g?(h=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[u,g]}),e[12]=u,e[13]=g,e[14]=h):h=e[14];let x;e[15]!==n||e[16]!==r||e[17]!==i||e[18]!==a?(x=t.jsx(Ht,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(S=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:a(S.groupKey)}),S.items.map(C=>{const R=r===C.id;return t.jsx("button",{type:"button",onClick:()=>{i(C.id),n?.()},className:oe("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",R?"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)})]},S.groupKey))}),e[15]=n,e[16]=r,e[17]=i,e[18]=a,e[19]=x):x=e[19];let A;return e[20]!==x||e[21]!==h?(A=t.jsxs("div",{className:"flex h-full flex-col bg-background",children:[h,x]}),e[20]=x,e[21]=h,e[22]=A):A=e[22],A};function Sy(s){return s.selectedPromptId}function Cy(s){return s.setSelectedPromptId}const xl={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},yl=(s,e)=>Object.prototype.hasOwnProperty.call(s,e),$r=s=>s.endsWith(".visible"),Iy=()=>{const{t:s}=st(),e=o.useCallback(y=>s(y),[s]),n=xi(y=>y.selectedPromptId),[a,r]=o.useState(!0),[i,l]=o.useState({}),[d,c]=o.useState({}),[f,m]=o.useState({}),[p,u]=o.useState({}),[j,g]=o.useState(!1);o.useEffect(()=>{let y=!0;return(async()=>{r(!0);try{const E=await sm();if(!y)return;l(E)}catch(E){console.warn("Failed to load magic prompts:",E),W.error(s("settings.magicPrompts.page.toast.loadFailed"))}finally{y&&r(!1)}})(),()=>{y=!1}},[s]);const h=xl[n]??xl["git.commit.generate"],x=o.useCallback(y=>yl(i,y)?i[y]:wr(y),[i]),A=o.useCallback(y=>d[y]??x(y),[d,x]),S=o.useCallback((y,v)=>{c(E=>E[y]===v?E:{...E,[y]:v})},[]),C=o.useCallback(async y=>{const v=A(y);if($r(y)&&v.trim().length===0){W.error(s("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(E=>({...E,[y]:!0}));try{const E=v===wr(y)?await Wi(y):await Zu(y,v);l(E.overrides),W.success(s("settings.magicPrompts.page.toast.saved"))}catch(E){const K=E instanceof Error?E.message:String(E);W.error(s("settings.magicPrompts.page.toast.saveFailed"),{description:K})}finally{m(E=>({...E,[y]:!1}))}},[A,s]),R=o.useCallback(async y=>{u(v=>({...v,[y]:!0}));try{const v=await Wi(y);l(v.overrides),c(E=>({...E,[y]:wr(y)})),W.success(s("settings.magicPrompts.page.toast.resetSuccess"))}catch(v){const E=v instanceof Error?v.message:String(v);W.error(s("settings.magicPrompts.page.toast.resetFailed"),{description:E})}finally{u(v=>({...v,[y]:!1}))}},[s]),k=o.useCallback(async()=>{g(!0);try{const y=await em();l(y.overrides),c({}),W.success(s("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(y){const v=y instanceof Error?y.message:String(y);W.error(s("settings.magicPrompts.page.toast.resetAllFailed"),{description:v})}finally{g(!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(h.titleKey)}),t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:e(h.descriptionKey)})]})]})}),t.jsx(G,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{k()},disabled:j||Object.keys(i).length===0,children:s(j?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),h.blocks.map((y,v)=>{const E=tm(y.id),K=x(y.id),U=A(y.id),M=yl(i,y.id),I=U!==K,P=$r(y.id)&&U.trim().length===0,z=f[y.id]===!0,T=p[y.id]===!0;return t.jsxs("section",{"data-settings-item":$r(y.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",className:v>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:e(y.titleKey)}),t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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(J=>`{{${J.key}}}`).join(", ")]})]}),t.jsx(hs,{value:U,onChange:J=>S(y.id,J.target.value),className:"min-h-[220px] font-mono text-sm"}),P&&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(I?"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(G,{variant:"outline",size:"sm",onClick:()=>{R(y.id)},disabled:!M||z||T,children:s(T?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),t.jsx(G,{size:"sm",onClick:()=>{C(y.id)},disabled:!I||z||T||P,children:s(z?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},y.id)})]})})},Py=s=>{const e=Ze.c(89),{onItemSelect:n}=s,{t:a}=st(),[r,i]=o.useState(null),[l,d]=o.useState(null),[c,f]=o.useState(null),{selectedSnippetName:m,snippets:p,setSelectedSnippet:u,setSnippetDraft:j,deleteSnippet:g,loadSnippets:h}=hr(Es(Ay));let x,A;e[0]!==h?(x=()=>{h()},A=[h],e[0]=h,e[1]=x,e[2]=A):(x=e[1],A=e[2]),o.useEffect(x,A);let S;e[3]!==n||e[4]!==u||e[5]!==j||e[6]!==p?(S=async()=>{const Z=new Set(p.map(Dy));let se="new-snippet",ve=1;for(;Z.has(se);)se=`new-snippet-${ve++}`;j({name:se,scope:"global"}),u(se),n?.()},e[3]=n,e[4]=u,e[5]=j,e[6]=p,e[7]=S):S=e[7];const C=S;let R;e[8]!==r||e[9]!==g||e[10]!==a?(R=async()=>{if(!r)return;await g(r.name)?(W.success(a("settings.snippets.sidebar.toast.deleted")),i(null)):W.error(a("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=g,e[10]=a,e[11]=R):R=e[11];const k=R;let y;e[12]!==p?(y=[...p].sort(Ey),e[12]=p,e[13]=y):y=e[13];const v=y;let E;e[14]===Symbol.for("react.memo_cache_sentinel")?(E=oe("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]!==p.length||e[20]!==a?(M=a("settings.snippets.sidebar.total",{count:p.length}),e[19]=p.length,e[20]=a,e[21]=M):M=e[21];let I;e[22]!==M?(I=t.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[22]=M,e[23]=I):I=e[23];let P;e[24]!==a?(P=a("settings.snippets.sidebar.actions.create"),e[24]=a,e[25]=P):P=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]!==P?(T=t.jsx(G,{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":P,children:z}),e[27]=C,e[28]=P,e[29]=T):T=e[29];let J;e[30]!==I||e[31]!==T?(J=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,T]}),e[30]=I,e[31]=T,e[32]=J):J=e[32];let _;e[33]!==J||e[34]!==U?(_=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[U,J]}),e[33]=J,e[34]=U,e[35]=_):_=e[35];let ee;if(e[36]!==n||e[37]!==l||e[38]!==c||e[39]!==m||e[40]!==u||e[41]!==v||e[42]!==a){let Z;e[44]!==n||e[45]!==l||e[46]!==c||e[47]!==m||e[48]!==u||e[49]!==a?(Z=se=>t.jsxs(yn,{open:c===se.name,onOpenChange:ve=>f(ve?se.name:null),children:[t.jsxs(bn,{render:t.jsx("div",{className:oe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m===se.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ve=>{ve.preventDefault(),f(se.name)}}),children:[t.jsxs("button",{onClick:()=>{u(se.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:["#",se.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.${se.source}`)})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:se.description||se.content.replace(/\s+/g," ").substring(0,80)})]}),t.jsxs(gs,{open:l===se.name,onOpenChange:ve=>{ve&&f(null),d(ve?se.name:null)},children:[t.jsx(ms,{asChild:!0,children:t.jsx(G,{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:se.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(Ss,{onClick:ve=>{ve.stopPropagation(),i(se)},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:ve=>{ve.stopPropagation(),i(se)},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")]})})]},`${se.source}:${se.filePath}`),e[44]=n,e[45]=l,e[46]=c,e[47]=m,e[48]=u,e[49]=a,e[50]=Z):Z=e[50],ee=v.map(Z),e[36]=n,e[37]=l,e[38]=c,e[39]=m,e[40]=u,e[41]=v,e[42]=a,e[43]=ee}else ee=e[43];let Q;e[51]!==ee?(Q=t.jsx(Ht,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:ee}),e[51]=ee,e[52]=Q):Q=e[52];const N=r!==null;let V;e[53]===Symbol.for("react.memo_cache_sentinel")?(V=Z=>{Z||i(null)},e[53]=V):V=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(Ut,{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 $;e[61]!==q?($=t.jsx(_t,{children:q}),e[61]=q,e[62]=$):$=e[62];let ie;e[63]!==F||e[64]!==$?(ie=t.jsxs(Kt,{children:[F,$]}),e[63]=F,e[64]=$,e[65]=ie):ie=e[65];let le;e[66]===Symbol.for("react.memo_cache_sentinel")?(le=()=>i(null),e[66]=le):le=e[66];let ne;e[67]!==a?(ne=a("settings.common.actions.cancel"),e[67]=a,e[68]=ne):ne=e[68];let ye;e[69]!==ne?(ye=t.jsx(G,{size:"sm",variant:"ghost",onClick:le,children:ne}),e[69]=ne,e[70]=ye):ye=e[70];let ae;e[71]!==a?(ae=a("settings.common.actions.delete"),e[71]=a,e[72]=ae):ae=e[72];let ge;e[73]!==k||e[74]!==ae?(ge=t.jsx(G,{size:"sm",onClick:k,children:ae}),e[73]=k,e[74]=ae,e[75]=ge):ge=e[75];let Ne;e[76]!==ye||e[77]!==ge?(Ne=t.jsxs(Jt,{children:[ye,ge]}),e[76]=ye,e[77]=ge,e[78]=Ne):Ne=e[78];let he;e[79]!==ie||e[80]!==Ne?(he=t.jsxs(Ft,{className:"max-w-md",children:[ie,Ne]}),e[79]=ie,e[80]=Ne,e[81]=he):he=e[81];let we;e[82]!==N||e[83]!==he?(we=t.jsx(Lt,{open:N,onOpenChange:V,children:he}),e[82]=N,e[83]=he,e[84]=we):we=e[84];let ce;return e[85]!==_||e[86]!==Q||e[87]!==we?(ce=t.jsxs("div",{className:E,children:[_,Q,we]}),e[85]=_,e[86]=Q,e[87]=we,e[88]=ce):ce=e[88],ce};function Ay(s){return{selectedSnippetName:s.selectedSnippetName,snippets:s.snippets,setSelectedSnippet:s.setSelectedSnippet,setSnippetDraft:s.setSnippetDraft,deleteSnippet:s.deleteSnippet,loadSnippets:s.loadSnippets}}function Dy(s){return s.name}function Ey(s,e){return s.name.localeCompare(e.name)}const My=()=>{const{t:s}=st(),{selectedSnippetName:e,snippets:n,snippetDraft:a,setSnippetDraft:r,updateSnippet:i,createSnippet:l}=hr(Es(E=>({selectedSnippetName:E.selectedSnippetName,snippets:E.snippets,snippetDraft:E.snippetDraft,setSnippetDraft:E.setSnippetDraft,updateSnippet:E.updateSnippet,createSnippet:E.createSnippet}))),d=o.useMemo(()=>e?n.find(E=>E.name===e||E.aliases.includes(e))??null:null,[e,n]),c=!!(a&&a.name===e&&!d),[f,m]=o.useState(""),[p,u]=o.useState("global"),[j,g]=o.useState(""),[h,x]=o.useState(""),[A,S]=o.useState(""),[C,R]=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),u(E.draftScope),g(E.description),x(E.aliases),S(E.content),k.current=E}else if(d){const E={draftName:"",draftScope:"global",description:d.description??"",aliases:d.aliases.join(", "),content:d.content};g(E.description),x(E.aliases),S(E.content),k.current=E}},[d,c,e,a]);const y=o.useMemo(()=>{const E=k.current;return E?c&&f!==E.draftName||c&&p!==E.draftScope?!0:j!==E.description||h!==E.aliases||A!==E.content:!1},[h,A,j,f,p,c]),v=async()=>{const E=c?f.trim().replace(/\s+/g,"-"):e?.trim();if(!E){W.error(s("settings.snippets.page.toast.nameRequired"));return}if(!A.trim()){W.error(s("settings.snippets.page.toast.contentRequired"));return}const K=h.split(",").map(U=>U.trim()).filter(Boolean);R(!0);try{if(!(c?await l(E,A,{aliases:K,description:j,scope:p}):await i(E,{content:A,aliases:K,description:j}))){W.error(s("settings.snippets.page.toast.saveFailed"));return}W.success(s("settings.snippets.page.toast.saved")),c&&r(null)}finally{R(!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}`}),d?t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:d.filePath}):null]}),t.jsxs("div",{className:"mb-8 space-y-3 px-2",children:[t.jsxs("div",{children:[c?t.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:"#"}),t.jsx(Xe,{value:f,onChange:E=>m(E.target.value),placeholder:s("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),t.jsxs(Dt,{value:p,onValueChange:E=>u(E),children:[t.jsx(Et,{className:"w-fit min-w-[100px]",children:t.jsx(zt,{})}),t.jsxs(Mt,{align:"end",children:[t.jsx(mt,{value:"global",children:s("settings.common.scope.global")}),t.jsx(mt,{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:j,onChange:E=>g(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:h,onChange:E=>x(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:A,onChange:E=>S(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(G,{onClick:v,disabled:C||!y,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")})]})})},zc=()=>{const{t:s}=st(),e=it(p=>p.settingsGitmojiEnabled),n=it(p=>p.setSettingsGitmojiEnabled),a=$m(),r=Fe(p=>p.gitChangesViewMode),i=Fe(p=>p.setGitChangesViewMode),[l,d]=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 u=null;if(!u){const j=qs()?.settings;if(j)try{const h=(await j.load())?.settings;h&&(u={gitmojiEnabled:typeof h.gitmojiEnabled=="boolean"?h.gitmojiEnabled:void 0,gitChangesViewMode:h.gitChangesViewMode==="flat"||h.gitChangesViewMode==="tree"?h.gitChangesViewMode:void 0})}catch{}}if(!u){const j=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});j.ok&&(u=await j.json())}u&&(typeof u.gitmojiEnabled=="boolean"&&n(u.gitmojiEnabled),(u.gitChangesViewMode==="flat"||u.gitChangesViewMode==="tree")&&i(u.gitChangesViewMode))}catch(u){console.warn("Failed to load git settings:",u)}finally{d(!1)}})()},[i,n]);const f=o.useCallback(async p=>{n(p);try{await kt({gitmojiEnabled:p})}catch(u){console.warn("Failed to save gitmoji setting:",u)}},[n]),m=o.useCallback(p=>{p!==r&&(i(p),kt({gitChangesViewMode:p}))},[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(p=>{const u=r===p.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>{m(p.id)},onKeyDown:j=>{(j.key===" "||j.key==="Enter")&&(j.preventDefault(),m(p.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:u,onChange:()=>{m(p.id)},ariaLabel:s("settings.openchamber.git.optionAria",{option:p.label})}),t.jsx("span",{className:u?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:p.label})]},p.id)})})]}),t.jsxs("div",{"data-settings-item":"git.gitmoji",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{f(!e)},onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),f(!e))},children:[t.jsx(bt,{checked:e,onChange:p=>{f(p)},ariaLabel:s("settings.openchamber.git.enableGitmojiAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.git.enableGitmoji")})]}),t.jsxs("div",{"data-settings-item":"git.gitignored-files",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":a,onClick:()=>Cr(!a),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Cr(!a))},children:[t.jsx(bt,{checked:a,onChange:Cr,ariaLabel:s("settings.openchamber.git.showGitignoredAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.git.showGitignored")})]})]})]})},Uc=()=>{const{t:s}=st(),{isMobile:e}=Ms(),n=qs()?.github,a=nn(I=>I.status),r=nn(I=>I.isLoading),i=nn(I=>I.hasChecked),l=nn(I=>I.refreshStatus),d=nn(I=>I.setStatus),c=o.useCallback(async I=>{await on(I)},[]),[f,m]=o.useState(!1),[p,u]=o.useState(null),[j,g]=o.useState(null),h=o.useRef(null),x=o.useCallback(()=>{h.current!=null&&(window.clearInterval(h.current),h.current=null),g(null)},[]);o.useEffect(()=>((async()=>{try{i||await l(n)}catch(I){console.warn("Failed to load GitHub auth status:",I)}})(),()=>{x()}),[i,l,n,x]);const A=o.useCallback(async()=>{m(!0);try{const I=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})();u(I),g(Math.max(1,I.interval)*1e3);const P=I.verificationUriComplete||I.verificationUri;c(P)}catch(I){console.error("Failed to start GitHub connect:",I),W.error(s("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[c,n,s]),S=o.useCallback(async I=>{if(n)return n.authComplete(I);const P=await dt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:I})}),z=await P.json().catch(()=>null);if(!P.ok||!z)throw new Error(z?.error||P.statusText);return z},[n]);o.useEffect(()=>{if(!(!p?.deviceCode||!j)&&h.current==null)return h.current=window.setInterval(()=>{(async()=>{try{const I=await S(p.deviceCode);if(I.connected){W.success(s("settings.github.page.toast.connected")),u(null),x(),await l(n,{force:!0});return}I.status==="slow_down"&&g(P=>P?P+5e3:5e3),(I.status==="expired_token"||I.status==="access_denied")&&(W.error(I.error||s("settings.github.page.toast.authorizationFailed")),u(null),x())}catch(I){console.warn("GitHub polling failed:",I)}})()},j),()=>{h.current!=null&&(window.clearInterval(h.current),h.current=null)}},[p,j,S,l,n,x,s]);const C=o.useCallback(async I=>{m(!0);try{if(n)await n.authSetGhCliDisabled(I);else{const P=await dt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:I})}),z=await P.json().catch(()=>null);if(!P.ok)throw new Error(z?.error||P.statusText)}W.success(s(I?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await l(n,{force:!0})}catch(P){console.error("Failed to update gh CLI setting:",P),W.error(s("settings.github.page.toast.ghCliUpdateFailed"))}finally{m(!1)}},[l,n,s]),R=o.useCallback(async()=>{m(!0);try{if(x(),u(null),n)await n.authDisconnect();else{const I=await dt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!I.ok)throw new Error(I.statusText)}W.success(s("settings.github.page.toast.disconnected")),await l(n,{force:!0})}catch(I){console.error("Failed to disconnect GitHub:",I),W.error(s("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[l,n,x,s]),k=o.useCallback(async I=>{if(I){m(!0);try{const P=n?await n.authActivate(I):await(async()=>{const z=await dt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:I})}),T=await z.json().catch(()=>null);if(!z.ok||!T)throw new Error(T?.error||z.statusText);return T})();d(P),W.success(s("settings.github.page.toast.accountSwitched"))}catch(P){console.error("Failed to switch GitHub account:",P),W.error(s("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,d,s]);if(r)return null;const y=!!a?.connected,v=a?.user,K=(a?.accounts??[]).filter(I=>!I.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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:s("settings.github.page.tooltip.connectAccount")})]})]})}),t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[y?t.jsxs("div",{className:oe("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:oe("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[v?.avatarUrl?t.jsx("img",{src:v.avatarUrl,alt:v.login?s("settings.github.page.avatarAlt.withLogin",{login:v.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:v?.name?.trim()||v?.login||"GitHub"}),t.jsxs("div",{className:oe("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:v?.login||s("settings.github.page.label.unknownUser")}),v?.email&&t.jsx("span",{className:"opacity-50",children:"•"}),v?.email&&t.jsx("span",{children:v.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(G,{size:"sm",variant:"outline",onClick:()=>C(!0),disabled:f,className:oe(e?"w-full":void 0),children:s("settings.github.page.ghCli.actions.disable")}):t.jsx(G,{size:"sm",variant:"outline",onClick:R,disabled:f,className:oe("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(G,{size:"sm",variant:"default",onClick:A,disabled:f,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(I=>{const P=I.user,z=I.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:[P?.avatarUrl?t.jsx("img",{src:P.avatarUrl,alt:P.login?s("settings.github.page.avatarAlt.withLogin",{login:P.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:P?.name?.trim()||P?.login||"GitHub"}),P?.login&&t.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[t.jsx("span",{className:"font-mono",children:P.login}),t.jsx("span",{className:"mx-1 opacity-50",children:"·"}),t.jsx("span",{children:z})]})]})]}),t.jsx(G,{size:"sm",variant:"ghost",onClick:()=>k(I.id),disabled:f,children:s("settings.github.page.actions.switchTo")})]},I.id)})})]})]}),y&&t.jsx("div",{className:"mt-2 px-2 pb-2",children:t.jsx(G,{size:"sm",variant:"outline",onClick:A,disabled:f,className:oe(e?"w-full":void 0),children:s("settings.github.page.actions.addAccount")})}),p&&t.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("h4",{className:"typography-ui-label text-foreground",children:s("settings.github.page.flow.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.github.page.flow.description")})]}),t.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[t.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:p.userCode}),t.jsx(G,{size:"sm",asChild:!0,children:t.jsx("a",{href:p.verificationUriComplete||p.verificationUri,target:"_blank",rel:"noopener noreferrer",children:s("settings.github.page.actions.openGithub")})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[t.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:s("settings.github.page.flow.waiting")}),t.jsx(G,{size:"sm",variant:"ghost",disabled:f,onClick:()=>{x(),u(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:oe("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:oe("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:oe("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:oe("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(G,{size:"sm",variant:"outline",onClick:()=>C(!U.disabled),disabled:f,className:oe(e?"w-full":void 0),children:U.disabled?s("settings.github.page.ghCli.actions.enable"):s("settings.github.page.ghCli.actions.disable")})]})})]})]})},bl=[{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)"}],Ty=[{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"}],Ry=({open:s,onOpenChange:e,profileId:n,importData:a})=>{const{t:r}=st(),i=Ds($=>$.getProfileById),l=Ds($=>$.createProfile),d=Ds($=>$.updateProfile),c=Ds($=>$.deleteProfile),f=o.useMemo(()=>n&&n!=="new"&&!a?i(n):null,[n,i,a]),m=n==="new"||a!=null,p=n==="global",[u,j]=o.useState(""),[g,h]=o.useState(""),[x,A]=o.useState(""),[S,C]=o.useState("ssh"),[R,k]=o.useState(""),[y,v]=o.useState(!1),[E,K]=o.useState(""),[U,M]=o.useState(""),[I,P]=o.useState("keyword"),[z,T]=o.useState("branch"),[J,_]=o.useState(!1),[ee,Q]=o.useState(!1),[N,V]=o.useState(!1);o.useEffect(()=>{if(s){if(a){const $=a.host.split("/"),ie=$.length>=3?$[$.length-1]:a.host;j(ie),h(a.username),A(""),C("token"),k(""),v(!1),K(""),M(a.host),P("string"),T("code")}else if(m)j(""),h(""),A(""),C("ssh"),k(""),v(!1),K(""),M(""),P("keyword"),T("branch");else if(f)j(f.name),h(f.userName),A(f.userEmail),C(f.authType||"ssh"),k(f.sshKey||""),v(f.signCommits===!0),K(f.signingKey||""),M(f.host||""),P(f.color||"keyword"),T(f.icon||"branch");else if(p){const $=i("global");$&&(j($.name),h($.userName),A($.userEmail),C($.authType||"ssh"),k($.sshKey||""),v(!1),K(""),M($.host||""),P($.color||"keyword"),T($.icon||"branch"))}}},[s,n,f,m,a,p,i]);const B=async()=>{if(!g.trim()||!x.trim()){W.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(S==="token"&&!U.trim()){W.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(y&&!E.trim()){W.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}_(!0);try{const $={name:u.trim()||g.trim(),userName:g.trim(),userEmail:x.trim(),authType:S,sshKey:S==="ssh"&&R.trim()||null,signCommits:y,signingKey:E.trim()||null,host:S==="token"&&U.trim()||null,color:I,icon:z};let ie;if(m)ie=await l($);else if(n)ie=await d(n,$);else return;ie?(W.success(r(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):W.error(r(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch($){console.error("Error saving profile:",$),W.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{_(!1)}},F=async()=>{if(!(!n||m)){V(!0);try{await c(n)?(W.success(r("settings.gitIdentities.editor.toast.profileDeleted")),Q(!1),e(!1)):W.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch($){console.error("Error deleting profile:",$),W.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{V(!1)}}},O=o.useMemo(()=>bl.find(ie=>ie.key===I)?.cssVar||"var(--syntax-keyword)",[I]),q=a?r("settings.gitIdentities.editor.title.importCredential"):m?r("settings.gitIdentities.editor.title.newIdentity"):p?r("settings.gitIdentities.editor.title.globalIdentity"):f?.name||r("settings.gitIdentities.editor.title.editIdentity");return t.jsxs(t.Fragment,{children:[t.jsx(Lt,{open:s,onOpenChange:e,children:t.jsxs(Ft,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:q}),t.jsx(_t,{children:r(p?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),t.jsxs("div",{className:"space-y-5 py-2",children:[!p&&t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"typography-ui-label text-foreground block mb-1.5",children:r("settings.gitIdentities.editor.field.profileName")}),t.jsx(Xe,{value:u,onChange:$=>j($.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:bl.map($=>t.jsx("button",{type:"button",onClick:()=>P($.key),className:oe("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",I===$.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:$.cssVar},title:$.label},$.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:Ty.map($=>{const ie=$.Icon;return t.jsx("button",{type:"button",onClick:()=>T($.key),className:oe("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",z===$.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:$.label,children:t.jsx(D,{name:ie,className:"w-3.5 h-3.5",style:{color:z===$.key?O:"var(--surface-muted-foreground)"}})},$.key)})})]})]}),!p&&t.jsx("div",{className:"border-t border-border/40"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.userName")}),!p&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),t.jsx(Xe,{value:g,onChange:$=>h($.target.value),placeholder:r("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!p,readOnly:p,disabled:p,className:"h-8"})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.emailAddress")}),!p&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),t.jsx(Xe,{type:"email",value:x,onChange:$=>A($.target.value),placeholder:r("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!p,readOnly:p,disabled:p,className:"h-8"})]})]}),!p&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"border-t border-border/40"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.authMethod")}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsxs(G,{size:"sm",type:"button",variant:"chip","aria-pressed":S==="ssh",onClick:()=>C("ssh"),children:[t.jsx(D,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),t.jsxs(G,{size:"sm",type:"button",variant:"chip","aria-pressed":S==="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")]})]})]}),S==="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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),t.jsx(Xe,{value:R,onChange:$=>k($.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(bt,{checked:y,onChange:v,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:$=>K($.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!y,className:"h-8 font-mono text-xs"})]})]}),S==="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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]})]}),t.jsx(Xe,{value:U,onChange:$=>M($.target.value),placeholder:r("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),t.jsxs(Jt,{className:"gap-2",children:[!p&&!m&&t.jsxs(G,{variant:"outline",size:"sm",onClick:()=>Q(!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(G,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:r(p?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!p&&t.jsx(G,{size:"sm",onClick:B,disabled:J,children:r(J?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),t.jsx(Lt,{open:ee,onOpenChange:$=>{N||Q($)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:r("settings.gitIdentities.page.deleteDialog.title")}),t.jsx(_t,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:f?.name||u})})]}),t.jsxs(Jt,{children:[t.jsx(G,{variant:"ghost",onClick:()=>Q(!1),disabled:N,children:r("settings.common.actions.cancel")}),t.jsx(G,{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"},Fy={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},Oy=()=>{const s=Ze.c(118),{t:e}=st(),{profiles:n,globalIdentity:a,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:d,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:f,setDefaultGitIdentityId:m,getUnimportedCredentials:p}=Ds(Es(Uy)),[u,j]=o.useState(!1),[g,h]=o.useState(null),[x,A]=o.useState(null),[S,C]=o.useState(null),[R,k]=o.useState(!1);let y,v;s[0]!==f||s[1]!==c||s[2]!==d||s[3]!==l?(y=()=>{l(),d(),c(),f()},v=[l,d,c,f],s[0]=f,s[1]=c,s[2]=d,s[3]=l,s[4]=y,s[5]=v):(y=s[4],v=s[5]),o.useEffect(y,v);let E,K,U,M,I,P,z,T,J,_,ee,Q,N,V;if(s[6]!==r||s[7]!==S||s[8]!==i||s[9]!==p||s[10]!==a||s[11]!==n||s[12]!==m||s[13]!==e){const Ae=p();let De;s[28]===Symbol.for("react.memo_cache_sentinel")?(De=(je,Re)=>{h(je),A(Re??null),j(!0)},s[28]=De):De=s[28];const Pe=De;let Oe;s[29]!==r||s[30]!==m||s[31]!==e?(Oe=async je=>{const Re=r===je?null:je;if(!await m(Re)){W.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}W.success(e(Re?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},s[29]=r,s[30]=m,s[31]=e,s[32]=Oe):Oe=s[32];const Te=Oe;let Ue;s[33]!==S||s[34]!==i||s[35]!==e?(Ue=async()=>{if(!S)return;k(!0),await i(S.id)?(W.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:S.name})),C(null)):W.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),k(!1)},s[33]=S,s[34]=i,s[35]=e,s[36]=Ue):Ue=s[36],K=Ue,E=Ht,I="h-full",P="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(Uc,{})}),s[37]=M):M=s[37],Q="git.identities",N="border-t border-border/40 pt-6";let Be;s[38]!==e?(Be=e("settings.gitIdentities.page.section.title"),s[38]=e,s[39]=Be):Be=s[39];let Ke;s[40]!==Be?(Ke=t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:Be})}),s[40]=Be,s[41]=Ke):Ke=s[41];let Je,ue;s[42]===Symbol.for("react.memo_cache_sentinel")?(Je=()=>Pe("new"),ue=t.jsx(D,{name:"add",className:"w-3.5 h-3.5 mr-1"}),s[42]=Je,s[43]=ue):(Je=s[42],ue=s[43]);let Y;s[44]!==e?(Y=e("settings.common.badge.new"),s[44]=e,s[45]=Y):Y=s[45];let de;s[46]!==Y?(de=t.jsxs(G,{size:"sm",variant:"outline",onClick:Je,children:[ue," ",Y]}),s[46]=Y,s[47]=de):de=s[47],s[48]!==Ke||s[49]!==de?(V=t.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[Ke,de]}),s[48]=Ke,s[49]=de,s[50]=V):V=s[50],z="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",T=a&&t.jsx(vl,{profile:a,isDefault:r==="global",onEdit:()=>Pe("global"),onToggleDefault:()=>Te("global"),isReadOnly:!0,hasBorder:n.length>0||Ae.length>0}),J=n.map((je,Re)=>t.jsx(vl,{profile:je,isDefault:r===je.id,onEdit:()=>Pe(je.id),onToggleDefault:()=>Te(je.id),onDelete:()=>C(je),hasBorder:Re<n.length-1||Ae.length>0},je.id)),_=!a&&n.length===0&&Ae.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")})]}),ee=Ae.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")})}),Ae.map((je,Re)=>t.jsx(zy,{credential:je,onImport:()=>Pe("new",{host:je.host,username:je.username}),hasBorder:Re<Ae.length-1},`${je.host}-${je.username}`))]}),s[6]=r,s[7]=S,s[8]=i,s[9]=p,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]=I,s[19]=P,s[20]=z,s[21]=T,s[22]=J,s[23]=_,s[24]=ee,s[25]=Q,s[26]=N,s[27]=V}else E=s[14],K=s[15],U=s[16],M=s[17],I=s[18],P=s[19],z=s[20],T=s[21],J=s[22],_=s[23],ee=s[24],Q=s[25],N=s[26],V=s[27];let B;s[51]!==z||s[52]!==T||s[53]!==J||s[54]!==_||s[55]!==ee?(B=t.jsxs("div",{className:z,children:[T,J,_,ee]}),s[51]=z,s[52]=T,s[53]=J,s[54]=_,s[55]=ee,s[56]=B):B=s[56];let F;s[57]!==B||s[58]!==Q||s[59]!==N||s[60]!==V?(F=t.jsxs("div",{"data-settings-item":Q,className:N,children:[V,B]}),s[57]=B,s[58]=Q,s[59]=N,s[60]=V,s[61]=F):F=s[61];let O;s[62]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx(zc,{}),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 $;s[67]!==E||s[68]!==I||s[69]!==P||s[70]!==q?($=t.jsx(E,{outerClassName:I,className:P,children:q}),s[67]=E,s[68]=I,s[69]=P,s[70]=q,s[71]=$):$=s[71];let ie;s[72]!==x||s[73]!==u||s[74]!==g?(ie=t.jsx(Ry,{open:u,onOpenChange:j,profileId:g,importData:x}),s[72]=x,s[73]=u,s[74]=g,s[75]=ie):ie=s[75];const le=S!==null;let ne;s[76]!==R?(ne=Ae=>{R||Ae||C(null)},s[76]=R,s[77]=ne):ne=s[77];let ye;s[78]!==e?(ye=e("settings.gitIdentities.page.deleteDialog.title"),s[78]=e,s[79]=ye):ye=s[79];let ae;s[80]!==ye?(ae=t.jsx(Ut,{children:ye}),s[80]=ye,s[81]=ae):ae=s[81];const ge=S?.name??"";let Ne;s[82]!==e||s[83]!==ge?(Ne=e("settings.gitIdentities.page.deleteDialog.description",{name:ge}),s[82]=e,s[83]=ge,s[84]=Ne):Ne=s[84];let he;s[85]!==Ne?(he=t.jsx(_t,{children:Ne}),s[85]=Ne,s[86]=he):he=s[86];let we;s[87]!==ae||s[88]!==he?(we=t.jsxs(Kt,{children:[ae,he]}),s[87]=ae,s[88]=he,s[89]=we):we=s[89];let ce;s[90]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>C(null),s[90]=ce):ce=s[90];let Z;s[91]!==e?(Z=e("settings.common.actions.cancel"),s[91]=e,s[92]=Z):Z=s[92];let se;s[93]!==R||s[94]!==Z?(se=t.jsx(G,{variant:"ghost",onClick:ce,disabled:R,children:Z}),s[93]=R,s[94]=Z,s[95]=se):se=s[95];let ve;s[96]!==K?(ve=()=>{K()},s[96]=K,s[97]=ve):ve=s[97];let H;s[98]!==e?(H=e("settings.common.actions.delete"),s[98]=e,s[99]=H):H=s[99];let te;s[100]!==R||s[101]!==ve||s[102]!==H?(te=t.jsx(G,{size:"sm",variant:"destructive",onClick:ve,disabled:R,children:H}),s[100]=R,s[101]=ve,s[102]=H,s[103]=te):te=s[103];let re;s[104]!==se||s[105]!==te?(re=t.jsxs(Jt,{children:[se,te]}),s[104]=se,s[105]=te,s[106]=re):re=s[106];let pe;s[107]!==we||s[108]!==re?(pe=t.jsxs(Ft,{className:"max-w-md",children:[we,re]}),s[107]=we,s[108]=re,s[109]=pe):pe=s[109];let Me;s[110]!==le||s[111]!==ne||s[112]!==pe?(Me=t.jsx(Lt,{open:le,onOpenChange:ne,children:pe}),s[110]=le,s[111]=ne,s[112]=pe,s[113]=Me):Me=s[113];let Se;return s[114]!==$||s[115]!==ie||s[116]!==Me?(Se=t.jsxs(t.Fragment,{children:[$,ie,Me]}),s[114]=$,s[115]=ie,s[116]=Me,s[117]=Se):Se=s[117],Se},vl=s=>{const e=Ze.c(56),{profile:n,isDefault:a,onEdit:r,onToggleDefault:i,onDelete:l,isReadOnly:d,hasBorder:c}=s,{t:f}=st(),[m,p]=o.useState(!1),u=Ly[n.icon||"branch"]||"git-branch",j=Fy[n.color||""],g=n.authType||"ssh";let h;e[0]!==r?(h=F=>{F.currentTarget===F.target&&(F.key!=="Enter"&&F.key!==" "||(F.preventDefault(),r()))},e[0]=r,e[1]=h):h=e[1];const x=h;let A;e[2]!==a||e[3]!==d||e[4]!==l||e[5]!==i||e[6]!==f?(A=F=>t.jsxs(t.Fragment,{children:[t.jsx(F,{onClick:O=>{O.stopPropagation(),i()},children:f(a?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!d&&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"}),f("settings.common.actions.delete")]})]}),e[2]=a,e[3]=d,e[4]=l,e[5]=i,e[6]=f,e[7]=A):A=e[7];const S=A,C=c&&"border-b border-[var(--surface-subtle)]";let R;e[8]!==C?(R=oe("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]=R):R=e[9];let k;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=F=>{F.preventDefault(),p(!0)},e[10]=k):k=e[10];let y;e[11]!==x||e[12]!==r||e[13]!==R?(y=t.jsx("div",{className:R,onClick:r,role:"button",tabIndex:0,onKeyDown:x,onContextMenu:k}),e[11]=x,e[12]=r,e[13]=R,e[14]=y):y=e[14];let v;e[15]!==j?(v={color:j},e[15]=j,e[16]=v):v=e[16];let E;e[17]!==u||e[18]!==v?(E=t.jsx(D,{name:u,className:"w-4 h-4 shrink-0",style:v}),e[17]=u,e[18]=v,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]!==g?(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:g}),e[22]=g,e[23]=U):U=e[23];let M;e[24]!==a||e[25]!==f?(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:f("settings.gitIdentities.page.badge.default")}),e[24]=a,e[25]=f,e[26]=M):M=e[26];let I;e[27]!==d||e[28]!==f?(I=d&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f("settings.agents.sidebar.badge.system")}),e[27]=d,e[28]=f,e[29]=I):I=e[29];let P;e[30]!==U||e[31]!==M||e[32]!==I||e[33]!==K?(P=t.jsxs("div",{className:"flex items-center gap-1.5",children:[K,U,M,I]}),e[30]=U,e[31]=M,e[32]=I,e[33]=K,e[34]=P):P=e[34];const z=g==="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 J;e[37]!==P||e[38]!==T?(J=t.jsxs("div",{className:"min-w-0",children:[P,T]}),e[37]=P,e[38]=T,e[39]=J):J=e[39];let _;e[40]!==J||e[41]!==E?(_=t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[E,J]}),e[40]=J,e[41]=E,e[42]=_):_=e[42];let ee;e[43]===Symbol.for("react.memo_cache_sentinel")?(ee=t.jsx(ms,{asChild:!0,children:t.jsx(G,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:Ky,children:t.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=ee):ee=e[43];let Q;e[44]!==S?(Q=t.jsxs(gs,{children:[ee,t.jsx(ps,{align:"end",className:"w-fit min-w-28",children:S(Ss)})]}),e[44]=S,e[45]=Q):Q=e[45];let N;e[46]!==_||e[47]!==Q||e[48]!==y?(N=t.jsxs(bn,{render:y,children:[_,Q]}),e[46]=_,e[47]=Q,e[48]=y,e[49]=N):N=e[49];let V;e[50]!==S?(V=t.jsx(vn,{className:"w-fit min-w-28",children:S(ln)}),e[50]=S,e[51]=V):V=e[51];let B;return e[52]!==m||e[53]!==N||e[54]!==V?(B=t.jsxs(yn,{open:m,onOpenChange:p,children:[N,V]}),e[52]=m,e[53]=N,e[54]=V,e[55]=B):B=e[55],B},zy=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 d=l,c=d.length>=3?d[d.length-1]:n.host,f=n.host.includes("/"),m=r&&"border-b border-[var(--surface-subtle)]";let p;e[2]!==m?(p=oe("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=p):p=e[3];let u;e[4]!==c?(u=t.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=u):u=e[5];const j=f?n.host:n.username;let g;e[6]!==j?(g=t.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:j}),e[6]=j,e[7]=g):g=e[7];let h;e[8]!==u||e[9]!==g?(h=t.jsxs("div",{className:"min-w-0",children:[u,g]}),e[8]=u,e[9]=g,e[10]=h):h=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx(D,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let A;e[12]!==i?(A=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=A):A=e[13];let S;e[14]!==a||e[15]!==A?(S=t.jsxs(G,{size:"sm",variant:"ghost",onClick:a,className:"gap-1 shrink-0",children:[x,A]}),e[14]=a,e[15]=A,e[16]=S):S=e[16];let C;return e[17]!==S||e[18]!==p||e[19]!==h?(C=t.jsxs("div",{className:p,children:[h,S]}),e[17]=S,e[18]=p,e[19]=h,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 Ky(s){return s.stopPropagation()}const Kc=()=>{const s=nm();return{displayMode:s,installed:s!=="browser",browserTab:s==="browser"}},By=()=>{const s=Ze.c(2),[e,n]=o.useState($y);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(Kc())};l();for(const d of i)typeof d.addEventListener=="function"?d.addEventListener("change",l):typeof d.addListener=="function"&&d.addListener(l);return window.addEventListener("appinstalled",l),window.addEventListener("focus",l),()=>{for(const d of i)typeof d.removeEventListener=="function"?d.removeEventListener("change",l):typeof d.removeListener=="function"&&d.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 $y(){return Kc()}const Vy=[{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"}],_y=[{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"}],Hy=[{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"}],ga="OpenChamber - AI Coding Assistant",jl=[{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"}],wl=[{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"}],Wy=[{value:"default",labelKey:"settings.openchamber.visual.option.mobileLayout.default"},{value:"new",labelKey:"settings.openchamber.visual.option.mobileLayout.new"}],Vr=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"}],Gy=[{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"}],Nl=[{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"}],Jy=[{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"}],kl=[{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"}],Sl=[{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"}],Qy=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Yy=s=>s==="markdown"?"markdown":"plain",Ai=({visibleSettings:s})=>{const{locale:e,locales:n,setLocale:a,label:r,t:i}=st(),l=o.useCallback(w=>i(w),[i]),{isMobile:d}=Ms(),{browserTab:c}=By(),f=Vm(),m=Fe(w=>w.showReasoningTraces),p=Fe(w=>w.sessionRecapEnabled),u=Fe(w=>w.sessionSuggestionEnabled),j=Fe(w=>w.setSessionRecapEnabled),g=Fe(w=>w.setSessionSuggestionEnabled),h=Fe(w=>w.setShowReasoningTraces),x=Fe(w=>w.collapsibleThinkingBlocks),A=Fe(w=>w.setCollapsibleThinkingBlocks),S=Fe(w=>w.mermaidRenderingMode),C=Fe(w=>w.setMermaidRenderingMode),R=Fe(w=>w.userMessageRenderingMode),k=Fe(w=>w.setUserMessageRenderingMode),y=Fe(w=>w.collapsibleUserMessages),v=Fe(w=>w.setCollapsibleUserMessages),E=Fe(w=>w.stickyUserHeader),K=Fe(w=>w.setStickyUserHeader),U=Fe(w=>w.expandedEditorToolbar),M=Fe(w=>w.setExpandedEditorToolbar),I=Fe(w=>w.wideChatLayoutEnabled),P=Fe(w=>w.setWideChatLayoutEnabled),z=Fe(w=>w.codeBlockLineWrap),T=Fe(w=>w.setCodeBlockLineWrap),J=Fe(w=>w.chatRenderMode),_=Fe(w=>w.setChatRenderMode),ee=Fe(w=>w.activityRenderMode),Q=Fe(w=>w.setActivityRenderMode),N=Fe(w=>w.fontSize),V=Fe(w=>w.setFontSize),B=Fe(w=>w.terminalFontSize),F=Fe(w=>w.setTerminalFontSize),O=Fe(w=>w.uiFont),q=Fe(w=>w.setUiFont),$=Fe(w=>w.monoFont),ie=Fe(w=>w.setMonoFont),le=Fe(w=>w.padding),ne=Fe(w=>w.setPadding),ye=Fe(w=>w.inputBarOffset),ae=Fe(w=>w.setInputBarOffset),ge=Fe(w=>w.mobileKeyboardMode),Ne=Fe(w=>w.setMobileKeyboardMode),he=Fe(w=>w.diffLayoutPreference),we=Fe(w=>w.setDiffLayoutPreference),ce=Fe(w=>w.showTerminalQuickKeysOnDesktop),Z=Fe(w=>w.setShowTerminalQuickKeysOnDesktop),se=Fe(w=>w.fileEditorKeymap),ve=Fe(w=>w.setFileEditorKeymap),H=no(w=>w.followUpBehavior),te=no(w=>w.setFollowUpBehavior),re=Fe(w=>w.persistChatDraft),pe=Fe(w=>w.setPersistChatDraft),Me=Fe(w=>w.inputSpellcheckEnabled),Se=Fe(w=>w.setInputSpellcheckEnabled),Ae=Fe(w=>w.showToolFileIcons),De=Fe(w=>w.setShowToolFileIcons),Pe=Fe(w=>w.showTurnChangedFiles),Oe=Fe(w=>w.setShowTurnChangedFiles),Te=Fe(w=>w.showExpandedBashTools),Ue=Fe(w=>w.setShowExpandedBashTools),Be=Fe(w=>w.showExpandedEditTools),Ke=Fe(w=>w.setShowExpandedEditTools),Je=Fe(w=>w.timeFormatPreference),ue=Fe(w=>w.setTimeFormatPreference),Y=Fe(w=>w.weekStartPreference),de=Fe(w=>w.setWeekStartPreference),je=Fe(w=>w.showSplitAssistantMessageActions),Re=Fe(w=>w.setShowSplitAssistantMessageActions),Ie=it(w=>w.settingsMessageStreamTransport),Ve=it(w=>w.setSettingsMessageStreamTransport),X=Ie,b=it(w=>w.settingsDefaultFileViewerPreview),be=it(w=>w.setSettingsDefaultFileViewerPreview),Ee=Fe(w=>w.isSettingsDialogOpen),{themeMode:ze,setThemeMode:qe,availableThemes:rt,customThemesLoading:lt,reloadCustomThemes:at,lightThemeId:ct,darkThemeId:Ye,setLightThemePreference:_e,setDarkThemePreference:ft}=gr(),[xe,et]=o.useState(!1),nt=o.useMemo(()=>rs()&&typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancySupported===!0,[]),He=typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancy===!0,[yt,Nt]=o.useState(He),[Tt,me]=o.useState(!1),$e=o.useMemo(()=>rs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Qe=Fe(w=>w.dockBadgeEnabled),We=Fe(w=>w.setDockBadgeEnabled),[xt,St]=o.useState(0),ht=Fe(w=>w.reportUsage),Rt=Fe(w=>w.setReportUsage),Gt=o.useCallback(w=>{Rt(w),kt({reportUsage:w})},[Rt]),cs=Ee&&(s?s.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!cs)return;let w=null,gt=Date.now();const At=()=>{const zs=Date.now();zs-gt>=420&&(St(Qs=>(Qs+1)%24),gt=zs),w=requestAnimationFrame(At)};(typeof document>"u"||document.visibilityState==="visible")&&(w=requestAnimationFrame(At));const ns=()=>{document.visibilityState==="visible"&&w===null?w=requestAnimationFrame(At):document.visibilityState!=="visible"&&w!==null&&(cancelAnimationFrame(w),w=null)};return document.addEventListener("visibilitychange",ns),()=>{document.removeEventListener("visibilitychange",ns),w!==null&&cancelAnimationFrame(w)}},[cs]);const ds=o.useCallback(w=>{k(w),kt({userMessageRenderingMode:w})},[k]),xs=o.useCallback(w=>{K(w),kt({stickyUserHeader:w})},[K]),Zt=o.useCallback(w=>{M(w),kt({expandedEditorToolbar:w})},[M]),Cs=o.useCallback(w=>{v(w),kt({collapsibleUserMessages:w})},[v]),Ce=o.useCallback(w=>{P(w),kt({wideChatLayoutEnabled:w})},[P]),vt=o.useCallback(w=>{Re(w),kt({showSplitAssistantMessageActions:w})},[Re]),jt=o.useCallback(w=>{Se(w),kt({inputSpellcheckEnabled:w})},[Se]),qt=o.useCallback(w=>{_(w),kt({chatRenderMode:w})},[_]),es=o.useCallback(w=>{Ve(w),kt({messageStreamTransport:w})},[Ve]),Bt=o.useCallback(w=>{Q(w),kt({activityRenderMode:w})},[Q]),ys=o.useCallback(w=>{C(w),kt({mermaidRenderingMode:w})},[C]),ws=o.useCallback(w=>{De(w),kt({showToolFileIcons:w})},[De]),Qt=o.useCallback(w=>{Oe(w),kt({showTurnChangedFiles:w})},[Oe]),Fs=o.useCallback(w=>{be(w),kt({defaultFileViewerPreview:w}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:w}}))},[be]),kn=o.useCallback(w=>{Ue(w),kt({showExpandedBashTools:w})},[Ue]),Gs=o.useCallback(w=>{Ke(w),kt({showExpandedEditTools:w})},[Ke]),Bs=o.useCallback(w=>{ue(w),kt({timeFormatPreference:w})},[ue]),cn=o.useCallback(w=>{de(w),kt({weekStartPreference:w})},[de]),ot=o.useMemo(()=>rt.filter(w=>w.metadata.variant==="light").sort((w,gt)=>w.metadata.name.localeCompare(gt.metadata.name)),[rt]),pt=o.useMemo(()=>rt.filter(w=>w.metadata.variant==="dark").sort((w,gt)=>w.metadata.name.localeCompare(gt.metadata.name)),[rt]),wt=o.useMemo(()=>ot.find(w=>w.metadata.id===ct)??ot[0],[ot,ct]),Yt=o.useMemo(()=>pt.find(w=>w.metadata.id===Ye)??pt[0],[pt,Ye]),Xt=o.useCallback((w,gt)=>{const At=gt==="dark"?" Dark":" Light";return w.endsWith(At)?w.slice(0,-At.length):w},[]),Ge=w=>s?s.includes(w):!0,Ts=fs(),aa=Ge("theme")&&!Ts,Sa=Ge("theme")||Ge("timeFormat")||Ge("weekStart"),Ca=d&&Dn()&&!rs()&&!Ts,fr=Ts?Sa:Ge("theme")||Ca||Ge("pwaInstallName")||Ge("pwaOrientation")||Ge("timeFormat")||Ge("weekStart"),Ps=Ge("fontSize")||Ge("terminalFontSize")||Ge("spacing")||Ge("inputBarOffset"),$s=Ge("terminalQuickKeys")&&!d||Ge("fileEditorKeymap")||Ge("expandedEditorToolbar"),On=Ge("mermaidRendering")||Ge("userMessageRendering")||Ge("chatRenderMode")||Ge("messageTransport")||Ge("activityRenderMode")&&J==="sorted"||Ge("collapsibleUserMessages")||Ge("stickyUserHeader")||Ge("wideChatLayout")||Ge("codeBlockLineWrap")||Ge("splitAssistantMessageActions")||Ge("diffLayout")||Ge("dotfiles")||Ge("fileViewerPreview")||Ge("reasoning")||Ge("followUpBehavior")||Ge("persistDraft")||Ge("showToolFileIcons")||Ge("expandedTools")||!d&&Ge("inputSpellcheck"),As=Ge("pwaInstallName")&&Dn()&&c&&!rs()&&!Ts,Rs=Ge("pwaOrientation")&&Dn()&&!rs()&&!Ts,Sn=Ge("mobileKeyboardMode")&&Dn()&&!rs()&&!Ts&&_m(),[Vs,xr]=o.useState(()=>np()),[dn,Js]=o.useState(""),[ts,un]=o.useState("system"),zn=o.useMemo(()=>{const w=kl.find(gt=>gt.id===Je);return l(w?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Je,l]),Un=o.useMemo(()=>{const w=Sl.find(gt=>gt.id===Y);return l(w?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[Y,l]),yr=o.useMemo(()=>{const w=jl.find(gt=>gt.id===ts);return w?l(w.labelKey):void 0},[ts,l]),Ia=o.useMemo(()=>{const w=wl.find(gt=>gt.id===ge);return w?l(w.labelKey):void 0},[ge,l]),Kn=o.useCallback(w=>{w!==Vs&&(xr(w),ap(w),window.location.reload())},[Vs]),mn=o.useCallback(async w=>{if(typeof window>"u")return;const gt=window,ns=w.trim().replace(/\s+/g," ").slice(0,64);if(await kt({pwaAppName:ns}),typeof gt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const zs=gt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(ns);Js(zs);return}Js(ns||ga),gt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Pa=o.useCallback(async w=>{if(typeof window>"u")return;const gt=window,At=Vr(w);if(await kt({pwaOrientation:At}),typeof gt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const ns=gt.__OPENCHAMBER_SET_PWA_ORIENTATION__(At);un(ns);return}un(At),gt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!As&&!Rs&&!Sn)return;let w=!1;return(async()=>{try{const At=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!At.ok){w||Js(ga);return}const ns=await At.json().catch(()=>({})),Qs=(typeof ns?.pwaAppName=="string"?ns.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Bn=Vr(ns?.pwaOrientation),ra=lo(ns?.mobileKeyboardMode);w||(As&&Js(Qs||ga),Rs&&un(Bn),Sn&&Ne(ra))}catch{w||(As&&Js(ga),Rs&&un("system"),Sn&&Ne("native"))}})(),()=>{w=!0}},[Ne,Sn,As,Rs]),t.jsxs("div",{className:"space-y-8",children:[fr&&t.jsxs("div",{className:"mb-8 space-y-6",children:[aa&&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:Vy.map(w=>t.jsx(G,{variant:"chip",size:"xs","aria-pressed":ze===w.value,className:"!font-normal",onClick:()=>qe(w.value),children:l(w.labelKey)},w.value))})]}),Ca&&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:Wy.map(w=>t.jsx(G,{variant:"chip",size:"xs","aria-pressed":Vs===w.value,className:"!font-normal",onClick:()=>Kn(w.value),children:l(w.labelKey)},w.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(Dt,{value:wt?.metadata.id??"",onValueChange:_e,children:[t.jsx(Et,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:t.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:wt?Xt(wt.metadata.name,"light"):void 0})}),t.jsx(Mt,{children:ot.map(w=>t.jsx(mt,{value:w.metadata.id,children:Xt(w.metadata.name,"light")},w.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(Dt,{value:Yt?.metadata.id??"",onValueChange:ft,children:[t.jsx(Et,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:t.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Yt?Xt(Yt.metadata.name,"dark"):void 0})}),t.jsx(Mt,{children:pt.map(w=>t.jsx(mt,{value:w.metadata.id,children:Xt(w.metadata.name,"dark")},w.metadata.id))})]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[t.jsx("button",{type:"button",disabled:lt||xe,onClick:()=>{const w=Date.now();et(!0),at().finally(()=>{const gt=Date.now()-w;if(gt<500){window.setTimeout(()=>{et(!1)},500-gt);return}et(!1)})},className:"inline-flex items-center typography-ui-label font-normal text-foreground underline decoration-[1px] underline-offset-2 hover:text-foreground/80 disabled:cursor-not-allowed disabled:text-muted-foreground/60",children:i(xe?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),t.jsxs(Ct,{children:[t.jsx(It,{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(Pt,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]}),nt&&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":yt,onClick:()=>{Tt||Nt(!yt)},onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Tt||Nt(!yt))},children:[t.jsx(bt,{checked:yt,onChange:Nt,disabled:Tt,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")})]})]}),yt!==He&&t.jsx("div",{className:"pl-6",children:t.jsx(G,{variant:"outline",size:"sm",disabled:Tt,onClick:()=>{me(!0),Hm("desktop_set_vibrancy",{enabled:yt})},children:i(Tt?"settings.openchamber.visual.actions.restarting":"settings.openchamber.visual.actions.saveAndRestart")})})]}),$e&&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":Qe,onClick:()=>We(!Qe),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),We(!Qe))},children:[t.jsx(bt,{checked:Qe,onChange:We,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")})]})]})})]}),Sa&&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(Dt,{value:e,onValueChange:w=>a(w),children:[t.jsx(Et,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:t.jsx(zt,{children:r(e)})}),t.jsx(Mt,{children:n.map(w=>t.jsx(mt,{value:w,children:r(w)},w))})]})]}),(Ge("timeFormat")||Ge("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:[Ge("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(Dt,{value:Je,onValueChange:w=>Bs(w),children:[t.jsx(Et,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:t.jsx(zt,{children:zn})}),t.jsx(Mt,{children:kl.map(w=>t.jsx(mt,{value:w.id,children:l(w.labelKey)},w.id))})]})]}),Ge("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(Dt,{value:Y,onValueChange:w=>cn(w),children:[t.jsx(Et,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:t.jsx(zt,{children:Un})}),t.jsx(Mt,{children:Sl.map(w=>t.jsx(mt,{value:w.id,children:l(w.labelKey)},w.id))})]})]})]})]}),(As||Rs||Sn)&&t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[As&&t.jsxs("div",{"data-settings-item":"appearance.pwa-install-name",className:"py-1.5 space-y-1.5",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installAppName")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installAppNameHint")})]}),t.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[t.jsx(Xe,{value:dn,onChange:w=>{Js(w.target.value)},onBlur:()=>{mn(dn)},onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),mn(dn))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Js(ga),mn("")},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"})})]})]}),Rs&&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(Dt,{value:ts,onValueChange:w=>{const gt=Vr(w);un(gt),Pa(gt)},children:[t.jsx(Et,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:t.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:yr})}),t.jsx(Mt,{children:jl.map(w=>t.jsx(mt,{value:w.id,children:l(w.labelKey)},w.id))})]}),t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{un("system"),Pa("system")},disabled:ts==="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"})})]})]}),Sn&&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(Dt,{value:ge,onValueChange:w=>{const gt=lo(w);Ne(gt),kt({mobileKeyboardMode:gt})},children:[t.jsx(Et,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:t.jsx(zt,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Ia})}),t.jsx(Mt,{children:wl.map(w=>t.jsx(mt,{value:w.id,children:l(w.labelKey)},w.id))})]}),t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ne("native"),kt({mobileKeyboardMode:"native"})},disabled:ge==="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"})})]})]})]})]}),Ps&&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:[Ge("fontSize")&&!d&&t.jsxs("div",{"data-settings-item":"appearance.interface-font-size",className:"flex items-center gap-8 py-1",children:[t.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFont")})}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[t.jsxs(Dt,{value:O,onValueChange:w=>q(w),children:[t.jsx(Et,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:t.jsx(zt,{children:ao.find(w=>w.id===O)?.label})}),t.jsx(Mt,{children:ao.map(w=>t.jsx(mt,{value:w.id,children:t.jsx("span",{style:{fontFamily:w.stack},children:w.label})},w.id))})]}),t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>q(ro),disabled:O===ro,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"})})]})]}),Ge("terminalFontSize")&&t.jsxs("div",{className:oe("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:oe("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeFont")})}),t.jsxs("div",{className:oe("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsxs(Dt,{value:$,onValueChange:w=>ie(w),children:[t.jsx(Et,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:t.jsx(zt,{children:io.find(w=>w.id===$)?.label})}),t.jsx(Mt,{children:io.map(w=>t.jsx(mt,{value:w.id,children:t.jsx("span",{style:{fontFamily:w.stack},children:w.label})},w.id))})]}),t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>ie(oo),disabled:$===oo,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"})})]})]}),Ge("fontSize")&&!d&&t.jsxs("div",{className:"flex items-center gap-8 py-1",children:[t.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFontSize")})}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[t.jsx(ks,{value:N,onValueChange:V,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>V(100),disabled:N===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"})})]})]}),Ge("terminalFontSize")&&t.jsxs("div",{"data-settings-item":"appearance.terminal-font-size",className:oe("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:oe("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalFontSize")})}),t.jsxs("div",{className:oe("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(ks,{value:B,onValueChange:F,min:9,max:52,step:1,className:"w-16"}),t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(13),disabled:B===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"})})]})]}),Ge("spacing")&&t.jsxs("div",{"data-settings-item":"appearance.spacing-density",className:oe("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:oe("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.spacingDensity")})}),t.jsxs("div",{className:oe("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(ks,{value:le,onValueChange:ne,min:50,max:200,step:5,className:"w-16"}),t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>ne(100),disabled:le===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"})})]})]}),Ge("inputBarOffset")&&t.jsxs("div",{"data-settings-item":"appearance.input-bar-offset",className:oe("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:oe("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.inputBarOffset")}),t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),t.jsxs("div",{className:oe("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(ks,{value:ye,onValueChange:ae,min:0,max:100,step:5,className:"w-16"}),t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:()=>ae(0),disabled:ye===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"})})]})]})]})]})}),$s&&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")}),Ge("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(w=>{const gt=se===w,At=i(`settings.openchamber.visual.option.fileEditorKeymap.${w}`);return t.jsxs("button",{type:"button",className:"flex cursor-pointer items-center gap-2 py-0.5 text-left",role:"radio","aria-checked":gt,onClick:()=>ve(w),children:[t.jsx("span",{"aria-hidden":!0,className:oe("relative flex h-[14px] w-[14px] min-h-[14px] min-w-[14px] shrink-0 self-center items-center justify-center rounded-full transition-[background-color,box-shadow] duration-200 ease-out",gt?"bg-[color-mix(in_srgb,var(--primary-base)_80%,transparent)] shadow-none":"bg-[var(--surface-muted)] shadow-[inset_0_0_0_1px_var(--interactive-border)]"),children:t.jsx("span",{className:oe("block h-[5px] w-[5px] rounded-full bg-white",!gt&&"opacity-0")})}),t.jsx("span",{className:oe("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:At})]},w)})})]}),Ge("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":U,onClick:()=>Zt(!U),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Zt(!U))},children:[t.jsx(bt,{checked:U,onChange:Zt,ariaLabel:i("settings.openchamber.visual.field.expandedEditorToolbarAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.expandedEditorToolbar")})]}),Ge("terminalQuickKeys")&&!d&&t.jsxs("div",{"data-settings-item":"appearance.terminal-quick-keys",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ce,onClick:()=>Z(!ce),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Z(!ce))},children:[t.jsx(bt,{checked:ce,onChange:Z,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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),On&&t.jsxs("div",{className:"space-y-3",children:[(Ge("userMessageRendering")||Ge("mermaidRendering")||Ge("chatRenderMode")||Ge("messageTransport")||Ge("activityRenderMode")&&J==="sorted"||Ge("diffLayout")&&!Ts||Ge("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:[Ge("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:Gy.map(w=>{const gt=J===w.id,At=xt%12;return t.jsxs("button",{type:"button",onClick:()=>qt(w.id),"aria-pressed":gt,className:oe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",gt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsx("span",{className:oe("typography-ui-label",gt?"text-foreground":"text-muted-foreground"),children:l(w.labelKey)}),t.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:w.id==="live"?t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ns=>{const zs=ns*3+1,Qs=At-zs+1,Bn=Qs<=0?0:Qs===1?42:Qs===2?68:92,ra=Bn>0;return t.jsxs("div",{className:oe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",ra?"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:`${Bn}%`}})]},ns)})}):t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ns=>{const zs=At>=(ns+1)*3;return t.jsxs("div",{className:oe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",zs?"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%"}})]},ns)})})})]},w.id)})})]}),Ge("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:Nl.map(w=>t.jsx(G,{variant:"chip",size:"xs","aria-pressed":X===w.id,className:"!font-normal",onClick:()=>es(w.id),children:l(w.labelKey)},w.id))}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const w=Nl.find(gt=>gt.id===X);return w?.descriptionKey?l(w.descriptionKey):""})()})]})]}),Ge("activityRenderMode")&&J==="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:Jy.map(w=>{const gt=ee===w.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":gt,onClick:()=>Bt(w.id),onKeyDown:At=>{(At.key===" "||At.key==="Enter")&&(At.preventDefault(),Bt(w.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:gt,onChange:()=>Bt(w.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(w.labelKey)})}),t.jsx("span",{className:oe("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:l(w.labelKey)})]},w.id)})})]}),Ge("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":Te,onClick:()=>kn(!Te),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),kn(!Te))},children:[t.jsx(bt,{checked:Te,onChange:kn,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":Be,onClick:()=>Gs(!Be),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Gs(!Be))},children:[t.jsx(bt,{checked:Be,onChange:Gs,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),Ge("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(w=>{const gt=Yy(R)===w.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":gt,onClick:()=>ds(w.id),onKeyDown:At=>{(At.key===" "||At.key==="Enter")&&(At.preventDefault(),ds(w.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:gt,onChange:()=>ds(w.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(w.labelKey)})}),t.jsx("span",{className:oe("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:l(w.labelKey)})]},w.id)})})]}),Ge("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:Hy.map(w=>{const gt=S===w.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":gt,onClick:()=>ys(w.id),onKeyDown:At=>{(At.key===" "||At.key==="Enter")&&(At.preventDefault(),ys(w.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:gt,onChange:()=>ys(w.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(w.labelKey)})}),t.jsx("span",{className:oe("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:l(w.labelKey)})]},w.id)})})]}),Ge("diffLayout")&&!Ts&&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:_y.map(w=>{const gt=he===w.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":gt,onClick:()=>we(w.id),onKeyDown:At=>{(At.key===" "||At.key==="Enter")&&(At.preventDefault(),we(w.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:gt,onChange:()=>we(w.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:l(w.labelKey)})}),t.jsx("span",{className:oe("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:l(w.labelKey)})]},w.id)})})]}),Ge("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:Qy.map(w=>{const gt=H===w.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":gt,onClick:()=>te(w.id),onKeyDown:At=>{(At.key===" "||At.key==="Enter")&&(At.preventDefault(),te(w.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(tn,{checked:gt,onChange:()=>te(w.id),ariaLabel:i("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(w.labelKey)})}),t.jsx("span",{className:oe("typography-ui-label font-normal",gt?"text-foreground":"text-foreground/50"),children:l(w.labelKey)})]},w.id)})})]})]}),(Ge("sessionAssist")||Ge("collapsibleUserMessages")||Ge("stickyUserHeader")||Ge("wideChatLayout")||Ge("codeBlockLineWrap")||Ge("splitAssistantMessageActions")||Ge("dotfiles")||Ge("fileViewerPreview")||Ge("persistDraft")||Ge("showToolFileIcons")||Ge("showTurnChangedFiles")||!d&&Ge("inputSpellcheck")||Ge("reasoning"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[Ge("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":p,onClick:()=>j(!p),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),j(!p))},children:[t.jsx(bt,{checked:p,onChange:j,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":u,onClick:()=>g(!u),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),g(!u))},children:[t.jsx(bt,{checked:u,onChange:g,ariaLabel:i("settings.openchamber.visual.field.sessionSuggestionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sessionSuggestion")})]})]}),Ge("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:()=>h(!m),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),h(!m))},children:[t.jsx(bt,{checked:m,onChange:h,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),Ge("reasoning")&&m&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":x,onClick:()=>A(!x),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),A(!x))},children:[t.jsx(bt,{checked:x,onChange:A,ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleThinkingBlocks")})]}),Ge("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":y,onClick:()=>Cs(!y),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Cs(!y))},children:[t.jsx(bt,{checked:y,onChange:Cs,ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleUserMessages")})]}),Ge("stickyUserHeader")&&t.jsxs("div",{"data-settings-item":"chat.sticky-user-header",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":E,onClick:()=>xs(!E),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),xs(!E))},children:[t.jsx(bt,{checked:E,onChange:xs,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),Ge("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":I,onClick:()=>Ce(!I),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Ce(!I))},children:[t.jsx(bt,{checked:I,onChange:Ce,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),Ge("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":je,onClick:()=>vt(!je),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),vt(!je))},children:[t.jsx(bt,{checked:je,onChange:vt,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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),Ge("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":z,onClick:()=>T(!z),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),T(!z))},children:[t.jsx(bt,{checked:z,onChange:T,ariaLabel:i("settings.openchamber.visual.field.codeBlockLineWrapAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeBlockLineWrap")})]}),Ge("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":Ae,onClick:()=>ws(!Ae),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),ws(!Ae))},children:[t.jsx(bt,{checked:Ae,onChange:ws,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),Ge("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:()=>Qt(!Pe),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Qt(!Pe))},children:[t.jsx(bt,{checked:Pe,onChange:Qt,ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showTurnChangedFiles")})]}),Ge("dotfiles")&&!fs()&&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":f,onClick:()=>Ir(!f),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Ir(!f))},children:[t.jsx(bt,{checked:f,onChange:Ir,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),Ge("fileViewerPreview")&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":b,onClick:()=>Fs(!b),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Fs(!b))},children:[t.jsx("span",{onClick:w=>w.stopPropagation(),children:t.jsx(bt,{checked:b,onChange:Fs,ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.defaults.field.openFilesPreview")})]}),Ge("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":re,onClick:()=>pe(!re),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),pe(!re))},children:[t.jsx(bt,{checked:re,onChange:pe,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!d&&Ge("inputSpellcheck")&&t.jsxs("div",{"data-settings-item":"chat.spellcheck",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":Me,onClick:()=>jt(!Me),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),jt(!Me))},children:[t.jsx(bt,{checked:Me,onChange:jt,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),Ge("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(bt,{checked:ht,onChange:Gt,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":ht,onClick:()=>Gt(!ht),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),Gt(!ht))},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")})]})]})]})})]})},Xy=1,Zy=365,Cl=30,eb=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Bc=()=>{const s=Ze.c(113),{t:e}=st(),n=Fe(tb),a=Fe(sb),r=Fe(nb),i=Fe(ab),l=Fe(rb),d=Fe(ib);let c;s[0]===Symbol.for("react.memo_cache_sentinel")?(c={autoRun:!1},s[0]=c):c=s[0];const{candidates:f,isRunning:m,runCleanup:p,action:u}=am(c),j=f.length;let g;s[1]!==p||s[2]!==e?(g=async()=>{const re=await p({force:!0});if(re.completedIds.length===0&&re.failedIds.length===0){W.message(re.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}re.completedIds.length>0&&W.success(re.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:re.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:re.completedIds.length})),re.failedIds.length>0&&W.error(re.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:re.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:re.failedIds.length}))},s[1]=p,s[2]=e,s[3]=g):g=s[3];const h=g;let x;s[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),s[4]=e,s[5]=x):x=s[5];let A;s[6]!==x?(A=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),s[6]=x,s[7]=A):A=s[7];let S;s[8]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[8]=S):S=s[8];let C;s[9]!==e?(C=e("settings.openchamber.sessionRetention.tooltip"),s[9]=e,s[10]=C):C=s[10];let R;s[11]!==C?(R=t.jsxs(Ct,{children:[S,t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:C})]}),s[11]=C,s[12]=R):R=s[12];let k;s[13]!==A||s[14]!==R?(k=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[A,R]})}),s[13]=A,s[14]=R,s[15]=k):k=s[15];let y,v;s[16]!==n||s[17]!==i?(y=()=>i(!n),v=re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),i(!n))},s[16]=n,s[17]=i,s[18]=y,s[19]=v):(y=s[18],v=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(bt,{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 I;s[30]!==n||s[31]!==K||s[32]!==M||s[33]!==y||s[34]!==v?(I=t.jsxs("div",{"data-settings-item":"sessions.auto-cleanup",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:y,onKeyDown:v,children:[K,M]}),s[30]=n,s[31]=K,s[32]=M,s[33]=y,s[34]=v,s[35]=I):I=s[35];let P;s[36]!==e?(P=e("settings.openchamber.sessionRetention.field.retentionPeriod"),s[36]=e,s[37]=P):P=s[37];let z;s[38]!==P?(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:P})}),s[38]=P,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 J;s[42]!==a||s[43]!==l||s[44]!==T?(J=t.jsx(ks,{value:a,onValueChange:l,min:Xy,max:Zy,step:1,"aria-label":T,className:"w-20 tabular-nums"}),s[42]=a,s[43]=l,s[44]=T,s[45]=J):J=s[45];let _;s[46]!==e?(_=e("settings.openchamber.sessionRetention.field.days"),s[46]=e,s[47]=_):_=s[47];let ee;s[48]!==_?(ee=t.jsx("span",{className:"typography-ui-label text-muted-foreground",children:_}),s[48]=_,s[49]=ee):ee=s[49];let Q;s[50]!==l?(Q=()=>l(Cl),s[50]=l,s[51]=Q):Q=s[51];const N=a===Cl;let V;s[52]!==e?(V=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),s[52]=e,s[53]=V):V=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]!==Q||s[58]!==N||s[59]!==V||s[60]!==B?(O=t.jsx(G,{size:"sm",type:"button",variant:"ghost",onClick:Q,disabled:N,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":V,title:B,children:F}),s[57]=Q,s[58]=N,s[59]=V,s[60]=B,s[61]=O):O=s[61];let q;s[62]!==J||s[63]!==ee||s[64]!==O?(q=t.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[J,ee,O]}),s[62]=J,s[63]=ee,s[64]=O,s[65]=q):q=s[65];let $;s[66]!==z||s[67]!==q?($=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]=$):$=s[68];let ie;s[69]!==e?(ie=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),s[69]=e,s[70]=ie):ie=s[70];let le;s[71]!==ie?(le=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]=le):le=s[72];let ne;s[73]!==r||s[74]!==d||s[75]!==e?(ne=eb.map(re=>t.jsx(G,{type:"button",variant:"chip",size:"xs","aria-pressed":r===re.value,className:"!font-normal",onClick:()=>d(re.value),children:e(re.labelKey)},re.value)),s[73]=r,s[74]=d,s[75]=e,s[76]=ne):ne=s[76];let ye;s[77]!==ne?(ye=t.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:ne}),s[77]=ne,s[78]=ye):ye=s[78];let ae;s[79]!==le||s[80]!==ye?(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:[le,ye]}),s[79]=le,s[80]=ye,s[81]=ae):ae=s[81];let ge;s[82]!==I||s[83]!==$||s[84]!==ae?(ge=t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[I,$,ae]}),s[82]=I,s[83]=$,s[84]=ae,s[85]=ge):ge=s[85];let Ne;s[86]!==e?(Ne=e("settings.openchamber.sessionRetention.manualCleanup.title"),s[86]=e,s[87]=Ne):Ne=s[87];let he;s[88]!==Ne?(he=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:Ne})}),s[88]=Ne,s[89]=he):he=s[89];let we;s[90]!==m||s[91]!==e?(we=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),s[90]=m,s[91]=e,s[92]=we):we=s[92];let ce;s[93]!==h||s[94]!==m||s[95]!==we?(ce=t.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:t.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:h,disabled:m,className:"!font-normal",children:we})}),s[93]=h,s[94]=m,s[95]=we,s[96]=ce):ce=s[96];let Z;s[97]!==he||s[98]!==ce?(Z=t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[he,ce]}),s[97]=he,s[98]=ce,s[99]=Z):Z=s[99];let se;s[100]!==u||s[101]!==j||s[102]!==e?(se=u==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:j}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:j}),s[100]=u,s[101]=j,s[102]=e,s[103]=se):se=s[103];let ve;s[104]!==se?(ve=t.jsx("p",{className:"typography-meta text-muted-foreground",children:se}),s[104]=se,s[105]=ve):ve=s[105];let H;s[106]!==Z||s[107]!==ve?(H=t.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[Z,ve]}),s[106]=Z,s[107]=ve,s[108]=H):H=s[108];let te;return s[109]!==ge||s[110]!==H||s[111]!==k?(te=t.jsxs("div",{className:"mb-8",children:[k,ge,H]}),s[109]=ge,s[110]=H,s[111]=k,s[112]=te):te=s[112],te};function tb(s){return s.autoDeleteEnabled}function sb(s){return s.autoDeleteAfterDays}function nb(s){return s.sessionRetentionAction}function ab(s){return s.setAutoDeleteEnabled}function rb(s){return s.setAutoDeleteAfterDays}function ib(s){return s.setSessionRetentionAction}const Il=(s,e,n)=>!s||!Number.isFinite(s)?e:new Intl.DateTimeFormat(ki(),{dateStyle:"medium",timeStyle:"short",hour12:n==="auto"?void 0:n==="12h"}).format(s),$c=()=>{const{t:s}=st(),e=Fe(v=>v.timeFormatPreference),[n,a]=o.useState(!1),[r,i]=o.useState(!0),[l,d]=o.useState(!1),[c,f]=o.useState(null),[m,p]=o.useState(!1),[u,j]=o.useState([]),[g,h]=o.useState(rm),[x,A]=o.useState(""),S=o.useMemo(()=>im(),[]),C=o.useCallback(async()=>{i(!0),A("");try{const v=await om();j(v)}catch(v){const E=v instanceof Error?v.message:s("settings.openchamber.passkeys.toast.loadFailed");A(E)}finally{i(!1)}},[s]);o.useEffect(()=>{let v=!1;return(async()=>{try{if(!S.supported){v||(a(!1),i(!1));return}v||a(!0)}catch{v||a(!1)}if(!v){const E=await Nr();if(h(E),!E.enabled){j([]),i(!1);return}await C()}})(),()=>{v=!0,qi()}},[C,S.supported]);const R=o.useCallback(async()=>{if(!g.enabled){const v=s("settings.openchamber.passkeys.toast.enableUiPasswordFirst");A(v),W.message(v);return}if(!n){A(S.reason),W.message(S.reason);return}if(l){qi(),d(!1);return}A(""),d(!0);try{await lm(),h(await Nr()),await C(),W.success(s("settings.openchamber.passkeys.toast.added"))}catch(v){if(cm(v)){W.message(s("settings.openchamber.passkeys.toast.setupCanceled"));return}const E=v instanceof Error?v.message:s("settings.openchamber.passkeys.toast.addFailed");A(E),W.error(E)}finally{d(!1)}},[l,C,g.enabled,S.reason,n,s]),k=o.useCallback(async v=>{f(v),A("");try{await dm(v),h(await Nr()),await C(),W.success(s("settings.openchamber.passkeys.toast.removed"))}catch(E){const K=E instanceof Error?E.message:s("settings.openchamber.passkeys.toast.removeFailed");A(K),W.error(K)}finally{f(null)}},[C,s]),y=o.useCallback(async()=>{p(!0),A("");try{await um(),window.location.reload()}catch(v){const E=v instanceof Error?v.message:s("settings.openchamber.passkeys.toast.clearAuthFailed");A(E),W.error(E),p(!1)}},[s]);return t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.passkeys.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.passkeys.field.currentDevice")})}),t.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[t.jsx(G,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{R()},disabled:r||m,className:"!font-normal",children:s(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),t.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>{y()},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")})]})]}),!g.enabled&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.uiPasswordRequired")}),g.enabled&&!n&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:S.reason}),r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.loading")}):u.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.noneSaved")}):t.jsx("div",{className:"space-y-1 pt-1",children:u.map(v=>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:v.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:v.lastUsedAt?s("settings.openchamber.passkeys.item.lastUsed",{time:Il(v.lastUsedAt,s("settings.openchamber.passkeys.time.neverUsed"),e)}):s("settings.openchamber.passkeys.item.added",{time:Il(v.createdAt,s("settings.openchamber.passkeys.time.neverUsed"),e)})}),t.jsx(G,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k(v.id)},disabled:c===v.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===v.id?s("settings.openchamber.passkeys.actions.removing"):s("settings.common.actions.delete")})]})]},v.id))})]}),x&&t.jsx("div",{className:"mt-1 px-2 py-1.5",children:t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:x})})]})},Pl=s=>{const e=xn(s);return e||{providerId:"",modelId:""}},Vc=()=>{const{t:s}=st(),e=it(N=>N.setProvider),n=it(N=>N.setModel),a=it(N=>N.setAgent),r=it(N=>N.setCurrentVariant),i=it(N=>N.setSettingsDefaultModel),l=it(N=>N.setSettingsDefaultVariant),d=it(N=>N.setSettingsDefaultAgent),c=Fe(N=>N.showDeletionDialog),f=Fe(N=>N.setShowDeletionDialog),m=it(N=>N.providers),[p,u]=o.useState(),[j,g]=o.useState(),[h,x]=o.useState(),[A,S]=o.useState(!0),[C,R]=o.useState(),[k,y]=o.useState(),[v,E]=o.useState(!0),K=o.useMemo(()=>Pl(p),[p]);o.useEffect(()=>{(async()=>{try{let V=null;if(!V){const B=qs()?.settings;if(B)try{const O=(await B.load())?.settings;if(O){const q=O;V={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(!V){const B=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});B.ok&&(V=await B.json())}if(V){const B=typeof V.defaultModel=="string"&&V.defaultModel.trim().length>0?V.defaultModel.trim():void 0,F=typeof V.defaultVariant=="string"&&V.defaultVariant.trim().length>0?V.defaultVariant.trim():void 0,O=typeof V.defaultAgent=="string"&&V.defaultAgent.trim().length>0?V.defaultAgent.trim():void 0;B!==void 0&&u(B),F!==void 0&&g(F),O!==void 0&&x(O),typeof V.smallModelUseDefault=="boolean"&&S(V.smallModelUseDefault),typeof V.smallModelOverride=="string"&&V.smallModelOverride.trim()&&R(V.smallModelOverride.trim())}}catch(V){console.warn("Failed to load defaults settings:",V)}finally{E(!1)}})()},[]);const U=o.useCallback(async(N,V)=>{const B=N&&V?`${N}/${V}`:void 0;u(B),g(void 0),l(void 0),r(void 0),i(B),N&&V&&m.find(O=>O.id===N)&&(e(N),n(V));try{await kt({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__",I=o.useCallback(N=>N===M?s("settings.openchamber.defaults.option.default"):N.charAt(0).toUpperCase()+N.slice(1),[s]),P=o.useCallback(async N=>{const V=N===M?void 0:N||void 0;g(V),l(V),r(V);try{await kt({defaultVariant:V??""})}catch(B){console.warn("Failed to save default variant:",B)}},[r,l]),z=o.useCallback(async N=>{const V=N||void 0;x(V),d(V),N&&a(N);try{await kt({defaultAgent:V??""})}catch(B){console.warn("Failed to save default agent:",B)}},[a,d]),T=o.useCallback(async N=>{S(N);try{await kt({smallModelUseDefault:N})}catch(V){console.warn("Failed to save small model preference:",V)}},[]),J=o.useCallback(async(N,V)=>{const B=N&&V?`${N}/${V}`:void 0;R(B);try{await kt({smallModelOverride:B??""})}catch(F){console.warn("Failed to save small model override:",F)}},[]),_=o.useMemo(()=>Pl(C),[C]);o.useEffect(()=>{if(A||k!==void 0)return;let N=!1;return(async()=>{try{const V=await dt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!V.ok)return;const B=await V.json().catch(()=>null);!N&&Array.isArray(B?.authenticatedProviders)&&y(B.authenticatedProviders.filter(F=>typeof F=="string"))}catch{}})(),()=>{N=!0}},[A,k]);const ee=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]),Q=ee.length>0;return o.useEffect(()=>{!Q&&j&&(g(void 0),l(void 0),r(void 0),kt({defaultVariant:""}).catch(()=>{}))},[j,r,l,Q]),v?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,Q?` (${j??s("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):t.jsx("span",{className:"text-foreground",children:s("settings.openchamber.defaults.summaryOpenCodeDefault")}),h&&t.jsxs(t.Fragment,{children:[" / ",t.jsx("span",{className:"text-foreground",children:h})]})]}),t.jsxs("div",{"data-settings-item":"sessions.default-model",className:oe("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(ja,{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(Dt,{value:j??M,onValueChange:P,disabled:!Q,children:[t.jsx(Et,{className:"w-fit min-w-[120px]",children:t.jsx(zt,{placeholder:s("settings.openchamber.defaults.field.thinkingPlaceholder"),children:I(j??M)})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:M,children:s("settings.openchamber.defaults.option.default")}),ee.map(N=>t.jsx(mt,{value:N,children:I(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(rc,{agentName:h||"",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:()=>f(!c),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),f(!c))},children:[t.jsx(bt,{checked:c,onChange:f,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":A,onClick:()=>{T(!A)},onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),T(!A))},children:[t.jsx(bt,{checked:A,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")})]}),A?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(ja,{providerId:_.providerId,modelId:_.modelId,onChange:J,allowedProviderIds:k})})]})]})]})},Al={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"}},ob={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"},lb=()=>{const{t:s}=st(),e=o.useMemo(()=>rs(),[]),n=o.useMemo(()=>fs(),[]),a=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),r=!e&&!n&&!a,i=Fe(F=>F.nativeNotificationsEnabled),l=Fe(F=>F.setNativeNotificationsEnabled),d=Fe(F=>F.notificationMode),c=Fe(F=>F.setNotificationMode),f=Fe(F=>F.notifyOnSubtasks),m=Fe(F=>F.setNotifyOnSubtasks),p=Fe(F=>F.notifyOnCompletion),u=Fe(F=>F.setNotifyOnCompletion),j=Fe(F=>F.notifyOnError),g=Fe(F=>F.setNotifyOnError),h=Fe(F=>F.notifyOnQuestion),x=Fe(F=>F.setNotifyOnQuestion),A=Fe(F=>F.notificationTemplates),S=Fe(F=>F.setNotificationTemplates),[C,R]=o.useState("default"),[k,y]=o.useState(!1),[v,E]=o.useState(!1),[K,U]=o.useState(!1);o.useEffect(()=>{if(!r){y(!1),E(!1);return}typeof Notification<"u"&&R(Notification.permission);const F=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;y(F),(async()=>{if(!F){E(!1);return}try{const q=await navigator.serviceWorker.getRegistration();if(!q){E(!1);return}const $=await q.pushManager.getSubscription();E(!!$)}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();R(O),O==="granted"?l(!0):W.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),W.error(s("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(F&&C==="granted"))},I=e||n||a||r&&typeof Notification<"u"&&Notification.permission==="granted",P=(F,O,q)=>{S({...A,[F]:{...A[F],[O]:q}})},z=F=>{const O="=".repeat((4-F.length%4)%4),q=(F+O).replace(/-/g,"+").replace(/_/g,"/"),$=atob(q),ie=new Uint8Array($.length);for(let le=0;le<$.length;le+=1)ie[le]=$.charCodeAt(le);return ie},T=async(F,O,q)=>{let $=null;const ie=new Promise((le,ne)=>{$=setTimeout(()=>{ne(new Error(q))},O)});try{return await Promise.race([F,ie])}finally{$&&clearTimeout($)}},J=async F=>{if(F.active)return;const O=F.installing||F.waiting;O&&O.state!=="activated"&&await T(new Promise(q=>{const $=()=>{O.state==="activated"&&(O.removeEventListener("statechange",$),q())};O.addEventListener("statechange",$),$()}),15e3,"Service worker activation timed out")},_=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 $=q.opts?navigator.serviceWorker.register("/sw.js",q.opts):navigator.serviceWorker.register("/sw.js");return await T($,1e4,`Service worker registration timed out (${q.label})`)}catch($){O=$}throw O instanceof Error?O:new Error("Service worker registration failed")},ee=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 _();try{await O.update()}catch{}return await J(O),O},Q=F=>{const O=F,q=[`type=${typeof F}`,`toString=${String(F)}`,`name=${String(O?.name??"")}`,`message=${String(O?.message??"")}`];let $="";try{$=JSON.stringify(F)}catch{}return{summary:q.filter(Boolean).join(" | "),json:$,stack:typeof O?.stack=="string"?O.stack:""}},N=async()=>{const F=qs();if(!F?.notifications){W.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"})?W.success(s("settings.notifications.page.toast.testNotificationSent")):W.error(s("settings.notifications.page.toast.testNotificationFailed"))}catch(O){console.error("Test notification failed:",O),W.error(s("settings.notifications.page.toast.testNotificationFailed"))}},V=async()=>{if(!k){W.error(s("settings.notifications.page.toast.pushUnsupported"));return}const F=qs();if(!F?.push){W.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}U(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const ae=await Notification.requestPermission();if(R(ae),ae!=="granted"){W.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){W.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){W.error(s("settings.notifications.page.toast.pushKeyLoadFailed"));return}const q=await ee();await J(q);const $=await q.pushManager.getSubscription();if(!("pushManager"in q)||!q.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const le=($??await T(q.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:z(O.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ne=le.keys;if(!le.endpoint||!ne?.p256dh||!ne.auth)throw new Error("Push subscription missing keys");if(!(await T(F.push.subscribe({endpoint:le.endpoint,keys:{p256dh:ne.p256dh,auth:ne.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:sc()}),15e3,"Push subscribe request timed out"))?.ok){W.error(s("settings.notifications.page.toast.enableBackgroundFailed"));return}E(!0),W.success(s("settings.notifications.page.toast.backgroundEnabled"))}catch(O){console.error("[Push] Enable failed:",O);const q=Q(O);W.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){W.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}U(!0);try{const q=await(await ee()).pushManager.getSubscription();if(!q){E(!1);return}const $=q.endpoint;await q.unsubscribe(),await F.push.unsubscribe({endpoint:$}),E(!1),W.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&&I,onClick:()=>{M(!(i&&I))},onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),M(!(i&&I)))},children:[t.jsx(bt,{checked:i&&I,onChange:F=>{M(F)},ariaLabel:s("settings.notifications.page.delivery.enableAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.delivery.enableLabel")})]}),i&&I&&!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":d==="always",onClick:()=>c(d==="always"?"hidden-only":"always"),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),c(d==="always"?"hidden-only":"always"))},children:[t.jsx(bt,{checked:d==="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(G,{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&&I&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-settings-item":"notifications.events",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.events.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>u(!p),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),u(!p))},children:[t.jsx(bt,{checked:p,onChange:u,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":f,onClick:()=>m(!f),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),m(!f))},children:[t.jsx(bt,{checked:f,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":j,onClick:()=>g(!j),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),g(!j))},children:[t.jsx(bt,{checked:j,onChange:g,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":h,onClick:()=>x(!h),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),x(!h))},children:[t.jsx(bt,{checked:h,onChange:x,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(ob[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:A[F].title,onChange:O=>P(F,"title",O.target.value),className:"h-7",placeholder:s(Al[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:A[F].message,onChange:O=>P(F,"message",O.target.value),className:"h-7",placeholder:s(Al[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(bt,{checked:k?v:!1,disabled:!k||K,onChange:F=>{F?V():B()},ariaLabel:s("settings.notifications.page.push.enableAria")}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:oe("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")})})]})})]})]})},Is=s=>{if(!s)return;s.pause();const{src:e}=s;e.startsWith("blob:")&&URL.revokeObjectURL(e),s.removeAttribute("src"),s.load()},cb=[{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"}],Dl=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 d;e[2]!==a?(d=t.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:a}),e[2]=a,e[3]=d):d=e[3];let c;return e[4]!==r||e[5]!==l||e[6]!==d?(c=t.jsxs("span",{className:"flex items-center gap-1.5",title:r,children:[l,d]}),e[4]=r,e[5]=l,e[6]=d,e[7]=c):c=e[7],c},db=({selectedModelId:s,onSelect:e})=>{const{t:n}=st(),a=fe.useCallback(u=>n(u),[n]),[r,i]=fe.useState(new Map),[l,d]=fe.useState(null),c=fe.useCallback(async()=>{try{const u=await dt("/api/dictation/status",{query:{provider:"local"}});if(!u.ok)return;const j=await u.json();Array.isArray(j?.models)&&i(new Map(j.models.map(g=>[g.id,g])))}catch{}},[]);fe.useEffect(()=>{c()},[c]);const f=Array.from(r.values()).some(u=>u.downloading);fe.useEffect(()=>{if(!f)return;const u=setInterval(()=>{c()},2e3);return()=>clearInterval(u)},[f,c]);const m=async u=>{d(u);try{await dt(`/api/dictation/models/${encodeURIComponent(u)}/download`,{method:"POST"}),await c()}catch{}finally{d(null)}},p=async u=>{d(u);try{await dt(`/api/dictation/models/${encodeURIComponent(u)}`,{method:"DELETE"}),await c()}catch{}finally{d(null)}};return t.jsx("div",{role:"radiogroup","aria-label":n("settings.voice.page.field.model"),className:"mt-1 space-y-0",children:cb.map(u=>{const j=s===u.id,g=r.get(u.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:j,onChange:()=>e(u.id),ariaLabel:a(u.labelKey)})}),t.jsxs("div",{className:"min-w-0 flex-1 cursor-pointer",role:"button",tabIndex:0,onClick:()=>e(u.id),onKeyDown:h=>{(h.key===" "||h.key==="Enter")&&(h.preventDefault(),e(u.id))},children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5",children:[t.jsx("span",{className:oe("typography-ui-label font-normal",j?"text-foreground":"text-foreground/50"),children:a(u.labelKey)}),u.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(u.badgeKey)}):null]}),t.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-4 gap-y-0.5",children:[t.jsx(Dl,{value:u.accuracy,label:n("settings.voice.page.stt.meta.accuracy")}),t.jsx(Dl,{value:u.speed,label:n("settings.voice.page.stt.meta.speed")}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:u.size})]}),g?.downloadError?t.jsx("p",{className:"mt-0.5 typography-meta text-[var(--status-error)]",children:g.downloadError}):null]}),t.jsx("div",{className:"flex w-14 flex-shrink-0 items-center justify-end gap-1 pt-0.5",children:g?.installed?t.jsxs(t.Fragment,{children:[t.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===u.id,onClick:()=>{p(u.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")})]}):g?.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 g.downloadProgress=="number"?`${g.downloadProgress}%`:""})]}):t.jsx(G,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===u.id,onClick:()=>{m(u.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"})})})]},u.id)})})},_r=[{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)"}],Hr="kokoro-en-v0_19",ub=()=>{const{t:s}=st(),[e,n]=fe.useState(null),[a,r]=fe.useState(!1),i=fe.useCallback(async()=>{try{const d=await dt("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const c=await d.json(),f=Array.isArray(c?.ttsModels)?c.ttsModels.find(m=>m.id===Hr):null;f&&n(f)}catch{}},[]);fe.useEffect(()=>{i()},[i]),fe.useEffect(()=>{if(!e?.downloading)return;const d=setInterval(()=>{i()},2e3);return()=>clearInterval(d)},[e?.downloading,i]);const l=async d=>{r(!0);try{const c=d==="POST"?`/api/dictation/models/${Hr}/download`:`/api/dictation/models/${Hr}`;await dt(c,{method:d}),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(G,{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(G,{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},mb=[{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"}],pb=()=>{const{t:s}=st(),{isMobile:e}=Ms(),n=it(b=>b.voiceProvider),a=it(b=>b.setVoiceProvider),r=it(b=>b.speechRate),i=it(b=>b.setSpeechRate),l=it(b=>b.speechPitch),d=it(b=>b.setSpeechPitch),c=it(b=>b.speechVolume),f=it(b=>b.setSpeechVolume),m=it(b=>b.sayVoice),p=it(b=>b.setSayVoice),u=it(b=>b.localTtsVoiceId),j=it(b=>b.setLocalTtsVoiceId),{speak:g,stop:h,isPlaying:x,error:A}=mm(),S=fe.useCallback(()=>{if(x){h();return}const b=_r.find(be=>be.id===u)?.label??String(u);g(s("settings.voice.page.preview.voiceLine",{voiceName:b}),{speakerId:u,speed:it.getState().speechRate})},[x,u,g,h,s]),C=it(b=>b.browserVoice),R=it(b=>b.setBrowserVoice),k=it(b=>b.openaiVoice),y=it(b=>b.setOpenaiVoice),v=it(b=>b.openaiApiKey),E=it(b=>b.setOpenaiApiKey),K=it(b=>b.openaiCompatibleUrl),U=it(b=>b.setOpenaiCompatibleUrl),M=it(b=>b.openaiCompatibleApiKey),I=it(b=>b.setOpenaiCompatibleApiKey),P=it(b=>b.openaiCompatibleVoice),z=it(b=>b.setOpenaiCompatibleVoice),T=it(b=>b.openaiCompatibleTtsModel),J=it(b=>b.setOpenaiCompatibleTtsModel),_=it(b=>b.showMessageTTSButtons),ee=it(b=>b.ttsInputMode),Q=it(b=>b.setTtsInputMode),N=it(b=>b.sttProvider),V=it(b=>b.setSttProvider),B=it(b=>b.sttServerUrl),F=it(b=>b.setSttServerUrl),O=it(b=>b.sttApiKey),q=it(b=>b.setSttApiKey),$=it(b=>b.sttModel),ie=it(b=>b.setSttModel),le=it(b=>b.sttLocalModel),ne=it(b=>b.setSttLocalModel),ye=it(b=>b.sttLanguage),ae=it(b=>b.setSttLanguage),ge=it(b=>b.setShowMessageTTSButtons),Ne=it(b=>b.dictationEnabled),he=it(b=>b.setDictationEnabled),[we,ce]=fe.useState(!1),[Z,se]=fe.useState([]),[ve,H]=fe.useState(!1),[te,re]=fe.useState(null),[pe,Me]=fe.useState(!1),[Se,Ae]=fe.useState(!1),[De,Pe]=fe.useState(null),[Oe,Te]=fe.useState(!1),[Ue,Be]=fe.useState(null),[Ke,Je]=fe.useState([]),[ue,Y]=fe.useState(!1);fe.useEffect(()=>((async()=>{const be=await kr.waitForVoices();Je(be)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Je(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const de=fe.useMemo(()=>Ke.filter(b=>b.lang).sort((b,be)=>{const Ee=b.lang.startsWith("en"),ze=be.lang.startsWith("en");if(Ee&&!ze)return-1;if(!Ee&&ze)return 1;const qe=b.lang.localeCompare(be.lang);return qe!==0?qe:b.name.localeCompare(be.name)}),[Ke]),je=fe.useCallback(()=>{if(ue){kr.cancelSpeech(),Y(!1);return}const b=Ke.find(qe=>qe.name===C),be=b?.name??s("settings.voice.page.preview.browserVoiceFallback"),Ee=s("settings.voice.page.preview.voiceLine",{voiceName:be});Y(!0);const ze=new SpeechSynthesisUtterance(Ee);ze.rate=r,ze.pitch=l,ze.volume=c,b&&(ze.voice=b,ze.lang=b.lang),ze.onend=()=>Y(!1),ze.onerror=()=>Y(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(ze)},[C,Ke,r,l,c,ue,s]);fe.useEffect(()=>()=>{ue&&kr.cancelSpeech()},[ue]),fe.useEffect(()=>{if(!_||n!=="openai"&&n!=="openai-compatible"){Me(v.trim().length>0);return}(async()=>{try{const ze=(await(await dt("/api/tts/status")).json()).available,qe=v.trim().length>0;Me(ze||qe)}catch{Me(v.trim().length>0)}})()},[v,_,n]),fe.useEffect(()=>{if(!_){ce(!1),se([]);return}dt("/api/tts/say/status").then(b=>b.json()).then(b=>{if(ce(b.available),b.voices){const be=b.voices.filter((Ee,ze,qe)=>qe.findIndex(rt=>rt.name===Ee.name)===ze).sort((Ee,ze)=>Ee.name.localeCompare(ze.name));se(be)}}).catch(()=>{ce(!1)})},[_]);const Re=fe.useCallback(async()=>{if(te){Is(te),re(null),H(!1);return}H(!0);let b=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 Ee=await be.blob(),ze=URL.createObjectURL(Ee);b=new Audio(ze),b.onended=()=>{Is(b),re(null),H(!1)},b.onerror=()=>{Is(b),re(null),H(!1)},re(b),await b.play()}catch{Is(b),re(null),H(!1)}},[m,r,te,s]);fe.useEffect(()=>()=>{Is(te)},[te]);const Ie=fe.useCallback(async()=>{if(De){Is(De),Pe(null),Ae(!1);return}Ae(!0);let b=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:v||void 0})});if(!be.ok){const qe=await be.json().catch(()=>({error:"Unknown error"}));throw new Error(qe.error||`HTTP ${be.status}`)}const Ee=await be.blob(),ze=URL.createObjectURL(Ee);b=new Audio(ze),b.onended=()=>{Is(b),Pe(null),Ae(!1)},b.onerror=()=>{Is(b),Pe(null),Ae(!1)},Pe(b),await b.play()}catch{Is(b),Pe(null),Ae(!1)}},[k,r,De,v,s]);fe.useEffect(()=>()=>{Is(De)},[De]);const Ve=fe.useCallback(async()=>{if(Ue){Is(Ue),Be(null),Te(!1);return}if(!K.trim())return;Te(!0);let b=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:P,model:T||void 0,speed:r,baseURL:K,apiKey:M||void 0})});if(!be.ok){const qe=await be.json().catch(()=>({error:"Unknown error"}));throw new Error(qe.error||`HTTP ${be.status}`)}const Ee=await be.blob(),ze=URL.createObjectURL(Ee);b=new Audio(ze),b.onended=()=>{Is(b),Be(null),Te(!1)},b.onerror=()=>{Is(b),Be(null),Te(!1)},Be(b),await b.play()}catch{Is(b),Be(null),Te(!1)}},[K,P,T,M,r,Ue,s]);fe.useEffect(()=>()=>{Is(Ue)},[Ue]);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":_,onClick:()=>ge(!_),onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),ge(!_))},children:[t.jsx(bt,{checked:_,onChange:ge,ariaLabel:s("settings.voice.page.field.messageReadAloudButtonAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.messageReadAloudButton")})]}),_&&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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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(G,{variant:"chip",size:"xs","aria-pressed":n==="browser",onClick:()=>a("browser"),className:"!font-normal",children:s("settings.voice.page.provider.browser")}),t.jsx(G,{variant:"chip",size:"xs","aria-pressed":n==="local",onClick:()=>a("local"),className:"!font-normal",children:s("settings.voice.page.provider.local")}),t.jsx(G,{variant:"chip",size:"xs","aria-pressed":n==="openai",onClick:()=>a("openai"),className:"!font-normal",children:"OpenAI"}),t.jsx(G,{variant:"chip",size:"xs","aria-pressed":n==="openai-compatible",onClick:()=>a("openai-compatible"),className:"!font-normal",children:s("settings.voice.page.provider.custom")}),we&&t.jsxs(G,{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:oe("typography-ui-label text-foreground",!pe&&"text-[var(--status-error)]"),children:s("settings.voice.page.field.apiKey")}),t.jsx("span",{className:oe("typography-meta ml-2",pe?"text-muted-foreground":"text-[var(--status-error)]/80"),children:s(pe&&!v?"settings.voice.page.field.apiKeyHintUsingConfig":pe?"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:v,onChange:b=>E(b.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"}),v&&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:oe("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:b=>U(b.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:b=>I(b.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:()=>I(""),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:b=>J(b.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:P,onChange:b=>z(b.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(G,{size:"xs",variant:"ghost",onClick:Ve,title:s("settings.voice.page.actions.preview"),disabled:!K.trim(),children:Oe?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(ub,{}),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(Dt,{value:String(u),onValueChange:b=>j(Number.parseInt(b,10)||0),children:[t.jsx(Et,{className:"w-fit",children:t.jsx(zt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder"),children:b=>_r.find(be=>String(be.id)===b)?.label??b})}),t.jsx(Mt,{children:_r.map(b=>t.jsx(mt,{value:String(b.id),children:b.label},b.id))})]}),t.jsx(G,{size:"xs",variant:"ghost",onClick:S,title:s("settings.voice.page.actions.preview"),children:x?t.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(D,{name:"play",className:"w-3.5 h-3.5"})}),A?t.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:A}):null]}),n==="openai"&&pe&&t.jsxs(t.Fragment,{children:[t.jsxs(Dt,{value:k,onValueChange:y,children:[t.jsx(Et,{className:"w-fit",children:t.jsx(zt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Mt,{children:mb.map(b=>t.jsx(mt,{value:b.value,children:b.label},b.value))})]}),t.jsx(G,{size:"xs",variant:"ghost",onClick:Ie,title:s("settings.voice.page.actions.preview"),children:Se?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"&&we&&Z.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(Dt,{value:m,onValueChange:p,children:[t.jsx(Et,{className:"w-fit",children:t.jsx(zt,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Mt,{children:Z.map(b=>t.jsx(mt,{value:b.name,children:b.name},b.name))})]}),t.jsx(G,{size:"xs",variant:"ghost",onClick:Re,title:s("settings.voice.page.actions.preview"),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==="browser"&&de.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(Dt,{value:C||"$auto",onValueChange:b=>R(b==="$auto"?"":b),children:[t.jsx(Et,{className:"w-fit max-w-[200px]",children:t.jsx(zt,{placeholder:s("settings.voice.page.field.auto")})}),t.jsxs(Mt,{children:[t.jsx(mt,{value:"$auto",children:s("settings.voice.page.field.auto")}),de.map(b=>t.jsxs(mt,{value:b.name,children:[b.name," (",b.lang,")"]},b.name))]})]}),t.jsx(G,{size:"xs",variant:"ghost",onClick:je,title:s("settings.voice.page.actions.preview"),children:ue?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:b=>i(Number(b.target.value)),className:X}),t.jsx(ks,{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:b=>d(Number(b.target.value)),className:X}),t.jsx(ks,{value:l,onValueChange:d,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:b=>f(Number(b.target.value)),className:X}),e?t.jsx(ks,{value:Math.round(c*100),onValueChange:b=>f(b/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(G,{variant:"chip",size:"xs","aria-pressed":ee==="sanitized",onClick:()=>Q("sanitized"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeSanitized")}),t.jsx(G,{variant:"chip",size:"xs","aria-pressed":ee==="raw",onClick:()=>Q("raw"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeRaw")}),t.jsx(G,{variant:"chip",size:"xs","aria-pressed":ee==="summarized",onClick:()=>Q("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":Ne,onClick:()=>he(!Ne),onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),he(!Ne))},children:[t.jsx(bt,{checked:Ne,onChange:he,ariaLabel:s("settings.voice.page.field.enableVoiceInputAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.enableVoiceInput")})]}),Ne&&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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Pt,{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(G,{variant:"chip",size:"xs","aria-pressed":N==="local",onClick:()=>V("local"),className:"!font-normal",children:s("settings.voice.page.provider.local")}),t.jsx(G,{variant:"chip",size:"xs","aria-pressed":N==="openai-compatible",onClick:()=>V("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(db,{selectedModelId:le,onSelect:ne})]}),N==="openai-compatible"&&t.jsxs("div",{className:"py-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:oe("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:b=>F(b.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:b=>q(b.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:$,onChange:b=>ie(b.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:ye,onChange:b=>ae(b.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"})})]})]})]})]})]})]})},Va=[{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}],_a=[{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}],gb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",hb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Wr=[{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"}],fb=[".yml",".yaml",".json"],xb="settings.openchamber.tunnel.error.invalidConfigExtension",ha=s=>{const e=s.trim().toLowerCase();return fb.some(n=>e.endsWith(n))},yb=s=>s==="ngrok"?"ngrok":"cloudflared",_c=()=>{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"},bb=(s,e=_c())=>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/",qr=(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():yb(n),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():_c(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():bb(n,r);return{provider:n,dependency:a,installCommand:i}},Hc=s=>s==="cloudflare"?"Cloudflare":s==="ngrok"?"Ngrok":s,El=s=>{const e=Ze.c(11),{provider:n}=s;let a;e[0]!==n?(a=Hc(n),e[0]=n,e[1]=a):a=e[1];const r=a,d=n==="cloudflare"||n==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==d?(c=oe("size-4 shrink-0",d),e[2]=d,e[3]=c):c=e[3];let f;e[4]!==c?(f=t.jsx(D,{name:"cloud",className:c}),e[4]=c,e[5]=f):f=e[5];let m;e[6]!==r?(m=t.jsx("span",{children:r}),e[6]=r,e[7]=m):m=e[7];let p;return e[8]!==f||e[9]!==m?(p=t.jsxs("span",{className:"flex items-center gap-2",children:[f,m]}),e[8]=f,e[9]=m,e[10]=p):p=e[10],p},fn=s=>s==="quick"?"quick":s==="managed-remote"?"managed-remote":s==="managed-local"?"managed-local":"quick",yi=(s,e,n)=>s.find(r=>r.ms===e)?.value||n,Ml=(s,e,n)=>{const a=yi(s,e,n);return s.find(r=>r.value===a)?.label||a},Tl=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`},vb=(s,e)=>mc(s,e,{hour:"2-digit",precision:"second"}),sr=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()}},jb=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():"",d=typeof i.name=="string"?i.name.trim():"",c=sr(typeof i.hostname=="string"?i.hostname:"");!l||!d||!c||e.has(l)||n.has(c)||(e.add(l),n.add(c),a.push({id:l,name:d,hostname:c}))}return a},wb=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Nb=()=>{const{t:s}=st(),e=Fe(me=>me.timeFormatPreference),n=o.useCallback(me=>s(me),[s]),[a,r]=o.useState("checking"),[i,l]=o.useState(null),[d,c]=o.useState(null),[f,m]=o.useState(null),[p,u]=o.useState(null),[j,g]=o.useState(null),[h,x]=o.useState(!1),[A,S]=o.useState(!1),[C,R]=o.useState(!1),[k,y]=o.useState("cloudflare"),[v,E]=o.useState(()=>qr("cloudflare")),[K,U]=o.useState([]),[M,I]=o.useState("quick"),[P,z]=o.useState(null),[T,J]=o.useState([]),[_,ee]=o.useState({}),[Q,N]=o.useState(""),[V,B]=o.useState({}),[F,O]=o.useState(new Set),[q,$]=o.useState(!1),[ie,le]=o.useState(""),[ne,ye]=o.useState(""),[ae,ge]=o.useState(""),[Ne,he]=o.useState(1800*1e3),[we,ce]=o.useState(480*60*1e3),[Z,se]=o.useState(""),[ve,H]=o.useState([]),[te,re]=o.useState(()=>Date.now()),[pe,Me]=o.useState(null),Se=s(xb),Ae=o.useRef(null),De=o.useMemo(()=>P?!ha(P):!1,[P]),Pe=o.useMemo(()=>T.find(me=>me.id===Q)||T[0]||null,[T,Q]),Oe=o.useMemo(()=>ve.map(me=>{const $e=me.expiresAt<=te,Qe=me.status==="active"&&!$e,We=Qe?Tl(me.expiresAt-te):me.inactiveReason==="expired"||$e?"expired":"inactive",xt=We==="expired"?s("settings.openchamber.tunnel.state.expired"):me.inactiveReason==="tunnel-revoked"?s("settings.openchamber.tunnel.state.revoked"):s("settings.openchamber.tunnel.state.inactive"),St=fn(me.mode);return{...me,isActive:Qe,mode:St,remainingTextForSession:We,inactiveLabel:xt}}),[te,ve,s]),Te=o.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>te:!1,[te,i?.bootstrapExpiresAt,i?.connectUrl]),Ue=o.useMemo(()=>!i||a!=="active"&&a!=="stopping"?!1:d===M,[d,a,i,M]),Be=o.useMemo(()=>!i||a!=="active"||!d?!1:d!==M,[d,a,i,M]),Ke=o.useMemo(()=>{if(typeof pe=="number"&&Number.isFinite(pe)&&pe>0)return pe;if(typeof window>"u")return null;const $e=na()||window.location.href;let Qe=0;try{Qe=Number(new URL($e).port)}catch{Qe=Number(window.location.port)}return Number.isFinite(Qe)&&Qe>0?Qe:null},[pe]),Je=o.useMemo(()=>K.find(me=>me.provider===k)??null,[K,k]),ue=o.useMemo(()=>{const me=new Set(Je?.modes?.map($e=>$e.key).filter($e=>$e==="quick"||$e==="managed-remote"||$e==="managed-local"));return me.size===0?Wr:Wr.filter($e=>me.has($e.value))},[Je]),Y=o.useMemo(()=>ue.some(me=>me.value==="managed-remote"||me.value==="managed-local"),[ue]),de=o.useMemo(()=>v.provider===k?v:qr(k),[v,k]),je=o.useCallback(async me=>{await on(me)},[]),Re=o.useCallback((me,$e)=>(E(qr($e,me)),me.available===!0),[]),Ie=o.useCallback(async(me,$e)=>{try{const Qe=await dt("/api/openchamber/tunnel/check",{query:{provider:me},...$e?{signal:$e}:{}});if(!Qe.ok)return null;const We=await Qe.json();if($e?.aborted)return null;const xt=Re(We,me);return r(St=>St==="checking"||St==="starting"||St==="active"||St==="stopping"?St:xt?"idle":"not-available"),xt}catch{return null}},[Re]),Ve=o.useCallback(async me=>{try{const[$e,Qe,We,xt]=await Promise.all([dt("/api/openchamber/tunnel/check",{signal:me}),dt("/api/openchamber/tunnel/status",{signal:me}),dt("/api/config/settings",{signal:me,headers:{Accept:"application/json"}}),dt("/api/openchamber/tunnel/providers",{signal:me})]),St=await $e.json(),ht=await Qe.json(),Rt=We.ok?await We.json():{},Gt=xt.ok?await xt.json():{},cs=ht.ttlConfig?.bootstrapTtlMs??(Rt?.tunnelBootstrapTtlMs===null?null:typeof Rt?.tunnelBootstrapTtlMs=="number"?Rt.tunnelBootstrapTtlMs:1800*1e3),ds=typeof ht.ttlConfig?.sessionTtlMs=="number"?ht.ttlConfig.sessionTtlMs:typeof Rt?.tunnelSessionTtlMs=="number"?Rt.tunnelSessionTtlMs:480*60*1e3,xs=fn(ht.mode??Rt?.tunnelMode),Zt=typeof Rt?.tunnelProvider=="string"&&Rt.tunnelProvider.trim().length>0?Rt.tunnelProvider.trim().toLowerCase():"cloudflare",Cs=typeof Rt?.managedLocalTunnelConfigPath=="string"&&Rt.managedLocalTunnelConfigPath.trim()||null,Ce=Re(St,Zt),vt=jb(ht?.managedRemoteTunnelPresets),jt=typeof ht.managedRemoteTunnelHostname=="string"?ht.managedRemoteTunnelHostname:"",qt=vt.length>0?vt:jt?[{id:`legacy-${sr(jt)}`,name:jt,hostname:sr(jt)}]:[],es=qt[0]?.id||"";if(he(cs),ce(ds),y(Zt),U(Array.isArray(Gt?.providers)?Gt.providers:[]),I(xs),z(Cs),J(qt),N(es),H(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:[])),Me(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(Ce?"idle":"not-available")}catch{me.aborted||(r("error"),u(s("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Re,s]);o.useEffect(()=>{const me=new AbortController;return Ve(me.signal),()=>me.abort()},[Ve]),o.useEffect(()=>{if(!i?.connectUrl){m(null);return}let me=!1;return tc.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then($e=>{me||m($e)}).catch(()=>{me||m(null)}),()=>{me=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){se(s("settings.openchamber.tunnel.state.noExpiry"));return}let me=null,$e=Date.now();const Qe=()=>{const St=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;St<=0?se(s("settings.openchamber.tunnel.state.expired")):se(Tl(St))},We=()=>{const St=Date.now();St-$e>=1e3&&(Qe(),$e=St),me=requestAnimationFrame(We)};Qe(),(typeof document>"u"||document.visibilityState==="visible")&&(me=requestAnimationFrame(We));const xt=()=>{document.visibilityState==="visible"&&me===null?me=requestAnimationFrame(We):document.visibilityState!=="visible"&&me!==null&&(cancelAnimationFrame(me),me=null)};return document.addEventListener("visibilitychange",xt),()=>{document.removeEventListener("visibilitychange",xt),me!==null&&cancelAnimationFrame(me)}},[s,i?.bootstrapExpiresAt]),o.useEffect(()=>{let me=null,$e=Date.now();const Qe=()=>{const xt=Date.now();xt-$e>=1e3&&(re(xt),$e=xt),me=requestAnimationFrame(Qe)};(typeof document>"u"||document.visibilityState==="visible")&&(me=requestAnimationFrame(Qe));const We=()=>{document.visibilityState==="visible"&&me===null?me=requestAnimationFrame(Qe):document.visibilityState!=="visible"&&me!==null&&(cancelAnimationFrame(me),me=null)};return document.addEventListener("visibilitychange",We),()=>{document.removeEventListener("visibilitychange",We),me!==null&&cancelAnimationFrame(me)}},[]),o.useEffect(()=>{if(a==="starting"||a==="stopping"||a==="checking")return;let me=!1;const $e=async()=>{try{const We=await dt("/api/openchamber/tunnel/status");if(!We.ok||me)return;const xt=await We.json();if(me)return;H(Array.isArray(xt.activeSessions)?xt.activeSessions:[]),O(new Set(Array.isArray(xt.managedRemoteTunnelTokenPresetIds)?xt.managedRemoteTunnelTokenPresetIds:[])),Me(typeof xt.localPort=="number"?xt.localPort:null)}catch{}},Qe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||$e()},5e3);return()=>{me=!0,window.clearInterval(Qe)}},[a]);const X=o.useCallback(async me=>{R(!0);try{await kt(me),Object.prototype.hasOwnProperty.call(me,"tunnelMode")&&me.tunnelMode&&I(me.tunnelMode),Object.prototype.hasOwnProperty.call(me,"tunnelProvider")&&typeof me.tunnelProvider=="string"&&y(me.tunnelProvider),Object.prototype.hasOwnProperty.call(me,"managedLocalTunnelConfigPath")&&z(me.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(me,"managedRemoteTunnelPresets")&&me.managedRemoteTunnelPresets&&J(me.managedRemoteTunnelPresets)}catch{W.error(s("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{R(!1)}},[s]),b=o.useCallback(async(me,$e)=>{S(!0);try{await kt({tunnelBootstrapTtlMs:me,tunnelSessionTtlMs:$e})}catch{W.error(s("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{S(!1)}},[s]),be=o.useCallback(async me=>{const $e=me.token.trim();if($e)try{const Qe={...V,[me.presetId]:$e};await kt({managedRemoteTunnelPresetTokens:Qe}),O(We=>{const xt=new Set(We);return xt.add(me.presetId),xt})}catch{W.error(s("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[V,s]),Ee=o.useCallback(async me=>{g(null),u(null);const $e=K.find(We=>We.provider===me),Qe=$e?.modes?.some(We=>We.key===M)?M:fn($e?.modes?.[0]?.key);await X({tunnelProvider:me,tunnelMode:Qe}),Ie(me)},[K,Ie,X,M]),ze=o.useCallback(async()=>{const me=await fc({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(me.success&&typeof me.path=="string"&&me.path.trim().length>0){const $e=me.path.trim();if(!ha($e)){W.error(Se);return}z($e),await X({managedLocalTunnelConfigPath:$e});return}Ae.current?.click()},[Se,X]),qe=o.useCallback(me=>{const $e=me.trim();z($e.length>0?$e:null)},[]),rt=o.useCallback(async()=>{if(P&&!ha(P)){W.error(Se);return}await X({managedLocalTunnelConfigPath:P})},[Se,P,X]),lt=o.useCallback(async()=>{z(null),await X({managedLocalTunnelConfigPath:null})},[X]),at=o.useCallback(async me=>{const $e=me.target.files?.[0];if(!$e)return;const Qe=$e.name.trim();if(Qe.length!==0){if(!ha(Qe)){W.error(Se);return}z(Qe),await X({managedLocalTunnelConfigPath:Qe}),me.target.value=""}},[Se,X]),ct=o.useCallback(async()=>{if(u(null),g(null),M==="managed-local"&&P&&!ha(P)){u(Se),W.error(Se);return}r("starting");try{let me="",$e="";if(M==="managed-remote"){if(!Pe){r("idle"),g(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),W.error(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}me=Pe.hostname,$e=(V[Pe.id]||"").trim(),await X({tunnelMode:"managed-remote",managedRemoteTunnelPresets:T})}const Qe=await dt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:k,mode:M,...M==="managed-remote"&&Pe?{managedRemoteTunnelPresetId:Pe.id,managedRemoteTunnelPresetName:Pe.name}:{},...M==="managed-remote"&&me?{managedRemoteTunnelHostname:me}:{},...M==="managed-remote"&&$e?{managedRemoteTunnelToken:$e}:{},...M==="managed-local"&&P?{configPath:P}:{}})}),We=await Qe.json();if(!Qe.ok||!We.ok){if(M==="managed-remote"&&typeof We.error=="string"&&We.error.includes("Managed remote tunnel token is required")){r("idle"),g(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),W.error(s("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(We.error||s("settings.openchamber.tunnel.toast.startFailed")),W.error(We.error||s("settings.openchamber.tunnel.toast.startFailed"));return}const xt=typeof We.url=="string"?We.url:"";if(!xt){r("error"),u(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),W.error(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:xt,connectUrl:typeof We.connectUrl=="string"?We.connectUrl:null,bootstrapExpiresAt:typeof We.bootstrapExpiresAt=="number"?We.bootstrapExpiresAt:null}),c(We.activeTunnelMode?fn(We.activeTunnelMode):We.mode?fn(We.mode):M),H(Array.isArray(We.activeSessions)?We.activeSessions:[]),Array.isArray(We.managedRemoteTunnelTokenPresetIds)&&O(new Set(We.managedRemoteTunnelTokenPresetIds)),typeof We.localPort=="number"&&Me(We.localPort),typeof We.mode=="string"&&I(fn(We.mode)),r("active"),We.replacedTunnel){const St=typeof We.revokedBootstrapCount=="number"?We.revokedBootstrapCount:0,ht=typeof We.invalidatedSessionCount=="number"?We.invalidatedSessionCount:0;St===1&&ht===1?W.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):St===1?W.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ht})):ht===1?W.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:St})):W.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:St,invalidatedSessionCount:ht}))}else W.success(s("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(s("settings.openchamber.tunnel.toast.startFailed")),W.error(s("settings.openchamber.tunnel.toast.startFailed"))}},[Se,T,X,Pe,V,s,k,M,P]),Ye=o.useCallback(async()=>{r("stopping");try{await dt("/api/openchamber/tunnel/stop",{method:"POST"});const me=await dt("/api/openchamber/tunnel/status");if(me.ok){const $e=await me.json();H(Array.isArray($e.activeSessions)?$e.activeSessions:[]),O(new Set(Array.isArray($e.managedRemoteTunnelTokenPresetIds)?$e.managedRemoteTunnelTokenPresetIds:[])),Me(typeof $e.localPort=="number"?$e.localPort:null)}l(null),c(null),m(null),r("idle"),W.success(s("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(s("settings.openchamber.tunnel.toast.stopFailed")),W.error(s("settings.openchamber.tunnel.toast.stopFailed"))}},[s]),_e=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),x(!0),W.success(s("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>x(!1),2e3)}catch{W.error(s("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[s,i?.connectUrl]),ft=o.useCallback(async me=>{const $e=Va.find(Qe=>Qe.value===me);$e&&(he($e.ms),await b($e.ms,we))},[b,we]),xe=o.useCallback(async me=>{const $e=_a.find(Qe=>Qe.value===me);!$e||$e.ms===null||(ce($e.ms),await b(Ne,$e.ms))},[Ne,b]),et=o.useCallback(async me=>{g(null),u(null),a!=="active"&&a!=="stopping"&&a!=="starting"&&r("idle"),await X({tunnelMode:me,managedRemoteTunnelPresets:T})},[T,X,a]),nt=o.useCallback(async(me,$e)=>{try{await kt({managedRemoteTunnelPresets:$e})}catch{W.error(s("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[s]),He=o.useCallback(me=>{const $e=T.find(Qe=>Qe.id===me);$e&&(N($e.id),g(null),nt($e,T))},[T,nt]),yt=o.useCallback(async()=>{const me=ie.trim(),$e=sr(ne),Qe=ae.trim();if(!me){W.error(s("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!$e){W.error(s("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Qe){W.error(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(T.some(St=>St.hostname===$e)){W.error(s("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const We={id:wb(),name:me,hostname:$e},xt=[...T,We];J(xt),N(We.id),ee(St=>({...St,[We.id]:!0})),B(St=>({...St,[We.id]:Qe})),g(null),$(!1),le(""),ye(""),ge(""),await X({tunnelMode:"managed-remote",managedRemoteTunnelPresets:xt,managedRemoteTunnelPresetTokens:{...V,[We.id]:Qe}}),await be({presetId:We.id,presetName:We.name,hostname:We.hostname,token:Qe}),W.success(s("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[T,ne,ie,ae,be,X,V,s]),Nt=o.useCallback(async me=>{const $e=T.find(ht=>ht.id===me);if(!$e)return;const Qe=T.filter(ht=>ht.id!==$e.id),We=Qe[0]?.id||"",xt=Q===$e.id?We:Q,St=Object.fromEntries(Object.entries(V).filter(([ht,Rt])=>ht!==$e.id&&Rt.trim().length>0));J(Qe),N(xt),ee(ht=>{const Rt={...ht};return delete Rt[$e.id],Rt}),B(ht=>{const Rt={...ht};return delete Rt[$e.id],Rt}),O(ht=>{const Rt=new Set(ht);return Rt.delete($e.id),Rt}),g(null),await X({managedRemoteTunnelPresets:Qe,managedRemoteTunnelPresetTokens:St}),W.success(s("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[T,X,Q,V,s]),Tt="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")})]}),Oe.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:Oe.map(me=>{const $e=me.mode==="quick",Qe=me.mode==="managed-remote",We=$e?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Qe?"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)]",xt=me.isActive?$e?"text-[var(--status-warning)]":Qe?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",St=s($e?"settings.openchamber.tunnel.badge.quick":Qe?"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:oe("size-2.5 shrink-0",xt)}),t.jsx("span",{className:oe("typography-micro rounded border px-1.5 py-0.5 uppercase",We),children:St}),t.jsx("span",{className:"typography-meta text-muted-foreground/80",children:s("settings.openchamber.tunnel.session.redeemedAt",{time:vb(me.createdAt,e)})}),t.jsx("span",{className:"typography-meta text-foreground",children:me.isActive?s("settings.openchamber.tunnel.session.expiresIn",{remaining:me.remainingTextForSession}):me.inactiveLabel===s("settings.openchamber.tunnel.state.inactive")?s("settings.openchamber.tunnel.state.inactive"):s("settings.openchamber.tunnel.session.inactiveWithReason",{reason:me.inactiveLabel})})]},me.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:de.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:de.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(Dt,{value:k,onValueChange:me=>{Ee(me)},disabled:C||a==="starting"||a==="stopping",children:[t.jsx(Et,{className:"max-w-[16rem]",children:t.jsx(zt,{placeholder:s("settings.openchamber.tunnel.field.providerPlaceholder"),children:Hc(k)})}),t.jsxs(Mt,{children:[K.length>0?K.map(me=>t.jsx(mt,{value:me.provider,children:t.jsx(El,{provider:me.provider})},me.provider)):t.jsx(mt,{value:"cloudflare",children:t.jsx(El,{provider:"cloudflare"})}),t.jsx(mt,{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:ue.map(me=>t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(G,{variant:"chip",size:"xs","aria-pressed":M===me.value,className:"!font-normal",onClick:()=>{et(me.value)},disabled:C||a==="starting"||a==="stopping",children:n(me.labelKey)})}),t.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:n(me.tooltipKey)})]},me.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(Dt,{value:yi(Va,Ne,"1800000"),onValueChange:me=>{ft(me)},disabled:A||C||a==="starting"||a==="stopping",children:[t.jsx(Et,{className:"max-w-[11rem] min-w-0",children:t.jsx(zt,{className:"truncate",children:Ml(Va,Ne,"1800000")})}),t.jsx(Mt,{children:Va.map(me=>t.jsx(mt,{value:me.value,children:me.label},me.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(Dt,{value:yi(_a,we,"28800000"),onValueChange:me=>{xe(me)},disabled:A||C||a==="starting"||a==="stopping",children:[t.jsx(Et,{className:"max-w-[11rem] min-w-0",children:t.jsx(zt,{className:"truncate",children:Ml(_a,we,"28800000")})}),t.jsx(Mt,{children:_a.map(me=>t.jsx(mt,{value:me.value,children:me.label},me.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")}),Y&&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(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>$(me=>!me),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((me,$e)=>{const Qe=V[me.id]||"",We=F.has(me.id),xt=_[me.id]??!1;return t.jsx("div",{className:oe($e<T.length-1&&"border-b border-[var(--surface-subtle)]"),children:t.jsxs(Mn,{open:xt,onOpenChange:St=>{ee(ht=>({...ht,[me.id]:St})),St&&He(me.id)},className:"py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-2 px-3",children:[t.jsxs(Tn,{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:[xt?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:me.name})]}),t.jsx(G,{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:me.name}),onClick:()=>{Nt(me.id)},disabled:a==="starting"||a==="stopping"||C,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(Rn,{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:me.hostname})]}),t.jsx(Xe,{type:"password",value:Qe,onChange:St=>{const ht=St.target.value;g(null),B(Rt=>({...Rt,[me.id]:ht}))},onBlur:St=>{const ht=St.currentTarget.value.trim();ht&&be({presetId:me.id,presetName:me.name,hostname:me.hostname,token:ht})},placeholder:s(We?"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(G,{variant:"ghost",size:"xs",className:"!font-normal",disabled:a==="starting"||a==="stopping"||Qe.trim().length===0,onClick:()=>{be({presetId:me.id,presetName:me.name,hostname:me.hostname,token:Qe})},children:s("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},me.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:me=>le(me.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:C||a==="starting"||a==="stopping"}),t.jsx(Xe,{value:ne,onChange:me=>ye(me.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:me=>ge(me.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(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{yt()},disabled:C||a==="starting"||a==="stopping",children:s("settings.common.actions.saveChanges")}),t.jsx(G,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{$(!1),le(""),ye(""),ge("")},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(Ct,{children:[t.jsx(It,{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(Pt,{sideOffset:8,className:"max-w-xs",children:s("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!Pe&&j&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:j})]}),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:Ae,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:me=>{at(me)}}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xe,{value:P||"",onChange:me=>{qe(me.target.value)},onBlur:()=>{rt()},placeholder:s("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:a==="starting"||a==="stopping"||C}),t.jsx(G,{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"})}),P&&t.jsx(G,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{lt()},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(P?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),De&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Se})]})}),!Ue&&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:()=>{je(gb)},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:()=>{je(hb)},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(Wr.find(me=>me.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(Dt,{value:Q||(T[0]?.id??""),onValueChange:me=>{He(me)},disabled:C||a==="starting"||a==="stopping"||T.length<=1,children:[t.jsx(Et,{children:t.jsx(zt,{placeholder:s("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Pe?.name})}),t.jsx(Mt,{fitContent:!0,children:T.map(me=>t.jsx(mt,{value:me.id,children:me.name},me.id))})]})]}),Be&&t.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(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(G,{size:"sm",variant:"outline",onClick:ct,disabled:a==="starting"||C||M==="managed-remote"&&!Pe||M==="managed-local"&&De,className:oe(Tt,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")})]})]}),Ue&&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})]}),Te&&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(G,{size:"sm",variant:"ghost",onClick:_e,className:"shrink-0 gap-1.5",children:[h?t.jsx(D,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):t.jsx(D,{name:"file-copy",className:"size-3.5"}),s(h?"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?Z: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:[f?t.jsx("img",{src:f,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(G,{size:"sm",variant:"outline",onClick:ct,disabled:a==="stopping"||C||M==="managed-local"&&De,className:Tt,children:[t.jsx(D,{name:"restart",className:"size-3.5"}),s("settings.openchamber.tunnel.actions.newConnectLink")]}),t.jsx(G,{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"&&p&&t.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:p}),t.jsx(G,{size:"sm",variant:"ghost",onClick:ct,children:s("settings.openchamber.tunnel.actions.retry")})]})]})},Wc=()=>{const{t:s}=st(),[e,n]=fe.useState(""),[a,r]=fe.useState(!0),[i,l]=fe.useState(!1),d=Fe(u=>u.showOpenCodeUpdateNotifications),c=Fe(u=>u.setShowOpenCodeUpdateNotifications);fe.useEffect(()=>{let u=!1;return(async()=>{try{const j=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!j.ok)return;const g=await j.json().catch(()=>null);if(u||!g)return;const h=typeof g.opencodeBinary=="string"?g.opencodeBinary.trim():"";n(h)}catch{}finally{u||r(!1)}})(),()=>{u=!0}},[]);const f=fe.useCallback(async()=>{if(!(typeof window>"u")&&rs())try{const u=await fc();u.success&&u.path&&u.path.trim().length>0&&n(u.path.trim())}catch{}},[]),m=fe.useCallback(async()=>{l(!0);try{const u=e.trim(),j=u.length>=2&&(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))?u.slice(1,-1).trim():u;await kt({opencodeBinary:j}),await Qn({message:s("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{l(!1)}},[s,e]),p=fe.useCallback(u=>{c(u),kt({showOpenCodeUpdateNotifications:u})},[c]);return t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.opencodeCli.title")}),t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(Pt,{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:u=>n(u.target.value),placeholder:s("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:a||i,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),t.jsx(G,{type:"button",variant:"outline",size:"xs",onClick:f,disabled:a||i||!rs(),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(bt,{checked:d,onChange:p,ariaLabel:s("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.opencodeCli.field.showUpdateNotifications")})]}),t.jsx("div",{className:"flex justify-start py-1.5",children:t.jsx(G,{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")})})]})]})},qc=()=>{const{t:s}=st(),e=rs()&&sa(),[n,a]=fe.useState(!1),[r,i]=fe.useState(!1),[l,d]=fe.useState(""),[c,f]=fe.useState(""),[m,p]=fe.useState(!1),[u,j]=fe.useState(null),[g,h]=fe.useState(!0),[x,A]=fe.useState(!1),[S,C]=fe.useState(!1),[R,k]=fe.useState(!1),[y,v]=fe.useState(!1),[E,K]=fe.useState(!1),[U,M]=fe.useState(!1),[I,P]=fe.useState(!1),[z,T]=fe.useState(!1),[J,_]=fe.useState(!1),[ee,Q]=fe.useState(!1),[N,V]=fe.useState(null),[B,F]=fe.useState(null);fe.useEffect(()=>{if(!e){h(!1);return}let ce=!1;return(async()=>{try{const Z=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!Z.ok)throw new Error(s("settings.openchamber.desktopNetwork.error.loadFailed"));const se=await Z.json().catch(()=>null);if(ce)return;const ve=se?.desktopLanAccessEnabled===!0,H=typeof se?.desktopUiPassword=="string"?se.desktopUiPassword:"";a(ve),i(ve),d(H),f(H),p(se?.desktopLanAccessActive===!0),j(typeof se?.desktopLanAccessBlockedReason=="string"?se.desktopLanAccessBlockedReason:null),V(null)}catch(Z){ce||V(Z instanceof Error?Z.message:s("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{ce||h(!1)}})(),()=>{ce=!0}},[e,s]),fe.useEffect(()=>{if(!e){C(!1);return}let ce=!1;return(async()=>{const Z=await Wm();ce||(C(Z?.supported===!0),k(Z?.enabled===!0))})(),()=>{ce=!0}},[e]),fe.useEffect(()=>{if(!e){K(!1);return}let ce=!1;return(async()=>{const Z=await qm();ce||(K(Z?.supported===!0),M(Z?.enabled===!0))})(),()=>{ce=!0}},[e]),fe.useEffect(()=>{if(!e){T(!1);return}let ce=!1;return(async()=>{const Z=await Gm();ce||(T(Z?.supported===!0),_(Z?.enabled===!0))})(),()=>{ce=!0}},[e]),fe.useEffect(()=>{if(!e||!r){F(null);return}let ce=!1;return(async()=>{const Z=await hc();ce||F(Z)})(),()=>{ce=!0}},[r,e]);const O=r!==n||c!==l,q=fe.useMemo(()=>{if(typeof window>"u")return null;const Z=na()||window.location.href;let se=0;try{se=Number(new URL(Z).port)}catch{se=Number(window.location.port)}return Number.isFinite(se)&&se>0?se:null},[]),$=r&&m&&B&&q?`http://${B}:${q}`:null,ie=r&&!c.trim(),le=n&&!m&&u==="missing-password",ne=g||x||!O||ie,ye=fe.useCallback(()=>{i(ce=>!ce)},[]),ae=fe.useCallback(ce=>{f(ce),ce.trim()||i(!1)},[]),ge=fe.useCallback(async()=>{if(!S||y)return;const ce=!R;k(ce),v(!0),V(null);try{const Z=await Jm(ce);if(!Z?.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));k(Z.enabled)}catch(Z){k(!ce),V(Z instanceof Error?Z.message:s("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{v(!1)}},[y,R,S,s]),Ne=fe.useCallback(async()=>{if(!E||I)return;const ce=!U;M(ce),P(!0),V(null);try{const Z=await Qm(ce);if(!Z)throw new Error(s("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!Z.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));M(Z.enabled)}catch(Z){M(!ce),V(Z instanceof Error?Z.message:s("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{P(!1)}},[I,U,E,s]),he=fe.useCallback(async()=>{if(!z||ee)return;const ce=!J;_(ce),Q(!0),V(null);try{const Z=await Ym(ce);if(!Z?.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));_(Z.enabled)}catch(Z){_(!ce),V(Z instanceof Error?Z.message:s("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{Q(!1)}},[ee,J,z,s]),we=fe.useCallback(async()=>{if(O){A(!0),V(null);try{if(!(await dt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:c})})).ok)throw new Error(s("settings.openchamber.desktopNetwork.error.saveFailed"));if(a(r),d(c),!await Xm())throw new Error(s("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(ce){V(ce instanceof Error?ce.message:s("settings.openchamber.desktopNetwork.error.saveFailed")),A(!1)}}},[c,r,O,s]);return e?t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.desktopNetwork.title")})}),t.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[S?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:ge,onKeyDown:ce=>{(ce.key==="Enter"||ce.key===" ")&&(ce.preventDefault(),ge())},children:[t.jsx(bt,{checked:R,onChange:ge,ariaLabel:s("settings.openchamber.desktopNetwork.field.launchAtLoginAria"),disabled:y}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.desktopNetwork.field.launchAtLogin")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.launchAtLoginDescription")})]})]}):null,E?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:Ne,onKeyDown:ce=>{(ce.key==="Enter"||ce.key===" ")&&(ce.preventDefault(),Ne())},children:[t.jsx(bt,{checked:U,onChange:Ne,ariaLabel:s("settings.openchamber.desktopNetwork.field.minimizeToTrayAria"),disabled:I}),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,z?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:he,onKeyDown:ce=>{(ce.key==="Enter"||ce.key===" ")&&(ce.preventDefault(),he())},children:[t.jsx(bt,{checked:J,onChange:he,ariaLabel:s("settings.openchamber.desktopNetwork.field.keepAwakeAria"),disabled:ee}),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:c,onChange:ce=>ae(ce.target.value),placeholder:s("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:g||x,required:r,"aria-invalid":ie}),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:ye,onKeyDown:ce=>{(ce.key==="Enter"||ce.key===" ")&&(ce.preventDefault(),ye())},children:[t.jsx(bt,{checked:r,onChange:ye,ariaLabel:s("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:g||x}),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")}),ie||le?t.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:s("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]})]}),N?t.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:N}):null,$?t.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[s(O&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),t.jsx("span",{className:"font-mono text-foreground",children:$})]}):null,t.jsx("div",{className:"flex justify-start py-1.5",children:t.jsx(G,{type:"button",size:"xs",onClick:we,disabled:ne,className:"shrink-0 !font-normal",children:s(x?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},kb=new Set(["shift","control","alt","meta"]),Sb=s=>{if(kb.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=hm(s.key);return n?(e.push(n),_n(e.join("+"))):null},Cb=()=>{const s=Ze.c(61),{t:e}=st();let n;s[0]!==e?(n=ne=>e(ne),s[0]=e,s[1]=n):n=s[1];const a=n,r=Fe(Ib),i=Fe(Pb),l=Fe(Ab),d=Fe(Db);let c;s[2]===Symbol.for("react.memo_cache_sentinel")?(c=pm(),s[2]=c):c=s[2];const f=c;let m;s[3]!==a?(m=(ne,ye)=>{const ae=`settings.openchamber.keyboardShortcuts.action.${ne}.label`,ge=a(ae);return ge===ae?ye:ge},s[3]=a,s[4]=m):m=s[4];const p=m,[u,j]=o.useState(null);let g;s[5]===Symbol.for("react.memo_cache_sentinel")?(g={},s[5]=g):g=s[5];const[h,x]=o.useState(g),[A,S]=o.useState(""),[C,R]=o.useState(""),[k,y]=o.useState(null),v=Eb;let E;s[6]!==r?(E=(ne,ye)=>{const ae=_n(ye);for(const ge of f){if(ge.id===ne)continue;const Ne=Gi(ge.id,r);if(_n(Ne)===ae)return ge.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=(ne,ye)=>{const ae=_n(ye),ge=K(ne,ae);if(ge){y({actionId:ne,combo:ae,conflictActionId:ge}),S("");return}const Ne={...r,[ne]:ae};i(ne,ae),v(Ne),y(null),S(""),R(Ji(ae)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(he=>{const we={...he};return delete we[ne],we})},s[8]=K,s[9]=i,s[10]=r,s[11]=e,s[12]=U):U=s[12];const M=U;let I;s[13]!==k||s[14]!==i||s[15]!==r||s[16]!==e?(I=()=>{if(!k)return;const ne={...r,[k.conflictActionId]:Qi,[k.actionId]:k.combo};i(k.conflictActionId,Qi),i(k.actionId,k.combo),v(ne),y(null),S(""),R(Ji(k.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(ye=>{const ae={...ye};return delete ae[k.actionId],ae})},s[13]=k,s[14]=i,s[15]=r,s[16]=e,s[17]=I):I=s[17];const P=I;let z;s[18]!==l||s[19]!==r?(z=ne=>{const ye={...r};delete ye[ne],l(ne),v(ye),x(ae=>{const ge={...ae};return delete ge[ne],ge}),y(null),S(""),R("")},s[18]=l,s[19]=r,s[20]=z):z=s[20];const T=z;let J;s[21]!==e?(J=e("settings.openchamber.keyboardShortcuts.title"),s[21]=e,s[22]=J):J=s[22];let _;s[23]!==J?(_=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:J}),s[23]=J,s[24]=_):_=s[24];let ee;s[25]!==d?(ee=()=>{d(),v({}),x({}),y(null),S(""),R("")},s[25]=d,s[26]=ee):ee=s[26];let Q;s[27]!==e?(Q=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),s[27]=e,s[28]=Q):Q=s[28];let N;s[29]!==ee||s[30]!==Q?(N=t.jsx(G,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ee,children:Q}),s[29]=ee,s[30]=Q,s[31]=N):N=s[31];let V;s[32]===Symbol.for("react.memo_cache_sentinel")?(V=t.jsx(It,{asChild:!0,children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[32]=V):V=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(Ct,{children:[V,t.jsx(Pt,{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]!==_?(O=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[_,N,F]})}),s[37]=N,s[38]=F,s[39]=_,s[40]=O):O=s[40];let q;s[41]!==P||s[42]!==A||s[43]!==k||s[44]!==e||s[45]!==C?(q=(A||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(G,{type:"button",size:"xs",className:"!font-normal",onClick:P,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),t.jsx(G,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>y(null),children:e("settings.common.actions.cancel")})]})]}),A&&t.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:A}),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]=P,s[42]=A,s[43]=k,s[44]=e,s[45]=C,s[46]=q):q=s[46];let $;s[47]!==p||s[48]!==u||s[49]!==h||s[50]!==T||s[51]!==M||s[52]!==r||s[53]!==e?($=f.map((ne,ye)=>{const ae=Gi(ne.id,r),ge=h[ne.id],Ne=ge??ae,he=typeof ge=="string"&&_n(ge)!==_n(ae);return t.jsxs("div",{className:oe("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",ye>0&&"border-t border-[var(--surface-subtle)]"),children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:p(ne.id,ne.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:u===ne.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):gm(Ne),onFocus:()=>{j(ne.id),S("")},onBlur:()=>{u===ne.id&&j(null)},onKeyDown:we=>{if(we.preventDefault(),we.stopPropagation(),we.key==="Escape"){j(null);return}const ce=Sb(we);ce&&(x(Z=>({...Z,[ne.id]:ce})),j(null),y(null),S(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),t.jsx(G,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const we=h[ne.id];if(!we){S(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}M(ne.id,we)},disabled:!he,children:e("settings.common.actions.saveChanges")}),t.jsx(G,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>T(ne.id),children:e("settings.common.actions.reset")})]})]},ne.id)}),s[47]=p,s[48]=u,s[49]=h,s[50]=T,s[51]=M,s[52]=r,s[53]=e,s[54]=$):$=s[54];let ie;s[55]!==$?(ie=t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:$}),s[55]=$,s[56]=ie):ie=s[56];let le;return s[57]!==O||s[58]!==q||s[59]!==ie?(le=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]=le):le=s[60],le};function Ib(s){return s.shortcutOverrides}function Pb(s){return s.setShortcutOverride}function Ab(s){return s.clearShortcutOverride}function Db(s){return s.resetAllShortcutOverrides}function Eb(s){kt({shortcutOverrides:s})}const Gc=()=>{const s=Ze.c(2),[e,n]=o.useState(0);let a,r;return s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>Zm(()=>n($b)),r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),o.useEffect(a,r),e},Mb=s=>{const e=Ze.c(20),{section:n}=s,{isMobile:a}=Ms();Gc();let r;e[0]!==a?(r=a&&Dn(),e[0]=a,e[1]=r):r=e[1];const i=r;let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=fs(),e[2]=l):l=e[2];const d=l;let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=rs()&&sa(),e[3]=c):c=e[3];const f=c;if(!n){let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=t.jsx(Ai,{}),e[4]=g):g=e[4];let h,x,A;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Vc,{})}),x=f&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(qc,{})}),A=!d&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Wc,{})}),e[5]=h,e[6]=x,e[7]=A):(h=e[5],x=e[6],A=e[7]);let S;e[8]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Bc,{})}),e[8]=S):S=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($c,{})}),e[9]=C):C=e[9];let R;e[10]!==i?(R=i&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(vc,{})}),e[10]=i,e[11]=R):R=e[11];let k;return e[12]!==R?(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:[g,h,x,A,S,C,R]})}),e[12]=R,e[13]=k):k=e[13],k}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return t.jsx(Rb,{});case"chat":return t.jsx(Lb,{});case"sessions":return t.jsx(Fb,{});case"shortcuts":return t.jsx(Tb,{});case"git":return t.jsx(Ob,{});case"github":return t.jsx(zb,{});case"notifications":return t.jsx(Ub,{});case"voice":return t.jsx(Kb,{});case"tunnel":return t.jsx(Bb,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const p=m;let u;e[16]!==p?(u=p(),e[16]=p,e[17]=u):u=e[17];let j;return e[18]!==u?(j=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:u})}),e[18]=u,e[19]=j):j=e[19],j},Tb=()=>{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},Rb=()=>{const s=Ze.c(3);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=fs(),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(Ai,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a,"fontSize","terminalFontSize","fileEditorKeymap","spacing","inputBarOffset","expandedEditorToolbar",...n?[]:["terminalQuickKeys"],"reportUsage"]}),s[2]=r):r=s[2],r},Lb=()=>{const s=Ze.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Ai,{visibleSettings:["sessionAssist","chatRenderMode","messageTransport","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader","wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","diffLayout","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck"]}),s[0]=e):e=s[0],e},Fb=()=>{const s=Ze.c(7);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=fs(),s[0]=e):e=s[0];const n=e;Gc();let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=rs()&&sa(),s[1]=a):a=s[1];const r=a;let i,l,d;s[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(Vc,{}),l=r&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(qc,{})}),d=!n&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Wc,{})}),s[2]=i,s[3]=l,s[4]=d):(i=s[2],l=s[3],d=s[4]);let c;s[5]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Bc,{})}),s[5]=c):c=s[5];let f;return s[6]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsxs("div",{className:"space-y-6",children:[i,l,d,c,t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx($c,{})})]}),s[6]=f):f=s[6],f},Ob=()=>{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(zc,{})}),s[0]=e):e=s[0],e},zb=()=>{const s=Ze.c(1);if(fs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Uc,{}),s[0]=e):e=s[0],e},Ub=()=>{const s=Ze.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(lb,{}),s[0]=e):e=s[0],e},Kb=()=>{const s=Ze.c(1);if(fs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(pb,{}),s[0]=e):e=s[0],e},Bb=()=>{const s=Ze.c(1);if(fs())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Nb,{}),s[0]=e):e=s[0],e};function $b(s){return s+1}const Jc=[{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}],Vb={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function Jn(s){const e=s.trim().toLowerCase();return Jc.find(n=>n.slug===e)??null}function Di(s){const e=(s??"").trim().toLowerCase();if(!e)return"home";const n=Vb[e];if(n)return n;const a=Jn(e);return a?a.slug:"home"}const _b=[{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.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-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.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.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:s=>!s.isVSCode},{id:"chat.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.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-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 Rl(s){return s.trim().toLocaleLowerCase()}function Hb({query:s,runtimeCtx:e,visiblePageSlugs:n,t:a,getPageTitle:r}){const i=Rl(s);if(!i)return[];const l=n?new Set(n):null,d=i.split(/\s+/).filter(Boolean);return _b.flatMap(c=>{if(l&&!l.has(c.page))return[];const f=Jn(c.page);if(!f||f.isAvailable&&!f.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const m=a(c.titleKey),p=c.descriptionKey?a(c.descriptionKey):null,u=Rl([m,p,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return d.every(j=>u.includes(j))?[{...c,title:m,description:p,pageTitle:r(c.page)}]:[]})}const bi=176,vi=280,Ll=8,Qc="__openchamberSettingsDetail";function Gr(s){return Math.min(vi,Math.max(bi,s))}const Wb=["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"},Gb="__add_provider__";function Jb(s,e){const n=fs(),a=!s&&Dn();return{isVSCode:n,isWeb:a,isDesktop:s,isMobile:e}}function Fl(s,e){return s.isAvailable?s.isAvailable(e):!0}function ji(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function fa(s,e){const n=new Set(e);let a=s,r=1;for(;n.has(a);)a=`${s}-${r}`,r+=1;return a}function Jr(s){if(!ji(s))return null;const e=s[Qc];if(!ji(e))return null;const n=e.page,a=e.stage;return typeof n!="string"||a!=="page-content"?null:{page:Di(n),stage:a}}function Qb(){return typeof window>"u"||!ji(window.history.state)?{}:window.history.state}function Yc(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 Qr=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 d;e[6]!==l?(d=t.jsx("p",{className:"typography-ui text-muted-foreground",children:l}),e[6]=l,e[7]=d):d=e[7];let c;e[8]!==i||e[9]!==d?(c=t.jsxs("div",{className:"space-y-1",children:[i,d]}),e[8]=i,e[9]=d,e[10]=c):c=e[10];let f;e[11]!==n?(f=()=>n("providers"),e[11]=n,e[12]=f):f=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=oe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=m):m=e[13];let p;e[14]!==a?(p=a("settings.view.home.cards.providers.title"),e[14]=a,e[15]=p):p=e[15];let u;e[16]!==p?(u=t.jsx("div",{className:"typography-ui-label text-foreground",children:p}),e[16]=p,e[17]=u):u=e[17];let j;e[18]!==a?(j=a("settings.view.home.cards.providers.description"),e[18]=a,e[19]=j):j=e[19];let g;e[20]!==j?(g=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:j}),e[20]=j,e[21]=g):g=e[21];let h;e[22]!==g||e[23]!==f||e[24]!==u?(h=t.jsxs("button",{type:"button",onClick:f,className:m,children:[u,g]}),e[22]=g,e[23]=f,e[24]=u,e[25]=h):h=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let A;e[28]===Symbol.for("react.memo_cache_sentinel")?(A=oe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=A):A=e[28];let S;e[29]!==a?(S=a("settings.view.home.cards.agents.title"),e[29]=a,e[30]=S):S=e[30];let C;e[31]!==S?(C=t.jsx("div",{className:"typography-ui-label text-foreground",children:S}),e[31]=S,e[32]=C):C=e[32];let R;e[33]!==a?(R=a("settings.view.home.cards.agents.description"),e[33]=a,e[34]=R):R=e[34];let k;e[35]!==R?(k=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:R}),e[35]=R,e[36]=k):k=e[36];let y;e[37]!==x||e[38]!==C||e[39]!==k?(y=t.jsxs("button",{type:"button",onClick:x,className:A,children:[C,k]}),e[37]=x,e[38]=C,e[39]=k,e[40]=y):y=e[40];let v;e[41]!==n?(v=()=>n("skills.catalog"),e[41]=n,e[42]=v):v=e[42];let E;e[43]===Symbol.for("react.memo_cache_sentinel")?(E=oe("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 I;e[50]!==M?(I=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:M}),e[50]=M,e[51]=I):I=e[51];let P;e[52]!==v||e[53]!==U||e[54]!==I?(P=t.jsxs("button",{type:"button",onClick:v,className:E,children:[U,I]}),e[52]=v,e[53]=U,e[54]=I,e[55]=P):P=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=oe("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 J;e[59]!==a?(J=a("settings.view.home.cards.mcp.title"),e[59]=a,e[60]=J):J=e[60];let _;e[61]!==J?(_=t.jsx("div",{className:"typography-ui-label text-foreground",children:J}),e[61]=J,e[62]=_):_=e[62];let ee;e[63]!==a?(ee=a("settings.view.home.cards.mcp.description"),e[63]=a,e[64]=ee):ee=e[64];let Q;e[65]!==ee?(Q=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ee}),e[65]=ee,e[66]=Q):Q=e[66];let N;e[67]!==z||e[68]!==_||e[69]!==Q?(N=t.jsxs("button",{type:"button",onClick:z,className:T,children:[_,Q]}),e[67]=z,e[68]=_,e[69]=Q,e[70]=N):N=e[70];let V;e[71]!==n?(V=()=>n("usage"),e[71]=n,e[72]=V):V=e[72];let B;e[73]===Symbol.for("react.memo_cache_sentinel")?(B=oe("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 $;e[80]!==q?($=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:q}),e[80]=q,e[81]=$):$=e[81];let ie;e[82]!==V||e[83]!==O||e[84]!==$?(ie=t.jsxs("button",{type:"button",onClick:V,className:B,children:[O,$]}),e[82]=V,e[83]=O,e[84]=$,e[85]=ie):ie=e[85];let le;e[86]!==h||e[87]!==y||e[88]!==P||e[89]!==N||e[90]!==ie?(le=t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[h,y,P,N,ie]}),e[86]=h,e[87]=y,e[88]=P,e[89]=N,e[90]=ie,e[91]=le):le=e[91];let ne;return e[92]!==le||e[93]!==c?(ne=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,le]})}),e[92]=le,e[93]=c,e[94]=ne):ne=e[94],ne},Yb=s=>{const e=Ze.c(128),{onClose:n,forceMobile:a,isWindowed:r,visiblePageSlugs:i,initialMobileStage:l}=s,d=l===void 0?"nav":l,{t:c}=st(),f=Ms(),m=a??f.isMobile,p=Fe(Xb),u=Fe(Zb),j=Fe(ev);let g;e[0]!==p?(g=Di(p),e[0]=p,e[1]=g):g=e[1];const h=g,[x,A]=o.useState(d),S=o.useRef(null),[C,R]=o.useState(216),[k,y]=o.useState(""),[v,E]=o.useState(null),[K,U]=o.useState(0),[M,I]=o.useState(!1),[P,z]=o.useState(!1),T=o.useRef(0),J=o.useRef(C),_=o.useRef(null);let ee;e[2]===Symbol.for("react.memo_cache_sentinel")?(ee=[],e[2]=ee):ee=e[2];const Q=o.useRef(ee),N=o.useRef(0),V=o.useRef(!1);let B;e[3]===Symbol.for("react.memo_cache_sentinel")?(B=rs(),e[3]=B):B=e[3];const F=B;let O;e[4]===Symbol.for("react.memo_cache_sentinel")?(O=rs()&&sa(),e[4]=O):O=e[4];const q=O;let $;e[5]===Symbol.for("react.memo_cache_sentinel")?($=rs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",e[5]=$):$=e[5];const ie=$;let le;e[6]===Symbol.for("react.memo_cache_sentinel")?(le=rs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",e[6]=le):le=e[6];const ne=le;let ye;e[7]!==m?(ye=Jb(F,m),e[7]=m,e[8]=ye):ye=e[8];const ae=ye;let ge;if(e[9]!==m||e[10]!==ae||e[11]!==i){const ot=i?new Set(i):null;let pt;e[13]!==ae?(pt=Xt=>Fl(Xt,ae),e[13]=ae,e[14]=pt):pt=e[14];let wt;e[15]!==ae.isVSCode?(wt=Xt=>!(ae.isVSCode&&Xt.slug==="projects"),e[15]=ae.isVSCode,e[16]=wt):wt=e[16];let Yt;e[17]!==m?(Yt=Xt=>!(m&&Xt.slug==="shortcuts"),e[17]=m,e[18]=Yt):Yt=e[18],ge=Jc.filter(tv).filter(Xt=>!ot||ot.has(Xt.slug)).filter(pt).filter(wt).filter(Yt),e[9]=m,e[10]=ae,e[11]=i,e[12]=ge}else ge=e[12];const Ne=ge;let he;e[19]===Symbol.for("react.memo_cache_sentinel")?(he=new Map(Wb.map(sv)),e[19]=he):he=e[19];const we=he;let ce;if(e[20]!==Ne){let ot;e[22]===Symbol.for("react.memo_cache_sentinel")?(ot=(pt,wt)=>(we.get(pt.slug)??999)-(we.get(wt.slug)??999),e[22]=ot):ot=e[22],ce=Ne.slice().sort(ot),e[20]=Ne,e[21]=ce}else ce=e[21];const Z=ce,se=ss(nv);let ve,H;e[23]!==M?(ve=()=>{if(typeof window>"u")return;const ot=()=>{if(!M){const pt=Gr(Math.floor(window.innerWidth*.12));R(pt)}};return window.addEventListener("resize",ot),()=>window.removeEventListener("resize",ot)},H=[M],e[23]=M,e[24]=ve,e[25]=H):(ve=e[24],H=e[25]),o.useEffect(ve,H);let te,re;e[26]!==P?(te=()=>{if(!P)return;const ot=wt=>{const Yt=wt.clientX-T.current,Xt=Gr(J.current+Yt);R(Xt),I(!0)},pt=()=>z(!1);return window.addEventListener("pointermove",ot),window.addEventListener("pointerup",pt,{once:!0}),()=>{window.removeEventListener("pointermove",ot),window.removeEventListener("pointerup",pt)}},re=[P],e[26]=P,e[27]=te,e[28]=re):(te=e[27],re=e[28]),o.useEffect(te,re);let pe;e[29]!==C?(pe=ot=>{z(!0),T.current=ot.clientX,J.current=C,ot.preventDefault()},e[29]=C,e[30]=pe):pe=e[30];const Me=pe;let Se;e[31]!==C?(Se=ot=>{const pt=ot.shiftKey?Ll*4:Ll;let wt;e:switch(ot.key){case"ArrowLeft":{wt=C-pt;break e}case"ArrowRight":{wt=C+pt;break e}case"Home":{wt=bi;break e}case"End":{wt=vi;break e}default:return}ot.preventDefault(),R(Gr(wt)),I(!0)},e[31]=C,e[32]=Se):Se=e[32];const Ae=Se;let De;e[33]!==u||e[34]!==r||e[35]!==ae.isVSCode||e[36]!==h?(De=()=>{if(!(!u&&!ae.isVSCode&&!r)){if(h==="agents"){mr.getState().loadAgents();return}if(h==="commands"){pr.getState().loadCommands();return}if(h==="mcp"){ea.getState().loadMcpConfigs();return}if(h==="plugins"){ls.getState().loadPlugins();return}(h==="skills.installed"||h==="skills.catalog")&&(an.getState().loadSkills(),sn.getState().loadCatalog()),h==="snippets"&&hr.getState().loadSnippets()}},e[33]=u,e[34]=r,e[35]=ae.isVSCode,e[36]=h,e[37]=De):De=e[37];let Pe;e[38]!==se||e[39]!==u||e[40]!==r||e[41]!==ae.isVSCode||e[42]!==h?(Pe=[se,u,r,ae.isVSCode,h],e[38]=se,e[39]=u,e[40]=r,e[41]=ae.isVSCode,e[42]=h,e[43]=Pe):Pe=e[43],o.useEffect(De,Pe);let Oe;e[44]!==m||e[45]!==j?(Oe=ot=>{if(j(ot),S.current=ot,!m)return;const pt=Jn(ot);if(!pt||pt.slug==="home"){A("nav");return}A(pt.kind==="split"?"page-sidebar":"page-content")},e[44]=m,e[45]=j,e[46]=Oe):Oe=e[46];const Te=Oe;let Ue;e[47]!==h?(Ue=Jn(h),e[47]=h,e[48]=Ue):Ue=e[48];const Be=Ue;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 Je=Ke;let ue;e[50]!==c?(ue=ot=>{switch(ot){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]=ue):ue=e[51];const Y=ue;let de;e[52]!==Y||e[53]!==ae||e[54]!==k||e[55]!==c||e[56]!==i?(de=Hb({query:k,runtimeCtx:{...ae,isDesktopLocalOrigin:q,isMac:ie,isWindows:ne},visiblePageSlugs:i,t:c,getPageTitle:Y}),e[52]=Y,e[53]=ae,e[54]=k,e[55]=c,e[56]=i,e[57]=de):de=e[57];const je=de,Re=cv;let Ie;if(e[58]!==je){Ie=[];const ot=new Map;for(const pt of je){let wt=ot.get(pt.page);wt||(wt={page:pt.page,pageTitle:pt.pageTitle,results:[]},ot.set(pt.page,wt),Ie.push(wt)),wt.results.push(pt)}e[58]=je,e[59]=Ie}else Ie=e[59];const Ve=Ie;let X;e[60]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{U(0),N.current=0,V.current=!1},e[60]=X):X=e[60];let b;e[61]!==k?(b=[k],e[61]=k,e[62]=b):b=e[62],o.useEffect(X,b);let be,Ee;e[63]!==K?(be=()=>{N.current=K},Ee=[K],e[63]=K,e[64]=be,e[65]=Ee):(be=e[64],Ee=e[65]),o.useEffect(be,Ee);let ze,qe;e[66]!==K?(ze=()=>{Q.current[K]?.scrollIntoView({block:"nearest"})},qe=[K],e[66]=K,e[67]=ze,e[68]=qe):(ze=e[67],qe=e[68]),o.useEffect(ze,qe);let rt,lt;e[69]!==K||e[70]!==je.length?(rt=()=>{K>=je.length&&U(Math.max(0,je.length-1)),Q.current.length=je.length},lt=[K,je.length],e[69]=K,e[70]=je.length,e[71]=rt,e[72]=lt):(rt=e[71],lt=e[72]),o.useEffect(rt,lt);let at;e[73]!==m||e[74]!==Te?(at=ot=>{const pt=Re(ot);E(pt),Te(ot.page),m&&A("page-content"),ot.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(dv,50)},e[73]=m,e[74]=Te,e[75]=at):at=e[75];const ct=at;let Ye;e[76]!==ct||e[77]!==k||e[78]!==je?(Ye=ot=>{if(k.trim()){if(ot.key==="Escape"){ot.preventDefault(),y("");return}if(je.length!==0){if(ot.key==="ArrowDown"){ot.preventDefault(),V.current=!0,U(pt=>(pt+1)%je.length);return}if(ot.key==="ArrowUp"){ot.preventDefault(),V.current=!0,U(pt=>(pt-1+je.length)%je.length);return}if(ot.key==="Enter"){ot.preventDefault();const pt=(N.current%je.length+je.length)%je.length,wt=je[pt]??je[0];wt&&ct(wt)}}}},e[76]=ct,e[77]=k,e[78]=je,e[79]=Ye):Ye=e[79];const _e=Ye;let ft;e[80]!==v?(ft=()=>{const ot=v;if(!ot)return;let pt=!1;const wt=window.requestAnimationFrame(()=>{if(pt)return;const Yt=typeof CSS<"u"&&CSS.escape?CSS.escape(ot):ot.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Xt=_.current?.querySelector(`[data-settings-item="${Yt}"]`);Xt&&(E(null),Xt.scrollIntoView({block:"center",behavior:"smooth"}),Xt.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Xt.removeAttribute("data-settings-search-highlight")},1600))});return()=>{pt=!0,window.cancelAnimationFrame(wt)}},e[80]=v,e[81]=ft):ft=e[81];let xe;e[82]!==v||e[83]!==h?(xe=[v,h],e[82]=v,e[83]=h,e[84]=xe):xe=e[84],o.useEffect(ft,xe);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,He=uv;let yt;e[87]!==Te||e[88]!==nt||e[89]!==ae?(yt=ot=>{const pt=Jn(ot);if(pt&&!Fl(pt,ae))return nt();switch(ot){case"home":return t.jsx(Qr,{onOpen:Te});case"projects":return t.jsx(rx,{});case"remote-instances":return t.jsx(Tx,{});case"agents":return t.jsx(sg,{});case"behavior":return t.jsx(og,{});case"commands":return t.jsx(fg,{});case"mcp":return t.jsx(Wg,{});case"plugins":return t.jsx(Mh,{});case"skills.installed":return t.jsx(nl,{view:"installed"});case"skills.catalog":return t.jsx(nl,{view:"catalog"});case"providers":return t.jsx($x,{});case"usage":return t.jsx(wy,{});case"about":return t.jsx("div",{className:"h-full overflow-auto px-5 py-6",children:t.jsx(vc,{})});case"magic-prompts":return t.jsx(Iy,{});case"snippets":return t.jsx(My,{});case"git":return t.jsx(Oy,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const wt=Je[ot]??"visual";return t.jsx(Mb,{section:wt})}default:return t.jsx(Qr,{onOpen:Te})}},e[87]=Te,e[88]=nt,e[89]=ae,e[90]=yt):yt=e[90];const Nt=yt;let Tt,me;e[91]!==m||e[92]!==x||e[93]!==h?(Tt=()=>{if(!m||x!=="nav"||h==="home"||S.current===h)return;const ot=Jn(h);!ot||ot.slug==="home"||(S.current=h,A(ot.kind==="split"?"page-sidebar":"page-content"))},me=[m,x,h],e[91]=m,e[92]=x,e[93]=h,e[94]=Tt,e[95]=me):(Tt=e[94],me=e[95]),o.useEffect(Tt,me);const $e=m&&x!=="nav",Qe=m&&x==="page-content"&&h==="skills.installed",We=x==="page-content"&&Be?.kind==="split"&&!Qe;let xt;e[96]!==Qe||e[97]!==$e||e[98]!==c?(xt=c(Qe?"settings.view.actions.back":$e?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[96]=Qe,e[97]=$e,e[98]=c,e[99]=xt):xt=e[99];const St=xt,ht=fm();let Rt;e[100]!==ae.isVSCode?(Rt=ot=>{if(typeof window>"u"||ae.isVSCode)return;const pt=Jr(window.history.state);pt?.page===ot&&pt.stage==="page-content"||window.history.pushState({...Qb(),[Qc]:{page:ot,stage:"page-content"}},"",window.location.href)},e[100]=ae.isVSCode,e[101]=Rt):Rt=e[101];const Gt=Rt;let cs;e[102]!==Gt||e[103]!==h?(cs=()=>{A("page-content"),h==="skills.installed"&&Gt(h)},e[102]=Gt,e[103]=h,e[104]=cs):cs=e[104];const ds=cs;let xs;e[105]!==Qe||e[106]!==ae.isVSCode||e[107]!==h?(xs=()=>{if(Qe){if((typeof window<"u"?Jr(window.history.state):null)?.page===h&&!ae.isVSCode){window.history.back();return}A("page-sidebar");return}A("nav")},e[105]=Qe,e[106]=ae.isVSCode,e[107]=h,e[108]=xs):xs=e[108];const Zt=xs;let Cs,Ce;e[109]!==m||e[110]!==ae.isVSCode||e[111]!==h?(Cs=()=>{if(!m||ae.isVSCode)return;const ot=pt=>{if(h!=="skills.installed")return;if(Jr(pt.state)?.page==="skills.installed"){A("page-content");return}A(mv)};return window.addEventListener("popstate",ot),()=>{window.removeEventListener("popstate",ot)}},Ce=[m,ae.isVSCode,h],e[109]=m,e[110]=ae.isVSCode,e[111]=h,e[112]=Cs,e[113]=Ce):(Cs=e[112],Ce=e[113]),o.useEffect(Cs,Ce);let vt;e[114]===Symbol.for("react.memo_cache_sentinel")?(vt=()=>{A("page-sidebar")},e[114]=vt):vt=e[114];const jt=vt,qt=()=>{const ot=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=>y(pt.target.value),onKeyDown:_e,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"}),ot&&t.jsx("button",{type:"button",onClick:()=>y(""),"aria-label":c("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:t.jsx(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:ot?je.length>0?(()=>{let pt=0;return Ve.map(wt=>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:wt.pageTitle}),wt.results.map(Yt=>{const Xt=pt;pt=pt+1;const Ge=Xt===K,Ts=!!Yt.description;return t.jsxs("button",{type:"button",ref:aa=>{Q.current[Xt]=aa},onMouseMove:()=>{V.current=!1,U(Xt)},onClick:()=>ct(Yt),className:oe("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ts?"min-h-11 py-1.5":"py-2",Ge?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Yt.title}),Ts&&t.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:Yt.description})]},Yt.id)})]},wt.page))})():t.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:c("settings.view.search.noResults")}):Z.map(pt=>{const wt=h===pt.slug,Yt=Yc(pt.slug);return!Yt&&pt.slug!=="mcp"?null:t.jsx(Ct,{children:t.jsx(It,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:()=>Te(pt.slug),"aria-current":wt?"page":void 0,className:oe("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",wt?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[pt.slug==="mcp"?t.jsx(cp,{className:"h-4 w-4 shrink-0"}):t.jsx(D,{name:Yt,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:Y(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(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsxs("button",{type:"button",className:oe("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:gv,children:[t.jsx(D,{name:"restart",className:"h-4 w-4 shrink-0"}),t.jsx("span",{children:c("settings.view.actions.reloadOpenCode")})]})}),t.jsx(Pt,{children:c("settings.view.actions.reloadOpenCodeTooltip")})]})})})]})},es=()=>{if(x==="nav")return t.jsx("div",{className:oe("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:qt()})})});if(!Be)return t.jsx("div",{className:"flex-1 bg-background"});if(x==="page-sidebar"){if(Be.kind!=="split"){const pt=Nt(h);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:oe("flex-1 min-h-0 overflow-hidden",ae.isVSCode?"bg-background":"bg-sidebar"),children:t.jsx(gn,{children:He(h,{onItemSelect:ds})})})}const ot=Nt(h);return t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(gn,{children:ot})})};let Bt;e[115]!==Be||e[116]!==Te||e[117]!==Nt||e[118]!==ae.isVSCode||e[119]!==h?(Bt=()=>!Be||h==="home"?t.jsx(Qr,{onOpen:Te}):Be.kind==="split"?t.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[t.jsx("div",{className:oe("w-[264px] min-w-[264px] border-r",ae.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:t.jsx(gn,{children:He(h,{})})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(gn,{children:Nt(h)})})]}):t.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:t.jsx(gn,{children:Nt(h)})}),e[115]=Be,e[116]=Te,e[117]=Nt,e[118]=ae.isVSCode,e[119]=h,e[120]=Bt):Bt=e[120];const ys=Bt,ws="true";let Qt;e[121]===Symbol.for("react.memo_cache_sentinel")?(Qt=oe("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[121]=Qt):Qt=e[121];const Fs=m?t.jsxs("div",{className:oe("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?Zt:n,"aria-label":St,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:x==="nav"?c("settings.view.home.title"):Be?Y(Be.slug):c("settings.view.home.title")}),We&&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:oe("absolute left-3 z-50",r?"top-2":"top-3"),children:t.jsx("button",{type:"button",onClick:Zt,"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:oe("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",Gs=m?es():t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:oe("relative flex h-full min-h-0 flex-col overflow-hidden border-r",F?"bg-sidebar":ae.isVSCode?"bg-background":"bg-sidebar",P?"":"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:oe("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)]",P?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:Me,onKeyDown:Ae,role:"separator","aria-orientation":"vertical","aria-valuemin":bi,"aria-valuemax":vi,"aria-valuenow":C,"aria-label":c("settings.view.actions.resizeNavigation")}),t.jsx(gn,{children:qt()})]}),t.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:ys()})]});let Bs;e[122]!==Gs?(Bs=t.jsx("div",{className:kn,children:Gs}),e[122]=Gs,e[123]=Bs):Bs=e[123];let cn;return e[124]!==Qt||e[125]!==Fs||e[126]!==Bs?(cn=t.jsxs("div",{ref:_,"data-settings-view":ws,className:Qt,children:[Fs,Bs]}),e[124]=Qt,e[125]=Fs,e[126]=Bs,e[127]=cn):cn=e[127],cn};function Xb(s){return s.settingsPage}function Zb(s){return s.isSettingsDialogOpen}function ev(s){return s.setSettingsPage}function tv(s){return s.slug!=="home"}function sv(s,e){return[s,e]}function nv(s){return s.activeProjectId}function av(s){return s.name}function rv(s){return s.name}function iv(s){return s.name}function ov(s){return s.name}function lv(s){return s.name}function cv(s){if(s.id.startsWith("agents.")){const e=mr.getState(),n=fa("new-agent",e.agents.map(av));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=pr.getState(),n=fa("new-command",e.commands.map(rv));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=ea.getState(),n=fa("new-mcp-server",e.mcpServers.map(iv));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=hr.getState(),n=fa("new-snippet",e.snippets.map(ov));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=fa("new-skill",e.skills.map(lv));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"&&it.getState().setSelectedProvider(Gb),s.id==="plugins.create"?"plugins.spec":s.id}function dv(){window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))}function uv(s,e){switch(s){case"projects":return t.jsx(Ff,{onItemSelect:e.onItemSelect});case"agents":return t.jsx(Jp,{onItemSelect:e.onItemSelect});case"commands":return t.jsx(lg,{onItemSelect:e.onItemSelect});case"mcp":return t.jsx(xg,{onItemSelect:e.onItemSelect});case"plugins":return t.jsx(vh,{onItemSelect:e.onItemSelect});case"skills.installed":return t.jsx(Rh,{onItemSelect:e.onItemSelect});case"providers":return t.jsx(Fx,{onItemSelect:e.onItemSelect});case"usage":return t.jsx(ey,{onItemSelect:e.onItemSelect});case"magic-prompts":return t.jsx(ky,{onItemSelect:e.onItemSelect});case"snippets":return t.jsx(Py,{onItemSelect:e.onItemSelect});default:return null}}function mv(s){return s==="page-content"?"page-sidebar":s}function pv(){}function gv(){Qn({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]}).catch(pv)}const Xj=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:Yb,getSettingsNavIcon:Yc},Symbol.toStringTag,{value:"Module"})),hv=["chat","git","diff","terminal","files","diagram"],fv=["settings","agents","commands","skills","providers","usage","git-identities"],Os={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Ol(s){const e=xv();return{sessionId:yv(e),tab:bv(e),settingsPath:vv(e),diffFile:jv(e)}}function xv(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function yv(s){const e=s.get(Os.SESSION);return!e||e.trim().length===0?null:e.trim()}function bv(s){const e=s.get(Os.TAB);if(!e)return null;const n=e.toLowerCase().trim();return hv.includes(n)?n:null}function vv(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":(fv.includes(n),n)}function jv(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 zl(){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 wv="chat";function Xc(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!==wv&&e.set(Os.TAB,s.tab),s.tab==="diff"&&s.diffFile&&s.diffFile.trim().length>0&&e.set(Os.FILE,s.diffFile),e}function Nv(s,e){const n=typeof window<"u"?window.location.pathname:"/",a=s.toString();return a?`${n}?${a}`:n}function kv(s){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Xc(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 Ul(s,e={}){if(!(typeof window>"u")&&!Sv()&&!(!e.force&&kv(s)))try{const n=Xc(s),a=Nv(n);e.replace?window.history.replaceState({...window.history.state,route:s},"",a):window.history.pushState({route:s},"",a)}catch{}}function Sv(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function Cv(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function Zj(){const s=o.useMemo(()=>Cv(),[]),e=o.useRef(!1),n=o.useRef(!1),a=vs(p=>p.setCurrentSession),r=Fe(p=>p.setActiveMainTab),i=Fe(p=>p.setSettingsDialogOpen),l=Fe(p=>p.setSettingsPage),d=Fe(p=>p.navigateToDiff),c=o.useCallback(async p=>{if(!n.current){n.current=!0;try{if(p.sessionId){const u=vs.getState().currentSessionId;if(p.sessionId!==u){const j=vs.getState().getDirectoryForSession(p.sessionId);a(p.sessionId,j)}}if(p.settingsPath){l(Di(p.settingsPath)),i(!0);return}Fe.getState().isSettingsDialogOpen&&i(!1),p.tab&&r(p.tab),p.diffFile&&(p.tab==="diff"||!p.tab)&&d(p.diffFile)}finally{n.current=!1}}},[a,r,i,l,d]),f=o.useCallback(()=>{const p=vs.getState(),u=Fe.getState();return{sessionId:p.currentSessionId,tab:u.activeMainTab,isSettingsOpen:u.isSettingsDialogOpen,settingsPath:u.settingsPage,diffFile:u.pendingDiffFile}},[]),m=o.useCallback((p={})=>{if(s||n.current)return;const u=f();Ul(u,p)},[s,f]);o.useEffect(()=>{if(e.current||(e.current=!0,!zl()))return;const p=Ol();(async()=>(await c(p),s||Ul({...f(),sessionId:p.sessionId??vs.getState().currentSessionId,tab:p.tab??Fe.getState().activeMainTab,settingsPath:p.settingsPath??Fe.getState().settingsPage,diffFile:p.diffFile??Fe.getState().pendingDiffFile},{replace:!0,force:!0})))()},[c,f,s]),o.useEffect(()=>{if(s)return;let p=vs.getState().currentSessionId;return vs.subscribe(j=>{const g=j.currentSessionId;g===p||n.current||(p=g,m())})},[s,m]),o.useEffect(()=>{if(s)return;let p=Fe.getState().activeMainTab,u=Fe.getState().isSettingsDialogOpen,j=Fe.getState().settingsPage,g=Fe.getState().pendingDiffFile;return Fe.subscribe(x=>{if(n.current)return;const A=x.activeMainTab!==p,S=x.isSettingsDialogOpen!==u,C=x.settingsPage!==j,R=x.pendingDiffFile!==g&&x.activeMainTab==="diff";p=x.activeMainTab,u=x.isSettingsDialogOpen,j=x.settingsPage,g=x.pendingDiffFile,(A||S||C||R)&&m()})},[s,m]),o.useEffect(()=>{if(typeof window>"u"||s)return;const p=()=>{const u=Ol();if(zl())c(u);else{const j=Fe.getState();j.isSettingsDialogOpen&&i(!1),j.activeMainTab!=="chat"&&r("chat")}};return window.addEventListener("popstate",p),()=>{window.removeEventListener("popstate",p)}},[c,s,r,i])}function ew(){const s=Ze.c(5),e=bc(Pv),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 d=!1,c=null;const f=Iv,m=p=>{d||(c=window.setTimeout(async()=>{const u=await n.current(),j=typeof u=="number"&&Number.isFinite(u)?f(u):36e5;m(j)},p))};return m(3e3),()=>{d=!0,c!==null&&window.clearTimeout(c)}},l=[],s[3]=i,s[4]=l):(i=s[3],l=s[4]),o.useEffect(i,l)}function Iv(s){const e=Math.round(s*1e3);return Math.max(3e5,Math.min(864e5,e))}function Pv(s){return s.checkForUpdates}const Zc={"?":{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"}},Av=Zc.M;function Dv(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 Ev(s){const e=Dv(s);return Zc[e]??Av}const Mv=o.memo(function(e){const n=Ze.c(58),{file:a,actionLabel:r,actionSymbol:i,onAction:l,onViewDiff:d,onRevert:c,isReverting:f,stats:m,rowPaddingClassName:p,indentPx:u,actionAtStart:j,showRevert:g}=e,h=u===void 0?0:u,x=j===void 0?!1:j,A=g===void 0?!0:g;let S;n[0]!==a?(S=Ev(a),n[0]=a,n[1]=S):S=n[1];const C=S,{t:R}=st(),k=C.description,y=m?.insertions??0,v=m?.deletions??0;let E;n[2]!==l||n[3]!==d?(E=ge=>{ge.key===" "?(ge.preventDefault(),l()):ge.key==="Enter"&&(ge.preventDefault(),d())},n[2]=l,n[3]=d,n[4]=E):E=n[4];const K=E;let U;n[5]!==l?(U=ge=>{ge.preventDefault(),ge.stopPropagation(),l()},n[5]=l,n[6]=U):U=n[6];const M=U;let I;n[7]!==c?(I=ge=>{ge.preventDefault(),ge.stopPropagation(),c()},n[7]=c,n[8]=I):I=n[8];const P=I;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,J=`group flex items-center gap-2 py-1.5 cursor-pointer ${p??"px-3"}`;let _;n[13]!==h?(_=h>0?{paddingLeft:`${h}px`}:void 0,n[13]=h,n[14]=_):_=n[14];const ee=x?T:null;let Q;n[15]!==C.color?(Q={color:C.color},n[15]=C.color,n[16]=Q):Q=n[16];let N;n[17]!==C.code||n[18]!==k||n[19]!==Q?(N=t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:Q,title:k,"aria-label":k,children:C.code}),n[17]=C.code,n[18]=k,n[19]=Q,n[20]=N):N=n[20];let V;n[21]!==a.path?(V=t.jsx(xm,{filePath:a.path,className:"h-3.5 w-3.5 shrink-0"}),n[21]=a.path,n[22]=V):V=n[22];let B;if(n[23]!==a.path){e:{const ge=a.path.lastIndexOf("/");if(ge===-1){let ve;n[25]===Symbol.for("react.memo_cache_sentinel")?(ve={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[25]=ve):ve=n[25],B=t.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:ve,title:a.path,children:a.path});break e}const Ne=a.path.slice(0,ge),he=a.path.slice(ge);let we;n[26]===Symbol.for("react.memo_cache_sentinel")?(we={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[26]=we):we=n[26];let ce;n[27]===Symbol.for("react.memo_cache_sentinel")?(ce=t.jsx("span",{className:"text-muted-foreground",children:"/"}),n[27]=ce):ce=n[27];const Z=t.jsx("span",{className:"text-foreground",children:he.slice(1)});let se;n[28]!==Z?(se=t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[ce,Z]}),n[28]=Z,n[29]=se):se=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:we,children:Ne}),se]})}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]!==y?(O=t.jsxs("span",{style:F,children:["+",y]}),n[31]=y,n[32]=O):O=n[32];let q,$;n[33]===Symbol.for("react.memo_cache_sentinel")?(q=t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),$={color:"var(--status-error)"},n[33]=q,n[34]=$):(q=n[33],$=n[34]);let ie;n[35]!==v?(ie=t.jsxs("span",{style:$,children:["-",v]}),n[35]=v,n[36]=ie):ie=n[36];let le;n[37]!==O||n[38]!==ie?(le=t.jsxs("span",{className:"shrink-0 typography-micro",children:[O,q,ie]}),n[37]=O,n[38]=ie,n[39]=le):le=n[39];let ne;n[40]!==a.path||n[41]!==P||n[42]!==f||n[43]!==A||n[44]!==R?(ne=A?t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx("button",{type:"button",onClick:P,disabled:f,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":R("gitView.changes.revertFileAria",{path:a.path}),children:f?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(Pt,{sideOffset:8,children:R("gitView.changes.revertFileTooltip")})]}):null,n[40]=a.path,n[41]=P,n[42]=f,n[43]=A,n[44]=R,n[45]=ne):ne=n[45];const ye=x?null:T;let ae;return n[46]!==K||n[47]!==d||n[48]!==_||n[49]!==ee||n[50]!==N||n[51]!==V||n[52]!==B||n[53]!==le||n[54]!==ne||n[55]!==ye||n[56]!==J?(ae=t.jsxs("div",{className:J,role:"button",tabIndex:0,onClick:d,onKeyDown:K,style:_,children:[ee,N,V,B,le,ne,ye]}),n[46]=K,n[47]=d,n[48]=_,n[49]=ee,n[50]=N,n[51]=V,n[52]=B,n[53]=le,n[54]=ne,n[55]=ye,n[56]=J,n[57]=ae):ae=n[57],ae}),Kl=14,ed=s=>s.replace(/\\/g,"/").replace(/^\/+/,"").trim(),Bl=(s,e)=>({id:`dir:${s}`,path:s,name:e,children:new Map,directFiles:[],files:[]}),Tv=s=>{const e=Bl("","");for(const n of s){const a=ed(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 d="";for(const c of i){d=d?`${d}/${c}`:c;const f=l.children.get(c);if(f){f.files.push(n),l=f;continue}const m=Bl(d,c);m.files.push(n),l.children.set(c,m),l=m}}l.directFiles.push(n)}return e},Rv=(s,e)=>{const n=[],a=(r,i)=>{const l=Array.from(r.children.values()).sort((c,f)=>c.path.localeCompare(f.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 d=[...r.directFiles].sort((c,f)=>c.path.localeCompare(f.path));for(const c of d)n.push({key:`file:${ed(c.path)}`,kind:"file",depth:i,file:c})};return a(s,0),n},Lv=1e3,$l=34,Yr=30,Ha="pl-0 pr-2",Xr=(s,e)=>`${s} ${e}`,tw=({groups:s,diffStats:e,revertingPaths:n,isRevertingAll:a=!1,headerBackgroundClassName:r="bg-sidebar",onVisiblePathsChange:i,onRevertAll:l,onRevertDirectory:d})=>{const{t:c}=st(),f=o.useRef(null),p=Fe(O=>O.gitChangesViewMode)==="tree",u=o.useMemo(()=>s.filter(O=>O.entries.length>0),[s]),[j,g]=o.useState(new Set),[h,x]=o.useState(new Set),[A,S]=o.useState(!1),[C,R]=o.useState(null),k=o.useMemo(()=>u.map(O=>Tv(O.entries)),[u]),y=o.useMemo(()=>{const O=[];return u.forEach((q,$)=>{Array.from(k[$]?.children.values()??[]).forEach(ie=>{O.push(Xr(q.id,ie.path))})}),O},[k,u]);o.useEffect(()=>{p&&x(O=>{const q=new Set,$=new Set(y);return O.forEach(ie=>{(ie.slice(ie.indexOf(" ")+1).includes("/")||$.has(ie))&&q.add(ie)}),y.forEach(ie=>q.add(ie)),q})},[p,y]);const v=o.useMemo(()=>{const O=[];return u.forEach((q,$)=>{if(O.push({type:"header",key:`header:${q.id}`,groupIndex:$}),!j.has(q.id)){if(p){const ie=new Set;h.forEach(ne=>{ne.startsWith(`${q.id} `)&&ie.add(ne.slice(q.id.length+1))}),Rv(k[$],ie).forEach(ne=>{ne.kind==="file"?O.push({type:"file",key:`${q.id}:${ne.key}`,groupIndex:$,file:ne.file,depth:ne.depth}):O.push({type:"directory",key:`${q.id}:${ne.key}`,groupIndex:$,directory:ne.directory,depth:ne.depth})});return}q.entries.forEach(ie=>{O.push({type:"file",key:`${q.id}:file:${ie.path}`,groupIndex:$,file:ie,depth:0})})}}),l&&u.length>0&&O.push({type:"revert-all",key:"revert-all"}),O},[j,h,p,l,k,u]),E=v.length,K=E>=Lv,U=Yd({count:E,enabled:K,getScrollElement:()=>f.current,estimateSize:()=>$l,overscan:12,getItemKey:O=>v[O]?.key??O}),M=U.getVirtualItems(),I=o.useMemo(()=>{if(!K)return 0;const O=f.current?.scrollTop??0;return M.find($=>$.end>O)?.index??0},[K,M,f]);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 $ of v)if($.type==="file"&&(q.push($.file.path),q.length>=Yr))break;i(q);return}i(v.slice(I,I+Math.ceil((f.current?.clientHeight??0)/$l)+Yr).map(q=>O(q)).filter(q=>!!q).slice(0,Yr))},[i,E,v,K,I]);const P=o.useCallback(O=>{g(q=>{const $=new Set(q);return $.has(O)?$.delete(O):$.add(O),$})},[]),z=o.useCallback((O,q)=>{x($=>{const ie=new Set($),le=Xr(O,q);return ie.has(le)?ie.delete(le):ie.add(le),ie})},[]),T=o.useMemo(()=>{const O=new Set;return u.forEach(q=>q.entries.forEach($=>O.add($.path))),Array.from(O)},[u]),J=T.length,_=C?a||C.paths.some(O=>n.has(O)):!1,ee=o.useCallback(async()=>{!l||a||T.length===0||(await l(T),S(!1))},[T,a,l]),Q=o.useCallback(async()=>{!d||!C||_||(await d(C.paths),R(null))},[_,d,C]),N=o.useCallback((O,q)=>{const $=j.has(O.id),ie=O.entries.length;return t.jsxs("div",{className:oe("sticky top-0 z-10 flex items-center gap-2 py-2",r,Ha,!q&&"mt-1 border-t border-border/40"),children:[t.jsx("button",{type:"button",onClick:()=>O.onActionAll(O.entries.map(le=>le.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:()=>P(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":!$,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:oe("size-3.5 shrink-0 text-muted-foreground transition-transform",$&&"-rotate-90")})]})]})},[j,r,P]),V=o.useCallback((O,q,$)=>{const ie=h.has(Xr(O.id,q.path)),le=q.files.map(ye=>ye.path),ne=a||le.some(ye=>n.has(ye));return t.jsxs("div",{className:oe("group flex items-center gap-2 py-1.5",Ha),style:{paddingLeft:`${$*Kl}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&&d?t.jsx("button",{type:"button",onClick:()=>R({path:q.path,paths:le,count:le.length}),disabled:ne,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:ne?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(ye=>ye.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})]})},[h,a,d,n,c,z]),B=o.useCallback((O,q)=>{if(O.type==="revert-all")return t.jsx("div",{className:oe("flex justify-end py-2",Ha),children:t.jsxs(G,{variant:"ghost",size:"sm",onClick:()=>S(!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 $=u[O.groupIndex];if(!$)return null;if(O.type==="header")return N($,q);if(O.type==="directory")return V($,O.directory,O.depth);const ie=O.file;return t.jsx(Mv,{file:ie,actionLabel:$.getActionLabel(ie.path),actionSymbol:$.actionSymbol,onAction:()=>$.onActionFile(ie.path),stats:e?.[ie.path],onViewDiff:()=>$.onViewDiff(ie.path),onRevert:()=>$.onRevertFile(ie.path),isReverting:n.has(ie.path)||a,rowPaddingClassName:Ha,indentPx:O.depth*Kl,actionAtStart:!p,showRevert:$.showRevertActions!==!1})},[e,a,p,V,N,n,c,u]),F=o.useCallback(O=>{const q=v[O],$=v[O-1];return!q||!$||q.type!=="file"&&q.type!=="directory"||$.type!=="file"&&$.type!=="directory"?!1:$.groupIndex===q.groupIndex},[v]);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(ym,{ref:f,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=v[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:oe(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:v.map((O,q)=>t.jsx("div",{className:oe("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(bm,{containerRef:f,disableHorizontal:!0})]}),t.jsx(Lt,{open:A,onOpenChange:O=>{!a&&!O&&S(!1)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:c("gitView.changes.revertAllDialogTitle")}),t.jsx(_t,{children:J===1?c("gitView.changes.revertAllDescriptionSingle",{count:J}):c("gitView.changes.revertAllDescriptionPlural",{count:J})})]}),t.jsxs(Jt,{children:[t.jsx(G,{variant:"outline",size:"sm",onClick:()=>S(!1),disabled:a,children:c("gitView.common.cancel")}),t.jsx(G,{variant:"destructive",size:"sm",onClick:()=>{ee()},disabled:a,children:c(a?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})}),t.jsx(Lt,{open:!!C,onOpenChange:O=>{!_&&!O&&R(null)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(Ut,{children:c("gitView.changes.revertDirectoryDialogTitle")}),t.jsx(_t,{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(Jt,{children:[t.jsx(G,{variant:"outline",size:"sm",onClick:()=>R(null),disabled:_,children:c("gitView.common.cancel")}),t.jsx(G,{variant:"destructive",size:"sm",onClick:()=>{Q()},disabled:_||!C,children:c(_?"gitView.changes.reverting":"gitView.changes.revertDirectory")})]})]})})]})},Zr=38,Wa=200,Fv=s=>{const e=Ze.c(20),{value:n,onChange:a,placeholder:r,disabled:i,hasTouchInput:l,isMobile:d}=s,c=i===void 0?!1:i,f=l===void 0?!1:l,m=d===void 0?!1:d,{t:p}=st(),u=o.useRef(null),j=Fe(Ov);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{const K=u.current;if(!K)return;const U=document.activeElement===K,M=()=>{K.style.height=`${Zr}px`;const P=K.scrollHeight,z=Math.min(Math.max(P,Zr),Wa);K.style.height=`${z}px`,K.style.overflowY=P>Wa?"auto":"hidden",P>Wa&&!U&&(K.scrollTop=K.scrollHeight)};M();const I=window.requestAnimationFrame(M);return()=>{window.cancelAnimationFrame(I)}},e[0]=g):g=e[0];let h;e[1]!==n?(h=[n],e[1]=n,e[2]=h):h=e[2],o.useLayoutEffect(g,h);let x;e[3]!==a?(x=K=>a(K.target.value),e[3]=a,e[4]=x):x=e[4];let A;e[5]!==r||e[6]!==p?(A=r??p("gitView.commit.messagePlaceholder"),e[5]=r,e[6]=p,e[7]=A):A=e[7];const S=f?"on":"off",C=f?"sentences":"off",R=m||j,k=c&&"opacity-50";let y;e[8]!==k?(y=oe("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]=y):y=e[9];let v;e[10]===Symbol.for("react.memo_cache_sentinel")?(v={minHeight:Zr,maxHeight:Wa},e[10]=v):v=e[10];let E;return e[11]!==c||e[12]!==R||e[13]!==y||e[14]!==x||e[15]!==A||e[16]!==S||e[17]!==C||e[18]!==n?(E=t.jsx("textarea",{ref:u,value:n,onChange:x,placeholder:A,rows:1,disabled:c,autoCorrect:S,autoCapitalize:C,spellCheck:R,className:y,style:v}),e[11]=c,e[12]=R,e[13]=y,e[14]=x,e[15]=A,e[16]=S,e[17]=C,e[18]=n,e[19]=E):E=e[19],E};function Ov(s){return s.inputSpellcheckEnabled}const zv=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 d;e[3]!==r?(d=r("gitView.commit.aiHighlights.title"),e[3]=r,e[4]=d):d=e[4];let c;e[5]!==d?(c=t.jsx("p",{className:"typography-micro text-muted-foreground",children:d}),e[5]=d,e[6]=c):c=e[6];let f;e[7]!==r?(f=r("gitView.commit.aiHighlights.insertAria"),e[7]=r,e[8]=f):f=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 p;e[10]!==l||e[11]!==f?(p=t.jsx(It,{asChild:!0,children:t.jsx(G,{variant:"ghost",size:"icon",className:"size-6",onClick:l,"aria-label":f,children:m})}),e[10]=l,e[11]=f,e[12]=p):p=e[12];let u;e[13]!==r?(u=r("gitView.commit.aiHighlights.insertTooltip"),e[13]=r,e[14]=u):u=e[14];let j;e[15]!==u?(j=t.jsx(Pt,{sideOffset:8,children:u}),e[15]=u,e[16]=j):j=e[16];let g;e[17]!==p||e[18]!==j?(g=t.jsxs(Ct,{children:[p,j]}),e[17]=p,e[18]=j,e[19]=g):g=e[19];let h;e[20]!==c||e[21]!==g?(h=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c,g]}),e[20]=c,e[21]=g,e[22]=h):h=e[22];let x;e[23]!==n?(x=n.map(Uv),e[23]=n,e[24]=x):x=e[24];let A;e[25]!==x?(A=t.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=A):A=e[26];let S;return e[27]!==h||e[28]!==A?(S=t.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[h,A]}),e[27]=h,e[28]=A,e[29]=S):S=e[29],S};function Uv(s,e){return t.jsx("li",{className:"typography-meta text-foreground",children:s},`${s}-${e}`)}const sw=s=>{const e=Ze.c(75),{stagedCount:n,commitMessage:a,onCommitMessageChange:r,generatedHighlights:i,onInsertHighlights:l,onGenerateMessage:d,isGeneratingMessage:c,onCommit:f,onCommitAndPush:m,commitAction:p,hasPendingIndexMutation:u,gitmojiEnabled:j,onOpenGitmojiPicker:g}=s,h=u===void 0?!1:u,{t:x}=st(),A=n>0;let S;e[0]!==p||e[1]!==a||e[2]!==h||e[3]!==A?(S=a.trim()&&A&&p===null&&!h,e[0]=p,e[1]=a,e[2]=h,e[3]=A,e[4]=S):S=e[4];const C=S,{isMobile:R,hasTouchInput:k}=Ms();let y;e[5]!==x?(y=x("gitView.commit.title"),e[5]=x,e[6]=y):y=e[6];let v;e[7]!==y?(v=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:y}),e[7]=y,e[8]=v):v=e[8];let E;e[9]!==A||e[10]!==x?(E=A?null:t.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:x("gitView.commit.stageFilesHint")}),e[9]=A,e[10]=x,e[11]=E):E=e[11];let K;e[12]!==v||e[13]!==E?(K=t.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[v,E]}),e[12]=v,e[13]=E,e[14]=K):K=e[14];let U;e[15]!==i||e[16]!==l?(U=t.jsx(zv,{highlights:i,onInsert:l}),e[15]=i,e[16]=l,e[17]=U):U=e[17];let M;e[18]!==x?(M=x("gitView.commit.messagePlaceholder"),e[18]=x,e[19]=M):M=e[19];const I=p!==null;let P;e[20]!==a||e[21]!==k||e[22]!==R||e[23]!==r||e[24]!==M||e[25]!==I?(P=t.jsx(Fv,{value:a,onChange:r,placeholder:M,disabled:I,hasTouchInput:k,isMobile:R}),e[20]=a,e[21]=k,e[22]=R,e[23]=r,e[24]=M,e[25]=I,e[26]=P):P=e[26];let z;e[27]!==j||e[28]!==g||e[29]!==x?(z=j&&t.jsxs(G,{variant:"outline",size:"sm",onClick:g,className:"w-fit",type:"button",children:[t.jsx(D,{name:"emotion-happy",className:"size-4"}),x("gitView.commit.addGitmoji")]}),e[27]=j,e[28]=g,e[29]=x,e[30]=z):z=e[30];const T=c||p!==null||h||n===0;let J;e[31]!==x?(J=x("gitView.commit.generateAria"),e[31]=x,e[32]=J):J=e[32];let _;e[33]!==c?(_=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]=_):_=e[34];let ee;e[35]!==x?(ee=x("gitView.commit.generate"),e[35]=x,e[36]=ee):ee=e[36];let Q;e[37]!==ee?(Q=t.jsx("span",{className:"commit-actions__label",children:ee}),e[37]=ee,e[38]=Q):Q=e[38];let N;e[39]!==d||e[40]!==T||e[41]!==J||e[42]!==_||e[43]!==Q?(N=t.jsxs(G,{variant:"outline",size:"sm",onClick:d,disabled:T,type:"button","aria-label":J,className:"commit-actions__btn",children:[_,Q]}),e[39]=d,e[40]=T,e[41]=J,e[42]=_,e[43]=Q,e[44]=N):N=e[44];let V;e[45]===Symbol.for("react.memo_cache_sentinel")?(V=t.jsx("div",{className:"flex-1"}),e[45]=V):V=e[45];const B=!C||c;let F;e[46]!==x?(F=x("gitView.commit.commitAria"),e[46]=x,e[47]=F):F=e[47];let O;e[48]!==p||e[49]!==x?(O=p==="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:x("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:x("gitView.commit.commit")})]}),e[48]=p,e[49]=x,e[50]=O):O=e[50];let q;e[51]!==f||e[52]!==B||e[53]!==F||e[54]!==O?(q=t.jsx(G,{size:"sm",variant:"outline",onClick:f,disabled:B,className:"commit-actions__btn whitespace-nowrap","aria-label":F,children:O}),e[51]=f,e[52]=B,e[53]=F,e[54]=O,e[55]=q):q=e[55];let $;e[56]!==C||e[57]!==p||e[58]!==c||e[59]!==R||e[60]!==m||e[61]!==x?($=R?t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(G,{variant:"default",size:"sm",onClick:()=>m(),disabled:!C||c,className:"h-7 w-7 p-0","aria-label":x("gitView.commit.pushAria"),children:p==="commitAndPush"?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(D,{name:"arrow-up",className:"size-3.5"})})}),t.jsx(Pt,{side:"top",children:t.jsx("p",{children:x("gitView.commit.push")})})]}):t.jsx(G,{size:"sm",variant:"default",onClick:()=>m(),disabled:!C||c,className:"commit-actions__btn","aria-label":x("gitView.commit.pushAria"),children:p==="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:x("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:x("gitView.commit.push")})]})}),e[56]=C,e[57]=p,e[58]=c,e[59]=R,e[60]=m,e[61]=x,e[62]=$):$=e[62];let ie;e[63]!==N||e[64]!==q||e[65]!==$?(ie=t.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[N,V,q,$]}),e[63]=N,e[64]=q,e[65]=$,e[66]=ie):ie=e[66];let le;e[67]!==P||e[68]!==z||e[69]!==ie||e[70]!==U?(le=t.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[U,P,z,ie]}),e[67]=P,e[68]=z,e[69]=ie,e[70]=U,e[71]=le):le=e[71];let ne;return e[72]!==le||e[73]!==K?(ne=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[K,le]}),e[72]=le,e[73]=K,e[74]=ne):ne=e[74],ne},Kv=s=>{const e=Ze.c(41),{syncAction:n,remotes:a,onFetch:r,onSync:i,onRemoveRemote:l,disabled:d,removingRemoteName:c,aheadCount:f,behindCount:m,trackingRemoteName:p,hasUncommittedChanges:u}=s,j=a===void 0?[]:a,g=c===void 0?null:c,h=f===void 0?0:f,x=m===void 0?0:m,A=u===void 0?!1:u,{t:S}=st(),C=o.useRef(!1),R=!!g,k=j.find(se=>se.name===p)??j[0],y=x>0&&A,v=d||n!==null||R||!k||y,E=d||n!==null||R||j.length===0,K=h>0||x>0;let U;e[0]!==S?(U=S("gitView.sync.sync"),e[0]=S,e[1]=U):U=e[1];const M=x>0?`↓${x}`:null,I=h>0?`↑${h}`:null;let P;e[2]!==U||e[3]!==M||e[4]!==I?(P=[U,M,I].filter(Boolean),e[2]=U,e[3]=M,e[4]=I,e[5]=P):P=e[5];const z=P.join(" "),T=y?S("gitView.sync.commitOrStashTooltip"):k?K?S("gitView.sync.syncChangesTooltip",{ahead:h,behind:x}):S("gitView.sync.syncChanges"):S("gitView.sync.noRemoteTooltip"),J=()=>{k&&i(k)},_="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 ee;e[6]===Symbol.for("react.memo_cache_sentinel")?(ee=oe("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]=ee):ee=e[6];let Q;e[7]!==S?(Q=S("gitView.sync.syncChanges"),e[7]=S,e[8]=Q):Q=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 V;e[11]!==z?(V=t.jsx("span",{className:"whitespace-nowrap tabular-nums",children:z}),e[11]=z,e[12]=V):V=e[12];let B;e[13]!==J||e[14]!==v||e[15]!==Q||e[16]!==N||e[17]!==V?(B=t.jsx(It,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:J,disabled:v,className:ee,"aria-label":Q,children:[N,V]})}),e[13]=J,e[14]=v,e[15]=Q,e[16]=N,e[17]=V,e[18]=B):B=e[18];let F;e[19]!==T?(F=t.jsx(Pt,{sideOffset:8,children:T}),e[19]=T,e[20]=F):F=e[20];let O;e[21]!==B||e[22]!==F?(O=t.jsxs(Ct,{children:[B,F]}),e[21]=B,e[22]=F,e[23]=O):O=e[23];const q=gs;let $;e[24]===Symbol.for("react.memo_cache_sentinel")?($=oe("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]=$):$=e[24];let ie;e[25]!==S?(ie=S("gitView.sync.moreActionsAria"),e[25]=S,e[26]=ie):ie=e[26];let le;e[27]===Symbol.for("react.memo_cache_sentinel")?(le=t.jsx(D,{name:"arrow-down-s",className:"size-4"}),e[27]=le):le=e[27];let ne;e[28]!==E||e[29]!==ie?(ne=t.jsx(ms,{asChild:!0,children:t.jsx("button",{type:"button",className:$,disabled:E,"aria-label":ie,children:le})}),e[28]=E,e[29]=ie,e[30]=ne):ne=e[30];const ye=ps,ae="start",ge=-40,Ne="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",he=j.map(se=>t.jsx(Ss,{onSelect:ve=>{if(C.current){ve.preventDefault(),C.current=!1;return}r(se)},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:S("gitView.sync.fetchFromRemote",{name:se.name})}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:se.fetchUrl})]})}),l&&se.name!==p?t.jsx(G,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||R,onPointerDown:ve=>{C.current=!0,ve.preventDefault(),ve.stopPropagation()},onClick:ve=>{C.current=!0,ve.preventDefault(),ve.stopPropagation(),l(se)},"aria-label":S("gitView.header.removeRemoteAria",{name:se.name}),title:S("gitView.header.removeRemoteTitle",{name:se.name}),children:g===se.name?t.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(D,{name:"close",className:"size-3.5"})}):null]})},se.name));let we;e[31]!==ye||e[32]!==he?(we=t.jsx(ye,{align:ae,alignOffset:ge,className:Ne,children:he}),e[31]=ye,e[32]=he,e[33]=we):we=e[33];let ce;e[34]!==q||e[35]!==ne||e[36]!==we?(ce=t.jsxs(q,{children:[ne,we]}),e[34]=q,e[35]=ne,e[36]=we,e[37]=ce):ce=e[37];let Z;return e[38]!==O||e[39]!==ce?(Z=t.jsxs("div",{className:_,children:[O,ce]}),e[38]=O,e[39]=ce,e[40]=Z):Z=e[40],Z};function Bv(s){const e=Ze.c(85),{draft:n,onEdit:a,onDelete:r,className:i,maxWidth:l}=s,{t:d}=st(),f=ur()?.currentTheme,[m,p]=fe.useState(!1),[u,j]=fe.useState(!1),g=typeof n.text=="string"?n.text:"";let h;e[0]!==g?(h=g.length>150||g.split(`
30
+ `).length>3,e[0]=g,e[1]=h):h=e[1];const x=h;let A;e[2]!==i?(A=oe("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]=A):A=e[3];const S=f?.colors?.surface?.elevated,C=f?.colors?.interactive?.border,R=l?`${Math.max(200,Math.floor(l))}px`:void 0;let k;e[4]!==S||e[5]!==C||e[6]!==R?(k={backgroundColor:S,borderColor:C,maxWidth:R},e[4]=S,e[5]=C,e[6]=R,e[7]=k):k=e[7];let y;e[8]===Symbol.for("react.memo_cache_sentinel")?(y=H=>{H.preventDefault(),j(!0)},e[8]=y):y=e[8];let v;e[9]!==A||e[10]!==k?(v=t.jsx("div",{className:A,style:k,"data-comment-card":"true",onContextMenu:y}),e[9]=A,e[10]=k,e[11]=v):v=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]!==d?(U=d("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[15]=n.endLine,e[16]=n.startLine,e[17]=d,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 I;e[21]!==n.side?(I=n.side&&t.jsxs("span",{children:["(",n.side,")"]}),e[21]=n.side,e[22]=I):I=e[22];let P;e[23]!==M||e[24]!==I||e[25]!==E?(P=t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[E,K,M,I]}),e[23]=M,e[24]=I,e[25]=E,e[26]=P):P=e[26];const z=m||!x,T=!m&&x&&"line-clamp-3";let J;e[27]!==T?(J=oe("text-sm whitespace-pre-wrap break-words leading-relaxed",T),e[27]=T,e[28]=J):J=e[28];let _;e[29]!==g||e[30]!==J?(_=t.jsx("div",{className:J,children:g}),e[29]=g,e[30]=J,e[31]=_):_=e[31];let ee;e[32]!==x||e[33]!==m||e[34]!==d?(ee=x&&t.jsx(Tn,{asChild:!0,children:t.jsx(G,{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"}),d("inlineComment.actions.showLess")]}):t.jsxs(t.Fragment,{children:[t.jsx(D,{name:"arrow-down-s",className:"size-3 mr-1"}),d("inlineComment.actions.showMore")]})})}),e[32]=x,e[33]=m,e[34]=d,e[35]=ee):ee=e[35];let Q;e[36]===Symbol.for("react.memo_cache_sentinel")?(Q=t.jsx(Rn,{}),e[36]=Q):Q=e[36];let N;e[37]!==z||e[38]!==_||e[39]!==ee?(N=t.jsxs(Mn,{open:z,onOpenChange:p,children:[_,ee,Q]}),e[37]=z,e[38]=_,e[39]=ee,e[40]=N):N=e[40];let V;e[41]!==P||e[42]!==N?(V=t.jsxs("div",{className:"flex-1 min-w-0",children:[P,N]}),e[41]=P,e[42]=N,e[43]=V):V=e[43];let B;e[44]===Symbol.for("react.memo_cache_sentinel")?(B=t.jsx(ms,{asChild:!0,children:t.jsx(G,{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]!==d?(O=d("inlineComment.actions.editComment"),e[46]=d,e[47]=O):O=e[47];let q;e[48]!==a||e[49]!==O?(q=t.jsxs(Ss,{onClick:a,children:[F,O]}),e[48]=a,e[49]=O,e[50]=q):q=e[50];let $;e[51]===Symbol.for("react.memo_cache_sentinel")?($=t.jsx(D,{name:"delete-bin",className:"size-4 mr-2"}),e[51]=$):$=e[51];let ie;e[52]!==d?(ie=d("inlineComment.actions.deleteComment"),e[52]=d,e[53]=ie):ie=e[53];let le;e[54]!==r||e[55]!==ie?(le=t.jsxs(Ss,{onClick:r,className:"text-destructive",children:[$,ie]}),e[54]=r,e[55]=ie,e[56]=le):le=e[56];let ne;e[57]!==q||e[58]!==le?(ne=t.jsxs(gs,{children:[B,t.jsxs(ps,{align:"end",children:[q,le]})]}),e[57]=q,e[58]=le,e[59]=ne):ne=e[59];let ye;e[60]!==V||e[61]!==ne?(ye=t.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[V,ne]}),e[60]=V,e[61]=ne,e[62]=ye):ye=e[62];let ae;e[63]!==ye||e[64]!==v?(ae=t.jsx(bn,{render:v,children:ye}),e[63]=ye,e[64]=v,e[65]=ae):ae=e[65];let ge;e[66]===Symbol.for("react.memo_cache_sentinel")?(ge=t.jsx(D,{name:"edit",className:"size-4 mr-2"}),e[66]=ge):ge=e[66];let Ne;e[67]!==d?(Ne=d("inlineComment.actions.editComment"),e[67]=d,e[68]=Ne):Ne=e[68];let he;e[69]!==a||e[70]!==Ne?(he=t.jsxs(ln,{onClick:a,children:[ge,Ne]}),e[69]=a,e[70]=Ne,e[71]=he):he=e[71];let we;e[72]===Symbol.for("react.memo_cache_sentinel")?(we=t.jsx(D,{name:"delete-bin",className:"size-4 mr-2"}),e[72]=we):we=e[72];let ce;e[73]!==d?(ce=d("inlineComment.actions.deleteComment"),e[73]=d,e[74]=ce):ce=e[74];let Z;e[75]!==r||e[76]!==ce?(Z=t.jsxs(ln,{onClick:r,className:"text-destructive focus:text-destructive",children:[we,ce]}),e[75]=r,e[76]=ce,e[77]=Z):Z=e[77];let se;e[78]!==he||e[79]!==Z?(se=t.jsxs(vn,{children:[he,Z]}),e[78]=he,e[79]=Z,e[80]=se):se=e[80];let ve;return e[81]!==u||e[82]!==ae||e[83]!==se?(ve=t.jsxs(yn,{open:u,onOpenChange:j,children:[ae,se]}),e[81]=u,e[82]=ae,e[83]=se,e[84]=ve):ve=e[84],ve}function Vl(s){const e=Ze.c(62),{initialText:n,onTextChange:a,onSave:r,onCancel:i,fileLabel:l,lineRange:d,isEditing:c,className:f,maxWidth:m}=s,p=n===void 0?"":n,u=c===void 0?!1:c,{t:j}=st(),h=ur()?.currentTheme,{isMobile:x}=Ms(),[A,S]=o.useState(p),C=fe.useRef(null);let R;e[0]!==a?(R=re=>{S(re),a?.(re)},e[0]=a,e[1]=R):R=e[1];const k=R,y=fe.useRef(d);let v,E;e[2]!==d?(v=()=>{d&&(y.current=d)},E=[d],e[2]=d,e[3]=v,e[4]=E):(v=e[3],E=e[4]),fe.useEffect(v,E);const K=Gv,U=K(d);let M,I;e[5]!==x?(M=()=>{const re=C.current;if(!re)return;const pe=re.closest(".overlay-scrollbar-container"),Me=pe?.scrollTop??window.scrollY,Se=pe?.scrollLeft??window.scrollX;if(x){re.scrollIntoView({behavior:"auto",block:"nearest"});try{re.focus({preventScroll:!0})}catch{re.focus()}return}try{re.focus({preventScroll:!0})}catch{re.focus()}const Ae=re.value.length;try{re.setSelectionRange(Ae,Ae)}catch{}requestAnimationFrame(()=>{pe?(pe.scrollTop=Me,pe.scrollLeft=Se):window.scrollTo({top:Me,left:Se})})},I=[x],e[5]=x,e[6]=M,e[7]=I):(M=e[6],I=e[7]),fe.useEffect(M,I);let P;e[8]!==i||e[9]!==r||e[10]!==A?(P=re=>{(re.metaKey||re.ctrlKey)&&re.key==="Enter"?(re.preventDefault(),A.trim()&&r(A,K(y.current))):re.key==="Escape"&&(re.preventDefault(),i())},e[8]=i,e[9]=r,e[10]=A,e[11]=P):P=e[11];const z=P;let T;e[12]!==r||e[13]!==A?(T=re=>{re.stopPropagation(),A.trim()&&r(A,K(y.current))},e[12]=r,e[13]=A,e[14]=T):T=e[14];const J=T;let _;e[15]!==f?(_=oe("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",f),e[15]=f,e[16]=_):_=e[16];const ee=h?.colors?.surface?.elevated,Q=h?.colors?.interactive?.border,N=m?`${Math.max(200,Math.floor(m))}px`:void 0;let V;e[17]!==ee||e[18]!==Q||e[19]!==N?(V={backgroundColor:ee,borderColor:Q,maxWidth:N},e[17]=ee,e[18]=Q,e[19]=N,e[20]=V):V=e[20];const B="true",F=qv,O=Wv,q="p-3",$=(l||d)&&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&&d&&t.jsx("span",{children:"•"}),U&&t.jsx("span",{children:j("inlineComment.range.lines",{start:U.start,end:U.end})})]});let ie;e[21]!==k?(ie=re=>k(re.target.value),e[21]=k,e[22]=ie):ie=e[22];let le;e[23]!==x||e[24]!==j?(le=j(x?"inlineComment.input.placeholderShort":"inlineComment.input.placeholder"),e[23]=x,e[24]=j,e[25]=le):le=e[25];let ne;e[26]!==z||e[27]!==ie||e[28]!==le||e[29]!==A?(ne=t.jsx(hs,{simple:!0,ref:C,value:A,onChange:ie,onKeyDown:z,placeholder:le,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]=le,e[29]=A,e[30]=ne):ne=e[30];let ye;e[31]!==j?(ye=j("inlineComment.actions.cancel"),e[31]=j,e[32]=ye):ye=e[32];let ae;e[33]!==i||e[34]!==ye?(ae=t.jsx(G,{variant:"ghost",size:"sm",onClick:i,onPointerDown:Hv,onTouchStart:_v,className:"h-8 text-muted-foreground hover:text-foreground",children:ye}),e[33]=i,e[34]=ye,e[35]=ae):ae=e[35];let ge;e[36]!==A?(ge=A.trim(),e[36]=A,e[37]=ge):ge=e[37];const Ne=!ge,he=h?.colors?.status?.success,we=h?.colors?.status?.successForeground;let ce;e[38]!==he||e[39]!==we?(ce={backgroundColor:he,color:we},e[38]=he,e[39]=we,e[40]=ce):ce=e[40];let Z;e[41]!==u||e[42]!==j?(Z=j(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[41]=u,e[42]=j,e[43]=Z):Z=e[43];let se;e[44]!==J||e[45]!==Ne||e[46]!==ce||e[47]!==Z?(se=t.jsx(G,{size:"sm",onClick:J,onPointerDown:Vv,onTouchStart:$v,disabled:Ne,className:"h-8 min-w-[80px]",style:ce,children:Z}),e[44]=J,e[45]=Ne,e[46]=ce,e[47]=Z,e[48]=se):se=e[48];let ve;e[49]!==ae||e[50]!==se?(ve=t.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[ae,se]}),e[49]=ae,e[50]=se,e[51]=ve):ve=e[51];let H;e[52]!==$||e[53]!==ne||e[54]!==ve?(H=t.jsxs("div",{className:q,children:[$,ne,ve]}),e[52]=$,e[53]=ne,e[54]=ve,e[55]=H):H=e[55];let te;return e[56]!==_||e[57]!==V||e[58]!==F||e[59]!==O||e[60]!==H?(te=t.jsx("div",{className:_,style:V,"data-comment-input":B,onPointerDown:F,onTouchStart:O,children:H}),e[56]=_,e[57]=V,e[58]=F,e[59]=O,e[60]=H,e[61]=te):te=e[61],te}function $v(s){return s.stopPropagation()}function Vv(s){return s.stopPropagation()}function _v(s){return s.stopPropagation()}function Hv(s){return s.stopPropagation()}function Wv(s){return s.stopPropagation()}function qv(s){return s.stopPropagation()}function Gv(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 Jv=s=>{const e=Math.min(s.startLine,s.endLine),n=Math.max(s.startLine,s.endLine);return{...s,startLine:e,endLine:n}},_l=s=>{const e=Math.min(s.start,s.end),n=Math.max(s.start,s.end);return{...s,start:e,end:n}};function Qv(s){const e=Ze.c(40),{t:n}=st(),{source:a,fileLabel:r,language:i,getCodeForRange:l,toStoreRange:d,fromDraftRange:c}=s,f=vs(sj),m=vs(tj),p=Ea(ej),u=Ea(Zv),j=Ea(Xv),g=Ea(Yv),[h,x]=o.useState(null),[A,S]=o.useState(""),[C,R]=o.useState(null),k=f??(m?"draft":null);let y;e:{if(!k||!r){let B;e[0]===Symbol.for("react.memo_cache_sentinel")?(B=[],e[0]=B):B=e[0],y=B;break e}let Q;e[1]!==g||e[2]!==k?(Q=g[k]??[],e[1]=g,e[2]=k,e[3]=Q):Q=e[3];const N=Q;let V;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],V=N.filter(B),e[4]=r,e[5]=N,e[6]=a,e[7]=V}else V=e[7];y=V}const v=y;let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{x(null),S(""),R(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 I;e[13]!==c?(I=Q=>{const N=_l(c(Q));x(N),S(Q.text),R(Q.id)},e[13]=c,e[14]=I):I=e[14];const P=I;let z;e[15]!==C||e[16]!==j?(z=Q=>{j(Q.sessionKey,Q.id),C===Q.id&&K()},e[15]=C,e[16]=j,e[17]=z):z=e[17];const T=z;let J;e[18]!==p||e[19]!==C||e[20]!==r||e[21]!==l||e[22]!==i||e[23]!==h||e[24]!==k||e[25]!==a||e[26]!==n||e[27]!==d||e[28]!==u?(J=(Q,N)=>{const V=N??h,B=Q.trim();if(!V||!B||!r)return;if(!k){W.error(n("inlineComment.toast.selectSessionToSave"));return}const F=_l(V),O=Jv(d(F)),q=l(F);C?u(k,C,{fileLabel:r,startLine:O.startLine,endLine:O.endLine,side:O.side,code:q,language:i,text:B}):p({sessionKey:k,source:a,fileLabel:r,startLine:O.startLine,endLine:O.endLine,side:O.side,code:q,language:i,text:B}),K()},e[18]=p,e[19]=C,e[20]=r,e[21]=l,e[22]=i,e[23]=h,e[24]=k,e[25]=a,e[26]=n,e[27]=d,e[28]=u,e[29]=J):J=e[29];const _=J;let ee;return e[30]!==A||e[31]!==T||e[32]!==v||e[33]!==C||e[34]!==c||e[35]!==_||e[36]!==h||e[37]!==k||e[38]!==P?(ee={sessionKey:k,drafts:v,selection:h,setSelection:x,commentText:A,setCommentText:S,editingDraftId:C,setEditingDraftId:R,reset:K,cancel:M,startEdit:P,deleteDraft:T,saveComment:_,fromDraftRange:c},e[30]=A,e[31]=T,e[32]=v,e[33]=C,e[34]=c,e[35]=_,e[36]=h,e[37]=k,e[38]=P,e[39]=ee):ee=e[39],ee}function Yv(s){return s.drafts}function Xv(s){return s.removeDraft}function Zv(s){return s.updateDraft}function ej(s){return s.addDraft}function tj(s){return s.newSessionDraft?.open}function sj(s){return s.currentSessionId}const nr=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}`},nj=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)),d=i.side==="original"?"deletions":"additions";r.push({lineNumber:l,side:d,metadata:{type:i.id===n?"edit":"saved",draft:i}})}return a&&!n&&r.push({lineNumber:Math.max(a.start,a.end),side:a.side??"additions",metadata:{type:"new",selection:a}}),r};function aj(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 Hl(s){if(!(!s||s<=0))return Math.max(200,Math.floor(s))}function rj(s){const{diffRootRef:e,drafts:n,selection:a,editingDraftId:r,commentText:i,onTextChange:l,fileLabel:d,onSave:c,onCancel:f,onEdit:m,onDelete:p}=s,[u,j]=o.useState(0),[g,h]=o.useState(null),x=o.useMemo(()=>!a||r?null:nr({type:"new",selection:a}),[r,a]),A=o.useMemo(()=>{const R=n.map(k=>nr({type:k.id===r?"edit":"saved",draft:k}));return x&&R.push(x),R},[n,r,x]),S=o.useCallback(R=>{const k=e.current;if(!k)return null;const y=k.querySelector("diffs-container");if(!(y instanceof HTMLElement))return null;const v=y.querySelector(`[data-annotation-id="${R}"]`);if(v instanceof HTMLElement)return v;const E=y.shadowRoot;return E?E.querySelector(`[data-annotation-id="${R}"]`):null},[e]);o.useEffect(()=>{if(A.length===0)return;let R=!1,k=0;const y=12,v=()=>{R||A.every(K=>!!S(K))||k>=y||(k+=1,requestAnimationFrame(()=>{R||(j(K=>K+1),v())}))};return v(),()=>{R=!0}},[A,S]),o.useEffect(()=>{const R=e.current;if(!R)return;const k=()=>{const v=getComputedStyle(R),E=aj(v.getPropertyValue("--oc-context-panel-width")),K=R.getBoundingClientRect(),U=E??K.width;h(U>0?U:null)};k();const y=new ResizeObserver(()=>{k()});return y.observe(R),window.addEventListener("resize",k),()=>{y.disconnect(),window.removeEventListener("resize",k)}},[e]);const C=o.useCallback(R=>{const y=e.current?.getBoundingClientRect(),v=R.closest("[data-annotation-content]"),E=v instanceof HTMLElement?v.getBoundingClientRect():R.getBoundingClientRect(),K=[E.width];y&&K.push(y.right-E.left);const U=K.filter(M=>Number.isFinite(M)&&M>0);return U.length>0?Hl(Math.min(...U)):Hl(g)},[e,g]);return t.jsxs(t.Fragment,{children:[n.map(R=>{const k=nr({type:R.id===r?"edit":"saved",draft:R}),y=S(k);if(!y)return null;const v=C(y);return R.id===r?Ga.createPortal(t.jsx(Vl,{initialText:i,onTextChange:l,fileLabel:d,lineRange:{start:R.startLine,end:R.endLine,side:R.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:f,maxWidth:v}),y,`draft-edit-${R.id}`):Ga.createPortal(t.jsx(Bv,{draft:R,onEdit:()=>m(R),onDelete:()=>p(R),maxWidth:v}),y,`draft-card-${R.id}`)}),a&&!r&&x&&(()=>{const R=S(x);if(!R)return null;const k=C(R);return Ga.createPortal(t.jsx(Vl,{initialText:i,onTextChange:l,fileLabel:d,lineRange:a,isEditing:!1,onSave:c,onCancel:f,maxWidth:k}),R,x)})()]})}const Wl=5e5,ij=`
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
+ `,oj=`
53
+ ${ij}
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 lj(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}:${lj(e)}`}const cj=(s,e,n,a)=>{const r=a.side==="deletions",l=(n?(r?n.deletionLines:n.additionLines).join(""):r?s:e).split(`
164
+ `),d=Math.min(a.start,a.end),c=Math.max(a.start,a.end),f=Math.max(1,d),m=Math.min(l.length,c);return f>m?"":l.slice(f-1,m).join(`
165
+ `)},dj=(s,e)=>s===e?!0:!s||!e?!1:s.start===e.start&&s.end===e.end&&s.side===e.side,uj=s=>s==="auto"||s==="scroll"||s==="overlay",mj=s=>{let e=s?.parentElement??null;for(;e;){const n=window.getComputedStyle(e);if(uj(n.overflowY))return e;e=e.parentElement}return null},pj=(s,e)=>{if(!s||!e||typeof window>"u")return()=>{};const n=mj(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)}},gj=(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,d=(c=l())=>!!c?.querySelector("[data-line]");return d()?i():typeof MutationObserver<"u"?(a=new MutationObserver(()=>{const c=l();if(c){if(d(c)){i();return}a?.disconnect(),a=new MutationObserver(()=>{d(c)&&i()}),a.observe(c,{childList:!0,subtree:!0})}}),a.observe(s,{childList:!0,subtree:!0})):n=window.requestAnimationFrame(i),()=>{r=!0,a?.disconnect(),n!==null&&window.cancelAnimationFrame(n)}},qa=new WeakMap,hj={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function fj(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 xj(s){if(typeof document>"u")return null;const e=fj(s);let n=qa.get(e.key);if(!n){const r=new tu;r.setup(e.root,e.content),n={virtualizer:r,refs:0},qa.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=qa.get(e.key);r&&(r.refs-=1,!(r.refs>0)&&(r.virtualizer.cleanUp(),qa.delete(e.key)))}}}const yj=(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)}},nw=({original:s,modified:e,fileDiff:n,language:a,fileName:r,renderSideBySide:i,wrapLines:l,layout:d="fill",enableComments:c=!0})=>{const f=ur(),m=f?.currentTheme.metadata.variant==="dark",p=f?.availableThemes.find(H=>H.metadata.id===f.lightThemeId)??rr(!1),u=f?.availableThemes.find(H=>H.metadata.id===f.darkThemeId)??rr(!0),{isMobile:j}=Ms(),g=Qv({source:"diff",fileLabel:r||"unknown",language:a,getCodeForRange:H=>cj(s,e,n,H),toStoreRange:H=>({startLine:H.start,endLine:H.end,side:H.side==="deletions"?"original":"modified"}),fromDraftRange:H=>({start:H.startLine,end:H.endLine,side:H.side==="original"?"deletions":"additions"})}),{drafts:h,selection:x,setSelection:A,commentText:S,setCommentText:C,editingDraftId:R,saveComment:k,cancel:y,startEdit:v,deleteDraft:E}=g,K=fe.useRef(null),U=fe.useRef(null),M=fe.useRef(""),I=fe.useRef(!1),P=fe.useRef(null);fe.useEffect(()=>{K.current=x},[x]),fe.useEffect(()=>{U.current=R},[R]),fe.useEffect(()=>{M.current=S},[S]);const z=fe.useCallback(H=>{if(!c||I.current)return;const te=K.current;if(!(!H&&te&&M.current.trim())){if(j&&te&&H&&H.side===te.side){const re=Math.min(te.start,H.start),pe=Math.max(te.end,H.end);A({...H,start:re,end:pe})}else A(H);H&&(U.current||C(""))}},[c,j,C,A]),T=fe.useCallback(()=>{y()},[y]),J=fe.useCallback(H=>{const te=document.createElement("div");te.style.position="relative";const re=nr(H.metadata);return te.dataset.annotationId=re,te.dataset.annotationSide=H.side,te.dataset.annotationLine=String(H.lineNumber),te},[]),_=fe.useCallback((H,te)=>{k(H,te??x??void 0)},[k,x]),ee=fe.useCallback(H=>{A(H);const te=O.current;if(te)try{I.current=!0,te.setSelectedLines(H),P.current=H}catch{}finally{I.current=!1}},[A]),Q=fe.useCallback(H=>{const te=H.closest("[data-line-type]")?.getAttribute("data-line-type")??H.getAttribute("data-line-type");if(te==="change-deletion")return"deletions";if(te==="change-addition")return"additions";const re=H.getAttribute("data-column-side")??H.getAttribute("data-side")??H.closest("[data-column-side]")?.getAttribute("data-column-side");if(re==="deletions"||re==="left"||re==="original")return"deletions";if(re==="additions"||re==="right"||re==="modified")return"additions";const pe=H.closest("[data-line-type]");if(pe instanceof HTMLElement){const Me=pe.getBoundingClientRect(),Se=H.getBoundingClientRect(),Ae=Me.left+Me.width/2;return Se.left+Se.width/2<Ae?"deletions":"additions"}return"additions"},[]);ir(p),ir(u);const N=`${p.metadata.id}:${u.metadata.id}:${m?"dark":"light"}`,V=fe.useMemo(()=>{if(n){const H=n.deletionLines.reduce((re,pe)=>re+pe.length,0),te=n.additionLines.reduce((re,pe)=>re+pe.length,0);return Math.max(H,te)>Wl}return Math.max(s.length,e.length)>Wl},[n,e.length,s.length]),B=fe.useRef(null),F=fe.useRef(null),O=fe.useRef(null),q=fe.useRef(null),$=fe.useRef(null),ie=fe.useRef(null),le=fe.useRef(void 0),ne=fe.useRef(void 0),ye=fe.useRef(void 0),ae=fe.useRef(void 0),[,ge]=o.useReducer(H=>H+1,0),Ne=ci(V?"unified":i?"split":"unified"),he=fe.useMemo(()=>si(p),[p]),we=fe.useMemo(()=>si(u),[u]);o.useLayoutEffect(()=>{const H=B.current;if(!H)return;const te=H.querySelector("diffs-container");if(!te)return;const re=m?we:he,pe=(Je,ue)=>Je.colors?.[ue],Me=pe(he,"terminal.ansiGreen"),Se=pe(he,"terminal.ansiRed"),Ae=pe(he,"terminal.ansiBlue"),De=pe(we,"terminal.ansiGreen"),Pe=pe(we,"terminal.ansiRed"),Oe=pe(we,"terminal.ansiBlue");te.style.setProperty("--shiki-light",he.fg),te.style.setProperty("--shiki-light-bg",he.bg),Me&&te.style.setProperty("--shiki-light-addition-color",Me),Se&&te.style.setProperty("--shiki-light-deletion-color",Se),Ae&&te.style.setProperty("--shiki-light-modified-color",Ae),te.style.setProperty("--shiki-dark",we.fg),te.style.setProperty("--shiki-dark-bg",we.bg),De&&te.style.setProperty("--shiki-dark-addition-color",De),Pe&&te.style.setProperty("--shiki-dark-deletion-color",Pe),Oe&&te.style.setProperty("--shiki-dark-modified-color",Oe),te.style.setProperty("--diffs-bg",re.bg),te.style.setProperty("--diffs-fg",re.fg);const Te=m?De:Me,Ue=m?Pe:Se,Be=m?Oe:Ae;Te&&te.style.setProperty("--diffs-addition-color-override",Te),Ue&&te.style.setProperty("--diffs-deletion-color-override",Ue),Be&&te.style.setProperty("--diffs-modified-color-override",Be);const Ke=te.shadowRoot?.querySelector("pre");Ke&&(Ke.style.setProperty("--shiki-light",he.fg),Ke.style.setProperty("--shiki-light-bg",he.bg),Me&&Ke.style.setProperty("--shiki-light-addition-color",Me),Se&&Ke.style.setProperty("--shiki-light-deletion-color",Se),Ae&&Ke.style.setProperty("--shiki-light-modified-color",Ae),Ke.style.setProperty("--shiki-dark",we.fg),Ke.style.setProperty("--shiki-dark-bg",we.bg),De&&Ke.style.setProperty("--shiki-dark-addition-color",De),Pe&&Ke.style.setProperty("--shiki-dark-deletion-color",Pe),Oe&&Ke.style.setProperty("--shiki-dark-modified-color",Oe),Ke.style.setProperty("--diffs-bg",re.bg),Ke.style.setProperty("--diffs-fg",re.fg),Te&&Ke.style.setProperty("--diffs-addition-color-override",Te),Ue&&Ke.style.setProperty("--diffs-deletion-color-override",Ue),Be&&Ke.style.setProperty("--diffs-modified-color-override",Be))},[we,N,m,he]);const ce=fe.useMemo(()=>({theme:{dark:u.metadata.id,light:p.metadata.id},themeType:m?"dark":"light",diffStyle:i?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:V?0:1e3,maxLineLengthForHighlighting:V?1:1e3,tokenizeMaxLineLength:V?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:l?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:c,enableHoverUtility:!1,onLineSelected:c?z:void 0,unsafeCSS:oj,renderAnnotation:c?J:void 0}),[u.metadata.id,c,m,V,p.metadata.id,i,l,z,J]),Z=fe.useMemo(()=>c?nj({drafts:h,editingDraftId:R,selection:x}):[],[R,c,h,x]),se=fe.useRef(Z);if(fe.useEffect(()=>{se.current=Z},[Z]),fe.useEffect(()=>{const H=F.current;return()=>{O.current?.cleanUp(),O.current=null,q.current?.release(),q.current=null,$.current=null,ie.current=null,le.current=void 0,ne.current=void 0,ye.current=void 0,ae.current=void 0,H&&(H.innerHTML="")}},[]),fe.useEffect(()=>{if(typeof window>"u")return;const H=F.current,te=B.current;if(!H||!Ne)return;const re=pj(te,H);let pe=q.current;pe||(pe=xj(H),q.current=pe),q.current=pe;const Me=pe?.virtualizer??null,Se=n?void 0:{name:r||"",contents:s,lang:a,cacheKey:`old:${N}:${r}:${ql(s)}`},Ae=n?void 0:{name:r||"",contents:e,lang:a,cacheKey:`new:${N}:${r}:${ql(e)}`},De=n?ne.current!==n:ne.current!==void 0||!Se||!Ae||!ye.current||!ae.current||!Ki(ye.current,Se)||!Ki(ae.current,Ae),Pe=O.current,Oe=!!(Pe&&($.current!==Me||ie.current!==Ne||Me&&(le.current!==ce.hunkSeparators||De)));Oe&&(Pe?.cleanUp(),O.current=null,H.innerHTML="");let Te=O.current;const Ue=!Oe&&Pe?!Xd(Pe.options,ce):!1;if(Te?Te.setOptions(ce):(Te=pe?new Zd(ce,pe.virtualizer,hj,Ne):new eu(ce,Ne),O.current=Te,P.current=null),$.current=Me,ie.current=Ne,le.current=Me?ce.hunkSeparators:void 0,ne.current=n,ye.current=Se,ae.current=Ae,n)Te.render({fileDiff:n,forceRender:Ue,lineAnnotations:se.current,containerWrapper:H});else{if(!Se||!Ae)return;Te.render({oldFile:Se,newFile:Ae,forceRender:Ue,lineAnnotations:se.current,containerWrapper:H})}const Be=gj(H,()=>{re(),yj(Te,pe,ge)});return()=>{Be(),re()}},[N,n,r,a,e,ce,s,Ne]),fe.useEffect(()=>{const H=O.current;if(H){try{H.setLineAnnotations(Z)}catch(te){console.error("Failed to apply diff line annotations",te);try{H.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(O.current===H){try{H.rerender()}catch{}ge()}})}},[Z]),fe.useEffect(()=>{const H=O.current;if(!H||x!==null)return;const te=P.current;if(!dj(x,te))try{I.current=!0,H.setSelectedLines(x),P.current=x}catch{}finally{I.current=!1}},[x]),fe.useEffect(()=>{if(!c)return;const H=F.current;if(!H)return;let te=null,re=()=>{};const pe=()=>{const Se=H.querySelector("diffs-container")?.shadowRoot;if(!Se){te=requestAnimationFrame(pe);return}const Ae=De=>{if(!(De instanceof MouseEvent)||De.button!==0||!(De.target instanceof Element))return;const Pe=De.target.closest("[data-column-number]");if(!(Pe instanceof HTMLElement))return;const Oe=Pe.getAttribute("data-column-number"),Te=Oe?parseInt(Oe,10):NaN;if(Number.isNaN(Te))return;const Ue=Q(Pe);z({start:Te,end:Te,side:Ue}),De.preventDefault(),De.stopPropagation()};Se.addEventListener("click",Ae,!0),re=()=>{Se.removeEventListener("click",Ae,!0)}};return pe(),()=>{te!==null&&cancelAnimationFrame(te),re()}},[N,c,r,z,Q]),fe.useEffect(()=>{const H=F.current;if(!H)return;let te=null,re=null;const Me=setTimeout(()=>{const Se=H.querySelector("diffs-container");if(!(Se instanceof HTMLElement))return;const Ae=Se.shadowRoot;te=new MutationObserver(()=>{re&&cancelAnimationFrame(re),re=requestAnimationFrame(()=>{ge(),re=null})}),te.observe(Se,{childList:!0,subtree:!0}),Ae&&te.observe(Ae,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(Me),re&&cancelAnimationFrame(re),te?.disconnect()}},[N,r]),typeof window>"u")return null;const ve=c?t.jsx(rj,{diffRootRef:B,drafts:h,selection:x,editingDraftId:R,commentText:S,onTextChange:C,fileLabel:r?.split("/").pop()??"",onSave:_,onCancel:T,onEdit:H=>{ee({start:H.startLine,end:H.endLine,side:H.side==="original"?"deletions":"additions"}),v(H)},onDelete:E}):null;return d==="fill"?t.jsx("div",{className:oe("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"})})}),ve]})}):t.jsxs("div",{className:oe("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"})}),ve]})},bj=()=>{const s=Ze.c(13),[e,n]=fe.useState(!1);let a,r;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{n(rs())},r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),fe.useEffect(a,r);let i;s[2]!==e?(i=async u=>e?await ep(u):{success:!0,path:u},s[2]=e,s[3]=i):i=s[3];const l=i;let d;s[4]!==e?(d=async u=>e?await tp():{success:!0},s[4]=e,s[5]=d):d=s[5];const c=d;let f;s[6]!==e?(f=async u=>e?await sp():{success:!0},s[6]=e,s[7]=f):f=s[7];const m=f;let p;return s[8]!==e||s[9]!==l||s[10]!==c||s[11]!==m?(p={isDesktop:e,requestAccess:l,startAccessing:c,stopAccessing:m},s[8]=e,s[9]=l,s[10]=c,s[11]=m,s[12]=p):p=s[12],p},vj=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),jj=({currentBranch:s,localBranches:e,remoteBranches:n,branchInfo:a,onCheckout:r,onCreate:i,remotes:l=[],disabled:d=!1})=>{const{t:c}=st(),[f,m]=o.useState(!1),[p,u]=o.useState(""),[j,g]=o.useState(!1),[h,x]=o.useState(!1),[A,S]=o.useState(""),[C,R]=o.useState(!1),k=o.useRef(null),y=o.useCallback(_=>{_.stopPropagation()},[]),v=l.length>1,E=o.useMemo(()=>vj(A),[A]),K=o.useMemo(()=>{const _=p.toLowerCase();return _?e.filter(ee=>ee.toLowerCase().includes(_)):e},[p,e]),U=o.useMemo(()=>{const _=p.toLowerCase();return _?n.filter(ee=>ee.toLowerCase().includes(_)):n},[p,n]),M=_=>{if(_===s){m(!1);return}r(_),m(!1),u("")},I=()=>{g(!0),setTimeout(()=>k.current?.focus(),50)},P=async()=>{if(!(!E||C)){if(v){x(!0);return}R(!0);try{await i(E,l[0]),S(""),g(!1),m(!1)}finally{R(!1)}}},z=async _=>{if(!(!E||C)){R(!0);try{await i(E,_),S(""),g(!1),x(!1),m(!1)}finally{R(!1)}}},T=()=>{x(!1)},J=()=>{S(""),g(!1),x(!1)};return o.useEffect(()=>{f||(u(""),g(!1),x(!1),S(""))},[f]),t.jsxs(gs,{open:f,onOpenChange:m,children:[t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(ms,{asChild:!0,children:t.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:d,children:[t.jsx(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(Pt,{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(ai,{className:"h-full min-h-0",children:[t.jsx(ri,{placeholder:c("gitView.branch.searchPlaceholder"),value:p,onValueChange:u,onKeyDown:y}),t.jsxs(ii,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(oi,{children:c("gitView.branch.empty")}),t.jsx(en,{children:h?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(_=>t.jsxs("button",{type:"button",onClick:()=>z(_),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,_.name]}),t.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:_.pushUrl})]},_.name))})]}):j?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:A,onChange:_=>S(_.target.value),onClick:_=>_.stopPropagation(),onKeyDown:_=>{y(_),_.key==="Enter"?(_.preventDefault(),P()):_.key==="Escape"&&(_.preventDefault(),J())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),t.jsx("button",{type:"button",onClick:P,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:J,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(Ks,{onSelect:I,children:[t.jsx(D,{name:"add",className:"size-4"}),t.jsx("span",{children:c("gitView.branch.create")})]})}),t.jsx(Gn,{}),t.jsxs(en,{heading:c("gitView.branch.localBranches"),children:[K.map(_=>t.jsxs(Ks,{onSelect:()=>M(_),children:[t.jsxs("span",{className:"flex flex-1 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:_}),(a?.[_]?.ahead||a?.[_]?.behind)&&t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[a[_].ahead||0," ahead ·"," ",a[_].behind||0," behind"]})]}),s===_&&t.jsx("span",{className:"typography-micro text-primary",children:c("gitView.branch.currentBadge")})]},`local-${_}`)),K.length===0&&t.jsx(Ks,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noLocalBranches")})})]}),t.jsx(Gn,{}),t.jsxs(en,{heading:c("gitView.branch.remoteBranches"),children:[U.map(_=>t.jsx(Ks,{onSelect:()=>M(_),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:_})},`remote-${_}`)),U.length===0&&t.jsx(Ks,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noRemoteBranches")})})]})]})]})})]})},wj=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Nj=({currentBranch:s,onRename:e,showEditButton:n=!0})=>{const{t:a}=st(),[r,i]=o.useState(!1),[l,d]=o.useState(s||""),[c,f]=o.useState(!1),m=o.useRef(null),p=()=>{!s||!e||(d(s),i(!0),setTimeout(()=>m.current?.focus(),0))},u=async()=>{if(!s||!e||!l.trim())return;const h=wj(l);if(h===s){i(!1);return}f(!0);try{await e(s,h),i(!1),d("")}finally{f(!1)}},j=()=>{i(!1),d("")},g=h=>{h.key==="Enter"?(h.preventDefault(),u()):h.key==="Escape"&&(h.preventDefault(),j())};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:h=>{h.preventDefault(),u()},children:[t.jsx(D,{name:"git-branch",className:"size-4 text-primary"}),t.jsx("input",{ref:m,value:l,onChange:h=>d(h.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:g,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:j,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(G,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:p,title:a("gitView.branch.renameTitle"),children:t.jsx(D,{name:"edit",className:"size-4"})})]})]})},kj={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},Sj={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 td(s){return s&&Sj[s]||"var(--primary)"}const Gl=s=>{const e=Ze.c(8),{icon:n,className:a,colorToken:r}=s,i=kj[n??"branch"]??"user-3";let l;e[0]!==r?(l=td(r),e[0]=r,e[1]=l):l=e[1];let d;e[2]!==l?(d={color:l},e[2]=l,e[3]=d):d=e[3];let c;return e[4]!==a||e[5]!==i||e[6]!==d?(c=t.jsx(D,{name:i,className:a,style:d}),e[4]=a,e[5]=i,e[6]=d,e[7]=c):c=e[7],c},sd=s=>{const e=Ze.c(35),{activeProfile:n,identities:a,onSelect:r,isApplying:i,iconOnly:l}=s,d=l===void 0?!1:l,{t:c}=st(),f=i||a.length===0,m=n?.color;let p;e[0]!==m?(p=td(m),e[0]=m,e[1]=p):p=e[1];let u;e[2]!==p?(u={color:p},e[2]=p,e[3]=u):u=e[3];let j;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(j=i?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(Gl,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=j):j=e[7];let g;e[8]!==n?.name||e[9]!==d||e[10]!==c?(g=!d&&t.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||c("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=d,e[10]=c,e[11]=g):g=e[11];let h;e[12]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=h):h=e[12];let x;e[13]!==f||e[14]!==u||e[15]!==j||e[16]!==g?(x=t.jsx(It,{asChild:!0,children:t.jsx(ms,{asChild:!0,children:t.jsxs(G,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:u,disabled:f,children:[j,g,h]})})}),e[13]=f,e[14]=u,e[15]=j,e[16]=g,e[17]=x):x=e[17];let A;e[18]!==c?(A=c("gitView.header.identityTooltip"),e[18]=c,e[19]=A):A=e[19];let S;e[20]!==A?(S=t.jsx(Pt,{sideOffset:8,children:A}),e[20]=A,e[21]=S):S=e[21];let C;e[22]!==S||e[23]!==x?(C=t.jsxs(Ct,{children:[x,S]}),e[22]=S,e[23]=x,e[24]=C):C=e[24];let R;e[25]!==n?.id||e[26]!==a||e[27]!==r||e[28]!==c?(R=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(v=>{const E=n?.id===v.id;return t.jsx(Ss,{onSelect:()=>r(v),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(Gl,{icon:v.icon,colorToken:v.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:v.name}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:v.userEmail})]}),E?t.jsx(D,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},v.id)}),e[25]=n?.id,e[26]=a,e[27]=r,e[28]=c,e[29]=R):R=e[29];let k;e[30]!==R?(k=t.jsx(ps,{align:"end",className:"w-64",children:R}),e[30]=R,e[31]=k):k=e[31];let y;return e[32]!==C||e[33]!==k?(y=t.jsxs(gs,{children:[C,k]}),e[32]=C,e[33]=k,e[34]=y):y=e[34],y},Cj=s=>{const e=Ze.c(21),{comparison:n,trackingBranch:a,tooltipDelayMs:r}=s,i=r===void 0?1e3:r,{t:l}=st(),d=`${n.remote}/${n.branch}`,c=n.ahead===0&&n.behind===0;let f;e[0]!==l||e[1]!==d||e[2]!==a?(f=a?l("gitView.header.upstreamTooltipTracking",{target:d,tracking:a}):l("gitView.header.upstreamTooltip",{target:d}),e[0]=l,e[1]=d,e[2]=a,e[3]=f):f=e[3];const m=f;let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(D,{name:"git-branch",className:"size-3.5 shrink-0"}),e[4]=p):p=e[4];let u;e[5]!==d?(u=t.jsx("span",{className:"min-w-0 truncate text-foreground/80",children:d}),e[5]=d,e[6]=u):u=e[6];let j;e[7]!==n.ahead||e[8]!==n.behind||e[9]!==c||e[10]!==l?(j=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]=j):j=e[11];let g;e[12]!==u||e[13]!==j?(g=t.jsx(It,{asChild:!0,children:t.jsxs("div",{className:"inline-flex h-8 max-w-full items-center gap-1.5 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2 typography-micro text-muted-foreground",children:[p,u,j]})}),e[12]=u,e[13]=j,e[14]=g):g=e[14];let h;e[15]!==m?(h=t.jsx(Pt,{sideOffset:8,children:m}),e[15]=m,e[16]=h):h=e[16];let x;return e[17]!==g||e[18]!==h||e[19]!==i?(x=t.jsxs(Ct,{delayDuration:i,children:[g,h]}),e[17]=g,e[18]=h,e[19]=i,e[20]=x):x=e[20],x},aw=s=>{const e=Ze.c(54),{status:n,localBranches:a,remoteBranches:r,branchInfo:i,syncAction:l,remotes:d,onFetch:c,onSync:f,onRemoveRemote:m,removingRemoteName:p,onCheckoutBranch:u,onCreateBranch:j,onRenameBranch:g,activeIdentityProfile:h,availableIdentities:x,onSelectIdentity:A,isApplyingIdentity:S,isWorktreeMode:C,onOpenHistory:R,onOpenGraph:k,onOpenStashes:y,actionTabItems:v,activeActionTab:E,onSelectActionTab:K}=s,{t:U}=st();if(!n)return null;let M;e[0]!==k||e[1]!==R||e[2]!==y||e[3]!==U?(M=R||k||y?t.jsxs(gs,{children:[t.jsxs(Ct,{children:[t.jsx(It,{asChild:!0,children:t.jsx(ms,{asChild:!0,children:t.jsx(G,{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(Pt,{sideOffset:8,children:U("gitView.header.repositoryViews")})]}),t.jsxs(ps,{align:"end",children:[R?t.jsxs(Ss,{onSelect:R,children:[t.jsx(D,{name:"history",className:"size-4"}),U("gitView.history.title")]}):null,k?t.jsxs(Ss,{onSelect:k,children:[t.jsx(D,{name:"git-merge",className:"size-4"}),U("gitView.graph.title")]}):null,y?t.jsxs(Ss,{onSelect:y,children:[t.jsx(D,{name:"archive-stack",className:"size-4"}),U("gitView.stashes.title")]}):null]})]}):null,e[0]=k,e[1]=R,e[2]=y,e[3]=U,e[4]=M):M=e[4];let I;e[5]!==M?(I=t.jsx("div",{className:"flex items-center gap-1 shrink-0",children:M}),e[5]=M,e[6]=I):I=e[6];const P=I,z=!n;let T;e[7]!==n.tracking?(T=n.tracking?.split("/")[0],e[7]=n.tracking,e[8]=T):T=e[8];const J=(n.files?.length??0)>0;let _;e[9]!==c||e[10]!==m||e[11]!==f||e[12]!==d||e[13]!==p||e[14]!==n.ahead||e[15]!==n.behind||e[16]!==l||e[17]!==z||e[18]!==T||e[19]!==J?(_=t.jsx(Kv,{syncAction:l,remotes:d,onFetch:c,onSync:f,onRemoveRemote:m,removingRemoteName:p,disabled:z,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:T,hasUncommittedChanges:J}),e[9]=c,e[10]=m,e[11]=f,e[12]=d,e[13]=p,e[14]=n.ahead,e[15]=n.behind,e[16]=l,e[17]=z,e[18]=T,e[19]=J,e[20]=_):_=e[20];const ee=_;let Q;e[21]!==n.tracking||e[22]!==n.upstreamComparison?(Q=n.upstreamComparison?t.jsx(Cj,{comparison:n.upstreamComparison,trackingBranch:n.tracking,tooltipDelayMs:1e3}):null,e[21]=n.tracking,e[22]=n.upstreamComparison,e[23]=Q):Q=e[23];const N=Q;let V;e[24]!==h||e[25]!==x||e[26]!==S||e[27]!==A?(V=t.jsx(sd,{activeProfile:h,identities:x,onSelect:A,isApplying:S,iconOnly:!0}),e[24]=h,e[25]=x,e[26]=S,e[27]=A,e[28]=V):V=e[28];const B=V;let F;e[29]!==i||e[30]!==C||e[31]!==a||e[32]!==u||e[33]!==j||e[34]!==g||e[35]!==r||e[36]!==d||e[37]!==n.current?(F=t.jsx("div",{className:"min-w-0 flex-1",children:C?t.jsx(Nj,{currentBranch:n.current,onRename:g}):t.jsx(jj,{currentBranch:n.current,localBranches:a,remoteBranches:r,branchInfo:i,onCheckout:u,onCreate:j,remotes:d})}),e[29]=i,e[30]=C,e[31]=a,e[32]=u,e[33]=j,e[34]=g,e[35]=r,e[36]=d,e[37]=n.current,e[38]=F):F=e[38];let O;e[39]!==B||e[40]!==P?(O=t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[P,B]}),e[39]=B,e[40]=P,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 $;e[45]!==v||e[46]!==E||e[47]!==K||e[48]!==ee||e[49]!==N?($=v&&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(Ln,{items:v,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:ee})]}):null,e[45]=v,e[46]=E,e[47]=K,e[48]=ee,e[49]=N,e[50]=$):$=e[50];let ie;return e[51]!==q||e[52]!==$?(ie=t.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[q,$]}),e[51]=q,e[52]=$,e[53]=ie):ie=e[53],ie},Ij=s=>s==="/",cr=s=>s.replace(/\\/g,"/"),Ei=s=>{if(!s||Ij(s))return s;let e=s;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},Zn=s=>s.endsWith("/"),Pj=s=>{const e=s.trim();return!e||Zn(e)?e:`${e}/`},Mi=s=>s.lastIndexOf("/"),nd=s=>{if(Zn(s))return s;const e=Mi(s);return e<0?s:s.slice(0,e+1)},Aj=s=>{const e=Mi(s);return s.slice(e+1)},ad=s=>{const e=Ei(s.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=Mi(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},Dj=s=>Zn(s)&&ad(s)!==null,Ej=(s,e)=>`${nd(s)}${e}/`,Pn=s=>{if(!s)return null;const e=Ei(cr(s.trim()));return e?e.toLowerCase():null},Jl=(s,e)=>{const n=s.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},Mj=s=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey,ei=s=>{if(!s)return;s.focus({preventScroll:!0});const e=s.value.length;s.setSelectionRange(e,e),s.scrollLeft=s.scrollWidth},Tj=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 cr(e.home.trim())}}catch{}return js.getFilesystemHome().catch(()=>null)},rw=({open:s,onOpenChange:e})=>{const{t:n}=st(),a=Ns(b=>b.homeDirectory),r=ss(b=>b.projects),i=ss(b=>b.addProject),l=Ds(b=>b.profiles),d=Ds(b=>b.globalIdentity),c=Ds(b=>b.defaultGitIdentityId),f=Ds(b=>b.loadProfiles),m=Ds(b=>b.loadGlobalIdentity),p=Ds(b=>b.loadDefaultGitIdentityId),{isDesktop:u,requestAccess:j,startAccessing:g}=bj(),{isMobile:h}=Ms(),x=o.useRef(null),A=o.useRef(null),S=o.useRef(new Map),[C,R]=o.useState(""),[k,y]=o.useState("~/"),[v,E]=o.useState([]),[K,U]=o.useState(!1),[M,I]=o.useState(!1),[P,z]=o.useState(0),[T,J]=o.useState(!1),[_,ee]=o.useState(!1),[Q,N]=o.useState(0),[V,B]=o.useState(!1),[F,O]=o.useState(""),[q,$]=o.useState(null),[ie,le]=o.useState(!1),ne=C||a,ye=o.useMemo(()=>new Set(r.map(b=>Pn(b.path)).filter(b=>!!b)),[r]);o.useEffect(()=>{if(!s)return;y("~/"),E([]),z(0),J(!1),ee(!1),B(!1),O(""),$(null),le(!1),requestAnimationFrame(()=>ei(x.current));let b=!1;return(async()=>{const Ee=await Tj();b||(R(Ee||a||""),requestAnimationFrame(()=>ei(x.current)))})(),()=>{b=!0}},[a,s]),o.useEffect(()=>{s&&(f(),m(),p())},[p,f,m,s]);const ae=o.useMemo(()=>{const b=new Map;d&&b.set(d.id,d);for(const be of l)b.set(be.id,be);return Array.from(b.values())},[l,d]);o.useEffect(()=>{if(!s||!V||q!==null)return;const b=typeof c=="string"?c.trim():"";if(b&&ae.some(Ee=>Ee.id===b)){$(b);return}const be=ae.find(Ee=>Ee.authType==="ssh"||Ee.sshKey);be&&$(be.id)},[ae,c,V,s,q]);const ge=o.useMemo(()=>ae.find(b=>b.id===q)??null,[ae,q]),Ne=o.useMemo(()=>nd(k),[k]),he=o.useMemo(()=>Zn(k)?"":Aj(k),[k]),we=o.useMemo(()=>ne?Jl(Ne,ne):"",[Ne,ne]);o.useEffect(()=>{if(!s||!we){E([]);return}let b=!1;return U(!0),I(!1),js.listLocalDirectory(we).then(be=>{if(b)return;I(!1);const Ee=be.filter(ze=>ze.isDirectory).map(ze=>({name:ze.name,path:cr(ze.path)})).sort((ze,qe)=>ze.name.localeCompare(qe.name));E(Ee)}).catch(()=>{b||(E([]),I(!0))}).finally(()=>{b||U(!1)}),()=>{b=!0}},[we,s]);const ce=o.useMemo(()=>{const b=he.toLowerCase(),be=ie||he.startsWith(".");return v.filter(Ee=>Ee.name.toLowerCase().startsWith(b)&&(be||!Ee.name.startsWith(".")))},[he,v,ie]),Z=o.useMemo(()=>{const b=[];Dj(k)&&b.push({type:"up",value:"browse:up",name:"..",path:ad(k)});for(const be of ce){const Ee=Pn(be.path);b.push({type:"directory",value:`browse:${be.path}`,name:be.name,path:be.path,disabled:!!(Ee&&ye.has(Ee))})}return b},[ye,ce,k]);o.useEffect(()=>{z(0)},[k,Z.length]);const se=o.useMemo(()=>ne?Ei(Jl(k,ne)):"",[ne,k]),ve=Pn(se),H=!!(ve&&ye.has(ve)),te=o.useMemo(()=>he?ce.find(b=>b.name===he)??null:null,[he,ce]),re=!!(se&&!H&&(Zn(k)&&M||!Zn(k)&&he.trim().length>0&&te===null)),pe=!T&&!_&&!H&&!!se,Me=pe&&F.trim().length>0,Se=Z[P]??null,Ae=!!(Se&&(Se.type==="up"||Se.type==="directory"&&!Se.disabled)),De=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Pe=n(H?"directoryExplorerDialog.actions.alreadyAdded":V?T?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":T?"directoryExplorerDialog.actions.adding":re?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const b=A.current;if(!b)return;const be=()=>N(Math.ceil(b.getBoundingClientRect().width));if(be(),typeof ResizeObserver>"u")return;const Ee=new ResizeObserver(be);return Ee.observe(b),()=>Ee.disconnect()},[Pe]),o.useLayoutEffect(()=>{const b=x.current;b&&(b.scrollLeft=b.scrollWidth)},[Q,k]),o.useLayoutEffect(()=>{s&&ei(x.current)},[s]),o.useLayoutEffect(()=>{const b=Z[P];b&&S.current.get(b.value)?.scrollIntoView({block:"nearest"})},[P,Z]);const Oe=o.useCallback(()=>{e(!1)},[e]),Te=o.useCallback((b,be)=>{b.stopPropagation();const Ee=Pn(be);if(Ee&&ye.has(Ee))return;i(be)||W.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")})},[i,ye,n]),Ue=o.useCallback(async b=>{if(!b||T)return;const be=Pn(b);if(be&&ye.has(be))return;let Ee=b;J(!0);try{const ze=!V&&re&&Pn(b)===Pn(se);if(V){const rt=F.trim();if(!rt){W.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ee=(await js.cloneRepository({remoteUrl:rt,destinationPath:b,gitIdentityId:ge?.id??null})).path}else ze&&await js.createDirectory(b);if(!i(Ee)){W.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}Oe()}catch(ze){W.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:ze instanceof Error?ze.message:n("directoryExplorerDialog.toast.unknownError")})}finally{J(!1)}},[i,ye,F,Oe,V,T,ge?.id,re,se,n]),Be=o.useCallback(b=>{y(Pj(b))},[]),Ke=o.useCallback(b=>{y(Ej(k,b.name))},[k]),Je=o.useCallback(b=>{if(b){if(b.type==="up"){b.path&&Be(b.path);return}b.disabled||Ke(b)}},[Be,Ke]),ue=o.useCallback(async()=>{if(!(!u||_)){ee(!0);try{const b=await j(se);if(!b.success||!b.path){b.error&&b.error!=="Directory selection cancelled"&&W.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:b.error});return}const be=await g(b.path);if(!be.success){W.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:be.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Ue(b.path)}catch(b){W.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:b instanceof Error?b.message:n("directoryExplorerDialog.toast.unknownError")})}finally{ee(!1)}}},[Ue,u,_,j,g,n,se]),Y=o.useCallback(b=>{if(b.key==="ArrowDown"){b.preventDefault(),z(be=>Math.min(Z.length-1,be+1));return}if(b.key==="ArrowUp"){b.preventDefault(),z(be=>Math.max(0,be-1));return}if(b.key==="Enter"){if(b.preventDefault(),Mj(b)){Ue(se);return}Ae&&Je(Se);return}b.key==="Backspace"&&k===""&&(b.preventDefault(),Oe())},[Je,Ue,Oe,Ae,Se,k,Z.length,se]),de=t.jsxs("button",{type:"button",onClick:()=>le(b=>!b),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")]}),je=t.jsxs("div",{className:"px-2.5 py-1.5",children:[V?t.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[t.jsx(Xe,{value:F,onChange:b=>O(b.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(sd,{activeProfile:ge,identities:ae,onSelect:b=>$(b.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:x,value:k,onChange:b=>y(cr(b.target.value)),onKeyDown:Y,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!h&&Q>0?{paddingRight:`${Q+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),h?null:t.jsx(G,{ref:A,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:V?!Me:!pe,onMouseDown:b=>b.preventDefault(),onClick:()=>{Ue(se)},title:Pe,children:Pe})]})]}),Re=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")}):Z.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:Z.map((b,be)=>{const Ee=be===P;return t.jsxs("button",{ref:ze=>{ze?S.current.set(b.value,ze):S.current.delete(b.value)},type:"button",disabled:b.type==="directory"&&b.disabled,onMouseEnter:()=>z(be),onMouseDown:ze=>ze.preventDefault(),onClick:()=>Je(b),className:oe("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",Ee&&"bg-interactive-selection text-interactive-selection-foreground",!Ee&&"hover:bg-interactive-hover/50",b.type==="directory"&&b.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[b.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:b.name})}),b.type==="directory"&&b.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")}):b.type==="directory"?t.jsx("button",{type:"button",onMouseDown:ze=>ze.stopPropagation(),onClick:ze=>Te(ze,b.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]},b.value)})})]})}),Ie=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[je,Re]}),Ve=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:De}),t.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),X=()=>t.jsxs(t.Fragment,{children:[h?null:Ve,t.jsxs("div",{className:oe("flex w-full flex-row justify-end gap-2 sm:w-auto",h&&"justify-stretch"),children:[u?t.jsx(G,{variant:"ghost",size:"xs",onClick:ue,disabled:T||_||V,children:n(_?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,t.jsx(G,{variant:"ghost",size:"xs",onClick:()=>B(b=>!b),disabled:T||_,className:oe(h&&"flex-1"),children:n(V?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),h?t.jsx(G,{size:"xs",onClick:()=>{Ue(se)},disabled:V?!Me:!pe,className:"flex-1",children:Pe}):null]})]});return h?t.jsx(ya,{open:s,onClose:Oe,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:de}),Ie]})}):t.jsx(Lt,{open:s,onOpenChange:e,children:t.jsxs(Ft,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(Kt,{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(Ut,{children:n("directoryExplorerDialog.title")}),t.jsx(_t,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),de]})}),t.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:Ie}),t.jsx(Jt,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:X()})]})})};function Ql(s){const{localBranches:e,remoteBranches:n,query:a}=s,r=a.trim();if(!r)return{matching:[],otherLocal:e,otherRemote:n};const i=Yi(e,r,m=>m),l=Yi(n,r,m=>m),d=[],c=i.other,f=l.other;for(const m of i.matching)d.push({label:m,value:m,source:"local"});for(const m of l.matching)d.push({label:m,value:`remotes/${m}`,source:"remote"});return d.sort((m,p)=>{const u=m.label.localeCompare(p.label,void 0,{sensitivity:"accent"});return u!==0?u:m.source!==p.source?m.source.localeCompare(p.source):m.value.localeCompare(p.value)}),{matching:d,otherLocal:c,otherRemote:f}}function Rj({open:s,onOpenChange:e,onSelect:n}){const{t:a}=st(),r=Fe(Z=>Z.isMobile),{github:i}=Si(),l=nn(Z=>Z.status),d=nn(Z=>Z.hasChecked),c=Fe(Z=>Z.setSettingsDialogOpen),f=Fe(Z=>Z.setSettingsPage),m=ss(Z=>Z.getActiveProject()),p=m?.path??null,u=fe.useMemo(()=>p&&m?{id:m.id,path:p}:null,[m,p]),[j,g]=fe.useState("issues"),[h,x]=fe.useState(""),[A,S]=fe.useState([]),[C,R]=fe.useState([]),[k,y]=fe.useState(!1),[v,E]=fe.useState(!1),[K,U]=fe.useState(null),[M,I]=fe.useState(null),[P,z]=fe.useState(null),[T,J]=fe.useState(!1),[_,ee]=fe.useState(new Map),[Q,N]=fe.useState(1),[V,B]=fe.useState(!1),F=vm(h,350),O=fe.useCallback(async Z=>{if(!(!p||!i)&&!(d&&l?.connected===!1)){y(!0),U(null),N(1),B(!1);try{if(j==="issues"&&i.issuesList){const se=await i.issuesList(p,{page:1,query:Z});se.connected===!1?(U(a("session.githubIntegration.error.notConnected")),S([])):(S(se.issues??[]),N(se.page??1),B(!!se.hasMore))}else if(j==="prs"&&i.prsList){const se=await i.prsList(p,{page:1,query:Z});se.connected===!1?(U(a("session.githubIntegration.error.notConnected")),R([])):(R(se.prs??[]),N(se.page??1),B(!!se.hasMore))}}catch(se){U(se instanceof Error?se.message:a("session.githubIntegration.error.loadDataFailed"))}finally{y(!1)}}},[p,i,d,l,j,a]);fe.useEffect(()=>{if(!s||!p||d&&l?.connected===!1||!i)return;if(!F.trim()){O();return}const Z=new AbortController;y(!0),U(null),N(1),B(!1);const se=j==="issues"&&i.issuesList?i.issuesList(p,{page:1,query:F.trim()}):j==="prs"&&i.prsList?i.prsList(p,{page:1,query:F.trim()}):null;if(!se){y(!1);return}return se.then(ve=>{Z.signal.aborted||("issues"in ve?ve.connected===!1?(U(a("session.githubIntegration.error.notConnected")),S([])):(S(ve.issues??[]),N(ve.page??1),B(!!ve.hasMore)):"prs"in ve&&(ve.connected===!1?(U(a("session.githubIntegration.error.notConnected")),R([])):(R(ve.prs??[]),N(ve.page??1),B(!!ve.hasMore))))}).catch(ve=>{Z.signal.aborted||U(ve instanceof Error?ve.message:a("session.githubIntegration.error.loadDataFailed"))}).finally(()=>{Z.signal.aborted||y(!1)}),()=>Z.abort()},[s,p,i,d,l,j,F,O,a]);const q=fe.useCallback(async()=>{if(!(!p||!i)&&!(k||v)&&V){E(!0);try{const Z=Q+1;if(j==="issues"&&i.issuesList){const se=F.trim()?await i.issuesList(p,{page:Z,query:F.trim()}):await i.issuesList(p,{page:Z});se.connected!==!1&&(S(ve=>[...ve,...se.issues??[]]),N(se.page??Z),B(!!se.hasMore))}else if(j==="prs"&&i.prsList){const se=F.trim()?await i.prsList(p,{page:Z,query:F.trim()}):await i.prsList(p,{page:Z});se.connected!==!1&&(R(ve=>[...ve,...se.prs??[]]),N(se.page??Z),B(!!se.hasMore))}}catch{}finally{E(!1)}}},[p,i,j,Q,V,k,v,F]);fe.useEffect(()=>{if(!s){g("issues"),x(""),S([]),R([]),I(null),z(null),J(!1),U(null),ee(new Map),N(1),B(!1);return}O()},[s,O]);const $=fe.useCallback(async Z=>{if(!(!u||!Z)&&!_.has(Z))try{const ve=(await pc(u,{mode:"new",branchName:Z,worktreeName:Z})).errors.find(H=>H.code==="branch_in_use");ee(H=>new Map(H).set(Z,{isValid:!ve,error:ve?a(ve.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{ee(se=>new Map(se).set(Z,{isValid:!1,error:a("session.githubIntegration.validation.failed")}))}},[u,_,a]);fe.useEffect(()=>{!s||j!=="prs"||C.forEach(Z=>{Z.head&&$(Z.head)})},[s,j,C,$]);const ie=d&&l?.connected===!0,le=()=>{f("github"),c(!0)},ne=Z=>{I(Z),z(null)},ye=Z=>{z(Z),I(null)},ae=()=>{M?n({type:"issue",item:M}):P&&n({type:"pr",item:P,includeDiff:T}),e(!1)},ge=()=>{I(null),z(null),J(!1)},Ne=M||P&&_.get(P.head??"")?.isValid!==!1,he=Z=>Z.head?_.get(Z.head)?.isValid===!1:!0,we=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:h,onChange:Z=>x(Z.target.value),placeholder:a(j==="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&&j==="issues"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[A.length>0?A.map(Z=>t.jsx("button",{onClick:()=>ne(Z),className:oe("w-full text-left px-2 py-1.5 rounded transition-colors",M?.number===Z.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:["#",Z.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-2",children:Z.title}),Z.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:[Z.sourceRepo.owner,"/",Z.sourceRepo.repo]}):null]})]})},`${Z.sourceRepo?.owner??""}-${Z.sourceRepo?.repo??""}-${Z.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")}),V&&!v&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(G,{variant:"ghost",size:"sm",onClick:()=>{q()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),v&&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&&j==="prs"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[C.length>0?C.map(Z=>{const se=he(Z),ve=Z.head?_.get(Z.head):void 0;return t.jsx("button",{onClick:()=>!se&&ye(Z),disabled:se,className:oe("w-full text-left px-2 py-1.5 rounded transition-colors",P?.number===Z.number?"bg-interactive-selection text-interactive-selection-foreground":se?"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:["#",Z.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-1",children:Z.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[Z.head," → ",Z.base]}),Z.sourceRepo?.source==="upstream"?t.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[Z.sourceRepo.owner,"/",Z.sourceRepo.repo]}):null,se&&ve?.error&&t.jsx("span",{className:"typography-micro text-destructive",children:ve.error})]})]})]})},`${Z.sourceRepo?.owner??""}-${Z.sourceRepo?.repo??""}-${Z.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")}),V&&!v&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(G,{variant:"ghost",size:"sm",onClick:()=>{q()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),v&&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(G,{onClick:le,size:"sm",children:a("session.githubIntegration.connect.action")})]})}),ce=t.jsxs("div",{className:oe("w-full",r?"flex flex-col gap-2":"flex flex-row items-center"),children:[t.jsxs("div",{className:oe("flex items-center gap-4",r?"w-full justify-center order-1":"flex-1"),children:[!r&&(M||P)&&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:P?.number??""})}),t.jsx("button",{onClick:ge,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"})})]}),j==="prs"&&P&&t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[t.jsx(bt,{checked:T,onChange:Z=>J(Z),ariaLabel:a("session.githubIntegration.includeDiffAria")}),t.jsx("span",{className:"typography-small text-foreground",children:a("session.githubIntegration.includeDiff")})]})]}),t.jsxs("div",{className:oe("flex gap-2",r?"w-full order-2":"justify-end"),children:[t.jsx(G,{variant:"outline",size:"sm",onClick:()=>e(!1),className:oe(r&&"flex-1"),children:a("session.githubIntegration.actions.cancel")}),t.jsx(G,{size:"sm",onClick:ae,disabled:!Ne,className:oe(r&&"flex-1"),children:a("session.githubIntegration.actions.select")})]})]});return t.jsx(t.Fragment,{children:r?t.jsx(ya,{open:s,title:a("session.githubIntegration.title"),onClose:()=>e(!1),footer:ie?ce:void 0,renderHeader:Z=>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")}),Z]}),t.jsx("div",{className:"w-full",children:t.jsx(Ln,{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:j,onSelect:se=>{g(se),x("")},variant:"active-pill",layoutMode:"fit"})}),(M||P)&&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:P?.number??""})}),t.jsx("button",{onClick:ge,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:we}):t.jsx(Lt,{open:s,onOpenChange:e,children:t.jsxs(Ft,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsx(Kt,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(Ut,{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(Ln,{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:j,onSelect:Z=>{g(Z),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),we,t.jsx(Jt,{className:"mt-1",children:ce})]})})})}const xa=s=>s.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),bs=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),Yl="oc:lastWorktreeSourceBranch",Lj=s=>String(s).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",Xl=(s,e,n)=>{const a=xa(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(f=>{const m=f.indexOf("/");return m<=0||m>=f.length-1?!1:f.slice(m+1)===a});if(r){const f=r.indexOf("/"),m=r.slice(0,f);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",d=`pr-${Lj(l)}`,c=s.headRepo?.sshUrl||s.headRepo?.cloneUrl||"";if(!c)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${d}/${a}`,setUpstream:!0,upstreamRemote:d,upstreamBranch:a,ensureRemoteName:d,ensureRemoteUrl:c,sourceLabel:`${d}/${a}`}},Fj=s=>{const e={repo:s.repo??null,issue:s.issue,comments:s.comments};return`GitHub issue context (JSON)
166
+ ${JSON.stringify(e,null,2)}`},Oj=s=>`GitHub pull request context (JSON)
167
+ ${JSON.stringify(s,null,2)}`;function iw({open:s,onOpenChange:e,onWorktreeCreated:n}){const{t:a}=st(),{github:r,git:i}=Si(),l=Fe(X=>X.isMobile),d=nn(X=>X.status),c=nn(X=>X.hasChecked),f=ss(X=>X.getActiveProject()),m=f?.path??null,p=fe.useMemo(()=>m&&f?{id:f.id,path:m}:null,[f,m]),[u,j]=fe.useState("new-branch"),[g,h]=fe.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,A]=fe.useState({selectedBranch:"",worktreeName:""}),S=jm(m),C=wm(m),R=Nm(X=>X.fetchBranches),k=fe.useMemo(()=>S?.all?S.all.filter(X=>!X.startsWith("remotes/")).sort():[],[S]),y=fe.useMemo(()=>S?.all?S.all.filter(X=>X.startsWith("remotes/")).map(X=>X.replace(/^remotes\//,"")).sort():[],[S]),v=vs(X=>X.availableWorktreesByProject),E=fe.useMemo(()=>{if(!m)return new Set;const X=v.get(m)??[];return new Set(X.map(b=>b.name))},[v,m]),K=fe.useCallback((X=10)=>{for(let b=0;b<X;b++){const be=Sr();if(!E.has(be))return be}return`${Sr()}-${Date.now().toString(36).slice(-4)}`},[E]),[U,M]=fe.useState(!1),[I,P]=fe.useState(!1),[z,T]=fe.useState(!1),[J,_]=fe.useState(!1),[ee,Q]=fe.useState(!1),[N,V]=fe.useState(""),[B,F]=fe.useState(""),O=fe.useRef(null),q=fe.useRef(null),$=fe.useRef(null),ie=fe.useRef(null),le=fe.useCallback(X=>{X.stopPropagation()},[]),ne=fe.useCallback(X=>{let b=X;for(;b&&b!==document.body;){const{overflowY:be}=window.getComputedStyle(b);if((be==="auto"||be==="scroll")&&b.scrollHeight>b.clientHeight)return b;b=b.parentElement}return null},[]),ye=fe.useCallback(X=>{X&&(X.scrollTop=0)},[]),ae=fe.useCallback(X=>{const b=X.current?.querySelector('[data-slot="command-list"]')??null;ye(b)},[ye]),ge=fe.useCallback(X=>{const b=ne(X.current);ye(b)},[ne,ye]),Ne=fe.useMemo(()=>Ql({localBranches:k,remoteBranches:y,query:N}),[k,y,N]),he=fe.useMemo(()=>Ql({localBranches:k,remoteBranches:y,query:B}),[k,y,B]),we=N.trim().length>0,ce=B.trim().length>0,Z=Ne.matching.length>0,se=he.matching.length>0,ve=!!(m&&i),H=fe.useCallback(()=>{!m||!i||R(m,i)},[m,i,R]);fe.useEffect(()=>{!s||!m||!i||S?.all||R(m,i)},[s,m,i,S?.all,R]),fe.useEffect(()=>{!I&&!J&&V("")},[I,J]),fe.useEffect(()=>{!z&&!ee&&F("")},[z,ee]),fe.useEffect(()=>{I&&ae(O),J&&ge($)},[I,J,N,ae,ge]),fe.useEffect(()=>{z&&ae(q),ee&&ge(ie)},[z,ee,B,ae,ge]);const[te,re]=fe.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[pe,Me]=fe.useState(!1),[Se,Ae]=fe.useState(null),De=fe.useCallback(()=>{const X=it.getState(),b=X.getVisibleAgents();if(X.settingsDefaultAgent){const be=b.find(Ee=>Ee.name===X.settingsDefaultAgent);if(be)return be.name}return b.find(be=>be.name==="build")?.name||b[0]?.name},[]),Pe=fe.useCallback(()=>{const X=it.getState(),b=X.settingsDefaultModel;if(!b)return null;const be=xn(b);if(!be)return null;const{providerId:Ee,modelId:ze}=be;return X.getModelMetadata(Ee,ze)?{providerID:Ee,modelID:ze}:null},[]),Oe=fe.useCallback((X,b)=>{const be=it.getState(),Ee=be.settingsDefaultVariant,ze=be.currentProviderId===X&&be.currentModelId===b?be.currentVariant:void 0,lt=be.providers.find(at=>at.id===X)?.models.find(at=>at.id===b)?.variants;if(!lt)return Ee||ze||void 0;if(Ee&&Object.prototype.hasOwnProperty.call(lt,Ee))return Ee;if(ze&&Object.prototype.hasOwnProperty.call(lt,ze))return ze},[]),Te=fe.useCallback(async X=>{if(!m||!r)return;const b=it.getState(),be=km.getState().lastUsedProvider,Ee=Pe(),ze=Ee?.providerID||b.currentProviderId||be?.providerID,qe=Ee?.modelID||b.currentModelId||be?.modelID,rt=De()||b.currentAgentName||void 0;if(!ze||!qe){W.error(a("session.newWorktree.error.noModelSelected"));return}const lt=Oe(ze,qe);if(X.issue){if(!r.issueGet||!r.issueComments)return;const at=await r.issueGet(m,X.issue.number);if(at.connected===!1||!at.repo||!at.issue)throw new Error("Failed to load issue context");const ct=await r.issueComments(m,X.issue.number);if(ct.connected===!1)throw new Error("Failed to load issue comments");const Ye=await Ma("github.issue.review.visible",{issue_number:String(X.issue.number)}),_e=await Ma("github.issue.review.instructions"),ft=Fj({repo:at.repo,issue:at.issue,comments:ct.comments??[]});await vs.getState().sendMessage(Ye,ze,qe,rt,void 0,void 0,[{text:_e,synthetic:!0},{text:ft,synthetic:!0}],lt,void 0,{sessionId:X.sessionId}),W.success(a("session.newWorktree.toast.sessionFromIssue"));return}if(X.pr){if(!r.prContext)return;const at=await r.prContext(m,X.pr.number,{includeDiff:X.includeDiff,includeCheckDetails:!1});if(at.connected===!1||!at.repo||!at.pr)throw new Error("Failed to load PR context");const ct=await Ma("github.pr.review.visible",{pr_number:String(X.pr.number)}),Ye=await Ma("github.pr.review.instructions"),_e=Oj(at);await vs.getState().sendMessage(ct,ze,qe,rt,void 0,void 0,[{text:Ye,synthetic:!0},{text:_e,synthetic:!0}],lt,void 0,{sessionId:X.sessionId}),W.success(a("session.newWorktree.toast.sessionFromPr"))}},[r,m,De,Pe,Oe,a]),Ue=u==="new-branch"?g:x;fe.useEffect(()=>{if(!S?.all||!m||g.sourceBranch)return;(async()=>{try{const b=await Sm(m).catch(()=>null),be=localStorage.getItem(Yl),Ee=be&&S.all?.includes(be)?be:b&&S.all?.includes(b)?b:S.all?.includes("main")?"main":S.all?.includes("master")?"master":S.all?.[0]||"";Ee&&h(ze=>({...ze,sourceBranch:Ee}))}catch{}})()},[S,m,g.sourceBranch]),fe.useEffect(()=>{if(!s)return;j("new-branch"),A({selectedBranch:"",worktreeName:""}),P(!1),T(!1),_(!1),Q(!1),V(""),F(""),re({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const X=K();h({branchName:X,worktreeName:X,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[s,K]),fe.useEffect(()=>{if(u!=="new-branch"||!g.isSyncingWorktreeName)return;const X=xa(g.branchName),b=bs(X);h(be=>({...be,worktreeName:b}))},[u,g.branchName,g.isSyncingWorktreeName]);const Be=fe.useCallback(async()=>{if(!p||!te.touched||pe)return;Se&&Se.abort();const X=new AbortController;Ae(X),re(b=>({...b,isValidating:!0}));try{const b=u==="new-branch"?g.branchName:x.selectedBranch,be=Ue.worktreeName,Ee=xa(b),ze=bs(be);let qe=null,rt=null;if(Ee||(qe=a("session.newWorktree.error.branchNameRequired")),ze||(rt=a("session.newWorktree.error.worktreeDirectoryRequired")),Ee&&ze){const lt=u==="new-branch"?g.linkedPr:null,at=lt?Xl(lt,k,y):null,ct=await pc(p,{mode:u==="existing-branch"||at?"existing":"new",branchName:Ee,worktreeName:ze,existingBranch:at?.existingBranch??(u==="existing-branch"?Ee:void 0),...at?.ensureRemoteName?{ensureRemoteName:at.ensureRemoteName}:{},...at?.ensureRemoteUrl?{ensureRemoteUrl:at.ensureRemoteUrl}:{}});if(X.signal.aborted)return;ct.ok||ct.errors.forEach(Ye=>{if(Ye.code==="worktree_exists"){rt=rt??Ye.message;return}Ye.code.startsWith("branch_")&&(qe=qe??Ye.message)})}X.signal.aborted||re(lt=>({...lt,isValidating:!1,branchError:qe,worktreeError:rt}))}catch{X.signal.aborted||re(b=>({...b,isValidating:!1}))}},[p,u,g.branchName,g.linkedPr,x.selectedBranch,Ue.worktreeName,k,y,te.touched,Se,pe,a]),Ke=u==="new-branch"?g.branchName:x.selectedBranch;fe.useEffect(()=>{if(!s||!p||!te.touched||pe)return;const X=setTimeout(()=>{Be()},300);return()=>clearTimeout(X)},[Ue.worktreeName,Ke,s,p,Be,te.touched,pe]);const Je=async()=>{if(!p||!m){W.error(a("session.newWorktree.error.noActiveProject"));return}re(ze=>({...ze,touched:!0}));const X=u==="new-branch"?g.branchName:x.selectedBranch,b=Ue.worktreeName,be=xa(X),Ee=bs(b);if(!be){W.error(a("session.newWorktree.error.branchNameRequired"));return}if(!Ee){W.error(a("session.newWorktree.error.worktreeDirectoryRequired"));return}Se&&(Se.abort(),Ae(null)),re(ze=>({...ze,isValidating:!1,branchError:null,worktreeError:null})),Me(!0);try{const ze=u==="new-branch"?g.linkedPr:null,qe=u==="new-branch"?g.linkedIssue:null,rt=u==="new-branch"?g.linkedPr:null,lt=u==="new-branch"?g.includePrDiff:!1,at=!!(qe||rt),ct=await cc(p),Ye=g.sourceBranch;let _e="";const ft=(()=>{if(ze){const He=Xl(ze,k,y);return _e=He.sourceLabel,{preferredName:be||Ee,mode:"existing",branchName:be,worktreeName:Ee,existingBranch:He.existingBranch,setupCommands:ct,setUpstream:He.setUpstream,upstreamRemote:He.upstreamRemote,upstreamBranch:He.upstreamBranch,returnAfterDirectoryCreated:!0,...He.ensureRemoteName?{ensureRemoteName:He.ensureRemoteName}:{},...He.ensureRemoteUrl?{ensureRemoteUrl:He.ensureRemoteUrl}:{}}}return _e=u==="new-branch"?Ye:"",{preferredName:be||Ee,mode:u==="existing-branch"?"existing":"new",branchName:u==="existing-branch"?void 0:be,worktreeName:Ee,existingBranch:u==="existing-branch"?be:void 0,setupCommands:ct,returnAfterDirectoryCreated:!0,...Ye&&u==="new-branch"?{startRef:Ye}:{}}})(),xe=await Cm(m,ft),et=await Im(p,xe);let nt=null;if(at){await dc(p)&&await Pm(et.path);const He=qe?`#${qe.number} ${qe.title}`.trim():rt?`#${rt.number} ${rt.title}`.trim():a("session.newWorktree.newSessionTitle"),yt=await Am(He,et.path,null);if(!yt?.id)throw new Error("Failed to create session");nt=yt.id,n?.(et.path,{sessionId:nt}),e(!1),Me(!1),Dm(yt.id,He).catch(()=>{});try{vs.getState().initializeNewOpenChamberSession(yt.id,it.getState().agents)}catch{}}else e(!1),Me(!1);g.sourceBranch&&u==="new-branch"&&!g.linkedPr&&localStorage.setItem(Yl,g.sourceBranch),W.success(a("session.newWorktree.toast.worktreeCreated"),{description:a("session.newWorktree.toast.worktreeCreatedDescription",{target:`${et.branch||et.name}${_e?` ${a("session.newWorktree.fromSource",{source:_e})}`:""}`})}),nt?Te({sessionId:nt,directory:et.path,issue:qe,pr:rt,includeDiff:lt}).catch(He=>{const yt=He instanceof Error?He.message:a("session.newWorktree.error.sendGitHubContextFailed");W.error(a("session.newWorktree.error.sendGitHubContextFailed"),{description:yt})}):n?.(et.path)}catch(ze){const qe=ze instanceof Error?ze.message:a("session.newWorktree.error.createWorktreeFailed");W.error(a("session.newWorktree.error.createWorktreeFailed"),{description:qe})}finally{Me(!1)}},ue=X=>{j(X),re(b=>({...b,touched:!1,branchError:null,worktreeError:null}))},Y=X=>{if(!X){h(b=>({...b,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(X.type==="issue"){const b=X.item,be=`issue-${b.number}-${Sr()}`;h(Ee=>({...Ee,linkedIssue:b,linkedPr:null,includePrDiff:!1,branchName:be,worktreeName:bs(be),isSyncingWorktreeName:!0}))}else if(X.type==="pr"){const b=X.item;h(be=>({...be,linkedPr:b,linkedIssue:null,includePrDiff:X.includeDiff??!1,branchName:b.head,worktreeName:bs(b.head),isSyncingWorktreeName:!0}))}},de=c&&d?.connected===!0,Re=(u==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!te.branchError&&!te.worktreeError:!!xa(g.branchName)&&!!g.worktreeName&&!te.branchError&&!te.worktreeError)&&!pe,Ie=()=>{h(X=>({...X,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Ve=t.jsxs("div",{className:oe("flex gap-2",l?"flex-col w-full":"flex-row items-center"),children:[t.jsx("div",{className:oe("flex items-center gap-1.5 text-destructive",l?"w-full justify-center order-first":"mr-auto"),children:te.touched&&(te.branchError||te.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:te.branchError||te.worktreeError})]})}),t.jsxs("div",{className:oe("flex gap-2",l&&"w-full"),children:[t.jsx(G,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:pe,className:oe(l&&"flex-1"),children:a("session.newWorktree.actions.cancel")}),t.jsxs(G,{size:"sm",onClick:Je,disabled:!Re||pe,className:oe("gap-1.5",l&&"flex-1"),children:[pe&&t.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(pe?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return t.jsxs(t.Fragment,{children:[l?t.jsxs(ya,{open:s,title:a("session.newWorktree.title"),onClose:()=>e(!1),footer:Ve,children:[t.jsx("div",{className:"w-full mb-4",children:t.jsx(Ln,{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:u,onSelect:X=>ue(X),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),t.jsxs("div",{className:"space-y-6",children:[u==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(G,{variant:"outline",size:"sm",onClick:()=>_(!0),className:"flex-1 justify-between h-9",children:[t.jsx("span",{className:x.selectedBranch?"text-foreground":"text-muted-foreground",children:x.selectedBranch||a("session.newWorktree.chooseBranch")}),t.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),t.jsx(G,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:H,disabled:!ve||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(ya,{open:J,title:a("session.newWorktree.selectBranch"),onClose:()=>_(!1),children:t.jsxs("div",{className:"space-y-4",ref:$,children:[t.jsx(Xe,{value:N,onChange:X=>V(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&&y.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[we&&Z&&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:Ne.matching.map(X=>t.jsx("button",{onClick:()=>{A(b=>({...b,selectedBranch:X.value,worktreeName:bs(X.label)})),re(b=>({...b,touched:!0})),_(!1)},className:oe("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.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}`))})]}),we&&!Z&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),Ne.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(we?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:Ne.otherLocal.map(X=>t.jsx("button",{onClick:()=>{A(b=>({...b,selectedBranch:X,worktreeName:bs(X)})),re(b=>({...b,touched:!0})),_(!1)},className:oe("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.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))})]}),Ne.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(we?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:Ne.otherRemote.map(X=>t.jsx("button",{onClick:()=>{A(b=>({...b,selectedBranch:`remotes/${X}`,worktreeName:bs(X)})),re(b=>({...b,touched:!0})),_(!1)},className:oe("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.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")}),u==="new-branch"&&de&&t.jsxs(G,{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"}),g.linkedIssue||g.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(Xe,{value:g.branchName,onChange:X=>{h(b=>({...b,branchName:X.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>re(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:oe("h-8",te.touched&&te.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.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:g.linkedPr.head})})]}),g.linkedIssue&&!g.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:g.linkedIssue.number,title:g.linkedIssue.title})})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:a("session.newWorktree.worktreeDirectory")}),u!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const X=bs(u==="new-branch"?g.branchName:"");h(b=>({...b,worktreeName:X,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===bs(g.branchName),className:oe("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===bs(g.branchName)||!g.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:Ue.worktreeName,onChange:X=>{u==="new-branch"?h(b=>({...b,worktreeName:X.target.value,isSyncingWorktreeName:!1})):A(b=>({...b,worktreeName:X.target.value}))},onBlur:()=>re(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:oe("h-8",te.touched&&te.worktreeError&&"border-destructive")})]}),u==="new-branch"&&!g.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(G,{variant:"outline",size:"sm",onClick:()=>Q(!0),className:"w-full justify-between h-9",children:[t.jsx("span",{className:g.sourceBranch?"text-foreground":"text-muted-foreground",children:g.sourceBranch||a("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),g.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:a("session.newWorktree.newBranchFromSource",{source:g.sourceBranch})}),t.jsx(ya,{open:ee,title:a("session.newWorktree.selectSourceBranch"),onClose:()=>Q(!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&&y.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[ce&&se&&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:he.matching.map(X=>t.jsx("button",{onClick:()=>{h(b=>({...b,sourceBranch:X.value})),Q(!1)},className:oe("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.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}`))})]}),ce&&!se&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),he.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(ce?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:he.otherLocal.map(X=>t.jsx("button",{onClick:()=>{h(b=>({...b,sourceBranch:X})),Q(!1)},className:oe("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.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))})]}),he.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(ce?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:he.otherRemote.map(X=>t.jsx("button",{onClick:()=>{h(b=>({...b,sourceBranch:`remotes/${X}`})),Q(!1)},className:oe("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.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}`))})]})]})]})})]}),(g.linkedIssue||g.linkedPr)&&u==="new-branch"&&t.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),g.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.issueNumber",{number:g.linkedIssue.number})}),g.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.prNumber",{number:g.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:g.linkedIssue?.title||g.linkedPr?.title}),t.jsx("a",{href:g.linkedIssue?.url||g.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:Ie,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"})})]}),g.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:[g.linkedPr.head," → ",g.linkedPr.base]}),g.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(Lt,{open:s,onOpenChange:e,children:t.jsxs(Ft,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[t.jsx(Kt,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(Ut,{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(Ln,{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:u,onSelect:X=>ue(X),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),t.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[u==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(gs,{open:I,onOpenChange:P,children:[t.jsx(ms,{asChild:!0,children:t.jsxs(G,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[t.jsx("span",{className:oe("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.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(ai,{shouldFilter:!1,children:[t.jsx(ri,{placeholder:a("session.newWorktree.searchBranches"),value:N,onValueChange:V,onKeyDown:le}),t.jsx(ii,{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&&y.length===0?t.jsx(oi,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[we&&Z&&t.jsx(en,{heading:a("session.newWorktree.matchingBranches"),children:Ne.matching.map(X=>t.jsx(Ks,{value:X.value,onSelect:()=>{A(b=>({...b,selectedBranch:X.value,worktreeName:bs(X.label)})),re(b=>({...b,touched:!0})),P(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))}),we&&!Z&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),Ne.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[we&&t.jsx(Gn,{}),t.jsx(en,{heading:a(we?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:Ne.otherLocal.map(X=>t.jsx(Ks,{value:X,onSelect:()=>{A(b=>({...b,selectedBranch:X,worktreeName:bs(X)})),re(b=>({...b,touched:!0})),P(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`local-${X}`))})]}),Ne.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(Ne.otherLocal.length>0||we)&&t.jsx(Gn,{}),t.jsx(en,{heading:a(we?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:Ne.otherRemote.map(X=>t.jsx(Ks,{value:`remotes/${X}`,onSelect:()=>{A(b=>({...b,selectedBranch:`remotes/${X}`,worktreeName:bs(X)})),re(b=>({...b,touched:!0})),P(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`remote-${X}`))})]})]})})]})})]}),t.jsx(G,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:H,disabled:!ve||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")}),u==="new-branch"&&de&&t.jsxs(G,{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"}),g.linkedIssue||g.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(Xe,{value:g.branchName,onChange:X=>{h(b=>({...b,branchName:X.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>re(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:oe("h-8",te.touched&&te.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.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:g.linkedPr.head})})]}),g.linkedIssue&&!g.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:g.linkedIssue.number,title:g.linkedIssue.title})})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:a("session.newWorktree.worktreeDirectory")}),u!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const X=bs(u==="new-branch"?g.branchName:"");h(b=>({...b,worktreeName:X,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===bs(g.branchName),className:oe("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===bs(g.branchName)||!g.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:Ue.worktreeName,onChange:X=>{u==="new-branch"?h(b=>({...b,worktreeName:X.target.value,isSyncingWorktreeName:!1})):A(b=>({...b,worktreeName:X.target.value}))},onBlur:()=>re(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:oe("h-8",te.touched&&te.worktreeError&&"border-destructive")})]}),u==="new-branch"&&!g.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(G,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[t.jsx("span",{className:oe("truncate",g.sourceBranch?"text-foreground":"text-muted-foreground"),children:g.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(ai,{shouldFilter:!1,children:[t.jsx(ri,{placeholder:a("session.newWorktree.searchBranches"),value:B,onValueChange:F,onKeyDown:le}),t.jsx(ii,{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&&y.length===0?t.jsx(oi,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[ce&&se&&t.jsx(en,{heading:a("session.newWorktree.matchingBranches"),children:he.matching.map(X=>t.jsx(Ks,{value:X.value,onSelect:()=>{h(b=>({...b,sourceBranch:X.value})),T(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))}),ce&&!se&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),he.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[ce&&t.jsx(Gn,{}),t.jsx(en,{heading:a(ce?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:he.otherLocal.map(X=>t.jsx(Ks,{value:X,onSelect:()=>{h(b=>({...b,sourceBranch:X})),T(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`local-${X}`))})]}),he.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(he.otherLocal.length>0||ce)&&t.jsx(Gn,{}),t.jsx(en,{heading:a(ce?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:he.otherRemote.map(X=>t.jsx(Ks,{value:`remotes/${X}`,onSelect:()=>{h(b=>({...b,sourceBranch:`remotes/${X}`})),T(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`remote-${X}`))})]})]})})]})})]}),g.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:a("session.newWorktree.newBranchFromSource",{source:g.sourceBranch})})]}),(g.linkedIssue||g.linkedPr)&&u==="new-branch"&&t.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),g.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.issueNumber",{number:g.linkedIssue.number})}),g.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.prNumber",{number:g.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:g.linkedIssue?.title||g.linkedPr?.title}),t.jsx("a",{href:g.linkedIssue?.url||g.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:Ie,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"})})]}),g.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:[g.linkedPr.head," → ",g.linkedPr.base]}),g.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(Jt,{className:"mt-1 flex items-center justify-between",children:[t.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:te.touched&&(te.branchError||te.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:te.branchError||te.worktreeError})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(G,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:pe,children:a("session.newWorktree.actions.cancel")}),t.jsxs(G,{size:"sm",onClick:Je,disabled:!Re||pe,className:"gap-1.5",children:[pe&&t.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(pe?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),t.jsx(Rj,{open:U,onOpenChange:M,onSelect:Y})]})}const ow=()=>{xc(),js.reconnectToRuntimeBaseUrl(),gc()},lw=s=>{vs.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),Fe.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),s.previousRuntimeKey&&Em.getState().stopRunningRunsForRuntime(s.previousRuntimeKey),xc(),js.reconnectToRuntimeBaseUrl(),it.setState({providers:[],agents:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),ss.getState().resetForRuntimeSwitch(),ni.getState().resetForRuntimeSwitch(),vs.getState().restoreForRuntimeSwitch(s.runtimeKey),Fe.getState().restoreForRuntimeSwitch(s.runtimeKey),gc()};export{_l as $,vc as A,xy as B,tw as C,rw as D,Mn as E,Tn as F,Rn as G,Yj as H,Vl as I,_x as J,Hx as K,vo as L,cp as M,iw as N,Hj as O,nw as P,wn as Q,Ds as R,Kv as S,aw as T,fy as U,vn as V,Gj as W,ln as X,bn as Y,yn as Z,Qv as _,sw as a,tl as a0,Pf as a1,el as a2,Yh as a3,Jc as a4,Yc as a5,ax as a6,By as a7,_j as a8,Rg as a9,kc as aa,Mg as ab,Xj as ac,ij as b,lw as c,ew as d,Zj as e,Wj as f,ea as g,os as h,qj as i,Vj as j,Yb as k,Vt as l,Jx as m,hl as n,$j as o,bx as p,Bv as q,ow as r,us as s,Hf as t,bc as u,_f as v,Jj as w,Qj as x,Vf as y,Ln as z};