@openchamber/web 1.22.1 → 1.22.2

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 (111) hide show
  1. package/bin/cli.js +4 -1
  2. package/bin/cli.test.js +92 -0
  3. package/bin/lib/cli-startup.js +49 -0
  4. package/bin/lib/commands-startup.js +41 -6
  5. package/dist/assets/{CodeMirrorCommentWidgets-BO_2OW4E.js → CodeMirrorCommentWidgets-BI-TY1UG.js} +1 -1
  6. package/dist/assets/{DiffView-CNnDxRmO.js → DiffView-cOmByCaX.js} +3 -3
  7. package/dist/assets/{DirtyBranchSwitchDialog-jADfXQnR.js → DirtyBranchSwitchDialog-BwSnDlNy.js} +1 -1
  8. package/dist/assets/FilesView-DRRy_6oZ.js +17 -0
  9. package/dist/assets/{GitView-Cv2xH-S6.js → GitView-B7YCg1YM.js} +4 -4
  10. package/dist/assets/{JsonTreeView-DUiIpERC.js → JsonTreeView-CjzNsiIU.js} +1 -1
  11. package/dist/assets/{LinearIssuesView-CoZ7pQN5.js → LinearIssuesView-BYlE0YrW.js} +1 -1
  12. package/dist/assets/{MarkdownImageGallery-DffjmciG.js → MarkdownImageGallery-DlTF-wua.js} +1 -1
  13. package/dist/assets/MarkdownRendererImpl-CqgeZRlP.js +12 -0
  14. package/dist/assets/{OnboardingScreen-CTZe6HZn.js → OnboardingScreen-BsJU7oav.js} +1 -1
  15. package/dist/assets/{PatchDiff-BymkP9JA.js → PatchDiff-CDNu968J.js} +1 -1
  16. package/dist/assets/{PierreDiffViewer-BvwtCxW4.js → PierreDiffViewer-BoBsAanf.js} +1 -1
  17. package/dist/assets/{PlanView-C1qvAm7m.js → PlanView-Cxr8LQT1.js} +4 -4
  18. package/dist/assets/SettingsView-bsKpCZbB.js +28 -0
  19. package/dist/assets/{SettingsWindow-COzgfFxM.js → SettingsWindow-B0rHQdw4.js} +1 -1
  20. package/dist/assets/{ToolOutputDialog-Dlhh_-oe.js → ToolOutputDialog-6zP8hwzX.js} +6 -6
  21. package/dist/assets/{ToolPartDiffPreview-b9joNtXH.js → ToolPartDiffPreview-Bvwh4Y31.js} +2 -2
  22. package/dist/assets/{VirtualizedFileDiff-vqW3KKo5.js → VirtualizedFileDiff-aaIfrRxl.js} +1 -1
  23. package/dist/assets/{WalkthroughView-D-HFgdmM.js → WalkthroughView-baZ0ssy9.js} +2 -2
  24. package/dist/assets/{computeVirtualFileMetrics-DUnyszhW.js → computeVirtualFileMetrics-DfgllYQc.js} +2 -2
  25. package/dist/assets/{contextPanelEmbeddedChat-CV-DwAiX.js → contextPanelEmbeddedChat-prHos-tt.js} +1 -1
  26. package/dist/assets/{de-Cv_4FoXm.js → de-hknQLFxa.js} +2 -2
  27. package/dist/assets/{es-BIWNEbnS.js → es-C_bD3kvW.js} +2 -2
  28. package/dist/assets/{fr-SD3OfMHJ.js → fr-BVF-C2Nu.js} +2 -2
  29. package/dist/assets/index-B0aX0JeI.js +39 -0
  30. package/dist/assets/{index-DLiD86ge.js → index-DUwZ2cWA.js} +1 -1
  31. package/dist/assets/index-Dl3xbAB_.css +1 -0
  32. package/dist/assets/{isDiffPlainText-TNageFjy.js → isDiffPlainText-COIS9Df5.js} +1 -1
  33. package/dist/assets/{isFilePlainText-JPmZOYSp.js → isFilePlainText-D7LEG-KY.js} +1 -1
  34. package/dist/assets/{ja-D7I9HofF.js → ja-B2G5hD59.js} +2 -2
  35. package/dist/assets/{ko-BsVJM_PQ.js → ko-D6OrOdZ3.js} +2 -2
  36. package/dist/assets/main-BBuBZzoi.js +930 -0
  37. package/dist/assets/{main-DCB4JgVe.js → main-CwIEELQq.js} +2 -2
  38. package/dist/assets/{markdownCore-BoQVG5-a.js → markdownCore-BE_Hhps5.js} +2 -2
  39. package/dist/assets/{miniChat-BtV7N5OF.js → miniChat-CeXAoWiF.js} +2 -2
  40. package/dist/assets/{mobile-DZV_sfX7.js → mobile-ilq39yLQ.js} +2 -2
  41. package/dist/assets/{patchFileDiff-Chmiz6hq.js → patchFileDiff-DLky6SYr.js} +5 -5
  42. package/dist/assets/{pl-XR9Bs8Be.js → pl-CVroZXt1.js} +2 -2
  43. package/dist/assets/{pt-BR-Due4be8g.js → pt-BR-eH3onaIW.js} +2 -2
  44. package/dist/assets/{renderElectronMiniChatApp-8tXADjfl.js → renderElectronMiniChatApp-BsywqmJT.js} +2 -2
  45. package/dist/assets/{renderMobileApp-Cji7Hma5.js → renderMobileApp-CDun1795.js} +7 -7
  46. package/dist/assets/runtimeEndpointReset-DebJIo5U.js +17 -0
  47. package/dist/assets/{scheduledTasksApi-9e-UX6im.js → scheduledTasksApi-B0tChXQC.js} +1 -1
  48. package/dist/assets/{shikiHighlight-CRpCl7UT.js → shikiHighlight-DJSXdcG4.js} +1 -1
  49. package/dist/assets/tr-BvtU2tXS.js +7 -0
  50. package/dist/assets/{uk-COYh2BaN.js → uk-nu36iqFz.js} +2 -2
  51. package/dist/assets/{useAppFontEffects-CCgvcQ6u.js → useAppFontEffects-Bb1Zihd2.js} +134 -131
  52. package/dist/assets/useInlineCommentController-B8dQWRpH.js +2 -0
  53. package/dist/assets/{useRootScrollLock-KzOUytpn.js → useRootScrollLock-DrJ8gE-x.js} +1 -1
  54. package/dist/assets/{vendor-codemirror-language-data-BxpoC5Fp.js → vendor-codemirror-language-data-CNjvbb69.js} +2 -2
  55. package/dist/assets/vendor-zod-CK21ihK-.js +39 -0
  56. package/dist/assets/{web-components-B6QgbmTo.js → web-components-C06MmTcR.js} +1 -1
  57. package/dist/assets/{zh-CN-Cjk6lzhc.js → zh-CN-BClBzZ64.js} +2 -2
  58. package/dist/assets/{zh-TW-Dk0dOg03.js → zh-TW-CXtSqJHF.js} +2 -2
  59. package/dist/index.html +5 -5
  60. package/dist/mini-chat.html +4 -4
  61. package/dist/mobile.html +4 -4
  62. package/package.json +3 -3
  63. package/server/index.js +7 -1
  64. package/server/lib/changelog/update-notes.js +82 -0
  65. package/server/lib/changelog/update-notes.test.js +59 -0
  66. package/server/lib/fs/DOCUMENTATION.md +2 -0
  67. package/server/lib/fs/routes.js +32 -21
  68. package/server/lib/fs/routes.test.js +77 -0
  69. package/server/lib/git/service.js +10 -0
  70. package/server/lib/git/service.test.js +18 -0
  71. package/server/lib/message-queue/DOCUMENTATION.md +17 -7
  72. package/server/lib/message-queue/runtime.js +59 -7
  73. package/server/lib/message-queue/runtime.test.js +59 -3
  74. package/server/lib/opencode/DOCUMENTATION.md +8 -4
  75. package/server/lib/opencode/config-paths.test.js +116 -0
  76. package/server/lib/opencode/feature-routes-runtime.js +2 -0
  77. package/server/lib/opencode/input-history-scope.js +14 -0
  78. package/server/lib/opencode/plugins.js +2 -2
  79. package/server/lib/opencode/providers.js +44 -2
  80. package/server/lib/opencode/providers.test.js +131 -4
  81. package/server/lib/opencode/routes.js +4 -4
  82. package/server/lib/opencode/server-startup-runtime.js +1 -1
  83. package/server/lib/opencode/settings-helpers.js +28 -0
  84. package/server/lib/opencode/settings-helpers.test.js +177 -0
  85. package/server/lib/opencode/shared.js +4 -1
  86. package/server/lib/opencode/skill-routes.js +2 -1
  87. package/server/lib/opencode/snippets.js +1 -2
  88. package/server/lib/package-manager.js +3 -28
  89. package/server/lib/quota/utils/auth.js +1 -1
  90. package/server/lib/relay/host-client.test.js +9 -1
  91. package/server/lib/session-goal/DOCUMENTATION.md +20 -7
  92. package/server/lib/session-goal/runtime.js +76 -11
  93. package/server/lib/session-goal/runtime.test.js +426 -0
  94. package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
  95. package/server/lib/skills-catalog/install.js +3 -2
  96. package/server/lib/terminal/DOCUMENTATION.md +11 -7
  97. package/server/lib/terminal/runtime.js +150 -19
  98. package/server/lib/terminal/runtime.test.js +553 -26
  99. package/server/lib/terminal/shells.js +17 -0
  100. package/server/lib/terminal/shells.test.js +32 -1
  101. package/server/lib/walkthrough/routes.test.js +26 -5
  102. package/dist/assets/FilesView-8wdiG2mj.js +0 -17
  103. package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +0 -12
  104. package/dist/assets/SettingsView-xGONHFGS.js +0 -28
  105. package/dist/assets/index-CHUT_bDS.css +0 -1
  106. package/dist/assets/index-DDInLQDd.js +0 -40
  107. package/dist/assets/main-De8Z5w49.js +0 -928
  108. package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +0 -16
  109. package/dist/assets/tr-DBJcAv4y.js +0 -7
  110. package/dist/assets/useInlineCommentController-BkfXnjNZ.js +0 -2
  111. package/dist/assets/vendor-zod-DVWEh-IS.js +0 -39
@@ -1,28 +0,0 @@
1
- import{R as o,j as s,f as ut,r as We}from"./vendor-react-BUCujlKS.js";import{f as it,B,I as R,o as An,b7 as ua,t as D,O as ec,fF as tc,eq as _e,fG as Et,b as Vs,h as ve,fH as sc,b3 as sn,b5 as nn,fI as nc,b6 as an,eh as Bn,fJ as nl,fK as ac,fL as la,fM as on,b$ as Bs,bE as Kt,bF as zt,bG as _t,bH as $t,bI as Vt,bJ as ns,T as Je,fN as za,b2 as rn,e4 as Qi,fO as ic,fP as Kn,es as Jt,fQ as Ws,l as et,eF as Ot,bS as Pt,bT as It,eC as Lt,bU as Rt,bV as At,bW as ot,fR as Wt,bX as Is,dr as Oa,eE as In,eH as da,eG as en,fS as hs,dw as Ss,fT as Ps,fU as rc,cl as gt,fV as al,fW as oc,fX as _n,fY as il,fZ as lc,f_ as pa,ff as $s,f$ as ca,g0 as rl,g1 as cr,ds as ol,g2 as $n,a6 as ma,a5 as Rs,g3 as ll,g4 as Cr,ab as cc,e2 as cl,g as La,g5 as dc,g6 as Js,e1 as pc,g7 as mc,g8 as uc,g9 as dr,a7 as pr,a8 as mr,a9 as dl,ga as hn,a1 as gi,bf as ur,N as gr,gb as Pr,ao as gc,bY as hc,cB as fc,R as xc,Q as bc,S as vc,W as pl,gc as yc,gd as jc,bP as wc,bZ as Yi,ge as ml,aa as li,gf as ul,P as zn,gg as qs,ep as zs,ea as gl,a0 as kc,n as ts,dY as hi,x as hl,w as Nc,i as Sc,j as Cc,dZ as Pc,p as Ic,gh as Ac,gi as Tc,gj as Ir,dx as fl,gk as Ec,gl as Mi,gm as Ar,gn as Dc,go as Mc,gp as Rc,gq as Oc,dD as fi,gr as fs,gs as Os,gt as un,gu as gn,av as Pn,aw as ia,gv as Cn,gw as jn,gx as Ua,gy as Tr,gz as wa,gA as ka,bB as Hn,gB as Lc,gC as Fc,gD as Kc,gE as zc,gF as Ri,gG as Er,gH as Uc,gI as _c,gJ as $c,gK as Vc,gL as Dr,y as Bc,m as Mr,cP as Hc,gM as Gc,gN as Oi,gO as Rr,d$ as qc,gP as bi,gQ as Wc,gR as Jc,gS as Qc,gT as Yc,gU as Zc,gV as Li,cm as Xc,bC as xl,gW as bl,gX as ed,aq as wn,as as td}from"./useAppFontEffects-CCgvcQ6u.js";import{r as mt,u as ce,F as ds,cV as sd,cW as Or,w as fn,aw as xn,$ as nd,a7 as vt,o as tn,z as rs,K as Lr,cd as Fr,ck as Kr,R as Na,p as ad,cX as id,j as rd,cc as oa,cY as od,ag as ld,ch as cd,cZ as dd,c_ as pd,s as md,e as _a,ci as ud,A as $a,c$ as vl,X as gd,d0 as hd,cL as fd,W as xd,aD as zr,aE as bd,a6 as Vn,d1 as vd,v as yl,d2 as Ur,cU as _r,d3 as $r,aB as Vr,d4 as yd,d5 as jd,d6 as Br,b as wd,az as jl,d7 as wl,d8 as kd,d9 as Nd,da as Sd,db as Cd,dc as Pd,dd as Id,ar as Ad,i as kl}from"./index-DDInLQDd.js";import{u as Td,U as Hr,y as Gn,A as qn,E as Wn,F as Jn,d as hr,v as Tn,x as En,w as Dn,Y as Un,I as Ed,j as Cs,V as Dd,Z as Ma,_ as Nl,G as Md,H as Rd}from"./runtimeEndpointReset-gWt3Lb5D.js";import{u as Ls,c as Sl,d as Od,p as Ld}from"./vendor-zustand-BAGL70zf.js";import{s as Fd,p as Kd}from"./vendor-yaml-3778uTud.js";import{c as Gr,s as zd,C as qr,P as Ud}from"./shikiHighlight-CRpCl7UT.js";import{getResolvedShikiTheme as _d}from"./appThemeRegistry-BK0dHKa6.js";import{E as Wr}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Cl}from"./vendor-qrcode-DTJ12-WC.js";const Jr=()=>{const{t}=it(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const p=await mt("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!p.ok)return;const m=await p.json().catch(()=>null);if(!m||i)return;const f=typeof m.port=="number"&&Number.isFinite(m.port)&&m.port>0?m.port:null,d=typeof m.tunnelUrl=="string"&&m.tunnelUrl.trim().length>0?m.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(B,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{An(i.url)},children:[s.jsx(R,{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))})},Qr="https://github.com/openchamber/openchamber",$d="https://discord.gg/ZYRSdnwwKA",Yr="https://x.com/openchamber_dev",Vd=800,Pl=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=it(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,p]=o.useState(null),[m,f]=o.useState(null),d=Td(Ls(C=>({info:C.info,checking:C.checking,available:C.available,error:C.error,downloading:C.downloading,downloaded:C.downloaded,progress:C.progress,runtimeType:C.runtimeType,checkForUpdates:C.checkForUpdates,downloadUpdate:C.downloadUpdate,restartToUpdate:C.restartToUpdate}))),{isMobile:y}=ua(),c=l||d.info?.currentVersion||"unknown";o.useEffect(()=>{let C=!1;return(async()=>{try{const S=await mt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const g=await S.json().catch(()=>null),E=typeof g?.openchamberVersion=="string"&&g.openchamberVersion.trim().length>0?g.openchamberVersion.trim():null;C||p(E)}catch{C||p(null)}})(),()=>{C=!0}},[]),o.useEffect(()=>{let C=!1;return(async()=>{try{const S=await mt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const g=await S.json().catch(()=>null),E=typeof g?.currentVersion=="string"&&g.currentVersion.trim().length>0?g.currentVersion.trim():null;C||f(E)}catch{C||f(null)}})(),()=>{C=!0}},[]);const N=o.useRef(!1);o.useEffect(()=>{if(d.checking)r(!0),N.current=!0;else if(i){const C=setTimeout(()=>{r(!1),N.current&&!d.available&&!d.error&&(D.success(e("settings.openchamber.about.toast.latestVersion")),N.current=!1)},Vd);return()=>clearTimeout(C)}},[e,d.checking,i,d.available,d.error]);const b=d.checking||i;return y?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(ec,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${tc}`,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:c})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:m||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(Jr,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!d.available&&!d.error&&s.jsxs(B,{type:"button",variant:"outline",size:"sm",onClick:()=>d.checkForUpdates(),disabled:b,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[b?s.jsx(R,{name:"loader",className:"size-4 animate-spin"}):s.jsx(R,{name:"refresh",className:"size-4"}),e(b?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!b&&d.available&&s.jsxs(B,{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(R,{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:Qr,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(R,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:$d,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(R,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:Yr,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(R,{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(Hr,{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:Et,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Et,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:m||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(R,{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(B,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(R,{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(B,{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:Et,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(Jr,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:Qr,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(R,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Yr,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(R,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(Hr,{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})]})},Bd=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,Us=()=>{const t=ut.c(4),e=ce(Hd),a=Vs(Gd),n=Vs(qd);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=Bd(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function Hd(t){return t.settingsProjectPath}function Gd(t){return t.projects}function qd(t){return t.activeProjectId}const Il=t=>t.trim(),Va=t=>{const e=ut.c(40),{className:a}=t,{t:n}=it(),i=Vs(Wd),r=Us(),l=ce(Jd),p=ds();let m;e[0]!==i?(m=[...i].sort(Qd),e[0]=i,e[1]=m):m=e[1];const f=m;let d;e:{if(f.length===0){d=null;break e}let W;e[2]!==r||e[3]!==f?(W=f.find(k=>k.path===r)??f[0],e[2]=r,e[3]=f,e[4]=W):W=e[4],d=W}const y=d;if(p||f.length===0)return null;let c;e[5]!==y||e[6]!==n?(c=y?.label&&y.label.trim().length>0?y.label:y?.path.split("/").filter(Boolean).pop()||y?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=y,e[6]=n,e[7]=c):c=e[7];const N=c;let b;e[8]!==N?(b=Il(N),e[8]=N,e[9]=b):b=e[9];const C=b;let v;e[10]!==a?(v=ve(a),e[10]=a,e[11]=v):v=e[11];let S;e[12]!==n?(S=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=S):S=e[13];let g;e[14]!==n?(g=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=g):g=e[15];let E,M;e[16]===Symbol.for("react.memo_cache_sentinel")?(E=ve("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),M=s.jsx(R,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=E,e[17]=M):(E=e[16],M=e[17]);let A;e[18]!==C?(A=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:C}),e[18]=C,e[19]=A):A=e[19];let w;e[20]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(R,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=w):w=e[20];let h;e[21]!==A||e[22]!==S||e[23]!==g?(h=s.jsx(sn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":S,title:g,className:E,children:[M,A,w]})}),e[21]=A,e[22]=S,e[23]=g,e[24]=h):h=e[24];const j=y?.id??"";let L;e[25]!==l||e[26]!==f?(L=W=>{if(!W)return;const k=f.find(F=>F.id===W);k&&l(k.path)},e[25]=l,e[26]=f,e[27]=L):L=e[27];let T;e[28]!==f?(T=f.map(Yd),e[28]=f,e[29]=T):T=e[29];let P;e[30]!==j||e[31]!==L||e[32]!==T?(P=s.jsx(nn,{align:"start",className:"w-auto",children:s.jsx(nc,{value:j,onValueChange:L,children:T})}),e[30]=j,e[31]=L,e[32]=T,e[33]=P):P=e[33];let I;e[34]!==h||e[35]!==P?(I=s.jsxs(an,{children:[h,P]}),e[34]=h,e[35]=P,e[36]=I):I=e[36];let K;return e[37]!==I||e[38]!==v?(K=s.jsx("div",{className:v,children:I}),e[37]=I,e[38]=v,e[39]=K):K=e[39],K};function Wd(t){return t.projects}function Jd(t){return t.setSettingsProjectPath}function Qd(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function Yd(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Il(e);return s.jsx(sc,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function Zd(t,e){return`opencode:sidebar-group:${t}:${e}`}const Zi=t=>{const e=ut.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,p=r===void 0?!0:r;let m;e[0]!==a||e[1]!==i?(m=Zd(i,a),e[0]=a,e[1]=i,e[2]=m):m=e[2];const f=m,d=o.useId();let y;e[3]!==p||e[4]!==f?(y=()=>{try{const P=localStorage.getItem(f);if(P!==null)return P==="true"}catch{}return p},e[3]=p,e[4]=f,e[5]=y):y=e[5];const[c,N]=We.useState(y);let b,C;e[6]!==c||e[7]!==f?(b=()=>{try{localStorage.setItem(f,String(c))}catch{}},C=[f,c],e[6]=c,e[7]=f,e[8]=b,e[9]=C):(b=e[8],C=e[9]),We.useEffect(b,C);let v;e[10]===Symbol.for("react.memo_cache_sentinel")?(v=()=>N(Xd),e[10]=v):v=e[10];let S;e[11]===Symbol.for("react.memo_cache_sentinel")?(S=ve("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=S):S=e[11];const g=!c&&"-rotate-90";let E;e[12]!==g?(E=ve("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",g),e[12]=g,e[13]=E):E=e[13];let M;e[14]!==E?(M=s.jsx(R,{name:"arrow-down-s",className:E}),e[14]=E,e[15]=M):M=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 w;e[18]!==n?(w=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=w):w=e[19];let h;e[20]!==d||e[21]!==c||e[22]!==M||e[23]!==A||e[24]!==w?(h=s.jsxs("button",{type:"button",onClick:v,"aria-expanded":c,"aria-controls":d,className:S,children:[M,A,w]}),e[20]=d,e[21]=c,e[22]=M,e[23]=A,e[24]=w,e[25]=h):h=e[25];const j=!c;let L;e[26]!==l||e[27]!==d||e[28]!==j?(L=s.jsx("div",{id:d,hidden:j,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]=j,e[29]=L):L=e[29];let T;return e[30]!==h||e[31]!==L?(T=s.jsxs("div",{children:[h,L]}),e[30]=h,e[31]=L,e[32]=T):T=e[32],T};function Xd(t){return!t}const ep=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},tp=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())},Zr=t=>{const e=tp(ep(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},sp=({onItemSelect:t})=>{const{t:e}=it(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,p]=o.useState(null),[m,f]=o.useState(null),[d,y]=o.useState(!1),[c,N]=o.useState(null),{selectedAgentName:b,setSelectedAgent:C,setAgentDraft:v,createAgent:S,deleteAgent:g,loadAgents:E}=Bn(Ls(_=>({selectedAgentName:_.selectedAgentName,setSelectedAgent:_.setSelectedAgent,setAgentDraft:_.setAgentDraft,createAgent:_.createAgent,deleteAgent:_.deleteAgent,loadAgents:_.loadAgents}))),M=Us(),A=Bn(_=>nl(_,M));o.useEffect(()=>{E(M)},[E,M]);const w="bg-background",h=()=>{const _="new-agent";let re=_,V=1;for(;A.some($=>$.name===re);)re=`${_}-${V}`,V++;v({name:re,scope:"user"}),C(re),t?.()},j=async _=>{if(la(_)){D.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}p(_),f("delete")},L=async _=>{la(_)&&(p(_),f("reset"))},T=()=>{p(null),f(null)},P=async()=>{if(!(!l||!m)){y(!0);try{const _=await g(l.name,l.scope,M);_.ok?(_.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):_.restartDeferred?D.success(e("settings.view.pendingRestart.saved")):m==="delete"?D.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):D.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),T()):m==="delete"?D.error(e("settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(_){const re=_ instanceof Error?_.message:"",V=/built-in|not deletable|not found/i.test(re);m==="delete"?D.error(e(V?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}y(!1)}},I=_=>{const re=_.name;let V=1,$=`${re}-copy`;for(;A.some(Z=>Z.name===$);)V++,$=`${re}-copy-${V}`;const z=_,O=_.model?.providerID&&_.model?.modelID?`${_.model.providerID}/${_.model.modelID}`:null,Y=_;v({name:$,scope:z.scope||"user",description:_.description,model:O,variant:_.variant,temperature:_.temperature,top_p:_.topP,prompt:_.prompt,mode:_.mode,permission:Zr(_.permission),disable:Y.disable}),C($),t?.()},K=_=>{r(_.name),n(_)},W=async()=>{if(!a)return;const _=i.trim().replace(/\s+/g,"-");if(!_){D.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(_===a.name){n(null);return}if(A.some(z=>z.name===_)){D.error(e("settings.agents.sidebar.toast.agentExists"));return}const re=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,V=a,$=await S({name:_,description:a.description,model:re,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:Zr(a.permission),disable:V.disable,scope:V.scope},M);if($.ok){const z=await g(a.name,V.scope,M);z.ok?($.requiresManualRestart||z.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):D.success(e("settings.agents.sidebar.toast.agentRenamed",{name:_})),C(_)):D.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else D.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},k=_=>{switch(_){case"primary":return s.jsx(R,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(R,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(R,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},F=A.filter(_=>!ac(_)),q=F.filter(la),U=F.filter(_=>!la(_)),{groupedCustomAgents:Q,ungroupedCustomAgents:ne}=We.useMemo(()=>{const _={},re=[];for(const $ of U){const z=$;z.group?(_[z.group]||(_[z.group]=[]),_[z.group].push($)):re.push($)}return{groupedCustomAgents:Object.keys(_).sort(($,z)=>$.localeCompare(z)).map($=>({name:$,agents:_[$]})),ungroupedCustomAgents:re}},[U]);return s.jsxs("div",{className:ve("flex h-full flex-col",w),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${on} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Va,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:F.length})}),s.jsx(B,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:h,children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:F.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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:[q.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")}),q.map(_=>s.jsx(Fi,{agent:_,isSelected:b===_.name,onSelect:()=>{C(_.name),t?.()},onReset:()=>L(_),onDuplicate:()=>I(_),getAgentModeIcon:k,isMenuOpen:c===_.name,onMenuOpenChange:re=>N(re?_.name:null)},_.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")}),Q.map(({name:_,agents:re})=>s.jsx(Zi,{label:_,count:re.length,storageKey:"agents",children:re.map(V=>s.jsx(Fi,{agent:V,isSelected:b===V.name,onSelect:()=>{C(V.name),t?.()},onRename:()=>K(V),onDelete:()=>j(V),onDuplicate:()=>I(V),getAgentModeIcon:k,isMenuOpen:c===V.name,onMenuOpenChange:$=>N($?V.name:null)},V.name))},_)),ne.map(_=>s.jsx(Fi,{agent:_,isSelected:b===_.name,onSelect:()=>{C(_.name),t?.()},onRename:()=>K(_),onDelete:()=>j(_),onDuplicate:()=>I(_),getAgentModeIcon:k,isMenuOpen:c===_.name,onMenuOpenChange:re=>N(re?_.name:null)},_.name))]})]})}),s.jsx(Kt,{open:l!==null&&m!==null,onOpenChange:_=>{!_&&!d&&T()},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:e(m==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Vt,{children:m==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:T,disabled:d,children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:P,disabled:d,children:e(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Kt,{open:a!==null,onOpenChange:_=>!_&&n(null),children:s.jsxs(zt,{children:[s.jsxs(_t,{children:[s.jsx($t,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(Je,{value:i,onChange:_=>r(_.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:_=>{_.key==="Enter"&&W()}}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:W,children:e("settings.common.actions.rename")})]})]})})]})},Fi=t=>{const e=ut.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:p,onDuplicate:m,getAgentModeIcon:f,isMenuOpen:d,onMenuOpenChange:y}=t,{t:c}=it(),N=a;let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=za(),e[0]=b):b=e[0];const C=b,[v,S]=o.useState(!1);let g;e[1]!==r||e[2]!==m||e[3]!==p||e[4]!==l||e[5]!==c?(g=re=>s.jsxs(s.Fragment,{children:[p&&s.jsxs(re,{onClick:V=>{V.stopPropagation(),p()},children:[s.jsx(R,{name:"edit",className:"h-4 w-4 mr-px"}),c("settings.common.actions.rename")]}),s.jsxs(re,{onClick:V=>{V.stopPropagation(),m()},children:[s.jsx(R,{name:"file-copy",className:"h-4 w-4 mr-px"}),c("settings.common.actions.duplicate")]}),l&&s.jsxs(re,{onClick:V=>{V.stopPropagation(),l()},children:[s.jsx(R,{name:"restart",className:"h-4 w-4 mr-px"}),c("settings.common.actions.reset")]}),r&&s.jsxs(re,{onClick:V=>{V.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),c("settings.common.actions.delete")]})]}),e[1]=r,e[2]=m,e[3]=p,e[4]=l,e[5]=c,e[6]=g):g=e[6];const E=g,M=n?"bg-interactive-selection":"hover:bg-interactive-hover";let A;e[7]!==M?(A=ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",M),e[7]=M,e[8]=A):A=e[8];let w;e[9]===Symbol.for("react.memo_cache_sentinel")?(w=C?void 0:re=>{re.preventDefault(),S(!0)},e[9]=w):w=e[9];let h;e[10]!==A?(h=s.jsx("div",{className:A,onContextMenu:w}),e[10]=A,e[11]=h):h=e[11];let j;e[12]!==a.name?(j=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=j):j=e[13];let L;e[14]!==a.mode||e[15]!==f?(L=f(a.mode),e[14]=a.mode,e[15]=f,e[16]=L):L=e[16];let T;e[17]!==a||e[18]!==N.scope||e[19]!==c?(T=(N.scope||la(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:la(a)?c("settings.agents.sidebar.badge.system"):N.scope}),e[17]=a,e[18]=N.scope,e[19]=c,e[20]=T):T=e[20];let P;e[21]!==j||e[22]!==L||e[23]!==T?(P=s.jsxs("div",{className:"flex items-center gap-1.5",children:[j,L,T]}),e[21]=j,e[22]=L,e[23]=T,e[24]=P):P=e[24];let I;e[25]!==a.description?(I=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=I):I=e[26];let K;e[27]!==i||e[28]!==P||e[29]!==I?(K=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[P,I]}),e[27]=i,e[28]=P,e[29]=I,e[30]=K):K=e[30];let W;e[31]!==y?(W=re=>{re&&S(!1),y(re)},e[31]=y,e[32]=W):W=e[32];let k;e[33]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(sn,{asChild:!0,children:s.jsx(B,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=k):k=e[33];let F;e[34]!==E?(F=s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:E(rn)}),e[34]=E,e[35]=F):F=e[35];let q;e[36]!==d||e[37]!==W||e[38]!==F?(q=s.jsxs(an,{open:d,onOpenChange:W,children:[k,F]}),e[36]=d,e[37]=W,e[38]=F,e[39]=q):q=e[39];let U;e[40]!==K||e[41]!==q?(U=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[K,q]}),e[40]=K,e[41]=q,e[42]=U):U=e[42];let Q;e[43]!==U||e[44]!==h?(Q=s.jsx(Wn,{render:h,children:U}),e[43]=U,e[44]=h,e[45]=Q):Q=e[45];let ne;e[46]!==E?(ne=s.jsx(Gn,{className:"w-fit min-w-20",children:E(qn)}),e[46]=E,e[47]=ne):ne=e[47];let _;return e[48]!==v||e[49]!==Q||e[50]!==ne?(_=s.jsxs(Jn,{open:v,onOpenChange:S,children:[Q,ne]}),e[48]=v,e[49]=Q,e[50]=ne,e[51]=_):_=e[51],_},ss=t=>{const e=ut.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:p,description:m,headerEnd:f,showSaveStatus:d}=t,y=d===void 0?!1:d,c=r!=null||m!=null||f!=null||y,N=typeof r=="string"||typeof r=="number",b=l!=null||p!=null;let C;e[0]!==i?(C=ve("h-full",i),e[0]=i,e[1]=C):C=e[1];let v;e[2]!==n?(v=ve("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]=v):v=e[3];let S;e[4]!==m||e[5]!==c||e[6]!==b||e[7]!==f||e[8]!==N||e[9]!==y||e[10]!==r||e[11]!==p||e[12]!==l?(S=c&&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?N?b?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:ve(Qi,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:p})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Qi,children:r}):r:null,m!=null?typeof m=="string"||typeof m=="number"?s.jsx("p",{className:ic,children:m}):m:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[f,y&&s.jsx(ap,{})]})]}),e[4]=m,e[5]=c,e[6]=b,e[7]=f,e[8]=N,e[9]=y,e[10]=r,e[11]=p,e[12]=l,e[13]=S):S=e[13];let g;e[14]!==a||e[15]!==v||e[16]!==S?(g=s.jsxs("div",{className:v,children:[S,a]}),e[14]=a,e[15]=v,e[16]=S,e[17]=g):g=e[17];let E;return e[18]!==C||e[19]!==g?(E=s.jsx(Bs,{outerClassName:C,className:"w-full @container",children:g}),e[18]=C,e[19]=g,e[20]=E):E=e[20],E},np=500,ap=()=>{const t=ut.c(13),{t:e}=it(),a=o.useSyncExternalStore(sd,Or,Or),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const d=setTimeout(()=>i(!0),np);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(R,{name:"error-warning",className:"size-3.5"}),t[3]=d):d=t[3];let y;t[4]!==e?(y=e("settings.common.status.saveFailed"),t[4]=e,t[5]=y):y=t[5];let c;return t[6]!==y?(c=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:y})]}),t[6]=y,t[7]=c):c=t[7],c}if(a!=="saving"||!n)return null;let p;t[8]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=p):p=t[8];let m;t[9]!==e?(m=e("settings.common.actions.saving"),t[9]=e,t[10]=m):m=t[10];let f;return t[11]!==m?(f=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[p,s.jsx("span",{children:m})]}),t[11]=m,t[12]=f):f=t[12],f},ip=["allow","ask","deny"],Ra=t=>t==="allow"||t==="ask"||t==="deny",Xi=()=>({global:null,keys:{}}),rp=t=>{const e=Xi();if(t==null)return e;if(typeof t=="string")return Ra(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Ra(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(Ra(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))Ra(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},er=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},op=(t,e)=>JSON.stringify(er(t))===JSON.stringify(er(e)),kn=t=>JSON.parse(JSON.stringify(t)),lp=["edit","external_directory","doom_loop","plan_enter","plan_exit"],cp=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),Xr=new Set(["write","patch","apply_patch","multiedit","invalid"]),dp=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),pp=({agent:t})=>{const{t:e}=it(),a=Bn(z=>z.updateAgent),[n,i]=o.useState(Xi),[r,l]=o.useState(Xi),[p,m]=o.useState(!0),[f,d]=o.useState(!1),[y,c]=o.useState(!1),[N,b]=o.useState({}),[C,v]=o.useState([]),[S,g]=o.useState(""),[E,M]=o.useState(0),A=t.name,w=Us();o.useEffect(()=>{let z=!1;return m(!0),d(!1),(async()=>{try{const O=w,Y=O?`?directory=${encodeURIComponent(O)}`:"",Z=await mt(`/api/config/agents/${encodeURIComponent(A)}/config${Y}`,{headers:{"Cache-Control":"no-cache",...O?{"x-opencode-directory":O}:{}}});if(!Z.ok)throw new Error(String(Z.status));const ee=await Z.json().catch(()=>null);if(z)return;const ge=rp(ee?.config?.permission);i(kn(ge)),l(ge)}catch{z||d(!0)}finally{z||m(!1)}})(),()=>{z=!0}},[A,E,w]),o.useEffect(()=>{let z=!1;return(async()=>{try{const O=await fn.listToolIds({directory:w});!z&&Array.isArray(O)&&v(O.filter(Y=>typeof Y=="string"&&!Xr.has(Y)))}catch{}})(),()=>{z=!0}},[A,w]);const h=o.useMemo(()=>{const z=t.permission;if(!Array.isArray(z))return[];const O=[];for(const Y of z){if(!Y||typeof Y!="object")continue;const{permission:Z,pattern:ee,action:ge}=Y;typeof Z=="string"&&typeof ee=="string"&&Ra(ge)&&O.push({permission:Z,pattern:ee,action:ge})}return O},[t]),j=o.useCallback(z=>{const O=h.find(Z=>Z.permission===z&&Z.pattern==="*");if(O)return O.action;const Y=h.find(Z=>Z.permission==="*"&&Z.pattern==="*");return Y?Y.action:null},[h]),L=o.useCallback(z=>{const O=r.keys[z]?.patterns??[],Y=new Set(O.map(Z=>Z.pattern));return h.filter(Z=>Z.permission===z&&Z.pattern!=="*"&&!Y.has(Z.pattern))},[h,r.keys]),T=o.useMemo(()=>{const z=new Set;for(const O of C)z.add(O);for(const O of lp)z.add(O);for(const O of Object.keys(r.keys))z.add(O);for(const O of Xr)z.delete(O);return Array.from(z).sort((O,Y)=>O.localeCompare(Y))},[C,r.keys]),P=o.useMemo(()=>!op(r,n),[r,n]),I=z=>{l(O=>({...O,global:z}))},K=(z,O)=>{l(Y=>{const Z=kn(Y),ee=Z.keys[z]??{action:null,patterns:[]};return ee.action=O,ee.action===null&&ee.patterns.length===0?delete Z.keys[z]:Z.keys[z]=ee,Z})},W=(z,O,Y,Z)=>{l(ee=>{const ge=kn(ee),de=ge.keys[z]??{action:null,patterns:[]};return de.patterns[O]={pattern:Y,action:Z},ge.keys[z]=de,ge})},k=z=>{l(O=>{const Y=kn(O),Z=Y.keys[z]??{action:null,patterns:[]};return Z.patterns.push({pattern:"",action:"allow"}),Y.keys[z]=Z,Y}),b(O=>({...O,[z]:!0}))},F=(z,O)=>{l(Y=>{const Z=kn(Y),ee=Z.keys[z];return ee?(ee.patterns.splice(O,1),ee.action===null&&ee.patterns.length===0&&delete Z.keys[z],Z):Y})},q=()=>{const z=S.trim();!z||z==="*"||(l(O=>{if(O.keys[z])return O;const Y=kn(O);return Y.keys[z]={action:"ask",patterns:[]},Y}),b(O=>({...O,[z]:!0})),g(""))},U=async()=>{c(!0);try{const z=er(r),O=await a(A,{permission:z});O.ok?(i(kn(r)),D.success(O.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):D.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{c(!1)}},Q=()=>{l(kn(n))},ne=z=>e(z==="allow"?"settings.agents.page.permissionsEditor.action.allow":z==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),_=e("settings.agents.page.permissionsEditor.action.inherit"),re=e("settings.agents.page.permissionsEditor.action.default"),V=z=>[...z?[{value:"inherit",label:z}]:[],...ip.map(O=>({value:O,label:ne(O)}))],$=(z,O,Y,Z=_)=>s.jsx(Ws,{value:z??"inherit",options:V(Z),onChange:ee=>O(ee==="inherit"?null:ee),"aria-label":Y});return p?s.jsx(_e,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:Kn,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(B,{variant:"outline",size:"xs",onClick:()=>M(z=>z+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(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:Q,disabled:y,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(B,{size:"xs",className:"!font-normal",onClick:()=>{U()},disabled:y,children:e(y?"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:Et,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Jt,{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:ne(j("*")??"allow")})})]}),$(r.global,I,e("settings.agents.page.permissionsEditor.defaultAria"),re)]}),s.jsx("div",{children:T.map(z=>{const O=r.keys[z]??{action:null,patterns:[]},Y=L(z),Z=cp.has(z)||O.patterns.length>0,ee=Z||Y.length>0,ge=N[z]===!0,de=j(z);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:ee?()=>b(xe=>({...xe,[z]:!ge})):void 0,className:ve("flex min-w-0 items-center gap-1.5 text-left",!ee&&"cursor-default"),"aria-expanded":ee?ge:void 0,children:[s.jsx(R,{name:ge&&ee?"arrow-down-s":"arrow-right-s",className:ve("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ee&&"opacity-0")}),s.jsx("span",{className:Et,children:dp(z)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:z}),O.action===null&&de!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ne(de)})}),O.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(O.patterns.length)})})]}),$(O.action,xe=>K(z,xe),e("settings.agents.page.permissionsEditor.keyAria",{key:z}))]}),ge&&ee&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[O.patterns.map((xe,ae)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(Je,{value:xe.pattern,onChange:te=>W(z,ae,te.target.value,xe.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(Ws,{value:xe.action,options:V(),onChange:te=>W(z,ae,xe.pattern,te),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:z})}),s.jsx(B,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>F(z,ae),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]},ae)),Z&&s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>k(z),children:[s.jsx(R,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),Y.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(Jt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),Y.map(xe=>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:xe.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:ne(xe.action)})]},`${xe.pattern}-${xe.action}`))]})]})]},z)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(Je,{value:S,onChange:z=>g(z.target.value),onKeyDown:z=>{z.key==="Enter"&&(z.preventDefault(),q())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:q,disabled:!S.trim(),children:[s.jsx(R,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},mp=(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):[]},up=()=>{const{t}=it(),e=et($=>$.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agentDraft:l,setAgentDraft:p}=Bn(Ls($=>({selectedAgentName:$.selectedAgentName,getAgentByName:$.getAgentByName,createAgent:$.createAgent,updateAgent:$.updateAgent,agentDraft:$.agentDraft,setAgentDraft:$.setAgentDraft}))),m=Us(),f=Bn($=>nl($,m)),d=a?n(a,m):null,y=!!(l&&l.name===a&&!d),[c,N]=o.useState(""),[b,C]=o.useState("user"),[v,S]=o.useState(""),[g,E]=o.useState("subagent"),[M,A]=o.useState(""),[w,h]=o.useState(""),[j,L]=o.useState(void 0),[T,P]=o.useState(void 0),[I,K]=o.useState(""),[W,k]=o.useState(!1),F=o.useRef(null),q=o.useMemo(()=>mp(e,M),[M,e]),U=q.length>0,Q=w||"__default",ne=U,_=o.useMemo(()=>w&&!q.includes(w)?[w,...q]:q,[w,q]);o.useEffect(()=>{if(y&&l){const $=l.name||"",z=l.scope||"user",O=l.description||"",Y=l.mode||"subagent",Z=l.model||"",ee=l.variant||"",ge=l.temperature??void 0,de=l.top_p??void 0,xe=l.prompt||"";N($),C(z),S(O),E(Y),A(Z),h(ee),L(ge),P(de),K(xe),F.current={draftName:$,draftScope:z,description:O,mode:Y,model:Z,variant:ee,temperature:ge,topP:de,prompt:xe};return}if(d&&a===d.name){const $=d.description||"",z=d.mode||"subagent",O=d.model?.providerID&&d.model?.modelID?`${d.model.providerID}/${d.model.modelID}`:"",Y=d.variant||"",Z=d.temperature??void 0,ee=d.topP??void 0,ge=d.prompt||"";S($),E(z),A(O),h(Y),L(Z),P(ee),K(ge),F.current={draftName:"",draftScope:"user",description:$,mode:z,model:O,variant:Y,temperature:Z,topP:ee,prompt:ge}}},[l,y,d,a]);const re=o.useMemo(()=>{const $=F.current;return $?!!(y&&(c!==$.draftName||b!==$.draftScope)||v!==$.description||g!==$.mode||M!==$.model||w!==$.variant||j!==$.temperature||T!==$.topP||I!==$.prompt):!1},[v,c,b,y,g,M,I,j,T,w]),V=async()=>{const $=y?c.trim().replace(/\s+/g,"-"):a?.trim();if(!$){D.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(y&&f.some(z=>z.name===$)){D.error(t("settings.agents.sidebar.toast.agentExists"));return}k(!0);try{const z=M.trim(),O=w.trim(),Y=I.trim(),Z={name:$,...v.trim()?{description:v.trim()}:{},mode:g,model:z===""?null:z,variant:O===""?null:O||void 0,temperature:j??null,top_p:T??null,prompt:Y||(y?void 0:null),...y&&b?{scope:b}:{}};let ee;y?(ee=await i(Z,m),ee.ok&&p(null)):ee=await r($,Z,m),ee.ok?ee.requiresManualRestart?D.warning(t("settings.agents.page.toast.savedManualRestart")):ee.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(t(y?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):D.error(t(y?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(z){console.error("Error saving agent:",z);const O=z instanceof Error&&z.message?z.message:t("settings.agents.page.toast.saveUnexpectedError");D.error(O)}finally{k(!1)}};return a?s.jsxs(ss,{title:y?t("settings.agents.page.title.new"):a,description:t(y?"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:[y&&s.jsxs(Ot,{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(Je,{value:c,onChange:$=>N($.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Pt,{value:b,onValueChange:$=>C($),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Wt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Is,{value:v,onChange:$=>S($.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Wt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Ws,{"aria-label":t("settings.agents.page.field.mode"),value:g,onChange:E,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(Ot,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Oa,{providerId:da(M)?.providerId??"",modelId:da(M)?.modelId??"",onChange:($,z)=>{A($&&z?`${$}/${z}`:""),h("")},className:In})}),s.jsx(Ot,{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:ne?s.jsxs(Pt,{value:Q,onValueChange:$=>h($==="__default"?"":$),children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:$=>$==="__default"?t("chat.modelControls.default"):$})}),s.jsxs(At,{children:[s.jsx(ot,{value:"__default",children:t("chat.modelControls.default")}),_.map($=>s.jsx(ot,{value:$,children:$},$))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Je,{value:w,onChange:$=>h($.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!M&&!w,className:"h-8 w-40 rounded-md px-3"}),w&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>h(""),className:hs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Ot,{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(Ss,{value:j,fallbackValue:.7,onValueChange:L,onClear:()=>L(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),j!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>L(void 0),className:hs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Ot,{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(Ss,{value:T,fallbackValue:.9,onValueChange:P,onClear:()=>P(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),T!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>P(void 0),className:hs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(R,{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(Is,{value:I,onChange:$=>K($.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"})}),!y&&d&&s.jsx(pp,{agent:d}),s.jsx("div",{className:"pb-8",children:s.jsx(B,{onClick:V,disabled:W||!re,size:"xs",className:"!font-normal",children:t(W?"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(R,{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")})]})})},gp="~/.config/opencode/AGENTS.md",Al=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},hp=t=>t.length>0&&!t.endsWith(`
2
- `)?`${t}
3
- `:t,Qa={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},fp=(t,e)=>t==="custom"?e:lc(t),xp=t=>t==="custom"?"custom":al(t)?t:"concise",eo={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"},Ki=async(t,e)=>{xn("saving");try{const a=await mt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(await Al(a,e));xn("saved")}catch(a){throw xn("error"),a}},bp=()=>{const{t}=it(),e=rc(),[a,n]=o.useState(""),[i,r]=o.useState(!1),[l,p]=o.useState(Qa.responseStyleEnabled),[m,f]=o.useState(Qa.responseStylePreset),[d,y]=o.useState(Qa.responseStyleCustomInstructions),[c,N]=o.useState(!0),[b,C]=o.useState(!1),[v,S]=o.useState(!1),[g,E]=o.useState(""),[M,A]=o.useState(!1),w=o.useRef(null);o.useEffect(()=>{const I=new AbortController;return(async()=>{try{const[W,k]=await Promise.all([mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:I.signal}),mt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:I.signal})]);let F=Qa;if(W.ok){const q=await W.json();F={...F,optimizeSystemPrompt:q.optimizeSystemPrompt===!0,responseStyleEnabled:q.responseStyleEnabled===!0,responseStylePreset:xp(q.responseStylePreset),responseStyleCustomInstructions:typeof q.responseStyleCustomInstructions=="string"?q.responseStyleCustomInstructions:""},typeof q.globalBehaviorPrompt=="string"&&(F={...F,prompt:q.globalBehaviorPrompt})}if(!F.prompt.trim()&&k.ok){const q=await k.json();typeof q.content=="string"&&(F={...F,prompt:q.content})}n(F.prompt),r(F.optimizeSystemPrompt),A(F.optimizeSystemPrompt),p(F.responseStyleEnabled),f(F.responseStylePreset),y(F.responseStyleCustomInstructions),E(F.prompt),w.current={enabled:F.responseStyleEnabled,preset:F.responseStylePreset,custom:F.responseStyleCustomInstructions}}catch(W){W.name!=="AbortError"&&console.warn("Failed to load behavior settings:",W)}finally{N(!1)}})(),()=>I.abort()},[]),o.useEffect(()=>{if(c)return;const I=w.current;if(I&&I.enabled===l&&I.preset===m&&I.custom===d)return;const K={enabled:l,preset:m,custom:d},W=setTimeout(async()=>{try{await Ki({responseStyleEnabled:K.enabled,responseStylePreset:K.preset,responseStyleCustomInstructions:K.custom},t("settings.behavior.page.toast.saveFailed")),w.current=K}catch(k){const F=k instanceof Error?k.message:t("settings.behavior.page.toast.saveFailed");D.error(F)}},400);return()=>clearTimeout(W)},[l,m,d,c,t]);const h=fp(m,d),j=a!==g,L=i!==M,T=async()=>{C(!0);try{const I=hp(a),K=await mt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:I})});if(!K.ok)throw new Error(await Al(K,t("settings.behavior.page.toast.saveFailed")));const W=await K.json().catch(()=>null),k=il(W,"behavior",{id:"agents-md"});await Ki({globalBehaviorPrompt:I},t("settings.behavior.page.toast.saveFailed")),n(I),E(I),D.success(t(k?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(I){console.error("Failed to save behavior:",I);const K=I instanceof Error?I.message:t("settings.behavior.page.toast.saveFailed");D.error(K)}finally{C(!1)}},P=async()=>{S(!0);try{await Ki({optimizeSystemPrompt:i},t("settings.behavior.page.toast.saveFailed")),A(i),_n("behavior",{id:"optimize-system-prompt"}),D.success(t("settings.view.pendingRestart.saved"))}catch(I){const K=I instanceof Error?I.message:t("settings.behavior.page.toast.saveFailed");D.error(K)}finally{S(!1)}};return s.jsxs(ss,{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(gt,{checked:i,onChange:r,disabled:c||v,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(B,{type:"button",size:"xs",onClick:()=>{P()},disabled:c||v||!L,className:"!font-normal",children:t(v?"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:gp})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Is,{value:a,onChange:I=>n(I.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:c,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(B,{onClick:T,disabled:b||!j||c,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(gt,{checked:l,onChange:p,disabled:c,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Ot,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Pt,{value:m,onValueChange:I=>f(I),disabled:c||!l,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{children:I=>I==="custom"?t("settings.behavior.page.responseStyle.option.custom"):al(I)?t(eo[I]):null})}),s.jsxs(At,{children:[oc.map(I=>s.jsx(ot,{value:I,children:t(eo[I])},I)),s.jsx(ot,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Is,{value:h,onChange:I=>y(I.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:c||!l||m!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},vp=t=>{const e=ut.c(176),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,p]=o.useState(""),[m,f]=o.useState(null),[d,y]=o.useState(null),[c,N]=o.useState(!1),[b,C]=o.useState(null),{selectedCommandName:v,setSelectedCommand:S,setCommandDraft:g,createCommand:E,deleteCommand:M,loadCommands:A}=pa(Ls(yp)),w=Us();let h;e[0]!==w?(h=Ke=>rl(Ke,w),e[0]=w,e[1]=h):h=e[1];const j=pa(h);let L;e[2]!==w?(L=Ke=>cr(Ke,w),e[2]=w,e[3]=L):L=e[3];const T=$s(L),P=$s(jp);let I,K;e[4]!==A||e[5]!==P||e[6]!==w?(I=()=>{A(w),P(w)},K=[A,P,w],e[4]=A,e[5]=P,e[6]=w,e[7]=I,e[8]=K):(I=e[7],K=e[8]),o.useEffect(I,K);let W;e[9]!==T?(W=new Set(T.map(wp)),e[9]=T,e[10]=W):W=e[10];const k=W;let F;if(e[11]!==j||e[12]!==k){let Ke;e[14]!==k?(Ke=wt=>!k.has(wt.name),e[14]=k,e[15]=Ke):Ke=e[15],F=j.filter(Ke),e[11]=j,e[12]=k,e[13]=F}else F=e[13];const q=F;let U,Q;e[16]!==v||e[17]!==S||e[18]!==k?(U=()=>{v&&k.has(v)&&S(null)},Q=[v,S,k],e[16]=v,e[17]=S,e[18]=k,e[19]=U,e[20]=Q):(U=e[19],Q=e[20]),o.useEffect(U,Q);let ne;e[21]!==j||e[22]!==a||e[23]!==g||e[24]!==S?(ne=()=>{let Ke="new-command",wt=1;for(;j.some(Ee=>Ee.name===Ke);)Ke=`new-command-${wt}`,wt++;g({name:Ke,scope:"user"}),S(Ke),a?.()},e[21]=j,e[22]=a,e[23]=g,e[24]=S,e[25]=ne):ne=e[25];const _=ne;let re;e[26]!==n?(re=async Ke=>{if(ca(Ke)){D.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}f(Ke),y("delete")},e[26]=n,e[27]=re):re=e[27];const V=re;let $;e[28]===Symbol.for("react.memo_cache_sentinel")?($=async Ke=>{ca(Ke)&&(f(Ke),y("reset"))},e[28]=$):$=e[28];const z=$;let O;e[29]===Symbol.for("react.memo_cache_sentinel")?(O=()=>{f(null),y(null)},e[29]=O):O=e[29];const Y=O;let Z;e[30]!==m||e[31]!==d||e[32]!==M||e[33]!==w||e[34]!==n?(Z=async()=>{if(!m||!d)return;N(!0),await M(m.name,w)?(d==="delete"?D.success(n("settings.commands.sidebar.toast.commandDeleted",{name:m.name})):D.success(n("settings.commands.sidebar.toast.commandReset",{name:m.name})),Y()):d==="delete"?D.error(n("settings.commands.sidebar.toast.deleteFailed")):D.error(n("settings.commands.sidebar.toast.resetFailed")),N(!1)},e[30]=m,e[31]=d,e[32]=M,e[33]=w,e[34]=n,e[35]=Z):Z=e[35];const ee=Z;let ge;e[36]!==j||e[37]!==g||e[38]!==S?(ge=Ke=>{const wt=Ke.name;let Ee=1,jt=`${wt}-copy`;for(;j.some(J=>J.name===jt);)Ee++,jt=`${wt}-copy-${Ee}`;g({name:jt,scope:Ke.scope||"user",description:Ke.description,template:Ke.template,agent:Ke.agent,model:Ke.model}),S(jt)},e[36]=j,e[37]=g,e[38]=S,e[39]=ge):ge=e[39];const de=ge;let xe;e[40]===Symbol.for("react.memo_cache_sentinel")?(xe=Ke=>{p(Ke.name),r(Ke)},e[40]=xe):xe=e[40];const ae=xe;let te;e[41]!==j||e[42]!==E||e[43]!==M||e[44]!==i||e[45]!==l||e[46]!==S||e[47]!==w||e[48]!==n?(te=async()=>{if(!i)return;const Ke=l.trim().replace(/\s+/g,"-");if(!Ke){D.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ke===i.name){r(null);return}if(j.some(Ee=>Ee.name===Ke)){D.error(n("settings.commands.sidebar.toast.commandExists"));return}await E({name:Ke,description:i.description,template:i.template,agent:i.agent,model:i.model},w)?await M(i.name,w)?(D.success(`Command renamed to "${Ke}"`),S(Ke)):D.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):D.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[41]=j,e[42]=E,e[43]=M,e[44]=i,e[45]=l,e[46]=S,e[47]=w,e[48]=n,e[49]=te):te=e[49];const me=te;let Pe,Ne,Se,be,Fe,Le;if(e[50]!==q||e[51]!==_||e[52]!==V||e[53]!==de||e[54]!==a||e[55]!==b||e[56]!==v||e[57]!==S||e[58]!==n){const Ke=q.filter(ca),wt=q.filter(kp);e[65]===Symbol.for("react.memo_cache_sentinel")?(Fe=ve("flex h-full flex-col","bg-background"),e[65]=Fe):Fe=e[65];let Ee;e[66]!==n?(Ee=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Ee):Ee=e[67];let jt;e[68]!==Ee?(jt=s.jsx("h2",{className:`${on} mb-3`,children:Ee}),e[68]=Ee,e[69]=jt):jt=e[69];let J;e[70]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(Va,{className:"mb-3"}),e[70]=J):J=e[70];let he;e[71]!==q.length||e[72]!==n?(he=n("settings.commands.sidebar.total",{count:q.length}),e[71]=q.length,e[72]=n,e[73]=he):he=e[73];let ze;e[74]!==he?(ze=s.jsx("span",{className:"typography-meta text-muted-foreground",children:he}),e[74]=he,e[75]=ze):ze=e[75];let Re;e[76]===Symbol.for("react.memo_cache_sentinel")?(Re=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Re):Re=e[76];let ct;e[77]!==_?(ct=s.jsx(B,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:_,children:Re}),e[77]=_,e[78]=ct):ct=e[78];let lt;e[79]!==ze||e[80]!==ct?(lt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ze,ct]}),e[79]=ze,e[80]=ct,e[81]=lt):lt=e[81],e[82]!==jt||e[83]!==lt?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[jt,J,lt]}),e[82]=jt,e[83]=lt,e[84]=Le):Le=e[84],Pe=Bs,Ne="flex-1 min-h-0",Se="space-y-1 px-3 py-2",be=q.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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:[Ke.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")}),[...Ke].sort(Np).map(Qe=>s.jsx(to,{command:Qe,isSelected:v===Qe.name,onSelect:()=>{S(Qe.name),a?.()},onReset:()=>z(Qe),onDuplicate:()=>de(Qe),isMenuOpen:b===Qe.name,onMenuOpenChange:Nt=>C(Nt?Qe.name:null)},Qe.name))]}),wt.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")}),[...wt].sort(Sp).map(Qe=>s.jsx(to,{command:Qe,isSelected:v===Qe.name,onSelect:()=>{S(Qe.name),a?.()},onRename:()=>ae(Qe),onDelete:()=>V(Qe),onDuplicate:()=>de(Qe),isMenuOpen:b===Qe.name,onMenuOpenChange:Nt=>C(Nt?Qe.name:null)},Qe.name))]})]}),e[50]=q,e[51]=_,e[52]=V,e[53]=de,e[54]=a,e[55]=b,e[56]=v,e[57]=S,e[58]=n,e[59]=Pe,e[60]=Ne,e[61]=Se,e[62]=be,e[63]=Fe,e[64]=Le}else Pe=e[59],Ne=e[60],Se=e[61],be=e[62],Fe=e[63],Le=e[64];let oe;e[85]!==Pe||e[86]!==Ne||e[87]!==Se||e[88]!==be?(oe=s.jsx(Pe,{outerClassName:Ne,className:Se,children:be}),e[85]=Pe,e[86]=Ne,e[87]=Se,e[88]=be,e[89]=oe):oe=e[89];const fe=m!==null&&d!==null;let De;e[90]!==c?(De=Ke=>{!Ke&&!c&&Y()},e[90]=c,e[91]=De):De=e[91];let $e;e[92]!==d||e[93]!==n?($e=n(d==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=d,e[93]=n,e[94]=$e):$e=e[94];let Ve;e[95]!==$e?(Ve=s.jsx($t,{children:$e}),e[95]=$e,e[96]=Ve):Ve=e[96];let qe;e[97]!==m?.name||e[98]!==d||e[99]!==n?(qe=d==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:m?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:m?.name??""}),e[97]=m?.name,e[98]=d,e[99]=n,e[100]=qe):qe=e[100];let se;e[101]!==qe?(se=s.jsx(Vt,{children:qe}),e[101]=qe,e[102]=se):se=e[102];let ie;e[103]!==Ve||e[104]!==se?(ie=s.jsxs(_t,{children:[Ve,se]}),e[103]=Ve,e[104]=se,e[105]=ie):ie=e[105];let we;e[106]!==n?(we=n("settings.common.actions.cancel"),e[106]=n,e[107]=we):we=e[107];let ye;e[108]!==c||e[109]!==we?(ye=s.jsx(B,{size:"sm",variant:"ghost",onClick:Y,disabled:c,children:we}),e[108]=c,e[109]=we,e[110]=ye):ye=e[110];let Te;e[111]!==d||e[112]!==n?(Te=n(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=d,e[112]=n,e[113]=Te):Te=e[113];let Ue;e[114]!==ee||e[115]!==c||e[116]!==Te?(Ue=s.jsx(B,{size:"sm",onClick:ee,disabled:c,children:Te}),e[114]=ee,e[115]=c,e[116]=Te,e[117]=Ue):Ue=e[117];let Ie;e[118]!==ye||e[119]!==Ue?(Ie=s.jsxs(ns,{children:[ye,Ue]}),e[118]=ye,e[119]=Ue,e[120]=Ie):Ie=e[120];let je;e[121]!==ie||e[122]!==Ie?(je=s.jsxs(zt,{className:"max-w-md",children:[ie,Ie]}),e[121]=ie,e[122]=Ie,e[123]=je):je=e[123];let Ge;e[124]!==fe||e[125]!==De||e[126]!==je?(Ge=s.jsx(Kt,{open:fe,onOpenChange:De,children:je}),e[124]=fe,e[125]=De,e[126]=je,e[127]=Ge):Ge=e[127];const ue=i!==null;let Ce;e[128]===Symbol.for("react.memo_cache_sentinel")?(Ce=Ke=>!Ke&&r(null),e[128]=Ce):Ce=e[128];let Me;e[129]!==n?(Me=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=Me):Me=e[130];let Ye;e[131]!==Me?(Ye=s.jsx($t,{children:Me}),e[131]=Me,e[132]=Ye):Ye=e[132];const G=i?.name??"";let ke;e[133]!==n||e[134]!==G?(ke=n("settings.commands.sidebar.renameDialog.description",{name:G}),e[133]=n,e[134]=G,e[135]=ke):ke=e[135];let Ae;e[136]!==ke?(Ae=s.jsx(Vt,{children:ke}),e[136]=ke,e[137]=Ae):Ae=e[137];let He;e[138]!==Ye||e[139]!==Ae?(He=s.jsxs(_t,{children:[Ye,Ae]}),e[138]=Ye,e[139]=Ae,e[140]=He):He=e[140];let at;e[141]===Symbol.for("react.memo_cache_sentinel")?(at=Ke=>p(Ke.target.value),e[141]=at):at=e[141];let nt;e[142]!==n?(nt=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=nt):nt=e[143];let dt;e[144]!==me?(dt=Ke=>{Ke.key==="Enter"&&me()},e[144]=me,e[145]=dt):dt=e[145];let xt;e[146]!==l||e[147]!==nt||e[148]!==dt?(xt=s.jsx(Je,{value:l,onChange:at,placeholder:nt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:dt}),e[146]=l,e[147]=nt,e[148]=dt,e[149]=xt):xt=e[149];let H;e[150]===Symbol.for("react.memo_cache_sentinel")?(H=()=>r(null),e[150]=H):H=e[150];let Be;e[151]!==n?(Be=n("settings.common.actions.cancel"),e[151]=n,e[152]=Be):Be=e[152];let tt;e[153]!==Be?(tt=s.jsx(B,{size:"sm",variant:"ghost",onClick:H,children:Be}),e[153]=Be,e[154]=tt):tt=e[154];let rt;e[155]!==n?(rt=n("settings.common.actions.rename"),e[155]=n,e[156]=rt):rt=e[156];let pt;e[157]!==me||e[158]!==rt?(pt=s.jsx(B,{size:"sm",onClick:me,children:rt}),e[157]=me,e[158]=rt,e[159]=pt):pt=e[159];let Ct;e[160]!==tt||e[161]!==pt?(Ct=s.jsxs(ns,{children:[tt,pt]}),e[160]=tt,e[161]=pt,e[162]=Ct):Ct=e[162];let Xe;e[163]!==He||e[164]!==xt||e[165]!==Ct?(Xe=s.jsxs(zt,{children:[He,xt,Ct]}),e[163]=He,e[164]=xt,e[165]=Ct,e[166]=Xe):Xe=e[166];let Ze;e[167]!==ue||e[168]!==Xe?(Ze=s.jsx(Kt,{open:ue,onOpenChange:Ce,children:Xe}),e[167]=ue,e[168]=Xe,e[169]=Ze):Ze=e[169];let ht;return e[170]!==Fe||e[171]!==Le||e[172]!==oe||e[173]!==Ge||e[174]!==Ze?(ht=s.jsxs("div",{className:Fe,children:[Le,oe,Ge,Ze]}),e[170]=Fe,e[171]=Le,e[172]=oe,e[173]=Ge,e[174]=Ze,e[175]=ht):ht=e[175],ht},to=t=>{const e=ut.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:p,onDuplicate:m,isMenuOpen:f,onMenuOpenChange:d}=t,{t:y}=it();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=za(),e[0]=c):c=e[0];const N=c,[b,C]=o.useState(!1);let v;e[1]!==r||e[2]!==m||e[3]!==p||e[4]!==l||e[5]!==y?(v=Q=>s.jsxs(s.Fragment,{children:[p&&s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),p()},children:[s.jsx(R,{name:"edit",className:"h-4 w-4 mr-px"}),y("settings.common.actions.rename")]}),s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),m()},children:[s.jsx(R,{name:"file-copy",className:"h-4 w-4 mr-px"}),y("settings.common.actions.duplicate")]}),l&&s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),l()},children:[s.jsx(R,{name:"restart",className:"h-4 w-4 mr-px"}),y("settings.common.actions.reset")]}),r&&s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),y("settings.common.actions.delete")]})]}),e[1]=r,e[2]=m,e[3]=p,e[4]=l,e[5]=y,e[6]=v):v=e[6];const S=v,g=n?"bg-interactive-selection":"hover:bg-interactive-hover";let E;e[7]!==g?(E=ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",g),e[7]=g,e[8]=E):E=e[8];let M;e[9]===Symbol.for("react.memo_cache_sentinel")?(M=N?void 0:Q=>{Q.preventDefault(),C(!0)},e[9]=M):M=e[9];let A;e[10]!==E?(A=s.jsx("div",{className:E,onContextMenu:M}),e[10]=E,e[11]=A):A=e[11];let w;e[12]!==a.name?(w=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=w):w=e[13];let h;e[14]!==a||e[15]!==y?(h=(a.scope||ca(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:ca(a)?y("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=y,e[16]=h):h=e[16];let j;e[17]!==w||e[18]!==h?(j=s.jsxs("div",{className:"flex items-center gap-2",children:[w,h]}),e[17]=w,e[18]=h,e[19]=j):j=e[19];let L;e[20]!==a.description?(L=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=L):L=e[21];let T;e[22]!==i||e[23]!==L||e[24]!==j?(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-primary/50",tabIndex:0,children:[j,L]}),e[22]=i,e[23]=L,e[24]=j,e[25]=T):T=e[25];let P;e[26]!==d?(P=Q=>{Q&&C(!1),d(Q)},e[26]=d,e[27]=P):P=e[27];let I;e[28]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(sn,{asChild:!0,children:s.jsx(B,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=I):I=e[28];let K;e[29]!==S?(K=s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:S(rn)}),e[29]=S,e[30]=K):K=e[30];let W;e[31]!==f||e[32]!==P||e[33]!==K?(W=s.jsxs(an,{open:f,onOpenChange:P,children:[I,K]}),e[31]=f,e[32]=P,e[33]=K,e[34]=W):W=e[34];let k;e[35]!==T||e[36]!==W?(k=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[T,W]}),e[35]=T,e[36]=W,e[37]=k):k=e[37];let F;e[38]!==k||e[39]!==A?(F=s.jsx(Wn,{render:A,children:k}),e[38]=k,e[39]=A,e[40]=F):F=e[40];let q;e[41]!==S?(q=s.jsx(Gn,{className:"w-fit min-w-20",children:S(qn)}),e[41]=S,e[42]=q):q=e[42];let U;return e[43]!==b||e[44]!==F||e[45]!==q?(U=s.jsxs(Jn,{open:b,onOpenChange:C,children:[F,q]}),e[43]=b,e[44]=F,e[45]=q,e[46]=U):U=e[46],U};function yp(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 wp(t){return t.name}function kp(t){return!ca(t)}function Np(t,e){return t.name.localeCompare(e.name)}function Sp(t,e){return t.name.localeCompare(e.name)}const Cp=()=>{const{t}=it(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:r,setCommandDraft:l}=pa(Ls(I=>({selectedCommandName:I.selectedCommandName,getCommandByName:I.getCommandByName,createCommand:I.createCommand,updateCommand:I.updateCommand,commandDraft:I.commandDraft,setCommandDraft:I.setCommandDraft}))),p=Us(),m=pa(I=>rl(I,p)),f=e?a(e,p):null,d=!!(r&&r.name===e&&!f),[y,c]=o.useState(""),[N,b]=o.useState("user"),[C,v]=o.useState(""),[S,g]=o.useState(""),[E,M]=o.useState(""),[A,w]=o.useState(""),[h,j]=o.useState(!1),L=o.useRef(null);o.useEffect(()=>{if(d&&r){const I=r.name||"",K=r.scope||"user",W=r.description||"",k=r.agent||"",F=r.model||"",q=r.template||"";c(I),b(K),v(W),g(k),M(F),w(q),L.current={draftName:I,draftScope:K,description:W,agent:k,model:F,template:q}}else if(f){const I=f.description||"",K=f.agent||"",W=f.model||"",k=f.template||"";v(I),g(K),M(W),w(k),L.current={draftName:"",draftScope:"user",description:I,agent:K,model:W,template:k}}},[f,d,e,m,r]);const T=o.useMemo(()=>{const I=L.current;return I?!!(d&&(y!==I.draftName||N!==I.draftScope)||C!==I.description||S!==I.agent||E!==I.model||A!==I.template):!1},[S,C,y,N,d,E,A]),P=async()=>{const I=d?y.trim().replace(/\s+/g,"-"):e?.trim();if(!I){D.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!A.trim()){D.error(t("settings.commands.page.toast.templateRequired"));return}if(d&&m.some(K=>K.name===I)){D.error(t("settings.commands.sidebar.toast.commandExists"));return}j(!0);try{const K=S.trim(),W=E.trim(),k=A.trim(),F={name:I,description:C.trim()||void 0,agent:K===""?null:K,model:W===""?null:W,template:k,scope:d?N:void 0};let q;if(d?(q=await n(F,p),q&&l(null)):q=await i(I,F,p),q){const U=$n.getState().changes.some(Q=>Q.scope==="commands"&&Q.id.startsWith(`commands:${I}:`));D.success(t(U?"settings.view.pendingRestart.saved":d?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else D.error(t(d?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(K){console.error("Error saving command:",K),D.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{j(!1)}};return e?s.jsxs(ss,{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(Ot,{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(Je,{value:y,onChange:I=>c(I.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Pt,{value:N,onValueChange:I=>b(I),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{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(Is,{value:C,onChange:I=>v(I.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(Ot,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(ol,{agentName:S,onChange:I=>g(I),className:In})}),s.jsx(Ot,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Oa,{providerId:da(E)?.providerId??"",modelId:da(E)?.modelId??"",onChange:(I,K)=>{M(I&&K?`${I}/${K}`:"")},className:In})})]}),s.jsxs(_e,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Is,{value:A,onChange:I=>w(I.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(B,{onClick:P,disabled:h||!T,size:"xs",className:"!font-normal",children:t(h?"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(R,{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")})]})})},so=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},no=t=>{const e=ut.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=ve("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},Pp=t=>{const e=ut.c(124),{onItemSelect:a}=t,{t:n}=it(),{selectedMcpName:i,setSelectedMcp:r,setMcpDraft:l,loadMcpConfigs:p,deleteMcp:m}=ma(Ls(Ip)),f=Us();let d;e[0]!==f?(d=G=>ll(G,f),e[0]=f,e[1]=d):d=e[1];const y=ma(d);let c;e[2]!==f?(c=G=>G.getStatusForDirectory(f),e[2]=f,e[3]=c):c=e[3];const N=Rs(c),b=Rs(Ap),C=Rs(Tp),[v,S]=o.useState(null),[g,E]=o.useState(!1),[M,A]=o.useState(null),[w,h]=o.useState(null),[j,L]=o.useState(!1);let T;e[4]!==y?(T=y.filter(Ep),e[4]=y,e[5]=T):T=e[5];const P=T;let I;e[6]!==y?(I=y.filter(Dp),e[6]=y,e[7]=I):I=e[7];const K=I;let W,k;e[8]!==p||e[9]!==f?(W=()=>{p({directory:f})},k=[p,f],e[8]=p,e[9]=f,e[10]=W,e[11]=k):(W=e[10],k=e[11]),o.useEffect(W,k);let F;e[12]!==C||e[13]!==j||e[14]!==b||e[15]!==f?(F=()=>{if(j)return;L(!0);const G=new Promise(Mp);Promise.all([b({directory:f,silent:!0}),G]).then(()=>{const ke=C(f);ke&&D.error(ke)}).finally(()=>{L(!1)})},e[12]=C,e[13]=j,e[14]=b,e[15]=f,e[16]=F):F=e[16];const q=F;let U;e[17]!==y||e[18]!==a||e[19]!==l||e[20]!==r?(U=()=>{let G="new-mcp-server",ke=1;for(;y.some(He=>He.name===G);)G=`new-mcp-server-${ke}`,ke++;l({name:G,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),r(G),a?.()},e[17]=y,e[18]=a,e[19]=l,e[20]=r,e[21]=U):U=e[21];const Q=U;let ne;e[22]!==m||e[23]!==v||e[24]!==f||e[25]!==n?(ne=async()=>{if(!v)return;E(!0);const G=await m(v.name,f);G.ok?G.reloadFailed?D.warning(G.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:G.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):D.success(G.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:v.name})):D.error(n("settings.mcp.sidebar.toast.deleteFailed")),S(null),E(!1)},e[22]=m,e[23]=v,e[24]=f,e[25]=n,e[26]=ne):ne=e[26];const _=ne;let re;e[27]!==n?(re=(G,ke)=>s.jsxs(ke,{onClick:Ae=>{Ae.stopPropagation(),S(G)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=re):re=e[28];const V=re;let $;e[29]===Symbol.for("react.memo_cache_sentinel")?($=ve("flex h-full flex-col","bg-background"),e[29]=$):$=e[29];let z;e[30]!==n?(z=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=z):z=e[31];let O;e[32]!==z?(O=s.jsx("h2",{className:on,children:z}),e[32]=z,e[33]=O):O=e[33];let Y;e[34]!==n?(Y=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=Y):Y=e[35];let Z;e[36]!==n?(Z=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=Z):Z=e[37];const ee=j&&"animate-spin";let ge;e[38]!==ee?(ge=ve("h-4 w-4",ee),e[38]=ee,e[39]=ge):ge=e[39];let de;e[40]!==ge?(de=s.jsx(R,{name:"refresh",className:ge}),e[40]=ge,e[41]=de):de=e[41];let xe;e[42]!==q||e[43]!==j||e[44]!==Y||e[45]!==Z||e[46]!==de?(xe=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:j,onClick:q,"aria-label":Y,title:Z,children:de}),e[42]=q,e[43]=j,e[44]=Y,e[45]=Z,e[46]=de,e[47]=xe):xe=e[47];let ae;e[48]!==O||e[49]!==xe?(ae=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[O,xe]}),e[48]=O,e[49]=xe,e[50]=ae):ae=e[50];let te;e[51]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(Va,{className:"mb-3"}),e[51]=te):te=e[51];let me;e[52]!==y.length||e[53]!==n?(me=n("settings.mcp.sidebar.total",{count:y.length}),e[52]=y.length,e[53]=n,e[54]=me):me=e[54];let Pe;e[55]!==me?(Pe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:me}),e[55]=me,e[56]=Pe):Pe=e[56];let Ne;e[57]!==n?(Ne=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=Ne):Ne=e[58];let Se;e[59]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[59]=Se):Se=e[59];let be;e[60]!==Q||e[61]!==Ne?(be=s.jsx(B,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,title:Ne,children:Se}),e[60]=Q,e[61]=Ne,e[62]=be):be=e[62];let Fe;e[63]!==Pe||e[64]!==be?(Fe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Pe,be]}),e[63]=Pe,e[64]=be,e[65]=Fe):Fe=e[65];let Le;e[66]!==ae||e[67]!==Fe?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ae,te,Fe]}),e[66]=ae,e[67]=Fe,e[68]=Le):Le=e[68];let oe;e[69]!==y.length||e[70]!==N||e[71]!==a||e[72]!==M||e[73]!==P||e[74]!==V||e[75]!==w||e[76]!==i||e[77]!==l||e[78]!==r||e[79]!==n||e[80]!==K?(oe=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:y.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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(G=>{const ke=N[G.name],Ae=so(ke?.status),He=i===G.name,at=za();return s.jsxs(Jn,{open:w===G.name,onOpenChange:nt=>h(nt?G.name:null),children:[s.jsxs(Wn,{render:s.jsx("div",{className:ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",He?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:at?void 0:nt=>{nt.preventDefault(),h(G.name)}}),children:[s.jsxs("button",{onClick:()=>{r(G.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-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(no,{tone:Ae,enabled:G.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:G.name}),s.jsx("span",{title:G.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:G.type==="local"?s.jsx(R,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(R,{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:G.type==="local"?G.command?.join(" ")??"":G.url??""})]}),s.jsxs(an,{open:M===G.name,onOpenChange:nt=>{nt&&h(null),A(nt?G.name:null)},children:[s.jsx(sn,{asChild:!0,children:s.jsx(B,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:V(G,rn)})]})]}),s.jsx(Gn,{className:"w-fit min-w-20",children:V(G,qn)})]},G.name)})]}),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.mcp.sidebar.group.userServers")}),K.map(G=>{const ke=N[G.name],Ae=so(ke?.status),He=i===G.name,at=za();return s.jsxs(Jn,{open:w===G.name,onOpenChange:nt=>h(nt?G.name:null),children:[s.jsxs(Wn,{render:s.jsx("div",{className:ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",He?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:at?void 0:nt=>{nt.preventDefault(),h(G.name)}}),children:[s.jsxs("button",{onClick:()=>{r(G.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-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(no,{tone:Ae,enabled:G.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:G.name}),s.jsx("span",{title:G.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:G.type==="local"?s.jsx(R,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(R,{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:G.type==="local"?G.command?.join(" ")??"":G.url??""})]}),s.jsxs(an,{open:M===G.name,onOpenChange:nt=>{nt&&h(null),A(nt?G.name:null)},children:[s.jsx(sn,{asChild:!0,children:s.jsx(B,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:V(G,rn)})]})]}),s.jsx(Gn,{className:"w-fit min-w-20",children:V(G,qn)})]},G.name)})]})]})}),e[69]=y.length,e[70]=N,e[71]=a,e[72]=M,e[73]=P,e[74]=V,e[75]=w,e[76]=i,e[77]=l,e[78]=r,e[79]=n,e[80]=K,e[81]=oe):oe=e[81];const fe=v!==null;let De;e[82]!==g?(De=G=>{!G&&!g&&S(null)},e[82]=g,e[83]=De):De=e[83];let $e;e[84]!==n?($e=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=$e):$e=e[85];let Ve;e[86]!==$e?(Ve=s.jsx($t,{children:$e}),e[86]=$e,e[87]=Ve):Ve=e[87];const qe=v?.name||"";let se;e[88]!==n||e[89]!==qe?(se=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:qe}),e[88]=n,e[89]=qe,e[90]=se):se=e[90];let ie;e[91]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=ie):ie=e[91];let we;e[92]!==se?(we=s.jsxs(Vt,{children:[se," ",ie,"."]}),e[92]=se,e[93]=we):we=e[93];let ye;e[94]!==Ve||e[95]!==we?(ye=s.jsxs(_t,{children:[Ve,we]}),e[94]=Ve,e[95]=we,e[96]=ye):ye=e[96];let Te;e[97]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>S(null),e[97]=Te):Te=e[97];let Ue;e[98]!==n?(Ue=n("settings.common.actions.cancel"),e[98]=n,e[99]=Ue):Ue=e[99];let Ie;e[100]!==g||e[101]!==Ue?(Ie=s.jsx(B,{size:"sm",variant:"ghost",onClick:Te,disabled:g,children:Ue}),e[100]=g,e[101]=Ue,e[102]=Ie):Ie=e[102];let je;e[103]!==g||e[104]!==n?(je=n(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=g,e[104]=n,e[105]=je):je=e[105];let Ge;e[106]!==_||e[107]!==g||e[108]!==je?(Ge=s.jsx(B,{size:"sm",onClick:_,disabled:g,children:je}),e[106]=_,e[107]=g,e[108]=je,e[109]=Ge):Ge=e[109];let ue;e[110]!==Ie||e[111]!==Ge?(ue=s.jsxs(ns,{children:[Ie,Ge]}),e[110]=Ie,e[111]=Ge,e[112]=ue):ue=e[112];let Ce;e[113]!==ye||e[114]!==ue?(Ce=s.jsxs(zt,{className:"max-w-md",children:[ye,ue]}),e[113]=ye,e[114]=ue,e[115]=Ce):Ce=e[115];let Me;e[116]!==fe||e[117]!==De||e[118]!==Ce?(Me=s.jsx(Kt,{open:fe,onOpenChange:De,children:Ce}),e[116]=fe,e[117]=De,e[118]=Ce,e[119]=Me):Me=e[119];let Ye;return e[120]!==Le||e[121]!==oe||e[122]!==Me?(Ye=s.jsxs("div",{className:$,children:[Le,oe,Me]}),e[120]=Le,e[121]=oe,e[122]=Me,e[123]=Ye):Ye=e[123],Ye};function Ip(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Ap(t){return t.refresh}function Tp(t){return t.getErrorForDirectory}function Ep(t){return t.scope==="project"}function Dp(t){return t.scope!=="project"}function Mp(t){return setTimeout(t,500)}function Xs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Sa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Zs(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Ya(t,e,a){const n=Rp(a),i=typeof a.url=="string"?a.url.trim():"",r=ao(a,"env","environment"),l=ao(a,"headers"),p=Op(a),m=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():"",y=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",c=Lp(a),N=Fp(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:p,oauthClientId:m,oauthClientSecret:f,oauthScope:d,oauthRedirectUri:y,timeout:c,enabled:N}}function Rp(t){const e=t.command,a=t.args;if(Sa(e)&&Sa(a))return[...e,...a];if(Sa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Sa(a)?[...n,...a]:n}return Sa(a)?a:[]}function ao(t,...e){for(const a of e){const n=t[a];if(!Xs(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 Op(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!Xs(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 Lp(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 Fp(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function Kp(t){const e=t.mcpServers;if(Xs(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(Xs(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"&&Xs(i)});if(a.length===1){const n=a[0],i=t[n];if(Tl(i))return{name:n,entry:i}}return null}function Tl(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function zp(t,e){let a;try{const p=t.trim();if(!p)return Zs("No JSON content provided");a=JSON.parse(p)}catch(p){return Zs(p instanceof Error?`Invalid JSON: ${p.message}`:"Invalid JSON")}if(!Xs(a))return Zs("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(Xs(i)){const p=Object.keys(i);if(p.length===0)return Zs("mcpServers object is empty",a);if(p.length>1)return Zs("Paste one server at a time. Found "+p.length+" servers in mcpServers",a);const m=p[0],f=i[m];return Xs(f)?Ya(m,Za(f),f):Zs("Server entry is not a valid object",a)}const r=n.mcp;if(Xs(r)){const p=Object.keys(r);if(p.length===0)return Zs("mcp object is empty",a);if(p.length>1)return Zs("Paste one server at a time. Found "+p.length+" servers in mcp",a);const m=p[0],f=r[m];return Xs(f)?Ya(m,Za(f),f):Zs("Server entry in mcp is not a valid object",a)}const l=Kp(n);if(l)return Ya(l.name,Za(l.entry),l.entry);if(Tl(n)){const p=Za(n),m=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Ya(m,p,n)}return Zs("No recognizable MCP server configuration found in JSON",a)}function Za(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 Up(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 El(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 _p(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:pc(a.searchParams),stateKey:cl(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const $p=t=>{const e=ut.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[p,m]=o.useState(l),f=o.useRef(a);let d,y;e[2]!==a?(d=()=>{JSON.stringify(f.current)!==JSON.stringify(a)&&(f.current=a,m(a.join(`
5
- `)))},y=[a],e[2]=a,e[3]=d,e[4]=y):(d=e[3],y=e[4]),o.useEffect(d,y);let c;e[5]!==n||e[6]!==r?(c=w=>{const h=w.split(`
6
- `).filter(Qp);if(r&&h.length===1&&/^https?:\/\/\S+$/i.test(h[0].trim())){r(h[0].trim());return}n(h)},e[5]=n,e[6]=r,e[7]=c):c=e[7];const N=c;let b;e[8]!==n?(b=w=>{const j=w.clipboardData.getData("text").trim();if(!j||j.includes(`
7
- `)||!/\s/.test(j))return;const L=w.currentTarget;if(L.selectionStart!==0||L.selectionEnd!==L.value.length)return;w.preventDefault();const T=El(j);m(T.join(`
8
- `)),n(T)},e[8]=n,e[9]=b):b=e[9];const C=b;let v;e[10]!==N?(v=w=>{m(w.target.value),N(w.target.value)},e[10]=N,e[11]=v):v=e[11];let S;e[12]!==N||e[13]!==p?(S=()=>{const w=p.split(`
9
- `).map(Yp).join(`
10
- `);m(w),N(w)},e[12]=N,e[13]=p,e[14]=S):S=e[14];const g=Math.max(4,a.length+1);let E;e[15]!==C||e[16]!==v||e[17]!==S||e[18]!==g||e[19]!==p?(E=s.jsx(Is,{onPaste:C,value:p,onChange:v,onBlur:S,placeholder:`npx
11
- -y
12
- @modelcontextprotocol/server-postgres
13
- postgresql://user:pass@host/db`,rows:g,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=C,e[16]=v,e[17]=S,e[18]=g,e[19]=p,e[20]=E):E=e[20];let M;e[21]!==i||e[22]!==a?(M=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(Zp)})})]}),e[21]=i,e[22]=a,e[23]=M):M=e[23];let A;return e[24]!==M||e[25]!==E?(A=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[E,M]}),e[24]=M,e[25]=E,e[26]=A):A=e[26],A},Vp=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),io=({value:t,onChange:e,keyTransform:a=Vp,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:p,importSuccess:m,clipboardReadFailed:f,keyLabel:d,valueLabel:y,valuePlaceholder:c,hideValueTitle:N,showValueTitle:b,addVariable:C,plainTextWarning:v,removeVariableAria:S})=>{const[g,E]=o.useState(new Set),M=()=>e([...t,{key:"",value:""}]),A=T=>{e(t.filter((P,I)=>I!==T)),E(P=>{const I=new Set(P);return I.delete(T),I})},w=(T,P,I)=>{const K=[...t];K[T]={...K[T],[P]:I},e(K)},h=T=>{E(P=>{const I=new Set(P);return I.has(T)?I.delete(T):I.add(T),I})},j=async()=>{try{const T=await navigator.clipboard.readText(),P=[];for(const K of T.split(`
14
- `)){const W=K.trim();if(!W||W.startsWith("#"))continue;const k=W.indexOf("=");if(k===-1)continue;const F=W.slice(0,k).trim();let q=W.slice(k+1).trim();(q.startsWith('"')&&q.endsWith('"')||q.startsWith("'")&&q.endsWith("'"))&&(q=q.slice(1,-1)),F&&P.push({key:F,value:q})}if(P.length===0){D.error(p);return}const I=[...t];for(const K of P){const W=I.findIndex(k=>k.key===K.key);W!==-1?I[W]=K:I.push(K)}e(I),D.success(m(P.length))}catch{D.error(f)}},L=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:y})]}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:j,type:"button",title:l,children:[s.jsx(R,{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(Je,{value:T.key,onChange:I=>w(P,"key",a(I.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(Je,{type:g.has(P)?"text":"password",value:T.value,onChange:I=>w(P,"value",I.target.value),placeholder:c,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:()=>h(P),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:g.has(P)?N:b,children:g.has(P)?s.jsx(R,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(B,{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":S,children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},P))}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:M,type:"button",children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),C]}),L&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:v})]})},zi=t=>{const e=ut.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let p,m;if(e[0]!==i||e[1]!==a||e[2]!==l){m=Symbol.for("react.early_return_sentinel");e:{const c={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 N=ve("typography-micro font-medium rounded-full px-2 py-0.5",c.text,c.bg);let b;e[5]!==i||e[6]!==a?(b=i(a),e[5]=i,e[6]=a,e[7]=b):b=e[7],m=s.jsxs("span",{className:N,children:["● ",b]});break e}p=ve("typography-micro font-medium",c.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=p,e[4]=m}else p=e[3],m=e[4];if(m!==Symbol.for("react.early_return_sentinel"))return m;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]!==p||e[12]!==f?(d=s.jsxs("span",{className:p,children:["● ",f]}),e[11]=p,e[12]=f,e[13]=d):d=e[13],d},Bp=(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")}},Hp=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)]"}},Gp=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),qp=async t=>{const e=await mt(`/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},Ca=async t=>{typeof t!="string"||!t.trim()||await mt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Xa=(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},Wp=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},Jp=()=>{const{t}=it(),e=o.useCallback((le,ft)=>t(le,ft),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:r,getMcpByName:l,createMcp:p,updateMcp:m,deleteMcp:f}=ma(Ls(le=>({selectedMcpName:le.selectedMcpName,mcpDraft:le.mcpDraft,setMcpDraft:le.setMcpDraft,setSelectedMcp:le.setSelectedMcp,getMcpByName:le.getMcpByName,createMcp:le.createMcp,updateMcp:le.updateMcp,deleteMcp:le.deleteMcp}))),d=Us(),y=o.useMemo(()=>ds(),[]),c=Rs(le=>le.getStatusForDirectory(d)),N=Rs(le=>le.getDiagnosticForDirectory(d)),b=Rs(le=>le.refresh),C=Rs(le=>le.connect),v=Rs(le=>le.disconnect),S=Rs(le=>le.completeAuth),g=Rs(le=>le.clearAuth),E=Rs(le=>le.testConnection),M=$n(le=>le.changes),A=ma(le=>ll(le,d)),w=a?l(a,d):null,h=!!(n&&n.name===a&&!w),[j,L]=o.useState(""),[T,P]=o.useState("user"),[I,K]=o.useState("local"),[W,k]=o.useState([]),[F,q]=o.useState(""),[U,Q]=o.useState([]),[ne,_]=o.useState([]),[re,V]=o.useState(!0),[$,z]=o.useState(""),[O,Y]=o.useState(""),[Z,ee]=o.useState(""),[ge,de]=o.useState(""),[xe,ae]=o.useState(""),[te,me]=o.useState(!0),[Pe,Ne]=o.useState(!1),[Se,be]=o.useState(!1),[Fe,Le]=o.useState(!1),[oe,fe]=o.useState(!1),[De,$e]=o.useState(!1),[Ve,qe]=o.useState(!1),[se,ie]=o.useState(!1),[we,ye]=o.useState(!1),[Te,Ue]=o.useState(null),[Ie,je]=o.useState(null),[Ge,ue]=o.useState(""),[Ce,Me]=o.useState(!1),Ye=o.useRef(0),G=o.useRef(!1),[ke,Ae]=o.useState(!1),[He,at]=o.useState(!1),[nt,dt]=o.useState(""),[xt,H]=o.useState(null),Be=o.useMemo(()=>Wp(a,d),[d,a]),tt=o.useRef(Be),rt=o.useRef(null),pt=o.useCallback(()=>{Ue(null),je(null),ue(""),Me(!1),Ye.current=0,ye(!1),$e(!1),qe(!1),G.current=!1},[]),Ct=o.useCallback(()=>{dt(""),H(null),at(!0)},[]),Xe=o.useCallback(async()=>{try{const le=await navigator.clipboard.readText();dt(le),H(null)}catch{D.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Ze=o.useCallback(()=>{const le=zp(nt,{fallbackName:j});if(!le.ok){H(le.error);return}const yt=Up(le,{name:j,scope:T,type:I,command:W,url:F,environment:U,headers:ne,oauthEnabled:re,oauthClientId:$,oauthClientSecret:O,oauthScope:Z,oauthRedirectUri:ge,timeout:xe,enabled:te},{isNewServer:h});L(yt.name),K(yt.type),k(yt.command??[]),q(yt.url??""),Q(yt.environment??[]),_(yt.headers??[]),V(yt.oauthEnabled??!1),z(yt.oauthClientId??""),Y(yt.oauthClientSecret??""),ee(yt.oauthScope??""),de(yt.oauthRedirectUri??""),ae(yt.timeout??""),me(yt.enabled??!0),at(!1),dt(""),H(null),D.success(t("settings.mcp.page.toast.configImported"))},[nt,j,T,I,W,F,U,ne,re,$,O,Z,ge,xe,te,h,t]);o.useEffect(()=>{if(h&&n){L(n.name),P(n.scope||"user"),K(n.type),k(n.command),q(n.url),Q(n.environment),_(n.headers),V(n.oauthEnabled),z(n.oauthClientId),Y(n.oauthClientSecret),ee(n.oauthScope),de(n.oauthRedirectUri),ae(n.timeout),me(n.enabled),Ae(!1),rt.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(w){P(w.scope==="project"?"project":"user");const le=Cr(w.environment),ft=w.type==="remote"?w:null,yt=Cr(ft?.headers),Qt=ft?.oauth,Yt=Qt&&typeof Qt=="object"?Qt:null,Ht=Qt!==!1,as=w.type,js=as==="local"?w.command??[]:[],ls=as==="remote"?w.url??"":"",St=typeof ft?.timeout=="number"&&Number.isFinite(ft.timeout)?String(ft.timeout):"";K(as),k(js),q(ls),Q(le),_(yt),V(Ht),z(Ht?Yt?.clientId??"":""),Y(Ht?Yt?.clientSecret??"":""),ee(Ht?Yt?.scope??"":""),de(Ht?Yt?.redirectUri??"":""),ae(St),me(w.enabled),Ae(!1),rt.current={mcpType:as,command:js,url:ls,envEntries:le,headerEntries:yt,oauthEnabled:Ht,oauthClientId:Ht?Yt?.clientId??"":"",oauthClientSecret:Ht?Yt?.clientSecret??"":"",oauthScope:Ht?Yt?.scope??"":"",oauthRedirectUri:Ht?Yt?.redirectUri??"":"",timeout:St,enabled:w.enabled}}},[w,h,n]);const ht=o.useMemo(()=>{const le=rt.current;return le?I!==le.mcpType||te!==le.enabled||JSON.stringify(W)!==JSON.stringify(le.command)||F!==le.url||JSON.stringify(U)!==JSON.stringify(le.envEntries)||JSON.stringify(ne)!==JSON.stringify(le.headerEntries)||re!==le.oauthEnabled||$!==le.oauthClientId||O!==le.oauthClientSecret||Z!==le.oauthScope||ge!==le.oauthRedirectUri||xe!==le.timeout:!1},[I,W,F,U,ne,re,$,O,Z,ge,xe,te]),Ke=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(R,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(R,{name:"global",className:"h-3.5 w-3.5"})}],[t]),wt=o.useCallback(le=>{K("remote"),q(le),k([])},[]),Ee=o.useCallback(le=>{q(le);const ft=le.trim();ft&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ft)&&/\s/.test(ft)&&(K("local"),k(El(ft)),q(""))},[]),jt=async()=>{const le=h?j.trim():a??"";if(!le){D.error(t("settings.mcp.page.toast.nameRequired"));return}if(h&&A.some(yt=>yt.name===le)){D.error(t("settings.mcp.page.toast.serverNameExists"));return}if(I==="local"&&W.filter(Boolean).length===0){D.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(I==="remote"&&!F.trim()){D.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ft={name:le,scope:T,type:I,command:W,url:F,environment:U,headers:ne,oauthEnabled:re,oauthClientId:$,oauthClientSecret:O,oauthScope:Z,oauthRedirectUri:ge,timeout:xe,enabled:te};Ne(!0);try{const yt=h?await p(ft,d):await m(le,ft,d);yt.ok?(await Ca(Ie),pt(),h&&(i(null),r(le)),await b({directory:d,silent:!0}),yt.reloadFailed?D.warning(yt.message||t(h?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:yt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):yt.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(yt.message||t(h?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):D.error(t("settings.mcp.page.toast.saveFailed"))}catch(yt){D.error(yt instanceof Error?yt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Ne(!1)}},J=async()=>{if(!a)return;Le(!0);const le=await f(a,d);le.ok?(await Ca(Ie),pt(),le.reloadFailed?D.warning(le.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:le.warning||t("settings.mcp.page.toast.refreshListIfStale")}):D.success(le.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),be(!1)):D.error(t("settings.mcp.page.toast.deleteFailed")),Le(!1)},he=async()=>{if(a){fe(!0);try{if(c[a]?.status==="connected")await v(a,d),D.success(t("settings.mcp.page.toast.disconnected"));else{await C(a,d),await b({directory:d,silent:!0});const ft=Rs.getState().getStatusForDirectory(d)[a];ft?.status==="connected"?D.success(t("settings.mcp.page.toast.connected")):ft?.status==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ft?.status==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ft?.status==="failed"?D.error(ft.error||t("settings.mcp.page.toast.connectionFailed")):D.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await b({directory:d,silent:!0})}catch(le){D.error(le instanceof Error?le.message:t("settings.mcp.page.toast.connectionFailed"))}finally{fe(!1)}}},ze=o.useCallback(()=>h?(D.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):ht?(D.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[ht,h,t]),Re=o.useCallback(async(le=!1)=>{try{await b({directory:d,silent:le})}catch(ft){le||D.error(ft instanceof Error?ft.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[d,b,t]);o.useEffect(()=>{Re(!0)},[Re]),o.useEffect(()=>{tt.current=Be,fe(!1),ie(!1),pt()},[pt,Be]);const ct=o.useCallback(async()=>{if(!a||I!=="remote"||!ze())return;$e(!0);const le=Be;let ft=null;try{const yt=Rs.getState().getStatusForDirectory(d)[a]?.status;G.current=yt==="needs_auth"||yt==="needs_client_registration";const{authorizationUrl:Qt,opened:Yt,nativeFlow:Ht,completion:as}=await cc({name:a,directory:d});if(Ht){if(tt.current!==le)return;Ue(null),je(null),Me(!0),Ye.current=0,D.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),as?.then(()=>{tt.current===le&&(Me(!1),Ye.current=0,G.current=!1,D.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(ls=>{tt.current===le&&(Me(!1),Ye.current=0,G.current=!1,D.error(Xa(ls,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const js=cl(new URL(Qt).searchParams);if(ft=js,tt.current!==le||(Ue(Qt),je(js??null),Me(!0),Ye.current=0,tt.current!==le))return;Yt?D.message(t(y?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):D.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(yt){await Ca(ft),tt.current===le&&D.error(Xa(yt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{tt.current===le&&$e(!1)}},[d,y,I,ze,Be,a,t,e]),lt=o.useCallback(async()=>{if(!a||!ze())return;qe(!0);const le=Be;try{if(await g(a,d),tt.current!==le)return;Ue(null),je(null),ue(""),Me(!1),Ye.current=0,await Ca(Ie),D.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(ft){tt.current===le&&D.error(Xa(ft,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{tt.current===le&&qe(!1)}},[Ie,g,d,ze,Be,a,t,e]),Qe=o.useCallback(async()=>{if(!Te)return;if((await La(Te)).ok){D.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}D.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Te,t]),Nt=o.useCallback(async()=>{const le=_p(Ge);if(!le.code){D.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ft=le.stateKey?await qp(le.stateKey):null,yt=le.context??ft,Qt=yt?.name??a,Yt=yt?.directory??d;if(!Qt){D.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!yt&&!ze())return;ye(!0);const Ht=Be;try{if(await S(Qt,le.code,Yt),await Ca(le.stateKey??Ie),tt.current!==Ht)return;ue(""),Ue(null),je(null),Me(!1),Ye.current=0,D.success(Qt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Qt}))}catch(as){tt.current===Ht&&D.error(Xa(as,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{tt.current===Ht&&ye(!1)}},[Ge,Ie,S,d,ze,Be,a,t,e]),xs=o.useCallback(async()=>{if(!(!a||!ze())){if(!te){D.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ie(!0);try{const le=await E(a,d),ft=le.status?.status;le.warning?D.warning(le.warning):ft==="connected"?D.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ft==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ft==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ft==="failed"?D.error(le.status?.error||le.error||t("settings.mcp.page.toast.connectionTestFailed")):le.error?D.error(le.error):D.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(le){D.error(le instanceof Error?le.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{ie(!1)}}},[d,te,ze,a,t,E]);if(o.useEffect(()=>{if(!Ce||!a)return;const le=window.setInterval(()=>{(async()=>{Ye.current+=1,await b({directory:d,silent:!0});const ft=Rs.getState().getStatusForDirectory(d)[a];if(ft){if(G.current&&ft.status!=="needs_auth"&&ft.status!=="needs_client_registration"){Me(!1),Ye.current=0,G.current=!1,Ue(null),ue(""),ft.status==="connected"&&D.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!G.current&&ft.status==="failed"){Me(!1),Ye.current=0,G.current=!1,D.error(ft.error||t("settings.mcp.page.toast.authorizationFailed"));return}Ye.current>=30&&(Me(!1),Ye.current=0,G.current=!1,D.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(le)}},[d,Ce,b,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(R,{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 es=c[a],Ds=a?N[a]:void 0,Bt=es??Ds,os=!h&&!Bt&&M.some(le=>le.scope==="mcp"&&le.id.startsWith(`mcp:${a}:`)),qt=es?.status==="connected",bs=es?.status==="needs_auth"||es?.status==="needs_client_registration",ps=y||!a?null:dc(a),vs=async()=>{if(ps)try{await navigator.clipboard.writeText(ps),D.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{D.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},ms=Bp(Bt?.status,e,Bt&&"error"in Bt?Bt.error:void 0),ys=le=>{switch(le){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 le}};return s.jsxs(s.Fragment,{children:[s.jsxs(ss,{title:h?t("settings.mcp.page.header.newServer"):a,titleAccessory:h?void 0:s.jsx(zi,{status:os?"awaiting_restart":Bt?.status,enabled:te,getStatusLabel:ys,variant:"pill"}),description:h?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(I==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!h&&!os?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{variant:qt?"outline":"default",size:"xs",className:"!font-normal",onClick:he,disabled:oe||!te,children:t(oe?"settings.mcp.page.actions.working":qt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),I==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(B,{variant:bs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{ct()},disabled:De||!te,children:t(De?"settings.mcp.page.actions.starting":qt?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{lt()},disabled:Ve||!te,children:t(Ve?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),qt&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{xs()},disabled:se||!te,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[os&&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:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(zi,{status:"awaiting_restart",enabled:te,getStatusLabel:ys})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!h&&!os&&Gp(Bt?.status,Te,bs,Ce)&&s.jsx(_e,{divider:!1,children:s.jsxs("div",{className:ve("rounded-lg border p-3",Hp(Bt?.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:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(zi,{status:Bt?.status,enabled:te,getStatusLabel:ys})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ms}),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:!qt&&s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{xs()},disabled:se||!te,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Bt?.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(Js,{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")})]}),ps&&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:ps}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{vs()},children:[s.jsx(R,{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(Wt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(Je,{value:$,onChange:le=>{z(le.target.value),V(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(Wt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(Je,{type:"password",value:O,onChange:le=>{Y(le.target.value),V(!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")})]}),Te&&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:Te}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{An(Te)},children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Qe()},children:[s.jsx(R,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),y&&I==="remote"&&(bs||Ce||Te)&&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(Js,{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(Is,{value:Ge,onChange:le=>ue(le.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(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nt()},disabled:we,children:t(we?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Ce&&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:h?s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:Ct,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(R,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[h&&s.jsxs(Ot,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(Je,{value:j,onChange:le=>L(le.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(Pt,{value:T,onValueChange:le=>P(le),children:[s.jsxs(It,{size:Lt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(R,{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(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(gt,{checked:te,onChange:me,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(hr,{items:Ke,activeId:I,onSelect:le=>K(le),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),I==="local"?s.jsx($p,{value:W,onChange:k,preview:le=>t("settings.mcp.page.connection.previewArgs",{count:le}),onDetectUrl:wt}):s.jsx(Je,{value:F,onChange:le=>Ee(le.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(I==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),I==="remote"&&s.jsx(_e,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(Tn,{open:ke,onOpenChange:Ae,children:[s.jsxs(En,{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:["(",ne.length," ",t("settings.mcp.page.advanced.headers"),xe?` · ${xe}ms`:"",")"]})]}),ke?s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Dn,{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:Et,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Jt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Je,{type:"number",min:"1",step:"1",value:xe,onChange:le=>ae(le.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(Js,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),ne.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ne.length,")"]})]}),s.jsx(io,{value:ne,onChange:_,keyTransform:le=>le.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:le=>t("settings.mcp.page.toast.importedVariablesCount",{count:le}),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(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Q([{key:"",value:""}]),children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(io,{value:U,onChange:Q,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:le=>t("settings.mcp.page.toast.importedVariablesCount",{count:le}),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(B,{onClick:jt,disabled:Pe||!ht&&!h,size:"xs",className:"!font-normal",children:t(Pe?"settings.common.actions.saving":h?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!h&&s.jsx(B,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>be(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Kt,{open:He,onOpenChange:le=>{le||(at(!1),dt(""),H(null))},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{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(Is,{value:nt,onChange:le=>{dt(le.target.value),H(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"}),xt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:xt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Xe,type:"button",children:[s.jsx(R,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(ns,{children:[s.jsx(B,{variant:"outline",onClick:()=>{at(!1),dt(""),H(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{onClick:Ze,disabled:!nt.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Kt,{open:Se,onOpenChange:le=>{!le&&!Fe&&be(!1)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{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(ns,{children:[s.jsx(B,{variant:"outline",onClick:()=>be(!1),disabled:Fe,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{variant:"destructive",size:"sm",onClick:J,disabled:Fe,children:t(Fe?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function Qp(t){return t.trim().length>0}function Yp(t){return t.trimEnd()}function Zp(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 ci=()=>{try{const e=Vs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=fn.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},Xp=800,em=5e3,tm="__default__",tr=new Map,Ui=new Map,sm=1500,Dl=t=>t?.trim()||tm,nm=t=>{tr.delete(Dl(t))},us=Sl()(Od(Ld((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=ci(),i=Dl(n),r=Date.now(),l=tr.get(i)??0,p=e().entries.length>0||e().files.length>0;if(!a?.force&&p&&r-l<em)return!0;const m=Ui.get(i);if(!a?.force&&m)return m;const f=(async()=>{t({isLoading:!0});try{const d=await mt(Nn("/api/config/plugins",n),{headers:Pa(n)});if(!d.ok)throw new Error("Failed to load plugins");const y=await di(d);return t({entries:y.entries??[],files:y.files??[],isLoading:!1}),tr.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(d){return console.error("[PluginsStore] Failed to load plugins:",d),t({isLoading:!1}),!1}})();Ui.set(i,f);try{return await f}finally{Ui.delete(i)}},loadRegistryInfo:async a=>{const n=im(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=ci(),r={...e().registryInfo};for(const l of rm(n)){const p=await mt(am(l,a?.force===!0,i),{headers:Pa(i)});if(!p.ok)throw new Error("Failed to load plugin registry info");const m=await di(p);for(const f of m.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 ra("Creating plugin entry…",async i=>await mt(Nn("/api/config/plugins/entry",i),{method:"POST",headers:ei(i),body:JSON.stringify(ro(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(p=>p.id===a)?.spec,r=n.spec??i,l=await ra("Updating plugin entry…",async p=>await mt(Nn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,p),{method:"PATCH",headers:ei(p),body:JSON.stringify(ro(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 ra("Deleting plugin entry…",async r=>await mt(Nn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:Pa(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=ci(),i=await mt(Nn(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:Pa(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await di(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>ra("Creating plugin file…",async n=>await mt(Nn("/api/config/plugins/file",n),{method:"POST",headers:ei(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>ra("Updating plugin file…",async i=>await mt(Nn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:ei(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await ra("Deleting plugin file…",async i=>await mt(Nn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:Pa(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:nd(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function Nn(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function am(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 im(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>sm?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function Pa(t){return t?{"x-opencode-directory":t}:void 0}function ei(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function ro(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 ra(t,e,a,n){try{const i=ci(),r=await e(i),l=await di(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return nm(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):il(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&&(mc(t),await uc({message:l.message,delayMs:l.reloadDelayMs??Xp,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 di(t){return await t.json()}const om=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function lm(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 cm=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=it(),i=us(k=>k.createEntry),r=us(k=>k.createFile),[l,p]=o.useState("npm"),[m,f]=o.useState(""),[d,y]=o.useState(""),[c,N]=o.useState(""),[b,C]=o.useState(""),[v,S]=o.useState(a),[g,E]=o.useState(!1),M=o.useCallback(()=>{f(""),y(""),N(""),C(""),S(a)},[a]);o.useEffect(()=>{t&&(p("npm"),M())},[t,M]);const A=k=>{k!==l&&(p(k),M())},w=o.useMemo(()=>lm(d),[d]),h=!w.ok,j=l==="file"&&c.trim()!==""&&!om.test(c.trim()),L=(l==="npm"||l==="path")&&m.trim()==="",T=l==="file"&&b.trim()==="",P=l==="file"&&c.trim()==="",I=g||h||l==="npm"&&L||l==="path"&&L||l==="file"&&(P||j||T),K=async()=>{if(!I){E(!0);try{let k;l==="file"?k=await r({fileName:c.trim(),content:b,scope:v}):k=await i({spec:m.trim(),options:w.ok?w.value:void 0,scope:v}),k.ok?(k.restartDeferred?D.success(n("settings.view.pendingRestart.saved")):D.success(k.message||n("settings.plugins.toast.created")),k.reloadFailed&&D.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):D.error(k.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{E(!1)}}},W=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(Kt,{open:t,onOpenChange:k=>{!k&&g||e(k)},children:s.jsxs(zt,{className:"max-w-xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Vt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(hr,{items:W,activeId:l,onSelect:k=>A(k),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(Je,{id:"plugin-spec",value:m,onChange:k=>f(k.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":L?!1:void 0,disabled:g}),L&&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(Is,{id:"plugin-options",value:d,onChange:k=>y(k.target.value),rows:5,className:"font-mono",hasError:h,disabled:g}),h&&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(Je,{id:"plugin-filename",value:c,onChange:k=>N(k.target.value),placeholder:"my-plugin.ts","aria-invalid":j||void 0,disabled:g}),j&&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(Is,{id:"plugin-content",value:b,onChange:k=>C(k.target.value),rows:16,className:"font-mono",disabled:g})]})]}),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(k=>{const F=v===k,q=n(k==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>S(k),disabled:g,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(dr,{checked:F,onChange:()=>S(k),ariaLabel:q}),s.jsx("span",{className:ve("typography-ui-label font-normal",F?"text-foreground":"text-foreground/60"),children:q})]},k)})})]})]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:g,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(B,{size:"sm",onClick:()=>{K()},disabled:I,children:[g?s.jsx(R,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},dm=t=>{const e=ut.c(33),{spec:a}=t;let n;e[0]!==a?(n=p=>p.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=us(n),{t:r}=it();if(!i)return null;const l=pm;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=p):p=e[2];let m;e[3]!==i.latestVersion?(m=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[p,i.latestVersion]}),e[3]=i.latestVersion,e[4]=m):m=e[4];let f;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==m?(f=l(m,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]=m,e[9]=f):f=e[9],f}case"npm-missing-version":{let p;e[10]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=p):p=e[10];let m;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(m=l(p,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]=m):m=e[14],m}case"npm-missing-package":{let p;e[15]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=p):p=e[15];let m;return e[16]!==i.name||e[17]!==r?(m=l(p,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=m):m=e[18],m}case"npm-malformed":{let p;e[19]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=p):p=e[19];let m;return e[20]!==r?(m=l(p,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=m):m=e[21],m}case"npm-network":{let p;e[22]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=p):p=e[22];let m;return e[23]!==r?(m=l(p,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=m):m=e[24],m}case"path-missing":{let p;e[25]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=p):p=e[25];let m;return e[26]!==i.absolutePath||e[27]!==r?(m=l(p,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=m):m=e[28],m}case"path-unreadable":{let p;e[29]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=p):p=e[29];let m;return e[30]!==i.absolutePath||e[31]!==r?(m=l(p,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=m):m=e[32],m}case"path-ok":return null;default:return null}};function pm(t,e){return s.jsxs(pr,{children:[s.jsx(mr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(dl,{children:e})]})}const Ml=t=>{const e=ut.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,p=l===void 0?"sidebar":l,m=ds(),f=o.useRef(null),[d,y]=o.useState(!1),[c,N]=o.useState(!1),b=p==="background"||m?"bg-background":"bg-sidebar",C=b==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{const I=f.current;if(!I){y(!1),N(!1);return}if(!(I.scrollHeight>I.clientHeight+1)){y(!1),N(!1);return}y(I.scrollTop>1),N(I.scrollTop+I.clientHeight<I.scrollHeight-1)},e[0]=v):v=e[0];const S=v;let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{S()},e[1]=g):g=e[1];let E;e[2]!==i?(E=[i,S],e[2]=i,e[3]=E):E=e[3],o.useEffect(g,E);let M,A;e[4]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{const I=f.current;if(!I)return;const K=()=>S();return I.addEventListener("scroll",K,{passive:!0}),()=>I.removeEventListener("scroll",K)},A=[S],e[4]=M,e[5]=A):(M=e[4],A=e[5]),o.useEffect(M,A);let w;e[6]!==b||e[7]!==r?(w=ve("flex h-full flex-col",b,r),e[6]=b,e[7]=r,e[8]=w):w=e[8];let h;e[9]!==i?(h=s.jsx(Bs,{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]=h):h=e[10];let j;e[11]!==C||e[12]!==d?(j=d&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${C} 0%, transparent 100%)`}}),e[11]=C,e[12]=d,e[13]=j):j=e[13];let L;e[14]!==C||e[15]!==c?(L=c&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${C} 0%, transparent 100%)`}}),e[14]=C,e[15]=c,e[16]=L):L=e[16];let T;e[17]!==L||e[18]!==h||e[19]!==j?(T=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[h,j,L]}),e[17]=L,e[18]=h,e[19]=j,e[20]=T):T=e[20];let P;return e[21]!==n||e[22]!==a||e[23]!==T||e[24]!==w?(P=s.jsxs("div",{className:w,children:[a,T,n]}),e[21]=n,e[22]=a,e[23]=T,e[24]=w,e[25]=P):P=e[25],P},sr=t=>{const e=ut.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:p,className:m}=t,f=i===void 0?!1:i,d=p&&p.length>0,y=f?"bg-interactive-selection":"hover:bg-interactive-hover";let c;e[0]!==m||e[1]!==y?(c=ve("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",y,m),e[0]=m,e[1]=y,e[2]=c):c=e[2];let N;e[3]!==a?(N=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=N):N=e[4];let b;e[5]!==l||e[6]!==N?(b=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,N]}),e[5]=l,e[6]=N,e[7]=b):b=e[7];let C;e[8]!==n?(C=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=C):C=e[9];let v;e[10]!==r||e[11]!==b||e[12]!==C?(v=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-primary/50",tabIndex:0,children:[b,C]}),e[10]=r,e[11]=b,e[12]=C,e[13]=v):v=e[13];let S;e[14]!==p||e[15]!==d?(S=d&&s.jsxs(an,{children:[s.jsx(sn,{asChild:!0,children:s.jsx(B,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:p.map(mm)})]}),e[14]=p,e[15]=d,e[16]=S):S=e[16];let g;e[17]!==v||e[18]!==S?(g=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[v,S]}),e[17]=v,e[18]=S,e[19]=g):g=e[19];let E;return e[20]!==c||e[21]!==g?(E=s.jsx("div",{className:c,children:g}),e[20]=c,e[21]=g,e[22]=E):E=e[22],E};function mm(t){const e=t.icon;return s.jsxs(rn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:ve(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(R,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const um=t=>t.parsedKind==="npm"?"code-box":"folder",gm=t=>{const e=ut.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=it(),{entries:r,files:l,selectedId:p,setSelected:m,deleteEntry:f,deleteFile:d,loadPlugins:y}=us(Ls(hm)),c=us(fm),N=us(xm),b=us(bm),C=us(vm),[v,S]=o.useState(null),[g,E]=o.useState(!1),[M,A]=o.useState(!1);let w,h;e[0]!==y?(w=()=>{y()},h=[y],e[0]=y,e[1]=w,e[2]=h):(w=e[1],h=e[2]),o.useEffect(w,h);let j,L;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{const Xe=()=>A(!0);return window.addEventListener("openchamber:settings-open-plugin-add",Xe),()=>window.removeEventListener("openchamber:settings-open-plugin-add",Xe)},L=[],e[3]=j,e[4]=L):(j=e[3],L=e[4]),o.useEffect(j,L);let T;if(e[5]!==r||e[6]!==c){T={userEntries:0,projectEntries:0};for(const Xe of r){const Ze=c[Xe.spec];Ze?.kind==="npm-ok"&&Ze.hasUpdate&&(Xe.scope==="user"?T.userEntries=T.userEntries+1:Xe.scope==="project"&&(T.projectEntries=T.projectEntries+1))}e[5]=r,e[6]=c,e[7]=T}else T=e[7];const P=T;let I;e[8]!==r?(I=r.filter(ym),e[8]=r,e[9]=I):I=e[9];const K=I;let W;e[10]!==r?(W=r.filter(jm),e[10]=r,e[11]=W):W=e[11];const k=W;let F;e[12]!==l?(F=l.filter(wm),e[12]=l,e[13]=F):F=e[13];const q=F;let U;e[14]!==l?(U=l.filter(km),e[14]=l,e[15]=U):U=e[15];const Q=U,ne=r.length+l.length,_=ne===0;let re;e[16]!==n?(re=()=>{n?n():A(!0)},e[16]=n,e[17]=re):re=e[17];const V=re;let $;e[18]!==a||e[19]!==m?($=Xe=>{m(Xe),a?.()},e[18]=a,e[19]=m,e[20]=$):$=e[20];const z=$;let O;e[21]!==r||e[22]!==c||e[23]!==i||e[24]!==C?(O=async Xe=>{const Ze=r.find(Ee=>Ee.id===Xe);if(!Ze)return;const ht=c[Ze.spec];if(!ht||ht.kind!=="npm-ok"||!ht.hasUpdate||!ht.latestVersion)return;const Ke=ht.latestVersion;(await C(Xe)).ok?D.success(i("settings.plugins.toast.updatedToLatest",{version:Ke})):D.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=c,e[23]=i,e[24]=C,e[25]=O):O=e[25];const Y=O;let Z;e[26]!==b||e[27]!==i?(Z=async()=>{D.info(i("settings.plugins.toast.refreshing"));try{await b({force:!0})}catch{D.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=b,e[27]=i,e[28]=Z):Z=e[28];const ee=Z;let ge;e[29]!==f||e[30]!==d||e[31]!==v||e[32]!==i?(ge=async()=>{if(!v)return;E(!0);const Xe=v.kind==="entry"?await f(v.id):await d(v.id);Xe.ok?D.success(Xe.message||i("settings.plugins.sidebar.toast.deleted",{name:v.label})):D.error(i("settings.plugins.sidebar.toast.deleteFailed")),S(null),E(!1)},e[29]=f,e[30]=d,e[31]=v,e[32]=i,e[33]=ge):ge=e[33];const de=ge;let xe;e[34]!==z||e[35]!==Y||e[36]!==c||e[37]!==p||e[38]!==i?(xe=Xe=>{const Ze=c[Xe.spec],ht=Ze?.kind==="npm-ok"&&Ze.hasUpdate&&!!Ze.latestVersion,Ke=[];return ht&&Ke.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{Y(Xe.id)}}),Ke.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>S({kind:"entry",id:Xe.id,label:Xe.spec})}),s.jsx(sr,{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:Xe.spec}),s.jsx(dm,{spec:Xe.spec})]}),metadata:Xe.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:p===Xe.id,onSelect:()=>z(Xe.id),icon:s.jsx(R,{name:um(Xe),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Ke},Xe.id)},e[34]=z,e[35]=Y,e[36]=c,e[37]=p,e[38]=i,e[39]=xe):xe=e[39];const ae=xe;let te;e[40]!==z||e[41]!==p||e[42]!==i?(te=Xe=>s.jsx(sr,{title:Xe.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:p===Xe.id,onSelect:()=>z(Xe.id),icon:s.jsx(R,{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:()=>S({kind:"file",id:Xe.id,label:Xe.fileName})}]},Xe.id),e[40]=z,e[41]=p,e[42]=i,e[43]=te):te=e[43];const me=te;let Pe;e[44]!==i?(Pe=(Xe,Ze,ht)=>{const Ke=ht===void 0?0:ht;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:[Xe,Ke>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(Ke===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Ke})})]}),Ze]})},e[44]=i,e[45]=Pe):Pe=e[45];const Ne=Pe;let Se;e[46]!==i?(Se=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=Se):Se=e[47];let be;e[48]!==Se?(be=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:on,children:Se})}),e[48]=Se,e[49]=be):be=e[49];let Fe;e[50]!==i||e[51]!==ne?(Fe=i("settings.plugins.sidebar.total",{count:ne}),e[50]=i,e[51]=ne,e[52]=Fe):Fe=e[52];let Le;e[53]!==Fe?(Le=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Fe}),e[53]=Fe,e[54]=Le):Le=e[54];let oe;e[55]!==ee?(oe=()=>{ee()},e[55]=ee,e[56]=oe):oe=e[56];let fe;e[57]!==i?(fe=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=fe):fe=e[58];let De;e[59]!==i?(De=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=De):De=e[60];const $e=N?"size-4 animate-spin":"size-4";let Ve;e[61]!==$e?(Ve=s.jsx(R,{name:"refresh",className:$e}),e[61]=$e,e[62]=Ve):Ve=e[62];let qe;e[63]!==N||e[64]!==oe||e[65]!==fe||e[66]!==De||e[67]!==Ve?(qe=s.jsx(B,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:oe,disabled:N,"aria-label":fe,title:De,children:Ve}),e[63]=N,e[64]=oe,e[65]=fe,e[66]=De,e[67]=Ve,e[68]=qe):qe=e[68];let se;e[69]!==i?(se=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=se):se=e[70];let ie;e[71]!==i?(ie=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=ie):ie=e[72];let we;e[73]===Symbol.for("react.memo_cache_sentinel")?(we=s.jsx(R,{name:"add",className:"size-4"}),e[73]=we):we=e[73];let ye;e[74]!==V||e[75]!==se||e[76]!==ie?(ye=s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:V,"aria-label":se,title:ie,children:we}),e[74]=V,e[75]=se,e[76]=ie,e[77]=ye):ye=e[77];let Te;e[78]!==qe||e[79]!==ye?(Te=s.jsxs("div",{className:"flex items-center gap-1",children:[qe,ye]}),e[78]=qe,e[79]=ye,e[80]=Te):Te=e[80];let Ue;e[81]!==Le||e[82]!==Te?(Ue=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Le,Te]}),e[81]=Le,e[82]=Te,e[83]=Ue):Ue=e[83];let Ie;e[84]!==be||e[85]!==Ue?(Ie=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[be,Ue]}),e[84]=be,e[85]=Ue,e[86]=Ie):Ie=e[86];let je;e[87]!==_||e[88]!==k||e[89]!==Q||e[90]!==ae||e[91]!==me||e[92]!==Ne||e[93]!==i||e[94]!==P||e[95]!==K||e[96]!==q?(je=_?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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:[K.length>0&&Ne(i("settings.plugins.sidebar.group.userEntries"),K.map(ae),P.userEntries),q.length>0&&Ne(i("settings.plugins.sidebar.group.userFiles"),q.map(me)),k.length>0&&Ne(i("settings.plugins.sidebar.group.projectEntries"),k.map(ae),P.projectEntries),Q.length>0&&Ne(i("settings.plugins.sidebar.group.projectFiles"),Q.map(me))]}),e[87]=_,e[88]=k,e[89]=Q,e[90]=ae,e[91]=me,e[92]=Ne,e[93]=i,e[94]=P,e[95]=K,e[96]=q,e[97]=je):je=e[97];let Ge;e[98]!==Ie||e[99]!==je?(Ge=s.jsx(Ml,{variant:"background",header:Ie,children:je}),e[98]=Ie,e[99]=je,e[100]=Ge):Ge=e[100];let ue;e[101]!==M?(ue=s.jsx(cm,{open:M,onOpenChange:A}),e[101]=M,e[102]=ue):ue=e[102];const Ce=v!==null;let Me;e[103]!==g?(Me=Xe=>{!Xe&&!g&&S(null)},e[103]=g,e[104]=Me):Me=e[104];let Ye;e[105]!==i?(Ye=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=Ye):Ye=e[106];let G;e[107]!==Ye?(G=s.jsx($t,{children:Ye}),e[107]=Ye,e[108]=G):G=e[108];const ke=v?.label??"";let Ae;e[109]!==i||e[110]!==ke?(Ae=i("settings.plugins.sidebar.deleteDialog.description",{name:ke}),e[109]=i,e[110]=ke,e[111]=Ae):Ae=e[111];let He;e[112]!==Ae?(He=s.jsx(Vt,{children:Ae}),e[112]=Ae,e[113]=He):He=e[113];let at;e[114]!==G||e[115]!==He?(at=s.jsxs(_t,{children:[G,He]}),e[114]=G,e[115]=He,e[116]=at):at=e[116];let nt;e[117]===Symbol.for("react.memo_cache_sentinel")?(nt=()=>S(null),e[117]=nt):nt=e[117];let dt;e[118]!==i?(dt=i("settings.common.actions.cancel"),e[118]=i,e[119]=dt):dt=e[119];let xt;e[120]!==g||e[121]!==dt?(xt=s.jsx(B,{size:"sm",variant:"ghost",onClick:nt,disabled:g,children:dt}),e[120]=g,e[121]=dt,e[122]=xt):xt=e[122];let H;e[123]!==g||e[124]!==i?(H=i(g?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=g,e[124]=i,e[125]=H):H=e[125];let Be;e[126]!==de||e[127]!==g||e[128]!==H?(Be=s.jsx(B,{size:"sm",variant:"destructive",onClick:de,disabled:g,children:H}),e[126]=de,e[127]=g,e[128]=H,e[129]=Be):Be=e[129];let tt;e[130]!==xt||e[131]!==Be?(tt=s.jsxs(ns,{children:[xt,Be]}),e[130]=xt,e[131]=Be,e[132]=tt):tt=e[132];let rt;e[133]!==at||e[134]!==tt?(rt=s.jsxs(zt,{className:"max-w-md",children:[at,tt]}),e[133]=at,e[134]=tt,e[135]=rt):rt=e[135];let pt;e[136]!==Ce||e[137]!==Me||e[138]!==rt?(pt=s.jsx(Kt,{open:Ce,onOpenChange:Me,children:rt}),e[136]=Ce,e[137]=Me,e[138]=rt,e[139]=pt):pt=e[139];let Ct;return e[140]!==Ge||e[141]!==ue||e[142]!==pt?(Ct=s.jsxs(s.Fragment,{children:[Ge,ue,pt]}),e[140]=Ge,e[141]=ue,e[142]=pt,e[143]=Ct):Ct=e[143],Ct};function hm(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function fm(t){return t.registryInfo}function xm(t){return t.isLoadingRegistry}function bm(t){return t.loadRegistryInfo}function vm(t){return t.updateToLatest}function ym(t){return t.scope==="user"}function jm(t){return t.scope==="project"}function wm(t){return t.scope==="user"}function km(t){return t.scope==="project"}const Nm=({entryId:t,spec:e})=>{const{t:a}=it(),n=us(y=>y.registryInfo[e]),i=us(y=>y.updateToLatest),[r,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const y=n.latestVersion,c=n.currentVersion??"",N=async()=>{l(!0);try{(await i(t)).ok?D.success(a("settings.plugins.toast.updatedToLatest",{version:y})):D.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(R,{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:c,latest:y})})]}),s.jsx(B,{variant:"default",size:"sm",onClick:()=>{N()},disabled:r,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:y})})]})}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(R,{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 p=n.kind==="path-unreadable",m=p?"var(--status-warning)":"var(--status-error)",f=p?"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(R,{name:f,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:m}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:m},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:d})]})]})};function Sm(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 Rl(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function oo(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Rl(t.options),fileName:"",content:""}}function lo(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const co=t=>{const e=ut.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=ve("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},Cm=()=>{const{t}=it(),e=us(v=>v.selectedId),a=us(v=>v.entries),n=us(v=>v.files),i=us(v=>v.draft),r=us(v=>v.setDraft),l=us(v=>v.updateEntry),p=us(v=>v.updateFile),m=us(v=>v.readFile),f=o.useMemo(()=>e?a.find(v=>v.id===e)??null:null,[a,e]),d=o.useMemo(()=>e?n.find(v=>v.id===e)??null:null,[n,e]),[y,c]=o.useState(!1),[N,b]=o.useState(!1),C=o.useRef(new Map);if(o.useEffect(()=>{let v=!1;return f?(r(oo(f)),()=>{v=!0}):d?(b(!0),(async()=>{const S=await m(d.id);if(v)return;b(!1);const g=S?.content??"";C.current.set(d.id,g),r(lo(d,g))})(),()=>{v=!0}):(r(null),()=>{v=!0})},[f,d,m,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(R,{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 v=Sm(i.optionsJson),S=v.ok,g=i.spec!==f.spec||i.optionsJson!==Rl(f.options),E=()=>{r(oo(f))},M=async()=>{if(!S)return;const A=i.spec.trim();if(!A){D.error(t("settings.plugins.validation.specRequired"));return}c(!0);try{const w=await l(f.id,{spec:A,options:v.value});w.ok?w.reloadFailed?D.warning(w.message||t("settings.plugins.toast.reloadFailed"),{description:w.warning}):w.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(w.message||t("settings.plugins.toast.updated")):D.error(w.message||t("settings.plugins.toast.reloadFailed"))}finally{c(!1)}};return s.jsxs(ss,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(co,{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(Nm,{entryId:f.id,spec:f.spec})}),s.jsx(_e,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(Je,{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(Is,{value:i.optionsJson,onChange:A=>r({...i,optionsJson:A.target.value}),rows:10,className:ve("font-mono typography-meta min-h-[200px]",!S&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!S&&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(B,{variant:"default",size:"sm",onClick:()=>{M()},disabled:!g||!S||y,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:E,disabled:!g||y,children:t("settings.plugins.page.action.discard")})]})]})]})}if(d&&i&&i.mode==="file"){const v=C.current.get(d.id)??"",S=i.content!==v||i.fileName!==d.fileName,g=()=>{(async()=>{b(!0);const A=(await m(d.id))?.content??"";b(!1),C.current.set(d.id,A),r(lo(d,A))})()},E=async()=>{c(!0);try{const M=await p(d.id,{content:i.content});M.ok?(C.current.set(d.id,i.content),M.reloadFailed?D.warning(M.message||t("settings.plugins.toast.reloadFailed"),{description:M.warning}):M.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(M.message||t("settings.plugins.toast.updated"))):D.error(M.message||t("settings.plugins.toast.reloadFailed"))}finally{c(!1)}};return s.jsx(ss,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(co,{scope:d.scope,label:d.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:ve("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(Is,{value:i.content,onChange:M=>r({...i,content:M.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:N}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(B,{variant:"default",size:"sm",onClick:()=>{E()},disabled:!S||y||N,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:g,disabled:y||N,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(R,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Pm="<built-in>",Fa=t=>t?.path===Pm,nr=t=>!!t&&!Fa(t)&&t.renamable===!0,Im=t=>{const e=ut.c(157),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,p]=o.useState(""),[m,f]=o.useState(null),[d,y]=o.useState(!1),[c,N]=o.useState(null),{selectedSkillName:b,setSelectedSkill:C,setSkillDraft:v,deleteSkill:S,renameSkill:g,getSkillDetail:E}=$s(Ls(Am)),M=Us();let A;e[0]!==M?(A=Ee=>cr(Ee,M),e[0]=M,e[1]=A):A=e[1];const w=$s(A),h=$s(Tm);let j,L;e[2]!==h||e[3]!==M?(j=()=>{h(M)},L=[h,M],e[2]=h,e[3]=M,e[4]=j,e[5]=L):(j=e[4],L=e[5]),o.useEffect(j,L);let T;e[6]!==a||e[7]!==C||e[8]!==v||e[9]!==w?(T=()=>{let Ee="new-skill",jt=1;for(;w.some(J=>J.name===Ee);)Ee=`new-skill-${jt}`,jt++;v({name:Ee,scope:"user",source:"opencode",description:""}),C(Ee),a?.()},e[6]=a,e[7]=C,e[8]=v,e[9]=w,e[10]=T):T=e[10];const P=T;let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=async Ee=>{Fa(Ee)||f(Ee)},e[11]=I):I=e[11];const K=I;let W;e[12]!==m||e[13]!==S||e[14]!==M||e[15]!==n?(W=async()=>{if(!m)return;if(Fa(m)){f(null);return}y(!0),await S(m.name,M)?(D.success(n("settings.skills.sidebar.toast.skillDeleted",{name:m.name})),f(null)):D.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),y(!1)},e[12]=m,e[13]=S,e[14]=M,e[15]=n,e[16]=W):W=e[16];const k=W;let F;e[17]!==E||e[18]!==C||e[19]!==v||e[20]!==M||e[21]!==w||e[22]!==n?(F=async Ee=>{if(Fa(Ee))return;const jt=Ee.name;let J=1,he=`${jt}-copy`;for(;w.some(Re=>Re.name===he);)J++,he=`${jt}-copy-${J}`;const ze=await E(Ee.name,M);if(!ze){D.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}v({name:he,scope:Ee.scope||"user",source:Ee.source||"opencode",description:(ze.sources.md.fields.includes("description"),""),instructions:""}),C(he)},e[17]=E,e[18]=C,e[19]=v,e[20]=M,e[21]=w,e[22]=n,e[23]=F):F=e[23];const q=F;let U;e[24]===Symbol.for("react.memo_cache_sentinel")?(U=Ee=>{nr(Ee)&&(p(Ee.name),r(Ee))},e[24]=U):U=e[24];const Q=U;let ne;e[25]!==i||e[26]!==l||e[27]!==g||e[28]!==C||e[29]!==M||e[30]!==w||e[31]!==n?(ne=async()=>{if(!i)return;if(!nr(i)){r(null);return}const Ee=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Ee){D.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Ee===i.name){r(null);return}if(w.some(J=>J.name===Ee)){D.error(n("settings.skills.page.toast.skillExists"));return}await g(i.name,Ee,M)?(D.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Ee})),C(Ee)):D.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[25]=i,e[26]=l,e[27]=g,e[28]=C,e[29]=M,e[30]=w,e[31]=n,e[32]=ne):ne=e[32];const _=ne;let re;e[33]!==w?(re=w.filter(Em),e[33]=w,e[34]=re):re=e[34];const V=re;let $;e[35]!==w?($=w.filter(Dm),e[35]=w,e[36]=$):$=e[36];const z=$;let O;e[37]===Symbol.for("react.memo_cache_sentinel")?(O=function(jt){const J={},he=[];for(const Re of jt)Re.group?(J[Re.group]||(J[Re.group]=[]),J[Re.group].push(Re)):he.push(Re);const ze=Object.keys(J).sort(Mm).map(Re=>({name:Re,skills:[...J[Re]].sort(Rm)}));return he.sort(Om),{sortedGroups:ze,ungrouped:he}},e[37]=O):O=e[37];const Y=O;let Z;e[38]!==V?(Z=Y(V),e[38]=V,e[39]=Z):Z=e[39];const ee=Z;let ge;e[40]!==z?(ge=Y(z),e[40]=z,e[41]=ge):ge=e[41];const de=ge;let xe;e[42]===Symbol.for("react.memo_cache_sentinel")?(xe=ve("flex h-full flex-col","bg-background"),e[42]=xe):xe=e[42];let ae;e[43]!==n?(ae=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ae):ae=e[44];let te;e[45]!==ae?(te=s.jsx("h2",{className:`${on} mb-3`,children:ae}),e[45]=ae,e[46]=te):te=e[46];let me;e[47]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(Va,{className:"mb-3"}),e[47]=me):me=e[47];let Pe;e[48]!==w.length||e[49]!==n?(Pe=n("settings.skills.sidebar.total",{count:w.length}),e[48]=w.length,e[49]=n,e[50]=Pe):Pe=e[50];let Ne;e[51]!==Pe?(Ne=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Pe}),e[51]=Pe,e[52]=Ne):Ne=e[52];let Se;e[53]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[53]=Se):Se=e[53];let be;e[54]!==P?(be=s.jsx(B,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:P,children:Se}),e[54]=P,e[55]=be):be=e[55];let Fe;e[56]!==Ne||e[57]!==be?(Fe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ne,be]}),e[56]=Ne,e[57]=be,e[58]=Fe):Fe=e[58];let Le;e[59]!==te||e[60]!==Fe?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[te,me,Fe]}),e[59]=te,e[60]=Fe,e[61]=Le):Le=e[61];let oe;e[62]!==ee||e[63]!==de||e[64]!==q||e[65]!==a||e[66]!==c||e[67]!==V||e[68]!==b||e[69]!==C||e[70]!==w.length||e[71]!==n||e[72]!==z?(oe=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:w.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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:[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:n("settings.skills.sidebar.section.project")}),ee.sortedGroups.map(Ee=>{const{name:jt,skills:J}=Ee;return s.jsx(Zi,{label:jt,count:J.length,storageKey:"project-skills",children:J.map(he=>s.jsx(ti,{skill:he,isSelected:b===he.name,onSelect:()=>{C(he.name),a?.()},onRename:()=>Q(he),onDelete:()=>K(he),onDuplicate:()=>q(he),isMenuOpen:c===he.name,onMenuOpenChange:ze=>N(ze?he.name:null)},he.name))},jt)}),ee.ungrouped.map(Ee=>s.jsx(ti,{skill:Ee,isSelected:b===Ee.name,onSelect:()=>{C(Ee.name),a?.()},onRename:()=>Q(Ee),onDelete:()=>K(Ee),onDuplicate:()=>q(Ee),isMenuOpen:c===Ee.name,onMenuOpenChange:jt=>N(jt?Ee.name:null)},Ee.name))]}),z.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),de.sortedGroups.map(Ee=>{const{name:jt,skills:J}=Ee;return s.jsx(Zi,{label:jt,count:J.length,storageKey:"user-skills",children:J.map(he=>s.jsx(ti,{skill:he,isSelected:b===he.name,onSelect:()=>{C(he.name),a?.()},onRename:()=>Q(he),onDelete:()=>K(he),onDuplicate:()=>q(he),isMenuOpen:c===he.name,onMenuOpenChange:ze=>N(ze?he.name:null)},he.name))},jt)}),de.ungrouped.map(Ee=>s.jsx(ti,{skill:Ee,isSelected:b===Ee.name,onSelect:()=>{C(Ee.name),a?.()},onRename:()=>Q(Ee),onDelete:()=>K(Ee),onDuplicate:()=>q(Ee),isMenuOpen:c===Ee.name,onMenuOpenChange:jt=>N(jt?Ee.name:null)},Ee.name))]})]})}),e[62]=ee,e[63]=de,e[64]=q,e[65]=a,e[66]=c,e[67]=V,e[68]=b,e[69]=C,e[70]=w.length,e[71]=n,e[72]=z,e[73]=oe):oe=e[73];const fe=m!==null;let De;e[74]!==d?(De=Ee=>{!Ee&&!d&&f(null)},e[74]=d,e[75]=De):De=e[75];let $e;e[76]!==n?($e=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=$e):$e=e[77];let Ve;e[78]!==$e?(Ve=s.jsx($t,{children:$e}),e[78]=$e,e[79]=Ve):Ve=e[79];const qe=m?.name??"";let se;e[80]!==n||e[81]!==qe?(se=n("settings.skills.sidebar.deleteDialog.description",{name:qe}),e[80]=n,e[81]=qe,e[82]=se):se=e[82];let ie;e[83]!==se?(ie=s.jsx(Vt,{children:se}),e[83]=se,e[84]=ie):ie=e[84];let we;e[85]!==Ve||e[86]!==ie?(we=s.jsxs(_t,{children:[Ve,ie]}),e[85]=Ve,e[86]=ie,e[87]=we):we=e[87];let ye;e[88]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>f(null),e[88]=ye):ye=e[88];let Te;e[89]!==n?(Te=n("settings.common.actions.cancel"),e[89]=n,e[90]=Te):Te=e[90];let Ue;e[91]!==d||e[92]!==Te?(Ue=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:ye,disabled:d,children:Te}),e[91]=d,e[92]=Te,e[93]=Ue):Ue=e[93];let Ie;e[94]!==n?(Ie=n("settings.common.actions.delete"),e[94]=n,e[95]=Ie):Ie=e[95];let je;e[96]!==k||e[97]!==d||e[98]!==Ie?(je=s.jsx(B,{size:"sm",onClick:k,disabled:d,children:Ie}),e[96]=k,e[97]=d,e[98]=Ie,e[99]=je):je=e[99];let Ge;e[100]!==Ue||e[101]!==je?(Ge=s.jsxs(ns,{children:[Ue,je]}),e[100]=Ue,e[101]=je,e[102]=Ge):Ge=e[102];let ue;e[103]!==we||e[104]!==Ge?(ue=s.jsxs(zt,{className:"max-w-md",children:[we,Ge]}),e[103]=we,e[104]=Ge,e[105]=ue):ue=e[105];let Ce;e[106]!==fe||e[107]!==De||e[108]!==ue?(Ce=s.jsx(Kt,{open:fe,onOpenChange:De,children:ue}),e[106]=fe,e[107]=De,e[108]=ue,e[109]=Ce):Ce=e[109];const Me=i!==null;let Ye;e[110]===Symbol.for("react.memo_cache_sentinel")?(Ye=Ee=>!Ee&&r(null),e[110]=Ye):Ye=e[110];let G;e[111]!==n?(G=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=G):G=e[112];let ke;e[113]!==G?(ke=s.jsx($t,{children:G}),e[113]=G,e[114]=ke):ke=e[114];const Ae=i?.name??"";let He;e[115]!==n||e[116]!==Ae?(He=n("settings.skills.sidebar.renameDialog.description",{name:Ae}),e[115]=n,e[116]=Ae,e[117]=He):He=e[117];let at;e[118]!==He?(at=s.jsx(Vt,{children:He}),e[118]=He,e[119]=at):at=e[119];let nt;e[120]!==ke||e[121]!==at?(nt=s.jsxs(_t,{children:[ke,at]}),e[120]=ke,e[121]=at,e[122]=nt):nt=e[122];let dt;e[123]===Symbol.for("react.memo_cache_sentinel")?(dt=Ee=>p(Ee.target.value),e[123]=dt):dt=e[123];let xt;e[124]!==n?(xt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=xt):xt=e[125];let H;e[126]!==_?(H=Ee=>{Ee.key==="Enter"&&_()},e[126]=_,e[127]=H):H=e[127];let Be;e[128]!==l||e[129]!==xt||e[130]!==H?(Be=s.jsx(Je,{value:l,onChange:dt,placeholder:xt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:H}),e[128]=l,e[129]=xt,e[130]=H,e[131]=Be):Be=e[131];let tt;e[132]===Symbol.for("react.memo_cache_sentinel")?(tt=()=>r(null),e[132]=tt):tt=e[132];let rt;e[133]!==n?(rt=n("settings.common.actions.cancel"),e[133]=n,e[134]=rt):rt=e[134];let pt;e[135]!==rt?(pt=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:tt,children:rt}),e[135]=rt,e[136]=pt):pt=e[136];let Ct;e[137]!==n?(Ct=n("settings.common.actions.rename"),e[137]=n,e[138]=Ct):Ct=e[138];let Xe;e[139]!==_||e[140]!==Ct?(Xe=s.jsx(B,{size:"sm",onClick:_,children:Ct}),e[139]=_,e[140]=Ct,e[141]=Xe):Xe=e[141];let Ze;e[142]!==pt||e[143]!==Xe?(Ze=s.jsxs(ns,{children:[pt,Xe]}),e[142]=pt,e[143]=Xe,e[144]=Ze):Ze=e[144];let ht;e[145]!==nt||e[146]!==Be||e[147]!==Ze?(ht=s.jsxs(zt,{children:[nt,Be,Ze]}),e[145]=nt,e[146]=Be,e[147]=Ze,e[148]=ht):ht=e[148];let Ke;e[149]!==Me||e[150]!==ht?(Ke=s.jsx(Kt,{open:Me,onOpenChange:Ye,children:ht}),e[149]=Me,e[150]=ht,e[151]=Ke):Ke=e[151];let wt;return e[152]!==Le||e[153]!==oe||e[154]!==Ce||e[155]!==Ke?(wt=s.jsxs("div",{className:xe,children:[Le,oe,Ce,Ke]}),e[152]=Le,e[153]=oe,e[154]=Ce,e[155]=Ke,e[156]=wt):wt=e[156],wt},ti=t=>{const e=ut.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:p,isMenuOpen:m,onMenuOpenChange:f}=t,{t:d}=it();let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=za(),e[0]=y):y=e[0];const c=y;let N;e[1]!==a?(N=Fa(a),e[1]=a,e[2]=N):N=e[2];const b=N;let C;e[3]!==a?(C=nr(a),e[3]=a,e[4]=C):C=e[4];const v=C,[S,g]=o.useState(!1);let E;e[5]!==v||e[6]!==r||e[7]!==p||e[8]!==l||e[9]!==d?(E=q=>s.jsxs(s.Fragment,{children:[v?s.jsxs(q,{onClick:U=>{U.stopPropagation(),l()},children:[s.jsx(R,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}):null,s.jsxs(q,{onClick:U=>{U.stopPropagation(),p()},children:[s.jsx(R,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),s.jsxs(q,{onClick:U=>{U.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[5]=v,e[6]=r,e[7]=p,e[8]=l,e[9]=d,e[10]=E):E=e[10];const M=E,A=!b&&S,w=n?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[11]!==w?(h=ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",w),e[11]=w,e[12]=h):h=e[12];let j;e[13]!==b?(j=!c&&!b?q=>{q.preventDefault(),g(!0)}:void 0,e[13]=b,e[14]=j):j=e[14];let L;e[15]!==h||e[16]!==j?(L=s.jsx("div",{className:h,onContextMenu:j}),e[15]=h,e[16]=j,e[17]=L):L=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-primary/50",tabIndex:0,children:T}),e[20]=i,e[21]=T,e[22]=P):P=e[22];let I;e[23]!==b||e[24]!==m||e[25]!==f||e[26]!==M?(I=b?null:s.jsxs(an,{open:m,onOpenChange:q=>{q&&g(!1),f(q)},children:[s.jsx(sn,{asChild:!0,children:s.jsx(B,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:M(rn)})]}),e[23]=b,e[24]=m,e[25]=f,e[26]=M,e[27]=I):I=e[27];let K;e[28]!==P||e[29]!==I?(K=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,I]}),e[28]=P,e[29]=I,e[30]=K):K=e[30];let W;e[31]!==K||e[32]!==L?(W=s.jsx(Wn,{render:L,children:K}),e[31]=K,e[32]=L,e[33]=W):W=e[33];let k;e[34]!==b||e[35]!==M?(k=b?null:s.jsx(Gn,{className:"w-fit min-w-20",children:M(qn)}),e[34]=b,e[35]=M,e[36]=k):k=e[36];let F;return e[37]!==W||e[38]!==k||e[39]!==A?(F=s.jsxs(Jn,{open:A,onOpenChange:g,children:[W,k]}),e[37]=W,e[38]=k,e[39]=A,e[40]=F):F=e[40],F};function Am(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Tm(t){return t.loadSkills}function Em(t){return t.scope==="project"}function Dm(t){return t.scope==="user"}function Mm(t,e){return t.localeCompare(e)}function Rm(t,e){return t.name.localeCompare(e.name)}function Om(t,e){return t.name.localeCompare(e.name)}const Lm=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Fm=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},Km=async()=>{try{const t=tn()?.settings;if(t)return(await t.load())?.settings||{};const e=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},zm=t=>{const e=ut.c(162),{open:a,onOpenChange:n}=t,{t:i}=it(),r=hn(Um),l=hn(_m),p=hn($m),m=hn(Vm),f=hn(Bm),d=Un(Hm),y=Un(Gm),[c,N]=o.useState(""),[b,C]=o.useState(""),[v,S]=o.useState("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[E,M]=o.useState(g),[A,w]=o.useState(null),[h,j]=o.useState(!1);let L;e[1]===Symbol.for("react.memo_cache_sentinel")?(L=[],e[1]=L):L=e[1];const[T,P]=o.useState(L),[I,K]=o.useState(null),W=o.useRef(0);let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=Ze=>{W.current=W.current+1,j(!1),w(null),Ze?.clearIdentity&&(P([]),K(null))},e[2]=k):k=e[2];const F=k;let q,U;e[3]!==y||e[4]!==a?(q=()=>{a&&(W.current=W.current+1,N(""),C(""),S(""),w(null),j(!1),P([]),K(null),y(),(async()=>{const Ze=await Km(),ht=Array.isArray(Ze?.skillCatalogs)?Ze?.skillCatalogs:[];M(ht||[])})())},U=[a,y],e[3]=y,e[4]=a,e[5]=q,e[6]=U):(q=e[5],U=e[6]),o.useEffect(q,U);let Q;e[7]!==b?(Q=b.trim(),e[7]=b,e[8]=Q):Q=e[8];const ne=Q;let _;e[9]!==v?(_=v.trim(),e[9]=v,e[10]=_):_=e[10];const re=_;let V;if(e[11]!==E||e[12]!==ne||e[13]!==re){let Ze;e[15]!==ne||e[16]!==re?(Ze=ht=>{const Ke=(ht.source||"").trim(),wt=(ht.subpath||"").trim();return Ke===ne&&wt===re},e[15]=ne,e[16]=re,e[17]=Ze):Ze=e[17],V=E.some(Ze),e[11]=E,e[12]=ne,e[13]=re,e[14]=V}else V=e[14];const $=V;let z;e[18]!==d||e[19]!==I||e[20]!==c||e[21]!==r||e[22]!==b||e[23]!==v||e[24]!==i?(z=async()=>{const Ze=b.trim();if(!Ze){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}c.trim()||N(Fm(Ze)),j(!1),w(null);const ht=W.current+1;W.current=ht;const Ke=await r({source:Ze,subpath:v.trim()||void 0,gitIdentityId:I||void 0});if(W.current!==ht)return;if(!Ke.ok){if(Ke.error?.kind==="authRequired"){if(ds()){D.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Ee=Ke.error.identities||[];if(P(Ee),!I&&Ee.length>0){const jt=d&&d!=="global"&&Ee.some(J=>J.id===d)?d:Ee[0].id;K(jt)}D.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}D.error(Ke.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const wt=Ke.items?.length||0;if(w(wt),wt===0){D.error(i("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}P([]),j(!0),D.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:wt}))},e[18]=d,e[19]=I,e[20]=c,e[21]=r,e[22]=b,e[23]=v,e[24]=i,e[25]=z):z=e[25];const O=z;let Y;e[26]!==E||e[27]!==I||e[28]!==$||e[29]!==c||e[30]!==l||e[31]!==p||e[32]!==n||e[33]!==h||e[34]!==m||e[35]!==b||e[36]!==v||e[37]!==i?(Y=async()=>{const Ze=c.trim(),ht=b.trim(),Ke=v.trim();if(!Ze){D.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!ht){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!h){D.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if($){D.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const wt={id:Lm(),label:Ze,source:ht,...Ke?{subpath:Ke}:{},...I?{gitIdentityId:I}:{}},Ee=[...E,wt];try{await vt({skillCatalogs:Ee}),M(Ee),D.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await p(wt.id,{refresh:!0}),m(wt.id),n(!1)}catch(jt){const J=jt;D.error(J instanceof Error?J.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=E,e[27]=I,e[28]=$,e[29]=c,e[30]=l,e[31]=p,e[32]=n,e[33]=h,e[34]=m,e[35]=b,e[36]=v,e[37]=i,e[38]=Y):Y=e[38];const Z=Y;let ee;e[39]!==i?(ee=i("settings.skills.catalog.add.title"),e[39]=i,e[40]=ee):ee=e[40];let ge;e[41]!==ee?(ge=s.jsx($t,{children:ee}),e[41]=ee,e[42]=ge):ge=e[42];let de;e[43]!==i?(de=i("settings.skills.catalog.add.descriptionPrefix"),e[43]=i,e[44]=de):de=e[44];let xe;e[45]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=xe):xe=e[45];let ae;e[46]!==i?(ae=i("settings.skills.catalog.add.descriptionSuffix"),e[46]=i,e[47]=ae):ae=e[47];let te;e[48]!==de||e[49]!==ae?(te=s.jsxs(Vt,{children:[de," ",xe,ae]}),e[48]=de,e[49]=ae,e[50]=te):te=e[50];let me;e[51]!==ge||e[52]!==te?(me=s.jsxs(_t,{children:[ge,te]}),e[51]=ge,e[52]=te,e[53]=me):me=e[53];let Pe;e[54]!==i?(Pe=i("settings.skills.catalog.add.field.catalogName"),e[54]=i,e[55]=Pe):Pe=e[55];let Ne;e[56]!==Pe?(Ne=s.jsx("label",{className:"typography-ui-label text-foreground",children:Pe}),e[56]=Pe,e[57]=Ne):Ne=e[57];let Se;e[58]===Symbol.for("react.memo_cache_sentinel")?(Se=Ze=>N(Ze.target.value),e[58]=Se):Se=e[58];let be;e[59]!==i?(be=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=i,e[60]=be):be=e[60];let Fe;e[61]!==c||e[62]!==be?(Fe=s.jsx(Je,{value:c,onChange:Se,placeholder:be}),e[61]=c,e[62]=be,e[63]=Fe):Fe=e[63];let Le;e[64]!==Ne||e[65]!==Fe?(Le=s.jsxs("div",{className:"space-y-2",children:[Ne,Fe]}),e[64]=Ne,e[65]=Fe,e[66]=Le):Le=e[66];let oe;e[67]!==i?(oe=i("settings.skills.catalog.add.field.repository"),e[67]=i,e[68]=oe):oe=e[68];let fe;e[69]!==oe?(fe=s.jsx("label",{className:"typography-ui-label text-foreground",children:oe}),e[69]=oe,e[70]=fe):fe=e[70];let De;e[71]!==i?(De=i("settings.skills.catalog.add.field.repositoryHint"),e[71]=i,e[72]=De):De=e[72];let $e;e[73]!==De?($e=s.jsx(Jt,{children:De}),e[73]=De,e[74]=$e):$e=e[74];let Ve;e[75]!==fe||e[76]!==$e?(Ve=s.jsxs("div",{className:"flex items-center gap-1",children:[fe,$e]}),e[75]=fe,e[76]=$e,e[77]=Ve):Ve=e[77];let qe;e[78]===Symbol.for("react.memo_cache_sentinel")?(qe=Ze=>{C(Ze.target.value),F({clearIdentity:!0})},e[78]=qe):qe=e[78];let se;e[79]!==i?(se=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[79]=i,e[80]=se):se=e[80];let ie;e[81]!==b||e[82]!==se?(ie=s.jsx(Je,{value:b,onChange:qe,placeholder:se}),e[81]=b,e[82]=se,e[83]=ie):ie=e[83];let we;e[84]!==Ve||e[85]!==ie?(we=s.jsxs("div",{className:"space-y-2",children:[Ve,ie]}),e[84]=Ve,e[85]=ie,e[86]=we):we=e[86];let ye;e[87]!==i?(ye=i("settings.skills.catalog.add.field.optionalSubpath"),e[87]=i,e[88]=ye):ye=e[88];let Te;e[89]!==ye?(Te=s.jsx("label",{className:"typography-ui-label text-foreground",children:ye}),e[89]=ye,e[90]=Te):Te=e[90];let Ue;e[91]===Symbol.for("react.memo_cache_sentinel")?(Ue=Ze=>{S(Ze.target.value),F({clearIdentity:!0})},e[91]=Ue):Ue=e[91];let Ie;e[92]!==i?(Ie=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[92]=i,e[93]=Ie):Ie=e[93];let je;e[94]!==v||e[95]!==Ie?(je=s.jsx(Je,{value:v,onChange:Ue,placeholder:Ie}),e[94]=v,e[95]=Ie,e[96]=je):je=e[96];let Ge;e[97]!==Te||e[98]!==je?(Ge=s.jsxs("div",{className:"space-y-2",children:[Te,je]}),e[97]=Te,e[98]=je,e[99]=Ge):Ge=e[99];let ue;e[100]!==I||e[101]!==T||e[102]!==i?(ue=T.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:i("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:i("settings.skills.catalog.shared.auth.description")}),s.jsx(Jt,{className:"ml-1",children:i("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Pt,{value:I||"",onValueChange:Ze=>{K(Ze),F()},children:[s.jsx(It,{className:"w-fit",children:s.jsx("span",{children:T.find(Ze=>Ze.id===I)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(At,{align:"start",children:T.map(qm)})]})]}):null,e[100]=I,e[101]=T,e[102]=i,e[103]=ue):ue=e[103];let Ce;e[104]!==A||e[105]!==i?(Ce=A!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:A})}):null,e[104]=A,e[105]=i,e[106]=Ce):Ce=e[106];let Me;e[107]!==$||e[108]!==i?(Me=$?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[107]=$,e[108]=i,e[109]=Me):Me=e[109];let Ye;e[110]!==Le||e[111]!==we||e[112]!==Ge||e[113]!==ue||e[114]!==Ce||e[115]!==Me?(Ye=s.jsxs("div",{className:"space-y-4",children:[Le,we,Ge,ue,Ce,Me]}),e[110]=Le,e[111]=we,e[112]=Ge,e[113]=ue,e[114]=Ce,e[115]=Me,e[116]=Ye):Ye=e[116];let G;e[117]!==n?(G=()=>n(!1),e[117]=n,e[118]=G):G=e[118];let ke;e[119]!==i?(ke=i("settings.common.actions.cancel"),e[119]=i,e[120]=ke):ke=e[120];let Ae;e[121]!==G||e[122]!==ke?(Ae=s.jsx(B,{size:"sm",variant:"ghost",onClick:G,children:ke}),e[121]=G,e[122]=ke,e[123]=Ae):Ae=e[123];let He;e[124]!==O?(He=()=>{O()},e[124]=O,e[125]=He):He=e[125];let at;e[126]!==f||e[127]!==b?(at=f||!b.trim(),e[126]=f,e[127]=b,e[128]=at):at=e[128];let nt;e[129]===Symbol.for("react.memo_cache_sentinel")?(nt=s.jsx(R,{name:"git-repository",className:"h-4 w-4"}),e[129]=nt):nt=e[129];let dt;e[130]!==f||e[131]!==i?(dt=i(f?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[130]=f,e[131]=i,e[132]=dt):dt=e[132];let xt;e[133]!==He||e[134]!==at||e[135]!==dt?(xt=s.jsxs(B,{size:"sm",className:"gap-2",variant:"ghost",onClick:He,disabled:at,children:[nt,dt]}),e[133]=He,e[134]=at,e[135]=dt,e[136]=xt):xt=e[136];let H;e[137]!==Z?(H=()=>{Z()},e[137]=Z,e[138]=H):H=e[138];let Be;e[139]!==$||e[140]!==c||e[141]!==h||e[142]!==b?(Be=!h||$||!c.trim()||!b.trim(),e[139]=$,e[140]=c,e[141]=h,e[142]=b,e[143]=Be):Be=e[143];let tt;e[144]!==i?(tt=i("settings.skills.catalog.add.actions.addCatalog"),e[144]=i,e[145]=tt):tt=e[145];let rt;e[146]!==H||e[147]!==Be||e[148]!==tt?(rt=s.jsx(B,{size:"sm",onClick:H,disabled:Be,children:tt}),e[146]=H,e[147]=Be,e[148]=tt,e[149]=rt):rt=e[149];let pt;e[150]!==Ae||e[151]!==xt||e[152]!==rt?(pt=s.jsxs(ns,{children:[Ae,xt,rt]}),e[150]=Ae,e[151]=xt,e[152]=rt,e[153]=pt):pt=e[153];let Ct;e[154]!==me||e[155]!==Ye||e[156]!==pt?(Ct=s.jsxs(zt,{className:"max-w-xl",children:[me,Ye,pt]}),e[154]=me,e[155]=Ye,e[156]=pt,e[157]=Ct):Ct=e[157];let Xe;return e[158]!==n||e[159]!==a||e[160]!==Ct?(Xe=s.jsx(Kt,{open:a,onOpenChange:n,children:Ct}),e[158]=n,e[159]=a,e[160]=Ct,e[161]=Xe):Xe=e[161],Xe};function Um(t){return t.scanRepo}function _m(t){return t.loadCatalog}function $m(t){return t.loadSource}function Vm(t){return t.setSelectedSource}function Bm(t){return t.isScanning}function Hm(t){return t.defaultGitIdentityId}function Gm(t){return t.loadDefaultGitIdentityId}function qm(t){return s.jsx(ot,{value:t.id,children:t.name},t.id)}const Wm=t=>{const e=ut.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=it();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p={},e[0]=p):p=e[0];const[m,f]=o.useState(p);let d,y;e[1]!==i||e[2]!==a?(d=()=>{if(!a)return;const Z={};for(const ee of i)Z[ee.skillName]="skip";f(Z)},y=[a,i],e[1]=i,e[2]=a,e[3]=d,e[4]=y):(d=e[3],y=e[4]),o.useEffect(d,y);let c;e[5]!==i?(c=Z=>{const ee={};for(const ge of i)ee[ge.skillName]=Z;f(ee)},e[5]=i,e[6]=c):c=e[6];const N=c;let b;e[7]!==i||e[8]!==m?(b=i.length>0&&i.every(Z=>m[Z.skillName]),e[7]=i,e[8]=m,e[9]=b):b=e[9];const C=b;let v;e[10]!==l?(v=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=v):v=e[11];let S;e[12]!==v?(S=s.jsx($t,{children:v}),e[12]=v,e[13]=S):S=e[13];let g;e[14]!==l?(g=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=g):g=e[15];let E;e[16]!==g?(E=s.jsx(Vt,{children:g}),e[16]=g,e[17]=E):E=e[17];let M;e[18]!==S||e[19]!==E?(M=s.jsxs(_t,{children:[S,E]}),e[18]=S,e[19]=E,e[20]=M):M=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 w;e[24]!==A?(w=s.jsx("span",{className:"typography-meta text-muted-foreground",children:A}),e[24]=A,e[25]=w):w=e[25];let h;e[26]!==N?(h=()=>N("skip"),e[26]=N,e[27]=h):h=e[27];let j;e[28]!==l?(j=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=j):j=e[29];let L;e[30]!==h||e[31]!==j?(L=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:h,children:j}),e[30]=h,e[31]=j,e[32]=L):L=e[32];let T;e[33]!==N?(T=()=>N("overwrite"),e[33]=N,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 I;e[37]!==T||e[38]!==P?(I=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:T,children:P}),e[37]=T,e[38]=P,e[39]=I):I=e[39];let K;e[40]!==L||e[41]!==I?(K=s.jsxs("div",{className:"flex items-center gap-2",children:[L,I]}),e[40]=L,e[41]=I,e[42]=K):K=e[42];let W;e[43]!==w||e[44]!==K?(W=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w,K]}),e[43]=w,e[44]=K,e[45]=W):W=e[45];let k;if(e[46]!==i||e[47]!==m||e[48]!==l){let Z;e[50]!==m||e[51]!==l?(Z=ee=>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:ee.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:ee.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:ee.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Pt,{value:m[ee.skillName]||"skip",onValueChange:ge=>f(de=>({...de,[ee.skillName]:ge})),children:[s.jsx(It,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(m[ee.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(ot,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},ee.skillName),e[50]=m,e[51]=l,e[52]=Z):Z=e[52],k=i.map(Z),e[46]=i,e[47]=m,e[48]=l,e[49]=k}else k=e[49];let F;e[53]!==k?(F=s.jsx("div",{className:"space-y-2",children:k}),e[53]=k,e[54]=F):F=e[54];let q;e[55]!==W||e[56]!==F?(q=s.jsxs("div",{className:"space-y-3",children:[W,F]}),e[55]=W,e[56]=F,e[57]=q):q=e[57];let U;e[58]!==n?(U=()=>n(!1),e[58]=n,e[59]=U):U=e[59];let Q;e[60]!==l?(Q=l("settings.common.actions.cancel"),e[60]=l,e[61]=Q):Q=e[61];let ne;e[62]!==U||e[63]!==Q?(ne=s.jsx(B,{size:"sm",variant:"ghost",onClick:U,children:Q}),e[62]=U,e[63]=Q,e[64]=ne):ne=e[64];let _;e[65]!==m||e[66]!==r?(_=()=>r(m),e[65]=m,e[66]=r,e[67]=_):_=e[67];const re=!C;let V;e[68]!==l?(V=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=V):V=e[69];let $;e[70]!==_||e[71]!==re||e[72]!==V?($=s.jsx(B,{size:"sm",onClick:_,disabled:re,children:V}),e[70]=_,e[71]=re,e[72]=V,e[73]=$):$=e[73];let z;e[74]!==ne||e[75]!==$?(z=s.jsxs(ns,{children:[ne,$]}),e[74]=ne,e[75]=$,e[76]=z):z=e[76];let O;e[77]!==M||e[78]!==q||e[79]!==z?(O=s.jsxs(zt,{className:"max-w-2xl",children:[M,q,z]}),e[77]=M,e[78]=q,e[79]=z,e[80]=O):O=e[80];let Y;return e[81]!==n||e[82]!==a||e[83]!==O?(Y=s.jsx(Kt,{open:a,onOpenChange:n,children:O}),e[81]=n,e[82]=a,e[83]=O,e[84]=Y):Y=e[84],Y},fr=[{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 Ka(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 Ol(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=fr.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const Jm=t=>{const e=ut.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=it(),l=hn(Qm),p=hn(Ym),[m,f]=o.useState("user"),[d,y]=o.useState("opencode"),c=Vs(Zm),N=Vs(Xm),[b,C]=o.useState(null),[v,S]=o.useState(!1);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[E,M]=o.useState(g),[A,w]=o.useState(null);let h,j;e[1]!==N||e[2]!==a?(h=()=>{a&&(f("user"),y("opencode"),C(N),S(!1),M([]),w(null))},j=[a,N],e[1]=N,e[2]=a,e[3]=h,e[4]=j):(h=e[3],j=e[4]),o.useEffect(h,j);let L;e[5]!==r?(L=je=>{switch(je){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]=L):L=e[6];const T=L;let P;e[7]!==r?(P=je=>{switch(je){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 I=P;let K;e:{if(c.length===0){K=null;break e}if(b&&c.some(je=>je.id===b)){K=b;break e}if(N&&c.some(je=>je.id===N)){K=N;break e}K=c[0]?.id??null}const W=K;let k;e:{if(m!=="project"){k=null;break e}const je=W;if(!je){k=null;break e}let Ge;if(e[9]!==je||e[10]!==c){let Ce;e[12]!==je?(Ce=Me=>Me.id===je,e[12]=je,e[13]=Ce):Ce=e[13],Ge=c.find(Ce),e[9]=je,e[10]=c,e[11]=Ge}else Ge=e[11];k=Ge?.path??null}const F=k;let q;e[14]!==l||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==r?(q=async je=>{const Ge=await l({source:je.source,subpath:je.subpath,gitIdentityId:i?.gitIdentityId,scope:je.scope,targetSource:je.targetSource,selections:[{skillDir:je.skillDir}],conflictPolicy:"prompt",conflictDecisions:je.conflictDecisions},{directory:je.directoryOverride??null});if(Ge.ok){D.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(Ge.error?.kind==="conflicts"){w({source:je.source,subpath:je.subpath,scope:je.scope,targetSource:je.targetSource,skillDir:je.skillDir,directoryOverride:je.directoryOverride??null}),M(Ge.error.conflicts),S(!0);return}if(Ge.error?.kind==="authRequired"){D.error(Ge.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}D.error(Ge.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i?.gitIdentityId,e[16]=n,e[17]=r,e[18]=q):q=e[18];const U=q;if(!i)return null;let Q;e[19]!==r?(Q=r("settings.skills.catalog.installSkill.title"),e[19]=r,e[20]=Q):Q=e[20];let ne;e[21]!==Q?(ne=s.jsx($t,{children:Q}),e[21]=Q,e[22]=ne):ne=e[22];let _;e[23]!==r?(_=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=_):_=e[24];let re;e[25]!==i.skillName?(re=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=re):re=e[26];let V;e[27]!==r?(V=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=V):V=e[28];let $;e[29]!==_||e[30]!==re||e[31]!==V?($=s.jsxs(Vt,{children:[_," ",re," ",V]}),e[29]=_,e[30]=re,e[31]=V,e[32]=$):$=e[32];let z;e[33]!==ne||e[34]!==$?(z=s.jsxs(_t,{children:[ne,$]}),e[33]=ne,e[34]=$,e[35]=z):z=e[35];let O;e[36]!==r?(O=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=O):O=e[37];let Y;e[38]!==O?(Y=s.jsx("span",{className:"typography-ui-label text-foreground",children:O}),e[38]=O,e[39]=Y):Y=e[39];let Z;e[40]!==m||e[41]!==d?(Z=Ka(m,d),e[40]=m,e[41]=d,e[42]=Z):Z=e[42];let ee;e[43]===Symbol.for("react.memo_cache_sentinel")?(ee=je=>{const Ge=Ol(je);f(Ge.scope),y(Ge.source==="agents"?"agents":"opencode")},e[43]=ee):ee=e[43];let ge;e[44]!==m?(ge=m==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=m,e[45]=ge):ge=e[45];let de;e[46]!==d?(de=d==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=d,e[47]=de):de=e[47];let xe;e[48]!==T||e[49]!==m||e[50]!==d?(xe=T(Ka(m,d)),e[48]=T,e[49]=m,e[50]=d,e[51]=xe):xe=e[51];let ae;e[52]!==xe?(ae=s.jsx("span",{children:xe}),e[52]=xe,e[53]=ae):ae=e[53];let te;e[54]!==ge||e[55]!==de||e[56]!==ae?(te=s.jsxs(It,{className:"w-fit gap-1.5",children:[ge,de,ae]}),e[54]=ge,e[55]=de,e[56]=ae,e[57]=te):te=e[57];let me;e[58]!==I||e[59]!==T?(me=fr.map(je=>s.jsx(ot,{value:je.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:[je.scope==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),je.source==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:T(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:I(je.value)})]})},je.value)),e[58]=I,e[59]=T,e[60]=me):me=e[60];let Pe;e[61]!==me?(Pe=s.jsx(At,{align:"start",children:me}),e[61]=me,e[62]=Pe):Pe=e[62];let Ne;e[63]!==Z||e[64]!==te||e[65]!==Pe?(Ne=s.jsxs(Pt,{value:Z,onValueChange:ee,children:[te,Pe]}),e[63]=Z,e[64]=te,e[65]=Pe,e[66]=Ne):Ne=e[66];let Se;e[67]!==Y||e[68]!==Ne?(Se=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Y,Ne]}),e[67]=Y,e[68]=Ne,e[69]=Se):Se=e[69];let be;e[70]!==c||e[71]!==W||e[72]!==m||e[73]!==r?(be=m==="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")}),c.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Pt,{value:W??"",onValueChange:je=>C(je),disabled:c.length===1,children:[s.jsx(It,{className:"w-fit",children:s.jsx(Rt,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(At,{align:"start",children:c.map(eu)})]})]}),e[70]=c,e[71]=W,e[72]=m,e[73]=r,e[74]=be):be=e[74];let Fe;e[75]!==i.warnings?(Fe=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]=Fe):Fe=e[76];let Le;e[77]!==Se||e[78]!==be||e[79]!==Fe?(Le=s.jsxs("div",{className:"mt-2 space-y-3",children:[Se,be,Fe]}),e[77]=Se,e[78]=be,e[79]=Fe,e[80]=Le):Le=e[80];let oe;e[81]!==n?(oe=()=>n(!1),e[81]=n,e[82]=oe):oe=e[82];let fe;e[83]!==r?(fe=r("settings.common.actions.cancel"),e[83]=r,e[84]=fe):fe=e[84];let De;e[85]!==oe||e[86]!==fe?(De=s.jsx(B,{size:"sm",variant:"ghost",onClick:oe,children:fe}),e[85]=oe,e[86]=fe,e[87]=De):De=e[87];const $e=p||!i.installable||m==="project"&&!F;let Ve;e[88]!==F||e[89]!==U||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==m||e[94]!==d?(Ve=()=>{U({source:i.repoSource,subpath:i.repoSubpath,scope:m,targetSource:d,skillDir:i.skillDir,directoryOverride:F})},e[88]=F,e[89]=U,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=m,e[94]=d,e[95]=Ve):Ve=e[95];let qe;e[96]!==p||e[97]!==r?(qe=r(p?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=p,e[97]=r,e[98]=qe):qe=e[98];let se;e[99]!==$e||e[100]!==Ve||e[101]!==qe?(se=s.jsx(B,{size:"sm",disabled:$e,onClick:Ve,children:qe}),e[99]=$e,e[100]=Ve,e[101]=qe,e[102]=se):se=e[102];let ie;e[103]!==De||e[104]!==se?(ie=s.jsxs(ns,{children:[De,se]}),e[103]=De,e[104]=se,e[105]=ie):ie=e[105];let we;e[106]!==z||e[107]!==Le||e[108]!==ie?(we=s.jsxs(zt,{className:"max-w-md",children:[z,Le,ie]}),e[106]=z,e[107]=Le,e[108]=ie,e[109]=we):we=e[109];let ye;e[110]!==n||e[111]!==a||e[112]!==we?(ye=s.jsx(Kt,{open:a,onOpenChange:n,children:we}),e[110]=n,e[111]=a,e[112]=we,e[113]=ye):ye=e[113];let Te;e[114]!==A||e[115]!==U?(Te=je=>{A&&(U({source:A.source,subpath:A.subpath,scope:A.scope,targetSource:A.targetSource,skillDir:A.skillDir,conflictDecisions:je,directoryOverride:A.directoryOverride??null}),S(!1))},e[114]=A,e[115]=U,e[116]=Te):Te=e[116];let Ue;e[117]!==E||e[118]!==v||e[119]!==Te?(Ue=s.jsx(Wm,{open:v,onOpenChange:S,conflicts:E,onConfirm:Te}),e[117]=E,e[118]=v,e[119]=Te,e[120]=Ue):Ue=e[120];let Ie;return e[121]!==ye||e[122]!==Ue?(Ie=s.jsxs(s.Fragment,{children:[ye,Ue]}),e[121]=ye,e[122]=Ue,e[123]=Ie):Ie=e[123],Ie};function Qm(t){return t.installSkills}function Ym(t){return t.isInstalling}function Zm(t){return t.projects}function Xm(t){return t.activeProjectId}function eu(t){return s.jsx(ot,{value:t.id,children:t.label||t.path},t.id)}const tu=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,su=t=>{const e=t.trim();return tu.test(e)?`https://github.com/${e}`:null},nu=t=>{const e=su(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let si=null;const au=t=>{const e=ur();return(!si||si.locale!==e)&&(si={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),si.formatter.format(t)},iu=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)}},ru=async()=>{try{const t=tn()?.settings;if(t)return(await t.load())?.settings||{};const e=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},ou=t=>{const e=ut.c(50),{source:a,isActive:n,isLoading:i,skillsCount:r,onSelect:l,t:p}=t,m=a.stars??null;let f,d,y,c,N,b,C,v,S,g;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]!==m||e[8]!==p){const w=a.repoUpdatedAt?iu(a.repoUpdatedAt):null;v="button",S=l,g=n;const h=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==h?(d=ve("w-full min-h-24 text-left rounded-lg border bg-[var(--surface-elevated)] p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",h),e[19]=h,e[20]=d):d=e[20],N="min-w-0 flex-1 block";let j;e[21]!==a.label?(j=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=j):j=e[22];let L;e[23]!==i||e[24]!==r||e[25]!==p?(L=i?s.jsx(R,{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:p("settings.skills.catalog.page.source.skillsCount",{count:r})}),e[23]=i,e[24]=r,e[25]=p,e[26]=L):L=e[26],e[27]!==j||e[28]!==L?(b=s.jsxs("span",{className:"flex items-center gap-2",children:[j,L]}),e[27]=j,e[28]=L,e[29]=b):b=e[29],e[30]!==a.source?(C=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]=C):C=e[31],f="flex items-center gap-3 mt-1",e[32]!==m||e[33]!==p?(y=m!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:p("settings.skills.catalog.page.source.stars",{count:m}),children:[s.jsx(R,{name:"star",className:"h-3 w-3"}),au(m)]}),e[32]=m,e[33]=p,e[34]=y):y=e[34],c=w&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:w.key==="common.relative.justNow"?p(w.key):p("settings.skills.catalog.page.source.updated",{time:p(w.key,{count:w.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]=m,e[8]=p,e[9]=f,e[10]=d,e[11]=y,e[12]=c,e[13]=N,e[14]=b,e[15]=C,e[16]=v,e[17]=S,e[18]=g}else f=e[9],d=e[10],y=e[11],c=e[12],N=e[13],b=e[14],C=e[15],v=e[16],S=e[17],g=e[18];let E;e[35]!==f||e[36]!==y||e[37]!==c?(E=s.jsxs("span",{className:f,children:[y,c]}),e[35]=f,e[36]=y,e[37]=c,e[38]=E):E=e[38];let M;e[39]!==E||e[40]!==N||e[41]!==b||e[42]!==C?(M=s.jsxs("span",{className:N,children:[b,C,E]}),e[39]=E,e[40]=N,e[41]=b,e[42]=C,e[43]=M):M=e[43];let A;return e[44]!==d||e[45]!==M||e[46]!==v||e[47]!==S||e[48]!==g?(A=s.jsx("button",{type:v,onClick:S,"aria-pressed":g,className:d,children:M}),e[44]=d,e[45]=M,e[46]=v,e[47]=S,e[48]=g,e[49]=A):A=e[49],A},lu=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=it(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:p,loadCatalog:m,loadSource:f,isLoadingCatalog:d,isLoadingSource:y,loadedSourceIds:c,lastCatalogError:N}=hn(Ls(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}))),[b,C]=o.useState(""),[v,S]=o.useState(!1),[g,E]=o.useState(!1),[M,A]=o.useState(null),[w,h]=o.useState(!1),[j,L]=o.useState(!1),T=o.useRef(null);o.useEffect(()=>{m()},[m]),o.useEffect(()=>{const U=i.filter(_=>!c[_.id]);if(U.length===0)return;let Q=!1;return(async()=>{for(const _ of U){if(Q)return;await f(_.id)}})(),()=>{Q=!0}},[i,c,f]),o.useEffect(()=>{!l||c[l]||f(l)},[l,c,f]),o.useEffect(()=>{const U=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key.toLowerCase()==="k"&&(Q.preventDefault(),T.current?.focus())};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[]);const P=b.trim().length>0,I=o.useMemo(()=>P?gi(i.flatMap(U=>r[U.id]||[]),b,U=>[U.skillName,U.frontmatterName,U.description]):l?r[l]||[]:[],[i,r,l,b,P]),K=o.useMemo(()=>i.find(U=>U.id===l)||null,[i,l]),W=!!(l&&l.startsWith("custom:")),k=async()=>{if(!(!l||!W)){h(!0);try{const U=await ru(),ne=(Array.isArray(U?.skillCatalogs)?U?.skillCatalogs:[]).filter(_=>_.id!==l);await vt({skillCatalogs:ne}),await m({refresh:!0}),L(!1)}finally{h(!1)}}},F=P?n("settings.skills.catalog.page.list.searchTitle"):K?.label??"",q=!P&&l!==null&&!c[l]&&(y||d);return s.jsxs(s.Fragment,{children:[s.jsxs(ss,{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(hr,{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(R,{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(Je,{ref:T,value:b,onChange:U=>C(U.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:ve("h-8 pl-8 w-full",b&&"pr-8")}),b&&s.jsx("button",{type:"button",onClick:()=>{C(""),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(R,{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(ou,{source:U,isActive:U.id===l,isLoading:y&&!c[U.id],skillsCount:c[U.id]?(r[U.id]||[]).length:null,onSelect:()=>p(U.id),t:n},U.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>S(!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(R,{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")})]})]})]})}),N&&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:N.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:F}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:I.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!P?f(l,{refresh:!0}):m({refresh:!0})},disabled:d||y,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(R,{name:"refresh",className:ve("h-3.5 w-3.5",(d||y)&&"animate-spin")})}),W&&!P&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>L(!0),disabled:w,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),q||y&&I.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(R,{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")})]}):I.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:I.map(U=>{const Q=U.installed?.isInstalled,ne=U.installed?.scope,_=nu(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}),Q&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:ne||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:[_?s.jsxs("a",{href:_,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(R,{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:[_&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(_,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"})}),Q?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:ne||""}),children:s.jsx(R,{name:"check",className:"h-4 w-4"})}):s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",disabled:!U.installable,onClick:()=>{A(U),E(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${U.sourceId}:${U.skillDir}`)})})]})]}),s.jsx(zm,{open:v,onOpenChange:S}),s.jsx(Jm,{open:g,onOpenChange:E,item:M}),s.jsx(Kt,{open:j,onOpenChange:U=>{w||L(U)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Vt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>L(!1),disabled:w,children:n("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{k()},disabled:w,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},cu=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(lu,{mode:"external",onModeChange:hu,showModeTabs:!1}),t[0]=e):e=t[0],e},du="SKILL.md",pu="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",pi=(t,e)=>{const a=Fd({description:t}).trimEnd(),n=e.trimStart();return`---
22
- ${a}
23
- ---${n?`
24
-
25
- ${n}`:`
26
- `}`},mu=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ll=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=Kd(e[1]);if(mu(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},uu=(t,e)=>{const a=Ll(t);return pi(e,a.instructions)},gu=()=>{const{t}=it(),{currentTheme:e}=gr(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skillDraft:p,setSkillDraft:m,setSelectedSkill:f}=$s(Ls(ue=>({selectedSkillName:ue.selectedSkillName,getSkillByName:ue.getSkillByName,getSkillDetail:ue.getSkillDetail,createSkill:ue.createSkill,updateSkill:ue.updateSkill,skillDraft:ue.skillDraft,setSkillDraft:ue.setSkillDraft,setSelectedSkill:ue.setSelectedSkill}))),d=Us(),y=$s(ue=>cr(ue,d)),c=a?n(a,d):null,N=!!(p&&p.name===a&&!c),b=!!(a&&!c&&!p),C=c?.path==="<built-in>";o.useEffect(()=>{b&&f(null)},[b,f]);const[v,S]=o.useState(""),[g,E]=o.useState("user"),[M,A]=o.useState("opencode"),[w,h]=o.useState(""),[j,L]=o.useState(""),[T,P]=o.useState(()=>pi("","")),[I,K]=o.useState("edit"),[W,k]=o.useState([]),[F,q]=o.useState([]),[U,Q]=o.useState(!1),[ne,_]=o.useState(!1),[re,V]=o.useState(""),[$,z]=o.useState(""),[O,Y]=o.useState(!1),[Z,ee]=o.useState(""),[ge,de]=o.useState(""),[xe,ae]=o.useState(null),[te,me]=o.useState(!1),[Pe,Ne]=o.useState(""),[Se,be]=o.useState(null),[Fe,Le]=o.useState(!1),oe=N?v.trim()!==""||w.trim()!==""||j.trim()!==""||F.length>0:w!==re||j!==$,fe=xe?ge!==Pe:Z.trim()!=="",De=o.useCallback(ue=>{switch(ue){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]),$e=o.useCallback(ue=>{switch(ue){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(N&&p){const Ce=p.description||"",Me=p.instructions||"";S(p.name||""),E(p.scope||"user"),A(p.source==="agents"?"agents":"opencode"),h(Ce),L(Me),P(pi(Ce,Me)),V(""),z(""),k([]),q(p.pendingFiles||[])}else if(a&&c){_(!0);try{const Ce=await i(a,d);if(Ce){const Me=Ce.sources.md,Ye=Me.description||"",G=Me.instructions||"";h(Ye),L(G),P(pi(Ye,G)),V(Ye),z(G),k(Me.supportingFiles||[])}}catch(Ce){console.error("Failed to load skill details:",Ce)}finally{_(!1)}}})()},[c,N,a,d,y,p,i]);const Ve=ce(ue=>ue.editorFontSize),qe=o.useMemo(()=>{const ue=[Gr(e,{fontSize:Ve})],Ce=Pr(du);return Ce&&ue.push(Ce),ue.push(Wr.lineWrapping),ue},[e,Ve]),se=o.useMemo(()=>{const ue=Z.trim()||"supporting-file.md",Ce=gc(ue),Me=!!Ce&&Ce!=="markdown",Ye=[Gr(e,Me?{syntaxColors:!1,fontSize:Ve}:{fontSize:Ve})],G=Pr(ue);return G&&Ye.push(G),Me&&Ce&&Ye.push(zd({language:Ce,themeName:e.metadata.id,theme:_d(e)})),Ye.push(Wr.lineWrapping),Ye},[e,Z,Ve]),ie=o.useCallback(ue=>{h(ue),P(Ce=>uu(Ce,ue))},[]),we=o.useCallback(ue=>{P(ue);const Ce=Ll(ue);h(Ce.description??""),L(Ce.instructions)},[]),ye=async()=>{const ue=N?v.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!ue){D.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ue)||ue.length>64){D.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!w.trim()){D.error(t("settings.skills.page.toast.descriptionRequired"));return}if(N&&y.some(Ce=>Ce.name===ue)){D.error(t("settings.skills.page.toast.skillExists"));return}Q(!0);try{const Ce={name:ue,description:w.trim(),instructions:j.trim()||void 0,scope:N?g:void 0,source:N?M:void 0,targetPath:N?void 0:c?.path,supportingFiles:N&&F.length>0?F:void 0};let Me;if(N?(Me=await r(Ce,d),Me&&(m(null),q([]),f(ue))):(Me=await l(ue,Ce,d),Me&&(V(w.trim()),z(j.trim()))),Me){const Ye=$n.getState().changes.some(G=>G.scope==="skills"&&G.id.startsWith(`skills:${ue}:`));D.success(t(Ye?"settings.view.pendingRestart.saved":N?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else D.error(t(N?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Ce){console.error("Error saving skill:",Ce),D.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{Q(!1)}},Te=()=>{ae(null),ee(""),de(""),Ne(""),Y(!0)},Ue=async ue=>{if(ae(ue),ee(ue),N){const Me=F.find(Ye=>Ye.path===ue)?.content||"";de(Me),Ne(Me),Y(!0);return}if(a){me(!0),Y(!0);try{const{readSupportingFile:Ce}=$s.getState(),Me=await Ce(a,ue,d);de(Me||""),Ne(Me||"")}catch{D.error(t("settings.skills.page.toast.loadFileContentFailed")),de(""),Ne("")}finally{me(!1)}}},Ie=async()=>{if(!Z.trim()){D.error(t("settings.skills.page.toast.fileNameRequired"));return}const ue=Z.trim(),Ce=xe!==null;if(N){if(Ce)q(G=>G.map(ke=>ke.path===xe?{path:ue,content:ge}:ke)),D.success(t("settings.skills.page.toast.fileUpdated",{path:ue}));else{if(F.some(G=>G.path===ue)){D.error(t("settings.skills.page.toast.fileExists"));return}q(G=>[...G,{path:ue,content:ge}]),D.success(t("settings.skills.page.toast.fileAdded",{path:ue}))}Y(!1),ae(null);return}if(!a){D.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Me}=$s.getState();if(await Me(a,ue,ge,d)){D.success(Ce?t("settings.skills.page.toast.fileUpdated",{path:ue}):t("settings.skills.page.toast.fileCreated",{path:ue})),Y(!1),ae(null);const G=await i(a,d);G&&k(G.sources.md.supportingFiles||[])}else D.error(t(Ce?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},je=ue=>{if(N){q(Ce=>Ce.filter(Me=>Me.path!==ue)),D.success(t("settings.skills.page.toast.fileRemoved",{path:ue}));return}a&&be(ue)},Ge=async()=>{if(!Se||!a)return;Le(!0);const{deleteSupportingFile:ue}=$s.getState();if(await ue(a,Se,d)){D.success(t("settings.skills.page.toast.fileDeleted",{path:Se}));const Me=await i(a,d);Me&&k(Me.sources.md.supportingFiles||[]),be(null)}else D.error(t("settings.skills.page.toast.deleteFileFailed"));Le(!1)};return!a&&!p||b?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(R,{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")})]})}):ne?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(ss,{title:N?t("settings.skills.page.title.newSkill"):a,description:c?t("settings.skills.page.subtitle.skillLocation",{location:De(Ka(c.scope,c.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:[N&&s.jsxs(Ot,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(Je,{value:v,onChange:ue=>S(ue.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Pt,{value:Ka(g,M),onValueChange:ue=>{const Ce=Ol(ue);E(Ce.scope),A(Ce.source==="agents"?"agents":"opencode")},children:[s.jsxs(It,{size:Lt,className:"w-fit gap-1.5",children:[g==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),M==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:De(Ka(g,M))})]}),s.jsx(At,{align:"start",children:fr.map(ue=>s.jsx(ot,{value:ue.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ue.scope==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),ue.source==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:De(ue.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:$e(ue.value)})]})},ue.value))})]})]}),s.jsx(Wt,{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(Is,{value:w,onChange:ue=>ie(ue.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:C})})]}),s.jsx(_e,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(Ud,{currentMode:I==="preview"?"preview":"edit",onToggle:()=>K(ue=>ue==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:ve("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",pu),children:I==="preview"?s.jsx(Bs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(hc,{content:T,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(qr,{value:T,onChange:we,readOnly:C,extensions:qe,className:"h-full",enableSearch:!0})})}),s.jsx(_e,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Te,disabled:C,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const ue=N?F:W;return ue.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:ue.map(Ce=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Ue(Ce.path),children:[s.jsx(R,{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:Ce.path}),N&&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")}),!C&&s.jsx(B,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:Me=>{Me.stopPropagation(),je(Ce.path)},children:s.jsx(R,{name:"delete-bin",className:"h-3 w-3"})})]},Ce.path))})})()}),s.jsx(_e,{children:s.jsx(B,{onClick:ye,disabled:C||U||!oe,size:"xs",className:"!font-normal",children:t(U?"settings.common.actions.saving":N?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Kt,{open:Se!==null,onOpenChange:ue=>{!ue&&!Fe&&be(null)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Vt,{children:t("settings.skills.page.deleteFileDialog.description",{path:Se??""})})]}),s.jsxs(ns,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>be(null),disabled:Fe,children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:Ge,disabled:Fe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Kt,{open:O,onOpenChange:ue=>{Y(ue),ue||ae(null)},children:s.jsxs(zt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(_t,{className:"flex-shrink-0",children:[s.jsx($t,{children:t(xe?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Vt,{children:t(xe?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),te?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:Et,children:t("settings.skills.page.fileDialog.field.filePath")}),!xe&&s.jsx(Jt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(Je,{value:Z,onChange:ue=>ee(ue.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:xe!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Et} 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(qr,{value:ge,onChange:de,extensions:se,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(ns,{className:"mt-4",children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{Y(!1),ae(null)},children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:Ie,disabled:te||!fe,children:t(xe?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},po=t=>{const e=ut.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(cu,{}):s.jsx(gu,{}),e[0]=n,e[1]=i):i=e[1],i};function hu(){}const fu=t=>{const e=ut.c(38),{onItemSelect:a}=t,{t:n}=it(),i=Vs(xu),r=ce(bu),l=ce(vu),{currentTheme:p}=gr();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=ds(),e[0]=m):m=e[0];const f=m,d=yu;let y,c;e[1]!==i||e[2]!==r||e[3]!==l?(y=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(h=>h.id===r)||l(i[0].id)},c=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=y,e[5]=c):(y=e[4],c=e[5]),o.useEffect(y,c);let N;e[6]===Symbol.for("react.memo_cache_sentinel")?(N=ve("border-b px-3","pt-4 pb-3"),e[6]=N):N=e[6];let b;e[7]!==n?(b=n("settings.page.projects.title"),e[7]=n,e[8]=b):b=e[8];let C;e[9]!==b?(C=s.jsx("h2",{className:`${on} mb-3`,children:b}),e[9]=b,e[10]=C):C=e[10];let v;e[11]!==i.length||e[12]!==n?(v=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=v):v=e[13];let S;e[14]!==v?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:v}),e[14]=v,e[15]=S):S=e[15];let g;e[16]!==n?(g=!f&&s.jsx(B,{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(R,{name:"add",className:"size-4"})}),e[16]=n,e[17]=g):g=e[17];let E;e[18]!==S||e[19]!==g?(E=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,g]}),e[18]=S,e[19]=g,e[20]=E):E=e[20];let M;e[21]!==E||e[22]!==C?(M=s.jsxs("div",{className:N,children:[C,E]}),e[21]=E,e[22]=C,e[23]=M):M=e[23];let A;if(e[24]!==p||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let h;e[30]!==p||e[31]!==a||e[32]!==r||e[33]!==l?(h=j=>{const L=j.id===r,T=j.icon?xc[j.icon]:null,P=j.color?bc[j.color]??null:null,I=T?s.jsx(R,{name:T,className:ve("h-4 w-4",L?"text-foreground":"text-muted-foreground/70"),style:P?{color:P}:void 0}):s.jsx(R,{name:"folder",className:ve("h-4 w-4",L?"text-foreground":"text-muted-foreground/70"),style:P?{color:P}:void 0}),K=j.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:j.iconBackground?{backgroundColor:j.iconBackground}:void 0,children:s.jsx(vc,{project:j,options:{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground},className:"h-full w-full object-contain",fallback:I})}):I;return s.jsx(sr,{title:j.label||j.path,icon:K,selected:L,onSelect:()=>{l(j.id),a?.()}},j.id)},e[30]=p,e[31]=a,e[32]=r,e[33]=l,e[34]=h):h=e[34],A=i.map(h),e[24]=p,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=A}else A=e[29];let w;return e[35]!==M||e[36]!==A?(w=s.jsx(Ml,{variant:"background",header:M,children:A}),e[35]=M,e[36]=A,e[37]=w):w=e[37],w};function xu(t){return t.projects}function bu(t){return t.settingsProjectsSelectedId}function vu(t){return t.setSettingsProjectsSelectedId}function yu(){fc.requestDirectoryDialog()}const ju=()=>{const t=ut.c(30),{t:e}=it(),a=Vs(wu),n=Vs(ku),i=ce(Nu),r=ce(Su);let l;e:{if(!i){l=null;break e}let v;t[0]!==a||t[1]!==i?(v=a.find(S=>S.id===i)??null,t[0]=a,t[1]=i,t[2]=v):v=t[2],l=v}const p=l;let m,f;t[3]!==a||t[4]!==i||t[5]!==r?(m=()=>{if(a.length===0){r(null);return}i&&a.some(v=>v.id===i)||r(a[0].id)},f=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=m,t[7]=f):(m=t[6],f=t[7]),o.useEffect(m,f);let d;t[8]!==p||t[9]!==n?(d=async v=>{p&&n(p.id,{label:v.label,icon:v.icon,color:v.color,iconBackground:v.iconBackground,defaultModel:v.defaultModel??null,defaultVariant:v.defaultVariant??null})},t[8]=p,t[9]=n,t[10]=d):d=t[10];const y=d;if(!p){let v;t[11]!==e?(v=e("settings.page.projects.title"),t[11]=e,t[12]=v):v=t[12];let S;t[13]!==e?(S=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=S):S=t[14];let g;t[15]!==S?(g=s.jsx("p",{className:"typography-meta text-muted-foreground",children:S}),t[15]=S,t[16]=g):g=t[16];let E;return t[17]!==v||t[18]!==g?(E=s.jsx(ss,{title:v,showSaveStatus:!0,children:g}),t[17]=v,t[18]=g,t[19]=E):E=t[19],E}let c;t[20]!==p.label||t[21]!==e?(c=p.label??e("settings.projects.page.title.default"),t[20]=p.label,t[21]=e,t[22]=c):c=t[22];const N=c;let b;t[23]!==y||t[24]!==p?(b=s.jsx(Ed,{project:p,onIdentitySave:y}),t[23]=y,t[24]=p,t[25]=b):b=t[25];let C;return t[26]!==N||t[27]!==p.path||t[28]!==b?(C=s.jsx(ss,{title:N,description:p.path,showSaveStatus:!0,outerClassName:"bg-background",children:b}),t[26]=N,t[27]=p.path,t[28]=b,t[29]=C):C=t[29],C};function wu(t){return t.projects}function ku(t){return t.updateProjectMeta}function Nu(t){return t.settingsProjectsSelectedId}function Su(t){return t.setSettingsProjectsSelectedId}const mi=()=>Math.floor(2e4+Math.random()*3e4),Cu=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")},Pu=()=>{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"},mo=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}},uo=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"}},Iu=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),xr=t=>!!(t&&Iu.has(t)),go=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||xr(t)?"connecting":"idle",ho=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"}},Au=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},fo={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Tu=t=>t==="noRuntime"?fo.noRuntime:t==="noOpencode"?fo.noOpencode:null,xo=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||xr(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Eu=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}`,Du=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:mi(),remoteHost:"127.0.0.1",remotePort:80}),Mu=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",_s=t=>{const e=ut.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(Jt,{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 ${Et}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},Ru=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"}},bo=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Ou=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Lu=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}`},ar=(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}),Fu=t=>t.trim().toLowerCase()==="authorization",_i=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!Fu(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},Ku=t=>Object.entries(t||{}).map(([e,a])=>ar(e,a)),Fl=()=>{if(typeof window>"u")return null;const e=_a()||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}},vo=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},zu=async()=>{const t=oa(_a())||window.location.origin;if(!rs()||!$a())return t;let e;try{e=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}})}catch{return t}if(!e.ok||(await e.json().catch(()=>null))?.desktopLanAccessActive!==!0)return t;const n=await vl(),i=Fl();return!n||!i?t:`http://${n}:${i}`},ni=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Uu=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}},_u=()=>{const{t}=it(),e=ce(x=>x.timeFormatPreference),{clientAuth:a}=pl(),n=rs(),i=Cs(x=>x.instances),r=Cs(x=>x.statusesById),l=Cs(x=>x.importCandidates),p=Cs(x=>x.isLoading),m=Cs(x=>x.isImportsLoading),f=Cs(x=>x.isSaving),d=Cs(x=>x.error),y=Cs(x=>x.load),c=Cs(x=>x.loadImports),N=Cs(x=>x.refreshStatuses),b=Cs(x=>x.upsertInstance),C=Cs(x=>x.createFromCommand),v=Cs(x=>x.removeInstance),S=Cs(x=>x.connect),g=Cs(x=>x.disconnect),E=Cs(x=>x.retry),M=ce(x=>x.settingsRemoteInstancesSelectedId),A=ce(x=>x.setSettingsRemoteInstancesSelectedId),w=o.useMemo(()=>M&&i.find(x=>x.id===M)||null,[i,M]),[h,j]=o.useState(null),[L,T]=o.useState(!1),[P,I]=o.useState(!1),[K,W]=o.useState(null),[k,F]=o.useState([]),[q,U]=o.useState(null),[Q,ne]=o.useState(""),[_,re]=o.useState(!1),[V,$]=o.useState({}),[z,O]=o.useState(!1),[Y,Z]=o.useState(!1),[ee,ge]=o.useState(()=>Date.now()),[de,xe]=o.useState([]),[ae,te]=o.useState({}),[me,Pe]=o.useState("local"),[Ne,Se]=o.useState(!1),[be,Fe]=o.useState(!1),[Le,oe]=o.useState(""),[fe,De]=o.useState(""),[$e,Ve]=o.useState(""),[qe,se]=o.useState([]),[ie,we]=o.useState(""),[ye,Te]=o.useState(null),[Ue,Ie]=o.useState(!1),[je,Ge]=o.useState(!1),[ue,Ce]=o.useState(null),[Me,Ye]=o.useState(""),[G,ke]=o.useState(""),[Ae,He]=o.useState(""),[at,nt]=o.useState([]),[dt,xt]=o.useState([]),[H,Be]=o.useState([]),[tt,rt]=o.useState(!1),[pt,Ct]=o.useState(""),[Xe,Ze]=o.useState(null),[ht,Ke]=o.useState(null),[wt,Ee]=o.useState(null),[jt,J]=o.useState(null),[he,ze]=o.useState(!1),[Re,ct]=o.useState(!1),[lt,Qe]=o.useState("configure"),[Nt,xs]=o.useState(!1),[es,Ds]=o.useState("relay"),[Bt,os]=o.useState(!0),[qt,bs]=o.useState(null),ps=o.useMemo(()=>dt.filter(x=>!!x.revokedAt).length,[dt]),[vs,ms]=o.useState(!1),[ys,le]=o.useState("saved"),[ft,yt]=o.useState(""),[Qt,Yt]=o.useState(""),[Ht,as]=o.useState(""),[js,ls]=o.useState(!1);o.useEffect(()=>{y(),c()},[y,c]);const St=o.useCallback(async()=>{Se(!0),Te(null);try{const x=await Lr();xe(x.hosts||[]),Pe(x.defaultHostId||"local")}catch(x){Te(x instanceof Error?x.message:String(x))}finally{Se(!1)}},[]);o.useEffect(()=>{St()},[St]);const Tt=o.useCallback(async(x,X=me)=>{Fe(!0),Te(null);try{await Fr({hosts:x,defaultHostId:X,initialHostChoiceCompleted:!0}),xe(x),Pe(X)}catch(Oe){Te(Oe instanceof Error?Oe.message:String(Oe))}finally{Fe(!1)}},[me]),Ut=o.useCallback(async()=>{const x=Kr(fe);if(!x){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const X=x.persistedUrl,st={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Le.trim()||Na(X),url:X,apiUrl:X,...$e.trim()?{clientToken:$e.trim()}:{},..._i(qe)?{requestHeaders:_i(qe)}:{}};await Tt([st,...de],me),oe(""),De(""),Ve(""),se([]),Ie(!1),x.redeemUrl&&ni(x.redeemUrl)},[me,qe,de,Le,$e,fe,Tt,t]),Mt=o.useCallback(async()=>{const x=ad(ie);if(!x){Te(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const X=await id().catch(()=>""),Oe=JSON.stringify({pairingId:x.pairingId,secret:x.secret,clientLabel:x.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Pu(),...X?{dedupeKey:`desktop:${X}`}:{}}),st={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Oe},Ft=async Dt=>{if(!Dt.ok)return null;const Ks=await Dt.json().catch(()=>null);return(typeof Ks?.clientToken=="string"?Ks.clientToken.trim():"")||null},Ts=[...x.candidates].sort((Dt,Ks)=>(Dt.type==="relay"?1:0)-(Ks.type==="relay"?1:0));let ks=null;for(const Dt of Ts){if(Dt.type==="relay"){const ja=rd({relayUrl:Dt.relayUrl,serverId:Dt.serverId,hostEncPubJwk:Dt.hostEncPubJwk,...Dt.grant?{grant:Dt.grant}:{}});try{const Ja=await ja.fetch("/api/client-auth/pairing/redeem",st),Sr=await Ft(Ja);if(Sr){ks={kind:"relay",relay:{relayUrl:Dt.relayUrl,serverId:Dt.serverId,hostEncPubJwk:Dt.hostEncPubJwk},token:Sr};break}}catch{}finally{ja.close()}continue}const Ks=oa(Dt.url);if(Ks)try{const ja=await fetch(`${Ks}/api/client-auth/pairing/redeem`,st),Ja=await Ft(ja);if(Ja){ks={kind:"direct",url:Ks,token:Ja};break}}catch{}}if(!ks){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const Ms=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,gs=x.candidates.find(Dt=>Dt.type==="relay"),u=ks.kind==="relay"?ks.relay:gs?{relayUrl:gs.relayUrl,serverId:gs.serverId,hostEncPubJwk:gs.hostEncPubJwk}:void 0,bt=x.candidates.filter(Dt=>Dt.type!=="relay").map(Dt=>oa(Dt.url)).find(Dt=>!!Dt),Zt=ks.kind==="direct"?ks.url:bt,{token:Xt}=ks,kt=Zt||(u?od(u.serverId):null);if(!kt){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const Gt={url:kt,apiUrl:Zt||void 0,clientToken:Xt,...u?{relay:u}:{}},Ys=de.find(Dt=>u?Dt.relay?.serverId===u.serverId:!Dt.relay&&oa(Dt.apiUrl||Dt.url)===kt);if(Ys){const Dt=de.map(Ks=>Ks.id===Ys.id?{...Ks,label:x.label||Ks.label,...Gt}:Ks);await Tt(Dt,me)}else await Tt([{id:Ms(),label:x.label||Na(kt),...Gt},...de],me);we(""),Te(null),Ge(!1)},[ie,me,de,Tt,t]),is=o.useCallback(async x=>{const X=de.filter(st=>st.id!==x);await Tt(X,me===x?"local":me),ue===x&&Ce(null)},[me,ue,de,Tt]),As=o.useCallback(x=>{Ce(x.id),Ye(x.label),ke(x.apiUrl||x.url),He(x.clientToken||""),nt(Ku(x.requestHeaders)),Te(null)},[]),yi=o.useCallback(async()=>{if(!ue)return;const x=Kr(G);if(!x){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const X=x.persistedUrl,Oe=de.map(st=>st.id===ue?{...st,label:Me.trim()||Na(X),url:X,apiUrl:X,clientToken:Ae.trim()||void 0,requestHeaders:_i(at)}:st);await Tt(Oe,me),Ce(null),x.redeemUrl&&ni(x.redeemUrl)},[me,at,Me,Ae,G,ue,de,Tt,t]),Ba=o.useCallback(async()=>{const x=Qt.trim();if(!x){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const X=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await C(X,x,Ht.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),A(X),ms(!1),Yt(""),as(""),D.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Oe){D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Oe instanceof Error?Oe.message:String(Oe)})}},[C,A,Qt,Ht,t]),ji=o.useCallback(()=>{yt(""),le(l.length>0?"saved":"manual"),ms(!0)},[l.length]),wi=o.useCallback(async x=>{await Tt(de,x)},[de,Tt]);o.useEffect(()=>{if(!n||de.length===0)return;let x=!1;return Promise.all(de.map(async X=>{const Oe=()=>ud(X.relay,{clientToken:X.clientToken||null,requestHeaders:X.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(X.relay&&!X.apiUrl)return[X.id,await Oe()];const st=oa(ld(X));if(!st)return[X.id,X.relay?await Oe():{status:"unreachable",latencyMs:0}];const Ft=await cd(st,{clientToken:X.clientToken||null,requestHeaders:X.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Ft.status==="unreachable"&&X.relay){const Ts=await Oe();if(Ts.status==="ok")return[X.id,Ts]}return[X.id,Ft]})).then(X=>{x||te(Object.fromEntries(X))}),()=>{x=!0}},[de,n]);const Fs=o.useCallback(async x=>{if(a){x?.silent||rt(!0),x?.silent||Ze(null);try{const[X,Oe]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);xt(X),Oe&&Be(Oe)}catch(X){x?.silent||Ze(X instanceof Error?X.message:String(X))}finally{x?.silent||rt(!1)}}},[a]),ga=o.useRef(!1);o.useEffect(()=>{if(!(!Re||lt!=="result"||!wt)){if(H.some(x=>x.id===wt)){ga.current=!0;return}ga.current&&(Ee(null),ct(!1),dt.some(x=>x.pairingId===wt)&&D.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Re,lt,wt,H,dt,t]);const ki=o.useCallback(async x=>{if(a)try{await a.cancelPairing(x),Be(X=>X.filter(Oe=>Oe.id!==x)),await Fs({silent:!0})}catch(X){Ze(X instanceof Error?X.message:String(X))}},[a,Fs]);o.useEffect(()=>{if(!a)return;Fs();const x=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Fs({silent:!0})},5e3);return()=>window.clearInterval(x)},[a,Fs]);const Ha=o.useCallback(async()=>{if(a?.getPairingTransports)try{const st=await a.getPairingTransports();return{localUrl:st.local,lanUrl:st.lan,relayAvailable:st.relayAvailable}}catch{}const x=Fl(),X=x?`http://127.0.0.1:${x}`:vo(window.location.origin)?window.location.origin:null;let Oe=null;try{const st=oa(await zu());Oe=st&&!vo(st)?st:null}catch{}return{localUrl:X,lanUrl:Oe,relayAvailable:!0}},[a]),Ni=o.useCallback(async()=>{Ze(null),Ke(null),J(null),ze(!1),Ee(null),Qe("configure"),os(!0),ct(!0);const x=await Ha();bs(x),Ds(x.relayAvailable?"relay":x.lanUrl?"lan":"local")},[Ha]),Si=o.useCallback(async()=>{if(!(!a?.createPairingSession||!qt)){Ze(null),xs(!0);try{const x=pt.trim()||void 0;let X,Oe,st=!0;es==="local"?(X=qt.localUrl??void 0,Oe=!1):es==="lan"?(X=qt.lanUrl??void 0,Oe=Bt):Bt&&qt.lanUrl?(X=qt.lanUrl,Oe=!0):(st=!1,Oe=!0);const{pairing:Ft,server:Ts}=await a.createPairingSession({label:x,allowedClientKinds:["mobile","desktop"],serverUrl:X,includeRelay:Oe,includeDirect:st}),ks=dd({pairingId:Ft.id,secret:Ft.secret,label:Ts.label,fingerprint:Ft.fingerprint??void 0,expiresAt:Ft.expiresAt,candidates:Ts.candidates}),Ms=pd(ks);Ke(Ms),J(await Cl.toDataURL(Ms,{width:1024,margin:2,errorCorrectionLevel:"L"})),ze(!1),ga.current=!1,Ee(Ft.id),Qe("result"),await Fs({silent:!0})}catch(x){Ze(x instanceof Error?x.message:String(x))}finally{xs(!1)}}},[a,qt,es,Bt,pt,Fs]),Ci=o.useCallback(()=>{ht&&La(ht).then(x=>{x.ok&&(ze(!0),window.setTimeout(()=>ze(!1),2e3))})},[ht]),Pi=o.useCallback(async x=>{if(!a)return;const X=x.clientKind==="desktop-local";Ze(null);try{if(await a.revokeClient(x.id),X&&rs()){const Oe=await Lr();await Fr({hosts:Oe.hosts,defaultHostId:Oe.defaultHostId,initialHostChoiceCompleted:Oe.initialHostChoiceCompleted,localClientToken:null}),xt(st=>st.map(Ft=>Ft.id===x.id?{...Ft,revokedAt:new Date().toISOString()}:Ft)),md({apiBaseUrl:_a(),clientToken:null,runtimeKey:"local"});return}await Fs()}catch(Oe){Ze(Oe instanceof Error?Oe.message:String(Oe))}},[a,Fs]),Ii=o.useCallback(async()=>{if(a){Ze(null);try{await a.purgeRevokedClients(),await Fs()}catch(x){Ze(x instanceof Error?x.message:String(x))}}},[a,Fs]);o.useEffect(()=>{j(w)},[w]),o.useEffect(()=>{ls(!1)},[M]),o.useEffect(()=>{if(!M)return;const x=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||N()},2e3);return()=>{window.clearInterval(x)}},[N,M]),o.useEffect(()=>{let x=null,X=Date.now();const Oe=()=>{const Ft=Date.now();Ft-X>=1e3&&(ge(Ft),X=Ft),x=requestAnimationFrame(Oe)};(typeof document>"u"||document.visibilityState==="visible")&&(x=requestAnimationFrame(Oe));const st=()=>{document.visibilityState==="visible"&&x===null?x=requestAnimationFrame(Oe):document.visibilityState!=="visible"&&x!==null&&(cancelAnimationFrame(x),x=null)};return document.addEventListener("visibilitychange",st),()=>{document.removeEventListener("visibilitychange",st),x!==null&&cancelAnimationFrame(x)}},[]);const ws=M?r[M]:null,Hs=ws?.phase,Yn=Hs==="ready",ln=Hs==="degraded",bn=xr(Hs),Qs=Yn||(bn||ln),Ai=ws?Math.max(0,ee-ws.updatedAtMs):0,cn=ln&&Ai>12e3,dn=go(Hs),pn=dn==="error"?Au(ws?.detail):null,Mn=Tu(pn),Zn=o.useMemo(()=>!h||!w?!1:JSON.stringify(h)!==JSON.stringify(w),[h,w]),pe=o.useCallback(x=>{j(X=>X&&x(X))},[]),cs=o.useCallback(async()=>{if(!h)return;const x=Uu(h);if(!x.sshCommand.trim()){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(x.remoteOpenchamber.mode==="external"&&!x.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ls(!0);return}if(x.remoteOpenchamber.mode==="managed"&&x.remoteOpenchamber.bindHost==="0.0.0.0"&&!x.auth.openchamberPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ls(!0),window.setTimeout(()=>mn.current?.focus(),0);return}if(!(x.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(x.auth.sshPassword?.enabled&&x.auth.sshPassword.value?.trim()&&x.auth.sshPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));x.auth.sshPassword.store=X?"settings":"never",X||(x.auth.sshPassword.value=void 0)}if(x.auth.openchamberPassword?.enabled&&x.auth.openchamberPassword.value?.trim()&&x.auth.openchamberPassword.store!=="settings"){const X=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));x.auth.openchamberPassword.store=X?"settings":"never",X||(x.auth.openchamberPassword.value=void 0)}try{await b(x),D.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(X){D.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:X instanceof Error?X.message:String(X)})}}},[h,t,b]),Rn=o.useCallback(async(x,X)=>{const Oe=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await C(Oe,`ssh ${X}`,x),A(Oe),D.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(st){return D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:st instanceof Error?st.message:String(st)}),!1}},[C,A,t]),On=o.useCallback(()=>{_||(U(null),ne(""))},[_]),Ga=o.useCallback((x,X)=>{if(ms(!1),X){U(x),ne(Mu(x));return}Rn(x,x)},[Rn]),ha=o.useMemo(()=>gi(l,ft,x=>[x.host,x.sshCommand]),[l,ft]),qa=o.useCallback(x=>{const X=(x||"").trim();if(!X){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ni(X)},[t]),fa=o.useCallback(async()=>{const x=q,X=Q.trim();if(x){if(!X){D.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}re(!0);try{await Rn(x,X)&&(U(null),ne(""))}finally{re(!1)}}},[Rn,Q,q,t]),Xn=o.useCallback(async()=>{if(w)try{await S(w.id);return}catch(x){if(!Cu(x)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw x;const Oe={...w,localForward:{...w.localForward,preferredLocalPort:mi()}};await b(Oe),await S(Oe.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[S,w,t,b]),mn=o.useRef(null),ea=o.useRef(null),Wa=o.useCallback(async x=>{if(w){if(x==="localPort"){const X={...w,localForward:{...w.localForward,preferredLocalPort:mi()}};try{await b(X),await S(X.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Oe){D.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Oe instanceof Error?Oe.message:String(Oe)})}return}ls(!0),window.setTimeout(()=>{if(x==="uiPassword"){mn.current?.focus();return}ea.current?.scrollIntoView({block:"center"})},0)}},[S,w,t,b]),ta=o.useCallback(async x=>(await yc(x,600)).map(Oe=>Lu(Oe)),[]),sa=o.useCallback(async()=>{if(h){T(!0),I(!0),W(null);try{const x=await ta(h.id);F(x)}catch(x){F([]),W(x instanceof Error?x.message:String(x))}finally{I(!1)}}},[h,ta]);o.useEffect(()=>{if(!L||!h)return;let x=!1;const X=async()=>{try{const st=await ta(h.id);x||(F(st),W(null))}catch(st){x||W(st instanceof Error?st.message:String(st))}};X();const Oe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||X()},1e3);return()=>{x=!0,window.clearInterval(Oe)}},[h,L,ta]);const Gs=o.useMemo(()=>k.join(`
27
- `),[k]),vn=o.useCallback(()=>{if(!Gs.trim()){D.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}La(Gs).then(x=>{x.ok&&D.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Gs,t]),yn=o.useCallback(async()=>{if(h)try{await jc(h.id),F([]),D.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(x){D.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:x instanceof Error?x.message:String(x)})}},[h,t]),na=o.useCallback(async()=>{if(!ws?.localUrl){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const x=ws.localUrl.trim();if(!x){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ni(x)},[ws?.localUrl,t]),xa=o.useCallback(()=>{if(!h)return;if(!Qs&&h.remoteOpenchamber.mode==="external"&&!h.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ls(!0);return}if(!Qs&&h.remoteOpenchamber.mode==="managed"&&h.remoteOpenchamber.bindHost==="0.0.0.0"&&!h.auth.openchamberPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ls(!0),window.setTimeout(()=>mn.current?.focus(),0);return}O(!0),(Qs?g(h.id):Xn()).catch(X=>{const Oe=Qs?Yn?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";D.error(t(Oe),{description:X instanceof Error?X.message:String(X)})}).finally(()=>{O(!1)})},[Qs,Xn,g,h,Yn,t]),ba=o.useCallback(()=>{if(!h||bn)return;Z(!0),(ln?g(h.id).then(()=>Xn()):E(h.id)).catch(X=>{D.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:X instanceof Error?X.message:String(X)})}).finally(()=>{Z(!1)})},[Xn,g,h,bn,ln,E,t]),Ti=t(bn?"settings.remoteInstances.page.actions.connecting":ln?cn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Ei=!z&&!Y&&(Hs==="error"||Hs==="idle"||!Hs||ln&&cn)&&!bn,Di=t(Yn?"settings.remoteInstances.sidebar.actions.disconnect":Qs?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!h)return s.jsxs(ss,{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(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Ni()},children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[ps>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ii()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,tt&&dt.length===0&&H.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):dt.length===0&&H.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[H.map(x=>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:x.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),x.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(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ki(x.id)},children:t("settings.common.actions.cancel")})]},`pending-${x.id}`)),dt.map(x=>{const X=x.clientKind==="desktop-local",Oe=x.lastUsedAt?Date.parse(x.lastUsedAt):Number.NaN,st=!x.revokedAt&&(X||Number.isFinite(Oe)&&Date.now()-Oe<9e4),Ft=x.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):st?x.lastTransport==="relay"&&!X?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Oe)?t("settings.remoteInstances.clientAuth.lastUsed",{date:wc(Oe,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:ve("h-2 w-2 shrink-0 rounded-full",x.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:x.label}),mo(x.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:mo(x.devicePlatform)}):null,X?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:ve("typography-micro truncate",st&&!x.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Ft})]})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Pi(x)},disabled:!!x.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},x.id)})]})]}),Xe?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Xe}):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(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Ge(!0),disabled:be,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie(!0),disabled:be,children:[s.jsx(R,{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:Ne?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):de.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):de.map(x=>{const X=ae[x.id],Oe=X?X.status==="ok"?"desktopHostSwitcher.status.connected":X.status==="auth"?"desktopHostSwitcher.status.authRequired":X.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":X.status==="incompatible"?"desktopHostSwitcher.status.incompatible":X.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",st=X?.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:ve("h-2 w-2 shrink-0 rounded-full",X?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:Na(x.label)}),me===x.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:ve("typography-micro shrink-0",st?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Oe),st&&typeof X?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(X.latencyMs))}):""]})]}),s.jsx("p",{className:ve("typography-micro text-muted-foreground truncate",x.apiUrl&&"font-mono"),children:x.relay&&!x.apiUrl?t("mobile.connect.relay.badge"):Na(x.apiUrl||x.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{wi(x.id)},disabled:be||me===x.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:me===x.id?s.jsx(R,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"star",className:"h-3.5 w-3.5"})}),x.relay&&!x.apiUrl?null:s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>As(x),disabled:be,children:[s.jsx(R,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{is(x.id)},disabled:be,children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},x.id)})}),ye?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ye}):null]}):null,n?s.jsx(Kt,{open:Ue,onOpenChange:Ie,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{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:x=>{x.preventDefault(),Ut()},children:[s.jsx(Je,{className:"h-8",value:Le,onChange:x=>oe(x.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8",value:fe,onChange:x=>De(x.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:be,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(Je,{className:"h-8",value:$e,onChange:x=>Ve(x.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:be}),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(Js,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),qe.map(x=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Je,{className:"h-8 font-mono text-xs",value:x.name,onChange:X=>se(Oe=>Oe.map(st=>st.id===x.id?{...st,name:X.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8 font-mono text-xs",value:x.value,onChange:X=>se(Oe=>Oe.map(st=>st.id===x.id?{...st,value:X.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:be}),s.jsx("button",{type:"button",onClick:()=>se(X=>X.filter(Oe=>Oe.id!==x.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:be,children:s.jsx(R,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>se(x=>[...x,ar()]),disabled:be,children:[s.jsx(R,{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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie(!1),disabled:be,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:be||!fe.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Kt,{open:!!ue,onOpenChange:x=>{x||Ce(null)},children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),yi()},children:[s.jsx(Je,{className:"h-8",value:Me,onChange:x=>Ye(x.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8",value:G,onChange:x=>ke(x.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:be,autoFocus:!0}),s.jsx(Je,{className:"h-8",value:Ae,onChange:x=>He(x.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:be}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Js,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),at.map(x=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Je,{className:"h-8 font-mono text-xs",value:x.name,onChange:X=>nt(Oe=>Oe.map(st=>st.id===x.id?{...st,name:X.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8 font-mono text-xs",value:x.value,onChange:X=>nt(Oe=>Oe.map(st=>st.id===x.id?{...st,value:X.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:be}),s.jsx("button",{type:"button",onClick:()=>nt(X=>X.filter(Oe=>Oe.id!==x.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:be,children:s.jsx(R,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>nt(x=>[...x,ar()]),disabled:be,children:[s.jsx(R,{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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ce(null),disabled:be,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:be,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Kt,{open:je,onOpenChange:Ge,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{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:x=>{x.preventDefault(),Mt()},children:[s.jsx(Je,{className:"h-8",value:ie,onChange:x=>we(x.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:be,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ge(!1),disabled:be,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:be||!ie.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Kt,{open:Re,onOpenChange:ct,children:s.jsxs(zt,{className:lt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t(lt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Vt,{children:t(lt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),lt==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:x=>{x.preventDefault(),Si()},children:[s.jsx(Je,{className:"h-8",value:pt,onChange:x=>Ct(x.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:!!qt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!qt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!qt?.localUrl}].map(x=>{const X=es===x.key;return s.jsxs("div",{className:ve("flex items-start gap-2 py-0.5",x.available?"cursor-pointer":"opacity-45"),onClick:()=>{x.available&&Ds(x.key)},role:"presentation",children:[s.jsx(dr,{checked:X,disabled:!x.available,onChange:()=>Ds(x.key),ariaLabel:x.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:ve("typography-ui-label font-normal",X?"text-foreground":"text-foreground/70"),children:x.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:x.hint})]})]},x.key)})}),es==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Yi,{checked:Bt,onChange:os,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,es==="relay"&&qt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Yi,{checked:Bt,onChange:os,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]}),Xe?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Xe}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ct(!1),disabled:Nt,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:Nt||!qt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[jt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:jt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,ht?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:ht}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Ci,children:[s.jsx(R,{name:he?"check":"file-copy",className:ve("h-3.5 w-3.5",he&&"text-[var(--status-success)]")}),t(he?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>ct(!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(B,{type:"button",size:"xs",className:"!font-normal",onClick:ji,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:p?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(x=>{const X=r[x.id],Oe=x.nickname?.trim()||x.sshParsed?.destination||x.id,st=X?.phase,Ft=st==="ready",Ts=go(st),ks=Ts==="error"?X?.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 ${xo(st)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Oe})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(ho(Ts)),Ts==="connecting"?` · ${t(uo(st))}`:"",Ft&&X?.localUrl?` · ${X.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ft?s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>qa(X?.localUrl),children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Ft?g(x.id):S(x.id)).catch(gs=>D.error(t(Ft?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:gs instanceof Error?gs.message:String(gs)}))},children:[Ft?s.jsx(R,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Ft?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>A(x.id),children:[s.jsx(R,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&v(x.id).catch(gs=>D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:gs instanceof Error?gs.message:String(gs)}))},children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),ks?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:ks}):null]},x.id)})}):null,n?s.jsx(Kt,{open:vs,onOpenChange:ms,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Vt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Ws,{value:ys,onChange:le,"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")}]}),ys==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Je,{className:"h-8",value:ft,onChange:x=>yt(x.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),m?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")}):ha.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:ha.map(x=>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:[x.host,x.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:x.sshCommand})]}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ga(x.host,x.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${x.source}:${x.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Ba()},children:[s.jsx(Je,{className:"h-8",value:Ht,onChange:x=>as(x.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:f}),s.jsx(Je,{className:"h-8",value:Qt,onChange:x=>Yt(x.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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ms(!1),disabled:f,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:f||!Qt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Kt,{open:!!q,onOpenChange:x=>{x||On()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),fa()},children:[s.jsx(Je,{value:Q,onChange:x=>ne(x.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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:On,disabled:_,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:_,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Ln=h.remoteOpenchamber.mode==="managed",aa=Ln&&h.remoteOpenchamber.bindHost==="0.0.0.0",va=aa&&!h.auth.openchamberPassword?.value?.trim(),ya=h.nickname?.trim()||h.sshParsed?.destination||h.id;return s.jsx(Kt,{open:!!h,onOpenChange:x=>{x||A(null)},children:s.jsxs(zt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Qi} truncate`,children:ya}),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 ${xo(Hs)}`}),s.jsx("span",{className:"text-foreground",children:t(ho(dn))}),dn==="connecting"?s.jsx("span",{children:t(uo(Hs))}):null,ws?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:ws.localUrl}):null,cn?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(B,{type:"button",variant:Qs?"outline":"default",size:"xs",className:"!font-normal",onClick:xa,disabled:z||Y,children:[Qs?s.jsx(R,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"plug-2",className:"h-3.5 w-3.5"}),Di]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ba,disabled:!Ei,children:[s.jsx(R,{name:"refresh",className:`h-3.5 w-3.5 ${bn||ln&&!cn?"animate-spin":""}`}),Ti]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{sa()},children:[s.jsx(R,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(B,{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"))&&v(h.id).then(()=>{A(null),D.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(X=>{D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:X instanceof Error?X.message:String(X)})})},children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),dn==="error"&&ws?.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:ws.detail}),Mn?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(Mn)}):null,pn&&!Mn?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Wa(pn)},children:t(pn==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":pn==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,ws?.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:ws.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(Je,{className:"h-7 md:max-w-xl",value:h.sshCommand,onChange:x=>pe(X=>({...X,sshCommand:x.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(Je,{className:"h-7 md:max-w-sm",value:h.nickname||"",onChange:x=>pe(X=>({...X,nickname:x.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(_s,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Pt,{value:h.remoteOpenchamber.mode,onValueChange:x=>pe(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,mode:x==="external"?"external":"managed"}})),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(ot,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(Tn,{open:js,onOpenChange:ls,children:[s.jsxs(En,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:ml,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(R,{name:js?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(Dn,{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(Ss,{containerClassName:"w-fit",min:5,max:240,step:1,className:ve(Ps,"tabular-nums"),value:h.connectionTimeoutSec,onValueChange:x=>{pe(X=>({...X,connectionTimeoutSec:Number.isFinite(x)?x:X.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:ea,children:s.jsx(_s,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ve(Ps,"tabular-nums"),value:h.remoteOpenchamber.preferredPort,onValueChange:x=>{pe(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,preferredPort:Number.isFinite(x)&&x>0?x:void 0}}))},onClear:()=>{pe(x=>({...x,remoteOpenchamber:{...x.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Ln?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(_s,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Pt,{value:h.remoteOpenchamber.installMethod,onValueChange:x=>pe(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,installMethod:x==="npm"||x==="bun"?x:"auto"}})),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(ot,{value:"bun",children:"bun"}),s.jsx(ot,{value:"npm",children:"npm"})]})]})]}):null,Ln?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(_s,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(li,{checked:aa,onCheckedChange:x=>pe(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,bindHost:x?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),aa?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,Ln?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(_s,{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(li,{checked:h.remoteOpenchamber.keepRunning,onCheckedChange:x=>pe(X=>({...X,remoteOpenchamber:{...X.remoteOpenchamber,keepRunning:x}}))})})]}):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(_s,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Pt,{value:h.localForward.bindHost,onValueChange:x=>{x==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||pe(X=>({...X,localForward:{...X.localForward,bindHost:x==="localhost"||x==="0.0.0.0"?x:"127.0.0.1"}}))},children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[240px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(ot,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(ot,{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(_s,{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(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ve(Ps,"tabular-nums"),value:h.localForward.preferredLocalPort,onValueChange:x=>{pe(X=>({...X,localForward:{...X.localForward,preferredLocalPort:Number.isFinite(x)&&x>0?x:void 0}}))},onClear:()=>{pe(x=>({...x,localForward:{...x.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>pe(x=>({...x,localForward:{...x.localForward,preferredLocalPort:mi()}})),children:s.jsx(R,{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:`${h.localForward.bindHost}:${h.localForward.preferredLocalPort||"auto"} → ${h.sshParsed?.destination||h.nickname||"remote"}:${h.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(_s,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(Je,{className:"h-7 md:max-w-sm",type:"password",value:h.auth.sshPassword?.value||"",onChange:x=>pe(X=>({...X,auth:{...X.auth,sshPassword:{enabled:x.target.value.trim().length>0,value:x.target.value,store:X.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_s,{label:t(aa?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(Ln?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(Je,{className:ve("h-7 md:max-w-sm",va&&"border-[var(--status-error)]"),type:"password",ref:mn,"aria-invalid":va,value:h.auth.openchamberPassword?.value||"",onChange:x=>pe(X=>({...X,auth:{...X.auth,openchamberPassword:{enabled:x.target.value.trim().length>0,value:x.target.value,store:X.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:[h.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,h.portForwards.map((x,X)=>{const Oe=kt=>{pe(Gt=>({...Gt,portForwards:Gt.portForwards.map((Ys,Dt)=>Dt===X?kt(Ys):Ys)}))},st=x.type==="remote"?"Local target":"Local listen",Ft=x.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.",Ts=x.type==="remote"?"Remote listen":"Remote target",ks=x.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Ms=bo(x.localHost||"localhost",x.localPort),gs=bo(x.remoteHost||"localhost",x.remotePort),u=x.type==="local"&&typeof x.localPort=="number"&&x.localPort>0,bt=u?`http://${Ou(x.localHost)}:${x.localPort}`:"",Zt=!!V[x.id],Xt=x.type==="local"?t("settings.remoteInstances.page.forwardType.local"):x.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(Tn,{open:Zt,onOpenChange:kt=>{$(Gt=>({...Gt,[x.id]:kt}))},className:`${X>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(En,{className:"flex items-center gap-2 group",children:[s.jsx(R,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Zt?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Eu(x)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Xt})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(li,{checked:x.enabled,onCheckedChange:kt=>Oe(Gt=>({...Gt,enabled:kt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(B,{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:()=>pe(kt=>({...kt,portForwards:kt.portForwards.filter(Gt=>Gt.id!==x.id)})),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Dn,{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(_s,{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(Ru(x.type))})]})})}),s.jsxs(Pt,{value:x.type,onValueChange:kt=>Oe(Gt=>({...Gt,type:kt==="dynamic"||kt==="remote"?kt:"local"})),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(ot,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(ot,{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(_s,{label:st,hint:Ft})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Je,{className:"h-7 w-32",value:x.localHost||"127.0.0.1",onChange:kt=>Oe(Gt=>({...Gt,localHost:kt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ve(Ps,"tabular-nums"),value:x.localPort,onValueChange:kt=>{Oe(Gt=>({...Gt,localPort:Number.isFinite(kt)&&kt>0?kt:void 0}))},onClear:()=>{Oe(kt=>({...kt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),x.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(_s,{label:Ts,hint:ks})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Je,{className:"h-7 w-32",value:x.remoteHost||"",onChange:kt=>Oe(Gt=>({...Gt,remoteHost:kt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ve(Ps,"tabular-nums"),value:x.remotePort,onValueChange:kt=>{Oe(Gt=>({...Gt,remotePort:Number.isFinite(kt)&&kt>0?kt:void 0}))},onClear:()=>{Oe(kt=>({...kt,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:x.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ms}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):x.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:gs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(R,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(R,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ms}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ms}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(R,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(R,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:gs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),u?s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{An(bt).then(kt=>{kt||D.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},x.id)}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const x=Du();pe(X=>({...X,portForwards:[...X.portForwards,x]})),$(X=>({...X,[x.id]:!0}))},children:[s.jsx(R,{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(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{cs()},disabled:!Zn||f,children:t("settings.common.actions.saveChanges")}),ws?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{La(ws.localUrl||"").then(x=>{x.ok&&D.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(R,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{na()},children:[s.jsx(R,{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(Kt,{open:L,onOpenChange:T,children:s.jsxs(zt,{className:"sm:max-w-2xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Vt,{children:h?.nickname?.trim()||h?.sshParsed?.destination||h?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:vn,disabled:P||!Gs.trim(),children:[s.jsx(R,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn()},disabled:P,children:[s.jsx(R,{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")}):K?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:K}):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:k.length>0?k.join(`
28
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Kt,{open:!!q,onOpenChange:x=>{x||On()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:q?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:q}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),fa()},children:[s.jsx(Je,{value:Q,onChange:x=>ne(x.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(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:On,disabled:_,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:_,children:t("settings.common.actions.create")})]})]})]})})]})})},$u="__add_provider__",Vu=()=>{const t=fn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},Bu=({onItemSelect:t})=>{const{t:e}=it(),a=Us(),n=et(b=>ul(b,a)),i=et(b=>b.selectedProviderId),r=et(b=>b.setSelectedProvider),l=Vs(b=>b.activeProjectId),[p,m]=o.useState({}),f=o.useMemo(()=>a||Vu(),[l,a]),d=et(b=>b.loadProviders);o.useEffect(()=>{a&&d({directory:a,source:"settings:providers"})},[d,a]),o.useEffect(()=>{if(n.length===0){m({});return}let b=!1;return(async()=>{const v=n.map(async S=>{try{const g=f?`?directory=${encodeURIComponent(f)}`:"",E=await mt(`/api/provider/${encodeURIComponent(S.id)}/source${g}`,{method:"GET",headers:{Accept:"application/json"}});if(!E.ok)return;const M=await E.json().catch(()=>null),A=M?.sources??M?.data?.sources;if(!A||b)return;m(w=>({...w,[S.id]:A}))}catch{}});await Promise.all(v)})(),()=>{b=!0}},[f,n]);const y="bg-background",c=o.useMemo(()=>n.filter(b=>!!p[b.id]?.project?.exists),[n,p]),N=o.useMemo(()=>n.filter(b=>!p[b.id]?.project?.exists),[n,p]);return s.jsxs("div",{className:ve("flex h-full flex-col",y),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${on} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(Va,{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(B,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r($u),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Bs,{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(R,{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:[N.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")}),N.map(b=>s.jsx(yo,{provider:b,selectedProviderId:i,onSelect:()=>{r(b.id),t?.()}},b.id))]}),c.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ve("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",N.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),c.map(b=>s.jsx(yo,{provider:b,selectedProviderId:i,onSelect:()=>{r(b.id),t?.()}},b.id))]})]})})]})},yo=t=>{const e=ut.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,p=a.id,m=l?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==m?(f=ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",m),e[0]=m,e[1]=f):f=e[1];let d;e[2]!==a.id?(d=s.jsx(zn,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=d):d=e[3];const y=a.name||a.id;let c;e[4]!==y?(c=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:y}),e[4]=y,e[5]=c):c=e[5];let N;e[6]!==r?(N=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=N):N=e[7];let b;e[8]!==i||e[9]!==d||e[10]!==c||e[11]!==N?(b=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-primary/50",tabIndex:0,children:[d,c,N]}),e[8]=i,e[9]=d,e[10]=c,e[11]=N,e[12]=b):b=e[12];let C;return e[13]!==a.id||e[14]!==f||e[15]!==b?(C=s.jsx("div",{className:f,children:b},p),e[13]=a.id,e[14]=f,e[15]=b,e[16]=C):C=e[16],C},Hu=t=>t,Gu=(t,e,a)=>t&&!e&&!a,jo=t=>typeof t=="object"&&t!==null,Kl=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()},qu=t=>{if(!jo(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>jo(i)));return e},wo=t=>t.length===0?!0:t.some(e=>Kl(e)==="api"),ko=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>Kl(e)==="oauth"),Wu=t=>t!=="claude-code",No=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,Ju=t=>t.modelCount>0&&(!t.sourcesLoaded||t.hasCredentials||!!t.isEditableCustomProvider),Qu=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,br={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},Fn="__custom_provider__",Yu=/^[a-z0-9][a-z0-9-_]*$/,zl=/^https?:\/\//,Zu=/^\{env:([^}]+)\}$/;let Xu=0;const xi=()=>`row-${Xu++}`,vr=()=>({row:xi(),id:"",name:""}),yr=()=>({row:xi(),key:"",value:""}),eg=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[vr()],headers:[yr()]});function tg(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function sg(t){const e=t.trim();if(!e)return{};const n=e.match(Zu)?.[1]?.trim();return n?{env:n}:{key:e}}function ng(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&zl.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(br)).has(r.npm)})}function So(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&ng(t):!1}function Co(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function ag(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:xi(),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:xi(),id:typeof f?.id=="string"?f.id:"",name:typeof f?.name=="string"?f.name:typeof f?.id=="string"?f.id:""})):[vr()],p=Array.isArray(t.env)?t.env.find(f=>typeof f=="string"&&f.trim().length>0)?.trim():void 0,m=r.find(f=>"api"in f);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:tg(m?.api?.npm),baseURL:a,apiKey:p?`{env:${p}}`:"",models:l,headers:i.length>0?i:[yr()]}}function ig(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=sg(t.form.apiKey),l=t.disabledProviders??[],p=t.editingProviderID?.trim(),m=e?Yu.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?zl.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),c=!!(i||r||p&&t.allowExistingAuth&&p===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),N=l.includes(e),C=m||!!(p&&p===e)?void 0:t.existingProviderIDs.has(e)&&!N?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,v=new Set,S=t.form.models.map(T=>{const P=T.id.trim(),I=P?v.has(P)?t.t("settings.providers.page.custom.error.duplicate"):void v.add(P):t.t("settings.providers.page.custom.error.required"),K=T.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:I,name:K}}),g=S.every(T=>!T.id&&!T.name),E=Object.fromEntries(t.form.models.map(T=>[T.id.trim(),{name:T.name.trim()}])),M=new Set,A=t.form.headers.map(T=>{const P=T.key.trim(),I=T.value.trim();if(!P&&!I)return{};const K=P?M.has(P.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void M.add(P.toLowerCase()):t.t("settings.providers.page.custom.error.required"),W=I?void 0:t.t("settings.providers.page.custom.error.required");return{key:K,value:W}}),w=A.every(T=>!T.key&&!T.value),h=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])),j={providerID:m??C,name:f,baseURL:d,apiKey:c};return!m&&!C&&!f&&!d&&!c&&g&&w?{err:j,models:S,headers:A,result:{providerID:e,name:a,apiKey:r,config:{npm:br[t.form.protocol],name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(h).length>0?{headers:h}:{}},models:E}}}:{err:j,models:S,headers:A}}function rg(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function og(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Po=t=>{const e=ut.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:p,authFailureHint:m,onSubmit:f,onCancel:d,onDisconnect:y}=t;let c;e[0]!==n?(c=n===void 0?[]:n,e[0]=n,e[1]=c):c=e[1];const N=c,b=i===void 0?!1:i,C=r===void 0?"create":r,v=p===void 0?!1:p,S=m===void 0?null:m,{t:g}=it(),E=C==="edit";let M;e[2]!==l?(M=()=>l??eg(),e[2]=l,e[3]=M):M=e[3];const[A,w]=o.useState(M);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h={},e[4]=h):h=e[4];const[j,L]=o.useState(h);let T;e[5]===Symbol.for("react.memo_cache_sentinel")?(T=[],e[5]=T):T=e[5];const[P,I]=o.useState(T);let K;e[6]===Symbol.for("react.memo_cache_sentinel")?(K=[],e[6]=K):K=e[6];const[W,k]=o.useState(K),F=o.useRef(null);let q,U;e[7]!==l||e[8]!==E?(q=()=>{l&&(E&&F.current===l.providerID||(F.current=E?l.providerID:null,w(l),L({}),I([]),k([])))},U=[l,E],e[7]=l,e[8]=E,e[9]=q,e[10]=U):(q=e[9],U=e[10]),o.useEffect(q,U);let Q;e[11]===Symbol.for("react.memo_cache_sentinel")?(Q=(St,Tt)=>{w(Ut=>({...Ut,[St]:Tt})),L(Ut=>({...Ut,[St]:void 0}))},e[11]=Q):Q=e[11];const ne=Q;let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=(St,Tt,Ut)=>{w(Mt=>({...Mt,models:Mt.models.map((is,As)=>As===St?{...is,[Tt]:Ut}:is)})),I(Mt=>{const is=[...Mt];return is[St]={...is[St]??{},[Tt]:void 0},is})},e[12]=_):_=e[12];const re=_;let V;e[13]===Symbol.for("react.memo_cache_sentinel")?(V=(St,Tt,Ut)=>{w(Mt=>({...Mt,headers:Mt.headers.map((is,As)=>As===St?{...is,[Tt]:Ut}:is)})),k(Mt=>{const is=[...Mt];return is[St]={...is[St]??{},[Tt]:void 0},is})},e[13]=V):V=e[13];const $=V;let z;e[14]!==v||e[15]!==b||e[16]!==N||e[17]!==a||e[18]!==A||e[19]!==E||e[20]!==f||e[21]!==g?(z=async St=>{if(St.preventDefault(),b)return;const Tt=ig({form:A,t:((Ut,Mt)=>g(Ut,Mt)),existingProviderIDs:a,disabledProviders:N,editingProviderID:E?A.providerID:void 0,allowExistingAuth:E&&v});L(Tt.err),I(Tt.models),k(Tt.headers),Tt.result&&await f(Tt.result)},e[14]=v,e[15]=b,e[16]=N,e[17]=a,e[18]=A,e[19]=E,e[20]=f,e[21]=g,e[22]=z):z=e[22];const O=z;let Y;e[23]!==E||e[24]!==g?(Y=g(E?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=E,e[24]=g,e[25]=Y):Y=e[25];let Z;e[26]!==g?(Z=g("settings.providers.page.custom.description"),e[26]=g,e[27]=Z):Z=e[27];let ee;e[28]!==Z?(ee=s.jsx("p",{className:Kn,children:Z}),e[28]=Z,e[29]=ee):ee=e[29];let ge;e[30]!==S?(ge=S?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:S}):null,e[30]=S,e[31]=ge):ge=e[31];let de;e[32]!==g?(de=g("settings.providers.page.custom.field.providerID.label"),e[32]=g,e[33]=de):de=e[33];let xe;e[34]!==g?(xe=g("settings.providers.page.custom.field.providerID.info"),e[34]=g,e[35]=xe):xe=e[35];const ae=A.providerID;let te;e[36]===Symbol.for("react.memo_cache_sentinel")?(te=St=>ne("providerID",St.target.value),e[36]=te):te=e[36];let me;e[37]!==g?(me=g("settings.providers.page.custom.field.providerID.placeholder"),e[37]=g,e[38]=me):me=e[38];const Pe=!E,Ne=E||b,Se=!!j.providerID;let be;e[39]!==g?(be=g("settings.providers.page.custom.field.providerID.label"),e[39]=g,e[40]=be):be=e[40];let Fe;e[41]!==A.providerID||e[42]!==me||e[43]!==Pe||e[44]!==Ne||e[45]!==Se||e[46]!==be?(Fe=s.jsx(Je,{value:ae,onChange:te,placeholder:me,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:Pe,disabled:Ne,"aria-invalid":Se,"aria-label":be}),e[41]=A.providerID,e[42]=me,e[43]=Pe,e[44]=Ne,e[45]=Se,e[46]=be,e[47]=Fe):Fe=e[47];let Le;e[48]!==j.providerID?(Le=j.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.providerID}):null,e[48]=j.providerID,e[49]=Le):Le=e[49];let oe;e[50]!==de||e[51]!==xe||e[52]!==Fe||e[53]!==Le?(oe=s.jsxs(Wt,{label:de,info:xe,children:[Fe,Le]}),e[50]=de,e[51]=xe,e[52]=Fe,e[53]=Le,e[54]=oe):oe=e[54];let fe;e[55]!==g?(fe=g("settings.providers.page.custom.field.protocol.label"),e[55]=g,e[56]=fe):fe=e[56];let De;e[57]!==g?(De=g("settings.providers.page.custom.field.protocol.info"),e[57]=g,e[58]=De):De=e[58];const $e=A.protocol;let Ve;e[59]===Symbol.for("react.memo_cache_sentinel")?(Ve=St=>{St in br&&w(Tt=>({...Tt,protocol:St}))},e[59]=Ve):Ve=e[59];let qe;e[60]!==g?(qe=g("settings.providers.page.custom.field.protocol.label"),e[60]=g,e[61]=qe):qe=e[61];let se;e[62]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(Rt,{}),e[62]=se):se=e[62];let ie;e[63]!==qe?(ie=s.jsx(It,{"aria-label":qe,className:"w-full",children:se}),e[63]=qe,e[64]=ie):ie=e[64];let we;e[65]!==g?(we=g("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=g,e[66]=we):we=e[66];let ye;e[67]!==we?(ye=s.jsx(ot,{value:"openai-chat",children:we}),e[67]=we,e[68]=ye):ye=e[68];let Te;e[69]!==g?(Te=g("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=g,e[70]=Te):Te=e[70];let Ue;e[71]!==Te?(Ue=s.jsx(ot,{value:"openai-responses",children:Te}),e[71]=Te,e[72]=Ue):Ue=e[72];let Ie;e[73]!==g?(Ie=g("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=g,e[74]=Ie):Ie=e[74];let je;e[75]!==Ie?(je=s.jsx(ot,{value:"anthropic-messages",children:Ie}),e[75]=Ie,e[76]=je):je=e[76];let Ge;e[77]!==ye||e[78]!==Ue||e[79]!==je?(Ge=s.jsxs(At,{children:[ye,Ue,je]}),e[77]=ye,e[78]=Ue,e[79]=je,e[80]=Ge):Ge=e[80];let ue;e[81]!==b||e[82]!==A.protocol||e[83]!==ie||e[84]!==Ge?(ue=s.jsxs(Pt,{value:$e,onValueChange:Ve,disabled:b,children:[ie,Ge]}),e[81]=b,e[82]=A.protocol,e[83]=ie,e[84]=Ge,e[85]=ue):ue=e[85];let Ce;e[86]!==fe||e[87]!==De||e[88]!==ue?(Ce=s.jsx(Wt,{label:fe,info:De,children:ue}),e[86]=fe,e[87]=De,e[88]=ue,e[89]=Ce):Ce=e[89];let Me;e[90]!==g?(Me=g("settings.providers.page.custom.field.name.label"),e[90]=g,e[91]=Me):Me=e[91];let Ye;e[92]!==g?(Ye=g("settings.providers.page.custom.field.name.info"),e[92]=g,e[93]=Ye):Ye=e[93];const G=A.name;let ke;e[94]===Symbol.for("react.memo_cache_sentinel")?(ke=St=>ne("name",St.target.value),e[94]=ke):ke=e[94];let Ae;e[95]!==g?(Ae=g("settings.providers.page.custom.field.name.placeholder"),e[95]=g,e[96]=Ae):Ae=e[96];const He=!!j.name;let at;e[97]!==g?(at=g("settings.providers.page.custom.field.name.label"),e[97]=g,e[98]=at):at=e[98];let nt;e[99]!==A.name||e[100]!==Ae||e[101]!==He||e[102]!==at?(nt=s.jsx(Je,{value:G,onChange:ke,placeholder:Ae,className:"h-8 rounded-md px-3","aria-invalid":He,"aria-label":at}),e[99]=A.name,e[100]=Ae,e[101]=He,e[102]=at,e[103]=nt):nt=e[103];let dt;e[104]!==j.name?(dt=j.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.name}):null,e[104]=j.name,e[105]=dt):dt=e[105];let xt;e[106]!==Me||e[107]!==Ye||e[108]!==nt||e[109]!==dt?(xt=s.jsxs(Wt,{label:Me,info:Ye,children:[nt,dt]}),e[106]=Me,e[107]=Ye,e[108]=nt,e[109]=dt,e[110]=xt):xt=e[110];let H;e[111]!==g?(H=g("settings.providers.page.custom.field.baseURL.label"),e[111]=g,e[112]=H):H=e[112];let Be;e[113]!==g?(Be=g("settings.providers.page.custom.field.baseURL.info"),e[113]=g,e[114]=Be):Be=e[114];const tt=A.baseURL;let rt;e[115]===Symbol.for("react.memo_cache_sentinel")?(rt=St=>ne("baseURL",St.target.value),e[115]=rt):rt=e[115];let pt;e[116]!==g?(pt=g("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=g,e[117]=pt):pt=e[117];const Ct=!!j.baseURL;let Xe;e[118]!==g?(Xe=g("settings.providers.page.custom.field.baseURL.label"),e[118]=g,e[119]=Xe):Xe=e[119];let Ze;e[120]!==A.baseURL||e[121]!==pt||e[122]!==Ct||e[123]!==Xe?(Ze=s.jsx(Je,{value:tt,onChange:rt,placeholder:pt,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Ct,"aria-label":Xe}),e[120]=A.baseURL,e[121]=pt,e[122]=Ct,e[123]=Xe,e[124]=Ze):Ze=e[124];let ht;e[125]!==j.baseURL?(ht=j.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.baseURL}):null,e[125]=j.baseURL,e[126]=ht):ht=e[126];let Ke;e[127]!==H||e[128]!==Be||e[129]!==Ze||e[130]!==ht?(Ke=s.jsxs(Wt,{label:H,info:Be,children:[Ze,ht]}),e[127]=H,e[128]=Be,e[129]=Ze,e[130]=ht,e[131]=Ke):Ke=e[131];let wt;e[132]!==g?(wt=g("settings.providers.page.custom.field.apiKey.label"),e[132]=g,e[133]=wt):wt=e[133];let Ee;e[134]!==v||e[135]!==E||e[136]!==g?(Ee=g(E&&v?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=v,e[135]=E,e[136]=g,e[137]=Ee):Ee=e[137];const jt=A.apiKey;let J;e[138]===Symbol.for("react.memo_cache_sentinel")?(J=St=>ne("apiKey",St.target.value),e[138]=J):J=e[138];let he;e[139]!==v||e[140]!==E||e[141]!==g?(he=g(E&&v?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=v,e[140]=E,e[141]=g,e[142]=he):he=e[142];const ze=!!j.apiKey;let Re;e[143]!==g?(Re=g("settings.providers.page.custom.field.apiKey.label"),e[143]=g,e[144]=Re):Re=e[144];let ct;e[145]!==A.apiKey||e[146]!==he||e[147]!==ze||e[148]!==Re?(ct=s.jsx(Je,{type:"password",value:jt,onChange:J,placeholder:he,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":ze,"aria-label":Re}),e[145]=A.apiKey,e[146]=he,e[147]=ze,e[148]=Re,e[149]=ct):ct=e[149];let lt;e[150]!==j.apiKey?(lt=j.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.apiKey}):null,e[150]=j.apiKey,e[151]=lt):lt=e[151];let Qe;e[152]!==wt||e[153]!==Ee||e[154]!==ct||e[155]!==lt?(Qe=s.jsxs(Wt,{label:wt,info:Ee,children:[ct,lt]}),e[152]=wt,e[153]=Ee,e[154]=ct,e[155]=lt,e[156]=Qe):Qe=e[156];let Nt;e[157]!==Y||e[158]!==ee||e[159]!==ge||e[160]!==oe||e[161]!==Ce||e[162]!==xt||e[163]!==Ke||e[164]!==Qe?(Nt=s.jsxs(_e,{title:Y,divider:!1,settingsItem:"providers.custom",contentClassName:qs,children:[ee,ge,oe,Ce,xt,Ke,Qe]}),e[157]=Y,e[158]=ee,e[159]=ge,e[160]=oe,e[161]=Ce,e[162]=xt,e[163]=Ke,e[164]=Qe,e[165]=Nt):Nt=e[165];let xs;e[166]!==g?(xs=g("settings.providers.page.custom.models.title"),e[166]=g,e[167]=xs):xs=e[167];let es;if(e[168]!==A.models||e[169]!==P||e[170]!==g){let St;e[172]!==A.models.length||e[173]!==P||e[174]!==g?(St=(Tt,Ut)=>s.jsx("div",{className:`${zs} 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:Et,children:g("settings.providers.page.custom.models.idLabel")}),s.jsx(Je,{value:Tt.id,onChange:Mt=>re(Ut,"id",Mt.target.value),placeholder:g("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.models.idLabel")}),P[Ut]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:P[Ut]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.models.nameLabel")}),s.jsx(Je,{value:Tt.name,onChange:Mt=>re(Ut,"name",Mt.target.value),placeholder:g("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":g("settings.providers.page.custom.models.nameLabel")}),P[Ut]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:P[Ut]?.name}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:hs,disabled:A.models.length<=1,onClick:()=>{A.models.length<=1||(w(Mt=>({...Mt,models:Mt.models.filter((is,As)=>As!==Ut)})),I(Mt=>Mt.filter((is,As)=>As!==Ut)))},"aria-label":g("settings.providers.page.custom.models.remove"),children:s.jsx(R,{name:"delete-bin",className:"size-4"})})]})},Tt.row),e[172]=A.models.length,e[173]=P,e[174]=g,e[175]=St):St=e[175],es=A.models.map(St),e[168]=A.models,e[169]=P,e[170]=g,e[171]=es}else es=e[171];let Ds;e[176]===Symbol.for("react.memo_cache_sentinel")?(Ds=()=>{w(lg),I(cg)},e[176]=Ds):Ds=e[176];let Bt;e[177]!==g?(Bt=g("settings.providers.page.custom.models.add"),e[177]=g,e[178]=Bt):Bt=e[178];let os;e[179]!==Bt?(os=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ds,children:Bt}),e[179]=Bt,e[180]=os):os=e[180];let qt;e[181]!==xs||e[182]!==es||e[183]!==os?(qt=s.jsxs(_e,{title:xs,contentClassName:qs,children:[es,os]}),e[181]=xs,e[182]=es,e[183]=os,e[184]=qt):qt=e[184];let bs;e[185]!==g?(bs=g("settings.providers.page.custom.headers.title"),e[185]=g,e[186]=bs):bs=e[186];let ps;e[187]!==g?(ps=g("settings.providers.page.custom.headers.description"),e[187]=g,e[188]=ps):ps=e[188];let vs;e[189]!==ps?(vs=s.jsx("p",{className:Kn,children:ps}),e[189]=ps,e[190]=vs):vs=e[190];let ms;if(e[191]!==A.headers||e[192]!==W||e[193]!==g){let St;e[195]!==A.headers.length||e[196]!==W||e[197]!==g?(St=(Tt,Ut)=>s.jsx("div",{className:`${zs} 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:Et,children:g("settings.providers.page.custom.headers.keyLabel")}),s.jsx(Je,{value:Tt.key,onChange:Mt=>$(Ut,"key",Mt.target.value),placeholder:g("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.keyLabel")}),W[Ut]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:W[Ut]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.headers.valueLabel")}),s.jsx(Je,{value:Tt.value,onChange:Mt=>$(Ut,"value",Mt.target.value),placeholder:g("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.valueLabel")}),W[Ut]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:W[Ut]?.value}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:hs,disabled:A.headers.length<=1,onClick:()=>{A.headers.length<=1||(w(Mt=>({...Mt,headers:Mt.headers.filter((is,As)=>As!==Ut)})),k(Mt=>Mt.filter((is,As)=>As!==Ut)))},"aria-label":g("settings.providers.page.custom.headers.remove"),children:s.jsx(R,{name:"delete-bin",className:"size-4"})})]})},Tt.row),e[195]=A.headers.length,e[196]=W,e[197]=g,e[198]=St):St=e[198],ms=A.headers.map(St),e[191]=A.headers,e[192]=W,e[193]=g,e[194]=ms}else ms=e[194];let ys;e[199]===Symbol.for("react.memo_cache_sentinel")?(ys=()=>{w(dg),k(pg)},e[199]=ys):ys=e[199];let le;e[200]!==g?(le=g("settings.providers.page.custom.headers.add"),e[200]=g,e[201]=le):le=e[201];let ft;e[202]!==le?(ft=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ys,children:le}),e[202]=le,e[203]=ft):ft=e[203];let yt;e[204]!==bs||e[205]!==vs||e[206]!==ms||e[207]!==ft?(yt=s.jsxs(_e,{title:bs,contentClassName:qs,children:[vs,ms,ft]}),e[204]=bs,e[205]=vs,e[206]=ms,e[207]=ft,e[208]=yt):yt=e[208];let Qt;e[209]!==b||e[210]!==d||e[211]!==g?(Qt=d?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:d,disabled:b,children:g("settings.providers.page.custom.actions.back")}):null,e[209]=b,e[210]=d,e[211]=g,e[212]=Qt):Qt=e[212];let Yt;e[213]!==b||e[214]!==y||e[215]!==g?(Yt=y?s.jsx(B,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{y()},disabled:b,children:g("settings.providers.page.actions.disconnect")}):null,e[213]=b,e[214]=y,e[215]=g,e[216]=Yt):Yt=e[216];let Ht;e[217]!==b||e[218]!==E||e[219]!==g?(Ht=g(b?"settings.providers.page.actions.saving":E?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=b,e[218]=E,e[219]=g,e[220]=Ht):Ht=e[220];let as;e[221]!==b||e[222]!==Ht?(as=s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:b,children:Ht}),e[221]=b,e[222]=Ht,e[223]=as):as=e[223];let js;e[224]!==Qt||e[225]!==Yt||e[226]!==as?(js=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Qt,Yt,as]}),e[224]=Qt,e[225]=Yt,e[226]=as,e[227]=js):js=e[227];let ls;return e[228]!==O||e[229]!==Nt||e[230]!==qt||e[231]!==yt||e[232]!==js?(ls=s.jsxs("form",{onSubmit:O,className:"space-y-0",children:[Nt,qt,yt,js]}),e[228]=O,e[229]=Nt,e[230]=qt,e[231]=yt,e[232]=js,e[233]=ls):ls=e[233],ls};function lg(t){return{...t,models:[...t.models,vr()]}}function cg(t){return[...t,{}]}function dg(t){return{...t,headers:[...t.headers,yr()]}}function pg(t){return[...t,{}]}const mg=(t,e)=>!!e&&t!=="claude-code",ug=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Qn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ns=t=>typeof t=="string"&&t.length>0?t:void 0,gg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Qn(a))continue;const n=Ns(a.value);n!==void 0&&e.push({value:n,label:Ns(a.label)??n,...Ns(a.hint)?{hint:Ns(a.hint)}:{}})}return e},hg=t=>{if(!Qn(t))return;const e=Ns(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}},fg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Qn(a))continue;const n=Ns(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?gg(a.options):[];if(i==="select"&&r.length===0)continue;const l=hg(a.when);e.push({type:i,key:n,message:Ns(a.message)??n,options:r,...Ns(a.placeholder)?{placeholder:Ns(a.placeholder)}:{},...l?{when:l}:{}})}return e},xg=(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},jr=(t,e)=>t.filter(a=>xg(a,e)),bg=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},vg=(t,e)=>jr(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,yg=(t,e)=>{const a={};for(const n of jr(t,e))a[n.key]=(e[n.key]??"").trim();return a},jg=t=>{const e=Qn(t)?t:{},a=Qn(e.data)?e.data:e,n=Ns(a.url)??Ns(a.verification_uri_complete)??Ns(a.verification_uri),i=Ns(a.instructions)??Ns(a.message);if(!n&&!i)return null;const r=Ns(a.user_code)??Ns(a.userCode)??(i?ug.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},Io=(t,e,a)=>{const n=Qn(t)?t:{},i=Qn(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 Ns(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},$i={phase:"idle"},Ao=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=it(),[r,l]=o.useState($i),[p,m]=o.useState({}),[f,d]=o.useState(""),y=o.useRef(null);o.useEffect(()=>()=>y.current?.abort(),[]);const c=r.phase==="idle"?null:r.methodIndex,N=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,b=async(h,j,L)=>{const T=await La(h);if(T.ok){D.success(i(j));return}console.error("Failed to copy OAuth value:",T.error),D.error(i(L))},C=async(h,j)=>{const L=new AbortController;y.current?.abort(),y.current=L;try{const T=await fn.getSdkClient().provider.oauth.callback({providerID:t,method:h,...j?{code:j}:{}},{signal:L.signal});if(L.signal.aborted)return;if(T.error)throw T.error;l($i),D.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(T){if(L.signal.aborted)return;console.error("Failed to complete OAuth flow:",T),l({phase:"failed",methodIndex:h,message:Io(T,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{y.current===L&&(y.current=null)}},v=async(h,j)=>{l({phase:"authorizing",methodIndex:h});let L;try{const T=await fn.getSdkClient().provider.oauth.authorize({providerID:t,method:h,...Object.keys(j).length>0?{inputs:j}:{}});if(T.error)throw T.error;const P=jg(T.data);if(!P){l({phase:"failed",methodIndex:h,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}L=P}catch(T){console.error("Failed to start OAuth flow:",T),l({phase:"failed",methodIndex:h,message:Io(T,i,"settings.providers.page.toast.oauthStartFailed")});return}if(L.url&&mg(t,L.url)&&An(L.url),L.method==="code"){d(""),l({phase:"awaitingCode",methodIndex:h,authorization:L,submitting:!1});return}l({phase:"waiting",methodIndex:h,authorization:L}),await C(h)},S=h=>{const j=fg(h.prompts);if(j.length===0){v(h.index,{});return}m(bg(j)),l({phase:"prompting",methodIndex:h.index,prompts:j,error:null})},g=()=>{if(r.phase!=="prompting")return;const h=vg(r.prompts,p);if(h){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:h.message})});return}v(r.methodIndex,yg(r.prompts,p))},E=()=>{if(r.phase!=="awaitingCode")return;const h=f.trim();h&&(l({...r,submitting:!0}),C(r.methodIndex,h))},M=()=>{y.current?.abort(),y.current=null,l($i)},A=h=>{const j=p[h.key]??"",L=T=>m(P=>({...P,[h.key]:T}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:h.message}),h.type==="select"?s.jsxs(Pt,{value:j,onValueChange:L,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{children:T=>h.options.find(P=>P.value===T)?.label??null})}),s.jsx(At,{children:h.options.map(T=>s.jsx(ot,{value:T.value,children:T.hint?`${T.label} · ${T.hint}`:T.label},T.value))})]}):s.jsx(Je,{value:j,onChange:T=>L(T.target.value),placeholder:h.placeholder,className:"max-w-[24rem] text-xs"})]},h.key)},w=h=>s.jsxs(s.Fragment,{children:[h.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:h.instructions}),h.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:h.userCode,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{b(h.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),h.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:h.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(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{An(h.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{b(h.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:ve("space-y-4",n),children:e.map(h=>{const j=c===h.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:h.label}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>S(h),disabled:N,children:i("settings.providers.page.actions.connect")})]}),j&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[jr(r.prompts,p).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(B,{size:"xs",className:"!font-normal",onClick:g,children:i("settings.providers.page.actions.continue")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:M,children:i("settings.providers.page.actions.cancel")})]})]}),j&&r.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(R,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),j&&r.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[w(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(R,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:M,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),j&&r.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[w(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(Je,{value:f,onChange:L=>d(L.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:r.submitting}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:E,disabled:r.submitting||f.trim().length===0,children:r.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:M,disabled:r.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),j&&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(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>S(h),children:i("settings.providers.page.actions.tryAgain")})]})]},h.index)})})},To=t=>Array.isArray(t?.env)&&t.env.some(e=>e.trim().length>0),wg=t=>new Intl.NumberFormat(ur(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),Eo=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=wg(t);return e.endsWith(".0")?e.slice(0,-2):e},Ia="__add_provider__",Ul=t=>typeof t=="object"&&t!==null,Do=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),kg=t=>{if(typeof t=="string")return{id:t};if(!Ul(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}},Ng=t=>{let e=[];Array.isArray(t)?e=t:Ul(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>kg(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},Sg=()=>{const{t}=it(),e=Us(),a=et(G=>ul(G,e)),n=et(G=>G.selectedProviderId),i=et(G=>G.setSelectedProvider),r=et(G=>G.getModelMetadata),l=ce(G=>G.hiddenModels),p=ce(G=>G.toggleHiddenModel),m=ce(G=>G.hideAllModels),f=ce(G=>G.showAllModels),[d,y]=o.useState({}),[c,N]=o.useState(!1),[b,C]=o.useState({}),[v,S]=o.useState(null),[g,E]=o.useState(""),[M,A]=o.useState([]),[w,h]=o.useState(!1),[j,L]=o.useState(null),[T,P]=o.useState(""),[I,K]=o.useState(""),[W,k]=o.useState(!1),[F,q]=o.useState({}),[U,Q]=o.useState(0),[ne,_]=o.useState(!1),[re,V]=o.useState(null),[$,z]=o.useState(null),[O,Y]=o.useState(null),[Z,ee]=o.useState(null),[ge,de]=o.useState(null),[xe,ae]=o.useState(null),te=n===Ia,me=te&&T===Fn,Pe=!!($&&n&&$===n&&!te);o.useEffect(()=>{!n&&a.length>0&&i(a[0].id)},[a,n,i]),o.useEffect(()=>{if(!n)return;let G=!0;return(async()=>{N(!0);try{const Ae=await fn.getSdkClient().provider.auth();if(Ae.error)throw new Error(`provider.auth failed: ${String(Ae.error)}`);if(!G)return;y(qu(Ae.data))}catch(Ae){if(!G)return;console.error("Failed to load provider auth methods:",Ae),D.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{G&&N(!1)}})(),()=>{G=!1}},[n,t]),o.useEffect(()=>{if(!Hu(te))return;let G=!0;return(async()=>{h(!0),L(null);try{const Ae=await fn.getSdkClient().provider.list();if(Ae.error)throw new Error(`provider.list failed: ${String(Ae.error)}`);if(!G)return;A(Ng(Ae.data))}catch(Ae){if(!G)return;console.error("Failed to load available providers:",Ae),L(t("settings.providers.page.state.unableToLoadProviderList"))}finally{G&&h(!1)}})(),()=>{G=!1}},[te,t]);const Ne=o.useMemo(()=>new Set(a.map(G=>G.id)),[a]),Se=o.useMemo(()=>M.filter(G=>!Ne.has(G.id)).sort((G,ke)=>{const Ae=(G.name||G.id).toLowerCase(),He=(ke.name||ke.id).toLowerCase();return Ae.localeCompare(He)}),[M,Ne]);o.useEffect(()=>{n===Ia&&T&&T!==Fn&&!Se.some(G=>G.id===T)&&P("")},[n,T,Se]),o.useEffect(()=>{if(n===Ia){_(!0),V(null),z(null),Y(null),ee(null),de(null);return}_(!1),V(null),$&&$!==n&&(z(null),Y(null),ee(null),de(null))},[n,$]),o.useEffect(()=>{if(!n||n===Ia)return;const G=F[n];if(!G)return;const ke=a.find(at=>at.id===n),Ae=No({key:ke?.key,authSourceExists:G.auth.exists,optionsApiKey:ke?.options?.apiKey??null,envDeclared:To(ke)}),He=!!(ke&&So(ke,G));Qu({hasCredentials:Ae,userDismissed:re===n,isEditableCustomProvider:He})&&_(!0)},[n,F,a,re]),o.useEffect(()=>{if(!n||n===Ia)return;let G=!1;return(async()=>{try{const Ae=e?`?directory=${encodeURIComponent(e)}`:"",He=await mt(`/api/provider/${encodeURIComponent(n)}/source${Ae}`,{method:"GET",headers:{Accept:"application/json"}}),at=await He.json().catch(()=>null);if(!He.ok)throw new Error(at?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const nt=at?.sources??at?.data?.sources;!G&&nt&&q(dt=>({...dt,[n]:nt}))}catch(Ae){G||console.error("Failed to load provider sources:",Ae)}})(),()=>{G=!0}},[n,U,e,t]);const be=o.useCallback(()=>{Q(G=>G+1)},[]),Fe=o.useCallback(G=>{q(ke=>{const Ae=ke[G];return{...ke,[G]:{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}:{}}}}),V(null),_(!1),i(G),be()},[be,i]),Le=o.useCallback(async(G,ke)=>{try{return await gl({scopes:[G],mode:"active"}),"reloaded"}catch(Ae){if(Ae?.requiresManualRestart===!0)return ke&&_n(G,{id:ke}),"manual-restart";throw Ae}},[]),oe=a.find(G=>G.id===n),fe=n?F[n]:void 0,De=async G=>{const ke=b[G]?.trim()??"";if(!ke){D.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ae=`api:${G}`;S(Ae);try{if((await fn.getSdkClient().auth.set({providerID:G,auth:{type:"api",key:ke}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));D.success(t("settings.providers.page.toast.apiKeySaved")),C(at=>({...at,[G]:""})),await Le("providers",G),Fe(G)}catch(He){console.error("Failed to save API key:",He),D.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{S(null)}},$e=async G=>{const ke=`custom:${G.providerID}`;S(ke),ae(G.providerID),de(null);try{const Ae=rg(G);if(Ae&&(await fn.getSdkClient().auth.set(Ae)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const He=og(G,{scope:$?Z??Co(F[$]):"user"}),at=await mt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(He)}),nt=await at.json().catch(()=>null);if(!at.ok)throw Ae&&de(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(nt?.error||t("settings.providers.page.toast.customProviderSaveFailed"));D.success(t("settings.providers.page.toast.customProviderSaved",{provider:G.name})),P(""),z(null),Y(null),ee(null),de(null),ae(null),await Le("providers",G.providerID),Fe(G.providerID)}catch(Ae){console.error("Failed to save custom provider:",Ae),D.error(Ae instanceof Error&&Ae.message?Ae.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{S(null)}},Ve=G=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(G+1)}),qe=G=>{_(!1),Wu(G)&&_n("providers",{id:G}),Fe(G)},se=async G=>{const ke=`disconnect:${G}`;S(ke);try{const Ae=await mt(`/api/provider/${encodeURIComponent(G)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),He=await Ae.json().catch(()=>null);if(!Ae.ok)throw new Error(He?.error||t("settings.providers.page.toast.providerDisconnectFailed"));D.success(t("settings.providers.page.toast.providerDisconnected")),await Le("providers",G),V(null),be()}catch(Ae){console.error("Failed to disconnect provider:",Ae),D.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{S(null)}},ie=async G=>{G&&(await se(G),z(null),Y(null),ee(null),de(null),ae(null),P(""))};if(!te&&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(R,{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(te)return s.jsxs(ss,{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")}),w?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):j?s.jsx("p",{className:"typography-meta text-muted-foreground",children:j}):s.jsxs(an,{open:W,onOpenChange:G=>{k(G),G||K("")},children:[s.jsx(sn,{asChild:!0,children:s.jsxs("button",{type:"button",className:In,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[T&&T!==Fn?s.jsx(zn,{providerId:T,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ve("truncate typography-ui-label font-normal",T?"text-foreground":"text-muted-foreground"),children:T===Fn?t("settings.providers.page.custom.optionLabel"):T?Se.find(G=>G.id===T)?.name||T:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(nn,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:G=>G.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:G=>G.stopPropagation(),children:[s.jsx(R,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:I,onChange:G=>K(G.target.value),onKeyDown:G=>G.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(Bs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const G=t("settings.providers.page.custom.optionLabel"),ke=kc([G,"other","custom"],I),Ae=gi(Se,I,He=>[He.name||He.id,He.id]);return Ae.length===0&&!ke?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(He=>s.jsxs(rn,{onSelect:()=>{P(He.id),k(!1),K("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(zn,{providerId:He.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:He.name||He.id})]}),T===He.id&&s.jsx(R,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},He.id)),ke?s.jsxs(rn,{onSelect:()=>{P(Fn),k(!1),K("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(R,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:G})]}),T===Fn&&s.jsx(R,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Fn):null]})})()})]})]})]})}),me?s.jsx(Po,{mode:"create",existingProviderIDs:Ne,busy:v?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{P(""),de(null),ae(null)},onDisconnect:ge&&xe?()=>{ie(xe)}:void 0,onSubmit:$e}):T?s.jsx(_e,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const G=d[T]??[],ke=Do(ko(G),Ve),Ae=wo(G);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(Jt,{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(Je,{type:"password",value:b[T]??"",onChange:He=>C(at=>({...at,[T]:He.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:()=>De(T),disabled:v===`api:${T}`,children:v===`api:${T}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ke.length>0?s.jsx(Ao,{providerId:T,methods:ke,onConnected:()=>qe(T),className:ve(Ae&&"border-t border-[var(--surface-subtle)] pt-2")},T):null]})})()})}):null]});if(!oe)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(R,{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 we=Array.isArray(oe.models)?oe.models:[],ye=d[oe.id]??[],Te=Do(ko(ye),Ve),Ue=wo(ye),Ie=!!fe,je=Ie&&So(oe,fe),Ge=No({key:oe.key,authSourceExists:fe?.auth.exists,optionsApiKey:oe.options?.apiKey??null,envDeclared:To(oe)}),ue=Gu(Ie,Ge,je),Ce=Ju({modelCount:we.length,sourcesLoaded:Ie,hasCredentials:Ge,isEditableCustomProvider:je}),Me=!Ue&&Te.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),Ye=gi(we,g,G=>[typeof G?.name=="string"?G.name:"",typeof G?.id=="string"?G.id:""]);return Pe&&je&&O?s.jsx(ss,{title:oe.name||oe.id,titleLeading:s.jsx(zn,{providerId:oe.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:oe.id}),showSaveStatus:!1,children:s.jsx(Po,{mode:"edit",existingProviderIDs:Ne,initialValues:O,allowExistingAuth:Ge||!Ie,busy:v?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{z(null),Y(null),ee(null),de(null),ae(null)},onDisconnect:()=>{ie(oe.id)},onSubmit:$e})}):s.jsxs(ss,{title:oe.name||oe.id,titleLeading:s.jsx(zn,{providerId:oe.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:oe.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:[je?s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{de(null),Y(ag(oe)),ee(Co(fe)),z(oe.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const G=!ne;_(G),V(G?null:oe.id)},children:t(ne?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:ne?c?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:[Ue?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(Jt,{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(Je,{type:"password",value:b[oe.id]??"",onChange:G=>C(ke=>({...ke,[oe.id]:G.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:()=>De(oe.id),disabled:v===`api:${oe.id}`,children:v===`api:${oe.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Te.length>0&&s.jsx(Ao,{providerId:oe.id,methods:Te,onConnected:()=>qe(oe.id),className:ve(Ue&&"border-t border-[var(--surface-subtle)] pt-2")},oe.id)]}):ue?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(R,{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(Jt,{children:Me})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(R,{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(Jt,{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:fe&&(fe.auth.exists||fe.user.exists||fe.project.exists||fe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[fe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,fe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,fe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,fe.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(B,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>se(oe.id),disabled:v===`disconnect:${oe.id}`,children:v===`disconnect:${oe.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Ce?s.jsxs(_e,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",we.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const G=we.map(ke=>typeof ke?.id=="string"?ke.id:"").filter(ke=>ke.length>0);m(oe.id,G)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>f(oe.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(R,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Je,{value:g,onChange:G=>E(G.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),Ye.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:Ye.map(G=>{const ke=typeof G?.id=="string"?G.id:"",Ae=typeof G?.name=="string"?G.name:ke,He=ke?r(oe.id,ke):void 0,at=l.some(H=>H.providerID===oe.id&&H.modelID===ke),nt=Eo(He?.limit?.context),dt=Eo(He?.limit?.output),xt=[];return He?.tool_call&&xt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),He?.reasoning&&xt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),He?.attachment&&xt.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:ve("flex items-center gap-3",at&&"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:[(nt||dt)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[nt?`${nt} ${t("settings.providers.page.models.tokenBadge.context")}`:"",nt&&dt?" · ":"",dt?`${dt} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),xt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:xt.map(({key:H,icon:Be,label:tt})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:tt,"aria-label":tt,children:s.jsx(R,{name:Be,className:"h-3 w-3"})},H))}),s.jsx("button",{type:"button",onClick:()=>p(oe.id,ke),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(at?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(at?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:at?s.jsx(R,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ke)})})]}):null]})},Cg=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)},Pg=t=>{const e=ut.c(75),{onItemSelect:a}=t,{t:n}=it(),i=ts(Ig),r=ts(Ag),l=ts(Tg),p=ts(Eg),m=ts(Dg),f=ts(Mg),d=ts(Rg),y=ts(Og);let c,N;e[0]!==y?(c=()=>{y()},N=[y],e[0]=y,e[1]=c,e[2]=N):(c=e[1],N=e[2]),o.useEffect(c,N);const b=Lg;let C;e[3]!==d?(C=ee=>{ee!=="usage"&&ee!=="remaining"||(d(ee),b({usageDisplayMode:ee}))},e[3]=d,e[4]=C):C=e[4];const v=C;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=ve("flex h-full flex-col","bg-background"),e[5]=S):S=e[5];let g;e[6]!==n?(g=n("settings.usage.sidebar.title"),e[6]=n,e[7]=g):g=e[7];let E;e[8]!==g?(E=s.jsx("h2",{className:`${on} mb-3`,children:g}),e[8]=g,e[9]=E):E=e[9];let M;e[10]!==n?(M=n("settings.usage.sidebar.total",{count:hi.length}),e[10]=n,e[11]=M):M=e[11];let A;e[12]!==M?(A=s.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[12]=M,e[13]=A):A=e[13];let w;e[14]!==p?(w=()=>p(),e[14]=p,e[15]=w):w=e[15];let h;e[16]!==n?(h=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=h):h=e[17];let j;e[18]!==n?(j=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=j):j=e[19];const L=m&&"animate-spin";let T;e[20]!==L?(T=ve("h-3.5 w-3.5",L),e[20]=L,e[21]=T):T=e[21];let P;e[22]!==T?(P=s.jsx(R,{name:"refresh",className:T}),e[22]=T,e[23]=P):P=e[23];let I;e[24]!==m||e[25]!==h||e[26]!==j||e[27]!==P||e[28]!==w?(I=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(B,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:w,"aria-label":h,title:j,disabled:m,children:P})}),e[24]=m,e[25]=h,e[26]=j,e[27]=P,e[28]=w,e[29]=I):I=e[29];let K;e[30]!==I||e[31]!==A?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[A,I]}),e[30]=I,e[31]=A,e[32]=K):K=e[32];let W;e[33]!==n?(W=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=W):W=e[34];let k;e[35]!==W?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:W}),e[35]=W,e[36]=k):k=e[36];let F;e[37]!==n?(F=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=F):F=e[38];let q;e[39]!==F?(q=s.jsx(It,{className:"w-fit",children:s.jsx(Rt,{placeholder:F})}),e[39]=F,e[40]=q):q=e[40];let U;e[41]!==n?(U=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=U):U=e[42];let Q;e[43]!==U?(Q=s.jsx(ot,{value:"usage",children:U}),e[43]=U,e[44]=Q):Q=e[44];let ne;e[45]!==n?(ne=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=ne):ne=e[46];let _;e[47]!==ne?(_=s.jsx(ot,{value:"remaining",children:ne}),e[47]=ne,e[48]=_):_=e[48];let re;e[49]!==Q||e[50]!==_?(re=s.jsxs(At,{children:[Q,_]}),e[49]=Q,e[50]=_,e[51]=re):re=e[51];let V;e[52]!==v||e[53]!==q||e[54]!==re||e[55]!==f?(V=s.jsxs(Pt,{value:f,onValueChange:v,children:[q,re]}),e[52]=v,e[53]=q,e[54]=re,e[55]=f,e[56]=V):V=e[56];let $;e[57]!==k||e[58]!==V?($=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[k,V]}),e[57]=k,e[58]=V,e[59]=$):$=e[59];let z;e[60]!==K||e[61]!==$||e[62]!==E?(z=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[E,K,$]}),e[60]=K,e[61]=$,e[62]=E,e[63]=z):z=e[63];let O;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(O=hi.map(ee=>{const ge=i.find(Pe=>Pe.providerId===ee.id),de=Cg(ge?.usage),xe=hl(de),ae=ee.id===r,te=ge?.configured??!1,me=te?xe==="critical"?{backgroundColor:"var(--status-error)"}:xe==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ae?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(ee.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-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:me}),s.jsx(zn,{providerId:ee.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:ee.name}),!te&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},ee.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=O):O=e[69];let Y;e[70]!==O?(Y=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:O}),e[70]=O,e[71]=Y):Y=e[71];let Z;return e[72]!==z||e[73]!==Y?(Z=s.jsxs("div",{className:S,children:[z,Y]}),e[72]=z,e[73]=Y,e[74]=Z):Z=e[74],Z};function Ig(t){return t.results}function Ag(t){return t.selectedProviderId}function Tg(t){return t.setSelectedProvider}function Eg(t){return t.fetchAllQuotas}function Dg(t){return t.isLoading}function Mg(t){return t.displayMode}function Rg(t){return t.setDisplayMode}function Og(t){return t.loadSettings}async function Lg(t){try{await vt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Fg=t=>{const e=ut.c(17),{percent:a,tonePercent:n,className:i}=t;let r;e[0]!==a?(r=Nc(a)??0,e[0]=a,e[1]=r):r=e[1];const l=r,p=n??a;let m;e[2]!==p?(m=hl(p),e[2]=p,e[3]=m):m=e[3];const f=m;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 y=d;let c;e[6]!==i?(c=ve("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=c):c=e[7];const N=`${l}%`;let b;e[8]!==y||e[9]!==N?(b={...y,width:N},e[8]=y,e[9]=N,e[10]=b):b=e[10];let C;e[11]!==l||e[12]!==b?(C=s.jsx("div",{className:"h-full transition-all duration-300",style:b,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=b,e[13]=C):C=e[13];let v;return e[14]!==c||e[15]!==C?(v=s.jsx("div",{className:c,children:C}),e[14]=c,e[15]=C,e[16]=v):v=e[16],v},Vi=t=>{const e=ut.c(44),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:p}=t,m=r===void 0?!1:r,f=l===void 0?!1:l,d=ts(Kg),y=ce(zg),c=d==="remaining"?n.remainingPercent:n.usedPercent,N=d==="remaining"?"remaining":"used";let b;e[0]!==c||e[1]!==n.valueLabel?(b=Sc(n.valueLabel,c),e[0]=c,e[1]=n.valueLabel,e[2]=b):b=e[2];const C=b,v=n.resetAfterFormatted??n.resetAtFormatted;let S;e[3]!==v||e[4]!==y||e[5]!==n.resetAt?(S=Cc(n.resetAt,v,y),e[3]=v,e[4]=y,e[5]=n.resetAt,e[6]=S):S=e[6];const g=S;let E;e[7]!==a?(E=Pc(a),e[7]=a,e[8]=E):E=e[8];const M=E;let A;e[9]!==p||e[10]!==m||e[11]!==f?(A=m&&s.jsx(Yi,{checked:f,onChange:ne=>p?.(ne),ariaLabel:"Show in dropdown"}),e[9]=p,e[10]=m,e[11]=f,e[12]=A):A=e[12];let w;e[13]!==M?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:M}),e[13]=M,e[14]=w):w=e[14];let h;e[15]!==i?(h=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=h):h=e[16];let j;e[17]!==w||e[18]!==h?(j=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[w,h]}),e[17]=w,e[18]=h,e[19]=j):j=e[19];let L;e[20]!==j||e[21]!==A?(L=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[A,j]}),e[20]=j,e[21]=A,e[22]=L):L=e[22];const T=C==="-"?"":C;let P;e[23]!==T?(P=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:T}),e[23]=T,e[24]=P):P=e[24];let I;e[25]!==L||e[26]!==P?(I=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[L,P]}),e[25]=L,e[26]=P,e[27]=I):I=e[27];let K;e[28]!==c||e[29]!==n.usedPercent?(K=s.jsx(Fg,{percent:c,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=c,e[29]=n.usedPercent,e[30]=K):K=e[30];const W=g?`Resets ${g}`:"";let k;e[31]!==W?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:W}),e[31]=W,e[32]=k):k=e[32];let F;e[33]!==N?(F=s.jsx("span",{className:"typography-micro text-muted-foreground",children:N}),e[33]=N,e[34]=F):F=e[34];let q;e[35]!==k||e[36]!==F?(q=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[k,F]}),e[35]=k,e[36]=F,e[37]=q):q=e[37];let U;e[38]!==K||e[39]!==q?(U=s.jsxs("div",{className:"mt-2.5",children:[K,q]}),e[38]=K,e[39]=q,e[40]=U):U=e[40];let Q;return e[41]!==I||e[42]!==U?(Q=s.jsxs("div",{className:"py-3",children:[I,U]}),e[41]=I,e[42]=U,e[43]=Q):Q=e[43],Q};function Kg(t){return t.displayMode}function zg(t){return t.timeFormatPreference}const Ug=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,_g=({providerId:t,providerName:e})=>{const{t:a}=it(),[n,i]=o.useState(null),[r,l]=o.useState({}),[p,m]=o.useState(!1),f=`/api/quota/credentials/${t}`;o.useEffect(()=>{mt(f).then(async c=>{if(!c.ok)throw new Error;const N=await c.json();i(N),l({})}).catch(()=>i({configured:!1}))},[f]);const d=async(c,N,b)=>{m(!0);try{const C=await mt(c,{method:N,headers:b?{"Content-Type":"application/json"}:void 0,body:b?JSON.stringify(b):void 0}),v=await C.json().catch(()=>null);if(!C.ok)throw new Error(v?.error);v?.configured!==void 0&&i(v),l({}),D.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(C){D.error(C instanceof Error&&C.message?C.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{m(!1)}},y=(c,N,b)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[N,s.jsx(Je,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[c]??"",onChange:C=>l(v=>({...v,[c]:C.target.value})),placeholder:n?.secretMasked??b})]});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:Ug})]}),t==="ollama-cloud"&&y("cookie",a("settings.providers.page.openCodeGo.authCookie"),"session=..."),t==="exe-dev"&&y("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&y("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&y("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(B,{size:"xs",disabled:p,onClick:()=>d(f,"PUT",r),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(B,{variant:"outline",size:"xs",disabled:p,onClick:()=>d(`${f}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(B,{variant:"outline",size:"xs",disabled:p,onClick:()=>d(`${f}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(B,{variant:"destructive",size:"xs",disabled:p,onClick:()=>d(f,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Mo=(t,e)=>{if(!t)return"-";try{return fl(t,e,{fallback:"-"})}catch{return"-"}},$g=()=>{const{t}=it(),e=ce(k=>k.timeFormatPreference),a=ts(k=>k.results),n=ts(k=>k.selectedProviderId),i=ts(k=>k.setSelectedProvider),r=ts(k=>k.loadSettings),l=ts(k=>k.fetchAllQuotas),p=ts(k=>k.isLoading),m=ts(k=>k.lastUpdated),f=ts(k=>k.error),d=ts(k=>k.dropdownProviderIds),y=ts(k=>k.setDropdownProviderIds),c=ts(k=>k.selectedModels),N=ts(k=>k.toggleModelSelected),b=ts(k=>k.applyDefaultSelections);Ic(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const k=a.find(F=>F.configured)?.providerId;i(k??hi[0]?.id??null)},[a,n,i]);const C=a.find(k=>k.providerId===n)??null,S=hi.find(k=>k.id===n)?.name??n??t("settings.usage.sidebar.title"),g=C?.usage,E=C?.configured&&!C.ok?C.error:null,M=n?d.includes(n):!1,A=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",w=o.useCallback(k=>{if(!n)return;const F=k?Array.from(new Set([...d,n])):d.filter(q=>q!==n);y(F),vt({usageDropdownProviders:F})},[d,n,y]),h=o.useMemo(()=>g?.models?Object.entries(g.models).map(([k,F])=>({name:k,windows:F})).filter(k=>Object.keys(k.windows.windows).length>0):[],[g?.models]);o.useEffect(()=>{n&&h.length>0&&b(n,h.map(k=>k.name))},[n,h,b]);const j=o.useMemo(()=>!n||h.length===0?new Map:Ac(h,k=>k.name,n),[h,n]),L=o.useMemo(()=>{if(!n)return[];const k=Ec(n);return Tc(k)},[n]),[T,P]=o.useState(()=>({})),I=o.useCallback(k=>{P(F=>({...F,[k]:!F[k]}))},[]),K=o.useCallback(k=>{if(!n)return;N(n,k);const F=c[n]??[],U=F.includes(k)?F.filter(ne=>ne!==k):[...F,k],Q={...c,[n]:U};vt({usageSelectedModels:Q})},[n,c,N]),W=n?c[n]??[]:[];return n?s.jsxs(ss,{title:t("settings.usage.page.header.providerUsage",{provider:S}),titleLeading:s.jsx(zn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:p?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):C?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:C.planLabel,time:Mo(m,e)}):t("settings.usage.page.header.lastUpdated",{time:Mo(m,e)}),showSaveStatus:!0,children:[s.jsx(_e,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(gt,{checked:M,onChange:w,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!C&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(f||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:f??E})]}),C&&!C.configured&&!A&&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(_g,{providerId:n,providerName:S}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx(_e,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([k,F])=>s.jsx(Vi,{title:k,window:F},k))})}),h.length>0&&s.jsxs(_e,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[L.map(k=>{const F=j.get(k.id)??[];if(F.length===0)return null;const q=T[k.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Tn,{open:!q,onOpenChange:()=>I(k.id),children:[s.jsxs(En,{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:k.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",F.length,")"]})]}),q?s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Dn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:F.map(U=>{const Q=Object.entries(U.windows.windows);if(Q.length===0)return null;const[ne,_]=Q[0],re=W.includes(U.name);return s.jsx(Vi,{title:ne,subtitle:Ir(U.name),window:_,showToggle:!0,toggleEnabled:re,onToggle:()=>K(U.name)},U.name)})})})]})},k.id)}),(()=>{const k=j.get(null)??[];if(k.length===0)return null;const F=T.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Tn,{open:!F,onOpenChange:()=>I("other"),children:[s.jsxs(En,{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:["(",k.length,")"]})]}),F?s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Dn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:k.map(q=>{const U=Object.entries(q.windows.windows);if(U.length===0)return null;const[Q,ne]=U[0],_=W.includes(q.name);return s.jsx(Vi,{title:Q,subtitle:Ir(q.name),window:ne,showToggle:!0,toggleEnabled:_,onToggle:()=>K(q.name)},q.name)})})})]})})})()]}),C?.configured&&g&&Object.keys(g.windows??{}).length===0&&h.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")})})},Vg="git.commit.generate",ir=Sl(t=>({selectedPromptId:Vg,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Bg=t=>{const e=ut.c(24),{onItemSelect:a}=t,{t:n}=it(),i=ir(Hg),r=ir(Gg);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 p;e[1]===Symbol.for("react.memo_cache_sentinel")?(p={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]=p):p=e[1];let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=m):m=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,p,m,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 y=d;let c;e[5]!==n?(c=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=c):c=e[6];let N;e[7]!==c?(N=s.jsx("h2",{className:on,children:c}),e[7]=c,e[8]=N):N=e[8];let b;e[9]!==n?(b=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=b):b=e[10];let C;e[11]!==b?(C=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[11]=b,e[12]=C):C=e[12];let v;e[13]!==N||e[14]!==C?(v=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[N,C]}),e[13]=N,e[14]=C,e[15]=v):v=e[15];let S;e[16]!==a||e[17]!==i||e[18]!==r||e[19]!==n?(S=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:y.map(E=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(E.groupKey)}),E.items.map(M=>{const A=i===M.id;return s.jsx("button",{type:"button",onClick:()=>{r(M.id),a?.()},className:ve("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(M.titleKey)})},M.id)})]},E.groupKey))}),e[16]=a,e[17]=i,e[18]=r,e[19]=n,e[20]=S):S=e[20];let g;return e[21]!==v||e[22]!==S?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[v,S]}),e[21]=v,e[22]=S,e[23]=g):g=e[23],g};function Hg(t){return t.selectedPromptId}function Gg(t){return t.setSelectedPromptId}const Ro={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"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"}]}},Oo=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Bi=t=>t.endsWith(".visible"),qg=()=>{const{t}=it(),e=o.useCallback(w=>t(w),[t]),a=ir(w=>w.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[p,m]=o.useState({}),[f,d]=o.useState({}),[y,c]=o.useState({}),[N,b]=o.useState(!1);o.useEffect(()=>{let w=!0;return(async()=>{i(!0);try{const j=await Oc();if(!w)return;l(j)}catch(j){console.warn("Failed to load magic prompts:",j),D.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{w&&i(!1)}})(),()=>{w=!1}},[t]);const C=Ro[a]??Ro["git.commit.generate"],v=o.useCallback(w=>Oo(r,w)?r[w]:Mi(w),[r]),S=o.useCallback(w=>p[w]??v(w),[p,v]),g=o.useCallback((w,h)=>{m(j=>j[w]===h?j:{...j,[w]:h})},[]),E=o.useCallback(async w=>{const h=S(w);if(Bi(w)&&h.trim().length===0){D.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}d(j=>({...j,[w]:!0}));try{const j=h===Mi(w)?await Ar(w):await Dc(w,h);l(j.overrides),D.success(t("settings.magicPrompts.page.toast.saved"))}catch(j){const L=j instanceof Error?j.message:String(j);D.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:L})}finally{d(j=>({...j,[w]:!1}))}},[S,t]),M=o.useCallback(async w=>{c(h=>({...h,[w]:!0}));try{const h=await Ar(w);l(h.overrides),m(j=>({...j,[w]:Mi(w)})),D.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(h){const j=h instanceof Error?h.message:String(h);D.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:j})}finally{c(h=>({...h,[w]:!1}))}},[t]),A=o.useCallback(async()=>{b(!0);try{const w=await Mc();l(w.overrides),m({}),D.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(w){const h=w instanceof Error?w.message:String(w);D.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:h})}finally{b(!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(ss,{title:e(C.titleKey),titleAccessory:s.jsx(Jt,{contentClassName:"max-w-xs",children:e(C.descriptionKey)}),headerEnd:s.jsx(B,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{A()},disabled:N||Object.keys(r).length===0,children:t(N?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:C.blocks.map((w,h)=>{const j=Rc(w.id),L=v(w.id),T=S(w.id),P=Oo(r,w.id),I=T!==L,K=Bi(w.id)&&T.trim().length===0,W=f[w.id]===!0,k=y[w.id]===!0;return s.jsxs(_e,{title:e(w.titleKey),info:j.description,description:j.placeholders&&j.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${j.placeholders.map(F=>`{{${F.key}}}`).join(", ")}`:void 0,divider:h>0,settingsItem:Bi(w.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Is,{value:T,onChange:F=>g(w.id,F.target.value),className:"min-h-[220px] font-mono text-sm"}),K&&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(I?"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(B,{variant:"outline",size:"sm",onClick:()=>{M(w.id)},disabled:!P||W||k,children:t(k?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(B,{size:"sm",onClick:()=>{E(w.id)},disabled:!I||W||k||K,children:t(W?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},w.id)})})},Wg=t=>{const e=ut.c(89),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,p]=o.useState(null),[m,f]=o.useState(null),{selectedSnippetName:d,snippets:y,setSelectedSnippet:c,setSnippetDraft:N,deleteSnippet:b,loadSnippets:C}=fi(Ls(Jg));let v,S;e[0]!==C?(v=()=>{C()},S=[C],e[0]=C,e[1]=v,e[2]=S):(v=e[1],S=e[2]),o.useEffect(v,S);let g;e[3]!==a||e[4]!==c||e[5]!==N||e[6]!==y?(g=async()=>{const Ne=new Set(y.map(Qg));let Se="new-snippet",be=1;for(;Ne.has(Se);)Se=`new-snippet-${be++}`;N({name:Se,scope:"global"}),c(Se),a?.()},e[3]=a,e[4]=c,e[5]=N,e[6]=y,e[7]=g):g=e[7];const E=g;let M;e[8]!==i||e[9]!==b||e[10]!==n?(M=async()=>{if(!i)return;await b(i.name)?(D.success(n("settings.snippets.sidebar.toast.deleted")),r(null)):D.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=b,e[10]=n,e[11]=M):M=e[11];const A=M;let w;e[12]!==y?(w=[...y].sort(Yg),e[12]=y,e[13]=w):w=e[13];const h=w;let j;e[14]===Symbol.for("react.memo_cache_sentinel")?(j=ve("flex h-full flex-col","bg-background"),e[14]=j):j=e[14];let L;e[15]!==n?(L=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=L):L=e[16];let T;e[17]!==L?(T=s.jsx("h2",{className:`${on} mb-3`,children:L}),e[17]=L,e[18]=T):T=e[18];let P;e[19]!==y.length||e[20]!==n?(P=n("settings.snippets.sidebar.total",{count:y.length}),e[19]=y.length,e[20]=n,e[21]=P):P=e[21];let I;e[22]!==P?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[22]=P,e[23]=I):I=e[23];let K;e[24]!==n?(K=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=K):K=e[25];let W;e[26]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[26]=W):W=e[26];let k;e[27]!==E||e[28]!==K?(k=s.jsx(B,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:E,"aria-label":K,children:W}),e[27]=E,e[28]=K,e[29]=k):k=e[29];let F;e[30]!==I||e[31]!==k?(F=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,k]}),e[30]=I,e[31]=k,e[32]=F):F=e[32];let q;e[33]!==F||e[34]!==T?(q=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,F]}),e[33]=F,e[34]=T,e[35]=q):q=e[35];let U;if(e[36]!==a||e[37]!==l||e[38]!==m||e[39]!==d||e[40]!==c||e[41]!==h||e[42]!==n){let Ne;e[44]!==a||e[45]!==l||e[46]!==m||e[47]!==d||e[48]!==c||e[49]!==n?(Ne=Se=>s.jsxs(Jn,{open:m===Se.name,onOpenChange:be=>f(be?Se.name:null),children:[s.jsxs(Wn,{render:s.jsx("div",{className:ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",d===Se.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:be=>{be.preventDefault(),f(Se.name)}}),children:[s.jsxs("button",{onClick:()=>{c(Se.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-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",Se.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.${Se.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:Se.description||Se.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(an,{open:l===Se.name,onOpenChange:be=>{be&&f(null),p(be?Se.name:null)},children:[s.jsx(sn,{asChild:!0,children:s.jsx(B,{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:Se.name}),children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:s.jsxs(rn,{onClick:be=>{be.stopPropagation(),r(Se)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Gn,{className:"w-fit min-w-20",children:s.jsxs(qn,{onClick:be=>{be.stopPropagation(),r(Se)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${Se.source}:${Se.filePath}`),e[44]=a,e[45]=l,e[46]=m,e[47]=d,e[48]=c,e[49]=n,e[50]=Ne):Ne=e[50],U=h.map(Ne),e[36]=a,e[37]=l,e[38]=m,e[39]=d,e[40]=c,e[41]=h,e[42]=n,e[43]=U}else U=e[43];let Q;e[51]!==U?(Q=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:U}),e[51]=U,e[52]=Q):Q=e[52];const ne=i!==null;let _;e[53]===Symbol.for("react.memo_cache_sentinel")?(_=Ne=>{Ne||r(null)},e[53]=_):_=e[53];let re;e[54]!==n?(re=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=re):re=e[55];let V;e[56]!==re?(V=s.jsx($t,{children:re}),e[56]=re,e[57]=V):V=e[57];const $=i?.name??"";let z;e[58]!==n||e[59]!==$?(z=n("settings.snippets.sidebar.dialog.deleteDescription",{name:$}),e[58]=n,e[59]=$,e[60]=z):z=e[60];let O;e[61]!==z?(O=s.jsx(Vt,{children:z}),e[61]=z,e[62]=O):O=e[62];let Y;e[63]!==V||e[64]!==O?(Y=s.jsxs(_t,{children:[V,O]}),e[63]=V,e[64]=O,e[65]=Y):Y=e[65];let Z;e[66]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>r(null),e[66]=Z):Z=e[66];let ee;e[67]!==n?(ee=n("settings.common.actions.cancel"),e[67]=n,e[68]=ee):ee=e[68];let ge;e[69]!==ee?(ge=s.jsx(B,{size:"sm",variant:"ghost",onClick:Z,children:ee}),e[69]=ee,e[70]=ge):ge=e[70];let de;e[71]!==n?(de=n("settings.common.actions.delete"),e[71]=n,e[72]=de):de=e[72];let xe;e[73]!==A||e[74]!==de?(xe=s.jsx(B,{size:"sm",onClick:A,children:de}),e[73]=A,e[74]=de,e[75]=xe):xe=e[75];let ae;e[76]!==ge||e[77]!==xe?(ae=s.jsxs(ns,{children:[ge,xe]}),e[76]=ge,e[77]=xe,e[78]=ae):ae=e[78];let te;e[79]!==Y||e[80]!==ae?(te=s.jsxs(zt,{className:"max-w-md",children:[Y,ae]}),e[79]=Y,e[80]=ae,e[81]=te):te=e[81];let me;e[82]!==ne||e[83]!==te?(me=s.jsx(Kt,{open:ne,onOpenChange:_,children:te}),e[82]=ne,e[83]=te,e[84]=me):me=e[84];let Pe;return e[85]!==q||e[86]!==Q||e[87]!==me?(Pe=s.jsxs("div",{className:j,children:[q,Q,me]}),e[85]=q,e[86]=Q,e[87]=me,e[88]=Pe):Pe=e[88],Pe};function Jg(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function Qg(t){return t.name}function Yg(t,e){return t.name.localeCompare(e.name)}const Zg=()=>{const{t}=it(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=fi(Ls(j=>({selectedSnippetName:j.selectedSnippetName,snippets:j.snippets,snippetDraft:j.snippetDraft,setSnippetDraft:j.setSnippetDraft,updateSnippet:j.updateSnippet,createSnippet:j.createSnippet}))),p=o.useMemo(()=>e?a.find(j=>j.name===e||j.aliases.includes(e))??null:null,[e,a]),m=!!(n&&n.name===e&&!p),[f,d]=o.useState(""),[y,c]=o.useState("global"),[N,b]=o.useState(""),[C,v]=o.useState(""),[S,g]=o.useState(""),[E,M]=o.useState(!1),A=o.useRef(null);o.useEffect(()=>{if(m&&n){const j={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};d(j.draftName),c(j.draftScope),b(j.description),v(j.aliases),g(j.content),A.current=j}else if(p){const j={draftName:"",draftScope:"global",description:p.description??"",aliases:p.aliases.join(", "),content:p.content};b(j.description),v(j.aliases),g(j.content),A.current=j}},[p,m,e,n]);const w=o.useMemo(()=>{const j=A.current;return j?m&&f!==j.draftName||m&&y!==j.draftScope?!0:N!==j.description||C!==j.aliases||S!==j.content:!1},[C,S,N,f,y,m]),h=async()=>{const j=m?f.trim().replace(/\s+/g,"-"):e?.trim();if(!j){D.error(t("settings.snippets.page.toast.nameRequired"));return}if(!S.trim()){D.error(t("settings.snippets.page.toast.contentRequired"));return}const L=C.split(",").map(T=>T.trim()).filter(Boolean);M(!0);try{if(!(m?await l(j,S,{aliases:L,description:N,scope:y}):await r(j,{content:S,aliases:L,description:N}))){D.error(t("settings.snippets.page.toast.saveFailed"));return}D.success(t("settings.snippets.page.toast.saved")),m&&i(null)}finally{M(!1)}};return e?s.jsxs(ss,{title:m?t("settings.snippets.page.title.new"):`#${e}`,description:p?p.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(_e,{divider:!1,contentClassName:"space-y-0",children:[m?s.jsxs(Ot,{label:"#",children:[s.jsx(Je,{value:f,onChange:j=>d(j.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Pt,{value:y,onValueChange:j=>c(j),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"global",children:t("settings.common.scope.global")}),s.jsx(ot,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Wt,{label:t("settings.common.field.description"),children:s.jsx(Je,{value:N,onChange:j=>b(j.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Wt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(Je,{value:C,onChange:j=>v(j.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(Jt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Is,{value:S,onChange:j=>g(j.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(B,{onClick:h,disabled:E||!w,size:"xs",className:"!font-normal",children:t(E?"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(R,{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")})]})})},_l=()=>{const{t}=it(),e=et(y=>y.settingsGitmojiEnabled),a=et(y=>y.setSettingsGitmojiEnabled),n=gd(),i=ce(y=>y.gitChangesViewMode),r=ce(y=>y.setGitChangesViewMode),[l,p]=o.useState(!0),m=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{let c=null;if(!c){const N=tn()?.settings;if(N)try{const C=(await N.load())?.settings;C&&(c={gitmojiEnabled:typeof C.gitmojiEnabled=="boolean"?C.gitmojiEnabled:void 0,gitChangesViewMode:C.gitChangesViewMode==="flat"||C.gitChangesViewMode==="tree"?C.gitChangesViewMode:void 0})}catch{}}if(!c){const N=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});N.ok&&(c=await N.json())}c&&(typeof c.gitmojiEnabled=="boolean"&&a(c.gitmojiEnabled),(c.gitChangesViewMode==="flat"||c.gitChangesViewMode==="tree")&&r(c.gitChangesViewMode))}catch(c){console.warn("Failed to load git settings:",c)}finally{p(!1)}})()},[r,a]);const f=o.useCallback(async y=>{a(y);try{await vt({gitmojiEnabled:y})}catch(c){console.warn("Failed to save gitmoji setting:",c)}},[a]),d=o.useCallback(y=>{y!==i&&(r(y),vt({gitChangesViewMode:y}))},[i,r]);return l?null:s.jsx(_e,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(Os,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(un,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:m.map(y=>s.jsx(gn,{selected:i===y.id,onSelect:()=>{d(y.id)},label:y.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:y.label})},y.id))})}),s.jsx(gt,{settingsItem:"git.gitmoji",checked:e,onChange:y=>{f(y)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(gt,{settingsItem:"git.gitignored-files",checked:n,onChange:hd,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Lo=[{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)"}],Xg=[{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"}],eh=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=it(),r=Un(O=>O.getProfileById),l=Un(O=>O.createProfile),p=Un(O=>O.updateProfile),m=Un(O=>O.deleteProfile),f=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),d=a==="new"||n!=null,y=a==="global",[c,N]=o.useState(""),[b,C]=o.useState(""),[v,S]=o.useState(""),[g,E]=o.useState("ssh"),[M,A]=o.useState(""),[w,h]=o.useState(!1),[j,L]=o.useState(""),[T,P]=o.useState(""),[I,K]=o.useState("keyword"),[W,k]=o.useState("branch"),[F,q]=o.useState(!1),[U,Q]=o.useState(!1),[ne,_]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const O=n.host.split("/"),Y=O.length>=3?O[O.length-1]:n.host;N(Y),C(n.username),S(""),E("token"),A(""),h(!1),L(""),P(n.host),K("string"),k("code")}else if(d)N(""),C(""),S(""),E("ssh"),A(""),h(!1),L(""),P(""),K("keyword"),k("branch");else if(f)N(f.name),C(f.userName),S(f.userEmail),E(f.authType||"ssh"),A(f.sshKey||""),h(f.signCommits===!0),L(f.signingKey||""),P(f.host||""),K(f.color||"keyword"),k(f.icon||"branch");else if(y){const O=r("global");O&&(N(O.name),C(O.userName),S(O.userEmail),E(O.authType||"ssh"),A(O.sshKey||""),h(!1),L(""),P(O.host||""),K(O.color||"keyword"),k(O.icon||"branch"))}}},[t,a,f,d,n,y,r]);const re=async()=>{if(!b.trim()||!v.trim()){D.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(g==="token"&&!T.trim()){D.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(w&&!j.trim()){D.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}q(!0);try{const O={name:c.trim()||b.trim(),userName:b.trim(),userEmail:v.trim(),authType:g,sshKey:g==="ssh"&&M.trim()||null,signCommits:w,signingKey:j.trim()||null,host:g==="token"&&T.trim()||null,color:I,icon:W};let Y;if(d)Y=await l(O);else if(a)Y=await p(a,O);else return;Y?(D.success(i(d?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):D.error(i(d?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(O){console.error("Error saving profile:",O),D.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{q(!1)}},V=async()=>{if(!(!a||d)){_(!0);try{await m(a)?(D.success(i("settings.gitIdentities.editor.toast.profileDeleted")),Q(!1),e(!1)):D.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(O){console.error("Error deleting profile:",O),D.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{_(!1)}}},$=o.useMemo(()=>Lo.find(Y=>Y.key===I)?.cssVar||"var(--syntax-keyword)",[I]),z=n?i("settings.gitIdentities.editor.title.importCredential"):d?i("settings.gitIdentities.editor.title.newIdentity"):y?i("settings.gitIdentities.editor.title.globalIdentity"):f?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(_t,{children:[s.jsx($t,{children:z}),s.jsx(Vt,{children:i(y?"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:[!y&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Et} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(Je,{value:c,onChange:O=>N(O.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:Lo.map(O=>s.jsx("button",{type:"button",onClick:()=>K(O.key),className:ve("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",I===O.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:O.cssVar},title:O.label},O.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:Xg.map(O=>{const Y=O.Icon;return s.jsx("button",{type:"button",onClick:()=>k(O.key),className:ve("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",W===O.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:O.label,children:s.jsx(R,{name:Y,className:"w-3.5 h-3.5",style:{color:W===O.key?$:"var(--surface-muted-foreground)"}})},O.key)})})]})]}),!y&&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:Et,children:i("settings.gitIdentities.editor.field.userName")}),!y&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(Je,{value:b,onChange:O=>C(O.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!y,readOnly:y,disabled:y,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:Et,children:i("settings.gitIdentities.editor.field.emailAddress")}),!y&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(Je,{type:"email",value:v,onChange:O=>S(O.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!y,readOnly:y,disabled:y,className:"h-8"})]})]}),!y&&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(B,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="ssh",onClick:()=>E("ssh"),children:[s.jsx(R,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(B,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="token",onClick:()=>E("token"),children:[s.jsx(R,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),g==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(Je,{value:M,onChange:O=>A(O.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(gt,{checked:w,onChange:h,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:Et,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(Je,{value:j,onChange:O=>L(O.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!w,className:"h-8 font-mono text-xs"})]})]}),g==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(Je,{value:T,onChange:O=>P(O.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(ns,{className:"gap-2",children:[!y&&!d&&s.jsxs(B,{variant:"outline",size:"sm",onClick:()=>Q(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(R,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.common.actions.delete")]}),s.jsx(B,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:i(y?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!y&&s.jsx(B,{size:"sm",onClick:re,disabled:F,children:i(F?"settings.common.actions.saving":d?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Kt,{open:U,onOpenChange:O=>{ne||Q(O)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Vt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:f?.name||c})})]}),s.jsxs(ns,{children:[s.jsx(B,{variant:"ghost",onClick:()=>Q(!1),disabled:ne,children:i("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{V()},disabled:ne,children:i("settings.common.actions.delete")})]})]})})]})},th={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},sh={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},nh=()=>{const t=ut.c(112),{t:e}=it(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:p,loadDiscoveredCredentials:m,loadDefaultGitIdentityId:f,setDefaultGitIdentityId:d,getUnimportedCredentials:y}=Un(Ls(ih)),[c,N]=o.useState(!1),[b,C]=o.useState(null),[v,S]=o.useState(null),[g,E]=o.useState(null),[M,A]=o.useState(!1);let w,h;t[0]!==f||t[1]!==m||t[2]!==p||t[3]!==l?(w=()=>{l(),p(),m(),f()},h=[l,p,m,f],t[0]=f,t[1]=m,t[2]=p,t[3]=l,t[4]=w,t[5]=h):(w=t[4],h=t[5]),o.useEffect(w,h);let j,L,T,P,I,K,W,k,F,q,U,Q,ne,_;if(t[6]!==i||t[7]!==g||t[8]!==r||t[9]!==y||t[10]!==n||t[11]!==a||t[12]!==d||t[13]!==e){const $e=y();let Ve;t[28]===Symbol.for("react.memo_cache_sentinel")?(Ve=(Ie,je)=>{C(Ie),S(je??null),N(!0)},t[28]=Ve):Ve=t[28];const qe=Ve;let se;t[29]!==i||t[30]!==d||t[31]!==e?(se=async Ie=>{const je=i===Ie?null:Ie;if(!await d(je)){D.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}D.success(e(je?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=d,t[31]=e,t[32]=se):se=t[32];const ie=se;let we;t[33]!==g||t[34]!==r||t[35]!==e?(we=async()=>{if(!g)return;A(!0),await r(g.id)?(D.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:g.name})),E(null)):D.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),A(!1)},t[33]=g,t[34]=r,t[35]=e,t[36]=we):we=t[36],T=we,L=ss,t[37]!==e?(I=e("settings.page.git.title"),t[37]=e,t[38]=I):I=t[38],K=!0,j=_e,t[39]!==e?(Q=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=Q):Q=t[40],ne=!1;let ye,Te;t[41]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>qe("new"),Te=s.jsx(R,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=ye,t[42]=Te):(ye=t[41],Te=t[42]);let Ue;t[43]!==e?(Ue=e("settings.common.badge.new"),t[43]=e,t[44]=Ue):Ue=t[44],t[45]!==Ue?(_=s.jsxs(B,{size:"sm",variant:"outline",onClick:ye,children:[Te," ",Ue]}),t[45]=Ue,t[46]=_):_=t[46],P="git.identities",W="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",k=n&&s.jsx(Fo,{profile:n,isDefault:i==="global",onEdit:()=>qe("global"),onToggleDefault:()=>ie("global"),isReadOnly:!0,hasBorder:a.length>0||$e.length>0}),F=a.map((Ie,je)=>s.jsx(Fo,{profile:Ie,isDefault:i===Ie.id,onEdit:()=>qe(Ie.id),onToggleDefault:()=>ie(Ie.id),onDelete:()=>E(Ie),hasBorder:je<a.length-1||$e.length>0},Ie.id)),q=!n&&a.length===0&&$e.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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=$e.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")})}),$e.map((Ie,je)=>s.jsx(ah,{credential:Ie,onImport:()=>qe("new",{host:Ie.host,username:Ie.username}),hasBorder:je<$e.length-1},`${Ie.host}-${Ie.username}`))]}),t[6]=i,t[7]=g,t[8]=r,t[9]=y,t[10]=n,t[11]=a,t[12]=d,t[13]=e,t[14]=j,t[15]=L,t[16]=T,t[17]=P,t[18]=I,t[19]=K,t[20]=W,t[21]=k,t[22]=F,t[23]=q,t[24]=U,t[25]=Q,t[26]=ne,t[27]=_}else j=t[14],L=t[15],T=t[16],P=t[17],I=t[18],K=t[19],W=t[20],k=t[21],F=t[22],q=t[23],U=t[24],Q=t[25],ne=t[26],_=t[27];let re;t[47]!==W||t[48]!==k||t[49]!==F||t[50]!==q||t[51]!==U?(re=s.jsxs("div",{className:W,children:[k,F,q,U]}),t[47]=W,t[48]=k,t[49]=F,t[50]=q,t[51]=U,t[52]=re):re=t[52];let V;t[53]!==j||t[54]!==P||t[55]!==re||t[56]!==Q||t[57]!==ne||t[58]!==_?(V=s.jsx(j,{title:Q,divider:ne,headerAction:_,settingsItem:P,children:re}),t[53]=j,t[54]=P,t[55]=re,t[56]=Q,t[57]=ne,t[58]=_,t[59]=V):V=t[59];let $;t[60]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(_l,{}),t[60]=$):$=t[60];let z;t[61]!==L||t[62]!==I||t[63]!==K||t[64]!==V?(z=s.jsxs(L,{title:I,showSaveStatus:K,children:[V,$]}),t[61]=L,t[62]=I,t[63]=K,t[64]=V,t[65]=z):z=t[65];let O;t[66]!==v||t[67]!==c||t[68]!==b?(O=s.jsx(eh,{open:c,onOpenChange:N,profileId:b,importData:v}),t[66]=v,t[67]=c,t[68]=b,t[69]=O):O=t[69];const Y=g!==null;let Z;t[70]!==M?(Z=$e=>{M||$e||E(null)},t[70]=M,t[71]=Z):Z=t[71];let ee;t[72]!==e?(ee=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=ee):ee=t[73];let ge;t[74]!==ee?(ge=s.jsx($t,{children:ee}),t[74]=ee,t[75]=ge):ge=t[75];const de=g?.name??"";let xe;t[76]!==e||t[77]!==de?(xe=e("settings.gitIdentities.page.deleteDialog.description",{name:de}),t[76]=e,t[77]=de,t[78]=xe):xe=t[78];let ae;t[79]!==xe?(ae=s.jsx(Vt,{children:xe}),t[79]=xe,t[80]=ae):ae=t[80];let te;t[81]!==ge||t[82]!==ae?(te=s.jsxs(_t,{children:[ge,ae]}),t[81]=ge,t[82]=ae,t[83]=te):te=t[83];let me;t[84]===Symbol.for("react.memo_cache_sentinel")?(me=()=>E(null),t[84]=me):me=t[84];let Pe;t[85]!==e?(Pe=e("settings.common.actions.cancel"),t[85]=e,t[86]=Pe):Pe=t[86];let Ne;t[87]!==M||t[88]!==Pe?(Ne=s.jsx(B,{variant:"ghost",onClick:me,disabled:M,children:Pe}),t[87]=M,t[88]=Pe,t[89]=Ne):Ne=t[89];let Se;t[90]!==T?(Se=()=>{T()},t[90]=T,t[91]=Se):Se=t[91];let be;t[92]!==e?(be=e("settings.common.actions.delete"),t[92]=e,t[93]=be):be=t[93];let Fe;t[94]!==M||t[95]!==Se||t[96]!==be?(Fe=s.jsx(B,{size:"sm",variant:"destructive",onClick:Se,disabled:M,children:be}),t[94]=M,t[95]=Se,t[96]=be,t[97]=Fe):Fe=t[97];let Le;t[98]!==Ne||t[99]!==Fe?(Le=s.jsxs(ns,{children:[Ne,Fe]}),t[98]=Ne,t[99]=Fe,t[100]=Le):Le=t[100];let oe;t[101]!==te||t[102]!==Le?(oe=s.jsxs(zt,{className:"max-w-md",children:[te,Le]}),t[101]=te,t[102]=Le,t[103]=oe):oe=t[103];let fe;t[104]!==Y||t[105]!==Z||t[106]!==oe?(fe=s.jsx(Kt,{open:Y,onOpenChange:Z,children:oe}),t[104]=Y,t[105]=Z,t[106]=oe,t[107]=fe):fe=t[107];let De;return t[108]!==z||t[109]!==O||t[110]!==fe?(De=s.jsxs(s.Fragment,{children:[z,O,fe]}),t[108]=z,t[109]=O,t[110]=fe,t[111]=De):De=t[111],De},Fo=t=>{const e=ut.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:p,hasBorder:m}=t,{t:f}=it(),[d,y]=o.useState(!1),c=th[a.icon||"branch"]||"git-branch",N=sh[a.color||""],b=a.authType||"ssh";let C;e[0]!==i?(C=V=>{V.currentTarget===V.target&&(V.key!=="Enter"&&V.key!==" "||(V.preventDefault(),i()))},e[0]=i,e[1]=C):C=e[1];const v=C;let S;e[2]!==n||e[3]!==p||e[4]!==l||e[5]!==r||e[6]!==f?(S=V=>s.jsxs(s.Fragment,{children:[s.jsx(V,{onClick:$=>{$.stopPropagation(),r()},children:f(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!p&&l&&s.jsxs(V,{onClick:$=>{$.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]})]}),e[2]=n,e[3]=p,e[4]=l,e[5]=r,e[6]=f,e[7]=S):S=e[7];const g=S,E=m&&"border-b border-[var(--surface-subtle)]";let M;e[8]!==E?(M=ve("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",E),e[8]=E,e[9]=M):M=e[9];let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=V=>{V.preventDefault(),y(!0)},e[10]=A):A=e[10];let w;e[11]!==v||e[12]!==i||e[13]!==M?(w=s.jsx("div",{className:M,onClick:i,role:"button",tabIndex:0,onKeyDown:v,onContextMenu:A}),e[11]=v,e[12]=i,e[13]=M,e[14]=w):w=e[14];let h;e[15]!==N?(h={color:N},e[15]=N,e[16]=h):h=e[16];let j;e[17]!==c||e[18]!==h?(j=s.jsx(R,{name:c,className:"w-4 h-4 shrink-0",style:h}),e[17]=c,e[18]=h,e[19]=j):j=e[19];let L;e[20]!==a.name?(L=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=L):L=e[21];let T;e[22]!==b?(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:b}),e[22]=b,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 I;e[27]!==p||e[28]!==f?(I=p&&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]=p,e[28]=f,e[29]=I):I=e[29];let K;e[30]!==T||e[31]!==P||e[32]!==I||e[33]!==L?(K=s.jsxs("div",{className:"flex items-center gap-1.5",children:[L,T,P,I]}),e[30]=T,e[31]=P,e[32]=I,e[33]=L,e[34]=K):K=e[34];const W=b==="token"&&a.host?a.host:a.userEmail;let k;e[35]!==W?(k=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:W}),e[35]=W,e[36]=k):k=e[36];let F;e[37]!==K||e[38]!==k?(F=s.jsxs("div",{className:"min-w-0",children:[K,k]}),e[37]=K,e[38]=k,e[39]=F):F=e[39];let q;e[40]!==F||e[41]!==j?(q=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[j,F]}),e[40]=F,e[41]=j,e[42]=q):q=e[42];let U;e[43]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(sn,{asChild:!0,children:s.jsx(B,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:rh,children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=U):U=e[43];let Q;e[44]!==g?(Q=s.jsxs(an,{children:[U,s.jsx(nn,{align:"end",className:"w-fit min-w-28",children:g(rn)})]}),e[44]=g,e[45]=Q):Q=e[45];let ne;e[46]!==q||e[47]!==Q||e[48]!==w?(ne=s.jsxs(Wn,{render:w,children:[q,Q]}),e[46]=q,e[47]=Q,e[48]=w,e[49]=ne):ne=e[49];let _;e[50]!==g?(_=s.jsx(Gn,{className:"w-fit min-w-28",children:g(qn)}),e[50]=g,e[51]=_):_=e[51];let re;return e[52]!==d||e[53]!==ne||e[54]!==_?(re=s.jsxs(Jn,{open:d,onOpenChange:y,children:[ne,_]}),e[52]=d,e[53]=ne,e[54]=_,e[55]=re):re=e[55],re},ah=t=>{const e=ut.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=it();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const p=l,m=p.length>=3?p[p.length-1]:a.host,f=a.host.includes("/"),d=i&&"border-b border-[var(--surface-subtle)]";let y;e[2]!==d?(y=ve("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]=y):y=e[3];let c;e[4]!==m?(c=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:m}),e[4]=m,e[5]=c):c=e[5];const N=f?a.host:a.username;let b;e[6]!==N?(b=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:N}),e[6]=N,e[7]=b):b=e[7];let C;e[8]!==c||e[9]!==b?(C=s.jsxs("div",{className:"min-w-0",children:[c,b]}),e[8]=c,e[9]=b,e[10]=C):C=e[10];let v;e[11]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(R,{name:"download",className:"h-3 w-3"}),e[11]=v):v=e[11];let S;e[12]!==r?(S=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=S):S=e[13];let g;e[14]!==n||e[15]!==S?(g=s.jsxs(B,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[v,S]}),e[14]=n,e[15]=S,e[16]=g):g=e[16];let E;return e[17]!==g||e[18]!==y||e[19]!==C?(E=s.jsxs("div",{className:y,children:[C,g]}),e[17]=g,e[18]=y,e[19]=C,e[20]=E):E=e[20],E};function ih(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 rh(t){return t.stopPropagation()}const oh=({embedded:t=!1})=>{const{t:e}=it(),{isMobile:a}=ua(),n=tn()?.github,i=Pn(k=>k.status),r=Pn(k=>k.isLoading),l=Pn(k=>k.hasChecked),p=Pn(k=>k.refreshStatus),m=Pn(k=>k.setStatus),f=o.useCallback(async k=>{await An(k)},[]),[d,y]=o.useState(!1),[c,N]=o.useState(null),[b,C]=o.useState(null),v=o.useRef(null),S=o.useCallback(()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null),C(null)},[]);o.useEffect(()=>((async()=>{try{l||await p(n)}catch(k){console.warn("Failed to load GitHub auth status:",k)}})(),()=>{S()}),[l,p,n,S]);const g=o.useCallback(async()=>{y(!0);try{const k=n?await n.authStart():await(async()=>{const q=await mt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),U=await q.json().catch(()=>null);if(!q.ok||!U||!("deviceCode"in U))throw new Error(U?.error||q.statusText);return U})();N(k),C(Math.max(1,k.interval)*1e3);const F=k.verificationUriComplete||k.verificationUri;f(F)}catch(k){console.error("Failed to start GitHub connect:",k),D.error(e("settings.github.page.toast.startConnectFailed"))}finally{y(!1)}},[f,n,e]),E=o.useCallback(async k=>{if(n)return n.authComplete(k);const F=await mt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:k})}),q=await F.json().catch(()=>null);if(!F.ok||!q)throw new Error(q?.error||F.statusText);return q},[n]);o.useEffect(()=>{if(!(!c?.deviceCode||!b)&&v.current==null)return v.current=window.setInterval(()=>{(async()=>{try{const k=await E(c.deviceCode);if(k.connected){D.success(e("settings.github.page.toast.connected")),N(null),S(),await p(n,{force:!0});return}k.status==="slow_down"&&C(F=>F?F+5e3:5e3),(k.status==="expired_token"||k.status==="access_denied")&&(D.error(k.error||e("settings.github.page.toast.authorizationFailed")),N(null),S())}catch(k){console.warn("GitHub polling failed:",k)}})()},b),()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null)}},[c,b,E,p,n,S,e]);const M=o.useCallback(async k=>{y(!0);try{if(n)await n.authSetGhCliDisabled(k);else{const F=await mt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:k})}),q=await F.json().catch(()=>null);if(!F.ok)throw new Error(q?.error||F.statusText)}D.success(e(k?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await p(n,{force:!0})}catch(F){console.error("Failed to update gh CLI setting:",F),D.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{y(!1)}},[p,n,e]),A=o.useCallback(async()=>{y(!0);try{if(S(),N(null),n)await n.authDisconnect();else{const k=await mt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!k.ok)throw new Error(k.statusText)}D.success(e("settings.github.page.toast.disconnected")),await p(n,{force:!0})}catch(k){console.error("Failed to disconnect GitHub:",k),D.error(e("settings.github.page.toast.disconnectFailed"))}finally{y(!1)}},[p,n,S,e]),w=o.useCallback(async k=>{if(k){y(!0);try{const F=n?await n.authActivate(k):await(async()=>{const q=await mt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:k})}),U=await q.json().catch(()=>null);if(!q.ok||!U)throw new Error(U?.error||q.statusText);return U})();m(F),D.success(e("settings.github.page.toast.accountSwitched"))}catch(F){console.error("Failed to switch GitHub account:",F),D.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{y(!1)}}},[n,m,e]);if(r&&!l)return null;const h=!!i?.connected,j=i?.user,T=(i?.accounts??[]).filter(k=>!k.current),P=i?.ghCli??null,I=P?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),K=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[h?s.jsxs("div",{className:ve("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ve("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:j.login?e("settings.github.page.avatarAlt.withLogin",{login:j.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:j?.name?.trim()||j?.login||"GitHub"}),s.jsxs("div",{className:ve("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(R,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:j?.login||e("settings.github.page.label.unknownUser")}),j?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&s.jsx("span",{children:j.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:I})]}),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(B,{size:"sm",variant:"outline",onClick:()=>M(!0),disabled:d,className:ve(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(B,{size:"sm",variant:"outline",onClick:A,disabled:d,className:ve("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(B,{size:"sm",variant:"default",onClick:g,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(k=>{const F=k.user,q=k.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:[F?.avatarUrl?s.jsx("img",{src:F.avatarUrl,alt:F.login?e("settings.github.page.avatarAlt.withLogin",{login:F.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(R,{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:F?.name?.trim()||F?.login||"GitHub"}),F?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:F.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:q})]})]})]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>w(k.id),disabled:d,children:e("settings.github.page.actions.switchTo")})]},k.id)})})]})]}),h&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(B,{size:"sm",variant:"outline",onClick:g,disabled:d,className:ve(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),c&&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(Js,{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:c.userCode}),s.jsx(B,{size:"sm",asChild:!0,children:s.jsx("a",{href:c.verificationUriComplete||c.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(B,{size:"sm",variant:"ghost",disabled:d,onClick:()=>{S(),N(null)},children:e("settings.common.actions.cancel")})]})]})]}),W=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:ve("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ve("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(R,{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:ve("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(R,{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:ve("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(B,{size:"sm",variant:"outline",onClick:()=>M(!P.disabled),disabled:d,className:ve(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:[K,W?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Js,{children:e("settings.github.page.ghCli.title")}),W]}):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:K}),W?s.jsx(_e,{title:e("settings.github.page.ghCli.title"),children:W}):null]})},lh=()=>{const t=ut.c(37),{t:e}=it(),a=Pn(ch),n=Pn(dh),i=Pn(ph),[r,l]=o.useState(!1),p=a?.connected===!0;let m;t[0]!==p||t[1]!==i||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(m=n&&!i?e("common.loading"):p?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=p,t[1]=i,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=m):m=t[5];const f=m,d=p?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let y;t[6]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(R,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=y):y=t[6];let c;t[7]!==e?(c=e("settings.integrations.github.title"),t[7]=e,t[8]=c):c=t[8];let N;t[9]!==c?(N=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:c}),t[9]=c,t[10]=N):N=t[10];let b;t[11]!==e?(b=e("settings.integrations.github.description"),t[11]=e,t[12]=b):b=t[12];let C;t[13]!==b?(C=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:b}),t[13]=b,t[14]=C):C=t[14];let v;t[15]!==N||t[16]!==C?(v=s.jsxs("div",{className:"min-w-0 flex-1",children:[N,C]}),t[15]=N,t[16]=C,t[17]=v):v=t[17];let S;t[18]!==d?(S=ve("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",d),t[18]=d,t[19]=S):S=t[19];let g;t[20]!==f||t[21]!==S?(g=s.jsx("span",{"aria-live":"polite",className:S,children:f}),t[20]=f,t[21]=S,t[22]=g):g=t[22];const E=r&&"rotate-180";let M;t[23]!==E?(M=ve("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",E),t[23]=E,t[24]=M):M=t[24];let A;t[25]!==M?(A=s.jsx(R,{name:"arrow-down-s",className:M}),t[25]=M,t[26]=A):A=t[26];let w;t[27]!==A||t[28]!==v||t[29]!==g?(w=s.jsxs(En,{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:[y,v,g,A]}),t[27]=A,t[28]=v,t[29]=g,t[30]=w):w=t[30];let h;t[31]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Dn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(oh,{embedded:!0})}),t[31]=h):h=t[31];let j;t[32]!==w?(j=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[w,h]}),t[32]=w,t[33]=j):j=t[33];let L;return t[34]!==r||t[35]!==j?(L=s.jsx(Tn,{open:r,onOpenChange:l,children:j}),t[34]=r,t[35]=j,t[36]=L):L=t[36],L};function ch(t){return t.status}function dh(t){return t.isLoading}function ph(t){return t.hasChecked}const ai="__none__",ii="__inherit__";function mh({linear:t,connected:e,organizationId:a}){const{t:n}=it(),i=Vs(v=>v.projects),[r,l]=o.useState(null),[p,m]=o.useState(!1),[f,d]=o.useState(!1),y=o.useCallback(async()=>{if(!e){l(null),m(!1);return}try{const v=await t.mappingGet();if(v.connected===!1){l(null),m(!1);return}l(v),m(!1)}catch(v){console.error("Failed to load Linear mapping:",v),m(!0)}},[e,t]);o.useEffect(()=>{y()},[y,a]);const c=o.useCallback(async v=>{const S={};for(const g of v.teams??[])g.projectPath&&(S[g.id]=g.projectPath);d(!0),xn("saving");try{const g=await t.mappingSet({defaultProjectPath:v.defaultProjectPath??null,teamProjectPaths:S});if(g.connected===!1){l(null),xn("error");return}l(g),m(!1),xn("saved")}catch(g){console.error("Failed to save Linear mapping:",g),xn("error")}finally{d(!1)}},[t]);if(!e)return null;if(p&&!r)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!r)return null;const N=v=>i.find(g=>g.path===v)?.label?.trim()||v,b=v=>!v||v===ai?n("settings.integrations.linear.mapping.defaultProject.placeholder"):N(v),C=v=>!v||v===ii?n("settings.integrations.linear.mapping.teams.useDefault"):N(v);return s.jsxs("div",{className:qs,children:[i.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Ot,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Pt,{value:r.defaultProjectPath||ai,disabled:f||i.length===0,onValueChange:v=>{c({...r,defaultProjectPath:v===ai?null:v})},children:[s.jsx(It,{size:Lt,className:en,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(Rt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:b})}),s.jsxs(At,{children:[s.jsx(ot,{value:ai,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),r.defaultProjectPath&&!i.some(v=>v.path===r.defaultProjectPath)?s.jsx(ot,{value:r.defaultProjectPath,children:r.defaultProjectPath}):null,i.map(v=>s.jsx(ot,{value:v.path,children:N(v.path)},v.id))]})]})}),s.jsx(Os,{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:qs,children:(r.teams??[]).map(v=>s.jsx(Ot,{label:`${v.key} · ${v.name}`,children:s.jsxs(Pt,{value:v.projectPath||ii,disabled:f||i.length===0,onValueChange:S=>{c({...r,teams:(r.teams??[]).map(g=>g.id===v.id?{...g,projectPath:S===ii?null:S}:g)})},children:[s.jsx(It,{size:Lt,className:en,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:v.key}),children:s.jsx(Rt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:C})}),s.jsxs(At,{children:[s.jsx(ot,{value:ii,children:n("settings.integrations.linear.mapping.teams.useDefault")}),v.projectPath&&!i.some(S=>S.path===v.projectPath)?s.jsx(ot,{value:v.projectPath,children:v.projectPath}):null,i.map(S=>s.jsx(ot,{value:S.path,children:N(S.path)},S.id))]})]})},v.id))})})]})}function uh({linear:t,connected:e}){const{t:a}=it(),[n,i]=o.useState(null),[r,l]=o.useState(!1),[p,m]=o.useState(!1);o.useEffect(()=>{if(!e){i(null),l(!1);return}let d=!1;return t.preferencesGet().then(y=>{d||(i(y.sessionComments),l(!1))}).catch(()=>{d||l(!0)}),()=>{d=!0}},[e,t]);const f=o.useCallback(async d=>{const y=n;i(d),m(!0);try{const c=await t.preferencesSet({sessionComments:d});i(c.sessionComments),xn("saved")}catch{i(y),xn("error")}finally{m(!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:qs,children:s.jsx(Ot,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(li,{checked:n===!0,disabled:n===null||p,onCheckedChange:d=>{f(d)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const gh=3*6e4,hh=1500;function Ko(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 fh(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const xh=()=>{const{t}=it(),e=tn()?.linear,a=ia(P=>P.status),n=ia(P=>P.isLoading),i=ia(P=>P.hasChecked),r=ia(P=>P.refreshStatus),l=ia(P=>P.setStatus),[p,m]=o.useState(!1),[f,d]=o.useState(!1),[y,c]=o.useState(!1),N=o.useRef(null),b=o.useCallback(()=>{N.current!=null&&(window.clearInterval(N.current),N.current=null),d(!1)},[]);o.useEffect(()=>{if(e)return i||r(e),()=>{b()}},[i,r,e,b]);const C=o.useCallback(async()=>{if(!e)return;b(),m(!0);const P=Ko(ia.getState().status);try{const I=await e.authStart(rs()?"desktop":"web");d(!0),c(!0),An(I.authorizationUrl);const K=Date.now()+gh;N.current=window.setInterval(()=>{(async()=>{if(Date.now()>K){b(),D.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const W=await r(e,{force:!0});fh(P,Ko(W))&&(b(),D.success(t("settings.integrations.linear.toast.connected")),fd())})()},hh)}catch(I){console.error("Failed to start Linear connect:",I),D.error(t("settings.integrations.linear.toast.startConnectFailed")),b()}finally{m(!1)}},[r,e,b,t]),v=o.useCallback(async P=>{if(!(!e||!P)){m(!0);try{const I=await e.authActivate(P);l(I),D.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(I){console.error("Failed to switch Linear workspace:",I),D.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{m(!1)}}},[e,l,t]),S=o.useCallback(async()=>{if(e){m(!0);try{b(),await e.authDisconnect(),D.success(t("settings.integrations.linear.toast.disconnected")),await r(e,{force:!0})}catch(P){console.error("Failed to disconnect Linear:",P),D.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{m(!1)}}},[r,e,b,t]);if(!e)return null;const g=!!a?.connected,E=a?.user,M=a?.organization,w=(a?.workspaces??[]).filter(P=>!P.current),h=E?.displayName?.trim()||E?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),j=f?t("settings.integrations.linear.status.waiting"):n&&!i?t("common.loading"):g?M?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),L=f?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":g?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",T=f||y;return s.jsx(Tn,{open:T,onOpenChange:P=>{if(f){c(!0);return}c(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(En,{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(R,{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:ve("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",L),children:j}),s.jsx(R,{name:"arrow-down-s",className:ve("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",T&&"rotate-180")})]}),s.jsx(Dn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[g?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[E?.avatarUrl?s.jsx("img",{src:E.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:h}),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(R,{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:h}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[M?.name,E?.email].filter(Boolean).join(" · ")})]})]}):f?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,g?s.jsxs(s.Fragment,{children:[s.jsx(mh,{linear:e,connected:g,organizationId:M?.id??null}),s.jsx(uh,{linear:e,connected:g}),w.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:w.map(P=>{const I=P.user,K=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:K}),I?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:I.email}):null]}),s.jsx(B,{type:"button",size:"sm",variant:"ghost",onClick:()=>{v(P.id)},disabled:p,children:t("settings.integrations.linear.actions.switchTo")})]},P.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{type:"button",size:"sm",variant:"outline",onClick:()=>{C()},disabled:p||f,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>{S()},disabled:p,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(B,{type:"button",size:"sm",variant:"ghost",disabled:p,onClick:b,children:t("settings.common.actions.cancel")})]}):s.jsxs(B,{type:"button",size:"sm",variant:"default",onClick:()=>{C()},disabled:p||n&&!i,children:[p?s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},bh=()=>{const t=ut.c(18),{t:e}=it();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=ds(),t[0]=a):a=t[0];const n=!a,i=!!tn()?.linear;let r;t[1]!==e?(r=e("settings.page.integrations.title"),t[1]=e,t[2]=r):r=t[2];let l;t[3]!==e?(l=e("settings.page.integrations.description"),t[3]=e,t[4]=l):l=t[4];let p;t[5]!==e?(p=e("settings.integrations.firstParty.title"),t[5]=e,t[6]=p):p=t[6];let m;t[7]!==e?(m=e("settings.integrations.firstParty.info"),t[7]=e,t[8]=m):m=t[8];let f,d;t[9]===Symbol.for("react.memo_cache_sentinel")?(f=n?s.jsx(lh,{}):null,d=i?s.jsx(xh,{}):null,t[9]=f,t[10]=d):(f=t[9],d=t[10]);let y;t[11]!==p||t[12]!==m?(y=s.jsxs(_e,{title:p,info:m,divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[f,d]}),t[11]=p,t[12]=m,t[13]=y):y=t[13];let c;return t[14]!==r||t[15]!==l||t[16]!==y?(c=s.jsx(ss,{title:r,description:l,showSaveStatus:!0,children:y}),t[14]=r,t[15]=l,t[16]=y,t[17]=c):c=t[17],c},vh=[{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"}],yh=[{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"}],jh=[{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"}],Aa="OpenChamber - AI Coding Assistant",zo=[{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"}],Uo=[{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"}],Hi=t=>t==="portrait"||t==="landscape"?t:"system",wh=[{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"}],kh=[{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"}],_o=[{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"}],Nh=[{id:"collapsed",labelKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.openchamber.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.summary.description"}],$o=[{id:"auto",labelKey:"settings.openchamber.visual.option.timeFormat.auto.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.openchamber.visual.option.timeFormat.24h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.openchamber.visual.option.timeFormat.12h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.12h.description"}],Vo=[{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"}],Sh=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Ch=[{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"}],Ph=t=>t==="markdown"?"markdown":"plain",Ih=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],Ah=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],vi=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=it(),l=o.useCallback(u=>r(u),[r]),{isMobile:p}=ua(),{terminal:m}=pl(),{browserTab:f}=Dd(),d=xd(),y=ce(u=>u.showReasoningTraces),c=ce(u=>u.sessionRecapEnabled),N=ce(u=>u.sessionSuggestionEnabled),b=ce(u=>u.setSessionRecapEnabled),C=ce(u=>u.setSessionSuggestionEnabled),v=ce(u=>u.sessionGoalEnabled),S=ce(u=>u.setSessionGoalEnabled),g=ce(u=>u.sessionGoalDefaultBudgetEnabled),E=ce(u=>u.setSessionGoalDefaultBudgetEnabled),M=ce(u=>u.sessionGoalDefaultBudget),A=ce(u=>u.setSessionGoalDefaultBudget),w=ce(u=>u.setShowReasoningTraces),h=ce(u=>u.streamingAutoFollowEnabled),j=ce(u=>u.setStreamingAutoFollowEnabled),L=ce(u=>u.collapsibleThinkingBlocks),T=ce(u=>u.setCollapsibleThinkingBlocks),P=ce(u=>u.mermaidRenderingMode),I=ce(u=>u.setMermaidRenderingMode),K=ce(u=>u.userMessageRenderingMode),W=ce(u=>u.setUserMessageRenderingMode),k=ce(u=>u.collapsibleUserMessages),F=ce(u=>u.setCollapsibleUserMessages),q=ce(u=>u.stickyUserHeader),U=ce(u=>u.promptNavigatorEnabled),Q=ce(u=>u.setStickyUserHeader),ne=ce(u=>u.setPromptNavigatorEnabled),_=ce(u=>u.autoSaveEnabled),re=ce(u=>u.setAutoSaveEnabled),V=ce(u=>u.wideChatLayoutEnabled),$=ce(u=>u.setWideChatLayoutEnabled),z=ce(u=>u.codeBlockLineWrap),O=ce(u=>u.setCodeBlockLineWrap),Y=ce(u=>u.chatRenderMode),Z=ce(u=>u.setChatRenderMode),ee=ce(u=>u.activityRenderMode),ge=ce(u=>u.setActivityRenderMode),de=ce(u=>u.fontSize),xe=ce(u=>u.setFontSize),ae=ce(u=>u.terminalFontSize),te=ce(u=>u.setTerminalFontSize),me=ce(u=>u.terminalShell),Pe=ce(u=>u.setTerminalShell),Ne=ce(u=>u.terminalLoginShells),Se=ce(u=>u.setTerminalLoginShells),be=ce(u=>u.editorFontSize),Fe=ce(u=>u.setEditorFontSize),Le=ce(u=>u.uiFont),oe=ce(u=>u.setUiFont),fe=ce(u=>u.monoFont),De=ce(u=>u.setMonoFont),$e=ce(u=>u.padding),Ve=ce(u=>u.setPadding),qe=ce(u=>u.inputBarOffset),se=ce(u=>u.setInputBarOffset),ie=ce(u=>u.mobileKeyboardMode),we=ce(u=>u.setMobileKeyboardMode),ye=ce(u=>u.diffLayoutPreference),Te=ce(u=>u.setDiffLayoutPreference),Ue=ce(u=>u.showTerminalQuickKeysOnDesktop),Ie=ce(u=>u.sessionTabsEnabled),je=ce(u=>u.setSessionTabsEnabled),Ge=ce(u=>u.setShowTerminalQuickKeysOnDesktop),ue=ce(u=>u.fileEditorKeymap),Ce=ce(u=>u.setFileEditorKeymap),Me=zr(u=>u.followUpBehavior),Ye=zr(u=>u.setFollowUpBehavior),G=ce(u=>u.persistChatDraft),ke=ce(u=>u.setPersistChatDraft),Ae=ce(u=>u.inputSpellcheckEnabled),He=ce(u=>u.setInputSpellcheckEnabled),at=ce(u=>u.largeTextPasteBehavior),nt=ce(u=>u.setLargeTextPasteBehavior),dt=ce(u=>u.showToolFileIcons),xt=ce(u=>u.setShowToolFileIcons),H=ce(u=>u.showTurnChangedFiles),Be=ce(u=>u.setShowTurnChangedFiles),tt=ce(u=>u.showExpandedBashTools),rt=ce(u=>u.setShowExpandedBashTools),pt=ce(u=>u.showExpandedEditTools),Ct=ce(u=>u.setShowExpandedEditTools),Xe=ce(u=>u.timeFormatPreference),Ze=ce(u=>u.setTimeFormatPreference),ht=ce(u=>u.weekStartPreference),Ke=ce(u=>u.setWeekStartPreference),wt=ce(u=>u.showSplitAssistantMessageActions),Ee=ce(u=>u.setShowSplitAssistantMessageActions),jt=ce(u=>u.allowPromptingSubagentSessions),J=ce(u=>u.setAllowPromptingSubagentSessions),he=ce(u=>u.draftStartersVisible),ze=ce(u=>u.setDraftStartersVisible),Re=et(u=>u.settingsMessageStreamTransport),ct=et(u=>u.setSettingsMessageStreamTransport),lt=Re,Qe=et(u=>u.settingsDefaultFileViewerPreview),Nt=et(u=>u.setSettingsDefaultFileViewerPreview),xs=ce(u=>u.isSettingsDialogOpen),{themeMode:es,setThemeMode:Ds,availableThemes:Bt,customThemesLoading:os,reloadCustomThemes:qt,lightThemeId:bs,darkThemeId:ps,setLightThemePreference:vs,setDarkThemePreference:ms}=gr(),[ys,le]=o.useState(!1),ft=o.useMemo(()=>rs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),yt=ce(u=>u.dockBadgeEnabled),Qt=ce(u=>u.setDockBadgeEnabled),Yt=bd(),Ht=ce(u=>u.desktopWindowControlsPosition),as=ce(u=>u.setDesktopWindowControlsPosition),js=ce(u=>u.desktopWindowControlsStyle),ls=ce(u=>u.setDesktopWindowControlsStyle),[St,Tt]=o.useState(0),Ut=ce(u=>u.reportUsage),Mt=ce(u=>u.setReportUsage),is=o.useCallback(u=>{Mt(u),vt({reportUsage:u})},[Mt]),As=o.useCallback(u=>{as(u),vt({desktopWindowControlsPosition:u})},[as]),yi=o.useCallback(u=>{ls(u),vt({desktopWindowControlsStyle:u})},[ls]),Ba=(xs||p||ds())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Ba)return;let u=null,bt=Date.now();const Zt=()=>{const kt=Date.now();kt-bt>=420&&(Tt(Gt=>(Gt+1)%24),bt=kt),u=requestAnimationFrame(Zt)};(typeof document>"u"||document.visibilityState==="visible")&&(u=requestAnimationFrame(Zt));const Xt=()=>{document.visibilityState==="visible"&&u===null?u=requestAnimationFrame(Zt):document.visibilityState!=="visible"&&u!==null&&(cancelAnimationFrame(u),u=null)};return document.addEventListener("visibilitychange",Xt),()=>{document.removeEventListener("visibilitychange",Xt),u!==null&&cancelAnimationFrame(u)}},[Ba]);const ji=o.useCallback(u=>{W(u),vt({userMessageRenderingMode:u})},[W]),wi=o.useCallback(u=>{Q(u),vt({stickyUserHeader:u})},[Q]),Fs=o.useCallback(u=>{ne(u),vt({promptNavigatorEnabled:u})},[ne]),ga=o.useCallback(u=>{ze(u),vt({draftStartersVisible:u})},[ze]),ki=o.useCallback(u=>{F(u),vt({collapsibleUserMessages:u})},[F]),Ha=o.useCallback(u=>{$(u),vt({wideChatLayoutEnabled:u})},[$]),Ni=o.useCallback(u=>{Ee(u),vt({showSplitAssistantMessageActions:u})},[Ee]),Si=o.useCallback(u=>{He(u),vt({inputSpellcheckEnabled:u})},[He]),Ci=o.useCallback(u=>{Z(u),vt({chatRenderMode:u})},[Z]),Pi=o.useCallback(u=>{ct(u),vt({messageStreamTransport:u})},[ct]),Ii=o.useCallback(u=>{ge(u),vt({activityRenderMode:u})},[ge]),ws=o.useCallback(u=>{I(u),vt({mermaidRenderingMode:u})},[I]),Hs=o.useCallback(u=>{xt(u),vt({showToolFileIcons:u})},[xt]),Yn=o.useCallback(u=>{Be(u),vt({showTurnChangedFiles:u})},[Be]),ln=o.useCallback(u=>{Nt(u),vt({defaultFileViewerPreview:u}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:u}}))},[Nt]),bn=o.useCallback(u=>{rt(u),vt({showExpandedBashTools:u})},[rt]),Nr=o.useCallback(u=>{Ct(u),vt({showExpandedEditTools:u})},[Ct]),Qs=o.useCallback(u=>{Ze(u),vt({timeFormatPreference:u})},[Ze]),Ai=o.useCallback(u=>{Ke(u),vt({weekStartPreference:u})},[Ke]),cn=o.useMemo(()=>Bt.filter(u=>u.metadata.variant==="light").sort((u,bt)=>u.metadata.name.localeCompare(bt.metadata.name)),[Bt]),dn=o.useMemo(()=>Bt.filter(u=>u.metadata.variant==="dark").sort((u,bt)=>u.metadata.name.localeCompare(bt.metadata.name)),[Bt]),pn=o.useMemo(()=>cn.find(u=>u.metadata.id===bs)??cn[0],[cn,bs]),Mn=o.useMemo(()=>dn.find(u=>u.metadata.id===ps)??dn[0],[dn,ps]),Zn=o.useCallback((u,bt)=>{const Zt=bt==="dark"?" Dark":" Light";return u.endsWith(Zt)?u.slice(0,-Zt.length):u},[]),pe=u=>t?t.includes(u):!0,cs=ds(),Rn=pe("theme")&&!cs,On=pe("windowControlsPosition")&&Yt,Ga=pe("theme")||pe("timeFormat")||pe("weekStart"),ha=cs?Ga:pe("theme")||On||pe("pwaInstallName")||pe("pwaOrientation")||pe("timeFormat")||pe("weekStart"),qa=pe("fontSize")||pe("terminalFontSize")||pe("editorFontSize")||pe("spacing")||pe("inputBarOffset")&&p,fa=pe("terminalQuickKeys")&&!p||(pe("terminalShell")||pe("terminalLoginShell"))&&!cs||pe("fileEditorKeymap")||pe("autoSaveEnabled")||pe("sessionTabs")&&!cs&&!p,Xn=pe("mermaidRendering")||pe("sessionGoal")&&!cs||pe("userMessageRendering")||pe("chatRenderMode")||pe("messageTransport")||pe("activityRenderMode")&&Y==="sorted"||pe("collapsibleUserMessages")||pe("stickyUserHeader")||pe("promptNavigatorEnabled")&&!cs||pe("wideChatLayout")||pe("codeBlockLineWrap")||pe("splitAssistantMessageActions")||pe("subagentReadOnlyBanner")||pe("diffLayout")||pe("dotfiles")||pe("fileViewerPreview")||pe("reasoning")||pe("followUpBehavior")||pe("persistDraft")||pe("largeTextPaste")||pe("showToolFileIcons")||pe("expandedTools")||!p&&pe("inputSpellcheck"),mn=pe("chatRenderMode")||pe("activityRenderMode")&&Y==="sorted",ea=pe("messageTransport"),Wa=pe("userMessageRendering")||pe("mermaidRendering")||pe("diffLayout")&&!cs||pe("followUpBehavior"),ta=pe("sessionAssist")||pe("sessionGoal")&&!cs||pe("subagentReadOnlyBanner")||pe("collapsibleUserMessages")||pe("stickyUserHeader")||pe("promptNavigatorEnabled")&&!cs||pe("wideChatLayout")||pe("codeBlockLineWrap")||pe("splitAssistantMessageActions")||pe("dotfiles")||pe("fileViewerPreview")||pe("persistDraft")||pe("largeTextPaste")||pe("showToolFileIcons")||pe("showTurnChangedFiles")||!p&&pe("inputSpellcheck")||pe("reasoning")||pe("expandedTools"),sa=ha||qa||fa,Gs=pe("pwaInstallName")&&Vn()&&f&&!rs()&&!cs,vn=pe("pwaOrientation")&&Vn()&&!rs()&&!cs,yn=pe("mobileKeyboardMode")&&Vn()&&!rs()&&!cs&&vd(),na=(pe("terminalShell")||pe("terminalLoginShell"))&&!cs,[xa,ba]=o.useState([]),[Ti,Ei]=o.useState(0);o.useEffect(()=>yl(()=>{ba([]),Ei(u=>u+1)}),[]),o.useEffect(()=>{let u=!1;if(!(!na||!m.listShells))return m.listShells().then(bt=>{u||ba(bt)}).catch(()=>{u||ba([])}),()=>{u=!0}},[na,m,Ti]);const Di=o.useMemo(()=>{const u=xa.filter(bt=>bt.id!=="auto");return me==="auto"||u.some(bt=>bt.id===me)?u:[{id:me,name:me,supportsLogin:!1},...u]},[xa,me]),Ln=xa.find(u=>u.id===me)?.supportsLogin===!0,aa=Ne.includes(me),va=u=>{Se(u?[...Ne.filter(bt=>bt!==me),me]:Ne.filter(bt=>bt!==me))},[ya,x]=o.useState(""),[X,Oe]=o.useState("system"),st=o.useMemo(()=>{const u=$o.find(bt=>bt.id===Xe);return l(u?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Xe,l]),Ft=o.useMemo(()=>{const u=Vo.find(bt=>bt.id===ht);return l(u?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[ht,l]),Ts=o.useMemo(()=>{const u=zo.find(bt=>bt.id===X);return u?l(u.labelKey):void 0},[X,l]),ks=o.useMemo(()=>{const u=Uo.find(bt=>bt.id===ie);return u?l(u.labelKey):void 0},[ie,l]),Ms=o.useCallback(async u=>{if(typeof window>"u")return;const bt=window,Xt=u.trim().replace(/\s+/g," ").slice(0,64);if(await vt({pwaAppName:Xt}),typeof bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const kt=bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Xt);x(kt);return}x(Xt||Aa),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),gs=o.useCallback(async u=>{if(typeof window>"u")return;const bt=window,Zt=Hi(u);if(await vt({pwaOrientation:Zt}),typeof bt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Xt=bt.__OPENCHAMBER_SET_PWA_ORIENTATION__(Zt);Oe(Xt);return}Oe(Zt),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!Gs&&!vn&&!yn)return;let u=!1;return(async()=>{try{const Zt=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Zt.ok){u||x(Aa);return}const Xt=await Zt.json().catch(()=>({})),Gt=(typeof Xt?.pwaAppName=="string"?Xt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ys=Hi(Xt?.pwaOrientation),Dt=Br(Xt?.mobileKeyboardMode);u||(Gs&&x(Gt||Aa),vn&&Oe(Ys),yn&&we(Dt))}catch{u||(Gs&&x(Aa),vn&&Oe("system"),yn&&we("native"))}})(),()=>{u=!0}},[we,yn,Gs,vn]),s.jsxs("div",{className:"space-y-0",children:[ha&&s.jsxs("div",{className:"space-y-0",children:[Rn&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Cn,{children:[s.jsx("div",{className:qs,children:s.jsx(un,{"aria-label":r("settings.openchamber.visual.section.colorMode"),children:vh.map(u=>s.jsx(gn,{selected:es===u.value,onSelect:()=>Ds(u.value),label:l(u.labelKey),ariaLabel:l(u.labelKey)},u.value))})}),s.jsxs("div",{className:qs,children:[s.jsx(Wt,{label:r("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(Pt,{value:pn?.metadata.id??"",onValueChange:vs,children:[s.jsx(It,{"aria-label":r("settings.openchamber.visual.field.selectLightThemeAria"),size:Lt,className:jn,children:s.jsx(Rt,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:pn?Zn(pn.metadata.name,"light"):void 0})}),s.jsx(At,{children:cn.map(u=>s.jsx(ot,{value:u.metadata.id,children:Zn(u.metadata.name,"light")},u.metadata.id))})]})}),s.jsx(Wt,{label:r("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(Pt,{value:Mn?.metadata.id??"",onValueChange:ms,children:[s.jsx(It,{"aria-label":r("settings.openchamber.visual.field.selectDarkThemeAria"),size:Lt,className:jn,children:s.jsx(Rt,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:Mn?Zn(Mn.metadata.name,"dark"):void 0})}),s.jsx(At,{children:dn.map(u=>s.jsx(ot,{value:u.metadata.id,children:Zn(u.metadata.name,"dark")},u.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:os||ys,onClick:()=>{const u=Date.now();le(!0),qt().finally(()=>{const bt=Date.now()-u;if(bt<500){window.setTimeout(()=>{le(!1)},500-bt);return}le(!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(R,{name:"restart",className:ve("h-3.5 w-3.5",ys&&"animate-spin")}),r(ys?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Jt,{children:r("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),ft&&s.jsx(Ua,{settingsItem:"appearance.dock-badge",children:s.jsx(gt,{checked:yt,onChange:Qt,label:r("settings.openchamber.visual.field.dockBadge"),info:r("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:r("settings.openchamber.visual.field.dockBadge")})})]}),On&&s.jsx(_e,{title:r("settings.openchamber.desktopNetwork.field.windowControls"),info:r("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:Rn,children:s.jsxs(Cn,{children:[s.jsx(Wt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Ws,{value:Ht,options:Ih.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:As,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Wt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Ws,{value:js,options:Ah.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:yi,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),Ga&&s.jsx(_e,{title:r("settings.openchamber.visual.section.localization"),children:s.jsxs(Cn,{children:[s.jsx(Wt,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Pt,{value:e,onValueChange:u=>n(u),children:[s.jsx(It,{"aria-label":r("settings.appearance.language.select"),size:Lt,className:jn,children:s.jsx(Rt,{children:i(e)})}),s.jsx(At,{children:a.map(u=>s.jsx(ot,{value:u,children:i(u)},u))})]})}),(pe("timeFormat")||pe("weekStart"))&&s.jsxs("div",{className:qs,children:[pe("timeFormat")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Pt,{value:Xe,onValueChange:u=>Qs(u),children:[s.jsx(It,{"aria-label":r("settings.openchamber.visual.field.selectTimeFormatAria"),size:Lt,className:jn,children:s.jsx(Rt,{children:st})}),s.jsx(At,{children:$o.map(u=>s.jsx(ot,{value:u.id,children:l(u.labelKey)},u.id))})]})}),pe("weekStart")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Pt,{value:ht,onValueChange:u=>Ai(u),children:[s.jsx(It,{"aria-label":r("settings.openchamber.visual.field.selectWeekStartAria"),size:Lt,className:jn,children:s.jsx(Rt,{children:Ft})}),s.jsx(At,{children:Vo.map(u=>s.jsx(ot,{value:u.id,children:l(u.labelKey)},u.id))})]})})]})]})}),(Gs||vn||yn)&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.appInstall"),contentClassName:qs,children:[Gs&&s.jsxs(Ot,{label:r("settings.openchamber.visual.field.installAppName"),info:r("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:zs,children:[s.jsx(Je,{value:ya,onChange:u=>{x(u.target.value)},onBlur:()=>{Ms(ya)},onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),Ms(ya))},className:"min-w-0 flex-1",maxLength:64,"aria-label":r("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{x(Aa),Ms("")},className:hs,"aria-label":r("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]}),vn&&s.jsxs(Ot,{label:r("settings.openchamber.visual.field.installOrientation"),description:r("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:zs,children:[s.jsxs(Pt,{value:X,onValueChange:u=>{const bt=Hi(u);Oe(bt),gs(bt)},children:[s.jsx(It,{"aria-label":r("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Lt,className:Tr,children:s.jsx(Rt,{placeholder:r("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Ts})}),s.jsx(At,{children:zo.map(u=>s.jsx(ot,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Oe("system"),gs("system")},disabled:X==="system",className:hs,"aria-label":r("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]}),yn&&s.jsxs(Ot,{label:r("settings.openchamber.visual.field.mobileKeyboardMode"),info:r("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:zs,children:[s.jsxs(Pt,{value:ie,onValueChange:u=>{const bt=Br(u);we(bt),vt({mobileKeyboardMode:bt})},children:[s.jsx(It,{"aria-label":r("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Lt,className:Tr,children:s.jsx(Rt,{placeholder:r("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:ks})}),s.jsx(At,{children:Uo.map(u=>s.jsx(ot,{value:u.id,children:l(u.labelKey)},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{we("native"),vt({mobileKeyboardMode:"native"})},disabled:ie==="native",className:hs,"aria-label":r("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),qa&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.densityAndType"),contentClassName:qs,children:[pe("fontSize")&&!p||pe("terminalFontSize")?s.jsxs(Cn,{children:[pe("fontSize")&&!p&&s.jsxs(Wt,{label:r("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Pt,{value:Le,onValueChange:u=>oe(u),children:[s.jsx(It,{"aria-label":r("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Lt,className:jn,children:s.jsx(Rt,{children:Ur.find(u=>u.id===Le)?.label})}),s.jsx(At,{children:Ur.map(u=>s.jsx(ot,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>oe(_r),disabled:Le===_r,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]}),pe("terminalFontSize")&&s.jsxs(Wt,{label:r("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Pt,{value:fe,onValueChange:u=>De(u),children:[s.jsx(It,{"aria-label":r("settings.openchamber.visual.field.selectCodeFontAria"),size:Lt,className:jn,children:s.jsx(Rt,{children:$r.find(u=>u.id===fe)?.label})}),s.jsx(At,{children:$r.map(u=>s.jsx(ot,{value:u.id,children:s.jsx("span",{style:{fontFamily:u.stack},children:u.label})},u.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>De(Vr),disabled:fe===Vr,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,pe("fontSize")&&!p||pe("terminalFontSize")||pe("editorFontSize")?s.jsxs(Cn,{children:[pe("fontSize")&&!p&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:wa,children:[s.jsx(Ss,{value:de,onValueChange:xe,min:50,max:200,step:5,className:Ps,"aria-label":r("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:ka,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>xe(100),disabled:de===100,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})}),pe("terminalFontSize")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:wa,children:[s.jsx(Ss,{value:ae,onValueChange:te,min:9,max:52,step:1,className:Ps}),s.jsx("span",{className:ka,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>te(13),disabled:ae===13,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})}),pe("editorFontSize")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:wa,children:[s.jsx(Ss,{value:be,onValueChange:Fe,min:9,max:32,step:1,className:Ps}),s.jsx("span",{className:ka,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Fe(13),disabled:be===13,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,pe("spacing")||pe("inputBarOffset")&&p?s.jsxs(Cn,{children:[pe("spacing")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:wa,children:[s.jsx(Ss,{value:$e,onValueChange:Ve,min:50,max:200,step:5,className:Ps}),s.jsx("span",{className:ka,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ve(100),disabled:$e===100,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})}),pe("inputBarOffset")&&p&&s.jsx(Wt,{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(Ss,{value:qe,onValueChange:se,min:0,max:100,step:5,className:Ps}),s.jsx("span",{className:ka,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>se(0),disabled:qe===0,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null]}),fa&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[pe("fileEditorKeymap")&&s.jsx(Os,{title:r("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(un,{"aria-label":r("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(u=>s.jsx(gn,{selected:ue===u,onSelect:()=>Ce(u),label:r(`settings.openchamber.visual.option.fileEditorKeymap.${u}`),ariaLabel:r(`settings.openchamber.visual.option.fileEditorKeymap.${u}`)},u))})}),s.jsxs("div",{className:fs,children:[pe("autoSaveEnabled")&&s.jsx(gt,{checked:_,onChange:re,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"}),na&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.terminalShell"),info:r("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Pt,{value:me,onValueChange:u=>{yd(u)&&Pe(u)},children:[s.jsx(It,{"aria-label":r("settings.openchamber.visual.field.terminalShellAria"),size:Lt,className:jn,children:s.jsx(Rt,{})}),s.jsxs(At,{children:[s.jsx(ot,{value:"auto",children:r("settings.openchamber.visual.option.terminalShell.auto")}),Di.map(u=>s.jsx(ot,{value:u.id,children:u.name},u.id))]})]})}),na&&Ln&&s.jsx(gt,{checked:aa,onChange:va,label:r("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:r("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),pe("terminalQuickKeys")&&!p&&s.jsx(gt,{checked:Ue,onChange:Ge,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:Hn("ctrl"),alt:Hn("alt")})})]}),pe("sessionTabs")&&!cs&&!p&&s.jsx(Os,{title:r("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(gt,{checked:Ie,onChange:je,label:r("settings.openchamber.visual.field.sessionTabs"),ariaLabel:r("settings.openchamber.visual.field.sessionTabsAria"),info:r("settings.openchamber.visual.field.sessionTabsInfo")})})]}),Xn&&s.jsxs(s.Fragment,{children:[mn&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.chatDisplay"),divider:sa,contentClassName:"space-y-6",children:[pe("chatRenderMode")&&s.jsx(Os,{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:kh.map(u=>{const bt=Y===u.id,Zt=St%12;return s.jsxs("button",{type:"button",onClick:()=>Ci(u.id),"aria-pressed":bt,className:ve("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",bt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ve("typography-ui-label",bt?"text-foreground":"text-muted-foreground"),children:l(u.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:u.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Xt=>{const kt=Xt*3+1,Gt=Zt-kt+1,Ys=Gt<=0?0:Gt===1?42:Gt===2?68:92,Dt=Ys>0;return s.jsxs("div",{className:ve("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Dt?"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:`${Ys}%`}})]},Xt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Xt=>{const kt=Zt>=(Xt+1)*3;return s.jsxs("div",{className:ve("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",kt?"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%"}})]},Xt)})})})]},u.id)})})}),pe("activityRenderMode")&&Y==="sorted"&&s.jsx(Os,{title:r("settings.openchamber.visual.section.activityDefault"),children:s.jsx(un,{"aria-label":r("settings.openchamber.visual.section.activityDefaultAria"),children:Nh.map(u=>s.jsx(gn,{selected:ee===u.id,onSelect:()=>Ii(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(u.labelKey)})},u.id))})})]}),ea&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.messageStreamTransport"),divider:mn||sa,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Ws,{value:lt,options:_o.map(u=>({value:u.id,label:l(u.labelKey)})),onChange:Pi,"aria-label":r("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const u=_o.find(bt=>bt.id===lt);return u?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(u.descriptionKey)}):null})()]}),Wa&&s.jsx(_e,{title:r("settings.openchamber.visual.section.chatMessageOptions"),divider:mn||ea||sa,children:s.jsxs(Cn,{className:"lg:gap-y-6",children:[pe("userMessageRendering")&&s.jsx(Os,{title:r("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(un,{"aria-label":r("settings.openchamber.visual.section.userMessageRenderingAria"),children:wh.map(u=>s.jsx(gn,{selected:Ph(K)===u.id,onSelect:()=>ji(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(u.labelKey)})},u.id))})}),pe("mermaidRendering")&&s.jsx(Os,{title:r("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(un,{"aria-label":r("settings.openchamber.visual.section.mermaidRenderingAria"),children:jh.map(u=>s.jsx(gn,{selected:P===u.id,onSelect:()=>ws(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(u.labelKey)})},u.id))})}),pe("diffLayout")&&!cs&&s.jsx(Os,{title:r("settings.openchamber.visual.section.diffLayout"),children:s.jsx(un,{"aria-label":r("settings.openchamber.visual.section.diffLayoutAria"),children:yh.map(u=>s.jsx(gn,{selected:ye===u.id,onSelect:()=>Te(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.diffLayoutAria",{option:l(u.labelKey)})},u.id))})}),pe("followUpBehavior")&&s.jsx(Os,{title:r("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(un,{"aria-label":r("settings.openchamber.visual.section.followUpBehaviorAria"),children:Sh.map(u=>s.jsx(gn,{selected:Me===u.id,onSelect:()=>Ye(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(u.labelKey)})},u.id))})})]})}),ta&&s.jsxs(s.Fragment,{children:[pe("expandedTools")&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:mn||ea||Wa||sa,contentClassName:fs,children:[s.jsx(gt,{checked:tt,onChange:bn,label:r("settings.openchamber.visual.field.bash"),ariaLabel:r("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(gt,{checked:pt,onChange:Nr,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:fs,children:[s.jsx(gt,{checked:he,onChange:ga,label:r("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:r("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),pe("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:c,onChange:b,label:r("settings.openchamber.visual.field.sessionRecap"),ariaLabel:r("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(gt,{checked:N,onChange:C,label:r("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:r("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),pe("subagentReadOnlyBanner")&&s.jsx(gt,{checked:jt,onChange:J,label:r("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),pe("sessionGoal")&&!cs&&s.jsxs(_e,{title:r("settings.openchamber.visual.goal.sectionTitle"),info:r("settings.openchamber.visual.goal.description"),contentClassName:fs,children:[s.jsx(gt,{checked:v,onChange:S,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(gt,{checked:g,onChange:E,disabled:!v,label:r("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:r("settings.openchamber.visual.goal.budgetAria")}),v&&g?s.jsx(Ss,{value:M,onValueChange:u=>{typeof u=="number"&&Number.isFinite(u)&&u>0&&A(Math.floor(u))},min:1e3,max:1e8,step:5e4}):null]})]}),pe("reasoning")&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:fs,children:[s.jsx(gt,{checked:y,onChange:w,label:r("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:r("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),y&&s.jsx(gt,{checked:L,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:fs,children:s.jsx(gt,{checked:h,onChange:j,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"})}),(pe("collapsibleUserMessages")||pe("stickyUserHeader")||pe("promptNavigatorEnabled")&&!cs||pe("wideChatLayout")||pe("splitAssistantMessageActions")||pe("codeBlockLineWrap"))&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:fs,children:[pe("collapsibleUserMessages")&&s.jsx(gt,{checked:k,onChange:ki,label:r("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),pe("stickyUserHeader")&&s.jsx(gt,{checked:q,onChange:wi,label:r("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:r("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),pe("promptNavigatorEnabled")&&!cs&&s.jsx(gt,{checked:U,onChange:Fs,label:r("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),pe("wideChatLayout")&&s.jsx(gt,{checked:V,onChange:Ha,label:r("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:r("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),pe("splitAssistantMessageActions")&&s.jsx(gt,{checked:wt,onChange:Ni,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")}),pe("codeBlockLineWrap")&&s.jsx(gt,{checked:z,onChange:O,label:r("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(pe("showToolFileIcons")||pe("showTurnChangedFiles")||pe("dotfiles")&&!ds()||pe("fileViewerPreview"))&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:fs,children:[pe("showToolFileIcons")&&s.jsx(gt,{checked:dt,onChange:Hs,label:r("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:r("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),pe("showTurnChangedFiles")&&s.jsx(gt,{checked:H,onChange:Yn,label:r("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),pe("dotfiles")&&!ds()&&s.jsx(gt,{checked:d,onChange:jd,label:r("settings.openchamber.visual.field.showDotfiles"),ariaLabel:r("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),pe("fileViewerPreview")&&s.jsx(gt,{checked:Qe,onChange:ln,label:r("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:r("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(pe("persistDraft")||pe("largeTextPaste")||!p&&pe("inputSpellcheck"))&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:fs,children:[pe("persistDraft")&&s.jsx(gt,{checked:G,onChange:ke,label:r("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:r("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!p&&pe("inputSpellcheck")&&s.jsx(gt,{checked:Ae,onChange:Si,label:r("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"}),pe("largeTextPaste")&&s.jsx(Os,{title:r("settings.openchamber.visual.field.largeTextPaste"),info:r("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(un,{"aria-label":r("settings.openchamber.visual.field.largeTextPasteAria"),children:Ch.map(u=>s.jsx(gn,{selected:at===u.id,onSelect:()=>nt(u.id),label:l(u.labelKey),ariaLabel:r("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:l(u.labelKey)})},u.id))})})]})]})]}),pe("reportUsage")&&s.jsx(_e,{title:r("settings.openchamber.visual.section.privacy"),children:s.jsx(gt,{checked:Ut,onChange:is,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"})})]})},Th=1,Eh=365,Bo=30,Dh=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],$l=()=>{const t=ut.c(88),{t:e}=it(),a=ce(Mh),n=ce(Rh),i=ce(Oh),r=ce(Lh),l=ce(Fh),p=ce(Kh);let m;t[0]===Symbol.for("react.memo_cache_sentinel")?(m={autoRun:!1},t[0]=m):m=t[0];const{candidates:f,isRunning:d,runCleanup:y,action:c}=Lc(m),N=f.length;let b;t[1]!==y||t[2]!==e?(b=async()=>{const de=await y({force:!0});if(de.completedIds.length===0&&de.failedIds.length===0){D.message(de.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}de.completedIds.length>0&&D.success(de.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:de.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:de.completedIds.length})),de.failedIds.length>0&&D.error(de.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:de.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:de.failedIds.length}))},t[1]=y,t[2]=e,t[3]=b):b=t[3];const C=b;let v;t[4]!==e?(v=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=v):v=t[5];let S;t[6]!==e?(S=e("settings.openchamber.sessionRetention.tooltip"),t[6]=e,t[7]=S):S=t[7];let g;t[8]!==e?(g=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=g):g=t[9];let E;t[10]!==e?(E=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=E):E=t[11];let M;t[12]!==a||t[13]!==r||t[14]!==g||t[15]!==E?(M=s.jsx(gt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:g,ariaLabel:E}),t[12]=a,t[13]=r,t[14]=g,t[15]=E,t[16]=M):M=t[16];let A;t[17]!==e?(A=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[17]=e,t[18]=A):A=t[18];let w;t[19]!==e?(w=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[19]=e,t[20]=w):w=t[20];let h;t[21]===Symbol.for("react.memo_cache_sentinel")?(h=ve(Ps,"tabular-nums"),t[21]=h):h=t[21];let j;t[22]!==n||t[23]!==l||t[24]!==w?(j=s.jsx(Ss,{value:n,onValueChange:l,min:Th,max:Eh,step:1,"aria-label":w,className:h}),t[22]=n,t[23]=l,t[24]=w,t[25]=j):j=t[25];let L;t[26]!==e?(L=e("settings.openchamber.sessionRetention.field.days"),t[26]=e,t[27]=L):L=t[27];let T;t[28]!==L?(T=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:L}),t[28]=L,t[29]=T):T=t[29];let P;t[30]!==l?(P=()=>l(Bo),t[30]=l,t[31]=P):P=t[31];const I=n===Bo;let K;t[32]!==e?(K=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[32]=e,t[33]=K):K=t[33];let W;t[34]!==e?(W=e("settings.common.actions.reset"),t[34]=e,t[35]=W):W=t[35];let k;t[36]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"}),t[36]=k):k=t[36];let F;t[37]!==P||t[38]!==I||t[39]!==K||t[40]!==W?(F=s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:P,disabled:I,className:hs,"aria-label":K,title:W,children:k}),t[37]=P,t[38]=I,t[39]=K,t[40]=W,t[41]=F):F=t[41];let q;t[42]!==j||t[43]!==T||t[44]!==F||t[45]!==A?(q=s.jsxs(Ot,{settingsItem:"sessions.retention-period",label:A,children:[j,T,F]}),t[42]=j,t[43]=T,t[44]=F,t[45]=A,t[46]=q):q=t[46];let U;t[47]!==e?(U=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[47]=e,t[48]=U):U=t[48];let Q;t[49]!==e?(Q=Dh.map(de=>({value:de.value,label:e(de.labelKey)})),t[49]=e,t[50]=Q):Q=t[50];let ne;t[51]!==i||t[52]!==p||t[53]!==Q?(ne=s.jsx(Ws,{value:i,onChange:p,options:Q}),t[51]=i,t[52]=p,t[53]=Q,t[54]=ne):ne=t[54];let _;t[55]!==U||t[56]!==ne?(_=s.jsx(Ot,{settingsItem:"sessions.retention-action",label:U,children:ne}),t[55]=U,t[56]=ne,t[57]=_):_=t[57];let re;t[58]!==q||t[59]!==_?(re=s.jsxs(Ua,{className:"space-y-0",children:[q,_]}),t[58]=q,t[59]=_,t[60]=re):re=t[60];let V;t[61]!==e?(V=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[61]=e,t[62]=V):V=t[62];let $;t[63]!==d||t[64]!==e?($=e(d?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[63]=d,t[64]=e,t[65]=$):$=t[65];let z;t[66]!==C||t[67]!==d||t[68]!==$?(z=s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:C,disabled:d,className:"!font-normal",children:$}),t[66]=C,t[67]=d,t[68]=$,t[69]=z):z=t[69];let O;t[70]!==V||t[71]!==z?(O=s.jsx(Ot,{label:V,children:z}),t[70]=V,t[71]=z,t[72]=O):O=t[72];let Y;t[73]!==c||t[74]!==N||t[75]!==e?(Y=c==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:N}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:N}),t[73]=c,t[74]=N,t[75]=e,t[76]=Y):Y=t[76];let Z;t[77]!==Y?(Z=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Y}),t[77]=Y,t[78]=Z):Z=t[78];let ee;t[79]!==O||t[80]!==Z?(ee=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[O,Z]}),t[79]=O,t[80]=Z,t[81]=ee):ee=t[81];let ge;return t[82]!==v||t[83]!==re||t[84]!==S||t[85]!==ee||t[86]!==M?(ge=s.jsxs(_e,{title:v,info:S,children:[M,re,ee]}),t[82]=v,t[83]=re,t[84]=S,t[85]=ee,t[86]=M,t[87]=ge):ge=t[87],ge};function Mh(t){return t.autoDeleteEnabled}function Rh(t){return t.autoDeleteAfterDays}function Oh(t){return t.sessionRetentionAction}function Lh(t){return t.setAutoDeleteEnabled}function Fh(t){return t.setAutoDeleteAfterDays}function Kh(t){return t.setSessionRetentionAction}const Ho=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(ur(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),Vl=()=>{const{t}=it(),e=ce(h=>h.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,p]=o.useState(!1),[m,f]=o.useState(null),[d,y]=o.useState(!1),[c,N]=o.useState([]),[b,C]=o.useState(Fc),[v,S]=o.useState(""),g=o.useMemo(()=>Kc(),[]),E=o.useCallback(async()=>{r(!0),S("");try{const h=await zc();N(h)}catch(h){const j=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.loadFailed");S(j)}finally{r(!1)}},[t]);o.useEffect(()=>{let h=!1;return(async()=>{try{if(!g.supported){h||(n(!1),r(!1));return}h||n(!0)}catch{h||n(!1)}if(!h){const j=await Ri();if(C(j),!j.enabled){N([]),r(!1);return}await E()}})(),()=>{h=!0,Er()}},[E,g.supported]);const M=o.useCallback(async()=>{if(!b.enabled){const h=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");S(h),D.message(h);return}if(!a){S(g.reason),D.message(g.reason);return}if(l){Er(),p(!1);return}S(""),p(!0);try{await Uc(),C(await Ri()),await E(),D.success(t("settings.openchamber.passkeys.toast.added"))}catch(h){if(_c(h)){D.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const j=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.addFailed");S(j),D.error(j)}finally{p(!1)}},[l,E,b.enabled,g.reason,a,t]),A=o.useCallback(async h=>{f(h),S("");try{await $c(h),C(await Ri()),await E(),D.success(t("settings.openchamber.passkeys.toast.removed"))}catch(j){const L=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.removeFailed");S(L),D.error(L)}finally{f(null)}},[E,t]),w=o.useCallback(async()=>{y(!0),S("");try{await Vc(),window.location.reload()}catch(h){const j=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");S(j),D.error(j),y(!1)}},[t]);return s.jsxs(_e,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Ot,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(B,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{M()},disabled:i||d,className:"!font-normal",children:t(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{w()},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")})]}),!b.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),b.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):c.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:c.map(h=>s.jsxs(Ot,{label:s.jsx("span",{title:h.label,children:h.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Ho(h.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:Ho(h.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{A(h.id)},disabled:m===h.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:m===h.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},h.id))})]}),v&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v})})]})},Bl=()=>{const t=ut.c(14),{t:e}=it(),a=Dr(zh),n=Dr(Uh);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(B,{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 p;t[8]!==l?(p=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=p):p=t[9];let m;return t[10]!==i||t[11]!==r||t[12]!==p?(m=s.jsx(_e,{title:i,description:r,children:p}),t[10]=i,t[11]=r,t[12]=p,t[13]=m):m=t[13],m};function zh(t){return t.trustedSchemes}function Uh(t){return t.removeTrustedScheme}const Gi=t=>{const e=da(t);return e||{providerId:"",modelId:""}},Hl=()=>{const{t}=it(),e=et(ae=>ae.setProvider),a=et(ae=>ae.setModel),n=et(ae=>ae.setAgent),i=et(ae=>ae.setCurrentVariant),r=et(ae=>ae.setCurrentVariantOverride),l=et(ae=>ae.setSettingsDefaultModel),p=et(ae=>ae.setSettingsDefaultVariant),m=et(ae=>ae.setSettingsDefaultAgent),f=et(ae=>ae.selectionSource==="manual"),d=Bc(ae=>ae.currentSessionId),y=Mr(ae=>ae.getSessionModelSelection),c=Mr(ae=>ae.getSessionAgentSelection),N=!!(f&&d&&y(d)),b=!!(f&&d&&c(d)),C=ce(ae=>ae.showDeletionDialog),v=ce(ae=>ae.setShowDeletionDialog),S=et(ae=>ae.providers),g=et(ae=>ae.modelsMetadata),[E,M]=o.useState(),[A,w]=o.useState(),[h,j]=o.useState(),[L,T]=o.useState(!0),[P,I]=o.useState(),[K,W]=o.useState([]),[k,F]=o.useState(),[q,U]=o.useState(!0),Q=o.useMemo(()=>Gi(E),[E]);o.useEffect(()=>{(async()=>{try{let te=null;if(!te){const me=tn()?.settings;if(me)try{const Ne=(await me.load())?.settings;if(Ne){const Se=Ne;te={defaultModel:typeof Ne.defaultModel=="string"?Ne.defaultModel:void 0,defaultVariant:typeof Se.defaultVariant=="string"?Se.defaultVariant:void 0,defaultAgent:typeof Ne.defaultAgent=="string"?Ne.defaultAgent:void 0,smallModelUseDefault:typeof Se.smallModelUseDefault=="boolean"?Se.smallModelUseDefault:void 0,smallModelOverride:typeof Se.smallModelOverride=="string"?Se.smallModelOverride:void 0,walkthroughModelOverride:typeof Se.walkthroughModelOverride=="string"?Se.walkthroughModelOverride:void 0}}}catch{}}if(!te){const me=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});me.ok&&(te=await me.json())}if(te){const me=typeof te.defaultModel=="string"&&te.defaultModel.trim().length>0?te.defaultModel.trim():void 0,Pe=typeof te.defaultVariant=="string"&&te.defaultVariant.trim().length>0?te.defaultVariant.trim():void 0,Ne=typeof te.defaultAgent=="string"&&te.defaultAgent.trim().length>0?te.defaultAgent.trim():void 0;me!==void 0&&M(me),Pe!==void 0&&w(Pe),Ne!==void 0&&j(Ne),typeof te.smallModelUseDefault=="boolean"&&T(te.smallModelUseDefault),typeof te.smallModelOverride=="string"&&te.smallModelOverride.trim()&&I(te.smallModelOverride.trim()),typeof te.walkthroughModelOverride=="string"&&te.walkthroughModelOverride.trim()&&F(te.walkthroughModelOverride.trim())}}catch(te){console.warn("Failed to load defaults settings:",te)}finally{U(!1)}})()},[]);const ne=o.useCallback(async(ae,te)=>{const me=ae&&te?`${ae}/${te}`:void 0;M(me),w(void 0),p(void 0),l(me),N||(i(void 0),ae&&te&&S.find(Ne=>Ne.id===ae)&&(e(ae),a(te)));try{await vt({defaultModel:me??"",defaultVariant:""});const Pe=await mt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:me})});Pe.ok||console.warn("Failed to save default model to server:",Pe.status,Pe.statusText)}catch(Pe){console.warn("Failed to save default model:",Pe)}},[N,S,i,a,e,l,p]),_="__default__",re=o.useCallback(ae=>ae===_?t("settings.openchamber.defaults.option.default"):ae.charAt(0).toUpperCase()+ae.slice(1),[t]),V=o.useCallback(async ae=>{const te=ae===_?void 0:ae||void 0;w(te),p(te),N||r(te??null,te);try{await vt({defaultVariant:te??""})}catch(me){console.warn("Failed to save default variant:",me)}},[N,r,p]),$=o.useCallback(async ae=>{const te=ae||void 0;j(te),m(te),ae&&!b&&n(ae);try{await vt({defaultAgent:te??""})}catch(me){console.warn("Failed to save default agent:",me)}},[b,n,m]),z=o.useCallback(async ae=>{T(ae);try{await vt({smallModelUseDefault:ae})}catch(te){console.warn("Failed to save small model preference:",te)}},[]),O=o.useCallback(async(ae,te)=>{const me=ae&&te?`${ae}/${te}`:void 0;I(me);try{await vt({smallModelOverride:me??""})}catch(Pe){console.warn("Failed to save small model override:",Pe)}},[]),Y=o.useCallback(async(ae,te)=>{const me=ae&&te?`${ae}/${te}`:void 0;F(me);try{await vt({walkthroughModelOverride:me??""})}catch(Pe){console.warn("Failed to save walkthrough model override:",Pe)}},[]),Z=o.useCallback((ae,te)=>g.get(`${ae}/${te}`)?.structured_output!==!1,[g]),ee=o.useMemo(()=>Gi(P),[P]),ge=o.useMemo(()=>Gi(k),[k]);o.useEffect(()=>{let ae=!1;return(async()=>{try{const te=await mt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!te.ok)return;const me=await te.json().catch(()=>null);!ae&&Array.isArray(me?.authenticatedProviders)&&W(me.authenticatedProviders.filter(Pe=>typeof Pe=="string"))}catch{}})(),()=>{ae=!0}},[]);const de=o.useMemo(()=>{if(!Q.providerId||!Q.modelId)return[];const me=S.find(Pe=>Pe.id===Q.providerId)?.models.find(Pe=>Pe.id===Q.modelId)?.variants;return me?Object.keys(me):[]},[Q.modelId,Q.providerId,S]),xe=de.length>0;return o.useEffect(()=>{!xe&&A&&(w(void 0),p(void 0),N||i(void 0),vt({defaultVariant:""}).catch(()=>{}))},[N,A,i,p,xe]),q?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")," ",Q.providerId?s.jsxs("span",{className:"text-foreground",children:[Q.providerId,"/",Q.modelId,xe?` (${A??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),h&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:h})]})]}),s.jsxs("div",{children:[s.jsx(Ot,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(Oa,{providerId:Q.providerId,modelId:Q.modelId,onChange:ne,className:In})}),s.jsx(Ot,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Pt,{value:A??_,onValueChange:V,disabled:!xe,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:re(A??_)})}),s.jsxs(At,{children:[s.jsx(ot,{value:_,children:t("settings.openchamber.defaults.option.default")}),de.map(ae=>s.jsx(ot,{value:ae,children:re(ae)},ae))]})]})}),s.jsx(Ot,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(ol,{agentName:h||"",onChange:$,filter:ae=>Hc(ae.mode),className:In})})]}),s.jsx(Ua,{className:fs,children:s.jsx(gt,{settingsItem:"sessions.deletion-dialog",checked:C,onChange:v,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(Js,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Jt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(gt,{settingsItem:"sessions.small-model",checked:L,onChange:ae=>{z(ae)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),L?null:s.jsx(Ot,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(Oa,{providerId:ee.providerId,modelId:ee.modelId,onChange:O,allowedProviderIds:K,className:In})}),s.jsxs(Ua,{className:fs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Js,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Jt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Ot,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(Oa,{providerId:ge.providerId,modelId:ge.modelId,onChange:Y,allowedProviderIds:K,isModelAllowed:Z,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:In})})]})]})]})})})},Go={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"}},_h={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"},$h=()=>{const{t}=it(),e=o.useMemo(()=>rs(),[]),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(V=>V.nativeNotificationsEnabled),l=ce(V=>V.setNativeNotificationsEnabled),p=ce(V=>V.notificationMode),m=ce(V=>V.setNotificationMode),f=ce(V=>V.notifyOnSubtasks),d=ce(V=>V.setNotifyOnSubtasks),y=ce(V=>V.notifyOnCompletion),c=ce(V=>V.setNotifyOnCompletion),N=ce(V=>V.notifyOnError),b=ce(V=>V.setNotifyOnError),C=ce(V=>V.notifyOnQuestion),v=ce(V=>V.setNotifyOnQuestion),S=ce(V=>V.notificationTemplates),g=ce(V=>V.setNotificationTemplates),[E,M]=o.useState("default"),[A,w]=o.useState(!1),[h,j]=o.useState(!1),[L,T]=o.useState(!1);o.useEffect(()=>{if(!i){w(!1),j(!1);return}typeof Notification<"u"&&M(Notification.permission);const V=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;w(V),(async()=>{if(!V){j(!1);return}try{const z=await navigator.serviceWorker.getRegistration();if(!z){j(!1);return}const O=await z.pushManager.getSubscription();j(!!O)}catch{j(!1)}})()},[i]);const P=async V=>{if(e){l(V);return}if(!i){l(V);return}if(V&&typeof Notification<"u"&&Notification.permission==="default")try{const $=await Notification.requestPermission();M($),$==="granted"?l(!0):D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch($){console.error("Failed to request notification permission:",$),D.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(V&&E==="granted"))},I=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",K=(V,$,z)=>{g(O=>({...O,[V]:{...O[V],[$]:z}}))},W=V=>{const $="=".repeat((4-V.length%4)%4),z=(V+$).replace(/-/g,"+").replace(/_/g,"/"),O=atob(z),Y=new Uint8Array(O.length);for(let Z=0;Z<O.length;Z+=1)Y[Z]=O.charCodeAt(Z);return Y},k=async(V,$,z)=>{let O=null;const Y=new Promise((Z,ee)=>{O=setTimeout(()=>{ee(new Error(z))},$)});try{return await Promise.race([V,Y])}finally{O&&clearTimeout(O)}},F=async V=>{if(V.active)return;const $=V.installing||V.waiting;$&&$.state!=="activated"&&await k(new Promise(z=>{const O=()=>{$.state==="activated"&&($.removeEventListener("statechange",O),z())};$.addEventListener("statechange",O),O()}),15e3,"Service worker activation timed out")},q=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const V=[{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 $=null;for(const z of V)try{const O=z.opts?navigator.serviceWorker.register("/sw.js",z.opts):navigator.serviceWorker.register("/sw.js");return await k(O,1e4,`Service worker registration timed out (${z.label})`)}catch(O){$=O}throw $ instanceof Error?$:new Error("Service worker registration failed")},U=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const V=await navigator.serviceWorker.getRegistration();if(V)return V;const $=await q();try{await $.update()}catch{}return await F($),$},Q=V=>{const $=V,z=[`type=${typeof V}`,`toString=${String(V)}`,`name=${String($?.name??"")}`,`message=${String($?.message??"")}`];let O="";try{O=JSON.stringify(V)}catch{}return{summary:z.filter(Boolean).join(" | "),json:O,stack:typeof $?.stack=="string"?$.stack:""}},ne=async()=>{const V=tn();if(!V?.notifications){D.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await V.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?D.success(t("settings.notifications.page.toast.testNotificationSent")):D.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch($){console.error("Test notification failed:",$),D.error(t("settings.notifications.page.toast.testNotificationFailed"))}},_=async()=>{if(!A){D.error(t("settings.notifications.page.toast.pushUnsupported"));return}const V=tn();if(!V?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const de=await Notification.requestPermission();if(M(de),de!=="granted"){D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const $=await V.push.getVapidPublicKey();if(!$?.publicKey){D.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const z=await U();await F(z);const O=await z.pushManager.getSubscription();if(!("pushManager"in z)||!z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Z=(O??await k(z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:W($.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ee=Z.keys;if(!Z.endpoint||!ee?.p256dh||!ee.auth)throw new Error("Push subscription missing keys");if(!(await k(V.push.subscribe({endpoint:Z.endpoint,keys:{p256dh:ee.p256dh,auth:ee.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:wd()}),15e3,"Push subscribe request timed out"))?.ok){D.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}j(!0),D.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch($){console.error("[Push] Enable failed:",$);const z=Q($);D.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:z.summary})}finally{T(!1)}},re=async()=>{if(!A){j(!1);return}const V=tn();if(!V?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{const z=await(await U()).pushManager.getSubscription();if(!z){j(!1);return}const O=z.endpoint;await z.unsubscribe(),await V.push.unsubscribe({endpoint:O}),j(!1),D.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:fs,children:[s.jsx(gt,{checked:r&&I,onChange:V=>{P(V)},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&&I&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:p==="always",onChange:V=>m(V?"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(B,{type:"button",variant:"outline",size:"sm",onClick:()=>{ne()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[E==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),E==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&I&&s.jsxs(s.Fragment,{children:[s.jsx(_e,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(gt,{checked:y,onChange:c,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(gt,{checked:f,onChange:d,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(gt,{checked:N,onChange:b,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(gt,{checked:C,onChange:v,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(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]}),children:s.jsx(Cn,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(V=>s.jsxs("section",{className:"p-2",children:[s.jsx(Js,{className:"capitalize",children:t(_h[V])}),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(Je,{value:S[V].title,onChange:$=>K(V,"title",$.target.value),className:"h-7",placeholder:t(Go[V].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(Je,{value:S[V].message,onChange:$=>K(V,"message",$.target.value),className:"h-7",placeholder:t(Go[V].messageKey)})]})]})]},V))})})]}),i&&s.jsx(_e,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(gt,{checked:A?h:!1,disabled:!A||L,onChange:V=>{V?_():re()},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:L?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})})]})},Es=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Vh=[{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"}],qo=t=>{const e=ut.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 p;e[2]!==n?(p=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=p):p=e[3];let m;return e[4]!==i||e[5]!==l||e[6]!==p?(m=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,p]}),e[4]=i,e[5]=l,e[6]=p,e[7]=m):m=e[7],m},Bh=({selectedModelId:t,onSelect:e})=>{const{t:a}=it(),n=We.useCallback(c=>a(c),[a]),[i,r]=We.useState(new Map),[l,p]=We.useState(null),m=We.useCallback(async()=>{try{const c=await mt("/api/dictation/status",{query:{provider:"local"}});if(!c.ok)return;const N=await c.json();Array.isArray(N?.models)&&r(new Map(N.models.map(b=>[b.id,b])))}catch{}},[]);We.useEffect(()=>{m()},[m]);const f=Array.from(i.values()).some(c=>c.downloading);We.useEffect(()=>{if(!f)return;const c=setInterval(()=>{m()},2e3);return()=>clearInterval(c)},[f,m]);const d=async c=>{p(c);try{await mt(`/api/dictation/models/${encodeURIComponent(c)}/download`,{method:"POST"}),await m()}catch{}finally{p(null)}},y=async c=>{p(c);try{await mt(`/api/dictation/models/${encodeURIComponent(c)}`,{method:"DELETE"}),await m()}catch{}finally{p(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:Vh.map(c=>{const N=t===c.id,b=i.get(c.id)??null;return s.jsx("div",{className:ve("rounded-lg border border-[var(--interactive-border)] p-3",N&&"border-[var(--primary-base)] bg-[var(--primary-base)]/5"),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(c.id),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),e(c.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(dr,{checked:N,onChange:()=>e(c.id),ariaLabel:n(c.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:ve("typography-ui-label font-normal",N?"text-foreground":"text-foreground/50"),children:n(c.labelKey)}),c.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(c.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(qo,{value:c.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(qo,{value:c.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:c.size})]}),b?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:b?.installed?s.jsxs(s.Fragment,{children:[s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===c.id,onClick:()=>{y(c.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(R,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):b?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(R,{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 b.downloadProgress=="number"?`${b.downloadProgress}%`:""})]}):s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===c.id,onClick:()=>{d(c.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(R,{name:"download",className:"h-4 w-4"})})})]})},c.id)})})},Hh=[{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)"}],rr="kokoro-en-v0_19",Gh="kokoro-multi-lang-v1_1",qh=[{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)"}],Ta=(t,e)=>`${t}:${e}`,Wh=()=>{const[t,e]=We.useState([]),[a,n]=We.useState(null),i=We.useCallback(async()=>{try{const p=await mt("/api/dictation/status",{query:{provider:"local"}});if(!p.ok)return;const m=await p.json();Array.isArray(m?.ttsModels)&&e(m.ttsModels)}catch{}},[]);We.useEffect(()=>{i()},[i]);const r=t.some(p=>p.downloading);We.useEffect(()=>{if(!r)return;const p=setInterval(()=>{i()},2e3);return()=>clearInterval(p)},[r,i]);const l=We.useCallback(async(p,m)=>{n(p);try{const f=m==="POST"?`/api/dictation/models/${p}/download`:`/api/dictation/models/${p}`;await mt(f,{method:m}),await i()}catch{}finally{n(null)}},[i]);return{models:t,requestingId:a,request:l,refresh:i}},Jh=t=>{const e=Hh.map(a=>({modelId:rr,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===rr||!a.installed)){if(a.id===Gh){for(const n of qh)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},Qh=t=>{const e=ut.c(14),{models:a,requestingId:n,request:i}=t,{t:r}=it();let l,p,m;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==r){m=Symbol.for("react.early_return_sentinel");e:{const d=a.filter(Xh);if(d.length===0){m=null;break e}l="flex flex-col";let y;e[7]!==i||e[8]!==n||e[9]!==r?(y=c=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:c.description??c.id}),c.installed?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":r("settings.voice.page.stt.modelInstalled")}),s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{i(c.id,"DELETE")},title:r("settings.voice.page.stt.modelDelete"),"aria-label":r("settings.voice.page.stt.modelDelete"),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})})]}):c.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(R,{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 c.downloadProgress=="number"?`${c.downloadProgress}%`:""})]}):s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{i(c.id,"POST")},title:r("settings.voice.page.stt.modelDownload"),"aria-label":r("settings.voice.page.stt.modelDownload"),children:s.jsx(R,{name:"download",className:"h-4 w-4"})}),c.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:c.downloadError}):null]},c.id),e[7]=i,e[8]=n,e[9]=r,e[10]=y):y=e[10],p=d.map(y)}e[0]=a,e[1]=i,e[2]=n,e[3]=r,e[4]=l,e[5]=p,e[6]=m}else l=e[4],p=e[5],m=e[6];if(m!==Symbol.for("react.early_return_sentinel"))return m;let f;return e[11]!==l||e[12]!==p?(f=s.jsx("div",{className:l,children:p}),e[11]=l,e[12]=p,e[13]=f):f=e[13],f},Yh=[{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"}],Zh=()=>{const{t}=it(),{isMobile:e}=ua(),a=et(H=>H.voiceProvider),n=et(H=>H.setVoiceProvider),i=et(H=>H.speechRate),r=et(H=>H.setSpeechRate),l=et(H=>H.speechPitch),p=et(H=>H.setSpeechPitch),m=et(H=>H.speechVolume),f=et(H=>H.setSpeechVolume),d=et(H=>H.sayVoice),y=et(H=>H.setSayVoice),c=et(H=>H.localTtsVoiceId),N=et(H=>H.localTtsModelId),b=et(H=>H.setLocalTtsModelId),C=Wh(),v=We.useMemo(()=>Jh(C.models),[C.models]),S=et(H=>H.ttsFollowTextLanguage),g=et(H=>H.setTtsFollowTextLanguage),E=et(H=>H.setLocalTtsVoiceId),{speak:M,stop:A,isPlaying:w,error:h}=Gc(),j=We.useCallback(()=>{if(w){A();return}const H=v.find(Be=>Be.modelId===N&&Be.speakerId===c)?.label??String(c);M(t("settings.voice.page.preview.voiceLine",{voiceName:H}),{model:N,speakerId:c,speed:et.getState().speechRate})},[w,N,c,v,M,A,t]),L=et(H=>H.browserVoice),T=et(H=>H.setBrowserVoice),P=et(H=>H.openaiVoice),I=et(H=>H.setOpenaiVoice),K=et(H=>H.openaiApiKey),W=et(H=>H.setOpenaiApiKey),k=et(H=>H.openaiCompatibleUrl),F=et(H=>H.setOpenaiCompatibleUrl),q=et(H=>H.openaiCompatibleApiKey),U=et(H=>H.setOpenaiCompatibleApiKey),Q=et(H=>H.openaiCompatibleVoice),ne=et(H=>H.setOpenaiCompatibleVoice),_=et(H=>H.openaiCompatibleTtsModel),re=et(H=>H.setOpenaiCompatibleTtsModel),V=et(H=>H.showMessageTTSButtons),$=et(H=>H.ttsInputMode),z=et(H=>H.setTtsInputMode),O=et(H=>H.sttProvider),Y=et(H=>H.setSttProvider),Z=et(H=>H.sttServerUrl),ee=et(H=>H.setSttServerUrl),ge=et(H=>H.sttApiKey),de=et(H=>H.setSttApiKey),xe=et(H=>H.sttModel),ae=et(H=>H.setSttModel),te=et(H=>H.sttLocalModel),me=et(H=>H.setSttLocalModel),Pe=et(H=>H.sttLanguage),Ne=et(H=>H.setSttLanguage),Se=et(H=>H.setShowMessageTTSButtons),be=et(H=>H.dictationEnabled),Fe=et(H=>H.setDictationEnabled),[Le,oe]=We.useState(!1),[fe,De]=We.useState([]),[$e,Ve]=We.useState(!1),[qe,se]=We.useState(null),[ie,we]=We.useState(!1),[ye,Te]=We.useState(!1),[Ue,Ie]=We.useState(null),[je,Ge]=We.useState(!1),[ue,Ce]=We.useState(null),[Me,Ye]=We.useState([]),[G,ke]=We.useState(!1);We.useEffect(()=>((async()=>{const Be=await Oi.waitForVoices();Ye(Be)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ye(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ae=We.useMemo(()=>Me.filter(H=>H.lang).sort((H,Be)=>{const tt=H.lang.startsWith("en"),rt=Be.lang.startsWith("en");if(tt&&!rt)return-1;if(!tt&&rt)return 1;const pt=H.lang.localeCompare(Be.lang);return pt!==0?pt:H.name.localeCompare(Be.name)}),[Me]),He=We.useCallback(()=>{if(G){Oi.cancelSpeech(),ke(!1);return}const H=Me.find(pt=>pt.name===L),Be=H?.name??t("settings.voice.page.preview.browserVoiceFallback"),tt=t("settings.voice.page.preview.voiceLine",{voiceName:Be});ke(!0);const rt=new SpeechSynthesisUtterance(tt);rt.rate=i,rt.pitch=l,rt.volume=m,H&&(rt.voice=H,rt.lang=H.lang),rt.onend=()=>ke(!1),rt.onerror=()=>ke(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(rt)},[L,Me,i,l,m,G,t]);We.useEffect(()=>()=>{G&&Oi.cancelSpeech()},[G]),We.useEffect(()=>{if(!V||a!=="openai"&&a!=="openai-compatible"){we(K.trim().length>0);return}(async()=>{try{const rt=(await(await mt("/api/tts/status")).json()).available,pt=K.trim().length>0;we(rt||pt)}catch{we(K.trim().length>0)}})()},[K,V,a]),We.useEffect(()=>{if(!V){oe(!1),De([]);return}mt("/api/tts/say/status").then(H=>H.json()).then(H=>{if(oe(H.available),H.voices){const Be=H.voices.filter((tt,rt,pt)=>pt.findIndex(Ct=>Ct.name===tt.name)===rt).sort((tt,rt)=>tt.name.localeCompare(rt.name));De(Be)}}).catch(()=>{oe(!1)})},[V]);const at=We.useCallback(async()=>{if(qe){Es(qe),se(null),Ve(!1);return}Ve(!0);let H=null;try{const Be=await mt("/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(!Be.ok)throw new Error("Preview failed");const tt=await Be.blob(),rt=URL.createObjectURL(tt);H=new Audio(rt),H.onended=()=>{Es(H),se(null),Ve(!1)},H.onerror=()=>{Es(H),se(null),Ve(!1)},se(H),await H.play()}catch{Es(H),se(null),Ve(!1)}},[d,i,qe,t]);We.useEffect(()=>()=>{Es(qe)},[qe]);const nt=We.useCallback(async()=>{if(Ue){Es(Ue),Ie(null),Te(!1);return}Te(!0);let H=null;try{const Be=await mt("/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:K||void 0})});if(!Be.ok){const pt=await Be.json().catch(()=>({error:"Unknown error"}));throw new Error(pt.error||`HTTP ${Be.status}`)}const tt=await Be.blob(),rt=URL.createObjectURL(tt);H=new Audio(rt),H.onended=()=>{Es(H),Ie(null),Te(!1)},H.onerror=()=>{Es(H),Ie(null),Te(!1)},Ie(H),await H.play()}catch{Es(H),Ie(null),Te(!1)}},[P,i,Ue,K,t]);We.useEffect(()=>()=>{Es(Ue)},[Ue]);const dt=We.useCallback(async()=>{if(ue){Es(ue),Ce(null),Ge(!1);return}if(!k.trim())return;Ge(!0);let H=null;try{const Be=await mt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:Q,model:_||void 0,speed:i,baseURL:k,apiKey:q||void 0})});if(!Be.ok){const pt=await Be.json().catch(()=>({error:"Unknown error"}));throw new Error(pt.error||`HTTP ${Be.status}`)}const tt=await Be.blob(),rt=URL.createObjectURL(tt);H=new Audio(rt),H.onended=()=>{Es(H),Ce(null),Ge(!1)},H.onerror=()=>{Es(H),Ce(null),Ge(!1)},Ce(H),await H.play()}catch{Es(H),Ce(null),Ge(!1)}},[k,Q,_,q,i,ue,t]);We.useEffect(()=>()=>{Es(ue)},[ue]);const xt="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(gt,{checked:V,onChange:Se,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),V&&s.jsxs(s.Fragment,{children:[s.jsx(Os,{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(Ws,{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")},...Le?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(R,{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:ve(Et,!ie&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ve(Kn,!ie&&"text-[var(--status-error)]/80"),children:t(ie&&!K?"settings.voice.page.field.apiKeyHintUsingConfig":ie?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:ve("relative",zs),children:[s.jsx("input",{type:"password",value:K,onChange:H=>W(H.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),K&&s.jsx("button",{type:"button",onClick:()=>W(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{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:ve(Et,!k.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:ve("relative",zs),children:[s.jsx("input",{type:"text",value:k,onChange:H=>F(H.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),k&&s.jsx("button",{type:"button",onClick:()=>F(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:Kn,children:"Optional"}),s.jsxs("div",{className:ve("relative",zs),children:[s.jsx("input",{type:"password",value:q,onChange:H=>U(H.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),q&&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(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ve("relative",zs),children:s.jsx("input",{type:"text",value:_,onChange:H=>re(H.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.voice")}),s.jsx(Jt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:ve("flex items-center gap-2",zs),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:Q,onChange:H=>ne(H.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(B,{size:"xs",variant:"ghost",onClick:dt,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:je?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(Qh,{...C}),(a==="local"||a==="say")&&s.jsx(gt,{checked:S,onChange:g,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Ot,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{value:Ta(N,c),onValueChange:H=>{const Be=v.find(tt=>Ta(tt.modelId,tt.speakerId)===H);Be&&(b(Be.modelId),E(Be.speakerId))},children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:H=>v.find(Be=>Ta(Be.modelId,Be.speakerId)===H)?.label??H})}),s.jsx(At,{children:v.map(H=>s.jsx(ot,{value:Ta(H.modelId,H.speakerId),children:H.label},Ta(H.modelId,H.speakerId)))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:j,title:t("settings.voice.page.actions.preview"),children:w?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})}),h?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:h}):null]}),a==="openai"&&ie&&s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{value:P,onValueChange:I,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:Yh.map(H=>s.jsx(ot,{value:H.value,children:H.label},H.value))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:nt,title:t("settings.voice.page.actions.preview"),children:ye?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:Kn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&Le&&fe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{value:d,onValueChange:y,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:fe.map(H=>s.jsx(ot,{value:H.name,children:H.name},H.name))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:at,title:t("settings.voice.page.actions.preview"),children:$e?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Ae.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{value:L||"$auto",onValueChange:H=>T(H==="$auto"?"":H),children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"$auto",children:t("settings.voice.page.field.auto")}),Ae.map(H=>s.jsxs(ot,{value:H.name,children:[H.name," (",H.lang,")"]},H.name))]})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:He,title:t("settings.voice.page.actions.preview"),children:G?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Ot,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:H=>r(Number(H.target.value)),className:xt}),s.jsx(Ss,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:ve(Ps,"tabular-nums")})]}),s.jsxs(Ot,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:H=>p(Number(H.target.value)),className:xt}),s.jsx(Ss,{value:l,onValueChange:p,min:.5,max:2,step:.1,className:ve(Ps,"tabular-nums")})]}),s.jsxs(Ot,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:m,onChange:H=>f(Number(H.target.value)),className:xt}),e?s.jsx(Ss,{value:Math.round(m*100),onValueChange:H=>f(H/100),min:0,max:100,step:10,className:ve(Ps,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(m*100),"%"]})]}),s.jsx(Os,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Ws,{value:$,onChange:z,"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(gt,{checked:be,onChange:Fe,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),be&&s.jsxs(s.Fragment,{children:[s.jsx(Os,{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(Ws,{value:O,onChange:Y,"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")}]})}),O==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx(Bh,{selectedModelId:te,onSelect:me})]}),O==="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:ve(Et,!Z.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:ve("relative",zs),children:[s.jsx("input",{type:"text",value:Z,onChange:H=>ee(H.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),Z&&s.jsx("button",{type:"button",onClick:()=>ee(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:Kn,children:"Optional"}),s.jsxs("div",{className:ve("relative",zs),children:[s.jsx("input",{type:"password",value:ge,onChange:H=>de(H.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),ge&&s.jsx("button",{type:"button",onClick:()=>de(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ve("relative",zs),children:s.jsx("input",{type:"text",value:xe,onChange:H=>ae(H.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.language")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:Pe,onChange:H=>Ne(H.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]})]})]})]})]})};function Xh(t){return t.id===rr||t.installed||t.downloading}const ri=[{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}],oi=[{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}],ef="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",tf="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",qi=[{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"}],sf=[".yml",".yaml",".json"],nf="settings.openchamber.tunnel.error.invalidConfigExtension",Ea=t=>{const e=t.trim().toLowerCase();return sf.some(a=>e.endsWith(a))},af=t=>t==="ngrok"?"ngrok":"cloudflared",Gl=()=>{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"},rf=(t,e=Gl())=>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/",Wi=(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():af(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Gl(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():rf(a,i);return{provider:a,dependency:n,installCommand:r}},ql=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,Wo=t=>{const e=ut.c(11),{provider:a}=t;let n;e[0]!==a?(n=ql(a),e[0]=a,e[1]=n):n=e[1];const i=n,p=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let m;e[2]!==p?(m=ve("size-4 shrink-0",p),e[2]=p,e[3]=m):m=e[3];let f;e[4]!==m?(f=s.jsx(R,{name:"cloud",className:m}),e[4]=m,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 y;return e[8]!==f||e[9]!==d?(y=s.jsxs("span",{className:"flex items-center gap-2",children:[f,d]}),e[8]=f,e[9]=d,e[10]=y):y=e[10],y},Sn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",or=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,Jo=(t,e,a)=>{const n=or(t,e,a);return t.find(i=>i.value===n)?.label||n},Qo=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`},of=(t,e)=>fl(t,e,{hour:"2-digit",precision:"second"}),ui=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()}},lf=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():"",p=typeof r.name=="string"?r.name.trim():"",m=ui(typeof r.hostname=="string"?r.hostname:"");!l||!p||!m||e.has(l)||a.has(m)||(e.add(l),a.add(m),n.push({id:l,name:p,hostname:m}))}return n},cf=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,df=()=>{const{t}=it(),e=ce(J=>J.timeFormatPreference),a=o.useCallback(J=>t(J),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[p,m]=o.useState(null),[f,d]=o.useState(null),[y,c]=o.useState(null),[N,b]=o.useState(null),[C,v]=o.useState(!1),[S,g]=o.useState(!1),[E,M]=o.useState(!1),[A,w]=o.useState("cloudflare"),[h,j]=o.useState(()=>Wi("cloudflare")),[L,T]=o.useState([]),[P,I]=o.useState("quick"),[K,W]=o.useState(null),[k,F]=o.useState([]),[q,U]=o.useState({}),[Q,ne]=o.useState(""),[_,re]=o.useState({}),[V,$]=o.useState(new Set),[z,O]=o.useState(!1),[Y,Z]=o.useState(""),[ee,ge]=o.useState(""),[de,xe]=o.useState(""),[ae,te]=o.useState(1800*1e3),[me,Pe]=o.useState(480*60*1e3),[Ne,Se]=o.useState(""),[be,Fe]=o.useState([]),[Le,oe]=o.useState(()=>Date.now()),[fe,De]=o.useState(null),$e=t(nf),Ve=o.useRef(null),qe=o.useMemo(()=>K?!Ea(K):!1,[K]),se=o.useMemo(()=>k.find(J=>J.id===Q)||k[0]||null,[k,Q]),ie=o.useMemo(()=>be.map(J=>{const he=J.expiresAt<=Le,ze=J.status==="active"&&!he,Re=ze?Qo(J.expiresAt-Le):J.inactiveReason==="expired"||he?"expired":"inactive",ct=Re==="expired"?t("settings.openchamber.tunnel.state.expired"):J.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),lt=Sn(J.mode);return{...J,isActive:ze,mode:lt,remainingTextForSession:Re,inactiveLabel:ct}}),[Le,be,t]),we=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Le:!1,[Le,r?.bootstrapExpiresAt,r?.connectUrl]),ye=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:p===P,[p,n,r,P]),Te=o.useMemo(()=>!r||n!=="active"||!p?!1:p!==P,[p,n,r,P]),Ue=o.useMemo(()=>{if(typeof fe=="number"&&Number.isFinite(fe)&&fe>0)return fe;if(typeof window>"u")return null;const he=_a()||window.location.href;let ze=0;try{ze=Number(new URL(he).port)}catch{ze=Number(window.location.port)}return Number.isFinite(ze)&&ze>0?ze:null},[fe]),Ie=o.useMemo(()=>L.find(J=>J.provider===A)??null,[L,A]),je=o.useMemo(()=>{const J=new Set(Ie?.modes?.map(he=>he.key).filter(he=>he==="quick"||he==="managed-remote"||he==="managed-local"));return J.size===0?qi:qi.filter(he=>J.has(he.value))},[Ie]),Ge=o.useMemo(()=>je.some(J=>J.value==="managed-remote"||J.value==="managed-local"),[je]),ue=o.useMemo(()=>h.provider===A?h:Wi(A),[h,A]),Ce=o.useCallback(async J=>{await An(J)},[]),Me=o.useCallback((J,he)=>(j(Wi(he,J)),J.available===!0),[]),Ye=o.useCallback(async(J,he)=>{try{const ze=await mt("/api/openchamber/tunnel/check",{query:{provider:J},...he?{signal:he}:{}});if(!ze.ok)return null;const Re=await ze.json();if(he?.aborted)return null;const ct=Me(Re,J);return i(lt=>lt==="checking"||lt==="starting"||lt==="active"||lt==="stopping"?lt:ct?"idle":"not-available"),ct}catch{return null}},[Me]),G=o.useCallback(async J=>{try{const[he,ze,Re,ct]=await Promise.all([mt("/api/openchamber/tunnel/check",{signal:J}),mt("/api/openchamber/tunnel/status",{signal:J}),mt("/api/config/settings",{signal:J,headers:{Accept:"application/json"}}),mt("/api/openchamber/tunnel/providers",{signal:J})]),lt=await he.json(),Qe=await ze.json(),Nt=Re.ok?await Re.json():{},xs=ct.ok?await ct.json():{},es=Qe.ttlConfig?.bootstrapTtlMs??(Nt?.tunnelBootstrapTtlMs===null?null:typeof Nt?.tunnelBootstrapTtlMs=="number"?Nt.tunnelBootstrapTtlMs:1800*1e3),Ds=typeof Qe.ttlConfig?.sessionTtlMs=="number"?Qe.ttlConfig.sessionTtlMs:typeof Nt?.tunnelSessionTtlMs=="number"?Nt.tunnelSessionTtlMs:480*60*1e3,Bt=Sn(Qe.mode??Nt?.tunnelMode),os=typeof Nt?.tunnelProvider=="string"&&Nt.tunnelProvider.trim().length>0?Nt.tunnelProvider.trim().toLowerCase():"cloudflare",qt=typeof Nt?.managedLocalTunnelConfigPath=="string"&&Nt.managedLocalTunnelConfigPath.trim()||null,bs=Me(lt,os),ps=lf(Qe?.managedRemoteTunnelPresets),vs=typeof Qe.managedRemoteTunnelHostname=="string"?Qe.managedRemoteTunnelHostname:"",ms=ps.length>0?ps:vs?[{id:`legacy-${ui(vs)}`,name:vs,hostname:ui(vs)}]:[],ys=ms[0]?.id||"";if(te(es),Pe(Ds),w(os),T(Array.isArray(xs?.providers)?xs.providers:[]),I(Bt),W(qt),F(ms),ne(ys),Fe(Array.isArray(Qe.activeSessions)?Qe.activeSessions:[]),m(Qe.activeTunnelMode?Sn(Qe.activeTunnelMode):Qe.active&&Qe.mode?Sn(Qe.mode):null),$(new Set(Array.isArray(Qe.managedRemoteTunnelTokenPresetIds)?Qe.managedRemoteTunnelTokenPresetIds:[])),De(typeof Qe.localPort=="number"?Qe.localPort:null),Qe.active&&Qe.url){l({url:Qe.url,connectUrl:null,bootstrapExpiresAt:typeof Qe.bootstrapExpiresAt=="number"?Qe.bootstrapExpiresAt:null}),i("active");return}i(bs?"idle":"not-available")}catch{J.aborted||(i("error"),c(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Me,t]);o.useEffect(()=>{const J=new AbortController;return G(J.signal),()=>J.abort()},[G]),o.useEffect(()=>{if(!r?.connectUrl){d(null);return}let J=!1;return Cl.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(he=>{J||d(he)}).catch(()=>{J||d(null)}),()=>{J=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){Se(t("settings.openchamber.tunnel.state.noExpiry"));return}let J=null,he=Date.now();const ze=()=>{const lt=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;lt<=0?Se(t("settings.openchamber.tunnel.state.expired")):Se(Qo(lt))},Re=()=>{const lt=Date.now();lt-he>=1e3&&(ze(),he=lt),J=requestAnimationFrame(Re)};ze(),(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(Re));const ct=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(Re):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",ct),()=>{document.removeEventListener("visibilitychange",ct),J!==null&&cancelAnimationFrame(J)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let J=null,he=Date.now();const ze=()=>{const ct=Date.now();ct-he>=1e3&&(oe(ct),he=ct),J=requestAnimationFrame(ze)};(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(ze));const Re=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(ze):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",Re),()=>{document.removeEventListener("visibilitychange",Re),J!==null&&cancelAnimationFrame(J)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let J=!1;const he=async()=>{try{const Re=await mt("/api/openchamber/tunnel/status");if(!Re.ok||J)return;const ct=await Re.json();if(J)return;Fe(Array.isArray(ct.activeSessions)?ct.activeSessions:[]),$(new Set(Array.isArray(ct.managedRemoteTunnelTokenPresetIds)?ct.managedRemoteTunnelTokenPresetIds:[])),De(typeof ct.localPort=="number"?ct.localPort:null)}catch{}},ze=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||he()},5e3);return()=>{J=!0,window.clearInterval(ze)}},[n]);const ke=o.useCallback(async J=>{M(!0);try{await vt(J),Object.prototype.hasOwnProperty.call(J,"tunnelMode")&&J.tunnelMode&&I(J.tunnelMode),Object.prototype.hasOwnProperty.call(J,"tunnelProvider")&&typeof J.tunnelProvider=="string"&&w(J.tunnelProvider),Object.prototype.hasOwnProperty.call(J,"managedLocalTunnelConfigPath")&&W(J.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(J,"managedRemoteTunnelPresets")&&J.managedRemoteTunnelPresets&&F(J.managedRemoteTunnelPresets)}catch{D.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{M(!1)}},[t]),Ae=o.useCallback(async(J,he)=>{g(!0);try{await vt({tunnelBootstrapTtlMs:J,tunnelSessionTtlMs:he})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),He=o.useCallback(async J=>{const he=J.token.trim();if(he)try{const ze={..._,[J.presetId]:he};await vt({managedRemoteTunnelPresetTokens:ze}),$(Re=>{const ct=new Set(Re);return ct.add(J.presetId),ct})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[_,t]),at=o.useCallback(async J=>{b(null),c(null);const he=L.find(Re=>Re.provider===J),ze=he?.modes?.some(Re=>Re.key===P)?P:Sn(he?.modes?.[0]?.key);await ke({tunnelProvider:J,tunnelMode:ze}),Ye(J)},[L,Ye,ke,P]),nt=o.useCallback(async()=>{const J=await jl({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(J.success&&typeof J.path=="string"&&J.path.trim().length>0){const he=J.path.trim();if(!Ea(he)){D.error($e);return}W(he),await ke({managedLocalTunnelConfigPath:he});return}Ve.current?.click()},[$e,ke]),dt=o.useCallback(J=>{const he=J.trim();W(he.length>0?he:null)},[]),xt=o.useCallback(async()=>{if(K&&!Ea(K)){D.error($e);return}await ke({managedLocalTunnelConfigPath:K})},[$e,K,ke]),H=o.useCallback(async()=>{W(null),await ke({managedLocalTunnelConfigPath:null})},[ke]),Be=o.useCallback(async J=>{const he=J.target.files?.[0];if(!he)return;const ze=he.name.trim();if(ze.length!==0){if(!Ea(ze)){D.error($e);return}W(ze),await ke({managedLocalTunnelConfigPath:ze}),J.target.value=""}},[$e,ke]),tt=o.useCallback(async()=>{if(c(null),b(null),P==="managed-local"&&K&&!Ea(K)){c($e),D.error($e);return}i("starting");try{let J="",he="";if(P==="managed-remote"){if(!se){i("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),D.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}J=se.hostname,he=(_[se.id]||"").trim(),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:k})}const ze=await mt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:A,mode:P,...P==="managed-remote"&&se?{managedRemoteTunnelPresetId:se.id,managedRemoteTunnelPresetName:se.name}:{},...P==="managed-remote"&&J?{managedRemoteTunnelHostname:J}:{},...P==="managed-remote"&&he?{managedRemoteTunnelToken:he}:{},...P==="managed-local"&&K?{configPath:K}:{}})}),Re=await ze.json();if(!ze.ok||!Re.ok){if(P==="managed-remote"&&typeof Re.error=="string"&&Re.error.includes("Managed remote tunnel token is required")){i("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),D.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),c(Re.error||t("settings.openchamber.tunnel.toast.startFailed")),D.error(Re.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const ct=typeof Re.url=="string"?Re.url:"";if(!ct){i("error"),c(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),D.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:ct,connectUrl:typeof Re.connectUrl=="string"?Re.connectUrl:null,bootstrapExpiresAt:typeof Re.bootstrapExpiresAt=="number"?Re.bootstrapExpiresAt:null}),m(Re.activeTunnelMode?Sn(Re.activeTunnelMode):Re.mode?Sn(Re.mode):P),Fe(Array.isArray(Re.activeSessions)?Re.activeSessions:[]),Array.isArray(Re.managedRemoteTunnelTokenPresetIds)&&$(new Set(Re.managedRemoteTunnelTokenPresetIds)),typeof Re.localPort=="number"&&De(Re.localPort),typeof Re.mode=="string"&&I(Sn(Re.mode)),i("active"),Re.replacedTunnel){const lt=typeof Re.revokedBootstrapCount=="number"?Re.revokedBootstrapCount:0,Qe=typeof Re.invalidatedSessionCount=="number"?Re.invalidatedSessionCount:0;lt===1&&Qe===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):lt===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Qe})):Qe===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:lt})):D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:lt,invalidatedSessionCount:Qe}))}else D.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),c(t("settings.openchamber.tunnel.toast.startFailed")),D.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[$e,k,ke,se,_,t,A,P,K]),rt=o.useCallback(async()=>{i("stopping");try{await mt("/api/openchamber/tunnel/stop",{method:"POST"});const J=await mt("/api/openchamber/tunnel/status");if(J.ok){const he=await J.json();Fe(Array.isArray(he.activeSessions)?he.activeSessions:[]),$(new Set(Array.isArray(he.managedRemoteTunnelTokenPresetIds)?he.managedRemoteTunnelTokenPresetIds:[])),De(typeof he.localPort=="number"?he.localPort:null)}l(null),m(null),d(null),i("idle"),D.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),c(t("settings.openchamber.tunnel.toast.stopFailed")),D.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),pt=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),v(!0),D.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>v(!1),2e3)}catch{D.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),Ct=o.useCallback(async J=>{const he=ri.find(ze=>ze.value===J);he&&(te(he.ms),await Ae(he.ms,me))},[Ae,me]),Xe=o.useCallback(async J=>{const he=oi.find(ze=>ze.value===J);!he||he.ms===null||(Pe(he.ms),await Ae(ae,he.ms))},[ae,Ae]),Ze=o.useCallback(async J=>{b(null),c(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await ke({tunnelMode:J,managedRemoteTunnelPresets:k})},[k,ke,n]),ht=o.useCallback(async(J,he)=>{try{await vt({managedRemoteTunnelPresets:he})}catch{D.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Ke=o.useCallback(J=>{const he=k.find(ze=>ze.id===J);he&&(ne(he.id),b(null),ht(he,k))},[k,ht]),wt=o.useCallback(async()=>{const J=Y.trim(),he=ui(ee),ze=de.trim();if(!J){D.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!he){D.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!ze){D.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(k.some(lt=>lt.hostname===he)){D.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Re={id:cf(),name:J,hostname:he},ct=[...k,Re];F(ct),ne(Re.id),U(lt=>({...lt,[Re.id]:!0})),re(lt=>({...lt,[Re.id]:ze})),b(null),O(!1),Z(""),ge(""),xe(""),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:ct,managedRemoteTunnelPresetTokens:{..._,[Re.id]:ze}}),await He({presetId:Re.id,presetName:Re.name,hostname:Re.hostname,token:ze}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[k,ee,Y,de,He,ke,_,t]),Ee=o.useCallback(async J=>{const he=k.find(Qe=>Qe.id===J);if(!he)return;const ze=k.filter(Qe=>Qe.id!==he.id),Re=ze[0]?.id||"",ct=Q===he.id?Re:Q,lt=Object.fromEntries(Object.entries(_).filter(([Qe,Nt])=>Qe!==he.id&&Nt.trim().length>0));F(ze),ne(ct),U(Qe=>{const Nt={...Qe};return delete Nt[he.id],Nt}),re(Qe=>{const Nt={...Qe};return delete Nt[he.id],Nt}),$(Qe=>{const Nt=new Set(Qe);return Nt.delete(he.id),Nt}),b(null),await ke({managedRemoteTunnelPresets:ze,managedRemoteTunnelPresetTokens:lt}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[k,ke,Q,_,t]),jt="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:[ie.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(R,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Rr,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ie.map(J=>{const he=J.mode==="quick",ze=J.mode==="managed-remote",Re=he?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":ze?"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)]",ct=J.isActive?he?"text-[var(--status-warning)]":ze?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",lt=t(he?"settings.openchamber.tunnel.badge.quick":ze?"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(R,{name:"checkbox-blank-circle-fill",className:ve("size-2.5 shrink-0",ct)}),s.jsx("span",{className:ve("typography-micro rounded border px-1.5 py-0.5 uppercase",Re),children:lt}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:of(J.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:J.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:J.remainingTextForSession}):J.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:J.inactiveLabel})})]},J.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(R,{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:Rr,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:ue.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:ue.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:Et,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Pt,{value:A,onValueChange:J=>{at(J)},disabled:E||n==="starting"||n==="stopping",children:[s.jsx(It,{size:Lt,className:"max-w-[16rem]",children:s.jsx(Rt,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:ql(A)})}),s.jsxs(At,{children:[L.length>0?L.map(J=>s.jsx(ot,{value:J.provider,children:s.jsx(Wo,{provider:J.provider})},J.provider)):s.jsx(ot,{value:"cloudflare",children:s.jsx(Wo,{provider:"cloudflare"})}),s.jsx(ot,{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:Et,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:je.map(J=>s.jsxs(pr,{children:[s.jsx(mr,{asChild:!0,children:s.jsx(B,{variant:"chip",size:"xs","aria-pressed":P===J.value,className:"!font-normal",onClick:()=>{Ze(J.value)},disabled:E||n==="starting"||n==="stopping",children:a(J.labelKey)})}),s.jsx(dl,{sideOffset:8,className:"max-w-xs",children:a(J.tooltipKey)})]},J.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:ve(Et,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Pt,{value:or(ri,ae,"1800000"),onValueChange:J=>{Ct(J)},disabled:S||E||n==="starting"||n==="stopping",children:[s.jsx(It,{size:Lt,className:"max-w-[11rem] min-w-0",children:s.jsx(Rt,{className:"truncate",children:Jo(ri,ae,"1800000")})}),s.jsx(At,{children:ri.map(J=>s.jsx(ot,{value:J.value,children:J.label},J.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ve(Et,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Pt,{value:or(oi,me,"28800000"),onValueChange:J=>{Xe(J)},disabled:S||E||n==="starting"||n==="stopping",children:[s.jsx(It,{size:Lt,className:"max-w-[11rem] min-w-0",children:s.jsx(Rt,{className:"truncate",children:Jo(oi,me,"28800000")})}),s.jsx(At,{children:oi.map(J=>s.jsx(ot,{value:J.value,children:J.label},J.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(R,{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")}),Ge&&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 Ue=="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:",Ue]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Js,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>O(J=>!J),disabled:n==="starting"||n==="stopping"||E,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),k.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:k.map((J,he)=>{const ze=_[J.id]||"",Re=V.has(J.id),ct=q[J.id]??!1;return s.jsx("div",{className:ve(he<k.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(Tn,{open:ct,onOpenChange:lt=>{U(Qe=>({...Qe,[J.id]:lt})),lt&&Ke(J.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(En,{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"||E,children:[ct?s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(R,{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:J.name})]}),s.jsx(B,{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:J.name}),onClick:()=>{Ee(J.id)},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Dn,{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:J.hostname})]}),s.jsx(Je,{type:"password",value:ze,onChange:lt=>{const Qe=lt.target.value;b(null),re(Nt=>({...Nt,[J.id]:Qe}))},onBlur:lt=>{const Qe=lt.currentTarget.value.trim();Qe&&He({presetId:J.id,presetName:J.name,hostname:J.hostname,token:Qe})},placeholder:t(Re?"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(B,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||ze.trim().length===0,onClick:()=>{He({presetId:J.id,presetName:J.name,hostname:J.hostname,token:ze})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},J.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),z&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Je,{value:Y,onChange:J=>Z(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),s.jsx(Je,{value:ee,onChange:J=>ge(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),s.jsx(Je,{type:"password",value:de,onChange:J=>xe(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:E||n==="starting"||n==="stopping"}),typeof Ue=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ue]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{wt()},disabled:E||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{O(!1),Z(""),ge(""),xe("")},disabled:E||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(Jt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!se&&N&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:N})]}),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:Et,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Ve,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:J=>{Be(J)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:K||"",onChange:J=>{dt(J.target.value)},onBlur:()=>{xt()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||E}),s.jsx(B,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{nt()},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(R,{name:"folder",className:"size-3.5"})}),K&&s.jsx(B,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{H()},disabled:n==="starting"||n==="stopping"||E,children:s.jsx(R,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(K?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),qe&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:$e})]})}),!ye&&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(R,{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:()=>{Ce(ef)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(R,{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:()=>{Ce(tf)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(R,{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(qi.find(J=>J.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:Et,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Pt,{value:Q||(k[0]?.id??""),onValueChange:J=>{Ke(J)},disabled:E||n==="starting"||n==="stopping"||k.length<=1,children:[s.jsx(It,{size:Lt,children:s.jsx(Rt,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:se?.name})}),s.jsx(At,{fitContent:!0,children:k.map(J=>s.jsx(ot,{value:J.id,children:J.name},J.id))})]})]}),Te&&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(R,{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(B,{size:"sm",variant:"outline",onClick:tt,disabled:n==="starting"||E||P==="managed-remote"&&!se||P==="managed-local"&&qe,className:ve(jt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),ye&&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})]}),we&&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(B,{size:"sm",variant:"ghost",onClick:pt,className:"shrink-0 gap-1.5",children:[C?s.jsx(R,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(R,{name:"file-copy",className:"size-3.5"}),t(C?"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?Ne: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(B,{size:"sm",variant:"outline",onClick:tt,disabled:n==="stopping"||E||P==="managed-local"&&qe,className:jt,children:[s.jsx(R,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:rt,disabled:n==="stopping"||E,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&y&&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:y}),s.jsx(B,{size:"sm",variant:"ghost",onClick:tt,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},Wl=()=>{const{t}=it(),[e,a]=We.useState(""),[n,i]=We.useState(!0),[r,l]=We.useState(!1),p=ce(c=>c.showOpenCodeUpdateNotifications),m=ce(c=>c.setShowOpenCodeUpdateNotifications);We.useEffect(()=>{let c=!1;return(async()=>{try{const N=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const b=await N.json().catch(()=>null);if(c||!b)return;const C=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";a(C)}catch{}finally{c||i(!1)}})(),()=>{c=!0}},[]);const f=We.useCallback(async()=>{if(!(typeof window>"u")&&rs())try{const c=await jl();c.success&&c.path&&c.path.trim().length>0&&a(c.path.trim())}catch{}},[]),d=We.useCallback(async()=>{l(!0);try{const c=e.trim(),N=c.length>=2&&(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))?c.slice(1,-1).trim():c;await vt({opencodeBinary:N}),_n("cli",{id:"opencode-binary"}),D.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),y=We.useCallback(c=>{m(c),vt({showOpenCodeUpdateNotifications:c})},[m]);return s.jsx(_e,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Ot,{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(Je,{value:e,onChange:c=>a(c.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(B,{type:"button",variant:"outline",size:"xs",onClick:f,disabled:n||r||!rs(),className:hs,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(R,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Ua,{className:fs,children:[!wl()&&s.jsx(gt,{settingsItem:"sessions.opencode-update-notifications",checked:p,onChange:y,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(B,{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")})})]})]})})},Jl=()=>{const t=ut.c(44),{t:e}=it(),a=ce(pf),n=ce(mf),i=ce(uf),r=ce(gf),l=ce(hf),p=ce(ff),m=ce(xf);let f;t[0]!==n?(f=P=>{n(P),vt({agentControlToolEnabled:P}),_n("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=f):f=t[1];const d=f;let y;t[2]!==r?(y=P=>{r(P),vt({agentWebToolEnabled:P}),_n("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=y):y=t[3];const c=y;let N;t[4]!==m?(N=P=>{m(P),vt({agentMemoryToolEnabled:P}).finally(()=>{P&&qc.getState().refresh()}),_n("cli",{id:"agent-memory-tool"})},t[4]=m,t[5]=N):N=t[5];const b=N;let C;t[6]!==e?(C=e("settings.openchamber.tools.title"),t[6]=e,t[7]=C):C=t[7];let v;t[8]!==e?(v=e("settings.openchamber.tools.field.agentControlTool"),t[8]=e,t[9]=v):v=t[9];let S;t[10]!==e?(S=e("settings.openchamber.tools.field.agentControlToolAria"),t[10]=e,t[11]=S):S=t[11];let g;t[12]!==e?(g=e("settings.openchamber.tools.field.agentControlToolInfo"),t[12]=e,t[13]=g):g=t[13];let E;t[14]!==a||t[15]!==d||t[16]!==v||t[17]!==S||t[18]!==g?(E=s.jsx(gt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:d,label:v,ariaLabel:S,info:g}),t[14]=a,t[15]=d,t[16]=v,t[17]=S,t[18]=g,t[19]=E):E=t[19];let M;t[20]!==e?(M=e("settings.openchamber.tools.field.agentWebTool"),t[20]=e,t[21]=M):M=t[21];let A;t[22]!==e?(A=e("settings.openchamber.tools.field.agentWebToolAria"),t[22]=e,t[23]=A):A=t[23];let w;t[24]!==e?(w=e("settings.openchamber.tools.field.agentWebToolInfo"),t[24]=e,t[25]=w):w=t[25];let h;t[26]!==i||t[27]!==c||t[28]!==w||t[29]!==M||t[30]!==A?(h=s.jsx(gt,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:c,label:M,ariaLabel:A,info:w}),t[26]=i,t[27]=c,t[28]=w,t[29]=M,t[30]=A,t[31]=h):h=t[31];let j;t[32]!==p||t[33]!==l||t[34]!==b||t[35]!==e?(j=p?s.jsx(gt,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:b,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[32]=p,t[33]=l,t[34]=b,t[35]=e,t[36]=j):j=t[36];let L;t[37]!==h||t[38]!==j||t[39]!==E?(L=s.jsxs("div",{className:fs,children:[E,h,j]}),t[37]=h,t[38]=j,t[39]=E,t[40]=L):L=t[40];let T;return t[41]!==L||t[42]!==C?(T=s.jsx(_e,{title:C,children:L}),t[41]=L,t[42]=C,t[43]=T):T=t[43],T};function pf(t){return t.agentControlToolEnabled}function mf(t){return t.setAgentControlToolEnabled}function uf(t){return t.agentWebToolEnabled}function gf(t){return t.setAgentWebToolEnabled}function hf(t){return t.agentMemoryToolEnabled}function ff(t){return t.agentMemoryFeatureAvailable}function xf(t){return t.setAgentMemoryToolEnabled}const Ql=()=>{const{t}=it(),e=rs()&&$a(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=We.useState(!1),[r,l]=We.useState(!1),[p,m]=We.useState(""),[f,d]=We.useState(""),[y,c]=We.useState(!1),[N,b]=We.useState(!1),[C,v]=We.useState(null),[S,g]=We.useState(!0),[E,M]=We.useState(!1),[A,w]=We.useState(!1),[h,j]=We.useState(!1),[L,T]=We.useState(!1),[P,I]=We.useState(!1),[K,W]=We.useState(!1),[k,F]=We.useState(!1),[q,U]=We.useState(!0),[Q,ne]=We.useState(!0),[_,re]=We.useState(!1),[V,$]=We.useState(!1),[z,O]=We.useState(!1),[Y,Z]=We.useState(null),[ee,ge]=We.useState(null);We.useEffect(()=>{if(!e){g(!1);return}let oe=!1;return(async()=>{try{const fe=await mt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!fe.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const De=await fe.json().catch(()=>null);if(oe)return;const $e=De?.desktopLanAccessEnabled===!0,Ve=typeof De?.desktopUiPassword=="string"?De.desktopUiPassword:"";i($e),l($e),m(Ve),d(Ve),b(De?.desktopLanAccessActive===!0),v(typeof De?.desktopLanAccessBlockedReason=="string"?De.desktopLanAccessBlockedReason:null);const qe=De?.desktopMacMenuBarEnabled!==!1;U(qe),ne(qe),Z(null)}catch(fe){oe||Z(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{oe||g(!1)}})(),()=>{oe=!0}},[e,t]),We.useEffect(()=>{if(!e){w(!1);return}let oe=!1;return(async()=>{const fe=await kd();oe||(w(fe?.supported===!0),j(fe?.enabled===!0))})(),()=>{oe=!0}},[e]),We.useEffect(()=>{if(!e){I(!1);return}let oe=!1;return(async()=>{const fe=await Nd();oe||(I(fe?.supported===!0),W(fe?.enabled===!0))})(),()=>{oe=!0}},[e]),We.useEffect(()=>{if(!e){re(!1);return}let oe=!1;return(async()=>{const fe=await Sd();oe||(re(fe?.supported===!0),$(fe?.enabled===!0))})(),()=>{oe=!0}},[e]),We.useEffect(()=>{if(!e||!r){ge(null);return}let oe=!1;return(async()=>{const fe=await vl();oe||ge(fe)})(),()=>{oe=!0}},[r,e]);const de=r!==n||f!==p||Q!==q,xe=We.useMemo(()=>{if(typeof window>"u")return null;const fe=_a()||window.location.href;let De=0;try{De=Number(new URL(fe).port)}catch{De=Number(window.location.port)}return Number.isFinite(De)&&De>0?De:null},[]),ae=r&&N&&ee&&xe?`http://${ee}:${xe}`:null,te=r&&!f.trim(),me=n&&!N&&C==="missing-password",Pe=S||E||!de||te,Ne=We.useCallback(oe=>{d(oe),oe.trim()||l(!1)},[]),Se=We.useCallback(async()=>{if(!A||L)return;const oe=!h;j(oe),T(!0),Z(null);try{const fe=await Cd(oe);if(!fe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));j(fe.enabled)}catch(fe){j(!oe),Z(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{T(!1)}},[L,h,A,t]),be=We.useCallback(async()=>{if(!P||k)return;const oe=!K;W(oe),F(!0),Z(null);try{const fe=await Pd(oe);if(!fe)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!fe.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));W(fe.enabled)}catch(fe){W(!oe),Z(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{F(!1)}},[k,K,P,t]),Fe=We.useCallback(async()=>{if(!_||z)return;const oe=!V;$(oe),O(!0),Z(null);try{const fe=await Id(oe);if(!fe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));$(fe.enabled)}catch(fe){$(!oe),Z(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{O(!1)}},[z,V,_,t]),Le=We.useCallback(async()=>{if(de){M(!0),Z(null);try{if(!(await mt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:f,desktopMacMenuBarEnabled:Q})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(r),m(f),U(Q),!await Ad())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(oe){Z(oe instanceof Error?oe.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),M(!1)}}},[Q,f,r,de,t]);return e?s.jsx(_e,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[A||a||P||_?s.jsxs("div",{className:fs,children:[A?s.jsx(gt,{settingsItem:"sessions.desktop-launch-at-login",checked:h,onChange:oe=>{oe!==h&&Se()},disabled:L,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(gt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:Q,onChange:ne,disabled:S||E,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(gt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:K,onChange:oe=>{oe!==K&&be()},disabled:k,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,_?s.jsx(gt,{settingsItem:"sessions.desktop-keep-awake",checked:V,onChange:oe=>{oe!==V&&Fe()},disabled:z,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(Wt,{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(Je,{id:"desktop-ui-password",type:y?"text":"password",className:"h-8 min-w-0 flex-1",value:f,onChange:oe=>Ne(oe.target.value),placeholder:t("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:S||E,required:r,"aria-invalid":te}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(oe=>!oe),className:hs,"aria-label":t(y?"settings.openchamber.desktopPassword.actions.hidePassword":"settings.openchamber.desktopPassword.actions.showPassword"),"aria-pressed":y,children:s.jsx(R,{name:y?"eye-off":"eye",className:"h-4 w-4"})})]}),s.jsx("div",{className:fs,children:s.jsx(gt,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:S||E,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")}),te||me?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")})}),Y?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:Y}):null,ae?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(de&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ae})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(B,{type:"button",size:"xs",onClick:Le,disabled:Pe,className:"shrink-0 !font-normal",children:t(E?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},Yl=new Set(["shift","control","alt","meta"]),wr=3,bf=3e3;function kr(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 vf(t){return t.action.customizable}function Yo(t){if(kr(t)>wr)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?bi(e.join("+")):null}function yf(t){if(Yl.has(t.key.toLowerCase())||kr(t,!0)>wr)return null;const e=Qc(Yc(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),bi(a.join("+"))}function jf(t){const e=t.key.toLowerCase();if(!Yl.has(e)||kr(t,!0)>wr)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?bi(a.join("+")):null}function Zo(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function wf(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:Yo(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=yf(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:Yo(e)}}const kf=t=>{const e=ut.c(117),{action:a,overrides:n,onSave:i,onOpenChange:r}=t,{t:l}=it();let p;e[0]!==l?(p=te=>l(te.settingsLabelKey),e[0]=l,e[1]=p):p=e[1];const m=p;let f;e[2]!==m?(f=te=>te.action.customizable?m(te.action):Hn(te.action.defaultBinding),e[2]=m,e[3]=f):f=e[3];const d=f;let y;e[4]===Symbol.for("react.memo_cache_sentinel")?(y={chords:[],livePreview:null,settled:!1},e[4]=y):y=e[4];const[c,N]=o.useState(y),b=o.useRef(null);let C,v;e[5]!==a?(C=()=>{a&&(N({chords:[],livePreview:null,settled:!1}),b.current?.focus())},v=[a],e[5]=a,e[6]=C,e[7]=v):(C=e[6],v=e[7]),o.useEffect(C,v);const S=c.chords.length===1&&!c.settled;let g,E;e[8]!==S?(g=()=>{if(!S)return;const te=window.setTimeout(()=>N(Zo),bf);return()=>window.clearTimeout(te)},E=[S],e[8]=S,e[9]=g,e[10]=E):(g=e[9],E=e[10]),o.useEffect(g,E);let M;e[11]!==c.chords?(M=bi(c.chords.join(" ")),e[11]=c.chords,e[12]=M):M=e[12];const A=M;let w;e[13]!==a||e[14]!==A||e[15]!==n?(w=a&&A?Wc(a.id,A,n):[],e[13]=a,e[14]=A,e[15]=n,e[16]=w):w=e[16];const h=w;let j;e[17]!==h?(j=h.find(Nf),e[17]=h,e[18]=j):j=e[18];const L=j;let T,P,I,K,W,k,F,q,U,Q,ne,_,re,V,$;if(e[19]!==a||e[20]!==m||e[21]!==A||e[22]!==d||e[23]!==h||e[24]!==r||e[25]!==i||e[26]!==L||e[27]!==c||e[28]!==l){const te=h.filter(vf);W=te.find(Sf);const me=te.find(Cf),Pe=h.find(Pf);let Ne;e[44]!==r?(Ne=()=>r(!1),e[44]=r,e[45]=Ne):Ne=e[45],I=Ne,K=()=>{c.settled||N(Zo),!(!a||!A||L||W)&&(i(a.id,A,me?.action.id),I())};let Se;e[46]!==a||e[47]!==c?(Se=(ye,Te)=>{ye.preventDefault(),ye.stopPropagation();const Ue=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Te==="keyup"&&Ue&&c.chords.length===0){const je=jf(ye);if(je){N({chords:[je],livePreview:null,settled:!0});return}}const Ie=wf(c,{altKey:ye.altKey,code:ye.nativeEvent.code,ctrlKey:ye.ctrlKey,isComposing:ye.nativeEvent.isComposing,key:ye.key,metaKey:ye.metaKey,repeat:ye.repeat,shiftKey:ye.shiftKey},Te);N(Ue&&Ie.chords.length>1?c:Ie)},e[46]=a,e[47]=c,e[48]=Se):Se=e[48];const be=Se;P=Kt,V=a!==null,$=If,T=zt,k="max-w-md",F=b,q=!1;let Fe;e[49]!==a||e[50]!==m||e[51]!==l?(Fe=a?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:m(a)}):"",e[49]=a,e[50]=m,e[51]=l,e[52]=Fe):Fe=e[52];let Le;e[53]!==Fe?(Le=s.jsx($t,{children:Fe}),e[53]=Fe,e[54]=Le):Le=e[54];let oe;e[55]!==l?(oe=l("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=oe):oe=e[56];let fe;e[57]!==oe?(fe=s.jsx(Vt,{children:oe}),e[57]=oe,e[58]=fe):fe=e[58],e[59]!==Le||e[60]!==fe?(U=s.jsxs(_t,{children:[Le,fe]}),e[59]=Le,e[60]=fe,e[61]=U):U=e[61];let De,$e;e[62]!==be?(De=ye=>be(ye,"keydown"),$e=ye=>be(ye,"keyup"),e[62]=be,e[63]=De,e[64]=$e):(De=e[63],$e=e[64]);let Ve;e[65]===Symbol.for("react.memo_cache_sentinel")?(Ve=()=>N(Af),e[65]=Ve):Ve=e[65];let qe;e[66]!==c.chords?(qe=c.chords.map(Tf),e[66]=c.chords,e[67]=qe):qe=e[67];let se;e[68]!==c.livePreview?(se=c.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:Hn(c.livePreview)}):null,e[68]=c.livePreview,e[69]=se):se=e[69];let ie;e[70]!==c.chords.length||e[71]!==c.livePreview||e[72]!==l?(ie=c.chords.length===0&&!c.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=c.chords.length,e[71]=c.livePreview,e[72]=l,e[73]=ie):ie=e[73];let we;e[74]!==qe||e[75]!==se||e[76]!==ie?(we=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[qe,se,ie]}),e[74]=qe,e[75]=se,e[76]=ie,e[77]=we):we=e[77],e[78]!==De||e[79]!==$e||e[80]!==we?(Q=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:b,onKeyDown:De,onKeyUp:$e,onBlur:Ve,children:we}),e[78]=De,e[79]=$e,e[80]=we,e[81]=Q):Q=e[81],ne=c.settled&&L?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):c.settled&&W?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:m(W.action)})}):null,_=c.settled&&me&&!L&&!W?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:m(me.action)})}):null,re=c.settled&&Pe&&!L&&!W?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:d(Pe)})}):null,e[19]=a,e[20]=m,e[21]=A,e[22]=d,e[23]=h,e[24]=r,e[25]=i,e[26]=L,e[27]=c,e[28]=l,e[29]=T,e[30]=P,e[31]=I,e[32]=K,e[33]=W,e[34]=k,e[35]=F,e[36]=q,e[37]=U,e[38]=Q,e[39]=ne,e[40]=_,e[41]=re,e[42]=V,e[43]=$}else T=e[29],P=e[30],I=e[31],K=e[32],W=e[33],k=e[34],F=e[35],q=e[36],U=e[37],Q=e[38],ne=e[39],_=e[40],re=e[41],V=e[42],$=e[43];let z;e[82]!==A||e[83]!==c.settled||e[84]!==l?(z=c.settled&&A&&Jc(A)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=A,e[83]=c.settled,e[84]=l,e[85]=z):z=e[85];let O;e[86]!==l?(O=l("settings.common.actions.cancel"),e[86]=l,e[87]=O):O=e[87];let Y;e[88]!==I||e[89]!==O?(Y=s.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:I,children:O}),e[88]=I,e[89]=O,e[90]=Y):Y=e[90];const Z=!A||c.settled&&(!!L||!!W);let ee;e[91]!==l?(ee=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=ee):ee=e[92];let ge;e[93]!==K||e[94]!==Z||e[95]!==ee?(ge=s.jsx(B,{type:"button",size:"sm",disabled:Z,onClick:K,children:ee}),e[93]=K,e[94]=Z,e[95]=ee,e[96]=ge):ge=e[96];let de;e[97]!==Y||e[98]!==ge?(de=s.jsxs(ns,{children:[Y,ge]}),e[97]=Y,e[98]=ge,e[99]=de):de=e[99];let xe;e[100]!==T||e[101]!==k||e[102]!==F||e[103]!==q||e[104]!==U||e[105]!==Q||e[106]!==ne||e[107]!==_||e[108]!==re||e[109]!==z||e[110]!==de?(xe=s.jsxs(T,{className:k,initialFocus:F,showCloseButton:q,children:[U,Q,ne,_,re,z,de]}),e[100]=T,e[101]=k,e[102]=F,e[103]=q,e[104]=U,e[105]=Q,e[106]=ne,e[107]=_,e[108]=re,e[109]=z,e[110]=de,e[111]=xe):xe=e[111];let ae;return e[112]!==P||e[113]!==V||e[114]!==$||e[115]!==xe?(ae=s.jsx(P,{open:V,onOpenChange:$,children:xe}),e[112]=P,e[113]=V,e[114]=$,e[115]=xe,e[116]=ae):ae=e[116],ae};function Nf(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function Sf(t){return t.kind==="prefix"}function Cf(t){return t.kind==="exact"}function Pf(t){return t.kind==="contextual-prefix"}function If(t,e){t||e.cancel()}function Af(t){return{...t,livePreview:null}}function Tf(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:Hn(t)},`${t}-${e}`)}const Ef=["session","models","panels","navigation","application"],Df=()=>{const t=ut.c(24),{t:e}=it(),a=ce(Mf),n=ce(Rf),i=ce(Of),r=ce(Lf),[l,p]=o.useState(null);let m;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const A=Zc();m=ds()?A.filter(Ff):A,t[0]=m}else m=t[0];const f=m,d=Kf;let y;t[1]!==n||t[2]!==a?(y=(A,w,h)=>{const j={...a,[A]:w};h&&(j[h]=Li),n(A,w),h&&n(h,Li),d(j)},t[1]=n,t[2]=a,t[3]=y):y=t[3];const c=y;let N;t[4]!==i||t[5]!==a?(N=A=>{const w={...a};delete w[A],i(A),d(w)},t[4]=i,t[5]=a,t[6]=N):N=t[6];const b=N;let C;t[7]!==a||t[8]!==e?(C=A=>{const w="prefixStyle"in A&&A.prefixStyle,h=w?Xc(A.id,a):xl(A.id,a),j=Hn(h,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!w||!h||h===Li)return j;const L=A.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${j}${L}`},t[7]=a,t[8]=e,t[9]=C):C=t[9];const v=C;let S;t[10]!==r||t[11]!==b||t[12]!==v||t[13]!==a||t[14]!==e?(S=Ef.map((A,w)=>{const h=f.filter(j=>j.category===A);return h.length===0?null:s.jsx(_e,{settingsItem:w===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${A}`),divider:w!==0,info:w===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:w===0?s.jsx(B,{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:h.map(j=>s.jsxs(Ot,{label:e(j.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:v(j)}),s.jsx(B,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>p(j),children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),j.id in a?s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>b(j.id),children:e("settings.common.actions.reset")}):null]},j.id))})},A)}),t[10]=r,t[11]=b,t[12]=v,t[13]=a,t[14]=e,t[15]=S):S=t[15];let g;t[16]===Symbol.for("react.memo_cache_sentinel")?(g=A=>{A||p(null)},t[16]=g):g=t[16];let E;t[17]!==l||t[18]!==c||t[19]!==a?(E=s.jsx(kf,{action:l,overrides:a,onSave:c,onOpenChange:g}),t[17]=l,t[18]=c,t[19]=a,t[20]=E):E=t[20];let M;return t[21]!==S||t[22]!==E?(M=s.jsxs(s.Fragment,{children:[S,E]}),t[21]=S,t[22]=E,t[23]=M):M=t[23],M};function Mf(t){return t.shortcutOverrides}function Rf(t){return t.setShortcutOverride}function Of(t){return t.clearShortcutOverride}function Lf(t){return t.resetAllShortcutOverrides}function Ff(t){return t.id!=="toggle_prompt_navigator"}function Kf(t){vt({shortcutOverrides:t})}const Zl=()=>{const t=ut.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>yl(()=>a(Jf)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},zf=t=>{const e=ut.c(80),{section:a}=t,{t:n}=it(),{isMobile:i}=ua();Zl();let r;e[0]!==i?(r=i&&Vn(),e[0]=i,e[1]=r):r=e[1];const l=r;let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=ds(),e[2]=p):p=e[2];const m=p;let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=rs()&&$a(),e[3]=f):f=e[3];const d=f;if(!a){let _,re,V,$,z,O,Y,Z;e[4]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(vi,{}),$=s.jsx(Hl,{}),z=d&&s.jsx(Ql,{}),O=!m&&s.jsx(Wl,{}),Y=!m&&s.jsx(Jl,{}),Z=s.jsx($l,{}),_=s.jsx(Bl,{}),re=Vn()&&!rs()&&!m&&!kl()&&s.jsx(Vl,{}),e[4]=_,e[5]=re,e[6]=V,e[7]=$,e[8]=z,e[9]=O,e[10]=Y,e[11]=Z):(_=e[4],re=e[5],V=e[6],$=e[7],z=e[8],O=e[9],Y=e[10],Z=e[11]);let ee;e[12]!==l?(ee=l&&s.jsx(Pl,{}),e[12]=l,e[13]=ee):ee=e[13];let ge;return e[14]!==ee?(ge=s.jsxs(ss,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[V,$,z,O,Y,Z,_,re,ee]}),e[14]=ee,e[15]=ge):ge=e[15],ge}let y;e[16]!==a?(y=()=>{switch(a){case"general":return s.jsx(_f,{});case"visual":return s.jsx($f,{});case"chat":return s.jsx(Vf,{});case"sessions":return s.jsx(Bf,{});case"shortcuts":return s.jsx(Uf,{});case"git":return s.jsx(Hf,{});case"notifications":return s.jsx(Gf,{});case"voice":return s.jsx(qf,{});case"tunnel":return s.jsx(Wf,{});default:return null}},e[16]=a,e[17]=y):y=e[17];const c=y;let N;e[18]!==n?(N=n("settings.page.general.title"),e[18]=n,e[19]=N):N=e[19];let b;e[20]!==n?(b=n("settings.page.appearance.title"),e[20]=n,e[21]=b):b=e[21];let C;e[22]!==n?(C=n("settings.page.chat.title"),e[22]=n,e[23]=C):C=e[23];let v;e[24]!==n?(v=n("settings.page.sessions.title"),e[24]=n,e[25]=v):v=e[25];let S;e[26]!==n?(S=n("settings.page.shortcuts.title"),e[26]=n,e[27]=S):S=e[27];let g;e[28]!==n?(g=n("settings.page.git.title"),e[28]=n,e[29]=g):g=e[29];let E;e[30]!==n?(E=n("settings.page.git.title"),e[30]=n,e[31]=E):E=e[31];let M;e[32]!==n?(M=n("settings.page.notifications.title"),e[32]=n,e[33]=M):M=e[33];let A;e[34]!==n?(A=n("settings.page.voice.title"),e[34]=n,e[35]=A):A=e[35];let w;e[36]!==n?(w=n("settings.page.tunnel.title"),e[36]=n,e[37]=w):w=e[37];let h;e[38]!==g||e[39]!==E||e[40]!==M||e[41]!==A||e[42]!==w||e[43]!==N||e[44]!==b||e[45]!==C||e[46]!==v||e[47]!==S?(h={general:N,visual:b,chat:C,sessions:v,shortcuts:S,git:g,github:E,notifications:M,voice:A,tunnel:w},e[38]=g,e[39]=E,e[40]=M,e[41]=A,e[42]=w,e[43]=N,e[44]=b,e[45]=C,e[46]=v,e[47]=S,e[48]=h):h=e[48];const j=h[a];let L;e[49]!==n?(L=n("settings.page.general.description"),e[49]=n,e[50]=L):L=e[50];let T;e[51]!==n?(T=n("settings.page.appearance.description"),e[51]=n,e[52]=T):T=e[52];let P;e[53]!==n?(P=n("settings.page.chat.description"),e[53]=n,e[54]=P):P=e[54];let I;e[55]!==n?(I=n("settings.page.sessions.description"),e[55]=n,e[56]=I):I=e[56];let K;e[57]!==n?(K=n("settings.page.shortcuts.description"),e[57]=n,e[58]=K):K=e[58];let W;e[59]!==n?(W=n("settings.page.notifications.description"),e[59]=n,e[60]=W):W=e[60];let k;e[61]!==n?(k=n("settings.page.voice.description"),e[61]=n,e[62]=k):k=e[62];let F;e[63]!==n?(F=n("settings.page.tunnel.description"),e[63]=n,e[64]=F):F=e[64];let q;e[65]!==L||e[66]!==T||e[67]!==P||e[68]!==I||e[69]!==K||e[70]!==W||e[71]!==k||e[72]!==F?(q={general:L,visual:T,chat:P,sessions:I,shortcuts:K,git:void 0,github:void 0,notifications:W,voice:k,tunnel:F},e[65]=L,e[66]=T,e[67]=P,e[68]=I,e[69]=K,e[70]=W,e[71]=k,e[72]=F,e[73]=q):q=e[73];const U=q[a];let Q;e[74]!==c?(Q=c(),e[74]=c,e[75]=Q):Q=e[75];let ne;return e[76]!==U||e[77]!==j||e[78]!==Q?(ne=s.jsx(ss,{title:j,description:U,showSaveStatus:!0,className:"openchamber-page-body",children:Q}),e[76]=U,e[77]=j,e[78]=Q,e[79]=ne):ne=e[79],ne},Uf=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Df,{}),t[0]=e):e=t[0],e},_f=()=>{const t=ut.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ds(),t[0]=e):e=t[0];const a=e;Zl();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=rs()&&$a(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=Vn()&&!rs()&&!a&&!kl(),t[2]=r):r=t[2];const l=r;let p,m,f,d,y;t[3]===Symbol.for("react.memo_cache_sentinel")?(p=i&&s.jsx(Ql,{}),m=l&&s.jsx(Vl,{}),f=s.jsx(Bl,{}),d=!a&&s.jsx(Wl,{}),y=!a&&s.jsx(Jl,{}),t[3]=p,t[4]=m,t[5]=f,t[6]=d,t[7]=y):(p=t[3],m=t[4],f=t[5],d=t[6],y=t[7]);let c;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=a?[]:["sessionTabs"],t[8]=c):c=t[8];let N;return t[9]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsxs(s.Fragment,{children:[p,m,f,d,y,s.jsx(vi,{visibleSettings:["fileEditorKeymap",...c,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=N):N=t[9],N},$f=()=>{const t=ut.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(vi,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","inputBarOffset"]}),t[1]=n):n=t[1],n},Vf=()=>{const t=ut.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(vi,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste"]}),t[1]=n):n=t[1],n},Bf=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(Hl,{}),s.jsx($l,{})]}),t[0]=e):e=t[0],e},Hf=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(_l,{}),t[0]=e):e=t[0],e},Gf=()=>{const t=ut.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx($h,{}),t[0]=e):e=t[0],e},qf=()=>{const t=ut.c(1);if(ds())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Zh,{}),t[0]=e):e=t[0],e},Wf=()=>{const t=ut.c(1);if(ds())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(df,{}),t[0]=e):e=t[0],e};function Jf(t){return t+1}const Qf=t=>{const e=ut.c(85),{className:a}=t,{t:n}=it(),i=$n(bl),r=$n(Yf),l=ce(Zf),p=ce(Xf),[m,f]=We.useState(!1),[d,y]=We.useState(!1),c=i>0;let N;e[0]!==n?(N=async()=>{try{const Ne=await ed({message:n("settings.view.pendingRestart.applying")});if(Ne.requiresManualRestart){D.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Ne.ok&&D.success(n("settings.view.pendingRestart.applied"))}catch(Ne){const Se=Ne,be=Se instanceof Error&&Se.message?Se.message:n("settings.view.pendingRestart.applyFailed");D.error(be)}},e[0]=n,e[1]=N):N=e[1];const b=N;let C;e[2]!==n?(C=async()=>{try{await gl({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),$n.getState().clear()}catch{}},e[2]=n,e[3]=C):C=e[3];const v=C;let S;e[4]!==d||e[5]!==b||e[6]!==p?(S=()=>{d&&p(!1),f(!1),y(!1),b()},e[4]=d,e[5]=b,e[6]=p,e[7]=S):S=e[7];const g=S;let E;e[8]!==c||e[9]!==b||e[10]!==v||e[11]!==l?(E=()=>{if(!c){v();return}if(l){y(!1),f(!0);return}b()},e[8]=c,e[9]=b,e[10]=v,e[11]=l,e[12]=E):E=e[12];const M=E;let A;e[13]!==c||e[14]!==r||e[15]!==n?(A=n(c?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=c,e[14]=r,e[15]=n,e[16]=A):A=e[16];const w=A;let h;e[17]!==c||e[18]!==i||e[19]!==n?(h=c?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=c,e[18]=i,e[19]=n,e[20]=h):h=e[20];const j=h,L=c?"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]!==L||e[23]!==T?(P=ve("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-primary/50",L,T,a),e[21]=a,e[22]=L,e[23]=T,e[24]=P):P=e[24];let I;e[25]!==c||e[26]!==i?(I=c?s.jsx("span",{className:ve("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(R,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=c,e[26]=i,e[27]=I):I=e[27];let K;e[28]!==w?(K=s.jsx("span",{className:"truncate",children:w}),e[28]=w,e[29]=K):K=e[29];let W;e[30]!==M||e[31]!==r||e[32]!==I||e[33]!==K||e[34]!==P||e[35]!==j?(W=s.jsxs("button",{type:"button",disabled:r,title:j,"aria-label":j,onClick:M,className:P,children:[I,K]}),e[30]=M,e[31]=r,e[32]=I,e[33]=K,e[34]=P,e[35]=j,e[36]=W):W=e[36];let k;e[37]===Symbol.for("react.memo_cache_sentinel")?(k=Ne=>{f(Ne),Ne||y(!1)},e[37]=k):k=e[37];let F;e[38]!==n?(F=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=F):F=e[39];let q;e[40]!==F?(q=s.jsx($t,{children:F}),e[40]=F,e[41]=q):q=e[41];let U;e[42]!==n?(U=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=U):U=e[43];let Q;e[44]!==U?(Q=s.jsx(Vt,{children:U}),e[44]=U,e[45]=Q):Q=e[45];let ne;e[46]!==q||e[47]!==Q?(ne=s.jsxs(_t,{children:[q,Q]}),e[46]=q,e[47]=Q,e[48]=ne):ne=e[48];let _;e[49]===Symbol.for("react.memo_cache_sentinel")?(_={width:"40%"},e[49]=_):_=e[49];let re;e[50]===Symbol.for("react.memo_cache_sentinel")?(re=()=>f(!1),e[50]=re):re=e[50];let V;e[51]!==n?(V=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=V):V=e[52];let $;e[53]!==V?($=s.jsx("div",{className:"min-w-0 shrink-0",style:_,children:s.jsx(B,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:re,children:V})}),e[53]=V,e[54]=$):$=e[54];let z;e[55]===Symbol.for("react.memo_cache_sentinel")?(z={width:"40%"},e[55]=z):z=e[55];let O;e[56]!==n?(O=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=O):O=e[57];let Y;e[58]!==g||e[59]!==O?(Y=s.jsx("div",{className:"min-w-0 shrink-0",style:z,children:s.jsx(B,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:g,children:O})}),e[58]=g,e[59]=O,e[60]=Y):Y=e[60];let Z;e[61]!==$||e[62]!==Y?(Z=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[$,Y]}),e[61]=$,e[62]=Y,e[63]=Z):Z=e[63];let ee;e[64]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>y(ex),e[64]=ee):ee=e[64];let ge;e[65]!==d?(ge=d?s.jsx(R,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(R,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=d,e[66]=ge):ge=e[66];let de;e[67]!==n?(de=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=de):de=e[68];let xe;e[69]!==d||e[70]!==ge||e[71]!==de?(xe=s.jsxs("button",{type:"button",onClick:ee,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-primary/50","aria-pressed":d,children:[ge,de]}),e[69]=d,e[70]=ge,e[71]=de,e[72]=xe):xe=e[72];let ae;e[73]!==Z||e[74]!==xe?(ae=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[Z,xe]}),e[73]=Z,e[74]=xe,e[75]=ae):ae=e[75];let te;e[76]!==ne||e[77]!==ae?(te=s.jsxs(zt,{showCloseButton:!1,className:"max-w-md gap-5",children:[ne,ae]}),e[76]=ne,e[77]=ae,e[78]=te):te=e[78];let me;e[79]!==m||e[80]!==te?(me=s.jsx(Kt,{open:m,onOpenChange:k,children:te}),e[79]=m,e[80]=te,e[81]=me):me=e[81];let Pe;return e[82]!==W||e[83]!==me?(Pe=s.jsxs(s.Fragment,{children:[W,me]}),e[82]=W,e[83]=me,e[84]=Pe):Pe=e[84],Pe};function Yf(t){return t.isApplying}function Zf(t){return t.showOpenCodeRestartConfirm}function Xf(t){return t.setShowOpenCodeRestartConfirm}function ex(t){return!t}const tx=[{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.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.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.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:"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-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-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:"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}];function Xo(t){return t.trim().toLocaleLowerCase()}function sx({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=Xo(t);if(!r)return[];const l=a?new Set(a):null,p=r.split(/\s+/).filter(Boolean);return tx.flatMap(m=>{if(l&&!l.has(m.page))return[];const f=Ma(m.page);if(!f||f.isAvailable&&!f.isAvailable(e)||m.isAvailable&&!m.isAvailable(e))return[];const d=n(m.titleKey),y=m.descriptionKey?n(m.descriptionKey):null,c=Xo([d,y,i(m.page),...m.keywords??[]].filter(Boolean).join(" "));return p.every(N=>c.includes(N))?[{...m,title:d,description:y,pageTitle:i(m.page)}]:[]})}const el=256,tl=280,Xl="__openchamberSettingsDetail",nx=["general","appearance","chat","notifications","sessions","shortcuts","voice","integrations","usage","about","projects","remote-instances","tunnel","git","providers","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],ax=["general","projects","opencode","content"],ix="__add_provider__";function rx(t,e){const a=ds(),n=!t&&Vn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function sl(t,e){return t.isAvailable?t.isAvailable(e):!0}function lr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Da(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function Ji(t){if(!lr(t))return null;const e=t[Xl];if(!lr(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Nl(a),stage:n}}function ox(){return typeof window>"u"||!lr(window.history.state)?{}:window.history.state}const bx=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:i="nav"})=>{const{t:r}=it(),l=ua(),p=e??l.isMobile,m=$n(bl),f=ce(se=>se.settingsPage),d=ce(se=>se.isSettingsDialogOpen),y=ce(se=>se.setSettingsPage),c=ce(se=>se.shortcutOverrides.open_settings),N=Nl(f),[b,C]=o.useState(i),v=o.useRef(i==="nav"?N:null);o.useEffect(()=>{!p&&N==="home"&&y("general")},[p,y,N]);const[S,g]=o.useState(""),[E,M]=o.useState(null),[A,w]=o.useState(0),h=o.useRef(null),j=o.useRef(!1),L=o.useRef([]),T=o.useRef(0),P=o.useRef(!1),I=o.useMemo(()=>rs(),[]),K=o.useMemo(()=>rs()&&$a(),[]),W=o.useMemo(()=>rs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),k=o.useMemo(()=>rs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),F=o.useMemo(()=>rs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),q=o.useMemo(()=>wl(),[]),U=o.useMemo(()=>rx(I,p),[I,p]),Q=o.useMemo(()=>{const se=n?new Set(n):null;return Md.filter(ie=>ie.slug!=="home").filter(ie=>!se||se.has(ie.slug)).filter(ie=>sl(ie,U)).filter(ie=>!(U.isVSCode&&ie.slug==="projects")).filter(ie=>!(p&&ie.slug==="shortcuts"))},[U,p,n]),ne=o.useMemo(()=>{const se=new Map(nx.map((ie,we)=>[ie,we]));return Q.slice().sort((ie,we)=>(se.get(ie.slug)??999)-(se.get(we.slug)??999))},[Q]),_=Vs(se=>se.activeProjectId),re=Us();o.useEffect(()=>{if(!(!d&&!U.isVSCode&&!a)){if(N==="agents"){Bn.getState().loadAgents(re);return}if(N==="commands"){pa.getState().loadCommands(re);return}if(N==="mcp"){ma.getState().loadMcpConfigs({directory:re});return}if(N==="plugins"){us.getState().loadPlugins();return}(N==="skills.installed"||N==="skills.catalog")&&($s.getState().loadSkills(re),hn.getState().loadCatalog()),N==="snippets"&&fi.getState().loadSnippets()}},[_,d,a,U.isVSCode,re,N]);const V=o.useCallback(se=>{if(y(se),v.current=se,!p)return;const ie=Ma(se);if(!ie||ie.slug==="home"){C("nav");return}C(ie.kind==="split"?"page-sidebar":"page-content")},[p,y]),$=o.useMemo(()=>Ma(N),[N]),z=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),O=o.useCallback(se=>{switch(se){case"general":return r("settings.page.general.title");case"projects":return r("settings.page.projects.title");case"remote-instances":return r("settings.page.remoteInstances.title");case"providers":return r("settings.page.providers.title");case"usage":return r("settings.page.usage.title");case"agents":return r("settings.page.agents.title");case"behavior":return r("settings.page.behavior.title");case"commands":return r("settings.page.commands.title");case"mcp":return r("settings.page.mcp.title");case"plugins":return r("settings.page.plugins.title");case"skills.installed":return r("settings.page.skills.title");case"skills.catalog":return r("settings.page.skillsCatalog.title");case"git":return r("settings.page.git.title");case"integrations":return r("settings.page.integrations.title");case"appearance":return r("settings.page.appearance.title");case"chat":return r("settings.page.chat.title");case"shortcuts":return r("settings.page.shortcuts.title");case"sessions":return r("settings.page.sessions.title");case"magic-prompts":return r("settings.page.magicPrompts.title");case"snippets":return r("settings.page.snippets.title");case"notifications":return r("settings.page.notifications.title");case"voice":return r("settings.page.voice.title");case"tunnel":return r("settings.page.tunnel.title");case"about":return r("settings.page.about.title");default:return r("settings.view.home.title")}},[r]),Y=o.useMemo(()=>sx({query:S,runtimeCtx:{...U,isDesktopLocalOrigin:K,isMac:W,isWindows:k,isLinux:F,isWindowsArm64:q},visiblePageSlugs:n,t:r,getPageTitle:O}),[O,q,K,W,k,F,U,S,r,n]),Z=o.useCallback(se=>{if(se.id.startsWith("agents.")){const ie=Bn.getState(),we=Da("new-agent",ie.agents.map(ye=>ye.name));return ie.setAgentDraft({name:we,scope:"user"}),ie.setSelectedAgent(we),se.id==="agents.create"?"agents.name":se.id}if(se.id.startsWith("commands.")){const ie=pa.getState(),we=Da("new-command",ie.commands.map(ye=>ye.name));return ie.setCommandDraft({name:we,scope:"user"}),ie.setSelectedCommand(we),se.id==="commands.create"?"commands.name":se.id}if(se.id.startsWith("mcp.")){const ie=ma.getState(),we=Da("new-mcp-server",ie.mcpServers.map(ye=>ye.name));return ie.setMcpDraft({name:we,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),ie.setSelectedMcp(we),se.id==="mcp.create"?"mcp.server":se.id}if(se.id.startsWith("snippets.")){const ie=fi.getState(),we=Da("new-snippet",ie.snippets.map(ye=>ye.name));return ie.setSnippetDraft({name:we,scope:"global"}),ie.setSelectedSnippet(we),se.id==="snippets.create"?"snippets.content":se.id}if(se.id.startsWith("skills.")){const ie=$s.getState(),we=Da("new-skill",ie.skills.map(ye=>ye.name));return ie.setSkillDraft({name:we,scope:"user",source:"opencode",description:"",instructions:""}),ie.setSelectedSkill(we),se.id==="skills.create"?"skills.basic-information":se.id}return se.id==="providers.connect"&&et.getState().setSelectedProvider(ix),se.id==="plugins.create"?"plugins.spec":se.id},[]),ee=o.useMemo(()=>{const se=[],ie=new Map;for(const we of Y){let ye=ie.get(we.page);ye||(ye={page:we.page,pageTitle:we.pageTitle,results:[]},ie.set(we.page,ye),se.push(ye)),ye.results.push(we)}return se},[Y]);o.useEffect(()=>{w(0),T.current=0,P.current=!1},[S]),o.useEffect(()=>{T.current=A},[A]),o.useEffect(()=>{L.current[A]?.scrollIntoView({block:"nearest"})},[A]),o.useEffect(()=>{A>=Y.length&&w(Math.max(0,Y.length-1)),L.current.length=Y.length},[A,Y.length]);const ge=o.useCallback(se=>{const ie=Z(se);M(ie),V(se.page),p&&C("page-content"),se.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[p,V,Z]),de=o.useCallback(se=>{if(S.trim()){if(se.key==="Escape"){se.preventDefault(),g("");return}if(Y.length!==0){if(se.key==="ArrowDown"){se.preventDefault(),P.current=!0,w(ie=>(ie+1)%Y.length);return}if(se.key==="ArrowUp"){se.preventDefault(),P.current=!0,w(ie=>(ie-1+Y.length)%Y.length);return}if(se.key==="Enter"){se.preventDefault();const ie=(T.current%Y.length+Y.length)%Y.length,we=Y[ie]??Y[0];we&&ge(we)}}}},[ge,S,Y]);o.useEffect(()=>{const se=E;if(!se)return;let ie=!1;const we=window.requestAnimationFrame(()=>{if(ie)return;const ye=typeof CSS<"u"&&CSS.escape?CSS.escape(se):se.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Te=h.current?.querySelector(`[data-settings-item="${ye}"]`);Te&&(M(null),Te.scrollIntoView({block:"center",behavior:"smooth"}),Te.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Te.removeAttribute("data-settings-search-highlight")},1600))});return()=>{ie=!0,window.cancelAnimationFrame(we)}},[E,N]);const xe=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:ml,children:r("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:r("settings.view.unavailable.description")})]})}),[r]),ae=o.useCallback((se,ie)=>{switch(se){case"projects":return s.jsx(fu,{onItemSelect:ie.onItemSelect});case"agents":return s.jsx(sp,{onItemSelect:ie.onItemSelect});case"commands":return s.jsx(vp,{onItemSelect:ie.onItemSelect});case"mcp":return s.jsx(Pp,{onItemSelect:ie.onItemSelect});case"plugins":return s.jsx(gm,{onItemSelect:ie.onItemSelect});case"skills.installed":return s.jsx(Im,{onItemSelect:ie.onItemSelect});case"providers":return s.jsx(Bu,{onItemSelect:ie.onItemSelect});case"usage":return s.jsx(Pg,{onItemSelect:ie.onItemSelect});case"magic-prompts":return s.jsx(Bg,{onItemSelect:ie.onItemSelect});case"snippets":return s.jsx(Wg,{onItemSelect:ie.onItemSelect});default:return null}},[]),te=o.useCallback(se=>{const ie=Ma(se);if(ie&&!sl(ie,U))return xe();switch(se){case"projects":return s.jsx(ju,{});case"remote-instances":return s.jsx(_u,{});case"agents":return s.jsx(up,{});case"behavior":return s.jsx(bp,{});case"commands":return s.jsx(Cp,{});case"mcp":return s.jsx(Jp,{});case"plugins":return s.jsx(Cm,{});case"skills.installed":return s.jsx(po,{view:"installed"});case"skills.catalog":return s.jsx(po,{view:"catalog"});case"providers":return s.jsx(Sg,{});case"usage":return s.jsx($g,{});case"about":return s.jsx(ss,{title:r("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Pl,{})});case"magic-prompts":return s.jsx(qg,{});case"snippets":return s.jsx(Zg,{});case"git":return s.jsx(nh,{});case"integrations":return s.jsx(bh,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const we=z[se]??"visual";return s.jsx(zf,{section:we})}default:return null}},[z,xe,U,r]);o.useEffect(()=>{if(!p||b!=="nav"||N==="home"||v.current===N)return;const se=Ma(N);!se||se.slug==="home"||(v.current=N,C(se.kind==="split"?"page-sidebar":"page-content"))},[p,b,N]);const me=p&&b!=="nav",Pe=p&&b==="page-content"&&N==="skills.installed",Ne=b==="page-content"&&$?.kind==="split"&&!Pe,Se=r(Pe?"settings.view.actions.back":me?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),be=xl("open_settings",c===void 0?void 0:{open_settings:c}),Fe=be?r("settings.view.actions.closeSettingsWithShortcut",{shortcut:Hn(be)}):r("settings.view.actions.closeSettings"),Le=o.useCallback(se=>{if(typeof window>"u"||U.isVSCode)return;const ie=Ji(window.history.state);ie?.page===se&&ie.stage==="page-content"||window.history.pushState({...ox(),[Xl]:{page:se,stage:"page-content"}},"",window.location.href)},[U.isVSCode]),oe=o.useCallback(()=>{j.current=!0,C("page-content"),N==="skills.installed"&&Le(N)},[Le,N]);o.useEffect(()=>{if(!p||b!=="page-content"||!j.current)return;j.current=!1;const se=window.requestAnimationFrame(()=>{h.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(se)}},[p,b,N]);const fe=o.useCallback(()=>{if(Pe){if((typeof window<"u"?Ji(window.history.state):null)?.page===N&&!U.isVSCode){window.history.back();return}C("page-sidebar");return}C("nav")},[Pe,U.isVSCode,N]);o.useEffect(()=>{if(!p||U.isVSCode)return;const se=ie=>{if(N!=="skills.installed")return;if(Ji(ie.state)?.page==="skills.installed"){C("page-content");return}C(ye=>ye==="page-content"?"page-sidebar":ye)};return window.addEventListener("popstate",se),()=>{window.removeEventListener("popstate",se)}},[p,U.isVSCode,N]);const De=o.useCallback(()=>{C("page-sidebar")},[]),$e=()=>{const se=S.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:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[s.jsx(R,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:S,onChange:ie=>g(ie.target.value),onKeyDown:de,placeholder:r("settings.view.search.placeholder"),"aria-label":r("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:()=>g(""),"aria-label":r("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(R,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:se?Y.length>0?(()=>{let ie=0;return ee.map(we=>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:we.pageTitle}),we.results.map(ye=>{const Te=ie;ie+=1;const Ue=Te===A,Ie=!!ye.description;return s.jsxs("button",{type:"button",ref:je=>{L.current[Te]=je},onMouseMove:()=>{P.current=!1,w(Te)},onClick:()=>ge(ye),className:ve("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ie?"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:ye.title}),Ie&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:ye.description})]},ye.id)})]},we.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:r("settings.view.search.noResults")}):(()=>{const ie=new Map;for(const ye of ne){const Te=ye.group,Ue=ie.get(Te);Ue?Ue.push(ye):ie.set(Te,[ye])}return ax.map(ye=>({group:ye,pages:ie.get(ye)??[]})).filter(ye=>ye.pages.length>0).map(({group:ye,pages:Te},Ue)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:ve("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:r(`settings.view.nav.group.${ye}`)}),Te.map(Ie=>{const je=N===Ie.slug&&!(p&&b==="nav"),Ge=Rd(Ie.slug);return!Ge&&Ie.slug!=="mcp"?null:s.jsx(pr,{children:s.jsx(mr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>V(Ie.slug),"aria-current":je?"page":void 0,className:ve("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",je?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Ie.slug==="mcp"?s.jsx(td,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(R,{name:Ge,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:O(Ie.slug)}),Ie.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:r("settings.view.badge.beta")})]})]})})},Ie.slug)})]},ye))})()})}),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:(!U.isVSCode||m>0)&&s.jsx(Qf,{})})})]})},Ve=()=>{if(b==="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(wn,{children:$e()})})});if(!$)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if($.kind!=="split"){const ie=te(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(wn,{children:ie})})}return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(wn,{children:ae(N,{onItemSelect:oe})})})}const se=te(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(wn,{children:se})})},qe=()=>!$||N==="home"?null:$.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ve("border-r",U.isVSCode?"bg-background":"bg-sidebar"),style:{width:tl,minWidth:tl,borderColor:"var(--interactive-border)"},children:s.jsx(wn,{children:ae(N,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(wn,{children:te(N)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(wn,{children:te(N)})});return s.jsxs("div",{ref:h,"data-settings-view":"true",className:ve("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[p?s.jsxs("div",{className:ve("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",b!=="nav"&&"border-b","bg-background"),style:b!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[me?s.jsx("button",{type:"button",onClick:fe,"aria-label":Se,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{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:b==="nav"?r("settings.view.home.title"):$?O($.slug):r("settings.view.home.title")}),Ne&&s.jsx("button",{type:"button",onClick:De,"aria-label":r("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{name:"list-unordered",className:"h-5 w-5"})}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Fe,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[me&&s.jsx("div",{className:ve("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:fe,"aria-label":r("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:ve("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Fe,className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(R,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:p?Ve():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ve("relative flex h-full min-h-0 flex-col overflow-hidden border-r",I?"bg-sidebar":U.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${el}px`,minWidth:`${el}px`,borderColor:"var(--interactive-border)"},children:s.jsx(wn,{children:$e()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:qe()})]})})]})};export{Pl as A,bx as S};