@openchamber/web 1.14.1 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.test.js +8 -0
- package/bin/lib/DOCUMENTATION.md +3 -0
- package/bin/lib/cli-args.js +10 -0
- package/bin/lib/commands-connect-url.js +169 -22
- package/dist/assets/{DiagramView-Cb58svCq.js → DiagramView-he_RFVx5.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-CdBIHSPZ.js +11 -0
- package/dist/assets/{MultiRunWindow-BPSxV_B7.js → MultiRunWindow-B_C-tvVq.js} +1 -1
- package/dist/assets/OnboardingScreen-BBnTt-9w.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-CWWrCFzr.js +1 -0
- package/dist/assets/SettingsWindow-CjqLdpTE.js +1 -0
- package/dist/assets/{TerminalView-fTYjnQkh.js → TerminalView-DQcdegHp.js} +1 -1
- package/dist/assets/es-r0_jT91q.js +15 -0
- package/dist/assets/fr-Bo8rtAJ1.js +13 -0
- package/dist/assets/index-8J6waVO6.js +2 -0
- package/dist/assets/index-DEMqM4Lz.css +1 -0
- package/dist/assets/ja-BPWtkG-c.js +15 -0
- package/dist/assets/ko-Bv0k-0E3.js +15 -0
- package/dist/assets/main-B-GA5Tg5.js +237 -0
- package/dist/assets/main-Dfm-VKZ9.js +2 -0
- package/dist/assets/miniChat-CfmCFFfu.js +2 -0
- package/dist/assets/mobile-CXJqeDlm.js +2 -0
- package/dist/assets/pl-CiTP50bz.js +15 -0
- package/dist/assets/pt-BR-DadIjX5L.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-DS7Dy2ii.js +2 -0
- package/dist/assets/renderMobileApp-o7Fs9EBx.js +16 -0
- package/dist/assets/runtimeEndpointReset-MTaPPm4F.js +167 -0
- package/dist/assets/uk-2RpsWGoZ.js +15 -0
- package/dist/assets/{useAppFontEffects-BUUJYbAZ.js → useAppFontEffects-DkPuAMXD.js} +196 -133
- package/dist/assets/{vendor-.bun-C6iL44L9.js → vendor-.bun-BE757pvp.js} +1 -1
- package/dist/assets/zh-CN-BwKWaTuz.js +15 -0
- package/dist/assets/zh-TW--f_BqBpD.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -2
- package/server/index.js +236 -2
- package/server/lib/client-auth/pairing.js +308 -0
- package/server/lib/client-auth/pairing.test.js +142 -0
- package/server/lib/client-auth/remote-clients.js +65 -3
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/apns-runtime.js +11 -16
- package/server/lib/notifications/runtime.js +135 -33
- package/server/lib/opencode/DOCUMENTATION.md +1 -0
- package/server/lib/opencode/agents.js +3 -0
- package/server/lib/opencode/bootstrap-runtime.js +15 -0
- package/server/lib/opencode/core-routes.js +321 -8
- package/server/lib/opencode/core-routes.test.js +329 -9
- package/server/lib/opencode/feature-routes-runtime.js +6 -0
- package/server/lib/opencode/network-runtime.js +14 -1
- package/server/lib/opencode/network-runtime.test.js +29 -9
- package/server/lib/opencode/proxy.js +47 -6
- package/server/lib/opencode/settings-helpers.js +24 -0
- package/server/lib/opencode/settings-helpers.test.js +25 -0
- package/server/lib/opencode/settings-normalization-runtime.js +21 -4
- package/server/lib/opencode/settings-normalization-runtime.test.js +21 -0
- package/server/lib/opencode/settings-runtime.js +25 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/tunnel-auth.js +4 -9
- package/server/lib/package-manager.js +18 -5
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +34 -0
- package/server/lib/permission-auto-accept/runtime.js +263 -0
- package/server/lib/permission-auto-accept/runtime.test.js +137 -0
- package/server/lib/projects/project-config.js +8 -0
- package/server/lib/quota/DOCUMENTATION.md +5 -2
- package/server/lib/quota/credentials/providers.js +43 -0
- package/server/lib/quota/credentials/store.js +48 -0
- package/server/lib/quota/credentials/store.test.js +26 -0
- package/server/lib/quota/opencode-go-credentials.js +11 -0
- package/server/lib/quota/opencode-go-credentials.test.js +32 -0
- package/server/lib/quota/providers/codex.js +7 -4
- package/server/lib/quota/providers/codex.test.js +48 -0
- package/server/lib/quota/providers/cursor.js +28 -39
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/ollama-cloud.js +23 -42
- package/server/lib/quota/providers/ollama-cloud.test.js +12 -0
- package/server/lib/quota/providers/opencode-go.js +70 -0
- package/server/lib/quota/providers/opencode-go.test.js +17 -0
- package/server/lib/quota/routes.js +78 -7
- package/server/lib/quota/routes.test.js +40 -0
- package/server/lib/relay/DOCUMENTATION.md +98 -0
- package/server/lib/relay/cross-compat.test.js +135 -0
- package/server/lib/relay/e2ee.js +341 -0
- package/server/lib/relay/e2ee.test.js +124 -0
- package/server/lib/relay/host-client.js +389 -0
- package/server/lib/relay/host-client.test.js +280 -0
- package/server/lib/relay/host-lock.js +101 -0
- package/server/lib/relay/host-lock.test.js +129 -0
- package/server/lib/relay/identity.js +93 -0
- package/server/lib/relay/identity.test.js +78 -0
- package/server/lib/relay/service.js +334 -0
- package/server/lib/relay/signing-key.js +73 -0
- package/server/lib/relay/tunnel-codec.js +373 -0
- package/server/lib/relay/tunnel-codec.test.js +58 -0
- package/server/lib/relay/tunnel-host.js +462 -0
- package/server/lib/scheduled-tasks/runtime.js +104 -0
- package/server/lib/session-goal/DOCUMENTATION.md +176 -0
- package/server/lib/session-goal/objectives.js +61 -0
- package/server/lib/session-goal/routes.js +36 -0
- package/server/lib/session-goal/runtime.js +764 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +6 -0
- package/server/lib/ui-auth/ui-auth.js +10 -0
- package/server/opencode-proxy.test.js +38 -0
- package/dist/assets/MarkdownRendererImpl-D2yCDL5A.js +0 -7
- package/dist/assets/OnboardingScreen-Sl-6JgaP.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-4FWg9xMC.js +0 -1
- package/dist/assets/SettingsWindow-CY8q4msv.js +0 -1
- package/dist/assets/es-bWcuDy_2.js +0 -15
- package/dist/assets/fr-DzRs3OzV.js +0 -13
- package/dist/assets/index-KnWk9fmM.css +0 -1
- package/dist/assets/index-ZJTzZ0_U.js +0 -2
- package/dist/assets/ja-BqUX_UD3.js +0 -15
- package/dist/assets/ko-BQo10SNx.js +0 -15
- package/dist/assets/main-BDoqLlQB.js +0 -236
- package/dist/assets/main-DUGyTrDt.js +0 -2
- package/dist/assets/miniChat-DNDiX8GA.js +0 -2
- package/dist/assets/mobile-DnghtOCb.js +0 -2
- package/dist/assets/pl-Bgx_ATJT.js +0 -15
- package/dist/assets/pt-BR-B1yXRvoX.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-BB4C1K7t.js +0 -2
- package/dist/assets/renderMobileApp-CZgaXKi5.js +0 -16
- package/dist/assets/runtimeEndpointReset-By39StyB.js +0 -167
- package/dist/assets/uk-C9k8SP8q.js +0 -15
- package/dist/assets/zh-CN-Bri-Vo5y.js +0 -15
- package/dist/assets/zh-TW-DAUGzmYG.js +0 -15
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import{am as id,b as et,an as od,j as t,r as xe,ao as ld,ap as cd,a as wn,d as Na,p as Ii,R as o,O as Ps,ad as dd,ae as ud,ac as md,af as pd,aa as gd,ab as hd,ag as fd,aq as xd,ar as yd,as as bd,u as vd,l as jd,n as wd,w as Nd,C as kd,S as Sd,at as Cd,a8 as Id,D as Pd,q as Ad,au as Dd,av as Ed,aw as Md,ax as Td,ay as Rd,$ as Bs,az as Fd,aA as Ln,aB as Ki,aC as Ld,aD as Od,aE as kr,aF as zd,aG as Kd,aH as Ud,aI as Ui,aJ as tr,aK as Bi,k as Ha,aL as ec,aM as Pi,aN as or,aO as tc,aP as $i,aQ as Bd,aR as $d,aS as Vd,aT as _d,aU as Vi,aV as Ee,aW as Ia,aX as Hd,aY as Wd,aZ as Gd,a_ as qd,a$ as Jd,b0 as sc,a9 as Qd,b1 as _i,b2 as Yd,b3 as Xd,b4 as Zd,b5 as eu}from"./vendor-.bun-BE757pvp.js";import{dI as lr,A as sr,C as nr,v as ce,dJ as Wa,dK as Ga,dL as qa,b as es,c as st,I as E,aJ as St,aK as Ct,aL as It,V as tu,as as su,g as nc,o as tn,b8 as Rt,b7 as Ft,b6 as zt,bL as _t,D as ii,B as q,bk as Ai,y as En,aH as Ds,t as _,a2 as ac,dM as Jn,dN as nu,dO as au,dx as ru,dP as iu,dQ as ou,dR as lu,G as fs,dS as cu,d2 as du,d3 as uu,d4 as mu,cb as pu,aD as ls,aF as cs,cc as gu,aG as ds,a$ as cr,dT as hu,dU as Wn,b5 as Kt,bx as $t,bT as Gt,w as Xe,dV as va,aC as Ns,Y as lt,du as fu,bM as At,bN as Dt,bO as Ot,bP as Et,bQ as mt,bj as us,b0 as ja,dW as fn,cI as xs,b3 as yt,dX as rc,dY as xu,dZ as yu,d_ as dr,d$ as Zs,e0 as Qn,b2 as ic,e1 as Qs,e2 as bu,e3 as vu,e4 as ju,e5 as wu,e6 as Nu,e7 as ku,e8 as Ys,e9 as Su,z as ur,ch as Hi,p as Cu,cj as oi,aj as oc,L as Iu,P as lc,N as cc,cl as Pu,U as Wi,db as Au,ds as dc,dg as uc,di as Du,ea as Eu,u as li,cK as Mu,eb as Gi,ec as Tu,ed as Ru,ee as qi,ef as Fu,eg as Lu,eh as Ou,ei as zu,aI as Ku,ej as Uu,O as Bu,Q as $u,d as Di,ek as Vu,el as _u,ao as Yn,an as mc,am as Hu,em as Wu,en as Ji,ap as Gu,aq as qu,al as Ju,aN as Qu,aO as Yu,aP as pc,eo as Sr,ep as Qi,eq as Xu,er as Zu,es as em,et as tm,dj as mr,Z as Xs,eu as sm,ev as nm,ew as am,ex as rm,ey as im,ez as Cr,eA as Yi,eB as om,eC as lm,eD as cm,eE as dm,eF as um,eG as Ir,eH as mm,aY as Xi,eI as Vn,aX as pm,eJ as gm,eK as Zi,eL as eo,ck as hm,a4 as pn,F as fm,S as xm,eM as ym,cv as Pa,bp as ci,bq as di,br as ui,bs as mi,bt as Js,bu as zs,bU as Gn,M as ya,eN as to,c4 as bm,eO as gc,bW as vm,dn as jm,j as wm,eP as Pr,ai as Nm,bd as Aa,b_ as km,eQ as Sm,eR as Cm,dh as Im,eS as Pm,eT as Am,eU as hc,dG as Dm,eV as Em}from"./useAppFontEffects-DkPuAMXD.js";import{P as Ei,h as ct,o as ys,e as ws,ab as Mm,ac as so,ad as Tm,ae as Rm,E as ms,X as Dn,u as Ie,w as ta,a as no,t as Nt,d as sa,l as Vs,v as ns,F as ao,af as ro,ag as io,I as ca,ah as Fm,k as Lm,ai as _n,aj as Om,H as zm,ak as Km,s as Um,al as Bm,am as fc,S as $m,an as Ar,Q as Vm,ao as oo,ap as _m,J as Hm,aq as lo,ar as co,as as uo,at as mo,au as Dr,av as po,O as xc,aw as Wm,ax as Gm,ay as qm,az as Jm,aA as Qm,aB as Ym,aa as Xm,n as Zm,aC as ep,aD as tp,aE as sp,aF as yc}from"./index-8J6waVO6.js";import{g as np,s as ap}from"./mobileLayoutPreference-Dio-WWkI.js";function rp(){return new Worker(id,{type:"module"})}const ip=["typescript","javascript","tsx","jsx","json","markdown"],pi={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let go,ho;const fo=s=>{const e=pi[s],n=new od({workerFactory:rp,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:ip,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},op=s=>{if(!(typeof window>"u"))return s==="split"?(ho??=fo("split"),ho):(go??=fo("unified"),go)},lp=s=>{const e=et.c(7),{children:n,renderTheme:a}=s,r=gi("unified"),i=gi("split");let l,d;e[0]!==a||e[1]!==i||e[2]!==r?(l=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:pi.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:pi.split.lineDiffType})},d=[a,i,r],e[0]=a,e[1]=i,e[2]=r,e[3]=l,e[4]=d):(l=e[3],d=e[4]),xe.useEffect(l,d);let c;return e[5]!==n?(c=t.jsx(t.Fragment,{children:n}),e[5]=n,e[6]=c):c=e[6],c},Vj=s=>{const e=et.c(11),{children:n}=s,a=lr();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const h=sr(!1),m=sr(!0),p=a?.lightThemeId??h.metadata.id,u=a?.darkThemeId??m.metadata.id;i=a?.availableThemes.find(w=>w.metadata.id===p)??h,r=a?.availableThemes.find(w=>w.metadata.id===u)??m,nr(i),nr(r),e[0]=a?.availableThemes,e[1]=a?.darkThemeId,e[2]=a?.lightThemeId,e[3]=r,e[4]=i}else r=e[3],i=e[4];let l;e[5]!==r.metadata.id||e[6]!==i.metadata.id?(l={light:i.metadata.id,dark:r.metadata.id},e[5]=r.metadata.id,e[6]=i.metadata.id,e[7]=l):l=e[7];const d=l;let c;return e[8]!==n||e[9]!==d?(c=t.jsx(lp,{renderTheme:d,children:n}),e[8]=n,e[9]=d,e[10]=c):c=e[10],c},gi=s=>{const e=et.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=op(n),e[0]=n,e[1]=a):a=e[1],a};function cp(s){const e=et.c(4);let n,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=t.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),a=t.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=a):(n=e[0],a=e[1]);let r;return e[2]!==s?(r=t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...s,children:[n,a]}),e[2]=s,e[3]=r):r=e[3],r}const ar=xe.forwardRef((s,e)=>{const n=et.c(11);let a,r;n[0]!==s?({className:a,...r}=s,n[0]=s,n[1]=a,n[2]=r):(a=n[1],r=n[2]);let i;n[3]!==a?(i=ce("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",a),n[3]=a,n[4]=i):i=n[4];let l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let d;n[6]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(ld,{className:ce("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=d):d=n[6];let c;return n[7]!==r||n[8]!==e||n[9]!==i?(c=t.jsx(cd,{className:i,style:l,...r,ref:e,children:d}),n[7]=r,n[8]=e,n[9]=i,n[10]=c):c=n[10],c});ar.displayName="Switch";const Da=()=>{try{const e=es.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=ys.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[McpConfigStore] Error resolving config directory:",s)}return null},xo=s=>s?Object.entries(s).map(([e,n])=>({key:e,value:n})):[],yo=s=>{const e=s.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},Ea=s=>typeof s!="string"?void 0:s.trim()||void 0,Er=800,dp=5e3,up="__default__",hi=new Map,Mr=new Map,bc=s=>s?.trim()||up,Tr=s=>{hi.delete(bc(s))},Zn=wn()(Na(Ii((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=Da(),r=bc(a),i=Date.now(),l=hi.get(r)??0,d=e().mcpServers.length>0;if(!n?.force&&d&&i-l<dp)return!0;const c=Mr.get(r);if(!n?.force&&c)return c;const h=(async()=>{s({isLoading:!0});try{const m=a?`?directory=${encodeURIComponent(a)}`:"",p=await ct(`/api/config/mcp${m}`,{headers:a?{"x-opencode-directory":a}:void 0});if(!p.ok)throw new Error("Failed to load MCP configs");const u=await p.json();return s({mcpServers:u,isLoading:!1}),hi.set(r,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),s({isLoading:!1}),!1}})();Mr.set(r,h);try{return await h}finally{Mr.delete(r)}},createMcp:async n=>{Wa("Creating MCP server configuration…");let a=!1;try{const r=bo(n),i=Da(),l=i?`?directory=${encodeURIComponent(i)}`:"",d=await ct(`/api/config/mcp/${encodeURIComponent(n.name)}${l}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(r)}),c=await d.json().catch(()=>null);if(!d.ok)throw new Error(c?.error||"Failed to create MCP server");return Tr(i),c?.requiresReload?(a=!0,await Ga({message:c.message,delayMs:c.reloadDelayMs??Er,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning})}catch(r){return console.error("[McpConfigStore] Failed to create MCP:",r),{ok:!1}}finally{a||qa()}},updateMcp:async(n,a)=>{Wa("Updating MCP server configuration…");let r=!1;try{const i=bo(a),l=Da(),d=l?`?directory=${encodeURIComponent(l)}`:"",c=await ct(`/api/config/mcp/${encodeURIComponent(n)}${d}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},body:JSON.stringify(i)}),h=await c.json().catch(()=>null);if(!c.ok)throw new Error(h?.error||"Failed to update MCP server");return Tr(l),h?.requiresReload?(r=!0,await Ga({message:h.message,delayMs:h.reloadDelayMs??Er,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:h?.reloadFailed===!0,message:h?.message,warning:h?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:h?.reloadFailed===!0,message:h?.message,warning:h?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||qa()}},deleteMcp:async n=>{Wa("Deleting MCP server configuration…");let a=!1;try{const r=Da(),i=r?`?directory=${encodeURIComponent(r)}`:"",l=await ct(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:r?{"x-opencode-directory":r}:void 0}),d=await l.json().catch(()=>null);if(!l.ok)throw new Error(d?.error||"Failed to delete MCP server");return Tr(r),d?.requiresReload&&(a=!0,await Ga({message:d.message,delayMs:d.reloadDelayMs??Er,scopes:["all"]})),e().selectedMcpName===n&&s({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}}catch(r){return console.error("[McpConfigStore] Failed to delete MCP:",r),{ok:!1}}finally{a||qa()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:Ei(),partialize:s=>({selectedMcpName:s.selectedMcpName})}),{name:"mcp-config-store"}));function bo(s){const e={};if(s.scope!==void 0&&(e.scope=s.scope),s.type!==void 0&&(e.type=s.type),(s.type==="local"||s.command!==void 0)&&(e.command=(s.command??[]).filter(n=>n.trim())),(s.type==="remote"||s.url!==void 0)&&(e.url=s.url?.trim()??""),s.environment!==void 0&&(e.environment=yo(s.environment)??{}),s.headers!==void 0&&(e.headers=yo(s.headers)??{}),s.oauthEnabled!==void 0||s.oauthClientId!==void 0||s.oauthClientSecret!==void 0||s.oauthScope!==void 0||s.oauthRedirectUri!==void 0)if(s.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:Ea(s.oauthClientId),clientSecret:Ea(s.oauthClientSecret),scope:Ea(s.oauthScope),redirectUri:Ea(s.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:s.oauthEnabled?e.oauth={}:e.oauth=!1}if(s.timeout!==void 0){const n=Number(s.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return s.enabled!==void 0&&(e.enabled=s.enabled),e}const mp={},pp={},qs=s=>{if(typeof s!="string")return null;const e=s.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},Bn=s=>qs(s)??"__global__",In=s=>{const e=qs(s);return e?ys.getScopedApiClient(e):ys.getApiClient()},rs=wn()(Na((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=Bn(n??ws.getState().currentDirectory);return e().byDirectory[a]??mp},getDiagnosticForDirectory:n=>{const a=Bn(n??ws.getState().currentDirectory);return e().diagnosticsByDirectory[a]??pp},getErrorForDirectory:n=>{const a=Bn(n??ws.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=qs(n?.directory??ws.getState().currentDirectory),r=Bn(a);n?.silent||s(i=>({loadingKeys:{...i.loadingKeys,[r]:!0},lastErrorKeys:{...i.lastErrorKeys,[r]:null}}));try{const d=(await In(a).mcp.status()).data??{};s(c=>({byDirectory:{...c.byDirectory,[r]:d},diagnosticsByDirectory:{...c.diagnosticsByDirectory,[r]:Object.fromEntries(Object.entries(c.diagnosticsByDirectory[r]??{}).filter(([h])=>!d[h]))},loadingKeys:{...c.loadingKeys,[r]:!1},lastErrorKeys:{...c.lastErrorKeys,[r]:null}}))}catch(i){const l=i instanceof Error?i.message:"Failed to load MCP status";s(d=>({loadingKeys:{...d.loadingKeys,[r]:!1},lastErrorKeys:{...d.lastErrorKeys,[r]:l}}))}},connect:async(n,a)=>{const r=qs(a??ws.getState().currentDirectory),i=Bn(r),l=In(r);try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(d){const c=d instanceof Error?d.message:"Connection failed";throw s(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:c}}}})),d}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=qs(a??ws.getState().currentDirectory);await In(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=qs(a??ws.getState().currentDirectory),d=(await In(r).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!d)throw new Error("Authorization URL was not returned");return d},completeAuth:async(n,a,r)=>{const i=qs(r??ws.getState().currentDirectory);await In(i).mcp.auth.callback({name:n,code:a},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,a)=>{const r=qs(a??ws.getState().currentDirectory);await In(r).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},testConnection:async(n,a)=>{const r=qs(a??ws.getState().currentDirectory),i=Bn(r),l=In(r),c=e().getStatusForDirectory(r)[n]?.status==="connected";let h,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(w){h=w instanceof Error?w.message:"Connection failed",s(g=>({diagnosticsByDirectory:{...g.diagnosticsByDirectory,[i]:{...g.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:h??"Connection failed"}}}}))}await e().refresh({directory:r,silent:!0});const p=e().getStatusForDirectory(r)[n],u=p;if(!c&&p?.status==="connected"){try{await l.mcp.disconnect({name:n},{throwOnError:!0})}catch(w){m=`Connection test succeeded, but cleanup disconnect failed: ${w instanceof Error?w.message:"Disconnect failed"}`}await e().refresh({directory:r,silent:!0})}return{status:u??e().getStatusForDirectory(r)[n],error:h,warning:m}}}))),gp=(s,e)=>{if(!s)return e("mcpDropdown.status.unknown");switch(s.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:s.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:s.error||""});default:return s.status}},hp=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},_j=({active:s,className:e,headerAction:n,listClassName:a,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:l}=st(),c=ws(N=>N.currentDirectory)??null,h=rs(N=>N.getStatusForDirectory(c)),m=rs(N=>N.refresh),p=rs(N=>N.connect),u=rs(N=>N.disconnect),w=Zn(N=>N.mcpServers),g=Zn(N=>N.loadMcpConfigs),[f,x]=o.useState(!1),[D,P]=o.useState(null);o.useEffect(()=>{m({directory:c,silent:!0})},[m,c]),o.useEffect(()=>{g({force:!0})},[g]),o.useEffect(()=>{s&&Promise.all([m({directory:c,silent:!0}),g({force:!0})])},[s,m,c,g]);const I=o.useMemo(()=>{const N=new Set(Object.keys(h));for(const b of w)b?.name&&N.add(b.name);return Array.from(N).sort((b,j)=>b.localeCompare(j))},[w,h]),L=o.useCallback(N=>{if(N?.preventDefault(),f)return;x(!0);const b=new Promise(j=>setTimeout(j,500));Promise.all([m({directory:c}),b]).finally(()=>{x(!1)})},[f,m,c]);return t.jsxs("div",{className:ce("w-full",e),children:[r?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:t.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:l("mcpDropdown.title")}),c&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:c.split("/").pop()||c})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:f,onClick:L,"aria-label":l("mcpDropdown.actions.refreshAria"),children:t.jsx(E,{name:"refresh",className:ce("h-4 w-4",f&&"animate-spin")})})]})]})}),t.jsx("div",{className:ce("max-h-64 overflow-y-auto",i?"space-y-1 py-3":"px-3 py-2.5",a),children:t.jsxs("div",{className:ce(!i&&I.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[I.map(N=>{const b=h[N],j=hp(b),T=b?.status==="connected",U=D===N,K=gp(b,l);return t.jsxs("div",{className:ce("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",i?"gap-3 px-4 py-3":"gap-2 px-2.5 py-2"),children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx("span",{className:ce("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",j==="success"&&"bg-status-success",j==="error"&&"bg-status-error",j==="warning"&&"bg-status-warning",j==="default"&&"bg-muted-foreground/40"),"aria-label":K})}),t.jsx(It,{side:"left",children:t.jsx("p",{children:K})})]}),t.jsx("span",{className:ce("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:N})]})}),t.jsx(ar,{checked:T,disabled:U,className:"data-[checked]:bg-status-info",onCheckedChange:async M=>{P(N);try{M?await p(N,c):await u(N,c)}finally{P(null)}}})]},N)}),I.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:l("mcpDropdown.empty.configureInConfig")})]})})]})};function fp(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=su();return s}catch{return"unknown"}}function xp(){const s=typeof window<"u"?window.__VSCODE_CONFIG__?.arch?.toLowerCase?.():void 0;if(s==="arm64"||s==="aarch64")return"arm64";if(s==="x64"||s==="amd64"||s==="x86_64")return"x64";const n=(typeof navigator<"u"?navigator.userAgentData:void 0)?.architecture?.toLowerCase?.();if(n==="arm"||n==="arm64"||n==="aarch64")return"arm64";if(n==="x86"||n==="x64"||n==="amd64")return"x64";const a=typeof navigator<"u"?navigator.userAgent.toLowerCase():"";return a.includes("aarch64")||a.includes("arm64")||a.includes("armv")?"arm64":a.includes("x86_64")||a.includes("x64")||a.includes("amd64")||a.includes("win64")?"x64":"unknown"}function yp(){const s=nc();if(s==="android"||s==="ios")return s;if(typeof navigator>"u")return"web";const e=(navigator.platform||"").toLowerCase();return e.includes("mac")?"macos":e.includes("win")?"windows":e.includes("linux")?"linux":"web"}function bp(s){const e=Ie.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",fp()),n.set("arch",xp()),n.set("platform",yp()),s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",ta()?"local":"remote"),n):s==="vscode"?(n.set("appType","vscode"),n.set("instanceMode","local"),n):s==="mobile"?(n.set("appType","mobile-capacitor"),n.set("instanceMode","remote"),n):(n.set("appType","web"),n.set("instanceMode","unknown"),n)}async function Rr(s,e){try{const n=bp(s),a=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e?n.set("currentVersion",e):s==="vscode"&&a&&n.set("currentVersion",a);const r=await ct(`/api/openchamber/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!r.ok)throw new Error(`Server responded with ${r.status}`);const i=await r.json();return{available:i.available??!1,version:i.version,currentVersion:i.currentVersion??"unknown",body:i.body,releaseUrl:i.releaseUrl,downloadUrl:i.downloadUrl,nextSuggestedCheckInSec:typeof i.nextSuggestedCheckInSec=="number"&&Number.isFinite(i.nextSuggestedCheckInSec)?i.nextSuggestedCheckInSec:void 0,packageManager:i.packageManager,updateCommand:i.updateCommand}}catch(n){return console.warn("Failed to check for updates:",n),null}}function vp(){return tu()?"mobile":Rm()?"desktop":ms()?"vscode":Dn()?"web":null}const vo={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},vc=wn()((s,e)=>({...vo,checkForUpdates:async()=>{const n=vp();if(!n)return null;s({checking:!0,error:null,runtimeType:n});try{let a=null,r=null;if(n==="desktop"){const i=await so();return s({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null}),r}else n==="web"?(a=await Rr("web"),r=a?.nextSuggestedCheckInSec??null):n==="vscode"?r=(await Rr("vscode"))?.nextSuggestedCheckInSec??null:n==="mobile"&&(a=await Rr("mobile","1.16.0"),r=a?.nextSuggestedCheckInSec??null);return s({checking:!1,available:n==="vscode"?!1:a?.available??!1,info:n==="vscode"?null:a,lastChecked:Date.now(),nextCheckInSec:r}),r}catch(a){return s({checking:!1,error:a instanceof Error?a.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:a}=e();if(!(a!=="desktop"||!n)){s({downloading:!0,error:null,progress:null});try{const r=await so();if(!r?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(s(l=>({info:l.info?{...l.info,...r,body:l.info.body||r.body,available:l.info.available}:r})),!await Tm(l=>{s({progress:l})}))throw new Error("Desktop update only works on Local instance");s({downloading:!1,downloaded:!0})}catch(r){s({downloading:!1,error:r instanceof Error?r.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:a}=e();if(!(a!=="desktop"||!n))try{if(!await Mm())throw new Error("Desktop restart only works on Local instance")}catch(r){s({error:r instanceof Error?r.message:"Failed to restart"})}},dismiss:()=>{s({available:!1,downloaded:!1,info:null})},reset:()=>{s(vo)}})),jo="https://github.com/openchamber/openchamber/releases";function jp(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(Ai(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function wp(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function wo(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function Np(s,e){const n=s.split(".").map(r=>Number.parseInt(r,10)),a=e.split(".").map(r=>Number.parseInt(r,10));for(let r=0;r<3;r+=1){const i=Number.isFinite(n[r])?n[r]:0,l=Number.isFinite(a[r])?a[r]:0;if(i!==l)return l-i}return 0}function kp(s){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let a;for(;(a=e.exec(s))!==null;)n.push({version:a[1]??"",date:a[2]??"",start:a.index});return n.length===0?[]:n.map((r,i)=>{const l=n[i+1]?.start??s.length,d=s.slice(r.start,l).trim();return{version:r.version,date:r.date,start:r.start,end:l,raw:d}})}const No=2e3,Sp=600*1e3;async function Cp(){try{const s=await ct("/api/openchamber/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});return s.ok?{success:!0,autoRestart:(await s.json().catch(()=>({}))).autoRestart!==!1}:{success:!1,error:(await s.json().catch(()=>({}))).error||`Server error: ${s.status}`}}catch(s){return{success:!1,error:s instanceof Error?s.message:void 0}}}async function Ip(){try{return(await ct("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function Pp(s,e=Math.ceil(Sp/No),n=No){for(let a=0;a<e;a++){try{const r=await ct("/api/openchamber/update-check",{method:"GET",headers:{Accept:"application/json"}});if(r.ok){const i=await r.json().catch(()=>null);if(i&&i.available===!1||i&&typeof i.currentVersion=="string"&&typeof s=="string"&&i.currentVersion!==s)return!0}else if((r.status===401||r.status===403)&&await Ip())return!0}catch{}await new Promise(r=>setTimeout(r,n))}return!1}const ko=({open:s,onOpenChange:e,info:n,downloading:a,downloaded:r,progress:i,error:l,onDownload:d,onRestart:c,runtimeType:h="desktop"})=>{const{t:m}=st(),[p,u]=xe.useState(!1),[w,g]=xe.useState("idle"),[f,x]=xe.useState(null),D=n?.version?n.releaseUrl||`${jo}/tag/v${n.version}`:jo,P=n?.downloadUrl||D,I=i?.total?Math.round(i.downloaded/i.total*100):0,L=h==="web",N=h==="mobile",b=n?.updateCommand||"openchamber update";xe.useEffect(()=>{s||(g("idle"),x(null))},[s]);const j=async()=>{(await En(b)).ok&&(u(!0),setTimeout(()=>u(!1),2e3))},T=xe.useCallback(async A=>{await tn(A)},[]),U=xe.useCallback(async()=>{g("updating"),x(null);const A=await Cp();if(!A.success){g("error"),x(A.error||m("updateDialog.error.updateFailed"));return}A.autoRestart&&(g("restarting"),await new Promise(R=>setTimeout(R,2e3))),g("reconnecting"),await Pp(n?.currentVersion)?window.location.reload():(g("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),K=xe.useCallback(()=>{T(P)},[T,P]),M=w!=="idle"&&w!=="error",C=xe.useMemo(()=>{if(!n?.body)return null;const A=n.body.trim();if(!A)return null;const z=kp(A);if(z.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:wo(A)};const R=[...z].sort((Q,W)=>Np(Q.version,W.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:R.map(Q=>({version:Q.version,dateLabel:jp(Q.date),content:wo(wp(Q.raw)||A)}))}},[n?.body,m]);return t.jsx(Rt,{open:s,onOpenChange:M?void 0:e,children:t.jsxs(Ft,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[t.jsxs("div",{className:"flex items-center mb-1",children:[t.jsxs(zt,{className:"flex items-center gap-2.5",children:[t.jsx(E,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),t.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(w==="restarting"||w==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&t.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&t.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&t.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&t.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),t.jsxs("div",{className:"space-y-2",children:[L&&M&&t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(E,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),t.jsxs("div",{className:"typography-ui-label text-foreground",children:[w==="updating"&&m("updateDialog.status.installingUpdate"),w==="restarting"&&m("updateDialog.status.serverRestarting"),w==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),C&&!M&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(_t,{className:"max-h-[400px] p-0",fillContainer:!1,children:C.kind==="raw"?t.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:A=>{const R=A.target.closest("a");R&&R.href&&(A.preventDefault(),A.stopPropagation(),T(R.href))},children:t.jsx(ii,{content:C.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:C.sections.map(A=>t.jsxs("div",{className:"p-4",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",A.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:A.dateLabel})]}),t.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:z=>{const Q=z.target.closest("a");Q&&Q.href&&(z.preventDefault(),z.stopPropagation(),T(Q.href))},children:t.jsx(ii,{content:A.content,disableLinkSafety:!0,enableFileReferences:!1})})]},A.version))})})}),L&&w==="error"&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx(E,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:m("updateDialog.fallback.updateViaTerminal")})]}),t.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[t.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:b}),t.jsx("button",{onClick:j,className:ce("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",p&&"text-[var(--status-success)]"),title:m(p?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:p?t.jsx(E,{name:"check",className:"h-4 w-4"}):t.jsx(E,{name:"clipboard",className:"h-4 w-4"})})]})]}),!L&&!N&&a&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),t.jsxs("span",{className:"font-mono text-foreground",children:[I,"%"]})]}),t.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${I}%`}})})]}),(l||f)&&t.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:t.jsx("p",{className:"text-sm text-[var(--status-error)]",children:l||f})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:D,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[t.jsx(E,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!L&&!N&&!r&&!a&&t.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(E,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!L&&!N&&a&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(E,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!L&&!N&&r&&t.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[t.jsx(E,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),N&&t.jsxs(q,{onClick:K,size:"default",children:[t.jsx(E,{name:"external-link",className:"h-4 w-4"}),m("updateDialog.actions.openMobileUpdate")]}),L&&!M&&t.jsxs("button",{onClick:U,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(E,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),L&&M&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(E,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},So="https://github.com/openchamber/openchamber",Ap="https://discord.gg/ZYRSdnwwKA",Co="https://x.com/openchamber_dev",Dp=800,jc=({initialUpdateDialogOpen:s=!1})=>{const{t:e}=st(),[n,a]=o.useState(s),[r,i]=o.useState(!1),[l,d]=o.useState(null),[c,h]=o.useState(null),m=vc(Ps(f=>({info:f.info,checking:f.checking,available:f.available,error:f.error,downloading:f.downloading,downloaded:f.downloaded,progress:f.progress,runtimeType:f.runtimeType,checkForUpdates:f.checkForUpdates,downloadUpdate:f.downloadUpdate,restartToUpdate:f.restartToUpdate}))),{isMobile:p}=Ds(),u=l||m.info?.currentVersion||"unknown";o.useEffect(()=>{let f=!1;return(async()=>{try{const D=await ct("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const P=await D.json().catch(()=>null),I=typeof P?.openchamberVersion=="string"&&P.openchamberVersion.trim().length>0?P.openchamberVersion.trim():null;f||d(I)}catch{f||d(null)}})(),()=>{f=!0}},[]),o.useEffect(()=>{let f=!1;return(async()=>{try{const D=await ct("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const P=await D.json().catch(()=>null),I=typeof P?.currentVersion=="string"&&P.currentVersion.trim().length>0?P.currentVersion.trim():null;f||h(I)}catch{f||h(null)}})(),()=>{f=!0}},[]);const w=o.useRef(!1);o.useEffect(()=>{if(m.checking)i(!0),w.current=!0;else if(r){const f=setTimeout(()=>{i(!1),w.current&&!m.available&&!m.error&&(_.success(e("settings.openchamber.about.toast.latestVersion")),w.current=!1)},Dp);return()=>clearTimeout(f)}},[e,m.checking,r,m.available,m.error]);const g=m.checking||r;return p?t.jsxs("div",{className:"w-full space-y-6 pb-2",children:[t.jsxs("div",{className:"flex flex-col items-center text-center",children:[t.jsx(ac,{width:72,height:72}),t.jsx("h2",{className:"mt-4 typography-ui-header font-semibold text-foreground",children:"OpenChamber"}),t.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[t.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:u})}),t.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]})]}),t.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&t.jsxs(q,{type:"button",variant:"outline",size:"sm",onClick:()=>m.checkForUpdates(),disabled:g,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[g?t.jsx(E,{name:"loader",className:"size-4 animate-spin"}):t.jsx(E,{name:"refresh",className:"size-4"}),e(g?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!g&&m.available&&t.jsxs(q,{type:"button",variant:"default",size:"sm",onClick:()=>a(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[t.jsx(E,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]})]}),m.error&&t.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:m.error}),t.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[t.jsxs("div",{className:"flex items-center justify-center gap-5",children:[t.jsxs("a",{href:So,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(E,{name:"github-fill",className:"size-5"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:Ap,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(E,{name:"discord-fill",className:"size-5"}),t.jsx("span",{children:"Discord"})]})]}),t.jsxs("a",{href:Co,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(E,{name:"twitter-xfill",className:"size-5"}),t.jsx("span",{children:"@openchamber_dev"})]})]}),t.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),t.jsx(ko,{open:n,onOpenChange:a,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]}):t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-3 px-1",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:e("settings.openchamber.about.title")})}),t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.version")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:u})]}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.openCodeVersion")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(E,{name:"loader",className:"h-4 w-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!m.checking&&m.available&&t.jsxs(q,{size:"sm",variant:"default",onClick:()=>a(!0),children:[t.jsx(E,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]}),!m.checking&&!m.available&&!m.error&&t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t.jsx(q,{size:"sm",variant:"outline",onClick:()=>m.checkForUpdates(),disabled:m.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),m.error&&t.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m.error})}),t.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[t.jsxs("a",{href:So,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[t.jsx(E,{name:"github-fill",className:"h-4 w-4"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:Co,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[t.jsx(E,{name:"twitter-xfill",className:"h-4 w-4"}),t.jsx("span",{children:"@openchamber_dev"})]})]})]}),t.jsx(ko,{open:n,onOpenChange:a,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]})},Hj=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),Ep=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),Mp=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},Tp=s=>!s||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),da="opencode-update-available",Ma="opencode-upgrade-progress",Rp=5e3,Fp=[1e4,6e4],Io="opencode-update-toast-dismissed-version",Wj=()=>{const{t:s}=st(),e=Ie(l=>l.showOpenCodeUpdateNotifications),n=xe.useRef(new Set),a=xe.useRef(!1);xe.useEffect(()=>{e||_.dismiss(da)},[e]);const r=xe.useCallback(()=>{_.dismiss(Ma),Jn({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),i=xe.useCallback(async()=>{if(!a.current){a.current=!0,_.dismiss(da),_.message(s("opencodeUpdate.toast.upgrading.title"),{id:Ma,description:s("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:t.jsx(E,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const l=await ct("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),d=await l.json().catch(()=>null);if(!l.ok||d?.success===!1)throw new Error(d?.error||l.statusText||s("opencodeUpdate.toast.failed.description"));_.success(s("opencodeUpdate.toast.updated.title"),{id:Ma,description:d?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:d.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(E,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(l){_.error(s("opencodeUpdate.toast.failed.title"),{id:Ma,description:l instanceof Error?l.message:s("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{a.current=!1}}},[r,s]);return xe.useEffect(()=>{const l=p=>{if(!Ie.getState().showOpenCodeUpdateNotifications){_.dismiss(da);return}Ep({version:p,dismissedVersion:no().getItem(Io),seenVersions:n.current})&&(n.current.add(p),_.info(s("opencodeUpdate.toast.available.title"),{id:da,description:s("opencodeUpdate.toast.available.description",{version:p}),duration:1/0,action:{label:s("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:s("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{no().setItem(Io,p),Nt({openCodeUpdateToastDismissedVersion:p}),_.dismiss(da)}}}))},d=p=>{const u=Mp(p.detail);l(u)};let c=!1;const h=[],m=async p=>{try{const u=await ct("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!u.ok)throw new Error(u.statusText||"OpenCode upgrade status check failed");const w=await u.json().catch(()=>null),g=Tp(w);!c&&g&&l(g)}catch{const u=Fp[p];!c&&u!==void 0&&h.push(setTimeout(()=>{m(p+1)},u))}};return e&&h.push(setTimeout(()=>{m(0)},Rp)),window.addEventListener("openchamber:opencode-update-available",d),()=>{c=!0;for(const p of h)clearTimeout(p);window.removeEventListener("openchamber:opencode-update-available",d)}},[i,e,s]),null},Gj=()=>{const s=et.c(3),[e,n]=o.useState(Lp),{isUpdating:a}=e;let r,i;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>au(n),i=[],s[0]=r,s[1]=i):(r=s[0],i=s[1]),o.useEffect(r,i),!a)return null;let l;return s[2]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:t.jsx(ac,{width:80,height:80,isAnimated:!0})}),s[2]=l):l=s[2],l};function Lp(){return nu()}class Op extends o.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(ru,{className:"w-full max-w-md",children:[t.jsx(iu,{className:"text-center",children:t.jsxs(ou,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(E,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(lu,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(q,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(E,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function zp(s){const e=et.c(22),{t:n}=st();let a;e[0]!==n?(a=n("chat.errorBoundary.title"),e[0]=n,e[1]=a):a=e[1];let r;e[2]!==n?(r=n("chat.errorBoundary.description"),e[2]=n,e[3]=r):r=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let l;e[6]!==n?(l=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=l):l=e[7];let d;e[8]!==n?(d=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=d):d=e[9];let c;e[10]!==n?(c=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=c):c=e[11];let h;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==l||e[16]!==d||e[17]!==c?(h={title:a,description:r,sessionLabel:i,detailsSummary:l,resetAction:d,persistentHint:c},e[12]=a,e[13]=r,e[14]=i,e[15]=l,e[16]=d,e[17]=c,e[18]=h):h=e[18];let m;return e[19]!==s||e[20]!==h?(m=t.jsx(Op,{...s,texts:h}),e[19]=s,e[20]=h,e[21]=m):m=e[21],m}const qj=s=>{const e=et.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=fs(Kp)||void 0;let l;e[0]!==a?(l=t.jsx(cu,{readOnly:a}),e[0]=a,e[1]=l):l=e[1];let d;return e[2]!==i||e[3]!==l?(d=t.jsx(zp,{sessionId:i,children:l}),e[2]=i,e[3]=l,e[4]=d):d=e[4],d};function Kp(s){return s.currentSessionId}function xn(s){const e=et.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let a;return e[2]!==n?(a=t.jsx(dd,{...n}),e[2]=n,e[3]=a):a=e[3],a}function yn(s){const e=et.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let a;return e[2]!==n?(a=t.jsx(ud,{...n}),e[2]=n,e[3]=a):a=e[3],a}function bn(s){const e=et.c(20);let n,a,r,i,l;e[0]!==s?({className:a,positionerClassName:r,children:n,style:l,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i,e[5]=l):(n=e[1],a=e[2],r=e[3],i=e[4],l=e[5]);let d;e[6]!==r?(d=ce("app-region-no-drag z-50",r),e[6]=r,e[7]=d):d=e[7];let c;e[8]!==l?(c={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",...l},e[8]=l,e[9]=c):c=e[9];let h;e[10]!==a?(h=ce(du,a),e[10]=a,e[11]=h):h=e[11];let m;e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==h?(m=t.jsx(md,{"data-slot":"dropdown-menu-content",style:c,className:h,...i,children:n}),e[12]=n,e[13]=i,e[14]=c,e[15]=h,e[16]=m):m=e[16];let p;return e[17]!==d||e[18]!==m?(p=t.jsx(gd,{children:t.jsx(hd,{className:d,children:m})}),e[17]=d,e[18]=m,e[19]=p):p=e[19],p}function sn(s){const e=et.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=ce(uu,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(pd,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}function Jj(s){const e=et.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=ce(mu,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(fd,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}const wc=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),ka=s=>{const e=et.c(39),{className:n}=s,{t:a}=st(),r=es(Up),i=es(Bp),l=es($p),d=ms();let c;e[0]!==r?(c=[...r].sort(Vp),e[0]=r,e[1]=c):c=e[1];const h=c;let m;e:{if(h.length===0){m=null;break e}let z;e[2]!==i||e[3]!==h?(z=h.find(R=>R.id===i)??h[0],e[2]=i,e[3]=h,e[4]=z):z=e[4],m=z}const p=m;if(d||h.length===0)return null;let u;e[5]!==p||e[6]!==a?(u=p?.label&&p.label.trim().length>0?p.label:p?.path.split("/").filter(Boolean).pop()||p?.path||a("settings.shared.projectSelector.fallbackProject"),e[5]=p,e[6]=a,e[7]=u):u=e[7];const w=u;let g;e[8]!==w?(g=wc(w),e[8]=w,e[9]=g):g=e[9];const f=g;let x;e[10]!==n?(x=ce(n),e[10]=n,e[11]=x):x=e[11];let D;e[12]!==a?(D=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=D):D=e[13];let P;e[14]!==a?(P=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=P):P=e[15];let I,L;e[16]===Symbol.for("react.memo_cache_sentinel")?(I=ce("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),L=t.jsx(E,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=I,e[17]=L):(I=e[16],L=e[17]);let N;e[18]!==f?(N=t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:f}),e[18]=f,e[19]=N):N=e[19];let b;e[20]===Symbol.for("react.memo_cache_sentinel")?(b=t.jsx(E,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=b):b=e[20];let j;e[21]!==N||e[22]!==D||e[23]!==P?(j=t.jsx(ls,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":D,title:P,className:I,children:[L,N,b]})}),e[21]=N,e[22]=D,e[23]=P,e[24]=j):j=e[24];const T=p?.id??"";let U;e[25]!==l?(U=z=>{z&&l(z)},e[25]=l,e[26]=U):U=e[26];let K;e[27]!==h?(K=h.map(_p),e[27]=h,e[28]=K):K=e[28];let M;e[29]!==T||e[30]!==U||e[31]!==K?(M=t.jsx(cs,{align:"start",className:"w-auto",children:t.jsx(gu,{value:T,onValueChange:U,children:K})}),e[29]=T,e[30]=U,e[31]=K,e[32]=M):M=e[32];let C;e[33]!==j||e[34]!==M?(C=t.jsxs(ds,{children:[j,M]}),e[33]=j,e[34]=M,e[35]=C):C=e[35];let A;return e[36]!==C||e[37]!==x?(A=t.jsx("div",{className:x,children:C}),e[36]=C,e[37]=x,e[38]=A):A=e[38],A};function Up(s){return s.projects}function Bp(s){return s.activeProjectId}function $p(s){return s.setActiveProject}function Vp(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function _p(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=wc(e);return t.jsx(pu,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function Hp(s,e){return`opencode:sidebar-group:${s}:${e}`}const fi=s=>{const e=et.c(33),{label:n,count:a,storageKey:r,defaultExpanded:i,children:l}=s,d=i===void 0?!0:i;let c;e[0]!==n||e[1]!==r?(c=Hp(r,n),e[0]=n,e[1]=r,e[2]=c):c=e[2];const h=c,m=o.useId();let p;e[3]!==d||e[4]!==h?(p=()=>{try{const M=localStorage.getItem(h);if(M!==null)return M==="true"}catch{}return d},e[3]=d,e[4]=h,e[5]=p):p=e[5];const[u,w]=xe.useState(p);let g,f;e[6]!==u||e[7]!==h?(g=()=>{try{localStorage.setItem(h,String(u))}catch{}},f=[h,u],e[6]=u,e[7]=h,e[8]=g,e[9]=f):(g=e[8],f=e[9]),xe.useEffect(g,f);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>w(Wp),e[10]=x):x=e[10];let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=ce("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=D):D=e[11];const P=!u&&"-rotate-90";let I;e[12]!==P?(I=ce("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",P),e[12]=P,e[13]=I):I=e[13];let L;e[14]!==I?(L=t.jsx(E,{name:"arrow-down-s",className:I}),e[14]=I,e[15]=L):L=e[15];let N;e[16]!==n?(N=t.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=N):N=e[17];let b;e[18]!==a?(b=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=b):b=e[19];let j;e[20]!==m||e[21]!==u||e[22]!==L||e[23]!==N||e[24]!==b?(j=t.jsxs("button",{type:"button",onClick:x,"aria-expanded":u,"aria-controls":m,className:D,children:[L,N,b]}),e[20]=m,e[21]=u,e[22]=L,e[23]=N,e[24]=b,e[25]=j):j=e[25];const T=!u;let U;e[26]!==l||e[27]!==m||e[28]!==T?(U=t.jsx("div",{id:m,hidden:T,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=m,e[28]=T,e[29]=U):U=e[29];let K;return e[30]!==j||e[31]!==U?(K=t.jsxs("div",{children:[j,U]}),e[30]=j,e[31]=U,e[32]=K):K=e[32],K};function Wp(s){return!s}const Gp=s=>{if(!Array.isArray(s))return[];const e=[];for(const n of s){if(!n||typeof n!="object")continue;const a=n;typeof a.permission!="string"||typeof a.pattern!="string"||typeof a.action!="string"||a.action!=="allow"&&a.action!=="ask"&&a.action!=="deny"||e.push({permission:a.permission,pattern:a.pattern,action:a.action})}return e},qp=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},Po=s=>{const e=qp(Gp(s));if(e.length===0)return;const n={};for(const r of e)r.permission&&((n[r.permission]||={})[r.pattern]=r.action);const a={};for(const[r,i]of Object.entries(n)){const l=Object.keys(i);if(l.length===1&&l[0]==="*"){a[r]=i["*"];continue}a[r]=i}return Object.keys(a).length>0?a:void 0},Jp=({onItemSelect:s})=>{const{t:e}=st(),[n,a]=o.useState(null),[r,i]=o.useState(""),[l,d]=o.useState(null),[c,h]=o.useState(null),[m,p]=o.useState(!1),[u,w]=o.useState(null),{selectedAgentName:g,agents:f,setSelectedAgent:x,setAgentDraft:D,createAgent:P,deleteAgent:I,loadAgents:L}=cr(Ps(k=>({selectedAgentName:k.selectedAgentName,agents:k.agents,setSelectedAgent:k.setSelectedAgent,setAgentDraft:k.setAgentDraft,createAgent:k.createAgent,deleteAgent:k.deleteAgent,loadAgents:k.loadAgents})));o.useEffect(()=>{L()},[L]);const N="bg-background",b=()=>{const k="new-agent";let $=k,B=1;for(;f.some(F=>F.name===$);)$=`${k}-${B}`,B++;D({name:$,scope:"user"}),x($),s?.()},j=async k=>{if(Wn(k)){_.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(k),h("delete")},T=async k=>{Wn(k)&&(d(k),h("reset"))},U=()=>{d(null),h(null)},K=async()=>{if(!(!l||!c)){p(!0);try{const k=await I(l.name,l.scope);k.ok?(k.requiresManualRestart?_.warning(e("settings.agents.page.toast.savedManualRestart")):c==="delete"?_.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):_.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),U()):c==="delete"?_.error(e("settings.agents.sidebar.toast.deleteFailed")):_.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(k){const $=k instanceof Error?k.message:"",B=/built-in|not deletable|not found/i.test($);c==="delete"?_.error(e(B?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):_.error(e("settings.agents.sidebar.toast.resetFailed"))}p(!1)}},M=k=>{const $=k.name;let B=1,F=`${$}-copy`;for(;f.some(re=>re.name===F);)B++,F=`${$}-copy-${B}`;const O=k,J=k.model?.providerID&&k.model?.modelID?`${k.model.providerID}/${k.model.modelID}`:null,H=k;D({name:F,scope:O.scope||"user",description:k.description,model:J,variant:k.variant,temperature:k.temperature,top_p:k.topP,prompt:k.prompt,mode:k.mode,permission:Po(k.permission),disable:H.disable}),x(F)},C=k=>{i(k.name),a(k)},A=async()=>{if(!n)return;const k=r.trim().replace(/\s+/g,"-");if(!k){_.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(k===n.name){a(null);return}if(f.some(O=>O.name===k)){_.error(e("settings.agents.sidebar.toast.agentExists"));return}const $=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,B=n,F=await P({name:k,description:n.description,model:$,variant:n.variant,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Po(n.permission),disable:B.disable,scope:B.scope});if(F.ok){const O=await I(n.name,B.scope);O.ok?(F.requiresManualRestart||O.requiresManualRestart?_.warning(e("settings.agents.page.toast.savedManualRestart")):_.success(e("settings.agents.sidebar.toast.agentRenamed",{name:k})),x(k)):_.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else _.error(e("settings.agents.sidebar.toast.renameFailed"));a(null)},z=k=>{switch(k){case"primary":return t.jsx(E,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(E,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(E,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},R=f.filter(k=>!hu(k)),Q=R.filter(Wn),W=R.filter(k=>!Wn(k)),{groupedCustomAgents:te,ungroupedCustomAgents:Y}=xe.useMemo(()=>{const k={},$=[];for(const F of W){const O=F;O.group?(k[O.group]||(k[O.group]=[]),k[O.group].push(F)):$.push(F)}return{groupedCustomAgents:Object.keys(k).sort((F,O)=>F.localeCompare(O)).map(F=>({name:F,agents:k[F]})),ungroupedCustomAgents:$}},[W]);return t.jsxs("div",{className:ce("flex h-full flex-col",N),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),t.jsx(ka,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:R.length})}),t.jsx(q,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:b,children:t.jsx(E,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(_t,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:R.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(E,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[Q.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),Q.map(k=>t.jsx(Fr,{agent:k,isSelected:g===k.name,onSelect:()=>{x(k.name),s?.()},onReset:()=>T(k),onDuplicate:()=>M(k),getAgentModeIcon:z,isMenuOpen:u===k.name,onMenuOpenChange:$=>w($?k.name:null)},k.name))]}),W.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),te.map(({name:k,agents:$})=>t.jsx(fi,{label:k,count:$.length,storageKey:"agents",children:$.map(B=>t.jsx(Fr,{agent:B,isSelected:g===B.name,onSelect:()=>{x(B.name),s?.()},onRename:()=>C(B),onDelete:()=>j(B),onDuplicate:()=>M(B),getAgentModeIcon:z,isMenuOpen:u===B.name,onMenuOpenChange:F=>w(F?B.name:null)},B.name))},k)),Y.map(k=>t.jsx(Fr,{agent:k,isSelected:g===k.name,onSelect:()=>{x(k.name),s?.()},onRename:()=>C(k),onDelete:()=>j(k),onDuplicate:()=>M(k),getAgentModeIcon:z,isMenuOpen:u===k.name,onMenuOpenChange:$=>w($?k.name:null)},k.name))]})]})}),t.jsx(Rt,{open:l!==null&&c!==null,onOpenChange:k=>{!k&&!m&&U()},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx($t,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),t.jsxs(Gt,{children:[t.jsx(q,{size:"sm",variant:"ghost",onClick:U,disabled:m,children:e("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",onClick:K,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx(Rt,{open:n!==null,onOpenChange:k=>!k&&a(null),children:t.jsxs(Ft,{children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx($t,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(Xe,{value:r,onChange:k=>i(k.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&A()}}),t.jsxs(Gt,{children:[t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",onClick:A,children:e("settings.common.actions.rename")})]})]})})]})},Fr=s=>{const e=et.c(52),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,getAgentModeIcon:h,isMenuOpen:m,onMenuOpenChange:p}=s,{t:u}=st(),w=n;let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=va(),e[0]=g):g=e[0];const f=g,[x,D]=o.useState(!1);let P;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==u?(P=B=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(B,{onClick:F=>{F.stopPropagation(),d()},children:[t.jsx(E,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),t.jsxs(B,{onClick:F=>{F.stopPropagation(),c()},children:[t.jsx(E,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),l&&t.jsxs(B,{onClick:F=>{F.stopPropagation(),l()},children:[t.jsx(E,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),i&&t.jsxs(B,{onClick:F=>{F.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(E,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=l,e[5]=u,e[6]=P):P=e[6];const I=P,L=a?"bg-interactive-selection":"hover:bg-interactive-hover";let N;e[7]!==L?(N=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",L),e[7]=L,e[8]=N):N=e[8];let b;e[9]===Symbol.for("react.memo_cache_sentinel")?(b=f?void 0:B=>{B.preventDefault(),D(!0)},e[9]=b):b=e[9];let j;e[10]!==N?(j=t.jsx("div",{className:N,onContextMenu:b}),e[10]=N,e[11]=j):j=e[11];let T;e[12]!==n.name?(T=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[12]=n.name,e[13]=T):T=e[13];let U;e[14]!==n.mode||e[15]!==h?(U=h(n.mode),e[14]=n.mode,e[15]=h,e[16]=U):U=e[16];let K;e[17]!==n||e[18]!==w.scope||e[19]!==u?(K=(w.scope||Wn(n))&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Wn(n)?u("settings.agents.sidebar.badge.system"):w.scope}),e[17]=n,e[18]=w.scope,e[19]=u,e[20]=K):K=e[20];let M;e[21]!==T||e[22]!==U||e[23]!==K?(M=t.jsxs("div",{className:"flex items-center gap-1.5",children:[T,U,K]}),e[21]=T,e[22]=U,e[23]=K,e[24]=M):M=e[24];let C;e[25]!==n.description?(C=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[25]=n.description,e[26]=C):C=e[26];let A;e[27]!==r||e[28]!==M||e[29]!==C?(A=t.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[M,C]}),e[27]=r,e[28]=M,e[29]=C,e[30]=A):A=e[30];let z;e[31]!==p?(z=B=>{B&&D(!1),p(B)},e[31]=p,e[32]=z):z=e[32];let R;e[33]===Symbol.for("react.memo_cache_sentinel")?(R=t.jsx(ls,{asChild:!0,children:t.jsx(q,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(E,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=R):R=e[33];let Q;e[34]!==I?(Q=t.jsx(cs,{align:"end",className:"w-fit min-w-20",children:I(Ns)}),e[34]=I,e[35]=Q):Q=e[35];let W;e[36]!==m||e[37]!==z||e[38]!==Q?(W=t.jsxs(ds,{open:m,onOpenChange:z,children:[R,Q]}),e[36]=m,e[37]=z,e[38]=Q,e[39]=W):W=e[39];let te;e[40]!==A||e[41]!==W?(te=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,W]}),e[40]=A,e[41]=W,e[42]=te):te=e[42];let Y;e[43]!==te||e[44]!==j?(Y=t.jsx(yn,{render:j,children:te}),e[43]=te,e[44]=j,e[45]=Y):Y=e[45];let k;e[46]!==I?(k=t.jsx(bn,{className:"w-fit min-w-20",children:I(sn)}),e[46]=I,e[47]=k):k=e[47];let $;return e[48]!==x||e[49]!==Y||e[50]!==k?($=t.jsxs(xn,{open:x,onOpenChange:D,children:[Y,k]}),e[48]=x,e[49]=Y,e[50]=k,e[51]=$):$=e[51],$},Ao=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Ja=s=>s==="allow"||s==="ask"||s==="deny",An=(s,e)=>`${s}::${e}`,vn=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&Ja(n.action)&&e.set(An(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},Ta=s=>{const e=new Map;for(const n of vn(s))e.set(An(n.permission,n.pattern),n);return e},Do=s=>[...s].sort((e,n)=>{const a=e.permission.localeCompare(n.permission);return a!==0?a:e.pattern.localeCompare(n.pattern)}),Qp=(s,e)=>{const n=Do(vn(s)),a=Do(vn(e));return n.length!==a.length?!1:n.every((r,i)=>{const l=a[i];return r.permission===l.permission&&r.pattern===l.pattern&&r.action===l.action})},Yp=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",Xp=(s,e)=>vn(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),Lr=s=>{if(Array.isArray(s))return vn(s);if(Ja(s))return[{permission:"*",pattern:"*",action:s}];if(!s||typeof s!="object"||Array.isArray(s))return[];const e=[];for(const[n,a]of Object.entries(s))if(n!=="__originalKeys"){if(Ja(a)){e.push({permission:n,pattern:"*",action:a});continue}if(a&&typeof a=="object"&&!Array.isArray(a))for(const[r,i]of Object.entries(a))Ja(i)&&e.push({permission:n,pattern:r,action:i})}return e},Zp=(s,e)=>{const n=vn(e),a={};for(const i of n)(a[i.permission]||={})[i.pattern]=i.action;const r={};for(const[i,l]of Object.entries(a))if(i!=="*"){if(Object.keys(l).length===1&&l["*"]){r[i]=l["*"];continue}r[i]=l}return Object.keys(r).length===0?s:(s!=="allow"&&(r["*"]=s),r)},eg=(s,e)=>{const n=fn(e);if(!n)return[];const r=s.find(i=>i.id===n.providerId)?.models?.find(i=>i.id===n.modelId);return r?.variants?Object.keys(r.variants):[]},tg=()=>{const{t:s}=st(),{isMobile:e}=Ds(),n=lt(V=>V.providers),{selectedAgentName:a,getAgentByName:r,createAgent:i,updateAgent:l,agents:d,agentDraft:c,setAgentDraft:h}=cr(Ps(V=>({selectedAgentName:V.selectedAgentName,getAgentByName:V.getAgentByName,createAgent:V.createAgent,updateAgent:V.updateAgent,agents:V.agents,agentDraft:V.agentDraft,setAgentDraft:V.setAgentDraft}))),m=a?r(a):null,p=!!(c&&c.name===a&&!m),[u,w]=o.useState(""),[g,f]=o.useState("user"),[x,D]=o.useState(""),[P,I]=o.useState("subagent"),[L,N]=o.useState(""),[b,j]=o.useState(""),[T,U]=o.useState(void 0),[K,M]=o.useState(void 0),[C,A]=o.useState(""),[z,R]=o.useState("allow"),[Q,W]=o.useState([]),[te,Y]=o.useState([]),[k,$]=o.useState(""),[B,F]=o.useState("*"),[O,J]=o.useState(!1),[H,re]=o.useState(!1),le=o.useRef(null),ne=ws(V=>V.currentDirectory??null),[be,ae]=o.useState([]),ye=o.useMemo(()=>eg(n,L),[L,n]),ke=ye.length>0,he=o.useMemo(()=>!b||!ye.includes(b)?"__default":b,[b,ye]),we=ke&&(!b||ye.includes(b)),de=fu(V=>V.permission);o.useEffect(()=>{let V=!1;return(async()=>{const ge=await ys.listToolIds({directory:ne});if(V)return;const Fe=new Set(["write","patch","multiedit"]),Ne=ge.map(He=>typeof He=="string"?He.trim():"").filter(Boolean).filter(He=>He!=="*").filter(He=>He!=="invalid").filter(He=>!Fe.has(He));ae(Array.from(new Set(Ne)).sort((He,X)=>He.localeCompare(X)))})(),()=>{V=!0}},[ne]);const Z=o.useMemo(()=>{const V=new Set;for(const oe of d){const ge=vn(Lr(oe.permission));for(const Fe of ge)Fe.permission&&Fe.permission!=="*"&&Fe.permission!=="invalid"&&V.add(Fe.permission)}for(const oe of Object.values(de))for(const ge of oe){const Fe=ge.permission?.trim();Fe&&Fe!=="invalid"&&V.add(Fe)}for(const oe of be)V.add(oe);return Array.from(V).sort((oe,ge)=>oe.localeCompare(ge))},[d,de,be]),se=o.useMemo(()=>Ta(Q),[Q]),ve=o.useMemo(()=>Ta(te),[te]),G=o.useCallback(V=>ve.get(An(V,"*"))?.action,[ve]),ee=o.useCallback(V=>te.filter(oe=>oe.permission===V&&oe.pattern!=="*").sort((oe,ge)=>oe.pattern.localeCompare(ge.pattern)),[te]),ie=o.useMemo(()=>{const V=new Set;for(const oe of Ao)V.add(oe);for(const oe of Z)V.add(oe);return Array.from(V).sort((oe,ge)=>oe.localeCompare(ge))},[Z]),pe=o.useCallback(V=>{const oe=V==="*"?z:G(V)??z,ge=ee(V),Fe=!1,Ne=ge.reduce((X,v)=>(X[v.action]=(X[v.action]??0)+1,X),{allow:0,ask:0,deny:0}),He=["allow","ask","deny"].filter(X=>Ne[X]>0).map(X=>`${Ne[X]} ${X}`).join(", ");return{defaultAction:oe,patternRulesCount:ge.length,patternSummary:He,hasDefaultHint:Fe}},[ee,G,z]),Ae=o.useCallback(V=>s(V==="allow"?"settings.common.permission.allow":V==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),Se=o.useCallback(V=>V==="global"?s("settings.common.scope.global"):Ae(V),[Ae,s]),De=o.useMemo(()=>{const V=new Set;for(const oe of Ao)V.add(oe);for(const oe of Z)V.add(oe);return Array.from(V).sort((oe,ge)=>oe.localeCompare(ge))},[Z]),Me=o.useCallback((V,oe,ge)=>{Y(Fe=>{const Ne=Ta(Fe);return Ne.set(An(V,oe),{permission:V,pattern:oe,action:ge}),Array.from(Ne.values())})},[]),Te=o.useCallback((V,oe)=>{Y(ge=>{const Fe=Ta(ge);return Fe.delete(An(V,oe)),Array.from(Fe.values())})},[]),Be=o.useCallback((V,oe)=>{const ge=se.get(An(V,oe));if(ge){Me(V,oe,ge.action);return}Te(V,oe)},[se,Te,Me]),ze=o.useCallback((V,oe,ge)=>{Me(V,oe,ge)},[Me]),Oe=o.useCallback(V=>{R(V),Y(oe=>oe.filter(ge=>!(ge.pattern==="*"&&ge.action===V)))},[]),$e=o.useCallback(V=>{const oe=k.trim();if(!oe){_.error(s("settings.agents.page.toast.permissionNameRequired"));return}const ge=B.trim()||"*";if(oe==="*"&&ge==="*"){Oe(V),$(""),F("*");return}ge==="*"&&oe!=="*"&&V===z?Te(oe,"*"):Me(oe,ge,V),$(""),F("*")},[z,k,B,Te,Oe,s,Me]),Ke=o.useCallback(V=>V==="*"?s("settings.agents.page.permissions.defaultLabel"):V==="webfetch"?"WebFetch":V==="websearch"?"WebSearch":V==="codesearch"?"CodeSearch":V==="doom_loop"?"Doom Loop":V==="external_directory"?"External Directory":V==="todowrite"?"TodoWrite":V==="todoread"?"TodoRead":V.split(/[_-]+/g).filter(Boolean).map(oe=>oe.charAt(0).toUpperCase()+oe.slice(1)).join(" "),[s]);o.useEffect(()=>{$(""),F("*");const V=oe=>{const ge=vn(oe),Fe=Yp(ge),Ne=Xp(ge,Fe);return R(Fe),W(Ne),Y(Ne),{global:Fe,rules:Ne}};if(p&&c){const oe=c.name||"",ge=c.scope||"user",Fe=c.description||"",Ne=c.mode||"subagent",He=c.model||"",X=c.variant||"",v=c.temperature??void 0,je=c.top_p??void 0,Pe=c.prompt||"";w(oe),f(ge),D(Fe),I(Ne),N(He),j(X),U(v),M(je),A(Pe);const Le=Lr(c.permission),qe=V(Le);le.current={draftName:oe,draftScope:ge,description:Fe,mode:Ne,model:He,variant:X,temperature:v,topP:je,prompt:Pe,globalPermission:qe.global,permissionRules:qe.rules};return}if(m&&a===m.name){const oe=m.description||"",ge=m.mode||"subagent",Fe=m.model?.providerID&&m.model?.modelID?`${m.model.providerID}/${m.model.modelID}`:"",Ne=m.variant||"",He=m.temperature,X=m.topP,v=m.prompt||"";D(oe),I(ge),N(Fe),j(Ne),U(He),M(X),A(v);const je=V(Lr(m.permission));le.current={draftName:"",draftScope:"user",description:oe,mode:ge,model:Fe,variant:Ne,temperature:He,topP:X,prompt:v,globalPermission:je.global,permissionRules:je.rules}}},[c,p,m,a]);const Ye=o.useMemo(()=>{const V=le.current;return V?!!(p&&(u!==V.draftName||g!==V.draftScope)||x!==V.description||P!==V.mode||L!==V.model||b!==V.variant||T!==V.temperature||K!==V.topP||C!==V.prompt||z!==V.globalPermission||!Qp(te,V.permissionRules)):!1},[x,u,g,z,p,P,L,te,C,T,K,b]),Re=async()=>{const V=p?u.trim().replace(/\s+/g,"-"):a?.trim();if(!V){_.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(p&&d.some(oe=>oe.name===V)){_.error(s("settings.agents.sidebar.toast.agentExists"));return}re(!0);try{const oe=L.trim(),ge=b.trim(),Fe=C.trim(),Ne=Zp(z,te),He={name:V,...x.trim()?{description:x.trim()}:{},mode:P,model:oe===""?null:oe,variant:ge===""?null:ge||void 0,temperature:T??null,top_p:K??null,prompt:Fe||(p?void 0:null),permission:Ne,...p&&g?{scope:g}:{}};let X;p?(X=await i(He),X.ok&&h(null)):X=await l(V,He),X.ok?X.requiresManualRestart?_.warning(s("settings.agents.page.toast.savedManualRestart")):_.success(s(p?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):_.error(s(p?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(oe){console.error("Error saving agent:",oe);const ge=oe instanceof Error&&oe.message?oe.message:s("settings.agents.page.toast.saveUnexpectedError");_.error(ge)}finally{re(!1)}};return a?t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p?s("settings.agents.page.title.new"):a}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(p?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.identityRole")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&t.jsxs("div",{"data-settings-item":"agents.name",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.agentName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),t.jsx(Xe,{value:u,onChange:V=>w(V.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(At,{value:g,onValueChange:V=>f(V),children:[t.jsx(Dt,{className:"w-fit min-w-[100px]",children:t.jsx(Ot,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Et,{align:"end",children:[t.jsx(mt,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(mt,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(us,{value:x,onChange:V=>D(V.target.value),placeholder:s("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),t.jsx("div",{"data-settings-item":"agents.mode",className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.mode")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.modeTooltip")})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(q,{variant:"chip",size:"xs","aria-pressed":P==="primary",onClick:()=>I("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":P==="subagent",onClick:()=>I("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":P==="all",onClick:()=>I("all"),className:"!font-normal",children:s("settings.agents.page.mode.all")})]})]})})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.modelParameters")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{"data-settings-item":"agents.model",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(ja,{providerId:fn(L)?.providerId??"",modelId:fn(L)?.modelId??"",onChange:(V,oe)=>{N(V&&oe?`${V}/${oe}`:""),j("")}})})]}),t.jsxs("div",{"data-settings-item":"agents.variant",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.variant")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.variantTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.variantHint")})]}),t.jsx("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:we?t.jsxs(At,{value:he,onValueChange:V=>j(V==="__default"?"":V),children:[t.jsx(Dt,{className:ce("max-w-full",e?"w-full":"w-fit min-w-[10rem]"),children:t.jsx(Ot,{placeholder:s("settings.agents.page.field.variantPlaceholder"),children:V=>V==="__default"?s("chat.modelControls.default"):V})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"__default",children:s("chat.modelControls.default")}),ye.map(V=>t.jsx(mt,{value:V,children:V},V))]})]}):t.jsxs(t.Fragment,{children:[t.jsx(Xe,{value:b,onChange:V=>j(V.target.value),placeholder:s("settings.agents.page.field.variantPlaceholder"),disabled:!L&&!b,className:ce("h-7 w-40",e&&"w-full")}),b&&t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(""),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.common.actions.clear"),title:s("settings.common.actions.clear"),children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})})]})})]}),t.jsxs("div",{"data-settings-item":"agents.temperature",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.temperature")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.temperatureTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.temperatureRange")})]}),t.jsxs("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(xs,{value:T,fallbackValue:.7,onValueChange:U,onClear:()=>U(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),T!==void 0&&t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>U(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTemperatureAria"),title:s("settings.common.actions.clear"),children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{"data-settings-item":"agents.top-p",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.topP")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.topPTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.topPRange")})]}),t.jsxs("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(xs,{value:K,fallbackValue:.9,onValueChange:M,onClear:()=>M(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),K!==void 0&&t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>M(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTopPAria"),title:s("settings.common.actions.clear"),children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),t.jsxs("div",{"data-settings-item":"agents.system-prompt",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.systemPrompt")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(us,{value:C,onChange:V=>A(V.target.value),placeholder:s("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),t.jsxs("div",{"data-settings-item":"agents.permissions",className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.toolPermissions")}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>J(V=>!V),children:s(O?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),O?t.jsxs("div",{className:"space-y-6 px-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.permissions.globalDefault")}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),t.jsxs(At,{value:z,onValueChange:V=>Oe(V),children:[t.jsx(Dt,{className:"w-[100px]",children:t.jsx(Ot,{children:Ae(z)})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(mt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(mt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:ie.filter(V=>V!=="*").map(V=>{const oe=Ke(V),{defaultAction:ge,patternRulesCount:Fe}=pe(V),Ne=G(V),He=Ne??"global",X=ee(V),v=["allow","ask","deny"].filter(je=>je!==z);return t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[t.jsxs("div",{className:"flex items-center justify-between py-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:oe}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:V})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Fe>0?s("settings.agents.page.permissions.globalSummary",{summary:ge}):ge})]}),t.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Ne&&t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>Be(V,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(E,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(At,{value:He,onValueChange:je=>{if(je==="global"){Te(V,"*");return}Me(V,"*",je)},children:[t.jsx(Dt,{className:"w-[90px]",children:t.jsx(Ot,{children:Se(He)})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"global",children:s("settings.common.scope.global")}),v.map(je=>t.jsx(mt,{value:je,className:"capitalize",children:Ae(je)},je))]})]})]}),X.map(je=>{const Pe=An(je.permission,je.pattern),Le=se.get(Pe),qe=!Le,rt=!!(Le&&Le.action!==je.action);return t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:je.pattern}),qe&&t.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:s("settings.common.badge.new")}),rt&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:s("settings.common.badge.modified")}),(qe||rt)&&t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>qe?Te(je.permission,je.pattern):Be(je.permission,je.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(E,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(At,{value:je.action,onValueChange:ot=>ze(je.permission,je.pattern,ot),children:[t.jsx(Dt,{className:"w-[90px]",children:t.jsx(Ot,{children:Ae(je.action)})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(mt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(mt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},Pe)})]})]},V)})}),t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[t.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:s("settings.agents.page.permissions.addCustomRule")}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[t.jsxs(At,{value:k,onValueChange:$,children:[t.jsx(Dt,{className:"w-full sm:w-[160px]",children:k?t.jsx("span",{className:"truncate",children:Ke(k)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Et,{children:De.map(V=>t.jsx(mt,{value:V,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:Ke(V)})})},V))})]}),t.jsx(Xe,{value:B,onChange:V=>F(V.target.value),placeholder:s("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$e("allow"),children:s("settings.common.permission.allow")}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$e("ask"),children:s("settings.common.permission.ask")}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$e("deny"),children:s("settings.common.permission.deny")})]})]})]})]}):t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ie.map((V,oe)=>{const{defaultAction:ge,patternRulesCount:Fe,patternSummary:Ne,hasDefaultHint:He}=pe(V),X=Ke(V),v=He?`${ge} (env blocked)`:ge;return t.jsxs("div",{className:ce("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",oe>0&&"border-t border-[var(--surface-subtle)]"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:X}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:V})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Fe>0?t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.globalSummary",{summary:v})}):t.jsx("span",{className:ce("typography-micro capitalize px-1.5 py-0.5 rounded",v==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":v==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:v}),Fe>0&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.rulesSummary",{summary:Ne})})]})]},V)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(q,{onClick:Re,disabled:H||!Ye,size:"xs",className:"!font-normal",children:s(H?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(E,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.agents.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.agents.page.empty.description")})]})})},sg="~/.config/opencode/AGENTS.md",Nc=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},ng=s=>s.length>0&&!s.endsWith(`
|
|
2
|
+
`)?`${s}
|
|
3
|
+
`:s,Ra={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},ag=(s,e)=>s==="custom"?e:yu(s),rg=s=>s==="custom"?"custom":rc(s)?s:"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"},Mo=async(s,e)=>{const n=await ct("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(s)});if(!n.ok)throw new Error(await Nc(n,e))},ig=()=>{const{t:s}=st(),[e,n]=o.useState(""),[a,r]=o.useState(Ra.responseStyleEnabled),[i,l]=o.useState(Ra.responseStylePreset),[d,c]=o.useState(Ra.responseStyleCustomInstructions),[h,m]=o.useState(!0),[p,u]=o.useState(!1),[w,g]=o.useState(""),f=o.useRef(null);o.useEffect(()=>{const I=new AbortController;return(async()=>{try{const[N,b]=await Promise.all([ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:I.signal}),ct("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:I.signal})]);let j=Ra;if(N.ok){const T=await N.json();j={...j,responseStyleEnabled:T.responseStyleEnabled===!0,responseStylePreset:rg(T.responseStylePreset),responseStyleCustomInstructions:typeof T.responseStyleCustomInstructions=="string"?T.responseStyleCustomInstructions:""},typeof T.globalBehaviorPrompt=="string"&&(j={...j,prompt:T.globalBehaviorPrompt})}if(!j.prompt.trim()&&b.ok){const T=await b.json();typeof T.content=="string"&&(j={...j,prompt:T.content})}n(j.prompt),r(j.responseStyleEnabled),l(j.responseStylePreset),c(j.responseStyleCustomInstructions),g(j.prompt),f.current={enabled:j.responseStyleEnabled,preset:j.responseStylePreset,custom:j.responseStyleCustomInstructions}}catch(N){N.name!=="AbortError"&&console.warn("Failed to load behavior settings:",N)}finally{m(!1)}})(),()=>I.abort()},[]),o.useEffect(()=>{if(h)return;const I=f.current;if(I&&I.enabled===a&&I.preset===i&&I.custom===d)return;const L={enabled:a,preset:i,custom:d},N=setTimeout(async()=>{try{await Mo({responseStyleEnabled:L.enabled,responseStylePreset:L.preset,responseStyleCustomInstructions:L.custom},s("settings.behavior.page.toast.saveFailed")),f.current=L}catch(b){const j=b instanceof Error?b.message:s("settings.behavior.page.toast.saveFailed");_.error(j)}},400);return()=>clearTimeout(N)},[a,i,d,h,s]);const x=ag(i,d),D=e!==w,P=async()=>{u(!0);try{const I=ng(e),L=await ct("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:I})});if(!L.ok)throw new Error(await Nc(L,s("settings.behavior.page.toast.saveFailed")));await Mo({globalBehaviorPrompt:I},s("settings.behavior.page.toast.saveFailed")),n(I),g(I),_.success(s("settings.behavior.page.toast.saved"))}catch(I){console.error("Failed to save behavior:",I);const L=I instanceof Error?I.message:s("settings.behavior.page.toast.saveFailed");_.error(L)}finally{u(!1)}};return t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8 space-y-6",children:[t.jsx("div",{className:"space-y-1",children:t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.behavior.page.title")})}),t.jsxs("div",{"data-settings-item":"behavior.system-prompt",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.systemPrompt")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"font-medium text-foreground",children:s("settings.behavior.page.warning.title")}),t.jsx("p",{children:s("settings.behavior.page.warning.description",{path:sg})})]})})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsx(us,{value:e,onChange:I=>n(I.target.value),placeholder:s("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:h,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),t.jsx(q,{onClick:P,disabled:p||!D||h,size:"xs",className:"!font-normal",children:s(p?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),t.jsxs("div",{"data-settings-item":"behavior.response-style",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.responseStyle")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.behavior.page.responseStyle.tooltip")})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[t.jsx(yt,{checked:a,onChange:r,disabled:h,ariaLabel:s("settings.behavior.page.responseStyle.enableAria")}),s("settings.behavior.page.responseStyle.enable")]}),t.jsxs(At,{value:i,onValueChange:I=>l(I),disabled:h||!a,children:[t.jsx(Dt,{className:"w-full sm:w-56",size:"lg",children:t.jsx(Ot,{children:I=>I==="custom"?s("settings.behavior.page.responseStyle.option.custom"):rc(I)?s(Eo[I]):null})}),t.jsxs(Et,{children:[xu.map(I=>t.jsx(mt,{value:I,children:s(Eo[I])},I)),t.jsx(mt,{value:"custom",children:s("settings.behavior.page.responseStyle.option.custom")})]})]}),t.jsx(us,{value:x,onChange:I=>c(I.target.value),placeholder:s("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:h||!a||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},og=s=>{const e=et.c(169),{onItemSelect:n}=s,{t:a}=st(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,h]=o.useState(null),[m,p]=o.useState(null),[u,w]=o.useState(!1),[g,f]=o.useState(null),{selectedCommandName:x,commands:D,setSelectedCommand:P,setCommandDraft:I,createCommand:L,deleteCommand:N,loadCommands:b}=dr(Ps(lg)),j=Zs(cg),T=Zs(dg);let U,K;e[0]!==b||e[1]!==T?(U=()=>{b(),T()},K=[b,T],e[0]=b,e[1]=T,e[2]=U,e[3]=K):(U=e[2],K=e[3]),o.useEffect(U,K);let M;e[4]!==j?(M=new Set(j.map(ug)),e[4]=j,e[5]=M):M=e[5];const C=M;let A;if(e[6]!==D||e[7]!==C){let fe;e[9]!==C?(fe=tt=>!C.has(tt.name),e[9]=C,e[10]=fe):fe=e[10],A=D.filter(fe),e[6]=D,e[7]=C,e[8]=A}else A=e[8];const z=A;let R,Q;e[11]!==x||e[12]!==P||e[13]!==C?(R=()=>{x&&C.has(x)&&P(null)},Q=[x,P,C],e[11]=x,e[12]=P,e[13]=C,e[14]=R,e[15]=Q):(R=e[14],Q=e[15]),o.useEffect(R,Q);let W;e[16]!==D||e[17]!==n||e[18]!==I||e[19]!==P?(W=()=>{let fe="new-command",tt=1;for(;D.some(nt=>nt.name===fe);)fe=`new-command-${tt}`,tt++;I({name:fe,scope:"user"}),P(fe),n?.()},e[16]=D,e[17]=n,e[18]=I,e[19]=P,e[20]=W):W=e[20];const te=W;let Y;e[21]!==a?(Y=async fe=>{if(Qn(fe)){_.error(a("settings.commands.sidebar.toast.builtInCannotDelete"));return}h(fe),p("delete")},e[21]=a,e[22]=Y):Y=e[22];const k=Y;let $;e[23]===Symbol.for("react.memo_cache_sentinel")?($=async fe=>{Qn(fe)&&(h(fe),p("reset"))},e[23]=$):$=e[23];const B=$;let F;e[24]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{h(null),p(null)},e[24]=F):F=e[24];const O=F;let J;e[25]!==c||e[26]!==m||e[27]!==N||e[28]!==a?(J=async()=>{if(!c||!m)return;w(!0),await N(c.name)?(m==="delete"?_.success(a("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):_.success(a("settings.commands.sidebar.toast.commandReset",{name:c.name})),O()):m==="delete"?_.error(a("settings.commands.sidebar.toast.deleteFailed")):_.error(a("settings.commands.sidebar.toast.resetFailed")),w(!1)},e[25]=c,e[26]=m,e[27]=N,e[28]=a,e[29]=J):J=e[29];const H=J;let re;e[30]!==D||e[31]!==I||e[32]!==P?(re=fe=>{const tt=fe.name;let nt=1,Ze=`${tt}-copy`;for(;D.some(ft=>ft.name===Ze);)nt++,Ze=`${tt}-copy-${nt}`;I({name:Ze,scope:fe.scope||"user",description:fe.description,template:fe.template,agent:fe.agent,model:fe.model}),P(Ze)},e[30]=D,e[31]=I,e[32]=P,e[33]=re):re=e[33];const le=re;let ne;e[34]===Symbol.for("react.memo_cache_sentinel")?(ne=fe=>{d(fe.name),i(fe)},e[34]=ne):ne=e[34];const be=ne;let ae;e[35]!==D||e[36]!==L||e[37]!==N||e[38]!==r||e[39]!==l||e[40]!==P||e[41]!==a?(ae=async()=>{if(!r)return;const fe=l.trim().replace(/\s+/g,"-");if(!fe){_.error(a("settings.commands.sidebar.toast.commandNameRequired"));return}if(fe===r.name){i(null);return}if(D.some(nt=>nt.name===fe)){_.error(a("settings.commands.sidebar.toast.commandExists"));return}await L({name:fe,description:r.description,template:r.template,agent:r.agent,model:r.model})?await N(r.name)?(_.success(`Command renamed to "${fe}"`),P(fe)):_.error(a("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):_.error(a("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=D,e[36]=L,e[37]=N,e[38]=r,e[39]=l,e[40]=P,e[41]=a,e[42]=ae):ae=e[42];const ye=ae;let ke,he,we,de,Z,se;if(e[43]!==z||e[44]!==te||e[45]!==k||e[46]!==le||e[47]!==n||e[48]!==g||e[49]!==x||e[50]!==P||e[51]!==a){const fe=z.filter(Qn),tt=z.filter(mg);e[58]===Symbol.for("react.memo_cache_sentinel")?(Z=ce("flex h-full flex-col","bg-background"),e[58]=Z):Z=e[58];let nt;e[59]!==a?(nt=a("settings.commands.sidebar.title"),e[59]=a,e[60]=nt):nt=e[60];let Ze;e[61]!==nt?(Ze=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:nt}),e[61]=nt,e[62]=Ze):Ze=e[62];let ft;e[63]===Symbol.for("react.memo_cache_sentinel")?(ft=t.jsx(ka,{className:"mb-3"}),e[63]=ft):ft=e[63];let bt;e[64]!==z.length||e[65]!==a?(bt=a("settings.commands.sidebar.total",{count:z.length}),e[64]=z.length,e[65]=a,e[66]=bt):bt=e[66];let Mt;e[67]!==bt?(Mt=t.jsx("span",{className:"typography-meta text-muted-foreground",children:bt}),e[67]=bt,e[68]=Mt):Mt=e[68];let ue;e[69]===Symbol.for("react.memo_cache_sentinel")?(ue=t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),e[69]=ue):ue=e[69];let Ve;e[70]!==te?(Ve=t.jsx(q,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:te,children:ue}),e[70]=te,e[71]=Ve):Ve=e[71];let Qe;e[72]!==Mt||e[73]!==Ve?(Qe=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Mt,Ve]}),e[72]=Mt,e[73]=Ve,e[74]=Qe):Qe=e[74],e[75]!==Ze||e[76]!==Qe?(se=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Ze,ft,Qe]}),e[75]=Ze,e[76]=Qe,e[77]=se):se=e[77],ke=_t,he="flex-1 min-h-0",we="space-y-1 px-3 py-2",de=z.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(E,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.commands.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.commands.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[fe.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.commands.sidebar.section.builtIn")}),[...fe].sort(pg).map(Ge=>t.jsx(To,{command:Ge,isSelected:x===Ge.name,onSelect:()=>{P(Ge.name),n?.()},onReset:()=>B(Ge),onDuplicate:()=>le(Ge),isMenuOpen:g===Ge.name,onMenuOpenChange:xt=>f(xt?Ge.name:null)},Ge.name))]}),tt.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.commands.sidebar.section.custom")}),[...tt].sort(gg).map(Ge=>t.jsx(To,{command:Ge,isSelected:x===Ge.name,onSelect:()=>{P(Ge.name),n?.()},onRename:()=>be(Ge),onDelete:()=>k(Ge),onDuplicate:()=>le(Ge),isMenuOpen:g===Ge.name,onMenuOpenChange:xt=>f(xt?Ge.name:null)},Ge.name))]})]}),e[43]=z,e[44]=te,e[45]=k,e[46]=le,e[47]=n,e[48]=g,e[49]=x,e[50]=P,e[51]=a,e[52]=ke,e[53]=he,e[54]=we,e[55]=de,e[56]=Z,e[57]=se}else ke=e[52],he=e[53],we=e[54],de=e[55],Z=e[56],se=e[57];let ve;e[78]!==ke||e[79]!==he||e[80]!==we||e[81]!==de?(ve=t.jsx(ke,{outerClassName:he,className:we,children:de}),e[78]=ke,e[79]=he,e[80]=we,e[81]=de,e[82]=ve):ve=e[82];const G=c!==null&&m!==null;let ee;e[83]!==u?(ee=fe=>{!fe&&!u&&O()},e[83]=u,e[84]=ee):ee=e[84];let ie;e[85]!==m||e[86]!==a?(ie=a(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=a,e[87]=ie):ie=e[87];let pe;e[88]!==ie?(pe=t.jsx(zt,{children:ie}),e[88]=ie,e[89]=pe):pe=e[89];let Ae;e[90]!==c?.name||e[91]!==m||e[92]!==a?(Ae=m==="delete"?a("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):a("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[90]=c?.name,e[91]=m,e[92]=a,e[93]=Ae):Ae=e[93];let Se;e[94]!==Ae?(Se=t.jsx($t,{children:Ae}),e[94]=Ae,e[95]=Se):Se=e[95];let De;e[96]!==pe||e[97]!==Se?(De=t.jsxs(Kt,{children:[pe,Se]}),e[96]=pe,e[97]=Se,e[98]=De):De=e[98];let Me;e[99]!==a?(Me=a("settings.common.actions.cancel"),e[99]=a,e[100]=Me):Me=e[100];let Te;e[101]!==u||e[102]!==Me?(Te=t.jsx(q,{size:"sm",variant:"ghost",onClick:O,disabled:u,children:Me}),e[101]=u,e[102]=Me,e[103]=Te):Te=e[103];let Be;e[104]!==m||e[105]!==a?(Be=a(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=a,e[106]=Be):Be=e[106];let ze;e[107]!==H||e[108]!==u||e[109]!==Be?(ze=t.jsx(q,{size:"sm",onClick:H,disabled:u,children:Be}),e[107]=H,e[108]=u,e[109]=Be,e[110]=ze):ze=e[110];let Oe;e[111]!==Te||e[112]!==ze?(Oe=t.jsxs(Gt,{children:[Te,ze]}),e[111]=Te,e[112]=ze,e[113]=Oe):Oe=e[113];let $e;e[114]!==De||e[115]!==Oe?($e=t.jsxs(Ft,{className:"max-w-md",children:[De,Oe]}),e[114]=De,e[115]=Oe,e[116]=$e):$e=e[116];let Ke;e[117]!==G||e[118]!==ee||e[119]!==$e?(Ke=t.jsx(Rt,{open:G,onOpenChange:ee,children:$e}),e[117]=G,e[118]=ee,e[119]=$e,e[120]=Ke):Ke=e[120];const Ye=r!==null;let Re;e[121]===Symbol.for("react.memo_cache_sentinel")?(Re=fe=>!fe&&i(null),e[121]=Re):Re=e[121];let V;e[122]!==a?(V=a("settings.commands.sidebar.renameDialog.title"),e[122]=a,e[123]=V):V=e[123];let oe;e[124]!==V?(oe=t.jsx(zt,{children:V}),e[124]=V,e[125]=oe):oe=e[125];const ge=r?.name??"";let Fe;e[126]!==a||e[127]!==ge?(Fe=a("settings.commands.sidebar.renameDialog.description",{name:ge}),e[126]=a,e[127]=ge,e[128]=Fe):Fe=e[128];let Ne;e[129]!==Fe?(Ne=t.jsx($t,{children:Fe}),e[129]=Fe,e[130]=Ne):Ne=e[130];let He;e[131]!==oe||e[132]!==Ne?(He=t.jsxs(Kt,{children:[oe,Ne]}),e[131]=oe,e[132]=Ne,e[133]=He):He=e[133];let X;e[134]===Symbol.for("react.memo_cache_sentinel")?(X=fe=>d(fe.target.value),e[134]=X):X=e[134];let v;e[135]!==a?(v=a("settings.commands.sidebar.renameDialog.placeholder"),e[135]=a,e[136]=v):v=e[136];let je;e[137]!==ye?(je=fe=>{fe.key==="Enter"&&ye()},e[137]=ye,e[138]=je):je=e[138];let Pe;e[139]!==l||e[140]!==v||e[141]!==je?(Pe=t.jsx(Xe,{value:l,onChange:X,placeholder:v,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:je}),e[139]=l,e[140]=v,e[141]=je,e[142]=Pe):Pe=e[142];let Le;e[143]===Symbol.for("react.memo_cache_sentinel")?(Le=()=>i(null),e[143]=Le):Le=e[143];let qe;e[144]!==a?(qe=a("settings.common.actions.cancel"),e[144]=a,e[145]=qe):qe=e[145];let rt;e[146]!==qe?(rt=t.jsx(q,{size:"sm",variant:"ghost",onClick:Le,children:qe}),e[146]=qe,e[147]=rt):rt=e[147];let ot;e[148]!==a?(ot=a("settings.common.actions.rename"),e[148]=a,e[149]=ot):ot=e[149];let it;e[150]!==ye||e[151]!==ot?(it=t.jsx(q,{size:"sm",onClick:ye,children:ot}),e[150]=ye,e[151]=ot,e[152]=it):it=e[152];let dt;e[153]!==rt||e[154]!==it?(dt=t.jsxs(Gt,{children:[rt,it]}),e[153]=rt,e[154]=it,e[155]=dt):dt=e[155];let Je;e[156]!==He||e[157]!==Pe||e[158]!==dt?(Je=t.jsxs(Ft,{children:[He,Pe,dt]}),e[156]=He,e[157]=Pe,e[158]=dt,e[159]=Je):Je=e[159];let _e;e[160]!==Ye||e[161]!==Je?(_e=t.jsx(Rt,{open:Ye,onOpenChange:Re,children:Je}),e[160]=Ye,e[161]=Je,e[162]=_e):_e=e[162];let gt;return e[163]!==Z||e[164]!==se||e[165]!==ve||e[166]!==Ke||e[167]!==_e?(gt=t.jsxs("div",{className:Z,children:[se,ve,Ke,_e]}),e[163]=Z,e[164]=se,e[165]=ve,e[166]=Ke,e[167]=_e,e[168]=gt):gt=e[168],gt},To=s=>{const e=et.c(47),{command:n,isSelected:a,onSelect:r,onDelete:i,onReset:l,onRename:d,onDuplicate:c,isMenuOpen:h,onMenuOpenChange:m}=s,{t:p}=st();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=va(),e[0]=u):u=e[0];const w=u,[g,f]=o.useState(!1);let x;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==l||e[5]!==p?(x=Y=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(Y,{onClick:k=>{k.stopPropagation(),d()},children:[t.jsx(E,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),t.jsxs(Y,{onClick:k=>{k.stopPropagation(),c()},children:[t.jsx(E,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),l&&t.jsxs(Y,{onClick:k=>{k.stopPropagation(),l()},children:[t.jsx(E,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),i&&t.jsxs(Y,{onClick:k=>{k.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(E,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=l,e[5]=p,e[6]=x):x=e[6];const D=x,P=a?"bg-interactive-selection":"hover:bg-interactive-hover";let I;e[7]!==P?(I=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",P),e[7]=P,e[8]=I):I=e[8];let L;e[9]===Symbol.for("react.memo_cache_sentinel")?(L=w?void 0:Y=>{Y.preventDefault(),f(!0)},e[9]=L):L=e[9];let N;e[10]!==I?(N=t.jsx("div",{className:I,onContextMenu:L}),e[10]=I,e[11]=N):N=e[11];let b;e[12]!==n.name?(b=t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[12]=n.name,e[13]=b):b=e[13];let j;e[14]!==n||e[15]!==p?(j=(n.scope||Qn(n))&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Qn(n)?p("settings.agents.sidebar.badge.system"):n.scope}),e[14]=n,e[15]=p,e[16]=j):j=e[16];let T;e[17]!==b||e[18]!==j?(T=t.jsxs("div",{className:"flex items-center gap-2",children:[b,j]}),e[17]=b,e[18]=j,e[19]=T):T=e[19];let U;e[20]!==n.description?(U=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[20]=n.description,e[21]=U):U=e[21];let K;e[22]!==r||e[23]!==U||e[24]!==T?(K=t.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[T,U]}),e[22]=r,e[23]=U,e[24]=T,e[25]=K):K=e[25];let M;e[26]!==m?(M=Y=>{Y&&f(!1),m(Y)},e[26]=m,e[27]=M):M=e[27];let C;e[28]===Symbol.for("react.memo_cache_sentinel")?(C=t.jsx(ls,{asChild:!0,children:t.jsx(q,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(E,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=C):C=e[28];let A;e[29]!==D?(A=t.jsx(cs,{align:"end",className:"w-fit min-w-20",children:D(Ns)}),e[29]=D,e[30]=A):A=e[30];let z;e[31]!==h||e[32]!==M||e[33]!==A?(z=t.jsxs(ds,{open:h,onOpenChange:M,children:[C,A]}),e[31]=h,e[32]=M,e[33]=A,e[34]=z):z=e[34];let R;e[35]!==K||e[36]!==z?(R=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[K,z]}),e[35]=K,e[36]=z,e[37]=R):R=e[37];let Q;e[38]!==R||e[39]!==N?(Q=t.jsx(yn,{render:N,children:R}),e[38]=R,e[39]=N,e[40]=Q):Q=e[40];let W;e[41]!==D?(W=t.jsx(bn,{className:"w-fit min-w-20",children:D(sn)}),e[41]=D,e[42]=W):W=e[42];let te;return e[43]!==g||e[44]!==Q||e[45]!==W?(te=t.jsxs(xn,{open:g,onOpenChange:f,children:[Q,W]}),e[43]=g,e[44]=Q,e[45]=W,e[46]=te):te=e[46],te};function lg(s){return{selectedCommandName:s.selectedCommandName,commands:s.commands,setSelectedCommand:s.setSelectedCommand,setCommandDraft:s.setCommandDraft,createCommand:s.createCommand,deleteCommand:s.deleteCommand,loadCommands:s.loadCommands}}function cg(s){return s.skills}function dg(s){return s.loadSkills}function ug(s){return s.name}function mg(s){return!Qn(s)}function pg(s,e){return s.name.localeCompare(e.name)}function gg(s,e){return s.name.localeCompare(e.name)}const hg=()=>{const{t:s}=st(),{selectedCommandName:e,getCommandByName:n,createCommand:a,updateCommand:r,commands:i,commandDraft:l,setCommandDraft:d}=dr(Ps(M=>({selectedCommandName:M.selectedCommandName,getCommandByName:M.getCommandByName,createCommand:M.createCommand,updateCommand:M.updateCommand,commands:M.commands,commandDraft:M.commandDraft,setCommandDraft:M.setCommandDraft}))),c=e?n(e):null,h=!!(l&&l.name===e&&!c),[m,p]=o.useState(""),[u,w]=o.useState("user"),[g,f]=o.useState(""),[x,D]=o.useState(""),[P,I]=o.useState(""),[L,N]=o.useState(""),[b,j]=o.useState(!1),T=o.useRef(null);o.useEffect(()=>{if(h&&l){const M=l.name||"",C=l.scope||"user",A=l.description||"",z=l.agent||"",R=l.model||"",Q=l.template||"";p(M),w(C),f(A),D(z),I(R),N(Q),T.current={draftName:M,draftScope:C,description:A,agent:z,model:R,template:Q}}else if(c){const M=c.description||"",C=c.agent||"",A=c.model||"",z=c.template||"";f(M),D(C),I(A),N(z),T.current={draftName:"",draftScope:"user",description:M,agent:C,model:A,template:z}}},[c,h,e,i,l]);const U=o.useMemo(()=>{const M=T.current;return M?!!(h&&(m!==M.draftName||u!==M.draftScope)||g!==M.description||x!==M.agent||P!==M.model||L!==M.template):!1},[x,g,m,u,h,P,L]),K=async()=>{const M=h?m.trim().replace(/\s+/g,"-"):e?.trim();if(!M){_.error(s("settings.commands.sidebar.toast.commandNameRequired"));return}if(!L.trim()){_.error(s("settings.commands.page.toast.templateRequired"));return}if(h&&i.some(C=>C.name===M)){_.error(s("settings.commands.sidebar.toast.commandExists"));return}j(!0);try{const C=x.trim(),A=P.trim(),z=L.trim(),R={name:M,description:g.trim()||void 0,agent:C===""?null:C,model:A===""?null:A,template:z,scope:h?u:void 0};let Q;h?(Q=await a(R),Q&&d(null)):Q=await r(M,R),Q?_.success(s(h?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):_.error(s(h?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(C){console.error("Error saving command:",C),_.error(s("settings.commands.page.toast.saveUnexpectedError"))}finally{j(!1)}};return e?t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:h?s("settings.commands.page.title.new"):`/${e}`}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(h?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.identity")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[h&&t.jsxs("div",{"data-settings-item":"commands.name",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.commands.page.field.commandName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),t.jsx(Xe,{value:m,onChange:M=>p(M.target.value),placeholder:s("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(At,{value:u,onValueChange:M=>w(M),children:[t.jsx(Dt,{className:"w-fit min-w-[100px]",children:t.jsx(Ot,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Et,{align:"end",children:[t.jsx(mt,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(mt,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(us,{value:g,onChange:M=>f(M.target.value),placeholder:s("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.executionContext")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{"data-settings-item":"commands.agent",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.commands.page.field.overrideAgent")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(ic,{agentName:x,onChange:M=>D(M)})})]}),t.jsxs("div",{"data-settings-item":"commands.model",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(ja,{providerId:fn(P)?.providerId??"",modelId:fn(P)?.modelId??"",onChange:(M,C)=>{I(M&&C?`${M}/${C}`:"")}})})]})]})]}),t.jsxs("div",{"data-settings-item":"commands.template",className:"mb-2",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.template")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(us,{value:L,onChange:M=>N(M.target.value),placeholder:s("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),t.jsx("div",{className:"mt-2 px-2",children:t.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",s("settings.commands.page.templateHint.userInput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",s("settings.commands.page.templateHint.shellOutput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"@file"})," ",s("settings.commands.page.templateHint.fileContents")]})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(q,{onClick:K,disabled:b||!U,size:"xs",className:"!font-normal",children:s(b?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(E,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.commands.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.commands.page.empty.description")})]})})},Ro=s=>{switch(s){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Fo=s=>{const e=et.c(5),{tone:n,enabled:a}=s;if(!a){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let r;e[1]!==n?(r=ce("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[n]),e[1]=n,e[2]=r):r=e[2];let i;return e[3]!==r?(i=t.jsx("span",{className:r}),e[3]=r,e[4]=i):i=e[4],i},fg=s=>{const e=et.c(120),{onItemSelect:n}=s,{t:a}=st(),{mcpServers:r,selectedMcpName:i,setSelectedMcp:l,setMcpDraft:d,loadMcpConfigs:c,deleteMcp:h}=Zn(Ps(xg)),m=ws(yg);let p;e[0]!==m?(p=Ne=>Ne.getStatusForDirectory(m??null),e[0]=m,e[1]=p):p=e[1];const u=rs(p),w=rs(bg),g=rs(vg),[f,x]=o.useState(null),[D,P]=o.useState(!1),[I,L]=o.useState(null),[N,b]=o.useState(null),[j,T]=o.useState(!1);let U;e[2]!==r?(U=r.filter(jg),e[2]=r,e[3]=U):U=e[3];const K=U;let M;e[4]!==r?(M=r.filter(wg),e[4]=r,e[5]=M):M=e[5];const C=M;let A,z;e[6]!==c?(A=()=>{c()},z=[c],e[6]=c,e[7]=A,e[8]=z):(A=e[7],z=e[8]),o.useEffect(A,z);let R;e[9]!==m||e[10]!==g||e[11]!==j||e[12]!==w?(R=()=>{if(j)return;T(!0);const Ne=new Promise(Ng);Promise.all([w({directory:m,silent:!0}),Ne]).then(()=>{const He=g(m);He&&_.error(He)}).finally(()=>{T(!1)})},e[9]=m,e[10]=g,e[11]=j,e[12]=w,e[13]=R):R=e[13];const Q=R;let W;e[14]!==r||e[15]!==n||e[16]!==d||e[17]!==l?(W=()=>{let Ne="new-mcp-server",He=1;for(;r.some(v=>v.name===Ne);)Ne=`new-mcp-server-${He}`,He++;d({name:Ne,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),l(Ne),n?.()},e[14]=r,e[15]=n,e[16]=d,e[17]=l,e[18]=W):W=e[18];const te=W;let Y;e[19]!==h||e[20]!==f||e[21]!==a?(Y=async()=>{if(!f)return;P(!0);const Ne=await h(f.name);Ne.ok?Ne.reloadFailed?_.warning(Ne.message||`MCP server "${f.name}" deleted, but OpenCode reload failed`,{description:Ne.warning||a("settings.mcp.sidebar.toast.refreshListIfStale")}):_.success(Ne.message||a("settings.mcp.sidebar.toast.serverDeleted",{name:f.name})):_.error(a("settings.mcp.sidebar.toast.deleteFailed")),x(null),P(!1)},e[19]=h,e[20]=f,e[21]=a,e[22]=Y):Y=e[22];const k=Y;let $;e[23]!==a?($=(Ne,He)=>t.jsxs(He,{onClick:X=>{X.stopPropagation(),x(Ne)},className:"text-destructive focus:text-destructive",children:[t.jsx(E,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]}),e[23]=a,e[24]=$):$=e[24];const B=$;let F;e[25]===Symbol.for("react.memo_cache_sentinel")?(F=ce("flex h-full flex-col","bg-background"),e[25]=F):F=e[25];let O;e[26]!==a?(O=a("settings.mcp.sidebar.title"),e[26]=a,e[27]=O):O=e[27];let J;e[28]!==O?(J=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:O}),e[28]=O,e[29]=J):J=e[29];let H;e[30]!==a?(H=a("settings.mcp.sidebar.actions.refreshStatusAria"),e[30]=a,e[31]=H):H=e[31];let re;e[32]!==a?(re=a("settings.mcp.sidebar.actions.refreshStatusTitle"),e[32]=a,e[33]=re):re=e[33];const le=j&&"animate-spin";let ne;e[34]!==le?(ne=ce("h-4 w-4",le),e[34]=le,e[35]=ne):ne=e[35];let be;e[36]!==ne?(be=t.jsx(E,{name:"refresh",className:ne}),e[36]=ne,e[37]=be):be=e[37];let ae;e[38]!==Q||e[39]!==j||e[40]!==H||e[41]!==re||e[42]!==be?(ae=t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:j,onClick:Q,"aria-label":H,title:re,children:be}),e[38]=Q,e[39]=j,e[40]=H,e[41]=re,e[42]=be,e[43]=ae):ae=e[43];let ye;e[44]!==J||e[45]!==ae?(ye=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[J,ae]}),e[44]=J,e[45]=ae,e[46]=ye):ye=e[46];let ke;e[47]===Symbol.for("react.memo_cache_sentinel")?(ke=t.jsx(ka,{className:"mb-3"}),e[47]=ke):ke=e[47];let he;e[48]!==r.length||e[49]!==a?(he=a("settings.mcp.sidebar.total",{count:r.length}),e[48]=r.length,e[49]=a,e[50]=he):he=e[50];let we;e[51]!==he?(we=t.jsx("span",{className:"typography-meta text-muted-foreground",children:he}),e[51]=he,e[52]=we):we=e[52];let de;e[53]!==a?(de=a("settings.mcp.sidebar.actions.addServerTitle"),e[53]=a,e[54]=de):de=e[54];let Z;e[55]===Symbol.for("react.memo_cache_sentinel")?(Z=t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),e[55]=Z):Z=e[55];let se;e[56]!==te||e[57]!==de?(se=t.jsx(q,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:te,title:de,children:Z}),e[56]=te,e[57]=de,e[58]=se):se=e[58];let ve;e[59]!==we||e[60]!==se?(ve=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[we,se]}),e[59]=we,e[60]=se,e[61]=ve):ve=e[61];let G;e[62]!==ye||e[63]!==ve?(G=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ye,ke,ve]}),e[62]=ye,e[63]=ve,e[64]=G):G=e[64];let ee;e[65]!==r.length||e[66]!==u||e[67]!==n||e[68]!==I||e[69]!==K||e[70]!==B||e[71]!==N||e[72]!==i||e[73]!==d||e[74]!==l||e[75]!==a||e[76]!==C?(ee=t.jsx(_t,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:r.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(E,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.mcp.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.mcp.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[K.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.mcp.sidebar.group.projectServers")}),K.map(Ne=>{const He=u[Ne.name],X=Ro(He?.status),v=i===Ne.name,je=va();return t.jsxs(xn,{open:N===Ne.name,onOpenChange:Pe=>b(Pe?Ne.name:null),children:[t.jsxs(yn,{render:t.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",v?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:je?void 0:Pe=>{Pe.preventDefault(),b(Ne.name)}}),children:[t.jsxs("button",{onClick:()=>{l(Ne.name),d(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Fo,{tone:X,enabled:Ne.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ne.name}),t.jsx("span",{title:Ne.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Ne.type==="local"?t.jsx(E,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(E,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ne.type==="local"?Ne.command?.join(" ")??"":Ne.url??""})]}),t.jsxs(ds,{open:I===Ne.name,onOpenChange:Pe=>{Pe&&b(null),L(Pe?Ne.name:null)},children:[t.jsx(ls,{asChild:!0,children:t.jsx(q,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(E,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(cs,{align:"end",className:"w-fit min-w-20",children:B(Ne,Ns)})]})]}),t.jsx(bn,{className:"w-fit min-w-20",children:B(Ne,sn)})]},Ne.name)})]}),C.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.mcp.sidebar.group.userServers")}),C.map(Ne=>{const He=u[Ne.name],X=Ro(He?.status),v=i===Ne.name,je=va();return t.jsxs(xn,{open:N===Ne.name,onOpenChange:Pe=>b(Pe?Ne.name:null),children:[t.jsxs(yn,{render:t.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",v?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:je?void 0:Pe=>{Pe.preventDefault(),b(Ne.name)}}),children:[t.jsxs("button",{onClick:()=>{l(Ne.name),d(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Fo,{tone:X,enabled:Ne.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ne.name}),t.jsx("span",{title:Ne.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Ne.type==="local"?t.jsx(E,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(E,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ne.type==="local"?Ne.command?.join(" ")??"":Ne.url??""})]}),t.jsxs(ds,{open:I===Ne.name,onOpenChange:Pe=>{Pe&&b(null),L(Pe?Ne.name:null)},children:[t.jsx(ls,{asChild:!0,children:t.jsx(q,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(E,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(cs,{align:"end",className:"w-fit min-w-20",children:B(Ne,Ns)})]})]}),t.jsx(bn,{className:"w-fit min-w-20",children:B(Ne,sn)})]},Ne.name)})]})]})}),e[65]=r.length,e[66]=u,e[67]=n,e[68]=I,e[69]=K,e[70]=B,e[71]=N,e[72]=i,e[73]=d,e[74]=l,e[75]=a,e[76]=C,e[77]=ee):ee=e[77];const ie=f!==null;let pe;e[78]!==D?(pe=Ne=>{!Ne&&!D&&x(null)},e[78]=D,e[79]=pe):pe=e[79];let Ae;e[80]!==a?(Ae=a("settings.mcp.sidebar.deleteDialog.title"),e[80]=a,e[81]=Ae):Ae=e[81];let Se;e[82]!==Ae?(Se=t.jsx(zt,{children:Ae}),e[82]=Ae,e[83]=Se):Se=e[83];const De=f?.name||"";let Me;e[84]!==a||e[85]!==De?(Me=a("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:De}),e[84]=a,e[85]=De,e[86]=Me):Me=e[86];let Te;e[87]===Symbol.for("react.memo_cache_sentinel")?(Te=t.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[87]=Te):Te=e[87];let Be;e[88]!==Me?(Be=t.jsxs($t,{children:[Me," ",Te,"."]}),e[88]=Me,e[89]=Be):Be=e[89];let ze;e[90]!==Se||e[91]!==Be?(ze=t.jsxs(Kt,{children:[Se,Be]}),e[90]=Se,e[91]=Be,e[92]=ze):ze=e[92];let Oe;e[93]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>x(null),e[93]=Oe):Oe=e[93];let $e;e[94]!==a?($e=a("settings.common.actions.cancel"),e[94]=a,e[95]=$e):$e=e[95];let Ke;e[96]!==D||e[97]!==$e?(Ke=t.jsx(q,{size:"sm",variant:"ghost",onClick:Oe,disabled:D,children:$e}),e[96]=D,e[97]=$e,e[98]=Ke):Ke=e[98];let Ye;e[99]!==D||e[100]!==a?(Ye=a(D?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[99]=D,e[100]=a,e[101]=Ye):Ye=e[101];let Re;e[102]!==k||e[103]!==D||e[104]!==Ye?(Re=t.jsx(q,{size:"sm",onClick:k,disabled:D,children:Ye}),e[102]=k,e[103]=D,e[104]=Ye,e[105]=Re):Re=e[105];let V;e[106]!==Ke||e[107]!==Re?(V=t.jsxs(Gt,{children:[Ke,Re]}),e[106]=Ke,e[107]=Re,e[108]=V):V=e[108];let oe;e[109]!==ze||e[110]!==V?(oe=t.jsxs(Ft,{className:"max-w-md",children:[ze,V]}),e[109]=ze,e[110]=V,e[111]=oe):oe=e[111];let ge;e[112]!==ie||e[113]!==pe||e[114]!==oe?(ge=t.jsx(Rt,{open:ie,onOpenChange:pe,children:oe}),e[112]=ie,e[113]=pe,e[114]=oe,e[115]=ge):ge=e[115];let Fe;return e[116]!==G||e[117]!==ee||e[118]!==ge?(Fe=t.jsxs("div",{className:F,children:[G,ee,ge]}),e[116]=G,e[117]=ee,e[118]=ge,e[119]=Fe):Fe=e[119],Fe};function xg(s){return{mcpServers:s.mcpServers,selectedMcpName:s.selectedMcpName,setSelectedMcp:s.setSelectedMcp,setMcpDraft:s.setMcpDraft,loadMcpConfigs:s.loadMcpConfigs,deleteMcp:s.deleteMcp}}function yg(s){return s.currentDirectory}function bg(s){return s.refresh}function vg(s){return s.getErrorForDirectory}function jg(s){return s.scope==="project"}function wg(s){return s.scope!=="project"}function Ng(s){return setTimeout(s,500)}function $s(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function ua(s){return Array.isArray(s)&&s.every(e=>typeof e=="string")}function Us(s,e){return e!==void 0?{ok:!1,error:s,parsed:e}:{ok:!1,error:s}}function Fa(s,e,n){const a=kg(n),r=typeof n.url=="string"?n.url.trim():"",i=Lo(n,"env","environment"),l=Lo(n,"headers"),d=Sg(n),c=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",h=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",m=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",u=Cg(n),w=Ig(n);return{ok:!0,name:s,type:e,command:a,url:r,environment:i,headers:l,oauthEnabled:d,oauthClientId:c,oauthClientSecret:h,oauthScope:m,oauthRedirectUri:p,timeout:u,enabled:w}}function kg(s){const e=s.command,n=s.args;if(ua(e)&&ua(n))return[...e,...n];if(ua(e))return e;if(typeof e=="string"&&e.trim()){const a=e.trim().split(/\s+/);return ua(n)?[...a,...n]:a}return ua(n)?n:[]}function Lo(s,...e){for(const n of e){const a=s[n];if(!$s(a))continue;const r=Object.entries(a).filter(([i,l])=>i&&typeof l=="string");if(r.length>0)return r.map(([i,l])=>({key:i,value:String(l)}))}return[]}function Sg(s){if(s.oauth===!1||s.oauth===null||s.oauth===void 0||!$s(s.oauth))return!1;const e=s.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function Cg(s){const e=s.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const n=Number(e);if(Number.isFinite(n)&&n>0)return String(Math.floor(n))}return""}function Ig(s){return"disabled"in s&&s.disabled===!0?!1:"enabled"in s?!!s.enabled:!0}function Pg(s){const e=s.mcpServers;if($s(e)){const a=Object.keys(e);if(a.length===1){const r=a[0],i=e[r];if($s(i))return{name:r,entry:i}}if(a.length>1)return null}const n=Object.keys(s).filter(a=>{const r=s[a];return a!=="mcpServers"&&$s(r)});if(n.length===1){const a=n[0],r=s[a];if(kc(r))return{name:a,entry:r}}return null}function kc(s){return s.type==="local"||s.type==="remote"||Array.isArray(s.command)||typeof s.url=="string"||Array.isArray(s.args)}function Ag(s,e){let n;try{const d=s.trim();if(!d)return Us("No JSON content provided");n=JSON.parse(d)}catch(d){return Us(d instanceof Error?`Invalid JSON: ${d.message}`:"Invalid JSON")}if(!$s(n))return Us("Expected a JSON object, not an array or primitive");const a=n,r=a.mcpServers;if($s(r)){const d=Object.keys(r);if(d.length===0)return Us("mcpServers object is empty",n);if(d.length>1)return Us("Paste one server at a time. Found "+d.length+" servers in mcpServers",n);const c=d[0],h=r[c];return $s(h)?Fa(c,La(h),h):Us("Server entry is not a valid object",n)}const i=a.mcp;if($s(i)){const d=Object.keys(i);if(d.length===0)return Us("mcp object is empty",n);if(d.length>1)return Us("Paste one server at a time. Found "+d.length+" servers in mcp",n);const c=d[0],h=i[c];return $s(h)?Fa(c,La(h),h):Us("Server entry in mcp is not a valid object",n)}const l=Pg(a);if(l)return Fa(l.name,La(l.entry),l.entry);if(kc(a)){const d=La(a),c=typeof a.name=="string"&&a.name.trim()?a.name.trim():e?.fallbackName;return Fa(c,d,a)}return Us("No recognizable MCP server configuration found in JSON",n)}function La(s){return s.type==="remote"?"remote":s.type==="local"?"local":typeof s.url=="string"&&s.url.trim()?"remote":(Array.isArray(s.command)||typeof s.command=="string"||Array.isArray(s.args),"local")}function Dg(s,e,n){const a=n?.isNewServer??!1,r=s.name,i=a&&r?r:e.name??"";return{...e,name:i,type:s.type,command:s.type==="local"?s.command:[],url:s.type==="remote"?s.url:"",environment:s.environment,headers:s.type==="remote"?s.headers:[],oauthEnabled:s.type==="remote"?s.oauthEnabled:!1,oauthClientId:s.type==="remote"?s.oauthClientId:"",oauthClientSecret:s.type==="remote"?s.oauthClientSecret:"",oauthScope:s.type==="remote"?s.oauthScope:"",oauthRedirectUri:s.type==="remote"?s.oauthRedirectUri:"",timeout:s.type==="remote"?s.timeout:"",enabled:s.enabled}}const Eg="/mcp/oauth/callback",Mg=s=>{if(typeof window>"u")return null;try{const e=s.replace(/-/g,"+").replace(/_/g,"/"),n=e.length%4===0?"":"=".repeat(4-e.length%4),a=window.atob(e+n),r=Uint8Array.from(a,i=>i.charCodeAt(0));return new TextDecoder().decode(r)}catch{return null}},Tg=s=>{const e=Rg(s.get("state"));if(e)return e;const n=s.get("server");if(typeof n!="string"||!n.trim())return null;const a=s.get("directory");return{name:n.trim(),directory:typeof a=="string"&&a.trim()?a.trim():null}},Sc=s=>{const e=s.get("state");return typeof e!="string"?null:e.trim()||null},Rg=s=>{if(typeof s!="string"||!s.trim())return null;const e=Mg(s.trim());if(!e)return null;try{const n=JSON.parse(e);return n?.v!==1||typeof n.n!="string"||!n.n.trim()?null:{name:n.n.trim(),directory:typeof n.d=="string"&&n.d.trim()?n.d.trim():null}}catch{return null}},Mn=yd,Tn=s=>{const e=et.c(14);let n,a,r,i;e[0]!==s?({className:r,asChild:n,children:a,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i):(n=e[1],a=e[2],r=e[3],i=e[4]);let l;e[5]!==n||e[6]!==a?(l=n&&xe.isValidElement(a)?{render:a}:{children:a},e[5]=n,e[6]=a,e[7]=l):l=e[7];const d=l;let c;e[8]!==r?(c=ce("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",r),e[8]=r,e[9]=c):c=e[9];let h;return e[10]!==i||e[11]!==d||e[12]!==c?(h=t.jsx(xd,{className:c,...i,...d}),e[10]=i,e[11]=d,e[12]=c,e[13]=h):h=e[13],h},Rn=s=>{const e=et.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=ce("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(bd,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i};function Fg(s){const e=[];let n="",a=!1,r=!1;for(let i=0;i<s.length;i++){const l=s[i];if(l==="'"&&!r){a=!a;continue}if(l==='"'&&!a){r=!r;continue}if((l===" "||l===" ")&&!a&&!r){n&&(e.push(n),n="");continue}n+=l}return n&&e.push(n),e}function Lg(s){const e=s.trim();if(!e)return{code:null,context:null,stateKey:null};try{const n=new URL(e),a=n.searchParams.get("code");if(typeof a=="string"&&a.trim())return{code:a.trim(),context:Tg(n.searchParams),stateKey:Sc(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Og=({value:s,onChange:e,pasteCommandTitle:n,pasteCommandLabel:a,pasteSuccess:r,clipboardReadFailed:i,preview:l})=>{const[d,c]=o.useState(()=>s.join(`
|
|
4
|
+
`)),h=o.useRef(s);o.useEffect(()=>{JSON.stringify(h.current)!==JSON.stringify(s)&&(h.current=s,c(s.join(`
|
|
5
|
+
`)))},[s]);const m=u=>{const w=u.split(`
|
|
6
|
+
`).filter(g=>g.trim().length>0);e(w)},p=async()=>{try{const w=(await navigator.clipboard.readText()).trim(),g=w.includes(`
|
|
7
|
+
`)?w.split(`
|
|
8
|
+
`).filter(f=>f.trim()):Fg(w);c(g.join(`
|
|
9
|
+
`)),e(g),_.success(r(g.length))}catch{_.error(i)}};return t.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[t.jsx("div",{className:"flex items-center justify-end gap-2",children:t.jsxs(q,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:p,type:"button",title:n,children:[t.jsx(E,{name:"clipboard",className:"h-3 w-3"}),a]})}),t.jsx(us,{value:d,onChange:u=>{c(u.target.value),m(u.target.value)},onBlur:()=>{const u=d.split(`
|
|
10
|
+
`).map(w=>w.trimEnd()).join(`
|
|
11
|
+
`);c(u),m(u)},placeholder:`npx
|
|
12
|
+
-y
|
|
13
|
+
@modelcontextprotocol/server-postgres
|
|
14
|
+
postgresql://user:pass@host/db`,rows:Math.max(4,s.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),s.length>0&&t.jsxs("details",{className:"group",children:[t.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:l(s.length)}),t.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:t.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:s.map((u,w)=>t.jsxs("span",{className:"block",children:[t.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",w,"]"]}),u]},w))})})]})]})},zg=s=>s.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Oo=({value:s,onChange:e,keyTransform:n=zg,keyPlaceholder:a="API_KEY",keyInputClassName:r="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:d,importSuccess:c,clipboardReadFailed:h,keyLabel:m,valueLabel:p,valuePlaceholder:u,hideValueTitle:w,showValueTitle:g,addVariable:f,plainTextWarning:x,removeVariableAria:D})=>{const[P,I]=o.useState(new Set),L=()=>e([...s,{key:"",value:""}]),N=K=>{e(s.filter((M,C)=>C!==K)),I(M=>{const C=new Set(M);return C.delete(K),C})},b=(K,M,C)=>{const A=[...s];A[K]={...A[K],[M]:C},e(A)},j=K=>{I(M=>{const C=new Set(M);return C.has(K)?C.delete(K):C.add(K),C})},T=async()=>{try{const K=await navigator.clipboard.readText(),M=[];for(const A of K.split(`
|
|
15
|
+
`)){const z=A.trim();if(!z||z.startsWith("#"))continue;const R=z.indexOf("=");if(R===-1)continue;const Q=z.slice(0,R).trim();let W=z.slice(R+1).trim();(W.startsWith('"')&&W.endsWith('"')||W.startsWith("'")&&W.endsWith("'"))&&(W=W.slice(1,-1)),Q&&M.push({key:Q,value:W})}if(M.length===0){_.error(d);return}const C=[...s];for(const A of M){const z=C.findIndex(R=>R.key===A.key);z!==-1?C[z]=A:C.push(A)}e(C),_.success(c(M.length))}catch{_.error(h)}},U=s.some(K=>K.value.length>0);return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:p})]}),t.jsxs(q,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:T,type:"button",title:l,children:[t.jsx(E,{name:"clipboard",className:"h-3 w-3"}),i]})]}),t.jsx("div",{className:"space-y-1.5",children:s.map((K,M)=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xe,{value:K.key,onChange:C=>b(M,"key",n(C.target.value)),placeholder:a,className:r,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),t.jsxs("div",{className:"relative flex-1 flex items-center",children:[t.jsx(Xe,{type:P.has(M)?"text":"password",value:K.value,onChange:C=>b(M,"value",C.target.value),placeholder:u,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),t.jsx("button",{type:"button",onClick:()=>j(M),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:P.has(M)?w:g,children:P.has(M)?t.jsx(E,{name:"eye-off",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"eye",className:"h-3.5 w-3.5"})})]}),t.jsx(q,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>N(M),"aria-label":D,children:t.jsx(E,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},M))}),t.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:L,type:"button",children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),f]}),U&&t.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},zo=s=>{const e=et.c(14),{status:n,enabled:a,getStatusLabel:r,variant:i}=s,l=i===void 0?"compact":i;if(!a||!n)return null;let d,c;if(e[0]!==r||e[1]!==n||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const u={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[n]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const w=ce("typography-micro font-medium rounded-full px-2 py-0.5",u.text,u.bg);let g;e[5]!==r||e[6]!==n?(g=r(n),e[5]=r,e[6]=n,e[7]=g):g=e[7],c=t.jsxs("span",{className:w,children:["● ",g]});break e}d=ce("typography-micro font-medium",u.text)}e[0]=r,e[1]=n,e[2]=l,e[3]=d,e[4]=c}else d=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let h;e[8]!==r||e[9]!==n?(h=r(n),e[8]=r,e[9]=n,e[10]=h):h=e[10];let m;return e[11]!==d||e[12]!==h?(m=t.jsxs("span",{className:d,children:["● ",h]}),e[11]=d,e[12]=h,e[13]=m):m=e[13],m},Kg=(s,e,n)=>{switch(s){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return n?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return n?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},Ug=s=>{switch(s){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Bg=(s,e,n,a)=>!!(s==="failed"||s==="needs_auth"||s==="needs_client_registration"||e||n||a),Ko=(s,e)=>{if(typeof window>"u")return null;const n=new URL(Eg,sa()||window.location.origin);return typeof s=="string"&&s.trim()&&n.searchParams.set("server",s.trim()),typeof e=="string"&&e.trim()&&n.searchParams.set("directory",e.trim()),n.toString()},$g=async s=>{const e=await ct("/api/mcp/auth/pending",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:s.state,name:s.name,directory:typeof s.directory=="string"&&s.directory.trim()?s.directory.trim():null})});if(!e.ok){const n=await e.json().catch(()=>null);throw new Error(n?.error||"Failed to prepare MCP authorization callback")}},Vg=async s=>{const e=await ct(`/api/mcp/auth/pending?state=${encodeURIComponent(s)}`);if(!e.ok)return null;const n=await e.json().catch(()=>null);return n?.name?.trim()?{name:n.name.trim(),directory:typeof n.directory=="string"&&n.directory.trim()?n.directory.trim():null}:null},ma=async s=>{typeof s!="string"||!s.trim()||await ct(`/api/mcp/auth/pending?state=${encodeURIComponent(s.trim())}`,{method:"DELETE"}).catch(()=>{})},Or=(s,e,n)=>{const a=s instanceof Error?s.message:e;return/oauth state required/i.test(a)?n("settings.mcp.page.toast.authSessionExpired"):a},_g=(s,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${s??"__none__"}::${n}`},Hg=()=>{const{t:s}=st(),e=o.useCallback((Ce,jt)=>s(Ce,jt),[s]),{selectedMcpName:n,mcpServers:a,mcpDraft:r,setMcpDraft:i,setSelectedMcp:l,getMcpByName:d,createMcp:c,updateMcp:h,deleteMcp:m}=Zn(Ps(Ce=>({selectedMcpName:Ce.selectedMcpName,mcpServers:Ce.mcpServers,mcpDraft:Ce.mcpDraft,setMcpDraft:Ce.setMcpDraft,setSelectedMcp:Ce.setSelectedMcp,getMcpByName:Ce.getMcpByName,createMcp:Ce.createMcp,updateMcp:Ce.updateMcp,deleteMcp:Ce.deleteMcp}))),p=ws(Ce=>Ce.currentDirectory),u=o.useMemo(()=>ms(),[]),w=rs(Ce=>Ce.getStatusForDirectory(p??null)),g=rs(Ce=>Ce.getDiagnosticForDirectory(p??null)),f=rs(Ce=>Ce.refresh),x=rs(Ce=>Ce.connect),D=rs(Ce=>Ce.disconnect),P=rs(Ce=>Ce.startAuth),I=rs(Ce=>Ce.completeAuth),L=rs(Ce=>Ce.clearAuth),N=rs(Ce=>Ce.testConnection),b=n?d(n):null,j=!!(r&&r.name===n&&!b),[T,U]=o.useState(""),[K,M]=o.useState("user"),[C,A]=o.useState("local"),[z,R]=o.useState([]),[Q,W]=o.useState(""),[te,Y]=o.useState([]),[k,$]=o.useState([]),[B,F]=o.useState(!0),[O,J]=o.useState(""),[H,re]=o.useState(""),[le,ne]=o.useState(""),[be,ae]=o.useState(""),[ye,ke]=o.useState(""),[he,we]=o.useState(!0),[de,Z]=o.useState(!1),[se,ve]=o.useState(!1),[G,ee]=o.useState(!1),[ie,pe]=o.useState(!1),[Ae,Se]=o.useState(!1),[De,Me]=o.useState(!1),[Te,Be]=o.useState(!1),[ze,Oe]=o.useState(!1),[$e,Ke]=o.useState(null),[Ye,Re]=o.useState(null),[V,oe]=o.useState(""),[ge,Fe]=o.useState(!1),Ne=o.useRef(0),He=o.useRef(!1),[X,v]=o.useState(!1),[je,Pe]=o.useState(!1),[Le,qe]=o.useState(""),[rt,ot]=o.useState(null),it=o.useMemo(()=>_g(n,p),[p,n]),dt=o.useRef(it),Je=o.useRef(null),_e=o.useCallback(()=>{Ke(null),Re(null),oe(""),Fe(!1),Ne.current=0,Oe(!1),Se(!1),Me(!1),He.current=!1},[]),gt=o.useCallback(()=>{qe(""),ot(null),Pe(!0)},[]),fe=o.useCallback(async()=>{try{const Ce=await navigator.clipboard.readText();qe(Ce),ot(null)}catch{_.error(s("settings.mcp.page.toast.clipboardReadFailed"))}},[s]),tt=o.useCallback(()=>{const Ce=Ag(Le,{fallbackName:T});if(!Ce.ok){ot(Ce.error);return}const vt=Dg(Ce,{name:T,scope:K,type:C,command:z,url:Q,environment:te,headers:k,oauthEnabled:B,oauthClientId:O,oauthClientSecret:H,oauthScope:le,oauthRedirectUri:be,timeout:ye,enabled:he},{isNewServer:j});U(vt.name),A(vt.type),R(vt.command??[]),W(vt.url??""),Y(vt.environment??[]),$(vt.headers??[]),F(vt.oauthEnabled??!1),J(vt.oauthClientId??""),re(vt.oauthClientSecret??""),ne(vt.oauthScope??""),ae(vt.oauthRedirectUri??""),ke(vt.timeout??""),we(vt.enabled??!0),Pe(!1),qe(""),ot(null),_.success(s("settings.mcp.page.toast.configImported"))},[Le,T,K,C,z,Q,te,k,B,O,H,le,be,ye,he,j,s]);o.useEffect(()=>{if(j&&r){U(r.name),M(r.scope||"user"),A(r.type),R(r.command),W(r.url),Y(r.environment),$(r.headers),F(r.oauthEnabled),J(r.oauthClientId),re(r.oauthClientSecret),ne(r.oauthScope),ae(r.oauthRedirectUri),ke(r.timeout),we(r.enabled),v(!1),Je.current={mcpType:r.type,command:r.command,url:r.url,envEntries:r.environment,headerEntries:r.headers,oauthEnabled:r.oauthEnabled,oauthClientId:r.oauthClientId,oauthClientSecret:r.oauthClientSecret,oauthScope:r.oauthScope,oauthRedirectUri:r.oauthRedirectUri,timeout:r.timeout,enabled:r.enabled};return}if(b){M(b.scope==="project"?"project":"user");const Ce=xo(b.environment),jt=b.type==="remote"?b:null,vt=xo(jt?.headers),Ht=jt?.oauth,qt=Ht&&typeof Ht=="object"?Ht:null,Vt=Ht!==!1,ps=b.type,vs=ps==="local"?b.command??[]:[],Jt=ps==="remote"?b.url??"":"",Es=typeof jt?.timeout=="number"&&Number.isFinite(jt.timeout)?String(jt.timeout):"";A(ps),R(vs),W(Jt),Y(Ce),$(vt),F(Vt),J(Vt?qt?.clientId??"":""),re(Vt?qt?.clientSecret??"":""),ne(Vt?qt?.scope??"":""),ae(Vt?qt?.redirectUri??"":""),ke(Es),we(b.enabled),v(!1),Je.current={mcpType:ps,command:vs,url:Jt,envEntries:Ce,headerEntries:vt,oauthEnabled:Vt,oauthClientId:Vt?qt?.clientId??"":"",oauthClientSecret:Vt?qt?.clientSecret??"":"",oauthScope:Vt?qt?.scope??"":"",oauthRedirectUri:Vt?qt?.redirectUri??"":"",timeout:Es,enabled:b.enabled}}},[b,j,r]);const nt=o.useMemo(()=>{const Ce=Je.current;return Ce?C!==Ce.mcpType||he!==Ce.enabled||JSON.stringify(z)!==JSON.stringify(Ce.command)||Q!==Ce.url||JSON.stringify(te)!==JSON.stringify(Ce.envEntries)||JSON.stringify(k)!==JSON.stringify(Ce.headerEntries)||B!==Ce.oauthEnabled||O!==Ce.oauthClientId||H!==Ce.oauthClientSecret||le!==Ce.oauthScope||be!==Ce.oauthRedirectUri||ye!==Ce.timeout:!1},[C,z,Q,te,k,B,O,H,le,be,ye,he]),Ze=async()=>{const Ce=j?T.trim():n??"";if(!Ce){_.error(s("settings.mcp.page.toast.nameRequired"));return}if(j&&a.some(vt=>vt.name===Ce)){_.error(s("settings.mcp.page.toast.serverNameExists"));return}if(C==="local"&&z.filter(Boolean).length===0){_.error(s("settings.mcp.page.toast.localCommandRequired"));return}if(C==="remote"&&!Q.trim()){_.error(s("settings.mcp.page.toast.remoteUrlRequired"));return}const jt={name:Ce,scope:K,type:C,command:z,url:Q,environment:te,headers:k,oauthEnabled:B,oauthClientId:O,oauthClientSecret:H,oauthScope:le,oauthRedirectUri:be,timeout:ye,enabled:he};Z(!0);try{const vt=j?await c(jt):await h(Ce,jt);vt.ok?(await ma(Ye),_e(),j&&(i(null),l(Ce)),await f({directory:p,silent:!0}),vt.reloadFailed?_.warning(vt.message||s(j?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:vt.warning||s("settings.mcp.page.toast.retryRefreshHint")}):_.success(vt.message||s(j?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):_.error(s("settings.mcp.page.toast.saveFailed"))}catch(vt){_.error(vt instanceof Error?vt.message:s("settings.mcp.page.toast.unexpectedError"))}finally{Z(!1)}},ft=async()=>{if(!n)return;ee(!0);const Ce=await m(n);Ce.ok?(await ma(Ye),_e(),Ce.reloadFailed?_.warning(Ce.message||s("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Ce.warning||s("settings.mcp.page.toast.refreshListIfStale")}):_.success(Ce.message||s("settings.mcp.page.toast.serverDeleted",{name:n})),ve(!1)):_.error(s("settings.mcp.page.toast.deleteFailed")),ee(!1)},bt=async()=>{if(n){pe(!0);try{if(w[n]?.status==="connected")await D(n,p),_.success(s("settings.mcp.page.toast.disconnected"));else{await x(n,p),await f({directory:p,silent:!0});const jt=rs.getState().getStatusForDirectory(p??null)[n];jt?.status==="connected"?_.success(s("settings.mcp.page.toast.connected")):jt?.status==="needs_auth"?_.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):jt?.status==="needs_client_registration"?_.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):jt?.status==="failed"?_.error(jt.error||s("settings.mcp.page.toast.connectionFailed")):_.message(s("settings.mcp.page.toast.connectionAttemptFinished"));return}await f({directory:p,silent:!0})}catch(Ce){_.error(Ce instanceof Error?Ce.message:s("settings.mcp.page.toast.connectionFailed"))}finally{pe(!1)}}},Mt=o.useCallback(()=>j?(_.error(s("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):nt?(_.error(s("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[nt,j,s]),ue=o.useCallback(async(Ce=!1)=>{try{await f({directory:p,silent:Ce})}catch(jt){Ce||_.error(jt instanceof Error?jt.message:s("settings.mcp.page.toast.refreshStatusFailed"))}},[p,f,s]);o.useEffect(()=>{ue(!0)},[ue]),o.useEffect(()=>{dt.current=it,pe(!1),Be(!1),_e()},[_e,it]);const Ve=o.useCallback(async()=>{if(!n||C!=="remote"||!Mt())return;Se(!0);const Ce=it;let jt=null;try{const vt=rs.getState().getStatusForDirectory(p??null)[n]?.status;He.current=vt==="needs_auth"||vt==="needs_client_registration";const Ht=Ko(n,p);if(!Ht)throw new Error(s("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!be.trim()&&!u){const vs=await h(n,{oauthEnabled:B,oauthClientId:O,oauthClientSecret:H,oauthScope:le,oauthRedirectUri:Ht});if(!vs.ok)throw new Error(s("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(vs.reloadFailed)throw new Error(vs.warning||vs.message||s("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(dt.current!==Ce)return;ae(Ht),Je.current=Je.current?{...Je.current,oauthRedirectUri:Ht}:Je.current}const qt=await P(n,p),Vt=Sc(new URL(qt).searchParams);if(Vt&&(jt=Vt,await $g({state:Vt,name:n,directory:p})),dt.current!==Ce)return;Ke(qt),Re(Vt??null),Fe(!0),Ne.current=0;const ps=await tn(qt);if(dt.current!==Ce)return;ps?_.message(s(u?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):_.error(s("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(vt){await ma(jt),dt.current===Ce&&_.error(Or(vt,s("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{dt.current===Ce&&Se(!1)}},[p,u,C,O,H,B,be,le,Mt,it,n,P,s,e,h]),Qe=o.useCallback(async()=>{if(!n||!Mt())return;Me(!0);const Ce=it;try{if(await L(n,p),dt.current!==Ce)return;Ke(null),Re(null),oe(""),Fe(!1),Ne.current=0,await ma(Ye),_.success(s("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(jt){dt.current===Ce&&_.error(Or(jt,s("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{dt.current===Ce&&Me(!1)}},[Ye,L,p,Mt,it,n,s,e]),Ge=o.useCallback(async()=>{if(!$e)return;if((await En($e)).ok){_.success(s("settings.mcp.page.toast.authorizationUrlCopied"));return}_.error(s("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[$e,s]),xt=o.useCallback(async()=>{const Ce=Lg(V);if(!Ce.code){_.error(s("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const jt=Ce.stateKey?await Vg(Ce.stateKey):null,vt=Ce.context??jt,Ht=vt?.name??n,qt=vt?.directory??p;if(!Ht){_.error(s("settings.mcp.page.toast.missingServerDetails"));return}if(!vt&&!Mt())return;Oe(!0);const Vt=it;try{if(await I(Ht,Ce.code,qt),await ma(Ce.stateKey??Ye),dt.current!==Vt)return;oe(""),Ke(null),Re(null),Fe(!1),Ne.current=0,_.success(Ht===n?s("settings.mcp.page.toast.authorizationCompleted"):s("settings.mcp.page.toast.authorizationCompletedFor",{name:Ht}))}catch(ps){dt.current===Vt&&_.error(Or(ps,s("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{dt.current===Vt&&Oe(!1)}},[V,Ye,I,p,Mt,it,n,s,e]),kt=o.useCallback(async()=>{if(!(!n||!Mt())){if(!he){_.error(s("settings.mcp.page.toast.enableServerBeforeTest"));return}Be(!0);try{const Ce=await N(n,p),jt=Ce.status?.status;Ce.warning?_.warning(Ce.warning):jt==="connected"?_.success(s("settings.mcp.page.toast.connectionTestSucceeded")):jt==="needs_auth"?_.message(s("settings.mcp.page.toast.connectionNeedsAuthorization")):jt==="needs_client_registration"?_.message(s("settings.mcp.page.toast.connectionNeedsClientRegistration")):jt==="failed"?_.error(Ce.status?.error||Ce.error||s("settings.mcp.page.toast.connectionTestFailed")):Ce.error?_.error(Ce.error):_.message(s("settings.mcp.page.toast.connectionTestFinished"))}catch(Ce){_.error(Ce instanceof Error?Ce.message:s("settings.mcp.page.toast.connectionTestFailed"))}finally{Be(!1)}}},[p,he,Mt,n,s,N]);if(o.useEffect(()=>{if(!ge||!n)return;const Ce=window.setInterval(()=>{(async()=>{Ne.current+=1,await f({directory:p,silent:!0});const jt=rs.getState().getStatusForDirectory(p??null)[n];if(jt){if(He.current&&jt.status!=="needs_auth"&&jt.status!=="needs_client_registration"){Fe(!1),Ne.current=0,He.current=!1,Ke(null),oe(""),jt.status==="connected"&&_.success(s("settings.mcp.page.toast.authorizationCompleted"));return}if(!He.current&&jt.status==="failed"){Fe(!1),Ne.current=0,He.current=!1,_.error(jt.error||s("settings.mcp.page.toast.authorizationFailed"));return}Ne.current>=30&&(Fe(!1),Ne.current=0,He.current=!1,_.message(s("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Ce)}},[p,ge,f,n,s]),!n)return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(E,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.mcp.page.empty.selectServer")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.mcp.page.empty.addNewOne")})]})});const ht=w[n],Pt=n?g[n]:void 0,Wt=ht??Pt,ts=ht?.status==="connected",bs=ht?.status==="needs_auth"||ht?.status==="needs_client_registration",ks=u?null:Ko(n,p),Yt=Kg(Wt?.status,e,Wt&&"error"in Wt?Wt.error:void 0),Ss=Ce=>{switch(Ce){case"connected":return s("settings.mcp.page.status.label.connected");case"failed":return s("settings.mcp.page.status.label.failed");case"needs_auth":return s("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return s("settings.mcp.page.status.label.needsRegistration");default:return Ce}};return t.jsxs(_t,{outerClassName:"h-full",className:"w-full",children:[t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4",children:t.jsxs("div",{className:"min-w-0",children:[j?t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:s("settings.mcp.page.header.newServer")}):t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:n}),t.jsx(zo,{status:Wt?.status,enabled:he,getStatusLabel:Ss,variant:"pill"})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:j?s("settings.mcp.page.header.configureNewServer"):s("settings.mcp.page.header.transport",{type:s(C==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!j&&t.jsxs(t.Fragment,{children:[t.jsx(q,{variant:ts?"outline":"default",size:"xs",className:"!font-normal",onClick:bt,disabled:ie||!he,children:s(ie?"settings.mcp.page.actions.working":ts?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),C==="remote"&&t.jsxs(t.Fragment,{children:[t.jsx(q,{variant:bs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{Ve()},disabled:Ae||!he,children:s(Ae?"settings.mcp.page.actions.starting":bs?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),t.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{Qe()},disabled:De||!he,children:s(De?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),ts&&t.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{kt()},disabled:Te||!he,children:s(Te?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!j&&Bg(Wt?.status,$e,bs,ge)&&t.jsx("div",{className:"mb-6 px-2",children:t.jsxs("div",{className:ce("rounded-lg border p-3",Ug(Wt?.status)),children:[t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"min-w-0 space-y-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.status.runtimeStatus")}),t.jsx(zo,{status:Wt?.status,enabled:he,getStatusLabel:Ss})]}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:Yt}),t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:K==="project"?s("settings.mcp.page.status.projectScopedTo",{directory:p??s("settings.mcp.page.status.activeProject")}):s("settings.mcp.page.status.userScoped")})]}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!ts&&t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{kt()},disabled:Te||!he,children:s(Te?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),$e&&t.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.authorizationUrl")}),t.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:$e}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{tn($e)},children:[t.jsx(E,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.mcp.page.actions.openInBrowser")]}),t.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ge()},children:[t.jsx(E,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.actions.copyLink")]})]})]})}),C==="remote"&&(bs||ge||$e)&&t.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.auth.manualFallbackTitle")}),t.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.manualFallbackDescription")})]}),t.jsx(us,{value:V,onChange:Ce=>oe(Ce.target.value),placeholder:s("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{xt()},disabled:ze,children:s(ze?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),ge&&t.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:s("settings.mcp.page.auth.waitingForOpenCode")})]})}),t.jsxs("div",{"data-settings-item":"mcp.server",className:"mb-6",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.mcp.page.server.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[j&&t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.server.name")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsx(Xe,{value:T,onChange:Ce=>U(Ce.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:s("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 font-mono px-2",autoFocus:!0}),t.jsxs(At,{value:K,onValueChange:Ce=>M(Ce),children:[t.jsx(Dt,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:s(K==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:K==="user"?t.jsx(E,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"folder",className:"h-3.5 w-3.5"})}),t.jsxs(Et,{align:"end",children:[t.jsx(mt,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(mt,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),j&&t.jsx("div",{className:"py-1.5",children:t.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:gt,type:"button",title:s("settings.mcp.page.server.importJsonTitle"),children:[t.jsx(E,{name:"file-code",className:"h-3.5 w-3.5"}),s("settings.mcp.page.server.importJson")]})}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":he,onClick:()=>we(!he),onKeyDown:Ce=>{(Ce.key===" "||Ce.key==="Enter")&&(Ce.preventDefault(),we(!he))},children:[t.jsx(yt,{checked:he,onChange:we,ariaLabel:s("settings.mcp.page.server.enableAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.server.enable")})]}),t.jsx("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:t.jsxs("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.server.transportMode")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(q,{variant:"chip",size:"xs","aria-pressed":C==="local",onClick:()=>A("local"),className:"!font-normal",children:s("settings.mcp.page.transport.local")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":C==="remote",onClick:()=>A("remote"),className:"!font-normal",children:s("settings.mcp.page.transport.remote")})]})]})})]})]}),t.jsxs("div",{"data-settings-item":"mcp.command",className:"mb-6",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s(C==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:C==="local"?t.jsx(Og,{value:z,onChange:R,pasteCommandTitle:s("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:s("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Ce=>s("settings.mcp.page.toast.pastedArgumentsCount",{count:Ce}),clipboardReadFailed:s("settings.mcp.page.toast.clipboardReadFailed"),preview:Ce=>s("settings.mcp.page.connection.previewArgs",{count:Ce})}):t.jsx(Xe,{value:Q,onChange:Ce=>W(Ce.target.value),placeholder:s("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),C==="remote"&&t.jsxs("div",{"data-settings-item":"mcp.advanced",className:"mb-6",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.mcp.page.advanced.title")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsxs(Mn,{open:X,onOpenChange:v,children:[t.jsxs(Tn,{className:"flex w-full items-center justify-between py-0.5 group",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[t.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:s("settings.mcp.page.advanced.configure")}),t.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",s(B?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",k.length," ",s("settings.mcp.page.advanced.headers"),ye?` · ${ye}ms`:"",")"]})]}),X?t.jsx(E,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(E,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(Rn,{className:"pt-2",children:t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.advanced.timeoutMs")})}),t.jsx("div",{className:"flex items-center gap-2",children:t.jsx(Xe,{type:"number",min:"1",step:"1",value:ye,onChange:Ce=>ke(Ce.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]}),t.jsx("p",{className:"typography-micro text-muted-foreground sm:pl-64",children:s("settings.mcp.page.advanced.timeoutHint")})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"mb-2 typography-ui-label text-foreground",children:[s("settings.mcp.page.advanced.requestHeaders"),k.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",k.length,")"]})]}),t.jsx(Oo,{value:k,onChange:$,keyTransform:Ce=>Ce.trimStart(),keyPlaceholder:s("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:s("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:s("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:s("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ce=>s("settings.mcp.page.toast.importedVariablesCount",{count:Ce}),clipboardReadFailed:s("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:s("settings.mcp.page.env.key"),valueLabel:s("settings.mcp.page.env.value"),valuePlaceholder:s("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:s("settings.mcp.page.env.hide"),showValueTitle:s("settings.mcp.page.env.show"),addVariable:s("settings.mcp.page.env.addVariable"),plainTextWarning:s("settings.mcp.page.env.plainTextWarning"),removeVariableAria:s("settings.mcp.page.env.removeVariableAria")})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":B,onClick:()=>F(!B),onKeyDown:Ce=>{(Ce.key===" "||Ce.key==="Enter")&&(Ce.preventDefault(),F(!B))},children:[t.jsx(yt,{checked:B,onChange:F,ariaLabel:s("settings.mcp.page.advanced.oauthAutoDetectionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.mcp.page.advanced.oauthAutoDetection")})]}),t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.jsx(Xe,{value:O,onChange:Ce=>J(Ce.target.value),placeholder:s("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(Xe,{value:H,onChange:Ce=>re(Ce.target.value),placeholder:s("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(Xe,{value:le,onChange:Ce=>ne(Ce.target.value),placeholder:s("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),t.jsx(Xe,{value:be,onChange:Ce=>ae(Ce.target.value),placeholder:s("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:s("settings.mcp.page.advanced.oauthHint")}),ks&&t.jsxs("p",{className:"typography-micro text-muted-foreground",children:[s("settings.mcp.page.advanced.oauthCallbackHint"),t.jsx("span",{className:"mt-1 block break-all font-mono text-foreground/80",children:ks})]})]})]})})]})})]}),t.jsxs("div",{"data-settings-item":"mcp.environment",className:"mb-2",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[s("settings.mcp.page.env.title"),te.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",te.length,")"]})]})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:te.length===0?t.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Y([{key:"",value:""}]),children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),s("settings.mcp.page.env.addEnvironmentVariable")]}):t.jsx(Oo,{value:te,onChange:Y,keyPlaceholder:s("settings.mcp.page.env.keyPlaceholder"),pasteLabel:s("settings.mcp.page.env.pasteEnv"),pasteTitle:s("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:s("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ce=>s("settings.mcp.page.toast.importedVariablesCount",{count:Ce}),clipboardReadFailed:s("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:s("settings.mcp.page.env.key"),valueLabel:s("settings.mcp.page.env.value"),valuePlaceholder:s("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:s("settings.mcp.page.env.hide"),showValueTitle:s("settings.mcp.page.env.show"),addVariable:s("settings.mcp.page.env.addVariable"),plainTextWarning:s("settings.mcp.page.env.plainTextWarning"),removeVariableAria:s("settings.mcp.page.env.removeVariableAria")})})]}),t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[t.jsx(q,{onClick:Ze,disabled:de||!nt&&!j,size:"xs",className:"!font-normal",children:s(de?"settings.common.actions.saving":j?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!j&&t.jsx(q,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ve(!0),children:s("settings.common.actions.delete")})]})]}),t.jsx(Rt,{open:je,onOpenChange:Ce=>{Ce||(Pe(!1),qe(""),ot(null))},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("settings.mcp.page.importDialog.title")}),t.jsx($t,{children:s("settings.mcp.page.importDialog.description")})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx(us,{value:Le,onChange:Ce=>{qe(Ce.target.value),ot(null)},placeholder:`{
|
|
16
|
+
"mcpServers": {
|
|
17
|
+
"postgres": {
|
|
18
|
+
"command": "npx",
|
|
19
|
+
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),rt&&t.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:rt}),t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:t.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:fe,type:"button",children:[t.jsx(E,{name:"clipboard",className:"h-3.5 w-3.5"}),s("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),t.jsxs(Gt,{children:[t.jsx(q,{variant:"outline",onClick:()=>{Pe(!1),qe(""),ot(null)},className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(q,{onClick:tt,disabled:!Le.trim(),size:"sm",children:s("settings.common.actions.import")})]})]})}),t.jsx(Rt,{open:se,onOpenChange:Ce=>{!Ce&&!G&&ve(!1)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("settings.mcp.page.deleteDialog.title",{name:n??""})}),t.jsxs($t,{children:[s("settings.mcp.page.deleteDialog.descriptionPrefix")," ",t.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",s("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),t.jsxs(Gt,{children:[t.jsx(q,{variant:"outline",onClick:()=>ve(!1),disabled:G,className:"text-foreground",children:s("settings.common.actions.cancel")}),t.jsx(q,{variant:"destructive",size:"sm",onClick:ft,disabled:G,children:s(G?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},Wg=({transform:s})=>({...s,y:0}),Gg=s=>{const e=et.c(18),{id:n,children:a,className:r}=s;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:l,listeners:d,setNodeRef:c,transform:h,transition:m,isDragging:p}=Nd(i);let u;e[2]!==h?(u=kd.Transform.toString(h),e[2]=h,e[3]=u):u=e[3];let w;e[4]!==u||e[5]!==m?(w={transform:u,transition:m},e[4]=u,e[5]=m,e[6]=w):w=e[6];const g=p&&"opacity-50";let f;e[7]!==r||e[8]!==g?(f=ce("h-full rounded-md",r,g),e[7]=r,e[8]=g,e[9]=f):f=e[9];let x;return e[10]!==l||e[11]!==a||e[12]!==n||e[13]!==d||e[14]!==c||e[15]!==w||e[16]!==f?(x=t.jsx("div",{ref:c,"data-sortable-tab-id":n,style:w,className:f,...l,...d,children:a}),e[10]=l,e[11]=a,e[12]=n,e[13]=d,e[14]=c,e[15]=w,e[16]=f,e[17]=x):x=e[17],x},qg=s=>{const e=et.c(6),{id:n,children:a,className:r}=s;let i;e[0]!==r?(i=ce("h-full",r),e[0]=r,e[1]=i):i=e[1];let l;return e[2]!==a||e[3]!==n||e[4]!==i?(l=t.jsx("div",{className:i,"data-sortable-tab-id":n,children:a}),e[2]=a,e[3]=n,e[4]=i,e[5]=l):l=e[5],l},Fn=s=>{const e=et.c(121),{items:n,activeId:a,onSelect:r,onClose:i,onReorder:l,layoutMode:d,variant:c,activePillInsetClassName:h,activePillButtonClassName:m,inactiveTabsIconOnly:p,iconOnlyActiveTab:u,animateActivePill:w,activePillLowercase:g,className:f}=s,x=d===void 0?"scrollable":d,D=c===void 0?"default":c,P=p===void 0?!1:p,I=u===void 0?!1:u,L=g===void 0?!0:g,{t:N}=st(),b=Ie(Jg),{isTablet:j}=Ds(),T=b||j,U=o.useRef(null);let K;e[0]===Symbol.for("react.memo_cache_sentinel")?(K={left:!1,right:!1},e[0]=K):K=e[0];const[M,C]=o.useState(K);let A;e[1]!==n?(A=n.map(Qg),e[1]=n,e[2]=A):A=e[2];const z=A,R=x==="scrollable",Q=D==="default",W=D==="active-pill",te=D==="animated",Y=W||te,k=Q,$=Y||k,B=W&&R,F=Y,O=w??te,J=typeof l=="function",H=J?Gg:qg;let re;e[3]===Symbol.for("react.memo_cache_sentinel")?(re=new Map,e[3]=re):re=e[3];const le=o.useRef(re),[ne,be]=o.useState(null);let ae;e[4]===Symbol.for("react.memo_cache_sentinel")?(ae={activationConstraint:{distance:8}},e[4]=ae):ae=e[4];const ye=vd(jd(wd,ae)),ke=Yg;let he;e[5]===Symbol.for("react.memo_cache_sentinel")?(he=(Je,_e)=>{if(_e){le.current.set(Je,_e);return}le.current.delete(Je)},e[5]=he):he=e[5];const we=he;let de;e[6]!==a||e[7]!==$?(de=()=>{if(!$||!a){be(Xg);return}const Je=U.current,_e=le.current.get(a);if(!Je||!_e){be(Zg);return}let gt=0,fe=0,tt=_e;for(;tt&&tt!==Je;)gt=gt+tt.offsetLeft,fe=fe+tt.offsetTop,tt=tt.offsetParent;const nt={left:gt,top:fe,width:_e.offsetWidth,height:_e.offsetHeight};be(Ze=>ke(Ze,nt)?Ze:nt)},e[6]=a,e[7]=$,e[8]=de):de=e[8];const Z=de;let se;e[9]!==R?(se=()=>{if(!R){C({left:!1,right:!1});return}const Je=U.current;if(!Je){C({left:!1,right:!1});return}C({left:Je.scrollLeft>2,right:Je.scrollLeft+Je.clientWidth<Je.scrollWidth-2})},e[9]=R,e[10]=se):se=e[10];const ve=se;let G;e[11]!==R||e[12]!==ve?(G=()=>{if(!R){C({left:!1,right:!1});return}const Je=U.current;if(!Je)return;ve(),Je.addEventListener("scroll",ve,{passive:!0});const _e=new ResizeObserver(ve);return _e.observe(Je),()=>{Je.removeEventListener("scroll",ve),_e.disconnect()}},e[11]=R,e[12]=ve,e[13]=G):G=e[13];let ee;e[14]!==R||e[15]!==n.length||e[16]!==ve?(ee=[R,n.length,ve],e[14]=R,e[15]=n.length,e[16]=ve,e[17]=ee):ee=e[17],o.useEffect(G,ee);let ie;e[18]!==a||e[19]!==Z||e[20]!==$?(ie=()=>{if(!$){be(null);return}Z();const Je=U.current;if(!Je)return;const _e=new ResizeObserver(Z);if(_e.observe(Je),a){const gt=le.current.get(a);gt&&_e.observe(gt)}return()=>{_e.disconnect()}},e[18]=a,e[19]=Z,e[20]=$,e[21]=ie):ie=e[21];let pe;e[22]!==a||e[23]!==n.length||e[24]!==Z||e[25]!==$?(pe=[a,n.length,Z,$],e[22]=a,e[23]=n.length,e[24]=Z,e[25]=$,e[26]=pe):pe=e[26],o.useEffect(ie,pe);let Ae;e[27]!==Z?(Ae=()=>{Z()},e[27]=Z,e[28]=Ae):Ae=e[28],o.useLayoutEffect(Ae);let Se;e[29]!==a||e[30]!==R||e[31]!==ve?(Se=()=>{if(!R||!a)return;const Je=U.current;if(!Je)return;const _e=window.requestAnimationFrame(()=>{const gt=typeof window.CSS?.escape=="function"?window.CSS.escape(a):a.replace(/"/g,'\\"'),fe=Je.querySelector(`[data-sortable-tab-id="${gt}"]`);fe&&(fe.scrollIntoView({block:"nearest",inline:"nearest"}),ve())});return()=>{window.cancelAnimationFrame(_e)}},e[29]=a,e[30]=R,e[31]=ve,e[32]=Se):Se=e[32];let De;e[33]!==a||e[34]!==R||e[35]!==n.length||e[36]!==ve?(De=[a,R,n.length,ve],e[33]=a,e[34]=R,e[35]=n.length,e[36]=ve,e[37]=De):De=e[37],o.useEffect(Se,De);let Me;e[38]!==l?(Me=Je=>{if(!l)return;const{active:_e,over:gt}=Je;!gt||_e.id===gt.id||l(String(_e.id),String(gt.id))},e[38]=l,e[39]=Me):Me=e[39];const Te=Me;let Be;e[40]!==f?(Be=ce("relative flex h-full min-w-0 flex-1",f),e[40]=f,e[41]=Be):Be=e[41];let ze;e[42]!==R||e[43]!==M||e[44]!==Y?(ze=R&&M.left?t.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",Y?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=R,e[43]=M,e[44]=Y,e[45]=ze):ze=e[45];let Oe;e[46]!==R||e[47]!==M||e[48]!==Y?(Oe=R&&M.right?t.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",Y?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=R,e[47]=M,e[48]=Y,e[49]=Oe):Oe=e[49];const $e=Y?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Ke=Y&&"@container/pill-tabs",Ye=Y&&"pill-tabs__track",Re=Y&&(h??"gap-0.5 py-0.5"),V=k&&"items-center overflow-y-hidden",oe=F&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_2%,transparent)] p-0.5 gap-0.5",ge=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Fe;e[50]!==$e||e[51]!==Ke||e[52]!==Ye||e[53]!==Re||e[54]!==V||e[55]!==oe||e[56]!==ge?(Fe=ce("relative flex h-full min-w-0 flex-1",$e,Ke,Ye,Re,V,oe,ge),e[50]=$e,e[51]=Ke,e[52]=Ye,e[53]=Re,e[54]=V,e[55]=oe,e[56]=ge,e[57]=Fe):Fe=e[57];let Ne;e[58]!==R?(Ne=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=Ne):Ne=e[59];let He;e[60]!==N?(He=N("sortableTabsStrip.aria.tabs"),e[60]=N,e[61]=He):He=e[61];let X;e[62]!==ne||e[63]!==O||e[64]!==Y?(X=Y&&ne?t.jsx("div",{className:ce("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${ne.left}px, ${ne.top}px, 0)`,width:`${ne.width}px`,height:`${ne.height}px`,transition:O?"transform 300ms cubic-bezier(0.65, 0, 0.35, 1), width 300ms cubic-bezier(0.65, 0, 0.35, 1), height 300ms cubic-bezier(0.65, 0, 0.35, 1)":void 0}}):null,e[62]=ne,e[63]=O,e[64]=Y,e[65]=X):X=e[65];let v;e[66]!==ne||e[67]!==k?(v=k&&ne?t.jsx("div",{className:"pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",style:{transform:`translate3d(${ne.left}px, 0, 0)`,width:`${ne.width}px`},"aria-hidden":!0}):null,e[66]=ne,e[67]=k,e[68]=v):v=e[68];let je;if(e[69]!==H||e[70]!==a||e[71]!==m||e[72]!==L||e[73]!==T||e[74]!==I||e[75]!==P||e[76]!==W||e[77]!==b||e[78]!==R||e[79]!==n||e[80]!==i||e[81]!==r||e[82]!==B||e[83]!==Y){let Je;e[85]!==H||e[86]!==a||e[87]!==m||e[88]!==L||e[89]!==T||e[90]!==I||e[91]!==P||e[92]!==W||e[93]!==b||e[94]!==R||e[95]!==i||e[96]!==r||e[97]!==B||e[98]!==Y?(Je=_e=>{const gt=_e.id===a,fe=P&&Y&&!gt&&!!_e.icon,tt=!fe,nt=!!_e.icon&&(!I||gt),Ze=P&&Y&>&&!R&&!B,ft=_e.closable!==!1&&!!i,bt=ft&&!!_e.icon,Mt=R||B?void 0:Y?Ze?"flex-none basis-auto":b?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",ue=ft?Qe=>{Qe.button===1&&(Qe.preventDefault(),Qe.stopPropagation(),i?.(_e.id))}:void 0,Ve=ft?eh:void 0;return t.jsx(H,{id:_e.id,className:Mt,children:t.jsxs("div",{ref:Qe=>we(_e.id,Qe),onAuxClick:ue,onMouseDown:Ve,className:ce("group flex h-full min-w-0 flex-nowrap items-center",R||B?"shrink-0":Y?"w-full":"w-full min-w-0",Y?"relative z-10 bg-transparent":gt?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[t.jsx("button",{type:"button",role:"tab","aria-selected":gt,"aria-label":fe?_e.title??_e.label:void 0,onClick:()=>r(_e.id),className:ce(Y?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",Y&&L?"lowercase":null,Y&&(fe?"gap-0":"gap-1.5"),Y?B?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":fe?"px-2 !min-w-0 text-center":Ze?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":R?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",Y?m??(W?b?"h-[38px]":"h-[31px]":"h-7"):null,Y?gt?"text-foreground":"text-muted-foreground hover:text-foreground":null,Y?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:_e.title??_e.label,children:Y?t.jsxs(t.Fragment,{children:[nt?t.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[t.jsx("span",{className:ce("flex items-center justify-center transition-opacity",bt&&(T?"opacity-0":"group-hover:opacity-0")),children:_e.icon}),bt?t.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",T?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:th,onClick:Qe=>{Qe.stopPropagation(),i?.(_e.id)},"aria-label":_e.closeLabel??`Close ${_e.label} tab`,title:_e.closeLabel??`Close ${_e.label} tab`,children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,tt?t.jsx("span",{className:"animated-tabs__label truncate",children:_e.label}):null]}):t.jsxs("span",{className:ce("flex min-w-0 flex-nowrap items-center gap-1.5",!R&&"justify-center"),children:[nt?t.jsxs("span",{className:ce("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",gt?"text-[var(--primary-base)]":"text-muted-foreground"),children:[t.jsx("span",{className:ce("flex items-center justify-center transition-opacity",bt&&(T?"opacity-0":"group-hover:opacity-0")),children:_e.icon}),bt?t.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",T?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:sh,onClick:Qe=>{Qe.stopPropagation(),i?.(_e.id)},"aria-label":_e.closeLabel??`Close ${_e.label} tab`,title:_e.closeLabel??`Close ${_e.label} tab`,children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,t.jsx("span",{className:"truncate leading-[1.2]",children:_e.label})]})}),ft&&!bt?t.jsx("button",{type:"button",onPointerDown:nh,onClick:Qe=>{Qe.stopPropagation(),i?.(_e.id)},className:ce("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",Y?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",Y?gt?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":gt?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":_e.closeLabel??`Close ${_e.label} tab`,title:_e.closeLabel??`Close ${_e.label} tab`,children:t.jsx(E,{name:"close",className:"h-3 w-3"})}):null]})},_e.id)},e[85]=H,e[86]=a,e[87]=m,e[88]=L,e[89]=T,e[90]=I,e[91]=P,e[92]=W,e[93]=b,e[94]=R,e[95]=i,e[96]=r,e[97]=B,e[98]=Y,e[99]=Je):Je=e[99],je=n.map(Je),e[69]=H,e[70]=a,e[71]=m,e[72]=L,e[73]=T,e[74]=I,e[75]=P,e[76]=W,e[77]=b,e[78]=R,e[79]=n,e[80]=i,e[81]=r,e[82]=B,e[83]=Y,e[84]=je}else je=e[84];let Pe;e[100]!==Fe||e[101]!==Ne||e[102]!==He||e[103]!==X||e[104]!==v||e[105]!==je?(Pe=t.jsxs("div",{ref:U,className:Fe,style:Ne,role:"tablist","aria-label":He,children:[X,v,je]}),e[100]=Fe,e[101]=Ne,e[102]=He,e[103]=X,e[104]=v,e[105]=je,e[106]=Pe):Pe=e[106];let Le;e[107]!==Be||e[108]!==ze||e[109]!==Oe||e[110]!==Pe?(Le=t.jsxs("div",{className:Be,children:[ze,Oe,Pe]}),e[107]=Be,e[108]=ze,e[109]=Oe,e[110]=Pe,e[111]=Le):Le=e[111];const qe=Le;if(!J)return qe;let rt;e[112]===Symbol.for("react.memo_cache_sentinel")?(rt=[Wg],e[112]=rt):rt=e[112];let ot;e[113]!==z||e[114]!==qe?(ot=t.jsx(Sd,{items:z,strategy:Cd,children:qe}),e[113]=z,e[114]=qe,e[115]=ot):ot=e[115];let it;e[116]===Symbol.for("react.memo_cache_sentinel")?(it=t.jsx(Id,{dropAnimation:null}),e[116]=it):it=e[116];let dt;return e[117]!==Te||e[118]!==ye||e[119]!==ot?(dt=t.jsxs(Pd,{sensors:ye,collisionDetection:Ad,onDragEnd:Te,modifiers:rt,children:[ot,it]}),e[117]=Te,e[118]=ye,e[119]=ot,e[120]=dt):dt=e[120],dt};function Jg(s){return s.isMobile}function Qg(s){return s.id}function Yg(s,e){return!s||!e?s===e:Math.abs(s.left-e.left)<.5&&Math.abs(s.top-e.top)<.5&&Math.abs(s.width-e.width)<.5&&Math.abs(s.height-e.height)<.5}function Xg(s){return s===null?s:null}function Zg(s){return s===null?s:null}function eh(s){s.button===1&&s.preventDefault()}function th(s){s.stopPropagation()}function sh(s){s.stopPropagation()}function nh(s){s.stopPropagation()}const Qa=()=>{try{const e=es.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=ys.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[PluginsStore] Error resolving config directory:",s)}return null},ah=800,rh=5e3,ih="__default__",xi=new Map,zr=new Map,oh=1500,Cc=s=>s?.trim()||ih,lh=s=>{xi.delete(Cc(s))},is=wn()(Na(Ii((s,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:n=>s({selectedId:n}),setDraft:n=>s({draft:n}),loadPlugins:async n=>{const a=Qa(),r=Cc(a),i=Date.now(),l=xi.get(r)??0,d=e().entries.length>0||e().files.length>0;if(!n?.force&&d&&i-l<rh)return!0;const c=zr.get(r);if(!n?.force&&c)return c;const h=(async()=>{s({isLoading:!0});try{const m=await ct(gn("/api/config/plugins",a),{headers:pa(a)});if(!m.ok)throw new Error("Failed to load plugins");const p=await Ya(m);return s({entries:p.entries??[],files:p.files??[],isLoading:!1}),xi.set(r,Date.now()),n?.force||e().loadRegistryInfo(),!0}catch(m){return console.error("[PluginsStore] Failed to load plugins:",m),s({isLoading:!1}),!1}})();zr.set(r,h);try{return await h}finally{zr.delete(r)}},loadRegistryInfo:async n=>{const a=dh(n?.specs??e().entries.map(r=>r.spec));if(a.length===0){s({isLoadingRegistry:!1});return}s({isLoadingRegistry:!0});try{const r=Qa(),i={...e().registryInfo};for(const l of uh(a)){const d=await ct(ch(l,n?.force===!0,r),{headers:pa(r)});if(!d.ok)throw new Error("Failed to load plugin registry info");const c=await Ya(d);for(const h of c.results??[])i[h.spec]=h}s({registryInfo:i,isLoadingRegistry:!1})}catch(r){console.error("[PluginsStore] Failed to load plugin registry info:",r),s({isLoadingRegistry:!1})}},updateToLatest:async n=>{const a=e().entries.find(i=>i.id===n);if(!a)return{ok:!1};const r=e().registryInfo[a.spec];return!r||r.kind!=="npm-ok"||!r.hasUpdate||!r.latestVersion?{ok:!1}:await e().updateEntry(n,{spec:`${r.name}@${r.latestVersion}`})},createEntry:async n=>{const a=await $n("Creating plugin entry…",async r=>await ct(gn("/api/config/plugins/entry",r),{method:"POST",headers:Oa(r),body:JSON.stringify(Uo(n))}),e);return a.ok&&e().loadRegistryInfo({specs:[n.spec],force:!0}),a},updateEntry:async(n,a)=>{const r=e().entries.find(d=>d.id===n)?.spec,i=a.spec??r,l=await $n("Updating plugin entry…",async d=>await ct(gn(`/api/config/plugins/entry/${encodeURIComponent(n)}`,d),{method:"PATCH",headers:Oa(d),body:JSON.stringify(Uo(a))}),e);return l.ok&&i&&e().loadRegistryInfo({specs:[i],force:!0}),l},deleteEntry:async n=>{const a=e().entries.find(i=>i.id===n),r=await $n("Deleting plugin entry…",async i=>await ct(gn(`/api/config/plugins/entry/${encodeURIComponent(n)}`,i),{method:"DELETE",headers:pa(i)}),e);if(r.ok&&e().selectedId===n&&s({selectedId:null}),r.ok&&a){const i={...e().registryInfo};delete i[a.spec],s({registryInfo:i})}return r},readFile:async n=>{try{const a=Qa(),r=await ct(gn(`/api/config/plugins/file/${encodeURIComponent(n)}`,a),{headers:pa(a)});if(!r.ok)throw new Error("Failed to read plugin file");return await Ya(r)}catch(a){return console.error("[PluginsStore] Failed to read plugin file:",a),null}},createFile:async n=>$n("Creating plugin file…",async a=>await ct(gn("/api/config/plugins/file",a),{method:"POST",headers:Oa(a),body:JSON.stringify(n)}),e),updateFile:async(n,a)=>$n("Updating plugin file…",async r=>await ct(gn(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{method:"PUT",headers:Oa(r),body:JSON.stringify(a)}),e),deleteFile:async n=>{const a=await $n("Deleting plugin file…",async r=>await ct(gn(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{method:"DELETE",headers:pa(r)}),e);return a.ok&&e().selectedId===n&&s({selectedId:null}),a},getById:n=>e().entries.find(a=>a.id===n)??e().files.find(a=>a.id===n)}),{name:"plugins-store",storage:Ei(),partialize:s=>({selectedId:s.selectedId})}),{name:"plugins-store"}));function gn(s,e){const n=e?`?directory=${encodeURIComponent(e)}`:"";return`${s}${n}`}function ch(s,e,n){const a=new URLSearchParams;e&&a.set("refresh","true"),n&&a.set("directory",n);const r=a.toString();return`/api/config/plugins/registry?${`specs=${s.map(encodeURIComponent).join(",")}`}${r?`&${r}`:""}`}function dh(s){return Array.from(new Set(s.map(e=>e.trim()).filter(Boolean)))}function uh(s){const e=[];let n=[],a=0;for(const r of s){const i=encodeURIComponent(r),l=n.length===0?i.length:a+1+i.length;n.length>0&&l>oh?(e.push(n),n=[r],a=i.length):(n.push(r),a=l)}return n.length>0&&e.push(n),e}function pa(s){return s?{"x-opencode-directory":s}:void 0}function Oa(s){return{"Content-Type":"application/json",...s?{"x-opencode-directory":s}:{}}}function Uo(s){const e={};return s.spec!==void 0&&(e.spec=s.spec),s.options!==void 0&&(e.options=s.options),s.scope!==void 0&&(e.scope=s.scope),e}async function $n(s,e,n){Wa(s);let a=!1;try{const r=Qa(),i=await e(r),l=await Ya(i).catch(()=>null);if(!i.ok)throw new Error(l?.error||"Failed to update plugin configuration");return lh(r),l?.requiresReload&&(a=!0,await Ga({message:l.message,delayMs:l.reloadDelayMs??ah,scopes:["all"]})),await n().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}}catch(r){return console.error("[PluginsStore] Failed to update plugin configuration:",r),{ok:!1}}finally{a||qa()}}async function Ya(s){return await s.json()}const mh=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function ph(s){const e=s.trim();if(e==="")return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}const gh=({open:s,onOpenChange:e,defaultScope:n="user"})=>{const{t:a}=st(),r=is(R=>R.createEntry),i=is(R=>R.createFile),[l,d]=o.useState("npm"),[c,h]=o.useState(""),[m,p]=o.useState(""),[u,w]=o.useState(""),[g,f]=o.useState(""),[x,D]=o.useState(n),[P,I]=o.useState(!1),L=o.useCallback(()=>{h(""),p(""),w(""),f(""),D(n)},[n]);o.useEffect(()=>{s&&(d("npm"),L())},[s,L]);const N=R=>{R!==l&&(d(R),L())},b=o.useMemo(()=>ph(m),[m]),j=!b.ok,T=l==="file"&&u.trim()!==""&&!mh.test(u.trim()),U=(l==="npm"||l==="path")&&c.trim()==="",K=l==="file"&&g.trim()==="",M=l==="file"&&u.trim()==="",C=P||j||l==="npm"&&U||l==="path"&&U||l==="file"&&(M||T||K),A=async()=>{if(!C){I(!0);try{let R;l==="file"?R=await i({fileName:u.trim(),content:g,scope:x}):R=await r({spec:c.trim(),options:b.ok?b.value:void 0,scope:x}),R.ok?(_.success(R.message||a("settings.plugins.toast.created")),R.reloadFailed&&_.warning(a("settings.plugins.toast.reloadFailed")),e(!1)):_.error(R.message||a("settings.plugins.sidebar.toast.deleteFailed"))}finally{I(!1)}}},z=o.useMemo(()=>[{id:"npm",label:a("settings.plugins.dialog.add.tab.npm")},{id:"path",label:a("settings.plugins.dialog.add.tab.path")},{id:"file",label:a("settings.plugins.dialog.add.tab.file")}],[a]);return t.jsx(Rt,{open:s,onOpenChange:R=>{!R&&P||e(R)},children:t.jsxs(Ft,{className:"max-w-xl",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:a("settings.plugins.dialog.add.title")}),t.jsx($t,{children:a("settings.plugins.sidebar.empty.description")})]}),t.jsx(Fn,{items:z,activeId:l,onSelect:R=>N(R),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),t.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[t.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.spec")}),t.jsx(Xe,{id:"plugin-spec",value:c,onChange:R=>h(R.target.value),placeholder:a("settings.plugins.page.field.spec.placeholder"),"aria-invalid":U?!1:void 0,disabled:P}),U&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.plugins.validation.specRequired")})]}),t.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[t.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.options")}),t.jsx(us,{id:"plugin-options",value:m,onChange:R=>p(R.target.value),rows:5,className:"font-mono",hasError:j,disabled:P}),j&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:a("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[t.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.fileName")}),t.jsx(Xe,{id:"plugin-filename",value:u,onChange:R=>w(R.target.value),placeholder:"my-plugin.ts","aria-invalid":T||void 0,disabled:P}),T&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:a("settings.plugins.validation.fileName")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.content")}),t.jsx(us,{id:"plugin-content",value:g,onChange:R=>f(R.target.value),rows:16,className:"font-mono",disabled:P})]})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.plugins.page.field.scope")}),t.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(R=>{const Q=x===R,W=a(R==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return t.jsxs("button",{type:"button",onClick:()=>D(R),disabled:P,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[t.jsx(Qs,{checked:Q,onChange:()=>D(R),ariaLabel:W}),t.jsx("span",{className:ce("typography-ui-label font-normal",Q?"text-foreground":"text-foreground/60"),children:W})]},R)})})]})]}),t.jsxs(Gt,{children:[t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:P,children:a("settings.plugins.dialog.add.action.cancel")}),t.jsxs(q,{size:"sm",onClick:()=>{A()},disabled:C,children:[P?t.jsx(E,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,a("settings.plugins.dialog.add.action.submit")]})]})]})})},hh=s=>{const e=et.c(33),{spec:n}=s;let a;e[0]!==n?(a=d=>d.registryInfo[n],e[0]=n,e[1]=a):a=e[1];const r=is(a),{t:i}=st();if(!r)return null;const l=fh;switch(r.kind){case"npm-ok":{if(!r.hasUpdate||!r.latestVersion)return null;let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(E,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=d):d=e[2];let c;e[3]!==r.latestVersion?(c=t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[d,r.latestVersion]}),e[3]=r.latestVersion,e[4]=c):c=e[4];let h;return e[5]!==r.currentVersion||e[6]!==r.latestVersion||e[7]!==i||e[8]!==c?(h=l(c,i("settings.plugins.registry.badge.update.tooltip",{current:r.currentVersion??"",latest:r.latestVersion})),e[5]=r.currentVersion,e[6]=r.latestVersion,e[7]=i,e[8]=c,e[9]=h):h=e[9],h}case"npm-missing-version":{let d;e[10]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(E,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=d):d=e[10];let c;return e[11]!==r.currentVersion||e[12]!==r.name||e[13]!==i?(c=l(d,i("settings.plugins.registry.badge.missingVersion.tooltip",{version:r.currentVersion,name:r.name})),e[11]=r.currentVersion,e[12]=r.name,e[13]=i,e[14]=c):c=e[14],c}case"npm-missing-package":{let d;e[15]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(E,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=d):d=e[15];let c;return e[16]!==r.name||e[17]!==i?(c=l(d,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:r.name})),e[16]=r.name,e[17]=i,e[18]=c):c=e[18],c}case"npm-malformed":{let d;e[19]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(E,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=d):d=e[19];let c;return e[20]!==i?(c=l(d,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=c):c=e[21],c}case"npm-network":{let d;e[22]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(E,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=d):d=e[22];let c;return e[23]!==i?(c=l(d,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=c):c=e[24],c}case"path-missing":{let d;e[25]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(E,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=d):d=e[25];let c;return e[26]!==r.absolutePath||e[27]!==i?(c=l(d,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:r.absolutePath})),e[26]=r.absolutePath,e[27]=i,e[28]=c):c=e[28],c}case"path-unreadable":{let d;e[29]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(E,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=d):d=e[29];let c;return e[30]!==r.absolutePath||e[31]!==i?(c=l(d,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:r.absolutePath})),e[30]=r.absolutePath,e[31]=i,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function fh(s,e){return t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:s})}),t.jsx(It,{children:e})]})}const Ic=s=>{const e=et.c(26),{header:n,footer:a,children:r,className:i,variant:l}=s,d=l===void 0?"sidebar":l,c=ms(),h=o.useRef(null),[m,p]=o.useState(!1),[u,w]=o.useState(!1),g=d==="background"||c?"bg-background":"bg-sidebar",f=g==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const C=h.current;if(!C){p(!1),w(!1);return}if(!(C.scrollHeight>C.clientHeight+1)){p(!1),w(!1);return}p(C.scrollTop>1),w(C.scrollTop+C.clientHeight<C.scrollHeight-1)},e[0]=x):x=e[0];const D=x;let P;e[1]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{D()},e[1]=P):P=e[1];let I;e[2]!==r?(I=[r,D],e[2]=r,e[3]=I):I=e[3],o.useEffect(P,I);let L,N;e[4]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{const C=h.current;if(!C)return;const A=()=>D();return C.addEventListener("scroll",A,{passive:!0}),()=>C.removeEventListener("scroll",A)},N=[D],e[4]=L,e[5]=N):(L=e[4],N=e[5]),o.useEffect(L,N);let b;e[6]!==g||e[7]!==i?(b=ce("flex h-full flex-col",g,i),e[6]=g,e[7]=i,e[8]=b):b=e[8];let j;e[9]!==r?(j=t.jsx(_t,{ref:h,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:r}),e[9]=r,e[10]=j):j=e[10];let T;e[11]!==f||e[12]!==m?(T=m&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${f} 0%, transparent 100%)`}}),e[11]=f,e[12]=m,e[13]=T):T=e[13];let U;e[14]!==f||e[15]!==u?(U=u&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${f} 0%, transparent 100%)`}}),e[14]=f,e[15]=u,e[16]=U):U=e[16];let K;e[17]!==U||e[18]!==j||e[19]!==T?(K=t.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[j,T,U]}),e[17]=U,e[18]=j,e[19]=T,e[20]=K):K=e[20];let M;return e[21]!==a||e[22]!==n||e[23]!==K||e[24]!==b?(M=t.jsxs("div",{className:b,children:[n,K,a]}),e[21]=a,e[22]=n,e[23]=K,e[24]=b,e[25]=M):M=e[25],M},yi=s=>{const e=et.c(23),{title:n,metadata:a,selected:r,onSelect:i,icon:l,actions:d,className:c}=s,h=r===void 0?!1:r,m=d&&d.length>0,p=h?"bg-interactive-selection":"hover:bg-interactive-hover";let u;e[0]!==c||e[1]!==p?(u=ce("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",p,c),e[0]=c,e[1]=p,e[2]=u):u=e[2];let w;e[3]!==n?(w=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=w):w=e[4];let g;e[5]!==l||e[6]!==w?(g=t.jsxs("div",{className:"flex items-center gap-1.5",children:[l,w]}),e[5]=l,e[6]=w,e[7]=g):g=e[7];let f;e[8]!==a?(f=a&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a}),e[8]=a,e[9]=f):f=e[9];let x;e[10]!==i||e[11]!==g||e[12]!==f?(x=t.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[g,f]}),e[10]=i,e[11]=g,e[12]=f,e[13]=x):x=e[13];let D;e[14]!==d||e[15]!==m?(D=m&&t.jsxs(ds,{children:[t.jsx(ls,{asChild:!0,children:t.jsx(q,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(E,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(cs,{align:"end",className:"w-fit min-w-20",children:d.map(xh)})]}),e[14]=d,e[15]=m,e[16]=D):D=e[16];let P;e[17]!==x||e[18]!==D?(P=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,D]}),e[17]=x,e[18]=D,e[19]=P):P=e[19];let I;return e[20]!==u||e[21]!==P?(I=t.jsx("div",{className:u,children:P}),e[20]=u,e[21]=P,e[22]=I):I=e[22],I};function xh(s){const e=s.icon;return t.jsxs(Ns,{onClick:n=>{n.stopPropagation(),s.onClick()},className:ce(s.destructive&&"text-destructive focus:text-destructive"),children:[e&&t.jsx(E,{name:e,className:"h-4 w-4 mr-px"}),s.label]},s.label)}const yh=s=>s.parsedKind==="npm"?"code-box":"folder",bh=s=>{const e=et.c(144),{onItemSelect:n,onAddClick:a}=s,{t:r}=st(),{entries:i,files:l,selectedId:d,setSelected:c,deleteEntry:h,deleteFile:m,loadPlugins:p}=is(Ps(vh)),u=is(jh),w=is(wh),g=is(Nh),f=is(kh),[x,D]=o.useState(null),[P,I]=o.useState(!1),[L,N]=o.useState(!1);let b,j;e[0]!==p?(b=()=>{p()},j=[p],e[0]=p,e[1]=b,e[2]=j):(b=e[1],j=e[2]),o.useEffect(b,j);let T,U;e[3]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const fe=()=>N(!0);return window.addEventListener("openchamber:settings-open-plugin-add",fe),()=>window.removeEventListener("openchamber:settings-open-plugin-add",fe)},U=[],e[3]=T,e[4]=U):(T=e[3],U=e[4]),o.useEffect(T,U);let K;if(e[5]!==i||e[6]!==u){K={userEntries:0,projectEntries:0};for(const fe of i){const tt=u[fe.spec];tt?.kind==="npm-ok"&&tt.hasUpdate&&(fe.scope==="user"?K.userEntries=K.userEntries+1:fe.scope==="project"&&(K.projectEntries=K.projectEntries+1))}e[5]=i,e[6]=u,e[7]=K}else K=e[7];const M=K;let C;e[8]!==i?(C=i.filter(Sh),e[8]=i,e[9]=C):C=e[9];const A=C;let z;e[10]!==i?(z=i.filter(Ch),e[10]=i,e[11]=z):z=e[11];const R=z;let Q;e[12]!==l?(Q=l.filter(Ih),e[12]=l,e[13]=Q):Q=e[13];const W=Q;let te;e[14]!==l?(te=l.filter(Ph),e[14]=l,e[15]=te):te=e[15];const Y=te,k=i.length+l.length,$=k===0;let B;e[16]!==a?(B=()=>{a?a():N(!0)},e[16]=a,e[17]=B):B=e[17];const F=B;let O;e[18]!==n||e[19]!==c?(O=fe=>{c(fe),n?.()},e[18]=n,e[19]=c,e[20]=O):O=e[20];const J=O;let H;e[21]!==i||e[22]!==u||e[23]!==r||e[24]!==f?(H=async fe=>{const tt=i.find(bt=>bt.id===fe);if(!tt)return;const nt=u[tt.spec];if(!nt||nt.kind!=="npm-ok"||!nt.hasUpdate||!nt.latestVersion)return;const Ze=nt.latestVersion;(await f(fe)).ok?_.success(r("settings.plugins.toast.updatedToLatest",{version:Ze})):_.error(r("settings.plugins.toast.refreshFailed"))},e[21]=i,e[22]=u,e[23]=r,e[24]=f,e[25]=H):H=e[25];const re=H;let le;e[26]!==g||e[27]!==r?(le=async()=>{_.info(r("settings.plugins.toast.refreshing"));try{await g({force:!0})}catch{_.error(r("settings.plugins.toast.refreshFailed"))}},e[26]=g,e[27]=r,e[28]=le):le=e[28];const ne=le;let be;e[29]!==h||e[30]!==m||e[31]!==x||e[32]!==r?(be=async()=>{if(!x)return;I(!0);const fe=x.kind==="entry"?await h(x.id):await m(x.id);fe.ok?_.success(fe.message||r("settings.plugins.sidebar.toast.deleted",{name:x.label})):_.error(r("settings.plugins.sidebar.toast.deleteFailed")),D(null),I(!1)},e[29]=h,e[30]=m,e[31]=x,e[32]=r,e[33]=be):be=e[33];const ae=be;let ye;e[34]!==J||e[35]!==re||e[36]!==u||e[37]!==d||e[38]!==r?(ye=fe=>{const tt=u[fe.spec],nt=tt?.kind==="npm-ok"&&tt.hasUpdate&&!!tt.latestVersion,Ze=[];return nt&&Ze.push({label:r("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{re(fe.id)}}),Ze.push({label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>D({kind:"entry",id:fe.id,label:fe.spec})}),t.jsx(yi,{title:t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate",children:fe.spec}),t.jsx(hh,{spec:fe.spec})]}),metadata:fe.parsedKind==="npm"?r("settings.plugins.sidebar.kind.npm"):r("settings.plugins.sidebar.kind.path"),selected:d===fe.id,onSelect:()=>J(fe.id),icon:t.jsx(E,{name:yh(fe),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Ze},fe.id)},e[34]=J,e[35]=re,e[36]=u,e[37]=d,e[38]=r,e[39]=ye):ye=e[39];const ke=ye;let he;e[40]!==J||e[41]!==d||e[42]!==r?(he=fe=>t.jsx(yi,{title:fe.fileName,metadata:r("settings.plugins.sidebar.kind.file"),selected:d===fe.id,onSelect:()=>J(fe.id),icon:t.jsx(E,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:r("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>D({kind:"file",id:fe.id,label:fe.fileName})}]},fe.id),e[40]=J,e[41]=d,e[42]=r,e[43]=he):he=e[43];const we=he;let de;e[44]!==r?(de=(fe,tt,nt)=>{const Ze=nt===void 0?0:nt;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[fe,Ze>0&&t.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:r(Ze===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Ze})})]}),tt]})},e[44]=r,e[45]=de):de=e[45];const Z=de;let se;e[46]!==r?(se=r("settings.plugins.sidebar.title"),e[46]=r,e[47]=se):se=e[47];let ve;e[48]!==se?(ve=t.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:t.jsx("h2",{className:"text-base font-semibold text-foreground",children:se})}),e[48]=se,e[49]=ve):ve=e[49];let G;e[50]!==r||e[51]!==k?(G=r("settings.plugins.sidebar.total",{count:k}),e[50]=r,e[51]=k,e[52]=G):G=e[52];let ee;e[53]!==G?(ee=t.jsx("span",{className:"typography-meta text-muted-foreground",children:G}),e[53]=G,e[54]=ee):ee=e[54];let ie;e[55]!==ne?(ie=()=>{ne()},e[55]=ne,e[56]=ie):ie=e[56];let pe;e[57]!==r?(pe=r("settings.plugins.sidebar.actions.refresh"),e[57]=r,e[58]=pe):pe=e[58];let Ae;e[59]!==r?(Ae=r("settings.plugins.sidebar.actions.refresh"),e[59]=r,e[60]=Ae):Ae=e[60];const Se=w?"size-4 animate-spin":"size-4";let De;e[61]!==Se?(De=t.jsx(E,{name:"refresh",className:Se}),e[61]=Se,e[62]=De):De=e[62];let Me;e[63]!==w||e[64]!==ie||e[65]!==pe||e[66]!==Ae||e[67]!==De?(Me=t.jsx(q,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:ie,disabled:w,"aria-label":pe,title:Ae,children:De}),e[63]=w,e[64]=ie,e[65]=pe,e[66]=Ae,e[67]=De,e[68]=Me):Me=e[68];let Te;e[69]!==r?(Te=r("settings.plugins.sidebar.actions.addTitle"),e[69]=r,e[70]=Te):Te=e[70];let Be;e[71]!==r?(Be=r("settings.plugins.sidebar.actions.addTitle"),e[71]=r,e[72]=Be):Be=e[72];let ze;e[73]===Symbol.for("react.memo_cache_sentinel")?(ze=t.jsx(E,{name:"add",className:"size-4"}),e[73]=ze):ze=e[73];let Oe;e[74]!==F||e[75]!==Te||e[76]!==Be?(Oe=t.jsx(q,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:F,"aria-label":Te,title:Be,children:ze}),e[74]=F,e[75]=Te,e[76]=Be,e[77]=Oe):Oe=e[77];let $e;e[78]!==Me||e[79]!==Oe?($e=t.jsxs("div",{className:"flex items-center gap-1",children:[Me,Oe]}),e[78]=Me,e[79]=Oe,e[80]=$e):$e=e[80];let Ke;e[81]!==ee||e[82]!==$e?(Ke=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ee,$e]}),e[81]=ee,e[82]=$e,e[83]=Ke):Ke=e[83];let Ye;e[84]!==ve||e[85]!==Ke?(Ye=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ve,Ke]}),e[84]=ve,e[85]=Ke,e[86]=Ye):Ye=e[86];let Re;e[87]!==$||e[88]!==R||e[89]!==Y||e[90]!==ke||e[91]!==we||e[92]!==Z||e[93]!==r||e[94]!==M||e[95]!==A||e[96]!==W?(Re=$?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(E,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.plugins.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.plugins.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[A.length>0&&Z(r("settings.plugins.sidebar.group.userEntries"),A.map(ke),M.userEntries),W.length>0&&Z(r("settings.plugins.sidebar.group.userFiles"),W.map(we)),R.length>0&&Z(r("settings.plugins.sidebar.group.projectEntries"),R.map(ke),M.projectEntries),Y.length>0&&Z(r("settings.plugins.sidebar.group.projectFiles"),Y.map(we))]}),e[87]=$,e[88]=R,e[89]=Y,e[90]=ke,e[91]=we,e[92]=Z,e[93]=r,e[94]=M,e[95]=A,e[96]=W,e[97]=Re):Re=e[97];let V;e[98]!==Ye||e[99]!==Re?(V=t.jsx(Ic,{variant:"background",header:Ye,children:Re}),e[98]=Ye,e[99]=Re,e[100]=V):V=e[100];let oe;e[101]!==L?(oe=t.jsx(gh,{open:L,onOpenChange:N}),e[101]=L,e[102]=oe):oe=e[102];const ge=x!==null;let Fe;e[103]!==P?(Fe=fe=>{!fe&&!P&&D(null)},e[103]=P,e[104]=Fe):Fe=e[104];let Ne;e[105]!==r?(Ne=r("settings.plugins.sidebar.deleteDialog.title"),e[105]=r,e[106]=Ne):Ne=e[106];let He;e[107]!==Ne?(He=t.jsx(zt,{children:Ne}),e[107]=Ne,e[108]=He):He=e[108];const X=x?.label??"";let v;e[109]!==r||e[110]!==X?(v=r("settings.plugins.sidebar.deleteDialog.description",{name:X}),e[109]=r,e[110]=X,e[111]=v):v=e[111];let je;e[112]!==v?(je=t.jsx($t,{children:v}),e[112]=v,e[113]=je):je=e[113];let Pe;e[114]!==He||e[115]!==je?(Pe=t.jsxs(Kt,{children:[He,je]}),e[114]=He,e[115]=je,e[116]=Pe):Pe=e[116];let Le;e[117]===Symbol.for("react.memo_cache_sentinel")?(Le=()=>D(null),e[117]=Le):Le=e[117];let qe;e[118]!==r?(qe=r("settings.common.actions.cancel"),e[118]=r,e[119]=qe):qe=e[119];let rt;e[120]!==P||e[121]!==qe?(rt=t.jsx(q,{size:"sm",variant:"ghost",onClick:Le,disabled:P,children:qe}),e[120]=P,e[121]=qe,e[122]=rt):rt=e[122];let ot;e[123]!==P||e[124]!==r?(ot=r(P?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=P,e[124]=r,e[125]=ot):ot=e[125];let it;e[126]!==ae||e[127]!==P||e[128]!==ot?(it=t.jsx(q,{size:"sm",variant:"destructive",onClick:ae,disabled:P,children:ot}),e[126]=ae,e[127]=P,e[128]=ot,e[129]=it):it=e[129];let dt;e[130]!==rt||e[131]!==it?(dt=t.jsxs(Gt,{children:[rt,it]}),e[130]=rt,e[131]=it,e[132]=dt):dt=e[132];let Je;e[133]!==Pe||e[134]!==dt?(Je=t.jsxs(Ft,{className:"max-w-md",children:[Pe,dt]}),e[133]=Pe,e[134]=dt,e[135]=Je):Je=e[135];let _e;e[136]!==ge||e[137]!==Fe||e[138]!==Je?(_e=t.jsx(Rt,{open:ge,onOpenChange:Fe,children:Je}),e[136]=ge,e[137]=Fe,e[138]=Je,e[139]=_e):_e=e[139];let gt;return e[140]!==V||e[141]!==oe||e[142]!==_e?(gt=t.jsxs(t.Fragment,{children:[V,oe,_e]}),e[140]=V,e[141]=oe,e[142]=_e,e[143]=gt):gt=e[143],gt};function vh(s){return{entries:s.entries,files:s.files,selectedId:s.selectedId,setSelected:s.setSelected,deleteEntry:s.deleteEntry,deleteFile:s.deleteFile,loadPlugins:s.loadPlugins}}function jh(s){return s.registryInfo}function wh(s){return s.isLoadingRegistry}function Nh(s){return s.loadRegistryInfo}function kh(s){return s.updateToLatest}function Sh(s){return s.scope==="user"}function Ch(s){return s.scope==="project"}function Ih(s){return s.scope==="user"}function Ph(s){return s.scope==="project"}const bi=s=>{const e=et.c(10),{children:n,className:a,outerClassName:r}=s;let i;e[0]!==r?(i=ce("h-full",r),e[0]=r,e[1]=i):i=e[1];let l;e[2]!==a?(l=ce("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",a),e[2]=a,e[3]=l):l=e[3];let d;e[4]!==n||e[5]!==l?(d=t.jsx("div",{className:l,children:n}),e[4]=n,e[5]=l,e[6]=d):d=e[6];let c;return e[7]!==i||e[8]!==d?(c=t.jsx(_t,{outerClassName:i,className:"w-full",children:d}),e[7]=i,e[8]=d,e[9]=c):c=e[9],c},Ah=({entryId:s,spec:e})=>{const{t:n}=st(),a=is(p=>p.registryInfo[e]),r=is(p=>p.updateToLatest),[i,l]=o.useState(!1);if(!a)return null;if(a.kind==="npm-ok"){if(!a.hasUpdate||!a.latestVersion)return null;const p=a.latestVersion,u=a.currentVersion??"",w=async()=>{l(!0);try{(await r(s)).ok?_.success(n("settings.plugins.toast.updatedToLatest",{version:p})):_.error(n("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(E,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"typography-label text-[var(--status-success)]",children:n("settings.plugins.registry.banner.updateAvailable.title")}),t.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:n("settings.plugins.registry.banner.updateAvailable.description",{current:u,latest:p})})]}),t.jsx(q,{variant:"default",size:"sm",onClick:()=>{w()},disabled:i,children:n("settings.plugins.registry.banner.updateAvailable.action",{latest:p})})]})}if(a.kind==="path-ok")return null;if(a.kind==="npm-network")return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(E,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx("p",{className:"typography-micro text-muted-foreground",children:n("settings.plugins.registry.badge.network.tooltip")})})]});const d=a.kind==="path-unreadable",c=d?"var(--status-warning)":"var(--status-error)",h=d?"alert":"error-warning",m=(()=>{switch(a.kind){case"npm-missing-version":return n("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return n("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return n("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return n("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return n("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return t.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[t.jsx(E,{name:h,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"typography-label",style:{color:c},children:n("settings.plugins.registry.banner.invalid.title")}),t.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:m})]})]})};function Dh(s){const e=s.trim();if(e.length===0)return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}function Pc(s){return!s||Object.keys(s).length===0?"":JSON.stringify(s,null,2)}function Bo(s){return{mode:"entry",scope:s.scope,spec:s.spec,optionsJson:Pc(s.options),fileName:"",content:""}}function $o(s,e){return{mode:"file",scope:s.scope,spec:"",optionsJson:"",fileName:s.fileName,content:e}}const Vo=s=>{const e=et.c(4),{scope:n,label:a}=s;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=ce("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=r):r=e[0];let i;return e[1]!==a||e[2]!==n?(i=t.jsx("span",{className:r,"data-scope":n,children:a}),e[1]=a,e[2]=n,e[3]=i):i=e[3],i},Eh=()=>{const{t:s}=st(),e=is(x=>x.selectedId),n=is(x=>x.entries),a=is(x=>x.files),r=is(x=>x.draft),i=is(x=>x.setDraft),l=is(x=>x.updateEntry),d=is(x=>x.updateFile),c=is(x=>x.readFile),h=o.useMemo(()=>e?n.find(x=>x.id===e)??null:null,[n,e]),m=o.useMemo(()=>e?a.find(x=>x.id===e)??null:null,[a,e]),[p,u]=o.useState(!1),[w,g]=o.useState(!1),f=o.useRef(new Map);if(o.useEffect(()=>{let x=!1;return h?(i(Bo(h)),()=>{x=!0}):m?(g(!0),(async()=>{const D=await c(m.id);if(x)return;g(!1);const P=D?.content??"";f.current.set(m.id,P),i($o(m,P))})(),()=>{x=!0}):(i(null),()=>{x=!0})},[h,m,c,i]),!e)return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(E,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.plugins.page.empty.select")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.plugins.page.empty.add")})]})});if(h&&r&&r.mode==="entry"){const x=Dh(r.optionsJson),D=x.ok,P=r.spec!==h.spec||r.optionsJson!==Pc(h.options),I=()=>{i(Bo(h))},L=async()=>{if(!D)return;const N=r.spec.trim();if(!N){_.error(s("settings.plugins.validation.specRequired"));return}u(!0);try{const b=await l(h.id,{spec:N,options:x.value});b.ok?b.reloadFailed?_.warning(b.message||s("settings.plugins.toast.reloadFailed"),{description:b.warning}):_.success(b.message||s("settings.plugins.toast.updated")):_.error(b.message||s("settings.plugins.toast.reloadFailed"))}finally{u(!1)}};return t.jsxs(bi,{children:[t.jsx("div",{children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:s("settings.plugins.page.header.entry")}),t.jsx(Vo,{scope:h.scope,label:h.scope==="project"?s("settings.plugins.sidebar.group.projectEntries"):s("settings.plugins.sidebar.group.userEntries")})]})}),t.jsx(Ah,{entryId:h.id,spec:h.spec}),t.jsxs("div",{"data-settings-item":"plugins.spec",className:"space-y-1.5",children:[t.jsx("label",{className:"typography-meta text-muted-foreground",children:s("settings.plugins.page.field.spec")}),t.jsx(Xe,{value:r.spec,onChange:N=>i({...r,spec:N.target.value}),placeholder:s("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})]}),t.jsxs("div",{"data-settings-item":"plugins.options",className:"space-y-1.5",children:[t.jsx("label",{className:"typography-meta text-muted-foreground",children:s("settings.plugins.page.field.options")}),t.jsx(us,{value:r.optionsJson,onChange:N=>i({...r,optionsJson:N.target.value}),rows:10,className:ce("font-mono typography-meta min-h-[200px]",!D&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!D&&t.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:s("settings.plugins.page.field.options.invalidJson")})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(q,{variant:"default",size:"sm",onClick:()=>{L()},disabled:!P||!D||p,children:s("settings.plugins.page.action.save")}),t.jsx(q,{variant:"outline",size:"sm",onClick:I,disabled:!P||p,children:s("settings.plugins.page.action.discard")})]})]})}if(m&&r&&r.mode==="file"){const x=f.current.get(m.id)??"",D=r.content!==x||r.fileName!==m.fileName,P=()=>{(async()=>{g(!0);const N=(await c(m.id))?.content??"";g(!1),f.current.set(m.id,N),i($o(m,N))})()},I=async()=>{u(!0);try{const L=await d(m.id,{content:r.content});L.ok?(f.current.set(m.id,r.content),L.reloadFailed?_.warning(L.message||s("settings.plugins.toast.reloadFailed"),{description:L.warning}):_.success(L.message||s("settings.plugins.toast.updated"))):_.error(L.message||s("settings.plugins.toast.reloadFailed"))}finally{u(!1)}};return t.jsxs(bi,{children:[t.jsx("div",{children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:s("settings.plugins.page.header.file")}),t.jsx(Vo,{scope:m.scope,label:m.scope==="project"?s("settings.plugins.sidebar.group.projectFiles"):s("settings.plugins.sidebar.group.userFiles")}),t.jsx("span",{className:ce("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:m.fileName})]})}),t.jsxs("div",{"data-settings-item":"plugins.content",className:"space-y-1.5",children:[t.jsx("label",{className:"typography-meta text-muted-foreground",children:s("settings.plugins.page.field.content")}),t.jsx(us,{value:r.content,onChange:L=>i({...r,content:L.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:w})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(q,{variant:"default",size:"sm",onClick:()=>{I()},disabled:!D||p||w,children:s("settings.plugins.page.action.save")}),t.jsx(q,{variant:"outline",size:"sm",onClick:P,disabled:p||w,children:s("settings.plugins.page.action.discard")})]})]})}return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsx("div",{className:"text-center text-muted-foreground",children:t.jsx(E,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Mh="<built-in>",Hn=s=>s?.path===Mh,Th=s=>{const e=et.c(150),{onItemSelect:n}=s,{t:a}=st(),[r,i]=o.useState(null),[l,d]=o.useState(""),[c,h]=o.useState(null),[m,p]=o.useState(!1),[u,w]=o.useState(null),{selectedSkillName:g,skills:f,setSelectedSkill:x,setSkillDraft:D,createSkill:P,deleteSkill:I,getSkillDetail:L}=Zs(Ps(Rh));let N;e[0]!==n||e[1]!==x||e[2]!==D||e[3]!==f?(N=()=>{let fe="new-skill",tt=1;for(;f.some(nt=>nt.name===fe);)fe=`new-skill-${tt}`,tt++;D({name:fe,scope:"user",source:"opencode",description:""}),x(fe),n?.()},e[0]=n,e[1]=x,e[2]=D,e[3]=f,e[4]=N):N=e[4];const b=N;let j;e[5]===Symbol.for("react.memo_cache_sentinel")?(j=async fe=>{Hn(fe)||h(fe)},e[5]=j):j=e[5];const T=j;let U;e[6]!==c||e[7]!==I||e[8]!==a?(U=async()=>{if(!c)return;if(Hn(c)){h(null);return}p(!0),await I(c.name)?(_.success(a("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),h(null)):_.error(a("settings.skills.sidebar.toast.deleteSkillFailed")),p(!1)},e[6]=c,e[7]=I,e[8]=a,e[9]=U):U=e[9];const K=U;let M;e[10]!==L||e[11]!==x||e[12]!==D||e[13]!==f||e[14]!==a?(M=async fe=>{if(Hn(fe))return;const tt=fe.name;let nt=1,Ze=`${tt}-copy`;for(;f.some(bt=>bt.name===Ze);)nt++,Ze=`${tt}-copy-${nt}`;const ft=await L(fe.name);if(!ft){_.error(a("settings.skills.sidebar.toast.duplicateLoadFailed"));return}D({name:Ze,scope:fe.scope||"user",source:fe.source||"opencode",description:(ft.sources.md.fields.includes("description"),""),instructions:""}),x(Ze)},e[10]=L,e[11]=x,e[12]=D,e[13]=f,e[14]=a,e[15]=M):M=e[15];const C=M;let A;e[16]===Symbol.for("react.memo_cache_sentinel")?(A=fe=>{Hn(fe)||(d(fe.name),i(fe))},e[16]=A):A=e[16];const z=A;let R;e[17]!==P||e[18]!==I||e[19]!==L||e[20]!==r||e[21]!==l||e[22]!==x||e[23]!==f||e[24]!==a?(R=async()=>{if(!r)return;if(Hn(r)){i(null);return}const fe=l.trim().replace(/\s+/g,"-").toLowerCase();if(!fe){_.error(a("settings.skills.page.toast.skillNameRequired"));return}if(fe===r.name){i(null);return}if(f.some(Ze=>Ze.name===fe)){_.error(a("settings.skills.page.toast.skillExists"));return}if(!await L(r.name)){_.error(a("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await P({name:fe,description:"Renamed skill",scope:r.scope,source:r.source})?await I(r.name)?(_.success(`Skill renamed to "${fe}"`),x(fe)):_.error(a("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):_.error(a("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=P,e[18]=I,e[19]=L,e[20]=r,e[21]=l,e[22]=x,e[23]=f,e[24]=a,e[25]=R):R=e[25];const Q=R;let W;e[26]!==f?(W=f.filter(Fh),e[26]=f,e[27]=W):W=e[27];const te=W;let Y;e[28]!==f?(Y=f.filter(Lh),e[28]=f,e[29]=Y):Y=e[29];const k=Y;let $;e[30]===Symbol.for("react.memo_cache_sentinel")?($=function(tt){const nt={},Ze=[];for(const bt of tt)bt.group?(nt[bt.group]||(nt[bt.group]=[]),nt[bt.group].push(bt)):Ze.push(bt);const ft=Object.keys(nt).sort(Oh).map(bt=>({name:bt,skills:[...nt[bt]].sort(zh)}));return Ze.sort(Kh),{sortedGroups:ft,ungrouped:Ze}},e[30]=$):$=e[30];const B=$;let F;e[31]!==te?(F=B(te),e[31]=te,e[32]=F):F=e[32];const O=F;let J;e[33]!==k?(J=B(k),e[33]=k,e[34]=J):J=e[34];const H=J;let re;e[35]===Symbol.for("react.memo_cache_sentinel")?(re=ce("flex h-full flex-col","bg-background"),e[35]=re):re=e[35];let le;e[36]!==a?(le=a("settings.skills.sidebar.title"),e[36]=a,e[37]=le):le=e[37];let ne;e[38]!==le?(ne=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:le}),e[38]=le,e[39]=ne):ne=e[39];let be;e[40]===Symbol.for("react.memo_cache_sentinel")?(be=t.jsx(ka,{className:"mb-3"}),e[40]=be):be=e[40];let ae;e[41]!==f.length||e[42]!==a?(ae=a("settings.skills.sidebar.total",{count:f.length}),e[41]=f.length,e[42]=a,e[43]=ae):ae=e[43];let ye;e[44]!==ae?(ye=t.jsx("span",{className:"typography-meta text-muted-foreground",children:ae}),e[44]=ae,e[45]=ye):ye=e[45];let ke;e[46]===Symbol.for("react.memo_cache_sentinel")?(ke=t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),e[46]=ke):ke=e[46];let he;e[47]!==b?(he=t.jsx(q,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:b,children:ke}),e[47]=b,e[48]=he):he=e[48];let we;e[49]!==ye||e[50]!==he?(we=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ye,he]}),e[49]=ye,e[50]=he,e[51]=we):we=e[51];let de;e[52]!==ne||e[53]!==we?(de=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ne,be,we]}),e[52]=ne,e[53]=we,e[54]=de):de=e[54];let Z;e[55]!==O||e[56]!==H||e[57]!==C||e[58]!==n||e[59]!==u||e[60]!==te||e[61]!==g||e[62]!==x||e[63]!==f.length||e[64]!==a||e[65]!==k?(Z=t.jsx(_t,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:f.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(E,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.skills.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.skills.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[te.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.skills.sidebar.section.project")}),O.sortedGroups.map(fe=>{const{name:tt,skills:nt}=fe;return t.jsx(fi,{label:tt,count:nt.length,storageKey:"project-skills",children:nt.map(Ze=>t.jsx(za,{skill:Ze,isSelected:g===Ze.name,onSelect:()=>{x(Ze.name),n?.()},onRename:()=>z(Ze),onDelete:()=>T(Ze),onDuplicate:()=>C(Ze),isMenuOpen:u===Ze.name,onMenuOpenChange:ft=>w(ft?Ze.name:null)},Ze.name))},tt)}),O.ungrouped.map(fe=>t.jsx(za,{skill:fe,isSelected:g===fe.name,onSelect:()=>{x(fe.name),n?.()},onRename:()=>z(fe),onDelete:()=>T(fe),onDuplicate:()=>C(fe),isMenuOpen:u===fe.name,onMenuOpenChange:tt=>w(tt?fe.name:null)},fe.name))]}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.skills.sidebar.section.user")}),H.sortedGroups.map(fe=>{const{name:tt,skills:nt}=fe;return t.jsx(fi,{label:tt,count:nt.length,storageKey:"user-skills",children:nt.map(Ze=>t.jsx(za,{skill:Ze,isSelected:g===Ze.name,onSelect:()=>{x(Ze.name),n?.()},onRename:()=>z(Ze),onDelete:()=>T(Ze),onDuplicate:()=>C(Ze),isMenuOpen:u===Ze.name,onMenuOpenChange:ft=>w(ft?Ze.name:null)},Ze.name))},tt)}),H.ungrouped.map(fe=>t.jsx(za,{skill:fe,isSelected:g===fe.name,onSelect:()=>{x(fe.name),n?.()},onRename:()=>z(fe),onDelete:()=>T(fe),onDuplicate:()=>C(fe),isMenuOpen:u===fe.name,onMenuOpenChange:tt=>w(tt?fe.name:null)},fe.name))]})]})}),e[55]=O,e[56]=H,e[57]=C,e[58]=n,e[59]=u,e[60]=te,e[61]=g,e[62]=x,e[63]=f.length,e[64]=a,e[65]=k,e[66]=Z):Z=e[66];const se=c!==null;let ve;e[67]!==m?(ve=fe=>{!fe&&!m&&h(null)},e[67]=m,e[68]=ve):ve=e[68];let G;e[69]!==a?(G=a("settings.skills.sidebar.deleteDialog.title"),e[69]=a,e[70]=G):G=e[70];let ee;e[71]!==G?(ee=t.jsx(zt,{children:G}),e[71]=G,e[72]=ee):ee=e[72];const ie=c?.name??"";let pe;e[73]!==a||e[74]!==ie?(pe=a("settings.skills.sidebar.deleteDialog.description",{name:ie}),e[73]=a,e[74]=ie,e[75]=pe):pe=e[75];let Ae;e[76]!==pe?(Ae=t.jsx($t,{children:pe}),e[76]=pe,e[77]=Ae):Ae=e[77];let Se;e[78]!==ee||e[79]!==Ae?(Se=t.jsxs(Kt,{children:[ee,Ae]}),e[78]=ee,e[79]=Ae,e[80]=Se):Se=e[80];let De;e[81]===Symbol.for("react.memo_cache_sentinel")?(De=()=>h(null),e[81]=De):De=e[81];let Me;e[82]!==a?(Me=a("settings.common.actions.cancel"),e[82]=a,e[83]=Me):Me=e[83];let Te;e[84]!==m||e[85]!==Me?(Te=t.jsx(q,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:De,disabled:m,children:Me}),e[84]=m,e[85]=Me,e[86]=Te):Te=e[86];let Be;e[87]!==a?(Be=a("settings.common.actions.delete"),e[87]=a,e[88]=Be):Be=e[88];let ze;e[89]!==K||e[90]!==m||e[91]!==Be?(ze=t.jsx(q,{size:"sm",onClick:K,disabled:m,children:Be}),e[89]=K,e[90]=m,e[91]=Be,e[92]=ze):ze=e[92];let Oe;e[93]!==Te||e[94]!==ze?(Oe=t.jsxs(Gt,{children:[Te,ze]}),e[93]=Te,e[94]=ze,e[95]=Oe):Oe=e[95];let $e;e[96]!==Se||e[97]!==Oe?($e=t.jsxs(Ft,{className:"max-w-md",children:[Se,Oe]}),e[96]=Se,e[97]=Oe,e[98]=$e):$e=e[98];let Ke;e[99]!==se||e[100]!==ve||e[101]!==$e?(Ke=t.jsx(Rt,{open:se,onOpenChange:ve,children:$e}),e[99]=se,e[100]=ve,e[101]=$e,e[102]=Ke):Ke=e[102];const Ye=r!==null;let Re;e[103]===Symbol.for("react.memo_cache_sentinel")?(Re=fe=>!fe&&i(null),e[103]=Re):Re=e[103];let V;e[104]!==a?(V=a("settings.skills.sidebar.renameDialog.title"),e[104]=a,e[105]=V):V=e[105];let oe;e[106]!==V?(oe=t.jsx(zt,{children:V}),e[106]=V,e[107]=oe):oe=e[107];const ge=r?.name??"";let Fe;e[108]!==a||e[109]!==ge?(Fe=a("settings.skills.sidebar.renameDialog.description",{name:ge}),e[108]=a,e[109]=ge,e[110]=Fe):Fe=e[110];let Ne;e[111]!==Fe?(Ne=t.jsx($t,{children:Fe}),e[111]=Fe,e[112]=Ne):Ne=e[112];let He;e[113]!==oe||e[114]!==Ne?(He=t.jsxs(Kt,{children:[oe,Ne]}),e[113]=oe,e[114]=Ne,e[115]=He):He=e[115];let X;e[116]===Symbol.for("react.memo_cache_sentinel")?(X=fe=>d(fe.target.value),e[116]=X):X=e[116];let v;e[117]!==a?(v=a("settings.skills.sidebar.renameDialog.placeholder"),e[117]=a,e[118]=v):v=e[118];let je;e[119]!==Q?(je=fe=>{fe.key==="Enter"&&Q()},e[119]=Q,e[120]=je):je=e[120];let Pe;e[121]!==l||e[122]!==v||e[123]!==je?(Pe=t.jsx(Xe,{value:l,onChange:X,placeholder:v,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:je}),e[121]=l,e[122]=v,e[123]=je,e[124]=Pe):Pe=e[124];let Le;e[125]===Symbol.for("react.memo_cache_sentinel")?(Le=()=>i(null),e[125]=Le):Le=e[125];let qe;e[126]!==a?(qe=a("settings.common.actions.cancel"),e[126]=a,e[127]=qe):qe=e[127];let rt;e[128]!==qe?(rt=t.jsx(q,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Le,children:qe}),e[128]=qe,e[129]=rt):rt=e[129];let ot;e[130]!==a?(ot=a("settings.common.actions.rename"),e[130]=a,e[131]=ot):ot=e[131];let it;e[132]!==Q||e[133]!==ot?(it=t.jsx(q,{size:"sm",onClick:Q,children:ot}),e[132]=Q,e[133]=ot,e[134]=it):it=e[134];let dt;e[135]!==rt||e[136]!==it?(dt=t.jsxs(Gt,{children:[rt,it]}),e[135]=rt,e[136]=it,e[137]=dt):dt=e[137];let Je;e[138]!==He||e[139]!==Pe||e[140]!==dt?(Je=t.jsxs(Ft,{children:[He,Pe,dt]}),e[138]=He,e[139]=Pe,e[140]=dt,e[141]=Je):Je=e[141];let _e;e[142]!==Ye||e[143]!==Je?(_e=t.jsx(Rt,{open:Ye,onOpenChange:Re,children:Je}),e[142]=Ye,e[143]=Je,e[144]=_e):_e=e[144];let gt;return e[145]!==de||e[146]!==Z||e[147]!==Ke||e[148]!==_e?(gt=t.jsxs("div",{className:re,children:[de,Z,Ke,_e]}),e[145]=de,e[146]=Z,e[147]=Ke,e[148]=_e,e[149]=gt):gt=e[149],gt},za=s=>{const e=et.c(49),{skill:n,isSelected:a,onSelect:r,onDelete:i,onRename:l,onDuplicate:d,isMenuOpen:c,onMenuOpenChange:h}=s,{t:m}=st();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=va(),e[0]=p):p=e[0];const u=p;let w;e[1]!==n.source||e[2]!==m?(w=n.source==="claude"?m("settings.skills.sidebar.badge.claude"):n.source==="agents"?m("settings.skills.sidebar.badge.agents"):m("settings.skills.sidebar.badge.opencode"),e[1]=n.source,e[2]=m,e[3]=w):w=e[3];const g=w;let f;e[4]!==n?(f=Hn(n),e[4]=n,e[5]=f):f=e[5];const x=f,[D,P]=o.useState(!1);let I;e[6]!==i||e[7]!==d||e[8]!==l||e[9]!==m?(I=k=>t.jsxs(t.Fragment,{children:[t.jsxs(k,{onClick:$=>{$.stopPropagation(),l()},children:[t.jsx(E,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),t.jsxs(k,{onClick:$=>{$.stopPropagation(),d()},children:[t.jsx(E,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),t.jsxs(k,{onClick:$=>{$.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(E,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[6]=i,e[7]=d,e[8]=l,e[9]=m,e[10]=I):I=e[10];const L=I,N=!x&&D,b=a?"bg-interactive-selection":"hover:bg-interactive-hover";let j;e[11]!==b?(j=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",b),e[11]=b,e[12]=j):j=e[12];let T;e[13]!==x?(T=!u&&!x?k=>{k.preventDefault(),P(!0)}:void 0,e[13]=x,e[14]=T):T=e[14];let U;e[15]!==j||e[16]!==T?(U=t.jsx("div",{className:j,onContextMenu:T}),e[15]=j,e[16]=T,e[17]=U):U=e[17];let K;e[18]!==n.name?(K=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[18]=n.name,e[19]=K):K=e[19];let M;e[20]!==n.scope?(M=t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:n.scope}),e[20]=n.scope,e[21]=M):M=e[21];let C;e[22]!==g?(C=t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:g}),e[22]=g,e[23]=C):C=e[23];let A;e[24]!==K||e[25]!==M||e[26]!==C?(A=t.jsxs("div",{className:"flex items-center gap-1.5",children:[K,M,C]}),e[24]=K,e[25]=M,e[26]=C,e[27]=A):A=e[27];let z;e[28]!==r||e[29]!==A?(z=t.jsx("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:A}),e[28]=r,e[29]=A,e[30]=z):z=e[30];let R;e[31]!==x||e[32]!==c||e[33]!==h||e[34]!==L?(R=x?null:t.jsxs(ds,{open:c,onOpenChange:k=>{k&&P(!1),h(k)},children:[t.jsx(ls,{asChild:!0,children:t.jsx(q,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(E,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(cs,{align:"end",className:"w-fit min-w-20",children:L(Ns)})]}),e[31]=x,e[32]=c,e[33]=h,e[34]=L,e[35]=R):R=e[35];let Q;e[36]!==z||e[37]!==R?(Q=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[z,R]}),e[36]=z,e[37]=R,e[38]=Q):Q=e[38];let W;e[39]!==Q||e[40]!==U?(W=t.jsx(yn,{render:U,children:Q}),e[39]=Q,e[40]=U,e[41]=W):W=e[41];let te;e[42]!==x||e[43]!==L?(te=x?null:t.jsx(bn,{className:"w-fit min-w-20",children:L(sn)}),e[42]=x,e[43]=L,e[44]=te):te=e[44];let Y;return e[45]!==W||e[46]!==te||e[47]!==N?(Y=t.jsxs(xn,{open:N,onOpenChange:P,children:[W,te]}),e[45]=W,e[46]=te,e[47]=N,e[48]=Y):Y=e[48],Y};function Rh(s){return{selectedSkillName:s.selectedSkillName,skills:s.skills,setSelectedSkill:s.setSelectedSkill,setSkillDraft:s.setSkillDraft,createSkill:s.createSkill,deleteSkill:s.deleteSkill,getSkillDetail:s.getSkillDetail}}function Fh(s){return s.scope==="project"}function Lh(s){return s.scope==="user"}function Oh(s,e){return s.localeCompare(e)}function zh(s,e){return s.name.localeCompare(e.name)}function Kh(s,e){return s.name.localeCompare(e.name)}const Uh=s=>s!==null&&typeof s=="object"&&"updateStatus"in s&&typeof s.updateStatus=="function",Bh=s=>{const e=document.createElement("div");e.className="cm-vim-panel";const n=Td(s);if(!n)return{top:!1,dom:e};n.state.statusbar=e;const a=n.state.vimPlugin;return Uh(a)&&a.updateStatus(),{top:!1,dom:e,destroy(){n.state.statusbar===e&&(n.state.statusbar=null)}}};function _o(s){return s?[Dd(),Ed.of(Bh),Md()]:[]}const $h={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},Vh={case:"Match case",re:"Regular expression",word:"Match whole word"};function _h(s){const e=s.querySelector(".cm-search");if(e){for(const[n,a]of Object.entries($h)){const r=e.querySelector(`button[name="${n}"]`);r&&!r.title&&(r.title=a)}for(const[n,a]of Object.entries(Vh)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=a)}}}const Kr=new WeakMap;function Hh(s,e){const n=tr(s.state);if(!n.valid)return Kr.delete(s),0;const a=Kr.get(s);if(!e&&a?.doc===s.state.doc&&a.query.eq(n))return a.total;const r=n.getCursor(s.state);let i=0;for(let l=r.next();!l.done;l=r.next())i+=1;return Kr.set(s,{query:n,doc:s.state.doc,total:i}),i}function Wh(s){const e=tr(s.state);if(!e.valid)return 0;const n=s.state.selection.main,a=e.getCursor(s.state);let r=0,i=0;for(let l=a.next();!l.done;l=a.next()){const d=l.value;if(r+=1,i===0&&(i=r),n.from===d.from&&n.to===d.to||n.from<d.to&&n.to>d.from||d.from>=n.head)return r}return i}function Ho(s,e,n=!1){const a=s.querySelector(".cm-search");if(!a)return;let r=a.querySelector(".cm-search-message");if(!r){r=document.createElement("span"),r.className="cm-search-message",r.setAttribute("aria-live","polite");const d=a.querySelector('button[name="next"]'),c=d?.parentNode===a?d:a.firstChild;a.insertBefore(r,c)}const i=Hh(e,n),l=i===0?0:Wh(e);r.textContent=i===0?"":`${l}/${i}`}const Wo=new Ln,Go=new Ln,qo=new Ln,Jo=new Ln,Qo=new Ln,Yo=new Ln,Xo=new Ln,Zo=s=>s,Ur=Bd,Gh=$d,qh=Vd;class Jh extends _d{constructor(e,n){super(),this.id=e,this.containerMap=n}toDOM(){let e=this.containerMap.get(this.id);return e||(e=document.createElement("div"),e.className="oc-block-widget",e.dataset.widgetId=this.id,this.containerMap.set(this.id,e)),e}eq(e){return e.id===this.id}destroy(){}}const el=(s,e)=>!s||s.length===0?[]:tc.define({create(n){const a=new Pi,r=[...s].sort((i,l)=>i.afterLine-l.afterLine);for(const i of r){const l=n.doc.lines;if(i.afterLine>l)continue;const d=n.doc.line(i.afterLine);a.add(d.to,d.to,or.widget({widget:new Jh(i.id,e),block:!0,side:1}))}return a.finish()},update(n,a){return n.map(a.changes)},provide:n=>Bs.decorations.from(n)}),tl=s=>{if(!s)return[];const e=Math.max(1,s.start),n=Math.max(e,s.end);return ec.fromClass(class{decorations;constructor(a){this.decorations=this.build(a)}update(a){(a.docChanged||a.viewportChanged)&&(this.decorations=this.build(a.view))}build(a){const r=new Pi;for(let i=e;i<=n&&i<=a.state.doc.lines;i+=1){const l=a.state.doc.line(i);r.add(l.from,l.from,or.line({class:"oc-cm-selected-line"}))}return r.finish()}},{decorations:a=>a.decorations})};function sl({value:s,onChange:e,extensions:n,className:a,readOnly:r,lineNumbersConfig:i,highlightLines:l,onViewReady:d,onViewDestroy:c,blockWidgets:h,enableSearch:m,searchOpen:p,onSearchOpenChange:u,vimMode:w}){const g=o.useRef(null),f=o.useRef(null),x=o.useRef(s),D=o.useRef(e),P=o.useRef(d),I=o.useRef(c),L=o.useRef(u),N=o.useRef(h),b=o.useRef(w),j=o.useRef(new Map),[T,U]=o.useState([]),K=o.useCallback(C=>{const A=(C??[]).map(z=>{const R=j.current.get(z.id);return R?{id:z.id,content:z.content,container:R}:null}).filter(z=>z!==null);U(z=>z.length===A.length&&z.every((R,Q)=>{const W=A[Q];return R.id===W.id&&R.content===W.content&&R.container===W.container})?z:A)},[]),M=o.useCallback(C=>{const A=g.current,z=C??f.current;if(!A||!z)return;const R=z.dom.querySelector(".cm-gutters"),Q=R instanceof HTMLElement?R.getBoundingClientRect().width:0;A.style.setProperty("--oc-editor-gutter-width",`${Q}px`)},[]);return o.useEffect(()=>{x.current=s},[s]),o.useEffect(()=>{D.current=e},[e]),o.useEffect(()=>{P.current=d,I.current=c},[d,c]),o.useEffect(()=>{L.current=u},[u]),o.useEffect(()=>{N.current=h,K(h)},[h,K]),o.useEffect(()=>{if(!g.current)return;const C=(()=>{if(typeof document>"u")return null;const z=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(z)return z;const R=window.__OPENCHAMBER_CSP_NONCE__;return typeof R=="string"&&R.length>0?R:null})(),A=Rd.create({doc:x.current,extensions:[...C?[Bs.cspNonce.of(C)]:[],Fd({fixed:!0}),Wo.of(Ki(i)),Ld(),Od.of(" "),Xo.of(_o(w)),kr.of([zd,...Kd,...Ud]),Bs.updateListener.of(z=>{M(z.view),(z.viewportChanged||z.geometryChanged)&&K(N.current);const R=Ui(z.startState),Q=Ui(z.state);R!==Q&&L.current?.(Q);const W=!tr(z.startState).eq(tr(z.state));if(Q&&(R!==Q||W||z.docChanged||z.selectionSet)&&Ho(z.view.dom,z.view,R!==Q||W||z.docChanged),!z.docChanged)return;const te=z.state.doc.toString();x.current=te,D.current(te),K(N.current)}),Go.of(Bs.editable.of(!r)),qo.of(n??[]),Jo.of(tl(l)),Qo.of(el(h,j.current)),Yo.of(m?[Bi({top:!0}),kr.of(Zo($i))]:[])]});return f.current=new Bs({state:A,parent:g.current}),Ur(f.current,f.current.state.doc.length,200),f.current.requestMeasure(),requestAnimationFrame(()=>{M(f.current),K(N.current)}),f.current&&P.current?.(f.current),()=>{I.current?.(),f.current?.destroy(),f.current=null,U([])}},[N,M,K]),o.useEffect(()=>{const C=f.current;C&&(C.dispatch({effects:[Wo.reconfigure(Ki(i)),Go.reconfigure(Bs.editable.of(!r)),qo.reconfigure(n??[]),Jo.reconfigure(tl(l)),Qo.reconfigure(el(h,j.current)),Yo.reconfigure(m?[Bi({top:!0}),kr.of(Zo($i))]:[])]}),Ur(C,C.state.doc.length,200),C.requestMeasure(),requestAnimationFrame(()=>{M(C),K(N.current)}))},[n,l,i,r,h,m,M,K]),o.useEffect(()=>{const C=f.current;if(!C){b.current=w;return}b.current!==w&&(b.current=w,C.dispatch({effects:Xo.reconfigure(_o(w))}))},[w]),o.useEffect(()=>{const C=f.current;!C||m===!1||(p?(Gh(C),requestAnimationFrame(()=>{_h(C.dom),Ho(C.dom,C,!0)})):qh(C))},[p,m]),o.useEffect(()=>{const C=f.current;if(!C)return;const A=C.state.doc.toString();A!==s&&(C.dispatch({changes:{from:0,to:A.length,insert:s}}),Ur(C,C.state.doc.length,300),C.requestMeasure(),requestAnimationFrame(()=>M(C)))},[s,M]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:g,className:ce("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",a)}),T.map(C=>Ha.createPortal(C.content,C.container,C.id))]})}const Qh=s=>{const e=et.c(11),{currentMode:n,onToggle:a}=s,r=n==="preview",i=r?"Switch to edit mode":"Switch to preview mode",l=r?"Edit":"Preview";let d;e[0]!==r?(d=r?t.jsx(E,{name:"eye",className:"size-4","aria-hidden":"true"}):t.jsx(E,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=r,e[1]=d):d=e[1];let c;e[2]!==i||e[3]!==a||e[4]!==d?(c=t.jsx(Ct,{asChild:!0,children:t.jsx(q,{variant:"ghost",size:"sm",onClick:a,"aria-label":i,className:"h-5 w-5 p-0",children:d})}),e[2]=i,e[3]=a,e[4]=d,e[5]=c):c=e[5];let h;e[6]!==l?(h=t.jsx(It,{sideOffset:8,children:l}),e[6]=l,e[7]=h):h=e[7];let m;return e[8]!==c||e[9]!==h?(m=t.jsxs(St,{children:[c,h]}),e[8]=c,e[9]=h,e[10]=m):m=e[10],m},Is=wn()(Na(Ii((s,e)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{s({selectedProfileId:n})},loadProfiles:async()=>{s({isLoading:!0});const n=e().profiles;try{const a=await ku();return s({profiles:a,isLoading:!1}),!0}catch(a){return console.error("Failed to load git identity profiles:",a),s({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=await Nu();if(n&&n.userName&&n.userEmail){const a={id:"global",name:"Global Identity",userName:n.userName,userEmail:n.userEmail,authType:n.sshCommand?"ssh":void 0,sshKey:n.sshCommand?n.sshCommand.replace("ssh -i ",""):null,color:"info",icon:"house"};s({globalIdentity:a})}else s({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),s({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=await wu();return s({discoveredCredentials:n}),!0}catch(n){return console.error("Failed to discover git credentials:",n),s({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=a=>{if(typeof a!="string")return null;const r=a.trim();return r.length>0?r:null};try{let a=null;if(a===null){const r=Vs()?.settings;if(r)try{const l=(await r.load())?.settings||{};a=n(l.defaultGitIdentityId)}catch{}}if(a===null)try{const r=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(r.ok){const i=await r.json().catch(()=>null);a=n(i?.defaultGitIdentityId)}}catch{}return s({defaultGitIdentityId:a}),!0}catch(a){return console.error("Failed to load default git identity setting:",a),!1}},setDefaultGitIdentityId:async n=>{try{const a=typeof n=="string"?n.trim():"",r=a.length>0?a:"";return await Nt({defaultGitIdentityId:r}),s({defaultGitIdentityId:r.length>0?r:null}),!0}catch(a){return console.error("Failed to save default git identity setting:",a),!1}},createProfile:async n=>{try{const a={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};return await ju(a),await e().loadProfiles(),!0}catch(a){return console.error("Failed to create git identity profile:",a),!1}},updateProfile:async(n,a)=>{try{const r=e().profiles.find(l=>l.id===n);if(!r)throw new Error("Profile not found");const i={...r,...a};return await vu(n,i),await e().loadProfiles(),!0}catch(r){return console.error("Failed to update git identity profile:",r),!1}},deleteProfile:async n=>{try{return await bu(n),e().selectedProfileId===n&&s({selectedProfileId:null}),await e().loadProfiles(),!0}catch(a){return console.error("Failed to delete git identity profile:",a),!1}},getProfileById:n=>{const{profiles:a,globalIdentity:r}=e();return n==="global"?r||void 0:a.find(i=>i.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:a}=e();return a.filter(r=>!n.some(i=>i.authType==="token"&&i.host===r.host))}}),{name:"git-identities-store",storage:Ei(),partialize:s=>({selectedProfileId:s.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Is);const Yh=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Xh=s=>{const e=s.trim(),n=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(n==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(n==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const a=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return a?`${a[1]}/${a[2].replace(/\.git$/i,"")}`:e},Zh=async()=>{try{const s=Vs()?.settings;if(s)return(await s.load())?.settings||{};const e=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},ef=s=>{const e=et.c(160),{open:n,onOpenChange:a}=s,{t:r}=st(),i=Ys(tf),l=Ys(sf),d=Ys(nf),c=Ys(af),h=Ys(rf),m=Is(of),p=Is(lf),[u,w]=o.useState(""),[g,f]=o.useState(""),[x,D]=o.useState("");let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P=[],e[0]=P):P=e[0];const[I,L]=o.useState(P),[N,b]=o.useState(null),[j,T]=o.useState(!1);let U;e[1]===Symbol.for("react.memo_cache_sentinel")?(U=[],e[1]=U):U=e[1];const[K,M]=o.useState(U),[C,A]=o.useState(null),z=o.useRef(0);let R;e[2]===Symbol.for("react.memo_cache_sentinel")?(R=fe=>{z.current=z.current+1,T(!1),b(null),fe?.clearIdentity&&(M([]),A(null))},e[2]=R):R=e[2];const Q=R;let W,te;e[3]!==p||e[4]!==n?(W=()=>{n&&(z.current=z.current+1,w(""),f(""),D(""),b(null),T(!1),M([]),A(null),p(),(async()=>{const fe=await Zh(),tt=Array.isArray(fe?.skillCatalogs)?fe?.skillCatalogs:[];L(tt||[])})())},te=[n,p],e[3]=p,e[4]=n,e[5]=W,e[6]=te):(W=e[5],te=e[6]),o.useEffect(W,te);let Y;e[7]!==g?(Y=g.trim(),e[7]=g,e[8]=Y):Y=e[8];const k=Y;let $;e[9]!==x?($=x.trim(),e[9]=x,e[10]=$):$=e[10];const B=$;let F;if(e[11]!==I||e[12]!==k||e[13]!==B){let fe;e[15]!==k||e[16]!==B?(fe=tt=>{const nt=(tt.source||"").trim(),Ze=(tt.subpath||"").trim();return nt===k&&Ze===B},e[15]=k,e[16]=B,e[17]=fe):fe=e[17],F=I.some(fe),e[11]=I,e[12]=k,e[13]=B,e[14]=F}else F=e[14];const O=F;let J;e[18]!==m||e[19]!==C||e[20]!==u||e[21]!==i||e[22]!==g||e[23]!==x||e[24]!==r?(J=async()=>{const fe=g.trim();if(!fe){_.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}u.trim()||w(Xh(fe)),T(!1),b(null);const tt=z.current+1;z.current=tt;const nt=await i({source:fe,subpath:x.trim()||void 0,gitIdentityId:C||void 0});if(z.current!==tt)return;if(!nt.ok){if(nt.error?.kind==="authRequired"){if(ms()){_.error(r("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const ft=nt.error.identities||[];if(M(ft),!C&&ft.length>0){const bt=m&&m!=="global"&&ft.some(Mt=>Mt.id===m)?m:ft[0].id;A(bt)}_.error(r("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}_.error(nt.error?.message||r("settings.skills.catalog.add.toast.scanFailed"));return}const Ze=nt.items?.length||0;if(b(Ze),Ze===0){_.error(r("settings.skills.catalog.add.toast.noSkillsFound")),T(!1);return}M([]),T(!0),_.success(r("settings.skills.catalog.shared.toast.foundSkills",{count:Ze}))},e[18]=m,e[19]=C,e[20]=u,e[21]=i,e[22]=g,e[23]=x,e[24]=r,e[25]=J):J=e[25];const H=J;let re;e[26]!==I||e[27]!==C||e[28]!==O||e[29]!==u||e[30]!==l||e[31]!==d||e[32]!==a||e[33]!==j||e[34]!==c||e[35]!==g||e[36]!==x||e[37]!==r?(re=async()=>{const fe=u.trim(),tt=g.trim(),nt=x.trim();if(!fe){_.error(r("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!tt){_.error(r("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!j){_.error(r("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(O){_.error(r("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const Ze={id:Yh(),label:fe,source:tt,...nt?{subpath:nt}:{},...C?{gitIdentityId:C}:{}},ft=[...I,Ze];try{await Nt({skillCatalogs:ft}),L(ft),_.success(r("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await d(Ze.id,{refresh:!0}),c(Ze.id),a(!1)}catch(bt){const Mt=bt;_.error(Mt instanceof Error?Mt.message:r("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=I,e[27]=C,e[28]=O,e[29]=u,e[30]=l,e[31]=d,e[32]=a,e[33]=j,e[34]=c,e[35]=g,e[36]=x,e[37]=r,e[38]=re):re=e[38];const le=re;let ne;e[39]!==r?(ne=r("settings.skills.catalog.add.title"),e[39]=r,e[40]=ne):ne=e[40];let be;e[41]!==ne?(be=t.jsx(zt,{children:ne}),e[41]=ne,e[42]=be):be=e[42];let ae;e[43]!==r?(ae=r("settings.skills.catalog.add.descriptionPrefix"),e[43]=r,e[44]=ae):ae=e[44];let ye;e[45]===Symbol.for("react.memo_cache_sentinel")?(ye=t.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=ye):ye=e[45];let ke;e[46]!==r?(ke=r("settings.skills.catalog.add.descriptionSuffix"),e[46]=r,e[47]=ke):ke=e[47];let he;e[48]!==ae||e[49]!==ke?(he=t.jsxs($t,{children:[ae," ",ye,ke]}),e[48]=ae,e[49]=ke,e[50]=he):he=e[50];let we;e[51]!==be||e[52]!==he?(we=t.jsxs(Kt,{children:[be,he]}),e[51]=be,e[52]=he,e[53]=we):we=e[53];let de;e[54]!==r?(de=r("settings.skills.catalog.add.field.catalogName"),e[54]=r,e[55]=de):de=e[55];let Z;e[56]!==de?(Z=t.jsx("label",{className:"typography-ui-label text-foreground",children:de}),e[56]=de,e[57]=Z):Z=e[57];let se;e[58]===Symbol.for("react.memo_cache_sentinel")?(se=fe=>w(fe.target.value),e[58]=se):se=e[58];let ve;e[59]!==r?(ve=r("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=r,e[60]=ve):ve=e[60];let G;e[61]!==u||e[62]!==ve?(G=t.jsx(Xe,{value:u,onChange:se,placeholder:ve}),e[61]=u,e[62]=ve,e[63]=G):G=e[63];let ee;e[64]!==Z||e[65]!==G?(ee=t.jsxs("div",{className:"space-y-2",children:[Z,G]}),e[64]=Z,e[65]=G,e[66]=ee):ee=e[66];let ie;e[67]!==r?(ie=r("settings.skills.catalog.add.field.repository"),e[67]=r,e[68]=ie):ie=e[68];let pe;e[69]!==ie?(pe=t.jsx("label",{className:"typography-ui-label text-foreground",children:ie}),e[69]=ie,e[70]=pe):pe=e[70];let Ae;e[71]===Symbol.for("react.memo_cache_sentinel")?(Ae=fe=>{f(fe.target.value),Q({clearIdentity:!0})},e[71]=Ae):Ae=e[71];let Se;e[72]!==r?(Se=r("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[72]=r,e[73]=Se):Se=e[73];let De;e[74]!==g||e[75]!==Se?(De=t.jsx(Xe,{value:g,onChange:Ae,placeholder:Se}),e[74]=g,e[75]=Se,e[76]=De):De=e[76];let Me;e[77]!==r?(Me=r("settings.skills.catalog.add.field.repositoryHint"),e[77]=r,e[78]=Me):Me=e[78];let Te;e[79]!==Me?(Te=t.jsx("p",{className:"typography-micro text-muted-foreground",children:Me}),e[79]=Me,e[80]=Te):Te=e[80];let Be;e[81]!==pe||e[82]!==De||e[83]!==Te?(Be=t.jsxs("div",{className:"space-y-2",children:[pe,De,Te]}),e[81]=pe,e[82]=De,e[83]=Te,e[84]=Be):Be=e[84];let ze;e[85]!==r?(ze=r("settings.skills.catalog.add.field.optionalSubpath"),e[85]=r,e[86]=ze):ze=e[86];let Oe;e[87]!==ze?(Oe=t.jsx("label",{className:"typography-ui-label text-foreground",children:ze}),e[87]=ze,e[88]=Oe):Oe=e[88];let $e;e[89]===Symbol.for("react.memo_cache_sentinel")?($e=fe=>{D(fe.target.value),Q({clearIdentity:!0})},e[89]=$e):$e=e[89];let Ke;e[90]!==r?(Ke=r("settings.skills.catalog.shared.field.subpathPlaceholder"),e[90]=r,e[91]=Ke):Ke=e[91];let Ye;e[92]!==x||e[93]!==Ke?(Ye=t.jsx(Xe,{value:x,onChange:$e,placeholder:Ke}),e[92]=x,e[93]=Ke,e[94]=Ye):Ye=e[94];let Re;e[95]!==Oe||e[96]!==Ye?(Re=t.jsxs("div",{className:"space-y-2",children:[Oe,Ye]}),e[95]=Oe,e[96]=Ye,e[97]=Re):Re=e[97];let V;e[98]!==C||e[99]!==K||e[100]!==r?(V=K.length>0&&!ms()?t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:r("settings.skills.catalog.shared.auth.title")}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:r("settings.skills.catalog.shared.auth.description")})]}),t.jsxs(At,{value:C||"",onValueChange:fe=>{A(fe),Q()},children:[t.jsx(Dt,{className:"w-fit",children:t.jsx("span",{children:K.find(fe=>fe.id===C)?.name||r("settings.skills.catalog.shared.auth.chooseIdentity")})}),t.jsx(Et,{align:"start",children:K.map(cf)})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:r("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[98]=C,e[99]=K,e[100]=r,e[101]=V):V=e[101];let oe;e[102]!==N||e[103]!==r?(oe=N!==null?t.jsx("div",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.add.scanResult",{count:N})}):null,e[102]=N,e[103]=r,e[104]=oe):oe=e[104];let ge;e[105]!==O||e[106]!==r?(ge=O?t.jsx("div",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.add.duplicateMessage")}):null,e[105]=O,e[106]=r,e[107]=ge):ge=e[107];let Fe;e[108]!==ee||e[109]!==Be||e[110]!==Re||e[111]!==V||e[112]!==oe||e[113]!==ge?(Fe=t.jsxs("div",{className:"space-y-4",children:[ee,Be,Re,V,oe,ge]}),e[108]=ee,e[109]=Be,e[110]=Re,e[111]=V,e[112]=oe,e[113]=ge,e[114]=Fe):Fe=e[114];let Ne;e[115]!==a?(Ne=()=>a(!1),e[115]=a,e[116]=Ne):Ne=e[116];let He;e[117]!==r?(He=r("settings.common.actions.cancel"),e[117]=r,e[118]=He):He=e[118];let X;e[119]!==Ne||e[120]!==He?(X=t.jsx(q,{size:"sm",variant:"ghost",onClick:Ne,children:He}),e[119]=Ne,e[120]=He,e[121]=X):X=e[121];let v;e[122]!==H?(v=()=>{H()},e[122]=H,e[123]=v):v=e[123];let je;e[124]!==h||e[125]!==g?(je=h||!g.trim(),e[124]=h,e[125]=g,e[126]=je):je=e[126];let Pe;e[127]===Symbol.for("react.memo_cache_sentinel")?(Pe=t.jsx(E,{name:"git-repository",className:"h-4 w-4"}),e[127]=Pe):Pe=e[127];let Le;e[128]!==h||e[129]!==r?(Le=r(h?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[128]=h,e[129]=r,e[130]=Le):Le=e[130];let qe;e[131]!==v||e[132]!==je||e[133]!==Le?(qe=t.jsxs(q,{size:"sm",className:"gap-2",variant:"ghost",onClick:v,disabled:je,children:[Pe,Le]}),e[131]=v,e[132]=je,e[133]=Le,e[134]=qe):qe=e[134];let rt;e[135]!==le?(rt=()=>{le()},e[135]=le,e[136]=rt):rt=e[136];let ot;e[137]!==O||e[138]!==u||e[139]!==j||e[140]!==g?(ot=!j||O||!u.trim()||!g.trim(),e[137]=O,e[138]=u,e[139]=j,e[140]=g,e[141]=ot):ot=e[141];let it;e[142]!==r?(it=r("settings.skills.catalog.add.actions.addCatalog"),e[142]=r,e[143]=it):it=e[143];let dt;e[144]!==rt||e[145]!==ot||e[146]!==it?(dt=t.jsx(q,{size:"sm",onClick:rt,disabled:ot,children:it}),e[144]=rt,e[145]=ot,e[146]=it,e[147]=dt):dt=e[147];let Je;e[148]!==X||e[149]!==qe||e[150]!==dt?(Je=t.jsxs(Gt,{children:[X,qe,dt]}),e[148]=X,e[149]=qe,e[150]=dt,e[151]=Je):Je=e[151];let _e;e[152]!==we||e[153]!==Fe||e[154]!==Je?(_e=t.jsxs(Ft,{className:"max-w-xl",children:[we,Fe,Je]}),e[152]=we,e[153]=Fe,e[154]=Je,e[155]=_e):_e=e[155];let gt;return e[156]!==a||e[157]!==n||e[158]!==_e?(gt=t.jsx(Rt,{open:n,onOpenChange:a,children:_e}),e[156]=a,e[157]=n,e[158]=_e,e[159]=gt):gt=e[159],gt};function tf(s){return s.scanRepo}function sf(s){return s.loadCatalog}function nf(s){return s.loadSource}function af(s){return s.setSelectedSource}function rf(s){return s.isScanning}function of(s){return s.defaultGitIdentityId}function lf(s){return s.loadDefaultGitIdentityId}function cf(s){return t.jsx(mt,{value:s.id,children:s.name},s.id)}const df=s=>{const e=et.c(85),{open:n,onOpenChange:a,conflicts:r,onConfirm:i}=s,{t:l}=st();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];const[c,h]=o.useState(d);let m,p;e[1]!==r||e[2]!==n?(m=()=>{if(!n)return;const le={};for(const ne of r)le[ne.skillName]="skip";h(le)},p=[n,r],e[1]=r,e[2]=n,e[3]=m,e[4]=p):(m=e[3],p=e[4]),o.useEffect(m,p);let u;e[5]!==r?(u=le=>{const ne={};for(const be of r)ne[be.skillName]=le;h(ne)},e[5]=r,e[6]=u):u=e[6];const w=u;let g;e[7]!==r||e[8]!==c?(g=r.length>0&&r.every(le=>c[le.skillName]),e[7]=r,e[8]=c,e[9]=g):g=e[9];const f=g;let x;e[10]!==l?(x=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=x):x=e[11];let D;e[12]!==x?(D=t.jsx(zt,{children:x}),e[12]=x,e[13]=D):D=e[13];let P;e[14]!==l?(P=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=P):P=e[15];let I;e[16]!==P?(I=t.jsx($t,{children:P}),e[16]=P,e[17]=I):I=e[17];let L;e[18]!==D||e[19]!==I?(L=t.jsxs(Kt,{children:[D,I]}),e[18]=D,e[19]=I,e[20]=L):L=e[20];let N;e[21]!==r.length||e[22]!==l?(N=l("settings.skills.catalog.conflicts.count",{count:r.length}),e[21]=r.length,e[22]=l,e[23]=N):N=e[23];let b;e[24]!==N?(b=t.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[24]=N,e[25]=b):b=e[25];let j;e[26]!==w?(j=()=>w("skip"),e[26]=w,e[27]=j):j=e[27];let T;e[28]!==l?(T=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=T):T=e[29];let U;e[30]!==j||e[31]!==T?(U=t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:j,children:T}),e[30]=j,e[31]=T,e[32]=U):U=e[32];let K;e[33]!==w?(K=()=>w("overwrite"),e[33]=w,e[34]=K):K=e[34];let M;e[35]!==l?(M=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=M):M=e[36];let C;e[37]!==K||e[38]!==M?(C=t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:K,children:M}),e[37]=K,e[38]=M,e[39]=C):C=e[39];let A;e[40]!==U||e[41]!==C?(A=t.jsxs("div",{className:"flex items-center gap-2",children:[U,C]}),e[40]=U,e[41]=C,e[42]=A):A=e[42];let z;e[43]!==b||e[44]!==A?(z=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[b,A]}),e[43]=b,e[44]=A,e[45]=z):z=e[45];let R;if(e[46]!==r||e[47]!==c||e[48]!==l){let le;e[50]!==c||e[51]!==l?(le=ne=>t.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label truncate",children:ne.skillName}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:ne.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:ne.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),t.jsxs(At,{value:c[ne.skillName]||"skip",onValueChange:be=>h(ae=>({...ae,[ne.skillName]:be})),children:[t.jsx(Dt,{className:"w-fit",children:t.jsx("span",{className:"capitalize",children:(c[ne.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),t.jsxs(Et,{align:"end",children:[t.jsx(mt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),t.jsx(mt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},ne.skillName),e[50]=c,e[51]=l,e[52]=le):le=e[52],R=r.map(le),e[46]=r,e[47]=c,e[48]=l,e[49]=R}else R=e[49];let Q;e[53]!==R?(Q=t.jsx("div",{className:"space-y-2",children:R}),e[53]=R,e[54]=Q):Q=e[54];let W;e[55]!==z||e[56]!==Q?(W=t.jsxs("div",{className:"space-y-3",children:[z,Q]}),e[55]=z,e[56]=Q,e[57]=W):W=e[57];let te;e[58]!==a?(te=()=>a(!1),e[58]=a,e[59]=te):te=e[59];let Y;e[60]!==l?(Y=l("settings.common.actions.cancel"),e[60]=l,e[61]=Y):Y=e[61];let k;e[62]!==te||e[63]!==Y?(k=t.jsx(q,{size:"sm",variant:"ghost",onClick:te,children:Y}),e[62]=te,e[63]=Y,e[64]=k):k=e[64];let $;e[65]!==c||e[66]!==i?($=()=>i(c),e[65]=c,e[66]=i,e[67]=$):$=e[67];const B=!f;let F;e[68]!==l?(F=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=F):F=e[69];let O;e[70]!==$||e[71]!==B||e[72]!==F?(O=t.jsx(q,{size:"sm",onClick:$,disabled:B,children:F}),e[70]=$,e[71]=B,e[72]=F,e[73]=O):O=e[73];let J;e[74]!==k||e[75]!==O?(J=t.jsxs(Gt,{children:[k,O]}),e[74]=k,e[75]=O,e[76]=J):J=e[76];let H;e[77]!==L||e[78]!==W||e[79]!==J?(H=t.jsxs(Ft,{className:"max-w-2xl",children:[L,W,J]}),e[77]=L,e[78]=W,e[79]=J,e[80]=H):H=e[80];let re;return e[81]!==a||e[82]!==n||e[83]!==H?(re=t.jsx(Rt,{open:n,onOpenChange:a,children:H}),e[81]=a,e[82]=n,e[83]=H,e[84]=re):re=e[84],re},Mi=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function ba(s,e){return s==="project"&&e==="claude"?"project-claude":s==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":s==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Ac(s){if(s==="user-claude")return{scope:"user",source:"claude"};if(s==="project-claude")return{scope:"project",source:"claude"};const e=Mi.find(n=>n.value===s);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const uf=s=>{const e=et.c(124),{open:n,onOpenChange:a,item:r}=s,{t:i}=st(),l=Ys(mf),d=Ys(pf),[c,h]=o.useState("user"),[m,p]=o.useState("opencode"),u=es(gf),w=es(hf),[g,f]=o.useState(null),[x,D]=o.useState(!1);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P=[],e[0]=P):P=e[0];const[I,L]=o.useState(P),[N,b]=o.useState(null);let j,T;e[1]!==w||e[2]!==n?(j=()=>{n&&(h("user"),p("opencode"),f(w),D(!1),L([]),b(null))},T=[n,w],e[1]=w,e[2]=n,e[3]=j,e[4]=T):(j=e[3],T=e[4]),o.useEffect(j,T);let U;e[5]!==i?(U=Re=>{switch(Re){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=U):U=e[6];const K=U;let M;e[7]!==i?(M=Re=>{switch(Re){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=M):M=e[8];const C=M;let A;e:{if(u.length===0){A=null;break e}if(g&&u.some(Re=>Re.id===g)){A=g;break e}if(w&&u.some(Re=>Re.id===w)){A=w;break e}A=u[0]?.id??null}const z=A;let R;e:{if(c!=="project"){R=null;break e}const Re=z;if(!Re){R=null;break e}let V;if(e[9]!==Re||e[10]!==u){let ge;e[12]!==Re?(ge=Fe=>Fe.id===Re,e[12]=Re,e[13]=ge):ge=e[13],V=u.find(ge),e[9]=Re,e[10]=u,e[11]=V}else V=e[11];R=V?.path??null}const Q=R;let W;e[14]!==l||e[15]!==r||e[16]!==a||e[17]!==i?(W=async Re=>{const V={skillDir:Re.skillDir};r?.clawdhub&&(V.clawdhub={slug:r.clawdhub.slug,version:r.clawdhub.version});const oe=await l({source:Re.source,subpath:Re.subpath,gitIdentityId:r?.gitIdentityId,scope:Re.scope,targetSource:Re.targetSource,selections:[V],conflictPolicy:"prompt",conflictDecisions:Re.conflictDecisions},{directory:Re.directoryOverride??null});if(oe.ok){_.success(i("settings.skills.catalog.installSkill.toast.installed")),a(!1);return}if(oe.error?.kind==="conflicts"){b({source:Re.source,subpath:Re.subpath,scope:Re.scope,targetSource:Re.targetSource,skillDir:Re.skillDir,directoryOverride:Re.directoryOverride??null}),L(oe.error.conflicts),D(!0);return}if(oe.error?.kind==="authRequired"){_.error(oe.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}_.error(oe.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=r,e[16]=a,e[17]=i,e[18]=W):W=e[18];const te=W;if(!r)return null;let Y;e[19]!==i?(Y=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=Y):Y=e[20];let k;e[21]!==Y?(k=t.jsx(zt,{children:Y}),e[21]=Y,e[22]=k):k=e[22];let $;e[23]!==i?($=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=$):$=e[24];let B;e[25]!==r.skillName?(B=t.jsx("span",{className:"font-semibold text-foreground",children:r.skillName}),e[25]=r.skillName,e[26]=B):B=e[26];let F;e[27]!==i?(F=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=F):F=e[28];let O;e[29]!==$||e[30]!==B||e[31]!==F?(O=t.jsxs($t,{children:[$," ",B," ",F]}),e[29]=$,e[30]=B,e[31]=F,e[32]=O):O=e[32];let J;e[33]!==k||e[34]!==O?(J=t.jsxs(Kt,{children:[k,O]}),e[33]=k,e[34]=O,e[35]=J):J=e[35];let H;e[36]!==i?(H=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=H):H=e[37];let re;e[38]!==H?(re=t.jsx("span",{className:"typography-ui-label text-foreground",children:H}),e[38]=H,e[39]=re):re=e[39];let le;e[40]!==c||e[41]!==m?(le=ba(c,m),e[40]=c,e[41]=m,e[42]=le):le=e[42];let ne;e[43]===Symbol.for("react.memo_cache_sentinel")?(ne=Re=>{const V=Ac(Re);h(V.scope),p(V.source==="agents"?"agents":"opencode")},e[43]=ne):ne=e[43];let be;e[44]!==c?(be=c==="user"?t.jsx(E,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=be):be=e[45];let ae;e[46]!==m?(ae=m==="agents"?t.jsx(E,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=ae):ae=e[47];let ye;e[48]!==K||e[49]!==c||e[50]!==m?(ye=K(ba(c,m)),e[48]=K,e[49]=c,e[50]=m,e[51]=ye):ye=e[51];let ke;e[52]!==ye?(ke=t.jsx("span",{children:ye}),e[52]=ye,e[53]=ke):ke=e[53];let he;e[54]!==be||e[55]!==ae||e[56]!==ke?(he=t.jsxs(Dt,{className:"w-fit gap-1.5",children:[be,ae,ke]}),e[54]=be,e[55]=ae,e[56]=ke,e[57]=he):he=e[57];let we;e[58]!==C||e[59]!==K?(we=Mi.map(Re=>t.jsx(mt,{value:Re.value,className:"pr-2 [&>span:first-child]:hidden",children:t.jsxs("div",{className:"flex flex-col gap-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[Re.scope==="user"?t.jsx(E,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"folder",className:"h-3.5 w-3.5"}),Re.source==="agents"?t.jsx(E,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:K(Re.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:C(Re.value)})]})},Re.value)),e[58]=C,e[59]=K,e[60]=we):we=e[60];let de;e[61]!==we?(de=t.jsx(Et,{align:"start",children:we}),e[61]=we,e[62]=de):de=e[62];let Z;e[63]!==le||e[64]!==he||e[65]!==de?(Z=t.jsxs(At,{value:le,onValueChange:ne,children:[he,de]}),e[63]=le,e[64]=he,e[65]=de,e[66]=Z):Z=e[66];let se;e[67]!==re||e[68]!==Z?(se=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[re,Z]}),e[67]=re,e[68]=Z,e[69]=se):se=e[69];let ve;e[70]!==u||e[71]!==z||e[72]!==c||e[73]!==i?(ve=c==="project"&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),u.length===0?t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):t.jsxs(At,{value:z??"",onValueChange:Re=>f(Re),disabled:u.length===1,children:[t.jsx(Dt,{className:"w-fit",children:t.jsx(Ot,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),t.jsx(Et,{align:"start",children:u.map(ff)})]})]}),e[70]=u,e[71]=z,e[72]=c,e[73]=i,e[74]=ve):ve=e[74];let G;e[75]!==r.warnings?(G=r.warnings?.length?t.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:r.warnings.join(" · ")}):null,e[75]=r.warnings,e[76]=G):G=e[76];let ee;e[77]!==se||e[78]!==ve||e[79]!==G?(ee=t.jsxs("div",{className:"mt-2 space-y-3",children:[se,ve,G]}),e[77]=se,e[78]=ve,e[79]=G,e[80]=ee):ee=e[80];let ie;e[81]!==a?(ie=()=>a(!1),e[81]=a,e[82]=ie):ie=e[82];let pe;e[83]!==i?(pe=i("settings.common.actions.cancel"),e[83]=i,e[84]=pe):pe=e[84];let Ae;e[85]!==ie||e[86]!==pe?(Ae=t.jsx(q,{size:"sm",variant:"ghost",onClick:ie,children:pe}),e[85]=ie,e[86]=pe,e[87]=Ae):Ae=e[87];const Se=d||!r.installable||c==="project"&&!Q;let De;e[88]!==Q||e[89]!==te||e[90]!==r.repoSource||e[91]!==r.repoSubpath||e[92]!==r.skillDir||e[93]!==c||e[94]!==m?(De=()=>{te({source:r.repoSource,subpath:r.repoSubpath,scope:c,targetSource:m,skillDir:r.skillDir,directoryOverride:Q})},e[88]=Q,e[89]=te,e[90]=r.repoSource,e[91]=r.repoSubpath,e[92]=r.skillDir,e[93]=c,e[94]=m,e[95]=De):De=e[95];let Me;e[96]!==d||e[97]!==i?(Me=i(d?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=d,e[97]=i,e[98]=Me):Me=e[98];let Te;e[99]!==Se||e[100]!==De||e[101]!==Me?(Te=t.jsx(q,{size:"sm",disabled:Se,onClick:De,children:Me}),e[99]=Se,e[100]=De,e[101]=Me,e[102]=Te):Te=e[102];let Be;e[103]!==Ae||e[104]!==Te?(Be=t.jsxs(Gt,{children:[Ae,Te]}),e[103]=Ae,e[104]=Te,e[105]=Be):Be=e[105];let ze;e[106]!==J||e[107]!==ee||e[108]!==Be?(ze=t.jsxs(Ft,{className:"max-w-md",children:[J,ee,Be]}),e[106]=J,e[107]=ee,e[108]=Be,e[109]=ze):ze=e[109];let Oe;e[110]!==a||e[111]!==n||e[112]!==ze?(Oe=t.jsx(Rt,{open:n,onOpenChange:a,children:ze}),e[110]=a,e[111]=n,e[112]=ze,e[113]=Oe):Oe=e[113];let $e;e[114]!==N||e[115]!==te?($e=Re=>{N&&(te({source:N.source,subpath:N.subpath,scope:N.scope,targetSource:N.targetSource,skillDir:N.skillDir,conflictDecisions:Re,directoryOverride:N.directoryOverride??null}),D(!1))},e[114]=N,e[115]=te,e[116]=$e):$e=e[116];let Ke;e[117]!==I||e[118]!==x||e[119]!==$e?(Ke=t.jsx(df,{open:x,onOpenChange:D,conflicts:I,onConfirm:$e}),e[117]=I,e[118]=x,e[119]=$e,e[120]=Ke):Ke=e[120];let Ye;return e[121]!==Oe||e[122]!==Ke?(Ye=t.jsxs(t.Fragment,{children:[Oe,Ke]}),e[121]=Oe,e[122]=Ke,e[123]=Ye):Ye=e[123],Ye};function mf(s){return s.installSkills}function pf(s){return s.isInstalling}function gf(s){return s.projects}function hf(s){return s.activeProjectId}function ff(s){return t.jsx(mt,{value:s.id,children:s.label||s.path},s.id)}const xf=async()=>{try{const s=Vs()?.settings;if(s)return(await s.load())?.settings||{};const e=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},yf=({mode:s,onModeChange:e,showModeTabs:n=!0})=>{const{t:a}=st(),{sources:r,itemsBySource:i,selectedSourceId:l,setSelectedSource:d,loadCatalog:c,loadSource:h,loadMoreClawdHub:m,isLoadingCatalog:p,isLoadingSource:u,isLoadingMore:w,loadedSourceIds:g,clawdhubHasMoreBySource:f,lastCatalogError:x}=Ys(Ps(k=>({sources:k.sources,itemsBySource:k.itemsBySource,selectedSourceId:k.selectedSourceId,setSelectedSource:k.setSelectedSource,loadCatalog:k.loadCatalog,loadSource:k.loadSource,loadMoreClawdHub:k.loadMoreClawdHub,isLoadingCatalog:k.isLoadingCatalog,isLoadingSource:k.isLoadingSource,isLoadingMore:k.isLoadingMore,loadedSourceIds:k.loadedSourceIds,clawdhubHasMoreBySource:k.clawdhubHasMoreBySource,lastCatalogError:k.lastCatalogError}))),[D,P]=o.useState(""),[I,L]=o.useState(!1),[N,b]=o.useState(!1),[j,T]=o.useState(null),[U,K]=o.useState(!1),[M,C]=o.useState(!1);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{l&&(g[l]||h(l))},[l,g,h]);const A=o.useMemo(()=>l?i[l]||[]:[],[i,l]),z=o.useMemo(()=>{const k=D.trim().toLowerCase();return k?A.filter($=>{const B=$.skillName.toLowerCase(),F=($.description||"").toLowerCase(),O=($.frontmatterName||"").toLowerCase();return B.includes(k)||F.includes(k)||O.includes(k)}):A},[A,D]),R=o.useMemo(()=>r.find(k=>k.id===l)||null,[r,l]),Q=!!(l&&l.startsWith("custom:")),W=R?.source==="clawdhub:registry"||R?.sourceType==="clawdhub",te=!!(l&&(f[l]??!0)),Y=async()=>{if(!(!l||!Q)){K(!0);try{const k=await xf(),B=(Array.isArray(k?.skillCatalogs)?k?.skillCatalogs:[]).filter(F=>F.id!==l);await Nt({skillCatalogs:B}),await c({refresh:!0}),C(!1)}finally{K(!1)}}};return t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsxs("div",{className:"mb-4",children:[n&&t.jsx("div",{className:"mb-4",children:t.jsx("div",{className:"h-10",children:t.jsx(Fn,{items:[{id:"manual",label:a("settings.skills.catalog.page.mode.manual")},{id:"external",label:a("settings.skills.catalog.page.mode.external")}],activeId:s,onSelect:k=>e(k),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground px-1",children:a("settings.skills.catalog.page.title")})]}),t.jsxs("div",{"data-settings-item":"skills.catalog.source",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:a("settings.skills.catalog.page.section.sourceRepository")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[t.jsxs(At,{value:l||"",onValueChange:k=>d(k),children:[t.jsx(Dt,{className:"w-fit",children:t.jsx(Ot,{placeholder:a("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:R?.label})}),t.jsx(Et,{align:"start",children:r.map(k=>t.jsx(mt,{value:k.id,children:k.label},k.id))})]}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l?h(l,{refresh:!0}):c({refresh:!0})},disabled:p||u,title:a("settings.skills.catalog.page.actions.refreshTitle"),children:t.jsx(E,{name:"refresh",className:ce("h-3.5 w-3.5",(p||u)&&"animate-spin")})}),Q&&t.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>C(!0),disabled:U,title:a("settings.skills.catalog.page.actions.removeCatalogTitle"),children:t.jsx(E,{name:"delete-bin",className:"h-3.5 w-3.5"})}),t.jsxs(q,{"data-settings-item":"skills.catalog.add-catalog",size:"xs",className:"!font-normal gap-1",onClick:()=>L(!0),children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"})," ",a("settings.skills.catalog.page.actions.addCatalog")]})]}),t.jsxs("div",{"data-settings-item":"skills.catalog.search",className:"py-1.5",children:[t.jsxs("div",{className:"relative",children:[t.jsx(E,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),t.jsx(Xe,{value:D,onChange:k=>P(k.target.value),placeholder:a("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),t.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:p?a("settings.skills.catalog.page.loading.catalog"):a("settings.skills.catalog.page.foundCount",{count:z.length})})]})]})]}),x&&t.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[t.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:a("settings.skills.catalog.page.error.catalogTitle")}),t.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x.message})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("section",{className:"px-2 pb-2 pt-0",children:z.length===0&&!u?t.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[t.jsx("p",{className:"typography-body",children:a("settings.skills.catalog.page.empty.noSkillsTitle")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.skills.catalog.page.empty.noSkillsDescription")})]}):u?t.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[t.jsx(E,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),t.jsx("p",{className:"typography-meta",children:a("settings.skills.catalog.page.loading.skills")})]}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:z.map(k=>{const $=k.installed?.isInstalled,B=k.installed?.scope;return t.jsx("div",{className:"py-2",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:k.skillName}),$&&t.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:a("settings.skills.catalog.page.badge.installed",{scope:B||a("settings.skills.catalog.page.badge.unknown")})}),!k.installable&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:a("settings.skills.catalog.page.badge.notInstallable")})]}),k.description?t.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:k.description}):t.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:a("settings.skills.catalog.shared.noDescription")}),k.clawdhub&&t.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[k.clawdhub.owner&&t.jsxs("span",{children:[a("settings.skills.catalog.page.byOwnerPrefix")," ",t.jsx("span",{className:"font-medium text-foreground/80",children:k.clawdhub.owner})]}),t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(E,{name:"download",className:"h-3 w-3"}),k.clawdhub.downloads?.toLocaleString()??0]}),(k.clawdhub.stars??0)>0&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(E,{name:"star",className:"h-3 w-3"}),k.clawdhub.stars]}),t.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",k.clawdhub.version]})]}),k.warnings?.length?t.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:k.warnings.join(" · ")}):null]}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!k.installable,onClick:()=>{T(k),b(!0)},children:a("settings.skills.catalog.shared.actions.install")})]})},`${k.sourceId}:${k.skillDir}`)})})}),W&&te&&!u&&z.length>0&&t.jsx("div",{className:"flex justify-center mt-2 px-2",children:t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:w,children:a(w?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),t.jsx(ef,{open:I,onOpenChange:L}),t.jsx(uf,{open:N,onOpenChange:b,item:j}),t.jsx(Rt,{open:M,onOpenChange:k=>{U||C(k)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:a("settings.skills.catalog.page.removeDialog.title")}),t.jsx($t,{children:a("settings.skills.catalog.page.removeDialog.description")})]}),t.jsxs(Gt,{children:[t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>C(!1),disabled:U,children:a("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",variant:"destructive",onClick:()=>{Y()},disabled:U,children:a("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})};function nl(s,e){const n=s.metadata.variant==="dark",a=s.config?.fonts?.mono||"monospace",r=s.colors.syntax.highlights||{},i=s.colors.syntax.tokens||{},l=e?.fontSize?`${e.fontSize}px`:"var(--text-code)",d=Bs.theme({"&":{backgroundColor:"var(--background)",color:s.colors.syntax.base.foreground,fontSize:l,lineHeight:"1.5",position:"relative"},".cm-scroller":{fontFamily:a,backgroundColor:"var(--background)"},".cm-comment":{color:s.colors.syntax.base.comment},".cm-keyword":{color:s.colors.syntax.base.keyword},".cm-string":{color:s.colors.syntax.base.string},".cm-string-2":{color:i.stringEscape||s.colors.syntax.base.string},".cm-number":{color:s.colors.syntax.base.number},".cm-operator":{color:s.colors.syntax.base.operator},".cm-punctuation":{color:i.punctuation||s.colors.syntax.base.comment},".cm-atom":{color:i.boolean||s.colors.syntax.base.number},".cm-builtin":{color:i.functionCall||s.colors.syntax.base.function},".cm-def":{color:i.variableGlobal||s.colors.syntax.base.variable},".cm-attribute":{color:i.variableOther||i.variableProperty||s.colors.syntax.base.operator},".cm-meta":{color:s.colors.syntax.base.comment},".cm-property":{color:i.variableProperty||s.colors.syntax.base.keyword},".cm-variable":{color:s.colors.syntax.base.variable},".cm-variable-2":{color:i.variableOther||s.colors.syntax.base.function},".cm-variable-3":{color:i.variableGlobal||s.colors.syntax.base.type},".cm-tag":{color:i.tag||s.colors.syntax.base.keyword},".cm-link":{color:i.url||s.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:s.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:s.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:s.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||s.colors.syntax.base.comment,borderRight:`1px solid ${s.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||s.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:s.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:s.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${s.colors.interactive.border}`,backgroundColor:s.colors.surface.elevated,color:s.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${s.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${s.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${s.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:s.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${s.colors.interactive.border}`,backgroundColor:s.colors.surface.background,color:s.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:s.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:s.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:s.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:s.colors.interactive.hover,borderColor:s.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:s.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:s.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:s.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:s.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:s.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:s.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:s.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:s.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${s.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:s.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:s.colors.interactive.hover,color:s.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:s.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${s.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:s.colors.interactive.selection,color:s.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${s.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:n}),c=Vi.define([{tag:[Ee.comment,Ee.docComment,Ee.meta,Ee.documentMeta],class:"cm-comment"},{tag:[Ee.keyword,Ee.controlKeyword,Ee.moduleKeyword,Ee.definitionKeyword,Ee.modifier],class:"cm-keyword"},{tag:[Ee.operatorKeyword,Ee.operator,Ee.derefOperator,Ee.updateOperator,Ee.definitionOperator,Ee.typeOperator,Ee.controlOperator,Ee.logicOperator,Ee.bitwiseOperator,Ee.arithmeticOperator,Ee.compareOperator],class:"cm-operator"},{tag:[Ee.punctuation,Ee.separator,Ee.bracket,Ee.paren,Ee.brace,Ee.squareBracket,Ee.angleBracket],class:"cm-punctuation"},{tag:[Ee.string,Ee.regexp,Ee.attributeValue,Ee.special(Ee.string),Ee.monospace],class:"cm-string"},{tag:Ee.escape,class:"cm-string-2"},{tag:[Ee.number,Ee.bool,Ee.atom,Ee.null,Ee.self],class:"cm-number"},{tag:[Ee.function(Ee.variableName),Ee.function(Ee.definition(Ee.variableName)),Ee.function(Ee.propertyName),Ee.standard(Ee.variableName),Ee.special(Ee.variableName)],class:"cm-builtin"},{tag:Ee.definition(Ee.variableName),class:"cm-def"},{tag:[Ee.variableName,Ee.local(Ee.variableName),Ee.constant(Ee.variableName),Ee.literal],class:"cm-variable"},{tag:Ee.propertyName,class:"cm-property"},{tag:Ee.attributeName,class:"cm-attribute"},{tag:[Ee.className,Ee.typeName,Ee.namespace],class:"cm-variable-3"},{tag:[Ee.tagName,Ee.labelName,Ee.annotation,Ee.macroName],class:"cm-tag"},{tag:Ee.link,class:"cm-link"},{tag:[Ee.heading,Ee.heading1,Ee.heading2,Ee.heading3,Ee.heading4,Ee.heading5,Ee.heading6],class:"cm-keyword"}]),h=Vi.define([{tag:[Ee.comment,Ee.docComment,Ee.meta,Ee.documentMeta],color:s.colors.syntax.base.comment},{tag:[Ee.keyword,Ee.controlKeyword,Ee.moduleKeyword,Ee.definitionKeyword,Ee.modifier],color:s.colors.syntax.base.keyword},{tag:[Ee.operatorKeyword,Ee.operator,Ee.derefOperator,Ee.updateOperator,Ee.definitionOperator,Ee.typeOperator,Ee.controlOperator,Ee.logicOperator,Ee.bitwiseOperator,Ee.arithmeticOperator,Ee.compareOperator],color:s.colors.syntax.base.operator},{tag:[Ee.string,Ee.regexp,Ee.attributeValue,Ee.special(Ee.string),Ee.monospace],color:s.colors.syntax.base.string},{tag:Ee.escape,color:i.stringEscape||s.colors.syntax.base.string},{tag:[Ee.number,Ee.bool,Ee.atom,Ee.null,Ee.self],color:s.colors.syntax.base.number},{tag:[Ee.function(Ee.variableName),Ee.function(Ee.definition(Ee.variableName)),Ee.function(Ee.propertyName),Ee.standard(Ee.variableName),Ee.special(Ee.variableName)],color:s.colors.syntax.base.function},{tag:Ee.definition(Ee.variableName),color:i.variableGlobal||s.colors.syntax.base.variable},{tag:[Ee.variableName,Ee.local(Ee.variableName),Ee.constant(Ee.variableName),Ee.literal],color:s.colors.syntax.base.variable},{tag:Ee.propertyName,color:i.variableProperty||s.colors.syntax.base.variable},{tag:Ee.attributeName,color:i.variableOther||s.colors.syntax.base.variable},{tag:[Ee.className,Ee.typeName,Ee.namespace],color:s.colors.syntax.base.type},{tag:[Ee.tagName,Ee.labelName,Ee.annotation,Ee.macroName],color:i.tag||s.colors.syntax.base.keyword},{tag:Ee.link,color:i.url||s.colors.syntax.base.function,textDecoration:"underline"},{tag:[Ee.punctuation,Ee.separator,Ee.bracket,Ee.paren,Ee.brace,Ee.squareBracket,Ee.angleBracket],color:i.punctuation||s.colors.syntax.base.comment}]);return e?.syntaxColors===!1?[d]:[d,Ia(Hd,{fallback:!0}),Ia(Wd),Ia(c),Ia(h)]}const bf=180,Dc=Gd.define(),vf=1,jf=2,wf=4,al=new Map,Nf=(s,e)=>{const n=`${s}|${e}`,a=al.get(n);if(a)return a;let r="";s&&(r+=`color:${s};`),e&vf&&(r+="font-style:italic;"),e&jf&&(r+="font-weight:bold;"),e&wf&&(r+="text-decoration:underline;");const i=or.mark({attributes:{style:r}});return al.set(n,i),i},kf=(s,e)=>{const n=new Pi,a=s.state.doc,r=Math.min(e.length,a.lines);for(let i=0;i<r;i+=1){const l=e[i];if(!l||l.length===0)continue;const d=a.line(i+1);let c=d.from;for(const[h,m,p]of l){if(h<=0)continue;const u=c,w=Math.min(c+h,d.to);c+=h,!(w<=u)&&(!m&&!p||n.add(u,w,Nf(m,p)))}}return n.finish()},Sf=tc.define({create(){return or.none},update(s,e){let n=s.map(e.changes);for(const a of e.effects)a.is(Dc)&&(n=a.value);return n},provide:s=>Bs.decorations.from(s)}),Cf=s=>ec.fromClass(class{timer;generation=0;constructor(e){this.tokenize(e)}update(e){e.docChanged&&this.schedule(e.view)}schedule(e){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.tokenize(e)},bf)}async tokenize(e){const n=++this.generation,a=e.state.doc.toString(),r=await Su(a,s.language,s.themeName,s.theme);r&&n===this.generation&&e.state.doc.length===a.length&&e.dispatch({effects:Dc.of(kf(e,r))})}destroy(){this.timer&&clearTimeout(this.timer)}}),If=s=>[Sf,Cf(s)],Pf=()=>{const s=et.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(yf,{mode:"external",onModeChange:Rf,showModeTabs:!1}),s[0]=e):e=s[0],e},Af="SKILL.md",Df="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",Xa=(s,e)=>{const n=qd({description:s}).trimEnd(),a=e.trimStart();return`---
|
|
23
|
+
${n}
|
|
24
|
+
---${a?`
|
|
25
|
+
|
|
26
|
+
${a}`:`
|
|
27
|
+
`}`},Ef=s=>typeof s=="object"&&s!==null&&!Array.isArray(s),Ec=s=>{const e=s.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:s};let n=null;try{const a=Jd(e[1]);if(Ef(a)){const r=a.description;typeof r=="string"&&(n=r)}}catch{n=null}return{description:n,instructions:e[2].replace(/^\r?\n/,"")}},Mf=(s,e)=>{const n=Ec(s);return Xa(e,n.instructions)},Tf=()=>{const{t:s}=st(),{currentTheme:e}=ur(),{selectedSkillName:n,getSkillByName:a,getSkillDetail:r,createSkill:i,updateSkill:l,skills:d,skillDraft:c,setSkillDraft:h,setSelectedSkill:m}=Zs(Ps(V=>({selectedSkillName:V.selectedSkillName,getSkillByName:V.getSkillByName,getSkillDetail:V.getSkillDetail,createSkill:V.createSkill,updateSkill:V.updateSkill,skills:V.skills,skillDraft:V.skillDraft,setSkillDraft:V.setSkillDraft,setSelectedSkill:V.setSelectedSkill}))),p=n?a(n):null,u=!!(c&&c.name===n&&!p),w=!!(n&&!p&&!c),g=p?.path==="<built-in>";o.useEffect(()=>{w&&m(null)},[w,m]);const[f,x]=o.useState(""),[D,P]=o.useState("user"),[I,L]=o.useState("opencode"),[N,b]=o.useState(""),[j,T]=o.useState(""),[U,K]=o.useState(()=>Xa("","")),[M,C]=o.useState("edit"),[A,z]=o.useState([]),[R,Q]=o.useState([]),[W,te]=o.useState(!1),[Y,k]=o.useState(!1),[$,B]=o.useState(""),[F,O]=o.useState(""),[J,H]=o.useState(!1),[re,le]=o.useState(""),[ne,be]=o.useState(""),[ae,ye]=o.useState(null),[ke,he]=o.useState(!1),[we,de]=o.useState(""),[Z,se]=o.useState(null),[ve,G]=o.useState(!1),ee=u?f.trim()!==""||N.trim()!==""||j.trim()!==""||R.length>0:N!==$||j!==F,ie=ae?ne!==we:re.trim()!=="",pe=o.useCallback(V=>{switch(V){case"project-opencode":return s("settings.skills.location.option.projectOpencode.label");case"user-claude":return s("settings.skills.location.option.userClaude.label");case"project-claude":return s("settings.skills.location.option.projectClaude.label");case"user-agents":return s("settings.skills.location.option.userAgents.label");case"project-agents":return s("settings.skills.location.option.projectAgents.label");default:return s("settings.skills.location.option.userOpencode.label")}},[s]),Ae=o.useCallback(V=>{switch(V){case"project-opencode":return s("settings.skills.location.option.projectOpencode.description");case"user-claude":return s("settings.skills.location.option.userClaude.description");case"project-claude":return s("settings.skills.location.option.projectClaude.description");case"user-agents":return s("settings.skills.location.option.userAgents.description");case"project-agents":return s("settings.skills.location.option.projectAgents.description");default:return s("settings.skills.location.option.userOpencode.description")}},[s]);o.useEffect(()=>{(async()=>{if(u&&c){const oe=c.description||"",ge=c.instructions||"";x(c.name||""),P(c.scope||"user"),L(c.source==="agents"?"agents":"opencode"),b(oe),T(ge),K(Xa(oe,ge)),B(""),O(""),z([]),Q(c.pendingFiles||[])}else if(n&&p){k(!0);try{const oe=await r(n);if(oe){const ge=oe.sources.md,Fe=ge.description||"",Ne=ge.instructions||"";b(Fe),T(Ne),K(Xa(Fe,Ne)),B(Fe),O(Ne),z(ge.supportingFiles||[])}}catch(oe){console.error("Failed to load skill details:",oe)}finally{k(!1)}}})()},[p,u,n,d,c,r]);const Se=Ie(V=>V.editorFontSize),De=o.useMemo(()=>{const V=[nl(e,{fontSize:Se})],oe=Hi(Af);return oe&&V.push(oe),V.push(Bs.lineWrapping),V},[e,Se]),Me=o.useMemo(()=>{const V=re.trim()||"supporting-file.md",oe=Cu(V),ge=!!oe&&oe!=="markdown",Fe=[nl(e,ge?{syntaxColors:!1,fontSize:Se}:{fontSize:Se})],Ne=Hi(V);return Ne&&Fe.push(Ne),ge&&oe&&Fe.push(If({language:oe,themeName:e.metadata.id,theme:oi(e)})),Fe.push(Bs.lineWrapping),Fe},[e,re,Se]),Te=o.useCallback(V=>{b(V),K(oe=>Mf(oe,V))},[]),Be=o.useCallback(V=>{K(V);const oe=Ec(V);b(oe.description??""),T(oe.instructions)},[]),ze=async()=>{const V=u?f.trim().replace(/\s+/g,"-").toLowerCase():n?.trim();if(!V){_.error(s("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(V)||V.length>64){_.error(s("settings.skills.page.toast.invalidSkillName"));return}if(!N.trim()){_.error(s("settings.skills.page.toast.descriptionRequired"));return}if(u&&d.some(oe=>oe.name===V)){_.error(s("settings.skills.page.toast.skillExists"));return}te(!0);try{const oe={name:V,description:N.trim(),instructions:j.trim()||void 0,scope:u?D:void 0,source:u?I:void 0,targetPath:u?void 0:p?.path,supportingFiles:u&&R.length>0?R:void 0};let ge;u?(ge=await i(oe),ge&&(h(null),Q([]),m(V))):(ge=await l(V,oe),ge&&(B(N.trim()),O(j.trim()))),ge?_.success(s(u?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):_.error(s(u?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(oe){console.error("Error saving skill:",oe),_.error(s("settings.skills.page.toast.saveUnexpectedError"))}finally{te(!1)}},Oe=()=>{ye(null),le(""),be(""),de(""),H(!0)},$e=async V=>{if(ye(V),le(V),u){const ge=R.find(Fe=>Fe.path===V)?.content||"";be(ge),de(ge),H(!0);return}if(n){he(!0),H(!0);try{const{readSupportingFile:oe}=Zs.getState(),ge=await oe(n,V);be(ge||""),de(ge||"")}catch{_.error(s("settings.skills.page.toast.loadFileContentFailed")),be(""),de("")}finally{he(!1)}}},Ke=async()=>{if(!re.trim()){_.error(s("settings.skills.page.toast.fileNameRequired"));return}const V=re.trim(),oe=ae!==null;if(u){if(oe)Q(Ne=>Ne.map(He=>He.path===ae?{path:V,content:ne}:He)),_.success(s("settings.skills.page.toast.fileUpdated",{path:V}));else{if(R.some(Ne=>Ne.path===V)){_.error(s("settings.skills.page.toast.fileExists"));return}Q(Ne=>[...Ne,{path:V,content:ne}]),_.success(s("settings.skills.page.toast.fileAdded",{path:V}))}H(!1),ye(null);return}if(!n){_.error(s("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:ge}=Zs.getState();if(await ge(n,V,ne)){_.success(oe?s("settings.skills.page.toast.fileUpdated",{path:V}):s("settings.skills.page.toast.fileCreated",{path:V})),H(!1),ye(null);const Ne=await r(n);Ne&&z(Ne.sources.md.supportingFiles||[])}else _.error(s(oe?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ye=V=>{if(u){Q(oe=>oe.filter(ge=>ge.path!==V)),_.success(s("settings.skills.page.toast.fileRemoved",{path:V}));return}n&&se(V)},Re=async()=>{if(!Z||!n)return;G(!0);const{deleteSupportingFile:V}=Zs.getState();if(await V(n,Z)){_.success(s("settings.skills.page.toast.fileDeleted",{path:Z}));const ge=await r(n);ge&&z(ge.sources.md.supportingFiles||[]),se(null)}else _.error(s("settings.skills.page.toast.deleteFileFailed"));G(!1)};return!n&&!c||w?t.jsx("div",{className:"flex h-full items-center justify-center px-4",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(E,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.skills.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.skills.page.empty.description")})]})}):Y?t.jsx("div",{className:"flex h-full items-center justify-center px-4",children:t.jsx("div",{className:"text-center text-muted-foreground",children:t.jsx("p",{className:"typography-body",children:s("settings.skills.page.loading.details")})})}):t.jsxs(_t,{outerClassName:"h-full",className:"w-full",children:[t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:u?s("settings.skills.page.title.newSkill"):n}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:p?s("settings.skills.page.subtitle.skillLocation",{location:pe(ba(p.scope,p.source))}):s("settings.skills.page.subtitle.newSkill")})]})}),t.jsxs("div",{"data-settings-item":"skills.basic-information",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.skills.page.section.basicInformation")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[u&&t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.skills.page.field.skillNameLocation")}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:s("settings.skills.page.field.skillNameHint")}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[t.jsx(Xe,{value:f,onChange:V=>x(V.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:s("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),t.jsxs(At,{value:ba(D,I),onValueChange:V=>{const oe=Ac(V);P(oe.scope),L(oe.source==="agents"?"agents":"opencode")},children:[t.jsxs(Dt,{className:"w-fit gap-1.5",children:[D==="user"?t.jsx(E,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"folder",className:"h-3.5 w-3.5"}),I==="agents"?t.jsx(E,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:pe(ba(D,I))})]}),t.jsx(Et,{align:"start",children:Mi.map(V=>t.jsx(mt,{value:V.value,children:t.jsxs("div",{className:"flex flex-col gap-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[V.scope==="user"?t.jsx(E,{name:"user-3",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"folder",className:"h-3.5 w-3.5"}),V.source==="agents"?t.jsx(E,{name:"robot-2",className:"h-3.5 w-3.5"}):null,t.jsx("span",{children:pe(V.value)})]}),t.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ae(V.value)})]})},V.value))})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsxs("span",{className:"typography-ui-label text-foreground",children:[s("settings.common.field.description")," ",t.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:s("settings.skills.page.field.descriptionHint")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(us,{value:N,onChange:V=>Te(V.target.value),placeholder:s("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:g})})]})]})]}),t.jsxs("div",{"data-settings-item":"skills.instructions",className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.skills.page.section.instructions")}),t.jsx(Qh,{currentMode:M==="preview"?"preview":"edit",onToggle:()=>C(V=>V==="preview"?"edit":"preview")})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx("div",{className:ce("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Df),children:M==="preview"?t.jsx(_t,{outerClassName:"h-full",className:"h-full",children:t.jsx("div",{className:"min-h-full px-4 py-3",children:t.jsx(ii,{content:U,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):t.jsx(sl,{value:U,onChange:Be,readOnly:g,extensions:De,className:"h-full",enableSearch:!0})})})]}),t.jsxs("div",{"data-settings-item":"skills.supporting-files",className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.skills.page.section.supportingFiles")}),t.jsxs(q,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Oe,disabled:g,children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"})," ",s("settings.skills.page.actions.addFile")]})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:(()=>{const V=u?R:A;return V.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:s("settings.skills.page.supportingFiles.empty")}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:V.map(oe=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>$e(oe.path),children:[t.jsx(E,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:oe.path}),u&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:s("settings.skills.page.badge.pending")}),!g&&t.jsx(q,{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:ge=>{ge.stopPropagation(),Ye(oe.path)},children:t.jsx(E,{name:"delete-bin",className:"h-3 w-3"})})]},oe.path))})})()})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(q,{onClick:ze,disabled:g||W||!ee,size:"xs",className:"!font-normal",children:s(W?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),t.jsx(Rt,{open:Z!==null,onOpenChange:V=>{!V&&!ve&&se(null)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("settings.skills.page.deleteFileDialog.title")}),t.jsx($t,{children:s("settings.skills.page.deleteFileDialog.description",{path:Z??""})})]}),t.jsxs(Gt,{children:[t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>se(null),disabled:ve,children:s("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",variant:"destructive",onClick:Re,disabled:ve,children:s("settings.common.actions.delete")})]})]})}),t.jsx(Rt,{open:J,onOpenChange:V=>{H(V),V||ye(null)},children:t.jsxs(Ft,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[t.jsxs(Kt,{className:"flex-shrink-0",children:[t.jsx(zt,{children:s(ae?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),t.jsx($t,{children:s(ae?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),ke?t.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.skills.page.loading.fileContent")})}):t.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[t.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:s("settings.skills.page.fileDialog.field.filePath")}),t.jsx(Xe,{value:re,onChange:V=>le(V.target.value),placeholder:s("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:ae!==null}),!ae&&t.jsx("p",{className:"typography-micro text-muted-foreground",children:s("settings.skills.page.fileDialog.field.filePathHint")})]}),t.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground flex-shrink-0",children:s("settings.skills.page.fileDialog.field.content")}),t.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:t.jsx(sl,{value:ne,onChange:be,extensions:Me,className:"h-full",enableSearch:!0})})]})]}),t.jsxs(Gt,{className:"mt-4",children:[t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>{H(!1),ye(null)},children:s("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",onClick:Ke,disabled:ke||!ie,children:s(ae?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},rl=s=>{const e=et.c(2),{view:n}=s,a=n===void 0?"installed":n;let r;return e[0]!==a?(r=a==="catalog"?t.jsx(Pf,{}):t.jsx(Tf,{}),e[0]=a,e[1]=r):r=e[1],r};function Rf(){}const Ff=s=>{const e=et.c(38),{onItemSelect:n}=s,{t:a}=st(),r=es(Lf),i=Ie(Of),l=Ie(zf),{currentTheme:d}=ur();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=ms(),e[0]=c):c=e[0];const h=c,m=Kf;let p,u;e[1]!==r||e[2]!==i||e[3]!==l?(p=()=>{if(r.length===0){i!==null&&l(null);return}i&&r.some(j=>j.id===i)||l(r[0].id)},u=[r,i,l],e[1]=r,e[2]=i,e[3]=l,e[4]=p,e[5]=u):(p=e[4],u=e[5]),o.useEffect(p,u);let w;e[6]===Symbol.for("react.memo_cache_sentinel")?(w=ce("border-b px-3","pt-4 pb-3"),e[6]=w):w=e[6];let g;e[7]!==a?(g=a("settings.page.projects.title"),e[7]=a,e[8]=g):g=e[8];let f;e[9]!==g?(f=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[9]=g,e[10]=f):f=e[10];let x;e[11]!==r.length||e[12]!==a?(x=a("settings.projects.sidebar.total",{count:r.length}),e[11]=r.length,e[12]=a,e[13]=x):x=e[13];let D;e[14]!==x?(D=t.jsx("span",{className:"typography-meta text-muted-foreground",children:x}),e[14]=x,e[15]=D):D=e[15];let P;e[16]!==a?(P=!h&&t.jsx(q,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:m,"aria-label":a("settings.projects.sidebar.actions.addProject"),children:t.jsx(E,{name:"add",className:"size-4"})}),e[16]=a,e[17]=P):P=e[17];let I;e[18]!==D||e[19]!==P?(I=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[D,P]}),e[18]=D,e[19]=P,e[20]=I):I=e[20];let L;e[21]!==I||e[22]!==f?(L=t.jsxs("div",{className:w,children:[f,I]}),e[21]=I,e[22]=f,e[23]=L):L=e[23];let N;if(e[24]!==d||e[25]!==n||e[26]!==r||e[27]!==i||e[28]!==l){let j;e[30]!==d||e[31]!==n||e[32]!==i||e[33]!==l?(j=T=>{const U=T.id===i,K=T.icon?Iu[T.icon]:null,M=T.color?lc[T.color]??null:null,C=K?t.jsx(E,{name:K,className:ce("h-4 w-4",U?"text-foreground":"text-muted-foreground/70"),style:M?{color:M}:void 0}):t.jsx(E,{name:"folder",className:ce("h-4 w-4",U?"text-foreground":"text-muted-foreground/70"),style:M?{color:M}:void 0}),A=T.iconImage?t.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:T.iconBackground?{backgroundColor:T.iconBackground}:void 0,children:t.jsx(cc,{project:T,options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:C})}):C;return t.jsx(yi,{title:T.label||T.path,icon:A,selected:U,onSelect:()=>{l(T.id),n?.()}},T.id)},e[30]=d,e[31]=n,e[32]=i,e[33]=l,e[34]=j):j=e[34],N=r.map(j),e[24]=d,e[25]=n,e[26]=r,e[27]=i,e[28]=l,e[29]=N}else N=e[29];let b;return e[35]!==L||e[36]!==N?(b=t.jsx(Ic,{variant:"background",header:L,children:N}),e[35]=L,e[36]=N,e[37]=b):b=e[37],b};function Lf(s){return s.projects}function Of(s){return s.settingsProjectsSelectedId}function zf(s){return s.setSettingsProjectsSelectedId}function Kf(){oc.requestDirectoryDialog()}const wa="w-full max-w-[30rem]",en=s=>{const e=et.c(27),{title:n,description:a,settingsItem:r,titleAccessory:i,headerAction:l,children:d,className:c,contentClassName:h}=s;let m;e[0]!==c?(m=ce("border-b border-border/50 py-5 first:pt-0 last:border-b-0",c),e[0]=c,e[1]=m):m=e[1];let p;e[2]!==n?(p=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:n}),e[2]=n,e[3]=p):p=e[3];let u;e[4]!==p||e[5]!==i?(u=t.jsxs("div",{className:"flex items-center gap-2",children:[p,i]}),e[4]=p,e[5]=i,e[6]=u):u=e[6];let w;e[7]!==a?(w=a?t.jsx("p",{className:"mt-0.5 typography-meta text-muted-foreground",children:a}):null,e[7]=a,e[8]=w):w=e[8];let g;e[9]!==u||e[10]!==w?(g=t.jsxs("div",{className:"min-w-0 flex-1",children:[u,w]}),e[9]=u,e[10]=w,e[11]=g):g=e[11];let f;e[12]!==l?(f=l?t.jsx("div",{className:"shrink-0",children:l}):null,e[12]=l,e[13]=f):f=e[13];let x;e[14]!==g||e[15]!==f?(x=t.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3 px-1",children:[g,f]}),e[14]=g,e[15]=f,e[16]=x):x=e[16];let D;e[17]!==h?(D=ce("space-y-2 px-2",h),e[17]=h,e[18]=D):D=e[18];let P;e[19]!==d||e[20]!==D?(P=t.jsx("div",{className:D,children:d}),e[19]=d,e[20]=D,e[21]=P):P=e[21];let I;return e[22]!==r||e[23]!==m||e[24]!==x||e[25]!==P?(I=t.jsxs("section",{"data-settings-item":r,className:m,children:[x,P]}),e[22]=r,e[23]=m,e[24]=x,e[25]=P,e[26]=I):I=e[26],I},Uf=450,Bf=({projectRef:s=null})=>{const{t:e}=st(),{isMobile:n,isTablet:a}=Ds(),r=n||a,i=es(B=>B.getActiveProject()),l=s?.path??i?.path??null,d=fs(B=>B.getWorktreeMetadata),c=Pu(),h=ws(B=>B.homeDirectory),[m,p]=o.useState([]),[u,w]=o.useState(!1),[g,f]=o.useState(!1),[x,D]=o.useState(null),[P,I]=o.useState(null),[L,N]=o.useState([]),[b,j]=o.useState(!1),T=o.useRef(!1),U=o.useMemo(()=>s?.id&&s?.path?{id:s.id,path:s.path}:!i?.id||!l?null:{id:i.id,path:l},[i?.id,l,s?.id,s?.path]),K=o.useCallback(async()=>{if(!(!U||P===!1))try{const B=await Wi(U);N(B)}catch{}},[U,P]);o.useEffect(()=>{if(!l)return;let B=!1;return I(null),(async()=>{try{const F=await Au(l);if(B)return;I(F)}catch{}})(),()=>{B=!0}},[l]),o.useEffect(()=>{if(!U){N([]),j(!1);return}if(P===!1){N([]),j(!1);return}let B=!1;return j(!0),N([]),(async()=>{try{const F=await Wi(U);if(B)return;N(F)}catch{}finally{B||j(!1)}})(),()=>{B=!0}},[U,P]),o.useEffect(()=>{if(!U)return;let B=!1;return f(!0),(async()=>{try{const[F,O]=await Promise.all([dc(U),uc(U)]);if(!B){const J=F.length>0?F:[""];p(J),D(JSON.stringify(J)),w(O)}}catch{B||(p([""]),D(JSON.stringify([""])),w(!1))}finally{B||f(!1)}})(),()=>{B=!0}},[U]);const M=o.useCallback(async B=>{if(!U)return!1;const F=B.filter(O=>O.trim().length>0);try{return await Du(U,F)?(D(JSON.stringify(B)),!0):(_.error(e("settings.openchamber.worktrees.setup.toast.saveFailed")),!1)}catch{return _.error(e("settings.openchamber.worktrees.setup.toast.saveFailed")),!1}},[U,e]),C=o.useMemo(()=>x===null?!1:x!==JSON.stringify(m),[x,m]);o.useEffect(()=>{if(!C||g||T.current)return;const B=window.setTimeout(()=>{T.current||(T.current=!0,(async()=>{try{await M(m)}finally{T.current=!1}})())},Uf);return()=>{window.clearTimeout(B)}},[C,g,M,m]);const A=o.useCallback((B,F)=>{p(O=>{const J=[...O];return J[B]=F,J})},[]),z=o.useCallback(()=>{p(B=>[...B,""])},[]),R=o.useCallback(B=>{p(F=>{const O=F.filter((J,H)=>H!==B);return O.length>0?O:[""]})},[]),Q=o.useCallback(()=>{!C||T.current||(T.current=!0,(async()=>{try{await M(m)}finally{T.current=!1}})())},[C,M,m]),W=o.useCallback(B=>{w(B),U&&Eu(U,B)},[U]),te=o.useCallback(B=>{const F=ye=>ye.replace(/\\/g,"/").replace(/\/+$/,""),O=F(B.path),J=c.filter(ye=>{const ke=d(ye.id);if(ke?.path&&F(ke.path)===O)return!0;const he=ye.directory;return!!(he&&F(he)===O)}),H=new Set(J.map(ye=>ye.id)),re=[...li.getState().activeSessions,...li.getState().archivedSessions],le=ye=>{const ke=re.filter(we=>{const de=we.parentID;return de&&ye.has(de)});if(ke.length===0)return[];const he=new Set(ke.map(we=>we.id));return[...ke,...le(he)]},ne=le(H),be=new Set,ae=[...J,...ne].filter(ye=>be.has(ye.id)?!1:(be.add(ye.id),!0));oc.requestDelete({sessions:ae,mode:"worktree",worktree:B})},[c,d]),Y=o.useMemo(()=>c.map(B=>B.id).join(","),[c]);o.useEffect(()=>{P&&l&&K()},[Y,P,l,K]);const k=t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(It,{sideOffset:8,className:"max-w-xs",children:[e("settings.openchamber.worktrees.setup.tooltipPrefix")," ",t.jsx("code",{className:"font-mono text-xs bg-sidebar-accent/50 px-1 rounded",children:"$ROOT_PROJECT_PATH"})," ",e("settings.openchamber.worktrees.setup.tooltipSuffix")]})]}),$=t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]});return l?P===!1?t.jsx(en,{title:e("settings.projects.page.section.worktree"),settingsItem:"projects.worktree",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")})}):t.jsxs(t.Fragment,{children:[t.jsx(en,{title:e("settings.projects.page.section.worktree"),settingsItem:"projects.worktree",titleAccessory:k,children:g?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.setup.loading")}):t.jsxs("div",{className:ce("space-y-2",wa),children:[m.map((B,F)=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(Xe,{value:B,onChange:O=>A(F,O.target.value),onBlur:Q,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 min-w-0 flex-1 font-mono text-xs"}),t.jsx("button",{type:"button",onClick:()=>R(F),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:t.jsx(E,{name:"close",className:"h-4 w-4"})})]},F)),t.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:z,children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),e("settings.openchamber.worktrees.setup.addCommand")]}),t.jsxs("label",{"data-settings-item":"projects.worktree.setup.wait",className:"flex cursor-pointer items-center gap-2 py-1",children:[t.jsx(yt,{checked:u,onChange:W,ariaLabel:e("settings.openchamber.worktrees.setup.waitForCommandsAria")}),t.jsx("span",{className:ce("typography-ui-label font-normal",u?"text-foreground":"text-foreground/60"),children:e("settings.openchamber.worktrees.setup.waitForCommands")})]})]})}),t.jsx(en,{title:e("settings.openchamber.worktrees.list.title"),titleAccessory:$,children:b?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.list.loading")}):L.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:e("settings.openchamber.worktrees.list.empty")}):t.jsx("div",{className:ce("space-y-1",wa),children:L.map(B=>t.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("p",{className:"typography-meta min-w-0 truncate text-foreground",children:B.label||B.branch||e("settings.openchamber.worktrees.list.detachedHead")}),t.jsx("span",{className:"typography-micro flex-shrink-0 self-center rounded bg-sidebar-accent/40 px-1.5 py-[1px] leading-none text-muted-foreground/60",children:"OpenCode"})]}),t.jsx("p",{className:"typography-micro truncate text-muted-foreground/60",children:Mu(B.path,h)})]}),t.jsx("button",{type:"button",onClick:()=>te(B),className:ce("flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground/50 transition-opacity hover:bg-destructive/10 hover:text-destructive focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",r?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:B.branch||B.label||B.path}),children:t.jsx(E,{name:"delete-bin",className:"h-4 w-4"})})]},B.path))})})]}):t.jsx(en,{title:e("settings.projects.page.section.worktree"),settingsItem:"projects.worktree",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})})},il=(s,e)=>e.updatedAtMs-s.updatedAtMs,os=wn((s,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){s({isLoading:!0,error:null});try{const[n,a]=await Promise.all([Lu(),qi()]),r={};for(const i of a.sort(il))r[i.id]=i;e().listenerReady||await Ou(i=>{s(l=>({statusesById:{...l.statusesById,[i.id]:i}}))}),s({instances:n.instances,statusesById:r,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){s({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){s({isImportsLoading:!0,error:null});try{const n=await Fu();s({importCandidates:n,isImportsLoading:!1})}catch(n){s({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await qi(),a={};for(const r of n.sort(il))a[r.id]=r;s({statusesById:a})}catch(n){s({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{s({isSaving:!0,error:null});try{await Ru({instances:n}),s({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(a){throw s({isSaving:!1,error:a instanceof Error?a.message:String(a)}),a}},upsertInstance:async n=>{const a=e().instances,r=a.some(i=>i.id===n.id)?a.map(i=>i.id===n.id?n:i):[n,...a];await e().setInstances(r)},createFromCommand:async(n,a,r)=>{const i=zu(n,a);r&&r.trim()&&(i.nickname=r.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await Gi(n).catch(()=>{});const a=e().instances.filter(r=>r.id!==n);await e().setInstances(a),s(r=>{const i={...r.statusesById};return delete i[n],{statusesById:i}})},connect:async n=>{s({error:null});try{await Tu(n),await e().refreshStatuses()}catch(a){throw s({error:a instanceof Error?a.message:String(a)}),a}},disconnect:async n=>{s({error:null});try{await Gi(n),await e().refreshStatuses()}catch(a){throw s({error:a instanceof Error?a.message:String(a)}),a}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>s({error:null})})),Mc=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],$f=Object.fromEntries(Mc.map(s=>[s.key,s.Icon])),Vf="openchamber:project-actions-updated",_f=s=>{const e=(s||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},Qj=(s,e)=>`${_f(s)}::${e}`,Hf=s=>{const e=s.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},ol=s=>{if(typeof s!="number"||!Number.isFinite(s))return null;const e=Math.round(s);return e<1||e>65535?null:e},Wf=(s,e)=>{if(!e.enabled||e.type!=="local")return null;const n=ol(e.localPort),a=ol(e.remotePort);if(!n||!a)return null;const r=Hf(e.localHost||s.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),l=(s.nickname||s.id||"instance").trim();return{id:`${s.id}::${e.id}`,label:`${l} - ${r}:${n} -> ${i}:${a}`,url:`http://${r}:${n}`}},Tc=s=>{const e=[];for(const n of s)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const a of n.portForwards){const r=Wf(n,a);r&&e.push(r)}return e},Yj=(s,e)=>{const n=(s||"").trim();return n&&Tc(e).find(i=>i.id===n)?.url||null},Gf=450,qf=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,Jf=()=>({id:qf(),name:"",command:"",icon:"play"}),Qf=({projectRef:s})=>{const{t:e}=st(),n=o.useMemo(()=>ns(),[]),a=os(b=>b.instances),r=os(b=>b.load),[i,l]=o.useState([]),[d,c]=o.useState(!1),[h,m]=o.useState(null),[p,u]=o.useState({}),w=o.useRef(!1),g=o.useRef(null);o.useEffect(()=>{n&&r().catch(()=>{})},[n,r]),o.useEffect(()=>{let b=!1;return c(!0),(async()=>{try{const j=await Ku(s);if(b)return;l(j.actions),m(JSON.stringify({actions:j.actions}))}catch{if(b)return;l([]),m(JSON.stringify({actions:[]}))}finally{b||c(!1)}})(),()=>{b=!0}},[s]);const f=o.useMemo(()=>n?Tc(a):[],[a,n]),x=o.useMemo(()=>i.some(j=>j.name.trim().length===0||j.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),D=o.useMemo(()=>h===null?!1:h!==JSON.stringify({actions:i}),[i,h]),P=o.useCallback(async b=>await Uu(s,{actions:b,primaryActionId:null})?(m(JSON.stringify({actions:b})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Vf,{detail:{projectId:s.id}})),!0):(_.error(e("settings.projects.actions.toast.saveFailed")),!1),[s,e]);o.useEffect(()=>{if(!D||d||x||w.current)return;const b=window.setTimeout(()=>{w.current||(w.current=!0,(async()=>{try{await P(i)}finally{w.current=!1}})())},Gf);return()=>{window.clearTimeout(b)}},[i,D,d,P,x]),o.useEffect(()=>{if(!D||!x||d){x||(g.current=null);return}const b=window.setTimeout(()=>{g.current!==x&&(g.current=x,_.error(x))},1e3);return()=>{window.clearTimeout(b)}},[D,d,x]);const I=o.useCallback(()=>{const b=Jf();l(j=>[...j,b]),u(j=>({...j,[b.id]:!0}))},[]),L=o.useCallback(b=>{l(j=>j.filter(T=>T.id!==b)),u(j=>{const T={...j};return delete T[b],T})},[]),N=o.useCallback((b,j)=>{l(T=>T.map(U=>U.id===b?j(U):U))},[]);return t.jsxs(en,{title:e("settings.projects.actions.title"),description:e("settings.projects.actions.description"),settingsItem:"projects.actions",headerAction:t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:I,children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]}),contentClassName:"space-y-0",children:[d?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):i.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")}):t.jsx("div",{className:ce("space-y-0",wa),children:i.map(b=>{const j=b.icon||"play",T=$f[j]||"play",U=p[b.id]??!1,K=b.name.trim()||e("settings.projects.actions.state.untitled");return t.jsxs(Mn,{open:U,onOpenChange:M=>{u(C=>({...C,[b.id]:M}))},className:"py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs(Tn,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[U?t.jsx(E,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):t.jsx(E,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),t.jsx(E,{name:T,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:K})})]}),t.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>L(b.id),children:t.jsx(E,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(Rn,{className:"pt-1.5",children:t.jsxs("div",{className:"space-y-2 pb-4 pl-3 pr-1",children:[t.jsxs("div",{className:"flex items-center gap-2 py-1",children:[t.jsxs(ds,{children:[t.jsx(ls,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":e("settings.projects.actions.field.selectIconAria"),children:t.jsx(E,{name:T,className:"h-4 w-4"})})}),t.jsx(cs,{align:"start",className:"w-56 p-2",children:t.jsx("div",{className:"grid grid-cols-6 gap-1",children:Mc.map(M=>{const C=M.Icon,A=(b.icon||"play")===M.key;return t.jsx("button",{type:"button",onClick:()=>N(b.id,z=>({...z,icon:M.key})),className:ce("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",A&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:M.label}),children:t.jsx(E,{name:C,className:"h-4 w-4"})},M.key)})})})]}),t.jsx(Xe,{value:b.name,onChange:M=>N(b.id,C=>({...C,name:M.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 flex-1 min-w-0"})]}),t.jsxs("div",{className:"py-1",children:[t.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),t.jsx(us,{value:b.command,onChange:M=>N(b.id,C=>({...C,command:M.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] w-full font-mono text-xs"})]}),t.jsxs("div",{className:"py-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":b.autoOpenUrl===!0,onClick:()=>N(b.id,M=>({...M,...M.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),N(b.id,C=>({...C,...C.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[t.jsx(yt,{checked:b.autoOpenUrl===!0,onChange:M=>N(b.id,C=>({...C,...M?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:K})}),t.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),b.autoOpenUrl===!0?t.jsxs("div",{className:"mt-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xe,{value:b.openUrl||"",onChange:M=>N(b.id,C=>({...C,openUrl:M.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]})]}),n?t.jsxs("div",{className:"mt-2",children:[t.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),f.length>0?t.jsxs(At,{value:b.desktopOpenSshForward&&f.some(M=>M.id===b.desktopOpenSshForward)?b.desktopOpenSshForward:"__none__",onValueChange:M=>{N(b.id,C=>({...C,...M==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:M}}))},children:[t.jsx(Dt,{className:"h-7 w-full",children:t.jsx(Ot,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),f.map(M=>t.jsx(mt,{value:M.id,children:M.label},M.id))]})]}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},b.id)})}),x&&i.length>0?t.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:x}):null]})},Yf=s=>{const e=et.c(122),{form:n}=s,{t:a}=st(),{currentTheme:r}=ur(),{name:i,setName:l,icon:d,setIcon:c,color:h,setColor:m,iconBackground:p,setIconBackground:u,parsedDefaultModel:w,handleDefaultModelChange:g,isUploadingIcon:f,isRemovingCustomIcon:x,isDiscoveringIcon:D,pendingRemoveImageIcon:P,setPendingRemoveImageIcon:I,pendingUploadIconPreviewUrl:L,setPreviewImageFailed:N,hasPendingUploadImageIcon:b,hasCustomIcon:j,effectiveHasImageIcon:T,hasRemovableImageIcon:U,showImagePreview:K,fileInputRef:M,handleUploadIcon:C,handleRemoveImageIcon:A,handleDiscoverIcon:z,currentIconImage:R,project:Q}=n;if(!Q)return null;const W=h?lc[h]??null:null;let te;e[0]!==a?(te=a("settings.projects.page.field.projectName"),e[0]=a,e[1]=te):te=e[1];let Y;e[2]!==l?(Y=oe=>l(oe.target.value),e[2]=l,e[3]=Y):Y=e[3];let k;e[4]!==a?(k=a("settings.projects.page.field.projectNamePlaceholder"),e[4]=a,e[5]=k):k=e[5];let $;e[6]===Symbol.for("react.memo_cache_sentinel")?($=ce("h-7",wa),e[6]=$):$=e[6];let B;e[7]!==i||e[8]!==Y||e[9]!==k?(B=t.jsx(Xe,{value:i,onChange:Y,placeholder:k,className:$}),e[7]=i,e[8]=Y,e[9]=k,e[10]=B):B=e[10];let F;e[11]!==te||e[12]!==B?(F=t.jsx(en,{title:te,settingsItem:"projects.name",children:B}),e[11]=te,e[12]=B,e[13]=F):F=e[13];let O;e[14]!==a?(O=a("settings.projects.page.field.defaultModel"),e[14]=a,e[15]=O):O=e[15];let J;e[16]!==a?(J=a("settings.projects.page.field.defaultModelDescription"),e[16]=a,e[17]=J):J=e[17];let H;e[18]!==g||e[19]!==w.modelId||e[20]!==w.providerId?(H=t.jsx(ja,{providerId:w.providerId,modelId:w.modelId,onChange:g,className:wa}),e[18]=g,e[19]=w.modelId,e[20]=w.providerId,e[21]=H):H=e[21];let re;e[22]!==O||e[23]!==J||e[24]!==H?(re=t.jsx(en,{title:O,description:J,settingsItem:"projects.default-model",children:H}),e[22]=O,e[23]=J,e[24]=H,e[25]=re):re=e[25];let le;e[26]!==a?(le=a("settings.projects.page.field.accentColor"),e[26]=a,e[27]=le):le=e[27];let ne;e[28]!==m?(ne=()=>m(null),e[28]=m,e[29]=ne):ne=e[29];const be=h===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let ae;e[30]!==be?(ae=ce("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",be),e[30]=be,e[31]=ae):ae=e[31];let ye;e[32]!==a?(ye=a("settings.projects.page.field.none"),e[32]=a,e[33]=ye):ye=e[33];let ke;e[34]===Symbol.for("react.memo_cache_sentinel")?(ke=t.jsx(E,{name:"close",className:"h-4 w-4 text-muted-foreground"}),e[34]=ke):ke=e[34];let he;e[35]!==ne||e[36]!==ae||e[37]!==ye?(he=t.jsx("button",{type:"button",onClick:ne,className:ae,title:ye,children:ke}),e[35]=ne,e[36]=ae,e[37]=ye,e[38]=he):he=e[38];let we;e[39]!==h||e[40]!==m?(we=Bu.map(oe=>t.jsx("button",{type:"button",onClick:()=>m(oe.key),className:ce("h-7 w-7 rounded-md border transition-colors",h===oe.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:oe.cssVar},title:oe.label},oe.key)),e[39]=h,e[40]=m,e[41]=we):we=e[41];let de;e[42]!==he||e[43]!==we?(de=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[he,we]}),e[42]=he,e[43]=we,e[44]=de):de=e[44];let Z;e[45]!==le||e[46]!==de?(Z=t.jsx(en,{title:le,settingsItem:"projects.accent-color",children:de}),e[45]=le,e[46]=de,e[47]=Z):Z=e[47];let se;e[48]!==a?(se=a("settings.projects.page.field.projectIcon"),e[48]=a,e[49]=se):se=e[49];let ve;e[50]!==C?(ve=oe=>{const ge=oe.target.files?.[0]??null;C(ge),oe.currentTarget.value=""},e[50]=C,e[51]=ve):ve=e[51];let G;e[52]!==M||e[53]!==ve?(G=t.jsx("input",{ref:M,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:ve}),e[52]=M,e[53]=ve,e[54]=G):G=e[54];let ee;e[55]!==c?(ee=()=>c(null),e[55]=c,e[56]=ee):ee=e[56];const ie=d===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let pe;e[57]!==ie?(pe=ce("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",ie),e[57]=ie,e[58]=pe):pe=e[58];let Ae;e[59]!==a?(Ae=a("settings.projects.page.field.none"),e[59]=a,e[60]=Ae):Ae=e[60];let Se;e[61]===Symbol.for("react.memo_cache_sentinel")?(Se=t.jsx(E,{name:"close",className:"h-4 w-4 text-muted-foreground"}),e[61]=Se):Se=e[61];let De;e[62]!==ee||e[63]!==pe||e[64]!==Ae?(De=t.jsx("button",{type:"button",onClick:ee,className:pe,title:Ae,children:Se}),e[62]=ee,e[63]=pe,e[64]=Ae,e[65]=De):De=e[65];let Me;e[66]!==W||e[67]!==d||e[68]!==c?(Me=$u.map(oe=>{const ge=oe.Icon;return t.jsx("button",{type:"button",onClick:()=>c(oe.key),className:ce("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",d===oe.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:oe.label,children:t.jsx(E,{name:ge,className:"w-4 h-4",style:W&&d===oe.key?{color:W}:void 0})},oe.key)}),e[66]=W,e[67]=d,e[68]=c,e[69]=Me):Me=e[69];let Te;e[70]!==De||e[71]!==Me?(Te=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[De,Me]}),e[70]=De,e[71]=Me,e[72]=Te):Te=e[72];let Be;e[73]!==R||e[74]!==r||e[75]!==T||e[76]!==b||e[77]!==p||e[78]!==L||e[79]!==Q||e[80]!==N||e[81]!==K||e[82]!==a?(Be=T&&K&&t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:a("settings.projects.page.field.preview")}),t.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/60 bg-[var(--surface-elevated)] p-1",children:t.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:p?{backgroundColor:p}:void 0,children:b&&L?t.jsx("img",{src:L,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>N(!0)}):t.jsx(cc,{project:{...Q,iconImage:R??Q.iconImage},options:{themeVariant:r.metadata.variant,iconColor:r.colors.surface.foreground},className:"h-full w-full object-contain",onError:()=>N(!0)})})})]}),e[73]=R,e[74]=r,e[75]=T,e[76]=b,e[77]=p,e[78]=L,e[79]=Q,e[80]=N,e[81]=K,e[82]=a,e[83]=Be):Be=e[83];let ze;e[84]!==T||e[85]!==p||e[86]!==u||e[87]!==a?(ze=T&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("input",{type:"color",value:p??"#000000",onChange:oe=>u(oe.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":a("settings.projects.page.field.projectIconBackgroundAria")}),t.jsx(Xe,{value:p??"",onChange:oe=>u(oe.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),t.jsx(q,{type:"button",size:"xs",variant:"outline",onClick:()=>u(null),className:"h-7 w-7 p-0","aria-label":a("settings.projects.page.field.clearIconBackgroundAria"),title:a("settings.projects.page.field.clearBackground"),disabled:!p,children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})})]}),e[84]=T,e[85]=p,e[86]=u,e[87]=a,e[88]=ze):ze=e[88];let Oe;e[89]!==M||e[90]!==z||e[91]!==j||e[92]!==D||e[93]!==f||e[94]!==a?(Oe=!j&&t.jsxs(t.Fragment,{children:[t.jsx(q,{size:"xs",className:"h-6 !font-normal",onClick:()=>M.current?.click(),disabled:f,children:a(f?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),t.jsx(q,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{z()},disabled:D,children:a(D?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),e[89]=M,e[90]=z,e[91]=j,e[92]=D,e[93]=f,e[94]=a,e[95]=Oe):Oe=e[95];let $e;e[96]!==A||e[97]!==U||e[98]!==x||e[99]!==a?($e=U&&t.jsx(q,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{A()},disabled:x,children:a(x?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),e[96]=A,e[97]=U,e[98]=x,e[99]=a,e[100]=$e):$e=e[100];let Ke;e[101]!==x||e[102]!==P||e[103]!==I||e[104]!==a?(Ke=P&&t.jsx(q,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>I(!1),disabled:x,children:a("settings.projects.page.actions.undoRemove")}),e[101]=x,e[102]=P,e[103]=I,e[104]=a,e[105]=Ke):Ke=e[105];let Ye;e[106]!==Oe||e[107]!==$e||e[108]!==Ke?(Ye=t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Oe,$e,Ke]}),e[106]=Oe,e[107]=$e,e[108]=Ke,e[109]=Ye):Ye=e[109];let Re;e[110]!==se||e[111]!==G||e[112]!==Te||e[113]!==Be||e[114]!==ze||e[115]!==Ye?(Re=t.jsxs(en,{title:se,settingsItem:"projects.icon",children:[G,Te,Be,ze,Ye]}),e[110]=se,e[111]=G,e[112]=Te,e[113]=Be,e[114]=ze,e[115]=Ye,e[116]=Re):Re=e[116];let V;return e[117]!==re||e[118]!==Z||e[119]!==Re||e[120]!==F?(V=t.jsxs(t.Fragment,{children:[F,re,Z,Re]}),e[117]=re,e[118]=Z,e[119]=Re,e[120]=F,e[121]=V):V=e[121],V},Xf=/^#(?:[\da-fA-F]{3}|[\da-fA-F]{6})$/,Zf=s=>{if(!s)return null;const e=s.trim();return e&&Xf.test(e)?e.toLowerCase():null},ex=s=>{const{t:e}=st(),n=es(ae=>ae.uploadProjectIcon),a=es(ae=>ae.removeProjectIcon),r=es(ae=>ae.discoverProjectIcon),i=es(ae=>s?ae.projects.find(ye=>ye.id===s.id)?.iconImage??null:null),[l,d]=o.useState(""),[c,h]=o.useState(null),[m,p]=o.useState(null),[u,w]=o.useState(null),[g,f]=o.useState(void 0),[x,D]=o.useState(!1),[P,I]=o.useState(!1),[L,N]=o.useState(!1),[b,j]=o.useState(!1),[T,U]=o.useState(null),[K,M]=o.useState(null),[C,A]=o.useState(!1),z=o.useRef(null),R=o.useCallback(()=>{U(null),M(ae=>(ae&&URL.revokeObjectURL(ae),null))},[]),Q=s?.id??null;o.useEffect(()=>{if(!s){d(""),h(null),p(null),w(null),f(void 0);return}d(s.label??""),h(s.icon??null),p(s.color??null),w(s.iconBackground??null),f(s.defaultModel),j(!1),R(),A(!1)},[s,R]),o.useEffect(()=>()=>{R()},[R]);const W=o.useMemo(()=>fn(g)??{providerId:"",modelId:""},[g]),te=!!s?.iconImage,Y=!!(T&&K),k=s?.iconImage?.source==="custom",$=te&&!b||Y,B=$,F=!!(s&&te&&!b),O=!C&&(Y||F),J=!!s&&(l.trim()!==(s?.label??"").trim()||c!==(s?.icon??null)||m!==(s?.color??null)||u!==(s?.iconBackground??null)||(g??void 0)!==(s?.defaultModel??void 0)||b||!!T),H=o.useCallback((ae,ye)=>{f(ae&&ye?`${ae}/${ye}`:void 0)},[]),re=o.useCallback(ae=>{!s||!ae||x||(j(!1),A(!1),U(ae),M(ye=>(ye&&URL.revokeObjectURL(ye),URL.createObjectURL(ae))))},[x,s]),le=o.useCallback(()=>{!s||!B||P||(Y&&R(),j(!!te),A(!1))},[R,Y,B,te,P,s]),ne=o.useCallback(async()=>{if(!(!s||L)){R(),j(!1),A(!1),N(!0);try{const ae=await r(s.id);if(!ae.ok){_.error(ae.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(ae.skipped){_.success(e("settings.projects.page.toast.customIconAlreadySet"));return}_.success(e("settings.projects.page.toast.iconDiscovered"))}finally{N(!1)}}},[R,r,L,s,e]),be=o.useCallback(async ae=>{const ye=ae?.silent===!0;if(!s)return null;const ke=l.trim();if(!ke)return null;if(T){D(!0);const we=await n(s.id,T);if(D(!1),!we.ok)return _.error(we.error||e("settings.projects.page.toast.uploadIconFailed")),null;ye||_.success(e("settings.projects.page.toast.iconUpdated")),R(),j(!1)}const he=b&&!!s.iconImage;if(he){I(!0);const we=await a(s.id);if(I(!1),!we.ok)return _.error(we.error||e("settings.projects.page.toast.removeIconFailed")),null;ye||_.success(e("settings.projects.page.toast.iconRemoved")),j(!1),w(null)}return{label:ke,icon:c,color:m,iconBackground:Zf(he?null:u),defaultModel:g??null}},[R,m,g,c,u,l,b,T,s,a,e,n]);return o.useEffect(()=>{A(!1)},[Q,i?.updatedAt]),{name:l,setName:d,icon:c,setIcon:h,color:m,setColor:p,iconBackground:u,setIconBackground:w,defaultModel:g,parsedDefaultModel:W,handleDefaultModelChange:H,isUploadingIcon:x,isRemovingCustomIcon:P,isDiscoveringIcon:L,pendingRemoveImageIcon:b,setPendingRemoveImageIcon:j,pendingUploadIconFile:T,pendingUploadIconPreviewUrl:K,previewImageFailed:C,setPreviewImageFailed:A,hasStoredImageIcon:te,hasPendingUploadImageIcon:Y,hasCustomIcon:k,effectiveHasImageIcon:$,hasRemovableImageIcon:B,showStoredImagePreview:F,showImagePreview:O,fileInputRef:z,clearPendingUploadIcon:R,handleUploadIcon:re,handleRemoveImageIcon:le,handleDiscoverIcon:ne,hasChanges:J,prepareSaveData:be,currentIconImage:i,project:s}},tx=450,sx=(s,e)=>{const{t:n}=st(),{hasChanges:a,name:r,icon:i,color:l,iconBackground:d,defaultModel:c,pendingRemoveImageIcon:h,pendingUploadIconFile:m,isUploadingIcon:p,isRemovingCustomIcon:u,prepareSaveData:w}=s,g=o.useRef(!1);o.useEffect(()=>{if(!a||!r.trim()||p||u||g.current)return;const f=window.setTimeout(()=>{g.current||(g.current=!0,(async()=>{try{const x=await w({silent:!0});if(x)try{await e(x)}catch{_.error(n("settings.projects.page.toast.saveFailed"))}}finally{g.current=!1}})())},tx);return()=>{window.clearTimeout(f)}},[l,c,a,i,d,u,p,r,e,h,m,w,n])},nx=s=>{const e=et.c(25),{project:n,onIdentitySave:a}=s,{t:r}=st(),i=ex(n);let l;e:{if(!n){l=null;break e}let I;e[0]!==n.id||e[1]!==n.path?(I={id:n.id,path:n.path},e[0]=n.id,e[1]=n.path,e[2]=I):I=e[2],l=I}const d=l;let c;if(e[3]!==a?(c=async I=>{await a(I)},e[3]=a,e[4]=c):c=e[4],sx(i,c),!n||!d)return null;let m;e[5]!==n.label||e[6]!==r?(m=n.label??r("settings.projects.page.title.default"),e[5]=n.label,e[6]=r,e[7]=m):m=e[7];const p=m;let u;e[8]!==p?(u=t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p}),e[8]=p,e[9]=u):u=e[9];let w;e[10]!==n.path?(w=t.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:n.path,children:n.path}),e[10]=n.path,e[11]=w):w=e[11];let g;e[12]!==u||e[13]!==w?(g=t.jsxs("div",{className:"mb-5 px-1",children:[u,w]}),e[12]=u,e[13]=w,e[14]=g):g=e[14];let f;e[15]!==i?(f=t.jsx(Yf,{form:i}),e[15]=i,e[16]=f):f=e[16];let x,D;e[17]!==d?(x=t.jsx(Qf,{projectRef:d}),D=t.jsx(Bf,{projectRef:d}),e[17]=d,e[18]=x,e[19]=D):(x=e[18],D=e[19]);let P;return e[20]!==g||e[21]!==f||e[22]!==x||e[23]!==D?(P=t.jsxs("div",{className:"space-y-0",children:[g,f,x,D]}),e[20]=g,e[21]=f,e[22]=x,e[23]=D,e[24]=P):P=e[24],P},ax=()=>{const s=et.c(18),{t:e}=st(),n=es(rx),a=es(ix),r=Ie(ox),i=Ie(lx);let l;e:{if(!r){l=null;break e}let w;s[0]!==n||s[1]!==r?(w=n.find(g=>g.id===r)??null,s[0]=n,s[1]=r,s[2]=w):w=s[2],l=w}const d=l;let c,h;s[3]!==n||s[4]!==r||s[5]!==i?(c=()=>{if(n.length===0){i(null);return}r&&n.some(w=>w.id===r)||i(n[0].id)},h=[n,r,i],s[3]=n,s[4]=r,s[5]=i,s[6]=c,s[7]=h):(c=s[6],h=s[7]),o.useEffect(c,h);let m;s[8]!==d||s[9]!==a?(m=async w=>{d&&a(d.id,{label:w.label,icon:w.icon,color:w.color,iconBackground:w.iconBackground,defaultModel:w.defaultModel??null})},s[8]=d,s[9]=a,s[10]=m):m=s[10];const p=m;if(!d){let w;s[11]!==e?(w=e("settings.projects.page.empty.noProjects"),s[11]=e,s[12]=w):w=s[12];let g;return s[13]!==w?(g=t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsx("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:w})})}),s[13]=w,s[14]=g):g=s[14],g}let u;return s[15]!==p||s[16]!==d?(u=t.jsx(_t,{outerClassName:"h-full",className:"w-full bg-background",children:t.jsx("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:t.jsx(nx,{project:d,onIdentitySave:p})})}),s[15]=p,s[16]=d,s[17]=u):u=s[17],u};function rx(s){return s.projects}function ix(s){return s.updateProjectMeta}function ox(s){return s.settingsProjectsSelectedId}function lx(s){return s.setSettingsProjectsSelectedId}const Br=16384,rr=globalThis,cx=s=>{if(rr.Buffer)return rr.Buffer.from(s,"utf8").toString("base64url");const e=new TextEncoder().encode(s);let n="";for(let a=0;a<e.length;a+=32768)n+=String.fromCharCode(...e.slice(a,a+32768));return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},dx=s=>{try{if(rr.Buffer)return rr.Buffer.from(s,"base64url").toString("utf8");const e=s.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(s.length/4)*4,"="),n=atob(e),a=new Uint8Array(n.length);for(let r=0;r<n.length;r+=1)a[r]=n.charCodeAt(r);return new TextDecoder().decode(a)}catch{return null}},ux=s=>{if(typeof s!="string")return null;const e=s.trim();if(!e)return null;try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?null:(n.hash="",n.toString().replace(/\/+$/g,""))}catch{return null}},mx=s=>{if(typeof s!="string")return null;const e=s.trim();if(!e)return null;try{const n=new URL(e);return n.protocol!=="ws:"&&n.protocol!=="wss:"?null:(n.hash="",n.toString())}catch{return null}},ll=s=>typeof s=="string"&&s.length>0,px=s=>{if(!s||typeof s!="object"||Array.isArray(s))return null;const e=s;return e.kty!=="EC"||e.crv!=="P-256"||!ll(e.x)||!ll(e.y)?null:{kty:"EC",crv:"P-256",x:e.x,y:e.y}},gx=s=>typeof s=="number"&&Number.isFinite(s)?s:void 0,hx=s=>{if(!s||typeof s!="object")return null;const e=s,n=gx(e.priority);if(e.type==="lan"||e.type==="tunnel"){const a=ux(e.url);return a?n===void 0?{type:e.type,url:a}:{type:e.type,url:a,priority:n}:null}if(e.type==="relay"){const a=mx(e.relayUrl);if(!a)return null;const r=typeof e.serverId=="string"?e.serverId.trim():"";if(!r)return null;const i=px(e.hostEncPubJwk);if(!i)return null;const l=typeof e.grant=="string"&&e.grant.trim()?e.grant.trim():void 0;return{type:"relay",relayUrl:a,serverId:r,hostEncPubJwk:i,...l?{grant:l}:{},...n===void 0?{}:{priority:n}}}return null},Rc=s=>{if(!s||typeof s!="object")return null;const e=s;if(e.v!==2)return null;const n=typeof e.pairingId=="string"?e.pairingId.trim():"",a=typeof e.secret=="string"?e.secret.trim():"";if(!n||!a)return null;const r=Array.isArray(e.candidates)?e.candidates.map(hx).filter(c=>!!c):[];if(r.length===0)return null;const i=typeof e.expiresAt=="string"&&e.expiresAt.trim()?e.expiresAt.trim():void 0;if(i){const c=Date.parse(i);if(!Number.isFinite(c)||c<=Date.now())return null}const l=typeof e.label=="string"&&e.label.trim()?e.label.trim():void 0,d=typeof e.fingerprint=="string"&&e.fingerprint.trim()?e.fingerprint.trim():void 0;return{v:2,pairingId:n,secret:a,...l?{label:l}:{},...d?{fingerprint:d}:{},...i?{expiresAt:i}:{},candidates:r}},fx=s=>({v:2,pairingId:s.pairingId.trim(),secret:s.secret.trim(),...s.label?.trim()?{label:s.label.trim()}:{},...s.fingerprint?.trim()?{fingerprint:s.fingerprint.trim()}:{},...s.expiresAt?.trim()?{expiresAt:s.expiresAt.trim()}:{},candidates:s.candidates}),xx=s=>{const e=Rc(s);if(!e)throw new Error("Invalid pairing connection payload");const n=new URLSearchParams;return n.set("v","2"),n.set("p",cx(JSON.stringify(e))),`openchamber://connect?${n.toString()}`},yx=s=>{const e=s.trim();if(!e||e.length>Br)return null;try{const n=new URL(e);if(n.protocol!=="openchamber:"||n.hostname!=="connect"||n.searchParams.get("v")!=="2")return null;const a=n.searchParams.get("p")||"";if(!a||a.length>Br)return null;const r=dx(a);return!r||r.length>Br?null:Rc(JSON.parse(r))}catch{return null}},vi=()=>Math.floor(2e4+Math.random()*3e4),bx=s=>{const e=(s instanceof Error?s.message:String(s)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},vx=()=>{if(typeof navigator>"u")return;const s=(navigator.userAgent||"").toLowerCase();if(s.includes("mac"))return"macos";if(s.includes("win"))return"windows";if(s.includes("linux"))return"linux"},cl=s=>{switch((s||"").toLowerCase()){case"ios":return"iOS";case"android":return"Android";case"macos":case"darwin":return"macOS";case"windows":case"win32":return"Windows";case"linux":return"Linux";default:return null}},dl=s=>{switch(s){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingOpenChamber";case"updating":return"settings.remoteInstances.page.phase.updatingOpenChamber";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},jx=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Fc=s=>!!(s&&jx.has(s)),ul=s=>s==="ready"?"bg-[var(--status-success)] animate-pulse":s==="error"?"bg-[var(--status-error)] animate-pulse":s==="degraded"||Fc(s)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",wx=s=>s.type==="dynamic"?`${s.localHost||"127.0.0.1"}:${s.localPort||0}`:s.type==="remote"?`${s.remoteHost||"127.0.0.1"}:${s.remotePort||0} -> ${s.localHost||"127.0.0.1"}:${s.localPort||0}`:`${s.localHost||"127.0.0.1"}:${s.localPort||0} -> ${s.remoteHost||"127.0.0.1"}:${s.remotePort||0}`,Nx=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:vi(),remoteHost:"127.0.0.1",remotePort:80}),kx=s=>s.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Gs=s=>{const e=et.c(8),{label:n,hint:a}=s;let r;e[0]!==n?(r=t.jsx("span",{children:n}),e[0]=n,e[1]=r):r=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let l;e[3]!==a?(l=t.jsxs(St,{children:[i,t.jsx(It,{sideOffset:8,className:"max-w-xs",children:t.jsx("div",{className:"typography-meta text-foreground",children:a})})]}),e[3]=a,e[4]=l):l=e[4];let d;return e[5]!==r||e[6]!==l?(d=t.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[r,l]}),e[5]=r,e[6]=l,e[7]=d):d=e[7],d},Sx=s=>{switch(s){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},ml=(s,e)=>{const n=(s||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},Cx=s=>{const e=(s||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Ix=s=>{const e=s.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return s;const n=Number(e[1]),a=Number.isFinite(n)?new Date(n).toISOString():e[1],r=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${a}] [${r}] ${i}`},ji=(s="",e="")=>({id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`header-${Date.now()}-${Math.random().toString(16).slice(2)}`,name:s,value:e}),Px=s=>s.trim().toLowerCase()==="authorization",$r=s=>{const e={};for(const n of s){const a=n.name.trim(),r=n.value.trim();a&&r&&!Px(a)&&(e[a]=r)}return Object.keys(e).length>0?e:void 0},Ax=s=>Object.entries(s||{}).map(([e,n])=>ji(e,n)),Lc=()=>{if(typeof window>"u")return null;const e=sa()||window.location.href;try{const n=Number(new URL(e).port||window.location.port);return Number.isFinite(n)&&n>0?n:null}catch{const n=Number(window.location.port);return Number.isFinite(n)&&n>0?n:null}},pl=s=>{try{const e=new URL(s).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},Dx=async()=>{const s=_n(sa())||window.location.origin;if(!ns()||!ta())return s;let e;try{e=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}})}catch{return s}if(!e.ok||(await e.json().catch(()=>null))?.desktopLanAccessActive!==!0)return s;const a=await fc(),r=Lc();return!a||!r?s:`http://${a}:${r}`},Vr=s=>{const e=s.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Ex=s=>{const e=s.sshCommand.trim(),n=s.nickname?.trim(),a=s.portForwards.map(r=>({...r,localHost:r.localHost?.trim()||"127.0.0.1",localPort:typeof r.localPort=="number"?Math.max(1,Math.min(65535,Math.round(r.localPort))):void 0,remoteHost:r.remoteHost?.trim(),remotePort:typeof r.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(r.remotePort))):void 0}));return{...s,sshCommand:e,...n?{nickname:n}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(s.connectionTimeoutSec||60))),localForward:{...s.localForward,bindHost:s.localForward.bindHost==="localhost"||s.localForward.bindHost==="0.0.0.0"?s.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof s.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(s.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...s.remoteOpenchamber,preferredPort:typeof s.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(s.remoteOpenchamber.preferredPort))):void 0},portForwards:a}},Mx=()=>{const{t:s}=st(),{clientAuth:e}=Di(),n=ns(),a=os(S=>S.instances),r=os(S=>S.statusesById),i=os(S=>S.importCandidates),l=os(S=>S.isLoading),d=os(S=>S.isImportsLoading),c=os(S=>S.isSaving),h=os(S=>S.error),m=os(S=>S.load),p=os(S=>S.loadImports),u=os(S=>S.refreshStatuses),w=os(S=>S.upsertInstance),g=os(S=>S.createFromCommand),f=os(S=>S.removeInstance),x=os(S=>S.connect),D=os(S=>S.disconnect),P=os(S=>S.retry),I=Ie(S=>S.settingsRemoteInstancesSelectedId),L=Ie(S=>S.setSettingsRemoteInstancesSelectedId),N=o.useMemo(()=>I&&a.find(S=>S.id===I)||null,[a,I]),[b,j]=o.useState(null),[T,U]=o.useState(!1),[K,M]=o.useState(!1),[C,A]=o.useState(null),[z,R]=o.useState([]),[Q,W]=o.useState(null),[te,Y]=o.useState(""),[k,$]=o.useState(!1),[B,F]=o.useState({}),[O,J]=o.useState(!1),[H,re]=o.useState(!1),[le,ne]=o.useState(()=>Date.now()),[be,ae]=o.useState([]),[ye,ke]=o.useState({}),[he,we]=o.useState("local"),[de,Z]=o.useState(!1),[se,ve]=o.useState(!1),[G,ee]=o.useState(""),[ie,pe]=o.useState(""),[Ae,Se]=o.useState(""),[De,Me]=o.useState([]),[Te,Be]=o.useState(""),[ze,Oe]=o.useState(null),[$e,Ke]=o.useState(!1),[Ye,Re]=o.useState(!1),[V,oe]=o.useState(null),[ge,Fe]=o.useState(""),[Ne,He]=o.useState(""),[X,v]=o.useState(""),[je,Pe]=o.useState([]),[Le,qe]=o.useState([]),[rt,ot]=o.useState([]),[it,dt]=o.useState(!1),[Je,_e]=o.useState(""),[gt,fe]=o.useState(null),[tt,nt]=o.useState(null),[Ze,ft]=o.useState(null),[bt,Mt]=o.useState(null),[ue,Ve]=o.useState(!1),[Qe,Ge]=o.useState(!1),[xt,kt]=o.useState("configure"),[ht,Pt]=o.useState(!1),[Wt,ts]=o.useState("relay"),[bs,ks]=o.useState(!0),[Yt,Ss]=o.useState(null),Ce=o.useMemo(()=>Le.filter(S=>!!S.revokedAt).length,[Le]),[jt,vt]=o.useState(!1),[Ht,qt]=o.useState("ssh user@example.com"),[Vt,ps]=o.useState("");o.useEffect(()=>{m(),p()},[m,p]);const vs=o.useCallback(async()=>{Z(!0),Oe(null);try{const S=await ao();ae(S.hosts||[]),we(S.defaultHostId||"local")}catch(S){Oe(S instanceof Error?S.message:String(S))}finally{Z(!1)}},[]);o.useEffect(()=>{vs()},[vs]);const Jt=o.useCallback(async(S,me=he)=>{ve(!0),Oe(null);try{await ro({hosts:S,defaultHostId:me,initialHostChoiceCompleted:!0}),ae(S),we(me)}catch(We){Oe(We instanceof Error?We.message:String(We))}finally{ve(!1)}},[he]),Es=o.useCallback(async()=>{const S=io(ie);if(!S){Oe(s("desktopHostSwitcher.error.invalidUrl"));return}const me=S.persistedUrl,at={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:G.trim()||ca(me),url:me,apiUrl:me,...Ae.trim()?{clientToken:Ae.trim()}:{},...$r(De)?{requestHeaders:$r(De)}:{}};await Jt([at,...be],he),ee(""),pe(""),Se(""),Me([]),Ke(!1),S.redeemUrl&&Vr(S.redeemUrl)},[he,De,be,G,Ae,ie,Jt,s]),Nn=o.useCallback(async()=>{const S=yx(Te);if(!S){Oe(s("settings.remoteInstances.direct.error.invalidConnectLink"));return}const me=await Fm().catch(()=>""),We=JSON.stringify({pairingId:S.pairingId,secret:S.secret,clientLabel:S.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:vx(),...me?{dedupeKey:`desktop:${me}`}:{}}),at={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:We},Tt=async Ut=>{if(!Ut.ok)return null;const As=await Ut.json().catch(()=>null);return(typeof As?.clientToken=="string"?As.clientToken.trim():"")||null},js=[...S.candidates].sort((Ut,As)=>(Ut.type==="relay"?1:0)-(As.type==="relay"?1:0));let Zt=null;for(const Ut of js){if(Ut.type==="relay"){const la=Lm({relayUrl:Ut.relayUrl,serverId:Ut.serverId,hostEncPubJwk:Ut.hostEncPubJwk,...Ut.grant?{grant:Ut.grant}:{}});try{const Ca=await la.fetch("/api/client-auth/pairing/redeem",at),zi=await Tt(Ca);if(zi){Zt={kind:"relay",relay:{relayUrl:Ut.relayUrl,serverId:Ut.serverId,hostEncPubJwk:Ut.hostEncPubJwk},token:zi};break}}catch{}finally{la.close()}continue}const As=_n(Ut.url);if(As)try{const la=await fetch(`${As}/api/client-auth/pairing/redeem`,at),Ca=await Tt(la);if(Ca){Zt={kind:"direct",url:As,token:Ca};break}}catch{}}if(!Zt){Oe(s("desktopHostSwitcher.error.invalidUrl"));return}const mn=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Cn=S.candidates.find(Ut=>Ut.type==="relay"),Ws=Zt.kind==="relay"?Zt.relay:Cn?{relayUrl:Cn.relayUrl,serverId:Cn.serverId,hostEncPubJwk:Cn.hostEncPubJwk}:void 0,wr=S.candidates.filter(Ut=>Ut.type!=="relay").map(Ut=>_n(Ut.url)).find(Ut=>!!Ut),ia=Zt.kind==="direct"?Zt.url:wr,{token:Nr}=Zt,Lt=ia||(Ws?Om(Ws.serverId):null);if(!Lt){Oe(s("desktopHostSwitcher.error.invalidUrl"));return}const ss={url:Lt,apiUrl:ia||void 0,clientToken:Nr,...Ws?{relay:Ws}:{}},oa=be.find(Ut=>Ws?Ut.relay?.serverId===Ws.serverId:!Ut.relay&&_n(Ut.apiUrl||Ut.url)===Lt);if(oa){const Ut=be.map(As=>As.id===oa.id?{...As,label:S.label||As.label,...ss}:As);await Jt(Ut,he)}else await Jt([{id:mn(),label:S.label||ca(Lt),...ss},...be],he);Be(""),Oe(null),Re(!1)},[Te,he,be,Jt,s]),_s=o.useCallback(async S=>{const me=be.filter(at=>at.id!==S);await Jt(me,he===S?"local":he),V===S&&oe(null)},[he,V,be,Jt]),Ms=o.useCallback(S=>{oe(S.id),Fe(S.label),He(S.apiUrl||S.url),v(S.clientToken||""),Pe(Ax(S.requestHeaders)),Oe(null)},[]),nn=o.useCallback(async()=>{if(!V)return;const S=io(Ne);if(!S){Oe(s("desktopHostSwitcher.error.invalidUrl"));return}const me=S.persistedUrl,We=be.map(at=>at.id===V?{...at,label:ge.trim()||ca(me),url:me,apiUrl:me,clientToken:X.trim()||void 0,requestHeaders:$r(je)}:at);await Jt(We,he),oe(null),S.redeemUrl&&Vr(S.redeemUrl)},[he,je,ge,X,Ne,V,be,Jt,s]),ut=o.useCallback(async()=>{const S=Ht.trim();if(!S){_.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}const me=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await g(me,S,Vt.trim()||s("settings.remoteInstances.sidebar.newSshInstanceName")),L(me),vt(!1),qt("ssh user@example.com"),ps(""),_.success(s("settings.remoteInstances.page.toast.instanceCreated"))}catch(We){_.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:We instanceof Error?We.message:String(We)})}},[g,L,Ht,Vt,s]),pt=o.useCallback(async S=>{await Jt(be,S)},[be,Jt]);o.useEffect(()=>{if(!n||be.length===0)return;let S=!1;return Promise.all(be.map(async me=>{const We=()=>Bm(me.relay).catch(()=>({status:"unreachable",latencyMs:0}));if(me.relay&&!me.apiUrl)return[me.id,await We()];const at=_n(zm(me));if(!at)return[me.id,me.relay?await We():{status:"unreachable",latencyMs:0}];const Tt=await Km(at,{clientToken:me.clientToken||null,requestHeaders:me.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Tt.status==="unreachable"&&me.relay){const js=await We();if(js.status==="ok")return[me.id,js]}return[me.id,Tt]})).then(me=>{S||ke(Object.fromEntries(me))}),()=>{S=!0}},[be,n]);const wt=o.useCallback(async S=>{if(e){S?.silent||dt(!0),S?.silent||fe(null);try{const[me,We]=await Promise.all([e.listClients(),e.listPendingPairings().catch(()=>null)]);qe(me),We&&ot(We)}catch(me){S?.silent||fe(me instanceof Error?me.message:String(me))}finally{S?.silent||dt(!1)}}},[e]),Qt=o.useRef(!1);o.useEffect(()=>{if(!(!Qe||xt!=="result"||!Ze)){if(rt.some(S=>S.id===Ze)){Qt.current=!0;return}Qt.current&&(ft(null),Ge(!1),Le.some(S=>S.pairingId===Ze)&&_.success(s("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Qe,xt,Ze,rt,Le,s]);const Xt=o.useCallback(async S=>{if(e)try{await e.cancelPairing(S),ot(me=>me.filter(We=>We.id!==S)),await wt({silent:!0})}catch(me){fe(me instanceof Error?me.message:String(me))}},[e,wt]);o.useEffect(()=>{if(!e)return;wt();const S=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||wt({silent:!0})},5e3);return()=>window.clearInterval(S)},[e,wt]);const an=o.useCallback(async()=>{if(e?.getPairingTransports)try{const at=await e.getPairingTransports();return{localUrl:at.local,lanUrl:at.lan,relayAvailable:at.relayAvailable}}catch{}const S=Lc(),me=S?`http://127.0.0.1:${S}`:pl(window.location.origin)?window.location.origin:null;let We=null;try{const at=_n(await Dx());We=at&&!pl(at)?at:null}catch{}return{localUrl:me,lanUrl:We,relayAvailable:!0}},[e]),rn=o.useCallback(async()=>{fe(null),nt(null),Mt(null),Ve(!1),ft(null),kt("configure"),ks(!0),Ge(!0);const S=await an();Ss(S),ts(S.relayAvailable?"relay":S.lanUrl?"lan":"local")},[an]),kn=o.useCallback(async()=>{if(!(!e?.createPairingSession||!Yt)){fe(null),Pt(!0);try{const S=Je.trim()||void 0;let me,We,at=!0;Wt==="local"?(me=Yt.localUrl??void 0,We=!1):Wt==="lan"?(me=Yt.lanUrl??void 0,We=bs):bs&&Yt.lanUrl?(me=Yt.lanUrl,We=!0):(at=!1,We=!0);const{pairing:Tt,server:js}=await e.createPairingSession({label:S,allowedClientKinds:["mobile","desktop"],serverUrl:me,includeRelay:We,includeDirect:at}),Zt=fx({pairingId:Tt.id,secret:Tt.secret,label:js.label,fingerprint:Tt.fingerprint??void 0,expiresAt:Tt.expiresAt,candidates:js.candidates}),mn=xx(Zt);nt(mn),Mt(await sc.toDataURL(mn,{width:1024,margin:2,errorCorrectionLevel:"L"})),Ve(!1),Qt.current=!1,ft(Tt.id),kt("result"),await wt({silent:!0})}catch(S){fe(S instanceof Error?S.message:String(S))}finally{Pt(!1)}}},[e,Yt,Wt,bs,Je,wt]),pr=o.useCallback(()=>{tt&&En(tt).then(S=>{S.ok&&(Ve(!0),window.setTimeout(()=>Ve(!1),2e3))})},[tt]),gr=o.useCallback(async S=>{if(!e)return;const me=S.clientKind==="desktop-local";fe(null);try{if(await e.revokeClient(S.id),me&&ns()){const We=await ao();await ro({hosts:We.hosts,defaultHostId:We.defaultHostId,initialHostChoiceCompleted:We.initialHostChoiceCompleted,localClientToken:null}),qe(at=>at.map(Tt=>Tt.id===S.id?{...Tt,revokedAt:new Date().toISOString()}:Tt)),Um({apiBaseUrl:sa(),clientToken:null,runtimeKey:"local"});return}await wt()}catch(We){fe(We instanceof Error?We.message:String(We))}},[e,wt]),On=o.useCallback(async()=>{if(e){fe(null);try{await e.purgeRevokedClients(),await wt()}catch(S){fe(S instanceof Error?S.message:String(S))}}},[e,wt]);o.useEffect(()=>{j(N)},[N]),o.useEffect(()=>{if(!I)return;const S=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||u()},2e3);return()=>{window.clearInterval(S)}},[u,I]),o.useEffect(()=>{let S=null,me=Date.now();const We=()=>{const Tt=Date.now();Tt-me>=1e3&&(ne(Tt),me=Tt),S=requestAnimationFrame(We)};(typeof document>"u"||document.visibilityState==="visible")&&(S=requestAnimationFrame(We));const at=()=>{document.visibilityState==="visible"&&S===null?S=requestAnimationFrame(We):document.visibilityState!=="visible"&&S!==null&&(cancelAnimationFrame(S),S=null)};return document.addEventListener("visibilitychange",at),()=>{document.removeEventListener("visibilitychange",at),S!==null&&cancelAnimationFrame(S)}},[]);const gs=I?r[I]:null,Ts=gs?.phase,on=Ts==="ready",Rs=Ts==="degraded",Ue=Fc(Ts),ln=on||(Ue||Rs),Sa=gs?Math.max(0,le-gs.updatedAtMs):0,Sn=Rs&&Sa>12e3,hr=o.useMemo(()=>!b||!N?!1:JSON.stringify(b)!==JSON.stringify(N),[b,N]),as=o.useCallback(S=>{j(me=>me&&S(me))},[]),fr=o.useCallback(async()=>{if(!b)return;const S=Ex(b);if(!S.sshCommand.trim()){_.error(s("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(S.localForward.bindHost==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(S.auth.sshPassword?.enabled&&S.auth.sshPassword.value?.trim()&&S.auth.sshPassword.store!=="settings"){const me=window.confirm(s("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));S.auth.sshPassword.store=me?"settings":"never",me||(S.auth.sshPassword.value=void 0)}if(S.auth.openchamberPassword?.enabled&&S.auth.openchamberPassword.value?.trim()&&S.auth.openchamberPassword.store!=="settings"){const me=window.confirm(s("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));S.auth.openchamberPassword.store=me?"settings":"never",me||(S.auth.openchamberPassword.value=void 0)}try{await w(S),_.success(s("settings.remoteInstances.page.toast.instanceSaved"))}catch(me){_.error(s("settings.remoteInstances.page.toast.saveFailed"),{description:me instanceof Error?me.message:String(me)})}}},[b,s,w]),zn=o.useCallback(async(S,me)=>{const We=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await g(We,`ssh ${me}`,S),L(We),_.success(s("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(at){return _.error(s("settings.remoteInstances.sidebar.toast.createFailed"),{description:at instanceof Error?at.message:String(at)}),!1}},[g,L,s]),Os=o.useCallback(()=>{k||(W(null),Y(""))},[k]),cn=o.useCallback((S,me)=>{if(me){W(S),Y(kx(S));return}zn(S,S)},[zn]),Hs=o.useCallback(async()=>{const S=Q,me=te.trim();if(S){if(!me){_.error(s("settings.remoteInstances.page.toast.destinationRequired"));return}$(!0);try{await zn(S,me)&&(W(null),Y(""))}finally{$(!1)}}},[zn,te,Q,s]),dn=o.useCallback(async()=>{if(N)try{await x(N.id);return}catch(S){if(!bx(S)||!window.confirm(s("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw S;const We={...N,localForward:{...N.localForward,preferredLocalPort:vi()}};await w(We),await x(We.id),_.success(s("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[x,N,s,w]),Kn=o.useCallback(async S=>(await Vu(S,600)).map(We=>Ix(We)),[]),na=o.useCallback(async()=>{if(b){U(!0),M(!0),A(null);try{const S=await Kn(b.id);R(S)}catch(S){R([]),A(S instanceof Error?S.message:String(S))}finally{M(!1)}}},[b,Kn]);o.useEffect(()=>{if(!T||!b)return;let S=!1;const me=async()=>{try{const at=await Kn(b.id);S||(R(at),A(null))}catch(at){S||A(at instanceof Error?at.message:String(at))}};me();const We=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||me()},1e3);return()=>{S=!0,window.clearInterval(We)}},[b,T,Kn]);const Fs=o.useMemo(()=>z.join(`
|
|
28
|
+
`),[z]),Un=o.useCallback(()=>{if(!Fs.trim()){_.error(s("settings.remoteInstances.page.toast.noLogsToCopy"));return}En(Fs).then(S=>{S.ok&&_.success(s("settings.remoteInstances.page.toast.logsCopied"))})},[Fs,s]),un=o.useCallback(async()=>{if(b)try{await _u(b.id),R([]),_.success(s("settings.remoteInstances.page.toast.logsCleared"))}catch(S){_.error(s("settings.remoteInstances.page.toast.clearLogsFailed"),{description:S instanceof Error?S.message:String(S)})}},[b,s]),xr=o.useCallback(async()=>{if(!gs?.localUrl){_.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const S=gs.localUrl.trim();if(!S){_.error(s("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Vr(S)},[gs?.localUrl,s]),yr=o.useCallback(()=>{if(!b)return;J(!0),(ln?D(b.id):dn()).catch(me=>{const We=ln?on?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";_.error(s(We),{description:me instanceof Error?me.message:String(me)})}).finally(()=>{J(!1)})},[ln,dn,D,b,on,s]),br=o.useCallback(()=>{if(!b||Ue)return;re(!0),(Rs?D(b.id).then(()=>dn()):P(b.id)).catch(me=>{_.error(s("settings.remoteInstances.page.toast.retryFailed"),{description:me instanceof Error?me.message:String(me)})}).finally(()=>{re(!1)})},[dn,D,b,Ue,Rs,P,s]),vr=s(Ue?"settings.remoteInstances.page.actions.connecting":Rs?Sn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),jr=!O&&!H&&(Ts==="error"||Ts==="idle"||!Ts||Rs&&Sn)&&!Ue,aa=s(on?"settings.remoteInstances.sidebar.actions.disconnect":ln?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!b)return t.jsxs(bi,{children:[e?t.jsxs("div",{"data-settings-item":"remote-instances.client-auth",className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.clientAuth.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.description")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsx("div",{children:t.jsxs(q,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{rn()},children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.clientAuth.actions.addDevice")]})}),t.jsxs("div",{className:"space-y-1",children:[Ce>0?t.jsx("div",{className:"flex justify-end",children:t.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{On()},children:s("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,it&&Le.length===0&&rt.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.state.loading")}):Le.length===0&&rt.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.state.empty")}):t.jsxs(t.Fragment,{children:[rt.map(S=>t.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[var(--status-warning)] animate-pulse"}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:S.label||s("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),S.usesRelay?t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:s("settings.remoteInstances.clientAuth.state.viaRelay")}):null]}),t.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:s("settings.remoteInstances.clientAuth.state.pending")})]}),t.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Xt(S.id)},children:s("settings.common.actions.cancel")})]},`pending-${S.id}`)),Le.map(S=>{const me=S.clientKind==="desktop-local",We=S.lastUsedAt?Date.parse(S.lastUsedAt):Number.NaN,at=!S.revokedAt&&(me||Number.isFinite(We)&&Date.now()-We<9e4),Tt=S.revokedAt?s("settings.remoteInstances.clientAuth.state.revoked"):at?S.lastTransport==="relay"&&!me?s("settings.remoteInstances.clientAuth.state.connectedRelay"):s("settings.remoteInstances.clientAuth.state.connectedDirect"):S.lastUsedAt?s("settings.remoteInstances.clientAuth.lastUsed",{date:S.lastUsedAt}):s("settings.remoteInstances.clientAuth.neverUsed");return t.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:ce("h-2 w-2 shrink-0 rounded-full",S.revokedAt?"bg-muted-foreground/20":at?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:S.label}),cl(S.devicePlatform)?t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:cl(S.devicePlatform)}):null,me?t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:s("settings.remoteInstances.clientAuth.state.thisDevice")}):null]}),t.jsx("p",{className:ce("typography-micro truncate",at&&!S.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Tt})]}),t.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{gr(S)},disabled:!!S.revokedAt,children:s("settings.remoteInstances.clientAuth.actions.revoke")})]},S.id)})]})]}),gt?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:gt}):null]})]}):null,n?t.jsxs("div",{"data-settings-item":"remote-instances.direct-hosts",className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 flex items-start justify-between gap-3 px-1",children:[t.jsxs("div",{className:"min-w-0 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.direct.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.description")})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-2 pt-0.5",children:[t.jsx(q,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Re(!0),disabled:se,children:s("settings.remoteInstances.direct.import.action")}),t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ke(!0),disabled:se,children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.actions.add")]})]})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[t.jsx("div",{className:"space-y-1",children:de?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.state.loading")}):be.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.state.empty")}):be.map(S=>{const me=ye[S.id],We=me?me.status==="ok"?"desktopHostSwitcher.status.connected":me.status==="auth"?"desktopHostSwitcher.status.authRequired":me.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":me.status==="incompatible"?"desktopHostSwitcher.status.incompatible":me.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",at=me?.status==="ok";return t.jsx("div",{className:"py-1.5",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:ce("h-2 w-2 shrink-0 rounded-full",me?at?"bg-[var(--status-success)]":"bg-[var(--status-error)]":"bg-muted-foreground/30 animate-pulse")}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:ca(S.label)}),he===S.id?t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:s("desktopHostSwitcher.header.default")}):null,t.jsxs("span",{className:ce("typography-micro shrink-0",at?"text-[var(--status-success)]":"text-muted-foreground"),children:[s(We),at&&typeof me?.latencyMs=="number"?s("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(me.latencyMs))}):""]})]}),t.jsx("p",{className:ce("typography-micro text-muted-foreground truncate",S.apiUrl&&"font-mono"),children:S.relay&&!S.apiUrl?s("mobile.connect.relay.badge"):ca(S.apiUrl||S.url)})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{pt(S.id)},disabled:se||he===S.id,"aria-label":s("desktopHostSwitcher.actions.setAsDefaultAria"),children:he===S.id?t.jsx(E,{name:"star-fill",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"star",className:"h-3.5 w-3.5"})}),S.relay&&!S.apiUrl?null:t.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ms(S),disabled:se,children:[t.jsx(E,{name:"pencil",className:"h-3.5 w-3.5"}),s("desktopHostSwitcher.actions.edit")]}),t.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{_s(S.id)},disabled:se,children:[t.jsx(E,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]})},S.id)})}),ze?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ze}):null]})]}):null,n?t.jsx(Rt,{open:$e,onOpenChange:Ke,children:t.jsxs(Ft,{className:"sm:max-w-lg",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("settings.remoteInstances.direct.actions.add")}),t.jsx($t,{children:s("settings.remoteInstances.direct.addDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Es()},children:[t.jsx(Xe,{className:"h-8",value:G,onChange:S=>ee(S.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:se}),t.jsx(Xe,{className:"h-8",value:ie,onChange:S=>pe(S.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:se,autoFocus:!0}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(Xe,{className:"h-8",value:Ae,onChange:S=>Se(S.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:se}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:s("settings.remoteInstances.direct.note")})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.remoteInstances.direct.headers.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.headers.description")})]}),De.map(S=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(Xe,{className:"h-8 font-mono text-xs",value:S.name,onChange:me=>Me(We=>We.map(at=>at.id===S.id?{...at,name:me.target.value}:at)),placeholder:s("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:se}),t.jsx(Xe,{className:"h-8 font-mono text-xs",value:S.value,onChange:me=>Me(We=>We.map(at=>at.id===S.id?{...at,value:me.target.value}:at)),placeholder:s("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:se}),t.jsx("button",{type:"button",onClick:()=>Me(me=>me.filter(We=>We.id!==S.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":s("settings.remoteInstances.direct.headers.removeAria"),disabled:se,children:t.jsx(E,{name:"close",className:"h-4 w-4"})})]},S.id)),t.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Me(S=>[...S,ji()]),disabled:se,children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.headers.actions.add")]})]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ke(!1),disabled:se,children:s("settings.common.actions.cancel")}),t.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:se||!ie.trim(),children:s("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?t.jsx(Rt,{open:!!V,onOpenChange:S=>{S||oe(null)},children:t.jsxs(Ft,{className:"sm:max-w-lg",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("desktopHostSwitcher.actions.edit")}),t.jsx($t,{children:s("settings.remoteInstances.direct.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),nn()},children:[t.jsx(Xe,{className:"h-8",value:ge,onChange:S=>Fe(S.target.value),placeholder:s("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:se}),t.jsx(Xe,{className:"h-8",value:Ne,onChange:S=>He(S.target.value),placeholder:s("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:se,autoFocus:!0}),t.jsx(Xe,{className:"h-8",value:X,onChange:S=>v(S.target.value),placeholder:s("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:se}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.remoteInstances.direct.headers.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.direct.headers.description")})]}),je.map(S=>t.jsxs("div",{className:"flex w-full gap-2",children:[t.jsx(Xe,{className:"h-8 font-mono text-xs",value:S.name,onChange:me=>Pe(We=>We.map(at=>at.id===S.id?{...at,name:me.target.value}:at)),placeholder:s("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:se}),t.jsx(Xe,{className:"h-8 font-mono text-xs",value:S.value,onChange:me=>Pe(We=>We.map(at=>at.id===S.id?{...at,value:me.target.value}:at)),placeholder:s("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:se}),t.jsx("button",{type:"button",onClick:()=>Pe(me=>me.filter(We=>We.id!==S.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":s("settings.remoteInstances.direct.headers.removeAria"),disabled:se,children:t.jsx(E,{name:"close",className:"h-4 w-4"})})]},S.id)),t.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Pe(S=>[...S,ji()]),disabled:se,children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.direct.headers.actions.add")]})]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>oe(null),disabled:se,children:s("settings.common.actions.cancel")}),t.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:se,children:s("settings.common.actions.saveChanges")})]})]})]})}):null,n?t.jsx(Rt,{open:Ye,onOpenChange:Re,children:t.jsxs(Ft,{className:"sm:max-w-lg",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("settings.remoteInstances.direct.import.action")}),t.jsx($t,{children:s("settings.remoteInstances.direct.import.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Nn()},children:[t.jsx(Xe,{className:"h-8",value:Te,onChange:S=>Be(S.target.value),placeholder:s("settings.remoteInstances.direct.import.placeholder"),disabled:se,autoFocus:!0}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Re(!1),disabled:se,children:s("settings.common.actions.cancel")}),t.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:se||!Te.trim(),children:s("settings.remoteInstances.direct.import.action")})]})]})]})}):null,t.jsx(Rt,{open:Qe,onOpenChange:Ge,children:t.jsxs(Ft,{className:xt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s(xt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),t.jsx($t,{children:s(xt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),xt==="configure"?t.jsxs("form",{className:"space-y-4",onSubmit:S=>{S.preventDefault(),kn()},children:[t.jsx(Xe,{className:"h-8",value:Je,onChange:S=>_e(S.target.value),placeholder:s("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),t.jsx("div",{role:"radiogroup","aria-label":s("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:s("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:s("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!Yt?.relayAvailable},{key:"lan",label:s("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:s("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Yt?.lanUrl},{key:"local",label:s("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:s("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Yt?.localUrl}].map(S=>{const me=Wt===S.key;return t.jsxs("div",{className:ce("flex items-start gap-2 py-0.5",S.available?"cursor-pointer":"opacity-45"),onClick:()=>{S.available&&ts(S.key)},role:"presentation",children:[t.jsx(Qs,{checked:me,disabled:!S.available,onChange:()=>ts(S.key),ariaLabel:S.label,className:"mt-0.5"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:ce("typography-ui-label font-normal",me?"text-foreground":"text-foreground/70"),children:S.label}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:S.hint})]})]},S.key)})}),Wt==="lan"?t.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[t.jsx(yt,{checked:bs,onChange:ks,ariaLabel:s("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,Wt==="relay"&&Yt?.lanUrl?t.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[t.jsx(yt,{checked:bs,onChange:ks,ariaLabel:s("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")})]}):null]}),gt?t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:gt}):null,t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ge(!1),disabled:ht,children:s("settings.common.actions.cancel")}),t.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:ht||!Yt,children:s("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):t.jsxs("div",{className:"space-y-3",children:[bt?t.jsx("div",{className:"flex justify-center",children:t.jsx("img",{src:bt,alt:s("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,tt?t.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[t.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:tt}),t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:pr,children:[t.jsx(E,{name:ue?"check":"file-copy",className:ce("h-3.5 w-3.5",ue&&"text-[var(--status-success)]")}),s(ue?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,t.jsx("div",{className:"flex justify-end",children:t.jsx(q,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Ge(!1),children:s("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.sidebar.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.sidebar.total",{count:a.length})})]}),t.jsxs(q,{type:"button",size:"xs",className:"!font-normal",onClick:()=>vt(!0),children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.sidebar.actions.addSshInstance")]})]})}),t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-1",children:l?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.loading")}):a.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.noneFound")}):a.map(S=>{const me=r[S.id],We=S.nickname?.trim()||S.sshParsed?.destination||S.id,at=me?.phase,Tt=at==="ready";return t.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:`h-2 w-2 rounded-full ${ul(at)}`}),t.jsx("p",{className:"typography-ui-label text-foreground truncate",children:We})]}),t.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[s(dl(at)),me?.localUrl?` · ${me.localUrl}`:""]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Tt?D(S.id):x(S.id)).catch(Zt=>_.error(s(Tt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:Zt instanceof Error?Zt.message:String(Zt)}))},children:[Tt?t.jsx(E,{name:"stop",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"plug-2",className:"h-3.5 w-3.5"}),s(Tt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),t.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>L(S.id),children:[t.jsx(E,{name:"pencil",className:"h-3.5 w-3.5"}),s("desktopHostSwitcher.actions.edit")]}),t.jsxs(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(s("settings.remoteInstances.page.confirm.removeInstance"))&&f(S.id).catch(Zt=>_.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Zt instanceof Error?Zt.message:String(Zt)}))},children:[t.jsx(E,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.delete")]})]})]},S.id)})})]}):null,n?t.jsx(Rt,{open:jt,onOpenChange:vt,children:t.jsxs(Ft,{className:"sm:max-w-lg",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("settings.remoteInstances.sidebar.actions.addSshInstance")}),t.jsx($t,{children:s("settings.remoteInstances.page.section.instanceDescription")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),ut()},children:[t.jsx(Xe,{className:"h-8",value:Vt,onChange:S=>ps(S.target.value),placeholder:s("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:c}),t.jsx(Xe,{className:"h-8",value:Ht,onChange:S=>qt(S.target.value),placeholder:s("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:c,autoFocus:!0}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>vt(!1),disabled:c,children:s("settings.common.actions.cancel")}),t.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:c||!Ht.trim(),children:s("settings.common.actions.create")})]})]})]})}):null,n?t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.import.sectionTitle")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:d?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.loading")}):i.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.import.noneFound")}):t.jsx("div",{children:i.map(S=>t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] py-3 last:border-b-0",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"typography-ui-label font-medium text-foreground truncate",children:[S.host,S.pattern?` ${s("settings.remoteInstances.page.import.patternSuffix")}`:""]}),t.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:S.sshCommand})]}),t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{cn(S.host,S.pattern)},children:s("settings.common.actions.import")})]},`${S.source}:${S.host}`))})})]}):null,t.jsx(Rt,{open:!!Q,onOpenChange:S=>{S||Os()},children:t.jsxs(Ft,{className:"sm:max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx($t,{children:Q?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Q}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Hs()},children:[t.jsx(Xe,{value:te,onChange:S=>Y(S.target.value),placeholder:s("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Os,disabled:k,children:s("settings.common.actions.cancel")}),t.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:k,children:s("settings.remoteInstances.page.actions.create")})]})]})]})})]});const ra=b.remoteOpenchamber.mode==="managed",y=b.nickname?.trim()||b.sshParsed?.destination||b.id;return t.jsx(Rt,{open:!!b,onOpenChange:S=>{S||L(null)},children:t.jsxs(Ft,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[t.jsxs("div",{className:"mb-6 px-1",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:y}),t.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${ul(Ts)}`}),t.jsx("span",{children:s(dl(Ts))}),gs?.localUrl?t.jsx("span",{className:"font-mono text-foreground/80",children:gs.localUrl}):null,Sn?t.jsx("span",{children:s("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.actions")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.actionsDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(q,{type:"button",variant:ln?"outline":"default",size:"xs",className:"!font-normal",onClick:yr,disabled:O||H,children:[ln?t.jsx(E,{name:"stop",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"plug-2",className:"h-3.5 w-3.5"}),aa]}),t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:br,disabled:!jr,children:[t.jsx(E,{name:"refresh",className:`h-3.5 w-3.5 ${Ue||Rs&&!Sn?"animate-spin":""}`}),vr]}),t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{na()},children:[t.jsx(E,{name:"terminal-window",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.logs")]}),t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(s("settings.remoteInstances.page.confirm.removeInstance"))&&f(b.id).then(()=>{L(null),_.success(s("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(me=>{_.error(s("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:me instanceof Error?me.message:String(me)})})},children:[t.jsx(E,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.sidebar.actions.remove")]})]}),gs?.localUrl?t.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx("span",{children:s("settings.remoteInstances.page.status.currentLocalUrl")}),t.jsx("span",{className:"font-mono text-foreground/90",children:gs.localUrl})]}):null]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.instance")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.instanceDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.sshCommand")}),t.jsx(Xe,{className:"h-7 md:max-w-xl",value:b.sshCommand,onChange:S=>as(me=>({...me,sshCommand:S.target.value})),placeholder:s("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.nickname")}),t.jsx(Xe,{className:"h-7 md:max-w-sm",value:b.nickname||"",onChange:S=>as(me=>({...me,nickname:S.target.value})),placeholder:s("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),t.jsx(xs,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:b.connectionTimeoutSec,onValueChange:S=>{as(me=>({...me,connectionTimeoutSec:Number.isFinite(S)?S:me.connectionTimeoutSec}))}})]})]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.remoteServer")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.remoteServerDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Gs,{label:s("settings.remoteInstances.page.field.mode"),hint:s("settings.remoteInstances.page.field.modeHint")})}),t.jsxs(At,{value:b.remoteOpenchamber.mode,onValueChange:S=>as(me=>({...me,remoteOpenchamber:{...me.remoteOpenchamber,mode:S==="external"?"external":"managed"}})),children:[t.jsx(Dt,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Ot,{placeholder:s("settings.remoteInstances.page.field.modePlaceholder")})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"managed",children:s("settings.remoteInstances.page.field.modeManaged")}),t.jsx(mt,{value:"external",children:s("settings.remoteInstances.page.field.modeExternal")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Gs,{label:s("settings.remoteInstances.page.field.preferredRemotePort"),hint:s("settings.remoteInstances.page.field.preferredRemotePortHint")})}),t.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:b.remoteOpenchamber.preferredPort,onValueChange:S=>{as(me=>({...me,remoteOpenchamber:{...me.remoteOpenchamber,preferredPort:Number.isFinite(S)&&S>0?S:void 0}}))},onClear:()=>{as(S=>({...S,remoteOpenchamber:{...S.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]}),ra?t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Gs,{label:s("settings.remoteInstances.page.field.installMethod"),hint:s("settings.remoteInstances.page.field.installMethodHint")})}),t.jsxs(At,{value:b.remoteOpenchamber.installMethod,onValueChange:S=>as(me=>({...me,remoteOpenchamber:{...me.remoteOpenchamber,installMethod:S==="npm"||S==="download_release"||S==="upload_bundle"?S:"bun"}})),children:[t.jsx(Dt,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Ot,{placeholder:s("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"bun",children:"bun"}),t.jsx(mt,{value:"npm",children:"npm"}),t.jsx(mt,{value:"download_release",children:s("settings.remoteInstances.page.field.installMethodDownloadRelease")}),t.jsx(mt,{value:"upload_bundle",children:s("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,ra?t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Gs,{label:s("settings.remoteInstances.page.field.keepServerRunning"),hint:s("settings.remoteInstances.page.field.keepServerRunningHint")})}),t.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:t.jsx(ar,{checked:b.remoteOpenchamber.keepRunning,onCheckedChange:S=>as(me=>({...me,remoteOpenchamber:{...me.remoteOpenchamber,keepRunning:S}}))})})]}):null]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.mainTunnel")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.mainTunnelDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Gs,{label:s("settings.remoteInstances.page.field.bindHost"),hint:s("settings.remoteInstances.page.field.bindHostHint")})}),t.jsxs(At,{value:b.localForward.bindHost,onValueChange:S=>{S==="0.0.0.0"&&!window.confirm(s("settings.remoteInstances.page.confirm.bindAllInterfaces"))||as(me=>({...me,localForward:{...me.localForward,bindHost:S==="localhost"||S==="0.0.0.0"?S:"127.0.0.1"}}))},children:[t.jsx(Dt,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Ot,{placeholder:s("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"127.0.0.1",children:"127.0.0.1"}),t.jsx(mt,{value:"localhost",children:"localhost"}),t.jsx(mt,{value:"0.0.0.0",children:"0.0.0.0"})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Gs,{label:s("settings.remoteInstances.page.field.preferredLocalPort"),hint:s("settings.remoteInstances.page.field.preferredLocalPortHint")})}),t.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[t.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:b.localForward.preferredLocalPort,onValueChange:S=>{as(me=>({...me,localForward:{...me.localForward,preferredLocalPort:Number.isFinite(S)&&S>0?S:void 0}}))},onClear:()=>{as(S=>({...S,localForward:{...S.localForward,preferredLocalPort:void 0}}))},emptyLabel:s("settings.remoteInstances.page.field.auto")}),t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:s("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>as(S=>({...S,localForward:{...S.localForward,preferredLocalPort:vi()}})),children:t.jsx(E,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]})]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.authentication")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.authenticationDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.sshPasswordOptional")}),t.jsx(Xe,{className:"h-7 md:max-w-sm",type:"password",value:b.auth.sshPassword?.value||"",onChange:S=>as(me=>({...me,auth:{...me.auth,sshPassword:{enabled:S.target.value.trim().length>0,value:S.target.value,store:me.auth.sshPassword?.store||"never"}}})),placeholder:s("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:s("settings.remoteInstances.page.field.uiPasswordOptional")}),t.jsx(Xe,{className:"h-7 md:max-w-sm",type:"password",value:b.auth.openchamberPassword?.value||"",onChange:S=>as(me=>({...me,auth:{...me.auth,openchamberPassword:{enabled:S.target.value.trim().length>0,value:S.target.value,store:me.auth.openchamberPassword?.store||"never"}}})),placeholder:s("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]})]}),t.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[t.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.remoteInstances.page.section.portForwards")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.section.portForwardsDescription")})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[b.portForwards.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground/80",children:s("settings.remoteInstances.page.empty.noExtraForwards")}):null,b.portForwards.map((S,me)=>{const We=Lt=>{as(ss=>({...ss,portForwards:ss.portForwards.map((oa,Ut)=>Ut===me?Lt(oa):oa)}))},at=S.type==="remote"?"Local target":"Local listen",Tt=S.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",js=S.type==="remote"?"Remote listen":"Remote target",Zt=S.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",mn=ml(S.localHost||"localhost",S.localPort),Cn=ml(S.remoteHost||"localhost",S.remotePort),Ws=S.type==="local"&&typeof S.localPort=="number"&&S.localPort>0,wr=Ws?`http://${Cx(S.localHost)}:${S.localPort}`:"",ia=!!B[S.id],Nr=S.type==="local"?s("settings.remoteInstances.page.forwardType.local"):S.type==="remote"?s("settings.remoteInstances.page.forwardType.remote"):s("settings.remoteInstances.page.forwardType.dynamic");return t.jsxs(Mn,{open:ia,onOpenChange:Lt=>{F(ss=>({...ss,[S.id]:Lt}))},className:`${me>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("div",{className:"min-w-0 flex items-center gap-2",children:t.jsxs(Tn,{className:"flex items-center gap-2 group",children:[t.jsx(E,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${ia?"rotate-180":""}`}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:wx(S)}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Nr})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ar,{checked:S.enabled,onCheckedChange:Lt=>We(ss=>({...ss,enabled:Lt})),"aria-label":s("settings.remoteInstances.page.actions.enableForwardAria")}),t.jsx(q,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>as(Lt=>({...Lt,portForwards:Lt.portForwards.filter(ss=>ss.id!==S.id)})),children:t.jsx(E,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Rn,{className:"pt-2",children:t.jsxs("div",{className:"space-y-0 pb-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:s(Sx(S.type))}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Gs,{label:s("settings.remoteInstances.page.field.forwardType"),hint:s("settings.remoteInstances.page.field.forwardTypeHint")})}),t.jsxs(At,{value:S.type,onValueChange:Lt=>We(ss=>({...ss,type:Lt==="dynamic"||Lt==="remote"?Lt:"local"})),children:[t.jsx(Dt,{className:"h-7 w-fit min-w-[140px]",children:t.jsx(Ot,{placeholder:s("settings.remoteInstances.page.field.typePlaceholder")})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"local",children:s("settings.remoteInstances.page.forwardType.local")}),t.jsx(mt,{value:"remote",children:s("settings.remoteInstances.page.forwardType.remote")}),t.jsx(mt,{value:"dynamic",children:s("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Gs,{label:at,hint:Tt})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(Xe,{className:"h-7 w-32",value:S.localHost||"127.0.0.1",onChange:Lt=>We(ss=>({...ss,localHost:Lt.target.value})),placeholder:s("settings.remoteInstances.page.field.localHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:S.localPort,onValueChange:Lt=>{We(ss=>({...ss,localPort:Number.isFinite(Lt)&&Lt>0?Lt:void 0}))},onClear:()=>{We(Lt=>({...Lt,localPort:void 0}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]})]}),S.type!=="dynamic"?t.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[t.jsx("div",{className:"w-56 shrink-0",children:t.jsx(Gs,{label:js,hint:Zt})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(Xe,{className:"h-7 w-32",value:S.remoteHost||"",onChange:Lt=>We(ss=>({...ss,remoteHost:Lt.target.value})),placeholder:s("settings.remoteInstances.page.field.remoteHostPlaceholder")}),t.jsx("span",{className:"text-muted-foreground",children:":"}),t.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:S.remotePort,onValueChange:Lt=>{We(ss=>({...ss,remotePort:Number.isFinite(Lt)&&Lt>0?Lt:void 0}))},onClear:()=>{We(Lt=>({...Lt,remotePort:void 0}))},emptyLabel:s("settings.remoteInstances.page.field.auto")})]})]}):null,t.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[t.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:S.type==="dynamic"?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:mn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.localSocks5")})]}):S.type==="remote"?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"server",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:Cn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.remote")}),t.jsx(E,{name:"arrow-right",className:"h-3.5 w-3.5"}),t.jsx(E,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:mn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.local")})]}):t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"computer",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:mn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.local")}),t.jsx(E,{name:"arrow-right",className:"h-3.5 w-3.5"}),t.jsx(E,{name:"server",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"font-mono text-foreground",children:Cn}),t.jsx("span",{children:s("settings.remoteInstances.page.preview.remote")})]})}),Ws?t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{tn(wr).then(Lt=>{Lt||_.error(s("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[t.jsx(E,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},S.id)}),t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const S=Nx();as(me=>({...me,portForwards:[...me.portForwards,S]})),F(me=>({...me,[S.id]:!0}))},children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.addForward")]})]})]}),t.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(q,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{fr()},disabled:!hr||c,children:s("settings.common.actions.saveChanges")}),gs?.localUrl?t.jsxs(t.Fragment,{children:[t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{En(gs.localUrl||"").then(S=>{S.ok&&_.success(s("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[t.jsx(E,{name:"file-copy",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.copyLocalUrl")]}),t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{xr()},children:[t.jsx(E,{name:"external-link",className:"h-3.5 w-3.5"}),s("settings.remoteInstances.page.actions.open")]})]}):null,h?t.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:h}):null]})}),t.jsx(Rt,{open:T,onOpenChange:U,children:t.jsxs(Ft,{className:"sm:max-w-2xl",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("settings.remoteInstances.page.logsDialog.title")}),t.jsx($t,{children:b?.nickname?.trim()||b?.sshParsed?.destination||b?.id||s("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Un,disabled:K||!Fs.trim(),children:[t.jsx(E,{name:"file-copy",className:"h-3.5 w-3.5"}),s("settings.common.actions.copyAll")]}),t.jsxs(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{un()},disabled:K,children:[t.jsx(E,{name:"delete-bin",className:"h-3.5 w-3.5"}),s("settings.common.actions.clear")]})]}),K?t.jsx("div",{className:"typography-meta text-muted-foreground",children:s("settings.remoteInstances.page.logsDialog.loading")}):C?t.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:C}):t.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:z.length>0?z.join(`
|
|
29
|
+
`):s("settings.remoteInstances.page.logsDialog.empty")})]})}),t.jsx(Rt,{open:!!Q,onOpenChange:S=>{S||Os()},children:t.jsxs(Ft,{className:"sm:max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:s("settings.remoteInstances.page.patternDialog.title")}),t.jsx($t,{children:Q?s("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Q}):s("settings.remoteInstances.page.patternDialog.description")})]}),t.jsxs("form",{className:"space-y-3",onSubmit:S=>{S.preventDefault(),Hs()},children:[t.jsx(Xe,{value:te,onChange:S=>Y(S.target.value),placeholder:s("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Os,disabled:k,children:s("settings.common.actions.cancel")}),t.jsx(q,{type:"submit",size:"xs",className:"!font-normal",disabled:k,children:s("settings.common.actions.create")})]})]})]})})]})})},Tx="__add_provider__",Rx=()=>{const s=ys.getDirectory();return typeof s=="string"&&s.trim().length>0?s.trim():null},Fx=({onItemSelect:s})=>{const{t:e}=st(),n=lt(u=>u.providers),a=lt(u=>u.selectedProviderId),r=lt(u=>u.setSelectedProvider),i=es(u=>u.activeProjectId),[l,d]=o.useState({}),c=o.useMemo(()=>Rx(),[i]);o.useEffect(()=>{if(n.length===0){d({});return}let u=!1;return(async()=>{const g=n.map(async f=>{try{const x=c?`?directory=${encodeURIComponent(c)}`:"",D=await ct(`/api/provider/${encodeURIComponent(f.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const P=await D.json().catch(()=>null),I=P?.sources??P?.data?.sources;if(!I||u)return;d(L=>({...L,[f.id]:I}))}catch{}});await Promise.all(g)})(),()=>{u=!0}},[c,n]);const h="bg-background",m=o.useMemo(()=>n.filter(u=>!!l[u.id]?.project?.exists),[n,l]),p=o.useMemo(()=>n.filter(u=>!l[u.id]?.project?.exists),[n,l]);return t.jsxs("div",{className:ce("flex h-full flex-col",h),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.providers.sidebar.title")}),t.jsx(ka,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),t.jsx(q,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(Tx),s?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:t.jsx(E,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(_t,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(E,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[p.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),p.map(u=>t.jsx(gl,{provider:u,selectedProviderId:a,onSelect:()=>{r(u.id),s?.()}},u.id))]}),m.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:ce("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",p.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(u=>t.jsx(gl,{provider:u,selectedProviderId:a,onSelect:()=>{r(u.id),s?.()}},u.id))]})]})})]})},gl=s=>{const e=et.c(17),{provider:n,selectedProviderId:a,onSelect:r}=s,i=Array.isArray(n.models)?n.models.length:0,l=n.id===a,d=n.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[0]!==c?(h=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=h):h=e[1];let m;e[2]!==n.id?(m=t.jsx(Yn,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const p=n.name||n.id;let u;e[4]!==p?(u=t.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:p}),e[4]=p,e[5]=u):u=e[5];let w;e[6]!==i?(w=t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=w):w=e[7];let g;e[8]!==r||e[9]!==m||e[10]!==u||e[11]!==w?(g=t.jsxs("button",{type:"button",onClick:r,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,u,w]}),e[8]=r,e[9]=m,e[10]=u,e[11]=w,e[12]=g):g=e[12];let f;return e[13]!==n.id||e[14]!==h||e[15]!==g?(f=t.jsx("div",{className:h,children:g},d),e[13]=n.id,e[14]=h,e[15]=g,e[16]=f):f=e[16],f},Lx=s=>s,_r=({providerId:s,providerName:e})=>{const{t:n}=st(),[a,r]=o.useState(null),[i,l]=o.useState({}),[d,c]=o.useState(!1),h=`/api/quota/credentials/${s}`;o.useEffect(()=>{ct(h).then(async u=>{if(!u.ok)throw new Error;const w=await u.json();r(w),l(w.workspaceId?{workspaceId:w.workspaceId}:{})}).catch(()=>r({configured:!1}))},[h]);const m=async(u,w,g)=>{c(!0);try{const f=await ct(u,{method:w,headers:g?{"Content-Type":"application/json"}:void 0,body:g?JSON.stringify(g):void 0}),x=await f.json().catch(()=>null);if(!f.ok)throw new Error(x?.error);x?.configured!==void 0&&r(x),l(D=>D.workspaceId?{workspaceId:D.workspaceId}:{}),_.success(n("settings.providers.page.openCodeGo.saved"))}catch(f){_.error(f instanceof Error&&f.message?f.message:n("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},p=(u,w,g)=>t.jsxs("label",{className:"block typography-ui-label text-foreground",children:[w,t.jsx(Xe,{className:"mt-1 h-7 font-mono text-xs",type:u==="workspaceId"?"text":"password",autoComplete:"off",value:i[u]??"",onChange:f=>l(x=>({...x,[u]:f.target.value})),placeholder:a?.secretMasked??g})]});return t.jsxs("div",{"data-settings-item":`providers.${s}-credentials`,className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),t.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s==="opencode-go"&&p("workspaceId",n("settings.providers.page.openCodeGo.workspaceId"),"wrk_..."),s==="opencode-go"&&p("authCookie",n("settings.providers.page.openCodeGo.authCookie"),"auth=..."),s==="ollama-cloud"&&p("cookie",n("settings.providers.page.openCodeGo.authCookie"),"session=..."),s==="cursor"&&p("accessToken",n("settings.providers.page.auth.apiKeyLabel"),n("settings.providers.page.auth.apiKeyPlaceholder")),s==="cursor"&&p("refreshToken",n("settings.providers.page.auth.apiKeyLabel"),n("settings.providers.page.auth.apiKeyPlaceholder")),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(q,{size:"xs",disabled:d,onClick:()=>m(h,"PUT",i),children:a?.configured?n("settings.providers.page.openCodeGo.replace"):n("settings.providers.page.openCodeGo.save")}),a?.configured&&t.jsx(q,{variant:"outline",size:"xs",disabled:d,onClick:()=>m(`${h}/validate`,"POST"),children:n("settings.providers.page.openCodeGo.validate")}),s==="cursor"&&t.jsx(q,{variant:"outline",size:"xs",disabled:d,onClick:()=>m(`${h}/import`,"POST"),children:n("settings.providers.page.actions.connect")}),a?.configured&&t.jsx(q,{variant:"destructive",size:"xs",disabled:d,onClick:()=>m(h,"DELETE"),children:n("settings.providers.page.openCodeGo.delete")})]})]})]})},Ox=s=>new Intl.NumberFormat(Ai(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(s),hl=s=>{if(typeof s!="number"||Number.isNaN(s))return null;if(s===0)return"0";const e=Ox(s);return e.endsWith(".0")?e.slice(0,-2):e},Ka="__add_provider__",ea=s=>typeof s=="object"&&s!==null,fl=s=>{const e=typeof s.type=="string"?s.type:"",n=`${s.name??""} ${s.label??""}`.toLowerCase(),a=`${e} ${n}`.toLowerCase();return a.includes("oauth")?"oauth":a.includes("api")?"api":e.toLowerCase()},zx=s=>{if(!ea(s))return{};const e={};for(const[n,a]of Object.entries(s))Array.isArray(a)&&(e[n]=a.filter(r=>ea(r)));return e},Kx=s=>{if(typeof s=="string")return{id:s};if(!ea(s))return null;const e=typeof s.id=="string"&&s.id||typeof s.providerID=="string"&&s.providerID||typeof s.slug=="string"&&s.slug||typeof s.name=="string"&&s.name;if(!e)return null;const n=typeof s.name=="string"?s.name:void 0;return{id:e,name:n}},Ux=s=>{let e=[];Array.isArray(s)?e=s:ea(s)&&(Array.isArray(s.all)?e=s.all:Array.isArray(s.providers)&&(e=s.providers));const n=e.map(r=>Kx(r)).filter(r=>!!r),a=new Set;return n.filter(r=>a.has(r.id)?!1:(a.add(r.id),!0))},Bx=()=>{const{t:s}=st(),e=lt(G=>G.providers),n=lt(G=>G.selectedProviderId),a=lt(G=>G.setSelectedProvider),r=lt(G=>G.getModelMetadata),i=Ie(G=>G.hiddenModels),l=Ie(G=>G.toggleHiddenModel),d=Ie(G=>G.hideAllModels),c=Ie(G=>G.showAllModels),[h,m]=o.useState({}),[p,u]=o.useState(!1),[w,g]=o.useState({}),[f,x]=o.useState(null),[D,P]=o.useState(""),[I,L]=o.useState(null),[N,b]=o.useState({}),[j,T]=o.useState({}),[U,K]=o.useState([]),[M,C]=o.useState(!1),[A,z]=o.useState(null),[R,Q]=o.useState(""),[W,te]=o.useState(""),[Y,k]=o.useState(!1),[$,B]=o.useState({}),[F,O]=o.useState(!1),J=n===Ka;o.useEffect(()=>{!n&&e.length>0&&a(e[0].id)},[e,n,a]),o.useEffect(()=>{if(!J)return;let G=!0;return(async()=>{u(!0);try{const ie=await ys.getSdkClient().provider.auth();if(ie.error)throw new Error(`provider.auth failed: ${String(ie.error)}`);if(!G)return;m(zx(ie.data))}catch(ie){if(!G)return;console.error("Failed to load provider auth methods:",ie),_.error(s("settings.providers.page.toast.authMethodsLoadFailed"))}finally{G&&u(!1)}})(),()=>{G=!1}},[J,s]),o.useEffect(()=>{if(!Lx(J))return;let G=!0;return(async()=>{C(!0),z(null);try{const ie=await ys.getSdkClient().provider.list();if(ie.error)throw new Error(`provider.list failed: ${String(ie.error)}`);if(!G)return;K(Ux(ie.data))}catch(ie){if(!G)return;console.error("Failed to load available providers:",ie),z(s("settings.providers.page.state.unableToLoadProviderList"))}finally{G&&C(!1)}})(),()=>{G=!1}},[J,s]);const H=o.useMemo(()=>new Set(e.map(G=>G.id)),[e]),re=o.useMemo(()=>U.filter(G=>!H.has(G.id)).sort((G,ee)=>{const ie=(G.name||G.id).toLowerCase(),pe=(ee.name||ee.id).toLowerCase();return ie.localeCompare(pe)}),[U,H]);o.useEffect(()=>{n===Ka&&R&&!re.some(G=>G.id===R)&&Q("")},[n,R,re]),o.useEffect(()=>{if(n===Ka){O(!0);return}O(!1)},[n,s]),o.useEffect(()=>{if(!n||n===Ka)return;let G=!1;return(async()=>{try{const ie=await ct(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),pe=await ie.json().catch(()=>null);if(!ie.ok)throw new Error(pe?.error||s("settings.providers.page.toast.providerSourcesLoadFailed"));const Ae=pe?.sources??pe?.data?.sources;!G&&Ae&&B(Se=>({...Se,[n]:Ae}))}catch(ie){G||console.error("Failed to load provider sources:",ie)}})(),()=>{G=!0}},[n,s]);const le=e.find(G=>G.id===n),ne=n?$[n]:void 0,be=async G=>{const ee=w[G]?.trim()??"";if(!ee){_.error(s("settings.providers.page.toast.apiKeyRequired"));return}const ie=`api:${G}`;x(ie);try{if((await ys.getSdkClient().auth.set({providerID:G,auth:{type:"api",key:ee}})).error)throw new Error(s("settings.providers.page.toast.apiKeySaveFailed"));_.success(s("settings.providers.page.toast.apiKeySaved")),g(Ae=>({...Ae,[G]:""})),await Jn({scopes:["providers"],mode:"active"}),a(G)}catch(pe){console.error("Failed to save API key:",pe),_.error(s("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},ae=async(G,ee)=>{const ie=`oauth:${G}:${ee}`;x(ie);try{const pe=await ys.getSdkClient().provider.oauth.authorize({providerID:G,method:ee});if(pe.error)throw new Error(s("settings.providers.page.toast.oauthStartFailed"));const Ae=ea(pe.data)?pe.data:{},Se=Ae.data,De=ea(Se)?Se:Ae,Me=typeof De.url=="string"&&De.url||typeof De.verification_uri_complete=="string"&&De.verification_uri_complete||typeof De.verification_uri=="string"&&De.verification_uri||void 0,Te=typeof De.instructions=="string"&&De.instructions||typeof De.message=="string"&&De.message||void 0,Be=typeof De.user_code=="string"&&De.user_code||typeof De.code=="string"&&De.code||typeof De.userCode=="string"&&De.userCode||void 0;if(!Me&&!Te&&!Be)throw new Error(s("settings.providers.page.toast.oauthDetailsMissing"));const ze=`${G}:${ee}`;T(Oe=>({...Oe,[ze]:{url:Me,instructions:Te,userCode:Be}})),Me&&tn(Me),L({providerId:G,methodIndex:ee}),_.message(s("settings.providers.page.toast.completeOAuthInBrowser"))}catch(pe){console.error("Failed to start OAuth flow:",pe),_.error(s("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},ye=async(G,ee)=>{const ie=`${G}:${ee}`,pe=N[ie]?.trim(),Ae=`oauth-complete:${G}:${ee}`;x(Ae);try{const Se={method:ee};if(pe&&(Se.code=pe),(await ys.getSdkClient().provider.oauth.callback({providerID:G,method:Se.method,code:Se.code})).error)throw new Error(s("settings.providers.page.toast.oauthCompleteFailed"));_.success(s("settings.providers.page.toast.oauthCompleted")),b(Me=>({...Me,[ie]:""})),L(null),await Jn({scopes:["providers"],mode:"active"}),a(G)}catch(Se){console.error("Failed to complete OAuth flow:",Se),_.error(s("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},ke=async G=>{const ee=await En(G);if(ee.ok){_.success(s("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",ee.error),_.error(s("settings.providers.page.toast.oauthLinkCopyFailed"))},he=async G=>{const ee=await En(G);if(ee.ok){_.success(s("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",ee.error),_.error(s("settings.providers.page.toast.deviceCodeCopyFailed"))},we=async G=>{const ee=`disconnect:${G}`;x(ee);try{const ie=await ct(`/api/provider/${encodeURIComponent(G)}/auth?scope=all`,{method:"DELETE",headers:{Accept:"application/json"}}),pe=await ie.json().catch(()=>null);if(!ie.ok)throw new Error(pe?.error||s("settings.providers.page.toast.providerDisconnectFailed"));_.success(s("settings.providers.page.toast.providerDisconnected")),await Jn({scopes:["providers"],mode:"active"})}catch(ie){console.error("Failed to disconnect provider:",ie),_.error(s("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}};if(!J&&e.length===0)return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(E,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.providers.page.empty.noProvidersDetected")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(J)return t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{"data-settings-item":"providers.connect",className:"mb-4",children:t.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.providers.page.connect.title")})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.connect.selectProviderTitle")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.providers.page.connect.providerField")}),M?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.state.loading")}):A?t.jsx("p",{className:"typography-meta text-muted-foreground",children:A}):re.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.connect.allProvidersConnected")}):t.jsxs(ds,{open:Y,onOpenChange:G=>{k(G),G||te("")},children:[t.jsx(ls,{asChild:!0,children:t.jsxs("button",{type:"button",className:ce("flex items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover h-6 w-fit"),children:[t.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[R?t.jsx(Yn,{providerId:R,className:"h-3.5 w-3.5 flex-shrink-0"}):null,t.jsx("span",{className:ce("truncate typography-ui-label font-normal",R?"text-foreground":"text-muted-foreground"),children:R?re.find(G=>G.id===R)?.name||R:s("settings.providers.page.connect.selectProviderPlaceholder")})]}),t.jsx(E,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),t.jsxs(cs,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:G=>G.preventDefault(),children:[t.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:G=>G.stopPropagation(),children:[t.jsx(E,{name:"search",className:"h-4 w-4 text-muted-foreground"}),t.jsx("input",{type:"text",value:W,onChange:G=>te(G.target.value),onKeyDown:G=>G.stopPropagation(),placeholder:s("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),t.jsx(_t,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const G=re.filter(ee=>{const ie=W.toLowerCase();return(ee.name||ee.id).toLowerCase().includes(ie)||ee.id.toLowerCase().includes(ie)});return G.length===0?t.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:s("settings.providers.page.connect.noProvidersFound")}):G.map(ee=>t.jsxs(Ns,{onSelect:()=>{Q(ee.id),k(!1),te("")},className:"flex items-center justify-between",children:[t.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(Yn,{providerId:ee.id,className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:ee.name||ee.id})]}),R===ee.id&&t.jsx(E,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ee.id))})()})]})]})]})})]}),R&&t.jsxs("div",{"data-settings-item":"providers.auth",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.auth.title")})}),p?t.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:s("settings.providers.page.auth.loadingMethods")}):t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[t.jsxs("div",{className:"py-1.5",children:[t.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[s("settings.providers.page.auth.apiKeyLabel"),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.providers.page.auth.apiKeyTooltip")})]})]}),t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[t.jsx(Xe,{type:"password",value:w[R]??"",onChange:G=>g(ee=>({...ee,[R]:G.target.value})),placeholder:s("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),t.jsx(q,{size:"xs",className:"!font-normal shrink-0",onClick:()=>be(R),disabled:f===`api:${R}`,children:f===`api:${R}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),(()=>{const ee=(h[R]??[]).filter(ie=>fl(ie)==="oauth");return ee.length===0?null:t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ee.map((ie,pe)=>{const Ae=ie.label||ie.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String(pe+1)}),Se=`${R}:${pe}`,De=I?.providerId===R&&I?.methodIndex===pe;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:Ae}),(ie.description||ie.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(ie.description||ie.help)})]}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ae(R,pe),disabled:f===`oauth:${R}:${pe}`,children:s("settings.providers.page.actions.connect")})]}),j[Se]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:j[Se]?.instructions}),j[Se]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:j[Se]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>he(j[Se]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),j[Se]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:j[Se]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>tn(j[Se]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ke(j[Se]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),De&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:N[Se]??"",onChange:Me=>b(Te=>({...Te,[Se]:Me.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(q,{size:"xs",className:"!font-normal",onClick:()=>ye(R,pe),disabled:f===`oauth-complete:${R}:${pe}`,children:f===`oauth-complete:${R}:${pe}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${R}-${Ae}`)})})})()]})]})]})});if(!le)return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(E,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.providers.page.empty.selectProviderFromSidebar")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const de=Array.isArray(le.models)?le.models:[],se=(h[le.id]??[]).filter(G=>fl(G)==="oauth"),ve=de.filter(G=>{const ee=typeof G?.name=="string"?G.name:"",ie=typeof G?.id=="string"?G.id:"",pe=D.trim().toLowerCase();return pe?ee.toLowerCase().includes(pe)||ie.toLowerCase().includes(pe):!0});return t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[t.jsx(Yn,{providerId:le.id,className:"h-5 w-5 shrink-0"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:le.name||le.id}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t.jsx("span",{className:"font-mono",children:le.id})})]})]}),t.jsxs("div",{"data-settings-item":"providers.auth",className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.auth.title")}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>O(G=>!G),children:s(F?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:F?p?t.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:s("settings.providers.page.auth.loadingMethods")}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"py-1.5",children:[t.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[s("settings.providers.page.auth.apiKeyLabel"),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.providers.page.auth.apiKeyTooltip")})]})]}),t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[t.jsx(Xe,{type:"password",value:w[le.id]??"",onChange:G=>g(ee=>({...ee,[le.id]:G.target.value})),placeholder:s("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),t.jsx(q,{size:"xs",className:"!font-normal shrink-0",onClick:()=>be(le.id),disabled:f===`api:${le.id}`,children:f===`api:${le.id}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.saveKey")})]})]}),se.length>0&&t.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:se.map((G,ee)=>{const ie=G.label||G.name||s("settings.providers.page.auth.oauthMethodFallback",{index:String(ee+1)}),pe=`${le.id}:${ee}`,Ae=I?.providerId===le.id&&I?.methodIndex===ee;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:ie}),(G.description||G.help)&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:String(G.description||G.help)})]}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ae(le.id,ee),disabled:f===`oauth:${le.id}:${ee}`,children:s("settings.providers.page.actions.connect")})]}),j[pe]?.instructions&&t.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:j[pe]?.instructions}),j[pe]?.userCode&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:j[pe]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>he(j[pe]?.userCode??""),children:s("settings.providers.page.actions.copyCode")})]}),j[pe]?.url&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:j[pe]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>tn(j[pe]?.url??""),children:s("settings.providers.page.actions.open")}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ke(j[pe]?.url??""),children:s("settings.providers.page.actions.copy")})]})]}),Ae&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsx(Xe,{value:N[pe]??"",onChange:Se=>b(De=>({...De,[pe]:Se.target.value})),placeholder:s("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),t.jsx(q,{size:"xs",className:"!font-normal",onClick:()=>ye(le.id,ee),disabled:f===`oauth-complete:${le.id}:${ee}`,children:f===`oauth-complete:${le.id}:${ee}`?s("settings.providers.page.actions.saving"):s("settings.providers.page.actions.complete")})]})]},`${le.id}-${ie}`)})})]}):t.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[t.jsx(E,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.providers.page.auth.connected")}),t.jsx("span",{className:"typography-meta text-muted-foreground ml-1",children:s("settings.providers.page.auth.useReconnectHint")})]})})]}),(le.id==="opencode"||le.id==="opencode-go")&&t.jsx(_r,{providerId:"opencode-go",providerName:"OpenCode Go"}),(le.id==="ollama"||le.id==="ollama-cloud")&&t.jsx(_r,{providerId:"ollama-cloud",providerName:"Ollama Cloud"}),le.id==="cursor"&&t.jsx(_r,{providerId:"cursor",providerName:"Cursor"}),t.jsxs("div",{"data-settings-item":"providers.connection-details",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.providers.page.connectionDetails.title")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col",children:ne&&(ne.auth.exists||ne.user.exists||ne.project.exists||ne.custom?.exists)?t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[s("settings.providers.page.connectionDetails.configuredIn")," ",[ne.auth.exists?s("settings.providers.page.connectionDetails.source.authCredentials"):null,ne.user.exists?s("settings.providers.page.connectionDetails.source.userConfig"):null,ne.project.exists?s("settings.providers.page.connectionDetails.source.projectConfig"):null,ne.custom?.exists?s("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.providers.page.connectionDetails.noActiveSource")})}),t.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>we(le.id),disabled:f===`disconnect:${le.id}`,children:f===`disconnect:${le.id}`?s("settings.providers.page.actions.disconnecting"):s("settings.providers.page.actions.disconnect")})]})})]}),t.jsxs("div",{"data-settings-item":"providers.models",className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[t.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[s("settings.providers.page.models.title"),de.length>0&&t.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",de.length,")"]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const G=de.map(ee=>typeof ee?.id=="string"?ee.id:"").filter(ee=>ee.length>0);d(le.id,G)},children:s("settings.providers.page.actions.hideAll")}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>c(le.id),children:s("settings.providers.page.actions.showAll")})]})]}),t.jsxs("section",{className:"px-2 pb-2 pt-0",children:[t.jsxs("div",{className:"relative mb-2",children:[t.jsx(E,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),t.jsx(Xe,{value:D,onChange:G=>P(G.target.value),placeholder:s("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ve.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:s("settings.providers.page.models.noModelsMatchFilter")}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:ve.map(G=>{const ee=typeof G?.id=="string"?G.id:"",ie=typeof G?.name=="string"?G.name:ee,pe=ee?r(le.id,ee):void 0,Ae=i.some(Te=>Te.providerID===le.id&&Te.modelID===ee),Se=hl(pe?.limit?.context),De=hl(pe?.limit?.output),Me=[];return pe?.tool_call&&Me.push({key:"tools",icon:"tools",label:s("settings.providers.page.models.capability.toolCalling")}),pe?.reasoning&&Me.push({key:"reasoning",icon:"brain-ai-3",label:s("settings.providers.page.models.capability.reasoning")}),pe?.attachment&&Me.push({key:"image",icon:"file-image",label:s("settings.providers.page.models.capability.imageInput")}),t.jsx("div",{className:"py-1.5",children:t.jsxs("div",{className:ce("flex items-center gap-3",Ae&&"opacity-50"),children:[t.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:ie}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Se||De)&&t.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Se?`${Se} ${s("settings.providers.page.models.tokenBadge.context")}`:"",Se&&De?" · ":"",De?`${De} ${s("settings.providers.page.models.tokenBadge.output")}`:""]}),Me.length>0&&t.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Me.map(({key:Te,icon:Be,label:ze})=>t.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:ze,"aria-label":ze,children:t.jsx(E,{name:Be,className:"h-3 w-3"})},Te))}),t.jsx("button",{type:"button",onClick:()=>l(le.id,ee),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:s(Ae?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":s(Ae?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Ae?t.jsx(E,{name:"eye-off",className:"h-3.5 w-3.5"}):t.jsx(E,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ee)})})]})]})]})})},jn=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"cursor",name:"Cursor"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"wafer",name:"Wafer.ai"},{id:"opencode-go",name:"OpenCode Go"}];function xl(s){const e=s.indexOf("/");if(e!==-1){const n=s.substring(0,e);if(n==="gemini"||n==="antigravity")return s.substring(e+1)}return s}const $x=[{id:"gemini-auth",label:"Gemini",matcher:s=>s.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:s=>s.startsWith("antigravity/"),order:2}],Oc={google:$x};function zc(s,e){const n=Oc[e]??[];for(const a of n)if(a.matcher(s))return a;return null}function Vx(s){return Oc[s]??[]}function _x(s){return[...s].sort((e,n)=>e.order-n.order)}function Xj(s,e){const n=new Map;for(const a of Object.keys(s)){const i=zc(a,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(a)}return n}function Hx(s,e,n){const a=new Map;for(const r of s){const i=e(r),d=zc(i,n)?.id??null;a.has(d)||a.set(d,[]),a.get(d).push(r)}return a}function Wx(s,e){return e.filter(n=>{const a=n.toLowerCase(),r=a.includes("/")?a.split("/")[1]:a;return!!(r.startsWith("gemini-3-")||r.startsWith("claude-"))})}const Ti=6e4,yl=s=>{const e=jn.map(u=>u.id),n=typeof s?.usageAutoRefresh=="boolean"?s.usageAutoRefresh:!1,a=typeof s?.usageRefreshIntervalMs=="number"&&Number.isFinite(s.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(s.usageRefreshIntervalMs))):Ti,r=s?.usageDisplayMode==="remaining"?"remaining":"usage",i=typeof s?.usageShowPredValues=="boolean"?s.usageShowPredValues:!1,l=Array.isArray(s?.usageDropdownProviders)?s?.usageDropdownProviders:null,d=l?l.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},h=s?.usageSelectedModels;if(h&&typeof h=="object")for(const[u,w]of Object.entries(h))Array.isArray(w)&&(c[u]=w.filter(g=>typeof g=="string"));const m={},p=s?.usageExpandedFamilies;if(p&&typeof p=="object")for(const[u,w]of Object.entries(p))Array.isArray(w)&&(m[u]=w.filter(g=>typeof g=="string"));return{autoRefresh:n,refreshIntervalMs:a,displayMode:r,showPredValues:i,dropdownProviderIds:d,selectedModels:c,expandedFamilies:m}},Gx=async()=>{const s=Vs()?.settings;if(s)try{const n=(await s.load())?.settings;return yl(n??null)}catch{}if(!ms()){const e=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return yl(n)}}return{autoRefresh:!1,refreshIntervalMs:Ti,displayMode:"usage",showPredValues:!1,dropdownProviderIds:jn.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Bt=wn()(Na((s,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Ti,displayMode:"usage",showPredValues:!1,dropdownProviderIds:jn.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Gx();s(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{s({isLoading:!0,error:null});const n=jn.map(a=>a.id);try{await Promise.all(n.map(a=>e().fetchProviderQuota(a))),s({isLoading:!1,lastUpdated:Date.now()})}catch(a){const r=a instanceof Error?a.message:"Failed to fetch quotas";s({isLoading:!1,error:r})}},fetchProviderQuota:async n=>{s(a=>({isFetchingProvider:{...a.isFetchingProvider,[n]:!0}}));try{const a=await ct(`/api/quota/${encodeURIComponent(n)}`),r=await a.json().catch(()=>null);if(!a.ok)throw new Error(r?.error||"Failed to fetch quota");const i=r;s(l=>{const d=l.results.filter(c=>c.providerId!==n);return d.push(i),{results:d,error:null}})}catch(a){const r=a instanceof Error?a.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:r,usage:null,fetchedAt:Date.now()};s(l=>{const d=l.results.filter(c=>c.providerId!==n);return d.push(i),{results:d,error:r}})}finally{s(a=>({isFetchingProvider:{...a.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>s({selectedProviderId:n}),setAutoRefresh:n=>s({autoRefresh:n}),setRefreshInterval:n=>{const a=Math.max(3e4,Math.min(3e5,Math.round(n)));s({refreshIntervalMs:a})},setDisplayMode:n=>s({displayMode:n}),setShowPredValues:n=>s({showPredValues:n}),setDropdownProviderIds:n=>s({dropdownProviderIds:n}),setSelectedModels:(n,a)=>{s(r=>({selectedModels:{...r.selectedModels,[n]:a}}))},toggleModelSelected:(n,a)=>{s(r=>{const i=r.selectedModels[n]??[],d=i.includes(a)?i.filter(c=>c!==a):[...i,a];return{selectedModels:{...r.selectedModels,[n]:d}}})},setExpandedFamilies:(n,a)=>{s(r=>({expandedFamilies:{...r.expandedFamilies,[n]:a}})),Nt({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,a)=>{s(r=>{const i=r.expandedFamilies[n]??[],d=i.includes(a)?i.filter(c=>c!==a):[...i,a];return{expandedFamilies:{...r.expandedFamilies,[n]:d}}}),Nt({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,a)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=Wx(n,a);i.length!==0&&(s(l=>({selectedModels:{...l.selectedModels,[n]:i}})),Nt({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),qx=()=>{const s=et.c(5),e=Bt(Jx),n=Bt(Qx),a=Bt(Yx);let r,i;s[0]!==e||s[1]!==a||s[2]!==n?(r=()=>{if(!e)return;const l=window.setInterval(()=>{a()},n);return()=>window.clearInterval(l)},i=[e,n,a],s[0]=e,s[1]=a,s[2]=n,s[3]=r,s[4]=i):(r=s[3],i=s[4]),o.useEffect(r,i)};function Jx(s){return s.autoRefresh}function Qx(s){return s.refreshIntervalMs}function Yx(s){return s.fetchAllQuotas}const Xx=s=>{const e=s?.windows??{},n=Object.values(e).map(a=>a.usedPercent).filter(a=>typeof a=="number");return n.length===0?null:Math.max(...n)},Zx=s=>{const e=et.c(122),{onItemSelect:n}=s,{t:a}=st(),r=Bt(ey),i=Bt(ty),l=Bt(sy),d=Bt(ny),c=Bt(ay),h=Bt(ry),m=Bt(iy),p=Bt(oy),u=Bt(ly),w=Bt(cy),g=Bt(dy),f=Bt(uy),x=Bt(my),D=Bt(py);let P,I;e[0]!==D?(P=()=>{D()},I=[D],e[0]=D,e[1]=P,e[2]=I):(P=e[1],I=e[2]),o.useEffect(P,I);const L=gy;let N;e[3]!==u?(N=ge=>{u(ge),L({usageAutoRefresh:ge})},e[3]=u,e[4]=N):N=e[4];const b=N;let j;e[5]!==w?(j=ge=>{const Fe=Number(ge);Number.isFinite(Fe)&&(w(Fe),L({usageRefreshIntervalMs:Fe}))},e[5]=w,e[6]=j):j=e[6];const T=j;let U;e[7]!==g?(U=ge=>{ge!=="usage"&&ge!=="remaining"||(g(ge),L({usageDisplayMode:ge}))},e[7]=g,e[8]=U):U=e[8];const K=U;let M;e[9]!==x?(M=ge=>{x(ge),L({usageShowPredValues:ge})},e[9]=x,e[10]=M):M=e[10];const C=M;let A;e[11]===Symbol.for("react.memo_cache_sentinel")?(A=ce("flex h-full flex-col","bg-background"),e[11]=A):A=e[11];let z;e[12]!==a?(z=a("settings.usage.sidebar.title"),e[12]=a,e[13]=z):z=e[13];let R;e[14]!==z?(R=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:z}),e[14]=z,e[15]=R):R=e[15];let Q;e[16]!==a?(Q=a("settings.usage.sidebar.total",{count:jn.length}),e[16]=a,e[17]=Q):Q=e[17];let W;e[18]!==Q?(W=t.jsx("span",{className:"typography-meta text-muted-foreground",children:Q}),e[18]=Q,e[19]=W):W=e[19];let te;e[20]!==a?(te=a("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[20]=a,e[21]=te):te=e[21];let Y;e[22]!==b||e[23]!==te||e[24]!==h?(Y=t.jsx(Ct,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:t.jsx(yt,{checked:h,onChange:b,ariaLabel:te})})}),e[22]=b,e[23]=te,e[24]=h,e[25]=Y):Y=e[25];let k;e[26]!==a?(k=a("settings.usage.sidebar.tooltip.autoRefresh"),e[26]=a,e[27]=k):k=e[27];let $;e[28]!==k?($=t.jsx(It,{side:"bottom",children:k}),e[28]=k,e[29]=$):$=e[29];let B;e[30]!==Y||e[31]!==$?(B=t.jsxs(St,{children:[Y,$]}),e[30]=Y,e[31]=$,e[32]=B):B=e[32];const F=String(m),O=!h;let J;e[33]!==a?(J=a("settings.usage.sidebar.field.intervalPlaceholder"),e[33]=a,e[34]=J):J=e[34];let H;e[35]!==J?(H=t.jsx(Dt,{className:"w-fit",children:t.jsx(Ot,{placeholder:J})}),e[35]=J,e[36]=H):H=e[36];let re;e[37]===Symbol.for("react.memo_cache_sentinel")?(re=t.jsxs(Et,{children:[t.jsx(mt,{value:"30000",children:"30s"}),t.jsx(mt,{value:"60000",children:"1m"}),t.jsx(mt,{value:"300000",children:"5m"})]}),e[37]=re):re=e[37];let le;e[38]!==T||e[39]!==F||e[40]!==O||e[41]!==H?(le=t.jsxs(At,{value:F,onValueChange:T,disabled:O,children:[H,re]}),e[38]=T,e[39]=F,e[40]=O,e[41]=H,e[42]=le):le=e[42];let ne;e[43]!==d?(ne=()=>d(),e[43]=d,e[44]=ne):ne=e[44];let be;e[45]!==a?(be=a("settings.usage.sidebar.actions.refreshAria"),e[45]=a,e[46]=be):be=e[46];let ae;e[47]!==a?(ae=a("settings.usage.sidebar.actions.refreshTitle"),e[47]=a,e[48]=ae):ae=e[48];const ye=c&&"animate-spin";let ke;e[49]!==ye?(ke=ce("h-3.5 w-3.5",ye),e[49]=ye,e[50]=ke):ke=e[50];let he;e[51]!==ke?(he=t.jsx(E,{name:"refresh",className:ke}),e[51]=ke,e[52]=he):he=e[52];let we;e[53]!==c||e[54]!==ne||e[55]!==be||e[56]!==ae||e[57]!==he?(we=t.jsx(q,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ne,"aria-label":be,title:ae,disabled:c,children:he}),e[53]=c,e[54]=ne,e[55]=be,e[56]=ae,e[57]=he,e[58]=we):we=e[58];let de;e[59]!==B||e[60]!==le||e[61]!==we?(de=t.jsxs("div",{className:"flex items-center gap-2",children:[B,le,we]}),e[59]=B,e[60]=le,e[61]=we,e[62]=de):de=e[62];let Z;e[63]!==W||e[64]!==de?(Z=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[W,de]}),e[63]=W,e[64]=de,e[65]=Z):Z=e[65];let se;e[66]!==a?(se=a("settings.usage.sidebar.field.display"),e[66]=a,e[67]=se):se=e[67];let ve;e[68]!==se?(ve=t.jsx("span",{className:"typography-micro text-muted-foreground",children:se}),e[68]=se,e[69]=ve):ve=e[69];let G;e[70]!==a?(G=a("settings.usage.sidebar.field.displayModePlaceholder"),e[70]=a,e[71]=G):G=e[71];let ee;e[72]!==G?(ee=t.jsx(Dt,{className:"w-fit",children:t.jsx(Ot,{placeholder:G})}),e[72]=G,e[73]=ee):ee=e[73];let ie;e[74]!==a?(ie=a("settings.usage.sidebar.field.displayModeUsage"),e[74]=a,e[75]=ie):ie=e[75];let pe;e[76]!==ie?(pe=t.jsx(mt,{value:"usage",children:ie}),e[76]=ie,e[77]=pe):pe=e[77];let Ae;e[78]!==a?(Ae=a("settings.usage.sidebar.field.displayModeRemaining"),e[78]=a,e[79]=Ae):Ae=e[79];let Se;e[80]!==Ae?(Se=t.jsx(mt,{value:"remaining",children:Ae}),e[80]=Ae,e[81]=Se):Se=e[81];let De;e[82]!==pe||e[83]!==Se?(De=t.jsxs(Et,{children:[pe,Se]}),e[82]=pe,e[83]=Se,e[84]=De):De=e[84];let Me;e[85]!==K||e[86]!==ee||e[87]!==De||e[88]!==p?(Me=t.jsxs(At,{value:p,onValueChange:K,children:[ee,De]}),e[85]=K,e[86]=ee,e[87]=De,e[88]=p,e[89]=Me):Me=e[89];let Te;e[90]!==ve||e[91]!==Me?(Te=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ve,Me]}),e[90]=ve,e[91]=Me,e[92]=Te):Te=e[92];let Be;e[93]!==a?(Be=a("settings.usage.sidebar.field.showPredictions"),e[93]=a,e[94]=Be):Be=e[94];let ze;e[95]!==Be?(ze=t.jsx("span",{className:"typography-micro text-muted-foreground",children:Be}),e[95]=Be,e[96]=ze):ze=e[96];let Oe;e[97]!==a?(Oe=a("settings.usage.sidebar.field.showPredictions"),e[97]=a,e[98]=Oe):Oe=e[98];let $e;e[99]!==C||e[100]!==f||e[101]!==Oe?($e=t.jsx(yt,{checked:f,onChange:C,ariaLabel:Oe}),e[99]=C,e[100]=f,e[101]=Oe,e[102]=$e):$e=e[102];let Ke;e[103]!==ze||e[104]!==$e?(Ke=t.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ze,$e]}),e[103]=ze,e[104]=$e,e[105]=Ke):Ke=e[105];let Ye;e[106]!==Z||e[107]!==Te||e[108]!==Ke||e[109]!==R?(Ye=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[R,Z,Te,Ke]}),e[106]=Z,e[107]=Te,e[108]=Ke,e[109]=R,e[110]=Ye):Ye=e[110];let Re;e[111]!==n||e[112]!==r||e[113]!==i||e[114]!==l||e[115]!==a?(Re=jn.map(ge=>{const Fe=r.find(Pe=>Pe.providerId===ge.id),Ne=Xx(Fe?.usage),He=mc(Ne),X=ge.id===i,v=Fe?.configured??!1,je=v?He==="critical"?{backgroundColor:"var(--status-error)"}:He==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return t.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",X?"bg-interactive-selection":"hover:bg-interactive-hover"),children:t.jsxs("button",{type:"button",onClick:()=>{l(ge.id),n?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:je}),t.jsx(Yn,{providerId:ge.id,className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:ge.name}),!v&&t.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:a("settings.usage.sidebar.status.notSet")})]})},ge.id)}),e[111]=n,e[112]=r,e[113]=i,e[114]=l,e[115]=a,e[116]=Re):Re=e[116];let V;e[117]!==Re?(V=t.jsx(_t,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:Re}),e[117]=Re,e[118]=V):V=e[118];let oe;return e[119]!==Ye||e[120]!==V?(oe=t.jsxs("div",{className:A,children:[Ye,V]}),e[119]=Ye,e[120]=V,e[121]=oe):oe=e[121],oe};function ey(s){return s.results}function ty(s){return s.selectedProviderId}function sy(s){return s.setSelectedProvider}function ny(s){return s.fetchAllQuotas}function ay(s){return s.isLoading}function ry(s){return s.autoRefresh}function iy(s){return s.refreshIntervalMs}function oy(s){return s.displayMode}function ly(s){return s.setAutoRefresh}function cy(s){return s.setRefreshInterval}function dy(s){return s.setDisplayMode}function uy(s){return s.showPredValues}function my(s){return s.setShowPredValues}function py(s){return s.loadSettings}async function gy(s){try{await Nt(s)}catch(e){console.warn("Failed to save usage settings:",e)}}const hy=s=>{const e=et.c(20),{percent:n,tonePercent:a,className:r,expectedMarkerPercent:i}=s;let l;e[0]!==n?(l=Hu(n)??0,e[0]=n,e[1]=l):l=e[1];const d=l,c=a??n;let h;e[2]!==c?(h=mc(c),e[2]=c,e[3]=h):h=e[3];const m=h,p=i!=null?Math.max(0,Math.min(100,i)):null;let u;e[4]!==m?(u=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=u):u=e[5];const w=u;let g;e[6]!==r?(g=ce("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",r),e[6]=r,e[7]=g):g=e[7];const f=`${d}%`;let x;e[8]!==w||e[9]!==f?(x={...w,width:f},e[8]=w,e[9]=f,e[10]=x):x=e[10];let D;e[11]!==d||e[12]!==x?(D=t.jsx("div",{className:"h-full transition-all duration-300",style:x,role:"progressbar","aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100}),e[11]=d,e[12]=x,e[13]=D):D=e[13];let P;e[14]!==p?(P=p!=null&&p>0&&p<100&&t.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${p}%`},title:`Expected usage if spread evenly: ${Math.round(p)}% of quota`,"aria-hidden":"true"}),e[14]=p,e[15]=P):P=e[15];let I;return e[16]!==g||e[17]!==D||e[18]!==P?(I=t.jsxs("div",{className:g,children:[D,P]}),e[16]=g,e[17]=D,e[18]=P,e[19]=I):I=e[19],I},fy=s=>{const e=et.c(67),{paceInfo:n,className:a,compact:r}=s,i=r===void 0?!1:r,{t:l}=st();let d;e[0]!==n.status?(d=Wu(n.status),e[0]=n.status,e[1]=d):d=e[1];const c=d;let h;e:{switch(n.status){case"on-track":{let j;e[2]!==l?(j=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=j):j=e[3],h=j;break e}case"slightly-fast":{let j;e[4]!==l?(j=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=j):j=e[5],h=j;break e}case"too-fast":{let j;e[6]!==l?(j=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=j):j=e[7],h=j;break e}case"exhausted":{let j;e[8]!==l?(j=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=j):j=e[9],h=j;break e}}h=void 0}const m=h;let p;e[10]!==n.predictText||e[11]!==l?(p=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=p):p=e[12];const u=p;if(i){let j;e[13]!==a?(j=ce("flex items-center gap-1.5",a),e[13]=a,e[14]=j):j=e[14];let T;e[15]!==c?(T={backgroundColor:c},e[15]=c,e[16]=T):T=e[16];let U;e[17]!==m||e[18]!==T?(U=t.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:T,title:m}),e[17]=m,e[18]=T,e[19]=U):U=e[19];let K;e[20]!==c?(K={color:c},e[20]=c,e[21]=K):K=e[21];const M=n.isExhausted?void 0:u;let C;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(C=n.isExhausted?t.jsx(t.Fragment,{children:l("settings.usage.pace.wait",{duration:Ji(n.remainingSeconds)})}):t.jsx(t.Fragment,{children:l("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=l,e[26]=C):C=e[26];let A;e[27]!==C||e[28]!==K||e[29]!==M?(A=t.jsx("span",{className:"typography-micro tabular-nums",style:K,title:M,children:C}),e[27]=C,e[28]=K,e[29]=M,e[30]=A):A=e[30];let z;return e[31]!==A||e[32]!==j||e[33]!==U?(z=t.jsxs("div",{className:j,children:[U,A]}),e[31]=A,e[32]=j,e[33]=U,e[34]=z):z=e[34],z}let w;e[35]!==a?(w=ce("flex items-center justify-between gap-2",a),e[35]=a,e[36]=w):w=e[36];let g;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(g=!n.isExhausted&&t.jsx("span",{className:"typography-micro text-muted-foreground",children:l("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=l,e[40]=g):g=e[40];let f;e[41]!==g?(f=t.jsx("div",{className:"flex items-center gap-1.5",children:g}),e[41]=g,e[42]=f):f=e[42];let x;e[43]!==c?(x={color:c},e[43]=c,e[44]=x):x=e[44];let D;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==u||e[49]!==m||e[50]!==l?(D=n.isExhausted?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"font-medium",children:m}),t.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.waitSeparator")}),t.jsx("span",{className:"font-medium",children:Ji(n.remainingSeconds)})]}):t.jsxs("span",{title:u,children:[t.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.predictionLabel")}),t.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=u,e[49]=m,e[50]=l,e[51]=D):D=e[51];let P;e[52]!==x||e[53]!==D?(P=t.jsx("span",{className:"typography-micro tabular-nums",style:x,children:D}),e[52]=x,e[53]=D,e[54]=P):P=e[54];let I;e[55]!==c?(I={backgroundColor:c},e[55]=c,e[56]=I):I=e[56];let L;e[57]!==m||e[58]!==I?(L=t.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:I,title:m}),e[57]=m,e[58]=I,e[59]=L):L=e[59];let N;e[60]!==P||e[61]!==L?(N=t.jsxs("div",{className:"flex items-center gap-1.5",children:[P,L]}),e[60]=P,e[61]=L,e[62]=N):N=e[62];let b;return e[63]!==N||e[64]!==w||e[65]!==f?(b=t.jsxs("div",{className:w,children:[f,N]}),e[63]=N,e[64]=w,e[65]=f,e[66]=b):b=e[66],b},Hr=s=>{const e=et.c(54),{title:n,window:a,subtitle:r,showToggle:i,toggleEnabled:l,onToggle:d}=s,c=i===void 0?!1:i,h=l===void 0?!1:l,m=Bt(xy),p=Bt(yy),u=Ie(by),w=m==="remaining"?a.remainingPercent:a.usedPercent,g=m==="remaining"?"remaining":"used";let f;e[0]!==w||e[1]!==a.valueLabel?(f=Gu(a.valueLabel,w),e[0]=w,e[1]=a.valueLabel,e[2]=f):f=e[2];const x=f,D=a.resetAfterFormatted??a.resetAtFormatted;let P;e[3]!==D||e[4]!==u||e[5]!==a.resetAt?(P=qu(a.resetAt,D,u),e[3]=D,e[4]=u,e[5]=a.resetAt,e[6]=P):P=e[6];const I=P;let L;e[7]!==n?(L=Ju(n),e[7]=n,e[8]=L):L=e[8];const N=L;let b;e[9]!==n||e[10]!==a.resetAt||e[11]!==a.usedPercent||e[12]!==a.windowSeconds?(b=Qu(a.usedPercent,a.resetAt,a.windowSeconds,n),e[9]=n,e[10]=a.resetAt,e[11]=a.usedPercent,e[12]=a.windowSeconds,e[13]=b):b=e[13];const j=b;let T;e:{if(!j||j.dailyAllocationPercent===null){T=null;break e}const H=Yu(j.elapsedRatio);T=m==="remaining"?100-H:H}const U=T;let K;e[14]!==d||e[15]!==c||e[16]!==h?(K=c&&t.jsx(yt,{checked:h,onChange:H=>d?.(H),ariaLabel:"Show in dropdown"}),e[14]=d,e[15]=c,e[16]=h,e[17]=K):K=e[17];let M;e[18]!==N?(M=t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:N}),e[18]=N,e[19]=M):M=e[19];let C;e[20]!==r?(C=r&&t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:r}),e[20]=r,e[21]=C):C=e[21];let A;e[22]!==M||e[23]!==C?(A=t.jsxs("div",{className:"min-w-0 flex flex-col",children:[M,C]}),e[22]=M,e[23]=C,e[24]=A):A=e[24];let z;e[25]!==A||e[26]!==K?(z=t.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[K,A]}),e[25]=A,e[26]=K,e[27]=z):z=e[27];const R=x==="-"?"":x;let Q;e[28]!==R?(Q=t.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:R}),e[28]=R,e[29]=Q):Q=e[29];let W;e[30]!==z||e[31]!==Q?(W=t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[z,Q]}),e[30]=z,e[31]=Q,e[32]=W):W=e[32];let te;e[33]!==w||e[34]!==U||e[35]!==a.usedPercent?(te=t.jsx(hy,{percent:w,tonePercent:a.usedPercent,expectedMarkerPercent:U,className:"h-1.5"}),e[33]=w,e[34]=U,e[35]=a.usedPercent,e[36]=te):te=e[36];const Y=I?`Resets ${I}`:"";let k;e[37]!==Y?(k=t.jsx("span",{className:"typography-micro text-muted-foreground",children:Y}),e[37]=Y,e[38]=k):k=e[38];let $;e[39]!==g?($=t.jsx("span",{className:"typography-micro text-muted-foreground",children:g}),e[39]=g,e[40]=$):$=e[40];let B;e[41]!==k||e[42]!==$?(B=t.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[k,$]}),e[41]=k,e[42]=$,e[43]=B):B=e[43];let F;e[44]!==te||e[45]!==B?(F=t.jsxs("div",{className:"mt-2.5",children:[te,B]}),e[44]=te,e[45]=B,e[46]=F):F=e[46];let O;e[47]!==j||e[48]!==p?(O=j&&p&&t.jsx("div",{className:"mt-1.5",children:t.jsx(fy,{paceInfo:j})}),e[47]=j,e[48]=p,e[49]=O):O=e[49];let J;return e[50]!==W||e[51]!==F||e[52]!==O?(J=t.jsxs("div",{className:"py-3",children:[W,F,O]}),e[50]=W,e[51]=F,e[52]=O,e[53]=J):J=e[53],J};function xy(s){return s.displayMode}function yy(s){return s.showPredValues}function by(s){return s.timeFormatPreference}const vy=(s,e)=>{if(!s)return"-";try{return pc(s,e,{fallback:"-"})}catch{return"-"}},jy=()=>{const{t:s}=st(),e=Ie(A=>A.timeFormatPreference),n=Bt(A=>A.results),a=Bt(A=>A.selectedProviderId),r=Bt(A=>A.setSelectedProvider),i=Bt(A=>A.loadSettings),l=Bt(A=>A.fetchAllQuotas),d=Bt(A=>A.isLoading),c=Bt(A=>A.lastUpdated),h=Bt(A=>A.error),m=Bt(A=>A.dropdownProviderIds),p=Bt(A=>A.setDropdownProviderIds),u=Bt(A=>A.selectedModels),w=Bt(A=>A.toggleModelSelected),g=Bt(A=>A.applyDefaultSelections);qx(),o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(a||n.length===0)return;const A=n.find(z=>z.configured)?.providerId;r(A??jn[0]?.id??null)},[n,a,r]);const f=n.find(A=>A.providerId===a)??null,D=jn.find(A=>A.id===a)?.name??a??s("settings.usage.sidebar.title"),P=f?.usage,I=a?m.includes(a):!1,L=o.useCallback(A=>{if(!a)return;const z=A?Array.from(new Set([...m,a])):m.filter(R=>R!==a);p(z),Nt({usageDropdownProviders:z})},[m,a,p]),N=o.useMemo(()=>P?.models?Object.entries(P.models).map(([A,z])=>({name:A,windows:z})).filter(A=>Object.keys(A.windows.windows).length>0):[],[P?.models]);o.useEffect(()=>{a&&N.length>0&&g(a,N.map(A=>A.name))},[a,N,g]);const b=o.useMemo(()=>!a||N.length===0?new Map:Hx(N,A=>A.name,a),[N,a]),j=o.useMemo(()=>{if(!a)return[];const A=Vx(a);return _x(A)},[a]),[T,U]=o.useState(()=>({})),K=o.useCallback(A=>{U(z=>({...z,[A]:!z[A]}))},[]),M=o.useCallback(A=>{if(!a)return;w(a,A);const z=u[a]??[],Q=z.includes(A)?z.filter(te=>te!==A):[...z,A],W={...u,[a]:Q};Nt({usageSelectedModels:W})},[a,u,w]),C=a?u[a]??[]:[];return a?t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[t.jsx(Yn,{providerId:a,className:"h-5 w-5 shrink-0"}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:s("settings.usage.page.header.providerUsage",{provider:D})}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:d?t.jsx("span",{className:"animate-pulse",children:s("settings.usage.page.header.refreshing")}):s("settings.usage.page.header.lastUpdated",{time:vy(c,e)})})]})]}),t.jsx("div",{"data-settings-item":"usage.header-menu",className:"mb-8 px-2",children:t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":I,onClick:()=>L(!I),onKeyDown:A=>{(A.key===" "||A.key==="Enter")&&(A.preventDefault(),L(!I))},children:[t.jsx(yt,{checked:I,onChange:L,ariaLabel:s("settings.usage.page.options.showInHeaderAria")}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.usage.page.options.showInHeader")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!f&&t.jsx("div",{className:"mb-8 px-2",children:t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.usage.page.state.noData")})}),h&&t.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[t.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:s("settings.usage.page.state.refreshFailedTitle")}),t.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:h})]}),f&&!f.configured&&t.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[t.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:s("settings.usage.page.state.providerNotConfiguredTitle")}),t.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:s("settings.usage.page.state.providerNotConfiguredDescription")})]}),P?.windows&&Object.keys(P.windows).length>0&&t.jsx("div",{"data-settings-item":"usage.model-quotas",className:"mb-8",children:t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(P.windows).map(([A,z])=>t.jsx(Hr,{title:A,window:z},A))})})}),N.length>0&&t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.usage.page.section.modelQuotas")})}),t.jsxs("div",{className:"space-y-3",children:[j.map(A=>{const z=b.get(A.id)??[];if(z.length===0)return null;const R=T[A.id]??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(Mn,{open:!R,onOpenChange:()=>K(A.id),children:[t.jsxs(Tn,{className:"flex w-full items-center justify-between py-0.5 group",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[t.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:A.label}),t.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",z.length,")"]})]}),R?t.jsx(E,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(E,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(Rn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:z.map(Q=>{const W=Object.entries(Q.windows.windows);if(W.length===0)return null;const[te,Y]=W[0],k=C.includes(Q.name);return t.jsx(Hr,{title:te,subtitle:xl(Q.name),window:Y,showToggle:!0,toggleEnabled:k,onToggle:()=>M(Q.name)},Q.name)})})})]})},A.id)}),(()=>{const A=b.get(null)??[];if(A.length===0)return null;const z=T.other??!1;return t.jsx("section",{className:"p-2",children:t.jsxs(Mn,{open:!z,onOpenChange:()=>K("other"),children:[t.jsxs(Tn,{className:"flex w-full items-center justify-between py-0.5 group",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[t.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:s("settings.usage.page.section.otherModels")}),t.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",A.length,")"]})]}),z?t.jsx(E,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):t.jsx(E,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),t.jsx(Rn,{children:t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:A.map(R=>{const Q=Object.entries(R.windows.windows);if(Q.length===0)return null;const[W,te]=Q[0],Y=C.includes(R.name);return t.jsx(Hr,{title:W,subtitle:xl(R.name),window:te,showToggle:!0,toggleEnabled:Y,onToggle:()=>M(R.name)},R.name)})})})]})})})()]})]}),f?.configured&&P&&Object.keys(P.windows??{}).length===0&&N.length===0&&t.jsxs("div",{className:"mb-8 px-2",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.usage.page.state.noQuotaWindowsTitle")}),t.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:s("settings.usage.page.state.noQuotaWindowsDescription")})]})]})}):t.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:t.jsx("p",{className:"typography-body",children:s("settings.usage.page.empty.selectProvider")})})},wy="git.commit.generate",wi=wn(s=>({selectedPromptId:wy,setSelectedPromptId:e=>{s(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),Ny=s=>{const e=et.c(23),{onItemSelect:n}=s,{t:a}=st(),r=wi(ky),i=wi(Sy);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=d):d=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=c):c=e[2];let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h=[l,d,c,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=h):h=e[3];const m=h;let p;e[4]!==a?(p=a("settings.magicPrompts.sidebar.title"),e[4]=a,e[5]=p):p=e[5];let u;e[6]!==p?(u=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:p}),e[6]=p,e[7]=u):u=e[7];let w;e[8]!==a?(w=a("settings.magicPrompts.sidebar.description"),e[8]=a,e[9]=w):w=e[9];let g;e[10]!==w?(g=t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:w}),e[10]=w,e[11]=g):g=e[11];let f;e[12]!==u||e[13]!==g?(f=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[u,g]}),e[12]=u,e[13]=g,e[14]=f):f=e[14];let x;e[15]!==n||e[16]!==r||e[17]!==i||e[18]!==a?(x=t.jsx(_t,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(P=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:a(P.groupKey)}),P.items.map(I=>{const L=r===I.id;return t.jsx("button",{type:"button",onClick:()=>{i(I.id),n?.()},className:ce("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",L?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-ui-label truncate font-normal",children:a(I.titleKey)})},I.id)})]},P.groupKey))}),e[15]=n,e[16]=r,e[17]=i,e[18]=a,e[19]=x):x=e[19];let D;return e[20]!==x||e[21]!==f?(D=t.jsxs("div",{className:"flex h-full flex-col bg-background",children:[f,x]}),e[20]=x,e[21]=f,e[22]=D):D=e[22],D};function ky(s){return s.selectedPromptId}function Sy(s){return s.setSelectedPromptId}const bl={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},vl=(s,e)=>Object.prototype.hasOwnProperty.call(s,e),Wr=s=>s.endsWith(".visible"),Cy=()=>{const{t:s}=st(),e=o.useCallback(b=>s(b),[s]),n=wi(b=>b.selectedPromptId),[a,r]=o.useState(!0),[i,l]=o.useState({}),[d,c]=o.useState({}),[h,m]=o.useState({}),[p,u]=o.useState({}),[w,g]=o.useState(!1);o.useEffect(()=>{let b=!0;return(async()=>{r(!0);try{const T=await tm();if(!b)return;l(T)}catch(T){console.warn("Failed to load magic prompts:",T),_.error(s("settings.magicPrompts.page.toast.loadFailed"))}finally{b&&r(!1)}})(),()=>{b=!1}},[s]);const f=bl[n]??bl["git.commit.generate"],x=o.useCallback(b=>vl(i,b)?i[b]:Sr(b),[i]),D=o.useCallback(b=>d[b]??x(b),[d,x]),P=o.useCallback((b,j)=>{c(T=>T[b]===j?T:{...T,[b]:j})},[]),I=o.useCallback(async b=>{const j=D(b);if(Wr(b)&&j.trim().length===0){_.error(s("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(T=>({...T,[b]:!0}));try{const T=j===Sr(b)?await Qi(b):await Xu(b,j);l(T.overrides),_.success(s("settings.magicPrompts.page.toast.saved"))}catch(T){const U=T instanceof Error?T.message:String(T);_.error(s("settings.magicPrompts.page.toast.saveFailed"),{description:U})}finally{m(T=>({...T,[b]:!1}))}},[D,s]),L=o.useCallback(async b=>{u(j=>({...j,[b]:!0}));try{const j=await Qi(b);l(j.overrides),c(T=>({...T,[b]:Sr(b)})),_.success(s("settings.magicPrompts.page.toast.resetSuccess"))}catch(j){const T=j instanceof Error?j.message:String(j);_.error(s("settings.magicPrompts.page.toast.resetFailed"),{description:T})}finally{u(j=>({...j,[b]:!1}))}},[s]),N=o.useCallback(async()=>{g(!0);try{const b=await Zu();l(b.overrides),c({}),_.success(s("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(b){const j=b instanceof Error?b.message:String(b);_.error(s("settings.magicPrompts.page.toast.resetAllFailed"),{description:j})}finally{g(!1)}},[s]);return a?t.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[t.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":s("settings.magicPrompts.page.loading.aria")}),t.jsx("span",{className:"typography-ui",children:s("settings.magicPrompts.page.loading.text")})]}):t.jsx("div",{className:"h-full overflow-auto",children:t.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[t.jsx("div",{className:"space-y-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(f.titleKey)}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:e(f.descriptionKey)})]})]})}),t.jsx(q,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{N()},disabled:w||Object.keys(i).length===0,children:s(w?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),f.blocks.map((b,j)=>{const T=em(b.id),U=x(b.id),K=D(b.id),M=vl(i,b.id),C=K!==U,A=Wr(b.id)&&K.trim().length===0,z=h[b.id]===!0,R=p[b.id]===!0;return t.jsxs("section",{"data-settings-item":Wr(b.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",className:j>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:e(b.titleKey)}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:T.description})]})]}),T.placeholders&&T.placeholders.length>0&&t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[s("settings.magicPrompts.page.placeholdersLabel")," ",T.placeholders.map(Q=>`{{${Q.key}}}`).join(", ")]})]}),t.jsx(us,{value:K,onChange:Q=>P(b.id,Q.target.value),className:"min-h-[220px] font-mono text-sm"}),A&&t.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:s("settings.magicPrompts.page.validation.visiblePromptRequired")}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s(C?"settings.magicPrompts.page.status.unsavedChanges":M?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(q,{variant:"outline",size:"sm",onClick:()=>{L(b.id)},disabled:!M||z||R,children:s(R?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),t.jsx(q,{size:"sm",onClick:()=>{I(b.id)},disabled:!C||z||R||A,children:s(z?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},b.id)})]})})},Iy=s=>{const e=et.c(89),{onItemSelect:n}=s,{t:a}=st(),[r,i]=o.useState(null),[l,d]=o.useState(null),[c,h]=o.useState(null),{selectedSnippetName:m,snippets:p,setSelectedSnippet:u,setSnippetDraft:w,deleteSnippet:g,loadSnippets:f}=mr(Ps(Py));let x,D;e[0]!==f?(x=()=>{f()},D=[f],e[0]=f,e[1]=x,e[2]=D):(x=e[1],D=e[2]),o.useEffect(x,D);let P;e[3]!==n||e[4]!==u||e[5]!==w||e[6]!==p?(P=async()=>{const Z=new Set(p.map(Ay));let se="new-snippet",ve=1;for(;Z.has(se);)se=`new-snippet-${ve++}`;w({name:se,scope:"global"}),u(se),n?.()},e[3]=n,e[4]=u,e[5]=w,e[6]=p,e[7]=P):P=e[7];const I=P;let L;e[8]!==r||e[9]!==g||e[10]!==a?(L=async()=>{if(!r)return;await g(r.name)?(_.success(a("settings.snippets.sidebar.toast.deleted")),i(null)):_.error(a("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=r,e[9]=g,e[10]=a,e[11]=L):L=e[11];const N=L;let b;e[12]!==p?(b=[...p].sort(Dy),e[12]=p,e[13]=b):b=e[13];const j=b;let T;e[14]===Symbol.for("react.memo_cache_sentinel")?(T=ce("flex h-full flex-col","bg-background"),e[14]=T):T=e[14];let U;e[15]!==a?(U=a("settings.snippets.sidebar.title"),e[15]=a,e[16]=U):U=e[16];let K;e[17]!==U?(K=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:U}),e[17]=U,e[18]=K):K=e[18];let M;e[19]!==p.length||e[20]!==a?(M=a("settings.snippets.sidebar.total",{count:p.length}),e[19]=p.length,e[20]=a,e[21]=M):M=e[21];let C;e[22]!==M?(C=t.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[22]=M,e[23]=C):C=e[23];let A;e[24]!==a?(A=a("settings.snippets.sidebar.actions.create"),e[24]=a,e[25]=A):A=e[25];let z;e[26]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),e[26]=z):z=e[26];let R;e[27]!==I||e[28]!==A?(R=t.jsx(q,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:I,"aria-label":A,children:z}),e[27]=I,e[28]=A,e[29]=R):R=e[29];let Q;e[30]!==C||e[31]!==R?(Q=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[C,R]}),e[30]=C,e[31]=R,e[32]=Q):Q=e[32];let W;e[33]!==Q||e[34]!==K?(W=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[K,Q]}),e[33]=Q,e[34]=K,e[35]=W):W=e[35];let te;if(e[36]!==n||e[37]!==l||e[38]!==c||e[39]!==m||e[40]!==u||e[41]!==j||e[42]!==a){let Z;e[44]!==n||e[45]!==l||e[46]!==c||e[47]!==m||e[48]!==u||e[49]!==a?(Z=se=>t.jsxs(xn,{open:c===se.name,onOpenChange:ve=>h(ve?se.name:null),children:[t.jsxs(yn,{render:t.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m===se.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ve=>{ve.preventDefault(),h(se.name)}}),children:[t.jsxs("button",{onClick:()=>{u(se.name),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",se.name]}),t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:a(`snippets.source.${se.source}`)})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:se.description||se.content.replace(/\s+/g," ").substring(0,80)})]}),t.jsxs(ds,{open:l===se.name,onOpenChange:ve=>{ve&&h(null),d(ve?se.name:null)},children:[t.jsx(ls,{asChild:!0,children:t.jsx(q,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100","aria-label":a("settings.snippets.sidebar.actions.more",{name:se.name}),children:t.jsx(E,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(cs,{align:"end",className:"w-fit min-w-20",children:t.jsxs(Ns,{onClick:ve=>{ve.stopPropagation(),i(se)},className:"text-destructive focus:text-destructive",children:[t.jsx(E,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]})]}),t.jsx(bn,{className:"w-fit min-w-20",children:t.jsxs(sn,{onClick:ve=>{ve.stopPropagation(),i(se)},className:"text-destructive focus:text-destructive",children:[t.jsx(E,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]})})]},`${se.source}:${se.filePath}`),e[44]=n,e[45]=l,e[46]=c,e[47]=m,e[48]=u,e[49]=a,e[50]=Z):Z=e[50],te=j.map(Z),e[36]=n,e[37]=l,e[38]=c,e[39]=m,e[40]=u,e[41]=j,e[42]=a,e[43]=te}else te=e[43];let Y;e[51]!==te?(Y=t.jsx(_t,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:te}),e[51]=te,e[52]=Y):Y=e[52];const k=r!==null;let $;e[53]===Symbol.for("react.memo_cache_sentinel")?($=Z=>{Z||i(null)},e[53]=$):$=e[53];let B;e[54]!==a?(B=a("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=a,e[55]=B):B=e[55];let F;e[56]!==B?(F=t.jsx(zt,{children:B}),e[56]=B,e[57]=F):F=e[57];const O=r?.name??"";let J;e[58]!==a||e[59]!==O?(J=a("settings.snippets.sidebar.dialog.deleteDescription",{name:O}),e[58]=a,e[59]=O,e[60]=J):J=e[60];let H;e[61]!==J?(H=t.jsx($t,{children:J}),e[61]=J,e[62]=H):H=e[62];let re;e[63]!==F||e[64]!==H?(re=t.jsxs(Kt,{children:[F,H]}),e[63]=F,e[64]=H,e[65]=re):re=e[65];let le;e[66]===Symbol.for("react.memo_cache_sentinel")?(le=()=>i(null),e[66]=le):le=e[66];let ne;e[67]!==a?(ne=a("settings.common.actions.cancel"),e[67]=a,e[68]=ne):ne=e[68];let be;e[69]!==ne?(be=t.jsx(q,{size:"sm",variant:"ghost",onClick:le,children:ne}),e[69]=ne,e[70]=be):be=e[70];let ae;e[71]!==a?(ae=a("settings.common.actions.delete"),e[71]=a,e[72]=ae):ae=e[72];let ye;e[73]!==N||e[74]!==ae?(ye=t.jsx(q,{size:"sm",onClick:N,children:ae}),e[73]=N,e[74]=ae,e[75]=ye):ye=e[75];let ke;e[76]!==be||e[77]!==ye?(ke=t.jsxs(Gt,{children:[be,ye]}),e[76]=be,e[77]=ye,e[78]=ke):ke=e[78];let he;e[79]!==re||e[80]!==ke?(he=t.jsxs(Ft,{className:"max-w-md",children:[re,ke]}),e[79]=re,e[80]=ke,e[81]=he):he=e[81];let we;e[82]!==k||e[83]!==he?(we=t.jsx(Rt,{open:k,onOpenChange:$,children:he}),e[82]=k,e[83]=he,e[84]=we):we=e[84];let de;return e[85]!==W||e[86]!==Y||e[87]!==we?(de=t.jsxs("div",{className:T,children:[W,Y,we]}),e[85]=W,e[86]=Y,e[87]=we,e[88]=de):de=e[88],de};function Py(s){return{selectedSnippetName:s.selectedSnippetName,snippets:s.snippets,setSelectedSnippet:s.setSelectedSnippet,setSnippetDraft:s.setSnippetDraft,deleteSnippet:s.deleteSnippet,loadSnippets:s.loadSnippets}}function Ay(s){return s.name}function Dy(s,e){return s.name.localeCompare(e.name)}const Ey=()=>{const{t:s}=st(),{selectedSnippetName:e,snippets:n,snippetDraft:a,setSnippetDraft:r,updateSnippet:i,createSnippet:l}=mr(Ps(T=>({selectedSnippetName:T.selectedSnippetName,snippets:T.snippets,snippetDraft:T.snippetDraft,setSnippetDraft:T.setSnippetDraft,updateSnippet:T.updateSnippet,createSnippet:T.createSnippet}))),d=o.useMemo(()=>e?n.find(T=>T.name===e||T.aliases.includes(e))??null:null,[e,n]),c=!!(a&&a.name===e&&!d),[h,m]=o.useState(""),[p,u]=o.useState("global"),[w,g]=o.useState(""),[f,x]=o.useState(""),[D,P]=o.useState(""),[I,L]=o.useState(!1),N=o.useRef(null);o.useEffect(()=>{if(c&&a){const T={draftName:a.name||"",draftScope:a.scope||"global",description:a.description||"",aliases:(a.aliases||[]).join(", "),content:a.content||""};m(T.draftName),u(T.draftScope),g(T.description),x(T.aliases),P(T.content),N.current=T}else if(d){const T={draftName:"",draftScope:"global",description:d.description??"",aliases:d.aliases.join(", "),content:d.content};g(T.description),x(T.aliases),P(T.content),N.current=T}},[d,c,e,a]);const b=o.useMemo(()=>{const T=N.current;return T?c&&h!==T.draftName||c&&p!==T.draftScope?!0:w!==T.description||f!==T.aliases||D!==T.content:!1},[f,D,w,h,p,c]),j=async()=>{const T=c?h.trim().replace(/\s+/g,"-"):e?.trim();if(!T){_.error(s("settings.snippets.page.toast.nameRequired"));return}if(!D.trim()){_.error(s("settings.snippets.page.toast.contentRequired"));return}const U=f.split(",").map(K=>K.trim()).filter(Boolean);L(!0);try{if(!(c?await l(T,D,{aliases:U,description:w,scope:p}):await i(T,{content:D,aliases:U,description:w}))){_.error(s("settings.snippets.page.toast.saveFailed"));return}_.success(s("settings.snippets.page.toast.saved")),c&&r(null)}finally{L(!1)}};return e?t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsxs("div",{className:"mb-4 min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:c?s("settings.snippets.page.title.new"):`#${e}`}),d?t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:d.filePath}):null]}),t.jsxs("div",{className:"mb-8 space-y-3 px-2",children:[t.jsxs("div",{children:[c?t.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:"#"}),t.jsx(Xe,{value:h,onChange:T=>m(T.target.value),placeholder:s("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),t.jsxs(At,{value:p,onValueChange:T=>u(T),children:[t.jsx(Dt,{className:"w-fit min-w-[100px]",children:t.jsx(Ot,{})}),t.jsxs(Et,{align:"end",children:[t.jsx(mt,{value:"global",children:s("settings.common.scope.global")}),t.jsx(mt,{value:"project",children:s("settings.common.scope.project")})]})]})]}):null,t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx(Xe,{value:w,onChange:T=>g(T.target.value),placeholder:s("settings.snippets.page.field.descriptionPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.snippets.page.field.aliases")}),t.jsx(Xe,{value:f,onChange:T=>x(T.target.value),placeholder:s("settings.snippets.page.field.aliasesPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]})]}),t.jsxs("div",{"data-settings-item":"snippets.content",className:"mb-2 px-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.snippets.page.field.content")}),t.jsx(us,{value:D,onChange:T=>P(T.target.value),placeholder:s("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),t.jsx("p",{className:"mt-2 typography-meta text-muted-foreground",children:s("settings.snippets.page.hint")})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(q,{onClick:j,disabled:I||!b,size:"xs",className:"!font-normal",children:s(I?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(E,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.snippets.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.snippets.page.empty.description")})]})})},Kc=()=>{const{t:s}=st(),e=lt(p=>p.settingsGitmojiEnabled),n=lt(p=>p.setSettingsGitmojiEnabled),a=$m(),r=Ie(p=>p.gitChangesViewMode),i=Ie(p=>p.setGitChangesViewMode),[l,d]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:s("settings.openchamber.git.option.flatList")},{id:"tree",label:s("settings.openchamber.git.option.treeView")}],[s]);o.useEffect(()=>{(async()=>{try{let u=null;if(!u){const w=Vs()?.settings;if(w)try{const f=(await w.load())?.settings;f&&(u={gitmojiEnabled:typeof f.gitmojiEnabled=="boolean"?f.gitmojiEnabled:void 0,gitChangesViewMode:f.gitChangesViewMode==="flat"||f.gitChangesViewMode==="tree"?f.gitChangesViewMode:void 0})}catch{}}if(!u){const w=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});w.ok&&(u=await w.json())}u&&(typeof u.gitmojiEnabled=="boolean"&&n(u.gitmojiEnabled),(u.gitChangesViewMode==="flat"||u.gitChangesViewMode==="tree")&&i(u.gitChangesViewMode))}catch(u){console.warn("Failed to load git settings:",u)}finally{d(!1)}})()},[i,n]);const h=o.useCallback(async p=>{n(p);try{await Nt({gitmojiEnabled:p})}catch(u){console.warn("Failed to save gitmoji setting:",u)}},[n]),m=o.useCallback(p=>{p!==r&&(i(p),Nt({gitChangesViewMode:p}))},[r,i]);return l?null:t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.git.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[t.jsxs("div",{"data-settings-item":"git.changes-view",className:"pt-1 pb-1",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.git.changesViewTitle")}),t.jsx("div",{role:"radiogroup","aria-label":s("settings.openchamber.git.changesViewAria"),className:"mt-0.5 space-y-0",children:c.map(p=>{const u=r===p.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>{m(p.id)},onKeyDown:w=>{(w.key===" "||w.key==="Enter")&&(w.preventDefault(),m(p.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Qs,{checked:u,onChange:()=>{m(p.id)},ariaLabel:s("settings.openchamber.git.optionAria",{option:p.label})}),t.jsx("span",{className:u?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:p.label})]},p.id)})})]}),t.jsxs("div",{"data-settings-item":"git.gitmoji",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{h(!e)},onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),h(!e))},children:[t.jsx(yt,{checked:e,onChange:p=>{h(p)},ariaLabel:s("settings.openchamber.git.enableGitmojiAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.git.enableGitmoji")})]}),t.jsxs("div",{"data-settings-item":"git.gitignored-files",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":a,onClick:()=>Ar(!a),onKeyDown:p=>{(p.key===" "||p.key==="Enter")&&(p.preventDefault(),Ar(!a))},children:[t.jsx(yt,{checked:a,onChange:Ar,ariaLabel:s("settings.openchamber.git.showGitignoredAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.git.showGitignored")})]})]})]})},Uc=()=>{const{t:s}=st(),{isMobile:e}=Ds(),n=Vs()?.github,a=Xs(C=>C.status),r=Xs(C=>C.isLoading),i=Xs(C=>C.hasChecked),l=Xs(C=>C.refreshStatus),d=Xs(C=>C.setStatus),c=o.useCallback(async C=>{await tn(C)},[]),[h,m]=o.useState(!1),[p,u]=o.useState(null),[w,g]=o.useState(null),f=o.useRef(null),x=o.useCallback(()=>{f.current!=null&&(window.clearInterval(f.current),f.current=null),g(null)},[]);o.useEffect(()=>((async()=>{try{i||await l(n)}catch(C){console.warn("Failed to load GitHub auth status:",C)}})(),()=>{x()}),[i,l,n,x]);const D=o.useCallback(async()=>{m(!0);try{const C=n?await n.authStart():await(async()=>{const z=await ct("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),R=await z.json().catch(()=>null);if(!z.ok||!R||!("deviceCode"in R))throw new Error(R?.error||z.statusText);return R})();u(C),g(Math.max(1,C.interval)*1e3);const A=C.verificationUriComplete||C.verificationUri;c(A)}catch(C){console.error("Failed to start GitHub connect:",C),_.error(s("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[c,n,s]),P=o.useCallback(async C=>{if(n)return n.authComplete(C);const A=await ct("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:C})}),z=await A.json().catch(()=>null);if(!A.ok||!z)throw new Error(z?.error||A.statusText);return z},[n]);o.useEffect(()=>{if(!(!p?.deviceCode||!w)&&f.current==null)return f.current=window.setInterval(()=>{(async()=>{try{const C=await P(p.deviceCode);if(C.connected){_.success(s("settings.github.page.toast.connected")),u(null),x(),await l(n,{force:!0});return}C.status==="slow_down"&&g(A=>A?A+5e3:5e3),(C.status==="expired_token"||C.status==="access_denied")&&(_.error(C.error||s("settings.github.page.toast.authorizationFailed")),u(null),x())}catch(C){console.warn("GitHub polling failed:",C)}})()},w),()=>{f.current!=null&&(window.clearInterval(f.current),f.current=null)}},[p,w,P,l,n,x,s]);const I=o.useCallback(async C=>{m(!0);try{if(n)await n.authSetGhCliDisabled(C);else{const A=await ct("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:C})}),z=await A.json().catch(()=>null);if(!A.ok)throw new Error(z?.error||A.statusText)}_.success(s(C?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await l(n,{force:!0})}catch(A){console.error("Failed to update gh CLI setting:",A),_.error(s("settings.github.page.toast.ghCliUpdateFailed"))}finally{m(!1)}},[l,n,s]),L=o.useCallback(async()=>{m(!0);try{if(x(),u(null),n)await n.authDisconnect();else{const C=await ct("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!C.ok)throw new Error(C.statusText)}_.success(s("settings.github.page.toast.disconnected")),await l(n,{force:!0})}catch(C){console.error("Failed to disconnect GitHub:",C),_.error(s("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[l,n,x,s]),N=o.useCallback(async C=>{if(C){m(!0);try{const A=n?await n.authActivate(C):await(async()=>{const z=await ct("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:C})}),R=await z.json().catch(()=>null);if(!z.ok||!R)throw new Error(R?.error||z.statusText);return R})();d(A),_.success(s("settings.github.page.toast.accountSwitched"))}catch(A){console.error("Failed to switch GitHub account:",A),_.error(s("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,d,s]);if(r)return null;const b=!!a?.connected,j=a?.user,U=(a?.accounts??[]).filter(C=>!C.current),K=a?.ghCli??null,M=K?.active?s("settings.github.page.accountSource.cli"):s("settings.github.page.accountSource.oauth");return t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.github.page.oauth.title")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.github.page.tooltip.connectAccount")})]})]})}),t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[b?t.jsxs("div",{className:ce("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:ce("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[j?.avatarUrl?t.jsx("img",{src:j.avatarUrl,alt:j.login?s("settings.github.page.avatarAlt.withLogin",{login:j.login}):s("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:j?.name?.trim()||j?.login||"GitHub"}),t.jsxs("div",{className:ce("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[t.jsx(E,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"font-mono",children:j?.login||s("settings.github.page.label.unknownUser")}),j?.email&&t.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&t.jsx("span",{children:j.email}),t.jsx("span",{className:"opacity-50",children:"•"}),t.jsx("span",{children:M})]}),a?.scope&&t.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:s("settings.github.page.label.scopes",{value:a.scope})}),K?.active&&t.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:s("settings.github.page.ghCli.activeDescription")})]})]}),K?.active?t.jsx(q,{size:"sm",variant:"outline",onClick:()=>I(!0),disabled:h,className:ce(e?"w-full":void 0),children:s("settings.github.page.ghCli.actions.disable")}):t.jsx(q,{size:"sm",variant:"outline",onClick:L,disabled:h,className:ce("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:s("settings.github.page.actions.disconnect")})]}):t.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[t.jsx("div",{className:"flex min-w-0 flex-col",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.github.page.status.notConnected")})}),t.jsx(q,{size:"sm",variant:"default",onClick:D,disabled:h,children:s("settings.github.page.actions.connect")})]}),U.length>0&&t.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[t.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:s("settings.github.page.label.otherAccounts")}),t.jsx("div",{className:"space-y-1",children:U.map(C=>{const A=C.user,z=C.source==="gh-cli"?s("settings.github.page.accountSource.cli"):s("settings.github.page.accountSource.oauth");return t.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[A?.avatarUrl?t.jsx("img",{src:A.avatarUrl,alt:A.login?s("settings.github.page.avatarAlt.withLogin",{login:A.login}):s("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:t.jsx(E,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),t.jsxs("div",{className:"min-w-0 flex flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:A?.name?.trim()||A?.login||"GitHub"}),A?.login&&t.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[t.jsx("span",{className:"font-mono",children:A.login}),t.jsx("span",{className:"mx-1 opacity-50",children:"·"}),t.jsx("span",{children:z})]})]})]}),t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>N(C.id),disabled:h,children:s("settings.github.page.actions.switchTo")})]},C.id)})})]})]}),b&&t.jsx("div",{className:"mt-2 px-2 pb-2",children:t.jsx(q,{size:"sm",variant:"outline",onClick:D,disabled:h,className:ce(e?"w-full":void 0),children:s("settings.github.page.actions.addAccount")})}),p&&t.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("h4",{className:"typography-ui-label text-foreground",children:s("settings.github.page.flow.title")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.github.page.flow.description")})]}),t.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[t.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:p.userCode}),t.jsx(q,{size:"sm",asChild:!0,children:t.jsx("a",{href:p.verificationUriComplete||p.verificationUri,target:"_blank",rel:"noopener noreferrer",children:s("settings.github.page.actions.openGithub")})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[t.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:s("settings.github.page.flow.waiting")}),t.jsx(q,{size:"sm",variant:"ghost",disabled:h,onClick:()=>{x(),u(null)},children:s("settings.common.actions.cancel")})]})]}),K?.available&&!K?.active&&(!K.user||K.disabled)&&t.jsxs("div",{className:"mt-6",children:[t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground mb-3 px-1",children:s("settings.github.page.ghCli.title")}),t.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:t.jsxs("div",{className:ce("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[t.jsxs("div",{className:ce("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[K.user?.avatarUrl?t.jsx("img",{src:K.user.avatarUrl,alt:K.user.login?s("settings.github.page.avatarAlt.withLogin",{login:K.user.login}):s("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:t.jsx(E,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[!K.disabled&&K.user&&t.jsx("div",{className:"typography-ui-label text-foreground truncate",children:K.user.name?.trim()||K.user.login||"GitHub"}),!K.disabled&&K.user?.login&&t.jsxs("div",{className:ce("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[t.jsx(E,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"font-mono",children:K.user.login}),K.user.email&&t.jsx("span",{className:"opacity-50",children:"•"}),K.user.email&&t.jsx("span",{children:K.user.email})]}),t.jsx("div",{className:ce("typography-meta text-muted-foreground",K.disabled?"opacity-60":void 0),children:K.disabled?s("settings.github.page.ghCli.disabledDescription"):s("settings.github.page.ghCli.fallbackDescription")})]})]}),t.jsx(q,{size:"sm",variant:"outline",onClick:()=>I(!K.disabled),disabled:h,className:ce(e?"w-full":void 0),children:K.disabled?s("settings.github.page.ghCli.actions.enable"):s("settings.github.page.ghCli.actions.disable")})]})})]})]})},jl=[{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)"}],My=[{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"}],Ty=({open:s,onOpenChange:e,profileId:n,importData:a})=>{const{t:r}=st(),i=Is(H=>H.getProfileById),l=Is(H=>H.createProfile),d=Is(H=>H.updateProfile),c=Is(H=>H.deleteProfile),h=o.useMemo(()=>n&&n!=="new"&&!a?i(n):null,[n,i,a]),m=n==="new"||a!=null,p=n==="global",[u,w]=o.useState(""),[g,f]=o.useState(""),[x,D]=o.useState(""),[P,I]=o.useState("ssh"),[L,N]=o.useState(""),[b,j]=o.useState(!1),[T,U]=o.useState(""),[K,M]=o.useState(""),[C,A]=o.useState("keyword"),[z,R]=o.useState("branch"),[Q,W]=o.useState(!1),[te,Y]=o.useState(!1),[k,$]=o.useState(!1);o.useEffect(()=>{if(s){if(a){const H=a.host.split("/"),re=H.length>=3?H[H.length-1]:a.host;w(re),f(a.username),D(""),I("token"),N(""),j(!1),U(""),M(a.host),A("string"),R("code")}else if(m)w(""),f(""),D(""),I("ssh"),N(""),j(!1),U(""),M(""),A("keyword"),R("branch");else if(h)w(h.name),f(h.userName),D(h.userEmail),I(h.authType||"ssh"),N(h.sshKey||""),j(h.signCommits===!0),U(h.signingKey||""),M(h.host||""),A(h.color||"keyword"),R(h.icon||"branch");else if(p){const H=i("global");H&&(w(H.name),f(H.userName),D(H.userEmail),I(H.authType||"ssh"),N(H.sshKey||""),j(!1),U(""),M(H.host||""),A(H.color||"keyword"),R(H.icon||"branch"))}}},[s,n,h,m,a,p,i]);const B=async()=>{if(!g.trim()||!x.trim()){_.error(r("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(P==="token"&&!K.trim()){_.error(r("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(b&&!T.trim()){_.error(r("settings.gitIdentities.editor.toast.signingKeyRequired"));return}W(!0);try{const H={name:u.trim()||g.trim(),userName:g.trim(),userEmail:x.trim(),authType:P,sshKey:P==="ssh"&&L.trim()||null,signCommits:b,signingKey:T.trim()||null,host:P==="token"&&K.trim()||null,color:C,icon:z};let re;if(m)re=await l(H);else if(n)re=await d(n,H);else return;re?(_.success(r(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):_.error(r(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(H){console.error("Error saving profile:",H),_.error(r("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{W(!1)}},F=async()=>{if(!(!n||m)){$(!0);try{await c(n)?(_.success(r("settings.gitIdentities.editor.toast.profileDeleted")),Y(!1),e(!1)):_.error(r("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(H){console.error("Error deleting profile:",H),_.error(r("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{$(!1)}}},O=o.useMemo(()=>jl.find(re=>re.key===C)?.cssVar||"var(--syntax-keyword)",[C]),J=a?r("settings.gitIdentities.editor.title.importCredential"):m?r("settings.gitIdentities.editor.title.newIdentity"):p?r("settings.gitIdentities.editor.title.globalIdentity"):h?.name||r("settings.gitIdentities.editor.title.editIdentity");return t.jsxs(t.Fragment,{children:[t.jsx(Rt,{open:s,onOpenChange:e,children:t.jsxs(Ft,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:J}),t.jsx($t,{children:r(p?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),t.jsxs("div",{className:"space-y-5 py-2",children:[!p&&t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"typography-ui-label text-foreground block mb-1.5",children:r("settings.gitIdentities.editor.field.profileName")}),t.jsx(Xe,{value:u,onChange:H=>w(H.target.value),placeholder:r("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.color")}),t.jsx("div",{className:"flex gap-1.5",children:jl.map(H=>t.jsx("button",{type:"button",onClick:()=>A(H.key),className:ce("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",C===H.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:H.cssVar},title:H.label},H.key))})]}),t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.icon")}),t.jsx("div",{className:"flex gap-1.5",children:My.map(H=>{const re=H.Icon;return t.jsx("button",{type:"button",onClick:()=>R(H.key),className:ce("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",z===H.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:H.label,children:t.jsx(E,{name:re,className:"w-3.5 h-3.5",style:{color:z===H.key?O:"var(--surface-muted-foreground)"}})},H.key)})})]})]}),!p&&t.jsx("div",{className:"border-t border-border/40"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.userName")}),!p&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),t.jsx(Xe,{value:g,onChange:H=>f(H.target.value),placeholder:r("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!p,readOnly:p,disabled:p,className:"h-8"})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.emailAddress")}),!p&&t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),t.jsx(Xe,{type:"email",value:x,onChange:H=>D(H.target.value),placeholder:r("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!p,readOnly:p,disabled:p,className:"h-8"})]})]}),!p&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"border-t border-border/40"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.authMethod")}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsxs(q,{size:"sm",type:"button",variant:"chip","aria-pressed":P==="ssh",onClick:()=>I("ssh"),children:[t.jsx(E,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),t.jsxs(q,{size:"sm",type:"button",variant:"chip","aria-pressed":P==="token",onClick:()=>I("token"),children:[t.jsx(E,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.gitIdentities.editor.field.authToken")]})]})]}),P==="ssh"&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.sshKeyPath")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),t.jsx(Xe,{value:L,onChange:H=>N(H.target.value),placeholder:r("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),t.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(yt,{checked:b,onChange:j,ariaLabel:r("settings.gitIdentities.editor.field.signCommits")}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.signCommits")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:r("settings.gitIdentities.editor.section.commitSigning")})]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.signingKey")})}),t.jsx(Xe,{value:T,onChange:H=>U(H.target.value),placeholder:r("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!b,className:"h-8 font-mono text-xs"})]})]}),P==="token"&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",children:r("settings.gitIdentities.editor.field.host")}),t.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:r("settings.gitIdentities.editor.field.hostTooltip")})]})]}),t.jsx(Xe,{value:K,onChange:H=>M(H.target.value),placeholder:r("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),t.jsxs(Gt,{className:"gap-2",children:[!p&&!m&&t.jsxs(q,{variant:"outline",size:"sm",onClick:()=>Y(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[t.jsx(E,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",r("settings.common.actions.delete")]}),t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:r(p?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!p&&t.jsx(q,{size:"sm",onClick:B,disabled:Q,children:r(Q?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),t.jsx(Rt,{open:te,onOpenChange:H=>{k||Y(H)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:r("settings.gitIdentities.page.deleteDialog.title")}),t.jsx($t,{children:r("settings.gitIdentities.page.deleteDialog.description",{name:h?.name||u})})]}),t.jsxs(Gt,{children:[t.jsx(q,{variant:"ghost",onClick:()=>Y(!1),disabled:k,children:r("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",variant:"destructive",onClick:()=>{F()},disabled:k,children:r("settings.common.actions.delete")})]})]})})]})},Ry={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},Fy={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},Ly=()=>{const s=et.c(118),{t:e}=st(),{profiles:n,globalIdentity:a,defaultGitIdentityId:r,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:d,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:h,setDefaultGitIdentityId:m,getUnimportedCredentials:p}=Is(Ps(zy)),[u,w]=o.useState(!1),[g,f]=o.useState(null),[x,D]=o.useState(null),[P,I]=o.useState(null),[L,N]=o.useState(!1);let b,j;s[0]!==h||s[1]!==c||s[2]!==d||s[3]!==l?(b=()=>{l(),d(),c(),h()},j=[l,d,c,h],s[0]=h,s[1]=c,s[2]=d,s[3]=l,s[4]=b,s[5]=j):(b=s[4],j=s[5]),o.useEffect(b,j);let T,U,K,M,C,A,z,R,Q,W,te,Y,k,$;if(s[6]!==r||s[7]!==P||s[8]!==i||s[9]!==p||s[10]!==a||s[11]!==n||s[12]!==m||s[13]!==e){const De=p();let Me;s[28]===Symbol.for("react.memo_cache_sentinel")?(Me=(ge,Fe)=>{f(ge),D(Fe??null),w(!0)},s[28]=Me):Me=s[28];const Te=Me;let Be;s[29]!==r||s[30]!==m||s[31]!==e?(Be=async ge=>{const Fe=r===ge?null:ge;if(!await m(Fe)){_.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}_.success(e(Fe?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},s[29]=r,s[30]=m,s[31]=e,s[32]=Be):Be=s[32];const ze=Be;let Oe;s[33]!==P||s[34]!==i||s[35]!==e?(Oe=async()=>{if(!P)return;N(!0),await i(P.id)?(_.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:P.name})),I(null)):_.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),N(!1)},s[33]=P,s[34]=i,s[35]=e,s[36]=Oe):Oe=s[36],U=Oe,T=_t,C="h-full",A="w-full bg-background",K="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",s[37]===Symbol.for("react.memo_cache_sentinel")?(M=t.jsx("div",{"data-settings-item":"git.github-account",children:t.jsx(Uc,{})}),s[37]=M):M=s[37],Y="git.identities",k="border-t border-border/40 pt-6";let $e;s[38]!==e?($e=e("settings.gitIdentities.page.section.title"),s[38]=e,s[39]=$e):$e=s[39];let Ke;s[40]!==$e?(Ke=t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:$e})}),s[40]=$e,s[41]=Ke):Ke=s[41];let Ye,Re;s[42]===Symbol.for("react.memo_cache_sentinel")?(Ye=()=>Te("new"),Re=t.jsx(E,{name:"add",className:"w-3.5 h-3.5 mr-1"}),s[42]=Ye,s[43]=Re):(Ye=s[42],Re=s[43]);let V;s[44]!==e?(V=e("settings.common.badge.new"),s[44]=e,s[45]=V):V=s[45];let oe;s[46]!==V?(oe=t.jsxs(q,{size:"sm",variant:"outline",onClick:Ye,children:[Re," ",V]}),s[46]=V,s[47]=oe):oe=s[47],s[48]!==Ke||s[49]!==oe?($=t.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[Ke,oe]}),s[48]=Ke,s[49]=oe,s[50]=$):$=s[50],z="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",R=a&&t.jsx(wl,{profile:a,isDefault:r==="global",onEdit:()=>Te("global"),onToggleDefault:()=>ze("global"),isReadOnly:!0,hasBorder:n.length>0||De.length>0}),Q=n.map((ge,Fe)=>t.jsx(wl,{profile:ge,isDefault:r===ge.id,onEdit:()=>Te(ge.id),onToggleDefault:()=>ze(ge.id),onDelete:()=>I(ge),hasBorder:Fe<n.length-1||De.length>0},ge.id)),W=!a&&n.length===0&&De.length===0&&t.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[t.jsx(E,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),t.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),te=De.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:t.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),De.map((ge,Fe)=>t.jsx(Oy,{credential:ge,onImport:()=>Te("new",{host:ge.host,username:ge.username}),hasBorder:Fe<De.length-1},`${ge.host}-${ge.username}`))]}),s[6]=r,s[7]=P,s[8]=i,s[9]=p,s[10]=a,s[11]=n,s[12]=m,s[13]=e,s[14]=T,s[15]=U,s[16]=K,s[17]=M,s[18]=C,s[19]=A,s[20]=z,s[21]=R,s[22]=Q,s[23]=W,s[24]=te,s[25]=Y,s[26]=k,s[27]=$}else T=s[14],U=s[15],K=s[16],M=s[17],C=s[18],A=s[19],z=s[20],R=s[21],Q=s[22],W=s[23],te=s[24],Y=s[25],k=s[26],$=s[27];let B;s[51]!==z||s[52]!==R||s[53]!==Q||s[54]!==W||s[55]!==te?(B=t.jsxs("div",{className:z,children:[R,Q,W,te]}),s[51]=z,s[52]=R,s[53]=Q,s[54]=W,s[55]=te,s[56]=B):B=s[56];let F;s[57]!==B||s[58]!==Y||s[59]!==k||s[60]!==$?(F=t.jsxs("div",{"data-settings-item":Y,className:k,children:[$,B]}),s[57]=B,s[58]=Y,s[59]=k,s[60]=$,s[61]=F):F=s[61];let O;s[62]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx(Kc,{}),s[62]=O):O=s[62];let J;s[63]!==K||s[64]!==M||s[65]!==F?(J=t.jsxs("div",{className:K,children:[M,F,O]}),s[63]=K,s[64]=M,s[65]=F,s[66]=J):J=s[66];let H;s[67]!==T||s[68]!==C||s[69]!==A||s[70]!==J?(H=t.jsx(T,{outerClassName:C,className:A,children:J}),s[67]=T,s[68]=C,s[69]=A,s[70]=J,s[71]=H):H=s[71];let re;s[72]!==x||s[73]!==u||s[74]!==g?(re=t.jsx(Ty,{open:u,onOpenChange:w,profileId:g,importData:x}),s[72]=x,s[73]=u,s[74]=g,s[75]=re):re=s[75];const le=P!==null;let ne;s[76]!==L?(ne=De=>{L||De||I(null)},s[76]=L,s[77]=ne):ne=s[77];let be;s[78]!==e?(be=e("settings.gitIdentities.page.deleteDialog.title"),s[78]=e,s[79]=be):be=s[79];let ae;s[80]!==be?(ae=t.jsx(zt,{children:be}),s[80]=be,s[81]=ae):ae=s[81];const ye=P?.name??"";let ke;s[82]!==e||s[83]!==ye?(ke=e("settings.gitIdentities.page.deleteDialog.description",{name:ye}),s[82]=e,s[83]=ye,s[84]=ke):ke=s[84];let he;s[85]!==ke?(he=t.jsx($t,{children:ke}),s[85]=ke,s[86]=he):he=s[86];let we;s[87]!==ae||s[88]!==he?(we=t.jsxs(Kt,{children:[ae,he]}),s[87]=ae,s[88]=he,s[89]=we):we=s[89];let de;s[90]===Symbol.for("react.memo_cache_sentinel")?(de=()=>I(null),s[90]=de):de=s[90];let Z;s[91]!==e?(Z=e("settings.common.actions.cancel"),s[91]=e,s[92]=Z):Z=s[92];let se;s[93]!==L||s[94]!==Z?(se=t.jsx(q,{variant:"ghost",onClick:de,disabled:L,children:Z}),s[93]=L,s[94]=Z,s[95]=se):se=s[95];let ve;s[96]!==U?(ve=()=>{U()},s[96]=U,s[97]=ve):ve=s[97];let G;s[98]!==e?(G=e("settings.common.actions.delete"),s[98]=e,s[99]=G):G=s[99];let ee;s[100]!==L||s[101]!==ve||s[102]!==G?(ee=t.jsx(q,{size:"sm",variant:"destructive",onClick:ve,disabled:L,children:G}),s[100]=L,s[101]=ve,s[102]=G,s[103]=ee):ee=s[103];let ie;s[104]!==se||s[105]!==ee?(ie=t.jsxs(Gt,{children:[se,ee]}),s[104]=se,s[105]=ee,s[106]=ie):ie=s[106];let pe;s[107]!==we||s[108]!==ie?(pe=t.jsxs(Ft,{className:"max-w-md",children:[we,ie]}),s[107]=we,s[108]=ie,s[109]=pe):pe=s[109];let Ae;s[110]!==le||s[111]!==ne||s[112]!==pe?(Ae=t.jsx(Rt,{open:le,onOpenChange:ne,children:pe}),s[110]=le,s[111]=ne,s[112]=pe,s[113]=Ae):Ae=s[113];let Se;return s[114]!==H||s[115]!==re||s[116]!==Ae?(Se=t.jsxs(t.Fragment,{children:[H,re,Ae]}),s[114]=H,s[115]=re,s[116]=Ae,s[117]=Se):Se=s[117],Se},wl=s=>{const e=et.c(56),{profile:n,isDefault:a,onEdit:r,onToggleDefault:i,onDelete:l,isReadOnly:d,hasBorder:c}=s,{t:h}=st(),[m,p]=o.useState(!1),u=Ry[n.icon||"branch"]||"git-branch",w=Fy[n.color||""],g=n.authType||"ssh";let f;e[0]!==r?(f=F=>{F.currentTarget===F.target&&(F.key!=="Enter"&&F.key!==" "||(F.preventDefault(),r()))},e[0]=r,e[1]=f):f=e[1];const x=f;let D;e[2]!==a||e[3]!==d||e[4]!==l||e[5]!==i||e[6]!==h?(D=F=>t.jsxs(t.Fragment,{children:[t.jsx(F,{onClick:O=>{O.stopPropagation(),i()},children:h(a?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!d&&l&&t.jsxs(F,{onClick:O=>{O.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[t.jsx(E,{name:"delete-bin",className:"h-4 w-4 mr-px"}),h("settings.common.actions.delete")]})]}),e[2]=a,e[3]=d,e[4]=l,e[5]=i,e[6]=h,e[7]=D):D=e[7];const P=D,I=c&&"border-b border-[var(--surface-subtle)]";let L;e[8]!==I?(L=ce("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",I),e[8]=I,e[9]=L):L=e[9];let N;e[10]===Symbol.for("react.memo_cache_sentinel")?(N=F=>{F.preventDefault(),p(!0)},e[10]=N):N=e[10];let b;e[11]!==x||e[12]!==r||e[13]!==L?(b=t.jsx("div",{className:L,onClick:r,role:"button",tabIndex:0,onKeyDown:x,onContextMenu:N}),e[11]=x,e[12]=r,e[13]=L,e[14]=b):b=e[14];let j;e[15]!==w?(j={color:w},e[15]=w,e[16]=j):j=e[16];let T;e[17]!==u||e[18]!==j?(T=t.jsx(E,{name:u,className:"w-4 h-4 shrink-0",style:j}),e[17]=u,e[18]=j,e[19]=T):T=e[19];let U;e[20]!==n.name?(U=t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[20]=n.name,e[21]=U):U=e[21];let K;e[22]!==g?(K=t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:g}),e[22]=g,e[23]=K):K=e[23];let M;e[24]!==a||e[25]!==h?(M=a&&t.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:h("settings.gitIdentities.page.badge.default")}),e[24]=a,e[25]=h,e[26]=M):M=e[26];let C;e[27]!==d||e[28]!==h?(C=d&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:h("settings.agents.sidebar.badge.system")}),e[27]=d,e[28]=h,e[29]=C):C=e[29];let A;e[30]!==K||e[31]!==M||e[32]!==C||e[33]!==U?(A=t.jsxs("div",{className:"flex items-center gap-1.5",children:[U,K,M,C]}),e[30]=K,e[31]=M,e[32]=C,e[33]=U,e[34]=A):A=e[34];const z=g==="token"&&n.host?n.host:n.userEmail;let R;e[35]!==z?(R=t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:z}),e[35]=z,e[36]=R):R=e[36];let Q;e[37]!==A||e[38]!==R?(Q=t.jsxs("div",{className:"min-w-0",children:[A,R]}),e[37]=A,e[38]=R,e[39]=Q):Q=e[39];let W;e[40]!==Q||e[41]!==T?(W=t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[T,Q]}),e[40]=Q,e[41]=T,e[42]=W):W=e[42];let te;e[43]===Symbol.for("react.memo_cache_sentinel")?(te=t.jsx(ls,{asChild:!0,children:t.jsx(q,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:Ky,children:t.jsx(E,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=te):te=e[43];let Y;e[44]!==P?(Y=t.jsxs(ds,{children:[te,t.jsx(cs,{align:"end",className:"w-fit min-w-28",children:P(Ns)})]}),e[44]=P,e[45]=Y):Y=e[45];let k;e[46]!==W||e[47]!==Y||e[48]!==b?(k=t.jsxs(yn,{render:b,children:[W,Y]}),e[46]=W,e[47]=Y,e[48]=b,e[49]=k):k=e[49];let $;e[50]!==P?($=t.jsx(bn,{className:"w-fit min-w-28",children:P(sn)}),e[50]=P,e[51]=$):$=e[51];let B;return e[52]!==m||e[53]!==k||e[54]!==$?(B=t.jsxs(xn,{open:m,onOpenChange:p,children:[k,$]}),e[52]=m,e[53]=k,e[54]=$,e[55]=B):B=e[55],B},Oy=s=>{const e=et.c(21),{credential:n,onImport:a,hasBorder:r}=s,{t:i}=st();let l;e[0]!==n.host?(l=n.host.split("/"),e[0]=n.host,e[1]=l):l=e[1];const d=l,c=d.length>=3?d[d.length-1]:n.host,h=n.host.includes("/"),m=r&&"border-b border-[var(--surface-subtle)]";let p;e[2]!==m?(p=ce("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=p):p=e[3];let u;e[4]!==c?(u=t.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=u):u=e[5];const w=h?n.host:n.username;let g;e[6]!==w?(g=t.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:w}),e[6]=w,e[7]=g):g=e[7];let f;e[8]!==u||e[9]!==g?(f=t.jsxs("div",{className:"min-w-0",children:[u,g]}),e[8]=u,e[9]=g,e[10]=f):f=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx(E,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let D;e[12]!==i?(D=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=D):D=e[13];let P;e[14]!==a||e[15]!==D?(P=t.jsxs(q,{size:"sm",variant:"ghost",onClick:a,className:"gap-1 shrink-0",children:[x,D]}),e[14]=a,e[15]=D,e[16]=P):P=e[16];let I;return e[17]!==P||e[18]!==p||e[19]!==f?(I=t.jsxs("div",{className:p,children:[f,P]}),e[17]=P,e[18]=p,e[19]=f,e[20]=I):I=e[20],I};function zy(s){return{profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,deleteProfile:s.deleteProfile,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDiscoveredCredentials:s.loadDiscoveredCredentials,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId,setDefaultGitIdentityId:s.setDefaultGitIdentityId,getUnimportedCredentials:s.getUnimportedCredentials}}function Ky(s){return s.stopPropagation()}const Bc=()=>{const s=sm();return{displayMode:s,installed:s!=="browser",browserTab:s==="browser"}},Uy=()=>{const s=et.c(2),[e,n]=o.useState(By);let a,r;return s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const i=[window.matchMedia("(display-mode: standalone)"),window.matchMedia("(display-mode: minimal-ui)"),window.matchMedia("(display-mode: fullscreen)"),window.matchMedia("(display-mode: window-controls-overlay)")],l=()=>{n(Bc())};l();for(const d of i)typeof d.addEventListener=="function"?d.addEventListener("change",l):typeof d.addListener=="function"&&d.addListener(l);return window.addEventListener("appinstalled",l),window.addEventListener("focus",l),()=>{for(const d of i)typeof d.removeEventListener=="function"?d.removeEventListener("change",l):typeof d.removeListener=="function"&&d.removeListener(l);window.removeEventListener("appinstalled",l),window.removeEventListener("focus",l)}},r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),o.useEffect(a,r),e};function By(){return Bc()}const $y=[{value:"system",labelKey:"settings.openchamber.visual.option.themeMode.system"},{value:"light",labelKey:"settings.openchamber.visual.option.themeMode.light"},{value:"dark",labelKey:"settings.openchamber.visual.option.themeMode.dark"}],Vy=[{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"}],_y=[{id:"svg",labelKey:"settings.openchamber.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.openchamber.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.ascii.description"}],ga="OpenChamber - AI Coding Assistant",Nl=[{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"}],kl=[{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"}],Hy=[{value:"default",labelKey:"settings.openchamber.visual.option.mobileLayout.default"},{value:"new",labelKey:"settings.openchamber.visual.option.mobileLayout.new"}],Gr=s=>s==="portrait"||s==="landscape"?s:"system",Wy=[{id:"markdown",labelKey:"settings.openchamber.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.openchamber.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.plain.description"}],Gy=[{id:"sorted",labelKey:"settings.openchamber.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.openchamber.visual.option.chatRenderMode.live.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.live.description"}],Sl=[{id:"auto",labelKey:"settings.openchamber.visual.option.messageTransport.auto.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.openchamber.visual.option.messageTransport.ws.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.openchamber.visual.option.messageTransport.sse.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.sse.description"}],qy=[{id:"collapsed",labelKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.openchamber.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.summary.description"}],Cl=[{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"}],Il=[{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"}],Jy=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Qy=s=>s==="markdown"?"markdown":"plain",Ri=({visibleSettings:s})=>{const{locale:e,locales:n,setLocale:a,label:r,t:i}=st(),l=o.useCallback(y=>i(y),[i]),{isMobile:d}=Ds(),{browserTab:c}=Uy(),h=Vm(),m=Ie(y=>y.showReasoningTraces),p=Ie(y=>y.sessionRecapEnabled),u=Ie(y=>y.sessionSuggestionEnabled),w=Ie(y=>y.setSessionRecapEnabled),g=Ie(y=>y.setSessionSuggestionEnabled),f=Ie(y=>y.sessionGoalEnabled),x=Ie(y=>y.setSessionGoalEnabled),D=Ie(y=>y.sessionGoalDefaultBudgetEnabled),P=Ie(y=>y.setSessionGoalDefaultBudgetEnabled),I=Ie(y=>y.sessionGoalDefaultBudget),L=Ie(y=>y.setSessionGoalDefaultBudget),N=Ie(y=>y.setShowReasoningTraces),b=Ie(y=>y.collapsibleThinkingBlocks),j=Ie(y=>y.setCollapsibleThinkingBlocks),T=Ie(y=>y.mermaidRenderingMode),U=Ie(y=>y.setMermaidRenderingMode),K=Ie(y=>y.userMessageRenderingMode),M=Ie(y=>y.setUserMessageRenderingMode),C=Ie(y=>y.collapsibleUserMessages),A=Ie(y=>y.setCollapsibleUserMessages),z=Ie(y=>y.stickyUserHeader),R=Ie(y=>y.setStickyUserHeader),Q=Ie(y=>y.expandedEditorToolbar),W=Ie(y=>y.setExpandedEditorToolbar),te=Ie(y=>y.wideChatLayoutEnabled),Y=Ie(y=>y.setWideChatLayoutEnabled),k=Ie(y=>y.codeBlockLineWrap),$=Ie(y=>y.setCodeBlockLineWrap),B=Ie(y=>y.chatRenderMode),F=Ie(y=>y.setChatRenderMode),O=Ie(y=>y.activityRenderMode),J=Ie(y=>y.setActivityRenderMode),H=Ie(y=>y.fontSize),re=Ie(y=>y.setFontSize),le=Ie(y=>y.terminalFontSize),ne=Ie(y=>y.setTerminalFontSize),be=Ie(y=>y.editorFontSize),ae=Ie(y=>y.setEditorFontSize),ye=Ie(y=>y.uiFont),ke=Ie(y=>y.setUiFont),he=Ie(y=>y.monoFont),we=Ie(y=>y.setMonoFont),de=Ie(y=>y.padding),Z=Ie(y=>y.setPadding),se=Ie(y=>y.inputBarOffset),ve=Ie(y=>y.setInputBarOffset),G=Ie(y=>y.mobileKeyboardMode),ee=Ie(y=>y.setMobileKeyboardMode),ie=Ie(y=>y.diffLayoutPreference),pe=Ie(y=>y.setDiffLayoutPreference),Ae=Ie(y=>y.showTerminalQuickKeysOnDesktop),Se=Ie(y=>y.setShowTerminalQuickKeysOnDesktop),De=Ie(y=>y.fileEditorKeymap),Me=Ie(y=>y.setFileEditorKeymap),Te=oo(y=>y.followUpBehavior),Be=oo(y=>y.setFollowUpBehavior),ze=Ie(y=>y.persistChatDraft),Oe=Ie(y=>y.setPersistChatDraft),$e=Ie(y=>y.inputSpellcheckEnabled),Ke=Ie(y=>y.setInputSpellcheckEnabled),Ye=Ie(y=>y.showToolFileIcons),Re=Ie(y=>y.setShowToolFileIcons),V=Ie(y=>y.showTurnChangedFiles),oe=Ie(y=>y.setShowTurnChangedFiles),ge=Ie(y=>y.showExpandedBashTools),Fe=Ie(y=>y.setShowExpandedBashTools),Ne=Ie(y=>y.showExpandedEditTools),He=Ie(y=>y.setShowExpandedEditTools),X=Ie(y=>y.timeFormatPreference),v=Ie(y=>y.setTimeFormatPreference),je=Ie(y=>y.weekStartPreference),Pe=Ie(y=>y.setWeekStartPreference),Le=Ie(y=>y.showSplitAssistantMessageActions),qe=Ie(y=>y.setShowSplitAssistantMessageActions),rt=Ie(y=>y.allowPromptingSubagentSessions),ot=Ie(y=>y.setAllowPromptingSubagentSessions),it=lt(y=>y.settingsMessageStreamTransport),dt=lt(y=>y.setSettingsMessageStreamTransport),Je=it,_e=lt(y=>y.settingsDefaultFileViewerPreview),gt=lt(y=>y.setSettingsDefaultFileViewerPreview),fe=Ie(y=>y.isSettingsDialogOpen),{themeMode:tt,setThemeMode:nt,availableThemes:Ze,customThemesLoading:ft,reloadCustomThemes:bt,lightThemeId:Mt,darkThemeId:ue,setLightThemePreference:Ve,setDarkThemePreference:Qe}=ur(),[Ge,xt]=o.useState(!1),kt=o.useMemo(()=>ns()&&typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancySupported===!0,[]),ht=typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.macVibrancy===!0,[Pt,Wt]=o.useState(ht),[ts,bs]=o.useState(!1),ks=o.useMemo(()=>ns()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Yt=Ie(y=>y.dockBadgeEnabled),Ss=Ie(y=>y.setDockBadgeEnabled),[Ce,jt]=o.useState(0),vt=Ie(y=>y.reportUsage),Ht=Ie(y=>y.setReportUsage),qt=o.useCallback(y=>{Ht(y),Nt({reportUsage:y})},[Ht]),Vt=fe&&(s?s.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Vt)return;let y=null,S=Date.now();const me=()=>{const at=Date.now();at-S>=420&&(jt(Tt=>(Tt+1)%24),S=at),y=requestAnimationFrame(me)};(typeof document>"u"||document.visibilityState==="visible")&&(y=requestAnimationFrame(me));const We=()=>{document.visibilityState==="visible"&&y===null?y=requestAnimationFrame(me):document.visibilityState!=="visible"&&y!==null&&(cancelAnimationFrame(y),y=null)};return document.addEventListener("visibilitychange",We),()=>{document.removeEventListener("visibilitychange",We),y!==null&&cancelAnimationFrame(y)}},[Vt]);const ps=o.useCallback(y=>{M(y),Nt({userMessageRenderingMode:y})},[M]),vs=o.useCallback(y=>{R(y),Nt({stickyUserHeader:y})},[R]),Jt=o.useCallback(y=>{W(y),Nt({expandedEditorToolbar:y})},[W]),Es=o.useCallback(y=>{A(y),Nt({collapsibleUserMessages:y})},[A]),Nn=o.useCallback(y=>{Y(y),Nt({wideChatLayoutEnabled:y})},[Y]),_s=o.useCallback(y=>{qe(y),Nt({showSplitAssistantMessageActions:y})},[qe]),Ms=o.useCallback(y=>{Ke(y),Nt({inputSpellcheckEnabled:y})},[Ke]),nn=o.useCallback(y=>{F(y),Nt({chatRenderMode:y})},[F]),ut=o.useCallback(y=>{dt(y),Nt({messageStreamTransport:y})},[dt]),pt=o.useCallback(y=>{J(y),Nt({activityRenderMode:y})},[J]),wt=o.useCallback(y=>{U(y),Nt({mermaidRenderingMode:y})},[U]),Qt=o.useCallback(y=>{Re(y),Nt({showToolFileIcons:y})},[Re]),Xt=o.useCallback(y=>{oe(y),Nt({showTurnChangedFiles:y})},[oe]),an=o.useCallback(y=>{gt(y),Nt({defaultFileViewerPreview:y}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:y}}))},[gt]),rn=o.useCallback(y=>{Fe(y),Nt({showExpandedBashTools:y})},[Fe]),kn=o.useCallback(y=>{He(y),Nt({showExpandedEditTools:y})},[He]),pr=o.useCallback(y=>{v(y),Nt({timeFormatPreference:y})},[v]),gr=o.useCallback(y=>{Pe(y),Nt({weekStartPreference:y})},[Pe]),On=o.useMemo(()=>Ze.filter(y=>y.metadata.variant==="light").sort((y,S)=>y.metadata.name.localeCompare(S.metadata.name)),[Ze]),gs=o.useMemo(()=>Ze.filter(y=>y.metadata.variant==="dark").sort((y,S)=>y.metadata.name.localeCompare(S.metadata.name)),[Ze]),Ts=o.useMemo(()=>On.find(y=>y.metadata.id===Mt)??On[0],[On,Mt]),on=o.useMemo(()=>gs.find(y=>y.metadata.id===ue)??gs[0],[gs,ue]),Rs=o.useCallback((y,S)=>{const me=S==="dark"?" Dark":" Light";return y.endsWith(me)?y.slice(0,-me.length):y},[]),Ue=y=>s?s.includes(y):!0,Ks=ms(),ln=Ue("theme")&&!Ks,Sa=Ue("theme")||Ue("timeFormat")||Ue("weekStart"),Sn=d&&Dn()&&!ns()&&!Ks,hr=Ks?Sa:Ue("theme")||Sn||Ue("pwaInstallName")||Ue("pwaOrientation")||Ue("timeFormat")||Ue("weekStart"),as=Ue("fontSize")||Ue("terminalFontSize")||Ue("editorFontSize")||Ue("spacing")||Ue("inputBarOffset"),fr=Ue("terminalQuickKeys")&&!d||Ue("fileEditorKeymap")||Ue("expandedEditorToolbar"),zn=Ue("mermaidRendering")||Ue("userMessageRendering")||Ue("chatRenderMode")||Ue("messageTransport")||Ue("activityRenderMode")&&B==="sorted"||Ue("collapsibleUserMessages")||Ue("stickyUserHeader")||Ue("wideChatLayout")||Ue("codeBlockLineWrap")||Ue("splitAssistantMessageActions")||Ue("diffLayout")||Ue("dotfiles")||Ue("fileViewerPreview")||Ue("reasoning")||Ue("followUpBehavior")||Ue("persistDraft")||Ue("showToolFileIcons")||Ue("expandedTools")||!d&&Ue("inputSpellcheck"),Os=Ue("pwaInstallName")&&Dn()&&c&&!ns()&&!Ks,cn=Ue("pwaOrientation")&&Dn()&&!ns()&&!Ks,Hs=Ue("mobileKeyboardMode")&&Dn()&&!ns()&&!Ks&&_m(),[dn,Kn]=o.useState(()=>np()),[na,Fs]=o.useState(""),[Un,un]=o.useState("system"),xr=o.useMemo(()=>{const y=Cl.find(S=>S.id===X);return l(y?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[X,l]),yr=o.useMemo(()=>{const y=Il.find(S=>S.id===je);return l(y?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[je,l]),br=o.useMemo(()=>{const y=Nl.find(S=>S.id===Un);return y?l(y.labelKey):void 0},[Un,l]),vr=o.useMemo(()=>{const y=kl.find(S=>S.id===G);return y?l(y.labelKey):void 0},[G,l]),jr=o.useCallback(y=>{y!==dn&&(Kn(y),ap(y),window.location.reload())},[dn]),aa=o.useCallback(async y=>{if(typeof window>"u")return;const S=window,We=y.trim().replace(/\s+/g," ").slice(0,64);if(await Nt({pwaAppName:We}),typeof S.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const at=S.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(We);Fs(at);return}Fs(We||ga),S.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),ra=o.useCallback(async y=>{if(typeof window>"u")return;const S=window,me=Gr(y);if(await Nt({pwaOrientation:me}),typeof S.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const We=S.__OPENCHAMBER_SET_PWA_ORIENTATION__(me);un(We);return}un(me),S.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!Os&&!cn&&!Hs)return;let y=!1;return(async()=>{try{const me=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!me.ok){y||Fs(ga);return}const We=await me.json().catch(()=>({})),Tt=(typeof We?.pwaAppName=="string"?We.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),js=Gr(We?.pwaOrientation),Zt=po(We?.mobileKeyboardMode);y||(Os&&Fs(Tt||ga),cn&&un(js),Hs&&ee(Zt))}catch{y||(Os&&Fs(ga),cn&&un("system"),Hs&&ee("native"))}})(),()=>{y=!0}},[ee,Hs,Os,cn]),t.jsxs("div",{className:"space-y-8",children:[hr&&t.jsxs("div",{className:"mb-8 space-y-6",children:[ln&&t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsx("span",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.colorMode")}),t.jsx("div",{className:"flex flex-wrap items-center gap-1",children:$y.map(y=>t.jsx(q,{variant:"chip",size:"xs","aria-pressed":tt===y.value,className:"!font-normal",onClick:()=>nt(y.value),children:l(y.labelKey)},y.value))})]}),Sn&&t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5 py-1.5",children:[t.jsx("span",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.mobileLayout")}),t.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Hy.map(y=>t.jsx(q,{variant:"chip",size:"xs","aria-pressed":dn===y.value,className:"!font-normal",onClick:()=>jr(y.value),children:l(y.labelKey)},y.value))})]}),t.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[t.jsxs("div",{"data-settings-item":"appearance.light-theme",className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.lightTheme")}),t.jsxs(At,{value:Ts?.metadata.id??"",onValueChange:Ve,children:[t.jsx(Dt,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:t.jsx(Ot,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Ts?Rs(Ts.metadata.name,"light"):void 0})}),t.jsx(Et,{children:On.map(y=>t.jsx(mt,{value:y.metadata.id,children:Rs(y.metadata.name,"light")},y.metadata.id))})]})]}),t.jsxs("div",{"data-settings-item":"appearance.dark-theme",className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.darkTheme")}),t.jsxs(At,{value:on?.metadata.id??"",onValueChange:Qe,children:[t.jsx(Dt,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:t.jsx(Ot,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:on?Rs(on.metadata.name,"dark"):void 0})}),t.jsx(Et,{children:gs.map(y=>t.jsx(mt,{value:y.metadata.id,children:Rs(y.metadata.name,"dark")},y.metadata.id))})]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[t.jsx("button",{type:"button",disabled:ft||Ge,onClick:()=>{const y=Date.now();xt(!0),bt().finally(()=>{const S=Date.now()-y;if(S<500){window.setTimeout(()=>{xt(!1)},500-S);return}xt(!1)})},className:"inline-flex items-center typography-ui-label font-normal text-foreground underline decoration-[1px] underline-offset-2 hover:text-foreground/80 disabled:cursor-not-allowed disabled:text-muted-foreground/60",children:i(Ge?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx("button",{type:"button",className:"flex items-center justify-center rounded-md p-1 text-muted-foreground/70 hover:text-foreground","aria-label":i("settings.openchamber.visual.field.themeImportInfoAria"),children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(It,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]}),kt&&t.jsxs("div",{"data-settings-item":"appearance.window-transparency",className:"flex flex-col gap-1.5 border-t border-border/40 pt-3",children:[t.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Pt,onClick:()=>{ts||Wt(!Pt)},onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),ts||Wt(!Pt))},children:[t.jsx(yt,{checked:Pt,onChange:Wt,disabled:ts,ariaLabel:i("settings.openchamber.visual.field.macVibrancy")}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.macVibrancy")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.macVibrancyHint")})]})]}),Pt!==ht&&t.jsx("div",{className:"pl-6",children:t.jsx(q,{variant:"outline",size:"sm",disabled:ts,onClick:()=>{bs(!0),Hm("desktop_set_vibrancy",{enabled:Pt})},children:i(ts?"settings.openchamber.visual.actions.restarting":"settings.openchamber.visual.actions.saveAndRestart")})})]}),ks&&t.jsx("div",{"data-settings-item":"appearance.dock-badge",className:"flex flex-col gap-1.5 border-t border-border/40 pt-3",children:t.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Yt,onClick:()=>Ss(!Yt),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Ss(!Yt))},children:[t.jsx(yt,{checked:Yt,onChange:Ss,ariaLabel:i("settings.openchamber.visual.field.dockBadge")}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.dockBadge")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.dockBadgeHint")})]})]})})]}),Sa&&t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.localization")}),t.jsxs("div",{"data-settings-item":"appearance.language",className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.appearance.language.label")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.appearance.language.description")})]}),t.jsxs(At,{value:e,onValueChange:y=>a(y),children:[t.jsx(Dt,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:t.jsx(Ot,{children:r(e)})}),t.jsx(Et,{children:n.map(y=>t.jsx(mt,{value:y,children:r(y)},y))})]})]}),(Ue("timeFormat")||Ue("weekStart"))&&t.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[Ue("timeFormat")&&t.jsxs("div",{"data-settings-item":"appearance.time-format",className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.timeFormat")}),t.jsxs(At,{value:X,onValueChange:y=>pr(y),children:[t.jsx(Dt,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:t.jsx(Ot,{children:xr})}),t.jsx(Et,{children:Cl.map(y=>t.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]})]}),Ue("weekStart")&&t.jsxs("div",{"data-settings-item":"appearance.week-start",className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.weekStartsOn")}),t.jsxs(At,{value:je,onValueChange:y=>gr(y),children:[t.jsx(Dt,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:t.jsx(Ot,{children:yr})}),t.jsx(Et,{children:Il.map(y=>t.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]})]})]})]}),(Os||cn||Hs)&&t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[Os&&t.jsxs("div",{"data-settings-item":"appearance.pwa-install-name",className:"py-1.5 space-y-1.5",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installAppName")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installAppNameHint")})]}),t.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[t.jsx(Xe,{value:na,onChange:y=>{Fs(y.target.value)},onBlur:()=>{aa(na)},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),aa(na))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Fs(ga),aa("")},className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),cn&&t.jsxs("div",{"data-settings-item":"appearance.pwa-orientation",className:"py-1.5 space-y-1.5",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installOrientation")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installOrientationHint")})]}),t.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[t.jsxs(At,{value:Un,onValueChange:y=>{const S=Gr(y);un(S),ra(S)},children:[t.jsx(Dt,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:t.jsx(Ot,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:br})}),t.jsx(Et,{children:Nl.map(y=>t.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{un("system"),ra("system")},disabled:Un==="system",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Hs&&t.jsxs("div",{"data-settings-item":"appearance.mobile-keyboard-mode",className:"py-1.5 space-y-1.5",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardMode")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardModeHint")})]}),t.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[t.jsxs(At,{value:G,onValueChange:y=>{const S=po(y);ee(S),Nt({mobileKeyboardMode:S})},children:[t.jsx(Dt,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:t.jsx(Ot,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:vr})}),t.jsx(Et,{children:kl.map(y=>t.jsx(mt,{value:y.id,children:l(y.labelKey)},y.id))})]}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ee("native"),Nt({mobileKeyboardMode:"native"})},disabled:G==="native",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),as&&t.jsx("div",{className:"mb-8 space-y-3",children:t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.spacingAndLayout")}),t.jsxs("div",{className:"pl-2",children:[Ue("fontSize")&&!d&&t.jsxs("div",{"data-settings-item":"appearance.interface-font-size",className:"flex items-center gap-8 py-1",children:[t.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFont")})}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[t.jsxs(At,{value:ye,onValueChange:y=>ke(y),children:[t.jsx(Dt,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:t.jsx(Ot,{children:lo.find(y=>y.id===ye)?.label})}),t.jsx(Et,{children:lo.map(y=>t.jsx(mt,{value:y.id,children:t.jsx("span",{style:{fontFamily:y.stack},children:y.label})},y.id))})]}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>ke(co),disabled:ye===co,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Ue("terminalFontSize")&&t.jsxs("div",{className:ce("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeFont")})}),t.jsxs("div",{className:ce("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsxs(At,{value:he,onValueChange:y=>we(y),children:[t.jsx(Dt,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:t.jsx(Ot,{children:uo.find(y=>y.id===he)?.label})}),t.jsx(Et,{children:uo.map(y=>t.jsx(mt,{value:y.id,children:t.jsx("span",{style:{fontFamily:y.stack},children:y.label})},y.id))})]}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>we(mo),disabled:he===mo,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Ue("fontSize")&&!d&&t.jsxs("div",{className:"flex items-center gap-8 py-1",children:[t.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFontSize")})}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[t.jsx(xs,{value:H,onValueChange:re,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>re(100),disabled:H===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Ue("terminalFontSize")&&t.jsxs("div",{"data-settings-item":"appearance.terminal-font-size",className:ce("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalFontSize")})}),t.jsxs("div",{className:ce("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(xs,{value:le,onValueChange:ne,min:9,max:52,step:1,className:"w-16"}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>ne(13),disabled:le===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Ue("editorFontSize")&&t.jsxs("div",{"data-settings-item":"appearance.editor-font-size",className:ce("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editorFontSize")})}),t.jsxs("div",{className:ce("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(xs,{value:be,onValueChange:ae,min:9,max:32,step:1,className:"w-16"}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>ae(13),disabled:be===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Ue("spacing")&&t.jsxs("div",{"data-settings-item":"appearance.spacing-density",className:ce("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.spacingDensity")})}),t.jsxs("div",{className:ce("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(xs,{value:de,onValueChange:Z,min:50,max:200,step:5,className:"w-16"}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>Z(100),disabled:de===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Ue("inputBarOffset")&&t.jsxs("div",{"data-settings-item":"appearance.input-bar-offset",className:ce("py-1",d?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsx("div",{className:ce("flex min-w-0 flex-col",d?"w-full":"w-56 shrink-0"),children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.inputBarOffset")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),t.jsxs("div",{className:ce("flex items-center gap-2",d?"w-full":"w-fit"),children:[t.jsx(xs,{value:se,onValueChange:ve,min:0,max:100,step:5,className:"w-16"}),t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>ve(0),disabled:se===0,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),fr&&t.jsx("div",{className:"space-y-3",children:t.jsxs("section",{className:"px-2 pb-2 pt-0",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.navigation")}),Ue("fileEditorKeymap")&&t.jsxs("div",{"data-settings-item":"appearance.file-editor-keymap",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-start sm:gap-8",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:i("settings.openchamber.visual.field.fileEditorKeymap")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.field.fileEditorKeymap"),className:"space-y-0",children:["default","vim"].map(y=>{const S=De===y,me=i(`settings.openchamber.visual.option.fileEditorKeymap.${y}`);return t.jsxs("button",{type:"button",className:"flex cursor-pointer items-center gap-2 py-0.5 text-left",role:"radio","aria-checked":S,onClick:()=>Me(y),children:[t.jsx("span",{"aria-hidden":!0,className:ce("relative flex h-[14px] w-[14px] min-h-[14px] min-w-[14px] shrink-0 self-center items-center justify-center rounded-full transition-[background-color,box-shadow] duration-200 ease-out",S?"bg-[color-mix(in_srgb,var(--primary-base)_80%,transparent)] shadow-none":"bg-[var(--surface-muted)] shadow-[inset_0_0_0_1px_var(--interactive-border)]"),children:t.jsx("span",{className:ce("block h-[5px] w-[5px] rounded-full bg-white",!S&&"opacity-0")})}),t.jsx("span",{className:ce("typography-ui-label font-normal",S?"text-foreground":"text-foreground/50"),children:me})]},y)})})]}),Ue("expandedEditorToolbar")&&t.jsxs("div",{"data-settings-item":"appearance.expanded-editor-toolbar",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":Q,onClick:()=>Jt(!Q),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Jt(!Q))},children:[t.jsx(yt,{checked:Q,onChange:Jt,ariaLabel:i("settings.openchamber.visual.field.expandedEditorToolbarAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.expandedEditorToolbar")})]}),Ue("terminalQuickKeys")&&!d&&t.jsxs("div",{"data-settings-item":"appearance.terminal-quick-keys",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":Ae,onClick:()=>Se(!Ae),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Se(!Ae))},children:[t.jsx(yt,{checked:Ae,onChange:Se,ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria")}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalQuickKeys")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),zn&&t.jsxs("div",{className:"space-y-3",children:[(Ue("userMessageRendering")||Ue("mermaidRendering")||Ue("chatRenderMode")||Ue("messageTransport")||Ue("activityRenderMode")&&B==="sorted"||Ue("diffLayout")&&!Ks||Ue("followUpBehavior"))&&t.jsxs("div",{className:"grid grid-cols-1 gap-y-2 md:grid-cols-[minmax(0,16rem)_minmax(0,16rem)] md:justify-start md:gap-x-2",children:[Ue("chatRenderMode")&&t.jsxs("section",{"data-settings-item":"chat.render-mode",className:"p-2 md:col-span-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.chatRenderMode")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.chatRenderModeAria"),className:"mt-1 grid w-full max-w-[26rem] grid-cols-1 gap-3 sm:grid-cols-2",children:Gy.map(y=>{const S=B===y.id,me=Ce%12;return t.jsxs("button",{type:"button",onClick:()=>nn(y.id),"aria-pressed":S,className:ce("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsx("span",{className:ce("typography-ui-label",S?"text-foreground":"text-muted-foreground"),children:l(y.labelKey)}),t.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:y.id==="live"?t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(We=>{const at=We*3+1,Tt=me-at+1,js=Tt<=0?0:Tt===1?42:Tt===2?68:92,Zt=js>0;return t.jsxs("div",{className:ce("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Zt?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[t.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),t.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${js}%`}})]},We)})}):t.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(We=>{const at=me>=(We+1)*3;return t.jsxs("div",{className:ce("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",at?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[t.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),t.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},We)})})})]},y.id)})})]}),Ue("messageTransport")&&t.jsxs("section",{"data-settings-item":"chat.message-transport",className:"p-2 md:col-span-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.messageStreamTransport")}),t.jsxs("div",{className:"mt-1 flex max-w-[24rem] flex-col gap-2",children:[t.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Sl.map(y=>t.jsx(q,{variant:"chip",size:"xs","aria-pressed":Je===y.id,className:"!font-normal",onClick:()=>ut(y.id),children:l(y.labelKey)},y.id))}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const y=Sl.find(S=>S.id===Je);return y?.descriptionKey?l(y.descriptionKey):""})()})]})]}),Ue("activityRenderMode")&&B==="sorted"&&t.jsxs("section",{className:"p-2 md:col-span-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.activityDefault")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:qy.map(y=>{const S=O===y.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":S,onClick:()=>pt(y.id),onKeyDown:me=>{(me.key===" "||me.key==="Enter")&&(me.preventDefault(),pt(y.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Qs,{checked:S,onChange:()=>pt(y.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(y.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",S?"text-foreground":"text-foreground/50"),children:l(y.labelKey)})]},y.id)})})]}),Ue("expandedTools")&&t.jsxs("section",{className:"p-2 md:col-span-2 space-y-0.5",children:[t.jsx("div",{className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.showToolsOpenedByDefault")}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ge,onClick:()=>rn(!ge),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),rn(!ge))},children:[t.jsx(yt,{checked:ge,onChange:rn,ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.bash")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Ne,onClick:()=>kn(!Ne),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),kn(!Ne))},children:[t.jsx(yt,{checked:Ne,onChange:kn,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),Ue("userMessageRendering")&&t.jsxs("section",{className:"p-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.userMessageRendering")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.userMessageRenderingAria"),className:"mt-0.5 space-y-0",children:Wy.map(y=>{const S=Qy(K)===y.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":S,onClick:()=>ps(y.id),onKeyDown:me=>{(me.key===" "||me.key==="Enter")&&(me.preventDefault(),ps(y.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Qs,{checked:S,onChange:()=>ps(y.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(y.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",S?"text-foreground":"text-foreground/50"),children:l(y.labelKey)})]},y.id)})})]}),Ue("mermaidRendering")&&t.jsxs("section",{className:"p-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.mermaidRendering")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.mermaidRenderingAria"),className:"mt-0.5 space-y-0",children:_y.map(y=>{const S=T===y.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":S,onClick:()=>wt(y.id),onKeyDown:me=>{(me.key===" "||me.key==="Enter")&&(me.preventDefault(),wt(y.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Qs,{checked:S,onChange:()=>wt(y.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(y.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",S?"text-foreground":"text-foreground/50"),children:l(y.labelKey)})]},y.id)})})]}),Ue("diffLayout")&&!Ks&&t.jsxs("section",{className:"p-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.diffLayout")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.diffLayoutAria"),className:"mt-0.5 space-y-0",children:Vy.map(y=>{const S=ie===y.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":S,onClick:()=>pe(y.id),onKeyDown:me=>{(me.key===" "||me.key==="Enter")&&(me.preventDefault(),pe(y.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Qs,{checked:S,onChange:()=>pe(y.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:l(y.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",S?"text-foreground":"text-foreground/50"),children:l(y.labelKey)})]},y.id)})})]}),Ue("followUpBehavior")&&t.jsxs("section",{"data-settings-item":"chat.follow-up-behavior",className:"p-2",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.followUpBehavior")}),t.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.followUpBehaviorAria"),className:"mt-0.5 space-y-0",children:Jy.map(y=>{const S=Te===y.id;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":S,onClick:()=>Be(y.id),onKeyDown:me=>{(me.key===" "||me.key==="Enter")&&(me.preventDefault(),Be(y.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[t.jsx(Qs,{checked:S,onChange:()=>Be(y.id),ariaLabel:i("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(y.labelKey)})}),t.jsx("span",{className:ce("typography-ui-label font-normal",S?"text-foreground":"text-foreground/50"),children:l(y.labelKey)})]},y.id)})})]})]}),Ue("sessionGoal")&&!Ks&&t.jsxs("section",{className:"p-2 mb-6 space-y-0.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.goal.sectionTitle")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),t.jsx(It,{sideOffset:8,className:"max-w-sm",children:i("settings.openchamber.visual.goal.description")})]})]}),t.jsxs("div",{"data-settings-item":"chat.session-goal",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>x(!f),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),x(!f))},children:[t.jsx(yt,{checked:f,onChange:x,ariaLabel:i("settings.openchamber.visual.field.sessionGoalAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sessionGoal")})]}),t.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2 py-0.5",children:[t.jsxs("div",{className:ce("flex items-center gap-2",f?"cursor-pointer":"opacity-50"),role:"button",tabIndex:f?0:-1,"aria-pressed":D,onClick:()=>{f&&P(!D)},onKeyDown:y=>{f&&(y.key===" "||y.key==="Enter")&&(y.preventDefault(),P(!D))},children:[t.jsx(yt,{checked:D,onChange:P,disabled:!f,ariaLabel:i("settings.openchamber.visual.goal.budgetAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.goal.budgetLabel")})]}),f&&D?t.jsx(xs,{value:I,onValueChange:y=>{typeof y=="number"&&Number.isFinite(y)&&y>0&&L(Math.floor(y))},min:1e3,max:1e8,step:5e4}):null]})]}),(Ue("sessionAssist")||Ue("collapsibleUserMessages")||Ue("stickyUserHeader")||Ue("wideChatLayout")||Ue("codeBlockLineWrap")||Ue("splitAssistantMessageActions")||Ue("subagentReadOnlyBanner")||Ue("dotfiles")||Ue("fileViewerPreview")||Ue("persistDraft")||Ue("showToolFileIcons")||Ue("showTurnChangedFiles")||!d&&Ue("inputSpellcheck")||Ue("reasoning"))&&t.jsxs("div",{className:"space-y-6",children:[(Ue("sessionAssist")||Ue("subagentReadOnlyBanner"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.session-assistance",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.sessionAssistance")}),Ue("sessionAssist")&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-settings-item":"chat.session-recap",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>w(!p),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),w(!p))},children:[t.jsx(yt,{checked:p,onChange:w,ariaLabel:i("settings.openchamber.visual.field.sessionRecapAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sessionRecap")})]}),t.jsxs("div",{"data-settings-item":"chat.session-suggestion",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>g(!u),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),g(!u))},children:[t.jsx(yt,{checked:u,onChange:g,ariaLabel:i("settings.openchamber.visual.field.sessionSuggestionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sessionSuggestion")})]})]}),Ue("subagentReadOnlyBanner")&&t.jsxs("div",{"data-settings-item":"chat.subagent-read-only-banner",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":rt,onClick:()=>ot(!rt),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),ot(!rt))},children:[t.jsx(yt,{checked:rt,onChange:ot,ariaLabel:i("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.allowPromptingSubagentSessions")})]})]}),Ue("reasoning")&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.reasoning",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.reasoning")}),Ue("reasoning")&&t.jsxs("div",{"data-settings-item":"chat.reasoning-traces",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>N(!m),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),N(!m))},children:[t.jsx(yt,{checked:m,onChange:N,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),Ue("reasoning")&&m&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":b,onClick:()=>j(!b),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),j(!b))},children:[t.jsx(yt,{checked:b,onChange:j,ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleThinkingBlocks")})]})]}),(Ue("collapsibleUserMessages")||Ue("stickyUserHeader")||Ue("wideChatLayout")||Ue("splitAssistantMessageActions")||Ue("codeBlockLineWrap"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.message-appearance",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.messageAppearance")}),Ue("collapsibleUserMessages")&&t.jsxs("div",{"data-settings-item":"chat.collapsible-user-messages",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":C,onClick:()=>Es(!C),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Es(!C))},children:[t.jsx(yt,{checked:C,onChange:Es,ariaLabel:i("settings.openchamber.visual.field.collapsibleUserMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleUserMessages")})]}),Ue("stickyUserHeader")&&t.jsxs("div",{"data-settings-item":"chat.sticky-user-header",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":z,onClick:()=>vs(!z),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),vs(!z))},children:[t.jsx(yt,{checked:z,onChange:vs,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),Ue("wideChatLayout")&&t.jsxs("div",{"data-settings-item":"chat.wide-layout",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":te,onClick:()=>Nn(!te),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Nn(!te))},children:[t.jsx(yt,{checked:te,onChange:Nn,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),Ue("splitAssistantMessageActions")&&t.jsxs("div",{"data-settings-item":"chat.inline-assistant-actions",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Le,onClick:()=>_s(!Le),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),_s(!Le))},children:[t.jsx(yt,{checked:Le,onChange:_s,ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria")}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActions")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),Ue("codeBlockLineWrap")&&t.jsxs("div",{"data-settings-item":"chat.code-block-line-wrap",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":k,onClick:()=>$(!k),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),$(!k))},children:[t.jsx(yt,{checked:k,onChange:$,ariaLabel:i("settings.openchamber.visual.field.codeBlockLineWrapAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeBlockLineWrap")})]})]}),(Ue("showToolFileIcons")||Ue("showTurnChangedFiles")||Ue("dotfiles")||Ue("fileViewerPreview"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.tools-and-files",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.toolsAndFiles")}),Ue("showToolFileIcons")&&t.jsxs("div",{"data-settings-item":"chat.tool-file-icons",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Ye,onClick:()=>Qt(!Ye),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Qt(!Ye))},children:[t.jsx(yt,{checked:Ye,onChange:Qt,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),Ue("showTurnChangedFiles")&&t.jsxs("div",{"data-settings-item":"chat.changed-files",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":V,onClick:()=>Xt(!V),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Xt(!V))},children:[t.jsx(yt,{checked:V,onChange:Xt,ariaLabel:i("settings.openchamber.visual.field.showTurnChangedFilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showTurnChangedFiles")})]}),Ue("dotfiles")&&!ms()&&t.jsxs("div",{"data-settings-item":"chat.dotfiles",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":h,onClick:()=>Dr(!h),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Dr(!h))},children:[t.jsx(yt,{checked:h,onChange:Dr,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),Ue("fileViewerPreview")&&t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":_e,onClick:()=>an(!_e),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),an(!_e))},children:[t.jsx("span",{onClick:y=>y.stopPropagation(),children:t.jsx(yt,{checked:_e,onChange:an,ariaLabel:i("settings.openchamber.defaults.field.openFilesPreviewAria")})}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.defaults.field.openFilesPreview")})]})]}),(Ue("persistDraft")||!d&&Ue("inputSpellcheck"))&&t.jsxs("section",{className:"p-2 space-y-0.5",children:[t.jsx("h3",{"data-settings-item":"chat.composer",className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.composer")}),Ue("persistDraft")&&t.jsxs("div",{"data-settings-item":"chat.persist-drafts",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ze,onClick:()=>Oe(!ze),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Oe(!ze))},children:[t.jsx(yt,{checked:ze,onChange:Oe,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!d&&Ue("inputSpellcheck")&&t.jsxs("div",{"data-settings-item":"chat.spellcheck",className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":$e,onClick:()=>Ms(!$e),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),Ms(!$e))},children:[t.jsx(yt,{checked:$e,onChange:Ms,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]})]}),Ue("reportUsage")&&t.jsx("div",{className:"space-y-3",children:t.jsxs("section",{className:"px-2 pb-2 pt-0",children:[t.jsx("h4",{className:"typography-ui-header font-medium text-foreground mb-2",children:i("settings.openchamber.visual.section.privacy")}),t.jsxs("div",{"data-settings-item":"appearance.usage-reports",className:"flex items-start gap-2 py-1.5",children:[t.jsx(yt,{checked:vt,onChange:qt,ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria")}),t.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[t.jsx("div",{className:"group flex cursor-pointer",role:"button",tabIndex:0,"aria-pressed":vt,onClick:()=>qt(!vt),onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),qt(!vt))},children:t.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sendAnonymousUsageReports")})}),t.jsx("span",{className:"typography-meta text-muted-foreground pointer-events-none",children:i("settings.openchamber.visual.field.sendAnonymousUsageReportsHint")})]})]})]})})]})},Yy=1,Xy=365,Pl=30,Zy=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],$c=()=>{const s=et.c(113),{t:e}=st(),n=Ie(eb),a=Ie(tb),r=Ie(sb),i=Ie(nb),l=Ie(ab),d=Ie(rb);let c;s[0]===Symbol.for("react.memo_cache_sentinel")?(c={autoRun:!1},s[0]=c):c=s[0];const{candidates:h,isRunning:m,runCleanup:p,action:u}=nm(c),w=h.length;let g;s[1]!==p||s[2]!==e?(g=async()=>{const ie=await p({force:!0});if(ie.completedIds.length===0&&ie.failedIds.length===0){_.message(ie.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ie.completedIds.length>0&&_.success(ie.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ie.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ie.completedIds.length})),ie.failedIds.length>0&&_.error(ie.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ie.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ie.failedIds.length}))},s[1]=p,s[2]=e,s[3]=g):g=s[3];const f=g;let x;s[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),s[4]=e,s[5]=x):x=s[5];let D;s[6]!==x?(D=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),s[6]=x,s[7]=D):D=s[7];let P;s[8]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[8]=P):P=s[8];let I;s[9]!==e?(I=e("settings.openchamber.sessionRetention.tooltip"),s[9]=e,s[10]=I):I=s[10];let L;s[11]!==I?(L=t.jsxs(St,{children:[P,t.jsx(It,{sideOffset:8,className:"max-w-xs",children:I})]}),s[11]=I,s[12]=L):L=s[12];let N;s[13]!==D||s[14]!==L?(N=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[D,L]})}),s[13]=D,s[14]=L,s[15]=N):N=s[15];let b,j;s[16]!==n||s[17]!==i?(b=()=>i(!n),j=ie=>{(ie.key===" "||ie.key==="Enter")&&(ie.preventDefault(),i(!n))},s[16]=n,s[17]=i,s[18]=b,s[19]=j):(b=s[18],j=s[19]);let T;s[20]!==e?(T=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),s[20]=e,s[21]=T):T=s[21];let U;s[22]!==n||s[23]!==i||s[24]!==T?(U=t.jsx(yt,{checked:n,onChange:i,ariaLabel:T}),s[22]=n,s[23]=i,s[24]=T,s[25]=U):U=s[25];let K;s[26]!==e?(K=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),s[26]=e,s[27]=K):K=s[27];let M;s[28]!==K?(M=t.jsx("span",{className:"typography-ui-label text-foreground",children:K}),s[28]=K,s[29]=M):M=s[29];let C;s[30]!==n||s[31]!==U||s[32]!==M||s[33]!==b||s[34]!==j?(C=t.jsxs("div",{"data-settings-item":"sessions.auto-cleanup",className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:b,onKeyDown:j,children:[U,M]}),s[30]=n,s[31]=U,s[32]=M,s[33]=b,s[34]=j,s[35]=C):C=s[35];let A;s[36]!==e?(A=e("settings.openchamber.sessionRetention.field.retentionPeriod"),s[36]=e,s[37]=A):A=s[37];let z;s[38]!==A?(z=t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:A})}),s[38]=A,s[39]=z):z=s[39];let R;s[40]!==e?(R=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),s[40]=e,s[41]=R):R=s[41];let Q;s[42]!==a||s[43]!==l||s[44]!==R?(Q=t.jsx(xs,{value:a,onValueChange:l,min:Yy,max:Xy,step:1,"aria-label":R,className:"w-20 tabular-nums"}),s[42]=a,s[43]=l,s[44]=R,s[45]=Q):Q=s[45];let W;s[46]!==e?(W=e("settings.openchamber.sessionRetention.field.days"),s[46]=e,s[47]=W):W=s[47];let te;s[48]!==W?(te=t.jsx("span",{className:"typography-ui-label text-muted-foreground",children:W}),s[48]=W,s[49]=te):te=s[49];let Y;s[50]!==l?(Y=()=>l(Pl),s[50]=l,s[51]=Y):Y=s[51];const k=a===Pl;let $;s[52]!==e?($=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),s[52]=e,s[53]=$):$=s[53];let B;s[54]!==e?(B=e("settings.common.actions.reset"),s[54]=e,s[55]=B):B=s[55];let F;s[56]===Symbol.for("react.memo_cache_sentinel")?(F=t.jsx(E,{name:"restart",className:"h-3.5 w-3.5"}),s[56]=F):F=s[56];let O;s[57]!==Y||s[58]!==k||s[59]!==$||s[60]!==B?(O=t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:Y,disabled:k,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":$,title:B,children:F}),s[57]=Y,s[58]=k,s[59]=$,s[60]=B,s[61]=O):O=s[61];let J;s[62]!==Q||s[63]!==te||s[64]!==O?(J=t.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[Q,te,O]}),s[62]=Q,s[63]=te,s[64]=O,s[65]=J):J=s[65];let H;s[66]!==z||s[67]!==J?(H=t.jsxs("div",{"data-settings-item":"sessions.retention-period",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[z,J]}),s[66]=z,s[67]=J,s[68]=H):H=s[68];let re;s[69]!==e?(re=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),s[69]=e,s[70]=re):re=s[70];let le;s[71]!==re?(le=t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:re})}),s[71]=re,s[72]=le):le=s[72];let ne;s[73]!==r||s[74]!==d||s[75]!==e?(ne=Zy.map(ie=>t.jsx(q,{type:"button",variant:"chip",size:"xs","aria-pressed":r===ie.value,className:"!font-normal",onClick:()=>d(ie.value),children:e(ie.labelKey)},ie.value)),s[73]=r,s[74]=d,s[75]=e,s[76]=ne):ne=s[76];let be;s[77]!==ne?(be=t.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:ne}),s[77]=ne,s[78]=be):be=s[78];let ae;s[79]!==le||s[80]!==be?(ae=t.jsxs("div",{"data-settings-item":"sessions.retention-action",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[le,be]}),s[79]=le,s[80]=be,s[81]=ae):ae=s[81];let ye;s[82]!==C||s[83]!==H||s[84]!==ae?(ye=t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[C,H,ae]}),s[82]=C,s[83]=H,s[84]=ae,s[85]=ye):ye=s[85];let ke;s[86]!==e?(ke=e("settings.openchamber.sessionRetention.manualCleanup.title"),s[86]=e,s[87]=ke):ke=s[87];let he;s[88]!==ke?(he=t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("p",{className:"typography-meta text-foreground font-medium",children:ke})}),s[88]=ke,s[89]=he):he=s[89];let we;s[90]!==m||s[91]!==e?(we=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),s[90]=m,s[91]=e,s[92]=we):we=s[92];let de;s[93]!==f||s[94]!==m||s[95]!==we?(de=t.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:t.jsx(q,{type:"button",variant:"outline",size:"xs",onClick:f,disabled:m,className:"!font-normal",children:we})}),s[93]=f,s[94]=m,s[95]=we,s[96]=de):de=s[96];let Z;s[97]!==he||s[98]!==de?(Z=t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[he,de]}),s[97]=he,s[98]=de,s[99]=Z):Z=s[99];let se;s[100]!==u||s[101]!==w||s[102]!==e?(se=u==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:w}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:w}),s[100]=u,s[101]=w,s[102]=e,s[103]=se):se=s[103];let ve;s[104]!==se?(ve=t.jsx("p",{className:"typography-meta text-muted-foreground",children:se}),s[104]=se,s[105]=ve):ve=s[105];let G;s[106]!==Z||s[107]!==ve?(G=t.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[Z,ve]}),s[106]=Z,s[107]=ve,s[108]=G):G=s[108];let ee;return s[109]!==ye||s[110]!==G||s[111]!==N?(ee=t.jsxs("div",{className:"mb-8",children:[N,ye,G]}),s[109]=ye,s[110]=G,s[111]=N,s[112]=ee):ee=s[112],ee};function eb(s){return s.autoDeleteEnabled}function tb(s){return s.autoDeleteAfterDays}function sb(s){return s.sessionRetentionAction}function nb(s){return s.setAutoDeleteEnabled}function ab(s){return s.setAutoDeleteAfterDays}function rb(s){return s.setSessionRetentionAction}const Al=(s,e,n)=>!s||!Number.isFinite(s)?e:new Intl.DateTimeFormat(Ai(),{dateStyle:"medium",timeStyle:"short",hour12:n==="auto"?void 0:n==="12h"}).format(s),Vc=()=>{const{t:s}=st(),e=Ie(j=>j.timeFormatPreference),[n,a]=o.useState(!1),[r,i]=o.useState(!0),[l,d]=o.useState(!1),[c,h]=o.useState(null),[m,p]=o.useState(!1),[u,w]=o.useState([]),[g,f]=o.useState(am),[x,D]=o.useState(""),P=o.useMemo(()=>rm(),[]),I=o.useCallback(async()=>{i(!0),D("");try{const j=await im();w(j)}catch(j){const T=j instanceof Error?j.message:s("settings.openchamber.passkeys.toast.loadFailed");D(T)}finally{i(!1)}},[s]);o.useEffect(()=>{let j=!1;return(async()=>{try{if(!P.supported){j||(a(!1),i(!1));return}j||a(!0)}catch{j||a(!1)}if(!j){const T=await Cr();if(f(T),!T.enabled){w([]),i(!1);return}await I()}})(),()=>{j=!0,Yi()}},[I,P.supported]);const L=o.useCallback(async()=>{if(!g.enabled){const j=s("settings.openchamber.passkeys.toast.enableUiPasswordFirst");D(j),_.message(j);return}if(!n){D(P.reason),_.message(P.reason);return}if(l){Yi(),d(!1);return}D(""),d(!0);try{await om(),f(await Cr()),await I(),_.success(s("settings.openchamber.passkeys.toast.added"))}catch(j){if(lm(j)){_.message(s("settings.openchamber.passkeys.toast.setupCanceled"));return}const T=j instanceof Error?j.message:s("settings.openchamber.passkeys.toast.addFailed");D(T),_.error(T)}finally{d(!1)}},[l,I,g.enabled,P.reason,n,s]),N=o.useCallback(async j=>{h(j),D("");try{await cm(j),f(await Cr()),await I(),_.success(s("settings.openchamber.passkeys.toast.removed"))}catch(T){const U=T instanceof Error?T.message:s("settings.openchamber.passkeys.toast.removeFailed");D(U),_.error(U)}finally{h(null)}},[I,s]),b=o.useCallback(async()=>{p(!0),D("");try{await dm(),window.location.reload()}catch(j){const T=j instanceof Error?j.message:s("settings.openchamber.passkeys.toast.clearAuthFailed");D(T),_.error(T),p(!1)}},[s]);return t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.passkeys.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.passkeys.field.currentDevice")})}),t.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[t.jsx(q,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{L()},disabled:r||m,className:"!font-normal",children:s(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),t.jsx(q,{type:"button",variant:"ghost",size:"xs",onClick:()=>{b()},disabled:r||l||m,className:"!font-normal text-muted-foreground hover:text-foreground",children:s(m?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]})]}),!g.enabled&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.uiPasswordRequired")}),g.enabled&&!n&&t.jsx("p",{className:"typography-meta text-muted-foreground",children:P.reason}),r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.loading")}):u.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.passkeys.state.noneSaved")}):t.jsx("div",{className:"space-y-1 pt-1",children:u.map(j=>t.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j.label})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:j.lastUsedAt?s("settings.openchamber.passkeys.item.lastUsed",{time:Al(j.lastUsedAt,s("settings.openchamber.passkeys.time.neverUsed"),e)}):s("settings.openchamber.passkeys.item.added",{time:Al(j.createdAt,s("settings.openchamber.passkeys.time.neverUsed"),e)})}),t.jsx(q,{type:"button",variant:"ghost",size:"xs",onClick:()=>{N(j.id)},disabled:c===j.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===j.id?s("settings.openchamber.passkeys.actions.removing"):s("settings.common.actions.delete")})]})]},j.id))})]}),x&&t.jsx("div",{className:"mt-1 px-2 py-1.5",children:t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:x})})]})},Dl=s=>{const e=fn(s);return e||{providerId:"",modelId:""}},_c=()=>{const{t:s}=st(),e=lt(k=>k.setProvider),n=lt(k=>k.setModel),a=lt(k=>k.setAgent),r=lt(k=>k.setCurrentVariant),i=lt(k=>k.setSettingsDefaultModel),l=lt(k=>k.setSettingsDefaultVariant),d=lt(k=>k.setSettingsDefaultAgent),c=Ie(k=>k.showDeletionDialog),h=Ie(k=>k.setShowDeletionDialog),m=lt(k=>k.providers),[p,u]=o.useState(),[w,g]=o.useState(),[f,x]=o.useState(),[D,P]=o.useState(!0),[I,L]=o.useState(),[N,b]=o.useState(),[j,T]=o.useState(!0),U=o.useMemo(()=>Dl(p),[p]);o.useEffect(()=>{(async()=>{try{let $=null;if(!$){const B=Vs()?.settings;if(B)try{const O=(await B.load())?.settings;if(O){const J=O;$={defaultModel:typeof O.defaultModel=="string"?O.defaultModel:void 0,defaultVariant:typeof J.defaultVariant=="string"?J.defaultVariant:void 0,defaultAgent:typeof O.defaultAgent=="string"?O.defaultAgent:void 0,smallModelUseDefault:typeof J.smallModelUseDefault=="boolean"?J.smallModelUseDefault:void 0,smallModelOverride:typeof J.smallModelOverride=="string"?J.smallModelOverride:void 0}}}catch{}}if(!$){const B=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});B.ok&&($=await B.json())}if($){const B=typeof $.defaultModel=="string"&&$.defaultModel.trim().length>0?$.defaultModel.trim():void 0,F=typeof $.defaultVariant=="string"&&$.defaultVariant.trim().length>0?$.defaultVariant.trim():void 0,O=typeof $.defaultAgent=="string"&&$.defaultAgent.trim().length>0?$.defaultAgent.trim():void 0;B!==void 0&&u(B),F!==void 0&&g(F),O!==void 0&&x(O),typeof $.smallModelUseDefault=="boolean"&&P($.smallModelUseDefault),typeof $.smallModelOverride=="string"&&$.smallModelOverride.trim()&&L($.smallModelOverride.trim())}}catch($){console.warn("Failed to load defaults settings:",$)}finally{T(!1)}})()},[]);const K=o.useCallback(async(k,$)=>{const B=k&&$?`${k}/${$}`:void 0;u(B),g(void 0),l(void 0),r(void 0),i(B),k&&$&&m.find(O=>O.id===k)&&(e(k),n($));try{await Nt({defaultModel:B??"",defaultVariant:""});const F=await ct("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:B})});F.ok||console.warn("Failed to save default model to server:",F.status,F.statusText)}catch(F){console.warn("Failed to save default model:",F)}},[m,r,n,e,i,l]),M="__default__",C=o.useCallback(k=>k===M?s("settings.openchamber.defaults.option.default"):k.charAt(0).toUpperCase()+k.slice(1),[s]),A=o.useCallback(async k=>{const $=k===M?void 0:k||void 0;g($),l($),r($);try{await Nt({defaultVariant:$??""})}catch(B){console.warn("Failed to save default variant:",B)}},[r,l]),z=o.useCallback(async k=>{const $=k||void 0;x($),d($),k&&a(k);try{await Nt({defaultAgent:$??""})}catch(B){console.warn("Failed to save default agent:",B)}},[a,d]),R=o.useCallback(async k=>{P(k);try{await Nt({smallModelUseDefault:k})}catch($){console.warn("Failed to save small model preference:",$)}},[]),Q=o.useCallback(async(k,$)=>{const B=k&&$?`${k}/${$}`:void 0;L(B);try{await Nt({smallModelOverride:B??""})}catch(F){console.warn("Failed to save small model override:",F)}},[]),W=o.useMemo(()=>Dl(I),[I]);o.useEffect(()=>{if(D||N!==void 0)return;let k=!1;return(async()=>{try{const $=await ct("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!$.ok)return;const B=await $.json().catch(()=>null);!k&&Array.isArray(B?.authenticatedProviders)&&b(B.authenticatedProviders.filter(F=>typeof F=="string"))}catch{}})(),()=>{k=!0}},[D,N]);const te=o.useMemo(()=>{if(!U.providerId||!U.modelId)return[];const B=m.find(F=>F.id===U.providerId)?.models.find(F=>F.id===U.modelId)?.variants;return B?Object.keys(B):[]},[U.modelId,U.providerId,m]),Y=te.length>0;return o.useEffect(()=>{!Y&&w&&(g(void 0),l(void 0),r(void 0),Nt({defaultVariant:""}).catch(()=>{}))},[w,r,l,Y]),j?null:t.jsxs("div",{className:"mb-6",children:[t.jsx("div",{className:"mb-0.5 px-1",children:t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.defaults.title")})})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[s("settings.openchamber.defaults.summaryPrefix")," ",U.providerId?t.jsxs("span",{className:"text-foreground",children:[U.providerId,"/",U.modelId,Y?` (${w??s("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):t.jsx("span",{className:"text-foreground",children:s("settings.openchamber.defaults.summaryOpenCodeDefault")}),f&&t.jsxs(t.Fragment,{children:[" / ",t.jsx("span",{className:"text-foreground",children:f})]})]}),t.jsxs("div",{"data-settings-item":"sessions.default-model",className:ce("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.field.defaultModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(ja,{providerId:U.providerId,modelId:U.modelId,onChange:K})})]}),t.jsxs("div",{"data-settings-item":"sessions.default-thinking",className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.field.defaultThinking")})}),t.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:t.jsxs(At,{value:w??M,onValueChange:A,disabled:!Y,children:[t.jsx(Dt,{className:"w-fit min-w-[120px]",children:t.jsx(Ot,{placeholder:s("settings.openchamber.defaults.field.thinkingPlaceholder"),children:C(w??M)})}),t.jsxs(Et,{children:[t.jsx(mt,{value:M,children:s("settings.openchamber.defaults.option.default")}),te.map(k=>t.jsx(mt,{value:k,children:C(k)},k))]})]})})]}),t.jsxs("div",{"data-settings-item":"sessions.default-agent",className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.field.defaultAgent")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(ic,{agentName:f||"",onChange:z})})]}),t.jsxs("div",{"data-settings-item":"sessions.deletion-dialog",className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":c,onClick:()=>h(!c),onKeyDown:k=>{(k.key===" "||k.key==="Enter")&&(k.preventDefault(),h(!c))},children:[t.jsx(yt,{checked:c,onChange:h,ariaLabel:s("settings.openchamber.defaults.field.showDeletionDialogAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.field.showDeletionDialog")})]})]}),t.jsx("div",{className:"mt-6 mb-0.5 px-1",children:t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.defaults.smallModel.title")})})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsx("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:s("settings.openchamber.defaults.smallModel.description")}),t.jsxs("div",{"data-settings-item":"sessions.small-model",className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":D,onClick:()=>{R(!D)},onKeyDown:k=>{(k.key===" "||k.key==="Enter")&&(k.preventDefault(),R(!D))},children:[t.jsx(yt,{checked:D,onChange:k=>{R(k)},ariaLabel:s("settings.openchamber.defaults.smallModel.useDefaultAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.smallModel.useDefault")})]}),D?null:t.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.defaults.smallModel.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(ja,{providerId:W.providerId,modelId:W.modelId,onChange:Q,allowedProviderIds:N})})]})]})]})},El={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"}},ib={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"},ob=()=>{const{t:s}=st(),e=o.useMemo(()=>ns(),[]),n=o.useMemo(()=>ms(),[]),a=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),r=!e&&!n&&!a,i=Ie(F=>F.nativeNotificationsEnabled),l=Ie(F=>F.setNativeNotificationsEnabled),d=Ie(F=>F.notificationMode),c=Ie(F=>F.setNotificationMode),h=Ie(F=>F.notifyOnSubtasks),m=Ie(F=>F.setNotifyOnSubtasks),p=Ie(F=>F.notifyOnCompletion),u=Ie(F=>F.setNotifyOnCompletion),w=Ie(F=>F.notifyOnError),g=Ie(F=>F.setNotifyOnError),f=Ie(F=>F.notifyOnQuestion),x=Ie(F=>F.setNotifyOnQuestion),D=Ie(F=>F.notificationTemplates),P=Ie(F=>F.setNotificationTemplates),[I,L]=o.useState("default"),[N,b]=o.useState(!1),[j,T]=o.useState(!1),[U,K]=o.useState(!1);o.useEffect(()=>{if(!r){b(!1),T(!1);return}typeof Notification<"u"&&L(Notification.permission);const F=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;b(F),(async()=>{if(!F){T(!1);return}try{const J=await navigator.serviceWorker.getRegistration();if(!J){T(!1);return}const H=await J.pushManager.getSubscription();T(!!H)}catch{T(!1)}})()},[r]);const M=async F=>{if(e){l(F);return}if(!r){l(F);return}if(F&&typeof Notification<"u"&&Notification.permission==="default")try{const O=await Notification.requestPermission();L(O),O==="granted"?l(!0):_.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.description")})}catch(O){console.error("Failed to request notification permission:",O),_.error(s("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(F&&I==="granted"))},C=e||n||a||r&&typeof Notification<"u"&&Notification.permission==="granted",A=(F,O,J)=>{P({...D,[F]:{...D[F],[O]:J}})},z=F=>{const O="=".repeat((4-F.length%4)%4),J=(F+O).replace(/-/g,"+").replace(/_/g,"/"),H=atob(J),re=new Uint8Array(H.length);for(let le=0;le<H.length;le+=1)re[le]=H.charCodeAt(le);return re},R=async(F,O,J)=>{let H=null;const re=new Promise((le,ne)=>{H=setTimeout(()=>{ne(new Error(J))},O)});try{return await Promise.race([F,re])}finally{H&&clearTimeout(H)}},Q=async F=>{if(F.active)return;const O=F.installing||F.waiting;O&&O.state!=="activated"&&await R(new Promise(J=>{const H=()=>{O.state==="activated"&&(O.removeEventListener("statechange",H),J())};O.addEventListener("statechange",H),H()}),15e3,"Service worker activation timed out")},W=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const F=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let O=null;for(const J of F)try{const H=J.opts?navigator.serviceWorker.register("/sw.js",J.opts):navigator.serviceWorker.register("/sw.js");return await R(H,1e4,`Service worker registration timed out (${J.label})`)}catch(H){O=H}throw O instanceof Error?O:new Error("Service worker registration failed")},te=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const F=await navigator.serviceWorker.getRegistration();if(F)return F;const O=await W();try{await O.update()}catch{}return await Q(O),O},Y=F=>{const O=F,J=[`type=${typeof F}`,`toString=${String(F)}`,`name=${String(O?.name??"")}`,`message=${String(O?.message??"")}`];let H="";try{H=JSON.stringify(F)}catch{}return{summary:J.filter(Boolean).join(" | "),json:H,stack:typeof O?.stack=="string"?O.stack:""}},k=async()=>{const F=Vs();if(!F?.notifications){_.error(s("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await F.notifications.notifyAgentCompletion({title:s("settings.notifications.page.testNotification.title"),body:s("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?_.success(s("settings.notifications.page.toast.testNotificationSent")):_.error(s("settings.notifications.page.toast.testNotificationFailed"))}catch(O){console.error("Test notification failed:",O),_.error(s("settings.notifications.page.toast.testNotificationFailed"))}},$=async()=>{if(!N){_.error(s("settings.notifications.page.toast.pushUnsupported"));return}const F=Vs();if(!F?.push){_.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}K(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const ae=await Notification.requestPermission();if(L(ae),ae!=="granted"){_.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){_.error(s("settings.notifications.page.toast.permissionDenied.title"),{description:s("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const O=await F.push.getVapidPublicKey();if(!O?.publicKey){_.error(s("settings.notifications.page.toast.pushKeyLoadFailed"));return}const J=await te();await Q(J);const H=await J.pushManager.getSubscription();if(!("pushManager"in J)||!J.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const le=(H??await R(J.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:z(O.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ne=le.keys;if(!le.endpoint||!ne?.p256dh||!ne.auth)throw new Error("Push subscription missing keys");if(!(await R(F.push.subscribe({endpoint:le.endpoint,keys:{p256dh:ne.p256dh,auth:ne.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:nc()}),15e3,"Push subscribe request timed out"))?.ok){_.error(s("settings.notifications.page.toast.enableBackgroundFailed"));return}T(!0),_.success(s("settings.notifications.page.toast.backgroundEnabled"))}catch(O){console.error("[Push] Enable failed:",O);const J=Y(O);_.error(s("settings.notifications.page.toast.enableBackgroundFailed"),{description:J.summary})}finally{K(!1)}},B=async()=>{if(!N){T(!1);return}const F=Vs();if(!F?.push){_.error(s("settings.notifications.page.toast.pushApiUnavailable"));return}K(!0);try{const J=await(await te()).pushManager.getSubscription();if(!J){T(!1);return}const H=J.endpoint;await J.unsubscribe(),await F.push.unsubscribe({endpoint:H}),T(!1),_.success(s("settings.notifications.page.toast.backgroundDisabled"))}finally{K(!1)}};return t.jsxs("div",{className:"space-y-8",children:[t.jsxs("div",{"data-settings-item":"notifications.delivery",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.delivery.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":i&&C,onClick:()=>{M(!(i&&C))},onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),M(!(i&&C)))},children:[t.jsx(yt,{checked:i&&C,onChange:F=>{M(F)},ariaLabel:s("settings.notifications.page.delivery.enableAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.delivery.enableLabel")})]}),i&&C&&!a&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":d==="always",onClick:()=>c(d==="always"?"hidden-only":"always"),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),c(d==="always"?"hidden-only":"always"))},children:[t.jsx(yt,{checked:d==="always",onChange:F=>c(F?"always":"hidden-only"),ariaLabel:s("settings.notifications.page.delivery.focusedAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.delivery.focusedLabel")})]}),t.jsx("div",{className:"py-2",children:t.jsx(q,{type:"button",variant:"outline",size:"sm",onClick:()=>{k()},children:s("settings.notifications.page.delivery.testAction")})})]})]}),r&&t.jsxs("div",{className:"mt-1 px-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.notifications.page.delivery.browserPermissionHint")}),I==="denied"&&t.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:s("settings.notifications.page.delivery.permissionDenied")}),I==="granted"&&!i&&t.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:s("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),n&&t.jsx("div",{className:"mt-1 px-2",children:t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.notifications.page.delivery.vscodeHint")})})]}),i&&C&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-settings-item":"notifications.events",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.events.title")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>u(!p),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),u(!p))},children:[t.jsx(yt,{checked:p,onChange:u,ariaLabel:s("settings.notifications.page.events.completionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.completionLabel")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":h,onClick:()=>m(!h),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),m(!h))},children:[t.jsx(yt,{checked:h,onChange:m,ariaLabel:s("settings.notifications.page.events.subtaskAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.subtaskLabel")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>g(!w),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),g(!w))},children:[t.jsx(yt,{checked:w,onChange:g,ariaLabel:s("settings.notifications.page.events.errorAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.errorLabel")})]}),t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>x(!f),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),x(!f))},children:[t.jsx(yt,{checked:f,onChange:x,ariaLabel:s("settings.notifications.page.events.questionAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.notifications.page.events.questionLabel")})]})]})]}),!a&&t.jsxs("div",{className:"mb-8",children:[t.jsxs("div",{className:"mb-1 px-1",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.template.title")}),t.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[s("settings.notifications.page.template.variablesLabel")," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",t.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),t.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(F=>t.jsxs("section",{className:"p-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:s(ib[F])}),t.jsxs("div",{className:"mt-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:s("settings.notifications.page.template.field.title")}),t.jsx(Xe,{value:D[F].title,onChange:O=>A(F,"title",O.target.value),className:"h-7",placeholder:s(El[F].titleKey)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:s("settings.notifications.page.template.field.message")}),t.jsx(Xe,{value:D[F].message,onChange:O=>A(F,"message",O.target.value),className:"h-7",placeholder:s(El[F].messageKey)})]})]})]},F))})]})]}),r&&t.jsxs("div",{"data-settings-item":"notifications.push",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.notifications.page.push.title")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[t.jsx(yt,{checked:N?j:!1,disabled:!N||U,onChange:F=>{F?$():B()},ariaLabel:s("settings.notifications.page.push.enableAria")}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:ce("typography-ui-label",N?"text-foreground":"text-muted-foreground"),children:s("settings.notifications.page.push.enableLabel")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s(N?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),U&&t.jsx("div",{className:"pt-0.5 text-muted-foreground",children:t.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":s("settings.notifications.page.push.loadingAria")})})]})})]})]})},Cs=s=>{if(!s)return;s.pause();const{src:e}=s;e.startsWith("blob:")&&URL.revokeObjectURL(e),s.removeAttribute("src"),s.load()},lb=[{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"}],Ml=s=>{const e=et.c(8),{value:n,label:a}=s,r=`${a}: ${n}/5`,i=`${n/5*100}%`;let l;e[0]!==i?(l=t.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:t.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:i}})}),e[0]=i,e[1]=l):l=e[1];let d;e[2]!==a?(d=t.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:a}),e[2]=a,e[3]=d):d=e[3];let c;return e[4]!==r||e[5]!==l||e[6]!==d?(c=t.jsxs("span",{className:"flex items-center gap-1.5",title:r,children:[l,d]}),e[4]=r,e[5]=l,e[6]=d,e[7]=c):c=e[7],c},cb=({selectedModelId:s,onSelect:e})=>{const{t:n}=st(),a=xe.useCallback(u=>n(u),[n]),[r,i]=xe.useState(new Map),[l,d]=xe.useState(null),c=xe.useCallback(async()=>{try{const u=await ct("/api/dictation/status",{query:{provider:"local"}});if(!u.ok)return;const w=await u.json();Array.isArray(w?.models)&&i(new Map(w.models.map(g=>[g.id,g])))}catch{}},[]);xe.useEffect(()=>{c()},[c]);const h=Array.from(r.values()).some(u=>u.downloading);xe.useEffect(()=>{if(!h)return;const u=setInterval(()=>{c()},2e3);return()=>clearInterval(u)},[h,c]);const m=async u=>{d(u);try{await ct(`/api/dictation/models/${encodeURIComponent(u)}/download`,{method:"POST"}),await c()}catch{}finally{d(null)}},p=async u=>{d(u);try{await ct(`/api/dictation/models/${encodeURIComponent(u)}`,{method:"DELETE"}),await c()}catch{}finally{d(null)}};return t.jsx("div",{role:"radiogroup","aria-label":n("settings.voice.page.field.model"),className:"mt-1 space-y-0",children:lb.map(u=>{const w=s===u.id,g=r.get(u.id)??null;return t.jsxs("div",{className:"flex w-full items-start gap-2 py-1.5",children:[t.jsx("div",{className:"pt-0.5",children:t.jsx(Qs,{checked:w,onChange:()=>e(u.id),ariaLabel:a(u.labelKey)})}),t.jsxs("div",{className:"min-w-0 flex-1 cursor-pointer",role:"button",tabIndex:0,onClick:()=>e(u.id),onKeyDown:f=>{(f.key===" "||f.key==="Enter")&&(f.preventDefault(),e(u.id))},children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5",children:[t.jsx("span",{className:ce("typography-ui-label font-normal",w?"text-foreground":"text-foreground/50"),children:a(u.labelKey)}),u.badgeKey?t.jsx("span",{className:"rounded px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide",style:{backgroundColor:"var(--status-success-background)",color:"var(--status-success)",border:"1px solid var(--status-success-border)"},children:a(u.badgeKey)}):null]}),t.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-4 gap-y-0.5",children:[t.jsx(Ml,{value:u.accuracy,label:n("settings.voice.page.stt.meta.accuracy")}),t.jsx(Ml,{value:u.speed,label:n("settings.voice.page.stt.meta.speed")}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:u.size})]}),g?.downloadError?t.jsx("p",{className:"mt-0.5 typography-meta text-[var(--status-error)]",children:g.downloadError}):null]}),t.jsx("div",{className:"flex w-14 flex-shrink-0 items-center justify-end gap-1 pt-0.5",children:g?.installed?t.jsxs(t.Fragment,{children:[t.jsx(q,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===u.id,onClick:()=>{p(u.id)},title:n("settings.voice.page.stt.modelDelete"),"aria-label":n("settings.voice.page.stt.modelDelete"),children:t.jsx(E,{name:"delete-bin",className:"h-4 w-4"})}),t.jsx(E,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":n("settings.voice.page.stt.modelInstalled")})]}):g?.downloading?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(E,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof g.downloadProgress=="number"?`${g.downloadProgress}%`:""})]}):t.jsx(q,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===u.id,onClick:()=>{m(u.id)},title:n("settings.voice.page.stt.modelDownload"),"aria-label":n("settings.voice.page.stt.modelDownload"),children:t.jsx(E,{name:"download",className:"h-4 w-4"})})})]},u.id)})})},qr=[{id:0,label:"Alloy (af)"},{id:1,label:"Bella (af)"},{id:2,label:"Nicole (af)"},{id:3,label:"Sarah (af)"},{id:4,label:"Sky (af)"},{id:5,label:"Adam (am)"},{id:6,label:"Michael (am)"},{id:7,label:"Emma (bf)"},{id:8,label:"Isabella (bf)"},{id:9,label:"George (bm)"},{id:10,label:"Lewis (bm)"}],Jr="kokoro-en-v0_19",db=()=>{const{t:s}=st(),[e,n]=xe.useState(null),[a,r]=xe.useState(!1),i=xe.useCallback(async()=>{try{const d=await ct("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const c=await d.json(),h=Array.isArray(c?.ttsModels)?c.ttsModels.find(m=>m.id===Jr):null;h&&n(h)}catch{}},[]);xe.useEffect(()=>{i()},[i]),xe.useEffect(()=>{if(!e?.downloading)return;const d=setInterval(()=>{i()},2e3);return()=>clearInterval(d)},[e?.downloading,i]);const l=async d=>{r(!0);try{const c=d==="POST"?`/api/dictation/models/${Jr}/download`:`/api/dictation/models/${Jr}`;await ct(c,{method:d}),await i()}catch{}finally{r(!1)}};return e?t.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:"Kokoro"}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:"305 MB"}),e.installed?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":s("settings.voice.page.stt.modelInstalled")}),t.jsx(q,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:a,onClick:()=>{l("DELETE")},title:s("settings.voice.page.stt.modelDelete"),"aria-label":s("settings.voice.page.stt.modelDelete"),children:t.jsx(E,{name:"delete-bin",className:"h-4 w-4"})})]}):e.downloading?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(E,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof e.downloadProgress=="number"?`${e.downloadProgress}%`:""})]}):t.jsx(q,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:a,onClick:()=>{l("POST")},title:s("settings.voice.page.stt.modelDownload"),"aria-label":s("settings.voice.page.stt.modelDownload"),children:t.jsx(E,{name:"download",className:"h-4 w-4"})}),e.downloadError?t.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:e.downloadError}):null]}):null},ub=[{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"}],mb=()=>{const{t:s}=st(),{isMobile:e}=Ds(),n=lt(v=>v.voiceProvider),a=lt(v=>v.setVoiceProvider),r=lt(v=>v.speechRate),i=lt(v=>v.setSpeechRate),l=lt(v=>v.speechPitch),d=lt(v=>v.setSpeechPitch),c=lt(v=>v.speechVolume),h=lt(v=>v.setSpeechVolume),m=lt(v=>v.sayVoice),p=lt(v=>v.setSayVoice),u=lt(v=>v.localTtsVoiceId),w=lt(v=>v.setLocalTtsVoiceId),{speak:g,stop:f,isPlaying:x,error:D}=um(),P=xe.useCallback(()=>{if(x){f();return}const v=qr.find(je=>je.id===u)?.label??String(u);g(s("settings.voice.page.preview.voiceLine",{voiceName:v}),{speakerId:u,speed:lt.getState().speechRate})},[x,u,g,f,s]),I=lt(v=>v.browserVoice),L=lt(v=>v.setBrowserVoice),N=lt(v=>v.openaiVoice),b=lt(v=>v.setOpenaiVoice),j=lt(v=>v.openaiApiKey),T=lt(v=>v.setOpenaiApiKey),U=lt(v=>v.openaiCompatibleUrl),K=lt(v=>v.setOpenaiCompatibleUrl),M=lt(v=>v.openaiCompatibleApiKey),C=lt(v=>v.setOpenaiCompatibleApiKey),A=lt(v=>v.openaiCompatibleVoice),z=lt(v=>v.setOpenaiCompatibleVoice),R=lt(v=>v.openaiCompatibleTtsModel),Q=lt(v=>v.setOpenaiCompatibleTtsModel),W=lt(v=>v.showMessageTTSButtons),te=lt(v=>v.ttsInputMode),Y=lt(v=>v.setTtsInputMode),k=lt(v=>v.sttProvider),$=lt(v=>v.setSttProvider),B=lt(v=>v.sttServerUrl),F=lt(v=>v.setSttServerUrl),O=lt(v=>v.sttApiKey),J=lt(v=>v.setSttApiKey),H=lt(v=>v.sttModel),re=lt(v=>v.setSttModel),le=lt(v=>v.sttLocalModel),ne=lt(v=>v.setSttLocalModel),be=lt(v=>v.sttLanguage),ae=lt(v=>v.setSttLanguage),ye=lt(v=>v.setShowMessageTTSButtons),ke=lt(v=>v.dictationEnabled),he=lt(v=>v.setDictationEnabled),[we,de]=xe.useState(!1),[Z,se]=xe.useState([]),[ve,G]=xe.useState(!1),[ee,ie]=xe.useState(null),[pe,Ae]=xe.useState(!1),[Se,De]=xe.useState(!1),[Me,Te]=xe.useState(null),[Be,ze]=xe.useState(!1),[Oe,$e]=xe.useState(null),[Ke,Ye]=xe.useState([]),[Re,V]=xe.useState(!1);xe.useEffect(()=>((async()=>{const je=await Ir.waitForVoices();Ye(je)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ye(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const oe=xe.useMemo(()=>Ke.filter(v=>v.lang).sort((v,je)=>{const Pe=v.lang.startsWith("en"),Le=je.lang.startsWith("en");if(Pe&&!Le)return-1;if(!Pe&&Le)return 1;const qe=v.lang.localeCompare(je.lang);return qe!==0?qe:v.name.localeCompare(je.name)}),[Ke]),ge=xe.useCallback(()=>{if(Re){Ir.cancelSpeech(),V(!1);return}const v=Ke.find(qe=>qe.name===I),je=v?.name??s("settings.voice.page.preview.browserVoiceFallback"),Pe=s("settings.voice.page.preview.voiceLine",{voiceName:je});V(!0);const Le=new SpeechSynthesisUtterance(Pe);Le.rate=r,Le.pitch=l,Le.volume=c,v&&(Le.voice=v,Le.lang=v.lang),Le.onend=()=>V(!1),Le.onerror=()=>V(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(Le)},[I,Ke,r,l,c,Re,s]);xe.useEffect(()=>()=>{Re&&Ir.cancelSpeech()},[Re]),xe.useEffect(()=>{if(!W||n!=="openai"&&n!=="openai-compatible"){Ae(j.trim().length>0);return}(async()=>{try{const Le=(await(await ct("/api/tts/status")).json()).available,qe=j.trim().length>0;Ae(Le||qe)}catch{Ae(j.trim().length>0)}})()},[j,W,n]),xe.useEffect(()=>{if(!W){de(!1),se([]);return}ct("/api/tts/say/status").then(v=>v.json()).then(v=>{if(de(v.available),v.voices){const je=v.voices.filter((Pe,Le,qe)=>qe.findIndex(rt=>rt.name===Pe.name)===Le).sort((Pe,Le)=>Pe.name.localeCompare(Le.name));se(je)}}).catch(()=>{de(!1)})},[W]);const Fe=xe.useCallback(async()=>{if(ee){Cs(ee),ie(null),G(!1);return}G(!0);let v=null;try{const je=await ct("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.voiceLine",{voiceName:m}),voice:m,rate:Math.round(100+(r-.5)*200)})});if(!je.ok)throw new Error("Preview failed");const Pe=await je.blob(),Le=URL.createObjectURL(Pe);v=new Audio(Le),v.onended=()=>{Cs(v),ie(null),G(!1)},v.onerror=()=>{Cs(v),ie(null),G(!1)},ie(v),await v.play()}catch{Cs(v),ie(null),G(!1)}},[m,r,ee,s]);xe.useEffect(()=>()=>{Cs(ee)},[ee]);const Ne=xe.useCallback(async()=>{if(Me){Cs(Me),Te(null),De(!1);return}De(!0);let v=null;try{const je=await ct("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.voiceLine",{voiceName:N}),voice:N,speed:r,apiKey:j||void 0})});if(!je.ok){const qe=await je.json().catch(()=>({error:"Unknown error"}));throw new Error(qe.error||`HTTP ${je.status}`)}const Pe=await je.blob(),Le=URL.createObjectURL(Pe);v=new Audio(Le),v.onended=()=>{Cs(v),Te(null),De(!1)},v.onerror=()=>{Cs(v),Te(null),De(!1)},Te(v),await v.play()}catch{Cs(v),Te(null),De(!1)}},[N,r,Me,j,s]);xe.useEffect(()=>()=>{Cs(Me)},[Me]);const He=xe.useCallback(async()=>{if(Oe){Cs(Oe),$e(null),ze(!1);return}if(!U.trim())return;ze(!0);let v=null;try{const je=await ct("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:s("settings.voice.page.preview.customServerLine"),voice:A,model:R||void 0,speed:r,baseURL:U,apiKey:M||void 0})});if(!je.ok){const qe=await je.json().catch(()=>({error:"Unknown error"}));throw new Error(qe.error||`HTTP ${je.status}`)}const Pe=await je.blob(),Le=URL.createObjectURL(Pe);v=new Audio(Le),v.onended=()=>{Cs(v),$e(null),ze(!1)},v.onerror=()=>{Cs(v),$e(null),ze(!1)},$e(v),await v.play()}catch{Cs(v),$e(null),ze(!1)}},[U,A,R,M,r,Oe,s]);xe.useEffect(()=>()=>{Cs(Oe)},[Oe]);const X="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return t.jsxs("div",{className:"space-y-8",children:[t.jsxs("div",{"data-settings-item":"voice.playback",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.voice.page.section.playbackAndSummary")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":W,onClick:()=>ye(!W),onKeyDown:v=>{(v.key===" "||v.key==="Enter")&&(v.preventDefault(),ye(!W))},children:[t.jsx(yt,{checked:W,onChange:ye,ariaLabel:s("settings.voice.page.field.messageReadAloudButtonAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.messageReadAloudButton")})]}),W&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.provider")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:t.jsxs("ul",{className:"space-y-1",children:[t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.browser")})," ",s("settings.voice.page.tooltip.browser")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.local")})," ",s("settings.voice.page.tooltip.localTts")]}),t.jsxs("li",{children:[t.jsx("strong",{children:"OpenAI:"})," ",s("settings.voice.page.tooltip.openai")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.custom")})," ",s("settings.voice.page.tooltip.custom")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.say")})," ",s("settings.voice.page.tooltip.say")]})]})})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(q,{variant:"chip",size:"xs","aria-pressed":n==="browser",onClick:()=>a("browser"),className:"!font-normal",children:s("settings.voice.page.provider.browser")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":n==="local",onClick:()=>a("local"),className:"!font-normal",children:s("settings.voice.page.provider.local")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":n==="openai",onClick:()=>a("openai"),className:"!font-normal",children:"OpenAI"}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":n==="openai-compatible",onClick:()=>a("openai-compatible"),className:"!font-normal",children:s("settings.voice.page.provider.custom")}),we&&t.jsxs(q,{variant:"chip",size:"xs","aria-pressed":n==="say",onClick:()=>a("say"),className:"!font-normal",children:[t.jsx(E,{name:"apple",className:"w-3.5 h-3.5 mr-0.5"}),s("settings.voice.page.provider.say")]})]})]})}),n==="openai"&&t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:ce("typography-ui-label text-foreground",!pe&&"text-[var(--status-error)]"),children:s("settings.voice.page.field.apiKey")}),t.jsx("span",{className:ce("typography-meta ml-2",pe?"text-muted-foreground":"text-[var(--status-error)]/80"),children:s(pe&&!j?"settings.voice.page.field.apiKeyHintUsingConfig":pe?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"password",value:j,onChange:v=>T(v.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"}),j&&t.jsx("button",{type:"button",onClick:()=>T(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(E,{name:"close",className:"w-3.5 h-3.5"})})]})]}),n==="openai-compatible"&&t.jsxs("div",{className:"py-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:ce("typography-ui-label text-foreground",!U.trim()&&"text-[var(--status-error)]"),children:s("settings.voice.page.field.serverUrl")}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:s("settings.voice.page.field.serverUrlHint")}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"text",value:U,onChange:v=>K(v.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"}),U&&t.jsx("button",{type:"button",onClick:()=>K(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(E,{name:"close",className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:"API Key"}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:"Optional"}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"password",value:M,onChange:v=>C(v.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),M&&t.jsx("button",{type:"button",onClick:()=>C(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(E,{name:"close",className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.model")}),t.jsx("div",{className:"relative mt-1.5 max-w-xs",children:t.jsx("input",{type:"text",value:R,onChange:v=>Q(v.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.voice")}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:s("settings.voice.page.field.voiceIdentifierHint")}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[t.jsx("div",{className:"relative max-w-xs flex-1",children:t.jsx("input",{type:"text",value:A,onChange:v=>z(v.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),t.jsx(q,{size:"xs",variant:"ghost",onClick:He,title:s("settings.voice.page.actions.preview"),disabled:!U.trim(),children:Be?t.jsx(E,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(E,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),n==="local"&&t.jsx(db,{}),t.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.voice")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[n==="local"&&t.jsxs(t.Fragment,{children:[t.jsxs(At,{value:String(u),onValueChange:v=>w(Number.parseInt(v,10)||0),children:[t.jsx(Dt,{className:"w-fit",children:t.jsx(Ot,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder"),children:v=>qr.find(je=>String(je.id)===v)?.label??v})}),t.jsx(Et,{children:qr.map(v=>t.jsx(mt,{value:String(v.id),children:v.label},v.id))})]}),t.jsx(q,{size:"xs",variant:"ghost",onClick:P,title:s("settings.voice.page.actions.preview"),children:x?t.jsx(E,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(E,{name:"play",className:"w-3.5 h-3.5"})}),D?t.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:D}):null]}),n==="openai"&&pe&&t.jsxs(t.Fragment,{children:[t.jsxs(At,{value:N,onValueChange:b,children:[t.jsx(Dt,{className:"w-fit",children:t.jsx(Ot,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Et,{children:ub.map(v=>t.jsx(mt,{value:v.value,children:v.label},v.value))})]}),t.jsx(q,{size:"xs",variant:"ghost",onClick:Ne,title:s("settings.voice.page.actions.preview"),children:Se?t.jsx(E,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(E,{name:"play",className:"w-3.5 h-3.5"})})]}),n==="openai-compatible"&&t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.voice.page.field.configuredAbove")}),n==="say"&&we&&Z.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(At,{value:m,onValueChange:p,children:[t.jsx(Dt,{className:"w-fit",children:t.jsx(Ot,{placeholder:s("settings.voice.page.field.selectVoicePlaceholder")})}),t.jsx(Et,{children:Z.map(v=>t.jsx(mt,{value:v.name,children:v.name},v.name))})]}),t.jsx(q,{size:"xs",variant:"ghost",onClick:Fe,title:s("settings.voice.page.actions.preview"),children:ve?t.jsx(E,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(E,{name:"play",className:"w-3.5 h-3.5"})})]}),n==="browser"&&oe.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs(At,{value:I||"$auto",onValueChange:v=>L(v==="$auto"?"":v),children:[t.jsx(Dt,{className:"w-fit max-w-[200px]",children:t.jsx(Ot,{placeholder:s("settings.voice.page.field.auto")})}),t.jsxs(Et,{children:[t.jsx(mt,{value:"$auto",children:s("settings.voice.page.field.auto")}),oe.map(v=>t.jsxs(mt,{value:v.name,children:[v.name," (",v.lang,")"]},v.name))]})]}),t.jsx(q,{size:"xs",variant:"ghost",onClick:ge,title:s("settings.voice.page.actions.preview"),children:Re?t.jsx(E,{name:"stop",className:"w-3.5 h-3.5"}):t.jsx(E,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),t.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.speechRate")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&t.jsx("input",{type:"range",min:.5,max:2,step:.1,value:r,onChange:v=>i(Number(v.target.value)),className:X}),t.jsx(xs,{value:r,onValueChange:i,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),t.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.speechPitch")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&t.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:v=>d(Number(v.target.value)),className:X}),t.jsx(xs,{value:l,onValueChange:d,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),t.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:s("settings.voice.page.field.speechVolume")}),t.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&t.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:v=>h(Number(v.target.value)),className:X}),e?t.jsx(xs,{value:Math.round(c*100),onValueChange:v=>h(v/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):t.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(c*100),"%"]})]})]}),t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.ttsInputMode")})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(q,{variant:"chip",size:"xs","aria-pressed":te==="sanitized",onClick:()=>Y("sanitized"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeSanitized")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":te==="raw",onClick:()=>Y("raw"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeRaw")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":te==="summarized",onClick:()=>Y("summarized"),className:"!font-normal",children:s("settings.voice.page.field.ttsInputModeSummarized")})]})]})})]})]})]}),t.jsxs("div",{"data-settings-item":"voice.speech-recognition",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.voice.page.section.speechRecognition")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ke,onClick:()=>he(!ke),onKeyDown:v=>{(v.key===" "||v.key==="Enter")&&(v.preventDefault(),he(!ke))},children:[t.jsx(yt,{checked:ke,onChange:he,ariaLabel:s("settings.voice.page.field.enableVoiceInputAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.enableVoiceInput")})]}),ke&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.provider")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:t.jsxs("ul",{className:"space-y-1",children:[t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.local")})," ",s("settings.voice.page.tooltip.sttLocal")]}),t.jsxs("li",{children:[t.jsx("strong",{children:s("settings.voice.page.provider.server")})," ",s("settings.voice.page.tooltip.sttServer")]})]})})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(q,{variant:"chip",size:"xs","aria-pressed":k==="local",onClick:()=>$("local"),className:"!font-normal",children:s("settings.voice.page.provider.local")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":k==="openai-compatible",onClick:()=>$("openai-compatible"),className:"!font-normal",children:s("settings.voice.page.provider.server")})]})]})}),k==="local"&&t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.model")}),t.jsx(cb,{selectedModelId:le,onSelect:ne})]}),k==="openai-compatible"&&t.jsxs("div",{className:"py-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("span",{className:ce("typography-ui-label text-foreground",!B.trim()&&"text-[var(--status-error)]"),children:s("settings.voice.page.field.serverUrl")}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:s("settings.voice.page.field.sttServerUrlHint")}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"text",value:B,onChange:v=>F(v.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),B&&t.jsx("button",{type:"button",onClick:()=>F(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(E,{name:"close",className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:"API Key"}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:"Optional"}),t.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[t.jsx("input",{type:"password",value:O,onChange:v=>J(v.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),O&&t.jsx("button",{type:"button",onClick:()=>J(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t.jsx(E,{name:"close",className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.model")}),t.jsx("div",{className:"relative mt-1.5 max-w-xs",children:t.jsx("input",{type:"text",value:H,onChange:v=>re(v.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),t.jsxs("div",{children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.voice.page.field.language")}),t.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:s("settings.voice.page.field.sttLanguageHint")}),t.jsx("div",{className:"relative mt-1.5 max-w-[8rem]",children:t.jsx("input",{type:"text",value:be,onChange:v=>ae(v.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"})})]})]})]})]})]})]})},Ua=[{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}],Ba=[{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}],pb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",gb="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Qr=[{value:"quick",labelKey:"settings.openchamber.tunnel.option.mode.quick.label",tooltipKey:"settings.openchamber.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.openchamber.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.openchamber.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedLocal.tooltip"}],hb=[".yml",".yaml",".json"],fb="settings.openchamber.tunnel.error.invalidConfigExtension",ha=s=>{const e=s.trim().toLowerCase();return hb.some(n=>e.endsWith(n))},xb=s=>s==="ngrok"?"ngrok":"cloudflared",Hc=()=>{if(typeof window<"u"&&typeof window.__OPENCHAMBER_PLATFORM__=="string"){const e=window.__OPENCHAMBER_PLATFORM__;if(e==="win32"||e==="darwin"||e==="linux")return e}const s=typeof navigator<"u"?`${navigator.platform||""} ${navigator.userAgent||""}`.toLowerCase():"";return s.includes("win")?"win32":s.includes("mac")?"darwin":"linux"},yb=(s,e=Hc())=>s==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/",Yr=(s,e)=>{const n=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():s,a=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():xb(n),r=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Hc(),i=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():yb(n,r);return{provider:n,dependency:a,installCommand:i}},Wc=s=>s==="cloudflare"?"Cloudflare":s==="ngrok"?"Ngrok":s,Tl=s=>{const e=et.c(11),{provider:n}=s;let a;e[0]!==n?(a=Wc(n),e[0]=n,e[1]=a):a=e[1];const r=a,d=n==="cloudflare"||n==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==d?(c=ce("size-4 shrink-0",d),e[2]=d,e[3]=c):c=e[3];let h;e[4]!==c?(h=t.jsx(E,{name:"cloud",className:c}),e[4]=c,e[5]=h):h=e[5];let m;e[6]!==r?(m=t.jsx("span",{children:r}),e[6]=r,e[7]=m):m=e[7];let p;return e[8]!==h||e[9]!==m?(p=t.jsxs("span",{className:"flex items-center gap-2",children:[h,m]}),e[8]=h,e[9]=m,e[10]=p):p=e[10],p},hn=s=>s==="quick"?"quick":s==="managed-remote"?"managed-remote":s==="managed-local"?"managed-local":"quick",Ni=(s,e,n)=>s.find(r=>r.ms===e)?.value||n,Rl=(s,e,n)=>{const a=Ni(s,e,n);return s.find(r=>r.value===a)?.label||a},Fl=s=>{const e=Math.max(0,s),n=Math.floor(e/1e3),a=Math.floor(n/3600),r=Math.floor(n%3600/60),i=n%60;return a>0?`${a}h ${r}m`:r>0?`${r}m ${i}s`:`${i}s`},bb=(s,e)=>pc(s,e,{hour:"2-digit",precision:"second"}),Za=s=>{const e=s.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},vb=s=>{if(!Array.isArray(s))return[];const e=new Set,n=new Set,a=[];for(const r of s){if(!r||typeof r!="object")continue;const i=r,l=typeof i.id=="string"?i.id.trim():"",d=typeof i.name=="string"?i.name.trim():"",c=Za(typeof i.hostname=="string"?i.hostname:"");!l||!d||!c||e.has(l)||n.has(c)||(e.add(l),n.add(c),a.push({id:l,name:d,hostname:c}))}return a},jb=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,wb=()=>{const{t:s}=st(),e=Ie(ue=>ue.timeFormatPreference),n=o.useCallback(ue=>s(ue),[s]),[a,r]=o.useState("checking"),[i,l]=o.useState(null),[d,c]=o.useState(null),[h,m]=o.useState(null),[p,u]=o.useState(null),[w,g]=o.useState(null),[f,x]=o.useState(!1),[D,P]=o.useState(!1),[I,L]=o.useState(!1),[N,b]=o.useState("cloudflare"),[j,T]=o.useState(()=>Yr("cloudflare")),[U,K]=o.useState([]),[M,C]=o.useState("quick"),[A,z]=o.useState(null),[R,Q]=o.useState([]),[W,te]=o.useState({}),[Y,k]=o.useState(""),[$,B]=o.useState({}),[F,O]=o.useState(new Set),[J,H]=o.useState(!1),[re,le]=o.useState(""),[ne,be]=o.useState(""),[ae,ye]=o.useState(""),[ke,he]=o.useState(1800*1e3),[we,de]=o.useState(480*60*1e3),[Z,se]=o.useState(""),[ve,G]=o.useState([]),[ee,ie]=o.useState(()=>Date.now()),[pe,Ae]=o.useState(null),Se=s(fb),De=o.useRef(null),Me=o.useMemo(()=>A?!ha(A):!1,[A]),Te=o.useMemo(()=>R.find(ue=>ue.id===Y)||R[0]||null,[R,Y]),Be=o.useMemo(()=>ve.map(ue=>{const Ve=ue.expiresAt<=ee,Qe=ue.status==="active"&&!Ve,Ge=Qe?Fl(ue.expiresAt-ee):ue.inactiveReason==="expired"||Ve?"expired":"inactive",xt=Ge==="expired"?s("settings.openchamber.tunnel.state.expired"):ue.inactiveReason==="tunnel-revoked"?s("settings.openchamber.tunnel.state.revoked"):s("settings.openchamber.tunnel.state.inactive"),kt=hn(ue.mode);return{...ue,isActive:Qe,mode:kt,remainingTextForSession:Ge,inactiveLabel:xt}}),[ee,ve,s]),ze=o.useMemo(()=>i?.connectUrl?i.bootstrapExpiresAt===null?!0:i.bootstrapExpiresAt>ee:!1,[ee,i?.bootstrapExpiresAt,i?.connectUrl]),Oe=o.useMemo(()=>!i||a!=="active"&&a!=="stopping"?!1:d===M,[d,a,i,M]),$e=o.useMemo(()=>!i||a!=="active"||!d?!1:d!==M,[d,a,i,M]),Ke=o.useMemo(()=>{if(typeof pe=="number"&&Number.isFinite(pe)&&pe>0)return pe;if(typeof window>"u")return null;const Ve=sa()||window.location.href;let Qe=0;try{Qe=Number(new URL(Ve).port)}catch{Qe=Number(window.location.port)}return Number.isFinite(Qe)&&Qe>0?Qe:null},[pe]),Ye=o.useMemo(()=>U.find(ue=>ue.provider===N)??null,[U,N]),Re=o.useMemo(()=>{const ue=new Set(Ye?.modes?.map(Ve=>Ve.key).filter(Ve=>Ve==="quick"||Ve==="managed-remote"||Ve==="managed-local"));return ue.size===0?Qr:Qr.filter(Ve=>ue.has(Ve.value))},[Ye]),V=o.useMemo(()=>Re.some(ue=>ue.value==="managed-remote"||ue.value==="managed-local"),[Re]),oe=o.useMemo(()=>j.provider===N?j:Yr(N),[j,N]),ge=o.useCallback(async ue=>{await tn(ue)},[]),Fe=o.useCallback((ue,Ve)=>(T(Yr(Ve,ue)),ue.available===!0),[]),Ne=o.useCallback(async(ue,Ve)=>{try{const Qe=await ct("/api/openchamber/tunnel/check",{query:{provider:ue},...Ve?{signal:Ve}:{}});if(!Qe.ok)return null;const Ge=await Qe.json();if(Ve?.aborted)return null;const xt=Fe(Ge,ue);return r(kt=>kt==="checking"||kt==="starting"||kt==="active"||kt==="stopping"?kt:xt?"idle":"not-available"),xt}catch{return null}},[Fe]),He=o.useCallback(async ue=>{try{const[Ve,Qe,Ge,xt]=await Promise.all([ct("/api/openchamber/tunnel/check",{signal:ue}),ct("/api/openchamber/tunnel/status",{signal:ue}),ct("/api/config/settings",{signal:ue,headers:{Accept:"application/json"}}),ct("/api/openchamber/tunnel/providers",{signal:ue})]),kt=await Ve.json(),ht=await Qe.json(),Pt=Ge.ok?await Ge.json():{},Wt=xt.ok?await xt.json():{},ts=ht.ttlConfig?.bootstrapTtlMs??(Pt?.tunnelBootstrapTtlMs===null?null:typeof Pt?.tunnelBootstrapTtlMs=="number"?Pt.tunnelBootstrapTtlMs:1800*1e3),bs=typeof ht.ttlConfig?.sessionTtlMs=="number"?ht.ttlConfig.sessionTtlMs:typeof Pt?.tunnelSessionTtlMs=="number"?Pt.tunnelSessionTtlMs:480*60*1e3,ks=hn(ht.mode??Pt?.tunnelMode),Yt=typeof Pt?.tunnelProvider=="string"&&Pt.tunnelProvider.trim().length>0?Pt.tunnelProvider.trim().toLowerCase():"cloudflare",Ss=typeof Pt?.managedLocalTunnelConfigPath=="string"&&Pt.managedLocalTunnelConfigPath.trim()||null,Ce=Fe(kt,Yt),jt=vb(ht?.managedRemoteTunnelPresets),vt=typeof ht.managedRemoteTunnelHostname=="string"?ht.managedRemoteTunnelHostname:"",Ht=jt.length>0?jt:vt?[{id:`legacy-${Za(vt)}`,name:vt,hostname:Za(vt)}]:[],qt=Ht[0]?.id||"";if(he(ts),de(bs),b(Yt),K(Array.isArray(Wt?.providers)?Wt.providers:[]),C(ks),z(Ss),Q(Ht),k(qt),G(Array.isArray(ht.activeSessions)?ht.activeSessions:[]),c(ht.activeTunnelMode?hn(ht.activeTunnelMode):ht.active&&ht.mode?hn(ht.mode):null),O(new Set(Array.isArray(ht.managedRemoteTunnelTokenPresetIds)?ht.managedRemoteTunnelTokenPresetIds:[])),Ae(typeof ht.localPort=="number"?ht.localPort:null),ht.active&&ht.url){l({url:ht.url,connectUrl:null,bootstrapExpiresAt:typeof ht.bootstrapExpiresAt=="number"?ht.bootstrapExpiresAt:null}),r("active");return}r(Ce?"idle":"not-available")}catch{ue.aborted||(r("error"),u(s("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Fe,s]);o.useEffect(()=>{const ue=new AbortController;return He(ue.signal),()=>ue.abort()},[He]),o.useEffect(()=>{if(!i?.connectUrl){m(null);return}let ue=!1;return sc.toDataURL(i.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Ve=>{ue||m(Ve)}).catch(()=>{ue||m(null)}),()=>{ue=!0}},[i?.connectUrl]),o.useEffect(()=>{if(!i?.bootstrapExpiresAt){se(s("settings.openchamber.tunnel.state.noExpiry"));return}let ue=null,Ve=Date.now();const Qe=()=>{const kt=i.bootstrapExpiresAt?i.bootstrapExpiresAt-Date.now():0;kt<=0?se(s("settings.openchamber.tunnel.state.expired")):se(Fl(kt))},Ge=()=>{const kt=Date.now();kt-Ve>=1e3&&(Qe(),Ve=kt),ue=requestAnimationFrame(Ge)};Qe(),(typeof document>"u"||document.visibilityState==="visible")&&(ue=requestAnimationFrame(Ge));const xt=()=>{document.visibilityState==="visible"&&ue===null?ue=requestAnimationFrame(Ge):document.visibilityState!=="visible"&&ue!==null&&(cancelAnimationFrame(ue),ue=null)};return document.addEventListener("visibilitychange",xt),()=>{document.removeEventListener("visibilitychange",xt),ue!==null&&cancelAnimationFrame(ue)}},[s,i?.bootstrapExpiresAt]),o.useEffect(()=>{let ue=null,Ve=Date.now();const Qe=()=>{const xt=Date.now();xt-Ve>=1e3&&(ie(xt),Ve=xt),ue=requestAnimationFrame(Qe)};(typeof document>"u"||document.visibilityState==="visible")&&(ue=requestAnimationFrame(Qe));const Ge=()=>{document.visibilityState==="visible"&&ue===null?ue=requestAnimationFrame(Qe):document.visibilityState!=="visible"&&ue!==null&&(cancelAnimationFrame(ue),ue=null)};return document.addEventListener("visibilitychange",Ge),()=>{document.removeEventListener("visibilitychange",Ge),ue!==null&&cancelAnimationFrame(ue)}},[]),o.useEffect(()=>{if(a==="starting"||a==="stopping"||a==="checking")return;let ue=!1;const Ve=async()=>{try{const Ge=await ct("/api/openchamber/tunnel/status");if(!Ge.ok||ue)return;const xt=await Ge.json();if(ue)return;G(Array.isArray(xt.activeSessions)?xt.activeSessions:[]),O(new Set(Array.isArray(xt.managedRemoteTunnelTokenPresetIds)?xt.managedRemoteTunnelTokenPresetIds:[])),Ae(typeof xt.localPort=="number"?xt.localPort:null)}catch{}},Qe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ve()},5e3);return()=>{ue=!0,window.clearInterval(Qe)}},[a]);const X=o.useCallback(async ue=>{L(!0);try{await Nt(ue),Object.prototype.hasOwnProperty.call(ue,"tunnelMode")&&ue.tunnelMode&&C(ue.tunnelMode),Object.prototype.hasOwnProperty.call(ue,"tunnelProvider")&&typeof ue.tunnelProvider=="string"&&b(ue.tunnelProvider),Object.prototype.hasOwnProperty.call(ue,"managedLocalTunnelConfigPath")&&z(ue.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ue,"managedRemoteTunnelPresets")&&ue.managedRemoteTunnelPresets&&Q(ue.managedRemoteTunnelPresets)}catch{_.error(s("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{L(!1)}},[s]),v=o.useCallback(async(ue,Ve)=>{P(!0);try{await Nt({tunnelBootstrapTtlMs:ue,tunnelSessionTtlMs:Ve})}catch{_.error(s("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{P(!1)}},[s]),je=o.useCallback(async ue=>{const Ve=ue.token.trim();if(Ve)try{const Qe={...$,[ue.presetId]:Ve};await Nt({managedRemoteTunnelPresetTokens:Qe}),O(Ge=>{const xt=new Set(Ge);return xt.add(ue.presetId),xt})}catch{_.error(s("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[$,s]),Pe=o.useCallback(async ue=>{g(null),u(null);const Ve=U.find(Ge=>Ge.provider===ue),Qe=Ve?.modes?.some(Ge=>Ge.key===M)?M:hn(Ve?.modes?.[0]?.key);await X({tunnelProvider:ue,tunnelMode:Qe}),Ne(ue)},[U,Ne,X,M]),Le=o.useCallback(async()=>{const ue=await xc({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ue.success&&typeof ue.path=="string"&&ue.path.trim().length>0){const Ve=ue.path.trim();if(!ha(Ve)){_.error(Se);return}z(Ve),await X({managedLocalTunnelConfigPath:Ve});return}De.current?.click()},[Se,X]),qe=o.useCallback(ue=>{const Ve=ue.trim();z(Ve.length>0?Ve:null)},[]),rt=o.useCallback(async()=>{if(A&&!ha(A)){_.error(Se);return}await X({managedLocalTunnelConfigPath:A})},[Se,A,X]),ot=o.useCallback(async()=>{z(null),await X({managedLocalTunnelConfigPath:null})},[X]),it=o.useCallback(async ue=>{const Ve=ue.target.files?.[0];if(!Ve)return;const Qe=Ve.name.trim();if(Qe.length!==0){if(!ha(Qe)){_.error(Se);return}z(Qe),await X({managedLocalTunnelConfigPath:Qe}),ue.target.value=""}},[Se,X]),dt=o.useCallback(async()=>{if(u(null),g(null),M==="managed-local"&&A&&!ha(A)){u(Se),_.error(Se);return}r("starting");try{let ue="",Ve="";if(M==="managed-remote"){if(!Te){r("idle"),g(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),_.error(s("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}ue=Te.hostname,Ve=($[Te.id]||"").trim(),await X({tunnelMode:"managed-remote",managedRemoteTunnelPresets:R})}const Qe=await ct("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:N,mode:M,...M==="managed-remote"&&Te?{managedRemoteTunnelPresetId:Te.id,managedRemoteTunnelPresetName:Te.name}:{},...M==="managed-remote"&&ue?{managedRemoteTunnelHostname:ue}:{},...M==="managed-remote"&&Ve?{managedRemoteTunnelToken:Ve}:{},...M==="managed-local"&&A?{configPath:A}:{}})}),Ge=await Qe.json();if(!Qe.ok||!Ge.ok){if(M==="managed-remote"&&typeof Ge.error=="string"&&Ge.error.includes("Managed remote tunnel token is required")){r("idle"),g(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),_.error(s("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(Ge.error||s("settings.openchamber.tunnel.toast.startFailed")),_.error(Ge.error||s("settings.openchamber.tunnel.toast.startFailed"));return}const xt=typeof Ge.url=="string"?Ge.url:"";if(!xt){r("error"),u(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),_.error(s("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:xt,connectUrl:typeof Ge.connectUrl=="string"?Ge.connectUrl:null,bootstrapExpiresAt:typeof Ge.bootstrapExpiresAt=="number"?Ge.bootstrapExpiresAt:null}),c(Ge.activeTunnelMode?hn(Ge.activeTunnelMode):Ge.mode?hn(Ge.mode):M),G(Array.isArray(Ge.activeSessions)?Ge.activeSessions:[]),Array.isArray(Ge.managedRemoteTunnelTokenPresetIds)&&O(new Set(Ge.managedRemoteTunnelTokenPresetIds)),typeof Ge.localPort=="number"&&Ae(Ge.localPort),typeof Ge.mode=="string"&&C(hn(Ge.mode)),r("active"),Ge.replacedTunnel){const kt=typeof Ge.revokedBootstrapCount=="number"?Ge.revokedBootstrapCount:0,ht=typeof Ge.invalidatedSessionCount=="number"?Ge.invalidatedSessionCount:0;kt===1&&ht===1?_.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):kt===1?_.warning(s("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ht})):ht===1?_.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:kt})):_.warning(s("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:kt,invalidatedSessionCount:ht}))}else _.success(s("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(s("settings.openchamber.tunnel.toast.startFailed")),_.error(s("settings.openchamber.tunnel.toast.startFailed"))}},[Se,R,X,Te,$,s,N,M,A]),Je=o.useCallback(async()=>{r("stopping");try{await ct("/api/openchamber/tunnel/stop",{method:"POST"});const ue=await ct("/api/openchamber/tunnel/status");if(ue.ok){const Ve=await ue.json();G(Array.isArray(Ve.activeSessions)?Ve.activeSessions:[]),O(new Set(Array.isArray(Ve.managedRemoteTunnelTokenPresetIds)?Ve.managedRemoteTunnelTokenPresetIds:[])),Ae(typeof Ve.localPort=="number"?Ve.localPort:null)}l(null),c(null),m(null),r("idle"),_.success(s("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(s("settings.openchamber.tunnel.toast.stopFailed")),_.error(s("settings.openchamber.tunnel.toast.stopFailed"))}},[s]),_e=o.useCallback(async()=>{if(i?.connectUrl)try{await navigator.clipboard.writeText(i.connectUrl),x(!0),_.success(s("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>x(!1),2e3)}catch{_.error(s("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[s,i?.connectUrl]),gt=o.useCallback(async ue=>{const Ve=Ua.find(Qe=>Qe.value===ue);Ve&&(he(Ve.ms),await v(Ve.ms,we))},[v,we]),fe=o.useCallback(async ue=>{const Ve=Ba.find(Qe=>Qe.value===ue);!Ve||Ve.ms===null||(de(Ve.ms),await v(ke,Ve.ms))},[ke,v]),tt=o.useCallback(async ue=>{g(null),u(null),a!=="active"&&a!=="stopping"&&a!=="starting"&&r("idle"),await X({tunnelMode:ue,managedRemoteTunnelPresets:R})},[R,X,a]),nt=o.useCallback(async(ue,Ve)=>{try{await Nt({managedRemoteTunnelPresets:Ve})}catch{_.error(s("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[s]),Ze=o.useCallback(ue=>{const Ve=R.find(Qe=>Qe.id===ue);Ve&&(k(Ve.id),g(null),nt(Ve,R))},[R,nt]),ft=o.useCallback(async()=>{const ue=re.trim(),Ve=Za(ne),Qe=ae.trim();if(!ue){_.error(s("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Ve){_.error(s("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Qe){_.error(s("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(R.some(kt=>kt.hostname===Ve)){_.error(s("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ge={id:jb(),name:ue,hostname:Ve},xt=[...R,Ge];Q(xt),k(Ge.id),te(kt=>({...kt,[Ge.id]:!0})),B(kt=>({...kt,[Ge.id]:Qe})),g(null),H(!1),le(""),be(""),ye(""),await X({tunnelMode:"managed-remote",managedRemoteTunnelPresets:xt,managedRemoteTunnelPresetTokens:{...$,[Ge.id]:Qe}}),await je({presetId:Ge.id,presetName:Ge.name,hostname:Ge.hostname,token:Qe}),_.success(s("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[R,ne,re,ae,je,X,$,s]),bt=o.useCallback(async ue=>{const Ve=R.find(ht=>ht.id===ue);if(!Ve)return;const Qe=R.filter(ht=>ht.id!==Ve.id),Ge=Qe[0]?.id||"",xt=Y===Ve.id?Ge:Y,kt=Object.fromEntries(Object.entries($).filter(([ht,Pt])=>ht!==Ve.id&&Pt.trim().length>0));Q(Qe),k(xt),te(ht=>{const Pt={...ht};return delete Pt[Ve.id],Pt}),B(ht=>{const Pt={...ht};return delete Pt[Ve.id],Pt}),O(ht=>{const Pt=new Set(ht);return Pt.delete(Ve.id),Pt}),g(null),await X({managedRemoteTunnelPresets:Qe,managedRemoteTunnelPresetTokens:kt}),_.success(s("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[R,X,Y,$,s]),Mt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return a==="checking"?t.jsx("div",{className:"flex items-center justify-center py-12",children:t.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":s("settings.openchamber.tunnel.state.loading")})}):t.jsxs("div",{className:"space-y-6",children:[t.jsxs("div",{children:[t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.openchamber.tunnel.title")}),t.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/70",children:s("settings.openchamber.tunnel.description")}),t.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:s("settings.openchamber.tunnel.note.serverSideEnforced")}),t.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:s("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),Be.length>0&&t.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:t.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[t.jsx(E,{name:"information",className:"size-4 text-[var(--status-info)]"}),t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),t.jsx("div",{className:"space-y-1",children:Be.map(ue=>{const Ve=ue.mode==="quick",Qe=ue.mode==="managed-remote",Ge=Ve?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Qe?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",xt=ue.isActive?Ve?"text-[var(--status-warning)]":Qe?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",kt=s(Ve?"settings.openchamber.tunnel.badge.quick":Qe?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[t.jsx(E,{name:"checkbox-blank-circle-fill",className:ce("size-2.5 shrink-0",xt)}),t.jsx("span",{className:ce("typography-micro rounded border px-1.5 py-0.5 uppercase",Ge),children:kt}),t.jsx("span",{className:"typography-meta text-muted-foreground/80",children:s("settings.openchamber.tunnel.session.redeemedAt",{time:bb(ue.createdAt,e)})}),t.jsx("span",{className:"typography-meta text-foreground",children:ue.isActive?s("settings.openchamber.tunnel.session.expiresIn",{remaining:ue.remainingTextForSession}):ue.inactiveLabel===s("settings.openchamber.tunnel.state.inactive")?s("settings.openchamber.tunnel.state.inactive"):s("settings.openchamber.tunnel.session.inactiveWithReason",{reason:ue.inactiveLabel})})]},ue.sessionId)})})]})}),a==="not-available"&&t.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:t.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[t.jsx(E,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"typography-meta font-medium text-foreground",children:s("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:oe.dependency})}),t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.openchamber.tunnel.notAvailable.installHint")}),t.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:oe.installCommand})]})]})}),t.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{"data-settings-item":"tunnel.provider",className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.field.provider")}),t.jsxs(At,{value:N,onValueChange:ue=>{Pe(ue)},disabled:I||a==="starting"||a==="stopping",children:[t.jsx(Dt,{className:"max-w-[16rem]",children:t.jsx(Ot,{placeholder:s("settings.openchamber.tunnel.field.providerPlaceholder"),children:Wc(N)})}),t.jsxs(Et,{children:[U.length>0?U.map(ue=>t.jsx(mt,{value:ue.provider,children:t.jsx(Tl,{provider:ue.provider})},ue.provider)):t.jsx(mt,{value:"cloudflare",children:t.jsx(Tl,{provider:"cloudflare"})}),t.jsx(mt,{value:"__more-soon",disabled:!0,children:s("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),t.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.field.tunnelType")}),t.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Re.map(ue=>t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(q,{variant:"chip",size:"xs","aria-pressed":M===ue.value,className:"!font-normal",onClick:()=>{tt(ue.value)},disabled:I||a==="starting"||a==="stopping",children:n(ue.labelKey)})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:n(ue.tooltipKey)})]},ue.value))})]})]}),t.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:s("settings.openchamber.tunnel.field.connectLinkTtl")}),t.jsxs(At,{value:Ni(Ua,ke,"1800000"),onValueChange:ue=>{gt(ue)},disabled:D||I||a==="starting"||a==="stopping",children:[t.jsx(Dt,{className:"max-w-[11rem] min-w-0",children:t.jsx(Ot,{className:"truncate",children:Rl(Ua,ke,"1800000")})}),t.jsx(Et,{children:Ua.map(ue=>t.jsx(mt,{value:ue.value,children:ue.label},ue.value))})]})]}),t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:s("settings.openchamber.tunnel.field.tunnelSessionTtl")}),t.jsxs(At,{value:Ni(Ba,we,"28800000"),onValueChange:ue=>{fe(ue)},disabled:D||I||a==="starting"||a==="stopping",children:[t.jsx(Dt,{className:"max-w-[11rem] min-w-0",children:t.jsx(Ot,{className:"truncate",children:Rl(Ba,we,"28800000")})}),t.jsx(Et,{children:Ba.map(ue=>t.jsx(mt,{value:ue.value,children:ue.label},ue.value))})]})]})]}),M==="quick"&&t.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(E,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),t.jsxs("div",{children:[t.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:s("settings.openchamber.tunnel.option.mode.quick.tooltip")}),V&&t.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:s("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),M==="managed-remote"&&t.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Ke=="number"&&t.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:t.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[s("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",t.jsxs("code",{children:["http://localhost:",Ke]})]})}),t.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),t.jsxs(q,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>H(ue=>!ue),disabled:a==="starting"||a==="stopping"||I,children:[t.jsx(E,{name:"add",className:"h-3.5 w-3.5"}),s("settings.common.actions.create")]})]}),R.length>0?t.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:R.map((ue,Ve)=>{const Qe=$[ue.id]||"",Ge=F.has(ue.id),xt=W[ue.id]??!1;return t.jsx("div",{className:ce(Ve<R.length-1&&"border-b border-[var(--surface-subtle)]"),children:t.jsxs(Mn,{open:xt,onOpenChange:kt=>{te(ht=>({...ht,[ue.id]:kt})),kt&&Ze(ue.id)},className:"py-1.5",children:[t.jsxs("div",{className:"flex items-start gap-2 px-3",children:[t.jsxs(Tn,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:a==="starting"||a==="stopping"||I,children:[xt?t.jsx(E,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):t.jsx(E,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),t.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:ue.name})]}),t.jsx(q,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":s("settings.openchamber.tunnel.actions.removePresetAria",{name:ue.name}),onClick:()=>{bt(ue.id)},disabled:a==="starting"||a==="stopping"||I,children:t.jsx(E,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsx(Rn,{className:"pt-1.5",children:t.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[t.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[s("settings.openchamber.tunnel.field.hostnameLabel")," ",t.jsx("code",{children:ue.hostname})]}),t.jsx(Xe,{type:"password",value:Qe,onChange:kt=>{const ht=kt.target.value;g(null),B(Pt=>({...Pt,[ue.id]:ht}))},onBlur:kt=>{const ht=kt.currentTarget.value.trim();ht&&je({presetId:ue.id,presetName:ue.name,hostname:ue.hostname,token:ht})},placeholder:s(Ge?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:a==="starting"||a==="stopping"}),t.jsx("div",{className:"flex items-center justify-end",children:t.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal",disabled:a==="starting"||a==="stopping"||Qe.trim().length===0,onClick:()=>{je({presetId:ue.id,presetName:ue.name,hostname:ue.hostname,token:Qe})},children:s("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},ue.id)})}):t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),J&&t.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[t.jsx(Xe,{value:re,onChange:ue=>le(ue.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:I||a==="starting"||a==="stopping"}),t.jsx(Xe,{value:ne,onChange:ue=>be(ue.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:I||a==="starting"||a==="stopping"}),t.jsx(Xe,{type:"password",value:ae,onChange:ue=>ye(ue.target.value),placeholder:s("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:I||a==="starting"||a==="stopping"}),typeof Ke=="number"&&t.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[s("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",t.jsxs("code",{children:["http://localhost:",Ke]}),"."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ft()},disabled:I||a==="starting"||a==="stopping",children:s("settings.common.actions.saveChanges")}),t.jsx(q,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{H(!1),le(""),be(""),ye("")},disabled:I||a==="starting"||a==="stopping",children:s("settings.common.actions.cancel")})]})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("p",{className:"typography-meta text-muted-foreground/80",children:s("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground/70 hover:text-foreground","aria-label":s("settings.openchamber.tunnel.field.managedRemoteTokenInfoAria"),children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(It,{sideOffset:8,className:"max-w-xs",children:s("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!Te&&w&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:w})]}),M==="managed-local"&&t.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.field.configurationFile")}),t.jsx("input",{ref:De,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:ue=>{it(ue)}}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Xe,{value:A||"",onChange:ue=>{qe(ue.target.value)},onBlur:()=>{rt()},placeholder:s("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:a==="starting"||a==="stopping"||I}),t.jsx(q,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Le()},disabled:a==="starting"||a==="stopping"||I,children:t.jsx(E,{name:"folder",className:"size-3.5"})}),A&&t.jsx(q,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{ot()},disabled:a==="starting"||a==="stopping"||I,children:t.jsx(E,{name:"close",className:"size-3.5"})})]}),t.jsx("p",{className:"typography-meta text-muted-foreground/70",children:s(A?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Me&&t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Se})]})}),!Oe&&t.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[t.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(E,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),t.jsxs("div",{className:"space-y-1",children:[M==="managed-remote"&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:s("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),t.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{ge(pb)},children:[s("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),t.jsx(E,{name:"external-link",className:"size-3.5"})]})]}),M==="managed-local"&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:s("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),t.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{ge(gb)},children:[s("settings.openchamber.tunnel.actions.openManagedLocalDocs"),t.jsx(E,{name:"external-link",className:"size-3.5"})]})]}),t.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:s("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:n(Qr.find(ue=>ue.value===M)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),M==="managed-remote"&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),t.jsxs(At,{value:Y||(R[0]?.id??""),onValueChange:ue=>{Ze(ue)},disabled:I||a==="starting"||a==="stopping"||R.length<=1,children:[t.jsx(Dt,{children:t.jsx(Ot,{placeholder:s("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Te?.name})}),t.jsx(Et,{fitContent:!0,children:R.map(ue=>t.jsx(mt,{value:ue.id,children:ue.name},ue.id))})]})]}),$e&&t.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(E,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),t.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:s("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),t.jsx(q,{size:"sm",variant:"outline",onClick:dt,disabled:a==="starting"||I||M==="managed-remote"&&!Te||M==="managed-local"&&Me,className:ce(Mt,a==="starting"&&"opacity-70"),children:a==="starting"?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"loader-4",className:"size-3.5 animate-spin"})," ",s("settings.openchamber.tunnel.actions.startingTunnel")]}):s("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Oe&&i&&t.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),t.jsx("p",{className:"typography-meta font-medium text-foreground",children:s("settings.openchamber.tunnel.state.tunnelReady")})]}),t.jsxs("div",{children:[t.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:s("settings.openchamber.tunnel.field.publicUrlHint")}),t.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.url})]}),ze&&i.connectUrl&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:s("settings.openchamber.tunnel.field.connectLink")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:i.connectUrl}),t.jsxs(q,{size:"sm",variant:"ghost",onClick:_e,className:"shrink-0 gap-1.5",children:[f?t.jsx(E,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):t.jsx(E,{name:"file-copy",className:"size-3.5"}),s(f?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),t.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[s("settings.openchamber.tunnel.field.expires"),": ",i.bootstrapExpiresAt?Z:s("settings.openchamber.tunnel.state.never")]})]}),t.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[h?t.jsx("img",{src:h,alt:s("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):t.jsx("div",{className:"size-48 rounded bg-muted/30"}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),t.jsx("div",{className:"pt-1",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(q,{size:"sm",variant:"outline",onClick:dt,disabled:a==="stopping"||I||M==="managed-local"&&Me,className:Mt,children:[t.jsx(E,{name:"restart",className:"size-3.5"}),s("settings.openchamber.tunnel.actions.newConnectLink")]}),t.jsx(q,{size:"sm",variant:"ghost",onClick:Je,disabled:a==="stopping"||I,className:"gap-2 text-[var(--status-error)]",children:a==="stopping"?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"loader-4",className:"size-3.5 animate-spin"})," ",s("settings.openchamber.tunnel.actions.stopping")]}):s("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),a==="error"&&p&&t.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:p}),t.jsx(q,{size:"sm",variant:"ghost",onClick:dt,children:s("settings.openchamber.tunnel.actions.retry")})]})]})},Gc=()=>{const{t:s}=st(),[e,n]=xe.useState(""),[a,r]=xe.useState(!0),[i,l]=xe.useState(!1),d=Ie(u=>u.showOpenCodeUpdateNotifications),c=Ie(u=>u.setShowOpenCodeUpdateNotifications);xe.useEffect(()=>{let u=!1;return(async()=>{try{const w=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!w.ok)return;const g=await w.json().catch(()=>null);if(u||!g)return;const f=typeof g.opencodeBinary=="string"?g.opencodeBinary.trim():"";n(f)}catch{}finally{u||r(!1)}})(),()=>{u=!0}},[]);const h=xe.useCallback(async()=>{if(!(typeof window>"u")&&ns())try{const u=await xc();u.success&&u.path&&u.path.trim().length>0&&n(u.path.trim())}catch{}},[]),m=xe.useCallback(async()=>{l(!0);try{const u=e.trim(),w=u.length>=2&&(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))?u.slice(1,-1).trim():u;await Nt({opencodeBinary:w}),await Jn({message:s("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{l(!1)}},[s,e]),p=xe.useCallback(u=>{c(u),Nt({showOpenCodeUpdateNotifications:u})},[c]);return t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.opencodeCli.title")}),t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsxs(It,{sideOffset:8,className:"max-w-xs",children:[s("settings.openchamber.opencodeCli.tooltipPrefix")," ",t.jsx("code",{className:"font-mono text-xs",children:"opencode"}),s("settings.openchamber.opencodeCli.tooltipSuffix")]})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[t.jsxs("div",{"data-settings-item":"sessions.opencode-binary",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-3",children:[t.jsx("div",{className:"flex min-w-0 flex-col shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.opencodeCli.field.binaryPath")})}),t.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:w-[20rem]",children:[t.jsx(Xe,{value:e,onChange:u=>n(u.target.value),placeholder:s("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:a||i,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),t.jsx(q,{type:"button",variant:"outline",size:"xs",onClick:h,disabled:a||i||!ns(),className:"h-7 w-7 p-0","aria-label":s("settings.openchamber.opencodeCli.actions.browseAria"),title:s("settings.openchamber.opencodeCli.actions.browse"),children:t.jsx(E,{name:"folder",className:"h-4 w-4"})})]})]}),t.jsx("div",{className:"py-1.5",children:t.jsxs("div",{className:"typography-micro text-muted-foreground/70",children:[s("settings.openchamber.opencodeCli.tipPrefix")," ",t.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",s("settings.openchamber.opencodeCli.tipMiddle")," ",t.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]})}),t.jsxs("label",{"data-settings-item":"sessions.opencode-update-notifications",className:"flex cursor-pointer items-center gap-2 py-1.5",children:[t.jsx(yt,{checked:d,onChange:p,ariaLabel:s("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.opencodeCli.field.showUpdateNotifications")})]}),t.jsx("div",{className:"flex justify-start py-1.5",children:t.jsx(q,{type:"button",size:"xs",onClick:m,disabled:a||i,className:"shrink-0 !font-normal",children:s(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},qc=()=>{const{t:s}=st(),e=ns()&&ta(),[n,a]=xe.useState(!1),[r,i]=xe.useState(!1),[l,d]=xe.useState(""),[c,h]=xe.useState(""),[m,p]=xe.useState(!1),[u,w]=xe.useState(null),[g,f]=xe.useState(!0),[x,D]=xe.useState(!1),[P,I]=xe.useState(!1),[L,N]=xe.useState(!1),[b,j]=xe.useState(!1),[T,U]=xe.useState(!1),[K,M]=xe.useState(!1),[C,A]=xe.useState(!1),[z,R]=xe.useState(!1),[Q,W]=xe.useState(!1),[te,Y]=xe.useState(!1),[k,$]=xe.useState(null),[B,F]=xe.useState(null);xe.useEffect(()=>{if(!e){f(!1);return}let de=!1;return(async()=>{try{const Z=await ct("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!Z.ok)throw new Error(s("settings.openchamber.desktopNetwork.error.loadFailed"));const se=await Z.json().catch(()=>null);if(de)return;const ve=se?.desktopLanAccessEnabled===!0,G=typeof se?.desktopUiPassword=="string"?se.desktopUiPassword:"";a(ve),i(ve),d(G),h(G),p(se?.desktopLanAccessActive===!0),w(typeof se?.desktopLanAccessBlockedReason=="string"?se.desktopLanAccessBlockedReason:null),$(null)}catch(Z){de||$(Z instanceof Error?Z.message:s("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{de||f(!1)}})(),()=>{de=!0}},[e,s]),xe.useEffect(()=>{if(!e){I(!1);return}let de=!1;return(async()=>{const Z=await Wm();de||(I(Z?.supported===!0),N(Z?.enabled===!0))})(),()=>{de=!0}},[e]),xe.useEffect(()=>{if(!e){U(!1);return}let de=!1;return(async()=>{const Z=await Gm();de||(U(Z?.supported===!0),M(Z?.enabled===!0))})(),()=>{de=!0}},[e]),xe.useEffect(()=>{if(!e){R(!1);return}let de=!1;return(async()=>{const Z=await qm();de||(R(Z?.supported===!0),W(Z?.enabled===!0))})(),()=>{de=!0}},[e]),xe.useEffect(()=>{if(!e||!r){F(null);return}let de=!1;return(async()=>{const Z=await fc();de||F(Z)})(),()=>{de=!0}},[r,e]);const O=r!==n||c!==l,J=xe.useMemo(()=>{if(typeof window>"u")return null;const Z=sa()||window.location.href;let se=0;try{se=Number(new URL(Z).port)}catch{se=Number(window.location.port)}return Number.isFinite(se)&&se>0?se:null},[]),H=r&&m&&B&&J?`http://${B}:${J}`:null,re=r&&!c.trim(),le=n&&!m&&u==="missing-password",ne=g||x||!O||re,be=xe.useCallback(()=>{i(de=>!de)},[]),ae=xe.useCallback(de=>{h(de),de.trim()||i(!1)},[]),ye=xe.useCallback(async()=>{if(!P||b)return;const de=!L;N(de),j(!0),$(null);try{const Z=await Jm(de);if(!Z?.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));N(Z.enabled)}catch(Z){N(!de),$(Z instanceof Error?Z.message:s("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{j(!1)}},[b,L,P,s]),ke=xe.useCallback(async()=>{if(!T||C)return;const de=!K;M(de),A(!0),$(null);try{const Z=await Qm(de);if(!Z)throw new Error(s("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!Z.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));M(Z.enabled)}catch(Z){M(!de),$(Z instanceof Error?Z.message:s("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{A(!1)}},[C,K,T,s]),he=xe.useCallback(async()=>{if(!z||te)return;const de=!Q;W(de),Y(!0),$(null);try{const Z=await Ym(de);if(!Z?.supported)throw new Error(s("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));W(Z.enabled)}catch(Z){W(!de),$(Z instanceof Error?Z.message:s("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{Y(!1)}},[te,Q,z,s]),we=xe.useCallback(async()=>{if(O){D(!0),$(null);try{if(!(await ct("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:c})})).ok)throw new Error(s("settings.openchamber.desktopNetwork.error.saveFailed"));if(a(r),d(c),!await Xm())throw new Error(s("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(de){$(de instanceof Error?de.message:s("settings.openchamber.desktopNetwork.error.saveFailed")),D(!1)}}},[c,r,O,s]);return e?t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.openchamber.desktopNetwork.title")})}),t.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[P?t.jsxs("div",{"data-settings-item":"sessions.desktop-launch-at-login",className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:ye,onKeyDown:de=>{(de.key==="Enter"||de.key===" ")&&(de.preventDefault(),ye())},children:[t.jsx(yt,{checked:L,onChange:ye,ariaLabel:s("settings.openchamber.desktopNetwork.field.launchAtLoginAria"),disabled:b}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.desktopNetwork.field.launchAtLogin")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.launchAtLoginDescription")})]})]}):null,T?t.jsxs("div",{"data-settings-item":"sessions.desktop-minimize-to-tray",className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:ke,onKeyDown:de=>{(de.key==="Enter"||de.key===" ")&&(de.preventDefault(),ke())},children:[t.jsx(yt,{checked:K,onChange:ke,ariaLabel:s("settings.openchamber.desktopNetwork.field.minimizeToTrayAria"),disabled:C}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.desktopNetwork.field.minimizeToTray")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription")})]})]}):null,z?t.jsxs("div",{"data-settings-item":"sessions.desktop-keep-awake",className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:he,onKeyDown:de=>{(de.key==="Enter"||de.key===" ")&&(de.preventDefault(),he())},children:[t.jsx(yt,{checked:Q,onChange:he,ariaLabel:s("settings.openchamber.desktopNetwork.field.keepAwakeAria"),disabled:te}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.desktopNetwork.field.keepAwake")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.keepAwakeDescription")})]})]}):null,t.jsxs("div",{"data-settings-item":"sessions.desktop-ui-password",className:"space-y-1 py-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground",htmlFor:"desktop-ui-password",children:s("settings.openchamber.desktopPassword.field.password")}),t.jsx(Xe,{id:"desktop-ui-password",type:"password",className:"h-7 max-w-sm",value:c,onChange:de=>ae(de.target.value),placeholder:s("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:g||x,required:r,"aria-invalid":re}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopPassword.field.passwordDescription")})]}),t.jsxs("div",{"data-settings-item":"sessions.desktop-lan-access",className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:be,onKeyDown:de=>{(de.key==="Enter"||de.key===" ")&&(de.preventDefault(),be())},children:[t.jsx(yt,{checked:r,onChange:be,ariaLabel:s("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:g||x}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:s("settings.openchamber.desktopNetwork.field.allowLanAccess")}),t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:s("settings.openchamber.desktopNetwork.field.allowLanAccessDescription")}),t.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:s("settings.openchamber.desktopNetwork.field.warning")}),re||le?t.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:s("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]})]}),k?t.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:k}):null,H?t.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[s(O&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),t.jsx("span",{className:"font-mono text-foreground",children:H})]}):null,t.jsx("div",{className:"flex justify-start py-1.5",children:t.jsx(q,{type:"button",size:"xs",onClick:we,disabled:ne,className:"shrink-0 !font-normal",children:s(x?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},Nb=new Set(["shift","control","alt","meta"]),kb=s=>{if(Nb.has(s.key.toLowerCase()))return null;const e=[];(s.metaKey||s.ctrlKey)&&e.push("mod"),s.shiftKey&&e.push("shift"),s.altKey&&e.push("alt");const n=gm(s.key);return n?(e.push(n),Vn(e.join("+"))):null},Sb=()=>{const s=et.c(61),{t:e}=st();let n;s[0]!==e?(n=ne=>e(ne),s[0]=e,s[1]=n):n=s[1];const a=n,r=Ie(Cb),i=Ie(Ib),l=Ie(Pb),d=Ie(Ab);let c;s[2]===Symbol.for("react.memo_cache_sentinel")?(c=mm(),s[2]=c):c=s[2];const h=c;let m;s[3]!==a?(m=(ne,be)=>{const ae=`settings.openchamber.keyboardShortcuts.action.${ne}.label`,ye=a(ae);return ye===ae?be:ye},s[3]=a,s[4]=m):m=s[4];const p=m,[u,w]=o.useState(null);let g;s[5]===Symbol.for("react.memo_cache_sentinel")?(g={},s[5]=g):g=s[5];const[f,x]=o.useState(g),[D,P]=o.useState(""),[I,L]=o.useState(""),[N,b]=o.useState(null),j=Db;let T;s[6]!==r?(T=(ne,be)=>{const ae=Vn(be);for(const ye of h){if(ye.id===ne)continue;const ke=Xi(ye.id,r);if(Vn(ke)===ae)return ye.id}return null},s[6]=r,s[7]=T):T=s[7];const U=T;let K;s[8]!==U||s[9]!==i||s[10]!==r||s[11]!==e?(K=(ne,be)=>{const ae=Vn(be),ye=U(ne,ae);if(ye){b({actionId:ne,combo:ae,conflictActionId:ye}),P("");return}const ke={...r,[ne]:ae};i(ne,ae),j(ke),b(null),P(""),L(Zi(ae)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(he=>{const we={...he};return delete we[ne],we})},s[8]=U,s[9]=i,s[10]=r,s[11]=e,s[12]=K):K=s[12];const M=K;let C;s[13]!==N||s[14]!==i||s[15]!==r||s[16]!==e?(C=()=>{if(!N)return;const ne={...r,[N.conflictActionId]:eo,[N.actionId]:N.combo};i(N.conflictActionId,eo),i(N.actionId,N.combo),j(ne),b(null),P(""),L(Zi(N.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(be=>{const ae={...be};return delete ae[N.actionId],ae})},s[13]=N,s[14]=i,s[15]=r,s[16]=e,s[17]=C):C=s[17];const A=C;let z;s[18]!==l||s[19]!==r?(z=ne=>{const be={...r};delete be[ne],l(ne),j(be),x(ae=>{const ye={...ae};return delete ye[ne],ye}),b(null),P(""),L("")},s[18]=l,s[19]=r,s[20]=z):z=s[20];const R=z;let Q;s[21]!==e?(Q=e("settings.openchamber.keyboardShortcuts.title"),s[21]=e,s[22]=Q):Q=s[22];let W;s[23]!==Q?(W=t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:Q}),s[23]=Q,s[24]=W):W=s[24];let te;s[25]!==d?(te=()=>{d(),j({}),x({}),b(null),P(""),L("")},s[25]=d,s[26]=te):te=s[26];let Y;s[27]!==e?(Y=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),s[27]=e,s[28]=Y):Y=s[28];let k;s[29]!==te||s[30]!==Y?(k=t.jsx(q,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:te,children:Y}),s[29]=te,s[30]=Y,s[31]=k):k=s[31];let $;s[32]===Symbol.for("react.memo_cache_sentinel")?($=t.jsx(Ct,{asChild:!0,children:t.jsx(E,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s[32]=$):$=s[32];let B;s[33]!==e?(B=e("settings.openchamber.keyboardShortcuts.tooltip"),s[33]=e,s[34]=B):B=s[34];let F;s[35]!==B?(F=t.jsxs(St,{children:[$,t.jsx(It,{sideOffset:8,className:"max-w-xs",children:B})]}),s[35]=B,s[36]=F):F=s[36];let O;s[37]!==k||s[38]!==F||s[39]!==W?(O=t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-2",children:[W,k,F]})}),s[37]=k,s[38]=F,s[39]=W,s[40]=O):O=s[40];let J;s[41]!==A||s[42]!==D||s[43]!==N||s[44]!==e||s[45]!==I?(J=(D||I||N)&&t.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[N&&t.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[t.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),t.jsxs("div",{className:"flex gap-2 shrink-0",children:[t.jsx(q,{type:"button",size:"xs",className:"!font-normal",onClick:A,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),t.jsx(q,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>b(null),children:e("settings.common.actions.cancel")})]})]}),D&&t.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:D}),I&&t.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:I})]}),s[41]=A,s[42]=D,s[43]=N,s[44]=e,s[45]=I,s[46]=J):J=s[46];let H;s[47]!==p||s[48]!==u||s[49]!==f||s[50]!==R||s[51]!==M||s[52]!==r||s[53]!==e?(H=h.map((ne,be)=>{const ae=Xi(ne.id,r),ye=f[ne.id],ke=ye??ae,he=typeof ye=="string"&&Vn(ye)!==Vn(ae);return t.jsxs("div",{className:ce("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",be>0&&"border-t border-[var(--surface-subtle)]"),children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:p(ne.id,ne.label)})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsx(Xe,{readOnly:!0,value:u===ne.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):pm(ke),onFocus:()=>{w(ne.id),P("")},onBlur:()=>{u===ne.id&&w(null)},onKeyDown:we=>{if(we.preventDefault(),we.stopPropagation(),we.key==="Escape"){w(null);return}const de=kb(we);de&&(x(Z=>({...Z,[ne.id]:de})),w(null),b(null),P(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),t.jsx(q,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const we=f[ne.id];if(!we){P(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}M(ne.id,we)},disabled:!he,children:e("settings.common.actions.saveChanges")}),t.jsx(q,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>R(ne.id),children:e("settings.common.actions.reset")})]})]},ne.id)}),s[47]=p,s[48]=u,s[49]=f,s[50]=R,s[51]=M,s[52]=r,s[53]=e,s[54]=H):H=s[54];let re;s[55]!==H?(re=t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:H}),s[55]=H,s[56]=re):re=s[56];let le;return s[57]!==O||s[58]!==J||s[59]!==re?(le=t.jsxs("div",{"data-settings-item":"shortcuts.keyboard-shortcuts",className:"mb-8",children:[O,J,re]}),s[57]=O,s[58]=J,s[59]=re,s[60]=le):le=s[60],le};function Cb(s){return s.shortcutOverrides}function Ib(s){return s.setShortcutOverride}function Pb(s){return s.clearShortcutOverride}function Ab(s){return s.resetAllShortcutOverrides}function Db(s){Nt({shortcutOverrides:s})}const Jc=()=>{const s=et.c(2),[e,n]=o.useState(0);let a,r;return s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>Zm(()=>n(Bb)),r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),o.useEffect(a,r),e},Eb=s=>{const e=et.c(20),{section:n}=s,{isMobile:a}=Ds();Jc();let r;e[0]!==a?(r=a&&Dn(),e[0]=a,e[1]=r):r=e[1];const i=r;let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=ms(),e[2]=l):l=e[2];const d=l;let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=ns()&&ta(),e[3]=c):c=e[3];const h=c;if(!n){let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=t.jsx(Ri,{}),e[4]=g):g=e[4];let f,x,D;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(_c,{})}),x=h&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(qc,{})}),D=!d&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Gc,{})}),e[5]=f,e[6]=x,e[7]=D):(f=e[5],x=e[6],D=e[7]);let P;e[8]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx($c,{})}),e[8]=P):P=e[8];let I;e[9]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Vc,{})}),e[9]=I):I=e[9];let L;e[10]!==i?(L=i&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(jc,{})}),e[10]=i,e[11]=L):L=e[11];let N;return e[12]!==L?(N=t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[g,f,x,D,P,I,L]})}),e[12]=L,e[13]=N):N=e[13],N}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return t.jsx(Tb,{});case"chat":return t.jsx(Rb,{});case"sessions":return t.jsx(Fb,{});case"shortcuts":return t.jsx(Mb,{});case"git":return t.jsx(Lb,{});case"github":return t.jsx(Ob,{});case"notifications":return t.jsx(zb,{});case"voice":return t.jsx(Kb,{});case"tunnel":return t.jsx(Ub,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const p=m;let u;e[16]!==p?(u=p(),e[16]=p,e[17]=u):u=e[17];let w;return e[18]!==u?(w=t.jsx(_t,{outerClassName:"h-full",className:"w-full",children:t.jsx("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",children:u})}),e[18]=u,e[19]=w):w=e[19],w},Mb=()=>{const s=et.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Sb,{}),s[0]=e):e=s[0],e},Tb=()=>{const s=et.c(3);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=ms(),s[0]=e):e=s[0];const n=e;let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=n?[]:["weekStart"],s[1]=a):a=s[1];let r;return s[2]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(Ri,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a,"fontSize","terminalFontSize","editorFontSize","fileEditorKeymap","spacing","inputBarOffset","expandedEditorToolbar",...n?[]:["terminalQuickKeys"],"reportUsage"]}),s[2]=r):r=s[2],r},Rb=()=>{const s=et.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Ri,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","messageTransport","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader","wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck"]}),s[0]=e):e=s[0],e},Fb=()=>{const s=et.c(7);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=ms(),s[0]=e):e=s[0];const n=e;Jc();let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=ns()&&ta(),s[1]=a):a=s[1];const r=a;let i,l,d;s[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(_c,{}),l=r&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(qc,{})}),d=!n&&t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Gc,{})}),s[2]=i,s[3]=l,s[4]=d):(i=s[2],l=s[3],d=s[4]);let c;s[5]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx($c,{})}),s[5]=c):c=s[5];let h;return s[6]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsxs("div",{className:"space-y-6",children:[i,l,d,c,t.jsx("div",{className:"border-t border-border/40 pt-6",children:t.jsx(Vc,{})})]}),s[6]=h):h=s[6],h},Lb=()=>{const s=et.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx("div",{className:"space-y-6",children:t.jsx(Kc,{})}),s[0]=e):e=s[0],e},Ob=()=>{const s=et.c(1);if(ms())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(Uc,{}),s[0]=e):e=s[0],e},zb=()=>{const s=et.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(ob,{}),s[0]=e):e=s[0],e},Kb=()=>{const s=et.c(1);if(ms())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(mb,{}),s[0]=e):e=s[0],e},Ub=()=>{const s=et.c(1);if(ms())return null;let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx(wb,{}),s[0]=e):e=s[0],e};function Bb(s){return s+1}const Qc=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"single",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:s=>!s.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"usage",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"plugins",title:"Plugins",group:"opencode",kind:"split",keywords:["plugin","plugins","extensions","addons","npm","opencode-wakatime"]},{slug:"skills.installed",title:"Skills",group:"skills",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"skills",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"git",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:s=>!s.isVSCode},{slug:"appearance",title:"Appearance",group:"appearance",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:s=>!s.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"general",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:s=>!s.isVSCode},{slug:"snippets",title:"Snippets",group:"general",kind:"split",keywords:["prompt","templates","multi-run","strategy","approach"]},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"voice",title:"Voice",group:"advanced",kind:"single",keywords:["tts","speech","voice"],isAvailable:s=>!s.isVSCode},{slug:"tunnel",title:"Remote Tunnel",group:"advanced",kind:"single",keywords:["tunnel","cloudflare","qr","remote","mobile","share"],isAvailable:s=>!s.isVSCode},{slug:"about",title:"About",group:"advanced",kind:"single",keywords:["about","version","updates","release","changelog"],isAvailable:s=>s.isMobile}],$b={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function qn(s){const e=s.trim().toLowerCase();return Qc.find(n=>n.slug===e)??null}function Fi(s){const e=(s??"").trim().toLowerCase();if(!e)return"home";const n=$b[e];if(n)return n;const a=qn(e);return a?a.slug:"home"}const Vb=[{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.openchamber.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.openchamber.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"],isAvailable:s=>!s.isVSCode},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:s=>!s.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:s=>!s.isVSCode},{id:"appearance.window-transparency",page:"appearance",titleKey:"settings.openchamber.visual.field.macVibrancy",descriptionKey:"settings.openchamber.visual.field.macVibrancyHint",keywords:["transparent","transparency","vibrancy","blur","macos","opaque"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.openchamber.visual.field.dockBadge",descriptionKey:"settings.openchamber.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:s=>s.isMac},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:s=>s.isWeb&&!s.isDesktop&&!s.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:s=>s.isWeb&&!s.isDesktop&&!s.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.openchamber.visual.field.mobileKeyboardMode",descriptionKey:"settings.openchamber.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:s=>s.isMobile&&s.isWeb&&!s.isDesktop&&!s.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:s=>!s.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"]},{id:"appearance.expanded-editor-toolbar",page:"appearance",titleKey:"settings.openchamber.visual.field.expandedEditorToolbar",keywords:["editor","toolbar","tabs","docked","files"]},{id:"appearance.file-editor-keymap",page:"appearance",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.terminal-quick-keys",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:s=>!s.isMobile&&!s.isVSCode},{id:"appearance.usage-reports",page:"appearance",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"chat",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:s=>!s.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.openchamber.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:s=>!s.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.openchamber.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:s=>!s.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:s=>!s.isMobile},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.openchamber.defaults.smallModel.title",descriptionKey:"settings.openchamber.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.openchamber.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"sessions.desktop-minimize-to-tray",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.openchamber.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows"],isAvailable:s=>s.isDesktopLocalOrigin&&s.isWindows},{id:"sessions.desktop-keep-awake",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.keepAwake",descriptionKey:"settings.openchamber.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"sessions",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"sessions",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:s=>s.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"sessions",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:s=>!s.isVSCode},{id:"sessions.opencode-update-notifications",page:"sessions",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:s=>!s.isVSCode},{id:"git.github-account",page:"git",titleKey:"settings.github.page.actions.connect",keywords:["github","account","oauth","prs","issues"]},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.openchamber.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.openchamber.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.openchamber.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.header-menu",page:"usage",titleKey:"settings.usage.page.options.showInHeader",descriptionKey:"settings.usage.page.options.showInHeaderTooltip",keywords:["quota","header","dropdown"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.accent-color",page:"projects",titleKey:"settings.projects.page.field.accentColor",keywords:["color","appearance","project metadata"]},{id:"projects.icon",page:"projects",titleKey:"settings.projects.page.field.projectIcon",keywords:["icon","favicon","upload","project metadata"]},{id:"projects.worktree",page:"projects",titleKey:"settings.projects.page.section.worktree",keywords:["worktree","branch","repository"]},{id:"projects.worktree.setup.wait",page:"projects",titleKey:"settings.openchamber.worktrees.setup.waitForCommands",keywords:["worktree","setup commands","bootstrap","wait"]},{id:"remote-instances.client-auth",page:"remote-instances",titleKey:"settings.remoteInstances.clientAuth.title",descriptionKey:"settings.remoteInstances.clientAuth.description",keywords:["pairing link","client token","connect desktop","remote access","relay","devices","connect from anywhere"],isAvailable:s=>!s.isVSCode},{id:"remote-instances.direct-hosts",page:"remote-instances",titleKey:"settings.remoteInstances.direct.title",descriptionKey:"settings.remoteInstances.direct.description",keywords:["server url","connection token","import link","host switcher","additional headers","request headers","cloudflare access","service token"],isAvailable:s=>s.isDesktop},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.auth",page:"providers",titleKey:"settings.providers.page.auth.title",keywords:["api key","oauth","credentials"]},{id:"providers.connection-details",page:"providers",titleKey:"settings.providers.page.connectionDetails.title",keywords:["config","source","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:s=>!s.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:s=>!s.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:s=>!s.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.openchamber.keyboardShortcuts.title",descriptionKey:"settings.openchamber.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.provider",descriptionKey:"settings.openchamber.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:s=>!s.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:s=>!s.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.connectLinkTtl",descriptionKey:"settings.openchamber.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:s=>!s.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:s=>!s.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.configurationFile",descriptionKey:"settings.openchamber.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:s=>!s.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.openchamber.tunnel.actions.startTunnel",descriptionKey:"settings.openchamber.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:s=>!s.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:s=>s.isWeb&&!s.isDesktop&&!s.isVSCode}];function Ll(s){return s.trim().toLocaleLowerCase()}function _b({query:s,runtimeCtx:e,visiblePageSlugs:n,t:a,getPageTitle:r}){const i=Ll(s);if(!i)return[];const l=n?new Set(n):null,d=i.split(/\s+/).filter(Boolean);return Vb.flatMap(c=>{if(l&&!l.has(c.page))return[];const h=qn(c.page);if(!h||h.isAvailable&&!h.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const m=a(c.titleKey),p=c.descriptionKey?a(c.descriptionKey):null,u=Ll([m,p,r(c.page),...c.keywords??[]].filter(Boolean).join(" "));return d.every(w=>u.includes(w))?[{...c,title:m,description:p,pageTitle:r(c.page)}]:[]})}const ki=176,Si=280,Ol=8,Yc="__openchamberSettingsDetail";function Xr(s){return Math.min(Si,Math.max(ki,s))}const Hb=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","snippets","projects","remote-instances","agents","behavior","commands","mcp","plugins","providers","usage","skills.installed","skills.catalog","voice","tunnel","about"],Wb={icon:"chat-thread"},Gb="__add_provider__";function qb(s,e){const n=ms(),a=!s&&Dn();return{isVSCode:n,isWeb:a,isDesktop:s,isMobile:e}}function zl(s,e){return s.isAvailable?s.isAvailable(e):!0}function Ci(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function fa(s,e){const n=new Set(e);let a=s,r=1;for(;n.has(a);)a=`${s}-${r}`,r+=1;return a}function Zr(s){if(!Ci(s))return null;const e=s[Yc];if(!Ci(e))return null;const n=e.page,a=e.stage;return typeof n!="string"||a!=="page-content"?null:{page:Fi(n),stage:a}}function Jb(){return typeof window>"u"||!Ci(window.history.state)?{}:window.history.state}function Xc(s){switch(s){case"projects":return"folders";case"remote-instances":return"server";case"appearance":return"palette";case"chat":return"chat-ai-3";case"magic-prompts":return"ai-generate-2";case"snippets":return Wb.icon;case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"chat-history";case"providers":return"cloud";case"agents":return"ai-agent";case"behavior":return"brain";case"commands":return"slash-commands-2";case"mcp":return null;case"plugins":return"code-box";case"skills.installed":return"book-open";case"skills.catalog":return"book";case"git":return"git-branch";case"usage":return"bar-chart-2";case"voice":return"mic";case"tunnel":return"global";case"about":return"information";case"home":return null;default:return"robot-2"}}const ei=s=>{const e=et.c(95),{onOpen:n}=s,{t:a}=st();let r;e[0]!==a?(r=a("settings.view.home.title"),e[0]=a,e[1]=r):r=e[1];let i;e[2]!==r?(i=t.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:r}),e[2]=r,e[3]=i):i=e[3];let l;e[4]!==a?(l=a("settings.view.home.description"),e[4]=a,e[5]=l):l=e[5];let d;e[6]!==l?(d=t.jsx("p",{className:"typography-ui text-muted-foreground",children:l}),e[6]=l,e[7]=d):d=e[7];let c;e[8]!==i||e[9]!==d?(c=t.jsxs("div",{className:"space-y-1",children:[i,d]}),e[8]=i,e[9]=d,e[10]=c):c=e[10];let h;e[11]!==n?(h=()=>n("providers"),e[11]=n,e[12]=h):h=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=m):m=e[13];let p;e[14]!==a?(p=a("settings.view.home.cards.providers.title"),e[14]=a,e[15]=p):p=e[15];let u;e[16]!==p?(u=t.jsx("div",{className:"typography-ui-label text-foreground",children:p}),e[16]=p,e[17]=u):u=e[17];let w;e[18]!==a?(w=a("settings.view.home.cards.providers.description"),e[18]=a,e[19]=w):w=e[19];let g;e[20]!==w?(g=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:w}),e[20]=w,e[21]=g):g=e[21];let f;e[22]!==g||e[23]!==h||e[24]!==u?(f=t.jsxs("button",{type:"button",onClick:h,className:m,children:[u,g]}),e[22]=g,e[23]=h,e[24]=u,e[25]=f):f=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=D):D=e[28];let P;e[29]!==a?(P=a("settings.view.home.cards.agents.title"),e[29]=a,e[30]=P):P=e[30];let I;e[31]!==P?(I=t.jsx("div",{className:"typography-ui-label text-foreground",children:P}),e[31]=P,e[32]=I):I=e[32];let L;e[33]!==a?(L=a("settings.view.home.cards.agents.description"),e[33]=a,e[34]=L):L=e[34];let N;e[35]!==L?(N=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:L}),e[35]=L,e[36]=N):N=e[36];let b;e[37]!==x||e[38]!==I||e[39]!==N?(b=t.jsxs("button",{type:"button",onClick:x,className:D,children:[I,N]}),e[37]=x,e[38]=I,e[39]=N,e[40]=b):b=e[40];let j;e[41]!==n?(j=()=>n("skills.catalog"),e[41]=n,e[42]=j):j=e[42];let T;e[43]===Symbol.for("react.memo_cache_sentinel")?(T=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=T):T=e[43];let U;e[44]!==a?(U=a("settings.view.home.cards.skillsCatalog.title"),e[44]=a,e[45]=U):U=e[45];let K;e[46]!==U?(K=t.jsx("div",{className:"typography-ui-label text-foreground",children:U}),e[46]=U,e[47]=K):K=e[47];let M;e[48]!==a?(M=a("settings.view.home.cards.skillsCatalog.description"),e[48]=a,e[49]=M):M=e[49];let C;e[50]!==M?(C=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:M}),e[50]=M,e[51]=C):C=e[51];let A;e[52]!==j||e[53]!==K||e[54]!==C?(A=t.jsxs("button",{type:"button",onClick:j,className:T,children:[K,C]}),e[52]=j,e[53]=K,e[54]=C,e[55]=A):A=e[55];let z;e[56]!==n?(z=()=>n("mcp"),e[56]=n,e[57]=z):z=e[57];let R;e[58]===Symbol.for("react.memo_cache_sentinel")?(R=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=R):R=e[58];let Q;e[59]!==a?(Q=a("settings.view.home.cards.mcp.title"),e[59]=a,e[60]=Q):Q=e[60];let W;e[61]!==Q?(W=t.jsx("div",{className:"typography-ui-label text-foreground",children:Q}),e[61]=Q,e[62]=W):W=e[62];let te;e[63]!==a?(te=a("settings.view.home.cards.mcp.description"),e[63]=a,e[64]=te):te=e[64];let Y;e[65]!==te?(Y=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:te}),e[65]=te,e[66]=Y):Y=e[66];let k;e[67]!==z||e[68]!==W||e[69]!==Y?(k=t.jsxs("button",{type:"button",onClick:z,className:R,children:[W,Y]}),e[67]=z,e[68]=W,e[69]=Y,e[70]=k):k=e[70];let $;e[71]!==n?($=()=>n("usage"),e[71]=n,e[72]=$):$=e[72];let B;e[73]===Symbol.for("react.memo_cache_sentinel")?(B=ce("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=B):B=e[73];let F;e[74]!==a?(F=a("settings.view.home.cards.usage.title"),e[74]=a,e[75]=F):F=e[75];let O;e[76]!==F?(O=t.jsx("div",{className:"typography-ui-label text-foreground",children:F}),e[76]=F,e[77]=O):O=e[77];let J;e[78]!==a?(J=a("settings.view.home.cards.usage.description"),e[78]=a,e[79]=J):J=e[79];let H;e[80]!==J?(H=t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:J}),e[80]=J,e[81]=H):H=e[81];let re;e[82]!==$||e[83]!==O||e[84]!==H?(re=t.jsxs("button",{type:"button",onClick:$,className:B,children:[O,H]}),e[82]=$,e[83]=O,e[84]=H,e[85]=re):re=e[85];let le;e[86]!==f||e[87]!==b||e[88]!==A||e[89]!==k||e[90]!==re?(le=t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[f,b,A,k,re]}),e[86]=f,e[87]=b,e[88]=A,e[89]=k,e[90]=re,e[91]=le):le=e[91];let ne;return e[92]!==le||e[93]!==c?(ne=t.jsx("div",{className:"h-full overflow-auto",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl px-6 py-6 space-y-6",children:[c,le]})}),e[92]=le,e[93]=c,e[94]=ne):ne=e[94],ne},Qb=s=>{const e=et.c(128),{onClose:n,forceMobile:a,isWindowed:r,visiblePageSlugs:i,initialMobileStage:l}=s,d=l===void 0?"nav":l,{t:c}=st(),h=Ds(),m=a??h.isMobile,p=Ie(Yb),u=Ie(Xb),w=Ie(Zb);let g;e[0]!==p?(g=Fi(p),e[0]=p,e[1]=g):g=e[1];const f=g,[x,D]=o.useState(d),P=o.useRef(null),[I,L]=o.useState(216),[N,b]=o.useState(""),[j,T]=o.useState(null),[U,K]=o.useState(0),[M,C]=o.useState(!1),[A,z]=o.useState(!1),R=o.useRef(0),Q=o.useRef(I),W=o.useRef(null);let te;e[2]===Symbol.for("react.memo_cache_sentinel")?(te=[],e[2]=te):te=e[2];const Y=o.useRef(te),k=o.useRef(0),$=o.useRef(!1);let B;e[3]===Symbol.for("react.memo_cache_sentinel")?(B=ns(),e[3]=B):B=e[3];const F=B;let O;e[4]===Symbol.for("react.memo_cache_sentinel")?(O=ns()&&ta(),e[4]=O):O=e[4];const J=O;let H;e[5]===Symbol.for("react.memo_cache_sentinel")?(H=ns()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",e[5]=H):H=e[5];const re=H;let le;e[6]===Symbol.for("react.memo_cache_sentinel")?(le=ns()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",e[6]=le):le=e[6];const ne=le;let be;e[7]!==m?(be=qb(F,m),e[7]=m,e[8]=be):be=e[8];const ae=be;let ye;if(e[9]!==m||e[10]!==ae||e[11]!==i){const ut=i?new Set(i):null;let pt;e[13]!==ae?(pt=Xt=>zl(Xt,ae),e[13]=ae,e[14]=pt):pt=e[14];let wt;e[15]!==ae.isVSCode?(wt=Xt=>!(ae.isVSCode&&Xt.slug==="projects"),e[15]=ae.isVSCode,e[16]=wt):wt=e[16];let Qt;e[17]!==m?(Qt=Xt=>!(m&&Xt.slug==="shortcuts"),e[17]=m,e[18]=Qt):Qt=e[18],ye=Qc.filter(ev).filter(Xt=>!ut||ut.has(Xt.slug)).filter(pt).filter(wt).filter(Qt),e[9]=m,e[10]=ae,e[11]=i,e[12]=ye}else ye=e[12];const ke=ye;let he;e[19]===Symbol.for("react.memo_cache_sentinel")?(he=new Map(Hb.map(tv)),e[19]=he):he=e[19];const we=he;let de;if(e[20]!==ke){let ut;e[22]===Symbol.for("react.memo_cache_sentinel")?(ut=(pt,wt)=>(we.get(pt.slug)??999)-(we.get(wt.slug)??999),e[22]=ut):ut=e[22],de=ke.slice().sort(ut),e[20]=ke,e[21]=de}else de=e[21];const Z=de,se=es(sv);let ve,G;e[23]!==M?(ve=()=>{if(typeof window>"u")return;const ut=()=>{if(!M){const pt=Xr(Math.floor(window.innerWidth*.12));L(pt)}};return window.addEventListener("resize",ut),()=>window.removeEventListener("resize",ut)},G=[M],e[23]=M,e[24]=ve,e[25]=G):(ve=e[24],G=e[25]),o.useEffect(ve,G);let ee,ie;e[26]!==A?(ee=()=>{if(!A)return;const ut=wt=>{const Qt=wt.clientX-R.current,Xt=Xr(Q.current+Qt);L(Xt),C(!0)},pt=()=>z(!1);return window.addEventListener("pointermove",ut),window.addEventListener("pointerup",pt,{once:!0}),()=>{window.removeEventListener("pointermove",ut),window.removeEventListener("pointerup",pt)}},ie=[A],e[26]=A,e[27]=ee,e[28]=ie):(ee=e[27],ie=e[28]),o.useEffect(ee,ie);let pe;e[29]!==I?(pe=ut=>{z(!0),R.current=ut.clientX,Q.current=I,ut.preventDefault()},e[29]=I,e[30]=pe):pe=e[30];const Ae=pe;let Se;e[31]!==I?(Se=ut=>{const pt=ut.shiftKey?Ol*4:Ol;let wt;e:switch(ut.key){case"ArrowLeft":{wt=I-pt;break e}case"ArrowRight":{wt=I+pt;break e}case"Home":{wt=ki;break e}case"End":{wt=Si;break e}default:return}ut.preventDefault(),L(Xr(wt)),C(!0)},e[31]=I,e[32]=Se):Se=e[32];const De=Se;let Me;e[33]!==u||e[34]!==r||e[35]!==ae.isVSCode||e[36]!==f?(Me=()=>{if(!(!u&&!ae.isVSCode&&!r)){if(f==="agents"){cr.getState().loadAgents();return}if(f==="commands"){dr.getState().loadCommands();return}if(f==="mcp"){Zn.getState().loadMcpConfigs();return}if(f==="plugins"){is.getState().loadPlugins();return}(f==="skills.installed"||f==="skills.catalog")&&(Zs.getState().loadSkills(),Ys.getState().loadCatalog()),f==="snippets"&&mr.getState().loadSnippets()}},e[33]=u,e[34]=r,e[35]=ae.isVSCode,e[36]=f,e[37]=Me):Me=e[37];let Te;e[38]!==se||e[39]!==u||e[40]!==r||e[41]!==ae.isVSCode||e[42]!==f?(Te=[se,u,r,ae.isVSCode,f],e[38]=se,e[39]=u,e[40]=r,e[41]=ae.isVSCode,e[42]=f,e[43]=Te):Te=e[43],o.useEffect(Me,Te);let Be;e[44]!==m||e[45]!==w?(Be=ut=>{if(w(ut),P.current=ut,!m)return;const pt=qn(ut);if(!pt||pt.slug==="home"){D("nav");return}D(pt.kind==="split"?"page-sidebar":"page-content")},e[44]=m,e[45]=w,e[46]=Be):Be=e[46];const ze=Be;let Oe;e[47]!==f?(Oe=qn(f),e[47]=f,e[48]=Oe):Oe=e[48];const $e=Oe;let Ke;e[49]===Symbol.for("react.memo_cache_sentinel")?(Ke={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[49]=Ke):Ke=e[49];const Ye=Ke;let Re;e[50]!==c?(Re=ut=>{switch(ut){case"projects":return c("settings.page.projects.title");case"remote-instances":return c("settings.page.remoteInstances.title");case"providers":return c("settings.page.providers.title");case"usage":return c("settings.page.usage.title");case"agents":return c("settings.page.agents.title");case"behavior":return c("settings.page.behavior.title");case"commands":return c("settings.page.commands.title");case"mcp":return c("settings.page.mcp.title");case"plugins":return c("settings.page.plugins.title");case"skills.installed":return c("settings.page.skills.title");case"skills.catalog":return c("settings.page.skillsCatalog.title");case"git":return c("settings.page.git.title");case"appearance":return c("settings.page.appearance.title");case"chat":return c("settings.page.chat.title");case"shortcuts":return c("settings.page.shortcuts.title");case"sessions":return c("settings.page.sessions.title");case"magic-prompts":return c("settings.page.magicPrompts.title");case"snippets":return c("settings.page.snippets.title");case"notifications":return c("settings.page.notifications.title");case"voice":return c("settings.page.voice.title");case"tunnel":return c("settings.page.tunnel.title");case"about":return c("settings.page.about.title");default:return c("settings.view.home.title")}},e[50]=c,e[51]=Re):Re=e[51];const V=Re;let oe;e[52]!==V||e[53]!==ae||e[54]!==N||e[55]!==c||e[56]!==i?(oe=_b({query:N,runtimeCtx:{...ae,isDesktopLocalOrigin:J,isMac:re,isWindows:ne},visiblePageSlugs:i,t:c,getPageTitle:V}),e[52]=V,e[53]=ae,e[54]=N,e[55]=c,e[56]=i,e[57]=oe):oe=e[57];const ge=oe,Fe=lv;let Ne;if(e[58]!==ge){Ne=[];const ut=new Map;for(const pt of ge){let wt=ut.get(pt.page);wt||(wt={page:pt.page,pageTitle:pt.pageTitle,results:[]},ut.set(pt.page,wt),Ne.push(wt)),wt.results.push(pt)}e[58]=ge,e[59]=Ne}else Ne=e[59];const He=Ne;let X;e[60]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{K(0),k.current=0,$.current=!1},e[60]=X):X=e[60];let v;e[61]!==N?(v=[N],e[61]=N,e[62]=v):v=e[62],o.useEffect(X,v);let je,Pe;e[63]!==U?(je=()=>{k.current=U},Pe=[U],e[63]=U,e[64]=je,e[65]=Pe):(je=e[64],Pe=e[65]),o.useEffect(je,Pe);let Le,qe;e[66]!==U?(Le=()=>{Y.current[U]?.scrollIntoView({block:"nearest"})},qe=[U],e[66]=U,e[67]=Le,e[68]=qe):(Le=e[67],qe=e[68]),o.useEffect(Le,qe);let rt,ot;e[69]!==U||e[70]!==ge.length?(rt=()=>{U>=ge.length&&K(Math.max(0,ge.length-1)),Y.current.length=ge.length},ot=[U,ge.length],e[69]=U,e[70]=ge.length,e[71]=rt,e[72]=ot):(rt=e[71],ot=e[72]),o.useEffect(rt,ot);let it;e[73]!==m||e[74]!==ze?(it=ut=>{const pt=Fe(ut);T(pt),ze(ut.page),m&&D("page-content"),ut.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(cv,50)},e[73]=m,e[74]=ze,e[75]=it):it=e[75];const dt=it;let Je;e[76]!==dt||e[77]!==N||e[78]!==ge?(Je=ut=>{if(N.trim()){if(ut.key==="Escape"){ut.preventDefault(),b("");return}if(ge.length!==0){if(ut.key==="ArrowDown"){ut.preventDefault(),$.current=!0,K(pt=>(pt+1)%ge.length);return}if(ut.key==="ArrowUp"){ut.preventDefault(),$.current=!0,K(pt=>(pt-1+ge.length)%ge.length);return}if(ut.key==="Enter"){ut.preventDefault();const pt=(k.current%ge.length+ge.length)%ge.length,wt=ge[pt]??ge[0];wt&&dt(wt)}}}},e[76]=dt,e[77]=N,e[78]=ge,e[79]=Je):Je=e[79];const _e=Je;let gt;e[80]!==j?(gt=()=>{const ut=j;if(!ut)return;let pt=!1;const wt=window.requestAnimationFrame(()=>{if(pt)return;const Qt=typeof CSS<"u"&&CSS.escape?CSS.escape(ut):ut.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Xt=W.current?.querySelector(`[data-settings-item="${Qt}"]`);Xt&&(T(null),Xt.scrollIntoView({block:"center",behavior:"smooth"}),Xt.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Xt.removeAttribute("data-settings-search-highlight")},1600))});return()=>{pt=!0,window.cancelAnimationFrame(wt)}},e[80]=j,e[81]=gt):gt=e[81];let fe;e[82]!==j||e[83]!==f?(fe=[j,f],e[82]=j,e[83]=f,e[84]=fe):fe=e[84],o.useEffect(gt,fe);let tt;e[85]!==c?(tt=()=>t.jsx("div",{className:"flex h-full items-center justify-center px-6",children:t.jsxs("div",{className:"max-w-md text-center",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("settings.view.unavailable.title")}),t.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:c("settings.view.unavailable.description")})]})}),e[85]=c,e[86]=tt):tt=e[86];const nt=tt,Ze=dv;let ft;e[87]!==ze||e[88]!==nt||e[89]!==ae?(ft=ut=>{const pt=qn(ut);if(pt&&!zl(pt,ae))return nt();switch(ut){case"home":return t.jsx(ei,{onOpen:ze});case"projects":return t.jsx(ax,{});case"remote-instances":return t.jsx(Mx,{});case"agents":return t.jsx(tg,{});case"behavior":return t.jsx(ig,{});case"commands":return t.jsx(hg,{});case"mcp":return t.jsx(Hg,{});case"plugins":return t.jsx(Eh,{});case"skills.installed":return t.jsx(rl,{view:"installed"});case"skills.catalog":return t.jsx(rl,{view:"catalog"});case"providers":return t.jsx(Bx,{});case"usage":return t.jsx(jy,{});case"about":return t.jsx("div",{className:"h-full overflow-auto px-5 py-6",children:t.jsx(jc,{})});case"magic-prompts":return t.jsx(Cy,{});case"snippets":return t.jsx(Ey,{});case"git":return t.jsx(Ly,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const wt=Ye[ut]??"visual";return t.jsx(Eb,{section:wt})}default:return t.jsx(ei,{onOpen:ze})}},e[87]=ze,e[88]=nt,e[89]=ae,e[90]=ft):ft=e[90];const bt=ft;let Mt,ue;e[91]!==m||e[92]!==x||e[93]!==f?(Mt=()=>{if(!m||x!=="nav"||f==="home"||P.current===f)return;const ut=qn(f);!ut||ut.slug==="home"||(P.current=f,D(ut.kind==="split"?"page-sidebar":"page-content"))},ue=[m,x,f],e[91]=m,e[92]=x,e[93]=f,e[94]=Mt,e[95]=ue):(Mt=e[94],ue=e[95]),o.useEffect(Mt,ue);const Ve=m&&x!=="nav",Qe=m&&x==="page-content"&&f==="skills.installed",Ge=x==="page-content"&&$e?.kind==="split"&&!Qe;let xt;e[96]!==Qe||e[97]!==Ve||e[98]!==c?(xt=c(Qe?"settings.view.actions.back":Ve?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[96]=Qe,e[97]=Ve,e[98]=c,e[99]=xt):xt=e[99];const kt=xt,ht=hm();let Pt;e[100]!==ae.isVSCode?(Pt=ut=>{if(typeof window>"u"||ae.isVSCode)return;const pt=Zr(window.history.state);pt?.page===ut&&pt.stage==="page-content"||window.history.pushState({...Jb(),[Yc]:{page:ut,stage:"page-content"}},"",window.location.href)},e[100]=ae.isVSCode,e[101]=Pt):Pt=e[101];const Wt=Pt;let ts;e[102]!==Wt||e[103]!==f?(ts=()=>{D("page-content"),f==="skills.installed"&&Wt(f)},e[102]=Wt,e[103]=f,e[104]=ts):ts=e[104];const bs=ts;let ks;e[105]!==Qe||e[106]!==ae.isVSCode||e[107]!==f?(ks=()=>{if(Qe){if((typeof window<"u"?Zr(window.history.state):null)?.page===f&&!ae.isVSCode){window.history.back();return}D("page-sidebar");return}D("nav")},e[105]=Qe,e[106]=ae.isVSCode,e[107]=f,e[108]=ks):ks=e[108];const Yt=ks;let Ss,Ce;e[109]!==m||e[110]!==ae.isVSCode||e[111]!==f?(Ss=()=>{if(!m||ae.isVSCode)return;const ut=pt=>{if(f!=="skills.installed")return;if(Zr(pt.state)?.page==="skills.installed"){D("page-content");return}D(uv)};return window.addEventListener("popstate",ut),()=>{window.removeEventListener("popstate",ut)}},Ce=[m,ae.isVSCode,f],e[109]=m,e[110]=ae.isVSCode,e[111]=f,e[112]=Ss,e[113]=Ce):(Ss=e[112],Ce=e[113]),o.useEffect(Ss,Ce);let jt;e[114]===Symbol.for("react.memo_cache_sentinel")?(jt=()=>{D("page-sidebar")},e[114]=jt):jt=e[114];const vt=jt,Ht=()=>{const ut=N.trim().length>0;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[t.jsx("div",{className:"px-2 pt-3",children:t.jsxs("div",{className:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[t.jsx(E,{name:"search",className:"h-4 w-4 shrink-0"}),t.jsx("input",{value:N,onChange:pt=>b(pt.target.value),onKeyDown:_e,placeholder:c("settings.view.search.placeholder"),"aria-label":c("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),ut&&t.jsx("button",{type:"button",onClick:()=>b(""),"aria-label":c("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})})]})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:t.jsx("div",{className:"flex flex-col gap-0.5 pt-4 pb-2 px-2",children:ut?ge.length>0?(()=>{let pt=0;return He.map(wt=>t.jsxs("div",{className:"space-y-0.5",children:[t.jsx("div",{className:"px-2 pb-0.5 pt-2 typography-micro font-medium text-muted-foreground/70",children:wt.pageTitle}),wt.results.map(Qt=>{const Xt=pt;pt=pt+1;const an=Xt===U,rn=!!Qt.description;return t.jsxs("button",{type:"button",ref:kn=>{Y.current[Xt]=kn},onMouseMove:()=>{$.current=!1,K(Xt)},onClick:()=>dt(Qt),className:ce("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",rn?"min-h-11 py-1.5":"py-2",an?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Qt.title}),rn&&t.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:Qt.description})]},Qt.id)})]},wt.page))})():t.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:c("settings.view.search.noResults")}):Z.map(pt=>{const wt=f===pt.slug,Qt=Xc(pt.slug);return!Qt&&pt.slug!=="mcp"?null:t.jsx(St,{children:t.jsx(Ct,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:()=>ze(pt.slug),"aria-current":wt?"page":void 0,className:ce("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",wt?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[pt.slug==="mcp"?t.jsx(cp,{className:"h-4 w-4 shrink-0"}):t.jsx(E,{name:Qt,className:"h-4 w-4 shrink-0"}),t.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[t.jsx("span",{className:"typography-ui-label font-normal truncate",children:V(pt.slug)}),pt.slug==="tunnel"&&t.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:c("settings.view.badge.beta")})]})]})})},pt.slug)})})}),t.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:t.jsx("div",{className:"border-t border-border bg-sidebar px-2 py-1 space-y-0.5",children:!ae.isVSCode&&t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsxs("button",{type:"button",className:ce("flex h-7 w-full items-center gap-2 rounded-md px-2 overflow-hidden whitespace-nowrap","text-sm font-semibold text-sidebar-foreground/90","hover:text-sidebar-foreground hover:bg-interactive-hover"),onClick:pv,children:[t.jsx(E,{name:"restart",className:"h-4 w-4 shrink-0"}),t.jsx("span",{children:c("settings.view.actions.reloadOpenCode")})]})}),t.jsx(It,{children:c("settings.view.actions.reloadOpenCodeTooltip")})]})})})]})},qt=()=>{if(x==="nav")return t.jsx("div",{className:ce("flex-1 min-h-0 overflow-hidden",ae.isVSCode?"bg-background":"bg-sidebar"),children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:t.jsx(pn,{children:Ht()})})});if(!$e)return t.jsx("div",{className:"flex-1 bg-background"});if(x==="page-sidebar"){if($e.kind!=="split"){const pt=bt(f);return t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(pn,{children:pt})})}return t.jsx("div",{className:ce("flex-1 min-h-0 overflow-hidden",ae.isVSCode?"bg-background":"bg-sidebar"),children:t.jsx(pn,{children:Ze(f,{onItemSelect:bs})})})}const ut=bt(f);return t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(pn,{children:ut})})};let Vt;e[115]!==$e||e[116]!==ze||e[117]!==bt||e[118]!==ae.isVSCode||e[119]!==f?(Vt=()=>!$e||f==="home"?t.jsx(ei,{onOpen:ze}):$e.kind==="split"?t.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[t.jsx("div",{className:ce("w-[264px] min-w-[264px] border-r",ae.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:t.jsx(pn,{children:Ze(f,{})})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:t.jsx(pn,{children:bt(f)})})]}):t.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:t.jsx(pn,{children:bt(f)})}),e[115]=$e,e[116]=ze,e[117]=bt,e[118]=ae.isVSCode,e[119]=f,e[120]=Vt):Vt=e[120];const ps=Vt,vs="true";let Jt;e[121]===Symbol.for("react.memo_cache_sentinel")?(Jt=ce("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[121]=Jt):Jt=e[121];const Es=m?t.jsxs("div",{className:ce("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 border-b px-3","bg-background"),style:{borderColor:"var(--interactive-border)"},children:[Ve||n?t.jsx("button",{type:"button",onClick:Ve?Yt:n,"aria-label":kt,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:t.jsx(E,{name:"arrow-left-s",className:"h-5 w-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:x==="nav"?c("settings.view.home.title"):$e?V($e.slug):c("settings.view.home.title")}),Ge&&t.jsx("button",{type:"button",onClick:vt,"aria-label":c("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:t.jsx(E,{name:"list-unordered",className:"h-5 w-5"})}),n&&t.jsx("button",{type:"button",onClick:n,"aria-label":c("settings.view.actions.closeSettings"),title:c("settings.view.actions.closeSettingsWithShortcut",{shortcut:ht}),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:t.jsx(E,{name:"close",className:"h-5 w-5"})})]}):t.jsxs(t.Fragment,{children:[Ve&&t.jsx("div",{className:ce("absolute left-3 z-50",r?"top-2":"top-3"),children:t.jsx("button",{type:"button",onClick:Yt,"aria-label":c("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:t.jsx(E,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&t.jsx("div",{className:ce("absolute right-0.5 z-50",r?"top-0.5":"top-1"),children:t.jsx("button",{type:"button",onClick:n,"aria-label":c("settings.view.actions.closeSettings"),title:c("settings.view.actions.closeSettingsWithShortcut",{shortcut:ht}),className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:t.jsx(E,{name:"close",className:"h-5 w-5"})})})]}),Nn="flex flex-1 min-h-0 overflow-hidden",_s=m?qt():t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:ce("relative flex h-full min-h-0 flex-col overflow-hidden border-r",F?"bg-sidebar":ae.isVSCode?"bg-background":"bg-sidebar",A?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${I}px`,minWidth:`${I}px`,borderColor:"var(--interactive-border)"},children:[t.jsx("div",{className:ce("absolute right-0 top-0 z-20 h-full w-[6px] -mr-[3px] cursor-col-resize","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",A?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:Ae,onKeyDown:De,role:"separator","aria-orientation":"vertical","aria-valuemin":ki,"aria-valuemax":Si,"aria-valuenow":I,"aria-label":c("settings.view.actions.resizeNavigation")}),t.jsx(pn,{children:Ht()})]}),t.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:ps()})]});let Ms;e[122]!==_s?(Ms=t.jsx("div",{className:Nn,children:_s}),e[122]=_s,e[123]=Ms):Ms=e[123];let nn;return e[124]!==Jt||e[125]!==Es||e[126]!==Ms?(nn=t.jsxs("div",{ref:W,"data-settings-view":vs,className:Jt,children:[Es,Ms]}),e[124]=Jt,e[125]=Es,e[126]=Ms,e[127]=nn):nn=e[127],nn};function Yb(s){return s.settingsPage}function Xb(s){return s.isSettingsDialogOpen}function Zb(s){return s.setSettingsPage}function ev(s){return s.slug!=="home"}function tv(s,e){return[s,e]}function sv(s){return s.activeProjectId}function nv(s){return s.name}function av(s){return s.name}function rv(s){return s.name}function iv(s){return s.name}function ov(s){return s.name}function lv(s){if(s.id.startsWith("agents.")){const e=cr.getState(),n=fa("new-agent",e.agents.map(nv));return e.setAgentDraft({name:n,scope:"user"}),e.setSelectedAgent(n),s.id==="agents.create"?"agents.name":s.id}if(s.id.startsWith("commands.")){const e=dr.getState(),n=fa("new-command",e.commands.map(av));return e.setCommandDraft({name:n,scope:"user"}),e.setSelectedCommand(n),s.id==="commands.create"?"commands.name":s.id}if(s.id.startsWith("mcp.")){const e=Zn.getState(),n=fa("new-mcp-server",e.mcpServers.map(rv));return e.setMcpDraft({name:n,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),e.setSelectedMcp(n),s.id==="mcp.create"?"mcp.server":s.id}if(s.id.startsWith("snippets.")){const e=mr.getState(),n=fa("new-snippet",e.snippets.map(iv));return e.setSnippetDraft({name:n,scope:"global"}),e.setSelectedSnippet(n),s.id==="snippets.create"?"snippets.content":s.id}if(s.id.startsWith("skills.")){const e=Zs.getState(),n=fa("new-skill",e.skills.map(ov));return e.setSkillDraft({name:n,scope:"user",source:"opencode",description:"",instructions:""}),e.setSelectedSkill(n),s.id==="skills.create"?"skills.basic-information":s.id}return s.id==="providers.connect"&<.getState().setSelectedProvider(Gb),s.id==="plugins.create"?"plugins.spec":s.id}function cv(){window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))}function dv(s,e){switch(s){case"projects":return t.jsx(Ff,{onItemSelect:e.onItemSelect});case"agents":return t.jsx(Jp,{onItemSelect:e.onItemSelect});case"commands":return t.jsx(og,{onItemSelect:e.onItemSelect});case"mcp":return t.jsx(fg,{onItemSelect:e.onItemSelect});case"plugins":return t.jsx(bh,{onItemSelect:e.onItemSelect});case"skills.installed":return t.jsx(Th,{onItemSelect:e.onItemSelect});case"providers":return t.jsx(Fx,{onItemSelect:e.onItemSelect});case"usage":return t.jsx(Zx,{onItemSelect:e.onItemSelect});case"magic-prompts":return t.jsx(Ny,{onItemSelect:e.onItemSelect});case"snippets":return t.jsx(Iy,{onItemSelect:e.onItemSelect});default:return null}}function uv(s){return s==="page-content"?"page-sidebar":s}function mv(){}function pv(){Jn({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]}).catch(mv)}const Zj=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:Qb,getSettingsNavIcon:Xc},Symbol.toStringTag,{value:"Module"})),gv=["chat","git","diff","terminal","files","diagram"],hv=["settings","agents","commands","skills","providers","usage","git-identities"],Ls={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Kl(s){const e=fv();return{sessionId:xv(e),tab:yv(e),settingsPath:bv(e),diffFile:vv(e)}}function fv(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function xv(s){const e=s.get(Ls.SESSION);return!e||e.trim().length===0?null:e.trim()}function yv(s){const e=s.get(Ls.TAB);if(!e)return null;const n=e.toLowerCase().trim();return gv.includes(n)?n:null}function bv(s){const e=s.get(Ls.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(hv.includes(n),n)}function vv(s){const e=s.get(Ls.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Ul(){if(typeof window>"u")return!1;try{const s=new URLSearchParams(window.location.search);return s.has(Ls.SESSION)||s.has(Ls.TAB)||s.has(Ls.SETTINGS)||s.has(Ls.FILE)}catch{return!1}}const jv="chat";function Zc(s){const e=new URLSearchParams;if(s.sessionId&&s.sessionId.trim().length>0&&e.set(Ls.SESSION,s.sessionId),s.isSettingsOpen){const n=s.settingsPath.trim().length>0?s.settingsPath:"home";return e.set(Ls.SETTINGS,n),e}return s.tab!==jv&&e.set(Ls.TAB,s.tab),s.tab==="diff"&&s.diffFile&&s.diffFile.trim().length>0&&e.set(Ls.FILE,s.diffFile),e}function wv(s,e){const n=typeof window<"u"?window.location.pathname:"/",a=s.toString();return a?`${n}?${a}`:n}function Nv(s){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Zc(s),a=[...e.entries()].sort((i,l)=>i[0].localeCompare(l[0])),r=[...n.entries()].sort((i,l)=>i[0].localeCompare(l[0]));if(a.length!==r.length)return!1;for(let i=0;i<a.length;i++)if(a[i][0]!==r[i][0]||a[i][1]!==r[i][1])return!1;return!0}catch{return!0}}function Bl(s,e={}){if(!(typeof window>"u")&&!kv()&&!(!e.force&&Nv(s)))try{const n=Zc(s),a=wv(n);e.replace?window.history.replaceState({...window.history.state,route:s},"",a):window.history.pushState({route:s},"",a)}catch{}}function kv(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function Sv(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function ew(){const s=o.useMemo(()=>Sv(),[]),e=o.useRef(!1),n=o.useRef(!1),a=fs(p=>p.setCurrentSession),r=Ie(p=>p.setActiveMainTab),i=Ie(p=>p.setSettingsDialogOpen),l=Ie(p=>p.setSettingsPage),d=Ie(p=>p.navigateToDiff),c=o.useCallback(async p=>{if(!n.current){n.current=!0;try{if(p.sessionId){const u=fs.getState().currentSessionId;if(p.sessionId!==u){const w=fs.getState().getDirectoryForSession(p.sessionId);a(p.sessionId,w)}}if(p.settingsPath){l(Fi(p.settingsPath)),i(!0);return}Ie.getState().isSettingsDialogOpen&&i(!1),p.tab&&r(p.tab),p.diffFile&&(p.tab==="diff"||!p.tab)&&d(p.diffFile)}finally{n.current=!1}}},[a,r,i,l,d]),h=o.useCallback(()=>{const p=fs.getState(),u=Ie.getState();return{sessionId:p.currentSessionId,tab:u.activeMainTab,isSettingsOpen:u.isSettingsDialogOpen,settingsPath:u.settingsPage,diffFile:u.pendingDiffFile}},[]),m=o.useCallback((p={})=>{if(s||n.current)return;const u=h();Bl(u,p)},[s,h]);o.useEffect(()=>{if(e.current||(e.current=!0,!Ul()))return;const p=Kl();(async()=>(await c(p),s||Bl({...h(),sessionId:p.sessionId??fs.getState().currentSessionId,tab:p.tab??Ie.getState().activeMainTab,settingsPath:p.settingsPath??Ie.getState().settingsPage,diffFile:p.diffFile??Ie.getState().pendingDiffFile},{replace:!0,force:!0})))()},[c,h,s]),o.useEffect(()=>{if(s)return;let p=fs.getState().currentSessionId;return fs.subscribe(w=>{const g=w.currentSessionId;g===p||n.current||(p=g,m())})},[s,m]),o.useEffect(()=>{if(s)return;let p=Ie.getState().activeMainTab,u=Ie.getState().isSettingsDialogOpen,w=Ie.getState().settingsPage,g=Ie.getState().pendingDiffFile;return Ie.subscribe(x=>{if(n.current)return;const D=x.activeMainTab!==p,P=x.isSettingsDialogOpen!==u,I=x.settingsPage!==w,L=x.pendingDiffFile!==g&&x.activeMainTab==="diff";p=x.activeMainTab,u=x.isSettingsDialogOpen,w=x.settingsPage,g=x.pendingDiffFile,(D||P||I||L)&&m()})},[s,m]),o.useEffect(()=>{if(typeof window>"u"||s)return;const p=()=>{const u=Kl();if(Ul())c(u);else{const w=Ie.getState();w.isSettingsDialogOpen&&i(!1),w.activeMainTab!=="chat"&&r("chat")}};return window.addEventListener("popstate",p),()=>{window.removeEventListener("popstate",p)}},[c,s,r,i])}function tw(){const s=et.c(5),e=vc(Iv),n=o.useRef(e);let a,r;s[0]!==e?(a=()=>{n.current=e},r=[e],s[0]=e,s[1]=a,s[2]=r):(a=s[1],r=s[2]),o.useEffect(a,r);let i,l;s[3]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{let d=!1,c=null;const h=Cv,m=p=>{d||(c=window.setTimeout(async()=>{const u=await n.current(),w=typeof u=="number"&&Number.isFinite(u)?h(u):36e5;m(w)},p))};return m(3e3),()=>{d=!0,c!==null&&window.clearTimeout(c)}},l=[],s[3]=i,s[4]=l):(i=s[3],l=s[4]),o.useEffect(i,l)}function Cv(s){const e=Math.round(s*1e3);return Math.max(3e5,Math.min(864e5,e))}function Iv(s){return s.checkForUpdates}const ed={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}},Pv=ed.M;function Av(s){const e=s.index?.trim(),n=s.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"}function Dv(s){const e=Av(s);return ed[e]??Pv}const Ev=o.memo(function(e){const n=et.c(58),{file:a,actionLabel:r,actionSymbol:i,onAction:l,onViewDiff:d,onRevert:c,isReverting:h,stats:m,rowPaddingClassName:p,indentPx:u,actionAtStart:w,showRevert:g}=e,f=u===void 0?0:u,x=w===void 0?!1:w,D=g===void 0?!0:g;let P;n[0]!==a?(P=Dv(a),n[0]=a,n[1]=P):P=n[1];const I=P,{t:L}=st(),N=I.description,b=m?.insertions??0,j=m?.deletions??0;let T;n[2]!==l||n[3]!==d?(T=ye=>{ye.key===" "?(ye.preventDefault(),l()):ye.key==="Enter"&&(ye.preventDefault(),d())},n[2]=l,n[3]=d,n[4]=T):T=n[4];const U=T;let K;n[5]!==l?(K=ye=>{ye.preventDefault(),ye.stopPropagation(),l()},n[5]=l,n[6]=K):K=n[6];const M=K;let C;n[7]!==c?(C=ye=>{ye.preventDefault(),ye.stopPropagation(),c()},n[7]=c,n[8]=C):C=n[8];const A=C;let z;n[9]!==r||n[10]!==i||n[11]!==M?(z=t.jsx("button",{type:"button",onClick:M,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":r,title:r,children:i}),n[9]=r,n[10]=i,n[11]=M,n[12]=z):z=n[12];const R=z,Q=`group flex items-center gap-2 py-1.5 cursor-pointer ${p??"px-3"}`;let W;n[13]!==f?(W=f>0?{paddingLeft:`${f}px`}:void 0,n[13]=f,n[14]=W):W=n[14];const te=x?R:null;let Y;n[15]!==I.color?(Y={color:I.color},n[15]=I.color,n[16]=Y):Y=n[16];let k;n[17]!==I.code||n[18]!==N||n[19]!==Y?(k=t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:Y,title:N,"aria-label":N,children:I.code}),n[17]=I.code,n[18]=N,n[19]=Y,n[20]=k):k=n[20];let $;n[21]!==a.path?($=t.jsx(fm,{filePath:a.path,className:"h-3.5 w-3.5 shrink-0"}),n[21]=a.path,n[22]=$):$=n[22];let B;if(n[23]!==a.path){e:{const ye=a.path.lastIndexOf("/");if(ye===-1){let ve;n[25]===Symbol.for("react.memo_cache_sentinel")?(ve={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[25]=ve):ve=n[25],B=t.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:ve,title:a.path,children:a.path});break e}const ke=a.path.slice(0,ye),he=a.path.slice(ye);let we;n[26]===Symbol.for("react.memo_cache_sentinel")?(we={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[26]=we):we=n[26];let de;n[27]===Symbol.for("react.memo_cache_sentinel")?(de=t.jsx("span",{className:"text-muted-foreground",children:"/"}),n[27]=de):de=n[27];const Z=t.jsx("span",{className:"text-foreground",children:he.slice(1)});let se;n[28]!==Z?(se=t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[de,Z]}),n[28]=Z,n[29]=se):se=n[29],B=t.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:a.path,children:[t.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:we,children:ke}),se]})}n[23]=a.path,n[24]=B}else B=n[24];let F;n[30]===Symbol.for("react.memo_cache_sentinel")?(F={color:"var(--status-success)"},n[30]=F):F=n[30];let O;n[31]!==b?(O=t.jsxs("span",{style:F,children:["+",b]}),n[31]=b,n[32]=O):O=n[32];let J,H;n[33]===Symbol.for("react.memo_cache_sentinel")?(J=t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),H={color:"var(--status-error)"},n[33]=J,n[34]=H):(J=n[33],H=n[34]);let re;n[35]!==j?(re=t.jsxs("span",{style:H,children:["-",j]}),n[35]=j,n[36]=re):re=n[36];let le;n[37]!==O||n[38]!==re?(le=t.jsxs("span",{className:"shrink-0 typography-micro",children:[O,J,re]}),n[37]=O,n[38]=re,n[39]=le):le=n[39];let ne;n[40]!==a.path||n[41]!==A||n[42]!==h||n[43]!==D||n[44]!==L?(ne=D?t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx("button",{type:"button",onClick:A,disabled:h,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":L("gitView.changes.revertFileAria",{path:a.path}),children:h?t.jsx(E,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(E,{name:"arrow-go-back",className:"size-3.5"})})}),t.jsx(It,{sideOffset:8,children:L("gitView.changes.revertFileTooltip")})]}):null,n[40]=a.path,n[41]=A,n[42]=h,n[43]=D,n[44]=L,n[45]=ne):ne=n[45];const be=x?null:R;let ae;return n[46]!==U||n[47]!==d||n[48]!==W||n[49]!==te||n[50]!==k||n[51]!==$||n[52]!==B||n[53]!==le||n[54]!==ne||n[55]!==be||n[56]!==Q?(ae=t.jsxs("div",{className:Q,role:"button",tabIndex:0,onClick:d,onKeyDown:U,style:W,children:[te,k,$,B,le,ne,be]}),n[46]=U,n[47]=d,n[48]=W,n[49]=te,n[50]=k,n[51]=$,n[52]=B,n[53]=le,n[54]=ne,n[55]=be,n[56]=Q,n[57]=ae):ae=n[57],ae}),$l=14,td=s=>s.replace(/\\/g,"/").replace(/^\/+/,"").trim(),Vl=(s,e)=>({id:`dir:${s}`,path:s,name:e,children:new Map,directFiles:[],files:[]}),Mv=s=>{const e=Vl("","");for(const n of s){const a=td(n.path);if(!a)continue;const i=a.split("/").filter(Boolean).slice(0,-1);let l=e;if(l.files.push(n),i.length>0){let d="";for(const c of i){d=d?`${d}/${c}`:c;const h=l.children.get(c);if(h){h.files.push(n),l=h;continue}const m=Vl(d,c);m.files.push(n),l.children.set(c,m),l=m}}l.directFiles.push(n)}return e},Tv=(s,e)=>{const n=[],a=(r,i)=>{const l=Array.from(r.children.values()).sort((c,h)=>c.path.localeCompare(h.path));for(const c of l)n.push({key:c.id,kind:"directory",depth:i,directory:c}),e.has(c.path)&&a(c,i+1);const d=[...r.directFiles].sort((c,h)=>c.path.localeCompare(h.path));for(const c of d)n.push({key:`file:${td(c.path)}`,kind:"file",depth:i,file:c})};return a(s,0),n},Rv=1e3,_l=34,ti=30,$a="pl-0 pr-2",si=(s,e)=>`${s} ${e}`,sw=({groups:s,diffStats:e,revertingPaths:n,isRevertingAll:a=!1,headerBackgroundClassName:r="bg-sidebar",onVisiblePathsChange:i,onRevertAll:l,onRevertDirectory:d})=>{const{t:c}=st(),h=o.useRef(null),p=Ie(O=>O.gitChangesViewMode)==="tree",u=o.useMemo(()=>s.filter(O=>O.entries.length>0),[s]),[w,g]=o.useState(new Set),[f,x]=o.useState(new Set),[D,P]=o.useState(!1),[I,L]=o.useState(null),N=o.useMemo(()=>u.map(O=>Mv(O.entries)),[u]),b=o.useMemo(()=>{const O=[];return u.forEach((J,H)=>{Array.from(N[H]?.children.values()??[]).forEach(re=>{O.push(si(J.id,re.path))})}),O},[N,u]);o.useEffect(()=>{p&&x(O=>{const J=new Set,H=new Set(b);return O.forEach(re=>{(re.slice(re.indexOf(" ")+1).includes("/")||H.has(re))&&J.add(re)}),b.forEach(re=>J.add(re)),J})},[p,b]);const j=o.useMemo(()=>{const O=[];return u.forEach((J,H)=>{if(O.push({type:"header",key:`header:${J.id}`,groupIndex:H}),!w.has(J.id)){if(p){const re=new Set;f.forEach(ne=>{ne.startsWith(`${J.id} `)&&re.add(ne.slice(J.id.length+1))}),Tv(N[H],re).forEach(ne=>{ne.kind==="file"?O.push({type:"file",key:`${J.id}:${ne.key}`,groupIndex:H,file:ne.file,depth:ne.depth}):O.push({type:"directory",key:`${J.id}:${ne.key}`,groupIndex:H,directory:ne.directory,depth:ne.depth})});return}J.entries.forEach(re=>{O.push({type:"file",key:`${J.id}:file:${re.path}`,groupIndex:H,file:re,depth:0})})}}),l&&u.length>0&&O.push({type:"revert-all",key:"revert-all"}),O},[w,f,p,l,N,u]),T=j.length,U=T>=Rv,K=Qd({count:T,enabled:U,getScrollElement:()=>h.current,estimateSize:()=>_l,overscan:12,getItemKey:O=>j[O]?.key??O}),M=K.getVirtualItems(),C=o.useMemo(()=>{if(!U)return 0;const O=h.current?.scrollTop??0;return M.find(H=>H.end>O)?.index??0},[U,M,h]);o.useEffect(()=>{if(!i)return;const O=J=>J&&J.type==="file"?J.file.path:null;if(T===0){i([]);return}if(!U){const J=[];for(const H of j)if(H.type==="file"&&(J.push(H.file.path),J.length>=ti))break;i(J);return}i(j.slice(C,C+Math.ceil((h.current?.clientHeight??0)/_l)+ti).map(J=>O(J)).filter(J=>!!J).slice(0,ti))},[i,T,j,U,C]);const A=o.useCallback(O=>{g(J=>{const H=new Set(J);return H.has(O)?H.delete(O):H.add(O),H})},[]),z=o.useCallback((O,J)=>{x(H=>{const re=new Set(H),le=si(O,J);return re.has(le)?re.delete(le):re.add(le),re})},[]),R=o.useMemo(()=>{const O=new Set;return u.forEach(J=>J.entries.forEach(H=>O.add(H.path))),Array.from(O)},[u]),Q=R.length,W=I?a||I.paths.some(O=>n.has(O)):!1,te=o.useCallback(async()=>{!l||a||R.length===0||(await l(R),P(!1))},[R,a,l]),Y=o.useCallback(async()=>{!d||!I||W||(await d(I.paths),L(null))},[W,d,I]),k=o.useCallback((O,J)=>{const H=w.has(O.id),re=O.entries.length;return t.jsxs("div",{className:ce("sticky top-0 z-10 flex items-center gap-2 py-2",r,$a,!J&&"mt-1 border-t border-border/40"),children:[t.jsx("button",{type:"button",onClick:()=>O.onActionAll(O.entries.map(le=>le.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":O.actionAllLabel,title:O.actionAllLabel,children:O.actionSymbol}),t.jsxs("button",{type:"button",onClick:()=>A(O.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!H,children:[t.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:O.title}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:re}),t.jsx(E,{name:"arrow-down-s",className:ce("size-3.5 shrink-0 text-muted-foreground transition-transform",H&&"-rotate-90")})]})]})},[w,r,A]),$=o.useCallback((O,J,H)=>{const re=f.has(si(O.id,J.path)),le=J.files.map(be=>be.path),ne=a||le.some(be=>n.has(be));return t.jsxs("div",{className:ce("group flex items-center gap-2 py-1.5",$a),style:{paddingLeft:`${H*$l}px`},children:[t.jsxs("button",{type:"button",onClick:()=>z(O.id,J.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":re?c("gitView.changes.collapseDirectoryAria",{path:J.path}):c("gitView.changes.expandDirectoryAria",{path:J.path}),children:[re?t.jsx(E,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):t.jsx(E,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:J.path,children:J.name}),t.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:J.files.length})]}),O.showRevertActions!==!1&&d?t.jsx("button",{type:"button",onClick:()=>L({path:J.path,paths:le,count:le.length}),disabled:ne,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50","aria-label":c("gitView.changes.revertDirectoryAria",{path:J.path}),title:c("gitView.changes.revertDirectoryTooltip"),children:ne?t.jsx(E,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(E,{name:"arrow-go-back",className:"size-3.5"})}):null,t.jsx("button",{type:"button",onClick:()=>O.onActionAll(J.files.map(be=>be.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":c(O.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:J.path}),title:c(O.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:J.path}),children:O.actionSymbol})]})},[f,a,d,n,c,z]),B=o.useCallback((O,J)=>{if(O.type==="revert-all")return t.jsx("div",{className:ce("flex justify-end py-2",$a),children:t.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>P(!0),disabled:a,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[t.jsx(E,{name:"arrow-go-back",className:"size-3.5"}),c("gitView.changes.revertAll")]})});const H=u[O.groupIndex];if(!H)return null;if(O.type==="header")return k(H,J);if(O.type==="directory")return $(H,O.directory,O.depth);const re=O.file;return t.jsx(Ev,{file:re,actionLabel:H.getActionLabel(re.path),actionSymbol:H.actionSymbol,onAction:()=>H.onActionFile(re.path),stats:e?.[re.path],onViewDiff:()=>H.onViewDiff(re.path),onRevert:()=>H.onRevertFile(re.path),isReverting:n.has(re.path)||a,rowPaddingClassName:$a,indentPx:O.depth*$l,actionAtStart:!p,showRevert:H.showRevertActions!==!1})},[e,a,p,$,k,n,c,u]),F=o.useCallback(O=>{const J=j[O],H=j[O-1];return!J||!H||J.type!=="file"&&J.type!=="directory"||H.type!=="file"&&H.type!=="directory"?!1:H.groupIndex===J.groupIndex},[j]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[t.jsx(xm,{ref:h,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:U?t.jsx("div",{style:{height:K.getTotalSize(),position:"relative"},children:M.map(O=>{const J=j[O.index];return J?t.jsx("div",{"data-index":O.index,ref:K.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${O.start}px)`},className:ce(F(O.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:B(J,O.index===0)},J.key):null})}):t.jsx("div",{role:"list","aria-label":c("gitView.changes.changedFilesAria"),children:j.map((O,J)=>t.jsx("div",{className:ce("relative",F(J)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:B(O,J===0)},O.key))})}),t.jsx(ym,{containerRef:h,disableHorizontal:!0})]}),t.jsx(Rt,{open:D,onOpenChange:O=>{!a&&!O&&P(!1)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:c("gitView.changes.revertAllDialogTitle")}),t.jsx($t,{children:Q===1?c("gitView.changes.revertAllDescriptionSingle",{count:Q}):c("gitView.changes.revertAllDescriptionPlural",{count:Q})})]}),t.jsxs(Gt,{children:[t.jsx(q,{variant:"outline",size:"sm",onClick:()=>P(!1),disabled:a,children:c("gitView.common.cancel")}),t.jsx(q,{variant:"destructive",size:"sm",onClick:()=>{te()},disabled:a,children:c(a?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})}),t.jsx(Rt,{open:!!I,onOpenChange:O=>{!W&&!O&&L(null)},children:t.jsxs(Ft,{className:"max-w-md",children:[t.jsxs(Kt,{children:[t.jsx(zt,{children:c("gitView.changes.revertDirectoryDialogTitle")}),t.jsx($t,{children:I?I.count===1?c("gitView.changes.revertDirectoryDescriptionSingle",{count:I.count,path:I.path}):c("gitView.changes.revertDirectoryDescriptionPlural",{count:I.count,path:I.path}):null})]}),t.jsxs(Gt,{children:[t.jsx(q,{variant:"outline",size:"sm",onClick:()=>L(null),disabled:W,children:c("gitView.common.cancel")}),t.jsx(q,{variant:"destructive",size:"sm",onClick:()=>{Y()},disabled:W||!I,children:c(W?"gitView.changes.reverting":"gitView.changes.revertDirectory")})]})]})})]})},ni=38,Va=200,Fv=s=>{const e=et.c(20),{value:n,onChange:a,placeholder:r,disabled:i,hasTouchInput:l,isMobile:d}=s,c=i===void 0?!1:i,h=l===void 0?!1:l,m=d===void 0?!1:d,{t:p}=st(),u=o.useRef(null),w=Ie(Lv);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{const U=u.current;if(!U)return;const K=document.activeElement===U,M=()=>{U.style.height=`${ni}px`;const A=U.scrollHeight,z=Math.min(Math.max(A,ni),Va);U.style.height=`${z}px`,U.style.overflowY=A>Va?"auto":"hidden",A>Va&&!K&&(U.scrollTop=U.scrollHeight)};M();const C=window.requestAnimationFrame(M);return()=>{window.cancelAnimationFrame(C)}},e[0]=g):g=e[0];let f;e[1]!==n?(f=[n],e[1]=n,e[2]=f):f=e[2],o.useLayoutEffect(g,f);let x;e[3]!==a?(x=U=>a(U.target.value),e[3]=a,e[4]=x):x=e[4];let D;e[5]!==r||e[6]!==p?(D=r??p("gitView.commit.messagePlaceholder"),e[5]=r,e[6]=p,e[7]=D):D=e[7];const P=h?"on":"off",I=h?"sentences":"off",L=m||w,N=c&&"opacity-50";let b;e[8]!==N?(b=ce("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",N),e[8]=N,e[9]=b):b=e[9];let j;e[10]===Symbol.for("react.memo_cache_sentinel")?(j={minHeight:ni,maxHeight:Va},e[10]=j):j=e[10];let T;return e[11]!==c||e[12]!==L||e[13]!==b||e[14]!==x||e[15]!==D||e[16]!==P||e[17]!==I||e[18]!==n?(T=t.jsx("textarea",{ref:u,value:n,onChange:x,placeholder:D,rows:1,disabled:c,autoCorrect:P,autoCapitalize:I,spellCheck:L,className:b,style:j}),e[11]=c,e[12]=L,e[13]=b,e[14]=x,e[15]=D,e[16]=P,e[17]=I,e[18]=n,e[19]=T):T=e[19],T};function Lv(s){return s.inputSpellcheckEnabled}const Ov=s=>{const e=et.c(30),{highlights:n,onInsert:a}=s,{t:r}=st();if(n.length===0)return null;let i;e[0]!==n||e[1]!==a?(i=()=>{a(n)},e[0]=n,e[1]=a,e[2]=i):i=e[2];const l=i;let d;e[3]!==r?(d=r("gitView.commit.aiHighlights.title"),e[3]=r,e[4]=d):d=e[4];let c;e[5]!==d?(c=t.jsx("p",{className:"typography-micro text-muted-foreground",children:d}),e[5]=d,e[6]=c):c=e[6];let h;e[7]!==r?(h=r("gitView.commit.aiHighlights.insertAria"),e[7]=r,e[8]=h):h=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsx(E,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let p;e[10]!==l||e[11]!==h?(p=t.jsx(Ct,{asChild:!0,children:t.jsx(q,{variant:"ghost",size:"icon",className:"size-6",onClick:l,"aria-label":h,children:m})}),e[10]=l,e[11]=h,e[12]=p):p=e[12];let u;e[13]!==r?(u=r("gitView.commit.aiHighlights.insertTooltip"),e[13]=r,e[14]=u):u=e[14];let w;e[15]!==u?(w=t.jsx(It,{sideOffset:8,children:u}),e[15]=u,e[16]=w):w=e[16];let g;e[17]!==p||e[18]!==w?(g=t.jsxs(St,{children:[p,w]}),e[17]=p,e[18]=w,e[19]=g):g=e[19];let f;e[20]!==c||e[21]!==g?(f=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c,g]}),e[20]=c,e[21]=g,e[22]=f):f=e[22];let x;e[23]!==n?(x=n.map(zv),e[23]=n,e[24]=x):x=e[24];let D;e[25]!==x?(D=t.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=D):D=e[26];let P;return e[27]!==f||e[28]!==D?(P=t.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[f,D]}),e[27]=f,e[28]=D,e[29]=P):P=e[29],P};function zv(s,e){return t.jsx("li",{className:"typography-meta text-foreground",children:s},`${s}-${e}`)}const nw=s=>{const e=et.c(75),{stagedCount:n,commitMessage:a,onCommitMessageChange:r,generatedHighlights:i,onInsertHighlights:l,onGenerateMessage:d,isGeneratingMessage:c,onCommit:h,onCommitAndPush:m,commitAction:p,hasPendingIndexMutation:u,gitmojiEnabled:w,onOpenGitmojiPicker:g}=s,f=u===void 0?!1:u,{t:x}=st(),D=n>0;let P;e[0]!==p||e[1]!==a||e[2]!==f||e[3]!==D?(P=a.trim()&&D&&p===null&&!f,e[0]=p,e[1]=a,e[2]=f,e[3]=D,e[4]=P):P=e[4];const I=P,{isMobile:L,hasTouchInput:N}=Ds();let b;e[5]!==x?(b=x("gitView.commit.title"),e[5]=x,e[6]=b):b=e[6];let j;e[7]!==b?(j=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:b}),e[7]=b,e[8]=j):j=e[8];let T;e[9]!==D||e[10]!==x?(T=D?null:t.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:x("gitView.commit.stageFilesHint")}),e[9]=D,e[10]=x,e[11]=T):T=e[11];let U;e[12]!==j||e[13]!==T?(U=t.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[j,T]}),e[12]=j,e[13]=T,e[14]=U):U=e[14];let K;e[15]!==i||e[16]!==l?(K=t.jsx(Ov,{highlights:i,onInsert:l}),e[15]=i,e[16]=l,e[17]=K):K=e[17];let M;e[18]!==x?(M=x("gitView.commit.messagePlaceholder"),e[18]=x,e[19]=M):M=e[19];const C=p!==null;let A;e[20]!==a||e[21]!==N||e[22]!==L||e[23]!==r||e[24]!==M||e[25]!==C?(A=t.jsx(Fv,{value:a,onChange:r,placeholder:M,disabled:C,hasTouchInput:N,isMobile:L}),e[20]=a,e[21]=N,e[22]=L,e[23]=r,e[24]=M,e[25]=C,e[26]=A):A=e[26];let z;e[27]!==w||e[28]!==g||e[29]!==x?(z=w&&t.jsxs(q,{variant:"outline",size:"sm",onClick:g,className:"w-fit",type:"button",children:[t.jsx(E,{name:"emotion-happy",className:"size-4"}),x("gitView.commit.addGitmoji")]}),e[27]=w,e[28]=g,e[29]=x,e[30]=z):z=e[30];const R=c||p!==null||f||n===0;let Q;e[31]!==x?(Q=x("gitView.commit.generateAria"),e[31]=x,e[32]=Q):Q=e[32];let W;e[33]!==c?(W=c?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"ai-generate-2",className:"size-4 text-primary"}),e[33]=c,e[34]=W):W=e[34];let te;e[35]!==x?(te=x("gitView.commit.generate"),e[35]=x,e[36]=te):te=e[36];let Y;e[37]!==te?(Y=t.jsx("span",{className:"commit-actions__label",children:te}),e[37]=te,e[38]=Y):Y=e[38];let k;e[39]!==d||e[40]!==R||e[41]!==Q||e[42]!==W||e[43]!==Y?(k=t.jsxs(q,{variant:"outline",size:"sm",onClick:d,disabled:R,type:"button","aria-label":Q,className:"commit-actions__btn",children:[W,Y]}),e[39]=d,e[40]=R,e[41]=Q,e[42]=W,e[43]=Y,e[44]=k):k=e[44];let $;e[45]===Symbol.for("react.memo_cache_sentinel")?($=t.jsx("div",{className:"flex-1"}),e[45]=$):$=e[45];const B=!I||c;let F;e[46]!==x?(F=x("gitView.commit.commitAria"),e[46]=x,e[47]=F):F=e[47];let O;e[48]!==p||e[49]!==x?(O=p==="commit"?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"commit-actions__label",children:x("gitView.commit.committing")})]}):t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"git-commit",className:"size-4"}),t.jsx("span",{className:"commit-actions__label",children:x("gitView.commit.commit")})]}),e[48]=p,e[49]=x,e[50]=O):O=e[50];let J;e[51]!==h||e[52]!==B||e[53]!==F||e[54]!==O?(J=t.jsx(q,{size:"sm",variant:"outline",onClick:h,disabled:B,className:"commit-actions__btn whitespace-nowrap","aria-label":F,children:O}),e[51]=h,e[52]=B,e[53]=F,e[54]=O,e[55]=J):J=e[55];let H;e[56]!==I||e[57]!==p||e[58]!==c||e[59]!==L||e[60]!==m||e[61]!==x?(H=L?t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(q,{variant:"default",size:"sm",onClick:()=>m(),disabled:!I||c,className:"h-7 w-7 p-0","aria-label":x("gitView.commit.pushAria"),children:p==="commitAndPush"?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"arrow-up",className:"size-3.5"})})}),t.jsx(It,{side:"top",children:t.jsx("p",{children:x("gitView.commit.push")})})]}):t.jsx(q,{size:"sm",variant:"default",onClick:()=>m(),disabled:!I||c,className:"commit-actions__btn","aria-label":x("gitView.commit.pushAria"),children:p==="commitAndPush"?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:x("gitView.commit.pushing")})]}):t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"arrow-up",className:"size-3.5"}),t.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:x("gitView.commit.push")})]})}),e[56]=I,e[57]=p,e[58]=c,e[59]=L,e[60]=m,e[61]=x,e[62]=H):H=e[62];let re;e[63]!==k||e[64]!==J||e[65]!==H?(re=t.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[k,$,J,H]}),e[63]=k,e[64]=J,e[65]=H,e[66]=re):re=e[66];let le;e[67]!==A||e[68]!==z||e[69]!==re||e[70]!==K?(le=t.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[K,A,z,re]}),e[67]=A,e[68]=z,e[69]=re,e[70]=K,e[71]=le):le=e[71];let ne;return e[72]!==le||e[73]!==U?(ne=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[U,le]}),e[72]=le,e[73]=U,e[74]=ne):ne=e[74],ne},Kv=s=>{const e=et.c(41),{syncAction:n,remotes:a,onFetch:r,onSync:i,onRemoveRemote:l,disabled:d,removingRemoteName:c,aheadCount:h,behindCount:m,trackingRemoteName:p,hasUncommittedChanges:u}=s,w=a===void 0?[]:a,g=c===void 0?null:c,f=h===void 0?0:h,x=m===void 0?0:m,D=u===void 0?!1:u,{t:P}=st(),I=o.useRef(!1),L=!!g,N=w.find(se=>se.name===p)??w[0],b=x>0&&D,j=d||n!==null||L||!N||b,T=d||n!==null||L||w.length===0,U=f>0||x>0;let K;e[0]!==P?(K=P("gitView.sync.sync"),e[0]=P,e[1]=K):K=e[1];const M=x>0?`↓${x}`:null,C=f>0?`↑${f}`:null;let A;e[2]!==K||e[3]!==M||e[4]!==C?(A=[K,M,C].filter(Boolean),e[2]=K,e[3]=M,e[4]=C,e[5]=A):A=e[5];const z=A.join(" "),R=b?P("gitView.sync.commitOrStashTooltip"):N?U?P("gitView.sync.syncChangesTooltip",{ahead:f,behind:x}):P("gitView.sync.syncChanges"):P("gitView.sync.noRemoteTooltip"),Q=()=>{N&&i(N)},W="inline-flex items-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] border border-border/60 bg-[var(--surface-elevated)] overflow-hidden";let te;e[6]===Symbol.for("react.memo_cache_sentinel")?(te=ce("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=te):te=e[6];let Y;e[7]!==P?(Y=P("gitView.sync.syncChanges"),e[7]=P,e[8]=Y):Y=e[8];let k;e[9]!==n?(k=n==="sync"?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=k):k=e[10];let $;e[11]!==z?($=t.jsx("span",{className:"whitespace-nowrap tabular-nums",children:z}),e[11]=z,e[12]=$):$=e[12];let B;e[13]!==Q||e[14]!==j||e[15]!==Y||e[16]!==k||e[17]!==$?(B=t.jsx(Ct,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:Q,disabled:j,className:te,"aria-label":Y,children:[k,$]})}),e[13]=Q,e[14]=j,e[15]=Y,e[16]=k,e[17]=$,e[18]=B):B=e[18];let F;e[19]!==R?(F=t.jsx(It,{sideOffset:8,children:R}),e[19]=R,e[20]=F):F=e[20];let O;e[21]!==B||e[22]!==F?(O=t.jsxs(St,{children:[B,F]}),e[21]=B,e[22]=F,e[23]=O):O=e[23];const J=ds;let H;e[24]===Symbol.for("react.memo_cache_sentinel")?(H=ce("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[24]=H):H=e[24];let re;e[25]!==P?(re=P("gitView.sync.moreActionsAria"),e[25]=P,e[26]=re):re=e[26];let le;e[27]===Symbol.for("react.memo_cache_sentinel")?(le=t.jsx(E,{name:"arrow-down-s",className:"size-4"}),e[27]=le):le=e[27];let ne;e[28]!==T||e[29]!==re?(ne=t.jsx(ls,{asChild:!0,children:t.jsx("button",{type:"button",className:H,disabled:T,"aria-label":re,children:le})}),e[28]=T,e[29]=re,e[30]=ne):ne=e[30];const be=cs,ae="start",ye=-40,ke="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",he=w.map(se=>t.jsx(Ns,{onSelect:ve=>{if(I.current){ve.preventDefault(),I.current=!1;return}r(se)},children:t.jsxs("div",{className:"flex w-full items-center gap-2",children:[t.jsx(E,{name:"refresh",className:"size-4 text-muted-foreground"}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:P("gitView.sync.fetchFromRemote",{name:se.name})}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:se.fetchUrl})]})}),l&&se.name!==p?t.jsx(q,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||L,onPointerDown:ve=>{I.current=!0,ve.preventDefault(),ve.stopPropagation()},onClick:ve=>{I.current=!0,ve.preventDefault(),ve.stopPropagation(),l(se)},"aria-label":P("gitView.header.removeRemoteAria",{name:se.name}),title:P("gitView.header.removeRemoteTitle",{name:se.name}),children:g===se.name?t.jsx(E,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(E,{name:"close",className:"size-3.5"})}):null]})},se.name));let we;e[31]!==be||e[32]!==he?(we=t.jsx(be,{align:ae,alignOffset:ye,className:ke,children:he}),e[31]=be,e[32]=he,e[33]=we):we=e[33];let de;e[34]!==J||e[35]!==ne||e[36]!==we?(de=t.jsxs(J,{children:[ne,we]}),e[34]=J,e[35]=ne,e[36]=we,e[37]=de):de=e[37];let Z;return e[38]!==O||e[39]!==de?(Z=t.jsxs("div",{className:W,children:[O,de]}),e[38]=O,e[39]=de,e[40]=Z):Z=e[40],Z};function Uv(s){const e=et.c(85),{draft:n,onEdit:a,onDelete:r,className:i,maxWidth:l}=s,{t:d}=st(),h=lr()?.currentTheme,[m,p]=xe.useState(!1),[u,w]=xe.useState(!1),g=typeof n.text=="string"?n.text:"";let f;e[0]!==g?(f=g.length>150||g.split(`
|
|
30
|
+
`).length>3,e[0]=g,e[1]=f):f=e[1];const x=f;let D;e[2]!==i?(D=ce("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",i),e[2]=i,e[3]=D):D=e[3];const P=h?.colors?.surface?.elevated,I=h?.colors?.interactive?.border,L=l?`${Math.max(200,Math.floor(l))}px`:void 0;let N;e[4]!==P||e[5]!==I||e[6]!==L?(N={backgroundColor:P,borderColor:I,maxWidth:L},e[4]=P,e[5]=I,e[6]=L,e[7]=N):N=e[7];let b;e[8]===Symbol.for("react.memo_cache_sentinel")?(b=G=>{G.preventDefault(),w(!0)},e[8]=b):b=e[8];let j;e[9]!==D||e[10]!==N?(j=t.jsx("div",{className:D,style:N,"data-comment-card":"true",onContextMenu:b}),e[9]=D,e[10]=N,e[11]=j):j=e[11];let T;e[12]!==n.fileLabel?(T=t.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[12]=n.fileLabel,e[13]=T):T=e[13];let U;e[14]===Symbol.for("react.memo_cache_sentinel")?(U=t.jsx("span",{children:"•"}),e[14]=U):U=e[14];let K;e[15]!==n.endLine||e[16]!==n.startLine||e[17]!==d?(K=d("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[15]=n.endLine,e[16]=n.startLine,e[17]=d,e[18]=K):K=e[18];let M;e[19]!==K?(M=t.jsx("span",{children:K}),e[19]=K,e[20]=M):M=e[20];let C;e[21]!==n.side?(C=n.side&&t.jsxs("span",{children:["(",n.side,")"]}),e[21]=n.side,e[22]=C):C=e[22];let A;e[23]!==M||e[24]!==C||e[25]!==T?(A=t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[T,U,M,C]}),e[23]=M,e[24]=C,e[25]=T,e[26]=A):A=e[26];const z=m||!x,R=!m&&x&&"line-clamp-3";let Q;e[27]!==R?(Q=ce("text-sm whitespace-pre-wrap break-words leading-relaxed",R),e[27]=R,e[28]=Q):Q=e[28];let W;e[29]!==g||e[30]!==Q?(W=t.jsx("div",{className:Q,children:g}),e[29]=g,e[30]=Q,e[31]=W):W=e[31];let te;e[32]!==x||e[33]!==m||e[34]!==d?(te=x&&t.jsx(Tn,{asChild:!0,children:t.jsx(q,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"arrow-up-s",className:"size-3 mr-1"}),d("inlineComment.actions.showLess")]}):t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"arrow-down-s",className:"size-3 mr-1"}),d("inlineComment.actions.showMore")]})})}),e[32]=x,e[33]=m,e[34]=d,e[35]=te):te=e[35];let Y;e[36]===Symbol.for("react.memo_cache_sentinel")?(Y=t.jsx(Rn,{}),e[36]=Y):Y=e[36];let k;e[37]!==z||e[38]!==W||e[39]!==te?(k=t.jsxs(Mn,{open:z,onOpenChange:p,children:[W,te,Y]}),e[37]=z,e[38]=W,e[39]=te,e[40]=k):k=e[40];let $;e[41]!==A||e[42]!==k?($=t.jsxs("div",{className:"flex-1 min-w-0",children:[A,k]}),e[41]=A,e[42]=k,e[43]=$):$=e[43];let B;e[44]===Symbol.for("react.memo_cache_sentinel")?(B=t.jsx(ls,{asChild:!0,children:t.jsx(q,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:t.jsx(E,{name:"more",className:"size-4"})})}),e[44]=B):B=e[44];let F;e[45]===Symbol.for("react.memo_cache_sentinel")?(F=t.jsx(E,{name:"edit",className:"size-4 mr-2"}),e[45]=F):F=e[45];let O;e[46]!==d?(O=d("inlineComment.actions.editComment"),e[46]=d,e[47]=O):O=e[47];let J;e[48]!==a||e[49]!==O?(J=t.jsxs(Ns,{onClick:a,children:[F,O]}),e[48]=a,e[49]=O,e[50]=J):J=e[50];let H;e[51]===Symbol.for("react.memo_cache_sentinel")?(H=t.jsx(E,{name:"delete-bin",className:"size-4 mr-2"}),e[51]=H):H=e[51];let re;e[52]!==d?(re=d("inlineComment.actions.deleteComment"),e[52]=d,e[53]=re):re=e[53];let le;e[54]!==r||e[55]!==re?(le=t.jsxs(Ns,{onClick:r,className:"text-destructive",children:[H,re]}),e[54]=r,e[55]=re,e[56]=le):le=e[56];let ne;e[57]!==J||e[58]!==le?(ne=t.jsxs(ds,{children:[B,t.jsxs(cs,{align:"end",children:[J,le]})]}),e[57]=J,e[58]=le,e[59]=ne):ne=e[59];let be;e[60]!==$||e[61]!==ne?(be=t.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[$,ne]}),e[60]=$,e[61]=ne,e[62]=be):be=e[62];let ae;e[63]!==be||e[64]!==j?(ae=t.jsx(yn,{render:j,children:be}),e[63]=be,e[64]=j,e[65]=ae):ae=e[65];let ye;e[66]===Symbol.for("react.memo_cache_sentinel")?(ye=t.jsx(E,{name:"edit",className:"size-4 mr-2"}),e[66]=ye):ye=e[66];let ke;e[67]!==d?(ke=d("inlineComment.actions.editComment"),e[67]=d,e[68]=ke):ke=e[68];let he;e[69]!==a||e[70]!==ke?(he=t.jsxs(sn,{onClick:a,children:[ye,ke]}),e[69]=a,e[70]=ke,e[71]=he):he=e[71];let we;e[72]===Symbol.for("react.memo_cache_sentinel")?(we=t.jsx(E,{name:"delete-bin",className:"size-4 mr-2"}),e[72]=we):we=e[72];let de;e[73]!==d?(de=d("inlineComment.actions.deleteComment"),e[73]=d,e[74]=de):de=e[74];let Z;e[75]!==r||e[76]!==de?(Z=t.jsxs(sn,{onClick:r,className:"text-destructive focus:text-destructive",children:[we,de]}),e[75]=r,e[76]=de,e[77]=Z):Z=e[77];let se;e[78]!==he||e[79]!==Z?(se=t.jsxs(bn,{children:[he,Z]}),e[78]=he,e[79]=Z,e[80]=se):se=e[80];let ve;return e[81]!==u||e[82]!==ae||e[83]!==se?(ve=t.jsxs(xn,{open:u,onOpenChange:w,children:[ae,se]}),e[81]=u,e[82]=ae,e[83]=se,e[84]=ve):ve=e[84],ve}function Hl(s){const e=et.c(62),{initialText:n,onTextChange:a,onSave:r,onCancel:i,fileLabel:l,lineRange:d,isEditing:c,className:h,maxWidth:m}=s,p=n===void 0?"":n,u=c===void 0?!1:c,{t:w}=st(),f=lr()?.currentTheme,{isMobile:x}=Ds(),[D,P]=o.useState(p),I=xe.useRef(null);let L;e[0]!==a?(L=ie=>{P(ie),a?.(ie)},e[0]=a,e[1]=L):L=e[1];const N=L,b=xe.useRef(d);let j,T;e[2]!==d?(j=()=>{d&&(b.current=d)},T=[d],e[2]=d,e[3]=j,e[4]=T):(j=e[3],T=e[4]),xe.useEffect(j,T);const U=Gv,K=U(d);let M,C;e[5]!==x?(M=()=>{const ie=I.current;if(!ie)return;const pe=ie.closest(".overlay-scrollbar-container"),Ae=pe?.scrollTop??window.scrollY,Se=pe?.scrollLeft??window.scrollX;if(x){ie.scrollIntoView({behavior:"auto",block:"nearest"});try{ie.focus({preventScroll:!0})}catch{ie.focus()}return}try{ie.focus({preventScroll:!0})}catch{ie.focus()}const De=ie.value.length;try{ie.setSelectionRange(De,De)}catch{}requestAnimationFrame(()=>{pe?(pe.scrollTop=Ae,pe.scrollLeft=Se):window.scrollTo({top:Ae,left:Se})})},C=[x],e[5]=x,e[6]=M,e[7]=C):(M=e[6],C=e[7]),xe.useEffect(M,C);let A;e[8]!==i||e[9]!==r||e[10]!==D?(A=ie=>{(ie.metaKey||ie.ctrlKey)&&ie.key==="Enter"?(ie.preventDefault(),D.trim()&&r(D,U(b.current))):ie.key==="Escape"&&(ie.preventDefault(),i())},e[8]=i,e[9]=r,e[10]=D,e[11]=A):A=e[11];const z=A;let R;e[12]!==r||e[13]!==D?(R=ie=>{ie.stopPropagation(),D.trim()&&r(D,U(b.current))},e[12]=r,e[13]=D,e[14]=R):R=e[14];const Q=R;let W;e[15]!==h?(W=ce("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",h),e[15]=h,e[16]=W):W=e[16];const te=f?.colors?.surface?.elevated,Y=f?.colors?.interactive?.border,k=m?`${Math.max(200,Math.floor(m))}px`:void 0;let $;e[17]!==te||e[18]!==Y||e[19]!==k?($={backgroundColor:te,borderColor:Y,maxWidth:k},e[17]=te,e[18]=Y,e[19]=k,e[20]=$):$=e[20];const B="true",F=Wv,O=Hv,J="p-3",H=(l||d)&&t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[l&&t.jsx("span",{className:"truncate max-w-[200px]",children:l}),l&&d&&t.jsx("span",{children:"•"}),K&&t.jsx("span",{children:w("inlineComment.range.lines",{start:K.start,end:K.end})})]});let re;e[21]!==N?(re=ie=>N(ie.target.value),e[21]=N,e[22]=re):re=e[22];let le;e[23]!==x||e[24]!==w?(le=w(x?"inlineComment.input.placeholderShort":"inlineComment.input.placeholder"),e[23]=x,e[24]=w,e[25]=le):le=e[25];let ne;e[26]!==z||e[27]!==re||e[28]!==le||e[29]!==D?(ne=t.jsx(us,{simple:!0,ref:I,value:D,onChange:re,onKeyDown:z,placeholder:le,outerClassName:"rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]",className:"min-h-[80px] px-3 py-2.5 text-sm resize-y"}),e[26]=z,e[27]=re,e[28]=le,e[29]=D,e[30]=ne):ne=e[30];let be;e[31]!==w?(be=w("inlineComment.actions.cancel"),e[31]=w,e[32]=be):be=e[32];let ae;e[33]!==i||e[34]!==be?(ae=t.jsx(q,{variant:"ghost",size:"sm",onClick:i,onPointerDown:_v,onTouchStart:Vv,className:"h-8 text-muted-foreground hover:text-foreground",children:be}),e[33]=i,e[34]=be,e[35]=ae):ae=e[35];let ye;e[36]!==D?(ye=D.trim(),e[36]=D,e[37]=ye):ye=e[37];const ke=!ye,he=f?.colors?.status?.success,we=f?.colors?.status?.successForeground;let de;e[38]!==he||e[39]!==we?(de={backgroundColor:he,color:we},e[38]=he,e[39]=we,e[40]=de):de=e[40];let Z;e[41]!==u||e[42]!==w?(Z=w(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[41]=u,e[42]=w,e[43]=Z):Z=e[43];let se;e[44]!==Q||e[45]!==ke||e[46]!==de||e[47]!==Z?(se=t.jsx(q,{size:"sm",onClick:Q,onPointerDown:$v,onTouchStart:Bv,disabled:ke,className:"h-8 min-w-[80px]",style:de,children:Z}),e[44]=Q,e[45]=ke,e[46]=de,e[47]=Z,e[48]=se):se=e[48];let ve;e[49]!==ae||e[50]!==se?(ve=t.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[ae,se]}),e[49]=ae,e[50]=se,e[51]=ve):ve=e[51];let G;e[52]!==H||e[53]!==ne||e[54]!==ve?(G=t.jsxs("div",{className:J,children:[H,ne,ve]}),e[52]=H,e[53]=ne,e[54]=ve,e[55]=G):G=e[55];let ee;return e[56]!==W||e[57]!==$||e[58]!==F||e[59]!==O||e[60]!==G?(ee=t.jsx("div",{className:W,style:$,"data-comment-input":B,onPointerDown:F,onTouchStart:O,children:G}),e[56]=W,e[57]=$,e[58]=F,e[59]=O,e[60]=G,e[61]=ee):ee=e[61],ee}function Bv(s){return s.stopPropagation()}function $v(s){return s.stopPropagation()}function Vv(s){return s.stopPropagation()}function _v(s){return s.stopPropagation()}function Hv(s){return s.stopPropagation()}function Wv(s){return s.stopPropagation()}function Gv(s){if(!s)return;const e=Math.min(s.start,s.end),n=Math.max(s.start,s.end);return{...s,start:e,end:n}}const qv=s=>{const e=Math.min(s.startLine,s.endLine),n=Math.max(s.startLine,s.endLine);return{...s,startLine:e,endLine:n}},Wl=s=>{const e=Math.min(s.start,s.end),n=Math.max(s.start,s.end);return{...s,start:e,end:n}};function Jv(s){const e=et.c(40),{t:n}=st(),{source:a,fileLabel:r,language:i,getCodeForRange:l,toStoreRange:d,fromDraftRange:c}=s,h=fs(tj),m=fs(ej),p=Pa(Zv),u=Pa(Xv),w=Pa(Yv),g=Pa(Qv),[f,x]=o.useState(null),[D,P]=o.useState(""),[I,L]=o.useState(null),N=h??(m?"draft":null);let b;e:{if(!N||!r){let B;e[0]===Symbol.for("react.memo_cache_sentinel")?(B=[],e[0]=B):B=e[0],b=B;break e}let Y;e[1]!==g||e[2]!==N?(Y=g[N]??[],e[1]=g,e[2]=N,e[3]=Y):Y=e[3];const k=Y;let $;if(e[4]!==r||e[5]!==k||e[6]!==a){let B;e[8]!==r||e[9]!==a?(B=F=>F.source===a&&F.fileLabel===r,e[8]=r,e[9]=a,e[10]=B):B=e[10],$=k.filter(B),e[4]=r,e[5]=k,e[6]=a,e[7]=$}else $=e[7];b=$}const j=b;let T;e[11]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{x(null),P(""),L(null)},e[11]=T):T=e[11];const U=T;let K;e[12]===Symbol.for("react.memo_cache_sentinel")?(K=()=>{U()},e[12]=K):K=e[12];const M=K;let C;e[13]!==c?(C=Y=>{const k=Wl(c(Y));x(k),P(Y.text),L(Y.id)},e[13]=c,e[14]=C):C=e[14];const A=C;let z;e[15]!==I||e[16]!==w?(z=Y=>{w(Y.sessionKey,Y.id),I===Y.id&&U()},e[15]=I,e[16]=w,e[17]=z):z=e[17];const R=z;let Q;e[18]!==p||e[19]!==I||e[20]!==r||e[21]!==l||e[22]!==i||e[23]!==f||e[24]!==N||e[25]!==a||e[26]!==n||e[27]!==d||e[28]!==u?(Q=(Y,k)=>{const $=k??f,B=Y.trim();if(!$||!B||!r)return;if(!N){_.error(n("inlineComment.toast.selectSessionToSave"));return}const F=Wl($),O=qv(d(F)),J=l(F);I?u(N,I,{fileLabel:r,startLine:O.startLine,endLine:O.endLine,side:O.side,code:J,language:i,text:B}):p({sessionKey:N,source:a,fileLabel:r,startLine:O.startLine,endLine:O.endLine,side:O.side,code:J,language:i,text:B}),U()},e[18]=p,e[19]=I,e[20]=r,e[21]=l,e[22]=i,e[23]=f,e[24]=N,e[25]=a,e[26]=n,e[27]=d,e[28]=u,e[29]=Q):Q=e[29];const W=Q;let te;return e[30]!==D||e[31]!==R||e[32]!==j||e[33]!==I||e[34]!==c||e[35]!==W||e[36]!==f||e[37]!==N||e[38]!==A?(te={sessionKey:N,drafts:j,selection:f,setSelection:x,commentText:D,setCommentText:P,editingDraftId:I,setEditingDraftId:L,reset:U,cancel:M,startEdit:A,deleteDraft:R,saveComment:W,fromDraftRange:c},e[30]=D,e[31]=R,e[32]=j,e[33]=I,e[34]=c,e[35]=W,e[36]=f,e[37]=N,e[38]=A,e[39]=te):te=e[39],te}function Qv(s){return s.drafts}function Yv(s){return s.removeDraft}function Xv(s){return s.updateDraft}function Zv(s){return s.addDraft}function ej(s){return s.newSessionDraft?.open}function tj(s){return s.currentSessionId}const er=s=>{if(s.type==="new"){const e=Math.min(s.selection.start,s.selection.end),n=Math.max(s.selection.start,s.selection.end);return`new-comment-${s.selection.side??"additions"}-${e}-${n}`}return`draft-${s.draft.id}`},sj=s=>{const{drafts:e,editingDraftId:n,selection:a}=s,r=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const l=Math.max(1,Math.floor(i.endLine)),d=i.side==="original"?"deletions":"additions";r.push({lineNumber:l,side:d,metadata:{type:i.id===n?"edit":"saved",draft:i}})}return a&&!n&&r.push({lineNumber:Math.max(a.start,a.end),side:a.side??"additions",metadata:{type:"new",selection:a}}),r};function nj(s){const e=s.trim();if(!e)return null;if(/^-?\d+(\.\d+)?$/.test(e)){const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}if(e.endsWith("px")){const n=Number.parseFloat(e.slice(0,-2));return Number.isFinite(n)?n:null}return null}function Gl(s){if(!(!s||s<=0))return Math.max(200,Math.floor(s))}function aj(s){const{diffRootRef:e,drafts:n,selection:a,editingDraftId:r,commentText:i,onTextChange:l,fileLabel:d,onSave:c,onCancel:h,onEdit:m,onDelete:p}=s,[u,w]=o.useState(0),[g,f]=o.useState(null),x=o.useMemo(()=>!a||r?null:er({type:"new",selection:a}),[r,a]),D=o.useMemo(()=>{const L=n.map(N=>er({type:N.id===r?"edit":"saved",draft:N}));return x&&L.push(x),L},[n,r,x]),P=o.useCallback(L=>{const N=e.current;if(!N)return null;const b=N.querySelector("diffs-container");if(!(b instanceof HTMLElement))return null;const j=b.querySelector(`[data-annotation-id="${L}"]`);if(j instanceof HTMLElement)return j;const T=b.shadowRoot;return T?T.querySelector(`[data-annotation-id="${L}"]`):null},[e]);o.useEffect(()=>{if(D.length===0)return;let L=!1,N=0;const b=12,j=()=>{L||D.every(U=>!!P(U))||N>=b||(N+=1,requestAnimationFrame(()=>{L||(w(U=>U+1),j())}))};return j(),()=>{L=!0}},[D,P]),o.useEffect(()=>{const L=e.current;if(!L)return;const N=()=>{const j=getComputedStyle(L),T=nj(j.getPropertyValue("--oc-context-panel-width")),U=L.getBoundingClientRect(),K=T??U.width;f(K>0?K:null)};N();const b=new ResizeObserver(()=>{N()});return b.observe(L),window.addEventListener("resize",N),()=>{b.disconnect(),window.removeEventListener("resize",N)}},[e]);const I=o.useCallback(L=>{const b=e.current?.getBoundingClientRect(),j=L.closest("[data-annotation-content]"),T=j instanceof HTMLElement?j.getBoundingClientRect():L.getBoundingClientRect(),U=[T.width];b&&U.push(b.right-T.left);const K=U.filter(M=>Number.isFinite(M)&&M>0);return K.length>0?Gl(Math.min(...K)):Gl(g)},[e,g]);return t.jsxs(t.Fragment,{children:[n.map(L=>{const N=er({type:L.id===r?"edit":"saved",draft:L}),b=P(N);if(!b)return null;const j=I(b);return L.id===r?Ha.createPortal(t.jsx(Hl,{initialText:i,onTextChange:l,fileLabel:d,lineRange:{start:L.startLine,end:L.endLine,side:L.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:h,maxWidth:j}),b,`draft-edit-${L.id}`):Ha.createPortal(t.jsx(Uv,{draft:L,onEdit:()=>m(L),onDelete:()=>p(L),maxWidth:j}),b,`draft-card-${L.id}`)}),a&&!r&&x&&(()=>{const L=P(x);if(!L)return null;const N=I(L);return Ha.createPortal(t.jsx(Hl,{initialText:i,onTextChange:l,fileLabel:d,lineRange:a,isEditing:!1,onSave:c,onCancel:h,maxWidth:N}),L,x)})()]})}const ql=5e5,rj=`
|
|
31
|
+
:host {
|
|
32
|
+
font-family: var(--font-mono);
|
|
33
|
+
font-size: var(--text-code);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
pre, [data-code] {
|
|
37
|
+
font-family: var(--font-mono);
|
|
38
|
+
font-size: var(--text-code);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* Mobile touch selection support */
|
|
42
|
+
[data-line-number] {
|
|
43
|
+
touch-action: manipulation;
|
|
44
|
+
-webkit-tap-highlight-color: transparent;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* Ensure interactive line numbers work on touch */
|
|
49
|
+
pre[data-interactive-line-numbers] [data-line-number] {
|
|
50
|
+
touch-action: manipulation;
|
|
51
|
+
}
|
|
52
|
+
`,ij=`
|
|
53
|
+
${rj}
|
|
54
|
+
|
|
55
|
+
:host {
|
|
56
|
+
--diffs-bg-separator-override: var(--surface-elevated);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
[data-diff-header],
|
|
60
|
+
[data-diff] {
|
|
61
|
+
[data-separator] {
|
|
62
|
+
height: 24px !important;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
[data-separator="line-info-basic"] {
|
|
67
|
+
height: 24px !important;
|
|
68
|
+
background: var(--diffs-bg) !important;
|
|
69
|
+
position: relative;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
[data-diff-type="single"] [data-gutter],
|
|
73
|
+
[data-diff-type="split"] [data-deletions] [data-gutter] {
|
|
74
|
+
[data-separator-wrapper] {
|
|
75
|
+
position: absolute;
|
|
76
|
+
left: 100%;
|
|
77
|
+
display: flex;
|
|
78
|
+
align-items: center;
|
|
79
|
+
gap: unset;
|
|
80
|
+
width: max-content;
|
|
81
|
+
background: transparent;
|
|
82
|
+
color: var(--diffs-fg-number);
|
|
83
|
+
font-family: var(--diffs-header-font-family, var(--font-sans));
|
|
84
|
+
font-size: 0.75rem;
|
|
85
|
+
line-height: 1;
|
|
86
|
+
margin-left: calc(-2ch - 2px);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
[data-separator-wrapper][data-separator-multi-button] {
|
|
90
|
+
margin-left: calc(-3ch - 2px);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
[data-expand-button],
|
|
94
|
+
[data-separator-content] {
|
|
95
|
+
display: block;
|
|
96
|
+
align-self: unset;
|
|
97
|
+
min-width: unset;
|
|
98
|
+
min-height: unset;
|
|
99
|
+
padding: 0;
|
|
100
|
+
flex-shrink: 0;
|
|
101
|
+
grid-column: unset;
|
|
102
|
+
border: none;
|
|
103
|
+
width: auto;
|
|
104
|
+
height: auto;
|
|
105
|
+
background-color: transparent;
|
|
106
|
+
color: inherit;
|
|
107
|
+
font: inherit;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
[data-expand-button]:not([data-expand-all-button]) {
|
|
111
|
+
&[data-expand-down]::before {
|
|
112
|
+
content: '\\2191';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
&[data-expand-up]::before {
|
|
116
|
+
content: '\\2193';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
&[data-expand-both]::before {
|
|
120
|
+
content: '\\2195';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
svg {
|
|
124
|
+
display: none;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
[data-separator-content] {
|
|
129
|
+
background: transparent;
|
|
130
|
+
margin-left: calc(2px + 1ch);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
[data-expand-all-button] {
|
|
134
|
+
position: relative;
|
|
135
|
+
margin-left: 14px;
|
|
136
|
+
text-transform: lowercase;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
[data-expand-all-button]::before {
|
|
140
|
+
content: '';
|
|
141
|
+
display: block;
|
|
142
|
+
position: absolute;
|
|
143
|
+
top: 50%;
|
|
144
|
+
left: -8px;
|
|
145
|
+
margin-top: -1px;
|
|
146
|
+
width: 3px;
|
|
147
|
+
height: 3px;
|
|
148
|
+
border-radius: 2px;
|
|
149
|
+
background-color: var(--diffs-fg-number);
|
|
150
|
+
pointer-events: none;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
[data-separator-content]:hover,
|
|
154
|
+
[data-expand-button]:hover,
|
|
155
|
+
[data-expand-all-button]:hover {
|
|
156
|
+
color: var(--diffs-fg);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
[data-expand-all-button]:hover {
|
|
160
|
+
text-decoration: underline;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
`;function oj(s){let e=2166136261;for(let n=0;n<s.length;n+=1)e^=s.charCodeAt(n),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return e.toString(16)}function Jl(s){const e=s.length>400?`${s.slice(0,200)}${s.slice(-200)}`:s;return`${s.length}:${oj(e)}`}const lj=(s,e,n,a)=>{const r=a.side==="deletions",l=(n?(r?n.deletionLines:n.additionLines).join(""):r?s:e).split(`
|
|
164
|
+
`),d=Math.min(a.start,a.end),c=Math.max(a.start,a.end),h=Math.max(1,d),m=Math.min(l.length,c);return h>m?"":l.slice(h-1,m).join(`
|
|
165
|
+
`)},cj=(s,e)=>s===e?!0:!s||!e?!1:s.start===e.start&&s.end===e.end&&s.side===e.side,dj=s=>s==="auto"||s==="scroll"||s==="overlay",uj=s=>{let e=s?.parentElement??null;for(;e;){const n=window.getComputedStyle(e);if(dj(n.overflowY))return e;e=e.parentElement}return null},mj=(s,e)=>{if(!s||!e||typeof window>"u")return()=>{};const n=uj(s);if(!n)return()=>{};const a=e.getBoundingClientRect().height;if(!a)return()=>{};const r=s.getBoundingClientRect().top-n.getBoundingClientRect().top,i=e.style.minHeight;e.style.minHeight=`${Math.ceil(a)}px`;let l=!1;return()=>{if(l)return;l=!0,e.style.minHeight=i;const c=s.getBoundingClientRect().top-n.getBoundingClientRect().top-r;c&&(n.scrollTop+=c)}},pj=(s,e)=>{if(typeof window>"u")return()=>{};let n=null,a=null,r=!1;const i=()=>{r||(a?.disconnect(),a=null,n=window.requestAnimationFrame(()=>{n=window.requestAnimationFrame(()=>{r||e()})}))},l=()=>s.querySelector("diffs-container")?.shadowRoot??void 0,d=(c=l())=>!!c?.querySelector("[data-line]");return d()?i():typeof MutationObserver<"u"?(a=new MutationObserver(()=>{const c=l();if(c){if(d(c)){i();return}a?.disconnect(),a=new MutationObserver(()=>{d(c)&&i()}),a.observe(c,{childList:!0,subtree:!0})}}),a.observe(s,{childList:!0,subtree:!0})):n=window.requestAnimationFrame(i),()=>{r=!0,a?.disconnect(),n!==null&&window.cancelAnimationFrame(n)}},_a=new WeakMap,gj={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function hj(s){const e=s.closest("[data-diff-virtual-root]");if(e instanceof HTMLElement){const n=e.querySelector("[data-diff-virtual-content]");return{key:e,root:e,content:n instanceof HTMLElement?n:void 0}}return{key:document,root:document,content:void 0}}function fj(s){if(typeof document>"u")return null;const e=hj(s);let n=_a.get(e.key);if(!n){const r=new eu;r.setup(e.root,e.content),n={virtualizer:r,refs:0},_a.set(e.key,n)}n.refs+=1;let a=!1;return{virtualizer:n.virtualizer,root:e.root,release:()=>{if(a)return;a=!0;const r=_a.get(e.key);r&&(r.refs-=1,!(r.refs>0)&&(r.virtualizer.cleanUp(),_a.delete(e.key)))}}}const xj=(s,e,n)=>{if(typeof window>"u")return()=>{};const a=[],r=()=>{try{s.rerender()}catch{}const i=e?.root;i instanceof HTMLElement?i.dispatchEvent(new Event("scroll",{bubbles:!1})):document.dispatchEvent(new Event("scroll",{bubbles:!1})),window.dispatchEvent(new Event("resize")),n()};return a.push(window.requestAnimationFrame(r)),a.push(window.requestAnimationFrame(()=>{a.push(window.requestAnimationFrame(r))})),()=>{for(const i of a)window.cancelAnimationFrame(i)}},aw=({original:s,modified:e,fileDiff:n,language:a,fileName:r,renderSideBySide:i,wrapLines:l,layout:d="fill",enableComments:c=!0})=>{const h=lr(),m=h?.currentTheme.metadata.variant==="dark",p=h?.availableThemes.find(G=>G.metadata.id===h.lightThemeId)??sr(!1),u=h?.availableThemes.find(G=>G.metadata.id===h.darkThemeId)??sr(!0),{isMobile:w}=Ds(),g=Jv({source:"diff",fileLabel:r||"unknown",language:a,getCodeForRange:G=>lj(s,e,n,G),toStoreRange:G=>({startLine:G.start,endLine:G.end,side:G.side==="deletions"?"original":"modified"}),fromDraftRange:G=>({start:G.startLine,end:G.endLine,side:G.side==="original"?"deletions":"additions"})}),{drafts:f,selection:x,setSelection:D,commentText:P,setCommentText:I,editingDraftId:L,saveComment:N,cancel:b,startEdit:j,deleteDraft:T}=g,U=xe.useRef(null),K=xe.useRef(null),M=xe.useRef(""),C=xe.useRef(!1),A=xe.useRef(null);xe.useEffect(()=>{U.current=x},[x]),xe.useEffect(()=>{K.current=L},[L]),xe.useEffect(()=>{M.current=P},[P]);const z=xe.useCallback(G=>{if(!c||C.current)return;const ee=U.current;if(!(!G&&ee&&M.current.trim())){if(w&&ee&&G&&G.side===ee.side){const ie=Math.min(ee.start,G.start),pe=Math.max(ee.end,G.end);D({...G,start:ie,end:pe})}else D(G);G&&(K.current||I(""))}},[c,w,I,D]),R=xe.useCallback(()=>{b()},[b]),Q=xe.useCallback(G=>{const ee=document.createElement("div");ee.style.position="relative";const ie=er(G.metadata);return ee.dataset.annotationId=ie,ee.dataset.annotationSide=G.side,ee.dataset.annotationLine=String(G.lineNumber),ee},[]),W=xe.useCallback((G,ee)=>{N(G,ee??x??void 0)},[N,x]),te=xe.useCallback(G=>{D(G);const ee=O.current;if(ee)try{C.current=!0,ee.setSelectedLines(G),A.current=G}catch{}finally{C.current=!1}},[D]),Y=xe.useCallback(G=>{const ee=G.closest("[data-line-type]")?.getAttribute("data-line-type")??G.getAttribute("data-line-type");if(ee==="change-deletion")return"deletions";if(ee==="change-addition")return"additions";const ie=G.getAttribute("data-column-side")??G.getAttribute("data-side")??G.closest("[data-column-side]")?.getAttribute("data-column-side");if(ie==="deletions"||ie==="left"||ie==="original")return"deletions";if(ie==="additions"||ie==="right"||ie==="modified")return"additions";const pe=G.closest("[data-line-type]");if(pe instanceof HTMLElement){const Ae=pe.getBoundingClientRect(),Se=G.getBoundingClientRect(),De=Ae.left+Ae.width/2;return Se.left+Se.width/2<De?"deletions":"additions"}return"additions"},[]);nr(p),nr(u);const k=`${p.metadata.id}:${u.metadata.id}:${m?"dark":"light"}`,$=xe.useMemo(()=>{if(n){const G=n.deletionLines.reduce((ie,pe)=>ie+pe.length,0),ee=n.additionLines.reduce((ie,pe)=>ie+pe.length,0);return Math.max(G,ee)>ql}return Math.max(s.length,e.length)>ql},[n,e.length,s.length]),B=xe.useRef(null),F=xe.useRef(null),O=xe.useRef(null),J=xe.useRef(null),H=xe.useRef(null),re=xe.useRef(null),le=xe.useRef(void 0),ne=xe.useRef(void 0),be=xe.useRef(void 0),ae=xe.useRef(void 0),[,ye]=o.useReducer(G=>G+1,0),ke=gi($?"unified":i?"split":"unified"),he=xe.useMemo(()=>oi(p),[p]),we=xe.useMemo(()=>oi(u),[u]);o.useLayoutEffect(()=>{const G=B.current;if(!G)return;const ee=G.querySelector("diffs-container");if(!ee)return;const ie=m?we:he,pe=(Ye,Re)=>Ye.colors?.[Re],Ae=pe(he,"terminal.ansiGreen"),Se=pe(he,"terminal.ansiRed"),De=pe(he,"terminal.ansiBlue"),Me=pe(we,"terminal.ansiGreen"),Te=pe(we,"terminal.ansiRed"),Be=pe(we,"terminal.ansiBlue");ee.style.setProperty("--shiki-light",he.fg),ee.style.setProperty("--shiki-light-bg",he.bg),Ae&&ee.style.setProperty("--shiki-light-addition-color",Ae),Se&&ee.style.setProperty("--shiki-light-deletion-color",Se),De&&ee.style.setProperty("--shiki-light-modified-color",De),ee.style.setProperty("--shiki-dark",we.fg),ee.style.setProperty("--shiki-dark-bg",we.bg),Me&&ee.style.setProperty("--shiki-dark-addition-color",Me),Te&&ee.style.setProperty("--shiki-dark-deletion-color",Te),Be&&ee.style.setProperty("--shiki-dark-modified-color",Be),ee.style.setProperty("--diffs-bg",ie.bg),ee.style.setProperty("--diffs-fg",ie.fg);const ze=m?Me:Ae,Oe=m?Te:Se,$e=m?Be:De;ze&&ee.style.setProperty("--diffs-addition-color-override",ze),Oe&&ee.style.setProperty("--diffs-deletion-color-override",Oe),$e&&ee.style.setProperty("--diffs-modified-color-override",$e);const Ke=ee.shadowRoot?.querySelector("pre");Ke&&(Ke.style.setProperty("--shiki-light",he.fg),Ke.style.setProperty("--shiki-light-bg",he.bg),Ae&&Ke.style.setProperty("--shiki-light-addition-color",Ae),Se&&Ke.style.setProperty("--shiki-light-deletion-color",Se),De&&Ke.style.setProperty("--shiki-light-modified-color",De),Ke.style.setProperty("--shiki-dark",we.fg),Ke.style.setProperty("--shiki-dark-bg",we.bg),Me&&Ke.style.setProperty("--shiki-dark-addition-color",Me),Te&&Ke.style.setProperty("--shiki-dark-deletion-color",Te),Be&&Ke.style.setProperty("--shiki-dark-modified-color",Be),Ke.style.setProperty("--diffs-bg",ie.bg),Ke.style.setProperty("--diffs-fg",ie.fg),ze&&Ke.style.setProperty("--diffs-addition-color-override",ze),Oe&&Ke.style.setProperty("--diffs-deletion-color-override",Oe),$e&&Ke.style.setProperty("--diffs-modified-color-override",$e))},[we,k,m,he]);const de=xe.useMemo(()=>({theme:{dark:u.metadata.id,light:p.metadata.id},themeType:m?"dark":"light",diffStyle:i?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:$?0:1e3,maxLineLengthForHighlighting:$?1:1e3,tokenizeMaxLineLength:$?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:l?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:c,enableHoverUtility:!1,onLineSelected:c?z:void 0,unsafeCSS:ij,renderAnnotation:c?Q:void 0}),[u.metadata.id,c,m,$,p.metadata.id,i,l,z,Q]),Z=xe.useMemo(()=>c?sj({drafts:f,editingDraftId:L,selection:x}):[],[L,c,f,x]),se=xe.useRef(Z);if(xe.useEffect(()=>{se.current=Z},[Z]),xe.useEffect(()=>{const G=F.current;return()=>{O.current?.cleanUp(),O.current=null,J.current?.release(),J.current=null,H.current=null,re.current=null,le.current=void 0,ne.current=void 0,be.current=void 0,ae.current=void 0,G&&(G.innerHTML="")}},[]),xe.useEffect(()=>{if(typeof window>"u")return;const G=F.current,ee=B.current;if(!G||!ke)return;const ie=mj(ee,G);let pe=J.current;pe||(pe=fj(G),J.current=pe),J.current=pe;const Ae=pe?.virtualizer??null,Se=n?void 0:{name:r||"",contents:s,lang:a,cacheKey:`old:${k}:${r}:${Jl(s)}`},De=n?void 0:{name:r||"",contents:e,lang:a,cacheKey:`new:${k}:${r}:${Jl(e)}`},Me=n?ne.current!==n:ne.current!==void 0||!Se||!De||!be.current||!ae.current||!_i(be.current,Se)||!_i(ae.current,De),Te=O.current,Be=!!(Te&&(H.current!==Ae||re.current!==ke||Ae&&(le.current!==de.hunkSeparators||Me)));Be&&(Te?.cleanUp(),O.current=null,G.innerHTML="");let ze=O.current;const Oe=!Be&&Te?!Yd(Te.options,de):!1;if(ze?ze.setOptions(de):(ze=pe?new Xd(de,pe.virtualizer,gj,ke):new Zd(de,ke),O.current=ze,A.current=null),H.current=Ae,re.current=ke,le.current=Ae?de.hunkSeparators:void 0,ne.current=n,be.current=Se,ae.current=De,n)ze.render({fileDiff:n,forceRender:Oe,lineAnnotations:se.current,containerWrapper:G});else{if(!Se||!De)return;ze.render({oldFile:Se,newFile:De,forceRender:Oe,lineAnnotations:se.current,containerWrapper:G})}const $e=pj(G,()=>{ie(),xj(ze,pe,ye)});return()=>{$e(),ie()}},[k,n,r,a,e,de,s,ke]),xe.useEffect(()=>{const G=O.current;if(G){try{G.setLineAnnotations(Z)}catch(ee){console.error("Failed to apply diff line annotations",ee);try{G.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(O.current===G){try{G.rerender()}catch{}ye()}})}},[Z]),xe.useEffect(()=>{const G=O.current;if(!G||x!==null)return;const ee=A.current;if(!cj(x,ee))try{C.current=!0,G.setSelectedLines(x),A.current=x}catch{}finally{C.current=!1}},[x]),xe.useEffect(()=>{if(!c)return;const G=F.current;if(!G)return;let ee=null,ie=()=>{};const pe=()=>{const Se=G.querySelector("diffs-container")?.shadowRoot;if(!Se){ee=requestAnimationFrame(pe);return}const De=Me=>{if(!(Me instanceof MouseEvent)||Me.button!==0||!(Me.target instanceof Element))return;const Te=Me.target.closest("[data-column-number]");if(!(Te instanceof HTMLElement))return;const Be=Te.getAttribute("data-column-number"),ze=Be?parseInt(Be,10):NaN;if(Number.isNaN(ze))return;const Oe=Y(Te);z({start:ze,end:ze,side:Oe}),Me.preventDefault(),Me.stopPropagation()};Se.addEventListener("click",De,!0),ie=()=>{Se.removeEventListener("click",De,!0)}};return pe(),()=>{ee!==null&&cancelAnimationFrame(ee),ie()}},[k,c,r,z,Y]),xe.useEffect(()=>{const G=F.current;if(!G)return;let ee=null,ie=null;const Ae=setTimeout(()=>{const Se=G.querySelector("diffs-container");if(!(Se instanceof HTMLElement))return;const De=Se.shadowRoot;ee=new MutationObserver(()=>{ie&&cancelAnimationFrame(ie),ie=requestAnimationFrame(()=>{ye(),ie=null})}),ee.observe(Se,{childList:!0,subtree:!0}),De&&ee.observe(De,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(Ae),ie&&cancelAnimationFrame(ie),ee?.disconnect()}},[k,r]),typeof window>"u")return null;const ve=c?t.jsx(aj,{diffRootRef:B,drafts:f,selection:x,editingDraftId:L,commentText:P,onTextChange:I,fileLabel:r?.split("/").pop()??"",onSave:W,onCancel:R,onEdit:G=>{te({start:G.startLine,end:G.endLine,side:G.side==="original"?"deletions":"additions"}),j(G)},onDelete:T}):null;return d==="fill"?t.jsx("div",{className:ce("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:t.jsxs("div",{className:"flex-1 relative min-h-0",children:[t.jsx(_t,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:t.jsx("div",{ref:B,className:"size-full relative",children:t.jsx("div",{ref:F,className:"size-full"})})}),ve]})}):t.jsxs("div",{className:ce("relative","w-full"),children:[t.jsx("div",{ref:B,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:t.jsx("div",{ref:F,className:"w-full"})}),ve]})},yj=()=>{const s=et.c(13),[e,n]=xe.useState(!1);let a,r;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{n(ns())},r=[],s[0]=a,s[1]=r):(a=s[0],r=s[1]),xe.useEffect(a,r);let i;s[2]!==e?(i=async u=>e?await ep(u):{success:!0,path:u},s[2]=e,s[3]=i):i=s[3];const l=i;let d;s[4]!==e?(d=async u=>e?await tp():{success:!0},s[4]=e,s[5]=d):d=s[5];const c=d;let h;s[6]!==e?(h=async u=>e?await sp():{success:!0},s[6]=e,s[7]=h):h=s[7];const m=h;let p;return s[8]!==e||s[9]!==l||s[10]!==c||s[11]!==m?(p={isDesktop:e,requestAccess:l,startAccessing:c,stopAccessing:m},s[8]=e,s[9]=l,s[10]=c,s[11]=m,s[12]=p):p=s[12],p},bj=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),vj=({currentBranch:s,localBranches:e,remoteBranches:n,branchInfo:a,onCheckout:r,onCreate:i,remotes:l=[],disabled:d=!1})=>{const{t:c}=st(),[h,m]=o.useState(!1),[p,u]=o.useState(""),[w,g]=o.useState(!1),[f,x]=o.useState(!1),[D,P]=o.useState(""),[I,L]=o.useState(!1),N=o.useRef(null),b=o.useCallback(W=>{W.stopPropagation()},[]),j=l.length>1,T=o.useMemo(()=>bj(D),[D]),U=o.useMemo(()=>{const W=p.toLowerCase();return W?e.filter(te=>te.toLowerCase().includes(W)):e},[p,e]),K=o.useMemo(()=>{const W=p.toLowerCase();return W?n.filter(te=>te.toLowerCase().includes(W)):n},[p,n]),M=W=>{if(W===s){m(!1);return}r(W),m(!1),u("")},C=()=>{g(!0),setTimeout(()=>N.current?.focus(),50)},A=async()=>{if(!(!T||I)){if(j){x(!0);return}L(!0);try{await i(T,l[0]),P(""),g(!1),m(!1)}finally{L(!1)}}},z=async W=>{if(!(!T||I)){L(!0);try{await i(T,W),P(""),g(!1),x(!1),m(!1)}finally{L(!1)}}},R=()=>{x(!1)},Q=()=>{P(""),g(!1),x(!1)};return o.useEffect(()=>{h||(u(""),g(!1),x(!1),P(""))},[h]),t.jsxs(ds,{open:h,onOpenChange:m,children:[t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(ls,{asChild:!0,children:t.jsxs(q,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:d,children:[t.jsx(E,{name:"git-branch",className:"size-4 text-primary"}),t.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:s||c("gitView.branch.detachedHead")}),t.jsx(E,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),t.jsx(It,{sideOffset:8,children:c("gitView.branch.currentBranchTooltip")})]}),t.jsx(cs,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:t.jsxs(ci,{className:"h-full min-h-0",children:[t.jsx(di,{placeholder:c("gitView.branch.searchPlaceholder"),value:p,onValueChange:u,onKeyDown:b}),t.jsxs(ui,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(mi,{children:c("gitView.branch.empty")}),t.jsx(Js,{children:f?t.jsxs("div",{className:"px-2 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("button",{type:"button",onClick:R,disabled:I,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(E,{name:"arrow-left",className:"size-4"})}),t.jsxs("span",{className:"typography-meta text-muted-foreground",children:[c("gitView.branch.pushToPrefix")," ",t.jsx("span",{className:"text-foreground font-medium",children:T})," ",c("gitView.branch.pushToSuffix")]})]}),t.jsx("div",{className:"flex flex-col gap-1",children:l.map(W=>t.jsxs("button",{type:"button",onClick:()=>z(W),disabled:I,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[t.jsxs("span",{className:"typography-ui-label text-foreground",children:[I?t.jsx(E,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,W.name]}),t.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:W.pushUrl})]},W.name))})]}):w?t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[t.jsx("input",{ref:N,placeholder:c("gitView.branch.newBranchPlaceholder"),value:D,onChange:W=>P(W.target.value),onClick:W=>W.stopPropagation(),onKeyDown:W=>{b(W),W.key==="Enter"?(W.preventDefault(),A()):W.key==="Escape"&&(W.preventDefault(),Q())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),t.jsx("button",{type:"button",onClick:A,disabled:!T||I,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:I?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"add",className:"size-4"})}),t.jsx("button",{type:"button",onClick:Q,disabled:I,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(E,{name:"close",className:"size-4"})})]}):t.jsxs(zs,{onSelect:C,children:[t.jsx(E,{name:"add",className:"size-4"}),t.jsx("span",{children:c("gitView.branch.create")})]})}),t.jsx(Gn,{}),t.jsxs(Js,{heading:c("gitView.branch.localBranches"),children:[U.map(W=>t.jsxs(zs,{onSelect:()=>M(W),children:[t.jsxs("span",{className:"flex flex-1 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:W}),(a?.[W]?.ahead||a?.[W]?.behind)&&t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[a[W].ahead||0," ahead ·"," ",a[W].behind||0," behind"]})]}),s===W&&t.jsx("span",{className:"typography-micro text-primary",children:c("gitView.branch.currentBadge")})]},`local-${W}`)),U.length===0&&t.jsx(zs,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noLocalBranches")})})]}),t.jsx(Gn,{}),t.jsxs(Js,{heading:c("gitView.branch.remoteBranches"),children:[K.map(W=>t.jsx(zs,{onSelect:()=>M(W),children:t.jsx("span",{className:"typography-ui-label text-foreground",children:W})},`remote-${W}`)),K.length===0&&t.jsx(zs,{disabled:!0,className:"justify-center",children:t.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.branch.noRemoteBranches")})})]})]})]})})]})},jj=s=>s.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),wj=({currentBranch:s,onRename:e,showEditButton:n=!0})=>{const{t:a}=st(),[r,i]=o.useState(!1),[l,d]=o.useState(s||""),[c,h]=o.useState(!1),m=o.useRef(null),p=()=>{!s||!e||(d(s),i(!0),setTimeout(()=>m.current?.focus(),0))},u=async()=>{if(!s||!e||!l.trim())return;const f=jj(l);if(f===s){i(!1);return}h(!0);try{await e(s,f),i(!1),d("")}finally{h(!1)}},w=()=>{i(!1),d("")},g=f=>{f.key==="Enter"?(f.preventDefault(),u()):f.key==="Escape"&&(f.preventDefault(),w())};return r?t.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:t.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:f=>{f.preventDefault(),u()},children:[t.jsx(E,{name:"git-branch",className:"size-4 text-primary"}),t.jsx("input",{ref:m,value:l,onChange:f=>d(f.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:a("gitView.branch.namePlaceholder"),onKeyDown:g,autoFocus:!0}),t.jsx("button",{type:"submit",disabled:c,"aria-label":a(c?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:a(c?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:c?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"check",className:"size-4"})}),t.jsx("button",{type:"button",onClick:w,disabled:c,"aria-label":a("gitView.branch.renameCancel"),title:a("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:t.jsx(E,{name:"close",className:"size-4"})})]})}):t.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[t.jsx(E,{name:"git-branch",className:"size-4 text-primary shrink-0"}),t.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[t.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:s||a("gitView.branch.detachedHead")}),n&&e&&s&&t.jsx(q,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:p,title:a("gitView.branch.renameTitle"),children:t.jsx(E,{name:"edit",className:"size-4"})})]})]})},Nj={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},kj={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)",success:"var(--status-success)",info:"var(--status-info)",warning:"var(--status-warning)"};function sd(s){return s&&kj[s]||"var(--primary)"}const Ql=s=>{const e=et.c(8),{icon:n,className:a,colorToken:r}=s,i=Nj[n??"branch"]??"user-3";let l;e[0]!==r?(l=sd(r),e[0]=r,e[1]=l):l=e[1];let d;e[2]!==l?(d={color:l},e[2]=l,e[3]=d):d=e[3];let c;return e[4]!==a||e[5]!==i||e[6]!==d?(c=t.jsx(E,{name:i,className:a,style:d}),e[4]=a,e[5]=i,e[6]=d,e[7]=c):c=e[7],c},nd=s=>{const e=et.c(35),{activeProfile:n,identities:a,onSelect:r,isApplying:i,iconOnly:l}=s,d=l===void 0?!1:l,{t:c}=st(),h=i||a.length===0,m=n?.color;let p;e[0]!==m?(p=sd(m),e[0]=m,e[1]=p):p=e[1];let u;e[2]!==p?(u={color:p},e[2]=p,e[3]=u):u=e[3];let w;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(w=i?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(Ql,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=w):w=e[7];let g;e[8]!==n?.name||e[9]!==d||e[10]!==c?(g=!d&&t.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||c("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=d,e[10]=c,e[11]=g):g=e[11];let f;e[12]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx(E,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=f):f=e[12];let x;e[13]!==h||e[14]!==u||e[15]!==w||e[16]!==g?(x=t.jsx(Ct,{asChild:!0,children:t.jsx(ls,{asChild:!0,children:t.jsxs(q,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:u,disabled:h,children:[w,g,f]})})}),e[13]=h,e[14]=u,e[15]=w,e[16]=g,e[17]=x):x=e[17];let D;e[18]!==c?(D=c("gitView.header.identityTooltip"),e[18]=c,e[19]=D):D=e[19];let P;e[20]!==D?(P=t.jsx(It,{sideOffset:8,children:D}),e[20]=D,e[21]=P):P=e[21];let I;e[22]!==P||e[23]!==x?(I=t.jsxs(St,{children:[x,P]}),e[22]=P,e[23]=x,e[24]=I):I=e[24];let L;e[25]!==n?.id||e[26]!==a||e[27]!==r||e[28]!==c?(L=a.length===0?t.jsx("div",{className:"px-2 py-1.5",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:c("gitView.header.noProfiles")})}):a.map(j=>{const T=n?.id===j.id;return t.jsx(Ns,{onSelect:()=>r(j),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(Ql,{icon:j.icon,colorToken:j.color,className:"size-4"}),t.jsxs("span",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:j.name}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:j.userEmail})]}),T?t.jsx(E,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},j.id)}),e[25]=n?.id,e[26]=a,e[27]=r,e[28]=c,e[29]=L):L=e[29];let N;e[30]!==L?(N=t.jsx(cs,{align:"end",className:"w-64",children:L}),e[30]=L,e[31]=N):N=e[31];let b;return e[32]!==I||e[33]!==N?(b=t.jsxs(ds,{children:[I,N]}),e[32]=I,e[33]=N,e[34]=b):b=e[34],b},Sj=s=>{const e=et.c(21),{comparison:n,trackingBranch:a,tooltipDelayMs:r}=s,i=r===void 0?1e3:r,{t:l}=st(),d=`${n.remote}/${n.branch}`,c=n.ahead===0&&n.behind===0;let h;e[0]!==l||e[1]!==d||e[2]!==a?(h=a?l("gitView.header.upstreamTooltipTracking",{target:d,tracking:a}):l("gitView.header.upstreamTooltip",{target:d}),e[0]=l,e[1]=d,e[2]=a,e[3]=h):h=e[3];const m=h;let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(E,{name:"git-branch",className:"size-3.5 shrink-0"}),e[4]=p):p=e[4];let u;e[5]!==d?(u=t.jsx("span",{className:"min-w-0 truncate text-foreground/80",children:d}),e[5]=d,e[6]=u):u=e[6];let w;e[7]!==n.ahead||e[8]!==n.behind||e[9]!==c||e[10]!==l?(w=c?t.jsx("span",{className:"tabular-nums text-muted-foreground",children:l("gitView.header.upstreamSynced")}):t.jsxs("span",{className:"inline-flex items-center gap-1 tabular-nums",children:[n.ahead>0?t.jsxs("span",{className:"text-[var(--status-info)]",children:["↑",n.ahead]}):null,n.behind>0?t.jsxs("span",{className:"text-[var(--status-warning)]",children:["↓",n.behind]}):null]}),e[7]=n.ahead,e[8]=n.behind,e[9]=c,e[10]=l,e[11]=w):w=e[11];let g;e[12]!==u||e[13]!==w?(g=t.jsx(Ct,{asChild:!0,children:t.jsxs("div",{className:"inline-flex h-8 max-w-full items-center gap-1.5 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2 typography-micro text-muted-foreground",children:[p,u,w]})}),e[12]=u,e[13]=w,e[14]=g):g=e[14];let f;e[15]!==m?(f=t.jsx(It,{sideOffset:8,children:m}),e[15]=m,e[16]=f):f=e[16];let x;return e[17]!==g||e[18]!==f||e[19]!==i?(x=t.jsxs(St,{delayDuration:i,children:[g,f]}),e[17]=g,e[18]=f,e[19]=i,e[20]=x):x=e[20],x},rw=s=>{const e=et.c(54),{status:n,localBranches:a,remoteBranches:r,branchInfo:i,syncAction:l,remotes:d,onFetch:c,onSync:h,onRemoveRemote:m,removingRemoteName:p,onCheckoutBranch:u,onCreateBranch:w,onRenameBranch:g,activeIdentityProfile:f,availableIdentities:x,onSelectIdentity:D,isApplyingIdentity:P,isWorktreeMode:I,onOpenHistory:L,onOpenGraph:N,onOpenStashes:b,actionTabItems:j,activeActionTab:T,onSelectActionTab:U}=s,{t:K}=st();if(!n)return null;let M;e[0]!==N||e[1]!==L||e[2]!==b||e[3]!==K?(M=L||N||b?t.jsxs(ds,{children:[t.jsxs(St,{children:[t.jsx(Ct,{asChild:!0,children:t.jsx(ls,{asChild:!0,children:t.jsx(q,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":K("gitView.header.repositoryViews"),children:t.jsx(E,{name:"git-repository",className:"size-4"})})})}),t.jsx(It,{sideOffset:8,children:K("gitView.header.repositoryViews")})]}),t.jsxs(cs,{align:"end",children:[L?t.jsxs(Ns,{onSelect:L,children:[t.jsx(E,{name:"history",className:"size-4"}),K("gitView.history.title")]}):null,N?t.jsxs(Ns,{onSelect:N,children:[t.jsx(E,{name:"git-merge",className:"size-4"}),K("gitView.graph.title")]}):null,b?t.jsxs(Ns,{onSelect:b,children:[t.jsx(E,{name:"archive-stack",className:"size-4"}),K("gitView.stashes.title")]}):null]})]}):null,e[0]=N,e[1]=L,e[2]=b,e[3]=K,e[4]=M):M=e[4];let C;e[5]!==M?(C=t.jsx("div",{className:"flex items-center gap-1 shrink-0",children:M}),e[5]=M,e[6]=C):C=e[6];const A=C,z=!n;let R;e[7]!==n.tracking?(R=n.tracking?.split("/")[0],e[7]=n.tracking,e[8]=R):R=e[8];const Q=(n.files?.length??0)>0;let W;e[9]!==c||e[10]!==m||e[11]!==h||e[12]!==d||e[13]!==p||e[14]!==n.ahead||e[15]!==n.behind||e[16]!==l||e[17]!==z||e[18]!==R||e[19]!==Q?(W=t.jsx(Kv,{syncAction:l,remotes:d,onFetch:c,onSync:h,onRemoveRemote:m,removingRemoteName:p,disabled:z,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:R,hasUncommittedChanges:Q}),e[9]=c,e[10]=m,e[11]=h,e[12]=d,e[13]=p,e[14]=n.ahead,e[15]=n.behind,e[16]=l,e[17]=z,e[18]=R,e[19]=Q,e[20]=W):W=e[20];const te=W;let Y;e[21]!==n.tracking||e[22]!==n.upstreamComparison?(Y=n.upstreamComparison?t.jsx(Sj,{comparison:n.upstreamComparison,trackingBranch:n.tracking,tooltipDelayMs:1e3}):null,e[21]=n.tracking,e[22]=n.upstreamComparison,e[23]=Y):Y=e[23];const k=Y;let $;e[24]!==f||e[25]!==x||e[26]!==P||e[27]!==D?($=t.jsx(nd,{activeProfile:f,identities:x,onSelect:D,isApplying:P,iconOnly:!0}),e[24]=f,e[25]=x,e[26]=P,e[27]=D,e[28]=$):$=e[28];const B=$;let F;e[29]!==i||e[30]!==I||e[31]!==a||e[32]!==u||e[33]!==w||e[34]!==g||e[35]!==r||e[36]!==d||e[37]!==n.current?(F=t.jsx("div",{className:"min-w-0 flex-1",children:I?t.jsx(wj,{currentBranch:n.current,onRename:g}):t.jsx(vj,{currentBranch:n.current,localBranches:a,remoteBranches:r,branchInfo:i,onCheckout:u,onCreate:w,remotes:d})}),e[29]=i,e[30]=I,e[31]=a,e[32]=u,e[33]=w,e[34]=g,e[35]=r,e[36]=d,e[37]=n.current,e[38]=F):F=e[38];let O;e[39]!==B||e[40]!==A?(O=t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[A,B]}),e[39]=B,e[40]=A,e[41]=O):O=e[41];let J;e[42]!==O||e[43]!==F?(J=t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[F,O]}),e[42]=O,e[43]=F,e[44]=J):J=e[44];let H;e[45]!==j||e[46]!==T||e[47]!==U||e[48]!==te||e[49]!==k?(H=j&&T&&U?t.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(Fn,{items:j,activeId:T,onSelect:U,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),k?t.jsx("div",{className:"min-w-0 shrink",children:k}):null,t.jsx("div",{className:"shrink-0",children:te})]}):null,e[45]=j,e[46]=T,e[47]=U,e[48]=te,e[49]=k,e[50]=H):H=e[50];let re;return e[51]!==J||e[52]!==H?(re=t.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[J,H]}),e[51]=J,e[52]=H,e[53]=re):re=e[53],re},Cj=s=>s==="/",ir=s=>s.replace(/\\/g,"/"),Li=s=>{if(!s||Cj(s))return s;let e=s;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},Xn=s=>s.endsWith("/"),Ij=s=>{const e=s.trim();return!e||Xn(e)?e:`${e}/`},Oi=s=>s.lastIndexOf("/"),ad=s=>{if(Xn(s))return s;const e=Oi(s);return e<0?s:s.slice(0,e+1)},Pj=s=>{const e=Oi(s);return s.slice(e+1)},rd=s=>{const e=Li(s.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=Oi(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},Aj=s=>Xn(s)&&rd(s)!==null,Dj=(s,e)=>`${ad(s)}${e}/`,Pn=s=>{if(!s)return null;const e=Li(ir(s.trim()));return e?e.toLowerCase():null},Yl=(s,e)=>{const n=s.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},Ej=s=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?s.metaKey&&!s.ctrlKey:s.ctrlKey&&!s.metaKey,ai=s=>{if(!s)return;s.focus({preventScroll:!0});const e=s.value.length;s.setSelectionRange(e,e),s.scrollLeft=s.scrollWidth},Mj=async()=>{try{const s=await ct("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(s.ok){const e=await s.json();if(typeof e.home=="string"&&e.home.trim().length>0)return ir(e.home.trim())}}catch{}return ys.getFilesystemHome().catch(()=>null)},iw=({open:s,onOpenChange:e})=>{const{t:n}=st(),a=ws(v=>v.homeDirectory),r=es(v=>v.projects),i=es(v=>v.addProject),l=Is(v=>v.profiles),d=Is(v=>v.globalIdentity),c=Is(v=>v.defaultGitIdentityId),h=Is(v=>v.loadProfiles),m=Is(v=>v.loadGlobalIdentity),p=Is(v=>v.loadDefaultGitIdentityId),{isDesktop:u,requestAccess:w,startAccessing:g}=yj(),{isMobile:f}=Ds(),x=o.useRef(null),D=o.useRef(null),P=o.useRef(new Map),[I,L]=o.useState(""),[N,b]=o.useState("~/"),[j,T]=o.useState([]),[U,K]=o.useState(!1),[M,C]=o.useState(!1),[A,z]=o.useState(0),[R,Q]=o.useState(!1),[W,te]=o.useState(!1),[Y,k]=o.useState(0),[$,B]=o.useState(!1),[F,O]=o.useState(""),[J,H]=o.useState(null),[re,le]=o.useState(!1),ne=I||a,be=o.useMemo(()=>new Set(r.map(v=>Pn(v.path)).filter(v=>!!v)),[r]);o.useEffect(()=>{if(!s)return;b("~/"),T([]),z(0),Q(!1),te(!1),B(!1),O(""),H(null),le(!1),requestAnimationFrame(()=>ai(x.current));let v=!1;return(async()=>{const Pe=await Mj();v||(L(Pe||a||""),requestAnimationFrame(()=>ai(x.current)))})(),()=>{v=!0}},[a,s]),o.useEffect(()=>{s&&(h(),m(),p())},[p,h,m,s]);const ae=o.useMemo(()=>{const v=new Map;d&&v.set(d.id,d);for(const je of l)v.set(je.id,je);return Array.from(v.values())},[l,d]);o.useEffect(()=>{if(!s||!$||J!==null)return;const v=typeof c=="string"?c.trim():"";if(v&&ae.some(Pe=>Pe.id===v)){H(v);return}const je=ae.find(Pe=>Pe.authType==="ssh"||Pe.sshKey);je&&H(je.id)},[ae,c,$,s,J]);const ye=o.useMemo(()=>ae.find(v=>v.id===J)??null,[ae,J]),ke=o.useMemo(()=>ad(N),[N]),he=o.useMemo(()=>Xn(N)?"":Pj(N),[N]),we=o.useMemo(()=>ne?Yl(ke,ne):"",[ke,ne]);o.useEffect(()=>{if(!s||!we){T([]);return}let v=!1;return K(!0),C(!1),ys.listLocalDirectory(we).then(je=>{if(v)return;C(!1);const Pe=je.filter(Le=>Le.isDirectory).map(Le=>({name:Le.name,path:ir(Le.path)})).sort((Le,qe)=>Le.name.localeCompare(qe.name));T(Pe)}).catch(()=>{v||(T([]),C(!0))}).finally(()=>{v||K(!1)}),()=>{v=!0}},[we,s]);const de=o.useMemo(()=>{const v=he.toLowerCase(),je=re||he.startsWith(".");return j.filter(Pe=>Pe.name.toLowerCase().startsWith(v)&&(je||!Pe.name.startsWith(".")))},[he,j,re]),Z=o.useMemo(()=>{const v=[];Aj(N)&&v.push({type:"up",value:"browse:up",name:"..",path:rd(N)});for(const je of de){const Pe=Pn(je.path);v.push({type:"directory",value:`browse:${je.path}`,name:je.name,path:je.path,disabled:!!(Pe&&be.has(Pe))})}return v},[be,de,N]);o.useEffect(()=>{z(0)},[N,Z.length]);const se=o.useMemo(()=>ne?Li(Yl(N,ne)):"",[ne,N]),ve=Pn(se),G=!!(ve&&be.has(ve)),ee=o.useMemo(()=>he?de.find(v=>v.name===he)??null:null,[he,de]),ie=!!(se&&!G&&(Xn(N)&&M||!Xn(N)&&he.trim().length>0&&ee===null)),pe=!R&&!W&&!G&&!!se,Ae=pe&&F.trim().length>0,Se=Z[A]??null,De=!!(Se&&(Se.type==="up"||Se.type==="directory"&&!Se.disabled)),Me=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Te=n(G?"directoryExplorerDialog.actions.alreadyAdded":$?R?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":R?"directoryExplorerDialog.actions.adding":ie?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const v=D.current;if(!v)return;const je=()=>k(Math.ceil(v.getBoundingClientRect().width));if(je(),typeof ResizeObserver>"u")return;const Pe=new ResizeObserver(je);return Pe.observe(v),()=>Pe.disconnect()},[Te]),o.useLayoutEffect(()=>{const v=x.current;v&&(v.scrollLeft=v.scrollWidth)},[Y,N]),o.useLayoutEffect(()=>{s&&ai(x.current)},[s]),o.useLayoutEffect(()=>{const v=Z[A];v&&P.current.get(v.value)?.scrollIntoView({block:"nearest"})},[A,Z]);const Be=o.useCallback(()=>{e(!1)},[e]),ze=o.useCallback((v,je)=>{v.stopPropagation();const Pe=Pn(je);if(Pe&&be.has(Pe))return;i(je)||_.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")})},[i,be,n]),Oe=o.useCallback(async v=>{if(!v||R)return;const je=Pn(v);if(je&&be.has(je))return;let Pe=v;Q(!0);try{const Le=!$&&ie&&Pn(v)===Pn(se);if($){const rt=F.trim();if(!rt){_.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Pe=(await ys.cloneRepository({remoteUrl:rt,destinationPath:v,gitIdentityId:ye?.id??null})).path}else Le&&await ys.createDirectory(v);if(!i(Pe)){_.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}Be()}catch(Le){_.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Le instanceof Error?Le.message:n("directoryExplorerDialog.toast.unknownError")})}finally{Q(!1)}},[i,be,F,Be,$,R,ye?.id,ie,se,n]),$e=o.useCallback(v=>{b(Ij(v))},[]),Ke=o.useCallback(v=>{b(Dj(N,v.name))},[N]),Ye=o.useCallback(v=>{if(v){if(v.type==="up"){v.path&&$e(v.path);return}v.disabled||Ke(v)}},[$e,Ke]),Re=o.useCallback(async()=>{if(!(!u||W)){te(!0);try{const v=await w(se);if(!v.success||!v.path){v.error&&v.error!=="Directory selection cancelled"&&_.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:v.error});return}const je=await g(v.path);if(!je.success){_.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:je.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Oe(v.path)}catch(v){_.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:v instanceof Error?v.message:n("directoryExplorerDialog.toast.unknownError")})}finally{te(!1)}}},[Oe,u,W,w,g,n,se]),V=o.useCallback(v=>{if(v.key==="ArrowDown"){v.preventDefault(),z(je=>Math.min(Z.length-1,je+1));return}if(v.key==="ArrowUp"){v.preventDefault(),z(je=>Math.max(0,je-1));return}if(v.key==="Enter"){if(v.preventDefault(),Ej(v)){Oe(se);return}De&&Ye(Se);return}v.key==="Backspace"&&N===""&&(v.preventDefault(),Be())},[Ye,Oe,Be,De,Se,N,Z.length,se]),oe=t.jsxs("button",{type:"button",onClick:()=>le(v=>!v),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[re?t.jsx(E,{name:"checkbox",className:"h-4 w-4 text-primary"}):t.jsx(E,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),ge=t.jsxs("div",{className:"px-2.5 py-1.5",children:[$?t.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[t.jsx(Xe,{value:F,onChange:v=>O(v.target.value),placeholder:n("directoryExplorerDialog.clone.remoteUrlPlaceholder"),className:"min-w-0 flex-1 border-border/60 bg-[var(--surface-elevated)] font-mono typography-ui-label shadow-none",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),t.jsx(nd,{activeProfile:ye,identities:ae,onSelect:v=>H(v.id),isApplying:R,iconOnly:!0})]}):null,t.jsxs("div",{className:"relative",children:[t.jsx(E,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),t.jsx(Xe,{ref:x,value:N,onChange:v=>b(ir(v.target.value)),onKeyDown:V,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!f&&Y>0?{paddingRight:`${Y+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),f?null:t.jsx(q,{ref:D,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:$?!Ae:!pe,onMouseDown:v=>v.preventDefault(),onClick:()=>{Oe(se)},title:Te,children:Te})]})]}),Fe=t.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:t.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[t.jsx("div",{className:"px-2 pb-1 pt-0.5 typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),U?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):Z.length===0?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):t.jsx("div",{className:"space-y-0.5",children:Z.map((v,je)=>{const Pe=je===A;return t.jsxs("button",{ref:Le=>{Le?P.current.set(v.value,Le):P.current.delete(v.value)},type:"button",disabled:v.type==="directory"&&v.disabled,onMouseEnter:()=>z(je),onMouseDown:Le=>Le.preventDefault(),onClick:()=>Ye(v),className:ce("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Pe&&"bg-interactive-selection text-interactive-selection-foreground",!Pe&&"hover:bg-interactive-hover/50",v.type==="directory"&&v.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[v.type==="up"?t.jsx(E,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):t.jsx(E,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),t.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:t.jsx("span",{className:"truncate typography-ui-label text-foreground",children:v.name})}),v.type==="directory"&&v.disabled?t.jsx("span",{className:"rounded-full border border-border/60 px-2 py-0.5 typography-meta text-muted-foreground",children:n("directoryExplorerDialog.browse.addedBadge")}):v.type==="directory"?t.jsx("button",{type:"button",onMouseDown:Le=>Le.stopPropagation(),onClick:Le=>ze(Le,v.path),className:"flex-shrink-0 rounded-full p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",title:n("directoryExplorerDialog.browse.quickAdd"),children:t.jsx(E,{name:"add",className:"h-3.5 w-3.5"})}):null]},v.value)})})]})}),Ne=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[ge,Fe]}),He=t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(E,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),t.jsx(E,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(E,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx("span",{children:Me}),t.jsx(E,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),X=()=>t.jsxs(t.Fragment,{children:[f?null:He,t.jsxs("div",{className:ce("flex w-full flex-row justify-end gap-2 sm:w-auto",f&&"justify-stretch"),children:[u?t.jsx(q,{variant:"ghost",size:"xs",onClick:Re,disabled:R||W||$,children:n(W?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,t.jsx(q,{variant:"ghost",size:"xs",onClick:()=>B(v=>!v),disabled:R||W,className:ce(f&&"flex-1"),children:n($?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),f?t.jsx(q,{size:"xs",onClick:()=>{Oe(se)},disabled:$?!Ae:!pe,className:"flex-1",children:Te}):null]})]});return f?t.jsx(ya,{open:s,onClose:Be,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:t.jsx("div",{className:"flex flex-col gap-2",children:X()}),children:t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[t.jsx("div",{className:"flex justify-end",children:oe}),Ne]})}):t.jsx(Rt,{open:s,onOpenChange:e,children:t.jsxs(Ft,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(Kt,{className:"px-5 pb-2 pt-5",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{children:[t.jsx(zt,{children:n("directoryExplorerDialog.title")}),t.jsx($t,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),oe]})}),t.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:Ne}),t.jsx(Gt,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:X()})]})})};function Xl(s){const{localBranches:e,remoteBranches:n,query:a}=s,r=a.trim();if(!r)return{matching:[],otherLocal:e,otherRemote:n};const i=to(e,r,m=>m),l=to(n,r,m=>m),d=[],c=i.other,h=l.other;for(const m of i.matching)d.push({label:m,value:m,source:"local"});for(const m of l.matching)d.push({label:m,value:`remotes/${m}`,source:"remote"});return d.sort((m,p)=>{const u=m.label.localeCompare(p.label,void 0,{sensitivity:"accent"});return u!==0?u:m.source!==p.source?m.source.localeCompare(p.source):m.value.localeCompare(p.value)}),{matching:d,otherLocal:c,otherRemote:h}}const ri="oc:lastWorktreeSourceBranch",Tj=({mode:s,sourceBranch:e,linkedPr:n,selectedBranch:a})=>s==="existing-branch"?a||null:n?null:e||null,Rj=({branches:s,savedSourceBranch:e,rootBranch:n})=>!!(e&&s.includes(e))&&e?{sourceBranch:e,shouldClearSavedSourceBranch:!1}:{sourceBranch:n&&s.includes(n)?n:s.includes("main")?"main":s.includes("master")?"master":s[0]??"",shouldClearSavedSourceBranch:!!e};function Fj({open:s,onOpenChange:e,onSelect:n}){const{t:a}=st(),r=Ie(Z=>Z.isMobile),{github:i}=Di(),l=Xs(Z=>Z.status),d=Xs(Z=>Z.hasChecked),c=Ie(Z=>Z.setSettingsDialogOpen),h=Ie(Z=>Z.setSettingsPage),m=es(Z=>Z.getActiveProject()),p=m?.path??null,u=xe.useMemo(()=>p&&m?{id:m.id,path:p}:null,[m,p]),[w,g]=xe.useState("issues"),[f,x]=xe.useState(""),[D,P]=xe.useState([]),[I,L]=xe.useState([]),[N,b]=xe.useState(!1),[j,T]=xe.useState(!1),[U,K]=xe.useState(null),[M,C]=xe.useState(null),[A,z]=xe.useState(null),[R,Q]=xe.useState(!1),[W,te]=xe.useState(new Map),[Y,k]=xe.useState(1),[$,B]=xe.useState(!1),F=bm(f,350),O=xe.useCallback(async Z=>{if(!(!p||!i)&&!(d&&l?.connected===!1)){b(!0),K(null),k(1),B(!1);try{if(w==="issues"&&i.issuesList){const se=await i.issuesList(p,{page:1,query:Z});se.connected===!1?(K(a("session.githubIntegration.error.notConnected")),P([])):(P(se.issues??[]),k(se.page??1),B(!!se.hasMore))}else if(w==="prs"&&i.prsList){const se=await i.prsList(p,{page:1,query:Z});se.connected===!1?(K(a("session.githubIntegration.error.notConnected")),L([])):(L(se.prs??[]),k(se.page??1),B(!!se.hasMore))}}catch(se){K(se instanceof Error?se.message:a("session.githubIntegration.error.loadDataFailed"))}finally{b(!1)}}},[p,i,d,l,w,a]);xe.useEffect(()=>{if(!s||!p||d&&l?.connected===!1||!i)return;if(!F.trim()){O();return}const Z=new AbortController;b(!0),K(null),k(1),B(!1);const se=w==="issues"&&i.issuesList?i.issuesList(p,{page:1,query:F.trim()}):w==="prs"&&i.prsList?i.prsList(p,{page:1,query:F.trim()}):null;if(!se){b(!1);return}return se.then(ve=>{Z.signal.aborted||("issues"in ve?ve.connected===!1?(K(a("session.githubIntegration.error.notConnected")),P([])):(P(ve.issues??[]),k(ve.page??1),B(!!ve.hasMore)):"prs"in ve&&(ve.connected===!1?(K(a("session.githubIntegration.error.notConnected")),L([])):(L(ve.prs??[]),k(ve.page??1),B(!!ve.hasMore))))}).catch(ve=>{Z.signal.aborted||K(ve instanceof Error?ve.message:a("session.githubIntegration.error.loadDataFailed"))}).finally(()=>{Z.signal.aborted||b(!1)}),()=>Z.abort()},[s,p,i,d,l,w,F,O,a]);const J=xe.useCallback(async()=>{if(!(!p||!i)&&!(N||j)&&$){T(!0);try{const Z=Y+1;if(w==="issues"&&i.issuesList){const se=F.trim()?await i.issuesList(p,{page:Z,query:F.trim()}):await i.issuesList(p,{page:Z});se.connected!==!1&&(P(ve=>[...ve,...se.issues??[]]),k(se.page??Z),B(!!se.hasMore))}else if(w==="prs"&&i.prsList){const se=F.trim()?await i.prsList(p,{page:Z,query:F.trim()}):await i.prsList(p,{page:Z});se.connected!==!1&&(L(ve=>[...ve,...se.prs??[]]),k(se.page??Z),B(!!se.hasMore))}}catch{}finally{T(!1)}}},[p,i,w,Y,$,N,j,F]);xe.useEffect(()=>{if(!s){g("issues"),x(""),P([]),L([]),C(null),z(null),Q(!1),K(null),te(new Map),k(1),B(!1);return}O()},[s,O]);const H=xe.useCallback(async Z=>{if(!(!u||!Z)&&!W.has(Z))try{const ve=(await gc(u,{mode:"new",branchName:Z,worktreeName:Z})).errors.find(G=>G.code==="branch_in_use");te(G=>new Map(G).set(Z,{isValid:!ve,error:ve?a(ve.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{te(se=>new Map(se).set(Z,{isValid:!1,error:a("session.githubIntegration.validation.failed")}))}},[u,W,a]);xe.useEffect(()=>{!s||w!=="prs"||I.forEach(Z=>{Z.head&&H(Z.head)})},[s,w,I,H]);const re=d&&l?.connected===!0,le=()=>{h("github"),c(!0)},ne=Z=>{C(Z),z(null)},be=Z=>{z(Z),C(null)},ae=()=>{M?n({type:"issue",item:M}):A&&n({type:"pr",item:A,includeDiff:R}),e(!1)},ye=()=>{C(null),z(null),Q(!1)},ke=M||A&&W.get(A.head??"")?.isValid!==!1,he=Z=>Z.head?W.get(Z.head)?.isValid===!1:!0,we=t.jsx(t.Fragment,{children:re?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative mt-2",children:[t.jsx(E,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),t.jsx(Xe,{value:f,onChange:Z=>x(Z.target.value),placeholder:a(w==="issues"?"session.githubIntegration.search.issuesPlaceholder":"session.githubIntegration.search.prsPlaceholder"),className:"h-8 pl-9"})]}),t.jsx("div",{className:"mt-2 h-[300px] overflow-hidden",children:t.jsxs("div",{className:"h-full overflow-y-auto",children:[N&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx(E,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),U&&t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[t.jsx(E,{name:"error-warning",className:"h-4 w-4"}),t.jsx("span",{className:"typography-small",children:U})]})}),!N&&!U&&w==="issues"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[D.length>0?D.map(Z=>t.jsx("button",{onClick:()=>ne(Z),className:ce("w-full text-left px-2 py-1.5 rounded transition-colors",M?.number===Z.number?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",Z.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-2",children:Z.title}),Z.sourceRepo?.source==="upstream"?t.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block",children:[Z.sourceRepo.owner,"/",Z.sourceRepo.repo]}):null]})]})},`${Z.sourceRepo?.owner??""}-${Z.sourceRepo?.repo??""}-${Z.number}`)):t.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:a("session.githubIntegration.empty.noIssuesFound")}),$&&!j&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>{J()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),j&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(E,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!N&&!U&&w==="prs"&&t.jsxs("div",{className:"space-y-0.5 min-h-full",children:[I.length>0?I.map(Z=>{const se=he(Z),ve=Z.head?W.get(Z.head):void 0;return t.jsx("button",{onClick:()=>!se&&be(Z),disabled:se,className:ce("w-full text-left px-2 py-1.5 rounded transition-colors",A?.number===Z.number?"bg-interactive-selection text-interactive-selection-foreground":se?"opacity-50 cursor-not-allowed":"hover:bg-interactive-hover"),children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",Z.number]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"typography-small line-clamp-1",children:Z.title}),t.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[Z.head," → ",Z.base]}),Z.sourceRepo?.source==="upstream"?t.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[Z.sourceRepo.owner,"/",Z.sourceRepo.repo]}):null,se&&ve?.error&&t.jsx("span",{className:"typography-micro text-destructive",children:ve.error})]})]})]})},`${Z.sourceRepo?.owner??""}-${Z.sourceRepo?.repo??""}-${Z.number}`)}):t.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:a("session.githubIntegration.empty.noPullRequestsFound")}),$&&!j&&t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>{J()},className:"h-7 text-xs",children:a("session.githubIntegration.actions.loadMore")})}),j&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(E,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]})]})})]}):t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 gap-4",children:[t.jsx(E,{name:"github",className:"h-12 w-12 text-muted-foreground"}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"typography-ui-label text-foreground",children:a("session.githubIntegration.connect.title")}),t.jsx("p",{className:"typography-small text-muted-foreground mt-1",children:a("session.githubIntegration.connect.description")})]}),t.jsx(q,{onClick:le,size:"sm",children:a("session.githubIntegration.connect.action")})]})}),de=t.jsxs("div",{className:ce("w-full",r?"flex flex-col gap-2":"flex flex-row items-center"),children:[t.jsxs("div",{className:ce("flex items-center gap-4",r?"w-full justify-center order-1":"flex-1"),children:[!r&&(M||A)&&t.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[t.jsx(E,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),t.jsx("span",{className:"typography-small truncate max-w-[150px]",children:M?a("session.githubIntegration.selected.issueNumber",{number:M.number}):a("session.githubIntegration.selected.prNumber",{number:A?.number??""})}),t.jsx("button",{onClick:ye,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})})]}),w==="prs"&&A&&t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[t.jsx(yt,{checked:R,onChange:Z=>Q(Z),ariaLabel:a("session.githubIntegration.includeDiffAria")}),t.jsx("span",{className:"typography-small text-foreground",children:a("session.githubIntegration.includeDiff")})]})]}),t.jsxs("div",{className:ce("flex gap-2",r?"w-full order-2":"justify-end"),children:[t.jsx(q,{variant:"outline",size:"sm",onClick:()=>e(!1),className:ce(r&&"flex-1"),children:a("session.githubIntegration.actions.cancel")}),t.jsx(q,{size:"sm",onClick:ae,disabled:!ke,className:ce(r&&"flex-1"),children:a("session.githubIntegration.actions.select")})]})]});return t.jsx(t.Fragment,{children:r?t.jsx(ya,{open:s,title:a("session.githubIntegration.title"),onClose:()=>e(!1),footer:re?de:void 0,renderHeader:Z=>t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2 border-b border-border/40",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:a("session.githubIntegration.title")}),Z]}),t.jsx("div",{className:"w-full",children:t.jsx(Fn,{items:[{id:"issues",label:a("session.githubIntegration.tabs.issues"),icon:t.jsx(E,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:a("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(E,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:w,onSelect:se=>{g(se),x("")},variant:"active-pill",layoutMode:"fit"})}),(M||A)&&t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[t.jsx(E,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),t.jsx("span",{className:"typography-small truncate flex-1",children:M?a("session.githubIntegration.selected.issueNumber",{number:M.number}):a("session.githubIntegration.selected.prNumber",{number:A?.number??""})}),t.jsx("button",{onClick:ye,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:we}):t.jsx(Rt,{open:s,onOpenChange:e,children:t.jsxs(Ft,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsx(Kt,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(zt,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(E,{name:"github",className:"h-5 w-5"}),a("session.githubIntegration.title")]}),t.jsx("div",{className:"w-[220px]",children:t.jsx(Fn,{items:[{id:"issues",label:a("session.githubIntegration.tabs.issues"),icon:t.jsx(E,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:a("session.githubIntegration.tabs.pullRequests"),icon:t.jsx(E,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:w,onSelect:Z=>{g(Z),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),we,t.jsx(Gt,{className:"mt-1",children:de})]})})})}const xa=s=>s.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),hs=s=>s.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,"").split("/").join("-").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"").slice(0,80),Lj=s=>String(s).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",Zl=(s,e,n)=>{const a=xa(s.head||"");if(!a)throw new Error("PR head branch is missing");if(e.includes(a))return{existingBranch:a,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:a};const r=n.find(h=>{const m=h.indexOf("/");return m<=0||m>=h.length-1?!1:h.slice(m+1)===a});if(r){const h=r.indexOf("/"),m=r.slice(0,h);return{existingBranch:`remotes/${r}`,setUpstream:!0,upstreamRemote:m,upstreamBranch:a,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${m}/${a}`}}const i=String(s.headLabel||"").split(":")[0]?.trim(),l=s.headRepo?.owner||i||"pr-head",d=`pr-${Lj(l)}`,c=s.headRepo?.sshUrl||s.headRepo?.cloneUrl||"";if(!c)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${d}/${a}`,setUpstream:!0,upstreamRemote:d,upstreamBranch:a,ensureRemoteName:d,ensureRemoteUrl:c,sourceLabel:`${d}/${a}`}},Oj=s=>{const e={repo:s.repo??null,issue:s.issue,comments:s.comments};return`GitHub issue context (JSON)
|
|
166
|
+
${JSON.stringify(e,null,2)}`},zj=s=>`GitHub pull request context (JSON)
|
|
167
|
+
${JSON.stringify(s,null,2)}`;function ow({open:s,onOpenChange:e,onWorktreeCreated:n}){const{t:a}=st(),{github:r,git:i}=Di(),l=Ie(X=>X.isMobile),d=Xs(X=>X.status),c=Xs(X=>X.hasChecked),h=es(X=>X.getActiveProject()),m=h?.path??null,p=xe.useMemo(()=>m&&h?{id:h.id,path:m}:null,[h,m]),[u,w]=xe.useState("new-branch"),[g,f]=xe.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,D]=xe.useState({selectedBranch:"",worktreeName:""}),P=vm(m),I=jm(m),L=wm(X=>X.fetchBranches),N=xe.useMemo(()=>P?.all?P.all.filter(X=>!X.startsWith("remotes/")).sort():[],[P]),b=xe.useMemo(()=>P?.all?P.all.filter(X=>X.startsWith("remotes/")).map(X=>X.replace(/^remotes\//,"")).sort():[],[P]),j=fs(X=>X.availableWorktreesByProject),T=xe.useMemo(()=>{if(!m)return new Set;const X=j.get(m)??[];return new Set(X.map(v=>v.name))},[j,m]),U=xe.useCallback((X=10)=>{for(let v=0;v<X;v++){const je=Pr();if(!T.has(je))return je}return`${Pr()}-${Date.now().toString(36).slice(-4)}`},[T]),[K,M]=xe.useState(!1),[C,A]=xe.useState(!1),[z,R]=xe.useState(!1),[Q,W]=xe.useState(!1),[te,Y]=xe.useState(!1),[k,$]=xe.useState(""),[B,F]=xe.useState(""),O=xe.useRef(null),J=xe.useRef(null),H=xe.useRef(null),re=xe.useRef(null),le=xe.useCallback(X=>{X.stopPropagation()},[]),ne=xe.useCallback(X=>{let v=X;for(;v&&v!==document.body;){const{overflowY:je}=window.getComputedStyle(v);if((je==="auto"||je==="scroll")&&v.scrollHeight>v.clientHeight)return v;v=v.parentElement}return null},[]),be=xe.useCallback(X=>{X&&(X.scrollTop=0)},[]),ae=xe.useCallback(X=>{const v=X.current?.querySelector('[data-slot="command-list"]')??null;be(v)},[be]),ye=xe.useCallback(X=>{const v=ne(X.current);be(v)},[ne,be]),ke=xe.useMemo(()=>Xl({localBranches:N,remoteBranches:b,query:k}),[N,b,k]),he=xe.useMemo(()=>Xl({localBranches:N,remoteBranches:b,query:B}),[N,b,B]),we=k.trim().length>0,de=B.trim().length>0,Z=ke.matching.length>0,se=he.matching.length>0,ve=!!(m&&i),G=xe.useCallback(()=>{!m||!i||L(m,i)},[m,i,L]);xe.useEffect(()=>{!s||!m||!i||P?.all||L(m,i)},[s,m,i,P?.all,L]),xe.useEffect(()=>{!C&&!Q&&$("")},[C,Q]),xe.useEffect(()=>{!z&&!te&&F("")},[z,te]),xe.useEffect(()=>{C&&ae(O),Q&&ye(H)},[C,Q,k,ae,ye]),xe.useEffect(()=>{z&&ae(J),te&&ye(re)},[z,te,B,ae,ye]);const[ee,ie]=xe.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[pe,Ae]=xe.useState(!1),[Se,De]=xe.useState(null),Me=xe.useCallback(()=>{const X=lt.getState(),v=X.getVisibleAgents();if(X.settingsDefaultAgent){const je=v.find(Pe=>Pe.name===X.settingsDefaultAgent);if(je)return je.name}return v.find(je=>je.name==="build")?.name||v[0]?.name},[]),Te=xe.useCallback(()=>{const X=lt.getState(),v=X.settingsDefaultModel;if(!v)return null;const je=fn(v);if(!je)return null;const{providerId:Pe,modelId:Le}=je;return X.getModelMetadata(Pe,Le)?{providerID:Pe,modelID:Le}:null},[]),Be=xe.useCallback((X,v)=>{const je=lt.getState(),Pe=je.settingsDefaultVariant,Le=je.currentProviderId===X&&je.currentModelId===v?je.currentVariant:void 0,ot=je.providers.find(it=>it.id===X)?.models.find(it=>it.id===v)?.variants;if(!ot)return Pe||Le||void 0;if(Pe&&Object.prototype.hasOwnProperty.call(ot,Pe))return Pe;if(Le&&Object.prototype.hasOwnProperty.call(ot,Le))return Le},[]),ze=xe.useCallback(async X=>{if(!m||!r)return;const v=lt.getState(),je=Nm.getState().lastUsedProvider,Pe=Te(),Le=Pe?.providerID||v.currentProviderId||je?.providerID,qe=Pe?.modelID||v.currentModelId||je?.modelID,rt=Me()||v.currentAgentName||void 0;if(!Le||!qe){_.error(a("session.newWorktree.error.noModelSelected"));return}const ot=Be(Le,qe);if(X.issue){if(!r.issueGet||!r.issueComments)return;const it=await r.issueGet(m,X.issue.number,{sourceRepo:X.issue.sourceRepo??null});if(it.connected===!1||!it.repo||!it.issue)throw new Error("Failed to load issue context");const dt=await r.issueComments(m,X.issue.number,{sourceRepo:X.issue.sourceRepo??null});if(dt.connected===!1)throw new Error("Failed to load issue comments");const Je=await Aa("github.issue.review.visible",{issue_number:String(X.issue.number)}),_e=await Aa("github.issue.review.instructions"),gt=Oj({repo:it.repo,issue:it.issue,comments:dt.comments??[]});await fs.getState().sendMessage(Je,Le,qe,rt,void 0,void 0,[{text:_e,synthetic:!0},{text:gt,synthetic:!0}],ot,void 0,{sessionId:X.sessionId}),_.success(a("session.newWorktree.toast.sessionFromIssue"));return}if(X.pr){if(!r.prContext)return;const it=await r.prContext(m,X.pr.number,{sourceRepo:X.pr.sourceRepo??null,includeDiff:X.includeDiff,includeCheckDetails:!1});if(it.connected===!1||!it.repo||!it.pr)throw new Error("Failed to load PR context");const dt=await Aa("github.pr.review.visible",{pr_number:String(X.pr.number)}),Je=await Aa("github.pr.review.instructions"),_e=zj(it);await fs.getState().sendMessage(dt,Le,qe,rt,void 0,void 0,[{text:Je,synthetic:!0},{text:_e,synthetic:!0}],ot,void 0,{sessionId:X.sessionId}),_.success(a("session.newWorktree.toast.sessionFromPr"))}},[r,m,Me,Te,Be,a]),Oe=u==="new-branch"?g:x;xe.useEffect(()=>{if(!s||!P?.all||!m||g.sourceBranch)return;const X=g.sourceBranch;let v=!1;return(async()=>{try{const Pe=await km(m).catch(()=>null);if(v)return;const Le=localStorage.getItem(ri),{sourceBranch:qe,shouldClearSavedSourceBranch:rt}=Rj({branches:P.all,savedSourceBranch:Le,rootBranch:Pe});if(rt&&localStorage.removeItem(ri),v||X)return;qe&&f(ot=>({...ot,sourceBranch:qe}))}catch{}})(),()=>{v=!0}},[s,P?.all,m,g.sourceBranch]),xe.useLayoutEffect(()=>{if(!s)return;w("new-branch"),D({selectedBranch:"",worktreeName:""}),A(!1),R(!1),W(!1),Y(!1),$(""),F(""),ie({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const X=U();f({branchName:X,worktreeName:X,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[s,U]),xe.useEffect(()=>{if(u!=="new-branch"||!g.isSyncingWorktreeName)return;const X=xa(g.branchName),v=hs(X);f(je=>({...je,worktreeName:v}))},[u,g.branchName,g.isSyncingWorktreeName]);const $e=xe.useCallback(async()=>{if(!p||!ee.touched||pe)return;Se&&Se.abort();const X=new AbortController;De(X),ie(v=>({...v,isValidating:!0}));try{const v=u==="new-branch"?g.branchName:x.selectedBranch,je=Oe.worktreeName,Pe=xa(v),Le=hs(je);let qe=null,rt=null;if(Pe||(qe=a("session.newWorktree.error.branchNameRequired")),Le||(rt=a("session.newWorktree.error.worktreeDirectoryRequired")),Pe&&Le){const ot=u==="new-branch"?g.linkedPr:null,it=ot?Zl(ot,N,b):null,dt=await gc(p,{mode:u==="existing-branch"||it?"existing":"new",branchName:Pe,worktreeName:Le,existingBranch:it?.existingBranch??(u==="existing-branch"?Pe:void 0),...it?.ensureRemoteName?{ensureRemoteName:it.ensureRemoteName}:{},...it?.ensureRemoteUrl?{ensureRemoteUrl:it.ensureRemoteUrl}:{}});if(X.signal.aborted)return;dt.ok||dt.errors.forEach(Je=>{if(Je.code==="worktree_exists"){rt=rt??Je.message;return}Je.code.startsWith("branch_")&&(qe=qe??Je.message)})}X.signal.aborted||ie(ot=>({...ot,isValidating:!1,branchError:qe,worktreeError:rt}))}catch{X.signal.aborted||ie(v=>({...v,isValidating:!1}))}},[p,u,g.branchName,g.linkedPr,x.selectedBranch,Oe.worktreeName,N,b,ee.touched,Se,pe,a]),Ke=u==="new-branch"?g.branchName:x.selectedBranch;xe.useEffect(()=>{if(!s||!p||!ee.touched||pe)return;const X=setTimeout(()=>{$e()},300);return()=>clearTimeout(X)},[Oe.worktreeName,Ke,s,p,$e,ee.touched,pe]);const Ye=async()=>{if(!p||!m){_.error(a("session.newWorktree.error.noActiveProject"));return}ie(Le=>({...Le,touched:!0}));const X=u==="new-branch"?g.branchName:x.selectedBranch,v=Oe.worktreeName,je=xa(X),Pe=hs(v);if(!je){_.error(a("session.newWorktree.error.branchNameRequired"));return}if(!Pe){_.error(a("session.newWorktree.error.worktreeDirectoryRequired"));return}Se&&(Se.abort(),De(null)),ie(Le=>({...Le,isValidating:!1,branchError:null,worktreeError:null})),Ae(!0);try{const Le=u==="new-branch"?g.linkedPr:null,qe=u==="new-branch"?g.linkedIssue:null,rt=u==="new-branch"?g.linkedPr:null,ot=u==="new-branch"?g.includePrDiff:!1,it=!!(qe||rt),dt=await dc(p),Je=g.sourceBranch;let _e="";const gt=(()=>{if(Le){const ft=Zl(Le,N,b);return _e=ft.sourceLabel,{preferredName:je||Pe,mode:"existing",branchName:je,worktreeName:Pe,existingBranch:ft.existingBranch,setupCommands:dt,setUpstream:ft.setUpstream,upstreamRemote:ft.upstreamRemote,upstreamBranch:ft.upstreamBranch,returnAfterDirectoryCreated:!0,...ft.ensureRemoteName?{ensureRemoteName:ft.ensureRemoteName}:{},...ft.ensureRemoteUrl?{ensureRemoteUrl:ft.ensureRemoteUrl}:{}}}return _e=u==="new-branch"?Je:"",{preferredName:je||Pe,mode:u==="existing-branch"?"existing":"new",branchName:u==="existing-branch"?void 0:je,worktreeName:Pe,existingBranch:u==="existing-branch"?je:void 0,setupCommands:dt,returnAfterDirectoryCreated:!0,...Je&&u==="new-branch"?{startRef:Je}:{}}})(),fe=await Sm(m,gt),tt=await Cm(p,fe);let nt=null;if(it){await uc(p)&&await Im(tt.path);const ft=qe?`#${qe.number} ${qe.title}`.trim():rt?`#${rt.number} ${rt.title}`.trim():a("session.newWorktree.newSessionTitle"),bt=await Pm(ft,tt.path,null);if(!bt?.id)throw new Error("Failed to create session");nt=bt.id,n?.(tt.path,{sessionId:nt}),e(!1),Ae(!1),Am(bt.id,ft).catch(()=>{});try{fs.getState().initializeNewOpenChamberSession(bt.id,lt.getState().agents)}catch{}}else e(!1),Ae(!1);const Ze=Tj({mode:u,sourceBranch:g.sourceBranch,linkedPr:!!g.linkedPr,selectedBranch:x.selectedBranch});Ze&&localStorage.setItem(ri,Ze),_.success(a("session.newWorktree.toast.worktreeCreated"),{description:a("session.newWorktree.toast.worktreeCreatedDescription",{target:`${tt.branch||tt.name}${_e?` ${a("session.newWorktree.fromSource",{source:_e})}`:""}`})}),nt?ze({sessionId:nt,directory:tt.path,issue:qe,pr:rt,includeDiff:ot}).catch(ft=>{const bt=ft instanceof Error?ft.message:a("session.newWorktree.error.sendGitHubContextFailed");_.error(a("session.newWorktree.error.sendGitHubContextFailed"),{description:bt})}):n?.(tt.path)}catch(Le){const qe=Le instanceof Error?Le.message:a("session.newWorktree.error.createWorktreeFailed");_.error(a("session.newWorktree.error.createWorktreeFailed"),{description:qe})}finally{Ae(!1)}},Re=X=>{w(X),ie(v=>({...v,touched:!1,branchError:null,worktreeError:null}))},V=X=>{if(!X){f(v=>({...v,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(X.type==="issue"){const v=X.item,je=`issue-${v.number}-${Pr()}`;f(Pe=>({...Pe,linkedIssue:v,linkedPr:null,includePrDiff:!1,branchName:je,worktreeName:hs(je),isSyncingWorktreeName:!0}))}else if(X.type==="pr"){const v=X.item;f(je=>({...je,linkedPr:v,linkedIssue:null,includePrDiff:X.includeDiff??!1,branchName:v.head,worktreeName:hs(v.head),isSyncingWorktreeName:!0}))}},oe=c&&d?.connected===!0,Fe=(u==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!ee.branchError&&!ee.worktreeError:!!xa(g.branchName)&&!!g.worktreeName&&!ee.branchError&&!ee.worktreeError)&&!pe,Ne=()=>{f(X=>({...X,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},He=t.jsxs("div",{className:ce("flex gap-2",l?"flex-col w-full":"flex-row items-center"),children:[t.jsx("div",{className:ce("flex items-center gap-1.5 text-destructive",l?"w-full justify-center order-first":"mr-auto"),children:ee.touched&&(ee.branchError||ee.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:ee.branchError||ee.worktreeError})]})}),t.jsxs("div",{className:ce("flex gap-2",l&&"w-full"),children:[t.jsx(q,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:pe,className:ce(l&&"flex-1"),children:a("session.newWorktree.actions.cancel")}),t.jsxs(q,{size:"sm",onClick:Ye,disabled:!Fe||pe,className:ce("gap-1.5",l&&"flex-1"),children:[pe&&t.jsx(E,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(pe?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return t.jsxs(t.Fragment,{children:[l?t.jsxs(ya,{open:s,title:a("session.newWorktree.title"),onClose:()=>e(!1),footer:He,children:[t.jsx("div",{className:"w-full mb-4",children:t.jsx(Fn,{items:[{id:"new-branch",label:a("session.newWorktree.mode.newBranch"),icon:t.jsx(E,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:a("session.newWorktree.mode.existingBranch"),icon:t.jsx(E,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:u,onSelect:X=>Re(X),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),t.jsxs("div",{className:"space-y-6",children:[u==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(q,{variant:"outline",size:"sm",onClick:()=>W(!0),className:"flex-1 justify-between h-9",children:[t.jsx("span",{className:x.selectedBranch?"text-foreground":"text-muted-foreground",children:x.selectedBranch||a("session.newWorktree.chooseBranch")}),t.jsx(E,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),t.jsx(q,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:G,disabled:!ve||I,title:a("session.newWorktree.fetchBranches"),children:I?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"refresh",className:"size-4"})})]}),t.jsx(ya,{open:Q,title:a("session.newWorktree.selectBranch"),onClose:()=>W(!1),children:t.jsxs("div",{className:"space-y-4",ref:H,children:[t.jsx(Xe,{value:k,onChange:X=>$(X.target.value),placeholder:a("session.newWorktree.searchBranches"),className:"h-8"}),I?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):N.length===0&&b.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[we&&Z&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a("session.newWorktree.matchingBranches")}),t.jsx("div",{className:"space-y-1",children:ke.matching.map(X=>t.jsx("button",{onClick:()=>{D(v=>({...v,selectedBranch:X.value,worktreeName:hs(X.label)})),ie(v=>({...v,touched:!0})),W(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===X.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))})]}),we&&!Z&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),ke.otherLocal.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(we?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:ke.otherLocal.map(X=>t.jsx("button",{onClick:()=>{D(v=>({...v,selectedBranch:X,worktreeName:hs(X)})),ie(v=>({...v,touched:!0})),W(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===X?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X})},X))})]}),ke.otherRemote.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(we?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:ke.otherRemote.map(X=>t.jsx("button",{onClick:()=>{D(v=>({...v,selectedBranch:`remotes/${X}`,worktreeName:hs(X)})),ie(v=>({...v,touched:!0})),W(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${X}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X})},`remotes/${X}`))})]})]})]})})]}):t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.branchName")}),u==="new-branch"&&oe&&t.jsxs(q,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"gap-1.5 h-7",children:[t.jsx(E,{name:"github",className:"size-4 text-status-success"}),g.linkedIssue||g.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(Xe,{value:g.branchName,onChange:X=>{f(v=>({...v,branchName:X.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ie(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:ce("h-8",ee.touched&&ee.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(E,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.usingPrBranch",{branch:g.linkedPr.head})})]}),g.linkedIssue&&!g.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(E,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.fromIssue",{number:g.linkedIssue.number,title:g.linkedIssue.title})})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:a("session.newWorktree.worktreeDirectory")}),u!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const X=hs(u==="new-branch"?g.branchName:"");f(v=>({...v,worktreeName:X,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===hs(g.branchName),className:ce("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===hs(g.branchName)||!g.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:a("session.newWorktree.resetToMatchBranchName"),children:[t.jsx(E,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:a("session.newWorktree.actions.reset")})]})]}),t.jsx(Xe,{value:Oe.worktreeName,onChange:X=>{u==="new-branch"?f(v=>({...v,worktreeName:X.target.value,isSyncingWorktreeName:!1})):D(v=>({...v,worktreeName:X.target.value}))},onBlur:()=>ie(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:ce("h-8",ee.touched&&ee.worktreeError&&"border-destructive")})]}),u==="new-branch"&&!g.linkedPr&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.sourceBranch")}),t.jsxs(q,{variant:"outline",size:"sm",onClick:()=>Y(!0),className:"w-full justify-between h-9",children:[t.jsx("span",{className:g.sourceBranch?"text-foreground":"text-muted-foreground",children:g.sourceBranch||a("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(E,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),g.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:a("session.newWorktree.newBranchFromSource",{source:g.sourceBranch})}),t.jsx(ya,{open:te,title:a("session.newWorktree.selectSourceBranch"),onClose:()=>Y(!1),children:t.jsxs("div",{className:"space-y-4",ref:re,children:[t.jsx(Xe,{value:B,onChange:X=>F(X.target.value),placeholder:a("session.newWorktree.searchBranches"),className:"h-8"}),I?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):N.length===0&&b.length===0?t.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noBranchesFound")}):t.jsxs("div",{className:"space-y-4",children:[de&&se&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a("session.newWorktree.matchingBranches")}),t.jsx("div",{className:"space-y-1",children:he.matching.map(X=>t.jsx("button",{onClick:()=>{f(v=>({...v,sourceBranch:X.value})),Y(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===X.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))})]}),de&&!se&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),he.otherLocal.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(de?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),t.jsx("div",{className:"space-y-1",children:he.otherLocal.map(X=>t.jsx("button",{onClick:()=>{f(v=>({...v,sourceBranch:X})),Y(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===X?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X})},X))})]}),he.otherRemote.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:a(de?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),t.jsx("div",{className:"space-y-1",children:he.otherRemote.map(X=>t.jsx("button",{onClick:()=>{f(v=>({...v,sourceBranch:`remotes/${X}`})),Y(!1)},className:ce("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===`remotes/${X}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:t.jsx("span",{className:"typography-small break-all",children:X})},`remotes/${X}`))})]})]})]})})]}),(g.linkedIssue||g.linkedPr)&&u==="new-branch"&&t.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),g.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.issueNumber",{number:g.linkedIssue.number})}),g.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.prNumber",{number:g.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:g.linkedIssue?.title||g.linkedPr?.title}),t.jsx("a",{href:g.linkedIssue?.url||g.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:X=>X.stopPropagation(),children:t.jsx(E,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:Ne,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})})]}),g.linkedPr&&t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[g.linkedPr.head," → ",g.linkedPr.base]}),g.includePrDiff&&t.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:a("session.newWorktree.includeDiffBadge")})]})]})]})]}):t.jsx(Rt,{open:s,onOpenChange:e,children:t.jsxs(Ft,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[t.jsx(Kt,{className:"flex flex-row items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs(zt,{className:"flex items-center gap-2 shrink-0",children:[t.jsx(E,{name:"git-branch",className:"h-5 w-5"}),a("session.newWorktree.title")]}),t.jsx("div",{className:"w-[280px] shrink-0",children:t.jsx(Fn,{items:[{id:"new-branch",label:a("session.newWorktree.mode.newBranch"),icon:t.jsx(E,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:a("session.newWorktree.mode.existingBranch"),icon:t.jsx(E,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:u,onSelect:X=>Re(X),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),t.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[u==="existing-branch"?t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.selectBranch")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs(ds,{open:C,onOpenChange:A,children:[t.jsx(ls,{asChild:!0,children:t.jsxs(q,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[t.jsx("span",{className:ce("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||a("session.newWorktree.chooseBranch")}),t.jsx(E,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(cs,{align:"start",sideOffset:6,portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:O,children:t.jsxs(ci,{shouldFilter:!1,children:[t.jsx(di,{placeholder:a("session.newWorktree.searchBranches"),value:k,onValueChange:$,onKeyDown:le}),t.jsx(ui,{disableHorizontal:!0,children:I?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):N.length===0&&b.length===0?t.jsx(mi,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[we&&Z&&t.jsx(Js,{heading:a("session.newWorktree.matchingBranches"),children:ke.matching.map(X=>t.jsx(zs,{value:X.value,onSelect:()=>{D(v=>({...v,selectedBranch:X.value,worktreeName:hs(X.label)})),ie(v=>({...v,touched:!0})),A(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))}),we&&!Z&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),ke.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[we&&t.jsx(Gn,{}),t.jsx(Js,{heading:a(we?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ke.otherLocal.map(X=>t.jsx(zs,{value:X,onSelect:()=>{D(v=>({...v,selectedBranch:X,worktreeName:hs(X)})),ie(v=>({...v,touched:!0})),A(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`local-${X}`))})]}),ke.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(ke.otherLocal.length>0||we)&&t.jsx(Gn,{}),t.jsx(Js,{heading:a(we?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ke.otherRemote.map(X=>t.jsx(zs,{value:`remotes/${X}`,onSelect:()=>{D(v=>({...v,selectedBranch:`remotes/${X}`,worktreeName:hs(X)})),ie(v=>({...v,touched:!0})),A(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`remote-${X}`))})]})]})})]})})]}),t.jsx(q,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:G,disabled:!ve||I,title:a("session.newWorktree.fetchBranches"),children:I?t.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(E,{name:"refresh",className:"size-4"})})]})]}):t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.branchName")}),u==="new-branch"&&oe&&t.jsxs(q,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"gap-1.5 h-7",children:[t.jsx(E,{name:"github",className:"size-4 text-status-success"}),g.linkedIssue||g.linkedPr?a("session.newWorktree.actions.change"):a("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),t.jsx(Xe,{value:g.branchName,onChange:X=>{f(v=>({...v,branchName:X.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>ie(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:ce("h-8",ee.touched&&ee.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(E,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.usingPrBranch",{branch:g.linkedPr.head})})]}),g.linkedIssue&&!g.linkedPr&&t.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(E,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),t.jsx("span",{className:"typography-micro",children:a("session.newWorktree.fromIssue",{number:g.linkedIssue.number,title:g.linkedIssue.title})})]})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:a("session.newWorktree.worktreeDirectory")}),u!=="existing-branch"&&t.jsxs("button",{onClick:()=>{const X=hs(u==="new-branch"?g.branchName:"");f(v=>({...v,worktreeName:X,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===hs(g.branchName),className:ce("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===hs(g.branchName)||!g.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:a("session.newWorktree.resetToMatchBranchName"),children:[t.jsx(E,{name:"refresh",className:"h-3 w-3"}),t.jsx("span",{children:a("session.newWorktree.actions.reset")})]})]}),t.jsx(Xe,{value:Oe.worktreeName,onChange:X=>{u==="new-branch"?f(v=>({...v,worktreeName:X.target.value,isSyncingWorktreeName:!1})):D(v=>({...v,worktreeName:X.target.value}))},onBlur:()=>ie(X=>({...X,touched:!0})),placeholder:a("session.newWorktree.worktreeDirectoryPlaceholder"),className:ce("h-8",ee.touched&&ee.worktreeError&&"border-destructive")})]}),u==="new-branch"&&!g.linkedPr&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:a("session.newWorktree.sourceBranch")}),t.jsxs(ds,{open:z,onOpenChange:R,children:[t.jsx(ls,{asChild:!0,children:t.jsxs(q,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[t.jsx("span",{className:ce("truncate",g.sourceBranch?"text-foreground":"text-muted-foreground"),children:g.sourceBranch||a("session.newWorktree.selectSourceBranchPlaceholder")}),t.jsx(E,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),t.jsx(cs,{align:"start",portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:J,children:t.jsxs(ci,{shouldFilter:!1,children:[t.jsx(di,{placeholder:a("session.newWorktree.searchBranches"),value:B,onValueChange:F,onKeyDown:le}),t.jsx(ui,{disableHorizontal:!0,children:I?t.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:a("session.newWorktree.loadingBranches")}):N.length===0&&b.length===0?t.jsx(mi,{children:a("session.newWorktree.noBranchesFound")}):t.jsxs(t.Fragment,{children:[de&&se&&t.jsx(Js,{heading:a("session.newWorktree.matchingBranches"),children:he.matching.map(X=>t.jsx(zs,{value:X.value,onSelect:()=>{f(v=>({...v,sourceBranch:X.value})),R(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X.label})},`${X.source}-${X.value}`))}),de&&!se&&t.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:a("session.newWorktree.noMatchingBranches")}),he.otherLocal.length>0&&t.jsxs(t.Fragment,{children:[de&&t.jsx(Gn,{}),t.jsx(Js,{heading:a(de?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:he.otherLocal.map(X=>t.jsx(zs,{value:X,onSelect:()=>{f(v=>({...v,sourceBranch:X})),R(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`local-${X}`))})]}),he.otherRemote.length>0&&t.jsxs(t.Fragment,{children:[(he.otherLocal.length>0||de)&&t.jsx(Gn,{}),t.jsx(Js,{heading:a(de?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:he.otherRemote.map(X=>t.jsx(zs,{value:`remotes/${X}`,onSelect:()=>{f(v=>({...v,sourceBranch:`remotes/${X}`})),R(!1)},children:t.jsx("span",{className:"typography-small break-all",children:X})},`remote-${X}`))})]})]})})]})})]}),g.sourceBranch&&t.jsx("div",{className:"typography-micro text-muted-foreground",children:a("session.newWorktree.newBranchFromSource",{source:g.sourceBranch})})]}),(g.linkedIssue||g.linkedPr)&&u==="new-branch"&&t.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(E,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),g.linkedIssue&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.issueNumber",{number:g.linkedIssue.number})}),g.linkedPr&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:a("session.newWorktree.prNumber",{number:g.linkedPr.number})}),t.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:g.linkedIssue?.title||g.linkedPr?.title}),t.jsx("a",{href:g.linkedIssue?.url||g.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:X=>X.stopPropagation(),children:t.jsx(E,{name:"external-link",className:"h-3 w-3"})}),t.jsx("button",{onClick:Ne,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:t.jsx(E,{name:"close",className:"h-3.5 w-3.5"})})]}),g.linkedPr&&t.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[t.jsxs("span",{className:"typography-micro text-muted-foreground",children:[g.linkedPr.head," → ",g.linkedPr.base]}),g.includePrDiff&&t.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:a("session.newWorktree.includeDiffBadge")})]})]})]}),t.jsxs(Gt,{className:"mt-1 flex items-center justify-between",children:[t.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:ee.touched&&(ee.branchError||ee.worktreeError)&&t.jsxs(t.Fragment,{children:[t.jsx(E,{name:"error-warning",className:"h-3.5 w-3.5"}),t.jsx("span",{className:"typography-micro",children:ee.branchError||ee.worktreeError})]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(q,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:pe,children:a("session.newWorktree.actions.cancel")}),t.jsxs(q,{size:"sm",onClick:Ye,disabled:!Fe||pe,className:"gap-1.5",children:[pe&&t.jsx(E,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),a(pe?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),t.jsx(Fj,{open:K,onOpenChange:M,onSelect:V})]})}const lw=()=>{yc(),ys.reconnectToRuntimeBaseUrl(),hc()},cw=s=>{fs.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),Ie.getState().prepareForRuntimeSwitch(s.previousRuntimeKey),s.previousRuntimeKey&&Dm.getState().stopRunningRunsForRuntime(s.previousRuntimeKey),yc(),ys.reconnectToRuntimeBaseUrl(),lt.setState({providers:[],agents:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),es.getState().resetForRuntimeSwitch(),li.getState().resetForRuntimeSwitch(),Em.getState().reset(),fs.getState().restoreForRuntimeSwitch(s.runtimeKey),Ie.getState().restoreForRuntimeSwitch(s.runtimeKey),hc()};export{Wl as $,jc as A,fy as B,sw as C,iw as D,Mn as E,Tn as F,Rn as G,Xj as H,Hl as I,Vx as J,_x as K,ko as L,cp as M,ow as N,Wj as O,aw as P,jn as Q,Is as R,Kv as S,rw as T,hy as U,bn as V,Jj as W,sn as X,yn as Y,xn as Z,Jv as _,nw as a,nl as a0,If as a1,sl as a2,Qh as a3,Qc as a4,Xc as a5,nx as a6,ri as a7,Rj as a8,Uy as a9,Hj as aa,Tg as ab,Sc as ac,Eg as ad,Zj as ae,rj as b,cw as c,tw as d,ew as e,Gj as f,Zn as g,rs as h,qj as i,_j as j,Qb as k,Bt as l,qx as m,xl as n,Vj as o,yx as p,Uv as q,lw as r,os as s,_f as t,vc as u,Vf as v,Qj as w,Yj as x,$f as y,Fn as z};
|