@openchamber/web 1.23.2 → 1.24.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 (179) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-DdNGwbBw.js → CodeMirrorCommentWidgets-C9kV-n7r.js} +1 -1
  2. package/dist/assets/DiffView-B7YkbY-u.js +4 -0
  3. package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +1 -0
  4. package/dist/assets/FilesView-vjJx7VaM.js +13 -0
  5. package/dist/assets/GitView-BLhlMYEY.js +6 -0
  6. package/dist/assets/GuestAttachDialog-B-fwE8r3.js +3 -0
  7. package/dist/assets/{JsonTreeView-Chzx5Y6N.js → JsonTreeView-D_4G5X6-.js} +1 -1
  8. package/dist/assets/LinearIssuesView-1uKhePfH.js +1 -0
  9. package/dist/assets/{MarkdownImageGallery-CugnrZ6f.js → MarkdownImageGallery-Ix7N_2wp.js} +1 -1
  10. package/dist/assets/MarkdownRendererImpl-Deel_y5S.js +12 -0
  11. package/dist/assets/{OnboardingScreen-hH9xcTjA.js → OnboardingScreen-ToIakxb_.js} +1 -1
  12. package/dist/assets/{PatchDiff-DRgNYc9l.js → PatchDiff-BjMgezr1.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-ZT2CKuzJ.js → PierreDiffViewer-53Ghfnlr.js} +5 -5
  14. package/dist/assets/PlanView-BGAzxDwD.js +5 -0
  15. package/dist/assets/SettingsView-n2X-jfBB.js +29 -0
  16. package/dist/assets/SettingsWindow-Bi8LE9XI.js +1 -0
  17. package/dist/assets/SubmoduleDiffSummary--YFqK6Ih.js +1 -0
  18. package/dist/assets/ToolOutputDialog-DRWBvdaJ.js +15 -0
  19. package/dist/assets/{ToolPartDiffPreview-oWxWCu-4.js → ToolPartDiffPreview-BxZJCU28.js} +2 -2
  20. package/dist/assets/{VirtualizedFileDiff-CiyrAq_I.js → VirtualizedFileDiff-DCXjBGRf.js} +3 -3
  21. package/dist/assets/{WalkthroughView-CKTevaea.js → WalkthroughView-CfIPvWWa.js} +2 -2
  22. package/dist/assets/appThemeRegistry-DDROzcUO.js +1 -0
  23. package/dist/assets/{computeVirtualFileMetrics-SUWoTyPe.js → computeVirtualFileMetrics-DHgQIkUq.js} +1 -1
  24. package/dist/assets/de-CX_f-T5U.js +10 -0
  25. package/dist/assets/es-BERmWNn_.js +16 -0
  26. package/dist/assets/fr-BjYYE_-z.js +14 -0
  27. package/dist/assets/index-DpzTz2UH.css +1 -0
  28. package/dist/assets/index-Dy8xgawx.js +40 -0
  29. package/dist/assets/{index-C4jJ3Ur5.js → index-WjufPkIV.js} +1 -1
  30. package/dist/assets/{isDiffPlainText-DfG0cZxr.js → isDiffPlainText-D9faP70y.js} +1 -1
  31. package/dist/assets/{isFilePlainText-CyNivOCU.js → isFilePlainText-6qOcz5Ky.js} +1 -1
  32. package/dist/assets/ja-DxqeAk9N.js +16 -0
  33. package/dist/assets/ko-Dty1aUod.js +16 -0
  34. package/dist/assets/main-BOYSXfYn.js +896 -0
  35. package/dist/assets/{main-B8cGozKr.js → main-Bjcre_GE.js} +2 -2
  36. package/dist/assets/{markdown-shiki.worker-D5fBU-lw.js → markdown-shiki.worker-CahLvHIq.js} +5 -5
  37. package/dist/assets/{markdownCore-kyGrWGsn.js → markdownCore-DPrwM1rU.js} +5 -5
  38. package/dist/assets/{miniChat-Cay99IxR.js → miniChat-Dz_bPgMc.js} +2 -2
  39. package/dist/assets/{mobile-Zfhix7nz.js → mobile-BbZPBJrK.js} +2 -2
  40. package/dist/assets/{patchFileDiff-CJ5AN9Ql.js → patchFileDiff-BvU6KOQC.js} +3 -3
  41. package/dist/assets/pl-CX-_ROkr.js +16 -0
  42. package/dist/assets/{pt-BR-CLosVawq.js → pt-BR-DhRR1arx.js} +4 -4
  43. package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +2 -0
  44. package/dist/assets/renderMobileApp-BK1kFlcJ.js +25 -0
  45. package/dist/assets/runtimeEndpointReset-BULHvOwb.js +25 -0
  46. package/dist/assets/{scheduledTasksApi-CGFV4Pap.js → scheduledTasksApi-DW3xqMQ8.js} +1 -1
  47. package/dist/assets/shikiHighlight-DsxD9QEa.js +1 -0
  48. package/dist/assets/textMateThemeFromAppTheme-Da7ed8qM.js +1 -0
  49. package/dist/assets/tr-cIQtYBpg.js +7 -0
  50. package/dist/assets/uk-CD21CXFV.js +16 -0
  51. package/dist/assets/{useAppFontEffects-DgCHy6Mr.js → useAppFontEffects-hfv2s6mZ.js} +198 -147
  52. package/dist/assets/useInlineCommentController-BmtfVbo8.js +2 -0
  53. package/dist/assets/useRootScrollLock-Cwc4kSl2.js +1 -0
  54. package/dist/assets/{vendor-base-ui-BY_5qla_.js → vendor-base-ui-CsXYnR5c.js} +1 -1
  55. package/dist/assets/{vendor-codemirror-language-data-ES33GhKK.js → vendor-codemirror-language-data-BPMJpOpT.js} +2 -2
  56. package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +1 -0
  57. package/dist/assets/{vendor-motion-dom-D_o3BTI3.js → vendor-motion-dom-DcCgeG69.js} +1 -1
  58. package/dist/assets/vendor-strip-json-comments-5dJlOkP1.js +4 -0
  59. package/dist/assets/{vendor-zod-B6551dwG.js → vendor-zod-fZppILAM.js} +4 -4
  60. package/dist/assets/{web-components-CJZwV5BE.js → web-components-U-hWbgJo.js} +2 -2
  61. package/dist/assets/zh-CN-BWvlPHY-.js +16 -0
  62. package/dist/assets/zh-TW-CRp5dJU2.js +16 -0
  63. package/dist/index.html +4 -4
  64. package/dist/mini-chat.html +4 -4
  65. package/dist/mobile.html +4 -4
  66. package/package.json +7 -5
  67. package/server/built-in-extensions/registry.json +4 -0
  68. package/server/index.d.ts +2 -0
  69. package/server/index.js +15 -3
  70. package/server/lib/fs/DOCUMENTATION.md +8 -0
  71. package/server/lib/fs/git-process.test.js +77 -0
  72. package/server/lib/fs/routes.js +2 -1
  73. package/server/lib/fs/search.js +2 -1
  74. package/server/lib/git/DOCUMENTATION.md +3 -1
  75. package/server/lib/git/routes.js +16 -3
  76. package/server/lib/git/service.js +112 -8
  77. package/server/lib/git/service.test.js +127 -0
  78. package/server/lib/guests/DOCUMENTATION.md +66 -0
  79. package/server/lib/guests/auth-store.js +184 -0
  80. package/server/lib/guests/auth-store.test.js +112 -0
  81. package/server/lib/guests/builtins.js +34 -0
  82. package/server/lib/guests/builtins.test.js +174 -0
  83. package/server/lib/guests/catalog.js +466 -0
  84. package/server/lib/guests/catalog.test.js +390 -0
  85. package/server/lib/guests/clone.js +297 -0
  86. package/server/lib/guests/extract-zip.js +136 -0
  87. package/server/lib/guests/extract-zip.test.js +109 -0
  88. package/server/lib/guests/files.js +308 -0
  89. package/server/lib/guests/files.test.js +262 -0
  90. package/server/lib/guests/grant-scope.js +81 -0
  91. package/server/lib/guests/grant-scope.test.js +75 -0
  92. package/server/lib/guests/host-session.js +73 -0
  93. package/server/lib/guests/host-session.test.js +30 -0
  94. package/server/lib/guests/html-styles.js +6 -0
  95. package/server/lib/guests/html-styles.test.js +45 -0
  96. package/server/lib/guests/html-tokens.js +73 -0
  97. package/server/lib/guests/html-tokens.test.js +53 -0
  98. package/server/lib/guests/install.js +406 -0
  99. package/server/lib/guests/install.test.js +338 -0
  100. package/server/lib/guests/oauth.js +501 -0
  101. package/server/lib/guests/oauth.test.js +481 -0
  102. package/server/lib/guests/persist.js +336 -0
  103. package/server/lib/guests/persist.test.js +288 -0
  104. package/server/lib/guests/request.js +112 -0
  105. package/server/lib/guests/request.test.js +206 -0
  106. package/server/lib/guests/routes.js +838 -0
  107. package/server/lib/guests/service.js +538 -0
  108. package/server/lib/guests/service.test.js +277 -0
  109. package/server/lib/guests/sockets.js +129 -0
  110. package/server/lib/guests/sockets.test.js +110 -0
  111. package/server/lib/guests/ssh-install.test.js +188 -0
  112. package/server/lib/guests/storage.js +68 -0
  113. package/server/lib/guests/storage.test.js +59 -0
  114. package/server/lib/guests/updates.js +294 -0
  115. package/server/lib/guests/updates.test.js +334 -0
  116. package/server/lib/guests/upload.js +50 -0
  117. package/server/lib/guests/upload.test.js +131 -0
  118. package/server/lib/linear/DOCUMENTATION.md +1 -1
  119. package/server/lib/openchamber-control/DOCUMENTATION.md +6 -0
  120. package/server/lib/openchamber-sessions/routes.js +44 -11
  121. package/server/lib/openchamber-sessions/routes.test.js +47 -0
  122. package/server/lib/opencode/DOCUMENTATION.md +40 -0
  123. package/server/lib/opencode/core-routes.js +39 -1
  124. package/server/lib/opencode/feature-routes-runtime.js +10 -0
  125. package/server/lib/opencode/lifecycle-process.test.js +84 -0
  126. package/server/lib/opencode/lifecycle.js +54 -67
  127. package/server/lib/opencode/settings-normalization-runtime.js +2 -0
  128. package/server/lib/opencode/settings-normalization-runtime.test.js +13 -0
  129. package/server/lib/opencode/settings-registry.json +4 -0
  130. package/server/lib/opencode/shutdown-runtime.js +3 -0
  131. package/server/lib/opencode/shutdown-runtime.test.js +24 -0
  132. package/server/lib/opencode/theme-archive.js +53 -0
  133. package/server/lib/opencode/theme-catalog.js +171 -0
  134. package/server/lib/opencode/theme-catalog.test.js +125 -0
  135. package/server/lib/opencode/theme-import.test.js +144 -0
  136. package/server/lib/opencode/theme-runtime.js +100 -28
  137. package/server/lib/opencode/theme-runtime.test.js +15 -0
  138. package/server/lib/quota/DOCUMENTATION.md +0 -1
  139. package/server/lib/quota/providers/index.js +0 -7
  140. package/server/lib/terminal/DOCUMENTATION.md +2 -0
  141. package/server/lib/terminal/runtime.js +17 -2
  142. package/server/lib/terminal/runtime.test.js +45 -0
  143. package/server/lib/ui-auth/ui-auth.js +43 -8
  144. package/server/lib/ui-auth/ui-auth.test.js +40 -0
  145. package/dist/assets/DiffView-GYriC0Wk.js +0 -4
  146. package/dist/assets/DirtyBranchSwitchDialog-Bv0C99hc.js +0 -1
  147. package/dist/assets/FilesView-2Lin13wx.js +0 -13
  148. package/dist/assets/GitView-9wKba3UO.js +0 -6
  149. package/dist/assets/LinearIssuesView-DXS9QJiR.js +0 -1
  150. package/dist/assets/MarkdownRendererImpl-CaMyct2Q.js +0 -12
  151. package/dist/assets/PlanView-DiTBm2BD.js +0 -5
  152. package/dist/assets/SettingsView-CN8VeM99.js +0 -28
  153. package/dist/assets/SettingsWindow-DisOghhD.js +0 -1
  154. package/dist/assets/ToolOutputDialog-BqiKydxR.js +0 -15
  155. package/dist/assets/appThemeRegistry-BK0dHKa6.js +0 -1
  156. package/dist/assets/de-DQWC94VK.js +0 -10
  157. package/dist/assets/es-DixFUD3m.js +0 -16
  158. package/dist/assets/fr-D6u8tvfA.js +0 -14
  159. package/dist/assets/index-BvpFzhLs.js +0 -40
  160. package/dist/assets/index-n5p3SnES.css +0 -1
  161. package/dist/assets/ja-4u4pCorB.js +0 -16
  162. package/dist/assets/ko-C27-LW_b.js +0 -16
  163. package/dist/assets/main-tEA-fFPg.js +0 -930
  164. package/dist/assets/pl-FtCjsNdW.js +0 -16
  165. package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
  166. package/dist/assets/renderElectronMiniChatApp-CuHOGlF4.js +0 -2
  167. package/dist/assets/renderMobileApp-C4X_KUH8.js +0 -25
  168. package/dist/assets/runtimeEndpointReset-CMg-KUx3.js +0 -41
  169. package/dist/assets/shikiHighlight-DdKWYWrV.js +0 -1
  170. package/dist/assets/tr-D2j6wUez.js +0 -7
  171. package/dist/assets/uk-C6IzmwM_.js +0 -16
  172. package/dist/assets/useGitComparison-BIaI0WZI.js +0 -1
  173. package/dist/assets/useInlineCommentController-2wcCtpM3.js +0 -2
  174. package/dist/assets/useRootScrollLock-CbWA03xR.js +0 -1
  175. package/dist/assets/vendor-framer-motion-livSKyyV.js +0 -1
  176. package/dist/assets/zh-CN-Wl6tIDz1.js +0 -16
  177. package/dist/assets/zh-TW-hgphoWSN.js +0 -16
  178. package/server/lib/quota/providers/crof.js +0 -96
  179. package/server/lib/quota/providers/crof.test.js +0 -98
@@ -0,0 +1,29 @@
1
+ import{R as o,j as s,f as dt,r as Ye}from"./vendor-react-BUCujlKS.js";import{f as et,B as H,I as z,o as hn,bf as ua,t as M,O as sd,gB as nd,f2 as $e,gC as Ot,b as Xs,h as ye,au as ad,aq as fn,as as xn,at as id,ap as bn,eU as aa,gD as Wl,gE as rd,gF as Ia,gG as kn,c4 as ks,b_ as zt,b$ as Ut,c0 as $t,c1 as Bt,c2 as Vt,c3 as is,W as He,gH as si,bd as vn,eH as Tr,gI as od,gJ as Jn,f7 as Yt,gK as an,l as nt,fl as Ht,cf as Et,cg as Dt,fi as Gt,ch as _t,ci as Mt,cj as ut,gL as Kt,ck as Ms,e3 as Xa,fk as _n,fo as Da,fm as gn,gM as ys,e8 as ws,gN as Es,gO as ld,cP as mt,gP as Jl,gQ as cd,gR as ta,gS as Ql,gT as dd,g2 as Ma,g7 as Zs,gU as Pa,gV as Yl,gW as qr,e4 as Zl,gX as sa,a9 as Ra,a8 as Bs,gY as Xl,gZ as go,ae as ud,eF as ec,g as Aa,g_ as pd,g$ as rn,cc as yn,cn as jn,cd as wn,eE as md,h0 as gd,h1 as hd,h2 as Gr,aa as Wr,ab as Jr,ac as tc,h3 as Pn,a4 as zi,cs as Qr,S as La,h4 as ho,av as fd,cl as xd,d6 as bd,U as vd,T as yd,V as jd,Z as Yr,h5 as wd,h6 as kd,ca as Nd,cm as Er,h7 as sc,ad as Mi,fn as nc,P as Qn,h8 as nn,f1 as Vs,eN as ac,a3 as Sd,n as ls,ez as Ui,y as ic,x as Cd,i as Id,j as Pd,eA as Ad,p as Td,h9 as Ed,ha as Dd,hb as fo,e9 as rc,hc as Md,hd as cr,he as xo,hf as Rd,hg as Fd,hh as Od,hi as Ld,ef as _i,hj as js,hk as Ps,hl as sn,hm as Qs,dd as oc,bV as lc,de as cc,bW as Ys,hn as zn,ho as dc,aD as Un,aE as ja,hp as uc,hq as Kd,f0 as zd,e$ as Ud,hr as Dr,eM as _d,hs as Yn,ht as Us,hu as qs,f_ as Zn,hv as As,hw as $d,hx as bo,hy as pc,hz as Xn,hA as Bd,hB as Vd,R as Hd,hC as Kn,fh as Mn,hD as Fa,hE as vo,hF as wa,hG as ka,bX as ia,hH as qd,hI as Gd,hJ as Wd,hK as Jd,hL as dr,hM as yo,hN as Qd,hO as Yd,hP as Zd,hQ as Xd,hR as jo,z as eu,m as wo,dn as tu,hS as su,hT as ur,hU as ko,eC as nu,hV as Vi,hW as au,hX as iu,hY as ru,hZ as ou,h_ as lu,h$ as pr,cQ as cu,bY as mc,i0 as gc,i1 as du,ay as Rn,az as uu}from"./useAppFontEffects-hfv2s6mZ.js";import{h as xt,u as ce,O as ds,dh as pu,di as No,B as An,aF as Nn,t as yt,a1 as mu,E as cs,P as So,cw as Co,cD as Io,U as Ba,p as gu,dj as hu,k as fu,cv as Sa,dk as xu,ao as bu,cA as vu,dl as yu,dm as ju,s as wu,e as ni,cB as ku,F as ai,dn as hc,_ as Nu,dp as Su,a4 as fc,a as Oa,aE as zs,d7 as xc,a$ as bc,x as Ta,ai as Cu,aj as Iu,aK as Zr,dq as Pu,A as Hi,Z as Au,aP as Po,b3 as yi,aQ as Tu,dr as Eu,ad as na,ds as Du,dt as Ao,dg as To,du as Eo,aN as Do,dv as Mu,dw as Ru,dx as Fu,dy as Ou,dz as Mo,b as Lu,dA as vc,dB as Ku,dC as zu,dD as Uu,dE as _u,dF as $u,dG as Bu,az as Vu,i as yc}from"./index-Dy8xgawx.js";import{u as Hu,U as Ro,R as ra,W as oa,X as la,Y as ca,j as Xr,ab as ea,$ as qu,v as Ds,ac as Gu,a9 as Wu,ad as Ca,ae as jc,Z as Ju,_ as Qu}from"./runtimeEndpointReset-BULHvOwb.js";import{u as Hs,c as wc,d as Yu,p as Zu}from"./vendor-zustand-BAGL70zf.js";import{o as on,s as as,b as eo,_ as to,r as Mr,a as Rr,c as ii}from"./vendor-zod-fZppILAM.js";import{s as Xu,p as ep}from"./vendor-yaml-3778uTud.js";import{c as Fo,s as tp,C as Oo,P as sp}from"./shikiHighlight-DsxD9QEa.js";import{getResolvedShikiTheme as np}from"./appThemeRegistry-DDROzcUO.js";import{E as Lo}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as kc}from"./vendor-qrcode-DTJ12-WC.js";import{u as mr,s as ap,d as ip,b as rp,A as op,c as lp,e as cp,f as dp,h as up,i as gr,j as pp}from"./GuestAttachDialog-B-fwE8r3.js";import{toast as Ea}from"./vendor-sonner-DFyL3AvE.js";import{s as mp}from"./vendor-strip-json-comments-5dJlOkP1.js";const Ko=()=>{const{t}=et(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const u=await xt("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!u.ok)return;const c=await u.json().catch(()=>null);if(!c||i)return;const f=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,d=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:f,tunnelUrl:d})}catch{}})(),()=>{i=!0,r?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.openchamber.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.openchamber.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(i=>s.jsxs(H,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{hn(i.url)},children:[s.jsx(z,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:i.url})]},i.key))})},zo="https://github.com/openchamber/openchamber",gp="https://discord.gg/ZYRSdnwwKA",Uo="https://x.com/openchamber_dev",hp=800,Nc=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=et(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,u]=o.useState(null),[c,f]=o.useState(null),d=Hu(Hs(w=>({info:w.info,checking:w.checking,available:w.available,error:w.error,downloading:w.downloading,downloaded:w.downloaded,progress:w.progress,runtimeType:w.runtimeType,checkForUpdates:w.checkForUpdates,downloadUpdate:w.downloadUpdate,restartToUpdate:w.restartToUpdate}))),{isMobile:v}=ua(),p=l||d.info?.currentVersion||"unknown";o.useEffect(()=>{let w=!1;return(async()=>{try{const k=await xt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)return;const m=await k.json().catch(()=>null),I=typeof m?.openchamberVersion=="string"&&m.openchamberVersion.trim().length>0?m.openchamberVersion.trim():null;w||u(I)}catch{w||u(null)}})(),()=>{w=!0}},[]),o.useEffect(()=>{let w=!1;return(async()=>{try{const k=await xt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)return;const m=await k.json().catch(()=>null),I=typeof m?.currentVersion=="string"&&m.currentVersion.trim().length>0?m.currentVersion.trim():null;w||f(I)}catch{w||f(null)}})(),()=>{w=!0}},[]);const j=o.useRef(!1);o.useEffect(()=>{if(d.checking)r(!0),j.current=!0;else if(i){const w=setTimeout(()=>{r(!1),j.current&&!d.available&&!d.error&&(M.success(e("settings.openchamber.about.toast.latestVersion")),j.current=!1)},hp);return()=>clearTimeout(w)}},[e,d.checking,i,d.available,d.error]);const h=d.checking||i;return v?s.jsxs("div",{className:"w-full space-y-6 pb-2",children:[s.jsxs("div",{className:"flex flex-col items-center text-center",children:[s.jsx(sd,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${nd}`,children:"OpenChamber"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:p})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(Ko,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!d.available&&!d.error&&s.jsxs(H,{type:"button",variant:"outline",size:"sm",onClick:()=>d.checkForUpdates(),disabled:h,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[h?s.jsx(z,{name:"loader",className:"size-4 animate-spin"}):s.jsx(z,{name:"refresh",className:"size-4"}),e(h?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!h&&d.available&&s.jsxs(H,{type:"button",variant:"default",size:"sm",onClick:()=>n(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(z,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:d.info?.version||""})]})]}),d.error&&s.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:d.error}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href:zo,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:gp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:Uo,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(Ro,{open:a,onOpenChange:n,info:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]}):s.jsxs($e,{divider:!1,children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center justify-between gap-4 px-4 py-3 border-b border-border/40",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Ot,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:p})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Ot,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[d.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(z,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!d.checking&&d.available&&s.jsxs(H,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(z,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:d.info?.version||""})]}),!d.checking&&!d.available&&!d.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>d.checkForUpdates(),disabled:d.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),d.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:d.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Ot,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(Ko,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:zo,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(z,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Uo,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(z,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(Ro,{open:a,onOpenChange:n,info:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]})},fp=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,Gs=()=>{const t=dt.c(4),e=ce(xp),a=Xs(bp),n=Xs(vp);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=fp(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function xp(t){return t.settingsProjectPath}function bp(t){return t.projects}function vp(t){return t.activeProjectId}const Sc=t=>t.trim(),ri=t=>{const e=dt.c(40),{className:a}=t,{t:n}=et(),i=Xs(yp),r=Gs(),l=ce(jp),u=ds();let c;e[0]!==i?(c=[...i].sort(wp),e[0]=i,e[1]=c):c=e[1];const f=c;let d;e:{if(f.length===0){d=null;break e}let _;e[2]!==r||e[3]!==f?(_=f.find(C=>C.path===r)??f[0],e[2]=r,e[3]=f,e[4]=_):_=e[4],d=_}const v=d;if(u||f.length===0)return null;let p;e[5]!==v||e[6]!==n?(p=v?.label&&v.label.trim().length>0?v.label:v?.path.split("/").filter(Boolean).pop()||v?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=v,e[6]=n,e[7]=p):p=e[7];const j=p;let h;e[8]!==j?(h=Sc(j),e[8]=j,e[9]=h):h=e[9];const w=h;let b;e[10]!==a?(b=ye(a),e[10]=a,e[11]=b):b=e[11];let k;e[12]!==n?(k=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=k):k=e[13];let m;e[14]!==n?(m=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=m):m=e[15];let I,E;e[16]===Symbol.for("react.memo_cache_sentinel")?(I=ye("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-ring focus-visible:border-interactive-border-focus","flex items-center gap-1.5 text-left"),E=s.jsx(z,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=I,e[17]=E):(I=e[16],E=e[17]);let A;e[18]!==w?(A=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:w}),e[18]=w,e[19]=A):A=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(z,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=N):N=e[20];let x;e[21]!==A||e[22]!==k||e[23]!==m?(x=s.jsx(fn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":k,title:m,className:I,children:[E,A,N]})}),e[21]=A,e[22]=k,e[23]=m,e[24]=x):x=e[24];const y=v?.id??"";let F;e[25]!==l||e[26]!==f?(F=_=>{if(!_)return;const C=f.find(R=>R.id===_);C&&l(C.path)},e[25]=l,e[26]=f,e[27]=F):F=e[27];let T;e[28]!==f?(T=f.map(kp),e[28]=f,e[29]=T):T=e[29];let P;e[30]!==y||e[31]!==F||e[32]!==T?(P=s.jsx(xn,{align:"start",className:"w-auto",children:s.jsx(id,{value:y,onValueChange:F,children:T})}),e[30]=y,e[31]=F,e[32]=T,e[33]=P):P=e[33];let D;e[34]!==x||e[35]!==P?(D=s.jsxs(bn,{children:[x,P]}),e[34]=x,e[35]=P,e[36]=D):D=e[36];let $;return e[37]!==D||e[38]!==b?($=s.jsx("div",{className:b,children:D}),e[37]=D,e[38]=b,e[39]=$):$=e[39],$};function yp(t){return t.projects}function jp(t){return t.setSettingsProjectPath}function wp(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function kp(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Sc(e);return s.jsx(ad,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function Np(t,e){return`opencode:sidebar-group:${t}:${e}`}const Fr=t=>{const e=dt.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,u=r===void 0?!0:r;let c;e[0]!==a||e[1]!==i?(c=Np(i,a),e[0]=a,e[1]=i,e[2]=c):c=e[2];const f=c,d=o.useId();let v;e[3]!==u||e[4]!==f?(v=()=>{try{const P=localStorage.getItem(f);if(P!==null)return P==="true"}catch{}return u},e[3]=u,e[4]=f,e[5]=v):v=e[5];const[p,j]=Ye.useState(v);let h,w;e[6]!==p||e[7]!==f?(h=()=>{try{localStorage.setItem(f,String(p))}catch{}},w=[f,p],e[6]=p,e[7]=f,e[8]=h,e[9]=w):(h=e[8],w=e[9]),Ye.useEffect(h,w);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>j(Sp),e[10]=b):b=e[10];let k;e[11]===Symbol.for("react.memo_cache_sentinel")?(k=ye("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-ring"),e[11]=k):k=e[11];const m=!p&&"-rotate-90";let I;e[12]!==m?(I=ye("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",m),e[12]=m,e[13]=I):I=e[13];let E;e[14]!==I?(E=s.jsx(z,{name:"arrow-down-s",className:I}),e[14]=I,e[15]=E):E=e[15];let A;e[16]!==a?(A=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=A):A=e[17];let N;e[18]!==n?(N=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=N):N=e[19];let x;e[20]!==d||e[21]!==p||e[22]!==E||e[23]!==A||e[24]!==N?(x=s.jsxs("button",{type:"button",onClick:b,"aria-expanded":p,"aria-controls":d,className:k,children:[E,A,N]}),e[20]=d,e[21]=p,e[22]=E,e[23]=A,e[24]=N,e[25]=x):x=e[25];const y=!p;let F;e[26]!==l||e[27]!==d||e[28]!==y?(F=s.jsx("div",{id:d,hidden:y,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]=d,e[28]=y,e[29]=F):F=e[29];let T;return e[30]!==x||e[31]!==F?(T=s.jsxs("div",{children:[x,F]}),e[30]=x,e[31]=F,e[32]=T):T=e[32],T};function Sp(t){return!t}const Cp=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!a||typeof a!="object")continue;const n=a;typeof n.permission!="string"||typeof n.pattern!="string"||typeof n.action!="string"||n.action!=="allow"&&n.action!=="ask"&&n.action!=="deny"||e.push({permission:n.permission,pattern:n.pattern,action:n.action})}return e},Ip=t=>{const e=new Map;for(const a of t)!a.permission||a.permission==="invalid"||a.pattern&&e.set(`${a.permission}::${a.pattern}`,a);return Array.from(e.values())},_o=t=>{const e=Ip(Cp(t));if(e.length===0)return;const a={};for(const i of e)i.permission&&((a[i.permission]||={})[i.pattern]=i.action);const n={};for(const[i,r]of Object.entries(a)){const l=Object.keys(r);if(l.length===1&&l[0]==="*"){n[i]=r["*"];continue}n[i]=r}return Object.keys(n).length>0?n:void 0},Pp=({onItemSelect:t})=>{const{t:e}=et(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,u]=o.useState(null),[c,f]=o.useState(null),[d,v]=o.useState(!1),[p,j]=o.useState(null),{selectedAgentName:h,setSelectedAgent:w,setAgentDraft:b,createAgent:k,deleteAgent:m,loadAgents:I}=aa(Hs(O=>({selectedAgentName:O.selectedAgentName,setSelectedAgent:O.setSelectedAgent,setAgentDraft:O.setAgentDraft,createAgent:O.createAgent,deleteAgent:O.deleteAgent,loadAgents:O.loadAgents}))),E=Gs(),A=aa(O=>Wl(O,E));o.useEffect(()=>{I(E)},[I,E]);const N="bg-background",x=()=>{const O="new-agent";let ie=O,K=1;for(;A.some(q=>q.name===ie);)ie=`${O}-${K}`,K++;b({name:ie,scope:"user"}),w(ie),t?.()},y=async O=>{if(Ia(O)){M.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}u(O),f("delete")},F=async O=>{Ia(O)&&(u(O),f("reset"))},T=()=>{u(null),f(null)},P=async()=>{if(!(!l||!c)){v(!0);try{const O=await m(l.name,l.scope,E);O.ok?(O.requiresManualRestart?M.warning(e("settings.agents.page.toast.savedManualRestart")):O.restartDeferred?M.success(e("settings.view.pendingRestart.saved")):c==="delete"?M.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):M.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),T()):c==="delete"?M.error(e("settings.agents.sidebar.toast.deleteFailed")):M.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(O){const ie=O instanceof Error?O.message:"",K=/built-in|not deletable|not found/i.test(ie);c==="delete"?M.error(e(K?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):M.error(e("settings.agents.sidebar.toast.resetFailed"))}v(!1)}},D=O=>{const ie=O.name;let K=1,q=`${ie}-copy`;for(;A.some(G=>G.name===q);)K++,q=`${ie}-copy-${K}`;const B=O,L=O.model?.providerID&&O.model?.modelID?`${O.model.providerID}/${O.model.modelID}`:null,X=O;b({name:q,scope:B.scope||"user",description:O.description,model:L,variant:O.variant,temperature:O.temperature,top_p:O.topP,prompt:O.prompt,mode:O.mode,permission:_o(O.permission),disable:X.disable}),w(q),t?.()},$=O=>{r(O.name),n(O)},_=async()=>{if(!a)return;const O=i.trim().replace(/\s+/g,"-");if(!O){M.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(O===a.name){n(null);return}if(A.some(B=>B.name===O)){M.error(e("settings.agents.sidebar.toast.agentExists"));return}const ie=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,K=a,q=await k({name:O,description:a.description,model:ie,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:_o(a.permission),disable:K.disable,scope:K.scope},E);if(q.ok){const B=await m(a.name,K.scope,E);B.ok?(q.requiresManualRestart||B.requiresManualRestart?M.warning(e("settings.agents.page.toast.savedManualRestart")):M.success(e("settings.agents.sidebar.toast.agentRenamed",{name:O})),w(O)):M.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else M.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},C=O=>{switch(O){case"primary":return s.jsx(z,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(z,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(z,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},R=A.filter(O=>!rd(O)),V=R.filter(Ia),U=R.filter(O=>!Ia(O)),{groupedCustomAgents:W,ungroupedCustomAgents:te}=Ye.useMemo(()=>{const O={},ie=[];for(const q of U){const B=q;B.group?(O[B.group]||(O[B.group]=[]),O[B.group].push(q)):ie.push(q)}return{groupedCustomAgents:Object.keys(O).sort((q,B)=>q.localeCompare(B)).map(q=>({name:q,agents:O[q]})),ungroupedCustomAgents:ie}},[U]);return s.jsxs("div",{className:ye("flex h-full flex-col",N),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${kn} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(ri,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:R.length})}),s.jsx(H,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:x,children:s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:R.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[V.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),V.map(O=>s.jsx(hr,{agent:O,isSelected:h===O.name,onSelect:()=>{w(O.name),t?.()},onReset:()=>F(O),onDuplicate:()=>D(O),getAgentModeIcon:C,isMenuOpen:p===O.name,onMenuOpenChange:ie=>j(ie?O.name:null)},O.name))]}),U.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),W.map(({name:O,agents:ie})=>s.jsx(Fr,{label:O,count:ie.length,storageKey:"agents",children:ie.map(K=>s.jsx(hr,{agent:K,isSelected:h===K.name,onSelect:()=>{w(K.name),t?.()},onRename:()=>$(K),onDelete:()=>y(K),onDuplicate:()=>D(K),getAgentModeIcon:C,isMenuOpen:p===K.name,onMenuOpenChange:q=>j(q?K.name:null)},K.name))},O)),te.map(O=>s.jsx(hr,{agent:O,isSelected:h===O.name,onSelect:()=>{w(O.name),t?.()},onRename:()=>$(O),onDelete:()=>y(O),onDuplicate:()=>D(O),getAgentModeIcon:C,isMenuOpen:p===O.name,onMenuOpenChange:ie=>j(ie?O.name:null)},O.name))]})]})}),s.jsx(zt,{open:l!==null&&c!==null,onOpenChange:O=>{!O&&!d&&T()},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Vt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:T,disabled:d,children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:P,disabled:d,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(zt,{open:a!==null,onOpenChange:O=>!O&&n(null),children:s.jsxs(Ut,{children:[s.jsxs($t,{children:[s.jsx(Bt,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(He,{value:i,onChange:O=>r(O.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:O=>{O.key==="Enter"&&_()}}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:_,children:e("settings.common.actions.rename")})]})]})})]})},hr=t=>{const e=dt.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:u,onDuplicate:c,getAgentModeIcon:f,isMenuOpen:d,onMenuOpenChange:v}=t,{t:p}=et(),j=a;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=si(),e[0]=h):h=e[0];const w=h,[b,k]=o.useState(!1);let m;e[1]!==r||e[2]!==c||e[3]!==u||e[4]!==l||e[5]!==p?(m=ie=>s.jsxs(s.Fragment,{children:[u&&s.jsxs(ie,{onClick:K=>{K.stopPropagation(),u()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),s.jsxs(ie,{onClick:K=>{K.stopPropagation(),c()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),l&&s.jsxs(ie,{onClick:K=>{K.stopPropagation(),l()},children:[s.jsx(z,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),r&&s.jsxs(ie,{onClick:K=>{K.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[1]=r,e[2]=c,e[3]=u,e[4]=l,e[5]=p,e[6]=m):m=e[6];const I=m,E=n?"bg-interactive-selection":"hover:bg-interactive-hover";let A;e[7]!==E?(A=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",E),e[7]=E,e[8]=A):A=e[8];let N;e[9]===Symbol.for("react.memo_cache_sentinel")?(N=w?void 0:ie=>{ie.preventDefault(),k(!0)},e[9]=N):N=e[9];let x;e[10]!==A?(x=s.jsx("div",{className:A,onContextMenu:N}),e[10]=A,e[11]=x):x=e[11];let y;e[12]!==a.name?(y=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=y):y=e[13];let F;e[14]!==a.mode||e[15]!==f?(F=f(a.mode),e[14]=a.mode,e[15]=f,e[16]=F):F=e[16];let T;e[17]!==a||e[18]!==j.scope||e[19]!==p?(T=(j.scope||Ia(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Ia(a)?p("settings.agents.sidebar.badge.system"):j.scope}),e[17]=a,e[18]=j.scope,e[19]=p,e[20]=T):T=e[20];let P;e[21]!==y||e[22]!==F||e[23]!==T?(P=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,F,T]}),e[21]=y,e[22]=F,e[23]=T,e[24]=P):P=e[24];let D;e[25]!==a.description?(D=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=D):D=e[26];let $;e[27]!==i||e[28]!==P||e[29]!==D?($=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[P,D]}),e[27]=i,e[28]=P,e[29]=D,e[30]=$):$=e[30];let _;e[31]!==v?(_=ie=>{ie&&k(!1),v(ie)},e[31]=v,e[32]=_):_=e[32];let C;e[33]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(fn,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=C):C=e[33];let R;e[34]!==I?(R=s.jsx(xn,{align:"end",className:"w-fit min-w-20",children:I(vn)}),e[34]=I,e[35]=R):R=e[35];let V;e[36]!==d||e[37]!==_||e[38]!==R?(V=s.jsxs(bn,{open:d,onOpenChange:_,children:[C,R]}),e[36]=d,e[37]=_,e[38]=R,e[39]=V):V=e[39];let U;e[40]!==$||e[41]!==V?(U=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[$,V]}),e[40]=$,e[41]=V,e[42]=U):U=e[42];let W;e[43]!==U||e[44]!==x?(W=s.jsx(la,{render:x,children:U}),e[43]=U,e[44]=x,e[45]=W):W=e[45];let te;e[46]!==I?(te=s.jsx(ra,{className:"w-fit min-w-20",children:I(oa)}),e[46]=I,e[47]=te):te=e[47];let O;return e[48]!==b||e[49]!==W||e[50]!==te?(O=s.jsxs(ca,{open:b,onOpenChange:k,children:[W,te]}),e[48]=b,e[49]=W,e[50]=te,e[51]=O):O=e[51],O},os=t=>{const e=dt.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:u,description:c,headerEnd:f,showSaveStatus:d}=t,v=d===void 0?!1:d,p=r!=null||c!=null||f!=null||v,j=typeof r=="string"||typeof r=="number",h=l!=null||u!=null;let w;e[0]!==i?(w=ye("h-full",i),e[0]=i,e[1]=w):w=e[1];let b;e[2]!==n?(b=ye("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=b):b=e[3];let k;e[4]!==c||e[5]!==p||e[6]!==h||e[7]!==f||e[8]!==j||e[9]!==v||e[10]!==r||e[11]!==u||e[12]!==l?(k=p&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[r!=null?j?h?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:ye(Tr,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:u})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Tr,children:r}):r:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:od,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[f,v&&s.jsx(Tp,{})]})]}),e[4]=c,e[5]=p,e[6]=h,e[7]=f,e[8]=j,e[9]=v,e[10]=r,e[11]=u,e[12]=l,e[13]=k):k=e[13];let m;e[14]!==a||e[15]!==b||e[16]!==k?(m=s.jsxs("div",{className:b,children:[k,a]}),e[14]=a,e[15]=b,e[16]=k,e[17]=m):m=e[17];let I;return e[18]!==w||e[19]!==m?(I=s.jsx(ks,{outerClassName:w,className:"w-full @container",children:m}),e[18]=w,e[19]=m,e[20]=I):I=e[20],I},Ap=500,Tp=()=>{const t=dt.c(13),{t:e}=et(),a=o.useSyncExternalStore(pu,No,No),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const d=setTimeout(()=>i(!0),Ap);return()=>clearTimeout(d)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let d;t[3]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(z,{name:"error-warning",className:"size-3.5"}),t[3]=d):d=t[3];let v;t[4]!==e?(v=e("settings.common.status.saveFailed"),t[4]=e,t[5]=v):v=t[5];let p;return t[6]!==v?(p=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[d,s.jsx("span",{children:v})]}),t[6]=v,t[7]=p):p=t[7],p}if(a!=="saving"||!n)return null;let u;t[8]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=u):u=t[8];let c;t[9]!==e?(c=e("settings.common.actions.saving"),t[9]=e,t[10]=c):c=t[10];let f;return t[11]!==c?(f=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[u,s.jsx("span",{children:c})]}),t[11]=c,t[12]=f):f=t[12],f},Ep=["allow","ask","deny"],Za=t=>t==="allow"||t==="ask"||t==="deny",Or=()=>({global:null,keys:{}}),Dp=t=>{const e=Or();if(t==null)return e;if(typeof t=="string")return Za(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Za(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(Za(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))Za(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},Lr=t=>{const e={};t.global!==null&&(e["*"]=t.global);for(const[a,n]of Object.entries(t.keys)){const i=n.patterns.filter(r=>r.pattern.trim().length>0);if(n.action!==null&&i.length===0)e[a]=n.action;else if(i.length>0){const r={};n.action!==null&&(r["*"]=n.action);for(const l of i)r[l.pattern]=l.action;e[a]=r}}return Object.keys(e).length>0?e:null},Mp=(t,e)=>JSON.stringify(Lr(t))===JSON.stringify(Lr(e)),Fn=t=>JSON.parse(JSON.stringify(t)),Rp=["edit","external_directory","doom_loop","plan_enter","plan_exit"],Fp=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),$o=new Set(["write","patch","apply_patch","multiedit","invalid"]),Op=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Lp=({agent:t})=>{const{t:e}=et(),a=aa(B=>B.updateAgent),[n,i]=o.useState(Or),[r,l]=o.useState(Or),[u,c]=o.useState(!0),[f,d]=o.useState(!1),[v,p]=o.useState(!1),[j,h]=o.useState({}),[w,b]=o.useState([]),[k,m]=o.useState(""),[I,E]=o.useState(0),A=t.name,N=Gs();o.useEffect(()=>{let B=!1;return c(!0),d(!1),(async()=>{try{const L=N,X=L?`?directory=${encodeURIComponent(L)}`:"",G=await xt(`/api/config/agents/${encodeURIComponent(A)}/config${X}`,{headers:{"Cache-Control":"no-cache",...L?{"x-opencode-directory":L}:{}}});if(!G.ok)throw new Error(String(G.status));const Z=await G.json().catch(()=>null);if(B)return;const le=Dp(Z?.config?.permission);i(Fn(le)),l(le)}catch{B||d(!0)}finally{B||c(!1)}})(),()=>{B=!0}},[A,I,N]),o.useEffect(()=>{let B=!1;return(async()=>{try{const L=await An.listToolIds({directory:N});!B&&Array.isArray(L)&&b(L.filter(X=>typeof X=="string"&&!$o.has(X)))}catch{}})(),()=>{B=!0}},[A,N]);const x=o.useMemo(()=>{const B=t.permission;if(!Array.isArray(B))return[];const L=[];for(const X of B){if(!X||typeof X!="object")continue;const{permission:G,pattern:Z,action:le}=X;typeof G=="string"&&typeof Z=="string"&&Za(le)&&L.push({permission:G,pattern:Z,action:le})}return L},[t]),y=o.useCallback(B=>{const L=x.find(G=>G.permission===B&&G.pattern==="*");if(L)return L.action;const X=x.find(G=>G.permission==="*"&&G.pattern==="*");return X?X.action:null},[x]),F=o.useCallback(B=>{const L=r.keys[B]?.patterns??[],X=new Set(L.map(G=>G.pattern));return x.filter(G=>G.permission===B&&G.pattern!=="*"&&!X.has(G.pattern))},[x,r.keys]),T=o.useMemo(()=>{const B=new Set;for(const L of w)B.add(L);for(const L of Rp)B.add(L);for(const L of Object.keys(r.keys))B.add(L);for(const L of $o)B.delete(L);return Array.from(B).sort((L,X)=>L.localeCompare(X))},[w,r.keys]),P=o.useMemo(()=>!Mp(r,n),[r,n]),D=B=>{l(L=>({...L,global:B}))},$=(B,L)=>{l(X=>{const G=Fn(X),Z=G.keys[B]??{action:null,patterns:[]};return Z.action=L,Z.action===null&&Z.patterns.length===0?delete G.keys[B]:G.keys[B]=Z,G})},_=(B,L,X,G)=>{l(Z=>{const le=Fn(Z),oe=le.keys[B]??{action:null,patterns:[]};return oe.patterns[L]={pattern:X,action:G},le.keys[B]=oe,le})},C=B=>{l(L=>{const X=Fn(L),G=X.keys[B]??{action:null,patterns:[]};return G.patterns.push({pattern:"",action:"allow"}),X.keys[B]=G,X}),h(L=>({...L,[B]:!0}))},R=(B,L)=>{l(X=>{const G=Fn(X),Z=G.keys[B];return Z?(Z.patterns.splice(L,1),Z.action===null&&Z.patterns.length===0&&delete G.keys[B],G):X})},V=()=>{const B=k.trim();!B||B==="*"||(l(L=>{if(L.keys[B])return L;const X=Fn(L);return X.keys[B]={action:"ask",patterns:[]},X}),h(L=>({...L,[B]:!0})),m(""))},U=async()=>{p(!0);try{const B=Lr(r),L=await a(A,{permission:B});L.ok?(i(Fn(r)),M.success(L.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):M.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{p(!1)}},W=()=>{l(Fn(n))},te=B=>e(B==="allow"?"settings.agents.page.permissionsEditor.action.allow":B==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),O=e("settings.agents.page.permissionsEditor.action.inherit"),ie=e("settings.agents.page.permissionsEditor.action.default"),K=B=>[...B?[{value:"inherit",label:B}]:[],...Ep.map(L=>({value:L,label:te(L)}))],q=(B,L,X,G=O)=>s.jsx(an,{value:B??"inherit",options:K(G),onChange:Z=>L(Z==="inherit"?null:Z),"aria-label":X});return u?s.jsx($e,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:Jn,children:e("common.loading")})}):f?s.jsx($e,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.agents.page.permissionsEditor.state.loadFailed")}),s.jsx(H,{variant:"outline",size:"xs",onClick:()=>E(B=>B+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs($e,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:P?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:W,disabled:v,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(H,{size:"xs",className:"!font-normal",onClick:()=>{U()},disabled:v,children:e(v?"settings.common.actions.saving":"settings.agents.page.permissionsEditor.actions.save")})]}):void 0,contentClassName:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Ot,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Yt,{children:e("settings.agents.page.permissionsEditor.defaultInfo")}),r.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:te(y("*")??"allow")})})]}),q(r.global,D,e("settings.agents.page.permissionsEditor.defaultAria"),ie)]}),s.jsx("div",{children:T.map(B=>{const L=r.keys[B]??{action:null,patterns:[]},X=F(B),G=Fp.has(B)||L.patterns.length>0,Z=G||X.length>0,le=j[B]===!0,oe=y(B);return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:Z?()=>h(he=>({...he,[B]:!le})):void 0,className:ye("flex min-w-0 items-center gap-1.5 text-left",!Z&&"cursor-default"),"aria-expanded":Z?le:void 0,children:[s.jsx(z,{name:le&&Z?"arrow-down-s":"arrow-right-s",className:ye("h-3.5 w-3.5 shrink-0 text-muted-foreground",!Z&&"opacity-0")}),s.jsx("span",{className:Ot,children:Op(B)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:B}),L.action===null&&oe!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:te(oe)})}),L.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:e("settings.agents.page.permissionsEditor.ruleCount",{count:String(L.patterns.length)})})]}),q(L.action,he=>$(B,he),e("settings.agents.page.permissionsEditor.keyAria",{key:B}))]}),le&&Z&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[L.patterns.map((he,ee)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(He,{value:he.pattern,onChange:re=>_(B,ee,re.target.value,he.action),placeholder:e("settings.agents.page.permissionsEditor.patternPlaceholder"),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(an,{value:he.action,options:K(),onChange:re=>_(B,ee,he.pattern,re),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:B})}),s.jsx(H,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>R(B,ee),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]},ee)),G&&s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>C(B),children:[s.jsx(z,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),X.length>0&&s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-micro font-medium text-muted-foreground",children:e("settings.agents.page.permissionsEditor.sessionRulesTitle")}),s.jsx(Yt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),X.map(he=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro min-w-0 flex-1 truncate font-mono text-muted-foreground/70",children:he.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:te(he.action)})]},`${he.pattern}-${he.action}`))]})]})]},B)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(He,{value:k,onChange:B=>m(B.target.value),onKeyDown:B=>{B.key==="Enter"&&(B.preventDefault(),V())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:V,disabled:!k.trim(),children:[s.jsx(z,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},Kp=(t,e)=>{const a=Da(e);if(!a)return[];const i=t.find(r=>r.id===a.providerId)?.models?.find(r=>r.id===a.modelId);return i?.variants?Object.keys(i.variants):[]},zp=()=>{const{t}=et(),e=nt(q=>q.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agentDraft:l,setAgentDraft:u}=aa(Hs(q=>({selectedAgentName:q.selectedAgentName,getAgentByName:q.getAgentByName,createAgent:q.createAgent,updateAgent:q.updateAgent,agentDraft:q.agentDraft,setAgentDraft:q.setAgentDraft}))),c=Gs(),f=aa(q=>Wl(q,c)),d=a?n(a,c):null,v=!!(l&&l.name===a&&!d),[p,j]=o.useState(""),[h,w]=o.useState("user"),[b,k]=o.useState(""),[m,I]=o.useState("subagent"),[E,A]=o.useState(""),[N,x]=o.useState(""),[y,F]=o.useState(void 0),[T,P]=o.useState(void 0),[D,$]=o.useState(""),[_,C]=o.useState(!1),R=o.useRef(null),V=o.useMemo(()=>Kp(e,E),[E,e]),U=V.length>0,W=N||"__default",te=U,O=o.useMemo(()=>N&&!V.includes(N)?[N,...V]:V,[N,V]);o.useEffect(()=>{if(v&&l){const q=l.name||"",B=l.scope||"user",L=l.description||"",X=l.mode||"subagent",G=l.model||"",Z=l.variant||"",le=l.temperature??void 0,oe=l.top_p??void 0,he=l.prompt||"";j(q),w(B),k(L),I(X),A(G),x(Z),F(le),P(oe),$(he),R.current={draftName:q,draftScope:B,description:L,mode:X,model:G,variant:Z,temperature:le,topP:oe,prompt:he};return}if(d&&a===d.name){const q=d.description||"",B=d.mode||"subagent",L=d.model?.providerID&&d.model?.modelID?`${d.model.providerID}/${d.model.modelID}`:"",X=d.variant||"",G=d.temperature??void 0,Z=d.topP??void 0,le=d.prompt||"";k(q),I(B),A(L),x(X),F(G),P(Z),$(le),R.current={draftName:"",draftScope:"user",description:q,mode:B,model:L,variant:X,temperature:G,topP:Z,prompt:le}}},[l,v,d,a]);const ie=o.useMemo(()=>{const q=R.current;return q?!!(v&&(p!==q.draftName||h!==q.draftScope)||b!==q.description||m!==q.mode||E!==q.model||N!==q.variant||y!==q.temperature||T!==q.topP||D!==q.prompt):!1},[b,p,h,v,m,E,D,y,T,N]),K=async()=>{const q=v?p.trim().replace(/\s+/g,"-"):a?.trim();if(!q){M.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(v&&f.some(B=>B.name===q)){M.error(t("settings.agents.sidebar.toast.agentExists"));return}C(!0);try{const B=E.trim(),L=N.trim(),X=D.trim(),G={name:q,...b.trim()?{description:b.trim()}:{},mode:m,model:B===""?null:B,variant:L===""?null:L||void 0,temperature:y??null,top_p:T??null,prompt:X||(v?void 0:null),...v&&h?{scope:h}:{}};let Z;v?(Z=await i(G,c),Z.ok&&u(null)):Z=await r(q,G,c),Z.ok?Z.requiresManualRestart?M.warning(t("settings.agents.page.toast.savedManualRestart")):Z.restartDeferred?M.success(t("settings.view.pendingRestart.saved")):M.success(t(v?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):M.error(t(v?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(B){console.error("Error saving agent:",B);const L=B instanceof Error&&B.message?B.message:t("settings.agents.page.toast.saveUnexpectedError");M.error(L)}finally{C(!1)}};return a?s.jsxs(os,{title:v?t("settings.agents.page.title.new"):a,description:t(v?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs($e,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[v&&s.jsxs(Ht,{settingsItem:"agents.name",label:t("settings.agents.page.field.agentName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(He,{value:p,onChange:q=>j(q.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Et,{value:h,onValueChange:q=>w(q),children:[s.jsx(Dt,{size:Gt,className:"w-fit min-w-[100px]",children:s.jsx(_t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Mt,{align:"end",children:[s.jsx(ut,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ut,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Kt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Ms,{value:b,onChange:q=>k(q.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Kt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(an,{"aria-label":t("settings.agents.page.field.mode"),value:m,onChange:I,options:[{value:"primary",label:t("settings.agents.page.mode.primary")},{value:"subagent",label:t("settings.agents.page.mode.subagent")},{value:"all",label:t("settings.agents.page.mode.all")}]})})]}),s.jsxs($e,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Ht,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Xa,{providerId:Da(E)?.providerId??"",modelId:Da(E)?.modelId??"",onChange:(q,B)=>{A(q&&B?`${q}/${B}`:""),x("")},className:_n})}),s.jsx(Ht,{settingsItem:"agents.variant",label:t("settings.agents.page.field.variant"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.variantTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.variantHint")})]}),children:te?s.jsxs(Et,{value:W,onValueChange:q=>x(q==="__default"?"":q),children:[s.jsx(Dt,{size:Gt,className:gn,children:s.jsx(_t,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:q=>q==="__default"?t("chat.modelControls.default"):q})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:"__default",children:t("chat.modelControls.default")}),O.map(q=>s.jsx(ut,{value:q,children:q},q))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(He,{value:N,onChange:q=>x(q.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!E&&!N,className:"h-8 w-40 rounded-md px-3"}),N&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>x(""),className:ys,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Ht,{settingsItem:"agents.temperature",label:t("settings.agents.page.field.temperature"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.temperatureTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.temperatureRange")})]}),children:[s.jsx(ws,{value:y,fallbackValue:.7,onValueChange:F,onClear:()=>F(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Es}),y!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(void 0),className:ys,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Ht,{settingsItem:"agents.top-p",label:t("settings.agents.page.field.topP"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.topPTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.topPRange")})]}),children:[s.jsx(ws,{value:T,fallbackValue:.9,onValueChange:P,onClear:()=>P(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Es}),T!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>P(void 0),className:ys,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx($e,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Ms,{value:D,onChange:q=>$(q.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})}),!v&&d&&s.jsx(Lp,{agent:d}),s.jsx("div",{className:"pb-8",children:s.jsx(H,{onClick:K,disabled:_||!ie,size:"xs",className:"!font-normal",children:t(_?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})};function Up(t,e){return t.kind==="file"?t.content:e??""}const _p=on({content:as(),exists:eo(),path:as().min(1).optional()}),$p=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Bp=t=>t.length>0&&!t.endsWith(`
2
+ `)?`${t}
3
+ `:t,ji={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Vp=(t,e)=>t==="custom"?e:dd(t),Hp=t=>t==="custom"?"custom":Jl(t)?t:"concise",Bo={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"},fr=async(t,e)=>{if(!(await yt(t)).ok)throw new Error(e)},qp=()=>{const{t}=et(),e=ld(),[a,n]=o.useState(""),[i,r]=o.useState("AGENTS.md"),[l,u]=o.useState(!1),[c,f]=o.useState(ji.responseStyleEnabled),[d,v]=o.useState(ji.responseStylePreset),[p,j]=o.useState(ji.responseStyleCustomInstructions),[h,w]=o.useState(!0),[b,k]=o.useState(!1),[m,I]=o.useState(!1),[E,A]=o.useState(""),[N,x]=o.useState(!1),y=o.useRef(null);o.useEffect(()=>{const _=new AbortController;return(async()=>{try{const[R,V]=await Promise.all([Nn(),xt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:_.signal})]);let U=ji,W;R&&(U={...U,optimizeSystemPrompt:R.optimizeSystemPrompt===!0,responseStyleEnabled:R.responseStyleEnabled===!0,responseStylePreset:Hp(R.responseStylePreset),responseStyleCustomInstructions:R.responseStyleCustomInstructions??""},R.globalBehaviorPrompt!==void 0&&(W=R.globalBehaviorPrompt));let te={kind:"missing"};if(V.ok){const O=_p.parse(await V.json());if(_.signal.aborted)return;r(O.path??"AGENTS.md"),O.exists&&(te={kind:"file",content:O.content})}U={...U,prompt:Up(te,W)},n(U.prompt),u(U.optimizeSystemPrompt),x(U.optimizeSystemPrompt),f(U.responseStyleEnabled),v(U.responseStylePreset),j(U.responseStyleCustomInstructions),A(U.prompt),y.current={enabled:U.responseStyleEnabled,preset:U.responseStylePreset,custom:U.responseStyleCustomInstructions}}catch(R){R.name!=="AbortError"&&console.warn("Failed to load behavior settings:",R)}finally{w(!1)}})(),()=>_.abort()},[]),o.useEffect(()=>{if(h)return;const _=y.current;if(_&&_.enabled===c&&_.preset===d&&_.custom===p)return;const C={enabled:c,preset:d,custom:p},R=setTimeout(async()=>{try{await fr({responseStyleEnabled:C.enabled,responseStylePreset:C.preset,responseStyleCustomInstructions:C.custom},t("settings.behavior.page.toast.saveFailed")),y.current=C}catch(V){const U=V instanceof Error?V.message:t("settings.behavior.page.toast.saveFailed");M.error(U)}},400);return()=>clearTimeout(R)},[c,d,p,h,t]);const F=Vp(d,p),T=a!==E,P=l!==N,D=async()=>{k(!0);try{const _=Bp(a),C=await xt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:_})});if(!C.ok)throw new Error(await $p(C,t("settings.behavior.page.toast.saveFailed")));const R=await C.json().catch(()=>null),V=Ql(R,"behavior",{id:"agents-md"});await fr({globalBehaviorPrompt:_},t("settings.behavior.page.toast.saveFailed")),n(_),A(_),M.success(t(V?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(_){console.error("Failed to save behavior:",_);const C=_ instanceof Error?_.message:t("settings.behavior.page.toast.saveFailed");M.error(C)}finally{k(!1)}},$=async()=>{I(!0);try{await fr({optimizeSystemPrompt:l},t("settings.behavior.page.toast.saveFailed")),x(l),ta("behavior",{id:"optimize-system-prompt"}),M.success(t("settings.view.pendingRestart.saved"))}catch(_){const C=_ instanceof Error?_.message:t("settings.behavior.page.toast.saveFailed");M.error(C)}finally{I(!1)}};return s.jsxs(os,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs($e,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(mt,{checked:l,onChange:u,disabled:h||m,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(H,{type:"button",size:"xs",onClick:()=>{$()},disabled:h||m||!P,className:"!font-normal",children:t(m?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs($e,{title:t("settings.behavior.page.section.systemPrompt"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:i})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Ms,{value:a,onChange:_=>n(_.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:h,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(H,{onClick:D,disabled:b||!T||h,size:"xs",className:"!font-normal",children:t(b?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs($e,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(mt,{checked:c,onChange:f,disabled:h,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Ht,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Et,{value:d,onValueChange:_=>v(_),disabled:h||!c,children:[s.jsx(Dt,{size:Gt,className:gn,children:s.jsx(_t,{children:_=>_==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Jl(_)?t(Bo[_]):null})}),s.jsxs(Mt,{children:[cd.map(_=>s.jsx(ut,{value:_,children:t(Bo[_])},_)),s.jsx(ut,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Ms,{value:F,onChange:_=>j(_.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:h||!c||d!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Gp=t=>{const e=dt.c(176),{onItemSelect:a}=t,{t:n}=et(),[i,r]=o.useState(null),[l,u]=o.useState(""),[c,f]=o.useState(null),[d,v]=o.useState(null),[p,j]=o.useState(!1),[h,w]=o.useState(null),{selectedCommandName:b,setSelectedCommand:k,setCommandDraft:m,createCommand:I,deleteCommand:E,loadCommands:A}=Ma(Hs(Wp)),N=Gs();let x;e[0]!==N?(x=Je=>Yl(Je,N),e[0]=N,e[1]=x):x=e[1];const y=Ma(x);let F;e[2]!==N?(F=Je=>qr(Je,N),e[2]=N,e[3]=F):F=e[3];const T=Zs(F),P=Zs(Jp);let D,$;e[4]!==A||e[5]!==P||e[6]!==N?(D=()=>{A(N),P(N)},$=[A,P,N],e[4]=A,e[5]=P,e[6]=N,e[7]=D,e[8]=$):(D=e[7],$=e[8]),o.useEffect(D,$);let _;e[9]!==T?(_=new Set(T.map(Qp)),e[9]=T,e[10]=_):_=e[10];const C=_;let R;if(e[11]!==y||e[12]!==C){let Je;e[14]!==C?(Je=St=>!C.has(St.name),e[14]=C,e[15]=Je):Je=e[15],R=y.filter(Je),e[11]=y,e[12]=C,e[13]=R}else R=e[13];const V=R;let U,W;e[16]!==b||e[17]!==k||e[18]!==C?(U=()=>{b&&C.has(b)&&k(null)},W=[b,k,C],e[16]=b,e[17]=k,e[18]=C,e[19]=U,e[20]=W):(U=e[19],W=e[20]),o.useEffect(U,W);let te;e[21]!==y||e[22]!==a||e[23]!==m||e[24]!==k?(te=()=>{let Je="new-command",St=1;for(;y.some(Fe=>Fe.name===Je);)Je=`new-command-${St}`,St++;m({name:Je,scope:"user"}),k(Je),a?.()},e[21]=y,e[22]=a,e[23]=m,e[24]=k,e[25]=te):te=e[25];const O=te;let ie;e[26]!==n?(ie=async Je=>{if(Pa(Je)){M.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}f(Je),v("delete")},e[26]=n,e[27]=ie):ie=e[27];const K=ie;let q;e[28]===Symbol.for("react.memo_cache_sentinel")?(q=async Je=>{Pa(Je)&&(f(Je),v("reset"))},e[28]=q):q=e[28];const B=q;let L;e[29]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{f(null),v(null)},e[29]=L):L=e[29];const X=L;let G;e[30]!==c||e[31]!==d||e[32]!==E||e[33]!==N||e[34]!==n?(G=async()=>{if(!c||!d)return;j(!0),await E(c.name,N)?(d==="delete"?M.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):M.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),X()):d==="delete"?M.error(n("settings.commands.sidebar.toast.deleteFailed")):M.error(n("settings.commands.sidebar.toast.resetFailed")),j(!1)},e[30]=c,e[31]=d,e[32]=E,e[33]=N,e[34]=n,e[35]=G):G=e[35];const Z=G;let le;e[36]!==y||e[37]!==m||e[38]!==k?(le=Je=>{const St=Je.name;let Fe=1,wt=`${St}-copy`;for(;y.some(Y=>Y.name===wt);)Fe++,wt=`${St}-copy-${Fe}`;m({name:wt,scope:Je.scope||"user",description:Je.description,template:Je.template,agent:Je.agent,model:Je.model}),k(wt)},e[36]=y,e[37]=m,e[38]=k,e[39]=le):le=e[39];const oe=le;let he;e[40]===Symbol.for("react.memo_cache_sentinel")?(he=Je=>{u(Je.name),r(Je)},e[40]=he):he=e[40];const ee=he;let re;e[41]!==y||e[42]!==I||e[43]!==E||e[44]!==i||e[45]!==l||e[46]!==k||e[47]!==N||e[48]!==n?(re=async()=>{if(!i)return;const Je=l.trim().replace(/\s+/g,"-");if(!Je){M.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Je===i.name){r(null);return}if(y.some(Fe=>Fe.name===Je)){M.error(n("settings.commands.sidebar.toast.commandExists"));return}await I({name:Je,description:i.description,template:i.template,agent:i.agent,model:i.model},N)?await E(i.name,N)?(M.success(`Command renamed to "${Je}"`),k(Je)):M.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):M.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[41]=y,e[42]=I,e[43]=E,e[44]=i,e[45]=l,e[46]=k,e[47]=N,e[48]=n,e[49]=re):re=e[49];const de=re;let ke,ue,xe,pe,Ie,Te;if(e[50]!==V||e[51]!==O||e[52]!==K||e[53]!==oe||e[54]!==a||e[55]!==h||e[56]!==b||e[57]!==k||e[58]!==n){const Je=V.filter(Pa),St=V.filter(Yp);e[65]===Symbol.for("react.memo_cache_sentinel")?(Ie=ye("flex h-full flex-col","bg-background"),e[65]=Ie):Ie=e[65];let Fe;e[66]!==n?(Fe=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Fe):Fe=e[67];let wt;e[68]!==Fe?(wt=s.jsx("h2",{className:`${kn} mb-3`,children:Fe}),e[68]=Fe,e[69]=wt):wt=e[69];let Y;e[70]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(ri,{className:"mb-3"}),e[70]=Y):Y=e[70];let fe;e[71]!==V.length||e[72]!==n?(fe=n("settings.commands.sidebar.total",{count:V.length}),e[71]=V.length,e[72]=n,e[73]=fe):fe=e[73];let Me;e[74]!==fe?(Me=s.jsx("span",{className:"typography-meta text-muted-foreground",children:fe}),e[74]=fe,e[75]=Me):Me=e[75];let Ee;e[76]===Symbol.for("react.memo_cache_sentinel")?(Ee=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Ee):Ee=e[76];let rt;e[77]!==O?(rt=s.jsx(H,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:O,children:Ee}),e[77]=O,e[78]=rt):rt=e[78];let ot;e[79]!==Me||e[80]!==rt?(ot=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Me,rt]}),e[79]=Me,e[80]=rt,e[81]=ot):ot=e[81],e[82]!==wt||e[83]!==ot?(Te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[wt,Y,ot]}),e[82]=wt,e[83]=ot,e[84]=Te):Te=e[84],ke=ks,ue="flex-1 min-h-0",xe="space-y-1 px-3 py-2",pe=V.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[Je.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.builtIn")}),[...Je].sort(Zp).map(Ge=>s.jsx(Vo,{command:Ge,isSelected:b===Ge.name,onSelect:()=>{k(Ge.name),a?.()},onReset:()=>B(Ge),onDuplicate:()=>oe(Ge),isMenuOpen:h===Ge.name,onMenuOpenChange:Nt=>w(Nt?Ge.name:null)},Ge.name))]}),St.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.custom")}),[...St].sort(Xp).map(Ge=>s.jsx(Vo,{command:Ge,isSelected:b===Ge.name,onSelect:()=>{k(Ge.name),a?.()},onRename:()=>ee(Ge),onDelete:()=>K(Ge),onDuplicate:()=>oe(Ge),isMenuOpen:h===Ge.name,onMenuOpenChange:Nt=>w(Nt?Ge.name:null)},Ge.name))]})]}),e[50]=V,e[51]=O,e[52]=K,e[53]=oe,e[54]=a,e[55]=h,e[56]=b,e[57]=k,e[58]=n,e[59]=ke,e[60]=ue,e[61]=xe,e[62]=pe,e[63]=Ie,e[64]=Te}else ke=e[59],ue=e[60],xe=e[61],pe=e[62],Ie=e[63],Te=e[64];let we;e[85]!==ke||e[86]!==ue||e[87]!==xe||e[88]!==pe?(we=s.jsx(ke,{outerClassName:ue,className:xe,children:pe}),e[85]=ke,e[86]=ue,e[87]=xe,e[88]=pe,e[89]=we):we=e[89];const De=c!==null&&d!==null;let _e;e[90]!==p?(_e=Je=>{!Je&&!p&&X()},e[90]=p,e[91]=_e):_e=e[91];let Ve;e[92]!==d||e[93]!==n?(Ve=n(d==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=d,e[93]=n,e[94]=Ve):Ve=e[94];let ve;e[95]!==Ve?(ve=s.jsx(Bt,{children:Ve}),e[95]=Ve,e[96]=ve):ve=e[96];let se;e[97]!==c?.name||e[98]!==d||e[99]!==n?(se=d==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[97]=c?.name,e[98]=d,e[99]=n,e[100]=se):se=e[100];let ae;e[101]!==se?(ae=s.jsx(Vt,{children:se}),e[101]=se,e[102]=ae):ae=e[102];let je;e[103]!==ve||e[104]!==ae?(je=s.jsxs($t,{children:[ve,ae]}),e[103]=ve,e[104]=ae,e[105]=je):je=e[105];let Se;e[106]!==n?(Se=n("settings.common.actions.cancel"),e[106]=n,e[107]=Se):Se=e[107];let Ke;e[108]!==p||e[109]!==Se?(Ke=s.jsx(H,{size:"sm",variant:"ghost",onClick:X,disabled:p,children:Se}),e[108]=p,e[109]=Se,e[110]=Ke):Ke=e[110];let Ue;e[111]!==d||e[112]!==n?(Ue=n(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=d,e[112]=n,e[113]=Ue):Ue=e[113];let Oe;e[114]!==Z||e[115]!==p||e[116]!==Ue?(Oe=s.jsx(H,{size:"sm",onClick:Z,disabled:p,children:Ue}),e[114]=Z,e[115]=p,e[116]=Ue,e[117]=Oe):Oe=e[117];let Re;e[118]!==Ke||e[119]!==Oe?(Re=s.jsxs(is,{children:[Ke,Oe]}),e[118]=Ke,e[119]=Oe,e[120]=Re):Re=e[120];let Ce;e[121]!==je||e[122]!==Re?(Ce=s.jsxs(Ut,{className:"max-w-md",children:[je,Re]}),e[121]=je,e[122]=Re,e[123]=Ce):Ce=e[123];let Ze;e[124]!==De||e[125]!==_e||e[126]!==Ce?(Ze=s.jsx(zt,{open:De,onOpenChange:_e,children:Ce}),e[124]=De,e[125]=_e,e[126]=Ce,e[127]=Ze):Ze=e[127];const be=i!==null;let Pe;e[128]===Symbol.for("react.memo_cache_sentinel")?(Pe=Je=>!Je&&r(null),e[128]=Pe):Pe=e[128];let Le;e[129]!==n?(Le=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=Le):Le=e[130];let Xe;e[131]!==Le?(Xe=s.jsx(Bt,{children:Le}),e[131]=Le,e[132]=Xe):Xe=e[132];const Q=i?.name??"";let Ne;e[133]!==n||e[134]!==Q?(Ne=n("settings.commands.sidebar.renameDialog.description",{name:Q}),e[133]=n,e[134]=Q,e[135]=Ne):Ne=e[135];let Ae;e[136]!==Ne?(Ae=s.jsx(Vt,{children:Ne}),e[136]=Ne,e[137]=Ae):Ae=e[137];let We;e[138]!==Xe||e[139]!==Ae?(We=s.jsxs($t,{children:[Xe,Ae]}),e[138]=Xe,e[139]=Ae,e[140]=We):We=e[140];let lt;e[141]===Symbol.for("react.memo_cache_sentinel")?(lt=Je=>u(Je.target.value),e[141]=lt):lt=e[141];let at;e[142]!==n?(at=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=at):at=e[143];let pt;e[144]!==de?(pt=Je=>{Je.key==="Enter"&&de()},e[144]=de,e[145]=pt):pt=e[145];let bt;e[146]!==l||e[147]!==at||e[148]!==pt?(bt=s.jsx(He,{value:l,onChange:lt,placeholder:at,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:pt}),e[146]=l,e[147]=at,e[148]=pt,e[149]=bt):bt=e[149];let J;e[150]===Symbol.for("react.memo_cache_sentinel")?(J=()=>r(null),e[150]=J):J=e[150];let qe;e[151]!==n?(qe=n("settings.common.actions.cancel"),e[151]=n,e[152]=qe):qe=e[152];let it;e[153]!==qe?(it=s.jsx(H,{size:"sm",variant:"ghost",onClick:J,children:qe}),e[153]=qe,e[154]=it):it=e[154];let ct;e[155]!==n?(ct=n("settings.common.actions.rename"),e[155]=n,e[156]=ct):ct=e[156];let gt;e[157]!==de||e[158]!==ct?(gt=s.jsx(H,{size:"sm",onClick:de,children:ct}),e[157]=de,e[158]=ct,e[159]=gt):gt=e[159];let Rt;e[160]!==it||e[161]!==gt?(Rt=s.jsxs(is,{children:[it,gt]}),e[160]=it,e[161]=gt,e[162]=Rt):Rt=e[162];let tt;e[163]!==We||e[164]!==bt||e[165]!==Rt?(tt=s.jsxs(Ut,{children:[We,bt,Rt]}),e[163]=We,e[164]=bt,e[165]=Rt,e[166]=tt):tt=e[166];let ft;e[167]!==be||e[168]!==tt?(ft=s.jsx(zt,{open:be,onOpenChange:Pe,children:tt}),e[167]=be,e[168]=tt,e[169]=ft):ft=e[169];let jt;return e[170]!==Ie||e[171]!==Te||e[172]!==we||e[173]!==Ze||e[174]!==ft?(jt=s.jsxs("div",{className:Ie,children:[Te,we,Ze,ft]}),e[170]=Ie,e[171]=Te,e[172]=we,e[173]=Ze,e[174]=ft,e[175]=jt):jt=e[175],jt},Vo=t=>{const e=dt.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:u,onDuplicate:c,isMenuOpen:f,onMenuOpenChange:d}=t,{t:v}=et();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=si(),e[0]=p):p=e[0];const j=p,[h,w]=o.useState(!1);let b;e[1]!==r||e[2]!==c||e[3]!==u||e[4]!==l||e[5]!==v?(b=W=>s.jsxs(s.Fragment,{children:[u&&s.jsxs(W,{onClick:te=>{te.stopPropagation(),u()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),v("settings.common.actions.rename")]}),s.jsxs(W,{onClick:te=>{te.stopPropagation(),c()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),v("settings.common.actions.duplicate")]}),l&&s.jsxs(W,{onClick:te=>{te.stopPropagation(),l()},children:[s.jsx(z,{name:"restart",className:"h-4 w-4 mr-px"}),v("settings.common.actions.reset")]}),r&&s.jsxs(W,{onClick:te=>{te.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),v("settings.common.actions.delete")]})]}),e[1]=r,e[2]=c,e[3]=u,e[4]=l,e[5]=v,e[6]=b):b=e[6];const k=b,m=n?"bg-interactive-selection":"hover:bg-interactive-hover";let I;e[7]!==m?(I=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m),e[7]=m,e[8]=I):I=e[8];let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=j?void 0:W=>{W.preventDefault(),w(!0)},e[9]=E):E=e[9];let A;e[10]!==I?(A=s.jsx("div",{className:I,onContextMenu:E}),e[10]=I,e[11]=A):A=e[11];let N;e[12]!==a.name?(N=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=N):N=e[13];let x;e[14]!==a||e[15]!==v?(x=(a.scope||Pa(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Pa(a)?v("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=v,e[16]=x):x=e[16];let y;e[17]!==N||e[18]!==x?(y=s.jsxs("div",{className:"flex items-center gap-2",children:[N,x]}),e[17]=N,e[18]=x,e[19]=y):y=e[19];let F;e[20]!==a.description?(F=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=F):F=e[21];let T;e[22]!==i||e[23]!==F||e[24]!==y?(T=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[y,F]}),e[22]=i,e[23]=F,e[24]=y,e[25]=T):T=e[25];let P;e[26]!==d?(P=W=>{W&&w(!1),d(W)},e[26]=d,e[27]=P):P=e[27];let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(fn,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=D):D=e[28];let $;e[29]!==k?($=s.jsx(xn,{align:"end",className:"w-fit min-w-20",children:k(vn)}),e[29]=k,e[30]=$):$=e[30];let _;e[31]!==f||e[32]!==P||e[33]!==$?(_=s.jsxs(bn,{open:f,onOpenChange:P,children:[D,$]}),e[31]=f,e[32]=P,e[33]=$,e[34]=_):_=e[34];let C;e[35]!==T||e[36]!==_?(C=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[T,_]}),e[35]=T,e[36]=_,e[37]=C):C=e[37];let R;e[38]!==C||e[39]!==A?(R=s.jsx(la,{render:A,children:C}),e[38]=C,e[39]=A,e[40]=R):R=e[40];let V;e[41]!==k?(V=s.jsx(ra,{className:"w-fit min-w-20",children:k(oa)}),e[41]=k,e[42]=V):V=e[42];let U;return e[43]!==h||e[44]!==R||e[45]!==V?(U=s.jsxs(ca,{open:h,onOpenChange:w,children:[R,V]}),e[43]=h,e[44]=R,e[45]=V,e[46]=U):U=e[46],U};function Wp(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Jp(t){return t.loadSkills}function Qp(t){return t.name}function Yp(t){return!Pa(t)}function Zp(t,e){return t.name.localeCompare(e.name)}function Xp(t,e){return t.name.localeCompare(e.name)}const em=()=>{const{t}=et(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:r,setCommandDraft:l}=Ma(Hs(D=>({selectedCommandName:D.selectedCommandName,getCommandByName:D.getCommandByName,createCommand:D.createCommand,updateCommand:D.updateCommand,commandDraft:D.commandDraft,setCommandDraft:D.setCommandDraft}))),u=Gs(),c=Ma(D=>Yl(D,u)),f=e?a(e,u):null,d=!!(r&&r.name===e&&!f),[v,p]=o.useState(""),[j,h]=o.useState("user"),[w,b]=o.useState(""),[k,m]=o.useState(""),[I,E]=o.useState(""),[A,N]=o.useState(""),[x,y]=o.useState(!1),F=o.useRef(null);o.useEffect(()=>{if(d&&r){const D=r.name||"",$=r.scope||"user",_=r.description||"",C=r.agent||"",R=r.model||"",V=r.template||"";p(D),h($),b(_),m(C),E(R),N(V),F.current={draftName:D,draftScope:$,description:_,agent:C,model:R,template:V}}else if(f){const D=f.description||"",$=f.agent||"",_=f.model||"",C=f.template||"";b(D),m($),E(_),N(C),F.current={draftName:"",draftScope:"user",description:D,agent:$,model:_,template:C}}},[f,d,e,c,r]);const T=o.useMemo(()=>{const D=F.current;return D?!!(d&&(v!==D.draftName||j!==D.draftScope)||w!==D.description||k!==D.agent||I!==D.model||A!==D.template):!1},[k,w,v,j,d,I,A]),P=async()=>{const D=d?v.trim().replace(/\s+/g,"-"):e?.trim();if(!D){M.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!A.trim()){M.error(t("settings.commands.page.toast.templateRequired"));return}if(d&&c.some($=>$.name===D)){M.error(t("settings.commands.sidebar.toast.commandExists"));return}y(!0);try{const $=k.trim(),_=I.trim(),C=A.trim(),R={name:D,description:w.trim()||void 0,agent:$===""?null:$,model:_===""?null:_,template:C,scope:d?j:void 0};let V;if(d?(V=await n(R,u),V&&l(null)):V=await i(D,R,u),V){const U=sa.getState().changes.some(W=>W.scope==="commands"&&W.id.startsWith(`commands:${D}:`));M.success(t(U?"settings.view.pendingRestart.saved":d?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else M.error(t(d?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch($){console.error("Error saving command:",$),M.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{y(!1)}};return e?s.jsxs(os,{title:d?t("settings.commands.page.title.new"):`/${e}`,description:t(d?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs($e,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[d&&s.jsxs(Ht,{settingsItem:"commands.name",label:t("settings.commands.page.field.commandName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(He,{value:v,onChange:D=>p(D.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Et,{value:j,onValueChange:D=>h(D),children:[s.jsx(Dt,{size:Gt,className:"w-fit min-w-[100px]",children:s.jsx(_t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Mt,{align:"end",children:[s.jsx(ut,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ut,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(Ms,{value:w,onChange:D=>b(D.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs($e,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Ht,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(Zl,{agentName:k,onChange:D=>m(D),className:_n})}),s.jsx(Ht,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Xa,{providerId:Da(I)?.providerId??"",modelId:Da(I)?.modelId??"",onChange:(D,$)=>{E(D&&$?`${D}/${$}`:"")},className:_n})})]}),s.jsxs($e,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Ms,{value:A,onChange:D=>N(D.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"}),s.jsxs("p",{className:"mt-2 typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]}),s.jsx("div",{className:"pt-3",children:s.jsx(H,{onClick:P,disabled:x||!T,size:"xs",className:"!font-normal",children:t(x?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},Ho=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},qo=t=>{const e=dt.c(5),{tone:a,enabled:n}=t;if(!n){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.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 i;e[1]!==a?(i=ye("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"}[a]),e[1]=a,e[2]=i):i=e[2];let r;return e[3]!==i?(r=s.jsx("span",{className:i}),e[3]=i,e[4]=r):r=e[4],r},tm=t=>{const e=dt.c(124),{onItemSelect:a}=t,{t:n}=et(),{selectedMcpName:i,setSelectedMcp:r,setMcpDraft:l,loadMcpConfigs:u,deleteMcp:c}=Ra(Hs(sm)),f=Gs();let d;e[0]!==f?(d=Q=>Xl(Q,f),e[0]=f,e[1]=d):d=e[1];const v=Ra(d);let p;e[2]!==f?(p=Q=>Q.getStatusForDirectory(f),e[2]=f,e[3]=p):p=e[3];const j=Bs(p),h=Bs(nm),w=Bs(am),[b,k]=o.useState(null),[m,I]=o.useState(!1),[E,A]=o.useState(null),[N,x]=o.useState(null),[y,F]=o.useState(!1);let T;e[4]!==v?(T=v.filter(im),e[4]=v,e[5]=T):T=e[5];const P=T;let D;e[6]!==v?(D=v.filter(rm),e[6]=v,e[7]=D):D=e[7];const $=D;let _,C;e[8]!==u||e[9]!==f?(_=()=>{u({directory:f})},C=[u,f],e[8]=u,e[9]=f,e[10]=_,e[11]=C):(_=e[10],C=e[11]),o.useEffect(_,C);let R;e[12]!==w||e[13]!==y||e[14]!==h||e[15]!==f?(R=()=>{if(y)return;F(!0);const Q=new Promise(om);Promise.all([h({directory:f,silent:!0}),Q]).then(()=>{const Ne=w(f);Ne&&M.error(Ne)}).finally(()=>{F(!1)})},e[12]=w,e[13]=y,e[14]=h,e[15]=f,e[16]=R):R=e[16];const V=R;let U;e[17]!==v||e[18]!==a||e[19]!==l||e[20]!==r?(U=()=>{let Q="new-mcp-server",Ne=1;for(;v.some(We=>We.name===Q);)Q=`new-mcp-server-${Ne}`,Ne++;l({name:Q,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),r(Q),a?.()},e[17]=v,e[18]=a,e[19]=l,e[20]=r,e[21]=U):U=e[21];const W=U;let te;e[22]!==c||e[23]!==b||e[24]!==f||e[25]!==n?(te=async()=>{if(!b)return;I(!0);const Q=await c(b.name,f);Q.ok?Q.reloadFailed?M.warning(Q.message||`MCP server "${b.name}" deleted, but OpenCode reload failed`,{description:Q.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):M.success(Q.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:b.name})):M.error(n("settings.mcp.sidebar.toast.deleteFailed")),k(null),I(!1)},e[22]=c,e[23]=b,e[24]=f,e[25]=n,e[26]=te):te=e[26];const O=te;let ie;e[27]!==n?(ie=(Q,Ne)=>s.jsxs(Ne,{onClick:Ae=>{Ae.stopPropagation(),k(Q)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=ie):ie=e[28];const K=ie;let q;e[29]===Symbol.for("react.memo_cache_sentinel")?(q=ye("flex h-full flex-col","bg-background"),e[29]=q):q=e[29];let B;e[30]!==n?(B=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=B):B=e[31];let L;e[32]!==B?(L=s.jsx("h2",{className:kn,children:B}),e[32]=B,e[33]=L):L=e[33];let X;e[34]!==n?(X=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=X):X=e[35];let G;e[36]!==n?(G=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=G):G=e[37];const Z=y&&"animate-spin";let le;e[38]!==Z?(le=ye("h-4 w-4",Z),e[38]=Z,e[39]=le):le=e[39];let oe;e[40]!==le?(oe=s.jsx(z,{name:"refresh",className:le}),e[40]=le,e[41]=oe):oe=e[41];let he;e[42]!==V||e[43]!==y||e[44]!==X||e[45]!==G||e[46]!==oe?(he=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",disabled:y,onClick:V,"aria-label":X,title:G,children:oe}),e[42]=V,e[43]=y,e[44]=X,e[45]=G,e[46]=oe,e[47]=he):he=e[47];let ee;e[48]!==L||e[49]!==he?(ee=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[L,he]}),e[48]=L,e[49]=he,e[50]=ee):ee=e[50];let re;e[51]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(ri,{className:"mb-3"}),e[51]=re):re=e[51];let de;e[52]!==v.length||e[53]!==n?(de=n("settings.mcp.sidebar.total",{count:v.length}),e[52]=v.length,e[53]=n,e[54]=de):de=e[54];let ke;e[55]!==de?(ke=s.jsx("span",{className:"typography-meta text-muted-foreground",children:de}),e[55]=de,e[56]=ke):ke=e[56];let ue;e[57]!==n?(ue=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=ue):ue=e[58];let xe;e[59]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[59]=xe):xe=e[59];let pe;e[60]!==W||e[61]!==ue?(pe=s.jsx(H,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:W,title:ue,children:xe}),e[60]=W,e[61]=ue,e[62]=pe):pe=e[62];let Ie;e[63]!==ke||e[64]!==pe?(Ie=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ke,pe]}),e[63]=ke,e[64]=pe,e[65]=Ie):Ie=e[65];let Te;e[66]!==ee||e[67]!==Ie?(Te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ee,re,Ie]}),e[66]=ee,e[67]=Ie,e[68]=Te):Te=e[68];let we;e[69]!==v.length||e[70]!==j||e[71]!==a||e[72]!==E||e[73]!==P||e[74]!==K||e[75]!==N||e[76]!==i||e[77]!==l||e[78]!==r||e[79]!==n||e[80]!==$?(we=s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[P.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.projectServers")}),P.map(Q=>{const Ne=j[Q.name],Ae=Ho(Ne?.status),We=i===Q.name,lt=si();return s.jsxs(ca,{open:N===Q.name,onOpenChange:at=>x(at?Q.name:null),children:[s.jsxs(la,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",We?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:lt?void 0:at=>{at.preventDefault(),x(Q.name)}}),children:[s.jsxs("button",{onClick:()=>{r(Q.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qo,{tone:Ae,enabled:Q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Q.name}),s.jsx("span",{title:Q.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:Q.type==="local"?s.jsx(z,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(z,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Q.type==="local"?Q.command?.join(" ")??"":Q.url??""})]}),s.jsxs(bn,{open:E===Q.name,onOpenChange:at=>{at&&x(null),A(at?Q.name:null)},children:[s.jsx(fn,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(xn,{align:"end",className:"w-fit min-w-20",children:K(Q,vn)})]})]}),s.jsx(ra,{className:"w-fit min-w-20",children:K(Q,oa)})]},Q.name)})]}),$.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.userServers")}),$.map(Q=>{const Ne=j[Q.name],Ae=Ho(Ne?.status),We=i===Q.name,lt=si();return s.jsxs(ca,{open:N===Q.name,onOpenChange:at=>x(at?Q.name:null),children:[s.jsxs(la,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",We?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:lt?void 0:at=>{at.preventDefault(),x(Q.name)}}),children:[s.jsxs("button",{onClick:()=>{r(Q.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qo,{tone:Ae,enabled:Q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Q.name}),s.jsx("span",{title:Q.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:Q.type==="local"?s.jsx(z,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(z,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Q.type==="local"?Q.command?.join(" ")??"":Q.url??""})]}),s.jsxs(bn,{open:E===Q.name,onOpenChange:at=>{at&&x(null),A(at?Q.name:null)},children:[s.jsx(fn,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(xn,{align:"end",className:"w-fit min-w-20",children:K(Q,vn)})]})]}),s.jsx(ra,{className:"w-fit min-w-20",children:K(Q,oa)})]},Q.name)})]})]})}),e[69]=v.length,e[70]=j,e[71]=a,e[72]=E,e[73]=P,e[74]=K,e[75]=N,e[76]=i,e[77]=l,e[78]=r,e[79]=n,e[80]=$,e[81]=we):we=e[81];const De=b!==null;let _e;e[82]!==m?(_e=Q=>{!Q&&!m&&k(null)},e[82]=m,e[83]=_e):_e=e[83];let Ve;e[84]!==n?(Ve=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=Ve):Ve=e[85];let ve;e[86]!==Ve?(ve=s.jsx(Bt,{children:Ve}),e[86]=Ve,e[87]=ve):ve=e[87];const se=b?.name||"";let ae;e[88]!==n||e[89]!==se?(ae=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:se}),e[88]=n,e[89]=se,e[90]=ae):ae=e[90];let je;e[91]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=je):je=e[91];let Se;e[92]!==ae?(Se=s.jsxs(Vt,{children:[ae," ",je,"."]}),e[92]=ae,e[93]=Se):Se=e[93];let Ke;e[94]!==ve||e[95]!==Se?(Ke=s.jsxs($t,{children:[ve,Se]}),e[94]=ve,e[95]=Se,e[96]=Ke):Ke=e[96];let Ue;e[97]===Symbol.for("react.memo_cache_sentinel")?(Ue=()=>k(null),e[97]=Ue):Ue=e[97];let Oe;e[98]!==n?(Oe=n("settings.common.actions.cancel"),e[98]=n,e[99]=Oe):Oe=e[99];let Re;e[100]!==m||e[101]!==Oe?(Re=s.jsx(H,{size:"sm",variant:"ghost",onClick:Ue,disabled:m,children:Oe}),e[100]=m,e[101]=Oe,e[102]=Re):Re=e[102];let Ce;e[103]!==m||e[104]!==n?(Ce=n(m?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=m,e[104]=n,e[105]=Ce):Ce=e[105];let Ze;e[106]!==O||e[107]!==m||e[108]!==Ce?(Ze=s.jsx(H,{size:"sm",onClick:O,disabled:m,children:Ce}),e[106]=O,e[107]=m,e[108]=Ce,e[109]=Ze):Ze=e[109];let be;e[110]!==Re||e[111]!==Ze?(be=s.jsxs(is,{children:[Re,Ze]}),e[110]=Re,e[111]=Ze,e[112]=be):be=e[112];let Pe;e[113]!==Ke||e[114]!==be?(Pe=s.jsxs(Ut,{className:"max-w-md",children:[Ke,be]}),e[113]=Ke,e[114]=be,e[115]=Pe):Pe=e[115];let Le;e[116]!==De||e[117]!==_e||e[118]!==Pe?(Le=s.jsx(zt,{open:De,onOpenChange:_e,children:Pe}),e[116]=De,e[117]=_e,e[118]=Pe,e[119]=Le):Le=e[119];let Xe;return e[120]!==Te||e[121]!==we||e[122]!==Le?(Xe=s.jsxs("div",{className:q,children:[Te,we,Le]}),e[120]=Te,e[121]=we,e[122]=Le,e[123]=Xe):Xe=e[123],Xe};function sm(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function nm(t){return t.refresh}function am(t){return t.getErrorForDirectory}function im(t){return t.scope==="project"}function rm(t){return t.scope!=="project"}function om(t){return setTimeout(t,500)}function mn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Va(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function pn(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function wi(t,e,a){const n=lm(a),i=typeof a.url=="string"?a.url.trim():"",r=Go(a,"env","environment"),l=Go(a,"headers"),u=cm(a),c=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",f=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",d=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",v=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",p=dm(a),j=um(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:u,oauthClientId:c,oauthClientSecret:f,oauthScope:d,oauthRedirectUri:v,timeout:p,enabled:j}}function lm(t){const e=t.command,a=t.args;if(Va(e)&&Va(a))return[...e,...a];if(Va(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Va(a)?[...n,...a]:n}return Va(a)?a:[]}function Go(t,...e){for(const a of e){const n=t[a];if(!mn(n))continue;const i=Object.entries(n).filter(([r,l])=>r&&typeof l=="string");if(i.length>0)return i.map(([r,l])=>({key:r,value:String(l)}))}return[]}function cm(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!mn(t.oauth))return!1;const e=t.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function dm(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const a=Number(e);if(Number.isFinite(a)&&a>0)return String(Math.floor(a))}return""}function um(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function pm(t){const e=t.mcpServers;if(mn(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(mn(r))return{name:i,entry:r}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const i=t[n];return n!=="mcpServers"&&mn(i)});if(a.length===1){const n=a[0],i=t[n];if(Cc(i))return{name:n,entry:i}}return null}function Cc(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function mm(t,e){let a;try{const u=t.trim();if(!u)return pn("No JSON content provided");a=JSON.parse(u)}catch(u){return pn(u instanceof Error?`Invalid JSON: ${u.message}`:"Invalid JSON")}if(!mn(a))return pn("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(mn(i)){const u=Object.keys(i);if(u.length===0)return pn("mcpServers object is empty",a);if(u.length>1)return pn("Paste one server at a time. Found "+u.length+" servers in mcpServers",a);const c=u[0],f=i[c];return mn(f)?wi(c,ki(f),f):pn("Server entry is not a valid object",a)}const r=n.mcp;if(mn(r)){const u=Object.keys(r);if(u.length===0)return pn("mcp object is empty",a);if(u.length>1)return pn("Paste one server at a time. Found "+u.length+" servers in mcp",a);const c=u[0],f=r[c];return mn(f)?wi(c,ki(f),f):pn("Server entry in mcp is not a valid object",a)}const l=pm(n);if(l)return wi(l.name,ki(l.entry),l.entry);if(Cc(n)){const u=ki(n),c=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return wi(c,u,n)}return pn("No recognizable MCP server configuration found in JSON",a)}function ki(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function gm(t,e,a){const n=a?.isNewServer??!1,i=t.name,r=n&&i?i:e.name??"";return{...e,name:r,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}function Ic(t){const e=[];let a="",n=!1,i=!1;for(let r=0;r<t.length;r++){const l=t[r];if(l==="'"&&!i){n=!n;continue}if(l==='"'&&!n){i=!i;continue}if((l===" "||l===" ")&&!n&&!i){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function hm(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const a=new URL(e),n=a.searchParams.get("code");if(typeof n=="string"&&n.trim())return{code:n.trim(),context:md(a.searchParams),stateKey:ec(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const fm=t=>{const e=dt.c(27),{value:a,onChange:n,preview:i,onDetectUrl:r}=t;let l;e[0]!==a?(l=()=>a.join(`
4
+ `),e[0]=a,e[1]=l):l=e[1];const[u,c]=o.useState(l),f=o.useRef(a);let d,v;e[2]!==a?(d=()=>{JSON.stringify(f.current)!==JSON.stringify(a)&&(f.current=a,c(a.join(`
5
+ `)))},v=[a],e[2]=a,e[3]=d,e[4]=v):(d=e[3],v=e[4]),o.useEffect(d,v);let p;e[5]!==n||e[6]!==r?(p=N=>{const x=N.split(`
6
+ `).filter(Nm);if(r&&x.length===1&&/^https?:\/\/\S+$/i.test(x[0].trim())){r(x[0].trim());return}n(x)},e[5]=n,e[6]=r,e[7]=p):p=e[7];const j=p;let h;e[8]!==n?(h=N=>{const y=N.clipboardData.getData("text").trim();if(!y||y.includes(`
7
+ `)||!/\s/.test(y))return;const F=N.currentTarget;if(F.selectionStart!==0||F.selectionEnd!==F.value.length)return;N.preventDefault();const T=Ic(y);c(T.join(`
8
+ `)),n(T)},e[8]=n,e[9]=h):h=e[9];const w=h;let b;e[10]!==j?(b=N=>{c(N.target.value),j(N.target.value)},e[10]=j,e[11]=b):b=e[11];let k;e[12]!==j||e[13]!==u?(k=()=>{const N=u.split(`
9
+ `).map(Sm).join(`
10
+ `);c(N),j(N)},e[12]=j,e[13]=u,e[14]=k):k=e[14];const m=Math.max(4,a.length+1);let I;e[15]!==w||e[16]!==b||e[17]!==k||e[18]!==m||e[19]!==u?(I=s.jsx(Ms,{onPaste:w,value:u,onChange:b,onBlur:k,placeholder:`npx
11
+ -y
12
+ @modelcontextprotocol/server-postgres
13
+ postgresql://user:pass@host/db`,rows:m,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=w,e[16]=b,e[17]=k,e[18]=m,e[19]=u,e[20]=I):I=e[20];let E;e[21]!==i||e[22]!==a?(E=a.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:i(a.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:a.map(Cm)})})]}),e[21]=i,e[22]=a,e[23]=E):E=e[23];let A;return e[24]!==E||e[25]!==I?(A=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[I,E]}),e[24]=E,e[25]=I,e[26]=A):A=e[26],A},xm=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Wo=({value:t,onChange:e,keyTransform:a=xm,keyPlaceholder:n="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:r="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:u,importSuccess:c,clipboardReadFailed:f,keyLabel:d,valueLabel:v,valuePlaceholder:p,hideValueTitle:j,showValueTitle:h,addVariable:w,plainTextWarning:b,removeVariableAria:k})=>{const[m,I]=o.useState(new Set),E=()=>e([...t,{key:"",value:""}]),A=T=>{e(t.filter((P,D)=>D!==T)),I(P=>{const D=new Set(P);return D.delete(T),D})},N=(T,P,D)=>{const $=[...t];$[T]={...$[T],[P]:D},e($)},x=T=>{I(P=>{const D=new Set(P);return D.has(T)?D.delete(T):D.add(T),D})},y=async()=>{try{const T=await navigator.clipboard.readText(),P=[];for(const $ of T.split(`
14
+ `)){const _=$.trim();if(!_||_.startsWith("#"))continue;const C=_.indexOf("=");if(C===-1)continue;const R=_.slice(0,C).trim();let V=_.slice(C+1).trim();(V.startsWith('"')&&V.endsWith('"')||V.startsWith("'")&&V.endsWith("'"))&&(V=V.slice(1,-1)),R&&P.push({key:R,value:V})}if(P.length===0){M.error(u);return}const D=[...t];for(const $ of P){const _=D.findIndex(C=>C.key===$.key);_!==-1?D[_]=$:D.push($)}e(D),M.success(c(P.length))}catch{M.error(f)}},F=t.some(T=>T.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:d}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:v})]}),s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:y,type:"button",title:l,children:[s.jsx(z,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((T,P)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:T.key,onChange:D=>N(P,"key",a(D.target.value)),placeholder:n,className:i,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(He,{type:m.has(P)?"text":"password",value:T.value,onChange:D=>N(P,"value",D.target.value),placeholder:p,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>x(P),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:m.has(P)?j:h,children:m.has(P)?s.jsx(z,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>A(P),"aria-label":k,children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},P))}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:E,type:"button",children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),w]}),F&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:b})]})},xr=t=>{const e=dt.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let u,c;if(e[0]!==i||e[1]!==a||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const p={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"},awaiting_restart:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const j=ye("typography-micro font-medium rounded-full px-2 py-0.5",p.text,p.bg);let h;e[5]!==i||e[6]!==a?(h=i(a),e[5]=i,e[6]=a,e[7]=h):h=e[7],c=s.jsxs("span",{className:j,children:["● ",h]});break e}u=ye("typography-micro font-medium",p.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=u,e[4]=c}else u=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let f;e[8]!==i||e[9]!==a?(f=i(a),e[8]=i,e[9]=a,e[10]=f):f=e[10];let d;return e[11]!==u||e[12]!==f?(d=s.jsxs("span",{className:u,children:["● ",f]}),e[11]=u,e[12]=f,e[13]=d):d=e[13],d},bm=(t,e,a)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return a?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return a?.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")}},vm=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},ym=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),jm=async t=>{const e=await xt(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const a=await e.json().catch(()=>null);return a?.name?.trim()?{name:a.name.trim(),directory:typeof a.directory=="string"&&a.directory.trim()?a.directory.trim():null}:null},Ha=async t=>{typeof t!="string"||!t.trim()||await xt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Ni=(t,e,a)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?a("settings.mcp.page.toast.authSessionExpired"):n},wm=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},km=()=>{const{t}=et(),e=o.useCallback((me,ht)=>t(me,ht),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:r,getMcpByName:l,createMcp:u,updateMcp:c,deleteMcp:f}=Ra(Hs(me=>({selectedMcpName:me.selectedMcpName,mcpDraft:me.mcpDraft,setMcpDraft:me.setMcpDraft,setSelectedMcp:me.setSelectedMcp,getMcpByName:me.getMcpByName,createMcp:me.createMcp,updateMcp:me.updateMcp,deleteMcp:me.deleteMcp}))),d=Gs(),v=o.useMemo(()=>ds(),[]),p=Bs(me=>me.getStatusForDirectory(d)),j=Bs(me=>me.getDiagnosticForDirectory(d)),h=Bs(me=>me.refresh),w=Bs(me=>me.connect),b=Bs(me=>me.disconnect),k=Bs(me=>me.completeAuth),m=Bs(me=>me.clearAuth),I=Bs(me=>me.testConnection),E=sa(me=>me.changes),A=Ra(me=>Xl(me,d)),N=a?l(a,d):null,x=!!(n&&n.name===a&&!N),[y,F]=o.useState(""),[T,P]=o.useState("user"),[D,$]=o.useState("local"),[_,C]=o.useState([]),[R,V]=o.useState(""),[U,W]=o.useState([]),[te,O]=o.useState([]),[ie,K]=o.useState(!0),[q,B]=o.useState(""),[L,X]=o.useState(""),[G,Z]=o.useState(""),[le,oe]=o.useState(""),[he,ee]=o.useState(""),[re,de]=o.useState(!0),[ke,ue]=o.useState(!1),[xe,pe]=o.useState(!1),[Ie,Te]=o.useState(!1),[we,De]=o.useState(!1),[_e,Ve]=o.useState(!1),[ve,se]=o.useState(!1),[ae,je]=o.useState(!1),[Se,Ke]=o.useState(!1),[Ue,Oe]=o.useState(null),[Re,Ce]=o.useState(null),[Ze,be]=o.useState(""),[Pe,Le]=o.useState(!1),Xe=o.useRef(0),Q=o.useRef(!1),[Ne,Ae]=o.useState(!1),[We,lt]=o.useState(!1),[at,pt]=o.useState(""),[bt,J]=o.useState(null),qe=o.useMemo(()=>wm(a,d),[d,a]),it=o.useRef(qe),ct=o.useRef(null),gt=o.useCallback(()=>{Oe(null),Ce(null),be(""),Le(!1),Xe.current=0,Ke(!1),Ve(!1),se(!1),Q.current=!1},[]),Rt=o.useCallback(()=>{pt(""),J(null),lt(!0)},[]),tt=o.useCallback(async()=>{try{const me=await navigator.clipboard.readText();pt(me),J(null)}catch{M.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),ft=o.useCallback(()=>{const me=mm(at,{fallbackName:y});if(!me.ok){J(me.error);return}const kt=gm(me,{name:y,scope:T,type:D,command:_,url:R,environment:U,headers:te,oauthEnabled:ie,oauthClientId:q,oauthClientSecret:L,oauthScope:G,oauthRedirectUri:le,timeout:he,enabled:re},{isNewServer:x});F(kt.name),$(kt.type),C(kt.command??[]),V(kt.url??""),W(kt.environment??[]),O(kt.headers??[]),K(kt.oauthEnabled??!1),B(kt.oauthClientId??""),X(kt.oauthClientSecret??""),Z(kt.oauthScope??""),oe(kt.oauthRedirectUri??""),ee(kt.timeout??""),de(kt.enabled??!0),lt(!1),pt(""),J(null),M.success(t("settings.mcp.page.toast.configImported"))},[at,y,T,D,_,R,U,te,ie,q,L,G,le,he,re,x,t]);o.useEffect(()=>{if(x&&n){F(n.name),P(n.scope||"user"),$(n.type),C(n.command),V(n.url),W(n.environment),O(n.headers),K(n.oauthEnabled),B(n.oauthClientId),X(n.oauthClientSecret),Z(n.oauthScope),oe(n.oauthRedirectUri),ee(n.timeout),de(n.enabled),Ae(!1),ct.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,timeout:n.timeout,enabled:n.enabled};return}if(N){P(N.scope==="project"?"project":"user");const me=go(N.environment),ht=N.type==="remote"?N:null,kt=go(ht?.headers),Xt=ht?.oauth,ss=Xt&&typeof Xt=="object"?Xt:null,Jt=Xt!==!1,ms=N.type,Ns=ms==="local"?N.command??[]:[],us=ms==="remote"?N.url??"":"",It=typeof ht?.timeout=="number"&&Number.isFinite(ht.timeout)?String(ht.timeout):"";$(ms),C(Ns),V(us),W(me),O(kt),K(Jt),B(Jt?ss?.clientId??"":""),X(Jt?ss?.clientSecret??"":""),Z(Jt?ss?.scope??"":""),oe(Jt?ss?.redirectUri??"":""),ee(It),de(N.enabled),Ae(!1),ct.current={mcpType:ms,command:Ns,url:us,envEntries:me,headerEntries:kt,oauthEnabled:Jt,oauthClientId:Jt?ss?.clientId??"":"",oauthClientSecret:Jt?ss?.clientSecret??"":"",oauthScope:Jt?ss?.scope??"":"",oauthRedirectUri:Jt?ss?.redirectUri??"":"",timeout:It,enabled:N.enabled}}},[N,x,n]);const jt=o.useMemo(()=>{const me=ct.current;return me?D!==me.mcpType||re!==me.enabled||JSON.stringify(_)!==JSON.stringify(me.command)||R!==me.url||JSON.stringify(U)!==JSON.stringify(me.envEntries)||JSON.stringify(te)!==JSON.stringify(me.headerEntries)||ie!==me.oauthEnabled||q!==me.oauthClientId||L!==me.oauthClientSecret||G!==me.oauthScope||le!==me.oauthRedirectUri||he!==me.timeout:!1},[D,_,R,U,te,ie,q,L,G,le,he,re]),Je=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(z,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(z,{name:"global",className:"h-3.5 w-3.5"})}],[t]),St=o.useCallback(me=>{$("remote"),V(me),C([])},[]),Fe=o.useCallback(me=>{V(me);const ht=me.trim();ht&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ht)&&/\s/.test(ht)&&($("local"),C(Ic(ht)),V(""))},[]),wt=async()=>{const me=x?y.trim():a??"";if(!me){M.error(t("settings.mcp.page.toast.nameRequired"));return}if(x&&A.some(kt=>kt.name===me)){M.error(t("settings.mcp.page.toast.serverNameExists"));return}if(D==="local"&&_.filter(Boolean).length===0){M.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(D==="remote"&&!R.trim()){M.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ht={name:me,scope:T,type:D,command:_,url:R,environment:U,headers:te,oauthEnabled:ie,oauthClientId:q,oauthClientSecret:L,oauthScope:G,oauthRedirectUri:le,timeout:he,enabled:re};ue(!0);try{const kt=x?await u(ht,d):await c(me,ht,d);kt.ok?(await Ha(Re),gt(),x&&(i(null),r(me)),await h({directory:d,silent:!0}),kt.reloadFailed?M.warning(kt.message||t(x?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:kt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):kt.restartDeferred?M.success(t("settings.view.pendingRestart.saved")):M.success(kt.message||t(x?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):M.error(t("settings.mcp.page.toast.saveFailed"))}catch(kt){M.error(kt instanceof Error?kt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{ue(!1)}},Y=async()=>{if(!a)return;Te(!0);const me=await f(a,d);me.ok?(await Ha(Re),gt(),me.reloadFailed?M.warning(me.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:me.warning||t("settings.mcp.page.toast.refreshListIfStale")}):M.success(me.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),pe(!1)):M.error(t("settings.mcp.page.toast.deleteFailed")),Te(!1)},fe=async()=>{if(a){De(!0);try{if(p[a]?.status==="connected")await b(a,d),M.success(t("settings.mcp.page.toast.disconnected"));else{await w(a,d),await h({directory:d,silent:!0});const ht=Bs.getState().getStatusForDirectory(d)[a];ht?.status==="connected"?M.success(t("settings.mcp.page.toast.connected")):ht?.status==="needs_auth"?M.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ht?.status==="needs_client_registration"?M.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ht?.status==="failed"?M.error(ht.error||t("settings.mcp.page.toast.connectionFailed")):M.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await h({directory:d,silent:!0})}catch(me){M.error(me instanceof Error?me.message:t("settings.mcp.page.toast.connectionFailed"))}finally{De(!1)}}},Me=o.useCallback(()=>x?(M.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):jt?(M.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[jt,x,t]),Ee=o.useCallback(async(me=!1)=>{try{await h({directory:d,silent:me})}catch(ht){me||M.error(ht instanceof Error?ht.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[d,h,t]);o.useEffect(()=>{Ee(!0)},[Ee]),o.useEffect(()=>{it.current=qe,De(!1),je(!1),gt()},[gt,qe]);const rt=o.useCallback(async()=>{if(!a||D!=="remote"||!Me())return;Ve(!0);const me=qe;let ht=null;try{const kt=Bs.getState().getStatusForDirectory(d)[a]?.status;Q.current=kt==="needs_auth"||kt==="needs_client_registration";const{authorizationUrl:Xt,opened:ss,nativeFlow:Jt,completion:ms}=await ud({name:a,directory:d});if(Jt){if(it.current!==me)return;Oe(null),Ce(null),Le(!0),Xe.current=0,M.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),ms?.then(()=>{it.current===me&&(Le(!1),Xe.current=0,Q.current=!1,M.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(us=>{it.current===me&&(Le(!1),Xe.current=0,Q.current=!1,M.error(Ni(us,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const Ns=ec(new URL(Xt).searchParams);if(ht=Ns,it.current!==me||(Oe(Xt),Ce(Ns??null),Le(!0),Xe.current=0,it.current!==me))return;ss?M.message(t(v?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):M.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(kt){await Ha(ht),it.current===me&&M.error(Ni(kt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{it.current===me&&Ve(!1)}},[d,v,D,Me,qe,a,t,e]),ot=o.useCallback(async()=>{if(!a||!Me())return;se(!0);const me=qe;try{if(await m(a,d),it.current!==me)return;Oe(null),Ce(null),be(""),Le(!1),Xe.current=0,await Ha(Re),M.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(ht){it.current===me&&M.error(Ni(ht,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{it.current===me&&se(!1)}},[Re,m,d,Me,qe,a,t,e]),Ge=o.useCallback(async()=>{if(!Ue)return;if((await Aa(Ue)).ok){M.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}M.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Ue,t]),Nt=o.useCallback(async()=>{const me=hm(Ze);if(!me.code){M.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ht=me.stateKey?await jm(me.stateKey):null,kt=me.context??ht,Xt=kt?.name??a,ss=kt?.directory??d;if(!Xt){M.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!kt&&!Me())return;Ke(!0);const Jt=qe;try{if(await k(Xt,me.code,ss),await Ha(me.stateKey??Re),it.current!==Jt)return;be(""),Oe(null),Ce(null),Le(!1),Xe.current=0,M.success(Xt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Xt}))}catch(ms){it.current===Jt&&M.error(Ni(ms,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{it.current===Jt&&Ke(!1)}},[Ze,Re,k,d,Me,qe,a,t,e]),ns=o.useCallback(async()=>{if(!(!a||!Me())){if(!re){M.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}je(!0);try{const me=await I(a,d),ht=me.status?.status;me.warning?M.warning(me.warning):ht==="connected"?M.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ht==="needs_auth"?M.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ht==="needs_client_registration"?M.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ht==="failed"?M.error(me.status?.error||me.error||t("settings.mcp.page.toast.connectionTestFailed")):me.error?M.error(me.error):M.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(me){M.error(me instanceof Error?me.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{je(!1)}}},[d,re,Me,a,t,I]);if(o.useEffect(()=>{if(!Pe||!a)return;const me=window.setInterval(()=>{(async()=>{Xe.current+=1,await h({directory:d,silent:!0});const ht=Bs.getState().getStatusForDirectory(d)[a];if(ht){if(Q.current&&ht.status!=="needs_auth"&&ht.status!=="needs_client_registration"){Le(!1),Xe.current=0,Q.current=!1,Oe(null),be(""),ht.status==="connected"&&M.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!Q.current&&ht.status==="failed"){Le(!1),Xe.current=0,Q.current=!1,M.error(ht.error||t("settings.mcp.page.toast.authorizationFailed"));return}Xe.current>=30&&(Le(!1),Xe.current=0,Q.current=!1,M.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(me)}},[d,Pe,h,a,t]),!a)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Zt=p[a],Qe=a?j[a]:void 0,Be=Zt??Qe,Ct=!x&&!Be&&E.some(me=>me.scope==="mcp"&&me.id.startsWith(`mcp:${a}:`)),Pt=Zt?.status==="connected",es=Zt?.status==="needs_auth"||Zt?.status==="needs_client_registration",ts=v||!a?null:pd(a),rs=async()=>{if(ts)try{await navigator.clipboard.writeText(ts),M.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{M.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},fs=bm(Be?.status,e,Be&&"error"in Be?Be.error:void 0),Rs=me=>{switch(me){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");case"awaiting_restart":return t("settings.mcp.page.status.label.awaitingRestart");default:return me}};return s.jsxs(s.Fragment,{children:[s.jsxs(os,{title:x?t("settings.mcp.page.header.newServer"):a,titleAccessory:x?void 0:s.jsx(xr,{status:Ct?"awaiting_restart":Be?.status,enabled:re,getStatusLabel:Rs,variant:"pill"}),description:x?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(D==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!x&&!Ct?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{variant:Pt?"outline":"default",size:"xs",className:"!font-normal",onClick:fe,disabled:we||!re,children:t(we?"settings.mcp.page.actions.working":Pt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),D==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(H,{variant:es?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{rt()},disabled:_e||!re,children:t(_e?"settings.mcp.page.actions.starting":Pt?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ot()},disabled:ve||!re,children:t(ve?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Pt&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ns()},disabled:ae||!re,children:t(ae?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[Ct&&s.jsx($e,{divider:!1,children:s.jsx("div",{className:"rounded-lg border p-3 border-[var(--status-warning-border)] bg-[var(--status-warning-background)]",children:s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Ot,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(xr,{status:"awaiting_restart",enabled:re,getStatusLabel:Rs})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!x&&!Ct&&ym(Be?.status,Ue,es,Pe)&&s.jsx($e,{divider:!1,children:s.jsxs("div",{className:ye("rounded-lg border p-3",vm(Be?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Ot,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(xr,{status:Be?.status,enabled:re,getStatusLabel:Rs})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:fs}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:T==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:d??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Pt&&s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ns()},disabled:ae||!re,children:t(ae?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Be?.status==="needs_client_registration"&&s.jsxs("div",{className:"space-y-3 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:[s.jsxs("div",{children:[s.jsx(rn,{as:"div",children:t("settings.mcp.page.registration.title")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.description")})]}),ts&&s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.callbackLabel")}),s.jsxs("div",{className:"mt-1 flex items-start gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 break-all font-mono typography-micro text-foreground/80",children:ts}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rs()},children:[s.jsx(z,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]}),s.jsxs("div",{className:"grid gap-3 @xl:grid-cols-2",children:[s.jsx(Kt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(He,{value:q,onChange:me=>{B(me.target.value),K(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(Kt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(He,{type:"password",value:L,onChange:me=>{X(me.target.value),K(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.afterSaving")})]}),Ue&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:Ue}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{hn(Ue)},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ge()},children:[s.jsx(z,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),v&&D==="remote"&&(es||Pe||Ue)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx(rn,{as:"div",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(Ms,{value:Ze,onChange:me=>be(me.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nt()},disabled:Se,children:t(Se?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Pe&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs($e,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:x?s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:Rt,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(z,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[x&&s.jsxs(Ht,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(He,{value:y,onChange:me=>F(me.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 min-w-0 max-w-full shrink font-mono px-2",autoFocus:!0}),s.jsxs(Et,{value:T,onValueChange:me=>P(me),children:[s.jsxs(Dt,{size:Gt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(z,{name:T==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(T==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Mt,{align:"end",children:[s.jsx(ut,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(ut,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(mt,{checked:re,onChange:de,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs($e,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(Xr,{items:Je,activeId:D,onSelect:me=>$(me),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),D==="local"?s.jsx(fm,{value:_,onChange:C,preview:me=>t("settings.mcp.page.connection.previewArgs",{count:me}),onDetectUrl:St}):s.jsx(He,{value:R,onChange:me=>Fe(me.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(D==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),D==="remote"&&s.jsx($e,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(yn,{open:Ne,onOpenChange:Ae,children:[s.jsxs(jn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",te.length," ",t("settings.mcp.page.advanced.headers"),he?` · ${he}ms`:"",")"]})]}),Ne?s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(wn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("div",{className:"space-y-2",children:s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Ot,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Yt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(He,{type:"number",min:"1",step:"1",value:he,onChange:me=>ee(me.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]})}),s.jsxs("div",{children:[s.jsxs(rn,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),te.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",te.length,")"]})]}),s.jsx(Wo,{value:te,onChange:O,keyTransform:me=>me.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:me=>t("settings.mcp.page.toast.importedVariablesCount",{count:me}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]})]})})]})}),s.jsx($e,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:U.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",U.length,")"]}):null,settingsItem:"mcp.environment",children:U.length===0?s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>W([{key:"",value:""}]),children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Wo,{value:U,onChange:W,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:me=>t("settings.mcp.page.toast.importedVariablesCount",{count:me}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(H,{onClick:wt,disabled:ke||!jt&&!x,size:"xs",className:"!font-normal",children:t(ke?"settings.common.actions.saving":x?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!x&&s.jsx(H,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>pe(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(zt,{open:We,onOpenChange:me=>{me||(lt(!1),pt(""),J(null))},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Vt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Ms,{value:at,onChange:me=>{pt(me.target.value),J(null)},placeholder:`{
15
+ "mcpServers": {
16
+ "postgres": {
17
+ "command": "npx",
18
+ "args": ["-y", "@modelcontextprotocol/server-postgres"]
19
+ }
20
+ }
21
+ }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),bt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:bt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:tt,type:"button",children:[s.jsx(z,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(is,{children:[s.jsx(H,{variant:"outline",onClick:()=>{lt(!1),pt(""),J(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{onClick:ft,disabled:!at.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(zt,{open:xe,onOpenChange:me=>{!me&&!Ie&&pe(!1)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Vt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(is,{children:[s.jsx(H,{variant:"outline",onClick:()=>pe(!1),disabled:Ie,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{variant:"destructive",size:"sm",onClick:Y,disabled:Ie,children:t(Ie?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function Nm(t){return t.trim().length>0}function Sm(t){return t.trimEnd()}function Cm(t,e){return s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",e,"]"]}),t]},e)}const Ri=()=>{try{const e=Xs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=An.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},Im=800,Pm=5e3,Am="__default__",Kr=new Map,br=new Map,Tm=1500,Pc=t=>t?.trim()||Am,Em=t=>{Kr.delete(Pc(t))},vs=wc()(Yu(Zu((t,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:a=>t({selectedId:a}),setDraft:a=>t({draft:a}),loadPlugins:async a=>{const n=Ri(),i=Pc(n),r=Date.now(),l=Kr.get(i)??0,u=e().entries.length>0||e().files.length>0;if(!a?.force&&u&&r-l<Pm)return!0;const c=br.get(i);if(!a?.force&&c)return c;const f=(async()=>{t({isLoading:!0});try{const d=await xt(On("/api/config/plugins",n),{headers:qa(n)});if(!d.ok)throw new Error("Failed to load plugins");const v=await Fi(d);return t({entries:v.entries??[],files:v.files??[],isLoading:!1}),Kr.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(d){return console.error("[PluginsStore] Failed to load plugins:",d),t({isLoading:!1}),!1}})();br.set(i,f);try{return await f}finally{br.delete(i)}},loadRegistryInfo:async a=>{const n=Mm(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=Ri(),r={...e().registryInfo};for(const l of Rm(n)){const u=await xt(Dm(l,a?.force===!0,i),{headers:qa(i)});if(!u.ok)throw new Error("Failed to load plugin registry info");const c=await Fi(u);for(const f of c.results??[])r[f.spec]=f}return t({registryInfo:r,isLoadingRegistry:!1}),!0}catch(i){return console.error("[PluginsStore] Failed to load plugin registry info:",i),t({isLoadingRegistry:!1}),!1}},updateToLatest:async a=>{const n=e().entries.find(r=>r.id===a);if(!n)return{ok:!1};const i=e().registryInfo[n.spec];return!i||i.kind!=="npm-ok"||!i.hasUpdate||!i.latestVersion?{ok:!1}:await e().updateEntry(a,{spec:`${i.name}@${i.latestVersion}`})},createEntry:async a=>{const n=await Na("Creating plugin entry…",async i=>await xt(On("/api/config/plugins/entry",i),{method:"POST",headers:Si(i),body:JSON.stringify(Jo(a))}),e,{restartId:a.spec});return n.ok&&e().loadRegistryInfo({specs:[a.spec],force:!0}),n},updateEntry:async(a,n)=>{const i=e().entries.find(u=>u.id===a)?.spec,r=n.spec??i,l=await Na("Updating plugin entry…",async u=>await xt(On(`/api/config/plugins/entry/${encodeURIComponent(a)}`,u),{method:"PATCH",headers:Si(u),body:JSON.stringify(Jo(n))}),e,{restartId:a});return l.ok&&r&&e().loadRegistryInfo({specs:[r],force:!0}),l},deleteEntry:async a=>{const n=e().entries.find(r=>r.id===a),i=await Na("Deleting plugin entry…",async r=>await xt(On(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:qa(r)}),e,{restartId:a});if(i.ok&&e().selectedId===a&&t({selectedId:null}),i.ok&&n){const r={...e().registryInfo};delete r[n.spec],t({registryInfo:r})}return i},readFile:async a=>{try{const n=Ri(),i=await xt(On(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:qa(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await Fi(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>Na("Creating plugin file…",async n=>await xt(On("/api/config/plugins/file",n),{method:"POST",headers:Si(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>Na("Updating plugin file…",async i=>await xt(On(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:Si(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await Na("Deleting plugin file…",async i=>await xt(On(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:qa(i)}),e,{restartId:a});return n.ok&&e().selectedId===a&&t({selectedId:null}),n},getById:a=>e().entries.find(n=>n.id===a)??e().files.find(n=>n.id===a)}),{name:"plugins-store",storage:mu(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function On(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function Dm(t,e,a){const n=new URLSearchParams;e&&n.set("refresh","true"),a&&n.set("directory",a);const i=n.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${i?`&${i}`:""}`}function Mm(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function Rm(t){const e=[];let a=[],n=0;for(const i of t){const r=encodeURIComponent(i),l=a.length===0?r.length:n+1+r.length;a.length>0&&l>Tm?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function qa(t){return t?{"x-opencode-directory":t}:void 0}function Si(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function Jo(t){const e={};return t.spec!==void 0&&(e.spec=t.spec),t.options!==void 0&&(e.options=t.options),t.scope!==void 0&&(e.scope=t.scope),e}async function Na(t,e,a,n){try{const i=Ri(),r=await e(i),l=await Fi(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return Em(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):Ql(l,"plugins",{id:n?.restartId})?(await a().loadPlugins({force:!0}),{ok:!0,restartDeferred:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):(l?.requiresReload&&(gd(t),await hd({message:l.message,delayMs:l.reloadDelayMs??Im,scopes:["all"]})),await a().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning})}catch(i){return console.error("[PluginsStore] Failed to update plugin configuration:",i),{ok:!1}}}async function Fi(t){return await t.json()}const Fm=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Om(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}const Lm=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=et(),i=vs(C=>C.createEntry),r=vs(C=>C.createFile),[l,u]=o.useState("npm"),[c,f]=o.useState(""),[d,v]=o.useState(""),[p,j]=o.useState(""),[h,w]=o.useState(""),[b,k]=o.useState(a),[m,I]=o.useState(!1),E=o.useCallback(()=>{f(""),v(""),j(""),w(""),k(a)},[a]);o.useEffect(()=>{t&&(u("npm"),E())},[t,E]);const A=C=>{C!==l&&(u(C),E())},N=o.useMemo(()=>Om(d),[d]),x=!N.ok,y=l==="file"&&p.trim()!==""&&!Fm.test(p.trim()),F=(l==="npm"||l==="path")&&c.trim()==="",T=l==="file"&&h.trim()==="",P=l==="file"&&p.trim()==="",D=m||x||l==="npm"&&F||l==="path"&&F||l==="file"&&(P||y||T),$=async()=>{if(!D){I(!0);try{let C;l==="file"?C=await r({fileName:p.trim(),content:h,scope:b}):C=await i({spec:c.trim(),options:N.ok?N.value:void 0,scope:b}),C.ok?(C.restartDeferred?M.success(n("settings.view.pendingRestart.saved")):M.success(C.message||n("settings.plugins.toast.created")),C.reloadFailed&&M.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):M.error(C.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{I(!1)}}},_=o.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(zt,{open:t,onOpenChange:C=>{!C&&m||e(C)},children:s.jsxs(Ut,{className:"max-w-xl",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Vt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(Xr,{items:_,activeId:l,onSelect:C=>A(C),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.spec")}),s.jsx(He,{id:"plugin-spec",value:c,onChange:C=>f(C.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":F?!1:void 0,disabled:m}),F&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.options")}),s.jsx(Ms,{id:"plugin-options",value:d,onChange:C=>v(C.target.value),rows:5,className:"font-mono",hasError:x,disabled:m}),x&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(He,{id:"plugin-filename",value:p,onChange:C=>j(C.target.value),placeholder:"my-plugin.ts","aria-invalid":y||void 0,disabled:m}),y&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.content")}),s.jsx(Ms,{id:"plugin-content",value:h,onChange:C=>w(C.target.value),rows:16,className:"font-mono",disabled:m})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(C=>{const R=b===C,V=n(C==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>k(C),disabled:m,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(Gr,{checked:R,onChange:()=>k(C),ariaLabel:V}),s.jsx("span",{className:ye("typography-ui-label font-normal",R?"text-foreground":"text-foreground/60"),children:V})]},C)})})]})]}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:m,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(H,{size:"sm",onClick:()=>{$()},disabled:D,children:[m?s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},Km=t=>{const e=dt.c(33),{spec:a}=t;let n;e[0]!==a?(n=u=>u.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=vs(n),{t:r}=et();if(!i)return null;const l=zm;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(z,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=u):u=e[2];let c;e[3]!==i.latestVersion?(c=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[u,i.latestVersion]}),e[3]=i.latestVersion,e[4]=c):c=e[4];let f;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==c?(f=l(c,r("settings.plugins.registry.badge.update.tooltip",{current:i.currentVersion??"",latest:i.latestVersion})),e[5]=i.currentVersion,e[6]=i.latestVersion,e[7]=r,e[8]=c,e[9]=f):f=e[9],f}case"npm-missing-version":{let u;e[10]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=u):u=e[10];let c;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(c=l(u,r("settings.plugins.registry.badge.missingVersion.tooltip",{version:i.currentVersion,name:i.name})),e[11]=i.currentVersion,e[12]=i.name,e[13]=r,e[14]=c):c=e[14],c}case"npm-missing-package":{let u;e[15]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=u):u=e[15];let c;return e[16]!==i.name||e[17]!==r?(c=l(u,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=c):c=e[18],c}case"npm-malformed":{let u;e[19]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=u):u=e[19];let c;return e[20]!==r?(c=l(u,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=c):c=e[21],c}case"npm-network":{let u;e[22]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(z,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=u):u=e[22];let c;return e[23]!==r?(c=l(u,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=c):c=e[24],c}case"path-missing":{let u;e[25]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=u):u=e[25];let c;return e[26]!==i.absolutePath||e[27]!==r?(c=l(u,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=c):c=e[28],c}case"path-unreadable":{let u;e[29]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=u):u=e[29];let c;return e[30]!==i.absolutePath||e[31]!==r?(c=l(u,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function zm(t,e){return s.jsxs(Wr,{children:[s.jsx(Jr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(tc,{children:e})]})}const Ac=t=>{const e=dt.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,u=l===void 0?"sidebar":l,c=ds(),f=o.useRef(null),[d,v]=o.useState(!1),[p,j]=o.useState(!1),h=u==="background"||c?"bg-background":"bg-sidebar",w=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const D=f.current;if(!D){v(!1),j(!1);return}if(!(D.scrollHeight>D.clientHeight+1)){v(!1),j(!1);return}v(D.scrollTop>1),j(D.scrollTop+D.clientHeight<D.scrollHeight-1)},e[0]=b):b=e[0];const k=b;let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{k()},e[1]=m):m=e[1];let I;e[2]!==i?(I=[i,k],e[2]=i,e[3]=I):I=e[3],o.useEffect(m,I);let E,A;e[4]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{const D=f.current;if(!D)return;const $=()=>k();return D.addEventListener("scroll",$,{passive:!0}),()=>D.removeEventListener("scroll",$)},A=[k],e[4]=E,e[5]=A):(E=e[4],A=e[5]),o.useEffect(E,A);let N;e[6]!==h||e[7]!==r?(N=ye("flex h-full flex-col",h,r),e[6]=h,e[7]=r,e[8]=N):N=e[8];let x;e[9]!==i?(x=s.jsx(ks,{ref:f,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=x):x=e[10];let y;e[11]!==w||e[12]!==d?(y=d&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${w} 0%, transparent 100%)`}}),e[11]=w,e[12]=d,e[13]=y):y=e[13];let F;e[14]!==w||e[15]!==p?(F=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${w} 0%, transparent 100%)`}}),e[14]=w,e[15]=p,e[16]=F):F=e[16];let T;e[17]!==F||e[18]!==x||e[19]!==y?(T=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[x,y,F]}),e[17]=F,e[18]=x,e[19]=y,e[20]=T):T=e[20];let P;return e[21]!==n||e[22]!==a||e[23]!==T||e[24]!==N?(P=s.jsxs("div",{className:N,children:[a,T,n]}),e[21]=n,e[22]=a,e[23]=T,e[24]=N,e[25]=P):P=e[25],P},zr=t=>{const e=dt.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:u,className:c}=t,f=i===void 0?!1:i,d=u&&u.length>0,v=f?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==c||e[1]!==v?(p=ye("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",v,c),e[0]=c,e[1]=v,e[2]=p):p=e[2];let j;e[3]!==a?(j=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=j):j=e[4];let h;e[5]!==l||e[6]!==j?(h=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,j]}),e[5]=l,e[6]=j,e[7]=h):h=e[7];let w;e[8]!==n?(w=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=w):w=e[9];let b;e[10]!==r||e[11]!==h||e[12]!==w?(b=s.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-ring",tabIndex:0,children:[h,w]}),e[10]=r,e[11]=h,e[12]=w,e[13]=b):b=e[13];let k;e[14]!==u||e[15]!==d?(k=d&&s.jsxs(bn,{children:[s.jsx(fn,{asChild:!0,children:s.jsx(H,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(xn,{align:"end",className:"w-fit min-w-20",children:u.map(Um)})]}),e[14]=u,e[15]=d,e[16]=k):k=e[16];let m;e[17]!==b||e[18]!==k?(m=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[b,k]}),e[17]=b,e[18]=k,e[19]=m):m=e[19];let I;return e[20]!==p||e[21]!==m?(I=s.jsx("div",{className:p,children:m}),e[20]=p,e[21]=m,e[22]=I):I=e[22],I};function Um(t){const e=t.icon;return s.jsxs(vn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:ye(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(z,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const _m=t=>t.parsedKind==="npm"?"code-box":"folder",$m=t=>{const e=dt.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=et(),{entries:r,files:l,selectedId:u,setSelected:c,deleteEntry:f,deleteFile:d,loadPlugins:v}=vs(Hs(Bm)),p=vs(Vm),j=vs(Hm),h=vs(qm),w=vs(Gm),[b,k]=o.useState(null),[m,I]=o.useState(!1),[E,A]=o.useState(!1);let N,x;e[0]!==v?(N=()=>{v()},x=[v],e[0]=v,e[1]=N,e[2]=x):(N=e[1],x=e[2]),o.useEffect(N,x);let y,F;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{const tt=()=>A(!0);return window.addEventListener("openchamber:settings-open-plugin-add",tt),()=>window.removeEventListener("openchamber:settings-open-plugin-add",tt)},F=[],e[3]=y,e[4]=F):(y=e[3],F=e[4]),o.useEffect(y,F);let T;if(e[5]!==r||e[6]!==p){T={userEntries:0,projectEntries:0};for(const tt of r){const ft=p[tt.spec];ft?.kind==="npm-ok"&&ft.hasUpdate&&(tt.scope==="user"?T.userEntries=T.userEntries+1:tt.scope==="project"&&(T.projectEntries=T.projectEntries+1))}e[5]=r,e[6]=p,e[7]=T}else T=e[7];const P=T;let D;e[8]!==r?(D=r.filter(Wm),e[8]=r,e[9]=D):D=e[9];const $=D;let _;e[10]!==r?(_=r.filter(Jm),e[10]=r,e[11]=_):_=e[11];const C=_;let R;e[12]!==l?(R=l.filter(Qm),e[12]=l,e[13]=R):R=e[13];const V=R;let U;e[14]!==l?(U=l.filter(Ym),e[14]=l,e[15]=U):U=e[15];const W=U,te=r.length+l.length,O=te===0;let ie;e[16]!==n?(ie=()=>{n?n():A(!0)},e[16]=n,e[17]=ie):ie=e[17];const K=ie;let q;e[18]!==a||e[19]!==c?(q=tt=>{c(tt),a?.()},e[18]=a,e[19]=c,e[20]=q):q=e[20];const B=q;let L;e[21]!==r||e[22]!==p||e[23]!==i||e[24]!==w?(L=async tt=>{const ft=r.find(Fe=>Fe.id===tt);if(!ft)return;const jt=p[ft.spec];if(!jt||jt.kind!=="npm-ok"||!jt.hasUpdate||!jt.latestVersion)return;const Je=jt.latestVersion;(await w(tt)).ok?M.success(i("settings.plugins.toast.updatedToLatest",{version:Je})):M.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=p,e[23]=i,e[24]=w,e[25]=L):L=e[25];const X=L;let G;e[26]!==h||e[27]!==i?(G=async()=>{M.info(i("settings.plugins.toast.refreshing"));try{await h({force:!0})}catch{M.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=h,e[27]=i,e[28]=G):G=e[28];const Z=G;let le;e[29]!==f||e[30]!==d||e[31]!==b||e[32]!==i?(le=async()=>{if(!b)return;I(!0);const tt=b.kind==="entry"?await f(b.id):await d(b.id);tt.ok?M.success(tt.message||i("settings.plugins.sidebar.toast.deleted",{name:b.label})):M.error(i("settings.plugins.sidebar.toast.deleteFailed")),k(null),I(!1)},e[29]=f,e[30]=d,e[31]=b,e[32]=i,e[33]=le):le=e[33];const oe=le;let he;e[34]!==B||e[35]!==X||e[36]!==p||e[37]!==u||e[38]!==i?(he=tt=>{const ft=p[tt.spec],jt=ft?.kind==="npm-ok"&&ft.hasUpdate&&!!ft.latestVersion,Je=[];return jt&&Je.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{X(tt.id)}}),Je.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>k({kind:"entry",id:tt.id,label:tt.spec})}),s.jsx(zr,{title:s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:tt.spec}),s.jsx(Km,{spec:tt.spec})]}),metadata:tt.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:u===tt.id,onSelect:()=>B(tt.id),icon:s.jsx(z,{name:_m(tt),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Je},tt.id)},e[34]=B,e[35]=X,e[36]=p,e[37]=u,e[38]=i,e[39]=he):he=e[39];const ee=he;let re;e[40]!==B||e[41]!==u||e[42]!==i?(re=tt=>s.jsx(zr,{title:tt.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:u===tt.id,onSelect:()=>B(tt.id),icon:s.jsx(z,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>k({kind:"file",id:tt.id,label:tt.fileName})}]},tt.id),e[40]=B,e[41]=u,e[42]=i,e[43]=re):re=e[43];const de=re;let ke;e[44]!==i?(ke=(tt,ft,jt)=>{const Je=jt===void 0?0:jt;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[tt,Je>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(Je===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Je})})]}),ft]})},e[44]=i,e[45]=ke):ke=e[45];const ue=ke;let xe;e[46]!==i?(xe=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=xe):xe=e[47];let pe;e[48]!==xe?(pe=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:kn,children:xe})}),e[48]=xe,e[49]=pe):pe=e[49];let Ie;e[50]!==i||e[51]!==te?(Ie=i("settings.plugins.sidebar.total",{count:te}),e[50]=i,e[51]=te,e[52]=Ie):Ie=e[52];let Te;e[53]!==Ie?(Te=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ie}),e[53]=Ie,e[54]=Te):Te=e[54];let we;e[55]!==Z?(we=()=>{Z()},e[55]=Z,e[56]=we):we=e[56];let De;e[57]!==i?(De=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=De):De=e[58];let _e;e[59]!==i?(_e=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=_e):_e=e[60];const Ve=j?"size-4 animate-spin":"size-4";let ve;e[61]!==Ve?(ve=s.jsx(z,{name:"refresh",className:Ve}),e[61]=Ve,e[62]=ve):ve=e[62];let se;e[63]!==j||e[64]!==we||e[65]!==De||e[66]!==_e||e[67]!==ve?(se=s.jsx(H,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:we,disabled:j,"aria-label":De,title:_e,children:ve}),e[63]=j,e[64]=we,e[65]=De,e[66]=_e,e[67]=ve,e[68]=se):se=e[68];let ae;e[69]!==i?(ae=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=ae):ae=e[70];let je;e[71]!==i?(je=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=je):je=e[72];let Se;e[73]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(z,{name:"add",className:"size-4"}),e[73]=Se):Se=e[73];let Ke;e[74]!==K||e[75]!==ae||e[76]!==je?(Ke=s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:K,"aria-label":ae,title:je,children:Se}),e[74]=K,e[75]=ae,e[76]=je,e[77]=Ke):Ke=e[77];let Ue;e[78]!==se||e[79]!==Ke?(Ue=s.jsxs("div",{className:"flex items-center gap-1",children:[se,Ke]}),e[78]=se,e[79]=Ke,e[80]=Ue):Ue=e[80];let Oe;e[81]!==Te||e[82]!==Ue?(Oe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Te,Ue]}),e[81]=Te,e[82]=Ue,e[83]=Oe):Oe=e[83];let Re;e[84]!==pe||e[85]!==Oe?(Re=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[pe,Oe]}),e[84]=pe,e[85]=Oe,e[86]=Re):Re=e[86];let Ce;e[87]!==O||e[88]!==C||e[89]!==W||e[90]!==ee||e[91]!==de||e[92]!==ue||e[93]!==i||e[94]!==P||e[95]!==$||e[96]!==V?(Ce=O?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:i("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:i("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$.length>0&&ue(i("settings.plugins.sidebar.group.userEntries"),$.map(ee),P.userEntries),V.length>0&&ue(i("settings.plugins.sidebar.group.userFiles"),V.map(de)),C.length>0&&ue(i("settings.plugins.sidebar.group.projectEntries"),C.map(ee),P.projectEntries),W.length>0&&ue(i("settings.plugins.sidebar.group.projectFiles"),W.map(de))]}),e[87]=O,e[88]=C,e[89]=W,e[90]=ee,e[91]=de,e[92]=ue,e[93]=i,e[94]=P,e[95]=$,e[96]=V,e[97]=Ce):Ce=e[97];let Ze;e[98]!==Re||e[99]!==Ce?(Ze=s.jsx(Ac,{variant:"background",header:Re,children:Ce}),e[98]=Re,e[99]=Ce,e[100]=Ze):Ze=e[100];let be;e[101]!==E?(be=s.jsx(Lm,{open:E,onOpenChange:A}),e[101]=E,e[102]=be):be=e[102];const Pe=b!==null;let Le;e[103]!==m?(Le=tt=>{!tt&&!m&&k(null)},e[103]=m,e[104]=Le):Le=e[104];let Xe;e[105]!==i?(Xe=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=Xe):Xe=e[106];let Q;e[107]!==Xe?(Q=s.jsx(Bt,{children:Xe}),e[107]=Xe,e[108]=Q):Q=e[108];const Ne=b?.label??"";let Ae;e[109]!==i||e[110]!==Ne?(Ae=i("settings.plugins.sidebar.deleteDialog.description",{name:Ne}),e[109]=i,e[110]=Ne,e[111]=Ae):Ae=e[111];let We;e[112]!==Ae?(We=s.jsx(Vt,{children:Ae}),e[112]=Ae,e[113]=We):We=e[113];let lt;e[114]!==Q||e[115]!==We?(lt=s.jsxs($t,{children:[Q,We]}),e[114]=Q,e[115]=We,e[116]=lt):lt=e[116];let at;e[117]===Symbol.for("react.memo_cache_sentinel")?(at=()=>k(null),e[117]=at):at=e[117];let pt;e[118]!==i?(pt=i("settings.common.actions.cancel"),e[118]=i,e[119]=pt):pt=e[119];let bt;e[120]!==m||e[121]!==pt?(bt=s.jsx(H,{size:"sm",variant:"ghost",onClick:at,disabled:m,children:pt}),e[120]=m,e[121]=pt,e[122]=bt):bt=e[122];let J;e[123]!==m||e[124]!==i?(J=i(m?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=m,e[124]=i,e[125]=J):J=e[125];let qe;e[126]!==oe||e[127]!==m||e[128]!==J?(qe=s.jsx(H,{size:"sm",variant:"destructive",onClick:oe,disabled:m,children:J}),e[126]=oe,e[127]=m,e[128]=J,e[129]=qe):qe=e[129];let it;e[130]!==bt||e[131]!==qe?(it=s.jsxs(is,{children:[bt,qe]}),e[130]=bt,e[131]=qe,e[132]=it):it=e[132];let ct;e[133]!==lt||e[134]!==it?(ct=s.jsxs(Ut,{className:"max-w-md",children:[lt,it]}),e[133]=lt,e[134]=it,e[135]=ct):ct=e[135];let gt;e[136]!==Pe||e[137]!==Le||e[138]!==ct?(gt=s.jsx(zt,{open:Pe,onOpenChange:Le,children:ct}),e[136]=Pe,e[137]=Le,e[138]=ct,e[139]=gt):gt=e[139];let Rt;return e[140]!==Ze||e[141]!==be||e[142]!==gt?(Rt=s.jsxs(s.Fragment,{children:[Ze,be,gt]}),e[140]=Ze,e[141]=be,e[142]=gt,e[143]=Rt):Rt=e[143],Rt};function Bm(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function Vm(t){return t.registryInfo}function Hm(t){return t.isLoadingRegistry}function qm(t){return t.loadRegistryInfo}function Gm(t){return t.updateToLatest}function Wm(t){return t.scope==="user"}function Jm(t){return t.scope==="project"}function Qm(t){return t.scope==="user"}function Ym(t){return t.scope==="project"}const Zm=({entryId:t,spec:e})=>{const{t:a}=et(),n=vs(v=>v.registryInfo[e]),i=vs(v=>v.updateToLatest),[r,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const v=n.latestVersion,p=n.currentVersion??"",j=async()=>{l(!0);try{(await i(t)).ok?M.success(a("settings.plugins.toast.updatedToLatest",{version:v})):M.error(a("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:p,latest:v})})]}),s.jsx(H,{variant:"default",size:"sm",onClick:()=>{j()},disabled:r,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:v})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const u=n.kind==="path-unreadable",c=u?"var(--status-warning)":"var(--status-error)",f=u?"alert":"error-warning",d=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:f,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:c},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:d})]})]})};function Xm(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}function Tc(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function Qo(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Tc(t.options),fileName:"",content:""}}function Yo(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const Zo=t=>{const e=dt.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=ye("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]=i):i=e[0];let r;return e[1]!==n||e[2]!==a?(r=s.jsx("span",{className:i,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=r):r=e[3],r},eg=()=>{const{t}=et(),e=vs(b=>b.selectedId),a=vs(b=>b.entries),n=vs(b=>b.files),i=vs(b=>b.draft),r=vs(b=>b.setDraft),l=vs(b=>b.updateEntry),u=vs(b=>b.updateFile),c=vs(b=>b.readFile),f=o.useMemo(()=>e?a.find(b=>b.id===e)??null:null,[a,e]),d=o.useMemo(()=>e?n.find(b=>b.id===e)??null:null,[n,e]),[v,p]=o.useState(!1),[j,h]=o.useState(!1),w=o.useRef(new Map);if(o.useEffect(()=>{let b=!1;return f?(r(Qo(f)),()=>{b=!0}):d?(h(!0),(async()=>{const k=await c(d.id);if(b)return;h(!1);const m=k?.content??"";w.current.set(d.id,m),r(Yo(d,m))})(),()=>{b=!0}):(r(null),()=>{b=!0})},[f,d,c,r]),!e)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(f&&i&&i.mode==="entry"){const b=Xm(i.optionsJson),k=b.ok,m=i.spec!==f.spec||i.optionsJson!==Tc(f.options),I=()=>{r(Qo(f))},E=async()=>{if(!k)return;const A=i.spec.trim();if(!A){M.error(t("settings.plugins.validation.specRequired"));return}p(!0);try{const N=await l(f.id,{spec:A,options:b.value});N.ok?N.reloadFailed?M.warning(N.message||t("settings.plugins.toast.reloadFailed"),{description:N.warning}):N.restartDeferred?M.success(t("settings.view.pendingRestart.saved")):M.success(N.message||t("settings.plugins.toast.updated")):M.error(N.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsxs(os,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(Zo,{scope:f.scope,label:f.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx($e,{divider:!1,children:s.jsx(Zm,{entryId:f.id,spec:f.spec})}),s.jsx($e,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(He,{value:i.spec,onChange:A=>r({...i,spec:A.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs($e,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(Ms,{value:i.optionsJson,onChange:A=>r({...i,optionsJson:A.target.value}),rows:10,className:ye("font-mono typography-meta min-h-[200px]",!k&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!k&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:t("settings.plugins.page.field.options.invalidJson")}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{E()},disabled:!m||!k||v,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:I,disabled:!m||v,children:t("settings.plugins.page.action.discard")})]})]})]})}if(d&&i&&i.mode==="file"){const b=w.current.get(d.id)??"",k=i.content!==b||i.fileName!==d.fileName,m=()=>{(async()=>{h(!0);const A=(await c(d.id))?.content??"";h(!1),w.current.set(d.id,A),r(Yo(d,A))})()},I=async()=>{p(!0);try{const E=await u(d.id,{content:i.content});E.ok?(w.current.set(d.id,i.content),E.reloadFailed?M.warning(E.message||t("settings.plugins.toast.reloadFailed"),{description:E.warning}):E.restartDeferred?M.success(t("settings.view.pendingRestart.saved")):M.success(E.message||t("settings.plugins.toast.updated"))):M.error(E.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsx(os,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(Zo,{scope:d.scope,label:d.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:ye("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:d.fileName})]}),showSaveStatus:!1,children:s.jsxs($e,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(Ms,{value:i.content,onChange:E=>r({...i,content:E.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:j}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{I()},disabled:!k||v||j,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:m,disabled:v||j,children:t("settings.plugins.page.action.discard")})]})]})})}return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(z,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},tg="<built-in>",ei=t=>t?.path===tg,Ur=t=>!!t&&!ei(t)&&t.renamable===!0,sg=t=>{const e=dt.c(157),{onItemSelect:a}=t,{t:n}=et(),[i,r]=o.useState(null),[l,u]=o.useState(""),[c,f]=o.useState(null),[d,v]=o.useState(!1),[p,j]=o.useState(null),{selectedSkillName:h,setSelectedSkill:w,setSkillDraft:b,deleteSkill:k,renameSkill:m,getSkillDetail:I}=Zs(Hs(ng)),E=Gs();let A;e[0]!==E?(A=Fe=>qr(Fe,E),e[0]=E,e[1]=A):A=e[1];const N=Zs(A),x=Zs(ag);let y,F;e[2]!==x||e[3]!==E?(y=()=>{x(E)},F=[x,E],e[2]=x,e[3]=E,e[4]=y,e[5]=F):(y=e[4],F=e[5]),o.useEffect(y,F);let T;e[6]!==a||e[7]!==w||e[8]!==b||e[9]!==N?(T=()=>{let Fe="new-skill",wt=1;for(;N.some(Y=>Y.name===Fe);)Fe=`new-skill-${wt}`,wt++;b({name:Fe,scope:"user",source:"opencode",description:""}),w(Fe),a?.()},e[6]=a,e[7]=w,e[8]=b,e[9]=N,e[10]=T):T=e[10];const P=T;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=async Fe=>{ei(Fe)||f(Fe)},e[11]=D):D=e[11];const $=D;let _;e[12]!==c||e[13]!==k||e[14]!==E||e[15]!==n?(_=async()=>{if(!c)return;if(ei(c)){f(null);return}v(!0),await k(c.name,E)?(M.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),f(null)):M.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),v(!1)},e[12]=c,e[13]=k,e[14]=E,e[15]=n,e[16]=_):_=e[16];const C=_;let R;e[17]!==I||e[18]!==w||e[19]!==b||e[20]!==E||e[21]!==N||e[22]!==n?(R=async Fe=>{if(ei(Fe))return;const wt=Fe.name;let Y=1,fe=`${wt}-copy`;for(;N.some(Ee=>Ee.name===fe);)Y++,fe=`${wt}-copy-${Y}`;const Me=await I(Fe.name,E);if(!Me){M.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}b({name:fe,scope:Fe.scope||"user",source:Fe.source||"opencode",description:(Me.sources.md.fields.includes("description"),""),instructions:""}),w(fe)},e[17]=I,e[18]=w,e[19]=b,e[20]=E,e[21]=N,e[22]=n,e[23]=R):R=e[23];const V=R;let U;e[24]===Symbol.for("react.memo_cache_sentinel")?(U=Fe=>{Ur(Fe)&&(u(Fe.name),r(Fe))},e[24]=U):U=e[24];const W=U;let te;e[25]!==i||e[26]!==l||e[27]!==m||e[28]!==w||e[29]!==E||e[30]!==N||e[31]!==n?(te=async()=>{if(!i)return;if(!Ur(i)){r(null);return}const Fe=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Fe){M.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Fe===i.name){r(null);return}if(N.some(Y=>Y.name===Fe)){M.error(n("settings.skills.page.toast.skillExists"));return}await m(i.name,Fe,E)?(M.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Fe})),w(Fe)):M.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[25]=i,e[26]=l,e[27]=m,e[28]=w,e[29]=E,e[30]=N,e[31]=n,e[32]=te):te=e[32];const O=te;let ie;e[33]!==N?(ie=N.filter(ig),e[33]=N,e[34]=ie):ie=e[34];const K=ie;let q;e[35]!==N?(q=N.filter(rg),e[35]=N,e[36]=q):q=e[36];const B=q;let L;e[37]===Symbol.for("react.memo_cache_sentinel")?(L=function(wt){const Y={},fe=[];for(const Ee of wt)Ee.group?(Y[Ee.group]||(Y[Ee.group]=[]),Y[Ee.group].push(Ee)):fe.push(Ee);const Me=Object.keys(Y).sort(og).map(Ee=>({name:Ee,skills:[...Y[Ee]].sort(lg)}));return fe.sort(cg),{sortedGroups:Me,ungrouped:fe}},e[37]=L):L=e[37];const X=L;let G;e[38]!==K?(G=X(K),e[38]=K,e[39]=G):G=e[39];const Z=G;let le;e[40]!==B?(le=X(B),e[40]=B,e[41]=le):le=e[41];const oe=le;let he;e[42]===Symbol.for("react.memo_cache_sentinel")?(he=ye("flex h-full flex-col","bg-background"),e[42]=he):he=e[42];let ee;e[43]!==n?(ee=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ee):ee=e[44];let re;e[45]!==ee?(re=s.jsx("h2",{className:`${kn} mb-3`,children:ee}),e[45]=ee,e[46]=re):re=e[46];let de;e[47]===Symbol.for("react.memo_cache_sentinel")?(de=s.jsx(ri,{className:"mb-3"}),e[47]=de):de=e[47];let ke;e[48]!==N.length||e[49]!==n?(ke=n("settings.skills.sidebar.total",{count:N.length}),e[48]=N.length,e[49]=n,e[50]=ke):ke=e[50];let ue;e[51]!==ke?(ue=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ke}),e[51]=ke,e[52]=ue):ue=e[52];let xe;e[53]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[53]=xe):xe=e[53];let pe;e[54]!==P?(pe=s.jsx(H,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:P,children:xe}),e[54]=P,e[55]=pe):pe=e[55];let Ie;e[56]!==ue||e[57]!==pe?(Ie=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ue,pe]}),e[56]=ue,e[57]=pe,e[58]=Ie):Ie=e[58];let Te;e[59]!==re||e[60]!==Ie?(Te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[re,de,Ie]}),e[59]=re,e[60]=Ie,e[61]=Te):Te=e[61];let we;e[62]!==Z||e[63]!==oe||e[64]!==V||e[65]!==a||e[66]!==p||e[67]!==K||e[68]!==h||e[69]!==w||e[70]!==N.length||e[71]!==n||e[72]!==B?(we=s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:N.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[K.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.project")}),Z.sortedGroups.map(Fe=>{const{name:wt,skills:Y}=Fe;return s.jsx(Fr,{label:wt,count:Y.length,storageKey:"project-skills",children:Y.map(fe=>s.jsx(Ci,{skill:fe,isSelected:h===fe.name,onSelect:()=>{w(fe.name),a?.()},onRename:()=>W(fe),onDelete:()=>$(fe),onDuplicate:()=>V(fe),isMenuOpen:p===fe.name,onMenuOpenChange:Me=>j(Me?fe.name:null)},fe.name))},wt)}),Z.ungrouped.map(Fe=>s.jsx(Ci,{skill:Fe,isSelected:h===Fe.name,onSelect:()=>{w(Fe.name),a?.()},onRename:()=>W(Fe),onDelete:()=>$(Fe),onDuplicate:()=>V(Fe),isMenuOpen:p===Fe.name,onMenuOpenChange:wt=>j(wt?Fe.name:null)},Fe.name))]}),B.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),oe.sortedGroups.map(Fe=>{const{name:wt,skills:Y}=Fe;return s.jsx(Fr,{label:wt,count:Y.length,storageKey:"user-skills",children:Y.map(fe=>s.jsx(Ci,{skill:fe,isSelected:h===fe.name,onSelect:()=>{w(fe.name),a?.()},onRename:()=>W(fe),onDelete:()=>$(fe),onDuplicate:()=>V(fe),isMenuOpen:p===fe.name,onMenuOpenChange:Me=>j(Me?fe.name:null)},fe.name))},wt)}),oe.ungrouped.map(Fe=>s.jsx(Ci,{skill:Fe,isSelected:h===Fe.name,onSelect:()=>{w(Fe.name),a?.()},onRename:()=>W(Fe),onDelete:()=>$(Fe),onDuplicate:()=>V(Fe),isMenuOpen:p===Fe.name,onMenuOpenChange:wt=>j(wt?Fe.name:null)},Fe.name))]})]})}),e[62]=Z,e[63]=oe,e[64]=V,e[65]=a,e[66]=p,e[67]=K,e[68]=h,e[69]=w,e[70]=N.length,e[71]=n,e[72]=B,e[73]=we):we=e[73];const De=c!==null;let _e;e[74]!==d?(_e=Fe=>{!Fe&&!d&&f(null)},e[74]=d,e[75]=_e):_e=e[75];let Ve;e[76]!==n?(Ve=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=Ve):Ve=e[77];let ve;e[78]!==Ve?(ve=s.jsx(Bt,{children:Ve}),e[78]=Ve,e[79]=ve):ve=e[79];const se=c?.name??"";let ae;e[80]!==n||e[81]!==se?(ae=n("settings.skills.sidebar.deleteDialog.description",{name:se}),e[80]=n,e[81]=se,e[82]=ae):ae=e[82];let je;e[83]!==ae?(je=s.jsx(Vt,{children:ae}),e[83]=ae,e[84]=je):je=e[84];let Se;e[85]!==ve||e[86]!==je?(Se=s.jsxs($t,{children:[ve,je]}),e[85]=ve,e[86]=je,e[87]=Se):Se=e[87];let Ke;e[88]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>f(null),e[88]=Ke):Ke=e[88];let Ue;e[89]!==n?(Ue=n("settings.common.actions.cancel"),e[89]=n,e[90]=Ue):Ue=e[90];let Oe;e[91]!==d||e[92]!==Ue?(Oe=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Ke,disabled:d,children:Ue}),e[91]=d,e[92]=Ue,e[93]=Oe):Oe=e[93];let Re;e[94]!==n?(Re=n("settings.common.actions.delete"),e[94]=n,e[95]=Re):Re=e[95];let Ce;e[96]!==C||e[97]!==d||e[98]!==Re?(Ce=s.jsx(H,{size:"sm",onClick:C,disabled:d,children:Re}),e[96]=C,e[97]=d,e[98]=Re,e[99]=Ce):Ce=e[99];let Ze;e[100]!==Oe||e[101]!==Ce?(Ze=s.jsxs(is,{children:[Oe,Ce]}),e[100]=Oe,e[101]=Ce,e[102]=Ze):Ze=e[102];let be;e[103]!==Se||e[104]!==Ze?(be=s.jsxs(Ut,{className:"max-w-md",children:[Se,Ze]}),e[103]=Se,e[104]=Ze,e[105]=be):be=e[105];let Pe;e[106]!==De||e[107]!==_e||e[108]!==be?(Pe=s.jsx(zt,{open:De,onOpenChange:_e,children:be}),e[106]=De,e[107]=_e,e[108]=be,e[109]=Pe):Pe=e[109];const Le=i!==null;let Xe;e[110]===Symbol.for("react.memo_cache_sentinel")?(Xe=Fe=>!Fe&&r(null),e[110]=Xe):Xe=e[110];let Q;e[111]!==n?(Q=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=Q):Q=e[112];let Ne;e[113]!==Q?(Ne=s.jsx(Bt,{children:Q}),e[113]=Q,e[114]=Ne):Ne=e[114];const Ae=i?.name??"";let We;e[115]!==n||e[116]!==Ae?(We=n("settings.skills.sidebar.renameDialog.description",{name:Ae}),e[115]=n,e[116]=Ae,e[117]=We):We=e[117];let lt;e[118]!==We?(lt=s.jsx(Vt,{children:We}),e[118]=We,e[119]=lt):lt=e[119];let at;e[120]!==Ne||e[121]!==lt?(at=s.jsxs($t,{children:[Ne,lt]}),e[120]=Ne,e[121]=lt,e[122]=at):at=e[122];let pt;e[123]===Symbol.for("react.memo_cache_sentinel")?(pt=Fe=>u(Fe.target.value),e[123]=pt):pt=e[123];let bt;e[124]!==n?(bt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=bt):bt=e[125];let J;e[126]!==O?(J=Fe=>{Fe.key==="Enter"&&O()},e[126]=O,e[127]=J):J=e[127];let qe;e[128]!==l||e[129]!==bt||e[130]!==J?(qe=s.jsx(He,{value:l,onChange:pt,placeholder:bt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:J}),e[128]=l,e[129]=bt,e[130]=J,e[131]=qe):qe=e[131];let it;e[132]===Symbol.for("react.memo_cache_sentinel")?(it=()=>r(null),e[132]=it):it=e[132];let ct;e[133]!==n?(ct=n("settings.common.actions.cancel"),e[133]=n,e[134]=ct):ct=e[134];let gt;e[135]!==ct?(gt=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:it,children:ct}),e[135]=ct,e[136]=gt):gt=e[136];let Rt;e[137]!==n?(Rt=n("settings.common.actions.rename"),e[137]=n,e[138]=Rt):Rt=e[138];let tt;e[139]!==O||e[140]!==Rt?(tt=s.jsx(H,{size:"sm",onClick:O,children:Rt}),e[139]=O,e[140]=Rt,e[141]=tt):tt=e[141];let ft;e[142]!==gt||e[143]!==tt?(ft=s.jsxs(is,{children:[gt,tt]}),e[142]=gt,e[143]=tt,e[144]=ft):ft=e[144];let jt;e[145]!==at||e[146]!==qe||e[147]!==ft?(jt=s.jsxs(Ut,{children:[at,qe,ft]}),e[145]=at,e[146]=qe,e[147]=ft,e[148]=jt):jt=e[148];let Je;e[149]!==Le||e[150]!==jt?(Je=s.jsx(zt,{open:Le,onOpenChange:Xe,children:jt}),e[149]=Le,e[150]=jt,e[151]=Je):Je=e[151];let St;return e[152]!==Te||e[153]!==we||e[154]!==Pe||e[155]!==Je?(St=s.jsxs("div",{className:he,children:[Te,we,Pe,Je]}),e[152]=Te,e[153]=we,e[154]=Pe,e[155]=Je,e[156]=St):St=e[156],St},Ci=t=>{const e=dt.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:u,isMenuOpen:c,onMenuOpenChange:f}=t,{t:d}=et();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=si(),e[0]=v):v=e[0];const p=v;let j;e[1]!==a?(j=ei(a),e[1]=a,e[2]=j):j=e[2];const h=j;let w;e[3]!==a?(w=Ur(a),e[3]=a,e[4]=w):w=e[4];const b=w,[k,m]=o.useState(!1);let I;e[5]!==b||e[6]!==r||e[7]!==u||e[8]!==l||e[9]!==d?(I=V=>s.jsxs(s.Fragment,{children:[b?s.jsxs(V,{onClick:U=>{U.stopPropagation(),l()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}):null,s.jsxs(V,{onClick:U=>{U.stopPropagation(),u()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),s.jsxs(V,{onClick:U=>{U.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[5]=b,e[6]=r,e[7]=u,e[8]=l,e[9]=d,e[10]=I):I=e[10];const E=I,A=!h&&k,N=n?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[11]!==N?(x=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",N),e[11]=N,e[12]=x):x=e[12];let y;e[13]!==h?(y=!p&&!h?V=>{V.preventDefault(),m(!0)}:void 0,e[13]=h,e[14]=y):y=e[14];let F;e[15]!==x||e[16]!==y?(F=s.jsx("div",{className:x,onContextMenu:y}),e[15]=x,e[16]=y,e[17]=F):F=e[17];let T;e[18]!==a.name?(T=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name})}),e[18]=a.name,e[19]=T):T=e[19];let P;e[20]!==i||e[21]!==T?(P=s.jsx("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-ring",tabIndex:0,children:T}),e[20]=i,e[21]=T,e[22]=P):P=e[22];let D;e[23]!==h||e[24]!==c||e[25]!==f||e[26]!==E?(D=h?null:s.jsxs(bn,{open:c,onOpenChange:V=>{V&&m(!1),f(V)},children:[s.jsx(fn,{asChild:!0,children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(xn,{align:"end",className:"w-fit min-w-20",children:E(vn)})]}),e[23]=h,e[24]=c,e[25]=f,e[26]=E,e[27]=D):D=e[27];let $;e[28]!==P||e[29]!==D?($=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,D]}),e[28]=P,e[29]=D,e[30]=$):$=e[30];let _;e[31]!==$||e[32]!==F?(_=s.jsx(la,{render:F,children:$}),e[31]=$,e[32]=F,e[33]=_):_=e[33];let C;e[34]!==h||e[35]!==E?(C=h?null:s.jsx(ra,{className:"w-fit min-w-20",children:E(oa)}),e[34]=h,e[35]=E,e[36]=C):C=e[36];let R;return e[37]!==_||e[38]!==C||e[39]!==A?(R=s.jsxs(ca,{open:A,onOpenChange:m,children:[_,C]}),e[37]=_,e[38]=C,e[39]=A,e[40]=R):R=e[40],R};function ng(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function ag(t){return t.loadSkills}function ig(t){return t.scope==="project"}function rg(t){return t.scope==="user"}function og(t,e){return t.localeCompare(e)}function lg(t,e){return t.name.localeCompare(e.name)}function cg(t,e){return t.name.localeCompare(e.name)}const dg=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,ug=t=>{const e=t.trim(),a=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(a==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(a==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const n=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return n?`${n[1]}/${n[2].replace(/\.git$/i,"")}`:e},pg=({open:t,onOpenChange:e})=>{const{t:a}=et(),n=Pn(C=>C.scanRepo),i=Pn(C=>C.loadCatalog),r=Pn(C=>C.loadSource),l=Pn(C=>C.setSelectedSource),u=Pn(C=>C.isScanning),c=ea(C=>C.defaultGitIdentityId),f=ea(C=>C.loadDefaultGitIdentityId),[d,v]=o.useState(""),[p,j]=o.useState(""),[h,w]=o.useState(""),[b,k]=o.useState(null),[m,I]=o.useState(null),[E,A]=o.useState(!1),[N,x]=o.useState([]),[y,F]=o.useState(null),T=o.useRef(0),P=o.useCallback(C=>{T.current+=1,A(!1),I(null),C?.clearIdentity&&(x([]),F(null))},[]);o.useEffect(()=>{t&&(T.current+=1,v(""),j(""),w(""),I(null),A(!1),x([]),F(null),f(),k(null),(async()=>{const C=await Nn();k(C?C.skillCatalogs??[]:null)})())},[t,f]);const D=o.useMemo(()=>{const C=p.trim(),R=h.trim();return(b??[]).some(V=>{const U=(V.source||"").trim(),W=(V.subpath||"").trim();return U===C&&W===R})},[b,p,h]),$=async()=>{const C=p.trim();if(!C){M.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}d.trim()||v(ug(C)),A(!1),I(null);const R=T.current+1;T.current=R;const V=await n({source:C,subpath:h.trim()||void 0,gitIdentityId:y||void 0});if(T.current!==R)return;if(!V.ok){if(V.error?.kind==="authRequired"){if(ds()){M.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const W=V.error.identities||[];if(x(W),!y&&W.length>0){const te=c&&c!=="global"&&W.some(O=>O.id===c)?c:W[0].id;F(te)}M.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}M.error(V.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const U=V.items?.length||0;if(I(U),U===0){M.error(a("settings.skills.catalog.add.toast.noSkillsFound")),A(!1);return}x([]),A(!0),M.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:U}))},_=async()=>{const C=d.trim(),R=p.trim(),V=h.trim();if(!C){M.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!R){M.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!E){M.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(D){M.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const U={id:dg(),label:C,source:R,...V?{subpath:V}:{},...y?{gitIdentityId:y}:{}};if(b===null){M.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const W=[...b,U];try{if(!(await yt({skillCatalogs:W})).ok)throw new Error(a("settings.skills.catalog.add.toast.saveFailed"));k(W),M.success(a("settings.skills.catalog.add.toast.catalogAdded")),await i({refresh:!0}),await r(U.id,{refresh:!0}),l(U.id),e(!1)}catch(te){M.error(te instanceof Error?te.message:a("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(zt,{open:t,onOpenChange:e,children:s.jsxs(Ut,{className:"max-w-xl",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:a("settings.skills.catalog.add.title")}),s.jsxs(Vt,{children:[a("settings.skills.catalog.add.descriptionPrefix")," ",s.jsx("code",{className:"font-mono",children:"SKILL.md"}),a("settings.skills.catalog.add.descriptionSuffix")]})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.catalogName")}),s.jsx(He,{value:d,onChange:C=>v(C.target.value),placeholder:a("settings.skills.catalog.add.field.catalogNamePlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.repository")}),s.jsx(Yt,{children:a("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(He,{value:p,onChange:C=>{j(C.target.value),P({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.repositoryPlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.optionalSubpath")}),s.jsx(He,{value:h,onChange:C=>{w(C.target.value),P({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),N.length>0&&!ds()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:a("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:a("settings.skills.catalog.shared.auth.description")}),s.jsx(Yt,{className:"ml-1",children:a("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Et,{value:y||"",onValueChange:C=>{F(C),P()},children:[s.jsx(Dt,{className:"w-fit",children:s.jsx("span",{children:N.find(C=>C.id===y)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Mt,{align:"start",children:N.map(C=>s.jsx(ut,{value:C.id,children:C.name},C.id))})]})]}):null,m!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:m})}):null,D?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>e(!1),children:a("settings.common.actions.cancel")}),s.jsxs(H,{size:"sm",className:"gap-2",variant:"ghost",onClick:()=>{$()},disabled:u||!p.trim(),children:[s.jsx(z,{name:"git-repository",className:"h-4 w-4"}),a(u?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(H,{size:"sm",onClick:()=>{_()},disabled:!E||D||b===null||!d.trim()||!p.trim(),children:a("settings.skills.catalog.add.actions.addCatalog")})]})]})})},mg=t=>{const e=dt.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=et();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={},e[0]=u):u=e[0];const[c,f]=o.useState(u);let d,v;e[1]!==i||e[2]!==a?(d=()=>{if(!a)return;const G={};for(const Z of i)G[Z.skillName]="skip";f(G)},v=[a,i],e[1]=i,e[2]=a,e[3]=d,e[4]=v):(d=e[3],v=e[4]),o.useEffect(d,v);let p;e[5]!==i?(p=G=>{const Z={};for(const le of i)Z[le.skillName]=G;f(Z)},e[5]=i,e[6]=p):p=e[6];const j=p;let h;e[7]!==i||e[8]!==c?(h=i.length>0&&i.every(G=>c[G.skillName]),e[7]=i,e[8]=c,e[9]=h):h=e[9];const w=h;let b;e[10]!==l?(b=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=b):b=e[11];let k;e[12]!==b?(k=s.jsx(Bt,{children:b}),e[12]=b,e[13]=k):k=e[13];let m;e[14]!==l?(m=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=m):m=e[15];let I;e[16]!==m?(I=s.jsx(Vt,{children:m}),e[16]=m,e[17]=I):I=e[17];let E;e[18]!==k||e[19]!==I?(E=s.jsxs($t,{children:[k,I]}),e[18]=k,e[19]=I,e[20]=E):E=e[20];let A;e[21]!==i.length||e[22]!==l?(A=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=l,e[23]=A):A=e[23];let N;e[24]!==A?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:A}),e[24]=A,e[25]=N):N=e[25];let x;e[26]!==j?(x=()=>j("skip"),e[26]=j,e[27]=x):x=e[27];let y;e[28]!==l?(y=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=y):y=e[29];let F;e[30]!==x||e[31]!==y?(F=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:x,children:y}),e[30]=x,e[31]=y,e[32]=F):F=e[32];let T;e[33]!==j?(T=()=>j("overwrite"),e[33]=j,e[34]=T):T=e[34];let P;e[35]!==l?(P=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=P):P=e[36];let D;e[37]!==T||e[38]!==P?(D=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:T,children:P}),e[37]=T,e[38]=P,e[39]=D):D=e[39];let $;e[40]!==F||e[41]!==D?($=s.jsxs("div",{className:"flex items-center gap-2",children:[F,D]}),e[40]=F,e[41]=D,e[42]=$):$=e[42];let _;e[43]!==N||e[44]!==$?(_=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N,$]}),e[43]=N,e[44]=$,e[45]=_):_=e[45];let C;if(e[46]!==i||e[47]!==c||e[48]!==l){let G;e[50]!==c||e[51]!==l?(G=Z=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:Z.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:Z.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:Z.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Et,{value:c[Z.skillName]||"skip",onValueChange:le=>f(oe=>({...oe,[Z.skillName]:le})),children:[s.jsx(Dt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[Z.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Mt,{align:"end",children:[s.jsx(ut,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(ut,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},Z.skillName),e[50]=c,e[51]=l,e[52]=G):G=e[52],C=i.map(G),e[46]=i,e[47]=c,e[48]=l,e[49]=C}else C=e[49];let R;e[53]!==C?(R=s.jsx("div",{className:"space-y-2",children:C}),e[53]=C,e[54]=R):R=e[54];let V;e[55]!==_||e[56]!==R?(V=s.jsxs("div",{className:"space-y-3",children:[_,R]}),e[55]=_,e[56]=R,e[57]=V):V=e[57];let U;e[58]!==n?(U=()=>n(!1),e[58]=n,e[59]=U):U=e[59];let W;e[60]!==l?(W=l("settings.common.actions.cancel"),e[60]=l,e[61]=W):W=e[61];let te;e[62]!==U||e[63]!==W?(te=s.jsx(H,{size:"sm",variant:"ghost",onClick:U,children:W}),e[62]=U,e[63]=W,e[64]=te):te=e[64];let O;e[65]!==c||e[66]!==r?(O=()=>r(c),e[65]=c,e[66]=r,e[67]=O):O=e[67];const ie=!w;let K;e[68]!==l?(K=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=K):K=e[69];let q;e[70]!==O||e[71]!==ie||e[72]!==K?(q=s.jsx(H,{size:"sm",onClick:O,disabled:ie,children:K}),e[70]=O,e[71]=ie,e[72]=K,e[73]=q):q=e[73];let B;e[74]!==te||e[75]!==q?(B=s.jsxs(is,{children:[te,q]}),e[74]=te,e[75]=q,e[76]=B):B=e[76];let L;e[77]!==E||e[78]!==V||e[79]!==B?(L=s.jsxs(Ut,{className:"max-w-2xl",children:[E,V,B]}),e[77]=E,e[78]=V,e[79]=B,e[80]=L):L=e[80];let X;return e[81]!==n||e[82]!==a||e[83]!==L?(X=s.jsx(zt,{open:a,onOpenChange:n,children:L}),e[81]=n,e[82]=a,e[83]=L,e[84]=X):X=e[84],X},so=[{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 ti(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Ec(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=so.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const gg=t=>{const e=dt.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=et(),l=Pn(hg),u=Pn(fg),[c,f]=o.useState("user"),[d,v]=o.useState("opencode"),p=Xs(xg),j=Xs(bg),[h,w]=o.useState(null),[b,k]=o.useState(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=[],e[0]=m):m=e[0];const[I,E]=o.useState(m),[A,N]=o.useState(null);let x,y;e[1]!==j||e[2]!==a?(x=()=>{a&&(f("user"),v("opencode"),w(j),k(!1),E([]),N(null))},y=[a,j],e[1]=j,e[2]=a,e[3]=x,e[4]=y):(x=e[3],y=e[4]),o.useEffect(x,y);let F;e[5]!==r?(F=Ce=>{switch(Ce){case"project-opencode":return r("settings.skills.location.option.projectOpencode.label");case"user-agents":return r("settings.skills.location.option.userAgents.label");case"project-agents":return r("settings.skills.location.option.projectAgents.label");default:return r("settings.skills.location.option.userOpencode.label")}},e[5]=r,e[6]=F):F=e[6];const T=F;let P;e[7]!==r?(P=Ce=>{switch(Ce){case"project-opencode":return r("settings.skills.location.option.projectOpencode.description");case"user-agents":return r("settings.skills.location.option.userAgents.description");case"project-agents":return r("settings.skills.location.option.projectAgents.description");default:return r("settings.skills.location.option.userOpencode.description")}},e[7]=r,e[8]=P):P=e[8];const D=P;let $;e:{if(p.length===0){$=null;break e}if(h&&p.some(Ce=>Ce.id===h)){$=h;break e}if(j&&p.some(Ce=>Ce.id===j)){$=j;break e}$=p[0]?.id??null}const _=$;let C;e:{if(c!=="project"){C=null;break e}const Ce=_;if(!Ce){C=null;break e}let Ze;if(e[9]!==Ce||e[10]!==p){let Pe;e[12]!==Ce?(Pe=Le=>Le.id===Ce,e[12]=Ce,e[13]=Pe):Pe=e[13],Ze=p.find(Pe),e[9]=Ce,e[10]=p,e[11]=Ze}else Ze=e[11];C=Ze?.path??null}const R=C;let V;e[14]!==l||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==r?(V=async Ce=>{const Ze=await l({source:Ce.source,subpath:Ce.subpath,gitIdentityId:i?.gitIdentityId,scope:Ce.scope,targetSource:Ce.targetSource,selections:[{skillDir:Ce.skillDir}],conflictPolicy:"prompt",conflictDecisions:Ce.conflictDecisions},{directory:Ce.directoryOverride??null});if(Ze.ok){M.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(Ze.error?.kind==="conflicts"){N({source:Ce.source,subpath:Ce.subpath,scope:Ce.scope,targetSource:Ce.targetSource,skillDir:Ce.skillDir,directoryOverride:Ce.directoryOverride??null}),E(Ze.error.conflicts),k(!0);return}if(Ze.error?.kind==="authRequired"){M.error(Ze.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}M.error(Ze.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i?.gitIdentityId,e[16]=n,e[17]=r,e[18]=V):V=e[18];const U=V;if(!i)return null;let W;e[19]!==r?(W=r("settings.skills.catalog.installSkill.title"),e[19]=r,e[20]=W):W=e[20];let te;e[21]!==W?(te=s.jsx(Bt,{children:W}),e[21]=W,e[22]=te):te=e[22];let O;e[23]!==r?(O=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=O):O=e[24];let ie;e[25]!==i.skillName?(ie=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=ie):ie=e[26];let K;e[27]!==r?(K=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=K):K=e[28];let q;e[29]!==O||e[30]!==ie||e[31]!==K?(q=s.jsxs(Vt,{children:[O," ",ie," ",K]}),e[29]=O,e[30]=ie,e[31]=K,e[32]=q):q=e[32];let B;e[33]!==te||e[34]!==q?(B=s.jsxs($t,{children:[te,q]}),e[33]=te,e[34]=q,e[35]=B):B=e[35];let L;e[36]!==r?(L=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=L):L=e[37];let X;e[38]!==L?(X=s.jsx("span",{className:"typography-ui-label text-foreground",children:L}),e[38]=L,e[39]=X):X=e[39];let G;e[40]!==c||e[41]!==d?(G=ti(c,d),e[40]=c,e[41]=d,e[42]=G):G=e[42];let Z;e[43]===Symbol.for("react.memo_cache_sentinel")?(Z=Ce=>{const Ze=Ec(Ce);f(Ze.scope),v(Ze.source==="agents"?"agents":"opencode")},e[43]=Z):Z=e[43];let le;e[44]!==c?(le=c==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=le):le=e[45];let oe;e[46]!==d?(oe=d==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=d,e[47]=oe):oe=e[47];let he;e[48]!==T||e[49]!==c||e[50]!==d?(he=T(ti(c,d)),e[48]=T,e[49]=c,e[50]=d,e[51]=he):he=e[51];let ee;e[52]!==he?(ee=s.jsx("span",{children:he}),e[52]=he,e[53]=ee):ee=e[53];let re;e[54]!==le||e[55]!==oe||e[56]!==ee?(re=s.jsxs(Dt,{className:"w-fit gap-1.5",children:[le,oe,ee]}),e[54]=le,e[55]=oe,e[56]=ee,e[57]=re):re=e[57];let de;e[58]!==D||e[59]!==T?(de=so.map(Ce=>s.jsx(ut,{value:Ce.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[Ce.scope==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),Ce.source==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:T(Ce.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:D(Ce.value)})]})},Ce.value)),e[58]=D,e[59]=T,e[60]=de):de=e[60];let ke;e[61]!==de?(ke=s.jsx(Mt,{align:"start",children:de}),e[61]=de,e[62]=ke):ke=e[62];let ue;e[63]!==G||e[64]!==re||e[65]!==ke?(ue=s.jsxs(Et,{value:G,onValueChange:Z,children:[re,ke]}),e[63]=G,e[64]=re,e[65]=ke,e[66]=ue):ue=e[66];let xe;e[67]!==X||e[68]!==ue?(xe=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[X,ue]}),e[67]=X,e[68]=ue,e[69]=xe):xe=e[69];let pe;e[70]!==p||e[71]!==_||e[72]!==c||e[73]!==r?(pe=c==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.skills.catalog.installSkill.field.project")}),p.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Et,{value:_??"",onValueChange:Ce=>w(Ce),disabled:p.length===1,children:[s.jsx(Dt,{className:"w-fit",children:s.jsx(_t,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Mt,{align:"start",children:p.map(vg)})]})]}),e[70]=p,e[71]=_,e[72]=c,e[73]=r,e[74]=pe):pe=e[74];let Ie;e[75]!==i.warnings?(Ie=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=Ie):Ie=e[76];let Te;e[77]!==xe||e[78]!==pe||e[79]!==Ie?(Te=s.jsxs("div",{className:"mt-2 space-y-3",children:[xe,pe,Ie]}),e[77]=xe,e[78]=pe,e[79]=Ie,e[80]=Te):Te=e[80];let we;e[81]!==n?(we=()=>n(!1),e[81]=n,e[82]=we):we=e[82];let De;e[83]!==r?(De=r("settings.common.actions.cancel"),e[83]=r,e[84]=De):De=e[84];let _e;e[85]!==we||e[86]!==De?(_e=s.jsx(H,{size:"sm",variant:"ghost",onClick:we,children:De}),e[85]=we,e[86]=De,e[87]=_e):_e=e[87];const Ve=u||!i.installable||c==="project"&&!R;let ve;e[88]!==R||e[89]!==U||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==c||e[94]!==d?(ve=()=>{U({source:i.repoSource,subpath:i.repoSubpath,scope:c,targetSource:d,skillDir:i.skillDir,directoryOverride:R})},e[88]=R,e[89]=U,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=c,e[94]=d,e[95]=ve):ve=e[95];let se;e[96]!==u||e[97]!==r?(se=r(u?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=u,e[97]=r,e[98]=se):se=e[98];let ae;e[99]!==Ve||e[100]!==ve||e[101]!==se?(ae=s.jsx(H,{size:"sm",disabled:Ve,onClick:ve,children:se}),e[99]=Ve,e[100]=ve,e[101]=se,e[102]=ae):ae=e[102];let je;e[103]!==_e||e[104]!==ae?(je=s.jsxs(is,{children:[_e,ae]}),e[103]=_e,e[104]=ae,e[105]=je):je=e[105];let Se;e[106]!==B||e[107]!==Te||e[108]!==je?(Se=s.jsxs(Ut,{className:"max-w-md",children:[B,Te,je]}),e[106]=B,e[107]=Te,e[108]=je,e[109]=Se):Se=e[109];let Ke;e[110]!==n||e[111]!==a||e[112]!==Se?(Ke=s.jsx(zt,{open:a,onOpenChange:n,children:Se}),e[110]=n,e[111]=a,e[112]=Se,e[113]=Ke):Ke=e[113];let Ue;e[114]!==A||e[115]!==U?(Ue=Ce=>{A&&(U({source:A.source,subpath:A.subpath,scope:A.scope,targetSource:A.targetSource,skillDir:A.skillDir,conflictDecisions:Ce,directoryOverride:A.directoryOverride??null}),k(!1))},e[114]=A,e[115]=U,e[116]=Ue):Ue=e[116];let Oe;e[117]!==I||e[118]!==b||e[119]!==Ue?(Oe=s.jsx(mg,{open:b,onOpenChange:k,conflicts:I,onConfirm:Ue}),e[117]=I,e[118]=b,e[119]=Ue,e[120]=Oe):Oe=e[120];let Re;return e[121]!==Ke||e[122]!==Oe?(Re=s.jsxs(s.Fragment,{children:[Ke,Oe]}),e[121]=Ke,e[122]=Oe,e[123]=Re):Re=e[123],Re};function hg(t){return t.installSkills}function fg(t){return t.isInstalling}function xg(t){return t.projects}function bg(t){return t.activeProjectId}function vg(t){return s.jsx(ut,{value:t.id,children:t.label||t.path},t.id)}const yg=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,jg=t=>{const e=t.trim();return yg.test(e)?`https://github.com/${e}`:null},wg=t=>{const e=jg(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let Ii=null;const kg=t=>{const e=Qr();return(!Ii||Ii.locale!==e)&&(Ii={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Ii.formatter.format(t)},Ng=t=>{const e=Date.parse(t);if(Number.isNaN(e))return null;const a=Date.now()-e;if(a<6e4)return{key:"common.relative.justNow",count:0};const n=Math.floor(a/6e4);if(n<60)return{key:"common.relative.minutesAgoShort",count:n};const i=Math.floor(n/60);if(i<24)return{key:"common.relative.hoursAgoShort",count:i};const r=Math.floor(i/24);if(r<7)return{key:"common.relative.daysAgoShort",count:r};const l=Math.floor(r/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(r/365)}},Sg=t=>{const e=dt.c(50),{source:a,isActive:n,isLoading:i,skillsCount:r,onSelect:l,t:u}=t,c=a.stars??null;let f,d,v,p,j,h,w,b,k,m;if(e[0]!==n||e[1]!==i||e[2]!==l||e[3]!==r||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==c||e[8]!==u){const N=a.repoUpdatedAt?Ng(a.repoUpdatedAt):null;b="button",k=l,m=n;const x=n?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-interactive-border-hover";e[19]!==x?(d=ye("oc-surface-elevated w-full min-h-24 text-left rounded-lg border bg-surface-elevated p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",x),e[19]=x,e[20]=d):d=e[20],j="min-w-0 flex-1 block";let y;e[21]!==a.label?(y=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=y):y=e[22];let F;e[23]!==i||e[24]!==r||e[25]!==u?(F=i?s.jsx(z,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):r!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:u("settings.skills.catalog.page.source.skillsCount",{count:r})}),e[23]=i,e[24]=r,e[25]=u,e[26]=F):F=e[26],e[27]!==y||e[28]!==F?(h=s.jsxs("span",{className:"flex items-center gap-2",children:[y,F]}),e[27]=y,e[28]=F,e[29]=h):h=e[29],e[30]!==a.source?(w=s.jsx("span",{className:"typography-micro font-mono text-muted-foreground block mt-0.5 truncate",children:a.source}),e[30]=a.source,e[31]=w):w=e[31],f="flex items-center gap-3 mt-1",e[32]!==c||e[33]!==u?(v=c!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:u("settings.skills.catalog.page.source.stars",{count:c}),children:[s.jsx(z,{name:"star",className:"h-3 w-3"}),kg(c)]}),e[32]=c,e[33]=u,e[34]=v):v=e[34],p=N&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:N.key==="common.relative.justNow"?u(N.key):u("settings.skills.catalog.page.source.updated",{time:u(N.key,{count:N.count})})}),e[0]=n,e[1]=i,e[2]=l,e[3]=r,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=c,e[8]=u,e[9]=f,e[10]=d,e[11]=v,e[12]=p,e[13]=j,e[14]=h,e[15]=w,e[16]=b,e[17]=k,e[18]=m}else f=e[9],d=e[10],v=e[11],p=e[12],j=e[13],h=e[14],w=e[15],b=e[16],k=e[17],m=e[18];let I;e[35]!==f||e[36]!==v||e[37]!==p?(I=s.jsxs("span",{className:f,children:[v,p]}),e[35]=f,e[36]=v,e[37]=p,e[38]=I):I=e[38];let E;e[39]!==I||e[40]!==j||e[41]!==h||e[42]!==w?(E=s.jsxs("span",{className:j,children:[h,w,I]}),e[39]=I,e[40]=j,e[41]=h,e[42]=w,e[43]=E):E=e[43];let A;return e[44]!==d||e[45]!==E||e[46]!==b||e[47]!==k||e[48]!==m?(A=s.jsx("button",{type:b,onClick:k,"aria-pressed":m,className:d,children:E}),e[44]=d,e[45]=E,e[46]=b,e[47]=k,e[48]=m,e[49]=A):A=e[49],A},Cg=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=et(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:u,loadCatalog:c,loadSource:f,isLoadingCatalog:d,isLoadingSource:v,loadedSourceIds:p,lastCatalogError:j}=Pn(Hs(U=>({sources:U.sources,itemsBySource:U.itemsBySource,selectedSourceId:U.selectedSourceId,setSelectedSource:U.setSelectedSource,loadCatalog:U.loadCatalog,loadSource:U.loadSource,isLoadingCatalog:U.isLoadingCatalog,isLoadingSource:U.isLoadingSource,loadedSourceIds:U.loadedSourceIds,lastCatalogError:U.lastCatalogError}))),[h,w]=o.useState(""),[b,k]=o.useState(!1),[m,I]=o.useState(!1),[E,A]=o.useState(null),[N,x]=o.useState(!1),[y,F]=o.useState(!1),T=o.useRef(null);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{const U=i.filter(O=>!p[O.id]);if(U.length===0)return;let W=!1;return(async()=>{for(const O of U){if(W)return;await f(O.id)}})(),()=>{W=!0}},[i,p,f]),o.useEffect(()=>{!l||p[l]||f(l)},[l,p,f]),o.useEffect(()=>{const U=W=>{(W.metaKey||W.ctrlKey)&&W.key.toLowerCase()==="k"&&(W.preventDefault(),T.current?.focus())};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[]);const P=h.trim().length>0,D=o.useMemo(()=>P?zi(i.flatMap(U=>r[U.id]||[]),h,U=>[U.skillName,U.frontmatterName,U.description]):l?r[l]||[]:[],[i,r,l,h,P]),$=o.useMemo(()=>i.find(U=>U.id===l)||null,[i,l]),_=!!(l&&l.startsWith("custom:")),C=async()=>{if(!(!l||!_)){x(!0);try{const U=await Nn();if(!U)return;const te=(U.skillCatalogs??[]).filter(O=>O.id!==l);await yt({skillCatalogs:te}),await c({refresh:!0}),F(!1)}finally{x(!1)}}},R=P?n("settings.skills.catalog.page.list.searchTitle"):$?.label??"",V=!P&&l!==null&&!p[l]&&(v||d);return s.jsxs(s.Fragment,{children:[s.jsxs(os,{title:n("settings.skills.catalog.page.title"),showSaveStatus:!1,children:[a&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(Xr,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:U=>e(U),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:n("settings.skills.catalog.page.subtitle")}),s.jsx("div",{"data-settings-item":"skills.catalog.search",className:"mb-5",children:s.jsxs("div",{className:"relative max-w-md",children:[s.jsx(z,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{ref:T,value:h,onChange:U=>w(U.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:ye("h-8 pl-8 w-full",h&&"pr-8")}),h&&s.jsx("button",{type:"button",onClick:()=>{w(""),T.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center h-4 w-4 rounded text-muted-foreground hover:text-foreground transition-colors",title:n("settings.skills.catalog.page.search.clear"),children:s.jsx(z,{name:"close",className:"h-3 w-3"})})]})}),s.jsx($e,{title:n("settings.skills.catalog.page.section.sources"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 py-1.5",children:[i.map(U=>s.jsx(Sg,{source:U,isActive:U.id===l,isLoading:v&&!p[U.id],skillsCount:p[U.id]?(r[U.id]||[]).length:null,onSelect:()=>u(U.id),t:n},U.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>k(!0),className:"min-h-24 text-left rounded-lg border border-dashed border-[var(--interactive-border)] hover:border-[var(--interactive-border-hover)] hover:bg-[var(--surface-muted)] p-3.5 flex gap-3 items-start transition-colors",children:[s.jsx("span",{className:"flex items-center justify-center rounded-md bg-transparent text-muted-foreground w-8 h-8 shrink-0",children:s.jsx(z,{name:"add",className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground block",children:n("settings.skills.catalog.page.source.addOwnTitle")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 block mt-0.5",children:n("settings.skills.catalog.page.source.addOwnDescription")})]})]})]})}),j&&s.jsx($e,{children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:n("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:j.message})]})}),s.jsxs($e,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 pb-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-micro font-medium uppercase tracking-wide text-muted-foreground truncate",children:R}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:D.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!P?f(l,{refresh:!0}):c({refresh:!0})},disabled:d||v,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(z,{name:"refresh",className:ye("h-3.5 w-3.5",(d||v)&&"animate-spin")})}),_&&!P&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>F(!0),disabled:N,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),V||v&&D.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(z,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:n("settings.skills.catalog.page.loading.skills")})]}):D.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:n("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.catalog.page.empty.noSkillsDescription")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:D.map(U=>{const W=U.installed?.isInstalled,te=U.installed?.scope,O=wg(U);return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:U.skillName}),W&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:te||n("settings.skills.catalog.page.badge.unknown")})}),!U.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.notInstallable")})]}),U.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:U.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:n("settings.skills.catalog.shared.noDescription")}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80 mt-1 flex items-center gap-2 min-w-0",children:[O?s.jsxs("a",{href:O,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline truncate inline-flex items-center gap-1",title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:[s.jsx(z,{name:"github",className:"h-3 w-3 shrink-0"}),U.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:U.repoSource}),U.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:U.skillDir})]})]}),U.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:U.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[O&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(O,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"})}),W?s.jsx("span",{className:"text-[var(--status-success)] flex items-center justify-center w-7 h-7",title:n("settings.skills.catalog.page.badge.installed",{scope:te||""}),children:s.jsx(z,{name:"check",className:"h-4 w-4"})}):s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",disabled:!U.installable,onClick:()=>{A(U),I(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${U.sourceId}:${U.skillDir}`)})})]})]}),s.jsx(pg,{open:b,onOpenChange:k}),s.jsx(gg,{open:m,onOpenChange:I,item:E}),s.jsx(zt,{open:y,onOpenChange:U=>{N||F(U)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Vt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>F(!1),disabled:N,children:n("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{C()},disabled:N,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},Ig=()=>{const t=dt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Cg,{mode:"external",onModeChange:Mg,showModeTabs:!1}),t[0]=e):e=t[0],e},Pg="SKILL.md",Ag="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",Oi=(t,e)=>{const a=Xu({description:t}).trimEnd(),n=e.trimStart();return`---
22
+ ${a}
23
+ ---${n?`
24
+
25
+ ${n}`:`
26
+ `}`},Tg=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Dc=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let a=null;try{const n=ep(e[1]);if(Tg(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},Eg=(t,e)=>{const a=Dc(t);return Oi(e,a.instructions)},Dg=()=>{const{t}=et(),{currentTheme:e}=La(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skillDraft:u,setSkillDraft:c,setSelectedSkill:f}=Zs(Hs(be=>({selectedSkillName:be.selectedSkillName,getSkillByName:be.getSkillByName,getSkillDetail:be.getSkillDetail,createSkill:be.createSkill,updateSkill:be.updateSkill,skillDraft:be.skillDraft,setSkillDraft:be.setSkillDraft,setSelectedSkill:be.setSelectedSkill}))),d=Gs(),v=Zs(be=>qr(be,d)),p=a?n(a,d):null,j=!!(u&&u.name===a&&!p),h=!!(a&&!p&&!u),w=p?.path==="<built-in>";o.useEffect(()=>{h&&f(null)},[h,f]);const[b,k]=o.useState(""),[m,I]=o.useState("user"),[E,A]=o.useState("opencode"),[N,x]=o.useState(""),[y,F]=o.useState(""),[T,P]=o.useState(()=>Oi("","")),[D,$]=o.useState("edit"),[_,C]=o.useState([]),[R,V]=o.useState([]),[U,W]=o.useState(!1),[te,O]=o.useState(!1),[ie,K]=o.useState(""),[q,B]=o.useState(""),[L,X]=o.useState(!1),[G,Z]=o.useState(""),[le,oe]=o.useState(""),[he,ee]=o.useState(null),[re,de]=o.useState(!1),[ke,ue]=o.useState(""),[xe,pe]=o.useState(null),[Ie,Te]=o.useState(!1),we=j?b.trim()!==""||N.trim()!==""||y.trim()!==""||R.length>0:N!==ie||y!==q,De=he?le!==ke:G.trim()!=="",_e=o.useCallback(be=>{switch(be){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),Ve=o.useCallback(be=>{switch(be){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);o.useEffect(()=>{(async()=>{if(j&&u){const Pe=u.description||"",Le=u.instructions||"";k(u.name||""),I(u.scope||"user"),A(u.source==="agents"?"agents":"opencode"),x(Pe),F(Le),P(Oi(Pe,Le)),K(""),B(""),C([]),V(u.pendingFiles||[])}else if(a&&p){O(!0);try{const Pe=await i(a,d);if(Pe){const Le=Pe.sources.md,Xe=Le.description||"",Q=Le.instructions||"";x(Xe),F(Q),P(Oi(Xe,Q)),K(Xe),B(Q),C(Le.supportingFiles||[])}}catch(Pe){console.error("Failed to load skill details:",Pe)}finally{O(!1)}}})()},[p,j,a,d,v,u,i]);const ve=ce(be=>be.editorFontSize),se=o.useMemo(()=>{const be=[Fo(e,{fontSize:ve})],Pe=ho(Pg);return Pe&&be.push(Pe),be.push(Lo.lineWrapping),be},[e,ve]),ae=o.useMemo(()=>{const be=G.trim()||"supporting-file.md",Pe=fd(be),Le=!!Pe&&Pe!=="markdown",Xe=[Fo(e,Le?{syntaxColors:!1,fontSize:ve}:{fontSize:ve})],Q=ho(be);return Q&&Xe.push(Q),Le&&Pe&&Xe.push(tp({language:Pe,themeName:e.metadata.id,theme:np(e)})),Xe.push(Lo.lineWrapping),Xe},[e,G,ve]),je=o.useCallback(be=>{x(be),P(Pe=>Eg(Pe,be))},[]),Se=o.useCallback(be=>{P(be);const Pe=Dc(be);x(Pe.description??""),F(Pe.instructions)},[]),Ke=async()=>{const be=j?b.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!be){M.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(be)||be.length>64){M.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!N.trim()){M.error(t("settings.skills.page.toast.descriptionRequired"));return}if(j&&v.some(Pe=>Pe.name===be)){M.error(t("settings.skills.page.toast.skillExists"));return}W(!0);try{const Pe={name:be,description:N.trim(),instructions:y.trim()||void 0,scope:j?m:void 0,source:j?E:void 0,targetPath:j?void 0:p?.path,supportingFiles:j&&R.length>0?R:void 0};let Le;if(j?(Le=await r(Pe,d),Le&&(c(null),V([]),f(be))):(Le=await l(be,Pe,d),Le&&(K(N.trim()),B(y.trim()))),Le){const Xe=sa.getState().changes.some(Q=>Q.scope==="skills"&&Q.id.startsWith(`skills:${be}:`));M.success(t(Xe?"settings.view.pendingRestart.saved":j?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else M.error(t(j?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Pe){console.error("Error saving skill:",Pe),M.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{W(!1)}},Ue=()=>{ee(null),Z(""),oe(""),ue(""),X(!0)},Oe=async be=>{if(ee(be),Z(be),j){const Le=R.find(Xe=>Xe.path===be)?.content||"";oe(Le),ue(Le),X(!0);return}if(a){de(!0),X(!0);try{const{readSupportingFile:Pe}=Zs.getState(),Le=await Pe(a,be,d);oe(Le||""),ue(Le||"")}catch{M.error(t("settings.skills.page.toast.loadFileContentFailed")),oe(""),ue("")}finally{de(!1)}}},Re=async()=>{if(!G.trim()){M.error(t("settings.skills.page.toast.fileNameRequired"));return}const be=G.trim(),Pe=he!==null;if(j){if(Pe)V(Q=>Q.map(Ne=>Ne.path===he?{path:be,content:le}:Ne)),M.success(t("settings.skills.page.toast.fileUpdated",{path:be}));else{if(R.some(Q=>Q.path===be)){M.error(t("settings.skills.page.toast.fileExists"));return}V(Q=>[...Q,{path:be,content:le}]),M.success(t("settings.skills.page.toast.fileAdded",{path:be}))}X(!1),ee(null);return}if(!a){M.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Le}=Zs.getState();if(await Le(a,be,le,d)){M.success(Pe?t("settings.skills.page.toast.fileUpdated",{path:be}):t("settings.skills.page.toast.fileCreated",{path:be})),X(!1),ee(null);const Q=await i(a,d);Q&&C(Q.sources.md.supportingFiles||[])}else M.error(t(Pe?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ce=be=>{if(j){V(Pe=>Pe.filter(Le=>Le.path!==be)),M.success(t("settings.skills.page.toast.fileRemoved",{path:be}));return}a&&pe(be)},Ze=async()=>{if(!xe||!a)return;Te(!0);const{deleteSupportingFile:be}=Zs.getState();if(await be(a,xe,d)){M.success(t("settings.skills.page.toast.fileDeleted",{path:xe}));const Le=await i(a,d);Le&&C(Le.sources.md.supportingFiles||[]),pe(null)}else M.error(t("settings.skills.page.toast.deleteFileFailed"));Te(!1)};return!a&&!u||h?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):te?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(s.Fragment,{children:[s.jsxs(os,{title:j?t("settings.skills.page.title.newSkill"):a,description:p?t("settings.skills.page.subtitle.skillLocation",{location:_e(ti(p.scope,p.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs($e,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[j&&s.jsxs(Ht,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(He,{value:b,onChange:be=>k(be.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Et,{value:ti(m,E),onValueChange:be=>{const Pe=Ec(be);I(Pe.scope),A(Pe.source==="agents"?"agents":"opencode")},children:[s.jsxs(Dt,{size:Gt,className:"w-fit gap-1.5",children:[m==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),E==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:_e(ti(m,E))})]}),s.jsx(Mt,{align:"start",children:so.map(be=>s.jsx(ut,{value:be.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[be.scope==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),be.source==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:_e(be.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ve(be.value)})]})},be.value))})]})]}),s.jsx(Kt,{label:s.jsxs(s.Fragment,{children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),info:t("settings.skills.page.field.descriptionHint"),controlClassName:"w-full max-w-none",children:s.jsx(Ms,{value:N,onChange:be=>je(be.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:w})})]}),s.jsx($e,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(sp,{currentMode:D==="preview"?"preview":"edit",onToggle:()=>$(be=>be==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:ye("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Ag),children:D==="preview"?s.jsx(ks,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(xd,{content:T,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(Oo,{value:T,onChange:Se,readOnly:w,extensions:se,className:"h-full",enableSearch:!0})})}),s.jsx($e,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ue,disabled:w,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const be=j?R:_;return be.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:be.map(Pe=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Oe(Pe.path),children:[s.jsx(z,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Pe.path}),j&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),!w&&s.jsx(H,{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:Le=>{Le.stopPropagation(),Ce(Pe.path)},children:s.jsx(z,{name:"delete-bin",className:"h-3 w-3"})})]},Pe.path))})})()}),s.jsx($e,{children:s.jsx(H,{onClick:Ke,disabled:w||U||!we,size:"xs",className:"!font-normal",children:t(U?"settings.common.actions.saving":j?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(zt,{open:xe!==null,onOpenChange:be=>{!be&&!Ie&&pe(null)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Vt,{children:t("settings.skills.page.deleteFileDialog.description",{path:xe??""})})]}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>pe(null),disabled:Ie,children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:Ze,disabled:Ie,children:t("settings.common.actions.delete")})]})]})}),s.jsx(zt,{open:L,onOpenChange:be=>{X(be),be||ee(null)},children:s.jsxs(Ut,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs($t,{className:"flex-shrink-0",children:[s.jsx(Bt,{children:t(he?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Vt,{children:t(he?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),re?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Ot,children:t("settings.skills.page.fileDialog.field.filePath")}),!he&&s.jsx(Yt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(He,{value:G,onChange:be=>Z(be.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-ring",disabled:he!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Ot} flex-shrink-0`,children:t("settings.skills.page.fileDialog.field.content")}),s.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:s.jsx(Oo,{value:le,onChange:oe,extensions:ae,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(is,{className:"mt-4",children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>{X(!1),ee(null)},children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:Re,disabled:re||!De,children:t(he?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},Xo=t=>{const e=dt.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(Ig,{}):s.jsx(Dg,{}),e[0]=n,e[1]=i):i=e[1],i};function Mg(){}const Rg=t=>{const e=dt.c(38),{onItemSelect:a}=t,{t:n}=et(),i=Xs(Fg),r=ce(Og),l=ce(Lg),{currentTheme:u}=La();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=ds(),e[0]=c):c=e[0];const f=c,d=Kg;let v,p;e[1]!==i||e[2]!==r||e[3]!==l?(v=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(x=>x.id===r)||l(i[0].id)},p=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=v,e[5]=p):(v=e[4],p=e[5]),o.useEffect(v,p);let j;e[6]===Symbol.for("react.memo_cache_sentinel")?(j=ye("border-b px-3","pt-4 pb-3"),e[6]=j):j=e[6];let h;e[7]!==n?(h=n("settings.page.projects.title"),e[7]=n,e[8]=h):h=e[8];let w;e[9]!==h?(w=s.jsx("h2",{className:`${kn} mb-3`,children:h}),e[9]=h,e[10]=w):w=e[10];let b;e[11]!==i.length||e[12]!==n?(b=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=b):b=e[13];let k;e[14]!==b?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:b}),e[14]=b,e[15]=k):k=e[15];let m;e[16]!==n?(m=!f&&s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:d,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(z,{name:"add",className:"size-4"})}),e[16]=n,e[17]=m):m=e[17];let I;e[18]!==k||e[19]!==m?(I=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,m]}),e[18]=k,e[19]=m,e[20]=I):I=e[20];let E;e[21]!==I||e[22]!==w?(E=s.jsxs("div",{className:j,children:[w,I]}),e[21]=I,e[22]=w,e[23]=E):E=e[23];let A;if(e[24]!==u||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let x;e[30]!==u||e[31]!==a||e[32]!==r||e[33]!==l?(x=y=>{const F=y.id===r,T=y.icon?vd[y.icon]:null,P=y.color?yd[y.color]??null:null,D=T?s.jsx(z,{name:T,className:ye("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:P?{color:P}:void 0}):s.jsx(z,{name:"folder",className:ye("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:P?{color:P}:void 0}),$=y.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:y.iconBackground?{backgroundColor:y.iconBackground}:void 0,children:s.jsx(jd,{project:y,options:{themeVariant:u.metadata.variant,iconColor:u.colors.surface.foreground},className:"h-full w-full object-contain",fallback:D})}):D;return s.jsx(zr,{title:y.label||y.path,icon:$,selected:F,onSelect:()=>{l(y.id),a?.()}},y.id)},e[30]=u,e[31]=a,e[32]=r,e[33]=l,e[34]=x):x=e[34],A=i.map(x),e[24]=u,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=A}else A=e[29];let N;return e[35]!==E||e[36]!==A?(N=s.jsx(Ac,{variant:"background",header:E,children:A}),e[35]=E,e[36]=A,e[37]=N):N=e[37],N};function Fg(t){return t.projects}function Og(t){return t.settingsProjectsSelectedId}function Lg(t){return t.setSettingsProjectsSelectedId}function Kg(){bd.requestDirectoryDialog()}const zg=()=>{const t=dt.c(30),{t:e}=et(),a=Xs(Ug),n=Xs(_g),i=ce($g),r=ce(Bg);let l;e:{if(!i){l=null;break e}let b;t[0]!==a||t[1]!==i?(b=a.find(k=>k.id===i)??null,t[0]=a,t[1]=i,t[2]=b):b=t[2],l=b}const u=l;let c,f;t[3]!==a||t[4]!==i||t[5]!==r?(c=()=>{if(a.length===0){r(null);return}i&&a.some(b=>b.id===i)||r(a[0].id)},f=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=c,t[7]=f):(c=t[6],f=t[7]),o.useEffect(c,f);let d;t[8]!==u||t[9]!==n?(d=async b=>{u&&n(u.id,{label:b.label,icon:b.icon,color:b.color,iconBackground:b.iconBackground,defaultAgent:b.defaultAgent??null,defaultModel:b.defaultModel??null,defaultVariant:b.defaultVariant??null})},t[8]=u,t[9]=n,t[10]=d):d=t[10];const v=d;if(!u){let b;t[11]!==e?(b=e("settings.page.projects.title"),t[11]=e,t[12]=b):b=t[12];let k;t[13]!==e?(k=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=k):k=t[14];let m;t[15]!==k?(m=s.jsx("p",{className:"typography-meta text-muted-foreground",children:k}),t[15]=k,t[16]=m):m=t[16];let I;return t[17]!==b||t[18]!==m?(I=s.jsx(os,{title:b,showSaveStatus:!0,children:m}),t[17]=b,t[18]=m,t[19]=I):I=t[19],I}let p;t[20]!==u.label||t[21]!==e?(p=u.label??e("settings.projects.page.title.default"),t[20]=u.label,t[21]=e,t[22]=p):p=t[22];const j=p;let h;t[23]!==v||t[24]!==u?(h=s.jsx(qu,{project:u,onIdentitySave:v}),t[23]=v,t[24]=u,t[25]=h):h=t[25];let w;return t[26]!==j||t[27]!==u.path||t[28]!==h?(w=s.jsx(os,{title:j,description:u.path,showSaveStatus:!0,outerClassName:"bg-background",children:h}),t[26]=j,t[27]=u.path,t[28]=h,t[29]=w):w=t[29],w};function Ug(t){return t.projects}function _g(t){return t.updateProjectMeta}function $g(t){return t.settingsProjectsSelectedId}function Bg(t){return t.setSettingsProjectsSelectedId}const Li=()=>Math.floor(2e4+Math.random()*3e4),Vg=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},Hg=()=>{if(typeof navigator>"u")return;const t=(navigator.userAgent||"").toLowerCase();if(t.includes("mac"))return"macos";if(t.includes("win"))return"windows";if(t.includes("linux"))return"linux"},el=t=>{switch((t||"").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}},tl=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingOpenChamber";case"updating":return"settings.remoteInstances.page.phase.updatingOpenChamber";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},qg=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),no=t=>!!(t&&qg.has(t)),sl=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||no(t)?"connecting":"idle",nl=t=>{switch(t){case"ready":return"settings.remoteInstances.page.state.ready";case"connecting":return"settings.remoteInstances.page.state.connecting";case"error":return"settings.remoteInstances.page.state.problem";default:return"settings.remoteInstances.page.state.notConnected"}},Gg=t=>{const e=(t||"").toLowerCase();return e?e.includes("ui authentication")||e.includes("ui password")?"uiPassword":e.includes("already in use")||e.includes("eaddrinuse")?"localPort":e.includes("neither bun nor npm")?"noRuntime":e.includes("opencode cli is not installed")?"noOpencode":e.includes("requires a ui password")?"uiPassword":e.includes("preferred remote openchamber port")?"externalPort":null:null},al={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Wg=t=>t==="noRuntime"?al.noRuntime:t==="noOpencode"?al.noOpencode:null,il=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||no(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Jg=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,Qg=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Li(),remoteHost:"127.0.0.1",remotePort:80}),Yg=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Js=t=>{const e=dt.c(7),{label:a,hint:n}=t;let i;e[0]!==a?(i=s.jsx("span",{children:a}),e[0]=a,e[1]=i):i=e[1];let r;e[2]!==n?(r=s.jsx(Yt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=r):r=e[3];let l;return e[4]!==i||e[5]!==r?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Ot}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},Zg=t=>{switch(t){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},rl=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Xg=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},eh=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const a=Number(e[1]),n=Number.isFinite(a)?new Date(a).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),r=e[3]||"";return`[${n}] [${i}] ${r}`},_r=(t="",e="")=>({id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`header-${Date.now()}-${Math.random().toString(16).slice(2)}`,name:t,value:e}),th=t=>t.trim().toLowerCase()==="authorization",vr=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!th(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},sh=t=>Object.entries(t||{}).map(([e,a])=>_r(e,a)),Mc=()=>{if(typeof window>"u")return null;const e=ni()||window.location.href;try{const a=Number(new URL(e).port||window.location.port);return Number.isFinite(a)&&a>0?a:null}catch{const a=Number(window.location.port);return Number.isFinite(a)&&a>0?a:null}},ol=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},nh=async()=>{const t=Sa(ni())||window.location.origin;if(!cs()||!ai()||(await Nn())?.desktopLanAccessActive!==!0)return t;const a=await hc(),n=Mc();return!a||!n?t:`http://${a}:${n}`},Pi=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},ah=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},ih=()=>{const{t}=et(),e=ce(S=>S.timeFormatPreference),{clientAuth:a}=Yr(),n=cs(),i=Ds(S=>S.instances),r=Ds(S=>S.statusesById),l=Ds(S=>S.importCandidates),u=Ds(S=>S.isLoading),c=Ds(S=>S.isImportsLoading),f=Ds(S=>S.isSaving),d=Ds(S=>S.error),v=Ds(S=>S.load),p=Ds(S=>S.loadImports),j=Ds(S=>S.refreshStatuses),h=Ds(S=>S.upsertInstance),w=Ds(S=>S.createFromCommand),b=Ds(S=>S.removeInstance),k=Ds(S=>S.connect),m=Ds(S=>S.disconnect),I=Ds(S=>S.retry),E=ce(S=>S.settingsRemoteInstancesSelectedId),A=ce(S=>S.setSettingsRemoteInstancesSelectedId),N=o.useMemo(()=>E&&i.find(S=>S.id===E)||null,[i,E]),[x,y]=o.useState(null),[F,T]=o.useState(!1),[P,D]=o.useState(!1),[$,_]=o.useState(null),[C,R]=o.useState([]),[V,U]=o.useState(null),[W,te]=o.useState(""),[O,ie]=o.useState(!1),[K,q]=o.useState({}),[B,L]=o.useState(!1),[X,G]=o.useState(!1),[Z,le]=o.useState(()=>Date.now()),[oe,he]=o.useState([]),[ee,re]=o.useState({}),[de,ke]=o.useState("local"),[ue,xe]=o.useState(!1),[pe,Ie]=o.useState(!1),[Te,we]=o.useState(""),[De,_e]=o.useState(""),[Ve,ve]=o.useState(""),[se,ae]=o.useState([]),[je,Se]=o.useState(""),[Ke,Ue]=o.useState(null),[Oe,Re]=o.useState(!1),[Ce,Ze]=o.useState(!1),[be,Pe]=o.useState(null),[Le,Xe]=o.useState(""),[Q,Ne]=o.useState(""),[Ae,We]=o.useState(""),[lt,at]=o.useState([]),[pt,bt]=o.useState([]),[J,qe]=o.useState([]),[it,ct]=o.useState(!1),[gt,Rt]=o.useState(""),[tt,ft]=o.useState(null),[jt,Je]=o.useState(null),[St,Fe]=o.useState(null),[wt,Y]=o.useState(null),[fe,Me]=o.useState(!1),[Ee,rt]=o.useState(!1),[ot,Ge]=o.useState("configure"),[Nt,ns]=o.useState(!1),[Zt,Qe]=o.useState("relay"),[Be,Ct]=o.useState(!0),[Pt,es]=o.useState(null),ts=o.useMemo(()=>pt.filter(S=>!!S.revokedAt).length,[pt]),[rs,fs]=o.useState(!1),[Rs,me]=o.useState("saved"),[ht,kt]=o.useState(""),[Xt,ss]=o.useState(""),[Jt,ms]=o.useState(""),[Ns,us]=o.useState(!1);o.useEffect(()=>{v(),p()},[v,p]);const It=o.useCallback(async()=>{xe(!0),Ue(null);try{const S=await So();he(S.hosts||[]),ke(S.defaultHostId||"local")}catch(S){Ue(S instanceof Error?S.message:String(S))}finally{xe(!1)}},[]);o.useEffect(()=>{It()},[It]);const Ft=o.useCallback(async(S,ne=de)=>{Ie(!0),Ue(null);try{await Co({hosts:S,defaultHostId:ne,initialHostChoiceCompleted:!0}),he(S),ke(ne)}catch(ze){Ue(ze instanceof Error?ze.message:String(ze))}finally{Ie(!1)}},[de]),Wt=o.useCallback(async()=>{const S=Io(De);if(!S){Ue(t("desktopHostSwitcher.error.invalidUrl"));return}const ne=S.persistedUrl,st={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Te.trim()||Ba(ne),url:ne,apiUrl:ne,...Ve.trim()?{clientToken:Ve.trim()}:{},...vr(se)?{requestHeaders:vr(se)}:{}};await Ft([st,...oe],de),we(""),_e(""),ve(""),ae([]),Re(!1),S.redeemUrl&&Pi(S.redeemUrl)},[de,se,oe,Te,Ve,De,Ft,t]),qt=o.useCallback(async()=>{const S=gu(je);if(!S){Ue(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const ne=await hu().catch(()=>""),ze=JSON.stringify({pairingId:S.pairingId,secret:S.secret,clientLabel:S.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Hg(),...ne?{dedupeKey:`desktop:${ne}`}:{}}),st={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:ze},Lt=async Tt=>{if(!Tt.ok)return null;const Os=await Tt.json().catch(()=>null);return(typeof Os?.clientToken=="string"?Os.clientToken.trim():"")||null},Cs=[...S.candidates].sort((Tt,Os)=>(Tt.type==="relay"?1:0)-(Os.type==="relay"?1:0));let xs=null;for(const Tt of Cs){if(Tt.type==="relay"){const qn=fu({relayUrl:Tt.relayUrl,serverId:Tt.serverId,hostEncPubJwk:Tt.hostEncPubJwk,...Tt.grant?{grant:Tt.grant}:{}});try{const ya=await qn.fetch("/api/client-auth/pairing/redeem",st),bi=await Lt(ya);if(bi){xs={kind:"relay",relay:{relayUrl:Tt.relayUrl,serverId:Tt.serverId,hostEncPubJwk:Tt.hostEncPubJwk},token:bi};break}}catch{}finally{qn.close()}continue}const Os=Sa(Tt.url);if(Os)try{const qn=await fetch(`${Os}/api/client-auth/pairing/redeem`,st),ya=await Lt(qn);if(ya){xs={kind:"direct",url:Os,token:ya};break}}catch{}}if(!xs){Ue(t("desktopHostSwitcher.error.invalidUrl"));return}const Ws=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Is=S.candidates.find(Tt=>Tt.type==="relay"),tn=xs.kind==="relay"?xs.relay:Is?{relayUrl:Is.relayUrl,serverId:Is.serverId,hostEncPubJwk:Is.hostEncPubJwk}:void 0,_a=S.candidates.filter(Tt=>Tt.type!=="relay").map(Tt=>Sa(Tt.url)).find(Tt=>!!Tt),Hn=xs.kind==="direct"?xs.url:_a,{token:$a}=xs,At=Hn||(tn?xu(tn.serverId):null);if(!At){Ue(t("desktopHostSwitcher.error.invalidUrl"));return}const Qt={url:At,apiUrl:Hn||void 0,clientToken:$a,...tn?{relay:tn}:{}},dn=oe.find(Tt=>tn?Tt.relay?.serverId===tn.serverId:!Tt.relay&&Sa(Tt.apiUrl||Tt.url)===At);if(dn){const Tt=oe.map(Os=>Os.id===dn.id?{...Os,label:S.label||Os.label,...Qt}:Os);await Ft(Tt,de)}else await Ft([{id:Ws(),label:S.label||Ba(At),...Qt},...oe],de);Se(""),Ue(null),Ze(!1)},[je,de,oe,Ft,t]),ps=o.useCallback(async S=>{const ne=oe.filter(st=>st.id!==S);await Ft(ne,de===S?"local":de),be===S&&Pe(null)},[de,be,oe,Ft]),Fs=o.useCallback(S=>{Pe(S.id),Xe(S.label),Ne(S.apiUrl||S.url),We(S.clientToken||""),at(sh(S.requestHeaders)),Ue(null)},[]),Gi=o.useCallback(async()=>{if(!be)return;const S=Io(Q);if(!S){Ue(t("desktopHostSwitcher.error.invalidUrl"));return}const ne=S.persistedUrl,ze=oe.map(st=>st.id===be?{...st,label:Le.trim()||Ba(ne),url:ne,apiUrl:ne,clientToken:Ae.trim()||void 0,requestHeaders:vr(lt)}:st);await Ft(ze,de),Pe(null),S.redeemUrl&&Pi(S.redeemUrl)},[de,lt,Le,Ae,Q,be,oe,Ft,t]),Wi=o.useCallback(async()=>{const S=Xt.trim();if(!S){M.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const ne=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await w(ne,S,Jt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),A(ne),fs(!1),ss(""),ms(""),M.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(ze){M.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:ze instanceof Error?ze.message:String(ze)})}},[w,A,Xt,Jt,t]),oi=o.useCallback(()=>{kt(""),me(l.length>0?"saved":"manual"),fs(!0)},[l.length]),Ji=o.useCallback(async S=>{await Ft(oe,S)},[oe,Ft]);o.useEffect(()=>{if(!n||oe.length===0)return;let S=!1;return Promise.all(oe.map(async ne=>{const ze=()=>ku(ne.relay,{clientToken:ne.clientToken||null,requestHeaders:ne.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(ne.relay&&!ne.apiUrl)return[ne.id,await ze()];const st=Sa(bu(ne));if(!st)return[ne.id,ne.relay?await ze():{status:"unreachable",latencyMs:0}];const Lt=await vu(st,{clientToken:ne.clientToken||null,requestHeaders:ne.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Lt.status==="unreachable"&&ne.relay){const Cs=await ze();if(Cs.status==="ok")return[ne.id,Cs]}return[ne.id,Lt]})).then(ne=>{S||re(Object.fromEntries(ne))}),()=>{S=!0}},[oe,n]);const _s=o.useCallback(async S=>{if(a){S?.silent||ct(!0),S?.silent||ft(null);try{const[ne,ze]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);bt(ne),ze&&qe(ze)}catch(ne){S?.silent||ft(ne instanceof Error?ne.message:String(ne))}finally{S?.silent||ct(!1)}}},[a]),Ka=o.useRef(!1);o.useEffect(()=>{if(!(!Ee||ot!=="result"||!St)){if(J.some(S=>S.id===St)){Ka.current=!0;return}Ka.current&&(Fe(null),rt(!1),pt.some(S=>S.pairingId===St)&&M.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Ee,ot,St,J,pt,t]);const Qi=o.useCallback(async S=>{if(a)try{await a.cancelPairing(S),qe(ne=>ne.filter(ze=>ze.id!==S)),await _s({silent:!0})}catch(ne){ft(ne instanceof Error?ne.message:String(ne))}},[a,_s]);o.useEffect(()=>{if(!a)return;_s();const S=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||_s({silent:!0})},5e3);return()=>window.clearInterval(S)},[a,_s]);const li=o.useCallback(async()=>{if(a?.getPairingTransports)try{const st=await a.getPairingTransports();return{localUrl:st.local,lanUrl:st.lan,relayAvailable:st.relayAvailable}}catch{}const S=Mc(),ne=S?`http://127.0.0.1:${S}`:ol(window.location.origin)?window.location.origin:null;let ze=null;try{const st=Sa(await nh());ze=st&&!ol(st)?st:null}catch{}return{localUrl:ne,lanUrl:ze,relayAvailable:!0}},[a]),ci=o.useCallback(async()=>{ft(null),Je(null),Y(null),Me(!1),Fe(null),Ge("configure"),Ct(!0),rt(!0);const S=await li();es(S),Qe(S.relayAvailable?"relay":S.lanUrl?"lan":"local")},[li]),Yi=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Pt)){ft(null),ns(!0);try{const S=gt.trim()||void 0;let ne,ze,st=!0;Zt==="local"?(ne=Pt.localUrl??void 0,ze=!1):Zt==="lan"?(ne=Pt.lanUrl??void 0,ze=Be):Be&&Pt.lanUrl?(ne=Pt.lanUrl,ze=!0):(st=!1,ze=!0);const{pairing:Lt,server:Cs}=await a.createPairingSession({label:S,allowedClientKinds:["mobile","desktop"],serverUrl:ne,includeRelay:ze,includeDirect:st}),xs=yu({pairingId:Lt.id,secret:Lt.secret,label:Cs.label,fingerprint:Lt.fingerprint??void 0,expiresAt:Lt.expiresAt,candidates:Cs.candidates}),Ws=ju(xs);Je(Ws),Y(await kc.toDataURL(Ws,{width:1024,margin:2,errorCorrectionLevel:"L"})),Me(!1),Ka.current=!1,Fe(Lt.id),Ge("result"),await _s({silent:!0})}catch(S){ft(S instanceof Error?S.message:String(S))}finally{ns(!1)}}},[a,Pt,Zt,Be,gt,_s]),Zi=o.useCallback(()=>{jt&&Aa(jt).then(S=>{S.ok&&(Me(!0),window.setTimeout(()=>Me(!1),2e3))})},[jt]),Xi=o.useCallback(async S=>{if(!a)return;const ne=S.clientKind==="desktop-local";ft(null);try{if(await a.revokeClient(S.id),ne&&cs()){const ze=await So();await Co({hosts:ze.hosts,defaultHostId:ze.defaultHostId,initialHostChoiceCompleted:ze.initialHostChoiceCompleted,localClientToken:null}),bt(st=>st.map(Lt=>Lt.id===S.id?{...Lt,revokedAt:new Date().toISOString()}:Lt)),wu({apiBaseUrl:ni(),clientToken:null,runtimeKey:"local"});return}await _s()}catch(ze){ft(ze instanceof Error?ze.message:String(ze))}},[a,_s]),di=o.useCallback(async()=>{if(a){ft(null);try{await a.purgeRevokedClients(),await _s()}catch(S){ft(S instanceof Error?S.message:String(S))}}},[a,_s]);o.useEffect(()=>{y(N)},[N]),o.useEffect(()=>{us(!1)},[E]),o.useEffect(()=>{if(!E)return;const S=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||j()},2e3);return()=>{window.clearInterval(S)}},[j,E]),o.useEffect(()=>{let S=null,ne=Date.now();const ze=()=>{const Lt=Date.now();Lt-ne>=1e3&&(le(Lt),ne=Lt),S=requestAnimationFrame(ze)};(typeof document>"u"||document.visibilityState==="visible")&&(S=requestAnimationFrame(ze));const st=()=>{document.visibilityState==="visible"&&S===null?S=requestAnimationFrame(ze):document.visibilityState!=="visible"&&S!==null&&(cancelAnimationFrame(S),S=null)};return document.addEventListener("visibilitychange",st),()=>{document.removeEventListener("visibilitychange",st),S!==null&&cancelAnimationFrame(S)}},[]);const Ss=E?r[E]:null,en=Ss?.phase,pa=en==="ready",Sn=en==="degraded",Tn=no(en),ln=pa||(Tn||Sn),er=Ss?Math.max(0,Z-Ss.updatedAtMs):0,$n=Sn&&er>12e3,ma=sl(en),Bn=ma==="error"?Gg(Ss?.detail):null,za=Wg(Bn),tr=o.useMemo(()=>!x||!N?!1:JSON.stringify(x)!==JSON.stringify(N),[x,N]),gs=o.useCallback(S=>{y(ne=>ne&&S(ne))},[]),sr=o.useCallback(async()=>{if(!x)return;const S=ah(x);if(!S.sshCommand.trim()){M.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(S.remoteOpenchamber.mode==="external"&&!S.remoteOpenchamber.preferredPort){M.error(t("settings.remoteInstances.page.validation.externalPortRequired")),us(!0);return}if(S.remoteOpenchamber.mode==="managed"&&S.remoteOpenchamber.bindHost==="0.0.0.0"&&!S.auth.openchamberPassword?.value?.trim()){M.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),us(!0),window.setTimeout(()=>Cn.current?.focus(),0);return}if(!(S.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(S.auth.sshPassword?.enabled&&S.auth.sshPassword.value?.trim()&&S.auth.sshPassword.store!=="settings"){const ne=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));S.auth.sshPassword.store=ne?"settings":"never",ne||(S.auth.sshPassword.value=void 0)}if(S.auth.openchamberPassword?.enabled&&S.auth.openchamberPassword.value?.trim()&&S.auth.openchamberPassword.store!=="settings"){const ne=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));S.auth.openchamberPassword.store=ne?"settings":"never",ne||(S.auth.openchamberPassword.value=void 0)}try{await h(S),M.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(ne){M.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:ne instanceof Error?ne.message:String(ne)})}}},[x,t,h]),ga=o.useCallback(async(S,ne)=>{const ze=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await w(ze,`ssh ${ne}`,S),A(ze),M.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(st){return M.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:st instanceof Error?st.message:String(st)}),!1}},[w,A,t]),ha=o.useCallback(()=>{O||(U(null),te(""))},[O]),nr=o.useCallback((S,ne)=>{if(fs(!1),ne){U(S),te(Yg(S));return}ga(S,S)},[ga]),ui=o.useMemo(()=>zi(l,ht,S=>[S.host,S.sshCommand]),[l,ht]),ar=o.useCallback(S=>{const ne=(S||"").trim();if(!ne){M.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Pi(ne)},[t]),pi=o.useCallback(async()=>{const S=V,ne=W.trim();if(S){if(!ne){M.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}ie(!0);try{await ga(S,ne)&&(U(null),te(""))}finally{ie(!1)}}},[ga,W,V,t]),fa=o.useCallback(async()=>{if(N)try{await k(N.id);return}catch(S){if(!Vg(S)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw S;const ze={...N,localForward:{...N.localForward,preferredLocalPort:Li()}};await h(ze),await k(ze.id),M.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[k,N,t,h]),Cn=o.useRef(null),Vn=o.useRef(null),Ua=o.useCallback(async S=>{if(N){if(S==="localPort"){const ne={...N,localForward:{...N.localForward,preferredLocalPort:Li()}};try{await h(ne),await k(ne.id),M.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(ze){M.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:ze instanceof Error?ze.message:String(ze)})}return}us(!0),window.setTimeout(()=>{if(S==="uiPassword"){Cn.current?.focus();return}Vn.current?.scrollIntoView({block:"center"})},0)}},[k,N,t,h]),En=o.useCallback(async S=>(await wd(S,600)).map(ze=>eh(ze)),[]),xa=o.useCallback(async()=>{if(x){T(!0),D(!0),_(null);try{const S=await En(x.id);R(S)}catch(S){R([]),_(S instanceof Error?S.message:String(S))}finally{D(!1)}}},[x,En]);o.useEffect(()=>{if(!F||!x)return;let S=!1;const ne=async()=>{try{const st=await En(x.id);S||(R(st),_(null))}catch(st){S||_(st instanceof Error?st.message:String(st))}};ne();const ze=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ne()},1e3);return()=>{S=!0,window.clearInterval(ze)}},[x,F,En]);const ge=o.useMemo(()=>C.join(`
27
+ `),[C]),hs=o.useCallback(()=>{if(!ge.trim()){M.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Aa(ge).then(S=>{S.ok&&M.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[ge,t]),ba=o.useCallback(async()=>{if(x)try{await kd(x.id),R([]),M.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(S){M.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:S instanceof Error?S.message:String(S)})}},[x,t]),mi=o.useCallback(async()=>{if(!Ss?.localUrl){M.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const S=Ss.localUrl.trim();if(!S){M.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Pi(S)},[Ss?.localUrl,t]),gi=o.useCallback(()=>{if(!x)return;if(!ln&&x.remoteOpenchamber.mode==="external"&&!x.remoteOpenchamber.preferredPort){M.error(t("settings.remoteInstances.page.validation.externalPortRequired")),us(!0);return}if(!ln&&x.remoteOpenchamber.mode==="managed"&&x.remoteOpenchamber.bindHost==="0.0.0.0"&&!x.auth.openchamberPassword?.value?.trim()){M.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),us(!0),window.setTimeout(()=>Cn.current?.focus(),0);return}L(!0),(ln?m(x.id):fa()).catch(ne=>{const ze=ln?pa?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";M.error(t(ze),{description:ne instanceof Error?ne.message:String(ne)})}).finally(()=>{L(!1)})},[ln,fa,m,x,pa,t]),hi=o.useCallback(()=>{if(!x||Tn)return;G(!0),(Sn?m(x.id).then(()=>fa()):I(x.id)).catch(ne=>{M.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:ne instanceof Error?ne.message:String(ne)})}).finally(()=>{G(!1)})},[fa,m,x,Tn,Sn,I,t]),fi=t(Tn?"settings.remoteInstances.page.actions.connecting":Sn?$n?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),xi=!B&&!X&&(en==="error"||en==="idle"||!en||Sn&&$n)&&!Tn,ir=t(pa?"settings.remoteInstances.sidebar.actions.disconnect":ln?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!x)return s.jsxs(os,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs($e,{title:t("settings.remoteInstances.clientAuth.title"),info:t("settings.remoteInstances.clientAuth.description"),divider:!1,settingsItem:"remote-instances.client-auth",contentClassName:"space-y-3",children:[s.jsx("div",{children:s.jsxs(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{ci()},children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[ts>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{di()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,it&&pt.length===0&&J.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):pt.length===0&&J.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[J.map(S=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[var(--status-warning)] animate-pulse"}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:S.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),S.usesRelay?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.viaRelay")}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:t("settings.remoteInstances.clientAuth.state.pending")})]}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Qi(S.id)},children:t("settings.common.actions.cancel")})]},`pending-${S.id}`)),pt.map(S=>{const ne=S.clientKind==="desktop-local",ze=S.lastUsedAt?Date.parse(S.lastUsedAt):Number.NaN,st=!S.revokedAt&&(ne||Number.isFinite(ze)&&Date.now()-ze<9e4),Lt=S.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):st?S.lastTransport==="relay"&&!ne?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(ze)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Nd(ze,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",S.revokedAt?"bg-muted-foreground/20":st?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:S.label}),el(S.devicePlatform)?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:el(S.devicePlatform)}):null,ne?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:ye("typography-micro truncate",st&&!S.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Lt})]})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Xi(S)},disabled:!!S.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},S.id)})]})]}),tt?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:tt}):null]}):null,n?s.jsxs($e,{title:t("settings.remoteInstances.direct.title"),info:t("settings.remoteInstances.direct.description"),settingsItem:"remote-instances.direct-hosts",contentClassName:"space-y-4",headerAction:s.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Ze(!0),disabled:pe,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Re(!0),disabled:pe,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:ue?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):oe.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):oe.map(S=>{const ne=ee[S.id],ze=ne?ne.status==="ok"?"desktopHostSwitcher.status.connected":ne.status==="auth"?"desktopHostSwitcher.status.authRequired":ne.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":ne.status==="incompatible"?"desktopHostSwitcher.status.incompatible":ne.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",st=ne?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",ne?st?"bg-[var(--status-success)]":"bg-[var(--status-error)]":"bg-muted-foreground/30 animate-pulse")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Ba(S.label)}),de===S.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:ye("typography-micro shrink-0",st?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(ze),st&&typeof ne?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(ne.latencyMs))}):""]})]}),s.jsx("p",{className:ye("typography-micro text-muted-foreground truncate",S.apiUrl&&"font-mono"),children:S.relay&&!S.apiUrl?t("mobile.connect.relay.badge"):Ba(S.apiUrl||S.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ji(S.id)},disabled:pe||de===S.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:de===S.id?s.jsx(z,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"star",className:"h-3.5 w-3.5"})}),S.relay&&!S.apiUrl?null:s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Fs(S),disabled:pe,children:[s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ps(S.id)},disabled:pe,children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},S.id)})}),Ke?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ke}):null]}):null,n?s.jsx(zt,{open:Oe,onOpenChange:Re,children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Wt()},children:[s.jsx(He,{className:"h-8",value:Te,onChange:S=>we(S.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:pe}),s.jsx(He,{className:"h-8",value:De,onChange:S=>_e(S.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:pe,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(He,{className:"h-8",value:Ve,onChange:S=>ve(S.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:pe}),s.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:t("settings.remoteInstances.direct.note")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(rn,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Yt,{children:t("settings.remoteInstances.direct.headers.description")})]}),se.map(S=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:S.name,onChange:ne=>ae(ze=>ze.map(st=>st.id===S.id?{...st,name:ne.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:pe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:S.value,onChange:ne=>ae(ze=>ze.map(st=>st.id===S.id?{...st,value:ne.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:pe}),s.jsx("button",{type:"button",onClick:()=>ae(ne=>ne.filter(ze=>ze.id!==S.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":t("settings.remoteInstances.direct.headers.removeAria"),disabled:pe,children:s.jsx(z,{name:"close",className:"h-4 w-4"})})]},S.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ae(S=>[...S,_r()]),disabled:pe,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Re(!1),disabled:pe,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:pe||!De.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(zt,{open:!!be,onOpenChange:S=>{S||Pe(null)},children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Gi()},children:[s.jsx(He,{className:"h-8",value:Le,onChange:S=>Xe(S.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:pe}),s.jsx(He,{className:"h-8",value:Q,onChange:S=>Ne(S.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:pe,autoFocus:!0}),s.jsx(He,{className:"h-8",value:Ae,onChange:S=>We(S.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:pe}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(rn,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Yt,{children:t("settings.remoteInstances.direct.headers.description")})]}),lt.map(S=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:S.name,onChange:ne=>at(ze=>ze.map(st=>st.id===S.id?{...st,name:ne.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:pe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:S.value,onChange:ne=>at(ze=>ze.map(st=>st.id===S.id?{...st,value:ne.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:pe}),s.jsx("button",{type:"button",onClick:()=>at(ne=>ne.filter(ze=>ze.id!==S.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":t("settings.remoteInstances.direct.headers.removeAria"),disabled:pe,children:s.jsx(z,{name:"close",className:"h-4 w-4"})})]},S.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>at(S=>[...S,_r()]),disabled:pe,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe(null),disabled:pe,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:pe,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(zt,{open:Ce,onOpenChange:Ze,children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),qt()},children:[s.jsx(He,{className:"h-8",value:je,onChange:S=>Se(S.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:pe,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ze(!1),disabled:pe,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:pe||!je.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(zt,{open:Ee,onOpenChange:rt,children:s.jsxs(Ut,{className:ot==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t(ot==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Vt,{children:t(ot==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),ot==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:S=>{S.preventDefault(),Yi()},children:[s.jsx(He,{className:"h-8",value:gt,onChange:S=>Rt(S.target.value),placeholder:t("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:t("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!Pt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Pt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Pt?.localUrl}].map(S=>{const ne=Zt===S.key;return s.jsxs("div",{className:ye("flex items-start gap-2 py-0.5",S.available?"cursor-pointer":"opacity-45"),onClick:()=>{S.available&&Qe(S.key)},role:"presentation",children:[s.jsx(Gr,{checked:ne,disabled:!S.available,onChange:()=>Qe(S.key),ariaLabel:S.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:ye("typography-ui-label font-normal",ne?"text-foreground":"text-foreground/70"),children:S.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:S.hint})]})]},S.key)})}),Zt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Er,{checked:Be,onChange:Ct,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,Zt==="relay"&&Pt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Er,{checked:Be,onChange:Ct,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")})]}):null]}),tt?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:tt}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rt(!1),disabled:Nt,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:Nt||!Pt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[wt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:wt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,jt?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[s.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:jt}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Zi,children:[s.jsx(z,{name:fe?"check":"file-copy",className:ye("h-3.5 w-3.5",fe&&"text-[var(--status-success)]")}),t(fe?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>rt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx($e,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:i.length}),headerAction:s.jsxs(H,{type:"button",size:"xs",className:"!font-normal",onClick:oi,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:u?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):i.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:l.length===1?t("settings.remoteInstances.page.empty.noInstancesWithOneImport"):l.length>1?t("settings.remoteInstances.page.empty.noInstancesWithImports",{count:l.length}):t("settings.remoteInstances.page.empty.noInstances")}):i.map(S=>{const ne=r[S.id],ze=S.nickname?.trim()||S.sshParsed?.destination||S.id,st=ne?.phase,Lt=st==="ready",Cs=sl(st),xs=Cs==="error"?ne?.detail:void 0;return s.jsxs("div",{className:"space-y-1.5 py-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${il(st)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:ze})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(nl(Cs)),Cs==="connecting"?` · ${t(tl(st))}`:"",Lt&&ne?.localUrl?` · ${ne.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Lt?s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ar(ne?.localUrl),children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Lt?m(S.id):k(S.id)).catch(Is=>M.error(t(Lt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:Is instanceof Error?Is.message:String(Is)}))},children:[Lt?s.jsx(z,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Lt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>A(S.id),children:[s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&b(S.id).catch(Is=>M.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Is instanceof Error?Is.message:String(Is)}))},children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),xs?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:xs}):null]},S.id)})}):null,n?s.jsx(zt,{open:rs,onOpenChange:fs,children:s.jsxs(Ut,{className:"sm:max-w-lg",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Vt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(an,{value:Rs,onChange:me,"aria-label":t("settings.remoteInstances.page.addDialog.sourceLabel"),options:[{value:"saved",label:t("settings.remoteInstances.page.addDialog.tab.saved")},{value:"manual",label:t("settings.remoteInstances.page.addDialog.tab.manual")}]}),Rs==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(He,{className:"h-8",value:ht,onChange:S=>kt(S.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):l.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.emptySaved")}):ui.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.searchEmpty")}):s.jsx("div",{className:"max-h-[45vh] overflow-auto",children:ui.map(S=>s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] py-2.5 last:border-b-0",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label font-medium text-foreground truncate",children:[S.host,S.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:S.sshCommand})]}),s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{nr(S.host,S.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${S.source}:${S.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Wi()},children:[s.jsx(He,{className:"h-8",value:Jt,onChange:S=>ms(S.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:f}),s.jsx(He,{className:"h-8",value:Xt,onChange:S=>ss(S.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:f,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>fs(!1),disabled:f,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:f||!Xt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(zt,{open:!!V,onOpenChange:S=>{S||ha()},children:s.jsxs(Ut,{className:"sm:max-w-md",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:V?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:V}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),pi()},children:[s.jsx(He,{value:W,onChange:S=>te(S.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ha,disabled:O,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:O,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const cn=x.remoteOpenchamber.mode==="managed",Dn=cn&&x.remoteOpenchamber.bindHost==="0.0.0.0",va=Dn&&!x.auth.openchamberPassword?.value?.trim(),rr=x.nickname?.trim()||x.sshParsed?.destination||x.id;return s.jsx(zt,{open:!!x,onOpenChange:S=>{S||A(null)},children:s.jsxs(Ut,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Tr} truncate`,children:rr}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${il(en)}`}),s.jsx("span",{className:"text-foreground",children:t(nl(ma))}),ma==="connecting"?s.jsx("span",{children:t(tl(en))}):null,Ss?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:Ss.localUrl}):null,$n?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs($e,{title:t("settings.remoteInstances.page.section.actions"),info:t("settings.remoteInstances.page.section.actionsDescription"),divider:!1,contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{type:"button",variant:ln?"outline":"default",size:"xs",className:"!font-normal",onClick:gi,disabled:B||X,children:[ln?s.jsx(z,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"plug-2",className:"h-3.5 w-3.5"}),ir]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:hi,disabled:!xi,children:[s.jsx(z,{name:"refresh",className:`h-3.5 w-3.5 ${Tn||Sn&&!$n?"animate-spin":""}`}),fi]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{xa()},children:[s.jsx(z,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&b(x.id).then(()=>{A(null),M.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(ne=>{M.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ne instanceof Error?ne.message:String(ne)})})},children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),ma==="error"&&Ss?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:Ss.detail}),za?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(za)}):null,Bn&&!za?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ua(Bn)},children:t(Bn==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":Bn==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,Ss?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:Ss.localUrl})]}):null]}),s.jsxs($e,{title:t("settings.remoteInstances.page.section.instance"),info:t("settings.remoteInstances.page.section.instanceDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(He,{className:"h-7 md:max-w-xl",value:x.sshCommand,onChange:S=>gs(ne=>({...ne,sshCommand:S.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(He,{className:"h-7 md:max-w-sm",value:x.nickname||"",onChange:S=>gs(ne=>({...ne,nickname:S.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Et,{value:x.remoteOpenchamber.mode,onValueChange:S=>gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,mode:S==="external"?"external":"managed"}})),children:[s.jsx(Dt,{size:Gt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(ut,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(yn,{open:Ns,onOpenChange:us,children:[s.jsxs(jn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:sc,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(z,{name:Ns?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(wn,{children:[s.jsx("p",{className:"px-2 pb-2 typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.section.advancedHint")}),s.jsxs("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(ws,{containerClassName:"w-fit",min:5,max:240,step:1,className:ye(Es,"tabular-nums"),value:x.connectionTimeoutSec,onValueChange:S=>{gs(ne=>({...ne,connectionTimeoutSec:Number.isFinite(S)?S:ne.connectionTimeoutSec}))}})]}),s.jsxs($e,{title:t("settings.remoteInstances.page.section.remoteServer"),info:t("settings.remoteInstances.page.section.remoteServerDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",ref:Vn,children:s.jsx(Js,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(ws,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Es,"tabular-nums"),value:x.remoteOpenchamber.preferredPort,onValueChange:S=>{gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,preferredPort:Number.isFinite(S)&&S>0?S:void 0}}))},onClear:()=>{gs(S=>({...S,remoteOpenchamber:{...S.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),cn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Et,{value:x.remoteOpenchamber.installMethod,onValueChange:S=>gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,installMethod:S==="npm"||S==="bun"?S:"auto"}})),children:[s.jsx(Dt,{size:Gt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(ut,{value:"bun",children:"bun"}),s.jsx(ut,{value:"npm",children:"npm"})]})]})]}):null,cn?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(Mi,{checked:Dn,onCheckedChange:S=>gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,bindHost:S?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),Dn?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,cn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(Mi,{checked:x.remoteOpenchamber.keepRunning,onCheckedChange:S=>gs(ne=>({...ne,remoteOpenchamber:{...ne.remoteOpenchamber,keepRunning:S}}))})})]}):null]}),s.jsxs($e,{title:t("settings.remoteInstances.page.section.mainTunnel"),info:t("settings.remoteInstances.page.section.mainTunnelDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Et,{value:x.localForward.bindHost,onValueChange:S=>{S==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||gs(ne=>({...ne,localForward:{...ne.localForward,bindHost:S==="localhost"||S==="0.0.0.0"?S:"127.0.0.1"}}))},children:[s.jsx(Dt,{size:Gt,className:"w-fit min-w-[240px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(ut,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(ut,{value:"0.0.0.0",children:t("settings.remoteInstances.page.field.bindHostOption.lan")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(ws,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Es,"tabular-nums"),value:x.localForward.preferredLocalPort,onValueChange:S=>{gs(ne=>({...ne,localForward:{...ne.localForward,preferredLocalPort:Number.isFinite(S)&&S>0?S:void 0}}))},onClear:()=>{gs(S=>({...S,localForward:{...S.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>gs(S=>({...S,localForward:{...S.localForward,preferredLocalPort:Li()}})),children:s.jsx(z,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.tunnelPreview.caption")}),s.jsx("p",{className:"typography-micro font-mono text-foreground/80 break-all",children:`${x.localForward.bindHost}:${x.localForward.preferredLocalPort||"auto"} → ${x.sshParsed?.destination||x.nickname||"remote"}:${x.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs($e,{title:t("settings.remoteInstances.page.section.authentication"),info:t("settings.remoteInstances.page.section.authenticationDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(He,{className:"h-7 md:max-w-sm",type:"password",value:x.auth.sshPassword?.value||"",onChange:S=>gs(ne=>({...ne,auth:{...ne.auth,sshPassword:{enabled:S.target.value.trim().length>0,value:S.target.value,store:ne.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:t(Dn?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(cn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(He,{className:ye("h-7 md:max-w-sm",va&&"border-[var(--status-error)]"),type:"password",ref:Cn,"aria-invalid":va,value:x.auth.openchamberPassword?.value||"",onChange:S=>gs(ne=>({...ne,auth:{...ne.auth,openchamberPassword:{enabled:S.target.value.trim().length>0,value:S.target.value,store:ne.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),va?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs($e,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[x.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,x.portForwards.map((S,ne)=>{const ze=At=>{gs(Qt=>({...Qt,portForwards:Qt.portForwards.map((dn,Tt)=>Tt===ne?At(dn):dn)}))},st=S.type==="remote"?"Local target":"Local listen",Lt=S.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.",Cs=S.type==="remote"?"Remote listen":"Remote target",xs=S.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Ws=rl(S.localHost||"localhost",S.localPort),Is=rl(S.remoteHost||"localhost",S.remotePort),tn=S.type==="local"&&typeof S.localPort=="number"&&S.localPort>0,_a=tn?`http://${Xg(S.localHost)}:${S.localPort}`:"",Hn=!!K[S.id],$a=S.type==="local"?t("settings.remoteInstances.page.forwardType.local"):S.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(yn,{open:Hn,onOpenChange:At=>{q(Qt=>({...Qt,[S.id]:At}))},className:`${ne>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(jn,{className:"flex items-center gap-2 group",children:[s.jsx(z,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Hn?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Jg(S)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:$a})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Mi,{checked:S.enabled,onCheckedChange:At=>ze(Qt=>({...Qt,enabled:At})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(H,{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:()=>gs(At=>({...At,portForwards:At.portForwards.filter(Qt=>Qt.id!==S.id)})),children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(wn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:t("settings.remoteInstances.page.field.forwardType"),hint:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.remoteInstances.page.field.forwardTypeHint")}),s.jsx("p",{children:t(Zg(S.type))})]})})}),s.jsxs(Et,{value:S.type,onValueChange:At=>ze(Qt=>({...Qt,type:At==="dynamic"||At==="remote"?At:"local"})),children:[s.jsx(Dt,{size:Gt,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(ut,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(ut,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:st,hint:Lt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:S.localHost||"127.0.0.1",onChange:At=>ze(Qt=>({...Qt,localHost:At.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ws,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Es,"tabular-nums"),value:S.localPort,onValueChange:At=>{ze(Qt=>({...Qt,localPort:Number.isFinite(At)&&At>0?At:void 0}))},onClear:()=>{ze(At=>({...At,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),S.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Js,{label:Cs,hint:xs})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:S.remoteHost||"",onChange:At=>ze(Qt=>({...Qt,remoteHost:At.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ws,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ye(Es,"tabular-nums"),value:S.remotePort,onValueChange:At=>{ze(Qt=>({...Qt,remotePort:Number.isFinite(At)&&At>0?At:void 0}))},onClear:()=>{ze(At=>({...At,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:S.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ws}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):S.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Is}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(z,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ws}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ws}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(z,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(z,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Is}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),tn?s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{hn(_a).then(At=>{At||M.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},S.id)}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const S=Qg();gs(ne=>({...ne,portForwards:[...ne.portForwards,S]})),q(ne=>({...ne,[S.id]:!0}))},children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]})]}),s.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{sr()},disabled:!tr||f,children:t("settings.common.actions.saveChanges")}),Ss?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Aa(Ss.localUrl||"").then(S=>{S.ok&&M.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(z,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{mi()},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,d?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:d}):null]})}),s.jsx(zt,{open:F,onOpenChange:T,children:s.jsxs(Ut,{className:"sm:max-w-2xl",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Vt,{children:x?.nickname?.trim()||x?.sshParsed?.destination||x?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:hs,disabled:P||!ge.trim(),children:[s.jsx(z,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ba()},disabled:P,children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),P?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):$?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:$}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:C.length>0?C.join(`
28
+ `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(zt,{open:!!V,onOpenChange:S=>{S||ha()},children:s.jsxs(Ut,{className:"sm:max-w-md",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:V?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:V}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),pi()},children:[s.jsx(He,{value:W,onChange:S=>te(S.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ha,disabled:O,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:O,children:t("settings.common.actions.create")})]})]})]})})]})})},rh="__add_provider__",oh=()=>{const t=An.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},lh=({onItemSelect:t})=>{const{t:e}=et(),a=Gs(),n=nt(h=>nc(h,a)),i=nt(h=>h.selectedProviderId),r=nt(h=>h.setSelectedProvider),l=Xs(h=>h.activeProjectId),[u,c]=o.useState({}),f=o.useMemo(()=>a||oh(),[l,a]),d=nt(h=>h.loadProviders);o.useEffect(()=>{a&&d({directory:a,source:"settings:providers"})},[d,a]),o.useEffect(()=>{if(n.length===0){c({});return}let h=!1;return(async()=>{const b=n.map(async k=>{try{const m=f?`?directory=${encodeURIComponent(f)}`:"",I=await xt(`/api/provider/${encodeURIComponent(k.id)}/source${m}`,{method:"GET",headers:{Accept:"application/json"}});if(!I.ok)return;const E=await I.json().catch(()=>null),A=E?.sources??E?.data?.sources;if(!A||h)return;c(N=>({...N,[k.id]:A}))}catch{}});await Promise.all(b)})(),()=>{h=!0}},[f,n]);const v="bg-background",p=o.useMemo(()=>n.filter(h=>!!u[h.id]?.project?.exists),[n,u]),j=o.useMemo(()=>n.filter(h=>!u[h.id]?.project?.exists),[n,u]);return s.jsxs("div",{className:ye("flex h-full flex-col",v),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${kn} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(ri,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(rh),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[j.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),j.map(h=>s.jsx(ll,{provider:h,selectedProviderId:i,onSelect:()=>{r(h.id),t?.()}},h.id))]}),p.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",j.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),p.map(h=>s.jsx(ll,{provider:h,selectedProviderId:i,onSelect:()=>{r(h.id),t?.()}},h.id))]})]})})]})},ll=t=>{const e=dt.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,u=a.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==c?(f=ye("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 d;e[2]!==a.id?(d=s.jsx(Qn,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=d):d=e[3];const v=a.name||a.id;let p;e[4]!==v?(p=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:v}),e[4]=v,e[5]=p):p=e[5];let j;e[6]!==r?(j=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=j):j=e[7];let h;e[8]!==i||e[9]!==d||e[10]!==p||e[11]!==j?(h=s.jsxs("button",{type:"button",onClick:i,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-ring",tabIndex:0,children:[d,p,j]}),e[8]=i,e[9]=d,e[10]=p,e[11]=j,e[12]=h):h=e[12];let w;return e[13]!==a.id||e[14]!==f||e[15]!==h?(w=s.jsx("div",{className:f,children:h},u),e[13]=a.id,e[14]=f,e[15]=h,e[16]=w):w=e[16],w},ch=t=>t,dh=(t,e,a)=>t&&!e&&!a,cl=t=>typeof t=="object"&&t!==null,Rc=t=>{const e=typeof t.type=="string"?t.type:"",a=`${t.name??""} ${t.label??""}`.toLowerCase(),n=`${e} ${a}`.toLowerCase();return n.includes("oauth")?"oauth":n.includes("api")?"api":e.toLowerCase()},uh=t=>{if(!cl(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>cl(i)));return e},dl=t=>t.length===0?!0:t.some(e=>Rc(e)==="api"),ul=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>Rc(e)==="oauth"),ph=t=>t!=="claude-code",pl=t=>typeof t.key=="string"&&t.key.trim().length>0||typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0||t.envDeclared===!0?!0:t.authSourceExists===!0,mh=t=>t.modelCount>0&&(!t.sourcesLoaded||t.hasCredentials||!!t.isEditableCustomProvider),gh=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,ao={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},Wn="__custom_provider__",hh=/^[a-z0-9][a-z0-9-_]*$/,Fc=/^https?:\/\//,fh=/^\{env:([^}]+)\}$/;let xh=0;const $i=()=>`row-${xh++}`,io=()=>({row:$i(),id:"",name:""}),ro=()=>({row:$i(),key:"",value:""}),bh=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[io()],headers:[ro()]});function vh(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function yh(t){const e=t.trim();if(!e)return{};const n=e.match(fh)?.[1]?.trim();return n?{env:n}:{key:e}}function jh(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&Fc.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>{if(!i||typeof i!="object")return!1;const r="api"in i&&i.api&&typeof i.api=="object"?i.api:null;return typeof r?.npm=="string"&&new Set(Object.values(ao)).has(r.npm)})}function ml(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&jh(t):!1}function gl(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function wh(t){const e=t.options&&typeof t.options=="object"?t.options:{},a=typeof e.baseURL=="string"?e.baseURL:"",n=e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},i=Object.entries(n).filter(f=>typeof f[0]=="string"&&typeof f[1]=="string").map(([f,d])=>({row:$i(),key:f,value:d})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([f,d])=>({id:f,name:d&&typeof d=="object"&&"name"in d&&typeof d.name=="string"?d.name:f})):[],l=r.length>0?r.map(f=>({row:$i(),id:typeof f?.id=="string"?f.id:"",name:typeof f?.name=="string"?f.name:typeof f?.id=="string"?f.id:""})):[io()],u=Array.isArray(t.env)?t.env.find(f=>typeof f=="string"&&f.trim().length>0)?.trim():void 0,c=r.find(f=>"api"in f);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:vh(c?.api?.npm),baseURL:a,apiKey:u?`{env:${u}}`:"",models:l,headers:i.length>0?i:[ro()]}}function kh(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=yh(t.form.apiKey),l=t.disabledProviders??[],u=t.editingProviderID?.trim(),c=e?hh.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),f=a?void 0:t.t("settings.providers.page.custom.error.name.required"),d=n?Fc.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),p=!!(i||r||u&&t.allowExistingAuth&&u===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),j=l.includes(e),w=c||!!(u&&u===e)?void 0:t.existingProviderIDs.has(e)&&!j?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,b=new Set,k=t.form.models.map(T=>{const P=T.id.trim(),D=P?b.has(P)?t.t("settings.providers.page.custom.error.duplicate"):void b.add(P):t.t("settings.providers.page.custom.error.required"),$=T.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:D,name:$}}),m=k.every(T=>!T.id&&!T.name),I=Object.fromEntries(t.form.models.map(T=>[T.id.trim(),{name:T.name.trim()}])),E=new Set,A=t.form.headers.map(T=>{const P=T.key.trim(),D=T.value.trim();if(!P&&!D)return{};const $=P?E.has(P.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void E.add(P.toLowerCase()):t.t("settings.providers.page.custom.error.required"),_=D?void 0:t.t("settings.providers.page.custom.error.required");return{key:$,value:_}}),N=A.every(T=>!T.key&&!T.value),x=Object.fromEntries(t.form.headers.map(T=>({key:T.key.trim(),value:T.value.trim()})).filter(T=>T.key&&T.value).map(T=>[T.key,T.value])),y={providerID:c??w,name:f,baseURL:d,apiKey:p};return!c&&!w&&!f&&!d&&!p&&m&&N?{err:y,models:k,headers:A,result:{providerID:e,name:a,apiKey:r,config:{npm:ao[t.form.protocol],name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(x).length>0?{headers:x}:{}},models:I}}}:{err:y,models:k,headers:A}}function Nh(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function Sh(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const hl=t=>{const e=dt.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:u,authFailureHint:c,onSubmit:f,onCancel:d,onDisconnect:v}=t;let p;e[0]!==n?(p=n===void 0?[]:n,e[0]=n,e[1]=p):p=e[1];const j=p,h=i===void 0?!1:i,w=r===void 0?"create":r,b=u===void 0?!1:u,k=c===void 0?null:c,{t:m}=et(),I=w==="edit";let E;e[2]!==l?(E=()=>l??bh(),e[2]=l,e[3]=E):E=e[3];const[A,N]=o.useState(E);let x;e[4]===Symbol.for("react.memo_cache_sentinel")?(x={},e[4]=x):x=e[4];const[y,F]=o.useState(x);let T;e[5]===Symbol.for("react.memo_cache_sentinel")?(T=[],e[5]=T):T=e[5];const[P,D]=o.useState(T);let $;e[6]===Symbol.for("react.memo_cache_sentinel")?($=[],e[6]=$):$=e[6];const[_,C]=o.useState($),R=o.useRef(null);let V,U;e[7]!==l||e[8]!==I?(V=()=>{l&&(I&&R.current===l.providerID||(R.current=I?l.providerID:null,N(l),F({}),D([]),C([])))},U=[l,I],e[7]=l,e[8]=I,e[9]=V,e[10]=U):(V=e[9],U=e[10]),o.useEffect(V,U);let W;e[11]===Symbol.for("react.memo_cache_sentinel")?(W=(It,Ft)=>{N(Wt=>({...Wt,[It]:Ft})),F(Wt=>({...Wt,[It]:void 0}))},e[11]=W):W=e[11];const te=W;let O;e[12]===Symbol.for("react.memo_cache_sentinel")?(O=(It,Ft,Wt)=>{N(qt=>({...qt,models:qt.models.map((ps,Fs)=>Fs===It?{...ps,[Ft]:Wt}:ps)})),D(qt=>{const ps=[...qt];return ps[It]={...ps[It]??{},[Ft]:void 0},ps})},e[12]=O):O=e[12];const ie=O;let K;e[13]===Symbol.for("react.memo_cache_sentinel")?(K=(It,Ft,Wt)=>{N(qt=>({...qt,headers:qt.headers.map((ps,Fs)=>Fs===It?{...ps,[Ft]:Wt}:ps)})),C(qt=>{const ps=[...qt];return ps[It]={...ps[It]??{},[Ft]:void 0},ps})},e[13]=K):K=e[13];const q=K;let B;e[14]!==b||e[15]!==h||e[16]!==j||e[17]!==a||e[18]!==A||e[19]!==I||e[20]!==f||e[21]!==m?(B=async It=>{if(It.preventDefault(),h)return;const Ft=kh({form:A,t:((Wt,qt)=>m(Wt,qt)),existingProviderIDs:a,disabledProviders:j,editingProviderID:I?A.providerID:void 0,allowExistingAuth:I&&b});F(Ft.err),D(Ft.models),C(Ft.headers),Ft.result&&await f(Ft.result)},e[14]=b,e[15]=h,e[16]=j,e[17]=a,e[18]=A,e[19]=I,e[20]=f,e[21]=m,e[22]=B):B=e[22];const L=B;let X;e[23]!==I||e[24]!==m?(X=m(I?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=I,e[24]=m,e[25]=X):X=e[25];let G;e[26]!==m?(G=m("settings.providers.page.custom.description"),e[26]=m,e[27]=G):G=e[27];let Z;e[28]!==G?(Z=s.jsx("p",{className:Jn,children:G}),e[28]=G,e[29]=Z):Z=e[29];let le;e[30]!==k?(le=k?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:k}):null,e[30]=k,e[31]=le):le=e[31];let oe;e[32]!==m?(oe=m("settings.providers.page.custom.field.providerID.label"),e[32]=m,e[33]=oe):oe=e[33];let he;e[34]!==m?(he=m("settings.providers.page.custom.field.providerID.info"),e[34]=m,e[35]=he):he=e[35];const ee=A.providerID;let re;e[36]===Symbol.for("react.memo_cache_sentinel")?(re=It=>te("providerID",It.target.value),e[36]=re):re=e[36];let de;e[37]!==m?(de=m("settings.providers.page.custom.field.providerID.placeholder"),e[37]=m,e[38]=de):de=e[38];const ke=!I,ue=I||h,xe=!!y.providerID;let pe;e[39]!==m?(pe=m("settings.providers.page.custom.field.providerID.label"),e[39]=m,e[40]=pe):pe=e[40];let Ie;e[41]!==A.providerID||e[42]!==de||e[43]!==ke||e[44]!==ue||e[45]!==xe||e[46]!==pe?(Ie=s.jsx(He,{value:ee,onChange:re,placeholder:de,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:ke,disabled:ue,"aria-invalid":xe,"aria-label":pe}),e[41]=A.providerID,e[42]=de,e[43]=ke,e[44]=ue,e[45]=xe,e[46]=pe,e[47]=Ie):Ie=e[47];let Te;e[48]!==y.providerID?(Te=y.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.providerID}):null,e[48]=y.providerID,e[49]=Te):Te=e[49];let we;e[50]!==oe||e[51]!==he||e[52]!==Ie||e[53]!==Te?(we=s.jsxs(Kt,{label:oe,info:he,children:[Ie,Te]}),e[50]=oe,e[51]=he,e[52]=Ie,e[53]=Te,e[54]=we):we=e[54];let De;e[55]!==m?(De=m("settings.providers.page.custom.field.protocol.label"),e[55]=m,e[56]=De):De=e[56];let _e;e[57]!==m?(_e=m("settings.providers.page.custom.field.protocol.info"),e[57]=m,e[58]=_e):_e=e[58];const Ve=A.protocol;let ve;e[59]===Symbol.for("react.memo_cache_sentinel")?(ve=It=>{It in ao&&N(Ft=>({...Ft,protocol:It}))},e[59]=ve):ve=e[59];let se;e[60]!==m?(se=m("settings.providers.page.custom.field.protocol.label"),e[60]=m,e[61]=se):se=e[61];let ae;e[62]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(_t,{}),e[62]=ae):ae=e[62];let je;e[63]!==se?(je=s.jsx(Dt,{"aria-label":se,className:"w-full",children:ae}),e[63]=se,e[64]=je):je=e[64];let Se;e[65]!==m?(Se=m("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=m,e[66]=Se):Se=e[66];let Ke;e[67]!==Se?(Ke=s.jsx(ut,{value:"openai-chat",children:Se}),e[67]=Se,e[68]=Ke):Ke=e[68];let Ue;e[69]!==m?(Ue=m("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=m,e[70]=Ue):Ue=e[70];let Oe;e[71]!==Ue?(Oe=s.jsx(ut,{value:"openai-responses",children:Ue}),e[71]=Ue,e[72]=Oe):Oe=e[72];let Re;e[73]!==m?(Re=m("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=m,e[74]=Re):Re=e[74];let Ce;e[75]!==Re?(Ce=s.jsx(ut,{value:"anthropic-messages",children:Re}),e[75]=Re,e[76]=Ce):Ce=e[76];let Ze;e[77]!==Ke||e[78]!==Oe||e[79]!==Ce?(Ze=s.jsxs(Mt,{children:[Ke,Oe,Ce]}),e[77]=Ke,e[78]=Oe,e[79]=Ce,e[80]=Ze):Ze=e[80];let be;e[81]!==h||e[82]!==A.protocol||e[83]!==je||e[84]!==Ze?(be=s.jsxs(Et,{value:Ve,onValueChange:ve,disabled:h,children:[je,Ze]}),e[81]=h,e[82]=A.protocol,e[83]=je,e[84]=Ze,e[85]=be):be=e[85];let Pe;e[86]!==De||e[87]!==_e||e[88]!==be?(Pe=s.jsx(Kt,{label:De,info:_e,children:be}),e[86]=De,e[87]=_e,e[88]=be,e[89]=Pe):Pe=e[89];let Le;e[90]!==m?(Le=m("settings.providers.page.custom.field.name.label"),e[90]=m,e[91]=Le):Le=e[91];let Xe;e[92]!==m?(Xe=m("settings.providers.page.custom.field.name.info"),e[92]=m,e[93]=Xe):Xe=e[93];const Q=A.name;let Ne;e[94]===Symbol.for("react.memo_cache_sentinel")?(Ne=It=>te("name",It.target.value),e[94]=Ne):Ne=e[94];let Ae;e[95]!==m?(Ae=m("settings.providers.page.custom.field.name.placeholder"),e[95]=m,e[96]=Ae):Ae=e[96];const We=!!y.name;let lt;e[97]!==m?(lt=m("settings.providers.page.custom.field.name.label"),e[97]=m,e[98]=lt):lt=e[98];let at;e[99]!==A.name||e[100]!==Ae||e[101]!==We||e[102]!==lt?(at=s.jsx(He,{value:Q,onChange:Ne,placeholder:Ae,className:"h-8 rounded-md px-3","aria-invalid":We,"aria-label":lt}),e[99]=A.name,e[100]=Ae,e[101]=We,e[102]=lt,e[103]=at):at=e[103];let pt;e[104]!==y.name?(pt=y.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.name}):null,e[104]=y.name,e[105]=pt):pt=e[105];let bt;e[106]!==Le||e[107]!==Xe||e[108]!==at||e[109]!==pt?(bt=s.jsxs(Kt,{label:Le,info:Xe,children:[at,pt]}),e[106]=Le,e[107]=Xe,e[108]=at,e[109]=pt,e[110]=bt):bt=e[110];let J;e[111]!==m?(J=m("settings.providers.page.custom.field.baseURL.label"),e[111]=m,e[112]=J):J=e[112];let qe;e[113]!==m?(qe=m("settings.providers.page.custom.field.baseURL.info"),e[113]=m,e[114]=qe):qe=e[114];const it=A.baseURL;let ct;e[115]===Symbol.for("react.memo_cache_sentinel")?(ct=It=>te("baseURL",It.target.value),e[115]=ct):ct=e[115];let gt;e[116]!==m?(gt=m("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=m,e[117]=gt):gt=e[117];const Rt=!!y.baseURL;let tt;e[118]!==m?(tt=m("settings.providers.page.custom.field.baseURL.label"),e[118]=m,e[119]=tt):tt=e[119];let ft;e[120]!==A.baseURL||e[121]!==gt||e[122]!==Rt||e[123]!==tt?(ft=s.jsx(He,{value:it,onChange:ct,placeholder:gt,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Rt,"aria-label":tt}),e[120]=A.baseURL,e[121]=gt,e[122]=Rt,e[123]=tt,e[124]=ft):ft=e[124];let jt;e[125]!==y.baseURL?(jt=y.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.baseURL}):null,e[125]=y.baseURL,e[126]=jt):jt=e[126];let Je;e[127]!==J||e[128]!==qe||e[129]!==ft||e[130]!==jt?(Je=s.jsxs(Kt,{label:J,info:qe,children:[ft,jt]}),e[127]=J,e[128]=qe,e[129]=ft,e[130]=jt,e[131]=Je):Je=e[131];let St;e[132]!==m?(St=m("settings.providers.page.custom.field.apiKey.label"),e[132]=m,e[133]=St):St=e[133];let Fe;e[134]!==b||e[135]!==I||e[136]!==m?(Fe=m(I&&b?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=b,e[135]=I,e[136]=m,e[137]=Fe):Fe=e[137];const wt=A.apiKey;let Y;e[138]===Symbol.for("react.memo_cache_sentinel")?(Y=It=>te("apiKey",It.target.value),e[138]=Y):Y=e[138];let fe;e[139]!==b||e[140]!==I||e[141]!==m?(fe=m(I&&b?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=b,e[140]=I,e[141]=m,e[142]=fe):fe=e[142];const Me=!!y.apiKey;let Ee;e[143]!==m?(Ee=m("settings.providers.page.custom.field.apiKey.label"),e[143]=m,e[144]=Ee):Ee=e[144];let rt;e[145]!==A.apiKey||e[146]!==fe||e[147]!==Me||e[148]!==Ee?(rt=s.jsx(He,{type:"password",value:wt,onChange:Y,placeholder:fe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Me,"aria-label":Ee}),e[145]=A.apiKey,e[146]=fe,e[147]=Me,e[148]=Ee,e[149]=rt):rt=e[149];let ot;e[150]!==y.apiKey?(ot=y.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:y.apiKey}):null,e[150]=y.apiKey,e[151]=ot):ot=e[151];let Ge;e[152]!==St||e[153]!==Fe||e[154]!==rt||e[155]!==ot?(Ge=s.jsxs(Kt,{label:St,info:Fe,children:[rt,ot]}),e[152]=St,e[153]=Fe,e[154]=rt,e[155]=ot,e[156]=Ge):Ge=e[156];let Nt;e[157]!==X||e[158]!==Z||e[159]!==le||e[160]!==we||e[161]!==Pe||e[162]!==bt||e[163]!==Je||e[164]!==Ge?(Nt=s.jsxs($e,{title:X,divider:!1,settingsItem:"providers.custom",contentClassName:nn,children:[Z,le,we,Pe,bt,Je,Ge]}),e[157]=X,e[158]=Z,e[159]=le,e[160]=we,e[161]=Pe,e[162]=bt,e[163]=Je,e[164]=Ge,e[165]=Nt):Nt=e[165];let ns;e[166]!==m?(ns=m("settings.providers.page.custom.models.title"),e[166]=m,e[167]=ns):ns=e[167];let Zt;if(e[168]!==A.models||e[169]!==P||e[170]!==m){let It;e[172]!==A.models.length||e[173]!==P||e[174]!==m?(It=(Ft,Wt)=>s.jsx("div",{className:`${Vs} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Ot,children:m("settings.providers.page.custom.models.idLabel")}),s.jsx(He,{value:Ft.id,onChange:qt=>ie(Wt,"id",qt.target.value),placeholder:m("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.models.idLabel")}),P[Wt]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:P[Wt]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Ot,children:m("settings.providers.page.custom.models.nameLabel")}),s.jsx(He,{value:Ft.name,onChange:qt=>ie(Wt,"name",qt.target.value),placeholder:m("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":m("settings.providers.page.custom.models.nameLabel")}),P[Wt]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:P[Wt]?.name}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:ys,disabled:A.models.length<=1,onClick:()=>{A.models.length<=1||(N(qt=>({...qt,models:qt.models.filter((ps,Fs)=>Fs!==Wt)})),D(qt=>qt.filter((ps,Fs)=>Fs!==Wt)))},"aria-label":m("settings.providers.page.custom.models.remove"),children:s.jsx(z,{name:"delete-bin",className:"size-4"})})]})},Ft.row),e[172]=A.models.length,e[173]=P,e[174]=m,e[175]=It):It=e[175],Zt=A.models.map(It),e[168]=A.models,e[169]=P,e[170]=m,e[171]=Zt}else Zt=e[171];let Qe;e[176]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>{N(Ch),D(Ih)},e[176]=Qe):Qe=e[176];let Be;e[177]!==m?(Be=m("settings.providers.page.custom.models.add"),e[177]=m,e[178]=Be):Be=e[178];let Ct;e[179]!==Be?(Ct=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Qe,children:Be}),e[179]=Be,e[180]=Ct):Ct=e[180];let Pt;e[181]!==ns||e[182]!==Zt||e[183]!==Ct?(Pt=s.jsxs($e,{title:ns,contentClassName:nn,children:[Zt,Ct]}),e[181]=ns,e[182]=Zt,e[183]=Ct,e[184]=Pt):Pt=e[184];let es;e[185]!==m?(es=m("settings.providers.page.custom.headers.title"),e[185]=m,e[186]=es):es=e[186];let ts;e[187]!==m?(ts=m("settings.providers.page.custom.headers.description"),e[187]=m,e[188]=ts):ts=e[188];let rs;e[189]!==ts?(rs=s.jsx("p",{className:Jn,children:ts}),e[189]=ts,e[190]=rs):rs=e[190];let fs;if(e[191]!==A.headers||e[192]!==_||e[193]!==m){let It;e[195]!==A.headers.length||e[196]!==_||e[197]!==m?(It=(Ft,Wt)=>s.jsx("div",{className:`${Vs} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Ot,children:m("settings.providers.page.custom.headers.keyLabel")}),s.jsx(He,{value:Ft.key,onChange:qt=>q(Wt,"key",qt.target.value),placeholder:m("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.headers.keyLabel")}),_[Wt]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:_[Wt]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Ot,children:m("settings.providers.page.custom.headers.valueLabel")}),s.jsx(He,{value:Ft.value,onChange:qt=>q(Wt,"value",qt.target.value),placeholder:m("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":m("settings.providers.page.custom.headers.valueLabel")}),_[Wt]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:_[Wt]?.value}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:ys,disabled:A.headers.length<=1,onClick:()=>{A.headers.length<=1||(N(qt=>({...qt,headers:qt.headers.filter((ps,Fs)=>Fs!==Wt)})),C(qt=>qt.filter((ps,Fs)=>Fs!==Wt)))},"aria-label":m("settings.providers.page.custom.headers.remove"),children:s.jsx(z,{name:"delete-bin",className:"size-4"})})]})},Ft.row),e[195]=A.headers.length,e[196]=_,e[197]=m,e[198]=It):It=e[198],fs=A.headers.map(It),e[191]=A.headers,e[192]=_,e[193]=m,e[194]=fs}else fs=e[194];let Rs;e[199]===Symbol.for("react.memo_cache_sentinel")?(Rs=()=>{N(Ph),C(Ah)},e[199]=Rs):Rs=e[199];let me;e[200]!==m?(me=m("settings.providers.page.custom.headers.add"),e[200]=m,e[201]=me):me=e[201];let ht;e[202]!==me?(ht=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Rs,children:me}),e[202]=me,e[203]=ht):ht=e[203];let kt;e[204]!==es||e[205]!==rs||e[206]!==fs||e[207]!==ht?(kt=s.jsxs($e,{title:es,contentClassName:nn,children:[rs,fs,ht]}),e[204]=es,e[205]=rs,e[206]=fs,e[207]=ht,e[208]=kt):kt=e[208];let Xt;e[209]!==h||e[210]!==d||e[211]!==m?(Xt=d?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:d,disabled:h,children:m("settings.providers.page.custom.actions.back")}):null,e[209]=h,e[210]=d,e[211]=m,e[212]=Xt):Xt=e[212];let ss;e[213]!==h||e[214]!==v||e[215]!==m?(ss=v?s.jsx(H,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{v()},disabled:h,children:m("settings.providers.page.actions.disconnect")}):null,e[213]=h,e[214]=v,e[215]=m,e[216]=ss):ss=e[216];let Jt;e[217]!==h||e[218]!==I||e[219]!==m?(Jt=m(h?"settings.providers.page.actions.saving":I?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=h,e[218]=I,e[219]=m,e[220]=Jt):Jt=e[220];let ms;e[221]!==h||e[222]!==Jt?(ms=s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:h,children:Jt}),e[221]=h,e[222]=Jt,e[223]=ms):ms=e[223];let Ns;e[224]!==Xt||e[225]!==ss||e[226]!==ms?(Ns=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Xt,ss,ms]}),e[224]=Xt,e[225]=ss,e[226]=ms,e[227]=Ns):Ns=e[227];let us;return e[228]!==L||e[229]!==Nt||e[230]!==Pt||e[231]!==kt||e[232]!==Ns?(us=s.jsxs("form",{onSubmit:L,className:"space-y-0",children:[Nt,Pt,kt,Ns]}),e[228]=L,e[229]=Nt,e[230]=Pt,e[231]=kt,e[232]=Ns,e[233]=us):us=e[233],us};function Ch(t){return{...t,models:[...t.models,io()]}}function Ih(t){return[...t,{}]}function Ph(t){return{...t,headers:[...t.headers,ro()]}}function Ah(t){return[...t,{}]}const Th=(t,e)=>!!e&&t!=="claude-code",Eh=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,da=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ts=t=>typeof t=="string"&&t.length>0?t:void 0,Dh=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!da(a))continue;const n=Ts(a.value);n!==void 0&&e.push({value:n,label:Ts(a.label)??n,...Ts(a.hint)?{hint:Ts(a.hint)}:{}})}return e},Mh=t=>{if(!da(t))return;const e=Ts(t.key),a=t.op==="eq"||t.op==="neq"?t.op:void 0;if(!(!e||!a||typeof t.value!="string"))return{key:e,op:a,value:t.value}},Rh=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!da(a))continue;const n=Ts(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?Dh(a.options):[];if(i==="select"&&r.length===0)continue;const l=Mh(a.when);e.push({type:i,key:n,message:Ts(a.message)??n,options:r,...Ts(a.placeholder)?{placeholder:Ts(a.placeholder)}:{},...l?{when:l}:{}})}return e},Fh=(t,e)=>{if(!t.when)return!0;const a=e[t.when.key]??"";return t.when.op==="eq"?a===t.when.value:a!==t.when.value},oo=(t,e)=>t.filter(a=>Fh(a,e)),Oh=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},Lh=(t,e)=>oo(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,Kh=(t,e)=>{const a={};for(const n of oo(t,e))a[n.key]=(e[n.key]??"").trim();return a},zh=t=>{const e=da(t)?t:{},a=da(e.data)?e.data:e,n=Ts(a.url)??Ts(a.verification_uri_complete)??Ts(a.verification_uri),i=Ts(a.instructions)??Ts(a.message);if(!n&&!i)return null;const r=Ts(a.user_code)??Ts(a.userCode)??(i?Eh.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},fl=(t,e,a)=>{const n=da(t)?t:{},i=da(n.data)?n.data:{};switch(n.name){case"ProviderAuthOauthMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"ProviderAuthOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"ProviderAuthOauthCallbackFailed":return e("settings.providers.page.auth.oauth.error.declined");case"ProviderAuthValidationFailed":return Ts(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},yr={phase:"idle"},xl=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=et(),[r,l]=o.useState(yr),[u,c]=o.useState({}),[f,d]=o.useState(""),v=o.useRef(null);o.useEffect(()=>()=>v.current?.abort(),[]);const p=r.phase==="idle"?null:r.methodIndex,j=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,h=async(x,y,F)=>{const T=await Aa(x);if(T.ok){M.success(i(y));return}console.error("Failed to copy OAuth value:",T.error),M.error(i(F))},w=async(x,y)=>{const F=new AbortController;v.current?.abort(),v.current=F;try{const T=await An.getSdkClient().provider.oauth.callback({providerID:t,method:x,...y?{code:y}:{}},{signal:F.signal});if(F.signal.aborted)return;if(T.error)throw T.error;l(yr),M.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(T){if(F.signal.aborted)return;console.error("Failed to complete OAuth flow:",T),l({phase:"failed",methodIndex:x,message:fl(T,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{v.current===F&&(v.current=null)}},b=async(x,y)=>{l({phase:"authorizing",methodIndex:x});let F;try{const T=await An.getSdkClient().provider.oauth.authorize({providerID:t,method:x,...Object.keys(y).length>0?{inputs:y}:{}});if(T.error)throw T.error;const P=zh(T.data);if(!P){l({phase:"failed",methodIndex:x,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}F=P}catch(T){console.error("Failed to start OAuth flow:",T),l({phase:"failed",methodIndex:x,message:fl(T,i,"settings.providers.page.toast.oauthStartFailed")});return}if(F.url&&Th(t,F.url)&&hn(F.url),F.method==="code"){d(""),l({phase:"awaitingCode",methodIndex:x,authorization:F,submitting:!1});return}l({phase:"waiting",methodIndex:x,authorization:F}),await w(x)},k=x=>{const y=Rh(x.prompts);if(y.length===0){b(x.index,{});return}c(Oh(y)),l({phase:"prompting",methodIndex:x.index,prompts:y,error:null})},m=()=>{if(r.phase!=="prompting")return;const x=Lh(r.prompts,u);if(x){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:x.message})});return}b(r.methodIndex,Kh(r.prompts,u))},I=()=>{if(r.phase!=="awaitingCode")return;const x=f.trim();x&&(l({...r,submitting:!0}),w(r.methodIndex,x))},E=()=>{v.current?.abort(),v.current=null,l(yr)},A=x=>{const y=u[x.key]??"",F=T=>c(P=>({...P,[x.key]:T}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:x.message}),x.type==="select"?s.jsxs(Et,{value:y,onValueChange:F,children:[s.jsx(Dt,{size:Gt,className:gn,children:s.jsx(_t,{children:T=>x.options.find(P=>P.value===T)?.label??null})}),s.jsx(Mt,{children:x.options.map(T=>s.jsx(ut,{value:T.value,children:T.hint?`${T.label} · ${T.hint}`:T.label},T.value))})]}):s.jsx(He,{value:y,onChange:T=>F(T.target.value),placeholder:x.placeholder,className:"max-w-[24rem] text-xs"})]},x.key)},N=x=>s.jsxs(s.Fragment,{children:[x.instructions&&s.jsx("p",{className:"typography-meta text-[var(--status-info-text)] bg-[var(--status-info-background)] px-2 py-1.5 rounded",children:x.instructions}),x.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:x.userCode,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{h(x.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),x.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:x.url,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{hn(x.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{h(x.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:ye("space-y-4",n),children:e.map(x=>{const y=p===x.index;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:x.label}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>k(x),disabled:j,children:i("settings.providers.page.actions.connect")})]}),y&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[oo(r.prompts,u).map(A),r.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{size:"xs",className:"!font-normal",onClick:m,children:i("settings.providers.page.actions.continue")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:E,children:i("settings.providers.page.actions.cancel")})]})]}),y&&r.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(z,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),y&&r.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[N(r.authorization),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(z,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:E,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),y&&r.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[N(r.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:f,onChange:F=>d(F.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:r.submitting}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:I,disabled:r.submitting||f.trim().length===0,children:r.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:E,disabled:r.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),y&&r.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.message}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>k(x),children:i("settings.providers.page.actions.tryAgain")})]})]},x.index)})})},bl=t=>Array.isArray(t?.env)&&t.env.some(e=>e.trim().length>0),Uh=t=>new Intl.NumberFormat(Qr(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),vl=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Uh(t);return e.endsWith(".0")?e.slice(0,-2):e},Ga="__add_provider__",Oc=t=>typeof t=="object"&&t!==null,yl=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),_h=t=>{if(typeof t=="string")return{id:t};if(!Oc(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const a=typeof t.name=="string"?t.name:void 0;return{id:e,name:a}},$h=t=>{let e=[];Array.isArray(t)?e=t:Oc(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>_h(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},Bh=()=>{const{t}=et(),e=Gs(),a=nt(Q=>nc(Q,e)),n=nt(Q=>Q.selectedProviderId),i=nt(Q=>Q.setSelectedProvider),r=nt(Q=>Q.getModelMetadata),l=ce(Q=>Q.hiddenModels),u=ce(Q=>Q.toggleHiddenModel),c=ce(Q=>Q.hideAllModels),f=ce(Q=>Q.showAllModels),[d,v]=o.useState({}),[p,j]=o.useState(!1),[h,w]=o.useState({}),[b,k]=o.useState(null),[m,I]=o.useState(""),[E,A]=o.useState([]),[N,x]=o.useState(!1),[y,F]=o.useState(null),[T,P]=o.useState(""),[D,$]=o.useState(""),[_,C]=o.useState(!1),[R,V]=o.useState({}),[U,W]=o.useState(0),[te,O]=o.useState(!1),[ie,K]=o.useState(null),[q,B]=o.useState(null),[L,X]=o.useState(null),[G,Z]=o.useState(null),[le,oe]=o.useState(null),[he,ee]=o.useState(null),re=n===Ga,de=re&&T===Wn,ke=!!(q&&n&&q===n&&!re);o.useEffect(()=>{!n&&a.length>0&&i(a[0].id)},[a,n,i]),o.useEffect(()=>{if(!n)return;let Q=!0;return(async()=>{j(!0);try{const Ae=await An.getSdkClient().provider.auth();if(Ae.error)throw new Error(`provider.auth failed: ${String(Ae.error)}`);if(!Q)return;v(uh(Ae.data))}catch(Ae){if(!Q)return;console.error("Failed to load provider auth methods:",Ae),M.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{Q&&j(!1)}})(),()=>{Q=!1}},[n,t]),o.useEffect(()=>{if(!ch(re))return;let Q=!0;return(async()=>{x(!0),F(null);try{const Ae=await An.getSdkClient().provider.list();if(Ae.error)throw new Error(`provider.list failed: ${String(Ae.error)}`);if(!Q)return;A($h(Ae.data))}catch(Ae){if(!Q)return;console.error("Failed to load available providers:",Ae),F(t("settings.providers.page.state.unableToLoadProviderList"))}finally{Q&&x(!1)}})(),()=>{Q=!1}},[re,t]);const ue=o.useMemo(()=>new Set(a.map(Q=>Q.id)),[a]),xe=o.useMemo(()=>E.filter(Q=>!ue.has(Q.id)).sort((Q,Ne)=>{const Ae=(Q.name||Q.id).toLowerCase(),We=(Ne.name||Ne.id).toLowerCase();return Ae.localeCompare(We)}),[E,ue]);o.useEffect(()=>{n===Ga&&T&&T!==Wn&&!xe.some(Q=>Q.id===T)&&P("")},[n,T,xe]),o.useEffect(()=>{if(n===Ga){O(!0),K(null),B(null),X(null),Z(null),oe(null);return}O(!1),K(null),q&&q!==n&&(B(null),X(null),Z(null),oe(null))},[n,q]),o.useEffect(()=>{if(!n||n===Ga)return;const Q=R[n];if(!Q)return;const Ne=a.find(lt=>lt.id===n),Ae=pl({key:Ne?.key,authSourceExists:Q.auth.exists,optionsApiKey:Ne?.options?.apiKey??null,envDeclared:bl(Ne)}),We=!!(Ne&&ml(Ne,Q));gh({hasCredentials:Ae,userDismissed:ie===n,isEditableCustomProvider:We})&&O(!0)},[n,R,a,ie]),o.useEffect(()=>{if(!n||n===Ga)return;let Q=!1;return(async()=>{try{const Ae=e?`?directory=${encodeURIComponent(e)}`:"",We=await xt(`/api/provider/${encodeURIComponent(n)}/source${Ae}`,{method:"GET",headers:{Accept:"application/json"}}),lt=await We.json().catch(()=>null);if(!We.ok)throw new Error(lt?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const at=lt?.sources??lt?.data?.sources;!Q&&at&&V(pt=>({...pt,[n]:at}))}catch(Ae){Q||console.error("Failed to load provider sources:",Ae)}})(),()=>{Q=!0}},[n,U,e,t]);const pe=o.useCallback(()=>{W(Q=>Q+1)},[]),Ie=o.useCallback(Q=>{V(Ne=>{const Ae=Ne[Q];return{...Ne,[Q]:{auth:{exists:!0,path:Ae?.auth.path??null},user:Ae?.user??{exists:!1,path:null},project:Ae?.project??{exists:!1,path:null},...Ae?.custom?{custom:Ae.custom}:{}}}}),K(null),O(!1),i(Q),pe()},[pe,i]),Te=o.useCallback(async(Q,Ne)=>{try{return await ac({scopes:[Q],mode:"active"}),"reloaded"}catch(Ae){if(Ae?.requiresManualRestart===!0)return Ne&&ta(Q,{id:Ne}),"manual-restart";throw Ae}},[]),we=a.find(Q=>Q.id===n),De=n?R[n]:void 0,_e=async Q=>{const Ne=h[Q]?.trim()??"";if(!Ne){M.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ae=`api:${Q}`;k(Ae);try{if((await An.getSdkClient().auth.set({providerID:Q,auth:{type:"api",key:Ne}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));M.success(t("settings.providers.page.toast.apiKeySaved")),w(lt=>({...lt,[Q]:""})),await Te("providers",Q),Ie(Q)}catch(We){console.error("Failed to save API key:",We),M.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{k(null)}},Ve=async Q=>{const Ne=`custom:${Q.providerID}`;k(Ne),ee(Q.providerID),oe(null);try{const Ae=Nh(Q);if(Ae&&(await An.getSdkClient().auth.set(Ae)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const We=Sh(Q,{scope:q?G??gl(R[q]):"user"}),lt=await xt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(We)}),at=await lt.json().catch(()=>null);if(!lt.ok)throw Ae&&oe(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(at?.error||t("settings.providers.page.toast.customProviderSaveFailed"));M.success(t("settings.providers.page.toast.customProviderSaved",{provider:Q.name})),P(""),B(null),X(null),Z(null),oe(null),ee(null),await Te("providers",Q.providerID),Ie(Q.providerID)}catch(Ae){console.error("Failed to save custom provider:",Ae),M.error(Ae instanceof Error&&Ae.message?Ae.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{k(null)}},ve=Q=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(Q+1)}),se=Q=>{O(!1),ph(Q)&&ta("providers",{id:Q}),Ie(Q)},ae=async Q=>{const Ne=`disconnect:${Q}`;k(Ne);try{const Ae=await xt(`/api/provider/${encodeURIComponent(Q)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),We=await Ae.json().catch(()=>null);if(!Ae.ok)throw new Error(We?.error||t("settings.providers.page.toast.providerDisconnectFailed"));M.success(t("settings.providers.page.toast.providerDisconnected")),await Te("providers",Q),K(null),pe()}catch(Ae){console.error("Failed to disconnect provider:",Ae),M.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{k(null)}},je=async Q=>{Q&&(await ae(Q),B(null),X(null),Z(null),oe(null),ee(null),P(""))};if(!re&&a.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(re)return s.jsxs(os,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx($e,{title:t("settings.providers.page.connect.selectProviderTitle"),divider:!1,settingsItem:"providers.connect",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),N?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):y?s.jsx("p",{className:"typography-meta text-muted-foreground",children:y}):s.jsxs(bn,{open:_,onOpenChange:Q=>{C(Q),Q||$("")},children:[s.jsx(fn,{asChild:!0,children:s.jsxs("button",{type:"button",className:_n,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[T&&T!==Wn?s.jsx(Qn,{providerId:T,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ye("truncate typography-ui-label font-normal",T?"text-foreground":"text-muted-foreground"),children:T===Wn?t("settings.providers.page.custom.optionLabel"):T?xe.find(Q=>Q.id===T)?.name||T:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(xn,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:Q=>Q.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:Q=>Q.stopPropagation(),children:[s.jsx(z,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:D,onChange:Q=>$(Q.target.value),onKeyDown:Q=>Q.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(ks,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const Q=t("settings.providers.page.custom.optionLabel"),Ne=Sd([Q,"other","custom"],D),Ae=zi(xe,D,We=>[We.name||We.id,We.id]);return Ae.length===0&&!Ne?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):s.jsxs(s.Fragment,{children:[Ae.map(We=>s.jsxs(vn,{onSelect:()=>{P(We.id),C(!1),$("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Qn,{providerId:We.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:We.name||We.id})]}),T===We.id&&s.jsx(z,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},We.id)),Ne?s.jsxs(vn,{onSelect:()=>{P(Wn),C(!1),$("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(z,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Q})]}),T===Wn&&s.jsx(z,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Wn):null]})})()})]})]})]})}),de?s.jsx(hl,{mode:"create",existingProviderIDs:ue,busy:b?.startsWith("custom:")??!1,authFailureHint:le,onCancel:()=>{P(""),oe(null),ee(null)},onDisconnect:le&&he?()=>{je(he)}:void 0,onSubmit:Ve}):T?s.jsx($e,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:p?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const Q=d[T]??[],Ne=yl(ul(Q),ve),Ae=dl(Q);return s.jsxs(s.Fragment,{children:[Ae?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Yt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:h[T]??"",onChange:We=>w(lt=>({...lt,[T]:We.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>_e(T),disabled:b===`api:${T}`,children:b===`api:${T}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Ne.length>0?s.jsx(xl,{providerId:T,methods:Ne,onConnected:()=>se(T),className:ye(Ae&&"border-t border-[var(--surface-subtle)] pt-2")},T):null]})})()})}):null]});if(!we)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const Se=Array.isArray(we.models)?we.models:[],Ke=d[we.id]??[],Ue=yl(ul(Ke),ve),Oe=dl(Ke),Re=!!De,Ce=Re&&ml(we,De),Ze=pl({key:we.key,authSourceExists:De?.auth.exists,optionsApiKey:we.options?.apiKey??null,envDeclared:bl(we)}),be=dh(Re,Ze,Ce),Pe=mh({modelCount:Se.length,sourcesLoaded:Re,hasCredentials:Ze,isEditableCustomProvider:Ce}),Le=!Oe&&Ue.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),Xe=zi(Se,m,Q=>[typeof Q?.name=="string"?Q.name:"",typeof Q?.id=="string"?Q.id:""]);return ke&&Ce&&L?s.jsx(os,{title:we.name||we.id,titleLeading:s.jsx(Qn,{providerId:we.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:we.id}),showSaveStatus:!1,children:s.jsx(hl,{mode:"edit",existingProviderIDs:ue,initialValues:L,allowExistingAuth:Ze||!Re,busy:b?.startsWith("custom:")??!1,authFailureHint:le,onCancel:()=>{B(null),X(null),Z(null),oe(null),ee(null)},onDisconnect:()=>{je(we.id)},onSubmit:Ve})}):s.jsxs(os,{title:we.name||we.id,titleLeading:s.jsx(Qn,{providerId:we.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:we.id}),showSaveStatus:!1,children:[s.jsx($e,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[Ce?s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{oe(null),X(wh(we)),Z(gl(De)),B(we.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const Q=!te;O(Q),K(Q?null:we.id)},children:t(te?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:te?p?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[Oe?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Yt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:h[we.id]??"",onChange:Q=>w(Ne=>({...Ne,[we.id]:Q.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>_e(we.id),disabled:b===`api:${we.id}`,children:b===`api:${we.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Ue.length>0&&s.jsx(xl,{providerId:we.id,methods:Ue,onConnected:()=>se(we.id),className:ye(Oe&&"border-t border-[var(--surface-subtle)] pt-2")},we.id)]}):be?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(z,{name:"alert",className:"w-4 h-4 text-[var(--status-warning)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.incomplete")}),s.jsx(Yt,{children:Le})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(z,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx(Yt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx($e,{title:t("settings.providers.page.connectionDetails.title"),settingsItem:"providers.connection-details",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 @xl:flex-row @xl:items-center @xl:justify-between @xl:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:De&&(De.auth.exists||De.user.exists||De.project.exists||De.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[De.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,De.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,De.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,De.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ae(we.id),disabled:b===`disconnect:${we.id}`,children:b===`disconnect:${we.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Pe?s.jsxs($e,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",Se.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const Q=Se.map(Ne=>typeof Ne?.id=="string"?Ne.id:"").filter(Ne=>Ne.length>0);c(we.id,Q)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>f(we.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(z,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{value:m,onChange:Q=>I(Q.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),Xe.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Xe.map(Q=>{const Ne=typeof Q?.id=="string"?Q.id:"",Ae=typeof Q?.name=="string"?Q.name:Ne,We=Ne?r(we.id,Ne):void 0,lt=l.some(J=>J.providerID===we.id&&J.modelID===Ne),at=vl(We?.limit?.context),pt=vl(We?.limit?.output),bt=[];return We?.tool_call&&bt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),We?.reasoning&&bt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),We?.attachment&&bt.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:ye("flex items-center gap-3",lt&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Ae}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(at||pt)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[at?`${at} ${t("settings.providers.page.models.tokenBadge.context")}`:"",at&&pt?" · ":"",pt?`${pt} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),bt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:bt.map(({key:J,icon:qe,label:it})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:it,"aria-label":it,children:s.jsx(z,{name:qe,className:"h-3 w-3"})},J))}),s.jsx("button",{type:"button",onClick:()=>u(we.id,Ne),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(lt?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(lt?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:lt?s.jsx(z,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},Ne)})})]}):null]})},Vh=t=>{const e=t?.windows??{},a=Object.values(e).map(n=>n.usedPercent).filter(n=>typeof n=="number");return a.length===0?null:Math.max(...a)},Hh=t=>{const e=dt.c(75),{onItemSelect:a}=t,{t:n}=et(),i=ls(qh),r=ls(Gh),l=ls(Wh),u=ls(Jh),c=ls(Qh),f=ls(Yh),d=ls(Zh),v=ls(Xh);let p,j;e[0]!==v?(p=()=>{v()},j=[v],e[0]=v,e[1]=p,e[2]=j):(p=e[1],j=e[2]),o.useEffect(p,j);const h=ef;let w;e[3]!==d?(w=Z=>{Z!=="usage"&&Z!=="remaining"||(d(Z),h({usageDisplayMode:Z}))},e[3]=d,e[4]=w):w=e[4];const b=w;let k;e[5]===Symbol.for("react.memo_cache_sentinel")?(k=ye("flex h-full flex-col","bg-background"),e[5]=k):k=e[5];let m;e[6]!==n?(m=n("settings.usage.sidebar.title"),e[6]=n,e[7]=m):m=e[7];let I;e[8]!==m?(I=s.jsx("h2",{className:`${kn} mb-3`,children:m}),e[8]=m,e[9]=I):I=e[9];let E;e[10]!==n?(E=n("settings.usage.sidebar.total",{count:Ui.length}),e[10]=n,e[11]=E):E=e[11];let A;e[12]!==E?(A=s.jsx("span",{className:"typography-meta text-muted-foreground",children:E}),e[12]=E,e[13]=A):A=e[13];let N;e[14]!==u?(N=()=>u(),e[14]=u,e[15]=N):N=e[15];let x;e[16]!==n?(x=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=x):x=e[17];let y;e[18]!==n?(y=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=y):y=e[19];const F=c&&"animate-spin";let T;e[20]!==F?(T=ye("h-3.5 w-3.5",F),e[20]=F,e[21]=T):T=e[21];let P;e[22]!==T?(P=s.jsx(z,{name:"refresh",className:T}),e[22]=T,e[23]=P):P=e[23];let D;e[24]!==c||e[25]!==x||e[26]!==y||e[27]!==P||e[28]!==N?(D=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:N,"aria-label":x,title:y,disabled:c,children:P})}),e[24]=c,e[25]=x,e[26]=y,e[27]=P,e[28]=N,e[29]=D):D=e[29];let $;e[30]!==D||e[31]!==A?($=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[A,D]}),e[30]=D,e[31]=A,e[32]=$):$=e[32];let _;e[33]!==n?(_=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=_):_=e[34];let C;e[35]!==_?(C=s.jsx("span",{className:"typography-micro text-muted-foreground",children:_}),e[35]=_,e[36]=C):C=e[36];let R;e[37]!==n?(R=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=R):R=e[38];let V;e[39]!==R?(V=s.jsx(Dt,{className:"w-fit",children:s.jsx(_t,{placeholder:R})}),e[39]=R,e[40]=V):V=e[40];let U;e[41]!==n?(U=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=U):U=e[42];let W;e[43]!==U?(W=s.jsx(ut,{value:"usage",children:U}),e[43]=U,e[44]=W):W=e[44];let te;e[45]!==n?(te=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=te):te=e[46];let O;e[47]!==te?(O=s.jsx(ut,{value:"remaining",children:te}),e[47]=te,e[48]=O):O=e[48];let ie;e[49]!==W||e[50]!==O?(ie=s.jsxs(Mt,{children:[W,O]}),e[49]=W,e[50]=O,e[51]=ie):ie=e[51];let K;e[52]!==b||e[53]!==V||e[54]!==ie||e[55]!==f?(K=s.jsxs(Et,{value:f,onValueChange:b,children:[V,ie]}),e[52]=b,e[53]=V,e[54]=ie,e[55]=f,e[56]=K):K=e[56];let q;e[57]!==C||e[58]!==K?(q=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[C,K]}),e[57]=C,e[58]=K,e[59]=q):q=e[59];let B;e[60]!==$||e[61]!==q||e[62]!==I?(B=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[I,$,q]}),e[60]=$,e[61]=q,e[62]=I,e[63]=B):B=e[63];let L;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(L=Ui.map(Z=>{const le=i.find(ke=>ke.providerId===Z.id),oe=Vh(le?.usage),he=ic(oe),ee=Z.id===r,re=le?.configured,de=re?he==="critical"?{backgroundColor:"var(--status-error)"}:he==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ee?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(Z.id),a?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:de}),s.jsx(Qn,{providerId:Z.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:Z.name}),re===!1&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},Z.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=L):L=e[69];let X;e[70]!==L?(X=s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:L}),e[70]=L,e[71]=X):X=e[71];let G;return e[72]!==B||e[73]!==X?(G=s.jsxs("div",{className:k,children:[B,X]}),e[72]=B,e[73]=X,e[74]=G):G=e[74],G};function qh(t){return t.results}function Gh(t){return t.selectedProviderId}function Wh(t){return t.setSelectedProvider}function Jh(t){return t.fetchAllQuotas}function Qh(t){return t.isLoading}function Yh(t){return t.displayMode}function Zh(t){return t.setDisplayMode}function Xh(t){return t.loadSettings}async function ef(t){try{await yt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const tf=t=>{const e=dt.c(17),{percent:a,tonePercent:n,className:i}=t;let r;e[0]!==a?(r=Cd(a)??0,e[0]=a,e[1]=r):r=e[1];const l=r,u=n??a;let c;e[2]!==u?(c=ic(u),e[2]=u,e[3]=c):c=e[3];const f=c;let d;e[4]!==f?(d=f==="critical"?{backgroundColor:"var(--status-error)"}:f==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=f,e[5]=d):d=e[5];const v=d;let p;e[6]!==i?(p=ye("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=p):p=e[7];const j=`${l}%`;let h;e[8]!==v||e[9]!==j?(h={...v,width:j},e[8]=v,e[9]=j,e[10]=h):h=e[10];let w;e[11]!==l||e[12]!==h?(w=s.jsx("div",{className:"h-full transition-all duration-300",style:h,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=h,e[13]=w):w=e[13];let b;return e[14]!==p||e[15]!==w?(b=s.jsx("div",{className:p,children:w}),e[14]=p,e[15]=w,e[16]=b):b=e[16],b},jr=t=>{const e=dt.c(37),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:u}=t,c=r===void 0?!1:r,f=l===void 0?!1:l,d=ls(sf),v=ce(nf),p=d==="remaining"?n.remainingPercent:n.usedPercent,j=p!==null,h=d==="remaining"?"remaining":"used";let w;e[0]!==p||e[1]!==n.valueLabel?(w=Id(n.valueLabel,p),e[0]=p,e[1]=n.valueLabel,e[2]=w):w=e[2];const b=w,k=n.resetAfterFormatted??n.resetAtFormatted;let m;e[3]!==k||e[4]!==v||e[5]!==n.resetAt?(m=Pd(n.resetAt,k,v),e[3]=k,e[4]=v,e[5]=n.resetAt,e[6]=m):m=e[6];const I=m,E=I?`Resets ${I}`:"";let A;e[7]!==a?(A=Ad(a),e[7]=a,e[8]=A):A=e[8];const N=A;let x;e[9]!==u||e[10]!==c||e[11]!==f?(x=c&&s.jsx(Er,{checked:f,onChange:V=>u?.(V),ariaLabel:"Show in dropdown"}),e[9]=u,e[10]=c,e[11]=f,e[12]=x):x=e[12];let y;e[13]!==N?(y=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:N}),e[13]=N,e[14]=y):y=e[14];let F;e[15]!==i?(F=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=F):F=e[16];let T;e[17]!==y||e[18]!==F?(T=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[y,F]}),e[17]=y,e[18]=F,e[19]=T):T=e[19];let P;e[20]!==T||e[21]!==x?(P=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[x,T]}),e[20]=T,e[21]=x,e[22]=P):P=e[22];const D=b==="-"?"":b;let $;e[23]!==D?($=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:D}),e[23]=D,e[24]=$):$=e[24];let _;e[25]!==P||e[26]!==$?(_=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[P,$]}),e[25]=P,e[26]=$,e[27]=_):_=e[27];let C;e[28]!==h||e[29]!==p||e[30]!==j||e[31]!==E||e[32]!==n.usedPercent?(C=j?s.jsxs("div",{className:"mt-2.5",children:[s.jsx(tf,{percent:p,tonePercent:n.usedPercent,className:"h-1.5"}),s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:E}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:h})]})]}):E?s.jsx("div",{className:"mt-1 typography-micro text-muted-foreground",children:E}):null,e[28]=h,e[29]=p,e[30]=j,e[31]=E,e[32]=n.usedPercent,e[33]=C):C=e[33];let R;return e[34]!==_||e[35]!==C?(R=s.jsxs("div",{className:"py-3",children:[_,C]}),e[34]=_,e[35]=C,e[36]=R):R=e[36],R};function sf(t){return t.displayMode}function nf(t){return t.timeFormatPreference}const af=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,rf=({providerId:t,providerName:e})=>{const{t:a}=et(),[n,i]=o.useState(null),[r,l]=o.useState({}),[u,c]=o.useState(!1),f=`/api/quota/credentials/${t}`;o.useEffect(()=>{xt(f).then(async p=>{if(!p.ok)throw new Error;const j=await p.json();i(j),l({})}).catch(()=>i({configured:!1}))},[f]);const d=async(p,j,h)=>{c(!0);try{const w=await xt(p,{method:j,headers:h?{"Content-Type":"application/json"}:void 0,body:h?JSON.stringify(h):void 0}),b=await w.json().catch(()=>null);if(!w.ok)throw new Error(b?.error);b?.configured!==void 0&&i(b),l({}),M.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(w){M.error(w instanceof Error&&w.message?w.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},v=(p,j,h)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[j,s.jsx(He,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[p]??"",onChange:w=>l(b=>({...b,[p]:w.target.value})),placeholder:n?.secretMasked??h})]});return s.jsxs("div",{"data-settings-item":`usage.${t}-credentials`,className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t==="exe-dev"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.providers.page.quotaCredentials.exeDevTokenInstructions")}),s.jsx("code",{className:"typography-code block whitespace-pre-wrap break-all rounded bg-muted/50 px-2 py-1.5 text-xs text-foreground",children:af})]}),t==="ollama-cloud"&&v("cookie",a("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&v("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&v("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&v("refreshToken",a("settings.providers.page.quotaCredentials.refreshToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(H,{size:"xs",disabled:u,onClick:()=>d(f,"PUT",r),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(H,{variant:"outline",size:"xs",disabled:u,onClick:()=>d(`${f}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(H,{variant:"outline",size:"xs",disabled:u,onClick:()=>d(`${f}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(H,{variant:"destructive",size:"xs",disabled:u,onClick:()=>d(f,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},jl=(t,e)=>{if(!t)return"-";try{return rc(t,e,{fallback:"-"})}catch{return"-"}},of=()=>{const{t}=et(),e=ce(R=>R.timeFormatPreference),a=ls(R=>R.results),n=ls(R=>R.selectedProviderId),i=ls(R=>R.setSelectedProvider),r=ls(R=>R.loadSettings),l=ls(R=>R.fetchAllQuotas),u=ls(R=>R.isLoading),c=ls(R=>R.lastUpdated),f=ls(R=>R.refreshErrors),d=ls(R=>R.dropdownProviderIds),v=ls(R=>R.setDropdownProviderIds),p=ls(R=>R.selectedModels),j=ls(R=>R.toggleModelSelected),h=ls(R=>R.applyDefaultSelections);Td(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const R=a.find(V=>V.configured)?.providerId;i(R??Ui[0]?.id??null)},[a,n,i]);const w=a.find(R=>R.providerId===n)??null,k=Ui.find(R=>R.id===n)?.name??n??t("settings.usage.sidebar.title"),m=w?.usage,I=n?f[n]:void 0,E=I?m?t("header.services.usageRefreshFailedStale",{error:I}):I:w?.configured&&!w.ok?w.error:null,A=n?d.includes(n):!1,N=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",x=o.useCallback(R=>{if(!n)return;const V=R?Array.from(new Set([...d,n])):d.filter(U=>U!==n);v(V),yt({usageDropdownProviders:V})},[d,n,v]),y=o.useMemo(()=>m?.models?Object.entries(m.models).map(([R,V])=>({name:R,windows:V})).filter(R=>Object.keys(R.windows.windows).length>0):[],[m?.models]);o.useEffect(()=>{n&&y.length>0&&h(n,y.map(R=>R.name))},[n,y,h]);const F=o.useMemo(()=>!n||y.length===0?new Map:Ed(y,R=>R.name,n),[y,n]),T=o.useMemo(()=>{if(!n)return[];const R=Md(n);return Dd(R)},[n]),[P,D]=o.useState(()=>({})),$=o.useCallback(R=>{D(V=>({...V,[R]:!V[R]}))},[]),_=o.useCallback(R=>{if(!n)return;j(n,R);const V=p[n]??[],W=V.includes(R)?V.filter(O=>O!==R):[...V,R],te={...p,[n]:W};yt({usageSelectedModels:te})},[n,p,j]),C=n?p[n]??[]:[];return n?s.jsxs(os,{title:t("settings.usage.page.header.providerUsage",{provider:k}),titleLeading:s.jsx(Qn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:u?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):w?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:w.planLabel,time:jl(c,e)}):t("settings.usage.page.header.lastUpdated",{time:jl(c,e)}),showSaveStatus:!0,children:[s.jsx($e,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(mt,{checked:A,onChange:x,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!w&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),E&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:E})]}),w&&!w.configured&&!N&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="exe-dev"||n==="ollama-cloud"||n==="cursor")&&s.jsx(rf,{providerId:n,providerName:k}),m?.windows&&Object.keys(m.windows).length>0&&s.jsx($e,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(m.windows).map(([R,V])=>s.jsx(jr,{title:R,window:V},R))})}),y.length>0&&s.jsxs($e,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[T.map(R=>{const V=F.get(R.id)??[];if(V.length===0)return null;const U=P[R.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(yn,{open:!U,onOpenChange:()=>$(R.id),children:[s.jsxs(jn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:R.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",V.length,")"]})]}),U?s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(wn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:V.map(W=>{const te=Object.entries(W.windows.windows);if(te.length===0)return null;const[O,ie]=te[0],K=C.includes(W.name);return s.jsx(jr,{title:O,subtitle:fo(W.name),window:ie,showToggle:!0,toggleEnabled:K,onToggle:()=>_(W.name)},W.name)})})})]})},R.id)}),(()=>{const R=F.get(null)??[];if(R.length===0)return null;const V=P.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(yn,{open:!V,onOpenChange:()=>$("other"),children:[s.jsxs(jn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",R.length,")"]})]}),V?s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(wn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:R.map(U=>{const W=Object.entries(U.windows.windows);if(W.length===0)return null;const[te,O]=W[0],ie=C.includes(U.name);return s.jsx(jr,{title:te,subtitle:fo(U.name),window:O,showToggle:!0,toggleEnabled:ie,onToggle:()=>_(U.name)},U.name)})})})]})})})()]}),w?.configured&&m&&Object.keys(m.windows??{}).length===0&&y.length===0&&s.jsxs("div",{className:"pb-8",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},lf="git.commit.generate",$r=wc(t=>({selectedPromptId:lf,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),cf=t=>{const e=dt.c(24),{onItemSelect:a}=t,{t:n}=et(),i=$r(df),r=$r(uf);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=u):u=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=c):c=e[2];let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f={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[3]=f):f=e[3];let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=[l,u,c,f,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[4]=d):d=e[4];const v=d;let p;e[5]!==n?(p=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=p):p=e[6];let j;e[7]!==p?(j=s.jsx("h2",{className:kn,children:p}),e[7]=p,e[8]=j):j=e[8];let h;e[9]!==n?(h=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=h):h=e[10];let w;e[11]!==h?(w=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:h}),e[11]=h,e[12]=w):w=e[12];let b;e[13]!==j||e[14]!==w?(b=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[j,w]}),e[13]=j,e[14]=w,e[15]=b):b=e[15];let k;e[16]!==a||e[17]!==i||e[18]!==r||e[19]!==n?(k=s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:v.map(I=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(I.groupKey)}),I.items.map(E=>{const A=i===E.id;return s.jsx("button",{type:"button",onClick:()=>{r(E.id),a?.()},className:ye("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",A?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(E.titleKey)})},E.id)})]},I.groupKey))}),e[16]=a,e[17]=i,e[18]=r,e[19]=n,e[20]=k):k=e[20];let m;return e[21]!==b||e[22]!==k?(m=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[b,k]}),e[21]=b,e[22]=k,e[23]=m):m=e[23],m};function df(t){return t.selectedPromptId}function uf(t){return t.setSelectedPromptId}const wl={"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"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},kl=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),wr=t=>t.endsWith(".visible"),pf=()=>{const{t}=et(),e=o.useCallback(N=>t(N),[t]),a=$r(N=>N.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[u,c]=o.useState({}),[f,d]=o.useState({}),[v,p]=o.useState({}),[j,h]=o.useState(!1);o.useEffect(()=>{let N=!0;return(async()=>{i(!0);try{const y=await Ld();if(!N)return;l(y)}catch(y){console.warn("Failed to load magic prompts:",y),M.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{N&&i(!1)}})(),()=>{N=!1}},[t]);const w=wl[a]??wl["git.commit.generate"],b=o.useCallback(N=>kl(r,N)?r[N]:cr(N),[r]),k=o.useCallback(N=>u[N]??b(N),[u,b]),m=o.useCallback((N,x)=>{c(y=>y[N]===x?y:{...y,[N]:x})},[]),I=o.useCallback(async N=>{const x=k(N);if(wr(N)&&x.trim().length===0){M.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}d(y=>({...y,[N]:!0}));try{const y=x===cr(N)?await xo(N):await Rd(N,x);l(y.overrides),M.success(t("settings.magicPrompts.page.toast.saved"))}catch(y){const F=y instanceof Error?y.message:String(y);M.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:F})}finally{d(y=>({...y,[N]:!1}))}},[k,t]),E=o.useCallback(async N=>{p(x=>({...x,[N]:!0}));try{const x=await xo(N);l(x.overrides),c(y=>({...y,[N]:cr(N)})),M.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(x){const y=x instanceof Error?x.message:String(x);M.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:y})}finally{p(x=>({...x,[N]:!1}))}},[t]),A=o.useCallback(async()=>{h(!0);try{const N=await Fd();l(N.overrides),c({}),M.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(N){const x=N instanceof Error?N.message:String(N);M.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:x})}finally{h(!1)}},[t]);return n?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx(os,{title:e(w.titleKey),titleAccessory:s.jsx(Yt,{contentClassName:"max-w-xs",children:e(w.descriptionKey)}),headerEnd:s.jsx(H,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{A()},disabled:j||Object.keys(r).length===0,children:t(j?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:w.blocks.map((N,x)=>{const y=Od(N.id),F=b(N.id),T=k(N.id),P=kl(r,N.id),D=T!==F,$=wr(N.id)&&T.trim().length===0,_=f[N.id]===!0,C=v[N.id]===!0;return s.jsxs($e,{title:e(N.titleKey),info:y.description,description:y.placeholders&&y.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${y.placeholders.map(R=>`{{${R.key}}}`).join(", ")}`:void 0,divider:x>0,settingsItem:wr(N.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Ms,{value:T,onChange:R=>m(N.id,R.target.value),className:"min-h-[220px] font-mono text-sm"}),$&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(D?"settings.magicPrompts.page.status.unsavedChanges":P?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"outline",size:"sm",onClick:()=>{E(N.id)},disabled:!P||_||C,children:t(C?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(H,{size:"sm",onClick:()=>{I(N.id)},disabled:!D||_||C||$,children:t(_?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},N.id)})})},mf=t=>{const e=dt.c(89),{onItemSelect:a}=t,{t:n}=et(),[i,r]=o.useState(null),[l,u]=o.useState(null),[c,f]=o.useState(null),{selectedSnippetName:d,snippets:v,setSelectedSnippet:p,setSnippetDraft:j,deleteSnippet:h,loadSnippets:w}=_i(Hs(gf));let b,k;e[0]!==w?(b=()=>{w()},k=[w],e[0]=w,e[1]=b,e[2]=k):(b=e[1],k=e[2]),o.useEffect(b,k);let m;e[3]!==a||e[4]!==p||e[5]!==j||e[6]!==v?(m=async()=>{const ue=new Set(v.map(hf));let xe="new-snippet",pe=1;for(;ue.has(xe);)xe=`new-snippet-${pe++}`;j({name:xe,scope:"global"}),p(xe),a?.()},e[3]=a,e[4]=p,e[5]=j,e[6]=v,e[7]=m):m=e[7];const I=m;let E;e[8]!==i||e[9]!==h||e[10]!==n?(E=async()=>{if(!i)return;await h(i.name)?(M.success(n("settings.snippets.sidebar.toast.deleted")),r(null)):M.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=h,e[10]=n,e[11]=E):E=e[11];const A=E;let N;e[12]!==v?(N=[...v].sort(ff),e[12]=v,e[13]=N):N=e[13];const x=N;let y;e[14]===Symbol.for("react.memo_cache_sentinel")?(y=ye("flex h-full flex-col","bg-background"),e[14]=y):y=e[14];let F;e[15]!==n?(F=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=F):F=e[16];let T;e[17]!==F?(T=s.jsx("h2",{className:`${kn} mb-3`,children:F}),e[17]=F,e[18]=T):T=e[18];let P;e[19]!==v.length||e[20]!==n?(P=n("settings.snippets.sidebar.total",{count:v.length}),e[19]=v.length,e[20]=n,e[21]=P):P=e[21];let D;e[22]!==P?(D=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[22]=P,e[23]=D):D=e[23];let $;e[24]!==n?($=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=$):$=e[25];let _;e[26]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[26]=_):_=e[26];let C;e[27]!==I||e[28]!==$?(C=s.jsx(H,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:I,"aria-label":$,children:_}),e[27]=I,e[28]=$,e[29]=C):C=e[29];let R;e[30]!==D||e[31]!==C?(R=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[D,C]}),e[30]=D,e[31]=C,e[32]=R):R=e[32];let V;e[33]!==R||e[34]!==T?(V=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,R]}),e[33]=R,e[34]=T,e[35]=V):V=e[35];let U;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==d||e[40]!==p||e[41]!==x||e[42]!==n){let ue;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==d||e[48]!==p||e[49]!==n?(ue=xe=>s.jsxs(ca,{open:c===xe.name,onOpenChange:pe=>f(pe?xe.name:null),children:[s.jsxs(la,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",d===xe.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:pe=>{pe.preventDefault(),f(xe.name)}}),children:[s.jsxs("button",{onClick:()=>{p(xe.name),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",xe.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:n(`snippets.source.${xe.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:xe.description||xe.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(bn,{open:l===xe.name,onOpenChange:pe=>{pe&&f(null),u(pe?xe.name:null)},children:[s.jsx(fn,{asChild:!0,children:s.jsx(H,{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":n("settings.snippets.sidebar.actions.more",{name:xe.name}),children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(xn,{align:"end",className:"w-fit min-w-20",children:s.jsxs(vn,{onClick:pe=>{pe.stopPropagation(),r(xe)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(ra,{className:"w-fit min-w-20",children:s.jsxs(oa,{onClick:pe=>{pe.stopPropagation(),r(xe)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${xe.source}:${xe.filePath}`),e[44]=a,e[45]=l,e[46]=c,e[47]=d,e[48]=p,e[49]=n,e[50]=ue):ue=e[50],U=x.map(ue),e[36]=a,e[37]=l,e[38]=c,e[39]=d,e[40]=p,e[41]=x,e[42]=n,e[43]=U}else U=e[43];let W;e[51]!==U?(W=s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:U}),e[51]=U,e[52]=W):W=e[52];const te=i!==null;let O;e[53]===Symbol.for("react.memo_cache_sentinel")?(O=ue=>{ue||r(null)},e[53]=O):O=e[53];let ie;e[54]!==n?(ie=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=ie):ie=e[55];let K;e[56]!==ie?(K=s.jsx(Bt,{children:ie}),e[56]=ie,e[57]=K):K=e[57];const q=i?.name??"";let B;e[58]!==n||e[59]!==q?(B=n("settings.snippets.sidebar.dialog.deleteDescription",{name:q}),e[58]=n,e[59]=q,e[60]=B):B=e[60];let L;e[61]!==B?(L=s.jsx(Vt,{children:B}),e[61]=B,e[62]=L):L=e[62];let X;e[63]!==K||e[64]!==L?(X=s.jsxs($t,{children:[K,L]}),e[63]=K,e[64]=L,e[65]=X):X=e[65];let G;e[66]===Symbol.for("react.memo_cache_sentinel")?(G=()=>r(null),e[66]=G):G=e[66];let Z;e[67]!==n?(Z=n("settings.common.actions.cancel"),e[67]=n,e[68]=Z):Z=e[68];let le;e[69]!==Z?(le=s.jsx(H,{size:"sm",variant:"ghost",onClick:G,children:Z}),e[69]=Z,e[70]=le):le=e[70];let oe;e[71]!==n?(oe=n("settings.common.actions.delete"),e[71]=n,e[72]=oe):oe=e[72];let he;e[73]!==A||e[74]!==oe?(he=s.jsx(H,{size:"sm",onClick:A,children:oe}),e[73]=A,e[74]=oe,e[75]=he):he=e[75];let ee;e[76]!==le||e[77]!==he?(ee=s.jsxs(is,{children:[le,he]}),e[76]=le,e[77]=he,e[78]=ee):ee=e[78];let re;e[79]!==X||e[80]!==ee?(re=s.jsxs(Ut,{className:"max-w-md",children:[X,ee]}),e[79]=X,e[80]=ee,e[81]=re):re=e[81];let de;e[82]!==te||e[83]!==re?(de=s.jsx(zt,{open:te,onOpenChange:O,children:re}),e[82]=te,e[83]=re,e[84]=de):de=e[84];let ke;return e[85]!==V||e[86]!==W||e[87]!==de?(ke=s.jsxs("div",{className:y,children:[V,W,de]}),e[85]=V,e[86]=W,e[87]=de,e[88]=ke):ke=e[88],ke};function gf(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function hf(t){return t.name}function ff(t,e){return t.name.localeCompare(e.name)}const xf=()=>{const{t}=et(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=_i(Hs(y=>({selectedSnippetName:y.selectedSnippetName,snippets:y.snippets,snippetDraft:y.snippetDraft,setSnippetDraft:y.setSnippetDraft,updateSnippet:y.updateSnippet,createSnippet:y.createSnippet}))),u=o.useMemo(()=>e?a.find(y=>y.name===e||y.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!u),[f,d]=o.useState(""),[v,p]=o.useState("global"),[j,h]=o.useState(""),[w,b]=o.useState(""),[k,m]=o.useState(""),[I,E]=o.useState(!1),A=o.useRef(null);o.useEffect(()=>{if(c&&n){const y={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};d(y.draftName),p(y.draftScope),h(y.description),b(y.aliases),m(y.content),A.current=y}else if(u){const y={draftName:"",draftScope:"global",description:u.description??"",aliases:u.aliases.join(", "),content:u.content};h(y.description),b(y.aliases),m(y.content),A.current=y}},[u,c,e,n]);const N=o.useMemo(()=>{const y=A.current;return y?c&&f!==y.draftName||c&&v!==y.draftScope?!0:j!==y.description||w!==y.aliases||k!==y.content:!1},[w,k,j,f,v,c]),x=async()=>{const y=c?f.trim().replace(/\s+/g,"-"):e?.trim();if(!y){M.error(t("settings.snippets.page.toast.nameRequired"));return}if(!k.trim()){M.error(t("settings.snippets.page.toast.contentRequired"));return}const F=w.split(",").map(T=>T.trim()).filter(Boolean);E(!0);try{if(!(c?await l(y,k,{aliases:F,description:j,scope:v}):await r(y,{content:k,aliases:F,description:j}))){M.error(t("settings.snippets.page.toast.saveFailed"));return}M.success(t("settings.snippets.page.toast.saved")),c&&i(null)}finally{E(!1)}};return e?s.jsxs(os,{title:c?t("settings.snippets.page.title.new"):`#${e}`,description:u?u.filePath:void 0,showSaveStatus:!1,children:[s.jsxs($e,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs(Ht,{label:"#",children:[s.jsx(He,{value:f,onChange:y=>d(y.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Et,{value:v,onValueChange:y=>p(y),children:[s.jsx(Dt,{size:Gt,className:"w-fit min-w-[100px]",children:s.jsx(_t,{})}),s.jsxs(Mt,{align:"end",children:[s.jsx(ut,{value:"global",children:t("settings.common.scope.global")}),s.jsx(ut,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Kt,{label:t("settings.common.field.description"),children:s.jsx(He,{value:j,onChange:y=>h(y.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Kt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(He,{value:w,onChange:y=>b(y.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs($e,{settingsItem:"snippets.content",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(Yt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Ms,{value:k,onChange:y=>m(y.target.value),placeholder:t("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"}),s.jsx("div",{className:"pt-3",children:s.jsx(H,{onClick:x,disabled:I||!N,size:"xs",className:"!font-normal",children:t(I?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},Lc=()=>{const{t}=et(),e=nt(v=>v.settingsGitmojiEnabled),a=nt(v=>v.setSettingsGitmojiEnabled),n=Nu(),i=ce(v=>v.gitChangesViewMode),r=ce(v=>v.setGitChangesViewMode),[l,u]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{const p=await Nn();p&&(p.gitmojiEnabled!==void 0&&a(p.gitmojiEnabled),p.gitChangesViewMode!==void 0&&r(p.gitChangesViewMode))}catch(p){console.warn("Failed to load git settings:",p)}finally{u(!1)}})()},[r,a]);const f=o.useCallback(async v=>{a(v);try{await yt({gitmojiEnabled:v})}catch(p){console.warn("Failed to save gitmoji setting:",p)}},[a]),d=o.useCallback(v=>{v!==i&&(r(v),yt({gitChangesViewMode:v}))},[i,r]);return l?null:s.jsx($e,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:js,children:[s.jsx(Ps,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(sn,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:c.map(v=>s.jsx(Qs,{selected:i===v.id,onSelect:()=>{d(v.id)},label:v.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:v.label})},v.id))})}),s.jsx(mt,{settingsItem:"git.gitmoji",checked:e,onChange:v=>{f(v)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(mt,{settingsItem:"git.gitignored-files",checked:n,onChange:Su,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Nl=[{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)"}],bf=[{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"}],vf=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=et(),r=ea(L=>L.getProfileById),l=ea(L=>L.createProfile),u=ea(L=>L.updateProfile),c=ea(L=>L.deleteProfile),f=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),d=a==="new"||n!=null,v=a==="global",[p,j]=o.useState(""),[h,w]=o.useState(""),[b,k]=o.useState(""),[m,I]=o.useState("ssh"),[E,A]=o.useState(""),[N,x]=o.useState(!1),[y,F]=o.useState(""),[T,P]=o.useState(""),[D,$]=o.useState("keyword"),[_,C]=o.useState("branch"),[R,V]=o.useState(!1),[U,W]=o.useState(!1),[te,O]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const L=n.host.split("/"),X=L.length>=3?L[L.length-1]:n.host;j(X),w(n.username),k(""),I("token"),A(""),x(!1),F(""),P(n.host),$("string"),C("code")}else if(d)j(""),w(""),k(""),I("ssh"),A(""),x(!1),F(""),P(""),$("keyword"),C("branch");else if(f)j(f.name),w(f.userName),k(f.userEmail),I(f.authType||"ssh"),A(f.sshKey||""),x(f.signCommits===!0),F(f.signingKey||""),P(f.host||""),$(f.color||"keyword"),C(f.icon||"branch");else if(v){const L=r("global");L&&(j(L.name),w(L.userName),k(L.userEmail),I(L.authType||"ssh"),A(L.sshKey||""),x(!1),F(""),P(L.host||""),$(L.color||"keyword"),C(L.icon||"branch"))}}},[t,a,f,d,n,v,r]);const ie=async()=>{if(!h.trim()||!b.trim()){M.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(m==="token"&&!T.trim()){M.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(N&&!y.trim()){M.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}V(!0);try{const L={name:p.trim()||h.trim(),userName:h.trim(),userEmail:b.trim(),authType:m,sshKey:m==="ssh"&&E.trim()||null,signCommits:N,signingKey:y.trim()||null,host:m==="token"&&T.trim()||null,color:D,icon:_};let X;if(d)X=await l(L);else if(a)X=await u(a,L);else return;X?(M.success(i(d?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):M.error(i(d?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(L){console.error("Error saving profile:",L),M.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{V(!1)}},K=async()=>{if(!(!a||d)){O(!0);try{await c(a)?(M.success(i("settings.gitIdentities.editor.toast.profileDeleted")),W(!1),e(!1)):M.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(L){console.error("Error deleting profile:",L),M.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{O(!1)}}},q=o.useMemo(()=>Nl.find(X=>X.key===D)?.cssVar||"var(--syntax-keyword)",[D]),B=n?i("settings.gitIdentities.editor.title.importCredential"):d?i("settings.gitIdentities.editor.title.newIdentity"):v?i("settings.gitIdentities.editor.title.globalIdentity"):f?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(zt,{open:t,onOpenChange:e,children:s.jsxs(Ut,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:B}),s.jsx(Vt,{children:i(v?"settings.gitIdentities.editor.description.globalReadOnly":d?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!v&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Ot} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(He,{value:p,onChange:L=>j(L.target.value),placeholder:i("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Nl.map(L=>s.jsx("button",{type:"button",onClick:()=>$(L.key),className:ye("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",D===L.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:L.cssVar},title:L.label},L.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:bf.map(L=>{const X=L.Icon;return s.jsx("button",{type:"button",onClick:()=>C(L.key),className:ye("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",_===L.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:L.label,children:s.jsx(z,{name:X,className:"w-3.5 h-3.5",style:{color:_===L.key?q:"var(--surface-muted-foreground)"}})},L.key)})})]})]}),!v&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Ot,children:i("settings.gitIdentities.editor.field.userName")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(He,{value:h,onChange:L=>w(L.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!v,readOnly:v,disabled:v,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Ot,children:i("settings.gitIdentities.editor.field.emailAddress")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(He,{type:"email",value:b,onChange:L=>k(L.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!v,readOnly:v,disabled:v,className:"h-8"})]})]}),!v&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="ssh",onClick:()=>I("ssh"),children:[s.jsx(z,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":m==="token",onClick:()=>I("token"),children:[s.jsx(z,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),m==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Ot,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(He,{value:E,onChange:L=>A(L.target.value),placeholder:i("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(mt,{checked:N,onChange:x,label:i("settings.gitIdentities.editor.field.signCommits"),info:i("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:i("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Ot,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(He,{value:y,onChange:L=>F(L.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!N,className:"h-8 font-mono text-xs"})]})]}),m==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Ot,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(He,{value:T,onChange:L=>P(L.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(is,{className:"gap-2",children:[!v&&!d&&s.jsxs(H,{variant:"outline",size:"sm",onClick:()=>W(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(z,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.common.actions.delete")]}),s.jsx(H,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:i(v?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!v&&s.jsx(H,{size:"sm",onClick:ie,disabled:R,children:i(R?"settings.common.actions.saving":d?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(zt,{open:U,onOpenChange:L=>{te||W(L)},children:s.jsxs(Ut,{className:"max-w-md",children:[s.jsxs($t,{children:[s.jsx(Bt,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Vt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:f?.name||p})})]}),s.jsxs(is,{children:[s.jsx(H,{variant:"ghost",onClick:()=>W(!1),disabled:te,children:i("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{K()},disabled:te,children:i("settings.common.actions.delete")})]})]})})]})},yf={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},jf={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},wf=()=>{const t=dt.c(112),{t:e}=et(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:u,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:f,setDefaultGitIdentityId:d,getUnimportedCredentials:v}=ea(Hs(Nf)),[p,j]=o.useState(!1),[h,w]=o.useState(null),[b,k]=o.useState(null),[m,I]=o.useState(null),[E,A]=o.useState(!1);let N,x;t[0]!==f||t[1]!==c||t[2]!==u||t[3]!==l?(N=()=>{l(),u(),c(),f()},x=[l,u,c,f],t[0]=f,t[1]=c,t[2]=u,t[3]=l,t[4]=N,t[5]=x):(N=t[4],x=t[5]),o.useEffect(N,x);let y,F,T,P,D,$,_,C,R,V,U,W,te,O;if(t[6]!==i||t[7]!==m||t[8]!==r||t[9]!==v||t[10]!==n||t[11]!==a||t[12]!==d||t[13]!==e){const Ve=v();let ve;t[28]===Symbol.for("react.memo_cache_sentinel")?(ve=(Re,Ce)=>{w(Re),k(Ce??null),j(!0)},t[28]=ve):ve=t[28];const se=ve;let ae;t[29]!==i||t[30]!==d||t[31]!==e?(ae=async Re=>{const Ce=i===Re?null:Re;if(!await d(Ce)){M.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}M.success(e(Ce?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=d,t[31]=e,t[32]=ae):ae=t[32];const je=ae;let Se;t[33]!==m||t[34]!==r||t[35]!==e?(Se=async()=>{if(!m)return;A(!0),await r(m.id)?(M.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:m.name})),I(null)):M.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),A(!1)},t[33]=m,t[34]=r,t[35]=e,t[36]=Se):Se=t[36],T=Se,F=os,t[37]!==e?(D=e("settings.page.git.title"),t[37]=e,t[38]=D):D=t[38],$=!0,y=$e,t[39]!==e?(W=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=W):W=t[40],te=!1;let Ke,Ue;t[41]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>se("new"),Ue=s.jsx(z,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Ke,t[42]=Ue):(Ke=t[41],Ue=t[42]);let Oe;t[43]!==e?(Oe=e("settings.common.badge.new"),t[43]=e,t[44]=Oe):Oe=t[44],t[45]!==Oe?(O=s.jsxs(H,{size:"sm",variant:"outline",onClick:Ke,children:[Ue," ",Oe]}),t[45]=Oe,t[46]=O):O=t[46],P="git.identities",_="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",C=n&&s.jsx(Sl,{profile:n,isDefault:i==="global",onEdit:()=>se("global"),onToggleDefault:()=>je("global"),isReadOnly:!0,hasBorder:a.length>0||Ve.length>0}),R=a.map((Re,Ce)=>s.jsx(Sl,{profile:Re,isDefault:i===Re.id,onEdit:()=>se(Re.id),onToggleDefault:()=>je(Re.id),onDelete:()=>I(Re),hasBorder:Ce<a.length-1||Ve.length>0},Re.id)),V=!n&&a.length===0&&Ve.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),U=Ve.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),Ve.map((Re,Ce)=>s.jsx(kf,{credential:Re,onImport:()=>se("new",{host:Re.host,username:Re.username}),hasBorder:Ce<Ve.length-1},`${Re.host}-${Re.username}`))]}),t[6]=i,t[7]=m,t[8]=r,t[9]=v,t[10]=n,t[11]=a,t[12]=d,t[13]=e,t[14]=y,t[15]=F,t[16]=T,t[17]=P,t[18]=D,t[19]=$,t[20]=_,t[21]=C,t[22]=R,t[23]=V,t[24]=U,t[25]=W,t[26]=te,t[27]=O}else y=t[14],F=t[15],T=t[16],P=t[17],D=t[18],$=t[19],_=t[20],C=t[21],R=t[22],V=t[23],U=t[24],W=t[25],te=t[26],O=t[27];let ie;t[47]!==_||t[48]!==C||t[49]!==R||t[50]!==V||t[51]!==U?(ie=s.jsxs("div",{className:_,children:[C,R,V,U]}),t[47]=_,t[48]=C,t[49]=R,t[50]=V,t[51]=U,t[52]=ie):ie=t[52];let K;t[53]!==y||t[54]!==P||t[55]!==ie||t[56]!==W||t[57]!==te||t[58]!==O?(K=s.jsx(y,{title:W,divider:te,headerAction:O,settingsItem:P,children:ie}),t[53]=y,t[54]=P,t[55]=ie,t[56]=W,t[57]=te,t[58]=O,t[59]=K):K=t[59];let q;t[60]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(Lc,{}),t[60]=q):q=t[60];let B;t[61]!==F||t[62]!==D||t[63]!==$||t[64]!==K?(B=s.jsxs(F,{title:D,showSaveStatus:$,children:[K,q]}),t[61]=F,t[62]=D,t[63]=$,t[64]=K,t[65]=B):B=t[65];let L;t[66]!==b||t[67]!==p||t[68]!==h?(L=s.jsx(vf,{open:p,onOpenChange:j,profileId:h,importData:b}),t[66]=b,t[67]=p,t[68]=h,t[69]=L):L=t[69];const X=m!==null;let G;t[70]!==E?(G=Ve=>{E||Ve||I(null)},t[70]=E,t[71]=G):G=t[71];let Z;t[72]!==e?(Z=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=Z):Z=t[73];let le;t[74]!==Z?(le=s.jsx(Bt,{children:Z}),t[74]=Z,t[75]=le):le=t[75];const oe=m?.name??"";let he;t[76]!==e||t[77]!==oe?(he=e("settings.gitIdentities.page.deleteDialog.description",{name:oe}),t[76]=e,t[77]=oe,t[78]=he):he=t[78];let ee;t[79]!==he?(ee=s.jsx(Vt,{children:he}),t[79]=he,t[80]=ee):ee=t[80];let re;t[81]!==le||t[82]!==ee?(re=s.jsxs($t,{children:[le,ee]}),t[81]=le,t[82]=ee,t[83]=re):re=t[83];let de;t[84]===Symbol.for("react.memo_cache_sentinel")?(de=()=>I(null),t[84]=de):de=t[84];let ke;t[85]!==e?(ke=e("settings.common.actions.cancel"),t[85]=e,t[86]=ke):ke=t[86];let ue;t[87]!==E||t[88]!==ke?(ue=s.jsx(H,{variant:"ghost",onClick:de,disabled:E,children:ke}),t[87]=E,t[88]=ke,t[89]=ue):ue=t[89];let xe;t[90]!==T?(xe=()=>{T()},t[90]=T,t[91]=xe):xe=t[91];let pe;t[92]!==e?(pe=e("settings.common.actions.delete"),t[92]=e,t[93]=pe):pe=t[93];let Ie;t[94]!==E||t[95]!==xe||t[96]!==pe?(Ie=s.jsx(H,{size:"sm",variant:"destructive",onClick:xe,disabled:E,children:pe}),t[94]=E,t[95]=xe,t[96]=pe,t[97]=Ie):Ie=t[97];let Te;t[98]!==ue||t[99]!==Ie?(Te=s.jsxs(is,{children:[ue,Ie]}),t[98]=ue,t[99]=Ie,t[100]=Te):Te=t[100];let we;t[101]!==re||t[102]!==Te?(we=s.jsxs(Ut,{className:"max-w-md",children:[re,Te]}),t[101]=re,t[102]=Te,t[103]=we):we=t[103];let De;t[104]!==X||t[105]!==G||t[106]!==we?(De=s.jsx(zt,{open:X,onOpenChange:G,children:we}),t[104]=X,t[105]=G,t[106]=we,t[107]=De):De=t[107];let _e;return t[108]!==B||t[109]!==L||t[110]!==De?(_e=s.jsxs(s.Fragment,{children:[B,L,De]}),t[108]=B,t[109]=L,t[110]=De,t[111]=_e):_e=t[111],_e},Sl=t=>{const e=dt.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:u,hasBorder:c}=t,{t:f}=et(),[d,v]=o.useState(!1),p=yf[a.icon||"branch"]||"git-branch",j=jf[a.color||""],h=a.authType||"ssh";let w;e[0]!==i?(w=K=>{K.currentTarget===K.target&&(K.key!=="Enter"&&K.key!==" "||(K.preventDefault(),i()))},e[0]=i,e[1]=w):w=e[1];const b=w;let k;e[2]!==n||e[3]!==u||e[4]!==l||e[5]!==r||e[6]!==f?(k=K=>s.jsxs(s.Fragment,{children:[s.jsx(K,{onClick:q=>{q.stopPropagation(),r()},children:f(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!u&&l&&s.jsxs(K,{onClick:q=>{q.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]})]}),e[2]=n,e[3]=u,e[4]=l,e[5]=r,e[6]=f,e[7]=k):k=e[7];const m=k,I=c&&"border-b border-[var(--surface-subtle)]";let E;e[8]!==I?(E=ye("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",I),e[8]=I,e[9]=E):E=e[9];let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=K=>{K.preventDefault(),v(!0)},e[10]=A):A=e[10];let N;e[11]!==b||e[12]!==i||e[13]!==E?(N=s.jsx("div",{className:E,onClick:i,role:"button",tabIndex:0,onKeyDown:b,onContextMenu:A}),e[11]=b,e[12]=i,e[13]=E,e[14]=N):N=e[14];let x;e[15]!==j?(x={color:j},e[15]=j,e[16]=x):x=e[16];let y;e[17]!==p||e[18]!==x?(y=s.jsx(z,{name:p,className:"w-4 h-4 shrink-0",style:x}),e[17]=p,e[18]=x,e[19]=y):y=e[19];let F;e[20]!==a.name?(F=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=F):F=e[21];let T;e[22]!==h?(T=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:h}),e[22]=h,e[23]=T):T=e[23];let P;e[24]!==n||e[25]!==f?(P=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:f("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=f,e[26]=P):P=e[26];let D;e[27]!==u||e[28]!==f?(D=u&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f("settings.agents.sidebar.badge.system")}),e[27]=u,e[28]=f,e[29]=D):D=e[29];let $;e[30]!==T||e[31]!==P||e[32]!==D||e[33]!==F?($=s.jsxs("div",{className:"flex items-center gap-1.5",children:[F,T,P,D]}),e[30]=T,e[31]=P,e[32]=D,e[33]=F,e[34]=$):$=e[34];const _=h==="token"&&a.host?a.host:a.userEmail;let C;e[35]!==_?(C=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:_}),e[35]=_,e[36]=C):C=e[36];let R;e[37]!==$||e[38]!==C?(R=s.jsxs("div",{className:"min-w-0",children:[$,C]}),e[37]=$,e[38]=C,e[39]=R):R=e[39];let V;e[40]!==R||e[41]!==y?(V=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[y,R]}),e[40]=R,e[41]=y,e[42]=V):V=e[42];let U;e[43]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(fn,{asChild:!0,children:s.jsx(H,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:Sf,children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=U):U=e[43];let W;e[44]!==m?(W=s.jsxs(bn,{children:[U,s.jsx(xn,{align:"end",className:"w-fit min-w-28",children:m(vn)})]}),e[44]=m,e[45]=W):W=e[45];let te;e[46]!==V||e[47]!==W||e[48]!==N?(te=s.jsxs(la,{render:N,children:[V,W]}),e[46]=V,e[47]=W,e[48]=N,e[49]=te):te=e[49];let O;e[50]!==m?(O=s.jsx(ra,{className:"w-fit min-w-28",children:m(oa)}),e[50]=m,e[51]=O):O=e[51];let ie;return e[52]!==d||e[53]!==te||e[54]!==O?(ie=s.jsxs(ca,{open:d,onOpenChange:v,children:[te,O]}),e[52]=d,e[53]=te,e[54]=O,e[55]=ie):ie=e[55],ie},kf=t=>{const e=dt.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=et();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const u=l,c=u.length>=3?u[u.length-1]:a.host,f=a.host.includes("/"),d=i&&"border-b border-[var(--surface-subtle)]";let v;e[2]!==d?(v=ye("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",d),e[2]=d,e[3]=v):v=e[3];let p;e[4]!==c?(p=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=p):p=e[5];const j=f?a.host:a.username;let h;e[6]!==j?(h=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:j}),e[6]=j,e[7]=h):h=e[7];let w;e[8]!==p||e[9]!==h?(w=s.jsxs("div",{className:"min-w-0",children:[p,h]}),e[8]=p,e[9]=h,e[10]=w):w=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(z,{name:"download",className:"h-3 w-3"}),e[11]=b):b=e[11];let k;e[12]!==r?(k=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=k):k=e[13];let m;e[14]!==n||e[15]!==k?(m=s.jsxs(H,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[b,k]}),e[14]=n,e[15]=k,e[16]=m):m=e[16];let I;return e[17]!==m||e[18]!==v||e[19]!==w?(I=s.jsxs("div",{className:v,children:[w,m]}),e[17]=m,e[18]=v,e[19]=w,e[20]=I):I=e[20],I};function Nf(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function Sf(t){return t.stopPropagation()}const Kc=({guest:t})=>{const{t:e}=et(),a=t.integration,n=mr(G=>G.byId[t.id]),i=mr(G=>G.setStatus),r=o.useMemo(()=>oc(t.id,t.icon,fc().authenticatedAsset),[t.id,t.icon]),l=mr(G=>G.refresh),[u,c]=o.useState(!1),[f,d]=o.useState(!1),[v,p]=o.useState(!1),[j,h]=o.useState(""),[w,b]=o.useState(""),[k,m]=o.useState(""),[I,E]=o.useState(""),[A,N]=o.useState({}),[x,y]=o.useState(!1),F=o.useRef(null),[T]=o.useState(Oa),P=o.useRef(!0),D=()=>P.current&&Oa()===T,$=o.useCallback(()=>{F.current!=null&&(window.clearInterval(F.current),F.current=null),p(!1)},[]);if(o.useEffect(()=>(P.current=!0,l(t.id),()=>{P.current=!1,$()}),[t.id,l,$]),o.useEffect(()=>{n&&N(n.settings)},[n]),!a)return null;const _=a.auth,C=_==="token"&&a.token?.scheme==="basic",R=!!n?.connection.connected,V=n?.connection.account.trim()||"",U=v?e("settings.integrations.guests.status.waiting"):R?V||e("settings.integrations.guests.status.connected"):e("settings.integrations.guests.status.notConnected"),W=v?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":R?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",te=v||u,O=a.name,ie=async()=>{if(!D())return!1;const G=j.trim();if(!G)return n?.hasClient?!0:(M.error(e("settings.integrations.guests.toast.clientRequired")),!1);zs("saving");const Z=await up(t.id,G,w.trim()||void 0);return D()?Z?(i(t.id,Z),b(""),zs("saved"),!0):(zs("error"),M.error(e("settings.integrations.guests.toast.saveFailed",{name:O})),!1):!1},K=async(G=A)=>{if(!D())return!1;const Z=n?.settings??{};if((a.settings??[]).every(ee=>(G[ee.id]??"").trim()===(Z[ee.id]??"")))return!0;zs("saving");const he=await ap(t.id,G);return D()?he?(i(t.id,he),zs("saved"),!0):(zs("error"),M.error(e("settings.integrations.guests.toast.saveFailed",{name:O})),!1):!1},q=async()=>{if(!D())return!1;const G=k.trim();if(!G)return R?!0:(M.error(e("settings.integrations.guests.toast.tokenRequired")),!1);const Z=I.trim();if(C&&!Z)return M.error(e("settings.integrations.guests.toast.usernameRequired")),!1;zs("saving");const le=await dp(t.id,G,C?Z:void 0);return D()?le?(i(t.id,le),m(""),E(""),zs("saved"),!0):(zs("error"),M.error(e("settings.integrations.guests.toast.tokenInvalid")),!1):!1},B=async()=>{if(!D())return;$(),d(!0);const G=n?.connection??{connected:!1,account:""};try{if(_==="token"){if(await q()){if((a.settings??[]).length>0&&!await K()||!D())return;M.success(e("settings.integrations.guests.toast.connected",{name:O}))}return}if(_==="oauth"&&!n?.hasClient&&!await ie())return;const Z=await rp(t.id);if(!D())return;if(!Z){M.error(e("settings.integrations.guests.toast.startFailed",{name:O}));return}p(!0),c(!0),hn(Z);const le=Date.now()+op;F.current=window.setInterval(()=>{(async()=>{if(!D()){$();return}if(Date.now()>le){$(),M.error(e("settings.integrations.guests.toast.authorizationFailed",{name:O}));return}const oe=await l(t.id);D()&&oe&&lp(G,oe.connection)&&($(),M.success(e("settings.integrations.guests.toast.connected",{name:O})),cs()&&xc())})()},cp)}catch(Z){if(!D())return;console.error("Failed to start guest connect:",Z),M.error(e("settings.integrations.guests.toast.startFailed",{name:O})),$()}finally{D()&&d(!1)}},L=async()=>{if(D()){d(!0);try{$();const G=await ip(t.id);if(!D())return;if(!G){M.error(e("settings.integrations.guests.toast.disconnectFailed",{name:O}));return}i(t.id,G),M.success(e("settings.integrations.guests.toast.disconnected",{name:O}))}catch(G){if(!D())return;console.error("Failed to disconnect guest:",G),M.error(e("settings.integrations.guests.toast.disconnectFailed",{name:O}))}finally{D()&&d(!1)}}},X=async()=>{const G=n?.redirectUri??"";!G||!(await Aa(G)).ok||(y(!0),window.setTimeout(()=>y(!1),1500))};return s.jsx(yn,{open:te,onOpenChange:G=>{if(v){c(!0);return}c(G)},children:s.jsxs("div",{className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(jn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(lc,{icon:cc(t.icon),iconSrc:r,className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:O}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:a.description})]}),s.jsx("span",{"aria-live":"polite",className:ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",W),children:U}),s.jsx(z,{name:"arrow-down-s",className:ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",te&&"rotate-180")})]}),s.jsx(wn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[_==="oauth"?s.jsxs(s.Fragment,{children:[s.jsx(Kt,{label:e("settings.integrations.guests.field.clientId"),controlClassName:"w-full max-w-none",children:s.jsx(He,{value:j,onChange:G=>h(G.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:f})}),s.jsx(Kt,{label:e("settings.integrations.guests.field.clientSecret"),controlClassName:"w-full max-w-none",children:s.jsx(He,{type:"password",value:w,onChange:G=>b(G.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:f})})]}):null,C?s.jsx(Kt,{label:a.token?.usernameLabel??e("settings.integrations.guests.field.username"),controlClassName:"w-full max-w-none",children:s.jsx(He,{value:I,onChange:G=>E(G.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:f})}):null,_==="token"?s.jsx(Kt,{label:e("settings.integrations.guests.field.token"),info:e("settings.integrations.guests.field.token.info"),controlClassName:"w-full max-w-none",children:s.jsx(He,{type:"password",value:k,onChange:G=>m(G.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:f})}):null,(a.settings??[]).map(G=>s.jsx(Kt,{label:G.label,controlClassName:"w-full max-w-none",children:s.jsx(He,{value:A[G.id]??"",onChange:Z=>{N(le=>({...le,[G.id]:Z.target.value}))},onBlur:()=>{K()},autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:f})},G.id)),_==="oauth"?s.jsxs(Kt,{label:e("settings.integrations.guests.field.redirectUri"),info:e("settings.integrations.guests.field.redirectUri.info"),controlClassName:"w-full max-w-none",children:[s.jsx(He,{value:n?.redirectUri??"",readOnly:!0,className:"h-8 min-w-0 flex-1 rounded-md px-3"}),s.jsx(H,{type:"button",size:"sm",variant:"outline",disabled:!n?.redirectUri,onClick:()=>{X()},children:e(x?"settings.integrations.guests.actions.copied":"settings.integrations.guests.actions.copyRedirect")})]}):null,s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:R?s.jsx(H,{type:"button",size:"sm",variant:"destructive",disabled:f,onClick:()=>{L()},children:e("settings.integrations.guests.actions.disconnect")}):s.jsxs(H,{type:"button",size:"sm",disabled:f||v,onClick:()=>{B()},children:[f?s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}):null,e("settings.integrations.guests.actions.connect")]})})]})})]})})},Cf=t=>{const e=dt.c(27),{divider:a}=t,n=a===void 0?!0:a,{t:i}=et(),r=Ys(If),l=Ys(Pf);let u;if(e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0],o.useEffect(Af,u),ds()||bc())return null;let c,f,d,v,p,j,h,w;if(e[1]!==n||e[2]!==r||e[3]!==l||e[4]!==i){w=Symbol.for("react.early_return_sentinel");e:{const k=r.filter(Tf);if(k.length===0){w=null;break e}c=$e,e[13]!==i?(f=i("settings.integrations.guests.title"),e[13]=i,e[14]=f):f=e[14],e[15]!==i?(d=i("settings.integrations.guests.info"),e[15]=i,e[16]=d):d=e[16],v=n,p="integrations.guests",j="space-y-3";let m;e[17]!==l?(m=I=>s.jsx(Kc,{guest:I},`${l}:${I.id}`),e[17]=l,e[18]=m):m=e[18],h=k.map(m)}e[1]=n,e[2]=r,e[3]=l,e[4]=i,e[5]=c,e[6]=f,e[7]=d,e[8]=v,e[9]=p,e[10]=j,e[11]=h,e[12]=w}else c=e[5],f=e[6],d=e[7],v=e[8],p=e[9],j=e[10],h=e[11],w=e[12];if(w!==Symbol.for("react.early_return_sentinel"))return w;let b;return e[19]!==c||e[20]!==f||e[21]!==d||e[22]!==v||e[23]!==p||e[24]!==j||e[25]!==h?(b=s.jsx(c,{title:f,info:d,divider:v,settingsItem:p,contentClassName:j,children:h}),e[19]=c,e[20]=f,e[21]=d,e[22]=v,e[23]=p,e[24]=j,e[25]=h,e[26]=b):b=e[26],b};function If(t){return t.guests}function Pf(t){return t.runtimeKey}function Af(){zn()}function Tf(t){return t.source!=="bundled"&&t.integration&&dc(t)}const Ef=({embedded:t=!1})=>{const{t:e}=et(),{isMobile:a}=ua(),n=Ta()?.github,i=Un(C=>C.status),r=Un(C=>C.isLoading),l=Un(C=>C.hasChecked),u=Un(C=>C.refreshStatus),c=Un(C=>C.setStatus),f=o.useCallback(async C=>{await hn(C)},[]),[d,v]=o.useState(!1),[p,j]=o.useState(null),[h,w]=o.useState(null),b=o.useRef(null),k=o.useCallback(()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null),w(null)},[]);o.useEffect(()=>((async()=>{try{l||await u(n)}catch(C){console.warn("Failed to load GitHub auth status:",C)}})(),()=>{k()}),[l,u,n,k]);const m=o.useCallback(async()=>{v(!0);try{const C=n?await n.authStart():await(async()=>{const V=await xt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),U=await V.json().catch(()=>null);if(!V.ok||!U||!("deviceCode"in U))throw new Error(U?.error||V.statusText);return U})();j(C),w(Math.max(1,C.interval)*1e3);const R=C.verificationUriComplete||C.verificationUri;f(R)}catch(C){console.error("Failed to start GitHub connect:",C),M.error(e("settings.github.page.toast.startConnectFailed"))}finally{v(!1)}},[f,n,e]),I=o.useCallback(async C=>{if(n)return n.authComplete(C);const R=await xt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:C})}),V=await R.json().catch(()=>null);if(!R.ok||!V)throw new Error(V?.error||R.statusText);return V},[n]);o.useEffect(()=>{if(!(!p?.deviceCode||!h)&&b.current==null)return b.current=window.setInterval(()=>{(async()=>{try{const C=await I(p.deviceCode);if(C.connected){M.success(e("settings.github.page.toast.connected")),j(null),k(),await u(n,{force:!0});return}C.status==="slow_down"&&w(R=>R?R+5e3:5e3),(C.status==="expired_token"||C.status==="access_denied")&&(M.error(C.error||e("settings.github.page.toast.authorizationFailed")),j(null),k())}catch(C){console.warn("GitHub polling failed:",C)}})()},h),()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null)}},[p,h,I,u,n,k,e]);const E=o.useCallback(async C=>{v(!0);try{if(n)await n.authSetGhCliDisabled(C);else{const R=await xt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:C})}),V=await R.json().catch(()=>null);if(!R.ok)throw new Error(V?.error||R.statusText)}M.success(e(C?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await u(n,{force:!0})}catch(R){console.error("Failed to update gh CLI setting:",R),M.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{v(!1)}},[u,n,e]),A=o.useCallback(async()=>{v(!0);try{if(k(),j(null),n)await n.authDisconnect();else{const C=await xt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!C.ok)throw new Error(C.statusText)}M.success(e("settings.github.page.toast.disconnected")),await u(n,{force:!0})}catch(C){console.error("Failed to disconnect GitHub:",C),M.error(e("settings.github.page.toast.disconnectFailed"))}finally{v(!1)}},[u,n,k,e]),N=o.useCallback(async C=>{if(C){v(!0);try{const R=n?await n.authActivate(C):await(async()=>{const V=await xt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:C})}),U=await V.json().catch(()=>null);if(!V.ok||!U)throw new Error(U?.error||V.statusText);return U})();c(R),M.success(e("settings.github.page.toast.accountSwitched"))}catch(R){console.error("Failed to switch GitHub account:",R),M.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{v(!1)}}},[n,c,e]);if(r&&!l)return null;const x=!!i?.connected,y=i?.user,T=(i?.accounts??[]).filter(C=>!C.current),P=i?.ghCli??null,D=P?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),$=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[x?s.jsxs("div",{className:ye("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[y?.avatarUrl?s.jsx("img",{src:y.avatarUrl,alt:y.login?e("settings.github.page.avatarAlt.withLogin",{login:y.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:y?.name?.trim()||y?.login||"GitHub"}),s.jsxs("div",{className:ye("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(z,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:y?.login||e("settings.github.page.label.unknownUser")}),y?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),y?.email&&s.jsx("span",{children:y.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:D})]}),i?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:i.scope})}),P?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),P?.active?s.jsx(H,{size:"sm",variant:"outline",onClick:()=>E(!0),disabled:d,className:ye(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(H,{size:"sm",variant:"outline",onClick:A,disabled:d,className:ye("text-[var(--status-error)] hover:text-[var(--status-error)]",a?"w-full":void 0),children:e("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.github.page.status.notConnected")})}),s.jsx(H,{size:"sm",variant:"default",onClick:m,disabled:d,children:e("settings.github.page.actions.connect")})]}),T.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:e("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:T.map(C=>{const R=C.user,V=C.source==="gh-cli"?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[R?.avatarUrl?s.jsx("img",{src:R.avatarUrl,alt:R.login?e("settings.github.page.avatarAlt.withLogin",{login:R.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:R?.name?.trim()||R?.login||"GitHub"}),R?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:R.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:V})]})]})]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>N(C.id),disabled:d,children:e("settings.github.page.actions.switchTo")})]},C.id)})})]})]}),x&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(H,{size:"sm",variant:"outline",onClick:m,disabled:d,className:ye(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),p&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(rn,{children:e("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:p.userCode}),s.jsx(H,{size:"sm",asChild:!0,children:s.jsx("a",{href:p.verificationUriComplete||p.verificationUri,target:"_blank",rel:"noopener noreferrer",children:e("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:e("settings.github.page.flow.waiting")}),s.jsx(H,{size:"sm",variant:"ghost",disabled:d,onClick:()=>{k(),j(null)},children:e("settings.common.actions.cancel")})]})]})]}),_=P?.available&&!P?.active&&(!P.user||P.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:ye("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[P.user?.avatarUrl?s.jsx("img",{src:P.user.avatarUrl,alt:P.user.login?e("settings.github.page.avatarAlt.withLogin",{login:P.user.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!P.disabled&&P.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:P.user.name?.trim()||P.user.login||"GitHub"}),!P.disabled&&P.user?.login&&s.jsxs("div",{className:ye("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(z,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:P.user.login}),P.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),P.user.email&&s.jsx("span",{children:P.user.email})]}),s.jsx("div",{className:ye("typography-meta text-muted-foreground",P.disabled?"opacity-60":void 0),children:P.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>E(!P.disabled),disabled:d,className:ye(a?"w-full":void 0),children:P.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[$,_?s.jsxs("div",{className:"space-y-2",children:[s.jsx(rn,{children:e("settings.github.page.ghCli.title")}),_]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx($e,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:$}),_?s.jsx($e,{title:e("settings.github.page.ghCli.title"),children:_}):null]})},Df=()=>{const t=dt.c(37),{t:e}=et(),a=Un(Mf),n=Un(Rf),i=Un(Ff),[r,l]=o.useState(!1),u=a?.connected===!0;let c;t[0]!==u||t[1]!==i||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(c=n&&!i?e("common.loading"):u?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=u,t[1]=i,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=c):c=t[5];const f=c,d=u?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let v;t[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=v):v=t[6];let p;t[7]!==e?(p=e("settings.integrations.github.title"),t[7]=e,t[8]=p):p=t[8];let j;t[9]!==p?(j=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:p}),t[9]=p,t[10]=j):j=t[10];let h;t[11]!==e?(h=e("settings.integrations.github.description"),t[11]=e,t[12]=h):h=t[12];let w;t[13]!==h?(w=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:h}),t[13]=h,t[14]=w):w=t[14];let b;t[15]!==j||t[16]!==w?(b=s.jsxs("div",{className:"min-w-0 flex-1",children:[j,w]}),t[15]=j,t[16]=w,t[17]=b):b=t[17];let k;t[18]!==d?(k=ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",d),t[18]=d,t[19]=k):k=t[19];let m;t[20]!==f||t[21]!==k?(m=s.jsx("span",{"aria-live":"polite",className:k,children:f}),t[20]=f,t[21]=k,t[22]=m):m=t[22];const I=r&&"rotate-180";let E;t[23]!==I?(E=ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",I),t[23]=I,t[24]=E):E=t[24];let A;t[25]!==E?(A=s.jsx(z,{name:"arrow-down-s",className:E}),t[25]=E,t[26]=A):A=t[26];let N;t[27]!==A||t[28]!==b||t[29]!==m?(N=s.jsxs(jn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[v,b,m,A]}),t[27]=A,t[28]=b,t[29]=m,t[30]=N):N=t[30];let x;t[31]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(wn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(Ef,{embedded:!0})}),t[31]=x):x=t[31];let y;t[32]!==N?(y=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[N,x]}),t[32]=N,t[33]=y):y=t[33];let F;return t[34]!==r||t[35]!==y?(F=s.jsx(yn,{open:r,onOpenChange:l,children:y}),t[34]=r,t[35]=y,t[36]=F):F=t[36],F};function Mf(t){return t.status}function Rf(t){return t.isLoading}function Ff(t){return t.hasChecked}const Ai="__none__",Ti="__inherit__";function Of({linear:t,connected:e,organizationId:a}){const{t:n}=et(),i=Xs(b=>b.projects),[r,l]=o.useState(null),[u,c]=o.useState(!1),[f,d]=o.useState(!1),v=o.useCallback(async()=>{if(!e){l(null),c(!1);return}try{const b=await t.mappingGet();if(b.connected===!1){l(null),c(!1);return}l(b),c(!1)}catch(b){console.error("Failed to load Linear mapping:",b),c(!0)}},[e,t]);o.useEffect(()=>{v()},[v,a]);const p=o.useCallback(async b=>{const k={};for(const m of b.teams??[])m.projectPath&&(k[m.id]=m.projectPath);d(!0),zs("saving");try{const m=await t.mappingSet({defaultProjectPath:b.defaultProjectPath??null,teamProjectPaths:k});if(m.connected===!1){l(null),zs("error");return}l(m),c(!1),zs("saved")}catch(m){console.error("Failed to save Linear mapping:",m),zs("error")}finally{d(!1)}},[t]);if(!e)return null;if(u&&!r)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!r)return null;const j=b=>i.find(m=>m.path===b)?.label?.trim()||b,h=b=>!b||b===Ai?n("settings.integrations.linear.mapping.defaultProject.placeholder"):j(b),w=b=>!b||b===Ti?n("settings.integrations.linear.mapping.teams.useDefault"):j(b);return s.jsxs("div",{className:nn,children:[i.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Ht,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Et,{value:r.defaultProjectPath||Ai,disabled:f||i.length===0,onValueChange:b=>{p({...r,defaultProjectPath:b===Ai?null:b})},children:[s.jsx(Dt,{size:Gt,className:gn,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(_t,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:h})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:Ai,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),r.defaultProjectPath&&!i.some(b=>b.path===r.defaultProjectPath)?s.jsx(ut,{value:r.defaultProjectPath,children:r.defaultProjectPath}):null,i.map(b=>s.jsx(ut,{value:b.path,children:j(b.path)},b.id))]})]})}),s.jsx(Ps,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(r.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:nn,children:(r.teams??[]).map(b=>s.jsx(Ht,{label:`${b.key} · ${b.name}`,children:s.jsxs(Et,{value:b.projectPath||Ti,disabled:f||i.length===0,onValueChange:k=>{p({...r,teams:(r.teams??[]).map(m=>m.id===b.id?{...m,projectPath:k===Ti?null:k}:m)})},children:[s.jsx(Dt,{size:Gt,className:gn,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:b.key}),children:s.jsx(_t,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:w})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:Ti,children:n("settings.integrations.linear.mapping.teams.useDefault")}),b.projectPath&&!i.some(k=>k.path===b.projectPath)?s.jsx(ut,{value:b.projectPath,children:b.projectPath}):null,i.map(k=>s.jsx(ut,{value:k.path,children:j(k.path)},k.id))]})]})},b.id))})})]})}function Lf({linear:t,connected:e}){const{t:a}=et(),[n,i]=o.useState(null),[r,l]=o.useState(!1),[u,c]=o.useState(!1);o.useEffect(()=>{if(!e){i(null),l(!1);return}let d=!1;return t.preferencesGet().then(v=>{d||(i(v.sessionComments),l(!1))}).catch(()=>{d||l(!0)}),()=>{d=!0}},[e,t]);const f=o.useCallback(async d=>{const v=n;i(d),c(!0);try{const p=await t.preferencesSet({sessionComments:d});i(p.sessionComments),zs("saved")}catch{i(v),zs("error")}finally{c(!1)}},[n,t]);return e?r?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:nn,children:s.jsx(Ht,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(Mi,{checked:n===!0,disabled:n===null||u,onCheckedChange:d=>{f(d)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const Kf=3*6e4,zf=1500;function Cl(t){const e=t?.workspaces??[],a=e.find(n=>n.current);return{connected:!!t?.connected,ids:e.map(n=>n.id).slice().sort().join(","),currentId:a?.id||t?.organization?.id||"",currentAuthorizedAt:a?.authorizedAt??0}}function Uf(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const _f=()=>{const{t}=et(),e=Ta()?.linear,a=ja(P=>P.status),n=ja(P=>P.isLoading),i=ja(P=>P.hasChecked),r=ja(P=>P.refreshStatus),l=ja(P=>P.setStatus),[u,c]=o.useState(!1),[f,d]=o.useState(!1),[v,p]=o.useState(!1),j=o.useRef(null),h=o.useCallback(()=>{j.current!=null&&(window.clearInterval(j.current),j.current=null),d(!1)},[]);o.useEffect(()=>{if(e)return i||r(e),()=>{h()}},[i,r,e,h]);const w=o.useCallback(async()=>{if(!e)return;h(),c(!0);const P=Cl(ja.getState().status);try{const D=await e.authStart(cs()?"desktop":"web");d(!0),p(!0),hn(D.authorizationUrl);const $=Date.now()+Kf;j.current=window.setInterval(()=>{(async()=>{if(Date.now()>$){h(),M.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const _=await r(e,{force:!0});Uf(P,Cl(_))&&(h(),M.success(t("settings.integrations.linear.toast.connected")),xc())})()},zf)}catch(D){console.error("Failed to start Linear connect:",D),M.error(t("settings.integrations.linear.toast.startConnectFailed")),h()}finally{c(!1)}},[r,e,h,t]),b=o.useCallback(async P=>{if(!(!e||!P)){c(!0);try{const D=await e.authActivate(P);l(D),M.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(D){console.error("Failed to switch Linear workspace:",D),M.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{c(!1)}}},[e,l,t]),k=o.useCallback(async()=>{if(e){c(!0);try{h(),await e.authDisconnect(),M.success(t("settings.integrations.linear.toast.disconnected")),await r(e,{force:!0})}catch(P){console.error("Failed to disconnect Linear:",P),M.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{c(!1)}}},[r,e,h,t]);if(!e)return null;const m=!!a?.connected,I=a?.user,E=a?.organization,N=(a?.workspaces??[]).filter(P=>!P.current),x=I?.displayName?.trim()||I?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),y=f?t("settings.integrations.linear.status.waiting"):n&&!i?t("common.loading"):m?E?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),F=f?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":m?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",T=f||v;return s.jsx(yn,{open:T,onOpenChange:P=>{if(f){p(!0);return}p(P)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(jn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"linear",className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:t("settings.integrations.linear.title")}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:t("settings.integrations.linear.description")})]}),s.jsx("span",{"aria-live":"polite",className:ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",F),children:y}),s.jsx(z,{name:"arrow-down-s",className:ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",T&&"rotate-180")})]}),s.jsx(wn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[m?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[I?.avatarUrl?s.jsx("img",{src:I.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:x}),className:"size-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"linear",className:"size-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:x}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[E?.name,I?.email].filter(Boolean).join(" · ")})]})]}):f?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,m?s.jsxs(s.Fragment,{children:[s.jsx(Of,{linear:e,connected:m,organizationId:E?.id??null}),s.jsx(Lf,{linear:e,connected:m}),N.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.integrations.linear.label.otherWorkspaces")}),s.jsx("div",{className:"space-y-1",children:N.map(P=>{const D=P.user,$=P.name?.trim()||t("settings.integrations.linear.status.connected");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:$}),D?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:D.email}):null]}),s.jsx(H,{type:"button",size:"sm",variant:"ghost",onClick:()=>{b(P.id)},disabled:u,children:t("settings.integrations.linear.actions.switchTo")})]},P.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{type:"button",size:"sm",variant:"outline",onClick:()=>{w()},disabled:u||f,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(H,{type:"button",size:"sm",variant:"destructive",onClick:()=>{k()},disabled:u,children:t("settings.integrations.linear.actions.disconnect")})]})]}):f?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(H,{type:"button",size:"sm",variant:"ghost",disabled:u,onClick:h,children:t("settings.common.actions.cancel")})]}):s.jsxs(H,{type:"button",size:"sm",variant:"default",onClick:()=>{w()},disabled:u||n&&!i,children:[u?s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},$f=()=>{const t=dt.c(23),{t:e}=et();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=ds(),t[0]=a):a=t[0];const n=!a,i=!!Ta()?.linear,r=Ys(Bf),l=Ys(Vf);let u,c,f,d,v,p;if(t[1]!==r||t[2]!==l||t[3]!==e){const w=!ds()&&!bc()?r.filter(Hf):[];c=n||i||w.length>0,u=os,t[10]!==e?(f=e("settings.page.integrations.title"),t[10]=e,t[11]=f):f=t[11],t[12]!==e?(d=e("settings.page.integrations.description"),t[12]=e,t[13]=d):d=t[13],v=!0,p=c?s.jsxs($e,{title:e("settings.integrations.firstParty.title"),info:e("settings.integrations.firstParty.info"),divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[n?s.jsx(Df,{}):null,i?s.jsx(_f,{}):null,w.map(b=>s.jsx(Kc,{guest:b},`${l}:${b.id}`))]}):null,t[1]=r,t[2]=l,t[3]=e,t[4]=u,t[5]=c,t[6]=f,t[7]=d,t[8]=v,t[9]=p}else u=t[4],c=t[5],f=t[6],d=t[7],v=t[8],p=t[9];let j;t[14]!==c?(j=s.jsx(Cf,{divider:c}),t[14]=c,t[15]=j):j=t[15];let h;return t[16]!==u||t[17]!==f||t[18]!==d||t[19]!==v||t[20]!==p||t[21]!==j?(h=s.jsxs(u,{title:f,description:d,showSaveStatus:v,children:[p,j]}),t[16]=u,t[17]=f,t[18]=d,t[19]=v,t[20]=p,t[21]=j,t[22]=h):h=t[22],h};function Bf(t){return t.guests}function Vf(t){return t.runtimeKey}function Hf(t){return t.source==="bundled"&&t.integration&&dc(t)}const qf={prompt:{icon:"chat-1",titleKey:"settings.extensions.capability.prompt",detailKey:"settings.extensions.capability.prompt.detail"},sessions:{icon:"git-branch",titleKey:"settings.extensions.capability.sessions",detailKey:"settings.extensions.capability.sessions.detail"},files:{icon:"file-text",titleKey:"settings.extensions.capability.files",detailKey:"settings.extensions.capability.files.detail"},model:{icon:"sparkling",titleKey:"settings.extensions.capability.model",detailKey:"settings.extensions.capability.model.detail"},conversation:{icon:"chat-history",titleKey:"settings.extensions.capability.conversation",detailKey:"settings.extensions.capability.conversation.detail"},filesystem:{icon:"hard-drive-2",titleKey:"settings.extensions.capability.filesystem",detailKey:"settings.extensions.capability.filesystem.detail"},service:{icon:"terminal",titleKey:"settings.extensions.capability.service",detailKey:"settings.extensions.capability.service.detail"},network:{icon:"plug",titleKey:"settings.extensions.capability.network",detailKey:"settings.extensions.capability.network.detail"}},Gf=t=>{const e=dt.c(69),{guest:a,busy:n,onApprove:i,onDecline:r,onDismiss:l}=t,{t:u}=et();let c;e[0]!==a?.capabilities.requested?(c=a?.capabilities.requested??[],e[0]=a?.capabilities.requested,e[1]=c):c=e[1];const f=c;let d;e[2]!==a?.filesystem?(d=a?.filesystem??[],e[2]=a?.filesystem,e[3]=d):d=e[3];const v=d;let p;e[4]!==a?.service?.permissions?.exec?(p=a?.service?.permissions?.exec??[],e[4]=a?.service?.permissions?.exec,e[5]=p):p=e[5];const j=p;let h;e[6]!==a?.service?.permissions?.sockets?(h=a?.service?.permissions?.sockets??[],e[6]=a?.service?.permissions?.sockets,e[7]=h):h=e[7];const w=h,b=a?.integration?.apiOrigin??null,k=a!==null;let m;e[8]!==n||e[9]!==l?(m=ie=>{!ie&&!n&&l()},e[8]=n,e[9]=l,e[10]=m):m=e[10];const I=a?.name??"";let E;e[11]!==u||e[12]!==I?(E=u("settings.extensions.dialog.approveTitle",{name:I}),e[11]=u,e[12]=I,e[13]=E):E=e[13];let A;e[14]!==E?(A=s.jsx(Bt,{children:E}),e[14]=E,e[15]=A):A=e[15];const N=a?.name??"",x=a?.version?`v${a.version}`:"";let y;e[16]!==u||e[17]!==N||e[18]!==x?(y=u("settings.extensions.dialog.approveDescription",{name:N,version:x}),e[16]=u,e[17]=N,e[18]=x,e[19]=y):y=e[19];let F;e[20]!==y?(F=s.jsx(Vt,{children:y}),e[20]=y,e[21]=F):F=e[21];let T;e[22]!==F||e[23]!==A?(T=s.jsxs($t,{children:[A,F]}),e[22]=F,e[23]=A,e[24]=T):T=e[24];let P;if(e[25]!==b||e[26]!==v||e[27]!==f||e[28]!==j||e[29]!==w||e[30]!==u){let ie;e[32]!==b||e[33]!==v||e[34]!==j||e[35]!==w||e[36]!==u?(ie=K=>{const q=qf[K];return s.jsxs("li",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-md bg-[var(--surface-muted)]",children:s.jsx(z,{name:q.icon,className:"size-4 text-foreground"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:u(q.titleKey)}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:u(q.detailKey)}),K==="filesystem"&&v.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:v.map(Wf)}):null,K==="network"&&b?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[u("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:b})]}):null,K==="service"&&j.length>0?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[u("settings.extensions.capability.service.runs")," ",s.jsx("span",{className:"break-all font-mono",children:j.join(", ")})]}):null,K==="service"&&w.length>0?s.jsxs("p",{className:"typography-meta mt-0.5 text-foreground",children:[u("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:w.join(", ")})]}):null]})]},K)},e[32]=b,e[33]=v,e[34]=j,e[35]=w,e[36]=u,e[37]=ie):ie=e[37],P=f.map(ie),e[25]=b,e[26]=v,e[27]=f,e[28]=j,e[29]=w,e[30]=u,e[31]=P}else P=e[31];let D;e[38]!==P?(D=s.jsx("ul",{className:"space-y-3",children:P}),e[38]=P,e[39]=D):D=e[39];let $;e[40]!==a||e[41]!==r?($=()=>a&&r(a),e[40]=a,e[41]=r,e[42]=$):$=e[42];let _;e[43]!==u?(_=u("settings.extensions.dialog.decline"),e[43]=u,e[44]=_):_=e[44];let C;e[45]!==n||e[46]!==$||e[47]!==_?(C=s.jsx(H,{size:"sm",variant:"ghost",disabled:n,onClick:$,children:_}),e[45]=n,e[46]=$,e[47]=_,e[48]=C):C=e[48];let R;e[49]!==a||e[50]!==i?(R=()=>a&&i(a),e[49]=a,e[50]=i,e[51]=R):R=e[51];let V;e[52]!==u?(V=u("settings.extensions.dialog.approve"),e[52]=u,e[53]=V):V=e[53];let U;e[54]!==n||e[55]!==R||e[56]!==V?(U=s.jsx(H,{size:"sm",disabled:n,onClick:R,children:V}),e[54]=n,e[55]=R,e[56]=V,e[57]=U):U=e[57];let W;e[58]!==C||e[59]!==U?(W=s.jsxs(is,{children:[C,U]}),e[58]=C,e[59]=U,e[60]=W):W=e[60];let te;e[61]!==T||e[62]!==D||e[63]!==W?(te=s.jsxs(Ut,{className:"max-w-md",children:[T,D,W]}),e[61]=T,e[62]=D,e[63]=W,e[64]=te):te=e[64];let O;return e[65]!==te||e[66]!==k||e[67]!==m?(O=s.jsx(zt,{open:k,onOpenChange:m,children:te}),e[65]=te,e[66]=k,e[67]=m,e[68]=O):O=e[68],O};function Wf(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}const Jf=t=>{if(t.source!=="git"||!t.origin?.url)return null;const e=t.origin.url.trim(),a=/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*@)?([A-Za-z0-9][A-Za-z0-9.-]*\.[A-Za-z0-9.-]+):([^\s]+)$/.exec(e);try{const n=new URL(a?`ssh://${a[1]}/${a[2]}`:e);if(n.protocol!=="https:"&&n.protocol!=="ssh:")return null;const i=n.protocol==="ssh:"?new URL(`https://${n.hostname}${n.pathname}`):n;return i.username="",i.password="",i.search="",i.hash="",i.pathname=i.pathname.replace(/\/+$/,"").replace(/\.git$/i,""),i.pathname==="/"?null:i.href}catch{return null}},Qf=on({error:to(["invalid-path","invalid-url","not-found","invalid-manifest","id-taken","already-installed","missing-build","host-too-old","bundled","reserved-id","clone-failed","extract-failed","too-large"]),required:as().trim().min(1).max(64).optional(),id:as().trim().min(1).max(128).optional()}),Yf=t=>{const e=t.trim();if(!e)return{ok:!1,code:"invalid-path"};if(e.slice(0,8).toLowerCase()==="https://")return{ok:!0,request:{url:e}};if(e.slice(0,6).toLowerCase()==="ssh://"||/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*@)?[A-Za-z0-9][A-Za-z0-9.-]*\.[A-Za-z0-9.-]+:[^\s]+$/.test(e))return{ok:!0,request:{url:e}};const a=/^[a-zA-Z]:[\\/]/.test(e);return/^[a-z][a-z0-9+.-]*:/i.test(e)&&!a?{ok:!1,code:"invalid-url"}:e.startsWith("/")||a||e.startsWith("\\\\")?{ok:!0,request:{path:e}}:{ok:!1,code:"invalid-path"}},zc=async t=>{try{const e=Qf.safeParse(JSON.parse(await t.text()));return e.success?e.data.error==="host-too-old"&&e.data.required&&e.data.id?{code:"host-too-old",required:e.data.required,id:e.data.id}:e.data.error==="host-too-old"&&e.data.required?{code:"host-too-old",required:e.data.required}:e.data.id?{code:e.data.error,id:e.data.id}:{code:e.data.error}:{code:"failed"}}catch{return{code:"failed"}}},Uc=async(t,e)=>{if(!t.ok)return{ok:!1,...await zc(t),diagnostic:{method:"POST",path:e,kind:"http",status:t.status}};const a=await t.text().catch(()=>null),n=a===null?null:uc(a);return n?{ok:!0,guest:n,replaced:t.status===200}:{ok:!1,code:"failed",diagnostic:{method:"POST",path:e,kind:"invalid-response",status:t.status}}},Zf=async(t,e={})=>{const a=Yf(t);if(!a.ok)return a;const n={...a.request};e.replace&&(n.replace=!0),"url"in n&&e.gitIdentityId&&(n.gitIdentityId=e.gitIdentityId);try{const i=await xt("/api/guests",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});return await Uc(i,"/api/guests")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests",kind:"network"}}}},Xf=async(t,e={})=>{try{const a=await xt("/api/guests/upload",{method:"POST",query:{replace:e.replace?"true":void 0,name:t.name||void 0},headers:{"Content-Type":"application/octet-stream",Accept:"application/json"},body:t});return await Uc(a,"/api/guests/upload")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests/upload",kind:"network"}}}},ex=async t=>{try{const e=await xt(`/api/guests/${t}`,{method:"DELETE"});return e.status===204?{ok:!0}:{ok:!1,code:(await zc(e)).code}}catch{return{ok:!1,code:"failed"}}},tx=async(t,e)=>{try{return(await xt(`/api/guests/${t}/enabled`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})})).ok}catch{return!1}},sx=async(t,e)=>{try{return(await xt(`/api/guests/${t}/capabilities`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({granted:e})})).ok}catch{return!1}},kr=(t,e)=>{const a=`${t.method} ${t.path}`;return t.kind==="network"?`${a}: ${e("settings.extensions.request.noResponse")}`:t.kind==="invalid-response"?`${a}: ${e("settings.extensions.request.invalidResponse",{status:t.status})}`:`${a}: HTTP ${t.status}`},nx=on({updates:Mr(as().min(1),Kd)}),ax=on({error:to(["not-git","clone-failed","invalid-manifest","missing-build","host-too-old","swap-failed","not-found"]),required:as().trim().min(1).max(64).optional()}),Il=async t=>{try{const e=await xt("/api/guests/updates/check",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({force:t})});if(!e.ok)return{ok:!1};const a=nx.safeParse(JSON.parse(await e.text()));return a.success?{ok:!0,updates:a.data.updates}:{ok:!1}}catch{return{ok:!1}}},ix=async t=>{try{const e=ax.safeParse(JSON.parse(await t.text()));return e.success?e.data.required?{code:e.data.error,required:e.data.required}:{code:e.data.error}:{code:"failed"}}catch{return{code:"failed"}}},rx=async t=>{try{const e=await xt(`/api/guests/${t}/update`,{method:"POST",headers:{Accept:"application/json"}});if(!e.ok){const n=await ix(e);return n.required?{ok:!1,code:n.code,required:n.required}:{ok:!1,code:n.code}}const a=uc(await e.text());return a?{ok:!0,guest:a}:{ok:!1,code:"failed"}}catch{return{ok:!1,code:"failed"}}},ox=t=>t==="invalid-path"?"settings.extensions.toast.invalidPath":t==="invalid-url"?"settings.extensions.toast.invalidUrl":t==="not-found"?"settings.extensions.toast.notFound":t==="invalid-manifest"?"settings.extensions.toast.invalidManifest":t==="reserved-id"?"settings.extensions.toast.reservedId":t==="id-taken"?"settings.extensions.toast.idTaken":t==="already-installed"?"settings.extensions.toast.alreadyInstalled":t==="missing-build"?"settings.extensions.toast.missingBuild":t==="host-too-old"?"settings.extensions.toast.hostTooOld":t==="clone-failed"?"settings.extensions.toast.cloneFailed":t==="extract-failed"?"settings.extensions.toast.extractFailed":t==="too-large"?"settings.extensions.toast.zipTooLarge":"settings.extensions.toast.failed",Pl=t=>t.name.toLowerCase().endsWith(".zip"),lx=t=>t==="not-git"?"settings.extensions.toast.notGit":t==="clone-failed"?"settings.extensions.toast.cloneFailed":t==="invalid-manifest"?"settings.extensions.toast.invalidManifest":t==="missing-build"?"settings.extensions.toast.missingBuild":t==="swap-failed"?"settings.extensions.toast.swapFailed":t==="not-found"?"settings.extensions.toast.notFound":"settings.extensions.toast.updateFailed",cx=t=>t==="path"?"settings.extensions.source.path":t==="zip"?"settings.extensions.source.zip":t==="git"?"settings.extensions.source.git":"settings.extensions.source.bundled",dx=t=>{const e=(t.service?.socketBindings??[]).map(i=>i.resolved?`${i.id}=${i.resolved}`:`${i.id}?`),a=(t.service?.permissions?.sockets??[]).filter(i=>!(t.service?.socketBindings??[]).some(r=>r.id===i));return[...e,...a,...t.service?.permissions?.exec??[]].join(", ")},ux=t=>{const e=dt.c(27),{guest:a,binding:n,busy:i,onSaved:r}=t,{t:l}=et(),[u,c]=o.useState(n.override??n.resolved??""),[f,d]=o.useState(!1),[v,p]=o.useState(!n.resolved);let j;e[0]!==n.override||e[1]!==n.resolved?(j=()=>{c(n.override??n.resolved??""),n.resolved||p(!0)},e[0]=n.override,e[1]=n.resolved,e[2]=j):j=e[2];let h;e[3]!==n.id||e[4]!==n.override||e[5]!==n.resolved?(h=[n.id,n.override,n.resolved],e[3]=n.id,e[4]=n.override,e[5]=n.resolved,e[6]=h):h=e[6],o.useEffect(j,h);let w;e[7]!==n.id||e[8]!==a.id||e[9]!==a.name||e[10]!==r||e[11]!==l?(w=async E=>{d(!0);const A=await pp(a.id,n.id,E);if(d(!1),!A){M.error(l("settings.extensions.toast.socketSaveFailed"));return}M.success(l("settings.extensions.toast.socketSaved",{name:a.name})),p(!1),await r()},e[7]=n.id,e[8]=a.id,e[9]=a.name,e[10]=r,e[11]=l,e[12]=w):w=e[12];const b=w;let k;e[13]!==n.override||e[14]!==n.resolved?(k=()=>{c(n.override??n.resolved??""),n.resolved&&p(!1)},e[13]=n.override,e[14]=n.resolved,e[15]=k):k=e[15];const m=k;let I;return e[16]!==n.id||e[17]!==n.override||e[18]!==n.resolved||e[19]!==i||e[20]!==m||e[21]!==v||e[22]!==b||e[23]!==f||e[24]!==l||e[25]!==u?(I=s.jsx("div",{className:"space-y-1",children:v?s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx(He,{value:u,onChange:E=>c(E.target.value),placeholder:l("settings.extensions.service.socket.path",{id:n.id}),"aria-label":l("settings.extensions.service.socket.path.aria",{id:n.id}),className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:i||f,autoFocus:!0}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",disabled:i||f,"aria-label":l("settings.extensions.service.socket.save.aria",{id:n.id}),onClick:()=>{b(u.trim()||null)},children:l("settings.extensions.service.socket.save")}),n.override?s.jsx(H,{type:"button",variant:"ghost",size:"xs",disabled:i||f,"aria-label":l("settings.extensions.service.socket.clear.aria",{id:n.id}),onClick:()=>{b(null)},children:l("settings.extensions.service.socket.clear")}):null,n.resolved?s.jsx(H,{type:"button",variant:"ghost",size:"xs",disabled:i||f,"aria-label":l("settings.extensions.service.socket.cancel.aria",{id:n.id}),onClick:m,children:l("settings.extensions.service.socket.cancel")}):null]}):s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx("div",{className:"typography-meta min-w-0 flex-1 truncate text-muted-foreground",children:n.resolved?l("settings.extensions.service.socket.resolved",{path:n.resolved}):l("settings.extensions.service.socket.unresolved")}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:ys,disabled:i||f,"aria-label":l("settings.extensions.service.socket.edit.aria",{id:n.id}),onClick:()=>p(!0),children:s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"})})]})}),e[16]=n.id,e[17]=n.override,e[18]=n.resolved,e[19]=i,e[20]=m,e[21]=v,e[22]=b,e[23]=f,e[24]=l,e[25]=u,e[26]=I):I=e[26],I},px=t=>{const e=dt.c(143),{guest:a,busy:n,onReview:i,onRemove:r,onSetEnabled:l,onUpdate:u}=t,{t:c}=et(),[f,d]=o.useState(!1),v=a.enabled!==!1;let p;e[0]!==a?(p=Dr(a),e[0]=a,e[1]=p):p=e[1];const j=p;let h,w,b,k,m,I,E,A,N,x,y,F,T,P;if(e[2]!==v||e[3]!==a||e[4]!==j||e[5]!==f||e[6]!==c){const q=dx(a);b=!!(a.source&&a.source!=="bundled");const B=a.source==="bundled";let L;e[21]!==a?(L=Jf(a),e[21]=a,e[22]=L):L=e[22],k=L,P=a.source==="git"?a.update:void 0;let X;e[23]!==a.icon||e[24]!==a.id?(X=oc(a.id,a.icon,fc().authenticatedAsset),e[23]=a.icon,e[24]=a.id,e[25]=X):X=e[25];const G=X;let Z;e[26]!==B||e[27]!==a.source||e[28]!==c?(Z=B?null:c(cx(a.source)),e[26]=B,e[27]=a.source,e[28]=c,e[29]=Z):Z=e[29];const le=a.version?`v${a.version}`:null;let oe;e[30]!==a.entry||e[31]!==c?(oe=a.entry?null:c("settings.extensions.source.noPanel"),e[30]=a.entry,e[31]=c,e[32]=oe):oe=e[32];let he;e[33]!==Z||e[34]!==le||e[35]!==oe?(he=[Z,le,oe].filter(Boolean),e[33]=Z,e[34]=le,e[35]=oe,e[36]=he):he=e[36];const ee=he.join(" · "),re=a.path||a.id;let de;e[37]!==v||e[38]!==j||e[39]!==c?(de=c(j?"settings.extensions.status.needsApproval":v?"settings.extensions.status.enabled":"settings.extensions.status.disabled"),e[37]=v,e[38]=j,e[39]=c,e[40]=de):de=e[40];const ke=de,ue=j?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":v?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";w=yn,T=f,m=d,y="overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]";let xe;e[41]!==a.icon?(xe=cc(a.icon),e[41]=a.icon,e[42]=xe):xe=e[42];let pe;e[43]!==G||e[44]!==xe?(pe=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(lc,{icon:xe,iconSrc:G,className:"size-5 text-foreground"})}),e[43]=G,e[44]=xe,e[45]=pe):pe=e[45];let Ie;e[46]!==a.name?(Ie=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:a.name}),e[46]=a.name,e[47]=Ie):Ie=e[47];let Te;e[48]!==ee?(Te=s.jsx("p",{className:"mt-0.5 truncate text-xs leading-snug text-muted-foreground",children:ee}),e[48]=ee,e[49]=Te):Te=e[49];let we;e[50]!==Ie||e[51]!==Te?(we=s.jsxs("div",{className:"min-w-0 flex-1",children:[Ie,Te]}),e[50]=Ie,e[51]=Te,e[52]=we):we=e[52];let De;e[53]!==B||e[54]!==c?(De=B?s.jsx("span",{className:"shrink-0 rounded-full border border-[var(--interactive-border)] px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:c("settings.extensions.source.bundled")}):null,e[53]=B,e[54]=c,e[55]=De):De=e[55];let _e;e[56]!==c||e[57]!==P?(_e=P?s.jsx("span",{className:"max-w-40 shrink-0 truncate rounded-full bg-[var(--status-info)]/15 px-2 py-0.5 text-[10px] font-medium text-[var(--status-info)]",children:c("settings.extensions.update.badge",{version:P.version})}):null,e[56]=c,e[57]=P,e[58]=_e):_e=e[58];let Ve;e[59]!==ue?(Ve=ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ue),e[59]=ue,e[60]=Ve):Ve=e[60];let ve;e[61]!==ke||e[62]!==Ve?(ve=s.jsx("span",{"aria-live":"polite",className:Ve,children:ke}),e[61]=ke,e[62]=Ve,e[63]=ve):ve=e[63];const se=f&&"rotate-180";let ae;e[64]!==se?(ae=ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",se),e[64]=se,e[65]=ae):ae=e[65];let je;e[66]!==ae?(je=s.jsx(z,{name:"arrow-down-s",className:ae}),e[66]=ae,e[67]=je):je=e[67],e[68]!==pe||e[69]!==we||e[70]!==De||e[71]!==_e||e[72]!==ve||e[73]!==je?(F=s.jsxs(jn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[pe,we,De,_e,ve,je]}),e[68]=pe,e[69]=we,e[70]=De,e[71]=_e,e[72]=ve,e[73]=je,e[74]=F):F=e[74],h=wn,x="border-t border-[var(--interactive-border)] px-4 py-4",I="space-y-3",e[75]!==re?(E=s.jsx("p",{className:"typography-meta truncate font-mono text-muted-foreground",title:re,children:re}),e[75]=re,e[76]=E):E=e[76],e[77]!==B||e[78]!==c?(A=B?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.builtIn.info")}):null,e[77]=B,e[78]=c,e[79]=A):A=e[79],N=q?s.jsx("p",{className:"typography-meta truncate text-muted-foreground",children:c("settings.extensions.service.permissions",{list:q})}):null,e[2]=v,e[3]=a,e[4]=j,e[5]=f,e[6]=c,e[7]=h,e[8]=w,e[9]=b,e[10]=k,e[11]=m,e[12]=I,e[13]=E,e[14]=A,e[15]=N,e[16]=x,e[17]=y,e[18]=F,e[19]=T,e[20]=P}else h=e[7],w=e[8],b=e[9],k=e[10],m=e[11],I=e[12],E=e[13],A=e[14],N=e[15],x=e[16],y=e[17],F=e[18],T=e[19],P=e[20];let D;e[80]!==a.service||e[81]!==c?(D=a.service?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.service.warning")}):null,e[80]=a.service,e[81]=c,e[82]=D):D=e[82];let $;e[83]!==n||e[84]!==v||e[85]!==a?($=v?(a.service?.socketBindings??[]).map(q=>s.jsx(ux,{guest:a,binding:q,busy:n,onSaved:zn},q.id)):null,e[83]=n,e[84]=v,e[85]=a,e[86]=$):$=e[86];let _;e[87]!==n||e[88]!==a||e[89]!==u||e[90]!==c||e[91]!==P?(_=P?s.jsx(H,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.update.action.aria",{name:a.name,version:P.version}),onClick:()=>{u(a)},children:c("settings.extensions.update.action")}):null,e[87]=n,e[88]=a,e[89]=u,e[90]=c,e[91]=P,e[92]=_):_=e[92];let C;e[93]!==n||e[94]!==a||e[95]!==j||e[96]!==i||e[97]!==c?(C=j?s.jsx(H,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.review.aria",{name:a.name}),onClick:()=>i(a),children:c("settings.extensions.review")}):null,e[93]=n,e[94]=a,e[95]=j,e[96]=i,e[97]=c,e[98]=C):C=e[98];let R;e[99]!==n||e[100]!==v||e[101]!==a.id||e[102]!==a.name||e[103]!==l||e[104]!==c?(R=v?s.jsx(H,{type:"button",size:"sm",variant:"outline",disabled:n,"aria-label":c("settings.extensions.actions.disable.aria",{name:a.name}),onClick:()=>{l(a.id,a.name,!1)},children:c("settings.extensions.actions.disable")}):s.jsx(H,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.actions.enable.aria",{name:a.name}),onClick:()=>{l(a.id,a.name,!0)},children:c("settings.extensions.actions.enable")}),e[99]=n,e[100]=v,e[101]=a.id,e[102]=a.name,e[103]=l,e[104]=c,e[105]=R):R=e[105];let V;e[106]!==n||e[107]!==b||e[108]!==a.id||e[109]!==a.name||e[110]!==r||e[111]!==c?(V=b?s.jsx(H,{type:"button",size:"sm",variant:"destructive",disabled:n,"aria-label":c("settings.extensions.remove.aria",{name:a.name}),onClick:()=>{r(a.id,a.name)},children:c("settings.extensions.remove")}):null,e[106]=n,e[107]=b,e[108]=a.id,e[109]=a.name,e[110]=r,e[111]=c,e[112]=V):V=e[112];let U;e[113]!==k||e[114]!==c?(U=k?s.jsxs(H,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>{hn(k)},children:[s.jsx(z,{name:"external-link",className:"size-4"}),c("settings.extensions.actions.openSource")]}):null,e[113]=k,e[114]=c,e[115]=U):U=e[115];let W;e[116]!==_||e[117]!==C||e[118]!==R||e[119]!==V||e[120]!==U?(W=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[_,C,R,V,U]}),e[116]=_,e[117]=C,e[118]=R,e[119]=V,e[120]=U,e[121]=W):W=e[121];let te;e[122]!==D||e[123]!==$||e[124]!==W||e[125]!==I||e[126]!==E||e[127]!==A||e[128]!==N?(te=s.jsxs("div",{className:I,children:[E,A,N,D,$,W]}),e[122]=D,e[123]=$,e[124]=W,e[125]=I,e[126]=E,e[127]=A,e[128]=N,e[129]=te):te=e[129];let O;e[130]!==h||e[131]!==te||e[132]!==x?(O=s.jsx(h,{className:x,children:te}),e[130]=h,e[131]=te,e[132]=x,e[133]=O):O=e[133];let ie;e[134]!==O||e[135]!==y||e[136]!==F?(ie=s.jsxs("div",{className:y,children:[F,O]}),e[134]=O,e[135]=y,e[136]=F,e[137]=ie):ie=e[137];let K;return e[138]!==w||e[139]!==m||e[140]!==ie||e[141]!==T?(K=s.jsx(w,{open:T,onOpenChange:m,children:ie}),e[138]=w,e[139]=m,e[140]=ie,e[141]=T,e[142]=K):K=e[142],K},mx=()=>{const t=dt.c(174),{t:e}=et(),a=Ys(gx),n=Ys(hx),i=Ys(fx),r=Ys(xx),[l,u]=o.useState(null),[c,f]=o.useState(!1),[d,v]=o.useState("global"),p=n==="unsupported",[j,h]=o.useState(""),[w,b]=o.useState(!1),[k,m]=o.useState(!1),I=o.useRef(!1),[E,A]=o.useState(null),[N,x]=o.useState(null),[y,F]=o.useState(!1),T=o.useRef(0),P=o.useRef(null);let D;t[0]===Symbol.for("react.memo_cache_sentinel")?(D=Cu(),t[0]=D):D=t[0];const $=D;let _;t[1]===Symbol.for("react.memo_cache_sentinel")?(_=[],t[1]=_):_=t[1],o.useEffect(bx,_);let C,R;t[2]!==r||t[3]!==p?(C=()=>{let Qe=!1;if(u(null),f(!1),v("global"),A(null),x(null),I.current=!1,!p)return Promise.all([zd(),Ud()]).then(Be=>{const[Ct,Pt]=Be;Qe||u({runtimeKey:r,profiles:Ct,global:Pt})}).catch(()=>{Qe||f(!0)}),()=>{Qe=!0}},R=[r,p],t[2]=r,t[3]=p,t[4]=C,t[5]=R):(C=t[4],R=t[5]),o.useEffect(C,R);const V=l?.runtimeKey===r?l:null;let U;t[6]!==e?(U=e("settings.gitIdentities.editor.title.globalIdentity"),t[6]=e,t[7]=U):U=t[7];const W=V?.global?.userName??"",te=V?.global?.userEmail??"";let O;t[8]!==U||t[9]!==W||t[10]!==te?(O={id:"global",name:U,userName:W,userEmail:te,icon:"fingerprint",color:"info"},t[8]=U,t[9]=W,t[10]=te,t[11]=O):O=t[11];let ie;t[12]!==V?.profiles||t[13]!==O?(ie=[O,...V?.profiles.filter(vx)??[]],t[12]=V?.profiles,t[13]=O,t[14]=ie):ie=t[14];const K=ie;let q;t[15]!==K||t[16]!==d?(q=K.find(Qe=>Qe.id===d)??K[0],t[15]=K,t[16]=d,t[17]=q):q=t[17];const B=q;let L,X;t[18]!==n?(L=()=>{if(n!=="ready"||I.current)return;I.current=!0;const Qe=Ys.getState().runtimeKey;Il(!1).then(Be=>{Be.ok&&Ys.getState().applyUpdates(Be.updates,Qe)})},X=[n],t[18]=n,t[19]=L,t[20]=X):(L=t[19],X=t[20]),o.useEffect(L,X);let G;t[21]!==e?(G=async()=>{m(!0);const Qe=Ys.getState().runtimeKey,Be=await Il(!0);if(m(!1),!Be.ok){M.error(e("settings.extensions.toast.checkFailed"));return}Ys.getState().applyUpdates(Be.updates,Qe),Object.keys(Be.updates).length===0&&M.success(e("settings.extensions.toast.upToDate"))},t[21]=e,t[22]=G):G=t[22];const Z=G;let le;t[23]!==e?(le=async Qe=>{b(!0);const Be=await rx(Qe.id);if(b(!1),!Be.ok){M.error(Be.code==="host-too-old"&&Be.required?e("settings.extensions.toast.hostTooOld",{version:Be.required}):e(lx(Be.code)));return}gr(Qe.id),M.success(e("settings.extensions.toast.updated",{name:Be.guest.name,version:Be.guest.version??""})),await zn(),Dr(Be.guest)&&x(Be.guest)},t[23]=e,t[24]=le):le=t[24];const oe=le;let he;if(t[25]!==a||t[26]!==e){const Qe=async(Be,Ct,Pt)=>{const es=Pt===void 0?{}:Pt;if(!Be.ok){if(es.allowConflictDialog!==!1&&(Be.code==="id-taken"||Be.code==="already-installed")){const ts=Be.id?a.find(rs=>rs.id===Be.id):void 0;return A({source:Ct,name:ts?.name??Be.id??(Ct.kind==="file"?Ct.file.name:Ct.input)}),!1}return Be.code==="host-too-old"?M.error(Be.required?e("settings.extensions.toast.hostTooOld",{version:Be.required}):e("settings.extensions.toast.failed"),{description:Be.diagnostic?kr(Be.diagnostic,e):void 0}):M.error(e(ox(Be.code)),{description:Be.diagnostic?kr(Be.diagnostic,e):void 0}),!1}return h(""),A(null),M.success(Be.replaced?e("settings.extensions.toast.reinstalled",{name:Be.guest.name}):e("settings.extensions.toast.added",{name:Be.guest.name})),await zn(),Dr(Be.guest)&&x(Be.guest),!0};he=async(Be,Ct)=>{const Pt=Ct===void 0?{}:Ct,es=Oa();Be.kind==="input"&&h(Be.input),b(!0);const ts=Be.kind==="file"?await Xf(Be.file,Pt):await Zf(Be.input,{...Pt,gitIdentityId:Be.gitIdentityId});b(!1),Oa()===es&&await Qe(ts,Be,{allowConflictDialog:!Pt.replace})},t[25]=a,t[26]=e,t[27]=he}else he=t[27];const ee=he;let re;t[28]!==j||t[29]!==ee||t[30]!==B||t[31]!==e?(re=async()=>{const Qe=j.trim();if(!Qe){M.error(e("settings.extensions.toast.invalidPath"));return}await ee({kind:"input",input:Qe,gitIdentityId:B.id})},t[28]=j,t[29]=ee,t[30]=B,t[31]=e,t[32]=re):re=t[32];const de=re;let ke;t[33]!==ee?(ke=async()=>{if(!$)return;const Qe=await Iu("");Qe.success&&Qe.path&&await ee({kind:"input",input:Qe.path})},t[33]=ee,t[34]=ke):ke=t[34];const ue=ke;let xe;t[35]!==ee?(xe=async()=>{if(!$){P.current?.click();return}const Qe=await Zr({filters:[{name:"ZIP Archive",extensions:["zip"]}]});Qe.success&&Qe.path&&await ee({kind:"input",input:Qe.path})},t[35]=ee,t[36]=xe):xe=t[36];const pe=xe;let Ie;t[37]!==ee||t[38]!==e?(Ie=async Qe=>{const Be=Qe.target.files?.[0]??null;if(Qe.target.value="",!!Be){if(!Pl(Be)){M.error(e("settings.extensions.toast.invalidPath"));return}await ee({kind:"file",file:Be})}},t[37]=ee,t[38]=e,t[39]=Ie):Ie=t[39];const Te=Ie;let we;t[40]!==w?(we=Qe=>{w||(Qe.preventDefault(),T.current=T.current+1,F(!0))},t[40]=w,t[41]=we):we=t[41];const De=we;let _e;t[42]!==w?(_e=Qe=>{w||(Qe.preventDefault(),Qe.dataTransfer.dropEffect="copy")},t[42]=w,t[43]=_e):_e=t[43];const Ve=_e;let ve;t[44]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>{T.current=Math.max(0,T.current-1),T.current===0&&F(!1)},t[44]=ve):ve=t[44];const se=ve;let ae;t[45]!==w||t[46]!==ee||t[47]!==e?(ae=async Qe=>{if(Qe.preventDefault(),T.current=0,F(!1),w)return;const Be=Qe.dataTransfer.items[0],Ct=Be?.getAsFile()??null,es=(Be?.webkitGetAsEntry()??null)?.isDirectory===!0,ts=Ct!==null&&!es&&Pl(Ct),rs=Ct&&$?Pu(Ct):null;if(rs&&(es||ts)){await ee({kind:"input",input:rs});return}if(es){M.error(e($?"settings.extensions.toast.invalidPath":"settings.extensions.toast.folderNeedsZip"));return}if(!Ct||!ts){M.error(e("settings.extensions.toast.invalidPath"));return}await ee({kind:"file",file:Ct})},t[45]=w,t[46]=ee,t[47]=e,t[48]=ae):ae=t[48];const je=ae;let Se;t[49]!==E||t[50]!==ee?(Se=async()=>{E&&await ee(E.source,{replace:!0})},t[49]=E,t[50]=ee,t[51]=Se):Se=t[51];const Ke=Se;let Ue;t[52]!==e?(Ue=async(Qe,Be)=>{b(!0);const Ct=await ex(Qe);if(b(!1),!Ct.ok){M.error(e("settings.extensions.toast.removeFailed"));return}gr(Qe),M.success(e("settings.extensions.toast.removed",{name:Be})),await zn()},t[52]=e,t[53]=Ue):Ue=t[53];const Oe=Ue;let Re;t[54]!==e?(Re=async Qe=>{b(!0);const Be=await sx(Qe.id,Qe.capabilities.requested);if(b(!1),!Be){M.error(e("settings.extensions.toast.approveFailed"));return}x(null),M.success(e("settings.extensions.toast.approved",{name:Qe.name})),await zn()},t[54]=e,t[55]=Re):Re=t[55];const Ce=Re;let Ze;t[56]!==Oe?(Ze=async Qe=>{x(null),await Oe(Qe.id,Qe.name)},t[56]=Oe,t[57]=Ze):Ze=t[57];const be=Ze;let Pe;t[58]!==e?(Pe=async(Qe,Be,Ct)=>{b(!0);const Pt=await tx(Qe,Ct);if(b(!1),!Pt){M.error(e("settings.extensions.toast.enabledFailed"));return}Ct||gr(Qe),M.success(Ct?e("settings.extensions.toast.enabled",{name:Be}):e("settings.extensions.toast.disabled",{name:Be})),await zn()},t[58]=e,t[59]=Pe):Pe=t[59];const Le=Pe;let Xe;t[60]!==e?(Xe=e("settings.page.extensions.title"),t[60]=e,t[61]=Xe):Xe=t[61];let Q;t[62]!==e?(Q=e("settings.page.extensions.description"),t[62]=e,t[63]=Q):Q=t[63];let Ne;t[64]!==de||t[65]!==ue||t[66]!==pe||t[67]!==w||t[68]!==y||t[69]!==K||t[70]!==l||t[71]!==c||t[72]!==j||t[73]!==De||t[74]!==Ve||t[75]!==je||t[76]!==Te||t[77]!==B||t[78]!==e||t[79]!==p?(Ne=p?null:s.jsxs($e,{title:e("settings.extensions.add.action"),info:e("settings.extensions.add.info"),children:[s.jsx(Kt,{label:e("settings.extensions.add.label"),info:e($?"settings.extensions.add.drop":"settings.extensions.add.drop.zipOnly"),settingsItem:"extensions.add",controlClassName:"w-full max-w-none",children:s.jsxs("div",{className:ye("relative -m-1 flex min-w-0 flex-1 items-center gap-2 rounded-md border border-dashed border-transparent p-1 transition-colors",y&&"border-primary bg-primary/5"),onDragEnter:De,onDragOver:Ve,onDragLeave:se,onDrop:Qe=>{je(Qe)},children:[y?s.jsx("span",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-md bg-background/80 typography-ui-label text-primary",children:e("settings.extensions.add.drop.active")}):null,s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center",children:[s.jsx(He,{value:j,onChange:Qe=>h(Qe.target.value),onKeyDown:Qe=>{Qe.key==="Enter"&&(Qe.preventDefault(),de())},placeholder:e("settings.extensions.add.placeholder"),"aria-label":e("settings.extensions.add.label"),className:ye("h-8 min-w-0 flex-1 rounded-md pl-3",$?"pr-14":"pr-8"),disabled:w}),s.jsx("input",{ref:P,type:"file",accept:".zip,application/zip",className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:Qe=>{Te(Qe)}}),s.jsxs("div",{className:"absolute right-1 top-1/2 flex -translate-y-1/2 items-center gap-0.5",children:[$?s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseFolder"),"aria-label":e("settings.extensions.add.browseFolder.aria"),disabled:w,onClick:()=>{ue()},children:s.jsx(z,{name:"folder",className:"h-4 w-4"})}):null,s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseZip"),"aria-label":e("settings.extensions.add.browseZip.aria"),disabled:w,onClick:()=>{pe()},children:s.jsx(z,{name:"archive",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"shrink-0","data-settings-item":"extensions.gitIdentity",children:s.jsx(Gu,{activeProfile:B,identities:K,onSelect:Qe=>v(Qe.id),isApplying:w||!l&&!c,iconOnly:!0})}),s.jsxs(H,{type:"button",size:"sm",disabled:w,"aria-label":e("settings.extensions.add.aria"),onClick:()=>{de()},children:[s.jsx(z,{name:"add",className:"h-4 w-4"}),e("settings.extensions.add.action")]})]})}),c?s.jsx("p",{className:"typography-meta text-destructive",children:e("settings.extensions.identity.loadFailed")}):null]}),t[64]=de,t[65]=ue,t[66]=pe,t[67]=w,t[68]=y,t[69]=K,t[70]=l,t[71]=c,t[72]=j,t[73]=De,t[74]=Ve,t[75]=je,t[76]=Te,t[77]=B,t[78]=e,t[79]=p,t[80]=Ne):Ne=t[80];let Ae;t[81]!==e?(Ae=e("settings.extensions.section.installed"),t[81]=e,t[82]=Ae):Ae=t[82];let We;t[83]!==w||t[84]!==Z||t[85]!==k||t[86]!==n||t[87]!==e||t[88]!==p?(We=p?null:s.jsxs(H,{type:"button",variant:"ghost",size:"sm","data-settings-item":"extensions.updates.check",disabled:w||k||n!=="ready","aria-label":e("settings.extensions.updates.check.aria"),onClick:()=>{Z()},children:[s.jsx(z,{name:"refresh",className:ye("h-4 w-4",k&&"animate-spin")}),e("settings.extensions.updates.check")]}),t[83]=w,t[84]=Z,t[85]=k,t[86]=n,t[87]=e,t[88]=p,t[89]=We):We=t[89];let lt;t[90]!==i||t[91]!==n||t[92]!==e?(lt=n==="error"||i?s.jsxs("p",{className:"typography-meta whitespace-pre-line text-destructive",children:[e("settings.extensions.toast.loadFailed"),i?`
29
+ ${kr(i,e)}`:""]}):null,t[90]=i,t[91]=n,t[92]=e,t[93]=lt):lt=t[93];let at;t[94]!==e||t[95]!==p?(at=p?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.unsupported")}):null,t[94]=e,t[95]=p,t[96]=at):at=t[96];let pt;t[97]!==a.length||t[98]!==n||t[99]!==e?(pt=n==="ready"&&a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.empty")}):null,t[97]=a.length,t[98]=n,t[99]=e,t[100]=pt):pt=t[100];let bt;if(t[101]!==w||t[102]!==a||t[103]!==Oe||t[104]!==Le||t[105]!==oe){let Qe;t[107]!==w||t[108]!==Oe||t[109]!==Le||t[110]!==oe?(Qe=Be=>s.jsx(px,{guest:Be,busy:w,onReview:x,onRemove:Oe,onSetEnabled:Le,onUpdate:oe},Be.id),t[107]=w,t[108]=Oe,t[109]=Le,t[110]=oe,t[111]=Qe):Qe=t[111],bt=a.map(Qe),t[101]=w,t[102]=a,t[103]=Oe,t[104]=Le,t[105]=oe,t[106]=bt}else bt=t[106];let J;t[112]!==Ae||t[113]!==We||t[114]!==lt||t[115]!==at||t[116]!==pt||t[117]!==bt?(J=s.jsxs($e,{title:Ae,contentClassName:"space-y-3",headerAction:We,children:[lt,at,pt,bt]}),t[112]=Ae,t[113]=We,t[114]=lt,t[115]=at,t[116]=pt,t[117]=bt,t[118]=J):J=t[118];let qe;t[119]!==Ce?(qe=Qe=>{Ce(Qe)},t[119]=Ce,t[120]=qe):qe=t[120];let it;t[121]!==be?(it=Qe=>{be(Qe)},t[121]=be,t[122]=it):it=t[122];let ct;t[123]===Symbol.for("react.memo_cache_sentinel")?(ct=()=>x(null),t[123]=ct):ct=t[123];let gt;t[124]!==N||t[125]!==w||t[126]!==qe||t[127]!==it?(gt=s.jsx(Gf,{guest:N,busy:w,onApprove:qe,onDecline:it,onDismiss:ct}),t[124]=N,t[125]=w,t[126]=qe,t[127]=it,t[128]=gt):gt=t[128];const Rt=E!==null;let tt;t[129]!==w?(tt=Qe=>{!Qe&&!w&&A(null)},t[129]=w,t[130]=tt):tt=t[130];let ft;t[131]!==e?(ft=e("settings.extensions.dialog.reinstallTitle"),t[131]=e,t[132]=ft):ft=t[132];let jt;t[133]!==ft?(jt=s.jsx(Bt,{children:ft}),t[133]=ft,t[134]=jt):jt=t[134];const Je=E?.name??"";let St;t[135]!==e||t[136]!==Je?(St=e("settings.extensions.dialog.reinstallDescription",{name:Je}),t[135]=e,t[136]=Je,t[137]=St):St=t[137];let Fe;t[138]!==St?(Fe=s.jsx(Vt,{children:St}),t[138]=St,t[139]=Fe):Fe=t[139];let wt;t[140]!==jt||t[141]!==Fe?(wt=s.jsxs($t,{children:[jt,Fe]}),t[140]=jt,t[141]=Fe,t[142]=wt):wt=t[142];let Y;t[143]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>A(null),t[143]=Y):Y=t[143];let fe;t[144]!==e?(fe=e("settings.common.actions.cancel"),t[144]=e,t[145]=fe):fe=t[145];let Me;t[146]!==w||t[147]!==fe?(Me=s.jsx(H,{size:"sm",variant:"ghost",disabled:w,onClick:Y,children:fe}),t[146]=w,t[147]=fe,t[148]=Me):Me=t[148];let Ee;t[149]!==Ke?(Ee=()=>{Ke()},t[149]=Ke,t[150]=Ee):Ee=t[150];let rt;t[151]!==e?(rt=e("settings.extensions.dialog.reinstall"),t[151]=e,t[152]=rt):rt=t[152];let ot;t[153]!==w||t[154]!==Ee||t[155]!==rt?(ot=s.jsx(H,{size:"sm",disabled:w,onClick:Ee,children:rt}),t[153]=w,t[154]=Ee,t[155]=rt,t[156]=ot):ot=t[156];let Ge;t[157]!==Me||t[158]!==ot?(Ge=s.jsxs(is,{children:[Me,ot]}),t[157]=Me,t[158]=ot,t[159]=Ge):Ge=t[159];let Nt;t[160]!==wt||t[161]!==Ge?(Nt=s.jsxs(Ut,{className:"max-w-md",children:[wt,Ge]}),t[160]=wt,t[161]=Ge,t[162]=Nt):Nt=t[162];let ns;t[163]!==Rt||t[164]!==tt||t[165]!==Nt?(ns=s.jsx(zt,{open:Rt,onOpenChange:tt,children:Nt}),t[163]=Rt,t[164]=tt,t[165]=Nt,t[166]=ns):ns=t[166];let Zt;return t[167]!==Xe||t[168]!==Q||t[169]!==Ne||t[170]!==J||t[171]!==gt||t[172]!==ns?(Zt=s.jsxs(os,{title:Xe,description:Q,outerClassName:"extensions-settings-page",children:[Ne,J,gt,ns]}),t[167]=Xe,t[168]=Q,t[169]=Ne,t[170]=J,t[171]=gt,t[172]=ns,t[173]=Zt):Zt=t[173],Zt};function gx(t){return t.guests}function hx(t){return t.status}function fx(t){return t.failure}function xx(t){return t.runtimeKey}function bx(){zn()}function vx(t){return t.id!=="global"}const $s=Zn,yx=t=>{const e=t.kind==="dark"||t.kind==="high-contrast",a=_d(e),n=(pe,Ie)=>t.colors[pe]??Ie,i=pe=>pe!=="transparent"&&(qs(pe,"#000000")!==1||qs(pe,"#ffffff")!==1),r=(pe,Ie)=>{const Te=n(pe,Ie);return i(Te)?Te:Ie},l=n("chat.list.background",n("editor.background",a.colors.surface.background)),u=n("interactive-session.foreground",n("foreground",n("editor.foreground",a.colors.surface.foreground))),f=[["editorWidget.background","editorWidget.foreground"],["dropdown.background","dropdown.foreground"],["input.background","input.foreground"]].find(([pe])=>t.colors[pe]),d=f?n(f[0],a.colors.surface.elevated):a.colors.surface.elevated,v=Yn(u,d,l),p=f?n(f[1],v):v,j=n("sideBar.background",n("panel.background",a.colors.surface.muted)),h=n("descriptionForeground",n("input.placeholderForeground",a.colors.surface.mutedForeground)),w=n("textBlockQuote.background",j),b=a.colors.surface.overlay,k=n("button.background",n("textLink.foreground",a.colors.primary.base)),m=n("button.hoverBackground",k),I=t.colors["button.background"]?n("button.foreground",Us(k,l)):Us(k,l),E=$s(k,.5),N=[t.kind==="high-contrast"?n("contrastBorder",""):"",n("widget.border",""),n("input.border",""),n("panel.border",""),n("sideBar.border",""),n("editorWidget.border",""),n("contrastBorder","")].find(pe=>pe&&i(pe))||$s(u,e?.25:.2),x=n("toolbar.hoverBackground",n("list.hoverBackground",a.colors.interactive.hover)),y=n("toolbar.activeBackground",x),T=[["list.activeSelectionBackground","list.activeSelectionForeground"],["menu.selectionBackground","menu.selectionForeground"],["editor.selectionBackground","editor.selectionForeground"]].filter(([pe])=>t.colors[pe]),P=T.find(([pe])=>[l,j,d].every(Ie=>{const Te=qs(n(pe,""),Ie,l);return Te===null||Te>1.01}))??T[0],D=P?n(P[0],a.colors.interactive.selection):a.colors.interactive.selection,$=P?n(P[1],u):u,_=n("focusBorder",n("inputOption.activeBorder",k)),C=_,R=n("editorCursor.foreground",a.colors.interactive.cursor),V=n("editorError.foreground",n("testing.iconFailed",a.colors.status.error)),U=r("editorError.background",$s(V,e?.16:.12)),W=n("problemsWarningIcon.foreground",n("notificationsWarningIcon.foreground",n("editorWarning.foreground",a.colors.status.warning))),te=r("editorWarning.background",$s(W,e?.16:.12)),O=n("testing.iconPassed",n("gitDecoration.addedResourceForeground",a.colors.status.success)),ie=$s(O,e?.16:.12),K=n("problemsInfoIcon.foreground",n("editorInfo.foreground",a.colors.status.info)),q=r("editorInfo.background",$s(K,e?.16:.12)),B=n("editorLineNumber.foreground",h),L=n("textPreformat.foreground",n("terminal.ansiGreen",a.colors.syntax.base.string)),X=n("terminal.ansiBlue",k),G=n("terminal.ansiYellow",a.colors.syntax.base.number),Z=n("terminal.ansiCyan",a.colors.syntax.base.function),le=n("terminal.ansiMagenta",u),oe=n("terminal.ansiYellow",a.colors.syntax.base.type),he=n("chat.requestBorder",N),ee=n("diffEditor.insertedLineBackground",n("diffEditor.insertedTextBackground",ie)),re=n("diffEditor.removedLineBackground",n("diffEditor.removedTextBackground",U)),de=n("chat.linesAddedForeground",n("gitDecoration.addedResourceForeground",O)),ke=n("chat.linesRemovedForeground",n("gitDecoration.deletedResourceForeground",V)),ue=n("gitDecoration.modifiedResourceForeground",K),xe=n("chat.requestBubbleBackground",n("chat.requestBackground",d));return{...a,metadata:{...a.metadata,id:"vscode-auto",name:"VS Code Theme",description:"Mirrors your current VS Code color theme",author:"VS Code",version:"1.0.0",variant:e?"dark":"light",tags:["vscode","auto"]},colors:{...a.colors,primary:{base:k,hover:m,active:m,foreground:I,muted:E},surface:{background:l,foreground:u,muted:j,mutedForeground:h,elevated:d,elevatedForeground:p,overlay:b,subtle:w},interactive:{border:N,borderHover:n("toolbar.hoverOutline",N),borderFocus:_,selection:D,selectionForeground:$,focus:_,focusRing:C,cursor:R,hover:x,active:y},status:{error:V,errorForeground:Us(V,l),errorBackground:U,errorBorder:$s(V,e?.45:.35),warning:W,warningForeground:Us(W,l),warningBackground:te,warningBorder:$s(W,e?.45:.35),success:O,successForeground:Us(O,l),successBackground:ie,successBorder:$s(O,e?.45:.35),info:K,infoForeground:Us(K,l),infoBackground:q,infoBorder:$s(K,e?.45:.35)},syntax:{tokens:{},highlights:{diffAdded:de,diffAddedBackground:ee,diffRemoved:ke,diffRemovedBackground:re,diffModified:ue,diffModifiedBackground:$s(ue,e?.16:.12),lineNumber:n("editorLineNumber.foreground",h),lineNumberActive:n("editorLineNumber.activeForeground",u)},base:{background:n("editor.background",l),foreground:n("editor.foreground",u),comment:B,keyword:X,string:L,number:G,function:Z,variable:le,type:oe,operator:k}},tools:{border:he,icon:n("icon.foreground",h),title:u,description:$s(h,.8),edit:{added:de,addedBackground:ee,removed:ke,removedBackground:re,modified:ue,modifiedBackground:$s(ue,e?.16:.12),lineNumber:B}},chat:{background:l,userMessage:u,userMessageBackground:xe,assistantMessage:u,assistantMessageBackground:l,timestamp:h,divider:N,typing:n("chat.thinkingShimmer",h),avatarBackground:n("chat.avatarBackground",l),avatarForeground:n("chat.avatarForeground",u),slashCommandBackground:n("chat.slashCommandBackground",k),slashCommandForeground:n("chat.slashCommandForeground",I),inputWorkingBorderColor1:n("chat.inputWorkingBorderColor1",k),inputWorkingBorderColor2:n("chat.inputWorkingBorderColor2",m),inputWorkingBorderColor3:n("chat.inputWorkingBorderColor3",E)},markdown:{link:n("textLink.foreground",k),linkHover:n("textLink.activeForeground",m),inlineCode:n("textPreformat.foreground",L),inlineCodeBackground:n("textPreformat.background",n("editor.background",l)),blockquote:u,blockquoteBackground:n("textBlockQuote.background","transparent"),blockquoteBorder:n("textBlockQuote.border",N),listMarker:$s(k,.6)}}}},Nr=.075;function jx(t,e,a){const{surface:n,primary:i,status:r,interactive:l}=t.colors,u=n.background,c=t.metadata.variant==="dark",f=Us(n.muted,u),d=[u,n.muted,n.elevated,As(l.selection,n.muted,1,u)].filter(k=>Us(k,u)===f),v=k=>d.reduce((m,I)=>Yn(m,I,u),k),p=k=>[u,n.muted].every(m=>(qs(k,m,u)??0)>=3),j=[e["button.background"],e["textLink.foreground"],e["activityBarBadge.background"],e["list.highlightForeground"],e.focusBorder,e["inputOption.activeBorder"],a.function,a.keyword].filter(k=>k!==void 0),h=v(j.find(p)??i.base);h!==i.base&&(i.base=h,i.foreground=Us(h,u),i.hover=As(n.foreground,h,.08,u),i.active=As(n.foreground,h,.16,u),i.muted=Zn(h,.5),!e.focusBorder&&!e["inputOption.activeBorder"]&&(l.focus=h,l.focusRing=h,l.borderFocus=h),t.colors.markdown&&(e["textLink.foreground"]||(t.colors.markdown.link=h),e["textLink.activeForeground"]||(t.colors.markdown.linkHover=i.hover),t.colors.markdown.listMarker=Zn(h,.6))),d.some(k=>(qs(l.focusRing,k,u)??0)<1.1)&&(l.focus=i.base,l.focusRing=i.base,l.borderFocus=i.base);const w=(k,m,I)=>d.every(E=>(bo(k,m,E,u)??0)>=I);let b=v(r.info);if(!w(b,i.base,Nr)){const k=E=>w(E,i.base,Nr)&&[r.error,r.warning,r.success].every(A=>w(E,A,.1));let I=[e["notificationsInfoIcon.foreground"],e["editorInfo.foreground"],e["terminal.ansiCyan"],e["terminal.ansiBlue"],e["terminal.ansiMagenta"],e["textLink.foreground"],a.function,a.type].filter(E=>E!==void 0).map(v).find(k);if(!I){const E=As(b,u,1,u),N=[E,v(As(E,u,.5,u))].flatMap(x=>[.12,.18].flatMap(y=>[0,60,-60,90,-90,120,-120,180].map(F=>v($d(x,F,y)))));if(I=N.find(k),!I){const x=y=>Math.min(...[r.error,r.warning,r.success].map(F=>bo(y,F,n.muted,u)??0));I=N.filter(y=>w(y,i.base,Nr)).sort((y,F)=>x(F)-x(y))[0]}}I&&(b=I)}if(b!==r.info&&(r.info=b,r.infoForeground=Us(b,u),r.infoBackground=Zn(b,c?.16:.12),r.infoBorder=Zn(b,c?.45:.35)),t.colors.chat){const k=t.colors.chat.userMessageBackground??n.elevated;if((qs(k,u,u)??1)<1.1){const m=As(k,u,1,u);let E=(qs(m,"#000000")??1)<(qs(u,"#000000")??1)?"#000000":"#ffffff",A=m;((qs(E,u,u)??1)<1.1||(qs(m,u,u)??1)<1.01)&&(A=u,E=n.foreground);let N=0,x=1;for(let F=0;F<16;F++){const T=(N+x)/2,P=As(E,A,T,u);(qs(P,u,u)??1)>=1.1?x=T:N=T}const y=As(E,A,x,u);(qs(n.foreground,y,u)??0)>=4.5&&(t.colors.chat.userMessageBackground=y)}}}const Bi=as().regex(/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i),lo=on({foreground:Bi.optional()}),_c=on({scope:Rr([as(),ii(as())]).optional(),settings:lo}),wx=on({name:as().trim().min(1).max(160).optional(),author:as().max(160).optional(),description:as().max(1024).optional(),type:to(["light","dark","hc","hc-black","hc-light"]).optional(),include:as().optional(),colors:Mr(as(),Bi.nullable()).default({}),tokenColors:Rr([ii(_c),as()]).optional(),semanticHighlighting:eo().optional(),semanticTokenColors:Mr(as(),Rr([Bi,lo])).optional()});function kx(t){return t.flatMap(e=>(Array.isArray(e.scope)?e.scope:[e.scope??""]).flatMap(n=>n.split(",").map(i=>({scope:i.trim(),color:e.settings.foreground}))))}function Nx(t,e){for(const a of e){let n,i=-1;for(const r of t)!r.color||!r.scope||(a===r.scope||a.startsWith(`${r.scope}.`))&&r.scope.length>=i&&(n=r.color,i=r.scope.length);if(n)return n}}function Sx(t,e){for(const a of e.length?[...e,"*"]:e){const n=t[a];if(n===void 0)continue;const i=Bi.safeParse(n);if(i.success)return i.data;const r=lo.safeParse(n);if(r.success&&r.data.foreground)return r.data.foreground}}function Cx(t){return/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/.test(t)?t.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):t}function Ix(t,e,a,n){const i=Us(a,a);if(e.some(c=>Us(c,a)!==i))return t;let r=t;for(const c of e)r=Yn(r,c,a);let l=0,u=1;for(let c=0;c<16;c++){const f=(l+u)/2,d=Zn(r,f);e.every(v=>(qs(d,v,a)??0)>=n)?u=f:l=f}return Zn(r,u)}function $c(t,e){if(new TextEncoder().encode(t).byteLength>pc)throw new Xn("size");let a;try{a=wx.parse(JSON.parse(mp(t.replace(/^\uFEFF/,""),{trailingCommas:!0})))}catch{throw new Xn("invalid")}const n=ii(_c).safeParse(a.tokenColors??[]);if(a.include||!n.success)throw new Xn("include");const i={};for(const[F,T]of Object.entries(a.colors))T!==null&&(i[F]=T);const r={...i},l=i["editor.background"];if(!l)throw new Xn("background");const u=a.type?["dark","hc","hc-black"].includes(a.type):Us(l,"#ffffff")==="#ffffff",c=u?"dark":"light",f=As(l,u?"#000000":"#ffffff",1),d=kx(n.data),v=n.data.filter(F=>!F.scope&&F.settings.foreground).at(-1)?.settings.foreground,p=i["editor.foreground"]??v??i.foreground??Us(f,f),j=i["chat.list.background"]??f,h=i["interactive-session.foreground"]??i.foreground??p;i["editor.background"]=f,i["editor.foreground"]=p,i.foreground??=h,i["sideBar.background"]??=i["panel.background"]??As(h,j,.03,j),!i["editorWidget.background"]&&!i["dropdown.background"]&&!i["input.background"]&&(i["editorWidget.background"]=As(h,j,.04,j),i["editorWidget.foreground"]=Yn(h,i["editorWidget.background"],j)),i.descriptionForeground??=Yn(As(h,j,.6,j),j),i["widget.border"]??=i["input.border"]??i["panel.border"]??As(h,j,.15,j),i["toolbar.hoverBackground"]??=i["list.hoverBackground"]??As(h,j,.08,j),i["toolbar.activeBackground"]??=As(h,j,.12,j),!i["list.activeSelectionBackground"]&&!i["editor.selectionBackground"]&&(i["list.activeSelectionBackground"]=As(h,j,.16,j),i["list.activeSelectionForeground"]=Yn(h,i["list.activeSelectionBackground"],j)),i["button.background"]||(i["button.background"]=i["textLink.foreground"]??i.focusBorder??h,i["button.foreground"]=Us(i["button.background"],j)),i.focusBorder??=i["button.background"],i["editorCursor.foreground"]??=p;const w=a.type?.startsWith("hc")??!1;w&&i.contrastBorder&&(i["widget.border"]=i.contrastBorder);const k=yx({kind:u&&w?"high-contrast":c,colors:i});if(w)k.colors.interactive.focusRing=i.focusBorder;else{const{surface:F,interactive:T}=k.colors,P=Ix(T.border,[F.background,F.muted,F.elevated],F.background,u?1.15:1.2);T.border=P,i["toolbar.hoverOutline"]||(T.borderHover=P),k.colors.tools&&!i["chat.requestBorder"]&&(k.colors.tools.border=P),k.colors.chat&&(k.colors.chat.divider=P),k.colors.markdown&&!i["textBlockQuote.border"]&&(k.colors.markdown.blockquoteBorder=P)}const m=a.semanticHighlighting===!1?{}:a.semanticTokenColors??{},I=(F,T,P)=>Sx(m,F)??Nx(d,T)??P,E={background:f,foreground:p,comment:I(["comment"],["comment","comment.line","comment.block"],Yn(As(p,f,.6,f),f)),keyword:I(["keyword"],["keyword","storage","keyword.control","storage.type"],p),string:I(["string"],["string","string.quoted","string.template"],p),number:I(["number"],["constant.numeric"],p),function:I(["function"],["entity.name.function","support.function"],p),variable:I(["variable"],["variable.other.readwrite","variable"],p),type:I(["type"],["entity.name.type","support.type","support.class"],p),operator:I(["operator"],["keyword.operator"],p)},A=I(["class"],["entity.name.type.class","entity.name.class"],E.type),N=I(["property"],["variable.other.property","support.type.property-name"],E.variable),x={base:E,tokens:{className:A,interface:I(["interface"],["entity.name.type.interface"],E.type),enum:I(["enum"],["entity.name.type.enum"],A),method:I(["method"],["entity.name.function.method"],E.function),variableProperty:N,parameter:I(["parameter"],["variable.parameter"],E.variable),constant:I(["variable.readonly","*.readonly","enumMember"],["variable.other.constant","constant.other"],E.number),boolean:I([],["constant.language.boolean","constant.language"],E.number),punctuation:I([],["punctuation","punctuation.separator"],E.operator),stringEscape:I([],["constant.character.escape"],E.string),commentDoc:I([],["comment.block.documentation","comment.documentation"],E.comment),keywordImport:I([],["keyword.control.import","keyword.import"],E.keyword),tag:I([],["entity.name.tag"],E.keyword),tagAttribute:I([],["entity.other.attribute-name"],N)},highlights:k.colors.syntax.highlights},y=Cx(a.name??(e.replace(/\.(jsonc?|code-theme)$/i,"").replace(/[-_]color[-_]theme$/i,"").trim().slice(0,160)||"VS Code"));return jx(k,r,E),Bd({metadata:{id:`vscode-import-${c}`,name:y,variant:c,author:a.author,description:a.description??"",version:"1.0.0",tags:["imported","vscode"]},colors:{...k.colors,syntax:x,pr:{open:k.colors.status.success,draft:k.colors.surface.mutedForeground,blocked:k.colors.status.warning,merged:A,closed:k.colors.status.error}}})}const Px=on({namespace:as(),name:as(),version:as(),label:as(),icon:as().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&["open-vsx.org","openvsx.eclipsecontent.org"].includes(e.hostname)}).nullable()});async function Ax(t,e){const a=await xt("/api/config/themes/catalog/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t}),signal:e});if(!a.ok)throw new Error("catalog");return on({items:ii(Px).max(24)}).parse(await a.json()).items}async function Tx(t,e){const a=await xt("/api/config/themes/catalog/package",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:e});if(!a.ok)throw new Error("catalog");const{items:n}=on({items:ii(on({path:as(),name:as(),text:as(),error:eo()})).max(40)}).parse(await a.json());return n.map((i,r)=>{const l=`${r}:${i.path}`;try{if(i.error)throw new Error("invalid");const u=$c(i.text,i.path);return u.metadata.name=i.name,u.metadata.author=t.namespace,{status:"ready",key:l,name:i.name,definition:u,theme:Vd(u)}}catch{return{status:"invalid",key:l,name:i.name}}})}function Ex(t){const e=dt.c(3),{extension:a}=t,[n,i]=o.useState(!1);let r;return e[0]!==a.icon||e[1]!==n?(r=a.icon&&!n?s.jsx("img",{src:a.icon,alt:"",referrerPolicy:"no-referrer",loading:"lazy",className:"size-9 shrink-0 rounded object-contain",onError:()=>i(!0)}):s.jsx(z,{name:"palette",className:"size-9 shrink-0 text-muted-foreground"}),e[0]=a.icon,e[1]=n,e[2]=r):r=e[2],r}function Dx(t){const e=dt.c(93),{pickFile:a,fileBusy:n,onClose:i}=t,{t:r}=et(),l=ce(Fx),{isMobile:u}=ua(),c=l||u,{importTheme:f}=La(),[d,v]=o.useState("");let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p={step:"search",status:"idle",results:[]},e[0]=p):p=e[0];const[j,h]=o.useState(p);let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=new Set,e[1]=w):w=e[1];const[b,k]=o.useState(w);let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[2]=m):m=e[2];const[I,E]=o.useState(m),[A,N]=o.useState(!1),[x,y]=o.useState(null),F=o.useRef(null);let T,P;e[3]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const L=new AbortController;F.current=L;const X=Hi(()=>L.abort());return()=>{X(),L.abort()}},P=[],e[3]=T,e[4]=P):(T=e[3],P=e[4]),o.useEffect(T,P);let D,$;e[5]!==d||e[6]!==j.step?(D=()=>{if(j.step!=="search")return;const L=new AbortController,X=d.trim(),G=setTimeout(async()=>{if(!X){h({step:"search",status:"idle",results:[]});return}h({step:"search",status:"loading",results:[]});try{const Z=await Ax(X,L.signal);L.signal.aborted||h({step:"search",status:"ready",results:Z})}catch{L.signal.aborted||h({step:"search",status:"error",results:[]})}},350);return()=>{clearTimeout(G),L.abort()}},$=[d,j.step],e[5]=d,e[6]=j.step,e[7]=D,e[8]=$):(D=e[7],$=e[8]),o.useEffect(D,$);let _,C;if(e[9]!==n||e[10]!==f||e[11]!==c||e[12]!==a||e[13]!==d||e[14]!==x||e[15]!==I||e[16]!==A||e[17]!==b||e[18]!==j.extension||e[19]!==j.results||e[20]!==j.status||e[21]!==j.step||e[22]!==j.variants||e[23]!==r){const L=async ue=>{const xe=F.current?.signal;if(xe){h({step:"package",status:"loading",extension:ue}),E(new Set),y(null),k(new Set);try{const pe=await Tx(ue,xe);xe.aborted||h({step:"variants",extension:ue,variants:pe})}catch{xe.aborted||h({step:"package",status:"error",extension:ue})}}};let X;e[26]!==f||e[27]!==I||e[28]!==A||e[29]!==b||e[30]!==j.step||e[31]!==j.variants||e[32]!==r?(X=async()=>{if(j.step!=="variants"||A)return;const ue=F.current?.signal;if(!ue)return;N(!0),y(null);let xe=!1;for(const pe of j.variants){if(ue.aborted)break;if(!(pe.status!=="ready"||!b.has(pe.key)||I.has(pe.key)))try{if(await f(pe.definition,{activate:!1}),ue.aborted)break;E(Ie=>new Set(Ie).add(pe.key)),k(Ie=>{const Te=new Set(Ie);return Te.delete(pe.key),Te})}catch{xe=!0}}ue.aborted||(N(!1),y(xe?"partial":null),xe?Ea.error(r("settings.themeImport.partialError")):Ea.success(r("settings.themeImport.complete")))},e[26]=f,e[27]=I,e[28]=A,e[29]=b,e[30]=j.step,e[31]=j.variants,e[32]=r,e[33]=X):X=e[33];const G=X;let Z,le;e[34]!==I||e[35]!==b||e[36]!==j.step||e[37]!==j.variants?(Z=j.step==="variants"?j.variants.filter(ue=>ue.status==="ready"&&!I.has(ue.key)):[],le=Z.length>0&&Z.every(ue=>b.has(ue.key)),e[34]=I,e[35]=b,e[36]=j.step,e[37]=j.variants,e[38]=Z,e[39]=le):(Z=e[38],le=e[39]);const oe=le;let he;e[40]!==n||e[41]!==G||e[42]!==A||e[43]!==b||e[44]!==j.step||e[45]!==r?(he=j.step==="variants"&&s.jsx(H,{disabled:!b.size||A||n,onClick:()=>{G()},children:r(A?"settings.themeImport.busy":"settings.themeImport.importSelected")}),e[40]=n,e[41]=G,e[42]=A,e[43]=b,e[44]=j.step,e[45]=r,e[46]=he):he=e[46];const ee=A||n;let re;e[47]!==r?(re=r("settings.themeImport.chooseFile"),e[47]=r,e[48]=re):re=e[48];let de;e[49]!==a||e[50]!==ee||e[51]!==re?(de=s.jsx(H,{variant:"outline",className:"self-start",disabled:ee,onClick:a,children:re}),e[49]=a,e[50]=ee,e[51]=re,e[52]=de):de=e[52];let ke;e[53]!==he||e[54]!==de?(ke=s.jsxs(s.Fragment,{children:[he,de]}),e[53]=he,e[54]=de,e[55]=ke):ke=e[55],_=ke,C=s.jsx(s.Fragment,{children:j.step==="search"?s.jsxs(s.Fragment,{children:[s.jsx(He,{autoFocus:!0,"aria-label":r("settings.themeImport.search"),placeholder:r("settings.themeImport.search"),value:d,maxLength:160,onChange:ue=>v(ue.target.value)}),s.jsxs("div",{className:c?"space-y-1":"max-h-[45dvh] overflow-y-auto space-y-1","aria-live":"polite",children:[j.status==="loading"&&s.jsx("p",{className:"text-muted-foreground",children:r("common.loading")}),j.status==="error"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:r("settings.themeImport.catalogError")}),j.status==="ready"&&!j.results.length&&s.jsx("p",{className:"text-muted-foreground",children:r("settings.themeImport.empty")}),j.results.map(ue=>s.jsxs(H,{variant:"ghost",className:"h-auto w-full justify-start py-2 text-left",onClick:()=>{L(ue)},children:[s.jsx(Ex,{extension:ue}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"block truncate",children:ue.label}),s.jsx("span",{className:"block truncate typography-meta text-muted-foreground",children:ue.namespace})]})]},`${ue.namespace}.${ue.name}`))]})]}):s.jsxs(s.Fragment,{children:[s.jsxs(H,{variant:"ghost",size:"sm",className:"justify-start",disabled:A||j.step==="package"&&j.status==="loading",onClick:()=>h({step:"search",status:"idle",results:[]}),children:[s.jsx(z,{name:"arrow-left",className:"size-4"}),r("settings.themeImport.back")]}),s.jsx("p",{className:"typography-ui-label",children:j.extension.label}),x==="partial"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:r("settings.themeImport.partialError")}),j.step==="package"?j.status==="loading"?s.jsx("p",{role:"status",children:r("common.loading")}):s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:r("settings.themeImport.catalogError")}):s.jsxs(s.Fragment,{children:[j.variants.length>1&&s.jsx(H,{variant:"ghost",size:"sm",className:"self-start",disabled:A||n||!Z.length,onClick:()=>k(oe?new Set:new Set(Z.map(Rx))),children:r(oe?"settings.themeImport.deselectAll":"settings.themeImport.selectAll")}),s.jsx("div",{className:c?"space-y-2":"max-h-[45dvh] overflow-y-auto space-y-2",children:j.variants.map(ue=>s.jsxs("div",{className:"flex items-center gap-3",children:[ue.status==="ready"&&s.jsxs("div",{"aria-hidden":"true",className:"flex w-20 shrink-0 items-center gap-2 rounded px-2 py-3",style:{backgroundColor:ue.theme.colors.surface.background,color:ue.theme.colors.surface.foreground},children:[s.jsx("span",{children:"Aa"}),s.jsx("span",{className:"space-y-1",children:[ue.theme.colors.syntax.base.keyword,ue.theme.colors.syntax.base.string,ue.theme.colors.syntax.base.function].map(Mx)})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[I.has(ue.key)?s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsx(z,{name:"check",className:"size-4 shrink-0 text-[var(--status-success-text)]"}),s.jsx("span",{className:"typography-ui-label",children:ue.name})]}):s.jsx(mt,{checked:b.has(ue.key),disabled:ue.status!=="ready"||A||n,label:ue.name,onChange:xe=>k(pe=>{const Ie=new Set(pe);return xe?Ie.add(ue.key):Ie.delete(ue.key),Ie})}),s.jsx("p",{className:I.has(ue.key)?"typography-meta font-medium text-[var(--status-success-text)]":"typography-meta text-muted-foreground",children:ue.status!=="ready"?r("settings.themeImport.error.invalid"):I.has(ue.key)?r("settings.themeImport.installed"):r(ue.theme.metadata.variant==="dark"?"settings.openchamber.visual.option.themeMode.dark":"settings.openchamber.visual.option.themeMode.light")})]})]},ue.key))})]})]})}),e[9]=n,e[10]=f,e[11]=c,e[12]=a,e[13]=d,e[14]=x,e[15]=I,e[16]=A,e[17]=b,e[18]=j.extension,e[19]=j.results,e[20]=j.status,e[21]=j.step,e[22]=j.variants,e[23]=r,e[24]=_,e[25]=C}else _=e[24],C=e[25];const R=C;if(c){let L;e[56]!==r?(L=r("settings.themeImport.catalogTitle"),e[56]=r,e[57]=L):L=e[57];let X;e[58]!==_?(X=s.jsx("div",{className:"flex flex-col gap-2",children:_}),e[58]=_,e[59]=X):X=e[59];let G;e[60]!==r?(G=r("settings.themeImport.catalogHint"),e[60]=r,e[61]=G):G=e[61];let Z;e[62]!==G?(Z=s.jsx("p",{className:"typography-meta text-muted-foreground",children:G}),e[62]=G,e[63]=Z):Z=e[63];let le;e[64]!==R||e[65]!==Z?(le=s.jsxs("div",{className:"flex flex-col gap-4 px-1",children:[Z,R]}),e[64]=R,e[65]=Z,e[66]=le):le=e[66];let oe;return e[67]!==i||e[68]!==X||e[69]!==le||e[70]!==L?(oe=s.jsx(Hd,{open:!0,title:L,onClose:i,footer:X,children:le}),e[67]=i,e[68]=X,e[69]=le,e[70]=L,e[71]=oe):oe=e[71],oe}let V;e[72]!==i?(V=L=>{L||i()},e[72]=i,e[73]=V):V=e[73];let U;e[74]===Symbol.for("react.memo_cache_sentinel")?(U={forceRender:!0},e[74]=U):U=e[74];let W;e[75]!==r?(W=r("settings.themeImport.catalogTitle"),e[75]=r,e[76]=W):W=e[76];let te;e[77]!==W?(te=s.jsx(Bt,{children:W}),e[77]=W,e[78]=te):te=e[78];let O;e[79]!==r?(O=r("settings.themeImport.catalogHint"),e[79]=r,e[80]=O):O=e[80];let ie;e[81]!==O?(ie=s.jsx(Vt,{children:O}),e[81]=O,e[82]=ie):ie=e[82];let K;e[83]!==te||e[84]!==ie?(K=s.jsxs($t,{children:[te,ie]}),e[83]=te,e[84]=ie,e[85]=K):K=e[85];let q;e[86]!==_||e[87]!==R||e[88]!==K?(q=s.jsxs(Ut,{className:"max-w-lg",backdropProps:U,children:[K,R,_]}),e[86]=_,e[87]=R,e[88]=K,e[89]=q):q=e[89];let B;return e[90]!==q||e[91]!==V?(B=s.jsx(zt,{open:!0,onOpenChange:V,children:q}),e[90]=q,e[91]=V,e[92]=B):B=e[92],B}function Mx(t,e){return s.jsx("span",{className:"block h-1 w-5 rounded",style:{backgroundColor:t}},e)}function Rx(t){return t.key}function Fx(t){return t.isMobile}function Ox(){const{t}=et(),{importTheme:e,customThemesLoading:a}=La(),n=Yr(),[i,r]=o.useState(!1),l=o.useCallback(()=>r(!1),[]),u=o.useRef(null),c=o.useRef(0),f=o.useRef(null),[d,v]=o.useState(!1);o.useEffect(()=>Hi(()=>{c.current+=1,r(!1)}),[]);const p=async(w,b)=>{v(!0);try{if(w.size>pc)throw new Xn("size");const k=await w.text();if(b.key!==Oa()||b.generation!==c.current)throw new Xn("connection");const m=await e($c(k,w.name));Ea.success(t("settings.themeImport.success",{name:m.metadata.name})),r(!1)}catch(k){const m=k instanceof Xn?k.code:"invalid";Ea.error(t(`settings.themeImport.error.${m}`))}finally{v(!1)}},j=async()=>{if(d)return;const w={key:Oa(),generation:c.current};if(f.current=w,!n.themeFiles){u.current?.click();return}v(!0);try{const b=await n.themeFiles.pick();if(b?.status==="picked"){if(b.file){const k=b.file;await p({name:k.name,size:k.size,text:async()=>k.text},w)}return}u.current?.click()}catch{Ea.error(t("settings.themeImport.error.invalid"))}finally{v(!1)}},h=async w=>{const b=w.target.files?.[0];w.target.value="",b&&!d&&f.current&&await p(b,f.current)};return s.jsxs("div",{className:"flex items-center gap-2","data-settings-item":"appearance.import-theme",children:[s.jsxs(H,{variant:"outline",size:"sm",disabled:d||a,onClick:()=>r(!0),children:[s.jsx(z,{name:d?"loader":"add",className:d?"size-3.5 animate-spin":"size-3.5"}),t(d?"settings.themeImport.busy":"settings.themeImport.action")]}),s.jsx(Yt,{children:t("settings.themeImport.catalogHint")}),s.jsx("input",{ref:u,type:"file",accept:".json,.jsonc",className:"hidden","aria-label":t("settings.themeImport.action"),onChange:h}),i&&s.jsx(Dx,{pickFile:()=>{j()},fileBusy:d,onClose:l})]})}function Al({id:t,label:e}){const{deleteImportedTheme:a,customThemeIds:n}=La(),{t:i}=et(),[r,l]=o.useState(!1),u=o.useRef(null),c=o.useRef(null),f=async()=>{if(r)return;l(!0);const d=c.current?.closest('[data-slot="select-content"]');try{await a(t),requestAnimationFrame(()=>{d?.isConnected&&document.activeElement===document.body&&d.querySelector('[role="option"][aria-selected="true"]')?.focus()})}catch{Ea.error(i("settings.themeImport.deleteError"))}finally{l(!1)}};return n.includes(t)?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ut,{ref:u,value:t,className:"min-w-0 flex-1","aria-keyshortcuts":"Delete ArrowRight",onKeyDown:d=>{d.key!=="ArrowRight"&&d.key!=="Delete"||(d.preventDefault(),d.stopPropagation(),d.key==="ArrowRight"?c.current?.focus():f())},children:e}),s.jsx(H,{ref:c,variant:"ghost",size:"icon",disabled:r,"aria-label":i("settings.themeImport.delete",{name:e}),onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&d.stopPropagation(),d.key==="ArrowLeft"&&(d.preventDefault(),d.stopPropagation(),u.current?.focus())},onClick:d=>{d.stopPropagation(),f()},children:s.jsx(z,{name:r?"loader":"delete-bin",className:r?"size-4 animate-spin":"size-4"})})]}):s.jsx(ut,{value:t,children:e})}const Lx=[{value:"system",labelKey:"settings.openchamber.visual.option.themeMode.system",descriptionKey:"settings.openchamber.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.openchamber.visual.option.themeMode.light",descriptionKey:"settings.openchamber.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.openchamber.visual.option.themeMode.dark",descriptionKey:"settings.openchamber.visual.option.themeMode.dark.description"}],Kx=[{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"}],zx=[{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"}],Wa="OpenChamber - AI Coding Assistant",Tl=[{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"}],El=[{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"}],Sr=t=>t==="portrait"||t==="landscape"?t:"system",Ux=[{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"}],_x=[{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"}],Dl=[{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"}],$x=[{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"}],Ml=[{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"}],Rl=[{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"}],Bx=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Vx=[{id:"ask",labelKey:"settings.openchamber.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.openchamber.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.openchamber.visual.option.largeTextPaste.inline.label"}],Hx=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],qx=t=>t==="markdown"?"markdown":"plain",Gx=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],Wx=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],qi=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=et(),l=o.useCallback(g=>r(g),[r]),{isMobile:u}=ua(),{terminal:c}=Yr(),{browserTab:f}=Wu(),d=Au(),v=ce(g=>g.showReasoningTraces),p=ce(g=>g.sessionRecapEnabled),j=ce(g=>g.sessionSuggestionEnabled),h=ce(g=>g.setSessionRecapEnabled),w=ce(g=>g.setSessionSuggestionEnabled),b=ce(g=>g.sessionGoalEnabled),k=ce(g=>g.setSessionGoalEnabled),m=ce(g=>g.sessionGoalDefaultBudgetEnabled),I=ce(g=>g.setSessionGoalDefaultBudgetEnabled),E=ce(g=>g.sessionGoalDefaultBudget),A=ce(g=>g.setSessionGoalDefaultBudget),N=ce(g=>g.setShowReasoningTraces),x=ce(g=>g.streamingAutoFollowEnabled),y=ce(g=>g.setStreamingAutoFollowEnabled),F=ce(g=>g.collapsibleThinkingBlocks),T=ce(g=>g.setCollapsibleThinkingBlocks),P=ce(g=>g.mermaidRenderingMode),D=ce(g=>g.setMermaidRenderingMode),$=ce(g=>g.userMessageRenderingMode),_=ce(g=>g.setUserMessageRenderingMode),C=ce(g=>g.collapsibleUserMessages),R=ce(g=>g.setCollapsibleUserMessages),V=ce(g=>g.stickyUserHeader),U=ce(g=>g.promptNavigatorEnabled),W=ce(g=>g.setStickyUserHeader),te=ce(g=>g.setPromptNavigatorEnabled),O=ce(g=>g.autoSaveEnabled),ie=ce(g=>g.setAutoSaveEnabled),K=ce(g=>g.wideChatLayoutEnabled),q=ce(g=>g.setWideChatLayoutEnabled),B=ce(g=>g.codeBlockLineWrap),L=ce(g=>g.setCodeBlockLineWrap),X=ce(g=>g.chatRenderMode),G=ce(g=>g.setChatRenderMode),Z=ce(g=>g.activityRenderMode),le=ce(g=>g.setActivityRenderMode),oe=ce(g=>g.fontSize),he=ce(g=>g.setFontSize),ee=ce(g=>g.terminalFontSize),re=ce(g=>g.setTerminalFontSize),de=ce(g=>g.terminalShell),ke=ce(g=>g.setTerminalShell),ue=ce(g=>g.terminalLoginShells),xe=ce(g=>g.setTerminalLoginShells),pe=ce(g=>g.editorFontSize),Ie=ce(g=>g.setEditorFontSize),Te=ce(g=>g.uiFont),we=ce(g=>g.setUiFont),De=ce(g=>g.monoFont),_e=ce(g=>g.setMonoFont),Ve=ce(g=>g.padding),ve=ce(g=>g.setPadding),se=ce(g=>g.inputBarOffset),ae=ce(g=>g.setInputBarOffset),je=ce(g=>g.mobileKeyboardMode),Se=ce(g=>g.setMobileKeyboardMode),Ke=ce(g=>g.diffLayoutPreference),Ue=ce(g=>g.setDiffLayoutPreference),Oe=ce(g=>g.showTerminalQuickKeysOnDesktop),Re=ce(g=>g.sessionTabsEnabled),Ce=ce(g=>g.setSessionTabsEnabled),Ze=ce(g=>g.setShowTerminalQuickKeysOnDesktop),be=ce(g=>g.fileEditorKeymap),Pe=ce(g=>g.setFileEditorKeymap),Le=Po(g=>g.followUpBehavior),Xe=Po(g=>g.setFollowUpBehavior),Q=yi(g=>g.scope),Ne=yi(g=>g.entryLimit),Ae=yi(g=>g.applyScope),We=yi(g=>g.applyEntryLimit),lt=ce(g=>g.persistChatDraft),at=ce(g=>g.setPersistChatDraft),pt=ce(g=>g.inputSpellcheckEnabled),bt=ce(g=>g.setInputSpellcheckEnabled),J=ce(g=>g.largeTextPasteBehavior),qe=ce(g=>g.setLargeTextPasteBehavior),it=ce(g=>g.enterToSend),ct=ce(g=>g.setEnterToSend),gt=ce(g=>g.enterToSendConfigured),Rt=ce(g=>g.setEnterToSendConfigured),tt=gt?it:!u,ft=ce(g=>g.showToolFileIcons),jt=ce(g=>g.setShowToolFileIcons),Je=ce(g=>g.showTurnChangedFiles),St=ce(g=>g.setShowTurnChangedFiles),Fe=ce(g=>g.showExpandedBashTools),wt=ce(g=>g.setShowExpandedBashTools),Y=ce(g=>g.showExpandedEditTools),fe=ce(g=>g.setShowExpandedEditTools),Me=ce(g=>g.timeFormatPreference),Ee=ce(g=>g.setTimeFormatPreference),rt=ce(g=>g.weekStartPreference),ot=ce(g=>g.setWeekStartPreference),Ge=ce(g=>g.showSplitAssistantMessageActions),Nt=ce(g=>g.setShowSplitAssistantMessageActions),ns=ce(g=>g.allowPromptingSubagentSessions),Zt=ce(g=>g.setAllowPromptingSubagentSessions),Qe=ce(g=>g.draftStartersVisible),Be=ce(g=>g.setDraftStartersVisible),Ct=nt(g=>g.settingsMessageStreamTransport),Pt=nt(g=>g.setSettingsMessageStreamTransport),es=Ct,ts=nt(g=>g.settingsDefaultFileViewerPreview),rs=nt(g=>g.setSettingsDefaultFileViewerPreview),fs=ce(g=>g.isSettingsDialogOpen),{themeMode:Rs,setThemeMode:me,availableThemes:ht,customThemesLoading:kt,reloadCustomThemes:Xt,lightThemeId:ss,darkThemeId:Jt,setLightThemePreference:ms,setDarkThemePreference:Ns}=La(),[us,It]=o.useState(!1),Ft=o.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Wt=ce(g=>g.dockBadgeEnabled),qt=ce(g=>g.setDockBadgeEnabled),ps=ce(g=>g.alwaysShowScrollbars===!0),Fs=ce(g=>g.setAlwaysShowScrollbars),Gi=Tu(),Wi=ce(g=>g.desktopWindowControlsPosition),oi=ce(g=>g.setDesktopWindowControlsPosition),Ji=ce(g=>g.desktopWindowControlsStyle),_s=ce(g=>g.setDesktopWindowControlsStyle),[Ka,Qi]=o.useState(0),li=ce(g=>g.reportUsage),ci=ce(g=>g.setReportUsage),Yi=o.useCallback(g=>{ci(g),yt({reportUsage:g})},[ci]),Zi=o.useCallback(g=>{oi(g),yt({desktopWindowControlsPosition:g})},[oi]),Xi=o.useCallback(g=>{_s(g),yt({desktopWindowControlsStyle:g})},[_s]),di=(fs||u||ds())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!di)return;let g=null,vt=Date.now();const bs=()=>{const un=Date.now();un-vt>=420&&(Qi(Gn=>(Gn+1)%24),vt=un),g=requestAnimationFrame(bs)};(typeof document>"u"||document.visibilityState==="visible")&&(g=requestAnimationFrame(bs));const Ls=()=>{document.visibilityState==="visible"&&g===null?g=requestAnimationFrame(bs):document.visibilityState!=="visible"&&g!==null&&(cancelAnimationFrame(g),g=null)};return document.addEventListener("visibilitychange",Ls),()=>{document.removeEventListener("visibilitychange",Ls),g!==null&&cancelAnimationFrame(g)}},[di]);const Ss=o.useCallback(g=>{_(g),yt({userMessageRenderingMode:g})},[_]),en=o.useCallback(g=>{W(g),yt({stickyUserHeader:g})},[W]),pa=o.useCallback(g=>{te(g),yt({promptNavigatorEnabled:g})},[te]),Sn=o.useCallback(g=>{Be(g),yt({draftStartersVisible:g})},[Be]),Tn=o.useCallback(g=>{R(g),yt({collapsibleUserMessages:g})},[R]),po=o.useCallback(g=>{q(g),yt({wideChatLayoutEnabled:g})},[q]),ln=o.useCallback(g=>{Nt(g),yt({showSplitAssistantMessageActions:g})},[Nt]),er=o.useCallback(g=>{bt(g),yt({inputSpellcheckEnabled:g})},[bt]),$n=o.useCallback(g=>{ct(g),Rt(!0),yt({enterToSend:g,enterToSendConfigured:!0})},[ct,Rt]),ma=o.useCallback(g=>{G(g),yt({chatRenderMode:g})},[G]),Bn=o.useCallback(g=>{Pt(g),yt({messageStreamTransport:g})},[Pt]),za=o.useCallback(g=>{Ae(g),yt({inputHistoryScope:g})},[Ae]),tr=o.useCallback(g=>{const vt=Math.round(g);Eu(vt)&&(We(vt),yt({inputHistoryLimit:vt}))},[We]),gs=o.useCallback(g=>{le(g),yt({activityRenderMode:g})},[le]),sr=o.useCallback(g=>{D(g),yt({mermaidRenderingMode:g})},[D]),ga=o.useCallback(g=>{jt(g),yt({showToolFileIcons:g})},[jt]),ha=o.useCallback(g=>{St(g),yt({showTurnChangedFiles:g})},[St]),nr=o.useCallback(g=>{rs(g),yt({defaultFileViewerPreview:g}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:g}}))},[rs]),ui=o.useCallback(g=>{wt(g),yt({showExpandedBashTools:g})},[wt]),ar=o.useCallback(g=>{fe(g),yt({showExpandedEditTools:g})},[fe]),pi=o.useCallback(g=>{Ee(g),yt({timeFormatPreference:g})},[Ee]),fa=o.useCallback(g=>{ot(g),yt({weekStartPreference:g})},[ot]),Cn=o.useMemo(()=>ht.filter(g=>g.metadata.variant==="light").sort((g,vt)=>g.metadata.name.localeCompare(vt.metadata.name)),[ht]),Vn=o.useMemo(()=>ht.filter(g=>g.metadata.variant==="dark").sort((g,vt)=>g.metadata.name.localeCompare(vt.metadata.name)),[ht]),Ua=o.useMemo(()=>Cn.find(g=>g.metadata.id===ss)??Cn[0],[Cn,ss]),En=o.useMemo(()=>Vn.find(g=>g.metadata.id===Jt)??Vn[0],[Vn,Jt]),xa=o.useCallback((g,vt)=>{const bs=vt==="dark"?" Dark":" Light";return g.endsWith(bs)?g.slice(0,-bs.length):g},[]),ge=g=>t?t.includes(g):!0,hs=ds(),ba=ge("theme")&&!hs,mi=ge("windowControlsPosition")&&Gi,gi=ge("theme")||ge("timeFormat")||ge("weekStart"),hi=hs?gi:ge("theme")||mi||ge("pwaInstallName")||ge("pwaOrientation")||ge("timeFormat")||ge("weekStart"),fi=ge("fontSize")||ge("terminalFontSize")||ge("editorFontSize")||ge("spacing")||ge("scrollbars")&&!ba||ge("inputBarOffset")&&u,xi=ge("terminalQuickKeys")&&!u||(ge("terminalShell")||ge("terminalLoginShell"))&&!hs||ge("fileEditorKeymap")||ge("autoSaveEnabled")||ge("sessionTabs")&&!hs&&!u,ir=ge("mermaidRendering")||ge("sessionGoal")&&!hs||ge("userMessageRendering")||ge("chatRenderMode")||ge("messageTransport")||ge("activityRenderMode")||ge("collapsibleUserMessages")||ge("stickyUserHeader")||ge("promptNavigatorEnabled")&&!hs||ge("wideChatLayout")||ge("codeBlockLineWrap")||ge("splitAssistantMessageActions")||ge("subagentReadOnlyBanner")||ge("diffLayout")||ge("dotfiles")||ge("fileViewerPreview")||ge("reasoning")||ge("followUpBehavior")||ge("inputHistoryScope")||ge("inputHistoryLimit")||ge("persistDraft")||ge("largeTextPaste")||ge("showToolFileIcons")||ge("expandedTools")||!u&&ge("inputSpellcheck")||ge("enterToSend"),cn=ge("chatRenderMode")||ge("activityRenderMode"),Dn=ge("messageTransport"),va=ge("userMessageRendering")||ge("mermaidRendering")||ge("diffLayout")&&!hs||ge("followUpBehavior")||ge("inputHistoryScope")||ge("inputHistoryLimit"),rr=ge("sessionAssist")||ge("sessionGoal")&&!hs||ge("subagentReadOnlyBanner")||ge("collapsibleUserMessages")||ge("stickyUserHeader")||ge("promptNavigatorEnabled")&&!hs||ge("wideChatLayout")||ge("codeBlockLineWrap")||ge("splitAssistantMessageActions")||ge("dotfiles")||ge("fileViewerPreview")||ge("persistDraft")||ge("largeTextPaste")||ge("showToolFileIcons")||ge("showTurnChangedFiles")||!u&&ge("inputSpellcheck")||ge("enterToSend")||ge("reasoning")||ge("expandedTools"),S=hi||fi||xi,ne=ge("pwaInstallName")&&na()&&f&&!cs()&&!hs,ze=ge("pwaOrientation")&&na()&&!cs()&&!hs,st=ge("mobileKeyboardMode")&&na()&&!cs()&&!hs&&Du(),Lt=(ge("terminalShell")||ge("terminalLoginShell"))&&!hs,[Cs,xs]=o.useState([]),[Ws,Is]=o.useState(0);o.useEffect(()=>Hi(()=>{xs([]),Is(g=>g+1)}),[]),o.useEffect(()=>{let g=!1;if(!(!Lt||!c.listShells))return c.listShells().then(vt=>{g||xs(vt)}).catch(()=>{g||xs([])}),()=>{g=!0}},[Lt,c,Ws]);const tn=o.useMemo(()=>{const g=Cs.filter(vt=>vt.id!=="auto");return de==="auto"||g.some(vt=>vt.id===de)?g:[{id:de,name:de,supportsLogin:!1},...g]},[Cs,de]),_a=Cs.find(g=>g.id===de)?.supportsLogin===!0,Hn=ue.includes(de),$a=g=>{xe(g?[...ue.filter(vt=>vt!==de),de]:ue.filter(vt=>vt!==de))},[At,Qt]=o.useState(""),[dn,Tt]=o.useState("system"),Os=o.useMemo(()=>{const g=Ml.find(vt=>vt.id===Me);return l(g?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Me,l]),qn=o.useMemo(()=>{const g=Rl.find(vt=>vt.id===rt);return l(g?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[rt,l]),ya=o.useMemo(()=>{const g=Tl.find(vt=>vt.id===dn);return g?l(g.labelKey):void 0},[dn,l]),bi=o.useMemo(()=>{const g=El.find(vt=>vt.id===je);return g?l(g.labelKey):void 0},[je,l]),or=o.useCallback(async g=>{if(typeof window>"u")return;const vt=window,Ls=g.trim().replace(/\s+/g," ").slice(0,64);if(await yt({pwaAppName:Ls}),typeof vt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const un=vt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Ls);Qt(un);return}Qt(Ls||Wa),vt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),mo=o.useCallback(async g=>{if(typeof window>"u")return;const vt=window,bs=Sr(g);if(await yt({pwaOrientation:bs}),typeof vt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Ls=vt.__OPENCHAMBER_SET_PWA_ORIENTATION__(bs);Tt(Ls);return}Tt(bs),vt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);o.useEffect(()=>{if(typeof window>"u"||!ne&&!ze&&!st)return;let g=!1;return(async()=>{try{const bs=await Nn();if(!bs){g||Qt(Wa);return}const un=(bs.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),Gn=Sr(bs.pwaOrientation),vi=Mo(bs.mobileKeyboardMode);g||(ne&&Qt(un||Wa),ze&&Tt(Gn),st&&Se(vi))}catch{g||(ne&&Qt(Wa),ze&&Tt("system"),st&&Se("native"))}})(),()=>{g=!0}},[Se,st,ne,ze]);const lr=ge("scrollbars")?s.jsx(mt,{checked:ps,onChange:Fs,label:r("settings.openchamber.visual.field.alwaysShowScrollbars"),info:r("settings.openchamber.visual.field.alwaysShowScrollbarsHint"),settingsItem:"appearance.scrollbars"}):null;return s.jsxs("div",{className:"space-y-0",children:[hi&&s.jsxs("div",{className:"space-y-0",children:[ba&&s.jsxs($e,{title:r("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Kn,{children:[s.jsx("div",{className:nn,children:s.jsx(sn,{"aria-label":r("settings.openchamber.visual.section.colorMode"),children:Lx.map(g=>s.jsx(Qs,{selected:Rs===g.value,onSelect:()=>me(g.value),label:l(g.labelKey),ariaLabel:l(g.labelKey)},g.value))})}),s.jsxs("div",{className:nn,children:[s.jsx(Kt,{label:r("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(Et,{value:Ua?.metadata.id??"",onValueChange:ms,children:[s.jsx(Dt,{"aria-label":r("settings.openchamber.visual.field.selectLightThemeAria"),size:Gt,className:Mn,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:Ua?xa(Ua.metadata.name,"light"):void 0})}),s.jsx(Mt,{children:Cn.map(g=>s.jsx(Al,{id:g.metadata.id,label:xa(g.metadata.name,"light")},g.metadata.id))})]})}),s.jsx(Kt,{label:r("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(Et,{value:En?.metadata.id??"",onValueChange:Ns,children:[s.jsx(Dt,{"aria-label":r("settings.openchamber.visual.field.selectDarkThemeAria"),size:Gt,className:Mn,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:En?xa(En.metadata.name,"dark"):void 0})}),s.jsx(Mt,{children:Vn.map(g=>s.jsx(Al,{id:g.metadata.id,label:xa(g.metadata.name,"dark")},g.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:kt||us,onClick:()=>{const g=Date.now();It(!0),Xt().finally(()=>{const vt=Date.now()-g;if(vt<500){window.setTimeout(()=>{It(!1)},500-vt);return}It(!1)})},className:"typography-settings-link inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:[s.jsx(z,{name:"restart",className:ye("h-3.5 w-3.5",us&&"animate-spin")}),r(us?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Yt,{children:r("settings.openchamber.visual.field.themeImportInfoTooltip")})]}),s.jsx(Ox,{})]})]}),Ft&&s.jsx(Fa,{settingsItem:"appearance.dock-badge",children:s.jsx(mt,{checked:Wt,onChange:qt,label:r("settings.openchamber.visual.field.dockBadge"),info:r("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:r("settings.openchamber.visual.field.dockBadge")})}),lr&&s.jsx(Fa,{children:lr})]}),mi&&s.jsx($e,{title:r("settings.openchamber.desktopNetwork.field.windowControls"),info:r("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:ba,children:s.jsxs(Kn,{children:[s.jsx(Kt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(an,{value:Wi,options:Gx.map(g=>({value:g.id,label:l(g.labelKey)})),onChange:Zi,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Kt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(an,{value:Ji,options:Wx.map(g=>({value:g.id,label:l(g.labelKey)})),onChange:Xi,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),gi&&s.jsx($e,{title:r("settings.openchamber.visual.section.localization"),children:s.jsxs(Kn,{children:[s.jsx(Kt,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Et,{value:e,onValueChange:g=>n(g),children:[s.jsx(Dt,{"aria-label":r("settings.appearance.language.select"),size:Gt,className:Mn,children:s.jsx(_t,{children:i(e)})}),s.jsx(Mt,{children:a.map(g=>s.jsx(ut,{value:g,children:i(g)},g))})]})}),(ge("timeFormat")||ge("weekStart"))&&s.jsxs("div",{className:nn,children:[ge("timeFormat")&&s.jsx(Kt,{label:r("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Et,{value:Me,onValueChange:g=>pi(g),children:[s.jsx(Dt,{"aria-label":r("settings.openchamber.visual.field.selectTimeFormatAria"),size:Gt,className:Mn,children:s.jsx(_t,{children:Os})}),s.jsx(Mt,{children:Ml.map(g=>s.jsx(ut,{value:g.id,children:l(g.labelKey)},g.id))})]})}),ge("weekStart")&&s.jsx(Kt,{label:r("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Et,{value:rt,onValueChange:g=>fa(g),children:[s.jsx(Dt,{"aria-label":r("settings.openchamber.visual.field.selectWeekStartAria"),size:Gt,className:Mn,children:s.jsx(_t,{children:qn})}),s.jsx(Mt,{children:Rl.map(g=>s.jsx(ut,{value:g.id,children:l(g.labelKey)},g.id))})]})})]})]})}),(ne||ze||st)&&s.jsxs($e,{title:r("settings.openchamber.visual.section.appInstall"),contentClassName:nn,children:[ne&&s.jsxs(Ht,{label:r("settings.openchamber.visual.field.installAppName"),info:r("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Vs,children:[s.jsx(He,{value:At,onChange:g=>{Qt(g.target.value)},onBlur:()=>{or(At)},onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),or(At))},className:"min-w-0 flex-1",maxLength:64,"aria-label":r("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Qt(Wa),or("")},className:ys,"aria-label":r("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),ze&&s.jsxs(Ht,{label:r("settings.openchamber.visual.field.installOrientation"),description:r("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Vs,children:[s.jsxs(Et,{value:dn,onValueChange:g=>{const vt=Sr(g);Tt(vt),mo(vt)},children:[s.jsx(Dt,{"aria-label":r("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Gt,className:vo,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:ya})}),s.jsx(Mt,{children:Tl.map(g=>s.jsx(ut,{value:g.id,children:l(g.labelKey)},g.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Tt("system"),mo("system")},disabled:dn==="system",className:ys,"aria-label":r("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),st&&s.jsxs(Ht,{label:r("settings.openchamber.visual.field.mobileKeyboardMode"),info:r("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Vs,children:[s.jsxs(Et,{value:je,onValueChange:g=>{const vt=Mo(g);Se(vt),yt({mobileKeyboardMode:vt})},children:[s.jsx(Dt,{"aria-label":r("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Gt,className:vo,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:bi})}),s.jsx(Mt,{children:El.map(g=>s.jsx(ut,{value:g.id,children:l(g.labelKey)},g.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Se("native"),yt({mobileKeyboardMode:"native"})},disabled:je==="native",className:ys,"aria-label":r("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),fi&&s.jsxs($e,{title:r("settings.openchamber.visual.section.densityAndType"),contentClassName:nn,children:[ge("fontSize")&&!u||ge("terminalFontSize")?s.jsxs(Kn,{children:[ge("fontSize")&&!u&&s.jsxs(Kt,{label:r("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Et,{value:Te,onValueChange:g=>we(g),children:[s.jsx(Dt,{"aria-label":r("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Gt,className:Mn,children:s.jsx(_t,{children:Ao.find(g=>g.id===Te)?.label})}),s.jsx(Mt,{children:Ao.map(g=>s.jsx(ut,{value:g.id,children:s.jsx("span",{style:{fontFamily:g.stack},children:g.label})},g.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>we(To),disabled:Te===To,className:ys,"aria-label":r("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),ge("terminalFontSize")&&s.jsxs(Kt,{label:r("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Et,{value:De,onValueChange:g=>_e(g),children:[s.jsx(Dt,{"aria-label":r("settings.openchamber.visual.field.selectCodeFontAria"),size:Gt,className:Mn,children:s.jsx(_t,{children:Eo.find(g=>g.id===De)?.label})}),s.jsx(Mt,{children:Eo.map(g=>s.jsx(ut,{value:g.id,children:s.jsx("span",{style:{fontFamily:g.stack},children:g.label})},g.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>_e(Do),disabled:De===Do,className:ys,"aria-label":r("settings.openchamber.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,ge("fontSize")&&!u||ge("terminalFontSize")||ge("editorFontSize")?s.jsxs(Kn,{children:[ge("fontSize")&&!u&&s.jsx(Kt,{label:r("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:wa,children:[s.jsx(ws,{value:oe,onValueChange:he,min:50,max:200,step:5,className:Es,"aria-label":r("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:ka,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>he(100),disabled:oe===100,className:ys,"aria-label":r("settings.openchamber.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ge("terminalFontSize")&&s.jsx(Kt,{label:r("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:wa,children:[s.jsx(ws,{value:ee,onValueChange:re,min:9,max:52,step:1,className:Es}),s.jsx("span",{className:ka,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>re(13),disabled:ee===13,className:ys,"aria-label":r("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ge("editorFontSize")&&s.jsx(Kt,{label:r("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:wa,children:[s.jsx(ws,{value:pe,onValueChange:Ie,min:9,max:32,step:1,className:Es}),s.jsx("span",{className:ka,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ie(13),disabled:pe===13,className:ys,"aria-label":r("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,ge("spacing")||ge("inputBarOffset")&&u?s.jsxs(Kn,{children:[ge("spacing")&&s.jsx(Kt,{label:r("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:wa,children:[s.jsx(ws,{value:Ve,onValueChange:ve,min:50,max:200,step:5,className:Es}),s.jsx("span",{className:ka,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>ve(100),disabled:Ve===100,className:ys,"aria-label":r("settings.openchamber.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ge("inputBarOffset")&&u&&s.jsx(Kt,{label:r("settings.openchamber.visual.field.inputBarOffset"),info:r("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:wa,children:[s.jsx(ws,{value:se,onValueChange:ae,min:0,max:100,step:5,className:Es}),s.jsx("span",{className:ka,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>ae(0),disabled:se===0,className:ys,"aria-label":r("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!ba&&lr]}),xi&&s.jsxs($e,{title:r("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[ge("fileEditorKeymap")&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(sn,{"aria-label":r("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(g=>s.jsx(Qs,{selected:be===g,onSelect:()=>Pe(g),label:r(`settings.openchamber.visual.option.fileEditorKeymap.${g}`),ariaLabel:r(`settings.openchamber.visual.option.fileEditorKeymap.${g}`)},g))})}),s.jsxs("div",{className:js,children:[ge("autoSaveEnabled")&&s.jsx(mt,{checked:O,onChange:ie,label:r("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:r("settings.openchamber.visual.field.autoSaveEnabledAria"),info:r("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),Lt&&s.jsx(Kt,{label:r("settings.openchamber.visual.field.terminalShell"),info:r("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Et,{value:de,onValueChange:g=>{Mu(g)&&ke(g)},children:[s.jsx(Dt,{"aria-label":r("settings.openchamber.visual.field.terminalShellAria"),size:Gt,className:Mn,children:s.jsx(_t,{})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:"auto",children:r("settings.openchamber.visual.option.terminalShell.auto")}),tn.map(g=>s.jsx(ut,{value:g.id,children:g.name},g.id))]})]})}),Lt&&_a&&s.jsx(mt,{checked:Hn,onChange:$a,label:r("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:r("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),ge("terminalQuickKeys")&&!u&&s.jsx(mt,{checked:Oe,onChange:Ze,label:r("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:r("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:r("settings.openchamber.visual.field.terminalQuickKeysTooltip",{control:ia("ctrl"),alt:ia("alt")})})]}),ge("sessionTabs")&&!hs&&!u&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(mt,{checked:Re,onChange:Ce,label:r("settings.openchamber.visual.field.sessionTabs"),ariaLabel:r("settings.openchamber.visual.field.sessionTabsAria"),info:r("settings.openchamber.visual.field.sessionTabsInfo")})})]}),ir&&s.jsxs(s.Fragment,{children:[cn&&s.jsxs($e,{title:r("settings.openchamber.visual.section.chatDisplay"),divider:S,contentClassName:"space-y-6",children:[ge("chatRenderMode")&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":r("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:_x.map(g=>{const vt=X===g.id,bs=Ka%12;return s.jsxs("button",{type:"button",onClick:()=>ma(g.id),"aria-pressed":vt,className:ye("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",vt?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-border/80 hover:bg-interactive-hover"),children:[s.jsx("span",{className:ye("typography-ui-label",vt?"text-inherit":"text-muted-foreground"),children:l(g.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:g.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ls=>{const un=Ls*3+1,Gn=bs-un+1,vi=Gn<=0?0:Gn===1?42:Gn===2?68:92,td=vi>0;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",td?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${vi}%`}})]},Ls)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ls=>{const un=bs>=(Ls+1)*3;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",un?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},Ls)})})})]},g.id)})})}),ge("activityRenderMode")&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(sn,{"aria-label":r("settings.openchamber.visual.section.activityDefaultAria"),children:$x.map(g=>s.jsx(Qs,{selected:Z===g.id,onSelect:()=>gs(g.id),label:l(g.labelKey),ariaLabel:r("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(g.labelKey)})},g.id))})})]}),Dn&&s.jsxs($e,{title:r("settings.openchamber.visual.section.messageStreamTransport"),divider:cn||S,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(an,{value:es,options:Dl.map(g=>({value:g.id,label:l(g.labelKey)})),onChange:Bn,"aria-label":r("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const g=Dl.find(vt=>vt.id===es);return g?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(g.descriptionKey)}):null})()]}),va&&s.jsx($e,{title:r("settings.openchamber.visual.section.chatMessageOptions"),divider:cn||Dn||S,children:s.jsxs(Kn,{className:"lg:gap-y-6",children:[ge("userMessageRendering")&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(sn,{"aria-label":r("settings.openchamber.visual.section.userMessageRenderingAria"),children:Ux.map(g=>s.jsx(Qs,{selected:qx($)===g.id,onSelect:()=>Ss(g.id),label:l(g.labelKey),ariaLabel:r("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(g.labelKey)})},g.id))})}),ge("mermaidRendering")&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(sn,{"aria-label":r("settings.openchamber.visual.section.mermaidRenderingAria"),children:zx.map(g=>s.jsx(Qs,{selected:P===g.id,onSelect:()=>sr(g.id),label:l(g.labelKey),ariaLabel:r("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(g.labelKey)})},g.id))})}),ge("diffLayout")&&!hs&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.diffLayout"),children:s.jsx(sn,{"aria-label":r("settings.openchamber.visual.section.diffLayoutAria"),children:Kx.map(g=>s.jsx(Qs,{selected:Ke===g.id,onSelect:()=>Ue(g.id),label:l(g.labelKey),ariaLabel:r("settings.openchamber.visual.field.diffLayoutAria",{option:l(g.labelKey)})},g.id))})}),ge("followUpBehavior")&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(sn,{"aria-label":r("settings.openchamber.visual.section.followUpBehaviorAria"),children:Bx.map(g=>s.jsx(Qs,{selected:Le===g.id,onSelect:()=>Xe(g.id),label:l(g.labelKey),ariaLabel:r("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(g.labelKey)})},g.id))})}),ge("inputHistoryScope")&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.inputHistoryScope"),info:r("settings.openchamber.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(sn,{"aria-label":r("settings.openchamber.visual.section.inputHistoryScopeAria"),children:Hx.map(g=>s.jsx(Qs,{selected:Q===g.id,onSelect:()=>za(g.id),label:l(g.labelKey),ariaLabel:l(g.labelKey)},g.id))})}),ge("inputHistoryLimit")&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.inputHistoryLimit"),description:r("settings.openchamber.visual.field.inputHistoryLimitDescription"),contentClassName:Vs,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:wa,children:[s.jsx(ws,{value:Ne,onValueChange:tr,min:Fu,max:Ru,step:1,className:Es,deferExternalValueWhileFocused:!0,"aria-label":r("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:ka,children:r("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),rr&&s.jsxs(s.Fragment,{children:[ge("expandedTools")&&s.jsxs($e,{title:r("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:cn||Dn||va||S,contentClassName:js,children:[s.jsx(mt,{checked:Fe,onChange:ui,label:r("settings.openchamber.visual.field.bash"),ariaLabel:r("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(mt,{checked:Y,onChange:ar,label:r("settings.openchamber.visual.field.editTools"),ariaLabel:r("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs($e,{title:r("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:js,children:[s.jsx(mt,{checked:Qe,onChange:Sn,label:r("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:r("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),ge("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(mt,{checked:p,onChange:h,label:r("settings.openchamber.visual.field.sessionRecap"),ariaLabel:r("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(mt,{checked:j,onChange:w,label:r("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:r("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),ge("subagentReadOnlyBanner")&&s.jsx(mt,{checked:ns,onChange:Zt,label:r("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),ge("sessionGoal")&&!hs&&s.jsxs($e,{title:r("settings.openchamber.visual.goal.sectionTitle"),info:r("settings.openchamber.visual.goal.description"),contentClassName:js,children:[s.jsx(mt,{checked:b,onChange:k,label:r("settings.openchamber.visual.field.sessionGoal"),ariaLabel:r("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(mt,{checked:m,onChange:I,disabled:!b,label:r("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:r("settings.openchamber.visual.goal.budgetAria")}),b&&m?s.jsx(ws,{value:E,onValueChange:g=>{typeof g=="number"&&Number.isFinite(g)&&g>0&&A(Math.floor(g))},min:1e3,max:1e8,step:5e4}):null]})]}),ge("reasoning")&&s.jsxs($e,{title:r("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:js,children:[s.jsx(mt,{checked:v,onChange:N,label:r("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:r("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),v&&s.jsx(mt,{checked:F,onChange:T,label:r("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx($e,{title:r("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:js,children:s.jsx(mt,{checked:x,onChange:y,label:r("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:r("settings.openchamber.visual.field.streamingAutoFollowAria"),info:r("settings.openchamber.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(ge("collapsibleUserMessages")||ge("stickyUserHeader")||ge("promptNavigatorEnabled")&&!hs||ge("wideChatLayout")||ge("splitAssistantMessageActions")||ge("codeBlockLineWrap"))&&s.jsxs($e,{title:r("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:js,children:[ge("collapsibleUserMessages")&&s.jsx(mt,{checked:C,onChange:Tn,label:r("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),ge("stickyUserHeader")&&s.jsx(mt,{checked:V,onChange:en,label:r("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:r("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),ge("promptNavigatorEnabled")&&!hs&&s.jsx(mt,{checked:U,onChange:pa,label:r("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),ge("wideChatLayout")&&s.jsx(mt,{checked:K,onChange:po,label:r("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:r("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),ge("splitAssistantMessageActions")&&s.jsx(mt,{checked:Ge,onChange:ln,label:r("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),ge("codeBlockLineWrap")&&s.jsx(mt,{checked:B,onChange:L,label:r("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(ge("showToolFileIcons")||ge("showTurnChangedFiles")||ge("dotfiles")&&!ds()||ge("fileViewerPreview"))&&s.jsxs($e,{title:r("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:js,children:[ge("showToolFileIcons")&&s.jsx(mt,{checked:ft,onChange:ga,label:r("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:r("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),ge("showTurnChangedFiles")&&s.jsx(mt,{checked:Je,onChange:ha,label:r("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),ge("dotfiles")&&!ds()&&s.jsx(mt,{checked:d,onChange:Ou,label:r("settings.openchamber.visual.field.showDotfiles"),ariaLabel:r("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),ge("fileViewerPreview")&&s.jsx(mt,{checked:ts,onChange:nr,label:r("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:r("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(ge("persistDraft")||ge("largeTextPaste")||!u&&ge("inputSpellcheck")||ge("enterToSend"))&&s.jsxs($e,{title:r("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(ge("persistDraft")||!u&&ge("inputSpellcheck"))&&s.jsxs("div",{className:js,children:[ge("persistDraft")&&s.jsx(mt,{checked:lt,onChange:at,label:r("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:r("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!u&&ge("inputSpellcheck")&&s.jsx(mt,{checked:pt,onChange:er,label:r("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),ge("largeTextPaste")&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.largeTextPaste"),description:r("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(sn,{"aria-label":r("settings.openchamber.visual.field.largeTextPasteAria"),children:Vx.map(g=>s.jsx(Qs,{selected:J===g.id,onSelect:()=>qe(g.id),label:l(g.labelKey),ariaLabel:r("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:l(g.labelKey)})},g.id))})}),ge("enterToSend")&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.enterToSend"),description:r("settings.openchamber.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs(sn,{"aria-label":r("settings.openchamber.visual.field.enterToSend"),children:[s.jsx(Qs,{selected:tt,onSelect:()=>$n(!0),label:r("settings.openchamber.visual.option.enterToSend.enter.label"),ariaLabel:r("settings.openchamber.visual.option.enterToSend.enter.label")}),s.jsx(Qs,{selected:!tt,onSelect:()=>$n(!1),label:r("settings.openchamber.visual.option.enterToSend.modifier.label"),ariaLabel:r("settings.openchamber.visual.option.enterToSend.modifier.label")})]})})]})]})]}),ge("reportUsage")&&s.jsx($e,{title:r("settings.openchamber.visual.section.privacy"),children:s.jsx(mt,{checked:li,onChange:Yi,label:r("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:r("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:r("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},Jx=1,Qx=365,Fl=30,Yx=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Bc=()=>{const t=dt.c(105),{t:e}=et(),a=ce(Zx),n=ce(Xx),i=ce(eb),r=ce(tb),l=ce(sb),u=ce(nb),c=ce(ab);let f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f={autoRun:!1},t[0]=f):f=t[0];const{candidates:d,isRunning:v,runCleanup:p,action:j,status:h}=qd(f),w=d.length;let b;t[1]!==p||t[2]!==e?(b=async()=>{const xe=await p({force:!0}).catch(()=>(M.error(e("sessions.sidebar.group.empty.loadFailed")),null));if(!(!xe||xe.skippedReason&&xe.skippedReason!=="no-candidates")){if(xe.completedIds.length===0&&xe.failedIds.length===0){M.message(xe.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}xe.completedIds.length>0&&M.success(xe.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:xe.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:xe.completedIds.length})),xe.failedIds.length>0&&M.error(xe.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:xe.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:xe.failedIds.length}))}},t[1]=p,t[2]=e,t[3]=b):b=t[3];const k=b;let m;t[4]!==e?(m=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=m):m=t[5];const I=i?"settings.openchamber.sessionRetention.archivedTooltip":"settings.openchamber.sessionRetention.tooltip";let E;t[6]!==e||t[7]!==I?(E=e(I),t[6]=e,t[7]=I,t[8]=E):E=t[8];let A;t[9]!==e?(A=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=A):A=t[10];let N;t[11]!==e?(N=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[11]=e,t[12]=N):N=t[12];let x;t[13]!==a||t[14]!==r||t[15]!==A||t[16]!==N?(x=s.jsx(mt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:A,ariaLabel:N}),t[13]=a,t[14]=r,t[15]=A,t[16]=N,t[17]=x):x=t[17];let y;t[18]!==e?(y=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[18]=e,t[19]=y):y=t[19];let F;t[20]!==e?(F=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[20]=e,t[21]=F):F=t[21];let T;t[22]!==e?(T=e("settings.openchamber.sessionRetention.field.onlyArchivedDescription"),t[22]=e,t[23]=T):T=t[23];let P;t[24]!==v||t[25]!==i||t[26]!==c||t[27]!==T||t[28]!==y||t[29]!==F?(P=s.jsx(mt,{settingsItem:"sessions.retention-only-archived",checked:i,onChange:c,disabled:v,label:y,ariaLabel:F,info:T}),t[24]=v,t[25]=i,t[26]=c,t[27]=T,t[28]=y,t[29]=F,t[30]=P):P=t[30];let D;t[31]!==e?(D=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=D):D=t[32];let $;t[33]!==e?($=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=$):$=t[34];let _;t[35]===Symbol.for("react.memo_cache_sentinel")?(_=ye(Es,"tabular-nums"),t[35]=_):_=t[35];let C;t[36]!==n||t[37]!==l||t[38]!==$?(C=s.jsx(ws,{value:n,onValueChange:l,min:Jx,max:Qx,step:1,"aria-label":$,className:_}),t[36]=n,t[37]=l,t[38]=$,t[39]=C):C=t[39];let R;t[40]!==e?(R=e("settings.openchamber.sessionRetention.field.days"),t[40]=e,t[41]=R):R=t[41];let V;t[42]!==R?(V=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:R}),t[42]=R,t[43]=V):V=t[43];let U;t[44]!==l?(U=()=>l(Fl),t[44]=l,t[45]=U):U=t[45];const W=n===Fl;let te;t[46]!==e?(te=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=te):te=t[47];let O;t[48]!==e?(O=e("settings.common.actions.reset"),t[48]=e,t[49]=O):O=t[49];let ie;t[50]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=ie):ie=t[50];let K;t[51]!==U||t[52]!==W||t[53]!==te||t[54]!==O?(K=s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:U,disabled:W,className:ys,"aria-label":te,title:O,children:ie}),t[51]=U,t[52]=W,t[53]=te,t[54]=O,t[55]=K):K=t[55];let q;t[56]!==D||t[57]!==C||t[58]!==V||t[59]!==K?(q=s.jsxs(Ht,{settingsItem:"sessions.retention-period",label:D,children:[C,V,K]}),t[56]=D,t[57]=C,t[58]=V,t[59]=K,t[60]=q):q=t[60];let B;t[61]!==e?(B=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=B):B=t[62];let L;t[63]!==i||t[64]!==e?(L=Yx.map(xe=>({value:xe.value,label:e(xe.labelKey),disabled:i&&xe.value==="archive"})),t[63]=i,t[64]=e,t[65]=L):L=t[65];let X;t[66]!==j||t[67]!==u||t[68]!==L?(X=s.jsx(an,{value:j,onChange:u,options:L}),t[66]=j,t[67]=u,t[68]=L,t[69]=X):X=t[69];let G;t[70]!==B||t[71]!==X?(G=s.jsx(Ht,{settingsItem:"sessions.retention-action",label:B,children:X}),t[70]=B,t[71]=X,t[72]=G):G=t[72];let Z;t[73]!==P||t[74]!==q||t[75]!==G?(Z=s.jsxs(Fa,{className:"space-y-0",children:[P,q,G]}),t[73]=P,t[74]=q,t[75]=G,t[76]=Z):Z=t[76];let le;t[77]!==e?(le=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[77]=e,t[78]=le):le=t[78];let oe;t[79]!==v||t[80]!==e?(oe=e(v?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[79]=v,t[80]=e,t[81]=oe):oe=t[81];let he;t[82]!==k||t[83]!==v||t[84]!==oe?(he=s.jsx(H,{type:"button",variant:"outline",size:"xs",onClick:k,disabled:v,className:"!font-normal",children:oe}),t[82]=k,t[83]=v,t[84]=oe,t[85]=he):he=t[85];let ee;t[86]!==le||t[87]!==he?(ee=s.jsx(Ht,{label:le,children:he}),t[86]=le,t[87]=he,t[88]=ee):ee=t[88];let re;t[89]!==j||t[90]!==w||t[91]!==h||t[92]!==e?(re=h==="error"?e("sessions.sidebar.group.empty.loadFailed"):h!=="ready"?e("sessions.sidebar.group.empty.loadingSessions"):j==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:w}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:w}),t[89]=j,t[90]=w,t[91]=h,t[92]=e,t[93]=re):re=t[93];let de;t[94]!==re?(de=s.jsx("p",{className:"typography-meta text-muted-foreground",children:re}),t[94]=re,t[95]=de):de=t[95];let ke;t[96]!==ee||t[97]!==de?(ke=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[ee,de]}),t[96]=ee,t[97]=de,t[98]=ke):ke=t[98];let ue;return t[99]!==m||t[100]!==Z||t[101]!==ke||t[102]!==E||t[103]!==x?(ue=s.jsxs($e,{title:m,info:E,children:[x,Z,ke]}),t[99]=m,t[100]=Z,t[101]=ke,t[102]=E,t[103]=x,t[104]=ue):ue=t[104],ue};function Zx(t){return t.autoDeleteEnabled}function Xx(t){return t.autoDeleteAfterDays}function eb(t){return t.sessionRetentionOnlyArchived}function tb(t){return t.setAutoDeleteEnabled}function sb(t){return t.setAutoDeleteAfterDays}function nb(t){return t.setSessionRetentionAction}function ab(t){return t.setSessionRetentionOnlyArchived}const Ol=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(Qr(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),Vc=()=>{const{t}=et(),e=ce(x=>x.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,u]=o.useState(!1),[c,f]=o.useState(null),[d,v]=o.useState(!1),[p,j]=o.useState([]),[h,w]=o.useState(Gd),[b,k]=o.useState(""),m=o.useMemo(()=>Wd(),[]),I=o.useCallback(async()=>{r(!0),k("");try{const x=await Jd();j(x)}catch(x){const y=x instanceof Error?x.message:t("settings.openchamber.passkeys.toast.loadFailed");k(y)}finally{r(!1)}},[t]);o.useEffect(()=>{let x=!1;return(async()=>{try{if(!m.supported){x||(n(!1),r(!1));return}x||n(!0)}catch{x||n(!1)}if(!x){const y=await dr();if(w(y),!y.enabled){j([]),r(!1);return}await I()}})(),()=>{x=!0,yo()}},[I,m.supported]);const E=o.useCallback(async()=>{if(!h.enabled){const x=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");k(x),M.message(x);return}if(!a){k(m.reason),M.message(m.reason);return}if(l){yo(),u(!1);return}k(""),u(!0);try{await Qd(),w(await dr()),await I(),M.success(t("settings.openchamber.passkeys.toast.added"))}catch(x){if(Yd(x)){M.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const y=x instanceof Error?x.message:t("settings.openchamber.passkeys.toast.addFailed");k(y),M.error(y)}finally{u(!1)}},[l,I,h.enabled,m.reason,a,t]),A=o.useCallback(async x=>{f(x),k("");try{await Zd(x),w(await dr()),await I(),M.success(t("settings.openchamber.passkeys.toast.removed"))}catch(y){const F=y instanceof Error?y.message:t("settings.openchamber.passkeys.toast.removeFailed");k(F),M.error(F)}finally{f(null)}},[I,t]),N=o.useCallback(async()=>{v(!0),k("");try{await Xd(),window.location.reload()}catch(x){const y=x instanceof Error?x.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");k(y),M.error(y),v(!1)}},[t]);return s.jsxs($e,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Ht,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(H,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{E()},disabled:i||d,className:"!font-normal",children:t(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{N()},disabled:i||l||d,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(d?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!h.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),h.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:m.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):p.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:p.map(x=>s.jsxs(Ht,{label:s.jsx("span",{title:x.label,children:x.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:x.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Ol(x.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:Ol(x.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{A(x.id)},disabled:c===x.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===x.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},x.id))})]}),b&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b})})]})},Hc=()=>{const t=dt.c(14),{t:e}=et(),a=jo(ib),n=jo(rb);let i;t[0]!==e?(i=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=i):i=t[1];let r;t[2]!==e?(r=e("settings.openchamber.appLinks.info"),t[2]=e,t[3]=r):r=t[3];let l;t[4]!==n||t[5]!==e||t[6]!==a?(l=a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.appLinks.empty")}):a.map(f=>s.jsxs("div",{className:"flex items-center justify-between gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-[13px]",children:`${f}://`}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(f),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${f}://`}),children:e("settings.common.actions.delete")})]},f)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let u;t[8]!==l?(u=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=u):u=t[9];let c;return t[10]!==i||t[11]!==r||t[12]!==u?(c=s.jsx($e,{title:i,description:r,children:u}),t[10]=i,t[11]=r,t[12]=u,t[13]=c):c=t[13],c};function ib(t){return t.trustedSchemes}function rb(t){return t.removeTrustedScheme}const Cr=t=>{const e=Da(t);return e||{providerId:"",modelId:""}},qc=()=>{const{t}=et(),e=nt(ee=>ee.setProvider),a=nt(ee=>ee.setModel),n=nt(ee=>ee.setAgent),i=nt(ee=>ee.setCurrentVariant),r=nt(ee=>ee.setCurrentVariantOverride),l=nt(ee=>ee.setSettingsDefaultModel),u=nt(ee=>ee.setSettingsDefaultVariant),c=nt(ee=>ee.setSettingsDefaultAgent),f=nt(ee=>ee.selectionSource==="manual"),d=eu(ee=>ee.currentSessionId),v=wo(ee=>ee.getSessionModelSelection),p=wo(ee=>ee.getSessionAgentSelection),j=!!(f&&d&&v(d)),h=!!(f&&d&&p(d)),w=ce(ee=>ee.showDeletionDialog),b=ce(ee=>ee.setShowDeletionDialog),k=nt(ee=>ee.providers),m=nt(ee=>ee.modelsMetadata),[I,E]=o.useState(),[A,N]=o.useState(),[x,y]=o.useState(),[F,T]=o.useState(!0),[P,D]=o.useState(),[$,_]=o.useState([]),[C,R]=o.useState(),[V,U]=o.useState(!0),W=o.useMemo(()=>Cr(I),[I]);o.useEffect(()=>{(async()=>{try{const re=await Nn();if(re){const de=re.defaultModel?.trim()||void 0,ke=re.defaultVariant?.trim()||void 0,ue=re.defaultAgent?.trim()||void 0;de!==void 0&&E(de),ke!==void 0&&N(ke),ue!==void 0&&y(ue),re.smallModelUseDefault!==void 0&&T(re.smallModelUseDefault);const xe=re.smallModelOverride?.trim();xe&&D(xe);const pe=re.walkthroughModelOverride?.trim();pe&&R(pe)}}catch(re){console.warn("Failed to load defaults settings:",re)}finally{U(!1)}})()},[]);const te=o.useCallback(async(ee,re)=>{const de=ee&&re?`${ee}/${re}`:void 0;E(de),N(void 0),u(void 0),l(de),j||(i(void 0),ee&&re&&k.find(ue=>ue.id===ee)&&(e(ee),a(re)));try{await yt({defaultModel:de??"",defaultVariant:""})}catch(ke){console.warn("Failed to save default model:",ke)}},[j,k,i,a,e,l,u]),O="__default__",ie=o.useCallback(ee=>ee===O?t("settings.openchamber.defaults.option.default"):ee.charAt(0).toUpperCase()+ee.slice(1),[t]),K=o.useCallback(async ee=>{const re=ee===O?void 0:ee||void 0;N(re),u(re),j||r(re??null,re);try{await yt({defaultVariant:re??""})}catch(de){console.warn("Failed to save default variant:",de)}},[j,r,u]),q=o.useCallback(async ee=>{const re=ee||void 0;y(re),c(re),ee&&!h&&n(ee);try{await yt({defaultAgent:re??""})}catch(de){console.warn("Failed to save default agent:",de)}},[h,n,c]),B=o.useCallback(async ee=>{T(ee);try{await yt({smallModelUseDefault:ee})}catch(re){console.warn("Failed to save small model preference:",re)}},[]),L=o.useCallback(async(ee,re)=>{const de=ee&&re?`${ee}/${re}`:void 0;D(de);try{await yt({smallModelOverride:de??""})}catch(ke){console.warn("Failed to save small model override:",ke)}},[]),X=o.useCallback(async(ee,re)=>{const de=ee&&re?`${ee}/${re}`:void 0;R(de);try{await yt({walkthroughModelOverride:de??""})}catch(ke){console.warn("Failed to save walkthrough model override:",ke)}},[]),G=o.useCallback((ee,re)=>m.get(`${ee}/${re}`)?.structured_output!==!1,[m]),Z=o.useMemo(()=>Cr(P),[P]),le=o.useMemo(()=>Cr(C),[C]);o.useEffect(()=>{let ee=!1;return(async()=>{try{const re=await xt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!re.ok)return;const de=await re.json().catch(()=>null);!ee&&Array.isArray(de?.authenticatedProviders)&&_(de.authenticatedProviders.filter(ke=>typeof ke=="string"))}catch{}})(),()=>{ee=!0}},[]);const oe=o.useMemo(()=>{if(!W.providerId||!W.modelId)return[];const de=k.find(ke=>ke.id===W.providerId)?.models.find(ke=>ke.id===W.modelId)?.variants;return de?Object.keys(de):[]},[W.modelId,W.providerId,k]),he=oe.length>0;return V?null:s.jsx(s.Fragment,{children:s.jsx($e,{title:t("settings.openchamber.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",W.providerId?s.jsxs("span",{className:"text-foreground",children:[W.providerId,"/",W.modelId,he?` (${A??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),x&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:x})]})]}),s.jsxs("div",{children:[s.jsx(Ht,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(Xa,{providerId:W.providerId,modelId:W.modelId,onChange:te,className:_n})}),s.jsx(Ht,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Et,{value:A??O,onValueChange:K,disabled:!he,children:[s.jsx(Dt,{size:Gt,className:gn,children:s.jsx(_t,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:ie(A??O)})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:O,children:t("settings.openchamber.defaults.option.default")}),oe.map(ee=>s.jsx(ut,{value:ee,children:ie(ee)},ee))]})]})}),s.jsx(Ht,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(Zl,{agentName:x||"",onChange:q,filter:ee=>tu(ee.mode),className:_n})})]}),s.jsx(Fa,{className:js,children:s.jsx(mt,{settingsItem:"sessions.deletion-dialog",checked:w,onChange:b,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")})}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(rn,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Yt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(mt,{settingsItem:"sessions.small-model",checked:F,onChange:ee=>{B(ee)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),F?null:s.jsx(Ht,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(Xa,{providerId:Z.providerId,modelId:Z.modelId,onChange:L,allowedProviderIds:$,className:_n})}),s.jsxs(Fa,{className:js,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(rn,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Yt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Ht,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(Xa,{providerId:le.providerId,modelId:le.modelId,onChange:X,allowedProviderIds:$,isModelAllowed:G,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:_n})})]})]})]})})})},Ll={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}=et(),e=o.useMemo(()=>cs(),[]),a=o.useMemo(()=>ds(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=ce(K=>K.nativeNotificationsEnabled),l=ce(K=>K.setNativeNotificationsEnabled),u=ce(K=>K.notificationMode),c=ce(K=>K.setNotificationMode),f=ce(K=>K.notifyOnSubtasks),d=ce(K=>K.setNotifyOnSubtasks),v=ce(K=>K.notifyOnCompletion),p=ce(K=>K.setNotifyOnCompletion),j=ce(K=>K.notifyOnError),h=ce(K=>K.setNotifyOnError),w=ce(K=>K.notifyOnQuestion),b=ce(K=>K.setNotifyOnQuestion),k=ce(K=>K.notificationTemplates),m=ce(K=>K.setNotificationTemplates),[I,E]=o.useState("default"),[A,N]=o.useState(!1),[x,y]=o.useState(!1),[F,T]=o.useState(!1);o.useEffect(()=>{if(!i){N(!1),y(!1);return}typeof Notification<"u"&&E(Notification.permission);const K=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;N(K),(async()=>{if(!K){y(!1);return}try{const B=await navigator.serviceWorker.getRegistration();if(!B){y(!1);return}const L=await B.pushManager.getSubscription();y(!!L)}catch{y(!1)}})()},[i]);const P=async K=>{if(e){l(K);return}if(!i){l(K);return}if(K&&typeof Notification<"u"&&Notification.permission==="default")try{const q=await Notification.requestPermission();E(q),q==="granted"?l(!0):M.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(q){console.error("Failed to request notification permission:",q),M.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(K&&I==="granted"))},D=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",$=(K,q,B)=>{m(L=>({...L,[K]:{...L[K],[q]:B}}))},_=K=>{const q="=".repeat((4-K.length%4)%4),B=(K+q).replace(/-/g,"+").replace(/_/g,"/"),L=atob(B),X=new Uint8Array(L.length);for(let G=0;G<L.length;G+=1)X[G]=L.charCodeAt(G);return X},C=async(K,q,B)=>{let L=null;const X=new Promise((G,Z)=>{L=setTimeout(()=>{Z(new Error(B))},q)});try{return await Promise.race([K,X])}finally{L&&clearTimeout(L)}},R=async K=>{if(K.active)return;const q=K.installing||K.waiting;q&&q.state!=="activated"&&await C(new Promise(B=>{const L=()=>{q.state==="activated"&&(q.removeEventListener("statechange",L),B())};q.addEventListener("statechange",L),L()}),15e3,"Service worker activation timed out")},V=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const K=[{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 q=null;for(const B of K)try{const L=B.opts?navigator.serviceWorker.register("/sw.js",B.opts):navigator.serviceWorker.register("/sw.js");return await C(L,1e4,`Service worker registration timed out (${B.label})`)}catch(L){q=L}throw q instanceof Error?q:new Error("Service worker registration failed")},U=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const K=await navigator.serviceWorker.getRegistration();if(K)return K;const q=await V();try{await q.update()}catch{}return await R(q),q},W=K=>{const q=K,B=[`type=${typeof K}`,`toString=${String(K)}`,`name=${String(q?.name??"")}`,`message=${String(q?.message??"")}`];let L="";try{L=JSON.stringify(K)}catch{}return{summary:B.filter(Boolean).join(" | "),json:L,stack:typeof q?.stack=="string"?q.stack:""}},te=async()=>{const K=Ta();if(!K?.notifications){M.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await K.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?M.success(t("settings.notifications.page.toast.testNotificationSent")):M.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(q){console.error("Test notification failed:",q),M.error(t("settings.notifications.page.toast.testNotificationFailed"))}},O=async()=>{if(!A){M.error(t("settings.notifications.page.toast.pushUnsupported"));return}const K=Ta();if(!K?.push){M.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const oe=await Notification.requestPermission();if(E(oe),oe!=="granted"){M.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){M.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const q=await K.push.getVapidPublicKey();if(!q?.publicKey){M.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const B=await U();await R(B);const L=await B.pushManager.getSubscription();if(!("pushManager"in B)||!B.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const G=(L??await C(B.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:_(q.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Z=G.keys;if(!G.endpoint||!Z?.p256dh||!Z.auth)throw new Error("Push subscription missing keys");if(!(await C(K.push.subscribe({endpoint:G.endpoint,keys:{p256dh:Z.p256dh,auth:Z.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:Lu()}),15e3,"Push subscribe request timed out"))?.ok){M.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}y(!0),M.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(q){console.error("[Push] Enable failed:",q);const B=W(q);M.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:B.summary})}finally{T(!1)}},ie=async()=>{if(!A){y(!1);return}const K=Ta();if(!K?.push){M.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{const B=await(await U()).pushManager.getSubscription();if(!B){y(!1);return}const L=B.endpoint;await B.unsubscribe(),await K.push.unsubscribe({endpoint:L}),y(!1),M.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{T(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs($e,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:js,children:[s.jsx(mt,{checked:r&&D,onChange:K=>{P(K)},label:t("settings.notifications.page.delivery.enableLabel"),info:i?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),r&&D&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(mt,{checked:u==="always",onChange:K=>c(K?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(H,{type:"button",variant:"outline",size:"sm",onClick:()=>{te()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[I==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),I==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&D&&s.jsxs(s.Fragment,{children:[s.jsx($e,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:js,children:[s.jsx(mt,{checked:v,onChange:p,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(mt,{checked:f,onChange:d,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(mt,{checked:j,onChange:h,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(mt,{checked:w,onChange:b,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx($e,{title:t("settings.notifications.page.template.title"),description:s.jsxs(s.Fragment,{children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{last_message}"})]}),children:s.jsx(Kn,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(K=>s.jsxs("section",{className:"p-2",children:[s.jsx(rn,{className:"capitalize",children:t(ob[K])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(He,{value:k[K].title,onChange:q=>$(K,"title",q.target.value),className:"h-7",placeholder:t(Ll[K].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(He,{value:k[K].message,onChange:q=>$(K,"message",q.target.value),className:"h-7",placeholder:t(Ll[K].messageKey)})]})]})]},K))})})]}),i&&s.jsx($e,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(mt,{checked:A?x:!1,disabled:!A||F,onChange:K=>{K?O():ie()},label:t("settings.notifications.page.push.enableLabel"),description:A?void 0:t("settings.notifications.page.push.unsupportedHint"),info:A?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:F?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},Ks=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},In="oc-surface-elevated w-full h-7 rounded-lg border border-input bg-surface-elevated px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring focus:border-interactive-border-focus",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"}],Kl=t=>{const e=dt.c(8),{value:a,label:n}=t,i=`${n}: ${a}/5`,r=`${a/5*100}%`;let l;e[0]!==r?(l=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:r}})}),e[0]=r,e[1]=l):l=e[1];let u;e[2]!==n?(u=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=u):u=e[3];let c;return e[4]!==i||e[5]!==l||e[6]!==u?(c=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,u]}),e[4]=i,e[5]=l,e[6]=u,e[7]=c):c=e[7],c},db=({selectedModelId:t,onSelect:e})=>{const{t:a}=et(),n=Ye.useCallback(p=>a(p),[a]),[i,r]=Ye.useState(new Map),[l,u]=Ye.useState(null),c=Ye.useCallback(async()=>{try{const p=await xt("/api/dictation/status",{query:{provider:"local"}});if(!p.ok)return;const j=await p.json();Array.isArray(j?.models)&&r(new Map(j.models.map(h=>[h.id,h])))}catch{}},[]);Ye.useEffect(()=>{c()},[c]);const f=Array.from(i.values()).some(p=>p.downloading);Ye.useEffect(()=>{if(!f)return;const p=setInterval(()=>{c()},2e3);return()=>clearInterval(p)},[f,c]);const d=async p=>{u(p);try{await xt(`/api/dictation/models/${encodeURIComponent(p)}/download`,{method:"POST"}),await c()}catch{}finally{u(null)}},v=async p=>{u(p);try{await xt(`/api/dictation/models/${encodeURIComponent(p)}`,{method:"DELETE"}),await c()}catch{}finally{u(null)}};return s.jsx("div",{role:"radiogroup","aria-label":a("settings.voice.page.field.model"),className:"mt-1.5 grid w-full grid-cols-1 gap-3 @xl:grid-cols-2",children:cb.map(p=>{const j=t===p.id,h=i.get(p.id)??null;return s.jsx("div",{className:ye("rounded-lg border border-[var(--interactive-border)] p-3",j&&"border-border bg-interactive-selection text-interactive-selection-foreground"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(p.id),onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),e(p.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(Gr,{checked:j,onChange:()=>e(p.id),ariaLabel:n(p.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:ye("typography-ui-label font-normal",j?"text-foreground":"text-foreground/50"),children:n(p.labelKey)}),p.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(p.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Kl,{value:p.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(Kl,{value:p.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:p.size})]}),h?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:h.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:h?.installed?s.jsxs(s.Fragment,{children:[s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===p.id,onClick:()=>{v(p.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(z,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):h?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof h.downloadProgress=="number"?`${h.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===p.id,onClick:()=>{d(p.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(z,{name:"download",className:"h-4 w-4"})})})]})},p.id)})})},ub=[{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)"}],Br="kokoro-en-v0_19",pb="kokoro-multi-lang-v1_1",mb=[{id:0,label:"Maple (af)"},{id:1,label:"Sol (af)"},{id:2,label:"Vale (bf)"},{id:3,label:"Xiaoxiao (zf)"},{id:58,label:"Yunxi (zm)"}],Ja=(t,e)=>`${t}:${e}`,gb=()=>{const[t,e]=Ye.useState([]),[a,n]=Ye.useState(null),i=Ye.useCallback(async()=>{try{const u=await xt("/api/dictation/status",{query:{provider:"local"}});if(!u.ok)return;const c=await u.json();Array.isArray(c?.ttsModels)&&e(c.ttsModels)}catch{}},[]);Ye.useEffect(()=>{i()},[i]);const r=t.some(u=>u.downloading);Ye.useEffect(()=>{if(!r)return;const u=setInterval(()=>{i()},2e3);return()=>clearInterval(u)},[r,i]);const l=Ye.useCallback(async(u,c)=>{n(u);try{const f=c==="POST"?`/api/dictation/models/${u}/download`:`/api/dictation/models/${u}`;await xt(f,{method:c}),await i()}catch{}finally{n(null)}},[i]);return{models:t,requestingId:a,request:l,refresh:i}},hb=t=>{const e=ub.map(a=>({modelId:Br,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===Br||!a.installed)){if(a.id===pb){for(const n of mb)e.push({modelId:a.id,speakerId:n.id,label:`${n.label} · Kokoro zh/en`});continue}e.push({modelId:a.id,speakerId:0,label:a.description??a.id})}return e},fb=t=>{const e=dt.c(14),{models:a,requestingId:n,request:i}=t,{t:r}=et();let l,u,c;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==r){c=Symbol.for("react.early_return_sentinel");e:{const d=a.filter(vb);if(d.length===0){c=null;break e}l="flex flex-col";let v;e[7]!==i||e[8]!==n||e[9]!==r?(v=p=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:p.description??p.id}),p.installed?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":r("settings.voice.page.stt.modelInstalled")}),s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{i(p.id,"DELETE")},title:r("settings.voice.page.stt.modelDelete"),"aria-label":r("settings.voice.page.stt.modelDelete"),children:s.jsx(z,{name:"delete-bin",className:"h-4 w-4"})})]}):p.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof p.downloadProgress=="number"?`${p.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{i(p.id,"POST")},title:r("settings.voice.page.stt.modelDownload"),"aria-label":r("settings.voice.page.stt.modelDownload"),children:s.jsx(z,{name:"download",className:"h-4 w-4"})}),p.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:p.downloadError}):null]},p.id),e[7]=i,e[8]=n,e[9]=r,e[10]=v):v=e[10],u=d.map(v)}e[0]=a,e[1]=i,e[2]=n,e[3]=r,e[4]=l,e[5]=u,e[6]=c}else l=e[4],u=e[5],c=e[6];if(c!==Symbol.for("react.early_return_sentinel"))return c;let f;return e[11]!==l||e[12]!==u?(f=s.jsx("div",{className:l,children:u}),e[11]=l,e[12]=u,e[13]=f):f=e[13],f},xb=[{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"}],bb=()=>{const{t}=et(),{isMobile:e}=ua(),a=nt(J=>J.voiceProvider),n=nt(J=>J.setVoiceProvider),i=nt(J=>J.speechRate),r=nt(J=>J.setSpeechRate),l=nt(J=>J.speechPitch),u=nt(J=>J.setSpeechPitch),c=nt(J=>J.speechVolume),f=nt(J=>J.setSpeechVolume),d=nt(J=>J.sayVoice),v=nt(J=>J.setSayVoice),p=nt(J=>J.localTtsVoiceId),j=nt(J=>J.localTtsModelId),h=nt(J=>J.setLocalTtsModelId),w=gb(),b=Ye.useMemo(()=>hb(w.models),[w.models]),k=nt(J=>J.ttsFollowTextLanguage),m=nt(J=>J.setTtsFollowTextLanguage),I=nt(J=>J.setLocalTtsVoiceId),{speak:E,stop:A,isPlaying:N,error:x}=su(),y=Ye.useCallback(()=>{if(N){A();return}const J=b.find(qe=>qe.modelId===j&&qe.speakerId===p)?.label??String(p);E(t("settings.voice.page.preview.voiceLine",{voiceName:J}),{model:j,speakerId:p,speed:nt.getState().speechRate})},[N,j,p,b,E,A,t]),F=nt(J=>J.browserVoice),T=nt(J=>J.setBrowserVoice),P=nt(J=>J.openaiVoice),D=nt(J=>J.setOpenaiVoice),$=nt(J=>J.openaiApiKey),_=nt(J=>J.setOpenaiApiKey),C=nt(J=>J.openaiCompatibleUrl),R=nt(J=>J.setOpenaiCompatibleUrl),V=nt(J=>J.openaiCompatibleApiKey),U=nt(J=>J.setOpenaiCompatibleApiKey),W=nt(J=>J.openaiCompatibleVoice),te=nt(J=>J.setOpenaiCompatibleVoice),O=nt(J=>J.openaiCompatibleTtsModel),ie=nt(J=>J.setOpenaiCompatibleTtsModel),K=nt(J=>J.showMessageTTSButtons),q=nt(J=>J.ttsInputMode),B=nt(J=>J.setTtsInputMode),L=nt(J=>J.sttProvider),X=nt(J=>J.setSttProvider),G=nt(J=>J.sttServerUrl),Z=nt(J=>J.setSttServerUrl),le=nt(J=>J.sttApiKey),oe=nt(J=>J.setSttApiKey),he=nt(J=>J.sttModel),ee=nt(J=>J.setSttModel),re=nt(J=>J.sttLocalModel),de=nt(J=>J.setSttLocalModel),ke=nt(J=>J.sttLanguage),ue=nt(J=>J.setSttLanguage),xe=nt(J=>J.setShowMessageTTSButtons),pe=nt(J=>J.dictationEnabled),Ie=nt(J=>J.setDictationEnabled),[Te,we]=Ye.useState(!1),[De,_e]=Ye.useState([]),[Ve,ve]=Ye.useState(!1),[se,ae]=Ye.useState(null),[je,Se]=Ye.useState(!1),[Ke,Ue]=Ye.useState(!1),[Oe,Re]=Ye.useState(null),[Ce,Ze]=Ye.useState(!1),[be,Pe]=Ye.useState(null),[Le,Xe]=Ye.useState([]),[Q,Ne]=Ye.useState(!1);Ye.useEffect(()=>((async()=>{const qe=await ur.waitForVoices();Xe(qe)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Xe(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ae=Ye.useMemo(()=>Le.filter(J=>J.lang).sort((J,qe)=>{const it=J.lang.startsWith("en"),ct=qe.lang.startsWith("en");if(it&&!ct)return-1;if(!it&&ct)return 1;const gt=J.lang.localeCompare(qe.lang);return gt!==0?gt:J.name.localeCompare(qe.name)}),[Le]),We=Ye.useCallback(()=>{if(Q){ur.cancelSpeech(),Ne(!1);return}const J=Le.find(gt=>gt.name===F),qe=J?.name??t("settings.voice.page.preview.browserVoiceFallback"),it=t("settings.voice.page.preview.voiceLine",{voiceName:qe});Ne(!0);const ct=new SpeechSynthesisUtterance(it);ct.rate=i,ct.pitch=l,ct.volume=c,J&&(ct.voice=J,ct.lang=J.lang),ct.onend=()=>Ne(!1),ct.onerror=()=>Ne(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(ct)},[F,Le,i,l,c,Q,t]);Ye.useEffect(()=>()=>{Q&&ur.cancelSpeech()},[Q]),Ye.useEffect(()=>{if(!K||a!=="openai"&&a!=="openai-compatible"){Se($.trim().length>0);return}(async()=>{try{const ct=(await(await xt("/api/tts/status")).json()).available,gt=$.trim().length>0;Se(ct||gt)}catch{Se($.trim().length>0)}})()},[$,K,a]),Ye.useEffect(()=>{if(!K){we(!1),_e([]);return}xt("/api/tts/say/status").then(J=>J.json()).then(J=>{if(we(J.available),J.voices){const qe=J.voices.filter((it,ct,gt)=>gt.findIndex(Rt=>Rt.name===it.name)===ct).sort((it,ct)=>it.name.localeCompare(ct.name));_e(qe)}}).catch(()=>{we(!1)})},[K]);const lt=Ye.useCallback(async()=>{if(se){Ks(se),ae(null),ve(!1);return}ve(!0);let J=null;try{const qe=await xt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:d}),voice:d,rate:Math.round(100+(i-.5)*200)})});if(!qe.ok)throw new Error("Preview failed");const it=await qe.blob(),ct=URL.createObjectURL(it);J=new Audio(ct),J.onended=()=>{Ks(J),ae(null),ve(!1)},J.onerror=()=>{Ks(J),ae(null),ve(!1)},ae(J),await J.play()}catch{Ks(J),ae(null),ve(!1)}},[d,i,se,t]);Ye.useEffect(()=>()=>{Ks(se)},[se]);const at=Ye.useCallback(async()=>{if(Oe){Ks(Oe),Re(null),Ue(!1);return}Ue(!0);let J=null;try{const qe=await xt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:P}),voice:P,speed:i,apiKey:$||void 0})});if(!qe.ok){const gt=await qe.json().catch(()=>({error:"Unknown error"}));throw new Error(gt.error||`HTTP ${qe.status}`)}const it=await qe.blob(),ct=URL.createObjectURL(it);J=new Audio(ct),J.onended=()=>{Ks(J),Re(null),Ue(!1)},J.onerror=()=>{Ks(J),Re(null),Ue(!1)},Re(J),await J.play()}catch{Ks(J),Re(null),Ue(!1)}},[P,i,Oe,$,t]);Ye.useEffect(()=>()=>{Ks(Oe)},[Oe]);const pt=Ye.useCallback(async()=>{if(be){Ks(be),Pe(null),Ze(!1);return}if(!C.trim())return;Ze(!0);let J=null;try{const qe=await xt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:W,model:O||void 0,speed:i,baseURL:C,apiKey:V||void 0})});if(!qe.ok){const gt=await qe.json().catch(()=>({error:"Unknown error"}));throw new Error(gt.error||`HTTP ${qe.status}`)}const it=await qe.blob(),ct=URL.createObjectURL(it);J=new Audio(ct),J.onended=()=>{Ks(J),Pe(null),Ze(!1)},J.onerror=()=>{Ks(J),Pe(null),Ze(!1)},Pe(J),await J.play()}catch{Ks(J),Pe(null),Ze(!1)}},[C,W,O,V,i,be,t]);Ye.useEffect(()=>()=>{Ks(be)},[be]);const bt="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs(s.Fragment,{children:[s.jsxs($e,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(mt,{checked:K,onChange:xe,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),K&&s.jsxs(s.Fragment,{children:[s.jsx(Ps,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.localTts")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.openai")})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]}),children:s.jsx(an,{value:a,onChange:n,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"browser",label:t("settings.voice.page.provider.browser")},{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai",label:t("settings.voice.page.provider.openai")},{value:"openai-compatible",label:t("settings.voice.page.provider.custom")},...Te?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:ye(Ot,!je&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ye(Jn,!je&&"text-[var(--status-error)]/80"),children:t(je&&!$?"settings.voice.page.field.apiKeyHintUsingConfig":je?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:ye("relative",Vs),children:[s.jsx("input",{type:"password",value:$,onChange:J=>_(J.target.value),placeholder:"sk-...",className:In}),$&&s.jsx("button",{type:"button",onClick:()=>_(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Ot,!C.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Yt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:ye("relative",Vs),children:[s.jsx("input",{type:"text",value:C,onChange:J=>R(J.target.value),placeholder:"http://localhost:8880/v1",className:In}),C&&s.jsx("button",{type:"button",onClick:()=>R(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:"API Key"}),s.jsx("span",{className:Jn,children:"Optional"}),s.jsxs("div",{className:ye("relative",Vs),children:[s.jsx("input",{type:"password",value:V,onChange:J=>U(J.target.value),placeholder:"sk-...",className:In}),V&&s.jsx("button",{type:"button",onClick:()=>U(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Vs),children:s.jsx("input",{type:"text",value:O,onChange:J=>ie(J.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:In})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Ot,children:t("settings.voice.page.field.voice")}),s.jsx(Yt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:ye("flex items-center gap-2",Vs),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:W,onChange:J=>te(J.target.value),placeholder:"af_sky",className:In})}),s.jsx(H,{size:"xs",variant:"ghost",onClick:pt,title:t("settings.voice.page.actions.preview"),disabled:!C.trim(),children:Ce?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(fb,{...w}),(a==="local"||a==="say")&&s.jsx(mt,{checked:k,onChange:m,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Ht,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Et,{value:Ja(j,p),onValueChange:J=>{const qe=b.find(it=>Ja(it.modelId,it.speakerId)===J);qe&&(h(qe.modelId),I(qe.speakerId))},children:[s.jsx(Dt,{size:Gt,className:gn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:J=>b.find(qe=>Ja(qe.modelId,qe.speakerId)===J)?.label??J})}),s.jsx(Mt,{children:b.map(J=>s.jsx(ut,{value:Ja(J.modelId,J.speakerId),children:J.label},Ja(J.modelId,J.speakerId)))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:y,title:t("settings.voice.page.actions.preview"),children:N?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})}),x?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:x}):null]}),a==="openai"&&je&&s.jsxs(s.Fragment,{children:[s.jsxs(Et,{value:P,onValueChange:D,children:[s.jsx(Dt,{size:Gt,className:gn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Mt,{children:xb.map(J=>s.jsx(ut,{value:J.value,children:J.label},J.value))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:at,title:t("settings.voice.page.actions.preview"),children:Ke?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:Jn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&Te&&De.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Et,{value:d,onValueChange:v,children:[s.jsx(Dt,{size:Gt,className:gn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Mt,{children:De.map(J=>s.jsx(ut,{value:J.name,children:J.name},J.name))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:lt,title:t("settings.voice.page.actions.preview"),children:Ve?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Ae.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Et,{value:F||"$auto",onValueChange:J=>T(J==="$auto"?"":J),children:[s.jsx(Dt,{size:Gt,className:gn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Mt,{children:[s.jsx(ut,{value:"$auto",children:t("settings.voice.page.field.auto")}),Ae.map(J=>s.jsxs(ut,{value:J.name,children:[J.name," (",J.lang,")"]},J.name))]})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:We,title:t("settings.voice.page.actions.preview"),children:Q?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Ht,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:J=>r(Number(J.target.value)),className:bt}),s.jsx(ws,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:ye(Es,"tabular-nums")})]}),s.jsxs(Ht,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:J=>u(Number(J.target.value)),className:bt}),s.jsx(ws,{value:l,onValueChange:u,min:.5,max:2,step:.1,className:ye(Es,"tabular-nums")})]}),s.jsxs(Ht,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:J=>f(Number(J.target.value)),className:bt}),e?s.jsx(ws,{value:Math.round(c*100),onValueChange:J=>f(J/100),min:0,max:100,step:10,className:ye(Es,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(c*100),"%"]})]}),s.jsx(Ps,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(an,{value:q,onChange:B,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})})]})]}),s.jsxs($e,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(mt,{checked:pe,onChange:Ie,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),pe&&s.jsxs(s.Fragment,{children:[s.jsx(Ps,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.sttLocal")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]}),children:s.jsx(an,{value:L,onChange:X,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai-compatible",label:t("settings.voice.page.provider.server")}]})}),L==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:t("settings.voice.page.field.model")}),s.jsx(db,{selectedModelId:re,onSelect:de})]}),L==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Ot,!G.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Yt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:ye("relative",Vs),children:[s.jsx("input",{type:"text",value:G,onChange:J=>Z(J.target.value),placeholder:"http://localhost:8001/v1",className:In}),G&&s.jsx("button",{type:"button",onClick:()=>Z(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:"API Key"}),s.jsx("span",{className:Jn,children:"Optional"}),s.jsxs("div",{className:ye("relative",Vs),children:[s.jsx("input",{type:"password",value:le,onChange:J=>oe(J.target.value),placeholder:"sk-...",className:In}),le&&s.jsx("button",{type:"button",onClick:()=>oe(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Vs),children:s.jsx("input",{type:"text",value:he,onChange:J=>ee(J.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:In})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Ot,children:t("settings.voice.page.field.language")}),s.jsx(Yt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:ke,onChange:J=>ue(J.target.value),placeholder:"auto",className:In})})]})]})]})]})]})};function vb(t){return t.id===Br||t.installed||t.downloading}const Ei=[{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}],Di=[{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}],yb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",jb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Ir=[{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"}],wb=[".yml",".yaml",".json"],kb="settings.openchamber.tunnel.error.invalidConfigExtension",Qa=t=>{const e=t.trim().toLowerCase();return wb.some(a=>e.endsWith(a))},Nb=t=>t==="ngrok"?"ngrok":"cloudflared",Gc=()=>{if(typeof window<"u"&&typeof window.__OPENCHAMBER_PLATFORM__=="string"){const e=window.__OPENCHAMBER_PLATFORM__;if(e==="win32"||e==="darwin"||e==="linux")return e}const t=typeof navigator<"u"?`${navigator.platform||""} ${navigator.userAgent||""}`.toLowerCase():"";return t.includes("win")?"win32":t.includes("mac")?"darwin":"linux"},Sb=(t,e=Gc())=>t==="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/cloudflare-tunnel/downloads/",Pr=(t,e)=>{const a=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():t,n=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():Nb(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Gc(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Sb(a,i);return{provider:a,dependency:n,installCommand:r}},Wc=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,zl=t=>{const e=dt.c(11),{provider:a}=t;let n;e[0]!==a?(n=Wc(a),e[0]=a,e[1]=n):n=e[1];const i=n,u=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==u?(c=ye("size-4 shrink-0",u),e[2]=u,e[3]=c):c=e[3];let f;e[4]!==c?(f=s.jsx(z,{name:"cloud",className:c}),e[4]=c,e[5]=f):f=e[5];let d;e[6]!==i?(d=s.jsx("span",{children:i}),e[6]=i,e[7]=d):d=e[7];let v;return e[8]!==f||e[9]!==d?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[f,d]}),e[8]=f,e[9]=d,e[10]=v):v=e[10],v},Ln=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Vr=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,Ul=(t,e,a)=>{const n=Vr(t,e,a);return t.find(i=>i.value===n)?.label||n},_l=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),i=Math.floor(a%3600/60),r=a%60;return n>0?`${n}h ${i}m`:i>0?`${i}m ${r}s`:`${r}s`},Cb=(t,e)=>rc(t,e,{hour:"2-digit",precision:"second"}),Ki=t=>{const e=t.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},Ib=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const i of t){if(!i||typeof i!="object")continue;const r=i,l=typeof r.id=="string"?r.id.trim():"",u=typeof r.name=="string"?r.name.trim():"",c=Ki(typeof r.hostname=="string"?r.hostname:"");!l||!u||!c||e.has(l)||a.has(c)||(e.add(l),a.add(c),n.push({id:l,name:u,hostname:c}))}return n},Pb=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Ab=()=>{const{t}=et(),e=ce(Y=>Y.timeFormatPreference),a=o.useCallback(Y=>t(Y),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[u,c]=o.useState(null),[f,d]=o.useState(null),[v,p]=o.useState(null),[j,h]=o.useState(null),[w,b]=o.useState(!1),[k,m]=o.useState(!1),[I,E]=o.useState(!1),[A,N]=o.useState("cloudflare"),[x,y]=o.useState(()=>Pr("cloudflare")),[F,T]=o.useState([]),[P,D]=o.useState("quick"),[$,_]=o.useState(null),[C,R]=o.useState([]),[V,U]=o.useState({}),[W,te]=o.useState(""),[O,ie]=o.useState({}),[K,q]=o.useState(new Set),[B,L]=o.useState(!1),[X,G]=o.useState(""),[Z,le]=o.useState(""),[oe,he]=o.useState(""),[ee,re]=o.useState(1800*1e3),[de,ke]=o.useState(480*60*1e3),[ue,xe]=o.useState(""),[pe,Ie]=o.useState([]),[Te,we]=o.useState(()=>Date.now()),[De,_e]=o.useState(null),Ve=t(kb),ve=o.useRef(null),se=o.useMemo(()=>$?!Qa($):!1,[$]),ae=o.useMemo(()=>C.find(Y=>Y.id===W)||C[0]||null,[C,W]),je=o.useMemo(()=>pe.map(Y=>{const fe=Y.expiresAt<=Te,Me=Y.status==="active"&&!fe,Ee=Me?_l(Y.expiresAt-Te):Y.inactiveReason==="expired"||fe?"expired":"inactive",rt=Ee==="expired"?t("settings.openchamber.tunnel.state.expired"):Y.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),ot=Ln(Y.mode);return{...Y,isActive:Me,mode:ot,remainingTextForSession:Ee,inactiveLabel:rt}}),[Te,pe,t]),Se=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Te:!1,[Te,r?.bootstrapExpiresAt,r?.connectUrl]),Ke=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:u===P,[u,n,r,P]),Ue=o.useMemo(()=>!r||n!=="active"||!u?!1:u!==P,[u,n,r,P]),Oe=o.useMemo(()=>{if(typeof De=="number"&&Number.isFinite(De)&&De>0)return De;if(typeof window>"u")return null;const fe=ni()||window.location.href;let Me=0;try{Me=Number(new URL(fe).port)}catch{Me=Number(window.location.port)}return Number.isFinite(Me)&&Me>0?Me:null},[De]),Re=o.useMemo(()=>F.find(Y=>Y.provider===A)??null,[F,A]),Ce=o.useMemo(()=>{const Y=new Set(Re?.modes?.map(fe=>fe.key).filter(fe=>fe==="quick"||fe==="managed-remote"||fe==="managed-local"));return Y.size===0?Ir:Ir.filter(fe=>Y.has(fe.value))},[Re]),Ze=o.useMemo(()=>Ce.some(Y=>Y.value==="managed-remote"||Y.value==="managed-local"),[Ce]),be=o.useMemo(()=>x.provider===A?x:Pr(A),[x,A]),Pe=o.useCallback(async Y=>{await hn(Y)},[]),Le=o.useCallback((Y,fe)=>(y(Pr(fe,Y)),Y.available===!0),[]),Xe=o.useCallback(async(Y,fe)=>{try{const Me=await xt("/api/openchamber/tunnel/check",{query:{provider:Y},...fe?{signal:fe}:{}});if(!Me.ok)return null;const Ee=await Me.json();if(fe?.aborted)return null;const rt=Le(Ee,Y);return i(ot=>ot==="checking"||ot==="starting"||ot==="active"||ot==="stopping"?ot:rt?"idle":"not-available"),rt}catch{return null}},[Le]),Q=o.useCallback(async Y=>{try{const[fe,Me,Ee,rt]=await Promise.all([xt("/api/openchamber/tunnel/check",{signal:Y}),xt("/api/openchamber/tunnel/status",{signal:Y}),Nn(),xt("/api/openchamber/tunnel/providers",{signal:Y})]),ot=await fe.json(),Ge=await Me.json(),Nt=Ee??{},ns=rt.ok?await rt.json():{},Zt=Ge.ttlConfig?.bootstrapTtlMs??(Nt.tunnelBootstrapTtlMs===void 0?1800*1e3:Nt.tunnelBootstrapTtlMs),Qe=typeof Ge.ttlConfig?.sessionTtlMs=="number"?Ge.ttlConfig.sessionTtlMs:Nt.tunnelSessionTtlMs??480*60*1e3,Be=Ln(Ge.mode??Nt.tunnelMode),Ct=Nt.tunnelProvider??"cloudflare",Pt=Nt.managedLocalTunnelConfigPath??null,es=Le(ot,Ct),ts=Ib(Ge?.managedRemoteTunnelPresets),rs=typeof Ge.managedRemoteTunnelHostname=="string"?Ge.managedRemoteTunnelHostname:"",fs=ts.length>0?ts:rs?[{id:`legacy-${Ki(rs)}`,name:rs,hostname:Ki(rs)}]:[],Rs=fs[0]?.id||"";if(re(Zt),ke(Qe),N(Ct),T(Array.isArray(ns?.providers)?ns.providers:[]),D(Be),_(Pt),R(fs),te(Rs),Ie(Array.isArray(Ge.activeSessions)?Ge.activeSessions:[]),c(Ge.activeTunnelMode?Ln(Ge.activeTunnelMode):Ge.active&&Ge.mode?Ln(Ge.mode):null),q(new Set(Array.isArray(Ge.managedRemoteTunnelTokenPresetIds)?Ge.managedRemoteTunnelTokenPresetIds:[])),_e(typeof Ge.localPort=="number"?Ge.localPort:null),Ge.active&&Ge.url){l({url:Ge.url,connectUrl:null,bootstrapExpiresAt:typeof Ge.bootstrapExpiresAt=="number"?Ge.bootstrapExpiresAt:null}),i("active");return}i(es?"idle":"not-available")}catch{Y.aborted||(i("error"),p(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Le,t]);o.useEffect(()=>{const Y=new AbortController;return Q(Y.signal),()=>Y.abort()},[Q]),o.useEffect(()=>{if(!r?.connectUrl){d(null);return}let Y=!1;return kc.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(fe=>{Y||d(fe)}).catch(()=>{Y||d(null)}),()=>{Y=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){xe(t("settings.openchamber.tunnel.state.noExpiry"));return}let Y=null,fe=Date.now();const Me=()=>{const ot=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;ot<=0?xe(t("settings.openchamber.tunnel.state.expired")):xe(_l(ot))},Ee=()=>{const ot=Date.now();ot-fe>=1e3&&(Me(),fe=ot),Y=requestAnimationFrame(Ee)};Me(),(typeof document>"u"||document.visibilityState==="visible")&&(Y=requestAnimationFrame(Ee));const rt=()=>{document.visibilityState==="visible"&&Y===null?Y=requestAnimationFrame(Ee):document.visibilityState!=="visible"&&Y!==null&&(cancelAnimationFrame(Y),Y=null)};return document.addEventListener("visibilitychange",rt),()=>{document.removeEventListener("visibilitychange",rt),Y!==null&&cancelAnimationFrame(Y)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let Y=null,fe=Date.now();const Me=()=>{const rt=Date.now();rt-fe>=1e3&&(we(rt),fe=rt),Y=requestAnimationFrame(Me)};(typeof document>"u"||document.visibilityState==="visible")&&(Y=requestAnimationFrame(Me));const Ee=()=>{document.visibilityState==="visible"&&Y===null?Y=requestAnimationFrame(Me):document.visibilityState!=="visible"&&Y!==null&&(cancelAnimationFrame(Y),Y=null)};return document.addEventListener("visibilitychange",Ee),()=>{document.removeEventListener("visibilitychange",Ee),Y!==null&&cancelAnimationFrame(Y)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Y=!1;const fe=async()=>{try{const Ee=await xt("/api/openchamber/tunnel/status");if(!Ee.ok||Y)return;const rt=await Ee.json();if(Y)return;Ie(Array.isArray(rt.activeSessions)?rt.activeSessions:[]),q(new Set(Array.isArray(rt.managedRemoteTunnelTokenPresetIds)?rt.managedRemoteTunnelTokenPresetIds:[])),_e(typeof rt.localPort=="number"?rt.localPort:null)}catch{}},Me=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||fe()},5e3);return()=>{Y=!0,window.clearInterval(Me)}},[n]);const Ne=o.useCallback(async Y=>{E(!0);try{await yt(Y),Object.prototype.hasOwnProperty.call(Y,"tunnelMode")&&Y.tunnelMode&&D(Y.tunnelMode),Object.prototype.hasOwnProperty.call(Y,"tunnelProvider")&&typeof Y.tunnelProvider=="string"&&N(Y.tunnelProvider),Object.prototype.hasOwnProperty.call(Y,"managedLocalTunnelConfigPath")&&_(Y.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Y,"managedRemoteTunnelPresets")&&Y.managedRemoteTunnelPresets&&R(Y.managedRemoteTunnelPresets)}catch{M.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{E(!1)}},[t]),Ae=o.useCallback(async(Y,fe)=>{m(!0);try{await yt({tunnelBootstrapTtlMs:Y,tunnelSessionTtlMs:fe})}catch{M.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{m(!1)}},[t]),We=o.useCallback(async Y=>{const fe=Y.token.trim();if(fe)try{const Me={...O,[Y.presetId]:fe};await yt({managedRemoteTunnelPresetTokens:Me}),q(Ee=>{const rt=new Set(Ee);return rt.add(Y.presetId),rt})}catch{M.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[O,t]),lt=o.useCallback(async Y=>{h(null),p(null);const fe=F.find(Ee=>Ee.provider===Y),Me=fe?.modes?.some(Ee=>Ee.key===P)?P:Ln(fe?.modes?.[0]?.key);await Ne({tunnelProvider:Y,tunnelMode:Me}),Xe(Y)},[F,Xe,Ne,P]),at=o.useCallback(async()=>{const Y=await Zr({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Y.success&&typeof Y.path=="string"&&Y.path.trim().length>0){const fe=Y.path.trim();if(!Qa(fe)){M.error(Ve);return}_(fe),await Ne({managedLocalTunnelConfigPath:fe});return}ve.current?.click()},[Ve,Ne]),pt=o.useCallback(Y=>{const fe=Y.trim();_(fe.length>0?fe:null)},[]),bt=o.useCallback(async()=>{if($&&!Qa($)){M.error(Ve);return}await Ne({managedLocalTunnelConfigPath:$})},[Ve,$,Ne]),J=o.useCallback(async()=>{_(null),await Ne({managedLocalTunnelConfigPath:null})},[Ne]),qe=o.useCallback(async Y=>{const fe=Y.target.files?.[0];if(!fe)return;const Me=fe.name.trim();if(Me.length!==0){if(!Qa(Me)){M.error(Ve);return}_(Me),await Ne({managedLocalTunnelConfigPath:Me}),Y.target.value=""}},[Ve,Ne]),it=o.useCallback(async()=>{if(p(null),h(null),P==="managed-local"&&$&&!Qa($)){p(Ve),M.error(Ve);return}i("starting");try{let Y="",fe="";if(P==="managed-remote"){if(!ae){i("idle"),h(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),M.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Y=ae.hostname,fe=(O[ae.id]||"").trim(),await Ne({tunnelMode:"managed-remote",managedRemoteTunnelPresets:C})}const Me=await xt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:A,mode:P,...P==="managed-remote"&&ae?{managedRemoteTunnelPresetId:ae.id,managedRemoteTunnelPresetName:ae.name}:{},...P==="managed-remote"&&Y?{managedRemoteTunnelHostname:Y}:{},...P==="managed-remote"&&fe?{managedRemoteTunnelToken:fe}:{},...P==="managed-local"&&$?{configPath:$}:{}})}),Ee=await Me.json();if(!Me.ok||!Ee.ok){if(P==="managed-remote"&&typeof Ee.error=="string"&&Ee.error.includes("Managed remote tunnel token is required")){i("idle"),h(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),M.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),p(Ee.error||t("settings.openchamber.tunnel.toast.startFailed")),M.error(Ee.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const rt=typeof Ee.url=="string"?Ee.url:"";if(!rt){i("error"),p(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),M.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:rt,connectUrl:typeof Ee.connectUrl=="string"?Ee.connectUrl:null,bootstrapExpiresAt:typeof Ee.bootstrapExpiresAt=="number"?Ee.bootstrapExpiresAt:null}),c(Ee.activeTunnelMode?Ln(Ee.activeTunnelMode):Ee.mode?Ln(Ee.mode):P),Ie(Array.isArray(Ee.activeSessions)?Ee.activeSessions:[]),Array.isArray(Ee.managedRemoteTunnelTokenPresetIds)&&q(new Set(Ee.managedRemoteTunnelTokenPresetIds)),typeof Ee.localPort=="number"&&_e(Ee.localPort),typeof Ee.mode=="string"&&D(Ln(Ee.mode)),i("active"),Ee.replacedTunnel){const ot=typeof Ee.revokedBootstrapCount=="number"?Ee.revokedBootstrapCount:0,Ge=typeof Ee.invalidatedSessionCount=="number"?Ee.invalidatedSessionCount:0;ot===1&&Ge===1?M.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):ot===1?M.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Ge})):Ge===1?M.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:ot})):M.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:ot,invalidatedSessionCount:Ge}))}else M.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),p(t("settings.openchamber.tunnel.toast.startFailed")),M.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Ve,C,Ne,ae,O,t,A,P,$]),ct=o.useCallback(async()=>{i("stopping");try{await xt("/api/openchamber/tunnel/stop",{method:"POST"});const Y=await xt("/api/openchamber/tunnel/status");if(Y.ok){const fe=await Y.json();Ie(Array.isArray(fe.activeSessions)?fe.activeSessions:[]),q(new Set(Array.isArray(fe.managedRemoteTunnelTokenPresetIds)?fe.managedRemoteTunnelTokenPresetIds:[])),_e(typeof fe.localPort=="number"?fe.localPort:null)}l(null),c(null),d(null),i("idle"),M.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),p(t("settings.openchamber.tunnel.toast.stopFailed")),M.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),gt=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),b(!0),M.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>b(!1),2e3)}catch{M.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),Rt=o.useCallback(async Y=>{const fe=Ei.find(Me=>Me.value===Y);fe&&(re(fe.ms),await Ae(fe.ms,de))},[Ae,de]),tt=o.useCallback(async Y=>{const fe=Di.find(Me=>Me.value===Y);!fe||fe.ms===null||(ke(fe.ms),await Ae(ee,fe.ms))},[ee,Ae]),ft=o.useCallback(async Y=>{h(null),p(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await Ne({tunnelMode:Y,managedRemoteTunnelPresets:C})},[C,Ne,n]),jt=o.useCallback(async(Y,fe)=>{try{await yt({managedRemoteTunnelPresets:fe})}catch{M.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Je=o.useCallback(Y=>{const fe=C.find(Me=>Me.id===Y);fe&&(te(fe.id),h(null),jt(fe,C))},[C,jt]),St=o.useCallback(async()=>{const Y=X.trim(),fe=Ki(Z),Me=oe.trim();if(!Y){M.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!fe){M.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Me){M.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(C.some(ot=>ot.hostname===fe)){M.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ee={id:Pb(),name:Y,hostname:fe},rt=[...C,Ee];R(rt),te(Ee.id),U(ot=>({...ot,[Ee.id]:!0})),ie(ot=>({...ot,[Ee.id]:Me})),h(null),L(!1),G(""),le(""),he(""),await Ne({tunnelMode:"managed-remote",managedRemoteTunnelPresets:rt,managedRemoteTunnelPresetTokens:{...O,[Ee.id]:Me}}),await We({presetId:Ee.id,presetName:Ee.name,hostname:Ee.hostname,token:Me}),M.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[C,Z,X,oe,We,Ne,O,t]),Fe=o.useCallback(async Y=>{const fe=C.find(Ge=>Ge.id===Y);if(!fe)return;const Me=C.filter(Ge=>Ge.id!==fe.id),Ee=Me[0]?.id||"",rt=W===fe.id?Ee:W,ot=Object.fromEntries(Object.entries(O).filter(([Ge,Nt])=>Ge!==fe.id&&Nt.trim().length>0));R(Me),te(rt),U(Ge=>{const Nt={...Ge};return delete Nt[fe.id],Nt}),ie(Ge=>{const Nt={...Ge};return delete Nt[fe.id],Nt}),q(Ge=>{const Nt=new Set(Ge);return Nt.delete(fe.id),Nt}),h(null),await Ne({managedRemoteTunnelPresets:Me,managedRemoteTunnelPresetTokens:ot}),M.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[C,Ne,W,O,t]),wt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.openchamber.tunnel.state.loading")})}):s.jsx($e,{title:t("settings.openchamber.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.openchamber.tunnel.description")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[je.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(z,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:ko,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:je.map(Y=>{const fe=Y.mode==="quick",Me=Y.mode==="managed-remote",Ee=fe?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Me?"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)]",rt=Y.isActive?fe?"text-[var(--status-warning)]":Me?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",ot=t(fe?"settings.openchamber.tunnel.badge.quick":Me?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(z,{name:"checkbox-blank-circle-fill",className:ye("size-2.5 shrink-0",rt)}),s.jsx("span",{className:ye("typography-micro rounded border px-1.5 py-0.5 uppercase",Ee),children:ot}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:Cb(Y.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Y.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Y.remainingTextForSession}):Y.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:Y.inactiveLabel})})]},Y.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:ko,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:be.dependency})}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:be.installCommand})]})]})}),s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{"data-settings-item":"tunnel.provider",className:"space-y-1.5",children:[s.jsx("p",{className:Ot,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Et,{value:A,onValueChange:Y=>{lt(Y)},disabled:I||n==="starting"||n==="stopping",children:[s.jsx(Dt,{size:Gt,className:"max-w-[16rem]",children:s.jsx(_t,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Wc(A)})}),s.jsxs(Mt,{children:[F.length>0?F.map(Y=>s.jsx(ut,{value:Y.provider,children:s.jsx(zl,{provider:Y.provider})},Y.provider)):s.jsx(ut,{value:"cloudflare",children:s.jsx(zl,{provider:"cloudflare"})}),s.jsx(ut,{value:"__more-soon",disabled:!0,children:t("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Ot,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Ce.map(Y=>s.jsxs(Wr,{children:[s.jsx(Jr,{asChild:!0,children:s.jsx(H,{variant:"chip",size:"xs","aria-pressed":P===Y.value,className:"!font-normal",onClick:()=>{ft(Y.value)},disabled:I||n==="starting"||n==="stopping",children:a(Y.labelKey)})}),s.jsx(tc,{sideOffset:8,className:"max-w-xs",children:a(Y.tooltipKey)})]},Y.value))})]})]}),s.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:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Ot,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Et,{value:Vr(Ei,ee,"1800000"),onValueChange:Y=>{Rt(Y)},disabled:k||I||n==="starting"||n==="stopping",children:[s.jsx(Dt,{size:Gt,className:"max-w-[11rem] min-w-0",children:s.jsx(_t,{className:"truncate",children:Ul(Ei,ee,"1800000")})}),s.jsx(Mt,{children:Ei.map(Y=>s.jsx(ut,{value:Y.value,children:Y.label},Y.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Ot,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Et,{value:Vr(Di,de,"28800000"),onValueChange:Y=>{tt(Y)},disabled:k||I||n==="starting"||n==="stopping",children:[s.jsx(Dt,{size:Gt,className:"max-w-[11rem] min-w-0",children:s.jsx(_t,{className:"truncate",children:Ul(Di,de,"28800000")})}),s.jsx(Mt,{children:Di.map(Y=>s.jsx(ut,{value:Y.value,children:Y.label},Y.value))})]})]})]}),P==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),Ze&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),P==="managed-remote"&&s.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 Oe=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Oe]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(rn,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>L(Y=>!Y),disabled:n==="starting"||n==="stopping"||I,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),C.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:C.map((Y,fe)=>{const Me=O[Y.id]||"",Ee=K.has(Y.id),rt=V[Y.id]??!1;return s.jsx("div",{className:ye(fe<C.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(yn,{open:rt,onOpenChange:ot=>{U(Ge=>({...Ge,[Y.id]:ot})),ot&&Je(Y.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(jn,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||I,children:[rt?s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:Y.name})]}),s.jsx(H,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:Y.name}),onClick:()=>{Fe(Y.id)},disabled:n==="starting"||n==="stopping"||I,children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(wn,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:Y.hostname})]}),s.jsx(He,{type:"password",value:Me,onChange:ot=>{const Ge=ot.target.value;h(null),ie(Nt=>({...Nt,[Y.id]:Ge}))},onBlur:ot=>{const Ge=ot.currentTarget.value.trim();Ge&&We({presetId:Y.id,presetName:Y.name,hostname:Y.hostname,token:Ge})},placeholder:t(Ee?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Me.trim().length===0,onClick:()=>{We({presetId:Y.id,presetName:Y.name,hostname:Y.hostname,token:Me})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},Y.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),B&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(He,{value:X,onChange:Y=>G(Y.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:I||n==="starting"||n==="stopping"}),s.jsx(He,{value:Z,onChange:Y=>le(Y.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:I||n==="starting"||n==="stopping"}),s.jsx(He,{type:"password",value:oe,onChange:Y=>he(Y.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:I||n==="starting"||n==="stopping"}),typeof Oe=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Oe]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{St()},disabled:I||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{L(!1),G(""),le(""),he("")},disabled:I||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Yt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!ae&&j&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:j})]}),P==="managed-local"&&s.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:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Ot,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:ve,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Y=>{qe(Y)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:$||"",onChange:Y=>{pt(Y.target.value)},onBlur:()=>{bt()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||I}),s.jsx(H,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{at()},disabled:n==="starting"||n==="stopping"||I,children:s.jsx(z,{name:"folder",className:"size-3.5"})}),$&&s.jsx(H,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{J()},disabled:n==="starting"||n==="stopping"||I,children:s.jsx(z,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t($?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),se&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ve})]})}),!Ke&&s.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[P==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Pe(yb)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(z,{name:"external-link",className:"size-3.5"})]})]}),P==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Pe(jb)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(z,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:a(Ir.find(Y=>Y.value===P)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),P==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Ot,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Et,{value:W||(C[0]?.id??""),onValueChange:Y=>{Je(Y)},disabled:I||n==="starting"||n==="stopping"||C.length<=1,children:[s.jsx(Dt,{size:Gt,children:s.jsx(_t,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:ae?.name})}),s.jsx(Mt,{fitContent:!0,children:C.map(Y=>s.jsx(ut,{value:Y.id,children:Y.name},Y.id))})]})]}),Ue&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(H,{size:"sm",variant:"outline",onClick:it,disabled:n==="starting"||I||P==="managed-remote"&&!ae||P==="managed-local"&&se,className:ye(wt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ke&&r&&s.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.url})]}),Se&&r.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.connectUrl}),s.jsxs(H,{size:"sm",variant:"ghost",onClick:gt,className:"shrink-0 gap-1.5",children:[w?s.jsx(z,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(z,{name:"file-copy",className:"size-3.5"}),t(w?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",r.bootstrapExpiresAt?ue:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[f?s.jsx("img",{src:f,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{size:"sm",variant:"outline",onClick:it,disabled:n==="stopping"||I||P==="managed-local"&&se,className:wt,children:[s.jsx(z,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:ct,disabled:n==="stopping"||I,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&v&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v}),s.jsx(H,{size:"sm",variant:"ghost",onClick:it,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},Jc=()=>{const{t}=et(),[e,a]=Ye.useState(""),[n,i]=Ye.useState(!0),[r,l]=Ye.useState(!1),u=ce(p=>p.showOpenCodeUpdateNotifications),c=ce(p=>p.setShowOpenCodeUpdateNotifications);Ye.useEffect(()=>{let p=!1;return(async()=>{try{const j=await Nn();if(p||!j)return;a(j.opencodeBinary??"")}catch{}finally{p||i(!1)}})(),()=>{p=!0}},[]);const f=Ye.useCallback(async()=>{if(!(typeof window>"u")&&cs())try{const p=await Zr();p.success&&p.path&&p.path.trim().length>0&&a(p.path.trim())}catch{}},[]),d=Ye.useCallback(async()=>{l(!0);try{const p=e.trim(),j=p.length>=2&&(p.startsWith('"')&&p.endsWith('"')||p.startsWith("'")&&p.endsWith("'"))?p.slice(1,-1).trim():p;await yt({opencodeBinary:j}),ta("cli",{id:"opencode-binary"}),M.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),v=Ye.useCallback(p=>{c(p),yt({showOpenCodeUpdateNotifications:p})},[c]);return s.jsx($e,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Ht,{settingsItem:"sessions.opencode-binary",label:t("settings.openchamber.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(He,{value:e,onChange:p=>a(p.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:n||r,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(H,{type:"button",variant:"outline",size:"xs",onClick:f,disabled:n||r||!cs(),className:ys,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(z,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Fa,{className:js,children:[!vc()&&s.jsx(mt,{settingsItem:"sessions.opencode-update-notifications",checked:u,onChange:v,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(H,{type:"button",size:"xs",onClick:d,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},Qc=()=>{const t=dt.c(44),{t:e}=et(),a=ce(Tb),n=ce(Eb),i=ce(Db),r=ce(Mb),l=ce(Rb),u=ce(Fb),c=ce(Ob);let f;t[0]!==n?(f=P=>{n(P),yt({agentControlToolEnabled:P}),ta("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=f):f=t[1];const d=f;let v;t[2]!==r?(v=P=>{r(P),yt({agentWebToolEnabled:P}),ta("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=v):v=t[3];const p=v;let j;t[4]!==c?(j=P=>{c(P),yt({agentMemoryToolEnabled:P}).finally(()=>{P&&nu.getState().refresh()}),ta("cli",{id:"agent-memory-tool"})},t[4]=c,t[5]=j):j=t[5];const h=j;let w;t[6]!==e?(w=e("settings.openchamber.tools.title"),t[6]=e,t[7]=w):w=t[7];let b;t[8]!==e?(b=e("settings.openchamber.tools.field.agentControlTool"),t[8]=e,t[9]=b):b=t[9];let k;t[10]!==e?(k=e("settings.openchamber.tools.field.agentControlToolAria"),t[10]=e,t[11]=k):k=t[11];let m;t[12]!==e?(m=e("settings.openchamber.tools.field.agentControlToolInfo"),t[12]=e,t[13]=m):m=t[13];let I;t[14]!==a||t[15]!==d||t[16]!==b||t[17]!==k||t[18]!==m?(I=s.jsx(mt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:d,label:b,ariaLabel:k,info:m}),t[14]=a,t[15]=d,t[16]=b,t[17]=k,t[18]=m,t[19]=I):I=t[19];let E;t[20]!==e?(E=e("settings.openchamber.tools.field.agentWebTool"),t[20]=e,t[21]=E):E=t[21];let A;t[22]!==e?(A=e("settings.openchamber.tools.field.agentWebToolAria"),t[22]=e,t[23]=A):A=t[23];let N;t[24]!==e?(N=e("settings.openchamber.tools.field.agentWebToolInfo"),t[24]=e,t[25]=N):N=t[25];let x;t[26]!==i||t[27]!==p||t[28]!==N||t[29]!==E||t[30]!==A?(x=s.jsx(mt,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:p,label:E,ariaLabel:A,info:N}),t[26]=i,t[27]=p,t[28]=N,t[29]=E,t[30]=A,t[31]=x):x=t[31];let y;t[32]!==u||t[33]!==l||t[34]!==h||t[35]!==e?(y=u?s.jsx(mt,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:h,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[32]=u,t[33]=l,t[34]=h,t[35]=e,t[36]=y):y=t[36];let F;t[37]!==x||t[38]!==y||t[39]!==I?(F=s.jsxs("div",{className:js,children:[I,x,y]}),t[37]=x,t[38]=y,t[39]=I,t[40]=F):F=t[40];let T;return t[41]!==F||t[42]!==w?(T=s.jsx($e,{title:w,children:F}),t[41]=F,t[42]=w,t[43]=T):T=t[43],T};function Tb(t){return t.agentControlToolEnabled}function Eb(t){return t.setAgentControlToolEnabled}function Db(t){return t.agentWebToolEnabled}function Mb(t){return t.setAgentWebToolEnabled}function Rb(t){return t.agentMemoryToolEnabled}function Fb(t){return t.agentMemoryFeatureAvailable}function Ob(t){return t.setAgentMemoryToolEnabled}const Yc=()=>{const{t}=et(),e=cs()&&ai(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=Ye.useState(!1),[r,l]=Ye.useState(!1),[u,c]=Ye.useState(!1),[f,d]=Ye.useState(""),[v,p]=Ye.useState(!1),[j,h]=Ye.useState(!1),[w,b]=Ye.useState(null),[k,m]=Ye.useState(!0),[I,E]=Ye.useState(!1),[A,N]=Ye.useState(!1),[x,y]=Ye.useState(!1),[F,T]=Ye.useState(!1),[P,D]=Ye.useState(!1),[$,_]=Ye.useState(!1),[C,R]=Ye.useState(!1),[V,U]=Ye.useState(!0),[W,te]=Ye.useState(!0),[O,ie]=Ye.useState(!1),[K,q]=Ye.useState(!1),[B,L]=Ye.useState(!1),[X,G]=Ye.useState(null),[Z,le]=Ye.useState(null);Ye.useEffect(()=>{if(!e){m(!1);return}let ve=!1;return(async()=>{try{const se=await Nn();if(!se)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));if(ve)return;const ae=se.desktopLanAccessEnabled===!0;i(ae),l(ae),c(se.hasDesktopUiPassword===!0),d(""),p(!1),h(se.desktopLanAccessActive===!0),b(se.desktopLanAccessBlockedReason??null);const je=se.desktopMacMenuBarEnabled!==!1;U(je),te(je),G(null)}catch(se){ve||G(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{ve||m(!1)}})(),()=>{ve=!0}},[e,t]),Ye.useEffect(()=>{if(!e){N(!1);return}let ve=!1;return(async()=>{const se=await Ku();ve||(N(se?.supported===!0),y(se?.enabled===!0))})(),()=>{ve=!0}},[e]),Ye.useEffect(()=>{if(!e){D(!1);return}let ve=!1;return(async()=>{const se=await zu();ve||(D(se?.supported===!0),_(se?.enabled===!0))})(),()=>{ve=!0}},[e]),Ye.useEffect(()=>{if(!e){ie(!1);return}let ve=!1;return(async()=>{const se=await Uu();ve||(ie(se?.supported===!0),q(se?.enabled===!0))})(),()=>{ve=!0}},[e]),Ye.useEffect(()=>{if(!e||!r){le(null);return}let ve=!1;return(async()=>{const se=await hc();ve||le(se)})(),()=>{ve=!0}},[r,e]);const oe=f.trim(),he=oe.length>0||v,ee=r!==n||he||W!==V,re=Ye.useMemo(()=>{if(typeof window>"u")return null;const se=ni()||window.location.href;let ae=0;try{ae=Number(new URL(se).port)}catch{ae=Number(window.location.port)}return Number.isFinite(ae)&&ae>0?ae:null},[]),de=r&&j&&Z&&re?`http://${Z}:${re}`:null,ke=oe.length>0||u&&!v,ue=r&&!ke,xe=n&&!j&&w==="missing-password",pe=k||I||!ee||ue,Ie=Ye.useCallback(ve=>{d(ve),ve.trim()&&p(!1)},[]),Te=Ye.useCallback(()=>{d(""),p(!0),l(!1)},[]),we=Ye.useCallback(async()=>{if(!A||F)return;const ve=!x;y(ve),T(!0),G(null);try{const se=await _u(ve);if(!se?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));y(se.enabled)}catch(se){y(!ve),G(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{T(!1)}},[F,x,A,t]),De=Ye.useCallback(async()=>{if(!P||C)return;const ve=!$;_(ve),R(!0),G(null);try{const se=await $u(ve);if(!se)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!se.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));_(se.enabled)}catch(se){_(!ve),G(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{R(!1)}},[C,$,P,t]),_e=Ye.useCallback(async()=>{if(!O||B)return;const ve=!K;q(ve),L(!0),G(null);try{const se=await Bu(ve);if(!se?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));q(se.enabled)}catch(se){q(!ve),G(se instanceof Error?se.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{L(!1)}},[B,K,O,t]),Ve=Ye.useCallback(async()=>{if(ee){E(!0),G(null);try{if(!(await yt({desktopLanAccessEnabled:r,...oe?{desktopUiPassword:oe}:v?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:W})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(r),oe?c(!0):v&&c(!1),d(""),p(!1),U(W),!await Vu())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(ve){G(ve instanceof Error?ve.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),E(!1)}}},[W,r,ee,oe,v,t]);return e?s.jsx($e,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[A||a||P||O?s.jsxs("div",{className:js,children:[A?s.jsx(mt,{settingsItem:"sessions.desktop-launch-at-login",checked:x,onChange:ve=>{ve!==x&&we()},disabled:F,label:t("settings.openchamber.desktopNetwork.field.launchAtLogin"),info:t("settings.openchamber.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(mt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:W,onChange:te,disabled:k||I,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,P?s.jsx(mt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:$,onChange:ve=>{ve!==$&&De()},disabled:C,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,O?s.jsx(mt,{settingsItem:"sessions.desktop-keep-awake",checked:K,onChange:ve=>{ve!==K&&_e()},disabled:B,label:t("settings.openchamber.desktopNetwork.field.keepAwake"),info:t("settings.openchamber.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(Kt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),info:t("settings.openchamber.desktopPassword.field.passwordDescription"),children:[s.jsx(He,{id:"desktop-ui-password",type:"password",className:"h-8 min-w-0 flex-1",value:f,onChange:ve=>Ie(ve.target.value),placeholder:t(u&&!v?"settings.openchamber.desktopPassword.field.passwordSetPlaceholder":"settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:k||I,required:r&&!ke,"aria-invalid":ue}),u&&!v?s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:Te,disabled:k||I,className:"shrink-0 !font-normal",children:t("settings.openchamber.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:js,children:s.jsx(mt,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:k||I,label:t("settings.openchamber.desktopNetwork.field.allowLanAccess"),info:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription"),description:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")}),ue||xe?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria")})}),X?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:X}):null,de?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(ee&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:de})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(H,{type:"button",size:"xs",onClick:Ve,disabled:pe,className:"shrink-0 !font-normal",children:t(I?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},Zc=new Set(["shift","control","alt","meta"]),co=3,Lb=3e3;function uo(t,e=!1){const a=new Set;return t.altKey&&a.add("alt"),t.ctrlKey&&a.add("control"),t.metaKey&&a.add("meta"),t.shiftKey&&a.add("shift"),e&&a.add(t.key.toLowerCase()),a.size}function Kb(t){return t.action.customizable}function $l(t){if(uo(t)>co)return null;const e=[];return(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),e.length>0?Vi(e.join("+")):null}function zb(t){if(Zc.has(t.key.toLowerCase())||uo(t,!0)>co)return null;const e=ru(ou(t));if(!e)return null;const a=[];return(t.metaKey||t.ctrlKey)&&a.push("mod"),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a.push(e),Vi(a.join("+"))}function Ub(t){const e=t.key.toLowerCase();if(!Zc.has(e)||uo(t,!0)>co)return null;const a=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&a.push("mod"),(t.shiftKey||e==="shift")&&a.push("shift"),(t.altKey||e==="alt")&&a.push("alt"),a.length>0?Vi(a.join("+")):null}function Bl(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function _b(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:$l(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=zb(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const i=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:i,livePreview:null,settled:i.length===2}}return{...t,livePreview:$l(e)}}const $b=t=>{const e=dt.c(117),{action:a,overrides:n,onSave:i,onOpenChange:r}=t,{t:l}=et();let u;e[0]!==l?(u=re=>l(re.settingsLabelKey),e[0]=l,e[1]=u):u=e[1];const c=u;let f;e[2]!==c?(f=re=>re.action.customizable?c(re.action):ia(re.action.defaultBinding),e[2]=c,e[3]=f):f=e[3];const d=f;let v;e[4]===Symbol.for("react.memo_cache_sentinel")?(v={chords:[],livePreview:null,settled:!1},e[4]=v):v=e[4];const[p,j]=o.useState(v),h=o.useRef(null);let w,b;e[5]!==a?(w=()=>{a&&(j({chords:[],livePreview:null,settled:!1}),h.current?.focus())},b=[a],e[5]=a,e[6]=w,e[7]=b):(w=e[6],b=e[7]),o.useEffect(w,b);const k=p.chords.length===1&&!p.settled;let m,I;e[8]!==k?(m=()=>{if(!k)return;const re=window.setTimeout(()=>j(Bl),Lb);return()=>window.clearTimeout(re)},I=[k],e[8]=k,e[9]=m,e[10]=I):(m=e[9],I=e[10]),o.useEffect(m,I);let E;e[11]!==p.chords?(E=Vi(p.chords.join(" ")),e[11]=p.chords,e[12]=E):E=e[12];const A=E;let N;e[13]!==a||e[14]!==A||e[15]!==n?(N=a&&A?au(a.id,A,n):[],e[13]=a,e[14]=A,e[15]=n,e[16]=N):N=e[16];const x=N;let y;e[17]!==x?(y=x.find(Bb),e[17]=x,e[18]=y):y=e[18];const F=y;let T,P,D,$,_,C,R,V,U,W,te,O,ie,K,q;if(e[19]!==a||e[20]!==c||e[21]!==A||e[22]!==d||e[23]!==x||e[24]!==r||e[25]!==i||e[26]!==F||e[27]!==p||e[28]!==l){const re=x.filter(Kb);_=re.find(Vb);const de=re.find(Hb),ke=x.find(qb);let ue;e[44]!==r?(ue=()=>r(!1),e[44]=r,e[45]=ue):ue=e[45],D=ue,$=()=>{p.settled||j(Bl),!(!a||!A||F||_)&&(i(a.id,A,de?.action.id),D())};let xe;e[46]!==a||e[47]!==p?(xe=(Ke,Ue)=>{Ke.preventDefault(),Ke.stopPropagation();const Oe=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Ue==="keyup"&&Oe&&p.chords.length===0){const Ce=Ub(Ke);if(Ce){j({chords:[Ce],livePreview:null,settled:!0});return}}const Re=_b(p,{altKey:Ke.altKey,code:Ke.nativeEvent.code,ctrlKey:Ke.ctrlKey,isComposing:Ke.nativeEvent.isComposing,key:Ke.key,metaKey:Ke.metaKey,repeat:Ke.repeat,shiftKey:Ke.shiftKey},Ue);j(Oe&&Re.chords.length>1?p:Re)},e[46]=a,e[47]=p,e[48]=xe):xe=e[48];const pe=xe;P=zt,K=a!==null,q=Gb,T=Ut,C="max-w-md",R=h,V=!1;let Ie;e[49]!==a||e[50]!==c||e[51]!==l?(Ie=a?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:c(a)}):"",e[49]=a,e[50]=c,e[51]=l,e[52]=Ie):Ie=e[52];let Te;e[53]!==Ie?(Te=s.jsx(Bt,{children:Ie}),e[53]=Ie,e[54]=Te):Te=e[54];let we;e[55]!==l?(we=l("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=we):we=e[56];let De;e[57]!==we?(De=s.jsx(Vt,{children:we}),e[57]=we,e[58]=De):De=e[58],e[59]!==Te||e[60]!==De?(U=s.jsxs($t,{children:[Te,De]}),e[59]=Te,e[60]=De,e[61]=U):U=e[61];let _e,Ve;e[62]!==pe?(_e=Ke=>pe(Ke,"keydown"),Ve=Ke=>pe(Ke,"keyup"),e[62]=pe,e[63]=_e,e[64]=Ve):(_e=e[63],Ve=e[64]);let ve;e[65]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>j(Wb),e[65]=ve):ve=e[65];let se;e[66]!==p.chords?(se=p.chords.map(Jb),e[66]=p.chords,e[67]=se):se=e[67];let ae;e[68]!==p.livePreview?(ae=p.livePreview?s.jsx("kbd",{className:"rounded-md border border-dashed border-border bg-muted px-3 py-2 typography-ui-label font-mono text-muted-foreground",children:ia(p.livePreview)}):null,e[68]=p.livePreview,e[69]=ae):ae=e[69];let je;e[70]!==p.chords.length||e[71]!==p.livePreview||e[72]!==l?(je=p.chords.length===0&&!p.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=p.chords.length,e[71]=p.livePreview,e[72]=l,e[73]=je):je=e[73];let Se;e[74]!==se||e[75]!==ae||e[76]!==je?(Se=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[se,ae,je]}),e[74]=se,e[75]=ae,e[76]=je,e[77]=Se):Se=e[77],e[78]!==_e||e[79]!==Ve||e[80]!==Se?(W=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:h,onKeyDown:_e,onKeyUp:Ve,onBlur:ve,children:Se}),e[78]=_e,e[79]=Ve,e[80]=Se,e[81]=W):W=e[81],te=p.settled&&F?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):p.settled&&_?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:c(_.action)})}):null,O=p.settled&&de&&!F&&!_?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:c(de.action)})}):null,ie=p.settled&&ke&&!F&&!_?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:d(ke)})}):null,e[19]=a,e[20]=c,e[21]=A,e[22]=d,e[23]=x,e[24]=r,e[25]=i,e[26]=F,e[27]=p,e[28]=l,e[29]=T,e[30]=P,e[31]=D,e[32]=$,e[33]=_,e[34]=C,e[35]=R,e[36]=V,e[37]=U,e[38]=W,e[39]=te,e[40]=O,e[41]=ie,e[42]=K,e[43]=q}else T=e[29],P=e[30],D=e[31],$=e[32],_=e[33],C=e[34],R=e[35],V=e[36],U=e[37],W=e[38],te=e[39],O=e[40],ie=e[41],K=e[42],q=e[43];let B;e[82]!==A||e[83]!==p.settled||e[84]!==l?(B=p.settled&&A&&iu(A)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=A,e[83]=p.settled,e[84]=l,e[85]=B):B=e[85];let L;e[86]!==l?(L=l("settings.common.actions.cancel"),e[86]=l,e[87]=L):L=e[87];let X;e[88]!==D||e[89]!==L?(X=s.jsx(H,{type:"button",variant:"ghost",size:"sm",onClick:D,children:L}),e[88]=D,e[89]=L,e[90]=X):X=e[90];const G=!A||p.settled&&(!!F||!!_);let Z;e[91]!==l?(Z=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=Z):Z=e[92];let le;e[93]!==$||e[94]!==G||e[95]!==Z?(le=s.jsx(H,{type:"button",size:"sm",disabled:G,onClick:$,children:Z}),e[93]=$,e[94]=G,e[95]=Z,e[96]=le):le=e[96];let oe;e[97]!==X||e[98]!==le?(oe=s.jsxs(is,{children:[X,le]}),e[97]=X,e[98]=le,e[99]=oe):oe=e[99];let he;e[100]!==T||e[101]!==C||e[102]!==R||e[103]!==V||e[104]!==U||e[105]!==W||e[106]!==te||e[107]!==O||e[108]!==ie||e[109]!==B||e[110]!==oe?(he=s.jsxs(T,{className:C,initialFocus:R,showCloseButton:V,children:[U,W,te,O,ie,B,oe]}),e[100]=T,e[101]=C,e[102]=R,e[103]=V,e[104]=U,e[105]=W,e[106]=te,e[107]=O,e[108]=ie,e[109]=B,e[110]=oe,e[111]=he):he=e[111];let ee;return e[112]!==P||e[113]!==K||e[114]!==q||e[115]!==he?(ee=s.jsx(P,{open:K,onOpenChange:q,children:he}),e[112]=P,e[113]=K,e[114]=q,e[115]=he,e[116]=ee):ee=e[116],ee};function Bb(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function Vb(t){return t.kind==="prefix"}function Hb(t){return t.kind==="exact"}function qb(t){return t.kind==="contextual-prefix"}function Gb(t,e){t||e.cancel()}function Wb(t){return{...t,livePreview:null}}function Jb(t,e){return s.jsx("kbd",{className:"rounded-md border border-border bg-muted px-3 py-2 typography-ui-label font-mono text-foreground",children:ia(t)},`${t}-${e}`)}const Qb=["session","models","panels","navigation","application"],Yb=()=>{const t=dt.c(24),{t:e}=et(),a=ce(Zb),n=ce(Xb),i=ce(ev),r=ce(tv),[l,u]=o.useState(null);let c;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const A=lu();c=ds()?A.filter(sv):A,t[0]=c}else c=t[0];const f=c,d=nv;let v;t[1]!==n||t[2]!==a?(v=(A,N,x)=>{const y={...a,[A]:N};x&&(y[x]=pr),n(A,N),x&&n(x,pr),d(y)},t[1]=n,t[2]=a,t[3]=v):v=t[3];const p=v;let j;t[4]!==i||t[5]!==a?(j=A=>{const N={...a};delete N[A],i(A),d(N)},t[4]=i,t[5]=a,t[6]=j):j=t[6];const h=j;let w;t[7]!==a||t[8]!==e?(w=A=>{const N="prefixStyle"in A&&A.prefixStyle,x=N?cu(A.id,a):mc(A.id,a),y=ia(x,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!N||!x||x===pr)return y;const F=A.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${y}${F}`},t[7]=a,t[8]=e,t[9]=w):w=t[9];const b=w;let k;t[10]!==r||t[11]!==h||t[12]!==b||t[13]!==a||t[14]!==e?(k=Qb.map((A,N)=>{const x=f.filter(y=>y.category===A);return x.length===0?null:s.jsx($e,{settingsItem:N===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${A}`),divider:N!==0,info:N===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:N===0?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{r(),d({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:x.map(y=>s.jsxs(Ht,{label:e(y.settingsLabelKey),children:[s.jsx("kbd",{className:"min-w-32 rounded-md border border-border bg-muted px-2 py-1 text-center typography-meta font-mono text-foreground",children:b(y)}),s.jsx(H,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>u(y),children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),y.id in a?s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>h(y.id),children:e("settings.common.actions.reset")}):null]},y.id))})},A)}),t[10]=r,t[11]=h,t[12]=b,t[13]=a,t[14]=e,t[15]=k):k=t[15];let m;t[16]===Symbol.for("react.memo_cache_sentinel")?(m=A=>{A||u(null)},t[16]=m):m=t[16];let I;t[17]!==l||t[18]!==p||t[19]!==a?(I=s.jsx($b,{action:l,overrides:a,onSave:p,onOpenChange:m}),t[17]=l,t[18]=p,t[19]=a,t[20]=I):I=t[20];let E;return t[21]!==k||t[22]!==I?(E=s.jsxs(s.Fragment,{children:[k,I]}),t[21]=k,t[22]=I,t[23]=E):E=t[23],E};function Zb(t){return t.shortcutOverrides}function Xb(t){return t.setShortcutOverride}function ev(t){return t.clearShortcutOverride}function tv(t){return t.resetAllShortcutOverrides}function sv(t){return t.id!=="toggle_prompt_navigator"}function nv(t){yt({shortcutOverrides:t})}const Xc=()=>{const t=dt.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>Hi(()=>a(gv)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},av=t=>{const e=dt.c(83),{section:a}=t,{t:n}=et(),{isMobile:i}=ua(),r=Xc();let l;e[0]!==i?(l=i&&na(),e[0]=i,e[1]=l):l=e[1];const u=l;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=ds(),e[2]=c):c=e[2];const f=c;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=cs()&&ai(),e[3]=d):d=e[3];const v=d;if(!a){let ie;e[4]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(qi,{}),e[4]=ie):ie=e[4];let K;e[5]!==r?(K=s.jsx(qc,{},r),e[5]=r,e[6]=K):K=e[6];let q,B,L,X,G,Z;e[7]===Symbol.for("react.memo_cache_sentinel")?(L=v&&s.jsx(Yc,{}),X=!f&&s.jsx(Jc,{}),G=!f&&s.jsx(Qc,{}),Z=s.jsx(Bc,{}),q=s.jsx(Hc,{}),B=na()&&!cs()&&!f&&!yc()&&s.jsx(Vc,{}),e[7]=q,e[8]=B,e[9]=L,e[10]=X,e[11]=G,e[12]=Z):(q=e[7],B=e[8],L=e[9],X=e[10],G=e[11],Z=e[12]);let le;e[13]!==u?(le=u&&s.jsx(Nc,{}),e[13]=u,e[14]=le):le=e[14];let oe;return e[15]!==le||e[16]!==K?(oe=s.jsxs(os,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[ie,K,L,X,G,Z,q,B,le]}),e[15]=le,e[16]=K,e[17]=oe):oe=e[17],oe}let p;e[18]!==r||e[19]!==a?(p=()=>{switch(a){case"general":return s.jsx(rv,{});case"visual":return s.jsx(ov,{});case"chat":return s.jsx(lv,{});case"sessions":return s.jsx(cv,{runtimeEndpointEpoch:r});case"shortcuts":return s.jsx(iv,{});case"git":return s.jsx(dv,{});case"notifications":return s.jsx(uv,{});case"voice":return s.jsx(pv,{});case"tunnel":return s.jsx(mv,{});default:return null}},e[18]=r,e[19]=a,e[20]=p):p=e[20];const j=p;let h;e[21]!==n?(h=n("settings.page.general.title"),e[21]=n,e[22]=h):h=e[22];let w;e[23]!==n?(w=n("settings.page.appearance.title"),e[23]=n,e[24]=w):w=e[24];let b;e[25]!==n?(b=n("settings.page.chat.title"),e[25]=n,e[26]=b):b=e[26];let k;e[27]!==n?(k=n("settings.page.sessions.title"),e[27]=n,e[28]=k):k=e[28];let m;e[29]!==n?(m=n("settings.page.shortcuts.title"),e[29]=n,e[30]=m):m=e[30];let I;e[31]!==n?(I=n("settings.page.git.title"),e[31]=n,e[32]=I):I=e[32];let E;e[33]!==n?(E=n("settings.page.git.title"),e[33]=n,e[34]=E):E=e[34];let A;e[35]!==n?(A=n("settings.page.notifications.title"),e[35]=n,e[36]=A):A=e[36];let N;e[37]!==n?(N=n("settings.page.voice.title"),e[37]=n,e[38]=N):N=e[38];let x;e[39]!==n?(x=n("settings.page.tunnel.title"),e[39]=n,e[40]=x):x=e[40];let y;e[41]!==I||e[42]!==E||e[43]!==A||e[44]!==N||e[45]!==x||e[46]!==h||e[47]!==w||e[48]!==b||e[49]!==k||e[50]!==m?(y={general:h,visual:w,chat:b,sessions:k,shortcuts:m,git:I,github:E,notifications:A,voice:N,tunnel:x},e[41]=I,e[42]=E,e[43]=A,e[44]=N,e[45]=x,e[46]=h,e[47]=w,e[48]=b,e[49]=k,e[50]=m,e[51]=y):y=e[51];const F=y[a];let T;e[52]!==n?(T=n("settings.page.general.description"),e[52]=n,e[53]=T):T=e[53];let P;e[54]!==n?(P=n("settings.page.appearance.description"),e[54]=n,e[55]=P):P=e[55];let D;e[56]!==n?(D=n("settings.page.chat.description"),e[56]=n,e[57]=D):D=e[57];let $;e[58]!==n?($=n("settings.page.sessions.description"),e[58]=n,e[59]=$):$=e[59];let _;e[60]!==n?(_=n("settings.page.shortcuts.description"),e[60]=n,e[61]=_):_=e[61];let C;e[62]!==n?(C=n("settings.page.notifications.description"),e[62]=n,e[63]=C):C=e[63];let R;e[64]!==n?(R=n("settings.page.voice.description"),e[64]=n,e[65]=R):R=e[65];let V;e[66]!==n?(V=n("settings.page.tunnel.description"),e[66]=n,e[67]=V):V=e[67];let U;e[68]!==T||e[69]!==P||e[70]!==D||e[71]!==$||e[72]!==_||e[73]!==C||e[74]!==R||e[75]!==V?(U={general:T,visual:P,chat:D,sessions:$,shortcuts:_,git:void 0,github:void 0,notifications:C,voice:R,tunnel:V},e[68]=T,e[69]=P,e[70]=D,e[71]=$,e[72]=_,e[73]=C,e[74]=R,e[75]=V,e[76]=U):U=e[76];const W=U[a];let te;e[77]!==j?(te=j(),e[77]=j,e[78]=te):te=e[78];let O;return e[79]!==W||e[80]!==F||e[81]!==te?(O=s.jsx(os,{title:F,description:W,showSaveStatus:!0,className:"openchamber-page-body",children:te}),e[79]=W,e[80]=F,e[81]=te,e[82]=O):O=e[82],O},iv=()=>{const t=dt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Yb,{}),t[0]=e):e=t[0],e},rv=()=>{const t=dt.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;Xc();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=cs()&&ai(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=na()&&!cs()&&!a&&!yc(),t[2]=r):r=t[2];const l=r;let u,c,f,d,v;t[3]===Symbol.for("react.memo_cache_sentinel")?(u=i&&s.jsx(Yc,{}),c=l&&s.jsx(Vc,{}),f=s.jsx(Hc,{}),d=!a&&s.jsx(Jc,{}),v=!a&&s.jsx(Qc,{}),t[3]=u,t[4]=c,t[5]=f,t[6]=d,t[7]=v):(u=t[3],c=t[4],f=t[5],d=t[6],v=t[7]);let p;t[8]===Symbol.for("react.memo_cache_sentinel")?(p=a?[]:["sessionTabs"],t[8]=p):p=t[8];let j;return t[9]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsxs(s.Fragment,{children:[u,c,f,d,v,s.jsx(qi,{visibleSettings:["fileEditorKeymap",...p,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=j):j=t[9],j},ov=()=>{const t=dt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(qi,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset"]}),t[1]=n):n=t[1],n},lv=()=>{const t=dt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(qi,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[1]=n):n=t[1],n},cv=t=>{const e=dt.c(5),{runtimeEndpointEpoch:a}=t;let n;e[0]!==a?(n=s.jsx(qc,{},a),e[0]=a,e[1]=n):n=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Bc,{}),e[2]=i):i=e[2];let r;return e[3]!==n?(r=s.jsxs(s.Fragment,{children:[n,i]}),e[3]=n,e[4]=r):r=e[4],r},dv=()=>{const t=dt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Lc,{}),t[0]=e):e=t[0],e},uv=()=>{const t=dt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(lb,{}),t[0]=e):e=t[0],e},pv=()=>{const t=dt.c(1);if(ds())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(bb,{}),t[0]=e):e=t[0],e},mv=()=>{const t=dt.c(1);if(ds())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ab,{}),t[0]=e):e=t[0],e};function gv(t){return t+1}const hv=t=>{const e=dt.c(85),{className:a}=t,{t:n}=et(),i=sa(gc),r=sa(fv),l=ce(xv),u=ce(bv),[c,f]=Ye.useState(!1),[d,v]=Ye.useState(!1),p=i>0;let j;e[0]!==n?(j=async()=>{try{const ue=await du({message:n("settings.view.pendingRestart.applying")});if(ue.requiresManualRestart){M.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}ue.ok&&M.success(n("settings.view.pendingRestart.applied"))}catch(ue){const xe=ue,pe=xe instanceof Error&&xe.message?xe.message:n("settings.view.pendingRestart.applyFailed");M.error(pe)}},e[0]=n,e[1]=j):j=e[1];const h=j;let w;e[2]!==n?(w=async()=>{try{await ac({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),sa.getState().clear()}catch{}},e[2]=n,e[3]=w):w=e[3];const b=w;let k;e[4]!==d||e[5]!==h||e[6]!==u?(k=()=>{d&&u(!1),f(!1),v(!1),h()},e[4]=d,e[5]=h,e[6]=u,e[7]=k):k=e[7];const m=k;let I;e[8]!==p||e[9]!==h||e[10]!==b||e[11]!==l?(I=()=>{if(!p){b();return}if(l){v(!1),f(!0);return}h()},e[8]=p,e[9]=h,e[10]=b,e[11]=l,e[12]=I):I=e[12];const E=I;let A;e[13]!==p||e[14]!==r||e[15]!==n?(A=n(p?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=p,e[14]=r,e[15]=n,e[16]=A):A=e[16];const N=A;let x;e[17]!==p||e[18]!==i||e[19]!==n?(x=p?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=p,e[18]=i,e[19]=n,e[20]=x):x=e[20];const y=x,F=p?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",T=r&&"opacity-80";let P;e[21]!==a||e[22]!==F||e[23]!==T?(P=ye("flex w-full items-center gap-2 rounded-md overflow-hidden whitespace-nowrap","h-11 px-3 sm:h-8 sm:px-2","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",F,T,a),e[21]=a,e[22]=F,e[23]=T,e[24]=P):P=e[24];let D;e[25]!==p||e[26]!==i?(D=p?s.jsx("span",{className:ye("inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1.5","bg-background text-foreground typography-micro font-semibold tabular-nums"),"aria-hidden":"true",children:i}):s.jsx(z,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=p,e[26]=i,e[27]=D):D=e[27];let $;e[28]!==N?($=s.jsx("span",{className:"truncate",children:N}),e[28]=N,e[29]=$):$=e[29];let _;e[30]!==E||e[31]!==r||e[32]!==D||e[33]!==$||e[34]!==P||e[35]!==y?(_=s.jsxs("button",{type:"button",disabled:r,title:y,"aria-label":y,onClick:E,className:P,children:[D,$]}),e[30]=E,e[31]=r,e[32]=D,e[33]=$,e[34]=P,e[35]=y,e[36]=_):_=e[36];let C;e[37]===Symbol.for("react.memo_cache_sentinel")?(C=ue=>{f(ue),ue||v(!1)},e[37]=C):C=e[37];let R;e[38]!==n?(R=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=R):R=e[39];let V;e[40]!==R?(V=s.jsx(Bt,{children:R}),e[40]=R,e[41]=V):V=e[41];let U;e[42]!==n?(U=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=U):U=e[43];let W;e[44]!==U?(W=s.jsx(Vt,{children:U}),e[44]=U,e[45]=W):W=e[45];let te;e[46]!==V||e[47]!==W?(te=s.jsxs($t,{children:[V,W]}),e[46]=V,e[47]=W,e[48]=te):te=e[48];let O;e[49]===Symbol.for("react.memo_cache_sentinel")?(O={width:"40%"},e[49]=O):O=e[49];let ie;e[50]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>f(!1),e[50]=ie):ie=e[50];let K;e[51]!==n?(K=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=K):K=e[52];let q;e[53]!==K?(q=s.jsx("div",{className:"min-w-0 shrink-0",style:O,children:s.jsx(H,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:ie,children:K})}),e[53]=K,e[54]=q):q=e[54];let B;e[55]===Symbol.for("react.memo_cache_sentinel")?(B={width:"40%"},e[55]=B):B=e[55];let L;e[56]!==n?(L=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=L):L=e[57];let X;e[58]!==m||e[59]!==L?(X=s.jsx("div",{className:"min-w-0 shrink-0",style:B,children:s.jsx(H,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:m,children:L})}),e[58]=m,e[59]=L,e[60]=X):X=e[60];let G;e[61]!==q||e[62]!==X?(G=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[q,X]}),e[61]=q,e[62]=X,e[63]=G):G=e[63];let Z;e[64]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>v(vv),e[64]=Z):Z=e[64];let le;e[65]!==d?(le=d?s.jsx(z,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(z,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=d,e[66]=le):le=e[66];let oe;e[67]!==n?(oe=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=oe):oe=e[68];let he;e[69]!==d||e[70]!==le||e[71]!==oe?(he=s.jsxs("button",{type:"button",onClick:Z,className:"inline-flex items-center justify-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","aria-pressed":d,children:[le,oe]}),e[69]=d,e[70]=le,e[71]=oe,e[72]=he):he=e[72];let ee;e[73]!==G||e[74]!==he?(ee=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[G,he]}),e[73]=G,e[74]=he,e[75]=ee):ee=e[75];let re;e[76]!==te||e[77]!==ee?(re=s.jsxs(Ut,{showCloseButton:!1,className:"max-w-md gap-5",children:[te,ee]}),e[76]=te,e[77]=ee,e[78]=re):re=e[78];let de;e[79]!==c||e[80]!==re?(de=s.jsx(zt,{open:c,onOpenChange:C,children:re}),e[79]=c,e[80]=re,e[81]=de):de=e[81];let ke;return e[82]!==_||e[83]!==de?(ke=s.jsxs(s.Fragment,{children:[_,de]}),e[82]=_,e[83]=de,e[84]=ke):ke=e[84],ke};function fv(t){return t.isApplying}function xv(t){return t.showOpenCodeRestartConfirm}function bv(t){return t.setShowOpenCodeRestartConfirm}function vv(t){return!t}const yv=[{id:"chat.activity-default",page:"chat",titleKey:"settings.openchamber.visual.section.activityDefault",keywords:["activity","collapsed","expanded","live","tools","history"]},{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"]},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.import-theme",page:"appearance",titleKey:"settings.themeImport.action",descriptionKey:"settings.themeImport.catalogHint",keywords:["theme","import","vscode","open vsx","openvsx","json","jsonc","syntax","palette"],isAvailable:t=>!t.isVSCode},{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:t=>t.isMac},{id:"appearance.scrollbars",page:"appearance",titleKey:"settings.openchamber.visual.field.alwaysShowScrollbars",descriptionKey:"settings.openchamber.visual.field.alwaysShowScrollbarsHint",keywords:["scrollbar","scrollbars","scroll","mouse","wheel","accessibility","always visible"]},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.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:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.openchamber.visual.field.terminalShell",descriptionKey:"settings.openchamber.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.openchamber.visual.field.autoSaveEnabled",descriptionKey:"settings.openchamber.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.openchamber.visual.field.sessionTabsGroup",descriptionKey:"settings.openchamber.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.openchamber.appLinks.title",descriptionKey:"settings.openchamber.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.openchamber.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.openchamber.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.streaming",page:"chat",titleKey:"settings.openchamber.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.openchamber.visual.field.streamingAutoFollow",descriptionKey:"settings.openchamber.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.openchamber.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.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.input-history-scope",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryScope",descriptionKey:"settings.openchamber.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryLimit",descriptionKey:"settings.openchamber.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.openchamber.visual.field.largeTextPaste",descriptionKey:"settings.openchamber.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.openchamber.visual.field.enterToSend",descriptionKey:"settings.openchamber.visual.field.enterToSendHint",keywords:["enter","shift enter","ctrl enter","cmd enter","mod enter","send","newline"]},{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.walkthrough-model",page:"sessions",titleKey:"settings.openchamber.defaults.walkthroughModel.title",descriptionKey:"settings.openchamber.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","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-only-archived",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.onlyArchived",descriptionKey:"settings.openchamber.sessionRetention.field.onlyArchivedDescription",keywords:["archive","archived","only","delete","cleanup","retention"]},{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:"general",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.openchamber.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-window-controls-style",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsStyle",keywords:["desktop","window","controls","style","traffic","lights","classic","macos","titlebar"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-mac-menu-bar",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.macMenuBar",descriptionKey:"settings.openchamber.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.openchamber.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows","linux"],isAvailable:t=>t.isDesktopLocalOrigin&&(t.isWindows||t.isLinux)},{id:"sessions.desktop-keep-awake",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.keepAwake",descriptionKey:"settings.openchamber.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentControlTool",descriptionKey:"settings.openchamber.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","openchamber","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentWebTool",descriptionKey:"settings.openchamber.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","openchamber"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-memory-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentMemoryTool",descriptionKey:"settings.openchamber.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","openchamber"],isAvailable:t=>!t.isVSCode&&ce.getState().agentMemoryFeatureAvailable},{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.work-status-panel",page:"usage",titleKey:"settings.usage.page.options.showInWorkStatus",descriptionKey:"settings.usage.page.options.showInWorkStatusTooltip",keywords:["quota","work","status","panel"]},{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.default-agent",page:"projects",titleKey:"settings.projects.page.field.projectAgent",keywords:["agent","default","new chat","project metadata"]},{id:"projects.default-model",page:"projects",titleKey:"settings.projects.page.field.projectModel",keywords:["model","default","new chat","project metadata"]},{id:"projects.default-thinking",page:"projects",titleKey:"settings.projects.page.field.projectThinking",keywords:["thinking","variant","reasoning","effort","model","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:"projects.worktree.setup.replace",page:"projects",titleKey:"settings.projects.shared.replaceMode",keywords:["worktree","setup commands","shared","team","only mine"]},{id:"projects.shared",page:"projects",titleKey:"settings.projects.shared.title",descriptionKey:"settings.projects.shared.description",keywords:["shared","team","repository",".openchamber","project.json","trust"]},{id:"projects.shared.plansDir",page:"projects",titleKey:"settings.projects.shared.plansDir",descriptionKey:"settings.projects.shared.plansDirInfo",keywords:["plans","folder","shared","team","docs"]},{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:t=>!t.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:t=>t.isDesktop},{id:"behavior.system-prompt-optimization",page:"behavior",titleKey:"settings.behavior.page.section.systemPromptOptimization",descriptionKey:"settings.behavior.page.systemPromptOptimization.info",keywords:["system prompt","tokens","context","optimize","minimal"],isAvailable:t=>!t.isVSCode},{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.custom",page:"providers",titleKey:"settings.providers.page.custom.title",descriptionKey:"settings.providers.page.custom.description",keywords:["other","custom","openai-compatible","base url","api key"]},{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:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.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:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.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:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.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:t=>!t.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:t=>!t.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:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"integrations.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode},{id:"integrations.guests",page:"integrations",titleKey:"settings.integrations.guests.title",descriptionKey:"settings.integrations.guests.info",keywords:["guest","extension","oauth","clickup","gitlab","panel","connect"],isAvailable:t=>!t.isVSCode},{id:"extensions.add",page:"extensions",titleKey:"settings.extensions.add.label",descriptionKey:"settings.extensions.add.info",keywords:["folder","path","zip","git","url","install","guest","panel"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"extensions.gitIdentity",page:"extensions",titleKey:"settings.extensions.identity.title",descriptionKey:"settings.extensions.add.info",keywords:["ssh","key","identity","git","private","clone","extension"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"extensions.updates.check",page:"extensions",titleKey:"settings.extensions.updates.check",keywords:["update","upgrade","version","git","extension","guest","refresh"],isAvailable:t=>!t.isVSCode&&!t.isMobile}];function Vl(t){return t.trim().toLocaleLowerCase()}function jv({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=Vl(t);if(!r)return[];const l=a?new Set(a):null,u=r.split(/\s+/).filter(Boolean);return yv.flatMap(c=>{if(l&&!l.has(c.page))return[];const f=Ca(c.page);if(!f||f.isAvailable&&!f.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const d=n(c.titleKey),v=c.descriptionKey?n(c.descriptionKey):null,p=Vl([d,v,i(c.page),...c.keywords??[]].filter(Boolean).join(" "));return u.every(j=>p.includes(j))?[{...c,title:d,description:v,pageTitle:i(c.page)}]:[]})}const Hl=256,ql=280,ed="__openchamberSettingsDetail",wv=["general","appearance","chat","notifications","sessions","shortcuts","voice","integrations","extensions","usage","about","projects","remote-instances","tunnel","git","providers","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],kv=["general","projects","opencode","content"],Nv="__add_provider__";function Sv(t,e){const a=ds(),n=!t&&na();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function Gl(t,e){return t.isAvailable?t.isAvailable(e):!0}function Hr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Ya(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function Ar(t){if(!Hr(t))return null;const e=t[ed];if(!Hr(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:jc(a),stage:n}}function Cv(){return typeof window>"u"||!Hr(window.history.state)?{}:window.history.state}const _v=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:i="nav",registerBackHandler:r})=>{const{t:l}=et(),u=ua(),c=e??u.isMobile,f=sa(gc),d=ce(se=>se.settingsPage),v=ce(se=>se.isSettingsDialogOpen),p=ce(se=>se.setSettingsPage),j=ce(se=>se.shortcutOverrides.open_settings),h=jc(d),[w,b]=o.useState(i),k=o.useRef(i==="nav"?h:null);o.useEffect(()=>{!c&&h==="home"&&p("general")},[c,p,h]);const[m,I]=o.useState(""),[E,A]=o.useState(null),[N,x]=o.useState(0),y=o.useRef(null),F=o.useRef(!1),T=o.useRef([]),P=o.useRef(0),D=o.useRef(!1),$=o.useMemo(()=>cs(),[]),_=o.useMemo(()=>cs()&&ai(),[]),C=o.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),R=o.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),V=o.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),U=o.useMemo(()=>vc(),[]),W=o.useMemo(()=>Sv($,c),[$,c]),te=o.useMemo(()=>{const se=n?new Set(n):null;return Ju.filter(ae=>ae.slug!=="home").filter(ae=>!se||se.has(ae.slug)).filter(ae=>Gl(ae,W)).filter(ae=>!(W.isVSCode&&ae.slug==="projects")).filter(ae=>!(c&&ae.slug==="shortcuts"))},[W,c,n]),O=o.useMemo(()=>{const se=new Map(wv.map((ae,je)=>[ae,je]));return te.slice().sort((ae,je)=>(se.get(ae.slug)??999)-(se.get(je.slug)??999))},[te]),ie=Xs(se=>se.activeProjectId),K=Gs();o.useEffect(()=>{if(!(!v&&!W.isVSCode&&!a)){if(h==="agents"){aa.getState().loadAgents(K);return}if(h==="commands"){Ma.getState().loadCommands(K);return}if(h==="mcp"){Ra.getState().loadMcpConfigs({directory:K});return}if(h==="plugins"){vs.getState().loadPlugins();return}(h==="skills.installed"||h==="skills.catalog")&&(Zs.getState().loadSkills(K),Pn.getState().loadCatalog()),h==="snippets"&&_i.getState().loadSnippets()}},[ie,v,a,W.isVSCode,K,h]);const q=o.useCallback(se=>{if(p(se),k.current=se,!c)return;const ae=Ca(se);if(!ae||ae.slug==="home"){b("nav");return}b(ae.kind==="split"?"page-sidebar":"page-content")},[c,p]),B=o.useMemo(()=>Ca(h),[h]),L=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),X=o.useCallback(se=>{switch(se){case"general":return l("settings.page.general.title");case"projects":return l("settings.page.projects.title");case"remote-instances":return l("settings.page.remoteInstances.title");case"providers":return l("settings.page.providers.title");case"usage":return l("settings.page.usage.title");case"agents":return l("settings.page.agents.title");case"behavior":return l("settings.page.behavior.title");case"commands":return l("settings.page.commands.title");case"mcp":return l("settings.page.mcp.title");case"plugins":return l("settings.page.plugins.title");case"skills.installed":return l("settings.page.skills.title");case"skills.catalog":return l("settings.page.skillsCatalog.title");case"git":return l("settings.page.git.title");case"integrations":return l("settings.page.integrations.title");case"extensions":return l("settings.page.extensions.title");case"appearance":return l("settings.page.appearance.title");case"chat":return l("settings.page.chat.title");case"shortcuts":return l("settings.page.shortcuts.title");case"sessions":return l("settings.page.sessions.title");case"magic-prompts":return l("settings.page.magicPrompts.title");case"snippets":return l("settings.page.snippets.title");case"notifications":return l("settings.page.notifications.title");case"voice":return l("settings.page.voice.title");case"tunnel":return l("settings.page.tunnel.title");case"about":return l("settings.page.about.title");default:return l("settings.view.home.title")}},[l]),G=o.useMemo(()=>jv({query:m,runtimeCtx:{...W,isDesktopLocalOrigin:_,isMac:C,isWindows:R,isLinux:V,isWindowsArm64:U},visiblePageSlugs:n,t:l,getPageTitle:X}),[X,U,_,C,R,V,W,m,l,n]),Z=o.useCallback(se=>{if(se.id.startsWith("agents.")){const ae=aa.getState(),je=Ya("new-agent",ae.agents.map(Se=>Se.name));return ae.setAgentDraft({name:je,scope:"user"}),ae.setSelectedAgent(je),se.id==="agents.create"?"agents.name":se.id}if(se.id.startsWith("commands.")){const ae=Ma.getState(),je=Ya("new-command",ae.commands.map(Se=>Se.name));return ae.setCommandDraft({name:je,scope:"user"}),ae.setSelectedCommand(je),se.id==="commands.create"?"commands.name":se.id}if(se.id.startsWith("mcp.")){const ae=Ra.getState(),je=Ya("new-mcp-server",ae.mcpServers.map(Se=>Se.name));return ae.setMcpDraft({name:je,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),ae.setSelectedMcp(je),se.id==="mcp.create"?"mcp.server":se.id}if(se.id.startsWith("snippets.")){const ae=_i.getState(),je=Ya("new-snippet",ae.snippets.map(Se=>Se.name));return ae.setSnippetDraft({name:je,scope:"global"}),ae.setSelectedSnippet(je),se.id==="snippets.create"?"snippets.content":se.id}if(se.id.startsWith("skills.")){const ae=Zs.getState(),je=Ya("new-skill",ae.skills.map(Se=>Se.name));return ae.setSkillDraft({name:je,scope:"user",source:"opencode",description:"",instructions:""}),ae.setSelectedSkill(je),se.id==="skills.create"?"skills.basic-information":se.id}return se.id==="providers.connect"&&nt.getState().setSelectedProvider(Nv),se.id==="plugins.create"?"plugins.spec":se.id},[]),le=o.useMemo(()=>{const se=[],ae=new Map;for(const je of G){let Se=ae.get(je.page);Se||(Se={page:je.page,pageTitle:je.pageTitle,results:[]},ae.set(je.page,Se),se.push(Se)),Se.results.push(je)}return se},[G]);o.useEffect(()=>{x(0),P.current=0,D.current=!1},[m]),o.useEffect(()=>{P.current=N},[N]),o.useEffect(()=>{T.current[N]?.scrollIntoView({block:"nearest"})},[N]),o.useEffect(()=>{N>=G.length&&x(Math.max(0,G.length-1)),T.current.length=G.length},[N,G.length]);const oe=o.useCallback(se=>{const ae=Z(se);A(ae),q(se.page),c&&b("page-content"),se.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[c,q,Z]),he=o.useCallback(se=>{if(m.trim()){if(se.key==="Escape"){se.preventDefault(),I("");return}if(G.length!==0){if(se.key==="ArrowDown"){se.preventDefault(),D.current=!0,x(ae=>(ae+1)%G.length);return}if(se.key==="ArrowUp"){se.preventDefault(),D.current=!0,x(ae=>(ae-1+G.length)%G.length);return}if(se.key==="Enter"){se.preventDefault();const ae=(P.current%G.length+G.length)%G.length,je=G[ae]??G[0];je&&oe(je)}}}},[oe,m,G]);o.useEffect(()=>{const se=E;if(!se)return;let ae=!1;const je=window.requestAnimationFrame(()=>{if(ae)return;const Se=typeof CSS<"u"&&CSS.escape?CSS.escape(se):se.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Ke=y.current?.querySelector(`[data-settings-item="${Se}"]`);Ke&&(A(null),Ke.scrollIntoView({block:"center",behavior:"smooth"}),Ke.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Ke.removeAttribute("data-settings-search-highlight")},1600))});return()=>{ae=!0,window.cancelAnimationFrame(je)}},[E,h]);const ee=o.useCallback(()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:sc,children:l("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:l("settings.view.unavailable.description")})]})}),[l]),re=o.useCallback((se,ae)=>{switch(se){case"projects":return s.jsx(Rg,{onItemSelect:ae.onItemSelect});case"agents":return s.jsx(Pp,{onItemSelect:ae.onItemSelect});case"commands":return s.jsx(Gp,{onItemSelect:ae.onItemSelect});case"mcp":return s.jsx(tm,{onItemSelect:ae.onItemSelect});case"plugins":return s.jsx($m,{onItemSelect:ae.onItemSelect});case"skills.installed":return s.jsx(sg,{onItemSelect:ae.onItemSelect});case"providers":return s.jsx(lh,{onItemSelect:ae.onItemSelect});case"usage":return s.jsx(Hh,{onItemSelect:ae.onItemSelect});case"magic-prompts":return s.jsx(cf,{onItemSelect:ae.onItemSelect});case"snippets":return s.jsx(mf,{onItemSelect:ae.onItemSelect});default:return null}},[]),de=o.useCallback(se=>{const ae=Ca(se);if(ae&&!Gl(ae,W))return ee();switch(se){case"projects":return s.jsx(zg,{});case"remote-instances":return s.jsx(ih,{});case"agents":return s.jsx(zp,{});case"behavior":return s.jsx(qp,{});case"commands":return s.jsx(em,{});case"mcp":return s.jsx(km,{});case"plugins":return s.jsx(eg,{});case"skills.installed":return s.jsx(Xo,{view:"installed"});case"skills.catalog":return s.jsx(Xo,{view:"catalog"});case"providers":return s.jsx(Bh,{});case"usage":return s.jsx(of,{});case"about":return s.jsx(os,{title:l("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Nc,{})});case"magic-prompts":return s.jsx(pf,{});case"snippets":return s.jsx(xf,{});case"git":return s.jsx(wf,{});case"integrations":return s.jsx($f,{});case"extensions":return s.jsx(mx,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const je=L[se]??"visual";return s.jsx(av,{section:je})}default:return null}},[L,ee,W,l]);o.useEffect(()=>{if(!c||w!=="nav"||h==="home"||k.current===h)return;const se=Ca(h);!se||se.slug==="home"||(k.current=h,b(se.kind==="split"?"page-sidebar":"page-content"))},[c,w,h]);const ke=c&&w!=="nav",ue=c&&w==="page-content"&&B?.kind==="split",xe=l(ue?"settings.view.actions.back":ke?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),pe=mc("open_settings",j===void 0?void 0:{open_settings:j}),Ie=pe?l("settings.view.actions.closeSettingsWithShortcut",{shortcut:ia(pe)}):l("settings.view.actions.closeSettings"),Te=o.useCallback(se=>{if(typeof window>"u"||W.isVSCode)return;const ae=Ar(window.history.state);ae?.page===se&&ae.stage==="page-content"||window.history.pushState({...Cv(),[ed]:{page:se,stage:"page-content"}},"",window.location.href)},[W.isVSCode]),we=o.useCallback(()=>{F.current=!0,b("page-content"),Te(h)},[Te,h]);o.useEffect(()=>{if(!c||w!=="page-content"||!F.current)return;F.current=!1;const se=window.requestAnimationFrame(()=>{y.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(se)}},[c,w,h]);const De=o.useCallback(()=>{if(ue){if((typeof window<"u"?Ar(window.history.state):null)?.page===h&&!W.isVSCode){window.history.back();return}b("page-sidebar");return}b("nav")},[ue,W.isVSCode,h]);o.useEffect(()=>{if(r)return r(()=>!c||w==="nav"?!1:(De(),!0)),()=>r(null)},[De,c,w,r]),o.useEffect(()=>{if(!c||W.isVSCode)return;const se=ae=>{if(Ca(h)?.kind!=="split")return;if(Ar(ae.state)?.page===h){b("page-content");return}b(Se=>Se==="page-content"?"page-sidebar":Se)};return window.addEventListener("popstate",se),()=>{window.removeEventListener("popstate",se)}},[c,W.isVSCode,h]);const _e=()=>{const se=m.trim().length>0;return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"px-4 pt-3",children:s.jsxs("div",{className:"oc-surface-elevated flex h-10 items-center gap-1.5 rounded-md border border-border bg-surface-elevated/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-ring sm:h-8",children:[s.jsx(z,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:m,onChange:ae=>I(ae.target.value),onKeyDown:he,placeholder:l("settings.view.search.placeholder"),"aria-label":l("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),se&&s.jsx("button",{type:"button",onClick:()=>I(""),"aria-label":l("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:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx(ks,{outerClassName:"flex-1 min-h-0",disableHorizontal:!0,children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:se?G.length>0?(()=>{let ae=0;return le.map(je=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:"px-2 pb-0.5 pt-2 typography-micro font-medium text-muted-foreground/70",children:je.pageTitle}),je.results.map(Se=>{const Ke=ae;ae+=1;const Ue=Ke===N,Oe=!!Se.description;return s.jsxs("button",{type:"button",ref:Re=>{T.current[Ke]=Re},onMouseMove:()=>{D.current=!1,x(Ke)},onClick:()=>oe(Se),className:ye("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",Oe?"min-h-11 py-1.5":"py-2",Ue?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Se.title}),Oe&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:Se.description})]},Se.id)})]},je.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:l("settings.view.search.noResults")}):(()=>{const ae=new Map;for(const Se of O){const Ke=Se.group,Ue=ae.get(Ke);Ue?Ue.push(Se):ae.set(Ke,[Se])}return kv.map(Se=>({group:Se,pages:ae.get(Se)??[]})).filter(Se=>Se.pages.length>0).map(({group:Se,pages:Ke},Ue)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:ye("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Ue===0?"pt-1":"pt-4 sm:pt-3"),children:l(`settings.view.nav.group.${Se}`)}),Ke.map(Oe=>{const Re=h===Oe.slug&&!(c&&w==="nav"),Ce=Qu(Oe.slug);return!Ce&&Oe.slug!=="mcp"?null:s.jsx(Wr,{children:s.jsx(Jr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>q(Oe.slug),"aria-current":Re?"page":void 0,className:ye("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",Re?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Oe.slug==="mcp"?s.jsx(uu,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(z,{name:Ce,className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:X(Oe.slug)}),Oe.slug==="tunnel"&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:l("settings.view.badge.beta")})]})]})})},Oe.slug)})]},Se))})()})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-background px-4 py-1.5 space-y-0.5 sm:bg-sidebar",children:(!W.isVSCode||f>0)&&s.jsx(hv,{})})})]})},Ve=()=>{if(w==="nav")return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(Rn,{children:_e()})})});if(!B)return s.jsx("div",{className:"flex-1 bg-background"});if(w==="page-sidebar"){if(B.kind!=="split"){const ae=de(h);return s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Rn,{children:ae})})}return s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Rn,{children:re(h,{onItemSelect:we})})})}const se=de(h);return s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Rn,{children:se})})},ve=()=>!B||h==="home"?null:B.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ye("border-r",W.isVSCode?"bg-background":"bg-sidebar"),style:{width:ql,minWidth:ql,borderColor:"var(--interactive-border)"},children:s.jsx(Rn,{children:re(h,{})})}),s.jsx(ks,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Rn,{children:de(h)})})]}):s.jsx(ks,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Rn,{children:de(h)})});return s.jsxs("div",{ref:y,"data-settings-view":"true",className:ye("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[c?s.jsxs("div",{className:ye("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",w!=="nav"&&"border-b","bg-background"),style:w!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[ke?s.jsx("button",{type:"button",onClick:De,"aria-label":xe,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-ring",children:s.jsx(z,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:w==="nav"?l("settings.view.home.title"):B?X(B.slug):l("settings.view.home.title")}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:Ie,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-ring",children:s.jsx(z,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[ke&&s.jsx("div",{className:ye("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:De,"aria-label":l("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-ring",children:s.jsx(z,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:ye("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":l("settings.view.actions.closeSettings"),title:Ie,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-ring",children:s.jsx(z,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?Ve():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("relative flex h-full min-h-0 flex-col overflow-hidden border-r",$?"bg-sidebar":W.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${Hl}px`,minWidth:`${Hl}px`,borderColor:"var(--interactive-border)"},children:s.jsx(Rn,{children:_e()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:ve()})]})})]})};export{Nc as A,_v as S};